Cantera  2.3.0
GibbsExcessVPSSTP.h
Go to the documentation of this file.
1 /**
2  * @file GibbsExcessVPSSTP.h
3  * Header for intermediate ThermoPhase object for phases which
4  * employ Gibbs excess free energy based formulations
5  * (see \ref thermoprops
6  * and class \link Cantera::GibbsExcessVPSSTP GibbsExcessVPSSTP\endlink).
7  */
8 
9 // This file is part of Cantera. See License.txt in the top-level directory or
10 // at http://www.cantera.org/license.txt for license and copyright information.
11 
12 #ifndef CT_GIBBSEXCESSVPSSTP_H
13 #define CT_GIBBSEXCESSVPSSTP_H
14 
15 #include "VPStandardStateTP.h"
16 #include "cantera/base/Array.h"
17 
18 namespace Cantera
19 {
20 
21 /*!
22  * GibbsExcessVPSSTP is a derived class of ThermoPhase that handles variable
23  * pressure standard state methods for calculating thermodynamic properties that
24  * are further based on expressing the Excess Gibbs free energy as a function of
25  * the mole fractions (or pseudo mole fractions) of constituents. This category
26  * is the workhorse for describing molten salts, solid-phase mixtures of
27  * semiconductors, and mixtures of miscible and semi-miscible compounds.
28  *
29  * It includes
30  * - regular solutions
31  * - Margules expansions
32  * - NTRL equation
33  * - Wilson's equation
34  * - UNIQUAC equation of state.
35  *
36  * This class adds additional functions onto the ThermoPhase interface that
37  * handles the calculation of the excess Gibbs free energy. The ThermoPhase
38  * class includes a member function, ThermoPhase::activityConvention() that
39  * indicates which convention the activities are based on. The default is to
40  * assume activities are based on the molar convention. That default is used
41  * here.
42  *
43  * All of the Excess Gibbs free energy formulations in this area employ
44  * symmetrical formulations.
45  *
46  * Chemical potentials of species k, \f$ \mu_o \f$, has the following general
47  * format:
48  *
49  * \f[
50  * \mu_k = \mu^o_k(T,P) + R T ln( \gamma_k X_k )
51  * \f]
52  *
53  * where \f$ \gamma_k^{\triangle} \f$ is a molar based activity coefficient for
54  * species \f$k\f$.
55  *
56  * GibbsExcessVPSSTP contains an internal vector with the current mole fraction
57  * vector. That's one of its primary usages. In order to keep the mole fraction
58  * vector constant, all of the setState functions are redesigned at this layer.
59  *
60  * ### Activity Concentrations: Relationship of ThermoPhase to %Kinetics Expressions
61  *
62  * As explained in a similar discussion in the ThermoPhase class, the actual
63  * units used in kinetics expressions must be specified in the ThermoPhase class
64  * for the corresponding species. These units vary with the field of study.
65  * %Cantera uses the concept of activity concentrations to represent this.
66  * Activity concentrations are used directly in the expressions for kinetics.
67  * Standard concentrations are used as the multiplicative constant that takes
68  * the activity of a species and turns it into an activity concentration.
69  * Standard concentrations must not depend on the concentration of the species
70  * in the phase.
71  *
72  * Here we set a standard for the specification of the standard concentrations
73  * for this class and all child classes underneath it. We specify here that the
74  * standard concentration is equal to 1 for all species. Therefore, the
75  * activities appear directly in kinetics expressions involving species in
76  * underlying GibbsExcessVPSSTP phases.
77  *
78  * ### SetState Strategy
79  *
80  * All setState functions that set the internal state of the ThermoPhase object
81  * are overloaded at this level, so that a current mole fraction vector is
82  * maintained within the object.
83  */
85 {
86 public:
87  //! @name Constructors
88  //! @{
89 
91 
93  GibbsExcessVPSSTP& operator=(const GibbsExcessVPSSTP& b);
94  virtual ThermoPhase* duplMyselfAsThermoPhase() const;
95  //! @}
96 
97  //! @}
98  //! @name Mechanical Properties
99  //! @{
100 
101 protected:
102  /**
103  * Calculate the density of the mixture using the partial molar volumes and
104  * mole fractions as input
105  *
106  * The formula for this is
107  *
108  * \f[
109  * \rho = \frac{\sum_k{X_k W_k}}{\sum_k{X_k V_k}}
110  * \f]
111  *
112  * where \f$X_k\f$ are the mole fractions, \f$W_k\f$ are the molecular
113  * weights, and \f$V_k\f$ are the pure species molar volumes.
114  *
115  * Note, the basis behind this formula is that in an ideal solution the
116  * partial molar volumes are equal to the pure species molar volumes. We
117  * have additionally specified in this class that the pure species molar
118  * volumes are independent of temperature and pressure.
119  *
120  * NOTE: This is a non-virtual function, which is not a member of the
121  * ThermoPhase base class.
122  */
123  void calcDensity();
124 
125 public:
126  /**
127  * @}
128  * @name Activities, Standard States, and Activity Concentrations
129  *
130  * The activity \f$a_k\f$ of a species in solution is related to the
131  * chemical potential by \f[ \mu_k = \mu_k^0(T) + \hat R T \log a_k. \f] The
132  * quantity \f$\mu_k^0(T,P)\f$ is the chemical potential at unit activity,
133  * which depends only on temperature and pressure.
134  * @{
135  */
136 
137  virtual void getActivityConcentrations(doublereal* c) const;
138 
139  /**
140  * The standard concentration \f$ C^0_k \f$ used to normalize the
141  * generalized concentration. In many cases, this quantity will be the same
142  * for all species in a phase - for example, for an ideal gas
143  * \f$ C^0_k = P/\hat R T \f$. For this reason, this method returns a single
144  * value, instead of an array. However, for phases in which the standard
145  * concentration is species-specific (e.g. surface species of different
146  * sizes), this method may be called with an optional parameter indicating
147  * the species.
148  *
149  * The standard concentration for defaulted to 1. In other words
150  * the activity concentration is assumed to be 1.
151  *
152  * @param k species index. Defaults to zero.
153  */
154  virtual doublereal standardConcentration(size_t k=0) const;
155  virtual doublereal logStandardConc(size_t k=0) const;
156 
157  //! Get the array of non-dimensional activities (molality based for this
158  //! class and classes that derive from it) at the current solution
159  //! temperature, pressure, and solution concentration.
160  /*!
161  * \f[
162  * a_i^\triangle = \gamma_k^{\triangle} \frac{m_k}{m^\triangle}
163  * \f]
164  *
165  * This function must be implemented in derived classes.
166  *
167  * @param ac Output vector of molality-based activities. Length: m_kk.
168  */
169  virtual void getActivities(doublereal* ac) const;
170 
171  virtual void getActivityCoefficients(doublereal* ac) const;
172 
173  //! Get the array of temperature derivatives of the log activity coefficients
174  /*!
175  * This function is virtual, and first appears in GibbsExcessVPSSTP.
176  *
177  * units = 1/Kelvin
178  *
179  * @param dlnActCoeffdT Output vector of temperature derivatives of the
180  * log Activity Coefficients. length = m_kk
181  */
182  virtual void getdlnActCoeffdT(doublereal* dlnActCoeffdT) const {
183  throw NotImplementedError("GibbsExcessVPSSTP::getdlnActCoeffdT");
184  }
185 
186  virtual void getdlnActCoeffdlnN(const size_t ld, doublereal* const dlnActCoeffdlnN) {
187  throw NotImplementedError("GibbsExcessVPSSTP::getdlnActCoeffdlnN: "
188  "nonzero and nonimplemented");
189  }
190 
191  //! Get the array of log concentration-like derivatives of the log activity
192  //! coefficients
193  /*!
194  * This function is a virtual method. For ideal mixtures (unity activity
195  * coefficients), this can return zero. Implementations should take the
196  * derivative of the logarithm of the activity coefficient with respect to
197  * the logarithm of the concentration-like variable (i.e. number of moles in
198  * in a unit volume. ) that represents the standard state. This quantity is
199  * to be used in conjunction with derivatives of that concentration-like
200  * variable when the derivative of the chemical potential is taken.
201  *
202  * units = dimensionless
203  *
204  * @param dlnActCoeffdlnX Output vector of derivatives of the
205  * log Activity Coefficients. length = m_kk
206  */
207  virtual void getdlnActCoeffdlnX(doublereal* dlnActCoeffdlnX) const {
208  throw NotImplementedError("GibbsExcessVPSSTP::getdlnActCoeffdlnX");
209  }
210 
211  //@}
212  /// @name Partial Molar Properties of the Solution
213  //@{
214 
215  //! Return an array of partial molar volumes for the
216  //! species in the mixture. Units: m^3/kmol.
217  /*!
218  * Frequently, for this class of thermodynamics representations,
219  * the excess Volume due to mixing is zero. Here, we set it as
220  * a default. It may be overridden in derived classes.
221  *
222  * @param vbar Output vector of species partial molar volumes.
223  * Length = m_kk. units are m^3/kmol.
224  */
225  virtual void getPartialMolarVolumes(doublereal* vbar) const;
226  virtual const vector_fp& getPartialMolarVolumesVector() const;
227 
228  virtual bool addSpecies(shared_ptr<Species> spec);
229 
230 protected:
231  virtual void compositionChanged();
232 
233  //! utility routine to check mole fraction sum
234  /*!
235  * @param x vector of mole fractions.
236  */
237  double checkMFSum(const doublereal* const x) const;
238 
239  //! Storage for the current values of the mole fractions of the species
240  /*!
241  * This vector is kept up-to-date when the setState functions are called.
242  * Therefore, it may be considered to be an independent variable.
243  *
244  * Note in order to do this, the setState functions are redefined to always
245  * keep this vector current.
246  */
248 
249  //! Storage for the current values of the activity coefficients of the
250  //! species
252 
253  //! Storage for the current derivative values of the gradients with respect
254  //! to temperature of the log of the activity coefficients of the species
256 
257  //! Storage for the current derivative values of the gradients with respect
258  //! to temperature of the log of the activity coefficients of the species
260 
261  //! Storage for the current derivative values of the gradients with respect
262  //! to logarithm of the mole fraction of the log of the activity
263  //! coefficients of the species
265 
266  //! Storage for the current derivative values of the gradients with respect
267  //! to logarithm of the mole fraction of the log of the activity
268  //! coefficients of the species
270 
271  //! Storage for the current derivative values of the gradients with respect
272  //! to logarithm of the species mole number of the log of the activity
273  //! coefficients of the species
274  /*!
275  * dlnActCoeffdlnN_(k, m) is the derivative of ln(gamma_k) wrt ln mole
276  * number of species m
277  */
279 };
280 
281 }
282 
283 #endif
virtual void getdlnActCoeffdlnN(const size_t ld, doublereal *const dlnActCoeffdlnN)
Get the array of derivatives of the log activity coefficients with respect to the log of the species ...
double checkMFSum(const doublereal *const x) const
utility routine to check mole fraction sum
vector_fp dlnActCoeffdlnX_diag_
Storage for the current derivative values of the gradients with respect to logarithm of the mole frac...
An error indicating that an unimplemented function has been called.
Definition: ctexceptions.h:193
virtual void compositionChanged()
Apply changes to the state which are needed after the composition changes.
virtual void getActivityConcentrations(doublereal *c) const
This method returns an array of generalized concentrations.
A class for 2D arrays stored in column-major (Fortran-compatible) form.
Definition: Array.h:31
Base class for a phase with thermodynamic properties.
Definition: ThermoPhase.h:93
Header file for class Cantera::Array2D.
vector_fp dlnActCoeffdlnN_diag_
Storage for the current derivative values of the gradients with respect to logarithm of the mole frac...
vector_fp d2lnActCoeffdT2_Scaled_
Storage for the current derivative values of the gradients with respect to temperature of the log of ...
virtual bool addSpecies(shared_ptr< Species > spec)
void calcDensity()
Calculate the density of the mixture using the partial molar volumes and mole fractions as input...
This is a filter class for ThermoPhase that implements some prepatory steps for efficiently handling ...
vector_fp lnActCoeff_Scaled_
Storage for the current values of the activity coefficients of the species.
virtual void getdlnActCoeffdlnX(doublereal *dlnActCoeffdlnX) const
Get the array of log concentration-like derivatives of the log activity coefficients.
virtual void getActivities(doublereal *ac) const
Get the array of non-dimensional activities (molality based for this class and classes that derive fr...
virtual doublereal standardConcentration(size_t k=0) const
The standard concentration used to normalize the generalized concentration.
virtual ThermoPhase * duplMyselfAsThermoPhase() const
Duplication routine for objects which inherit from ThermoPhase.
Header file for a derived class of ThermoPhase that handles variable pressure standard state methods ...
virtual void getPartialMolarVolumes(doublereal *vbar) const
Return an array of partial molar volumes for the species in the mixture.
std::vector< double > vector_fp
Turn on the use of stl vectors for the basic array type within cantera Vector of doubles.
Definition: ct_defs.h:157
vector_fp moleFractions_
Storage for the current values of the mole fractions of the species.
Array2D dlnActCoeffdlnN_
Storage for the current derivative values of the gradients with respect to logarithm of the species m...
Namespace for the Cantera kernel.
Definition: application.cpp:29
virtual void getActivityCoefficients(doublereal *ac) const
Get the array of non-dimensional molar-based activity coefficients at the current solution temperatur...
virtual void getdlnActCoeffdT(doublereal *dlnActCoeffdT) const
Get the array of temperature derivatives of the log activity coefficients.
vector_fp dlnActCoeffdT_Scaled_
Storage for the current derivative values of the gradients with respect to temperature of the log of ...
virtual doublereal logStandardConc(size_t k=0) const
Natural logarithm of the standard concentration of the kth species.