From 2ed8552939dfd578167f70b5b08f071ab99b6cf9 Mon Sep 17 00:00:00 2001 From: Ray Speth Date: Fri, 20 Feb 2015 23:44:21 +0000 Subject: [PATCH] [Thermo] Add a version of Phase::mean_X that takes vector_fp This simplifies all internal calls to this function --- include/cantera/thermo/IdealGasPhase.h | 2 +- include/cantera/thermo/Phase.h | 3 +++ src/thermo/ConstDensityThermo.cpp | 8 +++----- src/thermo/DebyeHuckel.cpp | 8 ++++---- src/thermo/HMWSoln.cpp | 12 ++++++------ src/thermo/IdealGasPhase.cpp | 4 ++-- src/thermo/IdealMolalSoln.cpp | 10 +++++----- src/thermo/IdealSolidSolnPhase.cpp | 12 ++++-------- src/thermo/IdealSolnGasVPSS.cpp | 10 +++------- src/thermo/IonsFromNeutralVPSSTP.cpp | 10 +++++----- src/thermo/LatticePhase.cpp | 9 ++++----- src/thermo/MaskellSolidSolnPhase.cpp | 4 ++-- src/thermo/Phase.cpp | 5 +++++ src/thermo/RedlichKwongMFTP.cpp | 6 +++--- src/thermo/SurfPhase.cpp | 4 ++-- 15 files changed, 52 insertions(+), 55 deletions(-) diff --git a/include/cantera/thermo/IdealGasPhase.h b/include/cantera/thermo/IdealGasPhase.h index 8ee20b885..9ce7d2ef0 100644 --- a/include/cantera/thermo/IdealGasPhase.h +++ b/include/cantera/thermo/IdealGasPhase.h @@ -382,7 +382,7 @@ public: * \see SpeciesThermo */ virtual doublereal enthalpy_mole() const { - return GasConstant * temperature() * mean_X(&enthalpy_RT_ref()[0]); + return GasConstant * temperature() * mean_X(enthalpy_RT_ref()); } /** diff --git a/include/cantera/thermo/Phase.h b/include/cantera/thermo/Phase.h index 4fe685f4b..044f37109 100644 --- a/include/cantera/thermo/Phase.h +++ b/include/cantera/thermo/Phase.h @@ -648,6 +648,9 @@ public: //! @return mole-fraction-weighted mean of Q doublereal mean_X(const doublereal* const Q) const; + //! @copydoc Phase::mean_X(const doublereal* const Q) const + doublereal mean_X(const vector_fp& Q) const; + //! Evaluate the mass-fraction-weighted mean of an array Q. //! \f[ \sum_k Y_k Q_k \f] //! @param[in] Q Array of species property values in mass units. diff --git a/src/thermo/ConstDensityThermo.cpp b/src/thermo/ConstDensityThermo.cpp index 96422e077..8e3613fc7 100644 --- a/src/thermo/ConstDensityThermo.cpp +++ b/src/thermo/ConstDensityThermo.cpp @@ -55,19 +55,17 @@ doublereal ConstDensityThermo::enthalpy_mole() const { doublereal p0 = m_spthermo->refPressure(); return GasConstant * temperature() * - mean_X(&enthalpy_RT()[0]) - + (pressure() - p0)/molarDensity(); + mean_X(enthalpy_RT()) + (pressure() - p0)/molarDensity(); } doublereal ConstDensityThermo::entropy_mole() const { - return GasConstant * (mean_X(&entropy_R()[0]) - - sum_xlogx()); + return GasConstant * (mean_X(entropy_R()) - sum_xlogx()); } doublereal ConstDensityThermo::cp_mole() const { - return GasConstant * mean_X(&cp_R()[0]); + return GasConstant * mean_X(cp_R()); } doublereal ConstDensityThermo::cv_mole() const diff --git a/src/thermo/DebyeHuckel.cpp b/src/thermo/DebyeHuckel.cpp index 29fcab267..182bdc8b4 100644 --- a/src/thermo/DebyeHuckel.cpp +++ b/src/thermo/DebyeHuckel.cpp @@ -192,25 +192,25 @@ int DebyeHuckel::eosType() const doublereal DebyeHuckel::enthalpy_mole() const { getPartialMolarEnthalpies(DATA_PTR(m_tmpV)); - return mean_X(DATA_PTR(m_tmpV)); + return mean_X(m_tmpV); } doublereal DebyeHuckel::entropy_mole() const { getPartialMolarEntropies(DATA_PTR(m_tmpV)); - return mean_X(DATA_PTR(m_tmpV)); + return mean_X(m_tmpV); } doublereal DebyeHuckel::gibbs_mole() const { getChemPotentials(DATA_PTR(m_tmpV)); - return mean_X(DATA_PTR(m_tmpV)); + return mean_X(m_tmpV); } doublereal DebyeHuckel::cp_mole() const { getPartialMolarCp(DATA_PTR(m_tmpV)); - return mean_X(DATA_PTR(m_tmpV)); + return mean_X(m_tmpV); } doublereal DebyeHuckel::cv_mole() const diff --git a/src/thermo/HMWSoln.cpp b/src/thermo/HMWSoln.cpp index a6e5cf752..74732df03 100644 --- a/src/thermo/HMWSoln.cpp +++ b/src/thermo/HMWSoln.cpp @@ -426,19 +426,19 @@ doublereal HMWSoln::enthalpy_mole() const { getPartialMolarEnthalpies(DATA_PTR(m_tmpV)); getMoleFractions(DATA_PTR(m_pp)); - return mean_X(DATA_PTR(m_tmpV)); + return mean_X(m_tmpV); } doublereal HMWSoln::relative_enthalpy() const { getPartialMolarEnthalpies(DATA_PTR(m_tmpV)); - double hbar = mean_X(DATA_PTR(m_tmpV)); + double hbar = mean_X(m_tmpV); getEnthalpy_RT(DATA_PTR(m_gamma_tmp)); double RT = GasConstant * temperature(); for (size_t k = 0; k < m_kk; k++) { m_gamma_tmp[k] *= RT; } - double h0bar = mean_X(DATA_PTR(m_gamma_tmp)); + double h0bar = mean_X(m_gamma_tmp); return hbar - h0bar; } @@ -485,19 +485,19 @@ doublereal HMWSoln::relative_molal_enthalpy() const doublereal HMWSoln::entropy_mole() const { getPartialMolarEntropies(DATA_PTR(m_tmpV)); - return mean_X(DATA_PTR(m_tmpV)); + return mean_X(m_tmpV); } doublereal HMWSoln::gibbs_mole() const { getChemPotentials(DATA_PTR(m_tmpV)); - return mean_X(DATA_PTR(m_tmpV)); + return mean_X(m_tmpV); } doublereal HMWSoln::cp_mole() const { getPartialMolarCp(DATA_PTR(m_tmpV)); - return mean_X(DATA_PTR(m_tmpV)); + return mean_X(m_tmpV); } doublereal HMWSoln::cv_mole() const diff --git a/src/thermo/IdealGasPhase.cpp b/src/thermo/IdealGasPhase.cpp index aba465da9..43aea6a95 100644 --- a/src/thermo/IdealGasPhase.cpp +++ b/src/thermo/IdealGasPhase.cpp @@ -69,12 +69,12 @@ ThermoPhase* IdealGasPhase::duplMyselfAsThermoPhase() const doublereal IdealGasPhase::entropy_mole() const { - return GasConstant * (mean_X(&entropy_R_ref()[0]) - sum_xlogx() - std::log(pressure() / m_spthermo->refPressure())); + return GasConstant * (mean_X(entropy_R_ref()) - sum_xlogx() - std::log(pressure() / m_spthermo->refPressure())); } doublereal IdealGasPhase::cp_mole() const { - return GasConstant * mean_X(&cp_R_ref()[0]); + return GasConstant * mean_X(cp_R_ref()); } doublereal IdealGasPhase::cv_mole() const diff --git a/src/thermo/IdealMolalSoln.cpp b/src/thermo/IdealMolalSoln.cpp index d6d6680ec..b2a465e28 100644 --- a/src/thermo/IdealMolalSoln.cpp +++ b/src/thermo/IdealMolalSoln.cpp @@ -139,31 +139,31 @@ doublereal IdealMolalSoln::enthalpy_mole() const { getPartialMolarEnthalpies(DATA_PTR(m_tmpV)); getMoleFractions(DATA_PTR(m_pp)); - return mean_X(DATA_PTR(m_tmpV)); + return mean_X(m_tmpV); } doublereal IdealMolalSoln::intEnergy_mole() const { getPartialMolarEnthalpies(DATA_PTR(m_tmpV)); - return mean_X(DATA_PTR(m_tmpV)); + return mean_X(m_tmpV); } doublereal IdealMolalSoln::entropy_mole() const { getPartialMolarEntropies(DATA_PTR(m_tmpV)); - return mean_X(DATA_PTR(m_tmpV)); + return mean_X(m_tmpV); } doublereal IdealMolalSoln::gibbs_mole() const { getChemPotentials(DATA_PTR(m_tmpV)); - return mean_X(DATA_PTR(m_tmpV)); + return mean_X(m_tmpV); } doublereal IdealMolalSoln::cp_mole() const { getPartialMolarCp(DATA_PTR(m_tmpV)); - return mean_X(DATA_PTR(m_tmpV)); + return mean_X(m_tmpV); } doublereal IdealMolalSoln::cv_mole() const diff --git a/src/thermo/IdealSolidSolnPhase.cpp b/src/thermo/IdealSolidSolnPhase.cpp index a2f2e6415..cd00ef578 100644 --- a/src/thermo/IdealSolidSolnPhase.cpp +++ b/src/thermo/IdealSolidSolnPhase.cpp @@ -114,27 +114,23 @@ int IdealSolidSolnPhase::eosType() const doublereal IdealSolidSolnPhase::enthalpy_mole() const { - const double* eptr = &(enthalpy_RT_ref()[0]); - doublereal htp = (GasConstant * temperature() * mean_X(eptr)); + doublereal htp = GasConstant * temperature() * mean_X(enthalpy_RT_ref()); return htp + (pressure() - m_Pref)/molarDensity(); } doublereal IdealSolidSolnPhase::entropy_mole() const { - const double* dptr = DATA_PTR(entropy_R_ref()); - return GasConstant * (mean_X(dptr) - sum_xlogx()); + return GasConstant * (mean_X(entropy_R_ref()) - sum_xlogx()); } doublereal IdealSolidSolnPhase::gibbs_mole() const { - const double* dptr = DATA_PTR(gibbs_RT_ref()); - return GasConstant * temperature() * (mean_X(dptr) + sum_xlogx()); + return GasConstant * temperature() * (mean_X(gibbs_RT_ref()) + sum_xlogx()); } doublereal IdealSolidSolnPhase::cp_mole() const { - const double* dptr = DATA_PTR(cp_R_ref()); - return GasConstant * mean_X(dptr); + return GasConstant * mean_X(cp_R_ref()); } /******************************************************************** diff --git a/src/thermo/IdealSolnGasVPSS.cpp b/src/thermo/IdealSolnGasVPSS.cpp index e8b2784ed..3633df644 100644 --- a/src/thermo/IdealSolnGasVPSS.cpp +++ b/src/thermo/IdealSolnGasVPSS.cpp @@ -89,24 +89,20 @@ int IdealSolnGasVPSS::eosType() const doublereal IdealSolnGasVPSS::enthalpy_mole() const { updateStandardStateThermo(); - const vector_fp& enth_RT = m_VPSS_ptr->enthalpy_RT(); - return (GasConstant * temperature() * - mean_X(DATA_PTR(enth_RT))); + return GasConstant * temperature() * mean_X(m_VPSS_ptr->enthalpy_RT()); } doublereal IdealSolnGasVPSS::entropy_mole() const { updateStandardStateThermo(); - const vector_fp& entrop_R = m_VPSS_ptr->entropy_R(); - return GasConstant * (mean_X(DATA_PTR(entrop_R)) - sum_xlogx()); + return GasConstant * (mean_X(m_VPSS_ptr->entropy_R()) - sum_xlogx()); } doublereal IdealSolnGasVPSS::cp_mole() const { updateStandardStateThermo(); - const vector_fp& cp_R = m_VPSS_ptr->cp_R(); - return GasConstant * (mean_X(DATA_PTR(cp_R))); + return GasConstant * mean_X(m_VPSS_ptr->cp_R()); } doublereal IdealSolnGasVPSS::cv_mole() const diff --git a/src/thermo/IonsFromNeutralVPSSTP.cpp b/src/thermo/IonsFromNeutralVPSSTP.cpp index c55ac8518..af9bb2866 100644 --- a/src/thermo/IonsFromNeutralVPSSTP.cpp +++ b/src/thermo/IonsFromNeutralVPSSTP.cpp @@ -263,32 +263,32 @@ int IonsFromNeutralVPSSTP::eosType() const doublereal IonsFromNeutralVPSSTP::enthalpy_mole() const { getPartialMolarEnthalpies(DATA_PTR(m_pp)); - return mean_X(DATA_PTR(m_pp)); + return mean_X(m_pp); } doublereal IonsFromNeutralVPSSTP::entropy_mole() const { getPartialMolarEntropies(DATA_PTR(m_pp)); - return mean_X(DATA_PTR(m_pp)); + return mean_X(m_pp); } doublereal IonsFromNeutralVPSSTP::gibbs_mole() const { getChemPotentials(DATA_PTR(m_pp)); - return mean_X(DATA_PTR(m_pp)); + return mean_X(m_pp); } doublereal IonsFromNeutralVPSSTP::cp_mole() const { getPartialMolarCp(DATA_PTR(m_pp)); - return mean_X(DATA_PTR(m_pp)); + return mean_X(m_pp); } doublereal IonsFromNeutralVPSSTP::cv_mole() const { // Need to revisit this, as it is wrong getPartialMolarCp(DATA_PTR(m_pp)); - return mean_X(DATA_PTR(m_pp)); + return mean_X(m_pp); } /* diff --git a/src/thermo/LatticePhase.cpp b/src/thermo/LatticePhase.cpp index b7f8ac4a9..7a857369b 100644 --- a/src/thermo/LatticePhase.cpp +++ b/src/thermo/LatticePhase.cpp @@ -67,19 +67,18 @@ ThermoPhase* LatticePhase::duplMyselfAsThermoPhase() const doublereal LatticePhase::enthalpy_mole() const { - return GasConstant * temperature() * - mean_X(&enthalpy_RT_ref()[0]) - + (pressure() - m_Pref)/molarDensity(); + return GasConstant * temperature() * mean_X(enthalpy_RT_ref()) + + (pressure() - m_Pref)/molarDensity(); } doublereal LatticePhase::entropy_mole() const { - return GasConstant * (mean_X(&entropy_R_ref()[0]) - sum_xlogx()); + return GasConstant * (mean_X(entropy_R_ref()) - sum_xlogx()); } doublereal LatticePhase::cp_mole() const { - return GasConstant * mean_X(&cp_R_ref()[0]); + return GasConstant * mean_X(cp_R_ref()); } doublereal LatticePhase::cv_mole() const diff --git a/src/thermo/MaskellSolidSolnPhase.cpp b/src/thermo/MaskellSolidSolnPhase.cpp index 9d13a8154..7d1760ae0 100644 --- a/src/thermo/MaskellSolidSolnPhase.cpp +++ b/src/thermo/MaskellSolidSolnPhase.cpp @@ -74,7 +74,7 @@ void MaskellSolidSolnPhase::getActivityConcentrations(doublereal* c) const doublereal MaskellSolidSolnPhase::enthalpy_mole() const { _updateThermo(); - const doublereal h0 = GasConstant * temperature() * mean_X(&m_h0_RT[0]); + const doublereal h0 = GasConstant * temperature() * mean_X(m_h0_RT); const doublereal r = moleFraction(product_species_index); const doublereal fmval = fm(r); return h0 + r * fmval * h_mixing; @@ -88,7 +88,7 @@ doublereal xlogx(doublereal x) doublereal MaskellSolidSolnPhase::entropy_mole() const { _updateThermo(); - const doublereal s0 = GasConstant * mean_X(&m_s0_R[0]); + const doublereal s0 = GasConstant * mean_X(m_s0_R); const doublereal r = moleFraction(product_species_index); const doublereal fmval = fm(r); const doublereal rfm = r * fmval; diff --git a/src/thermo/Phase.cpp b/src/thermo/Phase.cpp index 3233dc30b..d1b0dfd37 100644 --- a/src/thermo/Phase.cpp +++ b/src/thermo/Phase.cpp @@ -687,6 +687,11 @@ doublereal Phase::mean_X(const doublereal* const Q) const return m_mmw*std::inner_product(m_ym.begin(), m_ym.end(), Q, 0.0); } +doublereal Phase::mean_X(const vector_fp& Q) const +{ + return m_mmw*std::inner_product(m_ym.begin(), m_ym.end(), Q.begin(), 0.0); +} + doublereal Phase::mean_Y(const doublereal* const Q) const { return dot(m_y.begin(), m_y.end(), Q); diff --git a/src/thermo/RedlichKwongMFTP.cpp b/src/thermo/RedlichKwongMFTP.cpp index 56515d599..f6b93e06a 100644 --- a/src/thermo/RedlichKwongMFTP.cpp +++ b/src/thermo/RedlichKwongMFTP.cpp @@ -179,7 +179,7 @@ int RedlichKwongMFTP::eosType() const doublereal RedlichKwongMFTP::enthalpy_mole() const { _updateReferenceStateThermo(); - doublereal h_ideal = _RT() * mean_X(DATA_PTR(m_h0_RT)); + doublereal h_ideal = _RT() * mean_X(m_h0_RT); doublereal h_nonideal = hresid(); return h_ideal + h_nonideal; } @@ -187,7 +187,7 @@ doublereal RedlichKwongMFTP::enthalpy_mole() const doublereal RedlichKwongMFTP::entropy_mole() const { _updateReferenceStateThermo(); - doublereal sr_ideal = GasConstant * (mean_X(DATA_PTR(m_s0_R)) + doublereal sr_ideal = GasConstant * (mean_X(m_s0_R) - sum_xlogx() - std::log(pressure()/m_spthermo->refPressure())); doublereal sr_nonideal = sresid(); return sr_ideal + sr_nonideal; @@ -201,7 +201,7 @@ doublereal RedlichKwongMFTP::cp_mole() const doublereal mv = molarVolume(); doublereal vpb = mv + m_b_current; pressureDerivatives(); - doublereal cpref = GasConstant * mean_X(DATA_PTR(m_cp0_R)); + doublereal cpref = GasConstant * mean_X(m_cp0_R); doublereal dadt = da_dt(); doublereal fac = TKelvin * dadt - 3.0 * m_a_current / 2.0; doublereal dHdT_V = (cpref + mv * dpdT_ - GasConstant - 1.0 / (2.0 * m_b_current * TKelvin * sqt) * log(vpb/mv) * fac diff --git a/src/thermo/SurfPhase.cpp b/src/thermo/SurfPhase.cpp index 551481f67..a69b4adfc 100644 --- a/src/thermo/SurfPhase.cpp +++ b/src/thermo/SurfPhase.cpp @@ -102,7 +102,7 @@ doublereal SurfPhase::enthalpy_mole() const return 0.0; } _updateThermo(); - return mean_X(DATA_PTR(m_h0)); + return mean_X(m_h0); } doublereal SurfPhase::intEnergy_mole() const @@ -124,7 +124,7 @@ doublereal SurfPhase::entropy_mole() const doublereal SurfPhase::cp_mole() const { _updateThermo(); - return mean_X(&m_cp0[0]); + return mean_X(m_cp0); } doublereal SurfPhase::cv_mole() const