From 35679c2e9ec13f3bc01850c8fcd2a354ba34cc88 Mon Sep 17 00:00:00 2001 From: Ray Speth Date: Sun, 12 Feb 2017 22:19:50 -0500 Subject: [PATCH] [Thermo] Make m_species a non-pointer member of ThermoPhase --- include/cantera/thermo/ThermoPhase.h | 12 ++++++------ src/thermo/ConstDensityThermo.cpp | 8 ++++---- src/thermo/IdealGasPhase.cpp | 14 +++++++------- src/thermo/IdealSolidSolnPhase.cpp | 2 +- src/thermo/LatticePhase.cpp | 2 +- src/thermo/MaskellSolidSolnPhase.cpp | 2 +- src/thermo/MixtureFugacityTP.cpp | 10 +++++----- src/thermo/PureFluidPhase.cpp | 6 +++--- src/thermo/RedlichKwongMFTP.cpp | 2 +- src/thermo/SingleSpeciesTP.cpp | 2 +- src/thermo/SurfPhase.cpp | 2 +- src/thermo/ThermoPhase.cpp | 19 +++++++------------ src/thermo/VPStandardStateTP.cpp | 4 ++-- src/thermo/WaterSSTP.cpp | 4 ---- 14 files changed, 40 insertions(+), 49 deletions(-) diff --git a/include/cantera/thermo/ThermoPhase.h b/include/cantera/thermo/ThermoPhase.h index b06ed14e4..861fd36fd 100644 --- a/include/cantera/thermo/ThermoPhase.h +++ b/include/cantera/thermo/ThermoPhase.h @@ -114,7 +114,7 @@ public: * that calls the species thermo refPressure function. */ virtual doublereal refPressure() const { - return m_spthermo->refPressure(); + return m_spthermo.refPressure(); } //! Minimum temperature for which the thermodynamic data for the species @@ -129,7 +129,7 @@ public: * of the min value over all species. */ virtual doublereal minTemp(size_t k = npos) const { - return m_spthermo->minTemp(k); + return m_spthermo.minTemp(k); } //! Report the 298 K Heat of Formation of the standard state of one species @@ -144,7 +144,7 @@ public: * and 1 bar */ doublereal Hf298SS(const size_t k) const { - return m_spthermo->reportOneHf298(k); + return m_spthermo.reportOneHf298(k); } //! Modify the value of the 298 K Heat of Formation of one species in the @@ -159,7 +159,7 @@ public: * 298K and 1 bar */ virtual void modifyOneHf298SS(const size_t k, const doublereal Hf298New) { - m_spthermo->modifyOneHf298(k, Hf298New); + m_spthermo.modifyOneHf298(k, Hf298New); invalidateCache(); } @@ -182,7 +182,7 @@ public: * of the max value over all species. */ virtual doublereal maxTemp(size_t k = npos) const { - return m_spthermo->maxTemp(k); + return m_spthermo.maxTemp(k); } //! Returns the chargeNeutralityNecessity boolean @@ -1604,7 +1604,7 @@ protected: * This class is called when the reference-state thermodynamic properties * of all the species in the phase needs to be evaluated. */ - MultiSpeciesThermo* m_spthermo; + MultiSpeciesThermo m_spthermo; //! Vector of pointers to the species databases. /*! diff --git a/src/thermo/ConstDensityThermo.cpp b/src/thermo/ConstDensityThermo.cpp index 60af0f624..420f53adb 100644 --- a/src/thermo/ConstDensityThermo.cpp +++ b/src/thermo/ConstDensityThermo.cpp @@ -16,7 +16,7 @@ namespace Cantera doublereal ConstDensityThermo::enthalpy_mole() const { - doublereal p0 = m_spthermo->refPressure(); + doublereal p0 = refPressure(); return RT() * mean_X(enthalpy_RT()) + (pressure() - p0)/molarDensity(); } @@ -64,7 +64,7 @@ doublereal ConstDensityThermo::standardConcentration(size_t k) const void ConstDensityThermo::getChemPotentials(doublereal* mu) const { - doublereal vdp = (pressure() - m_spthermo->refPressure())/ + doublereal vdp = (pressure() - refPressure())/ molarDensity(); const vector_fp& g_RT = gibbs_RT(); for (size_t k = 0; k < m_kk; k++) { @@ -95,8 +95,8 @@ void ConstDensityThermo::_updateThermo() const { doublereal tnow = temperature(); if (m_tlast != tnow) { - m_spthermo->update(tnow, &m_cp0_R[0], &m_h0_RT[0], - &m_s0_R[0]); + m_spthermo.update(tnow, &m_cp0_R[0], &m_h0_RT[0], + &m_s0_R[0]); m_tlast = tnow; for (size_t k = 0; k < m_kk; k++) { m_g0_RT[k] = m_h0_RT[k] - m_s0_R[k]; diff --git a/src/thermo/IdealGasPhase.cpp b/src/thermo/IdealGasPhase.cpp index 5c4dba927..e25e71497 100644 --- a/src/thermo/IdealGasPhase.cpp +++ b/src/thermo/IdealGasPhase.cpp @@ -38,7 +38,7 @@ IdealGasPhase::IdealGasPhase(XML_Node& phaseRef, const std::string& id_) : doublereal IdealGasPhase::entropy_mole() const { - return GasConstant * (mean_X(entropy_R_ref()) - sum_xlogx() - std::log(pressure() / m_spthermo->refPressure())); + return GasConstant * (mean_X(entropy_R_ref()) - sum_xlogx() - std::log(pressure() / refPressure())); } doublereal IdealGasPhase::cp_mole() const @@ -67,7 +67,7 @@ void IdealGasPhase::getStandardChemPotentials(doublereal* muStar) const { const vector_fp& gibbsrt = gibbs_RT_ref(); scale(gibbsrt.begin(), gibbsrt.end(), muStar, RT()); - double tmp = log(pressure() / m_spthermo->refPressure()) * RT(); + double tmp = log(pressure() / refPressure()) * RT(); for (size_t k = 0; k < m_kk; k++) { muStar[k] += tmp; // add RT*ln(P/P_0) } @@ -94,7 +94,7 @@ void IdealGasPhase::getPartialMolarEntropies(doublereal* sbar) const { const vector_fp& _s = entropy_R_ref(); scale(_s.begin(), _s.end(), sbar, GasConstant); - doublereal logp = log(pressure() / m_spthermo->refPressure()); + doublereal logp = log(pressure() / refPressure()); for (size_t k = 0; k < m_kk; k++) { doublereal xx = std::max(SmallNumber, moleFraction(k)); sbar[k] += GasConstant * (-logp - log(xx)); @@ -135,7 +135,7 @@ void IdealGasPhase::getEntropy_R(doublereal* sr) const { const vector_fp& _s = entropy_R_ref(); copy(_s.begin(), _s.end(), sr); - double tmp = log(pressure() / m_spthermo->refPressure()); + double tmp = log(pressure() / refPressure()); for (size_t k = 0; k < m_kk; k++) { sr[k] -= tmp; } @@ -145,7 +145,7 @@ void IdealGasPhase::getGibbs_RT(doublereal* grt) const { const vector_fp& gibbsrt = gibbs_RT_ref(); copy(gibbsrt.begin(), gibbsrt.end(), grt); - double tmp = log(pressure() / m_spthermo->refPressure()); + double tmp = log(pressure() / refPressure()); for (size_t k = 0; k < m_kk; k++) { grt[k] += tmp; } @@ -155,7 +155,7 @@ void IdealGasPhase::getPureGibbs(doublereal* gpure) const { const vector_fp& gibbsrt = gibbs_RT_ref(); scale(gibbsrt.begin(), gibbsrt.end(), gpure, RT()); - double tmp = log(pressure() / m_spthermo->refPressure()) * RT(); + double tmp = log(pressure() / refPressure()) * RT(); for (size_t k = 0; k < m_kk; k++) { gpure[k] += tmp; } @@ -284,7 +284,7 @@ void IdealGasPhase::_updateThermo() const // If the temperature has changed since the last time these // properties were computed, recompute them. if (cached.state1 != tnow) { - m_spthermo->update(tnow, &m_cp0_R[0], &m_h0_RT[0], &m_s0_R[0]); + m_spthermo.update(tnow, &m_cp0_R[0], &m_h0_RT[0], &m_s0_R[0]); cached.state1 = tnow; // update the species Gibbs functions diff --git a/src/thermo/IdealSolidSolnPhase.cpp b/src/thermo/IdealSolidSolnPhase.cpp index b93a2ffc8..5c1fda1bb 100644 --- a/src/thermo/IdealSolidSolnPhase.cpp +++ b/src/thermo/IdealSolidSolnPhase.cpp @@ -456,7 +456,7 @@ void IdealSolidSolnPhase::_updateThermo() const if (m_tlast != tnow) { // Update the thermodynamic functions of the reference state. - m_spthermo->update(tnow, m_cp0_R.data(), m_h0_RT.data(), m_s0_R.data()); + m_spthermo.update(tnow, m_cp0_R.data(), m_h0_RT.data(), m_s0_R.data()); m_tlast = tnow; doublereal rrt = 1.0 / RT(); for (size_t k = 0; k < m_kk; k++) { diff --git a/src/thermo/LatticePhase.cpp b/src/thermo/LatticePhase.cpp index f6b96881a..32fc40595 100644 --- a/src/thermo/LatticePhase.cpp +++ b/src/thermo/LatticePhase.cpp @@ -286,7 +286,7 @@ void LatticePhase::_updateThermo() const { doublereal tnow = temperature(); if (m_tlast != tnow) { - m_spthermo->update(tnow, &m_cp0_R[0], &m_h0_RT[0], &m_s0_R[0]); + m_spthermo.update(tnow, &m_cp0_R[0], &m_h0_RT[0], &m_s0_R[0]); m_tlast = tnow; for (size_t k = 0; k < m_kk; k++) { m_g0_RT[k] = m_h0_RT[k] - m_s0_R[k]; diff --git a/src/thermo/MaskellSolidSolnPhase.cpp b/src/thermo/MaskellSolidSolnPhase.cpp index e5c331703..7f58c373a 100644 --- a/src/thermo/MaskellSolidSolnPhase.cpp +++ b/src/thermo/MaskellSolidSolnPhase.cpp @@ -245,7 +245,7 @@ void MaskellSolidSolnPhase::_updateThermo() const // Update the thermodynamic functions of the reference state. doublereal tnow = temperature(); if (!cached.validate(tnow)) { - m_spthermo->update(tnow, m_cp0_R.data(), m_h0_RT.data(), m_s0_R.data()); + m_spthermo.update(tnow, m_cp0_R.data(), m_h0_RT.data(), m_s0_R.data()); for (size_t k = 0; k < m_kk; k++) { m_g0_RT[k] = m_h0_RT[k] - m_s0_R[k]; } diff --git a/src/thermo/MixtureFugacityTP.cpp b/src/thermo/MixtureFugacityTP.cpp index eb0e401aa..36ca48e21 100644 --- a/src/thermo/MixtureFugacityTP.cpp +++ b/src/thermo/MixtureFugacityTP.cpp @@ -60,7 +60,7 @@ void MixtureFugacityTP::getStandardChemPotentials(doublereal* g) const { _updateReferenceStateThermo(); copy(m_g0_RT.begin(), m_g0_RT.end(), g); - double tmp = log(pressure() /m_spthermo->refPressure()); + double tmp = log(pressure() / refPressure()); for (size_t k = 0; k < m_kk; k++) { g[k] = RT() * (g[k] + tmp); } @@ -75,7 +75,7 @@ void MixtureFugacityTP::getEntropy_R(doublereal* sr) const { _updateReferenceStateThermo(); copy(m_s0_R.begin(), m_s0_R.end(), sr); - double tmp = log(pressure() /m_spthermo->refPressure()); + double tmp = log(pressure() / refPressure()); for (size_t k = 0; k < m_kk; k++) { sr[k] -= tmp; } @@ -85,7 +85,7 @@ void MixtureFugacityTP::getGibbs_RT(doublereal* grt) const { _updateReferenceStateThermo(); copy(m_g0_RT.begin(), m_g0_RT.end(), grt); - double tmp = log(pressure() /m_spthermo->refPressure()); + double tmp = log(pressure() / refPressure()); for (size_t k = 0; k < m_kk; k++) { grt[k] += tmp; } @@ -95,7 +95,7 @@ void MixtureFugacityTP::getPureGibbs(doublereal* g) const { _updateReferenceStateThermo(); scale(m_g0_RT.begin(), m_g0_RT.end(), g, RT()); - double tmp = log(pressure() /m_spthermo->refPressure()) * RT(); + double tmp = log(pressure() / refPressure()) * RT(); for (size_t k = 0; k < m_kk; k++) { g[k] += tmp; } @@ -796,7 +796,7 @@ void MixtureFugacityTP::_updateReferenceStateThermo() const // If the temperature has changed since the last time these // properties were computed, recompute them. if (m_Tlast_ref != Tnow) { - m_spthermo->update(Tnow, &m_cp0_R[0], &m_h0_RT[0], &m_s0_R[0]); + m_spthermo.update(Tnow, &m_cp0_R[0], &m_h0_RT[0], &m_s0_R[0]); m_Tlast_ref = Tnow; // update the species Gibbs functions diff --git a/src/thermo/PureFluidPhase.cpp b/src/thermo/PureFluidPhase.cpp index 5f3631662..ddb736f5c 100644 --- a/src/thermo/PureFluidPhase.cpp +++ b/src/thermo/PureFluidPhase.cpp @@ -55,7 +55,7 @@ void PureFluidPhase::initThermo() p = 0.001 * p; m_sub->Set(tpx::PropertyPair::TP, T0, p); - m_spthermo->update_single(0, T0, &cp0_R, &h0_RT, &s0_R); + m_spthermo.update_single(0, T0, &cp0_R, &h0_RT, &s0_R); double s_R = s0_R - log(p/refPressure()); m_sub->setStdState(h0_RT*GasConstant*298.15/m_mw, s_R*GasConstant/m_mw, T0, p); @@ -221,7 +221,7 @@ void PureFluidPhase::getGibbs_RT_ref(doublereal* grt) const { double psave = pressure(); double t = temperature(); - double pref = m_spthermo->refPressure(); + double pref = refPressure(); double plow = 1.0E-8; Set(tpx::PropertyPair::TP, t, plow); getGibbs_RT(grt); @@ -239,7 +239,7 @@ void PureFluidPhase::getEntropy_R_ref(doublereal* er) const { double psave = pressure(); double t = temperature(); - double pref = m_spthermo->refPressure(); + double pref = refPressure(); double plow = 1.0E-8; Set(tpx::PropertyPair::TP, t, plow); getEntropy_R(er); diff --git a/src/thermo/RedlichKwongMFTP.cpp b/src/thermo/RedlichKwongMFTP.cpp index 24969e035..4efe62fcb 100644 --- a/src/thermo/RedlichKwongMFTP.cpp +++ b/src/thermo/RedlichKwongMFTP.cpp @@ -128,7 +128,7 @@ doublereal RedlichKwongMFTP::entropy_mole() const { _updateReferenceStateThermo(); doublereal sr_ideal = GasConstant * (mean_X(m_s0_R) - - sum_xlogx() - std::log(pressure()/m_spthermo->refPressure())); + - sum_xlogx() - std::log(pressure()/refPressure())); doublereal sr_nonideal = sresid(); return sr_ideal + sr_nonideal; } diff --git a/src/thermo/SingleSpeciesTP.cpp b/src/thermo/SingleSpeciesTP.cpp index 8c7a709f2..c2653d3a7 100644 --- a/src/thermo/SingleSpeciesTP.cpp +++ b/src/thermo/SingleSpeciesTP.cpp @@ -262,7 +262,7 @@ void SingleSpeciesTP::_updateThermo() const { doublereal tnow = temperature(); if (m_tlast != tnow) { - m_spthermo->update(tnow, &m_cp0_R, &m_h0_RT, &m_s0_R); + m_spthermo.update(tnow, &m_cp0_R, &m_h0_RT, &m_s0_R); m_tlast = tnow; } } diff --git a/src/thermo/SurfPhase.cpp b/src/thermo/SurfPhase.cpp index e4f2b3178..d0f180ac6 100644 --- a/src/thermo/SurfPhase.cpp +++ b/src/thermo/SurfPhase.cpp @@ -292,7 +292,7 @@ void SurfPhase::_updateThermo(bool force) const { doublereal tnow = temperature(); if (m_tlast != tnow || force) { - m_spthermo->update(tnow, m_cp0.data(), m_h0.data(), m_s0.data()); + m_spthermo.update(tnow, m_cp0.data(), m_h0.data(), m_s0.data()); m_tlast = tnow; for (size_t k = 0; k < m_kk; k++) { m_h0[k] *= GasConstant * tnow; diff --git a/src/thermo/ThermoPhase.cpp b/src/thermo/ThermoPhase.cpp index 4f486460d..a2daee453 100644 --- a/src/thermo/ThermoPhase.cpp +++ b/src/thermo/ThermoPhase.cpp @@ -25,7 +25,7 @@ namespace Cantera { ThermoPhase::ThermoPhase() : - m_spthermo(new MultiSpeciesThermo()), m_speciesData(0), + m_speciesData(0), m_phi(0.0), m_hasElementPotentials(false), m_chargeNeutralityNecessary(false), @@ -39,15 +39,14 @@ ThermoPhase::~ThermoPhase() for (size_t k = 0; k < m_speciesData.size(); k++) { delete m_speciesData[k]; } - delete m_spthermo; } void ThermoPhase::resetHf298(size_t k) { if (k != npos) { - m_spthermo->resetHf298(k); + m_spthermo.resetHf298(k); } else { for (size_t k = 0; k < nSpecies(); k++) { - m_spthermo->resetHf298(k); + m_spthermo.resetHf298(k); } } invalidateCache(); @@ -577,11 +576,7 @@ void ThermoPhase::setState_SPorSV(double Starget, double p, MultiSpeciesThermo& ThermoPhase::speciesThermo(int k) { - if (!m_spthermo) { - throw CanteraError("ThermoPhase::speciesThermo()", - "species reference state thermo manager was not set"); - } - return *m_spthermo; + return m_spthermo; } void ThermoPhase::initThermoFile(const std::string& inputFile, @@ -607,7 +602,7 @@ void ThermoPhase::initThermoXML(XML_Node& phaseNode, const std::string& id) void ThermoPhase::initThermo() { // Check to see that all of the species thermo objects have been initialized - if (!m_spthermo->ready(m_kk)) { + if (!m_spthermo.ready(m_kk)) { throw CanteraError("ThermoPhase::initThermo()", "Missing species thermo data"); } @@ -622,7 +617,7 @@ bool ThermoPhase::addSpecies(shared_ptr spec) bool added = Phase::addSpecies(spec); if (added) { spec->thermo->validate(spec->name); - m_spthermo->install_STIT(m_kk-1, spec->thermo); + m_spthermo.install_STIT(m_kk-1, spec->thermo); } return added; } @@ -640,7 +635,7 @@ void ThermoPhase::modifySpecies(size_t k, shared_ptr spec) spec->name, speciesName(k), k); } spec->thermo->validate(spec->name); - m_spthermo->modifySpecies(k, spec->thermo); + m_spthermo.modifySpecies(k, spec->thermo); } void ThermoPhase::saveSpeciesData(const size_t k, const XML_Node* const data) diff --git a/src/thermo/VPStandardStateTP.cpp b/src/thermo/VPStandardStateTP.cpp index 9a38f45ef..793266d16 100644 --- a/src/thermo/VPStandardStateTP.cpp +++ b/src/thermo/VPStandardStateTP.cpp @@ -292,12 +292,12 @@ void VPStandardStateTP::createInstallPDSS(size_t k, const XML_Node& s, if (use_STITbyPDSS) { auto stit = make_shared(kPDSS); - m_spthermo->install_STIT(k, stit); + m_spthermo.install_STIT(k, stit); } else { shared_ptr stit( newSpeciesThermoInterpType(s.child("thermo"))); stit->validate(s["name"]); - m_spthermo->install_STIT(k, stit); + m_spthermo.install_STIT(k, stit); } m_PDSS_storage[k].reset(kPDSS); diff --git a/src/thermo/WaterSSTP.cpp b/src/thermo/WaterSSTP.cpp index 53de637f9..bf4f8318a 100644 --- a/src/thermo/WaterSSTP.cpp +++ b/src/thermo/WaterSSTP.cpp @@ -102,10 +102,6 @@ void WaterSSTP::initThermo() m_waterProps.reset(new WaterProps(&m_sub)); - // We have to do something with the thermo function here. - delete m_spthermo; - m_spthermo = 0; - // Set the flag to say we are ready to calculate stuff m_ready = true; }