NasaPoly1.h

Go to the documentation of this file.
00001 
00002 /**
00003  *  @file NasaPoly1.h
00004  *  Header for a single-species standard state object derived
00005  *  from \link Cantera::SpeciesThermoInterpType SpeciesThermoInterpType\endlink  based 
00006  *  on the NASA temperature polynomial form applied to one temperature region
00007  *  (see \ref spthermo and class \link Cantera::NasaPoly1 NasaPoly1\endlink).
00008  *
00009  *  This parameterization has one NASA temperature region.
00010  */
00011 
00012 
00013 #ifndef CT_NASAPOLY1_H
00014 #define CT_NASAPOLY1_H
00015 
00016 
00017 /* $Author: hkmoffa $
00018  * $Revision: 306 $
00019  * $Date: 2009-12-09 12:29:23 -0500 (Wed, 09 Dec 2009) $
00020  */
00021 
00022 // Copyright 2001  California Institute of Technology
00023 
00024 
00025 #include "global.h"
00026 #include "SpeciesThermoInterpType.h"
00027 
00028 namespace Cantera {
00029 
00030   /**
00031    * The NASA polynomial parameterization for one temperature range.
00032    * This parameterization expresses the heat capacity as a
00033    * fourth-order polynomial. Note that this is the form used in the
00034    * 1971 NASA equilibrium program and by the Chemkin software
00035    * package, but differs from the form used in the more recent NASA
00036    * equilibrium program.
00037    *
00038    * Seven coefficients \f$(a_0,\dots,a_6)\f$ are used to represent
00039    * \f$ c_p^0(T)\f$, \f$ h^0(T)\f$, and \f$ s^0(T) \f$ as 
00040    * polynomials in \f$ T \f$ :  
00041    * \f[
00042    * \frac{c_p(T)}{R} = a_0 + a_1 T + a_2 T^2 + a_3 T^3 + a_4 T^4
00043    * \f]
00044    * \f[
00045    * \frac{h^0(T)}{RT} = a_0 + \frac{a_1}{2} T + \frac{a_2}{3} T^2 
00046    * + \frac{a_3}{4} T^3 + \frac{a_4}{5} T^4  + \frac{a_5}{T}.
00047    * \f]
00048    * \f[
00049    * \frac{s^0(T)}{R} = a_0\ln T + a_1 T + \frac{a_2}{2} T^2 
00050    + \frac{a_3}{3} T^3 + \frac{a_4}{4} T^4  + a_6.
00051    * \f]
00052    * 
00053    * This class is designed specifically for use by class NasaThermo.
00054    * @ingroup spthermo
00055    */
00056   class NasaPoly1 : public SpeciesThermoInterpType {
00057 
00058   public:
00059 
00060     //! Empty constructor
00061     NasaPoly1() 
00062       : m_lowT(0.0), m_highT (0.0),
00063         m_Pref(0.0), m_index (0), m_coeff(array_fp(7)) {}
00064 
00065 
00066     //! constructor used in templated instantiations
00067     /*!
00068      * @param n            Species index
00069      * @param tlow         Minimum temperature
00070      * @param thigh        Maximum temperature
00071      * @param pref         reference pressure (Pa).
00072      * @param coeffs       Vector of coefficients used to set the
00073      *                     parameters for the standard state.
00074      */
00075     NasaPoly1(int n, doublereal tlow, doublereal thigh, doublereal pref,
00076               const doublereal* coeffs) :
00077       m_lowT      (tlow),
00078       m_highT     (thigh),
00079       m_Pref      (pref),
00080       m_index     (n),
00081       m_coeff     (array_fp(7)) {
00082       std::copy(coeffs, coeffs + 7, m_coeff.begin());
00083     }
00084 
00085     //! copy constructor
00086     /*!
00087      * @param b object to be copied
00088      */
00089     NasaPoly1(const NasaPoly1& b) :
00090       m_lowT      (b.m_lowT),
00091       m_highT     (b.m_highT),
00092       m_Pref      (b.m_Pref),
00093       m_index     (b.m_index),
00094       m_coeff     (array_fp(7)) {
00095       std::copy(b.m_coeff.begin(),
00096                 b.m_coeff.begin() + 7,
00097                 m_coeff.begin());
00098     }
00099 
00100     //! assignment operator
00101     /*!
00102      * @param b object to be copied
00103      */
00104     NasaPoly1& operator=(const NasaPoly1& b) {
00105       if (&b != this) {
00106         m_lowT   = b.m_lowT;
00107         m_highT  = b.m_highT;
00108         m_Pref   = b.m_Pref;
00109         m_index  = b.m_index;
00110         std::copy(b.m_coeff.begin(),
00111                   b.m_coeff.begin() + 7,
00112                   m_coeff.begin());
00113       }
00114       return *this;
00115     }
00116 
00117     //! Destructor
00118     virtual ~NasaPoly1(){}
00119 
00120     //! duplicator
00121     virtual SpeciesThermoInterpType *
00122     duplMyselfAsSpeciesThermoInterpType() const {
00123       NasaPoly1* np = new NasaPoly1(*this);
00124       return (SpeciesThermoInterpType *) np;
00125     }
00126 
00127     //! Returns the minimum temperature that the thermo
00128     //! parameterization is valid
00129     virtual doublereal minTemp() const     { return m_lowT;}
00130 
00131     //! Returns the maximum temperature that the thermo
00132     //! parameterization is valid
00133     virtual doublereal maxTemp() const     { return m_highT;}
00134 
00135     //! Returns the reference pressure (Pa)
00136     virtual doublereal refPressure() const { return m_Pref; }
00137 
00138     //! Returns an integer representing the type of parameterization
00139     virtual int reportType() const { return NASA1; }
00140       
00141      //! Returns an integer representing the species index
00142     virtual int speciesIndex() const { return m_index; }
00143   
00144     //! Update the properties for this species, given a temperature polynomial
00145     /*!
00146      * This method is called with a pointer to an array containing the functions of
00147      * temperature needed by this  parameterization, and three pointers to arrays where the
00148      * computed property values should be written. This method updates only one value in
00149      * each array.
00150      *
00151      * Temperature Polynomial:
00152      *  tt[0] = t;
00153      *  tt[1] = t*t;
00154      *  tt[2] = m_t[1]*t;
00155      *  tt[3] = m_t[2]*t;
00156      *  tt[4] = 1.0/t;
00157      *  tt[5] = std::log(t);
00158      *
00159      * @param tt      vector of temperature polynomials
00160      * @param cp_R    Vector of Dimensionless heat capacities.
00161      *                (length m_kk).
00162      * @param h_RT    Vector of Dimensionless enthalpies.
00163      *                (length m_kk).
00164      * @param s_R     Vector of Dimensionless entropies.
00165      *                (length m_kk).
00166      */
00167     virtual void updateProperties(const doublereal* tt, 
00168                                   doublereal* cp_R, doublereal* h_RT, doublereal* s_R) const {
00169           
00170       doublereal ct0 = m_coeff[2];          // a0 
00171       doublereal ct1 = m_coeff[3]*tt[0];    // a1 * T
00172       doublereal ct2 = m_coeff[4]*tt[1];    // a2 * T^2
00173       doublereal ct3 = m_coeff[5]*tt[2];    // a3 * T^3
00174       doublereal ct4 = m_coeff[6]*tt[3];    // a4 * T^4
00175  
00176       doublereal cp, h, s;
00177       cp = ct0 + ct1 + ct2 + ct3 + ct4;
00178       h = ct0 + 0.5*ct1 + OneThird*ct2 + 0.25*ct3 + 0.2*ct4
00179         + m_coeff[0]*tt[4];               // last term is a5/T
00180       s = ct0*tt[5] + ct1 + 0.5*ct2 + OneThird*ct3
00181         +0.25*ct4 + m_coeff[1];           // last term is a6
00182 
00183       // return the computed properties in the location in the output 
00184       // arrays for this species
00185       cp_R[m_index] = cp;
00186       h_RT[m_index] = h;
00187       s_R[m_index] = s;
00188       //writelog("NASA1: for species "+int2str(m_index)+", h_RT = "+
00189       //    fp2str(h)+"\n");
00190     }
00191 
00192  
00193     //! Compute the reference-state property of one species
00194     /*!
00195      * Given temperature T in K, this method updates the values of
00196      * the non-dimensional heat capacity at constant pressure,
00197      * enthalpy, and entropy, at the reference pressure, Pref
00198      * of one of the species. The species index is used
00199      * to reference into the cp_R, h_RT, and s_R arrays.
00200      *
00201      * @param temp    Temperature (Kelvin)
00202      * @param cp_R    Vector of Dimensionless heat capacities.
00203      *                (length m_kk).
00204      * @param h_RT    Vector of Dimensionless enthalpies.
00205      *                (length m_kk).
00206      * @param s_R     Vector of Dimensionless entropies.
00207      *                (length m_kk).
00208      */
00209     virtual void updatePropertiesTemp(const doublereal temp, 
00210                                       doublereal* cp_R, doublereal* h_RT, 
00211                                       doublereal* s_R) const {
00212       double tPoly[6];
00213       tPoly[0]  = temp;
00214       tPoly[1]  = temp * temp;
00215       tPoly[2]  = tPoly[1] * temp;
00216       tPoly[3]  = tPoly[2] * temp;
00217       tPoly[4]  = 1.0 / temp;
00218       tPoly[5]  = std::log(temp);
00219       updateProperties(tPoly, cp_R, h_RT, s_R);
00220     }
00221 
00222     //!This utility function reports back the type of 
00223     //! parameterization and all of the parameters for the 
00224     //! species, index.
00225     /*!
00226      * All parameters are output variables
00227      *
00228      * @param n         Species index
00229      * @param type      Integer type of the standard type
00230      * @param tlow      output - Minimum temperature
00231      * @param thigh     output - Maximum temperature
00232      * @param pref      output - reference pressure (Pa).
00233      * @param coeffs    Vector of coefficients used to set the
00234      *                  parameters for the standard state.
00235      */
00236     virtual void reportParameters(int &n, int &type,
00237                                   doublereal &tlow, doublereal &thigh,
00238                                   doublereal &pref,
00239                                   doublereal* const coeffs) const {
00240       n = m_index;
00241       type = NASA1;
00242       tlow = m_lowT;
00243       thigh = m_highT;
00244       pref = m_Pref;
00245       coeffs[5] = m_coeff[0];
00246       coeffs[6] = m_coeff[1];
00247       for (int i = 2; i < 7; i++) {
00248         coeffs[i-2] = m_coeff[i];
00249       }
00250 #ifdef WARN_ABOUT_CHANGES_FROM_VERSION_1_6
00251       cout << "************************************************\n"
00252         cout << "Warning: NasaPoly1::reportParameters now returns \n"
00253            << "the coefficient array in the same order as in\n"
00254            << "the input file.  See file NasaPoly1.h" << endl;
00255       cout << "************************************************\n"
00256 #endif
00257         }
00258 
00259     //! Modify parameters for the standard state
00260     /*!
00261      * @param coeffs   Vector of coefficients used to set the
00262      *                 parameters for the standard state.
00263      */
00264     virtual void modifyParameters(doublereal* coeffs) {
00265       m_coeff[0] = coeffs[5];
00266       m_coeff[1] = coeffs[6];
00267       for (int i = 0; i < 5; i++) {
00268         m_coeff[i+2] = coeffs[i];
00269       }            
00270     }
00271 
00272 #ifdef H298MODIFY_CAPABILITY
00273 
00274     virtual doublereal reportHf298(doublereal* const h298 = 0) const {
00275       double tt[6];
00276       double temp = 298.15;
00277       tt[0]  = temp;
00278       tt[1]  = temp * temp;
00279       tt[2]  = tt[1] * temp;
00280       tt[3]  = tt[2] * temp;
00281       tt[4]  = 1.0 / temp;
00282       //tt[5]  = std::log(temp);
00283       doublereal ct0 = m_coeff[2];          // a0 
00284       doublereal ct1 = m_coeff[3]*tt[0];    // a1 * T
00285       doublereal ct2 = m_coeff[4]*tt[1];    // a2 * T^2
00286       doublereal ct3 = m_coeff[5]*tt[2];    // a3 * T^3
00287       doublereal ct4 = m_coeff[6]*tt[3];    // a4 * T^4
00288  
00289       double h_RT = ct0 + 0.5*ct1 + OneThird*ct2 + 0.25*ct3 + 0.2*ct4
00290         + m_coeff[0]*tt[4];               // last t
00291       
00292       double h = h_RT * GasConstant * temp;
00293       if (h298) {
00294         h298[m_index] = h; 
00295       }
00296       return h;
00297     }
00298 
00299     virtual void modifyOneHf298(const int k, const doublereal Hf298New) {
00300       if (k != m_index) return;
00301       double hcurr = reportHf298(0);
00302       double delH = Hf298New - hcurr;
00303       m_coeff[0] += (delH) / GasConstant;
00304     }
00305     
00306 #endif
00307 
00308   protected:
00309     //! lowest valid temperature
00310     doublereal m_lowT;    
00311     //! highest valid temperature
00312     doublereal m_highT;   
00313     //! standard-state pressure
00314     doublereal m_Pref;     
00315     //! species index
00316     int m_index;  
00317     //! array of polynomial coefficients       
00318     array_fp m_coeff;    
00319 
00320   };
00321 
00322 }
00323 #endif
00324 
Generated by  doxygen 1.6.3