[Input] Parse YAML entries for Shomate polynomials

This commit is contained in:
Ray Speth 2018-12-14 18:10:27 -05:00
parent 2b41486850
commit 7ff6e8fac2
2 changed files with 46 additions and 0 deletions

View file

@ -249,6 +249,30 @@ static SpeciesThermoInterpType* newShomateThermoFromXML(
return newSpeciesThermoInterpType(SHOMATE, tmin, tmax, p0, &c[0]);
}
void setupShomatePoly(ShomatePoly2& thermo, const AnyMap& node,
const UnitSystem& units)
{
setupSpeciesThermo(thermo, node, units);
vector_fp Tranges = units.convert(
node.at("temperature-ranges").asVector<AnyValue>(2, 3), "K");
const auto& data = node.at("data").asVector<vector_fp>(Tranges.size()-1);
for (const auto& poly : data) {
if (poly.size() != 7) {
throw CanteraError("setupShomatePoly", "Wrong number of coefficients "
"for Shomate polynomial. Expected 7, but got {}", poly.size());
}
}
thermo.setMinTemp(Tranges.front());
thermo.setMaxTemp(Tranges.back());
if (Tranges.size() == 3) { // standard 2 temperature range polynomial
thermo.setParameters(Tranges[1], data[0], data[1]);
} else { // Repeat data for single temperature range for both ranges
thermo.setParameters(Tranges[1], data[0], data[0]);
}
}
//! Create a "simple" constant heat capacity thermodynamic property
//! parameterization for a ! species
/*!
@ -382,6 +406,10 @@ unique_ptr<SpeciesThermoInterpType> newSpeciesThermo(
unique_ptr<NasaPoly2> thermo(new NasaPoly2());
setupNasaPoly(*thermo, node, units);
return unique_ptr<SpeciesThermoInterpType>(move(thermo));
} else if (model == "Shomate") {
unique_ptr<ShomatePoly2> thermo(new ShomatePoly2());
setupShomatePoly(*thermo, node, units);
return unique_ptr<SpeciesThermoInterpType>(move(thermo));
} else {
throw CanteraError("newSpeciesThermo",
"Uknown thermo model '{}'", model);

View file

@ -163,3 +163,21 @@ TEST(SpeciesThermo, NasaPoly2FromYaml2) {
EXPECT_DOUBLE_EQ(h_RT, 13.735827875868003);
EXPECT_DOUBLE_EQ(s_R, 28.913447733267262);
}
TEST(SpeciesThermo, Shomate2FromYaml1) {
AnyMap data = AnyMap::fromYamlString(
"model: Shomate\n"
"temperature-ranges: [298, 1300, 6000]\n"
"data:\n"
"- [25.56759, 6.096130, 4.054656, -2.671301, 0.131021, -118.0089, 227.3665]\n"
"- [35.15070, 1.300095, -0.205921, 0.013550, -3.282780, -127.8375, 231.7120]\n");
UnitSystem U;
double cp_R, h_RT, s_R;
auto st = newSpeciesThermo(data, U);
st->validate("CO");
st->updatePropertiesTemp(1500, &cp_R, &h_RT, &s_R);
EXPECT_DOUBLE_EQ(st->refPressure(), OneAtm);
EXPECT_DOUBLE_EQ(cp_R, 4.2365023429076265);
EXPECT_DOUBLE_EQ(h_RT, -5.747001162488512);
EXPECT_DOUBLE_EQ(s_R, 29.878976075583324);
}