Cantera 2.6.0
PengRobinson.h
Go to the documentation of this file.
1//! @file PengRobinson.h
2
3// This file is part of Cantera. See License.txt in the top-level directory or
4// at https://cantera.org/license.txt for license and copyright information.
5
6#ifndef CT_PENGROBINSON_H
7#define CT_PENGROBINSON_H
8
9#include "MixtureFugacityTP.h"
10#include "cantera/base/Array.h"
11
12namespace Cantera
13{
14/**
15 * Implementation of a multi-species Peng-Robinson equation of state
16 *
17 * @ingroup thermoprops
18 */
20{
21public:
22
23 //! Construct and initialize a PengRobinson object directly from an
24 //! input file
25 /*!
26 * @param infile Name of the input file containing the phase YAML data.
27 * If blank, an empty phase will be created.
28 * @param id ID of the phase in the input file. If empty, the
29 * first phase definition in the input file will be used.
30 */
31 explicit PengRobinson(const std::string& infile="",
32 const std::string& id="");
33
34 virtual std::string type() const {
35 return "Peng-Robinson";
36 }
37
38 //! @name Molar Thermodynamic properties
39 //! @{
40
41 virtual double cp_mole() const;
42 virtual double cv_mole() const;
43
44 //! @}
45 //! @name Mechanical Properties
46 //! @{
47
48 //! Return the thermodynamic pressure (Pa).
49 /*!
50 * Since the mass density, temperature, and mass fractions are stored,
51 * this method uses these values to implement the
52 * mechanical equation of state \f$ P(T, \rho, Y_1, \dots, Y_K) \f$.
53 *
54 * \f[
55 * P = \frac{RT}{v-b_{mix}}
56 * - \frac{\left(\alpha a\right)_{mix}}{v^2 + 2b_{mix}v - b_{mix}^2}
57 * \f]
58 *
59 * where:
60 *
61 * \f[
62 * \alpha = \left[ 1 + \kappa \left(1-T_r^{0.5}\right)\right]^2
63 * \f]
64 *
65 * and
66 *
67 * \f[
68 * \kappa = \left(0.37464 + 1.54226\omega - 0.26992\omega^2\right),
69 * \qquad \qquad \text{For } \omega <= 0.491 \\
70 *
71 * \kappa = \left(0.379642 + 1.487503\omega - 0.164423\omega^2 + 0.016667\omega^3 \right),
72 * \qquad \text{For } \omega > 0.491
73 * \f]
74 *
75 * Coefficients \f$ a_{mix}, b_{mix} \f$ and \f$(a \alpha)_{mix}\f$ are calculated as
76 *
77 * \f[
78 * a_{mix} = \sum_i \sum_j X_i X_j a_{i, j} = \sum_i \sum_j X_i X_j \sqrt{a_i a_j}
79 * \f]
80 *
81 * \f[
82 * b_{mix} = \sum_i X_i b_i
83 * \f]
84 *
85 * \f[
86 * {a \alpha}_{mix} = \sum_i \sum_j X_i X_j {a \alpha}_{i, j}
87 * = \sum_i \sum_j X_i X_j \sqrt{a_i a_j} \sqrt{\alpha_i \alpha_j}
88 * \f]
89 */
90 virtual double pressure() const;
91
92 //! @}
93
94 //! Returns the standard concentration \f$ C^0_k \f$, which is used to
95 //! normalize the generalized concentration.
96 /*!
97 * This is defined as the concentration by which the generalized
98 * concentration is normalized to produce the activity.
99 * The ideal gas mixture is considered as the standard or reference state here.
100 * Since the activity for an ideal gas mixture is simply the mole fraction,
101 * for an ideal gas, \f$ C^0_k = P/\hat R T \f$.
102 *
103 * @param k Optional parameter indicating the species. The default is to
104 * assume this refers to species 0.
105 * @return
106 * Returns the standard Concentration in units of m^3 / kmol.
107 */
108 virtual double standardConcentration(size_t k=0) const;
109
110 //! Get the array of non-dimensional activity coefficients at the current
111 //! solution temperature, pressure, and solution concentration.
112 /*!
113 * For all objects with the Mixture Fugacity approximation, we define the
114 * standard state as an ideal gas at the current temperature and pressure of
115 * the solution. The activities are based on this standard state.
116 *
117 * @param ac Output vector of activity coefficients. Length: m_kk.
118 */
119 virtual void getActivityCoefficients(double* ac) const;
120
121 //! @name Partial Molar Properties of the Solution
122 //! @{
123
124 virtual void getChemPotentials(double* mu) const;
125 virtual void getPartialMolarEnthalpies(double* hbar) const;
126 virtual void getPartialMolarEntropies(double* sbar) const;
127 virtual void getPartialMolarIntEnergies(double* ubar) const;
128 //! Calculate species-specific molar specific heats
129 /*!
130 * This function is currently not implemented for Peng-Robinson phase.
131 */
132 virtual void getPartialMolarCp(double* cpbar) const;
133 virtual void getPartialMolarVolumes(double* vbar) const;
134 //! @}
135
136 //! Calculate species-specific critical temperature
137 /*!
138 * The temperature dependent parameter in P-R EoS is calculated as
139 * \f[ T_{crit} = (0.0778 a)/(0.4572 b R) \f]
140 * Units: Kelvin
141 *
142 * @param a species-specific coefficients used in P-R EoS
143 * @param b species-specific coefficients used in P-R EoS
144 */
145 virtual double speciesCritTemperature(double a, double b) const;
146
147 //! @name Initialization Methods - For Internal use
148 /*!
149 * The following methods are used in the process of constructing
150 * the phase and setting its parameters from a specification in an
151 * input file. They are not normally used in application programs.
152 * To see how they are used, see importPhase().
153 */
154 //! @{
155
156 virtual bool addSpecies(shared_ptr<Species> spec);
157 virtual void initThermo();
158 virtual void getSpeciesParameters(const std::string& name,
159 AnyMap& speciesNode) const;
160
161 //! Set the pure fluid interaction parameters for a species
162 /*!
163 * @param species Name of the species
164 * @param a \f$a\f$ parameter in the Peng-Robinson model [Pa-m^6/kmol^2]
165 * @param b \f$a\f$ parameter in the Peng-Robinson model [m^3/kmol]
166 * @param w acentric factor
167 */
168 void setSpeciesCoeffs(const std::string& species, double a, double b,
169 double w);
170
171 //! Set values for the interaction parameter between two species
172 /*!
173 * @param species_i Name of one species
174 * @param species_j Name of the other species
175 * @param a \f$a\f$ parameter in the Peng-Robinson model [Pa-m^6/kmol^2]
176 */
177 void setBinaryCoeffs(const std::string& species_i,
178 const std::string& species_j, double a);
179 //! @}
180
181protected:
182 // Special functions inherited from MixtureFugacityTP
183 virtual double sresid() const;
184 virtual double hresid() const;
185
186 virtual double liquidVolEst(double T, double& pres) const;
187 virtual double densityCalc(double T, double pressure, int phase, double rhoguess);
188
189 virtual double densSpinodalLiquid() const;
190 virtual double densSpinodalGas() const;
191 virtual double dpdVCalc(double T, double molarVol, double& presCalc) const;
192
193 // Special functions not inherited from MixtureFugacityTP
194
195 //! Calculate temperature derivative \f$d(a \alpha)/dT\f$
196 /*!
197 * These are stored internally.
198 */
199 double daAlpha_dT() const;
200
201 //! Calculate second derivative \f$d^2(a \alpha)/dT^2\f$
202 /*!
203 * These are stored internally.
204 */
205 double d2aAlpha_dT2() const;
206
207public:
208
209 //! Calculate \f$dp/dV\f$ and \f$dp/dT\f$ at the current conditions
210 /*!
211 * These are stored internally.
212 */
213 void calculatePressureDerivatives() const;
214
215 //! Update the \f$a\f$, \f$b\f$, and \f$\alpha\f$ parameters
216 /*!
217 * The \f$a\f$ and the \f$b\f$ parameters depend on the mole fraction and the
218 * parameter \f$\alpha\f$ depends on the temperature. This function updates
219 * the internal numbers based on the state of the object.
220 */
221 virtual void updateMixingExpressions();
222
223 //! Calculate the \f$a\f$, \f$b\f$, and \f$\alpha\f$ parameters given the temperature
224 /*!
225 * This function doesn't change the internal state of the object, so it is a
226 * const function. It does use the stored mole fractions in the object.
227 *
228 * @param aCalc (output) Returns the a value
229 * @param bCalc (output) Returns the b value.
230 * @param aAlpha (output) Returns the (a*alpha) value.
231 */
232 void calculateAB(double& aCalc, double& bCalc, double& aAlpha) const;
233
234 void calcCriticalConditions(double& pc, double& tc, double& vc) const;
235
236 //! Prepare variables and call the function to solve the cubic equation of state
237 int solveCubic(double T, double pres, double a, double b, double aAlpha,
238 double Vroot[3]) const;
239protected:
240 //! Value of \f$b\f$ in the equation of state
241 /*!
242 * `m_b` is a function of the mole fractions and species-specific b values.
243 */
244 double m_b;
245
246 //! Value of \f$a\f$ in the equation of state
247 /*!
248 * `m_a` depends only on the mole fractions.
249 */
250 double m_a;
251
252 //! Value of \f$\alpha\f$ in the equation of state
253 /*!
254 * `m_aAlpha_mix` is a function of the temperature and the mole fractions.
255 */
257
258 // Vectors required to store species-specific a_coeff, b_coeff, alpha, kappa
259 // and other derivatives. Length = m_kk.
260 vector_fp m_b_coeffs;
261 vector_fp m_kappa;
262 vector_fp m_acentric; //!< acentric factor for each species, length #m_kk
263 mutable vector_fp m_dalphadT;
264 mutable vector_fp m_d2alphadT2;
265 vector_fp m_alpha;
266
267 // Matrices for Binary coefficients a_{i,j} and {a*alpha}_{i.j} are saved in an
268 // array form. Size = (m_kk, m_kk).
269 Array2D m_a_coeffs;
270 Array2D m_aAlpha_binary;
271
272 //! Explicitly-specified binary interaction parameters, to enable serialization
273 std::map<std::string, std::map<std::string, double>> m_binaryParameters;
274
275 int m_NSolns;
276
277 double m_Vroot[3];
278
279 //! Temporary storage - length = m_kk.
281
282 // Partial molar volumes of the species
283 mutable vector_fp m_partialMolarVolumes;
284
285 //! The derivative of the pressure with respect to the volume
286 /*!
287 * Calculated at the current conditions. temperature and mole number kept
288 * constant
289 */
290 mutable double m_dpdV;
291
292 //! The derivative of the pressure with respect to the temperature
293 /*!
294 * Calculated at the current conditions. Total volume and mole number kept
295 * constant
296 */
297 mutable double m_dpdT;
298
299 //! Vector of derivatives of pressure with respect to mole number
300 /*!
301 * Calculated at the current conditions. Total volume, temperature and
302 * other mole number kept constant
303 */
305
306 enum class CoeffSource { EoS, CritProps, Database };
307 //! For each species, specifies the source of the a, b, and omega coefficients
308 std::vector<CoeffSource> m_coeffSource;
309
310private:
311 //! Omega constant: a0 (= omega_a) used in Peng-Robinson equation of state
312 /*!
313 * This value is calculated by solving P-R cubic equation at the critical point.
314 */
315 static const double omega_a;
316
317 //! Omega constant: b0 (= omega_b) used in Peng-Robinson equation of state
318 /*!
319 * This value is calculated by solving P-R cubic equation at the critical point.
320 */
321 static const double omega_b;
322
323 //! Omega constant for the critical molar volume
324 static const double omega_vc;
325};
326}
327
328#endif
Header file for class Cantera::Array2D.
Header file for a derived class of ThermoPhase that handles non-ideal mixtures based on the fugacity ...
A map of string keys to values whose type can vary at runtime.
Definition: AnyMap.h:399
A class for 2D arrays stored in column-major (Fortran-compatible) form.
Definition: Array.h:30
This is a filter class for ThermoPhase that implements some preparatory steps for efficiently handlin...
Implementation of a multi-species Peng-Robinson equation of state.
Definition: PengRobinson.h:20
virtual double cv_mole() const
Molar heat capacity at constant volume. Units: J/kmol/K.
virtual bool addSpecies(shared_ptr< Species > spec)
void setSpeciesCoeffs(const std::string &species, double a, double b, double w)
Set the pure fluid interaction parameters for a species.
virtual double standardConcentration(size_t k=0) const
Returns the standard concentration , which is used to normalize the generalized concentration.
virtual double densityCalc(double T, double pressure, int phase, double rhoguess)
Calculates the density given the temperature and the pressure and a guess at the density.
virtual double pressure() const
Return the thermodynamic pressure (Pa).
static const double omega_b
Omega constant: b0 (= omega_b) used in Peng-Robinson equation of state.
Definition: PengRobinson.h:321
virtual void getPartialMolarEnthalpies(double *hbar) const
Returns an array of partial molar enthalpies for the species in the mixture.
vector_fp m_pp
Temporary storage - length = m_kk.
Definition: PengRobinson.h:280
virtual double densSpinodalLiquid() const
Return the value of the density at the liquid spinodal point (on the liquid side) for the current tem...
virtual void getActivityCoefficients(double *ac) const
Get the array of non-dimensional activity coefficients at the current solution temperature,...
virtual double dpdVCalc(double T, double molarVol, double &presCalc) const
Calculate the pressure and the pressure derivative given the temperature and the molar volume.
virtual double cp_mole() const
Molar heat capacity at constant pressure. Units: J/kmol/K.
std::vector< CoeffSource > m_coeffSource
For each species, specifies the source of the a, b, and omega coefficients.
Definition: PengRobinson.h:308
double m_dpdT
The derivative of the pressure with respect to the temperature.
Definition: PengRobinson.h:297
PengRobinson(const std::string &infile="", const std::string &id="")
Construct and initialize a PengRobinson object directly from an input file.
virtual void updateMixingExpressions()
Update the , , and parameters.
virtual void getChemPotentials(double *mu) const
Get the species chemical potentials. Units: J/kmol.
virtual double liquidVolEst(double T, double &pres) const
Estimate for the molar volume of the liquid.
virtual double densSpinodalGas() const
Return the value of the density at the gas spinodal point (on the gas side) for the current temperatu...
int solveCubic(double T, double pres, double a, double b, double aAlpha, double Vroot[3]) const
Prepare variables and call the function to solve the cubic equation of state.
std::map< std::string, std::map< std::string, double > > m_binaryParameters
Explicitly-specified binary interaction parameters, to enable serialization.
Definition: PengRobinson.h:273
virtual void initThermo()
Initialize the ThermoPhase object after all species have been set up.
double daAlpha_dT() const
Calculate temperature derivative .
void calculatePressureDerivatives() const
Calculate and at the current conditions.
virtual void getPartialMolarIntEnergies(double *ubar) const
Return an array of partial molar internal energies for the species in the mixture.
double m_aAlpha_mix
Value of in the equation of state.
Definition: PengRobinson.h:256
double m_a
Value of in the equation of state.
Definition: PengRobinson.h:250
static const double omega_a
Omega constant: a0 (= omega_a) used in Peng-Robinson equation of state.
Definition: PengRobinson.h:315
virtual std::string type() const
String indicating the thermodynamic model implemented.
Definition: PengRobinson.h:34
void setBinaryCoeffs(const std::string &species_i, const std::string &species_j, double a)
Set values for the interaction parameter between two species.
static const double omega_vc
Omega constant for the critical molar volume.
Definition: PengRobinson.h:324
virtual void getPartialMolarVolumes(double *vbar) const
Return an array of partial molar volumes for the species in the mixture.
void calculateAB(double &aCalc, double &bCalc, double &aAlpha) const
Calculate the , , and parameters given the temperature.
virtual double sresid() const
Calculate the deviation terms for the total entropy of the mixture from the ideal gas mixture.
double m_b
Value of in the equation of state.
Definition: PengRobinson.h:244
virtual void getSpeciesParameters(const std::string &name, AnyMap &speciesNode) const
Get phase-specific parameters of a Species object such that an identical one could be reconstructed a...
vector_fp m_dpdni
Vector of derivatives of pressure with respect to mole number.
Definition: PengRobinson.h:304
virtual double hresid() const
Calculate the deviation terms for the total enthalpy of the mixture from the ideal gas mixture.
double d2aAlpha_dT2() const
Calculate second derivative .
virtual void getPartialMolarEntropies(double *sbar) const
Returns an array of partial molar entropies of the species in the solution.
virtual void getPartialMolarCp(double *cpbar) const
Calculate species-specific molar specific heats.
double m_dpdV
The derivative of the pressure with respect to the volume.
Definition: PengRobinson.h:290
virtual double speciesCritTemperature(double a, double b) const
Calculate species-specific critical temperature.
vector_fp m_acentric
acentric factor for each species, length m_kk
Definition: PengRobinson.h:262
std::string name() const
Return the name of the phase.
Definition: Phase.cpp:70
shared_ptr< Species > species(const std::string &name) const
Return the Species object for the named species.
Definition: Phase.cpp:950
Namespace for the Cantera kernel.
Definition: AnyMap.h:29
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:184