Cantera  3.3.0a1
Loading...
Searching...
No Matches
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// This file is part of Cantera. See License.txt in the top-level directory or
9// at https://cantera.org/license.txt for license and copyright information.
10
11#ifndef CT_MIXTUREFUGACITYTP_H
12#define CT_MIXTUREFUGACITYTP_H
13
14#include "ThermoPhase.h"
15
16namespace Cantera
17{
18//! Various states of the Fugacity object. In general there can be multiple liquid
19//! objects for a single phase identified with each species.
20
21#define FLUID_UNSTABLE -4
22#define FLUID_UNDEFINED -3
23#define FLUID_SUPERCRIT -2
24#define FLUID_GAS -1
25#define FLUID_LIQUID_0 0
26#define FLUID_LIQUID_1 1
27#define FLUID_LIQUID_2 2
28#define FLUID_LIQUID_3 3
29#define FLUID_LIQUID_4 4
30#define FLUID_LIQUID_5 5
31#define FLUID_LIQUID_6 6
32#define FLUID_LIQUID_7 7
33#define FLUID_LIQUID_8 8
34#define FLUID_LIQUID_9 9
35
36/**
37 * @ingroup thermoprops
38 *
39 * This is a filter class for ThermoPhase that implements some preparatory steps
40 * for efficiently handling mixture of gases that whose standard states are
41 * defined as ideal gases, but which describe also non-ideal solutions. In
42 * addition a multicomponent liquid phase below the critical temperature of the
43 * mixture is also allowed. The main subclass is currently a mixture Redlich-
44 * Kwong class.
45 *
46 * Several concepts are introduced. The first concept is there are temporary
47 * variables for holding the species standard state values of Cp, H, S, G, and V
48 * at the last temperature and pressure called. These functions are not
49 * recalculated if a new call is made using the previous temperature and
50 * pressure.
51 *
52 * The other concept is that the current state of the mixture is tracked. The
53 * state variable is either GAS, LIQUID, or SUPERCRIT fluid. Additionally, the
54 * variable LiquidContent is used and may vary between 0 and 1.
55 *
56 * Typically, only one liquid phase is allowed to be formed within these
57 * classes. Additionally, there is an inherent contradiction between three phase
58 * models and the ThermoPhase class. The ThermoPhase class is really only meant
59 * to represent a single instantiation of a phase. The three phase models may be
60 * in equilibrium with multiple phases of the fluid in equilibrium with each
61 * other. This has yet to be resolved.
62 *
63 * This class is usually used for non-ideal gases.
64 */
66{
67public:
68 //! @name Constructors and Duplicators for MixtureFugacityTP
69 //! @{
70
71 //! Constructor.
72 MixtureFugacityTP() = default;
73
74 //! @}
75 //! @name Utilities
76 //! @{
77
78 string type() const override {
79 return "MixtureFugacity";
80 }
81
82 int standardStateConvention() const override;
83
84 //! Set the solution branch to force the ThermoPhase to exist on one branch
85 //! or another
86 /*!
87 * @param solnBranch Branch that the solution is restricted to. the value
88 * -1 means gas. The value -2 means unrestricted. Values of zero or
89 * greater refer to species dominated condensed phases.
90 */
91 void setForcedSolutionBranch(int solnBranch);
92
93 //! Report the solution branch which the solution is restricted to
94 /*!
95 * @return Branch that the solution is restricted to. the value -1 means
96 * gas. The value -2 means unrestricted. Values of zero or greater
97 * refer to species dominated condensed phases.
98 */
99 int forcedSolutionBranch() const;
100
101 //! Report the solution branch which the solution is actually on
102 /*!
103 * @return Branch that the solution is restricted to. the value -1 means
104 * gas. The value -2 means superfluid.. Values of zero or greater refer
105 * to species dominated condensed phases.
106 */
107 int reportSolnBranchActual() const;
108
109 //! @}
110 //! @name Molar Thermodynamic properties
111 //! @{
112
113 double enthalpy_mole() const override;
114 double entropy_mole() const override;
115
116 //! @}
117 //! @name Properties of the Standard State of the Species in the Solution
118 //!
119 //! Within MixtureFugacityTP, these properties are calculated via a common
120 //! routine, _updateStandardStateThermo(), which must be overloaded in
121 //! inherited objects. The values are cached within this object, and are not
122 //! recalculated unless the temperature or pressure changes.
123 //! @{
124
125 //! Get the array of chemical potentials at unit activity.
126 /*!
127 * These are the standard state chemical potentials @f$ \mu^0_k(T,P)
128 * @f$. The values are evaluated at the current temperature and pressure.
129 *
130 * For all objects with the Mixture Fugacity approximation, we define the
131 * standard state as an ideal gas at the current temperature and pressure
132 * of the solution.
133 *
134 * @param mu Output vector of standard state chemical potentials.
135 * length = m_kk. units are J / kmol.
136 */
137 void getStandardChemPotentials(double* mu) const override;
138
139 //! Get the nondimensional Enthalpy functions for the species at their
140 //! standard states at the current *T* and *P* of the solution.
141 /*!
142 * For all objects with the Mixture Fugacity approximation, we define the
143 * standard state as an ideal gas at the current temperature and pressure
144 * of the solution.
145 *
146 * @param hrt Output vector of standard state enthalpies.
147 * length = m_kk. units are unitless.
148 */
149 void getEnthalpy_RT(double* hrt) const override;
150
151 //! Get the array of nondimensional Enthalpy functions for the standard
152 //! state species at the current *T* and *P* of the solution.
153 /*!
154 * For all objects with the Mixture Fugacity approximation, we define the
155 * standard state as an ideal gas at the current temperature and pressure of
156 * the solution.
157 *
158 * @param sr Output vector of nondimensional standard state entropies.
159 * length = m_kk.
160 */
161 void getEntropy_R(double* sr) const override;
162
163 //! Get the nondimensional Gibbs functions for the species at their standard
164 //! states of solution at the current T and P of the solution.
165 /*!
166 * For all objects with the Mixture Fugacity approximation, we define the
167 * standard state as an ideal gas at the current temperature and pressure
168 * of the solution.
169 *
170 * @param grt Output vector of nondimensional standard state Gibbs free
171 * energies. length = m_kk.
172 */
173 void getGibbs_RT(double* grt) const override;
174
175 //! Returns the vector of nondimensional internal Energies of the standard
176 //! state at the current temperature and pressure of the solution for each
177 //! species.
178 /*!
179 * For all objects with the Mixture Fugacity approximation, we define the
180 * standard state as an ideal gas at the current temperature and pressure
181 * of the solution.
182 *
183 * @f[
184 * u^{ss}_k(T,P) = h^{ss}_k(T) - P * V^{ss}_k
185 * @f]
186 *
187 * @param urt Output vector of nondimensional standard state internal
188 * energies. length = m_kk.
189 */
190 void getIntEnergy_RT(double* urt) const override;
191
192 //! Get the nondimensional Heat Capacities at constant pressure for the
193 //! standard state of the species at the current T and P.
194 /*!
195 * For all objects with the Mixture Fugacity approximation, we define the
196 * standard state as an ideal gas at the current temperature and pressure of
197 * the solution.
198 *
199 * @param cpr Output vector containing the the nondimensional Heat
200 * Capacities at constant pressure for the standard state of
201 * the species. Length: m_kk.
202 */
203 void getCp_R(double* cpr) const override;
204
205 //! Get the molar volumes of each species in their standard states at the
206 //! current *T* and *P* of the solution.
207 /*!
208 * For all objects with the Mixture Fugacity approximation, we define the
209 * standard state as an ideal gas at the current temperature and pressure of
210 * the solution.
211 *
212 * units = m^3 / kmol
213 *
214 * @param vol Output vector of species volumes. length = m_kk.
215 * units = m^3 / kmol
216 */
217 void getStandardVolumes(double* vol) const override;
218 //! @}
219
220 //! Set the temperature of the phase
221 /*!
222 * Currently this passes down to setState_TP(). It does not make sense to
223 * calculate the standard state without first setting T and P.
224 *
225 * @param temp Temperature (kelvin)
226 */
227 void setTemperature(const double temp) override;
228
229 //! Set the internally stored pressure (Pa) at constant temperature and
230 //! composition
231 /*!
232 * Currently this passes down to setState_TP(). It does not make sense to
233 * calculate the standard state without first setting T and P.
234 *
235 * @param p input Pressure (Pa)
236 */
237 void setPressure(double p) override;
238
239protected:
240 void compositionChanged() override;
241
242 //! Updates the reference state thermodynamic functions at the current T of
243 //! the solution.
244 /*!
245 * This function must be called for every call to functions in this class.
246 * It checks to see whether the temperature has changed and thus the ss
247 * thermodynamics functions for all of the species must be recalculated.
248 *
249 * This function is responsible for updating the following internal members:
250 *
251 * - m_h0_RT;
252 * - m_cp0_R;
253 * - m_g0_RT;
254 * - m_s0_R;
255 */
256 virtual void _updateReferenceStateThermo() const;
257
258public:
259
260 //! @name Thermodynamic Values for the Species Reference States
261 //!
262 //! There are also temporary variables for holding the species reference-
263 //! state values of Cp, H, S, and V at the last temperature and reference
264 //! pressure called. These functions are not recalculated if a new call is
265 //! made using the previous temperature. All calculations are done within the
266 //! routine _updateRefStateThermo().
267 //! @{
268
269 void getEnthalpy_RT_ref(double* hrt) const override;
270 void getGibbs_RT_ref(double* grt) const override;
271
272protected:
273 //! Returns the vector of nondimensional Gibbs free energies of the
274 //! reference state at the current temperature of the solution and the
275 //! reference pressure for the species.
276 /*!
277 * @return Output vector contains the nondimensional Gibbs free energies
278 * of the reference state of the species
279 * length = m_kk, units = dimensionless.
280 */
281 const vector<double>& gibbs_RT_ref() const;
282
283public:
284 void getGibbs_ref(double* g) const override;
285 void getEntropy_R_ref(double* er) const override;
286 void getCp_R_ref(double* cprt) const override;
287 void getStandardVolumes_ref(double* vol) const override;
288
289 //! @}
290 //! @name Initialization Methods - For Internal use
291 //!
292 //! The following methods are used in the process of constructing
293 //! the phase and setting its parameters from a specification in an
294 //! input file. They are not normally used in application programs.
295 //! To see how they are used, see importPhase().
296 //! @{
297 bool addSpecies(shared_ptr<Species> spec) override;
298 //! @}
299
300protected:
301 //! @name Special Functions for fugacity classes
302 //! @{
303
304 //! Calculate the value of z
305 /*!
306 * @f[
307 * z = \frac{P v}{R T}
308 * @f]
309 *
310 * returns the value of z
311 */
312 double z() const;
313
314 //! Calculate the deviation terms for the total entropy of the mixture from
315 //! the ideal gas mixture
316 /**
317 * Here we use the current state conditions
318 *
319 * @returns the change in entropy in units of J kmol-1 K-1.
320 */
321 virtual double sresid() const;
322
323 //! Calculate the deviation terms for the total enthalpy of the mixture from
324 //! the ideal gas mixture
325 /**
326 * Here we use the current state conditions
327 *
328 * @returns the change in entropy in units of J kmol-1.
329 */
330 virtual double hresid() const;
331
332 //! Estimate for the saturation pressure
333 /*!
334 * Note: this is only used as a starting guess for later routines that
335 * actually calculate an accurate value for the saturation pressure.
336 *
337 * @param TKelvin temperature in kelvin
338 * @return the estimated saturation pressure at the given temperature
339 */
340 virtual double psatEst(double TKelvin) const;
341
342public:
343 //! Estimate for the molar volume of the liquid
344 /*!
345 * Note: this is only used as a starting guess for later routines that
346 * actually calculate an accurate value for the liquid molar volume. This
347 * routine doesn't change the state of the system.
348 *
349 * @param TKelvin temperature in kelvin
350 * @param pres Pressure in Pa. This is used as an initial guess. If the
351 * routine needs to change the pressure to find a stable
352 * liquid state, the new pressure is returned in this
353 * variable.
354 * @returns the estimate of the liquid volume. If the liquid can't be
355 * found, this routine returns -1.
356 */
357 virtual double liquidVolEst(double TKelvin, double& pres) const;
358
359 //! Calculates the density given the temperature and the pressure and a
360 //! guess at the density.
361 /*!
362 * Note, below T_c, this is a multivalued function. We do not cross the
363 * vapor dome in this. This is protected because it is called during
364 * setState_TP() routines. Infinite loops would result if it were not
365 * protected.
366 *
367 * @param TKelvin Temperature in Kelvin
368 * @param pressure Pressure in Pascals (Newton/m**2)
369 * @param phaseRequested int representing the phase whose density we are
370 * requesting. If we put a gas or liquid phase here, we will attempt to
371 * find a volume in that part of the volume space, only, in this
372 * routine. A value of FLUID_UNDEFINED means that we will accept
373 * anything.
374 * @param rhoguess Guessed density of the fluid. A value of -1.0 indicates
375 * that there is no guessed density
376 * @return We return the density of the fluid at the requested phase. If
377 * we have not found any acceptable density we return a -1. If we
378 * have found an acceptable density at a different phase, we
379 * return a -2.
380 */
381 virtual double densityCalc(double TKelvin, double pressure, int phaseRequested,
382 double rhoguess);
383
384protected:
385 //! Utility routine in the calculation of the saturation pressure
386 /*!
387 * @param TKelvin temperature (kelvin)
388 * @param pres pressure (Pascal)
389 * @param[out] densLiq density of liquid
390 * @param[out] densGas density of gas
391 * @param[out] liqGRT deltaG/RT of liquid
392 * @param[out] gasGRT deltaG/RT of gas
393 */
394 int corr0(double TKelvin, double pres, double& densLiq,
395 double& densGas, double& liqGRT, double& gasGRT);
396
397public:
398 //! Returns the Phase State flag for the current state of the object
399 /*!
400 * @param checkState If true, this function does a complete check to see
401 * where in parameters space we are
402 *
403 * There are three values:
404 * - WATER_GAS below the critical temperature but below the critical density
405 * - WATER_LIQUID below the critical temperature but above the critical density
406 * - WATER_SUPERCRIT above the critical temperature
407 */
408 int phaseState(bool checkState = false) const;
409
410 //! Calculate the saturation pressure at the current mixture content for the
411 //! given temperature
412 /*!
413 * @param TKelvin (input) Temperature (Kelvin)
414 * @param molarVolGas (return) Molar volume of the gas
415 * @param molarVolLiquid (return) Molar volume of the liquid
416 * @returns the saturation pressure at the given temperature
417 */
418 double calculatePsat(double TKelvin, double& molarVolGas, double& molarVolLiquid);
419
420public:
421 //! Calculate the saturation pressure at the current mixture content for the
422 //! given temperature
423 /*!
424 * @param TKelvin Temperature (Kelvin)
425 * @return The saturation pressure at the given temperature
426 */
427 double satPressure(double TKelvin) override;
428 void getActivityConcentrations(double* c) const override;
429
430protected:
431 //! Calculate the pressure and the pressure derivative given the temperature
432 //! and the molar volume
433 /*!
434 * Temperature and mole number are held constant
435 *
436 * @param TKelvin temperature in kelvin
437 * @param molarVol molar volume ( m3/kmol)
438 * @param presCalc Returns the pressure.
439 * @returns the derivative of the pressure wrt the molar volume
440 */
441 virtual double dpdVCalc(double TKelvin, double molarVol, double& presCalc) const;
442
443 virtual void updateMixingExpressions();
444
445 //! @}
446 //! @name Critical State Properties.
447 //! @{
448
449 double critTemperature() const override;
450 double critPressure() const override;
451 double critVolume() const override;
452 double critCompressibility() const override;
453 double critDensity() const override;
454 virtual void calcCriticalConditions(double& pc, double& tc, double& vc) const;
455
456 //! Solve the cubic equation of state
457 /*!
458 *
459 * Returns the number of solutions found. For the gas phase solution, it returns
460 * a positive number (1 or 2). If it only finds the liquid branch solution,
461 * it will return -1 or -2 instead of 1 or 2.
462 * If it returns 0, then there is an error.
463 * The cubic equation is solved using Nickalls' method @cite nickalls1993.
464 *
465 * @param T temperature (kelvin)
466 * @param pres pressure (Pa)
467 * @param a "a" parameter in the non-ideal EoS [Pa-m^6/kmol^2]
468 * @param b "b" parameter in the non-ideal EoS [m^3/kmol]
469 * @param aAlpha a*alpha (temperature dependent function for P-R EoS, 1 for R-K EoS)
470 * @param Vroot Roots of the cubic equation for molar volume (m3/kmol)
471 * @param an constant used in cubic equation
472 * @param bn constant used in cubic equation
473 * @param cn constant used in cubic equation
474 * @param dn constant used in cubic equation
475 * @param tc Critical temperature (kelvin)
476 * @param vc Critical volume
477 * @returns the number of solutions found
478 */
479 int solveCubic(double T, double pres, double a, double b,
480 double aAlpha, double Vroot[3], double an,
481 double bn, double cn, double dn, double tc, double vc) const;
482
483 //! @}
484
485 //! Storage for the current values of the mole fractions of the species
486 /*!
487 * This vector is kept up-to-date when some the setState functions are called.
488 */
489 vector<double> moleFractions_;
490
491 //! Current state of the fluid
492 /*!
493 * There are three possible states of the fluid:
494 * - FLUID_GAS
495 * - FLUID_LIQUID
496 * - FLUID_SUPERCRIT
497 */
498 int iState_ = FLUID_GAS;
499
500 //! Force the system to be on a particular side of the spinodal curve
501 int forcedState_ = FLUID_UNDEFINED;
502
503 //! Temporary storage for dimensionless reference state enthalpies
504 mutable vector<double> m_h0_RT;
505
506 //! Temporary storage for dimensionless reference state heat capacities
507 mutable vector<double> m_cp0_R;
508
509 //! Temporary storage for dimensionless reference state Gibbs energies
510 mutable vector<double> m_g0_RT;
511
512 //! Temporary storage for dimensionless reference state entropies
513 mutable vector<double> m_s0_R;
514};
515}
516
517#endif
Header file for class ThermoPhase, the base class for phases with thermodynamic properties,...
This is a filter class for ThermoPhase that implements some preparatory steps for efficiently handlin...
int iState_
Current state of the fluid.
int reportSolnBranchActual() const
Report the solution branch which the solution is actually on.
double enthalpy_mole() const override
Molar enthalpy. Units: J/kmol.
int standardStateConvention() const override
This method returns the convention used in specification of the standard state, of which there are cu...
MixtureFugacityTP()=default
Constructor.
vector< double > m_g0_RT
Temporary storage for dimensionless reference state Gibbs energies.
double critPressure() const override
Critical pressure (Pa).
double critDensity() const override
Critical density (kg/m3).
void getEntropy_R(double *sr) const override
Get the array of nondimensional Enthalpy functions for the standard state species at the current T an...
vector< double > m_h0_RT
Temporary storage for dimensionless reference state enthalpies.
void getGibbs_ref(double *g) const override
Returns the vector of the Gibbs function of the reference state at the current temperature of the sol...
void getStandardChemPotentials(double *mu) const override
Get the array of chemical potentials at unit activity.
double critTemperature() const override
Critical temperature (K).
void getCp_R(double *cpr) const override
Get the nondimensional Heat Capacities at constant pressure for the standard state of the species at ...
virtual void _updateReferenceStateThermo() const
Updates the reference state thermodynamic functions at the current T of the solution.
string type() const override
String indicating the thermodynamic model implemented.
double satPressure(double TKelvin) override
Calculate the saturation pressure at the current mixture content for the given temperature.
void getActivityConcentrations(double *c) const override
This method returns an array of generalized concentrations.
int solveCubic(double T, double pres, double a, double b, double aAlpha, double Vroot[3], double an, double bn, double cn, double dn, double tc, double vc) const
Solve the cubic equation of state.
double critCompressibility() const override
Critical compressibility (unitless).
void setPressure(double p) override
Set the internally stored pressure (Pa) at constant temperature and composition.
const vector< double > & gibbs_RT_ref() const
Returns the vector of nondimensional Gibbs free energies of the reference state at the current temper...
void getStandardVolumes_ref(double *vol) const override
Get the molar volumes of the species reference states at the current T and P_ref of the solution.
double calculatePsat(double TKelvin, double &molarVolGas, double &molarVolLiquid)
Calculate the saturation pressure at the current mixture content for the given temperature.
vector< double > moleFractions_
Storage for the current values of the mole fractions of the species.
void getEnthalpy_RT(double *hrt) const override
Get the nondimensional Enthalpy functions for the species at their standard states at the current T a...
void getEntropy_R_ref(double *er) const override
Returns the vector of nondimensional entropies of the reference state at the current temperature of t...
void setTemperature(const double temp) override
Set the temperature of the phase.
vector< double > m_s0_R
Temporary storage for dimensionless reference state entropies.
virtual double dpdVCalc(double TKelvin, double molarVol, double &presCalc) const
Calculate the pressure and the pressure derivative given the temperature and the molar volume.
void getGibbs_RT(double *grt) const override
Get the nondimensional Gibbs functions for the species at their standard states of solution at the cu...
double entropy_mole() const override
Molar entropy. Units: J/kmol/K.
virtual double densityCalc(double TKelvin, double pressure, int phaseRequested, double rhoguess)
Calculates the density given the temperature and the pressure and a guess at the density.
double critVolume() const override
Critical volume (m3/kmol).
virtual double psatEst(double TKelvin) const
Estimate for the saturation pressure.
void getCp_R_ref(double *cprt) const override
Returns the vector of nondimensional constant pressure heat capacities of the reference state at the ...
void getStandardVolumes(double *vol) const override
Get the molar volumes of each species in their standard states at the current T and P of the solution...
virtual double sresid() const
Calculate the deviation terms for the total entropy of the mixture from the ideal gas mixture.
void getIntEnergy_RT(double *urt) const override
Returns the vector of nondimensional internal Energies of the standard state at the current temperatu...
int forcedState_
Force the system to be on a particular side of the spinodal curve.
virtual double liquidVolEst(double TKelvin, double &pres) const
Estimate for the molar volume of the liquid.
int forcedSolutionBranch() const
Report the solution branch which the solution is restricted to.
void compositionChanged() override
Apply changes to the state which are needed after the composition changes.
vector< double > m_cp0_R
Temporary storage for dimensionless reference state heat capacities.
int corr0(double TKelvin, double pres, double &densLiq, double &densGas, double &liqGRT, double &gasGRT)
Utility routine in the calculation of the saturation pressure.
void setForcedSolutionBranch(int solnBranch)
Set the solution branch to force the ThermoPhase to exist on one branch or another.
bool addSpecies(shared_ptr< Species > spec) override
Add a Species to this Phase.
virtual double hresid() const
Calculate the deviation terms for the total enthalpy of the mixture from the ideal gas mixture.
void getGibbs_RT_ref(double *grt) const override
Returns the vector of nondimensional Gibbs Free Energies of the reference state at the current temper...
double z() const
Calculate the value of z.
int phaseState(bool checkState=false) const
Returns the Phase State flag for the current state of the object.
void getEnthalpy_RT_ref(double *hrt) const override
Returns the vector of nondimensional enthalpies of the reference state at the current temperature of ...
virtual double pressure() const
Return the thermodynamic pressure (Pa).
Definition Phase.h:616
Base class for a phase with thermodynamic properties.
Namespace for the Cantera kernel.
Definition AnyMap.cpp:595