Cantera  2.1.2
PureFluidPhase.h
Go to the documentation of this file.
1 /**
2  * @file PureFluidPhase.h
3  *
4  * Header for a ThermoPhase class for a pure fluid phase consisting of
5  * gas, liquid, mixed-gas-liquid and supercrit fluid (see \ref thermoprops
6  * and class \link Cantera::PureFluidPhase PureFluidPhase\endlink).
7  *
8  * It inherits from ThermoPhase, but is built on top of the tpx package.
9  */
10 
11 // Copyright 2003 California Institute of Technology
12 
13 #ifndef CT_EOS_TPX_H
14 #define CT_EOS_TPX_H
15 
16 #include "ThermoPhase.h"
17 #include "mix_defs.h"
18 #include "cantera/tpx/Sub.h"
19 
20 namespace Cantera
21 {
22 //! This phase object consists of a single component that can be a
23 //! gas, a liquid, a mixed gas-liquid fluid, or a fluid beyond its
24 //! critical point
25 /*!
26  * The object inherits from ThermoPhase. However, it's built on top
27  * of the tpx package.
28  *
29  * @ingroup thermoprops
30  */
32 {
33 public:
34 
35  //! Empty Base Constructor
37 
38  //! Copy Constructor
39  /*!
40  * @param right Object to be copied
41  */
42  PureFluidPhase(const PureFluidPhase& right);
43 
44  //! Assignment operator
45  /*!
46  * @param right Object to be copied
47  */
49 
50  //! Destructor
51  virtual ~PureFluidPhase();
52 
53  //! Duplication function
54  /*!
55  * This virtual function is used to create a duplicate of the
56  * current phase. It's used to duplicate the phase when given
57  * a ThermoPhase pointer to the phase.
58  *
59  * @return It returns a ThermoPhase pointer.
60  */
62 
63  //! Equation of state type
64  virtual int eosType() const {
65  return cPureFluid;
66  }
67 
68  /// Molar enthalpy. Units: J/kmol.
69  virtual doublereal enthalpy_mole() const;
70 
71  /// Molar internal energy. Units: J/kmol.
72  virtual doublereal intEnergy_mole() const;
73 
74  /// Molar entropy. Units: J/kmol/K.
75  virtual doublereal entropy_mole() const;
76 
77  /// Molar Gibbs function. Units: J/kmol.
78  virtual doublereal gibbs_mole() const;
79 
80  /// Molar heat capacity at constant pressure. Units: J/kmol/K.
81  virtual doublereal cp_mole() const;
82 
83  /// Molar heat capacity at constant volume. Units: J/kmol/K.
84  virtual doublereal cv_mole() const;
85 
86  //! Return the thermodynamic pressure (Pa).
87  /*!
88  * This method calculates the current pressure consistent with the
89  * independent variables, T, rho.
90  */
91  virtual doublereal pressure() const;
92 
93  //! sets the thermodynamic pressure (Pa).
94  /*!
95  * This method calculates the density that is consistent with the
96  * desired pressure, given the temperature.
97  *
98  * @param p Pressure (Pa)
99  */
100  virtual void setPressure(doublereal p);
101 
102  //! Get the species chemical potentials. Units: J/kmol.
103  /*!
104  * This function returns a vector of chemical potentials of the
105  * species in solution at the current temperature, pressure
106  * and mole fraction of the solution.
107  *
108  * @param mu Output vector of species chemical
109  * potentials. Length: m_kk. Units: J/kmol
110  */
111  virtual void getChemPotentials(doublereal* mu) const {
112  mu[0] = gibbs_mole();
113  }
114 
115  //! Get the species electrochemical potentials.
116  /*!
117  * These are partial molar quantities. This method adds a term \f$ F z_k
118  * \phi_p \f$ to each chemical potential.
119  * The electrochemical potential of species k in a phase p, \f$ \zeta_k \f$,
120  * is related to the chemical potential via
121  * the following equation,
122  *
123  * \f[
124  * \zeta_{k}(T,P) = \mu_{k}(T,P) + F z_k \phi_p
125  * \f]
126  *
127  * @param mu Output vector of species electrochemical
128  * potentials. Length: m_kk. Units: J/kmol
129  */
130  void getElectrochemPotentials(doublereal* mu) const {
131  getChemPotentials(mu);
132  double ve = Faraday * electricPotential();
133  for (size_t k = 0; k < m_kk; k++) {
134  mu[k] += ve*charge(k);
135  }
136  }
137 
138  //! Returns an array of partial molar enthalpies for the species
139  //! in the mixture. Units (J/kmol)
140  /*!
141  * @param hbar Output vector of species partial molar enthalpies.
142  * Length: m_kk. units are J/kmol.
143  */
144  virtual void getPartialMolarEnthalpies(doublereal* hbar) const;
145 
146  //! Returns an array of partial molar entropies of the species in the
147  //! solution. Units: J/kmol/K.
148  /*!
149  * @param sbar Output vector of species partial molar entropies.
150  * Length = m_kk. units are J/kmol/K.
151  */
152  virtual void getPartialMolarEntropies(doublereal* sbar) const;
153 
154  //! Return an array of partial molar internal energies for the
155  //! species in the mixture. Units: J/kmol.
156  /*!
157  * @param ubar Output vector of species partial molar internal energies.
158  * Length = m_kk. units are J/kmol.
159  */
160  virtual void getPartialMolarIntEnergies(doublereal* ubar) const;
161 
162  //! Return an array of partial molar heat capacities for the
163  //! species in the mixture. Units: J/kmol/K
164  /*!
165  * @param cpbar Output vector of species partial molar heat
166  * capacities at constant pressure.
167  * Length = m_kk. units are J/kmol/K.
168  */
169  virtual void getPartialMolarCp(doublereal* cpbar) const;
170 
171  //! Return an array of partial molar volumes for the
172  //! species in the mixture. Units: m^3/kmol.
173  /*!
174  * @param vbar Output vector of species partial molar volumes.
175  * Length = m_kk. units are m^3/kmol.
176  */
177  virtual void getPartialMolarVolumes(doublereal* vbar) const;
178 
179  //! This method returns the convention used in specification
180  //! of the standard state, of which there are currently two,
181  //! temperature based, and variable pressure based.
182  /*!
183  * Currently, there are two standard state conventions:
184  * - Temperature-based activities
185  * cSS_CONVENTION_TEMPERATURE 0
186  * - default
187  *
188  * - Variable Pressure and Temperature -based activities
189  * cSS_CONVENTION_VPSS 1
190  *
191  * - Thermodynamics is set via slave ThermoPhase objects with
192  * nothing being carried out at this %ThermoPhase object level
193  * cSS_CONVENTION_SLAVE 2
194  */
195  virtual int standardStateConvention() const;
196 
197  //! This method returns an array of generalized concentrations
198  /*!
199  * \f$ C^a_k\f$ are defined such that \f$ a_k = C^a_k /
200  * C^0_k, \f$ where \f$ C^0_k \f$ is a standard concentration
201  * defined below and \f$ a_k \f$ are activities used in the
202  * thermodynamic functions. These activity (or generalized)
203  * concentrations are used
204  * by kinetics manager classes to compute the forward and
205  * reverse rates of elementary reactions. Note that they may
206  * or may not have units of concentration --- they might be
207  * partial pressures, mole fractions, or surface coverages,
208  * for example.
209  *
210  * @param c Output array of generalized concentrations. The
211  * units depend upon the implementation of the
212  * reaction rate expressions within the phase.
213  */
214  virtual void getActivityConcentrations(doublereal* c) const;
215 
216  //! Return the standard concentration for the kth species
217  /*!
218  * The standard concentration \f$ C^0_k \f$ used to normalize
219  * the activity (i.e., generalized) concentration. In many cases, this quantity
220  * will be the same for all species in a phase - for example,
221  * for an ideal gas \f$ C^0_k = P/\hat R T \f$. For this
222  * reason, this method returns a single value, instead of an
223  * array. However, for phases in which the standard
224  * concentration is species-specific (e.g. surface species of
225  * different sizes), this method may be called with an
226  * optional parameter indicating the species.
227  *
228  * @param k Optional parameter indicating the species. The default
229  * is to assume this refers to species 0.
230  * @return
231  * Returns the standard concentration. The units are by definition
232  * dependent on the ThermoPhase and kinetics manager representation.
233  */
234  virtual doublereal standardConcentration(size_t k=0) const;
235 
236  //! Get the array of non-dimensional activities at
237  //! the current solution temperature, pressure, and solution concentration.
238  /*!
239  * Note, for molality based formulations, this returns the
240  * molality based activities.
241  *
242  * We resolve this function at this level by calling
243  * on the activityConcentration function. However,
244  * derived classes may want to override this default
245  * implementation.
246  *
247  * @param a Output vector of activities. Length: m_kk.
248  */
249  virtual void getActivities(doublereal* a) const;
250 
251  //! Returns the isothermal compressibility. Units: 1/Pa.
252  /*!
253  * The isothermal compressibility is defined as
254  * \f[
255  * \kappa_T = -\frac{1}{v}\left(\frac{\partial v}{\partial P}\right)_T
256  * \f]
257  */
258  virtual doublereal isothermalCompressibility() const;
259 
260  //! Return the volumetric thermal expansion coefficient. Units: 1/K.
261  /*!
262  * The thermal expansion coefficient is defined as
263  * \f[
264  * \beta = \frac{1}{v}\left(\frac{\partial v}{\partial T}\right)_P
265  * \f]
266  */
267  virtual doublereal thermalExpansionCoeff() const;
268 
269  //! Returns a reference to the substance object
271 
272  //@}
273  /// @name Properties of the Standard State of the Species in the Solution
274  /*!
275  * The standard state of the pure fluid is defined as the real properties
276  * of the pure fluid at the most stable state of the fluid at the current
277  * temperature and pressure of the solution. With this definition, the
278  * activity of the fluid is always then defined to be equal to one.
279  */
280  //@{
281 
282  //! Get the array of chemical potentials at unit activity for the species
283  //! at their standard states at the current <I>T</I> and <I>P</I> of the solution.
284  /*!
285  * These are the standard state chemical potentials \f$ \mu^0_k(T,P)
286  * \f$. The values are evaluated at the current
287  * temperature and pressure of the solution
288  *
289  * @param mu Output vector of chemical potentials.
290  * Length: m_kk.
291  */
292  virtual void getStandardChemPotentials(doublereal* mu) const;
293 
294  //! Get the nondimensional Enthalpy functions for the species
295  //! at their standard states at the current <I>T</I> and <I>P</I> of the solution.
296  /*!
297  * @param hrt Output vector of nondimensional standard state enthalpies.
298  * Length: m_kk.
299  */
300  virtual void getEnthalpy_RT(doublereal* hrt) const;
301 
302  //! Get the array of nondimensional Entropy functions for the
303  //! standard state species at the current <I>T</I> and <I>P</I> of the solution.
304  /*!
305  * @param sr Output vector of nondimensional standard state entropies.
306  * Length: m_kk.
307  */
308  virtual void getEntropy_R(doublereal* sr) const;
309 
310  //! Get the nondimensional Gibbs functions for the species
311  //! in their standard states at the current <I>T</I> and <I>P</I> of the solution.
312  /*!
313  * @param grt Output vector of nondimensional standard state gibbs free energies
314  * Length: m_kk.
315  */
316  virtual void getGibbs_RT(doublereal* grt) const;
317 
318  //@}
319 
320  /// @name Thermodynamic Values for the Species Reference States
321  /*!
322  * The species reference state for pure fluids is defined as an ideal gas at the
323  * reference pressure and current temperature of the fluid.
324  */
325  //@{
326 
327  //! Returns the vector of nondimensional enthalpies of the reference state at the current temperature
328  //! of the solution and the reference pressure for the species.
329  /*!
330  * @param hrt Output vector containing the nondimensional reference state enthalpies
331  * Length: m_kk.
332  */
333  virtual void getEnthalpy_RT_ref(doublereal* hrt) const;
334 
335  //! Returns the vector of nondimensional Gibbs Free Energies of the reference state at the current temperature
336  //! of the solution and the reference pressure for the species.
337  /*!
338  * @param grt Output vector containing the nondimensional reference state
339  * Gibbs Free energies. Length: m_kk.
340  */
341  virtual void getGibbs_RT_ref(doublereal* grt) const;
342 
343  //! Returns the vector of the gibbs function of the reference state at the current temperature
344  //! of the solution and the reference pressure for the species.
345  /*!
346  * units = J/kmol
347  *
348  * @param g Output vector containing the reference state
349  * Gibbs Free energies. Length: m_kk. Units: J/kmol.
350  */
351  virtual void getGibbs_ref(doublereal* g) const;
352 
353  //! Returns the vector of nondimensional entropies of the reference state at the current temperature
354  //! of the solution and the reference pressure for each species.
355  /*!
356  * @param er Output vector containing the nondimensional reference state
357  * entropies. Length: m_kk.
358  */
359  virtual void getEntropy_R_ref(doublereal* er) const;
360 
361  /**
362  * @name Setting the State
363  *
364  * These methods set all or part of the thermodynamic state.
365  * @{
366  */
367 
368  //! Set the internally stored specific enthalpy (J/kg) and pressure (Pa) of the phase.
369  /*!
370  * @param h Specific enthalpy (J/kg)
371  * @param p Pressure (Pa)
372  * @param tol Optional parameter setting the tolerance of the
373  * calculation.
374  */
375  virtual void setState_HP(doublereal h, doublereal p,
376  doublereal tol = 1.e-8);
377 
378  //! Set the specific internal energy (J/kg) and specific volume (m^3/kg).
379  /*!
380  * This function fixes the internal state of the phase so that
381  * the specific internal energy and specific volume have the value of the input parameters.
382  *
383  * @param u specific internal energy (J/kg)
384  * @param v specific volume (m^3/kg).
385  * @param tol Optional parameter setting the tolerance of the
386  * calculation.
387  */
388  virtual void setState_UV(doublereal u, doublereal v,
389  doublereal tol = 1.e-8);
390 
391  //! Set the specific entropy (J/kg/K) and specific volume (m^3/kg).
392  /*!
393  * This function fixes the internal state of the phase so that
394  * the specific entropy and specific volume have the value of the input parameters.
395  *
396  * @param s specific entropy (J/kg/K)
397  * @param v specific volume (m^3/kg).
398  * @param tol Optional parameter setting the tolerance of the
399  * calculation.
400  */
401  virtual void setState_SV(doublereal s, doublereal v,
402  doublereal tol = 1.e-8);
403 
404  //! Set the specific entropy (J/kg/K) and pressure (Pa).
405  /*!
406  * This function fixes the internal state of the phase so that
407  * the specific entropy and the pressure have the value of the input parameters.
408  *
409  * @param s specific entropy (J/kg/K)
410  * @param p specific pressure (Pa).
411  * @param tol Optional parameter setting the tolerance of the
412  * calculation.
413  */
414  virtual void setState_SP(doublereal s, doublereal p,
415  doublereal tol = 1.e-8);
416  //@}
417 
418  //! @name Critical State Properties
419  //@{
420 
421  //! critical temperature
422  virtual doublereal critTemperature() const;
423 
424  //! critical pressure
425  virtual doublereal critPressure() const;
426 
427  //! critical density
428  virtual doublereal critDensity() const;
429 
430  //@}
431 
432  //! @name Saturation properties.
433  //@{
434 
435  //! saturation temperature
436  /*!
437  * @param p Pressure (Pa)
438  */
439  virtual doublereal satTemperature(doublereal p) const;
440 
441  //! Return the saturation pressure given the temperature
442  /*!
443  * @param t Temperature (Kelvin)
444  */
445  virtual doublereal satPressure(doublereal t);
446 
447  //! Return the fraction of vapor at the current conditions
448  virtual doublereal vaporFraction() const;
449 
450  //! Set the state to a saturated system at a particular temperature
451  /*!
452  * @param t Temperature (kelvin)
453  * @param x Fraction of vapor
454  */
455  virtual void setState_Tsat(doublereal t, doublereal x);
456 
457  //! Set the state to a saturated system at a particular pressure
458  /*!
459  * @param p Pressure (Pa)
460  * @param x Fraction of vapor
461  */
462  virtual void setState_Psat(doublereal p, doublereal x);
463  //@}
464 
465  //! Initialize the ThermoPhase object after all species have been set up
466  /*!
467  * @internal Initialize.
468  *
469  * This method is provided to allow
470  * subclasses to perform any initialization required after all
471  * species have been added. For example, it might be used to
472  * resize internal work arrays that must have an entry for
473  * each species. The base class implementation does nothing,
474  * and subclasses that do not require initialization do not
475  * need to overload this method. When importing a CTML phase
476  * description, this method is called from ThermoPhase::initThermoXML(),
477  * which is called from importPhase(),
478  * just prior to returning from function importPhase().
479  *
480  * @see importCTML.cpp
481  */
482  virtual void initThermo();
483 
484  //! Set equation of state parameter values from XML entries.
485  /*!
486  * This method is called by function importPhase() in
487  * file importCTML.cpp when processing a phase definition in
488  * an input file. It should be overloaded in subclasses to set
489  * any parameters that are specific to that particular phase
490  * model. Note, this method is called before the phase is
491  * initialized with elements and/or species.
492  *
493  * @param eosdata An XML_Node object corresponding to
494  * the "thermo" entry for this phase in the input file.
495  */
496  virtual void setParametersFromXML(const XML_Node& eosdata);
497 
498  //! returns a summary of the state of the phase as a string
499  /*!
500  * @param show_thermo If true, extra information is printed out
501  * about the thermodynamic state of the system.
502  */
503  virtual std::string report(bool show_thermo = true) const;
504 
505 protected:
506 
507  //! Main call to the tpx level to set the state of the system
508  /*!
509  * @param n Integer indicating which 2 thermo components are held constant
510  * @param x Value of the first component
511  * @param y Value of the second component
512  */
513  void Set(tpx::PropertyPair::type n, double x, double y) const;
514 
515  //! Sets the state using a TPX::TV call
516  void setTPXState() const;
517 
518 private:
519  //! Pointer to the underlying tpx object Substance that does the work
521 
522  //! Int indicating the type of the fluid
523  /*!
524  * The tpx package uses an int to indicate what fluid is being sought.
525  */
527 
528  //! Molecular weight of the substance (kg kmol-1)
529  doublereal m_mw;
530 
531  //! flag to turn on some printing.
532  bool m_verbose;
533 };
534 
535 }
536 
537 #endif
PureFluidPhase()
Empty Base Constructor.
virtual ~PureFluidPhase()
Destructor.
doublereal electricPotential() const
Returns the electric potential of this phase (V).
Definition: ThermoPhase.h:391
virtual void setPressure(doublereal p)
sets the thermodynamic pressure (Pa).
virtual doublereal gibbs_mole() const
Molar Gibbs function. Units: J/kmol.
bool m_verbose
flag to turn on some printing.
This phase object consists of a single component that can be a gas, a liquid, a mixed gas-liquid flui...
virtual void getEnthalpy_RT_ref(doublereal *hrt) const
Returns the vector of nondimensional enthalpies of the reference state at the current temperature of ...
virtual void getActivities(doublereal *a) const
Get the array of non-dimensional activities at the current solution temperature, pressure, and solution concentration.
virtual doublereal intEnergy_mole() const
Molar internal energy. Units: J/kmol.
virtual void setState_UV(doublereal u, doublereal v, doublereal tol=1.e-8)
Set the specific internal energy (J/kg) and specific volume (m^3/kg).
tpx::Substance & TPX_Substance()
Returns a reference to the substance object.
virtual void getEntropy_R(doublereal *sr) const
Get the array of nondimensional Entropy functions for the standard state species at the current T and...
Class XML_Node is a tree-based representation of the contents of an XML file.
Definition: xml.h:100
int m_subflag
Int indicating the type of the fluid.
virtual void getPartialMolarVolumes(doublereal *vbar) const
Return an array of partial molar volumes for the species in the mixture.
doublereal m_mw
Molecular weight of the substance (kg kmol-1)
virtual std::string report(bool show_thermo=true) const
returns a summary of the state of the phase as a string
virtual void getPartialMolarCp(doublereal *cpbar) const
Return an array of partial molar heat capacities for the species in the mixture.
virtual void setState_Tsat(doublereal t, doublereal x)
Set the state to a saturated system at a particular temperature.
virtual doublereal isothermalCompressibility() const
Returns the isothermal compressibility. Units: 1/Pa.
virtual void getPartialMolarEntropies(doublereal *sbar) const
Returns an array of partial molar entropies of the species in the solution.
virtual void setState_SV(doublereal s, doublereal v, doublereal tol=1.e-8)
Set the specific entropy (J/kg/K) and specific volume (m^3/kg).
virtual doublereal critPressure() const
critical pressure
virtual void getGibbs_RT(doublereal *grt) const
Get the nondimensional Gibbs functions for the species in their standard states at the current T and ...
Base class for a phase with thermodynamic properties.
Definition: ThermoPhase.h:101
virtual int standardStateConvention() const
This method returns the convention used in specification of the standard state, of which there are cu...
tpx::Substance * m_sub
Pointer to the underlying tpx object Substance that does the work.
virtual void setState_Psat(doublereal p, doublereal x)
Set the state to a saturated system at a particular pressure.
virtual doublereal satTemperature(doublereal p) const
saturation temperature
virtual doublereal critTemperature() const
critical temperature
virtual doublereal thermalExpansionCoeff() const
Return the volumetric thermal expansion coefficient. Units: 1/K.
ThermoPhase * duplMyselfAsThermoPhase() const
Duplication function.
void setTPXState() const
Sets the state using a TPX::TV call.
virtual void getChemPotentials(doublereal *mu) const
Get the species chemical potentials. Units: J/kmol.
virtual doublereal standardConcentration(size_t k=0) const
Return the standard concentration for the kth species.
virtual doublereal pressure() const
Return the thermodynamic pressure (Pa).
virtual doublereal critDensity() const
critical density
virtual void getEnthalpy_RT(doublereal *hrt) const
Get the nondimensional Enthalpy functions for the species at their standard states at the current T a...
virtual doublereal enthalpy_mole() const
Molar enthalpy. Units: J/kmol.
virtual void getStandardChemPotentials(doublereal *mu) const
Get the array of chemical potentials at unit activity for the species at their standard states at the...
virtual void setParametersFromXML(const XML_Node &eosdata)
Set equation of state parameter values from XML entries.
virtual void setState_HP(doublereal h, doublereal p, doublereal tol=1.e-8)
Set the internally stored specific enthalpy (J/kg) and pressure (Pa) of the phase.
virtual doublereal entropy_mole() const
Molar entropy. Units: J/kmol/K.
void getElectrochemPotentials(doublereal *mu) const
Get the species electrochemical potentials.
PureFluidPhase & operator=(const PureFluidPhase &right)
Assignment operator.
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...
virtual void initThermo()
Initialize the ThermoPhase object after all species have been set up.
virtual doublereal cv_mole() const
Molar heat capacity at constant volume. Units: J/kmol/K.
virtual void getPartialMolarIntEnergies(doublereal *ubar) const
Return an array of partial molar internal energies for the species in the mixture.
virtual void getPartialMolarEnthalpies(doublereal *hbar) const
Returns an array of partial molar enthalpies for the species in the mixture.
virtual void getActivityConcentrations(doublereal *c) const
This method returns an array of generalized concentrations.
size_t m_kk
Number of species in the phase.
Definition: Phase.h:716
virtual doublereal cp_mole() const
Molar heat capacity at constant pressure. Units: J/kmol/K.
void Set(tpx::PropertyPair::type n, double x, double y) const
Main call to the tpx level to set the state of the system.
Header file for class ThermoPhase, the base class for phases with thermodynamic properties, and the text for the Module thermoprops (see Thermodynamic Properties and class ThermoPhase).
virtual doublereal satPressure(doublereal t)
Return the saturation pressure given the temperature.
virtual void setState_SP(doublereal s, doublereal p, doublereal tol=1.e-8)
Set the specific entropy (J/kg/K) and pressure (Pa).
virtual void getGibbs_RT_ref(doublereal *grt) const
Returns the vector of nondimensional Gibbs Free Energies of the reference state at the current temper...
virtual doublereal vaporFraction() const
Return the fraction of vapor at the current conditions.
virtual void getEntropy_R_ref(doublereal *er) const
Returns the vector of nondimensional entropies of the reference state at the current temperature of t...
virtual int eosType() const
Equation of state type.
doublereal charge(size_t k) const
Dimensionless electrical charge of a single molecule of species k The charge is normalized by the the...
Definition: Phase.h:504