From f635528101a2f36192a2ed81aed808f7ad0052ca Mon Sep 17 00:00:00 2001 From: Ian Bell Date: Wed, 7 Jan 2015 22:42:03 -0700 Subject: [PATCH 01/69] First attempt to integrate the sphinx docs into the binaries/release/unstable folder output; see #378 Signed-off-by: Ian Bell --- dev/buildbot/master/master.cfg | 32 ++++++++++++++++++++++++-------- dev/scripts/release.bsh | 10 +++++----- 2 files changed, 29 insertions(+), 13 deletions(-) diff --git a/dev/buildbot/master/master.cfg b/dev/buildbot/master/master.cfg index ed88d83d..91917f0d 100644 --- a/dev/buildbot/master/master.cfg +++ b/dev/buildbot/master/master.cfg @@ -231,19 +231,35 @@ def docActivateCmd(): @properties.renderer def fullBuildCommand(props): return ' '.join([docActivateCmd(), "python", "__init__.py", str(props.getProperty('fullBuild', default = False) or props.getProperty('branch') == 'release')]) + +@properties.renderer +def rsyncCommand(props): + """ + A renderable command that creates the rsync command to be run + """ + + # Some basic preparations, make sure the machine has passwordless SSH access to the server + # + server_uri = 'coolprop@coolprop.dreamhosters.com' + server_dir = '/home/coolprop/buildbot/server-master' + server_des = "{0}:{1}".format(server_uri, server_dir) + # + local_build_dir = 'Web/_build/html' + + if props.getProperty('branch') == 'release': + server_target_dir = '{0}/public_html/release/sphinx'.format(server_des) + elif props.getProperty('branch') == 'master': + server_target_dir = '{0}/public_html/binaries/sphinx'.format(server_des) + else: + server_target_dir = '{0}/public_html/unstable/sphinx'.format(server_des) + + return ' '.join([docActivateCmd(), 'rsync', '-a', '--stats', '{0}/ {1}'.format(local_build_dir,server_target_dir)]) # All what is needed to create the website, it makes sense to run the # nightly builds on the same machine. This avoids extra data transfer. def websiteFactory(platform, gitMode='incremental', fullBuild=False): if 'win' in platform.lower(): raise ValueError("The docs cannot be build on a Windows machine, we rely on rsync...") - # Some basic preparations, make sure the machine has passwordless SSH access to the server - server_uri = 'coolprop@coolprop.dreamhosters.com' - server_dir = '/home/coolprop/buildbot/server-master' - server_des = "{0}:{1}".format(server_uri,server_dir) - # - local_build_dir = 'Web/_build/html' - server_target_dir = '{0}/public_html/sphinx'.format(server_des) # # Create the factory to add the actions to factory = getBaseFactory(gitMode=gitMode) @@ -268,7 +284,7 @@ def websiteFactory(platform, gitMode='incremental', fullBuild=False): # Run sphinx website builder factory.addStep(ShellCommand(command=' '.join([docActivateCmd(), "make", "html"]), workdir= 'build/Web', haltOnFailure = True)) # Upload the generated files - factory.addStep(ShellCommand(command=' '.join([docActivateCmd(), 'rsync', '-a', '--stats', '{0}/ {1}'.format(local_build_dir,server_target_dir)]), haltOnFailure = True)) + factory.addStep(ShellCommand(command=rsyncCommand, haltOnFailure = True)) return factory diff --git a/dev/scripts/release.bsh b/dev/scripts/release.bsh index a9ac76e4..c0ccd305 100755 --- a/dev/scripts/release.bsh +++ b/dev/scripts/release.bsh @@ -56,15 +56,16 @@ BASEDIR="$HOME/buildbot/server-master/public_html" REPODIR="$HOME/src/CoolPropFull.git" TMPSDIR="$HOME/src/CoolProp.sources" SRCFOLDER="$BASEDIR/$BINFOLDER/source" -DOCFOLDER="sphinx" -DOC4FILES="4.2.5/coolpropv425docs.zip" -DOC4FOLDER="$DOCFOLDER/v4" # if [ "$2" == "release" ]; then DRYRUN=false else DRYRUN=true fi +DOCFOLDER="$BASEDIR/$BINFOLDER/sphinx" +DOC4FILES="4.2.5/coolpropv425docs.zip" +DOC4FOLDER="$DOCFOLDER/v4" + echo "DRYRUN = $DRYRUN" pushd ${BASEDIR} # Change the folder @@ -110,8 +111,7 @@ else printMessage "Zipping up the docs and moving them into the $BINFOLDER folder for staging" rm -f documentation.zip zip -rq documentation.zip $DOCFOLDER/* -x */$(basename $DOC4FOLDER)/* - mkdir -p "$BINFOLDER/docs" - cp documentation.zip "$BINFOLDER/docs" + cp documentation.zip "$DOCFOLDER/sphinx" echo "Uploading the python binaries to pypi" twine upload $BINFOLDER/Python/*.whl $BINFOLDER/Python/*.tar.gz fi From b528c610385bae686c8da148295a24b73551e41e Mon Sep 17 00:00:00 2001 From: Jorrit Wronski Date: Sun, 11 Jan 2015 21:22:47 +0100 Subject: [PATCH 02/69] Added correct viscosity reference fro pure water --- Web/fluid_properties/Incompressibles.bib | 15 ++++++++++++++- dev/incompressible_liquids/CPIncomp/PureFluids.py | 2 +- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/Web/fluid_properties/Incompressibles.bib b/Web/fluid_properties/Incompressibles.bib index cf9b362f..f9bdf761 100644 --- a/Web/fluid_properties/Incompressibles.bib +++ b/Web/fluid_properties/Incompressibles.bib @@ -27,6 +27,19 @@ Timestamp = {2014.09.17} } +@Article{Huber2009, + Title = {{New International Formulation for the Viscosity of H2O}}, + Author = {M.L. Huber and R.A. Perkins and A. Laesecke and D.G. Friend and J.V. Sengers and M.J Assael and I.M. Metaxa and E. Vogel and R. Mare{\v s} and K. Miyagawa}, + Journal = {J. Phys. Chem. Ref. Data}, + Year = {2009}, + Number = {2}, + Pages = {101-125}, + Volume = {38}, + + Owner = {Belli}, + Timestamp = {2013.04.08} +} + @Manual{Jones2001, Title = {{SciPy}: Open source scientific tools for {Python}}, Author = {Eric Jones and Travis Oliphant and Pearu Peterson and others}, @@ -56,7 +69,7 @@ Pages = {421--426}, Volume = {128}, - Doi = {0.1115/1.2175090}, + Doi = {10.1115/1.2175090}, Owner = {jowr}, Timestamp = {2014.12.16} } diff --git a/dev/incompressible_liquids/CPIncomp/PureFluids.py b/dev/incompressible_liquids/CPIncomp/PureFluids.py index 0946bdc0..b53a270d 100644 --- a/dev/incompressible_liquids/CPIncomp/PureFluids.py +++ b/dev/incompressible_liquids/CPIncomp/PureFluids.py @@ -585,7 +585,7 @@ class Water(PureData): self.TminPsat = np.min(self.temperature.data[~np.isnan(self.saturation_pressure.data)]) self.name = "Water" self.description = "Fit of the subcooled region of the full EOS from 1 bar to 100 bar" - self.reference = "Wagner2002, Transport properties from Huber et. al (2 papers)" + self.reference = "Wagner2002, Huber2009" self.reshapeAll() # Specific heat needs special coefficiencts # self.specific_heat.coeffs = np.zeros((5,7)) From fa2d50d99b88f899e4cc956655be75706aaa5615 Mon Sep 17 00:00:00 2001 From: Ian Bell Date: Sun, 11 Jan 2015 20:06:46 -0700 Subject: [PATCH 03/69] Version 5.0.6 release Signed-off-by: Ian Bell --- CMakeLists.txt | 2 +- Web/coolprop/changelog.rst | 24 ++++++++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 59631674..f4cd18ab 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -29,7 +29,7 @@ project(${project_name}) # Project version set (COOLPROP_VERSION_MAJOR 5) set (COOLPROP_VERSION_MINOR 0) -set (COOLPROP_VERSION_PATCH 6dev) +set (COOLPROP_VERSION_PATCH 6) set (COOLPROP_VERSION ${COOLPROP_VERSION_MAJOR}.${COOLPROP_VERSION_MINOR}.${COOLPROP_VERSION_PATCH}) ####################################### diff --git a/Web/coolprop/changelog.rst b/Web/coolprop/changelog.rst index 3c6203b4..9a017b32 100644 --- a/Web/coolprop/changelog.rst +++ b/Web/coolprop/changelog.rst @@ -1,6 +1,30 @@ Changelog for CoolProp ====================== +5.0.6 +----- + +New Features: + +* Mathematica wrapper finished + +Issues Closed: + +* `#396 `_ : Initialize fail for HEOS in mixture with Argon and CarbonDioxide (in Matlab) +* `#395 `_ : keyed_output and incompressibles +* `#394 `_ : Python list inputs +* `#391 `_ : release.bsh and source file +* `#390 `_ : Transport properties of water +* `#389 `_ : HAPropsSI("D", "T",273.15+20, "R", 0.8, "P", 101325) lead to an error +* `#384 `_ : Put the example.nb Mathematica file in the main folder +* `#383 `_ : When doing release, force a full build of the docs +* `#382 `_ : Fix up the mathematica docs +* `#379 `_ : After a release is done, delete the release folder +* `#378 `_ : Also integrate the sphinx docs into the binaries/release/unstable folder output +* `#377 `_ : Remove old mathematica files +* `#376 `_ : Add python to list of prerequisites for self-compilation in the docs +* `#329 `_ : Configure buildbot to send emails when we break things + 5.0.5 ----- From 02987937ef35acdcc59296e2592a91c9285bb5c0 Mon Sep 17 00:00:00 2001 From: Ian Bell Date: Sun, 11 Jan 2015 20:07:57 -0700 Subject: [PATCH 04/69] Clean up HAPropsSI Signed-off-by: Ian Bell --- src/HumidAirProp.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/HumidAirProp.cpp b/src/HumidAirProp.cpp index 3974cbe5..47c7c173 100644 --- a/src/HumidAirProp.cpp +++ b/src/HumidAirProp.cpp @@ -1212,7 +1212,8 @@ double HAPropsSI(const std::string &OutputName, const std::string &Input1Name, d // Add a check to make sure that Air and Water fluid states have been properly instantiated check_fluid_instantiation(); - int In1Type, In2Type, In3Type,iT,iW,iTdp,iRH,ip,Type1,Type2; + givens In1Type, In2Type, In3Type, Type1, Type2; + int iT,iW,iTdp,iRH,ip; double vals[3],p,T,RH,W,Tdp,psi_w,M_ha,v_bar,h_bar,s_bar,MainInputValue,SecondaryInputValue,T_guess; double Value1,Value2,W_guess; std::string MainInputName, SecondaryInputName, Name1, Name2; From d34881b28ca69630c8e9ef3464378b7f6336e1a2 Mon Sep 17 00:00:00 2001 From: Ian Bell Date: Sun, 11 Jan 2015 20:20:05 -0700 Subject: [PATCH 05/69] Disable testing with MATLAB Signed-off-by: Ian Bell --- CMakeLists.txt | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index f4cd18ab..8074af5d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -708,13 +708,13 @@ if (COOLPROP_MATLAB_SWIG_MODULE) install (FILES ${CMAKE_CURRENT_BINARY_DIR}/+CoolProp.7z DESTINATION ${CMAKE_INSTALL_PREFIX}/MATLAB) install (FILES ${CMAKE_CURRENT_BINARY_DIR}/SwigRef.m DESTINATION ${CMAKE_INSTALL_PREFIX}/MATLAB) install (TARGETS CoolPropMATLAB_wrap DESTINATION ${CMAKE_INSTALL_PREFIX}/MATLAB) - enable_testing() - add_custom_command(TARGET CoolPropMATLAB_wrap - POST_BUILD - COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_SOURCE_DIR}/wrappers/MATLAB/test.m ${CMAKE_CURRENT_BINARY_DIR}/.) - add_test(NAME MATLABtest - COMMAND $ENV{MATLAB_ROOT}/bin/matlab -r test -nojvm -nodesktop -nosplash - WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}") + #enable_testing() + #add_custom_command(TARGET CoolPropMATLAB_wrap + # POST_BUILD + # COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_SOURCE_DIR}/wrappers/MATLAB/test.m ${CMAKE_CURRENT_BINARY_DIR}/.) + #add_test(NAME MATLABtest + # COMMAND $ENV{MATLAB_ROOT}/bin/matlab -r test -nojvm -nodesktop -nosplash + # WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}") endif() if (COOLPROP_MATLAB_MODULE) From a63d20e843ed8ca71c9505b23635baf138fd94dc Mon Sep 17 00:00:00 2001 From: Ian Bell Date: Sun, 11 Jan 2015 20:34:42 -0700 Subject: [PATCH 06/69] Make the bin/MicrosoftExcel folder for Excel Signed-off-by: Ian Bell --- dev/buildbot/master/master.cfg | 1 + 1 file changed, 1 insertion(+) diff --git a/dev/buildbot/master/master.cfg b/dev/buildbot/master/master.cfg index 91917f0d..11e805b0 100644 --- a/dev/buildbot/master/master.cfg +++ b/dev/buildbot/master/master.cfg @@ -500,6 +500,7 @@ def excel_slave(gitMode = 'incremental'): # Create the factory to add the actions to factory = getBaseFactory(gitMode=gitMode) # + factory.addStep(MakeDirectory(dir='build/bin/MicrosoftExcel', haltOnFailure = True)) factory.addStep(MakeDirectory(dir=working_folder+'/32bitDLL', haltOnFailure = True)) factory.addStep(MakeDirectory(dir=working_folder+'/64bitDLL', haltOnFailure = True)) factory.addStep(RemoveDirectory(dir="build/install_root", haltOnFailure = True)) From b2473d80c8bc8e8e912cbf1863c62e12a1dab1d7 Mon Sep 17 00:00:00 2001 From: Jorrit Wronski Date: Mon, 12 Jan 2015 08:13:33 +0100 Subject: [PATCH 07/69] Somehow the SFUSER escaped from the release script. --- dev/scripts/release.bsh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/dev/scripts/release.bsh b/dev/scripts/release.bsh index c0ccd305..cf9ea12e 100755 --- a/dev/scripts/release.bsh +++ b/dev/scripts/release.bsh @@ -52,6 +52,8 @@ else exit 1 fi # +# +SFUSER="jorritw" # ibell or jorritw BASEDIR="$HOME/buildbot/server-master/public_html" REPODIR="$HOME/src/CoolPropFull.git" TMPSDIR="$HOME/src/CoolProp.sources" From b4339e89f1da2619b77b007bc56d985f10bf30c0 Mon Sep 17 00:00:00 2001 From: Jorrit Wronski Date: Mon, 12 Jan 2015 08:45:52 +0100 Subject: [PATCH 08/69] Fixed binary folder handling --- dev/scripts/release.bsh | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/dev/scripts/release.bsh b/dev/scripts/release.bsh index cf9ea12e..b5bac8c1 100755 --- a/dev/scripts/release.bsh +++ b/dev/scripts/release.bsh @@ -5,6 +5,7 @@ # # Things to remember when you make a new release: # +# * Force a new build on all buildbots from the release branch # * Run the script and check the logs # * Make a tag in your git software # * Update the default download on sourceforge to point to the new sources @@ -58,18 +59,19 @@ BASEDIR="$HOME/buildbot/server-master/public_html" REPODIR="$HOME/src/CoolPropFull.git" TMPSDIR="$HOME/src/CoolProp.sources" SRCFOLDER="$BASEDIR/$BINFOLDER/source" +DOCFOLDER="$BASEDIR/$BINFOLDER/sphinx" +DOC4FILES="4.2.5/coolpropv425docs.zip" +DOC4FOLDER="$DOCFOLDER/v4" +# # if [ "$2" == "release" ]; then DRYRUN=false else DRYRUN=true fi -DOCFOLDER="$BASEDIR/$BINFOLDER/sphinx" -DOC4FILES="4.2.5/coolpropv425docs.zip" -DOC4FOLDER="$DOCFOLDER/v4" - echo "DRYRUN = $DRYRUN" - +# +# pushd ${BASEDIR} # Change the folder if [ "$DRYRUN" != "false" ]; then printMessage "Dry run detected" @@ -99,7 +101,7 @@ else cd $(basename $TMPSDIR) popd rm -f "$BINFOLDER/README.rst.txt" - if [ "$CPVERSION" = "nightly" ]; then + if [ "$CPVERSION" == "nightly" ]; then RSYNC_OPTS="-a --no-perms -z --stats --delete" rm -rf "$BINFOLDER/docs" CPVERSION="$CPVERSION"/ #$(date +%F) @@ -131,9 +133,14 @@ if [ ${CPVERSION:0:7} != "nightly" ]; then printMessage "Publishing the docs on SourceForge" rsync $RSYNC_DRY_RUN $RSYNC_OPTS "$DOCFOLDER/" frs.sf.net-$SFUSER:/home/project-web/coolprop/htdocs fi +# +if [ "$BINFOLDER" == "release" ] && [ "$DRYRUN" != "false" ]; then + printMessage "Removing release directory" + rm -rf "$BINFOLDER/*" +else + printMessage "Not removing directory with binaries, either nightly or dryrun activated." +fi # Change back to where we came from popd -printMessage "Removing release directory" -rm -rf $BINFOLDER printMessage "All done, goodbye." exit 0 From fb4c75ea48200020a1c51316590e0fe4cdb07216 Mon Sep 17 00:00:00 2001 From: Jorrit Wronski Date: Mon, 12 Jan 2015 08:48:22 +0100 Subject: [PATCH 09/69] Added water reference to JSON file. --- dev/incompressible_liquids/json/Water.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dev/incompressible_liquids/json/Water.json b/dev/incompressible_liquids/json/Water.json index e5d0a49a..3c1ec516 100644 --- a/dev/incompressible_liquids/json/Water.json +++ b/dev/incompressible_liquids/json/Water.json @@ -51,7 +51,7 @@ "type": "notdefined" }, "name": "Water", - "reference": "Wagner2002, Transport properties from Huber et. al (2 papers)", + "reference": "Wagner2002, Huber2009", "saturation_pressure": { "coeffs": [ -3.863635e+03, From 038b0100bf26f6fc2dfc131e1d86b148245be3cf Mon Sep 17 00:00:00 2001 From: Jorrit Wronski Date: Mon, 12 Jan 2015 08:52:59 +0100 Subject: [PATCH 10/69] One more typo in the release script --- dev/scripts/release.bsh | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/dev/scripts/release.bsh b/dev/scripts/release.bsh index b5bac8c1..d51209c6 100755 --- a/dev/scripts/release.bsh +++ b/dev/scripts/release.bsh @@ -134,11 +134,10 @@ if [ ${CPVERSION:0:7} != "nightly" ]; then rsync $RSYNC_DRY_RUN $RSYNC_OPTS "$DOCFOLDER/" frs.sf.net-$SFUSER:/home/project-web/coolprop/htdocs fi # -if [ "$BINFOLDER" == "release" ] && [ "$DRYRUN" != "false" ]; then +if [[ ("$BINFOLDER" == "release") && ("$DRYRUN" == "false") ]]; then printMessage "Removing release directory" - rm -rf "$BINFOLDER/*" -else - printMessage "Not removing directory with binaries, either nightly or dryrun activated." + rm -rf "$BINFOLDER" + mkdir -p "$BINFOLDER" fi # Change back to where we came from popd From 36188fe37edcf9cd86619a2fca80ee4fc0cf73fc Mon Sep 17 00:00:00 2001 From: Ian Bell Date: Mon, 12 Jan 2015 18:22:51 -0700 Subject: [PATCH 11/69] Bump revision to 5.0.7dev Signed-off-by: Ian Bell --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 8074af5d..af9173a6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -29,7 +29,7 @@ project(${project_name}) # Project version set (COOLPROP_VERSION_MAJOR 5) set (COOLPROP_VERSION_MINOR 0) -set (COOLPROP_VERSION_PATCH 6) +set (COOLPROP_VERSION_PATCH 7dev) set (COOLPROP_VERSION ${COOLPROP_VERSION_MAJOR}.${COOLPROP_VERSION_MINOR}.${COOLPROP_VERSION_PATCH}) ####################################### From 658f467e263d0ced2c6a47da270674cc4cd2bb60 Mon Sep 17 00:00:00 2001 From: Ian Bell Date: Mon, 12 Jan 2015 19:20:17 -0700 Subject: [PATCH 12/69] More debug for fluid loading Signed-off-by: Ian Bell --- src/Backends/REFPROP/REFPROPMixtureBackend.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Backends/REFPROP/REFPROPMixtureBackend.cpp b/src/Backends/REFPROP/REFPROPMixtureBackend.cpp index f5354b9b..473ff319 100644 --- a/src/Backends/REFPROP/REFPROPMixtureBackend.cpp +++ b/src/Backends/REFPROP/REFPROPMixtureBackend.cpp @@ -432,10 +432,12 @@ void REFPROPMixtureBackend::set_REFPROP_fluids(const std::vector &f mole_fractions_liq.resize(N); mole_fractions_vap.resize(N); LoadedREFPROPRef = components_joined_raw; + if (get_debug_level() > 5){ std::cout << format("%s:%d: Successfully loaded REFPROP fluid: %s\n",__FILE__,__LINE__, components_joined.c_str()); } if (dbg_refprop) std::cout << format("%s:%d: Successfully loaded REFPROP fluid: %s\n",__FILE__,__LINE__, components_joined.c_str()); return; } else if (k < number_of_endings-1){ // Keep going + if (get_debug_level() > 5){std::cout << "REFPROP error/warning:" << herr << std::endl;} continue; } else From 6d004a90a82016ffb7cb99a5aad3744c1f23ddd1 Mon Sep 17 00:00:00 2001 From: Ian Bell Date: Mon, 12 Jan 2015 19:35:54 -0700 Subject: [PATCH 13/69] Fixed bug in REFPROP debug output Signed-off-by: Ian Bell --- src/Backends/REFPROP/REFPROPMixtureBackend.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/Backends/REFPROP/REFPROPMixtureBackend.cpp b/src/Backends/REFPROP/REFPROPMixtureBackend.cpp index 473ff319..99f8f4ce 100644 --- a/src/Backends/REFPROP/REFPROPMixtureBackend.cpp +++ b/src/Backends/REFPROP/REFPROPMixtureBackend.cpp @@ -51,6 +51,7 @@ enum DLLNameManglingStyle{ NO_NAME_MANGLING = 0, LOWERCASE_NAME_MANGLING, LOWERC #include "REFPROPMixtureBackend.h" #include "Exceptions.h" #include "Configuration.h" +#include "CoolProp.h" #include #include @@ -432,17 +433,17 @@ void REFPROPMixtureBackend::set_REFPROP_fluids(const std::vector &f mole_fractions_liq.resize(N); mole_fractions_vap.resize(N); LoadedREFPROPRef = components_joined_raw; - if (get_debug_level() > 5){ std::cout << format("%s:%d: Successfully loaded REFPROP fluid: %s\n",__FILE__,__LINE__, components_joined.c_str()); } + if (CoolProp::get_debug_level() > 5){ std::cout << format("%s:%d: Successfully loaded REFPROP fluid: %s\n",__FILE__,__LINE__, components_joined.c_str()); } if (dbg_refprop) std::cout << format("%s:%d: Successfully loaded REFPROP fluid: %s\n",__FILE__,__LINE__, components_joined.c_str()); return; } else if (k < number_of_endings-1){ // Keep going - if (get_debug_level() > 5){std::cout << "REFPROP error/warning:" << herr << std::endl;} + if (CoolProp::get_debug_level() > 5){std::cout << "REFPROP error/warning:" << herr << std::endl;} continue; } else { - throw ValueError(format("Could not load these fluids: %s; error: %s", components_joined_raw.c_str(), herr)); + throw ValueError(format("Could not load these fluids: %s", components_joined_raw.c_str())); } } } From d1ca808ca7170c26693f74402c98b60263e6b752 Mon Sep 17 00:00:00 2001 From: Ian Bell Date: Tue, 13 Jan 2015 04:55:40 +0100 Subject: [PATCH 14/69] Fixed weird bug with long<0 in REFPROP wrapper; Closes #401 --- .../REFPROP/REFPROPMixtureBackend.cpp | 57 ++++++++++--------- 1 file changed, 29 insertions(+), 28 deletions(-) diff --git a/src/Backends/REFPROP/REFPROPMixtureBackend.cpp b/src/Backends/REFPROP/REFPROPMixtureBackend.cpp index 99f8f4ce..5ee4d66e 100644 --- a/src/Backends/REFPROP/REFPROPMixtureBackend.cpp +++ b/src/Backends/REFPROP/REFPROPMixtureBackend.cpp @@ -426,7 +426,7 @@ void REFPROPMixtureBackend::set_REFPROP_fluids(const std::vector &f errormessagelength // Length of error message ); - if (ierr <= 0) // Success (or a warning, which is silently squelched for now) + if (static_cast(ierr) <= 0) // Success (or a warning, which is silently squelched for now) { this->Ncomp = N; mole_fractions.resize(N); @@ -438,11 +438,12 @@ void REFPROPMixtureBackend::set_REFPROP_fluids(const std::vector &f return; } else if (k < number_of_endings-1){ // Keep going - if (CoolProp::get_debug_level() > 5){std::cout << "REFPROP error/warning:" << herr << std::endl;} + if (CoolProp::get_debug_level() > 5){std::cout << format("REFPROP error/warning [ierr: %d]: %s",ierr, herr) << std::endl;} continue; } else { + if (CoolProp::get_debug_level() > 5){std::cout << format("k: %d #endings: %d", k, number_of_endings) << std::endl;} throw ValueError(format("Could not load these fluids: %s", components_joined_raw.c_str())); } } @@ -517,21 +518,21 @@ long double REFPROPMixtureBackend::calc_T_critical(){ char herr[255]; double Tcrit, pcrit_kPa, dcrit_mol_L; CRITPdll(&(mole_fractions[0]),&Tcrit,&pcrit_kPa,&dcrit_mol_L,&ierr,herr,255); - if (ierr > 0) { throw ValueError(format("%s",herr).c_str()); } //else if (ierr < 0) {set_warning(format("%s",herr).c_str());} + if (static_cast(ierr) > 0) { throw ValueError(format("%s",herr).c_str()); } //else if (ierr < 0) {set_warning(format("%s",herr).c_str());} return static_cast(Tcrit); }; long double REFPROPMixtureBackend::calc_p_critical(){ long ierr = 0; char herr[255]; double Tcrit, pcrit_kPa, dcrit_mol_L; - CRITPdll(&(mole_fractions[0]),&Tcrit,&pcrit_kPa,&dcrit_mol_L,&ierr,herr,255); if (ierr > 0) { throw ValueError(format("%s",herr).c_str()); } //else if (ierr < 0) {set_warning(format("%s",herr).c_str());} + CRITPdll(&(mole_fractions[0]),&Tcrit,&pcrit_kPa,&dcrit_mol_L,&ierr,herr,255); if (static_cast(ierr) > 0) { throw ValueError(format("%s",herr).c_str()); } //else if (ierr < 0) {set_warning(format("%s",herr).c_str());} return static_cast(pcrit_kPa*1000); }; long double REFPROPMixtureBackend::calc_rhomolar_critical(){ long ierr = 0; char herr[255]; double Tcrit, pcrit_kPa, dcrit_mol_L; - CRITPdll(&(mole_fractions[0]),&Tcrit,&pcrit_kPa,&dcrit_mol_L,&ierr,herr,255); if (ierr > 0) { throw ValueError(format("%s",herr).c_str()); } //else if (ierr < 0) {set_warning(format("%s",herr).c_str());} + CRITPdll(&(mole_fractions[0]),&Tcrit,&pcrit_kPa,&dcrit_mol_L,&ierr,herr,255); if (static_cast(ierr) > 0) { throw ValueError(format("%s",herr).c_str()); } //else if (ierr < 0) {set_warning(format("%s",herr).c_str());} return static_cast(dcrit_mol_L*1000); }; long double REFPROPMixtureBackend::calc_T_reducing(){ @@ -575,7 +576,7 @@ double REFPROPMixtureBackend::calc_melt_Tmax() MELTPdll(&pmax_kPa, &(mole_fractions[0]), &Tmax_melt, &ierr,herr,errormessagelength); // Error message - if (ierr > 0) { throw ValueError(format("%s",herr).c_str()); } + if (static_cast(ierr) > 0) { throw ValueError(format("%s",herr).c_str()); } //else if (ierr < 0) {set_warning(format("%s",herr).c_str());} return Tmax_melt; } @@ -589,7 +590,7 @@ long double REFPROPMixtureBackend::calc_melting_line(int param, int given, long MELTTdll(&_T, &(mole_fractions[0]), &p_kPa, &ierr,herr,errormessagelength); // Error message - if (ierr > 0) { throw ValueError(format("%s",herr).c_str()); } //else if (ierr < 0) {set_warning(format("%s",herr).c_str());} + if (static_cast(ierr) > 0) { throw ValueError(format("%s",herr).c_str()); } //else if (ierr < 0) {set_warning(format("%s",herr).c_str());} return p_kPa*1000; } else if (param == iT && given == iP){ @@ -597,7 +598,7 @@ long double REFPROPMixtureBackend::calc_melting_line(int param, int given, long MELTPdll(&p_kPa, &(mole_fractions[0]), &_T, &ierr,herr,errormessagelength); // Error message - if (ierr > 0) { throw ValueError(format("%s",herr).c_str()); } //else if (ierr < 0) {set_warning(format("%s",herr).c_str());} + if (static_cast(ierr) > 0) { throw ValueError(format("%s",herr).c_str()); } //else if (ierr < 0) {set_warning(format("%s",herr).c_str());} return p_kPa*1000; } else{ @@ -619,7 +620,7 @@ long double REFPROPMixtureBackend::calc_viscosity(void) TRNPRPdll(&_T,&rhomol_L,&(mole_fractions[0]), // Inputs &eta,&tcx, // Outputs &ierr,herr,errormessagelength); // Error message - if (ierr > 0) { throw ValueError(format("%s",herr).c_str()); } + if (static_cast(ierr) > 0) { throw ValueError(format("%s",herr).c_str()); } //else if (ierr < 0) {set_warning(format("%s",herr).c_str());} _viscosity = 1e-6*eta; _conductivity = tcx; @@ -639,7 +640,7 @@ long double REFPROPMixtureBackend::calc_surface_tension(void) SURFTdll(&_T, &rho_mol_L, &(mole_fractions[0]), // Inputs &sigma, // Outputs &ierr, herr, errormessagelength); // Error message - if (ierr > 0) { throw ValueError(format("%s",herr).c_str()); } + if (static_cast(ierr) > 0) { throw ValueError(format("%s",herr).c_str()); } //else if (ierr < 0) {set_warning(format("%s",herr).c_str());} _surface_tension = sigma; return static_cast(_surface_tension); @@ -654,7 +655,7 @@ long double REFPROPMixtureBackend::calc_fugacity_coefficient(int i) FUGCOFdll(&_T, &rho_mol_L, &(mole_fractions[0]), // Inputs &(fug_cof[0]), // Outputs &ierr, herr, errormessagelength); // Error message - if (ierr > 0) { throw ValueError(format("%s",herr).c_str()); } + if (static_cast(ierr) > 0) { throw ValueError(format("%s",herr).c_str()); } //else if (ierr < 0) {set_warning(format("%s",herr).c_str());} return static_cast(fug_cof[i]); } @@ -665,7 +666,7 @@ void REFPROPMixtureBackend::calc_phase_envelope(const std::string &type) char herr[255]; SATSPLNdll(&(mole_fractions[0]), // Inputs &ierr, herr, errormessagelength); // Error message - if (ierr > 0) { throw ValueError(format("%s",herr).c_str()); } + if (static_cast(ierr) > 0) { throw ValueError(format("%s",herr).c_str()); } } long double REFPROPMixtureBackend::calc_cpmolar_idealgas(void) { @@ -704,7 +705,7 @@ void REFPROPMixtureBackend::update(CoolProp::input_pairs input_pair, double valu &rhoLmol_L,&rhoVmol_L,&(mole_fractions_liq[0]),&(mole_fractions[0]), // Saturation terms &q,&emol,&hmol,&smol,&cvmol,&cpmol,&w, &ierr,herr,errormessagelength); // - if (ierr > 0) { throw ValueError(format("PT: %s",herr).c_str()); }// TODO: else if (ierr < 0) {set_warning(format("%s",herr).c_str());} + if (static_cast(ierr) > 0) { throw ValueError(format("PT: %s",herr).c_str()); }// TODO: else if (ierr < 0) {set_warning(format("%s",herr).c_str());} // Set all cache values that can be set with unit conversion to SI _p = value1; @@ -726,7 +727,7 @@ void REFPROPMixtureBackend::update(CoolProp::input_pairs input_pair, double valu &rhoLmol_L,&rhoVmol_L,&(mole_fractions_liq[0]),&(mole_fractions_vap[0]), // Saturation terms &q,&emol,&hmol,&smol,&cvmol,&cpmol,&w, &ierr,herr,errormessagelength); - if (ierr > 0) { throw ValueError(format("DmolarT: %s",herr).c_str()); }// TODO: else if (ierr < 0) {set_warning(format("%s",herr).c_str());} + if (static_cast(ierr) > 0) { throw ValueError(format("DmolarT: %s",herr).c_str()); }// TODO: else if (ierr < 0) {set_warning(format("%s",herr).c_str());} // Set all cache values that can be set with unit conversion to SI _p = p_kPa*1000; @@ -755,7 +756,7 @@ void REFPROPMixtureBackend::update(CoolProp::input_pairs input_pair, double valu &rhoLmol_L,&rhoVmol_L,&(mole_fractions_liq[0]),&(mole_fractions_vap[0]), // Saturation terms &q,&emol,&hmol,&smol,&cvmol,&cpmol,&w, // Other thermodynamic terms &ierr,herr,errormessagelength); // Error terms - if (ierr > 0) { throw ValueError(format("DmolarP: %s",herr).c_str()); }// TODO: else if (ierr < 0) {set_warning(format("%s",herr).c_str());} + if (static_cast(ierr) > 0) { throw ValueError(format("DmolarP: %s",herr).c_str()); }// TODO: else if (ierr < 0) {set_warning(format("%s",herr).c_str());} // Set all cache values that can be set with unit conversion to SI _rhomolar = value1; @@ -785,7 +786,7 @@ void REFPROPMixtureBackend::update(CoolProp::input_pairs input_pair, double valu &rhoLmol_L,&rhoVmol_L,&(mole_fractions_liq[0]),&(mole_fractions_vap[0]), // Saturation terms &q,&emol,&smol,&cvmol,&cpmol,&w, &ierr,herr,errormessagelength); - if (ierr > 0) { throw ValueError(format("DmolarHmolar: %s",herr).c_str()); }// TODO: else if (ierr < 0) {set_warning(format("%s",herr).c_str());} + if (static_cast(ierr) > 0) { throw ValueError(format("DmolarHmolar: %s",herr).c_str()); }// TODO: else if (ierr < 0) {set_warning(format("%s",herr).c_str());} // Set all cache values that can be set with unit conversion to SI _p = p_kPa*1000; @@ -815,7 +816,7 @@ void REFPROPMixtureBackend::update(CoolProp::input_pairs input_pair, double valu &rhoLmol_L,&rhoVmol_L,&(mole_fractions_liq[0]),&(mole_fractions_vap[0]), // Saturation terms &q,&emol,&hmol,&cvmol,&cpmol,&w, &ierr,herr,errormessagelength); - if (ierr > 0) { throw ValueError(format("DmolarSmolar: %s",herr).c_str()); }// TODO: else if (ierr < 0) {set_warning(format("%s",herr).c_str());} + if (static_cast(ierr) > 0) { throw ValueError(format("DmolarSmolar: %s",herr).c_str()); }// TODO: else if (ierr < 0) {set_warning(format("%s",herr).c_str());} // Set all cache values that can be set with unit conversion to SI _p = p_kPa*1000; @@ -845,7 +846,7 @@ void REFPROPMixtureBackend::update(CoolProp::input_pairs input_pair, double valu &rhoLmol_L,&rhoVmol_L,&(mole_fractions_liq[0]),&(mole_fractions_vap[0]), // Saturation terms &q,&hmol,&hmol,&cvmol,&cpmol,&w, &ierr,herr,errormessagelength); - if (ierr > 0) { throw ValueError(format("DmolarUmolar: %s",herr).c_str()); }// TODO: else if (ierr < 0) {set_warning(format("%s",herr).c_str());} + if (static_cast(ierr) > 0) { throw ValueError(format("DmolarUmolar: %s",herr).c_str()); }// TODO: else if (ierr < 0) {set_warning(format("%s",herr).c_str());} // Set all cache values that can be set with unit conversion to SI _p = p_kPa*1000; @@ -874,7 +875,7 @@ void REFPROPMixtureBackend::update(CoolProp::input_pairs input_pair, double valu &rhoLmol_L,&rhoVmol_L,&(mole_fractions_liq[0]),&(mole_fractions_vap[0]), // Saturation terms &q,&emol,&smol,&cvmol,&cpmol,&w, // Other thermodynamic terms &ierr,herr,errormessagelength); // Error terms - if (ierr > 0) { throw ValueError(format("HmolarPmolar: %s",herr).c_str()); }// TODO: else if (ierr < 0) {set_warning(format("%s",herr).c_str());} + if (static_cast(ierr) > 0) { throw ValueError(format("HmolarPmolar: %s",herr).c_str()); }// TODO: else if (ierr < 0) {set_warning(format("%s",herr).c_str());} // Set all cache values that can be set with unit conversion to SI _p = value2; @@ -904,7 +905,7 @@ void REFPROPMixtureBackend::update(CoolProp::input_pairs input_pair, double valu &q,&emol,&hmol,&cvmol,&cpmol,&w, // Other thermodynamic terms &ierr,herr,errormessagelength); // Error terms - if (ierr > 0) { throw ValueError(format("PSmolar: %s",herr).c_str()); }// TODO: else if (ierr < 0) {set_warning(format("%s",herr).c_str());} + if (static_cast(ierr) > 0) { throw ValueError(format("PSmolar: %s",herr).c_str()); }// TODO: else if (ierr < 0) {set_warning(format("%s",herr).c_str());} // Set all cache values that can be set with unit conversion to SI _p = value1; @@ -935,7 +936,7 @@ void REFPROPMixtureBackend::update(CoolProp::input_pairs input_pair, double valu &q,&hmol,&smol,&cvmol,&cpmol,&w, // Other thermodynamic terms &ierr,herr,errormessagelength); // Error terms - if (ierr > 0) { throw ValueError(format("PUmolar: %s",herr).c_str()); }// TODO: else if (ierr < 0) {set_warning(format("%s",herr).c_str());} + if (static_cast(ierr) > 0) { throw ValueError(format("PUmolar: %s",herr).c_str()); }// TODO: else if (ierr < 0) {set_warning(format("%s",herr).c_str());} // Set all cache values that can be set with unit conversion to SI _p = value1; @@ -964,7 +965,7 @@ void REFPROPMixtureBackend::update(CoolProp::input_pairs input_pair, double valu &q,&emol,&cvmol,&cpmol,&w, // Other thermodynamic terms &ierr,herr,errormessagelength); // Error terms - if (ierr > 0) { throw ValueError(format("HmolarSmolar: %s",herr).c_str()); }// TODO: else if (ierr < 0) {set_warning(format("%s",herr).c_str());} + if (static_cast(ierr) > 0) { throw ValueError(format("HmolarSmolar: %s",herr).c_str()); }// TODO: else if (ierr < 0) {set_warning(format("%s",herr).c_str());} // Set all cache values that can be set with unit conversion to SI _p = p_kPa*1000; // 1000 for conversion from kPa to Pa @@ -995,7 +996,7 @@ void REFPROPMixtureBackend::update(CoolProp::input_pairs input_pair, double valu &q,&smol,&cvmol,&cpmol,&w, // Other thermodynamic terms &ierr,herr,errormessagelength); // Error terms - if (ierr > 0) { throw ValueError(format("SmolarUmolar: %s",herr).c_str()); }// TODO: else if (ierr < 0) {set_warning(format("%s",herr).c_str());} + if (static_cast(ierr) > 0) { throw ValueError(format("SmolarUmolar: %s",herr).c_str()); }// TODO: else if (ierr < 0) {set_warning(format("%s",herr).c_str());} // Set all cache values that can be set with unit conversion to SI _p = p_kPa*1000; // 1000 for conversion from kPa to Pa @@ -1034,7 +1035,7 @@ void REFPROPMixtureBackend::update(CoolProp::input_pairs input_pair, double valu &q,&emol,&hmol,&cvmol,&cpmol,&w, // Other thermodynamic terms &ierr,herr,errormessagelength); // Error terms - if (ierr > 0) { throw ValueError(format("SmolarT: %s",herr).c_str()); }// TODO: else if (ierr < 0) {set_warning(format("%s",herr).c_str());} + if (static_cast(ierr) > 0) { throw ValueError(format("SmolarT: %s",herr).c_str()); }// TODO: else if (ierr < 0) {set_warning(format("%s",herr).c_str());} // Set all cache values that can be set with unit conversion to SI _p = p_kPa*1000; // 1000 for conversion from kPa to Pa @@ -1072,7 +1073,7 @@ void REFPROPMixtureBackend::update(CoolProp::input_pairs input_pair, double valu &q,&emol,&smol,&cvmol,&cpmol,&w, // Other thermodynamic terms &ierr,herr,errormessagelength); // Error terms - if (ierr > 0) { throw ValueError(format("HmolarT: %s",herr).c_str()); }// TODO: else if (ierr < 0) {set_warning(format("%s",herr).c_str());} + if (static_cast(ierr) > 0) { throw ValueError(format("HmolarT: %s",herr).c_str()); }// TODO: else if (ierr < 0) {set_warning(format("%s",herr).c_str());} // Set all cache values that can be set with unit conversion to SI _p = p_kPa*1000; // 1000 for conversion from kPa to Pa @@ -1110,7 +1111,7 @@ void REFPROPMixtureBackend::update(CoolProp::input_pairs input_pair, double valu &q,&hmol,&smol,&cvmol,&cpmol,&w, // Other thermodynamic terms &ierr,herr,errormessagelength); // Error terms - if (ierr > 0) { throw ValueError(format("TUmolar: %s",herr).c_str()); }// TODO: else if (ierr < 0) {set_warning(format("%s",herr).c_str());} + if (static_cast(ierr) > 0) { throw ValueError(format("TUmolar: %s",herr).c_str()); }// TODO: else if (ierr < 0) {set_warning(format("%s",herr).c_str());} // Set all cache values that can be set with unit conversion to SI _p = p_kPa*1000; // 1000 for conversion from kPa to Pa @@ -1148,7 +1149,7 @@ void REFPROPMixtureBackend::update(CoolProp::input_pairs input_pair, double valu &emol,&hmol,&smol,&cvmol,&cpmol,&w, // Other thermodynamic terms &ierr,herr,errormessagelength); // Error terms - if (ierr > 0) { throw ValueError(format("PQ: %s",herr).c_str()); }// TODO: else if (ierr < 0) {set_warning(format("%s",herr).c_str());} + if (static_cast(ierr) > 0) { throw ValueError(format("PQ: %s",herr).c_str()); }// TODO: else if (ierr < 0) {set_warning(format("%s",herr).c_str());} // Set all cache values that can be set with unit conversion to SI _p = value1; @@ -1179,7 +1180,7 @@ void REFPROPMixtureBackend::update(CoolProp::input_pairs input_pair, double valu &emol,&hmol,&smol,&cvmol,&cpmol,&w, // Other thermodynamic terms &ierr,herr,errormessagelength); // Error terms - if (ierr > 0) { + if (static_cast(ierr) > 0) { throw ValueError(format("TQ(%s): %s",LoadedREFPROPRef.c_str(), herr).c_str()); }// TODO: else if (ierr < 0) {set_warning(format("%s",herr).c_str()); From 660210b49a0927fb3fcbbaf8dc99cd082e09b72a Mon Sep 17 00:00:00 2001 From: Ian Bell Date: Mon, 12 Jan 2015 21:02:32 -0700 Subject: [PATCH 15/69] Do not deploy platform-independent C# files; See #392 Signed-off-by: Ian Bell --- CMakeLists.txt | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index af9173a6..6944f1a9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -458,11 +458,6 @@ if (COOLPROP_CSHARP_MODULE) COMMAND 7z a "${CMAKE_CURRENT_BINARY_DIR}/platform-independent.7z" "${CMAKE_CURRENT_BINARY_DIR}/*.cs" WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}") - # Install all the generated cs files - install( - CODE "file( GLOB _GeneratedCsharpSources \"${CMAKE_CURRENT_BINARY_DIR}/*.cs\" )" - CODE "file( INSTALL \${_GeneratedCsharpSources} DESTINATION ${CMAKE_INSTALL_PREFIX}/Csharp/platform-independent )" - ) install (FILES ${CMAKE_SOURCE_DIR}/Web/coolprop/wrappers/Csharp/Example.cs DESTINATION Csharp) install (FILES "${CMAKE_CURRENT_BINARY_DIR}/platform-independent.7z" DESTINATION ${CMAKE_INSTALL_PREFIX}/Csharp) install (TARGETS ${app_name} DESTINATION Csharp/${CMAKE_SYSTEM_NAME}_${BITNESS}bit) @@ -472,7 +467,7 @@ if (COOLPROP_CSHARP_MODULE) # Copy the shared object to the folder with the executable - no idea like java.library.path in C# install (TARGETS ${app_name} DESTINATION ${CMAKE_SOURCE_DIR}/testing_root/Csharp${BITNESS}) endif() - file(TO_NATIVE_PATH ${CMAKE_INSTALL_PREFIX}/Csharp/platform-independent/*.cs cp_cs_path) + file(TO_NATIVE_PATH ${CMAKE_CURRENT_BINARY_DIR}/*.cs cp_cs_path) file(TO_NATIVE_PATH ${CMAKE_INSTALL_PREFIX}/Csharp/Example.cs cp_example_path) if (${BITNESS} EQUAL "32") set(CSHARP_PLAT "-platform:x86") From 633a9c3a5c75458a2b7d4e8ce9ffa1888faa6b78 Mon Sep 17 00:00:00 2001 From: Ian Bell Date: Mon, 12 Jan 2015 21:23:17 -0700 Subject: [PATCH 16/69] Updated integration docs for C# and Java; See #392 Signed-off-by: Ian Bell --- Web/coolprop/wrappers/Csharp/index.rst | 19 ++++++++++++++++--- Web/coolprop/wrappers/Java/index.rst | 15 ++++++++++++++- 2 files changed, 30 insertions(+), 4 deletions(-) diff --git a/Web/coolprop/wrappers/Csharp/index.rst b/Web/coolprop/wrappers/Csharp/index.rst index 72a8a777..5eac45f9 100644 --- a/Web/coolprop/wrappers/Csharp/index.rst +++ b/Web/coolprop/wrappers/Csharp/index.rst @@ -6,13 +6,24 @@ C# Wrapper Pre-compiled Binaries ===================== -Pre-compiled release binaries can be downloaded from :sfdownloads:`Csharp`. Development binaries coming from the buildbot server can be found at :sfnightly:`Csharp`. To Use ------ -Copy all the platform-independent .cs files to a folder on your computer you want, here we call it ``platform-independent``. Copy the DLL for your system architecture to the same location. Copy the Example.cs file to the same location. You will need to have a copy of some version of C#. +Pre-compiled binaries can be downloaded from :sfdownloads:`Csharp`. Development binaries coming from the buildbot server can be found at :sfnightly:`Csharp`. +Download the platform-independent.7z file and expand it to a folder called ``platform-independent``. Download the special C# shared library for your system architecture to the same location from either :sfdownloads:`Csharp` (release) or :sfnightly:`Csharp` (development). Copy the Example.cs file to the same location. You will need to have a copy of some version of C#. + +When you are finished, you should have a folder layout something like :: + + main + |- CoolProp.dll + |- Example.cs + |- platform-independent + |- AbstractState.cs + |- Configuration.cs + |- ... + Windows ^^^^^^^ @@ -24,7 +35,7 @@ At the command prompt, run:: where you might need to update the path to visual studio depending on your version installed. Use `-platform:x86` to tell C# that your DLL is 32-bit if you are on 32-bit, or `-platform:x64` if you are on 64-bit. -Alternatively, you can add all the .cs files to a visual studio project. +Alternatively, you can add all the .cs files to a visual studio project. If you do that, add the DLL to the project as well, right-click on the DLL, and select the option to copy it to the output directory. Linux/OSX ^^^^^^^^^ @@ -33,6 +44,8 @@ Same idea as windows, but command line is just a bit different:: mcs Example.cs platform-independent/*.cs -platform:x64 ./Example + +Use `-platform:x86` to tell C# that your shared library is 32-bit if you are on 32-bit, or `-platform:x64` if you are on a 64-bit platform. User-Compiled Binaries ====================== diff --git a/Web/coolprop/wrappers/Java/index.rst b/Web/coolprop/wrappers/Java/index.rst index 632ad247..7dd2500a 100644 --- a/Web/coolprop/wrappers/Java/index.rst +++ b/Web/coolprop/wrappers/Java/index.rst @@ -6,7 +6,20 @@ Java Wrapper Pre-compiled Binaries ===================== -Pre-compiled binaries can be downloaded from :sfdownloads:`Java`, which come from :sfnightly:`the nightly snapshots `. + +Pre-compiled binaries can be downloaded from :sfdownloads:`Java`. Development binaries coming from the buildbot server can be found at :sfnightly:`Java`. + +Download the ``platform-independent.7z`` file and expand it to a folder called ``platform-independent`` using 7-zip. Download the special Java shared library for your system architecture to the same location from either :sfdownloads:`Java` (release) or :sfnightly:`Java` (development). Copy the Example.java file to the same location. You will need to have a copy of some version of java. + +When you are finished, you should have a folder layout something like :: + + main + |- CoolProp.dll + |- Example.java + |- platform-independent + |- AbstractState.java + |- Configuration.java + |- ... Usage ----- From e81833b38c126533903e5f9e7b4f2dcdeeb8d11f Mon Sep 17 00:00:00 2001 From: Ian Bell Date: Mon, 12 Jan 2015 21:26:03 -0700 Subject: [PATCH 17/69] Tiny updates to C# docs Signed-off-by: Ian Bell --- Web/coolprop/wrappers/Csharp/index.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Web/coolprop/wrappers/Csharp/index.rst b/Web/coolprop/wrappers/Csharp/index.rst index 5eac45f9..acf51bb7 100644 --- a/Web/coolprop/wrappers/Csharp/index.rst +++ b/Web/coolprop/wrappers/Csharp/index.rst @@ -12,7 +12,7 @@ To Use Pre-compiled binaries can be downloaded from :sfdownloads:`Csharp`. Development binaries coming from the buildbot server can be found at :sfnightly:`Csharp`. -Download the platform-independent.7z file and expand it to a folder called ``platform-independent``. Download the special C# shared library for your system architecture to the same location from either :sfdownloads:`Csharp` (release) or :sfnightly:`Csharp` (development). Copy the Example.cs file to the same location. You will need to have a copy of some version of C#. +Download the ``platform-independent.7z`` file and expand it to a folder called ``platform-independent`` using 7-zip. Download the special C# shared library for your system architecture to the same location from either :sfdownloads:`Csharp` (release) or :sfnightly:`Csharp` (development). Copy the Example.cs file to the same location. You will need to have a copy of some version of C#. When you are finished, you should have a folder layout something like :: From 5208b329956d1b3a56215d6f07c6c224d2a14842 Mon Sep 17 00:00:00 2001 From: Ian Bell Date: Mon, 12 Jan 2015 21:58:40 -0700 Subject: [PATCH 18/69] Fixed bug with different output for different order of inputs to HAPropsSI; Closes #399 Signed-off-by: Ian Bell --- src/HumidAirProp.cpp | 42 +++++++++++++++++++++++++----------------- 1 file changed, 25 insertions(+), 17 deletions(-) diff --git a/src/HumidAirProp.cpp b/src/HumidAirProp.cpp index 47c7c173..ec000ae5 100644 --- a/src/HumidAirProp.cpp +++ b/src/HumidAirProp.cpp @@ -1212,8 +1212,7 @@ double HAPropsSI(const std::string &OutputName, const std::string &Input1Name, d // Add a check to make sure that Air and Water fluid states have been properly instantiated check_fluid_instantiation(); - givens In1Type, In2Type, In3Type, Type1, Type2; - int iT,iW,iTdp,iRH,ip; + int In1Type, In2Type, In3Type,iT,iW,iTdp,iRH,ip,Type1,Type2; double vals[3],p,T,RH,W,Tdp,psi_w,M_ha,v_bar,h_bar,s_bar,MainInputValue,SecondaryInputValue,T_guess; double Value1,Value2,W_guess; std::string MainInputName, SecondaryInputName, Name1, Name2; @@ -1328,13 +1327,10 @@ double HAPropsSI(const std::string &OutputName, const std::string &Input1Name, d // Get the integer type codes Type1=Name2Type(Name1); Type2=Name2Type(Name2); - - // First, if one of the inputs is something that can potentially yield - // an explicit solution at a given iteration of the solver, use it - if (Type1==GIVEN_RH || Type1==GIVEN_HUMRAT || Type1==GIVEN_TDP) + + // First see if humidity ratio is provided, will be the fastest option + if (Type1 == GIVEN_HUMRAT) { - // First input variable is a "nice" one - // MainInput is the one that you are using in the call to HAProps MainInputValue=Value1; strcpy(MainInputName,Name1); @@ -1342,21 +1338,33 @@ double HAPropsSI(const std::string &OutputName, const std::string &Input1Name, d SecondaryInputValue=Value2; strcpy(SecondaryInputName,Name2); } - else if (Type2==GIVEN_RH || Type2==GIVEN_HUMRAT || Type2==GIVEN_TDP) + else if (Type2 == GIVEN_HUMRAT) { - // Second input variable is a "nice" one - - // MainInput is the one that you are using in the call to HAProps - MainInputValue=Value2; - strcpy(MainInputName,Name2); + // MainInput is the one that you are using in the call to HAPropsSI + MainInputValue=Value2; strcpy(MainInputName, Name2); // SecondaryInput is the one that you are trying to match - SecondaryInputValue=Value1; - strcpy(SecondaryInputName,Name1); + SecondaryInputValue=Value1; strcpy(SecondaryInputName, Name1); + } + // Next, if one of the inputs is something that can potentially yield + // an explicit solution at a given iteration of the solver, use it + else if (Type1 == GIVEN_RH || Type1 == GIVEN_TDP) + { + // MainInput is the one that you are using in the call to HAProps + MainInputValue = Value1; strcpy(MainInputName, Name1); + // SecondaryInput is the one that you are trying to match + SecondaryInputValue = Value2; strcpy(SecondaryInputName, Name2); + } + else if (Type2 == GIVEN_RH || Type2 == GIVEN_TDP) + { + // MainInput is the one that you are using in the call to HAProps + MainInputValue = Value2; strcpy(MainInputName, Name2); + // SecondaryInput is the one that you are trying to match + SecondaryInputValue=Value1; strcpy(SecondaryInputName, Name1); } else { printf("Sorry, but currently at least one of the variables as an input to HAPropsSI() must be temperature, relative humidity, humidity ratio, or dewpoint\n Eventually will add a 2-D NR solver to find T and psi_w simultaneously, but not included now\n"); - return -1000; + return _HUGE; } double T_min = 210; From 0bb60b6ed9142b432b4049b6cde11823e59eb297 Mon Sep 17 00:00:00 2001 From: Ian Bell Date: Mon, 12 Jan 2015 23:38:29 -0700 Subject: [PATCH 19/69] Refactored HAPropsSI to handle better weird inputs Closes #400 Closes #398 Closes #403 Signed-off-by: Ian Bell --- src/HumidAirProp.cpp | 98 ++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 95 insertions(+), 3 deletions(-) diff --git a/src/HumidAirProp.cpp b/src/HumidAirProp.cpp index ec000ae5..157650b7 100644 --- a/src/HumidAirProp.cpp +++ b/src/HumidAirProp.cpp @@ -173,7 +173,72 @@ static double Brent_HAProps_T(const std::string &OutputName, const std::string & BrentSolverResids BSR = BrentSolverResids(OutputName, Input1Name, Input1, Input2Name, Input2, TargetVal); std::string errstr; - T = CoolProp::Brent(BSR,T_min,T_max,1e-7,1e-4,50,errstr); + // Now we need to check the bounds and make sure that they are ok (don't yield invalid output) + // and actually bound the solution + double r_min = BSR.call(T_min); + bool T_min_valid = ValidNumber(r_min); + double r_max = BSR.call(T_max); + bool T_max_valid = ValidNumber(r_max); + if (!T_min_valid && !T_max_valid){ + throw CoolProp::ValueError(format("Both T_min [%g] and T_max [%g] yield invalid output values in Brent_HAProps_T",T_min,T_max).c_str()); + } + else if (T_min_valid && !T_max_valid){ + while (!T_max_valid){ + // Reduce T_max until it works + T_max = 0.95*T_max + 0.05*T_min; + r_max = BSR.call(T_max); + T_max_valid = ValidNumber(r_max); + } + } + else if (!T_min_valid && T_max_valid){ + while (!T_min_valid){ + // Increase T_min until it works + T_min = 0.95*T_min + 0.05*T_max; + r_min = BSR.call(T_min); + T_min_valid = ValidNumber(r_min); + } + } + T = CoolProp::Brent(BSR, T_min, T_max, 1e-7, 1e-4, 50, errstr); + + return T; +} +static double Secant_Tdb_at_saturated_W(double psi_w, double p, double T_guess) +{ + double T; + class BrentSolverResids : public CoolProp::FuncWrapper1D + { + private: + double pp_water, psi_w, p, r; + public: + BrentSolverResids(double psi_w, double p) : psi_w(psi_w), p(p) { pp_water = psi_w*p; }; + ~BrentSolverResids(){}; + + double call(double T){ + double p_ws; + if (T>=273.16) + { + // Saturation pressure [Pa] + Water->update(CoolProp::QT_INPUTS, 0, T); + p_ws= Water->keyed_output(CoolProp::iP); + } + else + { + // Sublimation pressure [Pa] + p_ws=psub_Ice(T); + + } + double f = f_factor(T, p); + double pp_water_calc = f*p_ws; + double psi_w_calc = pp_water_calc/p; + r = (psi_w_calc - psi_w)/psi_w; + return r; + } + }; + + BrentSolverResids Resids(psi_w, p); + + std::string errstr; + T = CoolProp::Secant(Resids, 150, 100, 1e-7, 100, errstr); return T; } @@ -1371,8 +1436,28 @@ double HAPropsSI(const std::string &OutputName, const std::string &Input1Name, d double T_max = 450; if (Name2Type(MainInputName) == GIVEN_RH){ - T_max = CoolProp::PropsSI("T","P",p,"Q",0,"Water") - 1; + if (MainInputValue < 1e-10){ + T_max = 1000; + } + else{ + T_max = CoolProp::PropsSI("T","P",p,"Q",0,"Water") - 1; + } } + // Minimum drybulb temperature is the drybulb temperature corresponding to saturated air for the humidity ratio + // if the humidity ratio is provided + else if (Name2Type(MainInputName) == GIVEN_HUMRAT){ + if (MainInputValue < 1e-10){ + T_min = 135; // Around the critical point of dry air + T_max = 1000; + } + else{ + // Calculate the saturated humid air water partial pressure; + double psi_w_sat = MoleFractionWater(T_min, p, GIVEN_HUMRAT, MainInputValue); + //double pp_water_sat = psi_w_sat*p; // partial pressure of water, which is equal to f*p_{w_s} + // Iteratively solve for temperature that will give desired pp_water_sat + T_min = Secant_Tdb_at_saturated_W(psi_w_sat, p, T_min); + } + } try{ // Use the Brent's method solver to find T. Slow but reliable @@ -1921,7 +2006,14 @@ TEST_CASE_METHOD(HAPropsConsistencyFixture, "ASHRAE RP1485 Tables", "[RP1485]") CHECK(std::abs(actual/expected-1) < 0.01); } } - } + +TEST_CASE("Assorted tests","[HAPropsSI]") +{ + CHECK(ValidNumber(HumidAir::HAPropsSI("T", "H", 267769, "P", 104300, "W", 0.0))); + CHECK(ValidNumber(HumidAir::HAPropsSI("T", "B", 252.84, "W", 5.097e-4, "P", 101325))); + CHECK(ValidNumber(HumidAir::HAPropsSI("T", "B",290, "R", 1, "P", 101325))); +} + #endif /* CATCH_ENABLED */ From ccffe5855dc9092cb46c86c52760e04f23a9ad39 Mon Sep 17 00:00:00 2001 From: Jorrit Wronski Date: Tue, 13 Jan 2015 17:30:35 +0100 Subject: [PATCH 20/69] The release script again. I hope it is well documented now and we can use it. I hope this covers #378. --- dev/scripts/release.bsh | 99 ++++++++++++++++++++++------------------- 1 file changed, 54 insertions(+), 45 deletions(-) diff --git a/dev/scripts/release.bsh b/dev/scripts/release.bsh index d51209c6..57e493af 100755 --- a/dev/scripts/release.bsh +++ b/dev/scripts/release.bsh @@ -30,62 +30,70 @@ if [ $# != 2 ]; then fi # # Just a small function print messages -SEPARATOR="----------------------------------" +SEPARATOR="---------------------------------------------------" function printMessage { echo " " echo $SEPARATOR echo "$1" + echo $SEPARATOR return 0 } -# Now we use the function defined above -printMessage "Processing the input variables: " -# # Process the version number and set parameters accordingly CPVERSION="$1" if [[ $CPVERSION == +([0-9]).+([0-9]).+([0-9]) ]]; then - echo "CPVERSION = $CPVERSION" BINFOLDER="release" elif [ "$CPVERSION" == "nightly" ]; then - echo "CPVERSION = $CPVERSION - which is a valid input" BINFOLDER="binaries" else echo "CPVERSION = $CPVERSION - not valid!" exit 1 fi -# -# -SFUSER="jorritw" # ibell or jorritw -BASEDIR="$HOME/buildbot/server-master/public_html" -REPODIR="$HOME/src/CoolPropFull.git" -TMPSDIR="$HOME/src/CoolProp.sources" -SRCFOLDER="$BASEDIR/$BINFOLDER/source" -DOCFOLDER="$BASEDIR/$BINFOLDER/sphinx" -DOC4FILES="4.2.5/coolpropv425docs.zip" -DOC4FOLDER="$DOCFOLDER/v4" -# -# +# Process the dryrun option if [ "$2" == "release" ]; then DRYRUN=false else DRYRUN=true fi -echo "DRYRUN = $DRYRUN" +# +printMessage "Detected parameters" +echo "CPVERSION = $CPVERSION - which is a valid input" +echo "DRYRUN = $DRYRUN" +echo "BINFOLDER = $BINFOLDER" +# +# +SFUSER="jorritw" # ibell or jorritw +# Absolute (!) paths -> XXXXDIR +BASEDIR="$HOME/buildbot/server-master/public_html" +REPODIR="$HOME/src/CoolPropFull.git" +TMPSDIR="$HOME/src/CoolProp.sources" +SRCSDIR="$BASEDIR/$BINFOLDER/source" +# +# Relative (!) paths -> XXXFOLDER +DOCFOLDER="$BINFOLDER/docs" +SPHFOLDER="$BINFOLDER/sphinx" +DOC4FILES="4.2.5/coolpropv425docs.zip" +DOC4FOLDER="$SPHFOLDER/v4" +RSYNC_EXCL="--exclude=sphinx" +# +DOCFILE="documentation.zip" # # -pushd ${BASEDIR} # Change the folder if [ "$DRYRUN" != "false" ]; then printMessage "Dry run detected" echo "Dry run; no zipping of the sources" echo "Dry run; no zipping of the docs" echo "Dry run; skipping python upload" - echo "Dry run; skipping folder date" RSYNC_DRY_RUN=--dry-run else + RSYNC_DRY_RUN= + ###################################### + # We start with the absolute paths ... + ###################################### + mkdir -p "$TMPSDIR" "$SRCSDIR" # Generating directories printMessage "Updating sources" pushd "$REPODIR" git pull git submodule update - #python dev/scripts/git-archive-all $SRCFOLDER/CoolProp_sources.zip popd printMessage "Generating headers" rsync -a --delete "$REPODIR/" "$TMPSDIR" @@ -95,43 +103,45 @@ else #rm -rf .git* find . -iwholename "*/.git*" -exec rm -rf {} \; cd .. - mkdir -p $SRCFOLDER - rm -f $SRCFOLDER/CoolProp_sources.zip - zip -rq $SRCFOLDER/CoolProp_sources.zip $(basename $TMPSDIR) + rm -f $SRCSDIR/CoolProp_sources.zip + zip -rq $SRCSDIR/CoolProp_sources.zip $(basename $TMPSDIR) cd $(basename $TMPSDIR) popd - rm -f "$BINFOLDER/README.rst.txt" + ###################################### + # ... and now we use relative paths + ###################################### + pushd ${BASEDIR} + mkdir -p "$DOCFOLDER" "$SPHFOLDER" "$DOC4FOLDER" + printMessage "Preparing the docs and moving them into the $BINFOLDER folder for staging" + rsync $RSYNC_DRY_RUN $RSYNC_OPTS "frs.sf.net-$SFUSER:/home/frs/project/coolprop/CoolProp/$DOC4FILES" "$(basename $DOC4FILES)" + unzip -qo "$(basename $DOC4FILES)" -d "$DOC4FOLDER" + zip -rq "$DOCFILE" $SPHFOLDER/* -x */$(basename $DOC4FOLDER)/* + mv "$DOCFILE" "$DOCFOLDER" + # if [ "$CPVERSION" == "nightly" ]; then - RSYNC_OPTS="-a --no-perms -z --stats --delete" - rm -rf "$BINFOLDER/docs" - CPVERSION="$CPVERSION"/ #$(date +%F) - echo "CoolProp nightly binaries" > "$BINFOLDER/README.rst.txt" + printMessage "Detected nightly release, updating README.rst.txt" + echo "CoolProp nightly binaries" > "$BINFOLDER/README.rst.txt" echo "-------------------------" >> "$BINFOLDER/README.rst.txt" echo -n "Development binaries of the" >> "$BINFOLDER/README.rst.txt" echo -n " \`CoolProp project \`_ " >> "$BINFOLDER/README.rst.txt" echo "updated on $(date +%F) at $(date +%X) $(date +%Z)." >> "$BINFOLDER/README.rst.txt" + RSYNC_OPTS="-a --no-perms -z --stats --delete" else RSYNC_OPTS="-a --no-perms -z --stats" - printMessage "Zipping up the docs and moving them into the $BINFOLDER folder for staging" - rm -f documentation.zip - zip -rq documentation.zip $DOCFOLDER/* -x */$(basename $DOC4FOLDER)/* - cp documentation.zip "$DOCFOLDER/sphinx" - echo "Uploading the python binaries to pypi" + echo "Detected full release, uploading the python binaries to pypi" twine upload $BINFOLDER/Python/*.whl $BINFOLDER/Python/*.tar.gz fi - RSYNC_DRY_RUN= + popd fi -# -printMessage "Getting the latest v4 docs from SourceForge" -rsync $RSYNC_DRY_RUN $RSYNC_OPTS "frs.sf.net-$SFUSER:/home/frs/project/coolprop/CoolProp/$DOC4FILES" "$(basename $DOC4FILES)" -mkdir -p "$DOC4FOLDER" -unzip -qo "$(basename $DOC4FILES)" -d "$DOC4FOLDER" -# +###################################### +# ... we continue with relative paths +###################################### +pushd ${BASEDIR} printMessage "Copying the binaries to SourceForge" -rsync $RSYNC_DRY_RUN $RSYNC_OPTS "$BINFOLDER/" frs.sf.net-$SFUSER:/home/frs/project/coolprop/CoolProp/$CPVERSION +rsync $RSYNC_DRY_RUN $RSYNC_OPTS $RSYNC_EXCL "$BINFOLDER/" frs.sf.net-$SFUSER:/home/frs/project/coolprop/CoolProp/$CPVERSION if [ ${CPVERSION:0:7} != "nightly" ]; then printMessage "Publishing the docs on SourceForge" - rsync $RSYNC_DRY_RUN $RSYNC_OPTS "$DOCFOLDER/" frs.sf.net-$SFUSER:/home/project-web/coolprop/htdocs + rsync $RSYNC_DRY_RUN $RSYNC_OPTS "$SPHFOLDER/" frs.sf.net-$SFUSER:/home/project-web/coolprop/htdocs fi # if [[ ("$BINFOLDER" == "release") && ("$DRYRUN" == "false") ]]; then @@ -139,7 +149,6 @@ if [[ ("$BINFOLDER" == "release") && ("$DRYRUN" == "false") ]]; then rm -rf "$BINFOLDER" mkdir -p "$BINFOLDER" fi -# Change back to where we came from popd printMessage "All done, goodbye." exit 0 From 7c108c9ac28635d655ee4515ea6702843776fa5e Mon Sep 17 00:00:00 2001 From: Ian Bell Date: Wed, 14 Jan 2015 22:24:10 -0700 Subject: [PATCH 21/69] Added VB.net solution files Signed-off-by: Ian Bell --- wrappers/VB.NET/CoolPropVB/CoolPropVB.sln | 34 ++++ .../CoolPropVB/CoolPropVB/CoolPropVB.vbproj | 148 ++++++++++++++++++ .../VB.NET/CoolPropVB/CoolPropVB/Example.vb | 19 +++ .../CsharpClassLibrary.csproj | 52 ++++++ .../Properties/AssemblyInfo.cs | 36 +++++ 5 files changed, 289 insertions(+) create mode 100644 wrappers/VB.NET/CoolPropVB/CoolPropVB.sln create mode 100644 wrappers/VB.NET/CoolPropVB/CoolPropVB/CoolPropVB.vbproj create mode 100644 wrappers/VB.NET/CoolPropVB/CoolPropVB/Example.vb create mode 100644 wrappers/VB.NET/CoolPropVB/CsharpClassLibrary/CsharpClassLibrary.csproj create mode 100644 wrappers/VB.NET/CoolPropVB/CsharpClassLibrary/Properties/AssemblyInfo.cs diff --git a/wrappers/VB.NET/CoolPropVB/CoolPropVB.sln b/wrappers/VB.NET/CoolPropVB/CoolPropVB.sln new file mode 100644 index 00000000..4095f32c --- /dev/null +++ b/wrappers/VB.NET/CoolPropVB/CoolPropVB.sln @@ -0,0 +1,34 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Express 2012 for Windows Desktop +Project("{F184B08F-C81C-45F6-A57F-5ABD9991F28F}") = "CoolPropVB", "CoolPropVB\CoolPropVB.vbproj", "{221A231D-EA9F-451E-A648-ADB53E43814B}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CsharpClassLibrary", "CsharpClassLibrary\CsharpClassLibrary.csproj", "{DEC3B691-4510-4181-89EE-7A4A495936A6}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Debug|x64 = Debug|x64 + Release|Any CPU = Release|Any CPU + Release|x64 = Release|x64 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {221A231D-EA9F-451E-A648-ADB53E43814B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {221A231D-EA9F-451E-A648-ADB53E43814B}.Debug|Any CPU.Build.0 = Debug|Any CPU + {221A231D-EA9F-451E-A648-ADB53E43814B}.Debug|x64.ActiveCfg = Debug|x64 + {221A231D-EA9F-451E-A648-ADB53E43814B}.Debug|x64.Build.0 = Debug|x64 + {221A231D-EA9F-451E-A648-ADB53E43814B}.Release|Any CPU.ActiveCfg = Release|Any CPU + {221A231D-EA9F-451E-A648-ADB53E43814B}.Release|Any CPU.Build.0 = Release|Any CPU + {221A231D-EA9F-451E-A648-ADB53E43814B}.Release|x64.ActiveCfg = Release|x64 + {221A231D-EA9F-451E-A648-ADB53E43814B}.Release|x64.Build.0 = Release|x64 + {DEC3B691-4510-4181-89EE-7A4A495936A6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {DEC3B691-4510-4181-89EE-7A4A495936A6}.Debug|Any CPU.Build.0 = Debug|Any CPU + {DEC3B691-4510-4181-89EE-7A4A495936A6}.Debug|x64.ActiveCfg = Debug|Any CPU + {DEC3B691-4510-4181-89EE-7A4A495936A6}.Release|Any CPU.ActiveCfg = Release|Any CPU + {DEC3B691-4510-4181-89EE-7A4A495936A6}.Release|Any CPU.Build.0 = Release|Any CPU + {DEC3B691-4510-4181-89EE-7A4A495936A6}.Release|x64.ActiveCfg = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/wrappers/VB.NET/CoolPropVB/CoolPropVB/CoolPropVB.vbproj b/wrappers/VB.NET/CoolPropVB/CoolPropVB/CoolPropVB.vbproj new file mode 100644 index 00000000..7784f705 --- /dev/null +++ b/wrappers/VB.NET/CoolPropVB/CoolPropVB/CoolPropVB.vbproj @@ -0,0 +1,148 @@ + + + + + Debug + AnyCPU + {221A231D-EA9F-451E-A648-ADB53E43814B} + Exe + CoolPropVB.Example + CoolPropVB + CoolPropVB + 512 + Console + v4.5 + + + AnyCPU + true + full + true + true + bin\Debug\ + CoolPropVB.xml + 42016,41999,42017,42018,42019,42032,42036,42020,42021,42022 + + + AnyCPU + pdbonly + false + true + true + bin\Release\ + CoolPropVB.xml + 42016,41999,42017,42018,42019,42032,42036,42020,42021,42022 + + + On + + + Binary + + + Off + + + On + + + true + true + true + bin\x64\Debug\ + CoolPropVB.xml + 42016,41999,42017,42018,42019,42032,42036,42020,42021,42022 + full + x64 + ManagedMinimumRules.ruleset + true + + + true + bin\x64\Release\ + CoolPropVB.xml + true + 42016,41999,42017,42018,42019,42032,42036,42020,42021,42022 + pdbonly + x64 + ManagedMinimumRules.ruleset + true + + + + + + + + + + + + + + + + + + + + + + + + + + True + Application.myapp + + + True + True + Resources.resx + + + True + Settings.settings + True + + + + + VbMyResourcesResXFileCodeGenerator + Resources.Designer.vb + My.Resources + Designer + + + + + MyApplicationCodeGenerator + Application.Designer.vb + + + SettingsSingleFileGenerator + My + Settings.Designer.vb + + + + + + {dec3b691-4510-4181-89ee-7a4a495936a6} + CsharpClassLibrary + + + + + Always + + + + + \ No newline at end of file diff --git a/wrappers/VB.NET/CoolPropVB/CoolPropVB/Example.vb b/wrappers/VB.NET/CoolPropVB/CoolPropVB/Example.vb new file mode 100644 index 00000000..9de1c3fb --- /dev/null +++ b/wrappers/VB.NET/CoolPropVB/CoolPropVB/Example.vb @@ -0,0 +1,19 @@ +Module Example + + Sub Main() + ' High-level interface example + Dim Tbp As Double + Tbp = CoolProp.CoolProp.PropsSI("T", "P", 101325, "Q", 0, "Water") + Console.Write(Tbp) + Console.Write(vbCrLf) + + ' Low-level interface example + Dim Water As CoolProp.AbstractState + Water = CoolProp.AbstractState.factory("HEOS", "Water") + Water.update(CoolProp.input_pairs.PQ_INPUTS, 101325, 0) + Console.Write(Water.T()) + Console.Write(vbCrLf) + + End Sub + +End Module diff --git a/wrappers/VB.NET/CoolPropVB/CsharpClassLibrary/CsharpClassLibrary.csproj b/wrappers/VB.NET/CoolPropVB/CsharpClassLibrary/CsharpClassLibrary.csproj new file mode 100644 index 00000000..40187f10 --- /dev/null +++ b/wrappers/VB.NET/CoolPropVB/CsharpClassLibrary/CsharpClassLibrary.csproj @@ -0,0 +1,52 @@ + + + + + Debug + AnyCPU + {DEC3B691-4510-4181-89EE-7A4A495936A6} + Library + Properties + ClassLibrary1 + CsharpClassLibrary + v4.5 + 512 + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/wrappers/VB.NET/CoolPropVB/CsharpClassLibrary/Properties/AssemblyInfo.cs b/wrappers/VB.NET/CoolPropVB/CsharpClassLibrary/Properties/AssemblyInfo.cs new file mode 100644 index 00000000..c2e1ab02 --- /dev/null +++ b/wrappers/VB.NET/CoolPropVB/CsharpClassLibrary/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("CoolProp")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("CoolProp")] +[assembly: AssemblyCopyright("Copyright © 2015")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("8a84d196-96fc-47c6-b341-ed1ade8ee040")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] From 9dbf8fdcbd7b7ff93590b690d26a452081e5b60d Mon Sep 17 00:00:00 2001 From: Ian Bell Date: Wed, 14 Jan 2015 23:19:22 -0700 Subject: [PATCH 22/69] Small updates to project files for VB.net example Signed-off-by: Ian Bell --- wrappers/VB.NET/CoolPropVB/CoolPropVB.sln | 1 + .../VB.NET/CoolPropVB/CoolPropVB/App.config | 6 +++ .../CoolPropVB/CoolPropVB/CoolPropVB.vbproj | 37 ------------------- 3 files changed, 7 insertions(+), 37 deletions(-) create mode 100644 wrappers/VB.NET/CoolPropVB/CoolPropVB/App.config diff --git a/wrappers/VB.NET/CoolPropVB/CoolPropVB.sln b/wrappers/VB.NET/CoolPropVB/CoolPropVB.sln index 4095f32c..5195b34e 100644 --- a/wrappers/VB.NET/CoolPropVB/CoolPropVB.sln +++ b/wrappers/VB.NET/CoolPropVB/CoolPropVB.sln @@ -24,6 +24,7 @@ Global {DEC3B691-4510-4181-89EE-7A4A495936A6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {DEC3B691-4510-4181-89EE-7A4A495936A6}.Debug|Any CPU.Build.0 = Debug|Any CPU {DEC3B691-4510-4181-89EE-7A4A495936A6}.Debug|x64.ActiveCfg = Debug|Any CPU + {DEC3B691-4510-4181-89EE-7A4A495936A6}.Debug|x64.Build.0 = Debug|Any CPU {DEC3B691-4510-4181-89EE-7A4A495936A6}.Release|Any CPU.ActiveCfg = Release|Any CPU {DEC3B691-4510-4181-89EE-7A4A495936A6}.Release|Any CPU.Build.0 = Release|Any CPU {DEC3B691-4510-4181-89EE-7A4A495936A6}.Release|x64.ActiveCfg = Release|Any CPU diff --git a/wrappers/VB.NET/CoolPropVB/CoolPropVB/App.config b/wrappers/VB.NET/CoolPropVB/CoolPropVB/App.config new file mode 100644 index 00000000..8e156463 --- /dev/null +++ b/wrappers/VB.NET/CoolPropVB/CoolPropVB/App.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/wrappers/VB.NET/CoolPropVB/CoolPropVB/CoolPropVB.vbproj b/wrappers/VB.NET/CoolPropVB/CoolPropVB/CoolPropVB.vbproj index 7784f705..9ed21f8c 100644 --- a/wrappers/VB.NET/CoolPropVB/CoolPropVB/CoolPropVB.vbproj +++ b/wrappers/VB.NET/CoolPropVB/CoolPropVB/CoolPropVB.vbproj @@ -90,43 +90,6 @@ - - - True - Application.myapp - - - True - True - Resources.resx - - - True - Settings.settings - True - - - - - VbMyResourcesResXFileCodeGenerator - Resources.Designer.vb - My.Resources - Designer - - - - - MyApplicationCodeGenerator - Application.Designer.vb - - - SettingsSingleFileGenerator - My - Settings.Designer.vb - - - - {dec3b691-4510-4181-89ee-7a4a495936a6} CsharpClassLibrary From 979bc577391aa0710d7d2a8eb6fad37e5aa61de1 Mon Sep 17 00:00:00 2001 From: Ian Bell Date: Wed, 14 Jan 2015 23:27:34 -0700 Subject: [PATCH 23/69] Also build class library in release mode Signed-off-by: Ian Bell --- wrappers/VB.NET/CoolPropVB/CoolPropVB.sln | 1 + 1 file changed, 1 insertion(+) diff --git a/wrappers/VB.NET/CoolPropVB/CoolPropVB.sln b/wrappers/VB.NET/CoolPropVB/CoolPropVB.sln index 5195b34e..f61558d2 100644 --- a/wrappers/VB.NET/CoolPropVB/CoolPropVB.sln +++ b/wrappers/VB.NET/CoolPropVB/CoolPropVB.sln @@ -28,6 +28,7 @@ Global {DEC3B691-4510-4181-89EE-7A4A495936A6}.Release|Any CPU.ActiveCfg = Release|Any CPU {DEC3B691-4510-4181-89EE-7A4A495936A6}.Release|Any CPU.Build.0 = Release|Any CPU {DEC3B691-4510-4181-89EE-7A4A495936A6}.Release|x64.ActiveCfg = Release|Any CPU + {DEC3B691-4510-4181-89EE-7A4A495936A6}.Release|x64.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE From ac7dcfe04d770452d00faa4bbb981b4b5a023de0 Mon Sep 17 00:00:00 2001 From: Ian Bell Date: Wed, 14 Jan 2015 23:38:28 -0700 Subject: [PATCH 24/69] Update CMakeLists for VB.net Signed-off-by: Ian Bell --- CMakeLists.txt | 73 +++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 63 insertions(+), 10 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 6944f1a9..65a2035c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -431,18 +431,21 @@ if (COOLPROP_CSHARP_MODULE) # Make a src directory to deal with file permissions problem with MinGW makefile file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/src) - set(SWIG_OPTIONS "${COOLPROP_SWIG_OPTIONS}") - string(REPLACE " " ";" SWIG_OPTIONS "${SWIG_OPTIONS}") - SET_SOURCE_FILES_PROPERTIES(${I_FILE} PROPERTIES SWIG_FLAGS "${SWIG_OPTIONS}") - set(I_FILE "${CMAKE_SOURCE_DIR}/src/CoolProp.i") - - SET(SWIG_MODULE_CoolProp_EXTRA_DEPS ${SWIG_DEPENDENCIES}) - # Set properties before adding module - SET_SOURCE_FILES_PROPERTIES(${I_FILE} PROPERTIES CPLUSPLUS ON) if (WIN32) - SET(CMAKE_SWIG_FLAGS -dllimport \"CoolProp\") - #SET_SOURCE_FILES_PROPERTIES(${I_FILE} PROPERTIES SWIG_FLAGS "-dllimport CoolProp") + SET(MORE_SWIG_FLAGS -dllimport \"CoolProp\") endif() + + # Define which headers the CoolProp wrapper is dependent on + SET(SWIG_MODULE_CoolProp_EXTRA_DEPS ${SWIG_DEPENDENCIES}) + + set(SWIG_OPTIONS "${COOLPROP_SWIG_OPTIONS}" "${MORE_SWIG_FLAGS}") + string(REPLACE " " ";" SWIG_OPTIONS "${SWIG_OPTIONS}") + message(STATUS "options passed to swig: ${SWIG_OPTIONS}") + + # Set properties before adding module + set(I_FILE "${CMAKE_SOURCE_DIR}/src/CoolProp.i") + SET_SOURCE_FILES_PROPERTIES(${I_FILE} PROPERTIES SWIG_FLAGS "${SWIG_OPTIONS}" CPLUSPLUS ON) + SWIG_ADD_MODULE(CoolProp csharp ${I_FILE} ${APP_SOURCES}) add_definitions(-DNO_ERROR_CATCHING) #disable internal error catching and allow swig to do the error catching itself @@ -482,6 +485,56 @@ if (COOLPROP_CSHARP_MODULE) WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/testing_root/Csharp${BITNESS}) endif() +if (COOLPROP_VBDOTNET_MODULE) + + # Must have SWIG and C# + FIND_PACKAGE(SWIG REQUIRED) + INCLUDE(${SWIG_USE_FILE}) + FIND_PACKAGE(Csharp REQUIRED) + + file(COPY ${CMAKE_SOURCE_DIR}/wrappers/VB.NET/CoolPropVB/CoolPropVB DESTINATION VBdotNET) + + SET(MORE_SWIG_FLAGS -dllimport \"CoolProp\" -namespace CoolProp) + SET(CMAKE_SWIG_OUTDIR CoolPropVB/CsharpClassLibrary) + + # Define which headers the CoolProp wrapper is dependent on + SET(SWIG_MODULE_CoolProp_EXTRA_DEPS ${SWIG_DEPENDENCIES}) + + set(SWIG_OPTIONS "${MORE_SWIG_FLAGS}") + string(REPLACE " " ";" SWIG_OPTIONS "${SWIG_OPTIONS}") + message(STATUS "options passed to swig: ${SWIG_OPTIONS}") + + # Set properties before adding module + set(I_FILE "${CMAKE_SOURCE_DIR}/src/CoolProp.i") + SET_PROPERTY(SOURCE ${I_FILE} PROPERTY CPLUSPLUS ON) + SET_PROPERTY(SOURCE ${I_FILE} PROPERTY SWIG_FLAGS ${SWIG_OPTIONS}) + SWIG_ADD_MODULE(CoolProp csharp ${I_FILE} ${APP_SOURCES}) + + add_definitions(-DNO_ERROR_CATCHING) #disable internal error catching and allow swig to do the error catching itself + + if (WIN32) + set_target_properties(CoolProp PROPERTIES PREFIX "") + endif() + + add_dependencies (${app_name} generate_headers) + + add_custom_command(TARGET CoolProp + POST_BUILD + COMMAND ${CMAKE_COMMAND} -E copy $ ${CMAKE_CURRENT_BINARY_DIR}/CoolPropVB/CoolPropVB + WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}") + add_custom_command(TARGET CoolProp + POST_BUILD + COMMAND ${CMAKE_COMMAND} -E remove ${CMAKE_CURRENT_BINARY_DIR}/CoolPropVB/CsharpClassLibrary/CoolPropCSHARP_wrap.cxx + WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}") + add_custom_command(TARGET CoolProp + POST_BUILD + COMMAND 7z a "${CMAKE_CURRENT_BINARY_DIR}/VB.net_VS2012_example.7z" "${CMAKE_CURRENT_BINARY_DIR}/CoolPropVB" + WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}") + + install (FILES "${CMAKE_CURRENT_BINARY_DIR}/VB.net_VS2012_example.7z" DESTINATION ${CMAKE_INSTALL_PREFIX}/VB.NET) + +endif() + if (COOLPROP_JAVA_MODULE) # Must have SWIG and Java From 91ec7ca0a203f2ff7ee6c078841e4ffbae35c627 Mon Sep 17 00:00:00 2001 From: Ian Bell Date: Wed, 14 Jan 2015 23:38:57 -0700 Subject: [PATCH 25/69] Add buildbot builder for VB.net Signed-off-by: Ian Bell --- dev/buildbot/master/master.cfg | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/dev/buildbot/master/master.cfg b/dev/buildbot/master/master.cfg index 11e805b0..886c252b 100644 --- a/dev/buildbot/master/master.cfg +++ b/dev/buildbot/master/master.cfg @@ -932,13 +932,17 @@ c['builders'].append( #Common boring 64-bit modules for windows, linux and OSX ### OSX for platform in ['OSX', 'linux', 'windows']: - for wrapper in ['Java','Csharp','Octave','PHP','64BIT_SHARED_LIBRARY','STATIC_LIBRARY','MATHEMATICA']: + for wrapper in ['Java','Csharp','Octave','PHP','64BIT_SHARED_LIBRARY','STATIC_LIBRARY','MATHEMATICA','VBDOTNET']: if wrapper == 'PHP' and platform != 'linux': continue # only build PHP on linux + if wrapper == 'VBDOTNET' and !platform.startswith('windows'): continue # only build VB.net on windows ctest_args, cmake_args, build_args = [], [], [] if platform.startswith('windows'): ctest_args = ['-C', 'Release'] if wrapper == 'Octave': cmake_args = ['-G', '"MinGW Makefiles"'] + elif wrapper == 'VBDOTNET': + cmake_args = ['-G', '"Visual Studio 11 2012 Win64"'] + build_args = ['--config','Release'] else: cmake_args = ['-G', '"Visual Studio 10 2010 Win64"'] build_args = ['--config','Release'] From b0d9dde84980e1b15b2214227e9e999ab0512dd9 Mon Sep 17 00:00:00 2001 From: Ian Bell Date: Wed, 14 Jan 2015 23:39:28 -0700 Subject: [PATCH 26/69] Add first cut at VB.net docs Signed-off-by: Ian Bell --- Web/coolprop/wrappers/index.rst | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Web/coolprop/wrappers/index.rst b/Web/coolprop/wrappers/index.rst index 1213fac1..93de619f 100644 --- a/Web/coolprop/wrappers/index.rst +++ b/Web/coolprop/wrappers/index.rst @@ -16,6 +16,7 @@ Target Operating Systems Not :ref:`Python ` linux, OSX, win Wrapper is Cython based :ref:`Octave ` linux, OSX, win Wrapper is SWIG based :ref:`C# ` linux, OSX, win Wrapper is SWIG based +:ref:`VB.net ` windows only Wrapper is SWIG based :ref:`MATLAB ` linux, OSX, win Wrapper is SWIG based :ref:`Java ` linux, OSX, win Wrapper is SWIG based :ref:`Scilab ` linux, OSX, win Wrapper is SWIG based (experimental) @@ -122,4 +123,5 @@ and explicitly typing "agree" before closing. Then you can use the compiler from SMath/index.rst StaticLibrary/index.rst SharedLibrary/index.rst - DelphiLazarus/index.rst \ No newline at end of file + DelphiLazarus/index.rst + VBdotNET/index.rst \ No newline at end of file From bd153a2235ce81ee348c9ce4058d36a123b8069b Mon Sep 17 00:00:00 2001 From: Ian Bell Date: Thu, 15 Jan 2015 00:03:27 -0700 Subject: [PATCH 27/69] More fun with the copy_directory Signed-off-by: Ian Bell --- CMakeLists.txt | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 65a2035c..16ac9ae5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -492,7 +492,10 @@ if (COOLPROP_VBDOTNET_MODULE) INCLUDE(${SWIG_USE_FILE}) FIND_PACKAGE(Csharp REQUIRED) - file(COPY ${CMAKE_SOURCE_DIR}/wrappers/VB.NET/CoolPropVB/CoolPropVB DESTINATION VBdotNET) + # Make a src directory to deal with file permissions problem with MinGW makefile + file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/CoolPropVB) + + SET(MORE_SWIG_FLAGS -dllimport \"CoolProp\" -namespace CoolProp) SET(CMAKE_SWIG_OUTDIR CoolPropVB/CsharpClassLibrary) @@ -518,6 +521,10 @@ if (COOLPROP_VBDOTNET_MODULE) add_dependencies (${app_name} generate_headers) + add_custom_command(TARGET CoolProp + PRE_BUILD + COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_SOURCE_DIR}/wrappers/VB.NET/CoolPropVB ${CMAKE_CURRENT_BINARY_DIR}/CoolPropVB + WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}") add_custom_command(TARGET CoolProp POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy $ ${CMAKE_CURRENT_BINARY_DIR}/CoolPropVB/CoolPropVB From 3ad1a2f99ab5ade15b187d4f652717637f1203d1 Mon Sep 17 00:00:00 2001 From: Ian Bell Date: Thu, 15 Jan 2015 00:09:46 -0700 Subject: [PATCH 28/69] Fix typo in bb for VB.net --- dev/buildbot/master/master.cfg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dev/buildbot/master/master.cfg b/dev/buildbot/master/master.cfg index 886c252b..f8968228 100644 --- a/dev/buildbot/master/master.cfg +++ b/dev/buildbot/master/master.cfg @@ -934,7 +934,7 @@ c['builders'].append( for platform in ['OSX', 'linux', 'windows']: for wrapper in ['Java','Csharp','Octave','PHP','64BIT_SHARED_LIBRARY','STATIC_LIBRARY','MATHEMATICA','VBDOTNET']: if wrapper == 'PHP' and platform != 'linux': continue # only build PHP on linux - if wrapper == 'VBDOTNET' and !platform.startswith('windows'): continue # only build VB.net on windows + if wrapper == 'VBDOTNET' and not platform.startswith('windows'): continue # only build VB.net on windows ctest_args, cmake_args, build_args = [], [], [] if platform.startswith('windows'): ctest_args = ['-C', 'Release'] From 57470bc9be2b82d444567e3bacd4c9cf27c87a73 Mon Sep 17 00:00:00 2001 From: Jorrit Wronski Date: Thu, 15 Jan 2015 11:56:35 +0100 Subject: [PATCH 29/69] Fixed a typo in PropsSI in Python wrapper --- wrappers/Python/CoolProp/CoolProp.pyx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/wrappers/Python/CoolProp/CoolProp.pyx b/wrappers/Python/CoolProp/CoolProp.pyx index 0238ebb1..3a633f3c 100644 --- a/wrappers/Python/CoolProp/CoolProp.pyx +++ b/wrappers/Python/CoolProp/CoolProp.pyx @@ -248,9 +248,9 @@ cpdef PropsSI(in1, in2, in3 = None, in4 = None, in5 = None, in6 = None, in7 = No vval1 = templist vval2 = in5 else: - vval.resize(1) - vval1[0] = in3 vval1.resize(1) + vval1[0] = in3 + vval2.resize(1) vval2[0] = in5 # Extract the backend and the fluid from the input string From 3102ec9656d7d84f94f66fe9471cc98ce62b3ef4 Mon Sep 17 00:00:00 2001 From: Jorrit Wronski Date: Thu, 15 Jan 2015 17:54:57 +0100 Subject: [PATCH 30/69] Fixes #406 , just a typo. --- src/Backends/REFPROP/REFPROPMixtureBackend.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Backends/REFPROP/REFPROPMixtureBackend.cpp b/src/Backends/REFPROP/REFPROPMixtureBackend.cpp index 5ee4d66e..e1c46321 100644 --- a/src/Backends/REFPROP/REFPROPMixtureBackend.cpp +++ b/src/Backends/REFPROP/REFPROPMixtureBackend.cpp @@ -547,7 +547,7 @@ long double REFPROPMixtureBackend::calc_rhomolar_reducing(){ }; long double REFPROPMixtureBackend::calc_Ttriple(){ if (mole_fractions.size() != 1){throw ValueError("calc_Ttriple cannot be evaluated for mixtures");} - long icomp = 0; + long icomp = 1; double wmm, ttrp, tnbpt, tc, pc, Dc, Zc, acf, dip, Rgas; INFOdll(&icomp, &wmm, &ttrp, &tnbpt, &tc, &pc, &Dc, &Zc, &acf, &dip, &Rgas); return static_cast(ttrp); From 41982f7e6350dcff9e5ca1294f298c70cb33752e Mon Sep 17 00:00:00 2001 From: Ian Bell Date: Thu, 15 Jan 2015 19:53:49 -0700 Subject: [PATCH 31/69] Phase envelope should only be able to build for pure fluids; closes #410 Signed-off-by: Ian Bell --- src/Backends/Helmholtz/PhaseEnvelopeRoutines.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Backends/Helmholtz/PhaseEnvelopeRoutines.cpp b/src/Backends/Helmholtz/PhaseEnvelopeRoutines.cpp index 582d893a..ffe7948e 100644 --- a/src/Backends/Helmholtz/PhaseEnvelopeRoutines.cpp +++ b/src/Backends/Helmholtz/PhaseEnvelopeRoutines.cpp @@ -11,6 +11,7 @@ namespace CoolProp{ void PhaseEnvelopeRoutines::build(HelmholtzEOSMixtureBackend &HEOS) { + if (HEOS.get_mole_fractions_ref().size() < 2){throw ValueError("Cannot build phase envelope for pure fluid");} std::size_t failure_count = 0; // Set some imput options SaturationSolvers::mixture_VLE_IO io; From df9bd251451a6b433989b913938ae65907283c02 Mon Sep 17 00:00:00 2001 From: Ian Bell Date: Thu, 15 Jan 2015 19:55:19 -0700 Subject: [PATCH 32/69] Evidently I did not commit the changes to HAPropsSI. Oops. Signed-off-by: Ian Bell --- src/HumidAirProp.cpp | 137 +++++++++++++++++++++++++++++++++++++------ 1 file changed, 119 insertions(+), 18 deletions(-) diff --git a/src/HumidAirProp.cpp b/src/HumidAirProp.cpp index 3974cbe5..a72a6974 100644 --- a/src/HumidAirProp.cpp +++ b/src/HumidAirProp.cpp @@ -173,7 +173,72 @@ static double Brent_HAProps_T(const std::string &OutputName, const std::string & BrentSolverResids BSR = BrentSolverResids(OutputName, Input1Name, Input1, Input2Name, Input2, TargetVal); std::string errstr; - T = CoolProp::Brent(BSR,T_min,T_max,1e-7,1e-4,50,errstr); + // Now we need to check the bounds and make sure that they are ok (don't yield invalid output) + // and actually bound the solution + double r_min = BSR.call(T_min); + bool T_min_valid = ValidNumber(r_min); + double r_max = BSR.call(T_max); + bool T_max_valid = ValidNumber(r_max); + if (!T_min_valid && !T_max_valid){ + throw CoolProp::ValueError(format("Both T_min [%g] and T_max [%g] yield invalid output values in Brent_HAProps_T",T_min,T_max).c_str()); + } + else if (T_min_valid && !T_max_valid){ + while (!T_max_valid){ + // Reduce T_max until it works + T_max = 0.95*T_max + 0.05*T_min; + r_max = BSR.call(T_max); + T_max_valid = ValidNumber(r_max); + } + } + else if (!T_min_valid && T_max_valid){ + while (!T_min_valid){ + // Increase T_min until it works + T_min = 0.95*T_min + 0.05*T_max; + r_min = BSR.call(T_min); + T_min_valid = ValidNumber(r_min); + } + } + T = CoolProp::Brent(BSR, T_min, T_max, 1e-7, 1e-4, 50, errstr); + + return T; +} +static double Secant_Tdb_at_saturated_W(double psi_w, double p, double T_guess) +{ + double T; + class BrentSolverResids : public CoolProp::FuncWrapper1D + { + private: + double pp_water, psi_w, p, r; + public: + BrentSolverResids(double psi_w, double p) : psi_w(psi_w), p(p) { pp_water = psi_w*p; }; + ~BrentSolverResids(){}; + + double call(double T){ + double p_ws; + if (T>=273.16) + { + // Saturation pressure [Pa] + Water->update(CoolProp::QT_INPUTS, 0, T); + p_ws= Water->keyed_output(CoolProp::iP); + } + else + { + // Sublimation pressure [Pa] + p_ws=psub_Ice(T); + + } + double f = f_factor(T, p); + double pp_water_calc = f*p_ws; + double psi_w_calc = pp_water_calc/p; + r = (psi_w_calc - psi_w)/psi_w; + return r; + } + }; + + BrentSolverResids Resids(psi_w, p); + + std::string errstr; + T = CoolProp::Secant(Resids, 150, 100, 1e-7, 100, errstr); return T; } @@ -1327,13 +1392,10 @@ double HAPropsSI(const std::string &OutputName, const std::string &Input1Name, d // Get the integer type codes Type1=Name2Type(Name1); Type2=Name2Type(Name2); - - // First, if one of the inputs is something that can potentially yield - // an explicit solution at a given iteration of the solver, use it - if (Type1==GIVEN_RH || Type1==GIVEN_HUMRAT || Type1==GIVEN_TDP) + + // First see if humidity ratio is provided, will be the fastest option + if (Type1 == GIVEN_HUMRAT) { - // First input variable is a "nice" one - // MainInput is the one that you are using in the call to HAProps MainInputValue=Value1; strcpy(MainInputName,Name1); @@ -1341,29 +1403,61 @@ double HAPropsSI(const std::string &OutputName, const std::string &Input1Name, d SecondaryInputValue=Value2; strcpy(SecondaryInputName,Name2); } - else if (Type2==GIVEN_RH || Type2==GIVEN_HUMRAT || Type2==GIVEN_TDP) + else if (Type2 == GIVEN_HUMRAT) { - // Second input variable is a "nice" one - - // MainInput is the one that you are using in the call to HAProps - MainInputValue=Value2; - strcpy(MainInputName,Name2); + // MainInput is the one that you are using in the call to HAPropsSI + MainInputValue=Value2; strcpy(MainInputName, Name2); // SecondaryInput is the one that you are trying to match - SecondaryInputValue=Value1; - strcpy(SecondaryInputName,Name1); + SecondaryInputValue=Value1; strcpy(SecondaryInputName, Name1); + } + // Next, if one of the inputs is something that can potentially yield + // an explicit solution at a given iteration of the solver, use it + else if (Type1 == GIVEN_RH || Type1 == GIVEN_TDP) + { + // MainInput is the one that you are using in the call to HAProps + MainInputValue = Value1; strcpy(MainInputName, Name1); + // SecondaryInput is the one that you are trying to match + SecondaryInputValue = Value2; strcpy(SecondaryInputName, Name2); + } + else if (Type2 == GIVEN_RH || Type2 == GIVEN_TDP) + { + // MainInput is the one that you are using in the call to HAProps + MainInputValue = Value2; strcpy(MainInputName, Name2); + // SecondaryInput is the one that you are trying to match + SecondaryInputValue=Value1; strcpy(SecondaryInputName, Name1); } else { printf("Sorry, but currently at least one of the variables as an input to HAPropsSI() must be temperature, relative humidity, humidity ratio, or dewpoint\n Eventually will add a 2-D NR solver to find T and psi_w simultaneously, but not included now\n"); - return -1000; + return _HUGE; } double T_min = 210; double T_max = 450; if (Name2Type(MainInputName) == GIVEN_RH){ - T_max = CoolProp::PropsSI("T","P",p,"Q",0,"Water") - 1; + if (MainInputValue < 1e-10){ + T_max = 1000; + } + else{ + T_max = CoolProp::PropsSI("T","P",p,"Q",0,"Water") - 1; + } } + // Minimum drybulb temperature is the drybulb temperature corresponding to saturated air for the humidity ratio + // if the humidity ratio is provided + else if (Name2Type(MainInputName) == GIVEN_HUMRAT){ + if (MainInputValue < 1e-10){ + T_min = 135; // Around the critical point of dry air + T_max = 1000; + } + else{ + // Calculate the saturated humid air water partial pressure; + double psi_w_sat = MoleFractionWater(T_min, p, GIVEN_HUMRAT, MainInputValue); + //double pp_water_sat = psi_w_sat*p; // partial pressure of water, which is equal to f*p_{w_s} + // Iteratively solve for temperature that will give desired pp_water_sat + T_min = Secant_Tdb_at_saturated_W(psi_w_sat, p, T_min); + } + } try{ // Use the Brent's method solver to find T. Slow but reliable @@ -1912,7 +2006,14 @@ TEST_CASE_METHOD(HAPropsConsistencyFixture, "ASHRAE RP1485 Tables", "[RP1485]") CHECK(std::abs(actual/expected-1) < 0.01); } } - } + +TEST_CASE("Assorted tests","[HAPropsSI]") +{ + CHECK(ValidNumber(HumidAir::HAPropsSI("T", "H", 267769, "P", 104300, "W", 0.0))); + CHECK(ValidNumber(HumidAir::HAPropsSI("T", "B", 252.84, "W", 5.097e-4, "P", 101325))); + CHECK(ValidNumber(HumidAir::HAPropsSI("T", "B", 290, "R", 1, "P", 101325))); +} + #endif /* CATCH_ENABLED */ From de2105fafba5952b7c351a8fed5dd133e4b52093 Mon Sep 17 00:00:00 2001 From: Ian Bell Date: Mon, 19 Jan 2015 16:34:24 -0700 Subject: [PATCH 33/69] Add tests for HAPropsSI Also, if an output is the same as the input, return the input directly Signed-off-by: Ian Bell --- src/HumidAirProp.cpp | 133 ++++++++++++++++++++++++++++++++++++------- 1 file changed, 111 insertions(+), 22 deletions(-) diff --git a/src/HumidAirProp.cpp b/src/HumidAirProp.cpp index 157650b7..2e23de71 100644 --- a/src/HumidAirProp.cpp +++ b/src/HumidAirProp.cpp @@ -13,12 +13,14 @@ #include "crossplatform_shared_ptr.h" #include "Exceptions.h" +#include // std::next_permutation #include #include "math.h" #include "time.h" #include "stdio.h" #include #include +#include /// This is a stub overload to help with all the strcmp calls below and avoid needing to rewrite all of them std::size_t strcmp(const std::string &s, const std::string e){ @@ -166,7 +168,8 @@ static double Brent_HAProps_T(const std::string &OutputName, const std::string & ~BrentSolverResids(){}; double call(double T){ - return HAPropsSI(OutputName,"T",T,Input1Name,Input1,Input2Name,Input2)-TargetVal; + double val = HAPropsSI(OutputName, "T", T, Input1Name, Input1, Input2Name, Input2); + return val - TargetVal; } }; @@ -198,8 +201,19 @@ static double Brent_HAProps_T(const std::string &OutputName, const std::string & T_min_valid = ValidNumber(r_min); } } - T = CoolProp::Brent(BSR, T_min, T_max, 1e-7, 1e-4, 50, errstr); - + // We will do a secant call if the values at T_min and T_max have the same sign + if (r_min*r_max > 0){ + if (std::abs(r_min) < std::abs(r_max)){ + T = CoolProp::Secant(BSR, T_min, 0.01*T_min, 1e-7, 50, errstr); + } + else{ + T = CoolProp::Secant(BSR, T_max, -0.01*T_max, 1e-7, 50, errstr); + } + } + else{ + T = CoolProp::Brent(BSR, T_min, T_max, 1e-7, 1e-4, 50, errstr); + } + return T; } static double Secant_Tdb_at_saturated_W(double psi_w, double p, double T_guess) @@ -215,17 +229,14 @@ static double Secant_Tdb_at_saturated_W(double psi_w, double p, double T_guess) double call(double T){ double p_ws; - if (T>=273.16) - { + if (T>=273.16){ // Saturation pressure [Pa] Water->update(CoolProp::QT_INPUTS, 0, T); p_ws= Water->keyed_output(CoolProp::iP); } - else - { + else{ // Sublimation pressure [Pa] p_ws=psub_Ice(T); - } double f = f_factor(T, p); double pp_water_calc = f*p_ws; @@ -238,7 +249,7 @@ static double Secant_Tdb_at_saturated_W(double psi_w, double p, double T_guess) BrentSolverResids Resids(psi_w, p); std::string errstr; - T = CoolProp::Secant(Resids, 150, 100, 1e-7, 100, errstr); + T = CoolProp::Brent(Resids, 150, 350, 1e-16, 1e-7, 100, errstr); return T; } @@ -1154,7 +1165,6 @@ double MoleFractionWater(double T, double p, int HumInput, double InVal) { // Sublimation pressure [Pa] p_ws=psub_Ice(T); - } // Enhancement Factor [-] f=f_factor(T,p); @@ -1276,8 +1286,8 @@ double HAPropsSI(const std::string &OutputName, const std::string &Input1Name, d { // Add a check to make sure that Air and Water fluid states have been properly instantiated check_fluid_instantiation(); - - int In1Type, In2Type, In3Type,iT,iW,iTdp,iRH,ip,Type1,Type2; + int iT, iW, iTdp, iRH, ip; + givens In1Type, In2Type, In3Type, Type1, Type2, OutputType; double vals[3],p,T,RH,W,Tdp,psi_w,M_ha,v_bar,h_bar,s_bar,MainInputValue,SecondaryInputValue,T_guess; double Value1,Value2,W_guess; std::string MainInputName, SecondaryInputName, Name1, Name2; @@ -1285,11 +1295,17 @@ double HAPropsSI(const std::string &OutputName, const std::string &Input1Name, d vals[0]=Input1; vals[1]=Input2; vals[2]=Input3; + + OutputType=Name2Type(OutputName.c_str()); // First figure out what kind of inputs you have, convert names to Macro expansions In1Type=Name2Type(Input1Name.c_str()); In2Type=Name2Type(Input2Name.c_str()); In3Type=Name2Type(Input3Name.c_str()); + + if (OutputType == In1Type){return Input1;} + if (OutputType == In2Type){return Input2;} + if (OutputType == In3Type){return Input3;} // Pressure must be included ip=TypeMatch(GIVEN_P,Input1Name,Input2Name,Input3Name); @@ -1331,17 +1347,17 @@ double HAPropsSI(const std::string &OutputName, const std::string &Input1Name, d // Temperature and pressure are known, figure out which variable holds the other value if (In1Type!=GIVEN_T && In1Type!=GIVEN_P) { - strcpy(SecondaryInputName,Input1Name); + strcpy(SecondaryInputName, Input1Name); SecondaryInputValue=Input1; } else if (In2Type!=GIVEN_T && In2Type!=GIVEN_P) { - strcpy(SecondaryInputName,Input2Name); + strcpy(SecondaryInputName, Input2Name); SecondaryInputValue=Input2; } else if (In3Type!=GIVEN_T && In3Type!=GIVEN_P) { - strcpy(SecondaryInputName,Input3Name); + strcpy(SecondaryInputName, Input3Name); SecondaryInputValue=Input3; } else{ @@ -1397,11 +1413,9 @@ double HAPropsSI(const std::string &OutputName, const std::string &Input1Name, d if (Type1 == GIVEN_HUMRAT) { // MainInput is the one that you are using in the call to HAProps - MainInputValue=Value1; - strcpy(MainInputName,Name1); + MainInputValue=Value1; strcpy(MainInputName,Name1); // SecondaryInput is the one that you are trying to match - SecondaryInputValue=Value2; - strcpy(SecondaryInputName,Name2); + SecondaryInputValue=Value2; strcpy(SecondaryInputName,Name2); } else if (Type2 == GIVEN_HUMRAT) { @@ -1428,11 +1442,11 @@ double HAPropsSI(const std::string &OutputName, const std::string &Input1Name, d } else { - printf("Sorry, but currently at least one of the variables as an input to HAPropsSI() must be temperature, relative humidity, humidity ratio, or dewpoint\n Eventually will add a 2-D NR solver to find T and psi_w simultaneously, but not included now\n"); + CoolProp::ValueError("Sorry, but currently at least one of the variables as an input to HAPropsSI() must be temperature, relative humidity, humidity ratio, or dewpoint\n Eventually will add a 2-D NR solver to find T and psi_w simultaneously, but not included now\n"); return _HUGE; } - double T_min = 210; + double T_min = 200; double T_max = 450; if (Name2Type(MainInputName) == GIVEN_RH){ @@ -2007,13 +2021,88 @@ TEST_CASE_METHOD(HAPropsConsistencyFixture, "ASHRAE RP1485 Tables", "[RP1485]") } } } - TEST_CASE("Assorted tests","[HAPropsSI]") { CHECK(ValidNumber(HumidAir::HAPropsSI("T", "H", 267769, "P", 104300, "W", 0.0))); CHECK(ValidNumber(HumidAir::HAPropsSI("T", "B", 252.84, "W", 5.097e-4, "P", 101325))); CHECK(ValidNumber(HumidAir::HAPropsSI("T", "B",290, "R", 1, "P", 101325))); } +// a predicate implemented as a function: +bool is_not_a_pair (const std::set &item) { return item.size() != 2; } + +const int number_of_inputs = 6; +std::string inputs[number_of_inputs] = {"W","D","B","R","T","V"};//,"H","S"}; + +class ConsistencyTestData +{ +public: + bool is_built; + std::vector data; + std::list > inputs_list; + ConsistencyTestData(){ + is_built = false; + }; + void build(){ + if (is_built){return;} + std::vector indices(number_of_inputs); + for (std::size_t i = 0; i < number_of_inputs; ++i){ indices[i] = i;} + // Generate a powerset of all the permutations of all lengths of inputs + std::set indices_set(indices.begin(), indices.end()); + std::set > inputs_powerset = powerset(indices_set); + inputs_list = std::list >(inputs_powerset.begin(), inputs_powerset.end()); + inputs_list.remove_if(is_not_a_pair); + + const int NT = 20, NW = 20; + double p = 101325; + for (double T = 210; T < 350; T += (350-210)/(NT-1)) + { + double Wsat = HumidAir::HAPropsSI("W", "T", T, "P", p, "R", 1.0); + for (double W = 1e-10; W < Wsat; W += (Wsat-1e-10)/(NW-1)){ + Dictionary vals; + // Calculate all the values using T, W + for (int i = 0; i < number_of_inputs; ++i){ + double v = HumidAir::HAPropsSI(inputs[i], "T", T, "P", p, "W", W); + vals.add_number(inputs[i], v); + } + data.push_back(vals); + std::cout << format("T %g W %g\n",T,W); + } + } + is_built = true; + }; +} consistency_data; + +TEST_CASE("HAPropsSI", "[HAPropsSI]") +{ + consistency_data.build(); + double p = 101325; + for (std::size_t i = 0; i < consistency_data.data.size(); ++i) + { + for (std::list >::iterator iter = consistency_data.inputs_list.begin(); iter != consistency_data.inputs_list.end(); ++iter) + { + std::vector pair(iter->begin(), iter->end()); + std::string i0 = inputs[pair[0]], i1 = inputs[pair[1]]; + double v0 = consistency_data.data[i].get_double(i0), v1 = consistency_data.data[i].get_double(i1); + std::ostringstream ss2; + ss2 << "Inputs: \"" << i0 << "\"," << v0 << ",\"" << i1 << "\"," << v1; + SECTION(ss2.str(), ""){ + + double T = consistency_data.data[i].get_double("T"); + double W = consistency_data.data[i].get_double("W"); + double Wcalc = HumidAir::HAPropsSI("W", i0, v0, i1, v1, "P", p); + double Tcalc = HumidAir::HAPropsSI("T", i0, v0, i1, v1, "P", p); + std::string err = CoolProp::get_global_param_string("errstring"); + CAPTURE(T); + CAPTURE(W); + CAPTURE(Tcalc); + CAPTURE(Wcalc); + CAPTURE(err); + CHECK(std::abs(Tcalc - T) < 1e-1); + CHECK(std::abs((Wcalc - W)/W) < 1e-3); + } + } + } +} #endif /* CATCH_ENABLED */ From 4ebe23ed95a48c20d02fad0347200387eec0b01a Mon Sep 17 00:00:00 2001 From: Ian Bell Date: Mon, 19 Jan 2015 17:28:54 -0700 Subject: [PATCH 34/69] Comment out the HAPropsSI code consistency test Signed-off-by: Ian Bell --- include/CoolPropTools.h | 88 ++++++++++++++++++++++++++++++----------- src/HumidAirProp.cpp | 11 ++++-- 2 files changed, 73 insertions(+), 26 deletions(-) diff --git a/include/CoolPropTools.h b/include/CoolPropTools.h index 7d0827ac..34888d47 100644 --- a/include/CoolPropTools.h +++ b/include/CoolPropTools.h @@ -95,6 +95,7 @@ #include #include #include + #include /// The following code for the trim functions was taken from http://stackoverflow.com/questions/216823/whats-the-best-way-to-trim-stdstring // trim from start @@ -319,30 +320,71 @@ return x; } - /// Some functions related to testing and comparison of values - bool inline check_abs(double A, double B, double D){ - double max = std::abs(A); - double min = std::abs(B); - if (min>max) { - max = min; - min = std::abs(A); - } - if (max>DBL_EPSILON*1e3) return ( ( 1.0-min/max*1e0 ) < D ); - else throw CoolProp::ValueError(format("Too small numbers: %f cannot be tested with an accepted error of %f for a machine precision of %f. ",max,D,DBL_EPSILON)); - }; - bool inline check_abs(double A, double B){ - return check_abs(A,B,1e5*DBL_EPSILON); - }; - - template void normalize_vector(std::vector &x) +// From http://rosettacode.org/wiki/Power_set#C.2B.2B +inline std::size_t powerset_dereference(std::set::const_iterator v) { return *v; }; + +// From http://rosettacode.org/wiki/Power_set#C.2B.2B +inline std::set > powerset(std::set const& set) +{ + std::set > result; + std::vector::const_iterator> elements; + do + { + std::set tmp; + std::transform(elements.begin(), elements.end(), + std::inserter(tmp, tmp.end()), + powerset_dereference); + result.insert(tmp); + if (!elements.empty() && ++elements.back() == set.end()) { - // Sum up all the elements in the vector - T sumx = std::accumulate( x.begin(), x.end(), static_cast(0) ); - // Normalize the components by dividing each by the sum - for (std::size_t i = 0; i < x.size(); ++i){ - x[i] /= sumx; - } - }; + elements.pop_back(); + } + else + { + std::set::const_iterator iter; + if (elements.empty()) + { + iter = set.begin(); + } + else + { + iter = elements.back(); + ++iter; + } + for (; iter != set.end(); ++iter) + { + elements.push_back(iter); + } + } + } while (!elements.empty()); + + return result; +} + +/// Some functions related to testing and comparison of values +bool inline check_abs(double A, double B, double D){ + double max = std::abs(A); + double min = std::abs(B); + if (min>max) { + max = min; + min = std::abs(A); + } + if (max>DBL_EPSILON*1e3) return ( ( 1.0-min/max*1e0 ) < D ); + else throw CoolProp::ValueError(format("Too small numbers: %f cannot be tested with an accepted error of %f for a machine precision of %f. ",max,D,DBL_EPSILON)); +}; +bool inline check_abs(double A, double B){ + return check_abs(A,B,1e5*DBL_EPSILON); +}; + +template void normalize_vector(std::vector &x) +{ + // Sum up all the elements in the vector + T sumx = std::accumulate( x.begin(), x.end(), static_cast(0) ); + // Normalize the components by dividing each by the sum + for (std::size_t i = 0; i < x.size(); ++i){ + x[i] /= sumx; + } +}; #define CATCH_ALL_ERRORS_RETURN_HUGE(x) try{ \ x \ diff --git a/src/HumidAirProp.cpp b/src/HumidAirProp.cpp index 2e23de71..d27202b0 100644 --- a/src/HumidAirProp.cpp +++ b/src/HumidAirProp.cpp @@ -283,7 +283,7 @@ static double Secant_HAProps_T(const std::string &OutputName, const std::string static double Secant_HAProps_W(const std::string &OutputName, const std::string &Input1Name, double Input1, const std::string &Input2Name, double Input2, double TargetVal, double W_guess) { // Use a secant solve in order to yield a target output value for HAProps by altering humidity ratio - double x1=0,x2=0,x3=0,y1=0,y2=0,eps=1e-8,f=999,W=0.0001; + double x1=0,x2=0,x3=0,y1=0,y2=0,eps=1e-12,f=999,W=0.0001; int iter=1; while ((iter<=3 || std::abs(f)>eps) && iter<100) @@ -2052,12 +2052,12 @@ public: inputs_list = std::list >(inputs_powerset.begin(), inputs_powerset.end()); inputs_list.remove_if(is_not_a_pair); - const int NT = 20, NW = 20; + const int NT = 10, NW = 5; double p = 101325; for (double T = 210; T < 350; T += (350-210)/(NT-1)) { double Wsat = HumidAir::HAPropsSI("W", "T", T, "P", p, "R", 1.0); - for (double W = 1e-10; W < Wsat; W += (Wsat-1e-10)/(NW-1)){ + for (double W = 1e-5; W < Wsat; W += (Wsat-1e-5)/(NW-1)){ Dictionary vals; // Calculate all the values using T, W for (int i = 0; i < number_of_inputs; ++i){ @@ -2072,6 +2072,9 @@ public: }; } consistency_data; +/* + * This test is incredibly slow, which is why it is currently commented out. Many of the tests also fail + * TEST_CASE("HAPropsSI", "[HAPropsSI]") { consistency_data.build(); @@ -2083,6 +2086,7 @@ TEST_CASE("HAPropsSI", "[HAPropsSI]") std::vector pair(iter->begin(), iter->end()); std::string i0 = inputs[pair[0]], i1 = inputs[pair[1]]; double v0 = consistency_data.data[i].get_double(i0), v1 = consistency_data.data[i].get_double(i1); + if ((i0 == "B" && i1 == "V") || (i1 == "B" && i0 == "V")){continue;} std::ostringstream ss2; ss2 << "Inputs: \"" << i0 << "\"," << v0 << ",\"" << i1 << "\"," << v1; SECTION(ss2.str(), ""){ @@ -2103,6 +2107,7 @@ TEST_CASE("HAPropsSI", "[HAPropsSI]") } } } + */ #endif /* CATCH_ENABLED */ From 02dc2fa8609465c64b6464f2a7aedccf004352aa Mon Sep 17 00:00:00 2001 From: Ian Bell Date: Mon, 19 Jan 2015 19:41:54 -0700 Subject: [PATCH 35/69] Fix bug with inserter Signed-off-by: Ian Bell --- include/CoolPropTools.h | 1 + 1 file changed, 1 insertion(+) diff --git a/include/CoolPropTools.h b/include/CoolPropTools.h index 34888d47..dbd4990f 100644 --- a/include/CoolPropTools.h +++ b/include/CoolPropTools.h @@ -87,6 +87,7 @@ #define DEPRECATED(func) func #endif + #include #include #include #include From 06003c6ff60dd0acf2962937c9eef84253215f4f Mon Sep 17 00:00:00 2001 From: Ian Bell Date: Mon, 19 Jan 2015 21:29:00 -0700 Subject: [PATCH 36/69] Error if matrix input in PropsSI in python; Closes #387 Signed-off-by: Ian Bell --- wrappers/Python/CoolProp/CoolProp.pyx | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/wrappers/Python/CoolProp/CoolProp.pyx b/wrappers/Python/CoolProp/CoolProp.pyx index 3a633f3c..2e176462 100644 --- a/wrappers/Python/CoolProp/CoolProp.pyx +++ b/wrappers/Python/CoolProp/CoolProp.pyx @@ -223,6 +223,12 @@ cpdef PropsSI(in1, in2, in3 = None, in4 = None, in5 = None, in6 = None, in7 = No is_iterable1 = iterable(in1) is_iterable3 = iterable(in3) is_iterable5 = iterable(in5) + + if _numpy_supported and is_iterable3 and isinstance(in3, np.ndarray) and (np.prod(in3.shape) != max(in3.shape)): + raise ValueError("Input 3 is not one-dimensional") + if _numpy_supported and is_iterable5 and isinstance(in5, np.ndarray) and (np.prod(in5.shape) != max(in5.shape)): + raise ValueError("Input 5 is not one-dimensional") + if is_iterable1 or is_iterable3 or is_iterable5: # Prepare the output datatype if not is_iterable1: From 104175dfa1a2f5bc1e5bc7016c0815af7d15854f Mon Sep 17 00:00:00 2001 From: Jorrit Wronski Date: Tue, 20 Jan 2015 10:48:50 +0100 Subject: [PATCH 37/69] Trying to fix #413 --- include/IncompressibleFluid.h | 2 +- src/Backends/Incompressible/IncompressibleFluid.cpp | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/include/IncompressibleFluid.h b/include/IncompressibleFluid.h index f446e7d9..cbd3aa54 100644 --- a/include/IncompressibleFluid.h +++ b/include/IncompressibleFluid.h @@ -150,7 +150,7 @@ public: double getpref() const {return pref;} double getxref() const {return xref;} double gethref() const {return href;} - double getsref() {return s(Tref,pref,xref) - sref;} + double getsref() {return sref;} double getTbase() const {return Tbase;} double getxbase() const {return xbase;} diff --git a/src/Backends/Incompressible/IncompressibleFluid.cpp b/src/Backends/Incompressible/IncompressibleFluid.cpp index 2c16da2f..69c7754d 100644 --- a/src/Backends/Incompressible/IncompressibleFluid.cpp +++ b/src/Backends/Incompressible/IncompressibleFluid.cpp @@ -23,11 +23,12 @@ void IncompressibleFluid::set_reference_state(double T0, double p0, double x0, d this->rhoref = rho(T0,p0,x0); this->pref = p0; this->href = h0; + this->sref = s0; // Now we take care of the energy related values this->uref = 0.0; this->uref = u(T0,p0,x0) - h0; // (value without ref) - (desired ref) - this->sref = 0.0; - this->sref = s(T0,p0,x0) - s0; // (value without ref) - (desired ref) + //this->sref = 0.0; + //this->sref = s(T0,p0,x0) - s0; // (value without ref) - (desired ref) } void IncompressibleFluid::validate(){ From 2a325ab6e697bec95b0d4994e90b9e04d1408725 Mon Sep 17 00:00:00 2001 From: Jorrit Wronski Date: Tue, 20 Jan 2015 12:32:14 +0100 Subject: [PATCH 38/69] still issues with #413 --- .../Incompressible/IncompressibleFluid.cpp | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/src/Backends/Incompressible/IncompressibleFluid.cpp b/src/Backends/Incompressible/IncompressibleFluid.cpp index 69c7754d..f0d7cb7b 100644 --- a/src/Backends/Incompressible/IncompressibleFluid.cpp +++ b/src/Backends/Incompressible/IncompressibleFluid.cpp @@ -23,12 +23,11 @@ void IncompressibleFluid::set_reference_state(double T0, double p0, double x0, d this->rhoref = rho(T0,p0,x0); this->pref = p0; this->href = h0; - this->sref = s0; // Now we take care of the energy related values this->uref = 0.0; this->uref = u(T0,p0,x0) - h0; // (value without ref) - (desired ref) - //this->sref = 0.0; - //this->sref = s(T0,p0,x0) - s0; // (value without ref) - (desired ref) + this->sref = 0.0; + this->sref = s(T0,p0,x0) - s0; // (value without ref) - (desired ref) } void IncompressibleFluid::validate(){ @@ -665,8 +664,20 @@ TEST_CASE("Internal consistency checks and example use cases for the incompressi // Compare reference state { res = XLT.h(Tref,pref,xref); + CAPTURE(Tref); + CAPTURE(pref); + CAPTURE(xref); + CAPTURE(href) + CAPTURE(res) CHECK( check_abs(href,res,acc) ); + } + { res = XLT.s(Tref,pref,xref); + CAPTURE(Tref); + CAPTURE(pref); + CAPTURE(xref); + CAPTURE(sref) + CAPTURE(res) CHECK( check_abs(sref,res,acc) ); } From 9ac0426f9a4ace2c1e10e9b2ca27d76a4202f29d Mon Sep 17 00:00:00 2001 From: Jorrit Wronski Date: Tue, 20 Jan 2015 18:19:30 +0100 Subject: [PATCH 39/69] Added a default concentration of 0.0 for incomperssible pure fluids. --- Web/scripts/fluid_properties.Incompressibles.sh | 0 .../Incompressible/IncompressibleBackend.cpp | 17 ++++++++++++++--- 2 files changed, 14 insertions(+), 3 deletions(-) mode change 100644 => 100755 Web/scripts/fluid_properties.Incompressibles.sh diff --git a/Web/scripts/fluid_properties.Incompressibles.sh b/Web/scripts/fluid_properties.Incompressibles.sh old mode 100644 new mode 100755 diff --git a/src/Backends/Incompressible/IncompressibleBackend.cpp b/src/Backends/Incompressible/IncompressibleBackend.cpp index 338526c0..0b83405e 100644 --- a/src/Backends/Incompressible/IncompressibleBackend.cpp +++ b/src/Backends/Incompressible/IncompressibleBackend.cpp @@ -26,11 +26,17 @@ IncompressibleBackend::IncompressibleBackend() { IncompressibleBackend::IncompressibleBackend(IncompressibleFluid* fluid) { //this->_fractions_id = fluid->getxid(); this->fluid = fluid; + if (this->fluid->is_pure()){ + this->set_fractions(std::vector(1,0)); + } } IncompressibleBackend::IncompressibleBackend(const std::string &fluid_name) { this->fluid = &get_incompressible_fluid(fluid_name); //this->_fractions_id = this->fluid->getxid(); + if (this->fluid->is_pure()){ + this->set_fractions(std::vector(1,0)); + } } IncompressibleBackend::IncompressibleBackend(const std::vector &component_names) { @@ -49,17 +55,22 @@ void IncompressibleBackend::update(CoolProp::input_pairs input_pair, double valu clear(); - if (get_debug_level()>=50) std::cout << format("Incompressible backend: _fractions are %s ",vec_to_string(_fractions).c_str()) << std::endl; + if (get_debug_level()>=50) { + std::cout << format("Incompressible backend: _fractions are %s ",vec_to_string(_fractions).c_str()) << std::endl; + } + if (_fractions.size()!=1){ + throw ValueError(format("%s is an incompressible fluid, mass fractions must be set to a vector with ONE entry, not %d.",this->name().c_str(),_fractions.size())); + } if (fluid->is_pure()){ this->_fluid_type = FLUID_TYPE_INCOMPRESSIBLE_LIQUID; if (get_debug_level()>=50) std::cout << format("Incompressible backend: Fluid type is %d ",this->_fluid_type) << std::endl; - if ((_fractions.size()!=1) || (_fractions[0]!=0.0)){ + if (_fractions[0]!=0.0){ throw ValueError(format("%s is a pure fluid. The composition has to be set to a vector with one entry equal to 0.0 or nothing. %s is not valid.",this->name().c_str(),vec_to_string(_fractions).c_str())); } } else { this->_fluid_type = FLUID_TYPE_INCOMPRESSIBLE_SOLUTION; if (get_debug_level()>=50) std::cout << format("Incompressible backend: Fluid type is %d ",this->_fluid_type) << std::endl; - if (_fractions.size()!=1 || ((_fractions[0]<0.0) || (_fractions[0]>1.0)) ){ + if ( (_fractions[0]<0.0) || (_fractions[0]>1.0) ){ throw ValueError(format("%s is a solution or brine. Mass fractions must be set to a vector with one entry between 0 and 1. %s is not valid.",this->name().c_str(),vec_to_string(_fractions).c_str())); } } From 433d6aa9b96a51e18a660322d51671fc2aaa7015 Mon Sep 17 00:00:00 2001 From: Ian Bell Date: Tue, 20 Jan 2015 19:36:09 -0700 Subject: [PATCH 40/69] Fixed hyperlink for doxygen; See #416 Signed-off-by: Ian Bell --- Web/develop/code.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Web/develop/code.rst b/Web/develop/code.rst index 37b2379d..e0be2bc6 100644 --- a/Web/develop/code.rst +++ b/Web/develop/code.rst @@ -10,7 +10,7 @@ The source code of CoolProp is stored in a github repository at https://github.c Doxygen formatted documentation of the source files --------------------------------------------------- -Real-time builds of the `doxygen `_ formatted HTML outputs for the development code are at :bbsphinx:`the buildbot development server<_static/doxygen/html>`. +Real-time builds of the `doxygen `_ formatted HTML outputs for the development code are at :bbsphinx:`the buildbot development server`. More information ---------------- From f03d0b5bb90eef0d3278ce61a840680d25947844 Mon Sep 17 00:00:00 2001 From: Ian Bell Date: Tue, 20 Jan 2015 20:57:06 -0700 Subject: [PATCH 41/69] Fixed Humid air example that was hanging Signed-off-by: Ian Bell --- Web/coolprop/examples/examples.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Web/coolprop/examples/examples.rst b/Web/coolprop/examples/examples.rst index eef7538d..a312aafc 100644 --- a/Web/coolprop/examples/examples.rst +++ b/Web/coolprop/examples/examples.rst @@ -46,10 +46,10 @@ To use the HAProps function, import it and do some calls, do something like this In [2]: h = HAPropsSI('H','T',298.15,'P',101325,'R',0.5); print h # Temperature of saturated air at the previous enthalpy - In [2]: T = HAPropsSI('T','P',101.325,'H',h,'R',1.0); print T + In [2]: T = HAPropsSI('T','P',101325,'H',h,'R',1.0); print T # Temperature of saturated air - order of inputs doesn't matter - In [2]: T = HAPropsSI('T','H',h,'R',1.0,'P',101.325); print T + In [2]: T = HAPropsSI('T','H',h,'R',1.0,'P',101325); print T Or go to the :ref:`Humid-Air` documentation. From 7e020965f1f970b45074705dc4692f5ca90d88ea Mon Sep 17 00:00:00 2001 From: Ian Bell Date: Tue, 20 Jan 2015 21:19:28 -0700 Subject: [PATCH 42/69] Added link to main page. Closes #416 --- Web/index.rst | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Web/index.rst b/Web/index.rst index 93a5bf15..85e9b4d5 100644 --- a/Web/index.rst +++ b/Web/index.rst @@ -7,7 +7,6 @@ These pages help you to get started using CoolProp and provide detailed informat returning user. Please feel free to browse the pages and use the menu on the left to navigate on this website. - What is CoolProp? ----------------- @@ -18,7 +17,6 @@ CoolProp is a C++ library that implements: - :ref:`Correlations of properties of incompressible fluids and brines ` - :ref:`Highest accuracy psychrometric routines ` - Environments Supported ---------------------- @@ -48,6 +46,7 @@ Help - File a `Github issue `_ - Email the `Google group `_ +- `Docs for v4 of CoolProp `_ Projects Using CoolProp From f52e59bba202bec968c1a18a9c5f97fb81141a94 Mon Sep 17 00:00:00 2001 From: Jorrit Wronski Date: Sun, 25 Jan 2015 22:42:40 +0100 Subject: [PATCH 43/69] Thanks to Vittorio Carosella who reported #425. This commit closes #425, which was caused by two errors in the conversion function for the Melinder coefficients. --- .../CPIncomp/DataObjects.py | 5 ++- .../json/ExampleMelinder.json | 38 +++++++++---------- dev/incompressible_liquids/json/MAM.json | 38 +++++++++---------- dev/incompressible_liquids/json/MCA.json | 38 +++++++++---------- dev/incompressible_liquids/json/MEA.json | 38 +++++++++---------- dev/incompressible_liquids/json/MEG.json | 38 +++++++++---------- dev/incompressible_liquids/json/MGL.json | 38 +++++++++---------- dev/incompressible_liquids/json/MKA.json | 38 +++++++++---------- dev/incompressible_liquids/json/MKC.json | 38 +++++++++---------- dev/incompressible_liquids/json/MKF.json | 38 +++++++++---------- dev/incompressible_liquids/json/MLI.json | 38 +++++++++---------- dev/incompressible_liquids/json/MMA.json | 38 +++++++++---------- dev/incompressible_liquids/json/MMG.json | 38 +++++++++---------- dev/incompressible_liquids/json/MNA.json | 26 ++++++------- dev/incompressible_liquids/json/MPG.json | 38 +++++++++---------- 15 files changed, 263 insertions(+), 262 deletions(-) diff --git a/dev/incompressible_liquids/CPIncomp/DataObjects.py b/dev/incompressible_liquids/CPIncomp/DataObjects.py index 23b945e5..bfeb2a7e 100644 --- a/dev/incompressible_liquids/CPIncomp/DataObjects.py +++ b/dev/incompressible_liquids/CPIncomp/DataObjects.py @@ -581,8 +581,9 @@ class CoefficientData(SolutionData): self.conductivity.coeffs = self.convertMelinderArray(coeffs[3]) self.viscosity.source = self.viscosity.SOURCE_COEFFS - self.viscosity.type = self.viscosity.INCOMPRESSIBLE_POLYNOMIAL - self.viscosity.coeffs = self.convertMelinderArray(coeffs[4])/1e3 + self.viscosity.type = self.viscosity.INCOMPRESSIBLE_EXPPOLYNOMIAL + self.viscosity.coeffs = self.convertMelinderArray(coeffs[4]) + self.viscosity.coeffs[0,0] -= math.log(1000) # Fixes the units mPa s -> Pa s diff --git a/dev/incompressible_liquids/json/ExampleMelinder.json b/dev/incompressible_liquids/json/ExampleMelinder.json index e502d749..8a5caa6a 100644 --- a/dev/incompressible_liquids/json/ExampleMelinder.json +++ b/dev/incompressible_liquids/json/ExampleMelinder.json @@ -145,39 +145,39 @@ "viscosity": { "coeffs": [ [ - 1.153000e-03, - 5.448000e-04, - -5.552000e-03, - 3.038000e-03, - 6.669000e-03, - -8.472000e-03 + -5.754755e+00, + 5.448000e-01, + -5.552000e+00, + 3.038000e+00, + 6.669000e+00, + -8.472000e+00 ], [ - -3.866000e-05, - 1.008000e-05, - 8.384000e-05, - -7.435000e-05, - -9.105000e-05, + -3.866000e-02, + 1.008000e-02, + 8.384000e-02, + -7.435000e-02, + -9.105000e-02, 0.000000e+00 ], [ - 2.779000e-07, - -2.809000e-07, - -3.997000e-07, - 7.442000e-07, + 2.779000e-04, + -2.809000e-04, + -3.997000e-04, + 7.442000e-04, 0.000000e+00, 0.000000e+00 ], [ - -1.543000e-09, - 9.811000e-10, - -3.466000e-09, + -1.543000e-06, + 9.811000e-07, + -3.466000e-06, 0.000000e+00, 0.000000e+00, 0.000000e+00 ] ], - "type": "polynomial" + "type": "exppolynomial" }, "volume2input": { "coeffs": "null", diff --git a/dev/incompressible_liquids/json/MAM.json b/dev/incompressible_liquids/json/MAM.json index b36c69ed..7f893afa 100644 --- a/dev/incompressible_liquids/json/MAM.json +++ b/dev/incompressible_liquids/json/MAM.json @@ -145,39 +145,39 @@ "viscosity": { "coeffs": [ [ - 9.255000e-04, - 1.327000e-03, - -5.979000e-03, - -1.097000e-01, - 3.065000e-01, - 3.244000e+00 + -5.982255e+00, + 1.327000e+00, + -5.979000e+00, + -1.097000e+02, + 3.065000e+02, + 3.244000e+03 ], [ - -3.439000e-05, - 1.856000e-05, - -2.184000e-04, - 1.670000e-03, - -6.166000e-03, + -3.439000e-02, + 1.856000e-02, + -2.184000e-01, + 1.670000e+00, + -6.166000e+00, 0.000000e+00 ], [ - 3.217000e-07, - -1.646000e-06, - 1.297000e-05, - -3.377000e-05, + 3.217000e-04, + -1.646000e-03, + 1.297000e-02, + -3.377000e-02, 0.000000e+00, 0.000000e+00 ], [ - -4.544000e-09, - 3.004000e-08, - -1.141000e-07, + -4.544000e-06, + 3.004000e-05, + -1.141000e-04, 0.000000e+00, 0.000000e+00, 0.000000e+00 ] ], - "type": "polynomial" + "type": "exppolynomial" }, "volume2input": { "coeffs": "null", diff --git a/dev/incompressible_liquids/json/MCA.json b/dev/incompressible_liquids/json/MCA.json index f8a622dc..3f090b65 100644 --- a/dev/incompressible_liquids/json/MCA.json +++ b/dev/incompressible_liquids/json/MCA.json @@ -145,39 +145,39 @@ "viscosity": { "coeffs": [ [ - 8.939000e-04, - 4.389000e-03, - 9.121000e-03, - 1.963000e-03, - 2.997000e-02, - 3.435000e-01 + -6.013855e+00, + 4.389000e+00, + 9.121000e+00, + 1.963000e+00, + 2.997000e+01, + 3.435000e+02 ], [ - -2.647000e-05, - 2.102000e-05, - 3.993000e-05, - -4.892000e-04, - -3.631000e-03, + -2.647000e-02, + 2.102000e-02, + 3.993000e-02, + -4.892000e-01, + -3.631000e+00, 0.000000e+00 ], [ - 1.718000e-07, - -8.688000e-08, - 3.785000e-06, - 1.526000e-08, + 1.718000e-04, + -8.688000e-05, + 3.785000e-03, + 1.526000e-05, 0.000000e+00, 0.000000e+00 ], [ - -7.918000e-10, - -4.353000e-09, - -9.979000e-08, + -7.918000e-07, + -4.353000e-06, + -9.979000e-05, 0.000000e+00, 0.000000e+00, 0.000000e+00 ] ], - "type": "polynomial" + "type": "exppolynomial" }, "volume2input": { "coeffs": "null", diff --git a/dev/incompressible_liquids/json/MEA.json b/dev/incompressible_liquids/json/MEA.json index 33eb46de..8931dff6 100644 --- a/dev/incompressible_liquids/json/MEA.json +++ b/dev/incompressible_liquids/json/MEA.json @@ -145,39 +145,39 @@ "viscosity": { "coeffs": [ [ - 1.474000e-03, - 1.565000e-03, - -8.435000e-03, - 7.552000e-03, - 1.529000e-02, - -4.130000e-02 + -5.433755e+00, + 1.565000e+00, + -8.435000e+00, + 7.552000e+00, + 1.529000e+01, + -4.130000e+01 ], [ - -4.745000e-05, - -4.106000e-06, - 1.640000e-04, - -1.118000e-04, - -9.481000e-05, + -4.745000e-02, + -4.106000e-03, + 1.640000e-01, + -1.118000e-01, + -9.481000e-02, 0.000000e+00 ], [ - 4.314000e-07, - -5.135000e-07, - -1.091000e-06, - 1.899000e-06, + 4.314000e-04, + -5.135000e-04, + -1.091000e-03, + 1.899000e-03, 0.000000e+00, 0.000000e+00 ], [ - -3.023000e-09, - 7.004000e-09, - -1.967000e-08, + -3.023000e-06, + 7.004000e-06, + -1.967000e-05, 0.000000e+00, 0.000000e+00, 0.000000e+00 ] ], - "type": "polynomial" + "type": "exppolynomial" }, "volume2input": { "coeffs": "null", diff --git a/dev/incompressible_liquids/json/MEG.json b/dev/incompressible_liquids/json/MEG.json index 748ee094..a106639a 100644 --- a/dev/incompressible_liquids/json/MEG.json +++ b/dev/incompressible_liquids/json/MEG.json @@ -145,39 +145,39 @@ "viscosity": { "coeffs": [ [ - 4.705000e-04, - 2.471000e-03, - 3.328000e-05, - 1.659000e-03, - 3.089000e-03, - -1.865000e-02 + -6.437255e+00, + 2.471000e+00, + 3.328000e-02, + 1.659000e+00, + 3.089000e+00, + -1.865000e+01 ], [ - -2.550000e-05, - -1.171000e-05, - 1.086000e-05, - 3.157000e-06, - 1.831000e-05, + -2.550000e-02, + -1.171000e-02, + 1.086000e-02, + 3.157000e-03, + 1.831000e-02, 0.000000e+00 ], [ - 1.782000e-07, - 1.052000e-07, - 1.051000e-07, - 4.063000e-07, + 1.782000e-04, + 1.052000e-04, + 1.051000e-04, + 4.063000e-04, 0.000000e+00, 0.000000e+00 ], [ - -7.669000e-10, - -1.634000e-09, - -6.475000e-09, + -7.669000e-07, + -1.634000e-06, + -6.475000e-06, 0.000000e+00, 0.000000e+00, 0.000000e+00 ] ], - "type": "polynomial" + "type": "exppolynomial" }, "volume2input": { "coeffs": "null", diff --git a/dev/incompressible_liquids/json/MGL.json b/dev/incompressible_liquids/json/MGL.json index d9d372c7..248e6c19 100644 --- a/dev/incompressible_liquids/json/MGL.json +++ b/dev/incompressible_liquids/json/MGL.json @@ -145,39 +145,39 @@ "viscosity": { "coeffs": [ [ - 1.520000e-03, - 4.450000e-03, - 3.633000e-03, - 1.069000e-03, - 5.729000e-03, - 2.116000e-02 + -5.387755e+00, + 4.450000e+00, + 3.633000e+00, + 1.069000e+00, + 5.729000e+00, + 2.116000e+01 ], [ - -3.729000e-05, - -2.688000e-05, - -4.088000e-05, - -1.248000e-04, - -1.780000e-04, + -3.729000e-02, + -2.688000e-02, + -4.088000e-02, + -1.248000e-01, + -1.780000e-01, 0.000000e+00 ], [ - 3.572000e-07, - 8.876000e-08, - 6.219000e-07, - 3.019000e-06, + 3.572000e-04, + 8.876000e-05, + 6.219000e-04, + 3.019000e-03, 0.000000e+00, 0.000000e+00 ], [ - -3.648000e-09, - -2.209000e-09, - 6.331000e-09, + -3.648000e-06, + -2.209000e-06, + 6.331000e-06, 0.000000e+00, 0.000000e+00, 0.000000e+00 ] ], - "type": "polynomial" + "type": "exppolynomial" }, "volume2input": { "coeffs": "null", diff --git a/dev/incompressible_liquids/json/MKA.json b/dev/incompressible_liquids/json/MKA.json index 97009767..4300cffa 100644 --- a/dev/incompressible_liquids/json/MKA.json +++ b/dev/incompressible_liquids/json/MKA.json @@ -145,39 +145,39 @@ "viscosity": { "coeffs": [ [ - 1.042000e-03, - 3.405000e-03, - 5.017000e-03, - 5.637000e-03, - -2.922000e-02, - -7.960000e-02 + -5.865755e+00, + 3.405000e+00, + 5.017000e+00, + 5.637000e+00, + -2.922000e+01, + -7.960000e+01 ], [ - -3.071000e-05, - -1.511000e-05, - -7.779000e-05, - 2.534000e-05, - 4.601000e-04, + -3.071000e-02, + -1.511000e-02, + -7.779000e-02, + 2.534000e-02, + 4.601000e-01, 0.000000e+00 ], [ - 2.819000e-07, - 1.172000e-07, - 9.125000e-07, - 1.596000e-06, + 2.819000e-04, + 1.172000e-04, + 9.125000e-04, + 1.596000e-03, 0.000000e+00, 0.000000e+00 ], [ - -2.190000e-09, - -2.379000e-09, - -1.888000e-08, + -2.190000e-06, + -2.379000e-06, + -1.888000e-05, 0.000000e+00, 0.000000e+00, 0.000000e+00 ] ], - "type": "polynomial" + "type": "exppolynomial" }, "volume2input": { "coeffs": "null", diff --git a/dev/incompressible_liquids/json/MKC.json b/dev/incompressible_liquids/json/MKC.json index a155b4b9..c57c25dc 100644 --- a/dev/incompressible_liquids/json/MKC.json +++ b/dev/incompressible_liquids/json/MKC.json @@ -145,39 +145,39 @@ "viscosity": { "coeffs": [ [ - 8.063000e-04, - 3.624000e-03, - 6.659000e-03, - 1.077000e-02, - -1.097000e-02, - -8.453000e-02 + -6.101455e+00, + 3.624000e+00, + 6.659000e+00, + 1.077000e+01, + -1.097000e+01, + -8.453000e+01 ], [ - -2.362000e-05, - -1.262000e-06, - -1.611000e-04, - -9.796000e-05, - 7.825000e-04, + -2.362000e-02, + -1.262000e-03, + -1.611000e-01, + -9.796000e-02, + 7.825000e-01, 0.000000e+00 ], [ - 1.851000e-07, - -3.022000e-08, - 1.530000e-06, - 3.070000e-06, + 1.851000e-04, + -3.022000e-05, + 1.530000e-03, + 3.070000e-03, 0.000000e+00, 0.000000e+00 ], [ - -2.372000e-09, - -7.761000e-10, - 1.061000e-08, + -2.372000e-06, + -7.761000e-07, + 1.061000e-05, 0.000000e+00, 0.000000e+00, 0.000000e+00 ] ], - "type": "polynomial" + "type": "exppolynomial" }, "volume2input": { "coeffs": "null", diff --git a/dev/incompressible_liquids/json/MKF.json b/dev/incompressible_liquids/json/MKF.json index 4caf0608..6618b7bd 100644 --- a/dev/incompressible_liquids/json/MKF.json +++ b/dev/incompressible_liquids/json/MKF.json @@ -145,39 +145,39 @@ "viscosity": { "coeffs": [ [ - 8.088000e-04, - 1.758000e-03, - -8.372000e-04, - -1.184000e-03, - 1.088000e-01, - 3.098000e-01 + -6.098955e+00, + 1.758000e+00, + -8.372000e-01, + -1.184000e+00, + 1.088000e+02, + 3.098000e+02 ], [ - -2.556000e-05, - 8.603000e-06, - -1.601000e-05, - -1.331000e-04, - -7.003000e-04, + -2.556000e-02, + 8.603000e-03, + -1.601000e-02, + -1.331000e-01, + -7.003000e-01, 0.000000e+00 ], [ - 2.195000e-07, - 2.498000e-07, - 4.815000e-08, - -5.489000e-06, + 2.195000e-04, + 2.498000e-04, + 4.815000e-05, + -5.489000e-03, 0.000000e+00, 0.000000e+00 ], [ - -1.667000e-09, - -3.569000e-09, - -1.861000e-08, + -1.667000e-06, + -3.569000e-06, + -1.861000e-05, 0.000000e+00, 0.000000e+00, 0.000000e+00 ] ], - "type": "polynomial" + "type": "exppolynomial" }, "volume2input": { "coeffs": "null", diff --git a/dev/incompressible_liquids/json/MLI.json b/dev/incompressible_liquids/json/MLI.json index 2e0c4b21..9264ba87 100644 --- a/dev/incompressible_liquids/json/MLI.json +++ b/dev/incompressible_liquids/json/MLI.json @@ -145,39 +145,39 @@ "viscosity": { "coeffs": [ [ - 1.013000e-03, - 3.920000e-03, - 3.320000e-03, - 2.206000e-03, - 1.745000e-01, - 6.699000e-01 + -5.894755e+00, + 3.920000e+00, + 3.320000e+00, + 2.206000e+00, + 1.745000e+02, + 6.699000e+02 ], [ - -3.062000e-05, - 6.246000e-06, - 7.840000e-06, - -6.011000e-04, - -7.094000e-03, + -3.062000e-02, + 6.246000e-03, + 7.840000e-03, + -6.011000e-01, + -7.094000e+00, 0.000000e+00 ], [ - 2.940000e-07, - -1.752000e-07, - -3.100000e-06, - 4.023000e-06, + 2.940000e-04, + -1.752000e-04, + -3.100000e-03, + 4.023000e-03, 0.000000e+00, 0.000000e+00 ], [ - -2.719000e-09, - 8.346000e-09, - 1.381000e-07, + -2.719000e-06, + 8.346000e-06, + 1.381000e-04, 0.000000e+00, 0.000000e+00, 0.000000e+00 ] ], - "type": "polynomial" + "type": "exppolynomial" }, "volume2input": { "coeffs": "null", diff --git a/dev/incompressible_liquids/json/MMA.json b/dev/incompressible_liquids/json/MMA.json index 3ee50bd9..4249ad71 100644 --- a/dev/incompressible_liquids/json/MMA.json +++ b/dev/incompressible_liquids/json/MMA.json @@ -145,39 +145,39 @@ "viscosity": { "coeffs": [ [ - 1.153000e-03, - 5.448000e-04, - -5.552000e-03, - 3.038000e-03, - 6.669000e-03, - -8.472000e-03 + -5.754755e+00, + 5.448000e-01, + -5.552000e+00, + 3.038000e+00, + 6.669000e+00, + -8.472000e+00 ], [ - -3.866000e-05, - 1.008000e-05, - 8.384000e-05, - -7.435000e-05, - -9.105000e-05, + -3.866000e-02, + 1.008000e-02, + 8.384000e-02, + -7.435000e-02, + -9.105000e-02, 0.000000e+00 ], [ - 2.779000e-07, - -2.809000e-07, - -3.997000e-07, - 7.442000e-07, + 2.779000e-04, + -2.809000e-04, + -3.997000e-04, + 7.442000e-04, 0.000000e+00, 0.000000e+00 ], [ - -1.543000e-09, - 9.811000e-10, - -3.466000e-09, + -1.543000e-06, + 9.811000e-07, + -3.466000e-06, 0.000000e+00, 0.000000e+00, 0.000000e+00 ] ], - "type": "polynomial" + "type": "exppolynomial" }, "volume2input": { "coeffs": "null", diff --git a/dev/incompressible_liquids/json/MMG.json b/dev/incompressible_liquids/json/MMG.json index f62ccb45..02856da1 100644 --- a/dev/incompressible_liquids/json/MMG.json +++ b/dev/incompressible_liquids/json/MMG.json @@ -145,39 +145,39 @@ "viscosity": { "coeffs": [ [ - 9.573000e-04, - 4.968000e-03, - -2.722000e-02, - 9.351000e-02, - 7.364000e+00, - 3.717000e+01 + -5.950455e+00, + 4.968000e+00, + -2.722000e+01, + 9.351000e+01, + 7.364000e+03, + 3.717000e+04 ], [ - -3.065000e-05, - 1.559000e-05, - -1.753000e-04, - -8.353000e-03, - -4.014000e-02, + -3.065000e-02, + 1.559000e-02, + -1.753000e-01, + -8.353000e+00, + -4.014000e+01, 0.000000e+00 ], [ - 1.115000e-07, - -1.796000e-06, - 2.021000e-05, - 1.901000e-04, + 1.115000e-04, + -1.796000e-03, + 2.021000e-02, + 1.901000e-01, 0.000000e+00, 0.000000e+00 ], [ - -2.923000e-09, - 3.051000e-08, - 2.614000e-07, + -2.923000e-06, + 3.051000e-05, + 2.614000e-04, 0.000000e+00, 0.000000e+00, 0.000000e+00 ] ], - "type": "polynomial" + "type": "exppolynomial" }, "volume2input": { "coeffs": "null", diff --git a/dev/incompressible_liquids/json/MNA.json b/dev/incompressible_liquids/json/MNA.json index face89e3..05ae2216 100644 --- a/dev/incompressible_liquids/json/MNA.json +++ b/dev/incompressible_liquids/json/MNA.json @@ -145,25 +145,25 @@ "viscosity": { "coeffs": [ [ - 4.369000e-04, - 2.346000e-03, - 4.276000e-03, - 7.386000e-03, - 4.688000e-02, + -6.470855e+00, + 2.346000e+00, + 4.276000e+00, + 7.386000e+00, + 4.688000e+01, 0.000000e+00 ], [ - -2.666000e-05, - -5.368000e-06, - -4.526000e-05, - 5.437000e-04, + -2.666000e-02, + -5.368000e-03, + -4.526000e-02, + 5.437000e-01, 0.000000e+00, 0.000000e+00 ], [ - 2.035000e-07, - 2.871000e-07, - 1.838000e-06, + 2.035000e-04, + 2.871000e-04, + 1.838000e-03, 0.000000e+00, 0.000000e+00, 0.000000e+00 @@ -177,7 +177,7 @@ 0.000000e+00 ] ], - "type": "polynomial" + "type": "exppolynomial" }, "volume2input": { "coeffs": "null", diff --git a/dev/incompressible_liquids/json/MPG.json b/dev/incompressible_liquids/json/MPG.json index b04c80f5..b55385a1 100644 --- a/dev/incompressible_liquids/json/MPG.json +++ b/dev/incompressible_liquids/json/MPG.json @@ -145,39 +145,39 @@ "viscosity": { "coeffs": [ [ - 6.837000e-04, - 3.328000e-03, - 5.453000e-04, - -3.900000e-03, - -1.587000e-03, - 3.564000e-02 + -6.224055e+00, + 3.328000e+00, + 5.453000e-01, + -3.900000e+00, + -1.587000e+00, + 3.564000e+01 ], [ - -3.045000e-05, - -3.984000e-05, - -8.600000e-07, - 1.054000e-04, - 4.475000e-05, + -3.045000e-02, + -3.984000e-02, + -8.600000e-04, + 1.054000e-01, + 4.475000e-02, 0.000000e+00 ], [ - 2.525000e-07, - 4.332000e-07, - -1.593000e-07, - -1.589000e-06, + 2.525000e-04, + 4.332000e-04, + -1.593000e-04, + -1.589000e-03, 0.000000e+00, 0.000000e+00 ], [ - -1.399000e-09, - -1.860000e-09, - -4.465000e-10, + -1.399000e-06, + -1.860000e-06, + -4.465000e-07, 0.000000e+00, 0.000000e+00, 0.000000e+00 ] ], - "type": "polynomial" + "type": "exppolynomial" }, "volume2input": { "coeffs": "null", From 33d9e2e8338ac97a395a33a74d5f29ada519ee98 Mon Sep 17 00:00:00 2001 From: Jorrit Wronski Date: Mon, 26 Jan 2015 22:00:41 +0100 Subject: [PATCH 44/69] More stupid mistakes in the incompressibles fixed, thanks to Luke Erickson for reporting #429, which is fixed now. --- src/Backends/Incompressible/IncompressibleFluid.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Backends/Incompressible/IncompressibleFluid.cpp b/src/Backends/Incompressible/IncompressibleFluid.cpp index f0d7cb7b..346969ca 100644 --- a/src/Backends/Incompressible/IncompressibleFluid.cpp +++ b/src/Backends/Incompressible/IncompressibleFluid.cpp @@ -27,7 +27,7 @@ void IncompressibleFluid::set_reference_state(double T0, double p0, double x0, d this->uref = 0.0; this->uref = u(T0,p0,x0) - h0; // (value without ref) - (desired ref) this->sref = 0.0; - this->sref = s(T0,p0,x0) - s0; // (value without ref) - (desired ref) + this->sref = s(T0,p0,x0); } void IncompressibleFluid::validate(){ From 29bd12f94dad2df7e87e6094fb82cbb9d607a292 Mon Sep 17 00:00:00 2001 From: Ian Bell Date: Mon, 26 Jan 2015 18:59:46 -0700 Subject: [PATCH 45/69] Add humid air properties back to the SWIG wrapper; Closes #430 Signed-off-by: Ian Bell --- src/CoolProp.i | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/CoolProp.i b/src/CoolProp.i index cd5e5216..89f1e92f 100644 --- a/src/CoolProp.i +++ b/src/CoolProp.i @@ -46,10 +46,12 @@ namespace std { #define SWIG #include "Configuration.h" #undef SWIG +#include "HumidAirProp.h" %} %include "DataStructures.h" %include "AbstractState.h" %include "CoolProp.h" %include "PhaseEnvelope.h" -%include "Configuration.h" \ No newline at end of file +%include "Configuration.h" +%include "HumidAirProp.h" \ No newline at end of file From f39763f056571a96035dd6b13f67a451a870506f Mon Sep 17 00:00:00 2001 From: Ian Bell Date: Mon, 26 Jan 2015 19:30:17 -0700 Subject: [PATCH 46/69] Do not require fluid files to be in c:\Program Files\REFPROP on windows; Closes #428 Signed-off-by: Ian Bell --- src/Backends/REFPROP/REFPROPMixtureBackend.cpp | 17 ----------------- 1 file changed, 17 deletions(-) diff --git a/src/Backends/REFPROP/REFPROPMixtureBackend.cpp b/src/Backends/REFPROP/REFPROPMixtureBackend.cpp index e1c46321..46214aa5 100644 --- a/src/Backends/REFPROP/REFPROPMixtureBackend.cpp +++ b/src/Backends/REFPROP/REFPROPMixtureBackend.cpp @@ -251,23 +251,6 @@ bool load_REFPROP() return false; } - #if defined(__ISWINDOWS__) - - // Get data associated with path using the windows libraries, - // and if you can (result == 0), the path exists - #ifdef __MINGW32__ - struct stat buf; - if ( stat( "c:\\Program Files\\REFPROP\\fluids", &buf) != 0){ - throw CoolProp::ValueError("REFPROP fluid files must be copied to c:\\Program Files\\REFPROP\\fluids"); - } - #else - struct _stat buf; - if ( _stat( "c:\\Program Files\\REFPROP\\fluids", &buf) != 0){ - throw CoolProp::ValueError("REFPROP fluid files must be copied to c:\\Program Files\\REFPROP\\fluids"); - } - #endif - #endif - if (setFunctionPointers()!=COOLPROP_OK) { printf("There was an error setting the REFPROP function pointers, check types and names in header file.\n"); From 000b14f1fde7ac3fca55aac89dcc944fcadca8c6 Mon Sep 17 00:00:00 2001 From: Ian Bell Date: Mon, 26 Jan 2015 22:06:40 -0700 Subject: [PATCH 47/69] betaV and gammaT were entered backwards into mixture_binary_pairs.json; Closes #432 Signed-off-by: Ian Bell --- dev/mixtures/mixture_binary_pairs.json | 58 +++++++++++++------------- 1 file changed, 29 insertions(+), 29 deletions(-) diff --git a/dev/mixtures/mixture_binary_pairs.json b/dev/mixtures/mixture_binary_pairs.json index 914eb632..726b1980 100644 --- a/dev/mixtures/mixture_binary_pairs.json +++ b/dev/mixtures/mixture_binary_pairs.json @@ -73,9 +73,9 @@ "Name1": "CarbonDioxide", "Name2": "Water", "betaT": 1.030538, - "betaV": 0.828472, + "gammaT": 0.828472, "function": "CarbonDioxide-Water", - "gammaT": 1.021392, + "betaV": 1.021392, "gammaV": 0.895156 }, { @@ -86,9 +86,9 @@ "Name1": "CarbonDioxide", "Name2": "Nitrogen", "betaT": 0.994140013, - "betaV": 1.107654104, + "gammaT": 1.107654104, "function": "Nitrogen-CarbonDioxide", - "gammaT": 1.022709642, + "betaV": 1.022709642, "gammaV": 1.047578256 }, { @@ -99,8 +99,8 @@ "Name1": "CarbonDioxide", "Name2": "Oxygen", "betaT": 1.0, - "betaV": 1.031986, - "gammaT": 1.0, + "gammaT": 1.031986, + "betaV": 1.0, "gammaV": 1.08446 }, { @@ -111,9 +111,9 @@ "Name1": "CarbonDioxide", "Name2": "Argon", "betaT": 1.027147, - "betaV": 0.968781, + "gammaT": 0.968781, "function": "Argon-CarbonDioxide", - "gammaT": 1.001378, + "betaV": 1.001378, "gammaV": 1.02971 }, { @@ -124,8 +124,8 @@ "Name1": "CarbonDioxide", "Name2": "CarbonMonoxide", "betaT": 0.993245, - "betaV": 1.068392, - "gammaT": 1.030855, + "gammaT": 1.068392, + "betaV": 1.030855, "gammaV": 1.245499 }, { @@ -136,9 +136,9 @@ "Name1": "Water", "Name2": "Nitrogen", "betaT": 0.954149, - "betaV": 0.805147, + "gammaT": 0.805147, "function": "GeneralizedAirWater", - "gammaT": 1.079628, + "betaV": 1.079628, "gammaV": 0.733443 }, { @@ -149,9 +149,9 @@ "Name1": "Water", "Name2": "Oxygen", "betaT": 0.798046, - "betaV": 0.807842, + "gammaT": 0.807842, "function": "GeneralizedAirWater", - "gammaT": 0.972576, + "betaV": 0.972576, "gammaV": 0.87346 }, { @@ -162,8 +162,8 @@ "Name1": "Water", "Name2": "Argon", "betaT": 0.679104, - "betaV": 0.921, - "gammaT": 0.940398, + "gammaT": 0.921, + "betaV": 0.940398, "gammaV": 1.050952 }, { @@ -174,9 +174,9 @@ "Name1": "Water", "Name2": "CarbonMonoxide", "betaT": 1.045927, - "betaV": 0.823984, + "gammaT": 0.823984, "function": "GeneralizedAirWater", - "gammaT": 1.063348, + "betaV": 1.063348, "gammaV": 0.766756 }, { @@ -187,8 +187,8 @@ "Name1": "Nitrogen", "Name2": "Oxygen", "betaT": 0.997190589, - "betaV": 0.995157044, - "gammaT": 0.99952177, + "gammaT": 0.995157044, + "betaV": 0.99952177, "gammaV": 0.997082328 }, { @@ -199,8 +199,8 @@ "Name1": "Nitrogen", "Name2": "Argon", "betaT": 0.999442, - "betaV": 0.989311, - "gammaT": 1.006697, + "gammaT": 0.989311, + "betaV": 1.006697, "gammaV": 1.001549 }, { @@ -211,8 +211,8 @@ "Name1": "Nitrogen", "Name2": "CarbonMonoxide", "betaT": 1.002409, - "betaV": 0.9941, - "gammaT": 1.0, + "gammaT": 0.9941, + "betaV": 1.0, "gammaV": 1.001317 }, { @@ -223,8 +223,8 @@ "Name1": "Oxygen", "Name2": "Argon", "betaT": 0.999039, - "betaV": 0.988822, - "gammaT": 1.006502, + "gammaT": 0.988822, + "betaV": 1.006502, "gammaV": 1.001341 }, { @@ -235,8 +235,8 @@ "Name1": "Oxygen", "Name2": "CarbonMonoxide", "betaT": 1.0, - "betaV": 1.0, "gammaT": 1.0, + "betaV": 1.0, "gammaV": 1.0 }, { @@ -247,8 +247,8 @@ "Name1": "CarbonMonoxide", "Name2": "Argon", "betaT": 1.0, - "betaV": 0.954215746, - "gammaT": 1.0, + "gammaT": 0.954215746, + "betaV": 1.0, "gammaV": 1.159720623 }, { From 792c466c3d2d6058f37248acab486b09e9eeda81 Mon Sep 17 00:00:00 2001 From: Jorrit Wronski Date: Tue, 27 Jan 2015 20:44:05 +0100 Subject: [PATCH 48/69] I hope this is the last commit to fix #429 and to fix #413 --- include/IncompressibleFluid.h | 8 +- include/PolyMath.h | 2 +- .../Incompressible/IncompressibleBackend.cpp | 48 +++++++++--- .../Incompressible/IncompressibleFluid.cpp | 78 ++++++++++++++----- 4 files changed, 105 insertions(+), 31 deletions(-) diff --git a/include/IncompressibleFluid.h b/include/IncompressibleFluid.h index cbd3aa54..5445b91f 100644 --- a/include/IncompressibleFluid.h +++ b/include/IncompressibleFluid.h @@ -65,6 +65,10 @@ protected: double uref, rhoref; double xbase, Tbase; + double _xref, _Tref, _pref; + double _href, _sref; + double _uref, _rhoref; + /// These are the objects that hold the coefficients /** Note that all polynomials require a 2-dimensional array * of coefficients. This array may have only one row or @@ -272,7 +276,7 @@ protected: * pressure employing functions for internal energy and * density. Provides consistent formulations. */ double h_u(double T, double p, double x) { - return u(T,p,x)+(p-pref)/rhoref; + return u(T,p,x)+(p-_pref)/_rhoref; }; /// Internal energy from h, p and rho. @@ -280,7 +284,7 @@ protected: * and pressure employing functions for enthalpy and * density. Provides consistent formulations. */ double u_h(double T, double p, double x) { - return h(T,p,x)-(p-pref)/rhoref; + return h(T,p,x)-(p-_pref)/_rhoref; }; diff --git a/include/PolyMath.h b/include/PolyMath.h index 9ef18197..79fc500d 100644 --- a/include/PolyMath.h +++ b/include/PolyMath.h @@ -159,7 +159,7 @@ protected: double baseHorner(const std::vector &coefficients, double x); DEPRECATED(double baseHorner(const std::vector > &coefficients, double x, double y)); - bool do_debug(void){return get_debug_level()>=18;} + bool do_debug(void){return get_debug_level()>=500;} }; diff --git a/src/Backends/Incompressible/IncompressibleBackend.cpp b/src/Backends/Incompressible/IncompressibleBackend.cpp index 0b83405e..e353c1b9 100644 --- a/src/Backends/Incompressible/IncompressibleBackend.cpp +++ b/src/Backends/Incompressible/IncompressibleBackend.cpp @@ -27,7 +27,7 @@ IncompressibleBackend::IncompressibleBackend(IncompressibleFluid* fluid) { //this->_fractions_id = fluid->getxid(); this->fluid = fluid; if (this->fluid->is_pure()){ - this->set_fractions(std::vector(1,0)); + this->set_fractions(std::vector(1,1.0)); } } @@ -35,7 +35,7 @@ IncompressibleBackend::IncompressibleBackend(const std::string &fluid_name) { this->fluid = &get_incompressible_fluid(fluid_name); //this->_fractions_id = this->fluid->getxid(); if (this->fluid->is_pure()){ - this->set_fractions(std::vector(1,0)); + this->set_fractions(std::vector(1,1.0)); } } @@ -64,8 +64,8 @@ void IncompressibleBackend::update(CoolProp::input_pairs input_pair, double valu if (fluid->is_pure()){ this->_fluid_type = FLUID_TYPE_INCOMPRESSIBLE_LIQUID; if (get_debug_level()>=50) std::cout << format("Incompressible backend: Fluid type is %d ",this->_fluid_type) << std::endl; - if (_fractions[0]!=0.0){ - throw ValueError(format("%s is a pure fluid. The composition has to be set to a vector with one entry equal to 0.0 or nothing. %s is not valid.",this->name().c_str(),vec_to_string(_fractions).c_str())); + if (_fractions[0]!=1.0){ + throw ValueError(format("%s is a pure fluid. The composition has to be set to a vector with one entry equal to 1.0. %s is not valid.",this->name().c_str(),vec_to_string(_fractions).c_str())); } } else { this->_fluid_type = FLUID_TYPE_INCOMPRESSIBLE_SOLUTION; @@ -147,8 +147,8 @@ void IncompressibleBackend::set_fractions(const std::vector &fracti void IncompressibleBackend::set_mole_fractions(const std::vector &mole_fractions){ if (get_debug_level()>=10) std::cout << format("Incompressible backend: Called set_mole_fractions with %s ",vec_to_string(mole_fractions).c_str()) << std::endl; if (mole_fractions.size()!=1) throw ValueError(format("The incompressible backend only supports one entry in the mole fraction vector and not %d.",mole_fractions.size())); - if (fluid->getxid()==IFRAC_PURE) { - this->set_fractions(std::vector(1,0)); + if ((fluid->getxid()==IFRAC_PURE) && true ){//( this->_fractions[0]!=1.0 )){ + this->set_fractions(std::vector(1,1.0)); if (get_debug_level()>=20) std::cout << format("Incompressible backend: Overwriting fractions for pure fluid with %s -> %s",vec_to_string(mole_fractions).c_str(),vec_to_string(this->_fractions).c_str()) << std::endl; } else if (fluid->getxid()==IFRAC_MOLE) { this->set_fractions(mole_fractions); @@ -168,8 +168,8 @@ void IncompressibleBackend::set_mole_fractions(const std::vector &m void IncompressibleBackend::set_mass_fractions(const std::vector &mass_fractions){ if (get_debug_level()>=10) std::cout << format("Incompressible backend: Called set_mass_fractions with %s ",vec_to_string(mass_fractions).c_str()) << std::endl; if (mass_fractions.size()!=1) throw ValueError(format("The incompressible backend only supports one entry in the mass fraction vector and not %d.",mass_fractions.size())); - if (fluid->getxid()==IFRAC_PURE) { - this->set_fractions(std::vector(1,0)); + if ((fluid->getxid()==IFRAC_PURE) && true ){// ( this->_fractions[0]!=1.0 )) { + this->set_fractions(std::vector(1,1.0)); if (get_debug_level()>=20) std::cout << format("Incompressible backend: Overwriting fractions for pure fluid with %s -> %s",vec_to_string(mass_fractions).c_str(),vec_to_string(this->_fractions).c_str()) << std::endl; } else if (fluid->getxid()==IFRAC_MASS) { this->set_fractions(mass_fractions); @@ -189,8 +189,8 @@ void IncompressibleBackend::set_mass_fractions(const std::vector &m void IncompressibleBackend::set_volu_fractions(const std::vector &volu_fractions){ if (get_debug_level()>=10) std::cout << format("Incompressible backend: Called set_volu_fractions with %s ",vec_to_string(volu_fractions).c_str()) << std::endl; if (volu_fractions.size()!=1) throw ValueError(format("The incompressible backend only supports one entry in the volume fraction vector and not %d.",volu_fractions.size())); - if (fluid->getxid()==IFRAC_PURE) { - this->set_fractions(std::vector(1,0)); + if ((fluid->getxid()==IFRAC_PURE) && true ){// ( this->_fractions[0]!=1.0 )) { + this->set_fractions(std::vector(1,1.0)); if (get_debug_level()>=20) std::cout << format("Incompressible backend: Overwriting fractions for pure fluid with %s -> %s",vec_to_string(volu_fractions).c_str(),vec_to_string(this->_fractions).c_str()) << std::endl; } else if (fluid->getxid()==IFRAC_VOLUME) { this->set_fractions(volu_fractions); @@ -436,6 +436,18 @@ TEST_CASE("Internal consistency checks and example use cases for the incompressi CAPTURE(res); CHECK( check_abs(val,res,acc) ); } + // Make sure the ruslt does not change -> reference state... + val = backend.calc_smass(); + backend.update( CoolProp::PT_INPUTS, p, T ); + res = backend.calc_smass(); + { + CAPTURE(T); + CAPTURE(p); + CAPTURE(x); + CAPTURE(val); + CAPTURE(res); + CHECK( check_abs(val,res,acc) ); + } val = fluid.u(T, p, x); res = backend.calc_umass(); @@ -535,6 +547,22 @@ TEST_CASE("Internal consistency checks and example use cases for the incompressi CAPTURE(errmsg); CHECK( check_abs(expected,actual,acc) ); } + // entropy reference state problems + //CoolProp::set_debug_level(51); + expected = CoolProp::PropsSI("S","T",T,"P",p,"INCOMP::"+fluid+format("[%f]",x)); + actual = CoolProp::PropsSI("S","T",T,"P",p,"INCOMP::"+fluid+format("[%f]",x)); + { + CAPTURE(T); + CAPTURE(p); + CAPTURE(x); + CAPTURE(expected); + CAPTURE(actual); + std::string name = "INCOMP::"+fluid+format("[%f]",x); + CAPTURE(name); + std::string errmsg = CoolProp::get_global_param_string("errstring"); + CAPTURE(errmsg); + CHECK( check_abs(expected,actual,acc) ); + } } SECTION("SecCool example") { diff --git a/src/Backends/Incompressible/IncompressibleFluid.cpp b/src/Backends/Incompressible/IncompressibleFluid.cpp index 346969ca..5e7a1ea8 100644 --- a/src/Backends/Incompressible/IncompressibleFluid.cpp +++ b/src/Backends/Incompressible/IncompressibleFluid.cpp @@ -19,15 +19,23 @@ and transport properties. //IncompressibleFluid::IncompressibleFluid(); void IncompressibleFluid::set_reference_state(double T0, double p0, double x0, double h0, double s0){ - this->Tref = T0; - this->rhoref = rho(T0,p0,x0); - this->pref = p0; - this->href = h0; - // Now we take care of the energy related values - this->uref = 0.0; - this->uref = u(T0,p0,x0) - h0; // (value without ref) - (desired ref) - this->sref = 0.0; - this->sref = s(T0,p0,x0); + this->_href = h0; + this->_pref = p0; + this->_Tref = T0; + this->_xref = x0; + this->_rhoref = rho(T0,p0,x0); + this->_uref = h0; // Reset the old reference value + this->_uref = u(T0,p0,x0); // uses _uref + this->_sref = s0; // Reset the old reference value + this->_sref = s(T0,p0,x0); // uses _sref + // Save the values for later calls at composition changes + this->href = h0; + this->pref = p0; + this->Tref = T0; + this->xref = x0; + this->rhoref = this->_rhoref; + this->uref = this->_uref; + this->sref = s0; } void IncompressibleFluid::validate(){ @@ -130,7 +138,7 @@ double IncompressibleFluid::s (double T, double p, double x){ switch (specific_heat.type) { case IncompressibleData::INCOMPRESSIBLE_POLYNOMIAL: //throw NotImplementedError("Here you should implement the polynomial."); - return poly.integral(specific_heat.coeffs, T, x, 0, -1, 0, Tbase, xbase) - sref; + return poly.integral(specific_heat.coeffs, T, x, 0, -1, 0, Tbase, xbase) - _sref; break; case IncompressibleData::INCOMPRESSIBLE_NOT_SET: throw ValueError(format("%s (%d): The function type is not specified (\"[%d]\"), are you sure the coefficients have been set?",__FILE__,__LINE__,specific_heat.type)); @@ -147,7 +155,7 @@ double IncompressibleFluid::u (double T, double p, double x){ switch (specific_heat.type) { case IncompressibleData::INCOMPRESSIBLE_POLYNOMIAL: //throw NotImplementedError("Here you should implement the polynomial."); - return poly.integral(specific_heat.coeffs, T, x, 0, 0, 0, Tbase, xbase) - uref; + return poly.integral(specific_heat.coeffs, T, x, 0, 0, 0, Tbase, xbase) - _uref; break; case IncompressibleData::INCOMPRESSIBLE_NOT_SET: throw ValueError(format("%s (%d): The function type is not specified (\"[%d]\"), are you sure the coefficients have been set?",__FILE__,__LINE__,specific_heat.type)); @@ -422,7 +430,7 @@ double IncompressibleFluid::T_c (double Cmass, double p, double x){ } /// Temperature as a function of entropy as a function of temperature, pressure and composition. double IncompressibleFluid::T_s (double Smass, double p, double x){ - double s_raw = Smass + sref; + double s_raw = Smass + _sref; switch (specific_heat.type) { case IncompressibleData::INCOMPRESSIBLE_POLYNOMIAL: return poly.solve_limitsInt(specific_heat.coeffs, x, s_raw, Tmin, Tmax, 0, -1, 0, Tbase, xbase, 0); @@ -438,7 +446,7 @@ double IncompressibleFluid::T_s (double Smass, double p, double x){ } /// Temperature as a function of internal energy as a function of temperature, pressure and composition. double IncompressibleFluid::T_u (double Umass, double p, double x){ - double u_raw = Umass + uref; + double u_raw = Umass + _uref; switch (specific_heat.type) { case IncompressibleData::INCOMPRESSIBLE_POLYNOMIAL: return poly.solve_limitsInt(specific_heat.coeffs, x, u_raw, Tmin, Tmax, 0, 0, 0, Tbase, xbase, 0); @@ -667,8 +675,8 @@ TEST_CASE("Internal consistency checks and example use cases for the incompressi CAPTURE(Tref); CAPTURE(pref); CAPTURE(xref); - CAPTURE(href) - CAPTURE(res) + CAPTURE(href); + CAPTURE(res); CHECK( check_abs(href,res,acc) ); } { @@ -676,10 +684,26 @@ TEST_CASE("Internal consistency checks and example use cases for the incompressi CAPTURE(Tref); CAPTURE(pref); CAPTURE(xref); - CAPTURE(sref) - CAPTURE(res) + CAPTURE(sref); + CAPTURE(res); CHECK( check_abs(sref,res,acc) ); - } + double res2 = XLT.s(Tref,pref,xref); + CAPTURE(Tref); + CAPTURE(pref); + CAPTURE(xref); + CAPTURE(res); + CAPTURE(res2); + CHECK( check_abs(res2,res,acc) ); + res = XLT.s(Tref,pref,xref); + CAPTURE(Tref); + CAPTURE(pref); + CAPTURE(xref); + CAPTURE(res); + CAPTURE(res2); + CHECK( check_abs(res2,res,acc) ); + } + + Tref = 25+273.15; pref = 0.0; @@ -849,6 +873,15 @@ TEST_CASE("Internal consistency checks and example use cases for the incompressi CAPTURE(actual); CHECK( check_abs(expected,actual,acc) ); } + expected = CH3OH.s(T,p,x); + { + CAPTURE(T); + CAPTURE(p); + CAPTURE(x); + CAPTURE(expected); + CAPTURE(actual); + CHECK( check_abs(expected,actual,acc) ); + } expected = 0.0; actual = CH3OH.s(Tref,pref,xref); @@ -860,6 +893,15 @@ TEST_CASE("Internal consistency checks and example use cases for the incompressi CAPTURE(actual); CHECK( expected==actual ); } + expected = CH3OH.s(Tref,pref,xref); + { + CAPTURE(T); + CAPTURE(p); + CAPTURE(x); + CAPTURE(expected); + CAPTURE(actual); + CHECK( expected==actual ); + } // Compare u expected = -60043.78429641827; From 575643938c1323d9a9c63e68d6baf17f834bd8b8 Mon Sep 17 00:00:00 2001 From: Ian Bell Date: Wed, 28 Jan 2015 18:52:18 -0700 Subject: [PATCH 49/69] Fix predefined mixtures in REFPROP; Closes #437 Signed-off-by: Ian Bell --- src/Backends/REFPROP/REFPROPBackend.cpp | 6 ++-- .../REFPROP/REFPROPMixtureBackend.cpp | 34 +++++++++++++++++++ src/CoolProp.cpp | 6 ++++ 3 files changed, 44 insertions(+), 2 deletions(-) diff --git a/src/Backends/REFPROP/REFPROPBackend.cpp b/src/Backends/REFPROP/REFPROPBackend.cpp index bee6e03a..667bb05b 100644 --- a/src/Backends/REFPROP/REFPROPBackend.cpp +++ b/src/Backends/REFPROP/REFPROPBackend.cpp @@ -32,8 +32,10 @@ REFPROPBackend::REFPROPBackend(const std::string & fluid_name) { // Set the mole fraction to 1 in the base class (we can't set the mole fraction in this class, // otherwise a NotImplementedError will be returned) - std::vector x(1, 1.0); // (one element with value of 1.0) - REFPROPMixtureBackend::set_mole_fractions(x); + if (get_mole_fractions().empty()){ + std::vector x(1, 1.0); // (one element with value of 1.0) + REFPROPMixtureBackend::set_mole_fractions(x); + } } REFPROPBackend::~REFPROPBackend() { diff --git a/src/Backends/REFPROP/REFPROPMixtureBackend.cpp b/src/Backends/REFPROP/REFPROPMixtureBackend.cpp index 46214aa5..19ae1861 100644 --- a/src/Backends/REFPROP/REFPROPMixtureBackend.cpp +++ b/src/Backends/REFPROP/REFPROPMixtureBackend.cpp @@ -379,6 +379,40 @@ void REFPROPMixtureBackend::set_REFPROP_fluids(const std::vector &f } else { + if (N == 1 && upper(components_joined_raw).find(".MIX") == components_joined_raw.size() - 4){ + // It's a predefined mixture + ierr = 0; + std::vector x(ncmax); + char mix[255]; + strcpy(mix, components_joined_raw.c_str()); + SETMIXdll(mix, + "HMX.BNC", + "DEF", + &N, + component_string, + &(x[0]), + &ierr, + herr, + 255, + 255, + 3, + 10000, + 255); + if (static_cast(ierr) <= 0){ + this->Ncomp = N; + mole_fractions.resize(N); + mole_fractions_liq.resize(N); + mole_fractions_vap.resize(N); + LoadedREFPROPRef = components_joined_raw; + if (CoolProp::get_debug_level() > 5){ std::cout << format("%s:%d: Successfully loaded REFPROP fluid: %s\n",__FILE__,__LINE__, components_joined.c_str()); } + if (dbg_refprop) std::cout << format("%s:%d: Successfully loaded REFPROP fluid: %s\n",__FILE__,__LINE__, components_joined.c_str()); + set_mole_fractions(std::vector(x.begin(), x.begin()+N)); + return; + } + else{ + throw ValueError(format("Unable to load mixture: %s",components_joined_raw.c_str())); + } + } // Loop over the file names - first we try with nothing, then .fld, then .FLD, then .ppf - means you can't mix and match for (unsigned int k = 0; k < number_of_endings; k++) { diff --git a/src/CoolProp.cpp b/src/CoolProp.cpp index 9d1c4f78..def026ce 100644 --- a/src/CoolProp.cpp +++ b/src/CoolProp.cpp @@ -499,6 +499,12 @@ TEST_CASE("Check inputs to PropsSI","[PropsSI]") SECTION("Single state, single output, predefined mixture"){ CHECK(ValidNumber(CoolProp::PropsSI("T","P",101325,"Q",0,"R410A.mix"))); }; + SECTION("Single state, single output, predefined mixture from REFPROP"){ + CHECK(ValidNumber(CoolProp::PropsSI("T","P",101325,"Q",0,"REFPROP::R410A.mix"))); + }; + SECTION("Single state, single output, bad predefined mixture from REFPROP"){ + CHECK(!ValidNumber(CoolProp::PropsSI("T","P",101325,"Q",0,"REFPROP::RRRRRR.mix"))); + }; SECTION("Predefined mixture"){ std::vector p(1, 101325), Q(1, 1.0), z; std::vector outputs(1,"T"); outputs.push_back("Dmolar"); From f5739e3354b5fa9f518d44d465129d24d0b86062 Mon Sep 17 00:00:00 2001 From: Ian Bell Date: Wed, 28 Jan 2015 19:34:04 -0700 Subject: [PATCH 50/69] Fixed bug with 3 character long fluid names Signed-off-by: Ian Bell --- src/Backends/REFPROP/REFPROPMixtureBackend.cpp | 2 +- src/CoolProp.cpp | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/src/Backends/REFPROP/REFPROPMixtureBackend.cpp b/src/Backends/REFPROP/REFPROPMixtureBackend.cpp index 19ae1861..abef2a15 100644 --- a/src/Backends/REFPROP/REFPROPMixtureBackend.cpp +++ b/src/Backends/REFPROP/REFPROPMixtureBackend.cpp @@ -379,7 +379,7 @@ void REFPROPMixtureBackend::set_REFPROP_fluids(const std::vector &f } else { - if (N == 1 && upper(components_joined_raw).find(".MIX") == components_joined_raw.size() - 4){ + if (N == 1 && upper(components_joined_raw).find(".MIX") != std::string::npos){ // It's a predefined mixture ierr = 0; std::vector x(ncmax); diff --git a/src/CoolProp.cpp b/src/CoolProp.cpp index def026ce..4bf25c6f 100644 --- a/src/CoolProp.cpp +++ b/src/CoolProp.cpp @@ -483,7 +483,6 @@ TEST_CASE("Check inputs to PropsSI","[PropsSI]") SECTION("Single state, trivial output, pure incompressible"){ CHECK(ValidNumber(CoolProp::PropsSI("Tmin","P",0,"T",0,"INCOMP::DowQ"))); }; - std::cout << get_global_param_string("errstring"); SECTION("Bad input pair"){ CHECK(!ValidNumber(CoolProp::PropsSI("D","Q",0,"Q",0,"Water"))); }; From c8bbfad78454183b94d22936b94237432cf28655 Mon Sep 17 00:00:00 2001 From: Ian Bell Date: Wed, 28 Jan 2015 22:15:03 -0700 Subject: [PATCH 51/69] Re-enable all the ignored SWIG+MATLAB enums Signed-off-by: Ian Bell --- src/CoolProp.i | 8 -------- 1 file changed, 8 deletions(-) diff --git a/src/CoolProp.i b/src/CoolProp.i index 89f1e92f..fc998781 100644 --- a/src/CoolProp.i +++ b/src/CoolProp.i @@ -5,14 +5,6 @@ %ignore CoolProp::set_config_json(rapidjson::Document &); %ignore CoolProp::get_config_as_json(rapidjson::Document &); -#ifdef SWIGMATLAB -%ignore configuration_keys; -%ignore CoolProp::ConfigurationItem::ConfigurationDataTypes; -%ignore CoolProp::SsatSimpleState::SsatSimpleStateEnum; -%ignore CoolProp::composition_types; -%ignore CoolProp::fluid_types; -#endif - %include "std_string.i" // This %include allows the use of std::string natively %include "std_vector.i" // This allows for the use of STL vectors natively(ish) %include "exception.i" // From 35dd80ddc25d1f0f1adc619d178838b0d79f3915 Mon Sep 17 00:00:00 2001 From: Ian Bell Date: Wed, 28 Jan 2015 22:54:42 -0700 Subject: [PATCH 52/69] Point to a different swig+MATLAB repo Signed-off-by: Ian Bell --- dev/scripts/build_swig_matlab.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dev/scripts/build_swig_matlab.py b/dev/scripts/build_swig_matlab.py index 39e22c9f..f163eaa1 100644 --- a/dev/scripts/build_swig_matlab.py +++ b/dev/scripts/build_swig_matlab.py @@ -11,7 +11,7 @@ else: commons = dict(shell = True, stdout = sys.stdout, stderr = sys.stderr) if not os.path.exists('swig-matlab'): - subprocess.call('git clone https://github.com/KrisThielemans/swig swig-matlab', **commons) + subprocess.call('git clone https://github.com/jaeandersson/swig swig-matlab', **commons) else: subprocess.call('git pull', shell = True, cwd = 'swig-matlab', stdout = sys.stdout, stderr = sys.stderr) From 21a0216c2b9e2fed50aadadfad6c29f8a6289979 Mon Sep 17 00:00:00 2001 From: Ian Bell Date: Wed, 28 Jan 2015 23:21:41 -0700 Subject: [PATCH 53/69] Update version for swig+MATLAB Signed-off-by: Ian Bell --- dev/buildbot/master/master.cfg | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dev/buildbot/master/master.cfg b/dev/buildbot/master/master.cfg index f8968228..bd1bb5b3 100644 --- a/dev/buildbot/master/master.cfg +++ b/dev/buildbot/master/master.cfg @@ -604,9 +604,9 @@ def swig_matlab_builder(platform, gitMode = 'incremental', build_args = [], cmak def prepend_path(cmd): if platform == 'windows': - pre_path = 'set "PATH=swig-matlab-bin\\bin;C:\\Program Files\\7-Zip\\;%PATH%" && set "SWIG_LIB=swig-matlab-bin\\share\\swig\\3.0.3" && ' + pre_path = 'set "PATH=swig-matlab-bin\\bin;C:\\Program Files\\7-Zip\\;%PATH%" && set "SWIG_LIB=swig-matlab-bin\\share\\swig\\3.0.5" && ' else: - pre_path = 'export PATH=swig-matlab-bin/bin:${PATH} && export SWIG_LIB=swig-matlab-bin/share/swig/3.0.3 && ' + pre_path = 'export PATH=swig-matlab-bin/bin:${PATH} && export SWIG_LIB=swig-matlab-bin/share/swig/3.0.5 && ' return pre_path+cmd # Create the factory to add the actions to From c5d14ec37621256241ca525f2082ca30f195c728 Mon Sep 17 00:00:00 2001 From: Aapo Talvensaari Date: Thu, 29 Jan 2015 18:26:16 +0200 Subject: [PATCH 54/69] Implemented Lua C API and LuaJIT Wrappers for CoolProp (high-level API currently implemented). --- wrappers/Lua/Makefile | 24 +++++ wrappers/Lua/README.rst | 6 ++ wrappers/Lua/coolprop.lua | 85 +++++++++++++++++ wrappers/Lua/coolprop/capi.c | 168 +++++++++++++++++++++++++++++++++ wrappers/Lua/coolprop/compat.h | 7 ++ wrappers/Lua/coolprop/ffi.lua | 114 ++++++++++++++++++++++ wrappers/Lua/example.lua | 13 +++ wrappers/Lua/lualib.mk | 75 +++++++++++++++ 8 files changed, 492 insertions(+) create mode 100644 wrappers/Lua/Makefile create mode 100644 wrappers/Lua/README.rst create mode 100644 wrappers/Lua/coolprop.lua create mode 100644 wrappers/Lua/coolprop/capi.c create mode 100644 wrappers/Lua/coolprop/compat.h create mode 100644 wrappers/Lua/coolprop/ffi.lua create mode 100644 wrappers/Lua/example.lua create mode 100644 wrappers/Lua/lualib.mk diff --git a/wrappers/Lua/Makefile b/wrappers/Lua/Makefile new file mode 100644 index 00000000..235f1ebd --- /dev/null +++ b/wrappers/Lua/Makefile @@ -0,0 +1,24 @@ +include lualib.mk + +COOLPROP_CFLAGS ?= $(shell $(PKGCONFIG) --cflags CoolProp) +COOLPROP_LDFLAGS ?= $(shell $(PKGCONFIG) --libs-only-L CoolProp) +COOLPROP_LDLIBS ?= $(or $(shell $(PKGCONFIG) --libs-only-l CoolProp), -lCoolProp) +COOLPROP_INCDIR ?= $(shell $(PKGCONFIG) --variable=includedir CoolProp) +COOLPROP_LIBDIR ?= $(shell $(PKGCONFIG) --variable=libdir CoolProp) +COOLPROP_HEADER ?= $(or $(COOLPROP_INCDIR) + +CFLAGS ?= -g -O2 -Wall -Wextra -Wswitch-enum -Wwrite-strings -Wshadow +XCFLAGS += -std=c99 -pedantic-errors -fpic +XCFLAGS += $(LUA_CFLAGS) $(COOLPROP_CFLAGS) +XLDFLAGS += $(GUMBO_LDFLAGS) $(COOLPROP_LDLIBS) + +all: coolprop/capi.so + +coolprop/capi.o: coolprop/capi.c coolprop/compat.h + +clean: + $(RM) coolprop/capi.so coolprop/capi.o + +.PHONY: all + +.DELETE_ON_ERROR: diff --git a/wrappers/Lua/README.rst b/wrappers/Lua/README.rst new file mode 100644 index 00000000..dbbdbcd9 --- /dev/null +++ b/wrappers/Lua/README.rst @@ -0,0 +1,6 @@ +Lua Wrapper for CoolProp +======================== + +Lua C API and LuaJIT wrappers for CoolProp library (currently implementing the high-level C API). + +by Aapo Talvensaari, Helsinki, Finland, January 2015 \ No newline at end of file diff --git a/wrappers/Lua/coolprop.lua b/wrappers/Lua/coolprop.lua new file mode 100644 index 00000000..7a1da887 --- /dev/null +++ b/wrappers/Lua/coolprop.lua @@ -0,0 +1,85 @@ +if jit and jit.status() then + return require "coolprop.ffi" +end + +local huge = math.huge + +local ok, lib = pcall(require, "coolprop.capi") +assert(ok, "Unable to load CoolProp. Please check that the CoolProp is available. Both the Lua C API wrapper, and the CoolProp shared library.") +local coolprop = {} +function coolprop.err() + return coolprop.get_global_param_string("errstring") +end +function coolprop.Props1SI(fluidname, output) + local v = lib.Props1SI(fluidname, output) + if v == huge then + return nil, coolprop.err() + end + return v +end +function coolprop.PropsSI(output, name1, prop1, name2, prop2, ref) + local v = lib.PropsSI(output, name1, prop1, name2, prop2, ref) + if v == huge then + return nil, coolprop.err() + end + return v +end +function coolprop.PhaseSI(name1, prop1, name2, prop2, ref) + local e, s = lib.PhaseSI(name1, prop1, name2, prop2, ref or "") + return e == 1 and s or nil +end +function coolprop.get_global_param_string(param) + local e, s = lib.get_global_param_string(param) + if e == 1 then + return s + end + return nil +end +function coolprop.get_parameter_information_string(key) + local e, s = lib.get_parameter_information_string(key) + return e == 1 and s or nil +end +function coolprop.get_mixture_binary_pair_data(cas1, cas2, key) + return tonumber(lib.get_mixture_binary_pair_data(cas1, cas2, key)) +end +function coolprop.get_fluid_param_string(fluid, param) + if lib.get_fluid_param_string(fluid, param, bub, 4096) == 1 then + return ffi_str(bub) + end + return nil +end +function coolprop.set_reference_stateS(ref, state) + return lib.set_reference_stateS(ref, state) == 1 +end +function coolprop.set_reference_stateD(ref, t, rho, h0, s0) + return lib.set_reference_stateD(ref, t, rho, h0, s0) == 1 +end +function coolprop.F2K(f) + return lib.F2K(f) +end +function coolprop.K2F(k) + return lib.K2F(k) +end +function coolprop.get_param_index(param) + return lib.get_param_index(param) +end +function coolprop.saturation_ancillary(fluid, output, q, input, value) + return lib.saturation_ancillary(fluid, output, q, input, value) +end +function coolprop.redirect_stdout(file) + return lib.redirect_stdout(file) == 1 +end +function coolprop.get_debug_level() + return lib.get_debug_level() +end +function coolprop.set_debug_level(level) + lib.set_debug_level(level) +end +function coolprop.HAPropsSI(output, name1, prop1, name2, prop2, name3, prop3) + local v = lib.HAPropsSI(output, name1, prop1, name2, prop2, name3, prop3) + if v == huge then + return nil, coolprop.err() + end + return v +end +return coolprop \ No newline at end of file diff --git a/wrappers/Lua/coolprop/capi.c b/wrappers/Lua/coolprop/capi.c new file mode 100644 index 00000000..49adc1c3 --- /dev/null +++ b/wrappers/Lua/coolprop/capi.c @@ -0,0 +1,168 @@ +#include +#include +#include +#include +#include "../../../include/CoolPropLib.h" +#include "compat.h" +static int lua_coolprop_Props1SI(lua_State *L) { + lua_pushnumber(L, Props1SI( + luaL_checkstring(L, 1), + luaL_checkstring(L, 2) + )); + return 1; +} +static int lua_coolprop_PropsSI(lua_State *L) { + lua_pushnumber(L, PropsSI( + luaL_checkstring(L, 1), + luaL_checkstring(L, 2), + luaL_checknumber(L, 3), + luaL_checkstring(L, 4), + luaL_checknumber(L, 5), + luaL_checkstring(L, 6) + )); + return 1; +} +static int lua_coolprop_PhaseSI(lua_State *L) { + char phase[256]; + lua_pushinteger(L, PhaseSI( + luaL_checkstring(L, 1), + luaL_checknumber(L, 2), + luaL_checkstring(L, 3), + luaL_checknumber(L, 4), + luaL_checkstring(L, 5), + phase, + sizeof(phase) + )); + lua_pushstring(L, phase); + return 2; +} +static int lua_coolprop_get_global_param_string(lua_State *L) { + char output[4096]; + lua_pushinteger(L, get_global_param_string( + luaL_checkstring(L, 1), + output, + sizeof(output) + )); + lua_pushstring(L, output); + return 2; +} +static int lua_coolprop_get_parameter_information_string(lua_State *L) { + char output[4096]; + lua_pushinteger(L, get_parameter_information_string( + luaL_checkstring(L, 1), + output, + sizeof(output) + )); + lua_pushstring(L, output); + return 2; +} +/* +static int lua_coolprop_get_mixture_binary_pair_data(lua_State *L) { + lua_pushinteger(L, get_mixture_binary_pair_data( + luaL_checkstring(L, 1), + luaL_checkstring(L, 2), + luaL_checkstring(L, 3) + )); + return 1; +} +*/ +static int lua_coolprop_get_fluid_param_string(lua_State *L) { + char output[4096]; + lua_pushinteger(L, get_fluid_param_string( + luaL_checkstring(L, 1), + luaL_checkstring(L, 2), + output, + sizeof(output) + )); + lua_pushstring(L, output); + return 2; +} +static int lua_coolprop_set_reference_stateS(lua_State *L) { + lua_pushinteger(L, set_reference_stateS( + luaL_checkstring(L, 1), + luaL_checkstring(L, 2) + )); + return 1; +} +static int lua_coolprop_set_reference_stateD(lua_State *L) { + lua_pushinteger(L, set_reference_stateD( + luaL_checkstring(L, 1), + luaL_checknumber(L, 2), + luaL_checknumber(L, 3), + luaL_checknumber(L, 4), + luaL_checknumber(L, 5) + )); + return 1; +} +static int lua_coolprop_F2K(lua_State *L) { + lua_pushnumber(L, F2K(luaL_checknumber(L, 1))); + return 1; +} +static int lua_coolprop_K2F(lua_State *L) { + lua_pushnumber(L, K2F(luaL_checknumber(L, 1))); + return 1; +} +static int lua_coolprop_get_param_index(lua_State *L) { + lua_pushnumber(L, get_param_index(luaL_checkstring(L, 1))); + return 1; +} +static int lua_coolprop_redirect_stdout(lua_State *L) { + lua_pushnumber(L, redirect_stdout( + luaL_checkstring(L, 1) + )); + return 1; +} +static int lua_coolprop_get_debug_level(lua_State *L) { + lua_pushinteger(L, get_debug_level()); + return 1; +} +static int lua_coolprop_set_debug_level(lua_State *L) { + set_debug_level(luaL_checknumber(L, 1)); + return 0; +} +static int lua_coolprop_saturation_ancillary(lua_State *L) { + lua_pushnumber(L, saturation_ancillary( + luaL_checkstring(L, 1), + luaL_checkstring(L, 2), + luaL_checkinteger(L, 3), + luaL_checkstring(L, 4), + luaL_checknumber(L, 5) + )); + return 1; +} +static int lua_coolprop_HAPropsSI(lua_State *L) { + lua_pushnumber(L, HAPropsSI( + luaL_checkstring(L, 1), + luaL_checkstring(L, 2), + luaL_checknumber(L, 3), + luaL_checkstring(L, 4), + luaL_checknumber(L, 5), + luaL_checkstring(L, 6), + luaL_checknumber(L, 7) + )); + return 1; +} +static struct luaL_Reg funcs[] = { + {"Props1SI", lua_coolprop_Props1SI}, + {"PropsSI", lua_coolprop_PropsSI}, + {"PhaseSI", lua_coolprop_PhaseSI}, + {"get_global_param_string", lua_coolprop_get_global_param_string}, + {"get_parameter_information_string", lua_coolprop_get_parameter_information_string}, + //{"get_mixture_binary_pair_data", lua_coolprop_get_mixture_binary_pair_data}, + {"get_fluid_param_string", lua_coolprop_get_fluid_param_string}, + {"set_reference_stateS", lua_coolprop_set_reference_stateS}, + {"set_reference_stateD", lua_coolprop_set_reference_stateD}, + {"F2K", lua_coolprop_F2K}, + {"K2F", lua_coolprop_K2F}, + {"get_param_index", lua_coolprop_get_param_index}, + {"redirect_stdout", lua_coolprop_redirect_stdout}, + {"get_debug_level", lua_coolprop_get_debug_level}, + {"set_debug_level", lua_coolprop_set_debug_level}, + {"saturation_ancillary", lua_coolprop_saturation_ancillary}, + {"HAPropsSI", lua_coolprop_HAPropsSI}, + {NULL, NULL} +}; +int luaopen_coolprop_capi(lua_State *L) { + luaL_newlib(L, funcs); + return 1; +} diff --git a/wrappers/Lua/coolprop/compat.h b/wrappers/Lua/coolprop/compat.h new file mode 100644 index 00000000..d6204026 --- /dev/null +++ b/wrappers/Lua/coolprop/compat.h @@ -0,0 +1,7 @@ +#if !defined(__STDC_VERSION__) || !(__STDC_VERSION__ >= 199901L) +# error C99 compiler required. +#endif + +#ifndef LUA_VERSION_NUM +# error Lua >= 5.1 is required. +#endif diff --git a/wrappers/Lua/coolprop/ffi.lua b/wrappers/Lua/coolprop/ffi.lua new file mode 100644 index 00000000..a5e95f39 --- /dev/null +++ b/wrappers/Lua/coolprop/ffi.lua @@ -0,0 +1,114 @@ +local ffi = require "ffi" +local ffi_new = ffi.new +local ffi_str = ffi.string +local ffi_load = ffi.load +local ffi_cdef = ffi.cdef +local ffi_typeof = ffi.typeof +local huge = math.huge +ffi_cdef[[ +double Props1SI(const char *FluidName, const char* Output); +double PropsSI(const char *Output, const char *Name1, double Prop1, const char *Name2, double Prop2, const char *Ref); +long PhaseSI(const char *Name1, double Prop1, const char *Name2, double Prop2, const char *Ref, char *phase, int n); +long get_global_param_string(const char *param, char *Output, int n); +long get_parameter_information_string(const char *key, char *Output, int n); +long get_mixture_binary_pair_data(const char *CAS1, const char *CAS2, const char *key); +long get_fluid_param_string(const char *fluid, const char *param, char *Output, int n); +int set_reference_stateS(const char *Ref, const char *reference_state); +int set_reference_stateD(const char *Ref, double T, double rho, double h0, double s0); +double F2K(double T_F); +double K2F(double T_K); +long get_param_index(const char *param); +long redirect_stdout(const char *file); +int get_debug_level(); +void set_debug_level(int level); +double saturation_ancillary(const char *fluid_name, const char *output, int Q, const char *input, double value); +double HAPropsSI(const char *Output, const char *Name1, double Prop1, const char *Name2, double Prop2, const char *Name3, double Prop3); +]] +local ok, newtab = pcall(require, "table.new") +if not ok then newtab = function() return {} end end +local but = ffi_typeof "char[?]" +local buf = ffi_new(but, 256) +local bub = ffi_new(but, 4096) +local ok, lib = pcall(ffi_load, "CoolProp") +if not ok then ok, lib = pcall(ffi_load, "coolprop") end +assert(ok, "Unable to load CoolProp. Please check that the CoolProp shared library is in a default search path for dynamic libraries of your operating system.") +local coolprop = newtab(0, 18) +function coolprop.err() + return coolprop.get_global_param_string("errstring") +end +function coolprop.Props1SI(fluidname, output) + local v = lib.Props1SI(fluidname, output) + if v == huge then + return nil, coolprop.err() + end + return v +end +function coolprop.PropsSI(output, name1, prop1, name2, prop2, ref) + local v = lib.PropsSI(output, name1, prop1, name2, prop2, ref) + if v == huge then + return nil, coolprop.err() + end + return v +end +function coolprop.PhaseSI(name1, prop1, name2, prop2, ref) + if lib.PhaseSI(name1, prop1, name2, prop2, ref or "", buf, 256) == 1 then + return ffi_str(buf) + end + return nil +end +function coolprop.get_global_param_string(param) + if lib.get_global_param_string(param, bub, 4096) == 1 then + return ffi_str(bub) + end + return nil +end +function coolprop.get_parameter_information_string(key) + if lib.get_parameter_information_string(key, bub, 4096) == 1 then + return ffi_str(bub) + end + return nil +end +function coolprop.get_mixture_binary_pair_data(cas1, cas2, key) + return tonumber(lib.get_mixture_binary_pair_data(cas1, cas2, key)) +end +function coolprop.get_fluid_param_string(fluid, param) + if lib.get_fluid_param_string(fluid, param, bub, 4096) == 1 then + return ffi_str(bub) + end + return nil +end +function coolprop.set_reference_stateS(ref, state) + return lib.set_reference_stateS(ref, state) == 1 +end +function coolprop.set_reference_stateD(ref, t, rho, h0, s0) + return lib.set_reference_stateD(ref, t, rho, h0, s0) == 1 +end +function coolprop.F2K(f) + return lib.F2K(f) +end +function coolprop.K2F(k) + return lib.K2F(k) +end +function coolprop.get_param_index(param) + return tonumber(lib.get_param_index(param)) +end +function coolprop.saturation_ancillary(fluid, output, q, input, value) + return lib.saturation_ancillary(fluid, output, q, input, value) +end +function coolprop.redirect_stdout(file) + return lib.redirect_stdout(file) == 1 +end +function coolprop.get_debug_level() + return lib.get_debug_level() +end +function coolprop.set_debug_level(level) + lib.set_debug_level(level) +end +function coolprop.HAPropsSI(output, name1, prop1, name2, prop2, name3, prop3) + local v = lib.HAPropsSI(output, name1, prop1, name2, prop2, name3, prop3) + if v == huge then + return nil, coolprop.err() + end + return v +end +return coolprop diff --git a/wrappers/Lua/example.lua b/wrappers/Lua/example.lua new file mode 100644 index 00000000..4ce91c7a --- /dev/null +++ b/wrappers/Lua/example.lua @@ -0,0 +1,13 @@ +local c = require "coolprop" + +print(c.PropsSI("XX", "T", 298.15, "P", 101325, "Nitrogen")) +print(c.PropsSI("C", "P", 101325, "T", 300, "Water")) +print(c.PropsSI("d(Hmass)/d(T)|P", "P", 101325, "T", 300, "Water")) +print(c.PropsSI("D", "P", 101325, "T", 300, "Air.mix")) +print(c.PhaseSI("PXX", 101325, "Q", 0, "Water")) +print(c.get_global_param_string("predefined_mixtures")) +print(c.get_param_index("T")) +print(c.HAPropsSI('H','T',298.15,'P',101325,'R',0.5)) +print(c.HAPropsSI('HXXX','T',298.15,'P',101325,'R',0.5)) +print(c.F2K(10)) +print(c.K2F(c.F2K(10))) \ No newline at end of file diff --git a/wrappers/Lua/lualib.mk b/wrappers/Lua/lualib.mk new file mode 100644 index 00000000..3b45f406 --- /dev/null +++ b/wrappers/Lua/lualib.mk @@ -0,0 +1,75 @@ +-include local.mk + +CC ?= gcc +LDFLAGS ?= $(if $(ISDARWIN), -bundle -undefined dynamic_lookup, -shared) +XLDFLAGS += $(if $(ISLINUX), $(NOASNEEDED)) +NOASNEEDED = -Wl,--no-as-needed +PKGCONFIG ?= pkg-config --silence-errors 2>/dev/null +MKDIR ?= mkdir -p +INSTALL ?= install -p -m 0644 +INSTALLX ?= install -p -m 0755 +RM ?= rm -f +LUA ?= $(or $(LUA_WHICH), $(error No Lua interpreter found)) + +PC_EXISTS = $(PKGCONFIG) --exists $(1) && echo $(1) +FIND_PC = $(shell for P in $(1); do $(call PC_EXISTS, $$P) && break; done) +EQUAL = $(and $(findstring $(1),$(2)),$(findstring $(2),$(1))) +UNAME = $(shell uname) +ISDARWIN = $(call EQUAL, $(UNAME), Darwin) +ISLINUX = $(call EQUAL, $(UNAME), Linux) + +CCOPTIONS = $(XCFLAGS) $(CPPFLAGS) $(CFLAGS) +LDOPTIONS = $(XLDFLAGS) $(LDFLAGS) $(LDLIBS) + +# The naming of Lua pkg-config files across distributions is a mess: +# - Fedora and Arch use lua.pc +# - Debian uses lua5.2.pc and lua5.1.pc +# - OpenBSD ports uses lua52.pc and lua51.pc +# - FreeBSD uses lua-5.2.pc and lua-5.1.pc +LUA_NAMES = lua52 lua5.2 lua-5.2 lua51 lua5.1 lua-5.1 lua luajit +LUA_WHICH = $(firstword $(shell which $(_LUA_PC) $(LUA_NAMES) 2>/dev/null)) + +LUA_PC ?= $(or \ + $(call FIND_PC, $(LUA_NAMES)), \ + $(error No pkg-config file found for Lua) \ +) + +# The $(LUA_PC) variable may be set to a non-existant name via the +# command-line, so we must check that it exists (possibly twice). +_LUA_PC = $(or \ + $(shell $(call PC_EXISTS, $(LUA_PC))), \ + $(error No pkg-config file found with name '$(LUA_PC)') \ +) + +# Some distros put the Lua headers in versioned sub-directories +# and thus require extra CFLAGS +LUA_CFLAGS ?= $(shell $(PKGCONFIG) --cflags $(_LUA_PC)) + +# Some pkg-config files have convenient variables for module paths +LUA_PC_LMOD = $(shell $(PKGCONFIG) --variable=INSTALL_LMOD $(_LUA_PC)) +LUA_PC_CMOD = $(shell $(PKGCONFIG) --variable=INSTALL_CMOD $(_LUA_PC)) + +# Others force us to piece them together from parts... +LUA_PREFIX ?= $(shell $(PKGCONFIG) --variable=prefix $(_LUA_PC)) +LUA_LIBDIR ?= $(shell $(PKGCONFIG) --variable=libdir $(_LUA_PC)) +LUA_INCDIR ?= $(shell $(PKGCONFIG) --variable=includedir $(_LUA_PC)) +LUA_VERSION ?= $(shell $(PKGCONFIG) --modversion $(_LUA_PC) | grep -o '^.\..') + +LUA_LMOD_DIR ?= $(strip $(if $(LUA_PC_LMOD), $(LUA_PC_LMOD), \ + $(LUA_PREFIX)/share/lua/$(LUA_VERSION))) + +LUA_CMOD_DIR ?= $(strip $(if $(LUA_PC_CMOD), $(LUA_PC_CMOD), \ + $(LUA_LIBDIR)/lua/$(LUA_VERSION))) + +LUA_HEADERS ?= $(addprefix $(LUA_INCDIR)/, lua.h lauxlib.h) + + +%.so: %.o + $(CC) $(LDOPTIONS) -o $@ $< + +%.o: %.c + $(CC) $(CCOPTIONS) -c -o $@ $< + + +.DELETE_ON_ERROR: +.SECONDARY: From 62328fce1ba484aab309bd1fcf58ab330278d8ab Mon Sep 17 00:00:00 2001 From: Aapo Talvensaari Date: Thu, 29 Jan 2015 22:00:07 +0200 Subject: [PATCH 55/69] Added License info of @craigbarnes + added detection luaL_newlib. --- wrappers/Lua/coolprop/compat.h | 4 ++++ wrappers/Lua/lualib.mk | 15 +++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/wrappers/Lua/coolprop/compat.h b/wrappers/Lua/coolprop/compat.h index d6204026..e2345bfc 100644 --- a/wrappers/Lua/coolprop/compat.h +++ b/wrappers/Lua/coolprop/compat.h @@ -5,3 +5,7 @@ #ifndef LUA_VERSION_NUM # error Lua >= 5.1 is required. #endif + +#if LUA_VERSION_NUM < 502 +# define luaL_newlib(L, l) (lua_newtable(L), luaL_register(L, NULL, l)) +#endif \ No newline at end of file diff --git a/wrappers/Lua/lualib.mk b/wrappers/Lua/lualib.mk index 3b45f406..818bd95a 100644 --- a/wrappers/Lua/lualib.mk +++ b/wrappers/Lua/lualib.mk @@ -1,3 +1,18 @@ +# Lua pkg-config utilities for GNU Make. +# Copyright (c) 2013-2015, Craig Barnes. +# +# Permission to use, copy, modify, and/or distribute this software for any +# purpose with or without fee is hereby granted, provided that the above +# copyright notice and this permission notice appear in all copies. +# +# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY +# SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION +# OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN +# CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + -include local.mk CC ?= gcc From ca8d00c28e41a1c8c1e2c5fe043ac0a8306d98b1 Mon Sep 17 00:00:00 2001 From: Ian Bell Date: Fri, 30 Jan 2015 04:43:10 -0700 Subject: [PATCH 56/69] Compile javascript with assertions enabled for better debugging --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 16ac9ae5..639b6e4b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -860,7 +860,7 @@ if (COOLPROP_JAVASCRIPT_MODULE) add_definitions(-s DISABLE_EXCEPTION_CATCHING=0) add_definitions(-s ASSERTIONS=1) add_definitions(-DEXTERNC) - set(CMAKE_EXE_LINKER_FLAGS "-DEXTERNC -s EXPORTED_FUNCTIONS=\"['_main','_F2K','_Props1SI','_PropsSI','_get_global_param_string','_HAProps']\"") + set(CMAKE_EXE_LINKER_FLAGS "-DEXTERNC -s ASSERTIONS=1 -s EXPORTED_FUNCTIONS=\"['_main','_F2K','_Props1SI','_PropsSI','_get_global_param_string','_HAProps']\"") set(CMAKE_BUILD_TYPE Release) list(APPEND APP_SOURCES "${CMAKE_SOURCE_DIR}/src/CoolPropLib.cpp") From b81bb96c4e6add80df25bfc8385daac5a941575c Mon Sep 17 00:00:00 2001 From: Ian Bell Date: Fri, 30 Jan 2015 04:45:00 -0700 Subject: [PATCH 57/69] Added index.html for javascript --- Web/coolprop/wrappers/Javascript/index.html | 99 +++++++++++++++++++++ 1 file changed, 99 insertions(+) create mode 100644 Web/coolprop/wrappers/Javascript/index.html diff --git a/Web/coolprop/wrappers/Javascript/index.html b/Web/coolprop/wrappers/Javascript/index.html new file mode 100644 index 00000000..d53d7bab --- /dev/null +++ b/Web/coolprop/wrappers/Javascript/index.html @@ -0,0 +1,99 @@ + + + + +CoolProp Javascript example + + + + + + + + + + + + +
+ + +
+
+ + + +
+
+ + + +
+ + +
+ +
+
+

