Cantera  2.5.1
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 ThermoPhase\endlink).
6  */
7 
8 // This file is part of Cantera. See License.txt in the top-level directory or
9 // at https://cantera.org/license.txt for license and copyright information.
10 
11 #ifndef CT_THERMOPHASE_H
12 #define CT_THERMOPHASE_H
13 
14 #include "Phase.h"
15 #include "MultiSpeciesThermo.h"
16 #include "cantera/base/global.h"
17 
18 namespace Cantera
19 {
20 
21 /*!
22  * @name CONSTANTS - Specification of the Molality convention
23  */
24 //@{
25 //! Standard state uses the molar convention
26 const int cAC_CONVENTION_MOLAR = 0;
27 //! Standard state uses the molality convention
29 //@}
30 
31 /*!
32  * @name CONSTANTS - Specification of the SS convention
33  */
34 //@{
35 //! Standard state uses the molar convention
37 //! Standard state uses the molality convention
38 const int cSS_CONVENTION_VPSS = 1;
39 //! Standard state thermodynamics is obtained from slave ThermoPhase objects
40 const int cSS_CONVENTION_SLAVE = 2;
41 //@}
42 
43 //! Differentiate between mole fractions and mass fractions for input mixture composition
44 enum class ThermoBasis
45 {
46  mass,
47  molar
48 };
49 //@}
50 
51 //! Base class for a phase with thermodynamic properties.
52 /*!
53  * Class ThermoPhase is the base class for the family of classes that represent
54  * phases of matter of any type. It defines a common public interface, and
55  * implements a few methods. Most of the methods, however, are declared virtual
56  * and are meant to be overloaded in derived classes. The standard way used
57  * throughout Cantera to compute properties of phases of matter is through
58  * pointers of type ThermoPhase* that point to objects of subclasses of
59  * ThermoPhase.
60  *
61  * Class ThermoPhase extends class Phase by adding methods to compute
62  * thermodynamic properties in addition to the ones that are used to define the
63  * state of a substance (temperature, density/pressure and composition). The
64  * distinction is that the methods declared in ThermoPhase require knowing the
65  * particular equation of state of the phase of interest, while those of class
66  * Phase do not, since they only involve data values stored within the object.
67  *
68  * Instances of subclasses of ThermoPhase should be created using the factory
69  * class ThermoFactory, not by calling the constructor directly. This allows new
70  * classes to be used with the various Cantera language interfaces.
71  *
72  * To implement a new equation of state, derive a class from ThermoPhase and
73  * overload the virtual methods in ThermoPhase. Methods that are not needed can
74  * be left unimplemented, which will cause an exception to be thrown if it is
75  * called.
76  *
77  * Relationship with the kinetics operator:
78  *
79  * Describe activity coefficients.
80  *
81  * Describe K_a, K_p, and K_c, These are three different equilibrium
82  * constants.
83  *
84  * K_a is the calculation of the equilibrium constant from the standard state
85  * Gibbs free energy values. It is by definition dimensionless.
86  *
87  * K_p is the calculation of the equilibrium constant from the reference state
88  * Gibbs free energy values. It is by definition dimensionless. The pressure
89  * dependence is handled entirely on the RHS of the equilibrium expression.
90  *
91  * K_c is the equilibrium constant calculated from the activity
92  * concentrations. The dimensions depend on the number of products and
93  * reactants.
94  *
95  * The kinetics manager requires the calculation of K_c for the calculation of
96  * the reverse rate constant
97  *
98  * @ingroup thermoprops
99  * @ingroup phases
100  */
101 class ThermoPhase : public Phase
102 {
103 public:
104  //! Constructor. Note that ThermoPhase is meant to be used as a base class,
105  //! so this constructor should not be called explicitly.
106  ThermoPhase();
107 
108  virtual ~ThermoPhase();
109 
110  //! @name Information Methods
111  //! @{
112 
113  virtual std::string type() const {
114  return "ThermoPhase";
115  }
116 
117  //! String indicating the mechanical phase of the matter in this Phase.
118  /*!
119  * Options for the string are:
120  * * `unspecified`
121  * * `supercritical`
122  * * `gas`
123  * * `liquid`
124  * * `solid`
125  * * `solid-liquid-mix`
126  * * `solid-gas-mix`
127  * * `liquid-gas-mix`
128  * * `solid-liquid-gas-mix`
129  *
130  * `unspecified` is the default and should be used when the Phase does not
131  * distinguish between mechanical phases or does not have enough information to
132  * determine which mechanical phase(s) are present.
133  *
134  * @todo Needs to be implemented for all phase types. Currently only implemented for
135  * PureFluidPhase.
136  */
137  virtual std::string phaseOfMatter() const {
138  return "unspecified";
139  }
140 
141  /**
142  * Returns the reference pressure in Pa. This function is a wrapper
143  * that calls the species thermo refPressure function.
144  */
145  virtual doublereal refPressure() const {
146  return m_spthermo.refPressure();
147  }
148 
149  //! Minimum temperature for which the thermodynamic data for the species
150  //! or phase are valid.
151  /*!
152  * If no argument is supplied, the value returned will be the lowest
153  * temperature at which the data for \e all species are valid. Otherwise,
154  * the value will be only for species \a k. This function is a wrapper that
155  * calls the species thermo minTemp function.
156  *
157  * @param k index of the species. Default is -1, which will return the max
158  * of the min value over all species.
159  */
160  virtual doublereal minTemp(size_t k = npos) const {
161  return m_spthermo.minTemp(k);
162  }
163 
164  //! Report the 298 K Heat of Formation of the standard state of one species
165  //! (J kmol-1)
166  /*!
167  * The 298K Heat of Formation is defined as the enthalpy change to create
168  * the standard state of the species from its constituent elements in their
169  * standard states at 298 K and 1 bar.
170  *
171  * @param k species index
172  * @returns the current value of the Heat of Formation at 298K
173  * and 1 bar
174  */
175  doublereal Hf298SS(const size_t k) const {
176  return m_spthermo.reportOneHf298(k);
177  }
178 
179  //! Modify the value of the 298 K Heat of Formation of one species in the
180  //! phase (J kmol-1)
181  /*!
182  * The 298K heat of formation is defined as the enthalpy change to create
183  * the standard state of the species from its constituent elements in their
184  * standard states at 298 K and 1 bar.
185  *
186  * @param k Species k
187  * @param Hf298New Specify the new value of the Heat of Formation at
188  * 298K and 1 bar
189  */
190  virtual void modifyOneHf298SS(const size_t k, const doublereal Hf298New) {
191  m_spthermo.modifyOneHf298(k, Hf298New);
192  invalidateCache();
193  }
194 
195  //! Restore the original heat of formation of one or more species
196  /*!
197  * Resets changes made by modifyOneHf298SS(). If the species index is not
198  * specified, the heats of formation for all species are restored.
199  */
200  virtual void resetHf298(const size_t k=npos);
201 
202  //! Maximum temperature for which the thermodynamic data for the species
203  //! are valid.
204  /*!
205  * If no argument is supplied, the value returned will be the highest
206  * temperature at which the data for \e all species are valid. Otherwise,
207  * the value will be only for species \a k. This function is a wrapper that
208  * calls the species thermo maxTemp function.
209  *
210  * @param k index of the species. Default is -1, which will return the min
211  * of the max value over all species.
212  */
213  virtual doublereal maxTemp(size_t k = npos) const {
214  return m_spthermo.maxTemp(k);
215  }
216 
217  //! Returns the chargeNeutralityNecessity boolean
218  /*!
219  * Some phases must have zero net charge in order for their thermodynamics
220  * functions to be valid. If this is so, then the value returned from this
221  * function is true. If this is not the case, then this is false. Now, ideal
222  * gases have this parameter set to false, while solution with molality-
223  * based activity coefficients have this parameter set to true.
224  */
227  }
228 
229  //! @}
230  //! @name Molar Thermodynamic Properties of the Solution
231  //! @{
232 
233  /// Molar enthalpy. Units: J/kmol.
234  virtual doublereal enthalpy_mole() const {
235  throw NotImplementedError("ThermoPhase::enthalpy_mole");
236  }
237 
238  /// Molar internal energy. Units: J/kmol.
239  virtual doublereal intEnergy_mole() const {
240  return enthalpy_mole() - pressure()* molarVolume();
241  }
242 
243  /// Molar entropy. Units: J/kmol/K.
244  virtual doublereal entropy_mole() const {
245  throw NotImplementedError("ThermoPhase::entropy_mole");
246  }
247 
248  /// Molar Gibbs function. Units: J/kmol.
249  virtual doublereal gibbs_mole() const {
250  return enthalpy_mole() - temperature()*entropy_mole();
251  }
252 
253  /// Molar heat capacity at constant pressure. Units: J/kmol/K.
254  virtual doublereal cp_mole() const {
255  throw NotImplementedError("ThermoPhase::cp_mole");
256  }
257 
258  /// Molar heat capacity at constant volume. Units: J/kmol/K.
259  virtual doublereal cv_mole() const {
260  throw NotImplementedError("ThermoPhase::cv_mole");
261  }
262 
263  //! @}
264  //! @name Mechanical Properties
265  //! @{
266 
267  //! Returns the isothermal compressibility. Units: 1/Pa.
268  /*!
269  * The isothermal compressibility is defined as
270  * \f[
271  * \kappa_T = -\frac{1}{v}\left(\frac{\partial v}{\partial P}\right)_T
272  * \f]
273  * or
274  * \f[
275  * \kappa_T = \frac{1}{\rho}\left(\frac{\partial \rho}{\partial P}\right)_T
276  * \f]
277  */
278  virtual doublereal isothermalCompressibility() const {
279  throw NotImplementedError("ThermoPhase::isothermalCompressibility");
280  }
281 
282  //! Return the volumetric thermal expansion coefficient. Units: 1/K.
283  /*!
284  * The thermal expansion coefficient is defined as
285  * \f[
286  * \beta = \frac{1}{v}\left(\frac{\partial v}{\partial T}\right)_P
287  * \f]
288  */
289  virtual doublereal thermalExpansionCoeff() const {
290  throw NotImplementedError("ThermoPhase::thermalExpansionCoeff");
291  }
292 
293  /**
294  * @}
295  * @name Electric Potential
296  *
297  * The phase may be at some non-zero electrical potential. These methods
298  * set or get the value of the electric potential.
299  */
300  //@{
301 
302  //! Set the electric potential of this phase (V).
303  /*!
304  * This is used by classes InterfaceKinetics and EdgeKinetics to
305  * compute the rates of charge-transfer reactions, and in computing
306  * the electrochemical potentials of the species.
307  *
308  * Each phase may have its own electric potential.
309  *
310  * @param v Input value of the electric potential in Volts
311  */
312  void setElectricPotential(doublereal v) {
313  m_phi = v;
314  }
315 
316  //! Returns the electric potential of this phase (V).
317  /*!
318  * Units are Volts (which are Joules/coulomb)
319  */
320  doublereal electricPotential() const {
321  return m_phi;
322  }
323 
324  /**
325  * @}
326  * @name Activities, Standard States, and Activity Concentrations
327  *
328  * The activity \f$a_k\f$ of a species in solution is related to the
329  * chemical potential by \f[ \mu_k = \mu_k^0(T,P) + \hat R T \log a_k. \f]
330  * The quantity \f$\mu_k^0(T,P)\f$ is the standard chemical potential at
331  * unit activity, which depends on temperature and pressure, but not on
332  * composition. The activity is dimensionless.
333  * @{
334  */
335 
336  //! This method returns the convention used in specification of the
337  //! activities, of which there are currently two, molar- and molality-based
338  //! conventions.
339  /*!
340  * Currently, there are two activity conventions:
341  * - Molar-based activities
342  * %Unit activity of species at either a hypothetical pure
343  * solution of the species or at a hypothetical
344  * pure ideal solution at infinite dilution
345  * cAC_CONVENTION_MOLAR 0
346  * - default
347  *
348  * - Molality-based activities
349  * (unit activity of solutes at a hypothetical 1 molal
350  * solution referenced to infinite dilution at all
351  * pressures and temperatures).
352  * cAC_CONVENTION_MOLALITY 1
353  */
354  virtual int activityConvention() const;
355 
356  //! This method returns the convention used in specification of the standard
357  //! state, of which there are currently two, temperature based, and variable
358  //! pressure based.
359  /*!
360  * Currently, there are two standard state conventions:
361  * - Temperature-based activities
362  * cSS_CONVENTION_TEMPERATURE 0
363  * - default
364  *
365  * - Variable Pressure and Temperature -based activities
366  * cSS_CONVENTION_VPSS 1
367  *
368  * - Thermodynamics is set via slave ThermoPhase objects with
369  * nothing being carried out at this ThermoPhase object level
370  * cSS_CONVENTION_SLAVE 2
371  */
372  virtual int standardStateConvention() const;
373 
374  //! Returns the units of the "standard concentration" for this phase
375  /*!
376  * These are the units of the values returned by the functions
377  * getActivityConcentrations() and standardConcentration(), which can
378  * vary between different ThermoPhase-derived classes, or change within
379  * a single class depending on input options. See the documentation for
380  * standardConcentration() for the derived class for specific details.
381  */
382  virtual Units standardConcentrationUnits() const;
383 
384  //! This method returns an array of generalized concentrations
385  /*!
386  * \f$ C^a_k\f$ are defined such that \f$ a_k = C^a_k / C^0_k, \f$ where
387  * \f$ C^0_k \f$ is a standard concentration defined below and \f$ a_k \f$
388  * are activities used in the thermodynamic functions. These activity (or
389  * generalized) concentrations are used by kinetics manager classes to
390  * compute the forward and reverse rates of elementary reactions. Note that
391  * they may or may not have units of concentration --- they might be partial
392  * pressures, mole fractions, or surface coverages, for example.
393  *
394  * @param c Output array of generalized concentrations. The units depend
395  * upon the implementation of the reaction rate expressions within
396  * the phase.
397  */
398  virtual void getActivityConcentrations(doublereal* c) const {
399  throw NotImplementedError("ThermoPhase::getActivityConcentrations");
400  }
401 
402  //! Return the standard concentration for the kth species
403  /*!
404  * The standard concentration \f$ C^0_k \f$ used to normalize the activity
405  * (i.e., generalized) concentration. In many cases, this quantity will be
406  * the same for all species in a phase - for example, for an ideal gas \f$
407  * C^0_k = P/\hat R T \f$. For this reason, this method returns a single
408  * value, instead of an array. However, for phases in which the standard
409  * concentration is species-specific (e.g. surface species of different
410  * sizes), this method may be called with an optional parameter indicating
411  * the species.
412  *
413  * @param k Optional parameter indicating the species. The default
414  * is to assume this refers to species 0.
415  * @return
416  * Returns the standard concentration. The units are by definition
417  * dependent on the ThermoPhase and kinetics manager representation.
418  */
419  virtual doublereal standardConcentration(size_t k=0) const {
420  throw NotImplementedError("ThermoPhase::standardConcentration");
421  }
422 
423  //! Natural logarithm of the standard concentration of the kth species.
424  /*!
425  * @param k index of the species (defaults to zero)
426  */
427  virtual doublereal logStandardConc(size_t k=0) const;
428 
429  //! Get the array of non-dimensional activities at the current solution
430  //! temperature, pressure, and solution concentration.
431  /*!
432  * Note, for molality based formulations, this returns the molality based
433  * activities.
434  *
435  * We resolve this function at this level by calling on the
436  * activityConcentration function. However, derived classes may want to
437  * override this default implementation.
438  *
439  * @param a Output vector of activities. Length: m_kk.
440  */
441  virtual void getActivities(doublereal* a) const;
442 
443  //! Get the array of non-dimensional molar-based activity coefficients at
444  //! the current solution temperature, pressure, and solution concentration.
445  /*!
446  * @param ac Output vector of activity coefficients. Length: m_kk.
447  */
448  virtual void getActivityCoefficients(doublereal* ac) const {
449  if (m_kk == 1) {
450  ac[0] = 1.0;
451  } else {
452  throw NotImplementedError("ThermoPhase::getActivityCoefficients");
453  }
454  }
455 
456  //! Get the array of non-dimensional molar-based ln activity coefficients at
457  //! the current solution temperature, pressure, and solution concentration.
458  /*!
459  * @param lnac Output vector of ln activity coefficients. Length: m_kk.
460  */
461  virtual void getLnActivityCoefficients(doublereal* lnac) const;
462 
463  //@}
464  /// @name Partial Molar Properties of the Solution
465  //@{
466 
467  /**
468  * Get the array of non-dimensional species chemical potentials
469  * These are partial molar Gibbs free energies.
470  * \f$ \mu_k / \hat R T \f$.
471  * Units: unitless
472  *
473  * @param mu Output vector of dimensionless chemical potentials.
474  * Length: m_kk.
475  */
476  virtual void getChemPotentials_RT(doublereal* mu) const {
477  throw NotImplementedError("ThermoPhase::getChemPotentials_RT");
478  }
479 
480  //! Get the species chemical potentials. Units: J/kmol.
481  /*!
482  * This function returns a vector of chemical potentials of the species in
483  * solution at the current temperature, pressure and mole fraction of the
484  * solution.
485  *
486  * @param mu Output vector of species chemical
487  * potentials. Length: m_kk. Units: J/kmol
488  */
489  virtual void getChemPotentials(doublereal* mu) const {
490  throw NotImplementedError("ThermoPhase::getChemPotentials");
491  }
492 
493  //! Get the species electrochemical potentials.
494  /*!
495  * These are partial molar quantities. This method adds a term \f$ F z_k
496  * \phi_p \f$ to each chemical potential. The electrochemical potential of
497  * species k in a phase p, \f$ \zeta_k \f$, is related to the chemical
498  * potential via the following equation,
499  *
500  * \f[
501  * \zeta_{k}(T,P) = \mu_{k}(T,P) + F z_k \phi_p
502  * \f]
503  *
504  * @param mu Output vector of species electrochemical
505  * potentials. Length: m_kk. Units: J/kmol
506  */
507  void getElectrochemPotentials(doublereal* mu) const;
508 
509  //! Returns an array of partial molar enthalpies for the species
510  //! in the mixture. Units (J/kmol)
511  /*!
512  * @param hbar Output vector of species partial molar enthalpies.
513  * Length: m_kk. units are J/kmol.
514  */
515  virtual void getPartialMolarEnthalpies(doublereal* hbar) const {
516  throw NotImplementedError("ThermoPhase::getPartialMolarEnthalpies");
517  }
518 
519  //! Returns an array of partial molar entropies of the species in the
520  //! solution. Units: J/kmol/K.
521  /*!
522  * @param sbar Output vector of species partial molar entropies.
523  * Length = m_kk. units are J/kmol/K.
524  */
525  virtual void getPartialMolarEntropies(doublereal* sbar) const {
526  throw NotImplementedError("ThermoPhase::getPartialMolarEntropies");
527  }
528 
529  //! Return an array of partial molar internal energies for the
530  //! species in the mixture. Units: J/kmol.
531  /*!
532  * @param ubar Output vector of species partial molar internal energies.
533  * Length = m_kk. units are J/kmol.
534  */
535  virtual void getPartialMolarIntEnergies(doublereal* ubar) const {
536  throw NotImplementedError("ThermoPhase::getPartialMolarIntEnergies");
537  }
538 
539  //! Return an array of partial molar heat capacities for the
540  //! species in the mixture. Units: J/kmol/K
541  /*!
542  * @param cpbar Output vector of species partial molar heat
543  * capacities at constant pressure.
544  * Length = m_kk. units are J/kmol/K.
545  */
546  virtual void getPartialMolarCp(doublereal* cpbar) const {
547  throw NotImplementedError("ThermoPhase::getPartialMolarCp");
548  }
549 
550  //! Return an array of partial molar volumes for the
551  //! species in the mixture. Units: m^3/kmol.
552  /*!
553  * @param vbar Output vector of species partial molar volumes.
554  * Length = m_kk. units are m^3/kmol.
555  */
556  virtual void getPartialMolarVolumes(doublereal* vbar) const {
557  throw NotImplementedError("ThermoPhase::getPartialMolarVolumes");
558  }
559 
560  //@}
561  /// @name Properties of the Standard State of the Species in the Solution
562  //@{
563 
564  //! Get the array of chemical potentials at unit activity for the species at
565  //! their standard states at the current *T* and *P* of the solution.
566  /*!
567  * These are the standard state chemical potentials \f$ \mu^0_k(T,P)
568  * \f$. The values are evaluated at the current temperature and pressure of
569  * the solution
570  *
571  * @param mu Output vector of chemical potentials.
572  * Length: m_kk.
573  */
574  virtual void getStandardChemPotentials(doublereal* mu) const {
575  throw NotImplementedError("ThermoPhase::getStandardChemPotentials");
576  }
577 
578  //! Get the nondimensional Enthalpy functions for the species at their
579  //! standard states at the current *T* and *P* of the solution.
580  /*!
581  * @param hrt Output vector of nondimensional standard state enthalpies.
582  * Length: m_kk.
583  */
584  virtual void getEnthalpy_RT(doublereal* hrt) const {
585  throw NotImplementedError("ThermoPhase::getEnthalpy_RT");
586  }
587 
588  //! Get the array of nondimensional Entropy functions for the standard state
589  //! species at the current *T* and *P* of the solution.
590  /*!
591  * @param sr Output vector of nondimensional standard state entropies.
592  * Length: m_kk.
593  */
594  virtual void getEntropy_R(doublereal* sr) const {
595  throw NotImplementedError("ThermoPhase::getEntropy_R");
596  }
597 
598  //! Get the nondimensional Gibbs functions for the species in their standard
599  //! states at the current *T* and *P* of the solution.
600  /*!
601  * @param grt Output vector of nondimensional standard state Gibbs free
602  * energies. Length: m_kk.
603  */
604  virtual void getGibbs_RT(doublereal* grt) const {
605  throw NotImplementedError("ThermoPhase::getGibbs_RT");
606  }
607 
608  //! Get the Gibbs functions for the standard state of the species at the
609  //! current *T* and *P* of the solution
610  /*!
611  * Units are Joules/kmol
612  * @param gpure Output vector of standard state Gibbs free energies.
613  * Length: m_kk.
614  */
615  virtual void getPureGibbs(doublereal* gpure) const {
616  throw NotImplementedError("ThermoPhase::getPureGibbs");
617  }
618 
619  //! Returns the vector of nondimensional Internal Energies of the standard
620  //! state species at the current *T* and *P* of the solution
621  /*!
622  * @param urt output vector of nondimensional standard state internal energies
623  * of the species. Length: m_kk.
624  */
625  virtual void getIntEnergy_RT(doublereal* urt) const {
626  throw NotImplementedError("ThermoPhase::getIntEnergy_RT");
627  }
628 
629  //! Get the nondimensional Heat Capacities at constant pressure for the
630  //! species standard states at the current *T* and *P* of the
631  //! solution
632  /*!
633  * @param cpr Output vector of nondimensional standard state heat
634  * capacities. Length: m_kk.
635  */
636  virtual void getCp_R(doublereal* cpr) const {
637  throw NotImplementedError("ThermoPhase::getCp_R");
638  }
639 
640  //! Get the molar volumes of the species standard states at the current
641  //! *T* and *P* of the solution.
642  /*!
643  * units = m^3 / kmol
644  *
645  * @param vol Output vector containing the standard state volumes.
646  * Length: m_kk.
647  */
648  virtual void getStandardVolumes(doublereal* vol) const {
649  throw NotImplementedError("ThermoPhase::getStandardVolumes");
650  }
651 
652  //@}
653  /// @name Thermodynamic Values for the Species Reference States
654  //@{
655 
656  //! Returns the vector of nondimensional enthalpies of the reference state
657  //! at the current temperature of the solution and the reference pressure
658  //! for the species.
659  /*!
660  * @param hrt Output vector containing the nondimensional reference
661  * state enthalpies. Length: m_kk.
662  */
663  virtual void getEnthalpy_RT_ref(doublereal* hrt) const {
664  throw NotImplementedError("ThermoPhase::getEnthalpy_RT_ref");
665  }
666 
667  //! Returns the vector of nondimensional Gibbs Free Energies of the
668  //! reference state at the current temperature of the solution and the
669  //! reference pressure for the species.
670  /*!
671  * @param grt Output vector containing the nondimensional reference state
672  * Gibbs Free energies. Length: m_kk.
673  */
674  virtual void getGibbs_RT_ref(doublereal* grt) const {
675  throw NotImplementedError("ThermoPhase::getGibbs_RT_ref");
676  }
677 
678  //! Returns the vector of the Gibbs function of the reference state at the
679  //! current temperature of the solution and the reference pressure for the
680  //! species.
681  /*!
682  * @param g Output vector containing the reference state
683  * Gibbs Free energies. Length: m_kk. Units: J/kmol.
684  */
685  virtual void getGibbs_ref(doublereal* g) const {
686  throw NotImplementedError("ThermoPhase::getGibbs_ref");
687  }
688 
689  //! Returns the vector of nondimensional entropies of the reference state at
690  //! the current temperature of the solution and the reference pressure for
691  //! each species.
692  /*!
693  * @param er Output vector containing the nondimensional reference
694  * state entropies. Length: m_kk.
695  */
696  virtual void getEntropy_R_ref(doublereal* er) const {
697  throw NotImplementedError("ThermoPhase::getEntropy_R_ref");
698  }
699 
700  //! Returns the vector of nondimensional internal Energies of the reference
701  //! state at the current temperature of the solution and the reference
702  //! pressure for each species.
703  /*!
704  * @param urt Output vector of nondimensional reference state internal
705  * energies of the species. Length: m_kk
706  */
707  virtual void getIntEnergy_RT_ref(doublereal* urt) const {
708  throw NotImplementedError("ThermoPhase::getIntEnergy_RT_ref");
709  }
710 
711  //! Returns the vector of nondimensional constant pressure heat capacities
712  //! of the reference state at the current temperature of the solution and
713  //! reference pressure for each species.
714  /*!
715  * @param cprt Output vector of nondimensional reference state
716  * heat capacities at constant pressure for the species.
717  * Length: m_kk
718  */
719  virtual void getCp_R_ref(doublereal* cprt) const {
720  throw NotImplementedError("ThermoPhase::getCp_R_ref");
721  }
722 
723  //! Get the molar volumes of the species reference states at the current
724  //! *T* and *P_ref* of the solution.
725  /*!
726  * units = m^3 / kmol
727  *
728  * @param vol Output vector containing the standard state volumes.
729  * Length: m_kk.
730  */
731  virtual void getStandardVolumes_ref(doublereal* vol) const {
732  throw NotImplementedError("ThermoPhase::getStandardVolumes_ref");
733  }
734 
735  // The methods below are not virtual, and should not be overloaded.
736 
737  //@}
738  //! @name Specific Properties
739  //@{
740 
741  //! Specific enthalpy. Units: J/kg.
742  doublereal enthalpy_mass() const {
744  }
745 
746  //! Specific internal energy. Units: J/kg.
747  doublereal intEnergy_mass() const {
749  }
750 
751  //! Specific entropy. Units: J/kg/K.
752  doublereal entropy_mass() const {
754  }
755 
756  //! Specific Gibbs function. Units: J/kg.
757  doublereal gibbs_mass() const {
758  return gibbs_mole()/meanMolecularWeight();
759  }
760 
761  //! Specific heat at constant pressure. Units: J/kg/K.
762  doublereal cp_mass() const {
763  return cp_mole()/meanMolecularWeight();
764  }
765 
766  //! Specific heat at constant volume. Units: J/kg/K.
767  doublereal cv_mass() const {
768  return cv_mole()/meanMolecularWeight();
769  }
770  //@}
771 
772  //! Return the Gas Constant multiplied by the current temperature
773  /*!
774  * The units are Joules kmol-1
775  */
776  doublereal RT() const {
777  return temperature() * GasConstant;
778  }
779 
780  /**
781  * @name Setting the State
782  *
783  * These methods set all or part of the thermodynamic state.
784  * @{
785  */
786 
787  //! Set the temperature (K), pressure (Pa), and mole fractions.
788  /*!
789  * Note, the mole fractions are set first before the pressure is set.
790  * Setting the pressure may involve the solution of a nonlinear equation.
791  *
792  * @param t Temperature (K)
793  * @param p Pressure (Pa)
794  * @param x Vector of mole fractions.
795  * Length is equal to m_kk.
796  */
797  virtual void setState_TPX(doublereal t, doublereal p, const doublereal* x);
798 
799  //! Set the temperature (K), pressure (Pa), and mole fractions.
800  /*!
801  * Note, the mole fractions are set first before the pressure is set.
802  * Setting the pressure may involve the solution of a nonlinear equation.
803  *
804  * @param t Temperature (K)
805  * @param p Pressure (Pa)
806  * @param x Composition map of mole fractions. Species not in
807  * the composition map are assumed to have zero mole fraction
808  */
809  virtual void setState_TPX(doublereal t, doublereal p, const compositionMap& x);
810 
811  //! Set the temperature (K), pressure (Pa), and mole fractions.
812  /*!
813  * Note, the mole fractions are set first before the pressure is set.
814  * Setting the pressure may involve the solution of a nonlinear equation.
815  *
816  * @param t Temperature (K)
817  * @param p Pressure (Pa)
818  * @param x String containing a composition map of the mole fractions.
819  * Species not in the composition map are assumed to have zero
820  * mole fraction
821  */
822  virtual void setState_TPX(doublereal t, doublereal p, const std::string& x);
823 
824  //! Set the internally stored temperature (K), pressure (Pa), and mass
825  //! fractions of the phase.
826  /*!
827  * Note, the mass fractions are set first before the pressure is set.
828  * Setting the pressure may involve the solution of a nonlinear equation.
829  *
830  * @param t Temperature (K)
831  * @param p Pressure (Pa)
832  * @param y Vector of mass fractions.
833  * Length is equal to m_kk.
834  */
835  virtual void setState_TPY(doublereal t, doublereal p, const doublereal* y);
836 
837  //! Set the internally stored temperature (K), pressure (Pa), and mass
838  //! fractions of the phase
839  /*!
840  * Note, the mass fractions are set first before the pressure is set.
841  * Setting the pressure may involve the solution of a nonlinear equation.
842  *
843  * @param t Temperature (K)
844  * @param p Pressure (Pa)
845  * @param y Composition map of mass fractions. Species not in
846  * the composition map are assumed to have zero mass fraction
847  */
848  virtual void setState_TPY(doublereal t, doublereal p, const compositionMap& y);
849 
850  //! Set the internally stored temperature (K), pressure (Pa), and mass
851  //! fractions of the phase
852  /*!
853  * Note, the mass fractions are set first before the pressure is set.
854  * Setting the pressure may involve the solution of a nonlinear equation.
855  *
856  * @param t Temperature (K)
857  * @param p Pressure (Pa)
858  * @param y String containing a composition map of the mass fractions.
859  * Species not in the composition map are assumed to have zero
860  * mass fraction
861  */
862  virtual void setState_TPY(doublereal t, doublereal p, const std::string& y);
863 
864  //! Set the temperature (K) and pressure (Pa)
865  /*!
866  * Setting the pressure may involve the solution of a nonlinear equation.
867  *
868  * @param t Temperature (K)
869  * @param p Pressure (Pa)
870  */
871  virtual void setState_TP(doublereal t, doublereal p);
872 
873  //! Set the pressure (Pa) and mole fractions.
874  /*!
875  * Note, the mole fractions are set first before the pressure is set.
876  * Setting the pressure may involve the solution of a nonlinear equation.
877  *
878  * @param p Pressure (Pa)
879  * @param x Vector of mole fractions.
880  * Length is equal to m_kk.
881  */
882  virtual void setState_PX(doublereal p, doublereal* x);
883 
884  //! Set the internally stored pressure (Pa) and mass fractions.
885  /*!
886  * Note, the temperature is held constant during this operation. Note, the
887  * mass fractions are set first before the pressure is set. Setting the
888  * pressure may involve the solution of a nonlinear equation.
889  *
890  * @param p Pressure (Pa)
891  * @param y Vector of mass fractions.
892  * Length is equal to m_kk.
893  */
894  virtual void setState_PY(doublereal p, doublereal* y);
895 
896  //! Set the internally stored specific enthalpy (J/kg) and pressure (Pa) of
897  //! the phase.
898  /*!
899  * @param h Specific enthalpy (J/kg)
900  * @param p Pressure (Pa)
901  * @param tol Optional parameter setting the tolerance of the calculation.
902  * Important for some applications where numerical Jacobians
903  * are being calculated.
904  */
905  virtual void setState_HP(double h, double p, double tol=1e-9);
906 
907  //! Set the specific internal energy (J/kg) and specific volume (m^3/kg).
908  /*!
909  * This function fixes the internal state of the phase so that the specific
910  * internal energy and specific volume have the value of the input
911  * parameters.
912  *
913  * @param u specific internal energy (J/kg)
914  * @param v specific volume (m^3/kg).
915  * @param tol Optional parameter setting the tolerance of the calculation.
916  * Important for some applications where numerical Jacobians
917  * are being calculated.
918  */
919  virtual void setState_UV(double u, double v, double tol=1e-9);
920 
921  //! Set the specific entropy (J/kg/K) and pressure (Pa).
922  /*!
923  * This function fixes the internal state of the phase so that the specific
924  * entropy and the pressure have the value of the input parameters.
925  *
926  * @param s specific entropy (J/kg/K)
927  * @param p specific pressure (Pa).
928  * @param tol Optional parameter setting the tolerance of the calculation.
929  * Important for some applications where numerical Jacobians
930  * are being calculated.
931  */
932  virtual void setState_SP(double s, double p, double tol=1e-9);
933 
934  //! Set the specific entropy (J/kg/K) and specific volume (m^3/kg).
935  /*!
936  * This function fixes the internal state of the phase so that the specific
937  * entropy and specific volume have the value of the input parameters.
938  *
939  * @param s specific entropy (J/kg/K)
940  * @param v specific volume (m^3/kg).
941  * @param tol Optional parameter setting the tolerance of the calculation.
942  * Important for some applications where numerical Jacobians
943  * are being calculated.
944  */
945  virtual void setState_SV(double s, double v, double tol=1e-9);
946 
947  //! Set the specific entropy (J/kg/K) and temperature (K).
948  /*!
949  * This function fixes the internal state of the phase so that the specific
950  * entropy and temperature have the value of the input parameters.
951  * This base class function will throw an exception if not overridden.
952  *
953  * @param s specific entropy (J/kg/K)
954  * @param t temperature (K)
955  * @param tol Optional parameter setting the tolerance of the calculation.
956  * Important for some applications where numerical Jacobians
957  * are being calculated.
958  */
959  virtual void setState_ST(double s, double t, double tol=1e-9) {
960  throw NotImplementedError("ThermoPhase::setState_ST");
961  }
962 
963  //! Set the temperature (K) and specific volume (m^3/kg).
964  /*!
965  * This function fixes the internal state of the phase so that the
966  * temperature and specific volume have the value of the input parameters.
967  * This base class function will throw an exception if not overridden.
968  *
969  * @param t temperature (K)
970  * @param v specific volume (m^3/kg)
971  * @param tol Optional parameter setting the tolerance of the calculation.
972  * Important for some applications where numerical Jacobians
973  * are being calculated.
974  */
975  virtual void setState_TV(double t, double v, double tol=1e-9) {
976  throw NotImplementedError("ThermoPhase::setState_TV");
977  }
978 
979  //! Set the pressure (Pa) and specific volume (m^3/kg).
980  /*!
981  * This function fixes the internal state of the phase so that the
982  * pressure and specific volume have the value of the input parameters.
983  * This base class function will throw an exception if not overridden.
984  *
985  * @param p pressure (Pa)
986  * @param v specific volume (m^3/kg)
987  * @param tol Optional parameter setting the tolerance of the calculation.
988  * Important for some applications where numerical Jacobians
989  * are being calculated.
990  */
991  virtual void setState_PV(double p, double v, double tol=1e-9) {
992  throw NotImplementedError("ThermoPhase::setState_PV");
993  }
994 
995  //! Set the specific internal energy (J/kg) and pressure (Pa).
996  /*!
997  * This function fixes the internal state of the phase so that the specific
998  * internal energy and pressure have the value of the input parameters.
999  * This base class function will throw an exception if not overridden.
1000  *
1001  * @param u specific internal energy (J/kg)
1002  * @param p pressure (Pa)
1003  * @param tol Optional parameter setting the tolerance of the calculation.
1004  * Important for some applications where numerical Jacobians
1005  * are being calculated.
1006  */
1007  virtual void setState_UP(double u, double p, double tol=1e-9) {
1008  throw NotImplementedError("ThermoPhase::setState_UP");
1009  }
1010 
1011  //! Set the specific volume (m^3/kg) and the specific enthalpy (J/kg)
1012  /*!
1013  * This function fixes the internal state of the phase so that the specific
1014  * volume and the specific enthalpy have the value of the input parameters.
1015  * This base class function will throw an exception if not overridden.
1016  *
1017  * @param v specific volume (m^3/kg)
1018  * @param h specific enthalpy (J/kg)
1019  * @param tol Optional parameter setting the tolerance of the calculation.
1020  * Important for some applications where numerical Jacobians
1021  * are being calculated.
1022  */
1023  virtual void setState_VH(double v, double h, double tol=1e-9) {
1024  throw NotImplementedError("ThermoPhase::setState_VH");
1025  }
1026 
1027  //! Set the temperature (K) and the specific enthalpy (J/kg)
1028  /*!
1029  * This function fixes the internal state of the phase so that the
1030  * temperature and specific enthalpy have the value of the input parameters.
1031  * This base class function will throw an exception if not overridden.
1032  *
1033  * @param t temperature (K)
1034  * @param h specific enthalpy (J/kg)
1035  * @param tol Optional parameter setting the tolerance of the calculation.
1036  * Important for some applications where numerical Jacobians
1037  * are being calculated.
1038  */
1039  virtual void setState_TH(double t, double h, double tol=1e-9) {
1040  throw NotImplementedError("ThermoPhase::setState_TH");
1041  }
1042 
1043  //! Set the specific entropy (J/kg/K) and the specific enthalpy (J/kg)
1044  /*!
1045  * This function fixes the internal state of the phase so that the
1046  * temperature and pressure have the value of the input parameters.
1047  * This base class function will throw an exception if not overridden.
1048  *
1049  * @param s specific entropy (J/kg/K)
1050  * @param h specific enthalpy (J/kg)
1051  * @param tol Optional parameter setting the tolerance of the calculation.
1052  * Important for some applications where numerical Jacobians
1053  * are being calculated.
1054  */
1055  virtual void setState_SH(double s, double h, double tol=1e-9) {
1056  throw NotImplementedError("ThermoPhase::setState_SH");
1057  }
1058 
1059  //! Set the density (kg/m**3) and pressure (Pa) at constant composition
1060  /*!
1061  * This method must be reimplemented in derived classes, where it may
1062  * involve the solution of a nonlinear equation. Within %Cantera, the
1063  * independent variable is the density. Therefore, this function solves for
1064  * the temperature that will yield the desired input pressure and density.
1065  * The composition is held constant during this process.
1066  *
1067  * This base class function will print an error, if not overridden.
1068  *
1069  * @param rho Density (kg/m^3)
1070  * @param p Pressure (Pa)
1071  */
1072  virtual void setState_RP(doublereal rho, doublereal p) {
1073  throw NotImplementedError("ThermoPhase::setState_RP");
1074  }
1075 
1076  //! Set the density (kg/m**3), pressure (Pa) and mole fractions
1077  /*!
1078  * Note, the mole fractions are set first before the density and pressure
1079  * are set. Setting the pressure may involve the solution of a nonlinear
1080  * equation.
1081  *
1082  * @param rho Density (kg/m^3)
1083  * @param p Pressure (Pa)
1084  * @param x Vector of mole fractions.
1085  * Length is equal to m_kk.
1086  */
1087  virtual void setState_RPX(doublereal rho, doublereal p, const doublereal* x);
1088 
1089  //! Set the density (kg/m**3), pressure (Pa) and mole fractions
1090  /*!
1091  * Note, the mole fractions are set first before the density and pressure
1092  * are set. Setting the pressure may involve the solution of a nonlinear
1093  * equation.
1094  *
1095  * @param rho Density (kg/m^3)
1096  * @param p Pressure (Pa)
1097  * @param x Composition map of mole fractions. Species not in
1098  * the composition map are assumed to have zero mole fraction
1099  */
1100  virtual void setState_RPX(doublereal rho, doublereal p, const compositionMap& x);
1101 
1102  //! Set the density (kg/m**3), pressure (Pa) and mole fractions
1103  /*!
1104  * Note, the mole fractions are set first before the density and pressure
1105  * are set. Setting the pressure may involve the solution of a nonlinear
1106  * equation.
1107  *
1108  * @param rho Density (kg/m^3)
1109  * @param p Pressure (Pa)
1110  * @param x String containing a composition map of the mole fractions.
1111  * Species not in the composition map are assumed to have zero
1112  * mole fraction
1113  */
1114  virtual void setState_RPX(doublereal rho, doublereal p, const std::string& x);
1115 
1116  //! Set the density (kg/m**3), pressure (Pa) and mass fractions
1117  /*!
1118  * Note, the mass fractions are set first before the density and pressure
1119  * are set. Setting the pressure may involve the solution of a nonlinear
1120  * equation.
1121  *
1122  * @param rho Density (kg/m^3)
1123  * @param p Pressure (Pa)
1124  * @param y Vector of mole fractions.
1125  * Length is equal to m_kk.
1126  */
1127  virtual void setState_RPY(doublereal rho, doublereal p, const doublereal* y);
1128 
1129  //! Set the density (kg/m**3), pressure (Pa) and mass fractions
1130  /*!
1131  * Note, the mass fractions are set first before the density and pressure
1132  * are set. Setting the pressure may involve the solution of a nonlinear
1133  * equation.
1134  *
1135  * @param rho Density (kg/m^3)
1136  * @param p Pressure (Pa)
1137  * @param y Composition map of mole fractions. Species not in
1138  * the composition map are assumed to have zero mole fraction
1139  */
1140  virtual void setState_RPY(doublereal rho, doublereal p, const compositionMap& y);
1141 
1142  //! Set the density (kg/m**3), pressure (Pa) and mass fractions
1143  /*!
1144  * Note, the mass fractions are set first before the density and pressure
1145  * are set. Setting the pressure may involve the solution of a nonlinear
1146  * equation.
1147  *
1148  * @param rho Density (kg/m^3)
1149  * @param p Pressure (Pa)
1150  * @param y String containing a composition map of the mole fractions.
1151  * Species not in the composition map are assumed to have zero
1152  * mole fraction
1153  */
1154  virtual void setState_RPY(doublereal rho, doublereal p, const std::string& y);
1155 
1156  //! Set the state using an AnyMap containing any combination of properties
1157  //! supported by the thermodynamic model
1158  /*!
1159  * Accepted keys are:
1160  * * `X` (mole fractions)
1161  * * `Y` (mass fractions)
1162  * * `T` or `temperature`
1163  * * `P` or `pressure` [Pa]
1164  * * `H` or `enthalpy` [J/kg]
1165  * * `U` or `internal-energy` [J/kg]
1166  * * `S` or `entropy` [J/kg/K]
1167  * * `V` or `specific-volume` [m^3/kg]
1168  * * `D` or `density` [kg/m^3]
1169  *
1170  * Composition can be specified as either an AnyMap of species names to
1171  * values or as a composition string. All other values can be given as
1172  * floating point values in Cantera's default units, or as strings with the
1173  * units specified, which will be converted using the Units class.
1174  *
1175  * If no thermodynamic property pair is given, or only one of temperature or
1176  * pressure is given, then 298.15 K and 101325 Pa will be used as necessary
1177  * to fully set the state.
1178  */
1179  virtual void setState(const AnyMap& state);
1180 
1181  //@}
1182 
1183  //! @name Set Mixture Composition by Mixture Fraction
1184  //! @{
1185 
1186  //! Set the mixture composition according to the
1187  //! mixture fraction = kg fuel / (kg oxidizer + kg fuel)
1188  /*!
1189  * Fuel and oxidizer compositions are given either as
1190  * mole fractions or mass fractions (specified by `basis`)
1191  * and do not need to be normalized. Pressure and temperature are
1192  * kept constant. Elements C, S, H and O are considered for the oxidation.
1193  *
1194  * @param mixFrac mixture fraction (between 0 and 1)
1195  * @param fuelComp composition of the fuel
1196  * @param oxComp composition of the oxidizer
1197  * @param basis either ThermoPhase::molar or ThermoPhase::mass.
1198  * Fuel and oxidizer composition are interpreted
1199  * as mole or mass fractions (default: molar)
1200  */
1201  void setMixtureFraction(double mixFrac, const double* fuelComp, const double* oxComp,
1202  ThermoBasis basis = ThermoBasis::molar);
1203  //! @copydoc ThermoPhase::setMixtureFraction
1204  void setMixtureFraction(double mixFrac, const std::string& fuelComp, const std::string& oxComp,
1205  ThermoBasis basis = ThermoBasis::molar);
1206  //! @copydoc ThermoPhase::setMixtureFraction
1207  void setMixtureFraction(double mixFrac, const compositionMap& fuelComp, const compositionMap& oxComp,
1208  ThermoBasis basis = ThermoBasis::molar);
1209  //@}
1210 
1211  //! @name Compute Mixture Fraction
1212  //! @{
1213 
1214  //! Compute the mixture fraction = kg fuel / (kg oxidizer + kg fuel) for
1215  //! the current mixture given fuel and oxidizer compositions.
1216  /*!
1217  * Fuel and oxidizer compositions are given either as
1218  * mole fractions or mass fractions (specified by `basis`)
1219  * and do not need to be normalized.
1220  * The mixture fraction \f$ Z \f$ can be computed from a single element
1221  * \f[ Z_m = \frac{Z_{\mathrm{mass},m}-Z_{\mathrm{mass},m,\mathrm{ox}}}
1222  * {Z_{\mathrm{mass},\mathrm{fuel}}-Z_{\mathrm{mass},m,\mathrm{ox}}} \f] where
1223  * \f$ Z_{\mathrm{mass},m} \f$ is the elemental mass fraction of element m
1224  * in the mixture, and \f$ Z_{\mathrm{mass},m,\mathrm{ox}} \f$ and
1225  * \f$ Z_{\mathrm{mass},m,\mathrm{fuel}} \f$ are the elemental mass fractions
1226  * of the oxidizer and fuel, or from the Bilger mixture fraction,
1227  * which considers the elements C, S, H and O (R. W. Bilger, "Turbulent jet
1228  * diffusion flames," Prog. Energy Combust. Sci., 109-131 (1979))
1229  * \f[ Z_{\mathrm{Bilger}} = \frac{\beta-\beta_{\mathrm{ox}}}
1230  * {\beta_{\mathrm{fuel}}-\beta_{\mathrm{ox}}} \f]
1231  * with \f$ \beta = 2\frac{Z_C}{M_C}+2\frac{Z_S}{M_S}+\frac{1}{2}\frac{Z_H}{M_H}
1232  * -\frac{Z_O}{M_O} \f$
1233  * and \f$ M_m \f$ the atomic weight of element \f$ m \f$.
1234  *
1235  * @param fuelComp composition of the fuel
1236  * @param oxComp composition of the oxidizer
1237  * @param basis either ThermoPhase::mole or ThermoPhase::mass.
1238  * Fuel and oxidizer composition are interpreted
1239  * as mole or mass fractions (default: molar)
1240  * @param element either "Bilger" to compute the mixture fraction
1241  * in terms of the Bilger mixture fraction, or
1242  * an element name, to compute the mixture fraction
1243  * bsaed on a single element (default: "Bilger")
1244  * @returns mixture fraction (kg fuel / kg mixture)
1245  */
1246  double mixtureFraction(const double* fuelComp, const double* oxComp,
1247  ThermoBasis basis = ThermoBasis::molar, const std::string& element = "Bilger") const;
1248  //! @copydoc ThermoPhase::mixtureFraction
1249  double mixtureFraction(const std::string& fuelComp, const std::string& oxComp,
1250  ThermoBasis basis = ThermoBasis::molar, const std::string& element = "Bilger") const;
1251  //! @copydoc ThermoPhase::mixtureFraction
1252  double mixtureFraction(const compositionMap& fuelComp, const compositionMap& oxComp,
1253  ThermoBasis basis = ThermoBasis::molar, const std::string& element = "Bilger") const;
1254  //@}
1255 
1256  //! @name Set Mixture Composition by Equivalence Ratio
1257  //! @{
1258 
1259  //! Set the mixture composition according to the equivalence ratio.
1260  /*!
1261  * Fuel and oxidizer compositions are given either as
1262  * mole fractions or mass fractions (specified by `basis`)
1263  * and do not need to be normalized. Pressure and temperature are
1264  * kept constant. Elements C, S, H and O are considered for the oxidation.
1265  *
1266  * @param phi equivalence ratio
1267  * @param fuelComp composition of the fuel
1268  * @param oxComp composition of the oxidizer
1269  * @param basis either ThermoPhase::mole or ThermoPhase::mass.
1270  * Fuel and oxidizer composition are interpreted
1271  * as mole or mass fractions (default: molar)
1272  */
1273  void setEquivalenceRatio(double phi, const double* fuelComp, const double* oxComp, ThermoBasis basis = ThermoBasis::molar);
1274  //! @copydoc ThermoPhase::setEquivalenceRatio
1275  void setEquivalenceRatio(double phi, const std::string& fuelComp, const std::string& oxComp, ThermoBasis basis = ThermoBasis::molar);
1276  //! @copydoc ThermoPhase::setEquivalenceRatio
1277  void setEquivalenceRatio(double phi, const compositionMap& fuelComp, const compositionMap& oxComp, ThermoBasis basis = ThermoBasis::molar);
1278  //@}
1279 
1280  //! @name Compute Equivalence Ratio
1281  //! @{
1282 
1283  //! Compute the equivalence ratio for the current mixture
1284  //! given the compositions of fuel and oxidizer
1285  /*!
1286  * The equivalence ratio \f$ \phi \f$ is computed from
1287  * \f[ \phi = \frac{Z}{1-Z}\frac{1-Z_{\mathrm{st}}}{Z_{\mathrm{st}}} \f]
1288  * where \f$ Z \f$ is the Bilger mixture fraction of the mixture
1289  * given the specified fuel and oxidizer compositions
1290  * \f$ Z_{\mathrm{st}} \f$ is the mixture fraction at stoichiometric
1291  * conditions. Fuel and oxidizer compositions are given either as
1292  * mole fractions or mass fractions (specified by `basis`)
1293  * and do not need to be normalized.
1294  * Elements C, S, H and O are considered for the oxidation.
1295  * If fuel and oxidizer composition are unknown or not specified,
1296  * use the version that takes no arguments.
1297  *
1298  * @param fuelComp composition of the fuel
1299  * @param oxComp composition of the oxidizer
1300  * @param basis either ThermoPhase::mole or ThermoPhase::mass.
1301  * Fuel and oxidizer composition are interpreted
1302  * as mole or mass fractions (default: molar)
1303  * @returns equivalence ratio
1304  * @see mixtureFraction for the definition of the Bilger mixture fraction
1305  * @see equivalenceRatio() for the computation of \f$ \phi \f$ without arguments
1306  */
1307  double equivalenceRatio(const double* fuelComp, const double* oxComp, ThermoBasis basis = ThermoBasis::molar) const;
1308  //! @copydoc ThermoPhase::equivalenceRatio
1309  double equivalenceRatio(const std::string& fuelComp, const std::string& oxComp, ThermoBasis basis = ThermoBasis::molar) const;
1310  //! @copydoc ThermoPhase::equivalenceRatio
1311  double equivalenceRatio(const compositionMap& fuelComp, const compositionMap& oxComp, ThermoBasis basis = ThermoBasis::molar) const;
1312  //@}
1313 
1314  //! Compute the equivalence ratio for the current mixture
1315  //! from available oxygen and required oxygen
1316  /*!
1317  * Computes the equivalence ratio \f$ \phi \f$ from
1318  * \f[ \phi = \frac{Z_{\mathrm{mole},C} + Z_{\mathrm{mole},S} + \frac{1}{4}Z_{\mathrm{mole},H}}
1319  * {\frac{1}{2}Z_{\mathrm{mole},O}} \f]
1320  * where \f$ Z_{\mathrm{mole},m} \f$ is the elemental mole fraction
1321  * of element \f$ m \f$. In this special case, the equivalence ratio
1322  * is independent of a fuel or oxidizer composition because it only
1323  * considers the locally available oxygen compared to the required oxygen
1324  * for complete oxidation. It is the same as assuming that the oxidizer
1325  * only contains O (and inert elements) and the fuel contains only
1326  * H, C and S (and inert elements). If either of these conditions is
1327  * not met, use the version of this functions which takes the fuel and
1328  * oxidizer compositions as input
1329  *
1330  * @returns equivalence ratio
1331  * @see equivalenceRatio compute the equivalence ratio from specific
1332  * fuel and oxidizer compositions
1333  */
1334  double equivalenceRatio() const;
1335 
1336  //! @name Compute Stoichiometric Air to Fuel Ratio
1337  //! @{
1338 
1339  //! Compute the stoichiometric air to fuel ratio (kg oxidizer / kg fuel)
1340  //! given fuel and oxidizer compositions.
1341  /*!
1342  * Fuel and oxidizer compositions are given either as
1343  * mole fractions or mass fractions (specified by `basis`)
1344  * and do not need to be normalized.
1345  * Elements C, S, H and O are considered for the oxidation.
1346  * Note that the stoichiometric air to fuel ratio \f$ \mathit{AFR}_{\mathrm{st}} \f$
1347  * does not depend on the current mixture composition. The current
1348  * air to fuel ratio can be computed from \f$ \mathit{AFR} = \mathit{AFR}_{\mathrm{st}}/\phi \f$
1349  * where \f$ \phi \f$ is the equivalence ratio of the current mixture
1350  *
1351  * @param fuelComp composition of the fuel
1352  * @param oxComp composition of the oxidizer
1353  * @param basis either ThermoPhase::mole or ThermoPhase::mass.
1354  * Fuel and oxidizer composition are interpreted
1355  * as mole or mass fractions (default: molar)
1356  * @returns Stoichiometric Air to Fuel Ratio (kg oxidizer / kg fuel)
1357  */
1358  double stoichAirFuelRatio(const double* fuelComp, const double* oxComp, ThermoBasis basis = ThermoBasis::molar) const;
1359  //! @copydoc ThermoPhase::stoichAirFuelRatio
1360  double stoichAirFuelRatio(const std::string& fuelComp, const std::string& oxComp, ThermoBasis basis = ThermoBasis::molar) const;
1361  //! @copydoc ThermoPhase::stoichAirFuelRatio
1362  double stoichAirFuelRatio(const compositionMap& fuelComp, const compositionMap& oxComp, ThermoBasis basis = ThermoBasis::molar) const;
1363  //@}
1364 
1365 private:
1366 
1367  //! Carry out work in HP and UV calculations.
1368  /*!
1369  * @param h Specific enthalpy or internal energy (J/kg)
1370  * @param p Pressure (Pa) or specific volume (m^3/kg)
1371  * @param tol Optional parameter setting the tolerance of the calculation.
1372  * Important for some applications where numerical Jacobians
1373  * are being calculated.
1374  * @param doUV True if solving for UV, false for HP.
1375  */
1376  void setState_HPorUV(doublereal h, doublereal p,
1377  doublereal tol=1e-9, bool doUV = false);
1378 
1379  //! Carry out work in SP and SV calculations.
1380  /*!
1381  * @param s Specific entropy (J/kg)
1382  * @param p Pressure (Pa) or specific volume (m^3/kg)
1383  * @param tol Optional parameter setting the tolerance of the calculation.
1384  * Important for some applications where numerical Jacobians
1385  * are being calculated.
1386  * @param doSV True if solving for SV, false for SP.
1387  */
1388  void setState_SPorSV(double s, double p, double tol=1e-9, bool doSV = false);
1389 
1390  //! Helper function used by setState_HPorUV and setState_SPorSV.
1391  //! Sets the temperature and (if set_p is true) the pressure.
1392  void setState_conditional_TP(doublereal t, doublereal p, bool set_p);
1393 
1394  //! Helper function for computing the amount of oxygen required for complete oxidation.
1395  /*!
1396  * @param y array of (possibly non-normalized) mass fractions (length m_kk)
1397  * @returns amount of required oxygen in kmol O / kg mixture
1398  */
1399  double o2Required(const double* y) const;
1400 
1401  //! Helper function for computing the amount of oxygen
1402  //! available in the current mixture.
1403  /*!
1404  * @param y array of (possibly non-normalized) mass fractions (length m_kk)
1405  * @returns amount of O in kmol O / kg mixture
1406  */
1407  double o2Present(const double* y) const;
1408 
1409 public:
1410  /**
1411  * @name Chemical Equilibrium
1412  * Chemical equilibrium.
1413  * @{
1414  */
1415 
1416  //! Equilibrate a ThermoPhase object
1417  /*!
1418  * Set this phase to chemical equilibrium by calling one of several
1419  * equilibrium solvers. The XY parameter indicates what two thermodynamic
1420  * quantities are to be held constant during the equilibration process.
1421  *
1422  * @param XY String representation of what two properties are being
1423  * held constant
1424  * @param solver Name of the solver to be used to equilibrate the phase.
1425  * If solver = 'element_potential', the ChemEquil element potential
1426  * solver will be used. If solver = 'vcs', the VCS solver will be used.
1427  * If solver = 'gibbs', the MultiPhaseEquil solver will be used. If
1428  * solver = 'auto', the solvers will be tried in order if the initial
1429  * solver(s) fail.
1430  * @param rtol Relative tolerance
1431  * @param max_steps Maximum number of steps to take to find the solution
1432  * @param max_iter For the 'gibbs' and 'vcs' solvers, this is the maximum
1433  * number of outer temperature or pressure iterations to take when T
1434  * and/or P is not held fixed.
1435  * @param estimate_equil For MultiPhaseEquil solver, an integer indicating
1436  * whether the solver should estimate its own initial condition. If 0,
1437  * the initial mole fraction vector in the ThermoPhase object is used
1438  * as the initial condition. If 1, the initial mole fraction vector is
1439  * used if the element abundances are satisfied. If -1, the initial
1440  * mole fraction vector is thrown out, and an estimate is formulated.
1441  * @param log_level loglevel Controls amount of diagnostic output.
1442  * log_level=0 suppresses diagnostics, and increasingly-verbose
1443  * messages are written as loglevel increases.
1444  *
1445  * @ingroup equilfunctions
1446  */
1447  void equilibrate(const std::string& XY, const std::string& solver="auto",
1448  double rtol=1e-9, int max_steps=50000, int max_iter=100,
1449  int estimate_equil=0, int log_level=0);
1450 
1451  //!This method is used by the ChemEquil equilibrium solver.
1452  /*!
1453  * It sets the state such that the chemical potentials satisfy
1454  * \f[ \frac{\mu_k}{\hat R T} = \sum_m A_{k,m}
1455  * \left(\frac{\lambda_m} {\hat R T}\right) \f] where
1456  * \f$ \lambda_m \f$ is the element potential of element m. The
1457  * temperature is unchanged. Any phase (ideal or not) that
1458  * implements this method can be equilibrated by ChemEquil.
1459  *
1460  * @param mu_RT Input vector of dimensionless chemical potentials
1461  * The length is equal to nSpecies().
1462  */
1463  virtual void setToEquilState(const doublereal* mu_RT) {
1464  throw NotImplementedError("ThermoPhase::setToEquilState");
1465  }
1466 
1467  //! Indicates whether this phase type can be used with class MultiPhase for
1468  //! equilibrium calculations. Returns `false` for special phase types which
1469  //! already represent multi-phase mixtures, namely PureFluidPhase.
1470  virtual bool compatibleWithMultiPhase() const {
1471  return true;
1472  }
1473 
1474  //@}
1475  /// @name Critical State Properties.
1476  /// These methods are only implemented by subclasses that implement
1477  /// liquid-vapor equations of state.
1478  //@{
1479 
1480  /// Critical temperature (K).
1481  virtual doublereal critTemperature() const {
1482  throw NotImplementedError("ThermoPhase::critTemperature");
1483  }
1484 
1485  /// Critical pressure (Pa).
1486  virtual doublereal critPressure() const {
1487  throw NotImplementedError("ThermoPhase::critPressure");
1488  }
1489 
1490  /// Critical volume (m3/kmol).
1491  virtual doublereal critVolume() const {
1492  throw NotImplementedError("ThermoPhase::critVolume");
1493  }
1494 
1495  /// Critical compressibility (unitless).
1496  virtual doublereal critCompressibility() const {
1497  throw NotImplementedError("ThermoPhase::critCompressibility");
1498  }
1499 
1500  /// Critical density (kg/m3).
1501  virtual doublereal critDensity() const {
1502  throw NotImplementedError("ThermoPhase::critDensity");
1503  }
1504 
1505  //@}
1506 
1507  /** @name Saturation Properties.
1508  *
1509  * These methods are only implemented by subclasses that implement full
1510  * liquid-vapor equations of state.
1511  */
1512  //@{
1513 
1514  //! Return the saturation temperature given the pressure
1515  /*!
1516  * @param p Pressure (Pa)
1517  */
1518  virtual doublereal satTemperature(doublereal p) const {
1519  throw NotImplementedError("ThermoPhase::satTemperature");
1520  }
1521 
1522  //! Return the saturation pressure given the temperature
1523  /*!
1524  * @param t Temperature (Kelvin)
1525  */
1526  virtual doublereal satPressure(doublereal t) {
1527  throw NotImplementedError("ThermoPhase::satPressure");
1528  }
1529 
1530  //! Return the fraction of vapor at the current conditions
1531  virtual doublereal vaporFraction() const {
1532  throw NotImplementedError("ThermoPhase::vaporFraction");
1533  }
1534 
1535  //! Set the state to a saturated system at a particular temperature
1536  /*!
1537  * @param t Temperature (kelvin)
1538  * @param x Fraction of vapor
1539  */
1540  virtual void setState_Tsat(doublereal t, doublereal x) {
1541  throw NotImplementedError("ThermoPhase::setState_Tsat");
1542  }
1543 
1544  //! Set the state to a saturated system at a particular pressure
1545  /*!
1546  * @param p Pressure (Pa)
1547  * @param x Fraction of vapor
1548  */
1549  virtual void setState_Psat(doublereal p, doublereal x) {
1550  throw NotImplementedError("ThermoPhase::setState_Psat");
1551  }
1552 
1553  //! Set the temperature, pressure, and vapor fraction (quality).
1554  /*!
1555  * An exception is thrown if the thermodynamic state is not consistent.
1556  *
1557  * For temperatures below the critical temperature, if the vapor fraction is
1558  * not 0 or 1, the pressure and temperature must fall on the saturation
1559  * line.
1560  *
1561  * Above the critical temperature, the vapor fraction must be 1 if the
1562  * pressure is less than the critical pressure. Above the critical pressure,
1563  * the vapor fraction is not defined, and its value is ignored.
1564  *
1565  * @param T Temperature (K)
1566  * @param P Pressure (Pa)
1567  * @param Q vapor fraction
1568  */
1569  void setState_TPQ(double T, double P, double Q);
1570 
1571  //@}
1572 
1573  //! @name Initialization Methods - For Internal Use (ThermoPhase)
1574  /*!
1575  * The following methods are used in the process of constructing
1576  * the phase and setting its parameters from a specification in an
1577  * input file. They are not normally used in application programs.
1578  * To see how they are used, see importPhase().
1579  */
1580  //@{
1581 
1582  virtual bool addSpecies(shared_ptr<Species> spec);
1583 
1584  virtual void modifySpecies(size_t k, shared_ptr<Species> spec);
1585 
1586  //! Store a reference pointer to the XML tree containing the species data
1587  //! for this phase.
1588  /*!
1589  * This is used to access data needed to construct transport manager later.
1590  * @internal
1591  *
1592  * @param k Species index
1593  * @param data Pointer to the XML_Node data containing
1594  * information about the species in the phase.
1595  *
1596  * @deprecated The XML input format is deprecated and will be removed in
1597  * Cantera 3.0.
1598  */
1599  void saveSpeciesData(const size_t k, const XML_Node* const data);
1600 
1601  //! Return a pointer to the vector of XML nodes containing the species
1602  //! data for this phase.
1603  //!
1604  //! @deprecated The XML input format is deprecated and will be removed in
1605  //! Cantera 3.0.
1606  const std::vector<const XML_Node*> & speciesData() const;
1607 
1608  //! Return a changeable reference to the calculation manager for species
1609  //! reference-state thermodynamic properties
1610  /*!
1611  * @param k Species id. The default is -1, meaning return the default
1612  *
1613  * @internal
1614  */
1615  virtual MultiSpeciesThermo& speciesThermo(int k = -1);
1616 
1617  virtual const MultiSpeciesThermo& speciesThermo(int k = -1) const;
1618 
1619  /**
1620  * @internal
1621  * Initialize a ThermoPhase object using an input file.
1622  *
1623  * Used to implement constructors for derived classes which take a
1624  * file name and phase name as arguments.
1625  *
1626  * @param inputFile Input file containing the description of the phase
1627  * @param id Optional parameter identifying the name of the phase. If
1628  * blank, the first phase definition encountered will be used.
1629  */
1630  virtual void initThermoFile(const std::string& inputFile,
1631  const std::string& id);
1632 
1633  //!Import and initialize a ThermoPhase object using an XML tree.
1634  /*!
1635  * @internal
1636  *
1637  * Here we read extra information about the XML description of a phase.
1638  * Regular information about elements and species and their reference state
1639  * thermodynamic information have already been read at this point. For
1640  * example, we do not need to call this function for ideal gas equations of
1641  * state. This function is called from importPhase() after the elements and
1642  * the species are initialized with default ideal solution level data.
1643  *
1644  * The default implementation in ThermoPhase calls the virtual function
1645  * initThermo() and then sets the "state" of the phase by looking for an XML
1646  * element named "state", and then interpreting its contents by calling the
1647  * virtual function setStateFromXML().
1648  *
1649  * @param phaseNode This object must be the phase node of a complete XML
1650  * tree description of the phase, including all of the species data. In
1651  * other words while "phase" must point to an XML phase object, it must
1652  * have sibling nodes "speciesData" that describe the species in the
1653  * phase.
1654  * @param id ID of the phase. If nonnull, a check is done to see if
1655  * phaseNode is pointing to the phase with the correct id.
1656  *
1657  * @deprecated The XML input format is deprecated and will be removed in
1658  * Cantera 3.0.
1659  */
1660  virtual void initThermoXML(XML_Node& phaseNode, const std::string& id);
1661 
1662  //! Initialize the ThermoPhase object after all species have been set up
1663  /*!
1664  * @internal Initialize.
1665  *
1666  * This method is provided to allow subclasses to perform any initialization
1667  * required after all species have been added. For example, it might be used
1668  * to resize internal work arrays that must have an entry for each species.
1669  * The base class implementation does nothing, and subclasses that do not
1670  * require initialization do not need to overload this method. Derived
1671  * classes which do override this function should call their parent class's
1672  * implementation of this function as their last action.
1673  *
1674  * When importing a CTML phase description, this method is called from
1675  * initThermoXML(), which is called from importPhase(), just prior to
1676  * returning from function importPhase().
1677  *
1678  * When importing from an AnyMap phase description (or from a YAML file),
1679  * this method is responsible for setting model parameters from the data
1680  * stored in #m_input.
1681  */
1682  virtual void initThermo();
1683 
1684  //! Set the equation of state parameters
1685  /*!
1686  * @internal The number and meaning of these depends on the subclass.
1687  *
1688  * @param n number of parameters
1689  * @param c array of \a n coefficients
1690  */
1691  virtual void setParameters(int n, doublereal* const c) {
1692  }
1693 
1694  //! Get the equation of state parameters in a vector
1695  /*!
1696  * @internal The number and meaning of these depends on the subclass.
1697  *
1698  * @param n number of parameters
1699  * @param c array of \a n coefficients
1700  */
1701  virtual void getParameters(int& n, doublereal* const c) const {
1702  }
1703 
1704  //! Set equation of state parameters from an AnyMap phase description.
1705  //! Phases that need additional parameters from the root node should
1706  //! override this method.
1707  virtual void setParameters(const AnyMap& phaseNode,
1708  const AnyMap& rootNode=AnyMap());
1709 
1710  //! Access input data associated with the phase description
1711  const AnyMap& input() const;
1712  AnyMap& input();
1713 
1714  //! Set equation of state parameter values from XML entries.
1715  /*!
1716  * This method is called by function importPhase() when processing a phase
1717  * definition in an input file. It should be overloaded in subclasses to set
1718  * any parameters that are specific to that particular phase model. Note,
1719  * this method is called before the phase is initialized with elements
1720  * and/or species.
1721  *
1722  * @param eosdata An XML_Node object corresponding to
1723  * the "thermo" entry for this phase in the input file.
1724  *
1725  * @deprecated The XML input format is deprecated and will be removed in
1726  * Cantera 3.0.
1727  */
1728  virtual void setParametersFromXML(const XML_Node& eosdata) {}
1729 
1730  //! Set the initial state of the phase to the conditions specified in the
1731  //! state XML element.
1732  /*!
1733  * This method sets the temperature, pressure, and mole fraction vector to a
1734  * set default value.
1735  *
1736  * @param state AN XML_Node object corresponding to the "state" entry for
1737  * this phase in the input file.
1738  *
1739  * @deprecated The XML input format is deprecated and will be removed in
1740  * Cantera 3.0.
1741  */
1742  virtual void setStateFromXML(const XML_Node& state);
1743 
1744  virtual void invalidateCache();
1745 
1746  //! @}
1747  //! @name Derivatives of Thermodynamic Variables needed for Applications
1748  //! @{
1749 
1750  //! Get the change in activity coefficients wrt changes in state (temp, mole
1751  //! fraction, etc) along a line in parameter space or along a line in
1752  //! physical space
1753  /*!
1754  * @param dTds Input of temperature change along the path
1755  * @param dXds Input vector of changes in mole fraction along the
1756  * path. length = m_kk Along the path length it must
1757  * be the case that the mole fractions sum to one.
1758  * @param dlnActCoeffds Output vector of the directional derivatives of the
1759  * log Activity Coefficients along the path. length =
1760  * m_kk units are 1/units(s). if s is a physical
1761  * coordinate then the units are 1/m.
1762  */
1763  virtual void getdlnActCoeffds(const doublereal dTds, const doublereal* const dXds,
1764  doublereal* dlnActCoeffds) const {
1765  throw NotImplementedError("ThermoPhase::getdlnActCoeffds");
1766  }
1767 
1768  //! Get the array of ln mole fraction derivatives of the log activity
1769  //! coefficients - diagonal component only
1770  /*!
1771  * For ideal mixtures (unity activity coefficients), this can return zero.
1772  * Implementations should take the derivative of the logarithm of the
1773  * activity coefficient with respect to the logarithm of the mole fraction
1774  * variable that represents the standard state. This quantity is to be used
1775  * in conjunction with derivatives of that mole fraction variable when the
1776  * derivative of the chemical potential is taken.
1777  *
1778  * units = dimensionless
1779  *
1780  * @param dlnActCoeffdlnX_diag Output vector of derivatives of the log
1781  * Activity Coefficients wrt the mole fractions. length = m_kk
1782  */
1783  virtual void getdlnActCoeffdlnX_diag(doublereal* dlnActCoeffdlnX_diag) const {
1784  throw NotImplementedError("ThermoPhase::getdlnActCoeffdlnX_diag");
1785  }
1786 
1787  //! Get the array of log species mole number derivatives of the log activity
1788  //! coefficients
1789  /*!
1790  * For ideal mixtures (unity activity coefficients), this can return zero.
1791  * Implementations should take the derivative of the logarithm of the
1792  * activity coefficient with respect to the logarithm of the concentration-
1793  * like variable (i.e. moles) that represents the standard state. This
1794  * quantity is to be used in conjunction with derivatives of that species
1795  * mole number variable when the derivative of the chemical potential is
1796  * taken.
1797  *
1798  * units = dimensionless
1799  *
1800  * @param dlnActCoeffdlnN_diag Output vector of derivatives of the
1801  * log Activity Coefficients. length = m_kk
1802  */
1803  virtual void getdlnActCoeffdlnN_diag(doublereal* dlnActCoeffdlnN_diag) const {
1804  throw NotImplementedError("ThermoPhase::getdlnActCoeffdlnN_diag");
1805  }
1806 
1807  //! Get the array of derivatives of the log activity coefficients with
1808  //! respect to the log of the species mole numbers
1809  /*!
1810  * Implementations should take the derivative of the logarithm of the
1811  * activity coefficient with respect to a species log mole number (with all
1812  * other species mole numbers held constant). The default treatment in the
1813  * ThermoPhase object is to set this vector to zero.
1814  *
1815  * units = 1 / kmol
1816  *
1817  * dlnActCoeffdlnN[ ld * k + m] will contain the derivative of log
1818  * act_coeff for the *m*-th species with respect to the number of moles of
1819  * the *k*-th species.
1820  *
1821  * \f[
1822  * \frac{d \ln(\gamma_m) }{d \ln( n_k ) }\Bigg|_{n_i}
1823  * \f]
1824  *
1825  * @param ld Number of rows in the matrix
1826  * @param dlnActCoeffdlnN Output vector of derivatives of the
1827  * log Activity Coefficients. length = m_kk * m_kk
1828  */
1829  virtual void getdlnActCoeffdlnN(const size_t ld, doublereal* const dlnActCoeffdlnN);
1830 
1831  virtual void getdlnActCoeffdlnN_numderiv(const size_t ld, doublereal* const dlnActCoeffdlnN);
1832 
1833  //! @}
1834  //! @name Printing
1835  //! @{
1836 
1837  //! returns a summary of the state of the phase as a string
1838  /*!
1839  * @param show_thermo If true, extra information is printed out
1840  * about the thermodynamic state of the system.
1841  * @param threshold Show information about species with mole fractions
1842  * greater than *threshold*.
1843  */
1844  virtual std::string report(bool show_thermo=true,
1845  doublereal threshold=-1e-14) const;
1846 
1847  //! returns a summary of the state of the phase to a comma separated file.
1848  /*!
1849  * To customize the data included in the report, derived classes should
1850  * override the getCsvReportData method.
1851  *
1852  * @param csvFile ofstream file to print comma separated data for the phase
1853  */
1854  virtual void reportCSV(std::ofstream& csvFile) const;
1855 
1856  //@}
1857 
1858 protected:
1859  //! Fills `names` and `data` with the column names and species thermo
1860  //! properties to be included in the output of the reportCSV method.
1861  virtual void getCsvReportData(std::vector<std::string>& names,
1862  std::vector<vector_fp>& data) const;
1863 
1864  //! Pointer to the calculation manager for species reference-state
1865  //! thermodynamic properties
1866  /*!
1867  * This class is called when the reference-state thermodynamic properties
1868  * of all the species in the phase needs to be evaluated.
1869  */
1871 
1872  //! Data supplied via setParameters. When first set, this may include
1873  //! parameters used by different phase models when initThermo() is called.
1875 
1876  //! Vector of pointers to the species databases.
1877  /*!
1878  * This is used to access data needed to construct the transport manager and
1879  * other properties later in the initialization process. We create a copy of
1880  * the XML_Node data read in here. Therefore, we own this data.
1881  *
1882  * @deprecated The XML input format is deprecated and will be removed in
1883  * Cantera 3.0.
1884  */
1885  std::vector<const XML_Node*> m_speciesData;
1886 
1887  //! Stored value of the electric potential for this phase. Units are Volts.
1888  doublereal m_phi;
1889 
1890  //! Boolean indicating whether a charge neutrality condition is a necessity
1891  /*!
1892  * Note, the charge neutrality condition is not a necessity for ideal gas
1893  * phases. There may be a net charge in those phases, because the NASA
1894  * polynomials for ionized species in Ideal gases take this condition into
1895  * account. However, liquid phases usually require charge neutrality in
1896  * order for their derived thermodynamics to be valid.
1897  */
1899 
1900  //! Contains the standard state convention
1902 
1903  //! last value of the temperature processed by reference state
1904  mutable doublereal m_tlast;
1905 };
1906 
1907 //! typedef for the ThermoPhase class
1909 
1910 }
1911 
1912 #endif
Header for a general species thermodynamic property manager for a phase (see MultiSpeciesThermo).
Header file for class Phase.
A map of string keys to values whose type can vary at runtime.
Definition: AnyMap.h:360
A species thermodynamic property manager for a phase.
virtual doublereal minTemp(size_t k=npos) const
Minimum temperature.
virtual doublereal refPressure(size_t k=npos) const
The reference-state pressure for species k.
virtual void modifyOneHf298(const size_t k, const doublereal Hf298New)
Modify the value of the 298 K Heat of Formation of the standard state of one species in the phase (J ...
virtual doublereal reportOneHf298(const size_t k) const
Report the 298 K Heat of Formation of the standard state of one species (J kmol-1)
virtual doublereal maxTemp(size_t k=npos) const
Maximum temperature.
An error indicating that an unimplemented function has been called.
Definition: ctexceptions.h:187
Class Phase is the base class for phases of matter, managing the species and elements in a phase,...
Definition: Phase.h:101
size_t m_kk
Number of species in the phase.
Definition: Phase.h:942
doublereal meanMolecularWeight() const
The mean molecular weight. Units: (kg/kmol)
Definition: Phase.h:748
doublereal temperature() const
Temperature (K).
Definition: Phase.h:667
double molarVolume() const
Molar volume (m^3/kmol).
Definition: Phase.cpp:711
virtual double pressure() const
Return the thermodynamic pressure (Pa).
Definition: Phase.h:679
Base class for a phase with thermodynamic properties.
Definition: ThermoPhase.h:102
virtual void setStateFromXML(const XML_Node &state)
Set the initial state of the phase to the conditions specified in the state XML element.
int m_ssConvention
Contains the standard state convention.
Definition: ThermoPhase.h:1901
virtual std::string report(bool show_thermo=true, doublereal threshold=-1e-14) const
returns a summary of the state of the phase as a string
virtual void setState_TPY(doublereal t, doublereal p, const doublereal *y)
Set the internally stored temperature (K), pressure (Pa), and mass fractions of the phase.
virtual void getPartialMolarEntropies(doublereal *sbar) const
Returns an array of partial molar entropies of the species in the solution.
Definition: ThermoPhase.h:525
void setElectricPotential(doublereal v)
Set the electric potential of this phase (V).
Definition: ThermoPhase.h:312
virtual void setState_PY(doublereal p, doublereal *y)
Set the internally stored pressure (Pa) and mass fractions.
virtual void setState_HP(double h, double p, double tol=1e-9)
Set the internally stored specific enthalpy (J/kg) and pressure (Pa) of the phase.
virtual void getIntEnergy_RT_ref(doublereal *urt) const
Returns the vector of nondimensional internal Energies of the reference state at the current temperat...
Definition: ThermoPhase.h:707
virtual doublereal gibbs_mole() const
Molar Gibbs function. Units: J/kmol.
Definition: ThermoPhase.h:249
virtual void setState_UV(double u, double v, double tol=1e-9)
Set the specific internal energy (J/kg) and specific volume (m^3/kg).
bool chargeNeutralityNecessary() const
Returns the chargeNeutralityNecessity boolean.
Definition: ThermoPhase.h:225
virtual bool addSpecies(shared_ptr< Species > spec)
double equivalenceRatio() const
Compute the equivalence ratio for the current mixture from available oxygen and required oxygen.
doublereal entropy_mass() const
Specific entropy. Units: J/kg/K.
Definition: ThermoPhase.h:752
virtual void setState_TP(doublereal t, doublereal p)
Set the temperature (K) and pressure (Pa)
virtual void getIntEnergy_RT(doublereal *urt) const
Returns the vector of nondimensional Internal Energies of the standard state species at the current T...
Definition: ThermoPhase.h:625
virtual doublereal critPressure() const
Critical pressure (Pa).
Definition: ThermoPhase.h:1486
virtual void getPartialMolarEnthalpies(doublereal *hbar) const
Returns an array of partial molar enthalpies for the species in the mixture.
Definition: ThermoPhase.h:515
virtual void getGibbs_ref(doublereal *g) const
Returns the vector of the Gibbs function of the reference state at the current temperature of the sol...
Definition: ThermoPhase.h:685
doublereal RT() const
Return the Gas Constant multiplied by the current temperature.
Definition: ThermoPhase.h:776
virtual void getActivities(doublereal *a) const
Get the array of non-dimensional activities at the current solution temperature, pressure,...
Definition: ThermoPhase.cpp:75
virtual doublereal isothermalCompressibility() const
Returns the isothermal compressibility. Units: 1/Pa.
Definition: ThermoPhase.h:278
virtual void getLnActivityCoefficients(doublereal *lnac) const
Get the array of non-dimensional molar-based ln activity coefficients at the current solution tempera...
Definition: ThermoPhase.cpp:83
doublereal m_tlast
last value of the temperature processed by reference state
Definition: ThermoPhase.h:1904
virtual doublereal critTemperature() const
Critical temperature (K).
Definition: ThermoPhase.h:1481
virtual void setState_TV(double t, double v, double tol=1e-9)
Set the temperature (K) and specific volume (m^3/kg).
Definition: ThermoPhase.h:975
double o2Present(const double *y) const
Helper function for computing the amount of oxygen available in the current mixture.
virtual void setState_Tsat(doublereal t, doublereal x)
Set the state to a saturated system at a particular temperature.
Definition: ThermoPhase.h:1540
virtual void getCp_R(doublereal *cpr) const
Get the nondimensional Heat Capacities at constant pressure for the species standard states at the cu...
Definition: ThermoPhase.h:636
virtual void setState_PV(double p, double v, double tol=1e-9)
Set the pressure (Pa) and specific volume (m^3/kg).
Definition: ThermoPhase.h:991
virtual doublereal satPressure(doublereal t)
Return the saturation pressure given the temperature.
Definition: ThermoPhase.h:1526
virtual void setState(const AnyMap &state)
Set the state using an AnyMap containing any combination of properties supported by the thermodynamic...
void setState_SPorSV(double s, double p, double tol=1e-9, bool doSV=false)
Carry out work in SP and SV calculations.
virtual void getEnthalpy_RT(doublereal *hrt) const
Get the nondimensional Enthalpy functions for the species at their standard states at the current T a...
Definition: ThermoPhase.h:584
void setState_HPorUV(doublereal h, doublereal p, doublereal tol=1e-9, bool doUV=false)
Carry out work in HP and UV calculations.
virtual void getStandardVolumes(doublereal *vol) const
Get the molar volumes of the species standard states at the current T and P of the solution.
Definition: ThermoPhase.h:648
virtual void getChemPotentials(doublereal *mu) const
Get the species chemical potentials. Units: J/kmol.
Definition: ThermoPhase.h:489
virtual void getActivityCoefficients(doublereal *ac) const
Get the array of non-dimensional molar-based activity coefficients at the current solution temperatur...
Definition: ThermoPhase.h:448
virtual void initThermoFile(const std::string &inputFile, const std::string &id)
virtual void initThermoXML(XML_Node &phaseNode, const std::string &id)
Import and initialize a ThermoPhase object using an XML tree.
doublereal gibbs_mass() const
Specific Gibbs function. Units: J/kg.
Definition: ThermoPhase.h:757
virtual doublereal critVolume() const
Critical volume (m3/kmol).
Definition: ThermoPhase.h:1491
virtual doublereal logStandardConc(size_t k=0) const
Natural logarithm of the standard concentration of the kth species.
Definition: ThermoPhase.cpp:70
virtual void modifySpecies(size_t k, shared_ptr< Species > spec)
Modify the thermodynamic data associated with a species.
virtual void getCp_R_ref(doublereal *cprt) const
Returns the vector of nondimensional constant pressure heat capacities of the reference state at the ...
Definition: ThermoPhase.h:719
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 ...
virtual void setState_ST(double s, double t, double tol=1e-9)
Set the specific entropy (J/kg/K) and temperature (K).
Definition: ThermoPhase.h:959
virtual void getdlnActCoeffdlnN_diag(doublereal *dlnActCoeffdlnN_diag) const
Get the array of log species mole number derivatives of the log activity coefficients.
Definition: ThermoPhase.h:1803
double stoichAirFuelRatio(const double *fuelComp, const double *oxComp, ThermoBasis basis=ThermoBasis::molar) const
Compute the stoichiometric air to fuel ratio (kg oxidizer / kg fuel) given fuel and oxidizer composit...
virtual doublereal entropy_mole() const
Molar entropy. Units: J/kmol/K.
Definition: ThermoPhase.h:244
virtual void setState_RPY(doublereal rho, doublereal p, const doublereal *y)
Set the density (kg/m**3), pressure (Pa) and mass fractions.
virtual doublereal critDensity() const
Critical density (kg/m3).
Definition: ThermoPhase.h:1501
bool m_chargeNeutralityNecessary
Boolean indicating whether a charge neutrality condition is a necessity.
Definition: ThermoPhase.h:1898
virtual void getEntropy_R(doublereal *sr) const
Get the array of nondimensional Entropy functions for the standard state species at the current T and...
Definition: ThermoPhase.h:594
virtual void setState_TPX(doublereal t, doublereal p, const doublereal *x)
Set the temperature (K), pressure (Pa), and mole fractions.
const std::vector< const XML_Node * > & speciesData() const
Return a pointer to the vector of XML nodes containing the species data for this phase.
virtual void getGibbs_RT_ref(doublereal *grt) const
Returns the vector of nondimensional Gibbs Free Energies of the reference state at the current temper...
Definition: ThermoPhase.h:674
virtual void getPartialMolarVolumes(doublereal *vbar) const
Return an array of partial molar volumes for the species in the mixture.
Definition: ThermoPhase.h:556
doublereal cp_mass() const
Specific heat at constant pressure. Units: J/kg/K.
Definition: ThermoPhase.h:762
virtual void getPartialMolarCp(doublereal *cpbar) const
Return an array of partial molar heat capacities for the species in the mixture.
Definition: ThermoPhase.h:546
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...
virtual doublereal cp_mole() const
Molar heat capacity at constant pressure. Units: J/kmol/K.
Definition: ThermoPhase.h:254
virtual void setState_PX(doublereal p, doublereal *x)
Set the pressure (Pa) and mole fractions.
virtual std::string phaseOfMatter() const
String indicating the mechanical phase of the matter in this Phase.
Definition: ThermoPhase.h:137
virtual doublereal refPressure() const
Returns the reference pressure in Pa.
Definition: ThermoPhase.h:145
double o2Required(const double *y) const
Helper function for computing the amount of oxygen required for complete oxidation.
virtual doublereal cv_mole() const
Molar heat capacity at constant volume. Units: J/kmol/K.
Definition: ThermoPhase.h:259
ThermoPhase()
Constructor.
Definition: ThermoPhase.cpp:27
virtual doublereal intEnergy_mole() const
Molar internal energy. Units: J/kmol.
Definition: ThermoPhase.h:239
virtual void getActivityConcentrations(doublereal *c) const
This method returns an array of generalized concentrations.
Definition: ThermoPhase.h:398
virtual doublereal critCompressibility() const
Critical compressibility (unitless).
Definition: ThermoPhase.h:1496
virtual void getPartialMolarIntEnergies(doublereal *ubar) const
Return an array of partial molar internal energies for the species in the mixture.
Definition: ThermoPhase.h:535
virtual int activityConvention() const
This method returns the convention used in specification of the activities, of which there are curren...
Definition: ThermoPhase.cpp:54
virtual void initThermo()
Initialize the ThermoPhase object after all species have been set up.
virtual doublereal standardConcentration(size_t k=0) const
Return the standard concentration for the kth species.
Definition: ThermoPhase.h:419
virtual void getdlnActCoeffdlnX_diag(doublereal *dlnActCoeffdlnX_diag) const
Get the array of ln mole fraction derivatives of the log activity coefficients - diagonal component o...
Definition: ThermoPhase.h:1783
void saveSpeciesData(const size_t k, const XML_Node *const data)
Store a reference pointer to the XML tree containing the species data for this phase.
virtual void getChemPotentials_RT(doublereal *mu) const
Get the array of non-dimensional species chemical potentials These are partial molar Gibbs free energ...
Definition: ThermoPhase.h:476
virtual MultiSpeciesThermo & speciesThermo(int k=-1)
Return a changeable reference to the calculation manager for species reference-state thermodynamic pr...
virtual void setState_UP(double u, double p, double tol=1e-9)
Set the specific internal energy (J/kg) and pressure (Pa).
Definition: ThermoPhase.h:1007
virtual void getPureGibbs(doublereal *gpure) const
Get the Gibbs functions for the standard state of the species at the current T and P of the solution.
Definition: ThermoPhase.h:615
virtual doublereal satTemperature(doublereal p) const
Return the saturation temperature given the pressure.
Definition: ThermoPhase.h:1518
virtual void setState_SP(double s, double p, double tol=1e-9)
Set the specific entropy (J/kg/K) and pressure (Pa).
virtual int standardStateConvention() const
This method returns the convention used in specification of the standard state, of which there are cu...
Definition: ThermoPhase.cpp:59
virtual doublereal maxTemp(size_t k=npos) const
Maximum temperature for which the thermodynamic data for the species are valid.
Definition: ThermoPhase.h:213
virtual void setState_SH(double s, double h, double tol=1e-9)
Set the specific entropy (J/kg/K) and the specific enthalpy (J/kg)
Definition: ThermoPhase.h:1055
void getElectrochemPotentials(doublereal *mu) const
Get the species electrochemical potentials.
Definition: ThermoPhase.cpp:91
virtual std::string type() const
String indicating the thermodynamic model implemented.
Definition: ThermoPhase.h:113
doublereal cv_mass() const
Specific heat at constant volume. Units: J/kg/K.
Definition: ThermoPhase.h:767
virtual void setState_RP(doublereal rho, doublereal p)
Set the density (kg/m**3) and pressure (Pa) at constant composition.
Definition: ThermoPhase.h:1072
void setMixtureFraction(double mixFrac, const double *fuelComp, const double *oxComp, ThermoBasis basis=ThermoBasis::molar)
Set the mixture composition according to the mixture fraction = kg fuel / (kg oxidizer + kg fuel)
virtual void resetHf298(const size_t k=npos)
Restore the original heat of formation of one or more species.
Definition: ThermoPhase.cpp:43
virtual void setState_TH(double t, double h, double tol=1e-9)
Set the temperature (K) and the specific enthalpy (J/kg)
Definition: ThermoPhase.h:1039
virtual Units standardConcentrationUnits() const
Returns the units of the "standard concentration" for this phase.
Definition: ThermoPhase.cpp:64
virtual void setState_Psat(doublereal p, doublereal x)
Set the state to a saturated system at a particular pressure.
Definition: ThermoPhase.h:1549
std::vector< const XML_Node * > m_speciesData
Vector of pointers to the species databases.
Definition: ThermoPhase.h:1885
doublereal intEnergy_mass() const
Specific internal energy. Units: J/kg.
Definition: ThermoPhase.h:747
virtual void setState_RPX(doublereal rho, doublereal p, const doublereal *x)
Set the density (kg/m**3), pressure (Pa) and mole fractions.
virtual void modifyOneHf298SS(const size_t k, const doublereal Hf298New)
Modify the value of the 298 K Heat of Formation of one species in the phase (J kmol-1)
Definition: ThermoPhase.h:190
virtual void getEnthalpy_RT_ref(doublereal *hrt) const
Returns the vector of nondimensional enthalpies of the reference state at the current temperature of ...
Definition: ThermoPhase.h:663
virtual doublereal enthalpy_mole() const
Molar enthalpy. Units: J/kmol.
Definition: ThermoPhase.h:234
virtual doublereal thermalExpansionCoeff() const
Return the volumetric thermal expansion coefficient. Units: 1/K.
Definition: ThermoPhase.h:289
MultiSpeciesThermo m_spthermo
Pointer to the calculation manager for species reference-state thermodynamic properties.
Definition: ThermoPhase.h:1870
virtual void setParameters(int n, doublereal *const c)
Set the equation of state parameters.
Definition: ThermoPhase.h:1691
virtual void getdlnActCoeffds(const doublereal dTds, const doublereal *const dXds, doublereal *dlnActCoeffds) const
Get the change in activity coefficients wrt changes in state (temp, mole fraction,...
Definition: ThermoPhase.h:1763
doublereal m_phi
Stored value of the electric potential for this phase. Units are Volts.
Definition: ThermoPhase.h:1888
doublereal enthalpy_mass() const
Specific enthalpy. Units: J/kg.
Definition: ThermoPhase.h:742
virtual void getGibbs_RT(doublereal *grt) const
Get the nondimensional Gibbs functions for the species in their standard states at the current T and ...
Definition: ThermoPhase.h:604
double mixtureFraction(const double *fuelComp, const double *oxComp, ThermoBasis basis=ThermoBasis::molar, const std::string &element="Bilger") const
Compute the mixture fraction = kg fuel / (kg oxidizer + kg fuel) for the current mixture given fuel a...
AnyMap m_input
Data supplied via setParameters.
Definition: ThermoPhase.h:1874
virtual doublereal minTemp(size_t k=npos) const
Minimum temperature for which the thermodynamic data for the species or phase are valid.
Definition: ThermoPhase.h:160
virtual void reportCSV(std::ofstream &csvFile) const
returns a summary of the state of the phase to a comma separated file.
virtual void getEntropy_R_ref(doublereal *er) const
Returns the vector of nondimensional entropies of the reference state at the current temperature of t...
Definition: ThermoPhase.h:696
void setEquivalenceRatio(double phi, const double *fuelComp, const double *oxComp, ThermoBasis basis=ThermoBasis::molar)
Set the mixture composition according to the equivalence ratio.
void setState_TPQ(double T, double P, double Q)
Set the temperature, pressure, and vapor fraction (quality).
virtual void invalidateCache()
Invalidate any cached values which are normally updated only when a change in state is detected.
void setState_conditional_TP(doublereal t, doublereal p, bool set_p)
Helper function used by setState_HPorUV and setState_SPorSV.
virtual void getStandardChemPotentials(doublereal *mu) const
Get the array of chemical potentials at unit activity for the species at their standard states at the...
Definition: ThermoPhase.h:574
virtual void setState_VH(double v, double h, double tol=1e-9)
Set the specific volume (m^3/kg) and the specific enthalpy (J/kg)
Definition: ThermoPhase.h:1023
virtual void setParametersFromXML(const XML_Node &eosdata)
Set equation of state parameter values from XML entries.
Definition: ThermoPhase.h:1728
doublereal electricPotential() const
Returns the electric potential of this phase (V).
Definition: ThermoPhase.h:320
virtual void setState_SV(double s, double v, double tol=1e-9)
Set the specific entropy (J/kg/K) and specific volume (m^3/kg).
doublereal Hf298SS(const size_t k) const
Report the 298 K Heat of Formation of the standard state of one species (J kmol-1)
Definition: ThermoPhase.h:175
const AnyMap & input() const
Access input data associated with the phase description.
virtual void getParameters(int &n, doublereal *const c) const
Get the equation of state parameters in a vector.
Definition: ThermoPhase.h:1701
virtual void getStandardVolumes_ref(doublereal *vol) const
Get the molar volumes of the species reference states at the current T and P_ref of the solution.
Definition: ThermoPhase.h:731
virtual doublereal vaporFraction() const
Return the fraction of vapor at the current conditions.
Definition: ThermoPhase.h:1531
A representation of the units associated with a dimensional quantity.
Definition: Units.h:30
Class XML_Node is a tree-based representation of the contents of an XML file.
Definition: xml.h:104
This file contains definitions for utility functions and text for modules, inputfiles,...
virtual bool compatibleWithMultiPhase() const
Indicates whether this phase type can be used with class MultiPhase for equilibrium calculations.
Definition: ThermoPhase.h:1470
virtual void setToEquilState(const doublereal *mu_RT)
This method is used by the ChemEquil equilibrium solver.
Definition: ThermoPhase.h:1463
void equilibrate(const std::string &XY, const std::string &solver="auto", double rtol=1e-9, int max_steps=50000, int max_iter=100, int estimate_equil=0, int log_level=0)
Equilibrate a ThermoPhase object.
const size_t npos
index returned by functions to indicate "no position"
Definition: ct_defs.h:188
const double GasConstant
Universal Gas Constant [J/kmol/K].
Definition: ct_defs.h:109
std::map< std::string, double > compositionMap
Map connecting a string name with a double.
Definition: ct_defs.h:172
Namespace for the Cantera kernel.
Definition: AnyMap.cpp:264
const int cSS_CONVENTION_VPSS
Standard state uses the molality convention.
Definition: ThermoPhase.h:38
const int cAC_CONVENTION_MOLAR
Standard state uses the molar convention.
Definition: ThermoPhase.h:26
ThermoPhase thermo_t
typedef for the ThermoPhase class
Definition: ThermoPhase.h:1908
const int cSS_CONVENTION_TEMPERATURE
Standard state uses the molar convention.
Definition: ThermoPhase.h:36
ThermoBasis
Differentiate between mole fractions and mass fractions for input mixture composition.
Definition: ThermoPhase.h:45
const int cSS_CONVENTION_SLAVE
Standard state thermodynamics is obtained from slave ThermoPhase objects.
Definition: ThermoPhase.h:40
const int cAC_CONVENTION_MOLALITY
Standard state uses the molality convention.
Definition: ThermoPhase.h:28