Cantera 2.6.0
RedlichKwongMFTP.h
Go to the documentation of this file.
1//! @file RedlichKwongMFTP.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_REDLICHKWONGMFTP_H
7#define CT_REDLICHKWONGMFTP_H
8
9#include "MixtureFugacityTP.h"
10#include "cantera/base/Array.h"
11
12namespace Cantera
13{
14/**
15 * Implementation of a multi-species Redlich-Kwong equation of state
16 *
17 * @ingroup thermoprops
18 */
20{
21public:
22 //! Construct a RedlichKwongMFTP object from an input file
23 /*!
24 * @param infile Name of the input file containing the phase definition.
25 * If blank, an empty phase will be created.
26 * @param id name (ID) of the phase in the input file. If empty, the
27 * first phase definition in the input file will be used.
28 */
29 explicit RedlichKwongMFTP(const std::string& infile="",
30 const std::string& id="");
31
32 //! Construct and initialize a RedlichKwongMFTP object directly from an
33 //! XML database
34 /*!
35 * @param phaseRef XML phase node containing the description of the phase
36 * @param id id attribute containing the name of the phase. (default
37 * is the empty string)
38 *
39 * @deprecated The XML input format is deprecated and will be removed in
40 * Cantera 3.0.
41 */
42 RedlichKwongMFTP(XML_Node& phaseRef, const std::string& id = "");
43
44 virtual std::string type() const {
45 return "RedlichKwong";
46 }
47
48 //! @name Molar Thermodynamic properties
49 //! @{
50 virtual doublereal cp_mole() const;
51 virtual doublereal cv_mole() const;
52 //! @}
53 //! @name Mechanical Properties
54 //! @{
55
56 //! Return the thermodynamic pressure (Pa).
57 /*!
58 * Since the mass density, temperature, and mass fractions are stored,
59 * this method uses these values to implement the
60 * mechanical equation of state \f$ P(T, \rho, Y_1, \dots, Y_K) \f$.
61 *
62 * \f[
63 * P = \frac{RT}{v-b_{mix}} - \frac{a_{mix}}{T^{0.5} v \left( v + b_{mix} \right) }
64 * \f]
65 */
66 virtual doublereal pressure() const;
67
68 //! @}
69
70public:
71
72 //! Returns the standard concentration \f$ C^0_k \f$, which is used to
73 //! normalize the generalized concentration.
74 /*!
75 * This is defined as the concentration by which the generalized
76 * concentration is normalized to produce the activity. In many cases, this
77 * quantity will be the same for all species in a phase. Since the activity
78 * for an ideal gas mixture is simply the mole fraction, for an ideal gas
79 * \f$ C^0_k = P/\hat R T \f$.
80 *
81 * @param k Optional parameter indicating the species. The default is to
82 * assume this refers to species 0.
83 * @return
84 * Returns the standard Concentration in units of m3 kmol-1.
85 */
86 virtual doublereal standardConcentration(size_t k=0) const;
87
88 //! Get the array of non-dimensional activity coefficients at the current
89 //! solution temperature, pressure, and solution concentration.
90 /*!
91 * For all objects with the Mixture Fugacity approximation, we define the
92 * standard state as an ideal gas at the current temperature and pressure of
93 * the solution. The activities are based on this standard state.
94 *
95 * @param ac Output vector of activity coefficients. Length: m_kk.
96 */
97 virtual void getActivityCoefficients(doublereal* ac) const;
98
99 /// @name Partial Molar Properties of the Solution
100 //! @{
101
102 //! Get the array of non-dimensional species chemical potentials.
103 //! These are partial molar Gibbs free energies.
104 /*!
105 * \f$ \mu_k / \hat R T \f$.
106 * Units: unitless
107 *
108 * We close the loop on this function, here, calling getChemPotentials() and
109 * then dividing by RT. No need for child classes to handle.
110 *
111 * @param mu Output vector of non-dimensional species chemical potentials
112 * Length: m_kk.
113 */
114 virtual void getChemPotentials_RT(doublereal* mu) const;
115
116 virtual void getChemPotentials(doublereal* mu) const;
117 virtual void getPartialMolarEnthalpies(doublereal* hbar) const;
118 virtual void getPartialMolarEntropies(doublereal* sbar) const;
119 virtual void getPartialMolarIntEnergies(doublereal* ubar) const;
120 virtual void getPartialMolarCp(double* cpbar) const {
121 throw NotImplementedError("RedlichKwongMFTP::getPartialMolarCp");
122 }
123 virtual void getPartialMolarVolumes(doublereal* vbar) const;
124 //! @}
125
126public:
127 //! @name Initialization Methods - For Internal use
128 /*!
129 * The following methods are used in the process of constructing
130 * the phase and setting its parameters from a specification in an
131 * input file. They are not normally used in application programs.
132 * To see how they are used, see importPhase().
133 */
134 //! @{
135
136 virtual bool addSpecies(shared_ptr<Species> spec);
137 virtual void setParametersFromXML(const XML_Node& thermoNode);
138 virtual void initThermoXML(XML_Node& phaseNode, const std::string& id);
139 virtual void initThermo();
140 virtual void getSpeciesParameters(const std::string& name,
141 AnyMap& speciesNode) const;
142
143 //! Retrieve a and b coefficients by looking up tabulated critical parameters
144 /*!
145 * If pureFluidParameters are not provided for any species in the phase,
146 * consult the critical properties tabulated in `critical-properties.yaml`.
147 * If the species is found there, calculate pure fluid parameters a_k and b_k as:
148 * \f[ a_k = 0.4278*R**2*T_c^2.5/P_c \f]
149 *
150 * and:
151 * \f[ b_k = 0.08664*R*T_c/P_c \f]
152 *
153 * @deprecated To be removed after Cantera 2.6. Use of critical-properties.yaml is
154 * integrated into initThermo() for YAML input files.
155 *
156 * @param iName Name of the species
157 */
158 virtual std::vector<double> getCoeff(const std::string& iName);
159
160 //! Set the pure fluid interaction parameters for a species
161 /*!
162 * The "a" parameter for species *i* in the Redlich-Kwong model is assumed
163 * to be a linear function of temperature:
164 * \f[ a = a_0 + a_1 T \f]
165 *
166 * @param species Name of the species
167 * @param a0 constant term in the expression for the "a" parameter
168 * of the specified species [Pa-m^6/kmol^2]
169 * @param a1 temperature-proportional term in the expression for the
170 * "a" parameter of the specified species [Pa-m^6/kmol^2/K]
171 * @param b "b" parameter in the Redlich-Kwong model [m^3/kmol]
172 */
173 void setSpeciesCoeffs(const std::string& species, double a0, double a1,
174 double b);
175
176 //! Set values for the interaction parameter between two species
177 /*!
178 * The "a" parameter for interactions between species *i* and *j* is
179 * assumed by default to be computed as:
180 * \f[ a_{ij} = \sqrt(a_{i,0} a_{j,0}) + \sqrt(a_{i,1} a_{j,1}) T \f]
181 *
182 * This function overrides the defaults with the specified parameters:
183 * \f[ a_{ij} = a_{ij,0} + a_{ij,1} T \f]
184 *
185 * @param species_i Name of one species
186 * @param species_j Name of the other species
187 * @param a0 constant term in the "a" expression [Pa-m^6/kmol^2]
188 * @param a1 temperature-proportional term in the "a" expression
189 * [Pa-m^6/kmol^2/K]
190 */
191 void setBinaryCoeffs(const std::string& species_i,
192 const std::string& species_j, double a0, double a1);
193
194private:
195 //! Read the pure species RedlichKwong input parameters
196 /*!
197 * @param pureFluidParam XML_Node for the pure fluid parameters
198 */
199 void readXMLPureFluid(XML_Node& pureFluidParam);
200
201 //! Read the cross species RedlichKwong input parameters
202 /*!
203 * @param pureFluidParam XML_Node for the cross fluid parameters
204 */
205 void readXMLCrossFluid(XML_Node& pureFluidParam);
206
207 //! @}
208
209protected:
210 // Special functions inherited from MixtureFugacityTP
211 virtual doublereal sresid() const;
212 virtual doublereal hresid() const;
213
214public:
215 virtual doublereal liquidVolEst(doublereal TKelvin, doublereal& pres) const;
216 virtual doublereal densityCalc(doublereal T, doublereal pressure, int phase, doublereal rhoguess);
217
218 virtual doublereal densSpinodalLiquid() const;
219 virtual doublereal densSpinodalGas() const;
220 virtual doublereal dpdVCalc(doublereal TKelvin, doublereal molarVol, doublereal& presCalc) const;
221
222 //! Calculate dpdV and dpdT at the current conditions
223 /*!
224 * These are stored internally.
225 */
226 void pressureDerivatives() const;
227
228 //! Update the a and b parameters
229 /*!
230 * The a and the b parameters depend on the mole fraction and the
231 * temperature. This function updates the internal numbers based on the
232 * state of the object.
233 */
234 virtual void updateMixingExpressions();
235
236 //! Calculate the a and the b parameters given the temperature
237 /*!
238 * This function doesn't change the internal state of the object, so it is a
239 * const function. It does use the stored mole fractions in the object.
240 *
241 * @param temp Temperature (TKelvin)
242 * @param aCalc (output) Returns the a value
243 * @param bCalc (output) Returns the b value.
244 */
245 void calculateAB(doublereal temp, doublereal& aCalc, doublereal& bCalc) const;
246
247 // Special functions not inherited from MixtureFugacityTP
248
249 doublereal da_dt() const;
250
251 void calcCriticalConditions(doublereal& pc, doublereal& tc, doublereal& vc) const;
252
253 //! Prepare variables and call the function to solve the cubic equation of state
254 int solveCubic(double T, double pres, double a, double b, double Vroot[3]) const;
255
256protected:
257 //! Form of the temperature parameterization
258 /*!
259 * - 0 = There is no temperature parameterization of a or b
260 * - 1 = The a_ij parameter is a linear function of the temperature
261 */
263
264 //! Value of b in the equation of state
265 /*!
266 * m_b is a function of the temperature and the mole fraction.
267 */
268 doublereal m_b_current;
269
270 //! Value of a in the equation of state
271 /*!
272 * a_b is a function of the temperature and the mole fraction.
273 */
274 doublereal m_a_current;
275
276 vector_fp a_vec_Curr_;
277 vector_fp b_vec_Curr_;
278
279 Array2D a_coeff_vec;
280
281 //! Explicitly-specified binary interaction parameters
282 std::map<std::string, std::map<std::string, std::pair<double, double>>> m_binaryParameters;
283
284 enum class CoeffSource { EoS, CritProps, Database };
285 //! For each species, specifies the source of the a and b coefficients
286 std::vector<CoeffSource> m_coeffSource;
287
288 int NSolns_;
289
290 doublereal Vroot_[3];
291
292 //! Temporary storage - length = m_kk.
294
295 // Partial molar volumes of the species
296 mutable vector_fp m_partialMolarVolumes;
297
298 //! The derivative of the pressure wrt the volume
299 /*!
300 * Calculated at the current conditions. temperature and mole number kept
301 * constant
302 */
303 mutable doublereal dpdV_;
304
305 //! The derivative of the pressure wrt the temperature
306 /*!
307 * Calculated at the current conditions. Total volume and mole number kept
308 * constant
309 */
310 mutable doublereal dpdT_;
311
312 //! Vector of derivatives of pressure wrt mole number
313 /*!
314 * Calculated at the current conditions. Total volume, temperature and
315 * other mole number kept constant
316 */
318
319private:
320 //! Omega constant for a -> value of a in terms of critical properties
321 /*!
322 * this was calculated from a small nonlinear solve
323 */
324 static const doublereal omega_a;
325
326 //! Omega constant for b
327 static const doublereal omega_b;
328
329 //! Omega constant for the critical molar volume
330 static const doublereal omega_vc;
331};
332}
333
334#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...
An error indicating that an unimplemented function has been called.
Definition: ctexceptions.h:187
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
Implementation of a multi-species Redlich-Kwong equation of state.
virtual bool addSpecies(shared_ptr< Species > spec)
virtual void getActivityCoefficients(doublereal *ac) const
Get the array of non-dimensional activity coefficients at the current solution temperature,...
static const doublereal omega_b
Omega constant for b.
int m_formTempParam
Form of the temperature parameterization.
virtual doublereal hresid() const
Calculate the deviation terms for the total enthalpy of the mixture from the ideal gas mixture.
doublereal m_b_current
Value of b in the equation of state.
doublereal dpdT_
The derivative of the pressure wrt the temperature.
virtual doublereal pressure() const
Return the thermodynamic pressure (Pa).
std::map< std::string, std::map< std::string, std::pair< double, double > > > m_binaryParameters
Explicitly-specified binary interaction parameters.
virtual void getPartialMolarIntEnergies(doublereal *ubar) const
Return an array of partial molar internal energies for the species in the mixture.
virtual doublereal cp_mole() const
Molar heat capacity at constant pressure. Units: J/kmol/K.
virtual std::vector< double > getCoeff(const std::string &iName)
Retrieve a and b coefficients by looking up tabulated critical parameters.
virtual void getPartialMolarEnthalpies(doublereal *hbar) const
Returns an array of partial molar enthalpies for the species in the mixture.
virtual void getPartialMolarEntropies(doublereal *sbar) const
Returns an array of partial molar entropies of the species in the solution.
virtual void getPartialMolarCp(double *cpbar) const
Return an array of partial molar heat capacities for the species in the mixture.
virtual void initThermoXML(XML_Node &phaseNode, const std::string &id)
Import and initialize a ThermoPhase object using an XML tree.
void readXMLCrossFluid(XML_Node &pureFluidParam)
Read the cross species RedlichKwong input parameters.
virtual void getPartialMolarVolumes(doublereal *vbar) const
Return an array of partial molar volumes for the species in the mixture.
vector_fp m_pp
Temporary storage - length = m_kk.
RedlichKwongMFTP(const std::string &infile="", const std::string &id="")
Construct a RedlichKwongMFTP object from an input file.
virtual doublereal cv_mole() const
Molar heat capacity at constant volume. Units: J/kmol/K.
void readXMLPureFluid(XML_Node &pureFluidParam)
Read the pure species RedlichKwong input parameters.
virtual doublereal dpdVCalc(doublereal TKelvin, doublereal molarVol, doublereal &presCalc) const
Calculate the pressure and the pressure derivative given the temperature and the molar volume.
std::vector< CoeffSource > m_coeffSource
For each species, specifies the source of the a and b coefficients.
virtual doublereal sresid() const
Calculate the deviation terms for the total entropy of the mixture from the ideal gas mixture.
virtual void updateMixingExpressions()
Update the a and b parameters.
void setBinaryCoeffs(const std::string &species_i, const std::string &species_j, double a0, double a1)
Set values for the interaction parameter between two species.
void pressureDerivatives() const
Calculate dpdV and dpdT at the current conditions.
static const doublereal omega_vc
Omega constant for the critical molar volume.
virtual doublereal liquidVolEst(doublereal TKelvin, doublereal &pres) const
Estimate for the molar volume of the liquid.
virtual void initThermo()
Initialize the ThermoPhase object after all species have been set up.
virtual doublereal densityCalc(doublereal T, doublereal pressure, int phase, doublereal rhoguess)
Calculates the density given the temperature and the pressure and a guess at the density.
doublereal m_a_current
Value of a in the equation of state.
virtual doublereal densSpinodalGas() const
Return the value of the density at the gas spinodal point (on the gas side) for the current temperatu...
virtual std::string type() const
String indicating the thermodynamic model implemented.
void setSpeciesCoeffs(const std::string &species, double a0, double a1, double b)
Set the pure fluid interaction parameters for a species.
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...
void calculateAB(doublereal temp, doublereal &aCalc, doublereal &bCalc) const
Calculate the a and the b parameters given the temperature.
virtual void getChemPotentials_RT(doublereal *mu) const
Get the array of non-dimensional species chemical potentials.
doublereal dpdV_
The derivative of the pressure wrt the volume.
virtual doublereal densSpinodalLiquid() const
Return the value of the density at the liquid spinodal point (on the liquid side) for the current tem...
virtual void getChemPotentials(doublereal *mu) const
Get the species chemical potentials. Units: J/kmol.
static const doublereal omega_a
Omega constant for a -> value of a in terms of critical properties.
vector_fp dpdni_
Vector of derivatives of pressure wrt mole number.
virtual void setParametersFromXML(const XML_Node &thermoNode)
Set equation of state parameter values from XML entries.
int solveCubic(double T, double pres, double a, double b, double Vroot[3]) const
Prepare variables and call the function to solve the cubic equation of state.
virtual doublereal standardConcentration(size_t k=0) const
Returns the standard concentration , which is used to normalize the generalized concentration.
Class XML_Node is a tree-based representation of the contents of an XML file.
Definition: xml.h:103
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