Cantera  2.1.2
VPStandardStateTP.h
Go to the documentation of this file.
1 /**
2  * @file VPStandardStateTP.h
3  * Header file for a derived class of ThermoPhase that handles
4  * variable pressure standard state methods for calculating
5  * thermodynamic properties (see \ref thermoprops and
6  * class \link Cantera::VPStandardStateTP VPStandardStateTP\endlink).
7  *
8  * These include most of the
9  * methods for calculating liquid electrolyte thermodynamics.
10  */
11 /*
12  * Copyright (2005) Sandia Corporation. Under the terms of
13  * Contract DE-AC04-94AL85000 with Sandia Corporation, the
14  * U.S. Government retains certain rights in this software.
15  */
16 #ifndef CT_VPSTANDARDSTATETP_H
17 #define CT_VPSTANDARDSTATETP_H
18 
19 #include "ThermoPhase.h"
20 #include "VPSSMgr.h"
21 
22 namespace Cantera
23 {
24 
25 class XML_Node;
26 class PDSS;
27 
28 /**
29  * @ingroup thermoprops
30  *
31  * This is a filter class for ThermoPhase that implements some prepatory
32  * steps for efficiently handling
33  * a variable pressure standard state for species.
34  *
35  * Several concepts are introduced. The first concept is there are temporary
36  * variables for holding the species standard state values
37  * of Cp, H, S, G, and V at the
38  * last temperature and pressure called. These functions are not recalculated
39  * if a new call is made using the previous temperature and pressure. Currently,
40  * these variables and the calculation method are handled by the VPSSMgr class,
41  * for which VPStandardStateTP owns a pointer to.
42  *
43  * To support the above functionality, pressure and temperature variables,
44  * m_Plast_ss and m_Tlast_ss, are kept which store the last pressure and temperature
45  * used in the evaluation of standard state properties.
46  *
47  * This class is usually used for nearly incompressible phases. For those phases, it
48  * makes sense to change the equation of state independent variable from
49  * density to pressure. The variable m_Pcurrent contains the current value of the
50  * pressure within the phase.
51  *
52  * @todo
53  * Put some teeth into this level by overloading the setDensity() function. It should
54  * now throw an exception. Instead, setPressure routines should calculate the
55  * solution density and then call State:setDensity() directly.
56  *
57  * @nosubgrouping
58  */
60 {
61 
62 public:
63  //! @name Constructors and Duplicators for %VPStandardStateTP
64 
65  /// Constructor.
67 
68  //! Copy Constructor.
69  /*!
70  * @param b Object to be copied
71  */
73 
74  //! Assignment operator
75  /*!
76  * @param b Object to be copied
77  */
79 
80  //! Destructor.
81  virtual ~VPStandardStateTP();
82 
83  //! Duplication routine
84  virtual ThermoPhase* duplMyselfAsThermoPhase() const;
85 
86  //@}
87  //! @name Utilities (VPStandardStateTP)
88  //@{
89  /**
90  * Equation of state type flag. The base class returns
91  * zero. Subclasses should define this to return a unique
92  * non-zero value. Constants defined for this purpose are
93  * listed in mix_defs.h.
94  */
95  virtual int eosType() const {
96  return 0;
97  }
98 
99  //! This method returns the convention used in specification
100  //! of the standard state, of which there are currently two,
101  //! temperature based, and variable pressure based.
102  /*!
103  * Currently, there are two standard state conventions:
104  * - Temperature-based activities,
105  * `cSS_CONVENTION_TEMPERATURE 0` (default)
106  * - Variable Pressure and Temperature-based activities,
107  * `cSS_CONVENTION_VPSS 1`
108  */
109  virtual int standardStateConvention() const;
110 
111  //! Get the array of log concentration-like derivatives of the
112  //! log activity coefficients
113  /*!
114  * This function is a virtual method. For ideal mixtures
115  * (unity activity coefficients), this can return zero.
116  * Implementations should take the derivative of the
117  * logarithm of the activity coefficient with respect to the
118  * logarithm of the concentration-like variable (i.e. moles)
119  * that represents the standard state.
120  * This quantity is to be used in conjunction with derivatives of
121  * that concentration-like variable when the derivative of the chemical
122  * potential is taken.
123  *
124  * units = dimensionless
125  *
126  * @param dlnActCoeffdlnN_diag Output vector of derivatives of the
127  * log Activity Coefficients. length = m_kk
128  */
129  virtual void getdlnActCoeffdlnN_diag(doublereal* dlnActCoeffdlnN_diag) const {
130  err("getdlnActCoeffdlnN_diag");
131  }
132 
133  //@}
134  /// @name Partial Molar Properties of the Solution (VPStandardStateTP)
135  //@{
136 
137  //! Get the array of non-dimensional species chemical potentials.
138  /*!
139  * These are partial molar Gibbs free energies,
140  * \f$ \mu_k / \hat R T \f$.
141  *
142  * We close the loop on this function, here, calling
143  * getChemPotentials() and then dividing by RT. No need for child
144  * classes to handle.
145  *
146  * @param mu Output vector of non-dimensional species chemical potentials
147  * Length: m_kk.
148  */
149  void getChemPotentials_RT(doublereal* mu) const;
150 
151  //@}
152 
153  /*!
154  * @name Properties of the Standard State of the Species in the Solution (VPStandardStateTP)
155  *
156  * Within VPStandardStateTP, these properties are calculated via a common routine,
157  * _updateStandardStateThermo(), which must be overloaded in inherited
158  * objects. The values are cached within this object, and are not
159  * recalculated unless the temperature or pressure changes.
160  */
161  //@{
162 
163  //!Get the array of chemical potentials at unit activity.
164  /*!
165  * These are the standard state chemical potentials \f$ \mu^0_k(T,P)
166  * \f$. The values are evaluated at the current temperature and pressure.
167  *
168  * @param mu Output vector of standard state chemical potentials.
169  * length = m_kk. units are J / kmol.
170  */
171  virtual void getStandardChemPotentials(doublereal* mu) const;
172 
173  /**
174  * Get the nondimensional Enthalpy functions for the species
175  * at their standard states at the current
176  * <I>T</I> and <I>P</I> of the solution.
177  *
178  * @param hrt Output vector of standard state enthalpies.
179  * length = m_kk. units are unitless.
180  */
181  virtual void getEnthalpy_RT(doublereal* hrt) const;
182 
183  /**
184  * Get the array of nondimensional Enthalpy functions for the
185  * standard state species
186  * at the current <I>T</I> and <I>P</I> of the solution.
187  *
188  * @param sr Output vector of nondimensional standard state
189  * entropies. length = m_kk.
190  */
191  virtual void getEntropy_R(doublereal* sr) const;
192 
193  /**
194  * Get the nondimensional Gibbs functions for the species
195  * at their standard states of solution at the current T and P
196  * of the solution.
197  *
198  * @param grt Output vector of nondimensional standard state
199  * Gibbs free energies. length = m_kk.
200  */
201  virtual void getGibbs_RT(doublereal* grt) const;
202 
203  //! Get the standard state Gibbs functions for each species
204  //! at the current T and P.
205  /*!
206  * (Note resolved at this level)
207  *
208  * @param gpure Output vector of standard state
209  * Gibbs free energies. length = m_kk.
210  * units are J/kmol.
211  */
212  void getPureGibbs(doublereal* gpure) const;
213 
214  /**
215  * Returns the vector of nondimensional
216  * internal Energies of the standard state at the current temperature
217  * and pressure of the solution for each species.
218  * \f[
219  * u^{ss}_k(T,P) = h^{ss}_k(T) - P * V^{ss}_k
220  * \f]
221  *
222  * @param urt Output vector of nondimensional standard state
223  * internal energies. length = m_kk.
224  */
225  virtual void getIntEnergy_RT(doublereal* urt) const;
226 
227  /**
228  * Get the nondimensional Heat Capacities at constant
229  * pressure for the standard state of the species
230  * at the current T and P.
231  *
232  * This is redefined here to call the internal function, _updateStandardStateThermo(),
233  * which calculates all standard state properties at the same time.
234  *
235  * @param cpr Output vector containing the
236  * the nondimensional Heat Capacities at constant
237  * pressure for the standard state of the species.
238  * Length: m_kk.
239  */
240  virtual void getCp_R(doublereal* cpr) const;
241 
242 
243  //! Get the molar volumes of each species in their standard
244  //! states at the current
245  //! <I>T</I> and <I>P</I> of the solution.
246  /*!
247  * units = m^3 / kmol
248  *
249  * This is redefined here to call the internal function, _updateStandardStateThermo(),
250  * which calculates all standard state properties at the same time.
251  *
252  * @param vol Output vector of species volumes. length = m_kk.
253  * units = m^3 / kmol
254  */
255  virtual void getStandardVolumes(doublereal* vol) const;
256  virtual const vector_fp& getStandardVolumes() const;
257 
258  //! Set the temperature of the phase
259  /*!
260  * Currently this passes down to setState_TP(). It does not
261  * make sense to calculate the standard state without first
262  * setting T and P.
263  *
264  * @param temp Temperature (kelvin)
265  */
266  virtual void setTemperature(const doublereal temp);
267 
268  //! Set the internally stored pressure (Pa) at constant
269  //! temperature and composition
270  /*!
271  * Currently this passes down to setState_TP(). It does not
272  * make sense to calculate the standard state without first
273  * setting T and P.
274  *
275  * @param p input Pressure (Pa)
276  */
277  virtual void setPressure(doublereal p);
278 
279 protected:
280  /**
281  * Calculate the density of the mixture using the partial
282  * molar volumes and mole fractions as input
283  *
284  * The formula for this is
285  *
286  * \f[
287  * \rho = \frac{\sum_k{X_k W_k}}{\sum_k{X_k V_k}}
288  * \f]
289  *
290  * where \f$X_k\f$ are the mole fractions, \f$W_k\f$ are
291  * the molecular weights, and \f$V_k\f$ are the pure species
292  * molar volumes.
293  *
294  * Note, the basis behind this formula is that in an ideal
295  * solution the partial molar volumes are equal to the pure
296  * species molar volumes. We have additionally specified
297  * in this class that the pure species molar volumes are
298  * independent of temperature and pressure.
299  *
300  * NOTE: This is a non-virtual function, which is not a
301  * member of the ThermoPhase base class.
302  */
303  virtual void calcDensity();
304 
305 public:
306  //! Set the temperature and pressure at the same time
307  /*!
308  * Note this function triggers a reevaluation of the standard
309  * state quantities.
310  *
311  * @param T temperature (kelvin)
312  * @param pres pressure (pascal)
313  */
314  virtual void setState_TP(doublereal T, doublereal pres);
315 
316  //! Returns the current pressure of the phase
317  /*!
318  * The pressure is an independent variable in this phase. Its current value
319  * is stored in the object VPStandardStateTP.
320  *
321  * @return return the pressure in pascals.
322  */
323  doublereal pressure() const {
324  return m_Pcurrent;
325  }
326 
327 protected:
328 
329  //! Updates the standard state thermodynamic functions at the current T and P of the solution.
330  /*!
331  * @internal
332  *
333  * If m_useTmpStandardStateStorage is true,
334  * this function must be called for every call to functions in this class.
335  *
336  * This function is responsible for updating the following internal members,
337  * when m_useTmpStandardStateStorage is true.
338  *
339  * - m_hss_RT;
340  * - m_cpss_R;
341  * - m_gss_RT;
342  * - m_sss_R;
343  * - m_Vss
344  *
345  * This function doesn't check to see if the temperature or pressure
346  * has changed. It automatically assumes that it has changed.
347  * If m_useTmpStandardStateStorage is not true, this function may be
348  * required to be called by child classes to update internal member data..
349  *
350  */
351  virtual void _updateStandardStateThermo() const;
352 
353 public:
354 
355  //! Updates the standard state thermodynamic functions at the current T and P of the solution.
356  /*!
357  *
358  * If m_useTmpStandardStateStorage is true,
359  * this function must be called for every call to functions in this
360  * class. It checks to see whether the temperature or pressure has changed and
361  * thus the ss thermodynamics functions for all of the species
362  * must be recalculated.
363  *
364  * This function is responsible for updating the following internal members,
365  * when m_useTmpStandardStateStorage is true.
366  *
367  * - m_hss_RT;
368  * - m_cpss_R;
369  * - m_gss_RT;
370  * - m_sss_R;
371  * - m_Vss
372  *
373  * If m_useTmpStandardStateStorage is not true, this function may be
374  * required to be called by child classes to update internal member data.
375  *
376  */
377  virtual void updateStandardStateThermo() const;
378 
379  //@}
380  /// @name Thermodynamic Values for the Species Reference States (VPStandardStateTP)
381  /*!
382  * There are also temporary
383  * variables for holding the species reference-state values of Cp, H, S, and V at the
384  * last temperature and reference pressure called. These functions are not recalculated
385  * if a new call is made using the previous temperature.
386  * All calculations are done within the routine _updateRefStateThermo().
387  */
388  //@{
389 
390  //! Returns the vector of nondimensional
391  //! enthalpies of the reference state at the current temperature
392  //! of the solution and the reference pressure for the species.
393  /*!
394  * @param hrt Output vector contains the nondimensional enthalpies
395  * of the reference state of the species
396  * length = m_kk, units = dimensionless.
397  */
398  virtual void getEnthalpy_RT_ref(doublereal* hrt) const;
399 
400 #ifdef H298MODIFY_CAPABILITY
401  //! Modify the value of the 298 K Heat of Formation of the standard state of
402  //! one species in the phase (J kmol-1)
403  /*!
404  * The 298K heat of formation is defined as the enthalpy change to create the standard state
405  * of the species from its constituent elements in their standard states at 298 K and 1 bar.
406  *
407  * @param k Index of the species
408  * @param Hf298New Specify the new value of the Heat of Formation at 298K and 1 bar.
409  * units = J/kmol.
410  */
411  void modifyOneHf298SS(const size_t& k, const doublereal Hf298New);
412 #endif
413 
414  //! Returns the vector of nondimensional
415  //! Gibbs free energies of the reference state at the current temperature
416  //! of the solution and the reference pressure for the species.
417  /*!
418  * @param grt Output vector contains the nondimensional Gibbs free energies
419  * of the reference state of the species
420  * length = m_kk, units = dimensionless.
421  */
422  virtual void getGibbs_RT_ref(doublereal* grt) const;
423 
424 protected:
425  const vector_fp& Gibbs_RT_ref() const;
426 public:
427  /*!
428  * Returns the vector of the
429  * gibbs function of the reference state at the current temperature
430  * of the solution and the reference pressure for the species.
431  * units = J/kmol
432  *
433  * @param g Output vector contain the Gibbs free energies
434  * of the reference state of the species
435  * length = m_kk, units = J/kmol.
436  */
437  virtual void getGibbs_ref(doublereal* g) const;
438 
439  /*!
440  * Returns the vector of nondimensional
441  * entropies of the reference state at the current temperature
442  * of the solution and the reference pressure for the species.
443  *
444  * @param er Output vector contain the nondimensional entropies
445  * of the species in their reference states
446  * length: m_kk, units: dimensionless.
447  */
448  virtual void getEntropy_R_ref(doublereal* er) const;
449 
450  /*!
451  * Returns the vector of nondimensional
452  * constant pressure heat capacities of the reference state
453  * at the current temperature of the solution
454  * and reference pressure for the species.
455  *
456  * @param cprt Output vector contains the nondimensional heat capacities
457  * of the species in their reference states
458  * length: m_kk, units: dimensionless.
459  */
460  virtual void getCp_R_ref(doublereal* cprt) const;
461 
462  //! Get the molar volumes of the species reference states at the current
463  //! <I>T</I> and <I>P_ref</I> of the solution.
464  /*!
465  * units = m^3 / kmol
466  *
467  * @param vol Output vector containing the standard state volumes.
468  * Length: m_kk.
469  */
470  virtual void getStandardVolumes_ref(doublereal* vol) const;
471  //@}
472 
473 public:
474  //! @name Initialization Methods - For Internal use (VPStandardState)
475  /*!
476  * The following methods are used in the process of constructing
477  * the phase and setting its parameters from a specification in an
478  * input file. They are not normally used in application programs.
479  * To see how they are used, see files importCTML.cpp and
480  * ThermoFactory.cpp.
481  */
482  //@{
483 
484  /**
485  * Set equation of state parameter values from XML
486  * entries. This method is called by function importPhase in
487  * file importCTML.cpp when processing a phase definition in
488  * an input file. It should be overloaded in subclasses to set
489  * any parameters that are specific to that particular phase
490  * model.
491  *
492  * @param eosdata An XML_Node object corresponding to
493  * the "thermo" entry for this phase in the input file.
494  */
495  virtual void setParametersFromXML(const XML_Node& eosdata) {}
496 
497  virtual void initThermo();
498 
499  //! Initialize a ThermoPhase object, potentially reading activity
500  //! coefficient information from an XML database.
501  /*!
502  * This routine initializes the lengths in the current object and
503  * then calls the parent routine.
504  * This method is provided to allow
505  * subclasses to perform any initialization required after all
506  * species have been added. For example, it might be used to
507  * resize internal work arrays that must have an entry for
508  * each species. The base class implementation does nothing,
509  * and subclasses that do not require initialization do not
510  * need to overload this method. When importing a CTML phase
511  * description, this method is called just prior to returning
512  * from function importPhase().
513  *
514  * @param phaseNode This object must be the phase node of a
515  * complete XML tree
516  * description of the phase, including all of the
517  * species data. In other words while "phase" must
518  * point to an XML phase object, it must have
519  * sibling nodes "speciesData" that describe
520  * the species in the phase.
521  * @param id ID of the phase. If nonnull, a check is done
522  * to see if phaseNode is pointing to the phase
523  * with the correct id.
524  */
525  virtual void initThermoXML(XML_Node& phaseNode, const std::string& id);
526 
527 
528  //! set the VPSS Mgr
529  /*!
530  * @param vp_ptr Pointer to the manager
531  */
532  void setVPSSMgr(VPSSMgr* vp_ptr);
533 
534  //! Return a pointer to the VPSSMgr for this phase
535  /*!
536  * @return Returns a pointer to the VPSSMgr for this phase
537  */
539 
540  void createInstallPDSS(size_t k, const XML_Node& s, const XML_Node* phaseNode_ptr);
541 
542  PDSS* providePDSS(size_t k);
543  const PDSS* providePDSS(size_t k) const;
544 
545 private:
546  //! @internal Initialize the internal lengths in this object.
547  /*!
548  * Note this is not a virtual function.
549  */
550  void initLengths();
551 
552  //@}
553 
554 protected:
555 
556  //! Current value of the pressure - state variable
557  /*!
558  * Because we are now using the pressure as a state variable, we need to carry it
559  * along within this object
560  *
561  * units = Pascals
562  */
563  doublereal m_Pcurrent;
564 
565  //! The last temperature at which the standard statethermodynamic properties were calculated at.
566  mutable doublereal m_Tlast_ss;
567 
568  //! The last pressure at which the Standard State thermodynamic
569  //! properties were calculated at.
570  mutable doublereal m_Plast_ss;
571 
572  /*!
573  * Reference pressure (Pa) must be the same for all species
574  * - defaults to OneAtm
575  */
576  doublereal m_P0;
577 
578  // -> suggest making this private!
579 protected:
580 
581  //! Pointer to the VPSS manager that calculates all of the standard state
582  //! info efficiently.
583  mutable VPSSMgr* m_VPSS_ptr;
584 
585  //! Storage for the PDSS objects for the species
586  /*!
587  * Storage is in species index order.
588  * VPStandardStateTp owns each of the objects.
589  * Copy operations are deep.
590  */
591  std::vector<PDSS*> m_PDSS_storage;
592 
593 private:
594  //! VPStandardStateTP has its own err routine
595  /*!
596  * @param msg Error message string
597  */
598  doublereal err(const std::string& msg) const;
599 
600 };
601 }
602 
603 #endif
doublereal m_Tlast_ss
The last temperature at which the standard statethermodynamic properties were calculated at...
virtual void getGibbs_RT(doublereal *grt) const
Get the nondimensional Gibbs functions for the species at their standard states of solution at the cu...
virtual ThermoPhase * duplMyselfAsThermoPhase() const
Duplication routine.
doublereal m_Plast_ss
The last pressure at which the Standard State thermodynamic properties were calculated at...
Virtual base class for the classes that manage the calculation of standard state properties for all t...
Definition: VPSSMgr.h:238
Declaration file for a virtual base class that manages the calculation of standard state properties f...
virtual void getGibbs_RT_ref(doublereal *grt) const
Returns the vector of nondimensional Gibbs free energies of the reference state at the current temper...
virtual void setTemperature(const doublereal temp)
Set the temperature of the phase.
virtual void getCp_R(doublereal *cpr) const
Get the nondimensional Heat Capacities at constant pressure for the standard state of the species at ...
virtual void getEnthalpy_RT_ref(doublereal *hrt) const
Returns the vector of nondimensional enthalpies of the reference state at the current temperature of ...
virtual void modifyOneHf298SS(const int k, const doublereal Hf298New)
Modify the value of the 298 K Heat of Formation of one species in the phase (J kmol-1) ...
Definition: ThermoPhase.h:227
virtual int eosType() const
Equation of state type flag.
Class XML_Node is a tree-based representation of the contents of an XML file.
Definition: xml.h:100
virtual void updateStandardStateThermo() const
Updates the standard state thermodynamic functions at the current T and P of the solution.
std::vector< PDSS * > m_PDSS_storage
Storage for the PDSS objects for the species.
virtual void setParametersFromXML(const XML_Node &eosdata)
Set equation of state parameter values from XML entries.
virtual void getCp_R_ref(doublereal *cprt) const
VPSSMgr * m_VPSS_ptr
Pointer to the VPSS manager that calculates all of the standard state info efficiently.
virtual void setPressure(doublereal p)
Set the internally stored pressure (Pa) at constant temperature and composition.
VPStandardStateTP & operator=(const VPStandardStateTP &b)
Assignment operator.
Base class for a phase with thermodynamic properties.
Definition: ThermoPhase.h:101
void setVPSSMgr(VPSSMgr *vp_ptr)
set the VPSS Mgr
virtual void initThermo()
Initialize the ThermoPhase object after all species have been set up.
virtual int standardStateConvention() const
This method returns the convention used in specification of the standard state, of which there are cu...
virtual ~VPStandardStateTP()
Destructor.
virtual void getStandardVolumes_ref(doublereal *vol) const
Get the molar volumes of the species reference states at the current T and P_ref of the solution...
doublereal pressure() const
Returns the current pressure of the phase.
virtual void calcDensity()
Calculate the density of the mixture using the partial molar volumes and mole fractions as input...
virtual void getdlnActCoeffdlnN_diag(doublereal *dlnActCoeffdlnN_diag) const
Get the array of log concentration-like derivatives of the log activity coefficients.
void getPureGibbs(doublereal *gpure) const
Get the standard state Gibbs functions for each species at the current T and P.
This is a filter class for ThermoPhase that implements some prepatory steps for efficiently handling ...
virtual void getIntEnergy_RT(doublereal *urt) const
Returns the vector of nondimensional internal Energies of the standard state at the current temperatu...
virtual void getEntropy_R(doublereal *sr) const
Get the array of nondimensional Enthalpy functions for the standard state species at the current T an...
virtual void getGibbs_ref(doublereal *g) const
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:165
Virtual base class for a species with a pressure dependent standard state.
Definition: PDSS.h:195
virtual void getEnthalpy_RT(doublereal *hrt) const
Get the nondimensional Enthalpy functions for the species at their standard states at the current T a...
virtual void initThermoXML(XML_Node &phaseNode, const std::string &id)
Initialize a ThermoPhase object, potentially reading activity coefficient information from an XML dat...
doublereal m_Pcurrent
Current value of the pressure - state variable.
virtual void getStandardChemPotentials(doublereal *mu) const
Get the array of chemical potentials at unit activity.
doublereal err(const std::string &msg) const
VPStandardStateTP has its own err routine.
Header file for class ThermoPhase, the base class for phases with thermodynamic properties, and the text for the Module thermoprops (see Thermodynamic Properties and class ThermoPhase).
VPSSMgr * provideVPSSMgr()
Return a pointer to the VPSSMgr for this phase.
virtual void getEntropy_R_ref(doublereal *er) const
void getChemPotentials_RT(doublereal *mu) const
Get the array of non-dimensional species chemical potentials.
virtual void setState_TP(doublereal T, doublereal pres)
Set the temperature and pressure at the same time.
virtual void _updateStandardStateThermo() const
Updates the standard state thermodynamic functions at the current T and P of the solution.