Cantera  2.2.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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  * Header file for a derived class of ThermoPhase that handles
9  * variable pressure standard state methods for calculating
10  * thermodynamic properties that are further based upon activities
11  * based on the molality scale. These include most of the methods for
12  * calculating liquid electrolyte thermodynamics.
13  */
14 /*
15  * Copyright (2006) Sandia Corporation. Under the terms of
16  * Contract DE-AC04-94AL85000 with Sandia Corporation, the
17  * U.S. Government retains certain rights in this software.
18  */
19 #ifndef CT_GIBBSEXCESSVPSSTP_H
20 #define CT_GIBBSEXCESSVPSSTP_H
21 
22 #include "VPStandardStateTP.h"
23 #include "cantera/base/Array.h"
24 
25 namespace Cantera
26 {
27 
28 /**
29  * @ingroup thermoprops
30  */
31 
32 /*!
33  * GibbsExcessVPSSTP is a derived class of ThermoPhase that handles
34  * variable pressure standard state methods for calculating
35  * thermodynamic properties that are further based on
36  * expressing the Excess Gibbs free energy as a function of
37  * the mole fractions (or pseudo mole fractions) of constituents.
38  * This category is the workhorse for describing molten salts,
39  * solid-phase mixtures of semiconductors, and mixtures of miscible
40  * and semi-miscible compounds.
41  *
42  * It includes
43  * - regular solutions
44  * - Margules expansions
45  * - NTRL equation
46  * - Wilson's equation
47  * - UNIQUAC equation of state.
48  *
49  * This class adds additional functions onto the ThermoPhase interface
50  * that handles the calculation of the excess Gibbs free energy. The ThermoPhase
51  * class includes a member function, ThermoPhase::activityConvention()
52  * that indicates which convention the activities are based on. The
53  * default is to assume activities are based on the molar convention.
54  * That default is used here.
55  *
56  * All of the Excess Gibbs free energy formulations in this area employ
57  * symmetrical formulations.
58  *
59  * Chemical potentials
60  * of species k, \f$ \mu_o \f$, has the following general format:
61  *
62  * \f[
63  * \mu_k = \mu^o_k(T,P) + R T ln( \gamma_k X_k )
64  * \f]
65  *
66  * where \f$ \gamma_k^{\triangle} \f$ is a molar based activity coefficient for species
67  * \f$k\f$.
68  *
69  * GibbsExcessVPSSTP contains an internal vector with the current mole
70  * fraction vector. That's one of its primary usages. In order to keep the mole fraction
71  * vector constant, all of the setState functions are redesigned at this layer.
72  *
73  * <H3>
74  * Activity Concentrations: Relationship of ThermoPhase to %Kinetics Expressions
75  * </H3>
76  *
77  * As explained in a similar discussion in the ThermoPhase class, the actual units used
78  * in kinetics expressions must be specified in the ThermoPhase class for the corresponding
79  * species. These units vary with the field of study. %Cantera uses the concept of
80  * activity concentrations to represent this. Activity concentrations are used directly
81  * in the expressions for kinetics. Standard concentrations are used as the multiplicative
82  * constant that takes the activity of a species and turns it into an activity concentration.
83  * Standard concentrations must not depend on the concentration of the species in the phase.
84  *
85  * Here we set a standard for the specification of the standard concentrations for this class
86  * and all child classes underneath it. We specify here that the standard concentration is
87  * equal to 1 for all species. Therefore, the activities appear directly in kinetics expressions
88  * involving species in underlying GibbsExcessVPSSTP phases.
89  *
90  * <H3>
91  * SetState Strategy
92  * </H3>
93  *
94  * All setState functions that set the internal state of the ThermoPhase object are
95  * overloaded at this level, so that a current mole fraction vector is maintained within
96  * the object.
97  */
99 {
100 public:
101  //! @name Constructors
102  //! @{
103  /*!
104  * This doesn't do much more than initialize constants with
105  * default values for water at 25C. Water molecular weight
106  * comes from the default elements.xml file. It actually
107  * differs slightly from the IAPWS95 value of 18.015268. However,
108  * density conservation and therefore element conservation
109  * is the more important principle to follow.
110  */
112 
113  //! Copy constructor
114  /*!
115  * @param b class to be copied
116  */
118 
119  /// Assignment operator
120  /*!
121  * @param b class to be copied.
122  */
124 
125  //! Duplication routine for objects which inherit from ThermoPhase.
126  /*!
127  * This virtual routine can be used to duplicate ThermoPhase objects
128  * inherited from ThermoPhase even if the application only has
129  * a pointer to ThermoPhase to work with.
130  */
131  virtual ThermoPhase* duplMyselfAsThermoPhase() const;
132  //! @}
133 
134  //! @}
135  //! @name Mechanical Properties
136  //! @{
137 
138  //! Set the internally stored pressure (Pa) at constant
139  //! temperature and composition
140  /*!
141  * This method sets the pressure within the object.
142  * The water model is a completely compressible model.
143  * Also, the dielectric constant is pressure dependent.
144  *
145  * @param p input Pressure (Pa)
146  *
147  * @todo Implement a variable pressure capability
148  */
149  virtual void setPressure(doublereal p);
150 
151 protected:
152  /**
153  * Calculate the density of the mixture using the partial
154  * molar volumes and mole fractions as input
155  *
156  * The formula for this is
157  *
158  * \f[
159  * \rho = \frac{\sum_k{X_k W_k}}{\sum_k{X_k V_k}}
160  * \f]
161  *
162  * where \f$X_k\f$ are the mole fractions, \f$W_k\f$ are
163  * the molecular weights, and \f$V_k\f$ are the pure species
164  * molar volumes.
165  *
166  * Note, the basis behind this formula is that in an ideal
167  * solution the partial molar volumes are equal to the pure
168  * species molar volumes. We have additionally specified
169  * in this class that the pure species molar volumes are
170  * independent of temperature and pressure.
171  *
172  * NOTE: This is a non-virtual function, which is not a
173  * member of the ThermoPhase base class.
174  */
175  void calcDensity();
176 
177 public:
178  /**
179  * @}
180  * @name Activities, Standard States, and Activity Concentrations
181  *
182  * The activity \f$a_k\f$ of a species in solution is
183  * related to the chemical potential by \f[ \mu_k = \mu_k^0(T)
184  * + \hat R T \log a_k. \f] The quantity \f$\mu_k^0(T,P)\f$ is
185  * the chemical potential at unit activity, which depends only
186  * on temperature and pressure.
187  * @{
188  */
189 
190  //! This method returns an array of generalized concentrations
191  /*!
192  * \f$ C^a_k\f$ are defined such that \f$ a_k = C^a_k /
193  * C^0_k, \f$ where \f$ C^0_k \f$ is a standard concentration
194  * defined below and \f$ a_k \f$ are activities used in the
195  * thermodynamic functions. These activity (or generalized)
196  * concentrations are used by kinetics manager classes to compute the forward and
197  * reverse rates of elementary reactions. Note that they may
198  * or may not have units of concentration --- they might be
199  * partial pressures, mole fractions, or surface coverages,
200  * for example.
201  *
202  * @param c Output array of generalized concentrations. The
203  * units depend upon the implementation of the
204  * reaction rate expressions within the phase.
205  */
206  virtual void getActivityConcentrations(doublereal* c) const;
207 
208  /**
209  * The standard concentration \f$ C^0_k \f$ used to normalize
210  * the generalized concentration. In many cases, this quantity
211  * will be the same for all species in a phase - for example,
212  * for an ideal gas \f$ C^0_k = P/\hat R T \f$. For this
213  * reason, this method returns a single value, instead of an
214  * array. However, for phases in which the standard
215  * concentration is species-specific (e.g. surface species of
216  * different sizes), this method may be called with an
217  * optional parameter indicating the species.
218  *
219  * The standard concentration for defaulted to 1. In other words
220  * the activity concentration is assumed to be 1.
221  *
222  * @param k species index. Defaults to zero.
223  */
224  virtual doublereal standardConcentration(size_t k=0) const;
225 
226  /**
227  * Returns the natural logarithm of the standard
228  * concentration of the kth species
229  *
230  * @param k species index
231  */
232  virtual doublereal logStandardConc(size_t k=0) const;
233 
234  /**
235  * Returns the units of the standard and generalized
236  * concentrations Note they have the same units, as their
237  * ratio is defined to be equal to the activity of the kth
238  * species in the solution, which is unitless.
239  *
240  * This routine is used in print out applications where the
241  * units are needed. Usually, MKS units are assumed throughout
242  * the program and in the XML input files.
243  *
244  * @param uA Output vector containing the units
245  * uA[0] = kmol units - default = 1
246  * uA[1] = m units - default = -nDim(), the number of spatial
247  * dimensions in the Phase class.
248  * uA[2] = kg units - default = 0;
249  * uA[3] = Pa(pressure) units - default = 0;
250  * uA[4] = Temperature units - default = 0;
251  * uA[5] = time units - default = 0
252  * @param k species index. Defaults to 0.
253  * @param sizeUA output int containing the size of the vector.
254  * Currently, this is equal to 6.
255  * @deprecated To be removed after Cantera 2.2.
256  */
257  virtual void getUnitsStandardConc(double* uA, int k = 0,
258  int sizeUA = 6) const;
259 
260 
261  //! Get the array of non-dimensional activities (molality
262  //! based for this class and classes that derive from it) at
263  //! the current solution temperature, pressure, and solution concentration.
264  /*!
265  * \f[
266  * a_i^\triangle = \gamma_k^{\triangle} \frac{m_k}{m^\triangle}
267  * \f]
268  *
269  * This function must be implemented in derived classes.
270  *
271  * @param ac Output vector of molality-based activities. Length: m_kk.
272  */
273  virtual void getActivities(doublereal* ac) const;
274 
275  //! Get the array of non-dimensional molar-based activity coefficients at
276  //! the current solution temperature, pressure, and solution concentration.
277  /*!
278  * @param ac Output vector of activity coefficients. Length: m_kk.
279  */
280  virtual void getActivityCoefficients(doublereal* ac) const;
281 
282  //! Get the array of temperature derivatives of the log activity coefficients
283  /*!
284  * This function is a virtual class, but it first appears in GibbsExcessVPSSTP
285  * class and derived classes from GibbsExcessVPSSTP.
286  *
287  * units = 1/Kelvin
288  *
289  * @param dlnActCoeffdT Output vector of temperature derivatives of the
290  * log Activity Coefficients. length = m_kk
291  */
292  virtual void getdlnActCoeffdT(doublereal* dlnActCoeffdT) const {
293  throw NotImplementedError("GibbsExcessVPSSTP::getdlnActCoeffdT");
294  }
295 
296  //! Get the array of derivatives of the log activity coefficients with respect to the log of the species mole numbers
297  /*!
298  * Implementations should take the derivative of the logarithm of the activity coefficient with respect to a
299  * species log mole number (with all other species mole numbers held constant). The default treatment in the
300  * ThermoPhase object is to set this vector to zero.
301  *
302  * units = 1 / kmol
303  *
304  * dlnActCoeffdlnN[ ld * k + m] will contain the derivative of log act_coeff for the <I>m</I><SUP>th</SUP>
305  * species with respect to the number of moles of the <I>k</I><SUP>th</SUP> species.
306  *
307  * \f[
308  * \frac{d \ln(\gamma_m) }{d \ln( n_k ) }\Bigg|_{n_i}
309  * \f]
310  *
311  * @param ld Number of rows in the matrix
312  * @param dlnActCoeffdlnN Output vector of derivatives of the
313  * log Activity Coefficients. length = m_kk * m_kk
314  */
315  virtual void getdlnActCoeffdlnN(const size_t ld, doublereal* const dlnActCoeffdlnN) {
316  throw NotImplementedError("GibbsExcessVPSSTP::getdlnActCoeffdlnN: "
317  "nonzero and nonimplemented");
318  }
319 
320  //! Get the array of log concentration-like derivatives of the
321  //! log activity coefficients
322  /*!
323  * This function is a virtual method. For ideal mixtures
324  * (unity activity coefficients), this can return zero.
325  * Implementations should take the derivative of the
326  * logarithm of the activity coefficient with respect to the
327  * logarithm of the concentration-like variable (i.e. number of moles in
328  * in a unit volume. ) that represents the standard state.
329  * This quantity is to be used in conjunction with derivatives of
330  * that concentration-like variable when the derivative of the chemical
331  * potential is taken.
332  *
333  * units = dimensionless
334  *
335  * @param dlnActCoeffdlnX Output vector of derivatives of the
336  * log Activity Coefficients. length = m_kk
337  */
338  virtual void getdlnActCoeffdlnX(doublereal* dlnActCoeffdlnX) const {
339  throw NotImplementedError("GibbsExcessVPSSTP::getdlnActCoeffdlnX");
340  }
341 
342  //@}
343  /// @name Partial Molar Properties of the Solution
344  //@{
345 
346  /**
347  * Get the species electrochemical potentials.
348  * These are partial molar quantities.
349  * This method adds a term \f$ Fz_k \phi_k \f$ to the
350  * to each chemical potential.
351  *
352  * Units: J/kmol
353  *
354  * @param mu output vector containing the species electrochemical potentials.
355  * Length: m_kk.
356  */
357  void getElectrochemPotentials(doublereal* mu) const;
358 
359  //! Return an array of partial molar volumes for the
360  //! species in the mixture. Units: m^3/kmol.
361  /*!
362  * Frequently, for this class of thermodynamics representations,
363  * the excess Volume due to mixing is zero. Here, we set it as
364  * a default. It may be overridden in derived classes.
365  *
366  * @param vbar Output vector of species partial molar volumes.
367  * Length = m_kk. units are m^3/kmol.
368  */
369  virtual void getPartialMolarVolumes(doublereal* vbar) const;
370  virtual const vector_fp& getPartialMolarVolumesVector() const;
371 
372  /**
373  * @}
374  * @name Setting the State
375  * These methods set all or part of the thermodynamic state.
376  * @{
377  */
378 
379  //! Set the temperature (K) and pressure (Pa)
380  /*!
381  * Set the temperature and pressure.
382  *
383  * @param t Temperature (K)
384  * @param p Pressure (Pa)
385  */
386  virtual void setState_TP(doublereal t, doublereal p);
387 
388  /**
389  * Set the mass fractions to the specified values, and then
390  * normalize them so that they sum to 1.0.
391  * @param y Array of unnormalized mass fraction values (input).
392  * Must have a length greater than or equal to the number of
393  * species.
394  *
395  * @param y Input vector of mass fractions.
396  * Length is m_kk.
397  */
398  virtual void setMassFractions(const doublereal* const y);
399 
400  /**
401  * Set the mass fractions to the specified values without
402  * normalizing. This is useful when the normalization
403  * condition is being handled by some other means, for example
404  * by a constraint equation as part of a larger set of
405  * equations.
406  *
407  * @param y Input vector of mass fractions.
408  * Length is m_kk.
409  */
410  virtual void setMassFractions_NoNorm(const doublereal* const y);
411 
412  /**
413  * Set the mole fractions to the specified values, and then
414  * normalize them so that they sum to 1.0.
415  * @param x Array of unnormalized mole fraction values (input).
416  * Must have a length greater than or equal to the number of
417  * species.
418  *
419  * @param x Input vector of mole fractions.
420  * Length is m_kk.
421  */
422  virtual void setMoleFractions(const doublereal* const x);
423 
424  /**
425  * Set the mole fractions to the specified values without
426  * normalizing. This is useful when the normalization
427  * condition is being handled by some other means, for example
428  * by a constraint equation as part of a larger set of
429  * equations.
430  *
431  * @param x Input vector of mole fractions.
432  * Length is m_kk.
433  */
434  virtual void setMoleFractions_NoNorm(const doublereal* const x);
435 
436  /**
437  * Set the concentrations to the specified values within the
438  * phase.
439  *
440  * @param c The input vector to this routine is in dimensional
441  * units. For volumetric phases c[k] is the
442  * concentration of the kth species in kmol/m3.
443  * For surface phases, c[k] is the concentration
444  * in kmol/m2. The length of the vector is the number
445  * of species in the phase.
446  */
447  virtual void setConcentrations(const doublereal* const c);
448  //@}
449 
450  /*!
451  * @internal Initialize. This method is provided to allow
452  * subclasses to perform any initialization required after all
453  * species have been added. For example, it might be used to
454  * resize internal work arrays that must have an entry for
455  * each species. The base class implementation does nothing,
456  * and subclasses that do not require initialization do not
457  * need to overload this method. When importing a CTML phase
458  * description, this method is called just prior to returning
459  * from function importPhase().
460  */
461  virtual void initThermo();
462 
463 private:
464  //! Initialize lengths of local variables after all species have
465  //! been identified.
466  void initLengths();
467 
468 protected:
469  //! utility routine to check mole fraction sum
470  /*!
471  * @param x vector of mole fractions.
472  */
473  double checkMFSum(const doublereal* const x) const;
474 
475  //! Storage for the current values of the mole fractions of the species
476  /*!
477  * This vector is kept up-to-date when the setState functions are called.
478  * Therefore, it may be considered to be an independent variable.
479  *
480  * Note in order to do this, the setState functions are redefined to always
481  * keep this vector current.
482  */
483  mutable std::vector<doublereal> moleFractions_;
484 
485  //! Storage for the current values of the activity coefficients of the
486  //! species
487  mutable std::vector<doublereal> lnActCoeff_Scaled_;
488 
489  //! Storage for the current derivative values of the
490  //! gradients with respect to temperature of the
491  //! log of the activity coefficients of the species
492  mutable std::vector<doublereal> dlnActCoeffdT_Scaled_;
493 
494  //! Storage for the current derivative values of the
495  //! gradients with respect to temperature of the
496  //! log of the activity coefficients of the species
497  mutable std::vector<doublereal> d2lnActCoeffdT2_Scaled_;
498 
499  //! Storage for the current derivative values of the
500  //! gradients with respect to logarithm of the mole fraction of the
501  //! log of the activity coefficients of the species
502  mutable std::vector<doublereal> dlnActCoeffdlnN_diag_;
503 
504  //! Storage for the current derivative values of the
505  //! gradients with respect to logarithm of the mole fraction of the
506  //! log of the activity coefficients of the species
507  mutable std::vector<doublereal> dlnActCoeffdlnX_diag_;
508 
509  //! Storage for the current derivative values of the gradients with respect to logarithm of the species mole number of the
510  //! log of the activity coefficients of the species
511  /*!
512  * dlnActCoeffdlnN_(k, m) is the derivative of ln(gamma_k) wrt ln mole number of species m
513  */
515 
516  //! Temporary storage space that is fair game
517  mutable std::vector<doublereal> m_pp;
518 };
519 
520 }
521 
522 #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 ...
std::vector< doublereal > m_pp
Temporary storage space that is fair game.
void initLengths()
Initialize lengths of local variables after all species have been identified.
GibbsExcessVPSSTP & operator=(const GibbsExcessVPSSTP &b)
Assignment operator.
An error indicating that an unimplemented function has been called.
Definition: ctexceptions.h:213
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 logStandardConc(size_t k=0) const
Returns the natural logarithm of the standard concentration of the kth species.
virtual ThermoPhase * duplMyselfAsThermoPhase() const
Duplication routine for objects which inherit from ThermoPhase.
virtual void getUnitsStandardConc(double *uA, int k=0, int sizeUA=6) const
Returns the units of the standard and generalized concentrations Note they have the same units...
virtual void getPartialMolarVolumes(doublereal *vbar) const
Return an array of partial molar volumes for the species in the mixture.
std::vector< doublereal > d2lnActCoeffdT2_Scaled_
Storage for the current derivative values of the gradients with respect to temperature of the log of ...
virtual void setState_TP(doublereal t, doublereal p)
Set the temperature (K) and pressure (Pa)
virtual doublereal standardConcentration(size_t k=0) const
The standard concentration used to normalize the generalized concentration.
std::vector< doublereal > dlnActCoeffdlnN_diag_
Storage for the current derivative values of the gradients with respect to logarithm of the mole frac...
A class for 2D arrays stored in column-major (Fortran-compatible) form.
Definition: Array.h:29
virtual void getActivityCoefficients(doublereal *ac) const
Get the array of non-dimensional molar-based activity coefficients at the current solution temperatur...
Base class for a phase with thermodynamic properties.
Definition: ThermoPhase.h:97
Header file for class Cantera::Array2D.
virtual void setConcentrations(const doublereal *const c)
Set the concentrations to the specified values within the phase.
virtual void getdlnActCoeffdT(doublereal *dlnActCoeffdT) const
Get the array of temperature derivatives of the log activity coefficients.
void calcDensity()
Calculate the density of the mixture using the partial molar volumes and mole fractions as input...
double checkMFSum(const doublereal *const x) const
utility routine to check mole fraction sum
This is a filter class for ThermoPhase that implements some prepatory steps for efficiently handling ...
void getElectrochemPotentials(doublereal *mu) const
Get the species electrochemical potentials.
virtual void setMassFractions(const doublereal *const y)
Set the mass fractions to the specified values, and then normalize them so that they sum to 1...
virtual void setMoleFractions(const doublereal *const x)
Set the mole fractions to the specified values, and then normalize them so that they sum to 1...
virtual void setMassFractions_NoNorm(const doublereal *const y)
Set the mass fractions to the specified values without normalizing.
std::vector< doublereal > dlnActCoeffdlnX_diag_
Storage for the current derivative values of the gradients with respect to logarithm of the mole frac...
virtual void getActivityConcentrations(doublereal *c) const
This method returns an array of generalized concentrations.
Header file for a derived class of ThermoPhase that handles variable pressure standard state methods ...
std::vector< doublereal > lnActCoeff_Scaled_
Storage for the current values of the activity coefficients of the species.
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
virtual void setPressure(doublereal p)
Set the internally stored pressure (Pa) at constant temperature and composition.
std::vector< doublereal > 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...
virtual void setMoleFractions_NoNorm(const doublereal *const x)
Set the mole fractions to the specified values without normalizing.
std::vector< doublereal > dlnActCoeffdT_Scaled_
Storage for the current derivative values of the gradients with respect to temperature of the log of ...
virtual void getdlnActCoeffdlnX(doublereal *dlnActCoeffdlnX) const
Get the array of log concentration-like derivatives of the log activity coefficients.