Cantera  2.0
ConstDensityThermo.h
Go to the documentation of this file.
1 /**
2  * @file ConstDensityThermo.h
3  * Header for a Thermo manager for incompressible ThermoPhases
4  * (see \ref thermoprops and \link Cantera::ConstDensityThermo ConstDensityThermo\endlink).
5  */
6 /*
7  * Copyright 2002 California Institute of Technology
8  */
9 
10 #ifndef CT_CONSTRHOTHERMO_H
11 #define CT_CONSTRHOTHERMO_H
12 
13 #include "cantera/base/ct_defs.h"
14 #include "mix_defs.h"
15 #include "ThermoPhase.h"
16 #include "SpeciesThermo.h"
17 #include "cantera/base/utilities.h"
18 
19 namespace Cantera
20 {
21 
22 //! Overloads the virtual methods of class ThermoPhase to implement the
23 //! incompressible equation of state.
24 /**
25  *
26  *
27  * <b> Specification of Species Standard State Properties </b>
28  *
29  *
30  * <b> Specification of Solution Thermodynamic Properties </b>
31  *
32  * The density is assumed to be constant, no matter what the concentration of the solution.
33  *
34  *
35  * <b> Application within %Kinetics Managers </b>
36  *
37  *
38  * <b> XML Example </b>
39  *
40  * An example of an XML Element named phase setting up a SurfPhase object named diamond_100
41  * is given below.
42  *
43  * @ingroup thermoprops
44  */
46 {
47 
48 public:
49 
50  //! Constructor.
51  /*!
52  *
53  */
55 
56  //! Destructor
57  virtual ~ConstDensityThermo() {}
58 
59  //! Copy Constructor
60  /*!
61  * @param right Object to be copied
62  */
64 
65  //! Assignment Operator
66  /*!
67  * @param right Object to be copied
68  */
70 
71 
72  //! Duplication routine for objects which inherit from
73  //! %SpeciesThermo
74  /*!
75  * This virtual routine can be used to duplicate %SpeciesThermo objects
76  * inherited from %SpeciesThermo even if the application only has
77  * a pointer to %SpeciesThermo to work with.
78  * ->commented out because we first need to add copy constructors
79  * and assignment operators to all of the derived classes.
80  */
82 
83  //! overloaded methods of class ThermoPhase
84  virtual int eosType() const;
85 
86  //! Return the Molar Enthalpy. Units: J/kmol.
87  /*!
88  *
89  */
90 
91  /// Molar enthalpy. Units: J/kmol.
92  virtual doublereal enthalpy_mole() const;
93 
94  /// Molar internal energy. Units: J/kmol.
95  virtual doublereal intEnergy_mole() const;
96 
97 
98  /// Molar entropy. Units: J/kmol/K.
99  virtual doublereal entropy_mole() const;
100 
101  /// Molar Gibbs function. Units: J/kmol.
102  virtual doublereal gibbs_mole() const;
103 
104  /// Molar heat capacity at constant pressure. Units: J/kmol/K.
105  virtual doublereal cp_mole() const;
106 
107  /// Molar heat capacity at constant volume. Units: J/kmol/K.
108  virtual doublereal cv_mole() const;
109 
110  //! Return the thermodynamic pressure (Pa).
111  /*!
112  * This method must be overloaded in derived classes. Since the
113  * mass density, temperature, and mass fractions are stored,
114  * this method should use these values to implement the
115  * mechanical equation of state \f$ P(T, \rho, Y_1, \dots,
116  * Y_K) \f$.
117  */
118  virtual doublereal pressure() const;
119 
120  //! Set the internally stored pressure (Pa) at constant
121  //! temperature and composition
122  /*!
123  * This method must be reimplemented in derived classes, where it
124  * may involve the solution of a nonlinear equation. Within %Cantera,
125  * the independent variable is the density. Therefore, this function
126  * solves for the density that will yield the desired input pressure.
127  * The temperature and composition iare held constant during this process.
128  *
129  * This base class function will print an error, if not overwritten.
130  *
131  * @param p input Pressure (Pa)
132  */
133  virtual void setPressure(doublereal p);
134 
135  //! This method returns an array of generalized concentrations
136  /*!
137  * \f$ C^a_k\f$ are defined such that \f$ a_k = C^a_k /
138  * C^0_k, \f$ where \f$ C^0_k \f$ is a standard concentration
139  * defined below and \f$ a_k \f$ are activities used in the
140  * thermodynamic functions. These activity (or generalized)
141  * concentrations are used
142  * by kinetics manager classes to compute the forward and
143  * reverse rates of elementary reactions. Note that they may
144  * or may not have units of concentration --- they might be
145  * partial pressures, mole fractions, or surface coverages,
146  * for example.
147  *
148  * @param c Output array of generalized concentrations. The
149  * units depend upon the implementation of the
150  * reaction rate expressions within the phase.
151  */
152  virtual void getActivityConcentrations(doublereal* c) const;
153 
154  //! Get the array of non-dimensional molar-based activity coefficients at
155  //! the current solution temperature, pressure, and solution concentration.
156  /*!
157  * @param ac Output vector of activity coefficients. Length: m_kk.
158  */
159  virtual void getActivityCoefficients(doublereal* ac) const;
160 
161  //! Get the species chemical potentials. Units: J/kmol.
162  /*!
163  * This function returns a vector of chemical potentials of the
164  * species in solution at the current temperature, pressure
165  * and mole fraction of the solution.
166  *
167  * @param mu Output vector of species chemical
168  * potentials. Length: m_kk. Units: J/kmol
169  */
170  virtual void getChemPotentials(doublereal* mu) const;
171 
172  //! Get the array of chemical potentials at unit activity for the species
173  //! at their standard states at the current <I>T</I> and <I>P</I> of the solution.
174  /*!
175  * These are the standard state chemical potentials \f$ \mu^0_k(T,P)
176  * \f$. The values are evaluated at the current
177  * temperature and pressure of the solution
178  *
179  * @param mu0 Output vector of chemical potentials.
180  * Length: m_kk.
181  */
182  virtual void getStandardChemPotentials(doublereal* mu0) const;
183 
184  //! Return the standard concentration for the kth species
185  /*!
186  * The standard concentration \f$ C^0_k \f$ used to normalize
187  * the activity (i.e., generalized) concentration. In many cases, this quantity
188  * will be the same for all species in a phase - for example,
189  * for an ideal gas \f$ C^0_k = P/\hat R T \f$. For this
190  * reason, this method returns a single value, instead of an
191  * array. However, for phases in which the standard
192  * concentration is species-specific (e.g. surface species of
193  * different sizes), this method may be called with an
194  * optional parameter indicating the species.
195  *
196  * @param k Optional parameter indicating the species. The default
197  * is to assume this refers to species 0.
198  * @return
199  * Returns the standard Concentration in units of m3 kmol-1.
200  */
201  virtual doublereal standardConcentration(size_t k=0) const;
202 
203  //! Natural logarithm of the standard concentration of the kth species.
204  /*!
205  * @param k index of the species (defaults to zero)
206  */
207  virtual doublereal logStandardConc(size_t k=0) const;
208 
209  //! Get the Gibbs functions for the standard
210  //! state of the species at the current <I>T</I> and <I>P</I> of the solution
211  /*!
212  * Units are Joules/kmol
213  * @param gpure Output vector of standard state gibbs free energies
214  * Length: m_kk.
215  */
216  virtual void getPureGibbs(doublereal* gpure) const {
217  const vector_fp& gibbsrt = gibbs_RT();
218  scale(gibbsrt.begin(), gibbsrt.end(), gpure, _RT());
219  }
220 
221  //! Get the nondimensional Enthalpy functions for the species
222  //! at their standard states at the current <I>T</I> and <I>P</I> of the solution.
223  /*!
224  * @param hrt Output vector of nondimensional standard state enthalpies.
225  * Length: m_kk.
226  */
227  void getEnthalpy_RT(doublereal* hrt) const {
228  const vector_fp& _h = enthalpy_RT();
229  std::copy(_h.begin(), _h.end(), hrt);
230  }
231 
232  //! Get the array of nondimensional Entropy functions for the
233  //! standard state species at the current <I>T</I> and <I>P</I> of the solution.
234  /*!
235  * @param sr Output vector of nondimensional standard state entropies.
236  * Length: m_kk.
237  */
238  void getEntropy_R(doublereal* sr) const {
239  const vector_fp& _s = entropy_R();
240  std::copy(_s.begin(), _s.end(), sr);
241  }
242 
243  //! Get the nondimensional Gibbs functions for the species
244  //! in their standard states at the current <I>T</I> and <I>P</I> of the solution.
245  /*!
246  * @param grt Output vector of nondimensional standard state gibbs free energies
247  * Length: m_kk.
248  */
249  virtual void getGibbs_RT(doublereal* grt) const {
250  const vector_fp& gibbsrt = gibbs_RT();
251  std::copy(gibbsrt.begin(), gibbsrt.end(), grt);
252  }
253 
254  //! Get the nondimensional Heat Capacities at constant
255  //! pressure for the species standard states
256  //! at the current <I>T</I> and <I>P</I> of the solution
257  /*!
258  * @param cpr Output vector of nondimensional standard state heat capacities
259  * Length: m_kk.
260  */
261  void getCp_R(doublereal* cpr) const {
262  const vector_fp& _cpr = cp_R();
263  std::copy(_cpr.begin(), _cpr.end(), cpr);
264  }
265 
266 
267  // new methods defined here
268 
269  //! Returns a reference to the vector of nondimensional
270  //! enthalpies of the reference state at the current temperature
271  //! of the solution and the reference pressure for the species.
272  const vector_fp& enthalpy_RT() const {
273  _updateThermo();
274  return m_h0_RT;
275  }
276 
277  //! Returns a reference to the vector of nondimensional
278  //! Gibbs Free Energies of the reference state at the current temperature
279  //! of the solution and the reference pressure for the species.
280  const vector_fp& gibbs_RT() const {
281  _updateThermo();
282  return m_g0_RT;
283  }
284 
285  //! Returns a reference to the vector of exponentials of the nondimensional
286  //! Gibbs Free Energies of the reference state at the current temperature
287  //! of the solution and the reference pressure for the species.
288  const vector_fp& expGibbs_RT() const {
289  _updateThermo();
290  for (size_t k = 0; k != m_kk; k++) {
291  m_expg0_RT[k] = std::exp(m_g0_RT[k]);
292  }
293  return m_expg0_RT;
294  }
295 
296  //! Returns a reference to the vector of nondimensional
297  //! entropies of the reference state at the current temperature
298  //! of the solution and the reference pressure for each species.
299  const vector_fp& entropy_R() const {
300  _updateThermo();
301  return m_s0_R;
302  }
303 
304  //! Returns a reference to the vector of nondimensional
305  //! constant pressure heat capacities of the reference state
306  //! at the current temperature of the solution
307  //! and reference pressure for each species.
308  const vector_fp& cp_R() const {
309  _updateThermo();
310  return m_cp0_R;
311  }
312 
313  //! Set the potential energy of species k
314  /*!
315  * @param k species index
316  * @param pe Potential energy (J kmol-1).
317  */
318  virtual void setPotentialEnergy(int k, doublereal pe) {
319  m_pe[k] = pe;
320  }
321 
322  //! Returns the potential energy of species k
323  /*!
324  * @param k species index
325  */
326  virtual doublereal potentialEnergy(int k) const {
327  return m_pe[k];
328  }
329 
330  //! Initialize the ThermoPhase object after all species have been set up
331  /*!
332  * @internal Initialize.
333  *
334  * This method is provided to allow
335  * subclasses to perform any initialization required after all
336  * species have been added. For example, it might be used to
337  * resize internal work arrays that must have an entry for
338  * each species. The base class implementation does nothing,
339  * and subclasses that do not require initialization do not
340  * need to overload this method. When importing a CTML phase
341  * description, this method is called from ThermoPhase::initThermoXML(),
342  * which is called from importPhase(),
343  * just prior to returning from function importPhase().
344  *
345  * @see importCTML.cpp
346  */
347  virtual void initThermo();
348 
349  //!This method is used by the ChemEquil equilibrium solver.
350  /*!
351  * It sets the state such that the chemical potentials satisfy
352  * \f[ \frac{\mu_k}{\hat R T} = \sum_m A_{k,m}
353  * \left(\frac{\lambda_m} {\hat R T}\right) \f] where
354  * \f$ \lambda_m \f$ is the element potential of element m. The
355  * temperature is unchanged. Any phase (ideal or not) that
356  * implements this method can be equilibrated by ChemEquil.
357  *
358  * @param lambda_RT Input vector of dimensionless element potentials
359  * The length is equal to nElements().
360  */
361  virtual void setToEquilState(const doublereal* lambda_RT);
362 
363 
364  //! Set the equation of state parameters
365  /*!
366  * @internal
367  * The number and meaning of these depends on the subclass.
368  *
369  * @param n number of parameters
370  * @param c array of \a n coefficients
371  */
372  virtual void setParameters(int n, doublereal* const c) {
373  setDensity(c[0]);
374  }
375 
376  //! Get the equation of state parameters in a vector
377  /*!
378  * @internal
379  * The number and meaning of these depends on the subclass.
380  *
381  * @param n number of parameters
382  * @param c array of \a n coefficients
383  */
384  virtual void getParameters(int& n, doublereal* const c) const {
385  double d = density();
386  c[0] = d;
387  n = 1;
388  }
389 
390  //! Set equation of state parameter values from XML entries.
391  /*!
392  *
393  * This method is called by function importPhase() in
394  * file importCTML.cpp when processing a phase definition in
395  * an input file. It should be overloaded in subclasses to set
396  * any parameters that are specific to that particular phase
397  * model. Note, this method is called before the phase is
398  * initialized with elements and/or species.
399  *
400  * @param eosdata An XML_Node object corresponding to
401  * the "thermo" entry for this phase in the input file.
402  */
403  virtual void setParametersFromXML(const XML_Node& eosdata);
404 
405 protected:
406 
407  //! number of elements
408  size_t m_mm;
409 
410 
411  //! Minimum temperature for valid species standard state thermo props
412  /*!
413  * This is the minimum temperature at which all species have valid standard
414  * state thermo props defined.
415  */
416  doublereal m_tmin;
417 
418  //! Maximum temperature for valid species standard state thermo props
419  /*!
420  * This is the maximum temperature at which all species have valid standard
421  * state thermo props defined.
422  */
423  doublereal m_tmax;
424 
425  //! Reference state pressure
426  /*!
427  * Value of the reference state pressure in Pascals.
428  * All species must have the same reference state pressure.
429  */
430  doublereal m_p0;
431 
432  //! last value of the temperature processed by reference state
433  mutable doublereal m_tlast;
434 
435  //! Temporary storage for dimensionless reference state enthalpies
437 
438  //! Temporary storage for dimensionless reference state heat capacities
440 
441  //! Temporary storage for dimensionless reference state gibbs energies
443 
444  //! Temporary storage for dimensionless reference state entropies
445  mutable vector_fp m_s0_R;
446 
447  //! currently unsed
448  /*!
449  * @deprecated
450  */
452 
453  //! Currently unused
454  /*
455  * @deprecated
456  */
457  mutable vector_fp m_pe;
458 
459  //! Temporary array containing internally calculated partial pressures
460  mutable vector_fp m_pp;
461 
462  //! Current pressure (Pa)
463  doublereal m_press;
464 
465 private:
466 
467  //! Function to update the reference state thermo functions
468  void _updateThermo() const;
469 };
470 }
471 
472 #endif