Cantera  2.2.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ShomateThermo.h
Go to the documentation of this file.
1 /**
2  * @file ShomateThermo.h
3  * Header for the 2 regions Shomate polynomial
4  * for multiple species in a phase, derived from the
5  * \link Cantera::SpeciesThermo SpeciesThermo\endlink base class (see \ref mgrsrefcalc and
6  * \link Cantera::ShomateThermo ShomateThermo\endlink).
7  */
8 // Copyright 2001 California Institute of Technology
9 
10 #ifndef CT_SHOMATETHERMO_H
11 #define CT_SHOMATETHERMO_H
12 
15 #include "cantera/base/global.h"
16 #include "cantera/base/utilities.h"
17 
18 namespace Cantera
19 {
20 //! A species thermodynamic property manager for the Shomate polynomial parameterization.
21 /*!
22  * This is the parameterization used
23  * in the NIST Chemistry WebBook (http://webbook.nist.gov/chemistry)
24  * The parameterization assumes there are two temperature regions
25  * each with its own Shomate polynomial representation, for each
26  * species in the phase.
27  *
28  * \f[
29  * \tilde{c}_p^0(T) = A + B t + C t^2 + D t^3 + \frac{E}{t^2}
30  * \f]
31  * \f[
32  * \tilde{h}^0(T) = A t + \frac{B t^2}{2} + \frac{C t^3}{3}
33  + \frac{D t^4}{4} - \frac{E}{t} + F.
34  * \f]
35  * \f[
36  * \tilde{s}^0(T) = A\ln t + B t + \frac{C t^2}{2}
37  + \frac{D t^3}{3} - \frac{E}{2t^2} + G.
38  * \f]
39  *
40  * In the above expressions, the thermodynamic polynomials are expressed
41  * in dimensional units, but the temperature,\f$ t \f$, is divided by 1000. The
42  * following dimensions are assumed in the above expressions:
43  *
44  * - \f$ \tilde{c}_p^0(T)\f$ = Heat Capacity (J/gmol*K)
45  * - \f$ \tilde{h}^0(T) \f$ = standard Enthalpy (kJ/gmol)
46  * - \f$ \tilde{s}^0(T) \f$= standard Entropy (J/gmol*K)
47  * - \f$ t \f$= temperature (K) / 1000.
48  *
49  * Note, the polynomial data (i.e., A, ... , G) is entered in dimensional form.
50  *
51  * This is in contrast to the NASA database polynomials which are entered in
52  * nondimensional form (i.e., NASA parameterizes C_p/R, while Shomate
53  * parameterizes C_p assuming units of J/gmol*K - and kJ/gmol*K for H).
54  * Note, also that the H - H_298.15 equation has units of kJ/gmol, because of
55  * the implicit integration of (t = T 1000), which provides a
56  * multiplier of 1000 to the Enthalpy equation.
57  *
58  * @deprecated To be removed after Cantera 2.2. Use GeneralSpeciesThermo instead.
59  * @ingroup mgrsrefcalc
60  */
62 {
63 public:
64  //! Initialized to the type of parameterization
65  /*!
66  * Note, this value is used in some template functions
67  */
68  const int ID;
69 
70  //! constructor
72  ID(SHOMATE),
73  m_tlow_max(0.0),
74  m_thigh_min(1.e30),
75  m_p0(-1.0),
76  m_ngroups(0) {
77  warn_deprecated("class ShomateThermo", "To be removed after "
78  "Cantera 2.2. Use GeneralSpeciesThermo instead.");
79  m_t.resize(7);
80  }
81 
82  //! Copy Constructor
83  /*!
84  * @param right Object to be copied
85  */
86  ShomateThermo(const ShomateThermo& right) :
87  ID(SHOMATE),
88  m_tlow_max(0.0),
89  m_thigh_min(1.e30),
90  m_p0(-1.0),
91  m_ngroups(0) {
92  *this = right;
93  }
94 
95  //! Assignment Operator
96  /*!
97  * @param right Object to be copied
98  */
100  if (&right == this) {
101  return *this;
102  }
103 
104  SpeciesThermo::operator=(right);
105  m_high = right.m_high;
106  m_low = right.m_low;
107  m_index = right.m_index;
108  m_tmid = right.m_tmid;
109  m_tlow_max = right.m_tlow_max;
110  m_thigh_min = right.m_thigh_min;
111  m_tlow = right.m_tlow;
112  m_thigh = right.m_thigh;
113  m_p0 = right.m_p0;
114  m_ngroups = right.m_ngroups;
115  m_t = right.m_t;
116  m_group_map = right.m_group_map;
118 
119  return *this;
120  }
121 
123  return new ShomateThermo(*this);
124  }
125 
126  //! Install a new species thermodynamic property
127  //! parameterization for one species using Shomate polynomials
128  /*!
129  * Two temperature regions are assumed.
130  *
131  * @param name Name of the species
132  * @param index Species index
133  * @param type int flag specifying the type of parameterization to be
134  * installed.
135  * @param c Vector of coefficients for the parameterization.
136  * There are 15 coefficients for the 2-zone Shomate polynomial.
137  * The first coefficient is the value of Tmid. The next 7
138  * coefficients are the low temperature range Shomate coefficients.
139  * The last 7 are the high temperature range Shomate coefficients.
140  *
141  * @param minTemp minimum temperature for which this parameterization
142  * is valid.
143  * @param maxTemp maximum temperature for which this parameterization
144  * is valid.
145  * @param refPressure standard-state pressure for this
146  * parameterization.
147  *
148  * @see ShomatePoly
149  * @see ShomatePoly2
150  */
151  virtual void install(const std::string& name, size_t index, int type,
152  const doublereal* c,
153  doublereal minTemp, doublereal maxTemp,
154  doublereal refPressure) {
155  if (type != SHOMATE) {
156  throw CanteraError("ShomateThermo::install",
157  "Incompatible thermo parameterization: Got " +
158  int2str(type) + " but " + int2str(SHOMATE) +
159  " was expected.");
160  }
161  int imid = int(c[0]); // midpoint temp converted to integer
162  int igrp = m_index[imid]; // has this value been seen before?
163  if (igrp == 0) { // if not, prepare new group
164  std::vector<ShomatePoly> v;
165  m_high.push_back(v);
166  m_low.push_back(v);
167  m_tmid.push_back(c[0]);
168  m_index[imid] = igrp = static_cast<int>(m_high.size());
169  m_ngroups++;
170  }
171  m_group_map[index] = igrp;
172  m_posInGroup_map[index] = (int) m_low[igrp-1].size();
173  doublereal tlow = minTemp;
174  doublereal tmid = c[0];
175  doublereal thigh = maxTemp;
176 
177  const doublereal* clow = c + 1;
178  const doublereal* chigh = c + 8;
179  m_high[igrp-1].push_back(ShomatePoly(index, tmid, thigh,
180  refPressure, chigh));
181  m_low[igrp-1].push_back(ShomatePoly(index, tlow, tmid,
182  refPressure, clow));
183  m_tlow_max = std::max(m_tlow_max, tlow);
184  m_thigh_min = std::min(m_thigh_min, thigh);
185  if (m_tlow.size() < index + 1) {
186  m_tlow.resize(index + 1, tlow);
187  m_thigh.resize(index + 1, thigh);
188  }
189  m_tlow[index] = tlow;
190  m_thigh[index] = thigh;
191 
192  if (m_p0 < 0.0) {
193  m_p0 = refPressure;
194  } else if (fabs(m_p0 - refPressure) > 0.1) {
195  std::string logmsg = " ERROR ShomateThermo: New Species, " + name
196  + ", has a different reference pressure, "
197  + fp2str(refPressure) + ", than existing reference pressure, " + fp2str(m_p0) + "\n";
198  writelog(logmsg);
199  logmsg = " This is now a fatal error\n";
200  writelog(logmsg);
201  throw CanteraError("install()", "Species have different reference pressures");
202  }
203  m_p0 = refPressure;
204  markInstalled(index);
205  }
206 
207  virtual void install_STIT(size_t index,
208  shared_ptr<SpeciesThermoInterpType> stit_ptr) {
209  throw CanteraError("install_STIT", "not implemented");
210  }
211 
212  //! Like update(), but only updates the single species k.
213  /*!
214  * @param k species index
215  * @param t Temperature (Kelvin)
216  * @param cp_R Vector of Dimensionless heat capacities. (length m_kk).
217  * @param h_RT Vector of Dimensionless enthalpies. (length m_kk).
218  * @param s_R Vector of Dimensionless entropies. (length m_kk).
219  */
220  virtual void update_one(size_t k, doublereal t, doublereal* cp_R,
221  doublereal* h_RT, doublereal* s_R) const {
222  doublereal tt = 1.e-3*t;
223  m_t[0] = tt;
224  m_t[1] = tt*tt;
225  m_t[2] = m_t[1]*tt;
226  m_t[3] = 1.0/m_t[1];
227  m_t[4] = log(tt);
228  m_t[5] = 1.0/GasConstant;
229  m_t[6] = 1.0/(GasConstant * t);
230 
231  size_t grp = getValue(m_group_map, k);
232  size_t pos = getValue(m_posInGroup_map, k);
233  const std::vector<ShomatePoly> &mlg = m_low[grp-1];
234  const ShomatePoly* nlow = &(mlg[pos]);
235 
236  if (t < nlow->maxTemp()) {
237  nlow->updateProperties(&m_t[0], cp_R, h_RT, s_R);
238  } else {
239  const std::vector<ShomatePoly> &mhg = m_high[grp-1];
240  const ShomatePoly* nhigh = &(mhg[pos]);
241  nhigh->updateProperties(&m_t[0], cp_R, h_RT, s_R);
242  }
243  }
244 
245  virtual void update(doublereal t, doublereal* cp_R,
246  doublereal* h_RT, doublereal* s_R) const {
247  doublereal tt = 1.e-3*t;
248  m_t[0] = tt;
249  m_t[1] = tt*tt;
250  m_t[2] = m_t[1]*tt;
251  m_t[3] = 1.0/m_t[1];
252  m_t[4] = log(tt);
253  m_t[5] = 1.0/GasConstant;
254  m_t[6] = 1.0/(GasConstant * t);
255 
256  std::vector<ShomatePoly>::const_iterator _begin, _end;
257  for (int i = 0; i != m_ngroups; i++) {
258  if (t > m_tmid[i]) {
259  _begin = m_high[i].begin();
260  _end = m_high[i].end();
261  } else {
262  _begin = m_low[i].begin();
263  _end = m_low[i].end();
264  }
265  for (; _begin != _end; ++_begin) {
266  _begin->updateProperties(&m_t[0], cp_R, h_RT, s_R);
267  }
268  }
269  }
270 
271  virtual doublereal minTemp(size_t k=npos) const {
272  if (k == npos) {
273  return m_tlow_max;
274  } else {
275  return m_tlow[k];
276  }
277  }
278 
279  virtual doublereal maxTemp(size_t k=npos) const {
280  if (k == npos) {
281  return m_thigh_min;
282  } else {
283  return m_thigh[k];
284  }
285  }
286 
287  virtual doublereal refPressure(size_t k=npos) const {
288  return m_p0;
289  }
290 
291  virtual int reportType(size_t index) const {
292  return SHOMATE;
293  }
294 
295  virtual void reportParams(size_t index, int& type,
296  doublereal* const c,
297  doublereal& minTemp,
298  doublereal& maxTemp,
299  doublereal& refPressure) const {
300  type = reportType(index);
301  if (type == SHOMATE) {
302  size_t grp = getValue(m_group_map, index);
303  size_t pos = getValue(m_posInGroup_map, index);
304  int itype = SHOMATE;
305  const std::vector<ShomatePoly> &mlg = m_low[grp-1];
306  const std::vector<ShomatePoly> &mhg = m_high[grp-1];
307  const ShomatePoly* lowPoly = &(mlg[pos]);
308  const ShomatePoly* highPoly = &(mhg[pos]);
309  doublereal tmid = lowPoly->maxTemp();
310  c[0] = tmid;
311  size_t n;
312  double ttemp;
313  lowPoly->reportParameters(n, itype, minTemp, ttemp, refPressure,
314  c + 1);
315  if (n != index) {
316  throw CanteraError("ShomateThermo::reportParams",
317  "Index mismatch in low-T polynomial");
318  }
319  if (itype != SHOMATE && itype != SHOMATE1) {
320  throw CanteraError("ShomateThermo::reportParams",
321  "Thermo type mismatch in low-T polynomial");
322  }
323  highPoly->reportParameters(n, itype, ttemp, maxTemp,
324  refPressure, c + 8);
325  if (n != index) {
326  throw CanteraError("ShomateThermo::reportParams",
327  "Index mismatch in high-T polynomial");
328  }
329  if (itype != SHOMATE && itype != SHOMATE1) {
330  throw CanteraError("ShomateThermo::reportParams",
331  "Thermo type mismatch in high-T polynomial");
332  }
333  } else {
334  throw CanteraError("ShomateThermo::reportParams", "Thermo type mismatch");
335  }
336  }
337 
338  virtual doublereal reportOneHf298(const size_t k) const {
339  size_t grp = getValue(m_group_map, k);
340  size_t pos = getValue(m_posInGroup_map, k);
341  const ShomatePoly& nlow = m_low[grp-1][pos];
342 
343  if (nlow.maxTemp() > 298.15) {
344  return nlow.reportHf298();
345  } else {
346  const ShomatePoly& nhigh = m_high[grp-1][pos];
347  return nhigh.reportHf298();
348  }
349  }
350 
351  virtual void modifyOneHf298(const size_t k, const doublereal Hf298New) {
352 
353  size_t grp = m_group_map[k];
354  size_t pos = m_posInGroup_map[k];
355  ShomatePoly& nlow = m_low[grp-1][pos];
356  ShomatePoly& nhigh = m_high[grp-1][pos];
357 
358  double hnow = reportOneHf298(k);
359  double delH = Hf298New - hnow;
360  if (nlow.maxTemp() > 298.15) {
361  nlow.modifyOneHf298(k, Hf298New);
362  double h = nhigh.reportHf298(0);
363  double hnew = h + delH;
364  nhigh.modifyOneHf298(k, hnew);
365  } else {
366  nhigh.modifyOneHf298(k, Hf298New);
367  double h = nlow.reportHf298(0);
368  double hnew = h + delH;
369  nlow.modifyOneHf298(k, hnew);
370  }
371 
372  }
373 
374 protected:
375  //! Vector of vector of NasaPoly1's for the high temp region.
376  /*!
377  * This is the high temp region representation. The first Length is equal
378  * to the number of groups. The second vector is equal to the number of
379  * species in that particular group.
380  */
381  std::vector<std::vector<ShomatePoly> > m_high;
382 
383  //! Vector of vector of NasaPoly1's for the low temp region.
384  /*!
385  * This is the low temp region representation. The first Length is equal
386  * to the number of groups. The second vector is equal to the number of
387  * species in that particular group.
388  */
389  std::vector<std::vector<ShomatePoly> > m_low;
390 
391  //! Map between the midpoint temperature, as an int, to the group number
392  /*!
393  * Length is equal to the number of groups. Only used in the setup.
394  */
395  std::map<int, int> m_index;
396 
397  //! Vector of log temperature limits
398  /*!
399  * Length is equal to the number of groups.
400  */
402 
403  //! Maximum value of the low temperature limit
404  doublereal m_tlow_max;
405 
406  //! Minimum value of the high temperature limit
407  doublereal m_thigh_min;
408 
409  //! Vector of low temperature limits (species index)
410  /*!
411  * Length is equal to number of species
412  */
414 
415  //! Vector of low temperature limits (species index)
416  /*!
417  * Length is equal to number of species
418  */
420 
421  //! Reference pressure (Pa)
422  /*!
423  * all species must have the same reference pressure.
424  */
425  doublereal m_p0;
426 
427  //! number of groups
429 
430  //! Vector of temperature polynomials
431  mutable vector_fp m_t;
432 
433  /*!
434  * This map takes as its index, the species index in the phase.
435  * It returns the group index, where the temperature polynomials
436  * for that species are stored. group indices start at 1,
437  * so a decrement is always performed to access vectors.
438  */
439  std::map<size_t, size_t> m_group_map;
440 
441  /*!
442  * This map takes as its index, the species index in the phase.
443  * It returns the position index within the group, where the
444  * temperature polynomials for that species are stored.
445  */
446  std::map<size_t, size_t> m_posInGroup_map;
447 };
448 
449 }
450 
451 #endif
vector_fp m_tlow
Vector of low temperature limits (species index)
virtual void install(const std::string &name, size_t index, int type, const doublereal *c, doublereal minTemp, doublereal maxTemp, doublereal refPressure)
Install a new species thermodynamic property parameterization for one species using Shomate polynomia...
std::string int2str(const int n, const std::string &fmt)
Convert an int to a string using a format converter.
Definition: stringUtils.cpp:39
virtual int reportType(size_t index) const
This utility function reports the type of parameterization used for the species with index number ind...
const int ID
Initialized to the type of parameterization.
Definition: ShomateThermo.h:68
#define SHOMATE
Two regions of Shomate Polynomials.
doublereal m_p0
Reference pressure (Pa)
Various templated functions that carry out common vector operations (see Templated Utility Functions)...
const size_t npos
index returned by functions to indicate "no position"
Definition: ct_defs.h:165
virtual void reportParameters(size_t &n, int &type, doublereal &tlow, doublereal &thigh, doublereal &pref, doublereal *const coeffs) const
This utility function reports back the type of parameterization and all of the parameters for the spe...
Definition: ShomatePoly.h:214
virtual void updateProperties(const doublereal *tt, doublereal *cp_R, doublereal *h_RT, doublereal *s_R) const
Update the properties for this species, given a temperature polynomial.
Definition: ShomatePoly.h:175
std::vector< std::vector< ShomatePoly > > m_low
Vector of vector of NasaPoly1's for the low temp region.
vector_fp m_t
Vector of temperature polynomials.
doublereal m_tlow_max
Maximum value of the low temperature limit.
void warn_deprecated(const std::string &method, const std::string &extra)
Print a warning indicating that method is deprecated.
Definition: global.cpp:78
This file contains definitions for utility functions and text for modules, inputfiles, logs, textlogs, (see Input File Handling, Diagnostic Output, and Writing messages to the screen).
virtual doublereal reportHf298(doublereal *const h298=0) const
Report the 298 K Heat of Formation of the standard state of one species (J kmol-1) ...
Definition: ShomatePoly.h:241
virtual void reportParams(size_t index, int &type, doublereal *const c, doublereal &minTemp, doublereal &maxTemp, doublereal &refPressure) const
This utility function reports back the type of parameterization and all of the parameters for the spe...
Pure Virtual base class for the species thermo manager classes.
ShomateThermo(const ShomateThermo &right)
Copy Constructor.
Definition: ShomateThermo.h:86
std::map< size_t, size_t > m_posInGroup_map
virtual doublereal reportOneHf298(const size_t k) const
Report the 298 K Heat of Formation of the standard state of one species (J kmol-1) ...
std::map< size_t, size_t > m_group_map
void markInstalled(size_t k)
Mark species k as having its thermodynamic data installed.
virtual doublereal maxTemp() const
Returns the maximum temperature that the thermo parameterization is valid.
std::vector< std::vector< ShomatePoly > > m_high
Vector of vector of NasaPoly1's for the high temp region.
virtual void modifyOneHf298(const size_t k, const doublereal Hf298New)
Modify the value of the 298 K Heat of Formation of one species in the phase (J kmol-1) ...
Definition: ShomatePoly.h:260
doublereal m_thigh_min
Minimum value of the high temperature limit.
std::map< int, int > m_index
Map between the midpoint temperature, as an int, to the group number.
The Shomate polynomial parameterization for one temperature range for one species.
Definition: ShomatePoly.h:56
Header for a single-species standard state object derived from SpeciesThermoInterpType based on the S...
ShomateThermo & operator=(const ShomateThermo &right)
Assignment Operator.
Definition: ShomateThermo.h:99
std::string fp2str(const double x, const std::string &fmt)
Convert a double into a c++ string.
Definition: stringUtils.cpp:28
virtual void install_STIT(size_t index, shared_ptr< SpeciesThermoInterpType > stit_ptr)
Install a new species thermodynamic property parameterization for one species.
virtual void update(doublereal t, doublereal *cp_R, doublereal *h_RT, doublereal *s_R) const
Compute the reference-state properties for all species.
Base class for exceptions thrown by Cantera classes.
Definition: ctexceptions.h:99
const U & getValue(const std::map< T, U > &m, const T &key)
Const accessor for a value in a std::map.
Definition: utilities.h:714
vector_fp m_thigh
Vector of low temperature limits (species index)
virtual doublereal minTemp(size_t k=npos) const
Minimum temperature.
virtual doublereal refPressure(size_t k=npos) const
The reference-state pressure for species k.
int m_ngroups
number of groups
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)
A species thermodynamic property manager for the Shomate polynomial parameterization.
Definition: ShomateThermo.h:61
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:157
virtual doublereal maxTemp(size_t k=npos) const
Maximum temperature.
virtual SpeciesThermo * duplMyselfAsSpeciesThermo() const
Duplication routine for objects derived from SpeciesThermo.
const doublereal GasConstant
Universal Gas Constant. [J/kmol/K].
Definition: ct_defs.h:64
vector_fp m_tmid
Vector of log temperature limits.
ShomateThermo()
constructor
Definition: ShomateThermo.h:71
void writelog(const std::string &msg)
Write a message to the screen.
Definition: global.cpp:33
virtual void modifyOneHf298(const size_t k, const doublereal Hf298New)
Modify the value of the 298 K Heat of Formation of the standard state of one species in the phase (J ...
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.
#define SHOMATE1
one region of Shomate Polynomials used in NIST database This is implemented in the NIST database...