Nasa9Poly1.cpp

Go to the documentation of this file.
00001 /**
00002  *  @file Nasa9Poly1.cpp
00003  *  Definitions for a single-species standard state object derived
00004  *  from 
00005  *  \link Cantera::SpeciesThermoInterpType SpeciesThermoInterpType\endlink 
00006  *  based 
00007  *  on the NASA 9 coefficient temperature polynomial form applied to one temperature region
00008  *  (see \ref spthermo and class \link Cantera::Nasa9Poly1 Nasa9Poly1\endlink).
00009  *
00010  *  This parameterization has one NASA temperature region.
00011  */
00012 
00013 /* $Author: hkmoffa $
00014  * $Revision: 279 $
00015  * $Date: 2009-12-05 14:08:43 -0500 (Sat, 05 Dec 2009) $
00016  */
00017 // Copyright 2007  Sandia National Laboratories
00018 
00019 #include "Nasa9Poly1.h"
00020 
00021 namespace Cantera {
00022 
00023  
00024   // The NASA 9 polynomial parameterization for one temperature range.
00025   /*
00026    * This parameterization expresses the heat capacity via a
00027    * 7 coefficient polynomial.
00028    * 
00029    *  Note that this is the form used in the
00030    * 2002 NASA equilibrium program
00031    *
00032    *  "NASA Glenn Coefficients for Calculating Thermodynamic
00033    *  Properties of Individual Species,"
00034    *  B. J. McBride, M. J. Zehe, S. Gordon
00035    *  NASA/TP-2002-211556, Sept. 2002
00036    *
00037    *
00038    * Nine 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^0(T)}{R} = a_0 T^{-2} + a_1 T^{-1} + a_2 + a_3 T 
00043    *                  + a_4 T^2 + a_5 T^3 + a_6 T^4
00044    * \f]
00045    * 
00046    * \f[
00047    * \frac{H^0(T)}{RT} = - a_0 T^{-2} + a_1 \frac{\ln(T)}{T} + a_2 
00048    * + a_3 T + a_4 T^2  + a_5 T^3 + a_6 T^4 + \frac{a_7}{T}
00049    * \f]
00050    *
00051    * \f[
00052    * \frac{s^0(T)}{R} = - \frac{a_0}{2} T^{-2} - a_1 T^{-1} + a_2 \ln(T)
00053    +    + a_3 T  \frac{a_4}{2} T^2 + \frac{a_5}{3} T^3  + \frac{a_6}{4} T^4 + a_8 
00054    * \f]
00055    * 
00056    *  The standard state is assumed to be the ideal gas at the
00057    *  standard pressure of 1 bar, for gases.
00058    *  For condensed species, the standard state is the
00059    *  pure crystalline or liquid substance at the standard
00060    *  pressure of 1 atm.
00061    * 
00062    * These NASA representations may have more than 2 temperature regions.
00063    *
00064    * @ingroup spthermo
00065    */
00066  
00067 
00068   //! Empty constructor
00069   Nasa9Poly1::Nasa9Poly1() 
00070     : m_lowT(0.0), m_highT (0.0),
00071       m_Pref(1.0E5), m_index (0), m_coeff(array_fp(9)) {}
00072 
00073 
00074   // constructor used in templated instantiations
00075   /*
00076    * @param n            Species index
00077    * @param tlow         Minimum temperature
00078    * @param thigh        Maximum temperature
00079    * @param pref         reference pressure (Pa).
00080    * @param coeffs       Vector of coefficients used to set the
00081    *                     parameters for the standard state.
00082    */
00083   Nasa9Poly1::Nasa9Poly1(int n, doublereal tlow, doublereal thigh, 
00084                          doublereal pref,
00085                          const doublereal* coeffs) :
00086     m_lowT      (tlow),
00087     m_highT     (thigh),
00088     m_Pref      (pref),
00089     m_index     (n),
00090     m_coeff     (array_fp(9)) {
00091     std::copy(coeffs, coeffs + 9, m_coeff.begin());
00092   }
00093 
00094   // copy constructor
00095   /*
00096    * @param b object to be copied
00097    */
00098   Nasa9Poly1::Nasa9Poly1(const Nasa9Poly1& b) :
00099     m_lowT      (b.m_lowT),
00100     m_highT     (b.m_highT),
00101     m_Pref      (b.m_Pref),
00102     m_index     (b.m_index),
00103     m_coeff     (array_fp(9)) {
00104     std::copy(b.m_coeff.begin(),
00105               b.m_coeff.begin() + 9,
00106               m_coeff.begin());
00107   }
00108 
00109   // assignment operator
00110   /*
00111    * @param b object to be copied
00112    */
00113   Nasa9Poly1& Nasa9Poly1::operator=(const Nasa9Poly1& b) {
00114     if (&b != this) {
00115       m_lowT   = b.m_lowT;
00116       m_highT  = b.m_highT;
00117       m_Pref   = b.m_Pref;
00118       m_index  = b.m_index;
00119       std::copy(b.m_coeff.begin(),
00120                 b.m_coeff.begin() + 9,
00121                 m_coeff.begin());
00122     }
00123     return *this;
00124   }
00125 
00126   // Destructor
00127   Nasa9Poly1::~Nasa9Poly1() {
00128   }
00129 
00130   // duplicator
00131   SpeciesThermoInterpType *
00132   Nasa9Poly1::duplMyselfAsSpeciesThermoInterpType() const {
00133     Nasa9Poly1* np = new Nasa9Poly1(*this);
00134     return (SpeciesThermoInterpType *) np;
00135   }
00136 
00137   // Returns the minimum temperature that the thermo
00138   // parameterization is valid
00139   doublereal Nasa9Poly1::minTemp() const     { return m_lowT;}
00140 
00141   // Returns the maximum temperature that the thermo
00142   // parameterization is valid
00143   doublereal Nasa9Poly1::maxTemp() const  { 
00144     return m_highT;
00145   }
00146 
00147   // Returns the reference pressure (Pa)
00148   doublereal Nasa9Poly1::refPressure() const { return m_Pref; }
00149 
00150   // Returns an integer representing the type of parameterization
00151   int Nasa9Poly1::reportType() const {
00152     return NASA9;
00153   }
00154       
00155   // Returns an integer representing the species index
00156   int Nasa9Poly1::speciesIndex() const { 
00157     return m_index;
00158   }
00159 
00160   // Update the properties for this species, given a temperature polynomial
00161   /*
00162    * This method is called with a pointer to an array containing the functions of
00163    * temperature needed by this  parameterization, and three pointers to arrays where the
00164    * computed property values should be written. This method updates only one value in
00165    * each array.
00166    *
00167    * Temperature Polynomial:
00168    *  tt[0] = t;
00169    *  tt[1] = t*t;
00170    *  tt[2] = t*t*t;
00171    *  tt[3] = t*t*t*t;
00172    *  tt[4] = 1.0/t;
00173    *  tt[5] = 1.0/(t*t);
00174    *  tt[6] = std::log(t);
00175    *
00176    * @param tt      vector of temperature polynomials
00177    * @param cp_R    Vector of Dimensionless heat capacities.
00178    *                (length m_kk).
00179    * @param h_RT    Vector of Dimensionless enthalpies.
00180    *                (length m_kk).
00181    * @param s_R     Vector of Dimensionless entropies.
00182    *                (length m_kk).
00183    */
00184   void Nasa9Poly1::updateProperties(const doublereal* tt, 
00185                                     doublereal* cp_R, doublereal* h_RT,
00186                                     doublereal* s_R) const {
00187           
00188     doublereal ct0 = m_coeff[0] * tt[5];   // a0 / (T^2)
00189     doublereal ct1 = m_coeff[1] * tt[4];   // a1 / T
00190     doublereal ct2 = m_coeff[2];           // a2
00191     doublereal ct3 = m_coeff[3] * tt[0];   // a3 * T
00192     doublereal ct4 = m_coeff[4] * tt[1];   // a4 * T^2
00193     doublereal ct5 = m_coeff[5] * tt[2];   // a5 * T^3
00194     doublereal ct6 = m_coeff[6] * tt[3];   // a6 * T^4
00195  
00196 
00197     doublereal cpdivR = ct0 + ct1 + ct2 + ct3 + ct4 + ct5 + ct6;
00198     doublereal hdivRT = -ct0 + tt[6]*ct1  + ct2 + 0.5*ct3 + OneThird*ct4  
00199       + 0.25*ct5  + 0.2*ct6 + m_coeff[7] * tt[4]; 
00200     doublereal sdivR  = -0.5*ct0  - ct1 + tt[6]*ct2  + ct3  + 0.5*ct4 
00201       + OneThird*ct5 + 0.25*ct6 + m_coeff[8]; 
00202 
00203     // return the computed properties in the location in the output 
00204     // arrays for this species
00205     cp_R[m_index] = cpdivR;
00206     h_RT[m_index] = hdivRT;
00207     s_R[m_index] = sdivR;
00208     //writelog("NASA9poly1: for species "+int2str(m_index)+", h_RT = "+
00209     //    fp2str(h)+"\n");
00210   }
00211 
00212  
00213   // Compute the reference-state property of one species
00214   /*
00215    * Given temperature T in K, this method updates the values of
00216    * the non-dimensional heat capacity at constant pressure,
00217    * enthalpy, and entropy, at the reference pressure, Pref
00218    * of one of the species. The species index is used
00219    * to reference into the cp_R, h_RT, and s_R arrays.
00220    *
00221    * Temperature Polynomial:
00222    *  tt[0] = t;
00223    *  tt[1] = t*t;
00224    *  tt[2] = t*t*t;
00225    *  tt[3] = t*t*t*t;
00226    *  tt[4] = 1.0/t;
00227    *  tt[5] = 1.0/(t*t);
00228    *  tt[6] = std::log(t);
00229    *
00230    * @param temp    Temperature (Kelvin)
00231    * @param cp_R    Vector of Dimensionless heat capacities.
00232    *                (length m_kk).
00233    * @param h_RT    Vector of Dimensionless enthalpies.
00234    *                (length m_kk).
00235    * @param s_R     Vector of Dimensionless entropies.
00236    *                (length m_kk).
00237    */
00238   void Nasa9Poly1::updatePropertiesTemp(const doublereal temp, 
00239                                         doublereal* cp_R, doublereal* h_RT, 
00240                                         doublereal* s_R) const {
00241     double tPoly[7];
00242     tPoly[0]  = temp;
00243     tPoly[1]  = temp * temp;
00244     tPoly[2]  = tPoly[1] * temp;
00245     tPoly[3]  = tPoly[2] * temp;
00246     tPoly[4]  = 1.0 / temp;
00247     tPoly[5]  = tPoly[4] / temp;
00248     tPoly[6]  = std::log(temp);
00249     updateProperties(tPoly, cp_R, h_RT, s_R);
00250   }
00251 
00252   //This utility function reports back the type of 
00253   // parameterization and all of the parameters for the 
00254   // species, index.
00255   /*
00256    * All parameters are output variables
00257    *
00258    * @param n         Species index
00259    * @param type      Integer type of the standard type
00260    * @param tlow      output - Minimum temperature
00261    * @param thigh     output - Maximum temperature
00262    * @param pref      output - reference pressure (Pa).
00263    * @param coeffs    Vector of coefficients used to set the
00264    *                  parameters for the standard state.
00265    */
00266   void Nasa9Poly1::reportParameters(int &n, int &type,
00267                                     doublereal &tlow, doublereal &thigh,
00268                                     doublereal &pref,
00269                                     doublereal* const coeffs) const {
00270     n = m_index;
00271     type = NASA9;
00272     tlow = m_lowT;
00273     thigh = m_highT;
00274     pref = m_Pref;
00275     coeffs[0] = 1;
00276     coeffs[1] = m_lowT;
00277     coeffs[2] = m_highT;
00278     for (int i = 0; i < 9; i++) {
00279       coeffs[i+3] = m_coeff[i];
00280     }
00281 
00282   }
00283 
00284   // Modify parameters for the standard state
00285   /*
00286    * @param coeffs   Vector of coefficients used to set the
00287    *                 parameters for the standard state.
00288    */
00289   void Nasa9Poly1::modifyParameters(doublereal* coeffs) {
00290     for (int i = 0; i < 9; i++) {
00291       m_coeff[i] = coeffs[i];
00292     }            
00293   }
00294 
00295 
00296 }
00297 
Generated by  doxygen 1.6.3