Cantera  2.0
ThermoPhase.h
Go to the documentation of this file.
1 /**
2  * @file ThermoPhase.h
3  * Header file for class ThermoPhase, the base class for phases with
4  * thermodynamic properties, and the text for the Module thermoprops
5  * (see \ref thermoprops and class \link Cantera::ThermoPhase
6  * ThermoPhase\endlink).
7  */
8 
9 // Copyright 2002 California Institute of Technology
10 
11 #ifndef CT_THERMOPHASE_H
12 #define CT_THERMOPHASE_H
13 
14 #include "Phase.h"
15 #include "SpeciesThermo.h"
16 
17 namespace Cantera
18 {
19 
20 /*!
21  * @name CONSTANTS - Specification of the Molality convention
22  */
23 //@{
24 //! Standard state uses the molar convention
25 const int cAC_CONVENTION_MOLAR = 0;
26 //! Standard state uses the molality convention
28 //@}
29 
30 /*!
31  * @name CONSTANTS - Specification of the SS convention
32  */
33 //@{
34 //! Standard state uses the molar convention
36 //! Standard state uses the molality convention
37 const int cSS_CONVENTION_VPSS = 1;
38 //! Standard state thermodynamics is obtained from slave %ThermoPhase objects
39 const int cSS_CONVENTION_SLAVE = 2;
40 //@}
41 
42 class XML_Node;
43 
44 //! Base class for a phase with thermodynamic properties.
45 /*!
46  * Class %ThermoPhase is the base class for the family of classes
47  * that represent phases of matter of any type. It defines a
48  * common public interface, and implements a few methods. Most of
49  * the methods, however, are declared virtual and are meant to be
50  * overloaded in derived classes. The standard way used
51  * throughout Cantera to compute properties of phases of matter is
52  * through pointers of type ThermoPhase* that point to objects of
53  * subclasses of ThermoPhase.
54  *
55  * Class %ThermoPhase extends class Phase by adding methods to compute
56  * thermodynamic
57  * properties in addition to the ones (temperature, density,
58  * composition) that class Phase provides. The distinction is that
59  * the methods declared in ThermoPhase require knowing the
60  * particular equation of state of the phase of interest, while
61  * those of class Phase do not, since they only involve data values
62  * stored within the object.
63  *
64  * Instances of subclasses of %ThermoPhase should be created using
65  * the factory class ThermoFactory, not by calling the constructor
66  * directly. This allows new classes to be used with the various
67  * Cantera language interfaces.
68  *
69  * To implement a new equation of state, derive a class from
70  * ThermoPhase and overload the virtual methods in
71  * ThermoPhase. Methods that are not needed can be left
72  * unimplemented, which will cause an exception to be thrown if it
73  * is called.
74  *
75  * Relationship with the kinetics operator:
76  *
77  * Describe activity coefficients.
78  *
79  * Describe K_a, K_p, and K_c, These are three different equilibrium
80  * constants.
81  *
82  * K_a is the calculation of the equilibrium constant from the
83  * standard state Gibbs free energy values. It is by definition
84  * dimensionless.
85  *
86  * K_p is the calculation of the equilibrium constant from the
87  * reference state gibbs free energy values. It is by definition
88  * dimensionless. The pressure dependence is handled entirely
89  * on the rhs of the equilibrium expression.
90  *
91  * K_c is the equilibrium constant calculated from the
92  * activity concentrations. The dimensions depend on the number
93  * of products and reactants.
94  *
95  *
96  * The kinetics manager requires the calculation of K_c for the
97  * calculation of the reverse rate constant
98  *
99  *
100  * @ingroup thermoprops
101  * @ingroup phases
102  */
103 class ThermoPhase : public Phase
104 {
105 
106 public:
107 
108  //! Constructor. Note that ThermoPhase is meant to be used as
109  //! a base class, so this constructor should not be called
110  //! explicitly.
111  ThermoPhase();
112 
113  //! Destructor. Deletes the species thermo manager.
114  virtual ~ThermoPhase();
115 
116  //!Copy Constructor for the %ThermoPhase object.
117  /*!
118  * @param right ThermoPhase to be copied
119  */
120  ThermoPhase(const ThermoPhase& right);
121 
122  //! Assignment operator
123  /*!
124  * This is NOT a virtual function.
125  *
126  * @param right Reference to %ThermoPhase object to be copied into the
127  * current one.
128  */
129  ThermoPhase& operator=(const ThermoPhase& right);
130 
131  //! Duplication routine for objects which inherit from
132  //! ThermoPhase.
133  /*!
134  * This virtual routine can be used to duplicate %ThermoPhase objects
135  * inherited from %ThermoPhase even if the application only has
136  * a pointer to %ThermoPhase to work with.
137  *
138  * These routines are basically wrappers around the derived copy
139  * constructor.
140  */
141  virtual ThermoPhase* duplMyselfAsThermoPhase() const;
142 
143  /**
144  *
145  * @name Information Methods
146  * @{
147  */
148 
149  //! Equation of state type flag.
150  /*!
151  * The base class returns
152  * zero. Subclasses should define this to return a unique
153  * non-zero value. Constants defined for this purpose are
154  * listed in mix_defs.h.
155  */
156  virtual int eosType() const {
157  return 0;
158  }
159 
160  /**
161  * Returns the reference pressure in Pa. This function is a wrapper
162  * that calls the species thermo refPressure function.
163  */
164  virtual doublereal refPressure() const {
165  return m_spthermo->refPressure();
166  }
167 
168 
169  //! Minimum temperature for which the thermodynamic data for the species
170  //! or phase are valid.
171  /*!
172  * If no argument is supplied, the
173  * value returned will be the lowest temperature at which the
174  * data for \e all species are valid. Otherwise, the value
175  * will be only for species \a k. This function is a wrapper
176  * that calls the species thermo minTemp function.
177  *
178  * @param k index of the species. Default is -1, which will return the max of the min value
179  * over all species.
180  */
181  virtual doublereal minTemp(size_t k = npos) const {
182  return m_spthermo->minTemp(k);
183  }
184 
185 #ifdef H298MODIFY_CAPABILITY
186 
187  //! Report the 298 K Heat of Formation of the standard state of one species (J kmol-1)
188  /*!
189  * The 298K Heat of Formation is defined as the enthalpy change to create the standard state
190  * of the species from its constituent elements in their standard states at 298 K and 1 bar.
191  *
192  * @param k species index
193  * @return Returns the current value of the Heat of Formation at 298K and 1 bar
194  */
195  doublereal Hf298SS(const int k) const {
196  return (m_spthermo->reportOneHf298(k));
197  }
198 
199  //! Modify the value of the 298 K Heat of Formation of one species in the phase (J kmol-1)
200  /*!
201  * The 298K heat of formation is defined as the enthalpy change to create the standard state
202  * of the species from its constituent elements in their standard states at 298 K and 1 bar.
203  *
204  * @param k Species k
205  * @param Hf298New Specify the new value of the Heat of Formation at 298K and 1 bar
206  */
207  virtual void modifyOneHf298SS(const int k, const doublereal Hf298New) {
208  m_spthermo->modifyOneHf298(k, Hf298New);
209  }
210 
211 #else
212 
213  //! Report the 298 K Heat of Formation of the standard state of one species (J kmol-1)
214  /*!
215  * The 298K Heat of Formation is defined as the enthalpy change to create the standard state
216  * of the species from its constituent elements in their standard states at 298 K and 1 bar.
217  *
218  * @param k species index
219  * @return Returns the current value of the Heat of Formation at 298K and 1 bar
220  */
221  doublereal Hf298SS(const int k) const {
222  return err("Hf298SS - H298MODIFY_CAPABILITY not compiled in");
223  }
224 
225  //! Modify the value of the 298 K Heat of Formation of one species in the phase (J kmol-1)
226  /*!
227  * The 298K heat of formation is defined as the enthalpy change to create the standard state
228  * of the species from its constituent elements in their standard states at 298 K and 1 bar.
229  *
230  * @param k Species k
231  * @param Hf298New Specify the new value of the Heat of Formation at 298K and 1 bar
232  */
233  virtual void modifyOneHf298SS(const int k, const doublereal Hf298New) {
234  (void) err("Hf298SS - H298MODIFY_CAPABILITY not compiled in");
235  }
236 #endif
237 
238  //! Maximum temperature for which the thermodynamic data for the species
239  //! are valid.
240  /*!
241  * If no argument is supplied, the
242  * value returned will be the highest temperature at which the
243  * data for \e all species are valid. Otherwise, the value
244  * will be only for species \a k. This function is a wrapper
245  * that calls the species thermo maxTemp function.
246  *
247  * @param k index of the species. Default is -1, which will return the min of the max value
248  * over all species.
249  */
250  virtual doublereal maxTemp(size_t k = npos) const {
251  return m_spthermo->maxTemp(k);
252  }
253 
254  //! Returns the chargeNeutralityNecessity boolean
255  /*!
256  * Some phases must have zero net charge in order for their thermodynamics functions to be valid.
257  * If this is so, then the value returned from this function is true.
258  * If this is not the case, then this is false. Now, ideal gases have this parameter set to false,
259  * while solution with molality-based activity coefficients have this parameter set to true.
260  */
263  }
264 
265  /**
266  * @}
267  * @name Molar Thermodynamic Properties of the Solution
268  * @{
269  */
270 
271  /// Molar enthalpy. Units: J/kmol.
272  virtual doublereal enthalpy_mole() const {
273  return err("enthalpy_mole");
274  }
275 
276  /// Molar internal energy. Units: J/kmol.
277  virtual doublereal intEnergy_mole() const {
278  return enthalpy_mole() - pressure()* molarVolume();
279  }
280 
281  /// Molar entropy. Units: J/kmol/K.
282  virtual doublereal entropy_mole() const {
283  return err("entropy_mole");
284  }
285 
286  /// Molar Gibbs function. Units: J/kmol.
287  virtual doublereal gibbs_mole() const {
288  return enthalpy_mole() - temperature()*entropy_mole();
289  }
290 
291  /// Molar heat capacity at constant pressure. Units: J/kmol/K.
292  virtual doublereal cp_mole() const {
293  return err("cp_mole");
294  }
295 
296  /// Molar heat capacity at constant volume. Units: J/kmol/K.
297  virtual doublereal cv_mole() const {
298  return err("cv_mole");
299  }
300 
301 
302  /**
303  * @}
304  * @name Mechanical Properties
305  * @{
306  */
307 
308  //! Return the thermodynamic pressure (Pa).
309  /*!
310  * This method must be overloaded in derived classes. Since the
311  * mass density, temperature, and mass fractions are stored,
312  * this method should use these values to implement the
313  * mechanical equation of state \f$ P(T, \rho, Y_1, \dots,
314  * Y_K) \f$.
315  */
316  virtual doublereal pressure() const {
317  return err("pressure");
318  }
319 
320  //! Set the internally stored pressure (Pa) at constant
321  //! temperature and composition
322  /*!
323  * This method must be reimplemented in derived classes, where it
324  * may involve the solution of a nonlinear equation. Within %Cantera,
325  * the independent variable is the density. Therefore, this function
326  * solves for the density that will yield the desired input pressure.
327  * The temperature and composition iare held constant during this process.
328  *
329  * This base class function will print an error, if not overwritten.
330  *
331  * @param p input Pressure (Pa)
332  */
333  virtual void setPressure(doublereal p) {
334  err("setPressure");
335  }
336 
337  //! Returns the isothermal compressibility. Units: 1/Pa.
338  /*!
339  * The isothermal compressibility is defined as
340  * \f[
341  * \kappa_T = -\frac{1}{v}\left(\frac{\partial v}{\partial P}\right)_T
342  * \f]
343  * or
344  * \f[
345  * \kappa_T = \frac{1}{\rho}\left(\frac{\partial \rho}{\partial P}\right)_T
346  * \f]
347  */
348  virtual doublereal isothermalCompressibility() const {
349  err("isothermalCompressibility");
350  return -1.0;
351  }
352 
353  //! Return the volumetric thermal expansion coefficient. Units: 1/K.
354  /*!
355  * The thermal expansion coefficient is defined as
356  * \f[
357  * \beta = \frac{1}{v}\left(\frac{\partial v}{\partial T}\right)_P
358  * \f]
359  */
360  virtual doublereal thermalExpansionCoeff() const {
361  err("thermalExpansionCoeff()");
362  return -1.0;
363  }
364 
365  /// @deprecated
366  virtual void updateDensity() {
367  deprecatedMethod("ThermoPhase","updateDensity","");
368  }
369 
370  /**
371  * @}
372  * @name Electric Potential
373  *
374  * The phase may be at some non-zero electrical
375  * potential. These methods set or get the value of the
376  * electric potential.
377  */
378  //@{
379 
380  //! Set the electric potential of this phase (V).
381  /*!
382  * This is used by classes InterfaceKinetics and EdgeKinetics to
383  * compute the rates of charge-transfer reactions, and in computing
384  * the electrochemical potentials of the species.
385  *
386  * Each phase may have its own electric potential.
387  *
388  * @param v Input value of the electric potential in Volts
389  */
390  void setElectricPotential(doublereal v) {
391  m_phi = v;
392  }
393 
394  //! Returns the electric potential of this phase (V).
395  /*!
396  * Units are Volts (which are Joules/coulomb)
397  */
398  doublereal electricPotential() const {
399  return m_phi;
400  }
401 
402  /**
403  * @}
404  * @name Activities, Standard States, and Activity Concentrations
405  *
406  * The activity \f$a_k\f$ of a species in solution is related
407  * to the chemical potential by \f[ \mu_k = \mu_k^0(T,P) +
408  * \hat R T \log a_k. \f] The quantity \f$\mu_k^0(T,P)\f$ is
409  * the standard chemical potential at unit activity,
410  * which depends on temperature and pressure,
411  * but not on composition. The
412  * activity is dimensionless.
413  * @{
414  */
415 
416 
417  //! This method returns the convention used in specification
418  //! of the activities, of which there are currently two, molar-
419  //! and molality-based conventions.
420  /*!
421  * Currently, there are two activity conventions:
422  * - Molar-based activities
423  * %Unit activity of species at either a hypothetical pure
424  * solution of the species or at a hypothetical
425  * pure ideal solution at infinite dilution
426  * cAC_CONVENTION_MOLAR 0
427  * - default
428  *
429  * - Molality-based activities
430  * (unit activity of solutes at a hypothetical 1 molal
431  * solution referenced to infinite dilution at all
432  * pressures and temperatures).
433  * cAC_CONVENTION_MOLALITY 1
434  */
435  virtual int activityConvention() const;
436 
437  //! This method returns the convention used in specification
438  //! of the standard state, of which there are currently two,
439  //! temperature based, and variable pressure based.
440  /*!
441  * Currently, there are two standard state conventions:
442  * - Temperature-based activities
443  * cSS_CONVENTION_TEMPERATURE 0
444  * - default
445  *
446  * - Variable Pressure and Temperature -based activities
447  * cSS_CONVENTION_VPSS 1
448  *
449  * - Thermodynamics is set via slave ThermoPhase objects with
450  * nothing being carried out at this %ThermoPhase object level
451  * cSS_CONVENTION_SLAVE 2
452  */
453  virtual int standardStateConvention() const;
454 
455  //! This method returns an array of generalized concentrations
456  /*!
457  * \f$ C^a_k\f$ are defined such that \f$ a_k = C^a_k /
458  * C^0_k, \f$ where \f$ C^0_k \f$ is a standard concentration
459  * defined below and \f$ a_k \f$ are activities used in the
460  * thermodynamic functions. These activity (or generalized)
461  * concentrations are used
462  * by kinetics manager classes to compute the forward and
463  * reverse rates of elementary reactions. Note that they may
464  * or may not have units of concentration --- they might be
465  * partial pressures, mole fractions, or surface coverages,
466  * for example.
467  *
468  * @param c Output array of generalized concentrations. The
469  * units depend upon the implementation of the
470  * reaction rate expressions within the phase.
471  */
472  virtual void getActivityConcentrations(doublereal* c) const {
473  err("getActivityConcentrations");
474  }
475 
476  //! Return the standard concentration for the kth species
477  /*!
478  * The standard concentration \f$ C^0_k \f$ used to normalize
479  * the activity (i.e., generalized) concentration. In many cases, this quantity
480  * will be the same for all species in a phase - for example,
481  * for an ideal gas \f$ C^0_k = P/\hat R T \f$. For this
482  * reason, this method returns a single value, instead of an
483  * array. However, for phases in which the standard
484  * concentration is species-specific (e.g. surface species of
485  * different sizes), this method may be called with an
486  * optional parameter indicating the species.
487  *
488  * @param k Optional parameter indicating the species. The default
489  * is to assume this refers to species 0.
490  * @return
491  * Returns the standard concentration. The units are by definition
492  * dependent on the ThermoPhase and kinetics manager representation.
493  */
494  virtual doublereal standardConcentration(size_t k=0) const {
495  err("standardConcentration");
496  return -1.0;
497  }
498 
499  //! Natural logarithm of the standard concentration of the kth species.
500  /*!
501  * @param k index of the species (defaults to zero)
502  */
503  virtual doublereal logStandardConc(size_t k=0) const;
504 
505  //! Returns the units of the standard and generalized concentrations.
506  /*!
507  * Note they have the same units, as their
508  * ratio is defined to be equal to the activity of the kth
509  * species in the solution, which is unitless.
510  *
511  * This routine is used in print out applications where the
512  * units are needed. Usually, MKS units are assumed throughout
513  * the program and in the XML input files.
514  *
515  * The base %ThermoPhase class assigns the default quantities
516  * of (kmol/m3) for all species.
517  * Inherited classes are responsible for overriding the default
518  * values if necessary.
519  *
520  * @param uA Output vector containing the units
521  * uA[0] = kmol units - default = 1
522  * uA[1] = m units - default = -nDim(), the number of spatial
523  * dimensions in the Phase class.
524  * uA[2] = kg units - default = 0;
525  * uA[3] = Pa(pressure) units - default = 0;
526  * uA[4] = Temperature units - default = 0;
527  * uA[5] = time units - default = 0
528  * @param k species index. Defaults to 0.
529  * @param sizeUA output int containing the size of the vector.
530  * Currently, this is equal to 6.
531  */
532  virtual void getUnitsStandardConc(double* uA, int k = 0,
533  int sizeUA = 6) const;
534 
535  //! Get the array of non-dimensional activities at
536  //! the current solution temperature, pressure, and solution concentration.
537  /*!
538  * Note, for molality based formulations, this returns the
539  * molality based activities.
540  *
541  * We resolve this function at this level by calling
542  * on the activityConcentration function. However,
543  * derived classes may want to override this default
544  * implementation.
545  *
546  * @param a Output vector of activities. Length: m_kk.
547  */
548  virtual void getActivities(doublereal* a) const;
549 
550  //! Get the array of non-dimensional molar-based activity coefficients at
551  //! the current solution temperature, pressure, and solution concentration.
552  /*!
553  * @param ac Output vector of activity coefficients. Length: m_kk.
554  */
555  virtual void getActivityCoefficients(doublereal* ac) const {
556  if (m_kk == 1) {
557  ac[0] = 1.0;
558  } else {
559  err("getActivityCoefficients");
560  }
561  }
562 
563  //! Get the array of non-dimensional molar-based ln activity coefficients at
564  //! the current solution temperature, pressure, and solution concentration.
565  /*!
566  * @param lnac Output vector of ln activity coefficients. Length: m_kk.
567  */
568  virtual void getLnActivityCoefficients(doublereal* lnac) const;
569 
570  //@}
571  /// @name Partial Molar Properties of the Solution
572  //@{
573 
574  /**
575  * Get the array of non-dimensional species chemical potentials
576  * These are partial molar Gibbs free energies.
577  * \f$ \mu_k / \hat R T \f$.
578  * Units: unitless
579  *
580  * @param mu Output vector of dimensionless chemical potentials.
581  * Length: m_kk.
582  */
583  virtual void getChemPotentials_RT(doublereal* mu) const {
584  err("getChemPotentials_RT");
585  }
586 
587 
588  //! Get the species chemical potentials. Units: J/kmol.
589  /*!
590  * This function returns a vector of chemical potentials of the
591  * species in solution at the current temperature, pressure
592  * and mole fraction of the solution.
593  *
594  * @param mu Output vector of species chemical
595  * potentials. Length: m_kk. Units: J/kmol
596  */
597  virtual void getChemPotentials(doublereal* mu) const {
598  err("getChemPotentials");
599  }
600 
601  //! Get the species electrochemical potentials.
602  /*!
603  * These are partial molar quantities. This method adds a term \f$ F z_k
604  * \phi_p \f$ to each chemical potential.
605  * The electrochemical potential of species k in a phase p, \f$ \zeta_k \f$,
606  * is related to the chemical potential via
607  * the following equation,
608  *
609  * \f[
610  * \zeta_{k}(T,P) = \mu_{k}(T,P) + F z_k \phi_p
611  * \f]
612  *
613  * @param mu Output vector of species electrochemical
614  * potentials. Length: m_kk. Units: J/kmol
615  */
616  void getElectrochemPotentials(doublereal* mu) const {
617  getChemPotentials(mu);
618  double ve = Faraday * electricPotential();
619  for (size_t k = 0; k < m_kk; k++) {
620  mu[k] += ve*charge(k);
621  }
622  }
623 
624  //! Returns an array of partial molar enthalpies for the species
625  //! in the mixture. Units (J/kmol)
626  /*!
627  * @param hbar Output vector of species partial molar enthalpies.
628  * Length: m_kk. units are J/kmol.
629  */
630  virtual void getPartialMolarEnthalpies(doublereal* hbar) const {
631  err("getPartialMolarEnthalpies");
632  }
633 
634  //! Returns an array of partial molar entropies of the species in the
635  //! solution. Units: J/kmol/K.
636  /*!
637  * @param sbar Output vector of species partial molar entropies.
638  * Length = m_kk. units are J/kmol/K.
639  */
640  virtual void getPartialMolarEntropies(doublereal* sbar) const {
641  err("getPartialMolarEntropies");
642  }
643 
644  //! Return an array of partial molar internal energies for the
645  //! species in the mixture. Units: J/kmol.
646  /*!
647  * @param ubar Output vector of species partial molar internal energies.
648  * Length = m_kk. units are J/kmol.
649  */
650  virtual void getPartialMolarIntEnergies(doublereal* ubar) const {
651  err("getPartialMolarIntEnergies");
652  }
653 
654  //! Return an array of partial molar heat capacities for the
655  //! species in the mixture. Units: J/kmol/K
656  /*!
657  * @param cpbar Output vector of species partial molar heat
658  * capacities at constant pressure.
659  * Length = m_kk. units are J/kmol/K.
660  */
661  virtual void getPartialMolarCp(doublereal* cpbar) const {
662  err("getPartialMolarCp");
663  }
664 
665  //! Return an array of partial molar volumes for the
666  //! species in the mixture. Units: m^3/kmol.
667  /*!
668  * @param vbar Output vector of species partial molar volumes.
669  * Length = m_kk. units are m^3/kmol.
670  */
671  virtual void getPartialMolarVolumes(doublereal* vbar) const {
672  err("getPartialMolarVolumes");
673  }
674 
675  //! Return an array of derivatives of partial molar volumes wrt temperature for the
676  //! species in the mixture. Units: m^3/kmol.
677  /*!
678  * The derivative is at constant pressure
679  *
680  * @param d_vbar_dT Output vector of derivatives of species partial molar volumes wrt T.
681  * Length = m_kk. units are m^3/kmol/K.
682  */
683  virtual void getdPartialMolarVolumes_dT(doublereal* d_vbar_dT) const {
684  err("getdPartialMolarVolumes_dT");
685  }
686 
687  //! Return an array of derivatives of partial molar volumes wrt pressure for the
688  //! species in the mixture. Units: m^3/kmol.
689  /*!
690  * The derivative is at constant temperature
691  *
692  * @param d_vbar_dP Output vector of derivatives of species partial molar volumes wrt P.
693  * Length = m_kk. units are m^3/kmol/Pa.
694  */
695  virtual void getdPartialMolarVolumes_dP(doublereal* d_vbar_dP) const {
696  err("getdPartialMolarVolumes_dP");
697  }
698 
699  //@}
700  /// @name Properties of the Standard State of the Species in the Solution
701  //@{
702 
703  //! Get the array of chemical potentials at unit activity for the species
704  //! at their standard states at the current <I>T</I> and <I>P</I> of the solution.
705  /*!
706  * These are the standard state chemical potentials \f$ \mu^0_k(T,P)
707  * \f$. The values are evaluated at the current
708  * temperature and pressure of the solution
709  *
710  * @param mu Output vector of chemical potentials.
711  * Length: m_kk.
712  */
713  virtual void getStandardChemPotentials(doublereal* mu) const {
714  err("getStandardChemPotentials");
715  }
716 
717  //! Get the nondimensional Enthalpy functions for the species
718  //! at their standard states at the current <I>T</I> and <I>P</I> of the solution.
719  /*!
720  * @param hrt Output vector of nondimensional standard state enthalpies.
721  * Length: m_kk.
722  */
723  virtual void getEnthalpy_RT(doublereal* hrt) const {
724  err("getEnthalpy_RT");
725  }
726 
727  //! Get the array of nondimensional Entropy functions for the
728  //! standard state species at the current <I>T</I> and <I>P</I> of the solution.
729  /*!
730  * @param sr Output vector of nondimensional standard state entropies.
731  * Length: m_kk.
732  */
733  virtual void getEntropy_R(doublereal* sr) const {
734  err("getEntropy_R");
735  }
736 
737  //! Get the nondimensional Gibbs functions for the species
738  //! in their standard states at the current <I>T</I> and <I>P</I> of the solution.
739  /*!
740  * @param grt Output vector of nondimensional standard state gibbs free energies
741  * Length: m_kk.
742  */
743  virtual void getGibbs_RT(doublereal* grt) const {
744  err("getGibbs_RT");
745  }
746 
747  //! Get the Gibbs functions for the standard
748  //! state of the species at the current <I>T</I> and <I>P</I> of the solution
749  /*!
750  * Units are Joules/kmol
751  * @param gpure Output vector of standard state gibbs free energies
752  * Length: m_kk.
753  */
754  virtual void getPureGibbs(doublereal* gpure) const {
755  err("getPureGibbs");
756  }
757 
758  //! Returns the vector of nondimensional Internal Energies of the standard
759  //! state species at the current <I>T</I> and <I>P</I> of the solution
760  /*!
761  * @param urt output vector of nondimensional standard state internal energies
762  * of the species. Length: m_kk.
763  */
764  virtual void getIntEnergy_RT(doublereal* urt) const {
765  err("getIntEnergy_RT");
766  }
767 
768  //! Get the nondimensional Heat Capacities at constant
769  //! pressure for the species standard states
770  //! at the current <I>T</I> and <I>P</I> of the solution
771  /*!
772  * @param cpr Output vector of nondimensional standard state heat capacities
773  * Length: m_kk.
774  */
775  virtual void getCp_R(doublereal* cpr) const {
776  err("getCp_R");
777  }
778 
779  //! Get the molar volumes of the species standard states at the current
780  //! <I>T</I> and <I>P</I> of the solution.
781  /*!
782  * units = m^3 / kmol
783  *
784  * @param vol Output vector containing the standard state volumes.
785  * Length: m_kk.
786  */
787  virtual void getStandardVolumes(doublereal* vol) const {
788  err("getStandardVolumes");
789  }
790 
791  //! Get the derivative of the molar volumes of the species standard states wrt temperature at the current
792  //! <I>T</I> and <I>P</I> of the solution.
793  /*!
794  * The derivative is at constant pressure
795  * units = m^3 / kmol / K
796  *
797  * @param d_vol_dT Output vector containing derivatives of standard state volumes wrt T
798  * Length: m_kk.
799  */
800  virtual void getdStandardVolumes_dT(doublereal* d_vol_dT) const {
801  err("getdStandardVolumes_dT");
802  }
803 
804  //! Get the derivative molar volumes of the species standard states wrt pressure at the current
805  //! <I>T</I> and <I>P</I> of the solution.
806  /*!
807  * The derivative is at constant temperature.
808  * units = m^3 / kmol / Pa
809  *
810  * @param d_vol_dP Output vector containing the derivative of standard state volumes wrt P.
811  * Length: m_kk.
812  */
813  virtual void getdStandardVolumes_dP(doublereal* d_vol_dP) const {
814  err("getdStandardVolumes_dP");
815  }
816 
817  //@}
818  /// @name Thermodynamic Values for the Species Reference States
819  //@{
820 
821  //! Returns the vector of nondimensional
822  //! enthalpies of the reference state at the current temperature
823  //! of the solution and the reference pressure for the species.
824  /*!
825  * This base function will throw a CanteraException unless
826  * it is overwritten in a derived class.
827  *
828  * @param hrt Output vector containing the nondimensional reference state
829  * enthalpies
830  * Length: m_kk.
831  */
832  virtual void getEnthalpy_RT_ref(doublereal* hrt) const {
833  err("getEnthalpy_RT_ref");
834  }
835 
836  //! Returns the vector of nondimensional
837  //! Gibbs Free Energies of the reference state at the current temperature
838  //! of the solution and the reference pressure for the species.
839  /*!
840  * @param grt Output vector containing the nondimensional reference state
841  * Gibbs Free energies. Length: m_kk.
842  */
843  virtual void getGibbs_RT_ref(doublereal* grt) const {
844  err("getGibbs_RT_ref");
845  }
846 
847  //! Returns the vector of the
848  //! gibbs function of the reference state at the current temperature
849  //! of the solution and the reference pressure for the species.
850  /*!
851  * units = J/kmol
852  *
853  * @param g Output vector containing the reference state
854  * Gibbs Free energies. Length: m_kk. Units: J/kmol.
855  */
856  virtual void getGibbs_ref(doublereal* g) const {
857  err("getGibbs_ref");
858  }
859 
860  //! Returns the vector of nondimensional
861  //! entropies of the reference state at the current temperature
862  //! of the solution and the reference pressure for each species.
863  /*!
864  * @param er Output vector containing the nondimensional reference state
865  * entropies. Length: m_kk.
866  */
867  virtual void getEntropy_R_ref(doublereal* er) const {
868  err("getEntropy_R_ref");
869  }
870 
871  //! Returns the vector of nondimensional
872  //! internal Energies of the reference state at the current temperature
873  //! of the solution and the reference pressure for each species.
874  /*!
875  * @param urt Output vector of nondimensional reference state
876  * internal energies of the species.
877  * Length: m_kk
878  */
879  virtual void getIntEnergy_RT_ref(doublereal* urt) const {
880  err("getIntEnergy_RT_ref");
881  }
882 
883  //! Returns the vector of nondimensional
884  //! constant pressure heat capacities of the reference state
885  //! at the current temperature of the solution
886  //! and reference pressure for each species.
887  /*!
888  * @param cprt Output vector of nondimensional reference state
889  * heat capacities at constant pressure for the species.
890  * Length: m_kk
891  */
892  virtual void getCp_R_ref(doublereal* cprt) const {
893  err("getCp_R_ref()");
894  }
895 
896  //! Get the molar volumes of the species reference states at the current
897  //! <I>T</I> and <I>P_ref</I> of the solution.
898  /*!
899  * units = m^3 / kmol
900  *
901  * @param vol Output vector containing the standard state volumes.
902  * Length: m_kk.
903  */
904  virtual void getStandardVolumes_ref(doublereal* vol) const {
905  err("getStandardVolumes_ref");
906  }
907 
908  //! Sets the reference composition
909  /*!
910  * @param x Mole fraction vector to set the reference composition to.
911  * If this is zero, then the reference mole fraction
912  * is set to the current mole fraction vector.
913  */
914  virtual void setReferenceComposition(const doublereal* const x);
915 
916  //! Gets the reference composition
917  /*!
918  * The reference mole fraction is a safe mole fraction.
919  * @param x Mole fraction vector containing the reference composition.
920  */
921  virtual void getReferenceComposition(doublereal* const x) const;
922 
923  //
924  // The methods below are not virtual, and should not
925  // be overloaded.
926  //
927 
928  //@}
929  /**
930  * @name Specific Properties
931  * @{
932  */
933 
934  /**
935  * Specific enthalpy. Units: J/kg.
936  */
937  doublereal enthalpy_mass() const {
939  }
940 
941  /**
942  * Specific internal energy. Units: J/kg.
943  */
944  doublereal intEnergy_mass() const {
946  }
947 
948  /**
949  * Specific entropy. Units: J/kg/K.
950  */
951  doublereal entropy_mass() const {
953  }
954 
955  /**
956  * Specific Gibbs function. Units: J/kg.
957  */
958  doublereal gibbs_mass() const {
959  return gibbs_mole()/meanMolecularWeight();
960  }
961 
962  /**
963  * Specific heat at constant pressure. Units: J/kg/K.
964  */
965  doublereal cp_mass() const {
966  return cp_mole()/meanMolecularWeight();
967  }
968 
969  /**
970  * Specific heat at constant volume. Units: J/kg/K.
971  */
972  doublereal cv_mass() const {
973  return cv_mole()/meanMolecularWeight();
974  }
975  //@}
976 
977  //! Return the Gas Constant multiplied by the current temperature
978  /*!
979  * The units are Joules kmol-1
980  */
981  doublereal _RT() const {
982  return temperature() * GasConstant;
983  }
984 
985  /**
986  * @name Setting the State
987  *
988  * These methods set all or part of the thermodynamic
989  * state.
990  * @{
991  */
992 
993  //! Set the temperature (K), pressure (Pa), and mole fractions.
994  /*!
995  * Note, the mole fractions are set first before the pressure is set.
996  * Setting the pressure may involve the solution of a nonlinear equation.
997  *
998  * @param t Temperature (K)
999  * @param p Pressure (Pa)
1000  * @param x Vector of mole fractions.
1001  * Length is equal to m_kk.
1002  */
1003  virtual void setState_TPX(doublereal t, doublereal p, const doublereal* x);
1004 
1005  //! Set the temperature (K), pressure (Pa), and mole fractions.
1006  /*!
1007  * Note, the mole fractions are set first before the pressure is set.
1008  * Setting the pressure may involve the solution of a nonlinear equation.
1009  *
1010  * @param t Temperature (K)
1011  * @param p Pressure (Pa)
1012  * @param x Composition map of mole fractions. Species not in
1013  * the composition map are assumed to have zero mole fraction
1014  */
1015  void setState_TPX(doublereal t, doublereal p, compositionMap& x);
1016 
1017  //! Set the temperature (K), pressure (Pa), and mole fractions.
1018  /*!
1019  * Note, the mole fractions are set first before the pressure is set.
1020  * Setting the pressure may involve the solution of a nonlinear equation.
1021  *
1022  * @param t Temperature (K)
1023  * @param p Pressure (Pa)
1024  * @param x String containing a composition map of the mole fractions. Species not in
1025  * the composition map are assumed to have zero mole fraction
1026  */
1027  void setState_TPX(doublereal t, doublereal p, const std::string& x);
1028 
1029  //! Set the internally stored temperature (K), pressure (Pa), and mass fractions of the phase.
1030  /*!
1031  * Note, the mass fractions are set first before the pressure is set.
1032  * Setting the pressure may involve the solution of a nonlinear equation.
1033  *
1034  * @param t Temperature (K)
1035  * @param p Pressure (Pa)
1036  * @param y Vector of mass fractions.
1037  * Length is equal to m_kk.
1038  */
1039  void setState_TPY(doublereal t, doublereal p, const doublereal* y);
1040 
1041  //! Set the internally stored temperature (K), pressure (Pa), and mass fractions of the phase
1042  /*!
1043  * Note, the mass fractions are set first before the pressure is set.
1044  * Setting the pressure may involve the solution of a nonlinear equation.
1045  *
1046  * @param t Temperature (K)
1047  * @param p Pressure (Pa)
1048  * @param y Composition map of mass fractions. Species not in
1049  * the composition map are assumed to have zero mass fraction
1050  */
1051  void setState_TPY(doublereal t, doublereal p, compositionMap& y);
1052 
1053  //! Set the internally stored temperature (K), pressure (Pa), and mass fractions of the phase
1054  /*!
1055  * Note, the mass fractions are set first before the pressure is set.
1056  * Setting the pressure may involve the solution of a nonlinear equation.
1057  *
1058  * @param t Temperature (K)
1059  * @param p Pressure (Pa)
1060  * @param y String containing a composition map of the mass fractions. Species not in
1061  * the composition map are assumed to have zero mass fraction
1062  */
1063  void setState_TPY(doublereal t, doublereal p, const std::string& y);
1064 
1065  //! Set the temperature (K) and pressure (Pa)
1066  /*!
1067  * Setting the pressure may involve the solution of a nonlinear equation.
1068  *
1069  * @param t Temperature (K)
1070  * @param p Pressure (Pa)
1071  */
1072  void setState_TP(doublereal t, doublereal p);
1073 
1074  //! Set the pressure (Pa) and mole fractions.
1075  /*!
1076  * Note, the mole fractions are set first before the pressure is set.
1077  * Setting the pressure may involve the solution of a nonlinear equation.
1078  *
1079  * @param p Pressure (Pa)
1080  * @param x Vector of mole fractions.
1081  * Length is equal to m_kk.
1082  */
1083  void setState_PX(doublereal p, doublereal* x);
1084 
1085  //! Set the internally stored pressure (Pa) and mass fractions.
1086  /*!
1087  * Note, the temperature is held constant during this operation.
1088  * Note, the mass fractions are set first before the pressure is set.
1089  * Setting the pressure may involve the solution of a nonlinear equation.
1090  *
1091  * @param p Pressure (Pa)
1092  * @param y Vector of mass fractions.
1093  * Length is equal to m_kk.
1094  */
1095  void setState_PY(doublereal p, doublereal* y);
1096 
1097  //! Set the internally stored specific enthalpy (J/kg) and pressure (Pa) of the phase.
1098  /*!
1099  * @param h Specific enthalpy (J/kg)
1100  * @param p Pressure (Pa)
1101  * @param tol Optional parameter setting the tolerance of the
1102  * calculation. Defaults to 1.0E-4
1103  */
1104  virtual void setState_HP(doublereal h, doublereal p, doublereal tol = 1.e-4);
1105 
1106  //! Set the specific internal energy (J/kg) and specific volume (m^3/kg).
1107  /*!
1108  * This function fixes the internal state of the phase so that
1109  * the specific internal energy and specific volume have the value of the input parameters.
1110  *
1111  * @param u specific internal energy (J/kg)
1112  * @param v specific volume (m^3/kg).
1113  * @param tol Optional parameter setting the tolerance of the
1114  * calculation. Defaults to 1.0E-4
1115  */
1116  virtual void setState_UV(doublereal u, doublereal v, doublereal tol = 1.e-4);
1117 
1118 private:
1119 
1120  //! Carry out work in HP and UV calculations.
1121  /*!
1122  * @param h Specific enthalpy or internal energy (J/kg)
1123  * @param p Pressure (Pa) or specific volume (m^3/kg)
1124  * @param tol Optional parameter setting the tolerance of the
1125  * calculation. Defaults to 1.0E-4
1126  * @param doUV True if solving for UV, false for HP.
1127  */
1128  void setState_HPorUV(doublereal h, doublereal p,
1129  doublereal tol = 1.e-4, bool doUV = false);
1130 
1131 public:
1132 
1133  //! Set the specific entropy (J/kg/K) and pressure (Pa).
1134  /*!
1135  * This function fixes the internal state of the phase so that
1136  * the specific entropy and the pressure have the value of the input parameters.
1137  *
1138  * @param s specific entropy (J/kg/K)
1139  * @param p specific pressure (Pa).
1140  * @param tol Optional parameter setting the tolerance of the
1141  * calculation. Defaults to 1.0E-4
1142  */
1143  virtual void setState_SP(doublereal s, doublereal p, doublereal tol = 1.e-4);
1144 
1145  //! Set the specific entropy (J/kg/K) and specific volume (m^3/kg).
1146  /*!
1147  * This function fixes the internal state of the phase so that
1148  * the specific entropy and specific volume have the value of the input parameters.
1149  *
1150  * @param s specific entropy (J/kg/K)
1151  * @param v specific volume (m^3/kg).
1152  * @param tol Optional parameter setting the tolerance of the
1153  * calculation. Defaults to 1.0E-4
1154  */
1155  virtual void setState_SV(doublereal s, doublereal v, doublereal tol = 1.e-4);
1156 
1157 private:
1158 
1159  //! Carry out work in SP and SV calculations.
1160  /*!
1161  * @param s Specific entropy (J/kg)
1162  * @param p Pressure (Pa) or specific volume (m^3/kg)
1163  * @param tol Optional parameter setting the tolerance of the
1164  * calculation. Defaults to 1.0E-4
1165  * @param doSV True if solving for SV, false for SP.
1166  */
1167  void setState_SPorSV(doublereal s, doublereal p,
1168  doublereal tol = 1.e-4, bool doSV = false);
1169 
1170 public:
1171 
1172  //@}
1173 
1174  /**
1175  * @name Chemical Equilibrium
1176  * Chemical equilibrium.
1177  * @{
1178  */
1179 
1180 
1181  //!This method is used by the ChemEquil equilibrium solver.
1182  /*!
1183  * It sets the state such that the chemical potentials satisfy
1184  * \f[ \frac{\mu_k}{\hat R T} = \sum_m A_{k,m}
1185  * \left(\frac{\lambda_m} {\hat R T}\right) \f] where
1186  * \f$ \lambda_m \f$ is the element potential of element m. The
1187  * temperature is unchanged. Any phase (ideal or not) that
1188  * implements this method can be equilibrated by ChemEquil.
1189  *
1190  * @param lambda_RT Input vector of dimensionless element potentials
1191  * The length is equal to nElements().
1192  */
1193  virtual void setToEquilState(const doublereal* lambda_RT) {
1194  err("setToEquilState");
1195  }
1196 
1197  //! Stores the element potentials in the ThermoPhase object
1198  /*!
1199  * Called by function 'equilibrate' in ChemEquil.h to transfer
1200  * the element potentials to this object after every successful
1201  * equilibration routine.
1202  * The element potentials are stored in their dimensionless
1203  * forms, calculated by dividing by RT.
1204  *
1205  * @param lambda Input vector containing the element potentials.
1206  * Length = nElements. Units are Joules/kmol.
1207  */
1208  void setElementPotentials(const vector_fp& lambda);
1209 
1210 
1211  //! Returns the element potentials stored in the ThermoPhase object
1212  /*!
1213  * Returns the stored element potentials.
1214  * The element potentials are retrieved from their stored
1215  * dimensionless forms by multiplying by RT.
1216  * @param lambda Output vector containing the element potentials.
1217  * Length = nElements. Units are Joules/kmol.
1218  * @return bool indicating whether there are any valid stored element
1219  * potentials. The calling routine should check this
1220  * bool. In the case that there aren't any, lambda is not
1221  * touched.
1222  */
1223  bool getElementPotentials(doublereal* lambda) const;
1224 
1225  //@}
1226 
1227 
1228  //---------------------------------------------------------
1229  /// @name Critical State Properties.
1230  /// These methods are only implemented by some subclasses, and may
1231  /// be moved out of ThermoPhase at a later date.
1232 
1233  //@{
1234 
1235  /// Critical temperature (K).
1236  virtual doublereal critTemperature() const {
1237  err("critTemperature");
1238  return -1.0;
1239  }
1240 
1241  /// Critical pressure (Pa).
1242  virtual doublereal critPressure() const {
1243  err("critPressure");
1244  return -1.0;
1245  }
1246 
1247  /// Critical density (kg/m3).
1248  virtual doublereal critDensity() const {
1249  err("critDensity");
1250  return -1.0;
1251  }
1252 
1253  //@}
1254 
1255  /** @name Saturation Properties.
1256  *
1257  * These methods are only implemented by subclasses that
1258  * implement full liquid-vapor equations of state. They may be
1259  * moved out of %ThermoPhase at a later date.
1260  */
1261  //@{
1262 
1263  //! Return the saturation temperature given the pressure
1264  /*!
1265  * @param p Pressure (Pa)
1266  */
1267  virtual doublereal satTemperature(doublereal p) const {
1268  err("satTemperature");
1269  return -1.0;
1270  }
1271 
1272  //! Return the saturation pressure given the temperature
1273  /*!
1274  * @param t Temperature (Kelvin)
1275  */
1276  virtual doublereal satPressure(doublereal t) const {
1277  err("satPressure");
1278  return -1.0;
1279  }
1280 
1281  //! Return the fraction of vapor at the current conditions
1282  virtual doublereal vaporFraction() const {
1283  err("vaprFraction");
1284  return -1.0;
1285  }
1286 
1287  //! Set the state to a saturated system at a particular temperature
1288  /*!
1289  * @param t Temperature (kelvin)
1290  * @param x Fraction of vapor
1291  */
1292  virtual void setState_Tsat(doublereal t, doublereal x) {
1293  err("setState_sat");
1294  }
1295 
1296  //! Set the state to a saturated system at a particular pressure
1297  /*!
1298  * @param p Pressure (Pa)
1299  * @param x Fraction of vapor
1300  */
1301  virtual void setState_Psat(doublereal p, doublereal x) {
1302  err("setState_sat");
1303  }
1304 
1305  //@}
1306 
1307 
1308  //! @name Initialization Methods - For Internal Use (%ThermoPhase)
1309  /*!
1310  * The following methods are used in the process of constructing
1311  * the phase and setting its parameters from a specification in an
1312  * input file. They are not normally used in application programs.
1313  * To see how they are used,
1314  * see files importCTML.cpp and ThermoFactory.cpp.
1315  */
1316  //@{
1317 
1318  //! Store a reference pointer to the XML tree containing the species data
1319  //! for this phase.
1320  /*!
1321  * This is used to access data needed to construct transport manager later.
1322  * @internal
1323  *
1324  * @param k Species index
1325  * @param data Pointer to the XML_Node data containing
1326  * information about the species in the phase.
1327  */
1328  void saveSpeciesData(const size_t k, const XML_Node* const data);
1329 
1330  //! Return a pointer to the vector of XML nodes containing the species
1331  //! data for this phase.
1332  const std::vector<const XML_Node*> & speciesData() const;
1333 
1334  //! Install a species thermodynamic property manager.
1335  /*!
1336  * The species thermodynamic property manager
1337  * computes properties of the pure species for use in
1338  * constructing solution properties. It is meant for internal
1339  * use, and some classes derived from ThermoPhase may not use
1340  * any species thermodynamic property manager. This method is
1341  * called by function importPhase() in importCTML.cpp.
1342  *
1343  * @param spthermo input pointer to the species thermodynamic property
1344  * manager.
1345  *
1346  * @internal
1347  */
1348  void setSpeciesThermo(SpeciesThermo* spthermo);
1349 
1350  //! Return a changeable reference to the calculation manager
1351  //! for species reference-state thermodynamic properties
1352  /*!
1353  *
1354  * @param k Speices id. The default is -1, meaning return the default
1355  *
1356  * @internal
1357  */
1358  virtual SpeciesThermo& speciesThermo(int k = -1);
1359 
1360  /**
1361  * @internal
1362  * Initialization of a ThermoPhase object using an
1363  * ctml file.
1364  *
1365  * This routine is a precursor to initThermoXML(XML_Node*)
1366  * routine, which does most of the work.
1367  * Here we read extra information about the XML description
1368  * of a phase. Regular information about elements and species
1369  * and their reference state thermodynamic information
1370  * have already been read at this point.
1371  * For example, we do not need to call this function for
1372  * ideal gas equations of state.
1373  *
1374  * @param inputFile XML file containing the description of the
1375  * phase
1376  *
1377  * @param id Optional parameter identifying the name of the
1378  * phase. If none is given, the first XML
1379  * phase element encountered will be used.
1380  */
1381  virtual void initThermoFile(std::string inputFile, std::string id);
1382 
1383 
1384  //!Import and initialize a ThermoPhase object using an XML tree.
1385  /*!
1386  * @internal
1387  *
1388  * Here we read extra information about the XML description
1389  * of a phase. Regular information about elements and species
1390  * and their reference state thermodynamic information
1391  * have already been read at this point.
1392  * For example, we do not need to call this function for
1393  * ideal gas equations of state. This function is called from importPhase()
1394  * after the elements and the species are initialized with
1395  * default ideal solution level data.
1396  *
1397  * The default implementation in ThermoPhase calls the
1398  * virtual function initThermo() and then sets the "state" of the
1399  * phase by looking for an XML element named "state", and then
1400  * interpreting its contents by calling the virtual function
1401  * setStateFromXML().
1402  *
1403  * @param phaseNode This object must be the phase node of a
1404  * complete XML tree
1405  * description of the phase, including all of the
1406  * species data. In other words while "phase" must
1407  * point to an XML phase object, it must have
1408  * sibling nodes "speciesData" that describe
1409  * the species in the phase.
1410  * @param id ID of the phase. If nonnull, a check is done
1411  * to see if phaseNode is pointing to the phase
1412  * with the correct id.
1413  */
1414  virtual void initThermoXML(XML_Node& phaseNode, std::string id);
1415 
1416  //! Initialize the ThermoPhase object after all species have been set up
1417  /*!
1418  * @internal Initialize.
1419  *
1420  * This method is provided to allow
1421  * subclasses to perform any initialization required after all
1422  * species have been added. For example, it might be used to
1423  * resize internal work arrays that must have an entry for
1424  * each species. The base class implementation does nothing,
1425  * and subclasses that do not require initialization do not
1426  * need to overload this method. When importing a CTML phase
1427  * description, this method is called from ThermoPhase::initThermoXML(),
1428  * which is called from importPhase(),
1429  * just prior to returning from function importPhase().
1430  *
1431  * @see importCTML.cpp
1432  */
1433  virtual void initThermo();
1434 
1435  //! Add in species from Slave phases
1436  /*!
1437  * This hook is used for cSS_CONVENTION_SLAVE phases
1438  *
1439  * @param phaseNode XML Element for the phase
1440  */
1441  virtual void installSlavePhases(Cantera::XML_Node* phaseNode);
1442 
1443  //! Set the equation of state parameters
1444  /*!
1445  * @internal
1446  * The number and meaning of these depends on the subclass.
1447  *
1448  * @param n number of parameters
1449  * @param c array of \a n coefficients
1450  */
1451  virtual void setParameters(int n, doublereal* const c) {}
1452 
1453 
1454  //! Get the equation of state parameters in a vector
1455  /*!
1456  * @internal
1457  * The number and meaning of these depends on the subclass.
1458  *
1459  * @param n number of parameters
1460  * @param c array of \a n coefficients
1461  */
1462  virtual void getParameters(int& n, doublereal* const c) const {}
1463 
1464 
1465  //! Set equation of state parameter values from XML entries.
1466  /*!
1467  *
1468  * This method is called by function importPhase() in
1469  * file importCTML.cpp when processing a phase definition in
1470  * an input file. It should be overloaded in subclasses to set
1471  * any parameters that are specific to that particular phase
1472  * model. Note, this method is called before the phase is
1473  * initialized with elements and/or species.
1474  *
1475  * @param eosdata An XML_Node object corresponding to
1476  * the "thermo" entry for this phase in the input file.
1477  */
1478  virtual void setParametersFromXML(const XML_Node& eosdata) {}
1479 
1480 
1481  //! Set the initial state of the phase to the conditions
1482  //! specified in the state XML element.
1483  /*!
1484  *
1485  * This method sets the temperature, pressure, and mole
1486  * fraction vector to a set default value.
1487  *
1488  * @param state AN XML_Node object corresponding to
1489  * the "state" entry for this phase in the
1490  * input file.
1491  */
1492  virtual void setStateFromXML(const XML_Node& state);
1493 
1494  /**
1495  * @}
1496  * @name Derivatives of Thermodynamic Variables needed for Applications
1497  * @{
1498  */
1499 
1500  //! Get the change in activity coefficients wrt changes in state (temp, mole fraction, etc) along
1501  //! a line in parameter space or along a line in physical space
1502  /*!
1503  *
1504  * @param dTds Input of temperature change along the path
1505  * @param dXds Input vector of changes in mole fraction along the path. length = m_kk
1506  * Along the path length it must be the case that the mole fractions sum to one.
1507  * @param dlnActCoeffds Output vector of the directional derivatives of the
1508  * log Activity Coefficients along the path. length = m_kk
1509  * units are 1/units(s). if s is a physical coordinate then the units are 1/m.
1510  */
1511  virtual void getdlnActCoeffds(const doublereal dTds, const doublereal* const dXds,
1512  doublereal* dlnActCoeffds) const {
1513  err("getdlnActCoeffds");
1514  }
1515 
1516  //! Get the array of ln mole fraction derivatives of the log activity coefficients - diagonal component only
1517  /*!
1518  * This function is a virtual method. For ideal mixtures
1519  * (unity activity coefficients), this can return zero.
1520  * Implementations should take the derivative of the
1521  * logarithm of the activity coefficient with respect to the
1522  * logarithm of the mole fraction variable
1523  * that represents the standard state.
1524  * This quantity is to be used in conjunction with derivatives of
1525  * that mole fraction variable when the derivative of the chemical
1526  * potential is taken.
1527  *
1528  * units = dimensionless
1529  *
1530  * @param dlnActCoeffdlnX_diag Output vector of derivatives of the
1531  * log Activity Coefficients wrt the mole fractions. length = m_kk
1532  */
1533  virtual void getdlnActCoeffdlnX_diag(doublereal* dlnActCoeffdlnX_diag) const {
1534  err("getdlnActCoeffdlnX_diag");
1535  }
1536 
1537  //! Get the array of log species mole number derivatives of the log activity coefficients
1538  /*!
1539  * This function is a virtual method.
1540  * For ideal mixtures (unity activity coefficients), this can return zero.
1541  * Implementations should take the derivative of the
1542  * logarithm of the activity coefficient with respect to the
1543  * logarithm of the concentration-like variable (i.e. moles)
1544  * that represents the standard state.
1545  * This quantity is to be used in conjunction with derivatives of
1546  * that species mole number variable when the derivative of the chemical
1547  * potential is taken.
1548  *
1549  * units = dimensionless
1550  *
1551  * @param dlnActCoeffdlnN_diag Output vector of derivatives of the
1552  * log Activity Coefficients. length = m_kk
1553  */
1554  virtual void getdlnActCoeffdlnN_diag(doublereal* dlnActCoeffdlnN_diag) const {
1555  err("getdlnActCoeffdlnN_diag");
1556  }
1557 
1558  //! Get the array of derivatives of the log activity coefficients with respect to the log of the species mole numbers
1559  /*!
1560  * Implementations should take the derivative of the logarithm of the activity coefficient with respect to a
1561  * species log mole number (with all other species mole numbers held constant). The default treatment in the
1562  * %ThermoPhase object is to set this vector to zero.
1563  *
1564  * units = 1 / kmol
1565  *
1566  * dlnActCoeffdlnN[ ld * k + m] will contain the derivative of log act_coeff for the <I>m</I><SUP>th</SUP>
1567  * species with respect to the number of moles of the <I>k</I><SUP>th</SUP> species.
1568  *
1569  * \f[
1570  * \frac{d \ln(\gamma_m) }{d \ln( n_k ) }\Bigg|_{n_i}
1571  * \f]
1572  *
1573  * @param ld Number of rows in the matrix
1574  * @param dlnActCoeffdlnN Output vector of derivatives of the
1575  * log Activity Coefficients. length = m_kk * m_kk
1576  */
1577  virtual void getdlnActCoeffdlnN(const size_t ld, doublereal* const dlnActCoeffdlnN);
1578 
1579  virtual void getdlnActCoeffdlnN_numderiv(const size_t ld, doublereal* const dlnActCoeffdlnN);
1580 
1581  /**
1582  * @}
1583  * @name Printing
1584  * @{
1585  */
1586 
1587  //! returns a summary of the state of the phase as a string
1588  /*!
1589  * @param show_thermo If true, extra information is printed out
1590  * about the thermodynamic state of the system.
1591  */
1592  virtual std::string report(bool show_thermo = true) const;
1593 
1594  //! returns a summary of the state of the phase to a comma separated file
1595  /*!
1596  * @param csvFile ofstream file to print comma separated data for
1597  * the phase
1598  */
1599  virtual void reportCSV(std::ofstream& csvFile) const;
1600 
1601  //@}
1602 
1603 protected:
1604 
1605  //! Pointer to the calculation manager for species
1606  //! reference-state thermodynamic properties
1607  /*!
1608  * This class is called when the reference-state thermodynamic properties
1609  * of all the species in the phase needs to be evaluated.
1610  */
1612 
1613  //! Vector of pointers to the species databases.
1614  /*!
1615  * This is used to access data needed to
1616  * construct the transport manager and other properties
1617  * later in the initialization process.
1618  * We create a copy of the XML_Node data read in here. Therefore, we own this
1619  * data.
1620  */
1621  std::vector<const XML_Node*> m_speciesData;
1622 
1623  //! Stored value of the electric potential for this phase
1624  /*!
1625  * Units are Volts
1626  */
1627  doublereal m_phi;
1628 
1629  /// Vector of element potentials.
1630  /// -> length equal to number of elements
1632 
1633  //! Boolean indicating whether there is a valid set of saved element potentials
1634  //! for this phase
1636 
1637  //! Boolean indicating whether a charge neutrality condition is a necessity
1638  /*!
1639  * Note, the charge neutrality condition is not a necessity for ideal gas phases. There may
1640  * be a net charge in those phases, because the NASA polynomials for ionized species
1641  * in Ideal gases take this condition into account.
1642  * However, liquid phases usually require charge neutrality in order for their derived
1643  * thermodynamics to be valid.
1644  */
1646 
1647  //! Contains the standard state convention
1649 
1650  //! Reference Mole Fraction Composition
1651  /*!
1652  * Occasionally, the need arises to find a safe mole fraction vector to initialize
1653  * the object to. This contains such a vector.
1654  * The algorithm will pick up the mole fraction vector that is applied from
1655  * the state xml file in the input file
1656  */
1657  std::vector<doublereal> xMol_Ref;
1658 
1659 private:
1660 
1661  //! Error function that gets called for unhandled cases
1662  /*!
1663  * @param msg String containing the message.
1664  */
1665  doublereal err(std::string msg) const;
1666 
1667 };
1668 
1669 //! typedef for the ThermoPhase class
1671 
1672 //! Format a summary of the mixture state for output.
1673 /*!
1674  * @param th ThermoPhase object to create a report about
1675  * @param show_thermo Boolean indicating whether the thermo functions
1676  * of the phase should be written out
1677  *
1678  * @return Returns a string containing the report
1679  * @deprecated use "th.report(show_thermo)" instead
1680  */
1681 DEPRECATED(std::string report(const ThermoPhase& th, const bool show_thermo = true));
1682 
1683 }
1684 
1685 #endif
1686