From 42e2dd0c0b57b29c7d1cb2bed4d3de4c7acd59bf Mon Sep 17 00:00:00 2001 From: Christopher Lueth Date: Wed, 26 May 2010 23:15:29 +0000 Subject: [PATCH] added enthalpy_mole(), entropy_mole().... capabilities to MargulesVPSSTP --- Cantera/src/thermo/GibbsExcessVPSSTP.cpp | 2 + Cantera/src/thermo/GibbsExcessVPSSTP.h | 5 ++ Cantera/src/thermo/MargulesVPSSTP.cpp | 87 ++++++++++++++++++++- Cantera/src/thermo/MargulesVPSSTP.h | 48 +++++++++++- Cantera/src/thermo/SpeciesThermoFactory.cpp | 2 +- Cantera/src/thermo/ThermoPhase.h | 4 +- 6 files changed, 143 insertions(+), 5 deletions(-) diff --git a/Cantera/src/thermo/GibbsExcessVPSSTP.cpp b/Cantera/src/thermo/GibbsExcessVPSSTP.cpp index d0b14221f..fe665941a 100644 --- a/Cantera/src/thermo/GibbsExcessVPSSTP.cpp +++ b/Cantera/src/thermo/GibbsExcessVPSSTP.cpp @@ -66,6 +66,7 @@ namespace Cantera { moleFractions_ = b.moleFractions_; lnActCoeff_Scaled_ = b.lnActCoeff_Scaled_; dlnActCoeffdT_Scaled_ = b.dlnActCoeffdT_Scaled_; + d2lnActCoeffdT2_Scaled_ = b.d2lnActCoeffdT2_Scaled_; dlnActCoeffdlnX_Scaled_ = b.dlnActCoeffdlnX_Scaled_; dlnActCoeffdlnN_Scaled_ = b.dlnActCoeffdlnN_Scaled_; m_pp = b.m_pp; @@ -324,6 +325,7 @@ namespace Cantera { moleFractions_.resize(m_kk); lnActCoeff_Scaled_.resize(m_kk); dlnActCoeffdT_Scaled_.resize(m_kk); + d2lnActCoeffdT2_Scaled_.resize(m_kk); dlnActCoeffdlnX_Scaled_.resize(m_kk); dlnActCoeffdlnN_Scaled_.resize(m_kk); m_pp.resize(m_kk); diff --git a/Cantera/src/thermo/GibbsExcessVPSSTP.h b/Cantera/src/thermo/GibbsExcessVPSSTP.h index a100e5f45..702e1f3b5 100644 --- a/Cantera/src/thermo/GibbsExcessVPSSTP.h +++ b/Cantera/src/thermo/GibbsExcessVPSSTP.h @@ -578,6 +578,11 @@ namespace Cantera { //! log of theactivity coefficients of the species mutable std::vector dlnActCoeffdT_Scaled_; + //! Storage for the current derivative values of the + //! gradients with respect to temperature of the + //! log of theactivity coefficients of the species + mutable std::vector d2lnActCoeffdT2_Scaled_; + //! Storage for the current derivative values of the //! gradients with respect to logarithm of the mole fraction of the //! log of theactivity coefficients of the species diff --git a/Cantera/src/thermo/MargulesVPSSTP.cpp b/Cantera/src/thermo/MargulesVPSSTP.cpp index 039f70460..216e6a273 100644 --- a/Cantera/src/thermo/MargulesVPSSTP.cpp +++ b/Cantera/src/thermo/MargulesVPSSTP.cpp @@ -408,6 +408,43 @@ namespace Cantera { } } + /// Molar enthalpy. Units: J/kmol. + doublereal MargulesVPSSTP::enthalpy_mole() const { + int kk = nSpecies(); + double hbar[kk], h = 0; + getPartialMolarEnthalpies(hbar); + for (int i = 0; i < kk; i++){ + h += moleFractions_[i]*hbar[i]; + } + return h; + } + + /// Molar entropy. Units: J/kmol. + doublereal MargulesVPSSTP::entropy_mole() const { + int kk = nSpecies(); + double sbar[kk], s = 0; + getPartialMolarEntropies(sbar); + for (int i = 0; i < kk; i++){ + s += moleFractions_[i]*sbar[i]; + } + return s; + } + + /// Molar heat capacity at constant pressure. Units: J/kmol/K. + doublereal MargulesVPSSTP::cp_mole() const { + int kk = nSpecies(); + double cpbar[kk], cp = 0; + getPartialMolarCp(cpbar); + for (int i = 0; i < kk; i++){ + cp += moleFractions_[i]*cpbar[i]; + } + return cp; + } + + /// Molar heat capacity at constant volume. Units: J/kmol/K. + doublereal MargulesVPSSTP::cv_mole() const { + return cp_mole() - GasConstant; + } // Returns an array of partial molar enthalpies for the species // in the mixture. @@ -448,6 +485,44 @@ namespace Cantera { } } + // Returns an array of partial molar heat capacities for the species + // in the mixture. + /* + * Units (J/kmol) + * + * For this phase, the partial molar enthalpies are equal to the + * standard state enthalpies modified by the derivative of the + * activity coefficent wrt temperature + * + * \f[ + * ??????????? \bar s_k(T,P) = s^o_k(T,P) - R T^2 \frac{d \ln(\gamma_k)}{dT} + * \f] + * + */ + void MargulesVPSSTP::getPartialMolarCp(doublereal* cpbar) const { + /* + * Get the nondimensional standard state entropies + */ + getCp_R(cpbar); + double T = temperature(); + /* + * Update the activity coefficients, This also update the + * internally storred molalities. + */ + s_update_lnActCoeff(); + s_update_dlnActCoeff_dT(); + + for (int k = 0; k < m_kk; k++) { + cpbar[k] -= 2 * T * dlnActCoeffdT_Scaled_[k] + T * T * d2lnActCoeffdT2_Scaled_[k]; + } + /* + * dimensionalize it. + */ + for (int k = 0; k < m_kk; k++) { + cpbar[k] *= GasConstant; + } + } + // Returns an array of partial molar entropies for the species // in the mixture. /* @@ -733,6 +808,7 @@ namespace Cantera { double RTT = GasConstant*T*T; fvo_zero_dbl_1(dlnActCoeffdT_Scaled_, m_kk); + fvo_zero_dbl_1(d2lnActCoeffdT2_Scaled_, m_kk); for ( iK = 0; iK < m_kk; iK++ ){ @@ -755,7 +831,9 @@ namespace Cantera { g0 = -m_HE_b_ij[i] / RTT; g1 = -m_HE_c_ij[i] / RTT; - dlnActCoeffdT_Scaled_[iK] += (delAK*XB+XA*delBK-XA*XB)*(g0+g1*XB)+XA*XB*(delBK-XB)*g1; + double temp = (delAK*XB+XA*delBK-XA*XB)*(g0+g1*XB)+XA*XB*(delBK-XB)*g1; + dlnActCoeffdT_Scaled_[iK] += temp; + d2lnActCoeffdT2_Scaled_[iK] -= 2*temp/T; } } } @@ -793,6 +871,13 @@ namespace Cantera { } } + void MargulesVPSSTP::getd2lnActCoeffdT2(doublereal *d2lnActCoeffdT2) const { + s_update_dlnActCoeff_dT(); + for (int k = 0; k < m_kk; k++) { + d2lnActCoeffdT2[k] = d2lnActCoeffdT2_Scaled_[k]; + } + } + // calculate the change of the log of the activity coefficients wrt change in state: dT, dX /* * This function will be called to calculate gradient of the diff --git a/Cantera/src/thermo/MargulesVPSSTP.h b/Cantera/src/thermo/MargulesVPSSTP.h index 4e7df72eb..53a57904a 100644 --- a/Cantera/src/thermo/MargulesVPSSTP.h +++ b/Cantera/src/thermo/MargulesVPSSTP.h @@ -525,7 +525,18 @@ namespace Cantera { */ virtual void getChemPotentials(doublereal* mu) const; - + /// Molar enthalpy. Units: J/kmol. + virtual doublereal enthalpy_mole() const; + + /// Molar entropy. Units: J/kmol. + virtual doublereal entropy_mole() const; + + /// Molar heat capacity at constant pressure. Units: J/kmol/K. + virtual doublereal cp_mole() const; + + /// Molar heat capacity at constant volume. Units: J/kmol/K. + virtual doublereal cv_mole() const; + //! Returns an array of partial molar enthalpies for the species //! in the mixture. /*! @@ -564,6 +575,28 @@ namespace Cantera { */ virtual void getPartialMolarEntropies(doublereal* sbar) const; + //! Returns an array of partial molar entropies for the species + //! in the mixture. + /*! + * Units (J/kmol) + * + * For this phase, the partial molar enthalpies are equal to the + * standard state enthalpies modified by the derivative of the + * activity coefficent wrt temperature + * + * \f[ + * ??????????????? + * \bar s_k(T,P) = s^o_k(T,P) - R T^2 \frac{d \ln(\gamma_k)}{dT} + * - R \ln( \gamma_k X_k) + * - R T \frac{d \ln(\gamma_k) }{dT} + * ??????????????? + * \f] + * + * @param cpbar Vector of returned partial molar heat capacities + * (length m_kk, units = J/kmol/K) + */ + virtual void getPartialMolarCp(doublereal* cpbar) const; + //! Return an array of partial molar volumes for the //! species in the mixture. Units: m^3/kmol. @@ -604,6 +637,19 @@ namespace Cantera { */ virtual void getdlnActCoeff(const doublereal dT, const doublereal * const dX, doublereal *dlnActCoeffdT) const; + //! Get the array of temperature second derivatives of the log activity coefficients + /*! + * This function is a virtual class, but it first appears in GibbsExcessVPSSTP + * class and derived classes from GibbsExcessVPSSTP. + * + * units = 1/Kelvin + * + * @param d2lnActCoeffdT2 Output vector of temperature 2nd derivatives of the + * log Activity Coefficients. length = m_kk + * + */ + virtual void getd2lnActCoeffdT2(doublereal *d2lnActCoeffdT2) const; + //! Get the array of temperature derivatives of the log activity coefficients /*! * This function is a virtual class, but it first appears in GibbsExcessVPSSTP diff --git a/Cantera/src/thermo/SpeciesThermoFactory.cpp b/Cantera/src/thermo/SpeciesThermoFactory.cpp index 816e26f07..ce0d21007 100644 --- a/Cantera/src/thermo/SpeciesThermoFactory.cpp +++ b/Cantera/src/thermo/SpeciesThermoFactory.cpp @@ -829,7 +829,7 @@ namespace Cantera { f0->name() + " and " + f1->name()); } } - else if (nc >= 2) { + else if (nc > 2) { const XML_Node* f0 = tp[0]; if (f0->name() == "NASA9") { installNasa9ThermoFromXML(speciesNode["name"], spthermo, k, tp); diff --git a/Cantera/src/thermo/ThermoPhase.h b/Cantera/src/thermo/ThermoPhase.h index c52e74e75..69b517e9c 100644 --- a/Cantera/src/thermo/ThermoPhase.h +++ b/Cantera/src/thermo/ThermoPhase.h @@ -859,7 +859,7 @@ namespace Cantera { /// Molar internal energy. Units: J/kmol. virtual doublereal intEnergy_mole() const { - return err("intEnergy_mole"); + return enthalpy_mole() - pressure()* molarVolume(); } /// Molar entropy. Units: J/kmol/K. @@ -869,7 +869,7 @@ namespace Cantera { /// Molar Gibbs function. Units: J/kmol. virtual doublereal gibbs_mole() const { - return err("gibbs_mole"); + return enthalpy_mole() - temperature()*entropy_mole(); } /// Molar heat capacity at constant pressure. Units: J/kmol/K.