diff --git a/include/cantera/thermo/GibbsExcessVPSSTP.h b/include/cantera/thermo/GibbsExcessVPSSTP.h index 39d3dbccd8..0519c6a23a 100644 --- a/include/cantera/thermo/GibbsExcessVPSSTP.h +++ b/include/cantera/thermo/GibbsExcessVPSSTP.h @@ -226,23 +226,11 @@ class GibbsExcessVPSSTP : public VPStandardStateTP virtual void getPartialMolarVolumes(doublereal* vbar) const; virtual const vector_fp& getPartialMolarVolumesVector() const; - /** - * @} - * @name Setting the State - * These methods set all or part of the thermodynamic state. - * @{ - */ - - virtual void setMassFractions(const doublereal* const y); - virtual void setMassFractions_NoNorm(const doublereal* const y); - virtual void setMoleFractions(const doublereal* const x); - virtual void setMoleFractions_NoNorm(const doublereal* const x); - virtual void setConcentrations(const doublereal* const c); - //@} - virtual bool addSpecies(shared_ptr spec); protected: + virtual void compositionChanged(); + //! utility routine to check mole fraction sum /*! * @param x vector of mole fractions. diff --git a/include/cantera/thermo/IdealSolidSolnPhase.h b/include/cantera/thermo/IdealSolidSolnPhase.h index a4894630ee..6e9d4692d8 100644 --- a/include/cantera/thermo/IdealSolidSolnPhase.h +++ b/include/cantera/thermo/IdealSolidSolnPhase.h @@ -247,12 +247,6 @@ class IdealSolidSolnPhase : public ThermoPhase */ virtual void setMolarDensity(const doublereal rho); - virtual void setMoleFractions(const doublereal* const x); - virtual void setMoleFractions_NoNorm(const doublereal* const x); - virtual void setMassFractions(const doublereal* const y); - virtual void setMassFractions_NoNorm(const doublereal* const y); - virtual void setConcentrations(const doublereal* const c); - //@} /** @@ -646,6 +640,8 @@ class IdealSolidSolnPhase : public ThermoPhase //@} protected: + virtual void compositionChanged(); + /** * Format for the generalized concentrations. * diff --git a/include/cantera/thermo/IonsFromNeutralVPSSTP.h b/include/cantera/thermo/IonsFromNeutralVPSSTP.h index 53a54a1c67..46e0230341 100644 --- a/include/cantera/thermo/IonsFromNeutralVPSSTP.h +++ b/include/cantera/thermo/IonsFromNeutralVPSSTP.h @@ -320,12 +320,6 @@ class IonsFromNeutralVPSSTP : public GibbsExcessVPSSTP */ virtual void calcNeutralMoleculeMoleFractions() const; - virtual void setMassFractions(const doublereal* const y); - virtual void setMassFractions_NoNorm(const doublereal* const y); - virtual void setMoleFractions(const doublereal* const x); - virtual void setMoleFractions_NoNorm(const doublereal* const x); - virtual void setConcentrations(const doublereal* const c); - //@} virtual void initThermo(); @@ -386,6 +380,8 @@ class IonsFromNeutralVPSSTP : public GibbsExcessVPSSTP void s_update_dlnActCoeff_dlnN() const; protected: + virtual void compositionChanged(); + //! Ion solution type /*! * There is either mixing on the anion, cation, or both lattices. diff --git a/include/cantera/thermo/LatticePhase.h b/include/cantera/thermo/LatticePhase.h index 6cb2d9b509..946406f7b3 100644 --- a/include/cantera/thermo/LatticePhase.h +++ b/include/cantera/thermo/LatticePhase.h @@ -372,12 +372,6 @@ class LatticePhase : public ThermoPhase */ doublereal calcDensity(); - virtual void setMoleFractions(const doublereal* const x); - virtual void setMoleFractions_NoNorm(const doublereal* const x); - virtual void setMassFractions(const doublereal* const y); - virtual void setMassFractions_NoNorm(const doublereal* const y); - virtual void setConcentrations(const doublereal* const c); - //@} /// @name Activities, Standard States, and Activity Concentrations /** @@ -669,6 +663,8 @@ class LatticePhase : public ThermoPhase //@} protected: + virtual void compositionChanged(); + //! Reference state pressure doublereal m_Pref; diff --git a/include/cantera/thermo/MixtureFugacityTP.h b/include/cantera/thermo/MixtureFugacityTP.h index 1572bed813..627f19af31 100644 --- a/include/cantera/thermo/MixtureFugacityTP.h +++ b/include/cantera/thermo/MixtureFugacityTP.h @@ -292,13 +292,8 @@ class MixtureFugacityTP : public ThermoPhase virtual void setState_TR(doublereal T, doublereal rho); virtual void setState_TPX(doublereal t, doublereal p, const doublereal* x); - virtual void setMassFractions(const doublereal* const y); - virtual void setMassFractions_NoNorm(const doublereal* const y); - virtual void setMoleFractions(const doublereal* const x); - virtual void setMoleFractions_NoNorm(const doublereal* const x); - virtual void setConcentrations(const doublereal* const c); - protected: + virtual void compositionChanged(); void setMoleFractions_NoState(const doublereal* const x); public: diff --git a/include/cantera/thermo/Phase.h b/include/cantera/thermo/Phase.h index 180cb8d13d..441878d1a7 100644 --- a/include/cantera/thermo/Phase.h +++ b/include/cantera/thermo/Phase.h @@ -760,6 +760,15 @@ class Phase m_rmolwts[k] = 1.0/mw; } + //! Apply changes to the state which are needed after the composition + //! changes. This function is called after any call to setMassFractions(), + //! setMoleFractions(), or similar. For phases which need to execute a + //! callback after any change to the composition, it should be done by + //! overriding this function rather than overriding all of the composition- + //! setting functions. Derived class implementations of compositionChanged() + //! should call the parent class method as well. + virtual void compositionChanged(); + size_t m_kk; //!< Number of species in the phase. //! Dimensionality of the phase. Volumetric phases have dimensionality 3 diff --git a/include/cantera/thermo/RedlichKwongMFTP.h b/include/cantera/thermo/RedlichKwongMFTP.h index 8d0910dd2a..e0710350ea 100644 --- a/include/cantera/thermo/RedlichKwongMFTP.h +++ b/include/cantera/thermo/RedlichKwongMFTP.h @@ -99,12 +99,7 @@ class RedlichKwongMFTP : public MixtureFugacityTP virtual void calcDensity(); virtual void setTemperature(const doublereal temp); - - virtual void setMassFractions(const doublereal* const y); - virtual void setMassFractions_NoNorm(const doublereal* const y); - virtual void setMoleFractions(const doublereal* const x); - virtual void setMoleFractions_NoNorm(const doublereal* const x); - virtual void setConcentrations(const doublereal* const c); + virtual void compositionChanged(); public: virtual void getActivityConcentrations(doublereal* c) const; diff --git a/src/thermo/GibbsExcessVPSSTP.cpp b/src/thermo/GibbsExcessVPSSTP.cpp index 683a17c03c..05cc09cf1e 100644 --- a/src/thermo/GibbsExcessVPSSTP.cpp +++ b/src/thermo/GibbsExcessVPSSTP.cpp @@ -52,33 +52,9 @@ ThermoPhase* GibbsExcessVPSSTP::duplMyselfAsThermoPhase() const return new GibbsExcessVPSSTP(*this); } -void GibbsExcessVPSSTP::setMassFractions(const doublereal* const y) +void GibbsExcessVPSSTP::compositionChanged() { - Phase::setMassFractions(y); - getMoleFractions(moleFractions_.data()); -} - -void GibbsExcessVPSSTP::setMassFractions_NoNorm(const doublereal* const y) -{ - Phase::setMassFractions_NoNorm(y); - getMoleFractions(moleFractions_.data()); -} - -void GibbsExcessVPSSTP::setMoleFractions(const doublereal* const x) -{ - Phase::setMoleFractions(x); - getMoleFractions(moleFractions_.data()); -} - -void GibbsExcessVPSSTP::setMoleFractions_NoNorm(const doublereal* const x) -{ - Phase::setMoleFractions_NoNorm(x); - getMoleFractions(moleFractions_.data()); -} - -void GibbsExcessVPSSTP::setConcentrations(const doublereal* const c) -{ - Phase::setConcentrations(c); + Phase::compositionChanged(); getMoleFractions(moleFractions_.data()); } diff --git a/src/thermo/IdealSolidSolnPhase.cpp b/src/thermo/IdealSolidSolnPhase.cpp index 7966b0f40b..051dc8b446 100644 --- a/src/thermo/IdealSolidSolnPhase.cpp +++ b/src/thermo/IdealSolidSolnPhase.cpp @@ -168,33 +168,9 @@ void IdealSolidSolnPhase::setMolarDensity(const doublereal n) "Density is not an independent variable"); } -void IdealSolidSolnPhase::setMoleFractions(const doublereal* const x) +void IdealSolidSolnPhase::compositionChanged() { - Phase::setMoleFractions(x); - calcDensity(); -} - -void IdealSolidSolnPhase::setMoleFractions_NoNorm(const doublereal* const x) -{ - Phase::setMoleFractions(x); - calcDensity(); -} - -void IdealSolidSolnPhase::setMassFractions(const doublereal* const y) -{ - Phase::setMassFractions(y); - calcDensity(); -} - -void IdealSolidSolnPhase::setMassFractions_NoNorm(const doublereal* const y) -{ - Phase::setMassFractions_NoNorm(y); - calcDensity(); -} - -void IdealSolidSolnPhase::setConcentrations(const doublereal* const c) -{ - Phase::setConcentrations(c); + Phase::compositionChanged(); calcDensity(); } diff --git a/src/thermo/IonsFromNeutralVPSSTP.cpp b/src/thermo/IonsFromNeutralVPSSTP.cpp index 34b67f5f9a..acd7db67cb 100644 --- a/src/thermo/IonsFromNeutralVPSSTP.cpp +++ b/src/thermo/IonsFromNeutralVPSSTP.cpp @@ -551,37 +551,9 @@ void IonsFromNeutralVPSSTP::getNeutralMoleculeMoleGrads(const doublereal* const } } -void IonsFromNeutralVPSSTP::setMassFractions(const doublereal* const y) +void IonsFromNeutralVPSSTP::compositionChanged() { - GibbsExcessVPSSTP::setMassFractions(y); - calcNeutralMoleculeMoleFractions(); - neutralMoleculePhase_->setMoleFractions(NeutralMolecMoleFractions_.data()); -} - -void IonsFromNeutralVPSSTP::setMassFractions_NoNorm(const doublereal* const y) -{ - GibbsExcessVPSSTP::setMassFractions_NoNorm(y); - calcNeutralMoleculeMoleFractions(); - neutralMoleculePhase_->setMoleFractions(NeutralMolecMoleFractions_.data()); -} - -void IonsFromNeutralVPSSTP::setMoleFractions(const doublereal* const x) -{ - GibbsExcessVPSSTP::setMoleFractions(x); - calcNeutralMoleculeMoleFractions(); - neutralMoleculePhase_->setMoleFractions(NeutralMolecMoleFractions_.data()); -} - -void IonsFromNeutralVPSSTP::setMoleFractions_NoNorm(const doublereal* const x) -{ - GibbsExcessVPSSTP::setMoleFractions_NoNorm(x); - calcNeutralMoleculeMoleFractions(); - neutralMoleculePhase_->setMoleFractions_NoNorm(NeutralMolecMoleFractions_.data()); -} - -void IonsFromNeutralVPSSTP::setConcentrations(const doublereal* const c) -{ - GibbsExcessVPSSTP::setConcentrations(c); + GibbsExcessVPSSTP::compositionChanged(); calcNeutralMoleculeMoleFractions(); neutralMoleculePhase_->setMoleFractions(NeutralMolecMoleFractions_.data()); } diff --git a/src/thermo/LatticePhase.cpp b/src/thermo/LatticePhase.cpp index dd1974a223..d40c098122 100644 --- a/src/thermo/LatticePhase.cpp +++ b/src/thermo/LatticePhase.cpp @@ -96,33 +96,9 @@ void LatticePhase::setPressure(doublereal p) calcDensity(); } -void LatticePhase::setMoleFractions(const doublereal* const x) +void LatticePhase::compositionChanged() { - Phase::setMoleFractions(x); - calcDensity(); -} - -void LatticePhase::setMoleFractions_NoNorm(const doublereal* const x) -{ - Phase::setMoleFractions(x); - calcDensity(); -} - -void LatticePhase::setMassFractions(const doublereal* const y) -{ - Phase::setMassFractions(y); - calcDensity(); -} - -void LatticePhase::setMassFractions_NoNorm(const doublereal* const y) -{ - Phase::setMassFractions_NoNorm(y); - calcDensity(); -} - -void LatticePhase::setConcentrations(const doublereal* const c) -{ - Phase::setConcentrations(c); + Phase::compositionChanged(); calcDensity(); } diff --git a/src/thermo/MixtureFugacityTP.cpp b/src/thermo/MixtureFugacityTP.cpp index f1510a57d9..c154bf750f 100644 --- a/src/thermo/MixtureFugacityTP.cpp +++ b/src/thermo/MixtureFugacityTP.cpp @@ -277,33 +277,9 @@ void MixtureFugacityTP::setPressure(doublereal p) setState_TP(temperature(), p); } -void MixtureFugacityTP::setMassFractions(const doublereal* const y) +void MixtureFugacityTP::compositionChanged() { - Phase::setMassFractions(y); - getMoleFractions(moleFractions_.data()); -} - -void MixtureFugacityTP::setMassFractions_NoNorm(const doublereal* const y) -{ - Phase::setMassFractions_NoNorm(y); - getMoleFractions(moleFractions_.data()); -} - -void MixtureFugacityTP::setMoleFractions(const doublereal* const x) -{ - Phase::setMoleFractions(x); - getMoleFractions(moleFractions_.data()); -} - -void MixtureFugacityTP::setMoleFractions_NoNorm(const doublereal* const x) -{ - Phase::setMoleFractions_NoNorm(x); - getMoleFractions(moleFractions_.data()); -} - -void MixtureFugacityTP::setConcentrations(const doublereal* const c) -{ - Phase::setConcentrations(c); + Phase::compositionChanged(); getMoleFractions(moleFractions_.data()); } diff --git a/src/thermo/Phase.cpp b/src/thermo/Phase.cpp index de071e5d48..59a4c88875 100644 --- a/src/thermo/Phase.cpp +++ b/src/thermo/Phase.cpp @@ -307,6 +307,7 @@ void Phase::saveState(size_t lenstate, doublereal* state) const void Phase::restoreState(const vector_fp& state) { restoreState(state.size(),&state[0]); + compositionChanged(); } void Phase::restoreState(size_t lenstate, const doublereal* state) @@ -350,7 +351,7 @@ void Phase::setMoleFractions(const doublereal* const x) // Calculate the normalized molecular weight m_mmw = sum/norm; - m_stateNum++; + compositionChanged(); } void Phase::setMoleFractions_NoNorm(const doublereal* const x) @@ -359,7 +360,7 @@ void Phase::setMoleFractions_NoNorm(const doublereal* const x) transform(x, x + m_kk, m_ym.begin(), timesConstant(1.0/m_mmw)); transform(m_ym.begin(), m_ym.begin() + m_kk, m_molwts.begin(), m_y.begin(), multiplies()); - m_stateNum++; + compositionChanged(); } void Phase::setMoleFractionsByName(const compositionMap& xMap) @@ -392,7 +393,7 @@ void Phase::setMassFractions(const doublereal* const y) transform(m_y.begin(), m_y.end(), m_rmolwts.begin(), m_ym.begin(), multiplies()); m_mmw = 1.0 / accumulate(m_ym.begin(), m_ym.end(), 0.0); - m_stateNum++; + compositionChanged(); } void Phase::setMassFractions_NoNorm(const doublereal* const y) @@ -403,7 +404,7 @@ void Phase::setMassFractions_NoNorm(const doublereal* const y) multiplies()); sum = accumulate(m_ym.begin(), m_ym.end(), 0.0); m_mmw = 1.0/sum; - m_stateNum++; + compositionChanged(); } void Phase::setMassFractionsByName(const compositionMap& yMap) @@ -611,7 +612,7 @@ void Phase::setConcentrations(const doublereal* const conc) m_ym[k] = m_y[k] * rsum; m_y[k] = m_ym[k] * m_molwts[k]; // m_y is now the mass fraction } - m_stateNum++; + compositionChanged(); } void Phase::setConcentrationsNoNorm(const double* const conc) @@ -628,7 +629,7 @@ void Phase::setConcentrationsNoNorm(const double* const conc) m_ym[k] = conc[k] * rsum; m_y[k] = m_ym[k] * m_molwts[k]; } - m_stateNum++; + compositionChanged(); } doublereal Phase::elementalMassFraction(const size_t m) const @@ -886,4 +887,8 @@ void Phase::invalidateCache() { m_cache.clear(); } +void Phase::compositionChanged() { + m_stateNum++; +} + } // namespace Cantera diff --git a/src/thermo/RedlichKwongMFTP.cpp b/src/thermo/RedlichKwongMFTP.cpp index d9a419004c..90307fb7ce 100644 --- a/src/thermo/RedlichKwongMFTP.cpp +++ b/src/thermo/RedlichKwongMFTP.cpp @@ -198,33 +198,9 @@ void RedlichKwongMFTP::setTemperature(const doublereal temp) updateAB(); } -void RedlichKwongMFTP::setMassFractions(const doublereal* const x) +void RedlichKwongMFTP::compositionChanged() { - MixtureFugacityTP::setMassFractions(x); - updateAB(); -} - -void RedlichKwongMFTP::setMassFractions_NoNorm(const doublereal* const x) -{ - MixtureFugacityTP::setMassFractions_NoNorm(x); - updateAB(); -} - -void RedlichKwongMFTP::setMoleFractions(const doublereal* const x) -{ - MixtureFugacityTP::setMoleFractions(x); - updateAB(); -} - -void RedlichKwongMFTP::setMoleFractions_NoNorm(const doublereal* const x) -{ - MixtureFugacityTP::setMoleFractions(x); - updateAB(); -} - -void RedlichKwongMFTP::setConcentrations(const doublereal* const c) -{ - MixtureFugacityTP::setConcentrations(c); + MixtureFugacityTP::compositionChanged(); updateAB(); }