Cantera  2.1.2
GeneralSpeciesThermo.cpp
Go to the documentation of this file.
1 /**
2  * @file GeneralSpeciesThermo.cpp
3  * Declarations for a completely general species thermodynamic property
4  * manager for a phase (see \ref spthermo and
5  * \link Cantera::GeneralSpeciesThermo GeneralSpeciesThermo\endlink).
6  */
7 // Copyright 2001-2004 California Institute of Technology
8 
11 #include "NasaPoly2.h"
12 #include "ShomatePoly.h"
13 #include "ConstCpPoly.h"
14 #include "cantera/thermo/Mu0Poly.h"
17 #include <iostream>
18 
19 using namespace std;
20 
21 namespace Cantera
22 {
23 GeneralSpeciesThermo::GeneralSpeciesThermo() :
24  SpeciesThermo(),
25  m_tlow_max(0.0),
26  m_thigh_min(1.0E30),
27  m_p0(OneAtm),
28  m_kk(0)
29 {
30  m_tlow_max = 0.0;
31  m_thigh_min = 1.0E30;
32 }
33 
36  m_tlow_max(b.m_tlow_max),
37  m_thigh_min(b.m_thigh_min),
38  m_kk(b.m_kk)
39 {
40  m_sp.resize(m_kk, 0);
41  for (size_t k = 0; k < m_kk; k++) {
42  SpeciesThermoInterpType* bk = b.m_sp[k];
43  if (bk) {
45  }
46  }
47 }
48 
51 {
52  if (&b != this) {
55 
56  for (size_t k = 0; k < m_kk; k++) {
58  if (sp) {
59  delete sp;
60  m_sp[k] = 0;
61  }
62  }
63  m_kk = b.m_kk;
64  m_sp.resize(m_kk, 0);
65  for (size_t k = 0; k < m_kk; k++) {
66  SpeciesThermoInterpType* bk = b.m_sp[k];
67  if (bk) {
69  }
70  }
71  }
72  return *this;
73 }
74 
76 {
77  for (size_t k = 0; k < m_kk; k++) {
79  if (sp) {
80  delete sp;
81  m_sp[k] = 0;
82  }
83  }
84 }
85 
86 
89 {
90  return new GeneralSpeciesThermo(*this);
91 }
92 
93 void GeneralSpeciesThermo::install(const std::string& name,
94  size_t index,
95  int type,
96  const doublereal* c,
97  doublereal minTemp_,
98  doublereal maxTemp_,
99  doublereal refPressure_)
100 {
101  /*
102  * Resize the arrays if necessary, filling the empty
103  * slots with the zero pointer.
104  */
105 
106  if (minTemp_ <= 0.0) {
107  throw CanteraError("Error in GeneralSpeciesThermo.cpp",
108  " Cannot take 0 tmin as input. \n\n");
109  }
110 
111  if (index >= m_kk) {
112  m_sp.resize(index+1, 0);
113  m_kk = index+1;
114  }
115 
116  //int nfreq = 3;
117  /*
118  * Create the necessary object
119  */
120 
121  switch (type) {
122  case NASA1:
123  m_sp[index] = new NasaPoly1(index, minTemp_, maxTemp_,
124  refPressure_, c);
125  break;
126  case SHOMATE1:
127  m_sp[index] = new ShomatePoly(index, minTemp_, maxTemp_,
128  refPressure_, c);
129  break;
130  case CONSTANT_CP:
131  case SIMPLE:
132  m_sp[index] = new ConstCpPoly(index, minTemp_, maxTemp_,
133  refPressure_, c);
134  break;
135  case MU0_INTERP:
136  m_sp[index] = new Mu0Poly(index, minTemp_, maxTemp_,
137  refPressure_, c);
138  break;
139  case SHOMATE2:
140  m_sp[index] = new ShomatePoly2(index, minTemp_, maxTemp_,
141  refPressure_, c);
142  break;
143  case NASA2:
144  m_sp[index] = new NasaPoly2(index, minTemp_, maxTemp_,
145  refPressure_, c);
146  break;
147 
148  case STAT:
149  m_sp[index] = new StatMech(index, minTemp_, maxTemp_,
150  refPressure_, c, name);
151  break;
152 
153  case ADSORBATE:
154  m_sp[index] = new Adsorbate(index, minTemp_, maxTemp_,
155  refPressure_, c);
156  break;
157  default:
159  "GeneralSpeciesThermo::install",
160  "unknown species type", int2str(type));
161  break;
162  }
163  if (!m_sp[index]) {
164  cout << "Null m_sp... index = " << index << endl;
165  cout << "type = " << type << endl;
166  }
167  m_tlow_max = max(minTemp_, m_tlow_max);
168  m_thigh_min = min(maxTemp_, m_thigh_min);
169 }
170 
172 {
173  /*
174  * Resize the arrays if necessary, filling the empty
175  * slots with the zero pointer.
176  */
177  if (!stit_ptr) {
178  throw CanteraError("GeneralSpeciesThermo::install_STIT",
179  "zero pointer");
180  }
181  size_t index = stit_ptr->speciesIndex();
182  if (index >= m_kk) {
183  m_sp.resize(index+1, 0);
184  m_kk = index+1;
185  }
186  AssertThrow(m_sp[index] == 0,
187  "Index position isn't null, duplication of assignment: " + int2str(index));
188  /*
189  * Now, simply assign the position
190  */
191  m_sp[index] = stit_ptr;
192 
193  /*
194  * Calculate max and min
195  */
196  m_tlow_max = max(stit_ptr->minTemp(), m_tlow_max);
197  m_thigh_min = min(stit_ptr->maxTemp(), m_thigh_min);
198 }
199 
201  VPSSMgr* vpssmgr_ptr)
202 {
203  STITbyPDSS* stit_ptr = new STITbyPDSS(k, vpssmgr_ptr, PDSS_ptr);
204  install_STIT(stit_ptr);
205 }
206 
208 update_one(size_t k, doublereal t, doublereal* cp_R,
209  doublereal* h_RT, doublereal* s_R) const
210 {
211  SpeciesThermoInterpType* sp_ptr = m_sp[k];
212  if (sp_ptr) {
213  sp_ptr->updatePropertiesTemp(t, cp_R, h_RT, s_R);
214  }
215 }
216 
218 update(doublereal t, doublereal* cp_R,
219  doublereal* h_RT, doublereal* s_R) const
220 {
221  vector<SpeciesThermoInterpType*>::const_iterator _begin, _end;
222  _begin = m_sp.begin();
223  _end = m_sp.end();
224  SpeciesThermoInterpType* sp_ptr = 0;
225  for (; _begin != _end; ++_begin) {
226  sp_ptr = *(_begin);
227  if (sp_ptr) {
228  sp_ptr->updatePropertiesTemp(t, cp_R, h_RT, s_R);
229  }
230  // else {
231  // writelog("General::update: sp_ptr is NULL!\n");
232  //}
233  }
234 }
235 
236 int GeneralSpeciesThermo::reportType(size_t index) const
237 {
238  SpeciesThermoInterpType* sp = m_sp[index];
239  if (sp) {
240  return sp->reportType();
241  }
242  return -1;
243 }
244 
246 reportParams(size_t index, int& type, doublereal* const c,
247  doublereal& minTemp_, doublereal& maxTemp_, doublereal& refPressure_) const
248 {
249  warn_deprecated("GeneralSpeciesThermo::reportParams");
250  SpeciesThermoInterpType* sp = m_sp[index];
251  size_t n;
252  if (sp) {
253  sp->reportParameters(n, type, minTemp_, maxTemp_,
254  refPressure_, c);
255  if (n != index) {
256  throw CanteraError("GeneralSpeciesThermo::reportParams",
257  "Internal error encountered");
258  }
259  } else {
260  type = -1;
261  }
262 }
263 
264 doublereal GeneralSpeciesThermo::minTemp(size_t k) const
265 {
266  if (k == npos) {
267  return m_tlow_max;
268  } else {
269  SpeciesThermoInterpType* sp = m_sp[k];
270  if (sp) {
271  return sp->minTemp();
272  }
273  }
274  return m_tlow_max;
275 }
276 
277 doublereal GeneralSpeciesThermo::maxTemp(size_t k) const
278 {
279  if (k == npos) {
280  return m_thigh_min;
281  } else {
282  SpeciesThermoInterpType* sp = m_sp[k];
283  if (sp) {
284  return sp->maxTemp();
285  }
286  }
287  return m_thigh_min;
288 }
289 
290 doublereal GeneralSpeciesThermo::refPressure(size_t k) const
291 {
292  if (k == npos) {
293  return m_p0;
294  } else {
295  SpeciesThermoInterpType* sp = m_sp[k];
296  if (sp) {
297  return sp->refPressure();
298  }
299  }
300  return m_p0;
301 }
302 
304 {
305  return m_sp[k];
306 }
307 
308 #ifdef H298MODIFY_CAPABILITY
309 
310 doublereal GeneralSpeciesThermo::reportOneHf298(int k) const
311 {
312  SpeciesThermoInterpType* sp_ptr = m_sp[k];
313  doublereal h = -1.0;
314  if (sp_ptr) {
315  h = sp_ptr->reportHf298(0);
316  }
317  return h;
318 }
319 
320 void GeneralSpeciesThermo::modifyOneHf298(const int k, const doublereal Hf298New)
321 {
322  SpeciesThermoInterpType* sp_ptr = m_sp[k];
323  if (sp_ptr) {
324  sp_ptr->modifyOneHf298(k, Hf298New);
325  }
326 }
327 
328 #endif
329 
330 }
Statistical mechanics.
Definition: StatMech.h:26
SpeciesThermoInterpType * provideSTIT(size_t k)
Provide the SpeciesthermoInterpType object.
std::string int2str(const int n, const std::string &fmt)
Convert an int to a string using a format converter.
Definition: stringUtils.cpp:40
Header for a single-species standard state object derived from SpeciesThermoInterpType based on a pie...
Pure Virtual Base class for the thermodynamic manager for an individual species' reference state...
#define CONSTANT_CP
Constant Cp.
The NASA polynomial parameterization for two temperature ranges.
Definition: NasaPoly2.h:48
const doublereal OneAtm
One atmosphere [Pa].
Definition: ct_defs.h:71
std::vector< SpeciesThermoInterpType * > m_sp
This is the main unknown in the object.
Virtual base class for the classes that manage the calculation of standard state properties for all t...
Definition: VPSSMgr.h:238
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.
const size_t npos
index returned by functions to indicate "no position"
Definition: ct_defs.h:173
virtual size_t speciesIndex() const
Returns an integer representing the species index.
#define NASA2
Two regions of 7 coefficient NASA Polynomials This is implemented in the class NasaPoly2 in NasaPoly2...
virtual SpeciesThermo * duplMyselfAsSpeciesThermo() const
Duplication routine for objects derived from SpeciesThermo.
void warn_deprecated(const std::string &method, const std::string &extra)
Print a warning indicating that method is deprecated.
Definition: global.cpp:76
The Mu0Poly class implements an interpolation of the Gibbs free energy based on a piecewise constant ...
Definition: Mu0Poly.h:71
A constant-heat capacity species thermodynamic property manager class.
Definition: ConstCpPoly.h:47
doublereal m_tlow_max
Maximum value of the lowest temperature.
Pure Virtual base class for the species thermo manager classes.
size_t m_kk
Internal variable indicating the length of the number of species in the phase.
virtual int reportType() const =0
Returns an integer representing the type of parameterization.
#define MU0_INTERP
piecewise interpolation of mu0.
virtual SpeciesThermoInterpType * duplMyselfAsSpeciesThermoInterpType() const =0
duplicator
#define NASA1
7 coefficient NASA Polynomials This is implemented in the class NasaPoly1 in NasaPoly1.h
virtual doublereal refPressure() const
Returns the reference pressure (Pa)
virtual doublereal maxTemp() const
Returns the maximum temperature that the thermo parameterization is valid.
A species thermodynamic property manager for a phase.
GeneralSpeciesThermo & operator=(const GeneralSpeciesThermo &b)
Assignment operator.
virtual void reportParameters(size_t &index, int &type, doublereal &minTemp, doublereal &maxTemp, doublereal &refPressure, doublereal *const coeffs) const =0
This utility function reports back the type of parameterization and all of the parameters for the spe...
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...
The Shomate polynomial parameterization for two temperature ranges for one species.
Definition: ShomatePoly.h:305
Class for the thermodynamic manager for an individual species' reference state which uses the PDSS ba...
#define AssertThrow(expr, procedure)
Assertion must be true or an error is thrown.
Definition: ctexceptions.h:229
virtual doublereal maxTemp(size_t k=npos) const
Maximum temperature.
Base class for exceptions thrown by Cantera classes.
Definition: ctexceptions.h:68
virtual doublereal minTemp(size_t k=npos) const
Minimum temperature.
#define SIMPLE
Constant Cp thermo.
Header for a single-species standard state object derived from SpeciesThermoInterpType based on the N...
#define SHOMATE2
Two regions of Shomate Polynomials.
virtual ~GeneralSpeciesThermo()
Destructor.
virtual doublereal minTemp() const
Returns the minimum temperature that the thermo parameterization is valid.
Throw a named error for an unknown or missing species thermo model.
An adsorbed surface species.
Header for factory to build instances of classes that manage the standard-state thermodynamic propert...
Headers for a completely general species thermodynamic property manager for a phase (see Managers for...
doublereal m_p0
reference pressure (Pa)
Virtual base class for a species with a pressure dependent standard state.
Definition: PDSS.h:195
#define STAT
Properties derived from theoretical considerations This is implemented in the class statmech in StatM...
virtual doublereal refPressure(size_t k=npos) const
The reference-state pressure for species k.
Headers for the SpeciesThermoInterpType object that employs a constant heat capacity assumption (see ...
virtual void updatePropertiesTemp(const doublereal temp, doublereal *cp_R, doublereal *h_RT, doublereal *s_R) const =0
Compute the reference-state property of one species.
doublereal m_thigh_min
Minimum value of the highest temperature.
Header for a single-species standard state object derived from SpeciesThermoInterpType based on the e...
virtual void install_STIT(SpeciesThermoInterpType *stit_ptr)
Install a new species thermodynamic property parameterization for one species.
The NASA polynomial parameterization for one temperature range.
Definition: NasaPoly1.h:48
virtual int reportType(size_t index) const
This utility function reports the type of parameterization used for the species with index number ind...
Header for a single-species standard state object derived from SpeciesThermoInterpType based on the N...
virtual void update(doublereal T, doublereal *cp_R, doublereal *h_RT, doublereal *s_R) const
Compute the reference-state properties for all species.
#define SHOMATE1
one region of Shomate Polynomials used in NIST database This is implemented in the NIST database...
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.
virtual void reportParams(size_t index, int &type, doublereal *const c, doublereal &minTemp, doublereal &maxTemp, doublereal &refPressure) const
#define ADSORBATE
Surface Adsorbate Model for a species on a surface.
void installPDSShandler(size_t k, PDSS *PDSS_ptr, VPSSMgr *vpssmgr_ptr)
Install a PDSS object to handle the reference state thermodynamics calculation.