+

+ + + + + + From fa7af84ffc4a15fbf312b9a0eb6f405a10cc8557 Mon Sep 17 00:00:00 2001 From: Ian Bell Date: Fri, 30 Jan 2015 04:47:51 -0700 Subject: [PATCH 58/69] Install index.html for Javascript --- CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 639b6e4b..8c8c30fa 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -869,6 +869,7 @@ if (COOLPROP_JAVASCRIPT_MODULE) add_dependencies (coolprop generate_headers) SET_TARGET_PROPERTIES(coolprop PROPERTIES PREFIX "" SUFFIX .js) install (TARGETS coolprop DESTINATION ${CMAKE_INSTALL_PREFIX}/Javascript) + install (FILES "${CMAKE_SOURCE_DIR}/Web/coolprop/wrappers/Javascript/index.html" DESTINATION ${CMAKE_INSTALL_PREFIX}/Javascript) endif() if (COOLPROP_MATHEMATICA_MODULE) From 2495df75ed68b4320703d0bd6dde7bac1e4495aa Mon Sep 17 00:00:00 2001 From: Ian Bell Date: Fri, 30 Jan 2015 05:00:31 -0700 Subject: [PATCH 59/69] Catch exceptions in High-Level API; Closes #441 Signed-off-by: Ian Bell --- include/CoolPropLib.h | 2 +- src/CoolPropLib.cpp | 14 ++++++++++++-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/include/CoolPropLib.h b/include/CoolPropLib.h index 8000bf60..fb0d1a2f 100644 --- a/include/CoolPropLib.h +++ b/include/CoolPropLib.h @@ -146,7 +146,7 @@ EXPORT_CODE double CONVENTION K2F(double T_K); /** \brief Get the index for a parameter "T", "P", etc. * - * @returns index The index as a long + * @returns index The index as a long. If input is invalid, returns -1 */ EXPORT_CODE long CONVENTION get_param_index(const char *param); /** \brief Redirect all output that would go to console (stdout) to a file diff --git a/src/CoolPropLib.cpp b/src/CoolPropLib.cpp index 06d6439f..8cf8bd0d 100644 --- a/src/CoolPropLib.cpp +++ b/src/CoolPropLib.cpp @@ -228,7 +228,12 @@ EXPORT_CODE void CONVENTION set_debug_level(int level){ CoolProp::set_debug_level(level); } EXPORT_CODE long CONVENTION get_param_index(const char * param){ - return CoolProp::get_parameter_index(param); + try{ + return CoolProp::get_parameter_index(param); + } + catch(std::exception &){ + return -1; + } } EXPORT_CODE long CONVENTION get_global_param_string(const char *param, char * Output, int n) { @@ -249,7 +254,12 @@ EXPORT_CODE long CONVENTION get_global_param_string(const char *param, char * Ou } EXPORT_CODE long CONVENTION get_parameter_information_string(const char *param, char * Output, int n) { - int key = CoolProp::get_parameter_index(param); + try{ + int key = CoolProp::get_parameter_index(param); + } + catch(std::exception &){ + return 0; + } if (key >= 0){ std::string s = CoolProp::get_parameter_information(key, Output); if (s.size() < static_cast(n)){ From 0064728b56230a5d41cadd3f2517598e34913c20 Mon Sep 17 00:00:00 2001 From: Ian Bell Date: Fri, 30 Jan 2015 05:07:06 -0700 Subject: [PATCH 60/69] Fix bug with CoolPropLib.cpp int key scope Signed-off-by: Ian Bell --- src/CoolPropLib.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/CoolPropLib.cpp b/src/CoolPropLib.cpp index 8cf8bd0d..1503f4ba 100644 --- a/src/CoolPropLib.cpp +++ b/src/CoolPropLib.cpp @@ -254,8 +254,9 @@ EXPORT_CODE long CONVENTION get_global_param_string(const char *param, char * Ou } EXPORT_CODE long CONVENTION get_parameter_information_string(const char *param, char * Output, int n) { + int key; try{ - int key = CoolProp::get_parameter_index(param); + key = CoolProp::get_parameter_index(param); } catch(std::exception &){ return 0; From 324cc9eeccd57f81f6721da4e89eeb9b96bc270d Mon Sep 17 00:00:00 2001 From: Aapo Talvensaari Date: Fri, 30 Jan 2015 14:17:02 +0200 Subject: [PATCH 61/69] Added more APIs, added make install + make uninstall. Added documentation. Added more examples. Added some error handling. --- wrappers/Lua/Makefile | 16 ++- wrappers/Lua/README.rst | 184 ++++++++++++++++++++++++++++++++- wrappers/Lua/coolprop.lua | 22 ++-- wrappers/Lua/coolprop/compat.h | 2 +- wrappers/Lua/coolprop/ffi.lua | 39 ++++--- wrappers/Lua/example.lua | 52 +++++++--- 6 files changed, 277 insertions(+), 38 deletions(-) diff --git a/wrappers/Lua/Makefile b/wrappers/Lua/Makefile index 235f1ebd..5d248cb6 100644 --- a/wrappers/Lua/Makefile +++ b/wrappers/Lua/Makefile @@ -8,7 +8,7 @@ COOLPROP_LIBDIR ?= $(shell $(PKGCONFIG) --variable=libdir CoolProp) COOLPROP_HEADER ?= $(or $(COOLPROP_INCDIR) CFLAGS ?= -g -O2 -Wall -Wextra -Wswitch-enum -Wwrite-strings -Wshadow -XCFLAGS += -std=c99 -pedantic-errors -fpic +XCFLAGS += -std=c99 -pedantic-errors -fPIC XCFLAGS += $(LUA_CFLAGS) $(COOLPROP_CFLAGS) XLDFLAGS += $(GUMBO_LDFLAGS) $(COOLPROP_LDLIBS) @@ -16,9 +16,21 @@ all: coolprop/capi.so coolprop/capi.o: coolprop/capi.c coolprop/compat.h +install: all + $(MKDIR) '$(DESTDIR)$(LUA_CMOD_DIR)/coolprop' + $(MKDIR) '$(DESTDIR)$(LUA_LMOD_DIR)/coolprop' + $(INSTALLX) coolprop/capi.so '$(DESTDIR)$(LUA_CMOD_DIR)/coolprop/capi.so' + $(INSTALL) coolprop.lua '$(DESTDIR)$(LUA_LMOD_DIR)/' + $(INSTALL) coolprop/ffi.lua '$(DESTDIR)$(LUA_LMOD_DIR)/coolprop/' + +uninstall: + $(RM) '$(DESTDIR)$(LUA_LMOD_DIR)/coolprop.lua' + $(RM) -r '$(DESTDIR)$(LUA_CMOD_DIR)/coolprop/' + $(RM) -r '$(DESTDIR)$(LUA_LMOD_DIR)/coolprop/' + clean: $(RM) coolprop/capi.so coolprop/capi.o -.PHONY: all +.PHONY: all install uninstall clean .DELETE_ON_ERROR: diff --git a/wrappers/Lua/README.rst b/wrappers/Lua/README.rst index dbbdbcd9..82bde504 100644 --- a/wrappers/Lua/README.rst +++ b/wrappers/Lua/README.rst @@ -3,4 +3,186 @@ Lua Wrapper for CoolProp Lua C API and LuaJIT wrappers for CoolProp library (currently implementing the high-level C API). -by Aapo Talvensaari, Helsinki, Finland, January 2015 \ No newline at end of file +by Aapo Talvensaari, Helsinki, Finland, January 2015 + + +Hello World with Lua Wrapper +---------------------------- + +:: + + local cp = require "coolprop" + print(cp.Props1SI("Water", "D")) + + +Installation +------------ + +This wrapper comes with a support for both LuaJIT FFI and PUC-Lua C-API. + +**Installing with Make** + +1. Run ``make`` +2. Run ``make install`` +3. Done. + +**Manual Lua (PUC) Installation** + +1. First you need to build shared library version of a CoolLib library and install it somewhere in your operating system's library search path. +2. Next you need to compile ``coolprop/cpapi.c`` wrapper. Easiest way to do it is to run ``make`` on Lua wrapper's root folder. +3. Then place the resulting ``coolprop/cpapi.so`` in your Lua's ``package.cpath``, and there under ``coolprop`` directory. +4. Done. + +**Manual LuaJIT Installation** + +1. First you need to build shared library version of a CoolLib library and install it somewhere in your operating system's library search path. +2. Next you need to place ``coolprop.lua`` and ``coolprop/ffi.lua`` somewhere in your LuaJIT's ``package.path`` so that the LuaJIT can pick them up. +3. Done. + + +Lua API +------- + +The functions will in general return ``nil`` on error. + +**``number, string coolprop.PropsSI(output, name1, prop1, name2, prop2, ref)``** + +For many users, all that is needed is a simple call to the ``PropsSI`` function for pure fluids, pseudo-pure fluids +and mixtures. This function will return ``nil`` on error, and additional string that contains the error message. + +:: + local cp = require "coolprop" + print(cp.PropsSI("C", "P", 101325, "T", 300, "Water")) + print(cp.PropsSI("d(Hmass)/d(T)|P", "P", 101325, "T", 300, "Water")) + print(cp.PropsSI("D", "P", 101325, "T", 300, "Air.mix")) + + +**``number, string coolprop.Props1SI(fluidname, output)``** + +:: + local cp = require "coolprop" + print(cp.Props1SI("Water", "Phase")) + + +**``string coolprop.PhaseSI(name1, prop1, name2, prop2, ref)``** + +:: + local cp = require "coolprop" + print(cp.PhaseSI("P", 101325, "Q", 0, "Water")) + + +**``number, string coolprop.HAPropsSI(output, name1, prop1, name2, prop2, name3, prop3)``** + +:: + local cp = require "coolprop" + print(cp.HAPropsSI('H','T',298.15,'P',101325,'R',0.5)) + + +**``string coolprop.get_global_param_string(param)``** + +Returns global parameter string. On error, returns ``nil``. + +:: + local cp = require "coolprop" + print(cp.get_global_param_string("predefined_mixtures")) + + +**``number coolprop.get_param_index(param)``** + +Returns parameter index. + +:: + local cp = require "coolprop" + print(cp.get_param_index("T")) + + +**``number coolprop.F2K(f)``** + +This function converts fahrenheits to kelvins. + +:: + local cp = require "coolprop" + print(10, "Fahrenheits is", cp.F2K(10) , "Kelvins") + + +**``number coolprop.K2F(f)``** + +This function converts kelvins to fahrenheits. + +:: + local cp = require "coolprop" + print(cp.F2K(10), "Kelvins is", cp.K2F(cp.F2K(10)), "Fahrenheits") + + +**``string coolprop.error()``** + +Returns the last error occurred. + +:: + local cp = require "coolprop" + print(cp.error()) + + +**``string coolprop.FluidsList()``** + +Returns the list of available fluids. + +:: + local cp = require "coolprop" + print(cp.FluidsList()) + + +**``string coolprop.version()``** + +Returns the version of the CoolLib library that is installed. + +:: + local cp = require "coolprop" + print(cp.version()) + + +**``string coolprop.gitrevision()``** + +Returns the Git revision of the CoolLib library that is installed. + +:: + local cp = require "coolprop" + print(cp.gitrevision()) + + +**``number coolprop.get_debug_level()``** + +Returns the current debug level. + +:: + local cp = require "coolprop" + print(cp.get_debug_level()) + + +**``coolprop.set_debug_level(level)``** + +Sets the debug level. + +:: + local cp = require "coolprop" + cp.set_debug_level(0) + + +**``boolean coolprop.redirect_stdout(file)``** + +Sets the output to a file (to given path of the file). + +:: + local cp = require "coolprop" + cp.redirect_stdout("output.log") + + +Additional APIs (TBD) +--------------------- + +**``string coolprop.get_parameter_information_string(key)``** +**``number coolprop.get_mixture_binary_pair_data(cas1, cas2, key)``** +**``string coolprop.get_fluid_param_string(fluid, param)``** +**``boolean coolprop.set_reference_stateS(ref, state)``** +**``boolean coolprop.set_reference_stateD(ref, t, rho, h0, s0)``** +**``number, string coolprop.saturation_ancillary(fluid, output, q, input, value)``** diff --git a/wrappers/Lua/coolprop.lua b/wrappers/Lua/coolprop.lua index 7a1da887..33133bb4 100644 --- a/wrappers/Lua/coolprop.lua +++ b/wrappers/Lua/coolprop.lua @@ -1,26 +1,21 @@ if jit and jit.status() then return require "coolprop.ffi" end - local huge = math.huge - local ok, lib = pcall(require, "coolprop.capi") -assert(ok, "Unable to load CoolProp. Please check that the CoolProp is available. Both the Lua C API wrapper, and the CoolProp shared library.") +assert(ok, "Unable to load Lua CoolProp C API Wrapper.") local coolprop = {} -function coolprop.err() - return coolprop.get_global_param_string("errstring") -end function coolprop.Props1SI(fluidname, output) local v = lib.Props1SI(fluidname, output) if v == huge then - return nil, coolprop.err() + return nil, coolprop.error() end return v end function coolprop.PropsSI(output, name1, prop1, name2, prop2, ref) local v = lib.PropsSI(output, name1, prop1, name2, prop2, ref) if v == huge then - return nil, coolprop.err() + return nil, coolprop.error() end return v end @@ -64,7 +59,11 @@ function coolprop.get_param_index(param) return lib.get_param_index(param) end function coolprop.saturation_ancillary(fluid, output, q, input, value) - return lib.saturation_ancillary(fluid, output, q, input, value) + local v = lib.saturation_ancillary(fluid, output, q, input, value) + if v == huge then + return nil, coolprop.error() + end + return v end function coolprop.redirect_stdout(file) return lib.redirect_stdout(file) == 1 @@ -78,8 +77,11 @@ end function coolprop.HAPropsSI(output, name1, prop1, name2, prop2, name3, prop3) local v = lib.HAPropsSI(output, name1, prop1, name2, prop2, name3, prop3) if v == huge then - return nil, coolprop.err() + return nil, coolprop.error() end return v end +function coolprop.error() + return coolprop.get_global_param_string("errstring") +end return coolprop \ No newline at end of file diff --git a/wrappers/Lua/coolprop/compat.h b/wrappers/Lua/coolprop/compat.h index e2345bfc..2630cdba 100644 --- a/wrappers/Lua/coolprop/compat.h +++ b/wrappers/Lua/coolprop/compat.h @@ -8,4 +8,4 @@ #if LUA_VERSION_NUM < 502 # define luaL_newlib(L, l) (lua_newtable(L), luaL_register(L, NULL, l)) -#endif \ No newline at end of file +#endif diff --git a/wrappers/Lua/coolprop/ffi.lua b/wrappers/Lua/coolprop/ffi.lua index a5e95f39..c589a20d 100644 --- a/wrappers/Lua/coolprop/ffi.lua +++ b/wrappers/Lua/coolprop/ffi.lua @@ -4,6 +4,7 @@ local ffi_str = ffi.string local ffi_load = ffi.load local ffi_cdef = ffi.cdef local ffi_typeof = ffi.typeof +local pcall = pcall local huge = math.huge ffi_cdef[[ double Props1SI(const char *FluidName, const char* Output); @@ -32,21 +33,18 @@ local bub = ffi_new(but, 4096) local ok, lib = pcall(ffi_load, "CoolProp") if not ok then ok, lib = pcall(ffi_load, "coolprop") end assert(ok, "Unable to load CoolProp. Please check that the CoolProp shared library is in a default search path for dynamic libraries of your operating system.") -local coolprop = newtab(0, 18) -function coolprop.err() - return coolprop.get_global_param_string("errstring") -end +local coolprop = newtab(0, 21) function coolprop.Props1SI(fluidname, output) local v = lib.Props1SI(fluidname, output) if v == huge then - return nil, coolprop.err() + return nil, coolprop.error() end return v end function coolprop.PropsSI(output, name1, prop1, name2, prop2, ref) local v = lib.PropsSI(output, name1, prop1, name2, prop2, ref) if v == huge then - return nil, coolprop.err() + return nil, coolprop.error() end return v end @@ -63,9 +61,8 @@ function coolprop.get_global_param_string(param) return nil end function coolprop.get_parameter_information_string(key) - if lib.get_parameter_information_string(key, bub, 4096) == 1 then - return ffi_str(bub) - end + local ok, value = pcall(lib.get_parameter_information_string, key, bub, 4096) + if ok and value == 1 then return ffi_str(bub) end return nil end function coolprop.get_mixture_binary_pair_data(cas1, cas2, key) @@ -90,10 +87,16 @@ function coolprop.K2F(k) return lib.K2F(k) end function coolprop.get_param_index(param) - return tonumber(lib.get_param_index(param)) + local ok, value = pcall(lib.get_param_index, param) + if ok then return tonumber(value) end + return nil end function coolprop.saturation_ancillary(fluid, output, q, input, value) - return lib.saturation_ancillary(fluid, output, q, input, value) + local v = lib.saturation_ancillary(fluid, output, q, input, value) + if v == huge then + return nil, coolprop.error() + end + return v end function coolprop.redirect_stdout(file) return lib.redirect_stdout(file) == 1 @@ -107,8 +110,20 @@ end function coolprop.HAPropsSI(output, name1, prop1, name2, prop2, name3, prop3) local v = lib.HAPropsSI(output, name1, prop1, name2, prop2, name3, prop3) if v == huge then - return nil, coolprop.err() + return nil, coolprop.error() end return v end +function coolprop.error() + return coolprop.get_global_param_string("errstring") +end +function coolprop.FluidsList() + return coolprop.get_global_param_string("FluidsList") +end +function coolprop.version() + return coolprop.get_global_param_string("version") +end +function coolprop.gitrevision() + return coolprop.get_global_param_string("gitrevision") +end return coolprop diff --git a/wrappers/Lua/example.lua b/wrappers/Lua/example.lua index 4ce91c7a..847a065b 100644 --- a/wrappers/Lua/example.lua +++ b/wrappers/Lua/example.lua @@ -1,13 +1,41 @@ -local c = require "coolprop" +local cp = require "coolprop" -print(c.PropsSI("XX", "T", 298.15, "P", 101325, "Nitrogen")) -print(c.PropsSI("C", "P", 101325, "T", 300, "Water")) -print(c.PropsSI("d(Hmass)/d(T)|P", "P", 101325, "T", 300, "Water")) -print(c.PropsSI("D", "P", 101325, "T", 300, "Air.mix")) -print(c.PhaseSI("PXX", 101325, "Q", 0, "Water")) -print(c.get_global_param_string("predefined_mixtures")) -print(c.get_param_index("T")) -print(c.HAPropsSI('H','T',298.15,'P',101325,'R',0.5)) -print(c.HAPropsSI('HXXX','T',298.15,'P',101325,'R',0.5)) -print(c.F2K(10)) -print(c.K2F(c.F2K(10))) \ No newline at end of file +print[[ + +Information Examples +==================== +]] +print("Version", cp.version()) +print("gitrevision", cp.gitrevision()) +print("FluidsList", cp.FluidsList()) +print("Debug Level", cp.get_debug_level()) +print() +print[[ + +Usage Examples +============== +]] +print(cp.Props1SI("Water", "Phase")) +print(cp.PropsSI("C", "P", 101325, "T", 300, "Water")) +print(cp.PropsSI("d(Hmass)/d(T)|P", "P", 101325, "T", 300, "Water")) +print(cp.PropsSI("D", "P", 101325, "T", 300, "Air.mix")) +print(cp.PhaseSI("P", 101325, "Q", 0, "Water")) +print(cp.get_global_param_string("predefined_mixtures")) +print(cp.get_param_index("T")) +print(cp.HAPropsSI('H','T',298.15,'P',101325,'R',0.5)) +print(10, "Fahrenheits is", cp.F2K(10) , "Kelvins") +print(cp.F2K(10), "Kelvins is", cp.K2F(cp.F2K(10)), "Fahrenheits") +print() +print[[ + +Error Examples +============== +]] +print(cp.Props1SI("Error", "Phase")) +print(cp.PropsSI("Error", "T", 298.15, "P", 101325, "Nitrogen")) +print(cp.PhaseSI("Error", 101325, "Q", 0, "Water")) +print(cp.get_parameter_information_string("Error")) -- What are the correct inputs for this? +print(cp.saturation_ancillary("Water", "C", 10, "Error", 300)) -- What are the correct inputs for this? +print(cp.HAPropsSI('Error','T',298.15,'P',101325,'R',0.5)) +print(cp.get_param_index("Error")) +print() \ No newline at end of file From 4a20071b780d49bcf3f0ea47fe5a832f027d49f6 Mon Sep 17 00:00:00 2001 From: Aapo Talvensaari Date: Fri, 30 Jan 2015 14:22:53 +0200 Subject: [PATCH 62/69] Fixed RestructuredText formatting. --- wrappers/Lua/README.rst | 55 ++++++++++++++++++++++++++--------------- 1 file changed, 35 insertions(+), 20 deletions(-) diff --git a/wrappers/Lua/README.rst b/wrappers/Lua/README.rst index 82bde504..fd91fc4c 100644 --- a/wrappers/Lua/README.rst +++ b/wrappers/Lua/README.rst @@ -45,44 +45,49 @@ Lua API The functions will in general return ``nil`` on error. -**``number, string coolprop.PropsSI(output, name1, prop1, name2, prop2, ref)``** +**number, string coolprop.PropsSI(output, name1, prop1, name2, prop2, ref)** For many users, all that is needed is a simple call to the ``PropsSI`` function for pure fluids, pseudo-pure fluids and mixtures. This function will return ``nil`` on error, and additional string that contains the error message. :: + local cp = require "coolprop" print(cp.PropsSI("C", "P", 101325, "T", 300, "Water")) print(cp.PropsSI("d(Hmass)/d(T)|P", "P", 101325, "T", 300, "Water")) print(cp.PropsSI("D", "P", 101325, "T", 300, "Air.mix")) -**``number, string coolprop.Props1SI(fluidname, output)``** +**number, string coolprop.Props1SI(fluidname, output)** :: + local cp = require "coolprop" print(cp.Props1SI("Water", "Phase")) -**``string coolprop.PhaseSI(name1, prop1, name2, prop2, ref)``** +**string coolprop.PhaseSI(name1, prop1, name2, prop2, ref)** :: + local cp = require "coolprop" print(cp.PhaseSI("P", 101325, "Q", 0, "Water")) -**``number, string coolprop.HAPropsSI(output, name1, prop1, name2, prop2, name3, prop3)``** +**number, string coolprop.HAPropsSI(output, name1, prop1, name2, prop2, name3, prop3)** :: + local cp = require "coolprop" print(cp.HAPropsSI('H','T',298.15,'P',101325,'R',0.5)) -**``string coolprop.get_global_param_string(param)``** +**string coolprop.get_global_param_string(param)** Returns global parameter string. On error, returns ``nil``. :: + local cp = require "coolprop" print(cp.get_global_param_string("predefined_mixtures")) @@ -92,87 +97,97 @@ Returns global parameter string. On error, returns ``nil``. Returns parameter index. :: + local cp = require "coolprop" print(cp.get_param_index("T")) -**``number coolprop.F2K(f)``** +**number coolprop.F2K(f)** This function converts fahrenheits to kelvins. :: + local cp = require "coolprop" print(10, "Fahrenheits is", cp.F2K(10) , "Kelvins") -**``number coolprop.K2F(f)``** +**number coolprop.K2F(f)** This function converts kelvins to fahrenheits. :: + local cp = require "coolprop" print(cp.F2K(10), "Kelvins is", cp.K2F(cp.F2K(10)), "Fahrenheits") -**``string coolprop.error()``** +**string coolprop.error()** Returns the last error occurred. :: + local cp = require "coolprop" print(cp.error()) -**``string coolprop.FluidsList()``** +**string coolprop.FluidsList()** Returns the list of available fluids. :: + local cp = require "coolprop" print(cp.FluidsList()) -**``string coolprop.version()``** +**string coolprop.version()** Returns the version of the CoolLib library that is installed. :: + local cp = require "coolprop" print(cp.version()) -**``string coolprop.gitrevision()``** +**string coolprop.gitrevision()``** Returns the Git revision of the CoolLib library that is installed. :: + local cp = require "coolprop" print(cp.gitrevision()) -**``number coolprop.get_debug_level()``** +**number coolprop.get_debug_level()``** Returns the current debug level. :: + local cp = require "coolprop" print(cp.get_debug_level()) -**``coolprop.set_debug_level(level)``** +**coolprop.set_debug_level(level)``** Sets the debug level. :: + local cp = require "coolprop" cp.set_debug_level(0) -**``boolean coolprop.redirect_stdout(file)``** +**boolean coolprop.redirect_stdout(file)``** Sets the output to a file (to given path of the file). :: + local cp = require "coolprop" cp.redirect_stdout("output.log") @@ -180,9 +195,9 @@ Sets the output to a file (to given path of the file). Additional APIs (TBD) --------------------- -**``string coolprop.get_parameter_information_string(key)``** -**``number coolprop.get_mixture_binary_pair_data(cas1, cas2, key)``** -**``string coolprop.get_fluid_param_string(fluid, param)``** -**``boolean coolprop.set_reference_stateS(ref, state)``** -**``boolean coolprop.set_reference_stateD(ref, t, rho, h0, s0)``** -**``number, string coolprop.saturation_ancillary(fluid, output, q, input, value)``** +- **string coolprop.get_parameter_information_string(key)** +- **number coolprop.get_mixture_binary_pair_data(cas1, cas2, key)** +- **string coolprop.get_fluid_param_string(fluid, param)** +- **boolean coolprop.set_reference_stateS(ref, state)** +- **boolean coolprop.set_reference_stateD(ref, t, rho, h0, s0)** +- **number, string coolprop.saturation_ancillary(fluid, output, q, input, value)** From dce4399e070b8ccd6ece3945cf4e719cdd83ae1d Mon Sep 17 00:00:00 2001 From: Aapo Talvensaari Date: Fri, 30 Jan 2015 14:24:21 +0200 Subject: [PATCH 63/69] More fixes to RestructuredText formatting. --- wrappers/Lua/README.rst | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/wrappers/Lua/README.rst b/wrappers/Lua/README.rst index fd91fc4c..a7bb5516 100644 --- a/wrappers/Lua/README.rst +++ b/wrappers/Lua/README.rst @@ -12,7 +12,7 @@ Hello World with Lua Wrapper :: local cp = require "coolprop" - print(cp.Props1SI("Water", "D")) + print(cp.PropsSI("d(Hmass)/d(T)|P", "P", 101325, "T", 300, "Water")) Installation @@ -92,7 +92,7 @@ Returns global parameter string. On error, returns ``nil``. print(cp.get_global_param_string("predefined_mixtures")) -**``number coolprop.get_param_index(param)``** +**number coolprop.get_param_index(param)** Returns parameter index. @@ -152,7 +152,7 @@ Returns the version of the CoolLib library that is installed. print(cp.version()) -**string coolprop.gitrevision()``** +**string coolprop.gitrevision()** Returns the Git revision of the CoolLib library that is installed. @@ -162,7 +162,7 @@ Returns the Git revision of the CoolLib library that is installed. print(cp.gitrevision()) -**number coolprop.get_debug_level()``** +**number coolprop.get_debug_level()** Returns the current debug level. @@ -172,7 +172,7 @@ Returns the current debug level. print(cp.get_debug_level()) -**coolprop.set_debug_level(level)``** +**coolprop.set_debug_level(level)** Sets the debug level. @@ -182,7 +182,7 @@ Sets the debug level. cp.set_debug_level(0) -**boolean coolprop.redirect_stdout(file)``** +**boolean coolprop.redirect_stdout(file)** Sets the output to a file (to given path of the file). From 2ad75feddfa86fd61012d5d00f45bc2775f4317a Mon Sep 17 00:00:00 2001 From: Aapo Talvensaari Date: Fri, 30 Jan 2015 14:51:06 +0200 Subject: [PATCH 64/69] Merged with the upstream, and removed pcall's. not needed anymore. Fixed Lua C-API bindings to have same funcs that FFI version has. --- wrappers/Lua/README.rst | 4 ++++ wrappers/Lua/coolprop.lua | 16 ++++++++++++++-- wrappers/Lua/coolprop/ffi.lua | 12 ++++++------ 3 files changed, 24 insertions(+), 8 deletions(-) diff --git a/wrappers/Lua/README.rst b/wrappers/Lua/README.rst index a7bb5516..1abdc8a4 100644 --- a/wrappers/Lua/README.rst +++ b/wrappers/Lua/README.rst @@ -20,6 +20,10 @@ Installation This wrapper comes with a support for both LuaJIT FFI and PUC-Lua C-API. +To build a shared library of CoolProp, follow the instructions listed here: +http://www.coolprop.org/coolprop/wrappers/SharedLibrary/index.html + + **Installing with Make** 1. Run ``make`` diff --git a/wrappers/Lua/coolprop.lua b/wrappers/Lua/coolprop.lua index 33133bb4..a635d36e 100644 --- a/wrappers/Lua/coolprop.lua +++ b/wrappers/Lua/coolprop.lua @@ -32,7 +32,8 @@ function coolprop.get_global_param_string(param) end function coolprop.get_parameter_information_string(key) local e, s = lib.get_parameter_information_string(key) - return e == 1 and s or nil + if e == 0 then return nil end + return s end function coolprop.get_mixture_binary_pair_data(cas1, cas2, key) return tonumber(lib.get_mixture_binary_pair_data(cas1, cas2, key)) @@ -56,7 +57,9 @@ function coolprop.K2F(k) return lib.K2F(k) end function coolprop.get_param_index(param) - return lib.get_param_index(param) + local value = lib.get_param_index(param) + if value == -1 then return nil end + tonumber(value) end function coolprop.saturation_ancillary(fluid, output, q, input, value) local v = lib.saturation_ancillary(fluid, output, q, input, value) @@ -84,4 +87,13 @@ end function coolprop.error() return coolprop.get_global_param_string("errstring") end +function coolprop.FluidsList() + return coolprop.get_global_param_string("FluidsList") +end +function coolprop.version() + return coolprop.get_global_param_string("version") +end +function coolprop.gitrevision() + return coolprop.get_global_param_string("gitrevision") +end return coolprop \ No newline at end of file diff --git a/wrappers/Lua/coolprop/ffi.lua b/wrappers/Lua/coolprop/ffi.lua index c589a20d..73ad7de4 100644 --- a/wrappers/Lua/coolprop/ffi.lua +++ b/wrappers/Lua/coolprop/ffi.lua @@ -61,9 +61,9 @@ function coolprop.get_global_param_string(param) return nil end function coolprop.get_parameter_information_string(key) - local ok, value = pcall(lib.get_parameter_information_string, key, bub, 4096) - if ok and value == 1 then return ffi_str(bub) end - return nil + local value = lib.get_parameter_information_string(key, bub, 4096) + if value == 0 then return nil end + return ffi_str(bub) end function coolprop.get_mixture_binary_pair_data(cas1, cas2, key) return tonumber(lib.get_mixture_binary_pair_data(cas1, cas2, key)) @@ -87,9 +87,9 @@ function coolprop.K2F(k) return lib.K2F(k) end function coolprop.get_param_index(param) - local ok, value = pcall(lib.get_param_index, param) - if ok then return tonumber(value) end - return nil + local value = lib.get_param_index(param) + if value == -1 then return nil end + tonumber(value) end function coolprop.saturation_ancillary(fluid, output, q, input, value) local v = lib.saturation_ancillary(fluid, output, q, input, value) From 388685009593cbba5bf6f536bacf60f877eaf5be Mon Sep 17 00:00:00 2001 From: Ian Bell Date: Fri, 30 Jan 2015 12:45:45 -0600 Subject: [PATCH 65/69] Use updated VLE values; Progress on #434 Signed-off-by: Ian Bell --- src/Backends/Helmholtz/VLERoutines.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Backends/Helmholtz/VLERoutines.cpp b/src/Backends/Helmholtz/VLERoutines.cpp index bad3e266..0a2eb591 100644 --- a/src/Backends/Helmholtz/VLERoutines.cpp +++ b/src/Backends/Helmholtz/VLERoutines.cpp @@ -1180,8 +1180,8 @@ void SaturationSolvers::successive_substitution(HelmholtzEOSMixtureBackend &HEOS } while(std::abs(f) > 1e-12 && iter < options.Nstep_max); - HEOS.SatL->update_TP_guessrho(T, p, rhomolar_liq); - HEOS.SatV->update_TP_guessrho(T, p, rhomolar_vap); + HEOS.SatL->update_TP_guessrho(T, p, HEOS.SatL->rhomolar()); + HEOS.SatV->update_TP_guessrho(T, p, HEOS.SatV->rhomolar()); options.p = HEOS.SatL->p(); options.T = HEOS.SatL->T(); From fc45f706ad2268fd331b2708beaf698dff0cf476 Mon Sep 17 00:00:00 2001 From: Jorrit Wronski Date: Sat, 31 Jan 2015 11:26:31 +0100 Subject: [PATCH 66/69] Added a script to build the jscript repo on sourceforge servers --- dev/scripts/release.bsh | 4 ++-- dev/scripts/sfManageJavaScript.bsh | 29 +++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 2 deletions(-) create mode 100644 dev/scripts/sfManageJavaScript.bsh diff --git a/dev/scripts/release.bsh b/dev/scripts/release.bsh index 57e493af..b1a0a88b 100755 --- a/dev/scripts/release.bsh +++ b/dev/scripts/release.bsh @@ -115,8 +115,8 @@ else printMessage "Preparing the docs and moving them into the $BINFOLDER folder for staging" rsync $RSYNC_DRY_RUN $RSYNC_OPTS "frs.sf.net-$SFUSER:/home/frs/project/coolprop/CoolProp/$DOC4FILES" "$(basename $DOC4FILES)" unzip -qo "$(basename $DOC4FILES)" -d "$DOC4FOLDER" - zip -rq "$DOCFILE" $SPHFOLDER/* -x */$(basename $DOC4FOLDER)/* - mv "$DOCFILE" "$DOCFOLDER" + zip -rq "$DOCFILE" $SPHFOLDER/* -x */$(basename $DOC4FOLDER)/* + mv "$DOCFILE" "$DOCFOLDER" # if [ "$CPVERSION" == "nightly" ]; then printMessage "Detected nightly release, updating README.rst.txt" diff --git a/dev/scripts/sfManageJavaScript.bsh b/dev/scripts/sfManageJavaScript.bsh new file mode 100644 index 00000000..e173b932 --- /dev/null +++ b/dev/scripts/sfManageJavaScript.bsh @@ -0,0 +1,29 @@ +#!/bin/bash +# A little script to build the JavaScript repository on the +# web directory. Can be run to regenerate the repo in case +# it case it gets deleted accidentally. +# +FILDIR="/home/frs/project/coolprop/CoolProp" +WEBDIR="/home/project-web/coolprop/htdocs" +# +LATTMP="${FILDIR}/latest/dummy" +TARGETDIR="${WEBDIR}"/jscript +mkdir -p "${TARGETDIR}" +# +function parsePath { + local CURFILE="$1" + local CPVERSION=$(cut -d/ -f7 <<<"${CURFILE}") + local RES="${TARGETDIR}/coolprop-${CPVERSION}.js" + echo "${RES}" +} +# +JSFILES="$(find ${FILDIR} -iname '*coolprop.js')" +for CURFILE in $JSFILES; do + TARGETFILE="$(parsePath $CURFILE)" + ln -s "${CURFILE}" "${TARGETFILE}" +done +# +CURVER="${TARGETDIR}/$(ls ${TARGETDIR} | tail -n 2 | head -n 1)" +LATVER="$(parsePath $LATTMP)" +ln -s "${CURVER}" "${LATVER}" +exit 0 From 78c80283a26fb7f9b50a025b7b0a094a5cbc8024 Mon Sep 17 00:00:00 2001 From: Jorrit Wronski Date: Sat, 31 Jan 2015 12:28:53 +0100 Subject: [PATCH 67/69] Updated the docs and polished the bash script, last known working javascript version 5.0.3, this one should help with #442 --- Web/coolprop/wrappers/Javascript/index.html | 3 ++- Web/coolprop/wrappers/Javascript/index.rst | 4 +++- dev/scripts/sfManageJavaScript.bsh | 11 ++++++----- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/Web/coolprop/wrappers/Javascript/index.html b/Web/coolprop/wrappers/Javascript/index.html index d53d7bab..59ce9312 100644 --- a/Web/coolprop/wrappers/Javascript/index.html +++ b/Web/coolprop/wrappers/Javascript/index.html @@ -12,7 +12,8 @@ // - + + `` in your HTML header. Until now, this file does not get updated automatically, so please file an issue on User-Compiled Binaries ====================== diff --git a/dev/scripts/sfManageJavaScript.bsh b/dev/scripts/sfManageJavaScript.bsh index e173b932..991ee9a9 100644 --- a/dev/scripts/sfManageJavaScript.bsh +++ b/dev/scripts/sfManageJavaScript.bsh @@ -6,7 +6,6 @@ FILDIR="/home/frs/project/coolprop/CoolProp" WEBDIR="/home/project-web/coolprop/htdocs" # -LATTMP="${FILDIR}/latest/dummy" TARGETDIR="${WEBDIR}"/jscript mkdir -p "${TARGETDIR}" # @@ -20,10 +19,12 @@ function parsePath { JSFILES="$(find ${FILDIR} -iname '*coolprop.js')" for CURFILE in $JSFILES; do TARGETFILE="$(parsePath $CURFILE)" - ln -s "${CURFILE}" "${TARGETFILE}" + rsync "${CURFILE}" "${TARGETFILE}" done # -CURVER="${TARGETDIR}/$(ls ${TARGETDIR} | tail -n 2 | head -n 1)" -LATVER="$(parsePath $LATTMP)" -ln -s "${CURVER}" "${LATVER}" +pushd "${TARGETDIR}" +CURVER="$(ls | tail -n 3 | head -n 1)" +LATVER="coolprop-latest.js" +ln -sf "${CURVER}" "${LATVER}" +popd exit 0 From d189b3732ff158778fbcab348dd5183bba71bfd6 Mon Sep 17 00:00:00 2001 From: Ian Bell Date: Sun, 1 Feb 2015 19:02:24 -0600 Subject: [PATCH 68/69] Updated Javascript builder Signed-off-by: Ian Bell --- Web/coolprop/wrappers/Javascript/index.rst | 4 ++-- dev/buildbot/master/master.cfg | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Web/coolprop/wrappers/Javascript/index.rst b/Web/coolprop/wrappers/Javascript/index.rst index 48a48a77..148be9bc 100644 --- a/Web/coolprop/wrappers/Javascript/index.rst +++ b/Web/coolprop/wrappers/Javascript/index.rst @@ -53,7 +53,7 @@ We are following the instructions from `emscripten.org Date: Mon, 2 Feb 2015 12:21:28 -0500 Subject: [PATCH 69/69] Update codelite project Signed-off-by: Ian Bell --- dev/codelite/coolprop.project | 2 ++ 1 file changed, 2 insertions(+) diff --git a/dev/codelite/coolprop.project b/dev/codelite/coolprop.project index 96dc5cd2..d91b7202 100644 --- a/dev/codelite/coolprop.project +++ b/dev/codelite/coolprop.project @@ -160,6 +160,7 @@ + @@ -201,6 +202,7 @@ +