Cantera  2.0
PDSS_HKFT.h
Go to the documentation of this file.
1 /**
2  * @file PDSS_HKFT.h
3  * Declarations for the class PDSS_HKFT (pressure dependent standard state)
4  * which handles calculations for a single species in a phase using the
5  * HKFT standard state
6  * (see \ref pdssthermo and class \link Cantera::PDSS_HKFT PDSS_HKFT\endlink).
7  */
8 /*
9  * Copyright (2006) Sandia Corporation. Under the terms of
10  * Contract DE-AC04-94AL85000 with Sandia Corporation, the
11  * U.S. Government retains certain rights in this software.
12  */
13 
14 #ifndef CT_PDSS_HKFT_H
15 #define CT_PDSS_HKFT_H
16 
17 class WaterPropsIAPWS;
18 #include "PDSS.h"
19 
20 namespace Cantera
21 {
22 class XML_Node;
23 class VPStandardState;
24 class PDSS_Water;
25 class WaterProps;
26 
27 //! Class for pressure dependent standard states corresponding to
28 //! ionic solutes in electrolyte water.
29 /*!
30  *
31  * Virtual base class for calculation of the
32  * pressure dependent standard state for a single species
33  *
34  * Class %PDSS is the base class
35  * for a family of classes that compute properties of a set of
36  * species in their standard states at a range of temperatures
37  * and pressures. The independent variables for this object
38  * are temperature and pressure.
39  * The class may have a reference to a SpeciesThermo object
40  * which handles the calculation of the reference state temperature
41  * behavior of a subset of species.
42  *
43  * This class is analogous to the SpeciesThermoInterpType
44  * class, except that the standard state inherently incorporates
45  * the pressure dependence.
46  *
47  * The class operates on a setState temperature and pressure basis.
48  * It only recalculates the standard state when the setState functions
49  * for temperature and pressure are called
50  *
51  * @ingroup pdssthermo
52  */
53 class PDSS_HKFT : public PDSS
54 {
55 
56 public:
57  /**
58  * @name Constructors
59  * @{
60  */
61 
62  //! Constructor that initializes the object by examining the XML entries
63  //! from the ThermoPhase object
64  /*!
65  * This function calls the constructPDSS member function.
66  *
67  * @param tp Pointer to the ThermoPhase object pertaining to the phase
68  * @param spindex Species index of the species in the phase
69  */
70  PDSS_HKFT(VPStandardStateTP* tp, size_t spindex);
71 
72  //! Copy Constructor
73  /*!
74  * @param b object to be copied
75  */
76  PDSS_HKFT(const PDSS_HKFT& b);
77 
78  //! Assignment operator
79  /*!
80  * @param b Object to be copied
81  */
82  PDSS_HKFT& operator=(const PDSS_HKFT& b);
83 
84  //! Constructor that initializes the object by examining the input file
85  //! of the ThermoPhase object
86  /*!
87  * This function calls the constructPDSSFile member function.
88  *
89  * @param vptp_ptr Pointer to the ThermoPhase object pertaining to the phase
90  * @param spindex Species index of the species in the phase
91  * @param inputFile String name of the input file
92  * @param id String name of the phase in the input file. The default
93  * is the empty string, in which case the first phase in the
94  * file is used.
95  */
96  PDSS_HKFT(VPStandardStateTP* vptp_ptr, size_t spindex,
97  std::string inputFile, std::string id = "");
98 
99  //! Constructor that initializes the object by examining the input file
100  //! of the ThermoPhase object
101  /*!
102  * This function calls the constructPDSSXML member function.
103  *
104  * @param vptp_ptr Pointer to the ThermoPhase object pertaining to the phase
105  * @param spindex Species index of the species in the phase
106  * @param speciesNode Reference to the species XML tree.
107  * @param phaseRef Reference to the XML tree containing the phase information.
108  * @param spInstalled Boolean indicating whether the species is installed yet
109  * or not.
110  */
111  PDSS_HKFT(VPStandardStateTP* vptp_ptr, size_t spindex, const XML_Node& speciesNode,
112  const XML_Node& phaseRef, bool spInstalled);
113 
114  //! Destructor for the phase
115  virtual ~PDSS_HKFT();
116 
117  //! Duplicator
118  virtual PDSS* duplMyselfAsPDSS() const;
119 
120  /**
121  * @}
122  * @name Utilities
123  * @{
124  */
125 
126  /**
127  * @}
128  * @name Molar Thermodynamic Properties of the Species Standard State
129  * in the Solution
130  * @{
131  */
132 
133  /**
134  * @}
135  * @name Molar Thermodynamic Properties of the Solution --------------
136  * @{
137  */
138 
139  //! Return the molar enthalpy in units of J kmol-1
140  /*!
141  * Returns the species standard state enthalpy in J kmol-1 at the
142  * current temperature and pressure.
143  *
144  * @return returns the species standard state enthalpy in J kmol-1
145  */
146  virtual doublereal enthalpy_mole() const;
147 
148 #ifdef DEBUG_MODE
149  //! Return the molar enthalpy in units of J kmol-1
150  /*!
151  * Returns the species standard state enthalpy in J kmol-1 at the
152  * current temperature and pressure.
153  *
154  * Note this is just an extra routine to check the arithmetic
155  *
156  * @return returns the species standard state enthalpy in J kmol-1
157  */
158  doublereal enthalpy_mole2() const;
159 #endif
160 
161  //! Return the standard state molar enthalpy divided by RT
162  /*!
163  * Returns the species standard state enthalpy divided by RT at the
164  * current temperature and pressure.
165  *
166  * @return returns the species standard state enthalpy in unitless form
167  */
168  virtual doublereal enthalpy_RT() const;
169 
170  //! Return the molar internal Energy in units of J kmol-1
171  /*!
172  * Returns the species standard state internal Energy in J kmol-1 at the
173  * current temperature and pressure.
174  *
175  * @return returns the species standard state internal Energy in J kmol-1
176  */
177  virtual doublereal intEnergy_mole() const;
178 
179  //! Return the molar entropy in units of J kmol-1 K-1
180  /*!
181  * Returns the species standard state entropy in J kmol-1 K-1 at the
182  * current temperature and pressure.
183  *
184  * @return returns the species standard state entropy in J kmol-1 K-1
185  */
186  virtual doublereal entropy_mole() const;
187 
188  //! Return the molar gibbs free energy in units of J kmol-1
189  /*!
190  * Returns the species standard state gibbs free energy in J kmol-1 at the
191  * current temperature and pressure.
192  *
193  * @return returns the species standard state gibbs free energy in J kmol-1
194  */
195  virtual doublereal gibbs_mole() const;
196 
197  //! Return the molar const pressure heat capacity in units of J kmol-1 K-1
198  /*!
199  * Returns the species standard state Cp in J kmol-1 K-1 at the
200  * current temperature and pressure.
201  *
202  * @return returns the species standard state Cp in J kmol-1 K-1
203  */
204  virtual doublereal cp_mole() const;
205 
206  //! Return the molar const volume heat capacity in units of J kmol-1 K-1
207  /*!
208  * Returns the species standard state Cv in J kmol-1 K-1 at the
209  * current temperature and pressure.
210  *
211  * @return returns the species standard state Cv in J kmol-1 K-1
212  */
213  virtual doublereal cv_mole() const;
214 
215  //! Return the molar volume at standard state
216  /*!
217  * Returns the species standard state molar volume at the
218  * current temperature and pressure
219  *
220  * @return returns the standard state molar volume divided by R
221  * units are m**3 kmol-1.
222  */
223  virtual doublereal molarVolume() const;
224 
225  //! Return the standard state density at standard state
226  /*!
227  * Returns the species standard state density at the
228  * current temperature and pressure
229  *
230  * @return returns the standard state density
231  * units are kg m-3
232  */
233  virtual doublereal density() const;
234 
235  /**
236  * @}
237  * @name Properties of the Reference State of the Species
238  * in the Solution
239  * @{
240  */
241 
242 
243  //! Return the reference pressure for this phase.
244  doublereal refPressure() const {
245  return m_p0;
246  }
247 
248  //! Return the molar gibbs free energy divided by RT at reference pressure
249  /*!
250  * Returns the species reference state gibbs free energy divided by RT at the
251  * current temperature.
252  *
253  * @return returns the reference state gibbs free energy divided by RT
254  */
255  virtual doublereal gibbs_RT_ref() const;
256 
257  //! Return the molar enthalpy divided by RT at reference pressure
258  /*!
259  * Returns the species reference state enthalpy divided by RT at the
260  * current temperature.
261  *
262  * @return returns the reference state enthalpy divided by RT
263  */
264  virtual doublereal enthalpy_RT_ref() const;
265 
266  //! Return the molar entropy divided by R at reference pressure
267  /*!
268  * Returns the species reference state entropy divided by R at the
269  * current temperature.
270  *
271  * @return returns the reference state entropy divided by R
272  */
273  virtual doublereal entropy_R_ref() const;
274 
275  //! Return the molar heat capacity divided by R at reference pressure
276  /*!
277  * Returns the species reference state heat capacity divided by R at the
278  * current temperature.
279  *
280  * @return returns the reference state heat capacity divided by R
281  */
282  virtual doublereal cp_R_ref() const;
283 
284  //! Return the molar volume at reference pressure
285  /*!
286  * Returns the species reference state molar volume at the
287  * current temperature.
288  *
289  * @return returns the reference state molar volume divided by R
290  * units are m**3 kmol-1.
291  */
292  virtual doublereal molarVolume_ref() const;
293 
294  /**
295  * @}
296  * @name Mechanical Equation of State Properties
297  * @{
298  */
299 
300  //! Returns the pressure (Pa)
301  virtual doublereal pressure() const;
302 
303  //! Sets the pressure in the object
304  /*!
305  * Currently, this sets the pressure in the PDSS object.
306  * It is indeterminant what happens to the owning VPStandardStateTP
307  * object and to the VPSSMgr object.
308  *
309  * @param pres Pressure to be set (Pascal)
310  */
311  virtual void setPressure(doublereal pres);
312 
313  //! Set the internal temperature
314  /*!
315  * @param temp Temperature (Kelvin)
316  */
317  virtual void setTemperature(doublereal temp);
318 
319  //! Return the current stored temperature
320  doublereal temperature() const;
321 
322  //! Set the internal temperature and pressure
323  /*!
324  * @param temp Temperature (Kelvin)
325  * @param pres pressure (Pascals)
326  */
327  virtual void setState_TP(doublereal temp, doublereal pres);
328 
329  /**
330  * @}
331  * @name Miscellaneous properties of the standard state
332  * @{
333  */
334 
335  /// critical temperature
336  virtual doublereal critTemperature() const;
337 
338  /// critical pressure
339  virtual doublereal critPressure() const;
340 
341  /// critical density
342  virtual doublereal critDensity() const;
343 
344  /**
345  * @}
346  * @name Initialization of the Object
347  * @{
348  */
349 
350  //! Initialization routine for all of the shallow pointers
351  /*!
352  * This is a cascading call, where each level should call the
353  * the parent level.
354  *
355  * The initThermo() routines get called before the initThermoXML() routines
356  * from the constructPDSSXML() routine.
357  *
358  *
359  * Calls initPtrs();
360  */
361  virtual void initThermo();
362 
363  //! Initialization of a PDSS object using an
364  //! input XML file.
365  /*!
366  *
367  * This routine is a precursor to constructPDSSXML(XML_Node*)
368  * routine, which does most of the work.
369  *
370  * @param vptp_ptr Pointer to the Variable pressure %ThermoPhase object
371  * This object must have already been malloced.
372  *
373  * @param spindex Species index within the phase
374  *
375  * @param inputFile XML file containing the description of the
376  * phase
377  *
378  * @param id Optional parameter identifying the name of the
379  * phase. If none is given, the first XML
380  * phase element will be used.
381  */
382  void constructPDSSFile(VPStandardStateTP* vptp_ptr, size_t spindex,
383  std::string inputFile, std::string id);
384 
385  //! Initialization of a PDSS object using an xml tree
386  /*!
387  * This routine is a driver for the initialization of the
388  * object.
389  *
390  * basic logic:
391  * initThermo() (cascade)
392  * getStuff from species Part of XML file
393  * initThermoXML(phaseNode) (cascade)
394  *
395  * @param vptp_ptr Pointer to the Variable pressure %ThermoPhase object
396  * This object must have already been malloced.
397  *
398  * @param spindex Species index within the phase
399  *
400  * @param speciesNode XML Node containing the species information
401  *
402  * @param phaseNode Reference to the phase Information for the phase
403  * that owns this species.
404  *
405  * @param spInstalled Boolean indicating whether the species is
406  * already installed.
407  */
408  void constructPDSSXML(VPStandardStateTP* vptp_ptr, size_t spindex,
409  const XML_Node& speciesNode,
410  const XML_Node& phaseNode, bool spInstalled);
411 
412  //! Initialization routine for the PDSS object based on the phaseNode
413  /*!
414  * This is a cascading call, where each level should call the
415  * the parent level.
416  *
417  * @param phaseNode Reference to the phase Information for the phase
418  * that owns this species.
419  *
420  * @param id Optional parameter identifying the name of the
421  * phase. If none is given, the first XML
422  * phase element will be used.
423  */
424  virtual void initThermoXML(const XML_Node& phaseNode, std::string& id);
425 
426  //! Initialize or Reinitialize all shallow pointers in the object
427  /*!
428  * This command is called to reinitialize all shallow pointers in the
429  * object. It's needed for the duplicator capability
430  *
431  * @param vptp_ptr Pointer to the Variable pressure %ThermoPhase object
432  * This object must have already been malloced.
433  *
434  * @param vpssmgr_ptr Pointer to the variable pressure standard state
435  * calculator for this phase
436  *
437  * @param spthermo_ptr Pointer to the optional SpeciesThermo object
438  * that will handle the calculation of the reference
439  * state thermodynamic coefficients.
440  */
441  virtual void initAllPtrs(VPStandardStateTP* vptp_ptr, VPSSMgr* vpssmgr_ptr,
442  SpeciesThermo* spthermo_ptr);
443 
444  //! This utility function reports back the type of
445  //! parameterization and all of the parameters for the
446  //! species, index.
447  /*!
448  *
449  * The following parameters are reported
450  *
451  * - c[0] = m_deltaG_formation_tr_pr;
452  * - c[1] = m_deltaH_formation_tr_pr;
453  * - c[2] = m_Mu0_tr_pr;
454  * - c[3] = m_Entrop_tr_pr;
455  * - c[4] = m_a1;
456  * - c[5] = m_a2;
457  * - c[6] = m_a3;
458  * - c[7] = m_a4;
459  * - c[8] = m_c1;
460  * - c[9] = m_c2;
461  * - c[10] = m_omega_pr_tr;
462  * .
463  *
464  * @param kindex Species index
465  * @param type Integer type of the standard type
466  * @param c Vector of coefficients used to set the
467  * parameters for the standard state.
468  * @param minTemp output - Minimum temperature
469  * @param maxTemp output - Maximum temperature
470  * @param refPressure output - reference pressure (Pa).
471  *
472  */
473  virtual void reportParams(size_t& kindex, int& type, doublereal* const c,
474  doublereal& minTemp, doublereal& maxTemp,
475  doublereal& refPressure) const;
476 
477  //@}
478 
479 
480 private:
481 
482  //! Main routine that actually calculates the gibbs free energy difference
483  //! between the reference state at Tr, Pr and T,P
484  /*!
485  * This is eEqn. 59 in Johnson et al. (1992).
486  *
487  */
488  doublereal deltaG() const;
489 
490  //! Main routine that actually calculates the entropy difference
491  //! between the reference state at Tr, Pr and T,P
492  /*!
493  * This is Eqn. 61 in Johnson et al. (1992). Actually, there appears to
494  * be an error in the latter. This is a correction.
495  */
496  doublereal deltaS() const;
497 
498 #ifdef DEBUG_MODE
499  //! Routine that actually calculates the enthalpy difference
500  //! between the reference state at Tr, Pr and T,P
501  /*!
502  * This is an extra routine that was added to check the arithmetic
503  */
504  doublereal deltaH() const;
505 #endif
506 
507  //! Internal formula for the calculation of a_g()
508  /*!
509  * The output of this is in units of Angstroms
510  *
511  * @param temp Temperature (K)
512  *
513  * @param ifunc parameters specifying the desired information
514  * - 0 function value
515  * - 1 derivative wrt temperature
516  * - 2 2nd derivative wrt temperature
517  * - 3 derivative wrt pressure
518  */
519  doublereal ag(const doublereal temp, const int ifunc = 0) const;
520 
521  //! Internal formula for the calculation of b_g()
522  /*!
523  * the output of this is unitless
524  *
525  * @param temp Temperature (K)
526  *
527  * @param ifunc parameters specifying the desired information
528  * - 0 function value
529  * - 1 derivative wrt temperature
530  * - 2 2nd derivative wrt temperature
531  * - 3 derivative wrt pressure
532  */
533  doublereal bg(const doublereal temp, const int ifunc = 0) const;
534 
535  //! function g appearing in the formulation
536  /*!
537  * Function g appearing in the Johnson et al formulation
538  *
539  * @param temp Temperature kelvin
540  * @param pres Pressure (pascal)
541  * @param ifunc parameters specifying the desired information
542  * - 0 function value
543  * - 1 derivative wrt temperature
544  * - 2 2nd derivative wrt temperature
545  * - 3 derivative wrt pressure
546  */
547  doublereal g(const doublereal temp, const doublereal pres, const int ifunc = 0) const;
548 
549  //! Difference function f appearing in the formulation
550  /*!
551  * Function f appearing in the Johnson et al formulation of omega_j
552  * Eqn. 33 ref
553  *
554  * @param temp Temperature kelvin
555  * @param pres Pressure (pascal)
556  * @param ifunc parameters specifying the desired information
557  * - 0 function value
558  * - 1 derivative wrt temperature
559  * - 2 2nd derivative wrt temperature
560  * - 3 derivative wrt pressure
561  */
562  doublereal f(const doublereal temp, const doublereal pres, const int ifunc = 0) const;
563 
564  //! Evaluate the Gstar value appearing in the HKFT formulation
565  /*!
566  *
567  * @param temp Temperature kelvin
568  * @param pres Pressure (pascal)
569  * @param ifunc parameters specifying the desired information
570  * - 0 function value
571  * - 1 derivative wrt temperature
572  * - 2 2nd derivative wrt temperature
573  * - 3 derivative wrt pressure
574  */
575  doublereal gstar(const doublereal temp, const doublereal pres,
576  const int ifunc = 0) const;
577 
578  //! Function to look up Element Free Energies
579  /*!
580  *
581  * This static function looks up the argument string in the
582  * element database and returns the associated 298 K Gibbs Free energy
583  * of the element in its stable state
584  *
585  * @param elemName String. Only the first 3 characters are significant
586  *
587  * @return
588  * Return value contains the Gibbs free energy for that element
589  *
590  * @exception CanteraError
591  * If a match is not found, a CanteraError is thrown as well
592  */
593  doublereal LookupGe(const std::string& elemName);
594 
595  //! Translate a Gibbs free energy of formation value to a NIST-based Chemical potential
596  /*!
597  * Internally, this function is used to translate the input value,
598  * m_deltaG_formation_tr_pr,
599  * to the internally stored value, m_Mu0_tr_pr.
600  */
601  void convertDGFormation();
602 
603 private:
604  //! Water standard state calculator
605  /*!
606  * derived from the equation of state for water.
607  * This object doesn't own the object. Just a shallow pointer.
608  */
610 
611  //! density of standard-state water
612  /*!
613  * internal temporary variable
614  */
615  mutable doublereal m_densWaterSS;
616 
617  //! Pointer to the water property calculator
619 
620  //! Born coefficient for the current ion or species
621  doublereal m_born_coeff_j;
622 
623  //! Electrostatic radii
624  doublereal m_r_e_j;
625 
626  //! Input value of deltaG of Formation at Tr and Pr (cal gmol-1)
627  /*!
628  * Tr = 298.15 Pr = 1 atm
629  *
630  * This is the delta G for the formation reaction of the
631  * ion from elements in their stable state at Tr, Pr.
632  */
634 
635  //! Input value of deltaH of Formation at Tr and Pr (cal gmol-1)
636  /*!
637  * Tr = 298.15 Pr = 1 atm
638  *
639  * This is the delta H for the formation reaction of the
640  * ion from elements in their stable state at Tr, Pr.
641  */
643 
644  //! Value of the Absolute Gibbs Free Energy NIST scale at T_r and P_r
645  /*!
646  * This is the NIST scale value of Gibbs free energy at T_r = 298.15
647  * and P_r = 1 atm.
648  *
649  * J kmol-1
650  */
651  doublereal m_Mu0_tr_pr;
652 
653  //! Input value of S_j at Tr and Pr (cal gmol-1 K-1)
654  /*!
655  * Tr = 298.15 Pr = 1 atm
656  */
657  doublereal m_Entrop_tr_pr;
658 
659  //! Input a1 coefficient (cal gmol-1 bar-1)
660  doublereal m_a1;
661 
662  //! Input a2 coefficient (cal gmol-1)
663  doublereal m_a2;
664 
665  //! Input a3 coefficient (cal K gmol-1 bar-1)
666  doublereal m_a3;
667 
668  //! Input a4 coefficient (cal K gmol-1)
669  doublereal m_a4;
670 
671  //! Input c1 coefficient (cal gmol-1 K-1)
672  doublereal m_c1;
673 
674  //! Input c2 coefficient (cal K gmol-1)
675  doublereal m_c2;
676 
677  //! Input omega_pr_tr coefficient(cal gmol-1)
678  doublereal m_omega_pr_tr;
679 
680  //! y = dZdT = 1/(esp*esp) desp/dT at 298.15 and 1 bar
681  doublereal m_Y_pr_tr;
682 
683  //! Z = -1 / relEpsilon at 298.15 and 1 bar
684  doublereal m_Z_pr_tr;
685 
686  //! Reference pressure is 1 atm in units of bar= 1.0132
687  doublereal m_presR_bar;
688 
689  //! small value that is not quite zero
690  doublereal m_domega_jdT_prtr;
691 
692  //! Charge of the ion
693  doublereal m_charge_j;
694 
695 };
696 
697 }
698 
699 #endif
700 
701 
702