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