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