Cantera  2.1.2
SimpleThermo.h
Go to the documentation of this file.
1 /**
2  * @file SimpleThermo.h
3  * Header for the SimpleThermo (constant heat capacity) species reference-state model
4  * for multiple species in a phase, derived from the
7  */
8 #ifndef CT_SIMPLETHERMO_H
9 #define CT_SIMPLETHERMO_H
10
11 #include "SpeciesThermoMgr.h"
12 #include "speciesThermoTypes.h"
13 #include "cantera/base/global.h"
14
15 namespace Cantera
16 {
17 /*!
18  * A constant-heat capacity species thermodynamic property manager class. This
19  * makes the assumption that the heat capacity is a constant. Then, the
20  * following relations are used to complete the specification of the
21  * thermodynamic functions for each species in the phase.
22  *
23  * \f[
24  * \frac{c_p(T)}{R} = Cp0\_R
25  * \f]
26  * \f[
27  * \frac{h^0(T)}{RT} = \frac{1}{T} * (h0\_R + (T - T_0) * Cp0\_R)
28  * \f]
29  * \f[
30  * \frac{s^0(T)}{R} = (s0\_R + (log(T) - log(T_0)) * Cp0\_R)
31  * \f]
32  *
33  * This parameterization takes 4 input values. These are:
34  * - c[0] = \f$T_0 \f$(Kelvin)
35  * - c[1] = \f$H_k^o(T_0, p_{ref}) \f$ (J/kmol)
36  * - c[2] = \f$S_k^o(T_0, p_{ref}) \f$ (J/kmol K)
37  * - c[3] = \f${Cp}_k^o(T_0, p_{ref}) \f$ (J(kmol K)
38  *
39  * All species must have the same reference pressure.
40  * The single-species standard-state property Manager ConstCpPoly has the same
41  * parameterization as the SimpleThermo class does.
42  *
43  * @see ConstCpPoly
44  *
45  * @ingroup mgrsrefcalc
46  */
48 {
49 public:
50  //! The type of parameterization. Note, this value is used in some
51  //! template functions. For this object the value is SIMPLE.
52  const int ID;
53
54  //! Constructor
56  ID(SIMPLE),
57  m_tlow_max(0.0),
58  m_thigh_min(1.e30),
59  m_p0(-1.0),
60  m_nspData(0) {}
61
62  //! Copy constructor
63  /*!
64  * @param right Object to be copied
65  */
66  SimpleThermo(const SimpleThermo& right) :
67  ID(SIMPLE),
68  m_tlow_max(0.0),
69  m_thigh_min(1.e30),
70  m_p0(-1.0),
71  m_nspData(0) {
72  /*
73  * Call the assignment operator
74  */
75  *this = operator=(right);
76  }
77
78  //! Assignment operator
79  /*!
80  * @param right Object to be copied
81  */
83  /*
84  * Check for self assignment.
85  */
86  if (this == &right) {
87  return *this;
88  }
89
90  m_loc = right.m_loc;
91  m_index = right.m_index;
92  m_tlow_max = right.m_tlow_max;
93  m_thigh_min = right.m_thigh_min;
94  m_tlow = right.m_tlow;
95  m_thigh = right.m_thigh;
96  m_t0 = right.m_t0;
97  m_logt0 = right.m_logt0;
98  m_h0_R = right.m_h0_R;
99  m_s0_R = right.m_s0_R;
100  m_cp0_R = right.m_cp0_R;
101  m_p0 = right.m_p0;
102  m_nspData = right.m_nspData;
103
104  return *this;
105  }
106
108  SimpleThermo* nt = new SimpleThermo(*this);
109  return (SpeciesThermo*) nt;
110  }
111
112  //! Install a new species thermodynamic property
113  //! parameterization for one species.
114  /*!
115  * @param name String name of the species
116  * @param index Species index, k
117  * @param type int flag specifying the type of parameterization to be
118  * installed.
119  * @param c Vector of coefficients for the parameterization.
120  * There are 4 coefficients. The values (and units) are the following
121  * - c[0] = \f$T_0 \f$(Kelvin)
122  * - c[1] = \f$H_k^o(T_0, p_{ref}) \f$ (J/kmol)
123  * - c[2] = \f$S_k^o(T_0, p_{ref}) \f$ (J/kmol K)
124  * - c[3] = \f${Cp}_k^o(T_0, p_{ref}) \f$ (J(kmol K)
125  *
126  * @param minTemp_ minimum temperature for which this parameterization
127  * is valid.
128  * @param maxTemp_ maximum temperature for which this parameterization
129  * is valid.
130  * @param refPressure_ standard-state pressure for this parameterization.
131  *
132  * @see ConstCpPoly
133  */
134  virtual void install(const std::string& name, size_t index, int type, const doublereal* c,
135  doublereal minTemp_, doublereal maxTemp_, doublereal refPressure_) {
136
137  m_logt0.push_back(log(c[0]));
138  m_t0.push_back(c[0]);
139  m_h0_R.push_back(c[1]/GasConstant);
140  m_s0_R.push_back(c[2]/GasConstant);
141  m_cp0_R.push_back(c[3]/GasConstant);
142  m_index.push_back(index);
143  m_loc[index] = m_nspData;
144  m_nspData++;
145  doublereal tlow = minTemp_;
146  doublereal thigh = maxTemp_;
147
148  if (tlow > m_tlow_max) {
149  m_tlow_max = tlow;
150  }
151  if (thigh < m_thigh_min) {
152  m_thigh_min = thigh;
153  }
154
155  if (m_tlow.size() < index + 1) {
156  m_tlow.resize(index + 1, tlow);
157  m_thigh.resize(index + 1, thigh);
158  }
159  m_tlow[index] = tlow;
160  m_thigh[index] = thigh;
161
162  if (m_p0 < 0.0) {
163  m_p0 = refPressure_;
164  } else if (fabs(m_p0 - refPressure_) > 0.1) {
165  std::string logmsg = " WARNING SimpleThermo: New Species, " + name +
166  ", has a different reference pressure, "
167  + fp2str(refPressure_) + ", than existing reference pressure, " + fp2str(m_p0) + "\n";
168  writelog(logmsg);
169  logmsg = " This is now a fatal error\n";
170  writelog(logmsg);
171  throw CanteraError("install()", "Species have different reference pressures");
172  }
173  m_p0 = refPressure_;
174  }
175
176  virtual void install_STIT(SpeciesThermoInterpType* stit_ptr) {
177  throw CanteraError("install_STIT", "not implemented");
178  }
179
180  virtual void update(doublereal t, doublereal* cp_R,
181  doublereal* h_RT, doublereal* s_R) const {
182  size_t k, ki;
183  doublereal logt = log(t);
184  doublereal rt = 1.0/t;
185  for (k = 0; k < m_nspData; k++) {
186  ki = m_index[k];
187  cp_R[ki] = m_cp0_R[k];
188  h_RT[ki] = rt*(m_h0_R[k] + (t - m_t0[k]) * m_cp0_R[k]);
189  s_R[ki] = m_s0_R[k] + m_cp0_R[k] * (logt - m_logt0[k]);
190  }
191  }
192
193  //! Like update(), but only updates the single species k.
194  /*!
195  * @param k species index
196  * @param t Temperature (Kelvin)
197  * @param cp_R Vector of Dimensionless heat capacities. (length m_kk).
198  * @param h_RT Vector of Dimensionless enthalpies. (length m_kk).
199  * @param s_R Vector of Dimensionless entropies. (length m_kk).
200  */
201  virtual void update_one(size_t k, doublereal t, doublereal* cp_R,
202  doublereal* h_RT, doublereal* s_R) const {
203  doublereal logt = log(t);
204  doublereal rt = 1.0/t;
205  size_t loc = m_loc[k];
206  cp_R[k] = m_cp0_R[loc];
207  h_RT[k] = rt*(m_h0_R[loc] + (t - m_t0[loc]) * m_cp0_R[loc]);
208  s_R[k] = m_s0_R[loc] + m_cp0_R[loc] * (logt - m_logt0[loc]);
209  }
210
211  virtual doublereal minTemp(size_t k=npos) const {
212  if (k == npos) {
213  return m_tlow_max;
214  } else {
215  return m_tlow[m_loc[k]];
216  }
217  }
218
219  virtual doublereal maxTemp(size_t k=npos) const {
220  if (k == npos) {
221  return m_thigh_min;
222  } else {
223  return m_thigh[m_loc[k]];
224  }
225  }
226
227  virtual doublereal refPressure(size_t k=npos) const {
228  return m_p0;
229  }
230
231  virtual int reportType(size_t index) const {
232  return SIMPLE;
233  }
234
235  /*!
236  * This utility function reports back the type of parameterization and all
237  * of the parameters for the species, index.
238  *
239  * @param index Species index
240  * @param type Integer type of the standard type
241  * @param c Vector of coefficients used to set the
242  * parameters for the standard state.
243  * For the SimpleThermo object, there are 4 coefficients.
244  * @param minTemp_ output - Minimum temperature
245  * @param maxTemp_ output - Maximum temperature
246  * @param refPressure_ output - reference pressure (Pa).
247  * @deprecated
248  */
249  virtual void reportParams(size_t index, int& type,
250  doublereal* const c,
251  doublereal& minTemp_,
252  doublereal& maxTemp_,
253  doublereal& refPressure_) const {
254  type = reportType(index);
255  size_t loc = m_loc[index];
256  if (type == SIMPLE) {
257  c[0] = m_t0[loc];
258  c[1] = m_h0_R[loc] * GasConstant;
259  c[2] = m_s0_R[loc] * GasConstant;
260  c[3] = m_cp0_R[loc] * GasConstant;
261  minTemp_ = m_tlow[loc];
262  maxTemp_ = m_thigh[loc];
263  refPressure_ = m_p0;
264  }
265  }
266
267 #ifdef H298MODIFY_CAPABILITY
268  virtual doublereal reportOneHf298(int k) const {
269  throw CanteraError("reportHF298", "unimplemented");
270  }
271
272  virtual void modifyOneHf298(const int k, const doublereal Hf298New) {
273  throw CanteraError("reportHF298", "unimplemented");
274  }
275 #endif
276
277 protected:
278  //! Mapping between the species index and the vector index where the coefficients are kept
279  /*!
280  * This object doesn't have a one-to one correspondence between the species index, kspec,
281  * and the data location index,indexData, m_cp0_R[indexData].
282  * This index keeps track of it.
283  * indexData = m_loc[kspec]
284  */
285  mutable std::map<size_t, size_t> m_loc;
286
287  //! Map between the vector index where the coefficients are kept and the species index
288  /*!
289  * Length is equal to the number of dataPoints.
290  * kspec = m_index[indexData]
291  */
292  std::vector<size_t> m_index;
293
294  //! Maximum value of the low temperature limit
295  doublereal m_tlow_max;
296
297  //! Minimum value of the high temperature limit
298  doublereal m_thigh_min;
299
300  //! Vector of low temperature limits (species index)
301  /*!
302  * Length is equal to number of data points
303  */
305
306  //! Vector of low temperature limits (species index)
307  /*!
308  * Length is equal to number of data points
309  */
311
312  //! Vector of base temperatures (kelvin)
313  /*!
314  * Length is equal to the number of species data points
315  */
317
318  //! Vector of base log temperatures (kelvin)
319  /*!
320  * Length is equal to the number of species data points
321  */
323
324  //! Vector of base dimensionless Enthalpies
325  /*!
326  * Length is equal to the number of species data points
327  */
329
330  //! Vector of base dimensionless Entropies
331  /*!
332  * Length is equal to the number of species data points
333  */
335
336  //! Vector of base dimensionless heat capacities
337  /*!
338  * Length is equal to the number of species data points
339  */
341
342  //! Reference pressure (Pa)
343  /*!
344  * all species must have the same reference pressure.
345  */
346  doublereal m_p0;
347
348  //! Number of species data points in the object.
349  /*!
350  * This is less than or equal to the number of species in the phase.
351  */
352  size_t m_nspData;
353 };
354
355 }
356
357 #endif
virtual doublereal maxTemp(size_t k=npos) const
Maximum temperature.
Definition: SimpleThermo.h:219
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.
Definition: SimpleThermo.h:134
virtual doublereal refPressure(size_t k=npos) const
The reference-state pressure for species k.
Definition: SimpleThermo.h:227
Pure Virtual Base class for the thermodynamic manager for an individual species' reference state...
vector_fp m_s0_R
Vector of base dimensionless Entropies.
Definition: SimpleThermo.h:334
const size_t npos
index returned by functions to indicate "no position"
Definition: ct_defs.h:173
vector_fp m_logt0
Vector of base log temperatures (kelvin)
Definition: SimpleThermo.h:322
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).
virtual SpeciesThermo * duplMyselfAsSpeciesThermo() const
Duplication routine for objects derived from SpeciesThermo.
Definition: SimpleThermo.h:107
SimpleThermo & operator=(const SimpleThermo &right)
Assignment operator.
Definition: SimpleThermo.h:82
Pure Virtual base class for the species thermo manager classes.
std::map< size_t, size_t > m_loc
Mapping between the species index and the vector index where the coefficients are kept...
Definition: SimpleThermo.h:285
Contains const definitions for types of species reference-state thermodynamics managers (see Species ...
doublereal m_tlow_max
Maximum value of the low temperature limit.
Definition: SimpleThermo.h:295
virtual doublereal minTemp(size_t k=npos) const
Minimum temperature.
Definition: SimpleThermo.h:211
std::string fp2str(const double x, const std::string &fmt)
Convert a double into a c++ string.
Definition: stringUtils.cpp:29
vector_fp m_tlow
Vector of low temperature limits (species index)
Definition: SimpleThermo.h:304
doublereal m_p0
Reference pressure (Pa)
Definition: SimpleThermo.h:346
virtual void install_STIT(SpeciesThermoInterpType *stit_ptr)
Install a new species thermodynamic property parameterization for one species.
Definition: SimpleThermo.h:176
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: SimpleThermo.h:201
Base class for exceptions thrown by Cantera classes.
Definition: ctexceptions.h:68
#define SIMPLE
Constant Cp thermo.
virtual void reportParams(size_t index, int &type, doublereal *const c, doublereal &minTemp_, doublereal &maxTemp_, doublereal &refPressure_) const
Definition: SimpleThermo.h:249
const int ID
The type of parameterization.
Definition: SimpleThermo.h:52
SimpleThermo()
Constructor.
Definition: SimpleThermo.h:55
size_t m_nspData
Number of species data points in the object.
Definition: SimpleThermo.h:352
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 m_thigh_min
Minimum value of the high temperature limit.
Definition: SimpleThermo.h:298
SimpleThermo(const SimpleThermo &right)
Copy constructor.
Definition: SimpleThermo.h:66
vector_fp m_cp0_R
Vector of base dimensionless heat capacities.
Definition: SimpleThermo.h:340
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
const doublereal GasConstant
Universal Gas Constant. [J/kmol/K].
Definition: ct_defs.h:66
std::vector< size_t > m_index
Map between the vector index where the coefficients are kept and the species index.
Definition: SimpleThermo.h:292
vector_fp m_h0_R
Vector of base dimensionless Enthalpies.
Definition: SimpleThermo.h:328
void writelog(const std::string &msg)
Write a message to the screen.
Definition: global.cpp:43
virtual void update(doublereal t, doublereal *cp_R, doublereal *h_RT, doublereal *s_R) const
Compute the reference-state properties for all species.
Definition: SimpleThermo.h:180
vector_fp m_thigh
Vector of low temperature limits (species index)
Definition: SimpleThermo.h:310
vector_fp m_t0
Vector of base temperatures (kelvin)
Definition: SimpleThermo.h:316
virtual int reportType(size_t index) const
This utility function reports the type of parameterization used for the species with index number ind...
Definition: SimpleThermo.h:231