From e7c6495ec7c0adbffe5f2ee3173c60f62c0d36ad Mon Sep 17 00:00:00 2001 From: Ray Speth Date: Tue, 15 Jan 2019 17:08:14 -0500 Subject: [PATCH] [Input] Create IdealMolalSoln objects from YAML definitions --- src/thermo/IdealMolalSoln.cpp | 33 +++++++++++++++-- src/thermo/ThermoFactory.cpp | 1 + test/data/thermo-models.yaml | 66 ++++++++++++++++++++++++++++++++++ test/thermo/thermoFromYaml.cpp | 12 +++++++ 4 files changed, 110 insertions(+), 2 deletions(-) diff --git a/src/thermo/IdealMolalSoln.cpp b/src/thermo/IdealMolalSoln.cpp index 702b77d64..79c51e188 100644 --- a/src/thermo/IdealMolalSoln.cpp +++ b/src/thermo/IdealMolalSoln.cpp @@ -406,6 +406,33 @@ void IdealMolalSoln::initThermoXML(XML_Node& phaseNode, const std::string& id_) void IdealMolalSoln::initThermo() { MolalityVPSSTP::initThermo(); + + if (m_input.hasKey("standard-concentration-basis")) { + setStandardConcentrationModel(m_input["standard-concentration-basis"].asString()); + } + if (m_input.hasKey("cutoff")) { + auto& cutoff = m_input["cutoff"].as(); + setCutoffModel(cutoff.getString("model", "none")); + if (cutoff.hasKey("gamma_o")) { + IMS_gamma_o_min_ = cutoff["gamma_o"].asDouble(); + } + if (cutoff.hasKey("gamma_k")) { + IMS_gamma_k_min_ = cutoff["gamma_k"].asDouble(); + } + if (cutoff.hasKey("X_o")) { + IMS_X_o_cutoff_ = cutoff["X_o"].asDouble(); + } + if (cutoff.hasKey("c_0")) { + IMS_cCut_ = cutoff["c_0"].asDouble(); + } + if (cutoff.hasKey("slope_f")) { + IMS_slopefCut_ = cutoff["slope_f"].asDouble(); + } + if (cutoff.hasKey("slope_g")) { + IMS_slopegCut_ = cutoff["slope_g"].asDouble(); + } + } + for (size_t k = 0; k < nSpecies(); k++) { m_speciesMolarVolume[k] = providePDSS(k)->molarVolume(); } @@ -419,9 +446,11 @@ void IdealMolalSoln::setStandardConcentrationModel(const std::string& model) { if (caseInsensitiveEquals(model, "unity")) { m_formGC = 0; - } else if (caseInsensitiveEquals(model, "molar_volume")) { + } else if (caseInsensitiveEquals(model, "species-molar-volume") + || caseInsensitiveEquals(model, "molar_volume")) { m_formGC = 1; - } else if (caseInsensitiveEquals(model, "solvent_volume")) { + } else if (caseInsensitiveEquals(model, "solvent-molar-volume") + || caseInsensitiveEquals(model, "solvent_volume")) { m_formGC = 2; } else { throw CanteraError("IdealSolnGasVPSS::setStandardConcentrationModel", diff --git a/src/thermo/ThermoFactory.cpp b/src/thermo/ThermoFactory.cpp index 52cdb286d..1ce39302d 100644 --- a/src/thermo/ThermoFactory.cpp +++ b/src/thermo/ThermoFactory.cpp @@ -64,6 +64,7 @@ ThermoFactory::ThermoFactory() reg("IdealSolidSolution", []() { return new IdealSolidSolnPhase(); }); reg("DebyeHuckel", []() { return new DebyeHuckel(); }); reg("IdealMolalSolution", []() { return new IdealMolalSoln(); }); + m_synonyms["ideal-molal-solution"] = "IdealMolalSolution"; reg("IdealGasVPSS", []() { return new IdealSolnGasVPSS(); }); m_synonyms["IdealGasVPSS"] = "IdealSolnVPSS"; reg("Margules", []() { return new MargulesVPSSTP(); }); diff --git a/test/data/thermo-models.yaml b/test/data/thermo-models.yaml index d23901d11..dbea283d5 100644 --- a/test/data/thermo-models.yaml +++ b/test/data/thermo-models.yaml @@ -29,6 +29,24 @@ phases: excess-enthalpy: [-17570, -377] excess-entropy: [-7.627, 4.958] +- name: ideal-molal-aqueous + thermo: ideal-molal-solution + species: + - {ideal-molal-fake-species: all} + standard-concentration-basis: solvent-molar-volume + cutoff: + model: polyexp + gamma_o: 0.0001 + gamma_k: 10.0 + X_o: 0.2 + c_0: 0.05 + slope_f: 0.6 + slope_g: 0.0 + state: + T: 298.15 + P: 1 atm + molalities: {CH4(aq): 0.01, H2S(aq): 0.03, CO2(aq): 0.1} + species: - name: NaCl(s) composition: {Na: 1, Cl: 1} @@ -82,3 +100,51 @@ species: equation-of-state: model: constant-volume molar-volume: 20.304 cm^3/gmol + + +ideal-molal-fake-species: +# Fake thermo data (GRI 3.0 coefficients for H2) +- name: H2O(l) + composition: {H: 2, O: 1} + thermo: + model: NASA7 + temperature-ranges: [200.0, 1000.0] + data: + - [2.34433112, 0.00798052075, -1.9478151e-05, 2.01572094e-08, -7.37611761e-12, + -917.935173, 0.683010238] + equation-of-state: + model: constant-volume + molar-volume: 1.5 +- name: CO2(aq) + composition: {C: 1, O: 2} + thermo: + model: NASA7 + temperature-ranges: [200.0, 1000.0] + data: + - [2.34433112, 0.00798052075, -1.9478151e-05, 2.01572094e-08, -7.37611761e-12, + -917.935173, 0.683010238] + equation-of-state: + model: constant-volume + molar-volume: 1.3 +- name: H2S(aq) + composition: {H: 2, S: 1} + thermo: + model: NASA7 + temperature-ranges: [200.0, 1000.0] + data: + - [2.34433112, 0.00798052075, -1.9478151e-05, 2.01572094e-08, -7.37611761e-12, + -917.935173, 0.683010238] + equation-of-state: + model: constant-volume + molar-volume: 0.1 +- name: CH4(aq) + composition: {C: 1, H: 4} + thermo: + model: NASA7 + temperature-ranges: [200.0, 1000.0] + data: + - [2.34433112, 0.00798052075, -1.9478151e-05, 2.01572094e-08, -7.37611761e-12, + -917.935173, 0.683010238] + equation-of-state: + model: constant-volume + molar-volume: 0.1 diff --git a/test/thermo/thermoFromYaml.cpp b/test/thermo/thermoFromYaml.cpp index 397100eb3..07428629e 100644 --- a/test/thermo/thermoFromYaml.cpp +++ b/test/thermo/thermoFromYaml.cpp @@ -126,3 +126,15 @@ TEST(ThermoFromYaml, Margules) EXPECT_NEAR(thermo->gibbs_mass(), -9682981.421693124, 1e-5); EXPECT_NEAR(thermo->cp_mole(), 67478.48085733457, 1e-8); } + +TEST(ThermoFromYaml, IdealMolalSoln) +{ + AnyMap infile = AnyMap::fromYamlFile("thermo-models.yaml"); + auto phaseNodes = infile["phases"].asMap("name"); + auto thermo = newPhase(*phaseNodes.at("ideal-molal-aqueous"), infile); + EXPECT_EQ(thermo->type(), "IdealMolalSoln"); + + EXPECT_NEAR(thermo->enthalpy_mole(), 0.013282, 1e-6); + EXPECT_NEAR(thermo->gibbs_mole(), -3.8986e7, 1e3); + EXPECT_NEAR(thermo->density(), 12.058, 1e-3); +}