00001 /** 00002 * @file WaterSSTP.h 00003 * Declares a %ThermoPhase class consisting of pure water (see \ref thermoprops 00004 * and class \link Cantera::WaterSSTP WaterSSTP\endlink). 00005 */ 00006 /* 00007 * Copywrite (2006) Sandia Corporation. Under the terms of 00008 * Contract DE-AC04-94AL85000 with Sandia Corporation, the 00009 * U.S. Government retains certain rights in this software. 00010 */ 00011 /* 00012 * $Id: WaterSSTP.h 384 2010-01-16 18:57:05Z hkmoffa $ 00013 */ 00014 00015 #ifndef CT_WATERSSTP_H 00016 #define CT_WATERSSTP_H 00017 00018 #include "SingleSpeciesTP.h" 00019 00020 00021 namespace Cantera { 00022 00023 class WaterPropsIAPWS; 00024 class WaterProps; 00025 //! Class for single-component water. This is designed to cover just the 00026 //! liquid part of water. 00027 /*! 00028 * The reference is W. Wagner, A. Prub, "The IAPWS Formulation 1995 for the Themodynamic 00029 * Properties of Ordinary Water Substance for General and Scientific Use," 00030 * J. Phys. Chem. Ref. Dat, 31, 387, 2002. 00031 * 00032 * <HR> 00033 * <H2> Specification of Species Standard %State Properties </H2> 00034 * <HR> 00035 * 00036 * The offsets used in the steam tables are different than NIST's. 00037 * They assume u_liq(TP) = 0.0, s_liq(TP) = 0.0, where TP is the 00038 * triple point conditions: 00039 * 00040 * - u(273.16, rho) = 0.0 00041 * - s(273.16, rho) = 0.0 00042 * - psat(273.16) = 611.655 Pascal 00043 * - rho(273.16, psat) = 999.793 kg m-3 00044 * 00045 * These "steam table" assumptions are used by the WaterPropsIAPWS class. 00046 * Therefore, offsets must be calculated to make the thermodynamic 00047 * properties calculated within this class to be consistent with 00048 * thermo properties within Cantera. 00049 * 00050 * The thermodynamic base state for water is set to the NIST basis here 00051 * by specifying constants, #EW_Offset and #SW_Offset, one for energy 00052 * quantities and one for entropy quantities. The offsets are 00053 * specified so that the following properties hold: 00054 * 00055 * - Delta_Hfo_idealgas(298.15) = -241.826 kJ/gmol 00056 * - So_idealgas(298.15, 1bar) = 188.835 J/gmolK 00057 * 00058 * ref -> (http://webbook.nist.gov) 00059 * 00060 * The "o" here refers to a hypothetical ideal gas state. The way 00061 * we achieve this in practice is to evaluate at a very low pressure 00062 * and then use the theoretical ideal gas results to scale up to 00063 * higher pressures: 00064 * 00065 * Ho(1bar) = H(P0) 00066 * 00067 * So(1bar) = S(P0) + RT ln(1bar/P0) 00068 * 00069 * <HR> 00070 * <H2> %Application within %Kinetics Managers </H2> 00071 * <HR> 00072 * 00073 * This is unimplemented. 00074 * 00075 * <HR> 00076 * <H2> Instantiation of the Class </H2> 00077 * <HR> 00078 * 00079 * The constructor for this phase is NOT located in the default ThermoFactory 00080 * for %Cantera. However, a new %WaterSSTP object may be created by 00081 * the following code snippets, combined with an XML file given in the 00082 * XML example section. 00083 * 00084 * @code 00085 * WaterSSTP *w = new WaterSSTP("waterSSTPphase.xml",""); 00086 * @endcode 00087 * 00088 * or 00089 * 00090 * @code 00091 * char iFile[80], file_ID[80]; 00092 * strcpy(iFile, "waterSSTPphase.xml"); 00093 * sprintf(file_ID,"%s#water", iFile); 00094 * XML_Node *xm = get_XML_NameID("phase", file_ID, 0); 00095 * WaterSSTP *w = new WaterSSTP(*xm); 00096 * @endcode 00097 * 00098 * or by the following call to importPhase(): 00099 * 00100 * @code 00101 * char iFile[80], file_ID[80]; 00102 * strcpy(iFile, "waterSSTPphase.xml"); 00103 * sprintf(file_ID,"%s#water", iFile); 00104 * XML_Node *xm = get_XML_NameID("phase", file_ID, 0); 00105 * WaterSSTP water; 00106 * importPhase(*xm, &water); 00107 * @endcode 00108 * 00109 * <HR> 00110 * <H2> XML Example </H2> 00111 * <HR> 00112 * 00113 * An example of an XML Element named phase setting up a WaterSSTP object with 00114 * id "water" is given below. 00115 * 00116 * @verbatim 00117 <!-- phase water --> 00118 <phase dim="3" id="water"> 00119 <elementArray datasrc="elements.xml">O H </elementArray> 00120 <speciesArray datasrc="#species_data">H2O</speciesArray> 00121 <state> 00122 <temperature units="K">300.0</temperature> 00123 <pressure units="Pa">101325.0</pressure> 00124 </state> 00125 <thermo model="PureLiquidWater"/> 00126 <kinetics model="none"/> 00127 </phase> 00128 @endverbatim 00129 * 00130 * Note the model "PureLiquidWater" indicates the usage of the WaterSSTP object. 00131 * 00132 * @ingroup thermoprops 00133 * 00134 */ 00135 class WaterSSTP : public SingleSpeciesTP { 00136 00137 public: 00138 00139 //! Base constructor 00140 WaterSSTP(); 00141 00142 //! Copy constructor 00143 WaterSSTP(const WaterSSTP &); 00144 00145 //! Assignment operator 00146 WaterSSTP& operator=(const WaterSSTP&); 00147 00148 //! Full constructor for a water phase 00149 /*! 00150 * @param inputFile String name of the input file 00151 * @param id string id of the phase name 00152 */ 00153 WaterSSTP(std::string inputFile, std::string id = ""); 00154 00155 //! Full constructor for a water phase 00156 /*! 00157 * @param phaseRef XML node referencing the water phase. 00158 * @param id string id of the phase name 00159 */ 00160 WaterSSTP(XML_Node& phaseRef, std::string id = ""); 00161 00162 //! Destructor 00163 virtual ~WaterSSTP(); 00164 00165 //! Duplicator from a ThermoPhase object 00166 ThermoPhase *duplMyselfAsThermoPhase() const; 00167 00168 /** 00169 * 00170 * @name Utilities 00171 * @{ 00172 */ 00173 virtual int eosType() const { return -1; } 00174 00175 /** 00176 * @} 00177 * @name Molar Thermodynamic Properties of the Solution -------------- 00178 * @{ 00179 */ 00180 00181 virtual doublereal cv_mole() const; 00182 00183 //@} 00184 /// @name Mechanical Equation of State Properties --------------------- 00185 //@{ 00186 00187 virtual doublereal pressure() const; 00188 virtual void setPressure(doublereal p); 00189 00190 //! Returns the isothermal compressibility. Units: 1/Pa. 00191 /*! 00192 * The isothermal compressibility is defined as 00193 * \f[ 00194 * \kappa_T = -\frac{1}{v}\left(\frac{\partial v}{\partial P}\right)_T 00195 * \f] 00196 * or 00197 * \f[ 00198 * \kappa_T = \frac{1}{\rho}\left(\frac{\partial \rho}{\partial P}\right)_T 00199 * \f] 00200 */ 00201 virtual doublereal isothermalCompressibility() const; 00202 00203 //! Return the volumetric thermal expansion coefficient. Units: 1/K. 00204 /*! 00205 * The thermal expansion coefficient is defined as 00206 * \f[ 00207 * \beta = \frac{1}{v}\left(\frac{\partial v}{\partial T}\right)_P 00208 * \f] 00209 */ 00210 virtual doublereal thermalExpansionCoeff() const; 00211 00212 //! Return the derivative of the volumetric thermal expansion coefficient. Units: 1/K2. 00213 /*! 00214 * The thermal expansion coefficient is defined as 00215 * \f[ 00216 * \beta = \frac{1}{v}\left(\frac{\partial v}{\partial T}\right)_P 00217 * \f] 00218 */ 00219 virtual doublereal dthermalExpansionCoeffdT() const; 00220 00221 /** 00222 * @} 00223 * @name Potential Energy 00224 * @{ 00225 */ 00226 00227 /** 00228 * @} 00229 * @name Activities, Standard States, and Activity Concentrations 00230 * @{ 00231 */ 00232 00233 //@} 00234 /// @name Partial Molar Properties of the Solution ----------------- 00235 //@{ 00236 00237 00238 //@} 00239 /// @name Properties of the Standard State of the Species 00240 // in the Solution -- 00241 //@{ 00242 00243 00244 //! Get the gibbs function for the species 00245 //! standard states at the current T and P of the solution. 00246 /*! 00247 * @param gss Vector of length m_kk, which on return 00248 * will contain the 00249 * standard state gibbs function for species <I>k</I>. 00250 */ 00251 virtual void getStandardChemPotentials(doublereal* gss) const; 00252 00253 //!Get the nondimensional gibbs function for the species 00254 //! standard states at the current T and P of the solution. 00255 /*! 00256 * @param grt Vector of length m_kk, which on return 00257 * will contain the nondimensional 00258 * standard state gibbs function for species <I>k</I> 00259 */ 00260 virtual void getGibbs_RT(doublereal* grt) const; 00261 00262 //! Get the array of nondimensional Enthalpy functions for the standard state species 00263 //! at the current <I>T</I> and <I>P</I> of the solution. 00264 /*! 00265 * 00266 * @param hrt Vector of length m_kk, which on return 00267 * will contain the nondimensional 00268 * standard state enthalpy of species <I>k</I> 00269 */ 00270 void getEnthalpy_RT(doublereal* hrt) const; 00271 00272 00273 //! Get the nondimensional Entropies for the species 00274 //! standard states at the current T and P of the solution. 00275 /*! 00276 * @param sr Vector of length m_kk, which on return 00277 * will contain the nondimensional 00278 * standard state entropy for species<I>k</I> 00279 */ 00280 void getEntropy_R(doublereal* sr) const; 00281 00282 //! Get the nondimensional heat capacity at constant pressure 00283 //! function for the species standard states at the current T and P of the solution. 00284 /*! 00285 * 00286 * @param cpr Vector of length m_kk, which on return 00287 * will contain the nondimensional 00288 * constant pressure heat capacity for species <I>k</I> 00289 */ 00290 virtual void getCp_R(doublereal* cpr) const; 00291 00292 //! Returns the vector of nondimensional 00293 //! internal Energies of the standard state at the current 00294 //! temperature and pressure of the solution for each species. 00295 /*! 00296 * 00297 * @param urt Output vector of standard state nondimensional internal energies. 00298 * Length: m_kk. 00299 */ 00300 virtual void getIntEnergy_RT(doublereal *urt) const; 00301 00302 //@} 00303 //! @name Thermodynamic Values for the Species Reference State 00304 /*! 00305 * All functions in this group need to be overrided, because 00306 * the m_spthermo SpeciesThermo function is not adequate for 00307 * the real equation of state. 00308 * 00309 */ 00310 //@{ 00311 00312 //! Returns the vector of nondimensional 00313 //! enthalpies of the reference state at the current temperature 00314 //! of the solution and the reference pressure for the species. 00315 /*! 00316 * @param hrt Output vector containing the nondimensional reference state enthalpies 00317 * Length: m_kk. 00318 */ 00319 virtual void getEnthalpy_RT_ref(doublereal *hrt) const; 00320 00321 /*! 00322 * Returns the vector of nondimensional 00323 * enthalpies of the reference state at the current temperature 00324 * of the solution and the reference pressure for the species. 00325 * 00326 * @param grt Output vector containing the nondimensional reference state 00327 * Gibbs Free energies. Length: m_kk. 00328 */ 00329 virtual void getGibbs_RT_ref(doublereal *grt) const; 00330 00331 00332 /*! 00333 * Returns the vector of the 00334 * gibbs function of the reference state at the current temperature 00335 * of the solution and the reference pressure for the species. 00336 * units = J/kmol 00337 * 00338 * @param g Output vector containing the reference state 00339 * Gibbs Free energies. Length: m_kk. Units: J/kmol. 00340 */ 00341 virtual void getGibbs_ref(doublereal *g) const; 00342 00343 /*! 00344 * Returns the vector of nondimensional 00345 * entropies of the reference state at the current temperature 00346 * of the solution and the reference pressure for each species. 00347 * 00348 * @param er Output vector containing the nondimensional reference state 00349 * entropies. Length: m_kk. 00350 */ 00351 virtual void getEntropy_R_ref(doublereal *er) const; 00352 00353 /*! 00354 * Returns the vector of nondimensional 00355 * constant pressure heat capacities of the reference state 00356 * at the current temperature of the solution 00357 * and reference pressure for each species. 00358 * 00359 * @param cprt Output vector of nondimensional reference state 00360 * heat capacities at constant pressure for the species. 00361 * Length: m_kk 00362 */ 00363 virtual void getCp_R_ref(doublereal *cprt) const; 00364 00365 //! Get the molar volumes of the species reference states at the current 00366 //! <I>T</I> and <I>P_ref</I> of the solution. 00367 /*! 00368 * units = m^3 / kmol 00369 * 00370 * @param vol Output vector containing the standard state volumes. 00371 * Length: m_kk. 00372 */ 00373 virtual void getStandardVolumes_ref(doublereal *vol) const; 00374 00375 /// critical temperature 00376 virtual doublereal critTemperature() const; 00377 00378 /// critical pressure 00379 virtual doublereal critPressure() const; 00380 00381 /// critical density 00382 virtual doublereal critDensity() const; 00383 00384 /// saturation temperature 00385 //virtual doublereal satTemperature(doublereal p) const; 00386 00387 00388 00389 /// saturation pressure 00390 /*! 00391 * @param t Temperature (kelvin) 00392 */ 00393 virtual doublereal satPressure(doublereal t) const; 00394 00395 //! Return the fraction of vapor at the current conditions 00396 /*! 00397 * Below Tcrit, this routine will always return 0, by definition 00398 * of the functionality of the routine. Above Tcrit, we query 00399 * the density to toggle between 0 and 1. 00400 */ 00401 virtual doublereal vaporFraction() const; 00402 00403 //! Set the temperature of the phase 00404 /*! 00405 * The density and composition of the phase is constant during this 00406 * operator. 00407 * 00408 * @param temp Temperature (Kelvin) 00409 */ 00410 virtual void setTemperature(const doublereal temp); 00411 00412 //! Set the density of the phase 00413 /*! 00414 * The temperature and composition of the phase is constant during this 00415 * operator. 00416 * 00417 * @param dens value of the density in kg m-3 00418 */ 00419 virtual void setDensity(const doublereal dens); 00420 00421 00422 //! Initialization of a pure water phase using an 00423 //! xml file. 00424 /*! 00425 * This routine is a precursor to constructPhaseXML(XML_Node*) 00426 * routine, which does most of the work. 00427 * 00428 * @param inputFile String name of the file. 00429 * 00430 * @param id Optional parameter identifying the name of the 00431 * phase. If none is given, the first XML 00432 * phase element will be used. 00433 */ 00434 void constructPhaseFile(std::string inputFile, std::string id); 00435 00436 00437 //! Initialization of a pure water phase using an xml file. 00438 /*! 00439 * This calls importPhase() to do the work. 00440 * 00441 * @param phaseNode XML file containing the description of the 00442 * phase 00443 * 00444 * @param id Optional parameter identifying the name of the 00445 * phase. If none is given, the first XML 00446 * phase element will be used. 00447 */ 00448 void constructPhaseXML(XML_Node& phaseNode, std::string id); 00449 00450 //!Import and initialize a ThermoPhase object using an XML tree. 00451 /*! 00452 * @internal 00453 * 00454 * Here we read extra information about the XML description 00455 * of a phase. Regular information about elements and species 00456 * and their reference state thermodynamic information 00457 * have already been read at this point. 00458 * For example, we do not need to call this function for 00459 * ideal gas equations of state. This function is called from importPhase() 00460 * after the elements and the species are initialized with 00461 * default ideal solution level data. 00462 * 00463 * The default implementation in ThermoPhase calls the 00464 * virtual function initThermo() and then sets the "state" of the 00465 * phase by looking for an XML element named "state", and then 00466 * interpreting its contents by calling the virtual function 00467 * setStateFromXML(). 00468 * 00469 * @param phaseNode This object must be the phase node of a 00470 * complete XML tree 00471 * description of the phase, including all of the 00472 * species data. In other words while "phase" must 00473 * point to an XML phase object, it must have 00474 * sibling nodes "speciesData" that describe 00475 * the species in the phase. 00476 * @param id ID of the phase. If nonnull, a check is done 00477 * to see if phaseNode is pointing to the phase 00478 * with the correct id. 00479 */ 00480 virtual void initThermoXML(XML_Node& phaseNode, std::string id); 00481 00482 //! Initialize the ThermoPhase object after all species have been set up 00483 /*! 00484 * @internal Initialize. 00485 * 00486 * This method is provided to allow 00487 * subclasses to perform any initialization required after all 00488 * species have been added. For example, it might be used to 00489 * resize internal work arrays that must have an entry for 00490 * each species. The base class implementation does nothing, 00491 * and subclasses that do not require initialization do not 00492 * need to overload this method. When importing a CTML phase 00493 * description, this method is called from ThermoPhase::initThermoXML(), 00494 * which is called from importPhase(), 00495 * just prior to returning from function importPhase(). 00496 * 00497 * @see importCTML.cpp 00498 */ 00499 virtual void initThermo(); 00500 00501 //! Set equation of state parameter values from XML entries. 00502 /*! 00503 * 00504 * This method is called by function importPhase() in 00505 * file importCTML.cpp when processing a phase definition in 00506 * an input file. It should be overloaded in subclasses to set 00507 * any parameters that are specific to that particular phase 00508 * model. Note, this method is called before the phase is 00509 * initialzed with elements and/or species. 00510 * 00511 * @param eosdata An XML_Node object corresponding to 00512 * the "thermo" entry for this phase in the input file. 00513 */ 00514 virtual void setParametersFromXML(const XML_Node& eosdata); 00515 00516 //! Get a pointer to a changeable WaterPropsIAPWS object 00517 WaterPropsIAPWS *getWater() { 00518 return m_sub; 00519 } 00520 00521 //! Get a pointer to a changeable WaterPropsIAPWS object 00522 WaterProps *getWaterProps() { 00523 return m_waterProps; 00524 } 00525 00526 00527 protected: 00528 00529 /** 00530 * @internal 00531 * This internal routine must be overwritten because 00532 * it is not applicable. 00533 */ 00534 void _updateThermo() const; 00535 00536 private: 00537 //! Pointer to the WaterPropsIAPWS that calculates the real properties 00538 //! of water. 00539 mutable WaterPropsIAPWS *m_sub; 00540 00541 //! Pointer to the WaterProps object 00542 /*! 00543 * This class is used to house several approximation 00544 * routines for properties of water. 00545 * 00546 * This object owns m_waterProps, and the WaterPropsIAPWS object used by 00547 * WaterProps is m_sub, which is defined above. 00548 */ 00549 WaterProps *m_waterProps; 00550 00551 //! Molecular weight of Water -> Cantera assumption 00552 doublereal m_mw; 00553 00554 //! Offset constants used to obtain consistency with the NIST database. 00555 /*! 00556 * This is added to all internal energy and enthalpy results. 00557 * units = J kmol-1. 00558 */ 00559 doublereal EW_Offset; 00560 00561 //! Offset constant used to obtain consistency with NIST convention. 00562 /*! 00563 * This is added to all internal entropy results. 00564 * units = J kmol-1 K-1. 00565 */ 00566 doublereal SW_Offset; 00567 00568 //! Boolean is true if object has been properly initialized for calculation 00569 bool m_ready; 00570 00571 /** 00572 * Since this phase represents a liquid phase, it's an error to 00573 * return a gas-phase answer. However, if the below is true, then 00574 * a gas-phase answer is allowed. This is used to check the thermodynamic 00575 * consistency with ideal-gas thermo functions for example. 00576 */ 00577 bool m_allowGasPhase; 00578 }; 00579 00580 } 00581 00582 #endif 00583 00584 00585