From 0756ede089c9c798dc901c4fef7a469379ec208d Mon Sep 17 00:00:00 2001 From: Harry Moffat Date: Tue, 9 Feb 2010 01:34:54 +0000 Subject: [PATCH 01/26] Added in code to automatically add -lm and -lstdc++ to the link line when they are present on the system. --- configure | 172 +++++++++++++++++++++++++++++++++++++++++++++++++-- configure.in | 28 ++++++++- 2 files changed, 191 insertions(+), 9 deletions(-) diff --git a/configure b/configure index b40bf7bcd..5f3a58df0 100755 --- a/configure +++ b/configure @@ -1738,9 +1738,7 @@ fi #---------------------------------------- - - -######################################################### +######################################################## # User Code ######################################################### USERDIR="" @@ -9740,11 +9738,161 @@ if test "$BUILD_WITH_F2C"="n"; then fi + # # Ending Libs for compiling static applications and # dynamically loaded libraries # (sunpro solaris needs a few for dynamic linking) # +# +# Check to see if we have a -lm line +# +echo "$as_me:$LINENO: checking for printf in -lm" >&5 +echo $ECHO_N "checking for printf in -lm... $ECHO_C" >&6 +if test "${ac_cv_lib_m_printf+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + ac_check_lib_save_LIBS=$LIBS +LIBS="-lm $LIBS" +cat >conftest.$ac_ext <<_ACEOF +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ + +/* Override any gcc2 internal prototype to avoid an error. */ +#ifdef __cplusplus +extern "C" +#endif +/* We use char because int might match the return type of a gcc2 + builtin and then its argument prototype would still apply. */ +char printf (); +int +main () +{ +printf (); + ; + return 0; +} +_ACEOF +rm -f conftest.$ac_objext conftest$ac_exeext +if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5 + (eval $ac_link) 2>conftest.er1 + ac_status=$? + grep -v '^ *+' conftest.er1 >conftest.err + rm -f conftest.er1 + cat conftest.err >&5 + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && + { ac_try='test -z "$ac_cxx_werror_flag" + || test ! -s conftest.err' + { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 + (eval $ac_try) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; } && + { ac_try='test -s conftest$ac_exeext' + { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 + (eval $ac_try) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; }; then + ac_cv_lib_m_printf=yes +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + +ac_cv_lib_m_printf=no +fi +rm -f conftest.err conftest.$ac_objext \ + conftest$ac_exeext conftest.$ac_ext +LIBS=$ac_check_lib_save_LIBS +fi +echo "$as_me:$LINENO: result: $ac_cv_lib_m_printf" >&5 +echo "${ECHO_T}$ac_cv_lib_m_printf" >&6 +if test $ac_cv_lib_m_printf = yes; then + add_stm=1 +else + add_stm=0 +fi + + +# +# Check to see if we have a -lstdc++ line +# +echo "$as_me:$LINENO: checking for printf in -lstdc++" >&5 +echo $ECHO_N "checking for printf in -lstdc++... $ECHO_C" >&6 +if test "${ac_cv_lib_stdcpp_printf+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + ac_check_lib_save_LIBS=$LIBS +LIBS="-lstdc++ $LIBS" +cat >conftest.$ac_ext <<_ACEOF +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ + +/* Override any gcc2 internal prototype to avoid an error. */ +#ifdef __cplusplus +extern "C" +#endif +/* We use char because int might match the return type of a gcc2 + builtin and then its argument prototype would still apply. */ +char printf (); +int +main () +{ +printf (); + ; + return 0; +} +_ACEOF +rm -f conftest.$ac_objext conftest$ac_exeext +if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5 + (eval $ac_link) 2>conftest.er1 + ac_status=$? + grep -v '^ *+' conftest.er1 >conftest.err + rm -f conftest.er1 + cat conftest.err >&5 + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && + { ac_try='test -z "$ac_cxx_werror_flag" + || test ! -s conftest.err' + { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 + (eval $ac_try) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; } && + { ac_try='test -s conftest$ac_exeext' + { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 + (eval $ac_try) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; }; then + ac_cv_lib_stdcpp_printf=yes +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + +ac_cv_lib_stdcpp_printf=no +fi +rm -f conftest.err conftest.$ac_objext \ + conftest$ac_exeext conftest.$ac_ext +LIBS=$ac_check_lib_save_LIBS +fi +echo "$as_me:$LINENO: result: $ac_cv_lib_stdcpp_printf" >&5 +echo "${ECHO_T}$ac_cv_lib_stdcpp_printf" >&6 +if test $ac_cv_lib_stdcpp_printf = yes; then + add_stdc=1 +else + add_stdc=0 +fi + + + if test -n "$NEED_F2C" ; then LCXX_END_LIBS="-lctf2c ""$LCXX_END_LIBS" fi @@ -9755,6 +9903,18 @@ case $ac_sys_system in LCXX_END_LIBS="$LCXX_END_LIBS"" -lCrun -lCstd -lfsu" ;; esac ;; esac +if test $add_stm = 1 ; then + echo 'Adding -lm to the end of the LCXX_END_LIBS variable' + LCXX_END_LIBS="$LCXX_END_LIBS"" -lm" + echo 'LCXX_END_LIBS = ' $LCXX_END_LIBS +fi +if test $add_stdc = 1 ; then + echo 'Adding -lstdc++ to the end of the LCXX_END_LIBS variable' + LCXX_END_LIBS="$LCXX_END_LIBS"" -lstdc++ " + echo 'LCXX_END_LIBS = ' $LCXX_END_LIBS +fi + + @@ -9888,7 +10048,7 @@ fi # Provide some information about the compiler. -echo "$as_me:9891:" \ +echo "$as_me:10051:" \ "checking for Fortran 77 compiler version" >&5 ac_compiler=`set X $ac_compile; echo $2` { (eval echo "$as_me:$LINENO: \"$ac_compiler --version &5\"") >&5 @@ -10095,7 +10255,7 @@ _ACEOF # flags. ac_save_FFLAGS=$FFLAGS FFLAGS="$FFLAGS $ac_verb" -(eval echo $as_me:10098: \"$ac_link\") >&5 +(eval echo $as_me:10258: \"$ac_link\") >&5 ac_f77_v_output=`eval $ac_link 5>&1 2>&1 | grep -v 'Driving:'` echo "$ac_f77_v_output" >&5 FFLAGS=$ac_save_FFLAGS @@ -10173,7 +10333,7 @@ _ACEOF # flags. ac_save_FFLAGS=$FFLAGS FFLAGS="$FFLAGS $ac_cv_prog_f77_v" -(eval echo $as_me:10176: \"$ac_link\") >&5 +(eval echo $as_me:10336: \"$ac_link\") >&5 ac_f77_v_output=`eval $ac_link 5>&1 2>&1 | grep -v 'Driving:'` echo "$ac_f77_v_output" >&5 FFLAGS=$ac_save_FFLAGS diff --git a/configure.in b/configure.in index 77744b3e7..8631f8b89 100755 --- a/configure.in +++ b/configure.in @@ -306,9 +306,7 @@ AC_SUBST(CXX_DEPENDS) #---------------------------------------- - - -######################################################### +######################################################## # User Code ######################################################### USERDIR="" @@ -1463,11 +1461,23 @@ if test "$BUILD_WITH_F2C"="n"; then fi AC_SUBST(LCXX_FLAGS) + # # Ending Libs for compiling static applications and # dynamically loaded libraries # (sunpro solaris needs a few for dynamic linking) # +# +# Check to see if we have a -lm line +# +AC_CHECK_LIB(m, printf, [add_stm=1], [add_stm=0], [ ]) + +# +# Check to see if we have a -lstdc++ line +# +AC_CHECK_LIB(stdc++, printf, [add_stdc=1], [add_stdc=0], []) + + if test -n "$NEED_F2C" ; then LCXX_END_LIBS="-lctf2c ""$LCXX_END_LIBS" fi @@ -1478,6 +1488,18 @@ case $ac_sys_system in LCXX_END_LIBS="$LCXX_END_LIBS"" -lCrun -lCstd -lfsu" ;; esac ;; esac +if test $add_stm = 1 ; then + echo 'Adding -lm to the end of the LCXX_END_LIBS variable' + LCXX_END_LIBS="$LCXX_END_LIBS"" -lm" + echo 'LCXX_END_LIBS = ' $LCXX_END_LIBS +fi +if test $add_stdc = 1 ; then + echo 'Adding -lstdc++ to the end of the LCXX_END_LIBS variable' + LCXX_END_LIBS="$LCXX_END_LIBS"" -lstdc++ " + echo 'LCXX_END_LIBS = ' $LCXX_END_LIBS +fi + + AC_SUBST(LCXX_END_LIBS) From 9023c30cd8b71957f30b32bd6746bc18ec75dc25 Mon Sep 17 00:00:00 2001 From: Harry Moffat Date: Tue, 9 Feb 2010 19:44:37 +0000 Subject: [PATCH 02/26] took out an unused command from the clean rule. --- test_problems/cxx_ex/Makefile.in | 1 - 1 file changed, 1 deletion(-) diff --git a/test_problems/cxx_ex/Makefile.in b/test_problems/cxx_ex/Makefile.in index d8a9a77be..3461c63ce 100644 --- a/test_problems/cxx_ex/Makefile.in +++ b/test_problems/cxx_ex/Makefile.in @@ -11,7 +11,6 @@ test: clean: (cd ../../examples/cxx ; @MAKE@ clean ) - ../../bin/rm_cvsignore depends: From 4b349de72b5f2c18a2a9d74f3739d4adbb5af4d7 Mon Sep 17 00:00:00 2001 From: Harry Moffat Date: Tue, 9 Feb 2010 19:49:20 +0000 Subject: [PATCH 03/26] Added more ignore files. From e2fb5d3483a8096ba5b4722eaeca3c196a2022bc Mon Sep 17 00:00:00 2001 From: Harry Moffat Date: Tue, 9 Feb 2010 19:57:02 +0000 Subject: [PATCH 04/26] Fixed compilation errors on solaris. --- Cantera/src/base/checkFinite.cpp | 2 ++ Cantera/src/base/misc.cpp | 26 ++++++++++++++++---------- 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/Cantera/src/base/checkFinite.cpp b/Cantera/src/base/checkFinite.cpp index b20096b99..be4fa224d 100644 --- a/Cantera/src/base/checkFinite.cpp +++ b/Cantera/src/base/checkFinite.cpp @@ -14,6 +14,8 @@ * See file License.txt for licensing information. */ +#include "ct_defs.h" + #include #include diff --git a/Cantera/src/base/misc.cpp b/Cantera/src/base/misc.cpp index b8893514e..9d39cfc12 100644 --- a/Cantera/src/base/misc.cpp +++ b/Cantera/src/base/misc.cpp @@ -1423,28 +1423,34 @@ protected: doublereal toSI(std::string unit) { doublereal f = Unit::units()->toSI(unit); - if (f) return f; - else throw CanteraError("toSI","unknown unit string: "+unit); - //return 1.0; + if (f) { + return f; + } else { + throw CanteraError("toSI","unknown unit string: "+unit); + } + return 1.0; } doublereal actEnergyToSI(std::string unit) { doublereal f = Unit::units()->actEnergyToSI(unit); - if (f) return f; - else return 1.0; + if (f) { + return f; + } + return 1.0; } string canteraRoot() { char* ctroot = 0; ctroot = getenv("CANTERA_ROOT"); - if (ctroot != 0) { return string(ctroot); } - else { + if (ctroot != 0) { + return string(ctroot); + } #ifdef CANTERA_ROOT - return string(CANTERA_ROOT); + return string(CANTERA_ROOT); #else - return ""; + return ""; #endif - } + } // exceptions From a5ea91b56a36e7c4558b093bcb7557a2f0ae5f81 Mon Sep 17 00:00:00 2001 From: Harry Moffat Date: Tue, 9 Feb 2010 20:24:11 +0000 Subject: [PATCH 05/26] Changes due to compilation problems on solaris --- Cantera/src/equil/ChemEquil.cpp | 5 ++- Cantera/src/equil/equilibrate.cpp | 6 +-- Cantera/src/kinetics/Kinetics.cpp | 5 ++- Cantera/src/numerics/ODE_integrators.cpp | 1 + Cantera/src/oneD/Domain1D.cpp | 3 +- Cantera/src/oneD/OneDim.cpp | 1 + Cantera/src/oneD/boundaries1D.cpp | 45 +++++++++++++++------- Cantera/src/thermo/Elements.cpp | 6 +-- Cantera/src/thermo/HMWSoln.cpp | 2 +- Cantera/src/thermo/IdealSolidSolnPhase.cpp | 6 --- Cantera/src/thermo/State.cpp | 13 +++---- Cantera/src/thermo/VPSSMgrFactory.cpp | 5 --- Cantera/src/thermo/WaterPropsIAPWS.cpp | 2 +- Cantera/src/zeroD/ReactorFactory.cpp | 1 + 14 files changed, 57 insertions(+), 44 deletions(-) diff --git a/Cantera/src/equil/ChemEquil.cpp b/Cantera/src/equil/ChemEquil.cpp index d78714575..f1af6a8a5 100755 --- a/Cantera/src/equil/ChemEquil.cpp +++ b/Cantera/src/equil/ChemEquil.cpp @@ -59,7 +59,10 @@ namespace Cantera { else if (flag == "SP") return SP; else if (flag == "SV") return SV; else if (flag == "UP") return UP; - else throw CanteraError("_equilflag","unknown property pair "+flag); + else { + throw CanteraError("_equilflag","unknown property pair "+flag); + } + return -1; } diff --git a/Cantera/src/equil/equilibrate.cpp b/Cantera/src/equil/equilibrate.cpp index 548df4f68..2efdb336f 100644 --- a/Cantera/src/equil/equilibrate.cpp +++ b/Cantera/src/equil/equilibrate.cpp @@ -27,7 +27,7 @@ namespace Cantera { doublereal equilibrate(MultiPhase& s, const char* XY, doublereal tol, int maxsteps, int maxiter, int loglevel) { - + if (loglevel > 0) { beginLogGroup("equilibrate",loglevel); addLogEntry("multiphase equilibrate function"); @@ -65,9 +65,9 @@ namespace Cantera { endLogGroup("equilibrate"); } throw CanteraError("equilibrate","unsupported option"); - //return -1.0; + return -1.0; } - + return 0.0; } /* diff --git a/Cantera/src/kinetics/Kinetics.cpp b/Cantera/src/kinetics/Kinetics.cpp index 38ea75fe0..7ab58f4f8 100644 --- a/Cantera/src/kinetics/Kinetics.cpp +++ b/Cantera/src/kinetics/Kinetics.cpp @@ -213,6 +213,7 @@ namespace Cantera { if (k >= 0) return thermo(n); } throw CanteraError("speciesPhase", "unknown species "+nm); + return thermo(0); } /** @@ -228,8 +229,8 @@ namespace Cantera { return n; } } - throw CanteraError("speciesPhaseIndex", - "illegal species index: "+int2str(k)); + throw CanteraError("speciesPhaseIndex", "illegal species index: "+int2str(k)); + return -1; } /* diff --git a/Cantera/src/numerics/ODE_integrators.cpp b/Cantera/src/numerics/ODE_integrators.cpp index e0c613b09..6f344530a 100644 --- a/Cantera/src/numerics/ODE_integrators.cpp +++ b/Cantera/src/numerics/ODE_integrators.cpp @@ -22,6 +22,7 @@ namespace Cantera { throw CanteraError("newIntegrator", "unknown ODE integrator: "+itype); } + return 0; } void deleteIntegrator(Integrator *cv) { diff --git a/Cantera/src/oneD/Domain1D.cpp b/Cantera/src/oneD/Domain1D.cpp index f9f19d92f..c0c87ef96 100644 --- a/Cantera/src/oneD/Domain1D.cpp +++ b/Cantera/src/oneD/Domain1D.cpp @@ -190,7 +190,8 @@ namespace Cantera { doublereal Domain1D::initialValue(int n, int j) { throw CanteraError("Domain1D::initialValue", - "base class method called!"); + "base class method called!"); + return 0.0; } diff --git a/Cantera/src/oneD/OneDim.cpp b/Cantera/src/oneD/OneDim.cpp index eabebdf28..a54602ce2 100644 --- a/Cantera/src/oneD/OneDim.cpp +++ b/Cantera/src/oneD/OneDim.cpp @@ -64,6 +64,7 @@ namespace Cantera { if (domain(n).id() == name) return n; } throw CanteraError("OneDim::domainIndex","no domain named >>"+name+"<<"); + return -1; } diff --git a/Cantera/src/oneD/boundaries1D.cpp b/Cantera/src/oneD/boundaries1D.cpp index 164047238..67bc98e75 100644 --- a/Cantera/src/oneD/boundaries1D.cpp +++ b/Cantera/src/oneD/boundaries1D.cpp @@ -117,10 +117,14 @@ namespace Cantera { string Inlet1D:: componentName(int n) const { switch (n) { - case 0: return "mdot"; break; - case 1: return "temperature"; break; - default: return "unknown"; + case 0: + return "mdot"; + case 1: + return "temperature"; + default: + break; } + return "unknown"; } void Inlet1D:: @@ -271,9 +275,12 @@ namespace Cantera { string Empty1D::componentName(int n) const { switch (n) { - case 0: return "dummy"; break; - default: return ""; + case 0: + return "dummy"; + default: + break; } + return ""; } void Empty1D:: @@ -326,9 +333,12 @@ namespace Cantera { string Symm1D::componentName(int n) const { switch (n) { - case 0: return "dummy"; break; - default: return ""; + case 0: + return "dummy"; + default: + break; } + return ""; } void Symm1D:: @@ -405,9 +415,12 @@ namespace Cantera { string Outlet1D::componentName(int n) const { switch (n) { - case 0: return "outlet dummy"; break; - default: return ""; + case 0: + return "outlet dummy"; + default: + break; } + return ""; } void Outlet1D:: @@ -522,9 +535,12 @@ namespace Cantera { string OutletRes1D::componentName(int n) const { switch (n) { - case 0: return "dummy"; break; - default: return ""; + case 0: + return "dummy"; + default: + break; } + return ""; } void OutletRes1D:: @@ -641,9 +657,12 @@ namespace Cantera { string Surf1D::componentName(int n) const { switch (n) { - case 0: return "temperature"; break; - default: return ""; + case 0: + return "temperature"; + default: + break; } + return ""; } void Surf1D:: diff --git a/Cantera/src/thermo/Elements.cpp b/Cantera/src/thermo/Elements.cpp index 5e5943361..1cd563d8e 100644 --- a/Cantera/src/thermo/Elements.cpp +++ b/Cantera/src/thermo/Elements.cpp @@ -321,10 +321,10 @@ namespace Cantera { * index. If m < 0 or m >= nElements() an exception is thrown. */ string Elements::elementName(int m) const { - if (m >= 0 && m < nElements()) - return m_elementNames[m]; - else + if (m < 0 || m >= nElements()) { throw ElementRangeError("Elements::elementName", m, nElements()); + } + return m_elementNames[m]; } diff --git a/Cantera/src/thermo/HMWSoln.cpp b/Cantera/src/thermo/HMWSoln.cpp index a250de5f0..5147b705d 100644 --- a/Cantera/src/thermo/HMWSoln.cpp +++ b/Cantera/src/thermo/HMWSoln.cpp @@ -792,7 +792,7 @@ namespace Cantera { doublereal HMWSoln::isothermalCompressibility() const { throw CanteraError("HMWSoln::isothermalCompressibility", "unimplemented"); - //return 0.0; + return 0.0; } /* diff --git a/Cantera/src/thermo/IdealSolidSolnPhase.cpp b/Cantera/src/thermo/IdealSolidSolnPhase.cpp index b8ba0af30..08fcbd784 100644 --- a/Cantera/src/thermo/IdealSolidSolnPhase.cpp +++ b/Cantera/src/thermo/IdealSolidSolnPhase.cpp @@ -494,13 +494,10 @@ namespace Cantera { switch (m_formGC) { case 0: return 1.0; - break; case 1: return 1.0 / m_speciesMolarVolume[k]; - break; case 2: return 1.0/m_speciesMolarVolume[m_kk-1]; - break; } return 0.0; } @@ -509,13 +506,10 @@ namespace Cantera { switch (m_formGC) { case 0: return 1.0; - break; case 1: return 1.0 / m_speciesMolarVolume[k]; - break; case 2: return 1.0 / m_speciesMolarVolume[m_kk-1]; - break; } return 0.0; } diff --git a/Cantera/src/thermo/State.cpp b/Cantera/src/thermo/State.cpp index 6191ce6bd..6eeec8ce8 100644 --- a/Cantera/src/thermo/State.cpp +++ b/Cantera/src/thermo/State.cpp @@ -96,6 +96,7 @@ namespace Cantera { throw CanteraError("State:moleFraction", "illegal species index number"); } + return 0.0; } void State::setMoleFractions(const doublereal* const x) { @@ -126,20 +127,16 @@ namespace Cantera { if (k >= 0 && k < m_kk) { return m_y[k]; } - else { - throw CanteraError("State:massFraction", - "illegal species index number"); - } + throw CanteraError("State:massFraction", "illegal species index number"); + return 0.0; } doublereal State::concentration(const int k) const { if (k >= 0 && k < m_kk) { return m_y[k] * m_dens * m_rmolwts[k] ; } - else { - throw CanteraError("State:massFraction", - "illegal species index number"); - } + throw CanteraError("State:massFraction", "illegal species index number"); + return 0.0; } void State::setMassFractions(const doublereal* const y) { diff --git a/Cantera/src/thermo/VPSSMgrFactory.cpp b/Cantera/src/thermo/VPSSMgrFactory.cpp index 6e3962fb6..f8f1f17b2 100644 --- a/Cantera/src/thermo/VPSSMgrFactory.cpp +++ b/Cantera/src/thermo/VPSSMgrFactory.cpp @@ -351,22 +351,17 @@ namespace Cantera { switch (type) { case cVPSSMGR_IDEALGAS: return new VPSSMgr_IdealGas(vp_ptr, &spthermoRef); - break; case cVPSSMGR_CONSTVOL: return new VPSSMgr_ConstVol(vp_ptr, &spthermoRef); - break; case cVPSSMGR_PUREFLUID: throw CanteraError("VPSSMgrFactory::newVPSSMgr", "unimplemented"); case cVPSSMGR_WATER_CONSTVOL: return new VPSSMgr_Water_ConstVol(vp_ptr, &spthermoRef); - break; case cVPSSMGR_WATER_HKFT: return new VPSSMgr_Water_HKFT(vp_ptr, &spthermoRef); - break; case cVPSSMGR_GENERAL: return new VPSSMgr_General(vp_ptr, &spthermoRef); - break; case cVPSSMGR_UNDEF: default: throw UnknownVPSSMgrModel("VPSSMgrFactory::newVPSSMgr", int2str(type)); diff --git a/Cantera/src/thermo/WaterPropsIAPWS.cpp b/Cantera/src/thermo/WaterPropsIAPWS.cpp index 0a7a83f9c..1fd721c83 100644 --- a/Cantera/src/thermo/WaterPropsIAPWS.cpp +++ b/Cantera/src/thermo/WaterPropsIAPWS.cpp @@ -875,4 +875,4 @@ doublereal WaterPropsIAPWS::molarVolume() const { return (M_water / rho); } -}; +} diff --git a/Cantera/src/zeroD/ReactorFactory.cpp b/Cantera/src/zeroD/ReactorFactory.cpp index ee07a21f3..3a07c12fa 100644 --- a/Cantera/src/zeroD/ReactorFactory.cpp +++ b/Cantera/src/zeroD/ReactorFactory.cpp @@ -67,6 +67,7 @@ namespace CanteraZeroD { throw CanteraError("ReactorFactory::newReactor", "unknown reactor type!"); } + return 0; } } From 039696dcc602b28dd964e2b2305d409cb1995aa4 Mon Sep 17 00:00:00 2001 From: Harry Moffat Date: Tue, 9 Feb 2010 20:39:03 +0000 Subject: [PATCH 06/26] More changes for solaris compile --- Cantera/clib/src/ct.cpp | 2565 +++++++++++++++++---------------- Cantera/clib/src/ctonedim.cpp | 12 +- Cantera/fortran/src/fct.cpp | 3 +- 3 files changed, 1292 insertions(+), 1288 deletions(-) diff --git a/Cantera/clib/src/ct.cpp b/Cantera/clib/src/ct.cpp index e6c33cbe8..9a5fa36d0 100755 --- a/Cantera/clib/src/ct.cpp +++ b/Cantera/clib/src/ct.cpp @@ -1,1282 +1,1283 @@ -/** - * @file ct.cpp - * Cantera interface library. This library of functions is designed - * to encapsulate Cantera functionality and make it available for - * use in languages and applications other than C++. A set of - * library functions is provided that are declared "extern C". All - * Cantera objects are stored and referenced by integers - no - * pointers are passed to or from the calling application. - */ - -/* $Id$ */ - -// turn off warnings under Windows -#ifdef WIN32 -#pragma warning(disable:4786) -#pragma warning(disable:4503) -#endif - -#define CANTERA_USE_INTERNAL -#include "ct.h" - -// Cantera includes -#include "equil.h" -#include "KineticsFactory.h" -#include "TransportFactory.h" -#include "ctml.h" -#include "importKinetics.h" -#include "ThermoFactory.h" -#include "ck2ct.h" -#include "Storage.h" -#include "Cabinet.h" -#include "InterfaceKinetics.h" -#include "PureFluidPhase.h" - - -using namespace std; -using namespace Cantera; - -#ifdef WIN32 -#include "windows.h" -#endif - - -inline XML_Node* _xml(int i) { - return Cabinet::cabinet(false)->item(i); -} - - -#ifdef WITH_PURE_FLUIDS -static PureFluidPhase* purefluid(int n) { - try { - ThermoPhase* tp = th(n); - if (tp->eosType() == cPureFluid) { - return (PureFluidPhase*)tp; - } - else { - throw CanteraError("purefluid","object is not a PureFluidPhase object"); - } - } - catch (CanteraError) { - return 0; - } -} - -static double pfprop(int n, int i, double v=0.0, double x=0.0) { - PureFluidPhase* p = purefluid(n); - if (p) { - switch(i) { - case 0: return p->critTemperature(); - case 1: return p->critPressure(); - case 2: return p->critDensity(); - case 3: return p->vaporFraction(); - case 4: return p->satTemperature(v); - case 5: return p->satPressure(v); - case 6: p->setState_Psat(v, x); return 0.0; - case 7: p->setState_Tsat(v, x); return 0.0; - } - } - return DERR; -} - - -#else - -static ThermoPhase* purefluid(int n) { - return th(n); -} -static double pfprop(int n, int i, double v=0.0, double x=0.0) { - return DERR; -} -#endif - - -inline int nThermo() { - return Storage::storage()->nThermo(); -} - -namespace Cantera { - void writephase(const ThermoPhase& th, bool show_thermo); -} - -/** - * Exported functions. - */ -extern "C" { - -#ifdef WIN32 -#ifndef NO_DLL_BUILD - /* - * The microsoft docs says we may need this in some - * cases when building dll's - */ - /* - bool WINAPI DllMain(HINSTANCE hModule, - DWORD ul_reason_for_call, - LPVOID lpReserved) { - switch(ul_reason_for_call ) { - case DLL_PROCESS_ATTACH: - break; - case DLL_THREAD_ATTACH: - break; - case DLL_THREAD_DETACH: - break; - case DLL_PROCESS_DETACH: - break; - } - return TRUE; - } - */ -#endif -#endif - - int DLL_EXPORT ct_appdelete() { - appdelete(); - return 0; - } - - //--------------- Phase ---------------------// - - int DLL_EXPORT phase_nElements(int n) { - return ph(n)->nElements(); - } - - int DLL_EXPORT phase_nSpecies(int n) { - return ph(n)->nSpecies(); - } - - doublereal DLL_EXPORT phase_temperature(int n) { - return ph(n)->temperature(); - } - - int DLL_EXPORT phase_setTemperature(int n, double t) { - try { - ph(n)->setTemperature(t); - } - catch(CanteraError) {return -1;} - return 0; - } - - doublereal DLL_EXPORT phase_density(int n) { - return ph(n)->density(); - } - - int DLL_EXPORT phase_setDensity(int n, double rho) { - if (rho < 0.0) return -1; - ph(n)->setDensity(rho); - return 0; - } - - doublereal DLL_EXPORT phase_molarDensity(int n) { - return ph(n)->molarDensity(); - } - - int DLL_EXPORT phase_setMolarDensity(int n, double ndens) { - if (ndens < 0.0) return -1; - ph(n)->setMolarDensity(ndens); - return 0; - } - - doublereal DLL_EXPORT phase_meanMolecularWeight(int n) { - return ph(n)->meanMolecularWeight(); - } - - int DLL_EXPORT phase_elementIndex(int n, char* nm) { - string elnm = string(nm); - return ph(n)->elementIndex(elnm); - } - - int DLL_EXPORT phase_speciesIndex(int n, char* nm) { - string spnm = string(nm); - return ph(n)->speciesIndex(spnm); - } - - int DLL_EXPORT phase_getMoleFractions(int n, int lenx, double* x) { - ThermoPhase* p = ph(n); - if (lenx >= p->nSpecies()) { - p->getMoleFractions(x); - return 0; - } - else - return -1; - } - - doublereal DLL_EXPORT phase_moleFraction(int n, int k) { - ThermoPhase* p = ph(n); - return p->moleFraction(k); - } - - int DLL_EXPORT phase_getMassFractions(int n, int leny, double* y) { - ThermoPhase* p = ph(n); - if (leny >= p->nSpecies()) { - p->getMassFractions(y); - return 0; - } - else - return -1; - } - - doublereal DLL_EXPORT phase_massFraction(int n, int k) { - ThermoPhase* p = ph(n); - return p->massFraction(k); - } - - int DLL_EXPORT phase_setMoleFractions(int n, int lenx, double* x, int norm) { - ThermoPhase* p = ph(n); - if (lenx >= p->nSpecies()) { - if (norm) p->setMoleFractions(x); - else p->setMoleFractions_NoNorm(x); - return 0; - } - else - return -1; - } - - int DLL_EXPORT phase_setMoleFractionsByName(int n, char* x) { - try { - ThermoPhase* p = ph(n); - compositionMap xx; - int nsp = p->nSpecies(); - for (int n = 0; n < nsp; n++) { - xx[p->speciesName(n)] = -1; - } - parseCompString(string(x), xx); - p->setMoleFractionsByName(xx); - return 0; - } - catch (CanteraError) {return -1;} - //catch (...) {return ERR;} - } - - int DLL_EXPORT phase_setMassFractions(int n, int leny, - double* y, int norm) { - ThermoPhase* p = ph(n); - if (leny >= p->nSpecies()) { - if (norm) p->setMassFractions(y); - else p->setMassFractions_NoNorm(y); - return 0; - } - else - return -10; - } - - int DLL_EXPORT phase_setMassFractionsByName(int n, char* y) { - try { - ThermoPhase* p = ph(n); - compositionMap yy; - int nsp = p->nSpecies(); - for (int n = 0; n < nsp; n++) { - yy[p->speciesName(n)] = -1; - } - parseCompString(string(y), yy); - p->setMassFractionsByName(yy); - return 0; - } - catch (CanteraError) {return -1;} - } - - int DLL_EXPORT phase_getAtomicWeights(int n, - int lenm, double* atw) { - ThermoPhase* p = ph(n); - if (lenm >= p->nElements()) { - const vector_fp& wt = p->atomicWeights(); - copy(wt.begin(), wt.end(), atw); - return 0; - } - else - return -10; - } - - int DLL_EXPORT phase_getMolecularWeights(int n, - int lenm, double* mw) { - ThermoPhase* p = ph(n); - if (lenm >= p->nSpecies()) { - const vector_fp& wt = p->molecularWeights(); - copy(wt.begin(), wt.end(), mw); - return 0; - } - else - return -10; - } - - int DLL_EXPORT phase_getName(int n, int lennm, char* nm) { - string name = ph(n)->name(); - int lout = (int) min(lennm, (int) name.size()); - copy(name.c_str(), name.c_str() + lout, nm); - nm[lout] = '\0'; - return 0; - } - - int DLL_EXPORT phase_setName(int n, const char* nm) { - string name = string(nm); - ph(n)->setName(name); - return 0; - } - - int DLL_EXPORT phase_getSpeciesName(int n, int k, int lennm, char* nm) { - try { - string spnm = ph(n)->speciesName(k); - int lout = min(lennm, (int) spnm.size()); - copy(spnm.c_str(), spnm.c_str() + lout, nm); - nm[lout] = '\0'; - return 0; - } - catch (CanteraError) { return -1; } - //catch (...) {return ERR;} - } - - int DLL_EXPORT phase_getElementName(int n, int m, int lennm, char* nm) { - try { - string elnm = ph(n)->elementName(m); - int lout = min(lennm, (int) elnm.size()); - copy(elnm.c_str(), elnm.c_str() + lout, nm); - nm[lout] = '\0'; - return 0; - } - catch (CanteraError) { return -1; } - } - - - doublereal DLL_EXPORT phase_nAtoms(int n, int k, int m) { - try { - return ph(n)->nAtoms(k,m); - } - catch (CanteraError) { return -1; } - } - - int DLL_EXPORT phase_addElement(int n, char* name, doublereal weight) { - try { - ph(n)->addElement(string(name),weight); - return 0; - } - catch (CanteraError) { return -1; } - } - -// int DLL_EXPORT phase_addSpecies(int n, char* name, int phase, -// int ncomp, doublereal* comp, int thermoType, int ncoeffs, -// double* coeffs, double minTemp, double maxTemp, double refPressure, -// doublereal charge, doublereal weight) { -// try { -// vector_fp cmp(ncomp); -// copy(comp, comp + ncomp, cmp.begin()); -// vector_fp c(ncoeffs); -// copy(coeffs, coeffs + ncoeffs, c.begin()); -// ph(n)->addSpecies(string(name), phase, cmp, -// thermoType, c, minTemp, maxTemp, refPressure, -// charge, weight); -// return 0; -// } -// catch (CanteraError) { return -1; } -// catch (...) {return ERR;} -// } - - - - //-------------- Thermo --------------------// - - // int DLL_EXPORT newThermo(int eos, int ph, int sptherm) { - // return Storage::storage()->addNewThermo(eos, ph, sptherm); - // } - - int DLL_EXPORT th_thermoIndex(char* id) { - return thermo_index(id); - } - -// int DLL_EXPORT newThermo(char* model) { -// try { -// string m = string(model); -// thermo_t* th = newThermoPhase(m); -// return Storage::storage()->addThermo(th); -// } -// catch (CanteraError) { return -1; } -// } - - int DLL_EXPORT newThermoFromXML(int mxml) { - try { - XML_Node* x = _xml(mxml); - thermo_t* th = newPhase(*x); - return Storage::storage()->addThermo(th); - } - catch (CanteraError) { return -1; } - } - - //int DLL_EXPORT th_phase(int n) { - // return th(n)->phase().index(); - // } - - int DLL_EXPORT th_nSpecies(int n) { - return th(n)->nSpecies(); - } - - int DLL_EXPORT th_eosType(int n) { - return th(n)->eosType(); - } - - double DLL_EXPORT th_enthalpy_mole(int n) { - try {return th(n)->enthalpy_mole();} - catch (CanteraError) {return DERR;} - } - - double DLL_EXPORT th_intEnergy_mole(int n) { - try {return th(n)->intEnergy_mole();} - catch (CanteraError) {return DERR;} - } - - double DLL_EXPORT th_entropy_mole(int n) { - try {return th(n)->entropy_mole();} - catch (CanteraError) {return DERR;} - } - - double DLL_EXPORT th_gibbs_mole(int n) { - try {return th(n)->gibbs_mole();} - catch (CanteraError) {return DERR;} - } - - double DLL_EXPORT th_cp_mole(int n) { - try {return th(n)->cp_mole();} - catch (CanteraError) {return DERR;} - } - - double DLL_EXPORT th_cv_mole(int n) { - try {return th(n)->cv_mole();} - catch (CanteraError) {return DERR;} - } - - double DLL_EXPORT th_pressure(int n) { - try {return th(n)->pressure();} - catch (CanteraError) {return DERR;} - } - - double DLL_EXPORT th_enthalpy_mass(int n) { - try {return th(n)->enthalpy_mass();} - catch (CanteraError) {return DERR;} - } - - double DLL_EXPORT th_intEnergy_mass(int n) { - try {return th(n)->intEnergy_mass();} - catch (CanteraError) {return DERR;} - } - - double DLL_EXPORT th_entropy_mass(int n) { - try {return th(n)->entropy_mass();} - catch (CanteraError) {return DERR;} - } - - double DLL_EXPORT th_gibbs_mass(int n) { - try {return th(n)->gibbs_mass();} - catch (CanteraError) {return DERR;} - } - - double DLL_EXPORT th_cp_mass(int n) { - try {return th(n)->cp_mass();} - catch (CanteraError) {return DERR;} - } - - double DLL_EXPORT th_cv_mass(int n) { - try {return th(n)->cv_mass();} - catch (CanteraError) {return DERR;} - } - - double DLL_EXPORT th_electricPotential(int n) { - try {return th(n)->electricPotential();} - catch (CanteraError) {return DERR;} - } - - int DLL_EXPORT th_chemPotentials(int n, int lenm, double* murt) { - thermo_t* thrm = th(n); - int nsp = thrm->nSpecies(); - if (lenm >= nsp) { - thrm->getChemPotentials(murt); - return 0; - } - else - return -10; - } - - int DLL_EXPORT th_elementPotentials(int n, int lenm, double* lambda) { - thermo_t* thrm = th(n); - int nel = thrm->nElements(); - if (lenm >= nel) { - equilibrate(*thrm, "TP", 0); - thrm->getElementPotentials(lambda); - return 0; - } - else - return -10; - } - - int DLL_EXPORT th_setPressure(int n, double p) { - try { - if (p < 0.0) throw CanteraError("th_setPressure", - "pressure cannot be negative"); - th(n)->setPressure(p); - return 0; - } - catch (CanteraError) {return -1;} - } - - int DLL_EXPORT th_set_HP(int n, double* vals) { - try { - if (vals[1] < 0.0) - throw CanteraError("th_set_HP", - "pressure cannot be negative"); - th(n)->setState_HP(vals[0],vals[1]); - if (th(n)->temperature() < 0.0) - throw CanteraError("th_set_HP", - "temperature cannot be negative"); - return 0; - } - catch (CanteraError) {return -1;} - } - - int DLL_EXPORT th_set_UV(int n, double* vals) { - try { - if (vals[1] < 0.0) - throw CanteraError("th_set_UV", - "specific volume cannot be negative"); - th(n)->setState_UV(vals[0],vals[1]); - if (th(n)->temperature() < 0.0) - throw CanteraError("th_set_UV", - "temperature cannot be negative"); - return 0; - } - catch (CanteraError) {return -1;} - } - - int DLL_EXPORT th_set_SV(int n, double* vals) { - try { - th(n)->setState_SV(vals[0],vals[1]); - return 0; - } - catch (CanteraError) {return -1;} - } - - int DLL_EXPORT th_set_SP(int n, double* vals) { - try { - th(n)->setState_SP(vals[0],vals[1]); - return 0; - } - catch (CanteraError) {return -1;} - } - - int DLL_EXPORT th_equil(int n, char* XY, int solver, - double rtol, int maxsteps, int maxiter, int loglevel) { - try { - equilibrate(*th(n), XY, solver, rtol, maxsteps, - maxiter, loglevel); return 0; - } - catch (CanteraError) { - return -1; - } - } - - doublereal DLL_EXPORT th_refPressure(int n) { - return th(n)->refPressure(); - } - - doublereal DLL_EXPORT th_minTemp(int n, int k) { - return th(n)->minTemp(k); - } - - doublereal DLL_EXPORT th_maxTemp(int n, int k) { - return th(n)->maxTemp(k); - } - - - int DLL_EXPORT th_getEnthalpies_RT(int n, int lenm, double* h_rt) { - try { - thermo_t* thrm = th(n); - int nsp = thrm->nSpecies(); - if (lenm >= nsp) { - thrm->getEnthalpy_RT_ref(h_rt); - return 0; - } - else - return -10; - } - catch (CanteraError) {return -1;} - } - - int DLL_EXPORT th_getEntropies_R(int n, int lenm, double* s_r) { - try { - thermo_t* thrm = th(n); - int nsp = thrm->nSpecies(); - if (lenm >= nsp) { - thrm->getEntropy_R_ref(s_r); - return 0; - } - else - return -10; - } - catch (CanteraError) {return -1;} - } - - int DLL_EXPORT th_getCp_R(int n, int lenm, double* cp_r) { - try { - thermo_t* thrm = th(n); - int nsp = thrm->nSpecies(); - if (lenm >= nsp) { - thrm->getCp_R_ref(cp_r); - return 0; - } - else - return -10; - } - catch (CanteraError) {return -1;} - } - - int DLL_EXPORT th_setElectricPotential(int n, double v) { - th(n)->setElectricPotential(v); - return 0; - } - - //-------------- pure fluids ---------------// -#ifdef WITH_PURE_FLUIDS - - double DLL_EXPORT th_critTemperature(int n) { - return pfprop(n,0); - } - - double DLL_EXPORT th_critPressure(int n) { - return purefluid(n)->critPressure(); - } - - double DLL_EXPORT th_critDensity(int n) { - return purefluid(n)->critDensity(); - } - - double DLL_EXPORT th_vaporFraction(int n) { - return purefluid(n)->vaporFraction(); - } - - double DLL_EXPORT th_satTemperature(int n, double p) { - try { - return purefluid(n)->satTemperature(p); - } - catch (CanteraError) { return DERR; } - } - - double DLL_EXPORT th_satPressure(int n, double t) { - try { - return purefluid(n)->satPressure(t); - } - catch (CanteraError) { return DERR; } - } - - int DLL_EXPORT th_setState_Psat(int n, double p, double x) { - try { - purefluid(n)->setState_Psat(p, x); - return 0; - } - catch (CanteraError) { return -1; } - } - - int DLL_EXPORT th_setState_Tsat(int n, double t, double x) { - try { - purefluid(n)->setState_Tsat(t, x); - return 0; - } - catch (CanteraError) { return -1; } - } -#else - - double DLL_EXPORT th_critTemperature(int n) { - return DERR; - } - - double DLL_EXPORT th_critPressure(int n) { - return DERR; - } - - double DLL_EXPORT th_critDensity(int n) { - return DERR; - } - - double DLL_EXPORT th_vaporFraction(int n) { - return DERR; - } - - double DLL_EXPORT th_satTemperature(int n, double p) { - return DERR; - } - - double DLL_EXPORT th_satPressure(int n, double t) { - return DERR; - } - - int DLL_EXPORT th_setState_Psat(int n, double p, double x) { - return DERR; - } - - int DLL_EXPORT th_setState_Tsat(int n, double t, double x) { - return DERR; - } -#endif - - - - //-------------- Kinetics ------------------// - - int DLL_EXPORT newKineticsFromXML(int mxml, int iphase, - int neighbor1, int neighbor2, int neighbor3, - int neighbor4) { - try { - XML_Node* x = _xml(mxml); - vector phases; - phases.push_back(th(iphase)); - if (neighbor1 >= 0) { - phases.push_back(th(neighbor1)); - if (neighbor2 >= 0) { - phases.push_back(th(neighbor2)); - if (neighbor3 >= 0) { - phases.push_back(th(neighbor3)); - if (neighbor4 >= 0) { - phases.push_back(th(neighbor4)); - } - } - } - } - Kinetics* kin = newKineticsMgr(*x, phases); - if (kin) - return Storage::storage()->addKinetics(kin); - else - return 0; - } - catch (CanteraError) { return -1; } - } - - int DLL_EXPORT installRxnArrays(int pxml, int ikin, - char* default_phase) { - try { - XML_Node* p = _xml(pxml); - kinetics_t* k = kin(ikin); - string defphase = string(default_phase); - installReactionArrays(*p, *k, defphase); - return 0; - } - catch (CanteraError) { return -1; } - } - - //------------------------------------- - int DLL_EXPORT kin_type(int n) { - return kin(n)->type(); - } - - int DLL_EXPORT kin_start(int n, int p) { - return kin(n)->kineticsSpeciesIndex(0,p); - } - - int DLL_EXPORT kin_speciesIndex(int n, const char* nm, const char* ph) { - return kin(n)->kineticsSpeciesIndex(string(nm), string(ph)); - } - - //--------------------------------------- - - int DLL_EXPORT kin_nSpecies(int n) { - return kin(n)->nTotalSpecies(); - } - - int DLL_EXPORT kin_nReactions(int n) { - return kin(n)->nReactions(); - } - - int DLL_EXPORT kin_nPhases(int n) { - return kin(n)->nPhases(); - } - - int DLL_EXPORT kin_phaseIndex(int n, char* ph) { - return kin(n)->phaseIndex(string(ph)); - } - - int DLL_EXPORT kin_reactionPhaseIndex(int n) { - return kin(n)->reactionPhaseIndex(); - } - - double DLL_EXPORT kin_reactantStoichCoeff(int n, int k, int i) { - return kin(n)->reactantStoichCoeff(k,i); - } - - double DLL_EXPORT kin_productStoichCoeff(int n, int k, int i) { - return kin(n)->productStoichCoeff(k,i); - } - - int DLL_EXPORT kin_reactionType(int n, int i) { - return kin(n)->reactionType(i); - } - - int DLL_EXPORT kin_getFwdRatesOfProgress(int n, int len, double* fwdROP) { - Kinetics* k = kin(n); - try { - if (len >= k->nReactions()) { - k->getFwdRatesOfProgress(fwdROP); - return 0; - } - else - return ERR; - } - catch (CanteraError) {return -1;} - } - - int DLL_EXPORT kin_getRevRatesOfProgress(int n, int len, double* revROP) { - Kinetics* k = kin(n); - try { - if (len >= k->nReactions()) { - k->getRevRatesOfProgress(revROP); - return 0; - } - else - return ERR; - } - catch (CanteraError) {return -1;} - } - - int DLL_EXPORT kin_isReversible(int n, int i) { - return (int)kin(n)->isReversible(i); - } - - int DLL_EXPORT kin_getNetRatesOfProgress(int n, int len, double* netROP) { - try { - Kinetics* k = kin(n); - if (len >= k->nReactions()) { - k->getNetRatesOfProgress(netROP); - return 0; - } - else - return ERR; - } - catch (CanteraError) {return -1;} - } - - int DLL_EXPORT kin_getFwdRateConstants(int n, int len, double* kfwd) { - try { - Kinetics* k = kin(n); - if (len >= k->nReactions()) { - k->getFwdRateConstants(kfwd); - return 0; - } - else - return ERR; - } - catch (CanteraError) {return -1;} - } - - int DLL_EXPORT kin_getRevRateConstants(int n, int doIrreversible, int len, double* krev) { - try { - Kinetics* k = kin(n); - bool doirrev = false; - if (doIrreversible != 0) doirrev = true; - if (len >= k->nReactions()) { - k->getRevRateConstants(krev, doirrev); - return 0; - } - else - return ERR; - } - catch (CanteraError) {return -1;} - } - - - int DLL_EXPORT kin_getActivationEnergies(int n, int len, double* E) { - try { - Kinetics* k = kin(n); - if (len >= k->nReactions()) { - k->getActivationEnergies(E); - return 0; - } - else - return ERR; - } - catch (CanteraError) {return -1;} - } - - - int DLL_EXPORT kin_getDelta(int n, int job, int len, double* delta) { - try { - Kinetics* k = kin(n); - if (len < k->nReactions()) return ERR; - switch (job) { - case 0: - k->getDeltaEnthalpy(delta); break; - case 1: - k->getDeltaGibbs(delta); break; - case 2: - k->getDeltaEntropy(delta); break; - case 3: - k->getDeltaSSEnthalpy(delta); break; - case 4: - k->getDeltaSSGibbs(delta); break; - case 5: - k->getDeltaSSEntropy(delta); break; - default: - return ERR; - } - return 0; - } - catch (CanteraError) {return -1;} - } - - - int DLL_EXPORT kin_getDeltaEntropy(int n, int len, double* deltaS) { - try { - Kinetics* k = kin(n); - if (len >= k->nReactions()) { - k->getDeltaEntropy(deltaS); - return 0; - } - else - return ERR; - } - catch (CanteraError) {return -1;} - } - - - int DLL_EXPORT kin_getCreationRates(int n, int len, double* cdot) { - try { - Kinetics* k = kin(n); - if (len >= k->nTotalSpecies()) { - k->getCreationRates(cdot); - return 0; - } - else - return ERR; - } - catch (CanteraError) {return -1;} - } - - int DLL_EXPORT kin_getDestructionRates(int n, int len, double* ddot) { - try { - Kinetics* k = kin(n); - if (len >= k->nTotalSpecies()) { - k->getDestructionRates(ddot); - return 0; - } - else - return ERR; - } - catch (CanteraError) {return -1;} - //catch (...) {return ERR;} - } - - int DLL_EXPORT kin_getNetProductionRates(int n, int len, double* wdot) { - try { - Kinetics* k = kin(n); - if (len >= k->nTotalSpecies()) { - k->getNetProductionRates(wdot); - return 0; - } - else - return ERR; - } - catch (CanteraError) {return -1;} - } - - int DLL_EXPORT kin_getSourceTerms(int n, int len, double* ydot) { - try { - Kinetics* k = kin(n); - ThermoPhase* p = &k->thermo(); - const vector_fp& mw = p->molecularWeights(); - int nsp = static_cast(mw.size()); - double rrho = 1.0/p->density(); - if (len >= nsp) { - k->getNetProductionRates(ydot); - multiply_each(ydot, ydot + nsp, mw.begin()); - scale(ydot, ydot + nsp, ydot, rrho); - return 0; - } - else - return ERR; - } - catch (CanteraError) {return -1;} - } - - double DLL_EXPORT kin_multiplier(int n, int i) { - return kin(n)->multiplier(i); - } - - int DLL_EXPORT kin_phase(int n, int i) { - return kin(n)->thermo(i).index(); - // return thermo_index(kin(n)->thermo(i).id()); - } - - int DLL_EXPORT kin_getEquilibriumConstants(int n, int len, double* kc) { - try { - Kinetics* k = kin(n); - if (len >= k->nReactions()) { - k->getEquilibriumConstants(kc); - return 0; - } - else - return ERR; - } - catch (CanteraError) {return -1;} - } - - int DLL_EXPORT kin_getReactionString(int n, int i, int len, char* buf) { - try { - Kinetics* k = kin(n); - string r = k->reactionString(i); - int lout = min(len, (int)r.size()); - copy(r.c_str(), r.c_str() + lout, buf); - buf[lout] = '\0'; - return 0; - } - catch (CanteraError) {return -1;} - } - - int DLL_EXPORT kin_setMultiplier(int n, int i, double v) { - try { - if (v >= 0.0) { - kin(n)->setMultiplier(i,v); - return 0; - } - else return ERR; - } - catch (CanteraError) {return -1;} - } - - int DLL_EXPORT kin_advanceCoverages(int n, double tstep) { - try { - Kinetics* k = kin(n); - if (k->type() == cInterfaceKinetics) { - ((InterfaceKinetics*)k)->advanceCoverages(tstep); - } - else { - throw CanteraError("kin_advanceCoverages", - "wrong kinetics manager type"); - } - return 0; - } - catch (CanteraError) {return -1;} - } - - //------------------- Transport --------------------------- - - int DLL_EXPORT newTransport(char* model, - int ith, int loglevel) { - string mstr = string(model); - thermo_t* t = th(ith); - try { - Transport* tr = newTransportMgr(mstr,t, loglevel); - return Storage::storage()->addTransport(tr); - } - catch (CanteraError) { return -1; } - } - - double DLL_EXPORT trans_viscosity(int n) { - try {return trans(n)->viscosity();} - catch (CanteraError) { return -1.0; } - } - - double DLL_EXPORT trans_thermalConductivity(int n) { - try {return trans(n)->thermalConductivity();} - catch (CanteraError) { return -1.0; } - } - - int DLL_EXPORT trans_getThermalDiffCoeffs(int n, int ldt, double* dt) { - try { trans(n)->getThermalDiffCoeffs(dt); return 0; } - catch (CanteraError) { return -1; } - } - - int DLL_EXPORT trans_getMixDiffCoeffs(int n, int ld, double* d) { - try { trans(n)->getMixDiffCoeffs(d); return 0;} - catch (CanteraError) { return -1; } - } - - int DLL_EXPORT trans_getBinDiffCoeffs(int n, int ld, double* d) { - try { trans(n)->getBinaryDiffCoeffs(ld,d); return 0;} - catch (CanteraError) { return -1; } - } - - int DLL_EXPORT trans_getMultiDiffCoeffs(int n, int ld, double* d) { - try { trans(n)->getMultiDiffCoeffs(ld,d); return 0;} - catch (CanteraError) { return -1; } - } - - int DLL_EXPORT trans_setParameters(int n, int type, int k, double* d) { - try { trans(n)->setParameters(type, k, d); return 0;} - catch (CanteraError) { return -1; } - } - - int DLL_EXPORT trans_getMolarFluxes(int n, const double* state1, - const double* state2, double delta, double* fluxes) { - try { - trans(n)->getMolarFluxes(state1, state2, delta, fluxes); - return 0; - } - catch (CanteraError) { return -1; } - } - - //-------------------- Functions --------------------------- - - int DLL_EXPORT import_phase(int nth, int nxml, char* id) { - thermo_t* thrm = th(nth); - XML_Node* node = _xml(nxml); - string idstr = string(id); - try { - importPhase(*node, thrm); - return 0; - } - catch (CanteraError) { return -1; } - } - - int DLL_EXPORT import_kinetics(int nxml, char* id, - int nphases, integer* ith, int nkin) { - vector phases; - for (int i = 0; i < nphases; i++) { - phases.push_back(th(ith[i])); - } - XML_Node* node = _xml(nxml); - Kinetics* k = kin(nkin); - string idstr = string(id); - try { - importKinetics(*node, phases, k); - return 0; - } - catch (CanteraError) { return -1; } - } - - - int DLL_EXPORT phase_report(int nth, - int ibuf, char* buf, int show_thermo) { - try { - bool stherm = (show_thermo != 0); - string s = report(*th(nth), stherm); - if (int(s.size()) > ibuf - 1) { - return -(static_cast(s.size()) + 1); - } - copy(s.begin(), s.end(), buf); - buf[s.size() - 1] = '\0'; - return 0; - - } - catch (CanteraError) { return -1; } - } - - int DLL_EXPORT write_phase(int nth, int show_thermo) { - try { - bool stherm = (show_thermo != 0); - writephase(*th(nth), stherm); - return 0; - } - catch (CanteraError) { return -1; } - } - - int DLL_EXPORT write_HTML_log(char* file) { - write_logfile(string(file)); - return 0; - } - - int DLL_EXPORT getCanteraError(int buflen, char* buf) { - string e; - e = lastErrorMessage(); - if (buflen > 0) { - int n = min(static_cast(e.size()), buflen-1); - copy(e.begin(), e.begin() + n, buf); - buf[min(n, buflen-1)] = '\0'; - } - return int(e.size()); - } - - int DLL_EXPORT showCanteraErrors() { - showErrors(); - return 0; - } - - int DLL_EXPORT addCanteraDirectory(int buflen, char* buf) { - addDirectory(string(buf)); - return 0; - } - - int DLL_EXPORT setLogWriter(void* logger) { - Logger* logwriter = (Logger*)logger; - setLogger(logwriter); - return 0; - } - - int DLL_EXPORT readlog(int n, char* buf) { - string s; - writelog("function readlog is deprecated!"); - //getlog(s); - int nlog = static_cast(s.size()); - if (n < 0) return nlog; - int nn = min(n-1, nlog); - copy(s.begin(), s.begin() + nn, - buf); - buf[min(nlog, n-1)] = '\0'; - //clearlog(); - return 0; - - } - int DLL_EXPORT clearStorage() { - try { - Storage::storage()->clear(); - return 0; - } - catch (CanteraError) { - return -1; - } - } - - int DLL_EXPORT delThermo(int n) { - try { - Storage::storage()->deleteThermo(n); - return 0; - } - catch (CanteraError) { - return -1; - } - } - - int DLL_EXPORT delKinetics(int n) { - Storage::storage()->deleteKinetics(n); - return 0; - } - - int DLL_EXPORT delTransport(int n) { - Storage::storage()->deleteTransport(n); - return 0; - } - - int DLL_EXPORT buildSolutionFromXML(char* src, int ixml, char* id, - int ith, int ikin) { - - XML_Node* root = 0; - if (ixml > 0) root = _xml(ixml); - - thermo_t* t = th(ith); - kinetics_t* k = kin(ikin); - - Kinetics& kin = *k; - XML_Node *x, *r=0; - if (root) r = &root->root(); - x = get_XML_Node(string(src), r); - //x = find_XML(string(src), r, string(id), "", "phase"); - if (!x) return false; - importPhase(*x, t); - kin.addPhase(*t); - kin.init(); - installReactionArrays(*x, kin, x->id()); - t->setState_TP(300.0, OneAtm); - if (r) { - if (&x->root() != &r->root()) delete &x->root(); - } - else delete &x->root(); - return 0; - } - - - int DLL_EXPORT ck_to_cti(char* in_file, char* db_file, - char* tr_file, char* id_tag, int debug, int validate) { - bool dbg = (debug != 0); - bool val = (validate != 0); - return pip::convert_ck(in_file, db_file, tr_file, id_tag, dbg, val); - } - - - int DLL_EXPORT writelogfile(char* logfile) { - write_logfile(string(logfile)); - return 0; - } - - -} +/** + * @file ct.cpp + * Cantera interface library. This library of functions is designed + * to encapsulate Cantera functionality and make it available for + * use in languages and applications other than C++. A set of + * library functions is provided that are declared "extern C". All + * Cantera objects are stored and referenced by integers - no + * pointers are passed to or from the calling application. + */ + +/* $Id$ */ + +// turn off warnings under Windows +#ifdef WIN32 +#pragma warning(disable:4786) +#pragma warning(disable:4503) +#endif + +#define CANTERA_USE_INTERNAL +#include "ct.h" + +// Cantera includes +#include "equil.h" +#include "KineticsFactory.h" +#include "TransportFactory.h" +#include "ctml.h" +#include "importKinetics.h" +#include "ThermoFactory.h" +#include "ck2ct.h" +#include "Storage.h" +#include "Cabinet.h" +#include "InterfaceKinetics.h" +#include "PureFluidPhase.h" + + +using namespace std; +using namespace Cantera; + +#ifdef WIN32 +#include "windows.h" +#endif + + +inline XML_Node* _xml(int i) { + return Cabinet::cabinet(false)->item(i); +} + + +#ifdef WITH_PURE_FLUIDS +static PureFluidPhase* purefluid(int n) { + try { + ThermoPhase* tp = th(n); + if (tp->eosType() == cPureFluid) { + return (PureFluidPhase*)tp; + } + else { + throw CanteraError("purefluid","object is not a PureFluidPhase object"); + } + } + catch (CanteraError) { + return 0; + } + return 0; +} + +static double pfprop(int n, int i, double v=0.0, double x=0.0) { + PureFluidPhase* p = purefluid(n); + if (p) { + switch(i) { + case 0: return p->critTemperature(); + case 1: return p->critPressure(); + case 2: return p->critDensity(); + case 3: return p->vaporFraction(); + case 4: return p->satTemperature(v); + case 5: return p->satPressure(v); + case 6: p->setState_Psat(v, x); return 0.0; + case 7: p->setState_Tsat(v, x); return 0.0; + } + } + return DERR; +} + + +#else + +static ThermoPhase* purefluid(int n) { + return th(n); +} +static double pfprop(int n, int i, double v=0.0, double x=0.0) { + return DERR; +} +#endif + + +inline int nThermo() { + return Storage::storage()->nThermo(); +} + +namespace Cantera { + void writephase(const ThermoPhase& th, bool show_thermo); +} + +/** + * Exported functions. + */ +extern "C" { + +#ifdef WIN32 +#ifndef NO_DLL_BUILD + /* + * The microsoft docs says we may need this in some + * cases when building dll's + */ + /* + bool WINAPI DllMain(HINSTANCE hModule, + DWORD ul_reason_for_call, + LPVOID lpReserved) { + switch(ul_reason_for_call ) { + case DLL_PROCESS_ATTACH: + break; + case DLL_THREAD_ATTACH: + break; + case DLL_THREAD_DETACH: + break; + case DLL_PROCESS_DETACH: + break; + } + return TRUE; + } + */ +#endif +#endif + + int DLL_EXPORT ct_appdelete() { + appdelete(); + return 0; + } + + //--------------- Phase ---------------------// + + int DLL_EXPORT phase_nElements(int n) { + return ph(n)->nElements(); + } + + int DLL_EXPORT phase_nSpecies(int n) { + return ph(n)->nSpecies(); + } + + doublereal DLL_EXPORT phase_temperature(int n) { + return ph(n)->temperature(); + } + + int DLL_EXPORT phase_setTemperature(int n, double t) { + try { + ph(n)->setTemperature(t); + } + catch(CanteraError) {return -1;} + return 0; + } + + doublereal DLL_EXPORT phase_density(int n) { + return ph(n)->density(); + } + + int DLL_EXPORT phase_setDensity(int n, double rho) { + if (rho < 0.0) return -1; + ph(n)->setDensity(rho); + return 0; + } + + doublereal DLL_EXPORT phase_molarDensity(int n) { + return ph(n)->molarDensity(); + } + + int DLL_EXPORT phase_setMolarDensity(int n, double ndens) { + if (ndens < 0.0) return -1; + ph(n)->setMolarDensity(ndens); + return 0; + } + + doublereal DLL_EXPORT phase_meanMolecularWeight(int n) { + return ph(n)->meanMolecularWeight(); + } + + int DLL_EXPORT phase_elementIndex(int n, char* nm) { + string elnm = string(nm); + return ph(n)->elementIndex(elnm); + } + + int DLL_EXPORT phase_speciesIndex(int n, char* nm) { + string spnm = string(nm); + return ph(n)->speciesIndex(spnm); + } + + int DLL_EXPORT phase_getMoleFractions(int n, int lenx, double* x) { + ThermoPhase* p = ph(n); + if (lenx >= p->nSpecies()) { + p->getMoleFractions(x); + return 0; + } + else + return -1; + } + + doublereal DLL_EXPORT phase_moleFraction(int n, int k) { + ThermoPhase* p = ph(n); + return p->moleFraction(k); + } + + int DLL_EXPORT phase_getMassFractions(int n, int leny, double* y) { + ThermoPhase* p = ph(n); + if (leny >= p->nSpecies()) { + p->getMassFractions(y); + return 0; + } + else + return -1; + } + + doublereal DLL_EXPORT phase_massFraction(int n, int k) { + ThermoPhase* p = ph(n); + return p->massFraction(k); + } + + int DLL_EXPORT phase_setMoleFractions(int n, int lenx, double* x, int norm) { + ThermoPhase* p = ph(n); + if (lenx >= p->nSpecies()) { + if (norm) p->setMoleFractions(x); + else p->setMoleFractions_NoNorm(x); + return 0; + } + else + return -1; + } + + int DLL_EXPORT phase_setMoleFractionsByName(int n, char* x) { + try { + ThermoPhase* p = ph(n); + compositionMap xx; + int nsp = p->nSpecies(); + for (int n = 0; n < nsp; n++) { + xx[p->speciesName(n)] = -1; + } + parseCompString(string(x), xx); + p->setMoleFractionsByName(xx); + return 0; + } + catch (CanteraError) {return -1;} + //catch (...) {return ERR;} + } + + int DLL_EXPORT phase_setMassFractions(int n, int leny, + double* y, int norm) { + ThermoPhase* p = ph(n); + if (leny >= p->nSpecies()) { + if (norm) p->setMassFractions(y); + else p->setMassFractions_NoNorm(y); + return 0; + } + else + return -10; + } + + int DLL_EXPORT phase_setMassFractionsByName(int n, char* y) { + try { + ThermoPhase* p = ph(n); + compositionMap yy; + int nsp = p->nSpecies(); + for (int n = 0; n < nsp; n++) { + yy[p->speciesName(n)] = -1; + } + parseCompString(string(y), yy); + p->setMassFractionsByName(yy); + return 0; + } + catch (CanteraError) {return -1;} + } + + int DLL_EXPORT phase_getAtomicWeights(int n, + int lenm, double* atw) { + ThermoPhase* p = ph(n); + if (lenm >= p->nElements()) { + const vector_fp& wt = p->atomicWeights(); + copy(wt.begin(), wt.end(), atw); + return 0; + } + else + return -10; + } + + int DLL_EXPORT phase_getMolecularWeights(int n, + int lenm, double* mw) { + ThermoPhase* p = ph(n); + if (lenm >= p->nSpecies()) { + const vector_fp& wt = p->molecularWeights(); + copy(wt.begin(), wt.end(), mw); + return 0; + } + else + return -10; + } + + int DLL_EXPORT phase_getName(int n, int lennm, char* nm) { + string name = ph(n)->name(); + int lout = (int) min(lennm, (int) name.size()); + copy(name.c_str(), name.c_str() + lout, nm); + nm[lout] = '\0'; + return 0; + } + + int DLL_EXPORT phase_setName(int n, const char* nm) { + string name = string(nm); + ph(n)->setName(name); + return 0; + } + + int DLL_EXPORT phase_getSpeciesName(int n, int k, int lennm, char* nm) { + try { + string spnm = ph(n)->speciesName(k); + int lout = min(lennm, (int) spnm.size()); + copy(spnm.c_str(), spnm.c_str() + lout, nm); + nm[lout] = '\0'; + return 0; + } + catch (CanteraError) { return -1; } + //catch (...) {return ERR;} + } + + int DLL_EXPORT phase_getElementName(int n, int m, int lennm, char* nm) { + try { + string elnm = ph(n)->elementName(m); + int lout = min(lennm, (int) elnm.size()); + copy(elnm.c_str(), elnm.c_str() + lout, nm); + nm[lout] = '\0'; + return 0; + } + catch (CanteraError) { return -1; } + } + + + doublereal DLL_EXPORT phase_nAtoms(int n, int k, int m) { + try { + return ph(n)->nAtoms(k,m); + } + catch (CanteraError) { return -1; } + } + + int DLL_EXPORT phase_addElement(int n, char* name, doublereal weight) { + try { + ph(n)->addElement(string(name),weight); + return 0; + } + catch (CanteraError) { return -1; } + } + +// int DLL_EXPORT phase_addSpecies(int n, char* name, int phase, +// int ncomp, doublereal* comp, int thermoType, int ncoeffs, +// double* coeffs, double minTemp, double maxTemp, double refPressure, +// doublereal charge, doublereal weight) { +// try { +// vector_fp cmp(ncomp); +// copy(comp, comp + ncomp, cmp.begin()); +// vector_fp c(ncoeffs); +// copy(coeffs, coeffs + ncoeffs, c.begin()); +// ph(n)->addSpecies(string(name), phase, cmp, +// thermoType, c, minTemp, maxTemp, refPressure, +// charge, weight); +// return 0; +// } +// catch (CanteraError) { return -1; } +// catch (...) {return ERR;} +// } + + + + //-------------- Thermo --------------------// + + // int DLL_EXPORT newThermo(int eos, int ph, int sptherm) { + // return Storage::storage()->addNewThermo(eos, ph, sptherm); + // } + + int DLL_EXPORT th_thermoIndex(char* id) { + return thermo_index(id); + } + +// int DLL_EXPORT newThermo(char* model) { +// try { +// string m = string(model); +// thermo_t* th = newThermoPhase(m); +// return Storage::storage()->addThermo(th); +// } +// catch (CanteraError) { return -1; } +// } + + int DLL_EXPORT newThermoFromXML(int mxml) { + try { + XML_Node* x = _xml(mxml); + thermo_t* th = newPhase(*x); + return Storage::storage()->addThermo(th); + } + catch (CanteraError) { return -1; } + } + + //int DLL_EXPORT th_phase(int n) { + // return th(n)->phase().index(); + // } + + int DLL_EXPORT th_nSpecies(int n) { + return th(n)->nSpecies(); + } + + int DLL_EXPORT th_eosType(int n) { + return th(n)->eosType(); + } + + double DLL_EXPORT th_enthalpy_mole(int n) { + try {return th(n)->enthalpy_mole();} + catch (CanteraError) {return DERR;} + } + + double DLL_EXPORT th_intEnergy_mole(int n) { + try {return th(n)->intEnergy_mole();} + catch (CanteraError) {return DERR;} + } + + double DLL_EXPORT th_entropy_mole(int n) { + try {return th(n)->entropy_mole();} + catch (CanteraError) {return DERR;} + } + + double DLL_EXPORT th_gibbs_mole(int n) { + try {return th(n)->gibbs_mole();} + catch (CanteraError) {return DERR;} + } + + double DLL_EXPORT th_cp_mole(int n) { + try {return th(n)->cp_mole();} + catch (CanteraError) {return DERR;} + } + + double DLL_EXPORT th_cv_mole(int n) { + try {return th(n)->cv_mole();} + catch (CanteraError) {return DERR;} + } + + double DLL_EXPORT th_pressure(int n) { + try {return th(n)->pressure();} + catch (CanteraError) {return DERR;} + } + + double DLL_EXPORT th_enthalpy_mass(int n) { + try {return th(n)->enthalpy_mass();} + catch (CanteraError) {return DERR;} + } + + double DLL_EXPORT th_intEnergy_mass(int n) { + try {return th(n)->intEnergy_mass();} + catch (CanteraError) {return DERR;} + } + + double DLL_EXPORT th_entropy_mass(int n) { + try {return th(n)->entropy_mass();} + catch (CanteraError) {return DERR;} + } + + double DLL_EXPORT th_gibbs_mass(int n) { + try {return th(n)->gibbs_mass();} + catch (CanteraError) {return DERR;} + } + + double DLL_EXPORT th_cp_mass(int n) { + try {return th(n)->cp_mass();} + catch (CanteraError) {return DERR;} + } + + double DLL_EXPORT th_cv_mass(int n) { + try {return th(n)->cv_mass();} + catch (CanteraError) {return DERR;} + } + + double DLL_EXPORT th_electricPotential(int n) { + try {return th(n)->electricPotential();} + catch (CanteraError) {return DERR;} + } + + int DLL_EXPORT th_chemPotentials(int n, int lenm, double* murt) { + thermo_t* thrm = th(n); + int nsp = thrm->nSpecies(); + if (lenm >= nsp) { + thrm->getChemPotentials(murt); + return 0; + } + else + return -10; + } + + int DLL_EXPORT th_elementPotentials(int n, int lenm, double* lambda) { + thermo_t* thrm = th(n); + int nel = thrm->nElements(); + if (lenm >= nel) { + equilibrate(*thrm, "TP", 0); + thrm->getElementPotentials(lambda); + return 0; + } + else + return -10; + } + + int DLL_EXPORT th_setPressure(int n, double p) { + try { + if (p < 0.0) throw CanteraError("th_setPressure", + "pressure cannot be negative"); + th(n)->setPressure(p); + return 0; + } + catch (CanteraError) {return -1;} + } + + int DLL_EXPORT th_set_HP(int n, double* vals) { + try { + if (vals[1] < 0.0) + throw CanteraError("th_set_HP", + "pressure cannot be negative"); + th(n)->setState_HP(vals[0],vals[1]); + if (th(n)->temperature() < 0.0) + throw CanteraError("th_set_HP", + "temperature cannot be negative"); + return 0; + } + catch (CanteraError) {return -1;} + } + + int DLL_EXPORT th_set_UV(int n, double* vals) { + try { + if (vals[1] < 0.0) + throw CanteraError("th_set_UV", + "specific volume cannot be negative"); + th(n)->setState_UV(vals[0],vals[1]); + if (th(n)->temperature() < 0.0) + throw CanteraError("th_set_UV", + "temperature cannot be negative"); + return 0; + } + catch (CanteraError) {return -1;} + } + + int DLL_EXPORT th_set_SV(int n, double* vals) { + try { + th(n)->setState_SV(vals[0],vals[1]); + return 0; + } + catch (CanteraError) {return -1;} + } + + int DLL_EXPORT th_set_SP(int n, double* vals) { + try { + th(n)->setState_SP(vals[0],vals[1]); + return 0; + } + catch (CanteraError) {return -1;} + } + + int DLL_EXPORT th_equil(int n, char* XY, int solver, + double rtol, int maxsteps, int maxiter, int loglevel) { + try { + equilibrate(*th(n), XY, solver, rtol, maxsteps, + maxiter, loglevel); return 0; + } + catch (CanteraError) { + return -1; + } + } + + doublereal DLL_EXPORT th_refPressure(int n) { + return th(n)->refPressure(); + } + + doublereal DLL_EXPORT th_minTemp(int n, int k) { + return th(n)->minTemp(k); + } + + doublereal DLL_EXPORT th_maxTemp(int n, int k) { + return th(n)->maxTemp(k); + } + + + int DLL_EXPORT th_getEnthalpies_RT(int n, int lenm, double* h_rt) { + try { + thermo_t* thrm = th(n); + int nsp = thrm->nSpecies(); + if (lenm >= nsp) { + thrm->getEnthalpy_RT_ref(h_rt); + return 0; + } + else + return -10; + } + catch (CanteraError) {return -1;} + } + + int DLL_EXPORT th_getEntropies_R(int n, int lenm, double* s_r) { + try { + thermo_t* thrm = th(n); + int nsp = thrm->nSpecies(); + if (lenm >= nsp) { + thrm->getEntropy_R_ref(s_r); + return 0; + } + else + return -10; + } + catch (CanteraError) {return -1;} + } + + int DLL_EXPORT th_getCp_R(int n, int lenm, double* cp_r) { + try { + thermo_t* thrm = th(n); + int nsp = thrm->nSpecies(); + if (lenm >= nsp) { + thrm->getCp_R_ref(cp_r); + return 0; + } + else + return -10; + } + catch (CanteraError) {return -1;} + } + + int DLL_EXPORT th_setElectricPotential(int n, double v) { + th(n)->setElectricPotential(v); + return 0; + } + + //-------------- pure fluids ---------------// +#ifdef WITH_PURE_FLUIDS + + double DLL_EXPORT th_critTemperature(int n) { + return pfprop(n,0); + } + + double DLL_EXPORT th_critPressure(int n) { + return purefluid(n)->critPressure(); + } + + double DLL_EXPORT th_critDensity(int n) { + return purefluid(n)->critDensity(); + } + + double DLL_EXPORT th_vaporFraction(int n) { + return purefluid(n)->vaporFraction(); + } + + double DLL_EXPORT th_satTemperature(int n, double p) { + try { + return purefluid(n)->satTemperature(p); + } + catch (CanteraError) { return DERR; } + } + + double DLL_EXPORT th_satPressure(int n, double t) { + try { + return purefluid(n)->satPressure(t); + } + catch (CanteraError) { return DERR; } + } + + int DLL_EXPORT th_setState_Psat(int n, double p, double x) { + try { + purefluid(n)->setState_Psat(p, x); + return 0; + } + catch (CanteraError) { return -1; } + } + + int DLL_EXPORT th_setState_Tsat(int n, double t, double x) { + try { + purefluid(n)->setState_Tsat(t, x); + return 0; + } + catch (CanteraError) { return -1; } + } +#else + + double DLL_EXPORT th_critTemperature(int n) { + return DERR; + } + + double DLL_EXPORT th_critPressure(int n) { + return DERR; + } + + double DLL_EXPORT th_critDensity(int n) { + return DERR; + } + + double DLL_EXPORT th_vaporFraction(int n) { + return DERR; + } + + double DLL_EXPORT th_satTemperature(int n, double p) { + return DERR; + } + + double DLL_EXPORT th_satPressure(int n, double t) { + return DERR; + } + + int DLL_EXPORT th_setState_Psat(int n, double p, double x) { + return DERR; + } + + int DLL_EXPORT th_setState_Tsat(int n, double t, double x) { + return DERR; + } +#endif + + + + //-------------- Kinetics ------------------// + + int DLL_EXPORT newKineticsFromXML(int mxml, int iphase, + int neighbor1, int neighbor2, int neighbor3, + int neighbor4) { + try { + XML_Node* x = _xml(mxml); + vector phases; + phases.push_back(th(iphase)); + if (neighbor1 >= 0) { + phases.push_back(th(neighbor1)); + if (neighbor2 >= 0) { + phases.push_back(th(neighbor2)); + if (neighbor3 >= 0) { + phases.push_back(th(neighbor3)); + if (neighbor4 >= 0) { + phases.push_back(th(neighbor4)); + } + } + } + } + Kinetics* kin = newKineticsMgr(*x, phases); + if (kin) + return Storage::storage()->addKinetics(kin); + else + return 0; + } + catch (CanteraError) { return -1; } + } + + int DLL_EXPORT installRxnArrays(int pxml, int ikin, + char* default_phase) { + try { + XML_Node* p = _xml(pxml); + kinetics_t* k = kin(ikin); + string defphase = string(default_phase); + installReactionArrays(*p, *k, defphase); + return 0; + } + catch (CanteraError) { return -1; } + } + + //------------------------------------- + int DLL_EXPORT kin_type(int n) { + return kin(n)->type(); + } + + int DLL_EXPORT kin_start(int n, int p) { + return kin(n)->kineticsSpeciesIndex(0,p); + } + + int DLL_EXPORT kin_speciesIndex(int n, const char* nm, const char* ph) { + return kin(n)->kineticsSpeciesIndex(string(nm), string(ph)); + } + + //--------------------------------------- + + int DLL_EXPORT kin_nSpecies(int n) { + return kin(n)->nTotalSpecies(); + } + + int DLL_EXPORT kin_nReactions(int n) { + return kin(n)->nReactions(); + } + + int DLL_EXPORT kin_nPhases(int n) { + return kin(n)->nPhases(); + } + + int DLL_EXPORT kin_phaseIndex(int n, char* ph) { + return kin(n)->phaseIndex(string(ph)); + } + + int DLL_EXPORT kin_reactionPhaseIndex(int n) { + return kin(n)->reactionPhaseIndex(); + } + + double DLL_EXPORT kin_reactantStoichCoeff(int n, int k, int i) { + return kin(n)->reactantStoichCoeff(k,i); + } + + double DLL_EXPORT kin_productStoichCoeff(int n, int k, int i) { + return kin(n)->productStoichCoeff(k,i); + } + + int DLL_EXPORT kin_reactionType(int n, int i) { + return kin(n)->reactionType(i); + } + + int DLL_EXPORT kin_getFwdRatesOfProgress(int n, int len, double* fwdROP) { + Kinetics* k = kin(n); + try { + if (len >= k->nReactions()) { + k->getFwdRatesOfProgress(fwdROP); + return 0; + } + else + return ERR; + } + catch (CanteraError) {return -1;} + } + + int DLL_EXPORT kin_getRevRatesOfProgress(int n, int len, double* revROP) { + Kinetics* k = kin(n); + try { + if (len >= k->nReactions()) { + k->getRevRatesOfProgress(revROP); + return 0; + } + else + return ERR; + } + catch (CanteraError) {return -1;} + } + + int DLL_EXPORT kin_isReversible(int n, int i) { + return (int)kin(n)->isReversible(i); + } + + int DLL_EXPORT kin_getNetRatesOfProgress(int n, int len, double* netROP) { + try { + Kinetics* k = kin(n); + if (len >= k->nReactions()) { + k->getNetRatesOfProgress(netROP); + return 0; + } + else + return ERR; + } + catch (CanteraError) {return -1;} + } + + int DLL_EXPORT kin_getFwdRateConstants(int n, int len, double* kfwd) { + try { + Kinetics* k = kin(n); + if (len >= k->nReactions()) { + k->getFwdRateConstants(kfwd); + return 0; + } + else + return ERR; + } + catch (CanteraError) {return -1;} + } + + int DLL_EXPORT kin_getRevRateConstants(int n, int doIrreversible, int len, double* krev) { + try { + Kinetics* k = kin(n); + bool doirrev = false; + if (doIrreversible != 0) doirrev = true; + if (len >= k->nReactions()) { + k->getRevRateConstants(krev, doirrev); + return 0; + } + else + return ERR; + } + catch (CanteraError) {return -1;} + } + + + int DLL_EXPORT kin_getActivationEnergies(int n, int len, double* E) { + try { + Kinetics* k = kin(n); + if (len >= k->nReactions()) { + k->getActivationEnergies(E); + return 0; + } + else + return ERR; + } + catch (CanteraError) {return -1;} + } + + + int DLL_EXPORT kin_getDelta(int n, int job, int len, double* delta) { + try { + Kinetics* k = kin(n); + if (len < k->nReactions()) return ERR; + switch (job) { + case 0: + k->getDeltaEnthalpy(delta); break; + case 1: + k->getDeltaGibbs(delta); break; + case 2: + k->getDeltaEntropy(delta); break; + case 3: + k->getDeltaSSEnthalpy(delta); break; + case 4: + k->getDeltaSSGibbs(delta); break; + case 5: + k->getDeltaSSEntropy(delta); break; + default: + return ERR; + } + return 0; + } + catch (CanteraError) {return -1;} + } + + + int DLL_EXPORT kin_getDeltaEntropy(int n, int len, double* deltaS) { + try { + Kinetics* k = kin(n); + if (len >= k->nReactions()) { + k->getDeltaEntropy(deltaS); + return 0; + } + else + return ERR; + } + catch (CanteraError) {return -1;} + } + + + int DLL_EXPORT kin_getCreationRates(int n, int len, double* cdot) { + try { + Kinetics* k = kin(n); + if (len >= k->nTotalSpecies()) { + k->getCreationRates(cdot); + return 0; + } + else + return ERR; + } + catch (CanteraError) {return -1;} + } + + int DLL_EXPORT kin_getDestructionRates(int n, int len, double* ddot) { + try { + Kinetics* k = kin(n); + if (len >= k->nTotalSpecies()) { + k->getDestructionRates(ddot); + return 0; + } + else + return ERR; + } + catch (CanteraError) {return -1;} + //catch (...) {return ERR;} + } + + int DLL_EXPORT kin_getNetProductionRates(int n, int len, double* wdot) { + try { + Kinetics* k = kin(n); + if (len >= k->nTotalSpecies()) { + k->getNetProductionRates(wdot); + return 0; + } + else + return ERR; + } + catch (CanteraError) {return -1;} + } + + int DLL_EXPORT kin_getSourceTerms(int n, int len, double* ydot) { + try { + Kinetics* k = kin(n); + ThermoPhase* p = &k->thermo(); + const vector_fp& mw = p->molecularWeights(); + int nsp = static_cast(mw.size()); + double rrho = 1.0/p->density(); + if (len >= nsp) { + k->getNetProductionRates(ydot); + multiply_each(ydot, ydot + nsp, mw.begin()); + scale(ydot, ydot + nsp, ydot, rrho); + return 0; + } + else + return ERR; + } + catch (CanteraError) {return -1;} + } + + double DLL_EXPORT kin_multiplier(int n, int i) { + return kin(n)->multiplier(i); + } + + int DLL_EXPORT kin_phase(int n, int i) { + return kin(n)->thermo(i).index(); + // return thermo_index(kin(n)->thermo(i).id()); + } + + int DLL_EXPORT kin_getEquilibriumConstants(int n, int len, double* kc) { + try { + Kinetics* k = kin(n); + if (len >= k->nReactions()) { + k->getEquilibriumConstants(kc); + return 0; + } + else + return ERR; + } + catch (CanteraError) {return -1;} + } + + int DLL_EXPORT kin_getReactionString(int n, int i, int len, char* buf) { + try { + Kinetics* k = kin(n); + string r = k->reactionString(i); + int lout = min(len, (int)r.size()); + copy(r.c_str(), r.c_str() + lout, buf); + buf[lout] = '\0'; + return 0; + } + catch (CanteraError) {return -1;} + } + + int DLL_EXPORT kin_setMultiplier(int n, int i, double v) { + try { + if (v >= 0.0) { + kin(n)->setMultiplier(i,v); + return 0; + } + else return ERR; + } + catch (CanteraError) {return -1;} + } + + int DLL_EXPORT kin_advanceCoverages(int n, double tstep) { + try { + Kinetics* k = kin(n); + if (k->type() == cInterfaceKinetics) { + ((InterfaceKinetics*)k)->advanceCoverages(tstep); + } + else { + throw CanteraError("kin_advanceCoverages", + "wrong kinetics manager type"); + } + return 0; + } + catch (CanteraError) {return -1;} + } + + //------------------- Transport --------------------------- + + int DLL_EXPORT newTransport(char* model, + int ith, int loglevel) { + string mstr = string(model); + thermo_t* t = th(ith); + try { + Transport* tr = newTransportMgr(mstr,t, loglevel); + return Storage::storage()->addTransport(tr); + } + catch (CanteraError) { return -1; } + } + + double DLL_EXPORT trans_viscosity(int n) { + try {return trans(n)->viscosity();} + catch (CanteraError) { return -1.0; } + } + + double DLL_EXPORT trans_thermalConductivity(int n) { + try {return trans(n)->thermalConductivity();} + catch (CanteraError) { return -1.0; } + } + + int DLL_EXPORT trans_getThermalDiffCoeffs(int n, int ldt, double* dt) { + try { trans(n)->getThermalDiffCoeffs(dt); return 0; } + catch (CanteraError) { return -1; } + } + + int DLL_EXPORT trans_getMixDiffCoeffs(int n, int ld, double* d) { + try { trans(n)->getMixDiffCoeffs(d); return 0;} + catch (CanteraError) { return -1; } + } + + int DLL_EXPORT trans_getBinDiffCoeffs(int n, int ld, double* d) { + try { trans(n)->getBinaryDiffCoeffs(ld,d); return 0;} + catch (CanteraError) { return -1; } + } + + int DLL_EXPORT trans_getMultiDiffCoeffs(int n, int ld, double* d) { + try { trans(n)->getMultiDiffCoeffs(ld,d); return 0;} + catch (CanteraError) { return -1; } + } + + int DLL_EXPORT trans_setParameters(int n, int type, int k, double* d) { + try { trans(n)->setParameters(type, k, d); return 0;} + catch (CanteraError) { return -1; } + } + + int DLL_EXPORT trans_getMolarFluxes(int n, const double* state1, + const double* state2, double delta, double* fluxes) { + try { + trans(n)->getMolarFluxes(state1, state2, delta, fluxes); + return 0; + } + catch (CanteraError) { return -1; } + } + + //-------------------- Functions --------------------------- + + int DLL_EXPORT import_phase(int nth, int nxml, char* id) { + thermo_t* thrm = th(nth); + XML_Node* node = _xml(nxml); + string idstr = string(id); + try { + importPhase(*node, thrm); + return 0; + } + catch (CanteraError) { return -1; } + } + + int DLL_EXPORT import_kinetics(int nxml, char* id, + int nphases, integer* ith, int nkin) { + vector phases; + for (int i = 0; i < nphases; i++) { + phases.push_back(th(ith[i])); + } + XML_Node* node = _xml(nxml); + Kinetics* k = kin(nkin); + string idstr = string(id); + try { + importKinetics(*node, phases, k); + return 0; + } + catch (CanteraError) { return -1; } + } + + + int DLL_EXPORT phase_report(int nth, + int ibuf, char* buf, int show_thermo) { + try { + bool stherm = (show_thermo != 0); + string s = report(*th(nth), stherm); + if (int(s.size()) > ibuf - 1) { + return -(static_cast(s.size()) + 1); + } + copy(s.begin(), s.end(), buf); + buf[s.size() - 1] = '\0'; + return 0; + + } + catch (CanteraError) { return -1; } + } + + int DLL_EXPORT write_phase(int nth, int show_thermo) { + try { + bool stherm = (show_thermo != 0); + writephase(*th(nth), stherm); + return 0; + } + catch (CanteraError) { return -1; } + } + + int DLL_EXPORT write_HTML_log(char* file) { + write_logfile(string(file)); + return 0; + } + + int DLL_EXPORT getCanteraError(int buflen, char* buf) { + string e; + e = lastErrorMessage(); + if (buflen > 0) { + int n = min(static_cast(e.size()), buflen-1); + copy(e.begin(), e.begin() + n, buf); + buf[min(n, buflen-1)] = '\0'; + } + return int(e.size()); + } + + int DLL_EXPORT showCanteraErrors() { + showErrors(); + return 0; + } + + int DLL_EXPORT addCanteraDirectory(int buflen, char* buf) { + addDirectory(string(buf)); + return 0; + } + + int DLL_EXPORT setLogWriter(void* logger) { + Logger* logwriter = (Logger*)logger; + setLogger(logwriter); + return 0; + } + + int DLL_EXPORT readlog(int n, char* buf) { + string s; + writelog("function readlog is deprecated!"); + //getlog(s); + int nlog = static_cast(s.size()); + if (n < 0) return nlog; + int nn = min(n-1, nlog); + copy(s.begin(), s.begin() + nn, + buf); + buf[min(nlog, n-1)] = '\0'; + //clearlog(); + return 0; + + } + int DLL_EXPORT clearStorage() { + try { + Storage::storage()->clear(); + return 0; + } + catch (CanteraError) { + return -1; + } + } + + int DLL_EXPORT delThermo(int n) { + try { + Storage::storage()->deleteThermo(n); + return 0; + } + catch (CanteraError) { + return -1; + } + } + + int DLL_EXPORT delKinetics(int n) { + Storage::storage()->deleteKinetics(n); + return 0; + } + + int DLL_EXPORT delTransport(int n) { + Storage::storage()->deleteTransport(n); + return 0; + } + + int DLL_EXPORT buildSolutionFromXML(char* src, int ixml, char* id, + int ith, int ikin) { + + XML_Node* root = 0; + if (ixml > 0) root = _xml(ixml); + + thermo_t* t = th(ith); + kinetics_t* k = kin(ikin); + + Kinetics& kin = *k; + XML_Node *x, *r=0; + if (root) r = &root->root(); + x = get_XML_Node(string(src), r); + //x = find_XML(string(src), r, string(id), "", "phase"); + if (!x) return false; + importPhase(*x, t); + kin.addPhase(*t); + kin.init(); + installReactionArrays(*x, kin, x->id()); + t->setState_TP(300.0, OneAtm); + if (r) { + if (&x->root() != &r->root()) delete &x->root(); + } + else delete &x->root(); + return 0; + } + + + int DLL_EXPORT ck_to_cti(char* in_file, char* db_file, + char* tr_file, char* id_tag, int debug, int validate) { + bool dbg = (debug != 0); + bool val = (validate != 0); + return pip::convert_ck(in_file, db_file, tr_file, id_tag, dbg, val); + } + + + int DLL_EXPORT writelogfile(char* logfile) { + write_logfile(string(logfile)); + return 0; + } + + +} diff --git a/Cantera/clib/src/ctonedim.cpp b/Cantera/clib/src/ctonedim.cpp index e1da6fa52..9295c2ed5 100644 --- a/Cantera/clib/src/ctonedim.cpp +++ b/Cantera/clib/src/ctonedim.cpp @@ -47,16 +47,18 @@ inline Domain1D* _domain(int i) { static StFlow* _stflow(int i) { Domain1D* d = _domain(i); if (d->domainType() == cFlowType) return (StFlow*)d; - else + else { throw CanteraError("_stflow","wrong domain type"); + } + return 0; } static Bdry1D* _bdry(int i) { Domain1D* d = _domain(i); - if (d->isConnector()) return (Bdry1D*)d; - else - throw CanteraError("_bdry","wrong domain type: " - +int2str(d->domainType())); + if (! d->isConnector()) { + throw CanteraError("_bdry","wrong domain type: " +int2str(d->domainType())); + } + return (Bdry1D*)d; } inline ThermoPhase* _phase(int n) { diff --git a/Cantera/fortran/src/fct.cpp b/Cantera/fortran/src/fct.cpp index e7dcf99fd..d6d7145b1 100644 --- a/Cantera/fortran/src/fct.cpp +++ b/Cantera/fortran/src/fct.cpp @@ -33,7 +33,7 @@ // Assert that there is storage // for the templated classes' static member // (needed to compile on solaris) -template<> Cabinet * Cabinet::__storage; +//template<> Cabinet * Cabinet::__storage; inline XML_Node* _xml(const integer* n) { return Cabinet::cabinet()->item(*n); @@ -93,6 +93,7 @@ extern "C" { catch (CanteraError) { handleError(); return -1; } + return -1; } //--------------- Phase ---------------------// From 08dca362047a929c919bd21426b7ec4d54c002c9 Mon Sep 17 00:00:00 2001 From: Christopher Lueth Date: Fri, 12 Feb 2010 22:23:44 +0000 Subject: [PATCH 07/26] hi --- Cantera/src/thermo/ThermoPhase.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Cantera/src/thermo/ThermoPhase.h b/Cantera/src/thermo/ThermoPhase.h index 3d5ddb577..b1f844c51 100644 --- a/Cantera/src/thermo/ThermoPhase.h +++ b/Cantera/src/thermo/ThermoPhase.h @@ -1,3 +1,5 @@ +//HI + /** * @file ThermoPhase.h * Header file for class ThermoPhase, the base class for phases with From 08615de2939cf3191fc952d916bb720933439709 Mon Sep 17 00:00:00 2001 From: Christopher Lueth Date: Fri, 12 Feb 2010 22:28:49 +0000 Subject: [PATCH 08/26] test commit --- Cantera/src/thermo/ThermoPhase.h | 2 -- 1 file changed, 2 deletions(-) diff --git a/Cantera/src/thermo/ThermoPhase.h b/Cantera/src/thermo/ThermoPhase.h index b1f844c51..3d5ddb577 100644 --- a/Cantera/src/thermo/ThermoPhase.h +++ b/Cantera/src/thermo/ThermoPhase.h @@ -1,5 +1,3 @@ -//HI - /** * @file ThermoPhase.h * Header file for class ThermoPhase, the base class for phases with From 48114593649a612616c39df6e908d6faf7d274d2 Mon Sep 17 00:00:00 2001 From: Harry Moffat Date: Fri, 2 Apr 2010 19:29:07 +0000 Subject: [PATCH 09/26] Changed the csvdiff default return value. Now a return of 0 indicates a success. Previously a return of 1 indicated a success. Please note! --- .../ChemEquil_ionizedGas/output_blessed.txt | 32 ++-- test_problems/ChemEquil_ionizedGas/runtest | 2 +- test_problems/VCSnonideal/NaCl_equil/runtest | 2 +- test_problems/VCSnonideal/NaCl_equil/runtestd | 2 +- test_problems/cxx_ex/runtest | 10 +- .../python/flame1/output_blessed.txt | 150 +++++++++--------- test_problems/python/flame1/runtest | 4 +- test_problems/python/runtest | 4 +- tools/testtools/.cvsignore | 4 - tools/testtools/csvdiff.cpp | 53 ++++--- tools/testtools/mdp_allo.cpp | 6 +- tools/testtools/mdp_allo.h | 6 +- tools/testtools/tok_input_util.cpp | 8 +- tools/testtools/tok_input_util.h | 8 +- 14 files changed, 149 insertions(+), 142 deletions(-) delete mode 100644 tools/testtools/.cvsignore diff --git a/test_problems/ChemEquil_ionizedGas/output_blessed.txt b/test_problems/ChemEquil_ionizedGas/output_blessed.txt index e26422df6..efe6c770a 100644 --- a/test_problems/ChemEquil_ionizedGas/output_blessed.txt +++ b/test_problems/ChemEquil_ionizedGas/output_blessed.txt @@ -322,7 +322,7 @@ Initial T = 414.143, pres = 1.17767e-06 atm NO 5.58575e-12 5.80828e-12 -38.5785 NO+ 4.52092e-104 4.70095e-104 12.1169 Electron 4.52092e-104 8.53846e-109 -254.253 - N+ 8.08849e-210 3.92595e-210 32.1429 + N+ 8.0885e-210 3.92595e-210 32.1429 O+ 3.41902e-171 1.8956e-171 30.6695 N2+ 6.99476e-169 6.79029e-169 13.5903 O2+ 3.64494e-127 4.04179e-127 10.6435 @@ -355,7 +355,7 @@ Initial T = 414.143, pres = 1.17767e-05 atm NO 5.58575e-12 5.80828e-12 -36.2759 NO+ 2.7933e-104 2.90453e-104 13.938 Electron 2.7933e-104 5.27558e-109 -252.432 - N+ 1.58037e-210 7.67069e-211 32.8127 + N+ 1.58037e-210 7.6707e-211 32.8127 O+ 6.68024e-172 3.70371e-172 31.3393 N2+ 4.32179e-169 4.19545e-169 15.4114 O2+ 2.25207e-127 2.49726e-127 12.4646 @@ -424,7 +424,7 @@ Initial T = 414.143, pres = 0.00117767 atm N+ 6.03308e-212 2.9283e-212 34.1523 O+ 2.55019e-173 1.4139e-173 32.6789 N2+ 1.64985e-169 1.60162e-169 19.0536 - O2+ 8.5973e-128 9.53333e-128 16.1068 + O2+ 8.5973e-128 9.53334e-128 16.1068 Final T = 414.143, pres = 0.00117767 atm Initial T = 414.143, pres = 0.0117767 atm @@ -457,7 +457,7 @@ Initial T = 414.143, pres = 0.0117767 atm N+ 1.17877e-212 5.72145e-213 34.8221 O+ 4.98269e-174 2.76254e-174 33.3487 N2+ 1.01938e-169 9.89578e-170 20.8747 - O2+ 5.31193e-128 5.89027e-128 17.9279 + O2+ 5.31194e-128 5.89027e-128 17.9279 Final T = 414.143, pres = 0.0117767 atm Initial T = 1153.16, pres = 3.27918e-08 atm @@ -485,10 +485,10 @@ Initial T = 1153.16, pres = 3.27918e-08 atm N 2.86312e-15 1.38975e-15 -21.3563 O 2.23425e-05 1.23879e-05 -22.8775 NO 0.000134494 0.000139854 -44.2338 - NO+ 9.19995e-24 9.56641e-24 7.08807 - Electron 9.19995e-24 1.73757e-28 -74.3227 - N+ 1.62751e-56 7.89959e-57 29.9656 - O+ 3.109e-43 1.72373e-43 28.4444 + NO+ 9.19996e-24 9.56642e-24 7.08807 + Electron 9.19996e-24 1.73757e-28 -74.3227 + N+ 1.62751e-56 7.8996e-57 29.9656 + O+ 3.109e-43 1.72374e-43 28.4444 N2+ 1.23423e-46 1.19817e-46 8.60924 O2+ 3.28303e-32 3.64051e-32 5.5669 @@ -523,7 +523,7 @@ Initial T = 1152.46, pres = 3.27723e-07 atm N+ 1.39651e-56 6.7783e-57 32.0898 O+ 2.65657e-43 1.47288e-43 30.5686 N2+ 3.33238e-46 3.23497e-46 11.8846 - O2+ 8.8243e-32 9.78508e-32 8.8423 + O2+ 8.8243e-32 9.78509e-32 8.8423 Final T = 1152.61, pres = 3.27763e-07 atm Initial T = 1152.61, pres = 3.27763e-06 atm @@ -551,11 +551,11 @@ Initial T = 1152.61, pres = 3.27763e-06 atm N 2.88709e-16 1.40138e-16 -19.0539 O 2.24413e-06 1.24425e-06 -20.575 NO 0.000134716 0.000140083 -39.6289 - NO+ 6.55508e-23 6.81612e-23 13.6391 - Electron 6.55508e-23 1.23803e-27 -67.7541 + NO+ 6.55509e-23 6.81613e-23 13.6391 + Electron 6.55509e-23 1.23803e-27 -67.7541 N+ 1.17797e-56 5.71759e-57 34.2141 O+ 2.23788e-43 1.24075e-43 32.693 - N2+ 8.87483e-46 8.6154e-46 15.1603 + N2+ 8.87483e-46 8.61541e-46 15.1603 O2+ 2.34675e-31 2.60226e-31 12.1179 Final T = 1152.66, pres = 3.27775e-06 atm @@ -617,11 +617,11 @@ Initial T = 1152.67, pres = 0.000327779 atm N 2.88951e-17 1.40255e-17 -16.7513 O 2.24513e-07 1.24481e-07 -18.2725 NO 0.000134738 0.000140106 -35.0238 - NO+ 4.59472e-22 4.77768e-22 20.1897 + NO+ 4.59472e-22 4.77769e-22 20.1897 Electron 4.59472e-22 8.67784e-27 -61.2017 - N+ 8.26992e-57 4.014e-57 38.4622 - O+ 1.57022e-43 8.70576e-44 36.941 - N2+ 6.22643e-45 6.04441e-45 21.7109 + N+ 8.26992e-57 4.01401e-57 38.4622 + O+ 1.57022e-43 8.70577e-44 36.941 + N2+ 6.22643e-45 6.04442e-45 21.7109 O2+ 1.64546e-30 1.82461e-30 18.6686 Final T = 1152.68, pres = 0.00032778 atm diff --git a/test_problems/ChemEquil_ionizedGas/runtest b/test_problems/ChemEquil_ionizedGas/runtest index 5ba6f1a8e..b69f109e8 100755 --- a/test_problems/ChemEquil_ionizedGas/runtest +++ b/test_problems/ChemEquil_ionizedGas/runtest @@ -25,7 +25,7 @@ ${CANTERA_BIN}/csvdiff -a 1.0E-19 table.csv table_blessed.csv > diff_csv.txt retnStat_csv=$? eCode=1 -if test $retnStat_csv = "1" +if test $retnStat_csv = "0" then eCode=0 echo "Successful test comparison on " $testName diff --git a/test_problems/VCSnonideal/NaCl_equil/runtest b/test_problems/VCSnonideal/NaCl_equil/runtest index 6397b25f6..489e71163 100755 --- a/test_problems/VCSnonideal/NaCl_equil/runtest +++ b/test_problems/VCSnonideal/NaCl_equil/runtest @@ -31,7 +31,7 @@ retnStat_txt=$? $BINDIR/csvdiff -a 1.0E-50 vcs_equilibrate_blessed.csv vcs_equilibrate_res.csv > diff_csv.txt retnStat_csv=$? -if test $retnStat_csv = "1" +if test $retnStat_csv = "0" then echo "Successful test comparison on "`pwd` if [ $retnStat_txt != "0" ] diff --git a/test_problems/VCSnonideal/NaCl_equil/runtestd b/test_problems/VCSnonideal/NaCl_equil/runtestd index b8b7da443..453ec1d11 100755 --- a/test_problems/VCSnonideal/NaCl_equil/runtestd +++ b/test_problems/VCSnonideal/NaCl_equil/runtestd @@ -42,7 +42,7 @@ retnStat_txt=$? $BINDIR/csvdiff -a 1.0E-50 vcs_equilibrate_blessed.csv vcs_equilibrate_res.csv > diff_csv.txt retnStat_csv=$? -if test $retnStat_csv = "1" +if test $retnStat_csv = "0" then echo "Successful test comparison on "`pwd` if [ $retnStat_txt != "0" ] diff --git a/test_problems/cxx_ex/runtest b/test_problems/cxx_ex/runtest index 31337b945..e7245a895 100755 --- a/test_problems/cxx_ex/runtest +++ b/test_problems/cxx_ex/runtest @@ -36,7 +36,7 @@ machType=`../../bin/get_arch` $CANTERA_BIN/csvdiff eq1.csv eq1_blessed.csv > eq1_test.out retnStat=$? -if [ $retnStat = "1" ] +if [ $retnStat = "0" ] then echo "successful csv comparison on eq1 test" else @@ -57,7 +57,7 @@ fi $CANTERA_BIN/csvdiff tr1.csv tr1_blessed.csv > tr1_test.out retnStat=$? -if [ $retnStat = "1" ] +if [ $retnStat = "0" ] then echo "successful csv comparison on tr1 test" if [ $temp_success = "1" ] @@ -82,7 +82,7 @@ fi $CANTERA_BIN/csvdiff tr2.csv tr2_blessed.csv > tr2_test.out retnStat=$? -if [ $retnStat = "1" ] +if [ $retnStat = "0" ] then echo "successful csv comparison on tr2 test" if [ $temp_success = "1" ] @@ -116,7 +116,7 @@ fi $CANTERA_BIN/csvdiff -r 3.0E-3 kin1.csv kin1_blessed_tmp.csv > kin1_test.out retnStat=$? -if [ $retnStat = "1" ] +if [ $retnStat = "0" ] then echo "successful csv comparison on kin1 test" if [ $temp_success = "1" ] @@ -150,7 +150,7 @@ fi $CANTERA_BIN/csvdiff kin2.csv kin2_blessed_tmp.csv > kin2_test.out retnStat=$? -if [ $retnStat = "1" ] +if [ $retnStat = "0" ] then echo "successful csv comparison on kin2 test" if [ $temp_success = "1" ] diff --git a/test_problems/python/flame1/output_blessed.txt b/test_problems/python/flame1/output_blessed.txt index 4980f4802..57e085ca2 100644 --- a/test_problems/python/flame1/output_blessed.txt +++ b/test_problems/python/flame1/output_blessed.txt @@ -116,7 +116,17 @@ Problem solved on [13] point grid(s). ############################################################################## Refining grid in flame. - New points inserted after grid points 0 1 + New points inserted after grid points 0 + to resolve H2O2 HO2 +.............................................................................. + +Attempt Newton solution of steady-state problem... success. + +Problem solved on [14] point grid(s). + +############################################################################## +Refining grid in flame. + New points inserted after grid points 0 to resolve H2O2 HO2 .............................................................................. @@ -127,7 +137,62 @@ Problem solved on [15] point grid(s). ############################################################################## Refining grid in flame. New points inserted after grid points 0 - to resolve H2O2 HO2 + to resolve HO2 +.............................................................................. + +Attempt Newton solution of steady-state problem... success. + +Problem solved on [16] point grid(s). + +no new points needed in flame +.............................................................................. + +Attempt Newton solution of steady-state problem... failure. + +.............................................................................. +Take 1 timesteps 7.5e-06 5.055 +.............................................................................. + +Attempt Newton solution of steady-state problem... failure. + +.............................................................................. +Take 2 timesteps 8.438e-06 5.05 +.............................................................................. + +Attempt Newton solution of steady-state problem... failure. + +.............................................................................. +Take 5 timesteps 3.204e-05 5.045 +.............................................................................. + +Attempt Newton solution of steady-state problem... failure. + +.............................................................................. +Take 10 timesteps 0.0002309 4.993 +.............................................................................. + +Attempt Newton solution of steady-state problem... failure. + +.............................................................................. +Take 10 timesteps 0.0008323 4.76 +.............................................................................. + +Attempt Newton solution of steady-state problem... failure. + +.............................................................................. +Take 10 timesteps 0.0007499 4.434 +.............................................................................. + +Attempt Newton solution of steady-state problem... failure. + +.............................................................................. +Take 10 timesteps 0.002703 4.143 +.............................................................................. + +Attempt Newton solution of steady-state problem... failure. + +.............................................................................. +Take 10 timesteps 0.002435 3.937 .............................................................................. Attempt Newton solution of steady-state problem... success. @@ -136,107 +201,48 @@ Problem solved on [16] point grid(s). ############################################################################## Refining grid in flame. - New points inserted after grid points 0 - to resolve HO2 -.............................................................................. - -Attempt Newton solution of steady-state problem... success. - -Problem solved on [17] point grid(s). - -no new points needed in flame -.............................................................................. - -Attempt Newton solution of steady-state problem... failure. - -.............................................................................. -Take 1 timesteps 7.5e-06 5.054 -.............................................................................. - -Attempt Newton solution of steady-state problem... failure. - -.............................................................................. -Take 2 timesteps 8.438e-06 5.049 -.............................................................................. - -Attempt Newton solution of steady-state problem... failure. - -.............................................................................. -Take 5 timesteps 3.204e-05 5.044 -.............................................................................. - -Attempt Newton solution of steady-state problem... failure. - -.............................................................................. -Take 10 timesteps 0.0002309 4.991 -.............................................................................. - -Attempt Newton solution of steady-state problem... failure. - -.............................................................................. -Take 10 timesteps 0.0008323 4.751 -.............................................................................. - -Attempt Newton solution of steady-state problem... failure. - -.............................................................................. -Take 10 timesteps 0.0015 4.747 -.............................................................................. - -Attempt Newton solution of steady-state problem... failure. - -.............................................................................. -Take 10 timesteps 0.001351 4.316 -.............................................................................. - -Attempt Newton solution of steady-state problem... success. - -Problem solved on [17] point grid(s). - -############################################################################## -Refining grid in flame. - New points inserted after grid points 0 1 2 3 4 5 6 7 8 9 10 11 12 13 + New points inserted after grid points 0 1 2 3 4 5 6 7 8 9 10 11 12 to resolve H H2 H2O H2O2 HO2 O O2 OH T u .............................................................................. Attempt Newton solution of steady-state problem... success. -Problem solved on [31] point grid(s). +Problem solved on [29] point grid(s). ############################################################################## Refining grid in flame. - New points inserted after grid points 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 22 23 26 27 + New points inserted after grid points 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 20 21 24 25 to resolve H H2 H2O H2O2 HO2 O O2 OH T u .............................................................................. Attempt Newton solution of steady-state problem... success. -Problem solved on [54] point grid(s). +Problem solved on [50] point grid(s). ############################################################################## Refining grid in flame. - New points inserted after grid points 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 47 + New points inserted after grid points 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 43 to resolve H H2 H2O H2O2 HO2 O O2 OH T u .............................................................................. Attempt Newton solution of steady-state problem... success. -Problem solved on [74] point grid(s). +Problem solved on [71] point grid(s). ############################################################################## Refining grid in flame. - New points inserted after grid points 0 1 2 3 5 6 7 8 9 10 11 12 13 14 16 17 24 25 26 27 28 29 30 31 32 33 - to resolve H H2 H2O H2O2 HO2 O O2 + New points inserted after grid points 0 1 2 3 5 6 7 8 9 10 11 12 13 14 16 17 24 25 26 27 28 29 30 31 32 33 34 + to resolve H H2 H2O H2O2 HO2 O O2 OH .............................................................................. Attempt Newton solution of steady-state problem... success. -Problem solved on [100] point grid(s). +Problem solved on [98] point grid(s). ############################################################################## Refining grid in flame. - New points inserted after grid points 0 1 2 - to resolve H2O2 HO2 + New points inserted after grid points 0 1 2 56 57 + to resolve H2O2 HO2 O .............................................................................. Attempt Newton solution of steady-state problem... success. diff --git a/test_problems/python/flame1/runtest b/test_problems/python/flame1/runtest index 3b635d12d..6dbc682f7 100755 --- a/test_problems/python/flame1/runtest +++ b/test_problems/python/flame1/runtest @@ -67,7 +67,7 @@ retnStat_txt=$? $BINDIR/csvdiff -a 1.0E-10 flame1_blessed.csv flame1.csv > diff_csv.txt retnStat_csv=$? -if test $retnStat_csv = "1" +if test $retnStat_csv = "0" then echo " Successful test comparison on "`pwd` if [ $retnStat_txt != "0" ] @@ -76,7 +76,7 @@ then fi else echo " Unsuccessful test comparison on "`pwd` " test" - if test $retnStat_csv != "1" + if test $retnStat_csv != "0" then echo " csv files are different - see diff_csv.txt" fi diff --git a/test_problems/python/runtest b/test_problems/python/runtest index 9d9286ded..0551c28f6 100755 --- a/test_problems/python/runtest +++ b/test_problems/python/runtest @@ -68,9 +68,9 @@ then echo "diamond.py returned with bad status, $retnStat, check output" fi -$CANTERA_BIN/csvdiff diamond.csv diamond_blessed.csv > diamond_test.out +$CANTERA_BIN/csvdiff diamond.csv diamond_blessed.csv > diamond_test_csv.out retnStat=$? -if [ $retnStat = "1" ] +if [ $retnStat = "0" ] then echo "successful csv comparison on diamond test" if [ $temp_success = "1" ] diff --git a/tools/testtools/.cvsignore b/tools/testtools/.cvsignore deleted file mode 100644 index 96db0f094..000000000 --- a/tools/testtools/.cvsignore +++ /dev/null @@ -1,4 +0,0 @@ -*.csv -.depends -Makefile -csvdiff diff --git a/tools/testtools/csvdiff.cpp b/tools/testtools/csvdiff.cpp index af25e6c32..3ea8e1183 100644 --- a/tools/testtools/csvdiff.cpp +++ b/tools/testtools/csvdiff.cpp @@ -3,9 +3,9 @@ * | CVS File Information | * ------------------------ * $RCSfile: csvdiff.cpp,v $ - * $Author: hkmoffa $ - * $Date: 2008/01/03 18:54:23 $ - * $Revision: 1.17 $ + * $Author$ + * $Date$ + * $Revision$ * $Name: $ *====================================================================*/ /* @@ -71,6 +71,11 @@ int Debug_Flag = TRUE; double grtol = 1.0E-3; double gatol = 1.0E-9; +#define RT_PASSED 0 +#define RT_FAILED_COL 1 +#define RT_FAILED_HDR 2 +#define RT_FAILED_OTHER 3 + /* * First iteration towards getting this variable */ @@ -646,7 +651,7 @@ int main(int argc, char *argv[]) int mixed_var = 0; int i, j, ndiff, jmax, i1, i2, k, found; double max_diff, rel_diff; - int testPassed = 1; + int testPassed = RT_PASSED; double atol_j, atol_arg = 0.0, rtol_arg = 0.0; /********************** BEGIN EXECUTION ************************************/ @@ -719,7 +724,7 @@ int main(int argc, char *argv[]) printf("\n"); printf("----------------------------------------------------------\n"); printf("csvdiff: CSVFile comparison utility program\n"); - printf(" Version $Revision: 1.17 $\n"); + printf(" Version $Revision$\n"); printf(" Harry K. Moffat Div. 9114 Sandia National Labs\n"); printf(" \n"); printf(" First CSV File = %s\n", fileName1); @@ -751,37 +756,37 @@ int main(int argc, char *argv[]) get_sizes(fp1, nTitleLines1, nColTitleLines1, nCol1, nDataRows1, &ColIsFloat1); if (nCol1 == 0) { printf("Number of columns in file %s is zero\n", fileName1); - testPassed = -1; - exit (-1); + testPassed = RT_FAILED_OTHER; + exit(RT_FAILED_OTHER); } if (nDataRows1 == 0) { printf("Number of data rows in file %s is zero\n", fileName1); - testPassed = -1; - exit (-1); + testPassed = RT_FAILED_OTHER; + exit(RT_FAILED_OTHER); } get_sizes(fp2, nTitleLines2, nColTitleLines2, nCol2, nDataRows2, &ColIsFloat2); if (nCol2 == 0) { printf("Number of columns in file %s is zero\n", fileName2); - testPassed = -1; - exit (-1); + testPassed = RT_FAILED_OTHER; + exit(RT_FAILED_OTHER); } if (nDataRows2 == 0) { printf("Number of data rows in file %s is zero\n", fileName2); - testPassed = -1; - exit (-1); + testPassed = RT_FAILED_OTHER; + exit(RT_FAILED_OTHER); } if (nTitleLines1 != nTitleLines2) { - printf("Number o Title Lines differ:, %d %d\n",nTitleLines1, nTitleLines2); - testPassed = 0; + printf("Number of Title Lines differ:, %d %d\n",nTitleLines1, nTitleLines2); + testPassed = RT_FAILED_OTHER; } else if (Debug_Flag) { printf("Number of Title Lines in each file = %d\n", nTitleLines1); } if (nColTitleLines1 != nColTitleLines2) { printf("Number of Column title lines differ:, %d %d\n", nColTitleLines1, nColTitleLines2); - testPassed = 0; + testPassed = RT_FAILED_OTHER; } else if (Debug_Flag) { printf("Number of column title lines in each file = %d\n", nColTitleLines1); } @@ -809,27 +814,27 @@ int main(int argc, char *argv[]) for (i = 0; i < n; i++) { if (strcmp(title1[i], title2[i]) != 0) { printf("Title Line %d differ:\n\t\"%s\"\n\t\"%s\"\n", i, title1[i], title2[i]); - testPassed = 0; + testPassed = RT_FAILED_HDR; } else if (Debug_Flag) { printf("Title Line %d for each file: \"%s\"\n", i, title1[i]); } } if (nTitleLines1 != nTitleLines2) { printf("Number of Title Lines differ: %d %d\n", nTitleLines1, nTitleLines2); - testPassed = -1; + testPassed = RT_FAILED_HDR;; } } else { if (nTitleLines1 != nTitleLines2) { if (nTitleLines1) { printf("Titles differ: title for first file: \"%s\"\n", title1[0]); - testPassed = 0; + testPassed = RT_FAILED_HDR; } if (nTitleLines2) { printf("Titles differ: title for second file: \"%s\"\n", title2[0]); } - testPassed = -1; + testPassed = RT_FAILED_HDR; } } @@ -842,7 +847,7 @@ int main(int argc, char *argv[]) printf("Number of column variables differ:, %d %d\n", nCol1, nCol2); mixed_var = TRUE; - testPassed = 0; + testPassed = RT_FAILED_OTHER; } else if (Debug_Flag) { printf("Number of column variables in both files = %d\n", nCol1); @@ -879,7 +884,7 @@ int main(int argc, char *argv[]) if (!found) { printf("csvdiff WARNING Variable %s (%d) in first file not found" " in second file\n", ColNames1[i], i); - testPassed = 0; + testPassed = RT_FAILED_OTHER; } } for (j = 0; j < nCol2; j++) { @@ -891,7 +896,7 @@ int main(int argc, char *argv[]) printf("csvdiff WARNING Variable %s (%d) in second file " "not found in first file\n", ColNames2[j], j); - testPassed = 0; + testPassed = RT_FAILED_OTHER; } } @@ -1024,7 +1029,7 @@ int main(int argc, char *argv[]) printf(" Largest difference was at data row %d ", jmax + 1); printf(": %g %g\n", curVarValues1[jmax], curVarValues2[jmax]); } - testPassed = 0; + testPassed = RT_FAILED_COL; } else if (Debug_Flag) { printf("Column variable %s passed\n", ColNames1[i1]); } diff --git a/tools/testtools/mdp_allo.cpp b/tools/testtools/mdp_allo.cpp index 9dd00d61e..4c60e2d7b 100644 --- a/tools/testtools/mdp_allo.cpp +++ b/tools/testtools/mdp_allo.cpp @@ -1,9 +1,9 @@ /* ****************************************************************************** * $RCSfile: mdp_allo.cpp,v $ -* $Author: hkmoffa $ -* $Date: 2009/04/19 02:31:12 $ -* $Revision: 1.6 $ +* $Author$ +* $Date$ +* $Revision$ * $Name: $ ****************************************************************************** */ diff --git a/tools/testtools/mdp_allo.h b/tools/testtools/mdp_allo.h index 1132ea571..cdf23dd11 100644 --- a/tools/testtools/mdp_allo.h +++ b/tools/testtools/mdp_allo.h @@ -5,11 +5,11 @@ * * $RCSfile: mdp_allo.h,v $ * - * $Author: hkmoffa $ + * $Author$ * - * $Date: 2007/03/26 21:53:45 $ + * $Date$ * - * $Revision: 1.3 $ + * $Revision$ * * $Name: $ *====================================================================*/ diff --git a/tools/testtools/tok_input_util.cpp b/tools/testtools/tok_input_util.cpp index 406f1519b..c481a2c29 100644 --- a/tools/testtools/tok_input_util.cpp +++ b/tools/testtools/tok_input_util.cpp @@ -5,14 +5,14 @@ * * $RCSfile: tok_input_util.cpp,v $ * - * $Author: hkmoffa $ + * $Author$ * - * $Date: 2009/03/28 03:07:23 $ + * $Date$ * - * $Revision: 1.2 $ + * $Revision$ * Symbolic $Name: $ * - * $Id: tok_input_util.cpp,v 1.2 2009/03/28 03:07:23 hkmoffa Exp $ + * $Id$ * $Source: /cvsroot/cantera/cantera/tools/testtools/tok_input_util.cpp,v $ * *====================================================================*/ diff --git a/tools/testtools/tok_input_util.h b/tools/testtools/tok_input_util.h index 07f7662e5..32ff823b3 100644 --- a/tools/testtools/tok_input_util.h +++ b/tools/testtools/tok_input_util.h @@ -5,14 +5,14 @@ * * $RCSfile: tok_input_util.h,v $ * - * $Author: dggoodwin $ + * $Author$ * - * $Date: 2003/04/14 17:58:00 $ + * $Date$ * - * $Revision: 1.1.1.1 $ + * $Revision$ * Symbolic $Name: $ * - * $Id: tok_input_util.h,v 1.1.1.1 2003/04/14 17:58:00 dggoodwin Exp $ + * $Id$ * $Source: /cvsroot/cantera/cantera/tools/testtools/tok_input_util.h,v $ * * From 1e77c40db04251136bcae744c62c12469a9bdf08 Mon Sep 17 00:00:00 2001 From: Harry Moffat Date: Fri, 2 Apr 2010 19:44:08 +0000 Subject: [PATCH 10/26] Small changes --- test_problems/cathermo/wtWater/Makefile.in | 1 - 1 file changed, 1 deletion(-) diff --git a/test_problems/cathermo/wtWater/Makefile.in b/test_problems/cathermo/wtWater/Makefile.in index a34cc1ce2..a8156e502 100755 --- a/test_problems/cathermo/wtWater/Makefile.in +++ b/test_problems/cathermo/wtWater/Makefile.in @@ -101,7 +101,6 @@ endif clean: $(RM) $(OBJS) $(PROGRAM) $(DEPENDS) .depends - ../../../bin/rm_cvsignore (if test -d SunWS_cache ; then \ $(RM) -rf SunWS_cache ; \ fi ) From df275cdddf8bbc218b8ea722063d59610cd41656 Mon Sep 17 00:00:00 2001 From: Harry Moffat Date: Fri, 2 Apr 2010 20:20:12 +0000 Subject: [PATCH 11/26] Added another example of a linux build --- .../linux_64_gcc424_dbg_python264_numpy | 112 ++++++++++++++++++ 1 file changed, 112 insertions(+) create mode 100755 docs/install_examples/linux_64_gcc424_dbg_python264_numpy diff --git a/docs/install_examples/linux_64_gcc424_dbg_python264_numpy b/docs/install_examples/linux_64_gcc424_dbg_python264_numpy new file mode 100755 index 000000000..d5e2effa5 --- /dev/null +++ b/docs/install_examples/linux_64_gcc424_dbg_python264_numpy @@ -0,0 +1,112 @@ +#!/bin/sh +# +# This is currently the test base. Meaning that the blessed versions +# of all test problems are created from this configuration. +# +CANTERA_CONFIG_PREFIX=${HOME}/arch/linux64_gcc424/cantera-1.8_Develop +export CANTERA_CONFIG_PREFIX + +SET_PYTHON_SITE_PACKAGE_TOPDIR=y +export SET_PYTHON_SITE_PACKAGE_TOPDIR + +PYTHON_SITE_PACKAGE_TOPDIR=$CANTERA_CONFIG_PREFIX +export PYTHON_SITE_PACKAGE_TOPDIR + +PYTHON_CMD=${HOME}/arch/linux64_gcc424/python-2.6.4/bin/python +export PYTHON_CMD + +PYTHON_PACKAGE='full' +#PYTHON_PACKAGE='minimal' +export PYTHON_PACKAGE + +DEBUG_MODE='y' +export DEBUG_MODE + +WITH_IDEAL_SOLUTIONS="y" +export WITH_IDEAL_SOLUTIONS + +WITH_ELECTROLYTES="y" +export WITH_ELECTROLYTES + +WITH_VCSNONIDEAL="y" +export WITH_VCSNONIDEAL + +WITH_H298MODIFY_CAPABILITY='y' +export WITH_H298MODIFY_CAPABILITY + +BUILD_MATLAB_TOOLBOX="y" +export BUILD_MATLAB_TOOLBOX + +INSTALL_BIN=config/install-sh +export INSTALL_BIN + +MATLAB_CMD="/usr/local/matlab/7.9/bin/matlab" +export MATLAB_CMD + +BUILD_F90_INTERFACE="y" +export BUILD_F90_INTERFACE + +NUMARRAY_HOME='' +export NUMARRAY_HOME + +USE_NUMPY='y' +export USE_NUMPY + +NUMPY_INC_DIR="${HOME}/arch/linux64_gcc424/python-2.6.4/lib/python2.6/site-packages/numpy/core/include" +export NUMPY_INC_DIR + +GRAPHVIZDIR=${HOME}'/arch/linux/bin' +export GRAPHVIZDIR + +# +# +USE_NUMERIC="n" +export USE_NUMERIC + +BUILD_WITH_F2C="n" +export BUILD_WITH_F2C + +BITCOMPILE="64" +export BITCOMPILE + +AFLAGS='DEBUG' + +CXX='/sierra/Sntools/extras/compilers/gcc-4.2.4/bin/g++' +export CXX + +CXX_DEPENDS='/sierra/Sntools/extras/compilers/gcc-4.2.4/bin/g++ -MM' +export CXX_DEPENDS + +CC='/sierra/Sntools/extras/compilers/gcc-4.2.4/bin/gcc' +export CC + +F77='/sierra/Sntools/extras/compilers/gcc-4.2.4/bin/gfortran' +export F77 + +CFLAGS="-g -Wall" +export CFLAGS + +CXXFLAGS="-g -Wall -Woverloaded-virtual -DDEBUG_HKM -DDEBUG_HKM_EPEQUIL" +export CXXFLAGS + +FFLAGS="-g -DDEBUG_HKM -fno-second-underscore" +export FFLAGS + +LDFLAGS=' ' +export LDFLAGS + +LCXX_END_LIBS="-lgfortran " +export LCXX_END_LIBS + +EXTRA_LINK=" " +export EXTRA_LINK + +MAKE=gmake +export MAKE + +USE_SUNDIALS='y' +export USE_SUNDIALS +SUNDIALS_HOME='${HOME}/arch/linux64_gcc424/sundials-2.4.0_dbg' +export SUNDIALS_HOME + +./preconfig From 350988be3732f8fd8c8a438c2d8d22666cb8b74f Mon Sep 17 00:00:00 2001 From: Harry Moffat Date: Wed, 21 Apr 2010 18:05:44 +0000 Subject: [PATCH 12/26] Changed the format of the xml file so that you only need 2 of the 3 fields: DG0, DH0, and S0. The third field is calculated consistently wrt the first two fields. --- Cantera/src/thermo/PDSS_HKFT.cpp | 74 ++++++++++++++++++++++++-------- 1 file changed, 55 insertions(+), 19 deletions(-) diff --git a/Cantera/src/thermo/PDSS_HKFT.cpp b/Cantera/src/thermo/PDSS_HKFT.cpp index f09c28b51..1ba20f27f 100644 --- a/Cantera/src/thermo/PDSS_HKFT.cpp +++ b/Cantera/src/thermo/PDSS_HKFT.cpp @@ -621,10 +621,10 @@ namespace Cantera { void PDSS_HKFT::constructPDSSXML(VPStandardStateTP *tp, int spindex, const XML_Node& speciesNode, const XML_Node& phaseNode, bool spInstalled) { - //PDSS::initThermo(); - - // m_p0 = OneAtm; - + int hasDGO = 0; + int hasSO = 0; + int hasDHO = 0; + if (!spInstalled) { throw CanteraError("PDSS_HKFT::constructPDSSXML", "spInstalled false not handled"); } @@ -666,22 +666,25 @@ namespace Cantera { if (hh->hasChild("DG0_f_Pr_Tr")) { doublereal val = getFloat(*hh, "DG0_f_Pr_Tr"); m_deltaG_formation_tr_pr = val; + hasDGO = 1; } else { - throw CanteraError("PDSS_HKFT::constructPDSSXML", " missing DG0_f_Pr_Tr field"); + // throw CanteraError("PDSS_HKFT::constructPDSSXML", " missing DG0_f_Pr_Tr field"); } if (hh->hasChild("DH0_f_Pr_Tr")) { doublereal val = getFloat(*hh, "DH0_f_Pr_Tr"); m_deltaH_formation_tr_pr = val; + hasDHO = 1; } else { - throw CanteraError("PDSS_HKFT::constructPDSSXML", " missing DH0_f_Pr_Tr field"); + // throw CanteraError("PDSS_HKFT::constructPDSSXML", " missing DH0_f_Pr_Tr field"); } if (hh->hasChild("S0_Pr_Tr")) { doublereal val = getFloat(*hh, "S0_Pr_Tr"); m_Entrop_tr_pr= val; + hasSO = 1; } else { - throw CanteraError("PDSS_HKFT::constructPDSSXML", " missing S0_Pr_Tr field"); + // throw CanteraError("PDSS_HKFT::constructPDSSXML", " missing S0_Pr_Tr field"); } const XML_Node *ss = speciesNode.findByName("standardState"); @@ -720,24 +723,57 @@ namespace Cantera { throw CanteraError("PDSS_HKFT::constructPDSSXML", " missing a4 field"); } - if (ss->hasChild("c1")) { + if (ss->hasChild("c1")) { doublereal val = getFloat(*ss, "c1"); m_c1 = val; - } else { - throw CanteraError("PDSS_HKFT::constructPDSSXML", " missing c1 field"); - } - if (ss->hasChild("c2")) { + } else { + throw CanteraError("PDSS_HKFT::constructPDSSXML", " missing c1 field"); + } + if (ss->hasChild("c2")) { doublereal val = getFloat(*ss, "c2"); m_c2 = val; - } else { - throw CanteraError("PDSS_HKFT::constructPDSSXML", " missing c2 field"); - } - if (ss->hasChild("omega_Pr_Tr")) { + } else { + throw CanteraError("PDSS_HKFT::constructPDSSXML", " missing c2 field"); + } + if (ss->hasChild("omega_Pr_Tr")) { doublereal val = getFloat(*ss, "omega_Pr_Tr"); m_omega_pr_tr = val; - } else { - throw CanteraError("PDSS_HKFT::constructPDSSXML", " missing omega_Pr_Tr field"); - } + } else { + throw CanteraError("PDSS_HKFT::constructPDSSXML", " missing omega_Pr_Tr field"); + } + + + int isum = hasDGO + hasDHO + hasSO; + if (isum < 2) { + throw CanteraError("PDSS_HKFT::constructPDSSXML", + "Missing 2 or more of DG0_f_Pr_Tr, DH0_f_Pr_Tr, or S0_f_Pr_Tr fields. " + "Need to supply at least two of these fields"); + } + // Ok, if we are missing one, then we construct its value from the other two. + // This code has been internally verified. + if (hasDHO == 0) { + m_charge_j = m_tp->charge(m_spindex); + convertDGFormation(); + doublereal Hcalc = m_Mu0_tr_pr + 298.15 * (m_Entrop_tr_pr * 1.0E3 * 4.184); + m_deltaH_formation_tr_pr = Hcalc / (1.0E3 * 4.184); + } + if (hasDGO == 0) { + doublereal DHjmol = m_deltaH_formation_tr_pr * 1.0E3 * 4.184; + m_Mu0_tr_pr = DHjmol - 298.15 * (m_Entrop_tr_pr * 1.0E3 * 4.184); + m_deltaG_formation_tr_pr = m_Mu0_tr_pr / (1.0E3 * 4.184); + double tmp = m_Mu0_tr_pr; + m_charge_j = m_tp->charge(m_spindex); + convertDGFormation(); + double totalSum = m_Mu0_tr_pr - tmp; + m_Mu0_tr_pr = tmp; + m_deltaG_formation_tr_pr = (m_Mu0_tr_pr - totalSum)/ (1.0E3 * 4.184); + } + if (hasSO == 0) { + m_charge_j = m_tp->charge(m_spindex); + convertDGFormation(); + doublereal DHjmol = m_deltaH_formation_tr_pr * 1.0E3 * 4.184; + m_Entrop_tr_pr = (DHjmol - m_Mu0_tr_pr) / (298.15 * 1.0E3 * 4.184); + } } From db3de591af55d7b7f1a3e2fd3edb1fac930203c0 Mon Sep 17 00:00:00 2001 From: Harry Moffat Date: Fri, 7 May 2010 14:41:34 +0000 Subject: [PATCH 13/26] Added comments. Added deprecated symbol for array_fp --- Cantera/src/base/ct_defs.h | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/Cantera/src/base/ct_defs.h b/Cantera/src/base/ct_defs.h index c394cadb7..1930ba377 100644 --- a/Cantera/src/base/ct_defs.h +++ b/Cantera/src/base/ct_defs.h @@ -76,21 +76,30 @@ namespace Cantera { */ //@{ - /// Avogadro's Number - const doublereal Avogadro = 6.02214179e26; // /kmol + //! Avogadro's Number + /*! + * Units are number/kmol + */ + const doublereal Avogadro = 6.02214179e26; /// Universal Gas Constant. 2006 CODATA value. const doublereal GasConstant = 8314.47215; // J/kmol/K const doublereal logGasConstant = 9.025752908; - /// One atmosphere - const doublereal OneAtm = 1.01325e5; // Pa + //! One atmosphere + /*! + * Units are Pa + */ + const doublereal OneAtm = 1.01325e5; - /// Universal gas constant in cal/mol/K + //! Universal gas constant in cal/mol/K const doublereal GasConst_cal_mol_K = 1.987; - /// Boltzmann's constant + //! Boltzmann's constant + /*! + * Units are J/K + */ const doublereal Boltzmann = GasConstant / Avogadro; /// Planck's constant. Units of J-s @@ -191,6 +200,9 @@ namespace Cantera { #define USE_STL_VECTOR #ifdef USE_STL_VECTOR //! Vector of doubles. + /*! + * @deprecated array_fp is going away, because vector_fp means the same thing + */ typedef std::vector array_fp; //! Vector of doubles. typedef std::vector vector_fp; From 74b1c3c0a177fbed0c1f1d673e2a174974650b33 Mon Sep 17 00:00:00 2001 From: Harry Moffat Date: Fri, 7 May 2010 14:44:05 +0000 Subject: [PATCH 14/26] Added more constructor inits --- Cantera/src/base/ctml.cpp | 5 ++++- Cantera/src/base/xml.cpp | 6 ++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/Cantera/src/base/ctml.cpp b/Cantera/src/base/ctml.cpp index 8de42e90f..f287ed95f 100644 --- a/Cantera/src/base/ctml.cpp +++ b/Cantera/src/base/ctml.cpp @@ -363,7 +363,9 @@ namespace ctml { const std::string typeString) { XML_Node& f = node.addChild("string", valueString); f.addAttribute("title", titleString); - if (typeString != "") f.addAttribute("type", typeString); + if (typeString != "") { + f.addAttribute("type", typeString); + } } XML_Node* getByTitle(const Cantera::XML_Node& node, const std::string &title) { @@ -633,6 +635,7 @@ namespace ctml { return getFloatCurrent(node, type); } + doublereal getFloatCurrent(const Cantera::XML_Node& node, const std::string type) { doublereal x, x0, x1, fctr = 1.0; diff --git a/Cantera/src/base/xml.cpp b/Cantera/src/base/xml.cpp index 3f3912ede..927f36a04 100644 --- a/Cantera/src/base/xml.cpp +++ b/Cantera/src/base/xml.cpp @@ -51,7 +51,8 @@ namespace Cantera { * @param line Number number where the error occurred. */ XML_Error(int line=0) : - m_line(line) + m_line(line), + m_msg(0) { m_msg = "Error in XML file"; if (line > 0) { @@ -392,7 +393,8 @@ namespace Cantera { ////////////////////////// XML_Node ///////////////////////////////// XML_Node::XML_Node(const char * cnm) - : m_value(""), + : m_name(""), + m_value(""), m_parent(0), m_locked(false), m_nchildren(0), From 33a21f76ac6462b401ee8f5c0240b8eaaf46f4d7 Mon Sep 17 00:00:00 2001 From: Harry Moffat Date: Fri, 7 May 2010 14:44:46 +0000 Subject: [PATCH 15/26] Added more constructor inits. --- Cantera/src/base/Array.h | 15 +++++++++++---- Cantera/src/base/mdp_allo.cpp | 2 +- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/Cantera/src/base/Array.h b/Cantera/src/base/Array.h index 22c508748..bde5f28c6 100644 --- a/Cantera/src/base/Array.h +++ b/Cantera/src/base/Array.h @@ -56,8 +56,11 @@ namespace Cantera { /** * Default constructor. Create an empty array. */ - Array2D() : m_nrows(0), m_ncols(0) { - m_data.clear(); + Array2D() : + m_data(0), + m_nrows(0), + m_ncols(0) + { } //! Constructor. @@ -70,7 +73,7 @@ namespace Cantera { * @param v Default fill value. The default is 0.0 */ Array2D(const int m, const int n, const doublereal v = 0.0) - : m_nrows(m), m_ncols(n) { + : m_data(0), m_nrows(m), m_ncols(n) { m_data.resize(n*m); std::fill(m_data.begin(), m_data.end(), v); } @@ -79,7 +82,11 @@ namespace Cantera { /*! * @param y Array2D to make the copy from */ - Array2D(const Array2D& y) { + Array2D(const Array2D& y) : + m_data(0), + m_nrows(0), + m_ncols(0) + { m_nrows = y.m_nrows; m_ncols = y.m_ncols; m_data.resize(m_nrows*m_ncols); diff --git a/Cantera/src/base/mdp_allo.cpp b/Cantera/src/base/mdp_allo.cpp index 1d9f90e3f..d650ed919 100644 --- a/Cantera/src/base/mdp_allo.cpp +++ b/Cantera/src/base/mdp_allo.cpp @@ -1458,7 +1458,7 @@ namespace mdp { * * mdp_copy_dbl_1: * - * Copies one Double vector into another double vector + * Copies one contiguous double vector into another double vector * * Input * ------------- From 3d64fae63c5c4ecaf607280a8a77a653754bb971 Mon Sep 17 00:00:00 2001 From: Harry Moffat Date: Fri, 7 May 2010 14:45:32 +0000 Subject: [PATCH 16/26] Added a deepStdVectorPointerCopy templated routine. Allows for deep copies of --- Cantera/src/base/utilities.h | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/Cantera/src/base/utilities.h b/Cantera/src/base/utilities.h index e54f87c61..19aead0a4 100644 --- a/Cantera/src/base/utilities.h +++ b/Cantera/src/base/utilities.h @@ -660,6 +660,32 @@ namespace Cantera { return (((c[3]*x + c[2])*x + c[1])*x + c[0]); } + //! Templated deep copy of a std vector of pointers + /*! + * Performs a deep copy of a std vectors of pointers to an object. This template assumes that + * that the templated object has a functioning copy constructor. + * It also assumes that pointers are zero when they are not malloced. + * + * @param fromVec Vector of pointers to a templated class. This will be + * deep-copied to the other vector + * @param toVec Vector of pointers to a templated class. This will be + * overwritten and on return will be a copy of the fromVec + */ + template + void deepStdVectorPointerCopy(const std::vector &fromVec, std::vector &toVec) { + int is = toVec.size(); + for (int i = 0; i < is; is++) { + if (toVec[i]) { + delete(toVec[i]); + } + } + is = fromVec.size(); + toVec.resize(is); + for (int i = 0; i < is; is++) { + toVec[i] = new D(*(fromVec[i])); + } + } + //@} } From 7b046ad00f0efc978200025642be22656ce2e5f7 Mon Sep 17 00:00:00 2001 From: Harry Moffat Date: Fri, 7 May 2010 14:47:03 +0000 Subject: [PATCH 17/26] Added comments. --- Cantera/src/base/misc.cpp | 69 +++++++++++++++++++++++++++++++++++---- 1 file changed, 63 insertions(+), 6 deletions(-) diff --git a/Cantera/src/base/misc.cpp b/Cantera/src/base/misc.cpp index 9d39cfc12..ba094f048 100644 --- a/Cantera/src/base/misc.cpp +++ b/Cantera/src/base/misc.cpp @@ -176,15 +176,66 @@ namespace Cantera { * constructor for the Messages class which is a subclass * of the Application class. */ - Messages() { + Messages() : + errorMessage(0), + errorRoutine(0), + logwriter(0) +#ifdef WITH_HTML_LOGS + ,xmllog(0), + current(0), + loglevel(0), + loglevels(0), + loggroups(0) +#endif + { // install a default logwriter that writes to standard // output / standard error logwriter = new Logger(); + } + + //! Copy Constructor for the Messages class + /*! + * Constructor for the Messages class which is a subclass + * of the Application class. + * @param r Message to be copied + */ + Messages(const Messages &r) : + errorMessage(r.errorMessage), + errorRoutine(r.errorRoutine), + logwriter(0) #ifdef WITH_HTML_LOGS - xmllog = 0; - current = 0; - loglevel = 0; + , xmllog(r.xmllog), + current(r.current), + loglevel(r.loglevel), + loglevels(r.loglevels), + loggroups(r.loggroups) #endif + { + // install a default logwriter that writes to standard + // output / standard error + logwriter = new Logger(*(r.logwriter)); + } + + //! Assignment operator + /*! + * @param r Message to be copied + */ + Messages & operator=(const Messages &r) + { + if (this == &r) { + return *this; + } + errorMessage = r.errorMessage; + errorRoutine = r.errorRoutine; + logwriter = new Logger(*(r.logwriter)); +#ifdef WITH_HTML_LOGS + xmllog = r.xmllog; + current = r.current; + loglevel = r.loglevel; + loglevels = r.loglevels; + loggroups = r.loggroups; +#endif + return *this; } //! Destructor for the Messages class @@ -486,8 +537,14 @@ namespace Cantera { protected: //RFB Protected ctor access thru static member function Instance //! Constructor for class sets up the initial conditions - Application() : /*linelen(0),*/ stop_on_error(false), - tmp_dir("."), m_sleep("1") + Application() : + inputDirs(0), + stop_on_error(false), + options(), + tmp_dir("."), + xmlfiles(), + m_sleep("1"), + pMessenger(0) { #if !defined( THREAD_SAFE_CANTERA ) pMessenger = std::auto_ptr(new Messages()); From 94d0d85925f31ea56c45c7df2789ded8d1744dda Mon Sep 17 00:00:00 2001 From: Harry Moffat Date: Fri, 7 May 2010 14:48:15 +0000 Subject: [PATCH 18/26] Added more units strings. Took out frequency conversion, until we reevalulate it --- Cantera/src/base/units.h | 34 ++++++++++++++++++++++++++++------ 1 file changed, 28 insertions(+), 6 deletions(-) diff --git a/Cantera/src/base/units.h b/Cantera/src/base/units.h index 6e3ac70a5..2a6a68e33 100644 --- a/Cantera/src/base/units.h +++ b/Cantera/src/base/units.h @@ -173,11 +173,15 @@ namespace Cantera { static boost::mutex units_mutex; #endif - /*! - * Units class constructor, containing the default mappings between - * strings and units. - */ - Unit(){ + //! Units class constructor, containing the default mappings between + //! strings and units. + Unit() : + m_u(), + m_act_u() + { + + // unity + m_u["1"] = 1.0; // length m_u["m"] = 1.0; @@ -197,6 +201,9 @@ namespace Cantera { m_u["kcal"] = 4184.0; m_u["eV"] = Faraday; //1.60217733e-19; + // resistance + m_u["ohm"] = 1.0; + // quantity m_u["mol"] = 1.0e-3; m_u["gmol"] = 1.0e-3; @@ -210,6 +217,7 @@ namespace Cantera { m_u["C"] = 1.0; // mass + m_u["gm"] = 1.0e-3; m_u["g"] = 1.0e-3; m_u["kg"] = 1.0; @@ -224,18 +232,32 @@ namespace Cantera { m_u["hr"] = 3600.0; m_u["ms"] = 0.001; - // frequency + /* + // frequency - Took frequency out to reevaluate it. Inverse cm is probably the wrong default unit m_u["hZ"] = 0.01/(lightSpeed); m_u["cm^-1"] = 1.0; m_u["m^-1"] = 0.1; m_u["cm-1"] = m_u["cm^-1"]; m_u["m-1"] = m_u["m^-1"]; m_u["wavenumbers"] = m_u["cm^-1"]; + */ // viscosity + m_u["Pa-s"] = 1; m_u["poise"] = 0.1; m_u["centipoise"] = 0.001; + m_u["P"] = 0.1; + m_u["cP"] = 0.001; + // volume + m_u["kL"] = 1.0; + m_u["liter"] = 0.001; + m_u["L"] = 0.001; + m_u["l"] = 0.001; + m_u["mL"] = 1.0e-6; + m_u["ml"] = 1.0e-6; + m_u["cc"] = 1.0e-6; + m_act_u["eV"] = m_u["eV"]; // /m_u["molec"]; m_act_u["K"] = GasConstant; m_act_u["Kelvin"] = GasConstant; From c292e98c8ac2d0b3d4374f52b6b4e1615054f033 Mon Sep 17 00:00:00 2001 From: Harry Moffat Date: Sat, 8 May 2010 03:04:39 +0000 Subject: [PATCH 19/26] Added various defines for Cantera's version control. --- config.h.in | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/config.h.in b/config.h.in index 9cc487cbe..52d4f7eb0 100755 --- a/config.h.in +++ b/config.h.in @@ -4,6 +4,17 @@ #ifndef CT_CONFIG_H #define CT_CONFIG_H +//---------------------------- Version Flags ------------------// +// Cantera version -> this will be a double-quoted string value +// refering to branch number within svn +#undef CANTERA_VERSION + +// Integer for major number of Cantera +#define CANTERA_VERSION_MAJORNUMBER 18 +// Flag indicating it's part of major version 18 +#define CANTERA_VERSION_18 1 +// Flag indicating it's a development version +#define CANTERA_VERSION_18_XXX 1 //------------------------ Development flags ------------------// // From eaa2875d10faf2d62a8c50959d9cffb75ac8be0f Mon Sep 17 00:00:00 2001 From: Harry Moffat Date: Sat, 8 May 2010 03:15:22 +0000 Subject: [PATCH 20/26] Two major capabilities have been merged into the main branch from liquidTransportDevelop branch The Exchange_current_reaction_ratecoeff_type method for formulating reaction rate constants for exchange current reactions has been ported into the main branch. Fixed the InterfaceKinetics object so that we can specify that a phase doesn't exist. If a phase doesn't exist, species in that phase can't be reactants in the phase. Before, this fix, they could be !?!! This was because InterfaceKinetics objects use ThermoPhase objects, which are intrinsic only. We need an extrinsic notion that is in addition to ThermoPhase info in order to get this right. --- Cantera/src/kinetics/InterfaceKinetics.cpp | 368 +++++++++++++++---- Cantera/src/kinetics/InterfaceKinetics.h | 202 +++++++++-- Cantera/src/kinetics/Kinetics.cpp | 29 +- Cantera/src/kinetics/Kinetics.h | 5 +- Cantera/src/kinetics/ReactionData.h | 14 +- Cantera/src/kinetics/ReactionStoichMgr.h | 1 + Cantera/src/kinetics/RxnRates.h | 393 +++++++++++++-------- Cantera/src/kinetics/importKinetics.cpp | 24 ++ Cantera/src/kinetics/reaction_defs.h | 11 +- 9 files changed, 794 insertions(+), 253 deletions(-) diff --git a/Cantera/src/kinetics/InterfaceKinetics.cpp b/Cantera/src/kinetics/InterfaceKinetics.cpp index 090b8585e..2f5cd0cd7 100644 --- a/Cantera/src/kinetics/InterfaceKinetics.cpp +++ b/Cantera/src/kinetics/InterfaceKinetics.cpp @@ -25,9 +25,8 @@ using namespace std; namespace Cantera { - ////////////////////////////////////////////////////////////////// - - /** + //==================================================================================================================== + /* * Construct an empty InterfaceKinetics reaction mechanism. * @param thermo This is an optional parameter that may be * used to initialize the inherited Kinetics class with @@ -35,8 +34,7 @@ namespace Cantera { * useful for initialization of homogeneous kinetics * mechanisms. */ - InterfaceKinetics:: - InterfaceKinetics(thermo_t* thermo) : + InterfaceKinetics::InterfaceKinetics(thermo_t* thermo) : Kinetics(), m_kk(0), m_redo_rates(false), @@ -44,27 +42,41 @@ namespace Cantera { m_nrev(0), m_surf(0), m_integrator(0), + m_beta(0), + m_ctrxn(0), + m_ctrxn_ecdf(0), + m_StandardConc(0), + m_deltaG0(0), + m_ProdStanConcReac(0), m_finalized(false), m_has_coverage_dependence(false), m_has_electrochem_rxns(false), + m_has_exchange_current_density_formulation(false), + m_phaseExistsCheck(false), + m_phaseExists(0), + m_rxnPhaseIsReactant(0), + m_rxnPhaseIsProduct(0), m_ioFlag(0) { if (thermo != 0) addPhase(*thermo); m_kdata = new InterfaceKineticsData; m_kdata->m_temp = 0.0; } - - /** + //==================================================================================================================== + /* * Destructor */ - InterfaceKinetics:: - ~InterfaceKinetics(){ + InterfaceKinetics::~InterfaceKinetics(){ delete m_kdata; if (m_integrator) { delete m_integrator; } + for (int i = 0; i < m_ii; i++) { + delete m_rxnPhaseIsReactant[i]; + delete m_rxnPhaseIsProduct[i]; + } } - + //==================================================================================================================== // Copy Constructor for the %InterfaceKinetics object. /* * Currently, this is not fully implemented. If called it will @@ -78,9 +90,20 @@ namespace Cantera { m_nrev(0), m_surf(0), m_integrator(0), + m_beta(0), + m_ctrxn(0), + m_ctrxn_ecdf(0), + m_StandardConc(0), + m_deltaG0(0), + m_ProdStanConcReac(0), m_finalized(false), m_has_coverage_dependence(false), m_has_electrochem_rxns(false), + m_has_exchange_current_density_formulation(false), + m_phaseExistsCheck(false), + m_phaseExists(0), + m_rxnPhaseIsReactant(0), + m_rxnPhaseIsProduct(0), m_ioFlag(0) { m_kdata = new InterfaceKineticsData; @@ -90,7 +113,7 @@ namespace Cantera { */ *this = operator=(right); } - + //==================================================================================================================== // Assignment operator /* * This is NOT a virtual function. @@ -100,13 +123,21 @@ namespace Cantera { */ InterfaceKinetics& InterfaceKinetics:: operator=(const InterfaceKinetics &right) { + int i; /* * Check for self assignment. */ if (this == &right) return *this; + for (i = 0; i < m_ii; i++) { + delete (m_rxnPhaseIsReactant[i]); + delete (m_rxnPhaseIsProduct[i]); + } + Kinetics::operator=(right); + + m_kk = right.m_kk; m_revindex = right.m_revindex; m_rates = right.m_rates; @@ -129,17 +160,58 @@ namespace Cantera { m_integrator = right.m_integrator; //DANGER - shallow copy m_beta = right.m_beta; m_ctrxn = right.m_ctrxn; + m_ctrxn_ecdf = right.m_ctrxn_ecdf; + m_StandardConc = right.m_StandardConc; + m_deltaG0 = right.m_deltaG0; + m_ProdStanConcReac = right.m_ProdStanConcReac; m_finalized = right.m_finalized; m_has_coverage_dependence = right.m_has_coverage_dependence; m_has_electrochem_rxns = right.m_has_electrochem_rxns; + m_has_exchange_current_density_formulation = right.m_has_exchange_current_density_formulation; + m_phaseExistsCheck = right.m_phaseExistsCheck; + m_phaseExists = right.m_phaseExists; + + + m_rxnPhaseIsReactant.resize(m_ii, 0); + m_rxnPhaseIsProduct.resize(m_ii, 0); + int np = nPhases(); + for (i = 0; i < m_ii; i++) { + m_rxnPhaseIsReactant[i] = new bool[np]; + m_rxnPhaseIsProduct[i] = new bool[np]; + for (int p = 0; p < np; p++) { + m_rxnPhaseIsReactant[i][p] = right.m_rxnPhaseIsReactant[i][p]; + m_rxnPhaseIsProduct[i][p] = right.m_rxnPhaseIsProduct[i][p]; + } + } + + m_rxnPhaseIsProduct = right.m_rxnPhaseIsProduct; + m_ioFlag = right.m_ioFlag; return *this; } + //==================================================================================================================== + // Return the ID of the kinetics object + int InterfaceKinetics::ID() const { + return cInterfaceKinetics; + } + //==================================================================================================================== + int InterfaceKinetics::type() const { + return cInterfaceKinetics; + } + //==================================================================================================================== + // Set the electric potential in the nth phase + /* + * @param n phase Index in this kinetics object. + * @param V Electric potential (volts) + */ + void InterfaceKinetics::setElectricPotential(int n, doublereal V) { + thermo(n).setElectricPotential(V); + m_redo_rates = true; + } - - // Duplication routine for objects which inherit from - // Kinetics + //==================================================================================================================== + // Duplication routine for objects which inherit from Kinetics /* * This virtual routine can be used to duplicate %Kinetics objects * inherited from %Kinetics even if the application only has @@ -152,14 +224,18 @@ namespace Cantera { InterfaceKinetics* tp = new InterfaceKinetics(*this); return dynamic_cast(tp); } - - - /** - * Update properties that depend on temperature + //==================================================================================================================== + // Update properties that depend on temperature + /* + * This is called to update all of the properties that depend on temperature * - */ - void InterfaceKinetics:: - _update_rates_T() { + * Current objects that this function updates + * m_kdata->m_logtemp + * m_kdata->m_rfn + * m_rates. + * updateKc(); + */ + void InterfaceKinetics::_update_rates_T() { _update_rates_phi(); if (m_has_coverage_dependence) { m_surf->getCoverages(DATA_PTR(m_conc)); @@ -167,20 +243,24 @@ namespace Cantera { m_redo_rates = true; } doublereal T = thermo(surfacePhaseIndex()).temperature(); + m_redo_rates = true; if (T != m_kdata->m_temp || m_redo_rates) { m_kdata->m_logtemp = log(T); m_rates.update(T, m_kdata->m_logtemp, DATA_PTR(m_kdata->m_rfn)); - if (m_has_electrochem_rxns) + if (m_has_exchange_current_density_formulation) { + applyExchangeCurrentDensityFormulation(DATA_PTR(m_kdata->m_rfn)); + } + if (m_has_electrochem_rxns) { applyButlerVolmerCorrection(DATA_PTR(m_kdata->m_rfn)); + } m_kdata->m_temp = T; updateKc(); m_kdata->m_ROP_ok = false; m_redo_rates = false; } } - - void InterfaceKinetics:: - _update_rates_phi() { + //==================================================================================================================== + void InterfaceKinetics::_update_rates_phi() { int np = nPhases(); for (int n = 0; n < np; n++) { if (thermo(n).electricPotential() != m_phi[n]) { @@ -189,6 +269,7 @@ namespace Cantera { } } } + //==================================================================================================================== /** @@ -198,8 +279,7 @@ namespace Cantera { * representing phases should overload to return the appropriate * quantities. */ - void InterfaceKinetics:: - _update_rates_C() { + void InterfaceKinetics::_update_rates_C() { int n; int np = nPhases(); @@ -263,6 +343,8 @@ namespace Cantera { } } } + //==================================================================================================================== + void InterfaceKinetics::checkPartialEquil() { @@ -338,6 +420,36 @@ namespace Cantera { } } + void InterfaceKinetics::getExchangeCurrentQuantities() { + /* + * First collect vectors of the standard Gibbs free energies of the + * species and the standard concentrations + * - m_mu0 + * - m_logStandardConc + */ + int ik = 0; + int np = nPhases(); + + for (int n = 0; n < np; n++) { + thermo(n).getStandardChemPotentials(DATA_PTR(m_mu0) + m_start[n]); + int nsp = thermo(n).nSpecies(); + for (int k = 0; k < nsp; k++) { + m_StandardConc[ik] = thermo(n).standardConcentration(k); + ik++; + } + } + + m_rxnstoich.getReactionDelta(m_ii, DATA_PTR(m_mu0), DATA_PTR(m_deltaG0)); + + + for (int i = 0; i < m_ii; i++) { + m_ProdStanConcReac[i] = 1.0; + } + + m_rxnstoich.multiplyReactants(DATA_PTR(m_StandardConc), DATA_PTR(m_ProdStanConcReac)); + + } + // Returns the Species creation rates [kmol/m^2/s]. /* * Return the species @@ -385,12 +497,17 @@ namespace Cantera { net); } - /** + //==================================================================================================================== + // Apply corrections for interfacial charge transfer reactions + /* * For reactions that transfer charge across a potential difference, * the activation energies are modified by the potential difference. * (see, for example, ...). This method applies this correction. + * + * @param kf Vector of forward reaction rate constants on which to have + * the correction applied */ - void InterfaceKinetics::applyButlerVolmerCorrection(doublereal* kf) { + void InterfaceKinetics::applyButlerVolmerCorrection(doublereal* const kf) { int i; int n, nsp, k, ik=0; @@ -410,8 +527,7 @@ namespace Cantera { // Compute the change in electrical potential energy for each // reaction. This will only be non-zero if a potential // difference is present. - m_rxnstoich.getReactionDelta(m_ii, DATA_PTR(m_pot), - DATA_PTR(m_rwork)); + m_rxnstoich.getReactionDelta(m_ii, DATA_PTR(m_pot), DATA_PTR(m_rwork)); // Modify the reaction rates. Only modify those with a // non-zero activation energy. Below we decrease the @@ -432,7 +548,8 @@ namespace Cantera { for (i = 0; i < nct; i++) { irxn = m_ctrxn[i]; eamod = m_beta[i]*m_rwork[irxn]; - if (eamod != 0.0 && m_E[irxn] != 0.0) { + // if (eamod != 0.0 && m_E[irxn] != 0.0) { + if (eamod != 0.0) { #ifdef DEBUG_KIN_MODE ea = GasConstant * m_E[irxn]; if (eamod + ea < 0.0) { @@ -450,18 +567,32 @@ namespace Cantera { } } } + //==================================================================================================================== + void InterfaceKinetics::applyExchangeCurrentDensityFormulation(doublereal* const kfwd) { + getExchangeCurrentQuantities(); + int nct = m_ctrxn.size(); + doublereal rt = GasConstant*thermo(0).temperature(); + doublereal rrt = 1.0/rt; + for (int i = 0; i < nct; i++) { + int irxn = m_ctrxn[i]; + int iECDFormulation = m_ctrxn_ecdf[i]; + if (iECDFormulation) { + double tmp = exp(- m_beta[i] * m_deltaG0[irxn] * rrt); + double tmp2 = m_ProdStanConcReac[irxn]; + tmp *= 1.0 / tmp2 / Faraday; + kfwd[irxn] *= tmp; + } + } - - + } + //==================================================================================================================== /** * Update the rates of progress of the reactions in the reaciton * mechanism. This routine operates on internal data. */ void InterfaceKinetics::getFwdRateConstants(doublereal* kfwd) { - // _update_rates_T(); - // _update_rates_C(); updateROP(); const vector_fp& rf = m_kdata->m_rfn; @@ -473,7 +604,7 @@ namespace Cantera { multiply_each(kfwd, kfwd + nReactions(), m_perturb.begin()); } - + //==================================================================================================================== /** * Update the rates of progress of the reactions in the reaciton @@ -493,12 +624,12 @@ namespace Cantera { multiply_each(krev, krev + nReactions(), rkc.begin()); } } - + //==================================================================================================================== void InterfaceKinetics::getActivationEnergies(doublereal *E) { copy(m_E.begin(), m_E.end(), E); } - + //==================================================================================================================== /** * Update the rates of progress of the reactions in the reaction * mechanism. This routine operates on internal data. @@ -545,7 +676,57 @@ namespace Cantera { for (int j = 0; j != m_ii; ++j) { ropnet[j] = ropf[j] - ropr[j]; - } + } + + + /* + * For reactions involving multiple phases, we must check that the phase + * being consumed actually exists. This is particularly important for + * phases that are stoichiometric phases containing one species with a unity activity + */ + if (m_phaseExistsCheck) { + for (int j = 0; j != m_ii; ++j) { + if ((ropr[j] > ropf[j]) && (ropr[j] > 0.0)) { + for (int p = 0; p < nPhases(); p++) { + if (m_rxnPhaseIsProduct[j][p]) { + if (! m_phaseExists[p]) { + ropnet[j] = 0.0; + ropr[j] = ropf[j]; + if (ropf[j] > 0.0) { + for (int rp = 0; rp < nPhases(); rp++) { + if (m_rxnPhaseIsReactant[j][rp]) { + if (! m_phaseExists[rp]) { + ropnet[j] = 0.0; + ropr[j] = ropf[j] = 0.0;; + } + } + } + } + } + } + } + } else if ((ropf[j] > ropr[j]) && (ropf[j] > 0.0)) { + for (int p = 0; p < nPhases(); p++) { + if (m_rxnPhaseIsReactant[j][p]) { + if (! m_phaseExists[p]) { + ropnet[j] = 0.0; + ropf[j] = ropr[j]; + if (ropf[j] > 0.0) { + for (int rp = 0; rp < nPhases(); rp++) { + if (m_rxnPhaseIsProduct[j][rp]) { + if (! m_phaseExists[rp]) { + ropnet[j] = 0.0; + ropf[j] = ropr[j] = 0.0; + } + } + } + } + } + } + } + } + } + } m_kdata->m_ROP_ok = true; } @@ -738,7 +919,7 @@ namespace Cantera { m_rxnstoich.getReactionDelta(m_ii, DATA_PTR(m_grt), deltaS); } - + //==================================================================================================================== /** * Add a single reaction to the mechanism. This routine * must be called after init() and before finalize(). @@ -752,21 +933,44 @@ namespace Cantera { * There is no difference between elementary and surface * reactions. */ - void InterfaceKinetics:: - addReaction(const ReactionData& r) { + void InterfaceKinetics::addReaction(const ReactionData& r) { addElementaryReaction(r); // operations common to all reaction types - installReagents( r ); + installReagents(r); //installGroups(reactionNumber(), r.rgroups, r.pgroups); incrementRxnCount(); m_rxneqn.push_back(r.equation); - } + m_rxnPhaseIsReactant.resize(m_ii, 0); + m_rxnPhaseIsProduct.resize(m_ii, 0); + + int np = nPhases(); + int i = m_ii -1; + m_rxnPhaseIsReactant[i] = new bool[np]; + m_rxnPhaseIsProduct[i] = new bool[np]; - void InterfaceKinetics:: - addElementaryReaction(const ReactionData& r) { + for (int p = 0; p < np; p++) { + m_rxnPhaseIsReactant[i][p] = false; + m_rxnPhaseIsProduct[i][p] = false; + } + + const vector_int& vr = reactants(i); + for (int ik = 0; ik < (int) vr.size(); ik++) { + int k = vr[ik]; + int p = speciesPhaseIndex(k); + m_rxnPhaseIsReactant[i][p] = true; + } + const vector_int& vp = products(i); + for (int ik = 0; ik < (int) vp.size(); ik++) { + int k = vp[ik]; + int p = speciesPhaseIndex(k); + m_rxnPhaseIsProduct[i][p] = true; + } + } + //==================================================================================================================== + void InterfaceKinetics::addElementaryReaction(const ReactionData& r) { int iloc; // install rate coeff calculator @@ -776,12 +980,11 @@ namespace Cantera { if (ncov > 3) { m_has_coverage_dependence = true; } - for (int m = 0; m < ncov; m++) rp.push_back(r.cov[m]); - - iloc = m_rates.install( reactionNumber(), - r.rateCoeffType, rp.size(), - DATA_PTR(rp) ); - + for (int m = 0; m < ncov; m++) { + rp.push_back(r.cov[m]); + } + // iloc = m_rates.install(reactionNumber(), r.rateCoeffType, rp.size(), DATA_PTR(rp)); + iloc = m_rates.install(reactionNumber(), ARRHENIUS_REACTION_RATECOEFF_TYPE, rp.size(), DATA_PTR(rp)); // store activation energy m_E.push_back(r.rateCoeffParameters[2]); @@ -789,13 +992,19 @@ namespace Cantera { m_has_electrochem_rxns = true; m_beta.push_back(r.beta); m_ctrxn.push_back(reactionNumber()); + if (r.rateCoeffType == EXCHANGE_CURRENT_REACTION_RATECOEFF_TYPE) { + m_has_exchange_current_density_formulation = true; + m_ctrxn_ecdf.push_back(1); + } else { + m_ctrxn_ecdf.push_back(0); + } } // add constant term to rate coeff value vector m_kdata->m_rfn.push_back(r.rateCoeffParameters[0]); registerReaction( reactionNumber(), ELEMENTARY_RXN, iloc); } - + //==================================================================================================================== void InterfaceKinetics::setIOFlag(int ioFlag) { m_ioFlag = ioFlag; @@ -912,7 +1121,7 @@ namespace Cantera { * calculates rates of species production from reaction rates of * progress. */ - m_rxnstoich.add( reactionNumber(), r); + m_rxnstoich.add(reactionNumber(), r); /* * register reaction in lists of reversible and irreversible rxns. */ @@ -920,11 +1129,16 @@ namespace Cantera { m_revindex.push_back(reactionNumber()); m_nrev++; } else { - m_irrev.push_back( reactionNumber() ); + m_irrev.push_back(reactionNumber()); m_nirrev++; } } - + //=============================================================================================== + void InterfaceKinetics::addPhase(thermo_t &thermo) { + Kinetics::addPhase(thermo); + m_phaseExists.push_back(true); + } + //================================================================================================ /** * Prepare the class for the addition of reactions. This function * must be called after instantiation of the class, but before @@ -948,7 +1162,7 @@ namespace Cantera { m_pot.resize(m_kk, 0.0); m_phi.resize(np, 0.0); } - + //================================================================================================ /** * Finish adding reactions and prepare for use. This function * must be called after all reactions are entered into the mechanism @@ -958,6 +1172,7 @@ namespace Cantera { * since we don't know this number up to now. */ void InterfaceKinetics::finalize() { + Kinetics::finalize(); m_rwork.resize(nReactions()); int ks = reactionPhaseIndex(); if (ks < 0) throw CanteraError("InterfaceKinetics::finalize", @@ -967,10 +1182,20 @@ namespace Cantera { throw CanteraError("InterfaceKinetics::finalize", "expected interface dimension = 2, but got dimension = " +int2str(m_surf->nDim())); + + + + m_StandardConc.resize(m_nTotalSpecies, 0.0); + m_deltaG0.resize(m_ii, 0.0); + m_ProdStanConcReac.resize(m_ii, 0.0); + + if (m_thermo.size() != m_phaseExists.size()) { + throw CanteraError("InterfaceKinetics::finalize", "internal error"); + } + m_finalized = true; } - doublereal InterfaceKinetics::electrochem_beta(int irxn) const{ int n = m_ctrxn.size(); for (int i = 0; i < n; i++) { @@ -985,7 +1210,7 @@ namespace Cantera { bool InterfaceKinetics::ready() const { return (m_finalized); } - + //================================================================================================ // Advance the surface coverages in time /* * @param tstep Time value to advance the surface coverages @@ -1002,7 +1227,7 @@ namespace Cantera { delete m_integrator; m_integrator = 0; } - + //================================================================================================ // Solve for the pseudo steady-state of the surface problem /* * Solve for the steady state of the surface problem. @@ -1031,7 +1256,25 @@ namespace Cantera { */ m_integrator->solvePseudoSteadyStateProblem(ifuncOverride, timeScaleOverride); } + //================================================================================================ + void InterfaceKinetics::setPhaseExistence(const int iphase, const bool exists) { + if (iphase < 0 || iphase >= (int) m_thermo.size()) { + throw CanteraError("InterfaceKinetics:setPhaseExistence", "out of bounds"); + } + if (exists) { + if (!m_phaseExists[iphase]) { + m_phaseExistsCheck--; + m_phaseExists[iphase] = true; + } + } else { + if (m_phaseExists[iphase]) { + m_phaseExistsCheck++; + m_phaseExists[iphase] = false; + } + } + } + //================================================================================================ void EdgeKinetics::finalize() { m_rwork.resize(nReactions()); int ks = reactionPhaseIndex(); @@ -1043,7 +1286,8 @@ namespace Cantera { "expected interface dimension = 1, but got dimension = " +int2str(m_surf->nDim())); m_finalized = true; - } + } + //================================================================================================ } diff --git a/Cantera/src/kinetics/InterfaceKinetics.h b/Cantera/src/kinetics/InterfaceKinetics.h index c1b0343a8..50ca5dc59 100644 --- a/Cantera/src/kinetics/InterfaceKinetics.h +++ b/Cantera/src/kinetics/InterfaceKinetics.h @@ -45,11 +45,16 @@ namespace Cantera { class InterfaceKineticsData { public: InterfaceKineticsData() : + m_logp0(0.0), + m_logc0(0.0), m_ROP_ok(false), - m_temp(0.0), m_logtemp(0.0) + m_temp(0.0), + m_logtemp(0.0) {} + //! Virtual destructor - virtual ~InterfaceKineticsData(){} + virtual ~InterfaceKineticsData() { + } doublereal m_logp0; doublereal m_logc0; @@ -59,7 +64,9 @@ namespace Cantera { bool m_ROP_ok; + //! Current temperature of the data doublereal m_temp; + //! Current log of the temperature doublereal m_logtemp; vector_fp m_rfn; vector_fp m_rkcn; @@ -76,9 +83,9 @@ namespace Cantera { public: - /** - * Constructor - * + + //! Constructor + /*! * @param thermo The optional parameter may be used to initialize * the object with one ThermoPhase object. * HKM Note -> Since the interface kinetics @@ -121,20 +128,18 @@ namespace Cantera { */ virtual Kinetics *duplMyselfAsKinetics() const; + //! Return the ID of the kinetics object + virtual int ID() const; - virtual int ID() const { return cInterfaceKinetics; } - virtual int type() const { return cInterfaceKinetics; } + //! Retunr the type of the kinetics object + virtual int type() const; - /** - * Set the electric potential in the nth phase - * + //! Set the electric potential in the nth phase + /*! * @param n phase Index in this kinetics object. * @param V Electric potential (volts) */ - void setElectricPotential(int n, doublereal V) { - thermo(n).setElectricPotential(V); - m_redo_rates = true; - } + void setElectricPotential(int n, doublereal V); /// @@ -172,8 +177,17 @@ namespace Cantera { std::copy(m_kdata->m_ropnet.begin(), m_kdata->m_ropnet.end(), netROP); } + + //! Get the equilibrium constants of all reactions, whether + //! the reaction is reversible or not. + /*! + * @param kc Returns the concentration equation constant for the reaction. + * Length is the number of reactions + */ virtual void getEquilibriumConstants(doublereal* kc); + void getExchangeCurrentQuantities(); + virtual void getDeltaGibbs( doublereal* deltaG); @@ -361,6 +375,19 @@ namespace Cantera { */ //@{ + //! Add a phase to the kinetics manager object. + /*! + * This must be done before the function init() is called or + * before any reactions are input. + * + * This function calls the Kinetics operator addPhase. + * It also sets the following functions + * + * m_phaseExists[] + * + * @param thermo Reference to the ThermoPhase to be added. + */ + virtual void addPhase(thermo_t& thermo); //! Prepare the class for the addition of reactions. /*! @@ -390,12 +417,26 @@ namespace Cantera { virtual bool ready() const; - + //! Internal routine that updates the Rates of Progress of the reactions + /*! + * This is actually the guts of the functionality of the object + */ void updateROP(); - + + //! Update properties that depend on temperature + /*! + * This is called to update all of the properties that depend on temperature + * + * Current objects that this function updates + * m_kdata->m_logtemp + * m_kdata->m_rfn + * m_rates. + * updateKc(); + */ void _update_rates_T(); + void _update_rates_phi(); void _update_rates_C(); @@ -445,15 +486,63 @@ namespace Cantera { void setIOFlag(int ioFlag); void checkPartialEquil(); - + + + int reactionNumber() const { return m_ii;} + + void addElementaryReaction(const ReactionData& r); + void addGlobalReaction(const ReactionData& r); + void installReagents(const ReactionData& r); + + void updateKc(); + + //! Write values into m_index + /*! + * @param rxnNumber reaction number + * @param type reaction type + * @param loc location ?? + */ + void registerReaction(int rxnNumber, int type, int loc) { + m_index[rxnNumber] = std::pair(type, loc); + } + + //! Apply corrections for interfacial charge transfer reactions + /*! + * For reactions that transfer charge across a potential difference, + * the activation energies are modified by the potential difference. + * (see, for example, ...). This method applies this correction. + * + * @param kf Vector of forward reaction rate constants on which to have + * the correction applied + */ + void applyButlerVolmerCorrection(doublereal* const kf); + + //! When an electrode reaction rate is optionally specified in terms of its + //! exchange current density, extra vectors need to be precalculated + /*! + * + */ + void applyExchangeCurrentDensityFormulation(doublereal* const kfwd); + + //! Set the existence of a phase in the reaction object + /*! + * Tell the kinetics object whether a phase in the object exists. + * This is actually an extrinsic specification that must be carried out on top of the + * intrinsic calculation of the reaction rate + * + * @param iphase Index of the phase. This is the order within the internal thermo vector object + * @param exists Boolean indicating whether the phase exists or not + */ + void setPhaseExistence(const int iphase, const bool exists); + + protected: + //! Temporary work vector of length m_kk vector_fp m_grt; - protected: - //! m_kk is the number of species in all of the phases //! that participate in this kinetics mechanism. - int m_kk; + int m_kk; //! List of reactions numbers which are reversible reactions /*! @@ -489,7 +578,7 @@ namespace Cantera { * production rates and also handles turning thermo * properties into reaction thermo properties. */ - ReactionStoichMgr m_rxnstoich; + ReactionStoichMgr m_rxnstoich; //! Number of irreversible reactions in the mechanism int m_nirrev; @@ -564,7 +653,7 @@ namespace Cantera { */ vector_fp m_mu0; - //! Vector of phase potentials + //! Vector of phase electric potentials /*! * Temporary vector containing the potential of each phase * in the kinetics object @@ -607,30 +696,36 @@ namespace Cantera { ImplicitSurfChem* m_integrator; vector_fp m_beta; + + //! Vector of reaction indexes specifying the id of the current transfer reactions + //! in the mechanism + /*! + * Vector of reaction indecices which involve current transfers. This provides + * an index into the m_beta array. + * + * irxn = m_ctrxn[i] + */ vector_int m_ctrxn; - int reactionNumber(){ return m_ii;} + //! Vector of booleans indicating whether the charge transfer reaction may be + //! described by an exchange current density expression + vector_int m_ctrxn_ecdf; - void addElementaryReaction(const ReactionData& r); - void addGlobalReaction(const ReactionData& r); - void installReagents(const ReactionData& r); + vector_fp m_StandardConc; + vector_fp m_deltaG0; + vector_fp m_ProdStanConcReac; - void updateKc(); - //! Write values into m_index - /*! - * @param rxnNumber reaction number - * @param type reaction type - * @param loc location ?? - */ - void registerReaction(int rxnNumber, int type, int loc) { - m_index[rxnNumber] = std::pair(type, loc); - } - - void applyButlerVolmerCorrection(doublereal* kf); //! boolean indicating whether mechanism has been finalized bool m_finalized; + + //! Boolean flag indicating whether any reaction in the mechanism + //! has a coverage dependent forward reaction rate + /*! + * If this is true, then the coverage dependence is multiplied into + * the forward reaction rates constant + */ bool m_has_coverage_dependence; //! Boolean flag indicating whether any reaction in the mechanism @@ -643,6 +738,37 @@ namespace Cantera { */ bool m_has_electrochem_rxns; + //! Boolean flag indicating whether any reaction in the mechanism + //! is described by an exchange current density expression + /*! + * If this is true, the standard state gibbs free energy of the reaction and + * the product of the reactant standard concentrations must be precalculated + * in order to calculate the rate constant. + */ + bool m_has_exchange_current_density_formulation; + + //! Int flag to indicate that some phases in the kinetics mechanism are + //! non-existent. + /*! + * We change the ROP vectors to make sure that non-existent phases are treated + * correctly in the kinetics operator. The value of this is equal to the number + * of phases which don't exist. + */ + int m_phaseExistsCheck; + + //! Vector of booleans indicating whether phases exist or not + /*! + * Vector of booleans indicating whether a phase exists or not. + * We use this to set the ROP's so that unphysical things don't happen + * + * length = number of phases in the object + * By default all phases exist. + */ + std::vector m_phaseExists; + + std::vector m_rxnPhaseIsReactant; + std::vector m_rxnPhaseIsProduct; + int m_ioFlag; private: diff --git a/Cantera/src/kinetics/Kinetics.cpp b/Cantera/src/kinetics/Kinetics.cpp index 7ab58f4f8..c2338e1e1 100644 --- a/Cantera/src/kinetics/Kinetics.cpp +++ b/Cantera/src/kinetics/Kinetics.cpp @@ -29,9 +29,16 @@ using namespace std; namespace Cantera { - Kinetics::Kinetics() : m_ii(0), m_thermo(0), - m_index(-1), m_surfphase(-1), m_rxnphase(-1), - m_mindim(4) {} + Kinetics::Kinetics() : + m_ii(0), + m_nTotalSpecies(0), + m_thermo(0), + m_index(-1), + m_surfphase(-1), + m_rxnphase(-1), + m_mindim(4) + { + } Kinetics::~Kinetics(){} @@ -42,7 +49,8 @@ namespace Cantera { * throw an exception. */ Kinetics::Kinetics(const Kinetics &right) : - m_ii(0), + m_ii(0), + m_nTotalSpecies(0), m_thermo(0), m_index(-1), m_surfphase(-1), @@ -70,6 +78,7 @@ namespace Cantera { if (this == &right) return *this; m_ii = right.m_ii; + m_nTotalSpecies = right.m_nTotalSpecies; m_perturb = right.m_perturb; m_reactants = right.m_reactants; m_products = right.m_products; @@ -216,7 +225,8 @@ namespace Cantera { return thermo(0); } - /** + //============================================================================================== + /* * This function takes as an argument the kineticsSpecies index * (i.e., the list index in the list of species in the kinetics * manager) and returns the index of the phase owning the @@ -286,6 +296,15 @@ namespace Cantera { m_phaseindex[m_thermo.back()->id()] = nPhases(); } + void Kinetics::finalize() { + m_nTotalSpecies = 0; + int np = nPhases(); + for (int n = 0; n < np; n++) { + int nsp = m_thermo[n]->nSpecies(); + m_nTotalSpecies += nsp; + } + } + //! Private function of the class Kinetics, indicating that a function //! inherited from the base class hasn't had a definition assigned to it diff --git a/Cantera/src/kinetics/Kinetics.h b/Cantera/src/kinetics/Kinetics.h index 25ca5305f..33b63263b 100644 --- a/Cantera/src/kinetics/Kinetics.h +++ b/Cantera/src/kinetics/Kinetics.h @@ -811,7 +811,7 @@ namespace Cantera { * any initialization (allocating arrays, etc.) that must be * done after the reactions are entered. */ - virtual void finalize() {} + virtual void finalize(); /** * Add a single reaction to the mechanism. This routine @@ -904,6 +904,9 @@ namespace Cantera { //! Number of reactions in the mechanism int m_ii; + + //! Number of species in the species vector for this kinetics operator + int m_nTotalSpecies; /// Vector of perturbation factors for each reaction's rate of /// progress vector. It is initialized to one. diff --git a/Cantera/src/kinetics/ReactionData.h b/Cantera/src/kinetics/ReactionData.h index a02d25f8e..5c4f8c466 100644 --- a/Cantera/src/kinetics/ReactionData.h +++ b/Cantera/src/kinetics/ReactionData.h @@ -25,7 +25,7 @@ namespace Cantera { number = 0; rxn_number = 0; reversible = true; - rateCoeffType = ARRHENIUS; + rateCoeffType = ARRHENIUS_REACTION_RATECOEFF_TYPE; falloffType = NONE; error = 0; equation = ""; @@ -36,7 +36,12 @@ namespace Cantera { } virtual ~ReactionData(){} + //! type of the reaction + /*! + * The valid types are listed in the file, reaction_defs.h. + */ int reactionType; + int number; int rxn_number; vector_int reactants; @@ -51,7 +56,14 @@ namespace Cantera { //! True if the current reaction is reversible. False otherwise bool reversible; + + //! type of the rate coefficient for the forward rate constant + /*! + * The valid types are listed in the file, reaction_defs.h and they + * all end in RATECOEFF_TYPE + */ int rateCoeffType; + vector_fp rateCoeffParameters; vector_fp auxRateCoeffParameters; int falloffType; diff --git a/Cantera/src/kinetics/ReactionStoichMgr.h b/Cantera/src/kinetics/ReactionStoichMgr.h index 203bfc5e4..eba12e5d5 100644 --- a/Cantera/src/kinetics/ReactionStoichMgr.h +++ b/Cantera/src/kinetics/ReactionStoichMgr.h @@ -214,6 +214,7 @@ namespace Cantera { * \f[ * R_i = R_i * \prod_k C_k^{o_{k,i}} * \f] + * * Here \f$ o_{k,i} \f$ is the reaction order of species k in reaction i. */ virtual void multiplyReactants(const doublereal* C, doublereal* R); diff --git a/Cantera/src/kinetics/RxnRates.h b/Cantera/src/kinetics/RxnRates.h index 4e3d495ad..e8b0b5284 100644 --- a/Cantera/src/kinetics/RxnRates.h +++ b/Cantera/src/kinetics/RxnRates.h @@ -18,94 +18,99 @@ #include "ctexceptions.h" namespace Cantera { - - /** - * A rate coefficient of the form - * \f[ - * A T^b \exp (-E/RT) - * \f] + + //! Arrhenius reaction rate type depends only on temperature + /** + * A reaction rate coefficient of the following form. + * + * \f[ + * k_f = A T^b \exp (-E/RT) + * \f] + * + */ + class Arrhenius { + + public: + + /// return the rate coefficient type. + static int type(){ return ARRHENIUS_REACTION_RATECOEFF_TYPE ; } + + /// Default constructor. + Arrhenius() : + m_logA(-1.0E300), + m_b (0.0), + m_E (0.0), + m_A(0.0) {} + + /// Constructor with Arrhenius parameters specified with an array. + Arrhenius(int csize, const doublereal* c) : + m_b (c[1]), + m_E (c[2]), + m_A (c[0]) + { + if (m_A <= 0.0) { + m_logA = -1.0E300; + } else { + m_logA = log(m_A); + } + } + + /// Constructor. + /// @param A pre-exponential. The unit system is + /// (kmol, m, s). The actual units depend on the reaction + /// order and the dimensionality (surface or bulk). + /// @param b Temperature exponent. Non-dimensional. + /// @param E Activation energy in temperature units. Kelvin. + Arrhenius(doublereal A, doublereal b, doublereal E) : + m_b (b), + m_E (E), + m_A (A) + { + if (m_A <= 0.0) { + m_logA = -1.0E300; + } else { + m_logA = log(m_A); + } + } + + //! Update concentration-dependent parts of the rate coefficient. + /*! + * For this class, there are no + * concentration-dependent parts, so this method does nothing. */ - class Arrhenius { - - public: + void update_C(const doublereal* c) { + } - /// return the rate coefficient type. - static int type(){ return ARRHENIUS; } - - /// Default constructor. - Arrhenius() : - m_logA(-1.0E300), - m_b (0.0), - m_E (0.0), - m_A(0.0) {} - - /// Constructor with Arrhenius parameters specified with an array. - Arrhenius(int csize, const doublereal* c) : - m_b (c[1]), - m_E (c[2]), - m_A (c[0]) - { - if (m_A <= 0.0) { - m_logA = -1.0E300; - } else { - m_logA = log(m_A); - } - } - - /// Constructor. - /// @param A pre-exponential. The unit system is - /// (kmol, m, s). The actual units depend on the reaction - /// order and the dimensionality (surface or bulk). - /// @param b Temperature exponent. Non-dimensional. - /// @param E Activation energy in temperature units. Kelvin. - Arrhenius(doublereal A, doublereal b, doublereal E) : - m_b (b), - m_E (E), - m_A (A) - { - if (m_A <= 0.0) { - m_logA = -1.0E300; - } else { - m_logA = log(m_A); - } - } - - /// Update concentration-dependent parts of the rate - /// coefficient. For this class, there are no - /// concentration-dependent parts, so this method does - /// nothing. - void update_C(const doublereal* c) {} + /** + * Update the value of the logarithm of the rate constant. + * + * Note, this function should never be called for negative A values. + * If it does then it will produce a negative overflow result, and + * a zero net forwards reaction rate, instead of a negative reaction + * rate constant that is the expected result. + */ + doublereal update(doublereal logT, doublereal recipT) const { + return m_logA + m_b*logT - m_E*recipT; + } - /** - * Update the value of the logarithm of the rate constant. - * - * Note, this function should never be called for negative A values. - * If it does then it will produce a negative overflow result, and - * a zero net forwards reaction rate, instead of a negative reaction - * rate constant that is the expected result. - */ - doublereal update(doublereal logT, doublereal recipT) const { - return m_logA + m_b*logT - m_E*recipT; - } - - /** - * Update the value the rate constant. - * - * This function returns the actual value of the rate constant. - * It can be safely called for negative values of the pre-exponential - * factor. - */ - doublereal updateRC(doublereal logT, doublereal recipT) const { - return m_A * exp(m_b*logT - m_E*recipT); - } + /** + * Update the value the rate constant. + * + * This function returns the actual value of the rate constant. + * It can be safely called for negative values of the pre-exponential + * factor. + */ + doublereal updateRC(doublereal logT, doublereal recipT) const { + return m_A * exp(m_b*logT - m_E*recipT); + } - void writeUpdateRHS(std::ostream& s) const { - s << " exp(" << m_logA; - if (m_b != 0.0) s << " + " << m_b << " * tlog"; - if (m_E != 0.0) s << " - " << m_E << " * rt"; - s << ");" << std::endl; - } + void writeUpdateRHS(std::ostream& s) const { + s << " exp(" << m_logA; + if (m_b != 0.0) s << " + " << m_b << " * tlog"; + if (m_E != 0.0) s << " - " << m_E << " * rt"; + s << ");" << std::endl; + } doublereal activationEnergy_R() const { return m_E; @@ -121,19 +126,19 @@ namespace Cantera { class ArrheniusSum { public: - static int type(){ return ARRHENIUS_SUM; } + static int type(){ return ARRHENIUS_SUM_REACTION_RATECOEFF_TYPE; } ArrheniusSum() : m_nterms(0) {} void addArrheniusTerm(doublereal A, doublereal b, doublereal E) { - if (A > 0.0) { - m_terms.push_back(Arrhenius(A, b, E)); - m_sign.push_back(1); - } - else if (A < 0.0) { - m_terms.push_back(Arrhenius(-A, b, E)); - m_sign.push_back(-1); - } - m_nterms++; + if (A > 0.0) { + m_terms.push_back(Arrhenius(A, b, E)); + m_sign.push_back(1); + } + else if (A < 0.0) { + m_terms.push_back(Arrhenius(-A, b, E)); + m_sign.push_back(-1); + } + m_nterms++; } void update_C(const doublereal* c) {} @@ -169,38 +174,38 @@ namespace Cantera { return fsum; } - void writeUpdateRHS(std::ostream& s) const { + void writeUpdateRHS(std::ostream& s) const { ; } static bool alwaysComputeRate() { return false;} protected: - std::vector m_terms; - vector_int m_sign; - int m_nterms; + std::vector m_terms; + vector_int m_sign; + int m_nterms; }; - /** - * An Arrhenius rate with coverage-dependent terms. - */ - class SurfaceArrhenius { + /** + * An Arrhenius rate with coverage-dependent terms. + */ + class SurfaceArrhenius { - public: - static int type(){ return ARRHENIUS; } - SurfaceArrhenius() : - m_logA(-1.0E300), - m_b (0.0), - m_E (0.0), - m_A(0.0), - m_acov(0.0), - m_ecov(0.0), - m_mcov(0.0), - m_ncov(0), - m_nmcov(0) - { - } + public: + static int type(){ return ARRHENIUS_REACTION_RATECOEFF_TYPE ; } + SurfaceArrhenius() : + m_logA(-1.0E300), + m_b (0.0), + m_E (0.0), + m_A(0.0), + m_acov(0.0), + m_ecov(0.0), + m_mcov(0.0), + m_ncov(0), + m_nmcov(0) + { + } SurfaceArrhenius( int csize, const doublereal* c ) : m_b (c[1]), @@ -325,7 +330,7 @@ namespace Cantera { return exp(lres); } - void writeUpdateRHS(std::ostream& s) const {} + void writeUpdateRHS(std::ostream& s) const {} protected: doublereal delta_s0, delta_e0; @@ -335,37 +340,143 @@ namespace Cantera { #endif -} -// class LandauTeller { -// public: -// static int type(){ return LANDAUTELLER; } -// LandauTeller(){} -// LandauTeller( const vector_fp& c ) : m_c(c) { m_c[0] = log(c[0]); } + //! Arrhenius reaction rate type depends only on temperature + /** + * A reaction rate coefficient of the following form. + * + * \f[ + * k_f = A T^b \exp (-E/RT) + * \f] + * + */ + class ExchangeCurrent { + + public: -// doublereal update(doublereal logT, doublereal recipT) const { -// return m_c[0] + m_c[1]*tt[1] - m_c[2]*tt[2] -// + m_c[3]*tt[3] + m_c[4]*tt[4]; -// } - -// //void writeUpdateRHS(ostream& s) const { -// // s << exp(m_logA); -// // s << " * exp("; -// // if (m_b != 0.0) s << m_b << " * tlog"; -// // if (m_E != 0.0) s << " - " << m_E << " * rt"; -// // if (m_E != 0.0) s << " - " << m_E << " * rt"; -// // s << ");" << endl; -// // } -// //} + //! return the rate coefficient type. + static int type() { + return EXCHANGE_CURRENT_REACTION_RATECOEFF_TYPE ; + } -// protected: -// doublereal m_logA, m_b, m_E; -// }; + //! Default constructor. + ExchangeCurrent() : + m_logA(-1.0E300), + m_b (0.0), + m_E (0.0), + m_A(0.0) {} + + //! Constructor with Arrhenius parameters specified with an array. + ExchangeCurrent(int csize, const doublereal* c) : + m_b (c[1]), + m_E (c[2]), + m_A (c[0]) + { + if (m_A <= 0.0) { + m_logA = -1.0E300; + } else { + m_logA = log(m_A); + } + } + + /// Constructor. + /// @param A pre-exponential. The unit system is + /// (kmol, m, s). The actual units depend on the reaction + /// order and the dimensionality (surface or bulk). + /// @param b Temperature exponent. Non-dimensional. + /// @param E Activation energy in temperature units. Kelvin. + ExchangeCurrent(doublereal A, doublereal b, doublereal E) : + m_b (b), + m_E (E), + m_A (A) + { + if (m_A <= 0.0) { + m_logA = -1.0E300; + } else { + m_logA = log(m_A); + } + } + + //! Update concentration-dependent parts of the rate coefficient. + /*! + * For this class, there are no + * concentration-dependent parts, so this method does nothing. + */ + void update_C(const doublereal* c) { + } + + /** + * Update the value of the logarithm of the rate constant. + * + * Note, this function should never be called for negative A values. + * If it does then it will produce a negative overflow result, and + * a zero net forwards reaction rate, instead of a negative reaction + * rate constant that is the expected result. + */ + doublereal update(doublereal logT, doublereal recipT) const { + return m_logA + m_b*logT - m_E*recipT; + } + + /** + * Update the value the rate constant. + * + * This function returns the actual value of the rate constant. + * It can be safely called for negative values of the pre-exponential + * factor. + */ + doublereal updateRC(doublereal logT, doublereal recipT) const { + return m_A * exp(m_b*logT - m_E*recipT); + } + + + void writeUpdateRHS(std::ostream& s) const { + s << " exp(" << m_logA; + if (m_b != 0.0) s << " + " << m_b << " * tlog"; + if (m_E != 0.0) s << " - " << m_E << " * rt"; + s << ");" << std::endl; + } + + doublereal activationEnergy_R() const { + return m_E; + } + + static bool alwaysComputeRate() { return false;} + + protected: + doublereal m_logA, m_b, m_E, m_A; + }; + + + // class LandauTeller { + + // public: + // static int type(){ return LANDAUTELLER; } + // LandauTeller(){} + // LandauTeller( const vector_fp& c ) : m_c(c) { m_c[0] = log(c[0]); } + + // doublereal update(doublereal logT, doublereal recipT) const { + // return m_c[0] + m_c[1]*tt[1] - m_c[2]*tt[2] + // + m_c[3]*tt[3] + m_c[4]*tt[4]; + // } + + // //void writeUpdateRHS(ostream& s) const { + // // s << exp(m_logA); + // // s << " * exp("; + // // if (m_b != 0.0) s << m_b << " * tlog"; + // // if (m_E != 0.0) s << " - " << m_E << " * rt"; + // // if (m_E != 0.0) s << " - " << m_E << " * rt"; + // // s << ");" << endl; + // // } + // //} + + // protected: + // doublereal m_logA, m_b, m_E; + // }; -//} - + //} +} #endif diff --git a/Cantera/src/kinetics/importKinetics.cpp b/Cantera/src/kinetics/importKinetics.cpp index e40a1df84..267c1b76c 100644 --- a/Cantera/src/kinetics/importKinetics.cpp +++ b/Cantera/src/kinetics/importKinetics.cpp @@ -521,9 +521,24 @@ namespace Cantera { * kf should point to a XML element named "rateCoeff". * rdata is the partially filled ReactionData object for the reaction. * This function will fill in more fields in the ReactionData object. + * + * @param kf Reference to the XML Node named rateCoeff */ void getRateCoefficient(const node_t& kf, kinetics_t& kin, ReactionData& rdata, int negA) { + string type = kf.attrib("type"); + if (type == "") { + type = "Arrhenius"; + rdata.rateCoeffType = ARRHENIUS_REACTION_RATECOEFF_TYPE; + } + if (type == "ExchangeCurrentDensity") { + rdata.rateCoeffType = EXCHANGE_CURRENT_REACTION_RATECOEFF_TYPE; + } else if (type == "Arrhenius") { + + } else { + throw CanteraError("getRateCoefficient", + "Unknown type: " + type); + } int nc = kf.nChildren(); nodeset_t& kf_children = kf.children(); @@ -557,6 +572,12 @@ namespace Cantera { "negative or zero A coefficient for reaction "+int2str(rdata.number)); } } + else if (nm == "Arrhenius_ExchangeCurrentDensity") { + vector_fp coeff(3); + getArrhenius(c, highlow, coeff[0], coeff[1], coeff[2]); + chigh = coeff; + rdata.rateCoeffType = EXCHANGE_CURRENT_REACTION_RATECOEFF_TYPE; + } else if (nm == "falloff") { getFalloff(c, rdata); } @@ -580,6 +601,9 @@ namespace Cantera { rdata.auxRateCoeffParameters = clow; else if (rdata.reactionType == CHEMACT_RXN) rdata.auxRateCoeffParameters = chigh; + + + } diff --git a/Cantera/src/kinetics/reaction_defs.h b/Cantera/src/kinetics/reaction_defs.h index eb36dc544..f709d36a7 100644 --- a/Cantera/src/kinetics/reaction_defs.h +++ b/Cantera/src/kinetics/reaction_defs.h @@ -81,11 +81,12 @@ namespace Cantera { */ //@{ - const int ARRHENIUS = 1; - const int LANDAUTELLER = 2; - const int TSTRATE = 3; - const int SURF_ARRHENIUS = 4; - const int ARRHENIUS_SUM = 5; + const int ARRHENIUS_REACTION_RATECOEFF_TYPE = 1; + const int LANDAUTELLER_REACTION_RATECOEFF_TYPE = 2; + const int TSTRATE_REACTION_RATECOEFF_TYPE = 3; + const int SURF_ARRHENIUS_REACTION_RATECOEFF_TYPE = 4; + const int ARRHENIUS_SUM_REACTION_RATECOEFF_TYPE = 5; + const int EXCHANGE_CURRENT_REACTION_RATECOEFF_TYPE = 6; //@} From 701952e50946dc3a3366c04553eeafa4abd07f18 Mon Sep 17 00:00:00 2001 From: Harry Moffat Date: Sat, 8 May 2010 03:33:37 +0000 Subject: [PATCH 21/26] Added CANTERA_VERSION information to preconfig and to the Cantera.mak files which are used in the application environment. --- Cantera/cxx/include/Cantera.mak.in | 6 ++++++ Cantera/cxx/include/Cantera_bt.mak.in | 6 ++++++ preconfig | 18 ++++++++++++++++-- 3 files changed, 28 insertions(+), 2 deletions(-) diff --git a/Cantera/cxx/include/Cantera.mak.in b/Cantera/cxx/include/Cantera.mak.in index cb0cfec51..29d63639f 100644 --- a/Cantera/cxx/include/Cantera.mak.in +++ b/Cantera/cxx/include/Cantera.mak.in @@ -23,6 +23,8 @@ # in_CanteraBuildTree = 0 +CANTERA_VERSION=@ctversion@ + ############################################################################### # CANTERA CORE ############################################################################### @@ -122,6 +124,10 @@ endif # CANTERA_TOTAL_INCLUDES= $(CANTERA_CORE_INCLUDES) $(CANTERA_BOOST_INCLUDES) $(CANTERA_CVODE_INCLUDE) # +# You can add this into the compilation environment to identify the version number +# +CANTERA_DEFINES = -DCANTERA_VERSION=@ctversion@ +# # LIBS and LIBS should be the same ... # CANTERA_TOTAL_LIBS2 = -L$(CANTERA_LIBSDIR) @LOCAL_LIBS@ diff --git a/Cantera/cxx/include/Cantera_bt.mak.in b/Cantera/cxx/include/Cantera_bt.mak.in index f9566f2bf..b98df72c3 100644 --- a/Cantera/cxx/include/Cantera_bt.mak.in +++ b/Cantera/cxx/include/Cantera_bt.mak.in @@ -23,6 +23,8 @@ # in_CanteraBuildTree = 0 +CANTERA_VERSION=@ctversion@ + ############################################################################### # CANTERA CORE ############################################################################### @@ -117,6 +119,10 @@ endif #################################################################### CANTERA_TOTAL_INCLUDES= $(CANTERA_CORE_INCLUDES) $(CANTERA_BOOST_INCLUDES) $(CANTERA_CVODE_INCLUDE) +# +# You can add this into the compilation environment to identify the version number +# +CANTERA_DEFINES = -DCANTERA_VERSION=@ctversion@ CANTERA_TOTAL_LIBS2 = @LOCAL_LIB_DIRS@ @LOCAL_LIBS@ diff --git a/preconfig b/preconfig index ee7b62fea..7aa1de70e 100755 --- a/preconfig +++ b/preconfig @@ -488,8 +488,22 @@ CT_SHARED_LIB=${CT_SHARED_LIB:=clib} # lowercase 'helvetica'. RPFONT=${RPFONT:="Helvetica"} -# Don't change this. -CANTERA_VERSION=${CANTERA_VERSION:="1.8.0"} +# +# Version Control: +# +# We define a new string for every branch created in svn. +# +# Currently expected versions: +# "1.7" Old version of Cantera +# "1.8.0" Released version of 1.8 +# "1.8.x" Development version of 1.8 +# "1.8_liquidTransportDevelop" branched version of 1.8 having to deal with liquid transport +# +# This field gets written into config.h and is also an autoconf variable. +# +# +CANTERA_VERSION=${CANTERA_VERSION:="1.8.x"} + #----------------------------------------------------------------------- #------------------- don't change anything below!! --------------------- From 6089ab2d6810896d57d8c69b88c3d9e9d573a7f9 Mon Sep 17 00:00:00 2001 From: Harry Moffat Date: Sat, 8 May 2010 18:03:30 +0000 Subject: [PATCH 22/26] Added version control information to this file. --- winconfig.h | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/winconfig.h b/winconfig.h index 02d3b239e..f0afd2e8e 100644 --- a/winconfig.h +++ b/winconfig.h @@ -6,6 +6,19 @@ #define CT_CONFIG_H +//---------------------------- Version Flags ------------------// +// Cantera version -> this will be a double-quoted string value +// refering to branch number within svn +#define CANTERA_VERSION "1.8.x" + +// Integer for major number of Cantera +#define CANTERA_VERSION_MAJORNUMBER 18 +// Flag indicating it's part of major version 18 +#define CANTERA_VERSION_18 1 +// Flag indicating it's a development version +#define CANTERA_VERSION_18_XXX 1 + + //------------------------ Development flags ------------------// // // Compile in additional debug printing where available. @@ -64,8 +77,6 @@ typedef int ftnlen; // Fortran hidden string length type /* #undef DARWIN */ #define HAS_SSTREAM 1 -// Cantera version -#define CANTERA_VERSION "1.8.0" // Identify whether the operating system is cygwin's overlay of // windows, with gcc being used as the compiler. From ef7728b1d32047ef5aa664f6c8bd36a23394b74a Mon Sep 17 00:00:00 2001 From: Harry Moffat Date: Sun, 9 May 2010 03:18:33 +0000 Subject: [PATCH 23/26] Merged thermo directory with the LiquidTransportDevelop thermo directory. The biggest change is the addition of the derivative routines of the activity wrt mole fraction and mole number. Also There is an addition of reportCSV() routine, which is a method to create a comma separated file from ThermoPhase routines. The rest are small issues. --- Cantera/src/thermo/Constituents.h | 9 +- Cantera/src/thermo/Elements.cpp | 1 - Cantera/src/thermo/GibbsExcessVPSSTP.cpp | 115 +---- Cantera/src/thermo/GibbsExcessVPSSTP.h | 98 +++-- Cantera/src/thermo/IdealGasPhase.h | 1 + Cantera/src/thermo/IonsFromNeutralVPSSTP.cpp | 420 ++++++++++++++----- Cantera/src/thermo/IonsFromNeutralVPSSTP.h | 108 ++++- Cantera/src/thermo/MargulesVPSSTP.cpp | 404 +++++++++++++----- Cantera/src/thermo/MargulesVPSSTP.h | 86 +++- Cantera/src/thermo/MolalityVPSSTP.cpp | 145 +++++++ Cantera/src/thermo/MolalityVPSSTP.h | 8 + Cantera/src/thermo/PDSS_SSVol.cpp | 4 +- Cantera/src/thermo/PureFluidPhase.cpp | 139 +++++- Cantera/src/thermo/PureFluidPhase.h | 8 + Cantera/src/thermo/State.cpp | 4 + Cantera/src/thermo/State.h | 3 + Cantera/src/thermo/ThermoPhase.cpp | 156 ++++++- Cantera/src/thermo/ThermoPhase.h | 54 ++- Cantera/src/thermo/VPSSMgr.cpp | 4 +- Cantera/src/thermo/VPStandardStateTP.h | 32 +- Cantera/src/thermo/WaterProps.cpp | 1 + 21 files changed, 1406 insertions(+), 394 deletions(-) diff --git a/Cantera/src/thermo/Constituents.h b/Cantera/src/thermo/Constituents.h index a38622906..22028b964 100644 --- a/Cantera/src/thermo/Constituents.h +++ b/Cantera/src/thermo/Constituents.h @@ -280,14 +280,13 @@ namespace Cantera { doublereal charge = 0.0, doublereal size = 1.0); - //! Index of species named 'name' + //! Returns the index of a species named 'name' within the ThermoPhase /*! - * The first species added - * will have index 0, and the last one index nSpecies() - 1. + * The first species added will have index 0, and the last one index nSpecies() - 1. * * @param name String name of the species - * @return - * Returns the index of the species. + * @return Returns the index of the species. If the name is not found + * the value of -1 is returned. */ int speciesIndex(std::string name) const; diff --git a/Cantera/src/thermo/Elements.cpp b/Cantera/src/thermo/Elements.cpp index 1cd563d8e..2c9e61bdc 100644 --- a/Cantera/src/thermo/Elements.cpp +++ b/Cantera/src/thermo/Elements.cpp @@ -328,7 +328,6 @@ namespace Cantera { } - doublereal Elements::entropyElement298(int m) const { AssertThrowMsg(m_entropy298[m] != ENTROPY298_UNKNOWN, "Elements::entropy298", diff --git a/Cantera/src/thermo/GibbsExcessVPSSTP.cpp b/Cantera/src/thermo/GibbsExcessVPSSTP.cpp index fd7e460c3..d0b14221f 100644 --- a/Cantera/src/thermo/GibbsExcessVPSSTP.cpp +++ b/Cantera/src/thermo/GibbsExcessVPSSTP.cpp @@ -23,6 +23,7 @@ #include "GibbsExcessVPSSTP.h" +#include using namespace std; namespace Cantera { @@ -65,13 +66,14 @@ namespace Cantera { moleFractions_ = b.moleFractions_; lnActCoeff_Scaled_ = b.lnActCoeff_Scaled_; dlnActCoeffdT_Scaled_ = b.dlnActCoeffdT_Scaled_; - dlnActCoeffdlnC_Scaled_ = b.dlnActCoeffdlnC_Scaled_; + dlnActCoeffdlnX_Scaled_ = b.dlnActCoeffdlnX_Scaled_; + dlnActCoeffdlnN_Scaled_ = b.dlnActCoeffdlnN_Scaled_; m_pp = b.m_pp; return *this; } - /** + /* * * ~GibbsExcessVPSSTP(): (virtual) * @@ -156,7 +158,9 @@ namespace Cantera { } void GibbsExcessVPSSTP::calcDensity() { - double *vbar = &m_pp[0]; + doublereal* vbar = NULL; + vbar = new doublereal[m_kk]; + // double *vbar = &m_pp[0]; getPartialMolarVolumes(vbar); doublereal vtotal = 0.0; @@ -165,6 +169,7 @@ namespace Cantera { } doublereal dd = meanMolecularWeight() / vtotal; State::setDensity(dd); + delete [] vbar; } void GibbsExcessVPSSTP::setState_TP(doublereal t, doublereal p) { @@ -309,7 +314,6 @@ namespace Cantera { void GibbsExcessVPSSTP::initThermo() { initLengths(); VPStandardStateTP::initThermo(); - } @@ -320,110 +324,11 @@ namespace Cantera { moleFractions_.resize(m_kk); lnActCoeff_Scaled_.resize(m_kk); dlnActCoeffdT_Scaled_.resize(m_kk); - dlnActCoeffdlnC_Scaled_.resize(m_kk); + dlnActCoeffdlnX_Scaled_.resize(m_kk); + dlnActCoeffdlnN_Scaled_.resize(m_kk); m_pp.resize(m_kk); } - - /* - * initThermoXML() (virtual from ThermoPhase) - * Import and initialize a ThermoPhase object - * - * @param phaseNode This object must be the phase node of a - * complete XML tree - * description of the phase, including all of the - * species data. In other words while "phase" must - * point to an XML phase object, it must have - * sibling nodes "speciesData" that describe - * the species in the phase. - * @param id ID of the phase. If nonnull, a check is done - * to see if phaseNode is pointing to the phase - * with the correct id. - */ - void GibbsExcessVPSSTP::initThermoXML(XML_Node& phaseNode, std::string id) { - - - VPStandardStateTP::initThermoXML(phaseNode, id); - } - /** - * Format a summary of the mixture state for output. - */ - std::string GibbsExcessVPSSTP::report(bool show_thermo) const { - - - char p[800]; - string s = ""; - try { - if (name() != "") { - sprintf(p, " \n %s:\n", name().c_str()); - s += p; - } - sprintf(p, " \n temperature %12.6g K\n", temperature()); - s += p; - sprintf(p, " pressure %12.6g Pa\n", pressure()); - s += p; - sprintf(p, " density %12.6g kg/m^3\n", density()); - s += p; - sprintf(p, " mean mol. weight %12.6g amu\n", meanMolecularWeight()); - s += p; - - doublereal phi = electricPotential(); - sprintf(p, " potential %12.6g V\n", phi); - s += p; - - int kk = nSpecies(); - array_fp x(kk); - array_fp molal(kk); - array_fp mu(kk); - array_fp muss(kk); - array_fp acMolal(kk); - array_fp actMolal(kk); - getMoleFractions(&x[0]); - - getChemPotentials(&mu[0]); - getStandardChemPotentials(&muss[0]); - getActivities(&actMolal[0]); - - - if (show_thermo) { - sprintf(p, " \n"); - s += p; - sprintf(p, " 1 kg 1 kmol\n"); - s += p; - sprintf(p, " ----------- ------------\n"); - s += p; - sprintf(p, " enthalpy %12.6g %12.4g J\n", - enthalpy_mass(), enthalpy_mole()); - s += p; - sprintf(p, " internal energy %12.6g %12.4g J\n", - intEnergy_mass(), intEnergy_mole()); - s += p; - sprintf(p, " entropy %12.6g %12.4g J/K\n", - entropy_mass(), entropy_mole()); - s += p; - sprintf(p, " Gibbs function %12.6g %12.4g J\n", - gibbs_mass(), gibbs_mole()); - s += p; - sprintf(p, " heat capacity c_p %12.6g %12.4g J/K\n", - cp_mass(), cp_mole()); - s += p; - try { - sprintf(p, " heat capacity c_v %12.6g %12.4g J/K\n", - cv_mass(), cv_mole()); - s += p; - } - catch(CanteraError) { - sprintf(p, " heat capacity c_v \n"); - s += p; - } - } - - } catch (CanteraError) { - ; - } - return s; - } - } diff --git a/Cantera/src/thermo/GibbsExcessVPSSTP.h b/Cantera/src/thermo/GibbsExcessVPSSTP.h index 185c2be27..a100e5f45 100644 --- a/Cantera/src/thermo/GibbsExcessVPSSTP.h +++ b/Cantera/src/thermo/GibbsExcessVPSSTP.h @@ -71,13 +71,14 @@ namespace Cantera { * \f$k\f$. * * GibbsExcessVPSSTP contains an internal vector with the current mole - * fraction vector. That's one of its primary usages. + * fraction vector. That's one of its primary usages. In order to keep the mole fraction + * vector constant, all of the setState functions are redesigned at this layer. * *

SetState Strategy

* - * The gibbsExcessVPSSTP object does not have a setState strategy. - * It's strictly an interfacial layer that writes the current mole fractions to the - * State object. + * All setState functions that set the internal state of the ThermoPhase object are + * overloaded at this level, so that a current mole fraction vector is maintained within + * the object. * * */ @@ -172,6 +173,7 @@ namespace Cantera { virtual void setPressure(doublereal p); protected: + /** * Calculate the density of the mixture using the partial * molar volumes and mole fractions as input @@ -301,6 +303,23 @@ namespace Cantera { virtual void getdlnActCoeffdT(doublereal *dlnActCoeffdT) const { err("getdlnActCoeffdT"); } + + //! Get the array of change in the log activity coefficients w.r.t. change in state (change temp, change mole fractions) + /*! + * This function is a virtual class, but it first appears in GibbsExcessVPSSTP + * class and derived classes from GibbsExcessVPSSTP. + * + * This function is a virtual method. For ideal mixtures + * (unity activity coefficients), this can gradX/X. + * + * @param dT Input of temperature change + * @param dX Input vector of changes in mole fraction. length = m_kk + * @param dlnActCoeff Output vector of derivatives of the + * log Activity Coefficients. length = m_kk + */ + virtual void getdlnActCoeff(const doublereal dT, const doublereal * const dX, doublereal *dlnActCoeff) const { + err("getdlnActCoeff"); + } //! Get the array of log concentration-like derivatives of the //! log activity coefficients @@ -317,11 +336,33 @@ namespace Cantera { * * units = dimensionless * - * @param dlnActCoeffdlnC Output vector of derivatives of the + * @param dlnActCoeffdlnN Output vector of derivatives of the * log Activity Coefficients. length = m_kk */ - virtual void getdlnActCoeffdlnC(doublereal *dlnActCoeffdlnC) const { - err("getdlnActCoeffdlnC"); + virtual void getdlnActCoeffdlnN(doublereal *dlnActCoeffdlnN) const { + err("getdlnActCoeffdlnN"); + } + + //! Get the array of log concentration-like derivatives of the + //! log activity coefficients + /*! + * This function is a virtual method. For ideal mixtures + * (unity activity coefficients), this can return zero. + * Implementations should take the derivative of the + * logarithm of the activity coefficient with respect to the + * logarithm of the concentration-like variable (i.e. number of moles in + * in a unit volume. ) that represents the standard state. + * This quantity is to be used in conjunction with derivatives of + * that concentration-like variable when the derivative of the chemical + * potential is taken. + * + * units = dimensionless + * + * @param dlnActCoeffdlnX Output vector of derivatives of the + * log Activity Coefficients. length = m_kk + */ + virtual void getdlnActCoeffdlnX(doublereal *dlnActCoeffdlnX) const { + err("getdlnActCoeffdlnX"); } //@} @@ -492,43 +533,14 @@ namespace Cantera { * @see importCTML.cpp */ virtual void initThermo(); - - - /** - * Import and initialize a ThermoPhase object - * - * @param phaseNode This object must be the phase node of a - * complete XML tree - * description of the phase, including all of the - * species data. In other words while "phase" must - * point to an XML phase object, it must have - * sibling nodes "speciesData" that describe - * the species in the phase. - * @param id ID of the phase. If nonnull, a check is done - * to see if phaseNode is pointing to the phase - * with the correct id. - */ - void initThermoXML(XML_Node& phaseNode, std::string id); - - //! returns a summary of the state of the phase as a string - /*! - * @param show_thermo If true, extra information is printed out - * about the thermodynamic state of the system. - */ - virtual std::string report(bool show_thermo = true) const; - private: - //! Initialize lengths of local variables after all species have //! been identified. void initLengths(); - - - private: //! Error function /*! * Print an error string and exit @@ -548,6 +560,13 @@ namespace Cantera { protected: //! Storage for the current values of the mole fractions of the species + /*! + * This vector is kept up-to-date when the setState functions are called. + * Therefore, it may be considered to be an independent variable. + * + * Note in order to do this, the setState functions are redefined to always + * keep this vector current. + */ mutable std::vector moleFractions_; //! Storage for the current values of the activity coefficients of the @@ -562,7 +581,12 @@ namespace Cantera { //! Storage for the current derivative values of the //! gradients with respect to logarithm of the mole fraction of the //! log of theactivity coefficients of the species - mutable std::vector dlnActCoeffdlnC_Scaled_; + mutable std::vector dlnActCoeffdlnN_Scaled_; + + //! Storage for the current derivative values of the + //! gradients with respect to logarithm of the mole fraction of the + //! log of theactivity coefficients of the species + mutable std::vector dlnActCoeffdlnX_Scaled_; //! Temporary storage space that is fair game mutable std::vector m_pp; diff --git a/Cantera/src/thermo/IdealGasPhase.h b/Cantera/src/thermo/IdealGasPhase.h index b83cec970..915e7bfa0 100644 --- a/Cantera/src/thermo/IdealGasPhase.h +++ b/Cantera/src/thermo/IdealGasPhase.h @@ -330,6 +330,7 @@ namespace Cantera { */ IdealGasPhase(const IdealGasPhase &right); + //! Asignment operator /*! * Assignment operator for the object. Constructed diff --git a/Cantera/src/thermo/IonsFromNeutralVPSSTP.cpp b/Cantera/src/thermo/IonsFromNeutralVPSSTP.cpp index df90bac16..5beb7725f 100644 --- a/Cantera/src/thermo/IonsFromNeutralVPSSTP.cpp +++ b/Cantera/src/thermo/IonsFromNeutralVPSSTP.cpp @@ -28,6 +28,7 @@ #include "mix_defs.h" #include +#include using namespace std; @@ -197,7 +198,8 @@ namespace Cantera { muNeutralMolecule_ = b.muNeutralMolecule_; gammaNeutralMolecule_ = b.gammaNeutralMolecule_; dlnActCoeffdT_NeutralMolecule_ = b.dlnActCoeffdT_NeutralMolecule_; - dlnActCoeffdlnC_NeutralMolecule_ = b.dlnActCoeffdlnC_NeutralMolecule_; + dlnActCoeffdlnX_NeutralMolecule_ = b.dlnActCoeffdlnX_NeutralMolecule_; + dlnActCoeffdlnN_NeutralMolecule_ = b.dlnActCoeffdlnN_NeutralMolecule_; return *this; } @@ -332,6 +334,14 @@ namespace Cantera { void IonsFromNeutralVPSSTP::getActivityConcentrations(doublereal* c) const { getActivities(c); } + + void IonsFromNeutralVPSSTP::getDissociationCoeffs(vector_fp& coeffs,vector_fp& charges, std::vector& neutMolIndex){ + coeffs = fm_neutralMolec_ions_; + charges = m_speciesCharge; + neutMolIndex = fm_invert_ionForNeutral; + //for ( int k = 0; k < fm_neutralMolec_ions_[k]; k++ ) + // coeffs.push_back(fm_neutralMolec_ions_[k]); + } // Return the standard concentration for the kth species /* @@ -598,22 +608,47 @@ namespace Cantera { * * units = dimensionless * - * @param dlnActCoeffdlnC Output vector of log(mole fraction) + * @param dlnActCoeffdlnX Output vector of log(mole fraction) * derivatives of the log Activity Coefficients. * length = m_kk */ - void IonsFromNeutralVPSSTP::getdlnActCoeffdlnC(doublereal *dlnActCoeffdlnC) const { + void IonsFromNeutralVPSSTP::getdlnActCoeffdlnX(doublereal *dlnActCoeffdlnX) const { s_update_lnActCoeff(); - s_update_dlnActCoeff_dlnC(); + s_update_dlnActCoeff_dlnX(); for (int k = 0; k < m_kk; k++) { - dlnActCoeffdlnC[k] = dlnActCoeffdlnC_Scaled_[k]; + dlnActCoeffdlnX[k] = dlnActCoeffdlnX_Scaled_[k]; + } + } + + //! Get the array of log concentration-like derivatives of the + //! log activity coefficients + /*! + * This function is a virtual method. For ideal mixtures + * (unity activity coefficients), this can return zero. + * Implementations should take the derivative of the + * logarithm of the activity coefficient with respect to the + * logarithm of the concentration-like variable (i.e. moles) + * that represents the standard state. + * This quantity is to be used in conjunction with derivatives of + * that concentration-like variable when the derivative of the chemical + * potential is taken. + * + * units = dimensionless + * + * @param dlnActCoeffdlnN Output vector of log(mole fraction) + * derivatives of the log Activity Coefficients. + * length = m_kk + */ + void IonsFromNeutralVPSSTP::getdlnActCoeffdlnN(doublereal *dlnActCoeffdlnN) const { + s_update_lnActCoeff(); + s_update_dlnActCoeff_dlnN(); + + for (int k = 0; k < m_kk; k++) { + dlnActCoeffdlnN[k] = dlnActCoeffdlnN_Scaled_[k]; } } - - - // This is temporary. We will get rid of this void IonsFromNeutralVPSSTP::setTemperature(const doublereal temp) { double p = pressure(); @@ -644,7 +679,10 @@ namespace Cantera { /* * Calculate the partial molar volumes, and then the density of the fluid */ - calcDensity(); + + //calcDensity(); + double dd = neutralMoleculePhase_->density(); + State::setDensity(dd); } // Calculate ion mole fractions from neutral molecule @@ -717,7 +755,7 @@ namespace Cantera { for (k = 0; k < m_kk; k++) { sum += moleFractions_[k]; } - if (fabs(sum) > 1.0E-11) { + if (fabs(sum) > 1.0E-11) { throw CanteraError("IonsFromNeutralVPSSTP::calcNeutralMoleculeMoleFractions", "molefracts don't sum to one: " + fp2str(sum)); } @@ -791,7 +829,130 @@ namespace Cantera { sum += NeutralMolecMoleFractions_[k]; } for (k = 0; k < numNeutralMoleculeSpecies_; k++) { - NeutralMolecMoleFractions_[k] /= sum; + NeutralMolecMoleFractions_[k] /= sum; + } + + break; + + case cIonSolnType_SINGLECATION: + + throw CanteraError("eosType", "Unknown type"); + + break; + + case cIonSolnType_MULTICATIONANION: + + throw CanteraError("eosType", "Unknown type"); + break; + + default: + + throw CanteraError("eosType", "Unknown type"); + break; + + } + } + +// Calculate neutral molecule mole fractions + /* + * This routine calculates the neutral molecule mole + * fraction given the vector of ion mole fractions, + * i.e., the mole fractions from this ThermoPhase. + * Note, this routine basically assumes that there + * is charge neutrality. If there isn't, then it wouldn't + * make much sense. + * + * for the case of cIonSolnType_SINGLEANION, some slough + * in the charge neutrality is allowed. The cation number + * is followed, while the difference in charge neutrality + * is dumped into the anion mole number to fix the imbalance. + */ + void IonsFromNeutralVPSSTP::getNeutralMoleculeMoleGrads(const doublereal * const dx, doublereal *dy) const { + int k, icat, jNeut; + doublereal sumCat; + doublereal sumAnion; + doublereal fmij; + vector_fp y; + y.resize(numNeutralMoleculeSpecies_,0.0); + doublereal sumy, sumdy; + + //check sum dx = 0 + + //! Zero the vector we are trying to find. + for (k = 0; k < numNeutralMoleculeSpecies_; k++) { + dy[k] = 0.0; + } + + + // bool fmSimple = true; + + switch (ionSolnType_) { + + case cIonSolnType_PASSTHROUGH: + + for (k = 0; k < m_kk; k++) { + dy[k] = dx[k]; + } + break; + + case cIonSolnType_SINGLEANION: + + sumCat = 0.0; + sumAnion = 0.0; + + for (k = 0; k < (int) cationList_.size(); k++) { + //! Get the id for the next cation + icat = cationList_[k]; + jNeut = fm_invert_ionForNeutral[icat]; + if (jNeut >= 0) { + fmij = fm_neutralMolec_ions_[icat + jNeut * m_kk]; + AssertTrace(fmij != 0.0); + dy[jNeut] += dx[icat] / fmij; + y[jNeut] += moleFractions_[icat] / fmij; + } + } + + for (k = 0; k < numPassThroughSpecies_; k++) { + icat = passThroughList_[k]; + jNeut = fm_invert_ionForNeutral[icat]; + fmij = fm_neutralMolec_ions_[ icat + jNeut * m_kk]; + dy[jNeut] += dx[icat] / fmij; + y[jNeut] += moleFractions_[icat] / fmij; + } +#ifdef DEBUG_MODE_NOT +//check dy sum to zero + for (k = 0; k < m_kk; k++) { + moleFractionsTmp_[k] = dx[k]; + } + for (jNeut = 0; jNeut < numNeutralMoleculeSpecies_; jNeut++) { + for (k = 0; k < m_kk; k++) { + fmij = fm_neutralMolec_ions_[k + jNeut * m_kk]; + moleFractionsTmp_[k] -= fmij * dy[jNeut]; + } + } + for (k = 0; k < m_kk; k++) { + if (fabs(moleFractionsTmp_[k]) > 1.0E-13) { + //! Check to see if we have in fact found the inverse. + if (anionList_[0] != k) { + throw CanteraError("", "neutral molecule calc error"); + } else { + //! For the single anion case, we will allow some slippage + if (fabs(moleFractionsTmp_[k]) > 1.0E-5) { + throw CanteraError("", "neutral molecule calc error - anion"); + } + } + } + } +#endif + // Normalize the Neutral Molecule mole fractions + sumy = 0.0; + sumdy = 0.0; + for (k = 0; k < numNeutralMoleculeSpecies_; k++) { + sumy += y[k]; + sumdy += dy[k]; + } + for (k = 0; k < numNeutralMoleculeSpecies_; k++) { + dy[k] = dy[k]/sumy - y[k]*sumdy/sumy/sumy; } break; @@ -815,6 +976,7 @@ namespace Cantera { } } + void IonsFromNeutralVPSSTP::setMassFractions(const doublereal* const y) { GibbsExcessVPSSTP::setMassFractions(y); calcNeutralMoleculeMoleFractions(); @@ -836,7 +998,7 @@ namespace Cantera { void IonsFromNeutralVPSSTP::setMoleFractions_NoNorm(const doublereal* const x) { GibbsExcessVPSSTP::setMoleFractions_NoNorm(x); calcNeutralMoleculeMoleFractions(); - neutralMoleculePhase_->setMoleFractions(DATA_PTR(NeutralMolecMoleFractions_)); + neutralMoleculePhase_->setMoleFractions_NoNorm(DATA_PTR(NeutralMolecMoleFractions_)); } @@ -1030,7 +1192,8 @@ namespace Cantera { muNeutralMolecule_.resize(numNeutralMoleculeSpecies_); gammaNeutralMolecule_.resize(numNeutralMoleculeSpecies_); dlnActCoeffdT_NeutralMolecule_.resize(numNeutralMoleculeSpecies_); - dlnActCoeffdlnC_NeutralMolecule_.resize(numNeutralMoleculeSpecies_); + dlnActCoeffdlnX_NeutralMolecule_.resize(numNeutralMoleculeSpecies_); + dlnActCoeffdlnN_NeutralMolecule_.resize(numNeutralMoleculeSpecies_); } static double factorOverlap(const std::vector& elnamesVN , @@ -1136,9 +1299,12 @@ namespace Cantera { std::vector elemVectorI(nElementsI); vector fm_tmp(m_kk); - for (int jNeut = 0; jNeut < numNeutralMoleculeSpecies_; jNeut++) { - fm_invert_ionForNeutral[jNeut] = -1; + for (int k = 0; k < m_kk; k++) { + fm_invert_ionForNeutral[k] = -1; } + /* for (int jNeut = 0; jNeut < numNeutralMoleculeSpecies_; jNeut++) { + fm_invert_ionForNeutral[jNeut] = -1; + }*/ for (int jNeut = 0; jNeut < numNeutralMoleculeSpecies_; jNeut++) { for (int m = 0; m < nElementsN; m++) { elemVectorN[m] = neutralMoleculePhase_->nAtoms(jNeut, m); @@ -1185,12 +1351,16 @@ namespace Cantera { } bool notTaken = true; for (int iNeut = 0; iNeut < jNeut; iNeut++) { - if (fm_invert_ionForNeutral[iNeut] == k) { + if (fm_invert_ionForNeutral[k] == iNeut) { notTaken = false; } } if (notTaken) { - fm_invert_ionForNeutral[jNeut] = k; + fm_invert_ionForNeutral[k] = jNeut; + } + else{ + throw CanteraError("IonsFromNeutralVPSSTP::initThermoXML", + "Simple formula matrix generation failed, one cation is shared between two salts"); } } fm_neutralMolec_ions_[k + jNeut * m_kk] += fac; @@ -1243,7 +1413,7 @@ namespace Cantera { icat = cationList_[k]; jNeut = fm_invert_ionForNeutral[icat]; fmij = fm_neutralMolec_ions_[icat + jNeut * m_kk]; - lnActCoeff_Scaled_[icat] = fmij * log(gammaNeutralMolecule_[jNeut]); + lnActCoeff_Scaled_[icat] = log(gammaNeutralMolecule_[jNeut])/fmij; } // Do the anion list @@ -1273,6 +1443,75 @@ namespace Cantera { } + + // get the gradient in the activity coefficients + + void IonsFromNeutralVPSSTP::getdlnActCoeff(const doublereal dT, const doublereal * const dX, doublereal *dlnActCoeff) const { + int k, icat, jNeut; + doublereal fmij; + int numNeutMolSpec; + /* + * Get the activity coefficients of the neutral molecules + */ + GibbsExcessVPSSTP *geThermo = dynamic_cast(neutralMoleculePhase_); + if (!geThermo) { + for ( k = 0; k < m_kk; k++ ){ + dlnActCoeff[k] = dX[k]/moleFractions_[k]; + } + return; + } + + numNeutMolSpec = geThermo->nSpecies(); + vector_fp dlnActCoeff_NeutralMolecule(numNeutMolSpec); + vector_fp dX_NeutralMolecule(numNeutMolSpec); + + + getNeutralMoleculeMoleGrads(DATA_PTR(dX),DATA_PTR(dX_NeutralMolecule)); + + // All mole fractions returned to normal + + geThermo->getdlnActCoeff(dT, DATA_PTR(dX_NeutralMolecule), DATA_PTR(dlnActCoeff_NeutralMolecule)); + + switch (ionSolnType_) { + case cIonSolnType_PASSTHROUGH: + break; + case cIonSolnType_SINGLEANION: + + // Do the cation list + for (k = 0; k < (int) cationList_.size(); k++) { + //! Get the id for the next cation + icat = cationList_[k]; + jNeut = fm_invert_ionForNeutral[icat]; + fmij = fm_neutralMolec_ions_[icat + jNeut * m_kk]; + dlnActCoeff[icat] = dlnActCoeff_NeutralMolecule[jNeut]/fmij; + } + + // Do the anion list + icat = anionList_[0]; + jNeut = fm_invert_ionForNeutral[icat]; + dlnActCoeff[icat]= 0.0; + + // Do the list of neutral molecules + for (k = 0; k < numPassThroughSpecies_; k++) { + icat = passThroughList_[k]; + jNeut = fm_invert_ionForNeutral[icat]; + dlnActCoeff[icat] = dlnActCoeff_NeutralMolecule[jNeut]; + } + break; + + case cIonSolnType_SINGLECATION: + throw CanteraError("IonsFromNeutralVPSSTP::s_update_lnActCoeff", "Unimplemented type"); + break; + case cIonSolnType_MULTICATIONANION: + throw CanteraError("IonsFromNeutralVPSSTP::s_update_lnActCoeff", "Unimplemented type"); + break; + default: + throw CanteraError("IonsFromNeutralVPSSTP::s_update_lnActCoeff", "Unimplemented type"); + break; + } + + } + // Update the temperatture derivative of the ln activity coefficients /* * This function will be called to update the internally storred @@ -1303,7 +1542,7 @@ namespace Cantera { icat = cationList_[k]; jNeut = fm_invert_ionForNeutral[icat]; fmij = fm_neutralMolec_ions_[icat + jNeut * m_kk]; - dlnActCoeffdT_Scaled_[icat] = fmij * dlnActCoeffdT_NeutralMolecule_[jNeut]; + dlnActCoeffdT_Scaled_[icat] = dlnActCoeffdT_NeutralMolecule_[jNeut]/fmij; } // Do the anion list @@ -1336,7 +1575,7 @@ namespace Cantera { * This function will be called to update the internally storred * temperature derivative of the natural logarithm of the activity coefficients */ - void IonsFromNeutralVPSSTP::s_update_dlnActCoeff_dlnC() const { + void IonsFromNeutralVPSSTP::s_update_dlnActCoeff_dlnX() const { int k, icat, jNeut; doublereal fmij; /* @@ -1344,11 +1583,11 @@ namespace Cantera { */ GibbsExcessVPSSTP *geThermo = dynamic_cast(neutralMoleculePhase_); if (!geThermo) { - fvo_zero_dbl_1(dlnActCoeffdlnC_Scaled_, m_kk); + fvo_zero_dbl_1(dlnActCoeffdlnX_Scaled_, m_kk); return; } - geThermo->getdlnActCoeffdlnC(DATA_PTR(dlnActCoeffdlnC_NeutralMolecule_)); + geThermo->getdlnActCoeffdlnX(DATA_PTR(dlnActCoeffdlnX_NeutralMolecule_)); switch (ionSolnType_) { case cIonSolnType_PASSTHROUGH: @@ -1361,19 +1600,19 @@ namespace Cantera { icat = cationList_[k]; jNeut = fm_invert_ionForNeutral[icat]; fmij = fm_neutralMolec_ions_[icat + jNeut * m_kk]; - dlnActCoeffdlnC_Scaled_[icat] = fmij * dlnActCoeffdlnC_NeutralMolecule_[jNeut]; + dlnActCoeffdlnX_Scaled_[icat] = dlnActCoeffdlnX_NeutralMolecule_[jNeut]/fmij; } // Do the anion list icat = anionList_[0]; jNeut = fm_invert_ionForNeutral[icat]; - dlnActCoeffdT_Scaled_[icat]= 0.0; + dlnActCoeffdlnX_Scaled_[icat]= 0.0; // Do the list of neutral molecules for (k = 0; k < numPassThroughSpecies_; k++) { icat = passThroughList_[k]; jNeut = fm_invert_ionForNeutral[icat]; - dlnActCoeffdlnC_Scaled_[icat] = dlnActCoeffdlnC_NeutralMolecule_[jNeut]; + dlnActCoeffdlnX_Scaled_[icat] = dlnActCoeffdlnX_NeutralMolecule_[jNeut]; } break; @@ -1390,83 +1629,62 @@ namespace Cantera { } - /** - * Format a summary of the mixture state for output. - */ - std::string IonsFromNeutralVPSSTP::report(bool show_thermo) const { - - - char p[800]; - string s = ""; - try { - if (name() != "") { - sprintf(p, " \n %s:\n", name().c_str()); - s += p; - } - sprintf(p, " \n temperature %12.6g K\n", temperature()); - s += p; - sprintf(p, " pressure %12.6g Pa\n", pressure()); - s += p; - sprintf(p, " density %12.6g kg/m^3\n", density()); - s += p; - sprintf(p, " mean mol. weight %12.6g amu\n", meanMolecularWeight()); - s += p; - - doublereal phi = electricPotential(); - sprintf(p, " potential %12.6g V\n", phi); - s += p; - - int kk = nSpecies(); - array_fp x(kk); - array_fp molal(kk); - array_fp mu(kk); - array_fp muss(kk); - array_fp acMolal(kk); - array_fp actMolal(kk); - getMoleFractions(&x[0]); - - getChemPotentials(&mu[0]); - getStandardChemPotentials(&muss[0]); - getActivities(&actMolal[0]); - - - if (show_thermo) { - sprintf(p, " \n"); - s += p; - sprintf(p, " 1 kg 1 kmol\n"); - s += p; - sprintf(p, " ----------- ------------\n"); - s += p; - sprintf(p, " enthalpy %12.6g %12.4g J\n", - enthalpy_mass(), enthalpy_mole()); - s += p; - sprintf(p, " internal energy %12.6g %12.4g J\n", - intEnergy_mass(), intEnergy_mole()); - s += p; - sprintf(p, " entropy %12.6g %12.4g J/K\n", - entropy_mass(), entropy_mole()); - s += p; - sprintf(p, " Gibbs function %12.6g %12.4g J\n", - gibbs_mass(), gibbs_mole()); - s += p; - sprintf(p, " heat capacity c_p %12.6g %12.4g J/K\n", - cp_mass(), cp_mole()); - s += p; - try { - sprintf(p, " heat capacity c_v %12.6g %12.4g J/K\n", - cv_mass(), cv_mole()); - s += p; - } - catch(CanteraError) { - sprintf(p, " heat capacity c_v \n"); - s += p; - } - } - - } catch (CanteraError) { - ; + /* + * This function will be called to update the internally storred + * temperature derivative of the natural logarithm of the activity coefficients + */ + void IonsFromNeutralVPSSTP::s_update_dlnActCoeff_dlnN() const { + int k, icat, jNeut; + doublereal fmij; + /* + * Get the activity coefficients of the neutral molecules + */ + GibbsExcessVPSSTP *geThermo = dynamic_cast(neutralMoleculePhase_); + if (!geThermo) { + fvo_zero_dbl_1(dlnActCoeffdlnN_Scaled_, m_kk); + return; } - return s; + + geThermo->getdlnActCoeffdlnN(DATA_PTR(dlnActCoeffdlnN_NeutralMolecule_)); + + switch (ionSolnType_) { + case cIonSolnType_PASSTHROUGH: + break; + case cIonSolnType_SINGLEANION: + + // Do the cation list + for (k = 0; k < (int) cationList_.size(); k++) { + //! Get the id for the next cation + icat = cationList_[k]; + jNeut = fm_invert_ionForNeutral[icat]; + fmij = fm_neutralMolec_ions_[icat + jNeut * m_kk]; + dlnActCoeffdlnN_Scaled_[icat] = dlnActCoeffdlnN_NeutralMolecule_[jNeut]/fmij; + } + + // Do the anion list + icat = anionList_[0]; + jNeut = fm_invert_ionForNeutral[icat]; + dlnActCoeffdlnN_Scaled_[icat]= 0.0; + + // Do the list of neutral molecules + for (k = 0; k < numPassThroughSpecies_; k++) { + icat = passThroughList_[k]; + jNeut = fm_invert_ionForNeutral[icat]; + dlnActCoeffdlnN_Scaled_[icat] = dlnActCoeffdlnN_NeutralMolecule_[jNeut]; + } + break; + + case cIonSolnType_SINGLECATION: + throw CanteraError("IonsFromNeutralVPSSTP::s_update_lnActCoeff", "Unimplemented type"); + break; + case cIonSolnType_MULTICATIONANION: + throw CanteraError("IonsFromNeutralVPSSTP::s_update_lnActCoeff", "Unimplemented type"); + break; + default: + throw CanteraError("IonsFromNeutralVPSSTP::s_update_lnActCoeff", "Unimplemented type"); + break; + } + } diff --git a/Cantera/src/thermo/IonsFromNeutralVPSSTP.h b/Cantera/src/thermo/IonsFromNeutralVPSSTP.h index 88b05e786..2aa23319b 100644 --- a/Cantera/src/thermo/IonsFromNeutralVPSSTP.h +++ b/Cantera/src/thermo/IonsFromNeutralVPSSTP.h @@ -404,6 +404,21 @@ namespace Cantera { */ virtual void getPartialMolarEntropies(doublereal* sbar) const; + //! Get the array of change in the log activity coefficients w.r.t. change in state (change temp, change mole fractions) + /*! + * This function is a virtual class, but it first appears in GibbsExcessVPSSTP + * class and derived classes from GibbsExcessVPSSTP. + * + * This function is a virtual method. For ideal mixtures + * (unity activity coefficients), this can gradX/X. + * + * @param dT Input of temperature change + * @param dX Input vector of changes in mole fraction. length = m_kk + * @param dlnActCoeff Output vector of derivatives of the + * log Activity Coefficients. length = m_kk + */ + virtual void getdlnActCoeff(const doublereal dT, const doublereal * const dX, doublereal *dlnActCoeff) const; + //! Get the array of log concentration-like derivatives of the //! log activity coefficients /*! @@ -411,19 +426,66 @@ namespace Cantera { * (unity activity coefficients), this can return zero. * Implementations should take the derivative of the * logarithm of the activity coefficient with respect to the - * logarithm of the concentration-like variable (i.e. mole fraction, - * molality, etc.) that represents the standard state. + * logarithm of the concentration-like variable (i.e. mole fraction) + * that represents the standard state. * This quantity is to be used in conjunction with derivatives of * that concentration-like variable when the derivative of the chemical * potential is taken. * * units = dimensionless * - * @param dlnActCoeffdlnC Output vector of log(mole fraction) + * @param dlnActCoeffdlnX Output vector of log(mole fraction) * derivatives of the log Activity Coefficients. * length = m_kk */ - virtual void getdlnActCoeffdlnC(doublereal *dlnActCoeffdlnC) const; + virtual void getdlnActCoeffdlnX(doublereal *dlnActCoeffdlnX) const; + + //! Get the array of log concentration-like derivatives of the + //! log activity coefficients + /*! + * This function is a virtual method. For ideal mixtures + * (unity activity coefficients), this can return zero. + * Implementations should take the derivative of the + * logarithm of the activity coefficient with respect to the + * logarithm of the concentration-like variable (i.e. number of moles) + * that represents the standard state. + * This quantity is to be used in conjunction with derivatives of + * that concentration-like variable when the derivative of the chemical + * potential is taken. + * + * units = dimensionless + * + * @param dlnActCoeffdlnN Output vector of log(mole fraction) + * derivatives of the log Activity Coefficients. + * length = m_kk + */ + virtual void getdlnActCoeffdlnN(doublereal *dlnActCoeffdlnN) const; + + //! Get the Salt Dissociation Coefficients + //! Returns the vector of dissociation coefficients and vector of charges + virtual void getDissociationCoeffs(vector_fp& coeffs, vector_fp& charges, std::vector& neutMolIndex); + + virtual void getNeutralMolecMoleFractions(vector_fp& fracs){fracs=NeutralMolecMoleFractions_;} + + //! Calculate neutral molecule mole fractions + /*! + * This routine calculates the neutral molecule mole + * fraction given the vector of ion mole fractions, + * i.e., the mole fractions from this ThermoPhase. + * Note, this routine basically assumes that there + * is charge neutrality. If there isn't, then it wouldn't + * make much sense. + * + * for the case of cIonSolnType_SINGLEANION, some slough + * in the charge neutrality is allowed. The cation number + * is followed, while the difference in charge neutrality + * is dumped into the anion mole number to fix the imbalance. + */ + virtual void getNeutralMoleculeMoleGrads(const doublereal * const x, doublereal *y) const; + + virtual void getCationList(std::vector& cation){cation=cationList_;} + virtual void getAnionList(std::vector& anion){anion=anionList_;} + virtual void getSpeciesNames(std::vector& names){names=m_speciesNames;} //@} @@ -650,14 +712,6 @@ namespace Cantera { */ void initThermoXML(XML_Node& phaseNode, std::string id); - - //! returns a summary of the state of the phase as a string - /*! - * @param show_thermo If true, extra information is printed out - * about the thermodynamic state of the system. - */ - virtual std::string report(bool show_thermo = true) const; - private: @@ -680,6 +734,14 @@ namespace Cantera { */ void s_update_dlnActCoeffdT() const; + //! Update the change in the ln activity coefficients + /*! + * This function will be called to update the internally storred + * change of the natural logarithm of the activity coefficients + * w.r.t a change in state (temp, mole fraction, etc) + */ + void s_update_dlnActCoeff() const; + //! Update the derivative of the log of the activity coefficients //! wrt log(mole fraction) /*! @@ -687,7 +749,16 @@ namespace Cantera { * derivative of the natural logarithm of the activity coefficients * wrt logarithm of the mole fractions. */ - void s_update_dlnActCoeff_dlnC() const; + void s_update_dlnActCoeff_dlnX() const; + + //! Update the derivative of the log of the activity coefficients + //! wrt log(number of moles) + /*! + * This function will be called to update the internally storred + * derivative of the natural logarithm of the activity coefficients + * wrt logarithm of the number of moles of given species. + */ + void s_update_dlnActCoeff_dlnN() const; private: @@ -726,7 +797,7 @@ namespace Cantera { //! Formula Matrix for composition of neutral molecules //! in terms of the molecules in this ThermoPhase /*! - * fm_neutralMolec_ions[ i + jNeut * NumNeut ] + * fm_neutralMolec_ions[ i + jNeut * m_kk ] * * This is the number of ions of type i in the neutral * molecule jNeut. @@ -735,6 +806,11 @@ namespace Cantera { //! Mapping between ion species and neutral molecule for quick invert. /*! + * + * fm_invert_ionForNeutral returns vector of int. Each element represents + * an ionic species and stores the value of the corresponding neutral + * molecule + * * For the case of fm_invert_simple_ = true, we assume that there * is a quick way to invert the formula matrix so that we can * quickly calculate the neutral molecule mole fraction @@ -818,8 +894,10 @@ namespace Cantera { mutable std::vector muNeutralMolecule_; mutable std::vector gammaNeutralMolecule_; + mutable std::vector dlnActCoeff_NeutralMolecule_; mutable std::vector dlnActCoeffdT_NeutralMolecule_; - mutable std::vector dlnActCoeffdlnC_NeutralMolecule_; + mutable std::vector dlnActCoeffdlnX_NeutralMolecule_; + mutable std::vector dlnActCoeffdlnN_NeutralMolecule_; }; diff --git a/Cantera/src/thermo/MargulesVPSSTP.cpp b/Cantera/src/thermo/MargulesVPSSTP.cpp index 2017d8357..0d1ab06dc 100644 --- a/Cantera/src/thermo/MargulesVPSSTP.cpp +++ b/Cantera/src/thermo/MargulesVPSSTP.cpp @@ -19,7 +19,7 @@ #include "MargulesVPSSTP.h" #include "ThermoFactory.h" - +#include using namespace std; @@ -99,6 +99,12 @@ namespace Cantera { m_SE_b_ij = b.m_SE_b_ij; m_SE_c_ij = b.m_SE_c_ij; m_SE_d_ij = b.m_SE_d_ij; + m_VHE_b_ij = b.m_VHE_b_ij; + m_VHE_c_ij = b.m_VHE_c_ij; + m_VHE_d_ij = b.m_VHE_d_ij; + m_VSE_b_ij = b.m_VSE_b_ij; + m_VSE_c_ij = b.m_VSE_c_ij; + m_VSE_d_ij = b.m_VSE_d_ij; m_pSpecies_A_ij = b.m_pSpecies_A_ij; m_pSpecies_B_ij = b.m_pSpecies_B_ij; formMargules_ = b.formMargules_; @@ -154,11 +160,20 @@ namespace Cantera { m_SE_b_ij.resize(1); m_SE_c_ij.resize(1); m_SE_d_ij.resize(1); + + m_VHE_b_ij.resize(1); + m_VHE_c_ij.resize(1); + m_VHE_d_ij.resize(1); + + m_VSE_b_ij.resize(1); + m_VSE_c_ij.resize(1); + m_VSE_d_ij.resize(1); m_pSpecies_A_ij.resize(1); m_pSpecies_B_ij.resize(1); + m_HE_b_ij[0] = -17570E3; m_HE_c_ij[0] = -377.0E3; m_HE_d_ij[0] = 0.0; @@ -166,6 +181,7 @@ namespace Cantera { m_SE_b_ij[0] = -7.627E3; m_SE_c_ij[0] = 4.958E3; m_SE_d_ij[0] = 0.0; + int iLiCl = speciesIndex("LiCl(L)"); if (iLiCl < 0) { @@ -217,7 +233,7 @@ namespace Cantera { */ void MargulesVPSSTP::constructPhaseFile(std::string inputFile, std::string id) { - if (inputFile.size() == 0) { + if ((int) inputFile.size() == 0) { throw CanteraError("MargulesVPSSTP:constructPhaseFile", "input file is null"); } @@ -274,7 +290,7 @@ namespace Cantera { */ void MargulesVPSSTP::constructPhaseXML(XML_Node& phaseNode, std::string id) { string stemp; - if (id.size() > 0) { + if ((int) id.size() > 0) { string idp = phaseNode.id(); if (idp != id) { throw CanteraError("MargulesVPSSTP::constructPhaseXML", @@ -350,7 +366,7 @@ namespace Cantera { * take the exp of the internally storred coefficients. */ for (int k = 0; k < m_kk; k++) { - ac[k] = exp(lnActCoeff_Scaled_[k]); + ac[k] = exp(lnActCoeff_Scaled_[k]); } } @@ -472,7 +488,56 @@ namespace Cantera { } } - + /* + * ------------ Partial Molar Properties of the Solution ------------ + */ + + // Return an array of partial molar volumes for the + // species in the mixture. Units: m^3/kmol. + /* + * Frequently, for this class of thermodynamics representations, + * the excess Volume due to mixing is zero. Here, we set it as + * a default. It may be overriden in derived classes. + * + * @param vbar Output vector of speciar partial molar volumes. + * Length = m_kk. units are m^3/kmol. + */ + void MargulesVPSSTP::getPartialMolarVolumes(doublereal* vbar) const { + + int iA, iB, iK, delAK, delBK; + double XA, XB, XK, g0 , g1; + double T = temperature(); + + /* + * Get the standard state values in m^3 kmol-1 + */ + getStandardVolumes(vbar); + //cout << "species name(0) = " << speciesName(0) << endl; + //cout << "iA = " << speciesName(m_pSpecies_A_ij[0]) << endl; + //cout << "iB = " << speciesName(m_pSpecies_B_ij[0]) << endl; + + for ( iK = 0; iK < m_kk; iK++ ){ + delAK = 0; + delBK = 0; + XK = moleFractions_[iK]; + for (int i = 0; i < numBinaryInteractions_; i++) { + + iA = m_pSpecies_A_ij[i]; + iB = m_pSpecies_B_ij[i]; + + if (iA==iK) delAK = 1; + else if (iB==iK) delBK = 1; + + XA = moleFractions_[iA]; + XB = moleFractions_[iB]; + + g0 = (m_VHE_b_ij[i] - T * m_VSE_b_ij[i]); + g1 = (m_VHE_c_ij[i] - T * m_VSE_c_ij[i]); + + vbar[iK] += XA*XB*(g0+g1*XB)+((delAK-XA)*XB+XA*(delBK-XB))*(g0+g1*XB)+XA*XB*(delBK-XB)*g1; + } + } + } doublereal MargulesVPSSTP::err(std::string msg) const { throw CanteraError("MargulesVPSSTP","Base class method " @@ -583,14 +648,54 @@ namespace Cantera { } + // Update the activity coefficients /* * This function will be called to update the internally storred * natural logarithm of the activity coefficients * - * he = X_A X_B(B + C(X_A - X_B)) + * he = X_A X_B(B + C X_B) */ + void MargulesVPSSTP::s_update_lnActCoeff() const { + int iA, iB, iK, delAK, delBK; + double XA, XB, XK, g0 , g1; + double T = temperature(); + double RT = GasConstant*T; + + fvo_zero_dbl_1(lnActCoeff_Scaled_, m_kk); + + for ( iK = 0; iK < m_kk; iK++ ){ + + XK = moleFractions_[iK]; + + for (int i = 0; i < numBinaryInteractions_; i++) { + + iA = m_pSpecies_A_ij[i]; + iB = m_pSpecies_B_ij[i]; + + delAK = 0; + delBK = 0; + + if (iA==iK) delAK = 1; + else if (iB==iK) delBK = 1; + + XA = moleFractions_[iA]; + XB = moleFractions_[iB]; + + g0 = (m_HE_b_ij[i] - T * m_SE_b_ij[i]) / RT; + g1 = (m_HE_c_ij[i] - T * m_SE_c_ij[i]) / RT; + + lnActCoeff_Scaled_[iK] += (delAK*XB+XA*delBK-XA*XB)*(g0+g1*XB)+XA*XB*(delBK-XB)*g1; + //lnActCoeff_Scaled_[iK] += XA*XB*(g0+g1*XB)+((delAK-XA)*XB+XA*(delBK-XB))*(g0+g1*XB)+XA*XB*(delBK-XB)*g1; + } + } + } + + + /* + // Not Right??? void MargulesVPSSTP::s_update_lnActCoeff() const { + int iA, iB; double XA, XB, g0 , g1; double T = temperature(); @@ -612,15 +717,52 @@ namespace Cantera { lnActCoeff_Scaled_[iB] += XA * XA * g0 + XA * XB * g1 * (2 * XA); } } + */ // Update the derivative of the log of the activity coefficients wrt T /* * This function will be called to update the internally storred * natural logarithm of the activity coefficients * - * he = X_A X_B(B + C(X_A - X_B)) + * he = X_A X_B(B + C X_B) */ void MargulesVPSSTP::s_update_dlnActCoeff_dT() const { + int iA, iB, iK, delAK, delBK; + double XA, XB, XK, g0 , g1; + double T = temperature(); + double RTT = GasConstant*T*T; + + fvo_zero_dbl_1(dlnActCoeffdT_Scaled_, m_kk); + + for ( iK = 0; iK < m_kk; iK++ ){ + + XK = moleFractions_[iK]; + + for (int i = 0; i < numBinaryInteractions_; i++) { + + iA = m_pSpecies_A_ij[i]; + iB = m_pSpecies_B_ij[i]; + + delAK = 0; + delBK = 0; + + if (iA==iK) delAK = 1; + else if (iB==iK) delBK = 1; + + XA = moleFractions_[iA]; + XB = moleFractions_[iB]; + + g0 = -m_HE_b_ij[i] / RTT; + g1 = -m_HE_c_ij[i] / RTT; + + dlnActCoeffdT_Scaled_[iK] += (delAK*XB+XA*delBK-XA*XB)*(g0+g1*XB)+XA*XB*(delBK-XB)*g1; + } + } + } + + /* Not Right??? + void MargulesVPSSTP::s_update_dlnActCoeff_dT() const {} + int iA, iB; doublereal XA, XB, h0 , h1; doublereal T = temperature(); @@ -642,6 +784,7 @@ namespace Cantera { dlnActCoeffdT_Scaled_[iB] += -(XA * XA * h0 + XA * XB * h1 * (2 * XA))/RTT; } } + */ void MargulesVPSSTP::getdlnActCoeffdT(doublereal *dlnActCoeffdT) const { s_update_dlnActCoeff_dT(); @@ -650,22 +793,123 @@ namespace Cantera { } } + // calculate the change of the log of the activity coefficients wrt change in state: dT, dX + /* + * This function will be called to calculate gradient of the + * logarithm of the activity coefficients based on gradients in temperature and mole fraction. + * + * he = X_A X_B(B + C X_B) + */ + void MargulesVPSSTP::getdlnActCoeff(const doublereal dT, const doublereal * const dX, doublereal* dlnActCoeff) const { + int iA, iB, iK, delAK, delBK; + double XA, XB, XK, g0 , g1, dXA, dXB; + double T = temperature(); + double RT = GasConstant*T; + + //fvo_zero_dbl_1(dlnActCoeff, m_kk); + s_update_dlnActCoeff_dT(); + + for ( iK = 0; iK < m_kk; iK++ ){ + + XK = moleFractions_[iK]; + dlnActCoeff[iK] = 0.0; + + for (int i = 0; i < numBinaryInteractions_; i++) { + + iA = m_pSpecies_A_ij[i]; + iB = m_pSpecies_B_ij[i]; + + delAK = 0; + delBK = 0; + + if (iA==iK) delAK = 1; + else if (iB==iK) delBK = 1; + + XA = moleFractions_[iA]; + XB = moleFractions_[iB]; + + dXA = dX[iA]; + dXB = dX[iB]; + + g0 = (m_HE_b_ij[i] - T * m_SE_b_ij[i]) / RT; + g1 = (m_HE_c_ij[i] - T * m_SE_c_ij[i]) / RT; + + dlnActCoeff[iK] += ((delBK-XB)*dXA + (delAK-XA)*dXB)*(g0+2*g1*XB) + (delBK-XB)*2*g1*XA*dXB + dlnActCoeffdT_Scaled_[iK]*dT; + } + } + } + // Update the derivative of the log of the activity coefficients wrt ln(X) /* * This function will be called to update the internally stored gradients of the * logarithm of the activity coefficients. These are used in the determination * of the diffusion coefficients. * - * he = X_A X_B(B + C(X_A - X_B)) + * he = X_A X_B(B + C X_B) */ - void MargulesVPSSTP::s_update_dlnActCoeff_dlnC() const { + void MargulesVPSSTP::s_update_dlnActCoeff_dlnN() const { + int iA, iB, iK, delAK, delBK; + double XA, XB, XK, g0 , g1; + double T = temperature(); + double RT = GasConstant*T; + + fvo_zero_dbl_1(dlnActCoeffdlnN_Scaled_, m_kk); + + for ( iK = 0; iK < m_kk; iK++ ){ + + XK = moleFractions_[iK]; + + for (int i = 0; i < numBinaryInteractions_; i++) { + + iA = m_pSpecies_A_ij[i]; + iB = m_pSpecies_B_ij[i]; + + delAK = 0; + delBK = 0; + + if (iA==iK) delAK = 1; + else if (iB==iK) delBK = 1; + + XA = moleFractions_[iA]; + XB = moleFractions_[iB]; + + g0 = (m_HE_b_ij[i] - T * m_SE_b_ij[i]) / RT; + g1 = (m_HE_c_ij[i] - T * m_SE_c_ij[i]) / RT; + + dlnActCoeffdlnN_Scaled_[iK] += 2*(delBK-XB) * (g0*(delAK-XA) + g1*(2*(delAK-XA)*XB + XA*(delBK-XB))); + } + dlnActCoeffdlnN_Scaled_[iK] = XK*dlnActCoeffdlnN_Scaled_[iK]-XK; + } + } + + void MargulesVPSSTP::s_update_dlnActCoeff_dlnX() const { + int iA, iB; doublereal XA, XB, g0 , g1; doublereal T = temperature(); - fvo_zero_dbl_1(dlnActCoeffdlnC_Scaled_, m_kk); + fvo_zero_dbl_1(dlnActCoeffdlnX_Scaled_, m_kk); doublereal RT = GasConstant * T; + + + for (int i = 0; i < numBinaryInteractions_; i++) { + + iA = m_pSpecies_A_ij[i]; + iB = m_pSpecies_B_ij[i]; + + XA = moleFractions_[iA]; + XB = moleFractions_[iB]; + + g0 = (m_HE_b_ij[i] - T * m_SE_b_ij[i]) / RT; + g1 = (m_HE_c_ij[i] - T * m_SE_c_ij[i]) / RT; + + dlnActCoeffdlnX_Scaled_[iA] += XA*XB*(2*g1*-2*g0-6*g1*XB); + dlnActCoeffdlnX_Scaled_[iB] += XA*XB*(2*g1*-2*g0-6*g1*XB); + } + + /* + // Wrong!!! for (int i = 0; i < numBinaryInteractions_; i++) { iA = m_pSpecies_A_ij[i]; iB = m_pSpecies_B_ij[i]; @@ -676,17 +920,25 @@ namespace Cantera { g0 = (m_HE_b_ij[i] - T * m_SE_b_ij[i]) / RT ; g1 = (m_HE_c_ij[i] - T * m_SE_c_ij[i]) / RT; - dlnActCoeffdlnC_Scaled_[iA] += XA * ( ( - 2.0 + 2.0 * XA ) * g0 + dlnActCoeffdlnX_Scaled_[iA] += XA * ( ( - 2.0 + 2.0 * XA ) * g0 + ( - 4.0 + 10.0 * XA - 6.0 * XA*XA ) * g1 ) ; - dlnActCoeffdlnC_Scaled_[iB] += XB * ( ( - 2.0 + 2.0 * XB ) * g0 + dlnActCoeffdlnX_Scaled_[iB] += XB * ( ( - 2.0 + 2.0 * XB ) * g0 + ( 2.0 - 8.0 * XB + 6.0 * XB*XB ) * g1 ) ; } + */ } + - void MargulesVPSSTP::getdlnActCoeffdlnC(doublereal *dlnActCoeffdlnC) const { - s_update_dlnActCoeff_dlnC(); + void MargulesVPSSTP::getdlnActCoeffdlnN(doublereal *dlnActCoeffdlnN) const { + s_update_dlnActCoeff_dlnN(); for (int k = 0; k < m_kk; k++) { - dlnActCoeffdlnC[k] = dlnActCoeffdlnC_Scaled_[k]; + dlnActCoeffdlnN[k] = dlnActCoeffdlnN_Scaled_[k]; + } + } + void MargulesVPSSTP::getdlnActCoeffdlnX(doublereal *dlnActCoeffdlnX) const { + s_update_dlnActCoeff_dlnX(); + for (int k = 0; k < m_kk; k++) { + dlnActCoeffdlnX[k] = dlnActCoeffdlnX_Scaled_[k]; } } @@ -699,6 +951,12 @@ namespace Cantera { m_SE_b_ij.resize(num, 0.0); m_SE_c_ij.resize(num, 0.0); m_SE_d_ij.resize(num, 0.0); + m_VHE_b_ij.resize(num, 0.0); + m_VHE_c_ij.resize(num, 0.0); + m_VHE_d_ij.resize(num, 0.0); + m_VSE_b_ij.resize(num, 0.0); + m_VSE_c_ij.resize(num, 0.0); + m_VSE_d_ij.resize(num, 0.0); m_pSpecies_A_ij.resize(num, -1); m_pSpecies_B_ij.resize(num, -1); @@ -769,7 +1027,7 @@ namespace Cantera { /* * Get the string containing all of the values */ - getFloatArray(xmlChild, vParams, true, "", "excessEnthalpy"); + getFloatArray(xmlChild, vParams, true, "toSI", "excessEnthalpy"); nParamsFound = vParams.size(); if (nParamsFound != 2) { @@ -785,7 +1043,7 @@ namespace Cantera { /* * Get the string containing all of the values */ - getFloatArray(xmlChild, vParams, true, "", "excessEntropy"); + getFloatArray(xmlChild, vParams, true, "toSI", "excessEntropy"); nParamsFound = vParams.size(); if (nParamsFound != 2) { @@ -797,90 +1055,42 @@ namespace Cantera { m_SE_c_ij[iSpot] = vParams[1]; } + if (nodeName == "excessvolume_enthalpy") { + /* + * Get the string containing all of the values + */ + getFloatArray(xmlChild, vParams, true, "toSI", "excessVolume_Enthalpy"); + nParamsFound = vParams.size(); + + if (nParamsFound != 2) { + throw CanteraError("MargulesVPSSTP::readXMLBinarySpecies::excessVolume_Enthalpy for " + ispName + + "::" + jspName, + "wrong number of params found"); + } + m_VHE_b_ij[iSpot] = vParams[0]; + m_VHE_c_ij[iSpot] = vParams[1]; + } + + if (nodeName == "excessvolume_entropy") { + /* + * Get the string containing all of the values + */ + getFloatArray(xmlChild, vParams, true, "toSI", "excessVolume_Entropy"); + nParamsFound = vParams.size(); + + if (nParamsFound != 2) { + throw CanteraError("MargulesVPSSTP::readXMLBinarySpecies::excessVolume_Entropy for " + ispName + + "::" + jspName, + "wrong number of params found"); + } + m_VSE_b_ij[iSpot] = vParams[0]; + m_VSE_c_ij[iSpot] = vParams[1]; + } + } } - - /** - * Format a summary of the mixture state for output. - */ - std::string MargulesVPSSTP::report(bool show_thermo) const { - - - char p[800]; - string s = ""; - try { - if (name() != "") { - sprintf(p, " \n %s:\n", name().c_str()); - s += p; - } - sprintf(p, " \n temperature %12.6g K\n", temperature()); - s += p; - sprintf(p, " pressure %12.6g Pa\n", pressure()); - s += p; - sprintf(p, " density %12.6g kg/m^3\n", density()); - s += p; - sprintf(p, " mean mol. weight %12.6g amu\n", meanMolecularWeight()); - s += p; - - doublereal phi = electricPotential(); - sprintf(p, " potential %12.6g V\n", phi); - s += p; - - int kk = nSpecies(); - array_fp x(kk); - array_fp molal(kk); - array_fp mu(kk); - array_fp muss(kk); - array_fp acMolal(kk); - array_fp actMolal(kk); - getMoleFractions(&x[0]); - - getChemPotentials(&mu[0]); - getStandardChemPotentials(&muss[0]); - getActivities(&actMolal[0]); - - - if (show_thermo) { - sprintf(p, " \n"); - s += p; - sprintf(p, " 1 kg 1 kmol\n"); - s += p; - sprintf(p, " ----------- ------------\n"); - s += p; - sprintf(p, " enthalpy %12.6g %12.4g J\n", - enthalpy_mass(), enthalpy_mole()); - s += p; - sprintf(p, " internal energy %12.6g %12.4g J\n", - intEnergy_mass(), intEnergy_mole()); - s += p; - sprintf(p, " entropy %12.6g %12.4g J/K\n", - entropy_mass(), entropy_mole()); - s += p; - sprintf(p, " Gibbs function %12.6g %12.4g J\n", - gibbs_mass(), gibbs_mole()); - s += p; - sprintf(p, " heat capacity c_p %12.6g %12.4g J/K\n", - cp_mass(), cp_mole()); - s += p; - try { - sprintf(p, " heat capacity c_v %12.6g %12.4g J/K\n", - cv_mass(), cv_mole()); - s += p; - } - catch(CanteraError) { - sprintf(p, " heat capacity c_v \n"); - s += p; - } - } - - } catch (CanteraError) { - ; - } - return s; - } - } diff --git a/Cantera/src/thermo/MargulesVPSSTP.h b/Cantera/src/thermo/MargulesVPSSTP.h index e9044b1bb..b75594c76 100644 --- a/Cantera/src/thermo/MargulesVPSSTP.h +++ b/Cantera/src/thermo/MargulesVPSSTP.h @@ -78,18 +78,20 @@ namespace Cantera { *

Specification of Solution Thermodynamic Properties

*
* - * The excess Gibbs free energy + * The excess Gibbs free energy (expressed as an extrinsic thermodynamic + * variable) is given by the following formula: * * \f[ - * G^E = \sum_i \left( H_{Ei} - T S_{Ei} \right) + * G^E = \sum_i \left( H_{Ei} - T S_{Ei} \right) * \f] * \f[ - * H^E_i = X_{Ai} X_{Bi} \left( h_{o,i} + h_{1,i} X_{Bi} \right) + * H^E_i = n X_{Ai} X_{Bi} \left( h_{o,i} + h_{1,i} X_{Bi} \right) * \f] * \f[ - * S^E_i = X_{Ai} X_{Bi} \left( s_{o,i} + s_{1,i} X_{Bi} \right) + * S^E_i = n X_{Ai} X_{Bi} \left( s_{o,i} + s_{1,i} X_{Bi} \right) * \f] * + * where n is the total moles in the solution. * * The activity of a species defined in the phase is given by an excess * Gibbs free energy formulation. @@ -565,6 +567,18 @@ namespace Cantera { virtual void getPartialMolarEntropies(doublereal* sbar) const; + //! Return an array of partial molar volumes for the + //! species in the mixture. Units: m^3/kmol. + /*! + * Frequently, for this class of thermodynamics representations, + * the excess Volume due to mixing is zero. Here, we set it as + * a default. It may be overriden in derived classes. + * + * @param vbar Output vector of speciar partial molar volumes. + * Length = m_kk. units are m^3/kmol. + */ + virtual void getPartialMolarVolumes(doublereal* vbar) const; + //! Get the species electrochemical potentials. /*! * These are partial molar quantities. @@ -579,6 +593,19 @@ namespace Cantera { void getElectrochemPotentials(doublereal* mu) const; + //! Get the array of change in the log activity coefficients with change in state (change temp, change mole fractions) + /*! + * This function is a virtual class, but it first appears in GibbsExcessVPSSTP + * class and derived classes from GibbsExcessVPSSTP. + * + * units = 1/Kelvin + * + * @param dlnActCoeff Output vector of temperature derivatives of the + * log Activity Coefficients. length = m_kk + * + */ + virtual void getdlnActCoeff(const doublereal dT, const doublereal * const dX, doublereal *dlnActCoeffdT) const; + //! Get the array of temperature derivatives of the log activity coefficients /*! * This function is a virtual class, but it first appears in GibbsExcessVPSSTP @@ -603,16 +630,17 @@ namespace Cantera { * logarithm of the concentration-like variable (i.e. mole fraction, * molality, etc.) that represents the standard state. * This quantity is to be used in conjunction with derivatives of - * that concentration-like variable when the derivative of the chemical + j that concentration-like variable when the derivative of the chemical * potential is taken. * * units = dimensionless * - * @param dlnActCoeffdlnC Output vector of log(mole fraction) + * @param dlnActCoeffdlnX Output vector of log(mole fraction) * derivatives of the log Activity Coefficients. * length = m_kk */ - virtual void getdlnActCoeffdlnC(doublereal *dlnActCoeffdlnC) const; + virtual void getdlnActCoeffdlnX(doublereal *dlnActCoeffdlnX) const; + virtual void getdlnActCoeffdlnN(doublereal *dlnActCoeffdlnN) const; //@} @@ -703,15 +731,6 @@ namespace Cantera { */ void initThermoXML(XML_Node& phaseNode, std::string id); - - - //! returns a summary of the state of the phase as a string - /*! - * @param show_thermo If true, extra information is printed out - * about the thermodynamic state of the system. - */ - virtual std::string report(bool show_thermo = true) const; - private: @@ -761,7 +780,16 @@ namespace Cantera { * derivative of the natural logarithm of the activity coefficients * wrt logarithm of the mole fractions. */ - void s_update_dlnActCoeff_dlnC() const; + void s_update_dlnActCoeff_dlnX() const; + + //! Update the derivative of the log of the activity coefficients + //! wrt log(moles) + /*! + * This function will be called to update the internally storred + * derivative of the natural logarithm of the activity coefficients + * wrt logarithm of the moles. + */ + void s_update_dlnActCoeff_dlnN() const; private: @@ -802,6 +830,30 @@ namespace Cantera { //! Entropy term for the quaternary mole fraction interaction of the //! excess gibbs free energy expression mutable vector_fp m_SE_d_ij; + + //! Enthalpy term for the binary mole fraction interaction of the + //! excess gibbs free energy expression + mutable vector_fp m_VHE_b_ij; + + //! Enthalpy term for the ternary mole fraction interaction of the + //! excess gibbs free energy expression + mutable vector_fp m_VHE_c_ij; + + //! Enthalpy term for the quaternary mole fraction interaction of the + //! excess gibbs free energy expression + mutable vector_fp m_VHE_d_ij; + + //! Entropy term for the binary mole fraction interaction of the + //! excess gibbs free energy expression + mutable vector_fp m_VSE_b_ij; + + //! Entropy term for the ternary mole fraction interaction of the + //! excess gibbs free energy expression + mutable vector_fp m_VSE_c_ij; + + //! Entropy term for the quaternary mole fraction interaction of the + //! excess gibbs free energy expression + mutable vector_fp m_VSE_d_ij; //! vector of species indices representing species A in the interaction /*! diff --git a/Cantera/src/thermo/MolalityVPSSTP.cpp b/Cantera/src/thermo/MolalityVPSSTP.cpp index 285289a9e..da2a30e60 100644 --- a/Cantera/src/thermo/MolalityVPSSTP.cpp +++ b/Cantera/src/thermo/MolalityVPSSTP.cpp @@ -24,6 +24,7 @@ #include "MolalityVPSSTP.h" +#include using namespace std; namespace Cantera { @@ -910,6 +911,150 @@ namespace Cantera { return s; } + /* + * Format a summary of the mixture state for output. + */ + void MolalityVPSSTP::reportCSV(std::ofstream& csvFile) const { + + + csvFile.precision(3); + int tabS = 15; + int tabM = 30; + int tabL = 40; + try { + if (name() != "") { + csvFile << "\n"+name()+"\n\n"; + } + csvFile << setw(tabL) << "temperature (K) =" << setw(tabS) << temperature() << endl; + csvFile << setw(tabL) << "pressure (Pa) =" << setw(tabS) << pressure() << endl; + csvFile << setw(tabL) << "density (kg/m^3) =" << setw(tabS) << density() << endl; + csvFile << setw(tabL) << "mean mol. weight (amu) =" << setw(tabS) << meanMolecularWeight() << endl; + csvFile << setw(tabL) << "potential (V) =" << setw(tabS) << electricPotential() << endl; + csvFile << endl; + + csvFile << setw(tabL) << "enthalpy (J/kg) = " << setw(tabS) << enthalpy_mass() << setw(tabL) << "enthalpy (J/kmol) = " << setw(tabS) << enthalpy_mole() << endl; + csvFile << setw(tabL) << "internal E (J/kg) = " << setw(tabS) << intEnergy_mass() << setw(tabL) << "internal E (J/kmol) = " << setw(tabS) << intEnergy_mole() << endl; + csvFile << setw(tabL) << "entropy (J/kg) = " << setw(tabS) << entropy_mass() << setw(tabL) << "entropy (J/kmol) = " << setw(tabS) << entropy_mole() << endl; + csvFile << setw(tabL) << "Gibbs (J/kg) = " << setw(tabS) << gibbs_mass() << setw(tabL) << "Gibbs (J/kmol) = " << setw(tabS) << gibbs_mole() << endl; + csvFile << setw(tabL) << "heat capacity c_p (J/K/kg) = " << setw(tabS) << cp_mass() << setw(tabL) << "heat capacity c_p (J/K/kmol) = " << setw(tabS) << cp_mole() << endl; + csvFile << setw(tabL) << "heat capacity c_v (J/K/kg) = " << setw(tabS) << cv_mass() << setw(tabL) << "heat capacity c_v (J/K/kmol) = " << setw(tabS) << cv_mole() << endl; + + csvFile.precision(8); + + int kk = nSpecies(); + double x[kk]; + double molal[kk]; + double mu[kk]; + double muss[kk]; + double aMolal[kk]; + double acMolal[kk]; + double hbar[kk]; + double sbar[kk]; + double ubar[kk]; + double cpbar[kk]; + double vbar[kk]; + vector pNames; + vector data; + + getMoleFractions(x); + pNames.push_back("X"); + data.push_back(x); + try{ + getMolalities(molal); + pNames.push_back("Molal"); + data.push_back(molal); + } + catch (CanteraError) {;} + try{ + getChemPotentials(mu); + pNames.push_back("Chem. Pot. (J/kmol)"); + data.push_back(mu); + } + catch (CanteraError) {;} + try{ + getStandardChemPotentials(muss); + pNames.push_back("Chem. Pot. SS (J/kmol)"); + data.push_back(muss); + } + catch (CanteraError) {;} + try{ + getMolalityActivityCoefficients(acMolal); + pNames.push_back("Molal Act. Coeff."); + data.push_back(acMolal); + } + catch (CanteraError) {;} + try{ + getActivities(aMolal); + pNames.push_back("Molal Activity"); + data.push_back(aMolal); + int iHp = speciesIndex("H+"); + if (iHp >= 0) { + double pH = -log(aMolal[iHp]) / log(10.0); + csvFile << setw(tabL) << "pH = " << setw(tabS) << pH << endl; + } + } + catch (CanteraError) {;} + try{ + getPartialMolarEnthalpies(hbar); + pNames.push_back("Part. Mol Enthalpy (J/kmol)"); + data.push_back(hbar); + } + catch (CanteraError) {;} + try{ + getPartialMolarEntropies(sbar); + pNames.push_back("Part. Mol. Entropy (J/K/kmol)"); + data.push_back(sbar); + } + catch (CanteraError) {;} + try{ + getPartialMolarIntEnergies(ubar); + pNames.push_back("Part. Mol. Energy (J/kmol)"); + data.push_back(ubar); + } + catch (CanteraError) {;} + try{ + getPartialMolarCp(cpbar); + pNames.push_back("Part. Mol. Cp (J/K/kmol"); + data.push_back(cpbar); + } + catch (CanteraError) {;} + try{ + getPartialMolarVolumes(vbar); + pNames.push_back("Part. Mol. Cv (J/K/kmol)"); + data.push_back(vbar); + } + catch (CanteraError) {;} + + csvFile << endl << setw(tabS) << "Species,"; + for ( int i = 0; i < (int)pNames.size(); i++ ){ + csvFile << setw(tabM) << pNames[i] << ","; + } + csvFile << endl; + /* + csvFile.fill('-'); + csvFile << setw(tabS+(tabM+1)*pNames.size()) << "-\n"; + csvFile.fill(' '); + */ + for (int k = 0; k < kk; k++) { + csvFile << setw(tabS) << speciesName(k) + ","; + if (x[k] > SmallNumber) { + for ( int i = 0; i < (int)pNames.size(); i++ ){ + csvFile << setw(tabM) << data[i][k] << ","; + } + csvFile << endl; + } + else{ + for ( int i = 0; i < (int)pNames.size(); i++ ){ + csvFile << setw(tabM) << 0 << ","; + } + csvFile << endl; + } + } + } + catch (CanteraError) { + ; + } + } } diff --git a/Cantera/src/thermo/MolalityVPSSTP.h b/Cantera/src/thermo/MolalityVPSSTP.h index f9eb439d9..60ea18feb 100644 --- a/Cantera/src/thermo/MolalityVPSSTP.h +++ b/Cantera/src/thermo/MolalityVPSSTP.h @@ -800,6 +800,14 @@ namespace Cantera { */ virtual std::string report(bool show_thermo = true) const; + //! returns a summary of the state of the phase to specified + //! comma separated files + /*! + * @param csvFile ofstream file to print comma separated data for + * the phase + */ + virtual void reportCSV(std::ofstream& csvFile) const; + protected: //! Get the array of unscaled non-dimensional molality based diff --git a/Cantera/src/thermo/PDSS_SSVol.cpp b/Cantera/src/thermo/PDSS_SSVol.cpp index 71ae96fd0..4ca9cd46f 100644 --- a/Cantera/src/thermo/PDSS_SSVol.cpp +++ b/Cantera/src/thermo/PDSS_SSVol.cpp @@ -134,14 +134,14 @@ namespace Cantera { m_constMolarVolume = getFloat(*ss, "molarVolume", "toSI"); } else if (model == "temperature_polynomial") { volumeModel_ = cSSVOLUME_TPOLY; - int num = getFloatArray(*ss, TCoeff_, true, "", "volumeTemperaturePolynomial"); + int num = getFloatArray(*ss, TCoeff_, true, "toSI", "volumeTemperaturePolynomial"); if (num != 4) { throw CanteraError("PDSS_SSVol::constructPDSSXML", " Didn't get 4 density polynomial numbers for species " + speciesNode.name()); } } else if (model == "density_temperature_polynomial") { volumeModel_ = cSSVOLUME_DENSITY_TPOLY; - int num = getFloatArray(*ss, TCoeff_, true, "", "densityTemperaturePolynomial"); + int num = getFloatArray(*ss, TCoeff_, true, "toSI", "densityTemperaturePolynomial"); if (num != 4) { throw CanteraError("PDSS_SSVol::constructPDSSXML", " Didn't get 4 density polynomial numbers for species " + speciesNode.name()); diff --git a/Cantera/src/thermo/PureFluidPhase.cpp b/Cantera/src/thermo/PureFluidPhase.cpp index a0748e18c..b5e8b96ff 100644 --- a/Cantera/src/thermo/PureFluidPhase.cpp +++ b/Cantera/src/thermo/PureFluidPhase.cpp @@ -17,6 +17,7 @@ #include "../../../ext/tpx/utils.h" #include +#include namespace Cantera { @@ -427,8 +428,144 @@ namespace Cantera { } return s; } + + /* + * Format a summary of the mixture state for output. + */ + void PureFluidPhase::reportCSV(std::ofstream& csvFile) const { + + + csvFile.precision(3); + int tabS = 15; + int tabM = 30; + int tabL = 40; + try { + if (name() != "") { + csvFile << "\n"+name()+"\n\n"; + } + csvFile << setw(tabL) << "temperature (K) =" << setw(tabS) << temperature() << endl; + csvFile << setw(tabL) << "pressure (Pa) =" << setw(tabS) << pressure() << endl; + csvFile << setw(tabL) << "density (kg/m^3) =" << setw(tabS) << density() << endl; + csvFile << setw(tabL) << "mean mol. weight (amu) =" << setw(tabS) << meanMolecularWeight() << endl; + csvFile << setw(tabL) << "potential (V) =" << setw(tabS) << electricPotential() << endl; + if (eosType() == cPureFluid) { + double xx = ((PureFluidPhase *) (this))->vaporFraction(); + csvFile << setw(tabL) << "vapor fraction = " << setw(tabS) << xx << endl; + } + csvFile << endl; + + csvFile << setw(tabL) << "enthalpy (J/kg) = " << setw(tabS) << enthalpy_mass() << setw(tabL) << "enthalpy (J/kmol) = " << setw(tabS) << enthalpy_mole() << endl; + csvFile << setw(tabL) << "internal E (J/kg) = " << setw(tabS) << intEnergy_mass() << setw(tabL) << "internal E (J/kmol) = " << setw(tabS) << intEnergy_mole() << endl; + csvFile << setw(tabL) << "entropy (J/kg) = " << setw(tabS) << entropy_mass() << setw(tabL) << "entropy (J/kmol) = " << setw(tabS) << entropy_mole() << endl; + csvFile << setw(tabL) << "Gibbs (J/kg) = " << setw(tabS) << gibbs_mass() << setw(tabL) << "Gibbs (J/kmol) = " << setw(tabS) << gibbs_mole() << endl; + csvFile << setw(tabL) << "heat capacity c_p (J/K/kg) = " << setw(tabS) << cp_mass() << setw(tabL) << "heat capacity c_p (J/K/kmol) = " << setw(tabS) << cp_mole() << endl; + csvFile << setw(tabL) << "heat capacity c_v (J/K/kg) = " << setw(tabS) << cv_mass() << setw(tabL) << "heat capacity c_v (J/K/kmol) = " << setw(tabS) << cv_mole() << endl; + + csvFile.precision(8); + + int kk = nSpecies(); + std::vector x(kk, 0.0); + std::vector y(kk, 0.0); + std::vector mu(kk, 0.0); + std::vector a(kk, 0.0); + std::vector ac(kk, 0.0); + std::vector hbar(kk, 0.0); + std::vector sbar(kk, 0.0); + std::vector ubar(kk, 0.0); + std::vector cpbar(kk, 0.0); + std::vector vbar(kk, 0.0); + vector pNames; + vector data; + + getMoleFractions(DATA_PTR(x)); + pNames.push_back("X"); + data.push_back(DATA_PTR(x)); + try{ + getMassFractions(DATA_PTR(y)); + pNames.push_back("Y"); + data.push_back(DATA_PTR(y)); + } + catch (CanteraError) {;} + try{ + getChemPotentials(DATA_PTR(mu)); + pNames.push_back("Chem. Pot (J/kmol)"); + data.push_back(DATA_PTR(mu)); + } + catch (CanteraError) {;} + try{ + getActivities(DATA_PTR(a)); + pNames.push_back("Activity"); + data.push_back(DATA_PTR(a)); + } + catch (CanteraError) {;} + try{ + getActivityCoefficients(DATA_PTR(ac)); + pNames.push_back("Act. Coeff."); + data.push_back(DATA_PTR(ac)); + } + catch (CanteraError) {;} + try{ + getPartialMolarEnthalpies(DATA_PTR(hbar)); + pNames.push_back("Part. Mol Enthalpy (J/kmol)"); + data.push_back(DATA_PTR(hbar)); + } + catch (CanteraError) {;} + try{ + getPartialMolarEntropies(DATA_PTR(sbar)); + pNames.push_back("Part. Mol. Entropy (J/K/kmol)"); + data.push_back(DATA_PTR(sbar)); + } + catch (CanteraError) {;} + try{ + getPartialMolarIntEnergies(DATA_PTR(ubar)); + pNames.push_back("Part. Mol. Energy (J/kmol)"); + data.push_back(DATA_PTR(ubar)); + } + catch (CanteraError) {;} + try{ + getPartialMolarCp(DATA_PTR(cpbar)); + pNames.push_back("Part. Mol. Cp (J/K/kmol"); + data.push_back(DATA_PTR(cpbar)); + } + catch (CanteraError) {;} + try{ + getPartialMolarVolumes(DATA_PTR(vbar)); + pNames.push_back("Part. Mol. Cv (J/K/kmol)"); + data.push_back(DATA_PTR(vbar)); + } + catch (CanteraError) {;} + + csvFile << endl << setw(tabS) << "Species,"; + for ( int i = 0; i < (int)pNames.size(); i++ ){ + csvFile << setw(tabM) << pNames[i] << ","; + } + csvFile << endl; + /* + csvFile.fill('-'); + csvFile << setw(tabS+(tabM+1)*pNames.size()) << "-\n"; + csvFile.fill(' '); + */ + for (int k = 0; k < kk; k++) { + csvFile << setw(tabS) << speciesName(k) + ","; + if (x[k] > SmallNumber) { + for ( int i = 0; i < (int)pNames.size(); i++ ){ + csvFile << setw(tabM) << data[i][k] << ","; + } + csvFile << endl; + } + else{ + for ( int i = 0; i < (int)pNames.size(); i++ ){ + csvFile << setw(tabM) << 0 << ","; + } + csvFile << endl; + } + } + } + catch (CanteraError) { + ; + } + } - } #endif // WITH_PURE_FLUIDS diff --git a/Cantera/src/thermo/PureFluidPhase.h b/Cantera/src/thermo/PureFluidPhase.h index 2e2c626c1..74626fe22 100644 --- a/Cantera/src/thermo/PureFluidPhase.h +++ b/Cantera/src/thermo/PureFluidPhase.h @@ -303,6 +303,14 @@ namespace Cantera { */ virtual std::string report(bool show_thermo = true) const; + //! returns a summary of the state of the phase to specified + //! comma separated files + /*! + * @param csvFile ofstream file to print comma separated data for + * the phase + */ + virtual void reportCSV(std::ofstream& csvFile) const; + protected: //! Main call to the tpx level to set the state of the system diff --git a/Cantera/src/thermo/State.cpp b/Cantera/src/thermo/State.cpp index 6eeec8ce8..a25d53701 100644 --- a/Cantera/src/thermo/State.cpp +++ b/Cantera/src/thermo/State.cpp @@ -193,6 +193,10 @@ namespace Cantera { return density()/meanMolecularWeight(); } + doublereal State::molarVolume() const { + return 1.0/molarDensity(); + } + void State::setConcentrations(const doublereal* const conc) { int k; doublereal sum = 0.0, norm = 0.0; diff --git a/Cantera/src/thermo/State.h b/Cantera/src/thermo/State.h index d05941add..ca2826df9 100644 --- a/Cantera/src/thermo/State.h +++ b/Cantera/src/thermo/State.h @@ -318,6 +318,9 @@ namespace Cantera { /// Molar density (kmol/m^3). doublereal molarDensity() const; + /// Molar density (kmol/m^3). + doublereal molarVolume() const; + //! Set the internally storred density (kg/m^3) of the phase /*! * Note the density of a phase is an indepedent variable. diff --git a/Cantera/src/thermo/ThermoPhase.cpp b/Cantera/src/thermo/ThermoPhase.cpp index eb0e60250..afc819617 100644 --- a/Cantera/src/thermo/ThermoPhase.cpp +++ b/Cantera/src/thermo/ThermoPhase.cpp @@ -21,6 +21,7 @@ #endif #include "ThermoPhase.h" +#include //@{ #ifndef MAX @@ -49,11 +50,13 @@ namespace Cantera { ThermoPhase::~ThermoPhase() { for (int k = 0; k < m_kk; k++) { - if (!m_speciesData[k]) { + if (m_speciesData[k]) { delete m_speciesData[k]; + m_speciesData[k] = 0; } } delete m_spthermo; + m_spthermo = 0; } /** @@ -95,8 +98,9 @@ namespace Cantera { * We need to destruct first */ for (int k = 0; k < m_kk; k++) { - if (!m_speciesData[k]) { + if (m_speciesData[k]) { delete m_speciesData[k]; + m_speciesData[k] = 0; } } if (m_spthermo) { @@ -1132,5 +1136,153 @@ namespace Cantera { return s; } + /* + * Format a summary of the mixture state for output. + */ + void ThermoPhase::reportCSV(std::ofstream& csvFile) const { + + csvFile.precision(3); + int tabS = 15; + int tabM = 30; + int tabL = 40; + try { + if (name() != "") { + csvFile << "\n"+name()+"\n\n"; + } + csvFile << setw(tabL) << "temperature (K) =" << setw(tabS) << temperature() << endl; + csvFile << setw(tabL) << "pressure (Pa) =" << setw(tabS) << pressure() << endl; + csvFile << setw(tabL) << "density (kg/m^3) =" << setw(tabS) << density() << endl; + csvFile << setw(tabL) << "mean mol. weight (amu) =" << setw(tabS) << meanMolecularWeight() << endl; + csvFile << setw(tabL) << "potential (V) =" << setw(tabS) << electricPotential() << endl; + csvFile << endl; + + csvFile << setw(tabL) << "enthalpy (J/kg) = " << setw(tabS) << enthalpy_mass() << setw(tabL) + << "enthalpy (J/kmol) = " << setw(tabS) << enthalpy_mole() << endl; + csvFile << setw(tabL) << "internal E (J/kg) = " << setw(tabS) << intEnergy_mass() << setw(tabL) + << "internal E (J/kmol) = " << setw(tabS) << intEnergy_mole() << endl; + csvFile << setw(tabL) << "entropy (J/kg) = " << setw(tabS) << entropy_mass() << setw(tabL) + << "entropy (J/kmol) = " << setw(tabS) << entropy_mole() << endl; + csvFile << setw(tabL) << "Gibbs (J/kg) = " << setw(tabS) << gibbs_mass() << setw(tabL) + << "Gibbs (J/kmol) = " << setw(tabS) << gibbs_mole() << endl; + csvFile << setw(tabL) << "heat capacity c_p (J/K/kg) = " << setw(tabS) << cp_mass() + << setw(tabL) << "heat capacity c_p (J/K/kmol) = " << setw(tabS) << cp_mole() << endl; + csvFile << setw(tabL) << "heat capacity c_v (J/K/kg) = " << setw(tabS) << cv_mass() + << setw(tabL) << "heat capacity c_v (J/K/kmol) = " << setw(tabS) << cv_mole() << endl; + + csvFile.precision(8); + + int kk = nSpecies(); + doublereal *x = new doublereal[kk]; + doublereal *y = new doublereal[kk]; + doublereal *mu = new doublereal[kk]; + doublereal *a = new doublereal[kk]; + doublereal *ac = new doublereal[kk]; + doublereal *hbar = new doublereal[kk]; + doublereal *sbar = new doublereal[kk]; + doublereal *ubar = new doublereal[kk]; + doublereal *cpbar= new doublereal[kk]; + doublereal *vbar = new doublereal[kk]; + std::vector pNames; + std::vector data; + + getMoleFractions(x); + pNames.push_back("X"); + data.push_back(x); + try{ + getMassFractions(y); + pNames.push_back("Y"); + data.push_back(y); + } + catch (CanteraError) {;} + try{ + getChemPotentials(mu); + pNames.push_back("Chem. Pot (J/kmol)"); + data.push_back(mu); + } + catch (CanteraError) {;} + try{ + getActivities(a); + pNames.push_back("Activity"); + data.push_back(a); + } + catch (CanteraError) {;} + try{ + getActivityCoefficients(ac); + pNames.push_back("Act. Coeff."); + data.push_back(ac); + } + catch (CanteraError) {;} + try{ + getPartialMolarEnthalpies(hbar); + pNames.push_back("Part. Mol Enthalpy (J/kmol)"); + data.push_back(hbar); + } + catch (CanteraError) {;} + try{ + getPartialMolarEntropies(sbar); + pNames.push_back("Part. Mol. Entropy (J/K/kmol)"); + data.push_back(sbar); + } + catch (CanteraError) {;} + try{ + getPartialMolarIntEnergies(ubar); + pNames.push_back("Part. Mol. Energy (J/kmol)"); + data.push_back(ubar); + } + catch (CanteraError) {;} + try{ + getPartialMolarCp(cpbar); + pNames.push_back("Part. Mol. Cp (J/K/kmol"); + data.push_back(cpbar); + } + catch (CanteraError) {;} + try{ + getPartialMolarVolumes(vbar); + pNames.push_back("Part. Mol. Cv (J/K/kmol)"); + data.push_back(vbar); + } + catch (CanteraError) {;} + + csvFile << endl << setw(tabS) << "Species,"; + for ( int i = 0; i < (int)pNames.size(); i++ ){ + csvFile << setw(tabM) << pNames[i] << ","; + } + csvFile << endl; + /* + csvFile.fill('-'); + csvFile << setw(tabS+(tabM+1)*pNames.size()) << "-\n"; + csvFile.fill(' '); + */ + for (int k = 0; k < kk; k++) { + csvFile << setw(tabS) << speciesName(k) + ","; + if (x[k] > SmallNumber) { + for (int i = 0; i < (int)pNames.size(); i++) { + csvFile << setw(tabM) << data[i][k] << ","; + } + csvFile << endl; + } else { + for (int i = 0; i < (int)pNames.size(); i++) { + csvFile << setw(tabM) << 0 << ","; + } + csvFile << endl; + } + } + delete [] x; + delete [] y; + delete [] mu; + delete [] a; + delete [] ac; + delete [] hbar; + delete [] sbar; + delete [] ubar; + delete [] cpbar; + delete [] vbar; + + } + catch (CanteraError) { + ; + } + } + } diff --git a/Cantera/src/thermo/ThermoPhase.h b/Cantera/src/thermo/ThermoPhase.h index 3d5ddb577..c52e74e75 100644 --- a/Cantera/src/thermo/ThermoPhase.h +++ b/Cantera/src/thermo/ThermoPhase.h @@ -883,6 +883,21 @@ namespace Cantera { } + //! Get the change in activity coefficients w.r.t. change in state + //! (temp, mole fraction, etc.) + /*! + * This function is a virtual method. For ideal mixtures + * (unity activity coefficients), this can gradX/X. + * + * @param dT Input of temperature change + * @param dX Input vector of changes in mole fraction. length = m_kk + * @param dlnActCoeff Output vector of derivatives of the + * log Activity Coefficients. length = m_kk + */ + virtual void getdlnActCoeff(const doublereal dT, const doublereal * const dX, doublereal *dlnActCoeff) const { + err("getdlnActCoeff"); + } + //! Get the array of log concentration-like derivatives of the //! log activity coefficients /*! @@ -890,19 +905,41 @@ namespace Cantera { * (unity activity coefficients), this can return zero. * Implementations should take the derivative of the * logarithm of the activity coefficient with respect to the - * logarithm of the concentration-like variable (i.e. mole fraction, - * molality, etc.) that represents the standard state. + * logarithm of the concentration-like variable (i.e. mole fraction) + * that represents the standard state. * This quantity is to be used in conjunction with derivatives of * that concentration-like variable when the derivative of the chemical * potential is taken. * * units = dimensionless * - * @param dlnActCoeffdlnC Output vector of derivatives of the + * @param dlnActCoeffdlnX Output vector of derivatives of the * log Activity Coefficients. length = m_kk */ - virtual void getdlnActCoeffdlnC(doublereal *dlnActCoeffdlnC) const { - err("getdlnActCoeffdlnC"); + virtual void getdlnActCoeffdlnX(doublereal *dlnActCoeffdlnX) const { + err("getdlnActCoeffdlnX"); + } + + //! Get the array of log concentration-like derivatives of the + //! log activity coefficients + /*! + * This function is a virtual method. For ideal mixtures + * (unity activity coefficients), this can return zero. + * Implementations should take the derivative of the + * logarithm of the activity coefficient with respect to the + * logarithm of the concentration-like variable (i.e. moles) + * that represents the standard state. + * This quantity is to be used in conjunction with derivatives of + * that concentration-like variable when the derivative of the chemical + * potential is taken. + * + * units = dimensionless + * + * @param dlnActCoeffdlnN Output vector of derivatives of the + * log Activity Coefficients. length = m_kk + */ + virtual void getdlnActCoeffdlnN(doublereal *dlnActCoeffdlnN) const { + err("getdlnActCoeffdlnN"); } @@ -2074,6 +2111,13 @@ namespace Cantera { * about the thermodynamic state of the system. */ virtual std::string report(bool show_thermo = true) const; + + //! returns a summary of the state of the phase to a comma separated file + /*! + * @param csvFile ofstream file to print comma separated data for + * the phase + */ + virtual void reportCSV(std::ofstream& csvFile) const; protected: diff --git a/Cantera/src/thermo/VPSSMgr.cpp b/Cantera/src/thermo/VPSSMgr.cpp index 64ec7e22c..1204bce2c 100644 --- a/Cantera/src/thermo/VPSSMgr.cpp +++ b/Cantera/src/thermo/VPSSMgr.cpp @@ -280,7 +280,8 @@ namespace Cantera { void VPSSMgr::getStandardVolumes_ref(doublereal *vol) const{ - err("getStandardVolumes_ref"); + getStandardVolumes(vol); + //err("getStandardVolumes_ref"); } /*****************************************************************/ @@ -359,6 +360,7 @@ namespace Cantera { m_sss_R.resize(m_kk, 0.0); m_Vss.resize(m_kk, 0.0); + // Storage used by the PDSS objects to store their // answers. mPDSS_h0_RT.resize(m_kk, 0.0); diff --git a/Cantera/src/thermo/VPStandardStateTP.h b/Cantera/src/thermo/VPStandardStateTP.h index c13412fe4..7990b2cff 100644 --- a/Cantera/src/thermo/VPStandardStateTP.h +++ b/Cantera/src/thermo/VPStandardStateTP.h @@ -127,19 +127,41 @@ namespace Cantera { * (unity activity coefficients), this can return zero. * Implementations should take the derivative of the * logarithm of the activity coefficient with respect to the - * logarithm of the concentration-like variable (i.e. mole fraction, - * molality, etc.) that represents the standard state. + * logarithm of the concentration-like variable (i.e. moles) + * that represents the standard state. * This quantity is to be used in conjunction with derivatives of * that concentration-like variable when the derivative of the chemical * potential is taken. * * units = dimensionless * - * @param dlnActCoeffdlnC Output vector of derivatives of the + * @param dlnActCoeffdlnN Output vector of derivatives of the * log Activity Coefficients. length = m_kk */ - virtual void getdlnActCoeffdlnC(doublereal *dlnActCoeffdlnC) const { - err("getdlnActCoeffdlnC"); + virtual void getdlnActCoeffdlnN(doublereal *dlnActCoeffdlnN) const { + err("getdlnActCoeffdlnN"); + } + + //! Get the array of log concentration-like derivatives of the + //! log activity coefficients + /*! + * This function is a virtual method. For ideal mixtures + * (unity activity coefficients), this can return zero. + * Implementations should take the derivative of the + * logarithm of the activity coefficient with respect to the + * logarithm of the concentration-like variable (i.e. mole fraction) + * that represents the standard state. + * This quantity is to be used in conjunction with derivatives of + * that concentration-like variable when the derivative of the chemical + * potential is taken. + * + * units = dimensionless + * + * @param dlnActCoeffdlnX Output vector of derivatives of the + * log Activity Coefficients. length = m_kk + */ + virtual void getdlnActCoeffdlnX(doublereal *dlnActCoeffdlnX) const { + err("getdlnActCoeffdlnX"); } diff --git a/Cantera/src/thermo/WaterProps.cpp b/Cantera/src/thermo/WaterProps.cpp index 9ba777163..f9a4421a0 100644 --- a/Cantera/src/thermo/WaterProps.cpp +++ b/Cantera/src/thermo/WaterProps.cpp @@ -501,6 +501,7 @@ namespace Cantera { 0.978197, 0.579829, -0.202354}; + //! parameter const doublereal Hij[6][7] = { From 58baed0f2e9ba0debd0f2bc5ab8644648e5dc661 Mon Sep 17 00:00:00 2001 From: Harry Moffat Date: Thu, 11 Nov 2010 00:19:59 +0000 Subject: [PATCH 24/26] Fixed issue 17 There was an obvious error in the THREAD_SAFE_CANTERA compile. --- Cantera/src/thermo/VPSSMgrFactory.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cantera/src/thermo/VPSSMgrFactory.cpp b/Cantera/src/thermo/VPSSMgrFactory.cpp index f8f1f17b2..5b78568a7 100644 --- a/Cantera/src/thermo/VPSSMgrFactory.cpp +++ b/Cantera/src/thermo/VPSSMgrFactory.cpp @@ -200,7 +200,7 @@ namespace Cantera { void VPSSMgrFactory::deleteFactory() { #if defined(THREAD_SAFE_CANTERA) - boost::mutex::scoped_lock lock(species_thermo_mutex); + boost::mutex::scoped_lock lock(vpss_species_thermo_mutex); #endif if (s_factory) { delete s_factory; From 56ad9ca9e878de159ca8d655515d4d39196ea795 Mon Sep 17 00:00:00 2001 From: Harry Moffat Date: Fri, 12 Nov 2010 18:02:21 +0000 Subject: [PATCH 25/26] Fixed a compile error in the THREAD_SAFE capability --- Cantera/src/base/misc.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cantera/src/base/misc.cpp b/Cantera/src/base/misc.cpp index ba094f048..ae43253ab 100644 --- a/Cantera/src/base/misc.cpp +++ b/Cantera/src/base/misc.cpp @@ -544,7 +544,7 @@ namespace Cantera { tmp_dir("."), xmlfiles(), m_sleep("1"), - pMessenger(0) + pMessenger() { #if !defined( THREAD_SAFE_CANTERA ) pMessenger = std::auto_ptr(new Messages()); From fa56309462f11e2f848707478ed660840586cab9 Mon Sep 17 00:00:00 2001 From: Harry Moffat Date: Fri, 12 Nov 2010 19:18:49 +0000 Subject: [PATCH 26/26] Modifications to the Makefiles to make the THREAD_SAFE_CANTERA ifdef block work again. --- test_problems/ChemEquil_gri_matrix/Makefile.in | 2 +- test_problems/ChemEquil_gri_pairs/Makefile.in | 2 +- test_problems/ChemEquil_ionizedGas/Makefile.in | 2 +- test_problems/ChemEquil_red1/Makefile.in | 2 +- test_problems/CpJump/Makefile.in | 2 +- test_problems/VCSnonideal/NaCl_equil/Makefile.in | 2 +- test_problems/cathermo/DH_graph_1/Makefile.in | 2 +- test_problems/cathermo/DH_graph_NM/Makefile.in | 2 +- test_problems/cathermo/DH_graph_acommon/Makefile.in | 2 +- test_problems/cathermo/HMW_dupl_test/Makefile.in | 2 +- test_problems/cathermo/HMW_graph_CpvT/Makefile.in | 2 +- test_problems/cathermo/HMW_graph_GvI/Makefile.in | 2 +- test_problems/cathermo/HMW_graph_GvT/Makefile.in | 2 +- test_problems/cathermo/HMW_graph_HvT/Makefile.in | 2 +- test_problems/cathermo/HMW_graph_VvT/Makefile.in | 2 +- test_problems/cathermo/VPissp/Makefile.in | 2 +- test_problems/cathermo/issp/Makefile.in | 2 +- test_problems/cathermo/stoichSubSSTP/Makefile.in | 2 +- test_problems/cathermo/testWaterTP/Makefile.in | 2 +- test_problems/cathermo/wtWater/Makefile.in | 2 +- test_problems/fracCoeff/Makefile.in | 2 +- test_problems/negATest/Makefile.in | 2 +- test_problems/rankine_democxx/Makefile.in | 2 +- test_problems/surfSolverTest/Makefile.in | 2 +- 24 files changed, 24 insertions(+), 24 deletions(-) diff --git a/test_problems/ChemEquil_gri_matrix/Makefile.in b/test_problems/ChemEquil_gri_matrix/Makefile.in index decf4e6c2..2054185f3 100644 --- a/test_problems/ChemEquil_gri_matrix/Makefile.in +++ b/test_problems/ChemEquil_gri_matrix/Makefile.in @@ -52,7 +52,7 @@ CANTERA_INCLUDES=-I$(CANTERA_INCROOTDIR) -I$(CANTERA_INCROOTDIR)/cantera # LOCAL_DEFS = -DEBUG_BASISOPTIMIZE # # C++ compile flags -CXX_FLAGS = @CXXFLAGS@ $(CANTERA_INCLUDES) $(LOCAL_DEFS) +CXX_FLAGS = @CXXFLAGS@ $(CANTERA_INCLUDES) $(LOCAL_DEFS) @CXX_INCLUDES@ # Ending C++ linking libraries LCXX_END_LIBS = @LCXX_END_LIBS@ diff --git a/test_problems/ChemEquil_gri_pairs/Makefile.in b/test_problems/ChemEquil_gri_pairs/Makefile.in index 960309deb..6e4d84b7f 100644 --- a/test_problems/ChemEquil_gri_pairs/Makefile.in +++ b/test_problems/ChemEquil_gri_pairs/Makefile.in @@ -37,7 +37,7 @@ endif CXX = @CXX@ # C++ compile flags -CXX_FLAGS = @CXXFLAGS@ +CXX_FLAGS = @CXXFLAGS@ @CXX_INCLUDES@ # Ending C++ linking libraries LCXX_END_LIBS = @LCXX_END_LIBS@ diff --git a/test_problems/ChemEquil_ionizedGas/Makefile.in b/test_problems/ChemEquil_ionizedGas/Makefile.in index a36be6324..d77d9ee7a 100644 --- a/test_problems/ChemEquil_ionizedGas/Makefile.in +++ b/test_problems/ChemEquil_ionizedGas/Makefile.in @@ -43,7 +43,7 @@ CXX = @CXX@ # LOCAL_DEFS=-DDEBUG_CHEMEQUIL # # C++ compile flags -CXX_FLAGS = @CXXFLAGS@ $(LOCAL_DEFS) +CXX_FLAGS = @CXXFLAGS@ $(LOCAL_DEFS) @CXX_INCLUDES@ # Ending C++ linking libraries LCXX_END_LIBS = @LCXX_END_LIBS@ diff --git a/test_problems/ChemEquil_red1/Makefile.in b/test_problems/ChemEquil_red1/Makefile.in index 551ee19f1..6da68eafd 100644 --- a/test_problems/ChemEquil_red1/Makefile.in +++ b/test_problems/ChemEquil_red1/Makefile.in @@ -52,7 +52,7 @@ CANTERA_INCLUDES=-I$(CANTERA_INCROOTDIR) -I$(CANTERA_INCROOTDIR)/cantera # LOCAL_DEFS = -DEBUG_BASISOPTIMIZE # # C++ compile flags -CXX_FLAGS = @CXXFLAGS@ $(CANTERA_INCLUDES) $(LOCAL_DEFS) +CXX_FLAGS = @CXXFLAGS@ $(CANTERA_INCLUDES) $(LOCAL_DEFS) @CXX_INCLUDES@ # Ending C++ linking libraries LCXX_END_LIBS = @LCXX_END_LIBS@ diff --git a/test_problems/CpJump/Makefile.in b/test_problems/CpJump/Makefile.in index 2eaf597fc..80d82350d 100644 --- a/test_problems/CpJump/Makefile.in +++ b/test_problems/CpJump/Makefile.in @@ -37,7 +37,7 @@ endif CXX = @CXX@ # C++ compile flags -CXX_FLAGS = @CXXFLAGS@ +CXX_FLAGS = @CXXFLAGS@ @CXX_INCLUDES@ # Ending C++ linking libraries LCXX_END_LIBS = @LCXX_END_LIBS@ diff --git a/test_problems/VCSnonideal/NaCl_equil/Makefile.in b/test_problems/VCSnonideal/NaCl_equil/Makefile.in index 4f5a8fd0c..9b24dbd03 100644 --- a/test_problems/VCSnonideal/NaCl_equil/Makefile.in +++ b/test_problems/VCSnonideal/NaCl_equil/Makefile.in @@ -45,7 +45,7 @@ CANTERA_INCDIR=@ctroot@/build/include/cantera INCLUDE_DIRS = -I$(CANTERA_INCDIR) # C++ compile flags -CXX_FLAGS = @CXXFLAGS@ $(INCLUDE_DIRS) +CXX_FLAGS = @CXXFLAGS@ $(INCLUDE_DIRS) @CXX_INCLUDES@ # Ending C++ linking libraries LCXX_END_LIBS = @LCXX_END_LIBS@ diff --git a/test_problems/cathermo/DH_graph_1/Makefile.in b/test_problems/cathermo/DH_graph_1/Makefile.in index 0cfc4d76a..757519488 100644 --- a/test_problems/cathermo/DH_graph_1/Makefile.in +++ b/test_problems/cathermo/DH_graph_1/Makefile.in @@ -37,7 +37,7 @@ endif CXX = @CXX@ # C++ compile flags -CXX_FLAGS = @CXXFLAGS@ +CXX_FLAGS = @CXXFLAGS@ @CXX_INCLUDES@ # Ending C++ linking libraries LCXX_END_LIBS = @LCXX_END_LIBS@ diff --git a/test_problems/cathermo/DH_graph_NM/Makefile.in b/test_problems/cathermo/DH_graph_NM/Makefile.in index 0029fed70..c58bbb03a 100644 --- a/test_problems/cathermo/DH_graph_NM/Makefile.in +++ b/test_problems/cathermo/DH_graph_NM/Makefile.in @@ -37,7 +37,7 @@ endif CXX = @CXX@ # C++ compile flags -CXX_FLAGS = @CXXFLAGS@ +CXX_FLAGS = @CXXFLAGS@ @CXX_INCLUDES@ # Ending C++ linking libraries LCXX_END_LIBS = @LCXX_END_LIBS@ diff --git a/test_problems/cathermo/DH_graph_acommon/Makefile.in b/test_problems/cathermo/DH_graph_acommon/Makefile.in index 2f5f6264e..de638c902 100644 --- a/test_problems/cathermo/DH_graph_acommon/Makefile.in +++ b/test_problems/cathermo/DH_graph_acommon/Makefile.in @@ -38,7 +38,7 @@ endif CXX = @CXX@ # C++ compile flags -CXX_FLAGS = @CXXFLAGS@ +CXX_FLAGS = @CXXFLAGS@ @CXX_INCLUDES@ # Ending C++ linking libraries LCXX_END_LIBS = @LCXX_END_LIBS@ diff --git a/test_problems/cathermo/HMW_dupl_test/Makefile.in b/test_problems/cathermo/HMW_dupl_test/Makefile.in index e210ad1b9..95f410f8c 100644 --- a/test_problems/cathermo/HMW_dupl_test/Makefile.in +++ b/test_problems/cathermo/HMW_dupl_test/Makefile.in @@ -39,7 +39,7 @@ endif CXX = @CXX@ # C++ compile flags -CXX_FLAGS = @CXXFLAGS@ +CXX_FLAGS = @CXXFLAGS@ @CXX_INCLUDES@ # Ending C++ linking libraries LCXX_END_LIBS = @LCXX_END_LIBS@ diff --git a/test_problems/cathermo/HMW_graph_CpvT/Makefile.in b/test_problems/cathermo/HMW_graph_CpvT/Makefile.in index 39ae2000a..445a524ff 100644 --- a/test_problems/cathermo/HMW_graph_CpvT/Makefile.in +++ b/test_problems/cathermo/HMW_graph_CpvT/Makefile.in @@ -39,7 +39,7 @@ endif CXX = @CXX@ # C++ compile flags -CXX_FLAGS = @CXXFLAGS@ +CXX_FLAGS = @CXXFLAGS@ @CXX_INCLUDES@ # Ending C++ linking libraries LCXX_END_LIBS = @LCXX_END_LIBS@ diff --git a/test_problems/cathermo/HMW_graph_GvI/Makefile.in b/test_problems/cathermo/HMW_graph_GvI/Makefile.in index 505d6ad40..cc2d1cbe2 100644 --- a/test_problems/cathermo/HMW_graph_GvI/Makefile.in +++ b/test_problems/cathermo/HMW_graph_GvI/Makefile.in @@ -39,7 +39,7 @@ endif CXX = @CXX@ # C++ compile flags -CXX_FLAGS = -DSRCDIRTREE @CXXFLAGS@ +CXX_FLAGS = -DSRCDIRTREE @CXXFLAGS@ @CXX_INCLUDES@ # Ending C++ linking libraries LCXX_END_LIBS = @LCXX_END_LIBS@ diff --git a/test_problems/cathermo/HMW_graph_GvT/Makefile.in b/test_problems/cathermo/HMW_graph_GvT/Makefile.in index 0127086c1..c65d4916f 100644 --- a/test_problems/cathermo/HMW_graph_GvT/Makefile.in +++ b/test_problems/cathermo/HMW_graph_GvT/Makefile.in @@ -37,7 +37,7 @@ endif CXX = @CXX@ # C++ compile flags -CXX_FLAGS = @CXXFLAGS@ +CXX_FLAGS = @CXXFLAGS@ @CXX_INCLUDES@ # Ending C++ linking libraries LCXX_END_LIBS = @LCXX_END_LIBS@ diff --git a/test_problems/cathermo/HMW_graph_HvT/Makefile.in b/test_problems/cathermo/HMW_graph_HvT/Makefile.in index f23503d3a..b0ecf6a2b 100644 --- a/test_problems/cathermo/HMW_graph_HvT/Makefile.in +++ b/test_problems/cathermo/HMW_graph_HvT/Makefile.in @@ -39,7 +39,7 @@ endif CXX = @CXX@ # C++ compile flags -CXX_FLAGS = @CXXFLAGS@ +CXX_FLAGS = @CXXFLAGS@ @CXX_INCLUDES@ # Ending C++ linking libraries LCXX_END_LIBS = @LCXX_END_LIBS@ diff --git a/test_problems/cathermo/HMW_graph_VvT/Makefile.in b/test_problems/cathermo/HMW_graph_VvT/Makefile.in index 8325e574c..cd5437328 100644 --- a/test_problems/cathermo/HMW_graph_VvT/Makefile.in +++ b/test_problems/cathermo/HMW_graph_VvT/Makefile.in @@ -39,7 +39,7 @@ endif CXX = @CXX@ # C++ compile flags -CXX_FLAGS = @CXXFLAGS@ +CXX_FLAGS = @CXXFLAGS@ @CXX_INCLUDES@ # Ending C++ linking libraries LCXX_END_LIBS = @LCXX_END_LIBS@ diff --git a/test_problems/cathermo/VPissp/Makefile.in b/test_problems/cathermo/VPissp/Makefile.in index ae869c571..59082ea8c 100644 --- a/test_problems/cathermo/VPissp/Makefile.in +++ b/test_problems/cathermo/VPissp/Makefile.in @@ -39,7 +39,7 @@ endif CXX = @CXX@ # C++ compile flags -CXX_FLAGS = @CXXFLAGS@ +CXX_FLAGS = @CXXFLAGS@ @CXX_INCLUDES@ # Ending C++ linking libraries LCXX_END_LIBS = @LCXX_END_LIBS@ diff --git a/test_problems/cathermo/issp/Makefile.in b/test_problems/cathermo/issp/Makefile.in index f4cd8710e..366a13061 100644 --- a/test_problems/cathermo/issp/Makefile.in +++ b/test_problems/cathermo/issp/Makefile.in @@ -39,7 +39,7 @@ endif CXX = @CXX@ # C++ compile flags -CXX_FLAGS = @CXXFLAGS@ +CXX_FLAGS = @CXXFLAGS@ @CXX_INCLUDES@ # Ending C++ linking libraries LCXX_END_LIBS = @LCXX_END_LIBS@ diff --git a/test_problems/cathermo/stoichSubSSTP/Makefile.in b/test_problems/cathermo/stoichSubSSTP/Makefile.in index 7b733c665..71498b17f 100644 --- a/test_problems/cathermo/stoichSubSSTP/Makefile.in +++ b/test_problems/cathermo/stoichSubSSTP/Makefile.in @@ -37,7 +37,7 @@ endif CXX = @CXX@ # C++ compile flags -CXX_FLAGS = @CXXFLAGS@ +CXX_FLAGS = @CXXFLAGS@ @CXX_INCLUDES@ # Ending C++ linking libraries LCXX_END_LIBS = @LCXX_END_LIBS@ diff --git a/test_problems/cathermo/testWaterTP/Makefile.in b/test_problems/cathermo/testWaterTP/Makefile.in index 685de3f4b..1dd7c0eb6 100644 --- a/test_problems/cathermo/testWaterTP/Makefile.in +++ b/test_problems/cathermo/testWaterTP/Makefile.in @@ -37,7 +37,7 @@ endif CXX = @CXX@ # C++ compile flags -CXX_FLAGS = @CXXFLAGS@ +CXX_FLAGS = @CXXFLAGS@ @CXX_INCLUDES@ # Ending C++ linking libraries LCXX_END_LIBS = @LCXX_END_LIBS@ diff --git a/test_problems/cathermo/wtWater/Makefile.in b/test_problems/cathermo/wtWater/Makefile.in index a8156e502..3aaaec32d 100755 --- a/test_problems/cathermo/wtWater/Makefile.in +++ b/test_problems/cathermo/wtWater/Makefile.in @@ -37,7 +37,7 @@ endif CXX = @CXX@ # C++ compile flags -CXX_FLAGS = @CXXFLAGS@ +CXX_FLAGS = @CXXFLAGS@ @CXX_INCLUDES@ # Ending C++ linking libraries LCXX_END_LIBS = @LCXX_END_LIBS@ diff --git a/test_problems/fracCoeff/Makefile.in b/test_problems/fracCoeff/Makefile.in index 275ee94ad..a4b2bd09c 100644 --- a/test_problems/fracCoeff/Makefile.in +++ b/test_problems/fracCoeff/Makefile.in @@ -39,7 +39,7 @@ endif CXX = @CXX@ # C++ compile flags -CXX_FLAGS = @CXXFLAGS@ +CXX_FLAGS = @CXXFLAGS@ @CXX_INCLUDES@ # Ending C++ linking libraries LCXX_END_LIBS = @LCXX_END_LIBS@ diff --git a/test_problems/negATest/Makefile.in b/test_problems/negATest/Makefile.in index ef159696a..bd11bd1b4 100644 --- a/test_problems/negATest/Makefile.in +++ b/test_problems/negATest/Makefile.in @@ -37,7 +37,7 @@ endif CXX = @CXX@ # C++ compile flags -CXX_FLAGS = @CXXFLAGS@ +CXX_FLAGS = @CXXFLAGS@ @CXX_INCLUDES@ # Ending C++ linking libraries LCXX_END_LIBS = @LCXX_END_LIBS@ diff --git a/test_problems/rankine_democxx/Makefile.in b/test_problems/rankine_democxx/Makefile.in index 781edc60e..19a4a97af 100644 --- a/test_problems/rankine_democxx/Makefile.in +++ b/test_problems/rankine_democxx/Makefile.in @@ -51,7 +51,7 @@ CANTERA_INCLUDES=-I$(CANTERA_INCROOTDIR) -I$(CANTERA_INCROOTDIR)/cantera # LOCAL_DEFS = -DEBUG_BASISOPTIMIZE # # C++ compile flags -CXX_FLAGS = @CXXFLAGS@ $(CANTERA_INCLUDES) $(LOCAL_DEFS) +CXX_FLAGS = @CXXFLAGS@ $(CANTERA_INCLUDES) $(LOCAL_DEFS) @CXX_INCLUDES@ # Ending C++ linking libraries LCXX_END_LIBS = @LCXX_END_LIBS@ diff --git a/test_problems/surfSolverTest/Makefile.in b/test_problems/surfSolverTest/Makefile.in index 887eddc3e..c3e454b9b 100644 --- a/test_problems/surfSolverTest/Makefile.in +++ b/test_problems/surfSolverTest/Makefile.in @@ -37,7 +37,7 @@ endif CXX = @CXX@ # C++ compile flags -CXX_FLAGS = @CXXFLAGS@ +CXX_FLAGS = @CXXFLAGS@ @CXX_INCLUDES@ # Ending C++ linking libraries LCXX_END_LIBS = @LCXX_END_LIBS@