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