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