00001 /** 00002 * @file ConstDensityThermo.h 00003 * Header for a Thermo manager for incompressible ThermoPhases 00004 * (see \ref thermoprops and \link Cantera::ConstDensityThermo ConstDensityThermo\endlink). 00005 */ 00006 /* 00007 * $Author: hkmoffa $ 00008 * $Date: 2009-12-09 12:29:23 -0500 (Wed, 09 Dec 2009) $ 00009 * $Revision: 306 $ 00010 * 00011 * Copyright 2002 California Institute of Technology 00012 * 00013 */ 00014 00015 #ifndef CT_CONSTRHOTHERMO_H 00016 #define CT_CONSTRHOTHERMO_H 00017 00018 #include "ct_defs.h" 00019 #include "mix_defs.h" 00020 #include "ThermoPhase.h" 00021 #include "SpeciesThermo.h" 00022 #include "utilities.h" 00023 00024 namespace Cantera { 00025 00026 //! Overloads the virtual methods of class ThermoPhase to implement the 00027 //! incompressible equation of state. 00028 /** 00029 * 00030 * 00031 * <b> Specification of Species Standard State Properties </b> 00032 * 00033 * 00034 * <b> Specification of Solution Thermodynamic Properties </b> 00035 * 00036 * The density is assumed to be constant, no matter what the concentration of the solution. 00037 * 00038 * 00039 * <b> Application within %Kinetics Managers </b> 00040 * 00041 * 00042 * <b> XML Example </b> 00043 * 00044 * An example of an XML Element named phase setting up a SurfPhase object named diamond_100 00045 * is given below. 00046 * 00047 * @ingroup thermoprops 00048 */ 00049 class ConstDensityThermo : public ThermoPhase { 00050 00051 public: 00052 00053 //! Constructor. 00054 /*! 00055 * 00056 */ 00057 ConstDensityThermo(); 00058 00059 //! Destructor 00060 virtual ~ConstDensityThermo() {} 00061 00062 //! Copy Constructor 00063 /*! 00064 * @param right Object to be copied 00065 */ 00066 ConstDensityThermo(const ConstDensityThermo &right); 00067 00068 //! Assignment Operator 00069 /*! 00070 * @param right Object to be copied 00071 */ 00072 ConstDensityThermo& operator=(const ConstDensityThermo &right); 00073 00074 00075 //! Duplication routine for objects which inherit from 00076 //! %SpeciesThermo 00077 /*! 00078 * This virtual routine can be used to duplicate %SpeciesThermo objects 00079 * inherited from %SpeciesThermo even if the application only has 00080 * a pointer to %SpeciesThermo to work with. 00081 * ->commented out because we first need to add copy constructors 00082 * and assignment operators to all of the derived classes. 00083 */ 00084 virtual SpeciesThermo *duplMyselfAsSpeciesThermo() const; 00085 00086 //! overloaded methods of class ThermoPhase 00087 virtual int eosType() const; 00088 00089 //! Return the Molar Enthalpy. Units: J/kmol. 00090 /*! 00091 * 00092 */ 00093 00094 /// Molar enthalpy. Units: J/kmol. 00095 virtual doublereal enthalpy_mole() const; 00096 00097 /// Molar internal energy. Units: J/kmol. 00098 virtual doublereal intEnergy_mole() const; 00099 00100 00101 /// Molar entropy. Units: J/kmol/K. 00102 virtual doublereal entropy_mole() const; 00103 00104 /// Molar Gibbs function. Units: J/kmol. 00105 virtual doublereal gibbs_mole() const; 00106 00107 /// Molar heat capacity at constant pressure. Units: J/kmol/K. 00108 virtual doublereal cp_mole() const; 00109 00110 /// Molar heat capacity at constant volume. Units: J/kmol/K. 00111 virtual doublereal cv_mole() const; 00112 00113 //! Return the thermodynamic pressure (Pa). 00114 /*! 00115 * This method must be overloaded in derived classes. Since the 00116 * mass density, temperature, and mass fractions are stored, 00117 * this method should use these values to implement the 00118 * mechanical equation of state \f$ P(T, \rho, Y_1, \dots, 00119 * Y_K) \f$. 00120 */ 00121 virtual doublereal pressure() const; 00122 00123 //! Set the internally storred pressure (Pa) at constant 00124 //! temperature and composition 00125 /*! 00126 * This method must be reimplemented in derived classes, where it 00127 * may involve the solution of a nonlinear equation. Within %Cantera, 00128 * the independent variable is the density. Therefore, this function 00129 * solves for the density that will yield the desired input pressure. 00130 * The temperature and composition iare held constant during this process. 00131 * 00132 * This base class function will print an error, if not overwritten. 00133 * 00134 * @param p input Pressure (Pa) 00135 */ 00136 virtual void setPressure(doublereal p); 00137 00138 //! This method returns an array of generalized concentrations 00139 /*! 00140 * \f$ C^a_k\f$ are defined such that \f$ a_k = C^a_k / 00141 * C^0_k, \f$ where \f$ C^0_k \f$ is a standard concentration 00142 * defined below and \f$ a_k \f$ are activities used in the 00143 * thermodynamic functions. These activity (or generalized) 00144 * concentrations are used 00145 * by kinetics manager classes to compute the forward and 00146 * reverse rates of elementary reactions. Note that they may 00147 * or may not have units of concentration --- they might be 00148 * partial pressures, mole fractions, or surface coverages, 00149 * for example. 00150 * 00151 * @param c Output array of generalized concentrations. The 00152 * units depend upon the implementation of the 00153 * reaction rate expressions within the phase. 00154 */ 00155 virtual void getActivityConcentrations(doublereal* c) const; 00156 00157 //! Get the array of non-dimensional molar-based activity coefficients at 00158 //! the current solution temperature, pressure, and solution concentration. 00159 /*! 00160 * @param ac Output vector of activity coefficients. Length: m_kk. 00161 */ 00162 virtual void getActivityCoefficients(doublereal* ac) const; 00163 00164 //! Get the species chemical potentials. Units: J/kmol. 00165 /*! 00166 * This function returns a vector of chemical potentials of the 00167 * species in solution at the current temperature, pressure 00168 * and mole fraction of the solution. 00169 * 00170 * @param mu Output vector of species chemical 00171 * potentials. Length: m_kk. Units: J/kmol 00172 */ 00173 virtual void getChemPotentials(doublereal* mu) const; 00174 00175 //! Get the array of chemical potentials at unit activity for the species 00176 //! at their standard states at the current <I>T</I> and <I>P</I> of the solution. 00177 /*! 00178 * These are the standard state chemical potentials \f$ \mu^0_k(T,P) 00179 * \f$. The values are evaluated at the current 00180 * temperature and pressure of the solution 00181 * 00182 * @param mu0 Output vector of chemical potentials. 00183 * Length: m_kk. 00184 */ 00185 virtual void getStandardChemPotentials(doublereal* mu0) const; 00186 00187 //! Return the standard concentration for the kth species 00188 /*! 00189 * The standard concentration \f$ C^0_k \f$ used to normalize 00190 * the activity (i.e., generalized) concentration. In many cases, this quantity 00191 * will be the same for all species in a phase - for example, 00192 * for an ideal gas \f$ C^0_k = P/\hat R T \f$. For this 00193 * reason, this method returns a single value, instead of an 00194 * array. However, for phases in which the standard 00195 * concentration is species-specific (e.g. surface species of 00196 * different sizes), this method may be called with an 00197 * optional parameter indicating the species. 00198 * 00199 * @param k Optional parameter indicating the species. The default 00200 * is to assume this refers to species 0. 00201 * @return 00202 * Returns the standard Concentration in units of m3 kmol-1. 00203 */ 00204 virtual doublereal standardConcentration(int k=0) const; 00205 00206 //! Natural logarithm of the standard concentration of the kth species. 00207 /*! 00208 * @param k index of the species (defaults to zero) 00209 */ 00210 virtual doublereal logStandardConc(int k=0) const; 00211 00212 //! Get the Gibbs functions for the standard 00213 //! state of the species at the current <I>T</I> and <I>P</I> of the solution 00214 /*! 00215 * Units are Joules/kmol 00216 * @param gpure Output vector of standard state gibbs free energies 00217 * Length: m_kk. 00218 */ 00219 virtual void getPureGibbs(doublereal* gpure) const { 00220 const array_fp& gibbsrt = gibbs_RT(); 00221 scale(gibbsrt.begin(), gibbsrt.end(), gpure, _RT()); 00222 } 00223 00224 //! Get the nondimensional Enthalpy functions for the species 00225 //! at their standard states at the current <I>T</I> and <I>P</I> of the solution. 00226 /*! 00227 * @param hrt Output vector of nondimensional standard state enthalpies. 00228 * Length: m_kk. 00229 */ 00230 void getEnthalpy_RT(doublereal* hrt) const { 00231 const array_fp& _h = enthalpy_RT(); 00232 std::copy(_h.begin(), _h.end(), hrt); 00233 } 00234 00235 //! Get the array of nondimensional Entropy functions for the 00236 //! standard state species at the current <I>T</I> and <I>P</I> of the solution. 00237 /*! 00238 * @param sr Output vector of nondimensional standard state entropies. 00239 * Length: m_kk. 00240 */ 00241 void getEntropy_R(doublereal* sr) const { 00242 const array_fp& _s = entropy_R(); 00243 std::copy(_s.begin(), _s.end(), sr); 00244 } 00245 00246 //! Get the nondimensional Gibbs functions for the species 00247 //! in their standard states at the current <I>T</I> and <I>P</I> of the solution. 00248 /*! 00249 * @param grt Output vector of nondimensional standard state gibbs free energies 00250 * Length: m_kk. 00251 */ 00252 virtual void getGibbs_RT(doublereal* grt) const { 00253 const array_fp& gibbsrt = gibbs_RT(); 00254 std::copy(gibbsrt.begin(), gibbsrt.end(), grt); 00255 } 00256 00257 //! Get the nondimensional Heat Capacities at constant 00258 //! pressure for the species standard states 00259 //! at the current <I>T</I> and <I>P</I> of the solution 00260 /*! 00261 * @param cpr Output vector of nondimensional standard state heat capacities 00262 * Length: m_kk. 00263 */ 00264 void getCp_R(doublereal* cpr) const { 00265 const array_fp& _cpr = cp_R(); 00266 std::copy(_cpr.begin(), _cpr.end(), cpr); 00267 } 00268 00269 00270 // new methods defined here 00271 00272 //! Returns a reference to the vector of nondimensional 00273 //! enthalpies of the reference state at the current temperature 00274 //! of the solution and the reference pressure for the species. 00275 const array_fp& enthalpy_RT() const { 00276 _updateThermo(); 00277 return m_h0_RT; 00278 } 00279 00280 //! Returns a reference to the vector of nondimensional 00281 //! Gibbs Free Energies of the reference state at the current temperature 00282 //! of the solution and the reference pressure for the species. 00283 const array_fp& gibbs_RT() const { 00284 _updateThermo(); 00285 return m_g0_RT; 00286 } 00287 00288 //! Returns a reference to the vector of exponentials of the nondimensional 00289 //! Gibbs Free Energies of the reference state at the current temperature 00290 //! of the solution and the reference pressure for the species. 00291 const array_fp& expGibbs_RT() const { 00292 _updateThermo(); 00293 int k; 00294 for (k = 0; k != m_kk; k++) m_expg0_RT[k] = std::exp(m_g0_RT[k]); 00295 return m_expg0_RT; 00296 } 00297 00298 //! Returns a reference to the vector of nondimensional 00299 //! entropies of the reference state at the current temperature 00300 //! of the solution and the reference pressure for each species. 00301 const array_fp& entropy_R() const { 00302 _updateThermo(); 00303 return m_s0_R; 00304 } 00305 00306 //! Returns a reference to the vector of nondimensional 00307 //! constant pressure heat capacities of the reference state 00308 //! at the current temperature of the solution 00309 //! and reference pressure for each species. 00310 const array_fp& cp_R() const { 00311 _updateThermo(); 00312 return m_cp0_R; 00313 } 00314 00315 //! Set the potential energy of species k 00316 /*! 00317 * @param k species index 00318 * @param pe Potential energy (J kmol-1). 00319 */ 00320 virtual void setPotentialEnergy(int k, doublereal pe) { 00321 m_pe[k] = pe; 00322 } 00323 00324 //! Returns the potential energy of species k 00325 /*! 00326 * @param k species index 00327 */ 00328 virtual doublereal potentialEnergy(int k) const { 00329 return m_pe[k]; 00330 } 00331 00332 //! Initialize the ThermoPhase object after all species have been set up 00333 /*! 00334 * @internal Initialize. 00335 * 00336 * This method is provided to allow 00337 * subclasses to perform any initialization required after all 00338 * species have been added. For example, it might be used to 00339 * resize internal work arrays that must have an entry for 00340 * each species. The base class implementation does nothing, 00341 * and subclasses that do not require initialization do not 00342 * need to overload this method. When importing a CTML phase 00343 * description, this method is called from ThermoPhase::initThermoXML(), 00344 * which is called from importPhase(), 00345 * just prior to returning from function importPhase(). 00346 * 00347 * @see importCTML.cpp 00348 */ 00349 virtual void initThermo(); 00350 00351 //!This method is used by the ChemEquil equilibrium solver. 00352 /*! 00353 * It sets the state such that the chemical potentials satisfy 00354 * \f[ \frac{\mu_k}{\hat R T} = \sum_m A_{k,m} 00355 * \left(\frac{\lambda_m} {\hat R T}\right) \f] where 00356 * \f$ \lambda_m \f$ is the element potential of element m. The 00357 * temperature is unchanged. Any phase (ideal or not) that 00358 * implements this method can be equilibrated by ChemEquil. 00359 * 00360 * @param lambda_RT Input vector of dimensionless element potentials 00361 * The length is equal to nElements(). 00362 */ 00363 virtual void setToEquilState(const doublereal* lambda_RT); 00364 00365 00366 //! Set the equation of state parameters 00367 /*! 00368 * @internal 00369 * The number and meaning of these depends on the subclass. 00370 * 00371 * @param n number of parameters 00372 * @param c array of \a n coefficients 00373 */ 00374 virtual void setParameters(int n, doublereal* const c) { 00375 setDensity(c[0]); 00376 } 00377 00378 //! Get the equation of state parameters in a vector 00379 /*! 00380 * @internal 00381 * The number and meaning of these depends on the subclass. 00382 * 00383 * @param n number of parameters 00384 * @param c array of \a n coefficients 00385 */ 00386 virtual void getParameters(int &n, doublereal * const c) const { 00387 double d = density(); 00388 c[0] = d; 00389 n = 1; 00390 } 00391 00392 //! Set equation of state parameter values from XML entries. 00393 /*! 00394 * 00395 * This method is called by function importPhase() in 00396 * file importCTML.cpp when processing a phase definition in 00397 * an input file. It should be overloaded in subclasses to set 00398 * any parameters that are specific to that particular phase 00399 * model. Note, this method is called before the phase is 00400 * initialzed with elements and/or species. 00401 * 00402 * @param eosdata An XML_Node object corresponding to 00403 * the "thermo" entry for this phase in the input file. 00404 */ 00405 virtual void setParametersFromXML(const XML_Node& eosdata); 00406 00407 protected: 00408 00409 //! number of elements 00410 int m_mm; 00411 00412 00413 //! Minimum temperature for valid species standard state thermo props 00414 /*! 00415 * This is the minimum temperature at which all species have valid standard 00416 * state thermo props defined. 00417 */ 00418 doublereal m_tmin; 00419 00420 //! Maximum temperature for valid species standard state thermo props 00421 /*! 00422 * This is the maximum temperature at which all species have valid standard 00423 * state thermo props defined. 00424 */ 00425 doublereal m_tmax; 00426 00427 //! Reference state pressure 00428 /*! 00429 * Value of the reference state pressure in Pascals. 00430 * All species must have the same reference state pressure. 00431 */ 00432 doublereal m_p0; 00433 00434 //! last value of the temperature processed by reference state 00435 mutable doublereal m_tlast; 00436 00437 //! Temporary storage for dimensionless reference state enthalpies 00438 mutable array_fp m_h0_RT; 00439 00440 //! Temporary storage for dimensionless reference state heat capacities 00441 mutable array_fp m_cp0_R; 00442 00443 //! Temporary storage for dimensionless reference state gibbs energies 00444 mutable array_fp m_g0_RT; 00445 00446 //! Temporary storage for dimensionless reference state entropies 00447 mutable array_fp m_s0_R; 00448 00449 //! currently unsed 00450 /*! 00451 * @deprecated 00452 */ 00453 mutable array_fp m_expg0_RT; 00454 00455 //! Currently unused 00456 /* 00457 * @deprecated 00458 */ 00459 mutable array_fp m_pe; 00460 00461 //! Temporary array containing internally calculated partial pressures 00462 mutable array_fp m_pp; 00463 00464 //! Current pressure (Pa) 00465 doublereal m_press; 00466 00467 private: 00468 00469 //! Function to update the reference state thermo functions 00470 void _updateThermo() const; 00471 }; 00472 } 00473 00474 #endif