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