From 033747761320c5e5074e422899d87b49c560b1f6 Mon Sep 17 00:00:00 2001 From: Ray Speth Date: Tue, 28 Aug 2018 19:23:30 -0400 Subject: [PATCH 1/7] [Thermo] Make WaterSSTP constructible using newPhase This makes it possible to create a WaterSSTP phase using an XML input file, and use this model from Python and Matlab. --- include/cantera/thermo/WaterSSTP.h | 11 ++++++++--- src/thermo/ThermoFactory.cpp | 2 ++ test_problems/cathermo/testWaterTP/testWaterSSTP.cpp | 4 ++-- test_problems/cathermo/wtWater/wtWater.cpp | 4 ++-- 4 files changed, 14 insertions(+), 7 deletions(-) diff --git a/include/cantera/thermo/WaterSSTP.h b/include/cantera/thermo/WaterSSTP.h index bb56f3a6ed..30de4cbf48 100644 --- a/include/cantera/thermo/WaterSSTP.h +++ b/include/cantera/thermo/WaterSSTP.h @@ -65,9 +65,14 @@ class WaterProps; * * ## Instantiation of the Class * - * The constructor for this phase is NOT located in the default ThermoFactory - * for %Cantera. However, a new WaterSSTP object may be created by the following - * code snippets, combined with an XML file given in the XML example section. + * A new WaterSSTP object may be created by the following code snippets, + * combined with an XML file given in the XML example section. + * + * @code + * ThermoPhase* w = newPhase("waterSSTPphase.xml"); + * @endcode + * + * or * * @code * WaterSSTP *w = new WaterSSTP("waterSSTPphase.xml",""); diff --git a/src/thermo/ThermoFactory.cpp b/src/thermo/ThermoFactory.cpp index f09dfb8c86..bb85636b18 100644 --- a/src/thermo/ThermoFactory.cpp +++ b/src/thermo/ThermoFactory.cpp @@ -39,6 +39,7 @@ #include "cantera/thermo/IdealMolalSoln.h" #include "cantera/thermo/MolarityIonicVPSSTP.h" #include "cantera/thermo/IdealSolnGasVPSS.h" +#include "cantera/thermo/WaterSSTP.h" #include "cantera/base/stringUtils.h" using namespace std; @@ -77,6 +78,7 @@ ThermoFactory::ThermoFactory() reg("RedlichKwong", []() { return new RedlichKwongMFTP(); }); m_synonyms["RedlichKwongMFTP"] = "RedlichKwong"; reg("MaskellSolidSolnPhase", []() { return new MaskellSolidSolnPhase(); }); + reg("PureLiquidWater", []() { return new WaterSSTP(); }); } ThermoPhase* ThermoFactory::newThermoPhase(const std::string& model) diff --git a/test_problems/cathermo/testWaterTP/testWaterSSTP.cpp b/test_problems/cathermo/testWaterTP/testWaterSSTP.cpp index 1f5673611e..cc1dd8bee4 100644 --- a/test_problems/cathermo/testWaterTP/testWaterSSTP.cpp +++ b/test_problems/cathermo/testWaterTP/testWaterSSTP.cpp @@ -1,4 +1,4 @@ -#include "cantera/thermo/WaterSSTP.h" +#include "cantera/thermo/ThermoFactory.h" #include using namespace std; @@ -20,7 +20,7 @@ int main() #endif double pres; try { - WaterSSTP* w = new WaterSSTP("waterTPphase.xml", "water"); + ThermoPhase* w = newPhase("waterTPphase.xml"); /* * Print out the triple point conditions diff --git a/test_problems/cathermo/wtWater/wtWater.cpp b/test_problems/cathermo/wtWater/wtWater.cpp index 8c21ca3fd5..1cdd18437b 100644 --- a/test_problems/cathermo/wtWater/wtWater.cpp +++ b/test_problems/cathermo/wtWater/wtWater.cpp @@ -1,5 +1,5 @@ -#include "cantera/thermo/WaterSSTP.h" +#include "cantera/thermo/ThermoFactory.h" #include "cantera/transport/WaterTransport.h" #include @@ -20,7 +20,7 @@ int main() { try { double lambda; - WaterSSTP* w = new WaterSSTP("waterTPphase.xml", ""); + ThermoPhase* w = newPhase("waterTPphase.xml"); WaterTransport* wtTran = new WaterTransport(w, 3); printf("------------------------------------------------------------------------------------\n"); From c43aaeb184e1880f2fed565018fcd5eda3d391be Mon Sep 17 00:00:00 2001 From: Ray Speth Date: Tue, 28 Aug 2018 19:52:31 -0400 Subject: [PATCH 2/7] [SCons/Test] Regression tests also look for input files in test/data This allows the elimination of a number of duplicate input files. --- .../data}/HMW_NaCl_sp1977_alt.xml | 0 .../NaCl_equil => test/data}/NaCl_Solid.xml | 0 .../data/liquid-water.xml | 15 -- test_problems/SConscript | 11 +- .../cathermo/HMW_graph_CpvT/NaCl_Solid.xml | 39 --- .../HMW_graph_GvT/HMW_NaCl_sp1977_alt.xml | 239 ------------------ .../cathermo/HMW_graph_GvT/NaCl_Solid.xml | 39 --- .../HMW_graph_HvT/HMW_NaCl_sp1977_alt.xml | 239 ------------------ .../cathermo/HMW_graph_HvT/NaCl_Solid.xml | 39 --- .../HMW_graph_VvT/HMW_NaCl_sp1977_alt.xml | 239 ------------------ .../cathermo/HMW_graph_VvT/NaCl_Solid.xml | 39 --- .../cathermo/stoichSub/NaCl_Solid.xml | 39 --- .../cathermo/testWaterTP/testWaterSSTP.cpp | 2 +- .../cathermo/wtWater/waterTPphase.xml | 54 ---- test_problems/cathermo/wtWater/wtWater.cpp | 2 +- 15 files changed, 8 insertions(+), 988 deletions(-) rename {test_problems/cathermo/HMW_graph_CpvT => test/data}/HMW_NaCl_sp1977_alt.xml (100%) rename {test_problems/VCSnonideal/NaCl_equil => test/data}/NaCl_Solid.xml (100%) rename test_problems/cathermo/testWaterTP/waterTPphase.xml => test/data/liquid-water.xml (73%) delete mode 100644 test_problems/cathermo/HMW_graph_CpvT/NaCl_Solid.xml delete mode 100644 test_problems/cathermo/HMW_graph_GvT/HMW_NaCl_sp1977_alt.xml delete mode 100644 test_problems/cathermo/HMW_graph_GvT/NaCl_Solid.xml delete mode 100644 test_problems/cathermo/HMW_graph_HvT/HMW_NaCl_sp1977_alt.xml delete mode 100644 test_problems/cathermo/HMW_graph_HvT/NaCl_Solid.xml delete mode 100644 test_problems/cathermo/HMW_graph_VvT/HMW_NaCl_sp1977_alt.xml delete mode 100644 test_problems/cathermo/HMW_graph_VvT/NaCl_Solid.xml delete mode 100644 test_problems/cathermo/stoichSub/NaCl_Solid.xml delete mode 100644 test_problems/cathermo/wtWater/waterTPphase.xml diff --git a/test_problems/cathermo/HMW_graph_CpvT/HMW_NaCl_sp1977_alt.xml b/test/data/HMW_NaCl_sp1977_alt.xml similarity index 100% rename from test_problems/cathermo/HMW_graph_CpvT/HMW_NaCl_sp1977_alt.xml rename to test/data/HMW_NaCl_sp1977_alt.xml diff --git a/test_problems/VCSnonideal/NaCl_equil/NaCl_Solid.xml b/test/data/NaCl_Solid.xml similarity index 100% rename from test_problems/VCSnonideal/NaCl_equil/NaCl_Solid.xml rename to test/data/NaCl_Solid.xml diff --git a/test_problems/cathermo/testWaterTP/waterTPphase.xml b/test/data/liquid-water.xml similarity index 73% rename from test_problems/cathermo/testWaterTP/waterTPphase.xml rename to test/data/liquid-water.xml index a58b5a2bae..3a0faf0af6 100644 --- a/test_problems/cathermo/testWaterTP/waterTPphase.xml +++ b/test/data/liquid-water.xml @@ -35,20 +35,5 @@ - - - - - H:2 C:2 F:4 - - - 273.14999999999998 - 23083414.8686 - 167025.46599999999 - 0.0 - - - - diff --git a/test_problems/SConscript b/test_problems/SConscript index 17ec0fdf42..d4a5e9a3f8 100644 --- a/test_problems/SConscript +++ b/test_problems/SConscript @@ -32,7 +32,8 @@ else: localenv['ENV']['PYTHON_CMD'] = localenv.subst('$python_cmd') haveConverters = True -localenv['ENV']['CANTERA_DATA'] = pjoin(os.getcwd(), '..', 'build', 'data') +localenv['ENV']['CANTERA_DATA'] = (Dir('#build/data').abspath + os.pathsep + + Dir('#test/data').abspath) # Add build/lib in order to find Cantera shared library if env['OS'] == 'Windows' or env['OS'] == 'Cygwin': @@ -183,7 +184,7 @@ Test('DH_graph_Pitzer', 'cathermo/DH_graph_1', CompileAndTest('HMW_graph_CpvT', 'cathermo/HMW_graph_CpvT', 'HMW_graph_CpvT', 'output_blessed.txt', extensions=['^HMW_graph_CpvT.cpp'], - arguments='HMW_NaCl_sp1977_alt.xml') + arguments=File('#test/data/HMW_NaCl_sp1977_alt.xml').abspath) CompileAndTest('HMW_graph_GvI', 'cathermo/HMW_graph_GvI', 'HMW_graph_GvI', None, comparisons=[('T298_blessed.csv', 'T298.csv'), @@ -193,15 +194,15 @@ CompileAndTest('HMW_graph_GvI', 'cathermo/HMW_graph_GvI', CompileAndTest('HMW_graph_GvT', 'cathermo/HMW_graph_GvT', 'HMW_graph_GvT', 'output_blessed.txt', extensions=['^HMW_graph_GvT.cpp'], - arguments='HMW_NaCl_sp1977_alt.xml') + arguments=File('#test/data/HMW_NaCl_sp1977_alt.xml').abspath) CompileAndTest('HMW_graph_HvT', 'cathermo/HMW_graph_HvT', 'HMW_graph_HvT', 'output_blessed.txt', extensions=['^HMW_graph_HvT.cpp'], - arguments='HMW_NaCl_sp1977_alt.xml') + arguments=File('#test/data/HMW_NaCl_sp1977_alt.xml').abspath) CompileAndTest('HMW_graph_VvT', 'cathermo/HMW_graph_VvT', 'HMW_graph_VvT', 'output_blessed.txt', extensions=['^HMW_graph_VvT.cpp'], - arguments='HMW_NaCl_sp1977_alt.xml') + arguments=File('#test/data/HMW_NaCl_sp1977_alt.xml').abspath) CompileAndTest('HMW_test_1', 'cathermo/HMW_test_1', 'HMW_test_1', 'output_noD_blessed.txt') CompileAndTest('HMW_test_3', 'cathermo/HMW_test_3', diff --git a/test_problems/cathermo/HMW_graph_CpvT/NaCl_Solid.xml b/test_problems/cathermo/HMW_graph_CpvT/NaCl_Solid.xml deleted file mode 100644 index d711be8ff0..0000000000 --- a/test_problems/cathermo/HMW_graph_CpvT/NaCl_Solid.xml +++ /dev/null @@ -1,39 +0,0 @@ - - - - - - - - - O H C Fe Ca N Na Cl - - NaCl(S) - - 2.165 - - - - - - - - - - - Na:1 Cl:1 - - - - 50.72389, 6.672267, -2.517167, - 10.15934, -0.200675, -427.2115, - 130.3973 - - - - 2.165 - - - - - diff --git a/test_problems/cathermo/HMW_graph_GvT/HMW_NaCl_sp1977_alt.xml b/test_problems/cathermo/HMW_graph_GvT/HMW_NaCl_sp1977_alt.xml deleted file mode 100644 index 0e4b0e510a..0000000000 --- a/test_problems/cathermo/HMW_graph_GvT/HMW_NaCl_sp1977_alt.xml +++ /dev/null @@ -1,239 +0,0 @@ - - - - - - H2O(L) Cl- H+ Na+ OH- - - - 298.15 - 101325.0 - - Na+:6.0954 - Cl-:6.0954 - H+:2.1628E-9 - OH-:1.3977E-6 - - - - - - - - - - - - 0.0765, 0.008946, -3.3158E-6, - -777.03, -4.4706 - - 0.2664, 6.1608E-5, 1.0715E-6 , 0.0, 0.0 - 0.0 , 0.0, 0.0, 0.0, 0.0 - 0.00127, -4.655E-5, 0.0, - 33.317, 0.09421 - - 2.0 - - - - 0.1775, 0.0, 0.0, 0.0, 0.0 - 0.2945, 0.0, 0.0, 0.0, 0.0 - 0.0, 0.0, 0.0, 0.0, 0.0 - 0.0008, 0.0, 0.0, 0.0, 0.0 - 2.0 - - - - 0.0864, 0.0, 0.0, 0.0, 0.0 - 0.253, 0.0, 0.0, 0.0, 0.0 - 0.0, 0.0, 0.0, 0.0, 0.0 - 0.0044, 0.0, 0.0, 0.0, 0.0 - 2.0 - - - - -0.05 - - - - -0.05 - -0.006 - - - - 0.036 - - - - 0.036 - -0.004 - - - - H2O(L) - - O H C E Fe Si N Na Cl - - - - - - - - - - H:2 O:1 - - - - 7.255750050E+01, -6.624454020E-01, 2.561987460E-03, -4.365919230E-06, - 2.781789810E-09, -4.188654990E+04, -2.882801370E+02 - - - - - - - - - - - Na:1 E:-1 - +1 - - - - -57993.47558 , 305112.6040 , -592222.1591 , - 401977.9827 , 804.4195980 , 10625.24901 , - -133796.2298 - - - - - - - 0.00834 - - - - - - Cl:1 E:1 - -1 - - - - 0.00834 - - - - - 56696.2042 , -297835.978 , 581426.549 , - -401759.991 , -804.301136 , -10873.8257 , - 130650.697 - - - - - - - - H:1 E:-1 - +1 - - 0.0 - - - - 0.0 - 3 - - 0.0 , 0.0, 0.0 - - - 273.15, 298.15 , 623.15 - - - - - - - - O:1 H:1 E:1 - -1 - - - 0.00834 - - - - - 44674.99961 , -234943.0414 , 460522.8260 , - -320695.1836 , -638.5044716 , -8683.955813 , - 102874.2667 - - - - - - - - diff --git a/test_problems/cathermo/HMW_graph_GvT/NaCl_Solid.xml b/test_problems/cathermo/HMW_graph_GvT/NaCl_Solid.xml deleted file mode 100644 index d711be8ff0..0000000000 --- a/test_problems/cathermo/HMW_graph_GvT/NaCl_Solid.xml +++ /dev/null @@ -1,39 +0,0 @@ - - - - - - - - - O H C Fe Ca N Na Cl - - NaCl(S) - - 2.165 - - - - - - - - - - - Na:1 Cl:1 - - - - 50.72389, 6.672267, -2.517167, - 10.15934, -0.200675, -427.2115, - 130.3973 - - - - 2.165 - - - - - diff --git a/test_problems/cathermo/HMW_graph_HvT/HMW_NaCl_sp1977_alt.xml b/test_problems/cathermo/HMW_graph_HvT/HMW_NaCl_sp1977_alt.xml deleted file mode 100644 index 0e4b0e510a..0000000000 --- a/test_problems/cathermo/HMW_graph_HvT/HMW_NaCl_sp1977_alt.xml +++ /dev/null @@ -1,239 +0,0 @@ - - - - - - H2O(L) Cl- H+ Na+ OH- - - - 298.15 - 101325.0 - - Na+:6.0954 - Cl-:6.0954 - H+:2.1628E-9 - OH-:1.3977E-6 - - - - - - - - - - - - 0.0765, 0.008946, -3.3158E-6, - -777.03, -4.4706 - - 0.2664, 6.1608E-5, 1.0715E-6 , 0.0, 0.0 - 0.0 , 0.0, 0.0, 0.0, 0.0 - 0.00127, -4.655E-5, 0.0, - 33.317, 0.09421 - - 2.0 - - - - 0.1775, 0.0, 0.0, 0.0, 0.0 - 0.2945, 0.0, 0.0, 0.0, 0.0 - 0.0, 0.0, 0.0, 0.0, 0.0 - 0.0008, 0.0, 0.0, 0.0, 0.0 - 2.0 - - - - 0.0864, 0.0, 0.0, 0.0, 0.0 - 0.253, 0.0, 0.0, 0.0, 0.0 - 0.0, 0.0, 0.0, 0.0, 0.0 - 0.0044, 0.0, 0.0, 0.0, 0.0 - 2.0 - - - - -0.05 - - - - -0.05 - -0.006 - - - - 0.036 - - - - 0.036 - -0.004 - - - - H2O(L) - - O H C E Fe Si N Na Cl - - - - - - - - - - H:2 O:1 - - - - 7.255750050E+01, -6.624454020E-01, 2.561987460E-03, -4.365919230E-06, - 2.781789810E-09, -4.188654990E+04, -2.882801370E+02 - - - - - - - - - - - Na:1 E:-1 - +1 - - - - -57993.47558 , 305112.6040 , -592222.1591 , - 401977.9827 , 804.4195980 , 10625.24901 , - -133796.2298 - - - - - - - 0.00834 - - - - - - Cl:1 E:1 - -1 - - - - 0.00834 - - - - - 56696.2042 , -297835.978 , 581426.549 , - -401759.991 , -804.301136 , -10873.8257 , - 130650.697 - - - - - - - - H:1 E:-1 - +1 - - 0.0 - - - - 0.0 - 3 - - 0.0 , 0.0, 0.0 - - - 273.15, 298.15 , 623.15 - - - - - - - - O:1 H:1 E:1 - -1 - - - 0.00834 - - - - - 44674.99961 , -234943.0414 , 460522.8260 , - -320695.1836 , -638.5044716 , -8683.955813 , - 102874.2667 - - - - - - - - diff --git a/test_problems/cathermo/HMW_graph_HvT/NaCl_Solid.xml b/test_problems/cathermo/HMW_graph_HvT/NaCl_Solid.xml deleted file mode 100644 index d711be8ff0..0000000000 --- a/test_problems/cathermo/HMW_graph_HvT/NaCl_Solid.xml +++ /dev/null @@ -1,39 +0,0 @@ - - - - - - - - - O H C Fe Ca N Na Cl - - NaCl(S) - - 2.165 - - - - - - - - - - - Na:1 Cl:1 - - - - 50.72389, 6.672267, -2.517167, - 10.15934, -0.200675, -427.2115, - 130.3973 - - - - 2.165 - - - - - diff --git a/test_problems/cathermo/HMW_graph_VvT/HMW_NaCl_sp1977_alt.xml b/test_problems/cathermo/HMW_graph_VvT/HMW_NaCl_sp1977_alt.xml deleted file mode 100644 index 0e4b0e510a..0000000000 --- a/test_problems/cathermo/HMW_graph_VvT/HMW_NaCl_sp1977_alt.xml +++ /dev/null @@ -1,239 +0,0 @@ - - - - - - H2O(L) Cl- H+ Na+ OH- - - - 298.15 - 101325.0 - - Na+:6.0954 - Cl-:6.0954 - H+:2.1628E-9 - OH-:1.3977E-6 - - - - - - - - - - - - 0.0765, 0.008946, -3.3158E-6, - -777.03, -4.4706 - - 0.2664, 6.1608E-5, 1.0715E-6 , 0.0, 0.0 - 0.0 , 0.0, 0.0, 0.0, 0.0 - 0.00127, -4.655E-5, 0.0, - 33.317, 0.09421 - - 2.0 - - - - 0.1775, 0.0, 0.0, 0.0, 0.0 - 0.2945, 0.0, 0.0, 0.0, 0.0 - 0.0, 0.0, 0.0, 0.0, 0.0 - 0.0008, 0.0, 0.0, 0.0, 0.0 - 2.0 - - - - 0.0864, 0.0, 0.0, 0.0, 0.0 - 0.253, 0.0, 0.0, 0.0, 0.0 - 0.0, 0.0, 0.0, 0.0, 0.0 - 0.0044, 0.0, 0.0, 0.0, 0.0 - 2.0 - - - - -0.05 - - - - -0.05 - -0.006 - - - - 0.036 - - - - 0.036 - -0.004 - - - - H2O(L) - - O H C E Fe Si N Na Cl - - - - - - - - - - H:2 O:1 - - - - 7.255750050E+01, -6.624454020E-01, 2.561987460E-03, -4.365919230E-06, - 2.781789810E-09, -4.188654990E+04, -2.882801370E+02 - - - - - - - - - - - Na:1 E:-1 - +1 - - - - -57993.47558 , 305112.6040 , -592222.1591 , - 401977.9827 , 804.4195980 , 10625.24901 , - -133796.2298 - - - - - - - 0.00834 - - - - - - Cl:1 E:1 - -1 - - - - 0.00834 - - - - - 56696.2042 , -297835.978 , 581426.549 , - -401759.991 , -804.301136 , -10873.8257 , - 130650.697 - - - - - - - - H:1 E:-1 - +1 - - 0.0 - - - - 0.0 - 3 - - 0.0 , 0.0, 0.0 - - - 273.15, 298.15 , 623.15 - - - - - - - - O:1 H:1 E:1 - -1 - - - 0.00834 - - - - - 44674.99961 , -234943.0414 , 460522.8260 , - -320695.1836 , -638.5044716 , -8683.955813 , - 102874.2667 - - - - - - - - diff --git a/test_problems/cathermo/HMW_graph_VvT/NaCl_Solid.xml b/test_problems/cathermo/HMW_graph_VvT/NaCl_Solid.xml deleted file mode 100644 index d711be8ff0..0000000000 --- a/test_problems/cathermo/HMW_graph_VvT/NaCl_Solid.xml +++ /dev/null @@ -1,39 +0,0 @@ - - - - - - - - - O H C Fe Ca N Na Cl - - NaCl(S) - - 2.165 - - - - - - - - - - - Na:1 Cl:1 - - - - 50.72389, 6.672267, -2.517167, - 10.15934, -0.200675, -427.2115, - 130.3973 - - - - 2.165 - - - - - diff --git a/test_problems/cathermo/stoichSub/NaCl_Solid.xml b/test_problems/cathermo/stoichSub/NaCl_Solid.xml deleted file mode 100644 index d711be8ff0..0000000000 --- a/test_problems/cathermo/stoichSub/NaCl_Solid.xml +++ /dev/null @@ -1,39 +0,0 @@ - - - - - - - - - O H C Fe Ca N Na Cl - - NaCl(S) - - 2.165 - - - - - - - - - - - Na:1 Cl:1 - - - - 50.72389, 6.672267, -2.517167, - 10.15934, -0.200675, -427.2115, - 130.3973 - - - - 2.165 - - - - - diff --git a/test_problems/cathermo/testWaterTP/testWaterSSTP.cpp b/test_problems/cathermo/testWaterTP/testWaterSSTP.cpp index cc1dd8bee4..2e1a433a29 100644 --- a/test_problems/cathermo/testWaterTP/testWaterSSTP.cpp +++ b/test_problems/cathermo/testWaterTP/testWaterSSTP.cpp @@ -20,7 +20,7 @@ int main() #endif double pres; try { - ThermoPhase* w = newPhase("waterTPphase.xml"); + ThermoPhase* w = newPhase("liquid-water.xml"); /* * Print out the triple point conditions diff --git a/test_problems/cathermo/wtWater/waterTPphase.xml b/test_problems/cathermo/wtWater/waterTPphase.xml deleted file mode 100644 index a58b5a2bae..0000000000 --- a/test_problems/cathermo/wtWater/waterTPphase.xml +++ /dev/null @@ -1,54 +0,0 @@ - - - - - - - O H - H2O - - 300.0 - 101325.0 - - - - - - - - - - - - - H:2 O:1 - - - - 4.198640560E+00, -2.036434100E-03, 6.520402110E-06, -5.487970620E-09, - 1.771978170E-12, -3.029372670E+04, -8.490322080E-01 - - - - 3.033992490E+00, 2.176918040E-03, -1.640725180E-07, -9.704198700E-11, - 1.682009920E-14, -3.000429710E+04, 4.966770100E+00 - - - - - - - - H:2 C:2 F:4 - - - 273.14999999999998 - 23083414.8686 - 167025.46599999999 - 0.0 - - - - - - diff --git a/test_problems/cathermo/wtWater/wtWater.cpp b/test_problems/cathermo/wtWater/wtWater.cpp index 1cdd18437b..b1f2c09fe5 100644 --- a/test_problems/cathermo/wtWater/wtWater.cpp +++ b/test_problems/cathermo/wtWater/wtWater.cpp @@ -20,7 +20,7 @@ int main() { try { double lambda; - ThermoPhase* w = newPhase("waterTPphase.xml"); + ThermoPhase* w = newPhase("liquid-water.xml"); WaterTransport* wtTran = new WaterTransport(w, 3); printf("------------------------------------------------------------------------------------\n"); From ca656695d25e74c00cdc4aec2d3bd480adeea0c7 Mon Sep 17 00:00:00 2001 From: Ray Speth Date: Tue, 28 Aug 2018 22:47:41 -0400 Subject: [PATCH 3/7] [Transport] Make WaterTransport constructible using newTransportMgr This makes it possible to specify the WaterTransport model in XML input files, and to use the model from Python and Matlab. Resolves #289 --- include/cantera/transport/WaterTransport.h | 6 ++---- src/transport/TransportFactory.cpp | 2 ++ src/transport/WaterTransport.cpp | 7 +++++-- test/data/liquid-water.xml | 1 + test_problems/cathermo/wtWater/wtWater.cpp | 4 ++-- 5 files changed, 12 insertions(+), 8 deletions(-) diff --git a/include/cantera/transport/WaterTransport.h b/include/cantera/transport/WaterTransport.h index 785f0296be..de5eb61f95 100644 --- a/include/cantera/transport/WaterTransport.h +++ b/include/cantera/transport/WaterTransport.h @@ -81,11 +81,9 @@ class WaterTransport : public Transport */ virtual doublereal thermalConductivity(); -private: - //! Routine to do some common initializations at the start of using - //! this routine. - void initTP(); + virtual void init(thermo_t* thermo, int mode=0, int log_level=0); +private: //! Pointer to the WaterPropsIAPWS object, which does the actual calculations //! for the real equation of state /*! diff --git a/src/transport/TransportFactory.cpp b/src/transport/TransportFactory.cpp index f04fb870f7..bbdd22fe0a 100644 --- a/src/transport/TransportFactory.cpp +++ b/src/transport/TransportFactory.cpp @@ -8,6 +8,7 @@ #include "cantera/transport/MixTransport.h" #include "cantera/transport/UnityLewisTransport.h" #include "cantera/transport/IonGasTransport.h" +#include "cantera/transport/WaterTransport.h" #include "cantera/transport/SolidTransport.h" #include "cantera/transport/DustyGasTransport.h" #include "cantera/transport/SimpleTransport.h" @@ -52,6 +53,7 @@ TransportFactory::TransportFactory() reg("Mix", []() { return new MixTransport(); }); reg("Multi", []() { return new MultiTransport(); }); reg("Ion", []() { return new IonGasTransport(); }); + reg("Water", []() { return new WaterTransport(); }); m_synonyms["CK_Mix"] = "Mix"; m_synonyms["CK_Multi"] = "Multi"; reg("HighP", []() { return new HighPressureGasTransport(); }); diff --git a/src/transport/WaterTransport.cpp b/src/transport/WaterTransport.cpp index 1a9993166d..3919373fbd 100644 --- a/src/transport/WaterTransport.cpp +++ b/src/transport/WaterTransport.cpp @@ -16,11 +16,14 @@ namespace Cantera WaterTransport::WaterTransport(thermo_t* thermo, int ndim) : Transport(thermo, ndim) { - initTP(); + if (thermo) { + init(thermo); + } } -void WaterTransport::initTP() +void WaterTransport::init(thermo_t* thermo, int mode, int log_level) { + m_thermo = thermo; // The expectation is that we have a VPStandardStateTP derived object VPStandardStateTP* vpthermo = dynamic_cast(m_thermo); if (!vpthermo) { diff --git a/test/data/liquid-water.xml b/test/data/liquid-water.xml index 3a0faf0af6..798f0895eb 100644 --- a/test/data/liquid-water.xml +++ b/test/data/liquid-water.xml @@ -12,6 +12,7 @@ + diff --git a/test_problems/cathermo/wtWater/wtWater.cpp b/test_problems/cathermo/wtWater/wtWater.cpp index b1f2c09fe5..61f2d056f0 100644 --- a/test_problems/cathermo/wtWater/wtWater.cpp +++ b/test_problems/cathermo/wtWater/wtWater.cpp @@ -1,6 +1,6 @@ #include "cantera/thermo/ThermoFactory.h" -#include "cantera/transport/WaterTransport.h" +#include "cantera/transport/TransportFactory.h" #include @@ -22,7 +22,7 @@ int main() double lambda; ThermoPhase* w = newPhase("liquid-water.xml"); - WaterTransport* wtTran = new WaterTransport(w, 3); + Transport* wtTran = newDefaultTransportMgr(w); printf("------------------------------------------------------------------------------------\n"); printf(" T(C) MPa Phase Visc Visc(paper) lambda lambda(paper)\n"); printf(" 10-6 kg/m/s 10-3 W/m/s \n"); From 2b9cdbd3a09cbf08848c1638d019b1ddf06496ad Mon Sep 17 00:00:00 2001 From: Ray Speth Date: Tue, 28 Aug 2018 23:50:36 -0400 Subject: [PATCH 4/7] [Transport] Migrate wtWater test to GTest test suite --- test/transport/transportModels.cpp | 52 +++++++++ test_problems/SConscript | 2 - .../cathermo/wtWater/output_blessed.txt | 12 -- test_problems/cathermo/wtWater/wtWater.cpp | 103 ------------------ 4 files changed, 52 insertions(+), 117 deletions(-) create mode 100644 test/transport/transportModels.cpp delete mode 100644 test_problems/cathermo/wtWater/output_blessed.txt delete mode 100644 test_problems/cathermo/wtWater/wtWater.cpp diff --git a/test/transport/transportModels.cpp b/test/transport/transportModels.cpp new file mode 100644 index 0000000000..19d6786d0d --- /dev/null +++ b/test/transport/transportModels.cpp @@ -0,0 +1,52 @@ +#include "gtest/gtest.h" + +#include "cantera/transport/TransportFactory.h" +#include "cantera/thermo/ThermoFactory.h" + +using namespace Cantera; + +class WaterTransportTest : public testing::Test +{ +public: + WaterTransportTest() { + phase = newPhase("liquid-water.xml"); + tran = newDefaultTransportMgr(phase); + } + + void check_viscosity(double T, double P, double mu_expected) { + phase->setState_TP(T + 273.15, P); + EXPECT_NEAR(tran->viscosity(), mu_expected, 2e-7); + } + + void check_thermal_conductivity(double T, double P, double lambda_expected) { + phase->setState_TP(T + 273.15, P); + EXPECT_NEAR(tran->thermalConductivity(), lambda_expected, 3e-4); + } + + ThermoPhase* phase; + Transport* tran; +}; + +// Reference values taken from tables in the Sengers and Watson paper +// (doi:10.1063/1.555763) which is the source of the interpolating equations. +TEST_F(WaterTransportTest, viscosity) +{ + check_viscosity(25, 1e5, 890.5e-6); + check_viscosity(100, 5e5, 281.9e-6); + check_viscosity(100, 1e7, 284.5e-6); + check_viscosity(250, 5e6, 106.4e-6); + check_viscosity(250, 5e7, 117.5e-6); + check_viscosity(350, 1.75e7, 67.0e-6); + check_viscosity(400, 1.5e7, 24.93e-6); +} + +TEST_F(WaterTransportTest, thermal_conductivity) +{ + check_thermal_conductivity(25, 1e5, 0.6072); + check_thermal_conductivity(100, 5e5, 0.6793); + check_thermal_conductivity(100, 1e7, 0.6845); + check_thermal_conductivity(250, 5e6, 0.6227); + check_thermal_conductivity(250, 5e7, 0.6721); + check_thermal_conductivity(350, 1.75e7, 0.4523); + check_thermal_conductivity(400, 1.5e7, 0.08068); +} diff --git a/test_problems/SConscript b/test_problems/SConscript index d4a5e9a3f8..d48c09dd92 100644 --- a/test_problems/SConscript +++ b/test_problems/SConscript @@ -217,8 +217,6 @@ CompileAndTest('WaterSSTP', 'cathermo/testWaterTP', 'testWaterSSTP', 'output_blessed.txt') CompileAndTest('ISSPTester2', 'cathermo/VPissp', 'ISSPTester2', 'output_blessed.txt') -CompileAndTest('wtWater', 'cathermo/wtWater', - 'wtWater', 'output_blessed.txt') CompileAndTest('ChemEquil_ionizedGas', 'ChemEquil_ionizedGas', 'ionizedGasEquil', 'output_blessed.txt', diff --git a/test_problems/cathermo/wtWater/output_blessed.txt b/test_problems/cathermo/wtWater/output_blessed.txt deleted file mode 100644 index 6d701d80fe..0000000000 --- a/test_problems/cathermo/wtWater/output_blessed.txt +++ /dev/null @@ -1,12 +0,0 @@ ------------------------------------------------------------------------------------- - T(C) MPa Phase Visc Visc(paper) lambda lambda(paper) - 10-6 kg/m/s 10-3 W/m/s ------------------------------------------------------------------------------------- - 25 0.1 L 890.5 890.5 607.2 607.2 - 100 0.1 L 281.8 281.9 679.1 679.1 - 100 10 L 284.457 284.5 684.47 684.5 - 250 5 L 106.405 106.4 622.487 622.7 - 250 50 L 117.43 117.5 671.917 672.1 - 350 17.5 L 66.9916 67.0 452.197 452.3 - 400 15 SC 24.9278 24.93 80.6816 80.68 ---------------------------------------------------------------------------------- diff --git a/test_problems/cathermo/wtWater/wtWater.cpp b/test_problems/cathermo/wtWater/wtWater.cpp deleted file mode 100644 index 61f2d056f0..0000000000 --- a/test_problems/cathermo/wtWater/wtWater.cpp +++ /dev/null @@ -1,103 +0,0 @@ - -#include "cantera/thermo/ThermoFactory.h" -#include "cantera/transport/TransportFactory.h" - -#include - -using namespace std; -using namespace Cantera; - -double tvalue(double val, double atol = 1.0E-9) -{ - double rval = val; - if (fabs(val) < atol) { - rval = 0.0; - } - return rval; -} - -int main() -{ - try { - double lambda; - ThermoPhase* w = newPhase("liquid-water.xml"); - - Transport* wtTran = newDefaultTransportMgr(w); - printf("------------------------------------------------------------------------------------\n"); - printf(" T(C) MPa Phase Visc Visc(paper) lambda lambda(paper)\n"); - printf(" 10-6 kg/m/s 10-3 W/m/s \n"); - printf("------------------------------------------------------------------------------------\n"); - - double T = 273.15 + 25.0; - double pres = 1.0E5; - w->setState_TP(T, pres); - double visc = wtTran->viscosity(); - lambda = wtTran->thermalConductivity(); - printf("%8g %10.3g L %13.4g 890.5 %13.4g 607.2\n", - T - 273.15, pres * 1.0E-6, visc * 1.0E6, lambda * 1.0E3); - - - T = 273.15 + 100.0; - pres = 1.0E5; - w->setState_TP(T, pres); - visc = wtTran->viscosity(); - lambda = wtTran->thermalConductivity(); - printf("%8g %10.3g L %13.4g 281.9 %13.4g 679.1\n", - T - 273.15, pres * 1.0E-6, visc * 1.0E6, lambda * 1.0E3); - - - - T = 273.15 + 100.0; - pres = 1.0E7; - w->setState_TP(T, pres); - visc = wtTran->viscosity(); - lambda = wtTran->thermalConductivity(); - printf("%8g %10.3g L %13.6g 284.5 %13.6g 684.5\n", - T - 273.15, pres * 1.0E-6, visc * 1.0E6, lambda * 1.0E3); - - T = 273.15 + 250.0; - pres = 5.0E6; - w->setState_TP(T, pres); - visc = wtTran->viscosity(); - lambda = wtTran->thermalConductivity(); - printf("%8g %10.3g L %13.6g 106.4 %13.6g 622.7\n", - T - 273.15, pres * 1.0E-6, visc * 1.0E6, lambda * 1.0E3); - - T = 273.15 + 250.0; - pres = 5.0E7; - w->setState_TP(T, pres); - visc = wtTran->viscosity(); - lambda = wtTran->thermalConductivity(); - printf("%8g %10.3g L %13.6g 117.5 %13.6g 672.1\n", - T - 273.15, pres * 1.0E-6, visc * 1.0E6, lambda * 1.0E3); - - - T = 273.15 + 350.0; - pres = 1.75E7; - w->setState_TP(T, pres); - visc = wtTran->viscosity(); - lambda = wtTran->thermalConductivity(); - printf("%8g %10.3g L %13.6g 67.0 %13.6g 452.3\n", - T - 273.15, pres * 1.0E-6, visc * 1.0E6, lambda * 1.0E3); - - - T = 273.15 + 400.0; - pres = 1.50E7; - w->setState_TP(T, pres); - visc = wtTran->viscosity(); - lambda = wtTran->thermalConductivity(); - printf("%8g %10.3g SC %13.6g 24.93 %13.6g 80.68\n", - T - 273.15, pres * 1.0E-6, visc * 1.0E6, lambda * 1.0E3); - - printf("---------------------------------------------------------------------------------\n"); - - delete w; - } catch (CanteraError& err) { - std::cout << err.what() << std::endl; - Cantera::appdelete(); - return -1; - } - - - return 0; -} From bd2fcd36d05f8b856c4c6e3004aecb3ee5b14f9e Mon Sep 17 00:00:00 2001 From: Ray Speth Date: Wed, 29 Aug 2018 23:12:26 -0400 Subject: [PATCH 5/7] [Transport] Move calculations into WaterTransport class Calculating viscosity and thermal conductivity in the WaterProps class was just an unnecessary level of indirection. --- include/cantera/thermo/WaterProps.h | 34 ------- src/thermo/WaterProps.cpp | 149 ---------------------------- src/transport/WaterTransport.cpp | 135 ++++++++++++++++++++++++- 3 files changed, 131 insertions(+), 187 deletions(-) diff --git a/include/cantera/thermo/WaterProps.h b/include/cantera/thermo/WaterProps.h index ec74fc263e..05c289be92 100644 --- a/include/cantera/thermo/WaterProps.h +++ b/include/cantera/thermo/WaterProps.h @@ -236,40 +236,6 @@ class WaterProps */ doublereal isothermalCompressibility_IAPWS(doublereal T, doublereal P); - //! Returns the viscosity of water at the current conditions - //! (kg/m/s) - /*! - * This function calculates the value of the viscosity of pure water at the - * current T and P. - * - * The formulas used are from the paper: J. V. Sengers, J. T. R. Watson, - * "Improved International Formulations for the Viscosity and Thermal - * Conductivity of Water Substance", J. Phys. Chem. Ref. Data, 15, 1291 - * (1986). - * - * The formulation is accurate for all temperatures and pressures, for steam - * and for water, even near the critical point. Pressures above 500 MPa and - * temperature above 900 C are suspect. - */ - doublereal viscosityWater() const; - - //! Returns the thermal conductivity of water at the current conditions - //! (W/m/K) - /*! - * This function calculates the value of the thermal conductivity of - * water at the current T and P. - * - * The formulas used are from the paper: J. V. Sengers, J. T. R. Watson, - * "Improved International Formulations for the Viscosity and Thermal - * Conductivity of Water Substance", J. Phys. Chem. Ref. Data, 15, 1291 - * (1986). - * - * The formulation is accurate for all temperatures and pressures, for steam - * and for water, even near the critical point. Pressures above 500 MPa and - * temperature above 900 C are suspect. - */ - doublereal thermalConductivityWater() const; - protected: //! Pointer to the WaterPropsIAPWS object WaterPropsIAPWS* m_waterIAPWS; diff --git a/src/thermo/WaterProps.cpp b/src/thermo/WaterProps.cpp index 0244e7b8e7..01ed150b0d 100644 --- a/src/thermo/WaterProps.cpp +++ b/src/thermo/WaterProps.cpp @@ -263,153 +263,4 @@ doublereal WaterProps::isothermalCompressibility_IAPWS(doublereal temp, doublere return m_waterIAPWS->isothermalCompressibility(); } -static const doublereal H[4] = {1., 0.978197, 0.579829, -0.202354}; - -static const doublereal Hij[6][7] = { - { 0.5132047, 0.2151778, -0.2818107, 0.1778064, -0.04176610, 0., 0.}, - { 0.3205656, 0.7317883, -1.070786 , 0.4605040, 0., -0.01578386, 0.}, - { 0., 1.241044 , -1.263184 , 0.2340379, 0., 0., 0.}, - { 0., 1.476783 , 0., -0.4924179, 0.1600435, 0., -0.003629481}, - {-0.7782567, 0.0 , 0., 0. , 0., 0., 0.}, - { 0.1885447, 0.0 , 0., 0. , 0., 0., 0.}, -}; - -static const doublereal rhoStar = 317.763; // kg / m3 -static const doublereal presStar = 22.115E6; // Pa - -doublereal WaterProps::viscosityWater() const -{ - static const doublereal TStar = 647.27; // Kelvin - static const doublereal muStar = 55.071E-6; //Pa s - doublereal temp = m_waterIAPWS->temperature(); - doublereal dens = m_waterIAPWS->density(); - - doublereal rhobar = dens/rhoStar; - doublereal tbar = temp / TStar; - doublereal tbar2 = tbar * tbar; - doublereal tbar3 = tbar2 * tbar; - doublereal mu0bar = std::sqrt(tbar) / (H[0] + H[1]/tbar + H[2]/tbar2 + H[3]/tbar3); - - doublereal tfac1 = 1.0 / tbar - 1.0; - doublereal tfac2 = tfac1 * tfac1; - doublereal tfac3 = tfac2 * tfac1; - doublereal tfac4 = tfac3 * tfac1; - doublereal tfac5 = tfac4 * tfac1; - - doublereal rfac1 = rhobar - 1.0; - doublereal rfac2 = rfac1 * rfac1; - doublereal rfac3 = rfac2 * rfac1; - doublereal rfac4 = rfac3 * rfac1; - doublereal rfac5 = rfac4 * rfac1; - doublereal rfac6 = rfac5 * rfac1; - - doublereal sum = (Hij[0][0] + Hij[1][0]*tfac1 + Hij[4][0]*tfac4 + Hij[5][0]*tfac5 + - Hij[0][1]*rfac1 + Hij[1][1]*tfac1*rfac1 + Hij[2][1]*tfac2*rfac1 + Hij[3][1]*tfac3*rfac1 + - Hij[0][2]*rfac2 + Hij[1][2]*tfac1*rfac2 + Hij[2][2]*tfac2*rfac2 + - Hij[0][3]*rfac3 + Hij[1][3]*tfac1*rfac3 + Hij[2][3]*tfac2*rfac3 + Hij[3][3]*tfac3*rfac3 + - Hij[0][4]*rfac4 + Hij[3][4]*tfac3*rfac4 + - Hij[1][5]*tfac1*rfac5 + Hij[3][6]*tfac3*rfac6 - ); - doublereal mu1bar = std::exp(rhobar * sum); - - // Apply the near-critical point corrections if necessary - doublereal mu2bar = 1.0; - if (tbar >= 0.9970 && tbar <= 1.0082 && rhobar >= 0.755 && rhobar <= 1.290) { - doublereal drhodp = 1.0 / m_waterIAPWS->dpdrho(); - drhodp *= presStar / rhoStar; - doublereal xsi = rhobar * drhodp; - if (xsi >= 21.93) { - mu2bar = 0.922 * std::pow(xsi, 0.0263); - } - } - - doublereal mubar = mu0bar * mu1bar * mu2bar; - return mubar * muStar; -} - -doublereal WaterProps::thermalConductivityWater() const -{ - static const doublereal Tstar = 647.27; - static const doublereal rhostar = 317.763; - static const doublereal lambdastar = 0.4945; - static const doublereal presstar = 22.115E6; - static const doublereal L[4] = { - 1.0000, - 6.978267, - 2.599096, - -0.998254 - }; - static const doublereal Lji[6][5] = { - { 1.3293046, 1.7018363, 5.2246158, 8.7127675, -1.8525999}, - {-0.40452437, -2.2156845, -10.124111, -9.5000611, 0.93404690}, - { 0.24409490, 1.6511057, 4.9874687, 4.3786606, 0.0}, - { 0.018660751, -0.76736002, -0.27297694, -0.91783782, 0.0}, - {-0.12961068, 0.37283344, -0.43083393, 0.0, 0.0}, - { 0.044809953, -0.11203160, 0.13333849, 0.0, 0.0}, - }; - - doublereal temp = m_waterIAPWS->temperature(); - doublereal dens = m_waterIAPWS->density(); - - doublereal rhobar = dens/rhostar; - doublereal tbar = temp / Tstar; - doublereal tbar2 = tbar * tbar; - doublereal tbar3 = tbar2 * tbar; - doublereal lambda0bar = sqrt(tbar) / (L[0] + L[1]/tbar + L[2]/tbar2 + L[3]/tbar3); - - doublereal tfac1 = 1.0 / tbar - 1.0; - doublereal tfac2 = tfac1 * tfac1; - doublereal tfac3 = tfac2 * tfac1; - doublereal tfac4 = tfac3 * tfac1; - - doublereal rfac1 = rhobar - 1.0; - doublereal rfac2 = rfac1 * rfac1; - doublereal rfac3 = rfac2 * rfac1; - doublereal rfac4 = rfac3 * rfac1; - doublereal rfac5 = rfac4 * rfac1; - - doublereal sum = (Lji[0][0] + Lji[0][1]*tfac1 + Lji[0][2]*tfac2 + Lji[0][3]*tfac3 + Lji[0][4]*tfac4 + - Lji[1][0]*rfac1 + Lji[1][1]*tfac1*rfac1 + Lji[1][2]*tfac2*rfac1 + Lji[1][3]*tfac3*rfac1 + Lji[1][4]*tfac4*rfac1 + - Lji[2][0]*rfac2 + Lji[2][1]*tfac1*rfac2 + Lji[2][2]*tfac2*rfac2 + Lji[2][3]*tfac3*rfac2 + - Lji[3][0]*rfac3 + Lji[3][1]*tfac1*rfac3 + Lji[3][2]*tfac2*rfac3 + Lji[3][3]*tfac3*rfac3 + - Lji[4][0]*rfac4 + Lji[4][1]*tfac1*rfac4 + Lji[4][2]*tfac2*rfac4 + - Lji[5][0]*rfac5 + Lji[5][1]*tfac1*rfac5 + Lji[5][2]*tfac2*rfac5 - ); - doublereal lambda1bar = exp(rhobar * sum); - doublereal mu0bar = std::sqrt(tbar) / (H[0] + H[1]/tbar + H[2]/tbar2 + H[3]/tbar3); - doublereal tfac5 = tfac4 * tfac1; - doublereal rfac6 = rfac5 * rfac1; - - sum = (Hij[0][0] + Hij[1][0]*tfac1 + Hij[4][0]*tfac4 + Hij[5][0]*tfac5 + - Hij[0][1]*rfac1 + Hij[1][1]*tfac1*rfac1 + Hij[2][1]*tfac2*rfac1 + Hij[3][1]*tfac3*rfac1 + - Hij[0][2]*rfac2 + Hij[1][2]*tfac1*rfac2 + Hij[2][2]*tfac2*rfac2 + - Hij[0][3]*rfac3 + Hij[1][3]*tfac1*rfac3 + Hij[2][3]*tfac2*rfac3 + Hij[3][3]*tfac3*rfac3 + - Hij[0][4]*rfac4 + Hij[3][4]*tfac3*rfac4 + - Hij[1][5]*tfac1*rfac5 + Hij[3][6]*tfac3*rfac6 - ); - doublereal mu1bar = std::exp(rhobar * sum); - doublereal t2r2 = tbar * tbar / (rhobar * rhobar); - doublereal drhodp = 1.0 / m_waterIAPWS->dpdrho(); - drhodp *= presStar / rhoStar; - doublereal xsi = rhobar * drhodp; - doublereal xsipow = std::pow(xsi, 0.4678); - doublereal rho1 = rhobar - 1.; - doublereal rho2 = rho1 * rho1; - doublereal rho4 = rho2 * rho2; - doublereal temp2 = (tbar - 1.0) * (tbar - 1.0); - - // beta = M / (rho * Rgas) (d (pressure) / dT) at constant rho - // - // Note for ideal gases this is equal to one. - // - // beta = delta (phi0_d() + phiR_d()) - // - tau delta (phi0_dt() + phiR_dt()) - doublereal beta = m_waterIAPWS->coeffPresExp(); - doublereal dpdT_const_rho = beta * GasConstant * dens / 18.015268; - dpdT_const_rho *= Tstar / presstar; - doublereal lambda2bar = 0.0013848 / (mu0bar * mu1bar) * t2r2 * dpdT_const_rho * dpdT_const_rho * - xsipow * sqrt(rhobar) * exp(-18.66*temp2 - rho4); - return (lambda0bar * lambda1bar + lambda2bar) * lambdastar; -} - } diff --git a/src/transport/WaterTransport.cpp b/src/transport/WaterTransport.cpp index 3919373fbd..6e4f283a0d 100644 --- a/src/transport/WaterTransport.cpp +++ b/src/transport/WaterTransport.cpp @@ -10,6 +10,25 @@ using namespace std; +namespace { + +const double Tstar = 647.27; +const double rhoStar = 317.763; // kg / m3 +const double presStar = 22.115E6; // Pa +const double muStar = 55.071E-6; //Pa s + +const double H[4] = {1., 0.978197, 0.579829, -0.202354}; +const double Hij[6][7] = { + { 0.5132047, 0.2151778, -0.2818107, 0.1778064, -0.04176610, 0., 0.}, + { 0.3205656, 0.7317883, -1.070786 , 0.4605040, 0., -0.01578386, 0.}, + { 0., 1.241044 , -1.263184 , 0.2340379, 0., 0., 0.}, + { 0., 1.476783 , 0., -0.4924179, 0.1600435, 0., -0.003629481}, + {-0.7782567, 0.0 , 0., 0. , 0., 0., 0.}, + { 0.1885447, 0.0 , 0., 0. , 0., 0., 0.}, +}; + +} + namespace Cantera { @@ -53,14 +72,122 @@ void WaterTransport::init(thermo_t* thermo, int mode, int log_level) } } -doublereal WaterTransport::viscosity() +double WaterTransport::viscosity() { - return m_waterProps->viscosityWater(); + static const double TStar = 647.27; // Kelvin + double temp = m_thermo->temperature(); + double dens = m_thermo->density(); + + double rhobar = dens/rhoStar; + double tbar = temp / TStar; + double tbar2 = tbar * tbar; + double tbar3 = tbar2 * tbar; + double mu0bar = std::sqrt(tbar) / (H[0] + H[1]/tbar + H[2]/tbar2 + H[3]/tbar3); + + double tfac1 = 1.0 / tbar - 1.0; + double tfac2 = tfac1 * tfac1; + double tfac3 = tfac2 * tfac1; + double tfac4 = tfac3 * tfac1; + double tfac5 = tfac4 * tfac1; + + double rfac1 = rhobar - 1.0; + double rfac2 = rfac1 * rfac1; + double rfac3 = rfac2 * rfac1; + double rfac4 = rfac3 * rfac1; + double rfac5 = rfac4 * rfac1; + double rfac6 = rfac5 * rfac1; + + double sum = Hij[0][0] + Hij[1][0]*tfac1 + Hij[4][0]*tfac4 + Hij[5][0]*tfac5 + + Hij[0][1]*rfac1 + Hij[1][1]*tfac1*rfac1 + Hij[2][1]*tfac2*rfac1 + Hij[3][1]*tfac3*rfac1 + + Hij[0][2]*rfac2 + Hij[1][2]*tfac1*rfac2 + Hij[2][2]*tfac2*rfac2 + + Hij[0][3]*rfac3 + Hij[1][3]*tfac1*rfac3 + Hij[2][3]*tfac2*rfac3 + Hij[3][3]*tfac3*rfac3 + + Hij[0][4]*rfac4 + Hij[3][4]*tfac3*rfac4 + + Hij[1][5]*tfac1*rfac5 + Hij[3][6]*tfac3*rfac6; + double mu1bar = std::exp(rhobar * sum); + + // Apply the near-critical point corrections if necessary + double mu2bar = 1.0; + if (tbar >= 0.9970 && tbar <= 1.0082 && rhobar >= 0.755 && rhobar <= 1.290) { + double drhodp = m_thermo->isothermalCompressibility() * dens; + drhodp *= presStar / rhoStar; + double xsi = rhobar * drhodp; + if (xsi >= 21.93) { + mu2bar = 0.922 * std::pow(xsi, 0.0263); + } + } + + double mubar = mu0bar * mu1bar * mu2bar; + return mubar * muStar; } -doublereal WaterTransport::thermalConductivity() +double WaterTransport::thermalConductivity() { - return m_waterProps->thermalConductivityWater(); + static const double lambdastar = 0.4945; + static const double L[4] = { + 1.0000, + 6.978267, + 2.599096, + -0.998254 + }; + static const double Lji[6][5] = { + { 1.3293046, 1.7018363, 5.2246158, 8.7127675, -1.8525999}, + {-0.40452437, -2.2156845, -10.124111, -9.5000611, 0.93404690}, + { 0.24409490, 1.6511057, 4.9874687, 4.3786606, 0.0}, + { 0.018660751, -0.76736002, -0.27297694, -0.91783782, 0.0}, + {-0.12961068, 0.37283344, -0.43083393, 0.0, 0.0}, + { 0.044809953, -0.11203160, 0.13333849, 0.0, 0.0}, + }; + + double temp = m_thermo->temperature(); + double dens = m_thermo->density(); + + double rhobar = dens / rhoStar; + double tbar = temp / Tstar; + double tbar2 = tbar * tbar; + double tbar3 = tbar2 * tbar; + double lambda0bar = sqrt(tbar) / (L[0] + L[1]/tbar + L[2]/tbar2 + L[3]/tbar3); + + double tfac1 = 1.0 / tbar - 1.0; + double tfac2 = tfac1 * tfac1; + double tfac3 = tfac2 * tfac1; + double tfac4 = tfac3 * tfac1; + double tfac5 = tfac4 * tfac1; + + double rfac1 = rhobar - 1.0; + double rfac2 = rfac1 * rfac1; + double rfac3 = rfac2 * rfac1; + double rfac4 = rfac3 * rfac1; + double rfac5 = rfac4 * rfac1; + double rfac6 = rfac5 * rfac1; + + double sum = (Lji[0][0] + Lji[0][1]*tfac1 + Lji[0][2]*tfac2 + Lji[0][3]*tfac3 + Lji[0][4]*tfac4 + + Lji[1][0]*rfac1 + Lji[1][1]*tfac1*rfac1 + Lji[1][2]*tfac2*rfac1 + Lji[1][3]*tfac3*rfac1 + Lji[1][4]*tfac4*rfac1 + + Lji[2][0]*rfac2 + Lji[2][1]*tfac1*rfac2 + Lji[2][2]*tfac2*rfac2 + Lji[2][3]*tfac3*rfac2 + + Lji[3][0]*rfac3 + Lji[3][1]*tfac1*rfac3 + Lji[3][2]*tfac2*rfac3 + Lji[3][3]*tfac3*rfac3 + + Lji[4][0]*rfac4 + Lji[4][1]*tfac1*rfac4 + Lji[4][2]*tfac2*rfac4 + + Lji[5][0]*rfac5 + Lji[5][1]*tfac1*rfac5 + Lji[5][2]*tfac2*rfac5 + ); + double lambda1bar = exp(rhobar * sum); + double mu0bar = std::sqrt(tbar) / (H[0] + H[1]/tbar + H[2]/tbar2 + H[3]/tbar3); + + sum = (Hij[0][0] + Hij[1][0]*tfac1 + Hij[4][0]*tfac4 + Hij[5][0]*tfac5 + + Hij[0][1]*rfac1 + Hij[1][1]*tfac1*rfac1 + Hij[2][1]*tfac2*rfac1 + Hij[3][1]*tfac3*rfac1 + + Hij[0][2]*rfac2 + Hij[1][2]*tfac1*rfac2 + Hij[2][2]*tfac2*rfac2 + + Hij[0][3]*rfac3 + Hij[1][3]*tfac1*rfac3 + Hij[2][3]*tfac2*rfac3 + Hij[3][3]*tfac3*rfac3 + + Hij[0][4]*rfac4 + Hij[3][4]*tfac3*rfac4 + + Hij[1][5]*tfac1*rfac5 + Hij[3][6]*tfac3*rfac6 + ); + double mu1bar = std::exp(rhobar * sum); + double t2r2 = tbar2 / (rhobar * rhobar); + double kappa = m_thermo->isothermalCompressibility(); + double xsi = rhobar * rhobar * kappa * presStar; + double xsipow = std::pow(xsi, 0.4678); + double temp2 = (tbar - 1.0) * (tbar - 1.0); + double dpdT_const_rho = m_thermo->thermalExpansionCoeff() / kappa; + dpdT_const_rho *= Tstar / presStar; + double lambda2bar = 0.0013848 / (mu0bar * mu1bar) * t2r2 * dpdT_const_rho * dpdT_const_rho * + xsipow * sqrt(rhobar) * exp(-18.66*temp2 - rfac4); + return (lambda0bar * lambda1bar + lambda2bar) * lambdastar; } } From 4d06adbd8aa3c801726b9d49a8e2e4a6bfa3a96a Mon Sep 17 00:00:00 2001 From: Ray Speth Date: Thu, 30 Aug 2018 10:30:32 -0400 Subject: [PATCH 6/7] [Transport] Relax requirements of thermo model for WaterTransport The ThermoPhase object used by the WaterTransport model can be any reasonably-accurate equation of state for water. --- src/transport/WaterTransport.cpp | 27 --------------------------- 1 file changed, 27 deletions(-) diff --git a/src/transport/WaterTransport.cpp b/src/transport/WaterTransport.cpp index 6e4f283a0d..04363ec555 100644 --- a/src/transport/WaterTransport.cpp +++ b/src/transport/WaterTransport.cpp @@ -43,33 +43,6 @@ WaterTransport::WaterTransport(thermo_t* thermo, int ndim) : void WaterTransport::init(thermo_t* thermo, int mode, int log_level) { m_thermo = thermo; - // The expectation is that we have a VPStandardStateTP derived object - VPStandardStateTP* vpthermo = dynamic_cast(m_thermo); - if (!vpthermo) { - WaterSSTP* wsstp = dynamic_cast(m_thermo); - if (!wsstp) { - throw CanteraError("WaterTransport::initTP()", - "Expectation is that ThermoPhase be a VPStandardStateTP"); - } else { - m_sub = wsstp->getWater(); - AssertTrace(m_sub != 0); - // Get a pointer to a changeable WaterProps object - m_waterProps = wsstp->getWaterProps(); - AssertTrace(m_waterProps != 0); - } - } else { - m_waterPDSS = dynamic_cast(vpthermo->providePDSS(0)); - if (!m_waterPDSS) { - throw CanteraError("WaterTransport::initTP()", - "Expectation is that first species be water with a PDSS_Water object"); - } - // Get a pointer to a changeable WaterPropsIAPWS object - m_sub = m_waterPDSS->getWater(); - AssertTrace(m_sub != 0); - // Get a pointer to a changeable WaterProps object - m_waterProps = m_waterPDSS->getWaterProps(); - AssertTrace(m_waterProps != 0); - } } double WaterTransport::viscosity() From 97b0b2bd3a35cac6a542fdd960142b94c6d44312 Mon Sep 17 00:00:00 2001 From: Ray Speth Date: Thu, 30 Aug 2018 10:32:12 -0400 Subject: [PATCH 7/7] [Python] Make transport properties accessible with the Water() function --- interfaces/cython/cantera/liquidvapor.py | 14 +++-- .../cython/cantera/test/test_transport.py | 53 +++++++++++++++++++ 2 files changed, 64 insertions(+), 3 deletions(-) diff --git a/interfaces/cython/cantera/liquidvapor.py b/interfaces/cython/cantera/liquidvapor.py index 544947c7bb..96021ae683 100644 --- a/interfaces/cython/cantera/liquidvapor.py +++ b/interfaces/cython/cantera/liquidvapor.py @@ -1,11 +1,19 @@ # This file is part of Cantera. See License.txt in the top-level directory or # at http://www.cantera.org/license.txt for license and copyright information. -from . import PureFluid +from . import PureFluid, _cantera + + def Water(): - """Create a `PureFluid` object using the equation of state for water.""" - return PureFluid('liquidvapor.xml','water') + """ + Create a `PureFluid` object using the equation of state for water and the + `WaterTransport` class for viscosity and thermal conductivity.""" + class WaterWithTransport(PureFluid, _cantera.Transport): + __slots__ = () + + + return WaterWithTransport('liquidvapor.xml', 'water', transport_model='Water') def Nitrogen(): """Create a `PureFluid` object using the equation of state for nitrogen.""" diff --git a/interfaces/cython/cantera/test/test_transport.py b/interfaces/cython/cantera/test/test_transport.py index 73614ce43f..207279b02c 100644 --- a/interfaces/cython/cantera/test/test_transport.py +++ b/interfaces/cython/cantera/test/test_transport.py @@ -268,6 +268,59 @@ def test_molar_fluxes(self): # self.assertNear(sum(fluxes1) / sum(abs(fluxes1)), 0.0) +class TestWaterTransport(utilities.CanteraTest): + """ + Comparison values are taken from the NIST Chemistry WebBook. Agreement is + limited by the use of a different equation of state here (Reynolds) than + in the Webbook (IAPWS95), as well as a different set of coefficients for + the transport property model. Differences are largest in the region near + the critical point. + """ + @classmethod + def setUpClass(cls): + cls.water = ct.Water() + + def check_viscosity(self, T, P, mu, rtol): + self.water.TP = T, P + self.assertNear(self.water.viscosity, mu, rtol) + + def check_thermal_conductivity(self, T, P, k, rtol): + self.water.TP = T, P + self.assertNear(self.water.thermal_conductivity, k, rtol) + + def test_viscosity_liquid(self): + self.check_viscosity(400, 1e6, 2.1880e-4, 1e-3) + self.check_viscosity(400, 8e6, 2.2061e-4, 1e-3) + self.check_viscosity(620, 1.6e7, 6.7489e-5, 2e-3) + self.check_viscosity(620, 2.8e7, 7.5684e-5, 2e-3) + + def test_thermal_conductivity_liquid(self): + self.check_thermal_conductivity(400, 1e6, 0.68410, 1e-3) + self.check_thermal_conductivity(400, 8e6, 0.68836, 1e-3) + self.check_thermal_conductivity(620, 1.6e7, 0.45458, 2e-3) + self.check_thermal_conductivity(620, 2.8e7, 0.49705, 2e-3) + + def test_viscosity_vapor(self): + self.check_viscosity(600, 1e6, 2.1329e-5, 1e-3) + self.check_viscosity(620, 5e6, 2.1983e-5, 1e-3) + self.check_viscosity(620, 1.5e7, 2.2858e-5, 2e-3) + + def test_thermal_conductivity_vapor(self): + self.check_thermal_conductivity(600, 1e6, 0.047636, 1e-3) + self.check_thermal_conductivity(620, 5e6, 0.055781, 1e-3) + self.check_thermal_conductivity(620, 1.5e7, 0.10524, 2e-3) + + def test_viscosity_supercritical(self): + self.check_viscosity(660, 2.2e7, 2.7129e-5, 2e-3) + self.check_viscosity(660, 2.54e7, 3.8212e-5, 1e-2) + self.check_viscosity(660, 2.8e7, 5.3159e-5, 1e-2) + + def test_thermal_conductivity_supercritical(self): + self.check_thermal_conductivity(660, 2.2e7, 0.14872, 1e-2) + self.check_thermal_conductivity(660, 2.54e7, 0.35484, 2e-2) + self.check_thermal_conductivity(660, 2.8e7, 0.38479, 1e-2) + + class TestTransportData(utilities.CanteraTest): @classmethod def setUpClass(cls):