diff --git a/Cantera/src/thermo/PureFluidPhase.cpp b/Cantera/src/thermo/PureFluidPhase.cpp index 41dcc6bcc..f753bc8cd 100644 --- a/Cantera/src/thermo/PureFluidPhase.cpp +++ b/Cantera/src/thermo/PureFluidPhase.cpp @@ -179,14 +179,14 @@ namespace Cantera { check(p); return p; } - + //==================================================================================================================== void PureFluidPhase:: setPressure(doublereal p) { Set(tpx::TP, temperature(), p); setDensity(1.0/m_sub->v()); check(); } - + //==================================================================================================================== void PureFluidPhase::Set(int n, double x, double y) const { try { m_sub->Set(n, x, y); @@ -195,36 +195,115 @@ namespace Cantera { reportTPXError(); } } - + //==================================================================================================================== void PureFluidPhase::setTPXState() const { Set(tpx::TV, temperature(), 1.0/density()); } - + //==================================================================================================================== void PureFluidPhase::check(doublereal v) const { if (m_sub->Error() || v == tpx::Undef) { throw CanteraError("PureFluidPhase",string(tpx::errorMsg( m_sub->Error()))); } } - + //==================================================================================================================== void PureFluidPhase::reportTPXError() const { string msg = tpx::TPX_Error::ErrorMessage; string proc = "tpx::"+tpx::TPX_Error::ErrorProcedure; throw CanteraError(proc,msg); } - + //==================================================================================================================== doublereal PureFluidPhase::isothermalCompressibility() const { return m_sub->isothermalCompressibility(); } - + //==================================================================================================================== doublereal PureFluidPhase::thermalExpansionCoeff() const { return m_sub->thermalExpansionCoeff(); } - + //==================================================================================================================== tpx::Substance& PureFluidPhase::TPX_Substance() { return *m_sub; } - - + //==================================================================================================================== + // Returns an array of partial molar enthalpies for the species + // in the mixture. Units (J/kmol) + /* + * @param hbar Output vector of species partial molar enthalpies. + * Length: m_kk. units are J/kmol. + */ + void PureFluidPhase::getPartialMolarEnthalpies(doublereal* hbar) const { + hbar[0] = enthalpy_mole(); + } + //==================================================================================================================== + // Returns an array of partial molar entropies of the species in the + // solution. Units: J/kmol/K. + /* + * @param sbar Output vector of species partial molar entropies. + * Length = m_kk. units are J/kmol/K. + */ + void PureFluidPhase::getPartialMolarEntropies(doublereal* sbar) const { + sbar[0] = entropy_mole(); + } + //==================================================================================================================== + // Return an array of partial molar internal energies for the + // species in the mixture. Units: J/kmol. + /* + * @param ubar Output vector of speciar partial molar internal energies. + * Length = m_kk. units are J/kmol. + */ + void PureFluidPhase::getPartialMolarIntEnergies(doublereal* ubar) const { + ubar[0] = intEnergy_mole(); + } + //==================================================================================================================== + // Return an array of partial molar heat capacities for the + // species in the mixture. Units: J/kmol/K + /* + * @param cpbar Output vector of species partial molar heat + * capacities at constant pressure. + * Length = m_kk. units are J/kmol/K. + */ + void PureFluidPhase::getPartialMolarCp(doublereal* cpbar) const { + cpbar[0] = cp_mole(); + } + //==================================================================================================================== + // Return an array of partial molar volumes for the + // species in the mixture. Units: m^3/kmol. + /* + * @param vbar Output vector of speciar partial molar volumes. + * Length = m_kk. units are m^3/kmol. + */ + void PureFluidPhase::getPartialMolarVolumes(doublereal* vbar) const { + vbar[0] = 1.0 / molarDensity(); + } + //==================================================================================================================== + int PureFluidPhase::standardStateConvention() const { + return cSS_CONVENTION_TEMPERATURE; + } + //==================================================================================================================== + void PureFluidPhase::getActivityConcentrations(doublereal* c) const { + c[0] = 1.0; + } + //==================================================================================================================== + doublereal PureFluidPhase::standardConcentration(int k) const { + return 1.0; + } + //==================================================================================================================== + void PureFluidPhase::getActivities(doublereal *a) const { + a[0] = 1.0; + } + //==================================================================================================================== + // Get the array of chemical potentials at unit activity for the species + // at their standard states at the current T and P of the solution. + /* + * These are the standard state chemical potentials \f$ \mu^0_k(T,P) + * \f$. The values are evaluated at the current + * temperature and pressure of the solution + * + * @param mu Output vector of chemical potentials. + * Length: m_kk. + */ + void PureFluidPhase::getStandardChemPotentials(doublereal* mu) const { + mu[0] = gibbs_mole(); + } //==================================================================================================================== // Get the nondimensional Enthalpy functions for the species // at their standard states at the current T and P of the solution. @@ -237,7 +316,6 @@ namespace Cantera { doublereal h = enthalpy_mole(); hrt[0] = h / rt; } - //==================================================================================================================== // Get the array of nondimensional Entropy functions for the // standard state species at the current T and P of the solution. @@ -296,26 +374,43 @@ namespace Cantera { Set(tpx::TP, t, psave); } //==================================================================================================================== + // Returns the vector of the gibbs function of the reference state at the current temperature + // of the solution and the reference pressure for the species. + /* + * units = J/kmol + * + * @param g Output vector containing the reference state + * Gibbs Free energies. Length: m_kk. Units: J/kmol. + */ + void PureFluidPhase::getGibbs_ref(doublereal *g) const { + getGibbs_RT_ref(g); + g[0] *= (GasConstant * temperature()); + } + //==================================================================================================================== // Returns the vector of nondimensional entropies of the reference state at the current temperature // of the solution and the reference pressure for each species. - /*! + /* * @param er Output vector containing the nondimensional reference state * entropies. Length: m_kk. */ void PureFluidPhase::getEntropy_R_ref(doublereal *er) const { - + double psave = pressure(); + double t = temperature(); + double pref = m_spthermo->refPressure(); + Set(tpx::TP, t, pref); + getEntropy_R(er); + Set(tpx::TP, t, psave); } //==================================================================================================================== - - /// critical temperature + // critical temperature doublereal PureFluidPhase::critTemperature() const { return m_sub->Tcrit(); } - + //==================================================================================================================== /// critical pressure doublereal PureFluidPhase::critPressure() const { return m_sub->Pcrit(); } - + //==================================================================================================================== /// critical density doublereal PureFluidPhase::critDensity() const { return 1.0/m_sub->Vcrit(); } - + //==================================================================================================================== /// saturation temperature doublereal PureFluidPhase::satTemperature(doublereal p) const { @@ -328,35 +423,35 @@ namespace Cantera { return -1.0; } } - + //==================================================================================================================== void PureFluidPhase::setState_HP(doublereal h, doublereal p, doublereal tol) { Set(tpx::HP, h, p); setState_TR(m_sub->Temp(), 1.0/m_sub->v()); check(); } - + //==================================================================================================================== void PureFluidPhase::setState_UV(doublereal u, doublereal v, doublereal tol) { Set(tpx::UV, u, v); setState_TR(m_sub->Temp(), 1.0/m_sub->v()); check(); } - + //==================================================================================================================== void PureFluidPhase::setState_SV(doublereal s, doublereal v, doublereal tol) { Set(tpx::SV, s, v); setState_TR(m_sub->Temp(), 1.0/m_sub->v()); check(); } - + //==================================================================================================================== void PureFluidPhase::setState_SP(doublereal s, doublereal p, doublereal tol) { Set(tpx::SP, s, p); setState_TR(m_sub->Temp(), 1.0/m_sub->v()); check(); } - + //==================================================================================================================== // saturation pressure doublereal PureFluidPhase::satPressure(doublereal t) const { doublereal vsv = m_sub->v(); @@ -370,14 +465,14 @@ namespace Cantera { return -1.0; } } - + //==================================================================================================================== doublereal PureFluidPhase::vaporFraction() const { setTPXState(); doublereal x = m_sub->x(); check(x); return x; } - + //==================================================================================================================== void PureFluidPhase::setState_Tsat(doublereal t, doublereal x) { setTemperature(t); setTPXState(); @@ -385,7 +480,7 @@ namespace Cantera { setDensity(1.0/m_sub->v()); check(); } - + //==================================================================================================================== void PureFluidPhase::setState_Psat(doublereal p, doublereal x) { setTPXState(); Set(tpx::PX, p, x); @@ -394,7 +489,7 @@ namespace Cantera { check(); } - + //==================================================================================================================== /** * Format a summary of the mixture state for output. */ @@ -512,7 +607,7 @@ namespace Cantera { } return s; } - + //==================================================================================================================== /* * Format a summary of the mixture state for output. */ @@ -650,6 +745,7 @@ namespace Cantera { } } + } #endif // WITH_PURE_FLUIDS diff --git a/Cantera/src/thermo/PureFluidPhase.h b/Cantera/src/thermo/PureFluidPhase.h index e08b0e2b3..f692bad1d 100644 --- a/Cantera/src/thermo/PureFluidPhase.h +++ b/Cantera/src/thermo/PureFluidPhase.h @@ -142,6 +142,145 @@ namespace Cantera { mu[0] = gibbs_mole(); } + + + //! Get the species electrochemical potentials. + /*! + * These are partial molar quantities. This method adds a term \f$ F z_k + * \phi_p \f$ to each chemical potential. + * The electrochemical potential of species k in a phase p, \f$ \zeta_k \f$, + * is related to the chemical potential via + * the following equation, + * + * \f[ + * \zeta_{k}(T,P) = \mu_{k}(T,P) + F z_k \phi_p + * \f] + * + * @param mu Output vector of species electrochemical + * potentials. Length: m_kk. Units: J/kmol + */ + void getElectrochemPotentials(doublereal* mu) const { + getChemPotentials(mu); + double ve = Faraday * electricPotential(); + for (int k = 0; k < m_kk; k++) { + mu[k] += ve*charge(k); + } + } + + //! Returns an array of partial molar enthalpies for the species + //! in the mixture. Units (J/kmol) + /*! + * @param hbar Output vector of species partial molar enthalpies. + * Length: m_kk. units are J/kmol. + */ + virtual void getPartialMolarEnthalpies(doublereal* hbar) const; + + + //! Returns an array of partial molar entropies of the species in the + //! solution. Units: J/kmol/K. + /*! + * @param sbar Output vector of species partial molar entropies. + * Length = m_kk. units are J/kmol/K. + */ + virtual void getPartialMolarEntropies(doublereal* sbar) const; + + //! Return an array of partial molar internal energies for the + //! species in the mixture. Units: J/kmol. + /*! + * @param ubar Output vector of speciar partial molar internal energies. + * Length = m_kk. units are J/kmol. + */ + virtual void getPartialMolarIntEnergies(doublereal* ubar) const; + + //! Return an array of partial molar heat capacities for the + //! species in the mixture. Units: J/kmol/K + /*! + * @param cpbar Output vector of species partial molar heat + * capacities at constant pressure. + * Length = m_kk. units are 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. + /*! + * @param vbar Output vector of speciar partial molar volumes. + * Length = m_kk. units are m^3/kmol. + */ + virtual void getPartialMolarVolumes(doublereal* vbar) const; + + //! This method returns the convention used in specification + //! of the standard state, of which there are currently two, + //! temperature based, and variable pressure based. + /*! + * Currently, there are two standard state conventions: + * - Temperature-based activities + * cSS_CONVENTION_TEMPERATURE 0 + * - default + * + * - Variable Pressure and Temperature -based activities + * cSS_CONVENTION_VPSS 1 + * + * - Thermodynamics is set via slave ThermoPhase objects with + * nothing being carried out at this %ThermoPhase object level + * cSS_CONVENTION_SLAVE 2 + */ + virtual int standardStateConvention() const; + + //! This method returns an array of generalized concentrations + /*! + * \f$ C^a_k\f$ are defined such that \f$ a_k = C^a_k / + * C^0_k, \f$ where \f$ C^0_k \f$ is a standard concentration + * defined below and \f$ a_k \f$ are activities used in the + * thermodynamic functions. These activity (or generalized) + * concentrations are used + * by kinetics manager classes to compute the forward and + * reverse rates of elementary reactions. Note that they may + * or may not have units of concentration --- they might be + * partial pressures, mole fractions, or surface coverages, + * for example. + * + * @param c Output array of generalized concentrations. The + * units depend upon the implementation of the + * reaction rate expressions within the phase. + */ + virtual void getActivityConcentrations(doublereal* c) const; + + //! Return the standard concentration for the kth species + /*! + * The standard concentration \f$ C^0_k \f$ used to normalize + * the activity (i.e., generalized) concentration. In many cases, this quantity + * will be the same for all species in a phase - for example, + * for an ideal gas \f$ C^0_k = P/\hat R T \f$. For this + * reason, this method returns a single value, instead of an + * array. However, for phases in which the standard + * concentration is species-specific (e.g. surface species of + * different sizes), this method may be called with an + * optional parameter indicating the species. + * + * @param k Optional parameter indicating the species. The default + * is to assume this refers to species 0. + * @return + * Returns the standard concentration. The units are by definition + * dependent on the ThermoPhase and kinetics manager representation. + */ + virtual doublereal standardConcentration(int k=0) const; + + //! Get the array of non-dimensional activities at + //! the current solution temperature, pressure, and solution concentration. + /*! + * Note, for molality based formulations, this returns the + * molality based activities. + * + * We resolve this function at this level by calling + * on the activityConcentration function. However, + * derived classes may want to override this default + * implementation. + * + * @param a Output vector of activities. Length: m_kk. + */ + virtual void getActivities(doublereal* a) const; + //! Returns the isothermal compressibility. Units: 1/Pa. /*! * The isothermal compressibility is defined as @@ -167,6 +306,17 @@ namespace Cantera { /// @name Properties of the Standard State of the Species in the Solution //@{ + //! Get the array of chemical potentials at unit activity for the species + //! at their standard states at the current T and P of the solution. + /*! + * These are the standard state chemical potentials \f$ \mu^0_k(T,P) + * \f$. The values are evaluated at the current + * temperature and pressure of the solution + * + * @param mu Output vector of chemical potentials. + * Length: m_kk. + */ + virtual void getStandardChemPotentials(doublereal* mu) const; //! Get the nondimensional Enthalpy functions for the species //! at their standard states at the current T and P of the solution. @@ -217,6 +367,18 @@ namespace Cantera { */ virtual void getGibbs_RT_ref(doublereal *grt) const; + //! Returns the vector of the gibbs function of the reference state at the current temperature + //! of the solution and the reference pressure for the species. + /*! + * units = J/kmol + * + * @param g Output vector containing the reference state + * Gibbs Free energies. Length: m_kk. Units: J/kmol. + */ + virtual void getGibbs_ref(doublereal *g) const; + + + //! Returns the vector of nondimensional //! entropies of the reference state at the current temperature //! of the solution and the reference pressure for each species.