Cantera  2.3.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  RedlichKwongMFTP(const RedlichKwongMFTP& right);
56  RedlichKwongMFTP& operator=(const RedlichKwongMFTP& right);
57  virtual ThermoPhase* duplMyselfAsThermoPhase() const;
58 
59  virtual int eosType() const;
60  virtual std::string type() const {
61  return "RedlichKwong";
62  }
63 
64  //! @name Molar Thermodynamic properties
65  //! @{
66 
67  virtual doublereal enthalpy_mole() const;
68  virtual doublereal entropy_mole() const;
69  virtual doublereal cp_mole() const;
70  virtual doublereal cv_mole() const;
71 
72  //! @}
73  //! @name Mechanical Properties
74  //! @{
75 
76  //! Return the thermodynamic pressure (Pa).
77  /*!
78  * Since the mass density, temperature, and mass fractions are stored,
79  * this method uses these values to implement the
80  * mechanical equation of state \f$ P(T, \rho, Y_1, \dots, Y_K) \f$.
81  *
82  * \f[
83  * P = \frac{RT}{v-b_{mix}} - \frac{a_{mix}}{T^{0.5} v \left( v + b_{mix} \right) }
84  * \f]
85  */
86  virtual doublereal pressure() const;
87 
88  // @}
89 
90 protected:
91  /**
92  * Calculate the density of the mixture using the partial molar volumes and
93  * mole fractions as input
94  *
95  * The formula for this is
96  *
97  * \f[
98  * \rho = \frac{\sum_k{X_k W_k}}{\sum_k{X_k V_k}}
99  * \f]
100  *
101  * where \f$X_k\f$ are the mole fractions, \f$W_k\f$ are the molecular
102  * weights, and \f$V_k\f$ are the pure species molar volumes.
103  *
104  * Note, the basis behind this formula is that in an ideal solution the
105  * partial molar volumes are equal to the species standard state molar
106  * volumes. The species molar volumes may be functions of temperature and
107  * pressure.
108  */
109  virtual void calcDensity();
110 
111  virtual void setTemperature(const doublereal temp);
112  virtual void compositionChanged();
113 
114 public:
115  virtual void getActivityConcentrations(doublereal* c) const;
116 
117  //! Returns the standard concentration \f$ C^0_k \f$, which is used to
118  //! normalize the generalized concentration.
119  /*!
120  * This is defined as the concentration by which the generalized
121  * concentration is normalized to produce the activity. In many cases, this
122  * quantity will be the same for all species in a phase. Since the activity
123  * for an ideal gas mixture is simply the mole fraction, for an ideal gas
124  * \f$ C^0_k = P/\hat R T \f$.
125  *
126  * @param k Optional parameter indicating the species. The default is to
127  * assume this refers to species 0.
128  * @return
129  * Returns the standard Concentration in units of m3 kmol-1.
130  */
131  virtual doublereal standardConcentration(size_t k=0) const;
132 
133  //! Get the array of non-dimensional activity coefficients at the current
134  //! solution temperature, pressure, and solution concentration.
135  /*!
136  * For all objects with the Mixture Fugacity approximation, we define the
137  * standard state as an ideal gas at the current temperature and pressure of
138  * the solution. The activities are based on this standard state.
139  *
140  * @param ac Output vector of activity coefficients. Length: m_kk.
141  */
142  virtual void getActivityCoefficients(doublereal* ac) const;
143 
144  /// @name Partial Molar Properties of the Solution
145  //@{
146 
147  //! Get the array of non-dimensional species chemical potentials.
148  //! These are partial molar Gibbs free energies.
149  /*!
150  * \f$ \mu_k / \hat R T \f$.
151  * Units: unitless
152  *
153  * We close the loop on this function, here, calling getChemPotentials() and
154  * then dividing by RT. No need for child classes to handle.
155  *
156  * @param mu Output vector of non-dimensional species chemical potentials
157  * Length: m_kk.
158  */
159  virtual void getChemPotentials_RT(doublereal* mu) const;
160 
161  virtual void getChemPotentials(doublereal* mu) const;
162  virtual void getPartialMolarEnthalpies(doublereal* hbar) const;
163  virtual void getPartialMolarEntropies(doublereal* sbar) const;
164  virtual void getPartialMolarIntEnergies(doublereal* ubar) const;
165  virtual void getPartialMolarCp(doublereal* cpbar) const;
166  virtual void getPartialMolarVolumes(doublereal* vbar) const;
167 
168  //@}
169  /// @name Critical State Properties.
170  //@{
171 
172  virtual doublereal critTemperature() const;
173  virtual doublereal critPressure() const;
174  virtual doublereal critVolume() const;
175  virtual doublereal critCompressibility() const;
176  virtual doublereal critDensity() const;
177 
178 public:
179  //@}
180  //! @name Initialization Methods - For Internal use
181  /*!
182  * The following methods are used in the process of constructing
183  * the phase and setting its parameters from a specification in an
184  * input file. They are not normally used in application programs.
185  * To see how they are used, see importPhase().
186  */
187  //@{
188 
189  virtual bool addSpecies(shared_ptr<Species> spec);
190  virtual void setParametersFromXML(const XML_Node& thermoNode);
191  virtual void setToEquilState(const doublereal* lambda_RT);
192  virtual void initThermoXML(XML_Node& phaseNode, const std::string& id);
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  //! Apply mixing rules for a coefficients
203 
204  //! Read the cross species RedlichKwong input parameters
205  /*!
206  * @param pureFluidParam XML_Node for the cross fluid parameters
207  */
208  void readXMLCrossFluid(XML_Node& pureFluidParam);
209 
210  // @}
211 
212 protected:
213  // Special functions inherited from MixtureFugacityTP
214  virtual doublereal sresid() const;
215  virtual doublereal hresid() const;
216 
217 public:
218  virtual doublereal liquidVolEst(doublereal TKelvin, doublereal& pres) const;
219  virtual doublereal densityCalc(doublereal TKelvin, doublereal pressure, int phase, doublereal rhoguess);
220 
221  virtual doublereal densSpinodalLiquid() const;
222  virtual doublereal densSpinodalGas() const;
223  virtual doublereal pressureCalc(doublereal TKelvin, doublereal molarVol) const;
224  virtual doublereal dpdVCalc(doublereal TKelvin, doublereal molarVol, doublereal& presCalc) const;
225 
226  //! Calculate dpdV and dpdT at the current conditions
227  /*!
228  * These are stored internally.
229  */
230  void pressureDerivatives() const;
231 
232  virtual void updateMixingExpressions();
233 
234  //! Update the a and b parameters
235  /*!
236  * The a and the b parameters depend on the mole fraction and the
237  * temperature. This function updates the internal numbers based on the
238  * state of the object.
239  */
240  void updateAB();
241 
242  //! Calculate the a and the b parameters given the temperature
243  /*!
244  * This function doesn't change the internal state of the object, so it is a
245  * const function. It does use the stored mole fractions in the object.
246  *
247  * @param temp Temperature (TKelvin)
248  * @param aCalc (output) Returns the a value
249  * @param bCalc (output) Returns the b value.
250  */
251  void calculateAB(doublereal temp, doublereal& aCalc, doublereal& bCalc) const;
252 
253  // Special functions not inherited from MixtureFugacityTP
254 
255  doublereal da_dt() const;
256 
257  void calcCriticalConditions(doublereal a, doublereal b, doublereal a0_coeff, doublereal aT_coeff,
258  doublereal& pc, doublereal& tc, doublereal& vc) const;
259 
260  //! Solve the cubic equation of state
261  /*!
262  * The R-K equation of state may be solved via the following formula:
263  *
264  * V**3 - V**2(RT/P) - V(RTb/P - a/(P T**.5) + b*b) - (a b / (P T**.5)) = 0
265  *
266  * Returns the number of solutions found. If it only finds the liquid
267  * branch solution, it will return a -1 or a -2 instead of 1 or 2. If it
268  * returns 0, then there is an error.
269  */
270  int NicholsSolve(double TKelvin, double pres, doublereal a, doublereal b,
271  doublereal Vroot[3]) const;
272 
273 protected:
274  //! boolean indicating whether standard mixing rules are applied
275  /*!
276  * - 1 = Yes, there are standard cross terms in the a coefficient matrices.
277  * - 0 = No, there are nonstandard cross terms in the a coefficient matrices.
278  */
280 
281  //! Form of the temperature parameterization
282  /*!
283  * - 0 = There is no temperature parameterization of a or b
284  * - 1 = The a_ij parameter is a linear function of the temperature
285  */
287 
288  //! Value of b in the equation of state
289  /*!
290  * m_b is a function of the temperature and the mole fraction.
291  */
292  doublereal m_b_current;
293 
294  //! Value of a in the equation of state
295  /*!
296  * a_b is a function of the temperature and the mole fraction.
297  */
298  doublereal m_a_current;
299 
300  vector_fp a_vec_Curr_;
301  vector_fp b_vec_Curr_;
302 
303  Array2D a_coeff_vec;
304 
305  vector_fp m_pc_Species;
306  vector_fp m_tc_Species;
307  vector_fp m_vc_Species;
308 
309  int NSolns_;
310 
311  doublereal Vroot_[3];
312 
313  //! Temporary storage - length = m_kk.
314  mutable vector_fp m_pp;
315 
316  //! Temporary storage - length = m_kk.
317  mutable vector_fp m_tmpV;
318 
319  // Partial molar volumes of the species
320  mutable vector_fp m_partialMolarVolumes;
321 
322  //! The derivative of the pressure wrt the volume
323  /*!
324  * Calculated at the current conditions. temperature and mole number kept
325  * constant
326  */
327  mutable doublereal dpdV_;
328 
329  //! The derivative of the pressure wrt the temperature
330  /*!
331  * Calculated at the current conditions. Total volume and mole number kept
332  * constant
333  */
334  mutable doublereal dpdT_;
335 
336  //! Vector of derivatives of pressure wrt mole number
337  /*!
338  * Calculated at the current conditions. Total volume, temperature and
339  * other mole number kept constant
340  */
341  mutable vector_fp dpdni_;
342 
343 public:
344  //! Omega constant for a -> value of a in terms of critical properties
345  /*!
346  * this was calculated from a small nonlinear solve
347  */
348  static const doublereal omega_a;
349 
350  //! Omega constant for b
351  static const doublereal omega_b;
352 
353  //! Omega constant for the critical molar volume
354  static const doublereal omega_vc;
355 };
356 }
357 
358 #endif
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 ThermoPhase * duplMyselfAsThermoPhase() const
Duplication routine for objects which inherit from ThermoPhase.
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
Base class for a phase with thermodynamic properties.
Definition: ThermoPhase.h:93
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.
int m_standardMixingRules
boolean indicating whether standard mixing rules are applied
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.
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).
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.
void applyStandardMixingRules()
Apply mixing rules for a coefficients.
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: application.cpp:29
virtual void getPartialMolarCp(doublereal *cpbar) const
Return an array of partial molar heat capacities for the species in the mixture.
virtual int eosType() const
Equation of state type flag.
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.