diff --git a/include/cantera/thermo/LatticePhase.h b/include/cantera/thermo/LatticePhase.h index 33b6ab544..0b056128d 100644 --- a/include/cantera/thermo/LatticePhase.h +++ b/include/cantera/thermo/LatticePhase.h @@ -602,10 +602,13 @@ public: //@{ virtual bool addSpecies(shared_ptr spec); - virtual void initThermoXML(XML_Node& phaseNode, const std::string& id); + + //! Set the density of lattice sites [kmol/m^3] + void setSiteDensity(double sitedens); //! Set the equation of state parameters from the argument list /*! + * @deprecated To be removed after Cantera 2.4. * @internal * Set equation of state parameters. * @@ -617,6 +620,7 @@ public: //! Get the equation of state parameters in a vector /*! + * @deprecated To be removed after Cantera 2.4. * @internal * * @param n number of parameters diff --git a/src/thermo/LatticePhase.cpp b/src/thermo/LatticePhase.cpp index 4434232f1..95ed78cc6 100644 --- a/src/thermo/LatticePhase.cpp +++ b/src/thermo/LatticePhase.cpp @@ -237,49 +237,18 @@ bool LatticePhase::addSpecies(shared_ptr spec) m_g0_RT.push_back(0.0); m_cp0_R.push_back(0.0); m_s0_R.push_back(0.0); - m_speciesMolarVolume.push_back(0.0); + if (spec->extra.hasKey("molar_volume")) { + m_speciesMolarVolume.push_back(spec->extra["molar_volume"].asDouble()); + } else { + m_speciesMolarVolume.push_back(1.0 / m_site_density); + } } return added; } -void LatticePhase::initThermoXML(XML_Node& phaseNode, const std::string& id_) +void LatticePhase::setSiteDensity(double sitedens) { - if (!id_.empty() && id_ != phaseNode.id()) { - throw CanteraError("LatticePhase::initThermoXML", - "ids don't match"); - } - - // Check on the thermo field. Must have: - // - if (phaseNode.hasChild("thermo")) { - XML_Node& thNode = phaseNode.child("thermo"); - if (!ba::iequals(thNode["model"], "lattice")) { - throw CanteraError("LatticePhase::initThermoXML", - "Unknown thermo model: " + thNode["model"]); - } - } else { - throw CanteraError("LatticePhase::initThermoXML", - "Unspecified thermo model"); - } - - // Now go get the molar volumes. use the default if not found - XML_Node& speciesList = phaseNode.child("speciesArray"); - XML_Node* speciesDB = get_XML_NameID("speciesData", speciesList["datasrc"], &phaseNode.root()); - - for (size_t k = 0; k < m_kk; k++) { - m_speciesMolarVolume[k] = 1.0 / m_site_density; - XML_Node* s = speciesDB->findByAttr("name", speciesName(k)); - if (!s) { - throw CanteraError(" LatticePhase::initThermoXML", "database problems"); - } - XML_Node* ss = s->findByName("standardState"); - if (ss && ss->findByName("molarVolume")) { - m_speciesMolarVolume[k] = getFloat(*ss, "molarVolume", "toSI"); - } - } - - // Call the base initThermo, which handles setting the initial state. - ThermoPhase::initThermoXML(phaseNode, id_); + m_site_density = sitedens; } void LatticePhase::_updateThermo() const @@ -297,12 +266,16 @@ void LatticePhase::_updateThermo() const void LatticePhase::setParameters(int n, doublereal* const c) { + warn_deprecated("LatticePhase::setParameters", + "To be removed after Cantera 2.4."); m_site_density = c[0]; setMolarDensity(m_site_density); } void LatticePhase::getParameters(int& n, doublereal* const c) const { + warn_deprecated("LatticePhase::getParameters", + "To be removed after Cantera 2.4."); c[0] = molarDensity(); n = 1; } @@ -310,7 +283,7 @@ void LatticePhase::getParameters(int& n, doublereal* const c) const void LatticePhase::setParametersFromXML(const XML_Node& eosdata) { eosdata._require("model", "Lattice"); - m_site_density = getFloat(eosdata, "site_density", "toSI"); + setSiteDensity(getFloat(eosdata, "site_density", "toSI")); } } diff --git a/src/thermo/Species.cpp b/src/thermo/Species.cpp index 22d17b28c..ebfe3322d 100644 --- a/src/thermo/Species.cpp +++ b/src/thermo/Species.cpp @@ -60,6 +60,12 @@ shared_ptr newSpecies(const XML_Node& species_node) s->extra["electrolyte_species_type"] = species_node.child("electrolyteSpeciesType").value(); } + // Extra data optionally used by LatticePhase + const XML_Node* stdstate = species_node.findByName("standardState"); + if (stdstate && stdstate->findByName("molarVolume")) { + s->extra["molar_volume"] = getFloat(*stdstate, "molarVolume", "toSI"); + } + return s; }