Cantera  2.0
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 
24 
25 /*
26  * Constructors
27  */
28 GeneralSpeciesThermo::GeneralSpeciesThermo() :
29  SpeciesThermo(),
30  m_tlow_max(0.0),
31  m_thigh_min(1.0E30),
32  m_p0(OneAtm),
33  m_kk(0)
34 {
35  m_tlow_max = 0.0;
36  m_thigh_min = 1.0E30;
37 }
38 
41  m_tlow_max(b.m_tlow_max),
42  m_thigh_min(b.m_thigh_min),
43  m_kk(b.m_kk)
44 {
45  m_sp.resize(m_kk, 0);
46  for (size_t k = 0; k < m_kk; k++) {
47  SpeciesThermoInterpType* bk = b.m_sp[k];
48  if (bk) {
50  }
51  }
52 }
53 
56 {
57  if (&b != this) {
60 
61  for (size_t k = 0; k < m_kk; k++) {
63  if (sp) {
64  delete sp;
65  m_sp[k] = 0;
66  }
67  }
68  m_kk = b.m_kk;
69  m_sp.resize(m_kk, 0);
70  for (size_t k = 0; k < m_kk; k++) {
71  SpeciesThermoInterpType* bk = b.m_sp[k];
72  if (bk) {
74  }
75  }
76  }
77  return *this;
78 }
79 
81 {
82  for (size_t k = 0; k < m_kk; k++) {
84  if (sp) {
85  delete sp;
86  m_sp[k] = 0;
87  }
88  }
89 }
90 
91 
94 {
95  GeneralSpeciesThermo* gsth = new GeneralSpeciesThermo(*this);
96  return (SpeciesThermo*) gsth;
97 }
98 
99 
100 /*
101  * Install parameterization for a species.
102  * @param index Species index
103  * @param type parameterization type
104  * @param c coefficients. The meaning of these depends on
105  * the parameterization.
106  */
107 void GeneralSpeciesThermo::install(std::string name,
108  size_t index,
109  int type,
110  const doublereal* c,
111  doublereal minTemp,
112  doublereal maxTemp,
113  doublereal refPressure)
114 {
115  /*
116  * Resize the arrays if necessary, filling the empty
117  * slots with the zero pointer.
118  */
119  if (index >= m_kk) {
120  m_sp.resize(index+1, 0);
121  m_kk = index+1;
122  }
123  //AssertThrow(m_sp[index] == 0,
124  // "Index position isn't null, duplication of assignment: " + int2str(index));
125 
126  //int nfreq = 3;
127  /*
128  * Create the necessary object
129  */
130 
131  switch (type) {
132  case NASA1:
133  m_sp[index] = new NasaPoly1(index, minTemp, maxTemp,
134  refPressure, c);
135  break;
136  case SHOMATE1:
137  m_sp[index] = new ShomatePoly(index, minTemp, maxTemp,
138  refPressure, c);
139  break;
140  case CONSTANT_CP:
141  case SIMPLE:
142  m_sp[index] = new ConstCpPoly(index, minTemp, maxTemp,
143  refPressure, c);
144  break;
145  case MU0_INTERP:
146  m_sp[index] = new Mu0Poly(index, minTemp, maxTemp,
147  refPressure, c);
148  break;
149  case SHOMATE2:
150  m_sp[index] = new ShomatePoly2(index, minTemp, maxTemp,
151  refPressure, c);
152  break;
153  case NASA2:
154  m_sp[index] = new NasaPoly2(index, minTemp, maxTemp,
155  refPressure, c);
156  break;
157  case ADSORBATE:
158  m_sp[index] = new Adsorbate(index, minTemp, maxTemp,
159  refPressure, c);
160  break;
161  default:
163  "GeneralSpeciesThermo::install",
164  "unknown species type", int2str(type));
165  break;
166  }
167  if (!m_sp[index]) {
168  cout << "Null m_sp... index = " << index << endl;
169  cout << "type = " << type << endl;
170  }
171  m_tlow_max = max(minTemp, m_tlow_max);
172  m_thigh_min = min(maxTemp, m_thigh_min);
173 }
174 
175 // Install a new species thermodynamic property
176 // parameterization for one species.
177 /*
178  * @param stit_ptr Pointer to the SpeciesThermoInterpType object
179  * This will set up the thermo for one species
180  */
182 {
183  /*
184  * Resize the arrays if necessary, filling the empty
185  * slots with the zero pointer.
186  */
187  if (!stit_ptr) {
188  throw CanteraError("GeneralSpeciesThermo::install_STIT",
189  "zero pointer");
190  }
191  size_t index = stit_ptr->speciesIndex();
192  if (index >= m_kk) {
193  m_sp.resize(index+1, 0);
194  m_kk = index+1;
195  }
196  AssertThrow(m_sp[index] == 0,
197  "Index position isn't null, duplication of assignment: " + int2str(index));
198  /*
199  * Now, simply assign the position
200  */
201  m_sp[index] = stit_ptr;
202 
203  /*
204  * Calculate max and min
205  */
206  double minTemp = stit_ptr->minTemp();
207  double maxTemp = stit_ptr->maxTemp();
208 
209  m_tlow_max = max(minTemp, m_tlow_max);
210  m_thigh_min = min(maxTemp, m_thigh_min);
211 }
212 
213 
214 
216  VPSSMgr* vpssmgr_ptr)
217 {
218  STITbyPDSS* stit_ptr = new STITbyPDSS(k, vpssmgr_ptr, PDSS_ptr);
219  install_STIT(stit_ptr);
220 }
221 
222 /**
223  * Update the properties for one species.
224  */
226 update_one(size_t k, doublereal t, doublereal* cp_R,
227  doublereal* h_RT, doublereal* s_R) const
228 {
229  SpeciesThermoInterpType* sp_ptr = m_sp[k];
230  if (sp_ptr) {
231  sp_ptr->updatePropertiesTemp(t, cp_R, h_RT, s_R);
232  }
233 }
234 
235 
236 /**
237  * Update the properties for all species.
238  */
240 update(doublereal t, doublereal* cp_R,
241  doublereal* h_RT, doublereal* s_R) const
242 {
243  vector<SpeciesThermoInterpType*>::const_iterator _begin, _end;
244  _begin = m_sp.begin();
245  _end = m_sp.end();
246  SpeciesThermoInterpType* sp_ptr = 0;
247  for (; _begin != _end; ++_begin) {
248  sp_ptr = *(_begin);
249  if (sp_ptr) {
250  sp_ptr->updatePropertiesTemp(t, cp_R, h_RT, s_R);
251  }
252  // else {
253  // writelog("General::update: sp_ptr is NULL!\n");
254  //}
255  }
256 }
257 
258 /**
259  * This utility function reports the type of parameterization
260  * used for the species, index.
261  */
262 int GeneralSpeciesThermo::reportType(size_t index) const
263 {
264  SpeciesThermoInterpType* sp = m_sp[index];
265  if (sp) {
266  return sp->reportType();
267  }
268  return -1;
269 }
270 
271 /**
272  * This utility function reports back the type of
273  * parameterization and all of the parameters for the
274  * species, index.
275  * For the NASA object, there are 15 coefficients.
276  */
278 reportParams(size_t index, int& type, doublereal* const c,
279  doublereal& minTemp, doublereal& maxTemp, doublereal& refPressure) const
280 {
281  SpeciesThermoInterpType* sp = m_sp[index];
282  size_t n;
283  if (sp) {
284  sp->reportParameters(n, type, minTemp, maxTemp,
285  refPressure, c);
286  if (n != index) {
287  throw CanteraError("GeneralSpeciesThermo::reportParams",
288  "Internal error encountered");
289  }
290  } else {
291  type = -1;
292  }
293 }
294 
295 //! Modify parameters for the standard state
296 /*!
297  * @param index Species index
298  * @param c Vector of coefficients used to set the
299  * parameters for the standard state.
300  */
302 modifyParams(size_t index, doublereal* c)
303 {
304  SpeciesThermoInterpType* sp = m_sp[index];
305  if (sp) {
306  sp->modifyParameters(c);
307  }
308 }
309 
310 
311 /**
312  * Return the lowest temperature at which the thermodynamic
313  * parameterization is valid. If no argument is supplied, the
314  * value is the one for which all species parameterizations
315  * are valid. Otherwise, if an integer argument is given, the
316  * value applies only to the species with that index.
317  */
318 doublereal GeneralSpeciesThermo::minTemp(size_t k) const
319 {
320  if (k == npos) {
321  return m_tlow_max;
322  } else {
323  SpeciesThermoInterpType* sp = m_sp[k];
324  if (sp) {
325  return sp->minTemp();
326  }
327  }
328  return m_tlow_max;
329 }
330 
331 doublereal GeneralSpeciesThermo::maxTemp(size_t k) const
332 {
333  if (k == npos) {
334  return m_thigh_min;
335  } else {
336  SpeciesThermoInterpType* sp = m_sp[k];
337  if (sp) {
338  return sp->maxTemp();
339  }
340  }
341  return m_thigh_min;
342 }
343 
344 doublereal GeneralSpeciesThermo::refPressure(size_t k) const
345 {
346  if (k == npos) {
347  return m_p0;
348  } else {
349  SpeciesThermoInterpType* sp = m_sp[k];
350  if (sp) {
351  return sp->refPressure();
352  }
353  }
354  return m_p0;
355 }
356 
357 
359 {
360  return (m_sp[k]);
361 }
362 
363 #ifdef H298MODIFY_CAPABILITY
364 
365 doublereal GeneralSpeciesThermo::reportOneHf298(int k) const
366 {
367  SpeciesThermoInterpType* sp_ptr = m_sp[k];
368  doublereal h = -1.0;
369  if (sp_ptr) {
370  h = sp_ptr->reportHf298(0);
371  }
372  return h;
373 }
374 
375 void GeneralSpeciesThermo::modifyOneHf298(const int k, const doublereal Hf298New)
376 {
377  SpeciesThermoInterpType* sp_ptr = m_sp[k];
378  if (sp_ptr) {
379  sp_ptr->modifyOneHf298(k, Hf298New);
380  }
381 }
382 
383 
384 #endif
385 
386 
387 }