Cantera  2.1.2
MolalityVPSSTP.h
Go to the documentation of this file.
1 /**
2  * @file MolalityVPSSTP.h
3  * Header for intermediate ThermoPhase object for phases which
4  * employ molality based activity coefficient formulations
5  * (see \ref thermoprops
6  * and class \link Cantera::MolalityVPSSTP MolalityVPSSTP\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_MOLALITYVPSSTP_H
20 #define CT_MOLALITYVPSSTP_H
21 
22 #include "VPStandardStateTP.h"
23 
24 namespace Cantera
25 {
26 
27 /**
28  * @ingroup thermoprops
29  */
30 
31 /*!
32  * MolalityVPSSTP is a derived class of ThermoPhase that handles
33  * variable pressure standard state methods for calculating
34  * thermodynamic properties that are further based on
35  * molality-scaled activities.
36  * This category incorporates most of the methods
37  * for calculating liquid electrolyte thermodynamics that have been
38  * developed since the 1970's.
39  *
40  * This class adds additional functions onto the %ThermoPhase interface
41  * that handle molality based standard states. The %ThermoPhase
42  * class includes a member function, ThermoPhase::activityConvention()
43  * that indicates which convention the activities are based on. The
44  * default is to assume activities are based on the molar convention.
45  * However, classes which derive from the MolalityVPSSTP class return
46  * <b>cAC_CONVENTION_MOLALITY</b> from this member function.
47  *
48  * The molality of a solute, \f$ m_i \f$, is defined as
49  *
50  * \f[
51  * m_i = \frac{n_i}{\tilde{M}_o n_o}
52  * \f]
53  * where
54  * \f[
55  * \tilde{M}_o = \frac{M_o}{1000}
56  * \f]
57  *
58  * where \f$ M_o \f$ is the molecular weight of the solvent. The molality
59  * has units of gmol kg<SUP>-1</SUP>. For the solute, the molality may be
60  * considered as the amount of gmol's of solute per kg of solvent, a natural
61  * experimental quantity.
62  *
63  * The formulas for calculating mole fractions if given the molalities of
64  * the solutes is stated below. First calculate \f$ L^{sum} \f$, an intermediate
65  * quantity.
66  *
67  * \f[
68  * L^{sum} = \frac{1}{\tilde{M}_o X_o} = \frac{1}{\tilde{M}_o} + \sum_{i\ne o} m_i
69  * \f]
70  * Then,
71  * \f[
72  * X_o = \frac{1}{\tilde{M}_o L^{sum}}
73  * \f]
74  * \f[
75  * X_i = \frac{m_i}{L^{sum}}
76  * \f]
77  * where \f$ X_o \f$ is the mole fraction of solvent, and \f$ X_o \f$ is the
78  * mole fraction of solute <I>i</I>. Thus, the molality scale and the mole fraction
79  * scale offer a one-to-one mapping between each other, except in the limit
80  * of a zero solvent mole fraction.
81  *
82  * The standard states for thermodynamic objects that derive from <b>MolalityVPSSTP</b>
83  * are on the unit molality basis. Chemical potentials
84  * of the solutes, \f$ \mu_k \f$, and the solvent, \f$ \mu_o \f$, which are based
85  * on the molality form, have the following general format:
86  *
87  * \f[
88  * \mu_k = \mu^{\triangle}_k(T,P) + R T ln(\gamma_k^{\triangle} \frac{m_k}{m^\triangle})
89  * \f]
90  * \f[
91  * \mu_o = \mu^o_o(T,P) + RT ln(a_o)
92  * \f]
93  *
94  * where \f$ \gamma_k^{\triangle} \f$ is the molality based activity coefficient for species
95  * \f$k\f$.
96  *
97  * The chemical potential of the solvent is thus expressed in a different format
98  * than the chemical potential of the solutes. Additionally, the activity of the
99  * solvent, \f$ a_o \f$, is further reexpressed in terms of an osmotic coefficient,
100  * \f$ \phi \f$.
101  * \f[
102  * \phi = \frac{- ln(a_o)}{\tilde{M}_o \sum_{i \ne o} m_i}
103  * \f]
104  *
105  * MolalityVPSSTP::osmoticCoefficient() returns the value of \f$ \phi \f$.
106  * Note there are a few of definitions of the osmotic coefficient floating
107  * around. We use the one defined in
108  * (Activity Coefficients in Electrolyte Solutions, K. S. Pitzer
109  * CRC Press, Boca Raton, 1991, p. 85, Eqn. 28). This definition is most clearly
110  * related to theoretical calculation.
111  *
112  * The molar-based activity coefficients \f$ \gamma_k \f$ may be calculated
113  * from the molality-based
114  * activity coefficients, \f$ \gamma_k^\triangle \f$ by the following
115  * formula.
116  * \f[
117  * \gamma_k = \frac{\gamma_k^\triangle}{X_o}
118  * \f]
119  * For purposes of establishing a convention, the molar activity coefficient of the
120  * solvent is set equal to the molality-based activity coefficient of the
121  * solvent:
122  * \f[
123  * \gamma_o = \gamma_o^\triangle
124  * \f]
125  *
126  * The molality-based and molarity-based standard states may be related to one
127  * another by the following formula.
128  *
129  * \f[
130  * \mu_k^\triangle(T,P) = \mu_k^o(T,P) + R T \ln(\tilde{M}_o m^\triangle)
131  * \f]
132  *
133  * An important convention is followed in all routines that derive from <b>%MolalityVPSSTP</b>.
134  * Standard state thermodynamic functions and reference state thermodynamic functions
135  * return the molality-based quantities. Also all functions which return
136  * activities return the molality-based activities. The reason for this convention
137  * has been discussed in supporting memos. However, it's important because the
138  * term in the equation above is non-trivial. For example it's equal
139  * to 2.38 kcal gmol<SUP>-1</SUP> for water at 298 K.
140  *
141  *
142  * In order to prevent a singularity, this class includes the concept of a minimum
143  * value for the solvent mole fraction. All calculations involving the formulation
144  * of activity coefficients and other non-ideal solution behavior adhere to
145  * this concept of a minimal value for the solvent mole fraction. This makes sense
146  * because these solution behavior were all designed and measured far away from
147  * the zero solvent singularity condition and are not applicable in that limit.
148  *
149  *
150  * This objects add a layer that supports molality. It inherits from VPStandardStateTP.
151  *
152  * All objects that derive from this are assumed to have molality based standard states.
153  *
154  * Molality based activity coefficients are scaled according to the current
155  * pH scale. See the Eq3/6 manual for details.
156  *
157  * Activity coefficients for species k may be altered between scales s1 to s2
158  * using the following formula
159  *
160  * \f[
161  * ln(\gamma_k^{s2}) = ln(\gamma_k^{s1})
162  * + \frac{z_k}{z_j} \left( ln(\gamma_j^{s2}) - ln(\gamma_j^{s1}) \right)
163  * \f]
164  *
165  * where j is any one species. For the NBS scale, j is equal to the Cl- species
166  * and
167  *
168  * \f[
169  * ln(\gamma_{Cl-}^{s2}) = \frac{-A_{\phi} \sqrt{I}}{1.0 + 1.5 \sqrt{I}}
170  * \f]
171  *
172  * The Pitzer scale doesn't actually change anything. The pitzer scale is defined
173  * as the raw unscaled activity coefficients produced by the underlying objects.
174  *
175  * <H3> SetState Strategy </H3>
176  *
177  * The MolalityVPSSTP object does not have a setState strategy concerning the
178  * molalities. It does not keep track of whether the molalities have changed.
179  * It's strictly an interfacial layer that writes the current mole fractions to the
180  * State object. When molalities are needed it recalculates the molalities from
181  * the State object's mole fraction vector.
182  *
183  *
184  * @todo Make two solvent minimum fractions. One would be for calculation of the non-ideal
185  * factors. The other one would be for purposes of stoichiometry evaluation. the
186  * stoichiometry evaluation one would be a 1E-13 limit. Anything less would create
187  * problems with roundoff error.
188  */
190 {
191 public:
192  /// Default Constructor
193  /*!
194  * This doesn't do much more than initialize constants with
195  * default values for water at 25C. Water molecular weight
196  * comes from the default elements.xml file. It actually
197  * differs slightly from the IAPWS95 value of 18.015268. However,
198  * density conservation and therefore element conservation
199  * is the more important principle to follow.
200  */
201  MolalityVPSSTP();
202 
203  //! Copy constructor
204  /*!
205  * @param b class to be copied
206  */
207  MolalityVPSSTP(const MolalityVPSSTP& b);
208 
209  /// Assignment operator
210  /*!
211  * @param b class to be copied.
212  */
214 
215  //! Duplication routine for objects which inherit from ThermoPhase.
216  /*!
217  * This virtual routine can be used to duplicate objects
218  * inherited from ThermoPhase even if the application only has
219  * a pointer to ThermoPhase to work with.
220  */
221  virtual ThermoPhase* duplMyselfAsThermoPhase() const;
222 
223  //! @name Utilities
224  //! @{
225 
226  //! Equation of state type flag.
227  /*!
228  * The ThermoPhase base class returns
229  * zero. Subclasses should define this to return a unique
230  * non-zero value. Known constants defined for this purpose are
231  * listed in mix_defs.h. The MolalityVPSSTP class also returns
232  * zero, as it is a non-complete class.
233  */
234  virtual int eosType() const;
235 
236  //! Set the pH scale, which determines the scale for single-ion activity
237  //! coefficients.
238  /*!
239  * Single ion activity coefficients are not unique in terms of the
240  * representing actual measurable quantities.
241  *
242  * @param pHscaleType Integer representing the pHscale
243  */
244  void setpHScale(const int pHscaleType);
245 
246  //! Reports the pH scale, which determines the scale for single-ion activity
247  //! coefficients.
248  /*!
249  * Single ion activity coefficients are not unique in terms of the
250  * representing actual measurable quantities.
251  *
252  * @return Return the pHscale type
253  */
254  int pHScale() const;
255 
256  //! @}
257  //! @name Utilities for Solvent ID and Molality
258  //! @{
259 
260  /**
261  * This routine sets the index number of the solvent for the phase.
262  *
263  * Note, having a solvent is a precursor to many things having to do
264  * with molality.
265  *
266  * @param k the solvent index number
267  */
268  void setSolvent(size_t k);
269 
270  //! Returns the solvent index.
271  size_t solventIndex() const;
272 
273  /**
274  * Sets the minimum mole fraction in the molality formulation.
275  * Note the molality formulation is singular in the limit that
276  * the solvent mole fraction goes to zero. Numerically, how
277  * this limit is treated and resolved is an ongoing issue within
278  * Cantera. The minimum mole fraction must be in the range 0 to 0.9.
279  *
280  * @param xmolSolventMIN Input double containing the minimum mole fraction
281  */
282  void setMoleFSolventMin(doublereal xmolSolventMIN);
283 
284  //! Returns the minimum mole fraction in the molality formulation.
285  doublereal moleFSolventMin() const;
286 
287  //! Calculates the molality of all species and stores the result internally.
288  /*!
289  * We calculate the vector of molalities of the species
290  * in the phase and store the result internally:
291  * \f[
292  * m_i = \frac{X_i}{1000 * M_o * X_{o,p}}
293  * \f]
294  * where
295  * - \f$ M_o \f$ is the molecular weight of the solvent
296  * - \f$ X_o \f$ is the mole fraction of the solvent
297  * - \f$ X_i \f$ is the mole fraction of the solute.
298  * - \f$ X_{o,p} = \max (X_{o}^{min}, X_o) \f$
299  * - \f$ X_{o}^{min} \f$ = minimum mole fraction of solvent allowed
300  * in the denominator.
301  */
302  void calcMolalities() const;
303 
304  //! This function will return the molalities of the species.
305  /*!
306  * We calculate the vector of molalities of the species
307  * in the phase
308  * \f[
309  * m_i = \frac{X_i}{1000 * M_o * X_{o,p}}
310  * \f]
311  * where
312  * - \f$ M_o \f$ is the molecular weight of the solvent
313  * - \f$ X_o \f$ is the mole fraction of the solvent
314  * - \f$ X_i \f$ is the mole fraction of the solute.
315  * - \f$ X_{o,p} = \max (X_{o}^{min}, X_o) \f$
316  * - \f$ X_{o}^{min} \f$ = minimum mole fraction of solvent allowed
317  * in the denominator.
318  *
319  * @param molal Output vector of molalities. Length: m_kk.
320  */
321  void getMolalities(doublereal* const molal) const;
322 
323  //! Set the molalities of the solutes in a phase
324  /*!
325  * Note, the entry for the solvent is not used.
326  * We are supplied with the molalities of all of the
327  * solute species. We then calculate the mole fractions of all
328  * species and update the %ThermoPhase object.
329  * \f[
330  * m_i = \frac{X_i}{M_o/1000 * X_{o,p}}
331  * \f]
332  * where
333  * - \f$M_o\f$ is the molecular weight of the solvent
334  * - \f$X_o\f$ is the mole fraction of the solvent
335  * - \f$X_i\f$ is the mole fraction of the solute.
336  * - \f$X_{o,p} = \max(X_o^{min}, X_o)\f$
337  * - \f$X_o^{min}\f$ = minimum mole fraction of solvent allowed
338  * in the denominator.
339  *
340  * The formulas for calculating mole fractions are
341  * \f[
342  * L^{sum} = \frac{1}{\tilde{M}_o X_o} = \frac{1}{\tilde{M}_o} + \sum_{i\ne o} m_i
343  * \f]
344  * Then,
345  * \f[
346  * X_o = \frac{1}{\tilde{M}_o L^{sum}}
347  * \f]
348  * \f[
349  * X_i = \frac{m_i}{L^{sum}}
350  * \f]
351  * It is currently an error if the solvent mole fraction is attempted to be set
352  * to a value lower than \f$X_o^{min}\f$.
353  *
354  * @param molal Input vector of molalities. Length: m_kk.
355  */
356  void setMolalities(const doublereal* const molal);
357 
358  //! Set the molalities of a phase
359  /*!
360  * Set the molalities of the solutes in a phase. Note, the entry for the
361  * solvent is not used.
362  *
363  * @param xMap Composition Map containing the molalities.
364  */
366 
367  //! Set the molalities of a phase
368  /*!
369  * Set the molalities of the solutes in a phase. Note, the entry for the
370  * solvent is not used.
371  *
372  * @param name String containing the information for a composition map.
373  */
374  void setMolalitiesByName(const std::string& name);
375 
376  /**
377  * @}
378  * @name Activities, Standard States, and Activity Concentrations
379  *
380  * The activity \f$a_k\f$ of a species in solution is
381  * related to the chemical potential by \f[ \mu_k = \mu_k^0(T)
382  * + \hat R T \log a_k. \f] The quantity \f$\mu_k^0(T,P)\f$ is
383  * the chemical potential at unit activity, which depends only
384  * on temperature and pressure.
385  * @{
386  */
387 
388  /**
389  * This method returns the activity convention.
390  * Currently, there are two activity conventions:
391  * - Molar-based activities: %Unit activity of species at either a
392  * hypothetical pure solution of the species or at a hypothetical
393  * pure ideal solution at infinite dilution.
394  * `cAC_CONVENTION_MOLAR 0` (default)
395  * - Molality based activities: unit activity of solutes at a hypothetical
396  * 1 molal solution referenced to infinite dilution at all pressures and
397  * temperatures. The solvent is still on molar basis.
398  * `cAC_CONVENTION_MOLALITY 1`
399  *
400  * We set the convention to molality here.
401  */
402  int activityConvention() const;
403 
404  /**
405  * This method returns an array of generalized concentrations
406  * \f$ C_k\f$ that are defined such that
407  * \f$ a_k = C_k / C^0_k, \f$ where \f$ C^0_k \f$
408  * is a standard concentration
409  * defined below. These generalized concentrations are used
410  * by kinetics manager classes to compute the forward and
411  * reverse rates of elementary reactions.
412  *
413  * @param c Array of generalized concentrations. The
414  * units depend upon the implementation of the
415  * reaction rate expressions within the phase.
416  */
417  virtual void getActivityConcentrations(doublereal* c) const;
418 
419  /**
420  * The standard concentration \f$ C^0_k \f$ used to normalize
421  * the generalized concentration. In many cases, this quantity
422  * will be the same for all species in a phase - for example,
423  * for an ideal gas \f$ C^0_k = P/\hat R T \f$. For this
424  * reason, this method returns a single value, instead of an
425  * array. However, for phases in which the standard
426  * concentration is species-specific (e.g. surface species of
427  * different sizes), this method may be called with an
428  * optional parameter indicating the species.
429  *
430  * @param k species index. Defaults to zero.
431  */
432  virtual doublereal standardConcentration(size_t k=0) const;
433 
434  /**
435  * Returns the natural logarithm of the standard
436  * concentration of the kth species
437  *
438  * @param k species index
439  */
440  virtual doublereal logStandardConc(size_t k=0) const;
441 
442  /**
443  * Returns the units of the standard and generalized
444  * concentrations Note they have the same units, as their
445  * ratio is defined to be equal to the activity of the kth
446  * species in the solution, which is unitless.
447  *
448  * This routine is used in print out applications where the
449  * units are needed. Usually, MKS units are assumed throughout
450  * the program and in the XML input files.
451  *
452  * @param uA Output vector containing the units
453  * uA[0] = kmol units - default = 1
454  * uA[1] = m units - default = -nDim(), the number of spatial
455  * dimensions in the Phase class.
456  * uA[2] = kg units - default = 0;
457  * uA[3] = Pa(pressure) units - default = 0;
458  * uA[4] = Temperature units - default = 0;
459  * uA[5] = time units - default = 0
460  * @param k species index. Defaults to 0.
461  * @param sizeUA output int containing the size of the vector.
462  * Currently, this is equal to 6.
463  * @deprecated
464  */
465  virtual void getUnitsStandardConc(double* uA, int k = 0,
466  int sizeUA = 6) const;
467 
468  //! Get the array of non-dimensional activities (molality
469  //! based for this class and classes that derive from it) at
470  //! the current solution temperature, pressure, and solution concentration.
471  /*!
472  * All standard state properties for molality-based phases are
473  * evaluated consistent with the molality scale. Therefore, this function
474  * must return molality-based activities.
475  *
476  * \f[
477  * a_i^\triangle = \gamma_k^{\triangle} \frac{m_k}{m^\triangle}
478  * \f]
479  *
480  * This function must be implemented in derived classes.
481  *
482  * @param ac Output vector of molality-based activities. Length: m_kk.
483  */
484  virtual void getActivities(doublereal* ac) const;
485 
486  //! Get the array of non-dimensional activity coefficients at
487  //! the current solution temperature, pressure, and solution concentration.
488  /*!
489  * These are mole-fraction based activity coefficients. In this
490  * object, their calculation is based on translating the values
491  * of the molality-based activity coefficients.
492  * See Denbigh p. 278 for a thorough discussion.
493  *
494  * The molar-based activity coefficients \f$ \gamma_k \f$ may be calculated from the
495  * molality-based
496  * activity coefficients, \f$ \gamma_k^\triangle \f$ by the following
497  * formula.
498  * \f[
499  * \gamma_k = \frac{\gamma_k^\triangle}{X_o}
500  * \f]
501  *
502  * For purposes of establishing a convention, the molar activity coefficient of the
503  * solvent is set equal to the molality-based activity coefficient of the
504  * solvent:
505  *
506  * \f[
507  * \gamma_o = \gamma_o^\triangle
508  * \f]
509  *
510  * Derived classes don't need to overload this function. This function is
511  * handled at this level.
512  *
513  * @param ac Output vector containing the mole-fraction based activity coefficients.
514  * length: m_kk.
515  */
516  void getActivityCoefficients(doublereal* ac) const;
517 
518  //! Get the array of non-dimensional molality based
519  //! activity coefficients at the current solution temperature,
520  //! pressure, and solution concentration.
521  /*!
522  * See Denbigh p. 278 for a thorough discussion. This class must be overwritten in
523  * classes which derive from %MolalityVPSSTP. This function takes over from the
524  * molar-based activity coefficient calculation, getActivityCoefficients(), in
525  * derived classes.
526  *
527  * These molality based activity coefficients are scaled according to the current
528  * pH scale. See the Eq3/6 manual for details.
529  *
530  * Activity coefficients for species k may be altered between scales s1 to s2
531  * using the following formula
532  *
533  * \f[
534  * ln(\gamma_k^{s2}) = ln(\gamma_k^{s1})
535  * + \frac{z_k}{z_j} \left( ln(\gamma_j^{s2}) - ln(\gamma_j^{s1}) \right)
536  * \f]
537  *
538  * where j is any one species. For the NBS scale, j is equal to the Cl- species
539  * and
540  *
541  * \f[
542  * ln(\gamma_{Cl-}^{s2}) = \frac{-A_{\phi} \sqrt{I}}{1.0 + 1.5 \sqrt{I}}
543  * \f]
544  *
545  * @param acMolality Output vector containing the molality based activity coefficients.
546  * length: m_kk.
547  */
548  virtual void getMolalityActivityCoefficients(doublereal* acMolality) const;
549 
550  //! Calculate the osmotic coefficient
551  /*!
552  * \f[
553  * \phi = \frac{- ln(a_o)}{\tilde{M}_o \sum_{i \ne o} m_i}
554  * \f]
555  *
556  * Note there are a few of definitions of the osmotic coefficient floating
557  * around. We use the one defined in
558  * (Activity Coefficients in Electrolyte Solutions, K. S. Pitzer
559  * CRC Press, Boca Raton, 1991, p. 85, Eqn. 28). This definition is most clearly
560  * related to theoretical calculation.
561  *
562  * units = dimensionless
563  */
564  virtual double osmoticCoefficient() const;
565 
566  //@}
567  /// @name Partial Molar Properties of the Solution
568  //@{
569 
570  /**
571  * Get the species electrochemical potentials.
572  * These are partial molar quantities. This method adds a term
573  * \f$ Fz_k \phi_k \f$ to each chemical potential.
574  *
575  * Units: J/kmol
576  *
577  * @param mu output vector containing the species electrochemical potentials.
578  * Length: m_kk.
579  */
580  void getElectrochemPotentials(doublereal* mu) const;
581 
582  //@}
583  /**
584  * @name Chemical Equilibrium
585  * Routines that implement the Chemical equilibrium capability
586  * for a single phase, based on the element-potential method.
587  * @{
588  */
589 
590  /**
591  * This method is used by the ChemEquil element-potential
592  * based equilibrium solver.
593  * It sets the state such that the chemical potentials of the
594  * species within the current phase satisfy
595  * \f[ \frac{\mu_k}{\hat R T} = \sum_m A_{k,m}
596  * \left(\frac{\lambda_m} {\hat R T}\right) \f] where
597  * \f$ \lambda_m \f$ is the element potential of element m. The
598  * temperature is unchanged. Any phase (ideal or not) that
599  * implements this method can be equilibrated by ChemEquil.
600  *
601  * @param lambda_RT Input vector containing the dimensionless
602  * element potentials.
603  */
604  virtual void setToEquilState(const doublereal* lambda_RT);
605 
606  //@}
607 
608  //! Set equation of state parameter values from XML entries.
609  /*!
610  * This method is called by function importPhase() in
611  * file importCTML.cpp when processing a phase definition in
612  * an input file. It should be overloaded in subclasses to set
613  * any parameters that are specific to that particular phase
614  * model.
615  *
616  * The MolalityVPSSTP object defines a new method for setting
617  * the concentrations of a phase. The new method is defined by a
618  * block called "soluteMolalities". If this block
619  * is found, the concentrations within that phase are
620  * set to the "name":"molalities pairs found within that
621  * XML block. The solvent concentration is then set
622  * to everything else.
623  *
624  * The function first calls the overloaded function,
625  * VPStandardStateTP::setStateFromXML(), to pick up the parent class
626  * behavior.
627  *
628  * usage: Overloaded functions should call this function
629  * before carrying out their own behavior.
630  *
631  * @param state An XML_Node object corresponding to
632  * the "state" entry for this phase in the input file.
633  */
634  virtual void setStateFromXML(const XML_Node& state);
635 
636  //@}
637  //! @name Initialization
638  /// The following methods are used in the process of constructing
639  /// the phase and setting its parameters from a specification in an
640  /// input file. They are not normally used in application programs.
641  /// To see how they are used, see files importCTML.cpp and
642  /// ThermoFactory.cpp.
643  //@{
644 
645  virtual void initThermo();
646 
647  /**
648  * Import and initialize a ThermoPhase object
649  *
650  * @param phaseNode This object must be the phase node of a
651  * complete XML tree
652  * description of the phase, including all of the
653  * species data. In other words while "phase" must
654  * point to an XML phase object, it must have
655  * sibling nodes "speciesData" that describe
656  * the species in the phase.
657  * @param id ID of the phase. If nonnull, a check is done
658  * to see if phaseNode is pointing to the phase
659  * with the correct id.
660  */
661  void initThermoXML(XML_Node& phaseNode, const std::string& id);
662 
663  //@}
664 
665  //! Set the temperature (K), pressure (Pa), and molalities
666  //!(gmol kg-1) of the solutes
667  /*!
668  * @param t Temperature (K)
669  * @param p Pressure (Pa)
670  * @param molalities Input vector of molalities of the solutes.
671  * Length: m_kk.
672  */
673  void setState_TPM(doublereal t, doublereal p,
674  const doublereal* const molalities);
675 
676  //! Set the temperature (K), pressure (Pa), and molalities.
677  /*!
678  * @param t Temperature (K)
679  * @param p Pressure (Pa)
680  * @param m compositionMap containing the molalities
681  */
682  void setState_TPM(doublereal t, doublereal p, compositionMap& m);
683 
684  //! Set the temperature (K), pressure (Pa), and molalities.
685  /*!
686  * @param t Temperature (K)
687  * @param p Pressure (Pa)
688  * @param m String which gets translated into a composition
689  * map for the molalities of the solutes.
690  */
691  void setState_TPM(doublereal t, doublereal p, const std::string& m);
692 
693  //! Get the array of derivatives of the log activity coefficients with respect to the log of the species mole numbers
694  /*!
695  * Implementations should take the derivative of the logarithm of the activity coefficient with respect to a
696  * species log mole number (with all other species mole numbers held constant). The default treatment in the
697  * %ThermoPhase object is to set this vector to zero.
698  *
699  * units = 1 / kmol
700  *
701  * dlnActCoeffdlnN[ ld * k + m] will contain the derivative of log act_coeff for the <I>m</I><SUP>th</SUP>
702  * species with respect to the number of moles of the <I>k</I><SUP>th</SUP> species.
703  *
704  * \f[
705  * \frac{d \ln(\gamma_m) }{d \ln( n_k ) }\Bigg|_{n_i}
706  * \f]
707  *
708  * @param ld Number of rows in the matrix
709  * @param dlnActCoeffdlnN Output vector of derivatives of the
710  * log Activity Coefficients. length = m_kk * m_kk
711  */
712  virtual void getdlnActCoeffdlnN(const size_t ld, doublereal* const dlnActCoeffdlnN) {
713  getdlnActCoeffdlnN_numderiv(ld, dlnActCoeffdlnN);
714  }
715 
716  //! returns a summary of the state of the phase as a string
717  /*!
718  * @param show_thermo If true, extra information is printed out
719  * about the thermodynamic state of the system.
720  */
721  virtual std::string report(bool show_thermo = true) const;
722 
723 protected:
724 
725  virtual void getCsvReportData(std::vector<std::string>& names,
726  std::vector<vector_fp>& data) const;
727 
728  //! Get the array of unscaled non-dimensional molality based
729  //! activity coefficients at the current solution temperature,
730  //! pressure, and solution concentration.
731  /*!
732  * See Denbigh p. 278 for a thorough discussion. This class must be overwritten in
733  * classes which derive from %MolalityVPSSTP. This function takes over from the
734  * molar-based activity coefficient calculation, getActivityCoefficients(), in
735  * derived classes.
736  *
737  * @param acMolality Output vector containing the molality based activity coefficients.
738  * length: m_kk.
739  */
740  virtual void getUnscaledMolalityActivityCoefficients(doublereal* acMolality) const;
741 
742  //! Apply the current phScale to a set of activity Coefficients or activities
743  /*!
744  * See the Eq3/6 Manual for a thorough discussion.
745  *
746  * @param acMolality input/Output vector containing the molality based
747  * activity coefficients. length: m_kk.
748  */
749  virtual void applyphScale(doublereal* acMolality) const;
750 
751 private:
752  //! Returns the index of the Cl- species.
753  /*!
754  * The Cl- species is special in the sense that its single ion
755  * molality-based activity coefficient is used in the specification
756  * of the pH scale for single ions. Therefore, we need to know
757  * what species index is Cl-. If the species isn't in the species
758  * list then this routine returns -1, and we can't use the NBS
759  * pH scale.
760  *
761  * Right now we use a restrictive interpretation. The species
762  * must be named "Cl-". It must consist of exactly one Cl and one E
763  * atom.
764  */
765  virtual size_t findCLMIndex() const;
766 
767  //! Initialize lengths of local variables after all species have
768  //! been identified.
769  void initLengths();
770 
771 protected:
772 
773  //! Index of the solvent
774  /*!
775  * Currently the index of the solvent is hard-coded to the value 0
776  */
778 
779  //! Scaling to be used for output of single-ion species activity
780  //! coefficients.
781  /*!
782  * Index of the species to be used in the single-ion scaling
783  * law. This is the identity of the Cl- species for the PHSCALE_NBS
784  * scaling.
785  * Either PHSCALE_PITZER or PHSCALE_NBS
786  */
788 
789  //! Index of the phScale species
790  /*!
791  * Index of the species to be used in the single-ion scaling
792  * law. This is the identity of the Cl- species for the PHSCALE_NBS
793  * scaling
794  */
795  size_t m_indexCLM;
796 
797  //! Molecular weight of the Solvent
798  doublereal m_weightSolvent;
799 
800  /*!
801  * In any molality implementation, it makes sense to have
802  * a minimum solvent mole fraction requirement, since the
803  * implementation becomes singular in the xmolSolvent=0
804  * limit. The default is to set it to 0.01.
805  * We then modify the molality definition to ensure that
806  * molal_solvent = 0 when xmol_solvent = 0.
807  */
808  doublereal m_xmolSolventMIN;
809 
810  //! This is the multiplication factor that goes inside
811  //! log expressions involving the molalities of species.
812  /*!
813  * It's equal to Wt_0 / 1000,
814  * where Wt_0 = weight of solvent (kg/kmol)
815  */
816  doublereal m_Mnaught;
817 
818  //! Current value of the molalities of the species in the phase.
819  /*!
820  * Note this vector is a mutable quantity.
821  * units are (kg/kmol)
822  */
824 
825 private:
826  //! Error function
827  /*!
828  * Print an error string and exit
829  *
830  * @param msg Message to be printed
831  */
832  doublereal err(const std::string& msg) const;
833 
834 };
835 
836 
837 //! Scale to be used for the output of single-ion activity coefficients
838 //! is that used by Pitzer.
839 /*!
840  * This is the internal scale used within the code. One property is that
841  * the activity coefficients for the cation and anion of a single salt
842  * will be equal. This scale is the one presumed by the formulation of the
843  * single-ion activity coefficients described in this report.
844  *
845  * Activity coefficients for species k may be altered between scales s1 to s2
846  * using the following formula
847  *
848  * \f[
849  * ln(\gamma_k^{s2}) = ln(\gamma_k^{s1})
850  * + \frac{z_k}{z_j} \left( ln(\gamma_j^{s2}) - ln(\gamma_j^{s1}) \right)
851  * \f]
852  *
853  * where j is any one species.
854  */
855 const int PHSCALE_PITZER = 0;
856 
857 //! Scale to be used for evaluation of single-ion activity coefficients
858 //! is that used by the NBS standard for evaluation of the pH variable.
859 /*!
860  * This is not the internal scale used within the code.
861  *
862  * Activity coefficients for species k may be altered between scales s1 to s2
863  * using the following formula
864  *
865  * \f[
866  * ln(\gamma_k^{s2}) = ln(\gamma_k^{s1})
867  * + \frac{z_k}{z_j} \left( ln(\gamma_j^{s2}) - ln(\gamma_j^{s1}) \right)
868  * \f]
869  *
870  * where j is any one species. For the NBS scale, j is equal to the Cl- species
871  * and
872  *
873  * \f[
874  * ln(\gamma_{Cl-}^{s2}) = \frac{-A_{\phi} \sqrt{I}}{1.0 + 1.5 \sqrt{I}}
875  * \f]
876  *
877  * This is the NBS pH scale, which is used in all conventional pH
878  * measurements. and is based on the Bates-Guggenheim equations.
879  */
880 const int PHSCALE_NBS = 1;
881 
882 }
883 
884 #endif
std::map< std::string, doublereal > compositionMap
Map connecting a string name with a double.
Definition: ct_defs.h:162
virtual double osmoticCoefficient() const
Calculate the osmotic coefficient.
void initLengths()
Initialize lengths of local variables after all species have been identified.
void getElectrochemPotentials(doublereal *mu) const
Get the species electrochemical potentials.
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 ...
void setSolvent(size_t k)
This routine sets the index number of the solvent for the phase.
virtual doublereal logStandardConc(size_t k=0) const
Returns the natural logarithm of the standard concentration of the kth species.
virtual void applyphScale(doublereal *acMolality) const
Apply the current phScale to a set of activity Coefficients or activities.
doublereal m_Mnaught
This is the multiplication factor that goes inside log expressions involving the molalities of specie...
void setpHScale(const int pHscaleType)
Set the pH scale, which determines the scale for single-ion activity coefficients.
size_t m_indexCLM
Index of the phScale species.
Class XML_Node is a tree-based representation of the contents of an XML file.
Definition: xml.h:100
virtual void getUnscaledMolalityActivityCoefficients(doublereal *acMolality) const
Get the array of unscaled non-dimensional molality based activity coefficients at the current solutio...
std::string name() const
Return the name of the phase.
Definition: Phase.cpp:129
virtual int eosType() const
Equation of state type flag.
Base class for a phase with thermodynamic properties.
Definition: ThermoPhase.h:101
size_t solventIndex() const
Returns the solvent index.
doublereal err(const std::string &msg) const
Error function.
virtual void getActivities(doublereal *ac) const
Get the array of non-dimensional activities (molality based for this class and classes that derive fr...
MolalityVPSSTP & operator=(const MolalityVPSSTP &b)
Assignment operator.
virtual void getMolalityActivityCoefficients(doublereal *acMolality) const
Get the array of non-dimensional molality based activity coefficients at the current solution tempera...
virtual void setToEquilState(const doublereal *lambda_RT)
This method is used by the ChemEquil element-potential based equilibrium solver.
const int PHSCALE_NBS
Scale to be used for evaluation of single-ion activity coefficients is that used by the NBS standard ...
void setMolalitiesByName(compositionMap &xMap)
Set the molalities of a phase.
virtual void getActivityConcentrations(doublereal *c) const
This method returns an array of generalized concentrations that are defined such that where is a s...
const int PHSCALE_PITZER
Scale to be used for the output of single-ion activity coefficients is that used by Pitzer...
This is a filter class for ThermoPhase that implements some prepatory steps for efficiently handling ...
int m_pHScalingType
Scaling to be used for output of single-ion species activity coefficients.
virtual void setStateFromXML(const XML_Node &state)
Set equation of state parameter values from XML entries.
virtual size_t findCLMIndex() const
Returns the index of the Cl- species.
void setMolalities(const doublereal *const molal)
Set the molalities of the solutes in a phase.
void setState_TPM(doublereal t, doublereal p, const doublereal *const molalities)
Set the temperature (K), pressure (Pa), and molalities (gmol kg-1) of the solutes.
doublereal moleFSolventMin() const
Returns the minimum mole fraction in the molality formulation.
void getActivityCoefficients(doublereal *ac) const
Get the array of non-dimensional activity coefficients at the current solution temperature, pressure, and solution concentration.
vector_fp m_molalities
Current value of the molalities of the species in the phase.
Header file for a derived class of ThermoPhase that handles variable pressure standard state methods ...
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:165
virtual void initThermo()
Initialize the ThermoPhase object after all species have been set up.
virtual void getCsvReportData(std::vector< std::string > &names, std::vector< vector_fp > &data) const
Fills names and data with the column names and species thermo properties to be included in the output...
void getMolalities(doublereal *const molal) const
This function will return the molalities of the species.
doublereal m_weightSolvent
Molecular weight of the Solvent.
void initThermoXML(XML_Node &phaseNode, const std::string &id)
Import and initialize a ThermoPhase object.
int activityConvention() const
This method returns the activity convention.
int pHScale() const
Reports the pH scale, which determines the scale for single-ion activity coefficients.
size_t m_indexSolvent
Index of the solvent.
virtual std::string report(bool show_thermo=true) const
returns a summary of the state of the phase as a string
virtual ThermoPhase * duplMyselfAsThermoPhase() const
Duplication routine for objects which inherit from ThermoPhase.
MolalityVPSSTP()
Default Constructor.
void calcMolalities() const
Calculates the molality of all species and stores the result internally.
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...
void setMoleFSolventMin(doublereal xmolSolventMIN)
Sets the minimum mole fraction in the molality formulation.
virtual doublereal standardConcentration(size_t k=0) const
The standard concentration used to normalize the generalized concentration.