Cantera  2.1.2
NasaThermo.h
Go to the documentation of this file.
1 /**
2  * @file NasaThermo.h
3  * Header for the 2 regime 7 coefficient Nasa thermodynamic
4  * polynomials for multiple species in a phase, derived from the
5  * \link Cantera::SpeciesThermo SpeciesThermo\endlink base class (see \ref mgrsrefcalc and
6  * \link Cantera::NasaThermo NasaThermo\endlink).
7  */
8 // Copyright 2003 California Institute of Technology
9 
10 #ifndef CT_NASATHERMO_H
11 #define CT_NASATHERMO_H
12 
16 #include "cantera/base/global.h"
17 
18 namespace Cantera
19 {
20 /**
21  * A species thermodynamic property manager for the NASA
22  * polynomial parameterization with two temperature ranges.
23  *
24  * This class is designed to efficiently evaluate the properties
25  * of a large number of species with the NASA parameterization.
26  *
27  * The original NASA polynomial parameterization expressed the
28  * heat capacity as a fourth-order polynomial in temperature, with
29  * separate coefficients for each of two temperature ranges. (The
30  * newer NASA format adds coefficients for 1/T and 1/T^2, and
31  * allows multiple temperature ranges.) This class is designed for
32  * use with the original parameterization, which is used, for
33  * example, by the Chemkin software package.
34  *
35  * In many cases, the midpoint temperature is the same for many
36  * species. To take advantage of this, class NasaThermo groups
37  * species with a common midpoint temperature, so that checking
38  * which range the desired temperature is in need be done only
39  * once for each group.
40  *
41  * @note There is a special CTML element for entering the
42  * coefficients of this parameterization.
43  * @see importCTML
44  *
45  * @ingroup mgrsrefcalc
46  */
47 class NasaThermo : public SpeciesThermo
48 {
49 public:
50  NasaThermo();
51 
52  NasaThermo(const NasaThermo& right);
53 
54  NasaThermo& operator=(const NasaThermo& right);
55 
57  NasaThermo* nt = new NasaThermo(*this);
58  return (SpeciesThermo*) nt;
59  }
60 
61  //! install a new species thermodynamic property
62  //! parameterization for one species.
63  /*!
64  * @param name Name of the species
65  * @param index The 'update' method will update the property values for
66  * this species at position i index in the property
67  * arrays.
68  * @param type int flag specifying the type of parameterization to be
69  * installed.
70  * @param c vector of coefficients for the parameterization.
71  * - c[0] midpoint temperature
72  * - c[1] - c[7] coefficients for low T range
73  * - c[8] - c[14] coefficients for high T range
74  * @param min_temp minimum temperature for which this parameterization
75  * is valid.
76  * @param max_temp maximum temperature for which this parameterization
77  * is valid.
78  * @param ref_pressure standard-state pressure for this parameterization.
79  * @see speciesThermoTypes.h
80  */
81  virtual void install(const std::string& name, size_t index, int type,
82  const doublereal* c,
83  doublereal min_temp, doublereal max_temp,
84  doublereal ref_pressure);
85 
86  virtual void install_STIT(SpeciesThermoInterpType* stit_ptr) {
87  throw CanteraError("install_STIT", "not implemented");
88  }
89 
90  //! Like update(), but only updates the single species k.
91  /*!
92  * @param k species index
93  * @param t Temperature (Kelvin)
94  * @param cp_R Vector of Dimensionless heat capacities. (length m_kk).
95  * @param h_RT Vector of Dimensionless enthalpies. (length m_kk).
96  * @param s_R Vector of Dimensionless entropies. (length m_kk).
97  */
98  virtual void update_one(size_t k, doublereal t, doublereal* cp_R,
99  doublereal* h_RT, doublereal* s_R) const;
100 
101  virtual void update(doublereal t, doublereal* cp_R,
102  doublereal* h_RT, doublereal* s_R) const;
103 
104  virtual doublereal minTemp(size_t k=npos) const {
105  if (k == npos) {
106  return m_tlow_max;
107  } else {
108  return m_tlow[k];
109  }
110  }
111 
112  virtual doublereal maxTemp(size_t k=npos) const {
113  if (k == npos) {
114  return m_thigh_min;
115  } else {
116  return m_thigh[k];
117  }
118  }
119 
120  virtual doublereal refPressure(size_t k=npos) const {
121  return m_p0;
122  }
123 
124  virtual int reportType(size_t index) const {
125  return NASA;
126  }
127 
128  /*!
129  * This utility function reports back the type of
130  * parameterization and all of the parameters for the
131  * species, index.
132  *
133  * @param index Species index
134  * @param type Integer type of the standard type
135  * @param c Vector of coefficients used to set the
136  * parameters for the standard state.
137  * For the NASA object, there are 15 coefficients.
138  * @param minTemp output - Minimum temperature
139  * @param maxTemp output - Maximum temperature
140  * @param refPressure output - reference pressure (Pa).
141  * @deprecated
142  */
143  virtual void reportParams(size_t index, int& type,
144  doublereal* const c,
145  doublereal& minTemp,
146  doublereal& maxTemp,
147  doublereal& refPressure) const;
148 
149 #ifdef H298MODIFY_CAPABILITY
150  virtual doublereal reportOneHf298(const int k) const;
151  virtual void modifyOneHf298(const int k, const doublereal Hf298New);
152 #endif
153 
154  //! Initialized to the type of parameterization
155  /*!
156  * Note, this value is used in some template functions
157  */
158  const int ID;
159 
160 protected:
161  //! Vector of vector of NasaPoly1's for the high temp region.
162  /*!
163  * This is the high temp region representation.
164  * The first Length is equal to the number of groups.
165  * The second vector is equal to the number of species
166  * in that particular group.
167  */
168  std::vector<std::vector<NasaPoly1> > m_high;
169 
170  //! Vector of vector of NasaPoly1's for the low temp region.
171  /*!
172  * This is the low temp region representation.
173  * The first Length is equal to the number of groups.
174  * The second vector is equal to the number of species
175  * in that particular group.
176  */
177  std::vector<std::vector<NasaPoly1> > m_low;
178 
179  //! Map between the midpoint temperature, as an int, to the group number
180  /*!
181  * Length is equal to the number of groups. Only used in the setup.
182  */
183  std::map<int, int> m_index;
184 
185  //! Vector of log temperature limits
186  /*!
187  * Length is equal to the number of groups.
188  */
190 
191  //! Maximum value of the low temperature limit
192  doublereal m_tlow_max;
193 
194  //! Minimum value of the high temperature limit
195  doublereal m_thigh_min;
196 
197  //! Vector of low temperature limits (species index)
198  /*!
199  * Length is equal to number of species
200  */
202 
203  //! Vector of low temperature limits (species index)
204  /*!
205  * Length is equal to number of species
206  */
208 
209  //! Reference pressure (Pa)
210  /*!
211  * all species must have the same reference pressure.
212  */
213  doublereal m_p0;
214 
215  //! number of groups
217 
218  //! Vector of temperature polynomials
219  mutable vector_fp m_t;
220 
221  /*!
222  * This map takes as its index, the species index in the phase.
223  * It returns the group index, where the temperature polynomials
224  * for that species are stored. group indices start at 1,
225  * so a decrement is always performed to access vectors.
226  */
227  mutable std::map<size_t, size_t> m_group_map;
228 
229  /*!
230  * This map takes as its index, the species index in the phase.
231  * It returns the position index within the group, where the
232  * temperature polynomials for that species are stored.
233  */
234  mutable std::map<size_t, size_t> m_posInGroup_map;
235 
236  //! Species name as a function of the species index
237  mutable std::map<size_t, std::string> m_name;
238 
239 protected:
240  //! Compute the nondimensional heat capacity using the given NASA polynomial
241  /*!
242  * @param t temperature
243  * @param c coefficient array
244  */
245  doublereal cp_R(double t, const doublereal* c);
246 
247  //! Compute the nondimensional enthalpy using the given NASA polynomial
248  /*!
249  * @param t temperature
250  * @param c coefficient array
251  */
252  doublereal enthalpy_RT(double t, const doublereal* c);
253 
254  //! Compute the nondimensional entropy using the given NASA polynomial
255  /*!
256  * @param t temperature
257  * @param c coefficient array
258  */
259  doublereal entropy_R(double t, const doublereal* c);
260 
261  //! Adjust polynomials to be continuous at the midpoint temperature.
262  /*!
263  * Check to see if the provided coefficients are nearly continuous. Adjust
264  * the values to get more precise continuity to avoid convergence
265  * issues with algorithms that expect these quantities to be continuous.
266  *
267  * @param name string name of species
268  * @param tmid Mid temperature, between the two temperature regions
269  * @param clow coefficients for lower temperature region
270  * @param chigh coefficients for higher temperature region
271  */
272  double checkContinuity(const std::string& name, double tmid,
273  doublereal* clow, doublereal* chigh);
274 
275  //! Adjust polynomials to be continuous at the midpoint temperature.
276  /*!
277  * We seek a set of coefficients for the low- and high-temperature
278  * polynomials which are continuous in Cp, H, and S at the midpoint while
279  * minimizing the difference between the values in Cp, H, and S over the
280  * entire valid temperature range. To do this, we formulate a linear
281  * least-squares problem to be solved for 11 of the 14 coefficients, with
282  * the remaining 3 coefficients eliminated in the process of satisfying
283  * the continuity constraints.
284  *
285  * @param Tlow Minimum temperature at which the low-T polynomial is valid
286  * @param Tmid Mid temperature, between the two temperature regions
287  * @param Thigh Maximum temperature at which the high-T polynomial is valid
288  * @param clow coefficients for lower temperature region
289  * @param chigh coefficients for higher temperature region
290  */
291  void fixDiscontinuities(doublereal Tlow, doublereal Tmid, doublereal Thigh,
292  doublereal* clow, doublereal* chigh);
293 };
294 
295 }
296 
297 #endif
Pure Virtual Base class for the thermodynamic manager for an individual species' reference state...
doublereal m_thigh_min
Minimum value of the high temperature limit.
Definition: NasaThermo.h:195
#define NASA
Two regions of 7 coefficient NASA Polynomials This is implemented in the class NasaPoly2 in NasaPoly2...
virtual doublereal minTemp(size_t k=npos) const
Minimum temperature.
Definition: NasaThermo.h:104
std::vector< std::vector< NasaPoly1 > > m_high
Vector of vector of NasaPoly1's for the high temp region.
Definition: NasaThermo.h:168
const size_t npos
index returned by functions to indicate "no position"
Definition: ct_defs.h:173
virtual void update(doublereal t, doublereal *cp_R, doublereal *h_RT, doublereal *s_R) const
Compute the reference-state properties for all species.
Definition: NasaThermo.cpp:149
virtual int reportType(size_t index) const
This utility function reports the type of parameterization used for the species with index number ind...
Definition: NasaThermo.h:124
virtual doublereal refPressure(size_t k=npos) const
The reference-state pressure for species k.
Definition: NasaThermo.h:120
virtual void reportParams(size_t index, int &type, doublereal *const c, doublereal &minTemp, doublereal &maxTemp, doublereal &refPressure) const
Definition: NasaThermo.cpp:178
A species thermodynamic property manager for the NASA polynomial parameterization with two temperatur...
Definition: NasaThermo.h:47
This file contains definitions for utility functions and text for modules, inputfiles, logs, textlogs, HTML_logs (see Input File Handling, Diagnostic Output, Writing messages to the screen and Writing HTML Logfiles).
doublereal m_tlow_max
Maximum value of the low temperature limit.
Definition: NasaThermo.h:192
const int ID
Initialized to the type of parameterization.
Definition: NasaThermo.h:158
Pure Virtual base class for the species thermo manager classes.
doublereal entropy_R(double t, const doublereal *c)
Compute the nondimensional entropy using the given NASA polynomial.
Definition: NasaThermo.cpp:275
Contains const definitions for types of species reference-state thermodynamics managers (see Species ...
double checkContinuity(const std::string &name, double tmid, doublereal *clow, doublereal *chigh)
Adjust polynomials to be continuous at the midpoint temperature.
Definition: NasaThermo.cpp:281
doublereal m_p0
Reference pressure (Pa)
Definition: NasaThermo.h:213
virtual SpeciesThermo * duplMyselfAsSpeciesThermo() const
Duplication routine for objects derived from SpeciesThermo.
Definition: NasaThermo.h:56
doublereal cp_R(double t, const doublereal *c)
Compute the nondimensional heat capacity using the given NASA polynomial.
Definition: NasaThermo.cpp:264
std::map< int, int > m_index
Map between the midpoint temperature, as an int, to the group number.
Definition: NasaThermo.h:183
virtual void install(const std::string &name, size_t index, int type, const doublereal *c, doublereal min_temp, doublereal max_temp, doublereal ref_pressure)
install a new species thermodynamic property parameterization for one species.
Definition: NasaThermo.cpp:58
vector_fp m_tmid
Vector of log temperature limits.
Definition: NasaThermo.h:189
Base class for exceptions thrown by Cantera classes.
Definition: ctexceptions.h:68
int m_ngroups
number of groups
Definition: NasaThermo.h:216
vector_fp m_t
Vector of temperature polynomials.
Definition: NasaThermo.h:219
Header for a single-species standard state object derived from SpeciesThermoInterpType based on the N...
This file contains descriptions of templated subclasses of the virtual base class, SpeciesThermo, which includes SpeciesThermoDuo (see Managers for Calculating Reference-State Thermodynamics and class SpeciesThermoDuo)
doublereal enthalpy_RT(double t, const doublereal *c)
Compute the nondimensional enthalpy using the given NASA polynomial.
Definition: NasaThermo.cpp:269
std::map< size_t, size_t > m_posInGroup_map
Definition: NasaThermo.h:234
std::map< size_t, std::string > m_name
Species name as a function of the species index.
Definition: NasaThermo.h:237
std::vector< double > vector_fp
Turn on the use of stl vectors for the basic array type within cantera Vector of doubles.
Definition: ct_defs.h:165
std::map< size_t, size_t > m_group_map
Definition: NasaThermo.h:227
void fixDiscontinuities(doublereal Tlow, doublereal Tmid, doublereal Thigh, doublereal *clow, doublereal *chigh)
Adjust polynomials to be continuous at the midpoint temperature.
Definition: NasaThermo.cpp:332
vector_fp m_thigh
Vector of low temperature limits (species index)
Definition: NasaThermo.h:207
vector_fp m_tlow
Vector of low temperature limits (species index)
Definition: NasaThermo.h:201
virtual doublereal maxTemp(size_t k=npos) const
Maximum temperature.
Definition: NasaThermo.h:112
virtual void update_one(size_t k, doublereal t, doublereal *cp_R, doublereal *h_RT, doublereal *s_R) const
Like update(), but only updates the single species k.
Definition: NasaThermo.cpp:124
std::vector< std::vector< NasaPoly1 > > m_low
Vector of vector of NasaPoly1's for the low temp region.
Definition: NasaThermo.h:177
virtual void install_STIT(SpeciesThermoInterpType *stit_ptr)
Install a new species thermodynamic property parameterization for one species.
Definition: NasaThermo.h:86