From 3011374ff6c7b17e081242480681d42250bfa69a Mon Sep 17 00:00:00 2001 From: Ray Speth Date: Mon, 4 Feb 2019 22:57:01 -0500 Subject: [PATCH] [Input] Create ConstDensityThermo objects from YAML definitions --- include/cantera/thermo/ConstDensityThermo.h | 1 + src/thermo/ConstDensityThermo.cpp | 8 ++++++++ src/thermo/ThermoFactory.cpp | 1 + test/data/thermo-models.yaml | 7 +++++++ test/thermo/thermoFromYaml.cpp | 6 ++++++ 5 files changed, 23 insertions(+) diff --git a/include/cantera/thermo/ConstDensityThermo.h b/include/cantera/thermo/ConstDensityThermo.h index 37617e5a2..c8619e5e9 100644 --- a/include/cantera/thermo/ConstDensityThermo.h +++ b/include/cantera/thermo/ConstDensityThermo.h @@ -136,6 +136,7 @@ public: n = 1; } + virtual void initThermo(); virtual void setParametersFromXML(const XML_Node& eosdata); protected: diff --git a/src/thermo/ConstDensityThermo.cpp b/src/thermo/ConstDensityThermo.cpp index e3edba6c4..9dcb21576 100644 --- a/src/thermo/ConstDensityThermo.cpp +++ b/src/thermo/ConstDensityThermo.cpp @@ -105,6 +105,14 @@ void ConstDensityThermo::_updateThermo() const } } +void ConstDensityThermo::initThermo() +{ + if (m_input.hasKey("density")) { + setDensity(m_input.convert("density", "kg/m^3")); + } + ThermoPhase::initThermo(); +} + void ConstDensityThermo::setParametersFromXML(const XML_Node& eosdata) { eosdata._require("model","Incompressible"); diff --git a/src/thermo/ThermoFactory.cpp b/src/thermo/ThermoFactory.cpp index 6323392c6..f8fd0e835 100644 --- a/src/thermo/ThermoFactory.cpp +++ b/src/thermo/ThermoFactory.cpp @@ -52,6 +52,7 @@ ThermoFactory::ThermoFactory() reg("IdealGas", []() { return new IdealGasPhase(); }); m_synonyms["ideal-gas"] = "IdealGas"; reg("Incompressible", []() { return new ConstDensityThermo(); }); + m_synonyms["constant-density"] = "Incompressible"; reg("Surface", []() { return new SurfPhase(); }); m_synonyms["ideal-surface"] = "Surface"; reg("Edge", []() { return new EdgePhase(); }); diff --git a/test/data/thermo-models.yaml b/test/data/thermo-models.yaml index 9e1223e39..5c6fe5220 100644 --- a/test/data/thermo-models.yaml +++ b/test/data/thermo-models.yaml @@ -179,6 +179,13 @@ phases: thermo: pure-fluid pure-fluid-name: nitrogen +- name: const-density + thermo: constant-density + density: 0.7 g/cm^3 + species: [NaCl(s), KCl(s)] + state: {T: 320, P: 1 atm} + + species: - name: NaCl(s) composition: {Na: 1, Cl: 1} diff --git a/test/thermo/thermoFromYaml.cpp b/test/thermo/thermoFromYaml.cpp index 6b39b5c7c..cf8e23a6c 100644 --- a/test/thermo/thermoFromYaml.cpp +++ b/test/thermo/thermoFromYaml.cpp @@ -332,3 +332,9 @@ TEST(ThermoFromYaml, PureFluid_nitrogen) EXPECT_NEAR(thermo->density(), 841.0420151, 1e-6); EXPECT_NEAR(thermo->gibbs_mole(), -17654452.8821914, 1e-6); } + +TEST(ThermoFromYaml, ConstDensityThermo) +{ + auto thermo = newThermo("thermo-models.yaml", "const-density"); + EXPECT_DOUBLE_EQ(thermo->density(), 700.0); +}