From aae7d0b44092521dc382d9d6a3c61fdfdb241909 Mon Sep 17 00:00:00 2001 From: John Hewson Date: Sun, 15 Nov 2009 04:40:37 +0000 Subject: [PATCH] Added method virtual void getdlnActCoeffdlnX(doublereal *dlnActCoeffdlnX) const; to ThermoPhase, GibbsExcessVPSSTP, VPStandardStateTP and MargulesVPSSTP classes (i.e. the whole thermo tree). In GibbsExcessVPSSTP and above, these methods are not yet implemented. In MargulesVPSSTP, the internal method void s_update_dlnActCoeff_dlnX() const; does the work and stores the result in the member dlnActCoeffdlnX_Scaled_. --- Cantera/src/thermo/GibbsExcessVPSSTP.cpp | 2 ++ Cantera/src/thermo/GibbsExcessVPSSTP.h | 32 +++++++++++++++++-- Cantera/src/thermo/MargulesVPSSTP.cpp | 40 ++++++++++++++++++++++++ Cantera/src/thermo/MargulesVPSSTP.h | 29 +++++++++++++++-- Cantera/src/thermo/PDSS_SSVol.cpp | 3 +- Cantera/src/thermo/ThermoPhase.h | 23 ++++++++++++++ Cantera/src/thermo/VPStandardStateTP.h | 25 +++++++++++++-- 7 files changed, 146 insertions(+), 8 deletions(-) diff --git a/Cantera/src/thermo/GibbsExcessVPSSTP.cpp b/Cantera/src/thermo/GibbsExcessVPSSTP.cpp index e45bd5243..f8606c1d3 100644 --- a/Cantera/src/thermo/GibbsExcessVPSSTP.cpp +++ b/Cantera/src/thermo/GibbsExcessVPSSTP.cpp @@ -63,6 +63,7 @@ namespace Cantera { moleFractions_ = b.moleFractions_; lnActCoeff_Scaled_ = b.lnActCoeff_Scaled_; dlnActCoeffdT_Scaled_ = b.dlnActCoeffdT_Scaled_; + dlnActCoeffdlnC_Scaled_ = b.dlnActCoeffdlnC_Scaled_; m_pp = b.m_pp; return *this; @@ -329,6 +330,7 @@ namespace Cantera { moleFractions_.resize(m_kk); lnActCoeff_Scaled_.resize(m_kk); dlnActCoeffdT_Scaled_.resize(m_kk); + dlnActCoeffdlnC_Scaled_.resize(m_kk); m_pp.resize(m_kk); } diff --git a/Cantera/src/thermo/GibbsExcessVPSSTP.h b/Cantera/src/thermo/GibbsExcessVPSSTP.h index 59b456232..185c2be27 100644 --- a/Cantera/src/thermo/GibbsExcessVPSSTP.h +++ b/Cantera/src/thermo/GibbsExcessVPSSTP.h @@ -302,6 +302,28 @@ namespace Cantera { err("getdlnActCoeffdT"); } + //! Get the array of log concentration-like derivatives of the + //! log activity coefficients + /*! + * This function is a virtual method. For ideal mixtures + * (unity activity coefficients), this can return zero. + * Implementations should take the derivative of the + * logarithm of the activity coefficient with respect to the + * logarithm of the concentration-like variable (i.e. mole fraction, + * molality, etc.) that represents the standard state. + * This quantity is to be used in conjunction with derivatives of + * that concentration-like variable when the derivative of the chemical + * potential is taken. + * + * units = dimensionless + * + * @param dlnActCoeffdlnC Output vector of derivatives of the + * log Activity Coefficients. length = m_kk + */ + virtual void getdlnActCoeffdlnC(doublereal *dlnActCoeffdlnC) const { + err("getdlnActCoeffdlnC"); + } + //@} /// @name Partial Molar Properties of the Solution //@{ @@ -532,10 +554,16 @@ namespace Cantera { //! species, divided by RT mutable std::vector lnActCoeff_Scaled_; - //! Storage for the current derivative values of the log of the - // activity coefficients of the species + //! 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 dlnActCoeffdT_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 + mutable std::vector dlnActCoeffdlnC_Scaled_; + //! Temporary storage space that is fair game mutable std::vector m_pp; diff --git a/Cantera/src/thermo/MargulesVPSSTP.cpp b/Cantera/src/thermo/MargulesVPSSTP.cpp index d2f6ebdce..4a9387970 100644 --- a/Cantera/src/thermo/MargulesVPSSTP.cpp +++ b/Cantera/src/thermo/MargulesVPSSTP.cpp @@ -648,6 +648,46 @@ namespace Cantera { } } + // Update the derivative of the log of the activity coefficients wrt ln(X) + /* + * This function will be called to update the internally stored gradients of the + * logarithm of the activity coefficients. These are used in the determination + * of the diffusion coefficients. + * + * he = X_A X_B(B + C(X_A - X_B)) + */ + void MargulesVPSSTP::s_update_dlnActCoeff_dlnX() const { + int iA, iB; + doublereal XA, XB, g0 , g1; + doublereal T = temperature(); + + fvo_zero_dbl_1(dlnActCoeffdlnX_Scaled_, m_kk); + + doublereal RT = GasConstant * T; + for (int i = 0; i < numBinaryInteractions_; i++) { + iA = m_pSpecies_A_ij[i]; + iB = m_pSpecies_B_ij[i]; + + XA = moleFractions_[iA]; + XB = moleFractions_[iB]; + + g0 = (m_HE_b_ij[i] - T * m_SE_b_ij[i]) / RT ; + g1 = (m_HE_c_ij[i] - T * m_SE_c_ij[i]) / RT; + + dlnActCoeffdlnX_Scaled_[iA] += XA * ( ( - 2.0 + 2.0 * XA ) * g0 + + ( - 4.0 + 10.0 * XA - 6.0 * XA*XA ) * g1 ) ; + dlnActCoeffdlnX_Scaled_[iB] += XB * ( ( - 2.0 + 2.0 * XB ) * g0 + + ( 2.0 - 8.0 * XB + 6.0 * XB*XB ) * g1 ) ; + } + } + + void MargulesVPSSTP::getdlnActCoeffdlnX(doublereal *dlnActCoeffdlnX) const { + s_update_dlnActCoeff_dlnX(); + for (int k = 0; k < m_kk; k++) { + dlnActCoeffdlnX[k] = dlnActCoeffdlnX_Scaled_[k]; + } + } + void MargulesVPSSTP::resizeNumInteractions(const int num) { numBinaryInteractions_ = num; diff --git a/Cantera/src/thermo/MargulesVPSSTP.h b/Cantera/src/thermo/MargulesVPSSTP.h index fdbfa8434..e3c8ad67a 100644 --- a/Cantera/src/thermo/MargulesVPSSTP.h +++ b/Cantera/src/thermo/MargulesVPSSTP.h @@ -589,13 +589,27 @@ namespace Cantera { * @param dlnActCoeffdT Output vector of temperature derivatives of the * log Activity Coefficients. length = m_kk * - * @param dlnActCoeffdT Vector of returned derivatives of - * ln (actCoeff) wrt temperature. - * (length m_kk, units = 1/K) */ virtual void getdlnActCoeffdT(doublereal *dlnActCoeffdT) const; + //! Get the array of derivatives of the log activity coefficients + //! with respect to the log mole fractions + /*! + * This function is a virtual class, but it first appears in + * GibbsExcessVPSSTP class and derived classes. + * Output vector of log(mole fraction) derivatives of the + * log Activity Coefficients. + * + * units = dimensionless + * + * @param dlnActCoeffdlnX Output vector of log(mole fraction) + * derivatives of the log Activity Coefficients. + * length = m_kk + */ + virtual void getdlnActCoeffdlnX(doublereal *dlnActCoeffdlnX) const; + + //@} /// @name Properties of the Standard State of the Species in the Solution //@{ @@ -735,6 +749,15 @@ namespace Cantera { */ void s_update_dlnActCoeff_dT() const; + //! Update the derivative of the log of the activity coefficients + //! wrt log(mole fraction) + /*! + * This function will be called to update the internally storred + * derivative of the natural logarithm of the activity coefficients + * wrt logarithm of the mole fractions. + */ + void s_update_dlnActCoeff_dlnX() const; + private: //! Error function diff --git a/Cantera/src/thermo/PDSS_SSVol.cpp b/Cantera/src/thermo/PDSS_SSVol.cpp index c99a1a537..98e1b95b6 100644 --- a/Cantera/src/thermo/PDSS_SSVol.cpp +++ b/Cantera/src/thermo/PDSS_SSVol.cpp @@ -39,7 +39,8 @@ namespace Cantera { } - PDSS_SSVol::PDSS_SSVol(VPStandardStateTP *tp, int spindex, std::string inputFile, std::string id) : + PDSS_SSVol::PDSS_SSVol(VPStandardStateTP *tp, + int spindex, std::string inputFile, std::string id) : PDSS(tp, spindex), volumeModel_(cSSVOLUME_CONSTANT), m_constMolarVolume(-1.0) diff --git a/Cantera/src/thermo/ThermoPhase.h b/Cantera/src/thermo/ThermoPhase.h index d6c7a64a1..a4ef04d99 100644 --- a/Cantera/src/thermo/ThermoPhase.h +++ b/Cantera/src/thermo/ThermoPhase.h @@ -848,6 +848,29 @@ namespace Cantera { } + //! Get the array of log concentration-like derivatives of the + //! log activity coefficients + /*! + * This function is a virtual method. For ideal mixtures + * (unity activity coefficients), this can return zero. + * Implementations should take the derivative of the + * logarithm of the activity coefficient with respect to the + * logarithm of the concentration-like variable (i.e. mole fraction, + * molality, etc.) that represents the standard state. + * This quantity is to be used in conjunction with derivatives of + * that concentration-like variable when the derivative of the chemical + * potential is taken. + * + * units = dimensionless + * + * @param dlnActCoeffdlnC Output vector of derivatives of the + * log Activity Coefficients. length = m_kk + */ + virtual void getdlnActCoeffdlnC(doublereal *dlnActCoeffdlnC) const { + err("getdlnActCoeffdlnC"); + } + + /** * @} * @name Mechanical Properties diff --git a/Cantera/src/thermo/VPStandardStateTP.h b/Cantera/src/thermo/VPStandardStateTP.h index 4df17709c..4faed6a10 100644 --- a/Cantera/src/thermo/VPStandardStateTP.h +++ b/Cantera/src/thermo/VPStandardStateTP.h @@ -120,10 +120,31 @@ namespace Cantera { */ virtual int standardStateConvention() const; - //@} + //! Get the array of log concentration-like derivatives of the + //! log activity coefficients + /*! + * This function is a virtual method. For ideal mixtures + * (unity activity coefficients), this can return zero. + * Implementations should take the derivative of the + * logarithm of the activity coefficient with respect to the + * logarithm of the concentration-like variable (i.e. mole fraction, + * molality, etc.) that represents the standard state. + * This quantity is to be used in conjunction with derivatives of + * that concentration-like variable when the derivative of the chemical + * potential is taken. + * + * units = dimensionless + * + * @param dlnActCoeffdlnC Output vector of derivatives of the + * log Activity Coefficients. length = m_kk + */ + virtual void getdlnActCoeffdlnC(doublereal *dlnActCoeffdlnC) const { + err("getdlnActCoeffdlnC"); + } - /// @name Partial Molar Properties of the Solution (VPStandardStateTP) + //@} + /// @name Partial Molar Properties of the Solution (VPStandardStateTP) //@{