Cantera  2.4.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 http://www.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  * @attention This class currently does not have any test cases or examples. Its
18  * implementation may be incomplete, and future changes to Cantera may
19  * unexpectedly cause this class to stop working. If you use this class,
20  * please consider contributing examples or test cases. In the absence of
21  * new tests or examples, this class may be deprecated and removed in a
22  * future version of Cantera. See
23  * https://github.com/Cantera/cantera/issues/267 for additional information.
24  *
25  * @ingroup thermoprops
26  */
28 {
29 public:
30  //! @name Constructors and Duplicators
31  //! @{
32 
33  //! Base constructor.
35 
36  //! Construct and initialize a RedlichKwongMFTP object directly from an
37  //! ASCII input file
38  /*!
39  * @param infile Name of the input file containing the phase XML data
40  * to set up the object
41  * @param id ID of the phase in the input file. Defaults to the empty
42  * string.
43  */
44  RedlichKwongMFTP(const std::string& infile, const std::string& id="");
45 
46  //! Construct and initialize a RedlichKwongMFTP object directly from an
47  //! XML database
48  /*!
49  * @param phaseRef XML phase node containing the description of the phase
50  * @param id id attribute containing the name of the phase. (default
51  * is the empty string)
52  */
53  RedlichKwongMFTP(XML_Node& phaseRef, const std::string& id = "");
54 
55  virtual std::string type() const {
56  return "RedlichKwong";
57  }
58 
59  //! @name Molar Thermodynamic properties
60  //! @{
61 
62  virtual doublereal enthalpy_mole() const;
63  virtual doublereal entropy_mole() const;
64  virtual doublereal cp_mole() const;
65  virtual doublereal cv_mole() const;
66 
67  //! @}
68  //! @name Mechanical Properties
69  //! @{
70 
71  //! Return the thermodynamic pressure (Pa).
72  /*!
73  * Since the mass density, temperature, and mass fractions are stored,
74  * this method uses these values to implement the
75  * mechanical equation of state \f$ P(T, \rho, Y_1, \dots, Y_K) \f$.
76  *
77  * \f[
78  * P = \frac{RT}{v-b_{mix}} - \frac{a_{mix}}{T^{0.5} v \left( v + b_{mix} \right) }
79  * \f]
80  */
81  virtual doublereal pressure() const;
82 
83  // @}
84 
85 protected:
86  /**
87  * Calculate the density of the mixture using the partial molar volumes and
88  * mole fractions as input
89  *
90  * The formula for this is
91  *
92  * \f[
93  * \rho = \frac{\sum_k{X_k W_k}}{\sum_k{X_k V_k}}
94  * \f]
95  *
96  * where \f$X_k\f$ are the mole fractions, \f$W_k\f$ are the molecular
97  * weights, and \f$V_k\f$ are the pure species molar volumes.
98  *
99  * Note, the basis behind this formula is that in an ideal solution the
100  * partial molar volumes are equal to the species standard state molar
101  * volumes. The species molar volumes may be functions of temperature and
102  * pressure.
103  */
104  virtual void calcDensity();
105 
106  virtual void setTemperature(const doublereal temp);
107  virtual void compositionChanged();
108 
109 public:
110  virtual void getActivityConcentrations(doublereal* c) const;
111 
112  //! Returns the standard concentration \f$ C^0_k \f$, which is used to
113  //! normalize the generalized concentration.
114  /*!
115  * This is defined as the concentration by which the generalized
116  * concentration is normalized to produce the activity. In many cases, this
117  * quantity will be the same for all species in a phase. Since the activity
118  * for an ideal gas mixture is simply the mole fraction, for an ideal gas
119  * \f$ C^0_k = P/\hat R T \f$.
120  *
121  * @param k Optional parameter indicating the species. The default is to
122  * assume this refers to species 0.
123  * @return
124  * Returns the standard Concentration in units of m3 kmol-1.
125  */
126  virtual doublereal standardConcentration(size_t k=0) const;
127 
128  //! Get the array of non-dimensional activity coefficients at the current
129  //! solution temperature, pressure, and solution concentration.
130  /*!
131  * For all objects with the Mixture Fugacity approximation, we define the
132  * standard state as an ideal gas at the current temperature and pressure of
133  * the solution. The activities are based on this standard state.
134  *
135  * @param ac Output vector of activity coefficients. Length: m_kk.
136  */
137  virtual void getActivityCoefficients(doublereal* ac) const;
138 
139  /// @name Partial Molar Properties of the Solution
140  //@{
141 
142  //! Get the array of non-dimensional species chemical potentials.
143  //! These are partial molar Gibbs free energies.
144  /*!
145  * \f$ \mu_k / \hat R T \f$.
146  * Units: unitless
147  *
148  * We close the loop on this function, here, calling getChemPotentials() and
149  * then dividing by RT. No need for child classes to handle.
150  *
151  * @param mu Output vector of non-dimensional species chemical potentials
152  * Length: m_kk.
153  */
154  virtual void getChemPotentials_RT(doublereal* mu) const;
155 
156  virtual void getChemPotentials(doublereal* mu) const;
157  virtual void getPartialMolarEnthalpies(doublereal* hbar) const;
158  virtual void getPartialMolarEntropies(doublereal* sbar) const;
159  virtual void getPartialMolarIntEnergies(doublereal* ubar) const;
160  virtual void getPartialMolarCp(doublereal* cpbar) const;
161  virtual void getPartialMolarVolumes(doublereal* vbar) const;
162 
163  //@}
164  /// @name Critical State Properties.
165  //@{
166 
167  virtual doublereal critTemperature() const;
168  virtual doublereal critPressure() const;
169  virtual doublereal critVolume() const;
170  virtual doublereal critCompressibility() const;
171  virtual doublereal critDensity() const;
172 
173 public:
174  //@}
175  //! @name Initialization Methods - For Internal use
176  /*!
177  * The following methods are used in the process of constructing
178  * the phase and setting its parameters from a specification in an
179  * input file. They are not normally used in application programs.
180  * To see how they are used, see importPhase().
181  */
182  //@{
183 
184  virtual bool addSpecies(shared_ptr<Species> spec);
185  virtual void setParametersFromXML(const XML_Node& thermoNode);
186  virtual void setToEquilState(const doublereal* lambda_RT);
187  virtual void initThermoXML(XML_Node& phaseNode, const std::string& id);
188 
189  //! Set the pure fluid interaction parameters for a species
190  /*!
191  * The "a" parameter for species *i* in the Redlich-Kwong model is assumed
192  * to be a linear function of temperature:
193  * \f[ a = a_0 + a_1 T \f]
194  *
195  * @param species Name of the species
196  * @param a0 constant term in the expression for the "a" parameter
197  * of the specified species [Pa-m^6/kmol^2]
198  * @param a1 temperature-proportional term in the expression for the
199  * "a" parameter of the specified species [Pa-m^6/kmol^2/K]
200  * @param b "b" parameter in the Redlich-Kwong model [m^3/kmol]
201  */
202  void setSpeciesCoeffs(const std::string& species, double a0, double a1,
203  double b);
204 
205  //! Set values for the interaction parameter between two species
206  /*!
207  * The "a" parameter for interactions between species *i* and *j* is
208  * assumed by default to be computed as:
209  * \f[ a_{ij} = \sqrt(a_{i,0} a_{j,0}) + \sqrt(a_{i,1} a_{j,1}) T \f]
210  *
211  * This function overrides the defaults with the specified parameters:
212  * \f[ a_{ij} = a_{ij,0} + a_{ij,1} T \f]
213  *
214  * @param species_i Name of one species
215  * @param species_j Name of the other species
216  * @param a0 constant term in the "a" expression [Pa-m^6/kmol^2]
217  * @param a1 temperature-proportional term in the "a" expression
218  * [Pa-m^6/kmol^2/K]
219  */
220  void setBinaryCoeffs(const std::string& species_i,
221  const std::string& species_j, double a0, double a1);
222 
223 private:
224  //! Read the pure species RedlichKwong input parameters
225  /*!
226  * @param pureFluidParam XML_Node for the pure fluid parameters
227  */
228  void readXMLPureFluid(XML_Node& pureFluidParam);
229 
230  //! Read the cross species RedlichKwong input parameters
231  /*!
232  * @param pureFluidParam XML_Node for the cross fluid parameters
233  */
234  void readXMLCrossFluid(XML_Node& pureFluidParam);
235 
236  // @}
237 
238 protected:
239  // Special functions inherited from MixtureFugacityTP
240  virtual doublereal sresid() const;
241  virtual doublereal hresid() const;
242 
243 public:
244  virtual doublereal liquidVolEst(doublereal TKelvin, doublereal& pres) const;
245  virtual doublereal densityCalc(doublereal TKelvin, doublereal pressure, int phase, doublereal rhoguess);
246 
247  virtual doublereal densSpinodalLiquid() const;
248  virtual doublereal densSpinodalGas() const;
249  virtual doublereal pressureCalc(doublereal TKelvin, doublereal molarVol) const;
250  virtual doublereal dpdVCalc(doublereal TKelvin, doublereal molarVol, doublereal& presCalc) const;
251 
252  //! Calculate dpdV and dpdT at the current conditions
253  /*!
254  * These are stored internally.
255  */
256  void pressureDerivatives() const;
257 
258  virtual void updateMixingExpressions();
259 
260  //! Update the a and b parameters
261  /*!
262  * The a and the b parameters depend on the mole fraction and the
263  * temperature. This function updates the internal numbers based on the
264  * state of the object.
265  */
266  void updateAB();
267 
268  //! Calculate the a and the b parameters given the temperature
269  /*!
270  * This function doesn't change the internal state of the object, so it is a
271  * const function. It does use the stored mole fractions in the object.
272  *
273  * @param temp Temperature (TKelvin)
274  * @param aCalc (output) Returns the a value
275  * @param bCalc (output) Returns the b value.
276  */
277  void calculateAB(doublereal temp, doublereal& aCalc, doublereal& bCalc) const;
278 
279  // Special functions not inherited from MixtureFugacityTP
280 
281  doublereal da_dt() const;
282 
283  void calcCriticalConditions(doublereal a, doublereal b, doublereal a0_coeff, doublereal aT_coeff,
284  doublereal& pc, doublereal& tc, doublereal& vc) const;
285 
286  //! Solve the cubic equation of state
287  /*!
288  * The R-K equation of state may be solved via the following formula:
289  *
290  * V**3 - V**2(RT/P) - V(RTb/P - a/(P T**.5) + b*b) - (a b / (P T**.5)) = 0
291  *
292  * Returns the number of solutions found. If it only finds the liquid
293  * branch solution, it will return a -1 or a -2 instead of 1 or 2. If it
294  * returns 0, then there is an error.
295  */
296  int NicholsSolve(double TKelvin, double pres, doublereal a, doublereal b,
297  doublereal Vroot[3]) const;
298 
299 protected:
300  //! Form of the temperature parameterization
301  /*!
302  * - 0 = There is no temperature parameterization of a or b
303  * - 1 = The a_ij parameter is a linear function of the temperature
304  */
306 
307  //! Value of b in the equation of state
308  /*!
309  * m_b is a function of the temperature and the mole fraction.
310  */
311  doublereal m_b_current;
312 
313  //! Value of a in the equation of state
314  /*!
315  * a_b is a function of the temperature and the mole fraction.
316  */
317  doublereal m_a_current;
318 
319  vector_fp a_vec_Curr_;
320  vector_fp b_vec_Curr_;
321 
322  Array2D a_coeff_vec;
323 
324  int NSolns_;
325 
326  doublereal Vroot_[3];
327 
328  //! Temporary storage - length = m_kk.
329  mutable vector_fp m_pp;
330 
331  //! Temporary storage - length = m_kk.
332  mutable vector_fp m_tmpV;
333 
334  // Partial molar volumes of the species
335  mutable vector_fp m_partialMolarVolumes;
336 
337  //! The derivative of the pressure wrt the volume
338  /*!
339  * Calculated at the current conditions. temperature and mole number kept
340  * constant
341  */
342  mutable doublereal dpdV_;
343 
344  //! The derivative of the pressure wrt the temperature
345  /*!
346  * Calculated at the current conditions. Total volume and mole number kept
347  * constant
348  */
349  mutable doublereal dpdT_;
350 
351  //! Vector of derivatives of pressure wrt mole number
352  /*!
353  * Calculated at the current conditions. Total volume, temperature and
354  * other mole number kept constant
355  */
356  mutable vector_fp dpdni_;
357 
358 public:
359  //! Omega constant for a -> value of a in terms of critical properties
360  /*!
361  * this was calculated from a small nonlinear solve
362  */
363  static const doublereal omega_a;
364 
365  //! Omega constant for b
366  static const doublereal omega_b;
367 
368  //! Omega constant for the critical molar volume
369  static const doublereal omega_vc;
370 };
371 }
372 
373 #endif
void setSpeciesCoeffs(const std::string &species, double a0, double a1, double b)
Set the pure fluid interaction parameters for a species.
virtual doublereal dpdVCalc(doublereal TKelvin, doublereal molarVol, doublereal &presCalc) const
Calculate the pressure and the pressure derivative given the temperature and the molar volume...
Implementation of a multi-species Redlich-Kwong equation of state.
doublereal m_b_current
Value of b in the equation of state.
doublereal dpdV_
The derivative of the pressure wrt the volume.
virtual void getPartialMolarIntEnergies(doublereal *ubar) const
Return an array of partial molar internal energies for the species in the mixture.
vector_fp m_tmpV
Temporary storage - length = m_kk.
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 compositionChanged()
Apply changes to the state which are needed after the composition changes.
void pressureDerivatives() const
Calculate dpdV and dpdT at the current conditions.
virtual doublereal hresid() const
Calculate the deviation terms for the total enthalpy of the mixture from the ideal gas mixture...
RedlichKwongMFTP()
Base constructor.
virtual doublereal critVolume() const
Critical volume (m3/kmol).
virtual doublereal densityCalc(doublereal TKelvin, doublereal pressure, int phase, doublereal rhoguess)
Calculates the density given the temperature and the pressure and a guess at the density.
Class XML_Node is a tree-based representation of the contents of an XML file.
Definition: xml.h:97
This is a filter class for ThermoPhase that implements some preparatory steps for efficiently handlin...
virtual void getActivityCoefficients(doublereal *ac) const
Get the array of non-dimensional activity coefficients at the current solution temperature, pressure, and solution concentration.
void readXMLPureFluid(XML_Node &pureFluidParam)
Read the pure species RedlichKwong input parameters.
virtual doublereal cp_mole() const
Molar heat capacity at constant pressure. Units: J/kmol/K.
virtual void getPartialMolarVolumes(doublereal *vbar) const
Return an array of partial molar volumes for the species in the mixture.
int NicholsSolve(double TKelvin, double pres, doublereal a, doublereal b, doublereal Vroot[3]) const
Solve the cubic equation of state.
virtual doublereal sresid() const
Calculate the deviation terms for the total entropy of the mixture from the ideal gas mixture...
virtual doublereal critTemperature() const
Critical temperature (K).
virtual void initThermoXML(XML_Node &phaseNode, const std::string &id)
Import and initialize a ThermoPhase object using an XML tree.
A class for 2D arrays stored in column-major (Fortran-compatible) form.
Definition: Array.h:31
virtual void setToEquilState(const doublereal *lambda_RT)
This method is used by the ChemEquil equilibrium solver.
Header file for class Cantera::Array2D.
virtual doublereal critDensity() const
Critical density (kg/m3).
virtual doublereal cv_mole() const
Molar heat capacity at constant volume. Units: J/kmol/K.
static const doublereal omega_b
Omega constant for b.
int m_formTempParam
Form of the temperature parameterization.
void calculateAB(doublereal temp, doublereal &aCalc, doublereal &bCalc) const
Calculate the a and the b parameters given the temperature.
virtual std::string type() const
String indicating the thermodynamic model implemented.
Header file for a derived class of ThermoPhase that handles non-ideal mixtures based on the fugacity ...
doublereal dpdT_
The derivative of the pressure wrt the temperature.
doublereal m_a_current
Value of a in the equation of state.
shared_ptr< Species > species(const std::string &name) const
Return the Species object for the named species.
Definition: Phase.cpp:803
vector_fp m_pp
Temporary storage - length = m_kk.
virtual void setParametersFromXML(const XML_Node &thermoNode)
Set equation of state parameter values from XML entries.
virtual doublereal critPressure() const
Critical pressure (Pa).
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.
virtual doublereal liquidVolEst(doublereal TKelvin, doublereal &pres) const
Estimate for the molar volume of the liquid.
virtual void getChemPotentials_RT(doublereal *mu) const
Get the array of non-dimensional species chemical potentials.
virtual void setTemperature(const doublereal temp)
Set the temperature of the phase.
void readXMLCrossFluid(XML_Node &pureFluidParam)
Read the cross species RedlichKwong input parameters.
virtual void calcDensity()
Calculate the density of the mixture using the partial molar volumes and mole fractions as input...
virtual doublereal enthalpy_mole() const
Molar enthalpy. Units: J/kmol.
virtual doublereal critCompressibility() const
Critical compressibility (unitless).
static const doublereal omega_a
Omega constant for a -> value of a in terms of critical properties.
virtual doublereal standardConcentration(size_t k=0) const
Returns the standard concentration , which is used to normalize the generalized concentration.
virtual void getPartialMolarEntropies(doublereal *sbar) const
Returns an array of partial molar entropies of the species in the solution.
virtual doublereal pressureCalc(doublereal TKelvin, doublereal molarVol) const
Calculate the pressure given the temperature and the molar volume.
virtual doublereal pressure() const
Return the thermodynamic pressure (Pa).
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:157
virtual bool addSpecies(shared_ptr< Species > spec)
virtual doublereal densSpinodalGas() const
Return the value of the density at the gas spinodal point (on the gas side) for the current temperatu...
virtual void getChemPotentials(doublereal *mu) const
Get the species chemical potentials. Units: J/kmol.
static const doublereal omega_vc
Omega constant for the critical molar volume.
virtual void getPartialMolarEnthalpies(doublereal *hbar) const
Returns an array of partial molar enthalpies for the species in the mixture.
virtual doublereal entropy_mole() const
Molar entropy. Units: J/kmol/K.
Namespace for the Cantera kernel.
Definition: AnyMap.cpp:8
virtual void getPartialMolarCp(doublereal *cpbar) const
Return an array of partial molar heat capacities for the species in the mixture.
vector_fp dpdni_
Vector of derivatives of pressure wrt mole number.
void updateAB()
Update the a and b parameters.
virtual void getActivityConcentrations(doublereal *c) const
This method returns an array of generalized concentrations.