diff --git a/include/cantera/thermo/FixedChemPotSSTP.h b/include/cantera/thermo/FixedChemPotSSTP.h index 660c37345..bdf8f9e97 100644 --- a/include/cantera/thermo/FixedChemPotSSTP.h +++ b/include/cantera/thermo/FixedChemPotSSTP.h @@ -318,6 +318,8 @@ public: virtual void initThermoXML(XML_Node& phaseNode, const std::string& id); + virtual void initThermo(); + //! Set the equation of state parameters /*! * @internal diff --git a/src/thermo/FixedChemPotSSTP.cpp b/src/thermo/FixedChemPotSSTP.cpp index 7907cb143..30eac2de6 100644 --- a/src/thermo/FixedChemPotSSTP.cpp +++ b/src/thermo/FixedChemPotSSTP.cpp @@ -212,6 +212,14 @@ void FixedChemPotSSTP::initThermoXML(XML_Node& phaseNode, const std::string& id_ } } +void FixedChemPotSSTP::initThermo() +{ + if (m_input.hasKey("chemical-potential")) { + chemPot_ = m_input.convert("chemical-potential", "J/kmol"); + } + SingleSpeciesTP::initThermo(); +} + void FixedChemPotSSTP::setParameters(int n, doublereal* const c) { chemPot_ = c[0]; diff --git a/src/thermo/ThermoFactory.cpp b/src/thermo/ThermoFactory.cpp index 746587e79..a82fdd8a3 100644 --- a/src/thermo/ThermoFactory.cpp +++ b/src/thermo/ThermoFactory.cpp @@ -69,6 +69,7 @@ ThermoFactory::ThermoFactory() reg("Margules", []() { return new MargulesVPSSTP(); }); reg("IonsFromNeutralMolecule", []() { return new IonsFromNeutralVPSSTP(); }); reg("FixedChemPot", []() { return new FixedChemPotSSTP(); }); + m_synonyms["fixed-chemical-potential"] = "FixedChemPot"; reg("Redlich-Kister", []() { return new RedlichKisterVPSSTP(); }); reg("RedlichKwong", []() { return new RedlichKwongMFTP(); }); m_synonyms["RedlichKwongMFTP"] = "RedlichKwong"; diff --git a/test/data/thermo-models.yaml b/test/data/thermo-models.yaml index 49447926b..8f726733e 100644 --- a/test/data/thermo-models.yaml +++ b/test/data/thermo-models.yaml @@ -14,6 +14,11 @@ phases: thermo: water-IAPWS95 species: [H2O(l)] +- name: Li-fixed + thermo: fixed-chemical-potential + species: [Li] + chemical-potential: -2.3e7 J/kmol + species: - name: NaCl(s) composition: {Na: 1, Cl: 1} @@ -42,3 +47,6 @@ species: - name: H2O(l) composition: {H: 2, O: 1} + +- name: Li + composition: {Li: 1} diff --git a/test/thermo/thermoFromYaml.cpp b/test/thermo/thermoFromYaml.cpp index d56111fa7..fd641b0e6 100644 --- a/test/thermo/thermoFromYaml.cpp +++ b/test/thermo/thermoFromYaml.cpp @@ -102,3 +102,14 @@ TEST(ThermoFromYaml, WaterSSTP) EXPECT_NEAR(thermo->density(), 973.7736331, 1e-6); EXPECT_NEAR(thermo->enthalpy_mass(), -15649442.2898854, 1e-6); } + +TEST(ThermoFromYaml, FixedChemPot) +{ + AnyMap infile = AnyMap::fromYamlFile("thermo-models.yaml"); + auto phaseNodes = infile["phases"].asMap("name"); + auto thermo = newPhase(*phaseNodes.at("Li-fixed"), infile); + EXPECT_EQ(thermo->nSpecies(), (size_t) 1); + double mu; + thermo->getChemPotentials(&mu); + EXPECT_DOUBLE_EQ(mu, -2.3e7); +}