From a520f782dbe10ec42db449c5a90ed44b917f004b Mon Sep 17 00:00:00 2001 From: Ray Speth Date: Sun, 13 Aug 2017 16:59:20 -0400 Subject: [PATCH] [Thermo] Make PDSS_SSVol contstructible wihout XML --- include/cantera/thermo/PDSS_SSVol.h | 11 ++++++++++ src/thermo/PDSS_SSVol.cpp | 34 +++++++++++++++++++---------- test/thermo/phaseConstructors.cpp | 30 +++++++++++++++++++++++++ 3 files changed, 63 insertions(+), 12 deletions(-) diff --git a/include/cantera/thermo/PDSS_SSVol.h b/include/cantera/thermo/PDSS_SSVol.h index 396071037..62d9ab233 100644 --- a/include/cantera/thermo/PDSS_SSVol.h +++ b/include/cantera/thermo/PDSS_SSVol.h @@ -165,6 +165,17 @@ public: //! @{ virtual void initThermo(); + + //! Set polynomial coefficients for the standard state molar volume as a + //! function of temperature. Cubic polynomial (4 coefficients). Leading + //! coefficient is the constant (temperature-independent) term [m^3/kmol]. + void setVolumePolynomial(double* coeffs); + + //! Set polynomial coefficients for the standard state density as a function + //! of temperature. Cubic polynomial (4 coefficients). Leading coefficient + //! is the constant (temperature-independent) term [kg/m^3]. + void setDensityPolynomial(double* coeffs); + virtual void setParametersFromXML(const XML_Node& speciesNode); //@} diff --git a/src/thermo/PDSS_SSVol.cpp b/src/thermo/PDSS_SSVol.cpp index 9a140fccb..bf719913b 100644 --- a/src/thermo/PDSS_SSVol.cpp +++ b/src/thermo/PDSS_SSVol.cpp @@ -32,20 +32,16 @@ void PDSS_SSVol::setParametersFromXML(const XML_Node& speciesNode) "no standardState Node for species " + speciesNode.name()); } std::string model = ss->attrib("model"); + vector_fp coeffs; + getFloatArray(*ss, coeffs, true, "toSI", "volumeTemperaturePolynomial"); + if (coeffs.size() != 4) { + throw CanteraError("PDSS_SSVol::setParametersFromXML", + " Didn't get 4 density polynomial numbers for species " + speciesNode.name()); + } if (model == "temperature_polynomial") { - volumeModel_ = SSVolume_Model::tpoly; - size_t 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()); - } + setVolumePolynomial(coeffs.data()); } else if (model == "density_temperature_polynomial") { - volumeModel_ = SSVolume_Model::density_tpoly; - size_t 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()); - } + setDensityPolynomial(coeffs.data()); } else { throw CanteraError("PDSS_SSVol::constructPDSSXML", "Unknown standardState model '{}'' for species '{}'", @@ -53,6 +49,20 @@ void PDSS_SSVol::setParametersFromXML(const XML_Node& speciesNode) } } +void PDSS_SSVol::setVolumePolynomial(double* coeffs) { + for (size_t i = 0; i < 4; i++) { + TCoeff_[i] = coeffs[i]; + } + volumeModel_ = SSVolume_Model::tpoly; +} + +void PDSS_SSVol::setDensityPolynomial(double* coeffs) { + for (size_t i = 0; i < 4; i++) { + TCoeff_[i] = coeffs[i]; + } + volumeModel_ = SSVolume_Model::density_tpoly; +} + void PDSS_SSVol::initThermo() { PDSS::initThermo(); diff --git a/test/thermo/phaseConstructors.cpp b/test/thermo/phaseConstructors.cpp index 1849ba73f..006b6e896 100644 --- a/test/thermo/phaseConstructors.cpp +++ b/test/thermo/phaseConstructors.cpp @@ -3,6 +3,7 @@ #include "cantera/thermo/PDSSFactory.h" #include "cantera/thermo/PDSS_ConstVol.h" #include "cantera/thermo/PDSS_Water.h" +#include "cantera/thermo/PDSS_SSVol.h" #include "cantera/thermo/FixedChemPotSSTP.h" #include "cantera/thermo/PureFluidPhase.h" #include "cantera/thermo/WaterSSTP.h" @@ -719,4 +720,33 @@ TEST(HMWSoln, fromScratch_HKFT) } } +TEST(PDSS_SSVol, fromScratch) +{ + // Regression test based on comparison with using XML input file + IdealSolnGasVPSS p; + p.addUndefinedElements(); + double coeffs[] = {700.0, 26.3072, 30.4657, -69.1692, 44.1951, 0.0776, + -6.0337, 59.8106, 22.6832, 10.476, -6.5428, 1.3255, 0.8783, -2.0426, + 62.8859}; + auto sLi = make_shomate2_species("Li(L)", "Li:1", coeffs); + p.addSpecies(sLi); + p.setSolnMode(); + p.setStandardConcentrationModel("unity"); + std::unique_ptr ss(new PDSS_SSVol()); + double rho_coeffs[] = {536.504, -1.04279e-1, 3.84825e-6, -5.2853e-9}; + ss->setDensityPolynomial(rho_coeffs); + p.installPDSS(0, std::move(ss)); + p.initThermo(); + p.setState_TP(300, OneAtm); + EXPECT_NEAR(p.density(), 505.42393940, 2e-8); + EXPECT_NEAR(p.gibbs_mole(), -7801634.1184443515, 2e-8); + p.setState_TP(400, 2*OneAtm); + EXPECT_NEAR(p.density(), 495.06986080, 2e-8); + EXPECT_NEAR(p.molarVolume(), 0.01402024350418708, 2e-12); + p.setState_TP(500, 2*OneAtm); + EXPECT_NEAR(p.density(), 484.66590, 2e-8); + EXPECT_NEAR(p.enthalpy_mass(), 1236522.9439646902, 2e-8); + EXPECT_NEAR(p.entropy_mole(), 49848.48843237689, 2e-8); +} + } // namespace Cantera