diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile new file mode 100644 index 0000000000..5397f69ac2 --- /dev/null +++ b/.devcontainer/Dockerfile @@ -0,0 +1,25 @@ +# See here for image contents: https://github.com/microsoft/vscode-dev-containers/tree/v0.224.3/containers/java/.devcontainer/base.Dockerfile + +# [Choice] Java version (use -bullseye variants on local arm64/Apple Silicon): 11, 17, 11-bullseye, 17-bullseye, 11-buster, 17-buster +ARG VARIANT="17-bullseye" +FROM mcr.microsoft.com/vscode/devcontainers/java:0-${VARIANT} + +# [Option] Install Maven +ARG INSTALL_MAVEN="false" +ARG MAVEN_VERSION="" +# [Option] Install Gradle +ARG INSTALL_GRADLE="false" +ARG GRADLE_VERSION="" +RUN if [ "${INSTALL_MAVEN}" = "true" ]; then su vscode -c "umask 0002 && . /usr/local/sdkman/bin/sdkman-init.sh && sdk install maven \"${MAVEN_VERSION}\""; fi \ + && if [ "${INSTALL_GRADLE}" = "true" ]; then su vscode -c "umask 0002 && . /usr/local/sdkman/bin/sdkman-init.sh && sdk install gradle \"${GRADLE_VERSION}\""; fi + +# [Choice] Node.js version: none, lts/*, 16, 14, 12, 10 +ARG NODE_VERSION="none" +RUN if [ "${NODE_VERSION}" != "none" ]; then su vscode -c "umask 0002 && . /usr/local/share/nvm/nvm.sh && nvm install ${NODE_VERSION} 2>&1"; fi + +# [Optional] Uncomment this section to install additional OS packages. +# RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \ +# && apt-get -y install --no-install-recommends + +# [Optional] Uncomment this line to install global node packages. +# RUN su vscode -c "source /usr/local/share/nvm/nvm.sh && npm install -g " 2>&1 \ No newline at end of file diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json new file mode 100644 index 0000000000..afbdff8c77 --- /dev/null +++ b/.devcontainer/devcontainer.json @@ -0,0 +1,62 @@ +// For format details, see https://aka.ms/devcontainer.json. For config options, see the README at: +// https://github.com/microsoft/vscode-dev-containers/tree/v0.224.3/containers/java +{ + "name": "Java", + "build": { + "dockerfile": "Dockerfile", + "args": { + // Update the VARIANT arg to pick a Java version: 11, 17 + // Append -bullseye or -buster to pin to an OS version. + // Use the -bullseye variants on local arm64/Apple Silicon. + "VARIANT": "11-bullseye", + // Options + "INSTALL_MAVEN": "true", + "INSTALL_GRADLE": "false", + "NODE_VERSION": "lts/*" + } + }, + + // Set *default* container specific settings.json values on container create. + //"settings": { + // "java.home": "/docker-java-home" + //}, + "settings": { + "java.configuration.updateBuildConfiguration": "interactive", + "[java]": { + "editor.defaultFormatter": "redhat.java", + "editor.formatOnSave": true, + "editor.tabSize": 2, + "editor.insertSpaces": true, + "editor.detectIndentation": false + }, + "java.format.settings.url": "https://raw.githubusercontent.com/google/styleguide/gh-pages/eclipse-java-google-style.xml", + "java.saveActions.organizeImports": true, + "editor.tabSize": 2, + "editor.insertSpaces": true, + "editor.detectIndentation": false, + "java.checkstyle.version": "10.3", + "java.checkstyle.configuration": "https://raw.githubusercontent.com/checkstyle/checkstyle/master/src/main/resources/google_checks.xml" + }, + + +// Add the IDs of extensions you want installed when the container is created. +"extensions": [ + "vscjava.vscode-java-pack", + "ms-vscode.test-adapter-converter", + "shengchen.vscode-checkstyle" +] + + +// Use 'forwardPorts' to make a list of ports inside the container available locally. +// "forwardPorts": [], + +// Use 'postCreateCommand' to run commands after the container is created. +// "postCreateCommand": "java -version", + +// Comment out to connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root. +//"remoteUser": "vscode", +//"features": { +// "github-cli": "latest" +//} +} + diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 480a6166cb..9cbfd48033 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -3,10 +3,6 @@ name: Build maven on: push: branches: [ master ] - - # pull_request: - # types: [ opened, edited, reopened, review_requested ] - # branches: [ master ] jobs: build: @@ -15,10 +11,10 @@ jobs: steps: - uses: actions/checkout@v1 - - name: Set up JDK 1.8 + - name: Set up JDK 11 uses: actions/setup-java@v1 with: - java-version: 1.8 + java-version: 11 - name: Build with Maven run: mvn -B package --file pom.xml # - run: mkdir staging && cp target/*.jar staging diff --git a/.github/workflows/pr_test.yml b/.github/workflows/pr_test.yml index 9bf56afaa5..72d3329360 100644 --- a/.github/workflows/pr_test.yml +++ b/.github/workflows/pr_test.yml @@ -11,9 +11,9 @@ jobs: steps: - uses: actions/checkout@v1 - - name: Set up JDK 1.8 + - name: Set up JDK 11 uses: actions/setup-java@v1 with: - java-version: 1.8 + java-version: 11 - name: Test with Maven run: mvn -B test --file pom.xml diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 29e2976588..58dd48b758 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -12,10 +12,10 @@ jobs: steps: - uses: actions/checkout@v1 - - name: Set up JDK 1.8 + - name: Set up JDK 11 uses: actions/setup-java@v1 with: - java-version: 1.8 + java-version: 11 - name: Get the version id: get_version run: echo ::set-output name=VERSION::${GITHUB_REF/refs\/tags\/v/} diff --git a/.github/workflows/workflow.yml b/.github/workflows/workflow.yml new file mode 100644 index 0000000000..e1b317cbce --- /dev/null +++ b/.github/workflows/workflow.yml @@ -0,0 +1,23 @@ +name: Jacoco Distributed Exec and Aggregation2 + +on: + push: + branches: [ master ] + +jobs: + unit-tests: + name: Unit Tests + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: actions/setup-java@v1 + with: + java-version: 11 + - name: Run tests + run: | + mvn '-Dtest=!*IntegrationTest' verify -Djacoco.destFile=exportJacoco/jacoco-fast.exec + - name: Upload jacoco exec results + uses: actions/upload-artifact@v2 + with: + name: unit-tests-jacoco + path: exportJacoco/jacoco-fast.exec diff --git a/.gitignore b/.gitignore index 391a48045e..16cda0aece 100644 --- a/.gitignore +++ b/.gitignore @@ -71,8 +71,13 @@ nbdist/ src/main/java/neqsim/util/database/NeqSimDataBase2.java neqsim.iml +.classpath .DS_Store - # Test output - Serialized files -test_*.ser \ No newline at end of file +test_*.ser + +.dccache + +#Intellij IDEA +.idea diff --git a/.mvn/wrapper/maven-wrapper.properties b/.mvn/wrapper/maven-wrapper.properties new file mode 100644 index 0000000000..84b111fb23 --- /dev/null +++ b/.mvn/wrapper/maven-wrapper.properties @@ -0,0 +1,18 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.6.3/apache-maven-3.6.3-bin.zip +wrapperUrl=https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.1.1/maven-wrapper-3.1.1.jar diff --git a/.vscode/settings.json b/.vscode/settings.json index f6fd1f9749..4e980e2539 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -8,5 +8,7 @@ "java.saveActions.organizeImports": true, "editor.tabSize": 2, "editor.insertSpaces": true, - "editor.detectIndentation": false + "editor.detectIndentation": false, + "java.checkstyle.version": "10.3", + "java.checkstyle.configuration": "https://raw.githubusercontent.com/checkstyle/checkstyle/master/src/main/resources/google_checks.xml" } diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index d62a9ce46f..9d62462697 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -22,14 +22,17 @@ This project uses Google Java style formatting rules. ### Visual Studio Code: -Install Language Support for Java(TM) by Red Hat and add the following to settings.json. +Install extensions [Language Support for Java(TM) by Red Hat](https://marketplace.visualstudio.com/items?itemName=redhat.java) and [Checkstyle for Java +](https://marketplace.visualstudio.com/items?itemName=shengchen.vscode-checkstyle) and add the following to settings.json. ``` "[java]": { "editor.defaultFormatter": "redhat.java", "editor.formatOnSave": true, }, "java.format.settings.url": "https://raw.githubusercontent.com/google/styleguide/gh-pages/eclipse-java-google-style.xml", - "java.saveActions.organizeImports": true + "java.saveActions.organizeImports": true, + "java.checkstyle.version": "10.3", + "java.checkstyle.configuration": "https://github.com/checkstyle/checkstyle/blob/master/src/main/resources/google_checks.xml" ``` Note: workspace/project specific settings are located in folder .vscode. diff --git a/README.md b/README.md index b38ebdba3b..1199f30d88 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,9 @@ # NeqSim [![Build Status](https://neqsim.visualstudio.com/neqsim_cicd/_apis/build/status/neqsim_build?branchName=master)](https://neqsim.visualstudio.com/neqsim_cicd/_build/latest?definitionId=1&branchName=master) -![Build maven](https://github.com/equinor/neqsim/workflows/Build%20maven/badge.svg?branch=master) +![Build maven](https://github.com/equinor/neqsim/workflows/Build%20maven/badge.svg?branch=master) +[![Known Vulnerabilities](https://snyk.io/test/github/equinor/neqsim/badge.svg)](https://snyk.io/test/github/equinor/neqsim) + NeqSim is the main part of the [NeqSim project](https://equinor.github.io/neqsimhome/). NeqSim (Non-Equilibrium Simulator) is a Java library for estimation of fluid behavior and process design for oil and gas production. The basis for NeqSim is a library of fundamental mathematical models related to phase behavior and physical properties of oil and gas. NeqSim is easilly extended with new models. NeqSim development was initiated at the [Norwegian University of Science and Technology (NTNU)](https://www.ntnu.edu/employees/even.solbraa). @@ -25,8 +27,12 @@ The NeqSim source code is downloaded by cloning the library to your local comput ```bash git clone https://github.com/equinor/neqsim.git cd neqsim -mvn install +./mvnw install ``` +> **Note** +> The maven wrapper command is dependend on your OS, for Unix use: ```./mvnw``` +> Windows: +> ```mvnw.cmd ``` An interactive demonstration of how to get started as a NeqSim developer is presented in this [NeqSim Colab demo](https://colab.research.google.com/drive/1JiszeCxfpcJZT2vejVWuNWGmd9SJdNC7). @@ -35,7 +41,12 @@ An interactive demonstration of how to get started as a NeqSim developer is pres The test files are written in JUnit5 and placed in the [test directory](https://github.com/equinor/neqsim/tree/master/src/test). All test have to be passed before merging to the master. Test code shuld be written for all new code added to the project. Test coverage can be examined using [jacoco](https://www.eclemma.org/jacoco/) from maven. -Generate a coverage report using `mvn jacoco:prepare-agent test install jacoco:report` and see results in target/site/jacoco/index.html. +Generate a coverage report using `./mvnw jacoco:prepare-agent test install jacoco:report` and see results in target/site/jacoco/index.html. +> **Note** +> The maven wrapper command is dependend on your OS, for Unix use: ```./mvnw``` +> Windows: +> ```mvnw.cmd ``` + ## Deployment diff --git a/mvnw b/mvnw new file mode 100755 index 0000000000..b7f064624f --- /dev/null +++ b/mvnw @@ -0,0 +1,287 @@ +#!/bin/sh +# ---------------------------------------------------------------------------- +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# ---------------------------------------------------------------------------- + +# ---------------------------------------------------------------------------- +# Apache Maven Wrapper startup batch script, version 3.1.1 +# +# Required ENV vars: +# ------------------ +# JAVA_HOME - location of a JDK home dir +# +# Optional ENV vars +# ----------------- +# MAVEN_OPTS - parameters passed to the Java VM when running Maven +# e.g. to debug Maven itself, use +# set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 +# MAVEN_SKIP_RC - flag to disable loading of mavenrc files +# ---------------------------------------------------------------------------- + +if [ -z "$MAVEN_SKIP_RC" ] ; then + + if [ -f /usr/local/etc/mavenrc ] ; then + . /usr/local/etc/mavenrc + fi + + if [ -f /etc/mavenrc ] ; then + . /etc/mavenrc + fi + + if [ -f "$HOME/.mavenrc" ] ; then + . "$HOME/.mavenrc" + fi + +fi + +# OS specific support. $var _must_ be set to either true or false. +cygwin=false; +darwin=false; +mingw=false +case "`uname`" in + CYGWIN*) cygwin=true ;; + MINGW*) mingw=true;; + Darwin*) darwin=true + # Use /usr/libexec/java_home if available, otherwise fall back to /Library/Java/Home + # See https://developer.apple.com/library/mac/qa/qa1170/_index.html + if [ -z "$JAVA_HOME" ]; then + if [ -x "/usr/libexec/java_home" ]; then + JAVA_HOME="`/usr/libexec/java_home`"; export JAVA_HOME + else + JAVA_HOME="/Library/Java/Home"; export JAVA_HOME + fi + fi + ;; +esac + +if [ -z "$JAVA_HOME" ] ; then + if [ -r /etc/gentoo-release ] ; then + JAVA_HOME=`java-config --jre-home` + fi +fi + +# For Cygwin, ensure paths are in UNIX format before anything is touched +if $cygwin ; then + [ -n "$JAVA_HOME" ] && + JAVA_HOME=`cygpath --unix "$JAVA_HOME"` + [ -n "$CLASSPATH" ] && + CLASSPATH=`cygpath --path --unix "$CLASSPATH"` +fi + +# For Mingw, ensure paths are in UNIX format before anything is touched +if $mingw ; then + [ -n "$JAVA_HOME" ] && + JAVA_HOME="`(cd "$JAVA_HOME"; pwd)`" +fi + +if [ -z "$JAVA_HOME" ]; then + javaExecutable="`which javac`" + if [ -n "$javaExecutable" ] && ! [ "`expr \"$javaExecutable\" : '\([^ ]*\)'`" = "no" ]; then + # readlink(1) is not available as standard on Solaris 10. + readLink=`which readlink` + if [ ! `expr "$readLink" : '\([^ ]*\)'` = "no" ]; then + if $darwin ; then + javaHome="`dirname \"$javaExecutable\"`" + javaExecutable="`cd \"$javaHome\" && pwd -P`/javac" + else + javaExecutable="`readlink -f \"$javaExecutable\"`" + fi + javaHome="`dirname \"$javaExecutable\"`" + javaHome=`expr "$javaHome" : '\(.*\)/bin'` + JAVA_HOME="$javaHome" + export JAVA_HOME + fi + fi +fi + +if [ -z "$JAVACMD" ] ; then + if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD="$JAVA_HOME/jre/sh/java" + else + JAVACMD="$JAVA_HOME/bin/java" + fi + else + JAVACMD="`\\unset -f command; \\command -v java`" + fi +fi + +if [ ! -x "$JAVACMD" ] ; then + echo "Error: JAVA_HOME is not defined correctly." >&2 + echo " We cannot execute $JAVACMD" >&2 + exit 1 +fi + +if [ -z "$JAVA_HOME" ] ; then + echo "Warning: JAVA_HOME environment variable is not set." +fi + +# traverses directory structure from process work directory to filesystem root +# first directory with .mvn subdirectory is considered project base directory +find_maven_basedir() { + if [ -z "$1" ] + then + echo "Path not specified to find_maven_basedir" + return 1 + fi + + basedir="$1" + wdir="$1" + while [ "$wdir" != '/' ] ; do + if [ -d "$wdir"/.mvn ] ; then + basedir=$wdir + break + fi + # workaround for JBEAP-8937 (on Solaris 10/Sparc) + if [ -d "${wdir}" ]; then + wdir=`cd "$wdir/.."; pwd` + fi + # end of workaround + done + printf '%s' "$(cd "$basedir"; pwd)" +} + +# concatenates all lines of a file +concat_lines() { + if [ -f "$1" ]; then + echo "$(tr -s '\n' ' ' < "$1")" + fi +} + +BASE_DIR=$(find_maven_basedir "$(dirname $0)") +if [ -z "$BASE_DIR" ]; then + exit 1; +fi + +MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-"$BASE_DIR"}; export MAVEN_PROJECTBASEDIR +if [ "$MVNW_VERBOSE" = true ]; then + echo $MAVEN_PROJECTBASEDIR +fi + +########################################################################################## +# Extension to allow automatically downloading the maven-wrapper.jar from Maven-central +# This allows using the maven wrapper in projects that prohibit checking in binary data. +########################################################################################## +if [ -r "$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" ]; then + if [ "$MVNW_VERBOSE" = true ]; then + echo "Found .mvn/wrapper/maven-wrapper.jar" + fi +else + if [ "$MVNW_VERBOSE" = true ]; then + echo "Couldn't find .mvn/wrapper/maven-wrapper.jar, downloading it ..." + fi + if [ -n "$MVNW_REPOURL" ]; then + wrapperUrl="$MVNW_REPOURL/org/apache/maven/wrapper/maven-wrapper/3.1.1/maven-wrapper-3.1.1.jar" + else + wrapperUrl="https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.1.1/maven-wrapper-3.1.1.jar" + fi + while IFS="=" read key value; do + case "$key" in (wrapperUrl) wrapperUrl="$value"; break ;; + esac + done < "$BASE_DIR/.mvn/wrapper/maven-wrapper.properties" + if [ "$MVNW_VERBOSE" = true ]; then + echo "Downloading from: $wrapperUrl" + fi + wrapperJarPath="$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" + if $cygwin; then + wrapperJarPath=`cygpath --path --windows "$wrapperJarPath"` + fi + + if command -v wget > /dev/null; then + QUIET="--quiet" + if [ "$MVNW_VERBOSE" = true ]; then + echo "Found wget ... using wget" + QUIET="" + fi + if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then + wget $QUIET "$wrapperUrl" -O "$wrapperJarPath" + else + wget $QUIET --http-user="$MVNW_USERNAME" --http-password="$MVNW_PASSWORD" "$wrapperUrl" -O "$wrapperJarPath" + fi + [ $? -eq 0 ] || rm -f "$wrapperJarPath" + elif command -v curl > /dev/null; then + QUIET="--silent" + if [ "$MVNW_VERBOSE" = true ]; then + echo "Found curl ... using curl" + QUIET="" + fi + if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then + curl $QUIET -o "$wrapperJarPath" "$wrapperUrl" -f -L + else + curl $QUIET --user "$MVNW_USERNAME:$MVNW_PASSWORD" -o "$wrapperJarPath" "$wrapperUrl" -f -L + fi + [ $? -eq 0 ] || rm -f "$wrapperJarPath" + else + if [ "$MVNW_VERBOSE" = true ]; then + echo "Falling back to using Java to download" + fi + javaSource="$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.java" + javaClass="$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" + # For Cygwin, switch paths to Windows format before running javac + if $cygwin; then + javaSource=`cygpath --path --windows "$javaSource"` + javaClass=`cygpath --path --windows "$javaClass"` + fi + if [ -e "$javaSource" ]; then + if [ ! -e "$javaClass" ]; then + if [ "$MVNW_VERBOSE" = true ]; then + echo " - Compiling MavenWrapperDownloader.java ..." + fi + # Compiling the Java class + ("$JAVA_HOME/bin/javac" "$javaSource") + fi + if [ -e "$javaClass" ]; then + # Running the downloader + if [ "$MVNW_VERBOSE" = true ]; then + echo " - Running MavenWrapperDownloader.java ..." + fi + ("$JAVA_HOME/bin/java" -cp .mvn/wrapper MavenWrapperDownloader "$MAVEN_PROJECTBASEDIR") + fi + fi + fi +fi +########################################################################################## +# End of extension +########################################################################################## + +MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS" + +# For Cygwin, switch paths to Windows format before running java +if $cygwin; then + [ -n "$JAVA_HOME" ] && + JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"` + [ -n "$CLASSPATH" ] && + CLASSPATH=`cygpath --path --windows "$CLASSPATH"` + [ -n "$MAVEN_PROJECTBASEDIR" ] && + MAVEN_PROJECTBASEDIR=`cygpath --path --windows "$MAVEN_PROJECTBASEDIR"` +fi + +# Provide a "standardized" way to retrieve the CLI args that will +# work with both Windows and non-Windows executions. +MAVEN_CMD_LINE_ARGS="$MAVEN_CONFIG $@" +export MAVEN_CMD_LINE_ARGS + +WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain + +exec "$JAVACMD" \ + $MAVEN_OPTS \ + $MAVEN_DEBUG_OPTS \ + -classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \ + "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \ + ${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$@" diff --git a/mvnw.cmd b/mvnw.cmd new file mode 100644 index 0000000000..cba1f040dc --- /dev/null +++ b/mvnw.cmd @@ -0,0 +1,187 @@ +@REM ---------------------------------------------------------------------------- +@REM Licensed to the Apache Software Foundation (ASF) under one +@REM or more contributor license agreements. See the NOTICE file +@REM distributed with this work for additional information +@REM regarding copyright ownership. The ASF licenses this file +@REM to you under the Apache License, Version 2.0 (the +@REM "License"); you may not use this file except in compliance +@REM with the License. You may obtain a copy of the License at +@REM +@REM http://www.apache.org/licenses/LICENSE-2.0 +@REM +@REM Unless required by applicable law or agreed to in writing, +@REM software distributed under the License is distributed on an +@REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +@REM KIND, either express or implied. See the License for the +@REM specific language governing permissions and limitations +@REM under the License. +@REM ---------------------------------------------------------------------------- + +@REM ---------------------------------------------------------------------------- +@REM Apache Maven Wrapper startup batch script, version 3.1.1 +@REM +@REM Required ENV vars: +@REM JAVA_HOME - location of a JDK home dir +@REM +@REM Optional ENV vars +@REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands +@REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a keystroke before ending +@REM MAVEN_OPTS - parameters passed to the Java VM when running Maven +@REM e.g. to debug Maven itself, use +@REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 +@REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files +@REM ---------------------------------------------------------------------------- + +@REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on' +@echo off +@REM set title of command window +title %0 +@REM enable echoing by setting MAVEN_BATCH_ECHO to 'on' +@if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO% + +@REM set %HOME% to equivalent of $HOME +if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%") + +@REM Execute a user defined script before this one +if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre +@REM check for pre script, once with legacy .bat ending and once with .cmd ending +if exist "%USERPROFILE%\mavenrc_pre.bat" call "%USERPROFILE%\mavenrc_pre.bat" %* +if exist "%USERPROFILE%\mavenrc_pre.cmd" call "%USERPROFILE%\mavenrc_pre.cmd" %* +:skipRcPre + +@setlocal + +set ERROR_CODE=0 + +@REM To isolate internal variables from possible post scripts, we use another setlocal +@setlocal + +@REM ==== START VALIDATION ==== +if not "%JAVA_HOME%" == "" goto OkJHome + +echo. +echo Error: JAVA_HOME not found in your environment. >&2 +echo Please set the JAVA_HOME variable in your environment to match the >&2 +echo location of your Java installation. >&2 +echo. +goto error + +:OkJHome +if exist "%JAVA_HOME%\bin\java.exe" goto init + +echo. +echo Error: JAVA_HOME is set to an invalid directory. >&2 +echo JAVA_HOME = "%JAVA_HOME%" >&2 +echo Please set the JAVA_HOME variable in your environment to match the >&2 +echo location of your Java installation. >&2 +echo. +goto error + +@REM ==== END VALIDATION ==== + +:init + +@REM Find the project base dir, i.e. the directory that contains the folder ".mvn". +@REM Fallback to current working directory if not found. + +set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR% +IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir + +set EXEC_DIR=%CD% +set WDIR=%EXEC_DIR% +:findBaseDir +IF EXIST "%WDIR%"\.mvn goto baseDirFound +cd .. +IF "%WDIR%"=="%CD%" goto baseDirNotFound +set WDIR=%CD% +goto findBaseDir + +:baseDirFound +set MAVEN_PROJECTBASEDIR=%WDIR% +cd "%EXEC_DIR%" +goto endDetectBaseDir + +:baseDirNotFound +set MAVEN_PROJECTBASEDIR=%EXEC_DIR% +cd "%EXEC_DIR%" + +:endDetectBaseDir + +IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig + +@setlocal EnableExtensions EnableDelayedExpansion +for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a +@endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS% + +:endReadAdditionalConfig + +SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe" +set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar" +set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain + +set WRAPPER_URL="https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.1.1/maven-wrapper-3.1.1.jar" + +FOR /F "usebackq tokens=1,2 delims==" %%A IN ("%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.properties") DO ( + IF "%%A"=="wrapperUrl" SET WRAPPER_URL=%%B +) + +@REM Extension to allow automatically downloading the maven-wrapper.jar from Maven-central +@REM This allows using the maven wrapper in projects that prohibit checking in binary data. +if exist %WRAPPER_JAR% ( + if "%MVNW_VERBOSE%" == "true" ( + echo Found %WRAPPER_JAR% + ) +) else ( + if not "%MVNW_REPOURL%" == "" ( + SET WRAPPER_URL="%MVNW_REPOURL%/org/apache/maven/wrapper/maven-wrapper/3.1.1/maven-wrapper-3.1.1.jar" + ) + if "%MVNW_VERBOSE%" == "true" ( + echo Couldn't find %WRAPPER_JAR%, downloading it ... + echo Downloading from: %WRAPPER_URL% + ) + + powershell -Command "&{"^ + "$webclient = new-object System.Net.WebClient;"^ + "if (-not ([string]::IsNullOrEmpty('%MVNW_USERNAME%') -and [string]::IsNullOrEmpty('%MVNW_PASSWORD%'))) {"^ + "$webclient.Credentials = new-object System.Net.NetworkCredential('%MVNW_USERNAME%', '%MVNW_PASSWORD%');"^ + "}"^ + "[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; $webclient.DownloadFile('%WRAPPER_URL%', '%WRAPPER_JAR%')"^ + "}" + if "%MVNW_VERBOSE%" == "true" ( + echo Finished downloading %WRAPPER_JAR% + ) +) +@REM End of extension + +@REM Provide a "standardized" way to retrieve the CLI args that will +@REM work with both Windows and non-Windows executions. +set MAVEN_CMD_LINE_ARGS=%* + +%MAVEN_JAVA_EXE% ^ + %JVM_CONFIG_MAVEN_PROPS% ^ + %MAVEN_OPTS% ^ + %MAVEN_DEBUG_OPTS% ^ + -classpath %WRAPPER_JAR% ^ + "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" ^ + %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %* +if ERRORLEVEL 1 goto error +goto end + +:error +set ERROR_CODE=1 + +:end +@endlocal & set ERROR_CODE=%ERROR_CODE% + +if not "%MAVEN_SKIP_RC%"=="" goto skipRcPost +@REM check for post script, once with legacy .bat ending and once with .cmd ending +if exist "%USERPROFILE%\mavenrc_post.bat" call "%USERPROFILE%\mavenrc_post.bat" +if exist "%USERPROFILE%\mavenrc_post.cmd" call "%USERPROFILE%\mavenrc_post.cmd" +:skipRcPost + +@REM pause the script if MAVEN_BATCH_PAUSE is set to 'on' +if "%MAVEN_BATCH_PAUSE%"=="on" pause + +if "%MAVEN_TERMINATE_CMD%"=="on" exit %ERROR_CODE% + +cmd /C exit /B %ERROR_CODE% diff --git a/pom.xml b/pom.xml index d706c460dc..207a5ec5b4 100644 --- a/pom.xml +++ b/pom.xml @@ -11,8 +11,8 @@ 2.3.3 UTF-8 UTF-8 - - + + @@ -20,23 +20,18 @@ central https://repo1.maven.org/maven2/ - - unidata-all - Unidata All - https://artifacts.unidata.ucar.edu/repository/unidata-all/ - org.apache.logging.log4j log4j-api - 2.17.1 + 2.18.0 org.apache.logging.log4j log4j-core - 2.17.1 + 2.18.0 org.junit.jupiter @@ -63,17 +58,18 @@ org.apache.derby derby - 10.14.2.0 + 10.15.2.0 - org.ejml - ejml-all - 0.40 + org.apache.derby + derbytools + 10.15.2.0 + test - com.lowagie - itext - 1.4.8 + org.ejml + ejml-all + 0.41 gov.nist.math @@ -83,37 +79,24 @@ org.jfree jcommon - 1.0.23 + 1.0.24 org.jfree jfreechart - 1.5.1 + 1.5.3 com.googlecode.matrix-toolkits-java mtj 1.0.4 - - - edu.ucar - netcdf4 - 4.6.16.1 - provided - org.ojalgo ojalgo 48.4.2 provided - - edu.wisc.ssec - visad - 2.0-20130124 - provided - @@ -191,8 +174,8 @@ maven-compiler-plugin 3.9.0 - 1.8 - 1.8 + 11 + 11 ${project.build.sourceEncoding} return getb() / (molarVolume * (numberOfMolesInPhase * molarVolume - loc_B)); + // aks Dr. Soolbra whats the difference between getb and loc_B and + // why the molar volume in the bracket is multiplied by the numberofmolesinphase (is it because + // of the units of molarvolume?) + } + + @Override + public double gVV() { + double val1 = numberOfMolesInPhase * getMolarVolume(); + double val2 = val1 + getC() - getB(); + return -1.0 / (val2 * val2) + 1.0 / (val1 * val1); + + // old is -->double val1 = numberOfMolesInPhase * getMolarVolume(); + // double val2 = val1 + getC - getB(); + // return -1.0 / (val2 * val2) + 1.0 / (val1 * val1); + } + + public double gVVV() { + double val1 = numberOfMolesInPhase * getMolarVolume(); + double val2 = val1 + getC() - getB(); + return 2.0 / (val2 * val2 * val2) - 2.0 / (val1 * val1 * val1); + } + + @Override + public double fv() { + return -1.0 / (R * (numberOfMolesInPhase * molarVolume + delta1 * getB() + loc_C()) + * (numberOfMolesInPhase * molarVolume + delta2 * getB() + loc_C())); + + // OLD IS--> return -1.0 / (R * (numberOfMolesInPhase * molarVolume + delta1 * loc_B) + // * (numberOfMolesInPhase * molarVolume + delta2 * loc_B)); + } + + @Override + public double fVV() { + double val1 = (numberOfMolesInPhase * molarVolume + delta1 * getB() + loc_C()); + double val2 = (numberOfMolesInPhase * molarVolume + delta2 * getB() + loc_C()); + return 1.0 / (R * getB() * (delta1 - delta2)) * (-1.0 / (val1 * val1) + 1.0 / (val2 * val2)); + + // old is-->double val1 = (numberOfMolesInPhase * molarVolume + delta1 * loc_B); + // double val2 = (numberOfMolesInPhase * molarVolume + delta2 * loc_B); + // return 1.0 / (R * loc_B * (delta1 - delta2)) * (-1.0 / (val1 * val1) + 1.0 / (val2 * val2)); + } + + public double fVVV() { + double val1 = numberOfMolesInPhase * molarVolume + getB() * delta1 + getC(); + double val2 = numberOfMolesInPhase * molarVolume + getB() * delta2 + getC(); + return 1.0 / (R * getB() * (delta1 - delta2)) + * (2.0 / (val1 * val1 * val1) - 2.0 / (val2 * val2 * val2)); + + // old is -->double val1 = numberOfMolesInPhase * molarVolume + getB() * delta1; + // double val2 = numberOfMolesInPhase * molarVolume + getB() * delta2; + // return 1.0 / (R * getB() * (delta1 - delta2)) * (2.0 / (val1 * val1 * val1) - 2.0 / (val2 * + // val2 * val2)); + } + + // derivative of small g with regards to b + // problem with the loc_b in gb(),gc()-->it says that it is not visible and I think this is + // because loc_B is marked as private + // in PhaseEoS...so for now I switch it to getb and we will see + + @Override + public double gb() { + // return -1.0 / (numberOfMolesInPhase * molarVolume - loc_B + loc_C); + return -1.0 / (numberOfMolesInPhase * molarVolume - getB() + getC()); + } + + //// derivative of small g with regards to c + public double gc() { + // return 1.0 / (numberOfMolesInPhase * molarVolume - loc_B + loc_C); + return 1.0 / (numberOfMolesInPhase * molarVolume - getB() + getC()); + } + + //// derivative of small f with regards to c-->equal to fv + public double fc() { + return -1.0 / (R * (numberOfMolesInPhase * molarVolume + delta1 * getB() + loc_C()) + * (numberOfMolesInPhase * molarVolume + delta2 * getB() + loc_C())); + } + + @Override + public double fb() { + return -(calcf() + (numberOfMolesInPhase * molarVolume + getC())* fv()) / getB(); +} + + //// second derivative of small f with regards to cc-->equal to fvv + public double fcc() { + return fVV(); + } + + //// second derivative of small f with regards to bc-->equal to fvv + public double fbc() { + return fBV(); + } + + //// second derivative of small f with regards to cv-->equal to fvv + public double fcv() { + return fVV(); + } + + //// second derivative of small f with regards to bv--> + @Override + public double fBV() { + return -(2.0 * fv() + (numberOfMolesInPhase * molarVolume + getC()) * fVV()) / getB(); + } + + //// second derivative of small f with regards to bb--> + @Override + public double fBB() { + return -(2.0 * fb() + (numberOfMolesInPhase * molarVolume + getC()) * fBV()) / getB(); + } + + //// second derivative of small g with regards to bv--> + @Override + public double gBV() { + double val = numberOfMolesInPhase * getMolarVolume() - getB() + getC(); + return 1.0 / (val * val); + } + + //// second derivative of small g with regards to bb--> + @Override + public double gBB() { + double val = numberOfMolesInPhase * getMolarVolume() - getB() + getC(); + return -1.0 / (val * val); + } + + //// second derivative of small g with regards to bc--> + public double gBC() { + double val = numberOfMolesInPhase * getMolarVolume() - getB() + getC(); + return 1.0 / (val * val); + } + + //// second derivative of small g with regards to cv--> + public double gCV() { + double val = numberOfMolesInPhase * getMolarVolume() - getB() + getC(); + return -1.0 / (val * val); + } + + //// second derivative of small g with regards to cc--> + public double gCC() { + double val = numberOfMolesInPhase * getMolarVolume() - getB() + getC(); + return -1.0 / (val * val); + } + + // Below are the partial derivatives of F with regards to model parameters + + @Override + public double F() { + return super.F(); + } + + // derivative of big F with regards to C + // @Override + public double FC() { + return -numberOfMolesInPhase * gc() - getA() / temperature * fc(); + } + + public double FnC() { + return -gc(); + } + + public double FTC() { + return getA() * fc() / temperature / temperature; + } + + public double FBC() { + return -numberOfMolesInPhase * gBC() - getA() * fbc() / temperature; + } + + public double FCV() { + return -numberOfMolesInPhase * gCV() - getA() * fcv() / temperature; + } + + public double FCC() { + return -numberOfMolesInPhase * gCC() - getA() * fcc() / temperature; + } + + public double FCD() { + return -fc() / temperature; + } + + @Override + public double dFdVdV() { + return -numberOfMolesInPhase * gVV() - getA() * fVV() / temperature; + } + + @Override + public double dFdVdVdV() { + return -numberOfMolesInPhase * gVVV() - getA() * fVVV() / temperature; + } + + /** {@inheritDoc} */ + @Override + public double dFdTdV() { + return FTV() + FDV() * getAT() + FCV() * getCT(); + } + + /** {@inheritDoc} */ + @Override + public double dFdT() { + return FT() + FD() * getAT() + FC() * getCT(); + } + + @Override + public double dFdTdT() { + return FTT() + 2.0 * FDT() * getAT() + FD() * getATT() + 2 * FTC() * getCT() + + FCC() * getCT() * getCT() + FC() * getCTT() + 2 * FCD() * getCT() * getAT(); + } + + @Override + public PhasePrEosvolcor clone() { + PhasePrEosvolcor clonedPhase = null; + try { + clonedPhase = (PhasePrEosvolcor) super.clone(); + } catch (Exception e) { + logger.error("Cloning failed.", e); + } + + return clonedPhase; + } + + @Override + public void addcomponent(String componentName, double moles, double molesInPhase, + int compNumber) { + super.addcomponent(molesInPhase); + componentArray[compNumber] = + new ComponentPRvolcor(componentName, moles, molesInPhase, compNumber); + } + +} diff --git a/src/main/java/neqsim/thermo/phase/PhaseSrkCPA.java b/src/main/java/neqsim/thermo/phase/PhaseSrkCPA.java index f70d0002d2..36eb5fead5 100644 --- a/src/main/java/neqsim/thermo/phase/PhaseSrkCPA.java +++ b/src/main/java/neqsim/thermo/phase/PhaseSrkCPA.java @@ -221,6 +221,7 @@ public void init(double totalNumberOfMoles, int numberOfComponents, int type, in if (type > 1) { initCPAMatrix(type); + super.init(totalNumberOfMoles, numberOfComponents, type, phase, beta); } } @@ -857,7 +858,7 @@ public double calc_g() { * @return a double */ public double calc_lngV() { - tempTotVol = getMolarVolume(); + tempTotVol = getTotalVolume(); // gv = -2.0 * getB() * (10.0 * getTotalVolume() - getB()) / getTotalVolume() / // ((8.0 * getTotalVolume() - getB()) * (4.0 * getTotalVolume() - getB())); return 1.0 / (2.0 - getB() / (4.0 * tempTotVol)) * getB() / (4.0 * tempTotVol * tempTotVol) @@ -873,7 +874,7 @@ public double calc_lngV() { * @return a double */ public double calc_lngVV() { - tempTotVol = getMolarVolume(); + tempTotVol = getTotalVolume(); return 2.0 * (640.0 * Math.pow(tempTotVol, 3.0) - 216.0 * getB() * tempTotVol * tempTotVol + 24.0 * Math.pow(getB(), 2.0) * tempTotVol - Math.pow(getB(), 3.0)) @@ -889,7 +890,7 @@ public double calc_lngVV() { * @return a double */ public double calc_lngVVV() { - tempTotVol = getMolarVolume(); + tempTotVol = getTotalVolume(); return 4.0 * (Math.pow(getB(), 5.0) + 17664.0 * Math.pow(tempTotVol, 4.0) * getB() - 4192.0 * Math.pow(tempTotVol, 3.0) * Math.pow(getB(), 2.0) diff --git a/src/main/java/neqsim/thermo/phase/PhaseSrkCPA_proceduralMatrices.java b/src/main/java/neqsim/thermo/phase/PhaseSrkCPA_proceduralMatrices.java index 6b9640bcc3..a1d4f1670c 100644 --- a/src/main/java/neqsim/thermo/phase/PhaseSrkCPA_proceduralMatrices.java +++ b/src/main/java/neqsim/thermo/phase/PhaseSrkCPA_proceduralMatrices.java @@ -392,7 +392,7 @@ moleculeNumber[i], moleculeNumber[j], this, getTemperature(), CommonOps_DDRM.mult(XVtransposeQMatksiksiksiXVtranspose, XV, mat4); DMatrixRMaj dFCPAdVdVdVMatrix = new DMatrixRMaj(); - dFCPAdVdVdVMatrix.set(QVVV); + dFCPAdVdVdVMatrix.setTo(QVVV); CommonOps_DDRM.addEquals(dFCPAdVdVdVMatrix, mat1); CommonOps_DDRM.addEquals(dFCPAdVdVdVMatrix, mat2); CommonOps_DDRM.addEquals(dFCPAdVdVdVMatrix, mat2); diff --git a/src/main/java/neqsim/thermo/phase/PhaseUMRCPA.java b/src/main/java/neqsim/thermo/phase/PhaseUMRCPA.java new file mode 100644 index 0000000000..558effcbf7 --- /dev/null +++ b/src/main/java/neqsim/thermo/phase/PhaseUMRCPA.java @@ -0,0 +1,2120 @@ +package neqsim.thermo.phase; + +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.ejml.data.DMatrixRMaj; +import org.ejml.dense.row.CommonOps_DDRM; +import org.ejml.dense.row.NormOps_DDRM; +import org.ejml.simple.SimpleMatrix; +// import org.ejml.data.DenseMatrix64F; +import neqsim.thermo.component.ComponentCPAInterface; +import neqsim.thermo.component.ComponentUMRCPA; +import neqsim.thermo.mixingRule.CPAMixing; +import neqsim.thermo.mixingRule.CPAMixingInterface; + +/** + *

+ * PhaseSrkCPA class. + *

+ * + * @author Even Solbraa + * @version $Id: $Id + */ +public class PhaseUMRCPA extends PhasePrEos implements PhaseCPAInterface { + /** + *

+ * Getter for the field dFdNtemp. + *

+ * + * @return the dFdNtemp + */ + public double[] getdFdNtemp() { + return dFdNtemp; + } + + private static final long serialVersionUID = 1000; + static Logger logger = LogManager.getLogger(PhaseUMRCPA.class); + + public CPAMixing cpaSelect = new CPAMixing(); + public CPAMixingInterface cpamix; + double gcpavv = 0.0, gcpavvv = 0.0, gcpa = 0.0, hcpatot = 1.0, FCPA = 0.0, dFCPAdTdV, + dFCPAdTdT = 0.0, dFCPAdT = 0, dFCPAdV = 0, dFCPAdVdV = 0.0, dFCPAdVdVdV = 0.0; + double gcpav = 0.0, tempTotVol = 0; + private double[] dFdNtemp = {0, 0}; + int cpaon = 1, oldTotalNumberOfAccociationSites = 0; + int totalNumberOfAccociationSites = 0; + int[][][] selfAccociationScheme = null; + int[][][][] crossAccociationScheme = null; + int[] activeAccosComp = null;// new int[100]; + private double[] lngi; + int[] moleculeNumber = null, assSiteNumber = null; + private double[][] gvector = null, delta = null, deltaNog = null, deltadT = null, + deltadTdT = null; + double[][][] Klkni = null; + private SimpleMatrix KlkTVMatrix = null, KlkTTMatrix = null, KlkTMatrix = null, + udotTimesmMatrix = null, mVector = null, udotMatrix = null, uMatrix = null, + QMatksiksiksi = null, KlkVVVMatrix = null, KlkVVMatrix = null, udotTimesmiMatrix = null, + ksiMatrix = null, KlkMatrix = null, hessianMatrix = null, hessianInvers = null, + KlkVMatrix = null; + private DMatrixRMaj corr2Matrix = null, corr3Matrix = null, corr4Matrix = null;// new + // DenseMatrix64F(getTotalNumberOfAccociationSites(), + // 1); + + /** + *

+ * Constructor for PhaseUMRCPA. + *

+ */ + public PhaseUMRCPA() { + super(); + thermoPropertyModelName = "UMR-CPA-EoS"; + } + + /** {@inheritDoc} */ + @Override + public PhaseUMRCPA clone() { + PhaseUMRCPA clonedPhase = null; + try { + clonedPhase = (PhaseUMRCPA) super.clone(); + } catch (Exception e) { + logger.error("Cloning failed.", e); + } + if (activeAccosComp != null) { + clonedPhase.activeAccosComp = activeAccosComp.clone(); + System.arraycopy(this.activeAccosComp, 0, clonedPhase.activeAccosComp, 0, + activeAccosComp.length); + } + // clonedPhase.cpaSelect = (CPAMixing) cpaSelect.clone(); + // clonedPhase.cpamix = (CPAMixingInterface) cpamix.clone(); + // clonedPhase.cpamix = cpaSelect.getMixingRule(1, this); + + return clonedPhase; + } + + /** {@inheritDoc} */ + @Override + public void init(double totalNumberOfMoles, int numberOfComponents, int type, int phase, + double beta) { + boolean changedAssosiationStatus = false; + + if (type == 0) { + activeAccosComp = new int[numberOfComponents]; + for (int i = 0; i < numberOfComponents; i++) { + if (componentArray[i].getNumberOfmoles() < 1e-50) { + componentArray[i].setNumberOfAssociationSites(0); + if (activeAccosComp[i] == 1) { + activeAccosComp[i] = 0; + changedAssosiationStatus = true; + } + } else { + if (activeAccosComp[i] == 0) { + changedAssosiationStatus = true; + activeAccosComp[i] = 1; + } + } + } + + if (changedAssosiationStatus || lngi == null) { + setTotalNumberOfAccociationSites(0); + selfAccociationScheme = new int[numberOfComponents][0][0]; + crossAccociationScheme = new int[numberOfComponents][numberOfComponents][0][0]; + for (int i = 0; i < numberOfComponents; i++) { + if (componentArray[i].getNumberOfmoles() < 1e-50) { + componentArray[i].setNumberOfAssociationSites(0); + } else { + componentArray[i].setNumberOfAssociationSites( + componentArray[i].getOrginalNumberOfAssociationSites()); + setTotalNumberOfAccociationSites(getTotalNumberOfAccociationSites() + + componentArray[i].getNumberOfAssociationSites()); + selfAccociationScheme[i] = cpaSelect.setAssociationScheme(i, this); + for (int j = 0; j < numberOfComponents; j++) { + crossAccociationScheme[i][j] = + cpaSelect.setCrossAssociationScheme(i, j, this); + } + } + } + } + + for (int i = 0; i < numberOfComponents; i++) { + for (int j = 0; j < componentArray[i].getNumberOfAssociationSites(); j++) { + ((ComponentUMRCPA) componentArray[i]).setXsite(j, 1.0); + ((ComponentUMRCPA) componentArray[i]).setXsitedV(j, 0.0); + ((ComponentUMRCPA) componentArray[i]).setXsitedT(j, 0.0); + } + } + + if (changedAssosiationStatus || lngi == null || mVector == null) { + lngi = new double[numberOfComponents]; + mVector = new SimpleMatrix(getTotalNumberOfAccociationSites(), 1); + KlkMatrix = new SimpleMatrix(getTotalNumberOfAccociationSites(), + getTotalNumberOfAccociationSites()); + KlkVMatrix = new SimpleMatrix(getTotalNumberOfAccociationSites(), + getTotalNumberOfAccociationSites()); + KlkVVMatrix = new SimpleMatrix(getTotalNumberOfAccociationSites(), + getTotalNumberOfAccociationSites()); + KlkVVVMatrix = new SimpleMatrix(getTotalNumberOfAccociationSites(), + getTotalNumberOfAccociationSites()); + hessianMatrix = new SimpleMatrix(getTotalNumberOfAccociationSites(), + getTotalNumberOfAccociationSites()); + KlkTMatrix = new SimpleMatrix(getTotalNumberOfAccociationSites(), + getTotalNumberOfAccociationSites()); + KlkTTMatrix = new SimpleMatrix(getTotalNumberOfAccociationSites(), + getTotalNumberOfAccociationSites()); + KlkTVMatrix = new SimpleMatrix(getTotalNumberOfAccociationSites(), + getTotalNumberOfAccociationSites()); + corr2Matrix = new DMatrixRMaj(getTotalNumberOfAccociationSites(), 1); + corr3Matrix = new DMatrixRMaj(getTotalNumberOfAccociationSites(), 1); + corr4Matrix = new DMatrixRMaj(getTotalNumberOfAccociationSites(), 1); + Klkni = new double[numberOfComponents][getTotalNumberOfAccociationSites()][getTotalNumberOfAccociationSites()]; + ksiMatrix = new SimpleMatrix(getTotalNumberOfAccociationSites(), 1); + uMatrix = new SimpleMatrix(getTotalNumberOfAccociationSites(), 1); + udotMatrix = new SimpleMatrix(getTotalNumberOfAccociationSites(), 1); + moleculeNumber = new int[getTotalNumberOfAccociationSites()]; + assSiteNumber = new int[getTotalNumberOfAccociationSites()]; + gvector = new double[getTotalNumberOfAccociationSites()][1]; + udotTimesmMatrix = new SimpleMatrix(getTotalNumberOfAccociationSites(), 1); + delta = new double[getTotalNumberOfAccociationSites()][getTotalNumberOfAccociationSites()]; + deltaNog = + new double[getTotalNumberOfAccociationSites()][getTotalNumberOfAccociationSites()]; + deltadT = + new double[getTotalNumberOfAccociationSites()][getTotalNumberOfAccociationSites()]; + deltadTdT = + new double[getTotalNumberOfAccociationSites()][getTotalNumberOfAccociationSites()]; + QMatksiksiksi = new SimpleMatrix(getTotalNumberOfAccociationSites(), 1); + udotTimesmiMatrix = + new SimpleMatrix(numberOfComponents, getTotalNumberOfAccociationSites()); + + oldTotalNumberOfAccociationSites = getTotalNumberOfAccociationSites(); + + int temp = 0; + for (int i = 0; i < numberOfComponents; i++) { + for (int j = 0; j < componentArray[i].getNumberOfAssociationSites(); j++) { + moleculeNumber[temp + j] = i; + assSiteNumber[temp + j] = j; + } + temp += componentArray[i].getNumberOfAssociationSites(); + } + } + } + + if (cpamix == null) { + cpamix = cpaSelect.getMixingRule(1, this); + } + if (type > 0) { + calcDelta(); + } + + super.init(totalNumberOfMoles, numberOfComponents, type, phase, beta); + + if (type > 0 && isConstantPhaseVolume()) { + solveX(); + super.init(totalNumberOfMoles, numberOfComponents, 1, phase, beta); + gcpa = calc_g(); + gcpav = calc_lngV(); + gcpavv = calc_lngVV(); + gcpavvv = calc_lngVVV(); + } + + if (type > 0) { + hcpatot = calc_hCPA(); + } + + if (type > 1) { + initCPAMatrix(type); + super.init(totalNumberOfMoles, numberOfComponents, type, phase, beta); + } + } + + /** + *

+ * initCPAMatrix. + *

+ * + * @param type a int + */ + public void initCPAMatrix(int type) { + if (totalNumberOfAccociationSites == 0) { + FCPA = 0.0; + dFCPAdTdV = 0.0; + dFCPAdTdT = 0.0; + dFCPAdT = 0; + dFCPAdV = 0; + dFCPAdVdV = 0.0; + dFCPAdVdVdV = 0.0; + return; + } + + int temp = 0; + double tempVar1, tempVar2; + for (int i = 0; i < numberOfComponents; i++) { + for (int j = 0; j < componentArray[i].getNumberOfAssociationSites(); j++) { + tempVar1 = ksiMatrix.get(temp + j, 0); + tempVar2 = udotMatrix.get(temp + j, 0); + uMatrix.set(temp + j, 0, Math.log(tempVar1) - tempVar1 + 1.0); + gvector[temp + j][0] = mVector.get(temp + j, 0) * tempVar2; + + if (moleculeNumber[temp + j] == i) { + udotTimesmiMatrix.set(i, temp + j, tempVar2); + } else { + udotTimesmiMatrix.set(i, temp + j, 0.0); + } + } + temp += componentArray[i].getNumberOfAssociationSites(); + } + + if (type > 2) { + for (int p = 0; p < numberOfComponents; p++) { + lngi[p] = ((ComponentUMRCPA) componentArray[p]).calc_lngi(this); + } + } + + for (int i = 0; i < totalNumberOfAccociationSites; i++) { + for (int j = i; j < totalNumberOfAccociationSites; j++) { + delta[i][j] = deltaNog[i][j] * gcpa; + delta[j][i] = delta[i][j]; + if (type > 1) { + deltadT[i][j] = cpamix.calcDeltadT(assSiteNumber[i], assSiteNumber[j], + moleculeNumber[i], moleculeNumber[j], this, getTemperature(), + getPressure(), numberOfComponents); + deltadT[j][i] = deltadT[i][j]; + + deltadTdT[i][j] = cpamix.calcDeltadTdT(assSiteNumber[i], assSiteNumber[j], + moleculeNumber[i], moleculeNumber[j], this, getTemperature(), + getPressure(), numberOfComponents); + deltadTdT[j][i] = deltadTdT[i][j]; + } + } + } + + double totalVolume = getTotalVolume(); + double totalVolume2 = totalVolume * totalVolume, totalVolume3 = totalVolume2 * totalVolume; + double gdv1 = getGcpav() - 1.0 / totalVolume; + double gdv2 = gdv1 * gdv1; + double gdv3 = gdv2 * gdv1; + double Klk = 0.0; + double tempVar; + double tempKsiRead = 0.0; + for (int i = 0; i < totalNumberOfAccociationSites; i++) { + for (int j = i; j < totalNumberOfAccociationSites; j++) { + Klk = KlkMatrix.get(i, j); + tempVar = Klk * gdv1; + KlkVMatrix.set(i, j, tempVar); + KlkVMatrix.set(j, i, tempVar); + + tempVar = Klk * gdv2 + Klk * (gcpavv + 1.0 / totalVolume2); + KlkVVMatrix.set(i, j, tempVar); + KlkVVMatrix.set(j, i, tempVar); + + tempVar = Klk * gdv3 + + 3.0 * Klk * (gcpav - 1.0 / totalVolume) * (gcpavv + 1.0 / (totalVolume2)) + + Klk * (gcpavvv - 2.0 / (totalVolume3)); + KlkVVVMatrix.set(i, j, tempVar); + KlkVVVMatrix.set(j, i, tempVar); + + if (type > 1) { + tempVar = deltadT[i][j] / delta[i][j]; + + if (Math.abs(tempVar) > 1e-50) { + double tempVardT = deltadTdT[i][j] / delta[i][j] + - (deltadT[i][j] * deltadT[i][j]) / (delta[i][j] * delta[i][j]); + + tempVar2 = Klk * tempVar; + KlkTMatrix.set(i, j, tempVar2); + KlkTMatrix.set(j, i, tempVar2); + + tempVar2 = Klk * tempVar * (gcpav - 1.0 / totalVolume); + KlkTVMatrix.set(i, j, tempVar2); + KlkTVMatrix.set(j, i, tempVar2); + + tempVar2 = Klk * (tempVar * tempVar + tempVardT); + KlkTTMatrix.set(i, j, tempVar2); + KlkTTMatrix.set(j, i, tempVar2); + } + + if (type > 2) { + for (int p = 0; p < numberOfComponents; p++) { + double t1 = 0.0, t2 = 0.0; + if (moleculeNumber[i] == p) { + t1 = 1.0 / mVector.get(i, 0); + } + if (moleculeNumber[j] == p) { + t2 = 1.0 / mVector.get(j, 0); + } + Klkni[p][i][j] = Klk * (t1 + t2 + lngi[p]);// ((ComponentSrkCPA) + // getComponent(p)).calc_lngi(this)); + Klkni[p][j][i] = Klkni[p][i][j]; + } + } + } + } + tempKsiRead = ksiMatrix.get(i, 0); + QMatksiksiksi.set(i, 0, + 2.0 * mVector.get(i, 0) / (tempKsiRead * tempKsiRead * tempKsiRead)); + } + + SimpleMatrix ksiMatrixTranspose = ksiMatrix.transpose(); + + // dXdV + SimpleMatrix KlkVMatrixksi = KlkVMatrix.mult(ksiMatrix); + SimpleMatrix XV = hessianInvers.mult(KlkVMatrixksi); + SimpleMatrix XVtranspose = XV.transpose(); + + FCPA = mVector.transpose().mult(uMatrix.minus(ksiMatrix.elementMult(udotMatrix).scale(0.5))) + .get(0, 0);// QCPA.get(0, + // 0);//*0.5; + + dFCPAdV = ksiMatrixTranspose.mult(KlkVMatrixksi).get(0, 0) * (-0.5); + SimpleMatrix KlkVVMatrixTImesKsi = KlkVVMatrix.mult(ksiMatrix); + dFCPAdVdV = ksiMatrixTranspose.mult(KlkVVMatrixTImesKsi).scale(-0.5) + .minus(KlkVMatrixksi.transpose().mult(XV)).get(0, 0); + + SimpleMatrix QVVV = ksiMatrixTranspose.mult(KlkVVVMatrix.mult(ksiMatrix));// .scale(-0.5); + SimpleMatrix QVVksi = KlkVVMatrixTImesKsi.scale(-1.0); + SimpleMatrix QksiVksi = KlkVMatrix.scale(-1.0); + + dFCPAdVdVdV = -0.5 * QVVV.get(0, 0) + QVVksi.transpose().mult(XV).get(0, 0) * 3.0 + + XVtranspose.mult(QksiVksi.mult(XV)).get(0, 0) * 3.0 + + XVtranspose.mult(QMatksiksiksi.mult(XVtranspose)).mult(XV).get(0, 0); + + if (type == 1) { + return; + } + + temp = 0; + for (int p = 0; p < numberOfComponents; p++) { + for (int kk = 0; kk < getComponent(p).getNumberOfAssociationSites(); kk++) { + ((ComponentCPAInterface) getComponent(p)).setXsitedV(kk, XV.get(temp + kk, 0)); + } + temp += getComponent(p).getNumberOfAssociationSites(); + } + + // KlkTMatrix = new SimpleMatrix(KlkdT); + SimpleMatrix KlkTMatrixTImesKsi = KlkTMatrix.mult(ksiMatrix); + // dQdT + SimpleMatrix tempMatrix2 = ksiMatrixTranspose.mult(KlkTMatrixTImesKsi);// .scale(-0.5); + dFCPAdT = tempMatrix2.get(0, 0) * (-0.5); + + // SimpleMatrix KlkTVMatrix = new SimpleMatrix(KlkdTdV); + // SimpleMatrix tempMatrixTV = + // ksiMatrixTranspose.mult(KlkTVMatrix.mult(ksiMatrix)).scale(-0.5).minus(KlkTMatrixTImesKsi.transpose().mult(XV)); + // dFCPAdTdV = tempMatrixTV.get(0, 0); + // dXdT + SimpleMatrix XT = hessianInvers.mult(KlkTMatrixTImesKsi); + // dQdTdT + SimpleMatrix tempMatrixTT = ksiMatrixTranspose.mult(KlkTTMatrix.mult(ksiMatrix)).scale(-0.5) + .minus(KlkTMatrixTImesKsi.transpose().mult(XT)); + dFCPAdTdT = tempMatrixTT.get(0, 0); + + SimpleMatrix tempMatrixTV = ksiMatrixTranspose.mult(KlkTVMatrix.mult(ksiMatrix)).scale(-0.5) + .minus(KlkTMatrixTImesKsi.transpose().mult(XV)); + dFCPAdTdV = tempMatrixTV.get(0, 0); + + temp = 0; + for (int p = 0; p < numberOfComponents; p++) { + for (int kk = 0; kk < getComponent(p).getNumberOfAssociationSites(); kk++) { + ((ComponentCPAInterface) getComponent(p)).setXsitedT(kk, XT.get(temp + kk, 0)); + } + temp += getComponent(p).getNumberOfAssociationSites(); + } + + if (type == 2) { + return; + } + + // int assSites = 0; + // if(true) return; + for (int p = 0; p < numberOfComponents; p++) { + SimpleMatrix KiMatrix = new SimpleMatrix(Klkni[p]); + // KiMatrix.print(10,10); + // Matrix dQdniMatrix = + // (ksiMatrix.transpose().times(KiMatrix.times(ksiMatrix)).times(-0.5)); // this + // methods misses one part of .... + // dQdniMatrix.print(10,10); + // KiMatrix.print(10, 10); + // miMatrix.getMatrix(assSites, assSites, 0, totalNumberOfAccociationSites - + // 1).print(10, 10); + // Matrix tempMatrix20 = miMatrix.getMatrix(assSites, assSites, 0, + // totalNumberOfAccociationSites - + // 1).times(uMatrix).minus(ksiMatrix.transpose().times(KiMatrix.times(ksiMatrix)).times(-0.5));// + // ksiMatrix.transpose().times(KlkTMatrix.times(ksiMatrix)).times(-0.5); + // System.out.println("dQdn "); + // tempMatrix20.print(10, 10); + SimpleMatrix tempMatrix4 = KiMatrix.mult(ksiMatrix); + // udotTimesmiMatrix.getMatrix(assSites, assSites, 0, + // totalNumberOfAccociationSites - 1).print(10, 10); + SimpleMatrix tempMatrix5 = + udotTimesmiMatrix.extractVector(true, p).transpose().minus(tempMatrix4); + // tempMki[0] = mki[p]; + // Matrix amatrix = new Matrix(croeneckerProduct(tempMki, + // udotMatrix.getArray())); + // System.out.println("aMatrix "); + // amatrix.transpose().print(10, 10); + // System.out.println("temp4 matrix"); + // tempMatrix4.print(10, 10); + // Matrix tempMatrix5 = amatrix.minus(tempMatrix4); + SimpleMatrix tempMatrix6 = hessianInvers.mult(tempMatrix5);// .scale(-1.0); + // System.out.println("dXdni"); + // tempMatrix4.print(10, 10); + // tempMatrix5.print(10, 10); + // System.out.println("dXdn "); + // tempMatrix6.print(10, 10); + int temp2 = 0; + for (int compp = 0; compp < numberOfComponents; compp++) { + for (int kk = 0; kk < getComponent(compp).getNumberOfAssociationSites(); kk++) { + ((ComponentCPAInterface) getComponent(compp)).setXsitedni(kk, p, + -1.0 * tempMatrix6.get(temp2 + kk, 0)); + } + temp2 += getComponent(compp).getNumberOfAssociationSites(); + } + // assSites += getComponent(p).getNumberOfAssociationSites(); + } + } + + /** {@inheritDoc} */ + @Override + public void setMixingRule(int type) { + super.setMixingRule(type); + cpamix = cpaSelect.getMixingRule(1, this); + } + + /** + *

+ * calcDelta. + *

+ */ + public void calcDelta() { + for (int i = 0; i < getTotalNumberOfAccociationSites(); i++) { + for (int j = i; j < getTotalNumberOfAccociationSites(); j++) { + deltaNog[i][j] = cpamix.calcDeltaNog(assSiteNumber[i], assSiteNumber[j], + moleculeNumber[i], moleculeNumber[j], this, getTemperature(), getPressure(), + numberOfComponents); + deltaNog[j][i] = deltaNog[i][j]; + } + } + } + + /** {@inheritDoc} */ + @Override + public void addcomponent(String componentName, double moles, double molesInPhase, + int compNumber) { + super.addcomponent(componentName, moles, molesInPhase, compNumber); + componentArray[compNumber] = + new ComponentUMRCPA(componentName, moles, molesInPhase, compNumber); + } + + /** {@inheritDoc} */ + @Override + public double getF() { + return super.getF() + cpaon * FCPA(); + } + + /** {@inheritDoc} */ + @Override + public double dFdT() { + return super.dFdT() + cpaon * dFCPAdT(); + } + + /** {@inheritDoc} */ + @Override + public double dFdTdV() { + return super.dFdTdV() + cpaon * dFCPAdTdV(); + } + + /** {@inheritDoc} */ + @Override + public double dFdV() { + double dv2 = dFCPAdV(); + return super.dFdV() + cpaon * dv2; + } + + // @Override + /** {@inheritDoc} */ + @Override + public double dFdVdV() { + return super.dFdVdV() + cpaon * dFCPAdVdV(); + } + + /** {@inheritDoc} */ + @Override + public double dFdVdVdV() { + return super.dFdVdVdV() + cpaon * dFCPAdVdVdV(); + } + + /** {@inheritDoc} */ + @Override + public double dFdTdT() { + return super.dFdTdT() + cpaon * dFCPAdTdT(); + } + + /** + *

+ * FCPA. + *

+ * + * @return a double + */ + public double FCPA() { + /* + * double tot = 0.0; double ans = 0.0; for (int i = 0; i < numberOfComponents; i++) { tot = + * 0.0; for (int j = 0; j < componentArray[i].getNumberOfAssociationSites(); j++) { double + * xai = ((ComponentSrkCPA) componentArray[i]).getXsite()[j]; tot += (Math.log(xai) - 1.0 / + * 2.0 * xai + 1.0 / 2.0); } ans += componentArray[i].getNumberOfMolesInPhase() * tot; } + * return ans; + */ + return FCPA; + } + + /** + *

+ * dFCPAdV. + *

+ * + * @return a double + */ + public double dFCPAdV() { + // return 1.0 / (2.0 * getTotalVolume()) * (1.0 - getTotalVolume() * getGcpav()) + // * hcpatot; + return dFCPAdV; + } + + /** + *

+ * dFCPAdVdV. + *

+ * + * @return a double + */ + public double dFCPAdVdV() { + // double sum1 = -1.0 / 2.0 * gcpavv * hcpatot; + // return -1.0 / getTotalVolume() * dFCPAdV() + sum1; + return dFCPAdVdV; + } + + /** + *

+ * dFCPAdVdVdV. + *

+ * + * @return a double + */ + public double dFCPAdVdVdV() { + return dFCPAdVdVdV; + // return -1.0 / getTotalVolume() * dFCPAdVdV() + 1.0 / + // Math.pow(getTotalVolume(), 2.0) * dFCPAdV() - hcpatot / (2.0 * + // Math.pow(getTotalVolume(), 2.0)) * (-getGcpav() - getTotalVolume() * gcpavv) + // + hcpatot / (2.0 * getTotalVolume()) * (-gcpavv - getTotalVolume() * gcpavvv + // - gcpavv); + } + + /** + *

+ * dFCPAdT. + *

+ * + * @return a double + */ + public double dFCPAdT() { + /* + * double tot = 0.0; double ans = 0.0; for (int i = 0; i < numberOfComponents; i++) { tot = + * 0.0; for (int j = 0; j < componentArray[i].getNumberOfAssociationSites(); j++) { double + * xai = ((ComponentSrkCPA) componentArray[i]).getXsite()[j]; double xaidT = + * ((ComponentSrkCPA) componentArray[i]).getXsitedT()[j]; tot += 1.0 / xai * xaidT - 0.5 * + * xaidT;// - 1.0 / 2.0 * xai + 1.0 / 2.0); } ans += + * componentArray[i].getNumberOfMolesInPhase() * tot; } System.out.println("dFCPAdT1 " + + * ans + " dfcpa2 " +dFCPAdT); return ans; + */ + return dFCPAdT; + } + + /** + *

+ * dFCPAdTdT. + *

+ * + * @return a double + */ + public double dFCPAdTdT() { + return dFCPAdTdT; + } + + /** + *

+ * dFCPAdTdV. + *

+ * + * @return a double + */ + public double dFCPAdTdV() { + // System.out.println("dFCPAdTdV1 " + dFCPAdTdV + " dFCPAdTdV " +( 1.0 / (2.0 * + // getTotalVolume()) * (1.0 - getTotalVolume() * getGcpav()) * hcpatotdT)); + return dFCPAdTdV; + /* + * if (totalNumberOfAccociationSites > 0) { return 1.0 / (2.0 * getTotalVolume()) * (1.0 - + * getTotalVolume() * getGcpav()) * hcpatotdT; } else { return 0; } + */ + } + + /** {@inheritDoc} */ + @Override + public double molarVolume(double pressure, double temperature, double A, double B, + int phasetype) throws neqsim.util.exception.IsNaNException, + neqsim.util.exception.TooManyIterationsException { + double BonV = phasetype == 0 ? 2.0 / (2.0 + temperature / getPseudoCriticalTemperature()) + : pressure * getB() / (numberOfMolesInPhase * temperature * R); + + if (BonV < 0) { + BonV = 1.0e-8; + } + + if (BonV >= 1.0) { + BonV = 0.9999; + } + double BonVold; + double BonV2; + double h = 0, dh = 0, dhh = 0; + double d1 = 0, d2 = 0; + double Btemp = getB(); + if (Btemp < 0) { + logger.info("b negative in volume calc"); + } + + setMolarVolume(1.0 / BonV * Btemp / numberOfMolesInPhase); + int iterations = 0; + int maxIterations = 300; + do { + iterations++; + gcpa = calc_g(); + if (gcpa < 0) { + setMolarVolume(1.0 / Btemp / numberOfMolesInPhase); + gcpa = calc_g(); + } + + // lngcpa = + // Math.log(gcpa); + gcpav = calc_lngV(); + gcpavv = calc_lngVV(); + gcpavvv = calc_lngVVV(); + + if (totalNumberOfAccociationSites > 0) { + solveX(); + } + + initCPAMatrix(1); + + BonV2 = BonV * BonV; + BonVold = BonV; + h = BonV - Btemp / numberOfMolesInPhase * dFdV() + - pressure * Btemp / (numberOfMolesInPhase * R * temperature); + dh = 1.0 + Btemp / (BonV2) * (Btemp / numberOfMolesInPhase * dFdVdV()); + dhh = -2.0 * Btemp / (BonV2 * BonV) * (Btemp / numberOfMolesInPhase * dFdVdV()) + - (Btemp * Btemp) / (BonV2 * BonV2) + * (Btemp / numberOfMolesInPhase * dFdVdVdV()); + + d1 = -h / dh; + d2 = -dh / dhh; + // System.out.println("h " + h + " iter " + iterations + " " + d1 + " d2 " + d2 + // + " d1 / d2 " + (d1 / d2)); + if (Math.abs(d1 / d2) <= 1.0) { + BonV += d1 * (1.0 + 0.5 * d1 / d2); + } else if (d1 / d2 < -1) { + BonV += 0.5 * d1; + } else if (d1 > d2) { + return molarVolumeChangePhase(pressure, temperature, A, B, phasetype); + // BonV += d2; + // double hnew = h + d2 * dh; + // if (Math.abs(hnew) > Math.abs(h)) { + // BonV = phasetype == 1 ? 2.0 / (2.0 + temperature / + // getPseudoCriticalTemperature()) : pressure * getB() / (numberOfMolesInPhase * + // temperature * R); + // } + } else { + BonV += 0.5 * d1; + } + if (Math.abs((BonV - BonVold) / BonV) > 0.1) { + BonV = BonVold + 0.1 * (BonV - BonVold); + } + if (BonV < 0) { + if (iterations < 10) { + // System.out.println(iterations + " BonV " + BonV); + BonV = (BonVold + BonV) / 2.0; + } else { + return molarVolumeChangePhase(pressure, temperature, A, B, phasetype); + } + } + + if (BonV >= 1.0) { + if (iterations < 10) { + BonV = (BonVold + BonV) / 2.0; + } else { + return molarVolumeChangePhase(pressure, temperature, A, B, phasetype); + } + } + /* + * if (BonV > 0.9999) { if (iterations < 10) { BonV = (BonVold + BonV) / 2.0; } else { + * // BonV = calcRootVolFinder(phasetype); // BonV = molarVolumeChangePhase(pressure, + * temperature, A, B, phasetype); // BonV = 0.9999; // BonV = phasetype == 1 ? 2.0 / + * (2.0 + temperature / getPseudoCriticalTemperature()) : pressure * getB() / + * (numberOfMolesInPhase * temperature * R); } + * + * } else if (BonV < 0) { if (iterations < 10) { BonV = Math.abs(BonVold + BonV) / 2.0; + * } else { // BonV = calcRootVolFinder(phasetype); // return + * molarVolumeChangePhase(pressure, temperature, A, B, phasetype); // BonV = phasetype + * == 1 ? 2.0 / (2.0 + temperature / getPseudoCriticalTemperature()) : pressure * getB() + * / (numberOfMolesInPhase * temperature * R); } } + */ + setMolarVolume(1.0 / BonV * Btemp / numberOfMolesInPhase); + Z = pressure * getMolarVolume() / (R * temperature); + } while ((Math.abs((BonV - BonVold) / BonV) > 1.0e-10 || Math.abs(h) > 1e-12) + && iterations < maxIterations); + + // System.out.println("h failed " + h + " Z" + Z + " iterations " + iterations + + // " BonV " + BonV); + // if (Math.abs(h) > 1e-12) { + // System.out.println("h failed " + h + " Z" + Z + " iterations " + iterations + + // " BonV " + BonV); + // return molarVolumeChangePhase(pressure, temperature, A, B, phasetype); + // return molarVolumeChangePhase(pressure, temperature, A, B, phasetype); + // } + // System.out.println("Z" + Z + " iterations " + iterations + " BonV " + BonV); + // System.out.println("pressure " + Z*R*temperature/getMolarVolume()); + // System.out.println("volume " + getTotalVolume() + " molar volume " + + // getMolarVolume()); + // if(iterations>=100) throw new util.exception.TooManyIterationsException(); + // System.out.println("error in volume " + + // (-pressure+R*temperature/getMolarVolume()-R*temperature*dFdV()));// + " + // firstterm " + (R*temperature/molarVolume) + " second " + + // R*temperature*dFdV()); + // System.out.println("BonV: " + BonV + " "+" itert: " + iterations +" " +h + " + // " +dh + " B " + Btemp + " gv" + gV() + " fv " + fv() + " fvv" + fVV()); + if (Double.isNaN(getMolarVolume())) { + throw new neqsim.util.exception.IsNaNException(this, "molarVolume", "Molar volume"); + // System.out.println("BonV: " + BonV + " "+" itert: " + iterations +" " +h + " + // " +dh + " B " + Btemp + " D " + Dtemp + " gv" + gV() + " fv " + fv() + " fvv" + // + fVV()); + } + dFdNtemp = calcdFdNtemp(); + return getMolarVolume(); + } + + /** + * @return double[] + */ + double[] calcdFdNtemp() { + double tot1 = 0.0, tot2 = 0.0, tot3 = 0.0, tot4 = 0.0; + // double temp, temp2; + for (int k = 0; k < getNumberOfComponents(); k++) { + tot2 = 0.0; + tot3 = 0.0; + // temp = ((ComponentSrkCPA) getComponent(k)).calc_lngi(this); + // temp2 = ((ComponentSrkCPA) getComponent(k)).calc_lngidV(this); + for (int i = 0; i < getComponent(k).getNumberOfAssociationSites(); i++) { + tot2 -= 1.0 * ((ComponentUMRCPA) getComponent(k)).getXsitedV()[i]; + tot3 += (1.0 - ((ComponentUMRCPA) getComponent(k)).getXsite()[i]) * 1.0; + } + tot1 += 1.0 / 2.0 * tot2 * getComponent(k).getNumberOfMolesInPhase(); + tot4 += 0.5 * getComponent(k).getNumberOfMolesInPhase() * tot3; + } + return new double[] {-tot1, -tot4}; + } + + /** + *

+ * calc_hCPA. + *

+ * + * @return a double + */ + public double calc_hCPA() { + double htot = 0.0; + double tot = 0.0; + for (int i = 0; i < numberOfComponents; i++) { + htot = 0.0; + for (int j = 0; j < componentArray[i].getNumberOfAssociationSites(); j++) { + htot += (1.0 - ((ComponentUMRCPA) componentArray[i]).getXsite()[j]); + } + tot += componentArray[i].getNumberOfMolesInPhase() * htot; + } + return tot; + } + + /** + *

+ * calc_g. + *

+ * + * @return a double + */ + public double calc_g() { + tempTotVol = getMolarVolume(); + double temp = 1.0 - getb() / 4.0 / tempTotVol; + return (2.0 - getb() / 4.0 / tempTotVol) / (2.0 * temp * temp * temp); + } + + /** + *

+ * calc_lngV. + *

+ * + * @return a double + */ + public double calc_lngV() { + tempTotVol = getMolarVolume(); + // gv = -2.0 * getB() * (10.0 * getTotalVolume() - getB()) / getTotalVolume() / + // ((8.0 * getTotalVolume() - getB()) * (4.0 * getTotalVolume() - getB())); + return 1.0 / (2.0 - getB() / (4.0 * tempTotVol)) * getB() / (4.0 * tempTotVol * tempTotVol) + - 3.0 / (1.0 - getB() / (4.0 * tempTotVol)) * getB() + / (4.0 * tempTotVol * tempTotVol); + } + + /** + *

+ * calc_lngVV. + *

+ * + * @return a double + */ + public double calc_lngVV() { + tempTotVol = getMolarVolume(); + return 2.0 + * (640.0 * Math.pow(tempTotVol, 3.0) - 216.0 * getB() * tempTotVol * tempTotVol + + 24.0 * Math.pow(getB(), 2.0) * tempTotVol - Math.pow(getB(), 3.0)) + * getB() / (tempTotVol * tempTotVol) / Math.pow(8.0 * tempTotVol - getB(), 2.0) + / Math.pow(4.0 * tempTotVol - getB(), 2.0); + } + + /** + *

+ * calc_lngVVV. + *

+ * + * @return a double + */ + public double calc_lngVVV() { + tempTotVol = getMolarVolume(); + return 4.0 + * (Math.pow(getB(), 5.0) + 17664.0 * Math.pow(tempTotVol, 4.0) * getB() + - 4192.0 * Math.pow(tempTotVol, 3.0) * Math.pow(getB(), 2.0) + + 528.0 * Math.pow(getB(), 3.0) * tempTotVol * tempTotVol + - 36.0 * tempTotVol * Math.pow(getB(), 4.0) + - 30720.0 * Math.pow(tempTotVol, 5.0)) + * getB() / (Math.pow(tempTotVol, 3.0)) / Math.pow(-8.0 * tempTotVol + getB(), 3.0) + / Math.pow(-4.0 * tempTotVol + getB(), 3.0); + } + + /** + *

+ * calcXsitedV. + *

+ */ + public void calcXsitedV() { + if (getTotalNumberOfAccociationSites() > 0) { + initCPAMatrix(1); + } + } + + /** + *

+ * solveX. + *

+ * + * @return a boolean + */ + public boolean solveX() { + if (totalNumberOfAccociationSites == 0) { + return true; + } + + boolean solvedX = solveX2(15); + + DMatrixRMaj mVectorMat = mVector.getMatrix(); + DMatrixRMaj ksiMatrixMat = ksiMatrix.getMatrix(); + + // ksiMatrix.print(); + // second order method not working correctly and not used t the moment b ecause of numerical + // stability + int temp = 0, iter = 0; + for (int i = 0; i < numberOfComponents; i++) { + for (int j = 0; j < componentArray[i].getNumberOfAssociationSites(); j++) { + mVectorMat.unsafe_set(temp + j, 0, componentArray[i].getNumberOfMolesInPhase()); + } + temp += componentArray[i].getNumberOfAssociationSites(); + } + + DMatrixRMaj mat1 = KlkMatrix.getMatrix(); + double Klk = 0.0; + double totvolume = getTotalVolume(); + double tempVari, tempVarj; + for (int i = 0; i < getTotalNumberOfAccociationSites(); i++) { + tempVari = mVectorMat.unsafe_get(i, 0); + for (int j = i; j < getTotalNumberOfAccociationSites(); j++) { + tempVarj = mVectorMat.unsafe_get(j, 0); + Klk = tempVari * tempVarj / totvolume * delta[i][j]; + mat1.unsafe_set(i, j, Klk); + mat1.unsafe_set(j, i, Klk); + } + } + boolean solved = true; + // SimpleMatrix corrMatrix = null; + do { + solved = true; + iter++; + temp = 0; + double ksi = 0; + + double temp1, temp2; + for (int i = 0; i < numberOfComponents; i++) { + temp1 = componentArray[i].getNumberOfMolesInPhase(); + for (int j = 0; j < componentArray[i].getNumberOfAssociationSites(); j++) { + ksi = ((ComponentUMRCPA) componentArray[i]).getXsite()[j]; + ksiMatrixMat.unsafe_set(temp + j, 0, ksi); + // ksiMatrix.getMatrix().unsafe_set(temp + j, 0, + // ksiMatrix.getMatrix().unsafe_get(temp + j, 0)); + tempVari = 1.0 / ksi - 1.0; + udotMatrix.set(temp + j, 0, tempVari); + udotTimesmMatrix.set(temp + j, 0, temp1 * tempVari); + } + temp += componentArray[i].getNumberOfAssociationSites(); + } + + int krondelt; + for (int i = 0; i < getTotalNumberOfAccociationSites(); i++) { + temp1 = mVectorMat.unsafe_get(i, 0); + temp2 = ksiMatrix.get(i, 0); + for (int j = i; j < getTotalNumberOfAccociationSites(); j++) { + krondelt = 0; + if (i == j) { + krondelt = 1; + } + tempVari = -temp1 / (temp2 * temp2) * krondelt - mat1.unsafe_get(i, j); + hessianMatrix.set(i, j, tempVari); + hessianMatrix.set(j, i, tempVari); + } + } + + // ksiMatrix = new SimpleMatrix(ksi); + // SimpleMatrix hessianMatrix = new SimpleMatrix(hessian); + try { + hessianInvers = hessianMatrix.invert(); + } catch (Exception e) { + logger.error("error", e); + return false; + } + if (solvedX) { + // System.out.println("solvedX "); + return true; + } + + DMatrixRMaj mat2 = ksiMatrix.getMatrix(); + CommonOps_DDRM.mult(mat1, mat2, corr2Matrix); + CommonOps_DDRM.subtract(udotTimesmMatrix.getDDRM(), corr2Matrix, corr3Matrix); + CommonOps_DDRM.mult(hessianInvers.getDDRM(), corr3Matrix, corr4Matrix); + // SimpleMatrix gMatrix = udotTimesmMatrix.minus(KlkMatrix.mult(ksiMatrix)); + // corrMatrix = + // hessianInvers.mult(udotTimesmMatrix.minus(KlkMatrix.mult(ksiMatrix)));//.scale(-1.0); + temp = 0; + // System.out.println("print SimpleMatrix ..."); + // corrMatrix.print(10, 10); + // SimpleMatrix simp = new SimpleMatrix(corr4Matrix); + // System.out.println("print CommonOps ..."); + // simp.print(10,10); + double newX; + for (int i = 0; i < numberOfComponents; i++) { + for (int j = 0; j < componentArray[i].getNumberOfAssociationSites(); j++) { + newX = ksiMatrix.get(temp + j, 0) - corr4Matrix.unsafe_get((temp + j), 0); + if (newX < 0) { + newX = 1e-10; + solved = false; + } + ((ComponentCPAInterface) componentArray[i]).setXsite(j, newX); + } + temp += componentArray[i].getNumberOfAssociationSites(); + } + // System.out.println("corrmatrix error " ); + // System.out.println("error " + NormOps_DDRM.normF(corr4Matrix)); + } while ((NormOps_DDRM.normF(corr4Matrix) > 1e-12 || !solved) && iter < 100); + + // System.out.println("iter " + iter + " error " + + // NormOps_DDRM.normF(corr4Matrix)); // corrMatrix.print(10, 10); + // ksiMatrix.print(10, 10); + return true; + } + + /** + *

+ * solveX2. + *

+ * + * @param maxIter a int + * @return a boolean + */ + public boolean solveX2(int maxIter) { + double err = .0, totalVolume = getTotalVolume(); + int iter = 0; + // if (delta == null) { + // initCPAMatrix(1); + double old = 0.0, neeval = 0.0; + // } + do { + iter++; + err = 0.0; + for (int i = 0; i < totalNumberOfAccociationSites; i++) { + old = ((ComponentUMRCPA) componentArray[moleculeNumber[i]]) + .getXsite()[assSiteNumber[i]]; + neeval = 0.0; + for (int j = 0; j < totalNumberOfAccociationSites; j++) { + neeval += componentArray[moleculeNumber[j]].getNumberOfMolesInPhase() + * delta[i][j] * ((ComponentUMRCPA) componentArray[moleculeNumber[j]]) + .getXsite()[assSiteNumber[j]]; + } + neeval = 1.0 / (1.0 + 1.0 / totalVolume * neeval); + ((ComponentUMRCPA) componentArray[moleculeNumber[i]]).setXsite(assSiteNumber[i], + neeval); + err += Math.abs((old - neeval) / neeval); + } + } while (Math.abs(err) > 1e-12 && iter < maxIter); + // System.out.println("iter " + iter); + if (Math.abs(err) < 1e-12) { + return true; + } else { + // System.out.println("did not solve for Xi in iterations: " + iter); + // System.out.println("error: " + err); + return false; + } + } + + /** {@inheritDoc} */ + @Override + public double getHcpatot() { + return hcpatot; + } + + /** + * Setter for property hcpatot. + * + * @param hcpatot New value of property hcpatot. + */ + public void setHcpatot(double hcpatot) { + this.hcpatot = hcpatot; + } + + /** {@inheritDoc} */ + @Override + public double getGcpa() { + return gcpa; + } + + /** + *

+ * calcRootVolFinder. + *

+ * + * @param phase a int + * @return a double + */ + public double calcRootVolFinder(int phase) { + double solvedBonVHigh = 0.0; + double solvedBonVlow = 1.0; + double oldh = 1; + // double[][] matrix = new double[2][2000]; + double BonV = 1.0 - 1e-10; + try { + // molarVolume(pressure, temperature, A, B, phaseType); + } catch (Exception e) { + logger.error("error", e); + } + double BonVold = BonV; + double Btemp = 0, h = 1; + // double Dtemp = 0, dh = 0, gvvv = 0, fvvv = 0, dhh = 0; + // double d1 = 0, d2 = 0; + Btemp = getB(); + // Dtemp = getA(); + setMolarVolume(1.0 / BonV * Btemp / numberOfMolesInPhase); + for (int i = 0; i < 2000; i++) { + BonVold = BonV; + BonV = 1.0 - (i + 1e-6) * 1.0 / 2000.0; + setMolarVolume(1.0 / BonV * Btemp / numberOfMolesInPhase); + Z = pressure * getMolarVolume() / (R * temperature); + gcpa = calc_g(); + // lngcpa = + // Math.log(gcpa); + setGcpav(calc_lngV()); + gcpavv = calc_lngVV(); + gcpavvv = calc_lngVVV(); + + do { + } while (!solveX()); + + h = BonV - Btemp / numberOfMolesInPhase * dFdV() + - pressure * Btemp / (numberOfMolesInPhase * R * temperature); + + if (Math.signum(h) * Math.signum(oldh) < 0 && i > 2) { + if (solvedBonVlow < 1e-3) { + solvedBonVlow = (BonV + BonVold) / 2.0; + if (phase == 1) { + break; + } + } else { + solvedBonVHigh = (BonV + BonVold) / 2.0; + if (phase == 0) { + break; + } + } + } + solvedBonVHigh = (BonV + BonVold) / 2.0; + oldh = h; + // matrix[0][i] = BonV; + // matrix[1][i] = h; + } + if (solvedBonVlow < 1e-3) { + solvedBonVlow = solvedBonVHigh; + } + // dataPresentation.fileHandeling.createTextFile.TextFile file = new + // dataPresentation.fileHandeling.createTextFile.TextFile(); + // file.setValues(matrix); + // file.setOutputFileName("D:/temp/temp2.txt"); + // file.createFile(); + if (phase == 1) { + return solvedBonVlow; + } else { + return solvedBonVHigh; + } + } + + /** + *

+ * molarVolumeChangePhase. + *

+ * + * @param pressure a double + * @param temperature a double + * @param A a double + * @param B a double + * @param phasetype a int + * @return a double + * @throws neqsim.util.exception.IsNaNException if any. + * @throws neqsim.util.exception.TooManyIterationsException if any. + */ + public double molarVolumeChangePhase(double pressure, double temperature, double A, double B, + int phasetype) throws neqsim.util.exception.IsNaNException, + neqsim.util.exception.TooManyIterationsException { + double BonV = phasetype == 1 ? 2.0 / (2.0 + temperature / getPseudoCriticalTemperature()) + : pressure * getB() / (numberOfMolesInPhase * temperature * R); + // double BonV = calcRootVolFinder(phasetype); + // double BonVInit = BonV; + if (BonV < 0) { + BonV = 1.0e-8; + } + + if (BonV >= 1.0) { + BonV = 0.9999; + } + double BonVold = BonV; + double Btemp = 0, h = 0, dh = 0, dhh = 0; + // double gvvv = 0, fvvv = 0; + double d1 = 0, d2 = 0; + Btemp = getB(); + if (Btemp < 0) { + logger.info("b negative in volume calc"); + } + calcDelta(); + + setMolarVolume(1.0 / BonV * Btemp / numberOfMolesInPhase); + int iterations = 0; + + do { + iterations++; + gcpa = calc_g(); + if (gcpa < 0) { + setMolarVolume(1.0 / Btemp / numberOfMolesInPhase); + gcpa = calc_g(); + } + + // lngcpa = + // Math.log(gcpa); + setGcpav(calc_lngV()); + gcpavv = calc_lngVV(); + gcpavvv = calc_lngVVV(); + + solveX(); + + initCPAMatrix(1); + double BonV2 = BonV * BonV; + BonVold = BonV; + h = BonV - Btemp / numberOfMolesInPhase * dFdV() + - pressure * Btemp / (numberOfMolesInPhase * R * temperature); + dh = 1.0 + Btemp / (BonV2) * (Btemp / numberOfMolesInPhase * dFdVdV()); + dhh = -2.0 * Btemp / (BonV2 * BonV) * (Btemp / numberOfMolesInPhase * dFdVdV()) + - (Btemp * Btemp) / (BonV2 * BonV2) + * (Btemp / numberOfMolesInPhase * dFdVdVdV()); + + d1 = -h / dh; + d2 = -dh / dhh; + // System.out.println("d1" + d1 + " d2 " + d2 + " d1 / d2 " + (d1 / d2)); + if (Math.abs(d1 / d2) <= 1.0) { + BonV += d1 * (1.0 + 0.5 * d1 / d2); + } else if (d1 / d2 < -1) { + BonV += 0.5 * d1; + } else if (d1 > d2) { + BonV += d2; + double hnew = h + d2 * dh; + if (Math.abs(hnew) > Math.abs(h)) { + BonV = phasetype == 1 + ? 2.0 / (2.0 + temperature / getPseudoCriticalTemperature()) + : pressure * getB() / (numberOfMolesInPhase * temperature * R); + } + } else { + BonV += 0.5 * d1; + } + if (Math.abs((BonV - BonVold) / BonVold) > 0.1) { + BonV = BonVold + 0.1 * (BonV - BonVold); + } + + if (BonV > 1.1) { + if (iterations < 3) { + BonV = (BonVold + BonV) / 2.0; + } else { + BonV = phasetype == 1 + ? 2.0 / (2.0 + temperature / getPseudoCriticalTemperature()) + : pressure * getB() / (numberOfMolesInPhase * temperature * R); + } + } + + if (BonV < 0) { + if (iterations < 3) { + BonV = Math.abs(BonVold + BonV) / 2.0; + } else { + BonV = phasetype == 1 + ? 2.0 / (2.0 + temperature / getPseudoCriticalTemperature()) + : pressure * getB() / (numberOfMolesInPhase * temperature * R); + } + } + + setMolarVolume(1.0 / BonV * Btemp / numberOfMolesInPhase); + Z = pressure * getMolarVolume() / (R * temperature); + + // System.out.println("Z " + Z + "h " + h + " BONV " + (Math.abs((BonV - + // BonVold) / BonV))); + } while ((Math.abs((BonV - BonVold) / BonV) > 1.0e-10) && iterations < 100); + + /* + * if (Math.abs(h) > 1e-8) { if (phasetype == 0) { molarVolume(pressure, temperature, A, B, + * 1); } else { molarVolume(pressure, temperature, A, B, 0); } return getMolarVolume(); } + */ + // System.out.println("Z" + Z + " iterations " + iterations + " BonV " + BonV); + // System.out.println("pressure " + Z*R*temperature/getMolarVolume()); + // System.out.println("volume " + getTotalVolume() + " molar volume " + + // getMolarVolume()); + // if(iterations>=100) throw new util.exception.TooManyIterationsException(); + // System.out.println("error in volume " + + // (-pressure+R*temperature/getMolarVolume()-R*temperature*dFdV()));// + " + // firstterm " + (R*temperature/molarVolume) + " second " + + // R*temperature*dFdV()); + // System.out.println("BonV: " + BonV + " "+" itert: " + iterations +" " +h + " " +dh + " B + // " + Btemp + " gv" + gV() + " fv " + fv() + " fvv" + fVV()); + if (Double.isNaN(getMolarVolume())) { + throw new neqsim.util.exception.IsNaNException(this, "molarVolumeChangePhase", + "Molar volume"); + // System.out.println("BonV: " + BonV + " "+" itert: " + iterations +" " +h + " + // " +dh + " B " + Btemp + " D " + Dtemp + " gv" + gV() + " fv " + fv() + " fvv" + // + fVV()); + } + + return getMolarVolume(); + } + + /** {@inheritDoc} */ + @Override + public double getGcpav() { + return gcpav; + } + + /** + *

+ * Setter for the field gcpav. + *

+ * + * @param gcpav a double + */ + public void setGcpav(double gcpav) { + this.gcpav = gcpav; + } + + /** {@inheritDoc} */ + @Override + public CPAMixingInterface getCpamix() { + return cpamix; + } + + /** {@inheritDoc} */ + @Override + public double calcPressure() { + gcpa = calc_g(); + // lngcpa = + // Math.log(gcpa); + setGcpav(calc_lngV()); + gcpavv = calc_lngVV(); + gcpavvv = calc_lngVVV(); + solveX(); + hcpatot = calc_hCPA(); + + initCPAMatrix(1); + return super.calcPressure(); + } + + /** {@inheritDoc} */ + @Override + public int getCrossAssosiationScheme(int comp1, int comp2, int site1, int site2) { + if (comp1 == comp2) { + return selfAccociationScheme[comp1][site1][site2]; + } else { + return crossAccociationScheme[comp1][comp2][site1][site2]; + } + } + + /** + *

+ * croeneckerProduct. + *

+ * + * @param a an array of {@link double} objects + * @param b an array of {@link double} objects + * @return an array of {@link double} objects + */ + public double[][] croeneckerProduct(double[][] a, double[][] b) { + int aLength = a.length; + int aCols = a[0].length; + int bLength = b.length; + int bCols = b[0].length; + double[][] result = new double[aLength * bLength][(aCols) * (bCols)]; + for (int z = 0; z < aLength; z++) { + for (int i = 0; i < aCols; i++) { + for (int j = 0; j < bLength; j++) { + for (int k = 0; k < bCols; k++) { + result[j + (z * bLength)][k + (i * bCols)] = a[z][i] * b[j][k]; + } + } + } + } + return result; + } + + /** {@inheritDoc} */ + @Override + public int getTotalNumberOfAccociationSites() { + return totalNumberOfAccociationSites; + } + + /** {@inheritDoc} */ + @Override + public void setTotalNumberOfAccociationSites(int totalNumberOfAccociationSites) { + this.totalNumberOfAccociationSites = totalNumberOfAccociationSites; + } + + /** + *

+ * initOld2. + *

+ * + * @param totalNumberOfMoles a double + * @param numberOfComponents a int + * @param type a int + * @param phase a int + * @param beta a double + */ + public void initOld2(double totalNumberOfMoles, int numberOfComponents, int type, int phase, + double beta) { // type + // = 0 + // start + // init + // type + // =1 gi + // nye + // betingelser + if (type == 0) { + setTotalNumberOfAccociationSites(0); + selfAccociationScheme = new int[numberOfComponents][0][0]; + crossAccociationScheme = new int[numberOfComponents][numberOfComponents][0][0]; + for (int i = 0; i < numberOfComponents; i++) { + if (componentArray[i].getNumberOfmoles() < 1e-50) { + componentArray[i].setNumberOfAssociationSites(0); + } else { + componentArray[i].setNumberOfAssociationSites( + componentArray[i].getOrginalNumberOfAssociationSites()); + setTotalNumberOfAccociationSites(getTotalNumberOfAccociationSites() + + componentArray[i].getNumberOfAssociationSites()); + selfAccociationScheme[i] = cpaSelect.setAssociationScheme(i, this); + for (int j = 0; j < numberOfComponents; j++) { + crossAccociationScheme[i][j] = + cpaSelect.setCrossAssociationScheme(i, j, this); + } + } + } + + // had to remove if below - dont understand why.. Even + // if (getTotalNumberOfAccociationSites() != oldTotalNumberOfAccociationSites) { + mVector = new SimpleMatrix(getTotalNumberOfAccociationSites(), 1); + KlkMatrix = new SimpleMatrix(getTotalNumberOfAccociationSites(), + getTotalNumberOfAccociationSites()); + KlkVMatrix = new SimpleMatrix(getTotalNumberOfAccociationSites(), + getTotalNumberOfAccociationSites()); + KlkVVMatrix = new SimpleMatrix(getTotalNumberOfAccociationSites(), + getTotalNumberOfAccociationSites()); + KlkVVVMatrix = new SimpleMatrix(getTotalNumberOfAccociationSites(), + getTotalNumberOfAccociationSites()); + hessianMatrix = new SimpleMatrix(getTotalNumberOfAccociationSites(), + getTotalNumberOfAccociationSites()); + KlkTMatrix = new SimpleMatrix(getTotalNumberOfAccociationSites(), + getTotalNumberOfAccociationSites()); + KlkTTMatrix = new SimpleMatrix(getTotalNumberOfAccociationSites(), + getTotalNumberOfAccociationSites()); + KlkTVMatrix = new SimpleMatrix(getTotalNumberOfAccociationSites(), + getTotalNumberOfAccociationSites()); + corr2Matrix = new DMatrixRMaj(getTotalNumberOfAccociationSites(), 1); + corr3Matrix = new DMatrixRMaj(getTotalNumberOfAccociationSites(), 1); + corr4Matrix = new DMatrixRMaj(getTotalNumberOfAccociationSites(), 1); + Klkni = new double[numberOfComponents][getTotalNumberOfAccociationSites()][getTotalNumberOfAccociationSites()]; + ksiMatrix = new SimpleMatrix(getTotalNumberOfAccociationSites(), 1); + uMatrix = new SimpleMatrix(getTotalNumberOfAccociationSites(), 1); + udotMatrix = new SimpleMatrix(getTotalNumberOfAccociationSites(), 1); + moleculeNumber = new int[getTotalNumberOfAccociationSites()]; + assSiteNumber = new int[getTotalNumberOfAccociationSites()]; + gvector = new double[getTotalNumberOfAccociationSites()][1]; + udotTimesmMatrix = new SimpleMatrix(getTotalNumberOfAccociationSites(), 1); + delta = new double[getTotalNumberOfAccociationSites()][getTotalNumberOfAccociationSites()]; + deltaNog = + new double[getTotalNumberOfAccociationSites()][getTotalNumberOfAccociationSites()]; + deltadT = + new double[getTotalNumberOfAccociationSites()][getTotalNumberOfAccociationSites()]; + deltadTdT = + new double[getTotalNumberOfAccociationSites()][getTotalNumberOfAccociationSites()]; + QMatksiksiksi = new SimpleMatrix(getTotalNumberOfAccociationSites(), 1); + // } + udotTimesmiMatrix = + new SimpleMatrix(getNumberOfComponents(), getTotalNumberOfAccociationSites()); + + oldTotalNumberOfAccociationSites = getTotalNumberOfAccociationSites(); + + int temp = 0; + for (int i = 0; i < numberOfComponents; i++) { + for (int j = 0; j < componentArray[i].getNumberOfAssociationSites(); j++) { + moleculeNumber[temp + j] = i; + assSiteNumber[temp + j] = j; + } + temp += componentArray[i].getNumberOfAssociationSites(); + } + } + if (cpamix == null) { + cpamix = cpaSelect.getMixingRule(1, this); + } + + super.init(totalNumberOfMoles, numberOfComponents, type, phase, beta); + if (type > 0 && isConstantPhaseVolume()) { + calcDelta(); + solveX(); + super.init(totalNumberOfMoles, numberOfComponents, 1, phase, beta); + gcpa = calc_g(); + // lngcpa = Math.log(gcpa); + setGcpav(calc_lngV()); + gcpavv = calc_lngVV(); + gcpavvv = calc_lngVVV(); + } + + if (type > 0) { + hcpatot = calc_hCPA(); + } + + if (type > 1) { + initCPAMatrix(type); + // hcpatotdT = calc_hCPAdT(); + // super.init(totalNumberOfMoles, numberOfComponents, type, phase, beta); + } + } + + /** {@inheritDoc} */ + @Override + public double molarVolume2(double pressure, double temperature, double A, double B, int phase) + throws neqsim.util.exception.IsNaNException, + neqsim.util.exception.TooManyIterationsException { + Z = phase == 0 ? 1.0 : 1.0e-5; + setMolarVolume(Z * R * temperature / pressure); + // super.molarVolume(pressure,temperature, A, B, phase); + int iterations = 0; + double err = 0.0, dErrdV = 0.0; + double deltaV = 0; + + do { + A = calcA(this, temperature, pressure, numberOfComponents); + B = calcB(this, temperature, pressure, numberOfComponents); + + double dFdV = dFdV(), dFdVdV = dFdVdV(); + // double dFdVdVdV = dFdVdVdV(); + // double factor1 = 1.0e0, factor2 = 1.0e0; + err = -R * temperature * dFdV + R * temperature / getMolarVolume() - pressure; + + // System.out.println("pressure " + -R * temperature * dFdV + " " + R * + // temperature / getMolarVolume()); + // -pressure; + dErrdV = -R * temperature * dFdVdV + - R * temperature * numberOfMolesInPhase / Math.pow(getVolume(), 2.0); + + // System.out.println("errdV " + dErrdV); + // System.out.println("err " + err); + deltaV = -err / dErrdV; + + setMolarVolume(getMolarVolume() + deltaV / numberOfMolesInPhase); + + Z = pressure * getMolarVolume() / (R * temperature); + if (Z < 0) { + Z = 1e-6; + setMolarVolume(Z * R * temperature / pressure); + } + + // System.out.println("Z " + Z); + } while (Math.abs(err) > 1.0e-8 || iterations < 100); + // System.out.println("Z " + Z); + return getMolarVolume(); + } + + /** + *

+ * initCPAMatrixOld. + *

+ * + * @param type a int + */ + public void initCPAMatrixOld(int type) { + if (getTotalNumberOfAccociationSites() == 0) { + FCPA = 0.0; + dFCPAdTdV = 0.0; + dFCPAdTdT = 0.0; + dFCPAdT = 0; + dFCPAdV = 0; + dFCPAdVdV = 0.0; + dFCPAdVdVdV = 0.0; + + return; + } + + int temp = 0; + for (int i = 0; i < numberOfComponents; i++) { + for (int j = 0; j < componentArray[i].getNumberOfAssociationSites(); j++) { + uMatrix.set(temp + j, 0, + Math.log(ksiMatrix.get(temp + j, 0)) - ksiMatrix.get(temp + j, 0) + 1.0); + gvector[temp + j][0] = mVector.get(temp + j, 0) * udotMatrix.get(temp + j, 0); + } + temp += componentArray[i].getNumberOfAssociationSites(); + } + for (int i = 0; i < getNumberOfComponents(); i++) { + for (int j = 0; j < getTotalNumberOfAccociationSites(); j++) { + if (moleculeNumber[j] == i) { + udotTimesmiMatrix.set(i, j, udotMatrix.get(j, 0)); + } else { + udotTimesmiMatrix.set(i, j, 0.0); + } + } + } + + for (int i = 0; i < getTotalNumberOfAccociationSites(); i++) { + for (int j = i; j < getTotalNumberOfAccociationSites(); j++) { + delta[i][j] = deltaNog[i][j] * getGcpa(); + delta[j][i] = delta[i][j]; + if (type > 1) { + deltadT[i][j] = cpamix.calcDeltadT(assSiteNumber[i], assSiteNumber[j], + moleculeNumber[i], moleculeNumber[j], this, getTemperature(), + getPressure(), numberOfComponents); + deltadT[j][i] = deltadT[i][j]; + + deltadTdT[i][j] = cpamix.calcDeltadTdT(assSiteNumber[i], assSiteNumber[j], + moleculeNumber[i], moleculeNumber[j], this, getTemperature(), + getPressure(), numberOfComponents); + deltadTdT[j][i] = deltadTdT[i][j]; + } + } + } + + double totalVolume = getTotalVolume(); + double totalVolume2 = totalVolume * totalVolume, totalVolume3 = totalVolume2 * totalVolume; + double gdv1 = getGcpav() - 1.0 / totalVolume; + double gdv2 = gdv1 * gdv1; + double gdv3 = gdv2 * gdv1; + // double Klk = 0.0; + for (int i = 0; i < getTotalNumberOfAccociationSites(); i++) { + for (int j = i; j < getTotalNumberOfAccociationSites(); j++) { + KlkVMatrix.set(i, j, KlkMatrix.get(i, j) * gdv1); + KlkVMatrix.set(j, i, KlkVMatrix.get(i, j)); + + KlkVVMatrix.set(i, j, KlkMatrix.get(i, j) * gdv2 + + KlkMatrix.get(i, j) * (gcpavv + 1.0 / totalVolume / totalVolume)); + KlkVVMatrix.set(j, i, KlkVVMatrix.get(i, j)); + + KlkVVVMatrix.set(i, j, + KlkMatrix.get(i, j) * gdv3 + + 3.0 * KlkMatrix.get(i, j) * (getGcpav() - 1.0 / totalVolume) + * (gcpavv + 1.0 / (totalVolume2)) + + KlkMatrix.get(i, j) * (gcpavvv - 2.0 / (totalVolume3))); + KlkVVVMatrix.set(j, i, KlkVVVMatrix.get(i, j)); + + if (type > 1) { + double tempVar = deltadT[i][j] / delta[i][j]; + double tempVardT = deltadTdT[i][j] / delta[i][j] + - (deltadT[i][j] * deltadT[i][j]) / (delta[i][j] * delta[i][j]); + + if (!Double.isNaN(tempVar)) { + // KlkdT[i][j] = KlkMatrix.getMatrix().unsafe_get(i, j) * tempVar; + // KlkdT[j][i] = KlkdT[i][j]; + + KlkTMatrix.set(i, j, KlkMatrix.get(i, j) * tempVar); + KlkTMatrix.set(j, i, KlkTMatrix.get(i, j)); + + KlkTVMatrix.set(i, j, + KlkMatrix.get(i, j) * tempVar * (gcpav - 1.0 / totalVolume)); + KlkTVMatrix.set(j, i, KlkTVMatrix.get(i, j)); + + KlkTTMatrix.set(i, j, + KlkMatrix.get(i, j) * (tempVar * tempVar + tempVardT)); + KlkTTMatrix.set(j, i, KlkTTMatrix.get(i, j)); + } + + if (type > 2) { + for (int p = 0; p < numberOfComponents; p++) { + double t1 = 0.0, t2 = 0.0; + if (moleculeNumber[i] == p) { + t1 = 1.0 / mVector.get(i, 0); + } + if (moleculeNumber[j] == p) { + t2 = 1.0 / mVector.get(j, 0); + } + Klkni[p][i][j] = KlkMatrix.get(i, j) * (t1 + t2 + + ((ComponentUMRCPA) getComponent(p)).calc_lngi(this)); + Klkni[p][j][i] = Klkni[p][i][j]; + } + } + } + } + QMatksiksiksi.set(i, 0, 2.0 * mVector.get(i, 0) + / (ksiMatrix.get(i, 0) * ksiMatrix.get(i, 0) * ksiMatrix.get(i, 0))); + } + + SimpleMatrix ksiMatrixTranspose = ksiMatrix.transpose(); + + // dXdV + SimpleMatrix KlkVMatrixksi = KlkVMatrix.mult(ksiMatrix); + SimpleMatrix XV = hessianInvers.mult(KlkVMatrixksi); + SimpleMatrix XVtranspose = XV.transpose(); + + SimpleMatrix QCPA = mVector.transpose() + .mult(uMatrix.minus(ksiMatrix.elementMult(udotMatrix).scale(0.5))); + FCPA = QCPA.get(0, 0); + + SimpleMatrix tempMatrix = ksiMatrixTranspose.mult(KlkVMatrixksi).scale(-0.5); + dFCPAdV = tempMatrix.get(0, 0); + SimpleMatrix KlkVVMatrixTImesKsi = KlkVVMatrix.mult(ksiMatrix); + SimpleMatrix tempMatrixVV = ksiMatrixTranspose.mult(KlkVVMatrixTImesKsi).scale(-0.5) + .minus(KlkVMatrixksi.transpose().mult(XV)); + dFCPAdVdV = tempMatrixVV.get(0, 0); + + SimpleMatrix QVVV = ksiMatrixTranspose.mult(KlkVVVMatrix.mult(ksiMatrix)).scale(-0.5); + SimpleMatrix QVVksi = KlkVVMatrixTImesKsi.scale(-1.0); + SimpleMatrix QksiVksi = KlkVMatrix.scale(-1.0); + + SimpleMatrix mat1 = QVVksi.transpose().mult(XV).scale(3.0); + SimpleMatrix mat2 = XVtranspose.mult(QksiVksi.mult(XV)).scale(3.0); + SimpleMatrix mat4 = XVtranspose.mult(QMatksiksiksi.mult(XVtranspose)).mult(XV); + + SimpleMatrix dFCPAdVdVdVMatrix = QVVV.plus(mat1).plus(mat2).plus(mat2).plus(mat4); + dFCPAdVdVdV = dFCPAdVdVdVMatrix.get(0, 0); + temp = 0; + + if (type == 1) { + return; + } + for (int p = 0; p < numberOfComponents; p++) { + for (int kk = 0; kk < getComponent(p).getNumberOfAssociationSites(); kk++) { + ((ComponentCPAInterface) getComponent(p)).setXsitedV(kk, XV.get(temp + kk, 0)); + } + temp += getComponent(p).getNumberOfAssociationSites(); + } + + // KlkTMatrix = new SimpleMatrix(KlkdT); + SimpleMatrix KlkTMatrixTImesKsi = KlkTMatrix.mult(ksiMatrix); + // dQdT + SimpleMatrix tempMatrix2 = ksiMatrixTranspose.mult(KlkTMatrixTImesKsi).scale(-0.5); + dFCPAdT = tempMatrix2.get(0, 0); + + // SimpleMatrix KlkTVMatrix = new SimpleMatrix(KlkdTdV); + // SimpleMatrix tempMatrixTV = + // ksiMatrixTranspose.mult(KlkTVMatrix.mult(ksiMatrix)).scale(-0.5).minus(KlkTMatrixTImesKsi.transpose().mult(XV)); + // dFCPAdTdV = tempMatrixTV.get(0, 0); + // dXdT + SimpleMatrix XT = hessianInvers.mult(KlkTMatrixTImesKsi); + // dQdTdT + SimpleMatrix tempMatrixTT = ksiMatrixTranspose.mult(KlkTTMatrix.mult(ksiMatrix)).scale(-0.5) + .minus(KlkTMatrixTImesKsi.transpose().mult(XT)); + dFCPAdTdT = tempMatrixTT.get(0, 0); + + SimpleMatrix tempMatrixTV = ksiMatrixTranspose.mult(KlkTVMatrix.mult(ksiMatrix)).scale(-0.5) + .minus(KlkTMatrixTImesKsi.transpose().mult(XV)); + dFCPAdTdV = tempMatrixTV.get(0, 0); + + temp = 0; + for (int p = 0; p < numberOfComponents; p++) { + for (int kk = 0; kk < getComponent(p).getNumberOfAssociationSites(); kk++) { + ((ComponentCPAInterface) getComponent(p)).setXsitedT(kk, XT.get(temp + kk, 0)); + } + temp += getComponent(p).getNumberOfAssociationSites(); + } + + if (type == 2) { + return; + } + + // int assSites = 0; + // if(true) return; + for (int p = 0; p < numberOfComponents; p++) { + SimpleMatrix KiMatrix = new SimpleMatrix(Klkni[p]); + // KiMatrix.print(10,10); + // Matrix dQdniMatrix = + // (ksiMatrix.transpose().times(KiMatrix.times(ksiMatrix)).times(-0.5)); // this + // methods misses one part of .... + // dQdniMatrix.print(10,10); + // KiMatrix.print(10, 10); + // miMatrix.getMatrix(assSites, assSites, 0, totalNumberOfAccociationSites - + // 1).print(10, 10); + // Matrix tempMatrix20 = miMatrix.getMatrix(assSites, assSites, 0, + // totalNumberOfAccociationSites - + // 1).times(uMatrix).minus(ksiMatrix.transpose().times(KiMatrix.times(ksiMatrix)).times(-0.5));// + // ksiMatrix.transpose().times(KlkTMatrix.times(ksiMatrix)).times(-0.5); + // System.out.println("dQdn "); + // tempMatrix20.print(10, 10); + SimpleMatrix tempMatrix4 = KiMatrix.mult(ksiMatrix); + // udotTimesmiMatrix.getMatrix(assSites, assSites, 0, + // totalNumberOfAccociationSites - 1).print(10, 10); + SimpleMatrix tempMatrix5 = + udotTimesmiMatrix.extractVector(true, p).transpose().minus(tempMatrix4); + // tempMki[0] = mki[p]; + // Matrix amatrix = new Matrix(croeneckerProduct(tempMki, + // udotMatrix.getArray())); + // System.out.println("aMatrix "); + // amatrix.transpose().print(10, 10); + // System.out.println("temp4 matrix"); + // tempMatrix4.print(10, 10); + // Matrix tempMatrix5 = amatrix.minus(tempMatrix4); + SimpleMatrix tempMatrix6 = hessianInvers.mult(tempMatrix5);// .scale(-1.0); + // System.out.println("dXdni"); + // tempMatrix4.print(10, 10); + // tempMatrix5.print(10, 10); + // System.out.println("dXdn "); + // tempMatrix6.print(10, 10); + int temp2 = 0; + for (int compp = 0; compp < numberOfComponents; compp++) { + for (int kk = 0; kk < getComponent(compp).getNumberOfAssociationSites(); kk++) { + ((ComponentCPAInterface) getComponent(compp)).setXsitedni(kk, p, + -1.0 * tempMatrix6.get(temp2 + kk, 0)); + } + temp2 += getComponent(compp).getNumberOfAssociationSites(); + } + // assSites += getComponent(p).getNumberOfAssociationSites(); + } + } + + /** + *

+ * solveXOld. + *

+ * + * @return a boolean + */ + public boolean solveXOld() { + if (getTotalNumberOfAccociationSites() == 0) { + return true; + } + + boolean solvedX = solveX2(5); + if (solvedX) { + // return true; + } + + DMatrixRMaj mat1 = KlkMatrix.getMatrix(); + DMatrixRMaj mat2 = ksiMatrix.getMatrix(); + // second order method not working correctly and not used t the moment b ecause of numerical + // stability + int temp = 0, iter = 0; + for (int i = 0; i < numberOfComponents; i++) { + for (int j = 0; j < componentArray[i].getNumberOfAssociationSites(); j++) { + mVector.set(temp + j, 0, componentArray[i].getNumberOfMolesInPhase()); + } + temp += componentArray[i].getNumberOfAssociationSites(); + } + double Klk = 0.0; + double totalVolume = getTotalVolume(); + for (int i = 0; i < getTotalNumberOfAccociationSites(); i++) { + for (int j = i; j < getTotalNumberOfAccociationSites(); j++) { + Klk = mVector.get(i, 0) * mVector.get(j, 0) / totalVolume * delta[i][j]; + KlkMatrix.set(i, j, Klk); + KlkMatrix.set(j, i, Klk); + } + } + boolean solved = true; + // SimpleMatrix corrMatrix = null; + do { + solved = true; + iter++; + temp = 0; + for (int i = 0; i < numberOfComponents; i++) { + for (int j = 0; j < componentArray[i].getNumberOfAssociationSites(); j++) { + ksiMatrix.set(temp + j, 0, ((ComponentUMRCPA) componentArray[i]).getXsite()[j]); + // ksiMatrix.getMatrix().unsafe_set(temp + j, 0, + // ksiMatrix.getMatrix().unsafe_get(temp + j, 0)); + udotMatrix.set(temp + j, 0, 1.0 / ksiMatrix.get(temp + j, 0) - 1.0); + udotTimesmMatrix.set(temp + j, 0, + mVector.get(temp + j, 0) * udotMatrix.get(temp + j, 0)); + } + temp += componentArray[i].getNumberOfAssociationSites(); + } + + for (int i = 0; i < getTotalNumberOfAccociationSites(); i++) { + for (int j = i; j < getTotalNumberOfAccociationSites(); j++) { + int krondelt = 0; + if (i == j) { + krondelt = 1; + } + hessianMatrix.set(i, j, + -mVector.get(i, 0) / (ksiMatrix.get(i, 0) * ksiMatrix.get(i, 0)) + * krondelt - KlkMatrix.get(i, j)); + hessianMatrix.set(j, i, hessianMatrix.get(i, j)); + } + } + + // ksiMatrix = new SimpleMatrix(ksi); + // SimpleMatrix hessianMatrix = new SimpleMatrix(hessian); + try { + hessianInvers = hessianMatrix.invert(); + } catch (Exception e) { + logger.error("error", e); + return false; + } + + CommonOps_DDRM.mult(mat1, mat2, corr2Matrix); + CommonOps_DDRM.subtract(udotTimesmMatrix.getDDRM(), corr2Matrix, corr3Matrix); + CommonOps_DDRM.mult(hessianInvers.getDDRM(), corr3Matrix, corr4Matrix); + // SimpleMatrix gMatrix = udotTimesmMatrix.minus(KlkMatrix.mult(ksiMatrix)); + // corrMatrix = + // hessianInvers.mult(udotTimesmMatrix.minus(KlkMatrix.mult(ksiMatrix)));//.scale(-1.0); + temp = 0; + // System.out.println("print SimpleMatrix ..."); + // corrMatrix.print(10, 10); + // SimpleMatrix simp = new SimpleMatrix(corr4Matrix); + // System.out.println("print CommonOps ..."); + // simp.print(10,10); + for (int i = 0; i < numberOfComponents; i++) { + for (int j = 0; j < componentArray[i].getNumberOfAssociationSites(); j++) { + double newX = + ksiMatrix.get(temp + j, 0) - corr4Matrix.unsafe_get((temp + j), 0); + if (newX < 0) { + newX = 1e-10; + solved = false; + } + ((ComponentCPAInterface) componentArray[i]).setXsite(j, newX); + } + temp += componentArray[i].getNumberOfAssociationSites(); + } + // System.out.println("corrmatrix error " ); + // System.out.println("error " + corrMatrix.norm1()); + } while ((NormOps_DDRM.normF(corr4Matrix) > 1e-12 || !solved) && iter < 100); + + // System.out.println("iter " + iter + " error " + NormOps.normF(corr4Matrix)); + // // corrMatrix.print(10, 10); + // ksiMatrix.print(10, 10); + return true; + } + + /** + *

+ * solveX2Old. + *

+ * + * @param maxIter a int + * @return a boolean + */ + public boolean solveX2Old(int maxIter) { + double err = .0; + int iter = 0; + // if (delta == null) { + // initCPAMatrix(1); + double old = 0.0, neeval = 0.0, totalVolume = getTotalVolume(); + // } + do { + iter++; + err = 0.0; + for (int i = 0; i < getTotalNumberOfAccociationSites(); i++) { + old = ((ComponentUMRCPA) getComponent(moleculeNumber[i])) + .getXsite()[assSiteNumber[i]]; + neeval = 0; + for (int j = 0; j < getTotalNumberOfAccociationSites(); j++) { + neeval += getComponent(moleculeNumber[j]).getNumberOfMolesInPhase() + * delta[i][j] * ((ComponentUMRCPA) getComponent(moleculeNumber[j])) + .getXsite()[assSiteNumber[j]]; + } + neeval = 1.0 / (1.0 + 1.0 / totalVolume * neeval); + ((ComponentCPAInterface) getComponent(moleculeNumber[i])).setXsite(assSiteNumber[i], + neeval); + err += Math.abs((old - neeval) / neeval); + } + } while (Math.abs(err) > 1e-10 && iter < maxIter); + // System.out.println("iter " + iter); + // if (Math.abs(err) + // < 1e-12) { + // return true; + // } else { + // System.out.println("did not solve for Xi in iterations: " + iter); + // System.out.println("error: " + err); + return false; + } + + /** + *

+ * molarVolumeOld. + *

+ * + * @param pressure a double + * @param temperature a double + * @param A a double + * @param B a double + * @param phasetype a int + * @return a double + * @throws neqsim.util.exception.IsNaNException if any. + * @throws neqsim.util.exception.TooManyIterationsException if any. + */ + public double molarVolumeOld(double pressure, double temperature, double A, double B, + int phasetype) throws neqsim.util.exception.IsNaNException, + neqsim.util.exception.TooManyIterationsException { + double BonV = phasetype == 0 ? 2.0 / (2.0 + temperature / getPseudoCriticalTemperature()) + : pressure * getB() / (numberOfMolesInPhase * temperature * R); + // if (pressure > 1000) { + // BonV = 0.9999; + // } + + // double calcRooBonVtVolFinder = calcRootVolFinder(phasetype); + // BonV = calcRooBonVtVolFinder; + // double BonVInit = BonV; + if (BonV < 0) { + BonV = 1.0e-8; + } + + if (BonV >= 1.0) { + BonV = 0.9999; + } + double BonVold; + double h = 0, dh = 0, dhh = 0; + double d1 = 0, d2 = 0; + double Btemp = getB(); + if (Btemp < 0) { + logger.info("b negative in volume calc"); + } + calcDelta(); + + setMolarVolume(1.0 / BonV * Btemp / numberOfMolesInPhase); + int iterations = 0; + + do { + iterations++; + gcpa = calc_g(); + if (gcpa < 0) { + setMolarVolume(1.0 / Btemp / numberOfMolesInPhase); + gcpa = calc_g(); + } + + // lngcpa = + // Math.log(gcpa); + setGcpav(calc_lngV()); + gcpavv = calc_lngVV(); + gcpavvv = calc_lngVVV(); + + if (getTotalNumberOfAccociationSites() > 0) { + solveX(); + } + + initCPAMatrix(1); + double BonV2 = BonV * BonV; + BonVold = BonV; + h = BonV - Btemp / numberOfMolesInPhase * dFdV() + - pressure * Btemp / (numberOfMolesInPhase * R * temperature); + dh = 1.0 + Btemp / (BonV2) * (Btemp / numberOfMolesInPhase * dFdVdV()); + dhh = -2.0 * Btemp / (BonV2 * BonV) * (Btemp / numberOfMolesInPhase * dFdVdV()) + - (Btemp * Btemp) / (BonV2 * BonV2) + * (Btemp / numberOfMolesInPhase * dFdVdVdV()); + + d1 = -h / dh; + d2 = -dh / dhh; + // System.out.println("h " + h + " iter " + iterations + " " + d1 + " d2 " + d2 + // + " d1 / d2 " + (d1 / d2)); + if (Math.abs(d1 / d2) <= 1.0) { + BonV += d1 * (1.0 + 0.5 * d1 / d2); + } else if (d1 / d2 < -1) { + BonV += 0.5 * d1; + } else if (d1 > d2) { + BonV += d2; + double hnew = h + d2 * dh; + if (Math.abs(hnew) > Math.abs(h)) { + BonV = phasetype == 1 + ? 2.0 / (2.0 + temperature / getPseudoCriticalTemperature()) + : pressure * getB() / (numberOfMolesInPhase * temperature * R); + } + } else { + BonV += 0.5 * d1; + } + if (Math.abs((BonV - BonVold) / BonVold) > 0.1) { + BonV = BonVold + 0.1 * (BonV - BonVold); + } + + if (BonV > 0.9999) { + if (iterations < 3) { + BonV = (BonVold + BonV) / 2.0; + } else { + // return molarVolumeChangePhase(pressure, temperature, A, B, phasetype); + // BonV = 0.9999; + // BonV = phasetype == 1 ? 2.0 / (2.0 + temperature / + // getPseudoCriticalTemperature()) : pressure * getB() / (numberOfMolesInPhase * + // temperature * R); + } + } else if (BonV < 0) { + if (iterations < 3) { + BonV = Math.abs(BonVold + BonV) / 2.0; + } else { + // return molarVolumeChangePhase(pressure, temperature, A, B, phasetype); + // BonV = phasetype == 1 ? 2.0 / (2.0 + temperature / + // getPseudoCriticalTemperature()) : pressure * getB() / (numberOfMolesInPhase * + // temperature * R); + } + } + setMolarVolume(1.0 / BonV * Btemp / numberOfMolesInPhase); + Z = pressure * getMolarVolume() / (R * temperature); + } while ((Math.abs((BonV - BonVold) / BonV) > 1.0e-10 || Math.abs(h) > 1e-12) + && iterations < 100); + + if (Math.abs(h) > 1e-12) { + // System.out.println("h failed " + "Z" + Z + " iterations " + iterations + " + // BonV " + BonV); + // return molarVolumeChangePhase(pressure, temperature, A, B, phasetype); + } + // System.out.println("Z" + Z + " iterations " + iterations + " BonV " + BonV); + // System.out.println("pressure " + Z*R*temperature/getMolarVolume()); + // System.out.println("volume " + totalVolume + " molar volume " + + // getMolarVolume()); + // if(iterations>=100) throw new util.exception.TooManyIterationsException(); + // System.out.println("error in volume " + + // (-pressure+R*temperature/getMolarVolume()-R*temperature*dFdV()));// + " + // firstterm " + (R*temperature/molarVolume) + " second " + + // R*temperature*dFdV()); + // System.out.println("BonV: " + BonV + " "+" itert: " + iterations +" " +h + " " +dh + " B + // " + Btemp + " gv" + gV() + " fv " + fv() + " fvv" + fVV()); + + if (Double.isNaN(getMolarVolume())) { + throw new neqsim.util.exception.IsNaNException(this, "molarVolumeOld", "Molar volume"); + // System.out.println("BonV: " + BonV + " "+" itert: " + iterations +" " +h + " + // " +dh + " B " + Btemp + " D " + Dtemp + " gv" + gV() + " fv " + fv() + " fvv" + // + fVV()); + } + return getMolarVolume(); + } +} diff --git a/src/main/java/neqsim/thermo/system/SystemBWRSEos.java b/src/main/java/neqsim/thermo/system/SystemBWRSEos.java index 57ef9932c8..c568b7a80a 100644 --- a/src/main/java/neqsim/thermo/system/SystemBWRSEos.java +++ b/src/main/java/neqsim/thermo/system/SystemBWRSEos.java @@ -5,7 +5,7 @@ import neqsim.thermo.phase.PhasePureComponentSolid; /** - * This class defines a thermodynamic system using the SRK equation of state + * This class defines a thermodynamic system using the BWRS equation of state * * @author Even Solbraa */ diff --git a/src/main/java/neqsim/thermo/system/SystemCSPsrkEos.java b/src/main/java/neqsim/thermo/system/SystemCSPsrkEos.java index 0a82ee951a..bd880ab8d6 100644 --- a/src/main/java/neqsim/thermo/system/SystemCSPsrkEos.java +++ b/src/main/java/neqsim/thermo/system/SystemCSPsrkEos.java @@ -5,7 +5,7 @@ import neqsim.thermo.phase.PhasePureComponentSolid; /** - * This class defines a thermodynamic system using the SRK equation of state + * This class defines a thermodynamic system using the CSP SRK equation of state * * @author Even Solbraa */ diff --git a/src/main/java/neqsim/thermo/system/SystemDesmukhMather.java b/src/main/java/neqsim/thermo/system/SystemDesmukhMather.java index aead20c9b7..8d143a01d9 100644 --- a/src/main/java/neqsim/thermo/system/SystemDesmukhMather.java +++ b/src/main/java/neqsim/thermo/system/SystemDesmukhMather.java @@ -5,7 +5,7 @@ import neqsim.thermo.phase.PhaseSrkEos; /** - * This class defines a thermodynamic system using the SRK equation of state + * This class defines a thermodynamic system using the Desmukh Mather thermodyanmic model * * @author Even Solbraa */ diff --git a/src/main/java/neqsim/thermo/system/SystemDuanSun.java b/src/main/java/neqsim/thermo/system/SystemDuanSun.java index 2274c25481..041a8096d2 100644 --- a/src/main/java/neqsim/thermo/system/SystemDuanSun.java +++ b/src/main/java/neqsim/thermo/system/SystemDuanSun.java @@ -6,7 +6,7 @@ import neqsim.thermodynamicOperations.ThermodynamicOperations; /** - * This class defines a thermodynamic system using the SRK EoS and Pitzer for liquids + * This class defines a thermodynamic system using the Duan Sun method used for CO2 * * @author Even Solbraa */ diff --git a/src/main/java/neqsim/thermo/system/SystemElectrolyteCPAstatoil.java b/src/main/java/neqsim/thermo/system/SystemElectrolyteCPAstatoil.java index 14d08b98e9..32bf40aef9 100644 --- a/src/main/java/neqsim/thermo/system/SystemElectrolyteCPAstatoil.java +++ b/src/main/java/neqsim/thermo/system/SystemElectrolyteCPAstatoil.java @@ -4,7 +4,7 @@ import neqsim.thermo.util.constants.FurstElectrolyteConstants; /** - * This class defines a thermodynamic system using the Electrolyte CPA EoS of Equinor + * This class defines a thermodynamic system using the electrolyte CPA EoS Statoil model * * @author Even Solbraa */ diff --git a/src/main/java/neqsim/thermo/system/SystemFurstElectrolyteEos.java b/src/main/java/neqsim/thermo/system/SystemFurstElectrolyteEos.java index 2c79a2ffaa..b503b9ffde 100644 --- a/src/main/java/neqsim/thermo/system/SystemFurstElectrolyteEos.java +++ b/src/main/java/neqsim/thermo/system/SystemFurstElectrolyteEos.java @@ -3,9 +3,8 @@ import neqsim.thermo.phase.PhaseModifiedFurstElectrolyteEos; /** - *

- * SystemFurstElectrolyteEos class. - *

+ * + * This class defines a thermodynamic system using the electrolyte the Furst Electrolyte Eos. * * @author Even Solbraa * @version $Id: $Id diff --git a/src/main/java/neqsim/thermo/system/SystemFurstElectrolyteEosMod2004.java b/src/main/java/neqsim/thermo/system/SystemFurstElectrolyteEosMod2004.java index 6531fe8da1..390c212af4 100644 --- a/src/main/java/neqsim/thermo/system/SystemFurstElectrolyteEosMod2004.java +++ b/src/main/java/neqsim/thermo/system/SystemFurstElectrolyteEosMod2004.java @@ -3,9 +3,8 @@ import neqsim.thermo.phase.PhaseModifiedFurstElectrolyteEosMod2004; /** - *

- * SystemFurstElectrolyteEosMod2004 class. - *

+ * This class defines a thermodynamic system using the electrolyte the Modified Furst Electrolyte + * Eos. * * @author Even Solbraa * @version $Id: $Id diff --git a/src/main/java/neqsim/thermo/system/SystemGERG2004Eos.java b/src/main/java/neqsim/thermo/system/SystemGERG2004Eos.java index 2495f4a5f1..e17a4cc7e7 100644 --- a/src/main/java/neqsim/thermo/system/SystemGERG2004Eos.java +++ b/src/main/java/neqsim/thermo/system/SystemGERG2004Eos.java @@ -5,7 +5,7 @@ import neqsim.thermo.phase.PhasePureComponentSolid; /** - * This class defines a thermodynamic system using the SRK equation of state + * This class defines a thermodynamic system using the GERG2004 equation of state * * @author Even Solbraa */ diff --git a/src/main/java/neqsim/thermo/system/SystemGERGwaterEos.java b/src/main/java/neqsim/thermo/system/SystemGERGwaterEos.java index 66e955fa75..417af8bf5d 100644 --- a/src/main/java/neqsim/thermo/system/SystemGERGwaterEos.java +++ b/src/main/java/neqsim/thermo/system/SystemGERGwaterEos.java @@ -5,7 +5,7 @@ import neqsim.thermo.phase.PhasePureComponentSolid; /** - * This class defines a thermodynamic system using the SRK equation of state + * This class defines a thermodynamic system using the GERG water equation of state * * @author Even Solbraa */ diff --git a/src/main/java/neqsim/thermo/system/SystemGEWilson.java b/src/main/java/neqsim/thermo/system/SystemGEWilson.java index 80438ae087..c0644afac0 100644 --- a/src/main/java/neqsim/thermo/system/SystemGEWilson.java +++ b/src/main/java/neqsim/thermo/system/SystemGEWilson.java @@ -5,7 +5,7 @@ import neqsim.thermo.phase.PhaseSrkEos; /** - * This class defines a thermodynamic system using the SRK equation of state + * This class defines a thermodynamic system using the Wilson GE model * * @author Even Solbraa */ diff --git a/src/main/java/neqsim/thermo/system/SystemInterface.java b/src/main/java/neqsim/thermo/system/SystemInterface.java index 563b8613a3..bfa0c7fc1d 100644 --- a/src/main/java/neqsim/thermo/system/SystemInterface.java +++ b/src/main/java/neqsim/thermo/system/SystemInterface.java @@ -2,6 +2,7 @@ import neqsim.chemicalReactions.ChemicalReactionOperations; import neqsim.physicalProperties.interfaceProperties.InterphasePropertiesInterface; +import neqsim.thermo.ThermodynamicConstantsInterface; import neqsim.thermo.characterization.WaxModelInterface; import neqsim.thermo.component.ComponentInterface; import neqsim.thermo.phase.PhaseInterface; @@ -15,2488 +16,2457 @@ * @version $Id: $Id */ public interface SystemInterface extends Cloneable, java.io.Serializable { - /** - *

- * saveFluid. - *

- * - * @param ID a int - */ - public void saveFluid(int ID); - - /** - *

- * getComponentNameTag. - *

- * - * @return a {@link java.lang.String} object - */ - public String getComponentNameTag(); - - /** - *

- * setComponentNameTagOnNormalComponents. - *

- * - * @param nameTag a {@link java.lang.String} object - */ - public void setComponentNameTagOnNormalComponents(String nameTag); - - /** - *

- * addPhaseFractionToPhase. - *

- * - * @param fraction a double - * @param specification a {@link java.lang.String} object - * @param fromPhaseName a {@link java.lang.String} object - * @param toPhaseName a {@link java.lang.String} object - */ - public void addPhaseFractionToPhase(double fraction, String specification, String fromPhaseName, - String toPhaseName); - - /** - *

- * addPhaseFractionToPhase. - *

- * - * @param fraction a double - * @param specification a {@link java.lang.String} object - * @param specifiedStream a {@link java.lang.String} object - * @param fromPhaseName a {@link java.lang.String} object - * @param toPhaseName a {@link java.lang.String} object - */ - public void addPhaseFractionToPhase(double fraction, String specification, - String specifiedStream, String fromPhaseName, String toPhaseName); - - /** - *

- * renameComponent. - *

- * - * @param oldName a {@link java.lang.String} object - * @param newName a {@link java.lang.String} object - */ - public void renameComponent(String oldName, String newName); - - /** - *

- * setComponentNameTag. - *

- * - * @param nameTag a {@link java.lang.String} object - */ - public void setComponentNameTag(String nameTag); - - /** - * Add named components to a System. Does nothing if components already exist in - * System. - * - * @param names Names of the components to be added. See NeqSim database for - * available components in the database. - */ - default public void addComponents(String[] names) { - for (int i = 0; i < names.length; i++) { - addComponent(names[i], 0.0); - } + /** + *

+ * saveFluid. + *

+ * + * @param id a int + */ + public void saveFluid(int id); + + /** + *

+ * saveFluid. + *

+ * + * @param id a int + * @param text a {@link java.lang.String} object + */ + public void saveFluid(int id, String text); + + /** + *

+ * getComponentNameTag. + *

+ * + * @return a {@link java.lang.String} object + */ + public String getComponentNameTag(); + + /** + *

+ * setComponentNameTagOnNormalComponents. + *

+ * + * @param nameTag a {@link java.lang.String} object + */ + public void setComponentNameTagOnNormalComponents(String nameTag); + + /** + *

+ * addPhaseFractionToPhase. + *

+ * + * @param fraction a double + * @param specification a {@link java.lang.String} object + * @param fromPhaseName a {@link java.lang.String} object + * @param toPhaseName a {@link java.lang.String} object + */ + public void addPhaseFractionToPhase(double fraction, String specification, String fromPhaseName, + String toPhaseName); + + /** + *

+ * addPhaseFractionToPhase. + *

+ * + * @param fraction a double + * @param specification a {@link java.lang.String} object + * @param specifiedStream a {@link java.lang.String} object + * @param fromPhaseName a {@link java.lang.String} object + * @param toPhaseName a {@link java.lang.String} object + */ + public void addPhaseFractionToPhase(double fraction, String specification, String specifiedStream, + String fromPhaseName, String toPhaseName); + + /** + *

+ * renameComponent. + *

+ * + * @param oldName a {@link java.lang.String} object + * @param newName a {@link java.lang.String} object + */ + public void renameComponent(String oldName, String newName); + + /** + *

+ * setComponentNameTag. + *

+ * + * @param nameTag a {@link java.lang.String} object + */ + public void setComponentNameTag(String nameTag); + + /** + * Add named components to a System. Does nothing if components already exist in System. + * + * @param names Names of the components to be added. See NeqSim database for available components + * in the database. + */ + public default void addComponents(String[] names) { + for (int i = 0; i < names.length; i++) { + addComponent(names[i], 0.0); } - - - /** - * Add named components to a System with a number of moles. - * If component already exists, the moles will be added to the component. - * - * @param names Names of the components to be added. See NeqSim database for - * available components in the database. - * @param moles Number of moles to add per component. - */ - default public void addComponents(String[] names, double[] moles) { - for (int i = 0; i < names.length; i++) { - addComponent(names[i], moles[i]); - } - } - - /** - *

- * calcResultTable. - *

- * - * @return an array of {@link java.lang.String} objects - */ - default public String[][] calcResultTable() { - return createTable(""); + } + + /** + * Add named components to a System with a number of moles. If component already exists, the moles + * will be added to the component. + * + * @param names Names of the components to be added. See NeqSim database for available components + * in the database. + * @param moles Number of moles to add per component. + */ + public default void addComponents(String[] names, double[] moles) { + for (int i = 0; i < names.length; i++) { + addComponent(names[i], moles[i]); } - - /** - * method to return kinematic viscosity in a specified unit - * - * @param unit Supported units are m2/sec - * @return kinematic viscosity in specified unit - */ - public double getKinematicViscosity(String unit); - - /** - *

- * Get number of components added to System. - *

- * - * @return the number of components in System. - */ - public int getNumberOfComponents(); - - /** - * method to get molar mass of a fluid phase - * - * @param unit Supported units are kg/mol, gr/mol - * @return molar mass in specified unit - */ - public double getMolarMass(String unit); - - /** - * This method is used to set the total molar composition of a plus fluid. The total flow rate - * will be kept constant. The input mole fractions will be normalized. - * - * @param molefractions is a double array taking the molar fraction of the components in the - * fluid. THe last molfraction is the mole fraction of the plus component - */ - public void setMolarCompositionPlus(double[] molefractions); - - /** - *

- * saveFluid. - *

- * - * @param ID a int - * @param text a {@link java.lang.String} object - */ - public void saveFluid(int ID, String text); - - /** - * This method is used to set the total molar composition of a characterized fluid. The total - * flow rate will be kept constant. The input mole fractions will be normalized. - * - * @param molefractions is a double array taking the molar fraction of the components in the - * fluid. THe last fraction in the array is the total molefraction of the characterized - * components. - */ - public void setMolarCompositionOfPlusFluid(double[] molefractions); - - /** - * method to get the Joule Thomson Coefficient of a system. Based on a phase - * mole fraction basis - * average - * - * @param unit Supported units are K/bar, C/bar - * @return Joule Thomson coefficient in specified unit - */ - public double getJouleThomsonCoefficient(String unit); - - /** - * method to return exergy in a specified unit - * - * @param temperatureOfSurroundings in Kelvin - * @return exergy in specified unit - * @param exergyUnit a {@link java.lang.String} object - */ - public double getExergy(double temperatureOfSurroundings, String exergyUnit); - - /** - * method to return exergy defined as (h1-T0*s1) in a unit Joule - * - * @param temperatureOfSurroundings in Kelvin - * @return a double - */ - public double getExergy(double temperatureOfSurroundings); - - /** - * method to get the Joule Thomson Coefficient of a system. Based on a phase mole fraction basis - * average - * - * @return Joule Thomson coefficient in K/bar - */ - public double getJouleThomsonCoefficient(); - - /** - * method to return mass of fluid - * - * @param unit Supported units are kg, gr, tons - * @return mass in specified unit - */ - public double getMass(String unit); - - /** - *

- * getMoleFractionsSum. - *

- * - * @return a double - */ - public double getMoleFractionsSum(); - - /** - * method to get the speed of sound of a system. THe sound speed is implemented - * based on a molar - * average over the phases - * - * @param unit Supported units are m/s, km/h - * @return speed of sound in m/s - */ - public double getSoundSpeed(String unit); - - /** - * method to get the speed of sound of a system. THe sound speed is implemented based on a molar - * average over the phases - * - * @return speed of sound in m/s - */ - public double getSoundSpeed(); - - /** - *

- * removePhaseKeepTotalComposition. - *

- * - * @param specPhase a int - */ - public void removePhaseKeepTotalComposition(int specPhase); - - /** - * Calculates thermodynamic and physical properties of a fluid using initThermoProperties() and - * initPhysicalProperties(); - */ - public void initProperties(); - - /** - * return two fluid added as a new fluid - * - * @param addFluid1 first fluid to add - * @param addFluid2 second fluid o add - * @return new fluid - */ - public static SystemInterface addFluids(SystemInterface addFluid1, SystemInterface addFluid2) { - SystemInterface newFluid = addFluid1.clone(); - newFluid.addFluid(addFluid2); - return newFluid; - } - - /** - *

- * getInterfacialTension. - *

- * - * @param phase1 a int - * @param phase2 a int - * @param unit a {@link java.lang.String} object - * @return a double - */ - public double getInterfacialTension(int phase1, int phase2, String unit); - - /** - * Calculates physical properties of type propertyName - * - * @param propertyName a {@link java.lang.String} object - */ - public void initPhysicalProperties(String propertyName); - - /** - * method to return heat capacity ratio calculated as Cp/(Cp-R) - * - * @return kappa - */ - public double getGamma2(); - - /** - * method to return heat capacity ratio/adiabatic index/Poisson constant - * - * @return kappa - */ - public double getGamma(); - - /** - * method to return fluid volume - * - * @param unit Supported units are m3, litre, m3/kg, m3/mol - * @return volume in specified unit - */ - public double getVolume(String unit); - - /** - * method to return flow rate of fluid - * - * @param flowunit Supported units are kg/sec, kg/min, kg/hr m3/sec, - * m3/min, m3/hr, mole/sec, mole/min, mole/hr, Sm3/hr, Sm3/day - * @return flow rate in specified unit - */ - public double getFlowRate(String flowunit); - - /** - * method to set the pressure of a fluid (same pressure for all phases) - * - * @param newPressure in specified unit - * @param unit unit can be bar, bara, barg or atm - */ - public void setPressure(double newPressure, String unit); - - /** - * method to set the temperature of a fluid (same temperature for all phases) - * - * @param newTemperature in specified unit - * @param unit unit can be C or K (Celcius of Kelvin) - */ - public void setTemperature(double newTemperature, String unit); - - /** - * method to return the volume fraction of a phase note: without Peneloux volume correction - * - * @param phaseNumber number of the phase to get volume fraction for - * @return volume fraction - */ - public double getVolumeFraction(int phaseNumber); - - /** - * method to return the volume fraction of a phase note: with Peneloux volume correction - * - * @param phaseNumber number of the phase to get volume fraction for - * @return volume fraction - */ - public double getCorrectedVolumeFraction(int phaseNumber); - - /** - *

- * getHeatOfVaporization. - *

- * - * @return a double - */ - public double getHeatOfVaporization(); - - /** - * method to return total enthalpy in a specified unit - * - * - * @param unit Supported units are 'J', 'J/mol', 'J/kg' and 'kJ/kg' - * @return enthalpy in specified unit - */ - public double getEnthalpy(String unit); - - /** - * method to return internal energy (U) in a specified unit - * - * @param unit Supported units are 'J', 'J/mol', 'J/kg' and 'kJ/kg' - * @return enthalpy in specified unit - */ - public double getInternalEnergy(String unit); - - /** - *

- * isForcePhaseTypes. - *

- * - * @return a boolean - */ - public boolean isForcePhaseTypes(); - - /** - *

- * setForcePhaseTypes. - *

- * - * @param forcePhaseTypes a boolean - */ - public void setForcePhaseTypes(boolean forcePhaseTypes); - - /** - * Set the flow rate of all components to zero. - * - * @deprecated use {@link #setEmptyFluid()} instead. - */ - @Deprecated - default public void removeMoles() { - setEmptyFluid(); - } - - /** - * Set the flow rate of all components to zero. - */ - public void setEmptyFluid(); - - /** - *

- * setMolarFlowRates. - *

- * - * @param moles an array of {@link double} objects - */ - public void setMolarFlowRates(double[] moles); - - /** - *

- * setComponentNames. - *

- * - * @param componentNames an array of {@link java.lang.String} objects - */ - public void setComponentNames(String[] componentNames); - - /** - *

- * calc_x_y_nonorm. - *

- */ - public void calc_x_y_nonorm(); - - /** - *

- * saveObjectToFile. - *

- * - * @param filePath a {@link java.lang.String} object - * @param fluidName a {@link java.lang.String} object - */ - public void saveObjectToFile(String filePath, String fluidName); - - /** - *

- * readObjectFromFile. - *

- * - * @param filePath a {@link java.lang.String} object - * @param fluidName a {@link java.lang.String} object - * @return a {@link neqsim.thermo.system.SystemInterface} object - */ - public SystemInterface readObjectFromFile(String filePath, String fluidName); - - /** - *

- * getLiquidVolume. - *

- * - * @return a double - */ - public double getLiquidVolume(); - - /** - *

- * resetPhysicalProperties. - *

- */ - public void resetPhysicalProperties(); - - /** - *

- * phaseToSystem. - *

- * - * @param phaseNumber1 a int - * @param phaseNumber2 a int - * @return a {@link neqsim.thermo.system.SystemInterface} object - */ - public SystemInterface phaseToSystem(int phaseNumber1, int phaseNumber2); - - /** - *

- * changeComponentName. - *

- * - * @param name a {@link java.lang.String} object - * @param newName a {@link java.lang.String} object - */ - public void changeComponentName(String name, String newName); - - /** - *

- * getWaxModel. - *

- * - * @return a {@link neqsim.thermo.characterization.WaxModelInterface} object - */ - public WaxModelInterface getWaxModel(); - - /** - *

- * getWaxCharacterisation. - *

- * - * @return a {@link neqsim.thermo.characterization.WaxCharacterise} object - */ - public neqsim.thermo.characterization.WaxCharacterise getWaxCharacterisation(); - - /** - *

- * phaseToSystem. - *

- * - * @param phaseName a {@link java.lang.String} object - * @return a {@link neqsim.thermo.system.SystemInterface} object - */ - public SystemInterface phaseToSystem(String phaseName); - - /** - * method to get the total molar flow rate of individual components in a fluid - * - * @return molar flow of individual components in unit mol/sec - */ - public double[] getMolarRate(); - - - /** - * Returns true if phase exists and is not null - * - * @param i Phase number - * @return True if phase exists, false if not. - */ - public boolean IsPhase(int i); - - - /** - *

- * getPhase. - *

- * - * @param phaseTypeName a {@link java.lang.String} object - * @return a {@link neqsim.thermo.phase.PhaseInterface} object - */ - public PhaseInterface getPhase(String phaseTypeName); - - /** - *

- * getPhaseIndexOfPhase. - *

- * - * @param phaseTypeName a {@link java.lang.String} object - * @return a int - */ - public int getPhaseIndexOfPhase(String phaseTypeName); - - /** - *

- * setTotalFlowRate. - *

- * - * @param flowRate a double - * @param flowunit a {@link java.lang.String} object - */ - public void setTotalFlowRate(double flowRate, String flowunit); - - /** - *

- * Returns the overall mole composition vector in unit mole fraction - *

- * - * @return an array of {@link double} objects - */ - public double[] getMolarComposition(); - - /** - *

- * getNumberOfOilFractionComponents. - *

- * - * @return a int - */ - public int getNumberOfOilFractionComponents(); - - /** - *

- * setHeavyTBPfractionAsPlusFraction. - *

- * - * @return a boolean - */ - public boolean setHeavyTBPfractionAsPlusFraction(); - - /** - *

- * getCapeOpenProperties11. - *

- * - * @return an array of {@link java.lang.String} objects - */ - public String[] getCapeOpenProperties11(); - - /** - *

- * getCapeOpenProperties10. - *

- * - * @return an array of {@link java.lang.String} objects - */ - public String[] getCapeOpenProperties10(); - - /** - *

- * getLowestGibbsEnergyPhase. - *

- * - * @return a {@link neqsim.thermo.phase.PhaseInterface} object - */ - public PhaseInterface getLowestGibbsEnergyPhase(); - - /** - *

- * getOilFractionNormalBoilingPoints. - *

- * - * @return an array of {@link double} objects - */ - public double[] getOilFractionNormalBoilingPoints(); - - /** - *

- * getOilFractionLiquidDensityAt25C. - *

- * - * @return an array of {@link double} objects - */ - public double[] getOilFractionLiquidDensityAt25C(); - - /** - *

- * getOilFractionMolecularMass. - *

- * - * @return an array of {@link double} objects - */ - public double[] getOilFractionMolecularMass(); - - /** - *

- * getOilFractionIDs. - *

- * - * @return an array of {@link int} objects - */ - public int[] getOilFractionIDs(); - - /** - *

- * getMoleFraction. - *

- * - * @param phaseNumber a int - * @return a double - */ - public double getMoleFraction(int phaseNumber); - - /** - * method to return specific heat capacity (Cv) - * - * @return Cv in unit J/K - */ - public double getCv(); - - /** - * method to return specific heat capacity (Cp) in a specified unit - * - * @param unit Supported units are J/K, J/molK, J/kgK and kJ/kgK - * @return Cp in specified unit - */ - public double getCv(String unit); - - /** - *

- * Getter for property characterization. - *

- * - * @return a {@link neqsim.thermo.characterization.Characterise} object - */ - public neqsim.thermo.characterization.Characterise getCharacterization(); - - /** - *

- * readObject. - *

- * - * @param ID a int - * @return a {@link neqsim.thermo.system.SystemInterface} object - */ - public SystemInterface readObject(int ID); - - /** - *

- * getCompIDs. - *

- * - * @return an array of {@link java.lang.String} objects - */ - public String[] getCompIDs(); - - /** - *

- * isImplementedCompositionDeriativesofFugacity. - *

- * - * @param isImpl a boolean - */ - public void isImplementedCompositionDeriativesofFugacity(boolean isImpl); - - /** - *

- * saveObject. - *

- * - * @param ID a int - * @param text a {@link java.lang.String} object - */ - public void saveObject(int ID, String text); - - /** - * Set mole fractions of all components to 0. - */ - public void reset(); - - /** - *

- * getCASNumbers. - *

- * - * @return an array of {@link java.lang.String} objects - */ - public String[] getCASNumbers(); - - /** - *

- * getMolecularWeights. - *

- * - * @return an array of {@link double} objects - */ - public double[] getMolecularWeights(); - - /** - *

- * getNormalBoilingPointTemperatures. - *

- * - * @return an array of {@link double} objects - */ - public double[] getNormalBoilingPointTemperatures(); - - /** - * Get names of all components in System. - * - * @return an array of {@link java.lang.String} objects - */ - public String[] getCompNames(); - - /** - *

- * getCompFormulaes. - *

- * - * @return an array of {@link java.lang.String} objects - */ - public String[] getCompFormulaes(); - - /** - *

- * getWtFraction. - *

- * - * @param phaseNumber a int - * @return a double - */ - public double getWtFraction(int phaseNumber); - - /** - *

- * isMultiphaseWaxCheck. - *

- * - * @return a boolean - */ - public boolean isMultiphaseWaxCheck(); - - /** - *

- * setMultiphaseWaxCheck. - *

- * - * @param multiphaseWaxCheck a boolean - */ - public void setMultiphaseWaxCheck(boolean multiphaseWaxCheck); - - /** - *

- * This method is used to set the total molar composition of a fluid. The total - * flow rate will be kept constant. The input mole fractions will be normalized. - *

- * - * @param moles an array of {@link double} objects - */ - public void setMolarComposition(double[] moles); - - /** - * return the phase of to specified type if the phase does not exist, the method will return - * null - * - * @param phaseTypeName the phase type to be returned (gas, oil, aqueous, wax, hydrate are - * supported) - * @return a {@link neqsim.thermo.phase.PhaseInterface} object - */ - public PhaseInterface getPhaseOfType(String phaseTypeName); - - /** - *

- * setUseTVasIndependentVariables. - *

- * - * @param useTVasIndependentVariables a boolean - */ - public void setUseTVasIndependentVariables(boolean useTVasIndependentVariables); - - /** - * method to add true boiling point fraction - * - * @param componentName selected name of the component to be added - * @param numberOfMoles number of moles to be added - * @param molarMass molar mass of the component in kg/mol - * @param density density of the component in g/cm3 - */ - public void addTBPfraction(String componentName, double numberOfMoles, double molarMass, - double density); - - /** - *

- * addTBPfraction. - *

- * - * @param componentName a {@link java.lang.String} object - * @param numberOfMoles a double - * @param molarMass a double - * @param density a double - * @param criticalTemperature a double - * @param criticalPressure a double - * @param acentricFactor a double - */ - public void addTBPfraction(String componentName, double numberOfMoles, double molarMass, - double density, double criticalTemperature, double criticalPressure, - double acentricFactor); - - /** - *

- * addPlusFraction. - *

- * - * @param componentName a {@link java.lang.String} object - * @param numberOfMoles a double - * @param molarMass a double - * @param density a double - */ - public void addPlusFraction(String componentName, double numberOfMoles, double molarMass, - double density); - - /** - *

- * addSalt. - *

- * - * @param componentName a {@link java.lang.String} object - * @param value a double - */ - public void addSalt(String componentName, double value); - - /** - *

- * deleteFluidPhase. - *

- * - * @param phase a int - */ - public void deleteFluidPhase(int phase); - - /** - *

- * setBmixType. - *

- * - * @param bmixType a int - */ - public void setBmixType(int bmixType); - - /** - *

- * hasSolidPhase. - *

- * - * @return a boolean - */ - public boolean hasSolidPhase(); - - /** - *

- * addSolidComplexPhase. - *

- * - * @param type a {@link java.lang.String} object - */ - public void addSolidComplexPhase(String type); - - /** - *

- * resetCharacterisation. - *

- */ - public void resetCharacterisation(); - - /** - *

- * getMaxNumberOfPhases. - *

- * - * @return a int - */ - public int getMaxNumberOfPhases(); - - /** - *

- * setMaxNumberOfPhases. - *

- * - * @param maxNumberOfPhases a int - */ - public void setMaxNumberOfPhases(int maxNumberOfPhases); - - /** - *

- * getMixingRuleName. - *

- * - * @return a {@link java.lang.String} object - */ - public java.lang.String getMixingRuleName(); - - /** - *

- * Getter for property modelName. - *

- * - * @return a {@link java.lang.String} object - */ - public java.lang.String getModelName(); - - /** - *

- * tuneModel. - *

- * - * @param model a {@link java.lang.String} object - * @param val a double - * @param phase a int - */ - public void tuneModel(String model, double val, int phase); - - /** - * add a component to a fluid. If component name already exists, it will be added to the - * component - * - * @param inComponent a {@link neqsim.thermo.component.ComponentInterface} object - */ - public void addComponent(ComponentInterface inComponent); - - /** - * add a component to a fluid. If component already exists, it will be added to the component - * - * @param name a {@link java.lang.String} object - */ - public void addComponent(String name); - - /** - * add a component to a fluid. If component already exists, it will be added to the component - * - * @param moles number of moles (per second) of the component to be added to the fluid - * @param name a {@link java.lang.String} object - */ - public void addComponent(String name, double moles); - - /** - * add a component to a fluid. If component already exists, it will be added to the component - * - * @param name Name of the component to be added. See NeqSim database for component in the - * database. - * @param unitName the unit of rate (sported units are kg/sec, mol/sec, Nlitre/min, kg/hr, - * Sm^3/hr, Sm^3/day, MSm^3/day .. - * @param value a double - */ - public void addComponent(String name, double value, String unitName); - - /** - *

- * addComponent. - *

- * - * @param name a {@link java.lang.String} object - * @param moles a double - * @param TC a double - * @param PC a double - * @param acs a double - */ - public void addComponent(String name, double moles, double TC, double PC, double acs); - - /** - * add a component to a fluid. I component already exists, it will be added to the component - * - * @param name Name of the component to be added. See NeqSim database for component in the - * database. - * @param moles number of moles (per second) of the component to be added to the fluid - * @param phaseNumber the phase number of the phase to add the component to - */ - public void addComponent(String name, double moles, int phaseNumber); - - /** - * add a component to a fluid. I component already exists, it will be added to the component - * - * @param name Name of the component to be added. See NeqSim database for component in the - * database. - * @param value rate of the component to be added to the fluid - * @param unitName the unit of the flow rate (eg. mol/sec, kg/sec, etc.) - * @param phaseNumber the phase number of the phase to add the component to - */ - public void addComponent(String name, double value, String unitName, int phaseNumber); - - /** - *

- * addComponent. - *

- * - * @param index a int - * @param moles a double - */ - public void addComponent(int index, double moles); - - /** - *

- * addComponent. - *

- * - * @param index a int - * @param moles a double - * @param phaseNumber a int - */ - public void addComponent(int index, double moles, int phaseNumber); - - /** - *

- * getBeta. - *

- * - * @param phase a int - * @return a double - */ - public double getBeta(int phase); - - /** - *

- * save. - *

- * - * @param name a {@link java.lang.String} object - */ - public void save(String name); - - /** - *

- * setModel. - *

- * - * @param model a {@link java.lang.String} object - * @return a {@link neqsim.thermo.system.SystemInterface} object - */ - public SystemInterface setModel(String model); - - /** - *

- * removeComponent. - *

- * - * @param name a {@link java.lang.String} object - */ - public void removeComponent(String name); - - /** - *

- * setMixingRule. - *

- * - * @param typename a {@link java.lang.String} object - * @param GEmodel a {@link java.lang.String} object - */ - public void setMixingRule(String typename, String GEmodel); - - /** - *

- * normalizeBeta. - *

- */ - public void normalizeBeta(); - - /** - *

- * Indexed getter for property phaseIndex. - *

- * - * @param index a int - * @return a int - */ - public int getPhaseIndex(int index); - - /** - *

- * Setter for property initType. - *

- * - * @param initType a int - */ - public void setInitType(int initType); - - /** - *

- * checkStability. - *

- * - * @param val a boolean - */ - public void checkStability(boolean val); - - /** - *

- * hasPlusFraction. - *

- * - * @return a boolean - */ - public boolean hasPlusFraction(); - - /** - *

- * checkStability. - *

- * - * @return a boolean - */ - public boolean checkStability(); - - /** - *

- * Getter for property initType. - *

- * - * @return a int - */ - public int getInitType(); - - /** - *

- * invertPhaseTypes. - *

- */ - public void invertPhaseTypes(); - - /** - * method to return fluid volume with Peneloux volume correction - * - * @return volume in unit m3 - */ - public double getCorrectedVolume(); - - /** - *

- * readFluid. - *

- * - * @param fluidName a {@link java.lang.String} object - */ - public void readFluid(String fluidName); - - /** - *

- * calcKIJ. - *

- * - * @param ok a boolean - */ - public void calcKIJ(boolean ok); - - /** - *

- * write. - *

- * - * @param name a {@link java.lang.String} object - * @param filename a {@link java.lang.String} object - * @param newfile a boolean - */ - public void write(String name, String filename, boolean newfile); - - /** - *

- * useVolumeCorrection. - *

- * - * @param volcor a boolean - */ - public void useVolumeCorrection(boolean volcor); - - /** - * method to set the mixing rule for the fluid - * - * @param typename a {@link java.lang.String} object - */ - public void setMixingRule(String typename); - - /** - *

- * Getter for property numericDerivatives. - *

- * - * @return a boolean - */ - public boolean isNumericDerivatives(); - - /** - *

- * Setter for property numericDerivatives. - *

- * - * @param numericDerivatives a boolean - */ - public void setNumericDerivatives(boolean numericDerivatives); - - /** - *

- * Getter for property info. - *

- * - * @return a {@link java.lang.String} object - */ - public java.lang.String getFluidInfo(); - - /** - *

- * Setter for property info. - * . - *

- * - * @param info a {@link java.lang.String} object - */ - public void setFluidInfo(java.lang.String info); - - /** - *

- * setPhaseIndex. - *

- * - * @param index a int - * @param phaseIndex a int - */ - public void setPhaseIndex(int index, int phaseIndex); - - /** - *

- * Indexed setter for property phaseIndex. - *

- * - * @param phase a {@link neqsim.thermo.phase.PhaseInterface} object - * @param numb a int - */ - public void setPhase(PhaseInterface phase, int numb); - - /** - * method to read pure component and interaction parameters from the NeqSim database and create - * temporary tables with parameters for active fluid. - * - * @param reset If reset is set to true, new temporary tables with parameters for the added - * components will be created. When parameters are needed (eg. when adding components or - * when setting a mixing rule) it will try to find them in the temporary tables first eg. - * COMPTEMP (for pure component parameters) and INTERTEMP (for interaction parameters). - * If reset is set to false it will not create new temporary tables. If a fluid is - * created with the same components many times, performance improvements will be - * obtained, if temporary tables are created the first time (reset=true), and then the - * same tables is used when creating new fluids with the same temporary tables - * (reset=false) - */ - public void createDatabase(boolean reset); - - /** - *

- * resetDatabase. - *

- */ - public void resetDatabase(); - - /** - *

- * Setter for property solidPhaseCheck. - *

- * - * @param test a boolean - */ - public void setSolidPhaseCheck(boolean test); - - /** - *

- * doSolidPhaseCheck. - *

- * - * @return a boolean - */ - public boolean doSolidPhaseCheck(); - - /** - *

- * Getter for property multiPhaseCheck. - *

- * - * @return a boolean - */ - public boolean doMultiPhaseCheck(); - - /** - * method to specify if calculations should check for more than two fluid phases. - * - * @param doMultiPhaseCheck Specify if the calculations should check for more than two fluid - * phases. Default is two fluid phases (gas and liquid). If set to true the program will - * check for gas and multiple liquid phases (eg. gas-oil-aqueous). - */ - public void setMultiPhaseCheck(boolean doMultiPhaseCheck); - - /** - * Calculate thermodynamic properties of the fluid using the init type set in fluid. - * - * @see getInitType - */ - default public void init() { - this.init(this.getInitType()); - } - - /** - * method to calculate thermodynamic properties of the fluid. The temperature, pressure, number - * of phases and composition of the phases will be used as basis for calculation. - * - * - * @param number - The number can be 0, 1, 2 or 3. 0: Set feed composition for all phases. 1: - * Calculation of density, fugacities and Z-factor 2: 1 + calculation of enthalpy, - * entropy, Cp, Cv, and most other thermodynamic properties 3: 1+2 + Calculation of - * composition derivatives of fugacity coefficients. - */ - public void init(int number); - - /** - * method to calculate thermodynamic properties of the selected phase. The temperature, - * pressure, number of phases and composition of the phase will be used as basis for - * calculation. - * - * @param number - The number can be 0, 1, 2 or 3. 0: Set feed composition. 1: Calculation of - * density, fugacities and Z-factor 2: 1 + calculation of enthalpy, entropy, Cp, Cv, and - * most other thermodynamic properties 3: 1+2 + Calculation of composition derivatives of - * fugacity coefficients. - * @param phase a int - */ - public void init(int number, int phase); - - /** - * initNumeric. - */ - public void initNumeric(); - - /** - * Calculates thermodynamic properties of a fluid using the init(2) method - */ - public void initThermoProperties(); - - /** - *

- * display. - *

- */ - public void display(); - - /** - *

- * addFluid. - *

- * - * @param addSystem a {@link neqsim.thermo.system.SystemInterface} object - * @return SystemInterface - */ - public SystemInterface addFluid(SystemInterface addSystem); - - /** - *

- * display. - *

- * - * @param name a {@link java.lang.String} object - */ - public void display(String name); - - /** - *

- * Getter for property hydrateCheck. - *

- * - * @return a boolean - */ - @Deprecated - public boolean doHydrateCheck(); - - /** - *

- * Getter for property hydrateCheck. - *

- * - * @return a boolean - */ - public boolean getHydrateCheck(); - - /** - *

- * createTable. - *

- * - * @param name a {@link java.lang.String} object - * @return an array of {@link java.lang.String} objects - */ - public String[][] createTable(String name); - - /** - *

- * setHydrateCheck. - *

- * - * @param hydrateCheck a boolean - */ - public void setHydrateCheck(boolean hydrateCheck); - - /** - *

- * calcBeta. - *

- * - * @return a double - * @throws neqsim.util.exception.IsNaNException if any. - * @throws neqsim.util.exception.TooManyIterationsException if any. - */ - public double calcBeta() throws neqsim.util.exception.IsNaNException, - neqsim.util.exception.TooManyIterationsException; - - /** - *

- * setAllComponentsInPhase. - *

- * - * @param phase a int - */ - public void setAllComponentsInPhase(int phase); - - /** - *

- * initTotalNumberOfMoles. - *

- * - * @param change a double - */ - public void initTotalNumberOfMoles(double change); - - /** - *

- * calc_x_y. - *

- */ - public void calc_x_y(); - - /** - *

- * getPhase. - *

- * - * @param i a int - * @return a {@link neqsim.thermo.phase.PhaseInterface} object - */ - public PhaseInterface getPhase(int i); - - /** - *

- * reset_x_y. - *

- */ - public void reset_x_y(); - - /** - *

- * isChemicalSystem. - *

- * - * @param temp a boolean - */ - public void isChemicalSystem(boolean temp); - - /** - *

- * addPhase. - *

- */ - public void addPhase(); - - /** - *

- * setAttractiveTerm. - *

- * - * @param i a int - */ - public void setAttractiveTerm(int i); - - /** - *

- * setBeta. - *

- * - * @param phase a int - * @param b a double - */ - public void setBeta(int phase, double b); - - /** - *

- * removePhase. - *

- * - * @param specPhase a int - */ - public void removePhase(int specPhase); - - /** - *

- * phaseToSystem. - *

- * - * @param newPhase a {@link neqsim.thermo.phase.PhaseInterface} object - * @return a {@link neqsim.thermo.system.SystemInterface} object - */ - public SystemInterface phaseToSystem(PhaseInterface newPhase); - - /** - *

- * method to set the temperature of a fluid (same temperature for all phases) - *

- * - * @param temp a double - */ - public void setTemperature(double temp); - - /** - *

- * setTemperature. - *

- * - * @param newTemperature a double - * @param phaseNumber a int - */ - public void setTemperature(double newTemperature, int phaseNumber); - // public void setPressure(double newPressure, int phaseNumber); - - /** - * method to set the pressure of a fluid (same pressure for all phases) - * - * @param pres pressure in unit bara (absolute pressure in bar) - */ - public void setPressure(double pres); - - /** - * method to return pressure - * - * @return pressure in unit bara - */ - public double getPressure(); - - /** - * method to return pressure in a specified unit - * - * @param unit Supported units are bara, barg, Pa and MPa - * @return pressure in specified unit - */ - public double getPressure(String unit); - - /** - *

- * reInitPhaseType. - *

- */ - public void reInitPhaseType(); - - /** - * specify the type for the physical properties you want to use. - * Type - * 0 Orginal/default - * 1 Water - * 2 Glycol - * 3 Amine - * - * @param type a int - */ - public void setPhysicalPropertyModel(int type); - - /** - *

- * clearAll. - *

- */ - public void clearAll(); - - /** - *

- * method to return pressure of phase - *

- * - * @param phaseNumber a int - * @return a double - */ - public double getPressure(int phaseNumber); - - /** - * method to get density of a fluid note: without Peneloux volume correction - * - * @return density with unit kg/m3 - */ - public double getDensity(); - - /** - * method to get density of a fluid note: with Peneloux volume correction - * - * @param unit Supported units are kg/m3, mol/m3 - * @return density in specified unit - */ - public double getDensity(String unit); - - /** - * method to return fluid volume - * - * @return volume in unit m3*1e5 - */ - public double getVolume(); - - /** - *

- * getChemicalReactionOperations. - *

- * - * @return a {@link neqsim.chemicalReactions.ChemicalReactionOperations} object - */ - public ChemicalReactionOperations getChemicalReactionOperations(); - - /** - *

- * isChemicalSystem. - *

- * - * @return a boolean - */ - public boolean isChemicalSystem(); - - /** - * method to return molar volume of the fluid note: without Peneloux volume correction - * - * @return molar volume volume in unit m3/mol*1e5 - */ - public double getMolarVolume(); - - /** - * method to get the total molar mass of a fluid - * - * @return molar mass in unit kg/mol - */ - public double getMolarMass(); - - /** - * method to get the total enthalpy of a fluid - * - * @return molar mass in unit J (Joule) - */ - public double getEnthalpy(); - - /** - *

- * calcInterfaceProperties. - *

- */ - public void calcInterfaceProperties(); - - /** - *

- * getInterphaseProperties. - *

- * - * @return a {@link neqsim.physicalProperties.interfaceProperties.InterphasePropertiesInterface} - * object - */ - public InterphasePropertiesInterface getInterphaseProperties(); - - /** - *

- * initBeta. - *

- * - * @return a double - */ - public double initBeta(); - - /** - *

- * init_x_y. - *

- */ - public void init_x_y(); - - /** - * method to return total entropy of the fluid - * - * @return entropy in unit J/K (Joule/Kelvin) - */ - public double getEntropy(); - - /** - * method to return total entropy of the fluid - * - * @param unit unit supported units are J/K, J/molK, J/kgK and kJ/kgK - * @return entropy in specified unit - */ - public double getEntropy(String unit); - - /** - * method to return temperature - * - * @return temperature in unit Kelvin - */ - public double getTemperature(); - - /** - * method to return temperature in a specified unit - * - * @param unit Supported units are K, C, R - * @return temperature in specified unit - */ - public double getTemperature(String unit); - - /** - *

- * getTemperature. - *

- * - * @param phaseNumber a int - * @return a double - */ - public double getTemperature(int phaseNumber); - - /** - *

- * getBeta. - *

- * - * @return a double - */ - public double getBeta(); - - /** - *

- * chemicalReactionInit. - *

- */ - public void chemicalReactionInit(); - - /** - * Init physical properties for all phases and interfaces. - */ - public void initPhysicalProperties(); - - /** - *

- * setBeta. - *

- * - * @param b a double - */ - public void setBeta(double b); - // public double getdfugdt(int i, int j); - - /** - *

- * method to set the phase type of a given phase - *

- * - * @param phaseToChange a int - * @param newPhaseType a int - */ - public void setPhaseType(int phaseToChange, int newPhaseType); - - /** - *

- * setNumberOfPhases. - *

- * - * @param number a int - */ - public void setNumberOfPhases(int number); - - /** - *

- * getTC. - *

- * - * @return a double - */ - public double getTC(); - - /** - *

- * getPC. - *

- * - * @return a double - */ - public double getPC(); - - /** - *

- * setTC. - *

- * - * @param TC a double - */ - public void setTC(double TC); - - /** - *

- * setPC. - *

- * - * @param PC a double - */ - public void setPC(double PC); - - /** - *

- * getPhases. - *

- * - * @return an array of {@link neqsim.thermo.phase.PhaseInterface} objects - */ - public PhaseInterface[] getPhases(); - - /** - *

- * getNumberOfPhases. - *

- * - * @return a int - */ - public int getNumberOfPhases(); - - /** - *

- * getGibbsEnergy. - *

- * - * @return a double - */ - public double getGibbsEnergy(); - - /** - * method to return internal energy (U) in unit J - * - * @return internal energy in unit Joule (J) - */ - public double getInternalEnergy(); - - /** - *

- * getHelmholtzEnergy. - *

- * - * @return a double - */ - public double getHelmholtzEnergy(); - - /** - *

- * getComponent. - *

- * - * @param name a {@link java.lang.String} object - * @return a {@link neqsim.thermo.component.ComponentInterface} object - */ - public ComponentInterface getComponent(String name); - - /** - *

- * getComponent. - *

- * - * @param number a int - * @return a {@link neqsim.thermo.component.ComponentInterface} object - */ - public ComponentInterface getComponent(int number); - - /** - *

- * getNumberOfMoles. - *

- * - * @return a double - */ - public double getNumberOfMoles(); - - /** - *

- * clone. - *

- * - * @return a {@link neqsim.thermo.system.SystemInterface} object - */ - public SystemInterface clone(); - - /** - * method to set mixing rule used for the fluid - * - * @param type The type of mixing rule to be used for the fluid. 1 - classic mixing rule with - * all kij set to zero 2 -classic mixing rule with kij from NeqSim database 3- classic - * mixing rule with temperature dependent kij 4- Huron Vidal mixing rule with parameters - * from NeqSim database 7 -classic mixing rule with kij of CPA from NeqSim Database 9 - * -classicmixing rule with temperature dependent kij of CPA from NeqSim database - * 10-classic mixing rule with temperature and composition dependent kij of CPA from - * NeqSim database - */ - public void setMixingRule(int type); - - /** - *

- * getComponentNames. - *

- * - * @return an array of {@link java.lang.String} objects - */ - public String[] getComponentNames(); - - /** - *

- * getdVdPtn. - *

- * - * @return a double - */ - public double getdVdPtn(); - - /** - *

- * getdVdTpn. - *

- * - * @return a double - */ - public double getdVdTpn(); - - /** - * method to return specific heat capacity (Cp) - * - * @return Cp in unit J/K - */ - public double getCp(); - - /** - * method to return specific heat capacity (Cp) in a specified unit - * - * @param unit Supported units are J/K, J/molK, J/kgK and kJ/kgK - * @return Cp in specified unit - */ - public double getCp(String unit); - - /** - * method to return heat capacity ratio/adiabatic index/Poisson constant - * - * @return kappa - */ - public double getKappa(); - - /** - *

- * replacePhase. - *

- * - * @param repPhase a int - * @param newPhase a {@link neqsim.thermo.phase.PhaseInterface} object - */ - public void replacePhase(int repPhase, PhaseInterface newPhase); - - /** - *

- * getGasPhase. - *

- * - * @return a {@link neqsim.thermo.phase.PhaseInterface} object - */ - public PhaseInterface getGasPhase(); - - /** - *

- * getLiquidPhase. - *

- * - * @return a {@link neqsim.thermo.phase.PhaseInterface} object - */ - public PhaseInterface getLiquidPhase(); - - /** - * method to return compressibility factor of a fluid compressibility factor is defined in EoS - * from PV=ZnRT where V is total volume of fluid - * - * @return compressibility factor Z - */ - public double getZ(); - - /** - * method to return viscosity of a fluid - * - * @return viscosity in unit kg/msec - */ - public double getViscosity(); - - /** - * method to return viscosity in a specified unit - * - * @param unit Supported units are kg/msec, cP (centipoise) - * @return viscosity in specified unit - */ - public double getViscosity(String unit); - - /** - * method to return thermal conductivity - * - * @return conductivity in unit W/mK - * @deprecated use {@link #getThermalConductivity()} instead. - */ - @Deprecated - public double getConductivity(); - - /** - * method to return thermal conductivity in a specified unit - * - * @param unit Supported units are W/mK, W/cmK - * @return conductivity in specified unit - * @deprecated use {@link #getThermalConductivity(String unit)} instead. - */ - @Deprecated - public double getConductivity(String unit); - - /** - * method to return conductivity of a fluid - * - * @return conductivity in unit W/mK - */ - public double getThermalConductivity(); - - /** - * method to return thermal conductivity in a specified unit - * - * @param unit Supported units are W/mK, W/cmK - * @return conductivity in specified unit - */ - public double getThermalConductivity(String unit); - - /** - * method to return interfacial tension between two phases - * - * @param phase1 phase type of phase1 as string (valid phases are gas, oil, aqueous) - * @param phase2 phase type of phase2 as string (valid phases are gas, oil, aqueous) - * @return interfacial tension with unit N/m. If one or both phases does not exist - the method - * will return NaN - */ - public double getInterfacialTension(String phase1, String phase2); - - /** - * method to return interfacial tension between two phases - * - * @param phase1 phase number of phase1 - * @param phase2 phase number of phase2 - * @return interfacial tension with unit N/m - */ - public double getInterfacialTension(int phase1, int phase2); - - /** - *

- * getKinematicViscosity. - *

- * - * @return a double - */ - public double getKinematicViscosity(); - - /** - *

- * initRefPhases. - *

- */ - public void initRefPhases(); - - /** - *

- * getFluidName. - *

- * - * @return a {@link java.lang.String} object - */ - public java.lang.String getFluidName(); - - /** - *

- * setFluidName. - *

- * - * @param fluidName a {@link java.lang.String} object - */ - public void setFluidName(java.lang.String fluidName); - - /** - *

- * setSolidPhaseCheck. - *

- * - * @param solidComponent a {@link java.lang.String} object - */ - public void setSolidPhaseCheck(String solidComponent); - - /** - *

- * Getter for property allowPhaseShift. - *

- * - * @return a boolean - */ - public boolean allowPhaseShift(); - - /** - *

- * Setter for property allowPhaseShift. - *

- * - * @param allowPhaseShift a boolean - */ - public void allowPhaseShift(boolean allowPhaseShift); - - /** - * method to return phase fraction of selected phase - * - * @param phaseTypeName: gas/oil/aqueous - * @param unit: mole/volume/weight - * @return phase: fraction in specified unit - */ - public double getPhaseFraction(String phaseTypeName, String unit); - - /** - *

- * setPhaseType. - *

- * - * @param phases a {@link java.lang.String} object - * @param newPhaseType a int - */ - public void setPhaseType(String phases, int newPhaseType); - - /** - * method to set the phase type of a given phase - * - * @param phaseToChange the phase number of the phase to set phase type - * @param phaseTypeName the phase type name (valid names are gas or liquid) - */ - public void setPhaseType(int phaseToChange, String phaseTypeName); - - - /** - *

- * getProperty. - *

- * - * @param prop a {@link java.lang.String} object - * @param compName a {@link java.lang.String} object - * @param phase a int - * @return a double - */ - public double getProperty(String prop, String compName, int phase); - - /** - *

- * getProperty. - *

- * - * @param prop a {@link java.lang.String} object - * @param phase a int - * @return a double - */ - public double getProperty(String prop, int phase); - - /** - *

- * getProperty. - *

- * - * @param prop a {@link java.lang.String} object - * @return a double - */ - public double getProperty(String prop); - - /** - *

- * Getter for property standard. - *

- * - * @return a {@link neqsim.standards.StandardInterface} object - */ - public neqsim.standards.StandardInterface getStandard(); - - /** - *

- * Getter for property standard. - *

- * - * @param standardName a {@link java.lang.String} object - * @return a {@link neqsim.standards.StandardInterface} object - */ - public neqsim.standards.StandardInterface getStandard(String standardName); - - /** - *

- * Setter for property standard. - *

- * - * @param standardName a {@link java.lang.String} object - */ - public void setStandard(String standardName); - - /** - *

- * saveToDataBase. - *

- */ - public void saveToDataBase(); - - /** - *

- * generatePDF. - *

- */ - public neqsim.dataPresentation.iTextPDF.PdfCreator generatePDF(); - - /** - *

- * displayPDF. - *

- */ - default public void displayPDF() { - generatePDF().openPDF(); - } - - /** - *

- * getMixingRule. - *

- * - * @return a int - */ - public int getMixingRule(); - - /** - *

- * getResultTable. - *

- * - * @return an array of {@link java.lang.String} objects - */ - public String[][] getResultTable(); - - /** - *

- * autoSelectModel. - *

- * - * @return a {@link neqsim.thermo.system.SystemInterface} object - */ - public SystemInterface autoSelectModel(); - - /** - *

- * autoSelectMixingRule. - *

- */ - public void autoSelectMixingRule(); - - /** - * Order phases by density. - */ - public void orderByDensity(); - - /** - *

- * addLiquidToGas. - *

- * - * @param fraction a double - */ - public void addLiquidToGas(double fraction); - - /** - *

- * addGasToLiquid. - *

- * - * @param fraction a double - */ - public void addGasToLiquid(double fraction); - - /** - * method to get the total molar flow rate of a fluid - * - * @return molar flow in unit mol/sec - */ - public double getTotalNumberOfMoles(); - - /** - *

- * setTotalNumberOfMoles. - *

- * - * @param totalNumberOfMoles a double - */ - public void setTotalNumberOfMoles(double totalNumberOfMoles); - - /** - *

- * phaseToSystem. - *

- * - * @param phaseNumber a int - * @return a {@link neqsim.thermo.system.SystemInterface} object - */ - public SystemInterface phaseToSystem(int phaseNumber); - - /** - *

- * hasPhaseType. - *

- * - * @param phaseTypeName a {@link java.lang.String} object - * @return a boolean - */ - public boolean hasPhaseType(String phaseTypeName); - - /** - *

- * getPhaseNumberOfPhase. - *

- * - * @param phaseTypeName a {@link java.lang.String} object - * @return a int - */ - public int getPhaseNumberOfPhase(String phaseTypeName); - - /** - *

- * getEmptySystemClone. - *

- * - * @return a {@link neqsim.thermo.system.SystemInterface} object - */ - public SystemInterface getEmptySystemClone(); - - /** - *

- * calcHenrysConstant. - *

- * - * @param component a {@link java.lang.String} object - * @return a double - */ - public double calcHenrysConstant(String component); - - /** - *

- * isImplementedTemperatureDeriativesofFugacity. - *

- * - * @return a boolean - */ - public boolean isImplementedTemperatureDeriativesofFugacity(); - - /** - *

- * setImplementedTemperatureDeriativesofFugacity. - *

- * - * @param implementedTemperatureDeriativesofFugacity a boolean - */ - public void setImplementedTemperatureDeriativesofFugacity( - boolean implementedTemperatureDeriativesofFugacity); - - /** - *

- * isImplementedPressureDeriativesofFugacity. - *

- * - * @return a boolean - */ - public boolean isImplementedPressureDeriativesofFugacity(); - - /** - *

- * setImplementedPressureDeriativesofFugacity. - *

- * - * @param implementedPressureDeriativesofFugacity a boolean - */ - public void setImplementedPressureDeriativesofFugacity( - boolean implementedPressureDeriativesofFugacity); - - /** - *

- * isImplementedCompositionDeriativesofFugacity. - *

- * - * @return a boolean - */ - public boolean isImplementedCompositionDeriativesofFugacity(); - - /** - *

- * setImplementedCompositionDeriativesofFugacity. - *

- * - * @param implementedCompositionDeriativesofFugacity a boolean - */ - public void setImplementedCompositionDeriativesofFugacity( - boolean implementedCompositionDeriativesofFugacity); - - /** - *

- * addCapeOpenProperty. - *

- * - * @param propertyName a {@link java.lang.String} object - */ - public void addCapeOpenProperty(String propertyName); - - /** - * Get physical properties of System. - * - * @return System properties - */ - public SystemProperties getProperties(); - - /** {@inheritDoc} */ - @Override - public boolean equals(Object o); - - /** {@inheritDoc} */ - @Override - public int hashCode(); - - /** {@inheritDoc} */ - public void addToComponentNames(java.lang.String name); + } + + /** + *

+ * calcResultTable. + *

+ * + * @return an array of {@link java.lang.String} objects + */ + public default String[][] calcResultTable() { + return createTable(""); + } + + /** + *

+ * getKinematicViscosity. + *

+ * + * @return a double + */ + public double getKinematicViscosity(); + + /** + * method to return kinematic viscosity in a specified unit. + * + * @param unit Supported units are m2/sec + * @return kinematic viscosity in specified unit + */ + public double getKinematicViscosity(String unit); + + /** + *

+ * Get number of components added to System. + *

+ * + * @return the number of components in System. + */ + public int getNumberOfComponents(); + + /** + * This method is used to set the total molar composition of a plus fluid. The total flow rate + * will be kept constant. The input mole fractions will be normalized. + * + * @param molefractions is a double array taking the molar fraction of the components in the + * fluid. THe last molfraction is the mole fraction of the plus component + */ + public void setMolarCompositionPlus(double[] molefractions); + + /** + * This method is used to set the total molar composition of a characterized fluid. The total flow + * rate will be kept constant. The input mole fractions will be normalized. + * + * @param molefractions is a double array taking the molar fraction of the components in the + * fluid. THe last fraction in the array is the total molefraction of the characterized + * components. + */ + public void setMolarCompositionOfPlusFluid(double[] molefractions); + + /** + * method to return exergy in a specified unit. + * + * @param temperatureOfSurroundings in Kelvin + * @return exergy in specified unit + * @param exergyUnit a {@link java.lang.String} object + */ + public double getExergy(double temperatureOfSurroundings, String exergyUnit); + + /** + * method to return exergy defined as (h1-T0*s1) in a unit Joule. + * + * @param temperatureOfSurroundings in Kelvin + * @return a double + */ + public double getExergy(double temperatureOfSurroundings); + + /** + * method to get the Joule Thomson Coefficient of a system. Based on a phase mole fraction basis + * average + * + * @return Joule Thomson coefficient in K/bar + */ + public double getJouleThomsonCoefficient(); + + /** + * method to get the Joule Thomson Coefficient of a system. Based on a phase mole fraction basis + * average. + * + * @param unit Supported units are K/bar, C/bar + * @return Joule Thomson coefficient in specified unit + */ + public double getJouleThomsonCoefficient(String unit); + + /** + * method to return mass of fluid. + * + * @param unit Supported units are kg, gr, tons + * @return mass in specified unit + */ + public double getMass(String unit); + + /** + *

+ * getMoleFractionsSum. + *

+ * + * @return a double + */ + public double getMoleFractionsSum(); + + /** + * method to get the speed of sound of a system. THe sound speed is implemented based on a molar + * average over the phases + * + * @param unit Supported units are m/s, km/h + * @return speed of sound in m/s + */ + public double getSoundSpeed(String unit); + + /** + * method to get the speed of sound of a system. THe sound speed is implemented based on a molar + * average over the phases + * + * @return speed of sound in m/s + */ + public double getSoundSpeed(); + + /** + *

+ * removePhaseKeepTotalComposition. + *

+ * + * @param specPhase a int + */ + public void removePhaseKeepTotalComposition(int specPhase); + + /** + * Init physical properties for all phases and interfaces. + */ + public void initPhysicalProperties(); + + /** + * Calculates physical properties of type propertyName. + * + * @param propertyName a {@link java.lang.String} object + */ + public void initPhysicalProperties(String propertyName); + + /** + * Calculates thermodynamic and physical properties of a fluid using initThermoProperties() and + * initPhysicalProperties(). + */ + public void initProperties(); + + /** + * return two fluid added as a new fluid. + * + * @param addFluid1 first fluid to add + * @param addFluid2 second fluid o add + * @return new fluid + */ + public static SystemInterface addFluids(SystemInterface addFluid1, SystemInterface addFluid2) { + SystemInterface newFluid = addFluid1.clone(); + newFluid.addFluid(addFluid2); + return newFluid; + } + + /** + * method to return interfacial tension between two phases. + * + * @param phase1 phase type of phase1 as string (valid phases are gas, oil, aqueous) + * @param phase2 phase type of phase2 as string (valid phases are gas, oil, aqueous) + * @return interfacial tension with unit N/m. If one or both phases does not exist - the method + * will return NaN + */ + public double getInterfacialTension(String phase1, String phase2); + + /** + * method to return interfacial tension between two phases. + * + * @param phase1 phase number of phase1 + * @param phase2 phase number of phase2 + * @return interfacial tension with unit N/m + */ + public double getInterfacialTension(int phase1, int phase2); + + /** + *

+ * getInterfacialTension. + *

+ * + * @param phase1 a int + * @param phase2 a int + * @param unit a {@link java.lang.String} object + * @return a double + */ + public double getInterfacialTension(int phase1, int phase2, String unit); + + /** + * method to return heat capacity ratio calculated as Cp/(Cp-R). + * + * @return kappa + */ + public default double getGamma2() { + return getCp() / (getCp() - ThermodynamicConstantsInterface.R * getTotalNumberOfMoles()); + } + + /** + * method to return heat capacity ratio/adiabatic index/Poisson constant. + * + * @return kappa + */ + public double getGamma(); + + /** + * method to return fluid volume. + * + * @return volume in unit m3*1e5 + */ + public double getVolume(); + + /** + * method to return fluid volume. + * + * @param unit Supported units are m3, litre, m3/kg, m3/mol + * @return volume in specified unit + */ + public double getVolume(String unit); + + /** + * method to return flow rate of fluid. + * + * @param flowunit Supported units are kg/sec, kg/min, kg/hr m3/sec, m3/min, m3/hr, mole/sec, + * mole/min, mole/hr, Sm3/hr, Sm3/day + * @return flow rate in specified unit + */ + public double getFlowRate(String flowunit); + + /** + * method to set the pressure of a fluid (same pressure for all phases). + * + * @param pres pressure in unit bara (absolute pressure in bar) + */ + public void setPressure(double pres); + + /** + * method to set the pressure of a fluid (same pressure for all phases). + * + * @param newPressure in specified unit + * @param unit unit can be bar, bara, barg or atm + */ + public void setPressure(double newPressure, String unit); + + /** + *

+ * method to set the temperature of a fluid (same temperature for all phases). + *

+ * + * @param temp a double + */ + public void setTemperature(double temp); + + /** + *

+ * setTemperature. + *

+ * + * @param newTemperature a double + * @param phaseNumber a int + */ + public void setTemperature(double newTemperature, int phaseNumber); + + /** + * method to set the temperature of a fluid (same temperature for all phases). + * + * @param newTemperature in specified unit + * @param unit unit can be C or K (Celcius of Kelvin) + */ + public void setTemperature(double newTemperature, String unit); + + /** + * method to return the volume fraction of a phase note: without Peneloux volume correction. + * + * @param phaseNumber number of the phase to get volume fraction for + * @return volume fraction + */ + public double getVolumeFraction(int phaseNumber); + + /** + * method to return the volume fraction of a phase note: with Peneloux volume correction. + * + * @param phaseNumber number of the phase to get volume fraction for + * @return volume fraction + */ + public double getCorrectedVolumeFraction(int phaseNumber); + + /** + *

+ * getHeatOfVaporization. + *

+ * + * @return a double + */ + public double getHeatOfVaporization(); + + /** + * method to return internal energy (U) in unit J. + * + * @return internal energy in unit Joule (J) + */ + public double getInternalEnergy(); + + /** + * method to return internal energy (U) in a specified unit. + * + * @param unit Supported units are 'J', 'J/mol', 'J/kg' and 'kJ/kg' + * @return enthalpy in specified unit + */ + public double getInternalEnergy(String unit); + + /** + *

+ * isForcePhaseTypes. + *

+ * + * @return a boolean + */ + public boolean isForcePhaseTypes(); + + /** + *

+ * setForcePhaseTypes. + *

+ * + * @param forcePhaseTypes a boolean + */ + public void setForcePhaseTypes(boolean forcePhaseTypes); + + /** + * Set the flow rate of all components to zero. + * + * @deprecated use {@link #setEmptyFluid()} instead. + */ + @Deprecated + public default void removeMoles() { + setEmptyFluid(); + } + + /** + * Set the flow rate of all components to zero. + */ + public void setEmptyFluid(); + + /** + *

+ * setMolarFlowRates. + *

+ * + * @param moles an array of {@link double} objects + */ + public void setMolarFlowRates(double[] moles); + + /** + *

+ * setComponentNames. + *

+ * + * @param componentNames an array of {@link java.lang.String} objects + */ + public void setComponentNames(String[] componentNames); + + /** + *

+ * calc_x_y_nonorm. + *

+ */ + public void calc_x_y_nonorm(); + + /** + *

+ * saveObjectToFile. + *

+ * + * @param filePath a {@link java.lang.String} object + * @param fluidName a {@link java.lang.String} object + */ + public void saveObjectToFile(String filePath, String fluidName); + + /** + *

+ * readObjectFromFile. + *

+ * + * @param filePath a {@link java.lang.String} object + * @param fluidName a {@link java.lang.String} object + * @return a {@link neqsim.thermo.system.SystemInterface} object + */ + public SystemInterface readObjectFromFile(String filePath, String fluidName); + + /** + *

+ * getLiquidVolume. + *

+ * + * @return a double + */ + public double getLiquidVolume(); + + /** + *

+ * resetPhysicalProperties. + *

+ */ + public void resetPhysicalProperties(); + + /** + *

+ * phaseToSystem. + *

+ * + * @param phaseNumber a int + * @return a {@link neqsim.thermo.system.SystemInterface} object + */ + public SystemInterface phaseToSystem(int phaseNumber); + + /** + *

+ * phaseToSystem. + *

+ * + * @param newPhase a {@link neqsim.thermo.phase.PhaseInterface} object + * @return a {@link neqsim.thermo.system.SystemInterface} object + */ + public SystemInterface phaseToSystem(PhaseInterface newPhase); + + /** + *

+ * phaseToSystem. + *

+ * + * @param phaseName a {@link java.lang.String} object + * @return a {@link neqsim.thermo.system.SystemInterface} object + */ + public SystemInterface phaseToSystem(String phaseName); + + /** + *

+ * phaseToSystem. + *

+ * + * @param phaseNumber1 a int + * @param phaseNumber2 a int + * @return a {@link neqsim.thermo.system.SystemInterface} object + */ + public SystemInterface phaseToSystem(int phaseNumber1, int phaseNumber2); + + /** + *

+ * changeComponentName. + *

+ * + * @param name a {@link java.lang.String} object + * @param newName a {@link java.lang.String} object + */ + public void changeComponentName(String name, String newName); + + /** + *

+ * getWaxModel. + *

+ * + * @return a {@link neqsim.thermo.characterization.WaxModelInterface} object + */ + public WaxModelInterface getWaxModel(); + + /** + *

+ * getWaxCharacterisation. + *

+ * + * @return a {@link neqsim.thermo.characterization.WaxCharacterise} object + */ + public neqsim.thermo.characterization.WaxCharacterise getWaxCharacterisation(); + + /** + * method to get the total molar flow rate of individual components in a fluid. + * + * @return molar flow of individual components in unit mol/sec + */ + public double[] getMolarRate(); + + /** + * Returns true if phase exists and is not null. + * + * @param i Phase number + * @return True if phase exists, false if not. + */ + public boolean IsPhase(int i); + + /** + * Get phase number i from SystemInterface object. + * + * @param i a int + * @return a {@link neqsim.thermo.phase.PhaseInterface} object + */ + public PhaseInterface getPhase(int i); + + /** + *

+ * getPhase. + *

+ * + * @param phaseTypeName a {@link java.lang.String} object + * @return a {@link neqsim.thermo.phase.PhaseInterface} object + */ + public PhaseInterface getPhase(String phaseTypeName); + + /** + *

+ * getPhaseIndexOfPhase. + *

+ * + * @param phaseTypeName a {@link java.lang.String} object + * @return a int + */ + public int getPhaseIndexOfPhase(String phaseTypeName); + + /** + *

+ * setTotalFlowRate. + *

+ * + * @param flowRate a double + * @param flowunit a {@link java.lang.String} object + */ + public void setTotalFlowRate(double flowRate, String flowunit); + + /** + *

+ * Returns the overall mole composition vector in unit mole fraction. + *

+ * + * @return an array of {@link double} objects + */ + public double[] getMolarComposition(); + + /** + *

+ * getNumberOfOilFractionComponents. + *

+ * + * @return a int + */ + public int getNumberOfOilFractionComponents(); + + /** + *

+ * setHeavyTBPfractionAsPlusFraction. + *

+ * + * @return a boolean + */ + public boolean setHeavyTBPfractionAsPlusFraction(); + + /** + *

+ * getCapeOpenProperties11. + *

+ * + * @return an array of {@link java.lang.String} objects + */ + public String[] getCapeOpenProperties11(); + + /** + *

+ * getCapeOpenProperties10. + *

+ * + * @return an array of {@link java.lang.String} objects + */ + public String[] getCapeOpenProperties10(); + + /** + *

+ * getLowestGibbsEnergyPhase. + *

+ * + * @return a {@link neqsim.thermo.phase.PhaseInterface} object + */ + public PhaseInterface getLowestGibbsEnergyPhase(); + + /** + *

+ * getOilFractionNormalBoilingPoints. + *

+ * + * @return an array of {@link double} objects + */ + public double[] getOilFractionNormalBoilingPoints(); + + /** + *

+ * getOilFractionLiquidDensityAt25C. + *

+ * + * @return an array of {@link double} objects + */ + public double[] getOilFractionLiquidDensityAt25C(); + + /** + *

+ * getOilFractionMolecularMass. + *

+ * + * @return an array of {@link double} objects + */ + public double[] getOilFractionMolecularMass(); + + /** + *

+ * getOilFractionIDs. + *

+ * + * @return an array of {@link int} objects + */ + public int[] getOilFractionIDs(); + + /** + *

+ * getMoleFraction. + *

+ * + * @param phaseNumber a int + * @return a double + */ + public double getMoleFraction(int phaseNumber); + + /** + * method to return specific heat capacity (Cv). + * + * @return Cv in unit J/K + */ + public double getCv(); + + /** + * method to return specific heat capacity (Cp) in a specified unit. + * + * @param unit Supported units are J/K, J/molK, J/kgK and kJ/kgK + * @return Cp in specified unit + */ + public double getCv(String unit); + + /** + *

+ * Getter for property characterization. + *

+ * + * @return a {@link neqsim.thermo.characterization.Characterise} object + */ + public neqsim.thermo.characterization.Characterise getCharacterization(); + + /** + *

+ * readObject. + *

+ * + * @param ID a int + * @return a {@link neqsim.thermo.system.SystemInterface} object + */ + public SystemInterface readObject(int ID); + + /** + *

+ * getCompIDs. + *

+ * + * @return an array of {@link java.lang.String} objects + */ + public String[] getCompIDs(); + + /** + *

+ * saveObject. + *

+ * + * @param ID a int + * @param text a {@link java.lang.String} object + */ + public void saveObject(int ID, String text); + + /** + * Set mole fractions of all components to 0. + */ + public void reset(); + + /** + *

+ * getCASNumbers. + *

+ * + * @return an array of {@link java.lang.String} objects + */ + public String[] getCASNumbers(); + + /** + *

+ * getMolecularWeights. + *

+ * + * @return an array of {@link double} objects + */ + public double[] getMolecularWeights(); + + /** + *

+ * getNormalBoilingPointTemperatures. + *

+ * + * @return an array of {@link double} objects + */ + public double[] getNormalBoilingPointTemperatures(); + + /** + * Get names of all components in System. + * + * @return an array of {@link java.lang.String} objects + */ + public String[] getCompNames(); + + /** + *

+ * getCompFormulaes. + *

+ * + * @return an array of {@link java.lang.String} objects + */ + public String[] getCompFormulaes(); + + /** + *

+ * getWtFraction. + *

+ * + * @param phaseNumber a int + * @return a double + */ + public double getWtFraction(int phaseNumber); + + /** + *

+ * isMultiphaseWaxCheck. + *

+ * + * @return a boolean + */ + public boolean isMultiphaseWaxCheck(); + + /** + *

+ * setMultiphaseWaxCheck. + *

+ * + * @param multiphaseWaxCheck a boolean + */ + public void setMultiphaseWaxCheck(boolean multiphaseWaxCheck); + + /** + *

+ * This method is used to set the total molar composition of a fluid. The total flow rate will be + * kept constant. The input mole fractions will be normalized. + *

+ * + * @param moles an array of {@link double} objects + */ + public void setMolarComposition(double[] moles); + + /** + * return the phase of to specified type if the phase does not exist, the method will return null. + * + * @param phaseTypeName the phase type to be returned (gas, oil, aqueous, wax, hydrate are + * supported) + * @return a {@link neqsim.thermo.phase.PhaseInterface} object + */ + public PhaseInterface getPhaseOfType(String phaseTypeName); + + /** + *

+ * setUseTVasIndependentVariables. + *

+ * + * @param useTVasIndependentVariables a boolean + */ + public void setUseTVasIndependentVariables(boolean useTVasIndependentVariables); + + /** + * method to add true boiling point fraction. + * + * @param componentName selected name of the component to be added + * @param numberOfMoles number of moles to be added + * @param molarMass molar mass of the component in kg/mol + * @param density density of the component in g/cm3 + */ + public void addTBPfraction(String componentName, double numberOfMoles, double molarMass, + double density); + + /** + *

+ * addTBPfraction. + *

+ * + * @param componentName a {@link java.lang.String} object + * @param numberOfMoles a double + * @param molarMass a double + * @param density a double + * @param criticalTemperature a double + * @param criticalPressure a double + * @param acentricFactor a double + */ + public void addTBPfraction(String componentName, double numberOfMoles, double molarMass, + double density, double criticalTemperature, double criticalPressure, double acentricFactor); + + /** + *

+ * addPlusFraction. + *

+ * + * @param componentName a {@link java.lang.String} object + * @param numberOfMoles a double + * @param molarMass a double + * @param density a double + */ + public void addPlusFraction(String componentName, double numberOfMoles, double molarMass, + double density); + + /** + *

+ * addSalt. + *

+ * + * @param componentName a {@link java.lang.String} object + * @param value a double + */ + public void addSalt(String componentName, double value); + + /** + *

+ * deleteFluidPhase. + *

+ * + * @param phase a int + */ + public void deleteFluidPhase(int phase); + + /** + *

+ * setBmixType. + *

+ * + * @param bmixType a int + */ + public void setBmixType(int bmixType); + + /** + *

+ * hasSolidPhase. + *

+ * + * @return a boolean + */ + public boolean hasSolidPhase(); + + /** + *

+ * addSolidComplexPhase. + *

+ * + * @param type a {@link java.lang.String} object + */ + public void addSolidComplexPhase(String type); + + /** + *

+ * resetCharacterisation. + *

+ */ + public void resetCharacterisation(); + + /** + *

+ * getMaxNumberOfPhases. + *

+ * + * @return a int + */ + public int getMaxNumberOfPhases(); + + /** + *

+ * setMaxNumberOfPhases. + *

+ * + * @param maxNumberOfPhases a int + */ + public void setMaxNumberOfPhases(int maxNumberOfPhases); + + /** + *

+ * getMixingRuleName. + *

+ * + * @return a {@link java.lang.String} object + */ + public java.lang.String getMixingRuleName(); + + /** + *

+ * Getter for property modelName. + *

+ * + * @return a {@link java.lang.String} object + */ + public java.lang.String getModelName(); + + /** + *

+ * tuneModel. + *

+ * + * @param model a {@link java.lang.String} object + * @param val a double + * @param phase a int + */ + public void tuneModel(String model, double val, int phase); + + /** + * add a component to a fluid. If component name already exists, it will be added to the component + * + * @param inComponent a {@link neqsim.thermo.component.ComponentInterface} object + */ + public void addComponent(ComponentInterface inComponent); + + /** + * add a component to a fluid. If component already exists, it will be added to the component + * + * @param name a {@link java.lang.String} object + */ + public void addComponent(String name); + + /** + * add a component to a fluid. If component already exists, it will be added to the component + * + * @param moles number of moles (per second) of the component to be added to the fluid + * @param name a {@link java.lang.String} object + */ + public void addComponent(String name, double moles); + + /** + * add a component to a fluid. If component already exists, it will be added to the component + * + * @param name Name of the component to be added. See NeqSim database for component in the + * database. + * @param unitName the unit of rate (sported units are kg/sec, mol/sec, Nlitre/min, kg/hr, + * Sm^3/hr, Sm^3/day, MSm^3/day .. + * @param value a double + */ + public void addComponent(String name, double value, String unitName); + + /** + *

+ * addComponent. + *

+ * + * @param name a {@link java.lang.String} object + * @param moles a double + * @param TC a double + * @param PC a double + * @param acs a double + */ + public void addComponent(String name, double moles, double TC, double PC, double acs); + + /** + * add a component to a fluid. I component already exists, it will be added to the component + * + * @param name Name of the component to be added. See NeqSim database for component in the + * database. + * @param moles number of moles (per second) of the component to be added to the fluid + * @param phaseNumber the phase number of the phase to add the component to + */ + public void addComponent(String name, double moles, int phaseNumber); + + /** + * add a component to a fluid. I component already exists, it will be added to the component + * + * @param name Name of the component to be added. See NeqSim database for component in the + * database. + * @param value rate of the component to be added to the fluid + * @param unitName the unit of the flow rate (eg. mol/sec, kg/sec, etc.) + * @param phaseNumber the phase number of the phase to add the component to + */ + public void addComponent(String name, double value, String unitName, int phaseNumber); + + /** + *

+ * addComponent. + *

+ * + * @param index a int + * @param moles a double + */ + public void addComponent(int index, double moles); + + /** + *

+ * addComponent. + *

+ * + * @param index a int + * @param moles a double + * @param phaseNumber a int + */ + public void addComponent(int index, double moles, int phaseNumber); + + /** + *

+ * getBeta. + *

+ * + * @return a double + */ + public double getBeta(); + + /** + *

+ * getBeta. + *

+ * + * @param phase a int + * @return a double + */ + public double getBeta(int phase); + + /** + *

+ * save. + *

+ * + * @param name a {@link java.lang.String} object + */ + public void save(String name); + + /** + *

+ * setModel. + *

+ * + * @param model a {@link java.lang.String} object + * @return a {@link neqsim.thermo.system.SystemInterface} object + */ + public SystemInterface setModel(String model); + + /** + *

+ * removeComponent. + *

+ * + * @param name a {@link java.lang.String} object + */ + public void removeComponent(String name); + + /** + *

+ * setMixingRule. + *

+ * + * @param typename a {@link java.lang.String} object + * @param GEmodel a {@link java.lang.String} object + */ + public void setMixingRule(String typename, String GEmodel); + + /** + * method to set mixing rule used for the fluid. + * + * @param type The type of mixing rule to be used for the fluid. 1 - classic mixing rule with all + * kij set to zero 2 -classic mixing rule with kij from NeqSim database 3- classic mixing + * rule with temperature dependent kij 4- Huron Vidal mixing rule with parameters from + * NeqSim database 7 -classic mixing rule with kij of CPA from NeqSim Database 9 + * -classicmixing rule with temperature dependent kij of CPA from NeqSim database + * 10-classic mixing rule with temperature and composition dependent kij of CPA from NeqSim + * database + */ + public void setMixingRule(int type); + + /** + * method to set the mixing rule for the fluid. + * + * @param typename a {@link java.lang.String} object + */ + public void setMixingRule(String typename); + + /** + *

+ * normalizeBeta. + *

+ */ + public void normalizeBeta(); + + /** + *

+ * Indexed getter for property phaseIndex. + *

+ * + * @param index a int + * @return a int + */ + public int getPhaseIndex(int index); + + /** + *

+ * Setter for property initType. + *

+ * + * @param initType a int + */ + public void setInitType(int initType); + + /** + *

+ * checkStability. + *

+ * + * @return a boolean + */ + public boolean checkStability(); + + /** + *

+ * checkStability. + *

+ * + * @param val a boolean + */ + public void checkStability(boolean val); + + /** + *

+ * hasPlusFraction. + *

+ * + * @return a boolean + */ + public boolean hasPlusFraction(); + + /** + *

+ * Getter for property initType. + *

+ * + * @return a int + */ + public int getInitType(); + + /** + *

+ * invertPhaseTypes. + *

+ */ + public void invertPhaseTypes(); + + /** + * method to return fluid volume with Peneloux volume correction. + * + * @return volume in unit m3 + */ + public double getCorrectedVolume(); + + /** + *

+ * readFluid. + *

+ * + * @param fluidName a {@link java.lang.String} object + */ + public void readFluid(String fluidName); + + /** + *

+ * calcKIJ. + *

+ * + * @param ok a boolean + */ + public void calcKIJ(boolean ok); + + /** + *

+ * write. + *

+ * + * @param name a {@link java.lang.String} object + * @param filename a {@link java.lang.String} object + * @param newfile a boolean + */ + public void write(String name, String filename, boolean newfile); + + /** + *

+ * useVolumeCorrection. + *

+ * + * @param volcor a boolean + */ + public void useVolumeCorrection(boolean volcor); + + /** + *

+ * Getter for property numericDerivatives. + *

+ * + * @return a boolean + */ + public boolean isNumericDerivatives(); + + /** + *

+ * Setter for property numericDerivatives. + *

+ * + * @param numericDerivatives a boolean + */ + public void setNumericDerivatives(boolean numericDerivatives); + + /** + *

+ * Getter for property info. + *

+ * + * @return a {@link java.lang.String} object + */ + public java.lang.String getFluidInfo(); + + /** + *

+ * Setter for property info. . + *

+ * + * @param info a {@link java.lang.String} object + */ + public void setFluidInfo(java.lang.String info); + + /** + *

+ * setPhaseIndex. + *

+ * + * @param index a int + * @param phaseIndex a int + */ + public void setPhaseIndex(int index, int phaseIndex); + + /** + *

+ * Indexed setter for property phaseIndex. + *

+ * + * @param phase a {@link neqsim.thermo.phase.PhaseInterface} object + * @param numb a int + */ + public void setPhase(PhaseInterface phase, int numb); + + /** + * method to read pure component and interaction parameters from the NeqSim database and create + * temporary tables with parameters for active fluid. + * + * @param reset If reset is set to true, new temporary tables with parameters for the added + * components will be created. When parameters are needed (eg. when adding components or + * when setting a mixing rule) it will try to find them in the temporary tables first eg. + * COMPTEMP (for pure component parameters) and INTERTEMP (for interaction parameters). If + * reset is set to false it will not create new temporary tables. If a fluid is created + * with the same components many times, performance improvements will be obtained, if + * temporary tables are created the first time (reset=true), and then the same tables is + * used when creating new fluids with the same temporary tables (reset=false) + */ + public void createDatabase(boolean reset); + + /** + *

+ * resetDatabase. + *

+ */ + public void resetDatabase(); + + /** + *

+ * Setter for property solidPhaseCheck. + *

+ * + * @param test a boolean + */ + public void setSolidPhaseCheck(boolean test); + + /** + *

+ * setSolidPhaseCheck. + *

+ * + * @param solidComponent a {@link java.lang.String} object + */ + public void setSolidPhaseCheck(String solidComponent); + + /** + *

+ * doSolidPhaseCheck. + *

+ * + * @return a boolean + */ + public boolean doSolidPhaseCheck(); + + /** + *

+ * Getter for property multiPhaseCheck. + *

+ * + * @return a boolean + */ + public boolean doMultiPhaseCheck(); + + /** + * method to specify if calculations should check for more than two fluid phases. + * + * @param doMultiPhaseCheck Specify if the calculations should check for more than two fluid + * phases. Default is two fluid phases (gas and liquid). If set to true the program will + * check for gas and multiple liquid phases (eg. gas-oil-aqueous). + */ + public void setMultiPhaseCheck(boolean doMultiPhaseCheck); + + /** + * Calculate thermodynamic properties of the fluid using the init type set in fluid. + * + * @see getInitType + */ + public default void init() { + this.init(this.getInitType()); + } + + /** + * method to calculate thermodynamic properties of the fluid. The temperature, pressure, number of + * phases and composition of the phases will be used as basis for calculation. + * + * + * @param number - The number can be 0, 1, 2 or 3. 0: Set feed composition for all phases. 1: + * Calculation of density, fugacities and Z-factor 2: 1 + calculation of enthalpy, entropy, + * Cp, Cv, and most other thermodynamic properties 3: 1+2 + Calculation of composition + * derivatives of fugacity coefficients. + */ + public void init(int number); + + /** + * method to calculate thermodynamic properties of the selected phase. The temperature, pressure, + * number of phases and composition of the phase will be used as basis for calculation. + * + * @param number - The number can be 0, 1, 2 or 3. 0: Set feed composition. 1: Calculation of + * density, fugacities and Z-factor 2: 1 + calculation of enthalpy, entropy, Cp, Cv, and + * most other thermodynamic properties 3: 1+2 + Calculation of composition derivatives of + * fugacity coefficients. + * @param phase a int + */ + public void init(int number, int phase); + + /** + * Calculates thermodynamic properties of a fluid using the init(2) method. + */ + public default void initThermoProperties() { + init(2); + } + + /** + * initNumeric. + */ + public void initNumeric(); + + /** + *

+ * display. + *

+ */ + public void display(); + + /** + *

+ * display. + *

+ * + * @param name a {@link java.lang.String} object + */ + public void display(String name); + + /** + *

+ * addFluid. + *

+ * + * @param addSystem a {@link neqsim.thermo.system.SystemInterface} object + * @return SystemInterface + */ + public SystemInterface addFluid(SystemInterface addSystem); + + /** + *

+ * Getter for property hydrateCheck. + *

+ * + * @return a boolean + */ + @Deprecated + public boolean doHydrateCheck(); + + /** + *

+ * Getter for property hydrateCheck. + *

+ * + * @return a boolean + */ + public boolean getHydrateCheck(); + + /** + *

+ * createTable. + *

+ * + * @param name a {@link java.lang.String} object + * @return an array of {@link java.lang.String} objects + */ + public String[][] createTable(String name); + + /** + *

+ * setHydrateCheck. + *

+ * + * @param hydrateCheck a boolean + */ + public void setHydrateCheck(boolean hydrateCheck); + + /** + *

+ * calcBeta. + *

+ * + * @return a double + * @throws neqsim.util.exception.IsNaNException if any. + * @throws neqsim.util.exception.TooManyIterationsException if any. + */ + public double calcBeta() + throws neqsim.util.exception.IsNaNException, neqsim.util.exception.TooManyIterationsException; + + /** + *

+ * setAllComponentsInPhase. + *

+ * + * @param phase a int + */ + public void setAllComponentsInPhase(int phase); + + /** + *

+ * initTotalNumberOfMoles. + *

+ * + * @param change a double + */ + public void initTotalNumberOfMoles(double change); + + /** + *

+ * calc_x_y. + *

+ */ + public void calc_x_y(); + + /** + *

+ * reset_x_y. + *

+ */ + public void reset_x_y(); + + /** + * Add phase to SystemInterface object. + */ + public void addPhase(); + + /** + *

+ * setAttractiveTerm. + *

+ * + * @param i a int + */ + public void setAttractiveTerm(int i); + + /** + *

+ * setBeta. + *

+ * + * @param b a double + */ + public void setBeta(double b); + + /** + *

+ * setBeta. + *

+ * + * @param phase a int + * @param b a double + */ + public void setBeta(int phase, double b); + + /** + *

+ * removePhase. + *

+ * + * @param specPhase a int + */ + public void removePhase(int specPhase); + + // public void setPressure(double newPressure, int phaseNumber); + + /** + * method to return pressure. + * + * @return pressure in unit bara + */ + public double getPressure(); + + /** + *

+ * method to return pressure of phase. + *

+ * + * @param phaseNumber a int + * @return a double + */ + public double getPressure(int phaseNumber); + + /** + * method to return pressure in a specified unit. + * + * @param unit Supported units are bara, barg, Pa and MPa + * @return pressure in specified unit + */ + public double getPressure(String unit); + + /** + *

+ * reInitPhaseType. + *

+ */ + public void reInitPhaseType(); + + /** + * specify the type for the physical properties you want to use. Type 0 Orginal/default 1 Water 2 + * Glycol 3 Amine. + * + * @param type a int + */ + public void setPhysicalPropertyModel(int type); + + /** + *

+ * clearAll. + *

+ */ + public void clearAll(); + + /** + * method to get density of a fluid note: without Peneloux volume correction. + * + * @return density with unit kg/m3 + */ + public double getDensity(); + + /** + * method to get density of a fluid note: with Peneloux volume correction. + * + * @param unit Supported units are kg/m3, mol/m3 + * @return density in specified unit + */ + public double getDensity(String unit); + + /** + *

+ * getChemicalReactionOperations. + *

+ * + * @return a {@link neqsim.chemicalReactions.ChemicalReactionOperations} object + */ + public ChemicalReactionOperations getChemicalReactionOperations(); + + /** + *

+ * isChemicalSystem. + *

+ * + * @return a boolean + */ + public boolean isChemicalSystem(); + + /** + *

+ * isChemicalSystem. + *

+ * + * @param temp a boolean + */ + public void isChemicalSystem(boolean temp); + + /** + * method to return molar volume of the fluid note: without Peneloux volume correction. + * + * @return molar volume volume in unit m3/mol*1e5 + */ + public double getMolarVolume(); + + /** + * method to get the total molar mass of a fluid. + * + * @return molar mass in unit kg/mol + */ + public double getMolarMass(); + + /** + * method to get molar mass of a fluid phase. + * + * @param unit Supported units are kg/mol, gr/mol + * @return molar mass in specified unit + */ + public double getMolarMass(String unit); + + /** + * method to get the total enthalpy of a fluid. + * + * @return molar mass in unit J (Joule) + */ + public double getEnthalpy(); + + /** + * method to return total enthalpy in a specified unit. + * + * @param unit Supported units are 'J', 'J/mol', 'J/kg' and 'kJ/kg' + * @return enthalpy in specified unit + */ + public double getEnthalpy(String unit); + + /** + *

+ * calcInterfaceProperties. + *

+ */ + public void calcInterfaceProperties(); + + /** + *

+ * getInterphaseProperties. + *

+ * + * @return a {@link neqsim.physicalProperties.interfaceProperties.InterphasePropertiesInterface} + * object + */ + public InterphasePropertiesInterface getInterphaseProperties(); + + /** + *

+ * initBeta. + *

+ * + * @return a double + */ + public double initBeta(); + + /** + *

+ * init_x_y. + *

+ */ + public void init_x_y(); + + /** + * method to return total entropy of the fluid. + * + * @return entropy in unit J/K (Joule/Kelvin) + */ + public double getEntropy(); + + /** + * method to return total entropy of the fluid. + * + * @param unit unit supported units are J/K, J/molK, J/kgK and kJ/kgK + * @return entropy in specified unit + */ + public double getEntropy(String unit); + + /** + * method to return temperature. + * + * @return temperature in unit Kelvin + */ + public double getTemperature(); + + /** + * method to return temperature in a specified unit. + * + * @param unit Supported units are K, C, R + * @return temperature in specified unit + */ + public double getTemperature(String unit); + + /** + *

+ * getTemperature. + *

+ * + * @param phaseNumber a int + * @return a double + */ + public double getTemperature(int phaseNumber); + + /** + *

+ * chemicalReactionInit. + *

+ */ + public void chemicalReactionInit(); + + // public double getdfugdt(int i, int j); + + /** + *

+ * method to set the phase type of a given phase. + *

+ * + * @param phaseToChange a int + * @param newPhaseType a int + */ + public void setPhaseType(int phaseToChange, int newPhaseType); + + /** + *

+ * setPhaseType. + *

+ * + * @param phases a {@link java.lang.String} object + * @param newPhaseType a int + */ + public void setPhaseType(String phases, int newPhaseType); + + /** + * method to set the phase type of a given phase. + * + * @param phaseToChange the phase number of the phase to set phase type + * @param phaseTypeName the phase type name (valid names are gas or liquid) + */ + public void setPhaseType(int phaseToChange, String phaseTypeName); + + /** + *

+ * setNumberOfPhases. + *

+ * + * @param number a int + */ + public void setNumberOfPhases(int number); + + /** + *

+ * getTC. + *

+ * + * @return a double + */ + public double getTC(); + + /** + *

+ * getPC. + *

+ * + * @return a double + */ + public double getPC(); + + /** + *

+ * setTC. + *

+ * + * @param TC a double + */ + public void setTC(double TC); + + /** + *

+ * setPC. + *

+ * + * @param PC a double + */ + public void setPC(double PC); + + /** + *

+ * getPhases. + *

+ * + * @return an array of {@link neqsim.thermo.phase.PhaseInterface} objects + */ + public PhaseInterface[] getPhases(); + + /** + *

+ * getNumberOfPhases. + *

+ * + * @return a int + */ + public int getNumberOfPhases(); + + /** + *

+ * getGibbsEnergy. + *

+ * + * @return a double + */ + public double getGibbsEnergy(); + + /** + *

+ * getHelmholtzEnergy. + *

+ * + * @return a double + */ + public double getHelmholtzEnergy(); + + /** + *

+ * getComponent. + *

+ * + * @param name a {@link java.lang.String} object + * @return a {@link neqsim.thermo.component.ComponentInterface} object + */ + public ComponentInterface getComponent(String name); + + /** + *

+ * getComponent. + *

+ * + * @param number a int + * @return a {@link neqsim.thermo.component.ComponentInterface} object + */ + public ComponentInterface getComponent(int number); + + /** + *

+ * getNumberOfMoles. + *

+ * + * @return a double + */ + public double getNumberOfMoles(); + + /** + *

+ * clone. + *

+ * + * @return a {@link neqsim.thermo.system.SystemInterface} object + */ + public SystemInterface clone(); + + /** + *

+ * getComponentNames. + *

+ * + * @return an array of {@link java.lang.String} objects + */ + public String[] getComponentNames(); + + /** + *

+ * getdVdPtn. + *

+ * + * @return a double + */ + public double getdVdPtn(); + + /** + *

+ * getdVdTpn. + *

+ * + * @return a double + */ + public double getdVdTpn(); + + /** + * method to return specific heat capacity (Cp). + * + * @return Cp in unit J/K + */ + public double getCp(); + + /** + * method to return specific heat capacity (Cp) in a specified unit. + * + * @param unit Supported units are J/K, J/molK, J/kgK and kJ/kgK + * @return Cp in specified unit + */ + public double getCp(String unit); + + /** + * method to return heat capacity ratio/adiabatic index/Poisson constant. + * + * @return kappa + */ + + public double getKappa(); + + /** + *

+ * replacePhase. + *

+ * + * @param repPhase a int + * @param newPhase a {@link neqsim.thermo.phase.PhaseInterface} object + */ + public void replacePhase(int repPhase, PhaseInterface newPhase); + + /** + *

+ * getGasPhase. + *

+ * + * @return a {@link neqsim.thermo.phase.PhaseInterface} object + */ + public PhaseInterface getGasPhase(); + + /** + *

+ * getLiquidPhase. + *

+ * + * @return a {@link neqsim.thermo.phase.PhaseInterface} object + */ + public PhaseInterface getLiquidPhase(); + + /** + * method to return compressibility factor of a fluid compressibility factor is defined in EoS + * from PV=ZnRT where V is total volume of fluid. + * + * @return compressibility factor Z + */ + public double getZ(); + + /** + * method to return viscosity of a fluid. + * + * @return viscosity in unit kg/msec + */ + public double getViscosity(); + + /** + * method to return viscosity in a specified unit. + * + * @param unit Supported units are kg/msec, cP (centipoise) + * @return viscosity in specified unit + */ + public double getViscosity(String unit); + + /** + * method to return thermal conductivity. + * + * @return conductivity in unit W/mK + * @deprecated use {@link #getThermalConductivity()} instead. + */ + @Deprecated + public double getConductivity(); + + /** + * method to return thermal conductivity in a specified unit. + * + * @param unit Supported units are W/mK, W/cmK + * @return conductivity in specified unit + * @deprecated use {@link #getThermalConductivity(String unit)} instead. + */ + @Deprecated + public double getConductivity(String unit); + + /** + * method to return conductivity of a fluid. + * + * @return conductivity in unit W/mK + */ + public double getThermalConductivity(); + + /** + * method to return thermal conductivity in a specified unit. + * + * @param unit Supported units are W/mK, W/cmK + * @return conductivity in specified unit + */ + public double getThermalConductivity(String unit); + + /** + *

+ * initRefPhases. + *

+ */ + public void initRefPhases(); + + /** + *

+ * getFluidName. + *

+ * + * @return a {@link java.lang.String} object + */ + public java.lang.String getFluidName(); + + /** + *

+ * setFluidName. + *

+ * + * @param fluidName a {@link java.lang.String} object + */ + public void setFluidName(java.lang.String fluidName); + + /** + *

+ * Getter for property allowPhaseShift. + *

+ * + * @return a boolean + */ + public boolean allowPhaseShift(); + + /** + *

+ * Setter for property allowPhaseShift. + *

+ * + * @param allowPhaseShift a boolean + */ + public void allowPhaseShift(boolean allowPhaseShift); + + /** + * method to return phase fraction of selected phase. + * + * @param phaseTypeName gas/oil/aqueous + * @param unit mole/volume/weight + * @return phase: fraction in specified unit + */ + public double getPhaseFraction(String phaseTypeName, String unit); + + /** + *

+ * getProperty. + *

+ * + * @param prop a {@link java.lang.String} object + * @param compName a {@link java.lang.String} object + * @param phase a int + * @return a double + */ + public double getProperty(String prop, String compName, int phase); + + /** + *

+ * getProperty. + *

+ * + * @param prop a {@link java.lang.String} object + * @param phase a int + * @return a double + */ + public double getProperty(String prop, int phase); + + /** + *

+ * getProperty. + *

+ * + * @param prop a {@link java.lang.String} object + * @return a double + */ + public double getProperty(String prop); + + /** + *

+ * Getter for property standard. + *

+ * + * @return a {@link neqsim.standards.StandardInterface} object + */ + public neqsim.standards.StandardInterface getStandard(); + + /** + *

+ * Getter for property standard. + *

+ * + * @param standardName a {@link java.lang.String} object + * @return a {@link neqsim.standards.StandardInterface} object + */ + public neqsim.standards.StandardInterface getStandard(String standardName); + + /** + *

+ * Setter for property standard. + *

+ * + * @param standardName a {@link java.lang.String} object + */ + public void setStandard(String standardName); + + /** + *

+ * saveToDataBase. + *

+ */ + public void saveToDataBase(); + + /** + *

+ * getMixingRule. + *

+ * + * @return a int + */ + public int getMixingRule(); + + /** + *

+ * getResultTable. + *

+ * + * @return an array of {@link java.lang.String} objects + */ + public String[][] getResultTable(); + + /** + *

+ * autoSelectModel. + *

+ * + * @return a {@link neqsim.thermo.system.SystemInterface} object + */ + public SystemInterface autoSelectModel(); + + /** + *

+ * autoSelectMixingRule. + *

+ */ + public void autoSelectMixingRule(); + + /** + * Order phases by density. + */ + public void orderByDensity(); + + /** + *

+ * addLiquidToGas. + *

+ * + * @param fraction a double + */ + public void addLiquidToGas(double fraction); + + /** + *

+ * addGasToLiquid. + *

+ * + * @param fraction a double + */ + public void addGasToLiquid(double fraction); + + /** + * method to get the total molar flow rate of a fluid. + * + * @return molar flow in unit mol/sec + */ + public double getTotalNumberOfMoles(); + + /** + *

+ * setTotalNumberOfMoles. + *

+ * + * @param totalNumberOfMoles a double + */ + public void setTotalNumberOfMoles(double totalNumberOfMoles); + + /** + *

+ * hasPhaseType. + *

+ * + * @param phaseTypeName a {@link java.lang.String} object + * @return a boolean + */ + public boolean hasPhaseType(String phaseTypeName); + + /** + *

+ * getPhaseNumberOfPhase. + *

+ * + * @param phaseTypeName a {@link java.lang.String} object + * @return a int + */ + public int getPhaseNumberOfPhase(String phaseTypeName); + + /** + *

+ * getEmptySystemClone. + *

+ * + * @return a {@link neqsim.thermo.system.SystemInterface} object + */ + public SystemInterface getEmptySystemClone(); + + /** + *

+ * calcHenrysConstant. + *

+ * + * @param component a {@link java.lang.String} object + * @return a double + */ + public double calcHenrysConstant(String component); + + /** + *

+ * isImplementedTemperatureDeriativesofFugacity. + *

+ * + * @return a boolean + */ + public boolean isImplementedTemperatureDeriativesofFugacity(); + + /** + *

+ * setImplementedTemperatureDeriativesofFugacity. + *

+ * + * @param implementedTemperatureDeriativesofFugacity a boolean + */ + public void setImplementedTemperatureDeriativesofFugacity( + boolean implementedTemperatureDeriativesofFugacity); + + /** + *

+ * isImplementedPressureDeriativesofFugacity. + *

+ * + * @return a boolean + */ + public boolean isImplementedPressureDeriativesofFugacity(); + + /** + *

+ * setImplementedPressureDeriativesofFugacity. + *

+ * + * @param implementedPressureDeriativesofFugacity a boolean + */ + public void setImplementedPressureDeriativesofFugacity( + boolean implementedPressureDeriativesofFugacity); + + /** + *

+ * isImplementedCompositionDeriativesofFugacity. + *

+ * + * @return a boolean + */ + public boolean isImplementedCompositionDeriativesofFugacity(); + + /** + *

+ * isImplementedCompositionDeriativesofFugacity. + *

+ * + * @param isImpl a boolean + */ + public void isImplementedCompositionDeriativesofFugacity(boolean isImpl); + + /** + *

+ * setImplementedCompositionDeriativesofFugacity. + *

+ * + * @param implementedCompositionDeriativesofFugacity a boolean + */ + public void setImplementedCompositionDeriativesofFugacity( + boolean implementedCompositionDeriativesofFugacity); + + /** + *

+ * addCapeOpenProperty. + *

+ * + * @param propertyName a {@link java.lang.String} object + */ + public void addCapeOpenProperty(String propertyName); + + /** + * Get physical properties of System. + * + * @return System properties + */ + public SystemProperties getProperties(); + + /** {@inheritDoc} */ + @Override + public boolean equals(Object o); + + /** {@inheritDoc} */ + @Override + public int hashCode(); + + /** {@inheritDoc} */ + public void addToComponentNames(java.lang.String name); } diff --git a/src/main/java/neqsim/thermo/system/SystemKentEisenberg.java b/src/main/java/neqsim/thermo/system/SystemKentEisenberg.java index df7af04c72..666c244305 100644 --- a/src/main/java/neqsim/thermo/system/SystemKentEisenberg.java +++ b/src/main/java/neqsim/thermo/system/SystemKentEisenberg.java @@ -5,7 +5,7 @@ import neqsim.thermo.phase.PhaseSrkEos; /** - * This class defines a thermodynamic system using the SRK equation of state + * This class defines a thermodynamic system using the Kent Eisenberg model * * @author Even Solbraa */ diff --git a/src/main/java/neqsim/thermo/system/SystemNRTL.java b/src/main/java/neqsim/thermo/system/SystemNRTL.java index f9d6d67f86..24d173a004 100644 --- a/src/main/java/neqsim/thermo/system/SystemNRTL.java +++ b/src/main/java/neqsim/thermo/system/SystemNRTL.java @@ -5,7 +5,7 @@ import neqsim.thermo.phase.PhaseSrkEos; /** - * This class defines a thermodynamic system using the SRK EoS amd NRTL for liquids + * This class defines a thermodynamic system using the SRK EoS for gas and NRTL for liquids * * @author Even Solbraa */ diff --git a/src/main/java/neqsim/thermo/system/SystemPrDanesh.java b/src/main/java/neqsim/thermo/system/SystemPrDanesh.java index bc44f6726e..8c4a498320 100644 --- a/src/main/java/neqsim/thermo/system/SystemPrDanesh.java +++ b/src/main/java/neqsim/thermo/system/SystemPrDanesh.java @@ -5,7 +5,7 @@ import neqsim.thermo.phase.PhasePureComponentSolid; /** - * This class defines a thermodynamic system using the SRK equation of state + * This class defines a thermodynamic system using the PR Danesh equation of state * * @author Even Solbraa */ diff --git a/src/main/java/neqsim/thermo/system/SystemPrEos1978.java b/src/main/java/neqsim/thermo/system/SystemPrEos1978.java index 25d622b94a..d3b43618cf 100644 --- a/src/main/java/neqsim/thermo/system/SystemPrEos1978.java +++ b/src/main/java/neqsim/thermo/system/SystemPrEos1978.java @@ -5,7 +5,7 @@ import neqsim.thermo.phase.PhasePureComponentSolid; /** - * This class defines a thermodynamic system using the Peng RObinson v. 1978 equation of state + * This class defines a thermodynamic system using the Peng Robinson v. 1978 equation of state * * @author Even Solbraa */ diff --git a/src/main/java/neqsim/thermo/system/SystemPrEosDelft1998.java b/src/main/java/neqsim/thermo/system/SystemPrEosDelft1998.java index 292bb675fb..ce73a05c02 100644 --- a/src/main/java/neqsim/thermo/system/SystemPrEosDelft1998.java +++ b/src/main/java/neqsim/thermo/system/SystemPrEosDelft1998.java @@ -5,7 +5,8 @@ import neqsim.thermo.phase.PhasePureComponentSolid; /** - * This class defines a thermodynamic system using the SRK equation of state + * This class defines a thermodynamic system using the PR EoS version of Delft (1998) equation of + * state * * @author Even Solbraa */ diff --git a/src/main/java/neqsim/thermo/system/SystemPrGassemEos.java b/src/main/java/neqsim/thermo/system/SystemPrGassemEos.java index 9b292d72f7..71b8d462b9 100644 --- a/src/main/java/neqsim/thermo/system/SystemPrGassemEos.java +++ b/src/main/java/neqsim/thermo/system/SystemPrGassemEos.java @@ -5,7 +5,7 @@ import neqsim.thermo.phase.PhasePureComponentSolid; /** - * This class defines a thermodynamic system using the SRK equation of state + * This class defines a thermodynamic system using the PR Gassem equation of state * * @author Even Solbraa */ diff --git a/src/main/java/neqsim/thermo/system/SystemPrMathiasCopeman.java b/src/main/java/neqsim/thermo/system/SystemPrMathiasCopeman.java index cad18ef3ef..e3ff1d3d43 100644 --- a/src/main/java/neqsim/thermo/system/SystemPrMathiasCopeman.java +++ b/src/main/java/neqsim/thermo/system/SystemPrMathiasCopeman.java @@ -1,7 +1,7 @@ package neqsim.thermo.system; /** - * This class defines a thermodynamic system using the SRK equation of state + * This class defines a thermodynamic system using the PR Mathias Copeman equation of state * * @author Even Solbraa */ diff --git a/src/main/java/neqsim/thermo/system/SystemProperties.java b/src/main/java/neqsim/thermo/system/SystemProperties.java index 2ee0dd1eac..820c477d52 100644 --- a/src/main/java/neqsim/thermo/system/SystemProperties.java +++ b/src/main/java/neqsim/thermo/system/SystemProperties.java @@ -12,7 +12,7 @@ public class SystemProperties { /** * Constructur for SystemProperties. * - * @param fluid + * @param fluid input fluid */ public SystemProperties(SystemInterface fluid) { final String[] phaseName = {"gas", "oil", "aqueous"}; diff --git a/src/main/java/neqsim/thermo/system/SystemSrkPenelouxEos.java b/src/main/java/neqsim/thermo/system/SystemSrkPenelouxEos.java index efaf18cf29..510cfd1cb4 100644 --- a/src/main/java/neqsim/thermo/system/SystemSrkPenelouxEos.java +++ b/src/main/java/neqsim/thermo/system/SystemSrkPenelouxEos.java @@ -5,7 +5,7 @@ import neqsim.thermo.phase.PhaseSrkPenelouxEos; /** - * This class defines a thermodynamic system using the SRK equation of state + * This class defines a thermodynamic system using the SRK Peneloux equation of state * * @author Even Solbraa */ diff --git a/src/main/java/neqsim/thermo/system/SystemSrkSchwartzentruberEos.java b/src/main/java/neqsim/thermo/system/SystemSrkSchwartzentruberEos.java index 7d8b9d40a1..1251b54ac8 100644 --- a/src/main/java/neqsim/thermo/system/SystemSrkSchwartzentruberEos.java +++ b/src/main/java/neqsim/thermo/system/SystemSrkSchwartzentruberEos.java @@ -1,7 +1,7 @@ package neqsim.thermo.system; /** - * This class defines a thermodynamic system using the SRK equation of state + * This class defines a thermodynamic system using the SRK Schwartzentruber equation of state * * @author Even Solbraa */ diff --git a/src/main/java/neqsim/thermo/system/SystemSrkTwuCoonEos.java b/src/main/java/neqsim/thermo/system/SystemSrkTwuCoonEos.java index a036b33cdb..492d9f4839 100644 --- a/src/main/java/neqsim/thermo/system/SystemSrkTwuCoonEos.java +++ b/src/main/java/neqsim/thermo/system/SystemSrkTwuCoonEos.java @@ -1,7 +1,7 @@ package neqsim.thermo.system; /** - * This class defines a thermodynamic system using the SRK equation of state + * This class defines a thermodynamic system using the SRK Two Coon equation of state * * @author Even Solbraa */ diff --git a/src/main/java/neqsim/thermo/system/SystemSrkTwuCoonParamEos.java b/src/main/java/neqsim/thermo/system/SystemSrkTwuCoonParamEos.java index 0a987a7781..765daae2a3 100644 --- a/src/main/java/neqsim/thermo/system/SystemSrkTwuCoonParamEos.java +++ b/src/main/java/neqsim/thermo/system/SystemSrkTwuCoonParamEos.java @@ -1,7 +1,7 @@ package neqsim.thermo.system; /** - * This class defines a thermodynamic system using the SRK equation of state + * This class defines a thermodynamic system using the SRK Two Coon Param equation of state * * @author Even Solbraa */ diff --git a/src/main/java/neqsim/thermo/system/SystemSrkTwuCoonStatoilEos.java b/src/main/java/neqsim/thermo/system/SystemSrkTwuCoonStatoilEos.java index 8158f4c7b8..2cb91cfe86 100644 --- a/src/main/java/neqsim/thermo/system/SystemSrkTwuCoonStatoilEos.java +++ b/src/main/java/neqsim/thermo/system/SystemSrkTwuCoonStatoilEos.java @@ -1,9 +1,8 @@ package neqsim.thermo.system; /** - *

- * SystemSrkTwuCoonStatoilEos class. - *

+ * This class defines a thermodynamic system using the SRK Two Coon model of Statoil equation of + * state * * @author asmund * @version $Id: $Id diff --git a/src/main/java/neqsim/thermo/system/SystemTSTEos.java b/src/main/java/neqsim/thermo/system/SystemTSTEos.java index ad665d0063..15be830516 100644 --- a/src/main/java/neqsim/thermo/system/SystemTSTEos.java +++ b/src/main/java/neqsim/thermo/system/SystemTSTEos.java @@ -5,7 +5,7 @@ import neqsim.thermo.phase.PhaseTSTEos; /** - * This class defines a thermodynamic system using the SRK equation of state + * This class defines a thermodynamic system using the TST equation of state * * @author Even Solbraa */ diff --git a/src/main/java/neqsim/thermo/system/SystemThermo.java b/src/main/java/neqsim/thermo/system/SystemThermo.java index 46e4164e83..511cad5d22 100644 --- a/src/main/java/neqsim/thermo/system/SystemThermo.java +++ b/src/main/java/neqsim/thermo/system/SystemThermo.java @@ -1,7 +1,6 @@ package neqsim.thermo.system; import java.awt.BorderLayout; -import java.awt.Color; import java.awt.Container; import java.awt.Dimension; import java.awt.Font; @@ -55,19 +54,28 @@ abstract class SystemThermo implements SystemInterface { protected String[][] resultTable = null; boolean isInitialized = false; protected String fluidInfo = "No Information Available"; - protected String fluidName = "DefaultName", modelName = "Default"; - protected boolean numericDerivatives = false, allowPhaseShift = true; + protected String fluidName = "DefaultName"; + + protected String modelName = "Default"; + + protected boolean numericDerivatives = false; + + protected boolean allowPhaseShift = true; + private boolean useTVasIndependentVariables = false; protected double criticalPressure = 0; private double totalNumberOfMoles = 0; public String componentNameTag = ""; - protected neqsim.thermo.characterization.WaxCharacterise waxCharacterisation = null;// new - // WaxCharacterise(this); + protected neqsim.thermo.characterization.WaxCharacterise waxCharacterisation = null; // new + // WaxCharacterise(this); protected double[] beta = new double[6]; - protected int a, initType = 3; + protected int a; + + protected int initType = 3; + private ArrayList componentNames = new ArrayList(); // protected ArrayList resultArray1 = new ArrayList(); - protected String[] CapeOpenProperties11 = {"molecularWeight", "speedOfSound", + protected String[] CapeOpenProperties11 = { "molecularWeight", "speedOfSound", "jouleThomsonCoefficient", "internalEnergy", "internalEnergy.Dtemperature", "gibbsEnergy", "helmholtzEnergy", "fugacityCoefficient", "logFugacityCoefficient", "logFugacityCoefficient.Dtemperature", "logFugacityCoefficient.Dpressure", @@ -76,8 +84,8 @@ abstract class SystemThermo implements SystemInterface { "entropy.Dmoles", "heatCapacityCp", "heatCapacityCv", "density", "density.Dtemperature", "density.Dpressure", "density.Dmoles", "volume", "volume.Dpressure", "volume.Dtemperature", "molecularWeight.Dtemperature", "molecularWeight.Dpressure", "molecularWeight.Dmoles", - "compressibilityFactor"}; - protected String[] CapeOpenProperties10 = {"molecularWeight", "speedOfSound", + "compressibilityFactor" }; + protected String[] CapeOpenProperties10 = { "molecularWeight", "speedOfSound", "jouleThomsonCoefficient", "energy", "energy.Dtemperature", "gibbsFreeEnergy", "helmholtzFreeEnergy", "fugacityCoefficient", "logFugacityCoefficient", "logFugacityCoefficient.Dtemperature", "logFugacityCoefficient.Dpressure", @@ -86,19 +94,25 @@ abstract class SystemThermo implements SystemInterface { "entropy.Dmoles", "heatCapacity", "heatCapacityCv", "density", "density.Dtemperature", "density.Dpressure", "density.Dmoles", "volume", "volume.Dpressure", "volume.Dtemperature", "molecularWeight.Dtemperature", "molecularWeight.Dpressure", "molecularWeight.Dmoles", - "compressibilityFactor"}; + "compressibilityFactor" }; protected int numberOfComponents = 0; protected int numberOfPhases = 2; public int maxNumberOfPhases = 2; protected int attractiveTermNumber = 0; protected int phase = 2; protected int onePhaseType = 1; // 0 - liquid 1 - gas - protected int[] phaseType = {1, 0, 0, 0, 0, 0}; - protected int[] phaseIndex = {0, 1, 2, 3, 4, 5}; + protected int[] phaseType = { 1, 0, 0, 0, 0, 0 }; + protected int[] phaseIndex = { 0, 1, 2, 3, 4, 5 }; protected ChemicalReactionOperations chemicalReactionOperations = null; private int mixingRule = 1; - protected boolean chemicalSystem = false, solidPhaseCheck = false, multiPhaseCheck = false, - hydrateCheck = false; + protected boolean chemicalSystem = false; + + protected boolean solidPhaseCheck = false; + + protected boolean multiPhaseCheck = false; + + protected boolean hydrateCheck = false; + protected boolean checkStability = true; protected PhaseInterface[] phaseArray; public neqsim.thermo.characterization.Characterise characterization = null; @@ -132,18 +146,18 @@ public SystemThermo(double T, double P) { if (T < 0.0) { String msg = "Negative input temperature"; logger.error(msg); - neqsim.util.exception.InvalidInputException e = - new neqsim.util.exception.InvalidInputException(this.getClass().getSimpleName(), - "SystemThermo", "T", "is negative"); + neqsim.util.exception.InvalidInputException e = new neqsim.util.exception.InvalidInputException( + this.getClass().getSimpleName(), + "SystemThermo", "T", "is negative"); throw new RuntimeException(e); } if (P < 0.0) { String msg = "Negative input pressure"; logger.error(msg); - neqsim.util.exception.InvalidInputException e = - new neqsim.util.exception.InvalidInputException(this.getClass().getSimpleName(), - "SystemThermo", "P", "is negative"); + neqsim.util.exception.InvalidInputException e = new neqsim.util.exception.InvalidInputException( + this.getClass().getSimpleName(), + "SystemThermo", "P", "is negative"); throw new RuntimeException(e); } beta[0] = 1.0; @@ -261,8 +275,10 @@ public SystemInterface addFluid(SystemInterface addSystem) { * addSystem.getPhase(0).getComponent(i).getNumberOfmoles(), * addSystem.getPhase(0).getComponent(i).getMolarMass(), * addSystem.getPhase(0).getComponent(i).getNormalLiquidDensity()); - * changeComponentName(addSystem.getPhase(0).getComponent(i).getComponentName()+ "_PC", - * addSystem.getPhase(0).getComponent(i).getComponentName().replaceFirst("_PC", "")); } + * changeComponentName(addSystem.getPhase(0).getComponent(i).getComponentName()+ + * "_PC", + * addSystem.getPhase(0).getComponent(i).getComponentName().replaceFirst("_PC", + * "")); } * addComponent(addSystem.getPhase(0).getComponent(i).getComponentName(), * addSystem.getPhase(0).getComponent(i).getNumberOfmoles()); */ @@ -281,19 +297,24 @@ public SystemInterface addFluid(SystemInterface addSystem) { @Override public void addPhase() { /* - * if (maxNumberOfPhases < 6 && !hydrateCheck) { ArrayList phaseList = new ArrayList(0); for - * (int i = 0; i < numberOfPhases; i++) { phaseList.add(phaseArray[i]); } // add the new phase - * phaseList.add(phaseArray[0].clone()); beta[phaseList.size() - 1] = 1.0e-8; // beta[1] -= + * if (maxNumberOfPhases < 6 && !hydrateCheck) { ArrayList phaseList = new + * ArrayList(0); for + * (int i = 0; i < numberOfPhases; i++) { phaseList.add(phaseArray[i]); } // add + * the new phase + * phaseList.add(phaseArray[0].clone()); beta[phaseList.size() - 1] = 1.0e-8; // + * beta[1] -= * beta[1]/1.0e5; * * PhaseInterface[] phaseArray2 = new PhaseInterface[numberOfPhases + 1]; * - * for (int i = 0; i < numberOfPhases + 1; i++) { phaseArray2[i] = (PhaseInterface) + * for (int i = 0; i < numberOfPhases + 1; i++) { phaseArray2[i] = + * (PhaseInterface) * phaseList.get(i); } * * phaseArray = phaseArray2; * - * System.out.println("number of phases " + numberOfPhases); if (maxNumberOfPhases < + * System.out.println("number of phases " + numberOfPhases); if + * (maxNumberOfPhases < * numberOfPhases) { maxNumberOfPhases = numberOfPhases; } } */ numberOfPhases++; @@ -525,28 +546,6 @@ public void replacePhase(int repPhase, PhaseInterface newPhase) { setTotalNumberOfMoles(newPhase.getNumberOfMolesInPhase()); } - /** {@inheritDoc} */ - @Override - public SystemInterface phaseToSystem(PhaseInterface newPhase) { - for (int i = 0; i < newPhase.getNumberOfComponents(); i++) { - newPhase.getComponents()[i] - .setNumberOfmoles(newPhase.getComponents()[i].getNumberOfMolesInPhase()); - } - - for (int i = 0; i < getMaxNumberOfPhases(); i++) { - phaseArray[i] = newPhase.clone(); - } - - setTotalNumberOfMoles(newPhase.getNumberOfMolesInPhase()); - this.init(0); - setNumberOfPhases(1); - setPhaseType(0, newPhase.getPhaseType()); - initBeta(); - init_x_y(); - this.init(1); - return this; - } - /** {@inheritDoc} */ @Override public SystemInterface getEmptySystemClone() { @@ -571,6 +570,28 @@ public SystemInterface getEmptySystemClone() { return newSystem; } + /** {@inheritDoc} */ + @Override + public SystemInterface phaseToSystem(PhaseInterface newPhase) { + for (int i = 0; i < newPhase.getNumberOfComponents(); i++) { + newPhase.getComponents()[i] + .setNumberOfmoles(newPhase.getComponents()[i].getNumberOfMolesInPhase()); + } + + for (int i = 0; i < getMaxNumberOfPhases(); i++) { + phaseArray[i] = newPhase.clone(); + } + + setTotalNumberOfMoles(newPhase.getNumberOfMolesInPhase()); + this.init(0); + setNumberOfPhases(1); + setPhaseType(0, newPhase.getPhaseType()); + initBeta(); + init_x_y(); + this.init(1); + return this; + } + /** {@inheritDoc} */ @Override public SystemInterface phaseToSystem(String phaseName) { @@ -605,7 +626,7 @@ public SystemInterface phaseToSystem(int phaseNumber) { newSystem.init(0); newSystem.setNumberOfPhases(1); - newSystem.setPhaseType(0, getPhase(phaseNumber).getPhaseType());// phaseType[phaseNumber]); + newSystem.setPhaseType(0, getPhase(phaseNumber).getPhaseType()); // phaseType[phaseNumber]); newSystem.init(1); return newSystem; } @@ -648,8 +669,7 @@ public void setTotalFlowRate(double flowRate, String flowunit) { initPhysicalProperties("density"); } density = getPhase(0).getDensity("kg/m3"); - neqsim.util.unit.Unit unit = - new neqsim.util.unit.RateUnit(flowRate, flowunit, getMolarMass(), density, 0); + neqsim.util.unit.Unit unit = new neqsim.util.unit.RateUnit(flowRate, flowunit, getMolarMass(), density, 0); double SIval = unit.getSIvalue(); double totalNumberOfMolesLocal = totalNumberOfMoles; for (int i = 0; i < numberOfComponents; i++) { @@ -729,16 +749,17 @@ public void changeComponentName(String name, String newName) { @Override public void addSalt(String componentName, double value) { neqsim.util.database.NeqSimDataBase database = new neqsim.util.database.NeqSimDataBase(); - java.sql.ResultSet dataSet = - database.getResultSet("SELECT * FROM compsalt WHERE SaltName='" + componentName + "'"); - double val1 = 1e-20, val2 = 1e-20; + java.sql.ResultSet dataSet = database.getResultSet("SELECT * FROM compsalt WHERE SaltName='" + componentName + "'"); + double val1 = 1e-20; + double val2 = 1e-20; try { dataSet.next(); String name1 = dataSet.getString("ion1").trim(); - String name2 = dataSet.getString("ion2").trim(); val1 = Double.parseDouble(dataSet.getString("stoc1")) * value; - val2 = Double.parseDouble(dataSet.getString("stoc2")) * value; this.addComponent(name1, val1); + + String name2 = dataSet.getString("ion2").trim(); + val2 = Double.parseDouble(dataSet.getString("stoc2")) * value; this.addComponent(name2, val2); logger.info("ok adding salts. Ions: " + name1 + ", " + name2); } catch (Exception e) { @@ -750,19 +771,28 @@ public void addSalt(String componentName, double value) { @Override public void addTBPfraction(String componentName, double numberOfMoles, double molarMass, double density) { - if (density < 0.0 || molarMass < 0.0) { - String msg = "Negative input molar mass or density."; + if (density < 0.0) { + String msg = "Negative input density."; logger.error(msg); - neqsim.util.exception.InvalidInputException e = - new neqsim.util.exception.InvalidInputException(msg); - throw new RuntimeException(e); + throw new RuntimeException(new neqsim.util.exception.InvalidInputException(this, + "addTBPfraction", "density", "is negative.")); + } + if (molarMass < 0.0) { + String msg = "Negative input molar mass."; + logger.error(msg); + throw new RuntimeException(new neqsim.util.exception.InvalidInputException(this, + "addTBPfraction", "molarMass", "is negative.")); } SystemInterface refSystem = null; - double TC = 0.0, PC = 0.0, m = 0.0, TB = 0.0, acs = 0.0; + double TC = 0.0; + double PC = 0.0; + double m = 0.0; + double TB = 0.0; + double acs = 0.0; // double penelouxC = 0.0; double racketZ = 0.0; - componentName = (componentName.split("_PC")[0]) + "_PC";// + getFluidName()); + componentName = (componentName.split("_PC")[0]) + "_PC"; // + getFluidName()); try { refSystem = this.getClass().getDeclaredConstructor().newInstance(); @@ -827,8 +857,8 @@ public void addTBPfraction(String componentName, double numberOfMoles, double mo logger.error("error", e); } - double critVol = characterization.getTBPModel().calcCriticalVolume(molarMass * 1000, density);// 0.2918-0.0928* - // acs)*8.314*TC/PC*10.0; + double critVol = characterization.getTBPModel().calcCriticalVolume(molarMass * 1000, density); // 0.2918-0.0928* + // acs)*8.314*TC/PC*10.0; addComponent(componentName, numberOfMoles, TC, PC, acs); double Kwatson = Math.pow(TB * 1.8, 1.0 / 3.0) / density; // System.out.println("watson " + Kwatson); @@ -886,15 +916,25 @@ public void addTBPfraction(String componentName, double numberOfMoles, double mo public void addTBPfraction(String componentName, double numberOfMoles, double molarMass, double density, double criticalTemperature, double criticalPressure, double acentricFactor) { if (density < 0.0 || molarMass < 0.0) { - String msg = "Negative input molar mass or density."; + String msg = "Negative input density."; logger.error(msg); - neqsim.util.exception.InvalidInputException e = - new neqsim.util.exception.InvalidInputException(msg); - throw new RuntimeException(e); + throw new RuntimeException(new neqsim.util.exception.InvalidInputException(this, + "addTBPfraction", "density", "is negative.")); + } + + if (density < 0.0 || molarMass < 0.0) { + String msg = "Negative input molar mass."; + logger.error(msg); + throw new RuntimeException(new neqsim.util.exception.InvalidInputException(this, + "addTBPfraction", "molarMass", "is negative.")); } SystemInterface refSystem = null; - double TC = 0.0, PC = 0.0, m = 0.0, TB = 0.0, acs = 0.0; + double TC = 0.0; + double PC = 0.0; + double m = 0.0; + double TB = 0.0; + double acs = 0.0; // double penelouxC = 0.0; double racketZ = 0.0; componentName = (componentName.split("_PC")[0]) + "_PC";// + getFluidName()); @@ -1074,11 +1114,10 @@ public void addComponent(String name) { addComponent(name, 0.0); } - /** {@inheritDoc} */ @Override public void addComponent(String componentName, double moles) { - componentName = ComponentInterface.getComponentName(componentName); + componentName = ComponentInterface.getComponentNameFromAlias(componentName); int index = 0; @@ -1099,9 +1138,8 @@ public void addComponent(String componentName, double moles) { if (moles < 0.0) { String msg = "Negative input number of moles of component: " + componentName; logger.error(msg); - neqsim.util.exception.InvalidInputException e = - new neqsim.util.exception.InvalidInputException(msg); - throw new RuntimeException(e); + throw new RuntimeException( + new neqsim.util.exception.InvalidInputException(this, "addComponent", "moles", msg)); } setTotalNumberOfMoles(getTotalNumberOfMoles() + moles); // System.out.println("adding " + componentName); @@ -1133,16 +1171,17 @@ public void addComponent(String componentName, double moles) { /** {@inheritDoc} */ @Override public void addComponent(String componentName, double value, String unitName) { - componentName = ComponentInterface.getComponentName(componentName); + componentName = ComponentInterface.getComponentNameFromAlias(componentName); if (!neqsim.util.database.NeqSimDataBase.hasComponent(componentName)) { logger.error("No component with name: " + componentName + " in database"); return; } neqsim.util.database.NeqSimDataBase database = new neqsim.util.database.NeqSimDataBase(); - java.sql.ResultSet dataSet = - database.getResultSet(("SELECT * FROM comp WHERE name='" + componentName + "'")); - double molarmass = 0.0, stddens = 0.0, boilp = 0.0; + java.sql.ResultSet dataSet = database.getResultSet(("SELECT * FROM comp WHERE name='" + componentName + "'")); + double molarmass = 0.0; + double stddens = 0.0; + double boilp = 0.0; try { dataSet.next(); molarmass = Double.parseDouble(dataSet.getString("molarmass")) / 1000.0; @@ -1157,8 +1196,7 @@ public void addComponent(String componentName, double value, String unitName) { logger.error("error", e); } } - neqsim.util.unit.Unit unit = - new neqsim.util.unit.RateUnit(value, unitName, molarmass, stddens, boilp); + neqsim.util.unit.Unit unit = new neqsim.util.unit.RateUnit(value, unitName, molarmass, stddens, boilp); double SIval = unit.getSIvalue(); // System.out.println("number of moles " + SIval); this.addComponent(componentName, SIval); @@ -1167,7 +1205,7 @@ public void addComponent(String componentName, double value, String unitName) { /** {@inheritDoc} */ @Override public void addComponent(String componentName, double moles, double TC, double PC, double acs) { - componentName = ComponentInterface.getComponentName(componentName); + componentName = ComponentInterface.getComponentNameFromAlias(componentName); String comNam = componentName; if (getPhase(0).hasComponent(componentName)) { @@ -1192,7 +1230,7 @@ public void addComponent(String componentName, double moles, double TC, double P /** {@inheritDoc} */ @Override public void addComponent(String componentName, double moles, int phaseNumber) { - componentName = ComponentInterface.getComponentName(componentName); + componentName = ComponentInterface.getComponentNameFromAlias(componentName); if (!neqsim.util.database.NeqSimDataBase.hasComponent(componentName)) { logger.error("No component with name: " + componentName + " in database"); @@ -1210,8 +1248,8 @@ public void addComponent(String componentName, double moles, int phaseNumber) { if (moles < 0.0) { String msg = "Negative input number of moles."; logger.error(msg); - neqsim.util.exception.InvalidInputException e = - new neqsim.util.exception.InvalidInputException(msg); + neqsim.util.exception.InvalidInputException e = new neqsim.util.exception.InvalidInputException(this, + "addComponent", "moles", msg); throw new RuntimeException(e); } @@ -1231,20 +1269,20 @@ public void addComponent(String componentName, double moles, int phaseNumber) { numberOfComponents++; } - /** {@inheritDoc} */ @Override public void addComponent(String componentName, double value, String name, int phase) { - componentName = ComponentInterface.getComponentName(componentName); + componentName = ComponentInterface.getComponentNameFromAlias(componentName); if (!neqsim.util.database.NeqSimDataBase.hasComponent(componentName)) { logger.error("No component with name: " + componentName + " in database"); return; } neqsim.util.database.NeqSimDataBase database = new neqsim.util.database.NeqSimDataBase(); - java.sql.ResultSet dataSet = - database.getResultSet(("SELECT * FROM comp WHERE name='" + componentName + "'")); - double molarmass = 0.0, stddens = 0.0, boilp = 0.0; + java.sql.ResultSet dataSet = database.getResultSet(("SELECT * FROM comp WHERE name='" + componentName + "'")); + double molarmass = 0.0; + double stddens = 0.0; + double boilp = 0.0; try { dataSet.next(); molarmass = Double.parseDouble(dataSet.getString("molarmass")) / 1000.0; @@ -1266,8 +1304,7 @@ public void addComponent(String componentName, double value, String name, int ph logger.error("error", e); } } - neqsim.util.unit.Unit unit = - new neqsim.util.unit.RateUnit(value, name, molarmass, stddens, boilp); + neqsim.util.unit.Unit unit = new neqsim.util.unit.RateUnit(value, name, molarmass, stddens, boilp); double SIval = unit.getSIvalue(); // System.out.println("number of moles " + SIval); this.addComponent(componentName, SIval, phase); @@ -1311,7 +1348,7 @@ public void addComponent(int index, double moles, int phaseNumber) { /** {@inheritDoc} */ @Override public void removeComponent(String name) { - name = ComponentInterface.getComponentName(name); + name = ComponentInterface.getComponentNameFromAlias(name); setTotalNumberOfMoles( getTotalNumberOfMoles() - phaseArray[0].getComponent(name).getNumberOfmoles()); @@ -1343,12 +1380,18 @@ public final double calcBeta() throws neqsim.util.exception.IsNaNException, neqsim.util.exception.TooManyIterationsException { ComponentInterface[] compArray = getPhase(0).getComponents(); - int i, iterations = 0; + int i; double tolerance = neqsim.thermo.ThermodynamicModelSettings.phaseFractionMinimumLimit; - double deriv = 0.0, gbeta = 0.0, gtest = 0.0, betal = 0; - double nybeta = 0, midler = 0, minBeta = tolerance, maxBeta = 1.0 - tolerance; - - double g0 = -1.0, g1 = 1.0; + double deriv = 0.0; + double gbeta = 0.0; + double betal = 0; + double nybeta = 0; + + double midler = 0; + double minBeta = tolerance; + double maxBeta = 1.0 - tolerance; + double g0 = -1.0; + double g1 = 1.0; nybeta = beta[0]; betal = 1.0 - nybeta; @@ -1382,7 +1425,7 @@ public final double calcBeta() throws neqsim.util.exception.IsNaNException, betal = 1.0 - nybeta; // ' *l = 1.0-nybeta; - gtest = 0.0; + double gtest = 0.0; for (i = 0; i < numberOfComponents; i++) { gtest += compArray[i].getz() * (compArray[i].getK() - 1.0) / (1.0 - nybeta + nybeta * compArray[i].getK()); // beta @@ -1402,7 +1445,7 @@ public final double calcBeta() throws neqsim.util.exception.IsNaNException, maxBeta = 1.0 - minold; } - iterations = 0; + int iterations = 0; int maxIterations = 300; // System.out.println("gtest: " + gtest); double step = 1.0; @@ -1437,7 +1480,8 @@ public final double calcBeta() throws neqsim.util.exception.IsNaNException, } /* - * if ((nybeta > maxBeta) || (nybeta < minBeta)) { // nybeta = 0.5 * (maxBeta + minBeta); + * if ((nybeta > maxBeta) || (nybeta < minBeta)) { // nybeta = 0.5 * (maxBeta + + * minBeta); * gbeta = 1.0; } */ } else { @@ -1468,7 +1512,8 @@ public final double calcBeta() throws neqsim.util.exception.IsNaNException, } /* - * if ((betal > maxBeta) || (betal < minBeta)) { gbeta = 1.0; { betal = 0.5 * (maxBeta + + * if ((betal > maxBeta) || (betal < minBeta)) { gbeta = 1.0; { betal = 0.5 * + * (maxBeta + * minBeta); } } */ nybeta = 1.0 - betal; @@ -1498,7 +1543,8 @@ public final double calcBeta() throws neqsim.util.exception.IsNaNException, } if (Double.isNaN(beta[1])) { /* - * for (i = 0; i < numberOfComponents; i++) { System.out.println("K " + compArray[i].getK()); + * for (i = 0; i < numberOfComponents; i++) { System.out.println("K " + + * compArray[i].getK()); * System.out.println("z " + compArray[i].getz()); } */ throw new neqsim.util.exception.IsNaNException(this, "calcBeta", "beta"); @@ -1528,6 +1574,8 @@ public double getJouleThomsonCoefficient(String unit) { case "C/bar": conversionFactor = 1.0; break; + default: + break; } return JTcoef * conversionFactor; } @@ -1554,6 +1602,8 @@ public double getSoundSpeed(String unit) { case "km/hr": conversionFactor = 3.6; break; + default: + break; } return refVel * conversionFactor; } @@ -1685,23 +1735,6 @@ public void init(int type) { } } - /** {@inheritDoc} */ - @Override - public void initThermoProperties() { - init(2); - } - - /** {@inheritDoc} */ - @Override - public void initProperties() { - if (!isInitialized) { - init(0); - setNumberOfPhases(1); - } - initThermoProperties(); - initPhysicalProperties(); - } - /** {@inheritDoc} */ @Override public void init(int type, int phase) { @@ -1718,8 +1751,10 @@ public void init(int type, int phase) { * initAnalytic. *

* - * @param type a int. 0 to initialize and 1 to reset, 2 to calculate T and P derivatives, 3 to - * calculate all derivatives and 4 to calculate all derivatives numerically + * @param type a int. 0 to initialize and 1 to reset, 2 to calculate T and P + * derivatives, 3 to + * calculate all derivatives and 4 to calculate all derivatives + * numerically */ public void initAnalytic(int type) { if (type == 0) { @@ -1737,8 +1772,7 @@ public void initAnalytic(int type) { } } numberOfPhases = 2; - } - else if (type == 1) { + } else if (type == 1) { for (int i = 0; i < numberOfPhases; i++) { if (IsPhase(i)) { getPhase(i).init(getTotalNumberOfMoles(), numberOfComponents, 1, phaseType[phaseIndex[i]], @@ -1823,7 +1857,7 @@ else if (type == 1) { * initAnalytic. *

* - * @param type a int + * @param type a int * @param phase a int */ public void initAnalytic(int type, int phase) { @@ -1888,7 +1922,7 @@ public void initNumeric(int type) { * initNumeric. *

* - * @param type a int + * @param type a int * @param phasen a int */ public void initNumeric(int type, int phasen) { @@ -1958,8 +1992,7 @@ public void initNumeric(int type, int phasen) { init(1); for (int i = 0; i < getPhases()[0].getNumberOfComponents(); i++) { - liqfug[0][i] = - Math.log(getPhases()[phase].getComponents()[i].getFugacityCoefficient()); + liqfug[0][i] = Math.log(getPhases()[phase].getComponents()[i].getFugacityCoefficient()); } addComponent(k, -2.0 * dn, phase); @@ -1970,8 +2003,7 @@ public void initNumeric(int type, int phasen) { for (int i = 0; i < getPhases()[0].getNumberOfComponents(); i++) { // gasfug[1][i] = // Math.log(getPhases()[0].getComponents()[i].getFugacityCoefficient()); - liqfug[1][i] = - Math.log(getPhases()[phase].getComponents()[i].getFugacityCoefficient()); + liqfug[1][i] = Math.log(getPhases()[phase].getComponents()[i].getFugacityCoefficient()); } addComponent(k, dn, phase); init_x_y(); @@ -2102,6 +2134,17 @@ public void initNumeric() { } } + /** {@inheritDoc} */ + @Override + public void initProperties() { + if (!isInitialized) { + init(0); + setNumberOfPhases(1); + } + initThermoProperties(); + initPhysicalProperties(); + } + /** {@inheritDoc} */ @Override public void initPhysicalProperties() { @@ -2182,7 +2225,6 @@ public final PhaseInterface getLiquidPhase() { return null; } - /** @{inheritdoc} */ @Override public boolean IsPhase(int i) { @@ -2204,6 +2246,50 @@ public final PhaseInterface getPhase(int i) { return phaseArray[phaseIndex[i]]; } + /** {@inheritDoc} */ + @Override + public PhaseInterface getPhase(String phaseTypeName) { + for (int i = 0; i < numberOfPhases; i++) { + if (getPhase(i).getPhaseTypeName().equals(phaseTypeName)) { + return getPhase(i); + } + } + throw new RuntimeException(); + } + + /** {@inheritDoc} */ + @Override + public int getPhaseNumberOfPhase(String phaseTypeName) { + for (int i = 0; i < numberOfPhases; i++) { + if (getPhase(i).getPhaseTypeName().equals(phaseTypeName)) { + return i; + } + } + return 0; + } + + /** {@inheritDoc} */ + @Override + public int getPhaseIndexOfPhase(String phaseTypeName) { + for (int i = 0; i < numberOfPhases; i++) { + if (getPhase(i).getPhaseTypeName().equals(phaseTypeName)) { + return phaseIndex[i]; + } + } + return phaseIndex[0]; + } + + /** {@inheritDoc} */ + @Override + public PhaseInterface getPhaseOfType(String phaseName) { + for (int i = 0; i < numberOfPhases; i++) { + if (getPhase(i).getPhaseTypeName().equals(phaseName)) { + return getPhase(i); + } + } + return null; + } + /** {@inheritDoc} */ @Override public final boolean isChemicalSystem() { @@ -2252,6 +2338,21 @@ public final void setPC(double PC) { criticalPressure = PC; } + /** + *

+ * setMixingRuleGEmodel. + *

+ * + * @param name a {@link java.lang.String} object + */ + public void setMixingRuleGEmodel(String name) { + for (PhaseInterface tmpPhase : phaseArray) { + if (tmpPhase != null) { + tmpPhase.setMixingRuleGEModel(name); + } + } + } + /** {@inheritDoc} */ @Override public final void setMixingRule(int type) { @@ -2268,20 +2369,6 @@ public final void setMixingRule(int type) { } } - /** - *

- * setMixingRuleGEmodel. - *

- * - * @param name a {@link java.lang.String} object - */ - public void setMixingRuleGEmodel(String name) { - for (PhaseInterface tmpPhase : phaseArray) { - if (tmpPhase != null) - tmpPhase.setMixingRuleGEModel(name); - } - } - /** {@inheritDoc} */ @Override public void setMixingRule(String typename, String GEmodel) { @@ -2383,6 +2470,8 @@ public double getExergy(double temperatureOfSurroundings, String exergyUnit) { case "kJ/kg": conversionFactor = 1.0 / getTotalNumberOfMoles() / getMolarMass() / 1000.0; break; + default: + break; } return refExergy * conversionFactor; } @@ -2422,6 +2511,8 @@ public double getEnthalpy(String unit) { case "kJ/kg": conversionFactor = 1.0 / getTotalNumberOfMoles() / getMolarMass() / 1000.0; break; + default: + break; } return refEnthalpy * conversionFactor; } @@ -2561,6 +2652,8 @@ public double getInternalEnergy(String unit) { case "kJ/kg": conversionFactor = 1.0 / getTotalNumberOfMoles() / getMolarMass() / 1000.0; break; + default: + break; } return refEnthalpy * conversionFactor; } @@ -2603,6 +2696,8 @@ public double getEntropy(String unit) { case "kJ/kgK": conversionFactor = 1.0 / getTotalNumberOfMoles() / getMolarMass() / 1000.0; break; + default: + break; } return refEntropy * conversionFactor; } @@ -2622,8 +2717,7 @@ public double getMolarVolume() { public double getDensity() { double density = 0; for (int i = 0; i < numberOfPhases; i++) { - density += - 1.0e5 * (getPhase(i).getMolarMass() * beta[phaseIndex[i]] / getPhase(i).getMolarVolume()); + density += 1.0e5 * (getPhase(i).getMolarMass() * beta[phaseIndex[i]] / getPhase(i).getMolarVolume()); } return density; } @@ -2633,8 +2727,7 @@ public double getDensity() { public double getDensity(String unit) { double density = 0; for (int i = 0; i < getNumberOfPhases(); i++) { - density += - getPhase(i).getVolume() / getVolume() * getPhase(i).getPhysicalProperties().getDensity(); + density += getPhase(i).getVolume() / getVolume() * getPhase(i).getPhysicalProperties().getDensity(); } double refDensity = density; // density in kg/m3 double conversionFactor = 1.0; @@ -2679,8 +2772,7 @@ public double getMoleFractionsSum() { public double getMolarMass() { double tempVar = 0; for (int i = 0; i < phaseArray[0].getNumberOfComponents(); i++) { - tempVar += - phaseArray[0].getComponents()[i].getz() * phaseArray[0].getComponents()[i].getMolarMass(); + tempVar += phaseArray[0].getComponents()[i].getz() * phaseArray[0].getComponents()[i].getMolarMass(); } return tempVar; } @@ -2711,6 +2803,12 @@ public void setTemperature(double newTemperature) { } } + /** {@inheritDoc} */ + @Override + public final void setTemperature(double newTemperature, int phase) { + getPhase(phaseIndex[phase]).setTemperature(newTemperature); + } + /** {@inheritDoc} */ @Override public void setTemperature(double newTemperature, String unit) { @@ -2833,12 +2931,6 @@ public final void setPressure(double newPressure, String unit) { } } - /** {@inheritDoc} */ - @Override - public final void setTemperature(double newPressure, int phase) { - getPhase(phaseIndex[phase]).setTemperature(newPressure); - } - /** {@inheritDoc} */ @Override public final double getTemperature() { @@ -2908,10 +3000,12 @@ public final int getNumberOfPhases() { /** {@inheritDoc} */ @Override public final void setBeta(double b) { - if (b < 0) + if (b < 0) { b = neqsim.thermo.ThermodynamicModelSettings.phaseFractionMinimumLimit; - if (b > 1) + } + if (b > 1) { b = 1.0 - neqsim.thermo.ThermodynamicModelSettings.phaseFractionMinimumLimit; + } beta[0] = b; beta[1] = 1.0 - b; } @@ -2919,10 +3013,12 @@ public final void setBeta(double b) { /** {@inheritDoc} */ @Override public final void setBeta(int phase, double b) { - if (b < 0) + if (b < 0) { b = neqsim.thermo.ThermodynamicModelSettings.phaseFractionMinimumLimit; - if (b > 1) + } + if (b > 1) { b = 1.0 - neqsim.thermo.ThermodynamicModelSettings.phaseFractionMinimumLimit; + } beta[phaseIndex[phase]] = b; } @@ -2953,6 +3049,8 @@ public double getVolume(String unit) { case "m3/mol": conversionFactor = 1.0 / getTotalNumberOfMoles(); break; + default: + break; } return conversionFactor * getVolume() / 1.0e5; } @@ -2972,6 +3070,8 @@ public double getMass(String unit) { case "tons": conversionFactor = 1.0e-3; break; + default: + break; } return conversionFactor * getTotalNumberOfMoles() * getMolarMass(); } @@ -3026,7 +3126,6 @@ public double getdVdTpn() { return dVdT; } - /** {@inheritDoc} */ @Override public double getCp() { @@ -3055,6 +3154,8 @@ public double getCp(String unit) { case "kJ/kgK": conversionFactor = 1.0 / getTotalNumberOfMoles() / getMolarMass() / 1000.0; break; + default: + break; } return refCp * conversionFactor; } @@ -3087,6 +3188,8 @@ public double getCv(String unit) { case "kJ/kgK": conversionFactor = 1.0 / getTotalNumberOfMoles() / getMolarMass() / 1000.0; break; + default: + break; } return refCv * conversionFactor; } @@ -3094,9 +3197,10 @@ public double getCv(String unit) { /** * {@inheritDoc} * - * @Override + * @return kappa real gas kappa * - * method to return real gas isentropic exponent (kappa = - Cp/Cv*(v/p)*dp/dv + * method to return real gas isentropic exponent (kappa = - + * Cp/Cv*(v/p)*dp/dv */ public double getKappa() { return -getCp() / getCv() * getVolume() / getPressure() * getdPdVtn(); @@ -3108,13 +3212,6 @@ public double getGamma() { return getCp() / getCv(); } - /** {@inheritDoc} */ - @Override - public double getGamma2() { - double cp0 = getCp(); - return cp0 / (cp0 - ThermodynamicConstantsInterface.R * totalNumberOfMoles); - } - /** {@inheritDoc} */ @Override public void calcInterfaceProperties() { @@ -3150,18 +3247,6 @@ public double getInterfacialTension(String phase1, String phase2) { } } - /** - *

- * write. - *

- * - * @return a {@link java.lang.String} object - */ - public String write() { - // create a String description of the system - return ""; - } - /** {@inheritDoc} */ @Override public void normalizeBeta() { @@ -3174,12 +3259,6 @@ public void normalizeBeta() { } } - /** {@inheritDoc} */ - @Override - public void display() { - display(this.getFluidName()); - } - /** {@inheritDoc} */ @Override public String[][] createTable(String name) { @@ -3227,49 +3306,45 @@ public String[][] createTable(String name) { table[j + 1][1] = nf.format(getPhase(0).getComponents()[j].getz(), buf, test).toString(); } buf = new StringBuffer(); - table[getPhases()[0].getNumberOfComponents() + 4][1] = - nf.format(getMolarMass() * 1000, buf, test).toString(); + table[getPhases()[0].getNumberOfComponents() + 4][1] = nf.format(getMolarMass() * 1000, buf, test).toString(); buf = new StringBuffer(); - table[getPhases()[0].getNumberOfComponents() + 9][1] = - nf.format(getEnthalpy() / (getTotalNumberOfMoles() * getMolarMass() * 1000), buf, test) - .toString(); + table[getPhases()[0].getNumberOfComponents() + 9][1] = nf + .format(getEnthalpy() / (getTotalNumberOfMoles() * getMolarMass() * 1000), buf, test) + .toString(); buf = new StringBuffer(); - table[getPhases()[0].getNumberOfComponents() + 10][1] = - nf.format(getEntropy() / (getTotalNumberOfMoles() * getMolarMass() * 1000), buf, test) - .toString(); + table[getPhases()[0].getNumberOfComponents() + 10][1] = nf + .format(getEntropy() / (getTotalNumberOfMoles() * getMolarMass() * 1000), buf, test) + .toString(); for (int i = 0; i < numberOfPhases; i++) { for (int j = 0; j < getPhases()[0].getNumberOfComponents(); j++) { table[j + 1][0] = getPhases()[0].getComponents()[j].getName(); buf = new StringBuffer(); - table[j + 1][i + 2] = - nf.format(getPhase(i).getComponents()[j].getx(), buf, test).toString(); + table[j + 1][i + 2] = nf.format(getPhase(i).getComponents()[j].getx(), buf, test).toString(); table[j + 1][6] = "[mole fraction]"; } buf = new StringBuffer(); table[getPhases()[0].getNumberOfComponents() + 2][0] = "Density"; - table[getPhases()[0].getNumberOfComponents() + 2][i + 2] = - nf.format(getPhase(i).getPhysicalProperties().getDensity(), buf, test).toString(); + table[getPhases()[0].getNumberOfComponents() + 2][i + 2] = nf + .format(getPhase(i).getPhysicalProperties().getDensity(), buf, test).toString(); table[getPhases()[0].getNumberOfComponents() + 2][6] = "[kg/m^3]"; // Double.longValue(system.getPhase(i).getBeta()); buf = new StringBuffer(); table[getPhases()[0].getNumberOfComponents() + 3][0] = "PhaseFraction"; - table[getPhases()[0].getNumberOfComponents() + 3][i + 2] = - nf.format(getPhase(i).getBeta(), buf, test).toString(); + table[getPhases()[0].getNumberOfComponents() + 3][i + 2] = nf.format(getPhase(i).getBeta(), buf, test).toString(); table[getPhases()[0].getNumberOfComponents() + 3][6] = "[mole fraction]"; buf = new StringBuffer(); table[getPhases()[0].getNumberOfComponents() + 4][0] = "MolarMass"; - table[getPhases()[0].getNumberOfComponents() + 4][i + 2] = - nf.format(getPhase(i).getMolarMass() * 1000, buf, test).toString(); + table[getPhases()[0].getNumberOfComponents() + 4][i + 2] = nf.format(getPhase(i).getMolarMass() * 1000, buf, test) + .toString(); table[getPhases()[0].getNumberOfComponents() + 4][6] = "[kg/kmol]"; buf = new StringBuffer(); table[getPhases()[0].getNumberOfComponents() + 5][0] = "Z factor"; - table[getPhases()[0].getNumberOfComponents() + 5][i + 2] = - nf.format(getPhase(i).getZ(), buf, test).toString(); + table[getPhases()[0].getNumberOfComponents() + 5][i + 2] = nf.format(getPhase(i).getZ(), buf, test).toString(); table[getPhases()[0].getNumberOfComponents() + 5][6] = "[-]"; buf = new StringBuffer(); @@ -3290,8 +3365,8 @@ public String[][] createTable(String name) { buf = new StringBuffer(); table[getPhases()[0].getNumberOfComponents() + 8][0] = "Speed of Sound"; - table[getPhases()[0].getNumberOfComponents() + 8][i + 2] = - nf.format((getPhase(i).getSoundSpeed()), buf, test).toString(); + table[getPhases()[0].getNumberOfComponents() + 8][i + 2] = nf.format((getPhase(i).getSoundSpeed()), buf, test) + .toString(); table[getPhases()[0].getNumberOfComponents() + 8][6] = "[m/sec]"; buf = new StringBuffer(); @@ -3312,47 +3387,47 @@ public String[][] createTable(String name) { buf = new StringBuffer(); table[getPhases()[0].getNumberOfComponents() + 11][0] = "JT coefficient"; - table[getPhases()[0].getNumberOfComponents() + 11][i + 2] = - nf.format((getPhase(i).getJouleThomsonCoefficient()), buf, test).toString(); + table[getPhases()[0].getNumberOfComponents() + 11][i + 2] = nf + .format((getPhase(i).getJouleThomsonCoefficient()), buf, test).toString(); table[getPhases()[0].getNumberOfComponents() + 11][6] = "[K/bar]"; buf = new StringBuffer(); table[getPhases()[0].getNumberOfComponents() + 13][0] = "Viscosity"; - table[getPhases()[0].getNumberOfComponents() + 13][i + 2] = - nf.format((getPhase(i).getPhysicalProperties().getViscosity()), buf, test).toString(); + table[getPhases()[0].getNumberOfComponents() + 13][i + 2] = nf + .format((getPhase(i).getPhysicalProperties().getViscosity()), buf, test).toString(); table[getPhases()[0].getNumberOfComponents() + 13][6] = "[kg/m*sec]"; buf = new StringBuffer(); table[getPhases()[0].getNumberOfComponents() + 14][0] = "Conductivity"; - table[getPhases()[0].getNumberOfComponents() + 14][i + 2] = - nf.format(getPhase(i).getPhysicalProperties().getConductivity(), buf, test).toString(); + table[getPhases()[0].getNumberOfComponents() + 14][i + 2] = nf + .format(getPhase(i).getPhysicalProperties().getConductivity(), buf, test).toString(); table[getPhases()[0].getNumberOfComponents() + 14][6] = "[W/m*K]"; buf = new StringBuffer(); table[getPhases()[0].getNumberOfComponents() + 15][0] = "SurfaceTension"; try { if (i < numberOfPhases - 1) { - table[getPhases()[0].getNumberOfComponents() + 15][2] = - nf.format(getInterphaseProperties().getSurfaceTension(0, 1), buf, test).toString(); + table[getPhases()[0].getNumberOfComponents() + 15][2] = nf + .format(getInterphaseProperties().getSurfaceTension(0, 1), buf, test).toString(); buf = new StringBuffer(); - table[getPhases()[0].getNumberOfComponents() + 15][3] = - nf.format(getInterphaseProperties().getSurfaceTension(0, 1), buf, test).toString(); + table[getPhases()[0].getNumberOfComponents() + 15][3] = nf + .format(getInterphaseProperties().getSurfaceTension(0, 1), buf, test).toString(); buf = new StringBuffer(); if (i == 1) { - table[getPhases()[0].getNumberOfComponents() + 17][2] = - nf.format(getInterphaseProperties().getSurfaceTension(0, 2), buf, test).toString(); + table[getPhases()[0].getNumberOfComponents() + 17][2] = nf + .format(getInterphaseProperties().getSurfaceTension(0, 2), buf, test).toString(); buf = new StringBuffer(); - table[getPhases()[0].getNumberOfComponents() + 17][4] = - nf.format(getInterphaseProperties().getSurfaceTension(0, 2), buf, test).toString(); + table[getPhases()[0].getNumberOfComponents() + 17][4] = nf + .format(getInterphaseProperties().getSurfaceTension(0, 2), buf, test).toString(); table[getPhases()[0].getNumberOfComponents() + 17][6] = "[N/m]"; } if (i == 1) { buf = new StringBuffer(); - table[getPhases()[0].getNumberOfComponents() + 16][3] = - nf.format(getInterphaseProperties().getSurfaceTension(1, 2), buf, test).toString(); + table[getPhases()[0].getNumberOfComponents() + 16][3] = nf + .format(getInterphaseProperties().getSurfaceTension(1, 2), buf, test).toString(); buf = new StringBuffer(); - table[getPhases()[0].getNumberOfComponents() + 16][4] = - nf.format(getInterphaseProperties().getSurfaceTension(1, 2), buf, test).toString(); + table[getPhases()[0].getNumberOfComponents() + 16][4] = nf + .format(getInterphaseProperties().getSurfaceTension(1, 2), buf, test).toString(); table[getPhases()[0].getNumberOfComponents() + 16][6] = "[N/m]"; } } @@ -3363,14 +3438,12 @@ public String[][] createTable(String name) { buf = new StringBuffer(); table[getPhases()[0].getNumberOfComponents() + 19][0] = "Pressure"; - table[getPhases()[0].getNumberOfComponents() + 19][i + 2] = - Double.toString(getPhase(i).getPressure()); + table[getPhases()[0].getNumberOfComponents() + 19][i + 2] = Double.toString(getPhase(i).getPressure()); table[getPhases()[0].getNumberOfComponents() + 19][6] = "[bar]"; buf = new StringBuffer(); table[getPhases()[0].getNumberOfComponents() + 20][0] = "Temperature"; - table[getPhases()[0].getNumberOfComponents() + 20][i + 2] = - Double.toString(getPhase(i).getTemperature()); + table[getPhases()[0].getNumberOfComponents() + 20][i + 2] = Double.toString(getPhase(i).getTemperature()); table[getPhases()[0].getNumberOfComponents() + 20][6] = "[K]"; Double.toString(getPhase(i).getTemperature()); @@ -3382,8 +3455,8 @@ public String[][] createTable(String name) { buf = new StringBuffer(); table[getPhases()[0].getNumberOfComponents() + 23][0] = "Mixing Rule"; try { - table[getPhases()[0].getNumberOfComponents() + 23][i + 2] = - ((PhaseEosInterface) getPhase(i)).getMixingRuleName(); + table[getPhases()[0].getNumberOfComponents() + 23][i + 2] = ((PhaseEosInterface) getPhase(i)) + .getMixingRuleName(); } catch (Exception e) { table[getPhases()[0].getNumberOfComponents() + 23][i + 2] = "?"; // logger.error("error",e); @@ -3400,6 +3473,12 @@ public String[][] createTable(String name) { return table; } + /** {@inheritDoc} */ + @Override + public void display() { + display(this.getFluidName()); + } + /** {@inheritDoc} */ @Override public void display(String name) { @@ -3408,7 +3487,7 @@ public void display(String name) { Container dialogContentPane = dialog.getContentPane(); dialogContentPane.setLayout(new BorderLayout()); - String[] names = {"", "Feed", "Phase 1", "Phase 2", "Phase 3", "Phase 4", "Unit"}; + String[] names = { "", "Feed", "Phase 1", "Phase 2", "Phase 3", "Phase 4", "Unit" }; String[][] table = createTable(name); JTable Jtab = new JTable(table, names); JScrollPane scrollpane = new JScrollPane(Jtab); @@ -3424,12 +3503,23 @@ public void display(String name) { dialog.setVisible(true); } + /** + *

+ * write. + *

+ * + * @return a {@link java.lang.String} object + */ + public String write() { + // create a String description of the system + return ""; + } + /** {@inheritDoc} */ @Override public void write(String name, String filename, boolean newfile) { String[][] table = createTable(name); - neqsim.dataPresentation.fileHandeling.createTextFile.TextFile file = - new neqsim.dataPresentation.fileHandeling.createTextFile.TextFile(); + neqsim.dataPresentation.fileHandeling.createTextFile.TextFile file = new neqsim.dataPresentation.fileHandeling.createTextFile.TextFile(); if (newfile) { file.newFile(filename); } @@ -3667,8 +3757,7 @@ public void save(String name) { public SystemInterface readObject(int ID) { ResultSet rs = null; SystemThermo tempSystem = null; - neqsim.util.database.NeqSimBlobDatabase database = - new neqsim.util.database.NeqSimBlobDatabase(); + neqsim.util.database.NeqSimBlobDatabase database = new neqsim.util.database.NeqSimBlobDatabase(); try { java.sql.Connection con = database.openConnection(); String sqlStr = "SELECT FLUID FROM fluid_blobdb WHERE ID=" + Integer.toString(ID); @@ -3676,8 +3765,7 @@ public SystemInterface readObject(int ID) { rs = ps.executeQuery(); if (rs.next()) { - try (ObjectInputStream ins = - new ObjectInputStream(new ByteArrayInputStream(rs.getBytes("FLUID")))) { + try (ObjectInputStream ins = new ObjectInputStream(new ByteArrayInputStream(rs.getBytes("FLUID")))) { tempSystem = (SystemThermo) ins.readObject(); } } @@ -3724,21 +3812,20 @@ public void saveObject(int ID, String text) { byte[] byteObject = fout.toByteArray(); ByteArrayInputStream inpStream = new ByteArrayInputStream(byteObject); - neqsim.util.database.NeqSimBlobDatabase database = - new neqsim.util.database.NeqSimBlobDatabase(); + neqsim.util.database.NeqSimBlobDatabase database = new neqsim.util.database.NeqSimBlobDatabase(); try { java.sql.Connection con = database.openConnection(); - java.sql.PreparedStatement ps = - con.prepareStatement("REPLACE INTO fluid_blobdb (ID, FLUID) VALUES (?,?)"); + java.sql.PreparedStatement ps = con.prepareStatement("REPLACE INTO fluid_blobdb (ID, FLUID) VALUES (?,?)"); ps.setInt(1, ID); ps.setBlob(2, inpStream); ps.executeUpdate(); /* * if (!text.isEmpty()) { ps = con.prepareStatement( - * "REPLACE INTO fluidinfo (ID, TEXT) VALUES (?,?)"); ps.setInt(1, ID); ps.setString(2, text); + * "REPLACE INTO fluidinfo (ID, TEXT) VALUES (?,?)"); ps.setInt(1, ID); + * ps.setString(2, text); * } * * ps.executeUpdate(); @@ -3775,8 +3862,7 @@ public void saveObjectToFile(String filePath, String fluidName) { @Override public SystemInterface readObjectFromFile(String filePath, String fluidName) { SystemThermo tempSystem = null; - try (ObjectInputStream objectinputstream = - new ObjectInputStream(new FileInputStream(filePath))) { + try (ObjectInputStream objectinputstream = new ObjectInputStream(new FileInputStream(filePath))) { tempSystem = (SystemThermo) objectinputstream.readObject(); } catch (Exception e) { logger.error(e.toString()); @@ -3813,18 +3899,19 @@ public java.lang.String getFluidName() { public void setFluidName(java.lang.String fluidName) { this.fluidName = fluidName; } - + public void addToComponentNames(java.lang.String name) { - for(int j=0;j * setLastTBPasPlus. @@ -3833,8 +3920,7 @@ public void addToComponentNames(java.lang.String name) { * @return a boolean */ public boolean setLastTBPasPlus() { - neqsim.thermo.characterization.PlusCharacterize temp = - new neqsim.thermo.characterization.PlusCharacterize(this); + neqsim.thermo.characterization.PlusCharacterize temp = new neqsim.thermo.characterization.PlusCharacterize(this); if (temp.hasPlusFraction()) { return false; } else { @@ -3959,9 +4045,8 @@ public void saveToDataBase() { database.execute("delete FROM systemreport"); int i = 0; for (; i < numberOfComponents; i++) { - String sqlString = - "'" + Integer.toString(i + 1) + "', '" + getPhase(0).getComponent(i).getName() + "', " - + "'molfrac[-] ', '" + Double.toString(getPhase(0).getComponent(i).getz()) + "'"; + String sqlString = "'" + Integer.toString(i + 1) + "', '" + getPhase(0).getComponent(i).getName() + "', " + + "'molfrac[-] ', '" + Double.toString(getPhase(0).getComponent(i).getz()) + "'"; int j = 0; for (; j < numberOfPhases; j++) { @@ -4051,51 +4136,6 @@ public neqsim.standards.StandardInterface getStandard(String standardName) { return standard; } - /** {@inheritDoc} */ - @Override - public neqsim.dataPresentation.iTextPDF.PdfCreator generatePDF() { - neqsim.dataPresentation.iTextPDF.PdfCreator pdfDocument = null; - pdfDocument = new neqsim.dataPresentation.iTextPDF.PdfCreator(); - pdfDocument.getDocument().addTitle("NeqSim Thermo Simulation Report"); - pdfDocument.getDocument().addKeywords("Temperature "); - - pdfDocument.getDocument().open(); - try { - pdfDocument.getDocument() - .add(new com.lowagie.text.Paragraph("Properties of fluid: " + getFluidName(), - com.lowagie.text.FontFactory.getFont(com.lowagie.text.FontFactory.TIMES_ROMAN, 12))); - - com.lowagie.text.List list = new com.lowagie.text.List(true, 20); - list.add(new com.lowagie.text.ListItem("Thermodynamic model: " + getModelName())); - list.add(new com.lowagie.text.ListItem("Mixing rule: " + getMixingRuleName())); - list.add(new com.lowagie.text.ListItem("Number of phases: " + getNumberOfPhases())); - list.add(new com.lowagie.text.ListItem("Status of calculation: ok")); - pdfDocument.getDocument().add(list); - - com.lowagie.text.Table resTable = - new com.lowagie.text.Table(6, getPhases()[0].getNumberOfComponents() + 30); - String[][] tempTable = createTable(getFluidName()); - for (int i = 0; i < getPhases()[0].getNumberOfComponents() + 30; i++) { - for (int j = 0; j < 6; j++) { - resTable.addCell(tempTable[i][j]); - } - } - pdfDocument.getDocument().add(resTable); - - com.lowagie.text.Anchor anchor = new com.lowagie.text.Anchor("NeqSim Website", - com.lowagie.text.FontFactory.getFont(com.lowagie.text.FontFactory.HELVETICA, 12, - com.lowagie.text.Font.UNDERLINE, new Color(0, 0, 255))); - anchor.setReference("http://www.stud.ntnu.no/~solbraa/neqsim"); - anchor.setName("NeqSim Website"); - - pdfDocument.getDocument().add(anchor); - } catch (Exception e) { - logger.error("error", e); - } - pdfDocument.getDocument().close(); - return pdfDocument; - } - /** * {@inheritDoc} * @@ -4175,8 +4215,7 @@ public double getHeatOfVaporization() { public void readFluid(String fluidName) { this.fluidName = fluidName; try { - neqsim.util.database.NeqSimFluidDataBase database = - new neqsim.util.database.NeqSimFluidDataBase(); + neqsim.util.database.NeqSimFluidDataBase database = new neqsim.util.database.NeqSimFluidDataBase(); java.sql.ResultSet dataSet = null; dataSet = database.getResultSet("SELECT * FROM " + fluidName); @@ -4240,15 +4279,13 @@ public SystemInterface setModel(String model) { tempModel = new SystemSrkSchwartzentruberEos(getPhase(0).getTemperature(), getPhase(0).getPressure()); } else if (model.equals("Electrolyte-ScRK-EOS")) { - tempModel = - new SystemFurstElectrolyteEos(getPhase(0).getTemperature(), getPhase(0).getPressure()); + tempModel = new SystemFurstElectrolyteEos(getPhase(0).getTemperature(), getPhase(0).getPressure()); } else if (model.equals("GERG-water-EOS")) { tempModel = new SystemGERGwaterEos(getPhase(0).getTemperature(), getPhase(0).getPressure()); } else if (model.equals("CPAs-SRK-EOS")) { tempModel = new SystemSrkCPAs(getPhase(0).getTemperature(), getPhase(0).getPressure()); } else if (model.equals("CPAs-SRK-EOS-statoil")) { - tempModel = - new SystemSrkCPAstatoil(getPhase(0).getTemperature(), getPhase(0).getPressure()); + tempModel = new SystemSrkCPAstatoil(getPhase(0).getTemperature(), getPhase(0).getPressure()); } else if (model.equals("Electrolyte-CPA-EOS-statoil") || model.equals("Electrolyte-CPA-EOS")) { tempModel = new SystemElectrolyteCPAstatoil(getPhase(0).getTemperature(), @@ -4260,11 +4297,9 @@ public SystemInterface setModel(String model) { } else if (model.equals("GERG-2008-EoS")) { tempModel = new SystemGERG2004Eos(getPhase(0).getTemperature(), getPhase(0).getPressure()); } else if (model.equals("SRK-TwuCoon-Statoil-EOS") || model.equals("SRK-TwuCoon-EOS")) { - tempModel = - new SystemSrkTwuCoonStatoilEos(getPhase(0).getTemperature(), getPhase(0).getPressure()); + tempModel = new SystemSrkTwuCoonStatoilEos(getPhase(0).getTemperature(), getPhase(0).getPressure()); } else if (model.equals("SRK-TwuCoon-Param-EOS")) { - tempModel = - new SystemSrkTwuCoonParamEos(getPhase(0).getTemperature(), getPhase(0).getPressure()); + tempModel = new SystemSrkTwuCoonParamEos(getPhase(0).getTemperature(), getPhase(0).getPressure()); } else if (model.equals("Duan-Sun")) { tempModel = new SystemDuanSun(getPhase(0).getTemperature(), getPhase(0).getPressure()); } else { @@ -4574,50 +4609,6 @@ public boolean hasPhaseType(String phaseTypeName) { return false; } - /** {@inheritDoc} */ - @Override - public PhaseInterface getPhase(String phaseTypeName) { - for (int i = 0; i < numberOfPhases; i++) { - if (getPhase(i).getPhaseTypeName().equals(phaseTypeName)) { - return getPhase(i); - } - } - throw new RuntimeException(); - } - - /** {@inheritDoc} */ - @Override - public int getPhaseNumberOfPhase(String phaseTypeName) { - for (int i = 0; i < numberOfPhases; i++) { - if (getPhase(i).getPhaseTypeName().equals(phaseTypeName)) { - return i; - } - } - return 0; - } - - /** {@inheritDoc} */ - @Override - public int getPhaseIndexOfPhase(String phaseTypeName) { - for (int i = 0; i < numberOfPhases; i++) { - if (getPhase(i).getPhaseTypeName().equals(phaseTypeName)) { - return phaseIndex[i]; - } - } - return phaseIndex[0]; - } - - /** {@inheritDoc} */ - @Override - public PhaseInterface getPhaseOfType(String phaseName) { - for (int i = 0; i < numberOfPhases; i++) { - if (getPhase(i).getPhaseTypeName().equals(phaseName)) { - return getPhase(i); - } - } - return null; - } - /** {@inheritDoc} */ @Override public double calcHenrysConstant(String component) { @@ -4664,21 +4655,21 @@ public void setBmixType(int bmixType) { /** {@inheritDoc} */ @Override - public boolean isImplementedTemperatureDeriativesofFugacity() { - return implementedTemperatureDeriativesofFugacity; + public boolean isImplementedCompositionDeriativesofFugacity() { + return implementedCompositionDeriativesofFugacity; } /** {@inheritDoc} */ @Override - public void setImplementedTemperatureDeriativesofFugacity( - boolean implementedTemperatureDeriativesofFugacity) { - this.implementedTemperatureDeriativesofFugacity = implementedTemperatureDeriativesofFugacity; + public void isImplementedCompositionDeriativesofFugacity(boolean isImpl) { + this.implementedCompositionDeriativesofFugacity = isImpl; } /** {@inheritDoc} */ @Override - public boolean isImplementedPressureDeriativesofFugacity() { - return implementedPressureDeriativesofFugacity; + public void setImplementedCompositionDeriativesofFugacity( + boolean implementedCompositionDeriativesofFugacity) { + this.implementedCompositionDeriativesofFugacity = implementedCompositionDeriativesofFugacity; } /** {@inheritDoc} */ @@ -4690,15 +4681,21 @@ public void setImplementedPressureDeriativesofFugacity( /** {@inheritDoc} */ @Override - public boolean isImplementedCompositionDeriativesofFugacity() { - return implementedCompositionDeriativesofFugacity; + public boolean isImplementedPressureDeriativesofFugacity() { + return implementedPressureDeriativesofFugacity; } /** {@inheritDoc} */ @Override - public void setImplementedCompositionDeriativesofFugacity( - boolean implementedCompositionDeriativesofFugacity) { - this.implementedCompositionDeriativesofFugacity = implementedCompositionDeriativesofFugacity; + public boolean isImplementedTemperatureDeriativesofFugacity() { + return implementedTemperatureDeriativesofFugacity; + } + + /** {@inheritDoc} */ + @Override + public void setImplementedTemperatureDeriativesofFugacity( + boolean implementedTemperatureDeriativesofFugacity) { + this.implementedTemperatureDeriativesofFugacity = implementedTemperatureDeriativesofFugacity; } /** {@inheritDoc} */ @@ -4725,19 +4722,19 @@ public void setMaxNumberOfPhases(int maxNumberOfPhases) { /** {@inheritDoc} */ @Override public void setMolarComposition(double[] molefractions) { - setMolarComposition(molefractions, ""); + setMolarFractions(molefractions, ""); } /** {@inheritDoc} */ @Override public void setMolarCompositionPlus(double[] molefractions) { - setMolarComposition(molefractions, "Plus"); + setMolarFractions(molefractions, "Plus"); } /** {@inheritDoc} */ @Override public void setMolarCompositionOfPlusFluid(double[] molefractions) { - setMolarComposition(molefractions, "PlusFluid"); + setMolarFractions(molefractions, "PlusFluid"); } /** {@inheritDoc} */ @@ -5006,12 +5003,6 @@ public double getMoleFraction(int phaseNumber) { return getPhase(phaseNumber).getBeta(); } - /** {@inheritDoc} */ - @Override - public void isImplementedCompositionDeriativesofFugacity(boolean isImpl) { - implementedCompositionDeriativesofFugacity = isImpl; - } - /** {@inheritDoc} */ @Override public void addCapeOpenProperty(String propertyName) { @@ -5074,20 +5065,18 @@ public void setForcePhaseTypes(boolean forcePhaseTypes) { this.forcePhaseTypes = forcePhaseTypes; } - /** @{inheritDoc} */ @Override public SystemProperties getProperties() { return new SystemProperties(this); } - private void setMolarComposition(double[] molefractions, String type) { + private void setMolarFractions(double[] molefractions, String type) { double totalFlow = getTotalNumberOfMoles(); if (totalFlow < 1e-100) { - String msg = "Total flow can not be 0 when setting molar composition"; + String msg = "must be larger than 0 (1e-100) when setting molar composition"; logger.error(msg); - neqsim.util.exception.InvalidInputException e = - new neqsim.util.exception.InvalidInputException(msg); - throw new RuntimeException(e); + throw new RuntimeException(new neqsim.util.exception.InvalidInputException(this, + "setMolarComposition", "totalFlow", msg)); } double sum = 0; for (double value : molefractions) { diff --git a/src/main/java/neqsim/thermo/system/SystemUMRCPAEoS.java b/src/main/java/neqsim/thermo/system/SystemUMRCPAEoS.java new file mode 100644 index 0000000000..f61f10ab41 --- /dev/null +++ b/src/main/java/neqsim/thermo/system/SystemUMRCPAEoS.java @@ -0,0 +1,48 @@ +/* + * System_SRK_EOS.java + * + * Created on 8. april 2000, 23:05 + */ + +package neqsim.thermo.system; +/** + * This class defines a thermodynamic system using the UMR CPA equation of state + * + * @author Even Solbraa + * @version + */ + +import neqsim.thermo.phase.PhaseUMRCPA; + +/** + * This class defines a thermodynamic system using the UMR-PRU with MC paramters equation of state + */ +public class SystemUMRCPAEoS extends SystemPrEos { + + public SystemUMRCPAEoS() { + super(); + modelName = "UMR-CPA"; + attractiveTermNumber = 19; + useVolumeCorrection(false); + for (int i = 0; i < numberOfPhases; i++) { + phaseArray[i] = new PhaseUMRCPA(); + phaseArray[i].setTemperature(298.15); + phaseArray[i].setPressure(1.0); + phaseArray[i].useVolumeCorrection(false); + } + } + + public SystemUMRCPAEoS(double T, double P) { + super(T, P); + modelName = "UMR-CPA"; + attractiveTermNumber = 19; + useVolumeCorrection(false); + for (int i = 0; i < numberOfPhases; i++) { + phaseArray[i] = new PhaseUMRCPA(); + phaseArray[i].setTemperature(T); + phaseArray[i].setPressure(P); + phaseArray[i].useVolumeCorrection(false); + } + } + +} diff --git a/src/main/java/neqsim/thermo/system/SystemUMRPRUMCEosNew.java b/src/main/java/neqsim/thermo/system/SystemUMRPRUMCEosNew.java index f2a70444bc..698c9276d7 100644 --- a/src/main/java/neqsim/thermo/system/SystemUMRPRUMCEosNew.java +++ b/src/main/java/neqsim/thermo/system/SystemUMRPRUMCEosNew.java @@ -1,61 +1,48 @@ -package neqsim.thermo.system; +/* + * System_SRK_EOS.java + * + * Created on 8. april 2000, 23:05 + */ +package neqsim.thermo.system; /** * This class defines a thermodynamic system using the UMR-PRU with MC paramters equation of state * * @author Even Solbraa + * @version */ -public class SystemUMRPRUMCEosNew extends SystemUMRPRUMCEos { - private static final long serialVersionUID = 1000; - /** - *

- * Constructor for SystemUMRPRUMCEosNew. - *

- */ - public SystemUMRPRUMCEosNew() { - super(); - setBmixType(1); - modelName = "UMR-PRU-MC-EoS-New"; - } +import neqsim.thermo.phase.PhasePrEosvolcor; - /** - *

- * Constructor for SystemUMRPRUMCEosNew. - *

- * - * @param T a double - * @param P a double - */ - public SystemUMRPRUMCEosNew(double T, double P) { - super(T, P); - modelName = "UMR-PRU-MC-EoS_new"; - attractiveTermNumber = 13; - } +/** + * This class defines a thermodynamic system using the UMR-PRU with MC paramters equation of state + */ +public class SystemUMRPRUMCEosNew extends SystemUMRPRUMCEos { - /** - *

- * Constructor for SystemUMRPRUMCEosNew. - *

- * - * @param T a double - * @param P a double - * @param solidCheck a boolean - */ - public SystemUMRPRUMCEosNew(double T, double P, boolean solidCheck) { - super(T, P, solidCheck); + public SystemUMRPRUMCEosNew() { + super(); + modelName = "UMR-PRU-MC-EoS-New"; + attractiveTermNumber = 19; + useVolumeCorrection(false); + for (int i = 0; i < numberOfPhases; i++) { + phaseArray[i] = new PhasePrEosvolcor(); + phaseArray[i].setTemperature(298.15); + phaseArray[i].setPressure(1.0); + phaseArray[i].useVolumeCorrection(false); } + } - /** {@inheritDoc} */ - @Override - public SystemUMRPRUMCEos clone() { - SystemUMRPRUMCEos clonedSystem = null; - try { - clonedSystem = (SystemUMRPRUMCEosNew) super.clone(); - } catch (Exception e) { - logger.error("Cloning failed.", e); - } - - return clonedSystem; + public SystemUMRPRUMCEosNew(double T, double P) { + super(T, P); + modelName = "UMR-PRU-MC-EoS-New"; + attractiveTermNumber = 19; + useVolumeCorrection(false); + for (int i = 0; i < numberOfPhases; i++) { + phaseArray[i] = new PhasePrEosvolcor(); + phaseArray[i].setTemperature(T); + phaseArray[i].setPressure(P); + phaseArray[i].useVolumeCorrection(false); } + } + } diff --git a/src/main/java/neqsim/thermo/system/SystemUNIFAC.java b/src/main/java/neqsim/thermo/system/SystemUNIFAC.java index 29f5a82ac3..7a290e2825 100644 --- a/src/main/java/neqsim/thermo/system/SystemUNIFAC.java +++ b/src/main/java/neqsim/thermo/system/SystemUNIFAC.java @@ -5,8 +5,8 @@ import neqsim.thermo.phase.PhaseSrkEos; /** - * This class defines a thermodynamic system using the SRK equation of state for gas and Unifac for - * liquids + * This class defines a thermodynamic system using the Unifac for liquids with SRK equation of state + * for gas * * @author Even Solbraa */ diff --git a/src/main/java/neqsim/thermo/system/SystemUNIFACpsrk.java b/src/main/java/neqsim/thermo/system/SystemUNIFACpsrk.java index f39576eb98..f41a78ca7f 100644 --- a/src/main/java/neqsim/thermo/system/SystemUNIFACpsrk.java +++ b/src/main/java/neqsim/thermo/system/SystemUNIFACpsrk.java @@ -5,7 +5,7 @@ import neqsim.thermo.phase.PhaseSrkEos; /** - * This class defines a thermodynamic system using the SRK equation of state + * This class defines a thermodynamic system using the UNIFAC for liquid and PSRK EoS for gas * * @author Even Solbraa */ diff --git a/src/main/java/neqsim/thermo/util/GERG/DETAIL.java b/src/main/java/neqsim/thermo/util/GERG/DETAIL.java index 01197c6a68..e792dfb9ac 100644 --- a/src/main/java/neqsim/thermo/util/GERG/DETAIL.java +++ b/src/main/java/neqsim/thermo/util/GERG/DETAIL.java @@ -460,10 +460,10 @@ static void xTermsDetail(double[] x) { } /** - * @param T - * @param D - * @param x - * @param a0 + * @param T ... + * @param D ... + * @param x ... + * @param a0 ... */ static void Alpha0Detail(double T, double D, double[] x, doubleW[] a0) { // Private Sub Alpha0Detail(T, D, x, a0) @@ -534,11 +534,11 @@ static void Alpha0Detail(double T, double D, double[] x, doubleW[] a0) { } /** - * @param itau - * @param idel - * @param T - * @param D - * @param ar + * @param itau .... + * @param idel ... + * @param T ... + * @param D ... + * @param ar ... */ static void AlpharDetail(int itau, int idel, double T, double D, doubleW[][] ar) { // Private Sub AlpharDetail(itau, idel, T, D, ar) diff --git a/src/main/java/neqsim/thermo/util/GERG/GERG2008.java b/src/main/java/neqsim/thermo/util/GERG/GERG2008.java index 490572eb90..165928b8d1 100644 --- a/src/main/java/neqsim/thermo/util/GERG/GERG2008.java +++ b/src/main/java/neqsim/thermo/util/GERG/GERG2008.java @@ -428,9 +428,9 @@ public static void PropertiesGERG(double T, double D, double[] x, doubleW P, dou } /** - * @param x - * @param Tr - * @param Dr + * @param x ... + * @param Tr ... + * @param Dr ... */ // The following routines are low-level routines that should not be called outside of this code. static void ReducingParametersGERG(double[] x, doubleW Tr, doubleW Dr) { @@ -491,10 +491,10 @@ static void ReducingParametersGERG(double[] x, doubleW Tr, doubleW Dr) { } /** - * @param T - * @param D - * @param x - * @param a0 + * @param T ... + * @param D ... + * @param x ... + * @param a0 ... */ static void Alpha0GERG(double T, double D, double[] x, doubleW[] a0) { // Private Sub Alpha0GERG(T, D, x, a0) @@ -561,12 +561,12 @@ static void Alpha0GERG(double T, double D, double[] x, doubleW[] a0) { } /** - * @param itau - * @param idelta - * @param T - * @param D - * @param x - * @param ar + * @param itau ... + * @param idelta ... + * @param T ... + * @param D .... + * @param x .... + * @param ar ... */ static void AlpharGERG(int itau, int idelta, double T, double D, double[] x, doubleW[][] ar) { // Private Sub AlpharGERG(itau, idelta, T, D, x, ar) @@ -715,8 +715,8 @@ static void AlpharGERG(int itau, int idelta, double T, double D, double[] x, dou } /** - * @param lntau - * @param x + * @param lntau ... + * @param x .... */ static void tTermsGERG(double lntau, double[] x) { // Private Sub tTermsGERG(lntau, x) @@ -761,9 +761,9 @@ static void tTermsGERG(double lntau, double[] x) { } /** - * @param x - * @param Tcx - * @param Dcx + * @param x composition + * @param Tcx temperature in Kelvin + * @param Dcx density */ static void PseudoCriticalPointGERG(double[] x, doubleW Tcx, doubleW Dcx) { // PseudoCriticalPointGERG(x, Tcx, Dcx) diff --git a/src/main/java/neqsim/thermo/util/parameterFitting/Procede/CH4CO2WaterMDEA/TestIonicInteractionParameterFittingCH4.java b/src/main/java/neqsim/thermo/util/parameterFitting/Procede/CH4CO2WaterMDEA/TestIonicInteractionParameterFittingCH4.java index 6365a16361..b37ddd59ca 100644 --- a/src/main/java/neqsim/thermo/util/parameterFitting/Procede/CH4CO2WaterMDEA/TestIonicInteractionParameterFittingCH4.java +++ b/src/main/java/neqsim/thermo/util/parameterFitting/Procede/CH4CO2WaterMDEA/TestIonicInteractionParameterFittingCH4.java @@ -12,103 +12,105 @@ import neqsim.util.database.NeqSimDataBase; /** - *

TestIonicInteractionParameterFittingCH4 class.

+ *

+ * TestIonicInteractionParameterFittingCH4 class. + *

* * @author Even Solbraa * @version $Id: $Id */ public class TestIonicInteractionParameterFittingCH4 { - static Logger logger = LogManager.getLogger(TestIonicInteractionParameterFittingCH4.class); - - /** - *

main.

- * - * @param args an array of {@link java.lang.String} objects - */ - @SuppressWarnings("unused") - public static void main(String[] args) { - LevenbergMarquardt optim = new LevenbergMarquardt(); - ArrayList sampleList = new ArrayList(); - - // inserting samples from database - NeqSimDataBase database = new NeqSimDataBase(); - ResultSet dataSet = database.getResultSet("SELECT * FROM CO2CH4MDEA"); - - double ID, x1, x2, x3, x4, y1, y2, y3, y4, temperature, pressure, loading; - - // double guess[] = {0.0005447481}; //Case I - // double guess[] = {0.0004929757}; //Case II - double guess[] = {0.0004929757, 1e-10}; // Case II and CO2-CH4 parameter also regressed - - try { - int i = 0; - logger.info("adding...."); - while (dataSet.next()) { - i++; - IonicInteractionParameterFittingFunctionCH4 function = - new IonicInteractionParameterFittingFunctionCH4(); - IonicInteractionParameterFittingFunctionCH4 function1 = - new IonicInteractionParameterFittingFunctionCH4(1, 1); - - ID = Integer.parseInt(dataSet.getString("ID")); - pressure = Double.parseDouble(dataSet.getString("Pressure")); - temperature = Double.parseDouble(dataSet.getString("Temperature")); - x1 = Double.parseDouble(dataSet.getString("x1")); - x2 = Double.parseDouble(dataSet.getString("x2")); - x3 = Double.parseDouble(dataSet.getString("x3")); - x4 = Double.parseDouble(dataSet.getString("x4")); - y1 = Double.parseDouble(dataSet.getString("y1")); - y2 = Double.parseDouble(dataSet.getString("y2")); - y3 = Double.parseDouble(dataSet.getString("y3")); - y4 = Double.parseDouble(dataSet.getString("y4")); - - loading = x2 / x4; - - SystemInterface testSystem = new SystemFurstElectrolyteEos(temperature, pressure); - testSystem.addComponent("methane", x1); - testSystem.addComponent("CO2", x2); - testSystem.addComponent("MDEA", x4); - testSystem.addComponent("water", x3); - - testSystem.chemicalReactionInit(); - testSystem.createDatabase(true); - testSystem.setMixingRule(4); - testSystem.init(0); - - double sample1[] = {loading}; - double standardDeviation1[] = {0.01}; - SampleValue sample = - new SampleValue(pressure, pressure / 100.0, sample1, standardDeviation1); - function.setInitialGuess(guess); - sample.setFunction(function); - sample.setReference("addicks"); - sample.setDescription(Double.toString(ID)); - sample.setThermodynamicSystem(testSystem); - sampleList.add(sample); - - double sample2[] = {loading}; - double standardDeviation2[] = {0.01}; - SampleValue sample3 = new SampleValue(pressure * y2, y2 * pressure / 100.0, sample2, - standardDeviation2); - function1.setInitialGuess(guess); - sample3.setFunction(function1); - sample3.setReference("addicks"); - sample3.setDescription(Double.toString(ID)); - sample3.setThermodynamicSystem(testSystem); - sampleList.add(sample3); - } - } catch (Exception e) { - logger.error("database error" + e); - } - - SampleSet sampleSet = new SampleSet(sampleList); - optim.setSampleSet(sampleSet); + static Logger logger = LogManager.getLogger(TestIonicInteractionParameterFittingCH4.class); + + /** + *

+ * main. + *

+ * + * @param args an array of {@link java.lang.String} objects + */ + @SuppressWarnings("unused") + public static void main(String[] args) { + LevenbergMarquardt optim = new LevenbergMarquardt(); + ArrayList sampleList = new ArrayList(); + + // inserting samples from database + NeqSimDataBase database = new NeqSimDataBase(); + ResultSet dataSet = database.getResultSet("SELECT * FROM CO2CH4MDEA"); + + double ID, x1, x2, x3, x4, y1, y2, y3, y4, temperature, pressure, loading; + + // double guess[] = {0.0005447481}; //Case I + // double guess[] = {0.0004929757}; //Case II + double guess[] = {0.0004929757, 1e-10}; // Case II and CO2-CH4 parameter also regressed + + try { + int i = 0; + logger.info("adding...."); + while (dataSet.next()) { + i++; + IonicInteractionParameterFittingFunctionCH4 function = + new IonicInteractionParameterFittingFunctionCH4(); + IonicInteractionParameterFittingFunctionCH4 function1 = + new IonicInteractionParameterFittingFunctionCH4(1, 1); + + ID = Integer.parseInt(dataSet.getString("ID")); + pressure = Double.parseDouble(dataSet.getString("Pressure")); + temperature = Double.parseDouble(dataSet.getString("Temperature")); + x1 = Double.parseDouble(dataSet.getString("x1")); + x2 = Double.parseDouble(dataSet.getString("x2")); + x3 = Double.parseDouble(dataSet.getString("x3")); + x4 = Double.parseDouble(dataSet.getString("x4")); + y1 = Double.parseDouble(dataSet.getString("y1")); + y2 = Double.parseDouble(dataSet.getString("y2")); + y3 = Double.parseDouble(dataSet.getString("y3")); + y4 = Double.parseDouble(dataSet.getString("y4")); + + loading = x2 / x4; + + SystemInterface testSystem = new SystemFurstElectrolyteEos(temperature, pressure); + testSystem.addComponent("methane", x1); + testSystem.addComponent("CO2", x2); + testSystem.addComponent("MDEA", x4); + testSystem.addComponent("water", x3); + + testSystem.chemicalReactionInit(); + testSystem.createDatabase(true); + testSystem.setMixingRule(4); + testSystem.init(0); + + double sample1[] = {loading}; + double standardDeviation1[] = {0.01}; + SampleValue sample = + new SampleValue(pressure, pressure / 100.0, sample1, standardDeviation1); + function.setInitialGuess(guess); + sample.setFunction(function); + sample.setReference("addicks"); + sample.setDescription(Double.toString(ID)); + sample.setThermodynamicSystem(testSystem); + sampleList.add(sample); + + double sample2[] = {loading}; + double standardDeviation2[] = {0.01}; + SampleValue sample3 = + new SampleValue(pressure * y2, y2 * pressure / 100.0, sample2, standardDeviation2); + function1.setInitialGuess(guess); + sample3.setFunction(function1); + sample3.setReference("addicks"); + sample3.setDescription(Double.toString(ID)); + sample3.setThermodynamicSystem(testSystem); + sampleList.add(sample3); + } + } catch (Exception e) { + logger.error("database error" + e); + } - // do simulations + SampleSet sampleSet = new SampleSet(sampleList); + optim.setSampleSet(sampleSet); - optim.solve(); - optim.displayCurveFit(); - // optim.writeToCdfFile("c:/testFit.nc"); - // optim.writeToTextFile("c:/testFit.txt"); - } + // do simulations + optim.solve(); + optim.displayCurveFit(); + // optim.writeToTextFile("c:/testFit.txt"); + } } diff --git a/src/main/java/neqsim/thermo/util/parameterFitting/binaryInteractionParameterFitting/EosInteractionParameterFitting/TestCPAParameterFittingToSolubilityData.java b/src/main/java/neqsim/thermo/util/parameterFitting/binaryInteractionParameterFitting/EosInteractionParameterFitting/TestCPAParameterFittingToSolubilityData.java index 0626c45c04..a38f95d3dd 100644 --- a/src/main/java/neqsim/thermo/util/parameterFitting/binaryInteractionParameterFitting/EosInteractionParameterFitting/TestCPAParameterFittingToSolubilityData.java +++ b/src/main/java/neqsim/thermo/util/parameterFitting/binaryInteractionParameterFitting/EosInteractionParameterFitting/TestCPAParameterFittingToSolubilityData.java @@ -20,98 +20,96 @@ * @version $Id: $Id */ public class TestCPAParameterFittingToSolubilityData { - static Logger logger = LogManager.getLogger(TestCPAParameterFittingToSolubilityData.class); + static Logger logger = LogManager.getLogger(TestCPAParameterFittingToSolubilityData.class); - /** - *

- * main. - *

- * - * @param args an array of {@link java.lang.String} objects - */ - public static void main(String[] args) { - LevenbergMarquardt optim = new LevenbergMarquardt(); - ArrayList sampleList = new ArrayList(); + /** + *

+ * main. + *

+ * + * @param args an array of {@link java.lang.String} objects + */ + public static void main(String[] args) { + LevenbergMarquardt optim = new LevenbergMarquardt(); + ArrayList sampleList = new ArrayList(); - // inserting samples from database - NeqSimExperimentDatabase database = new NeqSimExperimentDatabase(); - ResultSet dataSet = database.getResultSet( - "SELECT * FROM binarySolubilityData WHERE ComponentSolute='CO2' AND ComponentSolvent='water' AND Reference='Houghton1957' AND Reference<>'Nighswander1989' AND Temperature>283.15 AND Temperature<373.15 AND Pressure<60.01325 ORDER BY Temperature"); - // ResultSet dataSet = database.getResultSet( "SELECT * FROM - // binarysolubilitydata WHERE ComponentSolute='methane' AND - // ComponentSolvent='water' AND Temperature>278.0 AND Temperature<350.0"); - double parameterGuess[] = {-0.27686, 0.001121};// , 0.000117974}; //cpa + // inserting samples from database + NeqSimExperimentDatabase database = new NeqSimExperimentDatabase(); + ResultSet dataSet = database.getResultSet( + "SELECT * FROM binarySolubilityData WHERE ComponentSolute='CO2' AND ComponentSolvent='water' AND Reference='Houghton1957' AND Reference<>'Nighswander1989' AND Temperature>283.15 AND Temperature<373.15 AND Pressure<60.01325 ORDER BY Temperature"); + // ResultSet dataSet = database.getResultSet( "SELECT * FROM + // binarysolubilitydata WHERE ComponentSolute='methane' AND + // ComponentSolvent='water' AND Temperature>278.0 AND Temperature<350.0"); + double parameterGuess[] = {-0.27686, 0.001121};// , 0.000117974}; //cpa - try { - int p = 0; - logger.info("adding...."); - while (dataSet.next() && p < 200) { - p++; - CPAParameterFittingToSolubilityData function = - new CPAParameterFittingToSolubilityData(1, 0); + try { + int p = 0; + logger.info("adding...."); + while (dataSet.next() && p < 200) { + p++; + CPAParameterFittingToSolubilityData function = + new CPAParameterFittingToSolubilityData(1, 0); - SystemInterface testSystem = new SystemSrkCPAstatoil(290, 1.0); - // SystemInterface testSystem = new SystemSrkEos(290, 1.0); - testSystem.addComponent("CO2", 1.0); - testSystem.addComponent("water", 10.0); - testSystem.createDatabase(true); - testSystem.setMixingRule(10); - testSystem.setMultiPhaseCheck(true); - testSystem.setTemperature(Double.parseDouble(dataSet.getString("Temperature"))); - testSystem.setPressure(Double.parseDouble(dataSet.getString("Pressure"))); + SystemInterface testSystem = new SystemSrkCPAstatoil(290, 1.0); + // SystemInterface testSystem = new SystemSrkEos(290, 1.0); + testSystem.addComponent("CO2", 1.0); + testSystem.addComponent("water", 10.0); + testSystem.createDatabase(true); + testSystem.setMixingRule(10); + testSystem.setMultiPhaseCheck(true); + testSystem.setTemperature(Double.parseDouble(dataSet.getString("Temperature"))); + testSystem.setPressure(Double.parseDouble(dataSet.getString("Pressure"))); - testSystem.init(0); - double sample1[] = {testSystem.getPressure(), testSystem.getTemperature()}; - double standardDeviation1[] = {0.13, 0.12}; - double expVal = Double.parseDouble(dataSet.getString("x1")); - SampleValue sample = new SampleValue(expVal, - Double.parseDouble(dataSet.getString("StandardDeviation")), sample1, - standardDeviation1); - function.setInitialGuess(parameterGuess); - sample.setFunction(function); - sample.setThermodynamicSystem(testSystem); - sample.setReference(Double.toString(testSystem.getTemperature())); - // double parameterGuess[] = {-0.130}; //srk - // double parameterGuess[] = {-0.0668706940}; //cpa - sampleList.add(sample); - } - } catch (Exception e) { - logger.error("database error" + e); - } - /* - * - * dataSet = database.getResultSet( - * "SELECT * FROM BinaryEquilibriumData WHERE Component1='methane' AND Component2='MEG'" ); - * try { int p = 0; logger.info("adding...."); while (!dataSet.next() && p < 0) { p++; - * CPAParameterFittingToSolubilityData function = new - * CPAParameterFittingToSolubilityData(0,1); - * - * SystemInterface testSystem = new SystemSrkCPAstatoil(290, 1.0); //SystemInterface - * testSystem = new SystemSrkEos(290, 1.0); testSystem.addComponent("methane", 1.0); - * testSystem.addComponent("MEG", 1.0); //testSystem.createDatabase(true); - * testSystem.setTemperature(Double.parseDouble(dataSet.getString("Temperature") )); - * testSystem.setPressure(Double.parseDouble(dataSet.getString("Pressure"))); - * testSystem.setMixingRule(10); testSystem.init(0); double sample1[] = - * {testSystem.getPressure(), testSystem.getTemperature()}; double standardDeviation1[] = - * {0.13}; pressure double value = Double.parseDouble(dataSet.getString("y2")); SampleValue - * sample = new SampleValue(value, value/100.0, sample1, standardDeviation1); - * sample.setFunction(function); sample.setThermodynamicSystem(testSystem); - * sample.setReference(Double.toString(testSystem.getTemperature())); //double - * parameterGuess[] = {-0.130}; //srk // double parameterGuess[] = {-0.0668706940}; //cpa - * function.setInitialGuess(parameterGuess); sampleList.add(sample); } } catch (Exception e) - * { logger.error("database error" + e); } - */ + testSystem.init(0); + double sample1[] = {testSystem.getPressure(), testSystem.getTemperature()}; + double standardDeviation1[] = {0.13, 0.12}; + double expVal = Double.parseDouble(dataSet.getString("x1")); + SampleValue sample = + new SampleValue(expVal, Double.parseDouble(dataSet.getString("StandardDeviation")), + sample1, standardDeviation1); + function.setInitialGuess(parameterGuess); + sample.setFunction(function); + sample.setThermodynamicSystem(testSystem); + sample.setReference(Double.toString(testSystem.getTemperature())); + // double parameterGuess[] = {-0.130}; //srk + // double parameterGuess[] = {-0.0668706940}; //cpa + sampleList.add(sample); + } + } catch (Exception e) { + logger.error("database error" + e); + } + /* + * + * dataSet = database.getResultSet( + * "SELECT * FROM BinaryEquilibriumData WHERE Component1='methane' AND Component2='MEG'" ); try + * { int p = 0; logger.info("adding...."); while (!dataSet.next() && p < 0) { p++; + * CPAParameterFittingToSolubilityData function = new CPAParameterFittingToSolubilityData(0,1); + * + * SystemInterface testSystem = new SystemSrkCPAstatoil(290, 1.0); //SystemInterface testSystem + * = new SystemSrkEos(290, 1.0); testSystem.addComponent("methane", 1.0); + * testSystem.addComponent("MEG", 1.0); //testSystem.createDatabase(true); + * testSystem.setTemperature(Double.parseDouble(dataSet.getString("Temperature") )); + * testSystem.setPressure(Double.parseDouble(dataSet.getString("Pressure"))); + * testSystem.setMixingRule(10); testSystem.init(0); double sample1[] = + * {testSystem.getPressure(), testSystem.getTemperature()}; double standardDeviation1[] = + * {0.13}; pressure double value = Double.parseDouble(dataSet.getString("y2")); SampleValue + * sample = new SampleValue(value, value/100.0, sample1, standardDeviation1); + * sample.setFunction(function); sample.setThermodynamicSystem(testSystem); + * sample.setReference(Double.toString(testSystem.getTemperature())); //double parameterGuess[] + * = {-0.130}; //srk // double parameterGuess[] = {-0.0668706940}; //cpa + * function.setInitialGuess(parameterGuess); sampleList.add(sample); } } catch (Exception e) { + * logger.error("database error" + e); } + */ - SampleSet sampleSet = new SampleSet(sampleList); - optim.setSampleSet(sampleSet); + SampleSet sampleSet = new SampleSet(sampleList); + optim.setSampleSet(sampleSet); - // do simulations - // optim.solve(); - // optim.runMonteCarloSimulation(); - optim.calcDeviation(); - optim.displayResult(); - optim.displayCurveFit(); - // optim.writeToCdfFile("c:/testFit.nc"); - // optim.writeToTextFile("c:/testFit.txt"); - } + // do simulations + // optim.solve(); + // optim.runMonteCarloSimulation(); + optim.calcDeviation(); + optim.displayResult(); + optim.displayCurveFit(); + // optim.writeToTextFile("c:/testFit.txt"); + } } diff --git a/src/main/java/neqsim/thermo/util/parameterFitting/binaryInteractionParameterFitting/EosInteractionParameterFitting/TestCPAParameterFittingToSolubilityData_Lucia.java b/src/main/java/neqsim/thermo/util/parameterFitting/binaryInteractionParameterFitting/EosInteractionParameterFitting/TestCPAParameterFittingToSolubilityData_Lucia.java index 4d5e586c96..78e2fabf28 100644 --- a/src/main/java/neqsim/thermo/util/parameterFitting/binaryInteractionParameterFitting/EosInteractionParameterFitting/TestCPAParameterFittingToSolubilityData_Lucia.java +++ b/src/main/java/neqsim/thermo/util/parameterFitting/binaryInteractionParameterFitting/EosInteractionParameterFitting/TestCPAParameterFittingToSolubilityData_Lucia.java @@ -20,172 +20,169 @@ * @version $Id: $Id */ public class TestCPAParameterFittingToSolubilityData_Lucia { - static Logger logger = - LogManager.getLogger(TestCPAParameterFittingToSolubilityData_Lucia.class); + static Logger logger = LogManager.getLogger(TestCPAParameterFittingToSolubilityData_Lucia.class); - /** - *

- * main. - *

- * - * @param args an array of {@link java.lang.String} objects - */ - public static void main(String[] args) { - LevenbergMarquardt optim = new LevenbergMarquardt(); - ArrayList sampleList = new ArrayList(); + /** + *

+ * main. + *

+ * + * @param args an array of {@link java.lang.String} objects + */ + public static void main(String[] args) { + LevenbergMarquardt optim = new LevenbergMarquardt(); + ArrayList sampleList = new ArrayList(); - // inserting samples from database - NeqSimDataBase database = new NeqSimDataBase(); - ResultSet dataSet = database.getResultSet( - "SELECT * FROM luciadata8 WHERE Component='methane' AND Temperature>410.15 AND Pressure<100000000 AND L2<>NULL AND L2>0.00000001 ORDER BY Temperature,Pressure");// AND - // Reference='Houghton1957' - // AND - // Reference<>'Nighswander1989' - // AND - // Temperature>278.15 - // AND - // Temperature<383.15 - // AND - // Pressure<60.01325"); - // ResultSet dataSet = database.getResultSet( "SELECT * FROM LuciaData8 WHERE - // Component='nitrogen' AND Temperature<390 AND L2<>NULL AND L2>0.0000000001 - // ORDER BY Temperature,Pressure"); - // ResultSet dataSet = database.getResultSet( "SELECT * FROM LuciaData8 WHERE - // Component='CO2' AND Temperature<390 AND L2<>NULL AND L2>0.0000000001 ORDER BY - // Temperature,Pressure"); - // ResultSet dataSet = database.getResultSet( "SELECT * FROM LuciaData8 WHERE - // Component='ethane' AND Temperature<390 AND Pressure<10000000 AND L2<>NULL AND - // L2>0.0000000001 ORDER BY Temperature,Pressure"); - // ResultSet dataSet = database.getResultSet( "SELECT * FROM LuciaData8 WHERE - // Component='propane' AND Temperature<390 AND Pressure<15000000 AND L2<>NULL - // AND L2>0.0000000001 AND ID>2204 AND ID<2410 ORDER BY Temperature,Pressure"); - // ResultSet dataSet = database.getResultSet( "SELECT * FROM - // binarySolubilityData WHERE ComponentSolute='methane' AND - // ComponentSolvent='water'"); + // inserting samples from database + NeqSimDataBase database = new NeqSimDataBase(); + ResultSet dataSet = database.getResultSet( + "SELECT * FROM luciadata8 WHERE Component='methane' AND Temperature>410.15 AND Pressure<100000000 AND L2<>NULL AND L2>0.00000001 ORDER BY Temperature,Pressure");// AND + // Reference='Houghton1957' + // AND + // Reference<>'Nighswander1989' + // AND + // Temperature>278.15 + // AND + // Temperature<383.15 + // AND + // Pressure<60.01325"); + // ResultSet dataSet = database.getResultSet( "SELECT * FROM LuciaData8 WHERE + // Component='nitrogen' AND Temperature<390 AND L2<>NULL AND L2>0.0000000001 + // ORDER BY Temperature,Pressure"); + // ResultSet dataSet = database.getResultSet( "SELECT * FROM LuciaData8 WHERE + // Component='CO2' AND Temperature<390 AND L2<>NULL AND L2>0.0000000001 ORDER BY + // Temperature,Pressure"); + // ResultSet dataSet = database.getResultSet( "SELECT * FROM LuciaData8 WHERE + // Component='ethane' AND Temperature<390 AND Pressure<10000000 AND L2<>NULL AND + // L2>0.0000000001 ORDER BY Temperature,Pressure"); + // ResultSet dataSet = database.getResultSet( "SELECT * FROM LuciaData8 WHERE + // Component='propane' AND Temperature<390 AND Pressure<15000000 AND L2<>NULL + // AND L2>0.0000000001 AND ID>2204 AND ID<2410 ORDER BY Temperature,Pressure"); + // ResultSet dataSet = database.getResultSet( "SELECT * FROM + // binarySolubilityData WHERE ComponentSolute='methane' AND + // ComponentSolvent='water'"); - try { - int p = 0; - logger.info("adding...."); - while (!dataSet.next() && p < 50) { - p++; - CPAParameterFittingToSolubilityData function = - new CPAParameterFittingToSolubilityData(); + try { + int p = 0; + logger.info("adding...."); + while (!dataSet.next() && p < 50) { + p++; + CPAParameterFittingToSolubilityData function = new CPAParameterFittingToSolubilityData(); - SystemInterface testSystem = - new SystemSrkCPA(Double.parseDouble(dataSet.getString("Temperature")), - Double.parseDouble(dataSet.getString("Pressure")) / 1.0e5); - // SystemInterface testSystem = new - // SystemSrkEos(Double.parseDouble(dataSet.getString("Temperature")), - // Double.parseDouble(dataSet.getString("Pressure"))/1.0e5); - testSystem.addComponent("methane", 1.0); - // testSystem.addComponent("propane", 1.0); - testSystem.addComponent("water", 10.0); - // testSystem.createDatabase(true); - testSystem.setMixingRule(7); - testSystem.init(0); - double sample1[] = {testSystem.getPressure(), testSystem.getTemperature()}; - double standardDeviation1[] = {0.01}; - double val = Double.parseDouble(dataSet.getString("L2")); - double sdev = val / 100.0; - SampleValue sample = new SampleValue(val, sdev, sample1, standardDeviation1); - sample.setFunction(function); - sample.setThermodynamicSystem(testSystem);// 34.7 - sample.setReference(Double.toString(testSystem.getTemperature())); - // double parameterGuess[] = {0.05155112588}; //srk - double parameterGuess[] = {0.0459393339}; // cpa-srk- metan 23.658199 abs dev bias - // -6.267% - // double parameterGuess[] = {0.1592294845}; //cpa-pr - metan 21.9 - // double parameterGuess[] = {-0.059201934}; //cpa-srk - nitrogen - // double parameterGuess[] = {0.1}; - // double parameterGuess[] = {-0.059201934}; //cpa-pr - nitrogen 29.20534 abs - // bias 23.93392 - // double parameterGuess[] = {-0.0586254634}; //cpa-srk - CO2 abs 18.5043 bias - // -11.3665 - // double parameterGuess[] = {0.0160496243}; //cpa-pr - CO2 - // double parameterGuess[] = {0.13287685}; //srk + SystemInterface testSystem = + new SystemSrkCPA(Double.parseDouble(dataSet.getString("Temperature")), + Double.parseDouble(dataSet.getString("Pressure")) / 1.0e5); + // SystemInterface testSystem = new + // SystemSrkEos(Double.parseDouble(dataSet.getString("Temperature")), + // Double.parseDouble(dataSet.getString("Pressure"))/1.0e5); + testSystem.addComponent("methane", 1.0); + // testSystem.addComponent("propane", 1.0); + testSystem.addComponent("water", 10.0); + // testSystem.createDatabase(true); + testSystem.setMixingRule(7); + testSystem.init(0); + double sample1[] = {testSystem.getPressure(), testSystem.getTemperature()}; + double standardDeviation1[] = {0.01}; + double val = Double.parseDouble(dataSet.getString("L2")); + double sdev = val / 100.0; + SampleValue sample = new SampleValue(val, sdev, sample1, standardDeviation1); + sample.setFunction(function); + sample.setThermodynamicSystem(testSystem);// 34.7 + sample.setReference(Double.toString(testSystem.getTemperature())); + // double parameterGuess[] = {0.05155112588}; //srk + double parameterGuess[] = {0.0459393339}; // cpa-srk- metan 23.658199 abs dev bias + // -6.267% + // double parameterGuess[] = {0.1592294845}; //cpa-pr - metan 21.9 + // double parameterGuess[] = {-0.059201934}; //cpa-srk - nitrogen + // double parameterGuess[] = {0.1}; + // double parameterGuess[] = {-0.059201934}; //cpa-pr - nitrogen 29.20534 abs + // bias 23.93392 + // double parameterGuess[] = {-0.0586254634}; //cpa-srk - CO2 abs 18.5043 bias + // -11.3665 + // double parameterGuess[] = {0.0160496243}; //cpa-pr - CO2 + // double parameterGuess[] = {0.13287685}; //srk - function.setInitialGuess(parameterGuess); - sampleList.add(sample); - } - } catch (Exception e) { - logger.error("database error", e); - } + function.setInitialGuess(parameterGuess); + sampleList.add(sample); + } + } catch (Exception e) { + logger.error("database error", e); + } - // dataSet = database.getResultSet( "SELECT * FROM LuciaData WHERE - // Component='methane' AND ID<3000 AND Temperature<380 AND Pressure<100000000 - // AND Y<>NULL AND Y>0.00000001 ORDER BY Temperature,Pressure");// AND - // Reference='Houghton1957' AND Reference<>'Nighswander1989' AND - // Temperature>278.15 AND Temperature<383.15 AND Pressure<60.01325"); - dataSet = database.getResultSet( - "SELECT * FROM LuciaData8 WHERE Component='methane' AND Temperature>273.15 AND Pressure<153000000 AND Y<>NULL AND Y>0.000000001 ORDER BY Temperature,Pressure"); - // dataSet = database.getResultSet( "SELECT * FROM LuciaData8 WHERE - // Component='nitrogen' AND Temperature<390 AND Y<>NULL AND Y>0.000000001 ORDER - // BY Temperature,Pressure"); - // dataSet = database.getResultSet( "SELECT * FROM LuciaData8 WHERE - // Component='CO2' AND Temperature>310 AND Y<>NULL AND Y>0.000000001 ORDER BY - // Temperature,Pressure"); - // dataSet = database.getResultSet( "SELECT * FROM LuciaData8 WHERE - // Component='ethane' AND Temperature<390 AND Pressure<10000000 AND Y<>NULL AND - // Y>0.000000001 ORDER BY Temperature,Pressure"); - // dataSet = database.getResultSet( "SELECT * FROM LuciaData8 WHERE - // Component='propane' AND Temperature<390 AND Pressure<15000000 AND Y<>NULL AND - // Y>0.000000001 AND ID>2204 AND ID<2410 ORDER BY Temperature,Pressure"); - // ResultSet dataSet = database.getResultSet( "SELECT * FROM - // binarySolubilityData WHERE ComponentSolute='methane' AND - // ComponentSolvent='water'"); - try { - int p = 0; - logger.info("adding...."); - while (dataSet.next() && p < 150) { - p++; - CPAParameterFittingToSolubilityData_Vap function = - new CPAParameterFittingToSolubilityData_Vap(); + // dataSet = database.getResultSet( "SELECT * FROM LuciaData WHERE + // Component='methane' AND ID<3000 AND Temperature<380 AND Pressure<100000000 + // AND Y<>NULL AND Y>0.00000001 ORDER BY Temperature,Pressure");// AND + // Reference='Houghton1957' AND Reference<>'Nighswander1989' AND + // Temperature>278.15 AND Temperature<383.15 AND Pressure<60.01325"); + dataSet = database.getResultSet( + "SELECT * FROM LuciaData8 WHERE Component='methane' AND Temperature>273.15 AND Pressure<153000000 AND Y<>NULL AND Y>0.000000001 ORDER BY Temperature,Pressure"); + // dataSet = database.getResultSet( "SELECT * FROM LuciaData8 WHERE + // Component='nitrogen' AND Temperature<390 AND Y<>NULL AND Y>0.000000001 ORDER + // BY Temperature,Pressure"); + // dataSet = database.getResultSet( "SELECT * FROM LuciaData8 WHERE + // Component='CO2' AND Temperature>310 AND Y<>NULL AND Y>0.000000001 ORDER BY + // Temperature,Pressure"); + // dataSet = database.getResultSet( "SELECT * FROM LuciaData8 WHERE + // Component='ethane' AND Temperature<390 AND Pressure<10000000 AND Y<>NULL AND + // Y>0.000000001 ORDER BY Temperature,Pressure"); + // dataSet = database.getResultSet( "SELECT * FROM LuciaData8 WHERE + // Component='propane' AND Temperature<390 AND Pressure<15000000 AND Y<>NULL AND + // Y>0.000000001 AND ID>2204 AND ID<2410 ORDER BY Temperature,Pressure"); + // ResultSet dataSet = database.getResultSet( "SELECT * FROM + // binarySolubilityData WHERE ComponentSolute='methane' AND + // ComponentSolvent='water'"); + try { + int p = 0; + logger.info("adding...."); + while (dataSet.next() && p < 150) { + p++; + CPAParameterFittingToSolubilityData_Vap function = + new CPAParameterFittingToSolubilityData_Vap(); - SystemInterface testSystem = - new SystemSrkCPA(Double.parseDouble(dataSet.getString("Temperature")), - Double.parseDouble(dataSet.getString("Pressure")) / 1.0e5); - // SystemInterface testSystem = new - // SystemSrkEos(Double.parseDouble(dataSet.getString("Temperature")), - // Double.parseDouble(dataSet.getString("Pressure"))/1.0e5); - testSystem.addComponent("methane", 1.0); - // testSystem.addComponent("propane", 1.0); - testSystem.addComponent("water", 10.0); - // testSystem.createDatabase(true); - testSystem.init(0); - testSystem.setMixingRule(7); + SystemInterface testSystem = + new SystemSrkCPA(Double.parseDouble(dataSet.getString("Temperature")), + Double.parseDouble(dataSet.getString("Pressure")) / 1.0e5); + // SystemInterface testSystem = new + // SystemSrkEos(Double.parseDouble(dataSet.getString("Temperature")), + // Double.parseDouble(dataSet.getString("Pressure"))/1.0e5); + testSystem.addComponent("methane", 1.0); + // testSystem.addComponent("propane", 1.0); + testSystem.addComponent("water", 10.0); + // testSystem.createDatabase(true); + testSystem.init(0); + testSystem.setMixingRule(7); - double sample1[] = {testSystem.getPressure(), testSystem.getTemperature()}; - double standardDeviation1[] = {0.01}; - double val = 1.0 - Double.parseDouble(dataSet.getString("Y")); - double sdev = val / 100.0; - SampleValue sample = new SampleValue(val, sdev, sample1, standardDeviation1); - sample.setFunction(function); - sample.setThermodynamicSystem(testSystem); - sample.setReference(Double.toString(testSystem.getTemperature())); - // double parameterGuess[] = {0.0459393339}; //cpa-srk- metan 23.658199 abs dev - // bias -6.267% - double parameterGuess[] = {0.0459393339}; // cpa-pr - metan - // double parameterGuess[] = {-0.059201934}; //cpa-srk - nitrogen - // double parameterGuess[] = {0.1}; - // double parameterGuess[] = {0.2413992410}; //cpa-pr - nitrogen - // double parameterGuess[] = {-0.0586254634}; //cpa-srk - CO2 12.0 - // double parameterGuess[] = {0.0160496243}; //cpa-pr - CO2 - function.setInitialGuess(parameterGuess); - sampleList.add(sample); - } - } catch (Exception e) { - logger.error("database error", e); - } + double sample1[] = {testSystem.getPressure(), testSystem.getTemperature()}; + double standardDeviation1[] = {0.01}; + double val = 1.0 - Double.parseDouble(dataSet.getString("Y")); + double sdev = val / 100.0; + SampleValue sample = new SampleValue(val, sdev, sample1, standardDeviation1); + sample.setFunction(function); + sample.setThermodynamicSystem(testSystem); + sample.setReference(Double.toString(testSystem.getTemperature())); + // double parameterGuess[] = {0.0459393339}; //cpa-srk- metan 23.658199 abs dev + // bias -6.267% + double parameterGuess[] = {0.0459393339}; // cpa-pr - metan + // double parameterGuess[] = {-0.059201934}; //cpa-srk - nitrogen + // double parameterGuess[] = {0.1}; + // double parameterGuess[] = {0.2413992410}; //cpa-pr - nitrogen + // double parameterGuess[] = {-0.0586254634}; //cpa-srk - CO2 12.0 + // double parameterGuess[] = {0.0160496243}; //cpa-pr - CO2 + function.setInitialGuess(parameterGuess); + sampleList.add(sample); + } + } catch (Exception e) { + logger.error("database error", e); + } - SampleSet sampleSet = new SampleSet(sampleList); - optim.setSampleSet(sampleSet); + SampleSet sampleSet = new SampleSet(sampleList); + optim.setSampleSet(sampleSet); - // do simulations - // optim.solve(); - // optim.runMonteCarloSimulation(); - // optim.displayResult(); - optim.displayCurveFit(); - optim.writeToCdfFile("c:/testFit.nc"); - optim.writeToTextFile("c:/testFit.txt"); - } + // do simulations + // optim.solve(); + // optim.runMonteCarloSimulation(); + // optim.displayResult(); + optim.displayCurveFit(); + optim.writeToTextFile("c:/testFit.txt"); + } } diff --git a/src/main/java/neqsim/thermo/util/parameterFitting/binaryInteractionParameterFitting/EosInteractionParameterFitting/TestCPAParameterFittingToSolubilityGlycolHC.java b/src/main/java/neqsim/thermo/util/parameterFitting/binaryInteractionParameterFitting/EosInteractionParameterFitting/TestCPAParameterFittingToSolubilityGlycolHC.java index acde6e90aa..06db3d4f1e 100644 --- a/src/main/java/neqsim/thermo/util/parameterFitting/binaryInteractionParameterFitting/EosInteractionParameterFitting/TestCPAParameterFittingToSolubilityGlycolHC.java +++ b/src/main/java/neqsim/thermo/util/parameterFitting/binaryInteractionParameterFitting/EosInteractionParameterFitting/TestCPAParameterFittingToSolubilityGlycolHC.java @@ -20,120 +20,118 @@ * @version $Id: $Id */ public class TestCPAParameterFittingToSolubilityGlycolHC { - static Logger logger = LogManager.getLogger(TestCPAParameterFittingToSolubilityGlycolHC.class); + static Logger logger = LogManager.getLogger(TestCPAParameterFittingToSolubilityGlycolHC.class); - /** - *

- * main. - *

- * - * @param args an array of {@link java.lang.String} objects - */ - public static void main(String[] args) { - LevenbergMarquardt optim = new LevenbergMarquardt(); - ArrayList sampleList = new ArrayList(); + /** + *

+ * main. + *

+ * + * @param args an array of {@link java.lang.String} objects + */ + public static void main(String[] args) { + LevenbergMarquardt optim = new LevenbergMarquardt(); + ArrayList sampleList = new ArrayList(); - // inserting samples from database - NeqSimDataBase database = new NeqSimDataBase();// AND reference<>'Lindboe2002' - ResultSet dataSet = database.getResultSet( - "SELECT * FROM hcglycollldata WHERE comp1='n-heptane' AND comp2='MEG' AND reference='Lindboe2002' ORDER BY Temperature,Pressure");// AND - // Reference='Houghton1957' - // AND - // Reference<>'Nighswander1989' - // AND - // Temperature>278.15 - // AND - // Temperature<383.15 - // AND - // Pressure<60.01325"); - // double parameterGuess[] = {0.0471326591, 5.14, 10.819, 0.6744, 0.0141}; - // double parameterGuess[] = {0.0602997387, 5.2137117933, 10.3039876875, - // 0.6714377099, 0.0178639622}; // fitted to all data - double parameterGuess[] = {1924, 4938};// , -1.11, 1.24}; - // double parameterGuess[] = {0.0471326591}; + // inserting samples from database + NeqSimDataBase database = new NeqSimDataBase();// AND reference<>'Lindboe2002' + ResultSet dataSet = database.getResultSet( + "SELECT * FROM hcglycollldata WHERE comp1='n-heptane' AND comp2='MEG' AND reference='Lindboe2002' ORDER BY Temperature,Pressure");// AND + // Reference='Houghton1957' + // AND + // Reference<>'Nighswander1989' + // AND + // Temperature>278.15 + // AND + // Temperature<383.15 + // AND + // Pressure<60.01325"); + // double parameterGuess[] = {0.0471326591, 5.14, 10.819, 0.6744, 0.0141}; + // double parameterGuess[] = {0.0602997387, 5.2137117933, 10.3039876875, + // 0.6714377099, 0.0178639622}; // fitted to all data + double parameterGuess[] = {1924, 4938};// , -1.11, 1.24}; + // double parameterGuess[] = {0.0471326591}; - try { - int p = 0; - logger.info("adding...."); - while (!dataSet.next() && p < 50) { - p++; - CPAParameterFittingToSolubilityData function = - new CPAParameterFittingToSolubilityData(); + try { + int p = 0; + logger.info("adding...."); + while (!dataSet.next() && p < 50) { + p++; + CPAParameterFittingToSolubilityData function = new CPAParameterFittingToSolubilityData(); - // SystemInterface testSystem = new - // SystemSrkCPAs(Double.parseDouble(dataSet.getString("temperature"))+273.15, - // Double.parseDouble(dataSet.getString("pressure"))); - SystemInterface testSystem = new SystemSrkEos( - Double.parseDouble(dataSet.getString("temperature")) + 273.15, - Double.parseDouble(dataSet.getString("pressure"))); + // SystemInterface testSystem = new + // SystemSrkCPAs(Double.parseDouble(dataSet.getString("temperature"))+273.15, + // Double.parseDouble(dataSet.getString("pressure"))); + SystemInterface testSystem = + new SystemSrkEos(Double.parseDouble(dataSet.getString("temperature")) + 273.15, + Double.parseDouble(dataSet.getString("pressure"))); - testSystem.addComponent("n-heptane", 1.0); - testSystem.addComponent("MEG", 10.0); - // testSystem.createDatabase(true); - // testSystem.setMixingRule(7); - testSystem.setMixingRule(4); - testSystem.init(0); - double sample1[] = {testSystem.getTemperature()}; - double standardDeviation1[] = {0.01}; - double val = Double.parseDouble(dataSet.getString("x-glyinhc")); - double sdev = val / 100.0; - SampleValue sample = new SampleValue(val, sdev, sample1, standardDeviation1); - sample.setFunction(function); - sample.setThermodynamicSystem(testSystem);// 34.7 - sample.setReference(Double.toString(testSystem.getTemperature())); - function.setInitialGuess(parameterGuess); - sampleList.add(sample); - } - } catch (Exception e) { - logger.error("database error" + e); - } + testSystem.addComponent("n-heptane", 1.0); + testSystem.addComponent("MEG", 10.0); + // testSystem.createDatabase(true); + // testSystem.setMixingRule(7); + testSystem.setMixingRule(4); + testSystem.init(0); + double sample1[] = {testSystem.getTemperature()}; + double standardDeviation1[] = {0.01}; + double val = Double.parseDouble(dataSet.getString("x-glyinhc")); + double sdev = val / 100.0; + SampleValue sample = new SampleValue(val, sdev, sample1, standardDeviation1); + sample.setFunction(function); + sample.setThermodynamicSystem(testSystem);// 34.7 + sample.setReference(Double.toString(testSystem.getTemperature())); + function.setInitialGuess(parameterGuess); + sampleList.add(sample); + } + } catch (Exception e) { + logger.error("database error" + e); + } - dataSet = database.getResultSet( - "SELECT * FROM HCGlycolLLdata WHERE comp1='n-heptane' AND comp2='MEG' AND reference='Lindboe2002' ORDER BY Temperature,Pressure"); + dataSet = database.getResultSet( + "SELECT * FROM HCGlycolLLdata WHERE comp1='n-heptane' AND comp2='MEG' AND reference='Lindboe2002' ORDER BY Temperature,Pressure"); - try { - int p = 0; - logger.info("adding...."); - while (!dataSet.next() && p < 50) { - p++; - CPAParameterFittingToSolubilityData_Vap function = - new CPAParameterFittingToSolubilityData_Vap(); + try { + int p = 0; + logger.info("adding...."); + while (!dataSet.next() && p < 50) { + p++; + CPAParameterFittingToSolubilityData_Vap function = + new CPAParameterFittingToSolubilityData_Vap(); - // SystemInterface testSystem = new - // SystemSrkCPAs(Double.parseDouble(dataSet.getString("temperature"))+273.15, - // Double.parseDouble(dataSet.getString("pressure"))); - SystemInterface testSystem = new SystemSrkEos( - Double.parseDouble(dataSet.getString("temperature")) + 273.15, - Double.parseDouble(dataSet.getString("pressure"))); + // SystemInterface testSystem = new + // SystemSrkCPAs(Double.parseDouble(dataSet.getString("temperature"))+273.15, + // Double.parseDouble(dataSet.getString("pressure"))); + SystemInterface testSystem = + new SystemSrkEos(Double.parseDouble(dataSet.getString("temperature")) + 273.15, + Double.parseDouble(dataSet.getString("pressure"))); - testSystem.addComponent("n-heptane", 1.00); - testSystem.addComponent("MEG", 10.0); - testSystem.init(0); - testSystem.setMixingRule(4); - double sample1[] = {testSystem.getTemperature()}; - double standardDeviation1[] = {0.01}; - double val = Double.parseDouble(dataSet.getString("x-hcinglyc")); - double sdev = val / 100.0; - SampleValue sample = new SampleValue(val, sdev, sample1, standardDeviation1); - sample.setFunction(function); - sample.setThermodynamicSystem(testSystem); - sample.setReference(Double.toString(testSystem.getTemperature())); - function.setInitialGuess(parameterGuess); - sampleList.add(sample); - } - } catch (Exception e) { - logger.error("database error" + e); - } + testSystem.addComponent("n-heptane", 1.00); + testSystem.addComponent("MEG", 10.0); + testSystem.init(0); + testSystem.setMixingRule(4); + double sample1[] = {testSystem.getTemperature()}; + double standardDeviation1[] = {0.01}; + double val = Double.parseDouble(dataSet.getString("x-hcinglyc")); + double sdev = val / 100.0; + SampleValue sample = new SampleValue(val, sdev, sample1, standardDeviation1); + sample.setFunction(function); + sample.setThermodynamicSystem(testSystem); + sample.setReference(Double.toString(testSystem.getTemperature())); + function.setInitialGuess(parameterGuess); + sampleList.add(sample); + } + } catch (Exception e) { + logger.error("database error" + e); + } - SampleSet sampleSet = new SampleSet(sampleList); - optim.setSampleSet(sampleSet); + SampleSet sampleSet = new SampleSet(sampleList); + optim.setSampleSet(sampleSet); - // do simulations - optim.solve(); - // optim.runMonteCarloSimulation(); - // optim.displayResult(); - optim.displayCurveFit(); - optim.writeToCdfFile("c:/testFit.nc"); - optim.writeToTextFile("c:/testFit.txt"); - } + // do simulations + optim.solve(); + // optim.runMonteCarloSimulation(); + // optim.displayResult(); + optim.displayCurveFit(); + optim.writeToTextFile("c:/testFit.txt"); + } } diff --git a/src/main/java/neqsim/thermo/util/parameterFitting/binaryInteractionParameterFitting/EosInteractionParameterFitting/TestEosParameterFittingToMercurySolubility.java b/src/main/java/neqsim/thermo/util/parameterFitting/binaryInteractionParameterFitting/EosInteractionParameterFitting/TestEosParameterFittingToMercurySolubility.java index 189adba078..e054ba90d8 100644 --- a/src/main/java/neqsim/thermo/util/parameterFitting/binaryInteractionParameterFitting/EosInteractionParameterFitting/TestEosParameterFittingToMercurySolubility.java +++ b/src/main/java/neqsim/thermo/util/parameterFitting/binaryInteractionParameterFitting/EosInteractionParameterFitting/TestEosParameterFittingToMercurySolubility.java @@ -20,72 +20,71 @@ * @version $Id: $Id */ public class TestEosParameterFittingToMercurySolubility { - static Logger logger = LogManager.getLogger(TestEosParameterFittingToMercurySolubility.class); + static Logger logger = LogManager.getLogger(TestEosParameterFittingToMercurySolubility.class); - /** - *

- * main. - *

- * - * @param args an array of {@link java.lang.String} objects - */ - public static void main(String[] args) { - LevenbergMarquardt optim = new LevenbergMarquardt(); - ArrayList sampleList = new ArrayList(); + /** + *

+ * main. + *

+ * + * @param args an array of {@link java.lang.String} objects + */ + public static void main(String[] args) { + LevenbergMarquardt optim = new LevenbergMarquardt(); + ArrayList sampleList = new ArrayList(); - // inserting samples from database - NeqSimExperimentDatabase database = new NeqSimExperimentDatabase(); + // inserting samples from database + NeqSimExperimentDatabase database = new NeqSimExperimentDatabase(); - ResultSet dataSet = database.getResultSet( - "SELECT * FROM binarysolubilitydata WHERE ComponentSolute='mercury' AND ComponentSolvent='n-hexane'"); - // double parameterGuess[] = {0.13}; // mercury-methane - // double parameterGuess[] = {0.0496811275399517}; // mercury-methane - // double parameterGuess[] = {0.0704}; // mercury-ethane - double parameterGuess[] = {-0.03310000498911416}; // mercury-ibutane - // double parameterGuess[] = {0.0674064646735}; // mercury-propane - // double parameterGuess[] = { 0.3674008071}; // mercury-CO2 - // double parameterGuess[] = { 0.016529772608}; // mercury-nitrogen - try { - int p = 0; - logger.info("adding...."); - while (dataSet.next() && p < 40) { - p++; - CPAParameterFittingToSolubilityData function = - new CPAParameterFittingToSolubilityData(0, 0); + ResultSet dataSet = database.getResultSet( + "SELECT * FROM binarysolubilitydata WHERE ComponentSolute='mercury' AND ComponentSolvent='n-hexane'"); + // double parameterGuess[] = {0.13}; // mercury-methane + // double parameterGuess[] = {0.0496811275399517}; // mercury-methane + // double parameterGuess[] = {0.0704}; // mercury-ethane + double parameterGuess[] = {-0.03310000498911416}; // mercury-ibutane + // double parameterGuess[] = {0.0674064646735}; // mercury-propane + // double parameterGuess[] = { 0.3674008071}; // mercury-CO2 + // double parameterGuess[] = { 0.016529772608}; // mercury-nitrogen + try { + int p = 0; + logger.info("adding...."); + while (dataSet.next() && p < 40) { + p++; + CPAParameterFittingToSolubilityData function = + new CPAParameterFittingToSolubilityData(0, 0); - SystemInterface testSystem = new SystemSrkEos(290, 1.0); - testSystem.addComponent("mercury", 10.0); - testSystem.addComponent("n-hexane", 10.0); - testSystem.getPhase(0).getComponent("mercury").setAttractiveTerm(12); - testSystem.getPhase(1).getComponent("mercury").setAttractiveTerm(12); - testSystem.createDatabase(true); - testSystem.setMultiPhaseCheck(true); - testSystem.setTemperature(Double.parseDouble(dataSet.getString("Temperature"))); - testSystem.setPressure(Double.parseDouble(dataSet.getString("Pressure")) + 2); - testSystem.setMixingRule(2); - testSystem.init(0); - double sample1[] = {testSystem.getPressure(), testSystem.getTemperature()}; - double standardDeviation1[] = {0.13}; - double x1 = Double.parseDouble(dataSet.getString("x1")); - SampleValue sample = new SampleValue(x1, x1 / 100.0, sample1, standardDeviation1); - sample.setFunction(function); - sample.setThermodynamicSystem(testSystem); - function.setInitialGuess(parameterGuess); - sampleList.add(sample); - } - } catch (Exception e) { - logger.error("database error" + e); - } + SystemInterface testSystem = new SystemSrkEos(290, 1.0); + testSystem.addComponent("mercury", 10.0); + testSystem.addComponent("n-hexane", 10.0); + testSystem.getPhase(0).getComponent("mercury").setAttractiveTerm(12); + testSystem.getPhase(1).getComponent("mercury").setAttractiveTerm(12); + testSystem.createDatabase(true); + testSystem.setMultiPhaseCheck(true); + testSystem.setTemperature(Double.parseDouble(dataSet.getString("Temperature"))); + testSystem.setPressure(Double.parseDouble(dataSet.getString("Pressure")) + 2); + testSystem.setMixingRule(2); + testSystem.init(0); + double sample1[] = {testSystem.getPressure(), testSystem.getTemperature()}; + double standardDeviation1[] = {0.13}; + double x1 = Double.parseDouble(dataSet.getString("x1")); + SampleValue sample = new SampleValue(x1, x1 / 100.0, sample1, standardDeviation1); + sample.setFunction(function); + sample.setThermodynamicSystem(testSystem); + function.setInitialGuess(parameterGuess); + sampleList.add(sample); + } + } catch (Exception e) { + logger.error("database error" + e); + } - SampleSet sampleSet = new SampleSet(sampleList); - optim.setSampleSet(sampleSet); + SampleSet sampleSet = new SampleSet(sampleList); + optim.setSampleSet(sampleSet); - // do simulations - optim.solve(); - // optim.runMonteCarloSimulation(); - // optim.displayResult(); - optim.displayCurveFit(); - // optim.writeToCdfFile("c:/testFit.nc"); - // optim.writeToTextFile("c:/testFit.txt"); - } + // do simulations + optim.solve(); + // optim.runMonteCarloSimulation(); + // optim.displayResult(); + optim.displayCurveFit(); + // optim.writeToTextFile("c:/testFit.txt"); + } } diff --git a/src/main/java/neqsim/thermo/util/parameterFitting/binaryInteractionParameterFitting/EosInteractionParameterFitting/TestParameterFittingToSolubilityDataEinar.java b/src/main/java/neqsim/thermo/util/parameterFitting/binaryInteractionParameterFitting/EosInteractionParameterFitting/TestParameterFittingToSolubilityDataEinar.java index 5ea8f17f5c..5a6633bded 100644 --- a/src/main/java/neqsim/thermo/util/parameterFitting/binaryInteractionParameterFitting/EosInteractionParameterFitting/TestParameterFittingToSolubilityDataEinar.java +++ b/src/main/java/neqsim/thermo/util/parameterFitting/binaryInteractionParameterFitting/EosInteractionParameterFitting/TestParameterFittingToSolubilityDataEinar.java @@ -20,67 +20,65 @@ * @version $Id: $Id */ public class TestParameterFittingToSolubilityDataEinar { - static Logger logger = LogManager.getLogger(TestParameterFittingToSolubilityDataEinar.class); + static Logger logger = LogManager.getLogger(TestParameterFittingToSolubilityDataEinar.class); - /** - *

- * main. - *

- * - * @param args an array of {@link java.lang.String} objects - */ - public static void main(String[] args) { - LevenbergMarquardt optim = new LevenbergMarquardt(); - ArrayList sampleList = new ArrayList(); + /** + *

+ * main. + *

+ * + * @param args an array of {@link java.lang.String} objects + */ + public static void main(String[] args) { + LevenbergMarquardt optim = new LevenbergMarquardt(); + ArrayList sampleList = new ArrayList(); - // inserting samples from database - NeqSimDataBase database = new NeqSimDataBase(); - ResultSet dataSet = database.getResultSet( - "SELECT * FROM binarysolubilitydataeinar WHERE ComponentSolute='methane' AND ComponentSolvent='Water'"); + // inserting samples from database + NeqSimDataBase database = new NeqSimDataBase(); + ResultSet dataSet = database.getResultSet( + "SELECT * FROM binarysolubilitydataeinar WHERE ComponentSolute='methane' AND ComponentSolvent='Water'"); - try { - int p = 0; - logger.info("adding...."); - while (dataSet.next() && p < 4000) { - p++; - CPAParameterFittingToSolubilityData function = - new CPAParameterFittingToSolubilityData(); + try { + int p = 0; + logger.info("adding...."); + while (dataSet.next() && p < 4000) { + p++; + CPAParameterFittingToSolubilityData function = new CPAParameterFittingToSolubilityData(); - SystemInterface testSystem = new SystemPrEos(290, 1.0); - testSystem.addComponent("methane", 1.0); - testSystem.addComponent("water", 10.0); - testSystem.createDatabase(true); - testSystem.setTemperature(Double.parseDouble(dataSet.getString("Temperature"))); - testSystem.setPressure(Double.parseDouble(dataSet.getString("Pressure")) / 1.0e5); - testSystem.setMixingRule(2); - testSystem.init(0); - double sample1[] = {testSystem.getPressure(), testSystem.getTemperature()}; - double standardDeviation1[] = - {testSystem.getPressure() / 100.0, testSystem.getTemperature() / 100.0}; - SampleValue sample = new SampleValue(Double.parseDouble(dataSet.getString("x1")), - Double.parseDouble(dataSet.getString("StandardDeviation")), sample1, - standardDeviation1); - sample.setFunction(function); - sample.setThermodynamicSystem(testSystem); - sample.setReference(Double.toString(testSystem.getTemperature())); - // double parameterGuess[] = {-0.130}; //srk - double parameterGuess[] = {0.0000001}; - function.setInitialGuess(parameterGuess); - sampleList.add(sample); - } - } catch (Exception e) { - logger.error("database error" + e); - } + SystemInterface testSystem = new SystemPrEos(290, 1.0); + testSystem.addComponent("methane", 1.0); + testSystem.addComponent("water", 10.0); + testSystem.createDatabase(true); + testSystem.setTemperature(Double.parseDouble(dataSet.getString("Temperature"))); + testSystem.setPressure(Double.parseDouble(dataSet.getString("Pressure")) / 1.0e5); + testSystem.setMixingRule(2); + testSystem.init(0); + double sample1[] = {testSystem.getPressure(), testSystem.getTemperature()}; + double standardDeviation1[] = + {testSystem.getPressure() / 100.0, testSystem.getTemperature() / 100.0}; + SampleValue sample = new SampleValue(Double.parseDouble(dataSet.getString("x1")), + Double.parseDouble(dataSet.getString("StandardDeviation")), sample1, + standardDeviation1); + sample.setFunction(function); + sample.setThermodynamicSystem(testSystem); + sample.setReference(Double.toString(testSystem.getTemperature())); + // double parameterGuess[] = {-0.130}; //srk + double parameterGuess[] = {0.0000001}; + function.setInitialGuess(parameterGuess); + sampleList.add(sample); + } + } catch (Exception e) { + logger.error("database error" + e); + } - SampleSet sampleSet = new SampleSet(sampleList); - optim.setSampleSet(sampleSet); + SampleSet sampleSet = new SampleSet(sampleList); + optim.setSampleSet(sampleSet); - // do simulations - optim.solve(); - // optim.runMonteCarloSimulation(); - // optim.displayResult(); - optim.displayCurveFit(); - optim.writeToCdfFile("c:/testFit.nc"); - optim.writeToTextFile("c:/testFit.txt"); - } + // do simulations + optim.solve(); + // optim.runMonteCarloSimulation(); + // optim.displayResult(); + optim.displayCurveFit(); + optim.writeToTextFile("c:/testFit.txt"); + } } diff --git a/src/main/java/neqsim/thermo/util/parameterFitting/binaryInteractionParameterFitting/HuronVidalParameterFitting/TestBinaryHVParameterFittingToDewPointData.java b/src/main/java/neqsim/thermo/util/parameterFitting/binaryInteractionParameterFitting/HuronVidalParameterFitting/TestBinaryHVParameterFittingToDewPointData.java index 296b0f320b..7544e86cbd 100644 --- a/src/main/java/neqsim/thermo/util/parameterFitting/binaryInteractionParameterFitting/HuronVidalParameterFitting/TestBinaryHVParameterFittingToDewPointData.java +++ b/src/main/java/neqsim/thermo/util/parameterFitting/binaryInteractionParameterFitting/HuronVidalParameterFitting/TestBinaryHVParameterFittingToDewPointData.java @@ -20,98 +20,97 @@ * @version $Id: $Id */ public class TestBinaryHVParameterFittingToDewPointData { - static Logger logger = LogManager.getLogger(TestBinaryHVParameterFittingToDewPointData.class); + static Logger logger = LogManager.getLogger(TestBinaryHVParameterFittingToDewPointData.class); - /** - *

- * main. - *

- * - * @param args an array of {@link java.lang.String} objects - */ - public static void main(String[] args) { - LevenbergMarquardt optim = new LevenbergMarquardt(); - ArrayList sampleList = new ArrayList(); + /** + *

+ * main. + *

+ * + * @param args an array of {@link java.lang.String} objects + */ + public static void main(String[] args) { + LevenbergMarquardt optim = new LevenbergMarquardt(); + ArrayList sampleList = new ArrayList(); - // inserting samples from database - NeqSimDataBase database = new NeqSimDataBase(); - ResultSet dataSet = database.getResultSet( - "SELECT * FROM dewpointquaternary WHERE temperature>173.1 AND x4>0.0000021 ORDER BY x4,pressure"); - // ResultSet dataSet = database.getResultSet( "SELECT * FROM - // activityCoefficientTable WHERE Component1='MDEA' AND Component2='water'"); - // testSystem.addComponent(dataSet.getString("ComponentSolute"), 1.0); - // testSystem.addComponent(dataSet.getString("ComponentSolvent"), 1.0); - try { - int p = 0; - logger.info("adding...."); - while (dataSet.next() && p < 300) { - p++; - BinaryHVParameterFittingToDewPointData function = - new BinaryHVParameterFittingToDewPointData(); + // inserting samples from database + NeqSimDataBase database = new NeqSimDataBase(); + ResultSet dataSet = database.getResultSet( + "SELECT * FROM dewpointquaternary WHERE temperature>173.1 AND x4>0.0000021 ORDER BY x4,pressure"); + // ResultSet dataSet = database.getResultSet( "SELECT * FROM + // activityCoefficientTable WHERE Component1='MDEA' AND Component2='water'"); + // testSystem.addComponent(dataSet.getString("ComponentSolute"), 1.0); + // testSystem.addComponent(dataSet.getString("ComponentSolvent"), 1.0); + try { + int p = 0; + logger.info("adding...."); + while (dataSet.next() && p < 300) { + p++; + BinaryHVParameterFittingToDewPointData function = + new BinaryHVParameterFittingToDewPointData(); - // SystemInterface testSystem = new SystemFurstElectrolyteEos(280, 1.0); - // SystemInterface testSystem = new SystemSrkSchwartzentruberEos(290, 1.0); - SystemInterface testSystem = new SystemPrEos(290, 1.0); - testSystem.addComponent(dataSet.getString("comp1"), - Double.parseDouble(dataSet.getString("x1"))); - testSystem.addComponent(dataSet.getString("comp2"), - Double.parseDouble(dataSet.getString("x2"))); - testSystem.addComponent("ethane", Double.parseDouble(dataSet.getString("x3"))); - testSystem.addComponent(dataSet.getString("comp4"), - Double.parseDouble(dataSet.getString("x4"))); - // testSystem.setSolidPhaseCheck(true); - // testSystem.addComponent("CO2", 1.0); - // testSystem.addComponent("water", 1.0); - // testSystem.addComponent("MDEA", 1.000001); - // testSystem.chemicalReactionInit(); - // testSystem.createDatabase(true); - testSystem.setMixingRule(4); + // SystemInterface testSystem = new SystemFurstElectrolyteEos(280, 1.0); + // SystemInterface testSystem = new SystemSrkSchwartzentruberEos(290, 1.0); + SystemInterface testSystem = new SystemPrEos(290, 1.0); + testSystem.addComponent(dataSet.getString("comp1"), + Double.parseDouble(dataSet.getString("x1"))); + testSystem.addComponent(dataSet.getString("comp2"), + Double.parseDouble(dataSet.getString("x2"))); + testSystem.addComponent("ethane", Double.parseDouble(dataSet.getString("x3"))); + testSystem.addComponent(dataSet.getString("comp4"), + Double.parseDouble(dataSet.getString("x4"))); + // testSystem.setSolidPhaseCheck(true); + // testSystem.addComponent("CO2", 1.0); + // testSystem.addComponent("water", 1.0); + // testSystem.addComponent("MDEA", 1.000001); + // testSystem.chemicalReactionInit(); + // testSystem.createDatabase(true); + testSystem.setMixingRule(4); - // testSystem.getChemicalReactionOperations().solveChemEq(0); - // testSystem.getChemicalReactionOperations().solveChemEq(1); + // testSystem.getChemicalReactionOperations().solveChemEq(0); + // testSystem.getChemicalReactionOperations().solveChemEq(1); - // testSystem.isChemicalSystem(false); + // testSystem.isChemicalSystem(false); - // testSystem.addComponent("NaPlus", 1.0e-10); - // testSystem.addComponent("methane", 1.1); - testSystem.setTemperature(Double.parseDouble(dataSet.getString("temperature"))); - testSystem.setPressure(Double.parseDouble(dataSet.getString("pressure"))); - testSystem.init(0); - double sample1[] = {testSystem.getPressure(), testSystem.getTemperature()}; - double standardDeviation1[] = {0.01}; - SampleValue sample = new SampleValue(testSystem.getTemperature(), - testSystem.getTemperature() / 100.0, sample1, standardDeviation1); - sample.setFunction(function); - sample.setThermodynamicSystem(testSystem); - sample.setReference(Double.toString(testSystem.getTemperature())); - double parameterGuess[] = {0.01}; - // double parameterGuess[] = {4799.35, -2772.29, 0.6381, -1.68096}; - // double parameterGuess[] = {3932.0, -4127.0, -5.89, 8.9}; // HV CO2 - // double parameterGuess[] = {5023.6600682957, -136.4306560594, -3.9812435921, - // 1.4579901393}; // HV methane - // double parameterGuess[] = {3204.3057406886, -2753.7379912645, -12.4728330162 - // , 13.0150379323}; // HV - // double parameterGuess[] = {8.992E3, -3.244E3, -8.424E0, -1.824E0}; // HV - // double parameterGuess[] = {-7.132E2, -3.933E2};//, 3.96E0, 9.602E-1}; //, - // 1.239}; //WS - sample.setReference(Double.toString(testSystem.getPressure())); - function.setInitialGuess(parameterGuess); - sampleList.add(sample); - } - } catch (Exception e) { - logger.error("database error" + e); - } + // testSystem.addComponent("NaPlus", 1.0e-10); + // testSystem.addComponent("methane", 1.1); + testSystem.setTemperature(Double.parseDouble(dataSet.getString("temperature"))); + testSystem.setPressure(Double.parseDouble(dataSet.getString("pressure"))); + testSystem.init(0); + double sample1[] = {testSystem.getPressure(), testSystem.getTemperature()}; + double standardDeviation1[] = {0.01}; + SampleValue sample = new SampleValue(testSystem.getTemperature(), + testSystem.getTemperature() / 100.0, sample1, standardDeviation1); + sample.setFunction(function); + sample.setThermodynamicSystem(testSystem); + sample.setReference(Double.toString(testSystem.getTemperature())); + double parameterGuess[] = {0.01}; + // double parameterGuess[] = {4799.35, -2772.29, 0.6381, -1.68096}; + // double parameterGuess[] = {3932.0, -4127.0, -5.89, 8.9}; // HV CO2 + // double parameterGuess[] = {5023.6600682957, -136.4306560594, -3.9812435921, + // 1.4579901393}; // HV methane + // double parameterGuess[] = {3204.3057406886, -2753.7379912645, -12.4728330162 + // , 13.0150379323}; // HV + // double parameterGuess[] = {8.992E3, -3.244E3, -8.424E0, -1.824E0}; // HV + // double parameterGuess[] = {-7.132E2, -3.933E2};//, 3.96E0, 9.602E-1}; //, + // 1.239}; //WS + sample.setReference(Double.toString(testSystem.getPressure())); + function.setInitialGuess(parameterGuess); + sampleList.add(sample); + } + } catch (Exception e) { + logger.error("database error" + e); + } - SampleSet sampleSet = new SampleSet(sampleList); - optim.setSampleSet(sampleSet); + SampleSet sampleSet = new SampleSet(sampleList); + optim.setSampleSet(sampleSet); - // do simulations - // optim.solve(); - // optim.runMonteCarloSimulation(); - // optim.displayResult(); - optim.displayCurveFit(); - optim.displayResult(); - // optim.writeToCdfFile("c:/testFit.nc"); - // optim.writeToTextFile("c:/testFit.txt"); - } + // do simulations + // optim.solve(); + // optim.runMonteCarloSimulation(); + // optim.displayResult(); + optim.displayCurveFit(); + optim.displayResult(); + // optim.writeToTextFile("c:/testFit.txt"); + } } diff --git a/src/main/java/neqsim/thermo/util/parameterFitting/binaryInteractionParameterFitting/HuronVidalParameterFitting/TestBinaryHVParameterFittingToSolubilityData.java b/src/main/java/neqsim/thermo/util/parameterFitting/binaryInteractionParameterFitting/HuronVidalParameterFitting/TestBinaryHVParameterFittingToSolubilityData.java index 5cc95c17e2..d98d7547fe 100644 --- a/src/main/java/neqsim/thermo/util/parameterFitting/binaryInteractionParameterFitting/HuronVidalParameterFitting/TestBinaryHVParameterFittingToSolubilityData.java +++ b/src/main/java/neqsim/thermo/util/parameterFitting/binaryInteractionParameterFitting/HuronVidalParameterFitting/TestBinaryHVParameterFittingToSolubilityData.java @@ -20,104 +20,102 @@ * @version $Id: $Id */ public class TestBinaryHVParameterFittingToSolubilityData { - static Logger logger = LogManager.getLogger(TestBinaryHVParameterFittingToSolubilityData.class); + static Logger logger = LogManager.getLogger(TestBinaryHVParameterFittingToSolubilityData.class); - /** - *

- * main. - *

- * - * @param args an array of {@link java.lang.String} objects - */ - public static void main(String[] args) { - LevenbergMarquardt optim = new LevenbergMarquardt(); - ArrayList sampleList = new ArrayList(); + /** + *

+ * main. + *

+ * + * @param args an array of {@link java.lang.String} objects + */ + public static void main(String[] args) { + LevenbergMarquardt optim = new LevenbergMarquardt(); + ArrayList sampleList = new ArrayList(); - // inserting samples from database - NeqSimExperimentDatabase database = new NeqSimExperimentDatabase(); - // ResultSet dataSet = database.getResultSet( "SELECT * FROM - // binarySolubilityData WHERE ComponentSolute='CO2' AND ComponentSolvent='water' - // AND Reference='Houghton1957' AND Reference<>'Nighswander1989' AND - // Temperature>278.15 AND Temperature<363.15 AND Pressure<60.01325 ORDER BY - // Temperature,Pressure"); - ResultSet dataSet = database.getResultSet( - "SELECT * FROM binarySolubilityData WHERE ComponentSolute='oxygen' AND ComponentSolvent='water' ORDER BY Temperature,Pressure"); + // inserting samples from database + NeqSimExperimentDatabase database = new NeqSimExperimentDatabase(); + // ResultSet dataSet = database.getResultSet( "SELECT * FROM + // binarySolubilityData WHERE ComponentSolute='CO2' AND ComponentSolvent='water' + // AND Reference='Houghton1957' AND Reference<>'Nighswander1989' AND + // Temperature>278.15 AND Temperature<363.15 AND Pressure<60.01325 ORDER BY + // Temperature,Pressure"); + ResultSet dataSet = database.getResultSet( + "SELECT * FROM binarySolubilityData WHERE ComponentSolute='oxygen' AND ComponentSolvent='water' ORDER BY Temperature,Pressure"); - // ResultSet dataSet = database.getResultSet( "SELECT * FROM - // activityCoefficientTable WHERE Component1='MDEA' AND Component2='water'"); - // testSystem.addComponent(dataSet.getString("ComponentSolute"), 1.0); - // testSystem.addComponent(dataSet.getString("ComponentSolvent"), 1.0); - try { - int p = 0; - logger.info("adding...."); - while (dataSet.next() && p < 22) { - p++; - BinaryHVParameterFittingToSolubilityData function = - new BinaryHVParameterFittingToSolubilityData(); - // SystemInterface testSystem = new SystemSrkEos(280,1); - // SystemInterface testSystem = new SystemFurstElectrolyteEos(280, 1.0); - SystemInterface testSystem = new SystemSrkSchwartzentruberEos(290, 1.0); - // SystemInterface testSystem = new SystemSrkMathiasCopeman(290, 1.0); - testSystem.addComponent(dataSet.getString("ComponentSolute"), 1.0); - testSystem.addComponent(dataSet.getString("ComponentSolvent"), 100.0); + // ResultSet dataSet = database.getResultSet( "SELECT * FROM + // activityCoefficientTable WHERE Component1='MDEA' AND Component2='water'"); + // testSystem.addComponent(dataSet.getString("ComponentSolute"), 1.0); + // testSystem.addComponent(dataSet.getString("ComponentSolvent"), 1.0); + try { + int p = 0; + logger.info("adding...."); + while (dataSet.next() && p < 22) { + p++; + BinaryHVParameterFittingToSolubilityData function = + new BinaryHVParameterFittingToSolubilityData(); + // SystemInterface testSystem = new SystemSrkEos(280,1); + // SystemInterface testSystem = new SystemFurstElectrolyteEos(280, 1.0); + SystemInterface testSystem = new SystemSrkSchwartzentruberEos(290, 1.0); + // SystemInterface testSystem = new SystemSrkMathiasCopeman(290, 1.0); + testSystem.addComponent(dataSet.getString("ComponentSolute"), 1.0); + testSystem.addComponent(dataSet.getString("ComponentSolvent"), 100.0); - // testSystem.addComponent("CO2", 1.0); - // testSystem.addComponent("water", 1.0); - // testSystem.addComponent("MDEA", 1.000001); - // testSystem.chemicalReactionInit(); - testSystem.createDatabase(true); - testSystem.setMixingRule(4); + // testSystem.addComponent("CO2", 1.0); + // testSystem.addComponent("water", 1.0); + // testSystem.addComponent("MDEA", 1.000001); + // testSystem.chemicalReactionInit(); + testSystem.createDatabase(true); + testSystem.setMixingRule(4); - // testSystem.getChemicalReactionOperations().solveChemEq(0); - // testSystem.getChemicalReactionOperations().solveChemEq(1); + // testSystem.getChemicalReactionOperations().solveChemEq(0); + // testSystem.getChemicalReactionOperations().solveChemEq(1); - // testSystem.isChemicalSystem(false); + // testSystem.isChemicalSystem(false); - // testSystem.addComponent("NaPlus", 1.0e-10); - // testSystem.addComponent("methane", 1.1); - testSystem.setTemperature(Double.parseDouble(dataSet.getString("Temperature"))); - testSystem.setPressure(Double.parseDouble(dataSet.getString("Pressure"))); - logger.error("pressure " + testSystem.getPressure()); - testSystem.init(0); - double sample1[] = {testSystem.getPressure(), testSystem.getTemperature()}; - double standardDeviation1[] = {0.01}; - SampleValue sample = new SampleValue(Double.parseDouble(dataSet.getString("x1")), - Double.parseDouble(dataSet.getString("StandardDeviation")), sample1, - standardDeviation1); - sample.setFunction(function); - sample.setThermodynamicSystem(testSystem); - sample.setReference(Double.toString(testSystem.getTemperature())); - // double parameterGuess[] = {4799.35, -2772.29, 0.6381, -1.68096}; - // double parameterGuess[] = {5640.38, -3793.1, -4.42, 2.82}; // HV CO2 - // double parameterGuess[] = {7263.5285887088, -3712.3594920781, -7.1458168635, - // 1.2714576276};//CO2-SRK-MC - // double parameterGuess[] = {5251.7374371982, -3121.2788585048, -0.8420253536, - // -0.5123316046}; // HV CO2 -PVT-sim - double parameterGuess[] = - {2423.6600682957, -2136.4306560594, 1.9812435921, 1.4579901393}; // HV - // methane - // double parameterGuess[] = {3204.3057406886, -2753.7379912645, -12.4728330162 - // , 13.0150379323}; // HV - // double parameterGuess[] = {8.992E3, -3.244E3, -8.424E0, -1.824E0}; // HV - // double parameterGuess[] = {-7.132E2, -3.933E2};//, 3.96E0, 9.602E-1}; //, - // 1.239}; //WS - function.setInitialGuess(parameterGuess); - sampleList.add(sample); - } - } catch (Exception e) { - logger.error("database error" + e); - } + // testSystem.addComponent("NaPlus", 1.0e-10); + // testSystem.addComponent("methane", 1.1); + testSystem.setTemperature(Double.parseDouble(dataSet.getString("Temperature"))); + testSystem.setPressure(Double.parseDouble(dataSet.getString("Pressure"))); + logger.error("pressure " + testSystem.getPressure()); + testSystem.init(0); + double sample1[] = {testSystem.getPressure(), testSystem.getTemperature()}; + double standardDeviation1[] = {0.01}; + SampleValue sample = new SampleValue(Double.parseDouble(dataSet.getString("x1")), + Double.parseDouble(dataSet.getString("StandardDeviation")), sample1, + standardDeviation1); + sample.setFunction(function); + sample.setThermodynamicSystem(testSystem); + sample.setReference(Double.toString(testSystem.getTemperature())); + // double parameterGuess[] = {4799.35, -2772.29, 0.6381, -1.68096}; + // double parameterGuess[] = {5640.38, -3793.1, -4.42, 2.82}; // HV CO2 + // double parameterGuess[] = {7263.5285887088, -3712.3594920781, -7.1458168635, + // 1.2714576276};//CO2-SRK-MC + // double parameterGuess[] = {5251.7374371982, -3121.2788585048, -0.8420253536, + // -0.5123316046}; // HV CO2 -PVT-sim + double parameterGuess[] = {2423.6600682957, -2136.4306560594, 1.9812435921, 1.4579901393}; // HV + // methane + // double parameterGuess[] = {3204.3057406886, -2753.7379912645, -12.4728330162 + // , 13.0150379323}; // HV + // double parameterGuess[] = {8.992E3, -3.244E3, -8.424E0, -1.824E0}; // HV + // double parameterGuess[] = {-7.132E2, -3.933E2};//, 3.96E0, 9.602E-1}; //, + // 1.239}; //WS + function.setInitialGuess(parameterGuess); + sampleList.add(sample); + } + } catch (Exception e) { + logger.error("database error" + e); + } - SampleSet sampleSet = new SampleSet(sampleList); - optim.setSampleSet(sampleSet); + SampleSet sampleSet = new SampleSet(sampleList); + optim.setSampleSet(sampleSet); - // do simulations - optim.solve(); - // optim.runMonteCarloSimulation(); - // optim.displayResult(); - optim.displayCurveFit(); - // optim.displayResult(); - // optim.writeToCdfFile("c:/testFit.nc"); - // optim.writeToTextFile("c:/testFit.txt"); - } + // do simulations + optim.solve(); + // optim.runMonteCarloSimulation(); + // optim.displayResult(); + optim.displayCurveFit(); + // optim.displayResult(); + // optim.writeToTextFile("c:/testFit.txt"); + } } diff --git a/src/main/java/neqsim/thermo/util/parameterFitting/binaryInteractionParameterFitting/HuronVidalParameterFitting/TestBinaryHVParameterFittingToSolubilityData_Lucia.java b/src/main/java/neqsim/thermo/util/parameterFitting/binaryInteractionParameterFitting/HuronVidalParameterFitting/TestBinaryHVParameterFittingToSolubilityData_Lucia.java index bb49b345bb..a612bb4023 100644 --- a/src/main/java/neqsim/thermo/util/parameterFitting/binaryInteractionParameterFitting/HuronVidalParameterFitting/TestBinaryHVParameterFittingToSolubilityData_Lucia.java +++ b/src/main/java/neqsim/thermo/util/parameterFitting/binaryInteractionParameterFitting/HuronVidalParameterFitting/TestBinaryHVParameterFittingToSolubilityData_Lucia.java @@ -20,236 +20,235 @@ * @version $Id: $Id */ public class TestBinaryHVParameterFittingToSolubilityData_Lucia { - static Logger logger = - LogManager.getLogger(TestBinaryHVParameterFittingToSolubilityData_Lucia.class); - - /** - *

- * main. - *

- * - * @param args an array of {@link java.lang.String} objects - */ - public static void main(String[] args) { - LevenbergMarquardt optim = new LevenbergMarquardt(); - ArrayList sampleList = new ArrayList(); - - // inserting samples from database - NeqSimDataBase database = new NeqSimDataBase(); - ResultSet dataSet = database.getResultSet( - "SELECT * FROM LuciaData8 WHERE Component='methane' AND Temperature<520 AND L2<>NULL AND L2>0.0000000001 ORDER BY Temperature,Pressure");// AND - // Reference='Houghton1957' - // AND - // Reference<>'Nighswander1989' - // AND - // Temperature>278.15 - // AND - // Temperature<383.15 - // AND - // Pressure<60.01325"); - // ResultSet dataSet = database.getResultSet( "SELECT * FROM LuciaData8 WHERE - // Component='CO2' AND Temperature>250 AND Temperature<420 AND - // Pressure<700000000 AND L2 IS NOT NULL AND L2>0.000000001 ORDER BY - // Temperature,Pressure");// AND Reference='Houghton1957' AND - // Reference<>'Nighswander1989' AND Temperature>278.15 AND Temperature<383.15 - // AND Pressure<60.01325"); - // ResultSet dataSet = database.getResultSet( "SELECT * FROM LuciaData8 WHERE - // Component='propane' AND Temperature>250 AND Temperature<420 AND - // Pressure<700000000 AND L2<>NULL AND L2>0.000000001 ORDER BY - // Temperature,Pressure");// AND Reference='Houghton1957' AND - // Reference<>'Nighswander1989' AND Temperature>278.15 AND Temperature<383.15 - // AND Pressure<60.01325"); - // ResultSet dataSet = database.getResultSet( "SELECT * FROM LuciaData8 WHERE - // Component='methane' AND ID1>662 AND ID1<760 AND Temperature<520 AND L2<>NULL - // AND L2>0.0000000001 ORDER BY Temperature,Pressure");// AND - // Reference='Houghton1957' AND Reference<>'Nighswander1989' AND - // Temperature>278.15 AND Temperature<383.15 AND Pressure<60.01325"); - // ResultSet dataSet = database.getResultSet( "SELECT * FROM LuciaData8 WHERE - // Component='H2S' AND Temperature>250 AND Temperature<420 AND Pressure<10000000 - // AND L2<>NULL AND L2>0.000000001 ORDER BY Temperature,Pressure"); - try { - int p = 0; - logger.info("adding...."); - while (dataSet.next() && p < 150) { - p++; - BinaryHVParameterFittingToSolubilityData function = - new BinaryHVParameterFittingToSolubilityData(1, 1); - - // SystemInterface testSystem = new SystemFurstElectrolyteEos(280, 1.0); - // SystemInterface testSystem = new - // SystemPrEos1978(Double.parseDouble(dataSet.getString("Temperature")), - // Double.parseDouble(dataSet.getString("Pressure"))/1e5); - // SystemInterface testSystem = new - // SystemSrkEos(Double.parseDouble(dataSet.getString("Temperature")), - // Double.parseDouble(dataSet.getString("Pressure"))/1e5); - // SystemInterface testSystem = new - // SystemSrkEos(Double.parseDouble(dataSet.getString("Temperature")), - // Double.parseDouble(dataSet.getString("Pressure")) / 1e5); - SystemInterface testSystem = new SystemSrkCPAstatoil( - Double.parseDouble(dataSet.getString("Temperature")), - Double.parseDouble(dataSet.getString("Pressure")) / 1e5); - // testSystem.addComponent("propane", 10.0); - testSystem.addComponent("methane", 10.0); - testSystem.addComponent("water", 100.0); - - // testSystem.addComponent("CO2", 1.0); - // testSystem.addComponent("water", 1.0); - // testSystem.addComponent("MDEA", 1.000001); - // testSystem.chemicalReactionInit(); - // testSystem.createDatabase(true); - testSystem.setMixingRule(4); - // testSystem.getChemicalReactionOperations().solveChemEq(0); - // testSystem.getChemicalReactionOperations().solveChemEq(1); - - // testSystem.isChemicalSystem(false); - - // testSystem.addComponent("NaPlus", 1.0e-10); - // testSystem.addComponent("methane", 1.1); - testSystem.init(0); - double sample1[] = {testSystem.getPressure(), testSystem.getTemperature()}; - double standardDeviation1[] = {0.01}; - double val = Double.parseDouble(dataSet.getString("L2")); - double sdev = val / 100.0; - SampleValue sample = new SampleValue(val, sdev, sample1, standardDeviation1); - sample.setFunction(function); - sample.setThermodynamicSystem(testSystem); - sample.setReference(Double.toString(testSystem.getTemperature())); - // double parameterGuess[] = {4239.63, -232.924, -5.01417, 2.3761}; - // double parameterGuess[] = {3932.0, -4127.0, -5.89, 8.9}; // HV CO2 - // double parameterGuess[] = {1859.4161214985, -1025.4679064974, -1.5607986741, - // 2.1430069589}; // HV H2S - - // double parameterGuess[] = {1193.8840735911, 69.2494254233, -7.8323508140, - // 4.5299137720}; // H2S MDEA - // double parameterGuess[] ={5251.7374371982, -3121.2788585048, -0.8420253536, - // -0.5123316046};//;//,0.03};//co2 scsrk-ny - // double parameterGuess[] ={-1584, 3517, 3.9121943388, -0.44,-0.1};//propane - // double parameterGuess[] = { 5607, 0.897598343, -123.6011438188, - // -6.5496550381, 2.1378539395}; // HV methan570 - double parameterGuess[] = - {6114.2013874102, -188.264597921, -10.7239107857559, 2.310651690177652}; // HV - // methan570 - // double parameterGuess[] = {3204.3057406886, -2753.7379912645, -12.4728330162 - // , 13.0150379323}; // HV - // double parameterGuess[] = {8.992E3, -3.244E3, -8.424E0, -1.824E0}; // HV - // double parameterGuess[] = {-7.132E2, -3.933E2};//, 3.96E0, 9.602E-1}; //, - // 1.239}; //WS - function.setInitialGuess(parameterGuess); - sampleList.add(sample); - logger.info("liq points " + p); - } - } catch (Exception e) { - logger.error("database error" + e); - } - - dataSet = database.getResultSet( - "SELECT * FROM LuciaData8 WHERE Component='methane' AND ID<3000 AND Temperature<520 AND Y<>NULL AND Y>0.0000000001 ORDER BY Temperature,Pressure");// AND - // Reference='Houghton1957' - // AND - // Reference<>'Nighswander1989' - // AND - // Temperature>278.15 - // AND - // Temperature<383.15 - // AND - // Pressure<60.01325"); - // dataSet = database.getResultSet( "SELECT * FROM LuciaData8 WHERE - // Component='CO2' AND ID<3000 AND Temperature>250 AND Pressure<700000000 AND - // Temperature<420 AND Y IS NOT NULL AND Y>0.0000000001 ORDER BY - // Temperature,Pressure");// AND Reference='Houghton1957' AND - // Reference<>'Nighswander1989' AND Temperature>278.15 AND Temperature<383.15 - // AND Pressure<60.01325"); - // dataSet = database.getResultSet( "SELECT * FROM LuciaData8 WHERE - // Component='methane' AND Temperature>273.15 AND Pressure<153000000 AND Y<>NULL - // AND Y>0.000000001 ORDER BY Temperature,Pressure"); - - // ResultSet dataSet = database.getResultSet( "SELECT * FROM - // activityCoefficientTable WHERE Component1='MDEA' AND Component2='water'"); - // testSystem.addComponent(dataSet.getString("ComponentSolute"), 1.0); - // testSystem.addComponent(dataSet.getString("ComponentSolvent"), 1.0); - try { - int p = 0; - logger.info("adding...."); - while (dataSet.next() && p < 150) { - p++; - BinaryHVParameterFittingToSolubilityData function = - new BinaryHVParameterFittingToSolubilityData(0, 0); - - // SystemInterface testSystem = new - // SystemFurstElectrolyteEos(Double.parseDouble(dataSet.getString("Temperature")), - // Double.parseDouble(dataSet.getString("Pressure"))/1e5); - // SystemInterface testSystem = new - // SystemPrEos1978(Double.parseDouble(dataSet.getString("Temperature")), - // Double.parseDouble(dataSet.getString("Pressure"))/1e5); - // SystemInterface testSystem = new - // SystemSrkEos(Double.parseDouble(dataSet.getString("Temperature")), - // Double.parseDouble(dataSet.getString("Pressure"))/1e5); - // SystemInterface testSystem = new - // SystemSrkEos(Double.parseDouble(dataSet.getString("Temperature")), - // Double.parseDouble(dataSet.getString("Pressure")) / 1e5); - // testSystem.addComponent("CO2", 1.0); - SystemInterface testSystem = new SystemSrkCPAstatoil( - Double.parseDouble(dataSet.getString("Temperature")), - Double.parseDouble(dataSet.getString("Pressure")) / 1e5); - - testSystem.addComponent("methane", 10.0); - testSystem.addComponent("water", 10.0); - - // testSystem.addComponent("CO2", 1.0); - // testSystem.addComponent("water", 1.0); - // testSystem.addComponent("MDEA", 1.000001); - // testSystem.chemicalReactionInit(); - // testSystem.createDatabase(true); - testSystem.setMixingRule(4); - - // testSystem.getChemicalReactionOperations().solveChemEq(0); - // testSystem.getChemicalReactionOperations().solveChemEq(1); - - // testSystem.isChemicalSystem(false); - - // testSystem.addComponent("NaPlus", 1.0e-10); - // testSystem.addComponent("methane", 1.1); - testSystem.init(0); - double sample1[] = {testSystem.getPressure(), testSystem.getTemperature()}; - double standardDeviation1[] = {0.01}; - double val = 1.0 - Double.parseDouble(dataSet.getString("Y")); - double sdev = val / 100.0; - SampleValue sample = new SampleValue(val, sdev, sample1, standardDeviation1); - sample.setFunction(function); - sample.setThermodynamicSystem(testSystem); - sample.setReference(Double.toString(testSystem.getTemperature())); - // double parameterGuess[] = {4239.63, -232.924, -5.01417, 2.3761}; - // double parameterGuess[] ={3209.3031222305, -2016.3262143626, 4.2211091944, - // -3.3157456878}; - // double parameterGuess[] = {5640.0, -3793.0, -5.89, 8.9}; // HV CO2 - // double parameterGuess[] ={5251.7374371982, -3121.2788585048, -0.8420253536, - // -0.5123316046};//;//,0.03};//co2 scsrk-ny - double parameterGuess[] = - {6114.2013874102, -188.264597921, -10.7239107857559, 2.310651690177652}; // HV - // methane - // double parameterGuess[] = {3204.3057406886, -2753.7379912645, -12.4728330162 - // , 13.0150379323}; // HV - // double parameterGuess[] = {8.992E3, -3.244E3, -8.424E0, -1.824E0}; // HV - // double parameterGuess[] = {-7.132E2, -3.933E2};//, 3.96E0, 9.602E-1}; //, - // 1.239}; //WS - function.setInitialGuess(parameterGuess); - sample.setDescription(Double.toString(testSystem.getTemperature())); - sampleList.add(sample); - } - } catch (Exception e) { - logger.error("database error" + e); - } - - SampleSet sampleSet = new SampleSet(sampleList); - optim.setSampleSet(sampleSet); - - // do simulations - optim.solve(); - // optim.runMonteCarloSimulation(); - // optim.displayResult(); - optim.displayCurveFit(); - optim.displayResult(); - // optim.writeToCdfFile("c:/testFit.nc"); - // optim.writeToTextFile("c:/testFit.txt"); + static Logger logger = + LogManager.getLogger(TestBinaryHVParameterFittingToSolubilityData_Lucia.class); + + /** + *

+ * main. + *

+ * + * @param args an array of {@link java.lang.String} objects + */ + public static void main(String[] args) { + LevenbergMarquardt optim = new LevenbergMarquardt(); + ArrayList sampleList = new ArrayList(); + + // inserting samples from database + NeqSimDataBase database = new NeqSimDataBase(); + ResultSet dataSet = database.getResultSet( + "SELECT * FROM LuciaData8 WHERE Component='methane' AND Temperature<520 AND L2<>NULL AND L2>0.0000000001 ORDER BY Temperature,Pressure");// AND + // Reference='Houghton1957' + // AND + // Reference<>'Nighswander1989' + // AND + // Temperature>278.15 + // AND + // Temperature<383.15 + // AND + // Pressure<60.01325"); + // ResultSet dataSet = database.getResultSet( "SELECT * FROM LuciaData8 WHERE + // Component='CO2' AND Temperature>250 AND Temperature<420 AND + // Pressure<700000000 AND L2 IS NOT NULL AND L2>0.000000001 ORDER BY + // Temperature,Pressure");// AND Reference='Houghton1957' AND + // Reference<>'Nighswander1989' AND Temperature>278.15 AND Temperature<383.15 + // AND Pressure<60.01325"); + // ResultSet dataSet = database.getResultSet( "SELECT * FROM LuciaData8 WHERE + // Component='propane' AND Temperature>250 AND Temperature<420 AND + // Pressure<700000000 AND L2<>NULL AND L2>0.000000001 ORDER BY + // Temperature,Pressure");// AND Reference='Houghton1957' AND + // Reference<>'Nighswander1989' AND Temperature>278.15 AND Temperature<383.15 + // AND Pressure<60.01325"); + // ResultSet dataSet = database.getResultSet( "SELECT * FROM LuciaData8 WHERE + // Component='methane' AND ID1>662 AND ID1<760 AND Temperature<520 AND L2<>NULL + // AND L2>0.0000000001 ORDER BY Temperature,Pressure");// AND + // Reference='Houghton1957' AND Reference<>'Nighswander1989' AND + // Temperature>278.15 AND Temperature<383.15 AND Pressure<60.01325"); + // ResultSet dataSet = database.getResultSet( "SELECT * FROM LuciaData8 WHERE + // Component='H2S' AND Temperature>250 AND Temperature<420 AND Pressure<10000000 + // AND L2<>NULL AND L2>0.000000001 ORDER BY Temperature,Pressure"); + try { + int p = 0; + logger.info("adding...."); + while (dataSet.next() && p < 150) { + p++; + BinaryHVParameterFittingToSolubilityData function = + new BinaryHVParameterFittingToSolubilityData(1, 1); + + // SystemInterface testSystem = new SystemFurstElectrolyteEos(280, 1.0); + // SystemInterface testSystem = new + // SystemPrEos1978(Double.parseDouble(dataSet.getString("Temperature")), + // Double.parseDouble(dataSet.getString("Pressure"))/1e5); + // SystemInterface testSystem = new + // SystemSrkEos(Double.parseDouble(dataSet.getString("Temperature")), + // Double.parseDouble(dataSet.getString("Pressure"))/1e5); + // SystemInterface testSystem = new + // SystemSrkEos(Double.parseDouble(dataSet.getString("Temperature")), + // Double.parseDouble(dataSet.getString("Pressure")) / 1e5); + SystemInterface testSystem = + new SystemSrkCPAstatoil(Double.parseDouble(dataSet.getString("Temperature")), + Double.parseDouble(dataSet.getString("Pressure")) / 1e5); + // testSystem.addComponent("propane", 10.0); + testSystem.addComponent("methane", 10.0); + testSystem.addComponent("water", 100.0); + + // testSystem.addComponent("CO2", 1.0); + // testSystem.addComponent("water", 1.0); + // testSystem.addComponent("MDEA", 1.000001); + // testSystem.chemicalReactionInit(); + // testSystem.createDatabase(true); + testSystem.setMixingRule(4); + // testSystem.getChemicalReactionOperations().solveChemEq(0); + // testSystem.getChemicalReactionOperations().solveChemEq(1); + + // testSystem.isChemicalSystem(false); + + // testSystem.addComponent("NaPlus", 1.0e-10); + // testSystem.addComponent("methane", 1.1); + testSystem.init(0); + double sample1[] = {testSystem.getPressure(), testSystem.getTemperature()}; + double standardDeviation1[] = {0.01}; + double val = Double.parseDouble(dataSet.getString("L2")); + double sdev = val / 100.0; + SampleValue sample = new SampleValue(val, sdev, sample1, standardDeviation1); + sample.setFunction(function); + sample.setThermodynamicSystem(testSystem); + sample.setReference(Double.toString(testSystem.getTemperature())); + // double parameterGuess[] = {4239.63, -232.924, -5.01417, 2.3761}; + // double parameterGuess[] = {3932.0, -4127.0, -5.89, 8.9}; // HV CO2 + // double parameterGuess[] = {1859.4161214985, -1025.4679064974, -1.5607986741, + // 2.1430069589}; // HV H2S + + // double parameterGuess[] = {1193.8840735911, 69.2494254233, -7.8323508140, + // 4.5299137720}; // H2S MDEA + // double parameterGuess[] ={5251.7374371982, -3121.2788585048, -0.8420253536, + // -0.5123316046};//;//,0.03};//co2 scsrk-ny + // double parameterGuess[] ={-1584, 3517, 3.9121943388, -0.44,-0.1};//propane + // double parameterGuess[] = { 5607, 0.897598343, -123.6011438188, + // -6.5496550381, 2.1378539395}; // HV methan570 + double parameterGuess[] = + {6114.2013874102, -188.264597921, -10.7239107857559, 2.310651690177652}; // HV + // methan570 + // double parameterGuess[] = {3204.3057406886, -2753.7379912645, -12.4728330162 + // , 13.0150379323}; // HV + // double parameterGuess[] = {8.992E3, -3.244E3, -8.424E0, -1.824E0}; // HV + // double parameterGuess[] = {-7.132E2, -3.933E2};//, 3.96E0, 9.602E-1}; //, + // 1.239}; //WS + function.setInitialGuess(parameterGuess); + sampleList.add(sample); + logger.info("liq points " + p); + } + } catch (Exception e) { + logger.error("database error" + e); } + + dataSet = database.getResultSet( + "SELECT * FROM LuciaData8 WHERE Component='methane' AND ID<3000 AND Temperature<520 AND Y<>NULL AND Y>0.0000000001 ORDER BY Temperature,Pressure");// AND + // Reference='Houghton1957' + // AND + // Reference<>'Nighswander1989' + // AND + // Temperature>278.15 + // AND + // Temperature<383.15 + // AND + // Pressure<60.01325"); + // dataSet = database.getResultSet( "SELECT * FROM LuciaData8 WHERE + // Component='CO2' AND ID<3000 AND Temperature>250 AND Pressure<700000000 AND + // Temperature<420 AND Y IS NOT NULL AND Y>0.0000000001 ORDER BY + // Temperature,Pressure");// AND Reference='Houghton1957' AND + // Reference<>'Nighswander1989' AND Temperature>278.15 AND Temperature<383.15 + // AND Pressure<60.01325"); + // dataSet = database.getResultSet( "SELECT * FROM LuciaData8 WHERE + // Component='methane' AND Temperature>273.15 AND Pressure<153000000 AND Y<>NULL + // AND Y>0.000000001 ORDER BY Temperature,Pressure"); + + // ResultSet dataSet = database.getResultSet( "SELECT * FROM + // activityCoefficientTable WHERE Component1='MDEA' AND Component2='water'"); + // testSystem.addComponent(dataSet.getString("ComponentSolute"), 1.0); + // testSystem.addComponent(dataSet.getString("ComponentSolvent"), 1.0); + try { + int p = 0; + logger.info("adding...."); + while (dataSet.next() && p < 150) { + p++; + BinaryHVParameterFittingToSolubilityData function = + new BinaryHVParameterFittingToSolubilityData(0, 0); + + // SystemInterface testSystem = new + // SystemFurstElectrolyteEos(Double.parseDouble(dataSet.getString("Temperature")), + // Double.parseDouble(dataSet.getString("Pressure"))/1e5); + // SystemInterface testSystem = new + // SystemPrEos1978(Double.parseDouble(dataSet.getString("Temperature")), + // Double.parseDouble(dataSet.getString("Pressure"))/1e5); + // SystemInterface testSystem = new + // SystemSrkEos(Double.parseDouble(dataSet.getString("Temperature")), + // Double.parseDouble(dataSet.getString("Pressure"))/1e5); + // SystemInterface testSystem = new + // SystemSrkEos(Double.parseDouble(dataSet.getString("Temperature")), + // Double.parseDouble(dataSet.getString("Pressure")) / 1e5); + // testSystem.addComponent("CO2", 1.0); + SystemInterface testSystem = + new SystemSrkCPAstatoil(Double.parseDouble(dataSet.getString("Temperature")), + Double.parseDouble(dataSet.getString("Pressure")) / 1e5); + + testSystem.addComponent("methane", 10.0); + testSystem.addComponent("water", 10.0); + + // testSystem.addComponent("CO2", 1.0); + // testSystem.addComponent("water", 1.0); + // testSystem.addComponent("MDEA", 1.000001); + // testSystem.chemicalReactionInit(); + // testSystem.createDatabase(true); + testSystem.setMixingRule(4); + + // testSystem.getChemicalReactionOperations().solveChemEq(0); + // testSystem.getChemicalReactionOperations().solveChemEq(1); + + // testSystem.isChemicalSystem(false); + + // testSystem.addComponent("NaPlus", 1.0e-10); + // testSystem.addComponent("methane", 1.1); + testSystem.init(0); + double sample1[] = {testSystem.getPressure(), testSystem.getTemperature()}; + double standardDeviation1[] = {0.01}; + double val = 1.0 - Double.parseDouble(dataSet.getString("Y")); + double sdev = val / 100.0; + SampleValue sample = new SampleValue(val, sdev, sample1, standardDeviation1); + sample.setFunction(function); + sample.setThermodynamicSystem(testSystem); + sample.setReference(Double.toString(testSystem.getTemperature())); + // double parameterGuess[] = {4239.63, -232.924, -5.01417, 2.3761}; + // double parameterGuess[] ={3209.3031222305, -2016.3262143626, 4.2211091944, + // -3.3157456878}; + // double parameterGuess[] = {5640.0, -3793.0, -5.89, 8.9}; // HV CO2 + // double parameterGuess[] ={5251.7374371982, -3121.2788585048, -0.8420253536, + // -0.5123316046};//;//,0.03};//co2 scsrk-ny + double parameterGuess[] = + {6114.2013874102, -188.264597921, -10.7239107857559, 2.310651690177652}; // HV + // methane + // double parameterGuess[] = {3204.3057406886, -2753.7379912645, -12.4728330162 + // , 13.0150379323}; // HV + // double parameterGuess[] = {8.992E3, -3.244E3, -8.424E0, -1.824E0}; // HV + // double parameterGuess[] = {-7.132E2, -3.933E2};//, 3.96E0, 9.602E-1}; //, + // 1.239}; //WS + function.setInitialGuess(parameterGuess); + sample.setDescription(Double.toString(testSystem.getTemperature())); + sampleList.add(sample); + } + } catch (Exception e) { + logger.error("database error" + e); + } + + SampleSet sampleSet = new SampleSet(sampleList); + optim.setSampleSet(sampleSet); + + // do simulations + optim.solve(); + // optim.runMonteCarloSimulation(); + // optim.displayResult(); + optim.displayCurveFit(); + optim.displayResult(); + // optim.writeToTextFile("c:/testFit.txt"); + } } diff --git a/src/main/java/neqsim/thermo/util/parameterFitting/binaryInteractionParameterFitting/HuronVidalParameterFitting/TestBinaryHVParameterFittingToSolubilityData_LuciaPropane.java b/src/main/java/neqsim/thermo/util/parameterFitting/binaryInteractionParameterFitting/HuronVidalParameterFitting/TestBinaryHVParameterFittingToSolubilityData_LuciaPropane.java index 4ba0a3b572..ac7f6e8041 100644 --- a/src/main/java/neqsim/thermo/util/parameterFitting/binaryInteractionParameterFitting/HuronVidalParameterFitting/TestBinaryHVParameterFittingToSolubilityData_LuciaPropane.java +++ b/src/main/java/neqsim/thermo/util/parameterFitting/binaryInteractionParameterFitting/HuronVidalParameterFitting/TestBinaryHVParameterFittingToSolubilityData_LuciaPropane.java @@ -20,175 +20,173 @@ * @version $Id: $Id */ public class TestBinaryHVParameterFittingToSolubilityData_LuciaPropane { - static Logger logger = - LogManager.getLogger(TestBinaryHVParameterFittingToSolubilityData_LuciaPropane.class); + static Logger logger = + LogManager.getLogger(TestBinaryHVParameterFittingToSolubilityData_LuciaPropane.class); - /** - *

- * main. - *

- * - * @param args an array of {@link java.lang.String} objects - */ - public static void main(String[] args) { - LevenbergMarquardt optim = new LevenbergMarquardt(); - ArrayList sampleList = new ArrayList(); - - // inserting samples from database - NeqSimExperimentDatabase database = new NeqSimExperimentDatabase(); - ResultSet dataSet = database.getResultSet( - "SELECT * FROM LuciaData8 WHERE Component='nitrogen' AND Temperature>270.0 AND L2>0.000000001");// AND - // Temperature<600 - // AND - // Pressure<7000000000 - // AND - // L2<>NULL - // AND - // L2>0.000000001 - // ORDER - // BY - // Temperature,Pressure");// - // AND - // Reference='Houghton1957' - // AND - // Reference<>'Nighswander1989' - // AND - // Temperature>278.15 - // AND - // Temperature<383.15 - // AND - // Pressure<60.01325"); + /** + *

+ * main. + *

+ * + * @param args an array of {@link java.lang.String} objects + */ + public static void main(String[] args) { + LevenbergMarquardt optim = new LevenbergMarquardt(); + ArrayList sampleList = new ArrayList(); - try { - int p = 0; - logger.info("adding...."); - while (dataSet.next() && p < 80) { - p++; - BinaryHVParameterFittingToSolubilityData function = - new BinaryHVParameterFittingToSolubilityData(); + // inserting samples from database + NeqSimExperimentDatabase database = new NeqSimExperimentDatabase(); + ResultSet dataSet = database.getResultSet( + "SELECT * FROM LuciaData8 WHERE Component='nitrogen' AND Temperature>270.0 AND L2>0.000000001");// AND + // Temperature<600 + // AND + // Pressure<7000000000 + // AND + // L2<>NULL + // AND + // L2>0.000000001 + // ORDER + // BY + // Temperature,Pressure");// + // AND + // Reference='Houghton1957' + // AND + // Reference<>'Nighswander1989' + // AND + // Temperature>278.15 + // AND + // Temperature<383.15 + // AND + // Pressure<60.01325"); - SystemInterface testSystem = new SystemSrkSchwartzentruberEos( - Double.parseDouble(dataSet.getString("Temperature")), - Double.parseDouble(dataSet.getString("Pressure")) / 1e5); + try { + int p = 0; + logger.info("adding...."); + while (dataSet.next() && p < 80) { + p++; + BinaryHVParameterFittingToSolubilityData function = + new BinaryHVParameterFittingToSolubilityData(); - testSystem.addComponent("nitrogen", 10.0); - testSystem.addComponent("water", 10.0); + SystemInterface testSystem = + new SystemSrkSchwartzentruberEos(Double.parseDouble(dataSet.getString("Temperature")), + Double.parseDouble(dataSet.getString("Pressure")) / 1e5); - testSystem.createDatabase(true); - testSystem.setMixingRule("HV"); + testSystem.addComponent("nitrogen", 10.0); + testSystem.addComponent("water", 10.0); - testSystem.init(0); - double sample1[] = {testSystem.getPressure(), testSystem.getTemperature()}; - double standardDeviation1[] = {0.01}; - double val = Double.parseDouble(dataSet.getString("L2")); - double sdev = val / 100.0; - SampleValue sample = new SampleValue(val, sdev, sample1, standardDeviation1); - sample.setFunction(function); - sample.setThermodynamicSystem(testSystem); - sample.setReference(Double.toString(testSystem.getTemperature())); - double parameterGuess[] = {4898.64, -111.76};// , -0.1, -0.44};//, 0.07};//propane + testSystem.createDatabase(true); + testSystem.setMixingRule("HV"); - function.setInitialGuess(parameterGuess); - sampleList.add(sample); - } - } catch (Exception e) { - logger.error("database error" + e); - } + testSystem.init(0); + double sample1[] = {testSystem.getPressure(), testSystem.getTemperature()}; + double standardDeviation1[] = {0.01}; + double val = Double.parseDouble(dataSet.getString("L2")); + double sdev = val / 100.0; + SampleValue sample = new SampleValue(val, sdev, sample1, standardDeviation1); + sample.setFunction(function); + sample.setThermodynamicSystem(testSystem); + sample.setReference(Double.toString(testSystem.getTemperature())); + double parameterGuess[] = {4898.64, -111.76};// , -0.1, -0.44};//, 0.07};//propane - dataSet = database.getResultSet( - "SELECT * FROM LuciaData8 WHERE Component='nitrogen' AND ID>=1014 AND ID<=1045 AND Temperature<373.0");// AND - // ID<3000 - // AND - // Temperature>250 - // AND - // Pressure<7000000000 - // AND - // Temperature<600 - // AND - // Y<>NULL - // AND - // Y>0.0000000001 - // ORDER - // BY - // Temperature,Pressure");// - // AND - // Reference='Houghton1957' - // AND - // Reference<>'Nighswander1989' - // AND - // Temperature>278.15 - // AND - // Temperature<383.15 - // AND - // Pressure<60.01325"); - try { - int p = 0; - logger.info("adding...."); - while (dataSet.next() && p < 100) { - p++; - BinaryHVParameterFittingToSolubilityData function = - new BinaryHVParameterFittingToSolubilityData(0, 0); - SystemInterface testSystem = new SystemSrkSchwartzentruberEos( - Double.parseDouble(dataSet.getString("Temperature")), - Double.parseDouble(dataSet.getString("Pressure")) / 1e5); - testSystem.addComponent("nitrogen", 10.0); - testSystem.addComponent("water", 1000.0); - testSystem.setMixingRule("HV"); - testSystem.init(0); - double sample1[] = {testSystem.getPressure(), testSystem.getTemperature()}; - double standardDeviation1[] = {0.01}; - double val = 1.0 - Double.parseDouble(dataSet.getString("Y")); - double sdev = val / 100.0; - SampleValue sample = new SampleValue(val, sdev, sample1, standardDeviation1); - sample.setFunction(function); - sample.setThermodynamicSystem(testSystem); - sample.setReference(Double.toString(testSystem.getTemperature())); - double parameterGuess[] = {4898.64, -111.76};// , -0.1, -0.44};//, 0.07};//propane - function.setInitialGuess(parameterGuess); - sample.setDescription(Double.toString(testSystem.getTemperature())); - sampleList.add(sample); - } - } catch (Exception e) { - logger.error("database error" + e); - } - /* - * dataSet = database.getResultSet( - * "SELECT * FROM LuciaData8 WHERE Component='propane');// AND Temperature>270 AND Temperature<400 AND Pressure<700000000 AND L1<>NULL ORDER BY Temperature,Pressure" - * );// AND Reference='Houghton1957' AND Reference<>'Nighswander1989' AND Temperature>278.15 - * AND Temperature<383.15 AND Pressure<60.01325"); - * - * try{ int p=0; logger.info("adding...."); while(!dataSet.next() && p<10){ p++; - * BinaryHVParameterFittingToSolubilityData function = new - * BinaryHVParameterFittingToSolubilityData(0,0); - * - * SystemInterface testSystem = new - * SystemSrkSchwartzentruberEos(Double.parseDouble(dataSet.getString( "Temperature")), - * Double.parseDouble(dataSet.getString("Pressure"))/1e5); - * - * testSystem.addComponent("propane", 10.0); testSystem.addComponent("water", 10.0); - * - * //testSystem.createDatabase(true); testSystem.setMixingRule("HV"); - * - * testSystem.init(0); double sample1[] = {testSystem.getPressure(), - * testSystem.getTemperature()}; double standardDeviation1[] = {0.01}; // std.dev - * temperature double val = 1.0-Double.parseDouble(dataSet.getString("L1")); double sdev = - * val/100.0; SampleValue sample = new SampleValue(val, sdev, sample1, standardDeviation1); - * sample.setFunction(function); sample.setThermodynamicSystem(testSystem); - * sample.setReference(Double.toString(testSystem.getTemperature())); double - * parameterGuess[] ={3517,-1584, -0.1, -0.44, 0.07};//propane - * function.setInitialGuess(parameterGuess); sampleList.add(sample); } } catch(Exception e){ - * logger.error("database error" + e); } - */ - SampleSet sampleSet = new SampleSet(sampleList); - optim.setSampleSet(sampleSet); + function.setInitialGuess(parameterGuess); + sampleList.add(sample); + } + } catch (Exception e) { + logger.error("database error" + e); + } - // do simulations - optim.solve(); - // optim.runMonteCarloSimulation(); - // optim.displayResult(); - // optim.displayCurveFit(); - optim.displayResult(); - // optim.writeToCdfFile("c:/testFit.nc"); - // optim.writeToTextFile("c:/testFit.txt"); + dataSet = database.getResultSet( + "SELECT * FROM LuciaData8 WHERE Component='nitrogen' AND ID>=1014 AND ID<=1045 AND Temperature<373.0");// AND + // ID<3000 + // AND + // Temperature>250 + // AND + // Pressure<7000000000 + // AND + // Temperature<600 + // AND + // Y<>NULL + // AND + // Y>0.0000000001 + // ORDER + // BY + // Temperature,Pressure");// + // AND + // Reference='Houghton1957' + // AND + // Reference<>'Nighswander1989' + // AND + // Temperature>278.15 + // AND + // Temperature<383.15 + // AND + // Pressure<60.01325"); + try { + int p = 0; + logger.info("adding...."); + while (dataSet.next() && p < 100) { + p++; + BinaryHVParameterFittingToSolubilityData function = + new BinaryHVParameterFittingToSolubilityData(0, 0); + SystemInterface testSystem = + new SystemSrkSchwartzentruberEos(Double.parseDouble(dataSet.getString("Temperature")), + Double.parseDouble(dataSet.getString("Pressure")) / 1e5); + testSystem.addComponent("nitrogen", 10.0); + testSystem.addComponent("water", 1000.0); + testSystem.setMixingRule("HV"); + testSystem.init(0); + double sample1[] = {testSystem.getPressure(), testSystem.getTemperature()}; + double standardDeviation1[] = {0.01}; + double val = 1.0 - Double.parseDouble(dataSet.getString("Y")); + double sdev = val / 100.0; + SampleValue sample = new SampleValue(val, sdev, sample1, standardDeviation1); + sample.setFunction(function); + sample.setThermodynamicSystem(testSystem); + sample.setReference(Double.toString(testSystem.getTemperature())); + double parameterGuess[] = {4898.64, -111.76};// , -0.1, -0.44};//, 0.07};//propane + function.setInitialGuess(parameterGuess); + sample.setDescription(Double.toString(testSystem.getTemperature())); + sampleList.add(sample); + } + } catch (Exception e) { + logger.error("database error" + e); } + /* + * dataSet = database.getResultSet( + * "SELECT * FROM LuciaData8 WHERE Component='propane');// AND Temperature>270 AND Temperature<400 AND Pressure<700000000 AND L1<>NULL ORDER BY Temperature,Pressure" + * );// AND Reference='Houghton1957' AND Reference<>'Nighswander1989' AND Temperature>278.15 AND + * Temperature<383.15 AND Pressure<60.01325"); + * + * try{ int p=0; logger.info("adding...."); while(!dataSet.next() && p<10){ p++; + * BinaryHVParameterFittingToSolubilityData function = new + * BinaryHVParameterFittingToSolubilityData(0,0); + * + * SystemInterface testSystem = new + * SystemSrkSchwartzentruberEos(Double.parseDouble(dataSet.getString( "Temperature")), + * Double.parseDouble(dataSet.getString("Pressure"))/1e5); + * + * testSystem.addComponent("propane", 10.0); testSystem.addComponent("water", 10.0); + * + * //testSystem.createDatabase(true); testSystem.setMixingRule("HV"); + * + * testSystem.init(0); double sample1[] = {testSystem.getPressure(), + * testSystem.getTemperature()}; double standardDeviation1[] = {0.01}; // std.dev temperature + * double val = 1.0-Double.parseDouble(dataSet.getString("L1")); double sdev = val/100.0; + * SampleValue sample = new SampleValue(val, sdev, sample1, standardDeviation1); + * sample.setFunction(function); sample.setThermodynamicSystem(testSystem); + * sample.setReference(Double.toString(testSystem.getTemperature())); double parameterGuess[] + * ={3517,-1584, -0.1, -0.44, 0.07};//propane function.setInitialGuess(parameterGuess); + * sampleList.add(sample); } } catch(Exception e){ logger.error("database error" + e); } + */ + SampleSet sampleSet = new SampleSet(sampleList); + optim.setSampleSet(sampleSet); + + // do simulations + optim.solve(); + // optim.runMonteCarloSimulation(); + // optim.displayResult(); + // optim.displayCurveFit(); + optim.displayResult(); + // optim.writeToTextFile("c:/testFit.txt"); + } } diff --git a/src/main/java/neqsim/thermo/util/parameterFitting/binaryInteractionParameterFitting/HuronVidalParameterFitting/TestBinaryHVParameterFittingToSolubilityDatawaterCO2.java b/src/main/java/neqsim/thermo/util/parameterFitting/binaryInteractionParameterFitting/HuronVidalParameterFitting/TestBinaryHVParameterFittingToSolubilityDatawaterCO2.java index 0e001e4dff..878c16d8a2 100644 --- a/src/main/java/neqsim/thermo/util/parameterFitting/binaryInteractionParameterFitting/HuronVidalParameterFitting/TestBinaryHVParameterFittingToSolubilityDatawaterCO2.java +++ b/src/main/java/neqsim/thermo/util/parameterFitting/binaryInteractionParameterFitting/HuronVidalParameterFitting/TestBinaryHVParameterFittingToSolubilityDatawaterCO2.java @@ -20,121 +20,119 @@ * @version $Id: $Id */ public class TestBinaryHVParameterFittingToSolubilityDatawaterCO2 { - static Logger logger = - LogManager.getLogger(TestBinaryHVParameterFittingToSolubilityDatawaterCO2.class); + static Logger logger = + LogManager.getLogger(TestBinaryHVParameterFittingToSolubilityDatawaterCO2.class); - /** - *

- * main. - *

- * - * @param args an array of {@link java.lang.String} objects - */ - public static void main(String[] args) { - LevenbergMarquardt optim = new LevenbergMarquardt(); - ArrayList sampleList = new ArrayList(); + /** + *

+ * main. + *

+ * + * @param args an array of {@link java.lang.String} objects + */ + public static void main(String[] args) { + LevenbergMarquardt optim = new LevenbergMarquardt(); + ArrayList sampleList = new ArrayList(); - // inserting samples from database - NeqSimDataBase database = new NeqSimDataBase(); - // ResultSet dataSet = database.getResultSet( "SELECT * FROM CO2watersolubility - // WHERE pressureMPA<6 AND reference IN ('[18]', '[35]', '[36]', '[37]', '[38]', - // '[39]', '[40]', '[41]','[42]')"); + // inserting samples from database + NeqSimDataBase database = new NeqSimDataBase(); + // ResultSet dataSet = database.getResultSet( "SELECT * FROM CO2watersolubility + // WHERE pressureMPA<6 AND reference IN ('[18]', '[35]', '[36]', '[37]', '[38]', + // '[39]', '[40]', '[41]','[42]')"); - ResultSet dataSet = database.getResultSet( - "SELECT * FROM CO2watersolubility WHERE pressureMPA<5 AND reference IN ('[18]', '[35]', '[36]', '[37]', '[38]', '[39]', '[40]', '[41]','[42]', '[32]', '[33]', '[34]')"); + ResultSet dataSet = database.getResultSet( + "SELECT * FROM CO2watersolubility WHERE pressureMPA<5 AND reference IN ('[18]', '[35]', '[36]', '[37]', '[38]', '[39]', '[40]', '[41]','[42]', '[32]', '[33]', '[34]')"); - try { - int p = 0; - while (dataSet.next() && p < 550) { - p++; - BinaryHVParameterFittingToSolubilityData function = - new BinaryHVParameterFittingToSolubilityData(1, 10); + try { + int p = 0; + while (dataSet.next() && p < 550) { + p++; + BinaryHVParameterFittingToSolubilityData function = + new BinaryHVParameterFittingToSolubilityData(1, 10); - SystemInterface testSystem = new SystemSrkSchwartzentruberEos( - (Double.parseDouble(dataSet.getString("temperatureC")) + 273.15), - 10.0 * Double.parseDouble(dataSet.getString("pressureMPA"))); - // SystemInterface testSystem = new - // SystemSrkEos((Double.parseDouble(dataSet.getString("temperatureC"))+273.15), - // Double.parseDouble(dataSet.getString("pressurebar"))); - double valCO2 = Double.parseDouble(dataSet.getString("xCO2")); - testSystem.addComponent("CO2", valCO2); - testSystem.addComponent("water", 100.0 - valCO2); + SystemInterface testSystem = new SystemSrkSchwartzentruberEos( + (Double.parseDouble(dataSet.getString("temperatureC")) + 273.15), + 10.0 * Double.parseDouble(dataSet.getString("pressureMPA"))); + // SystemInterface testSystem = new + // SystemSrkEos((Double.parseDouble(dataSet.getString("temperatureC"))+273.15), + // Double.parseDouble(dataSet.getString("pressurebar"))); + double valCO2 = Double.parseDouble(dataSet.getString("xCO2")); + testSystem.addComponent("CO2", valCO2); + testSystem.addComponent("water", 100.0 - valCO2); - testSystem.createDatabase(true); - testSystem.setMixingRule("HV"); + testSystem.createDatabase(true); + testSystem.setMixingRule("HV"); - testSystem.init(0); - double sample1[] = {testSystem.getPressure(), testSystem.getTemperature()}; - double standardDeviation1[] = {0.01}; - double val = testSystem.getPressure(); - double sdev = val / 100.0; - SampleValue sample = new SampleValue(val, sdev, sample1, standardDeviation1); - sample.setFunction(function); - sample.setThermodynamicSystem(testSystem); - sample.setReference(Double.toString(testSystem.getTemperature())); - sample.setDescription(dataSet.getString("reference")); - // double parameterGuess[] = {5601.2391787479, -3170.8329162571, -1.7069851770, - // -0.5058509407}; // HV CO2 - double parameterGuess[] = - {5251.7374371982, -3121.2788585048, -0.8420253536, -0.5123316046}; - // double parameterGuess[] ={13694.7303713825, -807.1129937507, -10.4589547972, - // -10.9746096153}; - function.setInitialGuess(parameterGuess); - sampleList.add(sample); - logger.info("liq points " + p); - } - } catch (Exception e) { - logger.error("database error" + e); - } + testSystem.init(0); + double sample1[] = {testSystem.getPressure(), testSystem.getTemperature()}; + double standardDeviation1[] = {0.01}; + double val = testSystem.getPressure(); + double sdev = val / 100.0; + SampleValue sample = new SampleValue(val, sdev, sample1, standardDeviation1); + sample.setFunction(function); + sample.setThermodynamicSystem(testSystem); + sample.setReference(Double.toString(testSystem.getTemperature())); + sample.setDescription(dataSet.getString("reference")); + // double parameterGuess[] = {5601.2391787479, -3170.8329162571, -1.7069851770, + // -0.5058509407}; // HV CO2 + double parameterGuess[] = {5251.7374371982, -3121.2788585048, -0.8420253536, -0.5123316046}; + // double parameterGuess[] ={13694.7303713825, -807.1129937507, -10.4589547972, + // -10.9746096153}; + function.setInitialGuess(parameterGuess); + sampleList.add(sample); + logger.info("liq points " + p); + } + } catch (Exception e) { + logger.error("database error" + e); + } - dataSet = database.getResultSet( - "SELECT * FROM LuciaData8 WHERE Component='CO2' AND ID<3000 AND Temperature>250 AND Pressure<700000000 AND Temperature<420 AND Y<>NULL AND Y>0.0000000001 ORDER BY Temperature,Pressure"); + dataSet = database.getResultSet( + "SELECT * FROM LuciaData8 WHERE Component='CO2' AND ID<3000 AND Temperature>250 AND Pressure<700000000 AND Temperature<420 AND Y<>NULL AND Y>0.0000000001 ORDER BY Temperature,Pressure"); - try { - int p = 0; - while (!dataSet.next() && p < 100) { - p++; - BinaryHVParameterFittingToSolubilityData function = - new BinaryHVParameterFittingToSolubilityData(0, 0); + try { + int p = 0; + while (!dataSet.next() && p < 100) { + p++; + BinaryHVParameterFittingToSolubilityData function = + new BinaryHVParameterFittingToSolubilityData(0, 0); - SystemInterface testSystem = new SystemSrkSchwartzentruberEos( - Double.parseDouble(dataSet.getString("Temperature")), - Double.parseDouble(dataSet.getString("Pressure")) / 1e5); - testSystem.addComponent("CO2", 1.0); - testSystem.addComponent("water", 10.0); - testSystem.setMixingRule("HV"); + SystemInterface testSystem = + new SystemSrkSchwartzentruberEos(Double.parseDouble(dataSet.getString("Temperature")), + Double.parseDouble(dataSet.getString("Pressure")) / 1e5); + testSystem.addComponent("CO2", 1.0); + testSystem.addComponent("water", 10.0); + testSystem.setMixingRule("HV"); - testSystem.init(0); - double sample1[] = {testSystem.getPressure(), testSystem.getTemperature()}; - double standardDeviation1[] = {0.01}; - double val = 1.0 - Double.parseDouble(dataSet.getString("Y")); - double sdev = val / 100.0; - SampleValue sample = new SampleValue(val, sdev, sample1, standardDeviation1); - sample.setFunction(function); - sample.setThermodynamicSystem(testSystem); - sample.setReference(Double.toString(testSystem.getTemperature())); - // double parameterGuess[] = {5601.2391787479, -3170.8329162571, -1.7069851770, - // -0.5058509407}; // HV CO2 - double parameterGuess[] = {3626.0, -2241.0, 3.91, -3.16};// ; // HV CO2 - function.setInitialGuess(parameterGuess); - sample.setDescription(Double.toString(testSystem.getTemperature())); - sampleList.add(sample); - logger.info("gas points " + p); - } - } catch (Exception e) { - logger.error("database error" + e); - } + testSystem.init(0); + double sample1[] = {testSystem.getPressure(), testSystem.getTemperature()}; + double standardDeviation1[] = {0.01}; + double val = 1.0 - Double.parseDouble(dataSet.getString("Y")); + double sdev = val / 100.0; + SampleValue sample = new SampleValue(val, sdev, sample1, standardDeviation1); + sample.setFunction(function); + sample.setThermodynamicSystem(testSystem); + sample.setReference(Double.toString(testSystem.getTemperature())); + // double parameterGuess[] = {5601.2391787479, -3170.8329162571, -1.7069851770, + // -0.5058509407}; // HV CO2 + double parameterGuess[] = {3626.0, -2241.0, 3.91, -3.16};// ; // HV CO2 + function.setInitialGuess(parameterGuess); + sample.setDescription(Double.toString(testSystem.getTemperature())); + sampleList.add(sample); + logger.info("gas points " + p); + } + } catch (Exception e) { + logger.error("database error" + e); + } - SampleSet sampleSet = new SampleSet(sampleList); - optim.setSampleSet(sampleSet); + SampleSet sampleSet = new SampleSet(sampleList); + optim.setSampleSet(sampleSet); - // do simulations - // optim.solve(); - // optim.runMonteCarloSimulation(); - // optim.displayResult(); - optim.displayCurveFit(); - // optim.displayResult(); - // optim.writeToCdfFile("c:/testFit.nc"); - // optim.writeToTextFile("c:/testFit.txt"); - } + // do simulations + // optim.solve(); + // optim.runMonteCarloSimulation(); + // optim.displayResult(); + optim.displayCurveFit(); + // optim.displayResult(); + // optim.writeToTextFile("c:/testFit.txt"); + } } diff --git a/src/main/java/neqsim/thermo/util/parameterFitting/binaryInteractionParameterFitting/HuronVidalParameterFitting/TestBinaryUMRPRUFittingToSolubilityData.java b/src/main/java/neqsim/thermo/util/parameterFitting/binaryInteractionParameterFitting/HuronVidalParameterFitting/TestBinaryUMRPRUFittingToSolubilityData.java index 1d24765025..12b94111c5 100644 --- a/src/main/java/neqsim/thermo/util/parameterFitting/binaryInteractionParameterFitting/HuronVidalParameterFitting/TestBinaryUMRPRUFittingToSolubilityData.java +++ b/src/main/java/neqsim/thermo/util/parameterFitting/binaryInteractionParameterFitting/HuronVidalParameterFitting/TestBinaryUMRPRUFittingToSolubilityData.java @@ -20,284 +20,283 @@ * @version $Id: $Id */ public class TestBinaryUMRPRUFittingToSolubilityData { - static Logger logger = LogManager.getLogger(TestBinaryUMRPRUFittingToSolubilityData.class); - - /** - *

- * main. - *

- * - * @param args an array of {@link java.lang.String} objects - */ - public static void main(String[] args) { - LevenbergMarquardt optim = new LevenbergMarquardt(); - ArrayList sampleList = new ArrayList(); - - NeqSimDataBase database = new NeqSimDataBase(); - ResultSet dataSet = database.getResultSet( - "SELECT * FROM binarySolubilityData WHERE ComponentSolute='Hg' AND ComponentSolvent='n-decane'"); - - double parameterGuess[] = {188.385052774267, -0.84022345};// , 2630.871733876947}; - - try { - int p = 0; - logger.info("adding...."); - while (dataSet.next() && p < 31) { - p++; - UMRPRUFunction function = new UMRPRUFunction(); - SystemInterface testSystem = new SystemUMRPRUMCEos(290, 1.0); - testSystem.addComponent("nC10", 10.0); - testSystem.addComponent("mercury", 1.0); - - testSystem.createDatabase(true); - testSystem.setMixingRule("HV", "UNIFAC_UMRPRU"); - - testSystem.setTemperature(Double.parseDouble(dataSet.getString("Temperature"))); - testSystem.setPressure(Double.parseDouble(dataSet.getString("Pressure"))); - logger.info("pressure " + testSystem.getPressure()); - testSystem.init(0); - double sample1[] = {testSystem.getPressure(), testSystem.getTemperature()}; - double standardDeviation1[] = {0.01}; - - SampleValue sample = new SampleValue(Double.parseDouble(dataSet.getString("x1")), - Double.parseDouble(dataSet.getString("StandardDeviation")), sample1, - standardDeviation1); - sample.setFunction(function); - sample.setThermodynamicSystem(testSystem); - sample.setReference(Double.toString(testSystem.getTemperature())); - function.setInitialGuess(parameterGuess); - sampleList.add(sample); - } - } catch (Exception e) { - logger.error("database error" + e); - } - - dataSet = database.getResultSet( - "SELECT * FROM binarySolubilityData WHERE ComponentSolute='Hg' AND ComponentSolvent='n-heptane'"); - - try { - int p = 0; - logger.info("adding...."); - while (dataSet.next() && p < 60) { - p++; - UMRPRUFunction function = new UMRPRUFunction(); - SystemInterface testSystem = new SystemUMRPRUMCEos(290, 1.0); - testSystem.addComponent("n-heptane", 10.0); - testSystem.addComponent("mercury", 1.0); - - testSystem.createDatabase(true); - testSystem.setMixingRule("HV", "UNIFAC_UMRPRU"); - - testSystem.setTemperature(Double.parseDouble(dataSet.getString("Temperature"))); - testSystem.setPressure(Double.parseDouble(dataSet.getString("Pressure"))); - logger.info("pressure " + testSystem.getPressure()); - testSystem.init(0); - double sample1[] = {testSystem.getPressure(), testSystem.getTemperature()}; - double standardDeviation1[] = {0.01}; - - SampleValue sample = new SampleValue(Double.parseDouble(dataSet.getString("x1")), - Double.parseDouble(dataSet.getString("StandardDeviation")), sample1, - standardDeviation1); - sample.setFunction(function); - sample.setThermodynamicSystem(testSystem); - sample.setReference(Double.toString(testSystem.getTemperature())); - function.setInitialGuess(parameterGuess); - sampleList.add(sample); - } - } catch (Exception e) { - logger.error("database error" + e); - } - - dataSet = database.getResultSet( - "SELECT * FROM binarySolubilityData WHERE ComponentSolute='Hg' AND ComponentSolvent='n-octane'"); - - try { - int p = 0; - logger.info("adding...."); - while (dataSet.next() && p < 50) { - p++; - UMRPRUFunction function = new UMRPRUFunction(); - SystemInterface testSystem = new SystemUMRPRUMCEos(290, 1.0); - testSystem.addComponent("n-octane", 10.0); - testSystem.addComponent("mercury", 1.0); - - testSystem.createDatabase(true); - testSystem.setMixingRule("HV", "UNIFAC_UMRPRU"); - - testSystem.setTemperature(Double.parseDouble(dataSet.getString("Temperature"))); - testSystem.setPressure(Double.parseDouble(dataSet.getString("Pressure"))); - logger.info("pressure " + testSystem.getPressure()); - testSystem.init(0); - double sample1[] = {testSystem.getPressure(), testSystem.getTemperature()}; - double standardDeviation1[] = {0.01}; - - SampleValue sample = new SampleValue(Double.parseDouble(dataSet.getString("x1")), - Double.parseDouble(dataSet.getString("StandardDeviation")), sample1, - standardDeviation1); - sample.setFunction(function); - sample.setThermodynamicSystem(testSystem); - sample.setReference(Double.toString(testSystem.getTemperature())); - function.setInitialGuess(parameterGuess); - sampleList.add(sample); - } - } catch (Exception e) { - logger.info("database error" + e); - } - - dataSet = database.getResultSet( - "SELECT * FROM binarySolubilityData WHERE ComponentSolute='Hg' AND ComponentSolvent='n-hexane'"); - - try { - int p = 0; - logger.error("adding...."); - while (dataSet.next() && p < 30) { - p++; - UMRPRUFunction function = new UMRPRUFunction(); - SystemInterface testSystem = new SystemUMRPRUMCEos(290, 1.0); - testSystem.addComponent("n-hexane", 10.0); - testSystem.addComponent("mercury", 1.0); - - testSystem.createDatabase(true); - testSystem.setMixingRule("HV", "UNIFAC_UMRPRU"); - - testSystem.setTemperature(Double.parseDouble(dataSet.getString("Temperature"))); - testSystem.setPressure(Double.parseDouble(dataSet.getString("Pressure"))); - logger.info("pressure " + testSystem.getPressure()); - testSystem.init(0); - double sample1[] = {testSystem.getPressure(), testSystem.getTemperature()}; - double standardDeviation1[] = {0.01}; - - SampleValue sample = new SampleValue(Double.parseDouble(dataSet.getString("x1")), - Double.parseDouble(dataSet.getString("StandardDeviation")), sample1, - standardDeviation1); - sample.setFunction(function); - sample.setThermodynamicSystem(testSystem); - sample.setReference(Double.toString(testSystem.getTemperature())); - function.setInitialGuess(parameterGuess); - sampleList.add(sample); - } - } catch (Exception e) { - logger.error("database error" + e); - } - - dataSet = database.getResultSet( - "SELECT * FROM binarySolubilityData WHERE ComponentSolute='Hg' AND ComponentSolvent='n-pentane'"); - - try { - int p = 0; - logger.info("adding...."); - while (dataSet.next() && p < 30) { - p++; - UMRPRUFunction function = new UMRPRUFunction(); - SystemInterface testSystem = new SystemUMRPRUMCEos(290, 1.0); - testSystem.addComponent("n-pentane", 10.0); - testSystem.addComponent("mercury", 1.0); - - testSystem.createDatabase(true); - testSystem.setMixingRule("HV", "UNIFAC_UMRPRU"); - - testSystem.setTemperature(Double.parseDouble(dataSet.getString("Temperature"))); - testSystem.setPressure(Double.parseDouble(dataSet.getString("Pressure"))); - logger.info("pressure " + testSystem.getPressure()); - testSystem.init(0); - double sample1[] = {testSystem.getPressure(), testSystem.getTemperature()}; - double standardDeviation1[] = {0.01}; - - SampleValue sample = new SampleValue(Double.parseDouble(dataSet.getString("x1")), - Double.parseDouble(dataSet.getString("StandardDeviation")), sample1, - standardDeviation1); - sample.setFunction(function); - sample.setThermodynamicSystem(testSystem); - sample.setReference(Double.toString(testSystem.getTemperature())); - function.setInitialGuess(parameterGuess); - sampleList.add(sample); - } - } catch (Exception e) { - logger.error("database error" + e); - } - - dataSet = database.getResultSet( - "SELECT * FROM binarySolubilityData WHERE ComponentSolute='Hg' AND ComponentSolvent='butane'"); - - try { - int p = 0; - logger.info("adding...."); - while (dataSet.next() && p < 30) { - p++; - UMRPRUFunction function = new UMRPRUFunction(); - SystemInterface testSystem = new SystemUMRPRUMCEos(290, 1.0); - testSystem.addComponent("n-butane", 10.0); - testSystem.addComponent("mercury", 1.0); - - testSystem.createDatabase(true); - testSystem.setMixingRule("HV", "UNIFAC_UMRPRU"); - - testSystem.setTemperature(Double.parseDouble(dataSet.getString("Temperature"))); - testSystem.setPressure(Double.parseDouble(dataSet.getString("Pressure"))); - logger.info("pressure " + testSystem.getPressure()); - testSystem.init(0); - double sample1[] = {testSystem.getPressure(), testSystem.getTemperature()}; - double standardDeviation1[] = {0.01}; - - SampleValue sample = new SampleValue(Double.parseDouble(dataSet.getString("x1")), - Double.parseDouble(dataSet.getString("StandardDeviation")), sample1, - standardDeviation1); - sample.setFunction(function); - sample.setThermodynamicSystem(testSystem); - sample.setReference(Double.toString(testSystem.getTemperature())); - function.setInitialGuess(parameterGuess); - sampleList.add(sample); - } - } catch (Exception e) { - logger.error("database error" + e); - } - - dataSet = database.getResultSet( - "SELECT * FROM binarySolubilityData WHERE ComponentSolute='Hg' AND ComponentSolvent='propane'"); - - try { - int p = 0; - logger.info("adding...."); - while (dataSet.next() && p < 30) { - p++; - UMRPRUFunction function = new UMRPRUFunction(); - SystemInterface testSystem = new SystemUMRPRUMCEos(290, 1.0); - testSystem.addComponent("propane", 10.0); - testSystem.addComponent("mercury", 1.0); - - testSystem.createDatabase(true); - testSystem.setMixingRule("HV", "UNIFAC_UMRPRU"); - - testSystem.setTemperature(Double.parseDouble(dataSet.getString("Temperature"))); - testSystem.setPressure(Double.parseDouble(dataSet.getString("Pressure"))); - logger.info("pressure " + testSystem.getPressure()); - testSystem.init(0); - double sample1[] = {testSystem.getPressure(), testSystem.getTemperature()}; - double standardDeviation1[] = {0.01}; - - SampleValue sample = new SampleValue(Double.parseDouble(dataSet.getString("x1")), - Double.parseDouble(dataSet.getString("StandardDeviation")), sample1, - standardDeviation1); - sample.setFunction(function); - sample.setThermodynamicSystem(testSystem); - sample.setReference(Double.toString(testSystem.getTemperature())); - function.setInitialGuess(parameterGuess); - sampleList.add(sample); - } - } catch (Exception e) { - logger.error("database error" + e); - } - - SampleSet sampleSet = new SampleSet(sampleList); - optim.setSampleSet(sampleSet); - - // do simulations - optim.solve(); - // optim.runMonteCarloSimulation(); - // optim.displayResult(); - optim.displayCurveFit(); - optim.displayResult(); - // optim.writeToCdfFile("c:/testFit.nc"); - // optim.writeToTextFile("c:/testFit.txt"); + static Logger logger = LogManager.getLogger(TestBinaryUMRPRUFittingToSolubilityData.class); + + /** + *

+ * main. + *

+ * + * @param args an array of {@link java.lang.String} objects + */ + public static void main(String[] args) { + LevenbergMarquardt optim = new LevenbergMarquardt(); + ArrayList sampleList = new ArrayList(); + + NeqSimDataBase database = new NeqSimDataBase(); + ResultSet dataSet = database.getResultSet( + "SELECT * FROM binarySolubilityData WHERE ComponentSolute='Hg' AND ComponentSolvent='n-decane'"); + + double parameterGuess[] = {188.385052774267, -0.84022345};// , 2630.871733876947}; + + try { + int p = 0; + logger.info("adding...."); + while (dataSet.next() && p < 31) { + p++; + UMRPRUFunction function = new UMRPRUFunction(); + SystemInterface testSystem = new SystemUMRPRUMCEos(290, 1.0); + testSystem.addComponent("nC10", 10.0); + testSystem.addComponent("mercury", 1.0); + + testSystem.createDatabase(true); + testSystem.setMixingRule("HV", "UNIFAC_UMRPRU"); + + testSystem.setTemperature(Double.parseDouble(dataSet.getString("Temperature"))); + testSystem.setPressure(Double.parseDouble(dataSet.getString("Pressure"))); + logger.info("pressure " + testSystem.getPressure()); + testSystem.init(0); + double sample1[] = {testSystem.getPressure(), testSystem.getTemperature()}; + double standardDeviation1[] = {0.01}; + + SampleValue sample = new SampleValue(Double.parseDouble(dataSet.getString("x1")), + Double.parseDouble(dataSet.getString("StandardDeviation")), sample1, + standardDeviation1); + sample.setFunction(function); + sample.setThermodynamicSystem(testSystem); + sample.setReference(Double.toString(testSystem.getTemperature())); + function.setInitialGuess(parameterGuess); + sampleList.add(sample); + } + } catch (Exception e) { + logger.error("database error" + e); } + + dataSet = database.getResultSet( + "SELECT * FROM binarySolubilityData WHERE ComponentSolute='Hg' AND ComponentSolvent='n-heptane'"); + + try { + int p = 0; + logger.info("adding...."); + while (dataSet.next() && p < 60) { + p++; + UMRPRUFunction function = new UMRPRUFunction(); + SystemInterface testSystem = new SystemUMRPRUMCEos(290, 1.0); + testSystem.addComponent("n-heptane", 10.0); + testSystem.addComponent("mercury", 1.0); + + testSystem.createDatabase(true); + testSystem.setMixingRule("HV", "UNIFAC_UMRPRU"); + + testSystem.setTemperature(Double.parseDouble(dataSet.getString("Temperature"))); + testSystem.setPressure(Double.parseDouble(dataSet.getString("Pressure"))); + logger.info("pressure " + testSystem.getPressure()); + testSystem.init(0); + double sample1[] = {testSystem.getPressure(), testSystem.getTemperature()}; + double standardDeviation1[] = {0.01}; + + SampleValue sample = new SampleValue(Double.parseDouble(dataSet.getString("x1")), + Double.parseDouble(dataSet.getString("StandardDeviation")), sample1, + standardDeviation1); + sample.setFunction(function); + sample.setThermodynamicSystem(testSystem); + sample.setReference(Double.toString(testSystem.getTemperature())); + function.setInitialGuess(parameterGuess); + sampleList.add(sample); + } + } catch (Exception e) { + logger.error("database error" + e); + } + + dataSet = database.getResultSet( + "SELECT * FROM binarySolubilityData WHERE ComponentSolute='Hg' AND ComponentSolvent='n-octane'"); + + try { + int p = 0; + logger.info("adding...."); + while (dataSet.next() && p < 50) { + p++; + UMRPRUFunction function = new UMRPRUFunction(); + SystemInterface testSystem = new SystemUMRPRUMCEos(290, 1.0); + testSystem.addComponent("n-octane", 10.0); + testSystem.addComponent("mercury", 1.0); + + testSystem.createDatabase(true); + testSystem.setMixingRule("HV", "UNIFAC_UMRPRU"); + + testSystem.setTemperature(Double.parseDouble(dataSet.getString("Temperature"))); + testSystem.setPressure(Double.parseDouble(dataSet.getString("Pressure"))); + logger.info("pressure " + testSystem.getPressure()); + testSystem.init(0); + double sample1[] = {testSystem.getPressure(), testSystem.getTemperature()}; + double standardDeviation1[] = {0.01}; + + SampleValue sample = new SampleValue(Double.parseDouble(dataSet.getString("x1")), + Double.parseDouble(dataSet.getString("StandardDeviation")), sample1, + standardDeviation1); + sample.setFunction(function); + sample.setThermodynamicSystem(testSystem); + sample.setReference(Double.toString(testSystem.getTemperature())); + function.setInitialGuess(parameterGuess); + sampleList.add(sample); + } + } catch (Exception e) { + logger.info("database error" + e); + } + + dataSet = database.getResultSet( + "SELECT * FROM binarySolubilityData WHERE ComponentSolute='Hg' AND ComponentSolvent='n-hexane'"); + + try { + int p = 0; + logger.error("adding...."); + while (dataSet.next() && p < 30) { + p++; + UMRPRUFunction function = new UMRPRUFunction(); + SystemInterface testSystem = new SystemUMRPRUMCEos(290, 1.0); + testSystem.addComponent("n-hexane", 10.0); + testSystem.addComponent("mercury", 1.0); + + testSystem.createDatabase(true); + testSystem.setMixingRule("HV", "UNIFAC_UMRPRU"); + + testSystem.setTemperature(Double.parseDouble(dataSet.getString("Temperature"))); + testSystem.setPressure(Double.parseDouble(dataSet.getString("Pressure"))); + logger.info("pressure " + testSystem.getPressure()); + testSystem.init(0); + double sample1[] = {testSystem.getPressure(), testSystem.getTemperature()}; + double standardDeviation1[] = {0.01}; + + SampleValue sample = new SampleValue(Double.parseDouble(dataSet.getString("x1")), + Double.parseDouble(dataSet.getString("StandardDeviation")), sample1, + standardDeviation1); + sample.setFunction(function); + sample.setThermodynamicSystem(testSystem); + sample.setReference(Double.toString(testSystem.getTemperature())); + function.setInitialGuess(parameterGuess); + sampleList.add(sample); + } + } catch (Exception e) { + logger.error("database error" + e); + } + + dataSet = database.getResultSet( + "SELECT * FROM binarySolubilityData WHERE ComponentSolute='Hg' AND ComponentSolvent='n-pentane'"); + + try { + int p = 0; + logger.info("adding...."); + while (dataSet.next() && p < 30) { + p++; + UMRPRUFunction function = new UMRPRUFunction(); + SystemInterface testSystem = new SystemUMRPRUMCEos(290, 1.0); + testSystem.addComponent("n-pentane", 10.0); + testSystem.addComponent("mercury", 1.0); + + testSystem.createDatabase(true); + testSystem.setMixingRule("HV", "UNIFAC_UMRPRU"); + + testSystem.setTemperature(Double.parseDouble(dataSet.getString("Temperature"))); + testSystem.setPressure(Double.parseDouble(dataSet.getString("Pressure"))); + logger.info("pressure " + testSystem.getPressure()); + testSystem.init(0); + double sample1[] = {testSystem.getPressure(), testSystem.getTemperature()}; + double standardDeviation1[] = {0.01}; + + SampleValue sample = new SampleValue(Double.parseDouble(dataSet.getString("x1")), + Double.parseDouble(dataSet.getString("StandardDeviation")), sample1, + standardDeviation1); + sample.setFunction(function); + sample.setThermodynamicSystem(testSystem); + sample.setReference(Double.toString(testSystem.getTemperature())); + function.setInitialGuess(parameterGuess); + sampleList.add(sample); + } + } catch (Exception e) { + logger.error("database error" + e); + } + + dataSet = database.getResultSet( + "SELECT * FROM binarySolubilityData WHERE ComponentSolute='Hg' AND ComponentSolvent='butane'"); + + try { + int p = 0; + logger.info("adding...."); + while (dataSet.next() && p < 30) { + p++; + UMRPRUFunction function = new UMRPRUFunction(); + SystemInterface testSystem = new SystemUMRPRUMCEos(290, 1.0); + testSystem.addComponent("n-butane", 10.0); + testSystem.addComponent("mercury", 1.0); + + testSystem.createDatabase(true); + testSystem.setMixingRule("HV", "UNIFAC_UMRPRU"); + + testSystem.setTemperature(Double.parseDouble(dataSet.getString("Temperature"))); + testSystem.setPressure(Double.parseDouble(dataSet.getString("Pressure"))); + logger.info("pressure " + testSystem.getPressure()); + testSystem.init(0); + double sample1[] = {testSystem.getPressure(), testSystem.getTemperature()}; + double standardDeviation1[] = {0.01}; + + SampleValue sample = new SampleValue(Double.parseDouble(dataSet.getString("x1")), + Double.parseDouble(dataSet.getString("StandardDeviation")), sample1, + standardDeviation1); + sample.setFunction(function); + sample.setThermodynamicSystem(testSystem); + sample.setReference(Double.toString(testSystem.getTemperature())); + function.setInitialGuess(parameterGuess); + sampleList.add(sample); + } + } catch (Exception e) { + logger.error("database error" + e); + } + + dataSet = database.getResultSet( + "SELECT * FROM binarySolubilityData WHERE ComponentSolute='Hg' AND ComponentSolvent='propane'"); + + try { + int p = 0; + logger.info("adding...."); + while (dataSet.next() && p < 30) { + p++; + UMRPRUFunction function = new UMRPRUFunction(); + SystemInterface testSystem = new SystemUMRPRUMCEos(290, 1.0); + testSystem.addComponent("propane", 10.0); + testSystem.addComponent("mercury", 1.0); + + testSystem.createDatabase(true); + testSystem.setMixingRule("HV", "UNIFAC_UMRPRU"); + + testSystem.setTemperature(Double.parseDouble(dataSet.getString("Temperature"))); + testSystem.setPressure(Double.parseDouble(dataSet.getString("Pressure"))); + logger.info("pressure " + testSystem.getPressure()); + testSystem.init(0); + double sample1[] = {testSystem.getPressure(), testSystem.getTemperature()}; + double standardDeviation1[] = {0.01}; + + SampleValue sample = new SampleValue(Double.parseDouble(dataSet.getString("x1")), + Double.parseDouble(dataSet.getString("StandardDeviation")), sample1, + standardDeviation1); + sample.setFunction(function); + sample.setThermodynamicSystem(testSystem); + sample.setReference(Double.toString(testSystem.getTemperature())); + function.setInitialGuess(parameterGuess); + sampleList.add(sample); + } + } catch (Exception e) { + logger.error("database error" + e); + } + + SampleSet sampleSet = new SampleSet(sampleList); + optim.setSampleSet(sampleSet); + + // do simulations + optim.solve(); + // optim.runMonteCarloSimulation(); + // optim.displayResult(); + optim.displayCurveFit(); + optim.displayResult(); + // optim.writeToTextFile("c:/testFit.txt"); + } } diff --git a/src/main/java/neqsim/thermo/util/parameterFitting/binaryInteractionParameterFitting/HuronVidalParameterFitting/TestBinaryWSParameterFittingToSolubilityData_Lucia.java b/src/main/java/neqsim/thermo/util/parameterFitting/binaryInteractionParameterFitting/HuronVidalParameterFitting/TestBinaryWSParameterFittingToSolubilityData_Lucia.java index 9dd76cf3be..f3d7b244c1 100644 --- a/src/main/java/neqsim/thermo/util/parameterFitting/binaryInteractionParameterFitting/HuronVidalParameterFitting/TestBinaryWSParameterFittingToSolubilityData_Lucia.java +++ b/src/main/java/neqsim/thermo/util/parameterFitting/binaryInteractionParameterFitting/HuronVidalParameterFitting/TestBinaryWSParameterFittingToSolubilityData_Lucia.java @@ -20,191 +20,192 @@ * @version $Id: $Id */ public class TestBinaryWSParameterFittingToSolubilityData_Lucia { - static Logger logger = - LogManager.getLogger(TestBinaryWSParameterFittingToSolubilityData_Lucia.class); - - /** - *

- * main. - *

- * - * @param args an array of {@link java.lang.String} objects - */ - public static void main(String[] args) { - LevenbergMarquardt optim = new LevenbergMarquardt(); - ArrayList sampleList = new ArrayList(); - - // inserting samples from database - NeqSimDataBase database = new NeqSimDataBase(); - ResultSet dataSet = database.getResultSet( - "SELECT * FROM LuciaData WHERE Component='methane' AND Temperature<520 AND L2<>NULL AND L2>0.00000001 ORDER BY Temperature,Pressure");// AND - // Reference='Houghton1957' - // AND - // Reference<>'Nighswander1989' - // AND - // Temperature>278.15 - // AND - // Temperature<383.15 - // AND - // Pressure<60.01325"); - // ResultSet dataSet = database.getResultSet( "SELECT * FROM LuciaData WHERE - // Component='CO2' AND Temperature>250 AND Temperature<420 AND L2<>NULL AND - // L2>0.00000001 ORDER BY Temperature,Pressure");// AND Reference='Houghton1957' - // AND Reference<>'Nighswander1989' AND Temperature>278.15 AND - // Temperature<383.15 AND Pressure<60.01325"); - - try { - int p = 0; - while (dataSet.next() && p < 100) { - p++; - BinaryWSParameterFittingToSolubilityData function = - new BinaryWSParameterFittingToSolubilityData(); - - // SystemInterface testSystem = new SystemFurstElectrolyteEos(280, 1.0); - SystemInterface testSystem = new SystemSrkSchwartzentruberEos( - Double.parseDouble(dataSet.getString("Temperature")), - Double.parseDouble(dataSet.getString("Pressure")) / 1e5); - // SystemInterface testSystem = new - // SystemSrkEos(Double.parseDouble(dataSet.getString("Temperature")), - // Double.parseDouble(dataSet.getString("Pressure"))/1e5); - // SystemInterface testSystem = new - // SystemPrEos(Double.parseDouble(dataSet.getString("Temperature")), - // Double.parseDouble(dataSet.getString("Pressure"))/1e5); - - // testSystem.addComponent("CO2", 10.0); - testSystem.addComponent("methane", 10.0); - testSystem.addComponent("water", 10.0); - - // testSystem.addComponent("CO2", 1.0); - // testSystem.addComponent("water", 1.0); - // testSystem.addComponent("MDEA", 1.000001); - // testSystem.chemicalReactionInit(); - // testSystem.createDatabase(true); - testSystem.setMixingRule(5); - - // testSystem.getChemicalReactionOperations().solveChemEq(0); - // testSystem.getChemicalReactionOperations().solveChemEq(1); - - // testSystem.isChemicalSystem(false); - - // testSystem.addComponent("NaPlus", 1.0e-10); - // testSystem.addComponent("methane", 1.1); - testSystem.init(0); - double sample1[] = {testSystem.getPressure(), testSystem.getTemperature()}; - double standardDeviation1[] = {0.01}; - double val = Double.parseDouble(dataSet.getString("L2")); - double sdev = val / 100.0; - SampleValue sample = new SampleValue(val, sdev, sample1, standardDeviation1); - sample.setFunction(function); - sample.setThermodynamicSystem(testSystem); - sample.setReference(Double.toString(testSystem.getTemperature())); - // double parameterGuess[] = {3932.0, -4127.0, -5.89, 8.9}; // HV CO2 - double parameterGuess[] = {4802.7795779589, -440.6638711230, -7.6109236981, - 4.8742002317, 0.1, -0.0420817811}; // HV methan570 - // double parameterGuess[] = {3204.3057406886, -2753.7379912645, -12.4728330162 - // , 13.0150379323}; // HV - // double parameterGuess[] = {8.992E3, -3.244E3, -8.424E0, -1.824E0}; // HV - // double parameterGuess[] = {-7.132E2, -3.933E2};//, 3.96E0, 9.602E-1}; //, - // 1.239}; //WS - function.setInitialGuess(parameterGuess); - sampleList.add(sample); - } - } catch (Exception e) { - logger.error("database error" + e); - } - - dataSet = database.getResultSet( - "SELECT * FROM LuciaData WHERE Component='methane' AND ID<3000 AND Temperature<520 AND Y<>NULL AND Y>0.00000001 ORDER BY Temperature,Pressure");// AND - // Reference='Houghton1957' - // AND - // Reference<>'Nighswander1989' - // AND - // Temperature>278.15 - // AND - // Temperature<383.15 - // AND - // Pressure<60.01325"); - // dataSet = database.getResultSet( "SELECT * FROM LuciaData WHERE - // Component='CO2' AND ID<3000 AND Temperature>250 AND Temperature<420 AND - // Y<>NULL AND Y>0.00000001 ORDER BY Temperature,Pressure");// AND - // Reference='Houghton1957' AND Reference<>'Nighswander1989' AND - // Temperature>278.15 AND Temperature<383.15 AND Pressure<60.01325"); - - // ResultSet dataSet = database.getResultSet( "SELECT * FROM - // activityCoefficientTable WHERE Component1='MDEA' AND Component2='water'"); - // testSystem.addComponent(dataSet.getString("ComponentSolute"), 1.0); - // testSystem.addComponent(dataSet.getString("ComponentSolvent"), 1.0); - try { - int p = 0; - while (dataSet.next() && p < 100) { - p++; - BinaryWSParameterFittingToSolubilityData function = - new BinaryWSParameterFittingToSolubilityData(0, 0); - - // SystemInterface testSystem = new - // SystemFurstElectrolyteEos(Double.parseDouble(dataSet.getString("Temperature")), - // Double.parseDouble(dataSet.getString("Pressure"))/1e5); - SystemInterface testSystem = new SystemSrkSchwartzentruberEos( - Double.parseDouble(dataSet.getString("Temperature")), - Double.parseDouble(dataSet.getString("Pressure")) / 1e5); - // SystemInterface testSystem = new - // SystemSrkEos(Double.parseDouble(dataSet.getString("Temperature")), - // Double.parseDouble(dataSet.getString("Pressure"))/1e5); - // SystemInterface testSystem = new - // SystemPrEos(Double.parseDouble(dataSet.getString("Temperature")), - // Double.parseDouble(dataSet.getString("Pressure"))/1e5); - // testSystem.addComponent("CO2", 10.0); - testSystem.addComponent("methane", 10.0); - testSystem.addComponent("water", 10.0); - - // testSystem.addComponent("CO2", 1.0); - // testSystem.addComponent("water", 1.0); - // testSystem.addComponent("MDEA", 1.000001); - // testSystem.chemicalReactionInit(); - // testSystem.createDatabase(true); - testSystem.setMixingRule(5); - - // testSystem.getChemicalReactionOperations().solveChemEq(0); - // testSystem.getChemicalReactionOperations().solveChemEq(1); - - // testSystem.isChemicalSystem(false); - - // testSystem.addComponent("NaPlus", 1.0e-10); - // testSystem.addComponent("methane", 1.1); - testSystem.init(0); - double sample1[] = {testSystem.getPressure(), testSystem.getTemperature()}; - double standardDeviation1[] = {0.01}; - double val = 1.0 - Double.parseDouble(dataSet.getString("Y")); - double sdev = val / 100.0; - SampleValue sample = new SampleValue(val, sdev, sample1, standardDeviation1); - sample.setFunction(function); - sample.setThermodynamicSystem(testSystem); - sample.setReference(Double.toString(testSystem.getTemperature())); - // double parameterGuess[] = {3932.0, -4127.0, -5.89, 8.9}; // HV CO2 - double parameterGuess[] = {4802.7795779589, -440.6638711230, -7.6109236981, - 4.8742002317, 0.1, -0.0420817811}; // HV methan570 - // double parameterGuess[] = {3204.3057406886, -2753.7379912645, -12.4728330162 - // , 13.0150379323}; // HV - // double parameterGuess[] = {8.992E3, -3.244E3, -8.424E0, -1.824E0}; // HV - // double parameterGuess[] = {-7.132E2, -3.933E2};//, 3.96E0, 9.602E-1}; //, - // 1.239}; //WS - function.setInitialGuess(parameterGuess); - sampleList.add(sample); - } - } catch (Exception e) { - logger.error("database error" + e); - } - - SampleSet sampleSet = new SampleSet(sampleList); - optim.setSampleSet(sampleSet); - - // do simulations - optim.solve(); - // optim.runMonteCarloSimulation(); - // optim.displayResult(); - optim.displayCurveFit(); - optim.displayResult(); - // optim.writeToCdfFile("c:/testFit.nc"); - // optim.writeToTextFile("c:/testFit.txt"); + static Logger logger = + LogManager.getLogger(TestBinaryWSParameterFittingToSolubilityData_Lucia.class); + + /** + *

+ * main. + *

+ * + * @param args an array of {@link java.lang.String} objects + */ + public static void main(String[] args) { + LevenbergMarquardt optim = new LevenbergMarquardt(); + ArrayList sampleList = new ArrayList(); + + // inserting samples from database + NeqSimDataBase database = new NeqSimDataBase(); + ResultSet dataSet = database.getResultSet( + "SELECT * FROM LuciaData WHERE Component='methane' AND Temperature<520 AND L2<>NULL AND L2>0.00000001 ORDER BY Temperature,Pressure");// AND + // Reference='Houghton1957' + // AND + // Reference<>'Nighswander1989' + // AND + // Temperature>278.15 + // AND + // Temperature<383.15 + // AND + // Pressure<60.01325"); + // ResultSet dataSet = database.getResultSet( "SELECT * FROM LuciaData WHERE + // Component='CO2' AND Temperature>250 AND Temperature<420 AND L2<>NULL AND + // L2>0.00000001 ORDER BY Temperature,Pressure");// AND Reference='Houghton1957' + // AND Reference<>'Nighswander1989' AND Temperature>278.15 AND + // Temperature<383.15 AND Pressure<60.01325"); + + try { + int p = 0; + while (dataSet.next() && p < 100) { + p++; + BinaryWSParameterFittingToSolubilityData function = + new BinaryWSParameterFittingToSolubilityData(); + + // SystemInterface testSystem = new SystemFurstElectrolyteEos(280, 1.0); + SystemInterface testSystem = + new SystemSrkSchwartzentruberEos(Double.parseDouble(dataSet.getString("Temperature")), + Double.parseDouble(dataSet.getString("Pressure")) / 1e5); + // SystemInterface testSystem = new + // SystemSrkEos(Double.parseDouble(dataSet.getString("Temperature")), + // Double.parseDouble(dataSet.getString("Pressure"))/1e5); + // SystemInterface testSystem = new + // SystemPrEos(Double.parseDouble(dataSet.getString("Temperature")), + // Double.parseDouble(dataSet.getString("Pressure"))/1e5); + + // testSystem.addComponent("CO2", 10.0); + testSystem.addComponent("methane", 10.0); + testSystem.addComponent("water", 10.0); + + // testSystem.addComponent("CO2", 1.0); + // testSystem.addComponent("water", 1.0); + // testSystem.addComponent("MDEA", 1.000001); + // testSystem.chemicalReactionInit(); + // testSystem.createDatabase(true); + testSystem.setMixingRule(5); + + // testSystem.getChemicalReactionOperations().solveChemEq(0); + // testSystem.getChemicalReactionOperations().solveChemEq(1); + + // testSystem.isChemicalSystem(false); + + // testSystem.addComponent("NaPlus", 1.0e-10); + // testSystem.addComponent("methane", 1.1); + testSystem.init(0); + double sample1[] = {testSystem.getPressure(), testSystem.getTemperature()}; + double standardDeviation1[] = {0.01}; + double val = Double.parseDouble(dataSet.getString("L2")); + double sdev = val / 100.0; + SampleValue sample = new SampleValue(val, sdev, sample1, standardDeviation1); + sample.setFunction(function); + sample.setThermodynamicSystem(testSystem); + sample.setReference(Double.toString(testSystem.getTemperature())); + // double parameterGuess[] = {3932.0, -4127.0, -5.89, 8.9}; // HV CO2 + double parameterGuess[] = + {4802.7795779589, -440.6638711230, -7.6109236981, 4.8742002317, 0.1, -0.0420817811}; // HV + // methan570 + // double parameterGuess[] = {3204.3057406886, -2753.7379912645, -12.4728330162 + // , 13.0150379323}; // HV + // double parameterGuess[] = {8.992E3, -3.244E3, -8.424E0, -1.824E0}; // HV + // double parameterGuess[] = {-7.132E2, -3.933E2};//, 3.96E0, 9.602E-1}; //, + // 1.239}; //WS + function.setInitialGuess(parameterGuess); + sampleList.add(sample); + } + } catch (Exception e) { + logger.error("database error" + e); } + + dataSet = database.getResultSet( + "SELECT * FROM LuciaData WHERE Component='methane' AND ID<3000 AND Temperature<520 AND Y<>NULL AND Y>0.00000001 ORDER BY Temperature,Pressure");// AND + // Reference='Houghton1957' + // AND + // Reference<>'Nighswander1989' + // AND + // Temperature>278.15 + // AND + // Temperature<383.15 + // AND + // Pressure<60.01325"); + // dataSet = database.getResultSet( "SELECT * FROM LuciaData WHERE + // Component='CO2' AND ID<3000 AND Temperature>250 AND Temperature<420 AND + // Y<>NULL AND Y>0.00000001 ORDER BY Temperature,Pressure");// AND + // Reference='Houghton1957' AND Reference<>'Nighswander1989' AND + // Temperature>278.15 AND Temperature<383.15 AND Pressure<60.01325"); + + // ResultSet dataSet = database.getResultSet( "SELECT * FROM + // activityCoefficientTable WHERE Component1='MDEA' AND Component2='water'"); + // testSystem.addComponent(dataSet.getString("ComponentSolute"), 1.0); + // testSystem.addComponent(dataSet.getString("ComponentSolvent"), 1.0); + try { + int p = 0; + while (dataSet.next() && p < 100) { + p++; + BinaryWSParameterFittingToSolubilityData function = + new BinaryWSParameterFittingToSolubilityData(0, 0); + + // SystemInterface testSystem = new + // SystemFurstElectrolyteEos(Double.parseDouble(dataSet.getString("Temperature")), + // Double.parseDouble(dataSet.getString("Pressure"))/1e5); + SystemInterface testSystem = + new SystemSrkSchwartzentruberEos(Double.parseDouble(dataSet.getString("Temperature")), + Double.parseDouble(dataSet.getString("Pressure")) / 1e5); + // SystemInterface testSystem = new + // SystemSrkEos(Double.parseDouble(dataSet.getString("Temperature")), + // Double.parseDouble(dataSet.getString("Pressure"))/1e5); + // SystemInterface testSystem = new + // SystemPrEos(Double.parseDouble(dataSet.getString("Temperature")), + // Double.parseDouble(dataSet.getString("Pressure"))/1e5); + // testSystem.addComponent("CO2", 10.0); + testSystem.addComponent("methane", 10.0); + testSystem.addComponent("water", 10.0); + + // testSystem.addComponent("CO2", 1.0); + // testSystem.addComponent("water", 1.0); + // testSystem.addComponent("MDEA", 1.000001); + // testSystem.chemicalReactionInit(); + // testSystem.createDatabase(true); + testSystem.setMixingRule(5); + + // testSystem.getChemicalReactionOperations().solveChemEq(0); + // testSystem.getChemicalReactionOperations().solveChemEq(1); + + // testSystem.isChemicalSystem(false); + + // testSystem.addComponent("NaPlus", 1.0e-10); + // testSystem.addComponent("methane", 1.1); + testSystem.init(0); + double sample1[] = {testSystem.getPressure(), testSystem.getTemperature()}; + double standardDeviation1[] = {0.01}; + double val = 1.0 - Double.parseDouble(dataSet.getString("Y")); + double sdev = val / 100.0; + SampleValue sample = new SampleValue(val, sdev, sample1, standardDeviation1); + sample.setFunction(function); + sample.setThermodynamicSystem(testSystem); + sample.setReference(Double.toString(testSystem.getTemperature())); + // double parameterGuess[] = {3932.0, -4127.0, -5.89, 8.9}; // HV CO2 + double parameterGuess[] = + {4802.7795779589, -440.6638711230, -7.6109236981, 4.8742002317, 0.1, -0.0420817811}; // HV + // methan570 + // double parameterGuess[] = {3204.3057406886, -2753.7379912645, -12.4728330162 + // , 13.0150379323}; // HV + // double parameterGuess[] = {8.992E3, -3.244E3, -8.424E0, -1.824E0}; // HV + // double parameterGuess[] = {-7.132E2, -3.933E2};//, 3.96E0, 9.602E-1}; //, + // 1.239}; //WS + function.setInitialGuess(parameterGuess); + sampleList.add(sample); + } + } catch (Exception e) { + logger.error("database error" + e); + } + + SampleSet sampleSet = new SampleSet(sampleList); + optim.setSampleSet(sampleSet); + + // do simulations + optim.solve(); + // optim.runMonteCarloSimulation(); + // optim.displayResult(); + optim.displayCurveFit(); + optim.displayResult(); + // optim.writeToTextFile("c:/testFit.txt"); + } } diff --git a/src/main/java/neqsim/thermo/util/parameterFitting/binaryInteractionParameterFitting/HuronVidalParameterFitting/TestSolidAntoine.java b/src/main/java/neqsim/thermo/util/parameterFitting/binaryInteractionParameterFitting/HuronVidalParameterFitting/TestSolidAntoine.java index 2f86fbb329..ce1fb850f0 100644 --- a/src/main/java/neqsim/thermo/util/parameterFitting/binaryInteractionParameterFitting/HuronVidalParameterFitting/TestSolidAntoine.java +++ b/src/main/java/neqsim/thermo/util/parameterFitting/binaryInteractionParameterFitting/HuronVidalParameterFitting/TestSolidAntoine.java @@ -20,62 +20,61 @@ * @version $Id: $Id */ public class TestSolidAntoine { - static Logger logger = LogManager.getLogger(TestSolidAntoine.class); + static Logger logger = LogManager.getLogger(TestSolidAntoine.class); - /** - *

- * main. - *

- * - * @param args an array of {@link java.lang.String} objects - */ - public static void main(String[] args) { - LevenbergMarquardt optim = new LevenbergMarquardt(); - ArrayList sampleList = new ArrayList(); + /** + *

+ * main. + *

+ * + * @param args an array of {@link java.lang.String} objects + */ + public static void main(String[] args) { + LevenbergMarquardt optim = new LevenbergMarquardt(); + ArrayList sampleList = new ArrayList(); - // inserting samples from database - NeqSimDataBase database = new NeqSimDataBase(); + // inserting samples from database + NeqSimDataBase database = new NeqSimDataBase(); - ResultSet dataSet = database.getResultSet( - "SELECT * FROM BinaryFreezingPointData WHERE ComponentSolvent1='MEG' ORDER BY FreezingTemperature"); + ResultSet dataSet = database.getResultSet( + "SELECT * FROM BinaryFreezingPointData WHERE ComponentSolvent1='MEG' ORDER BY FreezingTemperature"); - try { - while (dataSet.next()) { - FreezeSolidFunction function = new FreezeSolidFunction(); - double guess[] = {-7566.84658558, 17.38710706}; // MEG - function.setInitialGuess(guess); + try { + while (dataSet.next()) { + FreezeSolidFunction function = new FreezeSolidFunction(); + double guess[] = {-7566.84658558, 17.38710706}; // MEG + function.setInitialGuess(guess); - SystemInterface testSystem = new SystemSrkSchwartzentruberEos(280, 1.101); - testSystem.addComponent(dataSet.getString("ComponentSolvent1"), - Double.parseDouble(dataSet.getString("x1"))); - testSystem.addComponent(dataSet.getString("ComponentSolvent2"), - Double.parseDouble(dataSet.getString("x2"))); - // testSystem.createDatabase(true); - testSystem.setSolidPhaseCheck(true); - testSystem.setMixingRule(4); - testSystem.init(0); - double sample1[] = {testSystem.getPhase(0).getComponent(0).getz()}; - double standardDeviation1[] = {0.1, 0.1, 0.1}; - double val = Double.parseDouble(dataSet.getString("FreezingTemperature")); - testSystem.setTemperature(val); - SampleValue sample = new SampleValue(val, val / 100.0, sample1, standardDeviation1); - sample.setFunction(function); - sample.setReference(dataSet.getString("Reference")); - sample.setThermodynamicSystem(testSystem); - sampleList.add(sample); - } - } catch (Exception e) { - logger.error("database error" + e); - } + SystemInterface testSystem = new SystemSrkSchwartzentruberEos(280, 1.101); + testSystem.addComponent(dataSet.getString("ComponentSolvent1"), + Double.parseDouble(dataSet.getString("x1"))); + testSystem.addComponent(dataSet.getString("ComponentSolvent2"), + Double.parseDouble(dataSet.getString("x2"))); + // testSystem.createDatabase(true); + testSystem.setSolidPhaseCheck(true); + testSystem.setMixingRule(4); + testSystem.init(0); + double sample1[] = {testSystem.getPhase(0).getComponent(0).getz()}; + double standardDeviation1[] = {0.1, 0.1, 0.1}; + double val = Double.parseDouble(dataSet.getString("FreezingTemperature")); + testSystem.setTemperature(val); + SampleValue sample = new SampleValue(val, val / 100.0, sample1, standardDeviation1); + sample.setFunction(function); + sample.setReference(dataSet.getString("Reference")); + sample.setThermodynamicSystem(testSystem); + sampleList.add(sample); + } + } catch (Exception e) { + logger.error("database error" + e); + } - SampleSet sampleSet = new SampleSet(sampleList); - optim.setSampleSet(sampleSet); + SampleSet sampleSet = new SampleSet(sampleList); + optim.setSampleSet(sampleSet); - // do simulations - optim.solve(); - // optim.runMonteCarloSimulation(); - optim.displayCurveFit(); - optim.writeToCdfFile("c:/testFit.nc"); - optim.writeToTextFile("c:/testFit.txt"); - } + // do simulations + optim.solve(); + // optim.runMonteCarloSimulation(); + optim.displayCurveFit(); + optim.writeToTextFile("c:/testFit.txt"); + } } diff --git a/src/main/java/neqsim/thermo/util/parameterFitting/binaryInteractionParameterFitting/ionicInteractionCoefficientFitting/TestIonicInteractionParameterFitting.java b/src/main/java/neqsim/thermo/util/parameterFitting/binaryInteractionParameterFitting/ionicInteractionCoefficientFitting/TestIonicInteractionParameterFitting.java index 7b80e8e3ae..974e105fee 100644 --- a/src/main/java/neqsim/thermo/util/parameterFitting/binaryInteractionParameterFitting/ionicInteractionCoefficientFitting/TestIonicInteractionParameterFitting.java +++ b/src/main/java/neqsim/thermo/util/parameterFitting/binaryInteractionParameterFitting/ionicInteractionCoefficientFitting/TestIonicInteractionParameterFitting.java @@ -20,265 +20,264 @@ * @version $Id: $Id */ public class TestIonicInteractionParameterFitting { - static Logger logger = LogManager.getLogger(TestIonicInteractionParameterFitting.class); + static Logger logger = LogManager.getLogger(TestIonicInteractionParameterFitting.class); - /** - *

- * main. - *

- * - * @param args an array of {@link java.lang.String} objects - */ - public static void main(String[] args) { - LevenbergMarquardt optim = new LevenbergMarquardt(); - ArrayList sampleList = new ArrayList(); + /** + *

+ * main. + *

+ * + * @param args an array of {@link java.lang.String} objects + */ + public static void main(String[] args) { + LevenbergMarquardt optim = new LevenbergMarquardt(); + ArrayList sampleList = new ArrayList(); - // inserting samples from database - NeqSimDataBase database = new NeqSimDataBase(); - // ResultSet dataSet = database.getResultSet( "SELECT * FROM CO2KurCor WHERE - // Reference<>'Bahiri1984' AND Temperature<373.15 ORDER BY - // wtMDEA,Temperature,Reference,loading"); - // ResultSet dataSet = database.getResultSet( "SELECT * FROM CO2KurCor WHERE - // Reference<>'Bahiri1984' AND Temperature<393.15 AND loading>0.05 AND loading<1.2 AND - // VapourPressure1<15.0 AND wtMDEA>40 AND wtMDEA<60 ORDER BY - // wtMDEA,Temperature,Reference,loading"); + // inserting samples from database + NeqSimDataBase database = new NeqSimDataBase(); + // ResultSet dataSet = database.getResultSet( "SELECT * FROM CO2KurCor WHERE + // Reference<>'Bahiri1984' AND Temperature<373.15 ORDER BY + // wtMDEA,Temperature,Reference,loading"); + // ResultSet dataSet = database.getResultSet( "SELECT * FROM CO2KurCor WHERE + // Reference<>'Bahiri1984' AND Temperature<393.15 AND loading>0.05 AND loading<1.2 AND + // VapourPressure1<15.0 AND wtMDEA>40 AND wtMDEA<60 ORDER BY + // wtMDEA,Temperature,Reference,loading"); - // //ResultSet dataSet = database.getResultSet( "SELECT * FROM CO2KurCor WHERE - // Reference<>'Bahiri1984' AND wtMDEA>40.0 AND Temperature>=280.15 AND Temperature<=470.15 - // AND loading>0.00002 AND VapourPressure1<25.0 ORDER BY wtMDEA,Temperature,Reference"); - // // ResultSet dataSet = database.getResultSet( "SELECT * FROM activityCoefficientTable - // WHERE Component1='MDEA' AND Component2='water'");AND Reference='Lemoine2000' - // //ResultSet dataSet = database.getResultSet( "SELECT * FROM CO2KurCor WHERE - // Reference='Austgen1991' AND loading>0.01"); + // //ResultSet dataSet = database.getResultSet( "SELECT * FROM CO2KurCor WHERE + // Reference<>'Bahiri1984' AND wtMDEA>40.0 AND Temperature>=280.15 AND Temperature<=470.15 + // AND loading>0.00002 AND VapourPressure1<25.0 ORDER BY wtMDEA,Temperature,Reference"); + // // ResultSet dataSet = database.getResultSet( "SELECT * FROM activityCoefficientTable + // WHERE Component1='MDEA' AND Component2='water'");AND Reference='Lemoine2000' + // //ResultSet dataSet = database.getResultSet( "SELECT * FROM CO2KurCor WHERE + // Reference='Austgen1991' AND loading>0.01"); - // try{ - // int i=0; - // while(dataSet.next() && i<450){ - // i++; - // IonicInteractionParameterFittingFunction function = new - // IonicInteractionParameterFittingFunction(); - // //IonicInteractionParameterFittingFunction_CO2 function = new + // try{ + // int i=0; + // while(dataSet.next() && i<450){ + // i++; + // IonicInteractionParameterFittingFunction function = new + // IonicInteractionParameterFittingFunction(); + // //IonicInteractionParameterFittingFunction_CO2 function = new + // IonicInteractionParameterFittingFunction_CO2(); + // //double guess[] = {-0.0005842392, 0.0003621714, 0.0481887797, + // 239.2501170265};//{-0.0000629, 0.00001255, 0.05, 240.8165};//, + // 0.311975E-4};//,0.0001439};//, 0.00000001439};//, -0.0000745697};//, 263.73, + // 466.41,0.1,0.1};//, 1.0,1.0};//;{-2.9222e-6, -7.991E-6, 3.924E-6};//,1.0,1.0};//, + // -7.223e-4}; + // //double bounds[][] = + // {{-0.0055,0.0055}};//,{-0.0055,0.0055},{-10.001,10.001},{-1.0015,1.0015},{-320.0015,320.0015},{-320.901,320.900195},{-1.0,1000},{-0.800001,0.8},{-80000.01,20000.8},{-0.01,10.6},{-0.01,0.0015},{-0.01,0.0015}}; + // //double guess[] = {0.0000231069, 0.0001092540, 0.00001046762};//, -0.0001190554};//, + // 1e-3,1e-3,1e-3,1e-3};//, 1110.0e-8};//, 0.0001052339, -0.0001046940};//,-2753.0e-8, + // 13.01e-8};//, 242.6021196937,-7858.0,-36.7816};//, -2753.0e-4, 13.01e-4};//, + // -0.00002653966};//, -0.000000745697};//,-2753.0e-4, 13.01e-4};//, + // 0.0000152542010};//,4.5};//, -2753.0e-4, 13.01e-4};//, 240.2701596331};// + // -2753.7379912645, 13.0150379323};//, -2.5254669805767994E-6};//,0.78000000000};// + // 241.2701596331, 0.8000000000};//, 3.162827E-4, -2.5254669805767994E-4};//, + // 239.2501170265};//, 3.11975E-5}; + // double guess[] = {0.0000260019, -0.0001172396, 0.0000615323, -0.0001285810};//, + // -0.0004677550, -0.0000389863};//, 2.88281314E-4};// detailed reactions + // // -0,0000186524 -0,0000470206 0,0000816440 -0,0001147055 -0,1422977509 -0,0351820850 + // 0,1531978514 -0,0062978601 + // //double guess[] = {0,0041639953 0,0009961457};, + // //double guess[] = {-2753.0e-4, 13.01e-4};// 263.73, -5.717, 8.6}; + // //SystemInterface testSystem = new SystemElectrolyteCPA((273.15+25.0), 1.0); + // SystemInterface testSystem = new SystemFurstElectrolyteEos((273.15+25.0), 1.0); + // testSystem.addComponent("CO2", Double.parseDouble(dataSet.getString("x1"))); + // testSystem.addComponent("MDEA", Double.parseDouble(dataSet.getString("x2"))); + // testSystem.addComponent("water", Double.parseDouble(dataSet.getString("x3"))); + // double temperature = Double.parseDouble(dataSet.getString("Temperature")); + // double pressure = Double.parseDouble(dataSet.getString("VapourPressure1")); + // testSystem.setTemperature(temperature); + // testSystem.setPressure(pressure+1.0); + // testSystem.chemicalReactionInit(); + // // testSystem.createDatabase(true); + // testSystem.setMixingRule(4); + // testSystem.init(0); + // double sample1[] = + // {testSystem.getPhase(0).getComponent(0).getNumberOfmoles()/testSystem.getPhase(0).getComponent(1).getNumberOfmoles()}; + // + // double standardDeviation1[] = {0.01}; + // double stddev = pressure;//Double.parseDouble(dataSet.getString("StandardDeviation")) + // SampleValue sample = new SampleValue(pressure, stddev, sample1, standardDeviation1); + // function.setInitialGuess(guess); + // //function.setBounds(bounds); + // sample.setFunction(function); + // double wtpr = Double.parseDouble(dataSet.getString("wtMDEA")); + // sample.setReference(dataSet.getString("Reference") + " " + temperature); + // sample.setDescription(Double.toString(wtpr)); + // sample.setThermodynamicSystem(testSystem); + // sampleList.add(sample); + // } + // } + // catch(Exception e){ + // logger.error("database error" + e); + // } + + double guess[] = {-0.0001868490, -0.0006868943, -0.0000210224, -0.0002324934, 0.0005}; + ResultSet dataSet = database.getResultSet( + "SELECT * FROM CO2waterMDEA2 WHERE Temperature<'393.15' AND PressureCO2<'20' AND Reference<>'GPA'"); + + try { + int i = 0; + while (dataSet.next() && i < 25) { + int ID = Integer.parseInt(dataSet.getString("ID")); + if ((ID > 56 && ID < 64) || (ID > 92 && ID < 101) || (ID > 123 && ID < 131)) { // 75 + // wt% + // amine + continue; + } + if (ID == 155) { + continue; // AAD >100 + } + if (ID == 29 || ID == 28 || ID == 258) { + continue; // large values of Pexp/Pcalc + } + + i++; + IonicInteractionParameterFittingFunction function = + new IonicInteractionParameterFittingFunction(); + // IonicInteractionParameterFittingFunction_CO2 function = new // IonicInteractionParameterFittingFunction_CO2(); - // //double guess[] = {-0.0005842392, 0.0003621714, 0.0481887797, + // double guess[] = {-0.0005842392, 0.0003621714, 0.0481887797, // 239.2501170265};//{-0.0000629, 0.00001255, 0.05, 240.8165};//, // 0.311975E-4};//,0.0001439};//, 0.00000001439};//, -0.0000745697};//, 263.73, - // 466.41,0.1,0.1};//, 1.0,1.0};//;{-2.9222e-6, -7.991E-6, 3.924E-6};//,1.0,1.0};//, - // -7.223e-4}; - // //double bounds[][] = + // 466.41,0.1,0.1};//, 1.0,1.0};//;{-2.9222e-6, -7.991E-6, + // 3.924E-6};//,1.0,1.0};//, -7.223e-4}; + // double bounds[][] = // {{-0.0055,0.0055}};//,{-0.0055,0.0055},{-10.001,10.001},{-1.0015,1.0015},{-320.0015,320.0015},{-320.901,320.900195},{-1.0,1000},{-0.800001,0.8},{-80000.01,20000.8},{-0.01,10.6},{-0.01,0.0015},{-0.01,0.0015}}; - // //double guess[] = {0.0000231069, 0.0001092540, 0.00001046762};//, -0.0001190554};//, - // 1e-3,1e-3,1e-3,1e-3};//, 1110.0e-8};//, 0.0001052339, -0.0001046940};//,-2753.0e-8, - // 13.01e-8};//, 242.6021196937,-7858.0,-36.7816};//, -2753.0e-4, 13.01e-4};//, + // double guess[] = {0.0000231069, 0.0001092540, 0.00001046762};//, + // -0.0001190554};//, 1e-3,1e-3,1e-3,1e-3};//, 1110.0e-8};//, 0.0001052339, + // -0.0001046940};//,-2753.0e-8, 13.01e-8};//, + // 242.6021196937,-7858.0,-36.7816};//, -2753.0e-4, 13.01e-4};//, // -0.00002653966};//, -0.000000745697};//,-2753.0e-4, 13.01e-4};//, // 0.0000152542010};//,4.5};//, -2753.0e-4, 13.01e-4};//, 240.2701596331};// - // -2753.7379912645, 13.0150379323};//, -2.5254669805767994E-6};//,0.78000000000};// - // 241.2701596331, 0.8000000000};//, 3.162827E-4, -2.5254669805767994E-4};//, + // -2753.7379912645, 13.0150379323};//, + // -2.5254669805767994E-6};//,0.78000000000};// 241.2701596331, + // 0.8000000000};//, 3.162827E-4, -2.5254669805767994E-4};//, // 239.2501170265};//, 3.11975E-5}; - // double guess[] = {0.0000260019, -0.0001172396, 0.0000615323, -0.0001285810};//, - // -0.0004677550, -0.0000389863};//, 2.88281314E-4};// detailed reactions - // // -0,0000186524 -0,0000470206 0,0000816440 -0,0001147055 -0,1422977509 -0,0351820850 - // 0,1531978514 -0,0062978601 - // //double guess[] = {0,0041639953 0,0009961457};, - // //double guess[] = {-2753.0e-4, 13.01e-4};// 263.73, -5.717, 8.6}; - // //SystemInterface testSystem = new SystemElectrolyteCPA((273.15+25.0), 1.0); - // SystemInterface testSystem = new SystemFurstElectrolyteEos((273.15+25.0), 1.0); - // testSystem.addComponent("CO2", Double.parseDouble(dataSet.getString("x1"))); - // testSystem.addComponent("MDEA", Double.parseDouble(dataSet.getString("x2"))); - // testSystem.addComponent("water", Double.parseDouble(dataSet.getString("x3"))); - // double temperature = Double.parseDouble(dataSet.getString("Temperature")); - // double pressure = Double.parseDouble(dataSet.getString("VapourPressure1")); - // testSystem.setTemperature(temperature); - // testSystem.setPressure(pressure+1.0); - // testSystem.chemicalReactionInit(); - // // testSystem.createDatabase(true); - // testSystem.setMixingRule(4); - // testSystem.init(0); - // double sample1[] = - // {testSystem.getPhase(0).getComponent(0).getNumberOfmoles()/testSystem.getPhase(0).getComponent(1).getNumberOfmoles()}; - // - // double standardDeviation1[] = {0.01}; - // double stddev = pressure;//Double.parseDouble(dataSet.getString("StandardDeviation")) - // SampleValue sample = new SampleValue(pressure, stddev, sample1, standardDeviation1); - // function.setInitialGuess(guess); - // //function.setBounds(bounds); - // sample.setFunction(function); - // double wtpr = Double.parseDouble(dataSet.getString("wtMDEA")); - // sample.setReference(dataSet.getString("Reference") + " " + temperature); - // sample.setDescription(Double.toString(wtpr)); - // sample.setThermodynamicSystem(testSystem); - // sampleList.add(sample); - // } - // } - // catch(Exception e){ - // logger.error("database error" + e); - // } - - double guess[] = {-0.0001868490, -0.0006868943, -0.0000210224, -0.0002324934, 0.0005}; - ResultSet dataSet = database.getResultSet( - "SELECT * FROM CO2waterMDEA2 WHERE Temperature<'393.15' AND PressureCO2<'20' AND Reference<>'GPA'"); + // double guess[] = {0.0000260019, -0.0001172396, 0.0000615323, + // -0.0001285810};//, -0.0004677550, -0.0000389863};//, 2.88281314E-4};// + // detailed reactions + // -0,0000186524 -0,0000470206 0,0000816440 -0,0001147055 -0,1422977509 + // -0,0351820850 0,1531978514 -0,0062978601 + // double guess[] = {0,0041639953 0,0009961457};, + // double guess[] = {-2753.0e-4, 13.01e-4};// 263.73, -5.717, 8.6}; + // SystemInterface testSystem = new SystemElectrolyteCPA((273.15+25.0), 1.0); + SystemInterface testSystem = new SystemFurstElectrolyteEos((273.15 + 25.0), 1.0); + testSystem.addComponent("CO2", Double.parseDouble(dataSet.getString("x1"))); + testSystem.addComponent("MDEA", Double.parseDouble(dataSet.getString("x3"))); + testSystem.addComponent("water", Double.parseDouble(dataSet.getString("x2"))); + double temperature = Double.parseDouble(dataSet.getString("Temperature")); + double pressure = Double.parseDouble(dataSet.getString("PressureCO2")); + testSystem.setTemperature(temperature); + testSystem.setPressure(pressure + 1.0); + testSystem.chemicalReactionInit(); + // testSystem.createDatabase(true); + testSystem.setMixingRule(4); + testSystem.init(0); + double sample1[] = {testSystem.getPhase(0).getComponent(0).getNumberOfmoles() + / testSystem.getPhase(0).getComponent(1).getNumberOfmoles()}; + double standardDeviation1[] = {0.01}; + double stddev = pressure;// Double.parseDouble(dataSet.getString("StandardDeviation")) + SampleValue sample = new SampleValue(pressure, stddev, sample1, standardDeviation1); + function.setInitialGuess(guess); + // function.setBounds(bounds); + sample.setFunction(function); + sample.setReference(dataSet.getString("Reference")); + sample.setThermodynamicSystem(testSystem); + sampleList.add(sample); + } + } catch (Exception e) { + logger.error("database error" + e); + } - try { - int i = 0; - while (dataSet.next() && i < 25) { - int ID = Integer.parseInt(dataSet.getString("ID")); - if ((ID > 56 && ID < 64) || (ID > 92 && ID < 101) || (ID > 123 && ID < 131)) { // 75 - // wt% - // amine - continue; - } - if (ID == 155) { - continue; // AAD >100 - } - if (ID == 29 || ID == 28 || ID == 258) { - continue; // large values of Pexp/Pcalc - } + dataSet = database.getResultSet( + "SELECT * FROM CO2waterMDEA2 WHERE Temperature<'393.15' AND Pressure<'20' AND Reference<>'GPA'"); - i++; - IonicInteractionParameterFittingFunction function = - new IonicInteractionParameterFittingFunction(); - // IonicInteractionParameterFittingFunction_CO2 function = new - // IonicInteractionParameterFittingFunction_CO2(); - // double guess[] = {-0.0005842392, 0.0003621714, 0.0481887797, - // 239.2501170265};//{-0.0000629, 0.00001255, 0.05, 240.8165};//, - // 0.311975E-4};//,0.0001439};//, 0.00000001439};//, -0.0000745697};//, 263.73, - // 466.41,0.1,0.1};//, 1.0,1.0};//;{-2.9222e-6, -7.991E-6, - // 3.924E-6};//,1.0,1.0};//, -7.223e-4}; - // double bounds[][] = - // {{-0.0055,0.0055}};//,{-0.0055,0.0055},{-10.001,10.001},{-1.0015,1.0015},{-320.0015,320.0015},{-320.901,320.900195},{-1.0,1000},{-0.800001,0.8},{-80000.01,20000.8},{-0.01,10.6},{-0.01,0.0015},{-0.01,0.0015}}; - // double guess[] = {0.0000231069, 0.0001092540, 0.00001046762};//, - // -0.0001190554};//, 1e-3,1e-3,1e-3,1e-3};//, 1110.0e-8};//, 0.0001052339, - // -0.0001046940};//,-2753.0e-8, 13.01e-8};//, - // 242.6021196937,-7858.0,-36.7816};//, -2753.0e-4, 13.01e-4};//, - // -0.00002653966};//, -0.000000745697};//,-2753.0e-4, 13.01e-4};//, - // 0.0000152542010};//,4.5};//, -2753.0e-4, 13.01e-4};//, 240.2701596331};// - // -2753.7379912645, 13.0150379323};//, - // -2.5254669805767994E-6};//,0.78000000000};// 241.2701596331, - // 0.8000000000};//, 3.162827E-4, -2.5254669805767994E-4};//, - // 239.2501170265};//, 3.11975E-5}; - // double guess[] = {0.0000260019, -0.0001172396, 0.0000615323, - // -0.0001285810};//, -0.0004677550, -0.0000389863};//, 2.88281314E-4};// - // detailed reactions - // -0,0000186524 -0,0000470206 0,0000816440 -0,0001147055 -0,1422977509 - // -0,0351820850 0,1531978514 -0,0062978601 - // double guess[] = {0,0041639953 0,0009961457};, - // double guess[] = {-2753.0e-4, 13.01e-4};// 263.73, -5.717, 8.6}; - // SystemInterface testSystem = new SystemElectrolyteCPA((273.15+25.0), 1.0); - SystemInterface testSystem = new SystemFurstElectrolyteEos((273.15 + 25.0), 1.0); - testSystem.addComponent("CO2", Double.parseDouble(dataSet.getString("x1"))); - testSystem.addComponent("MDEA", Double.parseDouble(dataSet.getString("x3"))); - testSystem.addComponent("water", Double.parseDouble(dataSet.getString("x2"))); - double temperature = Double.parseDouble(dataSet.getString("Temperature")); - double pressure = Double.parseDouble(dataSet.getString("PressureCO2")); - testSystem.setTemperature(temperature); - testSystem.setPressure(pressure + 1.0); - testSystem.chemicalReactionInit(); - // testSystem.createDatabase(true); - testSystem.setMixingRule(4); - testSystem.init(0); - double sample1[] = {testSystem.getPhase(0).getComponent(0).getNumberOfmoles() - / testSystem.getPhase(0).getComponent(1).getNumberOfmoles()}; - double standardDeviation1[] = {0.01}; - double stddev = pressure;// Double.parseDouble(dataSet.getString("StandardDeviation")) - SampleValue sample = new SampleValue(pressure, stddev, sample1, standardDeviation1); - function.setInitialGuess(guess); - // function.setBounds(bounds); - sample.setFunction(function); - sample.setReference(dataSet.getString("Reference")); - sample.setThermodynamicSystem(testSystem); - sampleList.add(sample); - } - } catch (Exception e) { - logger.error("database error" + e); + try { + int i = 0; + while (dataSet.next() && i < 2) { + int ID = Integer.parseInt(dataSet.getString("ID")); + if ((ID > 56 && ID < 64) || (ID > 92 && ID < 101) || (ID > 123 && ID < 131)) { // 75 + // wt% + // amine + continue; } - - dataSet = database.getResultSet( - "SELECT * FROM CO2waterMDEA2 WHERE Temperature<'393.15' AND Pressure<'20' AND Reference<>'GPA'"); - - try { - int i = 0; - while (dataSet.next() && i < 2) { - int ID = Integer.parseInt(dataSet.getString("ID")); - if ((ID > 56 && ID < 64) || (ID > 92 && ID < 101) || (ID > 123 && ID < 131)) { // 75 - // wt% - // amine - continue; - } - if (ID == 155) { - continue; // AAD >100 - } - if (ID == 29 || ID == 28 || ID == 258) { - continue; // large values of Pexp/Pcalc - } - - i++; - IonicInteractionParameterFittingFunction_1 function = - new IonicInteractionParameterFittingFunction_1(); - // IonicInteractionParameterFittingFunction_CO2 function = new - // IonicInteractionParameterFittingFunction_CO2(); - // double guess[] = {-0.0005842392, 0.0003621714, 0.0481887797, - // 239.2501170265};//{-0.0000629, 0.00001255, 0.05, 240.8165};//, - // 0.311975E-4};//,0.0001439};//, 0.00000001439};//, -0.0000745697};//, 263.73, - // 466.41,0.1,0.1};//, 1.0,1.0};//;{-2.9222e-6, -7.991E-6, - // 3.924E-6};//,1.0,1.0};//, -7.223e-4}; - // double bounds[][] = - // {{-0.0055,0.0055}};//,{-0.0055,0.0055},{-10.001,10.001},{-1.0015,1.0015},{-320.0015,320.0015},{-320.901,320.900195},{-1.0,1000},{-0.800001,0.8},{-80000.01,20000.8},{-0.01,10.6},{-0.01,0.0015},{-0.01,0.0015}}; - // double guess[] = {0.0000231069, 0.0001092540, 0.00001046762};//, - // -0.0001190554};//, 1e-3,1e-3,1e-3,1e-3};//, 1110.0e-8};//, 0.0001052339, - // -0.0001046940};//,-2753.0e-8, 13.01e-8};//, - // 242.6021196937,-7858.0,-36.7816};//, -2753.0e-4, 13.01e-4};//, - // -0.00002653966};//, -0.000000745697};//,-2753.0e-4, 13.01e-4};//, - // 0.0000152542010};//,4.5};//, -2753.0e-4, 13.01e-4};//, 240.2701596331};// - // -2753.7379912645, 13.0150379323};//, - // -2.5254669805767994E-6};//,0.78000000000};// 241.2701596331, - // 0.8000000000};//, 3.162827E-4, -2.5254669805767994E-4};//, - // 239.2501170265};//, 3.11975E-5}; - // double guess[] = {0.0000260019, -0.0001172396, 0.0000615323, - // -0.0001285810};//, -0.0004677550, -0.0000389863};//, 2.88281314E-4};// - // detailed reactions - // -0,0000186524 -0,0000470206 0,0000816440 -0,0001147055 -0,1422977509 - // -0,0351820850 0,1531978514 -0,0062978601 - // double guess[] = {0,0041639953 0,0009961457};, - // double guess[] = {-2753.0e-4, 13.01e-4};// 263.73, -5.717, 8.6}; - // SystemInterface testSystem = new SystemElectrolyteCPA((273.15+25.0), 1.0); - SystemInterface testSystem = new SystemFurstElectrolyteEos((273.15 + 25.0), 1.0); - testSystem.addComponent("CO2", Double.parseDouble(dataSet.getString("x1"))); - testSystem.addComponent("MDEA", Double.parseDouble(dataSet.getString("x3"))); - testSystem.addComponent("water", Double.parseDouble(dataSet.getString("x2"))); - double temperature = Double.parseDouble(dataSet.getString("Temperature")); - double pressure = Double.parseDouble(dataSet.getString("Pressure")); - testSystem.setTemperature(temperature); - testSystem.setPressure(pressure); - testSystem.chemicalReactionInit(); - // testSystem.createDatabase(true); - testSystem.setMixingRule(4); - testSystem.init(0); - double sample1[] = {testSystem.getPhase(0).getComponent(0).getNumberOfmoles() - / testSystem.getPhase(0).getComponent(1).getNumberOfmoles()}; - double standardDeviation1[] = {0.01}; - double stddev = pressure;// Double.parseDouble(dataSet.getString("StandardDeviation")) - SampleValue sample = new SampleValue(pressure, stddev, sample1, standardDeviation1); - function.setInitialGuess(guess); - // function.setBounds(bounds); - sample.setFunction(function); - sample.setReference(dataSet.getString("Reference")); - sample.setThermodynamicSystem(testSystem); - sampleList.add(sample); - } - } catch (Exception e) { - logger.error("database error" + e); + if (ID == 155) { + continue; // AAD >100 + } + if (ID == 29 || ID == 28 || ID == 258) { + continue; // large values of Pexp/Pcalc } - SampleSet sampleSet = new SampleSet(sampleList); - optim.setSampleSet(sampleSet); + i++; + IonicInteractionParameterFittingFunction_1 function = + new IonicInteractionParameterFittingFunction_1(); + // IonicInteractionParameterFittingFunction_CO2 function = new + // IonicInteractionParameterFittingFunction_CO2(); + // double guess[] = {-0.0005842392, 0.0003621714, 0.0481887797, + // 239.2501170265};//{-0.0000629, 0.00001255, 0.05, 240.8165};//, + // 0.311975E-4};//,0.0001439};//, 0.00000001439};//, -0.0000745697};//, 263.73, + // 466.41,0.1,0.1};//, 1.0,1.0};//;{-2.9222e-6, -7.991E-6, + // 3.924E-6};//,1.0,1.0};//, -7.223e-4}; + // double bounds[][] = + // {{-0.0055,0.0055}};//,{-0.0055,0.0055},{-10.001,10.001},{-1.0015,1.0015},{-320.0015,320.0015},{-320.901,320.900195},{-1.0,1000},{-0.800001,0.8},{-80000.01,20000.8},{-0.01,10.6},{-0.01,0.0015},{-0.01,0.0015}}; + // double guess[] = {0.0000231069, 0.0001092540, 0.00001046762};//, + // -0.0001190554};//, 1e-3,1e-3,1e-3,1e-3};//, 1110.0e-8};//, 0.0001052339, + // -0.0001046940};//,-2753.0e-8, 13.01e-8};//, + // 242.6021196937,-7858.0,-36.7816};//, -2753.0e-4, 13.01e-4};//, + // -0.00002653966};//, -0.000000745697};//,-2753.0e-4, 13.01e-4};//, + // 0.0000152542010};//,4.5};//, -2753.0e-4, 13.01e-4};//, 240.2701596331};// + // -2753.7379912645, 13.0150379323};//, + // -2.5254669805767994E-6};//,0.78000000000};// 241.2701596331, + // 0.8000000000};//, 3.162827E-4, -2.5254669805767994E-4};//, + // 239.2501170265};//, 3.11975E-5}; + // double guess[] = {0.0000260019, -0.0001172396, 0.0000615323, + // -0.0001285810};//, -0.0004677550, -0.0000389863};//, 2.88281314E-4};// + // detailed reactions + // -0,0000186524 -0,0000470206 0,0000816440 -0,0001147055 -0,1422977509 + // -0,0351820850 0,1531978514 -0,0062978601 + // double guess[] = {0,0041639953 0,0009961457};, + // double guess[] = {-2753.0e-4, 13.01e-4};// 263.73, -5.717, 8.6}; + // SystemInterface testSystem = new SystemElectrolyteCPA((273.15+25.0), 1.0); + SystemInterface testSystem = new SystemFurstElectrolyteEos((273.15 + 25.0), 1.0); + testSystem.addComponent("CO2", Double.parseDouble(dataSet.getString("x1"))); + testSystem.addComponent("MDEA", Double.parseDouble(dataSet.getString("x3"))); + testSystem.addComponent("water", Double.parseDouble(dataSet.getString("x2"))); + double temperature = Double.parseDouble(dataSet.getString("Temperature")); + double pressure = Double.parseDouble(dataSet.getString("Pressure")); + testSystem.setTemperature(temperature); + testSystem.setPressure(pressure); + testSystem.chemicalReactionInit(); + // testSystem.createDatabase(true); + testSystem.setMixingRule(4); + testSystem.init(0); + double sample1[] = {testSystem.getPhase(0).getComponent(0).getNumberOfmoles() + / testSystem.getPhase(0).getComponent(1).getNumberOfmoles()}; + double standardDeviation1[] = {0.01}; + double stddev = pressure;// Double.parseDouble(dataSet.getString("StandardDeviation")) + SampleValue sample = new SampleValue(pressure, stddev, sample1, standardDeviation1); + function.setInitialGuess(guess); + // function.setBounds(bounds); + sample.setFunction(function); + sample.setReference(dataSet.getString("Reference")); + sample.setThermodynamicSystem(testSystem); + sampleList.add(sample); + } + } catch (Exception e) { + logger.error("database error" + e); + } - // do simulations + SampleSet sampleSet = new SampleSet(sampleList); + optim.setSampleSet(sampleSet); - optim.solve(); - // optim.runMonteCarloSimulation(); - // optim.displayCurveFit(); - // optim.displayGraph(); - optim.displayCurveFit(); - optim.writeToCdfFile("c:/testFit.nc"); - optim.writeToTextFile("c:/testFit.txt"); - } + // do simulations + + optim.solve(); + // optim.runMonteCarloSimulation(); + // optim.displayCurveFit(); + // optim.displayGraph(); + optim.displayCurveFit(); + optim.writeToTextFile("c:/testFit.txt"); + } } diff --git a/src/main/java/neqsim/thermo/util/parameterFitting/binaryInteractionParameterFitting/ionicInteractionCoefficientFitting/TestIonicInteractionParameterFittingCH4.java b/src/main/java/neqsim/thermo/util/parameterFitting/binaryInteractionParameterFitting/ionicInteractionCoefficientFitting/TestIonicInteractionParameterFittingCH4.java index 4b67429060..8b13b7e1e6 100644 --- a/src/main/java/neqsim/thermo/util/parameterFitting/binaryInteractionParameterFitting/ionicInteractionCoefficientFitting/TestIonicInteractionParameterFittingCH4.java +++ b/src/main/java/neqsim/thermo/util/parameterFitting/binaryInteractionParameterFitting/ionicInteractionCoefficientFitting/TestIonicInteractionParameterFittingCH4.java @@ -20,141 +20,138 @@ * @version $Id: $Id */ public class TestIonicInteractionParameterFittingCH4 { - static Logger logger = LogManager.getLogger(TestIonicInteractionParameterFittingCH4.class); + static Logger logger = LogManager.getLogger(TestIonicInteractionParameterFittingCH4.class); - /** - *

- * main. - *

- * - * @param args an array of {@link java.lang.String} objects - */ - public static void main(String[] args) { - LevenbergMarquardt optim = new LevenbergMarquardt(); - ArrayList sampleList = new ArrayList(); + /** + *

+ * main. + *

+ * + * @param args an array of {@link java.lang.String} objects + */ + public static void main(String[] args) { + LevenbergMarquardt optim = new LevenbergMarquardt(); + ArrayList sampleList = new ArrayList(); - // inserting samples from database - NeqSimDataBase database = new NeqSimDataBase(); - ResultSet dataSet = database.getResultSet("SELECT * FROM Co2Ch4MDEA WHERE loading<1.9");// AND - // temperature=313.15 - // AND - // pressure<210 - // AND - // wt=30"); - // ResultSet dataSet = database.getResultSet( "SELECT * FROM - // activityCoefficientTable WHERE Component1='MDEA' AND Component2='water'");AND - // Reference='Lemoine2000' - double guess[] = {-0.0001617266, 0.5 * 1e-3};// , -0.0932324951};//, 0.6465043774,}; - // -0,0001550096 0,0007612383 + // inserting samples from database + NeqSimDataBase database = new NeqSimDataBase(); + ResultSet dataSet = database.getResultSet("SELECT * FROM Co2Ch4MDEA WHERE loading<1.9");// AND + // temperature=313.15 + // AND + // pressure<210 + // AND + // wt=30"); + // ResultSet dataSet = database.getResultSet( "SELECT * FROM + // activityCoefficientTable WHERE Component1='MDEA' AND Component2='water'");AND + // Reference='Lemoine2000' + double guess[] = {-0.0001617266, 0.5 * 1e-3};// , -0.0932324951};//, 0.6465043774,}; + // -0,0001550096 0,0007612383 - // double guess[] = {-0.0000309356,-0.1469925592,-0.0272808384}; + // double guess[] = {-0.0000309356,-0.1469925592,-0.0272808384}; - try { - int i = 0; - while (dataSet.next() && i < 100) { - i++; - IonicInteractionParameterFittingFunctionCH4 function = - new IonicInteractionParameterFittingFunctionCH4(); + try { + int i = 0; + while (dataSet.next() && i < 100) { + i++; + IonicInteractionParameterFittingFunctionCH4 function = + new IonicInteractionParameterFittingFunctionCH4(); - SystemInterface testSystem = new SystemFurstElectrolyteEos((273.15 + 25.0), 100.0); - testSystem.addComponent(dataSet.getString("gass2"), - Double.parseDouble(dataSet.getString("molCH4"))); - testSystem.addComponent(dataSet.getString("gass1"), - Double.parseDouble(dataSet.getString("molCO2"))); - testSystem.addComponent(dataSet.getString("liquid1"), - Double.parseDouble(dataSet.getString("molMDEA"))); - testSystem.addComponent(dataSet.getString("liquid2"), - Double.parseDouble(dataSet.getString("molWater"))); + SystemInterface testSystem = new SystemFurstElectrolyteEos((273.15 + 25.0), 100.0); + testSystem.addComponent(dataSet.getString("gass2"), + Double.parseDouble(dataSet.getString("molCH4"))); + testSystem.addComponent(dataSet.getString("gass1"), + Double.parseDouble(dataSet.getString("molCO2"))); + testSystem.addComponent(dataSet.getString("liquid1"), + Double.parseDouble(dataSet.getString("molMDEA"))); + testSystem.addComponent(dataSet.getString("liquid2"), + Double.parseDouble(dataSet.getString("molWater"))); - double temperature = Double.parseDouble(dataSet.getString("Temperature")); - double pressure = Double.parseDouble(dataSet.getString("Pressure")); - testSystem.setPressure(pressure); - testSystem.setTemperature(temperature); - testSystem.chemicalReactionInit(); - // testSystem.createDatabase(true); - testSystem.setMixingRule(4); - testSystem.init(0); - double sample1[] = {testSystem.getPhases()[0].getComponents()[0] - .getNumberOfMolesInPhase() - / testSystem.getPhases()[0].getComponents()[2].getNumberOfMolesInPhase()}; - double standardDeviation1[] = {0.01}; + double temperature = Double.parseDouble(dataSet.getString("Temperature")); + double pressure = Double.parseDouble(dataSet.getString("Pressure")); + testSystem.setPressure(pressure); + testSystem.setTemperature(temperature); + testSystem.chemicalReactionInit(); + // testSystem.createDatabase(true); + testSystem.setMixingRule(4); + testSystem.init(0); + double sample1[] = {testSystem.getPhases()[0].getComponents()[0].getNumberOfMolesInPhase() + / testSystem.getPhases()[0].getComponents()[2].getNumberOfMolesInPhase()}; + double standardDeviation1[] = {0.01}; - SampleValue sample = - new SampleValue(pressure, pressure / 100.0, sample1, standardDeviation1); - function.setInitialGuess(guess); - sample.setFunction(function); - sample.setReference("addicks"); - sample.setDescription(Double.toString(pressure)); - sample.setThermodynamicSystem(testSystem); - sampleList.add(sample); - } - } catch (Exception e) { - logger.error("database error" + e); - } - // dataSet = database.getResultSet( "SELECT * FROM Co2Ch4MDEA WHERE loading<1.9 - // AND temperature<453.15 AND pressure<210 AND wt<70"); - // ResultSet dataSet = database.getResultSet( "SELECT * FROM - // activityCoefficientTable WHERE Component1='MDEA' AND Component2='water'");AND - // Reference='Lemoine2000' - dataSet = database.getResultSet("SELECT * FROM Co2Ch4MDEA WHERE loading<1.9");// AND - // temperature=313.15 - // AND - // pressure<210 - // AND - // wt=50"); - try { - int i = 0; - while (!dataSet.next() && i < 100) { - i++; - IonicInteractionParameterFittingFunctionCH4_1 function = - new IonicInteractionParameterFittingFunctionCH4_1(); + SampleValue sample = + new SampleValue(pressure, pressure / 100.0, sample1, standardDeviation1); + function.setInitialGuess(guess); + sample.setFunction(function); + sample.setReference("addicks"); + sample.setDescription(Double.toString(pressure)); + sample.setThermodynamicSystem(testSystem); + sampleList.add(sample); + } + } catch (Exception e) { + logger.error("database error" + e); + } + // dataSet = database.getResultSet( "SELECT * FROM Co2Ch4MDEA WHERE loading<1.9 + // AND temperature<453.15 AND pressure<210 AND wt<70"); + // ResultSet dataSet = database.getResultSet( "SELECT * FROM + // activityCoefficientTable WHERE Component1='MDEA' AND Component2='water'");AND + // Reference='Lemoine2000' + dataSet = database.getResultSet("SELECT * FROM Co2Ch4MDEA WHERE loading<1.9");// AND + // temperature=313.15 + // AND + // pressure<210 + // AND + // wt=50"); + try { + int i = 0; + while (!dataSet.next() && i < 100) { + i++; + IonicInteractionParameterFittingFunctionCH4_1 function = + new IonicInteractionParameterFittingFunctionCH4_1(); - SystemInterface testSystem = new SystemFurstElectrolyteEos((273.15 + 25.0), 100.0); - testSystem.addComponent(dataSet.getString("gass2"), - Double.parseDouble(dataSet.getString("molCH4"))); - testSystem.addComponent(dataSet.getString("gass1"), - Double.parseDouble(dataSet.getString("molCO2"))); - testSystem.addComponent(dataSet.getString("liquid1"), - Double.parseDouble(dataSet.getString("molMDEA"))); - testSystem.addComponent(dataSet.getString("liquid2"), - Double.parseDouble(dataSet.getString("molWater"))); + SystemInterface testSystem = new SystemFurstElectrolyteEos((273.15 + 25.0), 100.0); + testSystem.addComponent(dataSet.getString("gass2"), + Double.parseDouble(dataSet.getString("molCH4"))); + testSystem.addComponent(dataSet.getString("gass1"), + Double.parseDouble(dataSet.getString("molCO2"))); + testSystem.addComponent(dataSet.getString("liquid1"), + Double.parseDouble(dataSet.getString("molMDEA"))); + testSystem.addComponent(dataSet.getString("liquid2"), + Double.parseDouble(dataSet.getString("molWater"))); - double temperature = Double.parseDouble(dataSet.getString("Temperature")); - double pressure = Double.parseDouble(dataSet.getString("Pressure")); - testSystem.setPressure(pressure); - testSystem.setTemperature(temperature); - testSystem.chemicalReactionInit(); - // testSystem.createDatabase(true); - testSystem.setMixingRule(4); - testSystem.init(0); - double sample1[] = {testSystem.getPhases()[0].getComponents()[1] - .getNumberOfMolesInPhase() - / testSystem.getPhases()[0].getComponents()[2].getNumberOfMolesInPhase()}; - double standardDeviation1[] = {0.01}; - double y1 = Double.parseDouble(dataSet.getString("y1")); - SampleValue sample = new SampleValue(pressure * y1, y1 * pressure / 100.0, sample1, - standardDeviation1); - function.setInitialGuess(guess); - sample.setFunction(function); - sample.setReference("addicks"); - sample.setDescription(Double.toString(pressure)); - sample.setThermodynamicSystem(testSystem); - sampleList.add(sample); - } - } catch (Exception e) { - logger.error("database error" + e); - } - SampleSet sampleSet = new SampleSet(sampleList); - optim.setSampleSet(sampleSet); + double temperature = Double.parseDouble(dataSet.getString("Temperature")); + double pressure = Double.parseDouble(dataSet.getString("Pressure")); + testSystem.setPressure(pressure); + testSystem.setTemperature(temperature); + testSystem.chemicalReactionInit(); + // testSystem.createDatabase(true); + testSystem.setMixingRule(4); + testSystem.init(0); + double sample1[] = {testSystem.getPhases()[0].getComponents()[1].getNumberOfMolesInPhase() + / testSystem.getPhases()[0].getComponents()[2].getNumberOfMolesInPhase()}; + double standardDeviation1[] = {0.01}; + double y1 = Double.parseDouble(dataSet.getString("y1")); + SampleValue sample = + new SampleValue(pressure * y1, y1 * pressure / 100.0, sample1, standardDeviation1); + function.setInitialGuess(guess); + sample.setFunction(function); + sample.setReference("addicks"); + sample.setDescription(Double.toString(pressure)); + sample.setThermodynamicSystem(testSystem); + sampleList.add(sample); + } + } catch (Exception e) { + logger.error("database error" + e); + } + SampleSet sampleSet = new SampleSet(sampleList); + optim.setSampleSet(sampleSet); - // do simulations + // do simulations - optim.solve(); - // optim.runMonteCarloSimulation(); - // optim.displayCurveFit(); - // optim.displayGraph(); - optim.displayCurveFit(); - optim.writeToCdfFile("c:/testFit.nc"); - optim.writeToTextFile("c:/testFit.txt"); - } + optim.solve(); + // optim.runMonteCarloSimulation(); + // optim.displayCurveFit(); + // optim.displayGraph(); + optim.displayCurveFit(); + optim.writeToTextFile("c:/testFit.txt"); + } } diff --git a/src/main/java/neqsim/thermo/util/parameterFitting/binaryInteractionParameterFitting/ionicInteractionCoefficientFitting/TestIonicInteractionParameterFittingCo2nacl.java b/src/main/java/neqsim/thermo/util/parameterFitting/binaryInteractionParameterFitting/ionicInteractionCoefficientFitting/TestIonicInteractionParameterFittingCo2nacl.java index 7950906056..e4f7f46921 100644 --- a/src/main/java/neqsim/thermo/util/parameterFitting/binaryInteractionParameterFitting/ionicInteractionCoefficientFitting/TestIonicInteractionParameterFittingCo2nacl.java +++ b/src/main/java/neqsim/thermo/util/parameterFitting/binaryInteractionParameterFitting/ionicInteractionCoefficientFitting/TestIonicInteractionParameterFittingCo2nacl.java @@ -20,80 +20,78 @@ * @version $Id: $Id */ public class TestIonicInteractionParameterFittingCo2nacl { - static Logger logger = LogManager.getLogger(TestIonicInteractionParameterFittingCo2nacl.class); + static Logger logger = LogManager.getLogger(TestIonicInteractionParameterFittingCo2nacl.class); - /** - *

- * main. - *

- * - * @param args an array of {@link java.lang.String} objects - */ - public static void main(String[] args) { - LevenbergMarquardt optim = new LevenbergMarquardt(); - ArrayList sampleList = new ArrayList(); + /** + *

+ * main. + *

+ * + * @param args an array of {@link java.lang.String} objects + */ + public static void main(String[] args) { + LevenbergMarquardt optim = new LevenbergMarquardt(); + ArrayList sampleList = new ArrayList(); - // inserting samples from database - NeqSimDataBase database = new NeqSimDataBase(); - ResultSet dataSet = database.getResultSet( - "SELECT * FROM co2wation WHERE comp3='K+' AND temperature>340 AND pressure<190"); - // ResultSet dataSet = database.getResultSet( "SELECT * FROM - // activityCoefficientTable WHERE Component1='MDEA' AND Component2='water'");AND - // Reference='Lemoine2000' - // double guess[] = {-0.0000110329, -0.1238487876};//Na+ - // double guess[] = {0.0000258505};//Na+ all temp - // double guess[] = {0.0000080642};//Na+ 40 - // double guess[] = {0.0000542456};//Na+ 80 - // double guess[] = { -0.0000442947, -0.1933846606};//k+ - // double guess[] = {-0.00000650867};//k+ 40 - double guess[] = {0.0000267226};// k+ 80 + // inserting samples from database + NeqSimDataBase database = new NeqSimDataBase(); + ResultSet dataSet = database.getResultSet( + "SELECT * FROM co2wation WHERE comp3='K+' AND temperature>340 AND pressure<190"); + // ResultSet dataSet = database.getResultSet( "SELECT * FROM + // activityCoefficientTable WHERE Component1='MDEA' AND Component2='water'");AND + // Reference='Lemoine2000' + // double guess[] = {-0.0000110329, -0.1238487876};//Na+ + // double guess[] = {0.0000258505};//Na+ all temp + // double guess[] = {0.0000080642};//Na+ 40 + // double guess[] = {0.0000542456};//Na+ 80 + // double guess[] = { -0.0000442947, -0.1933846606};//k+ + // double guess[] = {-0.00000650867};//k+ 40 + double guess[] = {0.0000267226};// k+ 80 - try { - int i = 0; - while (dataSet.next() && i < 403) { - i++; - IonicInteractionParameterFittingFunctionCo2nacl function = - new IonicInteractionParameterFittingFunctionCo2nacl(); - double temperature = Double.parseDouble(dataSet.getString("temperature")); - double pressure = Double.parseDouble(dataSet.getString("pressure")); - SystemInterface testSystem = new SystemFurstElectrolyteEos(temperature, pressure); - testSystem.addComponent("CO2", 10.1); - testSystem.addComponent("water", 1.0, "kg/sec"); - testSystem.addComponent(dataSet.getString("comp3"), - Double.parseDouble(dataSet.getString("x3-molal"))); - testSystem.addComponent(dataSet.getString("comp4"), - Double.parseDouble(dataSet.getString("x4-molal"))); - // testSystem.createDatabase(true); - testSystem.setPressure(pressure); - testSystem.setTemperature(temperature); - testSystem.setMixingRule(4); - testSystem.init(0); - double sample1[] = {pressure}; - double standardDeviation1[] = {0.01}; - double value = Double.parseDouble(dataSet.getString("x1-molfrac")); - SampleValue sample = - new SampleValue(value, value / 100.0, sample1, standardDeviation1); - function.setInitialGuess(guess); - sample.setFunction(function); - sample.setDescription(Double.toString(pressure)); - sample.setThermodynamicSystem(testSystem); - sampleList.add(sample); - } - } catch (Exception e) { - logger.error("database error" + e); - } + try { + int i = 0; + while (dataSet.next() && i < 403) { + i++; + IonicInteractionParameterFittingFunctionCo2nacl function = + new IonicInteractionParameterFittingFunctionCo2nacl(); + double temperature = Double.parseDouble(dataSet.getString("temperature")); + double pressure = Double.parseDouble(dataSet.getString("pressure")); + SystemInterface testSystem = new SystemFurstElectrolyteEos(temperature, pressure); + testSystem.addComponent("CO2", 10.1); + testSystem.addComponent("water", 1.0, "kg/sec"); + testSystem.addComponent(dataSet.getString("comp3"), + Double.parseDouble(dataSet.getString("x3-molal"))); + testSystem.addComponent(dataSet.getString("comp4"), + Double.parseDouble(dataSet.getString("x4-molal"))); + // testSystem.createDatabase(true); + testSystem.setPressure(pressure); + testSystem.setTemperature(temperature); + testSystem.setMixingRule(4); + testSystem.init(0); + double sample1[] = {pressure}; + double standardDeviation1[] = {0.01}; + double value = Double.parseDouble(dataSet.getString("x1-molfrac")); + SampleValue sample = new SampleValue(value, value / 100.0, sample1, standardDeviation1); + function.setInitialGuess(guess); + sample.setFunction(function); + sample.setDescription(Double.toString(pressure)); + sample.setThermodynamicSystem(testSystem); + sampleList.add(sample); + } + } catch (Exception e) { + logger.error("database error" + e); + } - SampleSet sampleSet = new SampleSet(sampleList); - optim.setSampleSet(sampleSet); + SampleSet sampleSet = new SampleSet(sampleList); + optim.setSampleSet(sampleSet); - // do simulations + // do simulations - optim.solve(); - // optim.runMonteCarloSimulation(); - // optim.displayCurveFit(); - // optim.displayGraph(); - optim.displayCurveFit(); - optim.writeToCdfFile("c:/testFit.nc"); - optim.writeToTextFile("c:/testFit.txt"); - } + optim.solve(); + // optim.runMonteCarloSimulation(); + // optim.displayCurveFit(); + // optim.displayGraph(); + optim.displayCurveFit(); + optim.writeToTextFile("c:/testFit.txt"); + } } diff --git a/src/main/java/neqsim/thermo/util/parameterFitting/binaryInteractionParameterFitting/ionicInteractionCoefficientFitting/TestIonicInteractionParameterFittingMDEAPiperazine.java b/src/main/java/neqsim/thermo/util/parameterFitting/binaryInteractionParameterFitting/ionicInteractionCoefficientFitting/TestIonicInteractionParameterFittingMDEAPiperazine.java index d336968553..adf2e7f0b1 100644 --- a/src/main/java/neqsim/thermo/util/parameterFitting/binaryInteractionParameterFitting/ionicInteractionCoefficientFitting/TestIonicInteractionParameterFittingMDEAPiperazine.java +++ b/src/main/java/neqsim/thermo/util/parameterFitting/binaryInteractionParameterFitting/ionicInteractionCoefficientFitting/TestIonicInteractionParameterFittingMDEAPiperazine.java @@ -20,75 +20,74 @@ * @version $Id: $Id */ public class TestIonicInteractionParameterFittingMDEAPiperazine { - static Logger logger = - LogManager.getLogger(TestIonicInteractionParameterFittingMDEAPiperazine.class); + static Logger logger = + LogManager.getLogger(TestIonicInteractionParameterFittingMDEAPiperazine.class); - /** - *

- * main. - *

- * - * @param args an array of {@link java.lang.String} objects - */ - public static void main(String[] args) { - LevenbergMarquardt optim = new LevenbergMarquardt(); - ArrayList sampleList = new ArrayList(); + /** + *

+ * main. + *

+ * + * @param args an array of {@link java.lang.String} objects + */ + public static void main(String[] args) { + LevenbergMarquardt optim = new LevenbergMarquardt(); + ArrayList sampleList = new ArrayList(); - // inserting samples from database - NeqSimDataBase database = new NeqSimDataBase(); + // inserting samples from database + NeqSimDataBase database = new NeqSimDataBase(); - double guess[] = {0.0007757516};// , -0.00013534324};//, -0.000210224};//, -0.0002324934, - // 0.0005}; - ResultSet dataSet = database.getResultSet("SELECT * FROM CO2waterPZ");// WHERE - // Temperature<393.15 - // AND - // PressureCO2<4"); + double guess[] = {0.0007757516};// , -0.00013534324};//, -0.000210224};//, -0.0002324934, + // 0.0005}; + ResultSet dataSet = database.getResultSet("SELECT * FROM CO2waterPZ");// WHERE + // Temperature<393.15 + // AND + // PressureCO2<4"); - try { - int i = 0; - while (dataSet.next() && i < 25) { - i++; - IonicInteractionParameterFittingFunctionPiperazine function = - new IonicInteractionParameterFittingFunctionPiperazine(); - SystemInterface testSystem = new SystemFurstElectrolyteEos((273.15 + 25.0), 1.0); - testSystem.addComponent("CO2", Double.parseDouble(dataSet.getString("x1"))); - testSystem.addComponent("Piperazine", Double.parseDouble(dataSet.getString("x3"))); - testSystem.addComponent("water", Double.parseDouble(dataSet.getString("x2"))); - double temperature = Double.parseDouble(dataSet.getString("Temperature")); - double pressure = Double.parseDouble(dataSet.getString("PressureCO2")); - testSystem.setTemperature(temperature); - testSystem.setPressure(pressure + 1.0); - testSystem.chemicalReactionInit(); - testSystem.createDatabase(true); - testSystem.setMixingRule(4); - testSystem.init(0); - double sample1[] = {testSystem.getPhase(0).getComponent(0).getNumberOfmoles() - / testSystem.getPhase(0).getComponent(1).getNumberOfmoles()}; - double standardDeviation1[] = {0.01}; - double stddev = pressure;// Double.parseDouble(dataSet.getString("StandardDeviation")) - SampleValue sample = new SampleValue(pressure, stddev, sample1, standardDeviation1); - function.setInitialGuess(guess); - // function.setBounds(bounds); - sample.setFunction(function); - sample.setReference(dataSet.getString("Reference")); - sample.setThermodynamicSystem(testSystem); - sampleList.add(sample); - } - } catch (Exception e) { - logger.error("database error" + e); - } + try { + int i = 0; + while (dataSet.next() && i < 25) { + i++; + IonicInteractionParameterFittingFunctionPiperazine function = + new IonicInteractionParameterFittingFunctionPiperazine(); + SystemInterface testSystem = new SystemFurstElectrolyteEos((273.15 + 25.0), 1.0); + testSystem.addComponent("CO2", Double.parseDouble(dataSet.getString("x1"))); + testSystem.addComponent("Piperazine", Double.parseDouble(dataSet.getString("x3"))); + testSystem.addComponent("water", Double.parseDouble(dataSet.getString("x2"))); + double temperature = Double.parseDouble(dataSet.getString("Temperature")); + double pressure = Double.parseDouble(dataSet.getString("PressureCO2")); + testSystem.setTemperature(temperature); + testSystem.setPressure(pressure + 1.0); + testSystem.chemicalReactionInit(); + testSystem.createDatabase(true); + testSystem.setMixingRule(4); + testSystem.init(0); + double sample1[] = {testSystem.getPhase(0).getComponent(0).getNumberOfmoles() + / testSystem.getPhase(0).getComponent(1).getNumberOfmoles()}; + double standardDeviation1[] = {0.01}; + double stddev = pressure;// Double.parseDouble(dataSet.getString("StandardDeviation")) + SampleValue sample = new SampleValue(pressure, stddev, sample1, standardDeviation1); + function.setInitialGuess(guess); + // function.setBounds(bounds); + sample.setFunction(function); + sample.setReference(dataSet.getString("Reference")); + sample.setThermodynamicSystem(testSystem); + sampleList.add(sample); + } + } catch (Exception e) { + logger.error("database error" + e); + } - SampleSet sampleSet = new SampleSet(sampleList); - optim.setSampleSet(sampleSet); + SampleSet sampleSet = new SampleSet(sampleList); + optim.setSampleSet(sampleSet); - // do simulations + // do simulations - optim.solve(); - // optim.runMonteCarloSimulation(); - // optim.displayCurveFit(); - // optim.displayGraph(); - optim.displayCurveFit(); - optim.writeToCdfFile("c:/testFit.nc"); - optim.writeToTextFile("c:/testFit.txt"); - } + optim.solve(); + // optim.runMonteCarloSimulation(); + // optim.displayCurveFit(); + // optim.displayGraph(); + optim.displayCurveFit(); + optim.writeToTextFile("c:/testFit.txt"); + } } diff --git a/src/main/java/neqsim/thermo/util/parameterFitting/binaryInteractionParameterFitting/ionicInteractionCoefficientFitting/TestIonicInteractionParameterFittingPiperazine.java b/src/main/java/neqsim/thermo/util/parameterFitting/binaryInteractionParameterFitting/ionicInteractionCoefficientFitting/TestIonicInteractionParameterFittingPiperazine.java index 7999683cd7..7558c1b264 100644 --- a/src/main/java/neqsim/thermo/util/parameterFitting/binaryInteractionParameterFitting/ionicInteractionCoefficientFitting/TestIonicInteractionParameterFittingPiperazine.java +++ b/src/main/java/neqsim/thermo/util/parameterFitting/binaryInteractionParameterFitting/ionicInteractionCoefficientFitting/TestIonicInteractionParameterFittingPiperazine.java @@ -20,75 +20,73 @@ * @version $Id: $Id */ public class TestIonicInteractionParameterFittingPiperazine { - static Logger logger = - LogManager.getLogger(TestIonicInteractionParameterFittingPiperazine.class); + static Logger logger = LogManager.getLogger(TestIonicInteractionParameterFittingPiperazine.class); - /** - *

- * main. - *

- * - * @param args an array of {@link java.lang.String} objects - */ - public static void main(String[] args) { - LevenbergMarquardt optim = new LevenbergMarquardt(); - ArrayList sampleList = new ArrayList(); + /** + *

+ * main. + *

+ * + * @param args an array of {@link java.lang.String} objects + */ + public static void main(String[] args) { + LevenbergMarquardt optim = new LevenbergMarquardt(); + ArrayList sampleList = new ArrayList(); - // inserting samples from database - NeqSimDataBase database = new NeqSimDataBase(); + // inserting samples from database + NeqSimDataBase database = new NeqSimDataBase(); - double guess[] = {-0.0001868490, -0.0006868943, -0.0000210224, -0.0002324934, 0.0005}; - ResultSet dataSet = database.getResultSet("SELECT * FROM CO2waterMDEAPiperazine");// WHERE - // Temperature<393.15 - // AND - // PressureCO2<4"); + double guess[] = {-0.0001868490, -0.0006868943, -0.0000210224, -0.0002324934, 0.0005}; + ResultSet dataSet = database.getResultSet("SELECT * FROM CO2waterMDEAPiperazine");// WHERE + // Temperature<393.15 + // AND + // PressureCO2<4"); - try { - int i = 0; - while (dataSet.next() && i < 16) { - i++; - IonicInteractionParameterFittingFunction function = - new IonicInteractionParameterFittingFunction(); - SystemInterface testSystem = new SystemFurstElectrolyteEos((273.15 + 25.0), 1.0); - testSystem.addComponent("CO2", Double.parseDouble(dataSet.getString("x1"))); - testSystem.addComponent("MDEA", Double.parseDouble(dataSet.getString("x3"))); - testSystem.addComponent("piperazine", Double.parseDouble(dataSet.getString("x4"))); - testSystem.addComponent("water", Double.parseDouble(dataSet.getString("x2"))); - double temperature = Double.parseDouble(dataSet.getString("Temperature")); - double pressure = Double.parseDouble(dataSet.getString("PressureCO2")); - testSystem.setTemperature(temperature); - testSystem.setPressure(pressure + 1.0); - testSystem.chemicalReactionInit(); - testSystem.createDatabase(true); - testSystem.setMixingRule(4); - testSystem.init(0); - double sample1[] = {testSystem.getPhase(0).getComponent(0).getNumberOfmoles() - / testSystem.getPhase(0).getComponent(1).getNumberOfmoles()}; - double standardDeviation1[] = {0.01}; - double stddev = pressure;// Double.parseDouble(dataSet.getString("StandardDeviation")) - SampleValue sample = new SampleValue(pressure, stddev, sample1, standardDeviation1); - function.setInitialGuess(guess); - // function.setBounds(bounds); - sample.setFunction(function); - sample.setReference(dataSet.getString("Reference")); - sample.setThermodynamicSystem(testSystem); - sampleList.add(sample); - } - } catch (Exception e) { - logger.error("database error" + e); - } + try { + int i = 0; + while (dataSet.next() && i < 16) { + i++; + IonicInteractionParameterFittingFunction function = + new IonicInteractionParameterFittingFunction(); + SystemInterface testSystem = new SystemFurstElectrolyteEos((273.15 + 25.0), 1.0); + testSystem.addComponent("CO2", Double.parseDouble(dataSet.getString("x1"))); + testSystem.addComponent("MDEA", Double.parseDouble(dataSet.getString("x3"))); + testSystem.addComponent("piperazine", Double.parseDouble(dataSet.getString("x4"))); + testSystem.addComponent("water", Double.parseDouble(dataSet.getString("x2"))); + double temperature = Double.parseDouble(dataSet.getString("Temperature")); + double pressure = Double.parseDouble(dataSet.getString("PressureCO2")); + testSystem.setTemperature(temperature); + testSystem.setPressure(pressure + 1.0); + testSystem.chemicalReactionInit(); + testSystem.createDatabase(true); + testSystem.setMixingRule(4); + testSystem.init(0); + double sample1[] = {testSystem.getPhase(0).getComponent(0).getNumberOfmoles() + / testSystem.getPhase(0).getComponent(1).getNumberOfmoles()}; + double standardDeviation1[] = {0.01}; + double stddev = pressure;// Double.parseDouble(dataSet.getString("StandardDeviation")) + SampleValue sample = new SampleValue(pressure, stddev, sample1, standardDeviation1); + function.setInitialGuess(guess); + // function.setBounds(bounds); + sample.setFunction(function); + sample.setReference(dataSet.getString("Reference")); + sample.setThermodynamicSystem(testSystem); + sampleList.add(sample); + } + } catch (Exception e) { + logger.error("database error" + e); + } - SampleSet sampleSet = new SampleSet(sampleList); - optim.setSampleSet(sampleSet); + SampleSet sampleSet = new SampleSet(sampleList); + optim.setSampleSet(sampleSet); - // do simulations + // do simulations - // optim.solve(); - // optim.runMonteCarloSimulation(); - // optim.displayCurveFit(); - // optim.displayGraph(); - optim.displayCurveFit(); - optim.writeToCdfFile("c:/testFit.nc"); - optim.writeToTextFile("c:/testFit.txt"); - } + // optim.solve(); + // optim.runMonteCarloSimulation(); + // optim.displayCurveFit(); + // optim.displayGraph(); + optim.displayCurveFit(); + optim.writeToTextFile("c:/testFit.txt"); + } } diff --git a/src/main/java/neqsim/thermo/util/parameterFitting/pureComponentParameterFitting/AntoineParameter/TestSolidAntoine.java b/src/main/java/neqsim/thermo/util/parameterFitting/pureComponentParameterFitting/AntoineParameter/TestSolidAntoine.java index 47ebc218b5..faede50677 100644 --- a/src/main/java/neqsim/thermo/util/parameterFitting/pureComponentParameterFitting/AntoineParameter/TestSolidAntoine.java +++ b/src/main/java/neqsim/thermo/util/parameterFitting/pureComponentParameterFitting/AntoineParameter/TestSolidAntoine.java @@ -20,67 +20,66 @@ * @version $Id: $Id */ public class TestSolidAntoine { - static Logger logger = LogManager.getLogger(TestSolidAntoine.class); + static Logger logger = LogManager.getLogger(TestSolidAntoine.class); - /** - *

- * main. - *

- * - * @param args an array of {@link java.lang.String} objects - */ - public static void main(String[] args) { - LevenbergMarquardt optim = new LevenbergMarquardt(); - ArrayList sampleList = new ArrayList(); + /** + *

+ * main. + *

+ * + * @param args an array of {@link java.lang.String} objects + */ + public static void main(String[] args) { + LevenbergMarquardt optim = new LevenbergMarquardt(); + ArrayList sampleList = new ArrayList(); - // inserting samples from database - NeqSimDataBase database = new NeqSimDataBase(); + // inserting samples from database + NeqSimDataBase database = new NeqSimDataBase(); - // ResultSet dataSet = database.getResultSet( "SELECT * FROM - // BinaryFreezingPointData WHERE ComponentSolvent1='MEG' ORDER BY - // FreezingTemperature"); - ResultSet dataSet = database.getResultSet( - "SELECT * FROM BinaryFreezingPointData WHERE ComponentSolvent1='MEG' ORDER BY FreezingTemperature"); - int i = 0; - try { - while (dataSet.next() && i < 4) { - i++; - AntoineSolidFunction function = new AntoineSolidFunction(); - double guess[] = {-7800.0, 10.09}; // MEG - function.setInitialGuess(guess); + // ResultSet dataSet = database.getResultSet( "SELECT * FROM + // BinaryFreezingPointData WHERE ComponentSolvent1='MEG' ORDER BY + // FreezingTemperature"); + ResultSet dataSet = database.getResultSet( + "SELECT * FROM BinaryFreezingPointData WHERE ComponentSolvent1='MEG' ORDER BY FreezingTemperature"); + int i = 0; + try { + while (dataSet.next() && i < 4) { + i++; + AntoineSolidFunction function = new AntoineSolidFunction(); + double guess[] = {-7800.0, 10.09}; // MEG + function.setInitialGuess(guess); - SystemInterface testSystem = new SystemSrkCPAstatoil(280, 1.101); - testSystem.addComponent(dataSet.getString("ComponentSolvent1"), - Double.parseDouble(dataSet.getString("x1"))); - testSystem.addComponent(dataSet.getString("ComponentSolvent2"), - Double.parseDouble(dataSet.getString("x2"))); - testSystem.createDatabase(true); - testSystem.setMixingRule(7); + SystemInterface testSystem = new SystemSrkCPAstatoil(280, 1.101); + testSystem.addComponent(dataSet.getString("ComponentSolvent1"), + Double.parseDouble(dataSet.getString("x1"))); + testSystem.addComponent(dataSet.getString("ComponentSolvent2"), + Double.parseDouble(dataSet.getString("x2"))); + testSystem.createDatabase(true); + testSystem.setMixingRule(7); - testSystem.setSolidPhaseCheck("MEG"); - testSystem.init(0); - double sample1[] = {testSystem.getPhase(0).getComponent(0).getz()}; - double standardDeviation1[] = {0.1, 0.1, 0.1}; - double val = Double.parseDouble(dataSet.getString("FreezingTemperature")); - testSystem.setTemperature(val); - SampleValue sample = new SampleValue(val, val / 100.0, sample1, standardDeviation1); - sample.setFunction(function); - sample.setReference(dataSet.getString("Reference")); - sample.setThermodynamicSystem(testSystem); - sampleList.add(sample); - } - } catch (Exception e) { - logger.error("database error" + e); - } + testSystem.setSolidPhaseCheck("MEG"); + testSystem.init(0); + double sample1[] = {testSystem.getPhase(0).getComponent(0).getz()}; + double standardDeviation1[] = {0.1, 0.1, 0.1}; + double val = Double.parseDouble(dataSet.getString("FreezingTemperature")); + testSystem.setTemperature(val); + SampleValue sample = new SampleValue(val, val / 100.0, sample1, standardDeviation1); + sample.setFunction(function); + sample.setReference(dataSet.getString("Reference")); + sample.setThermodynamicSystem(testSystem); + sampleList.add(sample); + } + } catch (Exception e) { + logger.error("database error" + e); + } - SampleSet sampleSet = new SampleSet(sampleList); - optim.setSampleSet(sampleSet); + SampleSet sampleSet = new SampleSet(sampleList); + optim.setSampleSet(sampleSet); - // do simulations - // optim.solve(); - // optim.runMonteCarloSimulation(); - optim.displayCurveFit(); - optim.writeToCdfFile("c:/testFit.nc"); - optim.writeToTextFile("c:/testFit.txt"); - } + // do simulations + // optim.solve(); + // optim.runMonteCarloSimulation(); + optim.displayCurveFit(); + // optim.writeToTextFile("c:/testFit.txt"); + } } diff --git a/src/main/java/neqsim/thermo/util/parameterFitting/pureComponentParameterFitting/AntoineParameter/TestSolidAntoine_S8.java b/src/main/java/neqsim/thermo/util/parameterFitting/pureComponentParameterFitting/AntoineParameter/TestSolidAntoine_S8.java index 9778aa152a..abe8b1c2df 100644 --- a/src/main/java/neqsim/thermo/util/parameterFitting/pureComponentParameterFitting/AntoineParameter/TestSolidAntoine_S8.java +++ b/src/main/java/neqsim/thermo/util/parameterFitting/pureComponentParameterFitting/AntoineParameter/TestSolidAntoine_S8.java @@ -20,59 +20,58 @@ * @version $Id: $Id */ public class TestSolidAntoine_S8 { - static Logger logger = LogManager.getLogger(TestSolidAntoine_S8.class); + static Logger logger = LogManager.getLogger(TestSolidAntoine_S8.class); - /** - *

- * main. - *

- * - * @param args an array of {@link java.lang.String} objects - */ - public static void main(String[] args) { - LevenbergMarquardt optim = new LevenbergMarquardt(); - ArrayList sampleList = new ArrayList(); + /** + *

+ * main. + *

+ * + * @param args an array of {@link java.lang.String} objects + */ + public static void main(String[] args) { + LevenbergMarquardt optim = new LevenbergMarquardt(); + ArrayList sampleList = new ArrayList(); - // inserting samples from database - NeqSimDataBase database = new NeqSimDataBase(); + // inserting samples from database + NeqSimDataBase database = new NeqSimDataBase(); - ResultSet dataSet = database.getResultSet( - "SELECT * FROM PureComponentVapourPressures WHERE ComponentName='S8' AND VapourPressure<100"); + ResultSet dataSet = database.getResultSet( + "SELECT * FROM PureComponentVapourPressures WHERE ComponentName='S8' AND VapourPressure<100"); - try { - while (dataSet.next()) { - AntoineSolidFunctionS8 function = new AntoineSolidFunctionS8(); - // double guess[] = {8.046, -4600.0, -144.0}; // S8 - double guess[] = {1.181E1, -8.356E3}; // S8 - function.setInitialGuess(guess); + try { + while (dataSet.next()) { + AntoineSolidFunctionS8 function = new AntoineSolidFunctionS8(); + // double guess[] = {8.046, -4600.0, -144.0}; // S8 + double guess[] = {1.181E1, -8.356E3}; // S8 + function.setInitialGuess(guess); - SystemInterface testSystem = new SystemSrkEos(280, 0.001); - testSystem.addComponent(dataSet.getString("ComponentName"), 100.0); + SystemInterface testSystem = new SystemSrkEos(280, 0.001); + testSystem.addComponent(dataSet.getString("ComponentName"), 100.0); - double sample1[] = {Double.parseDouble(dataSet.getString("Temperature"))}; - double vappres = Double.parseDouble(dataSet.getString("VapourPressure")); - double standardDeviation1[] = {0.15}; - SampleValue sample = new SampleValue(vappres, - Double.parseDouble(dataSet.getString("StandardDeviation")), sample1, - standardDeviation1); - sample.setFunction(function); + double sample1[] = {Double.parseDouble(dataSet.getString("Temperature"))}; + double vappres = Double.parseDouble(dataSet.getString("VapourPressure")); + double standardDeviation1[] = {0.15}; + SampleValue sample = + new SampleValue(vappres, Double.parseDouble(dataSet.getString("StandardDeviation")), + sample1, standardDeviation1); + sample.setFunction(function); - function.setInitialGuess(guess); - sample.setThermodynamicSystem(testSystem); - sampleList.add(sample); - } - } catch (Exception e) { - logger.error("database error" + e); - } + function.setInitialGuess(guess); + sample.setThermodynamicSystem(testSystem); + sampleList.add(sample); + } + } catch (Exception e) { + logger.error("database error" + e); + } - SampleSet sampleSet = new SampleSet(sampleList); - optim.setSampleSet(sampleSet); + SampleSet sampleSet = new SampleSet(sampleList); + optim.setSampleSet(sampleSet); - // do simulations - optim.solve(); - // optim.runMonteCarloSimulation(); - optim.displayCurveFit(); - optim.writeToCdfFile("c:/testFit.nc"); - optim.writeToTextFile("c:/testFit.txt"); - } + // do simulations + optim.solve(); + // optim.runMonteCarloSimulation(); + optim.displayCurveFit(); + // optim.writeToTextFile("c:/testFit.txt"); + } } diff --git a/src/main/java/neqsim/thermo/util/parameterFitting/pureComponentParameterFitting/acentricFactorFitting/TestAcentricSchwartzentruber.java b/src/main/java/neqsim/thermo/util/parameterFitting/pureComponentParameterFitting/acentricFactorFitting/TestAcentricSchwartzentruber.java index 92a6c4c0fe..2258531f7b 100644 --- a/src/main/java/neqsim/thermo/util/parameterFitting/pureComponentParameterFitting/acentricFactorFitting/TestAcentricSchwartzentruber.java +++ b/src/main/java/neqsim/thermo/util/parameterFitting/pureComponentParameterFitting/acentricFactorFitting/TestAcentricSchwartzentruber.java @@ -20,85 +20,84 @@ * @version $Id: $Id */ public class TestAcentricSchwartzentruber { - static Logger logger = LogManager.getLogger(TestAcentricSchwartzentruber.class); + static Logger logger = LogManager.getLogger(TestAcentricSchwartzentruber.class); - /** - *

- * main. - *

- * - * @param args an array of {@link java.lang.String} objects - */ - public static void main(String[] args) { - LevenbergMarquardt optim = new LevenbergMarquardt(); - ArrayList sampleList = new ArrayList(); + /** + *

+ * main. + *

+ * + * @param args an array of {@link java.lang.String} objects + */ + public static void main(String[] args) { + LevenbergMarquardt optim = new LevenbergMarquardt(); + ArrayList sampleList = new ArrayList(); - // inserting samples from database - NeqSimDataBase database = new NeqSimDataBase(); - // ResultSet dataSet = database.getResultSet( "SELECT * FROM - // PureComponentVapourPressures WHERE ComponentName='water' ORDER BY - // Reference,Temperature"); - // ResultSet dataSet = database.getResultSet( "SELECT * FROM - // PureComponentVapourPressures WHERE ComponentName='Piperazine'"); - // ResultSet dataSet = database.getResultSet( "SELECT * FROM - // PureComponentVapourPressures WHERE ComponentName='MDEA' ORDER BY - // Reference,Temperature"); - // ResultSet dataSet = database.getResultSet( "SELECT * FROM - // PureComponentVapourPressures WHERE ComponentName='MEG' ORDER BY - // Reference,Temperature"); - // ResultSet dataSet = database.getResultSet( "SELECT * FROM - // PureComponentVapourPressures WHERE ComponentName='nitrogen' AND - // VapourPressure<20"); - ResultSet dataSet = database.getResultSet( - "SELECT * FROM PureComponentVapourPressures WHERE ComponentName='mercury' AND VapourPressure<40 ORDER BY Reference,Temperature"); - // ResultSet dataSet = database.getResultSet( "SELECT * FROM - // PureComponentVapourPressures WHERE ComponentName='TEG' AND VapourPressure<0.5 - // ORDER BY Reference,Temperature"); - try { - while (dataSet.next()) { - // AcentricFunctionScwartzentruber function = new - // AcentricFunctionScwartzentruber(); - TwuCoon function = new TwuCoon(); - // MathiasCopeman function = new MathiasCopeman(); - // double guess[] = {0.0547834254, 0.0946785127, -2.2673294034}; // water - // double guess[] = {0.00492, 0.00492, -0.00626}; // MDEA - // double guess[] = {0.1662109957e-10, -11.5970369560e-10, 13.5388889636e-10}; - // // CO2 - // double guess[] ={0.0685841688, 0.9851816962, 4.2394590417} ; //mercury HYSYS - // - Pc=1608bara + // inserting samples from database + NeqSimDataBase database = new NeqSimDataBase(); + // ResultSet dataSet = database.getResultSet( "SELECT * FROM + // PureComponentVapourPressures WHERE ComponentName='water' ORDER BY + // Reference,Temperature"); + // ResultSet dataSet = database.getResultSet( "SELECT * FROM + // PureComponentVapourPressures WHERE ComponentName='Piperazine'"); + // ResultSet dataSet = database.getResultSet( "SELECT * FROM + // PureComponentVapourPressures WHERE ComponentName='MDEA' ORDER BY + // Reference,Temperature"); + // ResultSet dataSet = database.getResultSet( "SELECT * FROM + // PureComponentVapourPressures WHERE ComponentName='MEG' ORDER BY + // Reference,Temperature"); + // ResultSet dataSet = database.getResultSet( "SELECT * FROM + // PureComponentVapourPressures WHERE ComponentName='nitrogen' AND + // VapourPressure<20"); + ResultSet dataSet = database.getResultSet( + "SELECT * FROM PureComponentVapourPressures WHERE ComponentName='mercury' AND VapourPressure<40 ORDER BY Reference,Temperature"); + // ResultSet dataSet = database.getResultSet( "SELECT * FROM + // PureComponentVapourPressures WHERE ComponentName='TEG' AND VapourPressure<0.5 + // ORDER BY Reference,Temperature"); + try { + while (dataSet.next()) { + // AcentricFunctionScwartzentruber function = new + // AcentricFunctionScwartzentruber(); + TwuCoon function = new TwuCoon(); + // MathiasCopeman function = new MathiasCopeman(); + // double guess[] = {0.0547834254, 0.0946785127, -2.2673294034}; // water + // double guess[] = {0.00492, 0.00492, -0.00626}; // MDEA + // double guess[] = {0.1662109957e-10, -11.5970369560e-10, 13.5388889636e-10}; + // // CO2 + // double guess[] ={0.0685841688, 0.9851816962, 4.2394590417} ; //mercury HYSYS + // - Pc=1608bara - double guess[] = {0.09245, 0.9784, 2.244}; - // double guess[] ={0.1208932305, 0.9580163852, 0.9875864928} ; //mercury PROII - - // double guess[] = {0.4563609446};//, -140.87783836,44.122}; // nitrogen - function.setInitialGuess(guess); + double guess[] = {0.09245, 0.9784, 2.244}; + // double guess[] ={0.1208932305, 0.9580163852, 0.9875864928} ; //mercury PROII - + // double guess[] = {0.4563609446};//, -140.87783836,44.122}; // nitrogen + function.setInitialGuess(guess); - // SystemInterface testSystem = new SystemSrkSchwartzentruberEos(280, 0.101); - SystemInterface testSystem = new SystemSrkTwuCoonParamEos(280, 0.01); - // SystemInterface testSystem = new SystemPrEos1978(280, 0.01); - // testSystem.setAttractiveTerm(13); - testSystem.addComponent(dataSet.getString("ComponentName"), 100.0); - // testSystem.createDatabase(true); - double sample1[] = {Double.parseDouble(dataSet.getString("Temperature"))}; - double standardDeviation1[] = {0.1, 0.1, 0.1}; - double val = Math.log(Double.parseDouble(dataSet.getString("VapourPressure"))); - SampleValue sample = new SampleValue(val, val / 100.0, sample1, standardDeviation1); - sample.setFunction(function); - sample.setReference(dataSet.getString("Reference")); - sample.setThermodynamicSystem(testSystem); - sampleList.add(sample); - } - } catch (Exception e) { - logger.error("database error" + e); - } + // SystemInterface testSystem = new SystemSrkSchwartzentruberEos(280, 0.101); + SystemInterface testSystem = new SystemSrkTwuCoonParamEos(280, 0.01); + // SystemInterface testSystem = new SystemPrEos1978(280, 0.01); + // testSystem.setAttractiveTerm(13); + testSystem.addComponent(dataSet.getString("ComponentName"), 100.0); + // testSystem.createDatabase(true); + double sample1[] = {Double.parseDouble(dataSet.getString("Temperature"))}; + double standardDeviation1[] = {0.1, 0.1, 0.1}; + double val = Math.log(Double.parseDouble(dataSet.getString("VapourPressure"))); + SampleValue sample = new SampleValue(val, val / 100.0, sample1, standardDeviation1); + sample.setFunction(function); + sample.setReference(dataSet.getString("Reference")); + sample.setThermodynamicSystem(testSystem); + sampleList.add(sample); + } + } catch (Exception e) { + logger.error("database error" + e); + } - SampleSet sampleSet = new SampleSet(sampleList); - optim.setSampleSet(sampleSet); + SampleSet sampleSet = new SampleSet(sampleList); + optim.setSampleSet(sampleSet); - // do simulations - // optim.solve(); - optim.runMonteCarloSimulation(); - optim.displayCurveFit(); - // optim.writeToCdfFile("c:/testFit.nc"); - // optim.writeToTextFile("c:/testFit.txt"); - } + // do simulations + // optim.solve(); + optim.runMonteCarloSimulation(); + optim.displayCurveFit(); + // optim.writeToTextFile("c:/testFit.txt"); + } } diff --git a/src/main/java/neqsim/thermo/util/parameterFitting/pureComponentParameterFitting/acentricFactorFitting/TestFitToAntoineVapPres.java b/src/main/java/neqsim/thermo/util/parameterFitting/pureComponentParameterFitting/acentricFactorFitting/TestFitToAntoineVapPres.java index bcda35d3ef..792041e5e3 100644 --- a/src/main/java/neqsim/thermo/util/parameterFitting/pureComponentParameterFitting/acentricFactorFitting/TestFitToAntoineVapPres.java +++ b/src/main/java/neqsim/thermo/util/parameterFitting/pureComponentParameterFitting/acentricFactorFitting/TestFitToAntoineVapPres.java @@ -18,66 +18,62 @@ * @version $Id: $Id */ public class TestFitToAntoineVapPres { - static Logger logger = LogManager.getLogger(TestFitToAntoineVapPres.class); + static Logger logger = LogManager.getLogger(TestFitToAntoineVapPres.class); - /** - *

- * main. - *

- * - * @param args an array of {@link java.lang.String} objects - */ - @SuppressWarnings("unused") - public static void main(String[] args) { - LevenbergMarquardt optim = new LevenbergMarquardt(); - ArrayList sampleList = new ArrayList(); + /** + *

+ * main. + *

+ * + * @param args an array of {@link java.lang.String} objects + */ + @SuppressWarnings("unused") + public static void main(String[] args) { + LevenbergMarquardt optim = new LevenbergMarquardt(); + ArrayList sampleList = new ArrayList(); - try { - for (int i = 0; i < 30; i++) { - AcentricFunctionScwartzentruber function = new AcentricFunctionScwartzentruber(); - // double guess[] = {0.5212918734, -1.1520807481, -0.0138898820}; // Piperazine - double guess[] = {0.1032, 0.00365, -2.064}; // AceticAcid - function.setInitialGuess(guess); + try { + for (int i = 0; i < 30; i++) { + AcentricFunctionScwartzentruber function = new AcentricFunctionScwartzentruber(); + // double guess[] = {0.5212918734, -1.1520807481, -0.0138898820}; // Piperazine + double guess[] = {0.1032, 0.00365, -2.064}; // AceticAcid + function.setInitialGuess(guess); - SystemInterface testSystem = - new SystemSrkSchwartzentruberEos(273.15 + i * 5, 1.101); - // testSystem.addComponent("Piperazine", 100.0); - testSystem.addComponent("AceticAcid", 100.0); - testSystem.createDatabase(true); - testSystem.setMixingRule(0); + SystemInterface testSystem = new SystemSrkSchwartzentruberEos(273.15 + i * 5, 1.101); + // testSystem.addComponent("Piperazine", 100.0); + testSystem.addComponent("AceticAcid", 100.0); + testSystem.createDatabase(true); + testSystem.setMixingRule(0); - SystemInterface testSystemAntoine = - new SystemSrkSchwartzentruberEos(273.15 + i * 5, 1.101); - // testSystemAntoine.addComponent("Piperazine", 100.0); - testSystemAntoine.addComponent("AceticAcid", 100.0); - testSystemAntoine.setMixingRule(0); - neqsim.thermodynamicOperations.ThermodynamicOperations opsAntione = - new neqsim.thermodynamicOperations.ThermodynamicOperations( - testSystemAntoine); + SystemInterface testSystemAntoine = new SystemSrkSchwartzentruberEos(273.15 + i * 5, 1.101); + // testSystemAntoine.addComponent("Piperazine", 100.0); + testSystemAntoine.addComponent("AceticAcid", 100.0); + testSystemAntoine.setMixingRule(0); + neqsim.thermodynamicOperations.ThermodynamicOperations opsAntione = + new neqsim.thermodynamicOperations.ThermodynamicOperations(testSystemAntoine); - double sample1[] = {i * 5 + 273.15}; - double standardDeviation1[] = {0.1, 0.1, 0.1}; - double val = Math.log(testSystemAntoine.getPhase(0).getComponent(0) - .getAntoineVaporPressure(273.15 + i * 5)); - // opsAntione.bubblePointPressureFlash(false); - // double val = Math.log(testSystemAntoine.getPressure()); - SampleValue sample = new SampleValue(val, val / 100.0, sample1, standardDeviation1); - sample.setFunction(function); - sample.setThermodynamicSystem(testSystem); - sampleList.add(sample); - } - } catch (Exception e) { - logger.info("database error" + e); - } + double sample1[] = {i * 5 + 273.15}; + double standardDeviation1[] = {0.1, 0.1, 0.1}; + double val = Math.log( + testSystemAntoine.getPhase(0).getComponent(0).getAntoineVaporPressure(273.15 + i * 5)); + // opsAntione.bubblePointPressureFlash(false); + // double val = Math.log(testSystemAntoine.getPressure()); + SampleValue sample = new SampleValue(val, val / 100.0, sample1, standardDeviation1); + sample.setFunction(function); + sample.setThermodynamicSystem(testSystem); + sampleList.add(sample); + } + } catch (Exception e) { + logger.info("database error" + e); + } - SampleSet sampleSet = new SampleSet(sampleList); - optim.setSampleSet(sampleSet); + SampleSet sampleSet = new SampleSet(sampleList); + optim.setSampleSet(sampleSet); - // do simulations - // optim.solve(); - // optim.runMonteCarloSimulation(); - optim.displayCurveFit(); - // optim.writeToCdfFile("c:/testFit.nc"); - // optim.writeToTextFile("c:/testFit.txt"); - } + // do simulations + // optim.solve(); + // optim.runMonteCarloSimulation(); + optim.displayCurveFit(); + // optim.writeToTextFile("c:/testFit.txt"); + } } diff --git a/src/main/java/neqsim/thermo/util/parameterFitting/pureComponentParameterFitting/acentricFactorFitting/TestMathiasCopeman.java b/src/main/java/neqsim/thermo/util/parameterFitting/pureComponentParameterFitting/acentricFactorFitting/TestMathiasCopeman.java index f00e2d36ea..309c5a1608 100644 --- a/src/main/java/neqsim/thermo/util/parameterFitting/pureComponentParameterFitting/acentricFactorFitting/TestMathiasCopeman.java +++ b/src/main/java/neqsim/thermo/util/parameterFitting/pureComponentParameterFitting/acentricFactorFitting/TestMathiasCopeman.java @@ -20,111 +20,110 @@ * @version $Id: $Id */ public class TestMathiasCopeman { - static Logger logger = LogManager.getLogger(TestMathiasCopeman.class); - - /** - *

- * main. - *

- * - * @param args an array of {@link java.lang.String} objects - */ - public static void main(String[] args) { - LevenbergMarquardt optim = new LevenbergMarquardt(); - ArrayList sampleList = new ArrayList(); - - // String ComponentName = "CO2"; - String ComponentName = "methane"; - // String ComponentName = "ethane"; - // String ComponentName = "propane"; - // String ComponentName = "n-butane"; - // String ComponentName = "i-butane"; - // String ComponentName = "i-pentane"; - // String ComponentName = "n-pentane"; - // String ComponentName = "nitrogen"; - // String ComponentName = "neon"; - - try { - // for(int i=0;i<30;i++){ - MathiasCopeman function = new MathiasCopeman(); - // double guess[] = {0.8817389299100502,-0.8562550217314793,3.0949393273488686}; - // // CO2 chi sqr 0.0025 - double guess[] = {0.5379142011507664, -0.3219393792621987, 0.4361033659755846}; // Methane - // chi - // sqr - // 0.1425 - // double guess[] ={0.654848543521529,-0.18438917116800416,0.2601600498810114} ; - // // ethane chi sqr 0.35 - // double guess[] ={0.721211485876844,-0.09921664231818139,0.18182922712791916} - // ; // PROPANE chi sqr 0.2645 - // double guess[] ={0.8080635549718828,-0.21272494485460103,0.36296147537551615} - // ; // n-butane chi sqr 0.2645 - // double guess[] ={0.7803883597786199,-0.27338954339527566,0.6597871185507804} - // ; // i-butane chi sqr 0.166 - // double guess[] ={0.8578874087217438,-0.26763822614020133,0.4586427557929788} - // ; // i-pentane chi sqr 0.699 - // double guess[] ={0.9038611341253704,-0.3585531518594213,0.6638852213604798} ; - // // n-pentane chi sqr 0.827 - // double guess[] ={0.5742583288610631,-0.3225948761079366,0.5906544971686629} ; - // // nitrogen chi sqr 0.05144 - // double guess[] ={0.4844539990236587,-0.5088139220535864,0.7223945129559358} ; - // // neon chi sqr 0.0577 - - function.setInitialGuess(guess); - - // SystemInterface testSystem = new SystemSrkSchwartzentruberEos(40, 1); - // SystemInterface testSystem = new SystemSrkEos(280, 1); - SystemInterface testSystem = new SystemSrkMathiasCopeman(280, 5); - testSystem.addComponent(ComponentName, 100.0); - // testSystem.addComponent(ComponentName2, 100.0); - testSystem.setMixingRule(2); - - testSystem.createDatabase(true); - - // SystemInterface System2 = new SystemSrkSchwartzentruberEos(280, 5); - SystemInterface System2 = new SystemSrkTwuCoonEos(280, 5); - - System2.addComponent(ComponentName, 100.0); - // System2.addComponent(ComponentName2, 100.0); - System2.setMixingRule(2); - ThermodynamicOperations Ops = new ThermodynamicOperations(System2); - - double Ttp = testSystem.getPhase(0).getComponent(0).getTriplePointTemperature(); - double TC = testSystem.getPhase(0).getComponent(0).getTC(); - - for (int i = 0; i < 30; i++) { - double temperature = Ttp + ((TC - Ttp) / 30) * i; - // kan legge inn dewTflash for aa finne avvik til tilsvarende linje med - // schwarzentruber... da ogsaa for flerkomponent blandinger istedenfor antoine - // ligningen. - // double pressure = - // testSystem.getPhase(0).7getComponent(0).getAntoineVaporPressure(temperature); - System2.setTemperature(temperature); - Ops.dewPointPressureFlash(); - double pressure = System2.getPressure(); - - double sample1[] = {temperature}; - double standardDeviation1[] = {0.1, 0.1, 0.1}; - double val = Math.log(pressure); - SampleValue sample = new SampleValue(val, val / 100.0, sample1, standardDeviation1); - sample.setFunction(function); - sample.setReference("NIST"); - sample.setThermodynamicSystem(testSystem); - sampleList.add(sample); - } - } catch (Exception e) { - logger.error("database error" + e); - } - - SampleSet sampleSet = new SampleSet(sampleList); - optim.setSampleSet(sampleSet); - - // do simulations - - // optim.solve(); - // optim.runMonteCarloSimulation(); - optim.displayCurveFit(); - // optim.writeToCdfFile("c:/testFit.nc"); - // optim.writeToTextFile("c:/testFit.txt"); + static Logger logger = LogManager.getLogger(TestMathiasCopeman.class); + + /** + *

+ * main. + *

+ * + * @param args an array of {@link java.lang.String} objects + */ + public static void main(String[] args) { + LevenbergMarquardt optim = new LevenbergMarquardt(); + ArrayList sampleList = new ArrayList(); + + // String ComponentName = "CO2"; + String ComponentName = "methane"; + // String ComponentName = "ethane"; + // String ComponentName = "propane"; + // String ComponentName = "n-butane"; + // String ComponentName = "i-butane"; + // String ComponentName = "i-pentane"; + // String ComponentName = "n-pentane"; + // String ComponentName = "nitrogen"; + // String ComponentName = "neon"; + + try { + // for(int i=0;i<30;i++){ + MathiasCopeman function = new MathiasCopeman(); + // double guess[] = {0.8817389299100502,-0.8562550217314793,3.0949393273488686}; + // // CO2 chi sqr 0.0025 + double guess[] = {0.5379142011507664, -0.3219393792621987, 0.4361033659755846}; // Methane + // chi + // sqr + // 0.1425 + // double guess[] ={0.654848543521529,-0.18438917116800416,0.2601600498810114} ; + // // ethane chi sqr 0.35 + // double guess[] ={0.721211485876844,-0.09921664231818139,0.18182922712791916} + // ; // PROPANE chi sqr 0.2645 + // double guess[] ={0.8080635549718828,-0.21272494485460103,0.36296147537551615} + // ; // n-butane chi sqr 0.2645 + // double guess[] ={0.7803883597786199,-0.27338954339527566,0.6597871185507804} + // ; // i-butane chi sqr 0.166 + // double guess[] ={0.8578874087217438,-0.26763822614020133,0.4586427557929788} + // ; // i-pentane chi sqr 0.699 + // double guess[] ={0.9038611341253704,-0.3585531518594213,0.6638852213604798} ; + // // n-pentane chi sqr 0.827 + // double guess[] ={0.5742583288610631,-0.3225948761079366,0.5906544971686629} ; + // // nitrogen chi sqr 0.05144 + // double guess[] ={0.4844539990236587,-0.5088139220535864,0.7223945129559358} ; + // // neon chi sqr 0.0577 + + function.setInitialGuess(guess); + + // SystemInterface testSystem = new SystemSrkSchwartzentruberEos(40, 1); + // SystemInterface testSystem = new SystemSrkEos(280, 1); + SystemInterface testSystem = new SystemSrkMathiasCopeman(280, 5); + testSystem.addComponent(ComponentName, 100.0); + // testSystem.addComponent(ComponentName2, 100.0); + testSystem.setMixingRule(2); + + testSystem.createDatabase(true); + + // SystemInterface System2 = new SystemSrkSchwartzentruberEos(280, 5); + SystemInterface System2 = new SystemSrkTwuCoonEos(280, 5); + + System2.addComponent(ComponentName, 100.0); + // System2.addComponent(ComponentName2, 100.0); + System2.setMixingRule(2); + ThermodynamicOperations Ops = new ThermodynamicOperations(System2); + + double Ttp = testSystem.getPhase(0).getComponent(0).getTriplePointTemperature(); + double TC = testSystem.getPhase(0).getComponent(0).getTC(); + + for (int i = 0; i < 30; i++) { + double temperature = Ttp + ((TC - Ttp) / 30) * i; + // kan legge inn dewTflash for aa finne avvik til tilsvarende linje med + // schwarzentruber... da ogsaa for flerkomponent blandinger istedenfor antoine + // ligningen. + // double pressure = + // testSystem.getPhase(0).7getComponent(0).getAntoineVaporPressure(temperature); + System2.setTemperature(temperature); + Ops.dewPointPressureFlash(); + double pressure = System2.getPressure(); + + double sample1[] = {temperature}; + double standardDeviation1[] = {0.1, 0.1, 0.1}; + double val = Math.log(pressure); + SampleValue sample = new SampleValue(val, val / 100.0, sample1, standardDeviation1); + sample.setFunction(function); + sample.setReference("NIST"); + sample.setThermodynamicSystem(testSystem); + sampleList.add(sample); + } + } catch (Exception e) { + logger.error("database error" + e); } + + SampleSet sampleSet = new SampleSet(sampleList); + optim.setSampleSet(sampleSet); + + // do simulations + + // optim.solve(); + // optim.runMonteCarloSimulation(); + optim.displayCurveFit(); + // optim.writeToTextFile("c:/testFit.txt"); + } } diff --git a/src/main/java/neqsim/thermo/util/parameterFitting/pureComponentParameterFitting/acentricFactorFitting/TestMathiasCopemanToDewPoint.java b/src/main/java/neqsim/thermo/util/parameterFitting/pureComponentParameterFitting/acentricFactorFitting/TestMathiasCopemanToDewPoint.java index a51b643a30..79169abba6 100644 --- a/src/main/java/neqsim/thermo/util/parameterFitting/pureComponentParameterFitting/acentricFactorFitting/TestMathiasCopemanToDewPoint.java +++ b/src/main/java/neqsim/thermo/util/parameterFitting/pureComponentParameterFitting/acentricFactorFitting/TestMathiasCopemanToDewPoint.java @@ -20,158 +20,153 @@ * @version $Id: $Id */ public class TestMathiasCopemanToDewPoint { - static Logger logger = LogManager.getLogger(TestMathiasCopemanToDewPoint.class); - - /** - *

- * main. - *

- * - * @param args an array of {@link java.lang.String} objects - */ - public static void main(String[] args) { - LevenbergMarquardt optim = new LevenbergMarquardt(); - ArrayList sampleList = new ArrayList(); - - // inserting samples from database - NeqSimDataBase database = new NeqSimDataBase(); - ResultSet dataSet = null; - - // // PVTsim14 values for MC-parameters - // double guess[] ={0.547, -0.399, 0.575, // methane - // 0.685, -0.428, 0.738, //ethane - // 0.773, -0.509, 1.031, // propane - // 0.849, -0.552, 1.077, //n-butane) - // 0.780, -0.273,0.659, //i-butane - // 0.937, -0.766, 1.848, // n-pentane - // 0.547, -0.399, 1.575, //c-hexane - // 0.846, -0.386, 0.884, // benzene - // 1.087, -0.747, 1.577} ; //n-heptane - - // initial guess - // double guess[] ={1.4184728684, -1.6053750221, 0.7429086086, // methane - // 1.6853, -0.4284, 0.7382, //ethane - // 1.8653, -1.4386, 1.3447, // propane - // 1.8080, -0.2127, 1.3629, //n-butane) - // 1.78038835, -1.273389543,0.659787118550, //i-butane - // 0.903861134, -0.3585531518594, 0.66388522, // n-pentane - // 0.547, -1.399, 1.575, //c-hexane - // 0.8457,-1.3856,1.8843, // benzene - // 1.0874, -1.7465, 1.5765} ; //n-heptane - - // optimized chi-square: 21706 abs dev 2.65 - double guess[] = {0.7131945439, 0.4140076386, -2.5691833434, 4.3710359391, -1.1086000763, - 7.3866869416, 1.1183339865, -2.1831081128, 0.9948380388, 1.5665073967, - -5.5636308059, -1.4091055663, 0.8232405436, -0.3922156128, -1.4347079752, - 1.3771397711, -1.2103436623, 0.0028643344, 1.3423413878, -0.3330681068, - -2.1604332713, 1.1554915030, -1.7359747766, 1.1084438340, 1.1800358360, - -1.4810259893, 1.4887592454}; - String nameList[] = {"methane", "ethane", "propane", "n-butane", "i-butane", "n-pentane", - "c-hexane", "benzene", "n-heptane"}; - - for (int compNumb = 0; compNumb < nameList.length; compNumb++) { - dataSet = database - .getResultSet("SELECT * FROM PureComponentVapourPressures WHERE ComponentName='" - + nameList[compNumb] - + "' AND VapourPressure>0 ORDER BY Temperature ASC"); - - try { - long numberOfPoint = 3; - logger.error("point " + numberOfPoint); - int i = 0; - while (dataSet.next()) { - i++; - if (i % numberOfPoint == 0) { - MathiasCopemanToDewPoint function = new MathiasCopemanToDewPoint(); - function.setInitialGuess(guess); - - SystemInterface testSystem = new SystemSrkMathiasCopeman( - Double.parseDouble(dataSet.getString("Temperature")), - Double.parseDouble(dataSet.getString("VapourPressure"))); - testSystem.addComponent(dataSet.getString("ComponentName"), 100.0); - // testSystem.createDatabase(true); - double sample1[] = {testSystem.getPressure()}; - double standardDeviation1[] = {0.1, 0.1, 0.1}; - double val = testSystem.getTemperature(); - double stdErr = 1.0; - SampleValue sample = - new SampleValue(val, stdErr, sample1, standardDeviation1); - sample.setFunction(function); - sample.setReference(dataSet.getString("Reference")); - sample.setThermodynamicSystem(testSystem); - sampleList.add(sample); - } - } - } catch (Exception e) { - logger.error("database error" + e); - } + static Logger logger = LogManager.getLogger(TestMathiasCopemanToDewPoint.class); + + /** + *

+ * main. + *

+ * + * @param args an array of {@link java.lang.String} objects + */ + public static void main(String[] args) { + LevenbergMarquardt optim = new LevenbergMarquardt(); + ArrayList sampleList = new ArrayList(); + + // inserting samples from database + NeqSimDataBase database = new NeqSimDataBase(); + ResultSet dataSet = null; + + // // PVTsim14 values for MC-parameters + // double guess[] ={0.547, -0.399, 0.575, // methane + // 0.685, -0.428, 0.738, //ethane + // 0.773, -0.509, 1.031, // propane + // 0.849, -0.552, 1.077, //n-butane) + // 0.780, -0.273,0.659, //i-butane + // 0.937, -0.766, 1.848, // n-pentane + // 0.547, -0.399, 1.575, //c-hexane + // 0.846, -0.386, 0.884, // benzene + // 1.087, -0.747, 1.577} ; //n-heptane + + // initial guess + // double guess[] ={1.4184728684, -1.6053750221, 0.7429086086, // methane + // 1.6853, -0.4284, 0.7382, //ethane + // 1.8653, -1.4386, 1.3447, // propane + // 1.8080, -0.2127, 1.3629, //n-butane) + // 1.78038835, -1.273389543,0.659787118550, //i-butane + // 0.903861134, -0.3585531518594, 0.66388522, // n-pentane + // 0.547, -1.399, 1.575, //c-hexane + // 0.8457,-1.3856,1.8843, // benzene + // 1.0874, -1.7465, 1.5765} ; //n-heptane + + // optimized chi-square: 21706 abs dev 2.65 + double guess[] = {0.7131945439, 0.4140076386, -2.5691833434, 4.3710359391, -1.1086000763, + 7.3866869416, 1.1183339865, -2.1831081128, 0.9948380388, 1.5665073967, -5.5636308059, + -1.4091055663, 0.8232405436, -0.3922156128, -1.4347079752, 1.3771397711, -1.2103436623, + 0.0028643344, 1.3423413878, -0.3330681068, -2.1604332713, 1.1554915030, -1.7359747766, + 1.1084438340, 1.1800358360, -1.4810259893, 1.4887592454}; + String nameList[] = {"methane", "ethane", "propane", "n-butane", "i-butane", "n-pentane", + "c-hexane", "benzene", "n-heptane"}; + + for (int compNumb = 0; compNumb < nameList.length; compNumb++) { + dataSet = + database.getResultSet("SELECT * FROM PureComponentVapourPressures WHERE ComponentName='" + + nameList[compNumb] + "' AND VapourPressure>0 ORDER BY Temperature ASC"); + + try { + long numberOfPoint = 3; + logger.error("point " + numberOfPoint); + int i = 0; + while (dataSet.next()) { + i++; + if (i % numberOfPoint == 0) { + MathiasCopemanToDewPoint function = new MathiasCopemanToDewPoint(); + function.setInitialGuess(guess); + + SystemInterface testSystem = + new SystemSrkMathiasCopeman(Double.parseDouble(dataSet.getString("Temperature")), + Double.parseDouble(dataSet.getString("VapourPressure"))); + testSystem.addComponent(dataSet.getString("ComponentName"), 100.0); + // testSystem.createDatabase(true); + double sample1[] = {testSystem.getPressure()}; + double standardDeviation1[] = {0.1, 0.1, 0.1}; + double val = testSystem.getTemperature(); + double stdErr = 1.0; + SampleValue sample = new SampleValue(val, stdErr, sample1, standardDeviation1); + sample.setFunction(function); + sample.setReference(dataSet.getString("Reference")); + sample.setThermodynamicSystem(testSystem); + sampleList.add(sample); + } } + } catch (Exception e) { + logger.error("database error" + e); + } + } - dataSet = database - .getResultSet("SELECT * FROM dewPointDataSynthHCStatoil WHERE Pressure<80.0");// "0 - // AND - // reference='Morch2004gas1'"); - - try { - long numberOfPoint = 1; - logger.info("point " + numberOfPoint); - int i = 0; - while (dataSet.next() && i < 100) { - i++; - if (i % numberOfPoint == 0) { - MathiasCopemanToDewPoint function = new MathiasCopemanToDewPoint(); - function.setInitialGuess(guess); - - SystemInterface testSystem = new SystemSrkMathiasCopeman( - Double.parseDouble(dataSet.getString("Temperature")), - Double.parseDouble(dataSet.getString("Pressure"))); - testSystem.addComponent(dataSet.getString("comp1"), - Double.parseDouble(dataSet.getString("x1"))); - testSystem.addComponent(dataSet.getString("comp2"), - Double.parseDouble(dataSet.getString("x2"))); - testSystem.addComponent(dataSet.getString("comp3"), - Double.parseDouble(dataSet.getString("x3"))); - testSystem.addComponent(dataSet.getString("comp4"), - Double.parseDouble(dataSet.getString("x4"))); - testSystem.addComponent(dataSet.getString("comp5"), - Double.parseDouble(dataSet.getString("x5"))); - testSystem.addComponent(dataSet.getString("comp6"), - Double.parseDouble(dataSet.getString("x6"))); - testSystem.addComponent(dataSet.getString("comp7"), - Double.parseDouble(dataSet.getString("x7"))); - testSystem.addComponent(dataSet.getString("comp8"), - Double.parseDouble(dataSet.getString("x8"))); - testSystem.addComponent(dataSet.getString("comp9"), - Double.parseDouble(dataSet.getString("x9"))); - // testSystem.addComponent(dataSet.getString("comp9"), - // Double.parseDouble(dataSet.getString("x9"))); - // testSystem.addComponent(dataSet.getString("comp10"), - // Double.parseDouble(dataSet.getString("x10"))); - // testSystem.createDatabase(true); - double sample1[] = {testSystem.getPressure()}; - double standardDeviation1[] = {0.1, 0.1, 0.1}; - double val = testSystem.getTemperature(); - double stdErr = 1.0; - SampleValue sample = new SampleValue(val, stdErr, sample1, standardDeviation1); - sample.setFunction(function); - sample.setReference(dataSet.getString("reference")); - sample.setThermodynamicSystem(testSystem); - sampleList.add(sample); - } - } - } catch (Exception e) { - logger.error("database error" + e); + dataSet = database.getResultSet("SELECT * FROM dewPointDataSynthHCStatoil WHERE Pressure<80.0");// "0 + // AND + // reference='Morch2004gas1'"); + + try { + long numberOfPoint = 1; + logger.info("point " + numberOfPoint); + int i = 0; + while (dataSet.next() && i < 100) { + i++; + if (i % numberOfPoint == 0) { + MathiasCopemanToDewPoint function = new MathiasCopemanToDewPoint(); + function.setInitialGuess(guess); + + SystemInterface testSystem = + new SystemSrkMathiasCopeman(Double.parseDouble(dataSet.getString("Temperature")), + Double.parseDouble(dataSet.getString("Pressure"))); + testSystem.addComponent(dataSet.getString("comp1"), + Double.parseDouble(dataSet.getString("x1"))); + testSystem.addComponent(dataSet.getString("comp2"), + Double.parseDouble(dataSet.getString("x2"))); + testSystem.addComponent(dataSet.getString("comp3"), + Double.parseDouble(dataSet.getString("x3"))); + testSystem.addComponent(dataSet.getString("comp4"), + Double.parseDouble(dataSet.getString("x4"))); + testSystem.addComponent(dataSet.getString("comp5"), + Double.parseDouble(dataSet.getString("x5"))); + testSystem.addComponent(dataSet.getString("comp6"), + Double.parseDouble(dataSet.getString("x6"))); + testSystem.addComponent(dataSet.getString("comp7"), + Double.parseDouble(dataSet.getString("x7"))); + testSystem.addComponent(dataSet.getString("comp8"), + Double.parseDouble(dataSet.getString("x8"))); + testSystem.addComponent(dataSet.getString("comp9"), + Double.parseDouble(dataSet.getString("x9"))); + // testSystem.addComponent(dataSet.getString("comp9"), + // Double.parseDouble(dataSet.getString("x9"))); + // testSystem.addComponent(dataSet.getString("comp10"), + // Double.parseDouble(dataSet.getString("x10"))); + // testSystem.createDatabase(true); + double sample1[] = {testSystem.getPressure()}; + double standardDeviation1[] = {0.1, 0.1, 0.1}; + double val = testSystem.getTemperature(); + double stdErr = 1.0; + SampleValue sample = new SampleValue(val, stdErr, sample1, standardDeviation1); + sample.setFunction(function); + sample.setReference(dataSet.getString("reference")); + sample.setThermodynamicSystem(testSystem); + sampleList.add(sample); } + } + } catch (Exception e) { + logger.error("database error" + e); + } - SampleSet sampleSet = new SampleSet(sampleList); - optim.setSampleSet(sampleSet); + SampleSet sampleSet = new SampleSet(sampleList); + optim.setSampleSet(sampleSet); - // do simulations + // do simulations - // optim.solve(); - // optim.runMonteCarloSimulation(); - optim.displayCurveFit(); - // optim.writeToCdfFile("c:/testFit.nc"); - // optim.writeToTextFile("c:/testFit.txt"); - } + // optim.solve(); + // optim.runMonteCarloSimulation(); + optim.displayCurveFit(); + // optim.writeToTextFile("c:/testFit.txt"); + } } diff --git a/src/main/java/neqsim/thermo/util/parameterFitting/pureComponentParameterFitting/acentricFactorFitting/TestTwuCoon.java b/src/main/java/neqsim/thermo/util/parameterFitting/pureComponentParameterFitting/acentricFactorFitting/TestTwuCoon.java index 494018455e..c577d0f13c 100644 --- a/src/main/java/neqsim/thermo/util/parameterFitting/pureComponentParameterFitting/acentricFactorFitting/TestTwuCoon.java +++ b/src/main/java/neqsim/thermo/util/parameterFitting/pureComponentParameterFitting/acentricFactorFitting/TestTwuCoon.java @@ -20,112 +20,111 @@ * @version $Id: $Id */ public class TestTwuCoon { - static Logger logger = LogManager.getLogger(TestTwuCoon.class); - - /** - *

- * main. - *

- * - * @param args an array of {@link java.lang.String} objects - */ - public static void main(String[] args) { - LevenbergMarquardt optim = new LevenbergMarquardt(); - ArrayList sampleList = new ArrayList(); - - // String ComponentName = "CO2"; - // String ComponentName = "methane"; - // String ComponentName = "ethane"; - // String ComponentName = "propane"; - // String ComponentName = "n-butane"; - // String ComponentName = "i-butane"; - // String ComponentName = "i-pentane"; - // String ComponentName = "n-pentane"; - String ComponentName = "mercury"; - // String ComponentName = "neon"; - - try { - // for(int i=0;i<30;i++){ - TwuCoon function = new TwuCoon(); - // double guess[] = {1.4136010682288083,-0.6059654485151583,1.1018149483163808}; - // // CO2 chi sqr 0.45 - // double guess[] ={0.1228415979307727,0.9144707890284266,2.7419786111346327} ; - // // Methane chi sqr 0.1425 - // double guess[] ={0.2996073181440976,0.8766268388933209,1.6792384004871077} ; - // // ethane chi sqr 0.6 - // double guess[] ={0.4358258831879946,0.8661321788747547,1.3954328182729108} ; - // // PROPANE chi sqr 0.57 - // double guess[] ={0.33180058324421624,0.8546927333111055,1.8658288576964368} ; - // // n-butane chi sqr 0.66 - // double guess[] ={0.2179712800665,0.8488910728515817,2.284036968290834}; - // i-butane chi sqr 0.64 - // double guess[] ={0.3426699116420882,0.8518937813463485,1.9218752789862321} ; - // // i-pentane chi sqr 1.71 - // double guess[] ={0.2728761064186051,0.8503101221977485,2.340728864856859} ; - // // n-pentane chi sqr 0.827 - // double guess[] ={0.11262960694190573,0.9021997146737551,2.8749606780260866} ; - // // nitrogen chi sqr 0.063 - // double guess[] ={0.08838047169500897,0.9400222937525736,3.4011901770700264} ; - // // neon chi sqr 0.044 - // double guess[] = {0.0179791, 0.983218, 5.63251}; - double guess[] = {0.068584, 0.9784, 2.244}; - - // SystemInterface testSystem = new SystemSrkSchwartzentruberEos(40, 1); - // SystemInterface testSystem = new SystemSrkEos(280, 1); - SystemInterface testSystem = new SystemSrkTwuCoonParamEos(280, 5); - testSystem.addComponent(ComponentName, 100.0); - testSystem.setMixingRule(2); - - testSystem.createDatabase(true); - - // function.setFittingParams(0, guess[0]); - // function.setFittingParams(1, guess[1]); - // function.setFittingParams(2, guess[2]); - function.setInitialGuess(guess); - - SystemInterface System2 = new SystemSrkSchwartzentruberEos(280, 5); - // SystemInterface System2 = new SystemSrkTwuCoonEos(280, 5); - - System2.addComponent(ComponentName, 100.0); - System2.setMixingRule(2); - ThermodynamicOperations Ops = new ThermodynamicOperations(System2); - - double Ttp = testSystem.getPhase(0).getComponent(0).getTriplePointTemperature(); - double TC = testSystem.getPhase(0).getComponent(0).getTC(); - - for (int i = 0; i < 30; i++) { - double temperature = Ttp + ((TC - Ttp) / 30) * i; - // kan legge inn dewTflash for aa finne avvik til tilsvarende linje med - // schwarzentruber... da ogsaa for flerkomponent blandinger istedenfor antoine - // ligningen. - // double pressure = - // testSystem.getPhase(0).getComponent(0).getAntoineVaporPressure(temperature); - System2.setTemperature(temperature); - Ops.dewPointPressureFlash(); - double pressure = System2.getPressure(); - - double sample1[] = {temperature}; - double standardDeviation1[] = {0.1, 0.1, 0.1}; - double val = Math.log(pressure); - SampleValue sample = new SampleValue(val, val / 100.0, sample1, standardDeviation1); - sample.setFunction(function); - sample.setReference("Perry"); - sample.setThermodynamicSystem(testSystem); - sampleList.add(sample); - } - } catch (Exception e) { - logger.error("database error" + e); - } - - SampleSet sampleSet = new SampleSet(sampleList); - optim.setSampleSet(sampleSet); - - // do simulations - - optim.solve(); - // optim.runMonteCarloSimulation(); - optim.displayCurveFit(); - // optim.writeToCdfFile("c:/testFit.nc"); - // optim.writeToTextFile("c:/testFit.txt"); + static Logger logger = LogManager.getLogger(TestTwuCoon.class); + + /** + *

+ * main. + *

+ * + * @param args an array of {@link java.lang.String} objects + */ + public static void main(String[] args) { + LevenbergMarquardt optim = new LevenbergMarquardt(); + ArrayList sampleList = new ArrayList(); + + // String ComponentName = "CO2"; + // String ComponentName = "methane"; + // String ComponentName = "ethane"; + // String ComponentName = "propane"; + // String ComponentName = "n-butane"; + // String ComponentName = "i-butane"; + // String ComponentName = "i-pentane"; + // String ComponentName = "n-pentane"; + String ComponentName = "mercury"; + // String ComponentName = "neon"; + + try { + // for(int i=0;i<30;i++){ + TwuCoon function = new TwuCoon(); + // double guess[] = {1.4136010682288083,-0.6059654485151583,1.1018149483163808}; + // // CO2 chi sqr 0.45 + // double guess[] ={0.1228415979307727,0.9144707890284266,2.7419786111346327} ; + // // Methane chi sqr 0.1425 + // double guess[] ={0.2996073181440976,0.8766268388933209,1.6792384004871077} ; + // // ethane chi sqr 0.6 + // double guess[] ={0.4358258831879946,0.8661321788747547,1.3954328182729108} ; + // // PROPANE chi sqr 0.57 + // double guess[] ={0.33180058324421624,0.8546927333111055,1.8658288576964368} ; + // // n-butane chi sqr 0.66 + // double guess[] ={0.2179712800665,0.8488910728515817,2.284036968290834}; + // i-butane chi sqr 0.64 + // double guess[] ={0.3426699116420882,0.8518937813463485,1.9218752789862321} ; + // // i-pentane chi sqr 1.71 + // double guess[] ={0.2728761064186051,0.8503101221977485,2.340728864856859} ; + // // n-pentane chi sqr 0.827 + // double guess[] ={0.11262960694190573,0.9021997146737551,2.8749606780260866} ; + // // nitrogen chi sqr 0.063 + // double guess[] ={0.08838047169500897,0.9400222937525736,3.4011901770700264} ; + // // neon chi sqr 0.044 + // double guess[] = {0.0179791, 0.983218, 5.63251}; + double guess[] = {0.068584, 0.9784, 2.244}; + + // SystemInterface testSystem = new SystemSrkSchwartzentruberEos(40, 1); + // SystemInterface testSystem = new SystemSrkEos(280, 1); + SystemInterface testSystem = new SystemSrkTwuCoonParamEos(280, 5); + testSystem.addComponent(ComponentName, 100.0); + testSystem.setMixingRule(2); + + testSystem.createDatabase(true); + + // function.setFittingParams(0, guess[0]); + // function.setFittingParams(1, guess[1]); + // function.setFittingParams(2, guess[2]); + function.setInitialGuess(guess); + + SystemInterface System2 = new SystemSrkSchwartzentruberEos(280, 5); + // SystemInterface System2 = new SystemSrkTwuCoonEos(280, 5); + + System2.addComponent(ComponentName, 100.0); + System2.setMixingRule(2); + ThermodynamicOperations Ops = new ThermodynamicOperations(System2); + + double Ttp = testSystem.getPhase(0).getComponent(0).getTriplePointTemperature(); + double TC = testSystem.getPhase(0).getComponent(0).getTC(); + + for (int i = 0; i < 30; i++) { + double temperature = Ttp + ((TC - Ttp) / 30) * i; + // kan legge inn dewTflash for aa finne avvik til tilsvarende linje med + // schwarzentruber... da ogsaa for flerkomponent blandinger istedenfor antoine + // ligningen. + // double pressure = + // testSystem.getPhase(0).getComponent(0).getAntoineVaporPressure(temperature); + System2.setTemperature(temperature); + Ops.dewPointPressureFlash(); + double pressure = System2.getPressure(); + + double sample1[] = {temperature}; + double standardDeviation1[] = {0.1, 0.1, 0.1}; + double val = Math.log(pressure); + SampleValue sample = new SampleValue(val, val / 100.0, sample1, standardDeviation1); + sample.setFunction(function); + sample.setReference("Perry"); + sample.setThermodynamicSystem(testSystem); + sampleList.add(sample); + } + } catch (Exception e) { + logger.error("database error" + e); } + + SampleSet sampleSet = new SampleSet(sampleList); + optim.setSampleSet(sampleSet); + + // do simulations + + optim.solve(); + // optim.runMonteCarloSimulation(); + optim.displayCurveFit(); + // optim.writeToTextFile("c:/testFit.txt"); + } } diff --git a/src/main/java/neqsim/thermo/util/parameterFitting/pureComponentParameterFitting/furstIonicParameters/TestFurstIonicParameterFunction.java b/src/main/java/neqsim/thermo/util/parameterFitting/pureComponentParameterFitting/furstIonicParameters/TestFurstIonicParameterFunction.java index 8524f4788f..0f07938f63 100644 --- a/src/main/java/neqsim/thermo/util/parameterFitting/pureComponentParameterFitting/furstIonicParameters/TestFurstIonicParameterFunction.java +++ b/src/main/java/neqsim/thermo/util/parameterFitting/pureComponentParameterFitting/furstIonicParameters/TestFurstIonicParameterFunction.java @@ -20,171 +20,164 @@ * @version $Id: $Id */ public class TestFurstIonicParameterFunction { - static Logger logger = LogManager.getLogger(TestFurstIonicParameterFunction.class); + static Logger logger = LogManager.getLogger(TestFurstIonicParameterFunction.class); - /** - *

- * main. - *

- * - * @param args an array of {@link java.lang.String} objects - */ - public static void main(String[] args) { - LevenbergMarquardt optim = new LevenbergMarquardt(); - ArrayList sampleList = new ArrayList(); + /** + *

+ * main. + *

+ * + * @param args an array of {@link java.lang.String} objects + */ + public static void main(String[] args) { + LevenbergMarquardt optim = new LevenbergMarquardt(); + ArrayList sampleList = new ArrayList(); - // inserting samples from database - NeqSimDataBase database = new NeqSimDataBase(); - // double[] guess = {0.0000001880, 0.0000014139, 0.0000284666, 0.0000389043, - // -0.0000000451, 0.0000088136}; - // double[] guess = {0.0000250998, 0.0000198635, -0.0000000311, -0.0000006630}; - // double[] guess = { 0.0000001116, 0.0000053822, 0.0000691846, 0.0000049520, - // -0.0000000605, -0.0000216352}; - // double[] guess = {0.0000000640, 0.0000011845 , 0.0000209744, 0.0000089071, - // -0.0000000272, 0.0000019014};//cpa-el - double[] guess = {0.0000000752, 0.0000037242, 0.0000250998, 0.0000198635, -0.0000000311, - -0.0000006630}; - // ResultSet dataSet = database.getResultSet( "SELECT * FROM ionicData WHERE - // Description IN ('NaCl')");//,'LiCl','Sr2Br','Sr2I')"); - ResultSet dataSet = database.getResultSet( - "SELECT * FROM ionicData WHERE ion1<>'H3Oplus2' ORDER BY ion1,ion2,x2"); - // ResultSet dataSet = database.getResultSet( "SELECT * FROM ionicData WHERE - // ion1='Na+' AND ion2='Cl-'"); - int numb = 0; - try { - logger.info("adding...."); - while (dataSet.next() && numb < 22265) { - numb++; + // inserting samples from database + NeqSimDataBase database = new NeqSimDataBase(); + // double[] guess = {0.0000001880, 0.0000014139, 0.0000284666, 0.0000389043, + // -0.0000000451, 0.0000088136}; + // double[] guess = {0.0000250998, 0.0000198635, -0.0000000311, -0.0000006630}; + // double[] guess = { 0.0000001116, 0.0000053822, 0.0000691846, 0.0000049520, + // -0.0000000605, -0.0000216352}; + // double[] guess = {0.0000000640, 0.0000011845 , 0.0000209744, 0.0000089071, + // -0.0000000272, 0.0000019014};//cpa-el + double[] guess = + {0.0000000752, 0.0000037242, 0.0000250998, 0.0000198635, -0.0000000311, -0.0000006630}; + // ResultSet dataSet = database.getResultSet( "SELECT * FROM ionicData WHERE + // Description IN ('NaCl')");//,'LiCl','Sr2Br','Sr2I')"); + ResultSet dataSet = database + .getResultSet("SELECT * FROM ionicData WHERE ion1<>'H3Oplus2' ORDER BY ion1,ion2,x2"); + // ResultSet dataSet = database.getResultSet( "SELECT * FROM ionicData WHERE + // ion1='Na+' AND ion2='Cl-'"); + int numb = 0; + try { + logger.info("adding...."); + while (dataSet.next() && numb < 22265) { + numb++; - FurstIonicParameterFunction function = new FurstIonicParameterFunction(); - function.setInitialGuess(guess); - double x2 = Double.parseDouble(dataSet.getString("x2")); - // SystemInterface testSystem = new SystemFurstElectrolyteEos(280, - // 1.0); - SystemInterface testSystem = new SystemElectrolyteCPAstatoil(280.0, 1.0); - // testSystem.addComponent(dataSet.getString("ComponentSolvent"), - // Double.parseDouble(dataSet.getString("x1"))); - testSystem.addComponent("water", Double.parseDouble(dataSet.getString("x1"))); - testSystem.addComponent(dataSet.getString("Ion1"), x2); - testSystem.addComponent(dataSet.getString("Ion2"), - Double.parseDouble(dataSet.getString("x3"))); - testSystem.createDatabase(true); - testSystem.setMixingRule(10); - testSystem.setTemperature(Double.parseDouble(dataSet.getString("Temperature"))); - testSystem.setPressure(Double.parseDouble(dataSet.getString("Pressure"))); - testSystem.init(0); - double sample1[] = {x2 / 0.01802}; - double standardDeviation1[] = {0.01}; - double osmcoef = Double.parseDouble(dataSet.getString("OsmoticCoefficient")); + FurstIonicParameterFunction function = new FurstIonicParameterFunction(); + function.setInitialGuess(guess); + double x2 = Double.parseDouble(dataSet.getString("x2")); + // SystemInterface testSystem = new SystemFurstElectrolyteEos(280, + // 1.0); + SystemInterface testSystem = new SystemElectrolyteCPAstatoil(280.0, 1.0); + // testSystem.addComponent(dataSet.getString("ComponentSolvent"), + // Double.parseDouble(dataSet.getString("x1"))); + testSystem.addComponent("water", Double.parseDouble(dataSet.getString("x1"))); + testSystem.addComponent(dataSet.getString("Ion1"), x2); + testSystem.addComponent(dataSet.getString("Ion2"), + Double.parseDouble(dataSet.getString("x3"))); + testSystem.createDatabase(true); + testSystem.setMixingRule(10); + testSystem.setTemperature(Double.parseDouble(dataSet.getString("Temperature"))); + testSystem.setPressure(Double.parseDouble(dataSet.getString("Pressure"))); + testSystem.init(0); + double sample1[] = {x2 / 0.01802}; + double standardDeviation1[] = {0.01}; + double osmcoef = Double.parseDouble(dataSet.getString("OsmoticCoefficient")); - testSystem.init(1); + testSystem.init(1); - SampleValue sample = - new SampleValue(osmcoef, osmcoef / 100.0, sample1, standardDeviation1); - // SampleValue sample = new - // SampleValue(Double.parseDouble(dataSet.getString("IonicActivity")), - // Double.parseDouble(dataSet.getString("stddev2")), sample1, - // standardDeviation1); - sample.setFunction(function); - sample.setThermodynamicSystem(testSystem); - sample.setReference(dataSet.getString("Reference")); - sample.setDescription(dataSet.getString("Description")); - sampleList.add(sample); - } + SampleValue sample = new SampleValue(osmcoef, osmcoef / 100.0, sample1, standardDeviation1); + // SampleValue sample = new + // SampleValue(Double.parseDouble(dataSet.getString("IonicActivity")), + // Double.parseDouble(dataSet.getString("stddev2")), sample1, + // standardDeviation1); + sample.setFunction(function); + sample.setThermodynamicSystem(testSystem); + sample.setReference(dataSet.getString("Reference")); + sample.setDescription(dataSet.getString("Description")); + sampleList.add(sample); + } - // dataSet = database.getResultSet( "SELECT * FROM ionicData WHERE - // ion1<>'H3Oplus2' AND IonicActivity>=0.01"); - // dataSet = database.getResultSet( "SELECT * FROM ionicData WHERE - // Description - // IN ('NaCl','LiCl','Sr2Br','Sr2I') AND IonicActivity>=0.01"); - dataSet = database - .getResultSet("SELECT * FROM ionicData WHERE ion1='Na+' AND ion2='Cl-'"); - logger.info("setting new for activity"); - while (!dataSet.next()) { - FurstIonicParameterFunction_Activity function = - new FurstIonicParameterFunction_Activity(); - function.setInitialGuess(guess); - double x2 = Double.parseDouble(dataSet.getString("x2")); - // SystemInterface testSystem = new SystemFurstElectrolyteEos(280, - // 1.0); - SystemInterface testSystem = new SystemElectrolyteCPAstatoil(280, 1.0); - testSystem.addComponent(dataSet.getString("ComponentSolvent"), - Double.parseDouble(dataSet.getString("x1"))); - testSystem.addComponent(dataSet.getString("Ion1"), x2); - testSystem.addComponent(dataSet.getString("Ion2"), - Double.parseDouble(dataSet.getString("x3"))); - testSystem.createDatabase(true); - testSystem.setMixingRule(10); - testSystem.setTemperature(Double.parseDouble(dataSet.getString("Temperature"))); - testSystem.setPressure(Double.parseDouble(dataSet.getString("Pressure"))); - testSystem.init(0); - double sample1[] = {x2 / 0.01802}; - double standardDeviation1[] = {0.01}; - // SampleValue sample = new - // SampleValue(Double.parseDouble(dataSet.getString("OsmoticCoefficient")), - // Double.parseDouble(dataSet.getString("stddev1")), sample1, - // standardDeviation1); - double ionact = Double.parseDouble(dataSet.getString("IonicActivity")); - SampleValue sample = new SampleValue(ionact, ionact, sample1, standardDeviation1); - sample.setFunction(function); - sample.setThermodynamicSystem(testSystem); - sample.setReference(dataSet.getString("Reference")); - sample.setDescription(dataSet.getString("Description")); - sampleList.add(sample); - } + // dataSet = database.getResultSet( "SELECT * FROM ionicData WHERE + // ion1<>'H3Oplus2' AND IonicActivity>=0.01"); + // dataSet = database.getResultSet( "SELECT * FROM ionicData WHERE + // Description + // IN ('NaCl','LiCl','Sr2Br','Sr2I') AND IonicActivity>=0.01"); + dataSet = database.getResultSet("SELECT * FROM ionicData WHERE ion1='Na+' AND ion2='Cl-'"); + logger.info("setting new for activity"); + while (!dataSet.next()) { + FurstIonicParameterFunction_Activity function = new FurstIonicParameterFunction_Activity(); + function.setInitialGuess(guess); + double x2 = Double.parseDouble(dataSet.getString("x2")); + // SystemInterface testSystem = new SystemFurstElectrolyteEos(280, + // 1.0); + SystemInterface testSystem = new SystemElectrolyteCPAstatoil(280, 1.0); + testSystem.addComponent(dataSet.getString("ComponentSolvent"), + Double.parseDouble(dataSet.getString("x1"))); + testSystem.addComponent(dataSet.getString("Ion1"), x2); + testSystem.addComponent(dataSet.getString("Ion2"), + Double.parseDouble(dataSet.getString("x3"))); + testSystem.createDatabase(true); + testSystem.setMixingRule(10); + testSystem.setTemperature(Double.parseDouble(dataSet.getString("Temperature"))); + testSystem.setPressure(Double.parseDouble(dataSet.getString("Pressure"))); + testSystem.init(0); + double sample1[] = {x2 / 0.01802}; + double standardDeviation1[] = {0.01}; + // SampleValue sample = new + // SampleValue(Double.parseDouble(dataSet.getString("OsmoticCoefficient")), + // Double.parseDouble(dataSet.getString("stddev1")), sample1, + // standardDeviation1); + double ionact = Double.parseDouble(dataSet.getString("IonicActivity")); + SampleValue sample = new SampleValue(ionact, ionact, sample1, standardDeviation1); + sample.setFunction(function); + sample.setThermodynamicSystem(testSystem); + sample.setReference(dataSet.getString("Reference")); + sample.setDescription(dataSet.getString("Description")); + sampleList.add(sample); + } - dataSet = - database.getResultSet("SELECT * FROM saltdens WHERE ion1='Na+' AND ion2='Cl-'"); - logger.info("fitting to ionic density"); - while (!dataSet.next()) { - FurstIonicParameterFunction_Density function = - new FurstIonicParameterFunction_Density(); - function.setInitialGuess(guess); - double x2 = Double.parseDouble(dataSet.getString("molfrac1")); - double x3 = Double.parseDouble(dataSet.getString("molfrac2")); - double x1 = 1.0 - x2 - x3; - SystemInterface testSystem = new SystemElectrolyteCPAstatoil(280, 1.0); - // SystemInterface testSystem = new SystemElectrolyteCPA(280, 1.0); - testSystem.addComponent(dataSet.getString("solvent"), x1); - testSystem.addComponent(dataSet.getString("Ion1"), x2); - testSystem.addComponent(dataSet.getString("Ion2"), x3); - testSystem.setTemperature(Double.parseDouble(dataSet.getString("temperature"))); - testSystem.setPressure(Double.parseDouble(dataSet.getString("pressure"))); - testSystem.createDatabase(true); - testSystem.setMixingRule(7); - testSystem.init(0); - double sample1[] = {x2 / 0.01802}; - double standardDeviation1[] = {0.01}; - // SampleValue sample = new - // SampleValue(Double.parseDouble(dataSet.getString("OsmoticCoefficient")), - // Double.parseDouble(dataSet.getString("stddev1")), sample1, - // standardDeviation1); - double density = Double.parseDouble(dataSet.getString("density")) * 1000.0; - SampleValue sample = - new SampleValue(density, density / 100.0, sample1, standardDeviation1); - sample.setFunction(function); - sample.setThermodynamicSystem(testSystem); - sampleList.add(sample); - } - } catch (Exception e) { - logger.error("database error: ", e); - } + dataSet = database.getResultSet("SELECT * FROM saltdens WHERE ion1='Na+' AND ion2='Cl-'"); + logger.info("fitting to ionic density"); + while (!dataSet.next()) { + FurstIonicParameterFunction_Density function = new FurstIonicParameterFunction_Density(); + function.setInitialGuess(guess); + double x2 = Double.parseDouble(dataSet.getString("molfrac1")); + double x3 = Double.parseDouble(dataSet.getString("molfrac2")); + double x1 = 1.0 - x2 - x3; + SystemInterface testSystem = new SystemElectrolyteCPAstatoil(280, 1.0); + // SystemInterface testSystem = new SystemElectrolyteCPA(280, 1.0); + testSystem.addComponent(dataSet.getString("solvent"), x1); + testSystem.addComponent(dataSet.getString("Ion1"), x2); + testSystem.addComponent(dataSet.getString("Ion2"), x3); + testSystem.setTemperature(Double.parseDouble(dataSet.getString("temperature"))); + testSystem.setPressure(Double.parseDouble(dataSet.getString("pressure"))); + testSystem.createDatabase(true); + testSystem.setMixingRule(7); + testSystem.init(0); + double sample1[] = {x2 / 0.01802}; + double standardDeviation1[] = {0.01}; + // SampleValue sample = new + // SampleValue(Double.parseDouble(dataSet.getString("OsmoticCoefficient")), + // Double.parseDouble(dataSet.getString("stddev1")), sample1, + // standardDeviation1); + double density = Double.parseDouble(dataSet.getString("density")) * 1000.0; + SampleValue sample = new SampleValue(density, density / 100.0, sample1, standardDeviation1); + sample.setFunction(function); + sample.setThermodynamicSystem(testSystem); + sampleList.add(sample); + } + } catch (Exception e) { + logger.error("database error: ", e); + } - // double sample1[] = {0.1}; - // for(int i=0;i - * Constructor for HydrateFunction. - *

- */ - public HydrateFunction() { - // params = new double[3]; - } + /** + *

+ * Constructor for HydrateFunction. + *

+ */ + public HydrateFunction() { + // params = new double[3]; + } - /** {@inheritDoc} */ - @Override - public double calcValue(double[] dependentValues) { - try { - thermoOps.hydrateFormationTemperature(1); - // System.out.println("temperature " + system.getTemperature()); - } catch (Exception e) { - logger.error(e.toString()); - } - return system.getTemperature(); + /** {@inheritDoc} */ + @Override + public double calcValue(double[] dependentValues) { + try { + thermoOps.hydrateFormationTemperature(1); + // System.out.println("temperature " + system.getTemperature()); + } catch (Exception e) { + logger.error(e.toString()); } + return system.getTemperature(); + } - /** {@inheritDoc} */ - @Override - public double calcTrueValue(double val) { - return val; - } + /** {@inheritDoc} */ + @Override + public double calcTrueValue(double val) { + return val; + } - /** {@inheritDoc} */ - @Override - public void setFittingParams(int i, double value) { - int structure = 1; - params[i] = value; - // if(i==0) ((ComponentHydrate) - // system.getPhase(4).getComponent("water")).setDGfHydrate(value, structure); - // if(i==1) ((ComponentHydrate) - // system.getPhase(4).getComponent("water")).setDHfHydrate(value, structure); - // int k=0; + /** {@inheritDoc} */ + @Override + public void setFittingParams(int i, double value) { + // int structure = 1; + params[i] = value; + // if(i==0) ((ComponentHydrate) + // system.getPhase(4).getComponent("water")).setDGfHydrate(value, structure); + // if(i==1) ((ComponentHydrate) + // system.getPhase(4).getComponent("water")).setDHfHydrate(value, structure); + // int k=0; - // if(i==0) ((ComponentHydrate) - // system.getPhase(4).getComponent("water")).setEmptyHydrateVapourPressureConstant(0,0, - // value); - // if(i==1) ((ComponentHydrate) - // system.getPhase(4).getComponent("water")).setEmptyHydrateVapourPressureConstant(0,1, - // value); + // if(i==0) ((ComponentHydrate) + // system.getPhase(4).getComponent("water")).setEmptyHydrateVapourPressureConstant(0,0, + // value); + // if(i==1) ((ComponentHydrate) + // system.getPhase(4).getComponent("water")).setEmptyHydrateVapourPressureConstant(0,1, + // value); - // for(int k=0;k - * main. - *

- * - * @param args an array of {@link java.lang.String} objects - */ - public static void main(String[] args) { - LevenbergMarquardt optim = new LevenbergMarquardt(); - ArrayList sampleList = new ArrayList(); + /** + *

+ * main. + *

+ * + * @param args an array of {@link java.lang.String} objects + */ + public static void main(String[] args) { + LevenbergMarquardt optim = new LevenbergMarquardt(); + ArrayList sampleList = new ArrayList(); - // inserting samples from database - NeqSimDataBase database = new NeqSimDataBase(); + // inserting samples from database + NeqSimDataBase database = new NeqSimDataBase(); - double[] guess = {155.8090060223, 3.1907109417, 0.4069986258};// methane fitted statoil - // sCPA-MC - // double[] guess = { 176.4, 3.2641, 0.5651}; //ethane fitted statoil sCPA-MC - // double[] guess = {126.5783867132, 3.1325067483, 0.3591889027}; // nitrogen - // fitted statoil sCPA-MC - // double[] guess = {205.8859461427, 3.3205773626, 0.6623796853}; // propane - // fitted statoil sCPA-MC - // double[] guess = { 225.1504438988, 3.0810162204, 0.8708186545}; // i-butane - // fitted statoil sCPA-MC + double[] guess = {155.8090060223, 3.1907109417, 0.4069986258};// methane fitted statoil + // sCPA-MC + // double[] guess = { 176.4, 3.2641, 0.5651}; //ethane fitted statoil sCPA-MC + // double[] guess = {126.5783867132, 3.1325067483, 0.3591889027}; // nitrogen + // fitted statoil sCPA-MC + // double[] guess = {205.8859461427, 3.3205773626, 0.6623796853}; // propane + // fitted statoil sCPA-MC + // double[] guess = { 225.1504438988, 3.0810162204, 0.8708186545}; // i-butane + // fitted statoil sCPA-MC - // double[] guess = { 154.7937576383, 3.2008300801, 0.4526279094};//methane - // fitted sCPA - // double[] guess = { 170.1623828321, 3.0372071690, 0.6846338805}; //CO2 - // double[] guess = { 154.0936564578, 3.1720449934, 0.4436459226};//, - // -293247.7186651294};//methane fitted' - // double[] guess = {17.5988597357, -6056.9305919979}; + // double[] guess = { 154.7937576383, 3.2008300801, 0.4526279094};//methane + // fitted sCPA + // double[] guess = { 170.1623828321, 3.0372071690, 0.6846338805}; //CO2 + // double[] guess = { 154.0936564578, 3.1720449934, 0.4436459226};//, + // -293247.7186651294};//methane fitted' + // double[] guess = {17.5988597357, -6056.9305919979}; - // ljeps, ljdiam,a + // ljeps, ljdiam,a - ResultSet dataSet = database.getResultSet( - "SELECT * FROM HydratePureComp WHERE GuestMolecule='methane' AND Type<>'IHV' AND Pressure<57 AND Temperature>273.15"); + ResultSet dataSet = database.getResultSet( + "SELECT * FROM HydratePureComp WHERE GuestMolecule='methane' AND Type<>'IHV' AND Pressure<57 AND Temperature>273.15"); - int numb = 0; - try { - logger.info("adding...."); - while (dataSet.next() && numb < 6) { - numb++; - HydrateFunction function = new HydrateFunction(); - function.setInitialGuess(guess); - double pres = Double.parseDouble(dataSet.getString("Pressure")); - double temp = Double.parseDouble(dataSet.getString("Temperature")); - // SystemInterface testSystem = new SystemSrkSchwartzentruberEos(280, 1.0); - SystemInterface testSystem = new SystemSrkCPAstatoil(280, 1.0); - testSystem.addComponent(dataSet.getString("GuestMolecule"), 1.0); - testSystem.addComponent("water", 1.0); - // testSystem.setSolidPhaseCheck(true); - testSystem.setHydrateCheck(true); - testSystem.createDatabase(true); - testSystem.setMixingRule(7); - testSystem.setTemperature(temp); - testSystem.setPressure(pres); - testSystem.init(0); - double sample1[] = {temp}; - double standardDeviation1[] = {0.1}; - SampleValue sample = new SampleValue(temp, 1.0, sample1, standardDeviation1); - // SampleValue sample = new - // SampleValue(Double.parseDouble(dataSet.getString("IonicActivity")), - // Double.parseDouble(dataSet.getString("stddev2")), sample1, - // standardDeviation1); - sample.setFunction(function); - sample.setThermodynamicSystem(testSystem); - sample.setDescription(Double.toString(testSystem.getPressure())); - sample.setReference(dataSet.getString("Reference")); - sampleList.add(sample); - } - } catch (Exception e) { - logger.error("database error: ", e); - } + int numb = 0; + try { + logger.info("adding...."); + while (dataSet.next() && numb < 6) { + numb++; + HydrateFunction function = new HydrateFunction(); + function.setInitialGuess(guess); + double pres = Double.parseDouble(dataSet.getString("Pressure")); + double temp = Double.parseDouble(dataSet.getString("Temperature")); + // SystemInterface testSystem = new SystemSrkSchwartzentruberEos(280, 1.0); + SystemInterface testSystem = new SystemSrkCPAstatoil(280, 1.0); + testSystem.addComponent(dataSet.getString("GuestMolecule"), 1.0); + testSystem.addComponent("water", 1.0); + // testSystem.setSolidPhaseCheck(true); + testSystem.setHydrateCheck(true); + testSystem.createDatabase(true); + testSystem.setMixingRule(7); + testSystem.setTemperature(temp); + testSystem.setPressure(pres); + testSystem.init(0); + double sample1[] = {temp}; + double standardDeviation1[] = {0.1}; + SampleValue sample = new SampleValue(temp, 1.0, sample1, standardDeviation1); + // SampleValue sample = new + // SampleValue(Double.parseDouble(dataSet.getString("IonicActivity")), + // Double.parseDouble(dataSet.getString("stddev2")), sample1, + // standardDeviation1); + sample.setFunction(function); + sample.setThermodynamicSystem(testSystem); + sample.setDescription(Double.toString(testSystem.getPressure())); + sample.setReference(dataSet.getString("Reference")); + sampleList.add(sample); + } + } catch (Exception e) { + logger.error("database error: ", e); + } - SampleSet sampleSet = new SampleSet(sampleList); - optim.setSampleSet(sampleSet); + SampleSet sampleSet = new SampleSet(sampleList); + optim.setSampleSet(sampleSet); - // do simulations - optim.solve(); - // optim.runMonteCarloSimulation(); - optim.displayCurveFit(); - // optim.writeToCdfFile("c:/testFit.nc"); - // optim.writeToTextFile("c:/testFit.txt"); - } + // do simulations + optim.solve(); + // optim.runMonteCarloSimulation(); + optim.displayCurveFit(); + // optim.writeToTextFile("c:/testFit.txt"); + } } diff --git a/src/main/java/neqsim/thermodynamicOperations/BaseOperation.java b/src/main/java/neqsim/thermodynamicOperations/BaseOperation.java index 56ded9f079..359f67041b 100644 --- a/src/main/java/neqsim/thermodynamicOperations/BaseOperation.java +++ b/src/main/java/neqsim/thermodynamicOperations/BaseOperation.java @@ -16,56 +16,52 @@ * @version $Id: $Id */ public abstract class BaseOperation implements OperationInterface { - private static final long serialVersionUID = 1000; + private static final long serialVersionUID = 1000; - SystemInterface systemThermo = null;; + SystemInterface systemThermo = null;; - /** - *

- * Constructor for BaseOperation. - *

- */ - public BaseOperation() {} + /** + *

+ * Constructor for BaseOperation. + *

+ */ + public BaseOperation() {} - /** {@inheritDoc} */ - @Override - public double[] get(String name) { - return new double[3]; - } + /** {@inheritDoc} */ + @Override + public double[] get(String name) { + return new double[3]; + } - /** {@inheritDoc} */ - @Override - public String[][] getResultTable() { - return new String[10][3]; - } + /** {@inheritDoc} */ + @Override + public String[][] getResultTable() { + return new String[10][3]; + } - /** {@inheritDoc} */ - @Override - public SystemInterface getThermoSystem() { - return null; - } + /** {@inheritDoc} */ + @Override + public SystemInterface getThermoSystem() { + return null; + } - /** {@inheritDoc} */ - @Override - public org.jfree.chart.JFreeChart getJFreeChart(String name) { - return null; - } + /** {@inheritDoc} */ + @Override + public org.jfree.chart.JFreeChart getJFreeChart(String name) { + return null; + } - /** {@inheritDoc} */ - @Override - public void printToFile(String name) {} + /** {@inheritDoc} */ + @Override + public void printToFile(String name) {} - /** {@inheritDoc} */ - @Override - public void createNetCdfFile(String name) {} + /** {@inheritDoc} */ + @Override + public double[][] getPoints(int i) { + return null; + } - /** {@inheritDoc} */ - @Override - public double[][] getPoints(int i) { - return null; - } - - /** {@inheritDoc} */ - @Override - public void addData(String name, double[][] data) {} + /** {@inheritDoc} */ + @Override + public void addData(String name, double[][] data) {} } diff --git a/src/main/java/neqsim/thermodynamicOperations/OperationInterface.java b/src/main/java/neqsim/thermodynamicOperations/OperationInterface.java index 1d6cb4d2d3..18a6103b86 100644 --- a/src/main/java/neqsim/thermodynamicOperations/OperationInterface.java +++ b/src/main/java/neqsim/thermodynamicOperations/OperationInterface.java @@ -52,15 +52,6 @@ public interface OperationInterface extends Runnable, java.io.Serializable { */ public String[][] getResultTable(); - /** - *

- * createNetCdfFile. - *

- * - * @param name a {@link java.lang.String} object - */ - public void createNetCdfFile(String name); - /** *

* printToFile. diff --git a/src/main/java/neqsim/thermodynamicOperations/ThermodynamicOperations.java b/src/main/java/neqsim/thermodynamicOperations/ThermodynamicOperations.java index cf0f8773a7..0b4c4aaeb6 100644 --- a/src/main/java/neqsim/thermodynamicOperations/ThermodynamicOperations.java +++ b/src/main/java/neqsim/thermodynamicOperations/ThermodynamicOperations.java @@ -70,1965 +70,1971 @@ * @version $Id: $Id */ public class ThermodynamicOperations implements java.io.Serializable, Cloneable { - private static final long serialVersionUID = 1000; - - private Thread thermoOperationThread = new Thread(); - private OperationInterface operation = null; - SystemInterface system = null; - boolean writeFile = false; - String fileName = null; - private boolean runAsThread = false; - protected String[][] resultTable = null; - static Logger logger = LogManager.getLogger(ThermodynamicOperations.class); - - /** - *

- * Constructor for ThermodynamicOperations. - *

- */ - public ThermodynamicOperations() { - } - - /** - *

- * Constructor for ThermodynamicOperations. - *

- * - * @param system a {@link neqsim.thermo.system.SystemInterface} object - */ - public ThermodynamicOperations(SystemInterface system) { - this.system = system; - } - - /** - *

- * Setter for the field system. - *

- * - * @param system a {@link neqsim.thermo.system.SystemInterface} object - */ - public void setSystem(SystemInterface system) { - this.system = system; - } - - /** - *

- * TPSolidflash. - *

- */ - public void TPSolidflash() { - operation = new SolidFlash1(system); - getOperation().run(); - } - - /** - * Method to perform a flash at given temperature, pressure and specified volume - * The number of - * moles in the system are changed to match the specified volume. - * - * @param volumeSpec is the specified volume - * @param unit Supported units are m3 - */ - public void TPVflash(double volumeSpec, String unit) { - unit = "m3"; - TPflash(); - double startVolume = system.getVolume(unit); - system.setTotalNumberOfMoles(system.getNumberOfMoles() * volumeSpec / startVolume); - system.init(3); - } - - /** - *

- * TPflash. - *

- */ - public void TPflash() { - double flowRate = system.getTotalNumberOfMoles(); - double minimumFlowRate = 1e-50; - if (flowRate < 1e-3) { - system.setTotalNumberOfMoles(1.0); - } - operation = new neqsim.thermodynamicOperations.flashOps.TPflash(system, - system.doSolidPhaseCheck()); - if (!isRunAsThread()) { - getOperation().run(); - } else { - run(); - } - if (flowRate < 1e-3) { - if (flowRate < minimumFlowRate) { - system.setTotalNumberOfMoles(minimumFlowRate); - } else { - system.setTotalNumberOfMoles(flowRate); - } - system.init(2); - } - } - - /** - *

- * saturateWithWater. - *

- */ - public void saturateWithWater() { - operation = new SaturateWithWater(system); - getOperation().run(); - } - - /** - *

- * TPflash. - *

- * - * @param checkSolids a boolean - */ - public void TPflash(boolean checkSolids) { - operation = new neqsim.thermodynamicOperations.flashOps.TPflash(system, checkSolids); - getOperation().run(); - } - - /** - *

- * TPgradientFlash. - *

- * - * @param height a double - * @param temperature a double - * @return a {@link neqsim.thermo.system.SystemInterface} object - */ - public SystemInterface TPgradientFlash(double height, double temperature) { - operation = new TPgradientFlash(system, height, temperature); - getOperation().run(); - return operation.getThermoSystem(); - } - - /** - *

- * dTPflash. - *

- * - * @param comps an array of {@link java.lang.String} objects - */ - public void dTPflash(String[] comps) { - operation = new dTPflash(system, comps); - getOperation().run(); - } - - /** - *

- * chemicalEquilibrium. - *

- */ - public void chemicalEquilibrium() { - if (system.isChemicalSystem()) { - operation = new neqsim.thermodynamicOperations.chemicalEquilibrium.ChemicalEquilibrium( - system); - getOperation().run(); - } - } - - /** - *

- * PHflash. - *

- * - * @param Hspec a double - * @param type a int - */ - public void PHflash(double Hspec, int type) { - if (system.getPhase(0).getNumberOfComponents() == 1) { - operation = new PHflashSingleComp(system, Hspec, type); - } else { - operation = new PHflash(system, Hspec, type); - } - getOperation().run(); - } - - /** - * Method to perform a PH flash calculation - * - * @param Hspec is the enthalpy in the specified unit - * @param enthalpyUnit Supported units are J, J/mol, J/kg and kJ/kg - */ - public void PHflash(double Hspec, String enthalpyUnit) { - double conversionFactor = 1.0; - switch (enthalpyUnit) { - case "J": - conversionFactor = 1.0; - break; - case "J/mol": - conversionFactor = 1.0 / system.getTotalNumberOfMoles(); - break; - case "J/kg": - conversionFactor = 1.0 / system.getTotalNumberOfMoles() / system.getMolarMass(); - break; - case "kJ/kg": - conversionFactor = 1.0 / system.getTotalNumberOfMoles() / system.getMolarMass() / 1000.0; - break; - } - PHflash(Hspec / conversionFactor); - } - - /** - * Method to perform a PH flash calculation - * - * @param Hspec is the enthalpy in unit Joule to be held constant - */ - public void PHflash(double Hspec) { - this.PHflash(Hspec, 0); - } - - /** - * Method to perform a PH flash calculation based on GERG2008 EoS - * - * @param Hspec is the enthalpy in unit Joule to be held constant - */ - public void PHflashGERG2008(double Hspec) { - operation = new neqsim.thermodynamicOperations.flashOps.PHflashGERG2008(system, Hspec); - getOperation().run(); - } - - /** - *

- * PUflash. - *

- * - * @param Uspec a double - */ - public void PUflash(double Uspec) { - operation = new neqsim.thermodynamicOperations.flashOps.PUflash(system, Uspec); - getOperation().run(); - } - - /** - *

- * PUflash. - *

- * - * @param Pspec a double - * @param Uspec a double - * @param unitPressure a {@link java.lang.String} object - * @param unitEnergy a {@link java.lang.String} object - */ - public void PUflash(double Pspec, double Uspec, String unitPressure, String unitEnergy) { - system.setPressure(Pspec, unitPressure); - PUflash(Uspec, unitEnergy); - } - - /** - *

- * PUflash. - *

- * - * @param Uspec a double - * @param unitEnergy a {@link java.lang.String} object - */ - public void PUflash(double Uspec, String unitEnergy) { - double conversionFactorEntr = 1.0; - switch (unitEnergy) { - case "J": - conversionFactorEntr = 1.0; - break; - case "J/mol": - conversionFactorEntr = 1.0 / system.getTotalNumberOfMoles(); - break; - case "J/kg": - conversionFactorEntr = 1.0 / system.getTotalNumberOfMoles() / system.getMolarMass(); - break; - case "kJ/kg": - conversionFactorEntr = 1.0 / system.getTotalNumberOfMoles() / system.getMolarMass() / 1000.0; - break; - } - PUflash(Uspec / conversionFactorEntr); - } - - /** - *

- * PHflash2. - *

- * - * @param Hspec a double - * @param type a int - */ - public void PHflash2(double Hspec, int type) { - operation = new PHflash(system, Hspec, type); - getOperation().run(); - } - - /** - *

- * criticalPointFlash. - *

- */ - public void criticalPointFlash() { - operation = new CriticalPointFlash(system); - getOperation().run(); - } - - /** - *

- * PHsolidFlash. - *

- * - * @param Hspec a double - */ - public void PHsolidFlash(double Hspec) { - operation = new PHsolidFlash(system, Hspec); - getOperation().run(); - } - - /** - * Method to perform a PS flash calculation for a specified entropy and pressure - * - * @param Sspec is the entropy in the specified unit - * @param unit Supported units are J/K, J/molK, J/kgK and kJ/kgK - */ - public void PSflash(double Sspec, String unit) { - double conversionFactor = 1.0; - switch (unit) { - case "J/K": - conversionFactor = 1.0; - break; - case "J/molK": - conversionFactor = 1.0 / system.getTotalNumberOfMoles(); - break; - case "J/kgK": - conversionFactor = 1.0 / system.getTotalNumberOfMoles() / system.getMolarMass(); - break; - case "kJ/kgK": - conversionFactor = 1.0 / system.getTotalNumberOfMoles() / system.getMolarMass() / 1000.0; - break; - } - PSflash(Sspec / conversionFactor); - } - - /** - * Method to perform a TS flash calculation for a specified entropy and pressure - * - * @param Sspec is the entropy in the specified unit - * @param unit Supported units are J/K, J/molK, J/kgK and kJ/kgK - */ - public void TSflash(double Sspec, String unit) { - double conversionFactor = 1.0; - switch (unit) { - case "J/K": - conversionFactor = 1.0; - break; - case "J/molK": - conversionFactor = 1.0 / system.getTotalNumberOfMoles(); - break; - case "J/kgK": - conversionFactor = 1.0 / system.getTotalNumberOfMoles() / system.getMolarMass(); - break; - case "kJ/kgK": - conversionFactor = 1.0 / system.getTotalNumberOfMoles() / system.getMolarMass() / 1000.0; - break; - } - TSflash(Sspec / conversionFactor); - } - - /** - *

- * PSflash. - *

- * - * @param Sspec a double - */ - public void PSflash(double Sspec) { - if (system.getPhase(0).getNumberOfComponents() == 1) { - operation = new PSflashSingleComp(system, Sspec, 0); - } else { - operation = new PSFlash(system, Sspec, 0); - } - getOperation().run(); - } - - /** - *

- * PSflashGERG2008. - *

- * Run a flash at constant pressure and entropy using the GERG2008 EoS - * - * @param Sspec is the specidfied entropy - */ - public void PSflashGERG2008(double Sspec) { - operation = new PSFlashGERG2008(system, Sspec); - getOperation().run(); - } - - /** - *

- * TSflash. - *

- * - * @param Sspec a double - */ - public void TSflash(double Sspec) { - operation = new TSFlash(system, Sspec); - getOperation().run(); - } - - /** - *

- * PSflash2. - *

- * - * @param Sspec a double - */ - public void PSflash2(double Sspec) { - operation = new PSFlash(system, Sspec, 0); - getOperation().run(); - } - - /** - *

- * VSflash. - *

- * - * @param volume a double - * @param entropy a double - * @param unitVol a {@link java.lang.String} object - * @param unitEntropy a {@link java.lang.String} object - */ - public void VSflash(double volume, double entropy, String unitVol, String unitEntropy) { - double conversionFactorV = 1.0; - double conversionFactorEntr = 1.0; - - switch (unitVol) { - case "m3": - conversionFactorV = 1.0e5; - break; - } - - switch (unitEntropy) { - case "J/K": - conversionFactorEntr = 1.0; - break; - case "J/molK": - conversionFactorEntr = 1.0 / system.getTotalNumberOfMoles(); - break; - case "J/kgK": - conversionFactorEntr = 1.0 / system.getTotalNumberOfMoles() / system.getMolarMass(); - break; - case "kJ/kgK": - conversionFactorEntr = 1.0 / system.getTotalNumberOfMoles() / system.getMolarMass() / 1000.0; - break; - } - VSflash(volume * conversionFactorV, entropy / conversionFactorEntr); - } - - /** - *

- * VSflash. - *

- * - * @param volume a double - * @param entropy a double - */ - public void VSflash(double volume, double entropy) { - operation = new neqsim.thermodynamicOperations.flashOps.VSflash(system, volume, entropy); - getOperation().run(); - } - - /** - *

- * TVflash. - *

- * - * @param Vspec a double - * @param unit a {@link java.lang.String} object - */ - public void TVflash(double Vspec, String unit) { - double conversionFactor = 1.0; - switch (unit) { - case "m3": - conversionFactor = 1.0e5; - break; - } - TVflash(Vspec * conversionFactor); - } - - /** - *

- * TVflash. - *

- * - * @param Vspec a double - */ - public void TVflash(double Vspec) { - operation = new TVflash(system, Vspec); - getOperation().run(); - } - - /** - *

- * PVrefluxFlash. - *

- * - * @param refluxspec a double - * @param refluxPhase a int - */ - public void PVrefluxFlash(double refluxspec, int refluxPhase) { - operation = new PVrefluxflash(system, refluxspec, refluxPhase); - getOperation().run(); - } - - /** - *

- * VHflash. - *

- * - * @param Vspec a double - * @param Hspec a double - */ - public void VHflash(double Vspec, double Hspec) { - operation = new VHflashQfunc(system, Vspec, Hspec); - getOperation().run(); - } - - /** - *

- * VHflash. - *

- * - * @param volume a double - * @param enthalpy a double - * @param unitVol a {@link java.lang.String} object - * @param unitEnthalpy a {@link java.lang.String} object - */ - public void VHflash(double volume, double enthalpy, String unitVol, String unitEnthalpy) { - double conversionFactorV = 1.0; - double conversionFactorEntr = 1.0; - - switch (unitVol) { - case "m3": - conversionFactorV = 1.0e5; - break; - } - - switch (unitEnthalpy) { - case "J/K": - conversionFactorEntr = 1.0; - break; - case "J/mol": - conversionFactorEntr = 1.0 / system.getTotalNumberOfMoles(); - break; - case "J/kg": - conversionFactorEntr = 1.0 / system.getTotalNumberOfMoles() / system.getMolarMass(); - break; - case "kJ/kg": - conversionFactorEntr = 1.0 / system.getTotalNumberOfMoles() / system.getMolarMass() / 1000.0; - break; - } - VHflash(volume * conversionFactorV, enthalpy / conversionFactorEntr); - } - - /** - *

- * VUflash. - *

- * - * @param volume a double - * @param energy a double - * @param unitVol a {@link java.lang.String} object - * @param unitEnergy a {@link java.lang.String} object - */ - public void VUflash(double volume, double energy, String unitVol, String unitEnergy) { - double conversionFactorV = 1.0; - double conversionFactorEntr = 1.0; - - switch (unitVol) { - case "m3": - conversionFactorV = 1.0e5; - break; - } - - switch (unitEnergy) { - case "J/K": - conversionFactorEntr = 1.0; - break; - case "J/mol": - conversionFactorEntr = 1.0 / system.getTotalNumberOfMoles(); - break; - case "J/kg": - conversionFactorEntr = 1.0 / system.getTotalNumberOfMoles() / system.getMolarMass(); - break; - case "kJ/kg": - conversionFactorEntr = 1.0 / system.getTotalNumberOfMoles() / system.getMolarMass() / 1000.0; - break; - } - VUflash(volume * conversionFactorV, energy / conversionFactorEntr); - } - - /** - *

- * VUflash. - *

- * - * @param Vspec a double - * @param Uspec a double - */ - public void VUflash(double Vspec, double Uspec) { - operation = new VUflashQfunc(system, Vspec, Uspec); - getOperation().run(); - } - - /** - *

- * bubblePointTemperatureFlash. - *

- * - * @throws java.lang.Exception if any. - */ - public void bubblePointTemperatureFlash() throws Exception { - constantDutyFlashInterface operation = new bubblePointTemperatureNoDer(system); - operation.run(); - if (Double.isNaN(system.getTemperature()) || operation.isSuperCritical()) { - throw new neqsim.util.exception.IsNaNException(this.getClass().getSimpleName(), - "bubblePointTemperatureFlash", - "Could not find solution - possible no bubble point exists"); - } - } - - /** - *

- * freezingPointTemperatureFlash. - *

- * - * @throws java.lang.Exception if any. - */ - public void freezingPointTemperatureFlash() throws Exception { - operation = new freezingPointTemperatureFlash(system); - getOperation().run(); - if (Double.isNaN(system.getTemperature())) { - throw new neqsim.util.exception.IsNaNException(this.getClass().getSimpleName(), - "freezingPointTemperatureFlash", - "Could not find solution - possible no freezing point exists"); - } - } - - /** - *

- * freezingPointTemperatureFlash. - *

- * - * @param phaseName a {@link java.lang.String} object - * @throws java.lang.Exception if any. - */ - public void freezingPointTemperatureFlash(String phaseName) throws Exception { - operation = new freezingPointTemperatureFlash(system); - getOperation().run(); - if (Double.isNaN(system.getTemperature())) { - throw new neqsim.util.exception.IsNaNException(this.getClass().getSimpleName(), - "freezingPointTemperatureFlash", - "Could not find solution - possible no freezing point exists"); - } - } - - /** - *

- * waterDewPointTemperatureFlash. - *

- * - * @throws java.lang.Exception if any. - */ - public void waterDewPointTemperatureFlash() throws Exception { - operation = new waterDewPointTemperatureFlash(system); - getOperation().run(); - if (Double.isNaN(system.getTemperature())) { - throw new neqsim.util.exception.IsNaNException(this.getClass().getSimpleName(), - "waterDewPointTemperatureFlash", - "Could not find solution - possible no dew point exists"); - } - } - - /** - *

- * waterDewPointTemperatureMultiphaseFlash. - *

- * - * @throws java.lang.Exception if any. - */ - public void waterDewPointTemperatureMultiphaseFlash() throws Exception { - operation = new waterDewPointTemperatureMultiphaseFlash(system); - getOperation().run(); - } - - /** - *

- * waterPrecipitationTemperature. - *

- * - * @throws java.lang.Exception if any. - */ - public void waterPrecipitationTemperature() throws Exception { - double lowTemperature = 0.0; - dewPointTemperatureFlash(); - - if (system.getTemperature() > lowTemperature) { - lowTemperature = system.getTemperature(); - } - - // if(lowTemperature<273.15 && system.doSolidPhaseCheck()){ - // hydrateFormationTemperature(0); - // if(system.getTemperature()>lowTemperature) lowTemperature = - // system.getTemperature(); - // } - - // if(system.doHydrateCheck()){ - // hydrateFormationTemperature(1); - // if(system.getTemperature()>lowTemperature) lowTemperature = - // system.getTemperature(); - // hydrateFormationTemperature(2); - // if(system.getTemperature()>lowTemperature) lowTemperature = - // system.getTemperature(); - // } - - system.setTemperature(lowTemperature); - // TPflash(); - - if (Double.isNaN(system.getTemperature())) { - throw new neqsim.util.exception.IsNaNException(this.getClass().getSimpleName(), - "waterPrecipitationTemperature", - "Could not find solution - possible no dew point exists"); - } - } - - /** - *

- * calcSaltSaturation. - *

- * - * @param saltName a {@link java.lang.String} object - * @throws java.lang.Exception if any. - */ - public void calcSaltSaturation(String saltName) throws Exception { - operation = new calcSaltSatauration(system, saltName); - getOperation().run(); - if (Double.isNaN(system.getTemperature())) { - throw new neqsim.util.exception.IsNaNException(this.getClass().getSimpleName(), - "calcSaltSaturation", "Could not find solution - possible no dew point exists"); - } - } - - /** - *

- * checkScalePotential. - *

- * - * @param phaseNumber a int - * @throws java.lang.Exception if any. - */ - public void checkScalePotential(int phaseNumber) throws Exception { - operation = new checkScalePotential(system, phaseNumber); - getOperation().run(); - resultTable = getOperation().getResultTable(); - if (Double.isNaN(system.getTemperature())) { - throw new neqsim.util.exception.IsNaNException(this.getClass().getSimpleName(), - "checkScalePotential", "Could not find solution - possible no dew point exists"); - } - } - - /** - *

- * addIonToScaleSaturation. - *

- * - * @param phaseNumber a int - * @param scaleSaltName a {@link java.lang.String} object - * @param nameOfIonToBeAdded a {@link java.lang.String} object - * @throws java.lang.Exception if any. - */ - public void addIonToScaleSaturation(int phaseNumber, String scaleSaltName, - String nameOfIonToBeAdded) throws Exception { - operation = new addIonToScaleSaturation(system, phaseNumber, scaleSaltName, nameOfIonToBeAdded); - getOperation().run(); - resultTable = getOperation().getResultTable(); - if (Double.isNaN(system.getTemperature())) { - throw new neqsim.util.exception.IsNaNException(this.getClass().getSimpleName(), - "addIonToScaleSaturation", "Could not find solution - possible no dew point exists"); - } - } - - /** - *

- * hydrateFormationPressure. - *

- * - * @throws java.lang.Exception if any. - */ - public void hydrateFormationPressure() throws Exception { - operation = new HydrateFormationPressureFlash(system); - getOperation().run(); - if (Double.isNaN(system.getTemperature())) { - throw new neqsim.util.exception.IsNaNException(this.getClass().getSimpleName(), - "hydrateFormationPressure", "Could not find solution - possible no dew point exists"); - } - } - - /** - *

- * calcWAT. - *

- * - * @throws java.lang.Exception if any. - */ - public void calcWAT() throws Exception { - operation = new WATcalc(system); - getOperation().run(); - if (Double.isNaN(system.getTemperature())) { - throw new neqsim.util.exception.IsNaNException(this.getClass().getSimpleName(), "calcWAT", - "Could not find solution - possible no dew point exists"); - } - } - - /** - *

- * run. - *

- */ - public void run() { - setThermoOperationThread(new Thread(operation)); - getThermoOperationThread().start(); - } - - /** - *

- * waitAndCheckForFinishedCalculation. - *

- * - * @param maxTime a int - * @return a boolean - */ - public boolean waitAndCheckForFinishedCalculation(int maxTime) { - try { - getThermoOperationThread().join(maxTime); - getThermoOperationThread().interrupt(); - } catch (Exception e) { - logger.error("error", e); - } - boolean didFinish = !getThermoOperationThread().isInterrupted(); - // getThermoOperationThread().stop(); - return didFinish; - } - - /** - *

- * waitToFinishCalculation. - *

- */ - public void waitToFinishCalculation() { - try { - getThermoOperationThread().join(); - } catch (Exception e) { - logger.error("error", e); - } - } - - /** - *

- * calcSolidComlexTemperature. - *

- * - * @throws java.lang.Exception if any. - */ - public void calcSolidComlexTemperature() throws Exception { - operation = new SolidComplexTemperatureCalc(system); - getOperation().run(); - if (Double.isNaN(system.getTemperature())) { - throw new neqsim.util.exception.IsNaNException(this.getClass().getSimpleName(), - "calcSolidComlexTemperature", - "error in WAT() - could not find solution - possible no dew point exists"); - } - } - - /** - *

- * calcSolidComlexTemperature. - *

- * - * @param comp1 a {@link java.lang.String} object - * @param comp2 a {@link java.lang.String} object - * @throws java.lang.Exception if any. - */ - public void calcSolidComlexTemperature(String comp1, String comp2) throws Exception { - if (operation == null) { - operation = new SolidComplexTemperatureCalc(system, comp1, comp2); - } - getOperation().run(); - if (Double.isNaN(system.getTemperature())) { - throw new neqsim.util.exception.IsNaNException(this.getClass().getSimpleName(), - "calcSolidComlexTemperature", - "error in WAT() - could not find solution - possible no dew point exists"); - } - } - - /** - *

- * calcImobilePhaseHydrateTemperature. - *

- * - * @param temperature an array of {@link double} objects - * @param pressure an array of {@link double} objects - * @return an array of {@link double} objects - */ - public double[] calcImobilePhaseHydrateTemperature(double[] temperature, double[] pressure) { - double[] hydTemps = new double[temperature.length]; - SystemInterface systemTemp; - ThermodynamicOperations opsTemp; - systemTemp = system.clone(); - - for (int i = 0; i < temperature.length; i++) { - /* - * opsTemp = new ThermodynamicOperations(systemTemp); - * systemTemp.setTemperature(temperature[i]); - * systemTemp.setPressure(pressure[i]); - * systemTemp.init(0); systemTemp.display(); try { - * opsTemp.hydrateFormationTemperature(); } catch (Exception e) { - * logger.error("error",e); } systemTemp.display(); hydTemps[i] = - * systemTemp.getTemperature(); - * - */ - opsTemp = new ThermodynamicOperations(systemTemp); - systemTemp.setTemperature(temperature[i]); - systemTemp.setPressure(pressure[i]); - - opsTemp.TPflash(); - systemTemp.display(); - systemTemp = systemTemp.phaseToSystem(0); - } - - opsTemp = new ThermodynamicOperations(systemTemp); - systemTemp.setHydrateCheck(true); - systemTemp.setMixingRule(9); - try { - opsTemp.hydrateFormationTemperature(); - } catch (Exception e) { - logger.error("error", e); - } - systemTemp.display(); - return hydTemps; - } - - /** - *

- * calcTOLHydrateFormationTemperature. - *

- * - * @return a double - */ - public double calcTOLHydrateFormationTemperature() { - TPflash(); - - SystemInterface systemTemp = system.phaseToSystem(0); - ThermodynamicOperations opsTemp = new ThermodynamicOperations(systemTemp); - try { - opsTemp.hydrateFormationTemperature(); - } catch (Exception e) { - logger.error("error", e); - } - systemTemp.display(); - system.setTemperature(systemTemp.getTemperature()); - TPflash(); - return system.getTemperature(); - } - - /** - *

- * hydrateInhibitorConcentration. - *

- * - * @param inhibitorName a {@link java.lang.String} object - * @param hydEqTemperature a double - * @throws java.lang.Exception if any. - */ - public void hydrateInhibitorConcentration(String inhibitorName, double hydEqTemperature) - throws Exception { - operation = new HydrateInhibitorConcentrationFlash(system, inhibitorName, hydEqTemperature); - operation.run(); - } - - /** - *

- * hydrateInhibitorConcentrationSet. - *

- * - * @param inhibitorName a {@link java.lang.String} object - * @param wtfrac a double - * @throws java.lang.Exception if any. - */ - public void hydrateInhibitorConcentrationSet(String inhibitorName, double wtfrac) - throws Exception { - operation = new HydrateInhibitorwtFlash(system, inhibitorName, wtfrac); - operation.run(); - } - - /** - *

- * hydrateFormationTemperature. - *

- * - * @param initialTemperatureGuess a double - * @throws java.lang.Exception if any. - */ - public void hydrateFormationTemperature(double initialTemperatureGuess) throws Exception { - system.setTemperature(initialTemperatureGuess); - operation = new HydrateFormationTemperatureFlash(system); - for (int i = 0; i < system.getPhase(4).getNumberOfComponents(); i++) { - ((ComponentHydrate) system.getPhase(4).getComponent(i)).getHydrateStructure(); - } - if (!isRunAsThread()) { - getOperation().run(); - } else { - run(); - } - } - - /** - *

- * hydrateFormationTemperature. - *

- * - * @throws java.lang.Exception if any. - */ - public void hydrateFormationTemperature() throws Exception { - // guessing temperature - double factor = 1.0; - if (system.getPhase(0).hasComponent("methanol")) { - factor -= 2 * system.getPhase(0).getComponent("methanol").getz() - / system.getPhase(0).getComponent("water").getz(); - } - if (system.getPhase(0).hasComponent("MEG")) { - factor -= 2 * system.getPhase(0).getComponent("MEG").getz() - / system.getPhase(0).getComponent("water").getz(); - } - if (factor < 2) { - factor = 2; - } - - system.setTemperature(273.0 + system.getPressure() / 100.0 * 20.0 * factor - 20.0); - if (system.getTemperature() > 298.15) { - system.setTemperature(273.0 + 25.0); - } - // logger.info("guess hydrate temperature " + system.getTemperature()); - operation = new HydrateFormationTemperatureFlash(system); - - for (int i = 0; i < system.getPhase(4).getNumberOfComponents(); i++) { - ((ComponentHydrate) system.getPhase(4).getComponent(i)).getHydrateStructure(); - } - if (!isRunAsThread()) { - getOperation().run(); - } else { - run(); - } - // logger.info("Hydrate structure " + (((ComponentHydrate) - // system.getPhase(4).getComponent("water")).getHydrateStructure() + 1)); - } - - /** - *

- * hydrateEquilibriumLine. - *

- * - * @param minimumPressure a double - * @param maximumPressure a double - * @throws java.lang.Exception if any. - */ - public void hydrateEquilibriumLine(double minimumPressure, double maximumPressure) - throws Exception { - operation = new HydrateEquilibriumLine(system, minimumPressure, maximumPressure); - if (!isRunAsThread()) { - getOperation().run(); - } else { - run(); - } - } - - /** - *

- * calcCricoP. - *

- * - * @param cricondenBar an array of {@link double} objects - * @param cricondenBarX an array of {@link double} objects - * @param cricondenBarY an array of {@link double} objects - */ - public void calcCricoP(double[] cricondenBar, double[] cricondenBarX, double[] cricondenBarY) { - double phasefraction = 1.0 - 1e-10; - - operation = new CricondenBarFlash(system, fileName, phasefraction, cricondenBar, - cricondenBarX, cricondenBarY); - - getOperation().run(); - } - - /** - *

- * calcCricoT. - *

- * - * @param cricondenTherm an array of {@link double} objects - * @param cricondenThermX an array of {@link double} objects - * @param cricondenThermY an array of {@link double} objects - */ - public void calcCricoT(double[] cricondenTherm, double[] cricondenThermX, - double[] cricondenThermY) { - double phasefraction = 1.0 - 1e-10; - - operation = new CricondenThermFlash(system, fileName, phasefraction, cricondenTherm, - cricondenThermX, cricondenThermY); - - getOperation().run(); - } - - /** - *

- * waterDewPointLine. - *

- * - * @param minimumPressure a double - * @param maximumPressure a double - * @throws java.lang.Exception if any. - */ - public void waterDewPointLine(double minimumPressure, double maximumPressure) throws Exception { - operation = new WaterDewPointEquilibriumLine(system, minimumPressure, maximumPressure); - if (!isRunAsThread()) { - getOperation().run(); - } else { - run(); - } - } - - /** - *

- * hydrateFormationTemperature. - *

- * - * @param structure a int - * @throws java.lang.Exception if any. - */ - public void hydrateFormationTemperature(int structure) throws Exception { - system.setTemperature(273.0 + 1.0); - if (structure == 0) { - system.setSolidPhaseCheck("water"); - system.setHydrateCheck(true); - operation = new freezingPointTemperatureFlash(system); - } else { - operation = new HydrateFormationTemperatureFlash(system); - } - - for (int i = 0; i < system.getPhase(4).getNumberOfComponents(); i++) { - ((ComponentHydrate) system.getPhases()[4].getComponent(i)) - .setHydrateStructure(structure - 1); - } - if (!isRunAsThread()) { - getOperation().run(); - } else { - run(); - } - - if (Double.isNaN(system.getTemperature())) { - throw new neqsim.util.exception.IsNaNException(this.getClass().getSimpleName(), - "hydrateFormationTemperature", - "Could not find solution - possible no dew point exists"); - } - } - - /** - *

- * calcCricondenBar. - *

- * - * @return a double - */ - public double calcCricondenBar() { - system.init(0); - operation = new cricondebarFlash(system); - // operation = new CricondenBarFlash(system); - - // operation = new cricondenBarTemp1(system); - operation.run(); - return system.getPressure(); - } - - /** - *

- * bubblePointPressureFlash. - *

- * - * @throws java.lang.Exception if any. - */ - public void bubblePointPressureFlash() throws Exception { - system.init(0); - constantDutyFlashInterface operation = new constantDutyPressureFlash(system); - system.setBeta(1, 1.0 - 1e-10); - system.setBeta(0, 1e-10); - operation.run(); - if (Double.isNaN(system.getPressure()) || operation.isSuperCritical()) { - throw new neqsim.util.exception.IsNaNException(this.getClass().getSimpleName(), - "bubblePointPressureFlash", "Could not find solution - possible no dew point exists"); - } - } + private static final long serialVersionUID = 1000; + + private Thread thermoOperationThread = new Thread(); + private OperationInterface operation = null; + SystemInterface system = null; + boolean writeFile = false; + String fileName = null; + private boolean runAsThread = false; + protected String[][] resultTable = null; + static Logger logger = LogManager.getLogger(ThermodynamicOperations.class); + + /** + *

+ * Constructor for ThermodynamicOperations. + *

+ */ + public ThermodynamicOperations() {} + + /** + *

+ * Constructor for ThermodynamicOperations. + *

+ * + * @param system a {@link neqsim.thermo.system.SystemInterface} object + */ + public ThermodynamicOperations(SystemInterface system) { + this.system = system; + } + + /** + *

+ * Setter for the field system. + *

+ * + * @param system a {@link neqsim.thermo.system.SystemInterface} object + */ + public void setSystem(SystemInterface system) { + this.system = system; + } + + /** + *

+ * TPSolidflash. + *

+ */ + public void TPSolidflash() { + operation = new SolidFlash1(system); + getOperation().run(); + } + + /** + * Method to perform a flash at given temperature, pressure and specified volume The number of + * moles in the system are changed to match the specified volume. + * + * @param volumeSpec is the specified volume + * @param unit Supported units are m3 + */ + public void TPVflash(double volumeSpec, String unit) { + unit = "m3"; + TPflash(); + double startVolume = system.getVolume(unit); + system.setTotalNumberOfMoles(system.getNumberOfMoles() * volumeSpec / startVolume); + system.init(3); + } + + /** + *

+ * TPflash. + *

+ */ + public void TPflash() { + double flowRate = system.getTotalNumberOfMoles(); + double minimumFlowRate = 1e-50; + if (flowRate < 1e-3) { + system.setTotalNumberOfMoles(1.0); + system.init(1); + } + operation = + new neqsim.thermodynamicOperations.flashOps.TPflash(system, system.doSolidPhaseCheck()); + if (!isRunAsThread()) { + getOperation().run(); + } else { + run(); + } + if (flowRate < 1e-3) { + if (flowRate < minimumFlowRate) { + system.setTotalNumberOfMoles(minimumFlowRate); + } else { + system.setTotalNumberOfMoles(flowRate); + } + system.init(2); + } + } + + /** + *

+ * TPflash. + *

+ * + * @param checkSolids a boolean + */ + public void TPflash(boolean checkSolids) { + operation = new neqsim.thermodynamicOperations.flashOps.TPflash(system, checkSolids); + getOperation().run(); + } + + /** + *

+ * TPgradientFlash. + *

+ * + * @param height a double + * @param temperature a double + * @return a {@link neqsim.thermo.system.SystemInterface} object + */ + public SystemInterface TPgradientFlash(double height, double temperature) { + operation = new TPgradientFlash(system, height, temperature); + getOperation().run(); + return operation.getThermoSystem(); + } + + /** + *

+ * dTPflash. + *

+ * + * @param comps an array of {@link java.lang.String} objects + */ + public void dTPflash(String[] comps) { + operation = new dTPflash(system, comps); + getOperation().run(); + } + + /** + *

+ * saturateWithWater. + *

+ */ + public void saturateWithWater() { + operation = new SaturateWithWater(system); + getOperation().run(); + } + + /** + *

+ * chemicalEquilibrium. + *

+ */ + public void chemicalEquilibrium() { + if (system.isChemicalSystem()) { + operation = + new neqsim.thermodynamicOperations.chemicalEquilibrium.ChemicalEquilibrium(system); + getOperation().run(); + } + } + + /** + *

+ * PHflash. + *

+ * + * @param Hspec a double + * @param type a int + */ + public void PHflash(double Hspec, int type) { + if (system.getPhase(0).getNumberOfComponents() == 1) { + operation = new PHflashSingleComp(system, Hspec, type); + } else { + operation = new PHflash(system, Hspec, type); + } + getOperation().run(); + } + + /** + * Method to perform a PH flash calculation + * + * @param Hspec is the enthalpy in the specified unit + * @param enthalpyUnit Supported units are J, J/mol, J/kg and kJ/kg + */ + public void PHflash(double Hspec, String enthalpyUnit) { + double conversionFactor = 1.0; + switch (enthalpyUnit) { + case "J": + conversionFactor = 1.0; + break; + case "J/mol": + conversionFactor = 1.0 / system.getTotalNumberOfMoles(); + break; + case "J/kg": + conversionFactor = 1.0 / system.getTotalNumberOfMoles() / system.getMolarMass(); + break; + case "kJ/kg": + conversionFactor = 1.0 / system.getTotalNumberOfMoles() / system.getMolarMass() / 1000.0; + break; + default: + break; + } + PHflash(Hspec / conversionFactor); + } + + /** + * Method to perform a PH flash calculation + * + * @param Hspec is the enthalpy in unit Joule to be held constant + */ + public void PHflash(double Hspec) { + this.PHflash(Hspec, 0); + } + + /** + * Method to perform a PH flash calculation based on GERG2008 EoS + * + * @param Hspec is the enthalpy in unit Joule to be held constant + */ + public void PHflashGERG2008(double Hspec) { + operation = new neqsim.thermodynamicOperations.flashOps.PHflashGERG2008(system, Hspec); + getOperation().run(); + } + + /** + *

+ * PUflash. + *

+ * + * @param Uspec a double + */ + public void PUflash(double Uspec) { + operation = new neqsim.thermodynamicOperations.flashOps.PUflash(system, Uspec); + getOperation().run(); + } + + /** + *

+ * PUflash. + *

+ * + * @param Pspec a double + * @param Uspec a double + * @param unitPressure a {@link java.lang.String} object + * @param unitEnergy a {@link java.lang.String} object + */ + public void PUflash(double Pspec, double Uspec, String unitPressure, String unitEnergy) { + system.setPressure(Pspec, unitPressure); + PUflash(Uspec, unitEnergy); + } + + /** + *

+ * PUflash. + *

+ * + * @param Uspec a double + * @param unitEnergy a {@link java.lang.String} object + */ + public void PUflash(double Uspec, String unitEnergy) { + double conversionFactorEntr = 1.0; + switch (unitEnergy) { + case "J": + conversionFactorEntr = 1.0; + break; + case "J/mol": + conversionFactorEntr = 1.0 / system.getTotalNumberOfMoles(); + break; + case "J/kg": + conversionFactorEntr = 1.0 / system.getTotalNumberOfMoles() / system.getMolarMass(); + break; + case "kJ/kg": + conversionFactorEntr = + 1.0 / system.getTotalNumberOfMoles() / system.getMolarMass() / 1000.0; + break; + default: + break; + } + PUflash(Uspec / conversionFactorEntr); + } + + /** + *

+ * PHflash2. + *

+ * + * @param Hspec a double + * @param type a int + */ + public void PHflash2(double Hspec, int type) { + operation = new PHflash(system, Hspec, type); + getOperation().run(); + } + + /** + *

+ * criticalPointFlash. + *

+ */ + public void criticalPointFlash() { + operation = new CriticalPointFlash(system); + getOperation().run(); + } + + /** + *

+ * PHsolidFlash. + *

+ * + * @param Hspec a double + */ + public void PHsolidFlash(double Hspec) { + operation = new PHsolidFlash(system, Hspec); + getOperation().run(); + } + + /** + *

+ * PSflash. + *

+ * + * @param Sspec a double + */ + public void PSflash(double Sspec) { + if (system.getPhase(0).getNumberOfComponents() == 1) { + operation = new PSflashSingleComp(system, Sspec, 0); + } else { + operation = new PSFlash(system, Sspec, 0); + } + getOperation().run(); + } + + /** + * Method to perform a PS flash calculation for a specified entropy and pressure + * + * @param Sspec is the entropy in the specified unit + * @param unit Supported units are J/K, J/molK, J/kgK and kJ/kgK + */ + public void PSflash(double Sspec, String unit) { + double conversionFactor = 1.0; + switch (unit) { + case "J/K": + break; + case "J/molK": + conversionFactor = 1.0 / system.getTotalNumberOfMoles(); + break; + case "J/kgK": + conversionFactor = 1.0 / system.getTotalNumberOfMoles() / system.getMolarMass(); + break; + case "kJ/kgK": + conversionFactor = 1.0 / system.getTotalNumberOfMoles() / system.getMolarMass() / 1000.0; + break; + default: + break; + } + PSflash(Sspec / conversionFactor); + } + + /** + *

+ * TSflash. + *

+ * + * @param Sspec a double + */ + public void TSflash(double Sspec) { + operation = new TSFlash(system, Sspec); + getOperation().run(); + } + + /** + * Method to perform a TS flash calculation for a specified entropy and pressure + * + * @param Sspec is the entropy in the specified unit + * @param unit Supported units are J/K, J/molK, J/kgK and kJ/kgK + */ + public void TSflash(double Sspec, String unit) { + double conversionFactor = 1.0; + switch (unit) { + case "J/K": + conversionFactor = 1.0; + break; + case "J/molK": + conversionFactor = 1.0 / system.getTotalNumberOfMoles(); + break; + case "J/kgK": + conversionFactor = 1.0 / system.getTotalNumberOfMoles() / system.getMolarMass(); + break; + case "kJ/kgK": + conversionFactor = 1.0 / system.getTotalNumberOfMoles() / system.getMolarMass() / 1000.0; + break; + default: + break; + } + TSflash(Sspec / conversionFactor); + } + + /** + *

+ * PSflashGERG2008. + *

+ * Run a flash at constant pressure and entropy using the GERG2008 EoS + * + * @param Sspec is the specidfied entropy + */ + public void PSflashGERG2008(double Sspec) { + operation = new PSFlashGERG2008(system, Sspec); + getOperation().run(); + } + + /** + *

+ * PSflash2. + *

+ * + * @param Sspec a double + */ + public void PSflash2(double Sspec) { + operation = new PSFlash(system, Sspec, 0); + getOperation().run(); + } + + /** + *

+ * VSflash. + *

+ * + * @param volume a double + * @param entropy a double + * @param unitVol a {@link java.lang.String} object + * @param unitEntropy a {@link java.lang.String} object + */ + public void VSflash(double volume, double entropy, String unitVol, String unitEntropy) { + double conversionFactorV = 1.0; + double conversionFactorEntr = 1.0; + + switch (unitVol) { + case "m3": + conversionFactorV = 1.0e5; + break; + default: + break; + } + + switch (unitEntropy) { + case "J/K": + conversionFactorEntr = 1.0; + break; + case "J/molK": + conversionFactorEntr = 1.0 / system.getTotalNumberOfMoles(); + break; + case "J/kgK": + conversionFactorEntr = 1.0 / system.getTotalNumberOfMoles() / system.getMolarMass(); + break; + case "kJ/kgK": + conversionFactorEntr = + 1.0 / system.getTotalNumberOfMoles() / system.getMolarMass() / 1000.0; + break; + default: + break; + } + VSflash(volume * conversionFactorV, entropy / conversionFactorEntr); + } + + /** + *

+ * VSflash. + *

+ * + * @param volume a double + * @param entropy a double + */ + public void VSflash(double volume, double entropy) { + operation = new neqsim.thermodynamicOperations.flashOps.VSflash(system, volume, entropy); + getOperation().run(); + } + + /** + *

+ * TVflash. + *

+ * + * @param Vspec a double + * @param unit a {@link java.lang.String} object + */ + public void TVflash(double Vspec, String unit) { + double conversionFactor = 1.0; + switch (unit) { + case "m3": + conversionFactor = 1.0e5; + break; + default: + break; + } + TVflash(Vspec * conversionFactor); + } + + /** + *

+ * TVflash. + *

+ * + * @param Vspec a double + */ + public void TVflash(double Vspec) { + operation = new TVflash(system, Vspec); + getOperation().run(); + } + + /** + *

+ * PVrefluxFlash. + *

+ * + * @param refluxspec a double + * @param refluxPhase a int + */ + public void PVrefluxFlash(double refluxspec, int refluxPhase) { + operation = new PVrefluxflash(system, refluxspec, refluxPhase); + getOperation().run(); + } + + /** + *

+ * VHflash. + *

+ * + * @param Vspec a double + * @param Hspec a double + */ + public void VHflash(double Vspec, double Hspec) { + operation = new VHflashQfunc(system, Vspec, Hspec); + getOperation().run(); + } + + /** + *

+ * VHflash. + *

+ * + * @param volume a double + * @param enthalpy a double + * @param unitVol a {@link java.lang.String} object + * @param unitEnthalpy a {@link java.lang.String} object + */ + public void VHflash(double volume, double enthalpy, String unitVol, String unitEnthalpy) { + double conversionFactorV = 1.0; + double conversionFactorEntr = 1.0; + + switch (unitVol) { + case "m3": + conversionFactorV = 1.0e5; + break; + default: + break; + } + + switch (unitEnthalpy) { + case "J/K": + conversionFactorEntr = 1.0; + break; + case "J/mol": + conversionFactorEntr = 1.0 / system.getTotalNumberOfMoles(); + break; + case "J/kg": + conversionFactorEntr = 1.0 / system.getTotalNumberOfMoles() / system.getMolarMass(); + break; + case "kJ/kg": + conversionFactorEntr = + 1.0 / system.getTotalNumberOfMoles() / system.getMolarMass() / 1000.0; + break; + default: + break; + } + VHflash(volume * conversionFactorV, enthalpy / conversionFactorEntr); + } + + /** + *

+ * VUflash. + *

+ * + * @param volume a double + * @param energy a double + * @param unitVol a {@link java.lang.String} object + * @param unitEnergy a {@link java.lang.String} object + */ + public void VUflash(double volume, double energy, String unitVol, String unitEnergy) { + double conversionFactorV = 1.0; + double conversionFactorEntr = 1.0; + + switch (unitVol) { + case "m3": + conversionFactorV = 1.0e5; + break; + default: + break; + } + + switch (unitEnergy) { + case "J/K": + conversionFactorEntr = 1.0; + break; + case "J/mol": + conversionFactorEntr = 1.0 / system.getTotalNumberOfMoles(); + break; + case "J/kg": + conversionFactorEntr = 1.0 / system.getTotalNumberOfMoles() / system.getMolarMass(); + break; + case "kJ/kg": + conversionFactorEntr = + 1.0 / system.getTotalNumberOfMoles() / system.getMolarMass() / 1000.0; + break; + default: + break; + } + VUflash(volume * conversionFactorV, energy / conversionFactorEntr); + } + + /** + *

+ * VUflash. + *

+ * + * @param Vspec a double + * @param Uspec a double + */ + public void VUflash(double Vspec, double Uspec) { + operation = new VUflashQfunc(system, Vspec, Uspec); + getOperation().run(); + } + + /** + *

+ * bubblePointTemperatureFlash. + *

+ * + * @throws java.lang.Exception if any. + */ + public void bubblePointTemperatureFlash() throws Exception { + constantDutyFlashInterface operation = new bubblePointTemperatureNoDer(system); + operation.run(); + if (Double.isNaN(system.getTemperature()) || operation.isSuperCritical()) { + throw new neqsim.util.exception.IsNaNException(this.getClass().getSimpleName(), + "bubblePointTemperatureFlash", + "Could not find solution - possible no bubble point exists"); + } + } + + /** + *

+ * freezingPointTemperatureFlash. + *

+ * + * @throws java.lang.Exception if any. + */ + public void freezingPointTemperatureFlash() throws Exception { + operation = new freezingPointTemperatureFlash(system); + getOperation().run(); + if (Double.isNaN(system.getTemperature())) { + throw new neqsim.util.exception.IsNaNException(this.getClass().getSimpleName(), + "freezingPointTemperatureFlash", + "Could not find solution - possible no freezing point exists"); + } + } + + /** + *

+ * freezingPointTemperatureFlash. + *

+ * + * @param phaseName a {@link java.lang.String} object + * @throws java.lang.Exception if any. + */ + public void freezingPointTemperatureFlash(String phaseName) throws Exception { + operation = new freezingPointTemperatureFlash(system); + getOperation().run(); + if (Double.isNaN(system.getTemperature())) { + throw new neqsim.util.exception.IsNaNException(this.getClass().getSimpleName(), + "freezingPointTemperatureFlash", + "Could not find solution - possible no freezing point exists"); + } + } + + /** + *

+ * waterDewPointTemperatureFlash. + *

+ * + * @throws java.lang.Exception if any. + */ + public void waterDewPointTemperatureFlash() throws Exception { + operation = new waterDewPointTemperatureFlash(system); + getOperation().run(); + if (Double.isNaN(system.getTemperature())) { + throw new neqsim.util.exception.IsNaNException(this.getClass().getSimpleName(), + "waterDewPointTemperatureFlash", + "Could not find solution - possible no dew point exists"); + } + } + + /** + *

+ * waterDewPointTemperatureMultiphaseFlash. + *

+ * + * @throws java.lang.Exception if any. + */ + public void waterDewPointTemperatureMultiphaseFlash() throws Exception { + operation = new waterDewPointTemperatureMultiphaseFlash(system); + getOperation().run(); + } + + /** + *

+ * waterPrecipitationTemperature. + *

+ * + * @throws java.lang.Exception if any. + */ + public void waterPrecipitationTemperature() throws Exception { + double lowTemperature = 0.0; + dewPointTemperatureFlash(); + + if (system.getTemperature() > lowTemperature) { + lowTemperature = system.getTemperature(); + } + + // if(lowTemperature<273.15 && system.doSolidPhaseCheck()){ + // hydrateFormationTemperature(0); + // if(system.getTemperature()>lowTemperature) lowTemperature = + // system.getTemperature(); + // } - /** - *

- * constantPhaseFractionPressureFlash. - *

- * - * @param fraction a double - * @throws java.lang.Exception if any. - */ - public void constantPhaseFractionPressureFlash(double fraction) throws Exception { - system.init(0); - if (fraction < 1e-10) { - fraction = 1e-10; - } - if (fraction > 1.0 - 1e-10) { - fraction = 1.0 - 1.0e-10; - } - constantDutyFlashInterface operation = new constantDutyPressureFlash(system); - system.setBeta(1, 1.0 - fraction); - system.setBeta(0, fraction); - operation.run(); - if (Double.isNaN(system.getPressure()) || operation.isSuperCritical()) { - throw new neqsim.util.exception.IsNaNException(this.getClass().getSimpleName(), - "constantPhaseFractionPressureFlash", - "Could not find solution - possible no dew point exists"); - } - } + // if(system.doHydrateCheck()){ + // hydrateFormationTemperature(1); + // if(system.getTemperature()>lowTemperature) lowTemperature = + // system.getTemperature(); + // hydrateFormationTemperature(2); + // if(system.getTemperature()>lowTemperature) lowTemperature = + // system.getTemperature(); + // } - /** - *

- * constantPhaseFractionTemperatureFlash. - *

- * - * @param fraction a double - * @throws java.lang.Exception if any. - */ - public void constantPhaseFractionTemperatureFlash(double fraction) throws Exception { + system.setTemperature(lowTemperature); + // TPflash(); + + if (Double.isNaN(system.getTemperature())) { + throw new neqsim.util.exception.IsNaNException(this.getClass().getSimpleName(), + "waterPrecipitationTemperature", + "Could not find solution - possible no dew point exists"); + } + } + + /** + *

+ * calcSaltSaturation. + *

+ * + * @param saltName a {@link java.lang.String} object + * @throws java.lang.Exception if any. + */ + public void calcSaltSaturation(String saltName) throws Exception { + operation = new calcSaltSatauration(system, saltName); + getOperation().run(); + if (Double.isNaN(system.getTemperature())) { + throw new neqsim.util.exception.IsNaNException(this.getClass().getSimpleName(), + "calcSaltSaturation", "Could not find solution - possible no dew point exists"); + } + } + + /** + *

+ * checkScalePotential. + *

+ * + * @param phaseNumber a int + * @throws java.lang.Exception if any. + */ + public void checkScalePotential(int phaseNumber) throws Exception { + operation = new checkScalePotential(system, phaseNumber); + getOperation().run(); + resultTable = getOperation().getResultTable(); + if (Double.isNaN(system.getTemperature())) { + throw new neqsim.util.exception.IsNaNException(this.getClass().getSimpleName(), + "checkScalePotential", "Could not find solution - possible no dew point exists"); + } + } + + /** + *

+ * addIonToScaleSaturation. + *

+ * + * @param phaseNumber a int + * @param scaleSaltName a {@link java.lang.String} object + * @param nameOfIonToBeAdded a {@link java.lang.String} object + * @throws java.lang.Exception if any. + */ + public void addIonToScaleSaturation(int phaseNumber, String scaleSaltName, + String nameOfIonToBeAdded) throws Exception { + operation = new addIonToScaleSaturation(system, phaseNumber, scaleSaltName, nameOfIonToBeAdded); + getOperation().run(); + resultTable = getOperation().getResultTable(); + if (Double.isNaN(system.getTemperature())) { + throw new neqsim.util.exception.IsNaNException(this.getClass().getSimpleName(), + "addIonToScaleSaturation", "Could not find solution - possible no dew point exists"); + } + } + + /** + *

+ * hydrateFormationPressure. + *

+ * + * @throws java.lang.Exception if any. + */ + public void hydrateFormationPressure() throws Exception { + operation = new HydrateFormationPressureFlash(system); + getOperation().run(); + if (Double.isNaN(system.getTemperature())) { + throw new neqsim.util.exception.IsNaNException(this.getClass().getSimpleName(), + "hydrateFormationPressure", "Could not find solution - possible no dew point exists"); + } + } + + /** + *

+ * calcWAT. + *

+ * + * @throws java.lang.Exception if any. + */ + public void calcWAT() throws Exception { + operation = new WATcalc(system); + getOperation().run(); + if (Double.isNaN(system.getTemperature())) { + throw new neqsim.util.exception.IsNaNException(this.getClass().getSimpleName(), "calcWAT", + "Could not find solution - possible no dew point exists"); + } + } + + /** + *

+ * run. + *

+ */ + public void run() { + setThermoOperationThread(new Thread(operation)); + getThermoOperationThread().start(); + } + + /** + *

+ * waitAndCheckForFinishedCalculation. + *

+ * + * @param maxTime a int + * @return a boolean + */ + public boolean waitAndCheckForFinishedCalculation(int maxTime) { + try { + getThermoOperationThread().join(maxTime); + getThermoOperationThread().interrupt(); + } catch (Exception e) { + logger.error("error", e); + } + boolean didFinish = !getThermoOperationThread().isInterrupted(); + // getThermoOperationThread().stop(); + return didFinish; + } + + /** + *

+ * waitToFinishCalculation. + *

+ */ + public void waitToFinishCalculation() { + try { + getThermoOperationThread().join(); + } catch (Exception e) { + logger.error("error", e); + } + } + + /** + *

+ * calcSolidComlexTemperature. + *

+ * + * @throws java.lang.Exception if any. + */ + public void calcSolidComlexTemperature() throws Exception { + operation = new SolidComplexTemperatureCalc(system); + getOperation().run(); + if (Double.isNaN(system.getTemperature())) { + throw new neqsim.util.exception.IsNaNException(this.getClass().getSimpleName(), + "calcSolidComlexTemperature", + "error in WAT() - could not find solution - possible no dew point exists"); + } + } + + /** + *

+ * calcSolidComlexTemperature. + *

+ * + * @param comp1 a {@link java.lang.String} object + * @param comp2 a {@link java.lang.String} object + * @throws java.lang.Exception if any. + */ + public void calcSolidComlexTemperature(String comp1, String comp2) throws Exception { + if (operation == null) { + operation = new SolidComplexTemperatureCalc(system, comp1, comp2); + } + getOperation().run(); + if (Double.isNaN(system.getTemperature())) { + throw new neqsim.util.exception.IsNaNException(this.getClass().getSimpleName(), + "calcSolidComlexTemperature", + "error in WAT() - could not find solution - possible no dew point exists"); + } + } + + /** + *

+ * calcImobilePhaseHydrateTemperature. + *

+ * + * @param temperature an array of {@link double} objects + * @param pressure an array of {@link double} objects + * @return an array of {@link double} objects + */ + public double[] calcImobilePhaseHydrateTemperature(double[] temperature, double[] pressure) { + double[] hydTemps = new double[temperature.length]; + SystemInterface systemTemp; + ThermodynamicOperations opsTemp; + systemTemp = system.clone(); + + for (int i = 0; i < temperature.length; i++) { + /* + * opsTemp = new ThermodynamicOperations(systemTemp); + * systemTemp.setTemperature(temperature[i]); systemTemp.setPressure(pressure[i]); + * systemTemp.init(0); systemTemp.display(); try { opsTemp.hydrateFormationTemperature(); } + * catch (Exception e) { logger.error("error",e); } systemTemp.display(); hydTemps[i] = + * systemTemp.getTemperature(); + * + */ + opsTemp = new ThermodynamicOperations(systemTemp); + systemTemp.setTemperature(temperature[i]); + systemTemp.setPressure(pressure[i]); + + opsTemp.TPflash(); + systemTemp.display(); + systemTemp = systemTemp.phaseToSystem(0); + } + + opsTemp = new ThermodynamicOperations(systemTemp); + systemTemp.setHydrateCheck(true); + systemTemp.setMixingRule(9); + try { + opsTemp.hydrateFormationTemperature(); + } catch (Exception e) { + logger.error("error", e); + } + systemTemp.display(); + return hydTemps; + } + + /** + *

+ * calcTOLHydrateFormationTemperature. + *

+ * + * @return a double + */ + public double calcTOLHydrateFormationTemperature() { + TPflash(); + + SystemInterface systemTemp = system.phaseToSystem(0); + ThermodynamicOperations opsTemp = new ThermodynamicOperations(systemTemp); + try { + opsTemp.hydrateFormationTemperature(); + } catch (Exception e) { + logger.error("error", e); + } + systemTemp.display(); + system.setTemperature(systemTemp.getTemperature()); + TPflash(); + return system.getTemperature(); + } + + /** + *

+ * hydrateInhibitorConcentration. + *

+ * + * @param inhibitorName a {@link java.lang.String} object + * @param hydEqTemperature a double + * @throws java.lang.Exception if any. + */ + public void hydrateInhibitorConcentration(String inhibitorName, double hydEqTemperature) + throws Exception { + operation = new HydrateInhibitorConcentrationFlash(system, inhibitorName, hydEqTemperature); + operation.run(); + } + + /** + *

+ * hydrateInhibitorConcentrationSet. + *

+ * + * @param inhibitorName a {@link java.lang.String} object + * @param wtfrac a double + * @throws java.lang.Exception if any. + */ + public void hydrateInhibitorConcentrationSet(String inhibitorName, double wtfrac) + throws Exception { + operation = new HydrateInhibitorwtFlash(system, inhibitorName, wtfrac); + operation.run(); + } + + /** + *

+ * hydrateFormationTemperature. + *

+ * + * @param initialTemperatureGuess a double + * @throws java.lang.Exception if any. + */ + public void hydrateFormationTemperature(double initialTemperatureGuess) throws Exception { + system.setTemperature(initialTemperatureGuess); + operation = new HydrateFormationTemperatureFlash(system); + for (int i = 0; i < system.getPhase(4).getNumberOfComponents(); i++) { + ((ComponentHydrate) system.getPhase(4).getComponent(i)).getHydrateStructure(); + } + if (!isRunAsThread()) { + getOperation().run(); + } else { + run(); + } + } + + /** + *

+ * hydrateFormationTemperature. + *

+ * + * @throws java.lang.Exception if any. + */ + public void hydrateFormationTemperature() throws Exception { + // guessing temperature + double factor = 1.0; + if (system.getPhase(0).hasComponent("methanol")) { + factor -= 2 * system.getPhase(0).getComponent("methanol").getz() + / system.getPhase(0).getComponent("water").getz(); + } + if (system.getPhase(0).hasComponent("MEG")) { + factor -= 2 * system.getPhase(0).getComponent("MEG").getz() + / system.getPhase(0).getComponent("water").getz(); + } + if (factor < 2) { + factor = 2; + } + + system.setTemperature(273.0 + system.getPressure() / 100.0 * 20.0 * factor - 20.0); + if (system.getTemperature() > 298.15) { + system.setTemperature(273.0 + 25.0); + } + // logger.info("guess hydrate temperature " + system.getTemperature()); + operation = new HydrateFormationTemperatureFlash(system); + + for (int i = 0; i < system.getPhase(4).getNumberOfComponents(); i++) { + ((ComponentHydrate) system.getPhase(4).getComponent(i)).getHydrateStructure(); + } + if (!isRunAsThread()) { + getOperation().run(); + } else { + run(); + } + // logger.info("Hydrate structure " + (((ComponentHydrate) + // system.getPhase(4).getComponent("water")).getHydrateStructure() + 1)); + } + + /** + *

+ * hydrateFormationTemperature. + *

+ * + * @param structure a int + * @throws java.lang.Exception if any. + */ + public void hydrateFormationTemperature(int structure) throws Exception { + system.setTemperature(273.0 + 1.0); + if (structure == 0) { + system.setSolidPhaseCheck("water"); + system.setHydrateCheck(true); + operation = new freezingPointTemperatureFlash(system); + } else { + operation = new HydrateFormationTemperatureFlash(system); + } + + for (int i = 0; i < system.getPhase(4).getNumberOfComponents(); i++) { + ((ComponentHydrate) system.getPhases()[4].getComponent(i)).setHydrateStructure(structure - 1); + } + if (!isRunAsThread()) { + getOperation().run(); + } else { + run(); + } + + if (Double.isNaN(system.getTemperature())) { + throw new neqsim.util.exception.IsNaNException(this.getClass().getSimpleName(), + "hydrateFormationTemperature", "Could not find solution - possible no dew point exists"); + } + } + + /** + *

+ * hydrateEquilibriumLine. + *

+ * + * @param minimumPressure a double + * @param maximumPressure a double + * @throws java.lang.Exception if any. + */ + public void hydrateEquilibriumLine(double minimumPressure, double maximumPressure) + throws Exception { + operation = new HydrateEquilibriumLine(system, minimumPressure, maximumPressure); + if (!isRunAsThread()) { + getOperation().run(); + } else { + run(); + } + } + + /** + *

+ * calcCricoP. + *

+ * + * @param cricondenBar an array of {@link double} objects + * @param cricondenBarX an array of {@link double} objects + * @param cricondenBarY an array of {@link double} objects + */ + public void calcCricoP(double[] cricondenBar, double[] cricondenBarX, double[] cricondenBarY) { + double phasefraction = 1.0 - 1e-10; + + operation = new CricondenBarFlash(system, fileName, phasefraction, cricondenBar, cricondenBarX, + cricondenBarY); + + getOperation().run(); + } + + /** + *

+ * calcCricoT. + *

+ * + * @param cricondenTherm an array of {@link double} objects + * @param cricondenThermX an array of {@link double} objects + * @param cricondenThermY an array of {@link double} objects + */ + public void calcCricoT(double[] cricondenTherm, double[] cricondenThermX, + double[] cricondenThermY) { + double phasefraction = 1.0 - 1e-10; + + operation = new CricondenThermFlash(system, fileName, phasefraction, cricondenTherm, + cricondenThermX, cricondenThermY); + + getOperation().run(); + } + + /** + *

+ * waterDewPointLine. + *

+ * + * @param minimumPressure a double + * @param maximumPressure a double + * @throws java.lang.Exception if any. + */ + public void waterDewPointLine(double minimumPressure, double maximumPressure) throws Exception { + operation = new WaterDewPointEquilibriumLine(system, minimumPressure, maximumPressure); + if (!isRunAsThread()) { + getOperation().run(); + } else { + run(); + } + } + + /** + *

+ * calcCricondenBar. + *

+ * + * @return a double + */ + public double calcCricondenBar() { + system.init(0); + operation = new cricondebarFlash(system); + // operation = new CricondenBarFlash(system); + + // operation = new cricondenBarTemp1(system); + operation.run(); + return system.getPressure(); + } + + /** + *

+ * bubblePointPressureFlash. + *

+ * + * @throws java.lang.Exception if any. + */ + public void bubblePointPressureFlash() throws Exception { + system.init(0); + constantDutyFlashInterface operation = new constantDutyPressureFlash(system); + system.setBeta(1, 1.0 - 1e-10); + system.setBeta(0, 1e-10); + operation.run(); + if (Double.isNaN(system.getPressure()) || operation.isSuperCritical()) { + throw new neqsim.util.exception.IsNaNException(this.getClass().getSimpleName(), + "bubblePointPressureFlash", "Could not find solution - possible no dew point exists"); + } + } + + /** + *

+ * bubblePointPressureFlash. + *

+ * + * @param derivatives a boolean + * @throws java.lang.Exception if any. + */ + public void bubblePointPressureFlash(boolean derivatives) throws Exception { + constantDutyFlashInterface operation = null; + if (derivatives == true) { + operation = new bubblePointPressureFlashDer(system); + } else { + operation = new bubblePointPressureFlash(system); + } + operation.run(); + if (Double.isNaN(system.getPressure()) || operation.isSuperCritical()) { + throw new neqsim.util.exception.IsNaNException(this.getClass().getSimpleName(), + "bubblePointPressureFlash", "Could not find solution - possible no dew point exists"); + } + } + + /** + *

+ * constantPhaseFractionPressureFlash. + *

+ * + * @param fraction a double + * @throws java.lang.Exception if any. + */ + public void constantPhaseFractionPressureFlash(double fraction) throws Exception { + system.init(0); + if (fraction < 1e-10) { + fraction = 1e-10; + } + if (fraction > 1.0 - 1e-10) { + fraction = 1.0 - 1.0e-10; + } + constantDutyFlashInterface operation = new constantDutyPressureFlash(system); + system.setBeta(1, 1.0 - fraction); + system.setBeta(0, fraction); + operation.run(); + if (Double.isNaN(system.getPressure()) || operation.isSuperCritical()) { + throw new neqsim.util.exception.IsNaNException(this.getClass().getSimpleName(), + "constantPhaseFractionPressureFlash", + "Could not find solution - possible no dew point exists"); + } + } + + /** + *

+ * constantPhaseFractionTemperatureFlash. + *

+ * + * @param fraction a double + * @throws java.lang.Exception if any. + */ + public void constantPhaseFractionTemperatureFlash(double fraction) throws Exception { + system.init(0); + if (fraction < 1e-10) { + fraction = 1e-10; + } + if (fraction > 1.0 - 1e-10) { + fraction = 1.0 - 1.0e-10; + } + constantDutyFlashInterface operation = new constantDutyTemperatureFlash(system); + system.setBeta(1, fraction); + system.setBeta(0, fraction); + operation.run(); + if (Double.isNaN(system.getPressure()) || operation.isSuperCritical()) { + throw new neqsim.util.exception.IsNaNException(this.getClass().getSimpleName(), + "constantPhaseFractionTemperatureFlash", + "Could not find solution - possible no dew point exists"); + } + } + + /** + *

+ * dewPointMach. + *

+ * + * @param componentName a {@link java.lang.String} object + * @param specification a {@link java.lang.String} object + * @param spec a double + * @throws java.lang.Exception if any. + */ + public void dewPointMach(String componentName, String specification, double spec) + throws Exception { + // int componentNumber = + // system.getPhase(0).getComponent(componentName).getComponentNumber(); + + double dn = 0; + if (system.getPhase(0).hasComponent(componentName)) { + dn = system.getNumberOfMoles() / 1.0e6; + system.addComponent(componentName, dn); + } else { + throw new neqsim.util.exception.IsNaNException(this.getClass().getSimpleName(), + "dewPointMach", "Specified component is not present in mixture: " + componentName); + } + double newTemperature = system.getTemperature(); + double oldTemperature = newTemperature; + int iterations = 0; + if (specification.equals("dewPointTemperature")) { + // logger.info("new temperature " + newTemperature); + do { + iterations++; system.init(0); - if (fraction < 1e-10) { - fraction = 1e-10; - } - if (fraction > 1.0 - 1e-10) { - fraction = 1.0 - 1.0e-10; - } - constantDutyFlashInterface operation = new constantDutyTemperatureFlash(system); - system.setBeta(1, fraction); - system.setBeta(0, fraction); - operation.run(); - if (Double.isNaN(system.getPressure()) || operation.isSuperCritical()) { - throw new neqsim.util.exception.IsNaNException(this.getClass().getSimpleName(), - "constantPhaseFractionTemperatureFlash", - "Could not find solution - possible no dew point exists"); - } - } - - /** - *

- * bubblePointPressureFlash. - *

- * - * @param derivatives a boolean - * @throws java.lang.Exception if any. - */ - public void bubblePointPressureFlash(boolean derivatives) throws Exception { - constantDutyFlashInterface operation = null; - if (derivatives == true) { - operation = new bubblePointPressureFlashDer(system); - } else { - operation = new bubblePointPressureFlash(system); - } - operation.run(); - if (Double.isNaN(system.getPressure()) || operation.isSuperCritical()) { - throw new neqsim.util.exception.IsNaNException(this.getClass().getSimpleName(), - "bubblePointPressureFlash", "Could not find solution - possible no dew point exists"); - } - } - - /** - *

- * dewPointMach. - *

- * - * @param componentName a {@link java.lang.String} object - * @param specification a {@link java.lang.String} object - * @param spec a double - * @throws java.lang.Exception if any. - */ - public void dewPointMach(String componentName, String specification, double spec) - throws Exception { - // int componentNumber = - // system.getPhase(0).getComponent(componentName).getComponentNumber(); - - double dn = 0; - if (system.getPhase(0).hasComponent(componentName)) { - dn = system.getNumberOfMoles() / 1.0e6; - system.addComponent(componentName, dn); + dewPointTemperatureFlash(); + newTemperature = system.getTemperature(); + // logger.info("new temperature " + newTemperature); + double oldMoles = system.getPhase(0).getComponent(componentName).getNumberOfmoles(); + if (iterations > 1) { + system.addComponent(componentName, -(iterations / (30.0 + iterations)) + * (newTemperature - spec) / ((newTemperature - oldTemperature) / dn)); } else { - throw new neqsim.util.exception.IsNaNException(this.getClass().getSimpleName(), - "dewPointMach", "Specified component is not present in mixture: " + componentName); - } - double newTemperature = system.getTemperature(), oldTemperature = newTemperature; - int iterations = 0; - if (specification.equals("dewPointTemperature")) { - // logger.info("new temperature " + newTemperature); - do { - iterations++; - system.init(0); - dewPointTemperatureFlash(); - newTemperature = system.getTemperature(); - // logger.info("new temperature " + newTemperature); - double oldMoles = system.getPhase(0).getComponent(componentName).getNumberOfmoles(); - if (iterations > 1) { - system.addComponent(componentName, -(iterations / (30.0 + iterations)) - * (newTemperature - spec) / ((newTemperature - oldTemperature) / dn)); - } else { - system.addComponent(componentName, system.getNumberOfMoles() / 1.0e6); - } - dn = system.getPhase(0).getComponent(componentName).getNumberOfmoles() - oldMoles; - oldTemperature = newTemperature; - } while (Math.abs( - dn / system.getPhase(0).getComponent(componentName).getNumberOfmoles()) > 1e-9 - || iterations < 5 || iterations > 105); - - dewPointTemperatureFlash(); - } - - if (Double.isNaN(system.getPressure())) { - throw new neqsim.util.exception.IsNaNException(this.getClass().getSimpleName(), - "dewPointMach", "Could not find solution - possible no dew point exists"); - } - } - - /** - *

- * dewPointTemperatureFlash. - *

- * - * @throws java.lang.Exception if any. - */ - public void dewPointTemperatureFlash() throws Exception { - constantDutyFlashInterface operation = new neqsim.thermodynamicOperations.flashOps.saturationOps.dewPointTemperatureFlash( - system); - operation.run(); - if (Double.isNaN(system.getTemperature()) || operation.isSuperCritical()) { - throw new neqsim.util.exception.IsNaNException(this.getClass().getSimpleName(), - "dewPointTemperatureFlash", "Could not find solution - possible no dew point exists"); - } - } - - /** - *

- * dewPointTemperatureFlash. - *

- * - * @param derivatives a boolean - * @throws java.lang.Exception if any. - */ - public void dewPointTemperatureFlash(boolean derivatives) throws Exception { - constantDutyFlashInterface operation = new neqsim.thermodynamicOperations.flashOps.saturationOps.dewPointTemperatureFlash( - system); - if (derivatives) { - operation = new dewPointTemperatureFlashDer(system); - } - operation.run(); - if (Double.isNaN(system.getTemperature()) || operation.isSuperCritical()) { - throw new neqsim.util.exception.IsNaNException(this.getClass().getSimpleName(), - "dewPointTemperatureFlash", "Could not find solution - possible no dew point exists"); - } + system.addComponent(componentName, system.getNumberOfMoles() / 1.0e6); + } + dn = system.getPhase(0).getComponent(componentName).getNumberOfmoles() - oldMoles; + oldTemperature = newTemperature; + } while (Math + .abs(dn / system.getPhase(0).getComponent(componentName).getNumberOfmoles()) > 1e-9 + || iterations < 5 || iterations > 105); + + dewPointTemperatureFlash(); + } + + if (Double.isNaN(system.getPressure())) { + throw new neqsim.util.exception.IsNaNException(this.getClass().getSimpleName(), + "dewPointMach", "Could not find solution - possible no dew point exists"); + } + } + + /** + *

+ * dewPointTemperatureFlash. + *

+ * + * @throws java.lang.Exception if any. + */ + public void dewPointTemperatureFlash() throws Exception { + constantDutyFlashInterface operation = + new neqsim.thermodynamicOperations.flashOps.saturationOps.dewPointTemperatureFlash(system); + operation.run(); + if (Double.isNaN(system.getTemperature()) || operation.isSuperCritical()) { + throw new neqsim.util.exception.IsNaNException(this.getClass().getSimpleName(), + "dewPointTemperatureFlash", "Could not find solution - possible no dew point exists"); + } + } + + /** + *

+ * dewPointTemperatureFlash. + *

+ * + * @param derivatives a boolean + * @throws java.lang.Exception if any. + */ + public void dewPointTemperatureFlash(boolean derivatives) throws Exception { + constantDutyFlashInterface operation = + new neqsim.thermodynamicOperations.flashOps.saturationOps.dewPointTemperatureFlash(system); + if (derivatives) { + operation = new dewPointTemperatureFlashDer(system); + } + operation.run(); + if (Double.isNaN(system.getTemperature()) || operation.isSuperCritical()) { + throw new neqsim.util.exception.IsNaNException(this.getClass().getSimpleName(), + "dewPointTemperatureFlash", "Could not find solution - possible no dew point exists"); + } + } + + /** + *

+ * dewPointPressureFlashHC. + *

+ * + * @throws java.lang.Exception if any. + */ + public void dewPointPressureFlashHC() throws Exception { + // try{ + system.init(0); + constantDutyFlashInterface operation = new HCdewPointPressureFlash(system); + operation.run(); + if (Double.isNaN(system.getPressure()) || operation.isSuperCritical()) { + throw new neqsim.util.exception.IsNaNException(this.getClass().getSimpleName(), + "dewPointPressureFlashHC", "Could not find solution - possible no dew point exists"); } - - /** - *

- * dewPointPressureFlashHC. - *

- * - * @throws java.lang.Exception if any. - */ - public void dewPointPressureFlashHC() throws Exception { - // try{ - system.init(0); - constantDutyFlashInterface operation = new HCdewPointPressureFlash(system); - operation.run(); - if (Double.isNaN(system.getPressure()) || operation.isSuperCritical()) { - throw new neqsim.util.exception.IsNaNException(this.getClass().getSimpleName(), - "dewPointPressureFlashHC", "Could not find solution - possible no dew point exists"); - } - // } - } - - /** - *

- * dewPointPressureFlash. - *

- * - * @throws java.lang.Exception if any. - */ - public void dewPointPressureFlash() throws Exception { - // try{ - system.init(0); - constantDutyFlashInterface operation = new dewPointPressureFlash(system); - operation.run(); - if (Double.isNaN(system.getPressure()) || operation.isSuperCritical()) { - throw new neqsim.util.exception.IsNaNException(this.getClass().getSimpleName(), - "dewPointPressureFlash", "Could not find solution - possible no dew point exists"); - } - // } - } - - // public void dewPointPressureFlash(){ - // constantDutyFlashInterface operation = new constantDutyPressureFlash(system); - // operation.setBeta((1-1e-7)); - // operation.run(); // } - /** - *

- * calcPTphaseEnvelope. - *

- */ - public void calcPTphaseEnvelope() { - operation = new pTphaseEnvelope(system, fileName, (1.0 - 1e-10), 1.0, false); - // thisThread = new Thread(operation); - // thisThread.start(); - getOperation().run(); - } - - /** - *

- * calcPTphaseEnvelope. - *

- * - * @param bubfirst a boolean - * @param lowPres a double - */ - public void calcPTphaseEnvelope(boolean bubfirst, double lowPres) { - double phasefraction = 1.0 - 1e-10; - if (bubfirst) { - phasefraction = 1.0e-10; - } - operation = new pTphaseEnvelope(system, fileName, phasefraction, lowPres, bubfirst); - - // thisThread = new Thread(operation); - // thisThread.start(); - getOperation().run(); - } - - /** - *

- * calcPTphaseEnvelope. - *

- * - * @param lowPres a double - */ - public void calcPTphaseEnvelope(double lowPres) { - operation = new pTphaseEnvelope(system, fileName, 1e-10, lowPres, true); - // thisThread = new Thread(operation); - // thisThread.start(); - getOperation().run(); - } - - /** - *

- * calcPTphaseEnvelope. - *

- * - * @param bubfirst a boolean - */ - public void calcPTphaseEnvelope(boolean bubfirst) { - double phasefraction = 1.0 - 1e-10; - if (bubfirst) { - phasefraction = 1.0e-10; - } - operation = new pTphaseEnvelope(system, fileName, phasefraction, 1.0, bubfirst); - - // thisThread = new Thread(operation); - // thisThread.start(); - if (!isRunAsThread()) { - getOperation().run(); - } else { - run(); - } + } + + /** + *

+ * dewPointPressureFlash. + *

+ * + * @throws java.lang.Exception if any. + */ + public void dewPointPressureFlash() throws Exception { + // try{ + system.init(0); + constantDutyFlashInterface operation = new dewPointPressureFlash(system); + operation.run(); + if (Double.isNaN(system.getPressure()) || operation.isSuperCritical()) { + throw new neqsim.util.exception.IsNaNException(this.getClass().getSimpleName(), + "dewPointPressureFlash", "Could not find solution - possible no dew point exists"); } - - /** - *

- * getJfreeChart. - *

- * - * @return a {@link org.jfree.chart.JFreeChart} object - */ - public org.jfree.chart.JFreeChart getJfreeChart() { - return getOperation().getJFreeChart(""); - } - - /** - *

- * calcPTphaseEnvelopeNew. - *

- */ - public void calcPTphaseEnvelopeNew() { - // double phasefraction = 1.0 - 1e-10; - // operation = new pTphaseEnvelope(system, fileName, phasefraction, 1.0); - getOperation().run(); - } - - /** - *

- * calcPTphaseEnvelope. - *

- * - * @param lowPres a double - * @param phasefraction a double - */ - public void calcPTphaseEnvelope(double lowPres, double phasefraction) { - operation = new pTphaseEnvelope(system, fileName, phasefraction, lowPres, true); - - // thisThread = new Thread(operation); - // thisThread.start(); - getOperation().run(); - } - - /** - *

- * OLGApropTable. - *

- * - * @param minTemp a double - * @param maxTemp a double - * @param temperatureSteps a int - * @param minPres a double - * @param maxPres a double - * @param pressureSteps a int - * @param filename a {@link java.lang.String} object - * @param TABtype a int - */ - public void OLGApropTable(double minTemp, double maxTemp, int temperatureSteps, double minPres, - double maxPres, int pressureSteps, String filename, int TABtype) { - operation = new OLGApropertyTableGeneratorWaterStudents(system); - ((OLGApropertyTableGeneratorWaterStudents) operation).setFileName(filename); - ((OLGApropertyTableGeneratorWaterStudents) operation).setPressureRange(minPres, maxPres, - pressureSteps); - ((OLGApropertyTableGeneratorWaterStudents) operation).setTemperatureRange(minTemp, maxTemp, - temperatureSteps); - getOperation().run(); - } - - /** - *

- * OLGApropTablePH. - *

- * - * @param minEnthalpy a double - * @param maxEnthalpy a double - * @param enthalpySteps a int - * @param minPres a double - * @param maxPres a double - * @param pressureSteps a int - * @param filename a {@link java.lang.String} object - * @param TABtype a int - */ - public void OLGApropTablePH(double minEnthalpy, double maxEnthalpy, int enthalpySteps, - double minPres, double maxPres, int pressureSteps, String filename, int TABtype) { - operation = new OLGApropertyTableGeneratorWaterStudentsPH(system); - ((OLGApropertyTableGeneratorWaterStudentsPH) operation).setFileName(filename); - ((OLGApropertyTableGeneratorWaterStudentsPH) operation).setPressureRange(minPres, maxPres, - pressureSteps); - ((OLGApropertyTableGeneratorWaterStudentsPH) operation).setEnthalpyRange(minEnthalpy, - maxEnthalpy, enthalpySteps); - getOperation().run(); - } - - /** - *

- * calcPloadingCurve. - *

- */ - public void calcPloadingCurve() { - operation = new pLoadingCurve2(system); - // thisThread = new Thread(operation); - // thisThread.start(); - getOperation().run(); - } - - /** - *

- * calcHPTphaseEnvelope. - *

- */ - public void calcHPTphaseEnvelope() { - operation = new HPTphaseEnvelope(system); - // thisThread = new Thread(getOperation()); - // thisThread.start(); - operation.run(); - } - - /** - *

- * printToFile. - *

- * - * @param name a {@link java.lang.String} object - */ - public void printToFile(String name) { - getOperation().printToFile(name); - } - - // public double[] get(String name){ - // return operation.get(name); // } - /** - *

- * getData. - *

- * - * @return an array of {@link double} objects - */ - public double[][] getData() { - return getOperation().getPoints(0); - } - - /** - *

- * getDataPoints. - *

- * - * @return an array of {@link java.lang.String} objects - */ - public String[][] getDataPoints() { - String[][] str = new String[getOperation() - .getPoints(0).length][getOperation().getPoints(0)[0].length]; - for (int i = 0; i < getOperation().getPoints(0).length; i++) { - for (int j = 0; j < getOperation().getPoints(0)[0].length; j++) { - str[i][j] = Double.toString(getOperation().getPoints(0)[i][j]); - } - } - return str; - } - - /** - *

- * Getter for the field resultTable. - *

- * - * @return an array of {@link java.lang.String} objects - */ - public String[][] getResultTable() { - return resultTable; - } - - /** - *

- * dewPointTemperatureCondensationRate. - *

- * - * @return a double - */ - public double dewPointTemperatureCondensationRate() { - double dT = 1.1; - try { - dewPointTemperatureFlash(); - } catch (Exception e) { - logger.error("error", e); + } + + /** + *

+ * getJfreeChart. + *

+ * + * @return a {@link org.jfree.chart.JFreeChart} object + */ + public org.jfree.chart.JFreeChart getJfreeChart() { + return getOperation().getJFreeChart(""); + } + + // public void dewPointPressureFlash(){ + // constantDutyFlashInterface operation = new constantDutyPressureFlash(system); + // operation.setBeta((1-1e-7)); + // operation.run(); + // } + /** + *

+ * calcPTphaseEnvelope. + *

+ */ + public void calcPTphaseEnvelope() { + operation = new pTphaseEnvelope(system, fileName, (1.0 - 1e-10), 1.0, false); + // thisThread = new Thread(operation); + // thisThread.start(); + getOperation().run(); + } + + /** + *

+ * calcPTphaseEnvelope. + *

+ * + * @param bubfirst a boolean + * @param lowPres a double + */ + public void calcPTphaseEnvelope(boolean bubfirst, double lowPres) { + double phasefraction = 1.0 - 1e-10; + if (bubfirst) { + phasefraction = 1.0e-10; + } + operation = new pTphaseEnvelope(system, fileName, phasefraction, lowPres, bubfirst); + + // thisThread = new Thread(operation); + // thisThread.start(); + getOperation().run(); + } + + /** + *

+ * calcPTphaseEnvelope. + *

+ * + * @param lowPres a double + */ + public void calcPTphaseEnvelope(double lowPres) { + operation = new pTphaseEnvelope(system, fileName, 1e-10, lowPres, true); + // thisThread = new Thread(operation); + // thisThread.start(); + getOperation().run(); + } + + /** + *

+ * calcPTphaseEnvelope. + *

+ * + * @param bubfirst a boolean + */ + public void calcPTphaseEnvelope(boolean bubfirst) { + double phasefraction = 1.0 - 1e-10; + if (bubfirst) { + phasefraction = 1.0e-10; + } + operation = new pTphaseEnvelope(system, fileName, phasefraction, 1.0, bubfirst); + + // thisThread = new Thread(operation); + // thisThread.start(); + if (!isRunAsThread()) { + getOperation().run(); + } else { + run(); + } + } + + /** + *

+ * calcPTphaseEnvelope. + *

+ * + * @param lowPres a double + * @param phasefraction a double + */ + public void calcPTphaseEnvelope(double lowPres, double phasefraction) { + operation = new pTphaseEnvelope(system, fileName, phasefraction, lowPres, true); + + // thisThread = new Thread(operation); + // thisThread.start(); + getOperation().run(); + } + + /** + *

+ * calcPTphaseEnvelopeNew. + *

+ */ + public void calcPTphaseEnvelopeNew() { + // double phasefraction = 1.0 - 1e-10; + // operation = new pTphaseEnvelope(system, fileName, phasefraction, 1.0); + getOperation().run(); + } + + /** + *

+ * OLGApropTable. + *

+ * + * @param minTemp a double + * @param maxTemp a double + * @param temperatureSteps a int + * @param minPres a double + * @param maxPres a double + * @param pressureSteps a int + * @param filename a {@link java.lang.String} object + * @param TABtype a int + */ + public void OLGApropTable(double minTemp, double maxTemp, int temperatureSteps, double minPres, + double maxPres, int pressureSteps, String filename, int TABtype) { + operation = new OLGApropertyTableGeneratorWaterStudents(system); + ((OLGApropertyTableGeneratorWaterStudents) operation).setFileName(filename); + ((OLGApropertyTableGeneratorWaterStudents) operation).setPressureRange(minPres, maxPres, + pressureSteps); + ((OLGApropertyTableGeneratorWaterStudents) operation).setTemperatureRange(minTemp, maxTemp, + temperatureSteps); + getOperation().run(); + } + + /** + *

+ * OLGApropTablePH. + *

+ * + * @param minEnthalpy a double + * @param maxEnthalpy a double + * @param enthalpySteps a int + * @param minPres a double + * @param maxPres a double + * @param pressureSteps a int + * @param filename a {@link java.lang.String} object + * @param TABtype a int + */ + public void OLGApropTablePH(double minEnthalpy, double maxEnthalpy, int enthalpySteps, + double minPres, double maxPres, int pressureSteps, String filename, int TABtype) { + operation = new OLGApropertyTableGeneratorWaterStudentsPH(system); + ((OLGApropertyTableGeneratorWaterStudentsPH) operation).setFileName(filename); + ((OLGApropertyTableGeneratorWaterStudentsPH) operation).setPressureRange(minPres, maxPres, + pressureSteps); + ((OLGApropertyTableGeneratorWaterStudentsPH) operation).setEnthalpyRange(minEnthalpy, + maxEnthalpy, enthalpySteps); + getOperation().run(); + } + + /** + *

+ * calcPloadingCurve. + *

+ */ + public void calcPloadingCurve() { + operation = new pLoadingCurve2(system); + // thisThread = new Thread(operation); + // thisThread.start(); + getOperation().run(); + } + + /** + *

+ * calcHPTphaseEnvelope. + *

+ */ + public void calcHPTphaseEnvelope() { + operation = new HPTphaseEnvelope(system); + // thisThread = new Thread(getOperation()); + // thisThread.start(); + operation.run(); + } + + /** + *

+ * printToFile. + *

+ * + * @param name a {@link java.lang.String} object + */ + public void printToFile(String name) { + getOperation().printToFile(name); + } + + // public double[] get(String name){ + // return operation.get(name); + // } + /** + *

+ * getData. + *

+ * + * @return an array of {@link double} objects + */ + public double[][] getData() { + return getOperation().getPoints(0); + } + + /** + *

+ * getDataPoints. + *

+ * + * @return an array of {@link java.lang.String} objects + */ + public String[][] getDataPoints() { + String[][] str = + new String[getOperation().getPoints(0).length][getOperation().getPoints(0)[0].length]; + for (int i = 0; i < getOperation().getPoints(0).length; i++) { + for (int j = 0; j < getOperation().getPoints(0)[0].length; j++) { + str[i][j] = Double.toString(getOperation().getPoints(0)[i][j]); + } + } + return str; + } + + /** + *

+ * Getter for the field resultTable. + *

+ * + * @return an array of {@link java.lang.String} objects + */ + public String[][] getResultTable() { + return resultTable; + } + + /** + *

+ * dewPointTemperatureCondensationRate. + *

+ * + * @return a double + */ + public double dewPointTemperatureCondensationRate() { + double dT = 1.1; + try { + dewPointTemperatureFlash(); + } catch (Exception e) { + logger.error("error", e); + } + system.setTemperature(system.getTemperature() - dT); + TPflash(); + double condensationRate = system.getPhase(1).getMass() / (system.getVolume() * 1.0e-5); + try { + dewPointTemperatureFlash(); + } catch (Exception e) { + logger.error("error", e); + } + return condensationRate / dT; + } + + /** + *

+ * displayResult. + *

+ */ + public void displayResult() { + try { + getThermoOperationThread().join(); + } catch (Exception e) { + logger.error("Thread did not finish"); + } + getOperation().displayResult(); + } + + /** + *

+ * Setter for the field resultTable. + *

+ * + * @param resultTable an array of {@link java.lang.String} objects + */ + public void setResultTable(String[][] resultTable) { + this.resultTable = resultTable; + } + + /** + *

+ * display. + *

+ */ + public void display() { + JFrame dialog = new JFrame("System-Report"); + Container dialogContentPane = dialog.getContentPane(); + dialogContentPane.setLayout(new BorderLayout()); + + String[] names = new String[resultTable[0].length];// {"", "", ""}; + for (int i = 0; i < names.length; i++) { + names[i] = ""; + } + JTable Jtab = new JTable(resultTable, names); + JScrollPane scrollpane = new JScrollPane(Jtab); + dialogContentPane.add(scrollpane); + dialog.pack(); + dialog.setVisible(true); + } + + /** + *

+ * get. + *

+ * + * @param name a {@link java.lang.String} object + * @return an array of {@link double} objects + */ + public double[] get(String name) { + return getOperation().get(name); + } + + /** + *

+ * Getter for the field operation. + *

+ * + * @return the operation + */ + public OperationInterface getOperation() { + return operation; + } + + /** + *

+ * isRunAsThread. + *

+ * + * @return the runAsThread + */ + public boolean isRunAsThread() { + return runAsThread; + } + + /** + *

+ * Setter for the field runAsThread. + *

+ * + * @param runAsThread the runAsThread to set + */ + public void setRunAsThread(boolean runAsThread) { + this.runAsThread = runAsThread; + } + + /** + *

+ * Getter for the field thermoOperationThread. + *

+ * + * @return the thermoOperationThread + */ + public Thread getThermoOperationThread() { + return thermoOperationThread; + } + + /** + *

+ * Setter for the field thermoOperationThread. + *

+ * + * @param thermoOperationThread the thermoOperationThread to set + */ + public void setThermoOperationThread(Thread thermoOperationThread) { + this.thermoOperationThread = thermoOperationThread; + } + + /** + *

+ * addData. + *

+ * + * @param name a {@link java.lang.String} object + * @param data an array of {@link double} objects + */ + public void addData(String name, double[][] data) { + operation.addData(name, data); + } + + /** + *

+ * calcIonComposition. + *

+ * + * @param phaseNumber a int + */ + public void calcIonComposition(int phaseNumber) { + operation = new calcIonicComposition(system, phaseNumber); + getOperation().run(); + resultTable = getOperation().getResultTable(); + } + + /** + *

+ * flash. + *

+ * + * @param flashType a {@link java.lang.String} object + * @param spec1 a double + * @param spec2 a double + * @param unitSpec1 a {@link java.lang.String} object + * @param unitSpec2 a {@link java.lang.String} object + */ + public void flash(String flashType, double spec1, double spec2, String unitSpec1, + String unitSpec2) { + if (flashType.equals("TP")) { + system.setTemperature(spec1, unitSpec1); + system.setPressure(spec2, unitSpec2); + } else if (flashType.equals("TV")) { + system.setTemperature(spec1, unitSpec1); + TVflash(spec2, unitSpec2); + } else if (flashType.equals("PH")) { + system.setPressure(spec1, unitSpec1); + PHflash(spec2, unitSpec2); + } else if (flashType.equals("TS")) { + system.setTemperature(spec1, unitSpec1); + TSflash(spec2, unitSpec2); + } + } + + /** + * Perform flashes and return System properties per set of Spec1 and Spec2. + * + * Possible to specify fractions for each value of Spec1. + * + * + * @param Spec1 Flash pressure in bar absolute. + * @param Spec2 Flash specification. Depends on FlashMode. Temperature in Kelvin, entalphy in + * J/mol or entropy in J/molK. + * @param FlashMode 1 - PT 2 - PH 3 - PS + * @param components Not yet in use. + * @param onlineFractions Specify fractions per sample instance or null to use static composition + * specified in system. + * @return Object CalculationResult object + */ + public CalculationResult propertyFlash(List Spec1, List Spec2, int FlashMode, + List components, List> onlineFractions) { + + Double[][] fluidProperties = new Double[Spec1.size()][SystemProperties.nCols]; + String[] calculationError = new String[Spec1.size()]; + + Double[] sum = new Double[Spec1.size()]; + + if (onlineFractions != null) { + for (int t = 0; t < sum.length; t++) { + sum[t] = 0.0; + for (int comp = 0; comp < onlineFractions.size(); comp++) { + sum[t] = sum[t] + onlineFractions.get(comp).get(t).doubleValue(); + } + } + + if (this.system.getNumberOfMoles() == 0) { + this.system.setTotalNumberOfMoles(1); + } + } else { + double[] fraction = this.system.getMolarComposition(); + sum[0] = 0.0; + for (int comp = 0; comp < fraction.length; comp++) { + sum[0] = sum[0] + fraction[comp]; + } + } + + for (int t = 0; t < Spec1.size(); t++) { + try { + Double Sp1 = Spec1.get(t); + Double Sp2 = Spec2.get(t); + + if (Sp1 == null || Sp2 == null || Double.isNaN(Sp1) || Double.isNaN(Sp2)) { + calculationError[t] = "Sp1 or Sp2 is NaN"; + logger.info("Sp1 or Sp2 is NULL for datapoint {}", t); + continue; } - system.setTemperature(system.getTemperature() - dT); - TPflash(); - double condensationRate = system.getPhase(1).getMass() / (system.getVolume() * 1.0e-5); - try { - dewPointTemperatureFlash(); - } catch (Exception e) { - logger.error("error", e); - } - return condensationRate / dT; - } - - /** - *

- * displayResult. - *

- */ - public void displayResult() { - try { - getThermoOperationThread().join(); - } catch (Exception e) { - logger.error("Thread did not finish"); - } - getOperation().displayResult(); - } - - /** - *

- * writeNetCDF. - *

- * - * @param name a {@link java.lang.String} object - */ - public void writeNetCDF(String name) { - fileName = name; - getOperation().createNetCdfFile(name); - } - - /** - *

- * Setter for the field resultTable. - *

- * - * @param resultTable an array of {@link java.lang.String} objects - */ - public void setResultTable(String[][] resultTable) { - this.resultTable = resultTable; - } - - /** - *

- * display. - *

- */ - public void display() { - JFrame dialog = new JFrame("System-Report"); - Container dialogContentPane = dialog.getContentPane(); - dialogContentPane.setLayout(new BorderLayout()); - - String[] names = new String[resultTable[0].length];// {"", "", ""}; - for (int i = 0; i < names.length; i++) { - names[i] = ""; - } - JTable Jtab = new JTable(resultTable, names); - JScrollPane scrollpane = new JScrollPane(Jtab); - dialogContentPane.add(scrollpane); - dialog.pack(); - dialog.setVisible(true); - } - - /** - *

- * get. - *

- * - * @param name a {@link java.lang.String} object - * @return an array of {@link double} objects - */ - public double[] get(String name) { - return getOperation().get(name); - } - - /** - *

- * Getter for the field operation. - *

- * - * @return the operation - */ - public OperationInterface getOperation() { - return operation; - } - - /** - *

- * isRunAsThread. - *

- * - * @return the runAsThread - */ - public boolean isRunAsThread() { - return runAsThread; - } - - /** - *

- * Setter for the field runAsThread. - *

- * - * @param runAsThread the runAsThread to set - */ - public void setRunAsThread(boolean runAsThread) { - this.runAsThread = runAsThread; - } - - /** - *

- * Getter for the field thermoOperationThread. - *

- * - * @return the thermoOperationThread - */ - public Thread getThermoOperationThread() { - return thermoOperationThread; - } - - /** - *

- * Setter for the field thermoOperationThread. - *

- * - * @param thermoOperationThread the thermoOperationThread to set - */ - public void setThermoOperationThread(Thread thermoOperationThread) { - this.thermoOperationThread = thermoOperationThread; - } - - /** - *

- * addData. - *

- * - * @param name a {@link java.lang.String} object - * @param data an array of {@link double} objects - */ - public void addData(String name, double[][] data) { - operation.addData(name, data); - } - - /** - *

- * calcIonComposition. - *

- * - * @param phaseNumber a int - */ - public void calcIonComposition(int phaseNumber) { - operation = new calcIonicComposition(system, phaseNumber); - getOperation().run(); - resultTable = getOperation().getResultTable(); - } - - /** - *

- * flash. - *

- * - * @param flashType a {@link java.lang.String} object - * @param spec1 a double - * @param spec2 a double - * @param unitSpec1 a {@link java.lang.String} object - * @param unitSpec2 a {@link java.lang.String} object - */ - public void flash(String flashType, double spec1, double spec2, String unitSpec1, - String unitSpec2) { - if (flashType.equals("TP")) { - system.setTemperature(spec1, unitSpec1); - system.setPressure(spec2, unitSpec2); - } else if (flashType.equals("TV")) { - system.setTemperature(spec1, unitSpec1); - TVflash(spec2, unitSpec2); - } else if (flashType.equals("PH")) { - system.setPressure(spec1, unitSpec1); - PHflash(spec2, unitSpec2); - } else if (flashType.equals("TS")) { - system.setTemperature(spec1, unitSpec1); - TSflash(spec2, unitSpec2); - } - } - - /** - * Perform flashes and return System properties per set of Spec1 and Spec2. - * - * Possible to specify fractions for each value of Spec1. - * - * - * @param Spec1 Flash pressure in bar absolute. - * @param Spec2 Flash specification. Depends on FlashMode. Temperature in Kelvin, entalphy in - * J/mol or entropy in J/molK. - * @param FlashMode 1 - PT 2 - PH 3 - PS - * @param components Not yet in use. - * @param onlineFractions Specify fractions per sample instance or null to use static - * composition specified in system. - * @return - */ - public CalculationResult propertyFlash(List Spec1, List Spec2, int FlashMode, - List components, List> onlineFractions) { - - Double[][] fluidProperties = new Double[Spec1.size()][SystemProperties.nCols]; - String[] calculationError = new String[Spec1.size()]; - - Double[] sum = new Double[Spec1.size()]; if (onlineFractions != null) { - for (int t = 0; t < sum.length; t++) { - sum[t] = 0.0; - for (int comp = 0; comp < onlineFractions.size(); comp++) { - sum[t] = sum[t] + onlineFractions.get(comp).get(t).doubleValue(); - } - } - - if (this.system.getNumberOfMoles() == 0) { - this.system.setTotalNumberOfMoles(1); - } - } - else { - double[] fraction = this.system.getMolarComposition(); - sum[0] = 0.0; - for (int comp = 0; comp < fraction.length; comp++) { - sum[0] = sum[0] + fraction[comp]; + double range = 5; + if (!((sum[t] >= 1 - range / 100 && sum[t] <= 1 + range / 100) + || (sum[t] >= 100 - range && sum[t] <= 100 + range))) { + calculationError[t] = "Sum of fractions must be approximately 1 or 100, currently (" + + String.valueOf(sum[t]) + ")"; + logger.info("Online fraction does not sum to approximately 1 or 100 for datapoint {}", + t); + continue; + } else { + // Remaining fractions will be set to 0.0 + double[] fraction = new double[this.system.getNumberOfComponents()]; + + for (int comp = 0; comp < onlineFractions.size(); comp++) { + fraction[comp] = onlineFractions.get(comp).get(t).doubleValue(); } - } - for (int t = 0; t < Spec1.size(); t++) { - try { - Double Sp1 = Spec1.get(t); - Double Sp2 = Spec2.get(t); - - if (Sp1 == null || Sp2 == null || Double.isNaN(Sp1) || Double.isNaN(Sp2)) { - calculationError[t] = "Sp1 or Sp2 is NaN"; - logger.info("Sp1 or Sp2 is NULL for datapoint {}", t); - continue; - } - - if (onlineFractions != null) { - double range = 5; - if (!((sum[t] >= 1 - range / 100 && sum[t] <= 1 + range / 100) - || (sum[t] >= 100 - range && sum[t] <= 100 + range))) { - calculationError[t] = - "Sum of fractions must be approximately 1 or 100, currently (" - + String.valueOf(sum[t]) + ")"; - logger.info("Online fraction does not sum to approximately 1 or 100 for datapoint {}", t); - continue; - } else { - // Remaining fractions will be set to 0.0 - double[] fraction = new double[this.system.getNumberOfComponents()]; - - for (int comp = 0; comp < onlineFractions.size(); comp++) { - fraction[comp] = onlineFractions.get(comp).get(t).doubleValue(); - } - - this.system.setMolarComposition(fraction); - this.system.init(0); - } - } - else { - double range = 1e-8; - if (!((sum[0] >= 1 - range && sum[0] <= 1 + range) - || (sum[0] >= 100 - range && sum[0] <= 100 + range))) { - calculationError[t] = - "Sum of fractions must be equal to 1 or 100, currently (" - + String.valueOf(sum[t]) + ")"; - logger.info("Sum of fractions must be equal to 1 or 100 for datapoint {}", t); - continue; - } - } - - this.system.setPressure(Sp1); - if (FlashMode == 1) { - this.system.setTemperature(Sp2); - this.TPflash(); - } else if (FlashMode == 2) { - this.PHflash(Sp2, "J/mol"); - } else if (FlashMode == 3) { - this.PSflash(Sp2, "J/molK"); - } else { - throw new RuntimeException(new neqsim.util.exception.InvalidInputException( - "ThermodynamicOperations", "propertyFlash", "mode", "must be 1, 2 or 3")); - } - this.system.init(2); - this.system.initPhysicalProperties(); - - fluidProperties[t] = this.system.getProperties().getValues(); - } catch (Exception ex) { - calculationError[t] = ex.getMessage(); - logger.error(ex.getMessage()); - } + this.system.setMolarComposition(fraction); + this.system.init(0); + } + } else { + double range = 1e-8; + if (!((sum[0] >= 1 - range && sum[0] <= 1 + range) + || (sum[0] >= 100 - range && sum[0] <= 100 + range))) { + calculationError[t] = "Sum of fractions must be equal to 1 or 100, currently (" + + String.valueOf(sum[t]) + ")"; + logger.info("Sum of fractions must be equal to 1 or 100 for datapoint {}", t); + continue; + } + } + + this.system.setPressure(Sp1); + if (FlashMode == 1) { + this.system.setTemperature(Sp2); + this.TPflash(); + } else if (FlashMode == 2) { + this.PHflash(Sp2, "J/mol"); + } else if (FlashMode == 3) { + this.PSflash(Sp2, "J/molK"); + } else { + throw new RuntimeException(new neqsim.util.exception.InvalidInputException( + "ThermodynamicOperations", "propertyFlash", "mode", "must be 1, 2 or 3")); } + this.system.init(2); + this.system.initPhysicalProperties(); - return new CalculationResult(fluidProperties, calculationError); + fluidProperties[t] = this.system.getProperties().getValues(); + } catch (Exception ex) { + calculationError[t] = ex.getMessage(); + logger.error(ex.getMessage()); + } } + + return new CalculationResult(fluidProperties, calculationError); + } } diff --git a/src/main/java/neqsim/thermodynamicOperations/chemicalEquilibrium/ChemicalEquilibrium.java b/src/main/java/neqsim/thermodynamicOperations/chemicalEquilibrium/ChemicalEquilibrium.java index 77e9e65dd5..52aee0baf9 100644 --- a/src/main/java/neqsim/thermodynamicOperations/chemicalEquilibrium/ChemicalEquilibrium.java +++ b/src/main/java/neqsim/thermodynamicOperations/chemicalEquilibrium/ChemicalEquilibrium.java @@ -19,89 +19,84 @@ * @version $Id: $Id */ public class ChemicalEquilibrium extends BaseOperation { - private static final long serialVersionUID = 1000; - static Logger logger = LogManager.getLogger(ChemicalEquilibrium.class); + private static final long serialVersionUID = 1000; + static Logger logger = LogManager.getLogger(ChemicalEquilibrium.class); - SystemInterface system; + SystemInterface system; - public ChemicalEquilibrium() {} + public ChemicalEquilibrium() {} - /** - *

- * Constructor for ChemicalEquilibrium. - *

- * - * @param system a {@link neqsim.thermo.system.SystemInterface} object - */ - public ChemicalEquilibrium(SystemInterface system) { - this.system = system; - } + /** + *

+ * Constructor for ChemicalEquilibrium. + *

+ * + * @param system a {@link neqsim.thermo.system.SystemInterface} object + */ + public ChemicalEquilibrium(SystemInterface system) { + this.system = system; + } - /** {@inheritDoc} */ - @Override - public void run() { - double chemdev = 0; - int iter = 1; - if (system.isChemicalSystem()) { - double oldHeat = system.getChemicalReactionOperations().getReactionList() - .reacHeat(system.getPhase(1), "HCO3-"); - do { - iter++; - for (int phase = 1; phase < system.getNumberOfPhases(); phase++) { - chemdev = 0.0; - double xchem[] = new double[system.getPhases()[phase].getNumberOfComponents()]; + /** {@inheritDoc} */ + @Override + public void run() { + double chemdev = 0; + int iter = 1; + if (system.isChemicalSystem()) { + double oldHeat = system.getChemicalReactionOperations().getReactionList() + .reacHeat(system.getPhase(1), "HCO3-"); + do { + iter++; + for (int phase = 1; phase < system.getNumberOfPhases(); phase++) { + chemdev = 0.0; + double xchem[] = new double[system.getPhases()[phase].getNumberOfComponents()]; - for (int i = 0; i < system.getPhases()[phase].getNumberOfComponents(); i++) { - xchem[i] = system.getPhases()[phase].getComponents()[i].getx(); - } + for (int i = 0; i < system.getPhases()[phase].getNumberOfComponents(); i++) { + xchem[i] = system.getPhases()[phase].getComponents()[i].getx(); + } - system.init(1); - system.getChemicalReactionOperations().solveChemEq(phase); + system.init(1); + system.getChemicalReactionOperations().solveChemEq(phase); - for (int i = 0; i < system.getPhases()[phase].getNumberOfComponents(); i++) { - chemdev += Math.abs( - xchem[i] - system.getPhases()[phase].getComponents()[i].getx()); - } - } - } while (Math.abs(chemdev) > 1e-4 && iter < 100); - double newHeat = system.getChemicalReactionOperations().getReactionList() - .reacHeat(system.getPhase(1), "HCO3-"); - system.getChemicalReactionOperations().setDeltaReactionHeat(newHeat - oldHeat); - } - if (iter > 50) { - logger.info("iter : " + iter + " in chemicalequilibrium"); + for (int i = 0; i < system.getPhases()[phase].getNumberOfComponents(); i++) { + chemdev += Math.abs(xchem[i] - system.getPhases()[phase].getComponents()[i].getx()); + } } + } while (Math.abs(chemdev) > 1e-4 && iter < 100); + double newHeat = system.getChemicalReactionOperations().getReactionList() + .reacHeat(system.getPhase(1), "HCO3-"); + system.getChemicalReactionOperations().setDeltaReactionHeat(newHeat - oldHeat); } - - /** {@inheritDoc} */ - @Override - public void displayResult() { - system.display(); + if (iter > 50) { + logger.info("iter : " + iter + " in chemicalequilibrium"); } + } - /** {@inheritDoc} */ - @Override - public void printToFile(String name) {} + /** {@inheritDoc} */ + @Override + public void displayResult() { + system.display(); + } - /** {@inheritDoc} */ - @Override - public void createNetCdfFile(String name) {} + /** {@inheritDoc} */ + @Override + public void printToFile(String name) {} - /** {@inheritDoc} */ - @Override - public double[][] getPoints(int i) { - return null; - } + /** {@inheritDoc} */ + @Override + public double[][] getPoints(int i) { + return null; + } - /** {@inheritDoc} */ - @Override - public org.jfree.chart.JFreeChart getJFreeChart(String name) { - return null; - } + /** {@inheritDoc} */ + @Override + public org.jfree.chart.JFreeChart getJFreeChart(String name) { + return null; + } - /** {@inheritDoc} */ - @Override - public String[][] getResultTable() { - return null; - } + /** {@inheritDoc} */ + @Override + public String[][] getResultTable() { + return null; + } } diff --git a/src/main/java/neqsim/thermodynamicOperations/flashOps/Flash.java b/src/main/java/neqsim/thermodynamicOperations/flashOps/Flash.java index 4d9fab4c6b..ec5b05aad1 100644 --- a/src/main/java/neqsim/thermodynamicOperations/flashOps/Flash.java +++ b/src/main/java/neqsim/thermodynamicOperations/flashOps/Flash.java @@ -15,463 +15,453 @@ * @author Even Solbraa */ abstract class Flash extends BaseOperation { - private static final long serialVersionUID = 1000; - static Logger logger = LogManager.getLogger(Flash.class); - - SystemInterface system; - SystemInterface minimumGibbsEnergySystem; - - public double[] minGibsPhaseLogZ; - public double[] minGibsLogFugCoef; - int i = 0, j = 0, iterations = 0, maxNumberOfIterations = 100; - double gibbsEnergy = 0, gibbsEnergyOld = 0; - double Kold = 0, deviation = 0, g0 = 0, g1 = 0; - double lnOldOldOldK[], lnOldOldK[], lnK[], lnOldK[]; - double oldoldDeltalnK[], oldDeltalnK[], deltalnK[]; - double tm[]; - int lowestGibbsEnergyPhase = 0; - sysNewtonRhapsonTPflash secondOrderSolver; - protected boolean solidCheck = false, stabilityCheck = false; - boolean findLowesGibsPhaseIsChecked = false; - - /** - *

- * Constructor for Flash. - *

- */ - public Flash() {} - - /** - *

- * findLowestGibbsEnergyPhase. - *

- * - * @return a int - */ - public int findLowestGibbsEnergyPhase() { - if (!findLowesGibsPhaseIsChecked) { - minimumGibbsEnergySystem = system.clone(); - minimumGibbsEnergySystem.init(0); - minimumGibbsEnergySystem.init(1); - if ((minimumGibbsEnergySystem.getPhase(0).getGibbsEnergy() - * (1.0 - Math.signum(minimumGibbsEnergySystem.getPhase(0).getGibbsEnergy()) - * 1e-8)) < minimumGibbsEnergySystem.getPhase(1).getGibbsEnergy()) { - lowestGibbsEnergyPhase = 0; - } else { - lowestGibbsEnergyPhase = 1; - } - findLowesGibsPhaseIsChecked = true; - } - return lowestGibbsEnergyPhase; + private static final long serialVersionUID = 1000; + static Logger logger = LogManager.getLogger(Flash.class); + + SystemInterface system; + SystemInterface minimumGibbsEnergySystem; + + public double[] minGibsPhaseLogZ; + public double[] minGibsLogFugCoef; + int i = 0, j = 0, iterations = 0, maxNumberOfIterations = 100; + double gibbsEnergy = 0, gibbsEnergyOld = 0; + double Kold = 0, deviation = 0, g0 = 0, g1 = 0; + double lnOldOldOldK[], lnOldOldK[], lnK[], lnOldK[]; + double oldoldDeltalnK[], oldDeltalnK[], deltalnK[]; + double tm[]; + int lowestGibbsEnergyPhase = 0; + sysNewtonRhapsonTPflash secondOrderSolver; + protected boolean solidCheck = false, stabilityCheck = false; + boolean findLowesGibsPhaseIsChecked = false; + + /** + *

+ * Constructor for Flash. + *

+ */ + public Flash() {} + + /** + *

+ * findLowestGibbsEnergyPhase. + *

+ * + * @return a int + */ + public int findLowestGibbsEnergyPhase() { + if (!findLowesGibsPhaseIsChecked) { + minimumGibbsEnergySystem = system.clone(); + minimumGibbsEnergySystem.init(0); + minimumGibbsEnergySystem.init(1); + if ((minimumGibbsEnergySystem.getPhase(0).getGibbsEnergy() + * (1.0 - Math.signum(minimumGibbsEnergySystem.getPhase(0).getGibbsEnergy()) + * 1e-8)) < minimumGibbsEnergySystem.getPhase(1).getGibbsEnergy()) { + lowestGibbsEnergyPhase = 0; + } else { + lowestGibbsEnergyPhase = 1; + } + findLowesGibsPhaseIsChecked = true; + } + return lowestGibbsEnergyPhase; + } + + /** + *

+ * stabilityAnalysis. + *

+ * + * @throws neqsim.util.exception.IsNaNException if any. + * @throws neqsim.util.exception.TooManyIterationsException if any. + */ + public void stabilityAnalysis() throws neqsim.util.exception.IsNaNException, + neqsim.util.exception.TooManyIterationsException { + double[] logWi = new double[system.getPhases()[0].getNumberOfComponents()]; + double[] deltalogWi = new double[system.getPhases()[0].getNumberOfComponents()]; + double[] oldDeltalogWi = new double[system.getPhases()[0].getNumberOfComponents()]; + double[] oldoldDeltalogWi = new double[system.getPhases()[0].getNumberOfComponents()]; + double[][] Wi = new double[2][system.getPhases()[0].getNumberOfComponents()]; + double[] sumw = new double[2]; + boolean secondOrderStabilityAnalysis = false; + double[] oldlogw = new double[system.getPhases()[0].getNumberOfComponents()]; + double[] oldoldlogw = new double[system.getPhases()[0].getNumberOfComponents()]; + double[] oldoldoldlogw = new double[system.getPhases()[0].getNumberOfComponents()]; + double[] d = new double[system.getPhases()[0].getNumberOfComponents()]; + double[][] x = new double[2][system.getPhases()[0].getNumberOfComponents()]; + double[] error = new double[2]; + tm = new double[system.getPhase(0).getNumberOfComponents()]; + double[] alpha = null; + Matrix f = new Matrix(system.getPhases()[0].getNumberOfComponents(), 1); + Matrix df = null; + int maxiterations = 50; + double fNorm = 1.0e10, fNormOld = 0.0; + for (int i = 0; i < system.getPhases()[0].getNumberOfComponents(); i++) { + d[i] = minGibsPhaseLogZ[i] + minGibsLogFugCoef[i]; } - /** - *

- * stabilityAnalysis. - *

- * - * @throws neqsim.util.exception.IsNaNException if any. - * @throws neqsim.util.exception.TooManyIterationsException if any. - */ - public void stabilityAnalysis() throws neqsim.util.exception.IsNaNException, - neqsim.util.exception.TooManyIterationsException { - double[] logWi = new double[system.getPhases()[0].getNumberOfComponents()]; - double[] deltalogWi = new double[system.getPhases()[0].getNumberOfComponents()]; - double[] oldDeltalogWi = new double[system.getPhases()[0].getNumberOfComponents()]; - double[] oldoldDeltalogWi = new double[system.getPhases()[0].getNumberOfComponents()]; - double[][] Wi = new double[2][system.getPhases()[0].getNumberOfComponents()]; - double[] sumw = new double[2]; - boolean secondOrderStabilityAnalysis = false; - double[] oldlogw = new double[system.getPhases()[0].getNumberOfComponents()]; - double[] oldoldlogw = new double[system.getPhases()[0].getNumberOfComponents()]; - double[] oldoldoldlogw = new double[system.getPhases()[0].getNumberOfComponents()]; - double[] d = new double[system.getPhases()[0].getNumberOfComponents()]; - double[][] x = new double[2][system.getPhases()[0].getNumberOfComponents()]; - double[] error = new double[2]; - tm = new double[system.getPhase(0).getNumberOfComponents()]; - double[] alpha = null; - Matrix f = new Matrix(system.getPhases()[0].getNumberOfComponents(), 1); - Matrix df = null; - int maxiterations = 50; - double fNorm = 1.0e10, fNormOld = 0.0; - for (int i = 0; i < system.getPhases()[0].getNumberOfComponents(); i++) { - d[i] = minGibsPhaseLogZ[i] + minGibsLogFugCoef[i]; - } + SystemInterface clonedSystem = minimumGibbsEnergySystem; + clonedSystem.setTotalNumberOfMoles(1.0); + sumw[1] = 0.0; + sumw[0] = 0.0; - SystemInterface clonedSystem = minimumGibbsEnergySystem; - clonedSystem.setTotalNumberOfMoles(1.0); - sumw[1] = 0.0; - sumw[0] = 0.0; + for (int i = 0; i < clonedSystem.getPhase(0).getNumberOfComponents(); i++) { + sumw[1] += clonedSystem.getPhase(0).getComponent(i).getz() + / clonedSystem.getPhase(0).getComponent(i).getK(); + sumw[0] += clonedSystem.getPhase(0).getComponent(i).getK() + * clonedSystem.getPhase(0).getComponent(i).getz(); + } - for (int i = 0; i < clonedSystem.getPhase(0).getNumberOfComponents(); i++) { - sumw[1] += clonedSystem.getPhase(0).getComponent(i).getz() - / clonedSystem.getPhase(0).getComponent(i).getK(); - sumw[0] += clonedSystem.getPhase(0).getComponent(i).getK() - * clonedSystem.getPhase(0).getComponent(i).getz(); - } + // System.out.println("sumw0 " + sumw[0]); + // System.out.println("sumw1 " + sumw[1]); + + int start = 0; + int end = 1;// clonedSystem.getNumberOfPhases()-1; + int mult = 1; + // if (sumw[1] > sumw[0]) { + if (lowestGibbsEnergyPhase == 0) { + start = end; + end = 0; + mult = -1; + } - // System.out.println("sumw0 " + sumw[0]); - // System.out.println("sumw1 " + sumw[1]); - - int start = 0; - int end = 1;// clonedSystem.getNumberOfPhases()-1; - int mult = 1; - // if (sumw[1] > sumw[0]) { - if (lowestGibbsEnergyPhase == 0) { - start = end; - end = 0; - mult = -1; - } + for (int i = 0; i < clonedSystem.getPhase(0).getNumberOfComponents(); i++) { + clonedSystem.getPhase(1).getComponent(i).setx(clonedSystem.getPhase(0).getComponent(i).getz() + / clonedSystem.getPhase(0).getComponent(i).getK() / sumw[1]); + clonedSystem.getPhase(0).getComponent(i).setx(clonedSystem.getPhase(0).getComponent(i).getK() + * clonedSystem.getPhase(0).getComponent(i).getz() / sumw[0]); + } - for (int i = 0; i < clonedSystem.getPhase(0).getNumberOfComponents(); i++) { - clonedSystem.getPhase(1).getComponent(i) - .setx(clonedSystem.getPhase(0).getComponent(i).getz() - / clonedSystem.getPhase(0).getComponent(i).getK() / sumw[1]); - clonedSystem.getPhase(0).getComponent(i) - .setx(clonedSystem.getPhase(0).getComponent(i).getK() - * clonedSystem.getPhase(0).getComponent(i).getz() / sumw[0]); + // for (int j = 0; j < clonedSystem.getNumberOfPhases(); j++) { + for (int j = start; j >= end; j = j + mult) { + for (int i = 0; i < clonedSystem.getPhases()[0].getNumberOfComponents(); i++) { + Wi[j][i] = clonedSystem.getPhase(j).getComponent(i).getx(); + logWi[i] = Math.log(Wi[j][i]); + } + iterations = 0; + fNorm = 1.0e10; + + do { + iterations++; + error[j] = 0.0; + + for (int i = 0; i < clonedSystem.getPhases()[0].getNumberOfComponents(); i++) { + oldoldoldlogw[i] = oldoldlogw[i]; + oldoldlogw[i] = oldlogw[i]; + oldlogw[i] = logWi[i]; + + oldoldDeltalogWi[i] = oldoldlogw[i] - oldoldoldlogw[i]; + oldDeltalogWi[i] = oldlogw[i] - oldoldlogw[i]; } - // for (int j = 0; j < clonedSystem.getNumberOfPhases(); j++) { - for (int j = start; j >= end; j = j + mult) { - for (int i = 0; i < clonedSystem.getPhases()[0].getNumberOfComponents(); i++) { - Wi[j][i] = clonedSystem.getPhase(j).getComponent(i).getx(); - logWi[i] = Math.log(Wi[j][i]); - } - iterations = 0; - fNorm = 1.0e10; - - do { - iterations++; - error[j] = 0.0; - - for (int i = 0; i < clonedSystem.getPhases()[0].getNumberOfComponents(); i++) { - oldoldoldlogw[i] = oldoldlogw[i]; - oldoldlogw[i] = oldlogw[i]; - oldlogw[i] = logWi[i]; - - oldoldDeltalogWi[i] = oldoldlogw[i] - oldoldoldlogw[i]; - oldDeltalogWi[i] = oldlogw[i] - oldoldlogw[i]; - } - - if ((iterations <= maxiterations - 10) - || !system.isImplementedCompositionDeriativesofFugacity()) { - clonedSystem.init(1, j); - fNormOld = fNorm; - for (int i = 0; i < clonedSystem.getPhases()[0].getNumberOfComponents(); i++) { - f.set(i, 0, Math.sqrt(Wi[j][i]) * (Math.log(Wi[j][i]) + clonedSystem - .getPhase(j).getComponent(i).getLogFugacityCoefficient() - d[i])); - } - fNorm = f.norm2(); - if (fNorm > fNormOld && iterations > 3 || (iterations + 1) % 7 != 0) { - break; - } - if (iterations % 7 == 0 && fNorm < fNormOld && !secondOrderStabilityAnalysis) { - double vec1 = 0.0, vec2 = 0.0, prod1 = 0.0, prod2 = 0.0; - - for (i = 0; i < clonedSystem.getPhases()[0].getNumberOfComponents(); i++) { - vec1 = oldDeltalogWi[i] * oldoldDeltalogWi[i]; - vec2 = Math.pow(oldoldDeltalogWi[i], 2.0); - prod1 += vec1 * vec2; - prod2 += vec2 * vec2; - } - - double lambda = prod1 / prod2; - // logger.info("lambda " + lambda); - for (i = 0; i < clonedSystem.getPhases()[0].getNumberOfComponents(); i++) { - logWi[i] += lambda / (1.0 - lambda) * deltalogWi[i]; - error[j] += Math.abs((logWi[i] - oldlogw[i]) / oldlogw[i]); - Wi[j][i] = Math.exp(logWi[i]); - } - } else { - // succsessive substitution - for (int i = 0; i < clonedSystem.getPhases()[0] - .getNumberOfComponents(); i++) { - logWi[i] = d[i] - clonedSystem.getPhase(j).getComponent(i) - .getLogFugacityCoefficient(); - error[j] += Math.abs((logWi[i] - oldlogw[i]) / oldlogw[i]); - Wi[j][i] = Math.exp(logWi[i]); - } - } - } else { - if (!secondOrderStabilityAnalysis) { - alpha = new double[system.getPhases()[0].getNumberOfComponents()]; - df = new Matrix(system.getPhases()[0].getNumberOfComponents(), - system.getPhases()[0].getNumberOfComponents()); - secondOrderStabilityAnalysis = true; - } - - clonedSystem.init(3, j); - for (int i = 0; i < clonedSystem.getPhases()[0].getNumberOfComponents(); i++) { - alpha[i] = 2.0 * Math.sqrt(Wi[j][i]); - } - - for (int i = 0; i < clonedSystem.getPhases()[0].getNumberOfComponents(); i++) { - f.set(i, 0, Math.sqrt(Wi[j][i]) * (Math.log(Wi[j][i]) + clonedSystem - .getPhase(j).getComponent(i).getLogFugacityCoefficient() - d[i])); - for (int k = 0; k < clonedSystem.getPhases()[0] - .getNumberOfComponents(); k++) { - double kronDelt = (i == k) ? 1.5 : 0.0; // adding 0.5 to diagonal - df.set(i, k, kronDelt + Math.sqrt(Wi[j][k] * Wi[j][i]) - * clonedSystem.getPhase(j).getComponent(i).getdfugdn(k));// * - // clonedSystem.getPhases()[j].getNumberOfMolesInPhase()); - } - } - - Matrix dx = df.solve(f).times(-1.0); - for (int i = 0; i < clonedSystem.getPhases()[0].getNumberOfComponents(); i++) { - Wi[j][i] = Math.pow((alpha[i] + dx.get(i, 0)) / 2.0, 2.0); - logWi[i] = Math.log(Wi[j][i]); - error[j] += Math.abs((logWi[i] - oldlogw[i]) / oldlogw[i]); - } - - // logger.info("err newton " + error[j]); - } - - // logger.info("norm f " + f.norm1()); - // clonedSystem.display(); - sumw[j] = 0.0; - for (int i = 0; i < clonedSystem.getPhases()[0].getNumberOfComponents(); i++) { - sumw[j] += Wi[j][i]; - } - - for (int i = 0; i < clonedSystem.getPhases()[0].getNumberOfComponents(); i++) { - deltalogWi[i] = logWi[i] - oldlogw[i]; - clonedSystem.getPhase(j).getComponent(i).setx(Wi[j][i] / sumw[j]); - } - // logger.info("fnorm " + f.norm1() + " err " + error[j] + " iterations " + - // iterations + " phase " + j); - } while ((f.norm1() > 1e-6 && iterations < maxiterations) || (iterations % 7) == 0 - || iterations < 3); - // (error[j]= maxiterations) { - logger.error("err staability check " + error[j]); - // throw new util.exception.TooManyIterationsException(); + if ((iterations <= maxiterations - 10) + || !system.isImplementedCompositionDeriativesofFugacity()) { + clonedSystem.init(1, j); + fNormOld = fNorm; + for (int i = 0; i < clonedSystem.getPhases()[0].getNumberOfComponents(); i++) { + f.set(i, 0, Math.sqrt(Wi[j][i]) * (Math.log(Wi[j][i]) + + clonedSystem.getPhase(j).getComponent(i).getLogFugacityCoefficient() - d[i])); + } + fNorm = f.norm2(); + if (fNorm > fNormOld && iterations > 3 || (iterations + 1) % 7 != 0) { + break; + } + if (iterations % 7 == 0 && fNorm < fNormOld && !secondOrderStabilityAnalysis) { + double vec1 = 0.0, vec2 = 0.0, prod1 = 0.0, prod2 = 0.0; + + for (i = 0; i < clonedSystem.getPhases()[0].getNumberOfComponents(); i++) { + vec1 = oldDeltalogWi[i] * oldoldDeltalogWi[i]; + vec2 = Math.pow(oldoldDeltalogWi[i], 2.0); + prod1 += vec1 * vec2; + prod2 += vec2 * vec2; } - tm[j] = 1.0; + double lambda = prod1 / prod2; + // logger.info("lambda " + lambda); + for (i = 0; i < clonedSystem.getPhases()[0].getNumberOfComponents(); i++) { + logWi[i] += lambda / (1.0 - lambda) * deltalogWi[i]; + error[j] += Math.abs((logWi[i] - oldlogw[i]) / oldlogw[i]); + Wi[j][i] = Math.exp(logWi[i]); + } + } else { + // succsessive substitution for (int i = 0; i < clonedSystem.getPhases()[0].getNumberOfComponents(); i++) { - tm[j] -= Wi[j][i]; - x[j][i] = clonedSystem.getPhase(j).getComponent(i).getx(); + logWi[i] = + d[i] - clonedSystem.getPhase(j).getComponent(i).getLogFugacityCoefficient(); + error[j] += Math.abs((logWi[i] - oldlogw[i]) / oldlogw[i]); + Wi[j][i] = Math.exp(logWi[i]); } - if (tm[j] < -1e-4 && error[j] < 1e-6) { - break; - } else { - tm[j] = 1.0; + } + } else { + if (!secondOrderStabilityAnalysis) { + alpha = new double[system.getPhases()[0].getNumberOfComponents()]; + df = new Matrix(system.getPhases()[0].getNumberOfComponents(), + system.getPhases()[0].getNumberOfComponents()); + secondOrderStabilityAnalysis = true; + } + + clonedSystem.init(3, j); + for (int i = 0; i < clonedSystem.getPhases()[0].getNumberOfComponents(); i++) { + alpha[i] = 2.0 * Math.sqrt(Wi[j][i]); + } + + for (int i = 0; i < clonedSystem.getPhases()[0].getNumberOfComponents(); i++) { + f.set(i, 0, Math.sqrt(Wi[j][i]) * (Math.log(Wi[j][i]) + + clonedSystem.getPhase(j).getComponent(i).getLogFugacityCoefficient() - d[i])); + for (int k = 0; k < clonedSystem.getPhases()[0].getNumberOfComponents(); k++) { + double kronDelt = (i == k) ? 1.5 : 0.0; // adding 0.5 to diagonal + df.set(i, k, kronDelt + Math.sqrt(Wi[j][k] * Wi[j][i]) + * clonedSystem.getPhase(j).getComponent(i).getdfugdn(k));// * + // clonedSystem.getPhases()[j].getNumberOfMolesInPhase()); } - } + } - // check for trivial solution - double diffx = 0.0; - for (int i = 0; i < clonedSystem.getPhase(0).getNumberOfComponents(); i++) { - diffx += Math.abs(clonedSystem.getPhase(0).getComponent(i).getx() - - clonedSystem.getPhase(1).getComponent(i).getx()); + Matrix dx = df.solve(f).times(-1.0); + for (int i = 0; i < clonedSystem.getPhases()[0].getNumberOfComponents(); i++) { + Wi[j][i] = Math.pow((alpha[i] + dx.get(i, 0)) / 2.0, 2.0); + logWi[i] = Math.log(Wi[j][i]); + error[j] += Math.abs((logWi[i] - oldlogw[i]) / oldlogw[i]); + } + + // logger.info("err newton " + error[j]); } - if (diffx < 1e-10) { - tm[0] = 0.0; - tm[1] = 0.0; + + // logger.info("norm f " + f.norm1()); + // clonedSystem.display(); + sumw[j] = 0.0; + for (int i = 0; i < clonedSystem.getPhases()[0].getNumberOfComponents(); i++) { + sumw[j] += Wi[j][i]; } - if (((tm[0] < -1e-4) || (tm[1] < -1e-4)) - && !(Double.isNaN(tm[0]) || (Double.isNaN(tm[1])))) { - for (int i = 0; i < clonedSystem.getPhases()[0].getNumberOfComponents(); i++) { - if (system.getPhases()[1].getComponents()[i].getx() < 1e-100) { - continue; - } - if (tm[0] < -1e-4) { - system.getPhases()[1].getComponents()[i] - .setK((Wi[0][i] / sumw[0]) / (Wi[1][i] / sumw[1])); - system.getPhases()[0].getComponents()[i] - .setK((Wi[0][i] / sumw[0]) / (Wi[1][i] / sumw[1])); - } else if (tm[1] < -1e-4) { - system.getPhases()[1].getComponents()[i] - .setK((Wi[0][i] / sumw[0]) / (Wi[1][i] / sumw[1])); - system.getPhases()[0].getComponents()[i] - .setK((Wi[0][i] / sumw[0]) / (Wi[1][i] / sumw[1])); - } else { - logger.info("error in stability anlysis"); - system.init(0); - } - - if (Double.isNaN(tm[j])) { - tm[j] = 0; - } - } + for (int i = 0; i < clonedSystem.getPhases()[0].getNumberOfComponents(); i++) { + deltalogWi[i] = logWi[i] - oldlogw[i]; + clonedSystem.getPhase(j).getComponent(i).setx(Wi[j][i] / sumw[j]); } + // logger.info("fnorm " + f.norm1() + " err " + error[j] + " iterations " + + // iterations + " phase " + j); + } while ((f.norm1() > 1e-6 && iterations < maxiterations) || (iterations % 7) == 0 + || iterations < 3); + // (error[j]= maxiterations) { + logger.error("err staability check " + error[j]); + // throw new util.exception.TooManyIterationsException(); + } + + tm[j] = 1.0; + for (int i = 0; i < clonedSystem.getPhases()[0].getNumberOfComponents(); i++) { + tm[j] -= Wi[j][i]; + x[j][i] = clonedSystem.getPhase(j).getComponent(i).getx(); + } + if (tm[j] < -1e-4 && error[j] < 1e-6) { + break; + } else { + tm[j] = 1.0; + } + } - // logger.info("STABILITY ANALYSIS: "); - // logger.info("tm1: " + tm[0] + " tm2: " + tm[1]); + // check for trivial solution + double diffx = 0.0; + for (int i = 0; i < clonedSystem.getPhase(0).getNumberOfComponents(); i++) { + diffx += Math.abs(clonedSystem.getPhase(0).getComponent(i).getx() + - clonedSystem.getPhase(1).getComponent(i).getx()); + } + if (diffx < 1e-10) { + tm[0] = 0.0; + tm[1] = 0.0; } - /** - *

- * stabilityCheck. - *

- * - * @return a boolean - */ - public boolean stabilityCheck() { - boolean stable = false; - // logger.info("starting stability analysis...."); - lowestGibbsEnergyPhase = findLowestGibbsEnergyPhase(); - if (system.getPhase(lowestGibbsEnergyPhase).getNumberOfComponents() > 1) { - try { - stabilityAnalysis(); - } catch (Exception e) { - logger.error("error ", e); - } + if (((tm[0] < -1e-4) || (tm[1] < -1e-4)) && !(Double.isNaN(tm[0]) || (Double.isNaN(tm[1])))) { + for (int i = 0; i < clonedSystem.getPhases()[0].getNumberOfComponents(); i++) { + if (system.getPhases()[1].getComponents()[i].getx() < 1e-100) { + continue; } - if (!(tm[0] < -1e-4) && !(tm[1] < -1e-4) - || system.getPhase(0).getNumberOfComponents() == 1) { - stable = true; - system.init(0); - // logger.info("system is stable"); - // logger.info("Stable phase is : " + lowestGibbsEnergyPhase); - system.setNumberOfPhases(1); - - if (lowestGibbsEnergyPhase == 0) { - system.setPhaseType(0, 1); - } else { - system.setPhaseType(0, 0); - } - system.init(1); - if (solidCheck && !system.doMultiPhaseCheck()) { - this.solidPhaseFlash(); - } + if (tm[0] < -1e-4) { + system.getPhases()[1].getComponents()[i] + .setK((Wi[0][i] / sumw[0]) / (Wi[1][i] / sumw[1])); + system.getPhases()[0].getComponents()[i] + .setK((Wi[0][i] / sumw[0]) / (Wi[1][i] / sumw[1])); + } else if (tm[1] < -1e-4) { + system.getPhases()[1].getComponents()[i] + .setK((Wi[0][i] / sumw[0]) / (Wi[1][i] / sumw[1])); + system.getPhases()[0].getComponents()[i] + .setK((Wi[0][i] / sumw[0]) / (Wi[1][i] / sumw[1])); } else { - try { - system.calcBeta(); - } catch (Exception e) { - logger.error("error", e); - } - system.calc_x_y(); - system.init(1); + logger.info("error in stability anlysis"); + system.init(0); } - return stable; + if (Double.isNaN(tm[j])) { + tm[j] = 0; + } + } } - /** {@inheritDoc} */ - @Override - public void displayResult() { - system.display(); + // logger.info("STABILITY ANALYSIS: "); + // logger.info("tm1: " + tm[0] + " tm2: " + tm[1]); + } + + /** + *

+ * stabilityCheck. + *

+ * + * @return a boolean + */ + public boolean stabilityCheck() { + boolean stable = false; + // logger.info("starting stability analysis...."); + lowestGibbsEnergyPhase = findLowestGibbsEnergyPhase(); + if (system.getPhase(lowestGibbsEnergyPhase).getNumberOfComponents() > 1) { + try { + stabilityAnalysis(); + } catch (Exception e) { + logger.error("error ", e); + } + } + if (!(tm[0] < -1e-4) && !(tm[1] < -1e-4) || system.getPhase(0).getNumberOfComponents() == 1) { + stable = true; + system.init(0); + // logger.info("system is stable"); + // logger.info("Stable phase is : " + lowestGibbsEnergyPhase); + system.setNumberOfPhases(1); + + if (lowestGibbsEnergyPhase == 0) { + system.setPhaseType(0, 1); + } else { + system.setPhaseType(0, 0); + } + system.init(1); + if (solidCheck && !system.doMultiPhaseCheck()) { + this.solidPhaseFlash(); + } + } else { + try { + system.calcBeta(); + } catch (Exception e) { + logger.error("error", e); + } + system.calc_x_y(); + system.init(1); } - /** - *

- * solidPhaseFlash. - *

- */ - public void solidPhaseFlash() { - boolean solidPhase = false; - double frac = 0; - int solid = 0; - double[] tempVar = new double[system.getPhases()[0].getNumberOfComponents()]; - - if (!system.hasSolidPhase()) { - system.setNumberOfPhases(system.getNumberOfPhases() + 1); - system.setPhaseIndex(system.getNumberOfPhases() - 1, 3); - } - // logger.info("numb " + system.getNumberOfPhases()); - system.init(1); - - for (int k = 0; k < system.getPhase(0).getNumberOfComponents(); k++) { - if (system.getPhase(0).getComponent(k).doSolidCheck()) { - tempVar[k] = system.getPhase(0).getComponents()[k].getz(); - for (int i = 0; i < system.getNumberOfPhases() - 1; i++) { - tempVar[k] -= system.getBeta(i) - * system.getPhases()[3].getComponent(k).getFugacityCoefficient() - / system.getPhase(i).getComponent(k).getFugacityCoefficient(); - } - - if (tempVar[k] > 0.0 && tempVar[k] > frac) { - solidPhase = true; - solid = k; - frac = tempVar[k]; - for (int p = 0; p < system.getPhases()[0].getNumberOfComponents(); p++) { - system.getPhases()[3].getComponents()[p].setx(1.0e-20); - } - system.getPhases()[3].getComponents()[solid].setx(1.0); - } - // logger.info("tempVar: " + tempVar[k]); - } + return stable; + } + + /** {@inheritDoc} */ + @Override + public void displayResult() { + system.display(); + } + + /** + *

+ * solidPhaseFlash. + *

+ */ + public void solidPhaseFlash() { + boolean solidPhase = false; + double frac = 0; + int solid = 0; + double[] tempVar = new double[system.getPhases()[0].getNumberOfComponents()]; + + if (!system.hasSolidPhase()) { + system.setNumberOfPhases(system.getNumberOfPhases() + 1); + system.setPhaseIndex(system.getNumberOfPhases() - 1, 3); + } + // logger.info("numb " + system.getNumberOfPhases()); + system.init(1); + + for (int k = 0; k < system.getPhase(0).getNumberOfComponents(); k++) { + if (system.getPhase(0).getComponent(k).doSolidCheck()) { + tempVar[k] = system.getPhase(0).getComponents()[k].getz(); + for (int i = 0; i < system.getNumberOfPhases() - 1; i++) { + tempVar[k] -= + system.getBeta(i) * system.getPhases()[3].getComponent(k).getFugacityCoefficient() + / system.getPhase(i).getComponent(k).getFugacityCoefficient(); } - if (solidPhase) { - if (frac < system.getPhases()[0].getComponents()[solid].getz() + 1e10) { - for (int i = 0; i < system.getNumberOfPhases() - 1; i++) { - // system.getPhases()[i].getComponents()[solid].setx(1.0e-10); - } - system.init(1); - // logger.info("solid phase will form..." + system.getNumberOfPhases()); - // logger.info("freezing component " + solid); - system.setBeta(system.getNumberOfPhases() - 1, frac); - system.initBeta(); - system.setBeta(system.getNumberOfPhases() - 1, - system.getPhases()[3].getComponent(solid).getNumberOfmoles() - / system.getNumberOfMoles()); - // double phasetot=0.0; - // for(int ph=0;ph 0.0 && tempVar[k] > frac) { + solidPhase = true; + solid = k; + frac = tempVar[k]; + for (int p = 0; p < system.getPhases()[0].getNumberOfComponents(); p++) { + system.getPhases()[3].getComponents()[p].setx(1.0e-20); + } + system.getPhases()[3].getComponents()[solid].setx(1.0); } + // logger.info("tempVar: " + tempVar[k]); + } } - /** {@inheritDoc} */ - @Override - public void printToFile(String name) {} - - /** {@inheritDoc} */ - @Override - public void createNetCdfFile(String name) {} - - /** {@inheritDoc} */ - @Override - public double[][] getPoints(int i) { - return null; - } - - /** {@inheritDoc} */ - @Override - public String[][] getResultTable() { - return null; + if (solidPhase) { + if (frac < system.getPhases()[0].getComponents()[solid].getz() + 1e10) { + for (int i = 0; i < system.getNumberOfPhases() - 1; i++) { + // system.getPhases()[i].getComponents()[solid].setx(1.0e-10); + } + system.init(1); + // logger.info("solid phase will form..." + system.getNumberOfPhases()); + // logger.info("freezing component " + solid); + system.setBeta(system.getNumberOfPhases() - 1, frac); + system.initBeta(); + system.setBeta(system.getNumberOfPhases() - 1, + system.getPhases()[3].getComponent(solid).getNumberOfmoles() + / system.getNumberOfMoles()); + // double phasetot=0.0; + // for(int ph=0;ph - * Constructor for TPflash. - *

- */ - public TPflash() {} - - /** - *

- * Constructor for TPflash. - *

- * - * @param system a {@link neqsim.thermo.system.SystemInterface} object - */ - public TPflash(SystemInterface system) { - this.system = system; - lnOldOldOldK = new double[system.getPhases()[0].getNumberOfComponents()]; - lnOldOldK = new double[system.getPhases()[0].getNumberOfComponents()]; - lnOldK = new double[system.getPhases()[0].getNumberOfComponents()]; - lnK = new double[system.getPhases()[0].getNumberOfComponents()]; - oldoldDeltalnK = new double[system.getPhases()[0].getNumberOfComponents()]; - oldDeltalnK = new double[system.getPhases()[0].getNumberOfComponents()]; - deltalnK = new double[system.getPhases()[0].getNumberOfComponents()]; + private static final long serialVersionUID = 1000; + static Logger logger = LogManager.getLogger(TPflash.class); + + SystemInterface clonedSystem; + double betaTolerance = neqsim.thermo.ThermodynamicModelSettings.phaseFractionMinimumLimit; + double presdiff = 1.0; + + /** + *

+ * Constructor for TPflash. + *

+ */ + public TPflash() {} + + /** + *

+ * Constructor for TPflash. + *

+ * + * @param system a {@link neqsim.thermo.system.SystemInterface} object + */ + public TPflash(SystemInterface system) { + this.system = system; + lnOldOldOldK = new double[system.getPhases()[0].getNumberOfComponents()]; + lnOldOldK = new double[system.getPhases()[0].getNumberOfComponents()]; + lnOldK = new double[system.getPhases()[0].getNumberOfComponents()]; + lnK = new double[system.getPhases()[0].getNumberOfComponents()]; + oldoldDeltalnK = new double[system.getPhases()[0].getNumberOfComponents()]; + oldDeltalnK = new double[system.getPhases()[0].getNumberOfComponents()]; + deltalnK = new double[system.getPhases()[0].getNumberOfComponents()]; + } + + /** + *

+ * Constructor for TPflash. + *

+ * + * @param system a {@link neqsim.thermo.system.SystemInterface} object + * @param solCheck a boolean + */ + public TPflash(SystemInterface system, boolean solCheck) { + this(system); + solidCheck = solCheck; + } + + /** + *

+ * sucsSubs. + *

+ */ + public void sucsSubs() { + deviation = 0; + + for (i = 0; i < system.getPhase(0).getNumberOfComponents(); i++) { + if (system.getPhase(0).getComponent(i).getIonicCharge() != 0) { + Kold = system.getPhase(0).getComponent(i).getK(); + system.getPhase(0).getComponent(i).setK(1.0e-40); + system.getPhase(1).getComponent(i).setK(system.getPhase(0).getComponent(i).getK()); + } else { + Kold = system.getPhase(0).getComponent(i).getK(); + system.getPhase(0).getComponent(i) + .setK(system.getPhase(1).getComponent(i).getFugacityCoefficient() + / system.getPhase(0).getComponent(i).getFugacityCoefficient() * presdiff); + if (Double.isNaN(system.getPhase(0).getComponent(i).getK())) { + system.getPhase(0).getComponent(i).setK(Kold); + system.init(1); + } + system.getPhase(1).getComponent(i).setK(system.getPhase(0).getComponent(i).getK()); + deviation += Math.abs(Math.log(system.getPhase(0).getComponent(i).getK()) - Math.log(Kold)); + } } - /** - *

- * Constructor for TPflash. - *

- * - * @param system a {@link neqsim.thermo.system.SystemInterface} object - * @param solCheck a boolean - */ - public TPflash(SystemInterface system, boolean solCheck) { - this(system); - solidCheck = solCheck; + double oldBeta = system.getBeta(); + try { + system.calcBeta(); + } catch (Exception e) { + logger.error("error in beta calc" + e.toString()); + system.setBeta(oldBeta); + } + if (system.getBeta() > 1.0 - betaTolerance) { + system.setBeta(1.0 - betaTolerance); + } + if (system.getBeta() < betaTolerance) { + system.setBeta(betaTolerance); + } + system.calc_x_y(); + system.init(1); + } + + /** + *

+ * accselerateSucsSubs. + *

+ */ + public void accselerateSucsSubs() { + double prod1 = 0.0, prod2 = 0.0; + + for (i = 0; i < system.getPhase(0).getNumberOfComponents(); i++) { + prod1 += oldDeltalnK[i] * oldoldDeltalnK[i]; + prod2 += oldoldDeltalnK[i] * oldoldDeltalnK[i]; } - /** - *

- * sucsSubs. - *

- */ - public void sucsSubs() { - deviation = 0; - - for (i = 0; i < system.getPhase(0).getNumberOfComponents(); i++) { - if (system.getPhase(0).getComponent(i).getIonicCharge() != 0) { - Kold = system.getPhase(0).getComponent(i).getK(); - system.getPhase(0).getComponent(i).setK(1.0e-40); - system.getPhase(1).getComponent(i).setK(system.getPhase(0).getComponent(i).getK()); - } else { - Kold = system.getPhase(0).getComponent(i).getK(); - system.getPhase(0).getComponent(i) - .setK(system.getPhase(1).getComponent(i).getFugacityCoefficient() - / system.getPhase(0).getComponent(i).getFugacityCoefficient() - * presdiff); - if (Double.isNaN(system.getPhase(0).getComponent(i).getK())) { - system.getPhase(0).getComponent(i).setK(Kold); - system.init(1); - } - system.getPhase(1).getComponent(i).setK(system.getPhase(0).getComponent(i).getK()); - deviation += Math - .abs(Math.log(system.getPhase(0).getComponent(i).getK()) - Math.log(Kold)); - } - } + double lambda = prod1 / prod2; - double oldBeta = system.getBeta(); - try { - system.calcBeta(); - } catch (Exception e) { - logger.error("error in beta calc" + e.toString()); - system.setBeta(oldBeta); - } - if (system.getBeta() > 1.0 - betaTolerance) { - system.setBeta(1.0 - betaTolerance); - } - if (system.getBeta() < betaTolerance) { - system.setBeta(betaTolerance); - } - system.calc_x_y(); - system.init(1); + for (i = 0; i < system.getPhase(0).getNumberOfComponents(); i++) { + // lnK[i] = lnK[i] + lambda*lambda*oldoldDeltalnK[i]/(1.0-lambda); // byttet + + // til - + lnK[i] += lambda / (1.0 - lambda) * deltalnK[i]; + system.getPhase(0).getComponent(i).setK(Math.exp(lnK[i])); + system.getPhase(1).getComponent(i).setK(Math.exp(lnK[i])); + } + double oldBeta = system.getBeta(); + try { + system.calcBeta(); + } catch (Exception e) { + if (system.getBeta() > 1.0 - betaTolerance || system.getBeta() < betaTolerance) { + system.setBeta(oldBeta); + } + logger.info("temperature " + system.getTemperature() + " pressure " + system.getPressure()); + logger.error("error", e); } - /** - *

- * accselerateSucsSubs. - *

- */ - public void accselerateSucsSubs() { - double prod1 = 0.0, prod2 = 0.0; - - for (i = 0; i < system.getPhase(0).getNumberOfComponents(); i++) { - prod1 += oldDeltalnK[i] * oldoldDeltalnK[i]; - prod2 += oldoldDeltalnK[i] * oldoldDeltalnK[i]; - } + system.calc_x_y(); + system.init(1); + // sucsSubs(); + } + + /** + *

+ * setNewK. + *

+ */ + public void setNewK() { + for (i = 0; i < system.getPhase(0).getNumberOfComponents(); i++) { + lnOldOldOldK[i] = lnOldOldK[i]; + lnOldOldK[i] = lnOldK[i]; + lnOldK[i] = lnK[i]; + lnK[i] = Math.log(system.getPhase(1).getComponent(i).getFugacityCoefficient()) + - Math.log(system.getPhase(0).getComponents()[i].getFugacityCoefficient()); + + oldoldDeltalnK[i] = lnOldOldK[i] - lnOldOldOldK[i]; + oldDeltalnK[i] = lnOldK[i] - lnOldOldK[i]; + deltalnK[i] = lnK[i] - lnOldK[i]; + } + } + + /** + *

+ * resetK. + *

+ */ + public void resetK() { + + for (i = 0; i < system.getPhase(0).getNumberOfComponents(); i++) { + lnK[i] = lnOldK[i]; + system.getPhase(0).getComponents()[i].setK(Math.exp(lnK[i])); + system.getPhase(1).getComponents()[i].setK(Math.exp(lnK[i])); + } + try { + system.calcBeta(); + system.calc_x_y(); + system.init(1); + } catch (Exception e) { + logger.error("error", e); + } + } + + /** {@inheritDoc} */ + @Override + public void run() { + if (system.isForcePhaseTypes() && system.getMaxNumberOfPhases() == 1) { + system.setNumberOfPhases(1); + return; + } - double lambda = prod1 / prod2; + findLowesGibsPhaseIsChecked = false; + int minGibbsPhase = 0; + double minimumGibbsEnergy = 0; - for (i = 0; i < system.getPhase(0).getNumberOfComponents(); i++) { - // lnK[i] = lnK[i] + lambda*lambda*oldoldDeltalnK[i]/(1.0-lambda); // byttet + - // til - - lnK[i] += lambda / (1.0 - lambda) * deltalnK[i]; - system.getPhase(0).getComponent(i).setK(Math.exp(lnK[i])); - system.getPhase(1).getComponent(i).setK(Math.exp(lnK[i])); - } - double oldBeta = system.getBeta(); - try { - system.calcBeta(); - } catch (Exception e) { - if (system.getBeta() > 1.0 - betaTolerance || system.getBeta() < betaTolerance) { - system.setBeta(oldBeta); - } - logger.info( - "temperature " + system.getTemperature() + " pressure " + system.getPressure()); - logger.error("error", e); - } + system.init(0); + system.init(1); - system.calc_x_y(); - system.init(1); - // sucsSubs(); + if (system.getPhase(0).getGibbsEnergy() < system.getPhase(1).getGibbsEnergy()) { + minimumGibbsEnergy = system.getPhase(0).getGibbsEnergy(); + } else { + minGibbsPhase = 1; + minimumGibbsEnergy = system.getPhase(1).getGibbsEnergy(); } - /** - *

- * setNewK. - *

- */ - public void setNewK() { - for (i = 0; i < system.getPhase(0).getNumberOfComponents(); i++) { - lnOldOldOldK[i] = lnOldOldK[i]; - lnOldOldK[i] = lnOldK[i]; - lnOldK[i] = lnK[i]; - lnK[i] = Math.log(system.getPhase(1).getComponent(i).getFugacityCoefficient()) - - Math.log(system.getPhase(0).getComponents()[i].getFugacityCoefficient()); - - oldoldDeltalnK[i] = lnOldOldK[i] - lnOldOldOldK[i]; - oldDeltalnK[i] = lnOldK[i] - lnOldOldK[i]; - deltalnK[i] = lnK[i] - lnOldK[i]; - } + if (system.getPhase(0).getNumberOfComponents() == 1 || system.getMaxNumberOfPhases() == 1) { + system.setNumberOfPhases(1); + if (minGibbsPhase == 0) { + system.setPhaseIndex(0, 0); + } else { + system.setPhaseIndex(0, 1); + } + if (solidCheck) { + ThermodynamicOperations operation = new ThermodynamicOperations(system); + operation.TPSolidflash(); + } + return; } - /** - *

- * resetK. - *

- */ - public void resetK() { - for (i = 0; i < system.getPhase(0).getNumberOfComponents(); i++) { - lnK[i] = lnOldK[i]; - system.getPhase(0).getComponents()[i].setK(Math.exp(lnK[i])); - system.getPhase(1).getComponents()[i].setK(Math.exp(lnK[i])); - } - try { - system.calcBeta(); - system.calc_x_y(); - system.init(1); - } catch (Exception e) { - logger.error("error", e); - } + minGibsPhaseLogZ = new double[system.getPhase(0).getNumberOfComponents()]; + minGibsLogFugCoef = new double[system.getPhase(0).getNumberOfComponents()]; + + for (int i = 0; i < system.getPhase(0).getNumberOfComponents(); i++) { + minGibsPhaseLogZ[i] = Math.log(system.getPhase(minGibbsPhase).getComponent(i).getz()); + minGibsLogFugCoef[i] = + system.getPhase(minGibbsPhase).getComponent(i).getLogFugacityCoefficient(); } - /** {@inheritDoc} */ - @Override - public void run() { - if (system.isForcePhaseTypes() && system.getMaxNumberOfPhases() == 1) { - system.setNumberOfPhases(1); - return; - } + presdiff = system.getPhase(1).getPressure() / system.getPhase(0).getPressure(); + if (Math.abs(system.getPhase(0).getPressure() - system.getPhase(1).getPressure()) > 1e-12) { + for (i = 0; i < system.getPhase(0).getNumberOfComponents(); i++) { + system.getPhase(0).getComponent(i) + .setK(system.getPhase(0).getComponent(i).getK() * presdiff); + system.getPhase(1).getComponent(i).setK(system.getPhase(0).getComponent(i).getK()); + } + } - findLowesGibsPhaseIsChecked = false; - int minGibbsPhase = 0; - double minimumGibbsEnergy = 0; + if (system.isChemicalSystem()) { + system.getChemicalReactionOperations().solveChemEq(1, 0); + system.getChemicalReactionOperations().solveChemEq(1, 1); + } - system.init(0); - system.init(1); + // Calculates phase fractions and initial composition based on Wilson K-factors + try { + system.calcBeta(); + } catch (Exception e) { + logger.error("error", e); + } + system.calc_x_y(); + system.init(1); + // If phase fraction using Wilson K factor returns pure gas or pure liquid, we + // try with another K value guess based on calculated fugacities. + // This solves some problems when we have high volumes of water and heavy + // hydrocarbons returning only one liquid phase (and this phase desolves all + // gas) + if (system.getBeta() > (1.0 - betaTolerance * 1.1) + || system.getBeta() < (betaTolerance * 1.1)) { + system.setBeta(0.5); + sucsSubs(); + } - if (system.getPhase(0).getGibbsEnergy() < system.getPhase(1).getGibbsEnergy()) { - minimumGibbsEnergy = system.getPhase(0).getGibbsEnergy(); - } else { - minGibbsPhase = 1; - minimumGibbsEnergy = system.getPhase(1).getGibbsEnergy(); + // Performs three iterations of successive substitution + for (int k = 0; k < 3; k++) { + if (system.getBeta() < (1.0 - betaTolerance * 1.1) + && system.getBeta() > (betaTolerance * 1.1)) { + sucsSubs(); + if ((system.getGibbsEnergy() - minimumGibbsEnergy) + / Math.abs(minimumGibbsEnergy) < -1e-12) { + break; } + } + } - if (system.getPhase(0).getNumberOfComponents() == 1 || system.getMaxNumberOfPhases() == 1) { - system.setNumberOfPhases(1); - if (minGibbsPhase == 0) { - system.setPhaseIndex(0, 0); - } else { - system.setPhaseIndex(0, 1); - } - if (solidCheck) { - ThermodynamicOperations operation = new ThermodynamicOperations(system); - operation.TPSolidflash(); - } - return; + // System.out.println("beta " + system.getBeta()); + + int totiter = 0; + double tpdx = 1.0; + double tpdy = 1.0; + double dgonRT = 1.0; + boolean passedTests = false; + if (system.getBeta() > (1.0 - 1.1 * betaTolerance) + || system.getBeta() < (1.1 * betaTolerance)) { + tpdx = 1.0; + tpdy = 1.0; + dgonRT = 1.0; + } else if (system.getGibbsEnergy() < (minimumGibbsEnergy * (1.0 - 1.0e-12))) { + tpdx = -1.0; + tpdy = -1.0; + dgonRT = -1.0; + } else { + for (i = 0; i < system.getPhases()[0].getNumberOfComponents(); i++) { + tpdy += system.getPhase(0).getComponent(i).getx() + * (Math.log(system.getPhase(0).getComponent(i).getFugacityCoefficient()) + + Math.log(system.getPhase(0).getComponents()[i].getx()) - minGibsPhaseLogZ[i] + - minGibsLogFugCoef[i]); + tpdx += system.getPhase(1).getComponent(i).getx() + * (Math.log(system.getPhase(1).getComponent(i).getFugacityCoefficient()) + + Math.log(system.getPhase(1).getComponents()[i].getx()) - minGibsPhaseLogZ[i] + - minGibsLogFugCoef[i]); + } + + dgonRT = system.getPhase(0).getBeta() * tpdy + (1.0 - system.getPhase(0).getBeta()) * tpdx; + + if (dgonRT > 0) { + if (tpdx < 0) { + for (i = 0; i < system.getPhases()[0].getNumberOfComponents(); i++) { + system.getPhase(0).getComponent(i) + .setK(Math.exp(Math.log(system.getPhase(1).getComponent(i).getFugacityCoefficient()) + - minGibsLogFugCoef[i]) * presdiff); + system.getPhase(1).getComponent(i).setK(system.getPhase(0).getComponent(i).getK()); + } + } else if (tpdy < 0) { + for (i = 0; i < system.getPhase(0).getNumberOfComponents(); i++) { + system.getPhase(0).getComponents()[i].setK(Math + .exp(minGibsLogFugCoef[i] + - Math.log(system.getPhase(0).getComponent(i).getFugacityCoefficient())) + * presdiff); + system.getPhase(1).getComponent(i).setK(system.getPhase(0).getComponent(i).getK()); + } + } else { + passedTests = true; } + } + } - minGibsPhaseLogZ = new double[system.getPhase(0).getNumberOfComponents()]; - minGibsLogFugCoef = new double[system.getPhase(0).getNumberOfComponents()]; + if (passedTests || (dgonRT > 0 && tpdx > 0 && tpdy > 0) || Double.isNaN(system.getBeta())) { + if (system.checkStability()) { + if (stabilityCheck()) { + if (system.doMultiPhaseCheck()) { + // logger.info("one phase flash is stable - checking multiphase flash.... + // "); + TPmultiflash operation = new TPmultiflash(system, true); + operation.run(); + // commented out by Even Solbraa 6/2-2012k + // system.orderByDensity(); + // system.init(3); + } + if (solidCheck) { + this.solidPhaseFlash(); + } + if (system.isMultiphaseWaxCheck()) { + TPmultiflashWAX operation = new TPmultiflashWAX(system, true); + operation.run(); + } - for (int i = 0; i < system.getPhase(0).getNumberOfComponents(); i++) { - minGibsPhaseLogZ[i] = Math.log(system.getPhase(minGibbsPhase).getComponent(i).getz()); - minGibsLogFugCoef[i] = - system.getPhase(minGibbsPhase).getComponent(i).getLogFugacityCoefficient(); + system.orderByDensity(); + system.init(1); + return; } + } + } - presdiff = system.getPhase(1).getPressure() / system.getPhase(0).getPressure(); - if (Math.abs(system.getPhase(0).getPressure() - system.getPhase(1).getPressure()) > 1e-12) { - for (i = 0; i < system.getPhase(0).getNumberOfComponents(); i++) { - system.getPhase(0).getComponent(i) - .setK(system.getPhase(0).getComponent(i).getK() * presdiff); - system.getPhase(1).getComponent(i).setK(system.getPhase(0).getComponent(i).getK()); - } - } + setNewK(); - if (system.isChemicalSystem()) { - system.getChemicalReactionOperations().solveChemEq(1, 0); - system.getChemicalReactionOperations().solveChemEq(1, 1); - } + gibbsEnergy = system.getGibbsEnergy(); + gibbsEnergyOld = gibbsEnergy; - // Calculates phase fractions and initial composition based on Wilson K-factors - try { - system.calcBeta(); - } catch (Exception e) { - logger.error("error", e); - } - system.calc_x_y(); - system.init(1); - // If phase fraction using Wilson K factor returns pure gas or pure liquid, we - // try with another K value guess based on calculated fugacities. - // This solves some problems when we have high volumes of water and heavy - // hydrocarbons returning only one liquid phase (and this phase desolves all - // gas) - if (system.getBeta() > (1.0 - betaTolerance * 1.1) - || system.getBeta() < (betaTolerance * 1.1)) { - system.setBeta(0.5); - sucsSubs(); - } - - // Performs three iterations of successive substitution - for (int k = 0; k < 3; k++) { - if (system.getBeta() < (1.0 - betaTolerance * 1.1) - && system.getBeta() > (betaTolerance * 1.1)) { - sucsSubs(); - if ((system.getGibbsEnergy() - minimumGibbsEnergy) - / Math.abs(minimumGibbsEnergy) < -1e-12) { - break; - } - } - } + // Checks if gas or oil is the most stable phase + double gasgib = system.getPhase(0).getGibbsEnergy(); + system.setPhaseType(0, 0); + system.init(1, 0); + double liqgib = system.getPhase(0).getGibbsEnergy(); - // System.out.println("beta " + system.getBeta()); - - int totiter = 0; - double tpdx = 1.0; - double tpdy = 1.0; - double dgonRT = 1.0; - boolean passedTests = false; - if (system.getBeta() > (1.0 - 1.1 * betaTolerance) - || system.getBeta() < (1.1 * betaTolerance)) { - tpdx = 1.0; - tpdy = 1.0; - dgonRT = 1.0; - } else if (system.getGibbsEnergy() < (minimumGibbsEnergy * (1.0 - 1.0e-12))) { - tpdx = -1.0; - tpdy = -1.0; - dgonRT = -1.0; + if (gasgib * (1.0 - Math.signum(gasgib) * 1e-8) < liqgib) { + system.setPhaseType(0, 1); + } + system.init(1); + + int accelerateInterval = 7; + int newtonLimit = 20; + int timeFromLastGibbsFail = 0; + + double chemdev = 0, oldChemDiff = 1.0, diffChem = 1.0; + do { + iterations = 0; + do { + iterations++; + + if (iterations < newtonLimit || system.isChemicalSystem() + || !system.isImplementedCompositionDeriativesofFugacity()) { + if (timeFromLastGibbsFail > 6 && (iterations % accelerateInterval) == 0 + && !(system.isChemicalSystem() || system.doSolidPhaseCheck())) { + accselerateSucsSubs(); + } else { + sucsSubs(); + } + } else if (iterations >= newtonLimit && Math + .abs(system.getPhase(0).getPressure() - system.getPhase(1).getPressure()) < 1e-5) { + if (iterations == newtonLimit) { + secondOrderSolver = new sysNewtonRhapsonTPflash(system, 2, + system.getPhases()[0].getNumberOfComponents()); + } + try { + deviation = secondOrderSolver.solve(); + } catch (Exception e) { + sucsSubs(); + } } else { - for (i = 0; i < system.getPhases()[0].getNumberOfComponents(); i++) { - tpdy += system.getPhase(0).getComponent(i).getx() - * (Math.log(system.getPhase(0).getComponent(i).getFugacityCoefficient()) - + Math.log(system.getPhase(0).getComponents()[i].getx()) - - minGibsPhaseLogZ[i] - minGibsLogFugCoef[i]); - tpdx += system.getPhase(1).getComponent(i).getx() - * (Math.log(system.getPhase(1).getComponent(i).getFugacityCoefficient()) - + Math.log(system.getPhase(1).getComponents()[i].getx()) - - minGibsPhaseLogZ[i] - minGibsLogFugCoef[i]); - } - - dgonRT = system.getPhase(0).getBeta() * tpdy - + (1.0 - system.getPhase(0).getBeta()) * tpdx; - - if (dgonRT > 0) { - if (tpdx < 0) { - for (i = 0; i < system.getPhases()[0].getNumberOfComponents(); i++) { - system.getPhase(0).getComponent(i) - .setK(Math.exp(Math.log( - system.getPhase(1).getComponent(i).getFugacityCoefficient()) - - minGibsLogFugCoef[i]) * presdiff); - system.getPhase(1).getComponent(i) - .setK(system.getPhase(0).getComponent(i).getK()); - } - } else if (tpdy < 0) { - for (i = 0; i < system.getPhase(0).getNumberOfComponents(); i++) { - system.getPhase(0).getComponents()[i] - .setK(Math - .exp(minGibsLogFugCoef[i] - Math.log(system.getPhase(0) - .getComponent(i).getFugacityCoefficient())) - * presdiff); - system.getPhase(1).getComponent(i) - .setK(system.getPhase(0).getComponent(i).getK()); - } - } else { - passedTests = true; - } - } - } - - if (passedTests || (dgonRT > 0 && tpdx > 0 && tpdy > 0) || Double.isNaN(system.getBeta())) { - if (system.checkStability()) { - if (stabilityCheck()) { - if (system.doMultiPhaseCheck()) { - // logger.info("one phase flash is stable - checking multiphase flash.... - // "); - TPmultiflash operation = new TPmultiflash(system, true); - operation.run(); - // commented out by Even Solbraa 6/2-2012k - // system.orderByDensity(); - // system.init(3); - } - if (solidCheck) { - this.solidPhaseFlash(); - } - if (system.isMultiphaseWaxCheck()) { - TPmultiflashWAX operation = new TPmultiflashWAX(system, true); - operation.run(); - } - - system.orderByDensity(); - system.init(1); - return; - } - } + sucsSubs(); } - setNewK(); - - gibbsEnergy = system.getGibbsEnergy(); gibbsEnergyOld = gibbsEnergy; + gibbsEnergy = system.getGibbsEnergy(); - // Checks if gas or oil is the most stable phase - double gasgib = system.getPhase(0).getGibbsEnergy(); - system.setPhaseType(0, 0); - system.init(1, 0); - double liqgib = system.getPhase(0).getGibbsEnergy(); - - if (gasgib * (1.0 - Math.signum(gasgib) * 1e-8) < liqgib) { - system.setPhaseType(0, 1); - } - system.init(1); - - int accelerateInterval = 7; - int newtonLimit = 20; - int timeFromLastGibbsFail = 0; - - double chemdev = 0, oldChemDiff = 1.0, diffChem = 1.0; - do { - iterations = 0; - do { - iterations++; - - if (iterations < newtonLimit || system.isChemicalSystem() - || !system.isImplementedCompositionDeriativesofFugacity()) { - if (timeFromLastGibbsFail > 6 && (iterations % accelerateInterval) == 0 - && !(system.isChemicalSystem() || system.doSolidPhaseCheck())) { - accselerateSucsSubs(); - } else { - sucsSubs(); - } - } else if (iterations >= newtonLimit && Math.abs(system.getPhase(0).getPressure() - - system.getPhase(1).getPressure()) < 1e-5) { - if (iterations == newtonLimit) { - secondOrderSolver = new sysNewtonRhapsonTPflash(system, 2, - system.getPhases()[0].getNumberOfComponents()); - } - try { - deviation = secondOrderSolver.solve(); - } catch (Exception e) { - sucsSubs(); - } - } else { - sucsSubs(); - } - - gibbsEnergyOld = gibbsEnergy; - gibbsEnergy = system.getGibbsEnergy(); - - if ((gibbsEnergy - gibbsEnergyOld) / Math.abs(gibbsEnergyOld) > 1e-3 - && !system.isChemicalSystem()) { - resetK(); - timeFromLastGibbsFail = 0; - // logger.info("gibbs decrease " + (gibbsEnergy - gibbsEnergyOld) / - // Math.abs(gibbsEnergyOld)); - // setNewK(); - // logger.info("reset K.."); - } else { - timeFromLastGibbsFail++; - setNewK(); - } - // logger.info("iterations " + iterations + " error " + deviation); - } while ((deviation > 1e-10) && (iterations < maxNumberOfIterations)); - // logger.info("iterations " + iterations + " error " + deviation); - if (system.isChemicalSystem()) { - oldChemDiff = chemdev; - chemdev = 0.0; - - double xchem[] = new double[system.getPhase(0).getNumberOfComponents()]; - - for (int phase = 1; phase < system.getNumberOfPhases(); phase++) { - for (i = 0; i < system.getPhases()[phase].getNumberOfComponents(); i++) { - xchem[i] = system.getPhase(phase).getComponent(i).getx(); - } - - system.init(1); - system.getChemicalReactionOperations().solveChemEq(phase, 1); - - for (i = 0; i < system.getPhases()[phase].getNumberOfComponents(); i++) { - chemdev += - Math.abs(xchem[i] - system.getPhase(phase).getComponent(i).getx()) - / xchem[i]; - } - } - diffChem = Math.abs(oldChemDiff - chemdev); - } - // logger.info("chemdev: " + chemdev + " iter: " + totiter); - totiter++; - } while ((diffChem > 1e-6 && chemdev > 1e-6 && totiter < 300) - || (system.isChemicalSystem() && totiter < 2)); - if (system.isChemicalSystem()) { - sucsSubs(); - } - - // Checks if gas or oil is the most stable phase - if (system.getPhase(0).getPhaseType() == 1) { - gasgib = system.getPhase(0).getGibbsEnergy(); - system.setPhaseType(0, 0); - system.init(1, 0); - liqgib = system.getPhase(0).getGibbsEnergy(); + if ((gibbsEnergy - gibbsEnergyOld) / Math.abs(gibbsEnergyOld) > 1e-3 + && !system.isChemicalSystem() && timeFromLastGibbsFail>0) { + resetK(); + timeFromLastGibbsFail = 0; + // logger.info("gibbs decrease " + (gibbsEnergy - gibbsEnergyOld) / + // Math.abs(gibbsEnergyOld)); + // setNewK(); + // logger.info("reset K.."); } else { - liqgib = system.getPhase(0).getGibbsEnergy(); - system.setPhaseType(0, 1); - system.init(1, 0); - gasgib = system.getPhase(0).getGibbsEnergy(); + timeFromLastGibbsFail++; + setNewK(); } - - if (gasgib * (1.0 - Math.signum(gasgib) * 1e-8) < liqgib) { - system.setPhaseType(0, 1); + // logger.info("iterations " + iterations + " error " + deviation); + } while ((deviation > 1e-10) && (iterations < maxNumberOfIterations)); + // logger.info("iterations " + iterations + " error " + deviation); + if (system.isChemicalSystem()) { + oldChemDiff = chemdev; + chemdev = 0.0; + + double xchem[] = new double[system.getPhase(0).getNumberOfComponents()]; + + for (int phase = 1; phase < system.getNumberOfPhases(); phase++) { + for (i = 0; i < system.getPhases()[phase].getNumberOfComponents(); i++) { + xchem[i] = system.getPhase(phase).getComponent(i).getx(); + } + + system.init(1); + system.getChemicalReactionOperations().solveChemEq(phase, 1); + + for (i = 0; i < system.getPhases()[phase].getNumberOfComponents(); i++) { + chemdev += + Math.abs(xchem[i] - system.getPhase(phase).getComponent(i).getx()) / xchem[i]; + } } + diffChem = Math.abs(oldChemDiff - chemdev); + } + // logger.info("chemdev: " + chemdev + " iter: " + totiter); + totiter++; + } while ((diffChem > 1e-6 && chemdev > 1e-6 && totiter < 300) + || (system.isChemicalSystem() && totiter < 2)); + if (system.isChemicalSystem()) { + sucsSubs(); + } + if (system.doMultiPhaseCheck()) { + TPmultiflash operation = new TPmultiflash(system, true); + operation.run(); + } else { + // Checks if gas or oil is the most stable phase + if (system.getPhase(0).getPhaseType() == 1) { + gasgib = system.getPhase(0).getGibbsEnergy(); + system.setPhaseType(0, 0); + system.init(1, 0); + liqgib = system.getPhase(0).getGibbsEnergy(); + } else { + liqgib = system.getPhase(0).getGibbsEnergy(); + system.setPhaseType(0, 1); + system.init(1, 0); + gasgib = system.getPhase(0).getGibbsEnergy(); + } - system.init(1); + if (gasgib * (1.0 - Math.signum(gasgib) * 1e-8) < liqgib) { + system.setPhaseType(0, 1); + } - if (system.doMultiPhaseCheck()) { - TPmultiflash operation = new TPmultiflash(system, true); - operation.run(); - } - if (solidCheck) { - this.solidPhaseFlash(); - } - if (system.isMultiphaseWaxCheck()) { - TPmultiflashWAX operation = new TPmultiflashWAX(system, true); - operation.run(); - } + system.init(1); + } - for (int i = 0; i < system.getNumberOfPhases(); i++) { - if (system.getBeta(i) < betaTolerance * 1.01) { - system.removePhase(i); - } - } - // system.initPhysicalProperties("density"); - system.orderByDensity(); - system.init(1); + if (solidCheck) { + this.solidPhaseFlash(); + } + if (system.isMultiphaseWaxCheck()) { + TPmultiflashWAX operation = new TPmultiflashWAX(system, true); + operation.run(); } - /** {@inheritDoc} */ - @Override - public org.jfree.chart.JFreeChart getJFreeChart(String name) { - return null; + for (int i = 0; i < system.getNumberOfPhases(); i++) { + if (system.getBeta(i) < betaTolerance * 1.01) { + system.removePhase(i); + } } + // system.initPhysicalProperties("density"); + system.orderByDensity(); + system.init(1); + } + + /** {@inheritDoc} */ + @Override + public org.jfree.chart.JFreeChart getJFreeChart(String name) { + return null; + } } diff --git a/src/main/java/neqsim/thermodynamicOperations/flashOps/TVflash.java b/src/main/java/neqsim/thermodynamicOperations/flashOps/TVflash.java index 2499384fcb..556d816f73 100644 --- a/src/main/java/neqsim/thermodynamicOperations/flashOps/TVflash.java +++ b/src/main/java/neqsim/thermodynamicOperations/flashOps/TVflash.java @@ -90,9 +90,7 @@ public double solveQ() { } system.setPressure(nyPres); tpFlash.run(); - // System.out.println(" dQdv " + calcdQdV() + " new pressure " + nyPres + " - // error " + Math.abs((nyPres-oldPres)/(nyPres)) + " - // numberofphases"+system.getNumberOfPhases()); + // System.out.println(" dQdv " + calcdQdV() + " new pressure " + nyPres + " error " + Math.abs((nyPres-oldPres)/(nyPres)) + " numberofphases "+system.getNumberOfPhases()); } while (Math.abs((nyPres - oldPres) / (nyPres)) > 1e-9 && iterations < 1000 || iterations < 3); return nyPres; diff --git a/src/main/java/neqsim/thermodynamicOperations/flashOps/saturationOps/constantDutyFlash.java b/src/main/java/neqsim/thermodynamicOperations/flashOps/saturationOps/constantDutyFlash.java index f3a72e893e..07672189be 100644 --- a/src/main/java/neqsim/thermodynamicOperations/flashOps/saturationOps/constantDutyFlash.java +++ b/src/main/java/neqsim/thermodynamicOperations/flashOps/saturationOps/constantDutyFlash.java @@ -13,145 +13,138 @@ * @version $Id: $Id */ public abstract class constantDutyFlash implements constantDutyFlashInterface { - private static final long serialVersionUID = 1000; - static Logger logger = LogManager.getLogger(constantDutyFlash.class); - - SystemInterface system; - protected boolean superCritical = false; - int i, j = 0, nummer = 0, iterations = 0, maxNumberOfIterations = 10000; - double gibbsEnergy = 0, gibbsEnergyOld = 0; - double Kold, deviation = 0, g0 = 0, g1 = 0; - double lnOldOldK[], lnK[]; - double lnOldK[]; - double oldDeltalnK[], deltalnK[]; - double tm[] = {1, 1}; - double beta = 1e-5; - int lowestGibbsEnergyPhase = 0; // lowestGibbsEnergyPhase - - /** - *

- * Constructor for constantDutyFlash. - *

- */ - public constantDutyFlash() {} - - /** - *

- * Constructor for constantDutyFlash. - *

- * - * @param system a {@link neqsim.thermo.system.SystemInterface} object - */ - public constantDutyFlash(SystemInterface system) { - this.system = system; - lnOldOldK = new double[system.getPhases()[0].getNumberOfComponents()]; - lnOldK = new double[system.getPhases()[0].getNumberOfComponents()]; - lnK = new double[system.getPhases()[0].getNumberOfComponents()]; - oldDeltalnK = new double[system.getPhases()[0].getNumberOfComponents()]; - deltalnK = new double[system.getPhases()[0].getNumberOfComponents()]; - } - - /** {@inheritDoc} */ - @Override - public void setBeta(double beta) { - this.beta = beta; - } - - /** {@inheritDoc} */ - @Override - public void run() { - system.init(0); - system.init(2); - - // int iterations = 0, maxNumberOfIterations = 10000; - // double yold = 0, ytotal = 1; - double deriv = 0, funk = 0, dkidt = 0, dyidt = 0, dxidt = 0, Told = 0; - - do { - // system.setBeta(beta+0.65); - system.init(2); - - for (int i = 0; i < system.getPhases()[0].getNumberOfComponents(); i++) { - system.getPhases()[0].getComponents()[i] - .setK(system.getPhases()[0].getComponents()[i].getFugacityCoefficient() - / system.getPhases()[1].getComponents()[i] - .getFugacityCoefficient()); - system.getPhases()[1].getComponents()[i] - .setK(system.getPhases()[0].getComponents()[i].getFugacityCoefficient() - / system.getPhases()[1].getComponents()[i] - .getFugacityCoefficient()); - } - - system.calc_x_y(); - - funk = 0e0; - deriv = 0e0; - - for (int i = 0; i < system.getPhases()[0].getNumberOfComponents(); i++) { - dkidt = (system.getPhases()[0].getComponents()[i].getdfugdt() - - system.getPhases()[1].getComponents()[i].getdfugdt()) - * system.getPhases()[0].getComponents()[i].getK(); - dxidt = -system.getPhases()[0].getComponents()[i].getx() - * system.getPhases()[0].getComponents()[i].getx() * 1.0 - / system.getPhases()[0].getComponents()[i].getz() * system.getBeta() - * dkidt; - dyidt = dkidt * system.getPhases()[0].getComponents()[i].getx() - + system.getPhases()[0].getComponents()[i].getK() * dxidt; - funk = funk + system.getPhases()[1].getComponents()[i].getx() - - system.getPhases()[0].getComponents()[i].getx(); - deriv = deriv + dyidt - dxidt; - } - - Told = system.getTemperature(); - system.setTemperature((Told - funk / deriv * 0.9)); - logger.info("Temp: " + system.getTemperature()); - } while (Math.abs((system.getTemperature() - Told) / system.getTemperature()) > 1e-7); - } - - /** {@inheritDoc} */ - @Override - public void createNetCdfFile(String name) {} - - /** {@inheritDoc} */ - @Override - public double[][] getPoints(int i) { - return null; - } - - /** {@inheritDoc} */ - @Override - public double[] get(String name) { - return null; - } - - /** {@inheritDoc} */ - @Override - public void displayResult() { - system.display(); - } - - /** {@inheritDoc} */ - @Override - public boolean isSuperCritical() { - return superCritical; - } - - /** - * Setter for property superCritical. - * - * @param superCritical New value of property superCritical. - */ - public void setSuperCritical(boolean superCritical) { - this.superCritical = superCritical; - } - - /** {@inheritDoc} */ - @Override - public String[][] getResultTable() { - return null; - } - - /** {@inheritDoc} */ - @Override - public void addData(String name, double[][] data) {} + private static final long serialVersionUID = 1000; + static Logger logger = LogManager.getLogger(constantDutyFlash.class); + + SystemInterface system; + protected boolean superCritical = false; + int i, j = 0, nummer = 0, iterations = 0, maxNumberOfIterations = 10000; + double gibbsEnergy = 0, gibbsEnergyOld = 0; + double Kold, deviation = 0, g0 = 0, g1 = 0; + double lnOldOldK[], lnK[]; + double lnOldK[]; + double oldDeltalnK[], deltalnK[]; + double tm[] = {1, 1}; + double beta = 1e-5; + int lowestGibbsEnergyPhase = 0; // lowestGibbsEnergyPhase + + /** + *

+ * Constructor for constantDutyFlash. + *

+ */ + public constantDutyFlash() {} + + /** + *

+ * Constructor for constantDutyFlash. + *

+ * + * @param system a {@link neqsim.thermo.system.SystemInterface} object + */ + public constantDutyFlash(SystemInterface system) { + this.system = system; + lnOldOldK = new double[system.getPhases()[0].getNumberOfComponents()]; + lnOldK = new double[system.getPhases()[0].getNumberOfComponents()]; + lnK = new double[system.getPhases()[0].getNumberOfComponents()]; + oldDeltalnK = new double[system.getPhases()[0].getNumberOfComponents()]; + deltalnK = new double[system.getPhases()[0].getNumberOfComponents()]; + } + + /** {@inheritDoc} */ + @Override + public void setBeta(double beta) { + this.beta = beta; + } + + /** {@inheritDoc} */ + @Override + public void run() { + system.init(0); + system.init(2); + + // int iterations = 0, maxNumberOfIterations = 10000; + // double yold = 0, ytotal = 1; + double deriv = 0, funk = 0, dkidt = 0, dyidt = 0, dxidt = 0, Told = 0; + + do { + // system.setBeta(beta+0.65); + system.init(2); + + for (int i = 0; i < system.getPhases()[0].getNumberOfComponents(); i++) { + system.getPhases()[0].getComponents()[i] + .setK(system.getPhases()[0].getComponents()[i].getFugacityCoefficient() + / system.getPhases()[1].getComponents()[i].getFugacityCoefficient()); + system.getPhases()[1].getComponents()[i] + .setK(system.getPhases()[0].getComponents()[i].getFugacityCoefficient() + / system.getPhases()[1].getComponents()[i].getFugacityCoefficient()); + } + + system.calc_x_y(); + + funk = 0e0; + deriv = 0e0; + + for (int i = 0; i < system.getPhases()[0].getNumberOfComponents(); i++) { + dkidt = (system.getPhases()[0].getComponents()[i].getdfugdt() + - system.getPhases()[1].getComponents()[i].getdfugdt()) + * system.getPhases()[0].getComponents()[i].getK(); + dxidt = -system.getPhases()[0].getComponents()[i].getx() + * system.getPhases()[0].getComponents()[i].getx() * 1.0 + / system.getPhases()[0].getComponents()[i].getz() * system.getBeta() * dkidt; + dyidt = dkidt * system.getPhases()[0].getComponents()[i].getx() + + system.getPhases()[0].getComponents()[i].getK() * dxidt; + funk = funk + system.getPhases()[1].getComponents()[i].getx() + - system.getPhases()[0].getComponents()[i].getx(); + deriv = deriv + dyidt - dxidt; + } + + Told = system.getTemperature(); + system.setTemperature((Told - funk / deriv * 0.9)); + logger.info("Temp: " + system.getTemperature()); + } while (Math.abs((system.getTemperature() - Told) / system.getTemperature()) > 1e-7); + } + + /** {@inheritDoc} */ + @Override + public double[][] getPoints(int i) { + return null; + } + + /** {@inheritDoc} */ + @Override + public double[] get(String name) { + return null; + } + + /** {@inheritDoc} */ + @Override + public void displayResult() { + system.display(); + } + + /** {@inheritDoc} */ + @Override + public boolean isSuperCritical() { + return superCritical; + } + + /** + * Setter for property superCritical. + * + * @param superCritical New value of property superCritical. + */ + public void setSuperCritical(boolean superCritical) { + this.superCritical = superCritical; + } + + /** {@inheritDoc} */ + @Override + public String[][] getResultTable() { + return null; + } + + /** {@inheritDoc} */ + @Override + public void addData(String name, double[][] data) {} } diff --git a/src/main/java/neqsim/thermodynamicOperations/flashOps/saturationOps/cricondenBarTemp1.java b/src/main/java/neqsim/thermodynamicOperations/flashOps/saturationOps/cricondenBarTemp1.java index da1d4a17e1..8569a03781 100644 --- a/src/main/java/neqsim/thermodynamicOperations/flashOps/saturationOps/cricondenBarTemp1.java +++ b/src/main/java/neqsim/thermodynamicOperations/flashOps/saturationOps/cricondenBarTemp1.java @@ -236,15 +236,6 @@ public String[][] getResultTable() { return null; } - /** - *

- * createNetCdfFile. - *

- * - * @param name a {@link java.lang.String} object - */ - public void createNetCdfFile(String name) {} - /** *

* getThermoSystem. diff --git a/src/main/java/neqsim/thermodynamicOperations/phaseEnvelopeOps/multicomponentEnvelopeOps/HPTphaseEnvelope.java b/src/main/java/neqsim/thermodynamicOperations/phaseEnvelopeOps/multicomponentEnvelopeOps/HPTphaseEnvelope.java index a59ad23d66..bc8cf04432 100644 --- a/src/main/java/neqsim/thermodynamicOperations/phaseEnvelopeOps/multicomponentEnvelopeOps/HPTphaseEnvelope.java +++ b/src/main/java/neqsim/thermodynamicOperations/phaseEnvelopeOps/multicomponentEnvelopeOps/HPTphaseEnvelope.java @@ -11,7 +11,6 @@ import javax.swing.JProgressBar; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; -import neqsim.dataPresentation.visAD.visAd3D.visAd3DPlot; import neqsim.thermo.system.SystemInterface; import neqsim.thermodynamicOperations.BaseOperation; import neqsim.thermodynamicOperations.ThermodynamicOperations; @@ -25,108 +24,100 @@ * @version $Id: $Id */ public class HPTphaseEnvelope extends BaseOperation { - private static final long serialVersionUID = 1000; + private static final long serialVersionUID = 1000; - double[][] points = new double[10][10]; - SystemInterface system; - ThermodynamicOperations testOps; - JProgressBar monitor; - JFrame mainFrame; - JPanel mainPanel; - double startPressure = 1, endPressure = 0, startTemperature = 160, endTemperature = 0; - static Logger logger = LogManager.getLogger(HPTphaseEnvelope.class); + double[][] points = new double[10][10]; + SystemInterface system; + ThermodynamicOperations testOps; + JProgressBar monitor; + JFrame mainFrame; + JPanel mainPanel; + double startPressure = 1, endPressure = 0, startTemperature = 160, endTemperature = 0; + static Logger logger = LogManager.getLogger(HPTphaseEnvelope.class); - /** - *

- * Constructor for HPTphaseEnvelope. - *

- */ - public HPTphaseEnvelope() {} + /** + *

+ * Constructor for HPTphaseEnvelope. + *

+ */ + public HPTphaseEnvelope() {} - /** - *

- * Constructor for HPTphaseEnvelope. - *

- * - * @param system a {@link neqsim.thermo.system.SystemInterface} object - */ - public HPTphaseEnvelope(SystemInterface system) { - testOps = new ThermodynamicOperations(system); - this.system = system; - mainFrame = new JFrame("Progress Bar"); - mainPanel = new JPanel(); - mainPanel.setSize(200, 100); - mainFrame.getContentPane().setLayout(new FlowLayout()); - mainPanel.setLayout(new FlowLayout()); - mainFrame.setSize(200, 100); - monitor = new JProgressBar(0, 1000); - monitor.setSize(200, 100); - monitor.setStringPainted(true); - mainPanel.add(monitor); - mainFrame.getContentPane().add(mainPanel); - mainFrame.setVisible(true); - } + /** + *

+ * Constructor for HPTphaseEnvelope. + *

+ * + * @param system a {@link neqsim.thermo.system.SystemInterface} object + */ + public HPTphaseEnvelope(SystemInterface system) { + testOps = new ThermodynamicOperations(system); + this.system = system; + mainFrame = new JFrame("Progress Bar"); + mainPanel = new JPanel(); + mainPanel.setSize(200, 100); + mainFrame.getContentPane().setLayout(new FlowLayout()); + mainPanel.setLayout(new FlowLayout()); + mainFrame.setSize(200, 100); + monitor = new JProgressBar(0, 1000); + monitor.setSize(200, 100); + monitor.setStringPainted(true); + mainPanel.add(monitor); + mainFrame.getContentPane().add(mainPanel); + mainFrame.setVisible(true); + } - /** {@inheritDoc} */ - @Override - public void run() { - int np = 0; + /** {@inheritDoc} */ + @Override + public void run() { + int np = 0; - for (int i = 0; i < 10; i++) { - system.setPressure(i * 0.5 + startPressure); - for (int j = 0; j < 10; j++) { - np++; - if (np % 2 == 0) { - monitor.setValue(np); - monitor.setString("Calculated points: " + np); - } - - system.setTemperature(startTemperature + j); - testOps.TPflash(); - system.init(3); - points[i][j] = system.getEnthalpy(); - } + for (int i = 0; i < 10; i++) { + system.setPressure(i * 0.5 + startPressure); + for (int j = 0; j < 10; j++) { + np++; + if (np % 2 == 0) { + monitor.setValue(np); + monitor.setString("Calculated points: " + np); } - } - /** {@inheritDoc} */ - @Override - public void displayResult() { - try { - mainFrame.setVisible(false); - visAd3DPlot plot = - new visAd3DPlot("pressure[bar]", "temperature[K]", "enthalpy[J/mol]"); - plot.setXYvals(150, 160, 10, 10, 20, 10); - plot.setZvals(points); - plot.init(); - } catch (Exception e) { - logger.error("plotting failed"); - } + system.setTemperature(startTemperature + j); + testOps.TPflash(); + system.init(3); + points[i][j] = system.getEnthalpy(); + } } + } - /** {@inheritDoc} */ - @Override - public void printToFile(String name) {} + /** {@inheritDoc} */ + @Override + public void displayResult() { + /* + * try { mainFrame.setVisible(false); visAd3DPlot plot = new visAd3DPlot("pressure[bar]", + * "temperature[K]", "enthalpy[J/mol]"); plot.setXYvals(150, 160, 10, 10, 20, 10); + * plot.setZvals(points); plot.init(); } catch (Exception e) { logger.error("plotting failed"); + * } + */ + } - /** {@inheritDoc} */ - @Override - public double[][] getPoints(int i) { - return points; - } + /** {@inheritDoc} */ + @Override + public void printToFile(String name) {} - /** {@inheritDoc} */ - @Override - public void createNetCdfFile(String name) {} + /** {@inheritDoc} */ + @Override + public double[][] getPoints(int i) { + return points; + } - /** {@inheritDoc} */ - @Override - public org.jfree.chart.JFreeChart getJFreeChart(String name) { - return null; - } + /** {@inheritDoc} */ + @Override + public org.jfree.chart.JFreeChart getJFreeChart(String name) { + return null; + } - /** {@inheritDoc} */ - @Override - public String[][] getResultTable() { - return null; - } + /** {@inheritDoc} */ + @Override + public String[][] getResultTable() { + return null; + } } diff --git a/src/main/java/neqsim/thermodynamicOperations/phaseEnvelopeOps/multicomponentEnvelopeOps/pTphaseEnvelope.java b/src/main/java/neqsim/thermodynamicOperations/phaseEnvelopeOps/multicomponentEnvelopeOps/pTphaseEnvelope.java index 0d3a5d9061..d6a116ea16 100644 --- a/src/main/java/neqsim/thermodynamicOperations/phaseEnvelopeOps/multicomponentEnvelopeOps/pTphaseEnvelope.java +++ b/src/main/java/neqsim/thermodynamicOperations/phaseEnvelopeOps/multicomponentEnvelopeOps/pTphaseEnvelope.java @@ -42,8 +42,6 @@ public class pTphaseEnvelope extends BaseOperation { double[] cricondenBarX = new double[100]; double[] cricondenBarY = new double[100]; double phaseFraction = 1e-10; - neqsim.dataPresentation.fileHandeling.createNetCDF.netCDF2D.NetCdf2D file1; - neqsim.dataPresentation.fileHandeling.createNetCDF.netCDF2D.NetCdf2D file2; int i, j = 0, nummer = 0, iterations = 0, maxNumberOfIterations = 10000; double gibbsEnergy = 0, gibbsEnergyOld = 0; double Kold, deviation = 0, g0 = 0, g1 = 0, lowPres = 1.0; @@ -493,7 +491,7 @@ public void run() { // double nef = 0.; // logger.error("error", e2); } - +/* try { if (outputToFile) { // update this @@ -517,6 +515,7 @@ public void run() { // double nef = 0.; logger.error("error", e3); } + */ } catch (Exception e4) { // double nef = 0.; logger.error("error", e4); @@ -723,12 +722,6 @@ public double[] get(String name) { } } - /** {@inheritDoc} */ - @Override - public void createNetCdfFile(String name) { - fileName = name; - } - /** * Getter for property bubblePointFirst. * diff --git a/src/main/java/neqsim/thermodynamicOperations/phaseEnvelopeOps/multicomponentEnvelopeOps/pTphaseEnvelope1.java b/src/main/java/neqsim/thermodynamicOperations/phaseEnvelopeOps/multicomponentEnvelopeOps/pTphaseEnvelope1.java index dace93335a..ce360ac5d3 100644 --- a/src/main/java/neqsim/thermodynamicOperations/phaseEnvelopeOps/multicomponentEnvelopeOps/pTphaseEnvelope1.java +++ b/src/main/java/neqsim/thermodynamicOperations/phaseEnvelopeOps/multicomponentEnvelopeOps/pTphaseEnvelope1.java @@ -21,460 +21,442 @@ * @version $Id: $Id */ public class pTphaseEnvelope1 extends BaseOperation { - private static final long serialVersionUID = 1000; - static Logger logger = LogManager.getLogger(pTphaseEnvelope1.class); - - graph2b graph2 = null; - SystemInterface system; - boolean bubblePointFirst = true; - double[] cricondenTherm = new double[3]; - double[] cricondenBar = new double[3]; - double phaseFraction = 1e-10; - neqsim.dataPresentation.fileHandeling.createNetCDF.netCDF2D.NetCdf2D file1; - neqsim.dataPresentation.fileHandeling.createNetCDF.netCDF2D.NetCdf2D file2; - int i, j = 0, nummer = 0, iterations = 0, maxNumberOfIterations = 10000; - double gibbsEnergy = 0, gibbsEnergyOld = 0; - double Kold, deviation = 0, g0 = 0, g1 = 0, lowPres = 1.0; - double lnOldOldK[], lnK[]; - boolean outputToFile = false; - double lnOldK[]; - double oldDeltalnK[], deltalnK[]; - double tm[] = {1, 1}; - double beta = 1e-5; - int lowestGibbsEnergyPhase = 0; // lowestGibbsEnergyPhase - JProgressBar monitor; - JFrame mainFrame; - String fileName = "c:/file"; - JPanel mainPanel; - double temp = 0, pres = 0, startPres = 0; - double[][] points = new double[2][]; - double[] pointsH; - double[][] pointsH2 = new double[4][]; - double[] pointsV; - double[][] pointsV2 = new double[4][]; - double[] pointsS; - double[][] pointsS2 = new double[4][]; - public double[][] points2 = new double[4][]; - double[][] points3 = new double[8][]; - boolean moreLines = false; - int np = 0; - // points[2] = new double[1000]; - int speceq = 0; - - /** - *

- * Constructor for pTphaseEnvelope1. - *

- */ - public pTphaseEnvelope1() {} - - /** - *

- * Constructor for pTphaseEnvelope1. - *

- * - * @param system a {@link neqsim.thermo.system.SystemInterface} object - * @param name a {@link java.lang.String} object - * @param phaseFraction a double - * @param lowPres a double - * @param bubfirst a boolean - */ - public pTphaseEnvelope1(SystemInterface system, String name, double phaseFraction, - double lowPres, boolean bubfirst) { - this.bubblePointFirst = bubfirst; - if (name != null) { - outputToFile = true; - fileName = name; - } - this.system = system; - this.phaseFraction = phaseFraction; - lnOldOldK = new double[system.getPhase(0).getNumberOfComponents()]; - lnOldK = new double[system.getPhase(0).getNumberOfComponents()]; - lnK = new double[system.getPhase(0).getNumberOfComponents()]; - this.lowPres = lowPres; - oldDeltalnK = new double[system.getPhase(0).getNumberOfComponents()]; - deltalnK = new double[system.getPhase(0).getNumberOfComponents()]; - mainFrame = new JFrame("Progress Bar"); - mainPanel = new JPanel(); - mainPanel.setSize(200, 100); - mainFrame.getContentPane().setLayout(new FlowLayout()); - mainPanel.setLayout(new FlowLayout()); - mainFrame.setSize(200, 100); - monitor = new JProgressBar(0, 00); - monitor.setSize(200, 100); - monitor.setStringPainted(true); - mainPanel.add(monitor); - mainFrame.getContentPane().add(mainPanel); - mainFrame.setVisible(true); + private static final long serialVersionUID = 1000; + static Logger logger = LogManager.getLogger(pTphaseEnvelope1.class); + + graph2b graph2 = null; + SystemInterface system; + boolean bubblePointFirst = true; + double[] cricondenTherm = new double[3]; + double[] cricondenBar = new double[3]; + double phaseFraction = 1e-10; + int i, j = 0, nummer = 0, iterations = 0, maxNumberOfIterations = 10000; + double gibbsEnergy = 0, gibbsEnergyOld = 0; + double Kold, deviation = 0, g0 = 0, g1 = 0, lowPres = 1.0; + double lnOldOldK[], lnK[]; + boolean outputToFile = false; + double lnOldK[]; + double oldDeltalnK[], deltalnK[]; + double tm[] = {1, 1}; + double beta = 1e-5; + int lowestGibbsEnergyPhase = 0; // lowestGibbsEnergyPhase + JProgressBar monitor; + JFrame mainFrame; + String fileName = "c:/file"; + JPanel mainPanel; + double temp = 0, pres = 0, startPres = 0; + double[][] points = new double[2][]; + double[] pointsH; + double[][] pointsH2 = new double[4][]; + double[] pointsV; + double[][] pointsV2 = new double[4][]; + double[] pointsS; + double[][] pointsS2 = new double[4][]; + public double[][] points2 = new double[4][]; + double[][] points3 = new double[8][]; + boolean moreLines = false; + int np = 0; + // points[2] = new double[1000]; + int speceq = 0; + + /** + *

+ * Constructor for pTphaseEnvelope1. + *

+ */ + public pTphaseEnvelope1() {} + + /** + *

+ * Constructor for pTphaseEnvelope1. + *

+ * + * @param system a {@link neqsim.thermo.system.SystemInterface} object + * @param name a {@link java.lang.String} object + * @param phaseFraction a double + * @param lowPres a double + * @param bubfirst a boolean + */ + public pTphaseEnvelope1(SystemInterface system, String name, double phaseFraction, double lowPres, + boolean bubfirst) { + this.bubblePointFirst = bubfirst; + if (name != null) { + outputToFile = true; + fileName = name; } + this.system = system; + this.phaseFraction = phaseFraction; + lnOldOldK = new double[system.getPhase(0).getNumberOfComponents()]; + lnOldK = new double[system.getPhase(0).getNumberOfComponents()]; + lnK = new double[system.getPhase(0).getNumberOfComponents()]; + this.lowPres = lowPres; + oldDeltalnK = new double[system.getPhase(0).getNumberOfComponents()]; + deltalnK = new double[system.getPhase(0).getNumberOfComponents()]; + mainFrame = new JFrame("Progress Bar"); + mainPanel = new JPanel(); + mainPanel.setSize(200, 100); + mainFrame.getContentPane().setLayout(new FlowLayout()); + mainPanel.setLayout(new FlowLayout()); + mainFrame.setSize(200, 100); + monitor = new JProgressBar(0, 00); + monitor.setSize(200, 100); + monitor.setStringPainted(true); + mainPanel.add(monitor); + mainFrame.getContentPane().add(mainPanel); + mainFrame.setVisible(true); + } + + /** {@inheritDoc} */ + @Override + public void run() { + try { + points[0] = new double[10000]; + points[1] = new double[10000]; + + pointsH = new double[10000]; + pointsV = new double[10000]; + pointsS = new double[10000]; + system.init(0); + for (int i = 0; i < system.getPhase(0).getNumberOfComponents(); i++) { + if (system.getPhase(0).getComponent(i).getIonicCharge() == 0) { + if (system.getPhase(0).getComponents()[i].getTC() < system.getPhase(0).getComponents()[i] + .getTC()) { + speceq = system.getPhase(0).getComponent(i).getComponentNumber(); + } + } + } + + pres = lowPres; + temp = system.getPhase(0).getComponent(speceq).getAntoineVaporTemperature(pres); + // temp = system.getTemperature(); + system.setPressure(pres); - /** {@inheritDoc} */ - @Override - public void run() { + system.setBeta(1e-10); + + ThermodynamicOperations testOps = new ThermodynamicOperations(system); + + system.init(0); + for (int i = 0; i < 1000; i++) { + temp += i * 4; + system.setTemperature(temp); try { - points[0] = new double[10000]; - points[1] = new double[10000]; - - pointsH = new double[10000]; - pointsV = new double[10000]; - pointsS = new double[10000]; - system.init(0); - for (int i = 0; i < system.getPhase(0).getNumberOfComponents(); i++) { - if (system.getPhase(0).getComponent(i).getIonicCharge() == 0) { - if (system.getPhase(0).getComponents()[i] - .getTC() < system.getPhase(0).getComponents()[i].getTC()) { - speceq = system.getPhase(0).getComponent(i).getComponentNumber(); - } - } - } - - pres = lowPres; - temp = system.getPhase(0).getComponent(speceq).getAntoineVaporTemperature(pres); - // temp = system.getTemperature(); - system.setPressure(pres); - - system.setBeta(1e-10); - - ThermodynamicOperations testOps = new ThermodynamicOperations(system); - - system.init(0); - for (int i = 0; i < 1000; i++) { - temp += i * 4; - system.setTemperature(temp); - try { - if (bubblePointFirst) { - testOps.bubblePointTemperatureFlash(); - } else { - testOps.dewPointTemperatureFlash(); - } - } catch (Exception e) { - e.toString(); - } - double tempNy = system.getTemperature(); - - if (!Double.isNaN(tempNy)) { - temp = tempNy; - break; - } - } - - system.setPressure(pres); - system.setTemperature(temp); - logger.info("temp: " + system.getTemperature()); - - system.setBeta(phaseFraction); - - sysNewtonRhapsonPhaseEnvelope nonLinSolver = new sysNewtonRhapsonPhaseEnvelope(system, - 2, system.getPhase(0).getNumberOfComponents()); - nonLinSolver.solve(1); - - startPres = system.getPressure(); - - for (np = 1; np < 9500; np++) { - if (np % 5 == 0) { - monitor.setValue(np); - monitor.setString("Calculated points: " + np); - } - - nonLinSolver.calcInc(np); - nonLinSolver.solve(np); - - if (system.getTemperature() > cricondenTherm[0]) { - cricondenTherm[1] = system.getPressure(); - cricondenTherm[0] = system.getTemperature(); - } - if (system.getPressure() > cricondenBar[1]) { - cricondenBar[0] = system.getTemperature(); - cricondenBar[1] = system.getPressure(); - } - - if (Double.isNaN(system.getTemperature()) || Double.isNaN(system.getTemperature()) - || system.getPressure() < startPres) { - points[0][np - 1] = points[0][np - 3]; - points[1][np - 1] = points[1][np - 3]; - pointsH[np - 1] = pointsH[np - 3]; - pointsV[np - 1] = pointsV[np - 3]; - pointsS[np - 1] = pointsS[np - 3]; - - // logger.info("avbryter" + np); - break; - } - // logger.info("Ideal pres: " + getPressure()); - // logger.info("temp: " + system.getTemperature()); - points[0][np - 1] = system.getTemperature(); - points[1][np - 1] = system.getPressure(); - pointsH[np - 1] = system.getPhase(1).getEnthalpy() - / system.getPhase(1).getNumberOfMolesInPhase() - / system.getPhase(1).getMolarMass() / 1e3; - pointsV[np - 1] = system.getPhase(1).getDensity(); - pointsS[np - 1] = system.getPhase(1).getEntropy() - / system.getPhase(1).getNumberOfMolesInPhase() - / system.getPhase(1).getMolarMass() / 1e3; - } - - int ncr = nonLinSolver.getNpCrit(); - int ncr2 = np - ncr; - - logger.info("ncr: " + ncr + " ncr2 . " + ncr2); - points2[0] = new double[ncr + 1]; - points2[1] = new double[ncr + 1]; - pointsH2[0] = new double[ncr + 1]; - pointsH2[1] = new double[ncr + 1]; - pointsS2[0] = new double[ncr + 1]; - pointsS2[1] = new double[ncr + 1]; - pointsV2[0] = new double[ncr + 1]; - pointsV2[1] = new double[ncr + 1]; - if (ncr2 > 2) { - points2[2] = new double[ncr2 - 2]; - points2[3] = new double[ncr2 - 2]; - pointsH2[2] = new double[ncr2 - 2]; - pointsH2[3] = new double[ncr2 - 2]; - pointsV2[2] = new double[ncr2 - 2]; - pointsV2[3] = new double[ncr2 - 2]; - pointsS2[2] = new double[ncr2 - 2]; - pointsS2[3] = new double[ncr2 - 2]; - } else { - points2[2] = new double[0]; - points2[3] = new double[0]; - pointsH2[2] = new double[0]; - pointsH2[3] = new double[0]; - pointsV2[2] = new double[0]; - pointsV2[3] = new double[0]; - pointsS2[2] = new double[0]; - pointsS2[3] = new double[0]; - } - - for (int i = 0; i < ncr; i++) { - points2[0][i] = points[0][i]; - points2[1][i] = points[1][i]; - - pointsH2[1][i] = points[1][i]; - pointsH2[0][i] = pointsH[i]; - - pointsS2[1][i] = points[1][i]; - pointsS2[0][i] = pointsS[i]; - - pointsV2[1][i] = points[1][i]; - pointsV2[0][i] = pointsV[i]; - } - - system.setTemperature(system.getTC() + 0.001); - system.setPressure(system.getPC() + 0.001); - system.init(3); - - points2[0][ncr] = system.getTC(); - points2[1][ncr] = system.getPC(); - - pointsH2[1][ncr] = system.getPC(); - pointsH2[0][ncr] = - system.getPhase(1).getEnthalpy() / system.getPhase(1).getNumberOfMolesInPhase() - / system.getPhase(1).getMolarMass() / 1e3; - - pointsS2[1][ncr] = system.getPC(); - pointsS2[0][ncr] = - system.getPhase(1).getEntropy() / system.getPhase(1).getNumberOfMolesInPhase() - / system.getPhase(1).getMolarMass() / 1e3; - - pointsV2[1][ncr] = system.getPC(); - pointsV2[0][ncr] = system.getPhase(1).getDensity(); - - if (ncr2 > 2) { - points2[2][0] = system.getTC(); - points2[3][0] = system.getPC(); - pointsH2[3][0] = system.getPC(); - pointsH2[2][0] = system.getPhase(1).getEnthalpy() - / system.getPhase(1).getNumberOfMolesInPhase() - / system.getPhase(1).getMolarMass() / 1e3; - pointsS2[3][0] = system.getPC(); - pointsS2[2][0] = system.getPhase(1).getEntropy() - / system.getPhase(1).getNumberOfMolesInPhase() - / system.getPhase(1).getMolarMass() / 1e3; - pointsV2[3][0] = system.getPC(); - pointsV2[2][0] = system.getPhase(1).getDensity(); - - for (int i = 1; i < (ncr2 - 2); i++) { - points2[2][i] = points[0][i + ncr - 1]; - points2[3][i] = points[1][i + ncr - 1]; - - pointsH2[3][i] = points[1][i + ncr - 1]; - pointsH2[2][i] = pointsH[i + ncr - 1]; - - pointsS2[3][i] = points[1][i + ncr - 1]; - pointsS2[2][i] = pointsS[i + ncr - 1]; - - pointsV2[3][i] = points[1][i + ncr - 1]; - pointsV2[2][i] = pointsV[i + ncr - 1]; - } - } - // monitor.close(); - mainFrame.setVisible(false); - - if (outputToFile) { - String name1 = new String(); - name1 = fileName + "Dew.nc"; - file1 = new neqsim.dataPresentation.fileHandeling.createNetCDF.netCDF2D.NetCdf2D(); - file1.setOutputFileName(name1); - file1.setXvalues(points2[2], "temp", "sec"); - file1.setYvalues(points2[3], "pres", "meter"); - file1.createFile(); - - String name2 = new String(); - name2 = fileName + "Bub.nc"; - file2 = new neqsim.dataPresentation.fileHandeling.createNetCDF.netCDF2D.NetCdf2D(); - file2.setOutputFileName(name2); - file2.setXvalues(points2[0], "temp", "sec"); - file2.setYvalues(points2[1], "pres", "meter"); - file2.createFile(); - } + if (bubblePointFirst) { + testOps.bubblePointTemperatureFlash(); + } else { + testOps.dewPointTemperatureFlash(); + } } catch (Exception e) { - logger.error("error", e); + e.toString(); } - } + double tempNy = system.getTemperature(); - /** {@inheritDoc} */ - @Override - public void displayResult() { - DecimalFormat nf = new DecimalFormat(); - nf.setMaximumFractionDigits(1); - nf.applyPattern("####.#"); - - double TC = system.getTC(); - double PC = system.getPC(); - logger.info("tc : " + TC + " PC : " + PC); - String[] navn = {"bubble point", "dew point", "bubble point", "dew point"}; - String title = "PT-graph TC=" + String.valueOf(nf.format(TC)) + " PC=" - + String.valueOf(nf.format(PC)); - String title3 = "PH-graph TC=" + String.valueOf(nf.format(TC)) + " PC=" - + String.valueOf(nf.format(PC)); - String title4 = "Density-graph TC=" + String.valueOf(nf.format(TC)) + " PC=" - + String.valueOf(nf.format(PC)); - String title5 = "PS-graph TC=" + String.valueOf(nf.format(TC)) + " PC=" - + String.valueOf(nf.format(PC)); - - // logger.info("start flash"); - // logger.info("Tferdig.."); - - graph2b graph3 = new graph2b(pointsH2, navn, title3, "Enthalpy [kJ/kg]", "Pressure [bara]"); - graph3.setVisible(true); - graph3.saveFigure((neqsim.util.util.FileSystemSettings.tempDir + "NeqSimTempFig4.png")); - - graph2b graph4 = new graph2b(pointsV2, navn, title4, "Density [kg/m^3]", "Pressure [bara]"); - graph4.setVisible(true); - graph4.saveFigure(neqsim.util.util.FileSystemSettings.tempDir + "NeqSimTempFig2.png"); - - graph2b graph5 = - new graph2b(pointsS2, navn, title5, "Entropy [kJ/kg*K]", "Pressure [bara]"); - graph5.setVisible(true); - graph5.saveFigure(neqsim.util.util.FileSystemSettings.tempDir + "NeqSimTempFig3.png"); - - graph2 = new graph2b(points2, navn, title, "Temperature [K]", "Pressure [bara]"); - graph2.setVisible(true); - graph2.saveFigure(neqsim.util.util.FileSystemSettings.tempDir + "NeqSimTempFig1.png"); - - /* - * JDialog dialog = new JDialog(); Container dialogContentPane = dialog.getContentPane(); - * dialogContentPane.setLayout(new FlowLayout()); JFreeChartPanel chartPanel = - * graph4.getChartPanel(); dialogContentPane.add(chartPanel); dialog.show(); - */ - } + if (!Double.isNaN(tempNy)) { + temp = tempNy; + break; + } + } - /** {@inheritDoc} */ - @Override - public void printToFile(String name) {} - - /** {@inheritDoc} */ - @Override - public org.jfree.chart.JFreeChart getJFreeChart(String name) { - DecimalFormat nf = new DecimalFormat(); - nf.setMaximumFractionDigits(1); - nf.applyPattern("####.#"); - - double TC = system.getTC(); - double PC = system.getPC(); - logger.info("tc : " + TC + " PC : " + PC); - String[] navn = {"bubble point", "dew point", "bubble point", "dew point"}; - String title = "PT-graph. TC=" + String.valueOf(nf.format(TC)) + "K, PC=" - + String.valueOf(nf.format(PC) + " bara"); - graph2 = new graph2b(points2, navn, title, "Temperature [K]", "Pressure [bara]"); - return graph2.getChart(); - } + system.setPressure(pres); + system.setTemperature(temp); + logger.info("temp: " + system.getTemperature()); - /** {@inheritDoc} */ - @Override - public double[][] getPoints(int i) { - return points2; - } + system.setBeta(phaseFraction); - /** {@inheritDoc} */ - @Override - public double[] get(String name) { - if (name.equals("bubT")) { - return points2[0]; - } - if (name.equals("bubP")) { - return points2[1]; - } - if (name.equals("dewT")) { - return points2[2]; - } - if (name.equals("dewP")) { - return points2[3]; - } - if (name.equals("dewH")) { - return pointsH2[2]; - } - if (name.equals("dewDens")) { - return pointsV2[2]; - } - if (name.equals("dewS")) { - return pointsS2[2]; - } - if (name.equals("bubH")) { - return pointsH2[0]; + sysNewtonRhapsonPhaseEnvelope nonLinSolver = + new sysNewtonRhapsonPhaseEnvelope(system, 2, system.getPhase(0).getNumberOfComponents()); + nonLinSolver.solve(1); + + startPres = system.getPressure(); + + for (np = 1; np < 9500; np++) { + if (np % 5 == 0) { + monitor.setValue(np); + monitor.setString("Calculated points: " + np); } - if (name.equals("bubDens")) { - return pointsV2[0]; + + nonLinSolver.calcInc(np); + nonLinSolver.solve(np); + + if (system.getTemperature() > cricondenTherm[0]) { + cricondenTherm[1] = system.getPressure(); + cricondenTherm[0] = system.getTemperature(); } - if (name.equals("bubS")) { - return pointsS2[0]; + if (system.getPressure() > cricondenBar[1]) { + cricondenBar[0] = system.getTemperature(); + cricondenBar[1] = system.getPressure(); } - if (name.equals("cricondentherm")) { - return cricondenTherm; + + if (Double.isNaN(system.getTemperature()) || Double.isNaN(system.getTemperature()) + || system.getPressure() < startPres) { + points[0][np - 1] = points[0][np - 3]; + points[1][np - 1] = points[1][np - 3]; + pointsH[np - 1] = pointsH[np - 3]; + pointsV[np - 1] = pointsV[np - 3]; + pointsS[np - 1] = pointsS[np - 3]; + + // logger.info("avbryter" + np); + break; } - if (name.equals("cricondenbar")) { - return cricondenBar; - } else { - return null; + // logger.info("Ideal pres: " + getPressure()); + // logger.info("temp: " + system.getTemperature()); + points[0][np - 1] = system.getTemperature(); + points[1][np - 1] = system.getPressure(); + pointsH[np - 1] = + system.getPhase(1).getEnthalpy() / system.getPhase(1).getNumberOfMolesInPhase() + / system.getPhase(1).getMolarMass() / 1e3; + pointsV[np - 1] = system.getPhase(1).getDensity(); + pointsS[np - 1] = + system.getPhase(1).getEntropy() / system.getPhase(1).getNumberOfMolesInPhase() + / system.getPhase(1).getMolarMass() / 1e3; + } + + int ncr = nonLinSolver.getNpCrit(); + int ncr2 = np - ncr; + + logger.info("ncr: " + ncr + " ncr2 . " + ncr2); + points2[0] = new double[ncr + 1]; + points2[1] = new double[ncr + 1]; + pointsH2[0] = new double[ncr + 1]; + pointsH2[1] = new double[ncr + 1]; + pointsS2[0] = new double[ncr + 1]; + pointsS2[1] = new double[ncr + 1]; + pointsV2[0] = new double[ncr + 1]; + pointsV2[1] = new double[ncr + 1]; + if (ncr2 > 2) { + points2[2] = new double[ncr2 - 2]; + points2[3] = new double[ncr2 - 2]; + pointsH2[2] = new double[ncr2 - 2]; + pointsH2[3] = new double[ncr2 - 2]; + pointsV2[2] = new double[ncr2 - 2]; + pointsV2[3] = new double[ncr2 - 2]; + pointsS2[2] = new double[ncr2 - 2]; + pointsS2[3] = new double[ncr2 - 2]; + } else { + points2[2] = new double[0]; + points2[3] = new double[0]; + pointsH2[2] = new double[0]; + pointsH2[3] = new double[0]; + pointsV2[2] = new double[0]; + pointsV2[3] = new double[0]; + pointsS2[2] = new double[0]; + pointsS2[3] = new double[0]; + } + + for (int i = 0; i < ncr; i++) { + points2[0][i] = points[0][i]; + points2[1][i] = points[1][i]; + + pointsH2[1][i] = points[1][i]; + pointsH2[0][i] = pointsH[i]; + + pointsS2[1][i] = points[1][i]; + pointsS2[0][i] = pointsS[i]; + + pointsV2[1][i] = points[1][i]; + pointsV2[0][i] = pointsV[i]; + } + + system.setTemperature(system.getTC() + 0.001); + system.setPressure(system.getPC() + 0.001); + system.init(3); + + points2[0][ncr] = system.getTC(); + points2[1][ncr] = system.getPC(); + + pointsH2[1][ncr] = system.getPC(); + pointsH2[0][ncr] = system.getPhase(1).getEnthalpy() + / system.getPhase(1).getNumberOfMolesInPhase() / system.getPhase(1).getMolarMass() / 1e3; + + pointsS2[1][ncr] = system.getPC(); + pointsS2[0][ncr] = system.getPhase(1).getEntropy() + / system.getPhase(1).getNumberOfMolesInPhase() / system.getPhase(1).getMolarMass() / 1e3; + + pointsV2[1][ncr] = system.getPC(); + pointsV2[0][ncr] = system.getPhase(1).getDensity(); + + if (ncr2 > 2) { + points2[2][0] = system.getTC(); + points2[3][0] = system.getPC(); + pointsH2[3][0] = system.getPC(); + pointsH2[2][0] = + system.getPhase(1).getEnthalpy() / system.getPhase(1).getNumberOfMolesInPhase() + / system.getPhase(1).getMolarMass() / 1e3; + pointsS2[3][0] = system.getPC(); + pointsS2[2][0] = + system.getPhase(1).getEntropy() / system.getPhase(1).getNumberOfMolesInPhase() + / system.getPhase(1).getMolarMass() / 1e3; + pointsV2[3][0] = system.getPC(); + pointsV2[2][0] = system.getPhase(1).getDensity(); + + for (int i = 1; i < (ncr2 - 2); i++) { + points2[2][i] = points[0][i + ncr - 1]; + points2[3][i] = points[1][i + ncr - 1]; + + pointsH2[3][i] = points[1][i + ncr - 1]; + pointsH2[2][i] = pointsH[i + ncr - 1]; + + pointsS2[3][i] = points[1][i + ncr - 1]; + pointsS2[2][i] = pointsS[i + ncr - 1]; + + pointsV2[3][i] = points[1][i + ncr - 1]; + pointsV2[2][i] = pointsV[i + ncr - 1]; } + } + // monitor.close(); + mainFrame.setVisible(false); + /* + * if (outputToFile) { String name1 = new String(); name1 = fileName + "Dew.nc"; file1 = new + * neqsim.dataPresentation.fileHandeling.createNetCDF.netCDF2D.NetCdf2D(); + * file1.setOutputFileName(name1); file1.setXvalues(points2[2], "temp", "sec"); + * file1.setYvalues(points2[3], "pres", "meter"); file1.createFile(); + * + * String name2 = new String(); name2 = fileName + "Bub.nc"; file2 = new + * neqsim.dataPresentation.fileHandeling.createNetCDF.netCDF2D.NetCdf2D(); + * file2.setOutputFileName(name2); file2.setXvalues(points2[0], "temp", "sec"); + * file2.setYvalues(points2[1], "pres", "meter"); file2.createFile(); } + */ + } catch (Exception e) { + logger.error("error", e); } - - /** {@inheritDoc} */ - @Override - public void createNetCdfFile(String name) { - fileName = name; - } - - /** - * Getter for property bubblePointFirst. - * - * @return Value of property bubblePointFirst. + } + + /** {@inheritDoc} */ + @Override + public void displayResult() { + DecimalFormat nf = new DecimalFormat(); + nf.setMaximumFractionDigits(1); + nf.applyPattern("####.#"); + + double TC = system.getTC(); + double PC = system.getPC(); + logger.info("tc : " + TC + " PC : " + PC); + String[] navn = {"bubble point", "dew point", "bubble point", "dew point"}; + String title = + "PT-graph TC=" + String.valueOf(nf.format(TC)) + " PC=" + String.valueOf(nf.format(PC)); + String title3 = + "PH-graph TC=" + String.valueOf(nf.format(TC)) + " PC=" + String.valueOf(nf.format(PC)); + String title4 = "Density-graph TC=" + String.valueOf(nf.format(TC)) + " PC=" + + String.valueOf(nf.format(PC)); + String title5 = + "PS-graph TC=" + String.valueOf(nf.format(TC)) + " PC=" + String.valueOf(nf.format(PC)); + + // logger.info("start flash"); + // logger.info("Tferdig.."); + + graph2b graph3 = new graph2b(pointsH2, navn, title3, "Enthalpy [kJ/kg]", "Pressure [bara]"); + graph3.setVisible(true); + graph3.saveFigure((neqsim.util.util.FileSystemSettings.tempDir + "NeqSimTempFig4.png")); + + graph2b graph4 = new graph2b(pointsV2, navn, title4, "Density [kg/m^3]", "Pressure [bara]"); + graph4.setVisible(true); + graph4.saveFigure(neqsim.util.util.FileSystemSettings.tempDir + "NeqSimTempFig2.png"); + + graph2b graph5 = new graph2b(pointsS2, navn, title5, "Entropy [kJ/kg*K]", "Pressure [bara]"); + graph5.setVisible(true); + graph5.saveFigure(neqsim.util.util.FileSystemSettings.tempDir + "NeqSimTempFig3.png"); + + graph2 = new graph2b(points2, navn, title, "Temperature [K]", "Pressure [bara]"); + graph2.setVisible(true); + graph2.saveFigure(neqsim.util.util.FileSystemSettings.tempDir + "NeqSimTempFig1.png"); + + /* + * JDialog dialog = new JDialog(); Container dialogContentPane = dialog.getContentPane(); + * dialogContentPane.setLayout(new FlowLayout()); JFreeChartPanel chartPanel = + * graph4.getChartPanel(); dialogContentPane.add(chartPanel); dialog.show(); */ - public boolean isBubblePointFirst() { - return bubblePointFirst; + } + + /** {@inheritDoc} */ + @Override + public void printToFile(String name) {} + + /** {@inheritDoc} */ + @Override + public org.jfree.chart.JFreeChart getJFreeChart(String name) { + DecimalFormat nf = new DecimalFormat(); + nf.setMaximumFractionDigits(1); + nf.applyPattern("####.#"); + + double TC = system.getTC(); + double PC = system.getPC(); + logger.info("tc : " + TC + " PC : " + PC); + String[] navn = {"bubble point", "dew point", "bubble point", "dew point"}; + String title = "PT-graph. TC=" + String.valueOf(nf.format(TC)) + "K, PC=" + + String.valueOf(nf.format(PC) + " bara"); + graph2 = new graph2b(points2, navn, title, "Temperature [K]", "Pressure [bara]"); + return graph2.getChart(); + } + + /** {@inheritDoc} */ + @Override + public double[][] getPoints(int i) { + return points2; + } + + /** {@inheritDoc} */ + @Override + public double[] get(String name) { + if (name.equals("bubT")) { + return points2[0]; } - - /** - * Setter for property bubblePointFirst. - * - * @param bubblePointFirst New value of property bubblePointFirst. - */ - public void setBubblePointFirst(boolean bubblePointFirst) { - this.bubblePointFirst = bubblePointFirst; + if (name.equals("bubP")) { + return points2[1]; } - - /** {@inheritDoc} */ - @Override - public String[][] getResultTable() { - return null; + if (name.equals("dewT")) { + return points2[2]; + } + if (name.equals("dewP")) { + return points2[3]; + } + if (name.equals("dewH")) { + return pointsH2[2]; + } + if (name.equals("dewDens")) { + return pointsV2[2]; + } + if (name.equals("dewS")) { + return pointsS2[2]; + } + if (name.equals("bubH")) { + return pointsH2[0]; + } + if (name.equals("bubDens")) { + return pointsV2[0]; + } + if (name.equals("bubS")) { + return pointsS2[0]; + } + if (name.equals("cricondentherm")) { + return cricondenTherm; + } + if (name.equals("cricondenbar")) { + return cricondenBar; + } else { + return null; } + } + + /** + * Getter for property bubblePointFirst. + * + * @return Value of property bubblePointFirst. + */ + public boolean isBubblePointFirst() { + return bubblePointFirst; + } + + /** + * Setter for property bubblePointFirst. + * + * @param bubblePointFirst New value of property bubblePointFirst. + */ + public void setBubblePointFirst(boolean bubblePointFirst) { + this.bubblePointFirst = bubblePointFirst; + } + + /** {@inheritDoc} */ + @Override + public String[][] getResultTable() { + return null; + } } diff --git a/src/main/java/neqsim/thermodynamicOperations/phaseEnvelopeOps/multicomponentEnvelopeOps/pTphaseEnvelopeMay.java b/src/main/java/neqsim/thermodynamicOperations/phaseEnvelopeOps/multicomponentEnvelopeOps/pTphaseEnvelopeMay.java index da70ca2adf..02c54b233c 100644 --- a/src/main/java/neqsim/thermodynamicOperations/phaseEnvelopeOps/multicomponentEnvelopeOps/pTphaseEnvelopeMay.java +++ b/src/main/java/neqsim/thermodynamicOperations/phaseEnvelopeOps/multicomponentEnvelopeOps/pTphaseEnvelopeMay.java @@ -20,777 +20,756 @@ * @version $Id: $Id */ public class pTphaseEnvelopeMay extends BaseOperation { - private static final long serialVersionUID = 1000; - static Logger logger = LogManager.getLogger(pTphaseEnvelopeMay.class); - - double maxPressure = 1000.0; - double minPressure = 1.0; - double[][] copiedPoints = null; - graph2b graph2 = null; - SystemInterface system; - boolean bubblePointFirst = true; - boolean hascopiedPoints = false; - double[] cricondenTherm = new double[3]; - double[] cricondenBar = new double[3]; - double phaseFraction = 1e-10; - neqsim.dataPresentation.fileHandeling.createNetCDF.netCDF2D.NetCdf2D file1; - neqsim.dataPresentation.fileHandeling.createNetCDF.netCDF2D.NetCdf2D file2; - int i, j = 0, nummer = 0, iterations = 0, maxNumberOfIterations = 10000; - double gibbsEnergy = 0, gibbsEnergyOld = 0; - double Kold, deviation = 0, g0 = 0, g1 = 0, lowPres = 1.0; - double lnOldOldK[], lnK[]; - boolean outputToFile = false; - double lnOldK[]; - double lnKwil[]; - double oldDeltalnK[], deltalnK[]; - double tm[] = {1, 1}; - double beta = 1e-5; - int lowestGibbsEnergyPhase = 0; // lowestGibbsEnergyPhase - JProgressBar monitor; - JFrame mainFrame; - String fileName = "c:/file"; - JPanel mainPanel; - double temp = 0, pres = 0, startPres = 0; - double[][] points = new double[2][]; - double[] pointsH; - double[][] pointsH2 = new double[4][]; - double[] pointsV; - double[][] pointsV2 = new double[4][]; - double[] pointsS; - double[][] pointsS2 = new double[4][]; - public double[][] points2 = new double[4][]; - double[][] points3 = new double[8][]; - boolean moreLines = false; - boolean restart = true; - int np = 0; - // points[2] = new double[1000]; - int speceq = 0; - String[] navn = {"bubble point", "dew point", "bubble point", "dew point", "dew points"}; - int npfirst; - int ncrfirst; - double Tcfirst; - double Pcfirst; - double Tmin = 0.0; - - /** - *

- * Constructor for pTphaseEnvelopeMay. - *

- */ - public pTphaseEnvelopeMay() {} - - /** - *

- * Constructor for pTphaseEnvelopeMay. - *

- * - * @param system a {@link neqsim.thermo.system.SystemInterface} object - * @param name a {@link java.lang.String} object - * @param phaseFraction a double - * @param lowPres a double - * @param bubfirst a boolean - */ - public pTphaseEnvelopeMay(SystemInterface system, String name, double phaseFraction, - double lowPres, boolean bubfirst) { - this.bubblePointFirst = bubfirst; - if (name != null) { - outputToFile = true; - fileName = name; - } - this.system = system; - this.phaseFraction = phaseFraction; - lnOldOldK = new double[system.getPhase(0).getNumberOfComponents()]; - lnOldK = new double[system.getPhase(0).getNumberOfComponents()]; - lnK = new double[system.getPhase(0).getNumberOfComponents()]; - this.lowPres = lowPres; - oldDeltalnK = new double[system.getPhase(0).getNumberOfComponents()]; - deltalnK = new double[system.getPhase(0).getNumberOfComponents()]; + private static final long serialVersionUID = 1000; + static Logger logger = LogManager.getLogger(pTphaseEnvelopeMay.class); + + double maxPressure = 1000.0; + double minPressure = 1.0; + double[][] copiedPoints = null; + graph2b graph2 = null; + SystemInterface system; + boolean bubblePointFirst = true; + boolean hascopiedPoints = false; + double[] cricondenTherm = new double[3]; + double[] cricondenBar = new double[3]; + double phaseFraction = 1e-10; + int i, j = 0, nummer = 0, iterations = 0, maxNumberOfIterations = 10000; + double gibbsEnergy = 0, gibbsEnergyOld = 0; + double Kold, deviation = 0, g0 = 0, g1 = 0, lowPres = 1.0; + double lnOldOldK[], lnK[]; + boolean outputToFile = false; + double lnOldK[]; + double lnKwil[]; + double oldDeltalnK[], deltalnK[]; + double tm[] = {1, 1}; + double beta = 1e-5; + int lowestGibbsEnergyPhase = 0; // lowestGibbsEnergyPhase + JProgressBar monitor; + JFrame mainFrame; + String fileName = "c:/file"; + JPanel mainPanel; + double temp = 0, pres = 0, startPres = 0; + double[][] points = new double[2][]; + double[] pointsH; + double[][] pointsH2 = new double[4][]; + double[] pointsV; + double[][] pointsV2 = new double[4][]; + double[] pointsS; + double[][] pointsS2 = new double[4][]; + public double[][] points2 = new double[4][]; + double[][] points3 = new double[8][]; + boolean moreLines = false; + boolean restart = true; + int np = 0; + // points[2] = new double[1000]; + int speceq = 0; + String[] navn = {"bubble point", "dew point", "bubble point", "dew point", "dew points"}; + int npfirst; + int ncrfirst; + double Tcfirst; + double Pcfirst; + double Tmin = 0.0; + + /** + *

+ * Constructor for pTphaseEnvelopeMay. + *

+ */ + public pTphaseEnvelopeMay() {} + + /** + *

+ * Constructor for pTphaseEnvelopeMay. + *

+ * + * @param system a {@link neqsim.thermo.system.SystemInterface} object + * @param name a {@link java.lang.String} object + * @param phaseFraction a double + * @param lowPres a double + * @param bubfirst a boolean + */ + public pTphaseEnvelopeMay(SystemInterface system, String name, double phaseFraction, + double lowPres, boolean bubfirst) { + this.bubblePointFirst = bubfirst; + if (name != null) { + outputToFile = true; + fileName = name; } - - /** {@inheritDoc} */ - @Override - public void run() { - speceq = 0; // initialization + this.system = system; + this.phaseFraction = phaseFraction; + lnOldOldK = new double[system.getPhase(0).getNumberOfComponents()]; + lnOldK = new double[system.getPhase(0).getNumberOfComponents()]; + lnK = new double[system.getPhase(0).getNumberOfComponents()]; + this.lowPres = lowPres; + oldDeltalnK = new double[system.getPhase(0).getNumberOfComponents()]; + deltalnK = new double[system.getPhase(0).getNumberOfComponents()]; + } + + /** {@inheritDoc} */ + @Override + public void run() { + speceq = 0; // initialization + try { + points[0] = new double[10000]; // declarations for points + points[1] = new double[10000]; // declarations for points + + pointsH = new double[10000]; // declarations for points + pointsV = new double[10000]; // declarations for points + pointsS = new double[10000]; // declarations for points + system.init(0); // initialization + + // selects the most volatile and least volatile component based on Tc values + // afterwards it uses them to define the speceq of the first point + // based on the desired first point, dew/bubble + for (int i = 0; i < system.getPhase(0).getNumberOfComponents(); i++) { + if (system.getPhase(0).getComponent(i).getIonicCharge() == 0) { + if (bubblePointFirst == true && system.getPhase(0).getComponents()[speceq] + .getTC() > system.getPhase(0).getComponents()[i].getTC()) { + speceq = system.getPhase(0).getComponent(i).getComponentNumber(); + } + if (bubblePointFirst == false && system.getPhase(0).getComponents()[speceq] + .getTC() < system.getPhase(0).getComponents()[i].getTC()) { + speceq = system.getPhase(0).getComponent(i).getComponentNumber(); + } + } + } + + // initialized the first step of the phase envelope + // pressure is already defined + // temperature is the Antoine vapor pressure of the selected component + // (least or most volatile. + pres = lowPres; + // temp = + // system.getPhase(0).getComponent(speceq).getAntoineVaporTemperature(pres); + temp = tempKWilson(phaseFraction, pres); + + if (Double.isNaN(temp)) { + temp = system.getPhase(0).getComponent(speceq).getTC() - 20.0; + } + system.setTemperature(temp); + system.setPressure(pres); + + ThermodynamicOperations testOps = new ThermodynamicOperations(system); + + // this part converges the first phase envelope point. + // if the phase fraction is more than 0.5 it does a dew point initialization + // else a bubble point initialization + + for (int i = 0; i < 5; i++) { try { - points[0] = new double[10000]; // declarations for points - points[1] = new double[10000]; // declarations for points - - pointsH = new double[10000]; // declarations for points - pointsV = new double[10000]; // declarations for points - pointsS = new double[10000]; // declarations for points - system.init(0); // initialization - - // selects the most volatile and least volatile component based on Tc values - // afterwards it uses them to define the speceq of the first point - // based on the desired first point, dew/bubble - for (int i = 0; i < system.getPhase(0).getNumberOfComponents(); i++) { - if (system.getPhase(0).getComponent(i).getIonicCharge() == 0) { - if (bubblePointFirst == true && system.getPhase(0).getComponents()[speceq] - .getTC() > system.getPhase(0).getComponents()[i].getTC()) { - speceq = system.getPhase(0).getComponent(i).getComponentNumber(); - } - if (bubblePointFirst == false && system.getPhase(0).getComponents()[speceq] - .getTC() < system.getPhase(0).getComponents()[i].getTC()) { - speceq = system.getPhase(0).getComponent(i).getComponentNumber(); - } - } - } - - // initialized the first step of the phase envelope - // pressure is already defined - // temperature is the Antoine vapor pressure of the selected component - // (least or most volatile. - pres = lowPres; - // temp = - // system.getPhase(0).getComponent(speceq).getAntoineVaporTemperature(pres); - temp = tempKWilson(phaseFraction, pres); - - if (Double.isNaN(temp)) { - temp = system.getPhase(0).getComponent(speceq).getTC() - 20.0; - } + if (phaseFraction < 0.5) { + temp += i * 2; system.setTemperature(temp); - system.setPressure(pres); - - ThermodynamicOperations testOps = new ThermodynamicOperations(system); - - // this part converges the first phase envelope point. - // if the phase fraction is more than 0.5 it does a dew point initialization - // else a bubble point initialization - - for (int i = 0; i < 5; i++) { - try { - if (phaseFraction < 0.5) { - temp += i * 2; - system.setTemperature(temp); - testOps.bubblePointTemperatureFlash(); - } else { - temp += i * 2; - system.setTemperature(temp); - testOps.dewPointTemperatureFlash(); - } - } catch (Exception e) { - e.toString(); - } - double tempNy = system.getTemperature(); - - if (!Double.isNaN(tempNy)) { - temp = tempNy; - break; - } - } - - // this part sets the first envelope point into the system - system.setBeta(phaseFraction); - system.setPressure(pres); + testOps.bubblePointTemperatureFlash(); + } else { + temp += i * 2; system.setTemperature(temp); + testOps.dewPointTemperatureFlash(); + } + } catch (Exception e) { + e.toString(); + } + double tempNy = system.getTemperature(); - sysNewtonRhapsonPhaseEnvelope nonLinSolver = new sysNewtonRhapsonPhaseEnvelope(system, - 2, system.getPhase(0).getNumberOfComponents()); - startPres = system.getPressure(); - nonLinSolver.setu(); - for (np = 1; np < 9980; np++) { - try { - // solves the np point of the envelope - nonLinSolver.calcInc(np); - nonLinSolver.solve(np); - - // double TT = system.getPhase(0).getTemperature(); - // double PP = system.getPhase(0).getPressure(); - } catch (Exception e0) { - // the envelope crushed. - // this part keeps the old values - // restarts the envelope from the other side - // and then stops - - if (restart) { - restart = false; - // keep values - Tmin = points[0][np - 2]; - npfirst = np - 1; - ncrfirst = nonLinSolver.getNpCrit(); - if (ncrfirst == 0) { - ncrfirst = npfirst; - } - Tcfirst = system.getTC(); - Pcfirst = system.getPC(); - hascopiedPoints = true; - copiedPoints = new double[5][np - 1]; - for (int i = 0; i < np - 1; i++) { - copiedPoints[0][i] = points[0][i]; - copiedPoints[1][i] = points[1][i]; - copiedPoints[2][i] = pointsH[i]; - copiedPoints[3][i] = pointsS[i]; - copiedPoints[4][i] = pointsV[i]; - } - // new settings - phaseFraction = 1.0 - phaseFraction; - if (bubblePointFirst) { - bubblePointFirst = false; - } else { - bubblePointFirst = true; - } - run(); - break; - } else { - np = np - 1; - break; - } - } - - // check for critical point - double Kvallc = system.getPhase(0).getComponent(nonLinSolver.lc).getx() - / system.getPhase(1).getComponent(nonLinSolver.lc).getx(); - double Kvalhc = system.getPhase(0).getComponent(nonLinSolver.hc).getx() - / system.getPhase(1).getComponent(nonLinSolver.hc).getx(); - // double densV = system.getPhase(0).getDensity(); - // double densL = system.getPhase(1).getDensity(); - - // System.out.println(np + " " + system.getTemperature() + " " + - // system.getPressure() + " " + densV + " " + densL ); - - if ((nonLinSolver.etterCP == false)) { - if (Kvallc < 1.05 && Kvalhc > 0.95) { - // close to the critical point - // invert phase types and find the CP Temp and Press - - // System.out.println("critical point"); - nonLinSolver.npCrit = np; - system.invertPhaseTypes(); - nonLinSolver.etterCP = true; - // the critical point is found from interpolation plynimials based on K=1 of - // the - // most or least volatile component - nonLinSolver.calcCrit(); - } - } - if (nonLinSolver.calcCP) { - nonLinSolver.calcCP = false; - nonLinSolver.npCrit = np; - nonLinSolver.calcCrit(); - } - - // stores cricondenbar and cricondentherm - // HERE the new cricoT and crico P values will be called instead - if (system.getTemperature() > cricondenTherm[0]) { - cricondenTherm[1] = system.getPressure(); - cricondenTherm[0] = system.getTemperature(); - } else { - nonLinSolver.ettercricoT = true; - } - if (system.getPressure() > cricondenBar[1]) { - cricondenBar[0] = system.getTemperature(); - cricondenBar[1] = system.getPressure(); - } - - // Exit criteria - if ((system.getPressure() < minPressure && nonLinSolver.ettercricoT)) { - break; - } - if (system.getPressure() > maxPressure) { - break; - } - if (system.getTemperature() > Tmin && !restart) { - break; - } - - // Keeps the calculated points - points[0][np - 1] = system.getTemperature(); - points[1][np - 1] = system.getPressure(); - pointsH[np - 1] = system.getPhase(1).getEnthalpy() - / system.getPhase(1).getNumberOfMolesInPhase() - / system.getPhase(1).getMolarMass() / 1e3; - pointsV[np - 1] = system.getPhase(1).getDensity(); - pointsS[np - 1] = system.getPhase(1).getEntropy() - / system.getPhase(1).getNumberOfMolesInPhase() - / system.getPhase(1).getMolarMass() / 1e3; + if (!Double.isNaN(tempNy)) { + temp = tempNy; + break; + } + } + + // this part sets the first envelope point into the system + system.setBeta(phaseFraction); + system.setPressure(pres); + system.setTemperature(temp); + + sysNewtonRhapsonPhaseEnvelope nonLinSolver = + new sysNewtonRhapsonPhaseEnvelope(system, 2, system.getPhase(0).getNumberOfComponents()); + startPres = system.getPressure(); + nonLinSolver.setu(); + for (np = 1; np < 9980; np++) { + try { + // solves the np point of the envelope + nonLinSolver.calcInc(np); + nonLinSolver.solve(np); + + // double TT = system.getPhase(0).getTemperature(); + // double PP = system.getPhase(0).getPressure(); + } catch (Exception e0) { + // the envelope crushed. + // this part keeps the old values + // restarts the envelope from the other side + // and then stops + + if (restart) { + restart = false; + // keep values + Tmin = points[0][np - 2]; + npfirst = np - 1; + ncrfirst = nonLinSolver.getNpCrit(); + if (ncrfirst == 0) { + ncrfirst = npfirst; } - - try { - int ncr = nonLinSolver.getNpCrit(); - if (ncr == 0) { - ncr = np; - } - int ncr2 = np - ncr; - if (hascopiedPoints) { - // if it enters here the envelope crashed and restarted - // reallocate to have all values - points2 = new double[8][]; - pointsH2 = new double[8][]; - pointsS2 = new double[8][]; - pointsV2 = new double[8][]; - } - - // points2 are plotted - points2[0] = new double[ncr + 1]; - points2[1] = new double[ncr + 1]; - pointsH2[0] = new double[ncr + 1]; - pointsH2[1] = new double[ncr + 1]; - pointsS2[0] = new double[ncr + 1]; - pointsS2[1] = new double[ncr + 1]; - pointsV2[0] = new double[ncr + 1]; - pointsV2[1] = new double[ncr + 1]; - - if (ncr2 > 2) { - points2[2] = new double[ncr2 - 2]; - points2[3] = new double[ncr2 - 2]; - pointsH2[2] = new double[ncr2 - 2]; - pointsH2[3] = new double[ncr2 - 2]; - pointsS2[2] = new double[ncr2 - 2]; - pointsS2[3] = new double[ncr2 - 2]; - pointsV2[2] = new double[ncr2 - 2]; - pointsV2[3] = new double[ncr2 - 2]; - } else { - points2[2] = new double[0]; - points2[3] = new double[0]; - pointsH2[2] = new double[0]; - pointsH2[3] = new double[0]; - pointsS2[2] = new double[0]; - pointsS2[3] = new double[0]; - pointsV2[2] = new double[0]; - pointsV2[3] = new double[0]; - } - - for (int i = 0; i < ncr; i++) { - // second branch up to critical point - points2[0][i] = points[0][i]; - points2[1][i] = points[1][i]; - pointsH2[1][i] = points[1][i]; - pointsH2[0][i] = pointsH[i]; - pointsS2[1][i] = points[1][i]; - pointsS2[0][i] = pointsS[i]; - pointsV2[1][i] = points[1][i]; - pointsV2[0][i] = pointsV[i]; - } - if (ncr2 > 2) { - for (int i = 1; i < (ncr2 - 2); i++) { - // second branch after the critical point - points2[2][i] = points[0][i + ncr - 1]; - points2[3][i] = points[1][i + ncr - 1]; - pointsH2[3][i] = points[1][i + ncr - 1]; - pointsH2[2][i] = pointsH[i + ncr - 1]; - pointsS2[3][i] = points[1][i + ncr - 1]; - pointsS2[2][i] = pointsS[i + ncr - 1]; - pointsV2[3][i] = points[1][i + ncr - 1]; - pointsV2[2][i] = pointsV[i + ncr - 1]; - } - } - - if (hascopiedPoints) { - if (ncrfirst > npfirst) { - ncr = copiedPoints[0].length - 1; - ncr2 = npfirst - ncr; - npfirst = npfirst - 1; - } else { - ncr = ncrfirst; - ncr2 = npfirst - ncr; - } - - points2[4] = new double[ncr + 1]; - points2[5] = new double[ncr + 1]; - pointsH2[4] = new double[ncr + 1]; - pointsH2[5] = new double[ncr + 1]; - pointsS2[4] = new double[ncr + 1]; - pointsS2[5] = new double[ncr + 1]; - pointsV2[4] = new double[ncr + 1]; - pointsV2[5] = new double[ncr + 1]; - - if (ncr2 > 2) { - points2[6] = new double[ncr2 - 2]; - points2[7] = new double[ncr2 - 2]; - pointsH2[6] = new double[ncr2 - 2]; - pointsH2[7] = new double[ncr2 - 2]; - pointsS2[6] = new double[ncr2 - 2]; - pointsS2[7] = new double[ncr2 - 2]; - pointsV2[6] = new double[ncr2 - 2]; - pointsV2[7] = new double[ncr2 - 2]; - } else { - points2[6] = new double[0]; - points2[7] = new double[0]; - pointsH2[6] = new double[0]; - pointsH2[7] = new double[0]; - pointsS2[6] = new double[0]; - pointsS2[7] = new double[0]; - pointsV2[6] = new double[0]; - pointsV2[7] = new double[0]; - } - - for (int i = 0; i < ncr; i++) { - // first branch up to the critical point - points2[4][i] = copiedPoints[0][i]; - points2[5][i] = copiedPoints[1][i]; - pointsH2[5][i] = copiedPoints[1][i]; - pointsH2[4][i] = copiedPoints[2][i]; - pointsS2[5][i] = copiedPoints[1][i]; - pointsS2[4][i] = copiedPoints[3][i]; - pointsV2[5][i] = copiedPoints[1][i]; - pointsV2[4][i] = copiedPoints[4][i]; - } - if (ncr2 > 2) { - for (int i = 1; i < (ncr2 - 2); i++) { - // first branch after the critical point - points2[6][i] = copiedPoints[0][i + ncr - 1]; - points2[7][i] = copiedPoints[1][i + ncr - 1]; - pointsH2[7][i] = copiedPoints[1][i + ncr - 1]; - pointsH2[6][i] = copiedPoints[2][i + ncr - 1]; - pointsS2[7][i] = copiedPoints[1][i + ncr - 1]; - pointsS2[6][i] = copiedPoints[3][i + ncr - 1]; - pointsV2[7][i] = copiedPoints[1][i + ncr - 1]; - pointsV2[6][i] = copiedPoints[4][i + ncr - 1]; - } - } - } - - // critical point - system.setTemperature(system.getTC()); - system.setPressure(system.getPC()); - - system.init(3); - - points2[0][ncr] = system.getTC(); - points2[1][ncr] = system.getPC(); - - if (ncr2 > 2) { - points2[2][0] = system.getTC(); - points2[3][0] = system.getPC(); - } - } catch (Exception e2) { - // double nef = 0.; - logger.error("error", e2); + Tcfirst = system.getTC(); + Pcfirst = system.getPC(); + hascopiedPoints = true; + copiedPoints = new double[5][np - 1]; + for (int i = 0; i < np - 1; i++) { + copiedPoints[0][i] = points[0][i]; + copiedPoints[1][i] = points[1][i]; + copiedPoints[2][i] = pointsH[i]; + copiedPoints[3][i] = pointsS[i]; + copiedPoints[4][i] = pointsV[i]; } - - try { - if (outputToFile) { - // update this - String name1 = new String(); - name1 = fileName + "Dew.nc"; - file1 = new neqsim.dataPresentation.fileHandeling.createNetCDF.netCDF2D.NetCdf2D(); - file1.setOutputFileName(name1); - file1.setXvalues(points2[2], "temp", "sec"); - file1.setYvalues(points2[3], "pres", "meter"); - file1.createFile(); - - String name2 = new String(); - name2 = fileName + "Bub.nc"; - file2 = new neqsim.dataPresentation.fileHandeling.createNetCDF.netCDF2D.NetCdf2D(); - file2.setOutputFileName(name2); - file2.setXvalues(points2[0], "temp", "sec"); - file2.setYvalues(points2[1], "pres", "meter"); - file2.createFile(); - } - } catch (Exception e3) { - // double nef = 0.; - logger.error("error", e3); + // new settings + phaseFraction = 1.0 - phaseFraction; + if (bubblePointFirst) { + bubblePointFirst = false; + } else { + bubblePointFirst = true; } - } catch (Exception e4) { - // double nef = 0.; - logger.error("error", e4); + run(); + break; + } else { + np = np - 1; + break; + } } - } - /** - *

- * calcHydrateLine. - *

- */ - public void calcHydrateLine() { - ThermodynamicOperations opsHyd = new ThermodynamicOperations(system); - try { - opsHyd.hydrateEquilibriumLine(10.0, 300.0); - } catch (Exception e) { - logger.error("error", e); + // check for critical point + double Kvallc = system.getPhase(0).getComponent(nonLinSolver.lc).getx() + / system.getPhase(1).getComponent(nonLinSolver.lc).getx(); + double Kvalhc = system.getPhase(0).getComponent(nonLinSolver.hc).getx() + / system.getPhase(1).getComponent(nonLinSolver.hc).getx(); + // double densV = system.getPhase(0).getDensity(); + // double densL = system.getPhase(1).getDensity(); + + // System.out.println(np + " " + system.getTemperature() + " " + + // system.getPressure() + " " + densV + " " + densL ); + + if ((nonLinSolver.etterCP == false)) { + if (Kvallc < 1.05 && Kvalhc > 0.95) { + // close to the critical point + // invert phase types and find the CP Temp and Press + + // System.out.println("critical point"); + nonLinSolver.npCrit = np; + system.invertPhaseTypes(); + nonLinSolver.etterCP = true; + // the critical point is found from interpolation plynimials based on K=1 of + // the + // most or least volatile component + nonLinSolver.calcCrit(); + } } - - // double[][] hydData = opsHyd.getData(); - } - - /** {@inheritDoc} */ - @Override - public void displayResult() { - DecimalFormat nf = new DecimalFormat(); - nf.setMaximumFractionDigits(1); - nf.applyPattern("####.#"); - if (bubblePointFirst) { - // bubble point side - navn[0] = "bubble point 2"; - navn[1] = "dew point 2"; - navn[2] = "dew point 1"; - navn[3] = "bubble point 1"; - } else { - // dew point side and does not crash - navn[0] = "dew point"; - navn[1] = "bubble point"; - navn[2] = "dew point"; - navn[3] = "bubbl point"; + if (nonLinSolver.calcCP) { + nonLinSolver.calcCP = false; + nonLinSolver.npCrit = np; + nonLinSolver.calcCrit(); } - double TC = system.getTC(); - double PC = system.getPC(); - - String title = "PT-graph TC=" + String.valueOf(nf.format(TC)) + " PC=" - + String.valueOf(nf.format(PC)); - String title3 = "PH-graph TC=" + String.valueOf(nf.format(TC)) + " PC=" - + String.valueOf(nf.format(PC)); - String title4 = "Density-graph TC=" + String.valueOf(nf.format(TC)) + " PC=" - + String.valueOf(nf.format(PC)); - String title5 = "PS-graph TC=" + String.valueOf(nf.format(TC)) + " PC=" - + String.valueOf(nf.format(PC)); - - graph2b graph3 = new graph2b(pointsH2, navn, title3, "Enthalpy [kJ/kg]", "Pressure [bara]"); - graph3.setVisible(true); - // graph3.saveFigure(new String(util.util.FileSystemSettings.tempDir + - // "NeqSimTempFig4.png")); - - graph2b graph4 = new graph2b(pointsV2, navn, title4, "Density [kg/m^3]", "Pressure [bara]"); - graph4.setVisible(true); - // graph4.saveFigure(util.util.FileSystemSettings.tempDir + - // "NeqSimTempFig2.png"); - - graph2b graph5 = - new graph2b(pointsS2, navn, title5, "Entropy [kJ/kg*K]", "Pressure [bara]"); - graph5.setVisible(true); - // graph5.saveFigure(util.util.FileSystemSettings.tempDir + - // "NeqSimTempFig3.png"); - - graph2 = new graph2b(points2, navn, title, "Temperature [K]", "Pressure [bara]"); - graph2.setVisible(true); - // graph2.saveFigure(util.util.FileSystemSettings.tempDir + - // "NeqSimTempFig1.png"); - - /* - * JDialog dialog = new JDialog(); Container dialogContentPane = dialog.getContentPane(); - * dialogContentPane.setLayout(new FlowLayout()); JFreeChartPanel chartPanel = - * graph4.getChartPanel(); dialogContentPane.add(chartPanel); dialog.show(); - */ - } - - /** {@inheritDoc} */ - @Override - public void printToFile(String name) {} - - /** {@inheritDoc} */ - @Override - public double[][] getPoints(int i) { - return points2; - } - - /** {@inheritDoc} */ - @Override - public void addData(String name, double[][] data) { - double[][] localPoints = new double[points2.length + data.length][]; - navn[localPoints.length / 2 - 1] = name; - System.arraycopy(points2, 0, localPoints, 0, points2.length); - System.arraycopy(data, 0, localPoints, points2.length, data.length); - points2 = localPoints; - } - - /** {@inheritDoc} */ - @Override - public double[] get(String name) { - if (name.equals("dewT")) { - return points2[0]; - } - if (name.equals("dewP")) { - return points2[1]; - } - if (name.equals("bubT")) { - return points2[2]; - } - if (name.equals("bubP")) { - return points2[3]; - } - if (name.equals("dewT2")) { - return points2[4]; - } - if (name.equals("dewP2")) { - return points2[5]; - } - if (name.equals("bubT2")) { - return points2[6]; + // stores cricondenbar and cricondentherm + // HERE the new cricoT and crico P values will be called instead + if (system.getTemperature() > cricondenTherm[0]) { + cricondenTherm[1] = system.getPressure(); + cricondenTherm[0] = system.getTemperature(); + } else { + nonLinSolver.ettercricoT = true; } - if (name.equals("bubP2")) { - return points2[7]; + if (system.getPressure() > cricondenBar[1]) { + cricondenBar[0] = system.getTemperature(); + cricondenBar[1] = system.getPressure(); } - if (name.equals("dewH")) { - return pointsH2[2]; + + // Exit criteria + if ((system.getPressure() < minPressure && nonLinSolver.ettercricoT)) { + break; } - if (name.equals("dewDens")) { - return pointsV2[2]; + if (system.getPressure() > maxPressure) { + break; } - if (name.equals("dewS")) { - return pointsS2[2]; + if (system.getTemperature() > Tmin && !restart) { + break; } - if (name.equals("bubH")) { - return pointsH2[0]; + + // Keeps the calculated points + points[0][np - 1] = system.getTemperature(); + points[1][np - 1] = system.getPressure(); + pointsH[np - 1] = + system.getPhase(1).getEnthalpy() / system.getPhase(1).getNumberOfMolesInPhase() + / system.getPhase(1).getMolarMass() / 1e3; + pointsV[np - 1] = system.getPhase(1).getDensity(); + pointsS[np - 1] = + system.getPhase(1).getEntropy() / system.getPhase(1).getNumberOfMolesInPhase() + / system.getPhase(1).getMolarMass() / 1e3; + } + + try { + int ncr = nonLinSolver.getNpCrit(); + if (ncr == 0) { + ncr = np; } - if (name.equals("bubDens")) { - return pointsV2[0]; + int ncr2 = np - ncr; + if (hascopiedPoints) { + // if it enters here the envelope crashed and restarted + // reallocate to have all values + points2 = new double[8][]; + pointsH2 = new double[8][]; + pointsS2 = new double[8][]; + pointsV2 = new double[8][]; } - if (name.equals("bubS")) { - return pointsS2[0]; + + // points2 are plotted + points2[0] = new double[ncr + 1]; + points2[1] = new double[ncr + 1]; + pointsH2[0] = new double[ncr + 1]; + pointsH2[1] = new double[ncr + 1]; + pointsS2[0] = new double[ncr + 1]; + pointsS2[1] = new double[ncr + 1]; + pointsV2[0] = new double[ncr + 1]; + pointsV2[1] = new double[ncr + 1]; + + if (ncr2 > 2) { + points2[2] = new double[ncr2 - 2]; + points2[3] = new double[ncr2 - 2]; + pointsH2[2] = new double[ncr2 - 2]; + pointsH2[3] = new double[ncr2 - 2]; + pointsS2[2] = new double[ncr2 - 2]; + pointsS2[3] = new double[ncr2 - 2]; + pointsV2[2] = new double[ncr2 - 2]; + pointsV2[3] = new double[ncr2 - 2]; + } else { + points2[2] = new double[0]; + points2[3] = new double[0]; + pointsH2[2] = new double[0]; + pointsH2[3] = new double[0]; + pointsS2[2] = new double[0]; + pointsS2[3] = new double[0]; + pointsV2[2] = new double[0]; + pointsV2[3] = new double[0]; } - if (name.equals("cricondentherm")) { - return cricondenTherm; + + for (int i = 0; i < ncr; i++) { + // second branch up to critical point + points2[0][i] = points[0][i]; + points2[1][i] = points[1][i]; + pointsH2[1][i] = points[1][i]; + pointsH2[0][i] = pointsH[i]; + pointsS2[1][i] = points[1][i]; + pointsS2[0][i] = pointsS[i]; + pointsV2[1][i] = points[1][i]; + pointsV2[0][i] = pointsV[i]; } - if (name.equals("cricondenbar")) { - return cricondenBar; + if (ncr2 > 2) { + for (int i = 1; i < (ncr2 - 2); i++) { + // second branch after the critical point + points2[2][i] = points[0][i + ncr - 1]; + points2[3][i] = points[1][i + ncr - 1]; + pointsH2[3][i] = points[1][i + ncr - 1]; + pointsH2[2][i] = pointsH[i + ncr - 1]; + pointsS2[3][i] = points[1][i + ncr - 1]; + pointsS2[2][i] = pointsS[i + ncr - 1]; + pointsV2[3][i] = points[1][i + ncr - 1]; + pointsV2[2][i] = pointsV[i + ncr - 1]; + } } - if (name.equals("criticalPoint1")) { - return new double[] {system.getTC(), system.getPC()}; + + if (hascopiedPoints) { + if (ncrfirst > npfirst) { + ncr = copiedPoints[0].length - 1; + ncr2 = npfirst - ncr; + npfirst = npfirst - 1; + } else { + ncr = ncrfirst; + ncr2 = npfirst - ncr; + } + + points2[4] = new double[ncr + 1]; + points2[5] = new double[ncr + 1]; + pointsH2[4] = new double[ncr + 1]; + pointsH2[5] = new double[ncr + 1]; + pointsS2[4] = new double[ncr + 1]; + pointsS2[5] = new double[ncr + 1]; + pointsV2[4] = new double[ncr + 1]; + pointsV2[5] = new double[ncr + 1]; + + if (ncr2 > 2) { + points2[6] = new double[ncr2 - 2]; + points2[7] = new double[ncr2 - 2]; + pointsH2[6] = new double[ncr2 - 2]; + pointsH2[7] = new double[ncr2 - 2]; + pointsS2[6] = new double[ncr2 - 2]; + pointsS2[7] = new double[ncr2 - 2]; + pointsV2[6] = new double[ncr2 - 2]; + pointsV2[7] = new double[ncr2 - 2]; + } else { + points2[6] = new double[0]; + points2[7] = new double[0]; + pointsH2[6] = new double[0]; + pointsH2[7] = new double[0]; + pointsS2[6] = new double[0]; + pointsS2[7] = new double[0]; + pointsV2[6] = new double[0]; + pointsV2[7] = new double[0]; + } + + for (int i = 0; i < ncr; i++) { + // first branch up to the critical point + points2[4][i] = copiedPoints[0][i]; + points2[5][i] = copiedPoints[1][i]; + pointsH2[5][i] = copiedPoints[1][i]; + pointsH2[4][i] = copiedPoints[2][i]; + pointsS2[5][i] = copiedPoints[1][i]; + pointsS2[4][i] = copiedPoints[3][i]; + pointsV2[5][i] = copiedPoints[1][i]; + pointsV2[4][i] = copiedPoints[4][i]; + } + if (ncr2 > 2) { + for (int i = 1; i < (ncr2 - 2); i++) { + // first branch after the critical point + points2[6][i] = copiedPoints[0][i + ncr - 1]; + points2[7][i] = copiedPoints[1][i + ncr - 1]; + pointsH2[7][i] = copiedPoints[1][i + ncr - 1]; + pointsH2[6][i] = copiedPoints[2][i + ncr - 1]; + pointsS2[7][i] = copiedPoints[1][i + ncr - 1]; + pointsS2[6][i] = copiedPoints[3][i + ncr - 1]; + pointsV2[7][i] = copiedPoints[1][i + ncr - 1]; + pointsV2[6][i] = copiedPoints[4][i + ncr - 1]; + } + } } - if (name.equals("criticalPoint2")) { - return new double[] {0, 0}; - } else { - return null; + + // critical point + system.setTemperature(system.getTC()); + system.setPressure(system.getPC()); + + system.init(3); + + points2[0][ncr] = system.getTC(); + points2[1][ncr] = system.getPC(); + + if (ncr2 > 2) { + points2[2][0] = system.getTC(); + points2[3][0] = system.getPC(); } + } catch (Exception e2) { + // double nef = 0.; + logger.error("error", e2); + } + /* + * try { if (outputToFile) { // update this String name1 = new String(); name1 = fileName + + * "Dew.nc"; file1 = new + * neqsim.dataPresentation.fileHandeling.createNetCDF.netCDF2D.NetCdf2D(); + * file1.setOutputFileName(name1); file1.setXvalues(points2[2], "temp", "sec"); + * file1.setYvalues(points2[3], "pres", "meter"); file1.createFile(); + * + * String name2 = new String(); name2 = fileName + "Bub.nc"; file2 = new + * neqsim.dataPresentation.fileHandeling.createNetCDF.netCDF2D.NetCdf2D(); + * file2.setOutputFileName(name2); file2.setXvalues(points2[0], "temp", "sec"); + * file2.setYvalues(points2[1], "pres", "meter"); file2.createFile(); } } catch (Exception e3) + * { // double nef = 0.; logger.error("error", e3); } + */ + } catch (Exception e4) { + // double nef = 0.; + logger.error("error", e4); } - - /** {@inheritDoc} */ - @Override - public void createNetCdfFile(String name) { - fileName = name; + } + + /** + *

+ * calcHydrateLine. + *

+ */ + public void calcHydrateLine() { + ThermodynamicOperations opsHyd = new ThermodynamicOperations(system); + try { + opsHyd.hydrateEquilibriumLine(10.0, 300.0); + } catch (Exception e) { + logger.error("error", e); } - /** - * Getter for property bubblePointFirst. - * - * @return Value of property bubblePointFirst. - */ - public boolean isBubblePointFirst() { - return bubblePointFirst; + // double[][] hydData = opsHyd.getData(); + } + + /** {@inheritDoc} */ + @Override + public void displayResult() { + DecimalFormat nf = new DecimalFormat(); + nf.setMaximumFractionDigits(1); + nf.applyPattern("####.#"); + if (bubblePointFirst) { + // bubble point side + navn[0] = "bubble point 2"; + navn[1] = "dew point 2"; + navn[2] = "dew point 1"; + navn[3] = "bubble point 1"; + } else { + // dew point side and does not crash + navn[0] = "dew point"; + navn[1] = "bubble point"; + navn[2] = "dew point"; + navn[3] = "bubbl point"; } - /** - * Setter for property bubblePointFirst. - * - * @param bubblePointFirst New value of property bubblePointFirst. + double TC = system.getTC(); + double PC = system.getPC(); + + String title = + "PT-graph TC=" + String.valueOf(nf.format(TC)) + " PC=" + String.valueOf(nf.format(PC)); + String title3 = + "PH-graph TC=" + String.valueOf(nf.format(TC)) + " PC=" + String.valueOf(nf.format(PC)); + String title4 = "Density-graph TC=" + String.valueOf(nf.format(TC)) + " PC=" + + String.valueOf(nf.format(PC)); + String title5 = + "PS-graph TC=" + String.valueOf(nf.format(TC)) + " PC=" + String.valueOf(nf.format(PC)); + + graph2b graph3 = new graph2b(pointsH2, navn, title3, "Enthalpy [kJ/kg]", "Pressure [bara]"); + graph3.setVisible(true); + // graph3.saveFigure(new String(util.util.FileSystemSettings.tempDir + + // "NeqSimTempFig4.png")); + + graph2b graph4 = new graph2b(pointsV2, navn, title4, "Density [kg/m^3]", "Pressure [bara]"); + graph4.setVisible(true); + // graph4.saveFigure(util.util.FileSystemSettings.tempDir + + // "NeqSimTempFig2.png"); + + graph2b graph5 = new graph2b(pointsS2, navn, title5, "Entropy [kJ/kg*K]", "Pressure [bara]"); + graph5.setVisible(true); + // graph5.saveFigure(util.util.FileSystemSettings.tempDir + + // "NeqSimTempFig3.png"); + + graph2 = new graph2b(points2, navn, title, "Temperature [K]", "Pressure [bara]"); + graph2.setVisible(true); + // graph2.saveFigure(util.util.FileSystemSettings.tempDir + + // "NeqSimTempFig1.png"); + + /* + * JDialog dialog = new JDialog(); Container dialogContentPane = dialog.getContentPane(); + * dialogContentPane.setLayout(new FlowLayout()); JFreeChartPanel chartPanel = + * graph4.getChartPanel(); dialogContentPane.add(chartPanel); dialog.show(); */ - public void setBubblePointFirst(boolean bubblePointFirst) { - this.bubblePointFirst = bubblePointFirst; + } + + /** {@inheritDoc} */ + @Override + public void printToFile(String name) {} + + /** {@inheritDoc} */ + @Override + public double[][] getPoints(int i) { + return points2; + } + + /** {@inheritDoc} */ + @Override + public void addData(String name, double[][] data) { + double[][] localPoints = new double[points2.length + data.length][]; + navn[localPoints.length / 2 - 1] = name; + System.arraycopy(points2, 0, localPoints, 0, points2.length); + System.arraycopy(data, 0, localPoints, points2.length, data.length); + points2 = localPoints; + } + + /** {@inheritDoc} */ + @Override + public double[] get(String name) { + if (name.equals("dewT")) { + return points2[0]; } - - /** {@inheritDoc} */ - @Override - public String[][] getResultTable() { - return null; + if (name.equals("dewP")) { + return points2[1]; + } + if (name.equals("bubT")) { + return points2[2]; + } + if (name.equals("bubP")) { + return points2[3]; + } + if (name.equals("dewT2")) { + return points2[4]; + } + if (name.equals("dewP2")) { + return points2[5]; + } + if (name.equals("bubT2")) { + return points2[6]; + } + if (name.equals("bubP2")) { + return points2[7]; + } + if (name.equals("dewH")) { + return pointsH2[2]; + } + if (name.equals("dewDens")) { + return pointsV2[2]; + } + if (name.equals("dewS")) { + return pointsS2[2]; + } + if (name.equals("bubH")) { + return pointsH2[0]; + } + if (name.equals("bubDens")) { + return pointsV2[0]; + } + if (name.equals("bubS")) { + return pointsS2[0]; + } + if (name.equals("cricondentherm")) { + return cricondenTherm; + } + if (name.equals("cricondenbar")) { + return cricondenBar; + } + if (name.equals("criticalPoint1")) { + return new double[] {system.getTC(), system.getPC()}; + } + if (name.equals("criticalPoint2")) { + return new double[] {0, 0}; + } else { + return null; + } + } + + /** + * Getter for property bubblePointFirst. + * + * @return Value of property bubblePointFirst. + */ + public boolean isBubblePointFirst() { + return bubblePointFirst; + } + + /** + * Setter for property bubblePointFirst. + * + * @param bubblePointFirst New value of property bubblePointFirst. + */ + public void setBubblePointFirst(boolean bubblePointFirst) { + this.bubblePointFirst = bubblePointFirst; + } + + /** {@inheritDoc} */ + @Override + public String[][] getResultTable() { + return null; + } + + /** + *

+ * tempKWilson. + *

+ * + * @param beta a double + * @param P a double + * @return a double + */ + public double tempKWilson(double beta, double P) { + // Initiallizes the temperature of a saturation point for given pressure + // based on K values of Wilson + // see Michelsen book thermodynamics & computational aspects + + double initTc = 0.; + double initPc = 0.; + double initAc = 0.; + double Tstart = 0.; + double Tstartold = 0.; + double initT = 0; + double dinitT = 0; + int numberOfComponents = system.getPhase(0).getNumberOfComponents(); + int lc = 0; + int hc = 0; + + double[] Kwil = new double[numberOfComponents]; + + double min = 100000.; + double max = 0.; + + for (int i = 0; i < numberOfComponents; i++) { + if (system.getPhase(0).getComponents()[i].getTC() > max) { + max = system.getPhase(0).getComponents()[i].getTC(); + hc = i; + } + if (system.getPhase(0).getComponents()[i].getTC() < min) { + min = system.getPhase(0).getComponents()[i].getTC(); + lc = i; + } } - /** - *

- * tempKWilson. - *

- * - * @param beta a double - * @param P a double - * @return a double - */ - public double tempKWilson(double beta, double P) { - // Initiallizes the temperature of a saturation point for given pressure - // based on K values of Wilson - // see Michelsen book thermodynamics & computational aspects - - double initTc = 0.; - double initPc = 0.; - double initAc = 0.; - double Tstart = 0.; - double Tstartold = 0.; - double initT = 0; - double dinitT = 0; - int numberOfComponents = system.getPhase(0).getNumberOfComponents(); - int lc = 0; - int hc = 0; - - double[] Kwil = new double[numberOfComponents]; - - double min = 100000.; - double max = 0.; - - for (int i = 0; i < numberOfComponents; i++) { - if (system.getPhase(0).getComponents()[i].getTC() > max) { - max = system.getPhase(0).getComponents()[i].getTC(); - hc = i; - } - if (system.getPhase(0).getComponents()[i].getTC() < min) { - min = system.getPhase(0).getComponents()[i].getTC(); - lc = i; - } - } - - if (beta <= 0.5) { - initTc = system.getPhase(0).getComponents()[lc].getTC(); // closer to bubble point get - // the lightest - // component - initPc = system.getPhase(0).getComponents()[lc].getPC(); - initAc = system.getPhase(0).getComponents()[lc].getAcentricFactor(); - } else if (beta > 0.5) { - initTc = system.getPhase(0).getComponents()[hc].getTC(); // closer to dew point get the - // heaviest component - initPc = system.getPhase(0).getComponents()[hc].getPC(); - initAc = system.getPhase(0).getComponents()[hc].getAcentricFactor(); + if (beta <= 0.5) { + initTc = system.getPhase(0).getComponents()[lc].getTC(); // closer to bubble point get + // the lightest + // component + initPc = system.getPhase(0).getComponents()[lc].getPC(); + initAc = system.getPhase(0).getComponents()[lc].getAcentricFactor(); + } else if (beta > 0.5) { + initTc = system.getPhase(0).getComponents()[hc].getTC(); // closer to dew point get the + // heaviest component + initPc = system.getPhase(0).getComponents()[hc].getPC(); + initAc = system.getPhase(0).getComponents()[hc].getAcentricFactor(); + } + Tstart = initTc * 5.373 * (1 + initAc) / (5.373 * (1 + initAc) - Math.log(P / initPc)); // initial + // T + // based + // on + // the + // lighterst/heaviest + // component + + // solve for Tstart with Newton + for (int i = 0; i < 1000; i++) { + initT = 0.; + dinitT = 0.; + for (int j = 0; j < numberOfComponents; j++) { + Kwil[j] = system.getPhase(0).getComponents()[j].getPC() / P + * Math.exp(5.373 * (1. + system.getPhase(0).getComponents()[j].getAcentricFactor()) + * (1. - system.getPhase(0).getComponents()[j].getTC() / Tstart)); + system.getPhases()[0].getComponents()[j].setK(Math.log(Kwil[j])); + } + + for (int j = 0; j < numberOfComponents; j++) { + if (beta < 0.5) { + initT = initT + system.getPhase(0).getComponents()[j].getz() * Kwil[j]; + dinitT = dinitT + system.getPhase(0).getComponents()[j].getz() * Kwil[j] * 5.373 + * (1 + system.getPhase(0).getComponents()[j].getAcentricFactor()) + * system.getPhase(0).getComponents()[j].getTC() / (Tstart * Tstart); + } else { + initT = initT + system.getPhase(0).getComponents()[j].getz() / Kwil[j]; + dinitT = dinitT - system.getPhase(0).getComponents()[j].getz() / Kwil[j] * 5.373 + * (1 + system.getPhase(0).getComponents()[j].getAcentricFactor()) + * system.getPhase(0).getComponents()[j].getTC() / (Tstart * Tstart); } - Tstart = initTc * 5.373 * (1 + initAc) / (5.373 * (1 + initAc) - Math.log(P / initPc)); // initial - // T - // based - // on - // the - // lighterst/heaviest - // component - - // solve for Tstart with Newton - for (int i = 0; i < 1000; i++) { - initT = 0.; - dinitT = 0.; - for (int j = 0; j < numberOfComponents; j++) { - Kwil[j] = system.getPhase(0).getComponents()[j].getPC() / P - * Math.exp(5.373 - * (1. + system.getPhase(0).getComponents()[j].getAcentricFactor()) - * (1. - system.getPhase(0).getComponents()[j].getTC() / Tstart)); - system.getPhases()[0].getComponents()[j].setK(Math.log(Kwil[j])); - } - - for (int j = 0; j < numberOfComponents; j++) { - if (beta < 0.5) { - initT = initT + system.getPhase(0).getComponents()[j].getz() * Kwil[j]; - dinitT = dinitT + system.getPhase(0).getComponents()[j].getz() * Kwil[j] * 5.373 - * (1 + system.getPhase(0).getComponents()[j].getAcentricFactor()) - * system.getPhase(0).getComponents()[j].getTC() / (Tstart * Tstart); - } else { - initT = initT + system.getPhase(0).getComponents()[j].getz() / Kwil[j]; - dinitT = dinitT - system.getPhase(0).getComponents()[j].getz() / Kwil[j] * 5.373 - * (1 + system.getPhase(0).getComponents()[j].getAcentricFactor()) - * system.getPhase(0).getComponents()[j].getTC() / (Tstart * Tstart); - } - } - - initT = initT - 1.; - if (Math.abs(initT / dinitT) > 0.1 * Tstart) { - Tstart = Tstart - 0.001 * initT / dinitT; - } else { - Tstart = Tstart - initT / dinitT; - } + } - if (Math.abs(Tstart - Tstartold) < 1.e-5) { - return Tstart; - } - Tstartold = Tstart; - } + initT = initT - 1.; + if (Math.abs(initT / dinitT) > 0.1 * Tstart) { + Tstart = Tstart - 0.001 * initT / dinitT; + } else { + Tstart = Tstart - initT / dinitT; + } + if (Math.abs(Tstart - Tstartold) < 1.e-5) { return Tstart; + } + Tstartold = Tstart; } - /** {@inheritDoc} */ - @Override - public org.jfree.chart.JFreeChart getJFreeChart(String name) { - DecimalFormat nf = new DecimalFormat(); - nf.setMaximumFractionDigits(1); - nf.applyPattern("####.#"); - - double TC = system.getTC(); - double PC = system.getPC(); - logger.info("tc : " + TC + " PC : " + PC); - String[] navn = {"bubble point", "dew point", "bubble point", "dew point"}; - String title = "PT-graph. TC=" + String.valueOf(nf.format(TC)) + "K, PC=" - + String.valueOf(nf.format(PC) + " bara"); - graph2 = new graph2b(points2, navn, title, "Temperature [K]", "Pressure [bara]"); - return graph2.getChart(); - } + return Tstart; + } + + /** {@inheritDoc} */ + @Override + public org.jfree.chart.JFreeChart getJFreeChart(String name) { + DecimalFormat nf = new DecimalFormat(); + nf.setMaximumFractionDigits(1); + nf.applyPattern("####.#"); + + double TC = system.getTC(); + double PC = system.getPC(); + logger.info("tc : " + TC + " PC : " + PC); + String[] navn = {"bubble point", "dew point", "bubble point", "dew point"}; + String title = "PT-graph. TC=" + String.valueOf(nf.format(TC)) + "K, PC=" + + String.valueOf(nf.format(PC) + " bara"); + graph2 = new graph2b(points2, navn, title, "Temperature [K]", "Pressure [bara]"); + return graph2.getChart(); + } } diff --git a/src/main/java/neqsim/thermodynamicOperations/phaseEnvelopeOps/multicomponentEnvelopeOps/pTphaseEnvelopeNew.java b/src/main/java/neqsim/thermodynamicOperations/phaseEnvelopeOps/multicomponentEnvelopeOps/pTphaseEnvelopeNew.java index 49b90712b2..2e882d5c3f 100644 --- a/src/main/java/neqsim/thermodynamicOperations/phaseEnvelopeOps/multicomponentEnvelopeOps/pTphaseEnvelopeNew.java +++ b/src/main/java/neqsim/thermodynamicOperations/phaseEnvelopeOps/multicomponentEnvelopeOps/pTphaseEnvelopeNew.java @@ -21,392 +21,374 @@ * @version $Id: $Id */ public class pTphaseEnvelopeNew extends BaseOperation { - private static final long serialVersionUID = 1000; - static Logger logger = LogManager.getLogger(pTphaseEnvelopeNew.class); - - graph2b graph2 = null; - SystemInterface system; - double[] cricondenTherm = new double[3]; - double[] cricondenBar = new double[3]; - double phaseFraction = 1e-10; - neqsim.dataPresentation.fileHandeling.createNetCDF.netCDF2D.NetCdf2D file1; - neqsim.dataPresentation.fileHandeling.createNetCDF.netCDF2D.NetCdf2D file2; - int i, j = 0, nummer = 0, iterations = 0, maxNumberOfIterations = 10000; - double lowPres = 1.0; - boolean outputToFile = false; - JProgressBar monitor; - JFrame mainFrame; - String fileName = "c:/file"; - JPanel mainPanel; - double temp = 0, pres = 0; - double[][] points = new double[2][]; - double[] pointsH = new double[10000]; - double[][] pointsH2 = new double[4][]; - double[] pointsV = new double[10000]; - - ; - double[][] pointsV2 = new double[4][]; - double[] pointsS = new double[10000]; - double[][] pointsS2 = new double[4][]; - public double[][] points2 = new double[4][]; - int np = 0; - int speceq = 0; - - /** - *

- * Constructor for pTphaseEnvelopeNew. - *

- */ - public pTphaseEnvelopeNew() {} - - /** - *

- * Constructor for pTphaseEnvelopeNew. - *

- * - * @param system a {@link neqsim.thermo.system.SystemInterface} object - * @param name a {@link java.lang.String} object - * @param phaseFraction a double - * @param lowPres a double - */ - public pTphaseEnvelopeNew(SystemInterface system, String name, double phaseFraction, - double lowPres) { - this.system = system; - this.phaseFraction = phaseFraction; + private static final long serialVersionUID = 1000; + static Logger logger = LogManager.getLogger(pTphaseEnvelopeNew.class); + + graph2b graph2 = null; + SystemInterface system; + double[] cricondenTherm = new double[3]; + double[] cricondenBar = new double[3]; + double phaseFraction = 1e-10; + int i, j = 0, nummer = 0, iterations = 0, maxNumberOfIterations = 10000; + double lowPres = 1.0; + boolean outputToFile = false; + JProgressBar monitor; + JFrame mainFrame; + String fileName = "c:/file"; + JPanel mainPanel; + double temp = 0, pres = 0; + double[][] points = new double[2][]; + double[] pointsH = new double[10000]; + double[][] pointsH2 = new double[4][]; + double[] pointsV = new double[10000]; + + ; + double[][] pointsV2 = new double[4][]; + double[] pointsS = new double[10000]; + double[][] pointsS2 = new double[4][]; + public double[][] points2 = new double[4][]; + int np = 0; + int speceq = 0; + + /** + *

+ * Constructor for pTphaseEnvelopeNew. + *

+ */ + public pTphaseEnvelopeNew() {} + + /** + *

+ * Constructor for pTphaseEnvelopeNew. + *

+ * + * @param system a {@link neqsim.thermo.system.SystemInterface} object + * @param name a {@link java.lang.String} object + * @param phaseFraction a double + * @param lowPres a double + */ + public pTphaseEnvelopeNew(SystemInterface system, String name, double phaseFraction, + double lowPres) { + this.system = system; + this.phaseFraction = phaseFraction; + + this.lowPres = lowPres; + + if (name != null) { + outputToFile = true; + fileName = name; + } + mainFrame = new JFrame("Progress Bar"); + mainPanel = new JPanel(); + mainPanel.setSize(200, 100); + mainFrame.getContentPane().setLayout(new FlowLayout()); + mainPanel.setLayout(new FlowLayout()); + mainFrame.setSize(200, 100); + monitor = new JProgressBar(0, 00); + monitor.setSize(200, 100); + monitor.setStringPainted(true); + mainPanel.add(monitor); + mainFrame.getContentPane().add(mainPanel); + mainFrame.setVisible(true); + } + + /** {@inheritDoc} */ + @Override + public void run() { + try { + points[0] = new double[10000]; + points[1] = new double[10000]; + + system.setPressure(lowPres); + + ThermodynamicOperations testOps = new ThermodynamicOperations(system); + + try { + testOps.bubblePointTemperatureFlash(); + } catch (Exception e) { + e.toString(); + return; + } + logger.info("temperature bubT = " + system.getTemperature()); + + sysNewtonRhapsonPhaseEnvelope2 nonLinSolver = new sysNewtonRhapsonPhaseEnvelope2(system); + nonLinSolver.solve(1); + nonLinSolver.calcInc(1); + + for (np = 1; np < 5; np++) { + if (np % 5 == 0) { + monitor.setValue(np); + monitor.setString("Calculated points: " + np); + } - this.lowPres = lowPres; + nonLinSolver.calcInc(np); + nonLinSolver.solve(np); - if (name != null) { - outputToFile = true; - fileName = name; + if (system.getTemperature() > cricondenTherm[0]) { + cricondenTherm[1] = system.getPressure(); + cricondenTherm[0] = system.getTemperature(); + } + if (system.getPressure() > cricondenBar[1]) { + cricondenBar[0] = system.getTemperature(); + cricondenBar[1] = system.getPressure(); } - mainFrame = new JFrame("Progress Bar"); - mainPanel = new JPanel(); - mainPanel.setSize(200, 100); - mainFrame.getContentPane().setLayout(new FlowLayout()); - mainPanel.setLayout(new FlowLayout()); - mainFrame.setSize(200, 100); - monitor = new JProgressBar(0, 00); - monitor.setSize(200, 100); - monitor.setStringPainted(true); - mainPanel.add(monitor); - mainFrame.getContentPane().add(mainPanel); - mainFrame.setVisible(true); - } - /** {@inheritDoc} */ - @Override - public void run() { - try { - points[0] = new double[10000]; - points[1] = new double[10000]; - - system.setPressure(lowPres); - - ThermodynamicOperations testOps = new ThermodynamicOperations(system); - - try { - testOps.bubblePointTemperatureFlash(); - } catch (Exception e) { - e.toString(); - return; - } - logger.info("temperature bubT = " + system.getTemperature()); - - sysNewtonRhapsonPhaseEnvelope2 nonLinSolver = - new sysNewtonRhapsonPhaseEnvelope2(system); - nonLinSolver.solve(1); - nonLinSolver.calcInc(1); - - for (np = 1; np < 5; np++) { - if (np % 5 == 0) { - monitor.setValue(np); - monitor.setString("Calculated points: " + np); - } - - nonLinSolver.calcInc(np); - nonLinSolver.solve(np); - - if (system.getTemperature() > cricondenTherm[0]) { - cricondenTherm[1] = system.getPressure(); - cricondenTherm[0] = system.getTemperature(); - } - if (system.getPressure() > cricondenBar[1]) { - cricondenBar[0] = system.getTemperature(); - cricondenBar[1] = system.getPressure(); - } - - if (Double.isNaN(system.getTemperature()) - || Double.isNaN(system.getTemperature())) {// || - // system.getPressure() - // < lowPres) { - points[0][np - 1] = points[0][np - 3]; - points[1][np - 1] = points[1][np - 3]; - pointsH[np - 1] = pointsH[np - 3]; - pointsV[np - 1] = pointsV[np - 3]; - pointsS[np - 1] = pointsS[np - 3]; - - // logger.info("avbryter" + np); - break; - } - // logger.info("Ideal pres: " + getPressure()); - // logger.info("temp: " + system.getTemperature()); - points[0][np - 1] = system.getTemperature(); - points[1][np - 1] = system.getPressure(); - pointsH[np - 1] = system.getPhase(1).getEnthalpy() - / system.getPhase(1).getNumberOfMolesInPhase() - / system.getPhase(1).getMolarMass() / 1e3; - pointsV[np - 1] = system.getPhase(1).getDensity(); - pointsS[np - 1] = system.getPhase(1).getEntropy() - / system.getPhase(1).getNumberOfMolesInPhase() - / system.getPhase(1).getMolarMass() / 1e3; - } - - int ncr = nonLinSolver.getNpCrit(); - int ncr2 = np - ncr; - - logger.info("ncr: " + ncr + " ncr2 . " + ncr2); - points2[0] = new double[ncr + 1]; - points2[1] = new double[ncr + 1]; - pointsH2[0] = new double[ncr + 1]; - pointsH2[1] = new double[ncr + 1]; - pointsS2[0] = new double[ncr + 1]; - pointsS2[1] = new double[ncr + 1]; - pointsV2[0] = new double[ncr + 1]; - pointsV2[1] = new double[ncr + 1]; - if (ncr2 > 2) { - points2[2] = new double[ncr2 - 2]; - points2[3] = new double[ncr2 - 2]; - pointsH2[2] = new double[ncr2 - 2]; - pointsH2[3] = new double[ncr2 - 2]; - pointsV2[2] = new double[ncr2 - 2]; - pointsV2[3] = new double[ncr2 - 2]; - pointsS2[2] = new double[ncr2 - 2]; - pointsS2[3] = new double[ncr2 - 2]; - } else { - points2[2] = new double[0]; - points2[3] = new double[0]; - pointsH2[2] = new double[0]; - pointsH2[3] = new double[0]; - pointsV2[2] = new double[0]; - pointsV2[3] = new double[0]; - pointsS2[2] = new double[0]; - pointsS2[3] = new double[0]; - } - - for (int i = 0; i < ncr; i++) { - points2[0][i] = points[0][i]; - points2[1][i] = points[1][i]; - - pointsH2[1][i] = points[1][i]; - pointsH2[0][i] = pointsH[i]; - - pointsS2[1][i] = points[1][i]; - pointsS2[0][i] = pointsS[i]; - - pointsV2[1][i] = points[1][i]; - pointsV2[0][i] = pointsV[i]; - } - - system.setTemperature(system.getTC() + 0.001); - system.setPressure(system.getPC() + 0.001); - system.init(3); - - points2[0][ncr] = system.getTC(); - points2[1][ncr] = system.getPC(); - - pointsH2[1][ncr] = system.getPC(); - pointsH2[0][ncr] = - system.getPhase(1).getEnthalpy() / system.getPhase(1).getNumberOfMolesInPhase() - / system.getPhase(1).getMolarMass() / 1e3; - - pointsS2[1][ncr] = system.getPC(); - pointsS2[0][ncr] = - system.getPhase(1).getEntropy() / system.getPhase(1).getNumberOfMolesInPhase() - / system.getPhase(1).getMolarMass() / 1e3; - - pointsV2[1][ncr] = system.getPC(); - pointsV2[0][ncr] = system.getPhase(1).getDensity(); - - if (ncr2 > 2) { - points2[2][0] = system.getTC(); - points2[3][0] = system.getPC(); - pointsH2[3][0] = system.getPC(); - pointsH2[2][0] = system.getPhase(1).getEnthalpy() - / system.getPhase(1).getNumberOfMolesInPhase() - / system.getPhase(1).getMolarMass() / 1e3; - pointsS2[3][0] = system.getPC(); - pointsS2[2][0] = system.getPhase(1).getEntropy() - / system.getPhase(1).getNumberOfMolesInPhase() - / system.getPhase(1).getMolarMass() / 1e3; - pointsV2[3][0] = system.getPC(); - pointsV2[2][0] = system.getPhase(1).getDensity(); - - for (int i = 1; i < (ncr2 - 2); i++) { - points2[2][i] = points[0][i + ncr - 1]; - points2[3][i] = points[1][i + ncr - 1]; - - pointsH2[3][i] = points[1][i + ncr - 1]; - pointsH2[2][i] = pointsH[i + ncr - 1]; - - pointsS2[3][i] = points[1][i + ncr - 1]; - pointsS2[2][i] = pointsS[i + ncr - 1]; - - pointsV2[3][i] = points[1][i + ncr - 1]; - pointsV2[2][i] = pointsV[i + ncr - 1]; - } - } - // monitor.close(); - mainFrame.setVisible(false); - - if (outputToFile) { - String name1 = new String(); - name1 = fileName + "Dew.nc"; - file1 = new neqsim.dataPresentation.fileHandeling.createNetCDF.netCDF2D.NetCdf2D(); - file1.setOutputFileName(name1); - file1.setXvalues(points2[2], "temp", "sec"); - file1.setYvalues(points2[3], "pres", "meter"); - file1.createFile(); - - String name2 = new String(); - name2 = fileName + "Bub.nc"; - file2 = new neqsim.dataPresentation.fileHandeling.createNetCDF.netCDF2D.NetCdf2D(); - file2.setOutputFileName(name2); - file2.setXvalues(points2[0], "temp", "sec"); - file2.setYvalues(points2[1], "pres", "meter"); - file2.createFile(); - } - } catch (Exception e) { - logger.error("error", e); + if (Double.isNaN(system.getTemperature()) || Double.isNaN(system.getTemperature())) {// || + // system.getPressure() + // < + // lowPres) + // { + points[0][np - 1] = points[0][np - 3]; + points[1][np - 1] = points[1][np - 3]; + pointsH[np - 1] = pointsH[np - 3]; + pointsV[np - 1] = pointsV[np - 3]; + pointsS[np - 1] = pointsS[np - 3]; + + // logger.info("avbryter" + np); + break; + } + // logger.info("Ideal pres: " + getPressure()); + // logger.info("temp: " + system.getTemperature()); + points[0][np - 1] = system.getTemperature(); + points[1][np - 1] = system.getPressure(); + pointsH[np - 1] = + system.getPhase(1).getEnthalpy() / system.getPhase(1).getNumberOfMolesInPhase() + / system.getPhase(1).getMolarMass() / 1e3; + pointsV[np - 1] = system.getPhase(1).getDensity(); + pointsS[np - 1] = + system.getPhase(1).getEntropy() / system.getPhase(1).getNumberOfMolesInPhase() + / system.getPhase(1).getMolarMass() / 1e3; + } + + int ncr = nonLinSolver.getNpCrit(); + int ncr2 = np - ncr; + + logger.info("ncr: " + ncr + " ncr2 . " + ncr2); + points2[0] = new double[ncr + 1]; + points2[1] = new double[ncr + 1]; + pointsH2[0] = new double[ncr + 1]; + pointsH2[1] = new double[ncr + 1]; + pointsS2[0] = new double[ncr + 1]; + pointsS2[1] = new double[ncr + 1]; + pointsV2[0] = new double[ncr + 1]; + pointsV2[1] = new double[ncr + 1]; + if (ncr2 > 2) { + points2[2] = new double[ncr2 - 2]; + points2[3] = new double[ncr2 - 2]; + pointsH2[2] = new double[ncr2 - 2]; + pointsH2[3] = new double[ncr2 - 2]; + pointsV2[2] = new double[ncr2 - 2]; + pointsV2[3] = new double[ncr2 - 2]; + pointsS2[2] = new double[ncr2 - 2]; + pointsS2[3] = new double[ncr2 - 2]; + } else { + points2[2] = new double[0]; + points2[3] = new double[0]; + pointsH2[2] = new double[0]; + pointsH2[3] = new double[0]; + pointsV2[2] = new double[0]; + pointsV2[3] = new double[0]; + pointsS2[2] = new double[0]; + pointsS2[3] = new double[0]; + } + + for (int i = 0; i < ncr; i++) { + points2[0][i] = points[0][i]; + points2[1][i] = points[1][i]; + + pointsH2[1][i] = points[1][i]; + pointsH2[0][i] = pointsH[i]; + + pointsS2[1][i] = points[1][i]; + pointsS2[0][i] = pointsS[i]; + + pointsV2[1][i] = points[1][i]; + pointsV2[0][i] = pointsV[i]; + } + + system.setTemperature(system.getTC() + 0.001); + system.setPressure(system.getPC() + 0.001); + system.init(3); + + points2[0][ncr] = system.getTC(); + points2[1][ncr] = system.getPC(); + + pointsH2[1][ncr] = system.getPC(); + pointsH2[0][ncr] = system.getPhase(1).getEnthalpy() + / system.getPhase(1).getNumberOfMolesInPhase() / system.getPhase(1).getMolarMass() / 1e3; + + pointsS2[1][ncr] = system.getPC(); + pointsS2[0][ncr] = system.getPhase(1).getEntropy() + / system.getPhase(1).getNumberOfMolesInPhase() / system.getPhase(1).getMolarMass() / 1e3; + + pointsV2[1][ncr] = system.getPC(); + pointsV2[0][ncr] = system.getPhase(1).getDensity(); + + if (ncr2 > 2) { + points2[2][0] = system.getTC(); + points2[3][0] = system.getPC(); + pointsH2[3][0] = system.getPC(); + pointsH2[2][0] = + system.getPhase(1).getEnthalpy() / system.getPhase(1).getNumberOfMolesInPhase() + / system.getPhase(1).getMolarMass() / 1e3; + pointsS2[3][0] = system.getPC(); + pointsS2[2][0] = + system.getPhase(1).getEntropy() / system.getPhase(1).getNumberOfMolesInPhase() + / system.getPhase(1).getMolarMass() / 1e3; + pointsV2[3][0] = system.getPC(); + pointsV2[2][0] = system.getPhase(1).getDensity(); + + for (int i = 1; i < (ncr2 - 2); i++) { + points2[2][i] = points[0][i + ncr - 1]; + points2[3][i] = points[1][i + ncr - 1]; + + pointsH2[3][i] = points[1][i + ncr - 1]; + pointsH2[2][i] = pointsH[i + ncr - 1]; + + pointsS2[3][i] = points[1][i + ncr - 1]; + pointsS2[2][i] = pointsS[i + ncr - 1]; + + pointsV2[3][i] = points[1][i + ncr - 1]; + pointsV2[2][i] = pointsV[i + ncr - 1]; } + } + // monitor.close(); + mainFrame.setVisible(false); + /* + * if (outputToFile) { String name1 = new String(); name1 = fileName + "Dew.nc"; file1 = new + * neqsim.dataPresentation.fileHandeling.createNetCDF.netCDF2D.NetCdf2D(); + * file1.setOutputFileName(name1); file1.setXvalues(points2[2], "temp", "sec"); + * file1.setYvalues(points2[3], "pres", "meter"); file1.createFile(); + * + * String name2 = new String(); name2 = fileName + "Bub.nc"; file2 = new + * neqsim.dataPresentation.fileHandeling.createNetCDF.netCDF2D.NetCdf2D(); + * file2.setOutputFileName(name2); file2.setXvalues(points2[0], "temp", "sec"); + * file2.setYvalues(points2[1], "pres", "meter"); file2.createFile(); } + */ + } catch (Exception e) { + logger.error("error", e); } - - /** {@inheritDoc} */ - @Override - public void displayResult() { - DecimalFormat nf = new DecimalFormat(); - nf.setMaximumFractionDigits(1); - nf.applyPattern("####.#"); - - double TC = system.getTC(); - double PC = system.getPC(); - logger.info("tc : " + TC + " PC : " + PC); - String[] navn = {"bubble point", "dew point", "bubble point", "dew point"}; - String title = "PT-graph TC=" + String.valueOf(nf.format(TC)) + " PC=" - + String.valueOf(nf.format(PC)); - String title3 = "PH-graph TC=" + String.valueOf(nf.format(TC)) + " PC=" - + String.valueOf(nf.format(PC)); - String title4 = "Density-graph TC=" + String.valueOf(nf.format(TC)) + " PC=" - + String.valueOf(nf.format(PC)); - String title5 = "PS-graph TC=" + String.valueOf(nf.format(TC)) + " PC=" - + String.valueOf(nf.format(PC)); - - // logger.info("start flash"); - // logger.info("Tferdig.."); - - graph2b graph3 = new graph2b(pointsH2, navn, title3, "Enthalpy [kJ/kg]", "Pressure [bara]"); - graph3.setVisible(true); - graph3.saveFigure((neqsim.util.util.FileSystemSettings.tempDir + "NeqSimTempFig4.png")); - - graph2b graph4 = new graph2b(pointsV2, navn, title4, "Density [kg/m^3]", "Pressure [bara]"); - graph4.setVisible(true); - graph4.saveFigure(neqsim.util.util.FileSystemSettings.tempDir + "NeqSimTempFig2.png"); - - graph2b graph5 = - new graph2b(pointsS2, navn, title5, "Entropy [kJ/kg*K]", "Pressure [bara]"); - graph5.setVisible(true); - graph5.saveFigure(neqsim.util.util.FileSystemSettings.tempDir + "NeqSimTempFig3.png"); - - graph2 = new graph2b(points2, navn, title, "Temperature [K]", "Pressure [bara]"); - graph2.setVisible(true); - graph2.saveFigure(neqsim.util.util.FileSystemSettings.tempDir + "NeqSimTempFig1.png"); - - /* - * JDialog dialog = new JDialog(); Container dialogContentPane = dialog.getContentPane(); - * dialogContentPane.setLayout(new FlowLayout()); JFreeChartPanel chartPanel = - * graph4.getChartPanel(); dialogContentPane.add(chartPanel); dialog.show(); - */ + } + + /** {@inheritDoc} */ + @Override + public void displayResult() { + DecimalFormat nf = new DecimalFormat(); + nf.setMaximumFractionDigits(1); + nf.applyPattern("####.#"); + + double TC = system.getTC(); + double PC = system.getPC(); + logger.info("tc : " + TC + " PC : " + PC); + String[] navn = {"bubble point", "dew point", "bubble point", "dew point"}; + String title = + "PT-graph TC=" + String.valueOf(nf.format(TC)) + " PC=" + String.valueOf(nf.format(PC)); + String title3 = + "PH-graph TC=" + String.valueOf(nf.format(TC)) + " PC=" + String.valueOf(nf.format(PC)); + String title4 = "Density-graph TC=" + String.valueOf(nf.format(TC)) + " PC=" + + String.valueOf(nf.format(PC)); + String title5 = + "PS-graph TC=" + String.valueOf(nf.format(TC)) + " PC=" + String.valueOf(nf.format(PC)); + + // logger.info("start flash"); + // logger.info("Tferdig.."); + + graph2b graph3 = new graph2b(pointsH2, navn, title3, "Enthalpy [kJ/kg]", "Pressure [bara]"); + graph3.setVisible(true); + graph3.saveFigure((neqsim.util.util.FileSystemSettings.tempDir + "NeqSimTempFig4.png")); + + graph2b graph4 = new graph2b(pointsV2, navn, title4, "Density [kg/m^3]", "Pressure [bara]"); + graph4.setVisible(true); + graph4.saveFigure(neqsim.util.util.FileSystemSettings.tempDir + "NeqSimTempFig2.png"); + + graph2b graph5 = new graph2b(pointsS2, navn, title5, "Entropy [kJ/kg*K]", "Pressure [bara]"); + graph5.setVisible(true); + graph5.saveFigure(neqsim.util.util.FileSystemSettings.tempDir + "NeqSimTempFig3.png"); + + graph2 = new graph2b(points2, navn, title, "Temperature [K]", "Pressure [bara]"); + graph2.setVisible(true); + graph2.saveFigure(neqsim.util.util.FileSystemSettings.tempDir + "NeqSimTempFig1.png"); + + /* + * JDialog dialog = new JDialog(); Container dialogContentPane = dialog.getContentPane(); + * dialogContentPane.setLayout(new FlowLayout()); JFreeChartPanel chartPanel = + * graph4.getChartPanel(); dialogContentPane.add(chartPanel); dialog.show(); + */ + } + + /** {@inheritDoc} */ + @Override + public void printToFile(String name) {} + + /** {@inheritDoc} */ + @Override + public org.jfree.chart.JFreeChart getJFreeChart(String name) { + DecimalFormat nf = new DecimalFormat(); + nf.setMaximumFractionDigits(1); + nf.applyPattern("####.#"); + + double TC = system.getTC(); + double PC = system.getPC(); + logger.info("tc : " + TC + " PC : " + PC); + String[] navn = {"bubble point", "dew point", "bubble point", "dew point"}; + String title = "PT-graph. TC=" + String.valueOf(nf.format(TC)) + "K, PC=" + + String.valueOf(nf.format(PC) + " bara"); + graph2 = new graph2b(points2, navn, title, "Temperature [K]", "Pressure [bara]"); + return graph2.getChart(); + } + + /** {@inheritDoc} */ + @Override + public double[][] getPoints(int i) { + return points2; + } + + /** {@inheritDoc} */ + @Override + public double[] get(String name) { + if (name.equals("bubT")) { + return points2[0]; } - - /** {@inheritDoc} */ - @Override - public void printToFile(String name) {} - - /** {@inheritDoc} */ - @Override - public org.jfree.chart.JFreeChart getJFreeChart(String name) { - DecimalFormat nf = new DecimalFormat(); - nf.setMaximumFractionDigits(1); - nf.applyPattern("####.#"); - - double TC = system.getTC(); - double PC = system.getPC(); - logger.info("tc : " + TC + " PC : " + PC); - String[] navn = {"bubble point", "dew point", "bubble point", "dew point"}; - String title = "PT-graph. TC=" + String.valueOf(nf.format(TC)) + "K, PC=" - + String.valueOf(nf.format(PC) + " bara"); - graph2 = new graph2b(points2, navn, title, "Temperature [K]", "Pressure [bara]"); - return graph2.getChart(); + if (name.equals("bubP")) { + return points2[1]; } - - /** {@inheritDoc} */ - @Override - public double[][] getPoints(int i) { - return points2; + if (name.equals("dewT")) { + return points2[2]; } - - /** {@inheritDoc} */ - @Override - public double[] get(String name) { - if (name.equals("bubT")) { - return points2[0]; - } - if (name.equals("bubP")) { - return points2[1]; - } - if (name.equals("dewT")) { - return points2[2]; - } - if (name.equals("dewP")) { - return points2[3]; - } - if (name.equals("dewH")) { - return pointsH2[2]; - } - if (name.equals("dewDens")) { - return pointsV2[2]; - } - if (name.equals("dewS")) { - return pointsS2[2]; - } - if (name.equals("bubH")) { - return pointsH2[0]; - } - if (name.equals("bubDens")) { - return pointsV2[0]; - } - if (name.equals("bubS")) { - return pointsS2[0]; - } - if (name.equals("cricondentherm")) { - return cricondenTherm; - } - if (name.equals("cricondenbar")) { - return cricondenBar; - } else { - return null; - } + if (name.equals("dewP")) { + return points2[3]; } - - /** {@inheritDoc} */ - @Override - public void createNetCdfFile(String name) { - fileName = name; + if (name.equals("dewH")) { + return pointsH2[2]; } - - /** {@inheritDoc} */ - @Override - public String[][] getResultTable() { - return null; + if (name.equals("dewDens")) { + return pointsV2[2]; + } + if (name.equals("dewS")) { + return pointsS2[2]; + } + if (name.equals("bubH")) { + return pointsH2[0]; + } + if (name.equals("bubDens")) { + return pointsV2[0]; } + if (name.equals("bubS")) { + return pointsS2[0]; + } + if (name.equals("cricondentherm")) { + return cricondenTherm; + } + if (name.equals("cricondenbar")) { + return cricondenBar; + } else { + return null; + } + } + + /** {@inheritDoc} */ + @Override + public String[][] getResultTable() { + return null; + } } diff --git a/src/main/java/neqsim/thermodynamicOperations/phaseEnvelopeOps/reactiveCurves/pLoadingCurve.java b/src/main/java/neqsim/thermodynamicOperations/phaseEnvelopeOps/reactiveCurves/pLoadingCurve.java index 00e94673ae..d09724c10b 100644 --- a/src/main/java/neqsim/thermodynamicOperations/phaseEnvelopeOps/reactiveCurves/pLoadingCurve.java +++ b/src/main/java/neqsim/thermodynamicOperations/phaseEnvelopeOps/reactiveCurves/pLoadingCurve.java @@ -8,7 +8,6 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import neqsim.dataPresentation.JFreeChart.graph2b; -import neqsim.dataPresentation.fileHandeling.createNetCDF.netCDF2D.NetCdf2D; import neqsim.thermo.system.SystemInterface; import neqsim.thermodynamicOperations.OperationInterface; @@ -148,23 +147,6 @@ public double[][] getPoints(int i) { return points; } - /** {@inheritDoc} */ - @Override - public void createNetCdfFile(String name) { - NetCdf2D file = new NetCdf2D(); - file.setOutputFileName(name); - file.setXvalues(points[0], "loading", ""); - file.setYvalues(points[1], "pressure", ""); - for (int k = 0; k < system.getPhases()[1].getNumberOfComponents(); k++) { - file.setYvalues(points[k + 2], - "mol frac " + system.getPhases()[1].getComponents()[k].getComponentName(), ""); - file.setYvalues(points[k + 2 + system.getPhases()[1].getNumberOfComponents()], - ("activity " + system.getPhases()[1].getComponents()[k].getComponentName()), - ""); - } - file.createFile(); - } - /** {@inheritDoc} */ @Override public double[] get(String name) { diff --git a/src/main/java/neqsim/thermodynamicOperations/phaseEnvelopeOps/reactiveCurves/pLoadingCurve2.java b/src/main/java/neqsim/thermodynamicOperations/phaseEnvelopeOps/reactiveCurves/pLoadingCurve2.java index e1f2ff6a36..aa2372274b 100644 --- a/src/main/java/neqsim/thermodynamicOperations/phaseEnvelopeOps/reactiveCurves/pLoadingCurve2.java +++ b/src/main/java/neqsim/thermodynamicOperations/phaseEnvelopeOps/reactiveCurves/pLoadingCurve2.java @@ -8,7 +8,6 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import neqsim.dataPresentation.JFreeChart.graph2b; -import neqsim.dataPresentation.fileHandeling.createNetCDF.netCDF2D.NetCdf2D; import neqsim.thermo.system.SystemInterface; import neqsim.thermodynamicOperations.BaseOperation; import neqsim.thermodynamicOperations.ThermodynamicOperations; @@ -22,181 +21,173 @@ * @version $Id: $Id */ public class pLoadingCurve2 extends BaseOperation { - private static final long serialVersionUID = 1000; - static Logger logger = LogManager.getLogger(pLoadingCurve2.class); - - SystemInterface system; - int i, j = 0, nummer = 0, iterations = 0, maxNumberOfIterations = 10000; - double gibbsEnergy = 0, gibbsEnergyOld = 0; - double Kold, deviation = 0, g0 = 0, g1 = 0; - double lnOldOldK[], lnK[]; - double lnOldK[]; - double oldDeltalnK[], deltalnK[]; - double tm[] = {1, 1}; - double beta = 1e-5; - int lowestGibbsEnergyPhase = 0; // lowestGibbsEnergyPhase - JProgressBar monitor; - JFrame mainFrame; - JPanel mainPanel; - - double temp = 0, pres = 0, startPres = 0; - double[][] points = new double[35][]; - - boolean moreLines = false; - int np = 0; - // points[2] = new double[1000]; - int speceq = 0; - - /** - *

- * Constructor for pLoadingCurve2. - *

- */ - public pLoadingCurve2() {} - - /** - *

- * Constructor for pLoadingCurve2. - *

- * - * @param system a {@link neqsim.thermo.system.SystemInterface} object - */ - public pLoadingCurve2(SystemInterface system) { - this.system = system; - lnOldOldK = new double[system.getPhases()[0].getNumberOfComponents()]; - lnOldK = new double[system.getPhases()[0].getNumberOfComponents()]; - lnK = new double[system.getPhases()[0].getNumberOfComponents()]; - oldDeltalnK = new double[system.getPhases()[0].getNumberOfComponents()]; - deltalnK = new double[system.getPhases()[0].getNumberOfComponents()]; - mainFrame = new JFrame("Progress Bar"); - mainPanel = new JPanel(); - mainPanel.setSize(200, 100); - mainFrame.getContentPane().setLayout(new FlowLayout()); - mainPanel.setLayout(new FlowLayout()); - mainFrame.setSize(200, 100); - monitor = new JProgressBar(0, 1000); - monitor.setSize(200, 100); - monitor.setStringPainted(true); - mainPanel.add(monitor); - mainFrame.getContentPane().add(mainPanel); - mainFrame.setVisible(true); + private static final long serialVersionUID = 1000; + static Logger logger = LogManager.getLogger(pLoadingCurve2.class); + + SystemInterface system; + int i, j = 0, nummer = 0, iterations = 0, maxNumberOfIterations = 10000; + double gibbsEnergy = 0, gibbsEnergyOld = 0; + double Kold, deviation = 0, g0 = 0, g1 = 0; + double lnOldOldK[], lnK[]; + double lnOldK[]; + double oldDeltalnK[], deltalnK[]; + double tm[] = {1, 1}; + double beta = 1e-5; + int lowestGibbsEnergyPhase = 0; // lowestGibbsEnergyPhase + JProgressBar monitor; + JFrame mainFrame; + JPanel mainPanel; + + double temp = 0, pres = 0, startPres = 0; + double[][] points = new double[35][]; + + boolean moreLines = false; + int np = 0; + // points[2] = new double[1000]; + int speceq = 0; + + /** + *

+ * Constructor for pLoadingCurve2. + *

+ */ + public pLoadingCurve2() {} + + /** + *

+ * Constructor for pLoadingCurve2. + *

+ * + * @param system a {@link neqsim.thermo.system.SystemInterface} object + */ + public pLoadingCurve2(SystemInterface system) { + this.system = system; + lnOldOldK = new double[system.getPhases()[0].getNumberOfComponents()]; + lnOldK = new double[system.getPhases()[0].getNumberOfComponents()]; + lnK = new double[system.getPhases()[0].getNumberOfComponents()]; + oldDeltalnK = new double[system.getPhases()[0].getNumberOfComponents()]; + deltalnK = new double[system.getPhases()[0].getNumberOfComponents()]; + mainFrame = new JFrame("Progress Bar"); + mainPanel = new JPanel(); + mainPanel.setSize(200, 100); + mainFrame.getContentPane().setLayout(new FlowLayout()); + mainPanel.setLayout(new FlowLayout()); + mainFrame.setSize(200, 100); + monitor = new JProgressBar(0, 1000); + monitor.setSize(200, 100); + monitor.setStringPainted(true); + mainPanel.add(monitor); + mainFrame.getContentPane().add(mainPanel); + mainFrame.setVisible(true); + } + + /** {@inheritDoc} */ + @Override + public void run() { + int numbPoints = 50; + double inscr = 0.2103842275; + points[0] = new double[numbPoints]; + points[1] = new double[numbPoints]; + points[2] = new double[numbPoints]; + ThermodynamicOperations testOps = new ThermodynamicOperations(system); + + for (int k = 0; k < system.getPhases()[1].getNumberOfComponents(); k++) { + points[k + 3] = new double[numbPoints]; + points[k + 3 + system.getPhases()[1].getNumberOfComponents()] = new double[numbPoints]; } - /** {@inheritDoc} */ - @Override - public void run() { - int numbPoints = 50; - double inscr = 0.2103842275; - points[0] = new double[numbPoints]; - points[1] = new double[numbPoints]; - points[2] = new double[numbPoints]; - ThermodynamicOperations testOps = new ThermodynamicOperations(system); - - for (int k = 0; k < system.getPhases()[1].getNumberOfComponents(); k++) { - points[k + 3] = new double[numbPoints]; - points[k + 3 + system.getPhases()[1].getNumberOfComponents()] = new double[numbPoints]; - } - - double molMDEA = system.getPhases()[1].getComponents()[2].getNumberOfMolesInPhase(); - system.getChemicalReactionOperations().solveChemEq(1); - - for (int i = 1; i < points[0].length; i++) { - system.initBeta(); - system.init_x_y(); - try { - testOps.bubblePointPressureFlash(false); - } catch (Exception e) { - logger.info(e.toString()); - } - logger.info("beta " + system.getBeta()); - points[0][i] = (inscr * (i - 1)) / molMDEA; - points[1][i] = (system.getPressure()); - points[2][i] = (system.getPressure() * system.getPhase(0).getComponent(0).getx()); - - for (int k = 0; k < system.getPhases()[1].getNumberOfComponents(); k++) { - points[k + 3][i] = system.getPhases()[1].getComponents()[k].getx(); - points[k + 3 + system.getPhases()[1].getNumberOfComponents()][i] = - system.getPhase(1).getActivityCoefficient(k, 1);// ,1); - } - logger.info("point: " + points[0][i] + " tot pres " + points[1][i] + " CO2 pres " - + points[2][i]); - system.setPressure(points[1][i]); - logger.info("ph: " + system.getPhases()[1].getpH()); - system.addComponent("CO2", inscr); - } - mainFrame.setVisible(false); - } - - /** {@inheritDoc} */ - @Override - public void displayResult() { - DecimalFormat nf = new DecimalFormat(); - nf.setMaximumFractionDigits(1); - nf.applyPattern("####.#"); - - double TC = system.getTC(); - double PC = system.getPC(); - logger.info("tc : " + TC + " PC : " + PC); - String[] navn = {"CO2 fugacity", "", "", ""}; - String title = "CO2 vapour pressure"; - - graph2b graph2 = new graph2b(points, navn, title, "loading [-]", "Fugacity CO2 [bar]"); - graph2.setVisible(true); - } - - /** {@inheritDoc} */ - @Override - public void printToFile(String name) { - neqsim.dataPresentation.dataHandeling printDat = - new neqsim.dataPresentation.dataHandeling(); - printDat.printToFile(points, name); - } - - /** {@inheritDoc} */ - @Override - public double[][] getPoints(int i) { - return points; - } - - /** {@inheritDoc} */ - @Override - public void createNetCdfFile(String name) { - NetCdf2D file = new NetCdf2D(); - file.setOutputFileName(name); - file.setXvalues(points[0], "loading", ""); - file.setYvalues(points[1], "total pressure", ""); - file.setYvalues(points[2], " CO2 pressure", ""); - for (int k = 0; k < system.getPhases()[1].getNumberOfComponents(); k++) { - file.setYvalues(points[k + 3], - "mol frac " + system.getPhases()[1].getComponents()[k].getComponentName(), ""); - file.setYvalues(points[k + 3 + system.getPhases()[1].getNumberOfComponents()], - ("activity " + system.getPhases()[1].getComponents()[k].getComponentName()), - ""); - } - file.createFile(); - } - - /** {@inheritDoc} */ - @Override - public double[] get(String name) { - return null; - } - - /** {@inheritDoc} */ - @Override - public org.jfree.chart.JFreeChart getJFreeChart(String name) { - return null; - } - - /** {@inheritDoc} */ - @Override - public String[][] getResultTable() { - return null; - } - - /** {@inheritDoc} */ - @Override - public SystemInterface getThermoSystem() { - return system; + double molMDEA = system.getPhases()[1].getComponents()[2].getNumberOfMolesInPhase(); + system.getChemicalReactionOperations().solveChemEq(1); + + for (int i = 1; i < points[0].length; i++) { + system.initBeta(); + system.init_x_y(); + try { + testOps.bubblePointPressureFlash(false); + } catch (Exception e) { + logger.info(e.toString()); + } + logger.info("beta " + system.getBeta()); + points[0][i] = (inscr * (i - 1)) / molMDEA; + points[1][i] = (system.getPressure()); + points[2][i] = (system.getPressure() * system.getPhase(0).getComponent(0).getx()); + + for (int k = 0; k < system.getPhases()[1].getNumberOfComponents(); k++) { + points[k + 3][i] = system.getPhases()[1].getComponents()[k].getx(); + points[k + 3 + system.getPhases()[1].getNumberOfComponents()][i] = + system.getPhase(1).getActivityCoefficient(k, 1);// ,1); + } + logger.info( + "point: " + points[0][i] + " tot pres " + points[1][i] + " CO2 pres " + points[2][i]); + system.setPressure(points[1][i]); + logger.info("ph: " + system.getPhases()[1].getpH()); + system.addComponent("CO2", inscr); } + mainFrame.setVisible(false); + } + + /** {@inheritDoc} */ + @Override + public void displayResult() { + DecimalFormat nf = new DecimalFormat(); + nf.setMaximumFractionDigits(1); + nf.applyPattern("####.#"); + + double TC = system.getTC(); + double PC = system.getPC(); + logger.info("tc : " + TC + " PC : " + PC); + String[] navn = {"CO2 fugacity", "", "", ""}; + String title = "CO2 vapour pressure"; + + graph2b graph2 = new graph2b(points, navn, title, "loading [-]", "Fugacity CO2 [bar]"); + graph2.setVisible(true); + } + + /** {@inheritDoc} */ + @Override + public void printToFile(String name) { + neqsim.dataPresentation.dataHandeling printDat = new neqsim.dataPresentation.dataHandeling(); + printDat.printToFile(points, name); + } + + /** {@inheritDoc} */ + @Override + public double[][] getPoints(int i) { + return points; + } + + /* + * public void createNetCdfFile(String name) { NetCdf2D file = new NetCdf2D(); + * file.setOutputFileName(name); file.setXvalues(points[0], "loading", ""); + * file.setYvalues(points[1], "total pressure", ""); file.setYvalues(points[2], " CO2 pressure", + * ""); for (int k = 0; k < system.getPhases()[1].getNumberOfComponents(); k++) { + * file.setYvalues(points[k + 3], "mol frac " + + * system.getPhases()[1].getComponents()[k].getComponentName(), ""); file.setYvalues(points[k + 3 + * + system.getPhases()[1].getNumberOfComponents()], ("activity " + + * system.getPhases()[1].getComponents()[k].getComponentName()), ""); } file.createFile(); } + */ + + /** {@inheritDoc} */ + @Override + public double[] get(String name) { + return null; + } + + /** {@inheritDoc} */ + @Override + public org.jfree.chart.JFreeChart getJFreeChart(String name) { + return null; + } + + /** {@inheritDoc} */ + @Override + public String[][] getResultTable() { + return null; + } + + /** {@inheritDoc} */ + @Override + public SystemInterface getThermoSystem() { + return system; + } } diff --git a/src/main/java/neqsim/util/NamedBaseClass.java b/src/main/java/neqsim/util/NamedBaseClass.java index 7f8e501103..8bb97a43bf 100644 --- a/src/main/java/neqsim/util/NamedBaseClass.java +++ b/src/main/java/neqsim/util/NamedBaseClass.java @@ -11,7 +11,7 @@ public abstract class NamedBaseClass implements NamedInterface, java.io.Serializ /** * Constructor for NamedBaseClass * - * @param name + * @param name the name of the class */ public NamedBaseClass(String name) { this.name = name; diff --git a/src/test/java/neqsim/NeqSimTest.java b/src/test/java/neqsim/NeqSimTest.java index e303d5776d..c7e802b7e0 100644 --- a/src/test/java/neqsim/NeqSimTest.java +++ b/src/test/java/neqsim/NeqSimTest.java @@ -1,17 +1,12 @@ -/** - * - */ package neqsim; -import org.junit.jupiter.api.BeforeAll; - /** * @author ESOL * */ public class NeqSimTest { public NeqSimTest() { - //Setting NeqSim to use test parameter database + // Setting NeqSim to use test parameter database neqsim.util.database.NeqSimDataBase .setConnectionString("jdbc:derby:classpath:data/neqsimtestdatabase"); } diff --git a/src/test/java/neqsim/fluidMechanics/flowSystem/onePhaseFlowSystem/pipeFlowSystem/PipeFlowSystemTest.java b/src/test/java/neqsim/fluidMechanics/flowSystem/onePhaseFlowSystem/pipeFlowSystem/PipeFlowSystemTest.java index cffefc00a8..8cc0da7b39 100644 --- a/src/test/java/neqsim/fluidMechanics/flowSystem/onePhaseFlowSystem/pipeFlowSystem/PipeFlowSystemTest.java +++ b/src/test/java/neqsim/fluidMechanics/flowSystem/onePhaseFlowSystem/pipeFlowSystem/PipeFlowSystemTest.java @@ -1,118 +1,130 @@ package neqsim.fluidMechanics.flowSystem.onePhaseFlowSystem.pipeFlowSystem; import java.util.Arrays; -import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; - import neqsim.fluidMechanics.flowSystem.FlowSystemInterface; import neqsim.thermo.system.SystemInterface; - -public class PipeFlowSystemTest extends neqsim.NeqSimTest{ - FlowSystemInterface pipe; - - @BeforeEach - void setUp() { - pipe = new PipeFlowSystem(); - - SystemInterface testSystem = new neqsim.thermo.system.SystemSrkEos(285.15, 200.0); - testSystem.addComponent("methane", 0.9); - testSystem.addComponent("ethane", 0.1); - testSystem.createDatabase(true); - testSystem.init(0); - testSystem.init(3); - testSystem.initPhysicalProperties(); - testSystem.setTotalFlowRate(60.0, "MSm3/day"); - - double[] height = { 0, 0, 0 }; // , 0, 0, 0, 0, 0, 0, 0, 0}; - double[] diameter = {1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0}; - double[] roughness = {1.0e-5, 1.0e-5, 1.0e-5, 1.0e-5, 1.0e-5, 1.0e-5, 1.0e-5, 1.0e-5, - 1.0e-5, 1.0e-5, 1.0e-5}; - double[] outHeatCoef = {5.0, 5.0, 5.0, 5.0, 5.0, 5.0, 5.0, 5.0, 5.0, 5.0, 5.0}; - double[] wallHeacCoef = {15.0, 15.0, 15.0, 15.0, 15.0, 15.0, 15.0, 15.0, 15.0, 15.0, 15.0}; - - double[] length = - {0, 10000, 50000, 150000, 200000, 400000, 500000, 600000, 650000, 700000, 750000}; - double[] outerTemperature = - {278.0, 278.0, 278.0, 278.0, 278.0, 278.0, 278.0, 278.0, 278.0, 278.0, 278.0}; - - neqsim.fluidMechanics.geometryDefinitions.GeometryDefinitionInterface[] pipeGeometry = - new neqsim.fluidMechanics.geometryDefinitions.pipe.PipeData[height.length]; - - for (int i = 0; i < height.length; i++) { - pipeGeometry[i] = new neqsim.fluidMechanics.geometryDefinitions.pipe.PipeData(); - pipeGeometry[i].setDiameter(diameter[i]); - pipeGeometry[i].setInnerSurfaceRoughness(roughness[i]); - } - pipe.setInletThermoSystem(testSystem); - pipe.setNumberOfLegs(height.length - 1); - pipe.setNumberOfNodesInLeg(20); - pipe.setEquipmentGeometry(pipeGeometry); - pipe.setLegHeights(height); - pipe.setLegPositions(Arrays.copyOfRange(length, 0, height.length)); - pipe.setLegOuterTemperatures(Arrays.copyOfRange(outerTemperature, 0, height.length)); - pipe.setLegWallHeatTransferCoefficients(Arrays.copyOfRange(wallHeacCoef, 0, height.length)); - pipe.setLegOuterHeatTransferCoefficients(Arrays.copyOfRange(outHeatCoef, 0, height.length)); - } - - - @Test - void testCreateSystem() { - pipe.createSystem(); +public class PipeFlowSystemTest extends neqsim.NeqSimTest { + FlowSystemInterface pipe; + + @BeforeEach + void setUp() { + pipe = new PipeFlowSystem(); + + SystemInterface testSystem = new neqsim.thermo.system.SystemSrkEos(285.15, 200.0); + testSystem.addComponent("methane", 0.9); + testSystem.addComponent("ethane", 0.1); + testSystem.createDatabase(true); + testSystem.init(0); + testSystem.init(3); + testSystem.initPhysicalProperties(); + testSystem.setTotalFlowRate(60.0, "MSm3/day"); + + double[] height = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; + double[] diameter = {1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0}; + double[] roughness = + {1.0e-5, 1.0e-5, 1.0e-5, 1.0e-5, 1.0e-5, 1.0e-5, 1.0e-5, 1.0e-5, 1.0e-5, 1.0e-5, 1.0e-5}; + double[] outHeatCoef = {5.0, 5.0, 5.0, 5.0, 5.0, 5.0, 5.0, 5.0, 5.0, 5.0, 5.0}; + double[] wallHeacCoef = {15.0, 15.0, 15.0, 15.0, 15.0, 15.0, 15.0, 15.0, 15.0, 15.0, 15.0}; + + double[] length = + {0, 10000, 50000, 150000, 200000, 400000, 500000, 600000, 650000, 700000, 740000}; + double[] outerTemperature = + {278.0, 278.0, 278.0, 278.0, 278.0, 278.0, 278.0, 278.0, 278.0, 278.0, 278.0}; + + neqsim.fluidMechanics.geometryDefinitions.GeometryDefinitionInterface[] pipeGeometry = + new neqsim.fluidMechanics.geometryDefinitions.pipe.PipeData[height.length]; + + for (int i = 0; i < height.length; i++) { + pipeGeometry[i] = new neqsim.fluidMechanics.geometryDefinitions.pipe.PipeData(); + pipeGeometry[i].setDiameter(diameter[i]); + pipeGeometry[i].setInnerSurfaceRoughness(roughness[i]); } - - @Test - void testInit() { - testCreateSystem(); - pipe.init(); + pipe.setInletThermoSystem(testSystem); + pipe.setNumberOfLegs(height.length - 1); + pipe.setNumberOfNodesInLeg(20); + pipe.setEquipmentGeometry(pipeGeometry); + pipe.setLegHeights(height); + pipe.setLegPositions(Arrays.copyOfRange(length, 0, height.length)); + pipe.setLegOuterTemperatures(Arrays.copyOfRange(outerTemperature, 0, height.length)); + pipe.setLegWallHeatTransferCoefficients(Arrays.copyOfRange(wallHeacCoef, 0, height.length)); + pipe.setLegOuterHeatTransferCoefficients(Arrays.copyOfRange(outHeatCoef, 0, height.length)); + } + + @Test + void testCreateSystem() { + pipe.createSystem(); + } + + @Test + void testInit() { + testCreateSystem(); + pipe.init(); + } + + @Test + void testSolveSteadyStateConstantFrictionFactor() { + testInit(); + for (int i = 0; i < pipe.getFlowNodes().length; i++) { + pipe.getNode(i).setWallFrictionFactor(0, 0.00725); } - - @Test - void testSolveSteadyState() { - testInit(); - pipe.solveSteadyState(10); - // pipe.print(); + pipe.solveSteadyState(10); + // System.out.println("pressure out set friction " + } + + @Test + void testSolveSteadyState() { + testInit(); + pipe.solveSteadyState(10); + for (int i = 0; i < pipe.getFlowNodes().length; i++) { + // System.out.println("wall friction " + pipe.getNode(i).getWallFrictionFactor(0)); } - @Test - void testSolveTransient() { - testInit(); - // transient solver - double[] times = {0, 10000, 20000};// , 30000, 40000, 50000};//, 60000, 70000, 80000, - // 90000}; - pipe.getTimeSeries().setTimes(times); - - SystemInterface testSystem = new neqsim.thermo.system.SystemSrkEos(285.15, 200.0); - testSystem.addComponent("methane", 0.9); - testSystem.addComponent("ethane", 0.1); - - SystemInterface testSystem2 = new neqsim.thermo.system.SystemSrkEos(315.15, 200.0); - testSystem2.addComponent("methane", 26000.0); - testSystem2.addComponent("ethane", 1.10); - testSystem2.init(0); - testSystem2.init(3); - testSystem2.initPhysicalProperties(); - - SystemInterface testSystem3 = new neqsim.thermo.system.SystemSrkEos(285.15, 200.0); - testSystem3.addComponent("methane", 29000.0); - testSystem3.addComponent("ethane", 1221.10); - testSystem3.init(0); - - SystemInterface[] systems = {testSystem, testSystem2, testSystem2};// , testSystem2, - // testSystem2, - // testSystem2};//,testSystem2,testSystem2,testSystem2,testSystem2,testSystem2}; - pipe.getTimeSeries().setInletThermoSystems(systems); - pipe.getTimeSeries().setNumberOfTimeStepsInInterval(10); - // double[] outletFlowRates = {0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 0.01, - // 0.01, 0.01, 0.01}; - // pipe.getTimeSeries().setOutletMolarFlowRate(outletFlowRates); - - // pipe.solveTransient(20); - // pipe.getDisplay().displayResult("composition"); - // pipe.getDisplay().displayResult("pressure"); - // pipe.getDisplay().displayResult("composition"); - // pipe.getDisplay().createNetCdfFile("c:/temp5.nc"); - // pipe.getDisplay(1).displayResult(); - } + // System.out.println("pressure out calc friction " + // + pipe.getNode(pipe.getFlowNodes().length - 1).getBulkSystem().getPressure() + " bara"); + + // pipe.print(); + } + + @Test + void testSolveTransient() { + testInit(); + // transient solver + double[] times = {0, 10000, 20000};// , 30000, 40000, 50000};//, 60000, 70000, 80000, + // 90000}; + pipe.getTimeSeries().setTimes(times); + + SystemInterface testSystem = new neqsim.thermo.system.SystemSrkEos(285.15, 200.0); + testSystem.addComponent("methane", 0.9); + testSystem.addComponent("ethane", 0.1); + + SystemInterface testSystem2 = new neqsim.thermo.system.SystemSrkEos(315.15, 200.0); + testSystem2.addComponent("methane", 26000.0); + testSystem2.addComponent("ethane", 1.10); + testSystem2.init(0); + testSystem2.init(3); + testSystem2.initPhysicalProperties(); + + SystemInterface testSystem3 = new neqsim.thermo.system.SystemSrkEos(285.15, 200.0); + testSystem3.addComponent("methane", 29000.0); + testSystem3.addComponent("ethane", 1221.10); + testSystem3.init(0); + + SystemInterface[] systems = {testSystem, testSystem2, testSystem2};// , testSystem2, + // testSystem2, + // testSystem2};//,testSystem2,testSystem2,testSystem2,testSystem2,testSystem2}; + pipe.getTimeSeries().setInletThermoSystems(systems); + pipe.getTimeSeries().setNumberOfTimeStepsInInterval(10); + // double[] outletFlowRates = {0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 0.01, + // 0.01, 0.01, 0.01}; + // pipe.getTimeSeries().setOutletMolarFlowRate(outletFlowRates); + + // pipe.solveTransient(20); + // pipe.getDisplay().displayResult("composition"); + // pipe.getDisplay().displayResult("pressure"); + // pipe.getDisplay().displayResult("composition"); + // pipe.getDisplay(1).displayResult(); + } } diff --git a/src/test/java/neqsim/fluidMechanics/util/example/WettedWall_CO2_water.java b/src/test/java/neqsim/fluidMechanics/util/example/WettedWall_CO2_water.java index 2c2dcf4b88..695fbd48b5 100644 --- a/src/test/java/neqsim/fluidMechanics/util/example/WettedWall_CO2_water.java +++ b/src/test/java/neqsim/fluidMechanics/util/example/WettedWall_CO2_water.java @@ -1,6 +1,5 @@ package neqsim.fluidMechanics.util.example; -import org.junit.jupiter.api.BeforeAll; import neqsim.processSimulation.processEquipment.pipeline.Pipeline; import neqsim.processSimulation.processEquipment.pipeline.TwoPhasePipeLine; import neqsim.processSimulation.processEquipment.stream.NeqStream; @@ -18,7 +17,7 @@ * @version $Id: $Id * @since 2.2.3 */ -public class WettedWall_CO2_water extends neqsim.NeqSimTest{ +public class WettedWall_CO2_water extends neqsim.NeqSimTest { /** * This method is just meant to test the thermo package. diff --git a/src/test/java/neqsim/physicalProperties/physicalPropertyMethods/liquidPhysicalProperties/density/CostaldTest.java b/src/test/java/neqsim/physicalProperties/physicalPropertyMethods/liquidPhysicalProperties/density/CostaldTest.java new file mode 100644 index 0000000000..8b2e8687f7 --- /dev/null +++ b/src/test/java/neqsim/physicalProperties/physicalPropertyMethods/liquidPhysicalProperties/density/CostaldTest.java @@ -0,0 +1,29 @@ +package neqsim.physicalProperties.physicalPropertyMethods.liquidPhysicalProperties.density; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; +import neqsim.thermodynamicOperations.ThermodynamicOperations; + +public class CostaldTest { + + static neqsim.thermo.system.SystemInterface testSystem = null; + + @BeforeAll + public static void setUp() { + testSystem = new neqsim.thermo.system.SystemSrkEos(344.26, 689.47); + testSystem.addComponent("ethane", 70.0); + testSystem.addComponent("nC10", 30.0); + testSystem.setMixingRule("classic"); + ThermodynamicOperations testOps = new ThermodynamicOperations(testSystem); + testOps.TPflash(); + } + + @Test + void testCalcDensity() { + testSystem.getPhase("oil").getPhysicalProperties().setDensityModel("Costald"); + double costaldDensity = testSystem.getPhase("oil").getPhysicalProperties().calcDensity(); + double costaldVolume = costaldDensity; + assertEquals(628.6198, costaldVolume, 1e-3); + } +} diff --git a/src/test/java/neqsim/physicalProperties/util/examples/TestSurfaceTension2.java b/src/test/java/neqsim/physicalProperties/util/examples/TestSurfaceTension2.java index 63f88c9dfb..7f03d5ad6d 100644 --- a/src/test/java/neqsim/physicalProperties/util/examples/TestSurfaceTension2.java +++ b/src/test/java/neqsim/physicalProperties/util/examples/TestSurfaceTension2.java @@ -15,11 +15,12 @@ public class TestSurfaceTension2 { // John debug /** - *

main.

+ *

+ * main. + *

* * @param args an array of {@link java.lang.String} objects */ - @SuppressWarnings("unused") public static void main(String args[]) { int gtmethod = 1; // 2; John changed diff --git a/src/test/java/neqsim/processSimulation/measurementDevice/WellAllocatorTest.java b/src/test/java/neqsim/processSimulation/measurementDevice/WellAllocatorTest.java index 38b4396fe4..cb925ffaaf 100644 --- a/src/test/java/neqsim/processSimulation/measurementDevice/WellAllocatorTest.java +++ b/src/test/java/neqsim/processSimulation/measurementDevice/WellAllocatorTest.java @@ -1,9 +1,5 @@ -/** - * - */ package neqsim.processSimulation.measurementDevice; -import static org.junit.jupiter.api.Assertions.*; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; import neqsim.processSimulation.processEquipment.separator.Separator; @@ -16,7 +12,7 @@ * @author ESOL * */ -class WellAllocatorTest extends neqsim.NeqSimTest{ +class WellAllocatorTest extends neqsim.NeqSimTest { /** * @throws java.lang.Exception @@ -25,7 +21,8 @@ class WellAllocatorTest extends neqsim.NeqSimTest{ static void setUpBeforeClass() throws Exception {} /** - * Test method for {@link neqsim.processSimulation.measurementDevice.WellAllocator#getMeasuredValue(java.lang.String)}. + * Test method for + * {@link neqsim.processSimulation.measurementDevice.WellAllocator#getMeasuredValue(java.lang.String)}. */ @Test void testGetMeasuredValueString() { @@ -43,23 +40,21 @@ void testGetMeasuredValueString() { testFluid.setMixingRule(2); testFluid.addToComponentNames("_well1"); - + testFluid.setTemperature(24.0, "C"); testFluid.setPressure(48.0, "bara"); testFluid.setTotalFlowRate(2500.0, "kg/hr"); - - - SystemInterface testFluid2 = testFluid.clone(); + SystemInterface testFluid2 = testFluid.clone(); testFluid.setTemperature(24.0, "C"); testFluid.setPressure(48.0, "bara"); testFluid.setTotalFlowRate(2500.0, "kg/hr"); Stream stream_1 = new Stream("Stream1", testFluid); - + Stream stream_2 = new Stream("Stream2", testFluid2); - + Separator sep1 = new Separator("sep1", stream_1); sep1.addStream(stream_2); @@ -80,15 +75,15 @@ void testGetMeasuredValueString() { operations.add(stream_oilExp); operations.add(wellAlloc); operations.run(); - + WellAllocatorResponse responsAl = new WellAllocatorResponse(wellAlloc); - + System.out.println("name " + responsAl.name); System.out.println("gas flow " + responsAl.gasExportRate); System.out.println("oil flow " + responsAl.oilExportRate); System.out.println("total flow " + responsAl.totalExportRate); - // stream_1.displayResult(); - // stream_1.displayResult(); + // stream_1.displayResult(); + // stream_1.displayResult(); } } diff --git a/src/test/java/neqsim/processSimulation/measurementDevice/pHProbeTest.java b/src/test/java/neqsim/processSimulation/measurementDevice/pHProbeTest.java new file mode 100644 index 0000000000..3e8741b2bc --- /dev/null +++ b/src/test/java/neqsim/processSimulation/measurementDevice/pHProbeTest.java @@ -0,0 +1,78 @@ +package neqsim.processSimulation.measurementDevice; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; +import neqsim.processSimulation.processEquipment.stream.Stream; +import neqsim.thermo.system.SystemInterface; +import neqsim.thermo.system.SystemSrkCPAstatoil; + +class pHProbeTest { + + @BeforeAll + static void setUpBeforeClass() throws Exception {} + + @Test + void testGetMeasuredValue() { + SystemInterface testFluid = new SystemSrkCPAstatoil(318.15, 50.0); + testFluid.addComponent("nitrogen", 1.205); + testFluid.addComponent("CO2", 1.340); + testFluid.addComponent("methane", 87.974); + testFluid.addComponent("ethane", 5.258); + testFluid.addComponent("propane", 3.283); + testFluid.addComponent("i-butane", 0.082); + testFluid.addComponent("n-butane", 0.487); + testFluid.addComponent("i-pentane", 0.056); + testFluid.addComponent("n-pentane", 1.053); + testFluid.addComponent("nC10", 14.053); + testFluid.addComponent("water", 141.053); + testFluid.setMixingRule(10); + testFluid.setMultiPhaseCheck(true); + + Stream stream_1 = new Stream("Stream1", testFluid); + stream_1.run(); + + pHProbe phmeasurement = new pHProbe(stream_1); + phmeasurement.run(); + System.out.println("pH " + phmeasurement.getMeasuredValue()); + assertEquals(4.079098133484792, phmeasurement.getMeasuredValue(),0.01); + } + + @Test + void testGetMeasuredValueWithAlkanility() { + SystemInterface testFluid = new SystemSrkCPAstatoil(318.15, 50.0); + testFluid.addComponent("nitrogen", 1.205); + testFluid.addComponent("CO2", 1.340); + testFluid.addComponent("methane", 87.974); + testFluid.addComponent("ethane", 5.258); + testFluid.addComponent("propane", 3.283); + testFluid.addComponent("i-butane", 0.082); + testFluid.addComponent("n-butane", 0.487); + testFluid.addComponent("i-pentane", 0.056); + testFluid.addComponent("n-pentane", 1.053); + testFluid.addComponent("nC10", 14.053); + testFluid.addComponent("water", 141.053); + testFluid.setMixingRule(10); + testFluid.setMultiPhaseCheck(true); + + Stream stream_1 = new Stream("Stream1", testFluid); + stream_1.run(); + + pHProbe phmeasurement = new pHProbe(stream_1); + phmeasurement.setAlkanility(50.0); + phmeasurement.run(); + System.out.println("pH " + phmeasurement.getMeasuredValue()); + assertEquals(5.629055432357595, phmeasurement.getMeasuredValue(),0.01); + } + + @Test + void testPHProbe() { + //fail("Not yet implemented"); + } + + @Test + void testPHProbeStreamInterface() { + //fail("Not yet implemented"); + } + +} diff --git a/src/test/java/neqsim/processSimulation/processEquipment/compressor/CompressorChartTest.java b/src/test/java/neqsim/processSimulation/processEquipment/compressor/CompressorChartTest.java new file mode 100644 index 0000000000..8f2fb0fb01 --- /dev/null +++ b/src/test/java/neqsim/processSimulation/processEquipment/compressor/CompressorChartTest.java @@ -0,0 +1,161 @@ +package neqsim.processSimulation.processEquipment.compressor; + +import static org.junit.jupiter.api.Assertions.assertTrue; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import neqsim.processSimulation.processEquipment.stream.Stream; +import neqsim.thermo.system.SystemInterface; +import neqsim.thermo.system.SystemSrkEos; + +public class CompressorChartTest { + public Compressor comp1; + + @BeforeEach + public void setUp() { + + SystemInterface testFluid = new SystemSrkEos(298.15, 50.0); + + // testFluid.addComponent("methane", 1.0); + // testFluid.setMixingRule(2); + // testFluid.setTotalFlowRate(0.635, "MSm3/day"); + + testFluid.addComponent("nitrogen", 1.205); + testFluid.addComponent("CO2", 1.340); + testFluid.addComponent("methane", 87.974); + testFluid.addComponent("ethane", 5.258); + testFluid.addComponent("propane", 3.283); + testFluid.addComponent("i-butane", 0.082); + testFluid.addComponent("n-butane", 0.487); + testFluid.addComponent("i-pentane", 0.056); + testFluid.addComponent("n-pentane", 0.053); + testFluid.setMixingRule(2); + testFluid.setMultiPhaseCheck(true); + + testFluid.setTemperature(24.0, "C"); + testFluid.setPressure(48.0, "bara"); + testFluid.setTotalFlowRate(1.0, "MSm3/day"); + + Stream stream_1 = new Stream("Stream1", testFluid); + comp1 = new Compressor("cmp1", stream_1); + comp1.setUsePolytropicCalc(true); + // comp1.getAntiSurge().setActive(true); + comp1.setSpeed(11918); + + double[] chartConditions = new double[] {0.3, 1.0, 1.0, 1.0}; + // double[] speed = new double[] { 1000.0, 2000.0, 3000.0, 4000.0 }; + // double[][] flow = new double[][] { { 453.2, 600.0, 750.0, 800.0 }, { 453.2, + // 600.0, 750.0, 800.0 + // }, { 453.2, 600.0, 750.0, 800.0 }, { 453.2, 600.0, 750.0, 800.0 } }; + // double[][] head = new double[][] { { 10000.0, 9000.0, 8000.0, 7500.0 }, { + // 10000.0, 9000.0, 8000.0, 7500.0 }, { 10000.0, 9000.0, 8000.0, 7500.0 }, { + // 10000.0, 9000.0, 8000.0, 7500.0 } }; + // double[][] polyEff = new double[][] { { + // 90.0, 91.0, 89.0, 88.0 }, { 90.0, 91.0, 89.0, 88.0 }, { 90.0, 91.0, 89.0, + // 88.1 }, { 90.0, 91.0, 89.0, 88.1 } }; + + double[] speed = new double[] {12913, 12298, 11683, 11098, 10453, 9224, 8609, 8200}; + double[][] flow = new double[][] { + {2789.1285, 3174.0375, 3689.2288, 4179.4503, 4570.2768, 4954.7728, 5246.0329, 5661.0331}, + {2571.1753, 2943.7254, 3440.2675, 3837.4448, 4253.0898, 4668.6643, 4997.1926, 5387.4952}, + {2415.3793, 2763.0706, 3141.7095, 3594.7436, 4047.6467, 4494.1889, 4853.7353, 5138.7858}, + {2247.2043, 2799.7342, 3178.3428, 3656.1551, 4102.778, 4394.1591, 4648.3224, 4840.4998}, + {2072.8397, 2463.9483, 2836.4078, 3202.5266, 3599.6333, 3978.0203, 4257.0022, 4517.345}, + {1835.9552, 2208.455, 2618.1322, 2940.8034, 3244.7852, 3530.1279, 3753.3738, 3895.9746}, + {1711.3386, 1965.8848, 2356.9431, 2685.9247, 3008.5154, 3337.2855, 3591.5092}, + {1636.5807, 2002.8708, 2338.0319, 2642.1245, 2896.4894, 3113.6264, 3274.8764, 3411.2977}}; + double[][] head = + new double[][] {{80.0375, 78.8934, 76.2142, 71.8678, 67.0062, 60.6061, 53.0499, 39.728}, + {72.2122, 71.8369, 68.9009, 65.8341, 60.7167, 54.702, 47.2749, 35.7471}, + {65.1576, 64.5253, 62.6118, 59.1619, 54.0455, 47.0059, 39.195, 31.6387}, + {58.6154, 56.9627, 54.6647, 50.4462, 44.4322, 38.4144, 32.9084, 28.8109}, + {52.3295, 51.0573, 49.5283, 46.3326, 42.3685, 37.2502, 31.4884, 25.598}, + {40.6578, 39.6416, 37.6008, 34.6603, 30.9503, 27.1116, 23.2713, 20.4546}, + {35.2705, 34.6359, 32.7228, 31.0645, 27.0985, 22.7482, 18.0113}, + {32.192, 31.1756, 29.1329, 26.833, 23.8909, 21.3324, 18.7726, 16.3403},}; + double[][] polyEff = new double[][] { + {77.2452238409573, 79.4154186459363, 80.737960012489, 80.5229826589649, 79.2210931638144, + 75.4719133864634, 69.6034181197298, 58.7322388482707}, + {77.0107837113504, 79.3069974136389, 80.8941189021135, 80.7190194665918, 79.5313242980328, + 75.5912622896367, 69.6846136362097, 60.0043057990909}, + {77.0043065299874, 79.1690958847856, 80.8038169975675, 80.6543975614197, 78.8532389102705, + 73.6664774270613, 66.2735600426727, 57.671664571658}, + {77.0716623789093, 80.4629750233093, 81.1390811169072, 79.6374242667478, 75.380928428817, + 69.5332969549779, 63.7997587622339, 58.8120614497758}, + {76.9705872525642, 79.8335492585324, 80.9468133671171, 80.5806471927835, 78.0462158225426, + 73.0403707523258, 66.5572286338589, 59.8624822515064}, + {77.5063036680357, 80.2056198362559, 81.0339108025933, 79.6085962687939, 76.3814534404405, + 70.8027503005902, 64.6437367160571, 60.5299349982342}, + {77.8175271586685, 80.065165942218, 81.0631362122632, 79.8955051771299, 76.1983240929369, + 69.289982774309, 60.8567149372229}, + {78.0924334304045, 80.9353551568667, 80.7904437766234, 78.8639325223295, 75.2170936751143, + 70.3105081673411, 65.5507568533569, 61.0391468300337}}; + + // double[] chartConditions = new double[] { 0.3, 1.0, 1.0, 1.0 }; + // double[] speed = new double[] { 13402.0 }; + // double[][] flow = new double[][] { { 1050.0, 1260.0, 1650.0, 1950.0 } }; + // double[][] head = new double[][] { { 8555.0, 8227.0, 6918.0, 5223.0 } }; + // double[][] head = new double[][] { { 85.0, 82.0, 69.0, 52.0 } }; + // double[][] polyEff = new double[][] { { 66.8, 69.0, 66.4, 55.6 } }; + comp1.getCompressorChart().setCurves(chartConditions, speed, flow, head, polyEff); + comp1.getCompressorChart().setHeadUnit("kJ/kg"); + + double[] surgeflow = new double[] {2789.0, 2550.0, 2500.0, 2200.0}; + double[] surgehead = new double[] {80.0, 72.0, 70.0, 65.0}; + comp1.getCompressorChart().getSurgeCurve().setCurve(chartConditions, surgeflow, surgehead); + // comp1.getAntiSurge().setActive(true); + comp1.getAntiSurge().setSurgeControlFactor(1.0); + /* + * double[] surgeflow = new double[] { 453.2, 550.0, 700.0, 800.0 }; double[] surgehead = new + * double[] { 6000.0, 7000.0, 8000.0, 10000.0 }; + * comp1.getCompressorChart().getSurgeCurve().setCurve(chartConditions, surgeflow, surgehead) + * double[] stoneWallflow = new double[] { 923.2, 950.0, 980.0, 1000.0 }; double[] stoneWallHead + * = new double[] { 6000.0, 7000.0, 8000.0, 10000.0 }; + * comp1.getCompressorChart().getStoneWallCurve().setCurve(chartConditions, stoneWallflow, + * stoneWallHead); + */ + } + + @Test + public void test_Run() { + neqsim.processSimulation.processSystem.ProcessSystem operations = + new neqsim.processSimulation.processSystem.ProcessSystem(); + Stream stream_1 = (Stream) comp1.getInletStream(); + operations.add(stream_1); + operations.add(comp1); + operations.run(); + // operations.displayResult(); + + /* + * System.out.println("power " + comp1.getPower()); System.out.println("is surge " + + * comp1.getAntiSurge().isSurge()); System.out .println("fraction in anti surge line " + + * comp1.getAntiSurge().getCurrentSurgeFraction()); + * System.out.println("Polytropic head from curve:" + comp1.getPolytropicHead()); + * System.out.println("Polytropic eff from curve:" + comp1.getPolytropicEfficiency() * 100.0); + * System.out.println("flow " + stream_1.getThermoSystem().getFlowRate("m3/hr")); + * + * System.out.println("speed " + comp1.getCompressorChart().getSpeed( + * stream_1.getThermoSystem().getFlowRate("m3/hr") + 10.0, comp1.getPolytropicHead())); + * System.out.println("pressure out " + comp1.getOutletPressure()); + * System.out.println("temperature out " + (comp1.getOutTemperature() - 273.15) + " C"); + */ + + double temperatureOut = 273.15 + 84; + comp1.setOutletPressure(96.0); + comp1.setOutTemperature(temperatureOut); + operations.run(); + double polytropicHead = comp1.getPolytropicHead(); + double flowRate = stream_1.getThermoSystem().getFlowRate("m3/hr"); + double calcSpeed = comp1.getCompressorChart().getSpeed(flowRate, polytropicHead); + + assertTrue(calcSpeed > 0); + /* + * System.out.println("polytopic head " + polytropicHead); + * System.out.println("polytopic efficiency " + comp1.getPolytropicEfficiency()); + * System.out.println("temperature out " + (comp1.getOutTemperature() - 273.15) + " C"); + * System.out.println("calculated speed " + calcSpeed); System.out.println("power " + + * comp1.getPower()); + */ + + // comp1.getCompressorChart().plot(); + } +} diff --git a/src/test/java/neqsim/processSimulation/processEquipment/heatExchanger/HeatExchangerTest.java b/src/test/java/neqsim/processSimulation/processEquipment/heatExchanger/HeatExchangerTest.java index 4f371b95b8..24c0fcead4 100644 --- a/src/test/java/neqsim/processSimulation/processEquipment/heatExchanger/HeatExchangerTest.java +++ b/src/test/java/neqsim/processSimulation/processEquipment/heatExchanger/HeatExchangerTest.java @@ -51,7 +51,7 @@ public static void test_Run1(String args[]) { valv1.setOutletPressure(5.0); Recycle resyc = new Recycle("resyc"); - resyc.addStream(valv1.getOutStream()); + resyc.addStream(valv1.getOutletStream()); resyc.setOutletStream(stream_Cold); neqsim.processSimulation.processSystem.ProcessSystem operations = diff --git a/src/test/java/neqsim/processSimulation/processEquipment/mixer/MixerTest.java b/src/test/java/neqsim/processSimulation/processEquipment/mixer/MixerTest.java index 0912538e65..0485747fc1 100644 --- a/src/test/java/neqsim/processSimulation/processEquipment/mixer/MixerTest.java +++ b/src/test/java/neqsim/processSimulation/processEquipment/mixer/MixerTest.java @@ -56,6 +56,7 @@ void testRun() { testMixer.addStream(gasStream); testMixer.addStream(waterStream); testMixer.run(); - assertEquals(testMixer.getOutStream().getFluid().getEnthalpy("kJ/kg"),-177.27666625251516, 1e-3); + assertEquals(testMixer.getOutletStream().getFluid().getEnthalpy("kJ/kg"), -177.27666625251516, + 1e-3); } } diff --git a/src/test/java/neqsim/processSimulation/processEquipment/separator/SeparatorTest.java b/src/test/java/neqsim/processSimulation/processEquipment/separator/SeparatorTest.java new file mode 100644 index 0000000000..c3206ced21 --- /dev/null +++ b/src/test/java/neqsim/processSimulation/processEquipment/separator/SeparatorTest.java @@ -0,0 +1,69 @@ +package neqsim.processSimulation.processEquipment.separator; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import neqsim.processSimulation.processEquipment.stream.Stream; +import neqsim.processSimulation.processEquipment.stream.StreamInterface; +import neqsim.processSimulation.processSystem.ProcessSystem; +import neqsim.thermo.system.SystemSrkCPAstatoil; + +/** + * @author ESOL + * + */ +class SeparatorTest extends neqsim.NeqSimTest { + static neqsim.thermo.system.SystemInterface testSystem = null; + double pressure_inlet = 55.0; + double temperature_inlet = 35.0; + double gasFlowRate = 5.0; + ProcessSystem processOps = null; + + /** + * @throws java.lang.Exception + */ + @BeforeEach + public void setUpBeforeClass() throws Exception { + testSystem = new SystemSrkCPAstatoil(298.0, 10.0); + testSystem.addComponent("methane", 100.0); + testSystem.addComponent("ethane", 10.0); + testSystem.addComponent("nC10", 10.0); + testSystem.addComponent("water", 10.0); + testSystem.setMixingRule(10); + testSystem.setMultiPhaseCheck(true); + + processOps = new ProcessSystem(); + + StreamInterface inletStream = new Stream("inlet stream", testSystem); + inletStream.setPressure(pressure_inlet, "bara"); + inletStream.setTemperature(temperature_inlet, "C"); + inletStream.setFlowRate(gasFlowRate, "MSm3/day"); + + Separator sep = new Separator("inlet separator"); + sep.setInletStream(inletStream); + + StreamInterface gasFromSep = new Stream("liquid from separator", sep.getLiquidOutStream()); + StreamInterface liqFromSep = new Stream("liquid from separator", sep.getLiquidOutStream()); + + processOps.add(inletStream); + processOps.add(sep); + // processOps.add(gasFromSep); + // processOps.add(liqFromSep); + + // processOps.run(); + } + + @Test + public void testFlow() { + ((StreamInterface) processOps.getUnit("inlet stream")).setFlowRate(0.01, "MSm3/day"); + processOps.run(); + } + + @Test + public void testOnePhase() { + ((StreamInterface) processOps.getUnit("inlet stream")).setFlowRate(1.0, "MSm3/day"); + ((StreamInterface) processOps.getUnit("inlet stream")).getFluid() + .setMolarComposition(new double[] {1.0, 0.0, 0.0, 0.0}); + + processOps.run(); + } +} diff --git a/src/test/java/neqsim/processSimulation/processEquipment/splitter/ComponentSplitterTest.java b/src/test/java/neqsim/processSimulation/processEquipment/splitter/ComponentSplitterTest.java new file mode 100644 index 0000000000..effb512df6 --- /dev/null +++ b/src/test/java/neqsim/processSimulation/processEquipment/splitter/ComponentSplitterTest.java @@ -0,0 +1,52 @@ +package neqsim.processSimulation.processEquipment.splitter; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import neqsim.processSimulation.processEquipment.stream.Stream; +import neqsim.processSimulation.processEquipment.stream.StreamInterface; +import neqsim.processSimulation.processSystem.ProcessSystem; +import neqsim.thermo.system.SystemSrkEos; + +class ComponentSplitterTest { + static neqsim.thermo.system.SystemInterface testSystem = null; + double pressure_inlet = 85.0; + double temperature_inlet = 35.0; + double gasFlowRate = 5.0; + ProcessSystem processOps = null; + + @BeforeEach + public void setUpBeforeClass() throws Exception { + testSystem = new SystemSrkEos(298.0, 10.0); + testSystem.addComponent("methane", 100.0); + testSystem.addComponent("ethane", 10.0); + testSystem.addComponent("propane", 10.0); + processOps = new ProcessSystem(); + Stream inletStream = new Stream("inletStream", testSystem); + inletStream.setName("inlet stream"); + inletStream.setPressure(pressure_inlet, "bara"); + inletStream.setTemperature(temperature_inlet, "C"); + inletStream.setFlowRate(gasFlowRate, "MSm3/day"); + + ComponentSplitter splitter = new ComponentSplitter("splitter", inletStream); + splitter.setSplitFactors(new double[] {1.00, 0.0, 0.0}); + + StreamInterface stream1 = new Stream("stream 1", splitter.getSplitStream(0)); + StreamInterface stream2 = new Stream("stream 2",splitter.getSplitStream(1)); + + processOps.add(inletStream); + processOps.add(splitter); + processOps.add(stream1); + processOps.add(stream2); + } + + @Test + public void testRun() { + processOps.run(); + //((StreamInterface)processOps.getUnit("stream 1")).displayResult(); + //((StreamInterface)processOps.getUnit("stream 2")).displayResult(); + assertEquals(((StreamInterface)processOps.getUnit("stream 1")).getFluid().getComponent("methane").getx(), 1.0, 1e-6); + assertEquals(((StreamInterface)processOps.getUnit("stream 2")).getFluid().getComponent("methane").getx(), 0.0, 1e-6); + } + +} diff --git a/src/test/java/neqsim/processSimulation/processSystem/GlycolRigTest.java b/src/test/java/neqsim/processSimulation/processSystem/GlycolRigTest.java new file mode 100644 index 0000000000..d8ba2ac96b --- /dev/null +++ b/src/test/java/neqsim/processSimulation/processSystem/GlycolRigTest.java @@ -0,0 +1,177 @@ +package neqsim.processSimulation.processSystem; + +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import neqsim.processSimulation.processEquipment.absorber.WaterStripperColumn; +import neqsim.processSimulation.processEquipment.compressor.Compressor; +import neqsim.processSimulation.processEquipment.distillation.DistillationColumn; +import neqsim.processSimulation.processEquipment.heatExchanger.Heater; +import neqsim.processSimulation.processEquipment.mixer.Mixer; +import neqsim.processSimulation.processEquipment.separator.Separator; +import neqsim.processSimulation.processEquipment.stream.Stream; +import neqsim.processSimulation.processEquipment.util.Recycle; + +public class GlycolRigTest extends neqsim.NeqSimTest { + ProcessSystem p; + String _name = "TestProcess"; + + @BeforeEach + public void setUp() { + p = new ProcessSystem(); + p.setName(_name); + } + + @Test + public void runTEGProcessTest() { + neqsim.thermo.system.SystemInterface feedTEG = + new neqsim.thermo.system.SystemSrkCPAstatoil(273.15 + 145.0, 1.2); + feedTEG.addComponent("nitrogen", 0.00005); + feedTEG.addComponent("water", 0.19 - 1 * 0.00005); + feedTEG.addComponent("TEG", 0.8); + feedTEG.setMixingRule(10); + feedTEG.setMolarComposition(new double[] {0.00003, 0.2 - 1 * 0.00003, 0.8}); + + neqsim.thermo.system.SystemInterface strippingGasToStripperFluid = feedTEG.clone(); + strippingGasToStripperFluid.setMolarComposition(new double[] {1.0, 0.0, 0.0}); + + Stream strippingGas = new Stream("stripgas", strippingGasToStripperFluid); + strippingGas.setFlowRate(13.0, "kg/hr"); + strippingGas.setTemperature(55.0, "C"); + strippingGas.setPressure(0.2, "barg"); + + Stream gasToReboiler = strippingGas.clone(); + gasToReboiler.setName("gas to reboiler"); + + Stream TEGtoRegenerator = new Stream("feedTEG", feedTEG); + TEGtoRegenerator.setName("TEG to regenerator"); + TEGtoRegenerator.setFlowRate(400.0, "kg/hr"); + TEGtoRegenerator.setTemperature(145.0, "C"); + TEGtoRegenerator.setPressure(0.2, "barg"); + + DistillationColumn column = new DistillationColumn(1, true, true); + column.setName("TEG regeneration column"); + column.addFeedStream(TEGtoRegenerator, 1); + column.getReboiler().setOutTemperature(273.15 + 209.0); + column.getCondenser().setOutTemperature(273.15 + 94.0); + column.getReboiler().addStream(gasToReboiler); + column.setTopPressure(0.1 + 1.01325); + column.setBottomPressure(0.2 + 1.01325); + + WaterStripperColumn stripper = new WaterStripperColumn("TEG stripper"); + stripper.addSolventInStream(column.getLiquidOutStream()); + stripper.addGasInStream(strippingGas); + stripper.setNumberOfStages(2); + stripper.setStageEfficiency(0.7); + + Recycle recycleGasFromStripper = new Recycle("stripping gas recirc"); + recycleGasFromStripper.addStream(stripper.getGasOutStream()); + recycleGasFromStripper.setOutletStream(gasToReboiler); + + Heater coolerPipe = new Heater(column.getGasOutStream()); + coolerPipe.setName("heat loss cooling"); + coolerPipe.setOutTemperature(273.15 + 81.0); + + Heater coolerRegenGas = new Heater(coolerPipe.getOutStream()); + coolerRegenGas.setName("regen gas cooler"); + coolerRegenGas.setOutTemperature(273.15 + 25.0); + + Separator sepregenGas = new Separator(coolerRegenGas.getOutStream()); + sepregenGas.setName("regen gas separator"); + + Compressor blower = new Compressor(sepregenGas.getGasOutStream()); + blower.setOutletPressure(0.2, "barg"); + + Heater gasHeater = new Heater(blower.getOutStream()); + gasHeater.setOutTemperature(273.15 + 53.0); + + Recycle recycleGasfEED = new Recycle("FEED gas recirc"); + recycleGasfEED.addStream(gasHeater.getOutStream()); + recycleGasfEED.setOutletStream(strippingGas); + recycleGasfEED.setPriority(200); + + Heater coolerStripper = new Heater(stripper.getSolventOutStream()); + coolerStripper.setName("TEG cooler"); + coolerStripper.setOutTemperature(273.15 + 98.0); + + Stream liquidToTreatment = new Stream(sepregenGas.getLiquidOutStream()); + liquidToTreatment.setName("water to treatment"); + + Mixer TEGWaterMixer = new Mixer("TEG water mixer"); + TEGWaterMixer.addStream(coolerStripper.getOutStream()); + TEGWaterMixer.addStream(liquidToTreatment); + + neqsim.processSimulation.processSystem.ProcessSystem operations = + new neqsim.processSimulation.processSystem.ProcessSystem(); + operations.add(TEGtoRegenerator); + operations.add(strippingGas); + operations.add(gasToReboiler); + operations.add(column); + operations.add(coolerPipe); + operations.add(coolerRegenGas); + operations.add(sepregenGas); + operations.add(blower); + operations.add(gasHeater); + operations.add(recycleGasfEED); + operations.add(liquidToTreatment); + operations.add(stripper); + operations.add(recycleGasFromStripper); + operations.add(coolerStripper); + operations.add(TEGWaterMixer); + + Thread runThr = operations.runAsThread(); + try { + runThr.join(100000); + } catch (Exception e) { + + } + double wtpWaterRichTEG = + TEGtoRegenerator.getFluid().getPhase("aqueous").getWtFrac("TEG") * 100.0; + double wtpWaterFromReboil = + column.getLiquidOutStream().getFluid().getPhase("aqueous").getWtFrac("TEG") * 100.0; + double wtpWaterFromStripper = + stripper.getSolventOutStream().getFluid().getPhase("aqueous").getWtFrac("TEG") * 100.0; + System.out.println("wtpRichTEG " + wtpWaterRichTEG); + System.out.println("wtpWaterFromReboil " + wtpWaterFromReboil); + System.out.println("wtpWaterFromStripper " + wtpWaterFromStripper); + // double wtpWaterFromReboiler = + // column.getLiquidOutStream().getFluid().getPhase("aqueous").getWtFrac("water")*100.0 + // double wtpTEGSeparatorOut = + // liquidToTreatment.getFluid().getPhase("aqueous").getWtFrac("TEG")*100.0 + // double flowrateLiquidSeparatorOut = liquidToTreatment.getFlowRate("kg/hr") + // double wtWaterFromStripper = + // stripper.getSolventOutStream().getFluid().getPhase("aqueous").getWtFrac("water")*100.0 + // double wtWaterBufferTank = + // liquidFromBufferTank.getFluid().getPhase("aqueous").getWtFrac("water")*100.0 + //TEGtoRegenerator.displayResult(); + System.out.println("water to regenerator " + + TEGtoRegenerator.getFluid().getComponent("water").getTotalFlowRate("kg/hr")); + System.out.println("TEG to regenerator " + + TEGtoRegenerator.getFluid().getComponent("TEG").getTotalFlowRate("kg/hr")); + // System.out.println("oxygen to regenerator " + // + TEGtoRegenerator.getFluid().getComponent("oxygen").getTotalFlowRate("kg/hr")); + System.out.println("nitrogen to regenerator " + + TEGtoRegenerator.getFluid().getComponent("nitrogen").getTotalFlowRate("kg/hr")); + + System.out.println("water liquid from regenerator " + + column.getLiquidOutStream().getFluid().getComponent("water").getTotalFlowRate("kg/hr")); + System.out.println("water gas from regenerator " + + column.getGasOutStream().getFluid().getComponent("water").getTotalFlowRate("kg/hr")); + + double waterBalanceColumn = + column.getLiquidOutStream().getFluid().getComponent("water").getTotalFlowRate("kg/hr") + + column.getGasOutStream().getFluid().getComponent("water").getTotalFlowRate("kg/hr") + - TEGtoRegenerator.getFluid().getComponent("water").getTotalFlowRate("kg/hr") + - gasToReboiler.getFluid().getComponent("water").getTotalFlowRate("kg/hr"); + System.out.println("water balance " + waterBalanceColumn); + + System.out.println("wt water to reboil " + + TEGtoRegenerator.getFluid().getPhase("aqueous").getWtFrac("water") * 100.0); + + System.out.println("wt water from mixer " + + TEGWaterMixer.getFluid().getPhase("aqueous").getWtFrac("water") * 100.0); + //strippingGas.displayResult(); + System.out.println("stripping gas rate " + strippingGas.getFlowRate("kg/hr")); + Assertions.assertEquals(0.0, waterBalanceColumn, 1e-3); + } +} diff --git a/src/test/java/neqsim/processSimulation/processSystem/ProcessSystemControllerTest.java b/src/test/java/neqsim/processSimulation/processSystem/ProcessSystemControllerTest.java new file mode 100644 index 0000000000..7e77bda81f --- /dev/null +++ b/src/test/java/neqsim/processSimulation/processSystem/ProcessSystemControllerTest.java @@ -0,0 +1,127 @@ +package neqsim.processSimulation.processSystem; + +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import neqsim.processSimulation.controllerDevice.ControllerDeviceBaseClass; +import neqsim.processSimulation.controllerDevice.ControllerDeviceInterface; +import neqsim.processSimulation.measurementDevice.VolumeFlowTransmitter; +import neqsim.processSimulation.processEquipment.separator.Separator; +import neqsim.processSimulation.processEquipment.stream.Stream; +import neqsim.processSimulation.processEquipment.valve.ThrottlingValve; +import neqsim.thermo.system.SystemInterface; + +public class ProcessSystemControllerTest extends neqsim.NeqSimTest { + ProcessSystem p; + + @BeforeEach + public void setUp() { + p = new ProcessSystem(); + } + + @Test + public void testGetName() { + String name = "TestProsess"; + p.setName(name); + Assertions.assertEquals(name, p.getName()); + } + + @Test + void testGetTime() { + + } + + @Test + void testGetTimeStep() { + + } + + private SystemInterface getTestSystem() { + neqsim.thermo.system.SystemInterface testSystem = + new neqsim.thermo.system.SystemSrkEos((273.15 + 25.0), 10.00); + testSystem.addComponent("methane", 0.900); + testSystem.addComponent("ethane", 0.100); + testSystem.addComponent("n-heptane", 0.1); + testSystem.createDatabase(true); + testSystem.setMixingRule(2); + return testSystem; + } + + private double getRandomDistrurbanceFlowRate() { + double max = 5; + double min = -5; + double random_double = (int) Math.floor(Math.random() * (max - min + 1) + min); + return random_double; + } + + @Test + public void testStaticSimulationWithController() { + neqsim.thermo.system.SystemInterface testSystem = getTestSystem(); + + Stream stream_1 = new Stream("Stream1", testSystem); + stream_1.setFlowRate(100.0 + getRandomDistrurbanceFlowRate(), "kg/hr"); + stream_1.setPressure(10.0, "bara"); + + ThrottlingValve valve_1 = new ThrottlingValve("valve_1", stream_1); + valve_1.setOutletPressure(5.0); + + Separator separator_1 = new Separator("sep 1"); + separator_1.addStream(valve_1.getOutletStream()); + + VolumeFlowTransmitter flowTransmitter = + new VolumeFlowTransmitter(separator_1.getGasOutStream()); + flowTransmitter.setUnit("kg/hr"); + flowTransmitter.setMaximumValue(150.0); + flowTransmitter.setMinimumValue(10.0); + + ControllerDeviceInterface flowController = new ControllerDeviceBaseClass(); + flowController.setTransmitter(flowTransmitter); + flowController.setReverseActing(true); + flowController.setControllerSetPoint(65.0 + getRandomDistrurbanceFlowRate()); + flowController.setControllerParameters(0.5, 100.100, 0.0); + + p.add(stream_1); + p.add(valve_1); + p.add(separator_1); + p.add(flowTransmitter); + stream_1.setController(flowController); + + p.run(); + + // transient behaviour + p.setTimeStep(1.0); + for (int i = 0; i < 55; i++) { + flowController.setControllerSetPoint(65.0 + getRandomDistrurbanceFlowRate()); + p.runTransient(); + System.out.println( + "flow rate " + valve_1.getOutletStream().getFluid().getPhase("gas").getFlowRate("kg/hr") + + " controller response " + flowController.getResponse() + " valve opening " + + valve_1.getPercentValveOpening() + " pressure " + + separator_1.getGasOutStream().getPressure()); + } + + for (int i = 0; i < 100; i++) { + flowController.setControllerSetPoint(55.0 + getRandomDistrurbanceFlowRate()); + // stream_1.runTransient(1.0); + p.runTransient(); + System.out.println( + "flow rate " + valve_1.getOutletStream().getFluid().getPhase("gas").getFlowRate("kg/hr") + + " controller response " + flowController.getResponse() + " valve opening " + + valve_1.getPercentValveOpening() + " pressure " + + separator_1.getGasOutStream().getPressure()); + } + + // transient behaviour + p.setTimeStep(1.0); + for (int i = 0; i < 55; i++) { + flowController.setControllerSetPoint(75.0 + getRandomDistrurbanceFlowRate()); + p.runTransient(); + System.out.println( + "flow rate " + valve_1.getOutletStream().getFluid().getPhase("gas").getFlowRate("kg/hr") + + " controller response " + flowController.getResponse() + " valve opening " + + valve_1.getPercentValveOpening() + " pressure " + + separator_1.getGasOutStream().getPressure()); + // p.runTransient(); + } + } +} diff --git a/src/test/java/neqsim/processSimulation/processSystem/ProcessSystemRunTransientTest.java b/src/test/java/neqsim/processSimulation/processSystem/ProcessSystemRunTransientTest.java index d91daff9fe..2d0e9699ca 100644 --- a/src/test/java/neqsim/processSimulation/processSystem/ProcessSystemRunTransientTest.java +++ b/src/test/java/neqsim/processSimulation/processSystem/ProcessSystemRunTransientTest.java @@ -1,8 +1,10 @@ package neqsim.processSimulation.processSystem; +import static org.junit.jupiter.api.Assertions.assertEquals; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import neqsim.processSimulation.SimulationInterface; import neqsim.processSimulation.controllerDevice.ControllerDeviceBaseClass; import neqsim.processSimulation.controllerDevice.ControllerDeviceInterface; import neqsim.processSimulation.measurementDevice.LevelTransmitter; @@ -13,173 +15,203 @@ import neqsim.processSimulation.processEquipment.valve.ThrottlingValve; import neqsim.thermo.system.SystemInterface; -public class ProcessSystemRunTransientTest extends neqsim.NeqSimTest{ - ProcessSystem p; - - @BeforeEach - public void setUp() { - p = new ProcessSystem(); +public class ProcessSystemRunTransientTest extends neqsim.NeqSimTest { + ProcessSystem p; + + @BeforeEach + public void setUp() { + p = new ProcessSystem(); + } + + @Test + public void testGetName() { + String name = "TestProsess"; + p.setName(name); + Assertions.assertEquals(name, p.getName()); + } + + @Test + void testGetTime() { + + } + + @Test + void testGetTimeStep() { + + } + + private SystemInterface getTestSystem() { + neqsim.thermo.system.SystemInterface testSystem = + new neqsim.thermo.system.SystemSrkEos((273.15 + 25.0), 10.00); + testSystem.addComponent("methane", 0.900); + testSystem.addComponent("ethane", 0.100); + testSystem.addComponent("n-heptane", 1.00); + testSystem.createDatabase(true); + testSystem.setMixingRule(2); + return testSystem; + } + + // @Test + public void testDynamicCalculation() { + neqsim.thermo.system.SystemInterface testSystem = getTestSystem(); + + Stream stream1 = new Stream("Stream1", testSystem); + stream1.setFlowRate(50.0, "kg/hr"); + stream1.setPressure(10.0, "bara"); + + ThrottlingValve valve1 = new ThrottlingValve("valve_1", stream1); + valve1.setOutletPressure(5.0); + valve1.setPercentValveOpening(50); + + Separator separator1 = new Separator("sep 1"); + separator1.addStream(valve1.getOutletStream()); + + ThrottlingValve valve2 = new ThrottlingValve("valve_2", separator1.getLiquidOutStream()); + valve2.setOutletPressure(1.0); + valve2.setPercentValveOpening(50); + + ThrottlingValve valve3 = new ThrottlingValve("valve_3", separator1.getGasOutStream()); + valve3.setOutletPressure(1.0); + valve3.setPercentValveOpening(50); + + VolumeFlowTransmitter flowTransmitter = new VolumeFlowTransmitter(stream1); + flowTransmitter.setUnit("kg/hr"); + flowTransmitter.setMaximumValue(100.0); + flowTransmitter.setMinimumValue(1.0); + + ControllerDeviceInterface flowController = new ControllerDeviceBaseClass(); + flowController.setTransmitter(flowTransmitter); + flowController.setReverseActing(true); + flowController.setControllerSetPoint(63.5); + flowController.setControllerParameters(0.1, 0.10, 0.0); + + p.add(stream1); + p.add(valve1); + p.add(separator1); + p.add(valve2); + p.add(valve3); + p.add(flowTransmitter); + valve1.setController(flowController); + + p.run(); + + // transient behaviour + p.setTimeStep(1.0); + for (int i = 0; i < 5; i++) { + // System.out.println("volume flow " + flowTransmitter.getMeasuredValue() + // + " valve opening " + valve_1.getPercentValveOpening() + " pressure " + // + separator_1.getGasOutStream().getPressure()); + p.runTransient(); + for (SimulationInterface sim : p.getUnitOperations()) { + assertEquals(sim.getCalculationIdentifier(), p.getCalculationIdentifier()); + } } - - @Test - public void testGetName() { - String name = "TestProsess"; - p.setName(name); - Assertions.assertEquals(name, p.getName()); + } + + @Test + public void testDynamicCalculation2() { + neqsim.thermo.system.SystemInterface testSystem2 = + new neqsim.thermo.system.SystemSrkEos((273.15 + 25.0), 10.00); + testSystem2.addComponent("methane", 1.1); + testSystem2.addComponent("ethane", 0.10001); + testSystem2.addComponent("n-heptane", 1.001); + testSystem2.setMixingRule(2); + + Stream purgeStream = new Stream("Purge Stream", testSystem2); + ThrottlingValve purgeValve = new ThrottlingValve("purgeValve", purgeStream); + purgeValve.setOutletPressure(7.0); + purgeValve.setPercentValveOpening(50.0); + + neqsim.thermo.system.SystemInterface testSystem = getTestSystem(); + Stream stream1 = new Stream("Stream1", testSystem); + stream1.setCalculateSteadyState(false); + ThrottlingValve valve1 = new ThrottlingValve("valve_1", stream1); + valve1.setOutletPressure(7.0); + valve1.setPercentValveOpening(50); + + Separator separator1 = new Separator("separator_1"); + separator1.addStream(valve1.getOutletStream()); + separator1.addStream(purgeValve.getOutletStream()); + separator1.setCalculateSteadyState(true); + + ThrottlingValve valve2 = new ThrottlingValve("valve_2", separator1.getLiquidOutStream()); + valve2.setOutletPressure(5.0); + valve2.setPercentValveOpening(50); + valve2.setCalculateSteadyState(true); + // valve_2.setCv(10.0); + + ThrottlingValve valve3 = new ThrottlingValve("valve_3", separator1.getGasOutStream()); + valve3.setOutletPressure(5.0); + valve3.setPercentValveOpening(50); + valve3.setCalculateSteadyState(true); + // valve_3.setCv(10.0); + + LevelTransmitter separatorLevelTransmitter = new LevelTransmitter(separator1); + separatorLevelTransmitter.setName("separatorLevelTransmitter1"); + separatorLevelTransmitter.setUnit("meter"); + separatorLevelTransmitter.setMaximumValue(1.0); + separatorLevelTransmitter.setMinimumValue(0.0); + + ControllerDeviceInterface separatorLevelController = new ControllerDeviceBaseClass(); + separatorLevelController.setReverseActing(true); + separatorLevelController.setTransmitter(separatorLevelTransmitter); + separatorLevelController.setControllerSetPoint(0.3); + separatorLevelController.setControllerParameters(1, 1000.0, 0.0); + + PressureTransmitter separatorPressureTransmitter = + new PressureTransmitter(separator1.getGasOutStream()); + separatorPressureTransmitter.setUnit("bar"); + separatorPressureTransmitter.setMaximumValue(10.0); + separatorPressureTransmitter.setMinimumValue(1.0); + + ControllerDeviceInterface separatorPressureController = new ControllerDeviceBaseClass(); + separatorPressureController.setTransmitter(separatorPressureTransmitter); + separatorPressureController.setReverseActing(false); + separatorPressureController.setControllerSetPoint(7.0); + separatorPressureController.setControllerParameters(0.5, 10.0, 0.0); + + p.add(stream1); + p.add(valve1); + + p.add(purgeStream); + p.add(purgeValve); + p.add(separator1); + p.add(valve2); + p.add(valve3); + + // add transmitters + p.add(separatorLevelTransmitter); + valve2.setController(separatorLevelController); + + p.add(separatorPressureTransmitter); + valve3.setController(separatorPressureController); + + p.run(); + for (SimulationInterface sim : p.getUnitOperations()) { + assertEquals(sim.getCalculationIdentifier(), p.getCalculationIdentifier()); } - @Test - void testGetTime() { - + // p.displayResult(); + p.setTimeStep(0.01); + for (int i = 0; i < 500; i++) { + // System.out.println("pressure "+separator_1.getGasOutStream().getPressure()+ " flow "+ + // separator_1.getGasOutStream().getFlowRate("kg/hr") + " sepr height + // "+separatorLevelTransmitter.getMeasuredValue()); + p.runTransient(); + for (SimulationInterface sim : p.getUnitOperations()) { + assertEquals(p.getCalculationIdentifier(), sim.getCalculationIdentifier()); + } } - @Test - void testGetTimeStep() { - - } - - private SystemInterface getTestSystem() { - neqsim.thermo.system.SystemInterface testSystem = new neqsim.thermo.system.SystemSrkEos((273.15 + 25.0), 10.00); - testSystem.addComponent("methane", 0.900); - testSystem.addComponent("ethane", 0.100); - testSystem.addComponent("n-heptane", 1.00); - testSystem.createDatabase(true); - testSystem.setMixingRule(2); - return testSystem; - } - - // @Test - public void testDynamicCalculation() { - neqsim.thermo.system.SystemInterface testSystem = getTestSystem(); - - Stream stream_1 = new Stream("Stream1", testSystem); - stream_1.setFlowRate(50.0, "kg/hr"); - stream_1.setPressure(10.0, "bara"); - - ThrottlingValve valve_1 = new ThrottlingValve("valve_1", stream_1); - valve_1.setOutletPressure(5.0); - valve_1.setPercentValveOpening(50); - - Separator separator_1 = new Separator("sep 1"); - separator_1.addStream(valve_1.getOutStream()); - - ThrottlingValve valve_2 = new ThrottlingValve("valve_2", separator_1.getLiquidOutStream()); - valve_2.setOutletPressure(1.0); - valve_2.setPercentValveOpening(50); - - ThrottlingValve valve_3 = new ThrottlingValve("valve_3", separator_1.getGasOutStream()); - valve_3.setOutletPressure(1.0); - valve_3.setPercentValveOpening(50); - - VolumeFlowTransmitter flowTransmitter = new VolumeFlowTransmitter(stream_1); - flowTransmitter.setUnit("kg/hr"); - flowTransmitter.setMaximumValue(100.0); - flowTransmitter.setMinimumValue(1.0); - - ControllerDeviceInterface flowController = new ControllerDeviceBaseClass(); - flowController.setTransmitter(flowTransmitter); - flowController.setReverseActing(true); - flowController.setControllerSetPoint(63.5); - flowController.setControllerParameters(0.1, 0.10, 0.0); - - p.add(stream_1); - p.add(valve_1); - p.add(separator_1); - p.add(valve_2); - p.add(valve_3); - p.add(flowTransmitter); - valve_1.setController(flowController); - - p.run(); - - // transient behaviour - p.setTimeStep(1.0); - for (int i = 0; i < 5; i++) { - // System.out.println("volume flow " + flowTransmitter.getMeasuredValue() - // + " valve opening " + valve_1.getPercentValveOpening() + " pressure " - // + separator_1.getGasOutStream().getPressure()); - p.runTransient(); - } - } + valve1.setPercentValveOpening(60); - //@Test - public void testDynamicCalculation2() { - - neqsim.thermo.system.SystemInterface testSystem = getTestSystem(); - - neqsim.thermo.system.SystemInterface testSystem2 = new neqsim.thermo.system.SystemSrkEos((273.15 + 25.0), - 10.00); - testSystem2.addComponent("methane", 1.1); - testSystem2.addComponent("ethane", 0.10001); - testSystem2.addComponent("n-heptane", 1.001); - testSystem2.setMixingRule(2); - - Stream purgeStream = new Stream("Purge Stream", testSystem2); - ThrottlingValve purgeValve = new ThrottlingValve("purgeValve", purgeStream); - purgeValve.setOutletPressure(7.0); - purgeValve.setPercentValveOpening(50.0); - - Stream stream_1 = new Stream("Stream1", testSystem); - ThrottlingValve valve_1 = new ThrottlingValve("valve_1", stream_1); - valve_1.setOutletPressure(7.0); - valve_1.setPercentValveOpening(50); - - Separator separator_1 = new Separator("separator_1"); - separator_1.addStream(valve_1.getOutStream()); - separator_1.addStream(purgeValve.getOutStream()); - - ThrottlingValve valve_2 = new ThrottlingValve("valve_2", separator_1.getLiquidOutStream()); - valve_2.setOutletPressure(5.0); - valve_2.setPercentValveOpening(50); - // valve_2.setCv(10.0); - - ThrottlingValve valve_3 = new ThrottlingValve("valve_3", separator_1.getGasOutStream()); - valve_3.setOutletPressure(5.0); - valve_3.setPercentValveOpening(50); - // valve_3.setCv(10.0); - - LevelTransmitter separatorLevelTransmitter = new LevelTransmitter(separator_1); - separatorLevelTransmitter.setName("separatorLevelTransmitter1"); - separatorLevelTransmitter.setUnit("meter"); - separatorLevelTransmitter.setMaximumValue(1.0); - separatorLevelTransmitter.setMinimumValue(0.0); - - ControllerDeviceInterface separatorLevelController = new ControllerDeviceBaseClass(); - separatorLevelController.setReverseActing(false); - separatorLevelController.setTransmitter(separatorLevelTransmitter); - separatorLevelController.setControllerSetPoint(0.3); - separatorLevelController.setControllerParameters(1.0, 300.0, 10.0); - - PressureTransmitter separatorPressureTransmitter = new PressureTransmitter(separator_1.getGasOutStream()); - separatorPressureTransmitter.setUnit("bar"); - separatorPressureTransmitter.setMaximumValue(10.0); - separatorPressureTransmitter.setMinimumValue(1.0); - - ControllerDeviceInterface separatorPressureController = new ControllerDeviceBaseClass(); - separatorPressureController.setTransmitter(separatorPressureTransmitter); - separatorPressureController.setReverseActing(false); - separatorPressureController.setControllerSetPoint(7.0); - separatorPressureController.setControllerParameters(1.0, 300.0, 10.0); - - p.add(stream_1); - p.add(valve_1); - - p.add(purgeStream); - p.add(purgeValve); - p.add(separator_1); - p.add(valve_2); - p.add(valve_3); - - // add transmitters - p.add(separatorLevelTransmitter); - valve_2.setController(separatorLevelController); - - p.add(separatorPressureTransmitter); - valve_3.setController(separatorPressureController); - - p.run(); - // p.displayResult(); - p.setTimeStep(0.0001); - p.runTransient(); + for (int i = 0; i < 10; i++) { + // System.out.println("pressure "+separator_1.getGasOutStream().getPressure()+ " flow "+ + // separator_1.getGasOutStream().getFlowRate("kg/hr")); + p.runTransient(); + for (SimulationInterface sim : p.getUnitOperations()) { + assertEquals(p.getCalculationIdentifier(), sim.getCalculationIdentifier()); + } } + } } diff --git a/src/test/java/neqsim/processSimulation/util/example/LNGfilling.java b/src/test/java/neqsim/processSimulation/util/example/LNGfilling.java index e48aaf4d7f..ac0c2b8c52 100644 --- a/src/test/java/neqsim/processSimulation/util/example/LNGfilling.java +++ b/src/test/java/neqsim/processSimulation/util/example/LNGfilling.java @@ -59,6 +59,6 @@ public static void main(String args[]) { System.out.println("Volume Methane " + stream_1.getThermoSystem().getVolume()); System.out.println("Volume Nitrogen " + stream_2.getThermoSystem().getVolume()); System.out.println( - "Mixer Cooled Nitrogen " + mixer.getOutStream().getThermoSystem().getVolume()); + "Mixer Cooled Nitrogen " + mixer.getOutletStream().getThermoSystem().getVolume()); } } diff --git a/src/test/java/neqsim/processSimulation/util/example/LNGtankfilling.java b/src/test/java/neqsim/processSimulation/util/example/LNGtankfilling.java index 488514d3db..135589a1df 100644 --- a/src/test/java/neqsim/processSimulation/util/example/LNGtankfilling.java +++ b/src/test/java/neqsim/processSimulation/util/example/LNGtankfilling.java @@ -63,7 +63,7 @@ public static void main(String args[]) { valve.setOutletPressure(1.01325 + 0.110); Tank tank = new neqsim.processSimulation.processEquipment.tank.Tank("tank"); - tank.addStream(valve.getOutStream()); + tank.addStream(valve.getOutletStream()); // tank.addStream(stream_2); ValveInterface valve2 = new ThrottlingValve("valve2", tank.getGasOutStream()); diff --git a/src/test/java/neqsim/processSimulation/util/example/MEGinjection.java b/src/test/java/neqsim/processSimulation/util/example/MEGinjection.java index aa5f8e3d86..c5a9bc5020 100644 --- a/src/test/java/neqsim/processSimulation/util/example/MEGinjection.java +++ b/src/test/java/neqsim/processSimulation/util/example/MEGinjection.java @@ -68,11 +68,11 @@ public static void main(String[] args) { feedGasMEGmixer.addStream(feedGasStream); feedGasMEGmixer.addStream(MEGFeed); - Heater pipeline = new Heater("gas-MEG pipeline", feedGasMEGmixer.getOutStream()); + Heater pipeline = new Heater("gas-MEG pipeline", feedGasMEGmixer.getOutletStream()); pipeline.setOutTemperature(273.15 + 35.5); pipeline.setOutPressure(80.2); - Stream mixerStream = (Stream) pipeline.getOutStream(); + Stream mixerStream = (Stream) pipeline.getOutletStream(); mixerStream.setName("feed gas and MEG"); Adjuster adjuster = new Adjuster("MEG adjuster"); @@ -100,7 +100,7 @@ public static void main(String[] args) { onshoreChockeValve.setOutletPressure(70.3); ThreePhaseSeparator slugCatcher = - new ThreePhaseSeparator("slug catcher", onshoreChockeValve.getOutStream()); + new ThreePhaseSeparator("slug catcher", onshoreChockeValve.getOutletStream()); neqsim.thermo.system.SystemInterface feedMEGOnshore = feedGas.clone(); feedMEG.setMolarComposition(new double[] {0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, @@ -119,7 +119,7 @@ public static void main(String[] args) { MEGmixer1.addStream(slugCatcher.getGasOutStream()); MEGmixer1.addStream(MEGsplitter.getSplitStream(0)); - ThrottlingValve DPvalve1 = new ThrottlingValve("DP valve 1", MEGmixer1.getOutStream()); + ThrottlingValve DPvalve1 = new ThrottlingValve("DP valve 1", MEGmixer1.getOutletStream()); DPvalve1.setOutletPressure(70.0); neqsim.processSimulation.processSystem.ProcessSystem onshoreOperations = diff --git a/src/test/java/neqsim/processSimulation/util/example/MasstransferMeOH.java b/src/test/java/neqsim/processSimulation/util/example/MasstransferMeOH.java index 5333aa1c8b..aca24ac7ba 100644 --- a/src/test/java/neqsim/processSimulation/util/example/MasstransferMeOH.java +++ b/src/test/java/neqsim/processSimulation/util/example/MasstransferMeOH.java @@ -45,7 +45,7 @@ public static void main(String[] args) { new StreamSaturatorUtil("water saturator", dryFeedGas); Stream waterSaturatedFeedGas = - new Stream("water saturated feed gas", saturatedFeedGas.getOutStream()); + new Stream("water saturated feed gas", saturatedFeedGas.getOutletStream()); neqsim.thermo.system.SystemInterface feedMeOH = feedGas.clone(); feedMeOH.setMolarComposition(new double[] {0.0, 0.0, 1.0}); @@ -61,7 +61,7 @@ public static void main(String[] args) { neqsim.processSimulation.processEquipment.util.NeqSimUnit pipeline = new neqsim.processSimulation.processEquipment.util.NeqSimUnit( - mainMixer.getOutStream(), "pipeline", "stratified"); + mainMixer.getOutletStream(), "pipeline", "stratified"); pipeline.setLength(123.01); GasScrubber scrubber = new GasScrubber("gas scrub", pipeline.getOutStream()); diff --git a/src/test/java/neqsim/processSimulation/util/example/OffshoreProcess.java b/src/test/java/neqsim/processSimulation/util/example/OffshoreProcess.java index 0b50bee2b6..29b99feb21 100644 --- a/src/test/java/neqsim/processSimulation/util/example/OffshoreProcess.java +++ b/src/test/java/neqsim/processSimulation/util/example/OffshoreProcess.java @@ -78,20 +78,20 @@ public static void main(String args[]) { Compressor compressor1 = new Compressor("compressor1", stream_2); compressor1.setOutletPressure(131.3); - StreamInterface stream_4 = compressor1.getOutStream(); + StreamInterface stream_4 = compressor1.getOutletStream(); stream_4.setName("gas compressor out stream"); Compressor compressor2 = new Compressor("compressor2", stream_3); compressor2.setOutletPressure(131.3); - StreamInterface stream_5 = compressor2.getOutStream(); + StreamInterface stream_5 = compressor2.getOutletStream(); stream_5.setName("liquid compressor out stream"); Mixer mixer = new StaticPhaseMixer("Mixer 1"); mixer.addStream(stream_4); mixer.addStream(stream_5); - NeqStream stream_6 = new NeqStream("after mixer stream", mixer.getOutStream()); + NeqStream stream_6 = new NeqStream("after mixer stream", mixer.getOutletStream()); Pipeline pipe = new TwoPhasePipeLine("pipe", stream_6); pipe.setOutputFileName("c:/tempAsgard.nc"); diff --git a/src/test/java/neqsim/processSimulation/util/example/OffshoreProcess3.java b/src/test/java/neqsim/processSimulation/util/example/OffshoreProcess3.java index 6b31dbee99..8eb232ef03 100644 --- a/src/test/java/neqsim/processSimulation/util/example/OffshoreProcess3.java +++ b/src/test/java/neqsim/processSimulation/util/example/OffshoreProcess3.java @@ -63,13 +63,13 @@ public static void main(String[] args) { inletTempControl.setOutPressure(55.21, "bara"); ThrottlingValve valve = - new ThrottlingValve("inlet choke valve", inletTempControl.getOutStream()); + new ThrottlingValve("inlet choke valve", inletTempControl.getOutletStream()); valve.setOutletPressure(35.21); Stream oilToInletSep = new Stream("oilToInletSep", fluid3.clone()); oilToInletSep.setFlowRate(1e-10, "kg/hr"); ThreePhaseSeparator inletSeparator = - new ThreePhaseSeparator("1st stage separator", valve.getOutStream()); + new ThreePhaseSeparator("1st stage separator", valve.getOutletStream()); inletSeparator.setEntrainment(0.005, "mass", "product", "aqueous", "oil"); inletSeparator.setEntrainment(500e-6, "mole", "product", "oil", "aqueous"); inletSeparator.addStream(oilToInletSep); @@ -78,7 +78,8 @@ public static void main(String[] args) { new Heater("oil cooler/heater to 2nd stage", inletSeparator.getOilOutStream()); heater1.setOutTemperature(85.0, "C"); - ThrottlingValve valve2 = new ThrottlingValve("oil HP to MP valve", heater1.getOutStream()); + ThrottlingValve valve2 = + new ThrottlingValve("oil HP to MP valve", heater1.getOutletStream()); valve2.setOutletPressure(7.0); ThrottlingValve waterDPvalve = @@ -86,7 +87,7 @@ public static void main(String[] args) { waterDPvalve.setOutletPressure(1.01325); Separator waterStabSep = - new Separator("water degasing separator", waterDPvalve.getOutStream()); + new Separator("water degasing separator", waterDPvalve.getOutletStream()); Stream waterToTreatment = new Stream("water to treatment", waterStabSep.getLiquidOutStream()); @@ -98,7 +99,7 @@ public static void main(String[] args) { oilToSep.setFlowRate(1e-10, "kg/hr"); ThreePhaseSeparator mpseparator = - new ThreePhaseSeparator("2nd stage separator", valve2.getOutStream()); + new ThreePhaseSeparator("2nd stage separator", valve2.getOutletStream()); mpseparator.addStream(oilToSep); ThrottlingValve valvempValve = @@ -106,7 +107,7 @@ public static void main(String[] args) { valvempValve.setOutletPressure(2.1); ThreePhaseSeparator lpseparator = - new ThreePhaseSeparator("3rd stage separator", valvempValve.getOutStream()); + new ThreePhaseSeparator("3rd stage separator", valvempValve.getOutletStream()); Stream stableOilStream = (Stream) lpseparator.getOilOutStream(); stableOilStream.setName("stable oil"); @@ -114,9 +115,9 @@ public static void main(String[] args) { new Compressor("1st stage recompressor", lpseparator.getGasOutStream()); // lpcompressor.setOutletPressure(15.0); SetPoint compressorPresSet2 = - new SetPoint("comp pres LP set", lpcompressor, "pressure", valve2.getOutStream()); + new SetPoint("comp pres LP set", lpcompressor, "pressure", valve2.getOutletStream()); - Cooler lpgasheater = new Cooler("1st stage gas cooler", lpcompressor.getOutStream()); + Cooler lpgasheater = new Cooler("1st stage gas cooler", lpcompressor.getOutletStream()); lpgasheater.setOutTemperature(35.0, "C"); neqsim.thermo.system.SystemInterface coolingWaterSYstm = fluid3.clone(); @@ -137,10 +138,10 @@ public static void main(String[] args) { */ Cooler lpHeatExchanger = - new Cooler("1st stage gas heat exchanger", lpcompressor.getOutStream()); + new Cooler("1st stage gas heat exchanger", lpcompressor.getOutletStream()); lpgasheater.setOutTemperature(35.0, "C"); - Separator lpscrubber = new Separator("2nd stage scrubber", lpgasheater.getOutStream()); + Separator lpscrubber = new Separator("2nd stage scrubber", lpgasheater.getOutletStream()); Stream liqFromlpscrubber = (Stream) lpscrubber.getLiquidOutStream(); Recycle lpscrubberResyc = new Recycle("mpscrubberRes"); @@ -152,7 +153,7 @@ public static void main(String[] args) { mixermp.addStream(mpseparator.getGasOutStream()); Compressor compressor2stage = - new Compressor("2nd stage recompressor", mixermp.getOutStream()); + new Compressor("2nd stage recompressor", mixermp.getOutletStream()); compressor2stage.setIsentropicEfficiency(0.75); // compressor2stage.setOutletPressure(75.0); @@ -160,22 +161,22 @@ public static void main(String[] args) { new SetPoint("comp pres set", compressor2stage, "pressure", inletSeparator); Heater secondndstagecooler = - new Heater("2nd stage cooler", compressor2stage.getOutStream()); + new Heater("2nd stage cooler", compressor2stage.getOutletStream()); secondndstagecooler.setOutTemperature(290.0); Separator scrubbberfrom2ndstage = - new Separator("scrubber of mix gas HP", secondndstagecooler.getOutStream()); + new Separator("scrubber of mix gas HP", secondndstagecooler.getOutletStream()); Mixer mixer = new Mixer("HP rich gas mixer"); mixer.addStream(inletSeparator.getGasOutStream()); mixer.addStream(scrubbberfrom2ndstage.getGasOutStream()); Heater dewPointScrubberCooler = - new Heater("dew point scrubber cooler2", mixer.getOutStream()); + new Heater("dew point scrubber cooler2", mixer.getOutletStream()); dewPointScrubberCooler.setOutTemperature(273.15 + 32.3); Separator mpscrubber = - new Separator("dew point control scrubber", dewPointScrubberCooler.getOutStream()); + new Separator("dew point control scrubber", dewPointScrubberCooler.getOutletStream()); Stream liqFrommpscrubber = (Stream) mpscrubber.getLiquidOutStream(); @@ -188,24 +189,27 @@ public static void main(String[] args) { new MoleFractionControllerUtil(mpscrubber.getGasOutStream()); waterRemoval.setMoleFraction("water", 10.0e-6); - Stream richGas = new Stream("rich gas",waterRemoval.getOutStream()); + Stream richGas = new Stream("rich gas", waterRemoval.getOutletStream()); Compressor exportGasCompressor = new Compressor("1st stage export compressor",richGas); exportGasCompressor.setIsentropicEfficiency(0.75); exportGasCompressor.setOutletPressure(richGas.getPressure() * 2.5); - Cooler exportGasCompressorCooler = new Cooler("1st stage export gas cooler",exportGasCompressor.getOutStream()); + Cooler exportGasCompressorCooler = + new Cooler("1st stage export gas cooler", exportGasCompressor.getOutletStream()); exportGasCompressorCooler.setOutTemperature(35.0, "C"); - Compressor exportGasCompressor2 = new Compressor("2nd stage export compressor",exportGasCompressorCooler.getOutStream()); + Compressor exportGasCompressor2 = new Compressor("2nd stage export compressor", + exportGasCompressorCooler.getOutletStream()); exportGasCompressor2.setIsentropicEfficiency(0.75); exportGasCompressor2.setOutletPressure( - exportGasCompressorCooler.getOutStream().getPressure() * 2.5 * 2.5); + exportGasCompressorCooler.getOutletStream().getPressure() * 2.5 * 2.5); - Cooler exportGasCompressorCooler2 = new Cooler("2nd stage export gas cooler",exportGasCompressor2.getOutStream()); + Cooler exportGasCompressorCooler2 = + new Cooler("2nd stage export gas cooler", exportGasCompressor2.getOutletStream()); exportGasCompressorCooler2.setOutTemperature(35.0, "C"); - Stream exportGas = new Stream("export gas",exportGasCompressorCooler2.getOutStream()); + Stream exportGas = new Stream("export gas", exportGasCompressorCooler2.getOutletStream()); neqsim.processSimulation.processSystem.ProcessSystem operations = new neqsim.processSimulation.processSystem.ProcessSystem(); diff --git a/src/test/java/neqsim/processSimulation/util/example/OnshoreMEGprocess.java b/src/test/java/neqsim/processSimulation/util/example/OnshoreMEGprocess.java index ab8d2cd87e..89b4c0b187 100644 --- a/src/test/java/neqsim/processSimulation/util/example/OnshoreMEGprocess.java +++ b/src/test/java/neqsim/processSimulation/util/example/OnshoreMEGprocess.java @@ -60,18 +60,18 @@ public static void main(String[] args) { new StreamSaturatorUtil("water saturator", dryFeedGas); Stream waterSaturatedFeedGas = - new Stream("water saturated feed gas", saturatedFeedGas.getOutStream()); + new Stream("water saturated feed gas", saturatedFeedGas.getOutletStream()); Compressor inletCompressor = new Compressor("Compressor 1 - first stage", waterSaturatedFeedGas); inletCompressor.setOutletPressure(70.0, "bara"); Cooler interstageGasCooler = - new Cooler("Compressor 1 - interstage cooler", inletCompressor.getOutStream()); + new Cooler("Compressor 1 - interstage cooler", inletCompressor.getOutletStream()); interstageGasCooler.setOutTemperature(40.0, "C"); Compressor inletCompressor2ndstage = - new Compressor("Compressor 1 - second stage", interstageGasCooler.getOutStream()); + new Compressor("Compressor 1 - second stage", interstageGasCooler.getOutletStream()); inletCompressor2ndstage.setOutletPressure(105.0, "bara"); neqsim.thermo.system.SystemInterface feedMEG = feedGas.clone(); @@ -86,18 +86,18 @@ public static void main(String[] args) { MEGsplitter1.setSplitFactors(new double[] {0.01, 0.94, 0.05}); StaticMixer MEGmixer1 = new StaticMixer("MEG mixer 1"); - MEGmixer1.addStream(inletCompressor2ndstage.getOutStream()); + MEGmixer1.addStream(inletCompressor2ndstage.getOutletStream()); MEGmixer1.addStream(MEGsplitter1.getSplitStream(0)); - Cooler inletGasCooler = new Cooler("dehydration cooler", MEGmixer1.getOutStream()); + Cooler inletGasCooler = new Cooler("dehydration cooler", MEGmixer1.getOutletStream()); inletGasCooler.setOutTemperature(10.0, "C"); StaticMixer MEGmixer2 = new StaticMixer("MEG mixer 2"); - MEGmixer2.addStream(inletGasCooler.getOutStream()); + MEGmixer2.addStream(inletGasCooler.getOutletStream()); MEGmixer2.addStream(MEGsplitter1.getSplitStream(1)); HeatExchanger heatEx = - new HeatExchanger("gas-gas heat exchanger", MEGmixer2.getOutStream()); + new HeatExchanger("gas-gas heat exchanger", MEGmixer2.getOutletStream()); heatEx.setGuessOutTemperature(273.15 - 10.0); heatEx.setUAvalue(30000.0); @@ -105,11 +105,12 @@ public static void main(String[] args) { MEGmixer3.addStream(heatEx.getOutStream(0)); MEGmixer3.addStream(MEGsplitter1.getSplitStream(2)); - ThrottlingValve presRedValveLT = new ThrottlingValve("JT valve", MEGmixer3.getOutStream()); + ThrottlingValve presRedValveLT = + new ThrottlingValve("JT valve", MEGmixer3.getOutletStream()); presRedValveLT.setOutletPressure(92.0); ThreePhaseSeparator mpseparator = - new ThreePhaseSeparator("low temperature scrubber", presRedValveLT.getOutStream()); + new ThreePhaseSeparator("low temperature scrubber", presRedValveLT.getOutletStream()); Stream coldGasFromSep = new Stream("gas from cold scrubber", mpseparator.getGasOutStream()); @@ -124,14 +125,15 @@ public static void main(String[] args) { richMEGstreamHeater.setOutTemperature(15.0, "C"); Heater richMEGstreamHeater2 = - new Heater("column condenser HX", richMEGstreamHeater.getOutStream()); + new Heater("column condenser HX", richMEGstreamHeater.getOutletStream()); // richMEGstreamHeater2.setOutTemperature(22.0, "C"); ThrottlingValve presRedValve3 = - new ThrottlingValve("valve to flash drum", richMEGstreamHeater2.getOutStream()); + new ThrottlingValve("valve to flash drum", richMEGstreamHeater2.getOutletStream()); presRedValve3.setOutletPressure(3.9); - Separator flashDrumSep = new Separator("rich MEG flash drum", presRedValve3.getOutStream()); + Separator flashDrumSep = + new Separator("rich MEG flash drum", presRedValve3.getOutletStream()); Stream flashGasStream = new Stream("gas from flash drum", flashDrumSep.getGasOutStream()); @@ -149,7 +151,7 @@ public static void main(String[] args) { DistillationColumn column = new DistillationColumn(2, true, true); column.setName("MEG regeneration column"); - column.addFeedStream(presRedValve4.getOutStream(), 0); + column.addFeedStream(presRedValve4.getOutletStream(), 0); column.getReboiler().setOutTemperature(273.15 + 135.0); column.getCondenser().setOutTemperature(273.15 + 105.0); column.setTopPressure(1.0); @@ -160,7 +162,7 @@ public static void main(String[] args) { coolerRegenGas.setOutTemperature(273.15 + 20.0); Separator sepregenGas = - new Separator("overhead condenser scrubber", coolerRegenGas.getOutStream()); + new Separator("overhead condenser scrubber", coolerRegenGas.getOutletStream()); Stream gasToFlare = new Stream("gas to flare from regenerator", sepregenGas.getGasOutStream()); @@ -171,12 +173,12 @@ public static void main(String[] args) { Cooler bufferTank = new Cooler("MEG buffer tank", column.getLiquidOutStream()); bufferTank.setOutTemperature(273.15 + 130.0); - Pump hotLeanMEGPump = new Pump("hot lean MEG pump", bufferTank.getOutStream()); + Pump hotLeanMEGPump = new Pump("hot lean MEG pump", bufferTank.getOutletStream()); hotLeanMEGPump.setOutletPressure(105.0); hotLeanMEGPump.setIsentropicEfficiency(0.75); Stream streamHotPump = - new Stream("stream from hot lean MEG pump", hotLeanMEGPump.getOutStream()); + new Stream("stream from hot lean MEG pump", hotLeanMEGPump.getOutletStream()); columnPreHeater.setFeedStream(1, streamHotPump); @@ -184,7 +186,7 @@ public static void main(String[] args) { coolerHotMEG2.setOutTemperature(273.15 + 20.0); Stream leanMEGtoMixer = - new Stream("lean MEG to makeup mixer", coolerHotMEG2.getOutStream()); + new Stream("lean MEG to makeup mixer", coolerHotMEG2.getOutletStream()); neqsim.thermo.system.SystemInterface pureMEG = feedGas.clone(); pureMEG.setMolarComposition(new double[] {0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0}); @@ -205,7 +207,7 @@ public static void main(String[] args) { makeupMixer.addStream(leanMEGtoMixer); makeupMixer.addStream(makeupMEG); - Stream streamToResycle = new Stream("streamToResycle", makeupMixer.getOutStream()); + Stream streamToResycle = new Stream("streamToResycle", makeupMixer.getOutletStream()); Recycle resycleLeanMEG = new Recycle("lean MEG resycle"); resycleLeanMEG.addStream(streamToResycle); @@ -273,7 +275,7 @@ public static void main(String[] args) { System.out.println("MEG flow rate " + richMEGstream.getFluid().getFlowRate("kg/hr")); System.out.println("MEG feed to column rate " - + presRedValve4.getOutStream().getFluid().getFlowRate("kg/hr")); + + presRedValve4.getOutletStream().getFluid().getFlowRate("kg/hr")); System.out.println("MEG flow rate " + resycleLeanMEG.getFluid().getFlowRate("kg/hr")); System.out.println( @@ -297,9 +299,9 @@ public static void main(String[] args) { + column.getLiquidOutStream().getFluid().getPhase("aqueous").getWtFrac("MEG") * 100.0); System.out.println("hydrate temperature 1 " - + (inletGasCooler.getOutStream().getHydrateEquilibriumTemperature() - 273.15) + + (inletGasCooler.getOutletStream().getHydrateEquilibriumTemperature() - 273.15) + " wt% MEG " - + inletGasCooler.getOutStream().getFluid().getPhase("aqueous").getWtFrac("MEG") + + inletGasCooler.getOutletStream().getFluid().getPhase("aqueous").getWtFrac("MEG") * 100.0); operations.save("c:/temp/MEGdehydrationProcess.neqsim"); diff --git a/src/test/java/neqsim/processSimulation/util/example/OnshoreProcess1.java b/src/test/java/neqsim/processSimulation/util/example/OnshoreProcess1.java index 171ff55fa4..7499f24fa8 100644 --- a/src/test/java/neqsim/processSimulation/util/example/OnshoreProcess1.java +++ b/src/test/java/neqsim/processSimulation/util/example/OnshoreProcess1.java @@ -251,7 +251,8 @@ public static void main(String args[]) { MEGmixer1.addStream(MEGstream_1); MEGmixer1.addStream(snohvitFormationWaterStream); - ThrottlingValve valve1 = new ThrottlingValve("snohvit valve", MEGmixer1.getOutStream()); + ThrottlingValve valve1 = + new ThrottlingValve("snohvit valve", MEGmixer1.getOutletStream()); valve1.setOutletPressure(125.0); // Albatross reservoir stream @@ -272,15 +273,16 @@ public static void main(String args[]) { // Field mixer Mixer mixer1 = new Mixer("Field Mixer"); - mixer1.addStream(valve1.getOutStream()); - mixer1.addStream(valve2.getOutStream()); + mixer1.addStream(valve1.getOutletStream()); + mixer1.addStream(valve2.getOutletStream()); - WaterContentAnalyser waterAnalyser3 = new WaterContentAnalyser(mixer1.getOutStream()); + WaterContentAnalyser waterAnalyser3 = + new WaterContentAnalyser(mixer1.getOutletStream()); waterAnalyser3.setName("Total Water Analyser"); // Pipeline SimpleTPoutPipeline pipeLine1 = - new SimpleTPoutPipeline("snohvit pipeline", mixer1.getOutStream()); + new SimpleTPoutPipeline("snohvit pipeline", mixer1.getOutletStream()); pipeLine1.setOutPressure(55.0); pipeLine1.setOutTemperature(273.15 + 5.0); pipeLine1.setNumberOfLegs(1); @@ -293,7 +295,7 @@ public static void main(String args[]) { // // Land plant ThreePhaseSeparator slugCatcher = - new ThreePhaseSeparator("slugCatcher", pipeLine1.getOutStream()); + new ThreePhaseSeparator("slugCatcher", pipeLine1.getOutletStream()); VolumeFlowTransmitter volumeTransmitter2 = new VolumeFlowTransmitter(slugCatcher.getOilOutStream()); @@ -323,7 +325,7 @@ public static void main(String args[]) { ThreePhaseSeparator condensateSeparator = new ThreePhaseSeparator("condensateSeparator", - condensateheater1.getOutStream()); + condensateheater1.getOutletStream()); // Heater MEGheater1 = new Heater(stream_5); // MEGheater1.setName("MEG heater1"); diff --git a/src/test/java/neqsim/processSimulation/util/example/TEGAbsorberTest.java b/src/test/java/neqsim/processSimulation/util/example/TEGAbsorberTest.java index e1d28d4d9f..3646a97a4f 100644 --- a/src/test/java/neqsim/processSimulation/util/example/TEGAbsorberTest.java +++ b/src/test/java/neqsim/processSimulation/util/example/TEGAbsorberTest.java @@ -61,7 +61,7 @@ public static void main(String args[]) { ThrottlingValve TEG_HPLP_valve = new ThrottlingValve("ventil", TEGStreamOut); TEG_HPLP_valve.setOutletPressure(10.0); - Separator MPseparator = new Separator("Separator_MP", TEG_HPLP_valve.getOutStream()); + Separator MPseparator = new Separator("Separator_MP", TEG_HPLP_valve.getOutletStream()); StreamInterface MPstreamGas = MPseparator.getGasOutStream(); MPstreamGas.setName("MPGasStream"); @@ -72,7 +72,7 @@ public static void main(String args[]) { ThrottlingValve LP_valve = new ThrottlingValve("LPventil", MPstreamLiq); LP_valve.setOutletPressure(1.5); - ReBoiler reboiler = new ReBoiler("reboiler", LP_valve.getOutStream()); + ReBoiler reboiler = new ReBoiler("reboiler", LP_valve.getOutletStream()); reboiler.setReboilerDuty(20000.0); neqsim.thermo.system.SystemSrkEos testSystem3 = @@ -86,10 +86,10 @@ public static void main(String args[]) { Stream mixStream = new Stream("mixStream", testSystem3); Mixer mix = new Mixer("mixer"); - mix.addStream(reboiler.getOutStream()); + mix.addStream(reboiler.getOutletStream()); mix.addStream(mixStream); - StreamInterface ReboilLiqStream = mix.getOutStream(); + StreamInterface ReboilLiqStream = mix.getOutletStream(); ReboilLiqStream.setName("ReboilLiqStream"); // Stream ReboilGasStream = reboiler.getOutStream(); diff --git a/src/test/java/neqsim/processSimulation/util/example/TEGdehydrationProcess2.java b/src/test/java/neqsim/processSimulation/util/example/TEGdehydrationProcess2.java index 25349a2bf2..0cec3f2957 100644 --- a/src/test/java/neqsim/processSimulation/util/example/TEGdehydrationProcess2.java +++ b/src/test/java/neqsim/processSimulation/util/example/TEGdehydrationProcess2.java @@ -58,7 +58,7 @@ public static void main(String[] args) { StreamSaturatorUtil saturatedFeedGas = new StreamSaturatorUtil("water saturator", dryFeedGas); Stream waterSaturatedFeedGas = - new Stream("waterSaturatedFeedGas", saturatedFeedGas.getOutStream()); + new Stream("waterSaturatedFeedGas", saturatedFeedGas.getOutletStream()); neqsim.thermo.system.SystemInterface feedTEG = feedGas.clone(); feedTEG.setMolarComposition( new double[] {0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.02, 0.98}); @@ -82,14 +82,15 @@ public static void main(String[] args) { glycol_flash_valve.setOutletPressure(4.9); Heater richGLycolHeaterCondenser = - new Heater("rich TEG preheater", glycol_flash_valve.getOutStream()); + new Heater("rich TEG preheater", glycol_flash_valve.getOutletStream()); richGLycolHeaterCondenser.setOutTemperature(273.15 + 35.5); Heater richGLycolHeater = - new Heater("rich TEG heater HP", richGLycolHeaterCondenser.getOutStream()); + new Heater("rich TEG heater HP", richGLycolHeaterCondenser.getOutletStream()); richGLycolHeater.setOutTemperature(273.15 + 62.0); - Separator flashSep = new Separator("degasing separator", richGLycolHeater.getOutStream()); + Separator flashSep = + new Separator("degasing separator", richGLycolHeater.getOutletStream()); Stream flashGas = new Stream("gas from degasing separator", flashSep.getGasOutStream()); Stream flashLiquid = new Stream("liquid from degasing separator", flashSep.getLiquidOutStream()); @@ -99,12 +100,12 @@ public static void main(String[] args) { richGLycolHeater2.setOutPressure(1.23); Mixer mixerTOreboiler = new Mixer("reboil mxer"); - mixerTOreboiler.addStream(richGLycolHeater2.getOutStream()); + mixerTOreboiler.addStream(richGLycolHeater2.getOutletStream()); - Heater heaterToReboiler = new Heater("heaterToReboiler", mixerTOreboiler.getOutStream()); + Heater heaterToReboiler = new Heater("heaterToReboiler", mixerTOreboiler.getOutletStream()); heaterToReboiler.setOutTemperature(273.15 + 206.6); - Separator regenerator2 = new Separator("regenerator2", heaterToReboiler.getOutStream()); + Separator regenerator2 = new Separator("regenerator2", heaterToReboiler.getOutletStream()); Stream gasFromRegenerator = new Stream("gasFromRegenerator", regenerator2.getGasOutStream()); @@ -114,7 +115,7 @@ public static void main(String[] args) { sepregenGasCooler.setOutPressure(1.23); // sepregenGasCooler.setEnergyStream(richGLycolHeaterCondenser.getEnergyStream()); - Separator sepRegen = new Separator("sepRegen", sepregenGasCooler.getOutStream()); + Separator sepRegen = new Separator("sepRegen", sepregenGasCooler.getOutletStream()); Stream liquidRegenReflux = new Stream("liquidRegenReflux", sepRegen.getLiquidOutStream()); @@ -124,7 +125,7 @@ public static void main(String[] args) { Heater coolerRegenGas = new Heater("coolerRegenGas", sepRegen.getGasOutStream()); coolerRegenGas.setOutTemperature(273.15 + 35.5); - Separator sepregenGas = new Separator("sepregenGas", coolerRegenGas.getOutStream()); + Separator sepregenGas = new Separator("sepregenGas", coolerRegenGas.getOutletStream()); Stream gasToFlare = new Stream("gasToFlare", sepregenGas.getGasOutStream()); @@ -154,20 +155,20 @@ public static void main(String[] args) { Pump hotLeanTEGPump = new Pump("hot lean TEG pump", stripper.getSolventOutStream()); hotLeanTEGPump.setOutletPressure(20.0); - Heater coolerhOTteg = new Heater("hot lean TEG cooler", hotLeanTEGPump.getOutStream()); + Heater coolerhOTteg = new Heater("hot lean TEG cooler", hotLeanTEGPump.getOutletStream()); coolerhOTteg.setOutTemperature(273.15 + 116.8); Heater coolerhOTteg2 = - new Heater("medium hot lean TEG cooler", coolerhOTteg.getOutStream()); + new Heater("medium hot lean TEG cooler", coolerhOTteg.getOutletStream()); coolerhOTteg2.setOutTemperature(273.15 + 89.3); - Heater coolerhOTteg3 = new Heater("lean TEG cooler", coolerhOTteg2.getOutStream()); + Heater coolerhOTteg3 = new Heater("lean TEG cooler", coolerhOTteg2.getOutletStream()); coolerhOTteg3.setOutTemperature(273.15 + 44.85); - Pump hotLeanTEGPump2 = new Pump("lean TEG HP pump", coolerhOTteg3.getOutStream()); + Pump hotLeanTEGPump2 = new Pump("lean TEG HP pump", coolerhOTteg3.getOutletStream()); hotLeanTEGPump2.setOutletPressure(52.21); - Stream leanTEGtoabs = new Stream("lean TEG to absorber", hotLeanTEGPump2.getOutStream()); + Stream leanTEGtoabs = new Stream("lean TEG to absorber", hotLeanTEGPump2.getOutletStream()); neqsim.thermo.system.SystemInterface pureTEG = feedGas.clone(); pureTEG.setMolarComposition( @@ -190,7 +191,7 @@ public static void main(String[] args) { makeupMixer.addStream(makeupTEG); Recycle resycleLeanTEG = new Recycle("lean TEG resycle"); - resycleLeanTEG.addStream(makeupMixer.getOutStream()); + resycleLeanTEG.addStream(makeupMixer.getOutletStream()); neqsim.processSimulation.processSystem.ProcessSystem operations = new neqsim.processSimulation.processSystem.ProcessSystem(); @@ -238,7 +239,7 @@ public static void main(String[] args) { operations.add(resycleLeanTEG); operations.run(); - richGLycolHeater2.getOutStream().getFluid().display(); + richGLycolHeater2.getOutletStream().getFluid().display(); System.out.println("Energy reboiler " + heaterToReboiler.getDuty()); mixerTOreboiler.addStream(liquidRegenReflux); mixerTOreboiler.addStream(resycle3.getOutStream()); diff --git a/src/test/java/neqsim/processSimulation/util/example/TEGdehydrationProcessDistillation.java b/src/test/java/neqsim/processSimulation/util/example/TEGdehydrationProcessDistillation.java index fa1cbb6599..2eefd621ca 100644 --- a/src/test/java/neqsim/processSimulation/util/example/TEGdehydrationProcessDistillation.java +++ b/src/test/java/neqsim/processSimulation/util/example/TEGdehydrationProcessDistillation.java @@ -64,7 +64,7 @@ public static void main(String[] args) { new StreamSaturatorUtil("water saturator", dryFeedGas); Stream waterSaturatedFeedGas = - new Stream("water saturated feed gas", saturatedFeedGas.getOutStream()); + new Stream("water saturated feed gas", saturatedFeedGas.getOutletStream()); neqsim.thermo.system.SystemInterface feedTEG = feedGas.clone(); feedTEG.setMolarComposition( @@ -89,10 +89,10 @@ public static void main(String[] args) { glycol_flash_valve.setOutletPressure(4.9); Heater richGLycolHeaterCondenser = - new Heater("rich TEG preheater", glycol_flash_valve.getOutStream()); + new Heater("rich TEG preheater", glycol_flash_valve.getOutletStream()); HeatExchanger heatEx2 = new HeatExchanger("rich TEG heat exchanger 1", - richGLycolHeaterCondenser.getOutStream()); + richGLycolHeaterCondenser.getOutletStream()); heatEx2.setGuessOutTemperature(273.15 + 62.0); heatEx2.setUAvalue(220.0); @@ -126,7 +126,7 @@ public static void main(String[] args) { DistillationColumn column = new DistillationColumn(1, true, true); column.setName("TEG regeneration column"); - column.addFeedStream(glycol_flash_valve2.getOutStream(), 0); + column.addFeedStream(glycol_flash_valve2.getOutletStream(), 0); column.getReboiler().setOutTemperature(273.15 + 206.6); column.getCondenser().setOutTemperature(273.15 + 100.0); column.getReboiler().addStream(gasToReboiler); @@ -136,7 +136,8 @@ public static void main(String[] args) { Heater coolerRegenGas = new Heater("regen gas cooler", column.getGasOutStream()); coolerRegenGas.setOutTemperature(273.15 + 35.5); - Separator sepregenGas = new Separator("regen gas separator", coolerRegenGas.getOutStream()); + Separator sepregenGas = + new Separator("regen gas separator", coolerRegenGas.getOutletStream()); Stream gasToFlare = new Stream("gas to flare", sepregenGas.getGasOutStream()); @@ -156,22 +157,22 @@ public static void main(String[] args) { Heater bufferTank = new Heater("TEG buffer tank", stripper.getSolventOutStream()); bufferTank.setOutTemperature(273.15 + 185.0); - Pump hotLeanTEGPump = new Pump("hot lean TEG pump",bufferTank.getOutStream());// stripper.getSolventOutStream()); + Pump hotLeanTEGPump = new Pump("hot lean TEG pump", bufferTank.getOutletStream());// stripper.getSolventOutStream()); hotLeanTEGPump.setOutletPressure(20.0); hotLeanTEGPump.setIsentropicEfficiency(0.75); - heatEx.setFeedStream(1, hotLeanTEGPump.getOutStream()); + heatEx.setFeedStream(1, hotLeanTEGPump.getOutletStream()); heatEx2.setFeedStream(1, heatEx.getOutStream(1)); Heater coolerhOTteg3 = new Heater("lean TEG cooler",heatEx2.getOutStream(1)); coolerhOTteg3.setOutTemperature(273.15 + 43.0); - Pump hotLeanTEGPump2 = new Pump("lean TEG HP pump",coolerhOTteg3.getOutStream()); + Pump hotLeanTEGPump2 = new Pump("lean TEG HP pump", coolerhOTteg3.getOutletStream()); hotLeanTEGPump2.setOutletPressure(52.21); hotLeanTEGPump2.setIsentropicEfficiency(0.75); - Stream leanTEGtoabs = new Stream("lean TEG to absorber",hotLeanTEGPump2.getOutStream()); + Stream leanTEGtoabs = new Stream("lean TEG to absorber", hotLeanTEGPump2.getOutletStream()); neqsim.thermo.system.SystemInterface pureTEG = feedGas.clone(); pureTEG.setMolarComposition( @@ -194,7 +195,7 @@ public static void main(String[] args) { makeupMixer.addStream(makeupTEG); Recycle resycleLeanTEG = new Recycle("lean TEG resycle"); - resycleLeanTEG.addStream(makeupMixer.getOutStream()); + resycleLeanTEG.addStream(makeupMixer.getOutletStream()); resycleLeanTEG.setOutletStream(TEGFeed); resycleLeanTEG.setPriority(200); resycleLeanTEG.setDownstreamProperty("flow rate"); @@ -279,7 +280,7 @@ public static void main(String[] args) { System.out.println("flow rate from stripping column " + stripper.getLiquidOutStream().getFlowRate("kg/hr")); System.out.println("flow rate from pump2 " - + hotLeanTEGPump2.getOutStream().getFluid().getFlowRate("kg/hr")); + + hotLeanTEGPump2.getOutletStream().getFluid().getFlowRate("kg/hr")); System.out.println("makeup TEG " + makeupTEG.getFluid().getFlowRate("kg/hr")); TEGFeed.getFluid().display(); @@ -290,12 +291,12 @@ public static void main(String[] args) { System.out.println("wt lean TEG after reboiler " + column.getLiquidOutStream().getFluid().getPhase("aqueous").getWtFrac("TEG")); System.out.println("temperature from pump " - + (hotLeanTEGPump2.getOutStream().getTemperature() - 273.15)); + + (hotLeanTEGPump2.getOutletStream().getTemperature() - 273.15)); System.out.println("flow rate from reboiler " + ((Reboiler) column.getReboiler()).getLiquidOutStream().getFlowRate("kg/hr")); System.out.println("flow rate from pump2 " - + hotLeanTEGPump2.getOutStream().getFluid().getFlowRate("kg/hr")); + + hotLeanTEGPump2.getOutletStream().getFluid().getFlowRate("kg/hr")); System.out.println("flow rate to flare " + gasToFlare.getFluid().getFlowRate("kg/hr")); System.out.println("condenser duty " @@ -304,23 +305,24 @@ public static void main(String[] args) { System.out.println("richGLycolHeaterCondenser duty " + richGLycolHeaterCondenser.getEnergyStream().getDuty() / 1.0e3); System.out.println("richGLycolHeaterCondenser temperature out " - + richGLycolHeaterCondenser.getOutStream().getTemperature("C")); + + richGLycolHeaterCondenser.getOutletStream().getTemperature("C")); richGLycolHeaterCondenser.run(); - hotLeanTEGPump.getOutStream().displayResult(); + hotLeanTEGPump.getOutletStream().displayResult(); flashLiquid.displayResult(); System.out.println("Temperature rich TEG out of reflux condenser " - + richGLycolHeaterCondenser.getOutStream().getTemperature("C")); + + richGLycolHeaterCondenser.getOutletStream().getTemperature("C")); heatEx.displayResult(); System.out.println("glycol out temperature " - + glycol_flash_valve2.getOutStream().getFluid().getTemperature("C")); + + glycol_flash_valve2.getOutletStream().getFluid().getTemperature("C")); System.out .println("glycol out temperature2 " + heatEx2.getOutStream(0).getTemperature("C")); System.out .println("glycol out temperature2 " + heatEx2.getOutStream(1).getTemperature("C")); - System.out.println("out water rate LP valve" + glycol_flash_valve2.getOutStream().getFluid() + System.out.println("out water rate LP valve" + glycol_flash_valve2.getOutletStream() + .getFluid() .getPhase(0).getComponent("water").getNumberOfmoles()); System.out.println("glycol out water rate reboil " + ((Reboiler) column.getReboiler()) .getLiquidOutStream().getFluid().getComponent("water").getNumberOfmoles()); diff --git a/src/test/java/neqsim/processSimulation/util/example/TEGdehydrationProcessDistillation3.java b/src/test/java/neqsim/processSimulation/util/example/TEGdehydrationProcessDistillation3.java index 0c862366e1..0da0ab4c06 100644 --- a/src/test/java/neqsim/processSimulation/util/example/TEGdehydrationProcessDistillation3.java +++ b/src/test/java/neqsim/processSimulation/util/example/TEGdehydrationProcessDistillation3.java @@ -64,7 +64,7 @@ public static void main(String[] args) { new StreamSaturatorUtil("water saturator", dryFeedGas); Stream waterSaturatedFeedGas = - new Stream("water saturated feed gas", saturatedFeedGas.getOutStream()); + new Stream("water saturated feed gas", saturatedFeedGas.getOutletStream()); neqsim.thermo.system.SystemInterface feedTEG = feedGas.clone(); feedTEG.setMolarComposition( @@ -89,13 +89,14 @@ public static void main(String[] args) { glycol_flash_valve.setOutletPressure(4.9); Heater richGLycolHeaterCondenser = - new Heater("rich TEG preheater", glycol_flash_valve.getOutStream()); + new Heater("rich TEG preheater", glycol_flash_valve.getOutletStream()); Heater richGLycolHeater = - new Heater("rich TEG heater HP", richGLycolHeaterCondenser.getOutStream()); + new Heater("rich TEG heater HP", richGLycolHeaterCondenser.getOutletStream()); richGLycolHeater.setOutTemperature(273.15 + 62.0); - Separator flashSep = new Separator("degasing separator", richGLycolHeater.getOutStream()); + Separator flashSep = + new Separator("degasing separator", richGLycolHeater.getOutletStream()); Stream flashGas = new Stream("gas from degasing separator", flashSep.getGasOutStream()); @@ -120,7 +121,7 @@ public static void main(String[] args) { DistillationColumn column = new DistillationColumn(1, true, true); column.setName("TEG regeneration column"); - column.addFeedStream(richGLycolHeater2.getOutStream(), 0); + column.addFeedStream(richGLycolHeater2.getOutletStream(), 0); column.getReboiler().setOutTemperature(273.15 + 206.6); column.getCondenser().setOutTemperature(273.15 + 101.0); column.getReboiler().addStream(gasToReboiler); @@ -130,7 +131,8 @@ public static void main(String[] args) { Heater coolerRegenGas = new Heater("regen gas cooler", column.getGasOutStream()); coolerRegenGas.setOutTemperature(273.15 + 35.5); - Separator sepregenGas = new Separator("regen gas separator", coolerRegenGas.getOutStream()); + Separator sepregenGas = + new Separator("regen gas separator", coolerRegenGas.getOutletStream()); Stream gasToFlare = new Stream("gas to flare", sepregenGas.getGasOutStream()); @@ -150,25 +152,25 @@ public static void main(String[] args) { Heater bufferTank = new Heater("TEG buffer tank", stripper.getSolventOutStream()); bufferTank.setOutTemperature(273.15 + 185.0); - Pump hotLeanTEGPump = new Pump("hot lean TEG pump", bufferTank.getOutStream()); + Pump hotLeanTEGPump = new Pump("hot lean TEG pump", bufferTank.getOutletStream()); hotLeanTEGPump.setOutletPressure(20.0); hotLeanTEGPump.setIsentropicEfficiency(0.75); - Heater coolerhOTteg = new Heater("hot lean TEG cooler", hotLeanTEGPump.getOutStream()); + Heater coolerhOTteg = new Heater("hot lean TEG cooler", hotLeanTEGPump.getOutletStream()); coolerhOTteg.setOutTemperature(273.15 + 116.8); Heater coolerhOTteg2 = - new Heater("medium hot lean TEG cooler", coolerhOTteg.getOutStream()); + new Heater("medium hot lean TEG cooler", coolerhOTteg.getOutletStream()); coolerhOTteg2.setOutTemperature(273.15 + 89.3); - Heater coolerhOTteg3 = new Heater("lean TEG cooler", coolerhOTteg2.getOutStream()); + Heater coolerhOTteg3 = new Heater("lean TEG cooler", coolerhOTteg2.getOutletStream()); coolerhOTteg3.setOutTemperature(273.15 + 43.0); - Pump hotLeanTEGPump2 = new Pump("lean TEG HP pump", coolerhOTteg3.getOutStream()); + Pump hotLeanTEGPump2 = new Pump("lean TEG HP pump", coolerhOTteg3.getOutletStream()); hotLeanTEGPump2.setOutletPressure(52.21); hotLeanTEGPump2.setIsentropicEfficiency(0.75); - Stream leanTEGtoabs = new Stream("lean TEG to absorber", hotLeanTEGPump2.getOutStream()); + Stream leanTEGtoabs = new Stream("lean TEG to absorber", hotLeanTEGPump2.getOutletStream()); neqsim.thermo.system.SystemInterface pureTEG = feedGas.clone(); pureTEG.setMolarComposition( @@ -191,7 +193,7 @@ public static void main(String[] args) { makeupMixer.addStream(makeupTEG); Recycle resycleLeanTEG = new Recycle("lean TEG resycle"); - resycleLeanTEG.addStream(makeupMixer.getOutStream()); + resycleLeanTEG.addStream(makeupMixer.getOutletStream()); resycleLeanTEG.setOutletStream(TEGFeed); resycleLeanTEG.setPriority(200); resycleLeanTEG.setDownstreamProperty("flow rate"); @@ -277,7 +279,7 @@ public static void main(String[] args) { System.out.println("flow rate from stripping column " + stripper.getLiquidOutStream().getFlowRate("kg/hr")); System.out.println("flow rate from pump2 " - + hotLeanTEGPump2.getOutStream().getFluid().getFlowRate("kg/hr")); + + hotLeanTEGPump2.getOutletStream().getFluid().getFlowRate("kg/hr")); System.out.println("makeup TEG " + makeupTEG.getFluid().getFlowRate("kg/hr")); TEGFeed.getFluid().display(); @@ -288,26 +290,26 @@ public static void main(String[] args) { System.out.println("wt lean TEG after reboiler " + column.getLiquidOutStream().getFluid().getPhase("aqueous").getWtFrac("TEG")); System.out.println("temperature from pump " - + (hotLeanTEGPump2.getOutStream().getTemperature() - 273.15)); + + (hotLeanTEGPump2.getOutletStream().getTemperature() - 273.15)); System.out.println("flow rate from reboiler " + ((Reboiler) column.getReboiler()).getLiquidOutStream().getFlowRate("kg/hr")); System.out.println("flow rate from pump2 " - + hotLeanTEGPump2.getOutStream().getFluid().getFlowRate("kg/hr")); + + hotLeanTEGPump2.getOutletStream().getFluid().getFlowRate("kg/hr")); System.out.println("condenser duty " + ((Condenser) ((DistillationColumn) operations.getUnit("TEG regeneration column")) .getCondenser()).getDuty() / 1.0e3); System.out.println("richGLycolHeaterCondenser duty " + richGLycolHeaterCondenser.getEnergyStream().getDuty() / 1.0e3); System.out.println("richGLycolHeaterCondenser temperature out " - + richGLycolHeaterCondenser.getOutStream().getTemperature("C")); + + richGLycolHeaterCondenser.getOutletStream().getTemperature("C")); richGLycolHeaterCondenser.run(); - hotLeanTEGPump.getOutStream().displayResult(); + hotLeanTEGPump.getOutletStream().displayResult(); flashLiquid.displayResult(); HeatExchanger heatEx = - new HeatExchanger("heatEx", flashLiquid, hotLeanTEGPump.getOutStream()); + new HeatExchanger("heatEx", flashLiquid, hotLeanTEGPump.getOutletStream()); heatEx.setUAvalue(350.0); heatEx.run(); heatEx.displayResult(); diff --git a/src/test/java/neqsim/processSimulation/util/example/TEGdehydrationProcessDistillationAaHa.java b/src/test/java/neqsim/processSimulation/util/example/TEGdehydrationProcessDistillationAaHa.java index 6d50e6c621..caa29e84d7 100644 --- a/src/test/java/neqsim/processSimulation/util/example/TEGdehydrationProcessDistillationAaHa.java +++ b/src/test/java/neqsim/processSimulation/util/example/TEGdehydrationProcessDistillationAaHa.java @@ -65,7 +65,7 @@ public static neqsim.processSimulation.processSystem.ProcessSystem getProcess() new StreamSaturatorUtil("water saturator", dryFeedGas); Stream waterSaturatedFeedGas = - new Stream("water saturated feed gas", saturatedFeedGas.getOutStream()); + new Stream("water saturated feed gas", saturatedFeedGas.getOutletStream()); HydrateEquilibriumTemperatureAnalyser hydrateTAnalyser = new HydrateEquilibriumTemperatureAnalyser(waterSaturatedFeedGas); @@ -80,7 +80,7 @@ public static neqsim.processSimulation.processSystem.ProcessSystem getProcess() feedTPsetterToAbsorber.setOutTemperature(27.93, "C"); Stream feedToAbsorber = - new Stream("feed to TEG absorber", feedTPsetterToAbsorber.getOutStream()); + new Stream("feed to TEG absorber", feedTPsetterToAbsorber.getOutletStream()); Stream TEGFeed = new Stream("lean TEG to absorber", feedTEG); TEGFeed.setFlowRate(14.68 * 1100.0, "kg/hr"); @@ -110,10 +110,10 @@ public static neqsim.processSimulation.processSystem.ProcessSystem getProcess() glycol_flash_valve.setOutletPressure(5.5); Heater richGLycolHeaterCondenser = - new Heater("rich TEG preheater", glycol_flash_valve.getOutStream()); + new Heater("rich TEG preheater", glycol_flash_valve.getOutletStream()); HeatExchanger heatEx2 = new HeatExchanger("rich TEG heat exchanger 1", - richGLycolHeaterCondenser.getOutStream()); + richGLycolHeaterCondenser.getOutletStream()); heatEx2.setGuessOutTemperature(273.15 + 62.0); heatEx2.setUAvalue(200.0); @@ -127,11 +127,11 @@ public static neqsim.processSimulation.processSystem.ProcessSystem getProcess() Filter fineFilter = new Filter("TEG fine filter", flashLiquid); fineFilter.setDeltaP(0.05, "bara"); - Filter carbonFilter = new Filter("activated carbon filter", fineFilter.getOutStream()); + Filter carbonFilter = new Filter("activated carbon filter", fineFilter.getOutletStream()); carbonFilter.setDeltaP(0.01, "bara"); HeatExchanger heatEx = - new HeatExchanger("rich TEG heat exchanger 2", carbonFilter.getOutStream()); + new HeatExchanger("rich TEG heat exchanger 2", carbonFilter.getOutletStream()); heatEx.setGuessOutTemperature(273.15 + 130.0); heatEx.setUAvalue(390.0); @@ -154,7 +154,7 @@ public static neqsim.processSimulation.processSystem.ProcessSystem getProcess() DistillationColumn column = new DistillationColumn(1, true, true); column.setName("TEG regeneration column"); - column.addFeedStream(glycol_flash_valve2.getOutStream(), 0); + column.addFeedStream(glycol_flash_valve2.getOutletStream(), 0); column.getReboiler().setOutTemperature(273.15 + 201.0); column.getCondenser().setOutTemperature(273.15 + 92.0); column.getReboiler().addStream(gasToReboiler); @@ -164,7 +164,8 @@ public static neqsim.processSimulation.processSystem.ProcessSystem getProcess() Heater coolerRegenGas = new Heater("regen gas cooler", column.getGasOutStream()); coolerRegenGas.setOutTemperature(273.15 + 7.5); - Separator sepregenGas = new Separator("regen gas separator", coolerRegenGas.getOutStream()); + Separator sepregenGas = + new Separator("regen gas separator", coolerRegenGas.getOutletStream()); Stream gasToFlare = new Stream("gas to flare", sepregenGas.getGasOutStream()); @@ -188,25 +189,25 @@ public static neqsim.processSimulation.processSystem.ProcessSystem getProcess() Heater bufferTank = new Heater("TEG buffer tank", stripper.getLiquidOutStream()); bufferTank.setOutTemperature(273.15 + 191.0); - Pump hotLeanTEGPump = new Pump("hot lean TEG pump", bufferTank.getOutStream());// stripper.getSolventOutStream()); + Pump hotLeanTEGPump = new Pump("hot lean TEG pump", bufferTank.getOutletStream());// stripper.getSolventOutStream()); hotLeanTEGPump.setOutletPressure(5.0); hotLeanTEGPump.setIsentropicEfficiency(0.6); - heatEx.setFeedStream(1, hotLeanTEGPump.getOutStream()); + heatEx.setFeedStream(1, hotLeanTEGPump.getOutletStream()); heatEx2.setFeedStream(1, heatEx.getOutStream(1)); Heater coolerhOTteg3 = new Heater("lean TEG cooler", heatEx2.getOutStream(1)); coolerhOTteg3.setOutTemperature(273.15 + 35.41); - Pump hotLeanTEGPump2 = new Pump("lean TEG HP pump", coolerhOTteg3.getOutStream()); + Pump hotLeanTEGPump2 = new Pump("lean TEG HP pump", coolerhOTteg3.getOutletStream()); hotLeanTEGPump2.setOutletPressure(87.2); hotLeanTEGPump2.setIsentropicEfficiency(0.75); SetPoint pumpHPPresSet = new SetPoint("HP pump set", hotLeanTEGPump2, "pressure", feedToAbsorber); - Stream leanTEGtoabs = new Stream("lean TEG to absorber", hotLeanTEGPump2.getOutStream()); + Stream leanTEGtoabs = new Stream("lean TEG to absorber", hotLeanTEGPump2.getOutletStream()); neqsim.thermo.system.SystemInterface pureTEG = feedGas.clone(); pureTEG.setMolarComposition(new double[] {0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, @@ -229,7 +230,7 @@ public static neqsim.processSimulation.processSystem.ProcessSystem getProcess() makeupMixer.addStream(makeupTEG); Recycle resycleLeanTEG = new Recycle("lean TEG resycle"); - resycleLeanTEG.addStream(makeupMixer.getOutStream()); + resycleLeanTEG.addStream(makeupMixer.getOutletStream()); resycleLeanTEG.setOutletStream(TEGFeed); resycleLeanTEG.setPriority(200); resycleLeanTEG.setDownstreamProperty("flow rate"); diff --git a/src/test/java/neqsim/processSimulation/util/example/TEGdehydrationProcessDistillationGFA.java b/src/test/java/neqsim/processSimulation/util/example/TEGdehydrationProcessDistillationGFA.java index c53cbd185e..1791694fc4 100644 --- a/src/test/java/neqsim/processSimulation/util/example/TEGdehydrationProcessDistillationGFA.java +++ b/src/test/java/neqsim/processSimulation/util/example/TEGdehydrationProcessDistillationGFA.java @@ -193,7 +193,7 @@ public neqsim.processSimulation.processSystem.ProcessSystem getProcess() { new StreamSaturatorUtil("water saturator", dryFeedGas); Stream waterSaturatedFeedGas = - new Stream("water saturated feed gas", saturatedFeedGas.getOutStream()); + new Stream("water saturated feed gas", saturatedFeedGas.getOutletStream()); HydrateEquilibriumTemperatureAnalyser hydrateTAnalyser = new HydrateEquilibriumTemperatureAnalyser(waterSaturatedFeedGas); @@ -208,7 +208,7 @@ public neqsim.processSimulation.processSystem.ProcessSystem getProcess() { feedTPsetterToAbsorber.setOutTemperature(absorberFeedGasTemperature, "C"); Stream feedToAbsorber = - new Stream("feed to TEG absorber", feedTPsetterToAbsorber.getOutStream()); + new Stream("feed to TEG absorber", feedTPsetterToAbsorber.getOutletStream()); Stream TEGFeed = new Stream("lean TEG to absorber", feedTEG); TEGFeed.setFlowRate(leanTEGFlowRate, "kg/hr"); @@ -237,10 +237,10 @@ public neqsim.processSimulation.processSystem.ProcessSystem getProcess() { glycol_flash_valve.setOutletPressure(flashDrumPressure); Heater richGLycolHeaterCondenser = - new Heater("rich TEG preheater", glycol_flash_valve.getOutStream()); + new Heater("rich TEG preheater", glycol_flash_valve.getOutletStream()); HeatExchanger heatEx2 = new HeatExchanger("rich TEG heat exchanger 1", - richGLycolHeaterCondenser.getOutStream()); + richGLycolHeaterCondenser.getOutletStream()); heatEx2.setGuessOutTemperature(273.15 + 62.0); heatEx2.setUAvalue(UAvalueRichTEGHeatExchanger_1); @@ -254,7 +254,7 @@ public neqsim.processSimulation.processSystem.ProcessSystem getProcess() { Filter filter = new Filter("filters", flashLiquid); HeatExchanger heatEx = - new HeatExchanger("rich TEG heat exchanger 2", filter.getOutStream()); + new HeatExchanger("rich TEG heat exchanger 2", filter.getOutletStream()); heatEx.setGuessOutTemperature(273.15 + 130.0); heatEx.setUAvalue(UAvalueRichTEGHeatExchanger_2); @@ -275,7 +275,7 @@ public neqsim.processSimulation.processSystem.ProcessSystem getProcess() { DistillationColumn column = new DistillationColumn(3, true, true); column.setName("TEG regeneration column"); - column.addFeedStream(glycol_flash_valve2.getOutStream(), 1); + column.addFeedStream(glycol_flash_valve2.getOutletStream(), 1); column.getReboiler().setOutTemperature(273.15 + reboilerTemperature); column.getCondenser().setOutTemperature(273.15 + condenserTemperature); column.getReboiler().addStream(gasToReboiler); @@ -285,7 +285,8 @@ public neqsim.processSimulation.processSystem.ProcessSystem getProcess() { Heater coolerRegenGas = new Heater("regen gas cooler", column.getGasOutStream()); coolerRegenGas.setOutTemperature(273.15 + regenerationGasCoolerTemperature); - Separator sepregenGas = new Separator("regen gas separator", coolerRegenGas.getOutStream()); + Separator sepregenGas = + new Separator("regen gas separator", coolerRegenGas.getOutletStream()); Stream gasToFlare = new Stream("gas to flare", sepregenGas.getGasOutStream()); @@ -305,25 +306,25 @@ public neqsim.processSimulation.processSystem.ProcessSystem getProcess() { Heater bufferTank = new Heater("TEG buffer tank", stripper.getSolventOutStream()); bufferTank.setOutTemperature(273.15 + bufferTankTemperatureTEG); - Pump hotLeanTEGPump = new Pump("hot lean TEG pump", bufferTank.getOutStream());// stripper.getSolventOutStream()); + Pump hotLeanTEGPump = new Pump("hot lean TEG pump", bufferTank.getOutletStream());// stripper.getSolventOutStream()); hotLeanTEGPump.setOutletPressure(hotTEGpumpPressure); hotLeanTEGPump.setIsentropicEfficiency(hotTEGpumpIsentropicEfficiency); - heatEx.setFeedStream(1, hotLeanTEGPump.getOutStream()); + heatEx.setFeedStream(1, hotLeanTEGPump.getOutletStream()); heatEx2.setFeedStream(1, heatEx.getOutStream(1)); Heater coolerhOTteg3 = new Heater("lean TEG cooler", heatEx2.getOutStream(1)); coolerhOTteg3.setOutTemperature(273.15 + leanTEGTemperature); - Pump hotLeanTEGPump2 = new Pump("lean TEG HP pump", coolerhOTteg3.getOutStream()); + Pump hotLeanTEGPump2 = new Pump("lean TEG HP pump", coolerhOTteg3.getOutletStream()); hotLeanTEGPump2.setOutletPressure(absorberFeedGasPressure); hotLeanTEGPump2.setIsentropicEfficiency(coldTEGpumpIsentropicEfficiency); SetPoint pumpHPPresSet = new SetPoint("HP pump set", hotLeanTEGPump2, "pressure", feedToAbsorber); - Stream leanTEGtoabs = new Stream("lean TEG to absorber", hotLeanTEGPump2.getOutStream()); + Stream leanTEGtoabs = new Stream("lean TEG to absorber", hotLeanTEGPump2.getOutletStream()); neqsim.thermo.system.SystemInterface pureTEG = feedGas.clone(); pureTEG.setMolarComposition( @@ -346,7 +347,7 @@ public neqsim.processSimulation.processSystem.ProcessSystem getProcess() { makeupMixer.addStream(makeupTEG); Recycle resycleLeanTEG = new Recycle("lean TEG resycle"); - resycleLeanTEG.addStream(makeupMixer.getOutStream()); + resycleLeanTEG.addStream(makeupMixer.getOutletStream()); resycleLeanTEG.setOutletStream(TEGFeed); resycleLeanTEG.setPriority(200); resycleLeanTEG.setDownstreamProperty("flow rate"); @@ -416,7 +417,7 @@ public static void main(String[] args) { // neqsim.processSimulation.processSystem.ProcessSystem.open("c:/temp/TEGprocessGFA.neqsim"); double richTEGtemperature = ((Heater) operations.getUnit("rich TEG preheater")) - .getOutStream().getTemperature("C"); + .getOutletStream().getTemperature("C"); System.out.println("temp rich TEG " + richTEGtemperature); System.out.println("condenser duty (KW) " + ((Condenser) ((DistillationColumn) operations.getUnit("TEG regeneration column")) diff --git a/src/test/java/neqsim/processSimulation/util/example/TEGdehydrationProcessDistillationJS.java b/src/test/java/neqsim/processSimulation/util/example/TEGdehydrationProcessDistillationJS.java index 566a260474..6e69ca0ab6 100644 --- a/src/test/java/neqsim/processSimulation/util/example/TEGdehydrationProcessDistillationJS.java +++ b/src/test/java/neqsim/processSimulation/util/example/TEGdehydrationProcessDistillationJS.java @@ -198,7 +198,7 @@ public neqsim.processSimulation.processSystem.ProcessSystem getProcess() { new StreamSaturatorUtil("water saturator", dryFeedGas); Stream waterSaturatedFeedGas = - new Stream("water saturated feed gas", saturatedFeedGas.getOutStream()); + new Stream("water saturated feed gas", saturatedFeedGas.getOutletStream()); HydrateEquilibriumTemperatureAnalyser hydrateTAnalyser = new HydrateEquilibriumTemperatureAnalyser(waterSaturatedFeedGas); @@ -213,7 +213,7 @@ public neqsim.processSimulation.processSystem.ProcessSystem getProcess() { feedTPsetterToAbsorber.setOutTemperature(absorberFeedGasTemperature, "C"); Stream feedToAbsorber = - new Stream("feed to TEG absorber", feedTPsetterToAbsorber.getOutStream()); + new Stream("feed to TEG absorber", feedTPsetterToAbsorber.getOutletStream()); Stream TEGFeed = new Stream("lean TEG to absorber", feedTEG); TEGFeed.setFlowRate(leanTEGFlowRate, "kg/hr"); @@ -238,10 +238,10 @@ public neqsim.processSimulation.processSystem.ProcessSystem getProcess() { glycol_flash_valve.setOutletPressure(flashDrumPressure); Heater richGLycolHeaterCondenser = - new Heater("rich TEG preheater", glycol_flash_valve.getOutStream()); + new Heater("rich TEG preheater", glycol_flash_valve.getOutletStream()); HeatExchanger heatEx2 = new HeatExchanger("rich TEG heat exchanger 1", - richGLycolHeaterCondenser.getOutStream()); + richGLycolHeaterCondenser.getOutletStream()); heatEx2.setGuessOutTemperature(273.15 + 62.0); heatEx2.setUAvalue(UAvalueRichTEGHeatExchanger_1); @@ -255,11 +255,11 @@ public neqsim.processSimulation.processSystem.ProcessSystem getProcess() { Filter fineFilter = new Filter("TEG fine filter", flashLiquid); fineFilter.setDeltaP(0.05, "bara"); - Filter carbonFilter = new Filter("activated carbon filter", fineFilter.getOutStream()); + Filter carbonFilter = new Filter("activated carbon filter", fineFilter.getOutletStream()); carbonFilter.setDeltaP(0.01, "bara"); HeatExchanger heatEx = - new HeatExchanger("rich TEG heat exchanger 2", carbonFilter.getOutStream()); + new HeatExchanger("rich TEG heat exchanger 2", carbonFilter.getOutletStream()); heatEx.setGuessOutTemperature(273.15 + 130.0); heatEx.setUAvalue(UAvalueRichTEGHeatExchanger_2); @@ -280,7 +280,7 @@ public neqsim.processSimulation.processSystem.ProcessSystem getProcess() { DistillationColumn column = new DistillationColumn(1, true, true); column.setName("TEG regeneration column"); - column.addFeedStream(glycol_flash_valve2.getOutStream(), 0); + column.addFeedStream(glycol_flash_valve2.getOutletStream(), 0); column.getReboiler().setOutTemperature(273.15 + reboilerTemperature); column.getCondenser().setOutTemperature(273.15 + condenserTemperature); column.getReboiler().addStream(gasToReboiler); @@ -290,7 +290,8 @@ public neqsim.processSimulation.processSystem.ProcessSystem getProcess() { Heater coolerRegenGas = new Heater("regen gas cooler", column.getGasOutStream()); coolerRegenGas.setOutTemperature(273.15 + regenerationGasCoolerTemperature); - Separator sepregenGas = new Separator("regen gas separator", coolerRegenGas.getOutStream()); + Separator sepregenGas = + new Separator("regen gas separator", coolerRegenGas.getOutletStream()); Stream gasToFlare = new Stream("gas to flare", sepregenGas.getGasOutStream()); @@ -310,25 +311,25 @@ public neqsim.processSimulation.processSystem.ProcessSystem getProcess() { Heater bufferTank = new Heater("TEG buffer tank", stripper.getSolventOutStream()); bufferTank.setOutTemperature(273.15 + bufferTankTemperatureTEG); - Pump hotLeanTEGPump = new Pump("hot lean TEG pump", bufferTank.getOutStream()); + Pump hotLeanTEGPump = new Pump("hot lean TEG pump", bufferTank.getOutletStream()); hotLeanTEGPump.setOutletPressure(hotTEGpumpPressure); hotLeanTEGPump.setIsentropicEfficiency(hotTEGpumpIsentropicEfficiency); - heatEx.setFeedStream(1, hotLeanTEGPump.getOutStream()); + heatEx.setFeedStream(1, hotLeanTEGPump.getOutletStream()); heatEx2.setFeedStream(1, heatEx.getOutStream(1)); Heater coolerhOTteg3 = new Heater("lean TEG cooler", heatEx2.getOutStream(1)); coolerhOTteg3.setOutTemperature(273.15 + leanTEGTemperature); - Pump hotLeanTEGPump2 = new Pump("lean TEG HP pump", coolerhOTteg3.getOutStream()); + Pump hotLeanTEGPump2 = new Pump("lean TEG HP pump", coolerhOTteg3.getOutletStream()); hotLeanTEGPump2.setOutletPressure(absorberFeedGasPressure); hotLeanTEGPump2.setIsentropicEfficiency(coldTEGpumpIsentropicEfficiency); SetPoint pumpHPPresSet = new SetPoint("HP pump set", hotLeanTEGPump2, "pressure", feedToAbsorber); - Stream leanTEGtoabs = new Stream("lean TEG to absorber", hotLeanTEGPump2.getOutStream()); + Stream leanTEGtoabs = new Stream("lean TEG to absorber", hotLeanTEGPump2.getOutletStream()); neqsim.thermo.system.SystemInterface pureTEG = feedGas.clone(); pureTEG.setMolarComposition(new double[] {0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, @@ -351,7 +352,7 @@ public neqsim.processSimulation.processSystem.ProcessSystem getProcess() { makeupMixer.addStream(makeupTEG); Recycle resycleLeanTEG = new Recycle("lean TEG resycle"); - resycleLeanTEG.addStream(makeupMixer.getOutStream()); + resycleLeanTEG.addStream(makeupMixer.getOutletStream()); resycleLeanTEG.setOutletStream(TEGFeed); resycleLeanTEG.setPriority(200); resycleLeanTEG.setDownstreamProperty("flow rate"); diff --git a/src/test/java/neqsim/processSimulation/util/example/TestNeqsim.java b/src/test/java/neqsim/processSimulation/util/example/TestNeqsim.java index b5005bb416..b389ca1234 100644 --- a/src/test/java/neqsim/processSimulation/util/example/TestNeqsim.java +++ b/src/test/java/neqsim/processSimulation/util/example/TestNeqsim.java @@ -61,7 +61,7 @@ public static void main(String[] args) { compressor1.setOutletPressure(26.590909);// (20+5*i) compressor1.setUsePolytropicCalc(true); compressor1.setPolytropicEfficiency(0.64951); - Stream stream2 = new Stream("stream2", compressor1.getOutStream()); + Stream stream2 = new Stream("stream2", compressor1.getOutletStream()); neqsim.processSimulation.processSystem.ProcessSystem operations = new neqsim.processSimulation.processSystem.ProcessSystem(); @@ -90,7 +90,7 @@ public static void main(String[] args) { + stream1.getThermoSystem().getPhase(0).getSoundSpeed()); compressor1.solveEfficiency(390.15); - compressor1.getOutStream().displayResult(); + compressor1.getOutletStream().displayResult(); System.out.println("Hvap " + stream1.getThermoSystem().getHeatOfVaporization() + " POLI " + compressor1.getPolytropicEfficiency() + " dentity " + stream1.getThermoSystem().getDensity() + " cp " @@ -112,7 +112,7 @@ public static void main(String[] args) { double GVF = volFlowGas / (volFlowGas + volFlowOil + volFlowLiq); System.out.println("inlet stream - GMF " + GMF + " GVF " + GVF + " Z IN " + stream1.getThermoSystem().getZ() + " Z OUT " - + compressor1.getOutStream().getThermoSystem().getZ()); + + compressor1.getOutletStream().getThermoSystem().getZ()); /* * temperature[i] = compressor1.getOutStream().getTemperature(); work [i] = * compressor1.getTotalWork(); diff --git a/src/test/java/neqsim/processSimulation/util/example/TestSeparationTrain.java b/src/test/java/neqsim/processSimulation/util/example/TestSeparationTrain.java index 32b591ce73..e3cbc2a179 100644 --- a/src/test/java/neqsim/processSimulation/util/example/TestSeparationTrain.java +++ b/src/test/java/neqsim/processSimulation/util/example/TestSeparationTrain.java @@ -49,36 +49,36 @@ public static void main(String args[]) { liquidOutHeater.setOutTemperature(273.15 + 55.0); ThreePhaseSeparator firstStageSeparator = - new ThreePhaseSeparator("1st stage Separator", liquidOutHeater.getOutStream()); + new ThreePhaseSeparator("1st stage Separator", liquidOutHeater.getOutletStream()); ThrottlingValve valve1 = new ThrottlingValve("snohvit valve", firstStageSeparator.getOilOutStream()); valve1.setOutletPressure(secondstagePressure); ThreePhaseSeparator secondStageSeparator = - new ThreePhaseSeparator("2nd stage Separator", valve1.getOutStream()); + new ThreePhaseSeparator("2nd stage Separator", valve1.getOutletStream()); ThrottlingValve thirdStageValve = new ThrottlingValve("snohvit valve2", secondStageSeparator.getLiquidOutStream()); thirdStageValve.setOutletPressure(thirdstagePressure); ThreePhaseSeparator thirdStageSeparator = - new ThreePhaseSeparator("3rd stage Separator", thirdStageValve.getOutStream()); + new ThreePhaseSeparator("3rd stage Separator", thirdStageValve.getOutletStream()); Compressor thirdStageCompressor = new Compressor("thirdStageCompressor", thirdStageSeparator.getGasOutStream()); thirdStageCompressor.setOutletPressure(secondstagePressure); - Mixer thirdStageMixer = new Mixer(); - thirdStageMixer.addStream(thirdStageCompressor.getOutStream()); + Mixer thirdStageMixer = new Mixer("thirdStageMixer"); + thirdStageMixer.addStream(thirdStageCompressor.getOutletStream()); thirdStageMixer.addStream(secondStageSeparator.getGasOutStream()); Cooler thirdSstageCoooler = - new Cooler("thirdSstageCoooler", thirdStageMixer.getOutStream()); + new Cooler("thirdSstageCoooler", thirdStageMixer.getOutletStream()); thirdSstageCoooler.setOutTemperature(273.15 + 30.0); ThreePhaseSeparator thirdStageScrubber = new ThreePhaseSeparator( - "Third stage gas resirc scrubber", thirdSstageCoooler.getOutStream()); + "Third stage gas resirc scrubber", thirdSstageCoooler.getOutletStream()); secondStageSeparator.addStream(thirdStageScrubber.getOilOutStream()); secondStageSeparator.addStream(thirdStageScrubber.getWaterOutStream()); @@ -86,18 +86,18 @@ public static void main(String args[]) { new Compressor("secondStageCompressor", thirdStageScrubber.getGasOutStream()); secondStageCompressor.setOutletPressure(inletPressure); - Mixer HPgasMixer = new Mixer(); + Mixer HPgasMixer = new Mixer("HPgasMixer"); HPgasMixer.addStream(inletSeparator.getGasOutStream()); - HPgasMixer.addStream(secondStageCompressor.getOutStream()); + HPgasMixer.addStream(secondStageCompressor.getOutletStream()); Cooler oilCooler = new Cooler("oilCooler", thirdStageSeparator.getLiquidOutStream()); oilCooler.setOutTemperature(273.15 + 30.0); - Cooler inletGasCooler = new Cooler("inletGasCooler", HPgasMixer.getOutStream()); + Cooler inletGasCooler = new Cooler("inletGasCooler", HPgasMixer.getOutletStream()); inletGasCooler.setOutTemperature(273.15 + 30.0); Separator gasInletScrubber = - new Separator("Gas scrubber inlet", inletGasCooler.getOutStream()); + new Separator("Gas scrubber inlet", inletGasCooler.getOutletStream()); Recycle HPliquidRecycle = new Recycle("HPliquidRecycle"); double tolerance = 1e-10; diff --git a/src/test/java/neqsim/processSimulation/util/example/TestSlugcatcher.java b/src/test/java/neqsim/processSimulation/util/example/TestSlugcatcher.java index aa04fb8421..dae8ea8707 100644 --- a/src/test/java/neqsim/processSimulation/util/example/TestSlugcatcher.java +++ b/src/test/java/neqsim/processSimulation/util/example/TestSlugcatcher.java @@ -52,7 +52,7 @@ public static void main(String args[]) { valve1.setOutletPressure(1.4); ThreePhaseSeparator separator2 = - new ThreePhaseSeparator("Separator 1", valve1.getOutStream()); + new ThreePhaseSeparator("Separator 1", valve1.getOutletStream()); Stream stream_2 = new Stream("stream_2", separator2.getGasOutStream()); VolumeFlowTransmitter volumeTransmitter3 = diff --git a/src/test/java/neqsim/processSimulation/util/example/TestTransientFlow.java b/src/test/java/neqsim/processSimulation/util/example/TestTransientFlow.java index 44daa14f16..d732ffee98 100644 --- a/src/test/java/neqsim/processSimulation/util/example/TestTransientFlow.java +++ b/src/test/java/neqsim/processSimulation/util/example/TestTransientFlow.java @@ -57,8 +57,8 @@ public static void main(String args[]) { valve_1.setPercentValveOpening(50); Separator separator_1 = new Separator("separator_1"); - separator_1.addStream(valve_1.getOutStream()); - separator_1.addStream(purgeValve.getOutStream()); + separator_1.addStream(valve_1.getOutletStream()); + separator_1.addStream(purgeValve.getOutletStream()); ThrottlingValve valve_2 = new ThrottlingValve("valve_2", separator_1.getLiquidOutStream()); valve_2.setOutletPressure(5.0); diff --git a/src/test/java/neqsim/processSimulation/util/example/TestTransientFlow2.java b/src/test/java/neqsim/processSimulation/util/example/TestTransientFlow2.java index fbef3f1a5d..2e00c72ce3 100644 --- a/src/test/java/neqsim/processSimulation/util/example/TestTransientFlow2.java +++ b/src/test/java/neqsim/processSimulation/util/example/TestTransientFlow2.java @@ -35,7 +35,7 @@ public static void main(String args[]) { valve_1.setPercentValveOpening(50); Separator separator_1 = new Separator("separator_1"); - separator_1.addStream(valve_1.getOutStream()); + separator_1.addStream(valve_1.getOutletStream()); ThrottlingValve valve_2 = new ThrottlingValve("valve_2", separator_1.getLiquidOutStream()); valve_2.setOutletPressure(1.0); diff --git a/src/test/java/neqsim/processSimulation/util/example/WellStreamMixer.java b/src/test/java/neqsim/processSimulation/util/example/WellStreamMixer.java index 2b8924c901..87cca5fbd0 100644 --- a/src/test/java/neqsim/processSimulation/util/example/WellStreamMixer.java +++ b/src/test/java/neqsim/processSimulation/util/example/WellStreamMixer.java @@ -72,7 +72,7 @@ public static void main(String[] args) { wellStramMixer.addStream(wellStream_1); wellStramMixer.addStream(wellStream_2); - Stream mixerdStream = new Stream("mixed stream", wellStramMixer.getOutStream()); + Stream mixerdStream = new Stream("mixed stream", wellStramMixer.getOutletStream()); neqsim.processSimulation.processSystem.ProcessSystem operations = new neqsim.processSimulation.processSystem.ProcessSystem(); diff --git a/src/test/java/neqsim/processSimulation/util/example/compressorTest.java b/src/test/java/neqsim/processSimulation/util/example/compressorTest.java index 313b04326e..997421c0a1 100644 --- a/src/test/java/neqsim/processSimulation/util/example/compressorTest.java +++ b/src/test/java/neqsim/processSimulation/util/example/compressorTest.java @@ -35,7 +35,7 @@ public static void main(String args[]) { MixerInterface mixer = new StaticMixer("Mixer 1"); mixer.addStream(stream_1); - StreamInterface stream_3 = mixer.getOutStream(); + StreamInterface stream_3 = mixer.getOutletStream(); stream_3.setName("stream3"); Separator separator = new Separator("Separator 1", stream_3); diff --git a/src/test/java/neqsim/processSimulation/util/example/compressorTest_1.java b/src/test/java/neqsim/processSimulation/util/example/compressorTest_1.java index a2ae2b2c22..922fa4837c 100644 --- a/src/test/java/neqsim/processSimulation/util/example/compressorTest_1.java +++ b/src/test/java/neqsim/processSimulation/util/example/compressorTest_1.java @@ -51,17 +51,18 @@ public static void main(String args[]) { logger.info("power " + comp_1.getTotalWork()); logger.info("speed of sound " - + comp_1.getOutStream().getThermoSystem().getPhase(0).getSoundSpeed()); - logger.info("out temperature" + comp_1.getOutStream().getThermoSystem().getTemperature()); - logger.info("Cp " + comp_1.getOutStream().getThermoSystem().getPhase(0).getCp()); - logger.info("Cv " + comp_1.getOutStream().getThermoSystem().getPhase(0).getCv()); + + comp_1.getOutletStream().getThermoSystem().getPhase(0).getSoundSpeed()); + logger + .info("out temperature" + comp_1.getOutletStream().getThermoSystem().getTemperature()); + logger.info("Cp " + comp_1.getOutletStream().getThermoSystem().getPhase(0).getCp()); + logger.info("Cv " + comp_1.getOutletStream().getThermoSystem().getPhase(0).getCv()); logger.info( - "molarmass " + comp_1.getOutStream().getThermoSystem().getPhase(0).getMolarMass()); + "molarmass " + comp_1.getOutletStream().getThermoSystem().getPhase(0).getMolarMass()); double outTemp = 500.1; // temperature in Kelvin double efficiency = comp_1.solveEfficiency(outTemp); logger.info("compressor polytropic efficiency " + efficiency); - logger.info("compressor out temperature " + comp_1.getOutStream().getTemperature()); + logger.info("compressor out temperature " + comp_1.getOutletStream().getTemperature()); logger.info("compressor power " + comp_1.getPower() + " J/sec"); logger.info("compressor head " + comp_1.getPower() / comp_1.getThermoSystem().getTotalNumberOfMoles() + " J/mol"); diff --git a/src/test/java/neqsim/processSimulation/util/example/gasPipeline.java b/src/test/java/neqsim/processSimulation/util/example/gasPipeline.java index 6b7f77d038..8596677852 100644 --- a/src/test/java/neqsim/processSimulation/util/example/gasPipeline.java +++ b/src/test/java/neqsim/processSimulation/util/example/gasPipeline.java @@ -59,7 +59,7 @@ public static void main(String args[]) { // operations.add(simplePipeline2phase); operations.run(); - pipeline.getOutStream().displayResult(); + pipeline.getOutletStream().displayResult(); // simplePipeline.getOutStream().displayResult(); // simplePipeline2phase.getOutStream().displayResult(); diff --git a/src/test/java/neqsim/processSimulation/util/example/multiThreadTest.java b/src/test/java/neqsim/processSimulation/util/example/multiThreadTest.java index 5181625e44..21f56e15c6 100644 --- a/src/test/java/neqsim/processSimulation/util/example/multiThreadTest.java +++ b/src/test/java/neqsim/processSimulation/util/example/multiThreadTest.java @@ -37,7 +37,7 @@ public static void main(String args[]) { MixerInterface mixer = new StaticMixer("Mixer 1"); mixer.addStream(stream_1); - StreamInterface stream_3 = mixer.getOutStream(); + StreamInterface stream_3 = mixer.getOutletStream(); stream_3.setName("stream3"); Separator separator = new Separator("Separator 1", stream_3); @@ -47,7 +47,7 @@ public static void main(String args[]) { Compressor comp1 = new Compressor("comp1", stream_2); comp1.setOutletPressure(50.0); - Cooler cooler1 = new Cooler("cooler1", comp1.getOutStream()); + Cooler cooler1 = new Cooler("cooler1", comp1.getOutletStream()); cooler1.setOutTemperature(283.15 + 30); // mixer.addStream(stream_2); @@ -77,7 +77,7 @@ public static void main(String args[]) { MixerInterface mixer2 = new StaticMixer("Mixer 1"); mixer2.addStream(stream_22); - StreamInterface stream_32 = mixer2.getOutStream(); + StreamInterface stream_32 = mixer2.getOutletStream(); stream_32.setName("stream32"); Separator separator2 = new Separator("Separator 1", stream_32); @@ -87,10 +87,10 @@ public static void main(String args[]) { Compressor comp12 = new Compressor("comp22", stream_222); comp12.setOutletPressure(45.0); - Cooler cooler12 = new Cooler("cooler12", comp12.getOutStream()); + Cooler cooler12 = new Cooler("cooler12", comp12.getOutletStream()); cooler12.setOutTemperature(283.15 + 30); - Separator separator3 = new Separator("Separator 122", cooler12.getOutStream()); + Separator separator3 = new Separator("Separator 122", cooler12.getOutletStream()); Recycle resyc = new Recycle("resyc"); resyc.addStream(separator3.getLiquidOutStream()); diff --git a/src/test/java/neqsim/processSimulation/util/example/oxygenRemovalWater.java b/src/test/java/neqsim/processSimulation/util/example/oxygenRemovalWater.java index 7b36101a4b..6b75c72090 100644 --- a/src/test/java/neqsim/processSimulation/util/example/oxygenRemovalWater.java +++ b/src/test/java/neqsim/processSimulation/util/example/oxygenRemovalWater.java @@ -39,12 +39,12 @@ public static void main(String[] args) { mix.addStream(stream_air); // mix.addStream(stream_water); - Separator separator = new Separator("separator", mix.getOutStream()); + Separator separator = new Separator("separator", mix.getOutletStream()); Heater heater1 = new Heater("heater1", separator.getLiquidOutStream()); heater1.setOutTemperature(273.15 + 20); - ThrottlingValve LP_valve = new ThrottlingValve("LPventil", heater1.getOutStream()); + ThrottlingValve LP_valve = new ThrottlingValve("LPventil", heater1.getOutletStream()); LP_valve.setOutletPressure(30.0e-3); neqsim.processSimulation.processSystem.ProcessSystem operations = diff --git a/src/test/java/neqsim/processSimulation/util/example/process2.java b/src/test/java/neqsim/processSimulation/util/example/process2.java index 27e6515778..304d1116ac 100644 --- a/src/test/java/neqsim/processSimulation/util/example/process2.java +++ b/src/test/java/neqsim/processSimulation/util/example/process2.java @@ -39,9 +39,9 @@ public static void main(String args[]) { heater.setOutTemperature(310.0); MixerInterface mixer = new StaticMixer("Mixer 1"); - mixer.addStream(heater.getOutStream()); + mixer.addStream(heater.getOutletStream()); - StreamInterface stream_3 = mixer.getOutStream(); + StreamInterface stream_3 = mixer.getOutletStream(); stream_3.setName("stream3"); Separator separator = new Separator("Separator 1", stream_3); diff --git a/src/test/java/neqsim/processSimulation/util/example/propaneCoolingCycle.java b/src/test/java/neqsim/processSimulation/util/example/propaneCoolingCycle.java index 7067a4a088..d4292f91ed 100644 --- a/src/test/java/neqsim/processSimulation/util/example/propaneCoolingCycle.java +++ b/src/test/java/neqsim/processSimulation/util/example/propaneCoolingCycle.java @@ -38,15 +38,15 @@ public static void main(String args[]) { ThrottlingValve JTvalve = new ThrottlingValve("JTvalve", stream_1); JTvalve.setOutletPressure(1.11325); - Cooler cooler = new Cooler("cooler", JTvalve.getOutStream()); + Cooler cooler = new Cooler("cooler", JTvalve.getOutletStream()); // cooler.setPressureDrop(0.35); cooler.setSpecification("out stream"); - Stream stream_2 = new Stream("stream_2", cooler.getOutStream()); + Stream stream_2 = new Stream("stream_2", cooler.getOutletStream()); stream_2.setSpecification("dewP"); // stream_2.setTemperature(-40.0, "C"); - cooler.setOutStream(stream_2); + cooler.setOutletStream(stream_2); SetPoint setLPpressure = new SetPoint("set", JTvalve, "pressure", stream_2); @@ -56,10 +56,10 @@ public static void main(String args[]) { compressor1.setSpecification("out stream"); compressor1.setOutletPressure(stream_1.getPressure()); - Heater heater = new Heater("heater", compressor1.getOutStream()); + Heater heater = new Heater("heater", compressor1.getOutletStream()); heater.setPressureDrop(0.07); heater.setSpecification("out stream"); - heater.setOutStream(stream_1); + heater.setOutletStream(stream_1); neqsim.processSimulation.processSystem.ProcessSystem operations = new neqsim.processSimulation.processSystem.ProcessSystem(); @@ -83,7 +83,7 @@ public static void main(String args[]) { // operations.displayResult(); cooler.run(); - JTvalve.getOutStream().displayResult(); + JTvalve.getOutletStream().displayResult(); stream_2.displayResult(); System.out.println("compressor work" + compressor1.getEnergy() / 1.0e3 + " kW " diff --git a/src/test/java/neqsim/processSimulation/util/example/propaneMultiStageCoolingCycle.java b/src/test/java/neqsim/processSimulation/util/example/propaneMultiStageCoolingCycle.java index 9b167603b6..b8ce31f4e9 100644 --- a/src/test/java/neqsim/processSimulation/util/example/propaneMultiStageCoolingCycle.java +++ b/src/test/java/neqsim/processSimulation/util/example/propaneMultiStageCoolingCycle.java @@ -62,7 +62,7 @@ public static void main(String args[]) { JTvalve1.setOutletPressure(5.0); HeatExchanger heatEx1_et = new HeatExchanger("heatEx1_et", stream_Ethane); - heatEx1_et.setFeedStream(1, JTvalve1.getOutStream()); + heatEx1_et.setFeedStream(1, JTvalve1.getOutletStream()); heatEx1_et.setSpecification("out stream"); Stream stream_Ethane_out = new Stream("stream_Ethane_out", heatEx1_et.getOutStream(0)); @@ -88,7 +88,7 @@ public static void main(String args[]) { JTvalve2.setOutletPressure(1.5); HeatExchanger heatEx2 = new HeatExchanger("heatEx2", heatEx1.getOutStream(0)); - heatEx2.setFeedStream(1, JTvalve2.getOutStream()); + heatEx2.setFeedStream(1, JTvalve2.getOutletStream()); heatEx2.setSpecification("out stream"); // Cooler cooler = new Cooler(heatEx2.getOutStream(1)); @@ -103,7 +103,7 @@ public static void main(String args[]) { new Stream("coldGasFromPropaneCooler", heatEx2.getOutStream(0)); HeatExchanger heatEx22 = new HeatExchanger("heatEx22", heatEx2.getOutStream(0)); - heatEx22.setFeedStream(1, JTvalve1_et.getOutStream()); + heatEx22.setFeedStream(1, JTvalve1_et.getOutletStream()); heatEx22.setSpecification("out stream"); Stream stream_22 = new Stream("stream_22", heatEx22.getOutStream(1)); @@ -142,7 +142,7 @@ public static void main(String args[]) { coldGasFromPropaneCooler.displayResult(); heatEx22stream.getFluid().display(); - JTvalve2.getOutStream().getFluid().display(); + JTvalve2.getOutletStream().getFluid().display(); stream_22.getFluid().display(); // JTvalve1.displayResult(); diff --git a/src/test/java/neqsim/processSimulation/util/example/propaneTwoStageCoolingCycle.java b/src/test/java/neqsim/processSimulation/util/example/propaneTwoStageCoolingCycle.java index 55a4cd4158..34fd89b352 100644 --- a/src/test/java/neqsim/processSimulation/util/example/propaneTwoStageCoolingCycle.java +++ b/src/test/java/neqsim/processSimulation/util/example/propaneTwoStageCoolingCycle.java @@ -36,37 +36,37 @@ public static void main(String args[]) { ThrottlingValve JTvalve1 = new ThrottlingValve("JTvalve1", stream_1); JTvalve1.setOutletPressure(3.0); - Separator medPresSep = new Separator("medPresSep", JTvalve1.getOutStream()); + Separator medPresSep = new Separator("medPresSep", JTvalve1.getOutletStream()); ThrottlingValve JTvalve2 = new ThrottlingValve("JTvalve2", medPresSep.getLiquidOutStream()); JTvalve2.setOutletPressure(1.11325); - StreamInterface lowHStream = new Stream("lowHStream", JTvalve2.getOutStream()); + StreamInterface lowHStream = new Stream("lowHStream", JTvalve2.getOutletStream()); - Cooler cooler2 = new Cooler("cooler2", JTvalve2.getOutStream()); + Cooler cooler2 = new Cooler("cooler2", JTvalve2.getOutletStream()); // cooler2.setPressureDrop(0.35); cooler2.setSpecification("out stream"); - Stream stream_3 = new Stream("stream_3", cooler2.getOutStream()); + Stream stream_3 = new Stream("stream_3", cooler2.getOutletStream()); stream_3.setSpecification("dewP"); // stream_3.setTemperature(-40.0, "C"); - cooler2.setOutStream(stream_3); + cooler2.setOutletStream(stream_3); StreamInterface lowHStream2 = new Stream("lowHStream2", stream_3); Compressor compressor1 = new Compressor("compressor1", stream_3); compressor1.setOutletPressure(JTvalve1.getOutletPressure()); - Mixer propMixer = new Mixer(); - propMixer.addStream(compressor1.getOutStream()); + Mixer propMixer = new Mixer("propMixer"); + propMixer.addStream(compressor1.getOutletStream()); propMixer.addStream(medPresSep.getGasOutStream()); - Compressor compressor2 = new Compressor("compressor2", propMixer.getOutStream()); + Compressor compressor2 = new Compressor("compressor2", propMixer.getOutletStream()); compressor2.setOutletPressure(stream_1.getPressure()); - Heater cooler3 = new Heater("Heater", compressor2.getOutStream()); + Heater cooler3 = new Heater("Heater", compressor2.getOutletStream()); cooler3.setSpecification("out stream"); - cooler3.setOutStream(stream_1); + cooler3.setOutletStream(stream_1); neqsim.processSimulation.processSystem.ProcessSystem operations = new neqsim.processSimulation.processSystem.ProcessSystem(); @@ -91,7 +91,7 @@ public static void main(String args[]) { ThrottlingValve JTvalve3 = new ThrottlingValve("JTvalve3", medPresSep.getLiquidOutStream()); JTvalve3.setOutletPressure(2.03981146); JTvalve3.run(); - JTvalve3.getOutStream().displayResult(); + JTvalve3.getOutletStream().displayResult(); // JTvalve1.getOutStream().displayResult(); // JTvalve2.getOutStream().displayResult(); // medPresSep.displayResult(); @@ -120,12 +120,12 @@ public static void main(String args[]) { // System.out.println("compressor isentropic ef " + // compressor1.getIsentropicEfficiency()); System.out.println("cooler2 mass flow " - + cooler2.getOutStream().getFluid().getFlowRate("kg/hr") + " kg/hr"); + + cooler2.getOutletStream().getFluid().getFlowRate("kg/hr") + " kg/hr"); System.out.println("cooler3 mass flow " - + cooler3.getOutStream().getFluid().getFlowRate("kg/hr") + " kg/hr"); + + cooler3.getOutletStream().getFluid().getFlowRate("kg/hr") + " kg/hr"); System.out.println("delta enthalpy " + (stream_3.getFluid().getEnthalpy() - - JTvalve2.getOutStream().getFluid().getEnthalpy())); + - JTvalve2.getOutletStream().getFluid().getEnthalpy())); System.out.println("cooler2 duty " + cooler2.getEnergyInput() / 1.0e3 + " kW"); System.out.println("cooler3 duty " + cooler3.getEnergyInput() / 1.0e3 + " kW"); diff --git a/src/test/java/neqsim/processSimulation/util/example/simpleTopSideProcess.java b/src/test/java/neqsim/processSimulation/util/example/simpleTopSideProcess.java index 2cefd404a7..eb85cf345a 100644 --- a/src/test/java/neqsim/processSimulation/util/example/simpleTopSideProcess.java +++ b/src/test/java/neqsim/processSimulation/util/example/simpleTopSideProcess.java @@ -37,20 +37,20 @@ public static void main(String args[]) { Mixer mixerHP = new neqsim.processSimulation.processEquipment.mixer.StaticMixer("Mixer HP"); mixerHP.addStream(stream_1); - Separator separator = new Separator("Separator 1", mixerHP.getOutStream()); + Separator separator = new Separator("Separator 1", mixerHP.getOutletStream()); ThrottlingValve LP_valve = new ThrottlingValve("LPventil", separator.getLiquidOutStream()); LP_valve.setOutletPressure(5.0); - Separator LPseparator = new Separator("Separator 1", LP_valve.getOutStream()); + Separator LPseparator = new Separator("Separator 1", LP_valve.getOutletStream()); Compressor LPcompressor = new Compressor("LPcompressor", LPseparator.getGasOutStream()); LPcompressor.setOutletPressure(50.0); - Heater heaterLP = new Heater("heaterLP", LPcompressor.getOutStream()); + Heater heaterLP = new Heater("heaterLP", LPcompressor.getOutletStream()); heaterLP.setOutTemperature(270.25); - Stream stream_2 = new Stream("cooled gas", heaterLP.getOutStream()); + Stream stream_2 = new Stream("cooled gas", heaterLP.getOutletStream()); GasScrubberSimple gasScrubber = new GasScrubberSimple("Scrubber", stream_2); @@ -63,7 +63,7 @@ public static void main(String args[]) { mixer.addStream(separator.getGasOutStream()); mixer.addStream(gasScrubber.getGasOutStream()); - Compressor HPcompressor = new Compressor("HPcompressor", mixer.getOutStream()); + Compressor HPcompressor = new Compressor("HPcompressor", mixer.getOutletStream()); HPcompressor.setOutletPressure(200.0); neqsim.processSimulation.processSystem.ProcessSystem operations = diff --git a/src/test/java/neqsim/processSimulation/util/example/simpleTopSideProcess2.java b/src/test/java/neqsim/processSimulation/util/example/simpleTopSideProcess2.java index 595a0edba0..a25343fe69 100644 --- a/src/test/java/neqsim/processSimulation/util/example/simpleTopSideProcess2.java +++ b/src/test/java/neqsim/processSimulation/util/example/simpleTopSideProcess2.java @@ -32,7 +32,7 @@ public static void main(String args[]) { mixer_inlet.addStream(stream_inlet); ThreePhaseSeparator separator_inlet = - new ThreePhaseSeparator("Separator 1", mixer_inlet.getOutStream()); + new ThreePhaseSeparator("Separator 1", mixer_inlet.getOutletStream()); Stream stream_gasFromSep = new Stream("stream_gasFromSep", separator_inlet.getGasOutStream()); @@ -40,7 +40,7 @@ public static void main(String args[]) { Heater cooler1 = new Heater("cooler1", stream_gasFromSep); cooler1.setOutTemperature(285.25); - Separator scrubber = new Separator("Scrubber 1", cooler1.getOutStream()); + Separator scrubber = new Separator("Scrubber 1", cooler1.getOutletStream()); Recycle recyleOp = new Recycle("resyc"); recyleOp.addStream(scrubber.getLiquidOutStream()); diff --git a/src/test/java/neqsim/processSimulation/util/example/testGasScrubber.java b/src/test/java/neqsim/processSimulation/util/example/testGasScrubber.java index 507b867e82..1b1b59caba 100644 --- a/src/test/java/neqsim/processSimulation/util/example/testGasScrubber.java +++ b/src/test/java/neqsim/processSimulation/util/example/testGasScrubber.java @@ -57,7 +57,7 @@ public static void main(String args[]) { pipe.setDiameter(0.4); pipe.setLength(10); - StreamInterface stream_3 = pipe.getOutStream(); + StreamInterface stream_3 = pipe.getOutletStream(); neqsim.processSimulation.processSystem.ProcessSystem operations = new neqsim.processSimulation.processSystem.ProcessSystem(); diff --git a/src/test/java/neqsim/processSimulation/util/example/threePhaseSeparation.java b/src/test/java/neqsim/processSimulation/util/example/threePhaseSeparation.java index c1f7d41753..b17acb4281 100644 --- a/src/test/java/neqsim/processSimulation/util/example/threePhaseSeparation.java +++ b/src/test/java/neqsim/processSimulation/util/example/threePhaseSeparation.java @@ -73,11 +73,11 @@ public static void main(String args[]) { // waterRemoval.getOutStream(); MoleFractionControllerUtil TEGsaturator = - new MoleFractionControllerUtil(waterRemoval.getOutStream()); + new MoleFractionControllerUtil(waterRemoval.getOutletStream()); TEGsaturator.setMoleFraction("water", 5.0e-6); // TEGsaturator.getOutStream(); - ThrottlingValve LP_valve = new ThrottlingValve("LPventil", TEGsaturator.getOutStream()); + ThrottlingValve LP_valve = new ThrottlingValve("LPventil", TEGsaturator.getOutletStream()); LP_valve.setOutletPressure(5.0); // ThreePhaseSeparator separator2 = new ThreePhaseSeparator("Separator LP", diff --git a/src/test/java/neqsim/standards/gasQuality/Standard_ISO6976Test.java b/src/test/java/neqsim/standards/gasQuality/Standard_ISO6976Test.java index 2078df96d2..ca24eaab67 100644 --- a/src/test/java/neqsim/standards/gasQuality/Standard_ISO6976Test.java +++ b/src/test/java/neqsim/standards/gasQuality/Standard_ISO6976Test.java @@ -15,111 +15,159 @@ * @author ESOL * */ -class Standard_ISO6976Test extends neqsim.NeqSimTest{ - static SystemInterface testSystem = null; - /** - * @throws java.lang.Exception - */ - @BeforeAll - static void setUpBeforeClass() throws Exception { - testSystem = new SystemSrkEos(273.15 + 20.0, 1.0); - testSystem.addComponent("methane", 0.931819); - testSystem.addComponent("ethane", 0.025618); - testSystem.addComponent("nitrogen", 0.010335); - testSystem.addComponent("CO2", 0.015391); - testSystem.setMixingRule("classic"); - ThermodynamicOperations testOps = new ThermodynamicOperations(testSystem); - testOps.TPflash(); - } - - /** - * Test method for {@link neqsim.standards.gasQuality.Standard_ISO6976#calculate()}. - */ - @Test - void testCalculate() { - Standard_ISO6976 standard = new Standard_ISO6976(testSystem, 0, 15.55, "volume"); - standard.setReferenceState("real"); - standard.setReferenceType("volume"); - standard.calculate(); - double GCV = standard.getValue("GCV"); - double WI = standard.getValue("WI"); - assertEquals(39614.56783352743, GCV, 0.01); - assertEquals(44.61477915805513, WI, 0.01); - } - - @Test - void testCalculate2() { - SystemInterface testSystem = new SystemSrkEos(273.15 - 150.0, 1.0); - testSystem.addComponent("methane", 0.931819); - testSystem.addComponent("ethane", 0.025618); - testSystem.addComponent("nitrogen", 0.010335); - testSystem.addComponent("CO2", 0.015391); - - // ThermodynamicOperations testOps = new ThermodynamicOperations(testSystem); - /* - * testSystem.addComponent("methane", 0.922393); testSystem.addComponent("ethane", - * 0.025358); testSystem.addComponent("propane", 0.01519); - * testSystem.addComponent("n-butane", 0.000523); testSystem.addComponent("i-butane", - * 0.001512); testSystem.addComponent("n-pentane", 0.002846); - * testSystem.addComponent("i-pentane", 0.002832); testSystem.addComponent("22-dim-C3", - * 0.001015); testSystem.addComponent("n-hexane", 0.002865); - * testSystem.addComponent("nitrogen", 0.01023); testSystem.addComponent("CO2", 0.015236); - * - */ - - /* - * - * testSystem.addComponent("methane", 0.9247); testSystem.addComponent("ethane", 0.035); - * testSystem.addComponent("propane", 0.0098); testSystem.addComponent("n-butane", 0.0022); - * testSystem.addComponent("i-butane", 0.0034); testSystem.addComponent("n-pentane", - * 0.0006); testSystem.addComponent("nitrogen", 0.0175); testSystem.addComponent("CO2", - * 0.0068); - * - */ - - // testSystem.addComponent("water", 0.016837); - - /* - * testSystem.addComponent("n-hexane", 0.0); testSystem.addComponent("n-heptane", 0.0); - * testSystem.addComponent("n-octane", 0.0); testSystem.addComponent("n-nonane", 0.0); - * testSystem.addComponent("nC10", 0.0); - * - * testSystem.addComponent("CO2", 0.68); testSystem.addComponent("H2S", 0.0); - * testSystem.addComponent("water", 0.0); testSystem.addComponent("oxygen", 0.0); - * testSystem.addComponent("carbonmonoxide", 0.0); testSystem.addComponent("nitrogen", - * 1.75); - */ - // testSystem.addComponent("MEG", 1.75); - testSystem.createDatabase(true); - testSystem.setMixingRule(2); - - testSystem.init(0); - Standard_ISO6976 standard = new Standard_ISO6976(testSystem, 0, 15.55, "volume"); - standard.setReferenceState("real"); - standard.setReferenceType("volume"); - standard.calculate(); - Assertions.assertEquals(0.9974432506378011, standard.getValue("CompressionFactor")); - Assertions.assertEquals(39614.56783352743, standard.getValue("SuperiorCalorificValue")); - Assertions.assertEquals(35693.92161464964, standard.getValue("InferiorCalorificValue")); - Assertions.assertEquals(39614.56783352743, standard.getValue("GCV")); - - Assertions.assertEquals(51701.01275822569, standard.getValue("SuperiorWobbeIndex")); - Assertions.assertEquals(46584.17339159412, standard.getValue("InferiorWobbeIndex")); - - Assertions.assertEquals(0.5870995452263126, standard.getValue("RelativeDensity")); - Assertions.assertEquals(0.9974432506378011, standard.getValue("CompressionFactor")); - Assertions.assertEquals(16.972142879156355, standard.getValue("MolarMass")); - - //standard.display("test"); - /* - * StandardInterface standardUK = new UKspecifications_ICF_SI(testSystem); - * standardUK.calculate(); System.out.println("ICF " + - * standardUK.getValue("IncompleteCombustionFactor", "")); - * - * System.out.println("HID " + testSystem.getPhase(0).getComponent("methane").getHID(273.15 - * - 150.0)); System.out.println("Hres " + - * testSystem.getPhase(0).getComponent("methane").getHresTP(273.15 - 150.0)); - */ - } +class Standard_ISO6976Test extends neqsim.NeqSimTest { + static SystemInterface testSystem = null; + + /** + * @throws java.lang.Exception + */ + @BeforeAll + static void setUpBeforeClass() throws Exception { + testSystem = new SystemSrkEos(273.15 + 20.0, 1.0); + testSystem.addComponent("methane", 0.931819); + testSystem.addComponent("ethane", 0.025618); + testSystem.addComponent("nitrogen", 0.010335); + testSystem.addComponent("CO2", 0.015391); + testSystem.setMixingRule("classic"); + ThermodynamicOperations testOps = new ThermodynamicOperations(testSystem); + testOps.TPflash(); + } + + /** + * Test method for {@link neqsim.standards.gasQuality.Standard_ISO6976#calculate()}. + */ + @Test + void testCalculate() { + Standard_ISO6976 standard = new Standard_ISO6976(testSystem, 0, 15.55, "volume"); + standard.setReferenceState("real"); + standard.setReferenceType("volume"); + standard.calculate(); + double GCV = standard.getValue("GCV"); + double WI = standard.getValue("WI"); + assertEquals(39614.56783352743, GCV, 0.01); + assertEquals(44.61477915805513, WI, 0.01); + } + + /** + * Test method for {@link neqsim.standards.gasQuality.Standard_ISO6976#calculate()} if wrong + * reference state is gven. Valid reference states should be 0, 15 and 20 C and 15F (15.55C). If + * wrong reference state is given, the program should use standard conditions (15C). + */ + @Test + void testCalculateWithWrongReferenceState() { + double volumeReferenceState = 0; + double energyReferenceState = 15.55; + Standard_ISO6976 standard = + new Standard_ISO6976(testSystem, volumeReferenceState, energyReferenceState, "volume"); + standard.setReferenceState("real"); + standard.setReferenceType("volume"); + standard.calculate(); + double GCV = standard.getValue("GCV"); + double WI = standard.getValue("WI"); + assertEquals(39614.56783352743, GCV, 0.01); + energyReferenceState = 15.15; // example of wrong reference condition + volumeReferenceState = 1.15; // example of wrong volume reference condition + standard.setEnergyRefT(energyReferenceState); + standard.setVolRefT(volumeReferenceState); + standard.calculate(); + GCV = standard.getValue("GCV"); + assertEquals(37499.35392575905, GCV, 0.01); + } + + /** + * Test method for {@link neqsim.standards.gasQuality.Standard_ISO6976#calculate()}. + */ + @Test + void testCalculateWithPSeudo() { + SystemSrkEos testSystem = new SystemSrkEos(273.15 + 20.0, 1.0); + testSystem.addComponent("methane", 0.931819); + testSystem.addComponent("ethane", 0.025618); + testSystem.addComponent("nitrogen", 0.010335); + testSystem.addComponent("CO2", 0.015391); + testSystem.addTBPfraction("C10", 0.015391, 90.0 / 1000.0, 0.82); + testSystem.setMixingRule("classic"); + ThermodynamicOperations testOps = new ThermodynamicOperations(testSystem); + testOps.TPflash(); + Standard_ISO6976 standard = new Standard_ISO6976(testSystem, 0, 15.55, "volume"); + standard.setReferenceState("real"); + standard.setReferenceType("volume"); + standard.calculate(); + double GCV = standard.getValue("GCV"); + double WI = standard.getValue("WI"); + assertEquals(42377.76099372482, GCV, 0.01); + } + + @Test + void testCalculate2() { + SystemInterface testSystem = new SystemSrkEos(273.15 - 150.0, 1.0); + testSystem.addComponent("methane", 0.931819); + testSystem.addComponent("ethane", 0.025618); + testSystem.addComponent("nitrogen", 0.010335); + testSystem.addComponent("CO2", 0.015391); + + // ThermodynamicOperations testOps = new ThermodynamicOperations(testSystem); + /* + * testSystem.addComponent("methane", 0.922393); testSystem.addComponent("ethane", 0.025358); + * testSystem.addComponent("propane", 0.01519); testSystem.addComponent("n-butane", 0.000523); + * testSystem.addComponent("i-butane", 0.001512); testSystem.addComponent("n-pentane", + * 0.002846); testSystem.addComponent("i-pentane", 0.002832); + * testSystem.addComponent("22-dim-C3", 0.001015); testSystem.addComponent("n-hexane", + * 0.002865); testSystem.addComponent("nitrogen", 0.01023); testSystem.addComponent("CO2", + * 0.015236); + * + */ + + /* + * + * testSystem.addComponent("methane", 0.9247); testSystem.addComponent("ethane", 0.035); + * testSystem.addComponent("propane", 0.0098); testSystem.addComponent("n-butane", 0.0022); + * testSystem.addComponent("i-butane", 0.0034); testSystem.addComponent("n-pentane", 0.0006); + * testSystem.addComponent("nitrogen", 0.0175); testSystem.addComponent("CO2", 0.0068); + * + */ + + // testSystem.addComponent("water", 0.016837); + + /* + * testSystem.addComponent("n-hexane", 0.0); testSystem.addComponent("n-heptane", 0.0); + * testSystem.addComponent("n-octane", 0.0); testSystem.addComponent("n-nonane", 0.0); + * testSystem.addComponent("nC10", 0.0); + * + * testSystem.addComponent("CO2", 0.68); testSystem.addComponent("H2S", 0.0); + * testSystem.addComponent("water", 0.0); testSystem.addComponent("oxygen", 0.0); + * testSystem.addComponent("carbonmonoxide", 0.0); testSystem.addComponent("nitrogen", 1.75); + */ + // testSystem.addComponent("MEG", 1.75); + testSystem.createDatabase(true); + testSystem.setMixingRule(2); + + testSystem.init(0); + Standard_ISO6976 standard = new Standard_ISO6976(testSystem, 0, 15.55, "volume"); + standard.setReferenceState("real"); + standard.setReferenceType("volume"); + standard.calculate(); + Assertions.assertEquals(0.9974432506378011, standard.getValue("CompressionFactor")); + Assertions.assertEquals(39614.56783352743, standard.getValue("SuperiorCalorificValue")); + Assertions.assertEquals(35693.92161464964, standard.getValue("InferiorCalorificValue")); + Assertions.assertEquals(39614.56783352743, standard.getValue("GCV")); + + Assertions.assertEquals(51701.01275822569, standard.getValue("SuperiorWobbeIndex")); + Assertions.assertEquals(46584.17339159412, standard.getValue("InferiorWobbeIndex")); + + Assertions.assertEquals(0.5870995452263126, standard.getValue("RelativeDensity")); + Assertions.assertEquals(0.9974432506378011, standard.getValue("CompressionFactor")); + Assertions.assertEquals(16.972142879156355, standard.getValue("MolarMass")); + + // standard.display("test"); + /* + * StandardInterface standardUK = new UKspecifications_ICF_SI(testSystem); + * standardUK.calculate(); System.out.println("ICF " + + * standardUK.getValue("IncompleteCombustionFactor", "")); + * + * System.out.println("HID " + testSystem.getPhase(0).getComponent("methane").getHID(273.15 - + * 150.0)); System.out.println("Hres " + + * testSystem.getPhase(0).getComponent("methane").getHresTP(273.15 - 150.0)); + */ + } } diff --git a/src/test/java/neqsim/thermo/system/ModelBaseTest.java b/src/test/java/neqsim/thermo/system/ModelBaseTest.java index f6a98cd8dd..a9ae048a96 100644 --- a/src/test/java/neqsim/thermo/system/ModelBaseTest.java +++ b/src/test/java/neqsim/thermo/system/ModelBaseTest.java @@ -13,135 +13,135 @@ * @version $Id: $Id * @since 2.2.3 */ -public abstract class ModelBaseTest extends neqsim.NeqSimTest{ - static SystemInterface thermoSystem = null; - neqsim.thermo.ThermodynamicModelTest fugTest; +public abstract class ModelBaseTest extends neqsim.NeqSimTest { + public static SystemInterface thermoSystem = null; + neqsim.thermo.ThermodynamicModelTest fugTest; - /** - *

- * testInit0. - *

- */ - @Test - public void testInit0() { - try { - thermoSystem.init(0); - } catch (Exception success) { - fail("Error running init0"); - } + /** + *

+ * testInit0. + *

+ */ + @Test + public void testInit0() { + try { + thermoSystem.init(0); + } catch (Exception success) { + fail("Error running init0"); } + } - /** - *

- * testInit1. - *

- */ - @Test - public void testInit1() { - try { - thermoSystem.init(1); - } catch (Exception success) { - fail("Error running init1"); - } + /** + *

+ * testInit1. + *

+ */ + @Test + public void testInit1() { + try { + thermoSystem.init(1); + } catch (Exception success) { + fail("Error running init1"); } + } - /** - *

- * testActivity. - *

- */ - @Test - public void testActivity() { - thermoSystem.init(0); - thermoSystem.init(1); - double activ1 = thermoSystem.getPhase(1).getActivityCoefficient(0); - thermoSystem.init(0); - thermoSystem.init(1); - double activ2 = thermoSystem.getPhase(1).getActivityCoefficient(0); - assertTrue(Math.abs((activ1 - activ2)) < 1e-6); - } + /** + *

+ * testActivity. + *

+ */ + @Test + public void testActivity() { + thermoSystem.init(0); + thermoSystem.init(1); + double activ1 = thermoSystem.getPhase(1).getActivityCoefficient(0); + thermoSystem.init(0); + thermoSystem.init(1); + double activ2 = thermoSystem.getPhase(1).getActivityCoefficient(0); + assertTrue(Math.abs((activ1 - activ2)) < 1e-6); + } - /** - *

- * testVolume. - *

- */ - @Test - public void testVolume() { - thermoSystem.init(0); - thermoSystem.init(1); - double dens1 = thermoSystem.getPhase(0).getDensity(); - thermoSystem.init(0); - thermoSystem.init(1); - double dens2 = thermoSystem.getPhase(1).getDensity(); - assertTrue(dens2 > dens1); - } + /** + *

+ * testVolume. + *

+ */ + @Test + public void testVolume() { + thermoSystem.init(0); + thermoSystem.init(1); + double dens1 = thermoSystem.getPhase(0).getDensity(); + thermoSystem.init(0); + thermoSystem.init(1); + double dens2 = thermoSystem.getPhase(1).getDensity(); + assertTrue(dens2 > dens1); + } - /** - *

- * testGibbs. - *

- */ - @Test - public void testGibbs() { - thermoSystem.init(0); - thermoSystem.init(1); - double gibbs1 = thermoSystem.getPhase(0).getGibbsEnergy(); - thermoSystem.init(0); - thermoSystem.init(1); - double gibbs2 = thermoSystem.getPhase(1).getGibbsEnergy(); - assertTrue(gibbs2 < gibbs1); - } + /** + *

+ * testGibbs. + *

+ */ + @Test + public void testGibbs() { + thermoSystem.init(0); + thermoSystem.init(1); + double gibbs1 = thermoSystem.getPhase(0).getGibbsEnergy(); + thermoSystem.init(0); + thermoSystem.init(1); + double gibbs2 = thermoSystem.getPhase(1).getGibbsEnergy(); + assertTrue(gibbs2 < gibbs1); + } - /** - *

- * testFugasities. - *

- */ - @Test - public void testFugasities() { - thermoSystem.init(0); - thermoSystem.init(1); - fugTest = new neqsim.thermo.ThermodynamicModelTest(thermoSystem); - assertTrue(fugTest.checkFugacityCoefficients()); - } + /** + *

+ * testFugasities. + *

+ */ + @Test + public void testFugasities() { + thermoSystem.init(0); + thermoSystem.init(1); + fugTest = new neqsim.thermo.ThermodynamicModelTest(thermoSystem); + assertTrue(fugTest.checkFugacityCoefficients()); + } - /** - *

- * testFugasitiesdT. - *

- */ - @Test - public void testFugasitiesdT() { - thermoSystem.init(0); - thermoSystem.init(3); - fugTest = new neqsim.thermo.ThermodynamicModelTest(thermoSystem); - assertTrue(fugTest.checkFugacityCoefficientsDT()); - } + /** + *

+ * testFugasitiesdT. + *

+ */ + @Test + public void testFugasitiesdT() { + thermoSystem.init(0); + thermoSystem.init(3); + fugTest = new neqsim.thermo.ThermodynamicModelTest(thermoSystem); + assertTrue(fugTest.checkFugacityCoefficientsDT()); + } - /** - *

- * testFugasitiesdP. - *

- */ - @Test - public void testFugasitiesdP() { - thermoSystem.init(0); - thermoSystem.init(3); - fugTest = new neqsim.thermo.ThermodynamicModelTest(thermoSystem); - assertTrue(fugTest.checkFugacityCoefficientsDP()); - } + /** + *

+ * testFugasitiesdP. + *

+ */ + @Test + public void testFugasitiesdP() { + thermoSystem.init(0); + thermoSystem.init(3); + fugTest = new neqsim.thermo.ThermodynamicModelTest(thermoSystem); + assertTrue(fugTest.checkFugacityCoefficientsDP()); + } - /** - *

- * testFugasitiesdn. - *

- */ - @Test - public void testFugasitiesdn() { - thermoSystem.init(0); - thermoSystem.init(3); - fugTest = new neqsim.thermo.ThermodynamicModelTest(thermoSystem); - assertTrue(fugTest.checkFugacityCoefficientsDn()); - } + /** + *

+ * testFugasitiesdn. + *

+ */ + @Test + public void testFugasitiesdn() { + thermoSystem.init(0); + thermoSystem.init(3); + fugTest = new neqsim.thermo.ThermodynamicModelTest(thermoSystem); + assertTrue(fugTest.checkFugacityCoefficientsDn()); + } } diff --git a/src/test/java/neqsim/thermo/system/SystemPrEosTest.java b/src/test/java/neqsim/thermo/system/SystemPrEosTest.java index 63ff58f56e..8d30856733 100644 --- a/src/test/java/neqsim/thermo/system/SystemPrEosTest.java +++ b/src/test/java/neqsim/thermo/system/SystemPrEosTest.java @@ -2,11 +2,9 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertTrue; - import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; - import neqsim.thermodynamicOperations.ThermodynamicOperations; class SystemPrEoSTest extends neqsim.NeqSimTest{ @@ -41,6 +39,7 @@ public static void setUp() { @Test @DisplayName("test a TPflash2") public void testTPflash2() { + assertEquals(2, testSystem.getNumberOfPhases()); } diff --git a/src/test/java/neqsim/thermo/system/SystemThermoAddComponentTest.java b/src/test/java/neqsim/thermo/system/SystemThermoAddComponentTest.java index ae6c459dbe..7f5ffab634 100644 --- a/src/test/java/neqsim/thermo/system/SystemThermoAddComponentTest.java +++ b/src/test/java/neqsim/thermo/system/SystemThermoAddComponentTest.java @@ -20,7 +20,6 @@ void setup() { */ } - @Test void testAddComponent() { // Assure that System contains no components diff --git a/src/test/java/neqsim/thermo/system/SystemThermoSetMolarCompositionTest.java b/src/test/java/neqsim/thermo/system/SystemThermoSetMolarCompositionTest.java index 76eec2fa4a..3530ce5a2f 100644 --- a/src/test/java/neqsim/thermo/system/SystemThermoSetMolarCompositionTest.java +++ b/src/test/java/neqsim/thermo/system/SystemThermoSetMolarCompositionTest.java @@ -57,7 +57,7 @@ void testNoFlow() { sys.setMolarComposition(new double[] { 1, 1.5, 1.75 }); }); Assertions.assertEquals( - "neqsim.util.exception.InvalidInputException: Total flow can not be 0 when setting molar composition", + "neqsim.util.exception.InvalidInputException: SystemSrkEos:setMolarComposition - Input totalFlow must be larger than 0 (1e-100) when setting molar composition", thrown.getMessage()); } @@ -69,8 +69,8 @@ void testNoFlowPlus() { sys.setMolarCompositionPlus(new double[] { 1, 1.5, 1.75 }); }); Assertions.assertEquals( - "neqsim.util.exception.InvalidInputException: Total flow can not be 0 when setting molar composition", - thrown.getMessage()); + "neqsim.util.exception.InvalidInputException: SystemSrkEos:setMolarComposition - Input totalFlow must be larger than 0 (1e-100) when setting molar composition", + thrown.getMessage()); } @Test @@ -81,7 +81,7 @@ void testNoFlowPlusFluid() { sys.setMolarCompositionOfPlusFluid(new double[] { 1, 1.5, 1.75 }); }); Assertions.assertEquals( - "neqsim.util.exception.InvalidInputException: Total flow can not be 0 when setting molar composition", - thrown.getMessage()); + "neqsim.util.exception.InvalidInputException: SystemSrkEos:setMolarComposition - Input totalFlow must be larger than 0 (1e-100) when setting molar composition", + thrown.getMessage()); } } diff --git a/src/test/java/neqsim/thermo/system/SystemUMRCPAEoStest.java b/src/test/java/neqsim/thermo/system/SystemUMRCPAEoStest.java new file mode 100644 index 0000000000..920a9bbfbc --- /dev/null +++ b/src/test/java/neqsim/thermo/system/SystemUMRCPAEoStest.java @@ -0,0 +1,229 @@ +package neqsim.thermo.system; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import neqsim.thermodynamicOperations.ThermodynamicOperations; + +class SystemUMRCPAEoStest extends neqsim.NeqSimTest { + static neqsim.thermo.system.SystemInterface testSystem = null; + static neqsim.thermo.ThermodynamicModelTest testModel = null; + neqsim.thermo.ThermodynamicModelTest fugTest; + + /** + *

+ * setUp. + *

+ */ + @BeforeAll + public static void setUp() { + // testSystem = new neqsim.thermo.system.SystemUMRPRUMCEos(298.0, 10.0); + //testSystem = new neqsim.thermo.system.SystemSrkCPA(400.0, 500.0); + //testSystem = new neqsim.thermo.system.SystemSrkCPA(400.0, 500.0); + testSystem = new neqsim.thermo.system.SystemUMRCPAEoS(800, 110); + // testSystem = new neqsim.thermo.system.SystemSrkEos(298.0, 10.0); + //testSystem.addComponent("nitrogen", 1); + testSystem.addComponent("water", 1); + //testSystem.addComponent("CO2", 0.01); + //testSystem.addComponent("methane", 0.68); + //testSystem.addComponent("ethane", 0.1); + // testSystem.addComponent("n-heptane", 0.2); + // testSystem.setMixingRule("HV", "UNIFAC_UMRPRU"); + //testSystem.setMixingRule(1); + testModel = new neqsim.thermo.ThermodynamicModelTest(testSystem); + // testModel = new neqsim.thermo.ThermodynamicModelTest(testSystem); + ThermodynamicOperations testOps = new ThermodynamicOperations(testSystem); + testSystem.init(0); + testOps.TPflash(); + testSystem.init(3); + //testSystem.initProperties(); + // testSystem.i + } + + /** + *

+ * testFugasities. + *

+ */ + //@Test + public void testFugasities() { + testSystem.init(0); + testSystem.init(1); + fugTest = new neqsim.thermo.ThermodynamicModelTest(testSystem); + assertTrue(fugTest.checkFugacityCoefficients()); + + double fucoef = testSystem.getComponent(0).getLogFugacityCoefficient(); + + assertEquals(-0.002884922, fucoef, 1e-6); + + ThermodynamicOperations testOps = new ThermodynamicOperations(testSystem); + testOps.TPflash(); + testSystem.initProperties(); + double molvol = testSystem.getMolarVolume(); + + assertEquals(247.09909107115, molvol, 1e-2); + } + + /** + *

+ * testCompressibility. + *

+ */ + @Test + @DisplayName("test compressibility of gas phase") + public void testCompressibility() { + // testSystem = new neqsim.thermo.system.SystemPr(298.0, 10.0); + // testSystem = new SystemSrkEos(298.0, 10.0); + // testSystem = new neqsim.thermo.system.SystemUMRPRUMCEos(298.0, 10.0); + //testSystem = new neqsim.thermo.system.SystemSrkCPA(400, 500); + testSystem = new neqsim.thermo.system.SystemUMRCPAEoS(800, 110); + testSystem.addComponent("water", 1); + // testSystem.addComponent("CO2", 0.01); + //testSystem.addComponent("methane", 0.68); + //testSystem.addComponent("ethane", 0.1); + // testSystem.addComponent("n-heptane", 0.2); + //testSystem.setMixingRule(1); + testModel = new neqsim.thermo.ThermodynamicModelTest(testSystem); + // testModel = new neqsim.thermo.ThermodynamicModelTest(testSystem); + ThermodynamicOperations testOps = new ThermodynamicOperations(testSystem); + testSystem.init(0); + testOps.TPflash(); + testSystem.init(3); + testSystem.init(3); + System.out.println("molar volume gas+oil is " + testSystem.getMolarVolume()); + System.out.println("molar volume gas is " + testSystem.getPhase(0).getMolarVolume()); + System.out.println("fugacity of gas phase " + testSystem.getPhase(0).getFugacity(0)); + System.out.println("residual enthalpy of gas phase is " + testSystem.getPhase(0).getHresTP()); + System.out.println("isochoric heat capacity of gas phase is " + testSystem.getPhase(0).getCv("J/mol")); + System.out.println("isobaric heat capacity of gas phase is " + testSystem.getPhase(0).getCp("J/mol")); + System.out.println("internal energy of gas phase is " + testSystem.getPhase(0).getInternalEnergy()); + System.out.println("molar volume liquid is " + testSystem.getPhase(1).getMolarVolume()); + System.out.println("fugacity of gas phase " + testSystem.getPhase(1).getFugacity(0)); + System.out.println("enthalpy of gas phase is " + testSystem.getPhase(1).getEnthalpy("J/mol")); + System.out.println("isochoric heat capacity of gas phase is " + testSystem.getPhase(1).getCv("J/mol")); + //ThermodynamicOperations testOps = new ThermodynamicOperations(testSystem); + //testOps.TPflash(); + + // testSystem.initProperties(); + // assertEquals(0.9711401538454589, testSystem.getPhase(0).getZ(), 0.001); + } + + /** + *

+ * testTPflash2. + *

+ */ + @Disabled + @Test + @DisplayName("test a TPflash2") + public void testTPflash2() { + assertEquals(2, testSystem.getNumberOfPhases()); + } + + /** + *

+ * testTPflash. + *

+ */ + @Disabled + @Test + @DisplayName("test a TPflash of the fluid (should return two phases)") + public void testTPflash() { + assertEquals(2, testSystem.getNumberOfPhases()); + } + + /** + *

+ * testFugacityCoefficients. + *

+ */ + @Test + @DisplayName("test the fugacity coefficients calculated") + public void testFugacityCoefficients() { + assertTrue(testModel.checkFugacityCoefficients()); + + // System.out.println("molar volume liquid is " + testSystem.((PhasePrEosvolcor) + // phase).getFC()); + } + + /** + *

+ * checkFugacityCoefficientsDP. + *

+ */ + @Test + @DisplayName("test derivative of fugacity coefficients with respect to pressure") + public void checkFugacityCoefficientsDP() { + //testSystem.init(0); + //testSystem.init(3); + assertTrue(testModel.checkFugacityCoefficientsDP()); + } + + /** + *

+ * checkFugacityCoefficientsDT. + *

+ */ + + @Test + @DisplayName("test derivative of fugacity coefficients with respect to temperature") + public void checkFugacityCoefficientsDT() { + assertTrue(testModel.checkFugacityCoefficientsDT()); + } + + /** + *

+ * checkFugacityCoefficientsDn. + *

+ */ + //@Test + @DisplayName("test derivative of fugacity coefficients with respect to composition") + public void checkFugacityCoefficientsDn() { + assertTrue(testModel.checkFugacityCoefficientsDn()); + } + + /** + *

+ * checkFugacityCoefficientsDn2. + *

+ */ + //@Test + @DisplayName("test derivative of fugacity coefficients with respect to composition (2nd method)") + public void checkFugacityCoefficientsDn2() { + assertTrue(testModel.checkFugacityCoefficientsDn2()); + } + + /** + *

+ * checkPhaseEnvelope. + *

+ * + * @throws Exception + */ + // @Test + @DisplayName("calculate phase envelope using UMR") + public void checkPhaseEnvelope() throws Exception { + testSystem = new neqsim.thermo.system.SystemUMRPRUMCEos(298.0, 10.0); + testSystem.addComponent("methane", 0.9); + testSystem.addComponent("ethane", 0.1); + testSystem.addComponent("propane", 0.1); + testSystem.addComponent("i-butane", 0.1); + testSystem.addComponent("n-butane", 0.1); + testSystem.addComponent("n-pentane", 0.1); + testSystem.setMixingRule("HV", "UNIFAC_UMRPRU"); + testSystem.init(0); + ThermodynamicOperations testOps = new ThermodynamicOperations(testSystem); + try { + testOps.calcPTphaseEnvelope(); + System.out.println("Cricondenbar " + (testOps.get("cricondenbar")[0] - 273.15) + " " + + testOps.get("cricondenbar")[1]); + } catch (Exception e) { + assertTrue(false); + throw new Exception(e); + } + assertEquals(testOps.get("cricondenbar")[1], 130.686140727503, 0.02); + } +} diff --git a/src/test/java/neqsim/thermo/system/SystemUMRPRUMCEosNewTest.java b/src/test/java/neqsim/thermo/system/SystemUMRPRUMCEosNewTest.java index 4e58707d7f..8501bb81bb 100644 --- a/src/test/java/neqsim/thermo/system/SystemUMRPRUMCEosNewTest.java +++ b/src/test/java/neqsim/thermo/system/SystemUMRPRUMCEosNewTest.java @@ -3,160 +3,212 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertTrue; import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import neqsim.thermodynamicOperations.ThermodynamicOperations; -class SystemUMRPRUMCEosNewTest extends neqsim.NeqSimTest{ - static neqsim.thermo.system.SystemInterface testSystem = null; - static neqsim.thermo.ThermodynamicModelTest testModel = null; - - /** - *

- * setUp. - *

- */ - @BeforeAll - public static void setUp() { - testSystem = new neqsim.thermo.system.SystemUMRPRUMCEos(298.0, 10.0); - testSystem.addComponent("nitrogen", 0.01); - testSystem.addComponent("CO2", 0.01); - testSystem.addComponent("methane", 0.68); - testSystem.addComponent("ethane", 0.1); - testSystem.addComponent("n-heptane", 0.2); - testSystem.setMixingRule("HV", "UNIFAC_UMRPRU"); - testModel = new neqsim.thermo.ThermodynamicModelTest(testSystem); - ThermodynamicOperations testOps = new ThermodynamicOperations(testSystem); - testOps.TPflash(); - testSystem.initProperties(); - } +class SystemUMRPRUMCEosNewTest extends neqsim.NeqSimTest { + static neqsim.thermo.system.SystemInterface testSystem = null; + static neqsim.thermo.ThermodynamicModelTest testModel = null; + neqsim.thermo.ThermodynamicModelTest fugTest; - /** - *

- * testCompressibility. - *

- */ - @Test - @DisplayName("test compressibility of gas phase") - public void testCompressibility() { - testSystem = new neqsim.thermo.system.SystemUMRPRUMCEos(298.0, 10.0); - testSystem.addComponent("nitrogen", 0.01); - testSystem.addComponent("CO2", 0.01); - testSystem.addComponent("methane", 0.68); - testSystem.addComponent("ethane", 0.1); - testSystem.addComponent("n-heptane", 0.2); - testSystem.setMixingRule("HV", "UNIFAC_UMRPRU"); - ThermodynamicOperations testOps = new ThermodynamicOperations(testSystem); - testOps.TPflash(); - testSystem.initProperties(); - assertEquals(testSystem.getPhase(0).getZ(), 0.9711401538454589, 0.001); - } + /** + *

+ * setUp. + *

+ */ + @BeforeAll + public static void setUp() { + // testSystem = new neqsim.thermo.system.SystemUMRPRUMCEos(298.0, 10.0); + testSystem = new neqsim.thermo.system.SystemUMRPRUMCEosNew(298.0, 10.0); + //testSystem = new neqsim.thermo.system.SystemSrkEos(298.0, 10.0); + testSystem.addComponent("nitrogen", 0.7); + //testSystem.addComponent("CO2", 0.01); + //testSystem.addComponent("methane", 0.68); + testSystem.addComponent("ethane", 0.3); + // testSystem.addComponent("n-heptane", 0.2); + // testSystem.setMixingRule("HV", "UNIFAC_UMRPRU"); + // testSystem.setMixingRule(1); + testSystem.setMixingRule(1); + testModel = new neqsim.thermo.ThermodynamicModelTest(testSystem); + // testModel = new neqsim.thermo.ThermodynamicModelTest(testSystem); + ThermodynamicOperations testOps = new ThermodynamicOperations(testSystem); + testOps.TPflash(); + testSystem.init(0); + testSystem.init(3); + //testSystem.initProperties(); + // testSystem.i + } - /** - *

- * testTPflash2. - *

- */ - @Test - @DisplayName("test a TPflash2") - public void testTPflash2() { - assertEquals(2, testSystem.getNumberOfPhases()); - } + /** + *

+ * testFugasities. + *

+ */ + // @Test + public void testFugasities() { + testSystem.init(0); + testSystem.init(1); + fugTest = new neqsim.thermo.ThermodynamicModelTest(testSystem); + assertTrue(fugTest.checkFugacityCoefficients()); - /** - *

- * testTPflash. - *

- */ - @Test - @DisplayName("test a TPflash of the fluid (should return two phases)") - public void testTPflash() { - assertEquals(2, testSystem.getNumberOfPhases()); - } + double fucoef = testSystem.getComponent(0).getLogFugacityCoefficient(); - /** - *

- * testFugacityCoefficients. - *

- */ - @Test - @DisplayName("test the fugacity coefficients calculated") - public void testFugacityCoefficients() { - assertTrue(testModel.checkFugacityCoefficients()); - } + assertEquals(-0.002884922, fucoef, 1e-6); - /** - *

- * checkFugacityCoefficientsDP. - *

- */ - @Test - @DisplayName("test derivative of fugacity coefficients with respect to pressure") - public void checkFugacityCoefficientsDP() { - assertTrue(testModel.checkFugacityCoefficientsDP()); - } + ThermodynamicOperations testOps = new ThermodynamicOperations(testSystem); + testOps.TPflash(); + testSystem.initProperties(); + double molvol = testSystem.getMolarVolume(); - /** - *

- * checkFugacityCoefficientsDT. - *

- */ - @Test - @DisplayName("test derivative of fugacity coefficients with respect to temperature") - public void checkFugacityCoefficientsDT() { - assertTrue(testModel.checkFugacityCoefficientsDT()); - } + assertEquals(247.09909107115, molvol, 1e-2); + } - /** - *

- * checkFugacityCoefficientsDn. - *

- */ - @Test - @DisplayName("test derivative of fugacity coefficients with respect to composition") - public void checkFugacityCoefficientsDn() { - assertTrue(testModel.checkFugacityCoefficientsDn()); - } + /** + *

+ * testCompressibility. + *

+ */ + @Test + @DisplayName("test compressibility of gas phase") + public void testCompressibility() { + // testSystem = new neqsim.thermo.system.SystemPr(298.0, 10.0); + // testSystem = new SystemSrkEos(298.0, 10.0); + // testSystem = new neqsim.thermo.system.SystemUMRPRUMCEos(298.0, 10.0); + testSystem = new neqsim.thermo.system.SystemUMRPRUMCEosNew(298, 10); + testSystem.addComponent("nitrogen", 0.7); + // testSystem.addComponent("CO2", 0.01); + //testSystem.addComponent("methane", 0.68); + testSystem.addComponent("ethane", 0.3); + // testSystem.addComponent("n-heptane", 0.2); + //testSystem.setMixingRule("HV", "UNIFAC_UMRPRU"); + testSystem.setMixingRule(0); + testSystem.init(0); + // testSystem.init(1); + testSystem.init(3); + System.out.println("molar volume gas+oil is " + testSystem.getMolarVolume()); + System.out.println("molar volume gas is " + testSystem.getPhase(0).getMolarVolume()); + System.out.println("molar volume liquid is " + testSystem.getPhase(1).getMolarVolume()); + // ThermodynamicOperations testOps = new ThermodynamicOperations(testSystem); + // testOps.TPflash(); - /** - *

- * checkFugacityCoefficientsDn2. - *

- */ - @Test - @DisplayName("test derivative of fugacity coefficients with respect to composition (2nd method)") - public void checkFugacityCoefficientsDn2() { - assertTrue(testModel.checkFugacityCoefficientsDn2()); - } + // testSystem.initProperties(); + // assertEquals(0.9711401538454589, testSystem.getPhase(0).getZ(), 0.001); + } + + /** + *

+ * testTPflash2. + *

+ */ + @Disabled + @Test + @DisplayName("test a TPflash2") + public void testTPflash2() { + assertEquals(2, testSystem.getNumberOfPhases()); + } + + /** + *

+ * testTPflash. + *

+ */ + @Disabled + @Test + @DisplayName("test a TPflash of the fluid (should return two phases)") + public void testTPflash() { + assertEquals(2, testSystem.getNumberOfPhases()); + } + + /** + *

+ * testFugacityCoefficients. + *

+ */ + @Test + @DisplayName("test the fugacity coefficients calculated") + public void testFugacityCoefficients() { + assertTrue(testModel.checkFugacityCoefficients()); + + // System.out.println("molar volume liquid is " + testSystem.((PhasePrEosvolcor) + // phase).getFC()); + } + + /** + *

+ * checkFugacityCoefficientsDP. + *

+ */ + @Test + @DisplayName("test derivative of fugacity coefficients with respect to pressure") + public void checkFugacityCoefficientsDP() { + + assertTrue(testModel.checkFugacityCoefficientsDP()); + } + + /** + *

+ * checkFugacityCoefficientsDT. + *

+ */ + + @Test + @DisplayName("test derivative of fugacity coefficients with respect to temperature") + public void checkFugacityCoefficientsDT() { + assertTrue(testModel.checkFugacityCoefficientsDT()); + } + + /** + *

+ * checkFugacityCoefficientsDn. + *

+ */ + @Test + @DisplayName("test derivative of fugacity coefficients with respect to composition") + public void checkFugacityCoefficientsDn() { + assertTrue(testModel.checkFugacityCoefficientsDn()); + } + + /** + *

+ * checkFugacityCoefficientsDn2. + *

+ */ + @Test + @DisplayName("test derivative of fugacity coefficients with respect to composition (2nd method)") + public void checkFugacityCoefficientsDn2() { + assertTrue(testModel.checkFugacityCoefficientsDn2()); + } - /** - *

- * checkPhaseEnvelope. - *

- * - * @throws Exception - */ - @Test - @DisplayName("calculate phase envelope using UMR") - public void checkPhaseEnvelope() throws Exception { - testSystem = new neqsim.thermo.system.SystemUMRPRUMCEos(298.0, 10.0); - testSystem.addComponent("methane", 0.9); - testSystem.addComponent("ethane", 0.1); - testSystem.addComponent("propane", 0.1); - testSystem.addComponent("i-butane", 0.1); - testSystem.addComponent("n-butane", 0.1); - testSystem.addComponent("n-pentane", 0.1); - testSystem.setMixingRule("HV", "UNIFAC_UMRPRU"); - testSystem.init(0); - ThermodynamicOperations testOps = new ThermodynamicOperations(testSystem); - try { - testOps.calcPTphaseEnvelope(); - System.out.println("Cricondenbar " + (testOps.get("cricondenbar")[0] - 273.15) + " " - + testOps.get("cricondenbar")[1]); - } catch (Exception e) { - assertTrue(false); - throw new Exception(e); - } - assertEquals(testOps.get("cricondenbar")[1], 130.686140727503, 0.02); + /** + *

+ * checkPhaseEnvelope. + *

+ * + * @throws Exception + */ + @Test + @DisplayName("calculate phase envelope using UMR") + public void checkPhaseEnvelope() throws Exception { + testSystem = new neqsim.thermo.system.SystemUMRPRUMCEos(298.0, 10.0); + testSystem.addComponent("methane", 0.9); + testSystem.addComponent("ethane", 0.1); + testSystem.addComponent("propane", 0.1); + testSystem.addComponent("i-butane", 0.1); + testSystem.addComponent("n-butane", 0.1); + testSystem.addComponent("n-pentane", 0.1); + testSystem.setMixingRule("HV", "UNIFAC_UMRPRU"); + testSystem.init(0); + ThermodynamicOperations testOps = new ThermodynamicOperations(testSystem); + try { + testOps.calcPTphaseEnvelope(); + System.out.println("Cricondenbar " + (testOps.get("cricondenbar")[0] - 273.15) + " " + + testOps.get("cricondenbar")[1]); + } catch (Exception e) { + assertTrue(false); + throw new Exception(e); } + assertEquals(testOps.get("cricondenbar")[1], 130.686140727503, 0.02); + } } diff --git a/src/test/java/neqsim/thermo/util/example/ActivityCalc.java b/src/test/java/neqsim/thermo/util/example/ActivityCalc.java index c3ffdcce77..a1c15e1d87 100644 --- a/src/test/java/neqsim/thermo/util/example/ActivityCalc.java +++ b/src/test/java/neqsim/thermo/util/example/ActivityCalc.java @@ -41,7 +41,7 @@ public static void main(String args[]) { } catch (Exception e) { } - testSystem.display(); + //testSystem.display(); System.out.println("activity water " + testSystem.getPhase(1).getActivityCoefficient(1)); } } diff --git a/src/test/java/neqsim/thermo/util/example/ModelTest.java b/src/test/java/neqsim/thermo/util/example/ModelTest.java index 5fe82cf82e..01c0cec9e5 100644 --- a/src/test/java/neqsim/thermo/util/example/ModelTest.java +++ b/src/test/java/neqsim/thermo/util/example/ModelTest.java @@ -3,7 +3,7 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import neqsim.thermo.system.SystemInterface; -import neqsim.thermo.system.SystemSrkCPAstatoil; +import neqsim.thermo.system.SystemSrkCPA; import neqsim.thermodynamicOperations.ThermodynamicOperations; /** @@ -24,8 +24,10 @@ public class ModelTest { public static void main(String args[]) { // SystemInterface testSystem = new SystemFurstElectrolyteEos(280.15,10.00); - // SystemInterface testSystem = new SystemSrkEos(298.15, 10.01325); - SystemInterface testSystem = new SystemSrkCPAstatoil(273.14 + 92, 42.0); + //SystemInterface testSystem = new SystemSrkEos(500, 1.0); + //SystemInterface testSystem = new SystemSrkCPAstatoil(273+150, 1.0); + SystemInterface testSystem = new SystemSrkCPA(273+150, 70); + //SystemInterface testSystem = new SystemSrkCPAs(273+150, 1.0); // SystemInterface testSystem = new SystemElectrolyteCPAstatoil(273.14 + 12, // 61.0); // SystemInterface testSystem = new SystemFurstElectrolyteEos(273.14 + 12, @@ -34,25 +36,25 @@ public static void main(String args[]) { // SystemInterface testSystem = new SystemSrkEos(298.15, 1.01325); ThermodynamicOperations testOps = new ThermodynamicOperations(testSystem); - testSystem.addComponent("methane", 100); - testSystem.addComponent("n-heptane", 1); - // testSystem.addComponent("water", 100); - // testSystem.addComponent("methane", 1); - // testSystem.addComponent("ethane", 1); - // testSystem.addComponent("TEG", 9); - // testSystem.addComponent("MEG", 3.1); + //testSystem.addComponent("methane", 100); + //testSystem.addComponent("n-heptane", 1); + testSystem.addComponent("water", 50); + //testSystem.addComponent("methane", 10); + //testSystem.addComponent("ethane", 15); + testSystem.addComponent("TEG", 9); + testSystem.addComponent("MEG", 50); // testSystem.addComponent("n-octane", 3.1); // testSystem.addComponent("Na+", 0.1); // testSystem.addComponent("Cl-", 0.1); // testSystem.addComponent("MEG", 2.1); - // testSystem.addComponent("methanol", 5.3); + testSystem.addComponent("methanol", 20); /// testSystem.addComponent("MEG", 5.3); // testSystem.addComponent("MEG", 10.0); // testSystem.addTBPfraction("C8", 10.1, 90.0 / 1000.0, 0.8); - testSystem.addComponent("MEG", 10.5); + //testSystem.addComponent("MEG", 10.5); // testSystem.createDatabase(true); // testSystem.useVolumeCorrection(true); - testSystem.setMixingRule(2); + testSystem.setMixingRule(10); // testSystem.setMixingRule("HV", "NRTL"); // testSystem.setMixingRule("HV", "UNIFAC_UMRPRU"); // testSystem.setMixingRule(9); @@ -63,7 +65,7 @@ public static void main(String args[]) { neqsim.thermo.ThermodynamicModelTest testModel = new neqsim.thermo.ThermodynamicModelTest(testSystem); testModel.runTest(); - testSystem.display(); + // testSystem.display(); testSystem.init(3); double cp = testSystem.getPhase(1).getCp(); diff --git a/src/test/java/neqsim/thermo/util/example/PressureLoadingCurve.java b/src/test/java/neqsim/thermo/util/example/PressureLoadingCurve.java index 9488fab173..f59e5e74c5 100644 --- a/src/test/java/neqsim/thermo/util/example/PressureLoadingCurve.java +++ b/src/test/java/neqsim/thermo/util/example/PressureLoadingCurve.java @@ -7,68 +7,68 @@ import neqsim.thermodynamicOperations.ThermodynamicOperations; /** - *

PressureLoadingCurve class.

+ *

+ * PressureLoadingCurve class. + *

* * @author asmund * @version $Id: $Id * @since 2.2.3 */ public class PressureLoadingCurve { - static Logger logger = LogManager.getLogger(PressureLoadingCurve.class); + static Logger logger = LogManager.getLogger(PressureLoadingCurve.class); - /** - * This method is just meant to test the thermo package. - * - * @param args an array of {@link java.lang.String} objects - */ - @SuppressWarnings("unused") - public static void main(String args[]) { - double[][] points; - SystemInterface testSystem = new SystemFurstElectrolyteEos((273.15 + 75.0), 1.3); + /** + * This method is just meant to test the thermo package. + * + * @param args an array of {@link java.lang.String} objects + */ + @SuppressWarnings("unused") + public static void main(String args[]) { + double[][] points; + SystemInterface testSystem = new SystemFurstElectrolyteEos((273.15 + 75.0), 1.3); - double loading = 0.65; - double molProsMDEA = 11.21; - testSystem.addComponent("CO2", loading * molProsMDEA); - testSystem.addComponent("water", 100.0 - molProsMDEA - loading * molProsMDEA); - testSystem.addComponent("MDEA", molProsMDEA); - // testSystem.addComponent("Piperazine", loading*molProsMDEA*0.1); - testSystem.chemicalReactionInit(); - testSystem.createDatabase(true); - testSystem.setMixingRule(4); - testSystem.init(0); - ThermodynamicOperations testOps = new ThermodynamicOperations(testSystem); - // testOps.calcPloadingCurve(); - long time = System.currentTimeMillis(); + double loading = 0.65; + double molProsMDEA = 11.21; + testSystem.addComponent("CO2", loading * molProsMDEA); + testSystem.addComponent("water", 100.0 - molProsMDEA - loading * molProsMDEA); + testSystem.addComponent("MDEA", molProsMDEA); + // testSystem.addComponent("Piperazine", loading*molProsMDEA*0.1); + testSystem.chemicalReactionInit(); + testSystem.createDatabase(true); + testSystem.setMixingRule(4); + testSystem.init(0); + ThermodynamicOperations testOps = new ThermodynamicOperations(testSystem); + // testOps.calcPloadingCurve(); + long time = System.currentTimeMillis(); - try { - testOps.bubblePointPressureFlash(true); - } catch (Exception e) { - logger.error(e.toString()); - } - logger.info("Time taken for benchmark flash = " + (System.currentTimeMillis() - time)); - testSystem.display(); - logger.info("pressure " + testSystem.getPressure()); - int reactionNumber = 0; - logger.info("K " + testSystem.getChemicalReactionOperations().getReactionList() - .getReaction(reactionNumber).calcK(testSystem, 1)); - logger.info("Kx " + testSystem.getChemicalReactionOperations().getReactionList() - .getReaction(reactionNumber).calcKx(testSystem, 1)); - logger.info("Kgamma " + testSystem.getChemicalReactionOperations().getReactionList() - .getReaction(reactionNumber).calcKgamma(testSystem, 1)); - testSystem.setPressure(100.0); - testSystem.getChemicalReactionOperations().solveChemEq(1); - logger.info("K " + testSystem.getChemicalReactionOperations().getReactionList() - .getReaction(reactionNumber).calcK(testSystem, 1)); - logger.info("Kx " + testSystem.getChemicalReactionOperations().getReactionList() - .getReaction(reactionNumber).calcKx(testSystem, 1)); - logger.info("Kgamma " + testSystem.getChemicalReactionOperations().getReactionList() - .getReaction(reactionNumber).calcKgamma(testSystem, 1)); - - testSystem.display(); - // thermo.ThermodynamicModelTest testModel = new - // thermo.ThermodynamicModelTest(testSystem); - // testModel.runTest(); - // write data to netcdf - // testOps.writeNetCDF("c:/testloading.nc"); + try { + testOps.bubblePointPressureFlash(true); + } catch (Exception e) { + logger.error(e.toString()); } + logger.info("Time taken for benchmark flash = " + (System.currentTimeMillis() - time)); + testSystem.display(); + logger.info("pressure " + testSystem.getPressure()); + int reactionNumber = 0; + logger.info("K " + testSystem.getChemicalReactionOperations().getReactionList() + .getReaction(reactionNumber).calcK(testSystem, 1)); + logger.info("Kx " + testSystem.getChemicalReactionOperations().getReactionList() + .getReaction(reactionNumber).calcKx(testSystem, 1)); + logger.info("Kgamma " + testSystem.getChemicalReactionOperations().getReactionList() + .getReaction(reactionNumber).calcKgamma(testSystem, 1)); + testSystem.setPressure(100.0); + testSystem.getChemicalReactionOperations().solveChemEq(1); + logger.info("K " + testSystem.getChemicalReactionOperations().getReactionList() + .getReaction(reactionNumber).calcK(testSystem, 1)); + logger.info("Kx " + testSystem.getChemicalReactionOperations().getReactionList() + .getReaction(reactionNumber).calcKx(testSystem, 1)); + logger.info("Kgamma " + testSystem.getChemicalReactionOperations().getReactionList() + .getReaction(reactionNumber).calcKgamma(testSystem, 1)); + + testSystem.display(); + // thermo.ThermodynamicModelTest testModel = new + // thermo.ThermodynamicModelTest(testSystem); + // testModel.runTest(); + } } diff --git a/src/test/java/neqsim/thermo/util/example/TestNeqSimBug.java b/src/test/java/neqsim/thermo/util/example/TestNeqSimBug.java index 5d70047559..e63abe50bd 100644 --- a/src/test/java/neqsim/thermo/util/example/TestNeqSimBug.java +++ b/src/test/java/neqsim/thermo/util/example/TestNeqSimBug.java @@ -1,7 +1,6 @@ package neqsim.thermo.util.example; import java.util.Arrays; -import neqsim.api.ioc.CalculationResult; import neqsim.thermo.system.SystemInterface; import neqsim.thermo.system.SystemSrkEos; import neqsim.thermodynamicOperations.ThermodynamicOperations; @@ -16,61 +15,53 @@ * @since 2.2.3 */ public class TestNeqSimBug { - /** - *

- * main. - *

- * - * @param args an array of {@link java.lang.String} objects - */ - public static void main(String[] args) { - - // double[] spec1 = {1.0}; // salt water Pressure - // double[] spec2 = { -39678.555}; // salt water Enthalpy + /** + *

+ * main. + *

+ * + * @param args an array of {@link java.lang.String} objects + */ + public static void main(String[] args) { - SystemInterface fluid = new SystemSrkEos(273.15 + 55.0, 10.0); - fluid.addComponent("water", 0.0386243104934692); - fluid.addComponent("nitrogen", 1.08263303991407E-05); - fluid.addComponent("CO2", 0.00019008457660675); - fluid.addComponent("methane", 0.00305547803640366); - fluid.addComponent("ethane", 0.00200786963105202); - fluid.addComponent("propane", 0.00389420658349991); - fluid.addComponent("i-butane", 0.00179276615381241); - fluid.addComponent("n-butane", 0.00255768150091171); - fluid.addComponent("i-pentane", 0.00205287128686905); - fluid.addComponent("n-pentane", 0.00117853358387947); - fluid.addTBPfraction("CHCmp_1", 0.000867870151996613, 0.0810000000000000, 0.72122997045517); - fluid.addTBPfraction("CHCmp_2", 0.048198757171630900, 0.0987799987792969, - 0.754330039024353); - fluid.addTBPfraction("CHCmp_3", 0.097208471298217800, 0.1412200012207030, 0.81659996509552); - fluid.addTBPfraction("CHCmp_4", 0.165174083709717000, 0.1857899932861330, - 0.861050009727478); - fluid.addTBPfraction("CHCmp_5", 0.279571933746338000, 0.2410899963378910, - 0.902539968490601); - fluid.addTBPfraction("CHCmp_6", 0.240494251251221000, 0.4045100097656250, - 0.955269992351531); - fluid.addTBPfraction("CHCmp_7", 0.113120021820068000, 0.9069699707031250, 1.0074599981308); + // double[] spec1 = {1.0}; // salt water Pressure + // double[] spec2 = { -39678.555}; // salt water Enthalpy - fluid.createDatabase(true); - fluid.setMixingRule(2); - fluid.useVolumeCorrection(true); - fluid.setMultiPhaseCheck(true); + SystemInterface fluid = new SystemSrkEos(273.15 + 55.0, 10.0); + fluid.addComponent("water", 0.0386243104934692); + fluid.addComponent("nitrogen", 1.08263303991407E-05); + fluid.addComponent("CO2", 0.00019008457660675); + fluid.addComponent("methane", 0.00305547803640366); + fluid.addComponent("ethane", 0.00200786963105202); + fluid.addComponent("propane", 0.00389420658349991); + fluid.addComponent("i-butane", 0.00179276615381241); + fluid.addComponent("n-butane", 0.00255768150091171); + fluid.addComponent("i-pentane", 0.00205287128686905); + fluid.addComponent("n-pentane", 0.00117853358387947); + fluid.addTBPfraction("CHCmp_1", 0.000867870151996613, 0.0810000000000000, 0.72122997045517); + fluid.addTBPfraction("CHCmp_2", 0.048198757171630900, 0.0987799987792969, 0.754330039024353); + fluid.addTBPfraction("CHCmp_3", 0.097208471298217800, 0.1412200012207030, 0.81659996509552); + fluid.addTBPfraction("CHCmp_4", 0.165174083709717000, 0.1857899932861330, 0.861050009727478); + fluid.addTBPfraction("CHCmp_5", 0.279571933746338000, 0.2410899963378910, 0.902539968490601); + fluid.addTBPfraction("CHCmp_6", 0.240494251251221000, 0.4045100097656250, 0.955269992351531); + fluid.addTBPfraction("CHCmp_7", 0.113120021820068000, 0.9069699707031250, 1.0074599981308); - ThermodynamicOperations fluidOps = new ThermodynamicOperations(fluid); + fluid.createDatabase(true); + fluid.setMixingRule(2); + fluid.useVolumeCorrection(true); + fluid.setMultiPhaseCheck(true); - double spec1 = 73.22862045673597; // grane Pressure - double spec2 = -62179.7247076579; // Enthalpy + ThermodynamicOperations fluidOps = new ThermodynamicOperations(fluid); - CalculationResult s = - fluidOps.propertyFlash(Arrays.asList(spec1), Arrays.asList(spec2), 3, null, null); + double spec1 = 73.22862045673597; // grane Pressure + double spec2 = -62179.7247076579; // Enthalpy - Double[][] prop = s.fluidProperties; + fluidOps.propertyFlash(Arrays.asList(spec1), Arrays.asList(spec2), 3, null, null); - - /* - * for (int t = 0; t < 1; t++) { fluid.setPressure(spec1[t]); fluidOps.PHflash(spec2[t], - * "J/mol"); // fluidOps.TPflash(); fluid.init(2); fluid.initPhysicalProperties(); - */ - fluid.display(); - } + /* + * for (int t = 0; t < 1; t++) { fluid.setPressure(spec1[t]); fluidOps.PHflash(spec2[t], + * "J/mol"); // fluidOps.TPflash(); fluid.init(2); fluid.initPhysicalProperties(); + */ + fluid.display(); + } } diff --git a/src/test/java/neqsim/thermodynamicOperations/flashOps/TPFlashTest.java b/src/test/java/neqsim/thermodynamicOperations/flashOps/TPFlashTest.java new file mode 100644 index 0000000000..6ce26e05b3 --- /dev/null +++ b/src/test/java/neqsim/thermodynamicOperations/flashOps/TPFlashTest.java @@ -0,0 +1,103 @@ +/** + * + */ +package neqsim.thermodynamicOperations.flashOps; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import neqsim.thermodynamicOperations.ThermodynamicOperations; + +/** + * @author ESOL + * + */ +class TPFlashTest { + + static neqsim.thermo.system.SystemInterface testSystem = null; + static ThermodynamicOperations testOps = null; + + /** + * @throws java.lang.Exception + */ + @BeforeEach + void setUp() throws Exception { + testSystem = new neqsim.thermo.system.SystemPrEos(243.15, 300.0); + testSystem.addComponent("nitrogen", 1.0); + testSystem.addComponent("methane", 90.0); + testSystem.addComponent("ethane", 2.0); + testSystem.addComponent("propane", 1.0); + testSystem.addComponent("i-butane", 1.0); + testSystem.addComponent("n-butane", 1.0); + testSystem.addComponent("i-pentane", 1.0); + testSystem.addComponent("n-pentane", 1.0); + testSystem.addComponent("n-hexane", 1.0); + testSystem.addComponent("nC10", 1.0); + testSystem.addComponent("water", 10.0); + testSystem.setMixingRule("classic"); + testSystem.setMultiPhaseCheck(true); + } + + void testRun() { + testSystem.setMultiPhaseCheck(true); + testSystem.setPressure(10.0, "bara"); + testSystem.setTemperature(25.0, "C"); + testOps = new ThermodynamicOperations(testSystem); + testOps.TPflash(); + testSystem.initProperties(); + assertEquals(-430041.49312169873, testSystem.getEnthalpy(), 1e-2); + } + + @Test + void testRun2() { + testSystem.setMultiPhaseCheck(false); + testSystem.setPressure(10.0, "bara"); + testSystem.setTemperature(25.0, "C"); + testOps = new ThermodynamicOperations(testSystem); + testOps.TPflash(); + testSystem.initProperties(); + assertEquals(-359394.2117634512, testSystem.getEnthalpy(), 1e-2); + } + + @Test + void testRun3() { + testSystem.setMultiPhaseCheck(false); + testSystem.setPressure(500.0, "bara"); + testSystem.setTemperature(15.0, "C"); + testOps = new ThermodynamicOperations(testSystem); + testOps.TPflash(); + testSystem.initProperties(); + assertEquals(-552568.2810227782, testSystem.getEnthalpy(), 1e-2); + } + + // @Test + void testRun4() { + testSystem.setMultiPhaseCheck(true); + testSystem.setPressure(500.0, "bara"); + testSystem.setTemperature(15.0, "C"); + testOps = new ThermodynamicOperations(testSystem); + testOps.TPflash(); + testSystem.initProperties(); + assertEquals(-936973.1969586421, testSystem.getEnthalpy(), 1e-2); + } + + @Test + void testRun5() { + neqsim.thermo.system.SystemInterface testSystem5 = + new neqsim.thermo.system.SystemUMRPRUMCEos(243.15, 300.0); + testSystem5.addComponent("methane", 4.16683e-1); + testSystem5.addComponent("ethane", 1.7522e-1); + testSystem5.addComponent("n-pentane", 3.58009e-1); + testSystem5.addComponent("nC16", 5.00888e-2); + testSystem5.setMixingRule("classic"); + testSystem5.setMultiPhaseCheck(true); + testSystem5.setPressure(90.03461693, "bara"); + testSystem5.setTemperature(293.15, "K"); + testSystem5.setTotalFlowRate(4.925e-07, "kg/sec"); + testOps = new ThermodynamicOperations(testSystem5); + testOps.TPflash(); + testSystem5.initProperties(); + double beta = testSystem5.getBeta(); + assertEquals(6.272876522701802E-7, beta, 1e-5); + } +} diff --git a/src/test/java/neqsim/thermodynamicOperations/flashOps/TPFlashTestWellFluid.java b/src/test/java/neqsim/thermodynamicOperations/flashOps/TPFlashTestWellFluid.java new file mode 100644 index 0000000000..3af1b0eeb1 --- /dev/null +++ b/src/test/java/neqsim/thermodynamicOperations/flashOps/TPFlashTestWellFluid.java @@ -0,0 +1,79 @@ +/** + * + */ +package neqsim.thermodynamicOperations.flashOps; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import neqsim.thermodynamicOperations.ThermodynamicOperations; + +/** + * @author ESOL + * + */ +class TPFlashTestWellFluid { + + static neqsim.thermo.system.SystemInterface wellFluid = null; + static ThermodynamicOperations testOps = null; + + /** + * @throws java.lang.Exception + */ + @BeforeEach + void setUp() throws Exception { + wellFluid = new neqsim.thermo.system.SystemSrkCPAstatoil(273.15 + 30.0, 65.00); + wellFluid.addComponent("oxygen", 0.0); + wellFluid.addComponent("H2S", 0.00008); + wellFluid.addComponent("nitrogen", 0.08); + wellFluid.addComponent("CO2", 3.56); + wellFluid.addComponent("methane", 87.36); + wellFluid.addComponent("ethane", 4.02); + wellFluid.addComponent("propane", 1.54); + wellFluid.addComponent("i-butane", 0.2); + wellFluid.addComponent("n-butane", 0.42); + wellFluid.addComponent("i-pentane", 0.15); + wellFluid.addComponent("n-pentane", 0.20); + + wellFluid.addTBPfraction("C6_Frigg", 0.24, 84.99 / 1000.0, 695.0 / 1000.0); + wellFluid.addTBPfraction("C7_Frigg", 0.34, 97.87 / 1000.0, 718.0 / 1000.0); + wellFluid.addTBPfraction("C8_Frigg", 0.33, 111.54 / 1000.0, 729.0 / 1000.0); + wellFluid.addTBPfraction("C9_Frigg", 0.19, 126.1 / 1000.0, 749.0 / 1000.0); + wellFluid.addTBPfraction("C10_Frigg", 0.15, 140.14 / 1000.0, 760.0 / 1000.0); + wellFluid.addTBPfraction("C11_Frigg", 0.69, 175.0 / 1000.0, 830.0 / 1000.0); + wellFluid.addTBPfraction("C12_Frigg", 0.5, 280.0 / 1000.0, 914.0 / 1000.0); + wellFluid.addTBPfraction("C13_Frigg", 0.103, 560.0 / 1000.0, 980.0 / 1000.0); + + wellFluid.addTBPfraction("C6_ML_WestCtrl", 0.0, 84.0 / 1000.0, 684.0 / 1000.0); + wellFluid.addTBPfraction("C7_ML_WestCtrl", 0.0, 97.9 / 1000.0, 742.0 / 1000.0); + wellFluid.addTBPfraction("C8_ML_WestCtrl", 0.0, 111.5 / 1000.0, 770.0 / 1000.0); + wellFluid.addTBPfraction("C9_ML_WestCtrl", 0.0, 126.1 / 1000.0, 790.0 / 1000.0); + wellFluid.addTBPfraction("C10_ML_WestCtrl", 0.0, 140.14 / 1000.0, 805.0 / 1000.0); + wellFluid.addTBPfraction("C11_ML_WestCtrl", 0.0, 175.0 / 1000.0, 815.0 / 1000.0); + wellFluid.addTBPfraction("C12_ML_WestCtrl", 0.0, 280.0 / 1000.0, 835.0 / 1000.0); + wellFluid.addTBPfraction("C13_ML_WestCtrl", 0.0, 450.0 / 1000.0, 850.0 / 1000.0); + wellFluid.addComponent("water", 12.01); + wellFluid.setMixingRule(10); + wellFluid.init(0); + wellFluid.setMultiPhaseCheck(true); + } + + @Test + void testTPflashComp1() { + testOps = new ThermodynamicOperations(wellFluid); + testOps.TPflash(); + } + + @Test + void testTPflashComp2() { + wellFluid.setTemperature(339.04); + wellFluid.setPressure(1.5); + wellFluid.setMolarComposition(new double[] {0.0, 4.76579e-6, 1.21459e-5, 1.3409e-3, 3.30439e-2, + 5.06e-3, 7.34e-3, 1.53e-3, 4.11e-3, 1.58e-3, 2.255e-3, 2.8779e-4, 8.58e-4, 8.73e-4, 8.5e-4, + 3.88e-3, 7.36e-2, 1.47e-1, 6.176e-2, 3.69e-2, 7.735e-3, 1.023e-2, 6.19e-3, 4.3e-3, 1.2e-2, + 8.96e-3, 1.539e-3, 5.9921e-1}); + testOps = new ThermodynamicOperations(wellFluid); + testOps.TPflash(); + assertEquals(1.4292538950216407, wellFluid.getPhase(0).getDensity(), 1e-5); + } +} diff --git a/src/test/java/neqsim/thermodynamicOperations/flashOps/TVFlashTest.java b/src/test/java/neqsim/thermodynamicOperations/flashOps/TVFlashTest.java new file mode 100644 index 0000000000..a396e02a5d --- /dev/null +++ b/src/test/java/neqsim/thermodynamicOperations/flashOps/TVFlashTest.java @@ -0,0 +1,72 @@ +/** + * + */ +package neqsim.thermodynamicOperations.flashOps; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import neqsim.thermodynamicOperations.ThermodynamicOperations; + +/** + * @author ESOL + * + */ +class TVFlashTest { + + static neqsim.thermo.system.SystemInterface testSystem = null; + static neqsim.thermo.system.SystemInterface testSystem2 = null; + static ThermodynamicOperations testOps = null; + + /** + * @throws java.lang.Exception + */ + @BeforeEach + void setUp() throws Exception { + testSystem = new neqsim.thermo.system.SystemUMRPRUMCEos(293.15, 0.1); + testSystem.addComponent("methane", 0.0); + testSystem.addComponent("ethane", 0.0); + testSystem.addComponent("n-pentane", 9E-1); + testSystem.addComponent("nC16", 1E-1); + testSystem.setMixingRule("classic"); + testOps = new ThermodynamicOperations(testSystem); + testOps.TPflash(); + testSystem.initProperties(); + testSystem.setTotalFlowRate(1.0, "kg/sec"); + testOps.TPflash(); + testSystem.initProperties(); + + testSystem2 = new neqsim.thermo.system.SystemUMRPRUMCEos(293.15, 0.1); + testSystem2.addComponent("methane", 8.5E-1); + testSystem2.addComponent("ethane", 1.5E-1); + testSystem2.addComponent("n-pentane", 0); + testSystem2.addComponent("nC16", 0); + testSystem2.setMixingRule("classic"); + ThermodynamicOperations testOps = new ThermodynamicOperations(testSystem2); + testOps.TPflash(); + testSystem2.initProperties(); + testSystem2.setTotalFlowRate(0.3, "kg/sec"); + testOps.TPflash(); + testSystem2.initProperties(); + } + + @Test + void testTVflash() { + double total_rig_volume = 0.998; + + for(int i=0;i<50;i++) { + testSystem.addFluid(testSystem2); + ThermodynamicOperations testOps = new ThermodynamicOperations(testSystem); + try { + testOps.TVflash(total_rig_volume, "m3"); + } + catch(Exception e) { + System.out.println("error iterations " + i); + e.printStackTrace(); + } + } + assertEquals(235263.80103781424, testSystem.getEnthalpy(), 1e-2); + } + + } + diff --git a/src/test/java/neqsim/thermodynamicOperations/flashOps/WaxFlashTest.java b/src/test/java/neqsim/thermodynamicOperations/flashOps/WaxFlashTest.java new file mode 100644 index 0000000000..f9b22040c6 --- /dev/null +++ b/src/test/java/neqsim/thermodynamicOperations/flashOps/WaxFlashTest.java @@ -0,0 +1,76 @@ +/** + * + */ +package neqsim.thermodynamicOperations.flashOps; + +import static org.junit.jupiter.api.Assertions.*; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; +import neqsim.thermo.system.SystemInterface; +import neqsim.thermo.system.SystemSrkEos; +import neqsim.thermodynamicOperations.ThermodynamicOperations; +import neqsim.util.database.NeqSimDataBase; + +/** + * @author ESOL + * + */ +class WaxFlashTest { + + static neqsim.thermo.system.SystemInterface testSystem = null; + static ThermodynamicOperations testOps = null; + + /** + * @throws java.lang.Exception + */ + @BeforeEach + void setUp() throws Exception { + NeqSimDataBase.setConnectionString("jdbc:derby:C:/Users/esol/OneDrive - Equinor/programming/neqsim/src/main/resources/data/neqsimtestdatabase"); + NeqSimDataBase.setCreateTemporaryTables(true); + + testSystem = new SystemSrkEos(273.0 + 30, 50.0); + testSystem.addComponent("CO2", 0.018); + testSystem.addComponent("nitrogen", 0.333); + testSystem.addComponent("methane", 96.702); + testSystem.addComponent("ethane", 1.773); + testSystem.addComponent("propane", 0.496); + testSystem.addComponent("i-butane", 0.099); + testSystem.addComponent("n-butane", 0.115); + testSystem.addComponent("i-pentane", 0.004); + testSystem.addComponent("n-pentane", 0.024); + testSystem.addComponent("n-heptane", 0.324); + testSystem.addPlusFraction("C9", 0.095, 207.0 / 1000.0, 0.8331); + testSystem.getCharacterization().characterisePlusFraction(); + testSystem.getWaxModel().addTBPWax(); + testSystem.createDatabase(true); + testSystem.setMixingRule(2); + testSystem.addSolidComplexPhase("wax"); + // testSystem.setSolidPhaseCheck("nC14"); + testSystem.setMultiphaseWaxCheck(true); + NeqSimDataBase.setConnectionString("jdbc:derby:classpath:data/neqsimthermodatabase"); + NeqSimDataBase.setCreateTemporaryTables(false); + //testSystem.display(); + } + + /** + * Test method for {@link neqsim.thermodynamicOperations.flashOps.PHFlash#run()}. + */ + @Test + @Disabled + void testRun() { + testOps = new ThermodynamicOperations(testSystem); + try { + testOps.calcWAT(); + testOps.TPflash(); + } catch (Exception e) { + e.printStackTrace(); + } + double waxVolumeFrac = 0; + if (testSystem.hasPhaseType("wax")) { + waxVolumeFrac = testSystem.getWtFraction(testSystem.getPhaseIndexOfPhase("wax")); + } + } + +}