diff --git a/include/cantera/thermo/PureFluidPhase.h b/include/cantera/thermo/PureFluidPhase.h index 30e2736e2..fb6c038b5 100644 --- a/include/cantera/thermo/PureFluidPhase.h +++ b/include/cantera/thermo/PureFluidPhase.h @@ -49,6 +49,12 @@ public: return "PureFluid"; } + //! Set the name of the TPX substance to use for the equation of state. This + //! function should be called before initThermo(). + void setSubstance(const std::string& name) { + m_tpx_name = name; + } + virtual doublereal enthalpy_mole() const; virtual doublereal intEnergy_mole() const; virtual doublereal entropy_mole() const; @@ -190,10 +196,15 @@ private: //! Int indicating the type of the fluid /*! - * The tpx package uses an int to indicate what fluid is being sought. + * The tpx package uses an int to indicate what fluid is being sought. Used + * only if #m_tpx_name is not set. */ int m_subflag; + //! Name for this substance used by the TPX package. If this is not set, + //! #m_subflag is used instead. + std::string m_tpx_name; + //! Molecular weight of the substance (kg kmol-1) doublereal m_mw; diff --git a/src/thermo/PureFluidPhase.cpp b/src/thermo/PureFluidPhase.cpp index 591b87a64..621da2356 100644 --- a/src/thermo/PureFluidPhase.cpp +++ b/src/thermo/PureFluidPhase.cpp @@ -56,7 +56,11 @@ ThermoPhase* PureFluidPhase::duplMyselfAsThermoPhase() const void PureFluidPhase::initThermo() { - m_sub.reset(tpx::GetSub(m_subflag)); + if (m_tpx_name != "") { + m_sub.reset(tpx::newSubstance(m_tpx_name)); + } else { + m_sub.reset(tpx::GetSub(m_subflag)); + } if (!m_sub) { throw CanteraError("PureFluidPhase::initThermo", "could not create new substance object."); diff --git a/test/thermo/phaseConstructors.cpp b/test/thermo/phaseConstructors.cpp index fed866df5..226a8349f 100644 --- a/test/thermo/phaseConstructors.cpp +++ b/test/thermo/phaseConstructors.cpp @@ -1,7 +1,9 @@ #include "gtest/gtest.h" #include "cantera/thermo/ThermoFactory.h" #include "cantera/thermo/FixedChemPotSSTP.h" +#include "cantera/thermo/PureFluidPhase.h" #include "cantera/thermo/NasaPoly2.h" +#include "cantera/thermo/ShomatePoly.h" #include "cantera/thermo/IdealGasPhase.h" #include "cantera/base/ctml.h" #include "cantera/base/stringUtils.h" @@ -184,4 +186,17 @@ TEST_F(ConstructFromScratch, addUndefinedElements) ASSERT_DOUBLE_EQ(0.5, p.massFraction("CO2")); } +TEST(PureFluidFromScratch, CarbonDioxide) +{ + PureFluidPhase p; + auto sCO2 = make_shared("CO2", parseCompString("C:1 O:2")); + sCO2->thermo.reset(new ShomatePoly2(200, 6000, 101325, co2_shomate_coeffs)); + p.addUndefinedElements(); + p.addSpecies(sCO2); + p.setSubstance("carbondioxide"); + p.initThermo(); + p.setState_Tsat(280, 0.5); + EXPECT_NEAR(p.pressure(), 4160236.987, 1e-2); +} + } // namespace Cantera