Cantera  4.0.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(span<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(span<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(span<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(span<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(span<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(span<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(span<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(span<double> hrt) const override;
270 void getGibbs_RT_ref(span<double> grt) const override;
271 void getGibbs_ref(span<double> g) const override;
272 void getEntropy_R_ref(span<double> er) const override;
273 void getCp_R_ref(span<double> cprt) const override;
274 void getStandardVolumes_ref(span<double> vol) const override;
275
276 //! @}
277 //! @name Initialization Methods - For Internal use
278 //!
279 //! The following methods are used in the process of constructing
280 //! the phase and setting its parameters from a specification in an
281 //! input file. They are not normally used in application programs.
282 //! To see how they are used, see importPhase().
283 //! @{
284 bool addSpecies(shared_ptr<Species> spec) override;
285 //! @}
286
287protected:
288 //! @name Special Functions for fugacity classes
289 //! @{
290
291 //! Calculate the value of z
292 /*!
293 * @f[
294 * z = \frac{P v}{R T}
295 * @f]
296 *
297 * returns the value of z
298 */
299 double z() const;
300
301 //! Calculate the deviation terms for the total entropy of the mixture from
302 //! the ideal gas mixture
303 /**
304 * Here we use the current state conditions
305 *
306 * @returns the change in entropy in units of J kmol-1 K-1.
307 */
308 virtual double sresid() const;
309
310 //! Calculate the deviation terms for the total enthalpy of the mixture from
311 //! the ideal gas mixture
312 /**
313 * Here we use the current state conditions
314 *
315 * @returns the change in entropy in units of J kmol-1.
316 */
317 virtual double hresid() const;
318
319 //! Estimate for the saturation pressure
320 /*!
321 * Note: this is only used as a starting guess for later routines that
322 * actually calculate an accurate value for the saturation pressure.
323 *
324 * @param TKelvin temperature in kelvin
325 * @return the estimated saturation pressure at the given temperature
326 */
327 virtual double psatEst(double TKelvin) const;
328
329public:
330 //! Estimate for the molar volume of the liquid
331 /*!
332 * Note: this is only used as a starting guess for later routines that
333 * actually calculate an accurate value for the liquid molar volume. This
334 * routine doesn't change the state of the system.
335 *
336 * @param TKelvin temperature in kelvin
337 * @param pres Pressure in Pa. This is used as an initial guess. If the
338 * routine needs to change the pressure to find a stable
339 * liquid state, the new pressure is returned in this
340 * variable.
341 * @returns the estimate of the liquid volume. If the liquid can't be
342 * found, this routine returns -1.
343 */
344 virtual double liquidVolEst(double TKelvin, double& pres) const;
345
346 //! Calculates the density given the temperature and the pressure and a
347 //! guess at the density.
348 /*!
349 * Note, below T_c, this is a multivalued function. We do not cross the
350 * vapor dome in this. This is protected because it is called during
351 * setState_TP() routines. Infinite loops would result if it were not
352 * protected.
353 *
354 * @param TKelvin Temperature in Kelvin
355 * @param pressure Pressure in Pascals (Newton/m**2)
356 * @param phaseRequested int representing the phase whose density we are
357 * requesting. If we put a gas or liquid phase here, we will attempt to
358 * find a volume in that part of the volume space, only, in this
359 * routine. A value of FLUID_UNDEFINED means that we will accept
360 * anything.
361 * @param rhoguess Guessed density of the fluid. A value of -1.0 indicates
362 * that there is no guessed density
363 * @return We return the density of the fluid at the requested phase. If
364 * we have not found any acceptable density we return a -1. If we
365 * have found an acceptable density at a different phase, we
366 * return a -2.
367 */
368 virtual double densityCalc(double TKelvin, double pressure, int phaseRequested,
369 double rhoguess);
370
371protected:
372 //! Utility routine in the calculation of the saturation pressure
373 /*!
374 * @param TKelvin temperature (kelvin)
375 * @param pres pressure (Pascal)
376 * @param[out] densLiq density of liquid
377 * @param[out] densGas density of gas
378 * @param[out] liqGRT deltaG/RT of liquid
379 * @param[out] gasGRT deltaG/RT of gas
380 */
381 int corr0(double TKelvin, double pres, double& densLiq,
382 double& densGas, double& liqGRT, double& gasGRT);
383
384public:
385 //! Returns the Phase State flag for the current state of the object
386 /*!
387 * @param checkState If true, this function does a complete check to see
388 * where in parameters space we are
389 *
390 * There are three values:
391 * - WATER_GAS below the critical temperature but below the critical density
392 * - WATER_LIQUID below the critical temperature but above the critical density
393 * - WATER_SUPERCRIT above the critical temperature
394 */
395 int phaseState(bool checkState = false) const;
396
397 //! Calculate the saturation pressure at the current mixture content for the
398 //! given temperature
399 /*!
400 * @param TKelvin (input) Temperature (Kelvin)
401 * @param molarVolGas (return) Molar volume of the gas
402 * @param molarVolLiquid (return) Molar volume of the liquid
403 * @returns the saturation pressure at the given temperature
404 */
405 double calculatePsat(double TKelvin, double& molarVolGas, double& molarVolLiquid);
406
407public:
408 //! Calculate the saturation pressure at the current mixture content for the
409 //! given temperature
410 /*!
411 * @param TKelvin Temperature (Kelvin)
412 * @return The saturation pressure at the given temperature
413 */
414 double satPressure(double TKelvin) override;
415 void getActivityConcentrations(span<double> c) const override;
416
417protected:
418 //! Calculate the pressure and the pressure derivative given the temperature
419 //! and the molar volume
420 /*!
421 * Temperature and mole number are held constant
422 *
423 * @param TKelvin temperature in kelvin
424 * @param molarVol molar volume ( m3/kmol)
425 * @param presCalc Returns the pressure.
426 * @returns the derivative of the pressure wrt the molar volume
427 */
428 virtual double dpdVCalc(double TKelvin, double molarVol, double& presCalc) const;
429
430 virtual void updateMixingExpressions();
431
432 //! @}
433 //! @name Critical State Properties.
434 //! @{
435
436 double critTemperature() const override;
437 double critPressure() const override;
438 double critVolume() const override;
439 double critCompressibility() const override;
440 double critDensity() const override;
441 virtual void calcCriticalConditions(double& pc, double& tc, double& vc) const;
442
443 //! Solve the cubic equation of state
444 /*!
445 *
446 * Returns the number of solutions found. For the gas phase solution, it returns
447 * a positive number (1 or 2). If it only finds the liquid branch solution,
448 * it will return -1 or -2 instead of 1 or 2.
449 * If it returns 0, then there is an error.
450 * The cubic equation is solved using Nickalls' method @cite nickalls1993.
451 *
452 * @param T temperature (kelvin)
453 * @param pres pressure (Pa)
454 * @param a "a" parameter in the non-ideal EoS [Pa-m^6/kmol^2]
455 * @param b "b" parameter in the non-ideal EoS [m^3/kmol]
456 * @param aAlpha a*alpha (temperature dependent function for P-R EoS, 1 for R-K EoS)
457 * @param Vroot Roots of the cubic equation for molar volume (m3/kmol)
458 * @param an constant used in cubic equation
459 * @param bn constant used in cubic equation
460 * @param cn constant used in cubic equation
461 * @param dn constant used in cubic equation
462 * @param tc Critical temperature (kelvin)
463 * @param vc Critical volume
464 * @returns the number of solutions found
465 */
466 int solveCubic(double T, double pres, double a, double b,
467 double aAlpha, span<double> Vroot, double an,
468 double bn, double cn, double dn, double tc, double vc) const;
469
470 //! @}
471
472 //! Storage for the current values of the mole fractions of the species
473 /*!
474 * This vector is kept up-to-date when some the setState functions are called.
475 */
476 vector<double> moleFractions_;
477
478 //! Current state of the fluid
479 /*!
480 * There are three possible states of the fluid:
481 * - FLUID_GAS
482 * - FLUID_LIQUID
483 * - FLUID_SUPERCRIT
484 */
485 int iState_ = FLUID_GAS;
486
487 //! Force the system to be on a particular side of the spinodal curve
488 int forcedState_ = FLUID_UNDEFINED;
489
490 //! Temporary storage for dimensionless reference state enthalpies
491 mutable vector<double> m_h0_RT;
492
493 //! Temporary storage for dimensionless reference state heat capacities
494 mutable vector<double> m_cp0_R;
495
496 //! Temporary storage for dimensionless reference state Gibbs energies
497 mutable vector<double> m_g0_RT;
498
499 //! Temporary storage for dimensionless reference state entropies
500 mutable vector<double> m_s0_R;
501};
502}
503
504#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.
void getGibbs_ref(span< double > g) const override
Returns the vector of the Gibbs function of the reference state at the current temperature of the sol...
int reportSolnBranchActual() const
Report the solution branch which the solution is actually on.
double enthalpy_mole() const override
Molar enthalpy. Units: J/kmol.
void getCp_R(span< double > cpr) const override
Get the nondimensional Heat Capacities at constant pressure for the standard state of the species at ...
int standardStateConvention() const override
This method returns the convention used in specification of the standard state, of which there are cu...
void getEntropy_R_ref(span< double > er) const override
Returns the vector of nondimensional entropies of the reference state at the current temperature of t...
MixtureFugacityTP()=default
Constructor.
vector< double > m_g0_RT
Temporary storage for dimensionless reference state Gibbs energies.
void getIntEnergy_RT(span< double > urt) const override
Returns the vector of nondimensional internal Energies of the standard state at the current temperatu...
double critPressure() const override
Critical pressure (Pa).
double critDensity() const override
Critical density (kg/m3).
vector< double > m_h0_RT
Temporary storage for dimensionless reference state enthalpies.
void getStandardChemPotentials(span< double > mu) const override
Get the array of chemical potentials at unit activity.
double critTemperature() const override
Critical temperature (K).
void getGibbs_RT(span< double > grt) const override
Get the nondimensional Gibbs functions for the species at their standard states of solution at the cu...
void getCp_R_ref(span< double > cprt) const override
Returns the vector of nondimensional constant pressure heat capacities of the reference state at the ...
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.
double critCompressibility() const override
Critical compressibility (unitless).
void setPressure(double p) override
Set the internally stored pressure (Pa) at constant temperature and composition.
void getEnthalpy_RT_ref(span< double > hrt) const override
Returns the vector of nondimensional enthalpies of the reference state at the current temperature of ...
void getEnthalpy_RT(span< double > hrt) const override
Get the nondimensional Enthalpy functions for the species at their standard states at the current T a...
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.
int solveCubic(double T, double pres, double a, double b, double aAlpha, span< double > Vroot, double an, double bn, double cn, double dn, double tc, double vc) const
Solve the cubic equation of state.
void getEntropy_R(span< double > sr) const override
Get the array of nondimensional Enthalpy functions for the standard state species at the current T an...
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.
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 getGibbs_RT_ref(span< double > grt) const override
Returns the vector of nondimensional Gibbs Free Energies of the reference state at the current temper...
virtual double sresid() const
Calculate the deviation terms for the total entropy of the mixture from the ideal gas mixture.
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 getStandardVolumes(span< double > vol) const override
Get the molar volumes of each species in their standard states at the current T and P of the solution...
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 getActivityConcentrations(span< double > c) const override
This method returns an array of generalized concentrations.
double z() const
Calculate the value of z.
void getStandardVolumes_ref(span< double > vol) const override
Get the molar volumes of the species reference states at the current T and P_ref of the solution.
int phaseState(bool checkState=false) const
Returns the Phase State flag for the current state of the object.
virtual double pressure() const
Return the thermodynamic pressure (Pa).
Definition Phase.h:603
Base class for a phase with thermodynamic properties.
Namespace for the Cantera kernel.
Definition AnyMap.cpp:595