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