Cantera  2.0
MixtureFugacityTP.h
Go to the documentation of this file.
1 /**
2  * @file MixtureFugacityTP.h
3  * Header file for a derived class of ThermoPhase that handles
4  * non-ideal mixtures based on the fugacity models (see \ref thermoprops and
5  * class \link Cantera::MixtureFugacityTP MixtureFugacityTP\endlink).
6  *
7  */
8 /*
9  * Copyright (2005) Sandia Corporation. Under the terms of
10  * Contract DE-AC04-94AL85000 with Sandia Corporation, the
11  * U.S. Government retains certain rights in this software.
12  */
13 
14 #ifndef CT_MIXTUREFUGACITYTP_H
15 #define CT_MIXTUREFUGACITYTP_H
16 
17 #include "ThermoPhase.h"
18 #include "VPSSMgr.h"
20 
21 namespace Cantera
22 {
23 
24 class XML_Node;
25 class PDSS;
26 
27 //! Various states of the Fugacity object. In general there can be multiple liquid
28 //! objects for a single phase identified with each species.
29 
30 #define FLUID_UNSTABLE -4
31 #define FLUID_UNDEFINED -3
32 #define FLUID_SUPERCRIT -2
33 #define FLUID_GAS -1
34 #define FLUID_LIQUID_0 0
35 #define FLUID_LIQUID_1 1
36 #define FLUID_LIQUID_2 2
37 #define FLUID_LIQUID_3 3
38 #define FLUID_LIQUID_4 4
39 #define FLUID_LIQUID_5 5
40 #define FLUID_LIQUID_6 6
41 #define FLUID_LIQUID_7 7
42 #define FLUID_LIQUID_8 8
43 #define FLUID_LIQUID_9 9
44 
45 /**
46  * @ingroup thermoprops
47  *
48  * This is a filter class for ThermoPhase that implements some preparatory
49  * steps for efficiently handling mixture of gases that whose standard states
50  * are defined as ideal gases, but which describe also non-ideal solutions.
51  * In addition a multicomponent liquid phase below the critical temperature of the
52  * mixture is also allowed. The main subclass is currently a mixture Redlich-Kwong class.
53  *
54  * Several concepts are introduced. The first concept is there are temporary
55  * variables for holding the species standard state values
56  * of Cp, H, S, G, and V at the last temperature and pressure called. These functions are not recalculated
57  * if a new call is made using the previous temperature and pressure.
58  *
59  * The other concept is that the current state of the mixture is tracked.
60  * The state variable is either GAS, LIQUID, or SUPERCRIT fluid. Additionally,
61  * the variable LiquidContent is used and may vary between 0 and 1.
62  *
63  * To support the above functionality, pressure and temperature variables,
64  * m_Plast_ss and m_Tlast_ss, are kept which store the last pressure and temperature
65  * used in the evaluation of standard state properties.
66  *
67  * Typically, only one liquid phase is allowed to be formed within these classes.
68  * Additionally, there is an inherent contradiction between three phase models and
69  * the ThermoPhase class. The ThermoPhase class is really only meant to represent a
70  * single instantiation of a phase. The three phase models may be in equilibrium with
71  * multiple phases of the fluid in equilibrium with each other. This has yet to be resolved.
72  *
73  * This class is usually used for non-ideal gases.
74  *
75  *
76  * @nosubgrouping
77  */
79 {
80 
81 public:
82 
83  /*!
84  *
85  * @name Constructors and Duplicators for %MixtureFugacityTP
86  *
87  */
88  //! Constructor.
90 
91  //! Copy Constructor.
92  /*!
93  * @param b Object to be copied
94  */
96 
97  //! Assignment operator
98  /*!
99  * @param b Object to be copied
100  */
102 
103  //! Destructor.
104  virtual ~MixtureFugacityTP();
105 
106 
107  //! Duplication routine
108  /*!
109  * @return Returns a duplication
110  */
111  virtual ThermoPhase* duplMyselfAsThermoPhase() const;
112 
113  //@}
114 
115  /**
116  * @name Utilities (MixtureFugacityTP)
117  */
118  //@{
119  /**
120  * Equation of state type flag. The base class returns
121  * zero. Subclasses should define this to return a unique
122  * non-zero value. Constants defined for this purpose are
123  * listed in mix_defs.h.
124  */
125  virtual int eosType() const {
126  return 0;
127  }
128 
129  //! This method returns the convention used in specification
130  //! of the standard state, of which there are currently two,
131  //! temperature based, and variable pressure based.
132  /*!
133  * Currently, there are two standard state conventions:
134  * - Temperature-based activities
135  * cSS_CONVENTION_TEMPERATURE 0
136  * - default
137  *
138  * - Variable Pressure and Temperature -based activities
139  * cSS_CONVENTION_VPSS 1
140  */
141  virtual int standardStateConvention() const;
142 
143  //! Set the solution branch to force the ThermoPhase to exist on one branch or another
144  /*!
145  * @param solnBranch Branch that the solution is restricted to.
146  * the value -1 means gas. The value -2 means unrestricted.
147  * Values of zero or greater refer to species dominated condensed phases.
148  */
149  virtual void setForcedSolutionBranch(int solnBranch);
150 
151  //! Report the solution branch which the solution is restricted to
152  /*!
153  * @return Branch that the solution is restricted to.
154  * the value -1 means gas. The value -2 means unrestricted.
155  * Values of zero or greater refer to species dominated condensed phases.
156  */
157  virtual int forcedSolutionBranch() const;
158 
159  //! Report the solution branch which the solution is actually on
160  /*!
161  * @return Branch that the solution is restricted to.
162  * the value -1 means gas. The value -2 means superfluid..
163  * Values of zero or greater refer to species dominated condensed phases.
164  */
165  virtual int reportSolnBranchActual() const;
166 
167 
168 
169  //! Get the array of log concentration-like derivatives of the
170  //! log activity coefficients
171  /*!
172  * This function is a virtual method. For ideal mixtures
173  * (unity activity coefficients), this can return zero.
174  * Implementations should take the derivative of the
175  * logarithm of the activity coefficient with respect to the
176  * logarithm of the concentration-like variable (i.e. moles)
177  * that represents the standard state.
178  * This quantity is to be used in conjunction with derivatives of
179  * that concentration-like variable when the derivative of the chemical
180  * potential is taken.
181  *
182  * units = dimensionless
183  *
184  * @param dlnActCoeffdlnN_diag Output vector of derivatives of the
185  * log Activity Coefficients. length = m_kk
186  */
187  virtual void getdlnActCoeffdlnN_diag(doublereal* dlnActCoeffdlnN_diag) const {
188  err("getdlnActCoeffdlnN_diag");
189  }
190 
191 
192  //@}
193  /// @name Partial Molar Properties of the Solution (MixtureFugacityTP)
194  //@{
195 
196 
197  //! Get the array of non-dimensional species chemical potentials
198  //! These are partial molar Gibbs free energies.
199  /*!
200  * \f$ \mu_k / \hat R T \f$.
201  * Units: unitless
202  *
203  * We close the loop on this function, here, calling
204  * getChemPotentials() and then dividing by RT. No need for child
205  * classes to handle.
206  *
207  * @param mu Output vector of non-dimensional species chemical potentials
208  * Length: m_kk.
209  */
210  void getChemPotentials_RT(doublereal* mu) const;
211 
212  //@}
213 
214  /*!
215  * @name Properties of the Standard State of the Species in the Solution
216  * (MixtureFugacityTP)
217  *
218  * Within MixtureFugacityTP, these properties are calculated via a common routine,
219  * _updateStandardStateThermo(),
220  * which must be overloaded in inherited objects.
221  * The values are cached within this object, and are not recalculated unless
222  * the temperature or pressure changes.
223  */
224  //@{
225 
226  //! Get the array of chemical potentials at unit activity.
227  /*!
228  * These are the standard state chemical potentials \f$ \mu^0_k(T,P)
229  * \f$. The values are evaluated at the current temperature and pressure.
230  *
231  * For all objects with the Mixture Fugacity approximation, we define the
232  * standard state as an ideal gas at the current temperature and pressure
233  * of the solution.
234  *
235  * @param mu Output vector of standard state chemical potentials.
236  * length = m_kk. units are J / kmol.
237  */
238  virtual void getStandardChemPotentials(doublereal* mu) const;
239 
240  //! Get the nondimensional Enthalpy functions for the species
241  //! at their standard states at the current <I>T</I> and <I>P</I> of the solution.
242  /*!
243  * For all objects with the Mixture Fugacity approximation, we define the
244  * standard state as an ideal gas at the current temperature and pressure
245  * of the solution.
246  *
247  * @param hrt Output vector of standard state enthalpies.
248  * length = m_kk. units are unitless.
249  */
250  virtual void getEnthalpy_RT(doublereal* hrt) const;
251 
252 
253  //! Get the array of nondimensional Enthalpy functions for the standard state species
254  /*!
255  * at the current <I>T</I> and <I>P</I> of the solution.
256  * For all objects with the Mixture Fugacity approximation, we define the
257  * standard state as an ideal gas at the current temperature and pressure
258  * of the solution.
259  *
260  * @param sr Output vector of nondimensional standard state
261  * entropies. length = m_kk.
262  */
263  virtual void getEntropy_R(doublereal* sr) const;
264 
265  //! Get the nondimensional Gibbs functions for the species
266  //! at their standard states of solution at the current T and P of the solution.
267  /*!
268  * For all objects with the Mixture Fugacity approximation, we define the
269  * standard state as an ideal gas at the current temperature and pressure
270  * of the solution.
271  *
272  * @param grt Output vector of nondimensional standard state
273  * Gibbs free energies. length = m_kk.
274  */
275  virtual void getGibbs_RT(doublereal* grt) const;
276 
277  //! Get the pure Gibbs free energies of each species.
278  //! Species are assumed to be in their standard states. This is the same
279  //! as getStandardChemPotentials().
280  //! @param[out] gpure Array of standard state Gibbs free energies.
281  //! length = m_kk. units are J/kmol.
282  void getPureGibbs(doublereal* gpure) const;
283 
284  //! Returns the vector of nondimensional internal Energies of the standard state at the current temperature
285  //! and pressure of the solution for each species.
286  /*!
287  * For all objects with the Mixture Fugacity approximation, we define the
288  * standard state as an ideal gas at the current temperature and pressure
289  * of the solution.
290  *
291  * \f[
292  * u^{ss}_k(T,P) = h^{ss}_k(T) - P * V^{ss}_k
293  * \f]
294  *
295  * @param urt Output vector of nondimensional standard state
296  * internal energies. length = m_kk.
297  */
298  virtual void getIntEnergy_RT(doublereal* urt) const;
299 
300 
301  //! Get the nondimensional Heat Capacities at constant
302  //! pressure for the standard state of the species at the current T and P.
303  /*!
304  * For all objects with the Mixture Fugacity approximation, we define the
305  * standard state as an ideal gas at the current temperature and pressure of the solution.
306  *
307  * @param cpr Output vector containing the
308  * the nondimensional Heat Capacities at constant
309  * pressure for the standard state of the species.
310  * Length: m_kk.
311  */
312  virtual void getCp_R(doublereal* cpr) const;
313 
314 
315  //! Get the molar volumes of each species in their standard
316  //! states at the current <I>T</I> and <I>P</I> of the solution.
317  /*!
318  * For all objects with the Mixture Fugacity approximation, we define the
319  * standard state as an ideal gas at the current temperature and pressure of the solution.
320  *
321  * units = m^3 / kmol
322  *
323  * @param vol Output vector of species volumes. length = m_kk.
324  * units = m^3 / kmol
325  */
326  virtual void getStandardVolumes(doublereal* vol) const;
327 
328 
329  //! Set the temperature of the phase
330  /*!
331  * Currently this passes down to setState_TP(). It does not
332  * make sense to calculate the standard state without first
333  * setting T and P.
334  *
335  * @param temp Temperature (kelvin)
336  */
337  virtual void setTemperature(const doublereal temp);
338 
339 
340  //! Set the internally stored pressure (Pa) at constant
341  //! temperature and composition
342  /*!
343  * Currently this passes down to setState_TP(). It does not
344  * make sense to calculate the standard state without first
345  * setting T and P.
346  *
347  * @param p input Pressure (Pa)
348  */
349  virtual void setPressure(doublereal p);
350 
351 
352 
353 protected:
354  /**
355  * Calculate the density of the mixture using the partial
356  * molar volumes and mole fractions as input
357  *
358  * The formula for this is
359  *
360  * \f[
361  * \rho = \frac{\sum_k{X_k W_k}}{\sum_k{X_k V_k}}
362  * \f]
363  *
364  * where \f$X_k\f$ are the mole fractions, \f$W_k\f$ are
365  * the molecular weights, and \f$V_k\f$ are the pure species
366  * molar volumes.
367  *
368  * Note, the basis behind this formula is that in an ideal
369  * solution the partial molar volumes are equal to the pure
370  * species molar volumes. We have additionally specified
371  * in this class that the pure species molar volumes are
372  * independent of temperature and pressure.
373  *
374  * NOTE: This is a non-virtual function, which is not a
375  * member of the ThermoPhase base class.
376  */
377  virtual void calcDensity();
378 
379 public:
380  //! Set the temperature and pressure at the same time
381  /*!
382  * Note this function triggers a reevaluation of the standard
383  * state quantities.
384  *
385  * @param T temperature (kelvin)
386  * @param pres pressure (pascal)
387  */
388  virtual void setState_TP(doublereal T, doublereal pres);
389 
390  //! Set the internally stored temperature (K) and density (kg/m^3)
391  /*!
392  * @param T Temperature in kelvin
393  * @param rho Density (kg/m^3)
394  */
395  virtual void setState_TR(doublereal T, doublereal rho);
396 
397  //! Set the temperature (K), pressure (Pa), and mole fractions.
398  /*!
399  * Note, the mole fractions are set first before the pressure is set.
400  * Setting the pressure may involve the solution of a nonlinear equation.
401  *
402  * @param t Temperature (K)
403  * @param p Pressure (Pa)
404  * @param x Vector of mole fractions.
405  * Length is equal to m_kk.
406  */
407  virtual void setState_TPX(doublereal t, doublereal p, const doublereal* x);
408 
409 
410  //! Set the mass fractions to the specified values, and then
411  //! normalize them so that they sum to 1.0.
412  /*!
413  * @param y Array of unnormalized mass fraction values (input).
414  * Must have a length greater than or equal to the number of species.
415  */
416  virtual void setMassFractions(const doublereal* const y);
417 
418 
419  //!Set the mass fractions to the specified values without normalizing.
420  /*!
421  * This is useful when the normalization
422  * condition is being handled by some other means, for example
423  * by a constraint equation as part of a larger set of
424  * equations.
425  *
426  * @param y Input vector of mass fractions.
427  * Length is m_kk.
428  */
429  virtual void setMassFractions_NoNorm(const doublereal* const y);
430 
431 
432 
433  //! Set the mole fractions to the specified values, and then
434  //! normalize them so that they sum to 1.0.
435  /*!
436  * @param x Array of unnormalized mole fraction values (input).
437  * Must have a length greater than or equal to the number of species.
438  */
439  virtual void setMoleFractions(const doublereal* const x);
440 
441 
442  //! Set the mole fractions to the specified values without normalizing.
443  /*!
444  * This is useful when the normalization
445  * condition is being handled by some other means, for example
446  * by a constraint equation as part of a larger set of equations.
447  *
448  * @param x Input vector of mole fractions.
449  * Length is m_kk.
450  */
451  virtual void setMoleFractions_NoNorm(const doublereal* const x);
452 
453 
454  //! Set the concentrations to the specified values within the phase.
455  /*!
456  * @param c The input vector to this routine is in dimensional
457  * units. For volumetric phases c[k] is the
458  * concentration of the kth species in kmol/m3.
459  * For surface phases, c[k] is the concentration
460  * in kmol/m2. The length of the vector is the number
461  * of species in the phase.
462  */
463  virtual void setConcentrations(const doublereal* const c);
464 
465 protected:
466  void setMoleFractions_NoState(const doublereal* const x);
467 
468 
469 public:
470  //! Returns the current pressure of the phase
471  /*!
472  * The pressure is an independent variable in this phase. Its current value
473  * is stored in the object MixtureFugacityTP.
474  *
475  * @return return the pressure in pascals.
476  */
477  doublereal pressure() const {
478  return m_Pcurrent;
479  }
480 
481 
482 
483 
484 
485 protected:
486 
487  //! Updates the reference state thermodynamic functions at the current T of the solution.
488  /*!
489  *
490  * If m_useTmpStandardStateStorage is true,
491  * this function must be called for every call to functions in this
492  * class. It checks to see whether the temperature or pressure has changed and
493  * thus the ss thermodynamics functions for all of the species
494  * must be recalculated.
495  *
496  * This function is responsible for updating the following internal members,
497  * when m_useTmpStandardStateStorage is true.
498  *
499  * - m_hss_RT;
500  * - m_cpss_R;
501  * - m_gss_RT;
502  * - m_sss_R;
503  * - m_Vss
504  *
505  * If m_useTmpStandardStateStorage is not true, this function may be
506  * required to be called by child classes to update internal member data.
507  *
508  */
509  virtual void _updateReferenceStateThermo() const;
510 public:
511 
512  //@}
513  /// @name Thermodynamic Values for the Species Reference States (MixtureFugacityTP)
514  /*!
515  * There are also temporary
516  * variables for holding the species reference-state values of Cp, H, S, and V at the
517  * last temperature and reference pressure called. These functions are not recalculated
518  * if a new call is made using the previous temperature.
519  * All calculations are done within the routine _updateRefStateThermo().
520  */
521  //@{
522 
523 
524  //! Returns the vector of nondimensional
525  //! enthalpies of the reference state at the current temperature
526  //! of the solution and the reference pressure for the species.
527  /*!
528  * @param hrt Output vector contains the nondimensional enthalpies
529  * of the reference state of the species
530  * length = m_kk, units = dimensionless.
531  */
532  virtual void getEnthalpy_RT_ref(doublereal* hrt) const;
533 
534 #ifdef H298MODIFY_CAPABILITY
535  //! Modify the value of the 298 K Heat of Formation of the standard state of
536  //! one species in the phase (J kmol-1)
537  /*!
538  * The 298K heat of formation is defined as the enthalpy change to create the standard state
539  * of the species from its constituent elements in their standard states at 298 K and 1 bar.
540  *
541  * @param k Index of the species
542  * @param Hf298New Specify the new value of the Heat of Formation at 298K and 1 bar.
543  * units = J/kmol.
544  */
545  void modifyOneHf298SS(const int k, const doublereal Hf298New);
546 #endif
547 
548  //! Returns the vector of nondimensional
549  //! Gibbs free energies of the reference state at the current temperature
550  //! of the solution and the reference pressure for the species.
551  /*!
552  *
553  * @param grt Output vector contains the nondimensional Gibbs free energies
554  * of the reference state of the species
555  * length = m_kk, units = dimensionless.
556  */
557  virtual void getGibbs_RT_ref(doublereal* grt) const;
558 
559 protected:
560  //! Returns the vector of nondimensional
561  //! Gibbs free energies of the reference state at the current temperature
562  //! of the solution and the reference pressure for the species.
563  /*!
564  * @return Output vector contains the nondimensional Gibbs free energies
565  * of the reference state of the species
566  * length = m_kk, units = dimensionless.
567  */
568  const vector_fp& gibbs_RT_ref() const;
569 
570 public:
571  /*!
572  * Returns the vector of the
573  * gibbs function of the reference state at the current temperature
574  * of the solution and the reference pressure for the species.
575  * units = J/kmol
576  *
577  * @param g Output vector contain the Gibbs free energies
578  * of the reference state of the species
579  * length = m_kk, units = J/kmol.
580  */
581  virtual void getGibbs_ref(doublereal* g) const;
582 
583  /*!
584  * Returns the vector of nondimensional
585  * entropies of the reference state at the current temperature
586  * of the solution and the reference pressure for the species.
587  *
588  * @param er Output vector contain the nondimensional entropies
589  * of the species in their reference states
590  * length: m_kk, units: dimensionless.
591  */
592  virtual void getEntropy_R_ref(doublereal* er) const;
593 
594  /*!
595  * Returns the vector of nondimensional
596  * constant pressure heat capacities of the reference state
597  * at the current temperature of the solution
598  * and reference pressure for the species.
599  *
600  * @param cprt Output vector contains the nondimensional heat capacities
601  * of the species in their reference states
602  * length: m_kk, units: dimensionless.
603  */
604  virtual void getCp_R_ref(doublereal* cprt) const;
605 
606  //! Get the molar volumes of the species reference states at the current
607  //! <I>T</I> and reference pressure of the solution.
608  /*!
609  * units = m^3 / kmol
610  *
611  * @param vol Output vector containing the standard state volumes.
612  * Length: m_kk.
613  */
614  virtual void getStandardVolumes_ref(doublereal* vol) const;
615 
616 protected:
617 
618 
619 
620  //@}
621 
622 
623 public:
624 
625  //! @name Initialization Methods - For Internal use (VPStandardState)
626  /*!
627  * The following methods are used in the process of constructing
628  * the phase and setting its parameters from a specification in an
629  * input file. They are not normally used in application programs.
630  * To see how they are used, see files importCTML.cpp and
631  * ThermoFactory.cpp.
632  */
633  //@{
634 
635 
636  //! Set the initial state of the phase to the conditions specified in the state XML element.
637  /*!
638  *
639  * This method sets the temperature, pressure, and mole fraction vector to a set default value.
640  *
641  * @param state AN XML_Node object corresponding to
642  * the "state" entry for this phase in the input file.
643  */
644  virtual void setStateFromXML(const XML_Node& state);
645 
646  //! @internal Initialize the object
647  /*!
648  * This method is provided to allow
649  * subclasses to perform any initialization required after all
650  * species have been added. For example, it might be used to
651  * resize internal work arrays that must have an entry for
652  * each species. The base class implementation does nothing,
653  * and subclasses that do not require initialization do not
654  * need to overload this method. When importing a CTML phase
655  * description, this method is called after calling installSpecies()
656  * for each species in the phase. It's called before calling
657  * initThermoXML() for the phase. Therefore, it's the correct
658  * place for initializing vectors which have lengths equal to the
659  * number of species.
660  *
661  * @see importCTML.cpp
662  */
663  virtual void initThermo();
664 
665  //! Initialize a ThermoPhase object, potentially reading activity
666  //! coefficient information from an XML database.
667  /*!
668  * This routine initializes the lengths in the current object and
669  * then calls the parent routine.
670  * This method is provided to allow
671  * subclasses to perform any initialization required after all
672  * species have been added. For example, it might be used to
673  * resize internal work arrays that must have an entry for
674  * each species. The base class implementation does nothing,
675  * and subclasses that do not require initialization do not
676  * need to overload this method. When importing a CTML phase
677  * description, this method is called just prior to returning
678  * from function importPhase().
679  *
680  * @param phaseNode This object must be the phase node of a
681  * complete XML tree
682  * description of the phase, including all of the
683  * species data. In other words while "phase" must
684  * point to an XML phase object, it must have
685  * sibling nodes "speciesData" that describe
686  * the species in the phase.
687  * @param id ID of the phase. If nonnull, a check is done
688  * to see if phaseNode is pointing to the phase
689  * with the correct id.
690  */
691  virtual void initThermoXML(XML_Node& phaseNode, std::string id);
692 
693 
694 private:
695  //! @internal Initialize the internal lengths in this object.
696  /*!
697  * Note this is not a virtual function.
698  */
699  void initLengths();
700 
701 protected:
702  // Special Functions for fugacity classes
703 
704 
705  //! Calculate the value of z
706  /*!
707  * \f[
708  * z = \frac{P v}{ R T}
709  * \f]
710  *
711  * returns the value of z
712  */
713  doublereal z() const;
714 
715  //! Calculate the deviation terms for the total entropy of the mixture from the
716  //! ideal gas mixture
717  /*
718  * Here we use the current state conditions
719  *
720  * @return Returns the change in entropy in units of J kmol-1 K-1.
721  */
722  virtual doublereal sresid() const;
723 
724  //! Calculate the deviation terms for the total enthalpy of the mixture from the ideal gas mixture
725  /*
726  * Here we use the current state conditions
727  *
728  * @return Returns the change in entropy in units of J kmol-1.
729  */
730  virtual doublereal hresid() const;
731 
732 
733  //! Estimate for the saturation pressure
734  /*!
735  * Note: this is only used as a starting guess for later routines that actually calculate an
736  * accurate value for the saturation pressure.
737  *
738  * @param TKelvin temperature in kelvin
739  *
740  * @return returns the estimated saturation pressure at the given temperature
741  */
742  virtual doublereal psatEst(doublereal TKelvin) const;
743 public:
744  //! Estimate for the molar volume of the liquid
745  /*!
746  * Note: this is only used as a starting guess for later routines that actually calculate an
747  * accurate value for the liquid molar volume.
748  * This routine doesn't change the state of the system.
749  *
750  * @param TKelvin temperature in kelvin
751  * @param pres Pressure in Pa. This is used as an initial guess. If the routine
752  * needs to change the pressure to find a stable liquid state, the
753  * new pressure is returned in this variable.
754  *
755  * @return Returns the estimate of the liquid volume. If the liquid can't be found, this
756  * routine returns -1.
757  */
758  virtual doublereal liquidVolEst(doublereal TKelvin, doublereal& pres) const;
759 
760 public:
761  //! Calculates the density given the temperature and the pressure and a guess at the density.
762  /*!
763  * Note, below T_c, this is a multivalued function. We do not cross the vapor dome in this.
764  * This is protected because it is called during setState_TP() routines. Infinite loops would result
765  * if it were not protected.
766  *
767  * -> why is this not const?
768  *
769  * parameters:
770  * @param TKelvin Temperature in Kelvin
771  * @param pressure Pressure in Pascals (Newton/m**2)
772  * @param phaseRequested int representing the phase whose density we are requesting. If we put
773  * a gas or liquid phase here, we will attempt to find a volume in that
774  * part of the volume space, only, in this routine. A value of FLUID_UNDEFINED
775  * means that we will accept anything.
776  *
777  * @param rhoguess Guessed density of the fluid. A value of -1.0 indicates that there
778  * is no guessed density
779  *
780  *
781  * @return We return the density of the fluid at the requested phase. If we have not found any
782  * acceptable density we return a -1. If we have found an acceptable density at a
783  * different phase, we return a -2.
784  */
785  virtual doublereal densityCalc(doublereal TKelvin, doublereal pressure, int phaseRequested,
786  doublereal rhoguess);
787 protected:
788  //! Utility routine in the calculation of the saturation pressure
789  /*!
790  * Private routine
791  *
792  * @param TKelvin temperature (kelvin)
793  * @param pres pressure (Pascal)
794  * @param densLiq Output density of liquid
795  * @param densGas output density of gas
796  * @param gasGRT output delGRT
797  */
798  int corr0(doublereal TKelvin, doublereal pres, doublereal& densLiq,
799  doublereal& densGas, doublereal& liqGRT, doublereal& gasGRT);
800 public:
801  //! Returns the Phase State flag for the current state of the object
802  /*!
803  * @param checkState If true, this function does a complete check to see where
804  * in parameters space we are
805  *
806  * There are three values:
807  * WATER_GAS below the critical temperature but below the critical density
808  * WATER_LIQUID below the critical temperature but above the critical density
809  * WATER_SUPERCRIT above the critical temperature
810  */
811  int phaseState(bool checkState = false) const ;
812 
813  //! Return the value of the density at the liquid spinodal point (on the liquid side)
814  //! for the current temperature.
815  /*!
816  * @return returns the density with units of kg m-3
817  */
818  virtual doublereal densSpinodalLiquid() const;
819 
820 
821  //! Return the value of the density at the gas spinodal point (on the gas side)
822  //! for the current temperature.
823  /*!
824  * @return returns the density with units of kg m-3
825  */
826  virtual doublereal densSpinodalGas() const;
827 
828 
829 
830 
831 public:
832  //! Calculate the saturation pressure at the current mixture content for the given temperature
833  /*!
834  * @param TKelvin (input) Temperature (Kelvin)
835  * @param molarVolGas (return) Molar volume of the gas
836  * @param molarVolLiquid (return) Molar volume of the liquid
837  *
838  * @return Returns the saturation pressure at the given temperature
839  */
840  doublereal calculatePsat(doublereal TKelvin, doublereal& molarVolGas,
841  doublereal& molarVolLiquid);
842 protected:
843  //! Calculate the pressure given the temperature and the molar volume
844  /*!
845  * Calculate the pressure given the temperature and the molar volume
846  *
847  * @param TKelvin temperature in kelvin
848  * @param molarVol molar volume ( m3/kmol)
849  *
850  * @return Returns the pressure.
851  */
852  virtual doublereal pressureCalc(doublereal TKelvin, doublereal molarVol) const;
853 
854 
855  //! Calculate the pressure and the pressure derivative given the temperature and the molar volume
856  /*!
857  * Temperature and mole number are held constant
858  *
859  * @param TKelvin temperature in kelvin
860  * @param molarVol molar volume ( m3/kmol)
861  *
862  * @param presCalc Returns the pressure.
863  *
864  * @return Returns the derivative of the pressure wrt the molar volume
865  */
866  virtual doublereal dpdVCalc(doublereal TKelvin, doublereal molarVol, doublereal& presCalc) const;
867 
868 
869 
870  virtual void updateMixingExpressions();
871 
872 
873  //@}
874 
875 
876  class spinodalFunc : public Cantera::ResidEval
877  {
878  public:
879 
880  spinodalFunc(MixtureFugacityTP* tp);
881 
882  virtual int evalSS(const doublereal t, const doublereal* const y, doublereal* const r);
883 
884  MixtureFugacityTP* m_tp;
885  };
886 
887 
888 protected:
889 
890  //! Current value of the pressures
891  /*!
892  * Because the pressure is now a calculation, we store the result of the calculation whenever
893  * it is recalculated.
894  *
895  * units = Pascals
896  */
897  doublereal m_Pcurrent;
898 
899 
900  //! Storage for the current values of the mole fractions of the species
901  /*!
902  * This vector is kept up-to-date when some the setState functions are called.
903  *
904  * The State object is allowed to com
905  *
906  * Therefore, it may be considered to be an independent variable.
907  *
908 
909  */
910  std::vector<doublereal> moleFractions_;
911 
912  //! Current state of the fluid
913  /*!
914  * There are three possible states of the fluid
915  * FLUID_GAS
916  * FLUID_LIQUID
917  * FLUID_SUPERCRIT
918  */
919  int iState_;
920 
921 
922  //! Force the system to be on a particular side of the spinodal curve
924 
925  //! The last temperature at which the reference state thermodynamic properties were calculated at.
926  mutable doublereal m_Tlast_ref;
927 
928  //! Temporary storage for log of p/rt
929  mutable doublereal m_logc0;
930 
931  //! Temporary storage for dimensionless reference state enthalpies
933 
934  //! Temporary storage for dimensionless reference state heat capacities
936 
937  //! Temporary storage for dimensionless reference state gibbs energies
939 
940  //! Temporary storage for dimensionless reference state entropies
941  mutable vector_fp m_s0_R;
942 
943  spinodalFunc* fdpdv_;
944 private:
945 
946  //! MixtureFugacityTP has its own err routine
947  /*!
948  * @param msg Error message string
949  */
950  doublereal err(std::string msg) const;
951 
952 };
953 }
954 
955 #endif