Cantera  2.3.0
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 
9 // This file is part of Cantera. See License.txt in the top-level directory or
10 // at http://www.cantera.org/license.txt for license and copyright information.
11 
12 #ifndef CT_VPSTANDARDSTATETP_H
13 #define CT_VPSTANDARDSTATETP_H
14 
15 #include "ThermoPhase.h"
16 #include "VPSSMgr.h"
17 #include "PDSS.h"
18 
19 namespace Cantera
20 {
21 /**
22  * @ingroup thermoprops
23  *
24  * This is a filter class for ThermoPhase that implements some prepatory steps
25  * for efficiently handling a variable pressure standard state for species.
26  *
27  * Several concepts are introduced. The first concept is there are temporary
28  * variables for holding the species standard state values of Cp, H, S, G, and V
29  * at the last temperature and pressure called. These functions are not
30  * recalculated if a new call is made using the previous temperature and
31  * pressure. Currently, these variables and the calculation method are handled
32  * by the VPSSMgr class, for which VPStandardStateTP owns a pointer to.
33  *
34  * To support the above functionality, pressure and temperature variables,
35  * m_Plast_ss and m_Tlast_ss, are kept which store the last pressure and
36  * temperature used in the evaluation of standard state properties.
37  *
38  * This class is usually used for nearly incompressible phases. For those
39  * phases, it makes sense to change the equation of state independent variable
40  * from density to pressure. The variable m_Pcurrent contains the current value
41  * of the pressure within the phase.
42  *
43  * @todo Put some teeth into this level by overloading the setDensity()
44  * function. It should now throw an exception. Instead, setPressure routines
45  * should calculate the solution density and then call State:setDensity()
46  * directly.
47  */
49 {
50 public:
51  //! @name Constructors and Duplicators for VPStandardStateTP
52 
53  /// Constructor.
55 
57  VPStandardStateTP& operator=(const VPStandardStateTP& b);
58  virtual ThermoPhase* duplMyselfAsThermoPhase() const;
59 
60  //@}
61  //! @name Utilities (VPStandardStateTP)
62  //@{
63 
64  virtual int standardStateConvention() const;
65 
66  virtual void getdlnActCoeffdlnN_diag(doublereal* dlnActCoeffdlnN_diag) const {
67  throw NotImplementedError("VPStandardStateTP::getdlnActCoeffdlnN_diag");
68  }
69 
70  //@}
71  /// @name Partial Molar Properties of the Solution (VPStandardStateTP)
72  //@{
73 
74  //! Get the array of non-dimensional species chemical potentials.
75  /*!
76  * These are partial molar Gibbs free energies, \f$ \mu_k / \hat R T \f$.
77  *
78  * We close the loop on this function, here, calling getChemPotentials() and
79  * then dividing by RT. No need for child classes to handle.
80  *
81  * @param mu Output vector of non-dimensional species chemical potentials
82  * Length: m_kk.
83  */
84  virtual void getChemPotentials_RT(doublereal* mu) const;
85 
86  //@}
87 
88  /*!
89  * @name Properties of the Standard State of the Species in the Solution
90  *
91  * Within VPStandardStateTP, these properties are calculated via a common
92  * routine, _updateStandardStateThermo(), which must be overloaded in
93  * inherited objects. The values are cached within this object, and are not
94  * recalculated unless the temperature or pressure changes.
95  */
96  //@{
97 
98  virtual void getStandardChemPotentials(doublereal* mu) const;
99  virtual void getEnthalpy_RT(doublereal* hrt) const;
100  virtual void getEntropy_R(doublereal* sr) const;
101  virtual void getGibbs_RT(doublereal* grt) const;
102  virtual void getPureGibbs(doublereal* gpure) const;
103  virtual void getIntEnergy_RT(doublereal* urt) const;
104  virtual void getCp_R(doublereal* cpr) const;
105  virtual void getStandardVolumes(doublereal* vol) const;
106  virtual const vector_fp& getStandardVolumes() const;
107 
108  //! Set the temperature of the phase
109  /*!
110  * Currently this passes down to setState_TP(). It does not make sense to
111  * calculate the standard state without first setting T and P.
112  *
113  * @param temp Temperature (kelvin)
114  */
115  virtual void setTemperature(const doublereal temp);
116 
117  //! Set the internally stored pressure (Pa) at constant temperature and
118  //! composition
119  /*!
120  * Currently this passes down to setState_TP(). It does not make sense to
121  * calculate the standard state without first setting T and P.
122  *
123  * @param p input Pressure (Pa)
124  */
125  virtual void setPressure(doublereal p);
126 
127  //! Set the temperature and pressure at the same time
128  /*!
129  * Note this function triggers a reevaluation of the standard state
130  * quantities.
131  *
132  * @param T temperature (kelvin)
133  * @param pres pressure (pascal)
134  */
135  virtual void setState_TP(doublereal T, doublereal pres);
136 
137  //! Returns the current pressure of the phase
138  /*!
139  * The pressure is an independent variable in this phase. Its current value
140  * is stored in the object VPStandardStateTP.
141  *
142  * @returns the pressure in pascals.
143  */
144  virtual doublereal pressure() const {
145  return m_Pcurrent;
146  }
147 
148  //! Updates the standard state thermodynamic functions at the current T and P of the solution.
149  /*!
150  * If m_useTmpStandardStateStorage is true, this function must be called for
151  * every call to functions in this class. It checks to see whether the
152  * temperature or pressure has changed and thus the ss thermodynamics
153  * functions for all of the species must be recalculated.
154  *
155  * This function is responsible for updating the following internal members,
156  * when m_useTmpStandardStateStorage is true.
157  *
158  * - m_hss_RT;
159  * - m_cpss_R;
160  * - m_gss_RT;
161  * - m_sss_R;
162  * - m_Vss
163  *
164  * If m_useTmpStandardStateStorage is not true, this function may be
165  * required to be called by child classes to update internal member data.
166  */
167  virtual void updateStandardStateThermo() const;
168 
169  //@}
170 
171 protected:
172  /**
173  * Calculate the density of the mixture using the partial molar volumes and
174  * mole fractions as input.
175  *
176  * The formula for this is
177  *
178  * \f[
179  * \rho = \frac{\sum_k{X_k W_k}}{\sum_k{X_k V_k}}
180  * \f]
181  *
182  * where \f$X_k\f$ are the mole fractions, \f$W_k\f$ are the molecular
183  * weights, and \f$V_k\f$ are the pure species molar volumes.
184  *
185  * Note, the basis behind this formula is that in an ideal solution the
186  * partial molar volumes are equal to the pure species molar volumes. We
187  * have additionally specified in this class that the pure species molar
188  * volumes are independent of temperature and pressure.
189  *
190  * NOTE: This function is not a member of the ThermoPhase base class.
191  */
192  virtual void calcDensity();
193 
194  //! Updates the standard state thermodynamic functions at the current T and
195  //! P of the solution.
196  /*!
197  * @internal
198  *
199  * If m_useTmpStandardStateStorage is true,
200  * this function must be called for every call to functions in this class.
201  *
202  * This function is responsible for updating the following internal members,
203  * when m_useTmpStandardStateStorage is true.
204  *
205  * - m_hss_RT;
206  * - m_cpss_R;
207  * - m_gss_RT;
208  * - m_sss_R;
209  * - m_Vss
210  *
211  * This function doesn't check to see if the temperature or pressure
212  * has changed. It automatically assumes that it has changed.
213  * If m_useTmpStandardStateStorage is not true, this function may be
214  * required to be called by child classes to update internal member data..
215  */
216  virtual void _updateStandardStateThermo() const;
217 
218 public:
219  /// @name Thermodynamic Values for the Species Reference States
220  /*!
221  * There are also temporary variables for holding the species reference-
222  * state values of Cp, H, S, and V at the last temperature and reference
223  * pressure called. These functions are not recalculated if a new call is
224  * made using the previous temperature. All calculations are done within the
225  * routine _updateRefStateThermo().
226  */
227  //@{
228 
229  virtual void getEnthalpy_RT_ref(doublereal* hrt) const;
230  virtual void getGibbs_RT_ref(doublereal* grt) const;
231 
232 protected:
233  const vector_fp& Gibbs_RT_ref() const;
234 
235 public:
236  virtual void getGibbs_ref(doublereal* g) const;
237  virtual void getEntropy_R_ref(doublereal* er) const;
238  virtual void getCp_R_ref(doublereal* cprt) const;
239  virtual void getStandardVolumes_ref(doublereal* vol) const;
240  //@}
241 
242  //! @name Initialization Methods - For Internal use
243  /*!
244  * The following methods are used in the process of constructing
245  * the phase and setting its parameters from a specification in an
246  * input file. They are not normally used in application programs.
247  * To see how they are used, see importPhase().
248  */
249  //@{
250 
251  virtual void initThermo();
252  virtual void initThermoXML(XML_Node& phaseNode, const std::string& id);
253 
254  using Phase::addSpecies;
255  virtual bool addSpecies(shared_ptr<Species> spec);
256 
257  //! set the VPSS Mgr
258  /*!
259  * @param vp_ptr Pointer to the manager
260  */
261  void setVPSSMgr(VPSSMgr* vp_ptr);
262 
263  //! Return a pointer to the VPSSMgr for this phase
264  /*!
265  * @returns a pointer to the VPSSMgr for this phase
266  */
268 
269  void createInstallPDSS(size_t k, const XML_Node& s, const XML_Node* phaseNode_ptr);
270 
271  PDSS* providePDSS(size_t k);
272  const PDSS* providePDSS(size_t k) const;
273 
274 protected:
275  virtual void invalidateCache();
276 
277  //! Current value of the pressure - state variable
278  /*!
279  * Because we are now using the pressure as a state variable, we need to
280  * carry it along within this object
281  *
282  * units = Pascals
283  */
284  doublereal m_Pcurrent;
285 
286  //! The last temperature at which the standard statethermodynamic properties
287  //! were calculated at.
288  mutable doublereal m_Tlast_ss;
289 
290  //! The last pressure at which the Standard State thermodynamic properties
291  //! were calculated at.
292  mutable doublereal m_Plast_ss;
293 
294  /*!
295  * Reference pressure (Pa) must be the same for all species
296  * - defaults to OneAtm
297  */
298  doublereal m_P0;
299 
300  // -> suggest making this private!
301  //! Pointer to the VPSS manager that calculates all of the standard state
302  //! info efficiently.
303  mutable std::unique_ptr<VPSSMgr> m_VPSS_ptr;
304 
305  //! Storage for the PDSS objects for the species
306  /*!
307  * Storage is in species index order. VPStandardStateTp owns each of the
308  * objects. Copy operations are deep.
309  */
310  std::vector<std::unique_ptr<PDSS>> m_PDSS_storage;
311 };
312 }
313 
314 #endif
virtual void updateStandardStateThermo() const
Updates the standard state thermodynamic functions at the current T and P of the solution.
doublereal m_Tlast_ss
The last temperature at which the standard statethermodynamic properties were calculated at...
doublereal m_Plast_ss
The last pressure at which the Standard State thermodynamic properties were calculated at...
virtual void getGibbs_ref(doublereal *g) const
Returns the vector of the Gibbs function of the reference state at the current temperature of the sol...
An error indicating that an unimplemented function has been called.
Definition: ctexceptions.h:193
virtual void getChemPotentials_RT(doublereal *mu) const
Get the array of non-dimensional species chemical potentials.
Virtual base class for the classes that manage the calculation of standard state properties for all t...
Definition: VPSSMgr.h:228
Declaration file for a virtual base class that manages the calculation of standard state properties f...
virtual ThermoPhase * duplMyselfAsThermoPhase() const
Duplication routine for objects which inherit from ThermoPhase.
virtual void setTemperature(const doublereal temp)
Set the temperature of the phase.
std::vector< std::unique_ptr< PDSS > > m_PDSS_storage
Storage for the PDSS objects for the species.
Class XML_Node is a tree-based representation of the contents of an XML file.
Definition: xml.h:97
virtual void getCp_R(doublereal *cpr) const
Get the nondimensional Heat Capacities at constant pressure for the species standard states at the cu...
virtual void setPressure(doublereal p)
Set the internally stored pressure (Pa) at constant temperature and composition.
Base class for a phase with thermodynamic properties.
Definition: ThermoPhase.h:93
virtual bool addSpecies(shared_ptr< Species > spec)
virtual void invalidateCache()
Invalidate any cached values which are normally updated only when a change in state is detected...
virtual void getEntropy_R_ref(doublereal *er) const
Returns the vector of nondimensional entropies of the reference state at the current temperature of t...
void setVPSSMgr(VPSSMgr *vp_ptr)
set the VPSS Mgr
Declarations for the virtual base class PDSS (pressure dependent standard state) which handles calcul...
virtual void calcDensity()
Calculate the density of the mixture using the partial molar volumes and mole fractions as input...
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...
virtual void _updateStandardStateThermo() const
Updates the standard state thermodynamic functions at the current T and P of the solution.
virtual void getStandardChemPotentials(doublereal *mu) const
Get the array of chemical potentials at unit activity for the species at their standard states at the...
virtual void getGibbs_RT_ref(doublereal *grt) const
Returns the vector of nondimensional Gibbs Free Energies of the reference state at the current temper...
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:761
virtual void getEnthalpy_RT_ref(doublereal *hrt) const
virtual doublereal pressure() const
Returns the current pressure of the phase.
virtual void getCp_R_ref(doublereal *cprt) const
Returns the vector of nondimensional constant pressure heat capacities of the reference state at the ...
virtual void getGibbs_RT(doublereal *grt) const
Get the nondimensional Gibbs functions for the species in their standard states at the current T and ...
virtual void getPureGibbs(doublereal *gpure) const
Get the Gibbs functions for the standard state of the species at the current T and P of the solution...
std::unique_ptr< VPSSMgr > m_VPSS_ptr
Pointer to the VPSS manager that calculates all of the standard state info efficiently.
virtual void getIntEnergy_RT(doublereal *urt) const
Returns the vector of nondimensional Internal Energies of the standard state species at the current T...
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:176
virtual void getdlnActCoeffdlnN_diag(doublereal *dlnActCoeffdlnN_diag) const
Get the array of log species mole number derivatives of the log activity coefficients.
virtual void initThermoXML(XML_Node &phaseNode, const std::string &id)
Import and initialize a ThermoPhase object using an XML tree.
virtual void getEntropy_R(doublereal *sr) const
Get the array of nondimensional Entropy functions for the standard state species at the current T and...
doublereal m_Pcurrent
Current value of the pressure - state variable.
Namespace for the Cantera kernel.
Definition: application.cpp:29
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 getEnthalpy_RT(doublereal *hrt) const
Get the nondimensional Enthalpy functions for the species at their standard states at the current T a...
virtual void setState_TP(doublereal T, doublereal pres)
Set the temperature and pressure at the same time.
virtual int standardStateConvention() const
This method returns the convention used in specification of the standard state, of which there are cu...