00001 /** 00002 * @file VPStandardStateTP.h 00003 * Header file for a derived class of ThermoPhase that handles 00004 * variable pressure standard state methods for calculating 00005 * thermodynamic properties (see \ref thermoprops and 00006 * class \link Cantera::VPStandardStateTP VPStandardStateTP\endlink). 00007 * 00008 * These include most of the 00009 * methods for calculating liquid electrolyte thermodynamics. 00010 */ 00011 /* 00012 * Copywrite (2005) Sandia Corporation. Under the terms of 00013 * Contract DE-AC04-94AL85000 with Sandia Corporation, the 00014 * U.S. Government retains certain rights in this software. 00015 */ 00016 /* 00017 * $Date: 2010-01-17 12:05:46 -0500 (Sun, 17 Jan 2010) $ 00018 * $Revision: 385 $ 00019 */ 00020 00021 #ifndef CT_VPSTANDARDSTATETP_H 00022 #define CT_VPSTANDARDSTATETP_H 00023 00024 #include "ThermoPhase.h" 00025 #include "VPSSMgr.h" 00026 00027 namespace Cantera { 00028 00029 class XML_Node; 00030 class PDSS; 00031 00032 /** 00033 * @ingroup thermoprops 00034 * 00035 * This is a filter class for ThermoPhase that implements some prepatory 00036 * steps for efficiently handling 00037 * a variable pressure standard state for species. 00038 * 00039 * Several concepts are introduced. The first concept is there are temporary 00040 * variables for holding the species standard state values 00041 * of Cp, H, S, G, and V at the 00042 * last temperature and pressure called. These functions are not recalculated 00043 * if a new call is made using the previous temperature and pressure. Currently, 00044 * these variables and the calculation method are handled by the VPSSMgr class, 00045 * for which VPStandardStateTP owns a pointer to. 00046 * 00047 * To support the above functionality, pressure and temperature variables, 00048 * m_Plast_ss and m_Tlast_ss, are kept which store the last pressure and temperature 00049 * used in the evaluation of standard state properties. 00050 * 00051 * This class is usually used for nearly incompressible phases. For those phases, it 00052 * makes sense to change the equation of state independent variable from 00053 * density to pressure. The variable m_Pcurrent contains the current value of the 00054 * pressure within the phase. 00055 * 00056 * @todo 00057 * Put some teeth into this level by overloading the setDensity() function. It should 00058 * now throw an exception. Instead, setPressure routines should calculate the 00059 * solution density and then call State:setDensity() directly. 00060 * 00061 * @nosubgrouping 00062 */ 00063 class VPStandardStateTP : public ThermoPhase { 00064 00065 public: 00066 00067 /*! 00068 * 00069 * @name Constructors and Duplicators for %VPStandardStateTP 00070 * 00071 */ 00072 /// Constructor. 00073 VPStandardStateTP(); 00074 00075 //! Copy Constructor. 00076 /*! 00077 * @param b Object to be copied 00078 */ 00079 VPStandardStateTP(const VPStandardStateTP &b); 00080 00081 //! Assignment operator 00082 /*! 00083 * @param b Object to be copied 00084 */ 00085 VPStandardStateTP& operator=(const VPStandardStateTP &b); 00086 00087 //! Destructor. 00088 virtual ~VPStandardStateTP(); 00089 00090 /* 00091 * Duplication routine 00092 */ 00093 virtual ThermoPhase *duplMyselfAsThermoPhase() const; 00094 00095 //@} 00096 00097 /** 00098 * @name Utilities (VPStandardStateTP) 00099 */ 00100 //@{ 00101 /** 00102 * Equation of state type flag. The base class returns 00103 * zero. Subclasses should define this to return a unique 00104 * non-zero value. Constants defined for this purpose are 00105 * listed in mix_defs.h. 00106 */ 00107 virtual int eosType() const { return 0; } 00108 00109 //! This method returns the convention used in specification 00110 //! of the standard state, of which there are currently two, 00111 //! temperature based, and variable pressure based. 00112 /*! 00113 * Currently, there are two standard state conventions: 00114 * - Temperature-based activities 00115 * cSS_CONVENTION_TEMPERATURE 0 00116 * - default 00117 * 00118 * - Variable Pressure and Temperature -based activities 00119 * cSS_CONVENTION_VPSS 1 00120 */ 00121 virtual int standardStateConvention() const; 00122 00123 //! Get the array of log concentration-like derivatives of the 00124 //! log activity coefficients 00125 /*! 00126 * This function is a virtual method. For ideal mixtures 00127 * (unity activity coefficients), this can return zero. 00128 * Implementations should take the derivative of the 00129 * logarithm of the activity coefficient with respect to the 00130 * logarithm of the concentration-like variable (i.e. mole fraction, 00131 * molality, etc.) that represents the standard state. 00132 * This quantity is to be used in conjunction with derivatives of 00133 * that concentration-like variable when the derivative of the chemical 00134 * potential is taken. 00135 * 00136 * units = dimensionless 00137 * 00138 * @param dlnActCoeffdlnC Output vector of derivatives of the 00139 * log Activity Coefficients. length = m_kk 00140 */ 00141 virtual void getdlnActCoeffdlnC(doublereal *dlnActCoeffdlnC) const { 00142 err("getdlnActCoeffdlnC"); 00143 } 00144 00145 00146 //@} 00147 /// @name Partial Molar Properties of the Solution (VPStandardStateTP) 00148 //@{ 00149 00150 00151 //! Get the array of non-dimensional species chemical potentials 00152 //! These are partial molar Gibbs free energies. 00153 /*! 00154 * \f$ \mu_k / \hat R T \f$. 00155 * Units: unitless 00156 * 00157 * We close the loop on this function, here, calling 00158 * getChemPotentials() and then dividing by RT. No need for child 00159 * classes to handle. 00160 * 00161 * @param mu Output vector of non-dimensional species chemical potentials 00162 * Length: m_kk. 00163 */ 00164 void getChemPotentials_RT(doublereal* mu) const; 00165 00166 //@} 00167 00168 /*! 00169 * @name Properties of the Standard State of the Species in the Solution 00170 * (VPStandardStateTP) 00171 * 00172 * Within VPStandardStateTP, these properties are calculated via a common routine, 00173 * _updateStandardStateThermo(), 00174 * which must be overloaded in inherited objects. 00175 * The values are cached within this object, and are not recalculated unless 00176 * the temperature or pressure changes. 00177 */ 00178 //@{ 00179 00180 //!Get the array of chemical potentials at unit activity. 00181 /*! 00182 * These are the standard state chemical potentials \f$ \mu^0_k(T,P) 00183 * \f$. The values are evaluated at the current temperature and pressure. 00184 * 00185 * @param mu Output vector of standard state chemical potentials. 00186 * length = m_kk. units are J / kmol. 00187 */ 00188 virtual void getStandardChemPotentials(doublereal* mu) const; 00189 00190 /** 00191 * Get the nondimensional Enthalpy functions for the species 00192 * at their standard states at the current 00193 * <I>T</I> and <I>P</I> of the solution. 00194 * 00195 * @param hrt Output vector of standard state enthalpies. 00196 * length = m_kk. units are unitless. 00197 */ 00198 virtual void getEnthalpy_RT(doublereal* hrt) const; 00199 00200 /** 00201 * Get the array of nondimensional Enthalpy functions for the 00202 * standard state species 00203 * at the current <I>T</I> and <I>P</I> of the solution. 00204 * 00205 * @param sr Output vector of nondimensional standard state 00206 * entropies. length = m_kk. 00207 */ 00208 virtual void getEntropy_R(doublereal* sr) const; 00209 00210 /** 00211 * Get the nondimensional Gibbs functions for the species 00212 * at their standard states of solution at the current T and P 00213 * of the solution. 00214 * 00215 * @param grt Output vector of nondimensional standard state 00216 * Gibbs free energies. length = m_kk. 00217 */ 00218 virtual void getGibbs_RT(doublereal* grt) const; 00219 00220 00221 //! Get the nondimensional Gibbs functions for the standard 00222 //! state of the species at the current T and P. 00223 /*! 00224 * (Note resolved at this level) 00225 * 00226 * @param gpure Output vector of standard state 00227 * Gibbs free energies. length = m_kk. 00228 * units are J/kmol. 00229 * 00230 * @todo This could be eliminated. It doesn't fit into the current 00231 * naming convention. 00232 */ 00233 void getPureGibbs(doublereal* gpure) const; 00234 00235 /** 00236 * Returns the vector of nondimensional 00237 * internal Energies of the standard state at the current temperature 00238 * and pressure of the solution for each species. 00239 * \f[ 00240 * u^{ss}_k(T,P) = h^{ss}_k(T) - P * V^{ss}_k 00241 * \f] 00242 * 00243 * @param urt Output vector of nondimensional standard state 00244 * internal energies. length = m_kk. 00245 */ 00246 virtual void getIntEnergy_RT(doublereal *urt) const; 00247 00248 /** 00249 * Get the nondimensional Heat Capacities at constant 00250 * pressure for the standard state of the species 00251 * at the current T and P. 00252 * 00253 * This is redefined here to call the internal function, _updateStandardStateThermo(), 00254 * which calculates all standard state properties at the same time. 00255 * 00256 * @param cpr Output vector containing the 00257 * the nondimensional Heat Capacities at constant 00258 * pressure for the standard state of the species. 00259 * Length: m_kk. 00260 */ 00261 virtual void getCp_R(doublereal* cpr) const; 00262 00263 00264 //! Get the molar volumes of each species in their standard 00265 //! states at the current 00266 //! <I>T</I> and <I>P</I> of the solution. 00267 /*! 00268 * units = m^3 / kmol 00269 * 00270 * This is redefined here to call the internal function, _updateStandardStateThermo(), 00271 * which calculates all standard state properties at the same time. 00272 * 00273 * @param vol Output vector of species volumes. length = m_kk. 00274 * units = m^3 / kmol 00275 */ 00276 virtual void getStandardVolumes(doublereal *vol) const; 00277 00278 00279 //! Set the temperature of the phase 00280 /*! 00281 * Currently this passes down to setState_TP(). It does not 00282 * make sense to calculate the standard state without first 00283 * setting T and P. 00284 * 00285 * @param temp Temperature (kelvin) 00286 */ 00287 virtual void setTemperature(const doublereal temp); 00288 00289 00290 //! Set the internally storred pressure (Pa) at constant 00291 //! temperature and composition 00292 /*! 00293 * Currently this passes down to setState_TP(). It does not 00294 * make sense to calculate the standard state without first 00295 * setting T and P. 00296 * 00297 * @param p input Pressure (Pa) 00298 */ 00299 virtual void setPressure(doublereal p); 00300 00301 protected: 00302 /** 00303 * Calculate the density of the mixture using the partial 00304 * molar volumes and mole fractions as input 00305 * 00306 * The formula for this is 00307 * 00308 * \f[ 00309 * \rho = \frac{\sum_k{X_k W_k}}{\sum_k{X_k V_k}} 00310 * \f] 00311 * 00312 * where \f$X_k\f$ are the mole fractions, \f$W_k\f$ are 00313 * the molecular weights, and \f$V_k\f$ are the pure species 00314 * molar volumes. 00315 * 00316 * Note, the basis behind this formula is that in an ideal 00317 * solution the partial molar volumes are equal to the pure 00318 * species molar volumes. We have additionally specified 00319 * in this class that the pure species molar volumes are 00320 * independent of temperature and pressure. 00321 * 00322 * NOTE: This is a non-virtual function, which is not a 00323 * member of the ThermoPhase base class. 00324 */ 00325 virtual void calcDensity(); 00326 00327 public: 00328 //! Set the temperature and pressure at the same time 00329 /*! 00330 * Note this function triggers a reevalulation of the standard 00331 * state quantities. 00332 * 00333 * @param T temperature (kelvin) 00334 * @param pres pressure (pascal) 00335 */ 00336 virtual void setState_TP(doublereal T, doublereal pres); 00337 00338 //! Returns the current pressure of the phase 00339 /*! 00340 * The pressure is an independent variable in this phase. Its current value 00341 * is storred in the object VPStandardStateTP. 00342 * 00343 * @return return the pressure in pascals. 00344 */ 00345 doublereal pressure() const { 00346 return m_Pcurrent; 00347 } 00348 00349 protected: 00350 00351 //! Updates the standard state thermodynamic functions at the current T and P of the solution. 00352 /*! 00353 * @internal 00354 * 00355 * If m_useTmpStandardStateStorage is true, 00356 * this function must be called for every call to functions in this class. 00357 * 00358 * This function is responsible for updating the following internal members, 00359 * when m_useTmpStandardStateStorage is true. 00360 * 00361 * - m_hss_RT; 00362 * - m_cpss_R; 00363 * - m_gss_RT; 00364 * - m_sss_R; 00365 * - m_Vss 00366 * 00367 * This function doesn't check to see if the temperature or pressure 00368 * has changed. It automatically assumes that it has changed. 00369 * If m_useTmpStandardStateStorage is not true, this function may be 00370 * required to be called by child classes to update internal member data.. 00371 * 00372 */ 00373 virtual void _updateStandardStateThermo() const; 00374 00375 public: 00376 00377 //! Updates the standard state thermodynamic functions at the current T and P of the solution. 00378 /*! 00379 * 00380 * If m_useTmpStandardStateStorage is true, 00381 * this function must be called for every call to functions in this 00382 * class. It checks to see whether the temperature or pressure has changed and 00383 * thus the ss thermodynamics functions for all of the species 00384 * must be recalculated. 00385 * 00386 * This function is responsible for updating the following internal members, 00387 * when m_useTmpStandardStateStorage is true. 00388 * 00389 * - m_hss_RT; 00390 * - m_cpss_R; 00391 * - m_gss_RT; 00392 * - m_sss_R; 00393 * - m_Vss 00394 * 00395 * If m_useTmpStandardStateStorage is not true, this function may be 00396 * required to be called by child classes to update internal member data. 00397 * 00398 */ 00399 virtual void updateStandardStateThermo() const; 00400 00401 //@} 00402 /// @name Thermodynamic Values for the Species Reference States (VPStandardStateTP) 00403 /*! 00404 * There are also temporary 00405 * variables for holding the species reference-state values of Cp, H, S, and V at the 00406 * last temperature and reference pressure called. These functions are not recalculated 00407 * if a new call is made using the previous temperature. 00408 * All calculations are done within the routine _updateRefStateThermo(). 00409 */ 00410 //@{ 00411 00412 00413 //! Returns the vector of nondimensional 00414 //! enthalpies of the reference state at the current temperature 00415 //! of the solution and the reference pressure for the species. 00416 /*! 00417 * @param hrt Output vector contains the nondimensional enthalpies 00418 * of the reference state of the species 00419 * length = m_kk, units = dimensionless. 00420 */ 00421 virtual void getEnthalpy_RT_ref(doublereal *hrt) const; 00422 00423 #ifdef H298MODIFY_CAPABILITY 00424 //! Modify the value of the 298 K Heat of Formation of the standard state of 00425 //! one species in the phase (J kmol-1) 00426 /*! 00427 * The 298K heat of formation is defined as the enthalpy change to create the standard state 00428 * of the species from its constituent elements in their standard states at 298 K and 1 bar. 00429 * 00430 * @param k Index of the species 00431 * @param Hf298New Specify the new value of the Heat of Formation at 298K and 1 bar. 00432 * units = J/kmol. 00433 */ 00434 void modifyOneHf298SS(const int k, const doublereal Hf298New); 00435 #endif 00436 00437 //! Returns the vector of nondimensional 00438 //! Gibbs free energies of the reference state at the current temperature 00439 //! of the solution and the reference pressure for the species. 00440 /*! 00441 * 00442 * @param grt Output vector contains the nondimensional Gibbs free energies 00443 * of the reference state of the species 00444 * length = m_kk, units = dimensionless. 00445 */ 00446 virtual void getGibbs_RT_ref(doublereal *grt) const; 00447 00448 protected: 00449 const vector_fp & Gibbs_RT_ref() const; 00450 public: 00451 /*! 00452 * Returns the vector of the 00453 * gibbs function of the reference state at the current temperature 00454 * of the solution and the reference pressure for the species. 00455 * units = J/kmol 00456 * 00457 * @param g Output vector contain the Gibbs free energies 00458 * of the reference state of the species 00459 * length = m_kk, units = J/kmol. 00460 */ 00461 virtual void getGibbs_ref(doublereal *g) const; 00462 00463 /*! 00464 * Returns the vector of nondimensional 00465 * entropies of the reference state at the current temperature 00466 * of the solution and the reference pressure for the species. 00467 * 00468 * @param er Output vector contain the nondimensional entropies 00469 * of the species in their reference states 00470 * length: m_kk, units: dimensionless. 00471 */ 00472 virtual void getEntropy_R_ref(doublereal *er) const; 00473 00474 /*! 00475 * Returns the vector of nondimensional 00476 * constant pressure heat capacities of the reference state 00477 * at the current temperature of the solution 00478 * and reference pressure for the species. 00479 * 00480 * @param cprt Output vector contains the nondimensional heat capacities 00481 * of the species in their reference states 00482 * length: m_kk, units: dimensionless. 00483 */ 00484 virtual void getCp_R_ref(doublereal *cprt) const; 00485 00486 //! Get the molar volumes of the species reference states at the current 00487 //! <I>T</I> and <I>P_ref</I> of the solution. 00488 /*! 00489 * units = m^3 / kmol 00490 * 00491 * @param vol Output vector containing the standard state volumes. 00492 * Length: m_kk. 00493 */ 00494 virtual void getStandardVolumes_ref(doublereal *vol) const; 00495 00496 protected: 00497 00498 00499 00500 //@} 00501 00502 00503 public: 00504 00505 //! @name Initialization Methods - For Internal use (VPStandardState) 00506 /*! 00507 * The following methods are used in the process of constructing 00508 * the phase and setting its parameters from a specification in an 00509 * input file. They are not normally used in application programs. 00510 * To see how they are used, see files importCTML.cpp and 00511 * ThermoFactory.cpp. 00512 */ 00513 //@{ 00514 00515 /** 00516 * Set equation of state parameter values from XML 00517 * entries. This method is called by function importPhase in 00518 * file importCTML.cpp when processing a phase definition in 00519 * an input file. It should be overloaded in subclasses to set 00520 * any parameters that are specific to that particular phase 00521 * model. 00522 * 00523 * @param eosdata An XML_Node object corresponding to 00524 * the "thermo" entry for this phase in the input file. 00525 */ 00526 virtual void setParametersFromXML(const XML_Node& eosdata) {} 00527 00528 //! @internal Initialize the object 00529 /*! 00530 * This method is provided to allow 00531 * subclasses to perform any initialization required after all 00532 * species have been added. For example, it might be used to 00533 * resize internal work arrays that must have an entry for 00534 * each species. The base class implementation does nothing, 00535 * and subclasses that do not require initialization do not 00536 * need to overload this method. When importing a CTML phase 00537 * description, this method is called after calling installSpecies() 00538 * for each species in the phase. It's called before calling 00539 * initThermoXML() for the phase. Therefore, it's the correct 00540 * place for initializing vectors which have lengths equal to the 00541 * number of species. 00542 * 00543 * @see importCTML.cpp 00544 */ 00545 virtual void initThermo(); 00546 00547 //! Initialize a ThermoPhase object, potentially reading activity 00548 //! coefficient information from an XML database. 00549 /*! 00550 * This routine initializes the lengths in the current object and 00551 * then calls the parent routine. 00552 * This method is provided to allow 00553 * subclasses to perform any initialization required after all 00554 * species have been added. For example, it might be used to 00555 * resize internal work arrays that must have an entry for 00556 * each species. The base class implementation does nothing, 00557 * and subclasses that do not require initialization do not 00558 * need to overload this method. When importing a CTML phase 00559 * description, this method is called just prior to returning 00560 * from function importPhase(). 00561 * 00562 * @param phaseNode This object must be the phase node of a 00563 * complete XML tree 00564 * description of the phase, including all of the 00565 * species data. In other words while "phase" must 00566 * point to an XML phase object, it must have 00567 * sibling nodes "speciesData" that describe 00568 * the species in the phase. 00569 * @param id ID of the phase. If nonnull, a check is done 00570 * to see if phaseNode is pointing to the phase 00571 * with the correct id. 00572 */ 00573 virtual void initThermoXML(XML_Node& phaseNode, std::string id); 00574 00575 00576 //! set the VPSS Mgr 00577 /*! 00578 * @param vp_ptr Pointer to the manager 00579 */ 00580 void setVPSSMgr(VPSSMgr *vp_ptr); 00581 00582 //! Return a pointer to the VPSSMgr for this phase 00583 /*! 00584 * @return Returns a pointer to the VPSSMgr for this phase 00585 */ 00586 VPSSMgr *provideVPSSMgr(); 00587 00588 void createInstallPDSS(int k, const XML_Node& s, const XML_Node * phaseNode_ptr); 00589 00590 PDSS* providePDSS(int k); 00591 const PDSS* providePDSS(int k) const; 00592 00593 private: 00594 //! @internal Initialize the internal lengths in this object. 00595 /*! 00596 * Note this is not a virtual function. 00597 */ 00598 void initLengths(); 00599 00600 //@} 00601 00602 protected: 00603 00604 //! Current value of the pressure - state variable 00605 /*! 00606 * Because we are now using the pressure as a state variable, we need to carry it 00607 * along within this object 00608 * 00609 * units = Pascals 00610 */ 00611 doublereal m_Pcurrent; 00612 00613 //! The last temperature at which the standard statethermodynamic properties were calculated at. 00614 mutable doublereal m_Tlast_ss; 00615 00616 //! The last pressure at which the Standard State thermodynamic 00617 //! properties were calculated at. 00618 mutable doublereal m_Plast_ss; 00619 00620 /*! 00621 * Reference pressure (Pa) must be the same for all species 00622 * - defaults to OneAtm 00623 */ 00624 doublereal m_P0; 00625 00626 // -> suggest making this private! 00627 protected: 00628 00629 //! Pointer to the VPSS manager that calculates all of the standard state 00630 //! info efficiently. 00631 mutable VPSSMgr *m_VPSS_ptr; 00632 00633 //! Storage for the PDSS objects for the species 00634 /*! 00635 * Storage is in species index order. 00636 * VPStandardStateTp owns each of the objects. 00637 * Copy operations are deep. 00638 */ 00639 std::vector<PDSS *> m_PDSS_storage; 00640 00641 00642 private: 00643 00644 //! VPStandardStateTP has its own err routine 00645 /*! 00646 * @param msg Error message string 00647 */ 00648 doublereal err(std::string msg) const; 00649 00650 }; 00651 } 00652 00653 #endif