diff --git a/include/cantera/thermo/IdealSolidSolnPhase.h b/include/cantera/thermo/IdealSolidSolnPhase.h index 62afeed86a..ef42b5aa47 100644 --- a/include/cantera/thermo/IdealSolidSolnPhase.h +++ b/include/cantera/thermo/IdealSolidSolnPhase.h @@ -596,7 +596,7 @@ class IdealSolidSolnPhase : public ThermoPhase virtual bool addSpecies(shared_ptr spec); virtual void initThermo(); virtual void initThermoXML(XML_Node& phaseNode, const std::string& id); - virtual void setToEquilState(const doublereal* lambda_RT); + virtual void setToEquilState(const doublereal* mu_RT); //! Set the form for the standard and generalized concentrations /*! diff --git a/include/cantera/thermo/RedlichKwongMFTP.h b/include/cantera/thermo/RedlichKwongMFTP.h index 803c6d76f2..fa5e4f0eb5 100644 --- a/include/cantera/thermo/RedlichKwongMFTP.h +++ b/include/cantera/thermo/RedlichKwongMFTP.h @@ -176,7 +176,6 @@ class RedlichKwongMFTP : public MixtureFugacityTP virtual bool addSpecies(shared_ptr spec); virtual void setParametersFromXML(const XML_Node& thermoNode); - virtual void setToEquilState(const doublereal* lambda_RT); virtual void initThermoXML(XML_Node& phaseNode, const std::string& id); virtual void initThermo(); diff --git a/include/cantera/thermo/ThermoPhase.h b/include/cantera/thermo/ThermoPhase.h index e0b0965f3e..d49ded492b 100644 --- a/include/cantera/thermo/ThermoPhase.h +++ b/include/cantera/thermo/ThermoPhase.h @@ -1457,10 +1457,10 @@ class ThermoPhase : public Phase * temperature is unchanged. Any phase (ideal or not) that * implements this method can be equilibrated by ChemEquil. * - * @param lambda_RT Input vector of dimensionless element potentials - * The length is equal to nElements(). + * @param mu_RT Input vector of dimensionless chemical potentials + * The length is equal to nSpecies(). */ - virtual void setToEquilState(const doublereal* lambda_RT) { + virtual void setToEquilState(const doublereal* mu_RT) { throw NotImplementedError("ThermoPhase::setToEquilState"); } diff --git a/interfaces/cython/cantera/test/test_equilibrium.py b/interfaces/cython/cantera/test/test_equilibrium.py index 0ff4a0dc34..b33ef5f4ad 100644 --- a/interfaces/cython/cantera/test/test_equilibrium.py +++ b/interfaces/cython/cantera/test/test_equilibrium.py @@ -216,3 +216,13 @@ def test_vcs(self): def test_vcs_est(self): self.solve('vcs', estimate_equil=-1) + + +class Test_IdealSolidSolnPhase_Equil(utilities.CanteraTest): + def test_equil(self): + gas = ct.ThermoPhase('IdealSolidSolnPhaseExample.xml') + gas.TPX = 500, ct.one_atm, 'C2H2-graph: 1.0' + + gas.equilibrate('TP', solver='element_potential') + self.assertNear(gas['C-graph'].X[0], 2.0 / 3.0) + self.assertNear(gas['H2-solute'].X[0], 1.0 / 3.0) diff --git a/src/thermo/IdealSolidSolnPhase.cpp b/src/thermo/IdealSolidSolnPhase.cpp index befac7571a..054607a2a9 100644 --- a/src/thermo/IdealSolidSolnPhase.cpp +++ b/src/thermo/IdealSolidSolnPhase.cpp @@ -447,21 +447,28 @@ void IdealSolidSolnPhase::initThermoXML(XML_Node& phaseNode, const std::string& ThermoPhase::initThermoXML(phaseNode, id_); } -void IdealSolidSolnPhase::setToEquilState(const doublereal* lambda_RT) +void IdealSolidSolnPhase::setToEquilState(const doublereal* mu_RT) { const vector_fp& grt = gibbs_RT_ref(); - // set the pressure and composition to be consistent with the temperature doublereal pres = 0.0; + double m_p0 = refPressure(); for (size_t k = 0; k < m_kk; k++) { - m_pp[k] = -grt[k]; - for (size_t m = 0; m < nElements(); m++) { - m_pp[k] += nAtoms(k,m)*lambda_RT[m]; + double tmp = -grt[k] + mu_RT[k]; + if (tmp < -600.) { + m_pp[k] = 0.0; + } else if (tmp > 500.0) { + // Protect against inf results if the exponent is too high + double tmp2 = tmp / 500.; + tmp2 *= tmp2; + m_pp[k] = m_p0 * exp(500.) * tmp2; + } else { + m_pp[k] = m_p0 * exp(tmp); } - m_pp[k] = m_Pref * exp(m_pp[k]); pres += m_pp[k]; } - setState_PX(pres, &m_pp[0]); + // set state + setState_PX(pres, m_pp.data()); } void IdealSolidSolnPhase::setStandardConcentrationModel(const std::string& model) diff --git a/src/thermo/RedlichKwongMFTP.cpp b/src/thermo/RedlichKwongMFTP.cpp index 58ad30f6fe..7ce8021fb7 100644 --- a/src/thermo/RedlichKwongMFTP.cpp +++ b/src/thermo/RedlichKwongMFTP.cpp @@ -518,36 +518,6 @@ doublereal RedlichKwongMFTP::critDensity() const return mmw / vc; } -void RedlichKwongMFTP::setToEquilState(const doublereal* mu_RT) -{ - double tmp, tmp2; - _updateReferenceStateThermo(); - getGibbs_RT_ref(m_tmpV.data()); - - // Within the method, we protect against inf results if the exponent is too - // high. - // - // If it is too low, we set the partial pressure to zero. This capability is - // needed by the elemental potential method. - doublereal pres = 0.0; - double m_p0 = refPressure(); - for (size_t k = 0; k < m_kk; k++) { - tmp = -m_tmpV[k] + mu_RT[k]; - if (tmp < -600.) { - m_pp[k] = 0.0; - } else if (tmp > 500.0) { - tmp2 = tmp / 500.; - tmp2 *= tmp2; - m_pp[k] = m_p0 * exp(500.) * tmp2; - } else { - m_pp[k] = m_p0 * exp(tmp); - } - pres += m_pp[k]; - } - // set state - setState_PX(pres, &m_pp[0]); -} - bool RedlichKwongMFTP::addSpecies(shared_ptr spec) { bool added = MixtureFugacityTP::addSpecies(spec);