[Thermo] Make PDSS_SSVol contstructible wihout XML

This commit is contained in:
Ray Speth 2017-08-13 16:59:20 -04:00
parent be8e51d217
commit a520f782db
3 changed files with 63 additions and 12 deletions

View file

@ -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);
//@}

View file

@ -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();

View file

@ -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<PDSS_SSVol> 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