From a838d6dce2554c0b7a1539768301af967835e9d2 Mon Sep 17 00:00:00 2001 From: Harry Moffat Date: Wed, 10 Dec 2008 16:42:48 +0000 Subject: [PATCH] Changed the parameter list to a const on setParameters(). Moved remaining definitions from StoichSubstance.h to StoichSubstance.cpp --- Cantera/src/thermo/ConstDensityThermo.h | 2 +- Cantera/src/thermo/DebyeHuckel.cpp | 2 +- Cantera/src/thermo/DebyeHuckel.h | 2 +- Cantera/src/thermo/HMWSoln.cpp | 2 +- Cantera/src/thermo/HMWSoln.h | 2 +- Cantera/src/thermo/IdealMolalSoln.cpp | 2 +- Cantera/src/thermo/IdealMolalSoln.h | 2 +- Cantera/src/thermo/LatticePhase.cpp | 2 +- Cantera/src/thermo/LatticePhase.h | 2 +- Cantera/src/thermo/SingleSpeciesTP.h | 2 +- Cantera/src/thermo/StoichSubstance.cpp | 44 ++++++++++++++++++- Cantera/src/thermo/StoichSubstance.h | 50 ++++++---------------- Cantera/src/thermo/StoichSubstanceSSTP.cpp | 22 +++++----- Cantera/src/thermo/StoichSubstanceSSTP.h | 6 +-- Cantera/src/thermo/SurfPhase.cpp | 2 +- Cantera/src/thermo/SurfPhase.h | 2 +- Cantera/src/thermo/ThermoPhase.h | 2 +- 17 files changed, 81 insertions(+), 67 deletions(-) diff --git a/Cantera/src/thermo/ConstDensityThermo.h b/Cantera/src/thermo/ConstDensityThermo.h index 7384a367a..f462516c5 100755 --- a/Cantera/src/thermo/ConstDensityThermo.h +++ b/Cantera/src/thermo/ConstDensityThermo.h @@ -371,7 +371,7 @@ namespace Cantera { * @param n number of parameters * @param c array of \a n coefficients */ - virtual void setParameters(int n, doublereal* c) { + virtual void setParameters(int n, doublereal* const c) { setDensity(c[0]); } diff --git a/Cantera/src/thermo/DebyeHuckel.cpp b/Cantera/src/thermo/DebyeHuckel.cpp index 6742ecc16..20c4292d3 100644 --- a/Cantera/src/thermo/DebyeHuckel.cpp +++ b/Cantera/src/thermo/DebyeHuckel.cpp @@ -1618,7 +1618,7 @@ namespace Cantera { * @param c array of \i n coefficients * */ - void DebyeHuckel::setParameters(int n, doublereal* c) { + void DebyeHuckel::setParameters(int n, doublereal* const c) { } void DebyeHuckel::getParameters(int &n, doublereal * const c) const { diff --git a/Cantera/src/thermo/DebyeHuckel.h b/Cantera/src/thermo/DebyeHuckel.h index 12f0980d2..7a411f182 100644 --- a/Cantera/src/thermo/DebyeHuckel.h +++ b/Cantera/src/thermo/DebyeHuckel.h @@ -1163,7 +1163,7 @@ namespace Cantera { * @param n number of parameters * @param c array of \a n coefficients */ - virtual void setParameters(int n, doublereal* c); + virtual void setParameters(int n, doublereal* const c); //! Get the equation of state parameters in a vector /*! diff --git a/Cantera/src/thermo/HMWSoln.cpp b/Cantera/src/thermo/HMWSoln.cpp index bc2095efe..d5a57c085 100644 --- a/Cantera/src/thermo/HMWSoln.cpp +++ b/Cantera/src/thermo/HMWSoln.cpp @@ -1228,7 +1228,7 @@ namespace Cantera { * @param c array of \i n coefficients * */ - void HMWSoln::setParameters(int n, doublereal* c) { + void HMWSoln::setParameters(int n, doublereal* const c) { } void HMWSoln::getParameters(int &n, doublereal * const c) const { diff --git a/Cantera/src/thermo/HMWSoln.h b/Cantera/src/thermo/HMWSoln.h index fec76b5fe..ff0c918ec 100644 --- a/Cantera/src/thermo/HMWSoln.h +++ b/Cantera/src/thermo/HMWSoln.h @@ -1857,7 +1857,7 @@ namespace Cantera { * @param n number of parameters * @param c array of \a n coefficients */ - virtual void setParameters(int n, doublereal* c); + virtual void setParameters(int n, doublereal* const c); //! Get the equation of state parameters in a vector /*! diff --git a/Cantera/src/thermo/IdealMolalSoln.cpp b/Cantera/src/thermo/IdealMolalSoln.cpp index bfea6a01b..41948a135 100644 --- a/Cantera/src/thermo/IdealMolalSoln.cpp +++ b/Cantera/src/thermo/IdealMolalSoln.cpp @@ -1107,7 +1107,7 @@ namespace Cantera { * @param c array of \i n coefficients * */ - void IdealMolalSoln::setParameters(int n, doublereal* c) { + void IdealMolalSoln::setParameters(int n, doublereal* const c) { } void IdealMolalSoln::getParameters(int &n, doublereal * const c) const { diff --git a/Cantera/src/thermo/IdealMolalSoln.h b/Cantera/src/thermo/IdealMolalSoln.h index e4cce7fbf..b423158ba 100644 --- a/Cantera/src/thermo/IdealMolalSoln.h +++ b/Cantera/src/thermo/IdealMolalSoln.h @@ -698,7 +698,7 @@ namespace Cantera { * @param c array of n coefficients * */ - virtual void setParameters(int n, doublereal* c); + virtual void setParameters(int n, doublereal* const c); /*! * @internal diff --git a/Cantera/src/thermo/LatticePhase.cpp b/Cantera/src/thermo/LatticePhase.cpp index fc5158138..974d2c23c 100644 --- a/Cantera/src/thermo/LatticePhase.cpp +++ b/Cantera/src/thermo/LatticePhase.cpp @@ -235,7 +235,7 @@ namespace Cantera { } } - void LatticePhase::setParameters(int n, doublereal* c) { + void LatticePhase::setParameters(int n, doublereal* const c) { m_molar_density = c[0]; setMolarDensity(m_molar_density); } diff --git a/Cantera/src/thermo/LatticePhase.h b/Cantera/src/thermo/LatticePhase.h index b44372718..c6d2b890d 100644 --- a/Cantera/src/thermo/LatticePhase.h +++ b/Cantera/src/thermo/LatticePhase.h @@ -705,7 +705,7 @@ namespace Cantera { * @param c array of \a n coefficients * c[0] = The bulk lattice density (kmol m-3) */ - virtual void setParameters(int n, doublereal* c); + virtual void setParameters(int n, doublereal* const c); //! Get the equation of state parameters in a vector /*! diff --git a/Cantera/src/thermo/SingleSpeciesTP.h b/Cantera/src/thermo/SingleSpeciesTP.h index 8fa5436fe..3eb58c95b 100644 --- a/Cantera/src/thermo/SingleSpeciesTP.h +++ b/Cantera/src/thermo/SingleSpeciesTP.h @@ -624,7 +624,7 @@ namespace Cantera { * @param c array of n coefficients * */ - virtual void setParameters(int n, doublereal* c) {} + virtual void setParameters(int n, doublereal* const c) {} virtual void getParameters(int &n, doublereal * const c) const {} diff --git a/Cantera/src/thermo/StoichSubstance.cpp b/Cantera/src/thermo/StoichSubstance.cpp index 41d69a420..339f935d5 100644 --- a/Cantera/src/thermo/StoichSubstance.cpp +++ b/Cantera/src/thermo/StoichSubstance.cpp @@ -96,6 +96,35 @@ namespace Cantera { StoichSubstance::~StoichSubstance() { } + doublereal StoichSubstance::enthalpy_mole() const { + double hh = intEnergy_mole() + m_press / molarDensity(); + return hh; + } + + doublereal StoichSubstance::intEnergy_mole() const { + _updateThermo(); + return GasConstant * temperature() * m_h0_RT[0] + - m_p0 / molarDensity(); + } + + doublereal StoichSubstance::entropy_mole() const { + _updateThermo(); + return GasConstant * m_s0_R[0]; + } + + doublereal StoichSubstance::gibbs_mole() const { + return enthalpy_mole() - temperature() * entropy_mole(); + } + + doublereal StoichSubstance::cp_mole() const { + _updateThermo(); + return GasConstant * m_cp0_R[0]; + } + + doublereal StoichSubstance::cv_mole() const { + return cp_mole(); + } + void StoichSubstance::initThermo() { m_kk = nSpecies(); if (m_kk > 1) { @@ -123,7 +152,6 @@ namespace Cantera { setState_TP(tnow, m_p0); } - void StoichSubstance::_updateThermo() const { doublereal tnow = temperature(); if (m_tlast != tnow) { @@ -153,6 +181,10 @@ namespace Cantera { return 0.0; } + void StoichSubstance::getStandardChemPotentials(doublereal* mu0) const { + mu0[0] = gibbs_mole(); + } + void StoichSubstance:: getUnitsStandardConc(double *uA, int k, int sizeUA) const { for (int i = 0; i < sizeUA; i++) { @@ -164,6 +196,14 @@ namespace Cantera { * */ + void StoichSubstance::getChemPotentials_RT(doublereal* mu) const { + mu[0] = gibbs_mole() / (GasConstant * temperature()); + } + + void StoichSubstance::getChemPotentials(doublereal* mu) const { + mu[0] = gibbs_mole(); + } + void StoichSubstance::getElectrochemPotentials(doublereal* mu) const { getChemPotentials(mu); } @@ -236,7 +276,7 @@ namespace Cantera { * */ - void StoichSubstance::setParameters(int n, double * c) { + void StoichSubstance::setParameters(int n, double * const c) { double rho = c[0]; setDensity(rho); } diff --git a/Cantera/src/thermo/StoichSubstance.h b/Cantera/src/thermo/StoichSubstance.h index a0181aeb6..b8d78065b 100644 --- a/Cantera/src/thermo/StoichSubstance.h +++ b/Cantera/src/thermo/StoichSubstance.h @@ -1,7 +1,5 @@ /** - * * @file StoichSubstance.h - * * This file contains the class declarations for the StoichSubstance * ThermoPhase class. */ @@ -99,10 +97,7 @@ namespace Cantera { * is \f[ \hat h(T, P) = \hat u(T) + P \hat v \f], where the * molar specific volume is constant. */ - virtual doublereal enthalpy_mole() const { - double hh = intEnergy_mole() + m_press / molarDensity(); - return hh; - } + virtual doublereal enthalpy_mole() const; /** * Molar internal energy. J/kmol. For an incompressible, @@ -112,48 +107,33 @@ namespace Cantera { * term \f$ P_0 \hat v\f$ is subtracted from the specified molar * enthalpy to compute the molar internal energy. */ - virtual doublereal intEnergy_mole() const { - _updateThermo(); - return GasConstant * temperature() * m_h0_RT[0] - - m_p0 / molarDensity(); - } + virtual doublereal intEnergy_mole() const; /** * Molar entropy. Units: J/kmol/K. For an incompressible, * stoichiometric substance, the molar entropy depends only on * the temperature. */ - virtual doublereal entropy_mole() const { - _updateThermo(); - return GasConstant * m_s0_R[0]; - } + virtual doublereal entropy_mole() const; /** * Molar gibbs Function. Units: J/kmol. This is determined * from the molar enthalpy and entropy functions. */ - virtual doublereal gibbs_mole() const { - return enthalpy_mole() - temperature() * entropy_mole(); - } - + virtual doublereal gibbs_mole() const; /** * Molar heat capacity at constant pressure. Units: J/kmol/K. * For an incompressible substance, \f$ \hat c_p = \hat c_v\f$. */ - virtual doublereal cp_mole() const { - _updateThermo(); - return GasConstant * m_cp0_R[0]; - } + virtual doublereal cp_mole() const; /** * Molar heat capacity at constant volume. Units: J/kmol/K. * For an incompressible substance, \f$ \hat c_p = \hat c_v\f$. */ - virtual doublereal cv_mole() const { - return cp_mole(); - } + virtual doublereal cv_mole() const; //@} @@ -220,9 +200,7 @@ namespace Cantera { * standard chemical potential and the chemical potential * are both equal to the molar Gibbs function. */ - virtual void getStandardChemPotentials(doublereal* mu0) const { - mu0[0] = gibbs_mole(); - } + virtual void getStandardChemPotentials(doublereal* mu0) const; /** * Returns the units of the standard and generalized @@ -246,7 +224,7 @@ namespace Cantera { //@} - /// @name Partial Molar Properties of the Solution ---------------------------------- + /// @name Partial Molar Properties of the Solution ---------------------------- //@{ @@ -254,18 +232,14 @@ namespace Cantera { * Get the array of non-dimensional chemical potentials * \f$ \mu_k / \hat R T \f$. */ - virtual void getChemPotentials_RT(doublereal* mu) const { - mu[0] = gibbs_mole() / (GasConstant * temperature()); - } + virtual void getChemPotentials_RT(doublereal* mu) const; /** * For a stoichiometric substance, there is only one species. * This method returns the molar gibbs function in the * first element of array \c mu. */ - virtual void getChemPotentials(doublereal* mu) const { - mu[0] = gibbs_mole(); - } + virtual void getChemPotentials(doublereal* mu) const; /** * Get the species electrochemical potentials. Units: J/kmol. @@ -295,7 +269,7 @@ namespace Cantera { //@} - /// @name Properties of the Standard State of the Species in the Solution ------------------------------------- + /// @name Properties of the Standard State of the Species in the Solution ----- //@{ /** * Get the nondimensional Enthalpy functions for the species @@ -394,7 +368,7 @@ namespace Cantera { virtual void initThermo(); - virtual void setParameters(int n, double *c); + virtual void setParameters(int n, double * const c); virtual void getParameters(int &n, double * const c) const; diff --git a/Cantera/src/thermo/StoichSubstanceSSTP.cpp b/Cantera/src/thermo/StoichSubstanceSSTP.cpp index 89d30123c..e855b295e 100644 --- a/Cantera/src/thermo/StoichSubstanceSSTP.cpp +++ b/Cantera/src/thermo/StoichSubstanceSSTP.cpp @@ -254,7 +254,7 @@ namespace Cantera { * uA[5] = time units - default = 0 */ void StoichSubstanceSSTP:: - getUnitsStandardConc(double *uA, int k, int sizeUA) const { + getUnitsStandardConc(doublereal *uA, int k, int sizeUA) const { for (int i = 0; i < 6; i++) { uA[i] = 0; } @@ -298,8 +298,8 @@ namespace Cantera { */ void StoichSubstanceSSTP::getEnthalpy_RT(doublereal* hrt) const { getEnthalpy_RT_ref(hrt); - double RT = GasConstant * temperature(); - double presCorrect = (m_press - m_p0) / molarDensity(); + doublereal RT = GasConstant * temperature(); + doublereal presCorrect = (m_press - m_p0) / molarDensity(); hrt[0] += presCorrect / RT; } @@ -342,8 +342,8 @@ namespace Cantera { */ void StoichSubstanceSSTP::getIntEnergy_RT(doublereal* urt) const { _updateThermo(); - double RT = GasConstant * temperature(); - double PV = m_p0 / molarDensity(); + doublereal RT = GasConstant * temperature(); + doublereal PV = m_p0 / molarDensity(); urt[0] = m_h0_RT[0] - PV / RT; } @@ -365,8 +365,8 @@ namespace Cantera { */ void StoichSubstanceSSTP::getIntEnergy_RT_ref(doublereal* urt) const { _updateThermo(); - double RT = GasConstant * temperature(); - double PV = m_p0 / molarDensity(); + doublereal RT = GasConstant * temperature(); + doublereal PV = m_p0 / molarDensity(); urt[0] = m_h0_RT[0] - PV / RT; } @@ -431,8 +431,8 @@ namespace Cantera { * by this model. * C[0] = density of phase [ kg/m3 ] */ - void StoichSubstanceSSTP::setParameters(int n, double * c) { - double rho = c[0]; + void StoichSubstanceSSTP::setParameters(int n, doublereal * const c) { + doublereal rho = c[0]; setDensity(rho); } @@ -444,8 +444,8 @@ namespace Cantera { * n = 1 * C[0] = density of phase [ kg/m3 ] */ - void StoichSubstanceSSTP::getParameters(int &n, double * const c) const { - double rho = density(); + void StoichSubstanceSSTP::getParameters(int &n, doublereal * const c) const { + doublereal rho = density(); n = 1; c[0] = rho; } diff --git a/Cantera/src/thermo/StoichSubstanceSSTP.h b/Cantera/src/thermo/StoichSubstanceSSTP.h index 0feeaa6a5..71cb6d537 100644 --- a/Cantera/src/thermo/StoichSubstanceSSTP.h +++ b/Cantera/src/thermo/StoichSubstanceSSTP.h @@ -369,7 +369,7 @@ namespace Cantera { * @param sizeUA output int containing the size of the vector. * Currently, this is equal to 6. */ - virtual void getUnitsStandardConc(double *uA, int k = 0, + virtual void getUnitsStandardConc(doublereal *uA, int k = 0, int sizeUA = 6) const; //@} @@ -479,7 +479,7 @@ namespace Cantera { * @param c array of \a n coefficients * c[0] = density of phase [ kg/m3 ] */ - virtual void setParameters(int n, double *c); + virtual void setParameters(int n, doublereal * const c); //! Get the equation of state parameters in a vector /*! @@ -492,7 +492,7 @@ namespace Cantera { * - n = 1 * - c[0] = density of phase [ kg/m3 ] */ - virtual void getParameters(int &n, double * const c) const; + virtual void getParameters(int &n, doublereal * const c) const; //! Set equation of state parameter values from XML entries. /*! diff --git a/Cantera/src/thermo/SurfPhase.cpp b/Cantera/src/thermo/SurfPhase.cpp index 6a80e2a63..de3b9e0c2 100644 --- a/Cantera/src/thermo/SurfPhase.cpp +++ b/Cantera/src/thermo/SurfPhase.cpp @@ -250,7 +250,7 @@ namespace Cantera { /// The only parameter that can be set is the site density. void SurfPhase:: - setParameters(int n, doublereal* c) { + setParameters(int n, doublereal* const c) { if (n != 1) { throw CanteraError("SurfPhase::setParameters", "Bad value for number of parameter"); diff --git a/Cantera/src/thermo/SurfPhase.h b/Cantera/src/thermo/SurfPhase.h index ce81d7547..4f90f431b 100644 --- a/Cantera/src/thermo/SurfPhase.h +++ b/Cantera/src/thermo/SurfPhase.h @@ -363,7 +363,7 @@ namespace Cantera { * @param c array of \a n coefficients * c[0] = The site density (kmol m-2) */ - virtual void setParameters(int n, doublereal* c); + virtual void setParameters(int n, doublereal* const c); //! Set the Equation-of-State parameters by reading an XML Node Input /*! diff --git a/Cantera/src/thermo/ThermoPhase.h b/Cantera/src/thermo/ThermoPhase.h index c12f6d2bf..c868652a5 100755 --- a/Cantera/src/thermo/ThermoPhase.h +++ b/Cantera/src/thermo/ThermoPhase.h @@ -1924,7 +1924,7 @@ namespace Cantera { * @param n number of parameters * @param c array of \a n coefficients */ - virtual void setParameters(int n, doublereal* c) {} + virtual void setParameters(int n, doublereal* const c) {} //! Get the equation of state parameters in a vector