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