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
12 namespace Cantera
13{
14/**
15 * Implementation of a multi-species Redlich-Kwong equation of state
16 *
17 * @ingroup thermoprops
18 */
19 class RedlichKwongMFTP : public MixtureFugacityTP
20{
21 public:
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
70 public:
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
126 public:
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
194 private:
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
209 protected:
210 // Special functions inherited from MixtureFugacityTP
211 virtual doublereal sresid() const;
212 virtual doublereal hresid() const;
213
214 public:
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
256 protected:
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 */
262 int m_formTempParam;
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.
293 mutable vector_fp m_pp;
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 */
317 mutable vector_fp dpdni_;
318
319 private:
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
Array.h
Header file for class Cantera::Array2D.
MixtureFugacityTP.h
Header file for a derived class of ThermoPhase that handles non-ideal mixtures based on the fugacity ...
Cantera::AnyMap
A map of string keys to values whose type can vary at runtime.
Definition: AnyMap.h:399
Cantera::Array2D
A class for 2D arrays stored in column-major (Fortran-compatible) form.
Definition: Array.h:30
Cantera::MixtureFugacityTP
This is a filter class for ThermoPhase that implements some preparatory steps for efficiently handlin...
Definition: MixtureFugacityTP.h:75
Cantera::NotImplementedError
An error indicating that an unimplemented function has been called.
Definition: ctexceptions.h:187
Cantera::Phase::name
std::string name() const
Return the name of the phase.
Definition: Phase.cpp:70
Cantera::Phase::species
shared_ptr< Species > species(const std::string &name) const
Return the Species object for the named species.
Definition: Phase.cpp:950
Cantera::RedlichKwongMFTP
Implementation of a multi-species Redlich-Kwong equation of state.
Definition: RedlichKwongMFTP.h:20
Cantera::RedlichKwongMFTP::addSpecies
virtual bool addSpecies(shared_ptr< Species > spec)
Definition: RedlichKwongMFTP.cpp:382
Cantera::RedlichKwongMFTP::getActivityCoefficients
virtual void getActivityCoefficients(doublereal *ac) const
Get the array of non-dimensional activity coefficients at the current solution temperature,...
Definition: RedlichKwongMFTP.cpp:168
Cantera::RedlichKwongMFTP::omega_b
static const doublereal omega_b
Omega constant for b.
Definition: RedlichKwongMFTP.h:327
Cantera::RedlichKwongMFTP::m_formTempParam
int m_formTempParam
Form of the temperature parameterization.
Definition: RedlichKwongMFTP.h:262
Cantera::RedlichKwongMFTP::hresid
virtual doublereal hresid() const
Calculate the deviation terms for the total enthalpy of the mixture from the ideal gas mixture.
Definition: RedlichKwongMFTP.cpp:738
Cantera::RedlichKwongMFTP::m_b_current
doublereal m_b_current
Value of b in the equation of state.
Definition: RedlichKwongMFTP.h:268
Cantera::RedlichKwongMFTP::dpdT_
doublereal dpdT_
The derivative of the pressure wrt the temperature.
Definition: RedlichKwongMFTP.h:310
Cantera::RedlichKwongMFTP::pressure
virtual doublereal pressure() const
Return the thermodynamic pressure (Pa).
Definition: RedlichKwongMFTP.cpp:151
Cantera::RedlichKwongMFTP::m_binaryParameters
std::map< std::string, std::map< std::string, std::pair< double, double > > > m_binaryParameters
Explicitly-specified binary interaction parameters.
Definition: RedlichKwongMFTP.h:282
Cantera::RedlichKwongMFTP::getPartialMolarIntEnergies
virtual void getPartialMolarIntEnergies(doublereal *ubar) const
Return an array of partial molar internal energies for the species in the mixture.
Definition: RedlichKwongMFTP.cpp:338
Cantera::RedlichKwongMFTP::cp_mole
virtual doublereal cp_mole() const
Molar heat capacity at constant pressure. Units: J/kmol/K.
Definition: RedlichKwongMFTP.cpp:121
Cantera::RedlichKwongMFTP::getCoeff
virtual std::vector< double > getCoeff(const std::string &iName)
Retrieve a and b coefficients by looking up tabulated critical parameters.
Definition: RedlichKwongMFTP.cpp:620
Cantera::RedlichKwongMFTP::getPartialMolarEnthalpies
virtual void getPartialMolarEnthalpies(doublereal *hbar) const
Returns an array of partial molar enthalpies for the species in the mixture.
Definition: RedlichKwongMFTP.cpp:242
Cantera::RedlichKwongMFTP::getPartialMolarEntropies
virtual void getPartialMolarEntropies(doublereal *sbar) const
Returns an array of partial molar entropies of the species in the solution.
Definition: RedlichKwongMFTP.cpp:287
Cantera::RedlichKwongMFTP::getPartialMolarCp
virtual void getPartialMolarCp(double *cpbar) const
Return an array of partial molar heat capacities for the species in the mixture.
Definition: RedlichKwongMFTP.h:120
Cantera::RedlichKwongMFTP::initThermoXML
virtual void initThermoXML(XML_Node &phaseNode, const std::string &id)
Import and initialize a ThermoPhase object using an XML tree.
Definition: RedlichKwongMFTP.cpp:401
Cantera::RedlichKwongMFTP::readXMLCrossFluid
void readXMLCrossFluid(XML_Node &pureFluidParam)
Read the cross species RedlichKwong input parameters.
Definition: RedlichKwongMFTP.cpp:683
Cantera::RedlichKwongMFTP::getPartialMolarVolumes
virtual void getPartialMolarVolumes(doublereal *vbar) const
Return an array of partial molar volumes for the species in the mixture.
Definition: RedlichKwongMFTP.cpp:349
Cantera::RedlichKwongMFTP::m_pp
vector_fp m_pp
Temporary storage - length = m_kk.
Definition: RedlichKwongMFTP.h:293
Cantera::RedlichKwongMFTP::RedlichKwongMFTP
RedlichKwongMFTP(const std::string &infile="", const std::string &id="")
Construct a RedlichKwongMFTP object from an input file.
Definition: RedlichKwongMFTP.cpp:26
Cantera::RedlichKwongMFTP::cv_mole
virtual doublereal cv_mole() const
Molar heat capacity at constant volume. Units: J/kmol/K.
Definition: RedlichKwongMFTP.cpp:137
Cantera::RedlichKwongMFTP::readXMLPureFluid
void readXMLPureFluid(XML_Node &pureFluidParam)
Read the pure species RedlichKwong input parameters.
Definition: RedlichKwongMFTP.cpp:644
Cantera::RedlichKwongMFTP::dpdVCalc
virtual doublereal dpdVCalc(doublereal TKelvin, doublereal molarVol, doublereal &presCalc) const
Calculate the pressure and the pressure derivative given the temperature and the molar volume.
Definition: RedlichKwongMFTP.cpp:883
Cantera::RedlichKwongMFTP::m_coeffSource
std::vector< CoeffSource > m_coeffSource
For each species, specifies the source of the a and b coefficients.
Definition: RedlichKwongMFTP.h:286
Cantera::RedlichKwongMFTP::sresid
virtual doublereal sresid() const
Calculate the deviation terms for the total entropy of the mixture from the ideal gas mixture.
Definition: RedlichKwongMFTP.cpp:722
Cantera::RedlichKwongMFTP::updateMixingExpressions
virtual void updateMixingExpressions()
Update the a and b parameters.
Definition: RedlichKwongMFTP.cpp:911
Cantera::RedlichKwongMFTP::setBinaryCoeffs
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.
Definition: RedlichKwongMFTP.cpp:92
Cantera::RedlichKwongMFTP::pressureDerivatives
void pressureDerivatives() const
Calculate dpdV and dpdT at the current conditions.
Definition: RedlichKwongMFTP.cpp:896
Cantera::RedlichKwongMFTP::omega_vc
static const doublereal omega_vc
Omega constant for the critical molar volume.
Definition: RedlichKwongMFTP.h:330
Cantera::RedlichKwongMFTP::liquidVolEst
virtual doublereal liquidVolEst(doublereal TKelvin, doublereal &pres) const
Estimate for the molar volume of the liquid.
Definition: RedlichKwongMFTP.cpp:753
Cantera::RedlichKwongMFTP::initThermo
virtual void initThermo()
Initialize the ThermoPhase object after all species have been set up.
Definition: RedlichKwongMFTP.cpp:474
Cantera::RedlichKwongMFTP::densityCalc
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.
Definition: RedlichKwongMFTP.cpp:785
Cantera::RedlichKwongMFTP::m_a_current
doublereal m_a_current
Value of a in the equation of state.
Definition: RedlichKwongMFTP.h:274
Cantera::RedlichKwongMFTP::densSpinodalGas
virtual doublereal densSpinodalGas() const
Return the value of the density at the gas spinodal point (on the gas side) for the current temperatu...
Definition: RedlichKwongMFTP.cpp:861
Cantera::RedlichKwongMFTP::type
virtual std::string type() const
String indicating the thermodynamic model implemented.
Definition: RedlichKwongMFTP.h:44
Cantera::RedlichKwongMFTP::setSpeciesCoeffs
void setSpeciesCoeffs(const std::string &species, double a0, double a1, double b)
Set the pure fluid interaction parameters for a species.
Definition: RedlichKwongMFTP.cpp:50
Cantera::RedlichKwongMFTP::getSpeciesParameters
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...
Definition: RedlichKwongMFTP.cpp:571
Cantera::RedlichKwongMFTP::calculateAB
void calculateAB(doublereal temp, doublereal &aCalc, doublereal &bCalc) const
Calculate the a and the b parameters given the temperature.
Definition: RedlichKwongMFTP.cpp:948
Cantera::RedlichKwongMFTP::getChemPotentials_RT
virtual void getChemPotentials_RT(doublereal *mu) const
Get the array of non-dimensional species chemical potentials.
Definition: RedlichKwongMFTP.cpp:200
Cantera::RedlichKwongMFTP::dpdV_
doublereal dpdV_
The derivative of the pressure wrt the volume.
Definition: RedlichKwongMFTP.h:303
Cantera::RedlichKwongMFTP::densSpinodalLiquid
virtual doublereal densSpinodalLiquid() const
Return the value of the density at the liquid spinodal point (on the liquid side) for the current tem...
Definition: RedlichKwongMFTP.cpp:839
Cantera::RedlichKwongMFTP::getChemPotentials
virtual void getChemPotentials(doublereal *mu) const
Get the species chemical potentials. Units: J/kmol.
Definition: RedlichKwongMFTP.cpp:208
Cantera::RedlichKwongMFTP::omega_a
static const doublereal omega_a
Omega constant for a -> value of a in terms of critical properties.
Definition: RedlichKwongMFTP.h:324
Cantera::RedlichKwongMFTP::dpdni_
vector_fp dpdni_
Vector of derivatives of pressure wrt mole number.
Definition: RedlichKwongMFTP.h:317
Cantera::RedlichKwongMFTP::setParametersFromXML
virtual void setParametersFromXML(const XML_Node &thermoNode)
Set equation of state parameter values from XML entries.
Definition: RedlichKwongMFTP.cpp:716
Cantera::RedlichKwongMFTP::solveCubic
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.
Definition: RedlichKwongMFTP.cpp:1040
Cantera::RedlichKwongMFTP::standardConcentration
virtual doublereal standardConcentration(size_t k=0) const
Returns the standard concentration , which is used to normalize the generalized concentration.
Definition: RedlichKwongMFTP.cpp:162
Cantera::XML_Node
Class XML_Node is a tree-based representation of the contents of an XML file.
Definition: xml.h:103
Cantera
Namespace for the Cantera kernel.
Definition: AnyMap.cpp:557
Cantera::vector_fp
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