Cantera  2.0
SpeciesThermoMgr.h
Go to the documentation of this file.
1 /**
2  * @file SpeciesThermoMgr.h
3  * This file contains descriptions of templated subclasses of
4  * the virtual base class, SpeciesThermo, which includes SpeciesThermoDuo
5  * (see \ref mgrsrefcalc and class
6  * \link Cantera::SpeciesThermoDuo SpeciesThermoDuo\endlink)
7  */
8 
9 // Copyright 2001 California Institute of Technology
10 
11 #ifndef CT_SPECIESTHERMO_MGR_H
12 #define CT_SPECIESTHERMO_MGR_H
13 
14 #include "cantera/base/ct_defs.h"
17 #include "SpeciesThermo.h"
18 #include <map>
19 
20 namespace Cantera
21 {
22 
23 //! Invokes the 'updateProperties' method of all objects in the list.
24 /*!
25  * This templated function has one template, InputIter. It should
26  * point to a class such as one that inherits from the virtual
27  * base class, SpeciesThermoInterpType, which has
28  * an updateProperties(T, Cp_R, h_RT, s)R) function
29  *
30  * @param begin Beginning iterator
31  * @param end end iterator
32  * @param T Temperature (Kelvin)
33  * @param cp_R Vector of Dimensionless heat capacities.
34  * (length m_kk).
35  * @param h_RT Vector of Dimensionless enthalpies.
36  * (length m_kk).
37  * @param s_R Vector of Dimensionless entropies.
38  * (length m_kk).
39  *
40  * @ingroup mgrsrefcalc
41  * @deprecated unused
42  */
43 template<class InputIter>
44 inline void _updateAll(InputIter begin,
45  InputIter end,
46  doublereal T,
47  vector_fp& cp_R,
48  vector_fp& h_RT,
49  vector_fp& s_R)
50 {
51  for (; begin != end; ++begin) {
52  begin->updateProperties(T, cp_R, h_RT, s_R);
53  }
54 }
55 
56 //! Iterates through a list of objects which implement a method
57 //! 'minTemp()', and returns the largest 'minTemp' value.
58 /*!
59  * This templated function has one template, InputIter. It should
60  * point to a class such as one that inherits from either
61  * SpeciesThermoInterpType or SpeciesThermo, which have a minTemp() function
62  *
63  * @param begin Beginning iterator
64  * @param end end iterator
65  *
66  * @ingroup mgrsrefcalc
67  * @deprecated unused
68  */
69 template<class InputIter>
70 doublereal _minTemp(InputIter begin, InputIter end)
71 {
72  doublereal _minT = 0.0;
73  for (; begin != end; ++begin) {
74  _minT = std::max(_minT, begin->minTemp());
75  }
76  return _minT;
77 }
78 
79 //! Iterates through a list of objects which implement a method
80 //! 'maxTemp()', and returns the smallest 'maxTemp' value.
81 /*!
82  * This templated function has one template, InputIter. It should
83  * point to a class such as one that inherits from either
84  * SpeciesThermoInterpType or SpeciesThermo which have a minTemp() function
85  *
86  * @param begin Beginning iterator
87  * @param end end iterator
88  *
89  * @ingroup mgrsrefcalc
90  * @deprecated unused
91  */
92 template<class _InputIter>
93 doublereal _maxTemp(_InputIter begin, _InputIter end)
94 {
95  doublereal _maxT = 1.e10;
96  for (; begin != end; ++begin) {
97  _maxT = std::min(_maxT, begin->maxTemp());
98  }
99  return _maxT;
100 }
101 
102 /////////////////////// Exceptions //////////////////////////////
103 
104 //! Exception thrown if species reference pressures don't match.
105 /*!
106  * @ingroup mgrsrefcalc
107  * @deprecated unused
108  */
110 {
111 public:
112  //! constructor
113  /*!
114  * @param proc name of the procecdure
115  * @param prnew reference pressure
116  * @param prold old reference pressure
117  */
118  RefPressureMismatch(std::string proc, doublereal prnew,
119  doublereal prold) : CanteraError(proc,
120  "Species reference pressure ("
121  + fp2str(prnew) + ") does not match previously-defined "
122  + "reference pressure (" + fp2str(prold) + ")") {}
123  //! destructor
124  virtual ~RefPressureMismatch() throw() {}
125 };
126 
127 //! Unknown species thermo manager string error
128 /*!
129  * @ingroup mgrsrefcalc
130  */
132 {
133 public:
134 
135  //! constructor
136  /*!
137  * @param proc name of the procecdure
138  * @param type unknown type
139  */
140  UnknownSpeciesThermo(std::string proc, int type) :
141  CanteraError(proc, "Specified species parameterization type (" + int2str(type)
142  + ") does not match any known type.") {}
143 
144  //! Alternate constructor
145  /*!
146  * @param proc name of the procecdure
147  * @param stype String name for the unknown type
148  */
149  UnknownSpeciesThermo(std::string proc, std::string stype) :
150  CanteraError(proc, "Specified species parameterization type (" + stype
151  + ") does not match any known type.") {}
152  //! destructor
153  virtual ~UnknownSpeciesThermo() throw() {}
154 };
155 
156 
157 /**
158  * This species thermo manager requires that all species have one
159  * of two parameterizations.
160  *
161  * Note this seems to be a slow way to do things, and it may be on its way out.
162  *
163  * @ingroup mgrsrefcalc
164  */
165 template<class T1, class T2>
167 {
168 
169 public:
170  //! Constructor
172 
173  //! Destructor
174  virtual ~SpeciesThermoDuo() {};
175 
176  //! copy constructor
177  /*!
178  * @param right Object to be copied
179  */
181  {
182  *this = operator=(right);
183  }
184 
185  //! Assignment operator
186  /*!
187  * @param right Object to be copied
188  */
190 
191  //! Duplication routine for objects which inherit from
192  //! %SpeciesThermo
193  /*!
194  * This virtual routine can be used to duplicate %SpeciesThermo objects
195  * inherited from %SpeciesThermo even if the application only has
196  * a pointer to %SpeciesThermo to work with.
197  * ->commented out because we first need to add copy constructors
198  * and assignment operators to all of the derived classes.
199  */
200  virtual SpeciesThermo* duplMyselfAsSpeciesThermo() const;
201 
202  /**
203  * install a new species thermodynamic property
204  * parameterization for one species.
205  *
206  * @param name Name of the species
207  * @param sp The 'update' method will update the property
208  * values for this species
209  * at position i index in the property arrays.
210  * @param type int flag specifying the type of parameterization to be
211  * installed.
212  * @param c vector of coefficients for the parameterization.
213  * This vector is simply passed through to the
214  * parameterization constructor.
215  * @param minTemp minimum temperature for which this parameterization
216  * is valid.
217  * @param maxTemp maximum temperature for which this parameterization
218  * is valid.
219  * @param refPressure standard-state pressure for this
220  * parameterization.
221  * @see speciesThermoTypes.h
222  */
223  virtual void install(std::string name, size_t sp, int type,
224  const doublereal* c,
225  doublereal minTemp, doublereal maxTemp,
226  doublereal refPressure);
227 
228  //! Install a new species thermodynamic property
229  //! parameterization for one species.
230  /*!
231  * @param stit_ptr Pointer to the SpeciesThermoInterpType object
232  * This will set up the thermo for one species
233  */
234  virtual void install_STIT(SpeciesThermoInterpType* stit_ptr)
235  {
236  throw CanteraError("install_STIT", "not implemented");
237  }
238 
239  //! Compute the reference-state properties for all species.
240  /*!
241  * Given temperature T in K, this method updates the values of
242  * the non-dimensional heat capacity at constant pressure,
243  * enthalpy, and entropy, at the reference pressure, Pref
244  * of each of the standard states.
245  *
246  * @param t Temperature (Kelvin)
247  * @param cp_R Vector of Dimensionless heat capacities.
248  * (length m_kk).
249  * @param h_RT Vector of Dimensionless enthalpies.
250  * (length m_kk).
251  * @param s_R Vector of Dimensionless entropies.
252  * (length m_kk).
253  */
254  virtual void update(doublereal t, doublereal* cp_R,
255  doublereal* h_RT, doublereal* s_R) const;
256 
257  //! Minimum temperature.
258  /*!
259  * If no argument is supplied, this
260  * method returns the minimum temperature for which \e all
261  * parameterizations are valid. If an integer index k is
262  * supplied, then the value returned is the minimum
263  * temperature for species k in the phase.
264  *
265  * @param k Species index
266  */
267  virtual doublereal minTemp(size_t k = npos) const
268  {
269  return std::max(m_thermo1.minTemp(),m_thermo2.minTemp());
270  }
271 
272  //! Maximum temperature.
273  /*!
274  * If no argument is supplied, this
275  * method returns the maximum temperature for which \e all
276  * parameterizations are valid. If an integer index k is
277  * supplied, then the value returned is the maximum
278  * temperature for parameterization k.
279  *
280  * @param k index for parameterization k
281  */
282  virtual doublereal maxTemp(size_t k = npos) const
283  {
284  return std::min(m_thermo1.maxTemp(), m_thermo2.maxTemp());
285  }
286 
287  /**
288  * The reference-state pressure for species k.
289  *
290  * returns the reference state pressure in Pascals for
291  * species k. If k is left out of the argument list,
292  * it returns the reference state pressure for the first
293  * species.
294  * Note that some SpeciesThermo implementations, such
295  * as those for ideal gases, require that all species
296  * in the same phase have the same reference state pressures.
297  *
298  * @param k index for parameterization k
299  */
300  virtual doublereal refPressure(size_t k = npos) const
301  {
302  return m_p0;
303  }
304 
305  //! This utility function reports the type of parameterization
306  //! used for the species with index number index.
307  /*!
308  *
309  * @param k Species index
310  */
311  virtual int reportType(size_t k) const;
312 
313  /*!
314  * This utility function reports back the type of
315  * parameterization and all of the parameters for the
316  * species, index.
317  *
318  * @param index Species index
319  * @param type Integer type of the standard type
320  * @param c Vector of coefficients used to set the
321  * parameters for the standard state.
322  * @param minTemp output - Minimum temperature
323  * @param maxTemp output - Maximum temperature
324  * @param refPressure output - reference pressure (Pa).
325  *
326  */
327  virtual void reportParams(size_t index, int& type,
328  doublereal* const c,
329  doublereal& minTemp,
330  doublereal& maxTemp,
331  doublereal& refPressure) const;
332 
333  //! Modify parameters for the standard state
334  /*!
335  * @param index Species index
336  * @param c Vector of coefficients used to set the
337  * parameters for the standard state.
338  * @deprecated
339  */
340  DEPRECATED(virtual void modifyParams(size_t index, doublereal* c));
341 
342 #ifdef H298MODIFY_CAPABILITY
343 
344  virtual doublereal reportOneHf298(int k) const {
345  throw CanteraError("reportHF298", "unimplemented");
346  }
347 
348  virtual void modifyOneHf298(const int k, const doublereal Hf298New) {
349  throw CanteraError("reportHF298", "unimplemented");
350  }
351 
352 #endif
353 
354 private:
355 
356  //! Thermo Type 1
358  //! Thermo Type 2
360  //! Reference pressure
361  doublereal m_p0;
362  //! map from species to type
363  std::map<size_t, int> speciesToType;
364 };
365 
366 
367 // ------------------------- cpp part of file -------------------------------------
368 
369 // Definitions for the SpeciesThermoDuo<T1,T2> templated class
370 
371 template<class T1, class T2>
374 {
375  if (&right == this) {
376  return *this;
377  }
378 
379  m_thermo1 = right.m_thermo1;
380  m_thermo2 = right.m_thermo2;
381  m_p0 = right.m_p0;
382  speciesToType = right.speciesToType;
383 
384  return *this;
385 }
386 
387 template<class T1, class T2>
390 {
392  return (SpeciesThermo*) nt;
393 }
394 
395 template<class T1, class T2>
396 void
397 SpeciesThermoDuo<T1, T2>::install(std::string name, size_t sp, int type,
398  const doublereal* c,
399  doublereal minTemp,
400  doublereal maxTemp,
401  doublereal refPressure)
402 {
403  m_p0 = refPressure;
404  if (type == m_thermo1.ID) {
405  m_thermo1.install(name, sp, 0, c, minTemp, maxTemp,
406  refPressure);
407  speciesToType[sp] = m_thermo1.ID;
408  } else if (type == m_thermo2.ID) {
409  m_thermo2.install(name, sp, 0, c, minTemp, maxTemp,
410  refPressure);
411  speciesToType[sp] = m_thermo2.ID;
412  } else {
413  throw UnknownSpeciesThermo("SpeciesThermoDuo:install",type);
414  }
415 }
416 
417 template<class T1, class T2>
418 void
419 SpeciesThermoDuo<T1, T2>::update(doublereal t, doublereal* cp_R,
420  doublereal* h_RT, doublereal* s_R) const
421 {
422  m_thermo1.update(t, cp_R, h_RT, s_R);
423  m_thermo2.update(t, cp_R, h_RT, s_R);
424 }
425 
426 template<class T1, class T2>
427 int
429 {
430  std::map<size_t, int>::const_iterator p = speciesToType.find(k);
431  if (p != speciesToType.end()) {
432  return p->second;
433  }
434  return -1;
435 }
436 
437 template<class T1, class T2>
438 void
440  doublereal* const c,
441  doublereal& minTemp,
442  doublereal& maxTemp,
443  doublereal& refPressure) const
444 {
445  int ctype = reportType(index);
446  if (ctype == m_thermo1.ID) {
447  m_thermo1.reportParams(index, type, c, minTemp, maxTemp,
448  refPressure);
449  } else if (ctype == m_thermo2.ID) {
450  m_thermo2.reportParams(index, type, c, minTemp, maxTemp,
451  refPressure);
452  } else {
453  throw CanteraError(" ", "confused");
454  }
455 }
456 
457 template<class T1, class T2>
458 void
459 SpeciesThermoDuo<T1, T2>::modifyParams(size_t index, doublereal* c)
460 {
461  int ctype = reportType(index);
462  if (ctype == m_thermo1.ID) {
463  m_thermo1.modifyParams(index, c);
464  } else if (ctype == m_thermo2.ID) {
465  m_thermo2.modifyParams(index, c);
466  } else {
467  throw CanteraError("modifyParams", "confused");
468  }
469 }
470 
471 }
472 #endif