From 72d345619f31aea152d63589b47576d13bc200ed Mon Sep 17 00:00:00 2001 From: Ray Speth Date: Wed, 16 Jan 2019 23:21:06 -0500 Subject: [PATCH] [Input] Create PDSS_SSVol objects from YAML definitions --- src/thermo/PDSSFactory.cpp | 2 +- src/thermo/PDSS_SSVol.cpp | 21 +++++++++++++++++++++ test/data/thermo-models.yaml | 16 ++++++++++++++++ test/thermo/thermoFromYaml.cpp | 18 ++++++++++++++++++ 4 files changed, 56 insertions(+), 1 deletion(-) diff --git a/src/thermo/PDSSFactory.cpp b/src/thermo/PDSSFactory.cpp index 2000a4b2e..dd52fc01f 100644 --- a/src/thermo/PDSSFactory.cpp +++ b/src/thermo/PDSSFactory.cpp @@ -30,7 +30,7 @@ PDSSFactory::PDSSFactory() m_synonyms["IonFromNeutral"] = "ions-from-neutral"; m_synonyms["ions-from-neutral-molecule"] = "ions-from-neutral"; reg("temperature_polynomial", []() { return new PDSS_SSVol(); }); - m_synonyms["temperature-polynomial"] = "temperature_polynomial"; + m_synonyms["molar-volume-temperature-polynomial"] = "temperature_polynomial"; m_synonyms["density_temperature_polynomial"] = "temperature_polynomial"; m_synonyms["density-temperature-polynomial"] = "temperature_polynomial"; reg("HKFT", []() { return new PDSS_HKFT(); }); diff --git a/src/thermo/PDSS_SSVol.cpp b/src/thermo/PDSS_SSVol.cpp index bf719913b..f673bac03 100644 --- a/src/thermo/PDSS_SSVol.cpp +++ b/src/thermo/PDSS_SSVol.cpp @@ -66,6 +66,27 @@ void PDSS_SSVol::setDensityPolynomial(double* coeffs) { void PDSS_SSVol::initThermo() { PDSS::initThermo(); + if (m_input.hasKey("model")) { + const string& model = m_input["model"].asString(); + auto& data = m_input["data"].asVector(4); + if (model == "density-temperature-polynomial") { + double coeffs[] { + m_input.units().convert(data[0], "kg/m^3"), + m_input.units().convert(data[1], "kg/m^3/K"), + m_input.units().convert(data[2], "kg/m^3/K^2"), + m_input.units().convert(data[3], "kg/m^3/K^3"), + }; + setDensityPolynomial(coeffs); + } else if (model == "molar-volume-temperature-polynomial") { + double coeffs[] { + m_input.units().convert(data[0], "m^3/kmol"), + m_input.units().convert(data[1], "m^3/kmol/K"), + m_input.units().convert(data[2], "m^3/kmol/K^2"), + m_input.units().convert(data[3], "m^3/kmol/K^3"), + }; + setVolumePolynomial(coeffs); + } + } m_minTemp = m_spthermo->minTemp(); m_maxTemp = m_spthermo->maxTemp(); m_p0 = m_spthermo->refPressure(); diff --git a/test/data/thermo-models.yaml b/test/data/thermo-models.yaml index cb4d432ec..4f60f5c36 100644 --- a/test/data/thermo-models.yaml +++ b/test/data/thermo-models.yaml @@ -97,6 +97,10 @@ phases: species: [{gas-species: [H2O, H2, O2]}] state: {T: 400, P: 5 atm, X: {H2: 0.01, O2: 0.99}} +- name: IdealSolnGas-liquid + thermo: ideal-solution-VPSS + standard-concentration-basis: unity + species: [Li(l)] species: - name: NaCl(s) @@ -152,6 +156,18 @@ species: model: constant-volume molar-volume: 20.304 cm^3/gmol +- name: Li(l) + composition: {Li: 1} + thermo: + model: Shomate + temperature-ranges: [298, 700, 3000] + data: + - [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] + equation-of-state: + model: density-temperature-polynomial + units: {mass: g, length: cm} + data: [0.536504, -1.04279e-4, 3.84825e-9, -5.2853e-12] ideal-molal-fake-species: # Fake thermo data (GRI 3.0 coefficients for H2) diff --git a/test/thermo/thermoFromYaml.cpp b/test/thermo/thermoFromYaml.cpp index 64ad961ad..bf32c4a03 100644 --- a/test/thermo/thermoFromYaml.cpp +++ b/test/thermo/thermoFromYaml.cpp @@ -220,3 +220,21 @@ TEST(ThermoFromYaml, IdealSolnGas_gas) EXPECT_NEAR(thermo->moleFraction("H2O"), 0.01, 1e-4); EXPECT_NEAR(thermo->moleFraction("H2"), 0.0, 1e-4); } + +TEST(ThermoFromYaml, IdealSolnGas_liquid) +{ + AnyMap infile = AnyMap::fromYamlFile("thermo-models.yaml"); + auto phaseNodes = infile["phases"].asMap("name"); + auto thermo = newPhase(*phaseNodes.at("IdealSolnGas-liquid"), infile); + + thermo->setState_TP(300, OneAtm); + EXPECT_NEAR(thermo->density(), 505.42393940, 2e-8); + EXPECT_NEAR(thermo->gibbs_mole(), -7801634.1184443515, 2e-8); + thermo->setState_TP(400, 2*OneAtm); + EXPECT_NEAR(thermo->density(), 495.06986080, 2e-8); + EXPECT_NEAR(thermo->molarVolume(), 0.01402024350418708, 2e-12); + thermo->setState_TP(500, 2*OneAtm); + EXPECT_NEAR(thermo->density(), 484.66590, 2e-8); + EXPECT_NEAR(thermo->enthalpy_mass(), 1236522.9439646902, 2e-8); + EXPECT_NEAR(thermo->entropy_mole(), 49848.48843237689, 2e-8); +}