Cantera  2.1.2
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 
19 namespace Cantera
20 {
21 //! Unknown species thermo manager string error
22 /*!
23  * @ingroup mgrsrefcalc
24  */
26 {
27 public:
28  //! constructor
29  /*!
30  * @param proc name of the procecdure
31  * @param type unknown type
32  */
33  UnknownSpeciesThermo(const std::string& proc, int type) :
34  CanteraError(proc, "Specified species parameterization type (" + int2str(type)
35  + ") does not match any known type.") {}
36 
37  //! Alternate constructor
38  /*!
39  * @param proc name of the procecdure
40  * @param stype String name for the unknown type
41  */
42  UnknownSpeciesThermo(const std::string& proc, const std::string& stype) :
43  CanteraError(proc, "Specified species parameterization type (" + stype
44  + ") does not match any known type.") {}
45 };
46 
47 /**
48  * This species thermo manager requires that all species have one
49  * of two parameterizations.
50  *
51  * Note this seems to be a slow way to do things, and it may be on its way out.
52  *
53  * @ingroup mgrsrefcalc
54  */
55 template<class T1, class T2>
57 {
58 public:
59  //! Constructor
61 
62  //! copy constructor
63  /*!
64  * @param right Object to be copied
65  */
67  *this = operator=(right);
68  }
69 
70  //! Assignment operator
71  /*!
72  * @param right Object to be copied
73  */
75 
77 
78  virtual void install(const std::string& name, size_t sp, int type,
79  const doublereal* c,
80  doublereal minTemp, doublereal maxTemp,
81  doublereal refPressure);
82 
83  virtual void install_STIT(SpeciesThermoInterpType* stit_ptr) {
84  throw CanteraError("install_STIT", "not implemented");
85  }
86 
87  virtual void update(doublereal t, doublereal* cp_R,
88  doublereal* h_RT, doublereal* s_R) const;
89 
90  virtual doublereal minTemp(size_t k = npos) const {
91  return std::max(m_thermo1.minTemp(),m_thermo2.minTemp());
92  }
93 
94  virtual doublereal maxTemp(size_t k = npos) const {
95  return std::min(m_thermo1.maxTemp(), m_thermo2.maxTemp());
96  }
97 
98  virtual doublereal refPressure(size_t k = npos) const {
99  return m_p0;
100  }
101 
102  virtual int reportType(size_t k) const;
103 
104  //! @deprecated
105  virtual void reportParams(size_t index, int& type,
106  doublereal* const c,
107  doublereal& minTemp,
108  doublereal& maxTemp,
109  doublereal& refPressure) const;
110 
111 #ifdef H298MODIFY_CAPABILITY
112 
113  virtual doublereal reportOneHf298(int k) const {
114  throw CanteraError("reportHF298", "unimplemented");
115  }
116 
117  virtual void modifyOneHf298(const int k, const doublereal Hf298New) {
118  throw CanteraError("reportHF298", "unimplemented");
119  }
120 
121 #endif
122 
123 private:
124 
125  //! Thermo Type 1
127  //! Thermo Type 2
129  //! Reference pressure
130  doublereal m_p0;
131  //! map from species to type
132  std::map<size_t, int> speciesToType;
133 };
134 
135 
136 // ------------------------- cpp part of file -------------------------------------
137 
138 // Definitions for the SpeciesThermoDuo<T1,T2> templated class
139 
140 template<class T1, class T2>
143 {
144  if (&right == this) {
145  return *this;
146  }
147 
148  m_thermo1 = right.m_thermo1;
149  m_thermo2 = right.m_thermo2;
150  m_p0 = right.m_p0;
151  speciesToType = right.speciesToType;
152 
153  return *this;
154 }
155 
156 template<class T1, class T2>
159 {
160  return new SpeciesThermoDuo<T1,T2>(*this);
161 }
162 
163 template<class T1, class T2>
164 void
165 SpeciesThermoDuo<T1, T2>::install(const std::string& name, size_t sp, int type,
166  const doublereal* c,
167  doublereal minTemp_,
168  doublereal maxTemp_,
169  doublereal refPressure_)
170 {
171  m_p0 = refPressure_;
172  if (type == m_thermo1.ID) {
173  m_thermo1.install(name, sp, 0, c, minTemp_, maxTemp_,
174  refPressure_);
175  speciesToType[sp] = m_thermo1.ID;
176  } else if (type == m_thermo2.ID) {
177  m_thermo2.install(name, sp, 0, c, minTemp_, maxTemp_,
178  refPressure_);
179  speciesToType[sp] = m_thermo2.ID;
180  } else {
181  throw UnknownSpeciesThermo("SpeciesThermoDuo:install",type);
182  }
183 }
184 
185 template<class T1, class T2>
186 void
187 SpeciesThermoDuo<T1, T2>::update(doublereal t, doublereal* cp_R,
188  doublereal* h_RT, doublereal* s_R) const
189 {
190  m_thermo1.update(t, cp_R, h_RT, s_R);
191  m_thermo2.update(t, cp_R, h_RT, s_R);
192 }
193 
194 template<class T1, class T2>
195 int
197 {
198  std::map<size_t, int>::const_iterator p = speciesToType.find(k);
199  if (p != speciesToType.end()) {
200  return p->second;
201  }
202  return -1;
203 }
204 
205 template<class T1, class T2>
206 void
208  doublereal* const c,
209  doublereal& minTemp_,
210  doublereal& maxTemp_,
211  doublereal& refPressure_) const
212 {
213  int ctype = reportType(index);
214  if (ctype == m_thermo1.ID) {
215  m_thermo1.reportParams(index, type, c, minTemp_, maxTemp_,
216  refPressure_);
217  } else if (ctype == m_thermo2.ID) {
218  m_thermo2.reportParams(index, type, c, minTemp_, maxTemp_,
219  refPressure_);
220  } else {
221  throw CanteraError(" ", "confused");
222  }
223 }
224 
225 }
226 #endif
UnknownSpeciesThermo(const std::string &proc, const std::string &stype)
Alternate constructor.
std::string int2str(const int n, const std::string &fmt)
Convert an int to a string using a format converter.
Definition: stringUtils.cpp:40
Pure Virtual Base class for the thermodynamic manager for an individual species' reference state...
virtual doublereal maxTemp(size_t k=npos) const
Maximum temperature.
T2 m_thermo2
Thermo Type 2.
virtual doublereal minTemp(size_t k=npos) const
Minimum temperature.
const size_t npos
index returned by functions to indicate "no position"
Definition: ct_defs.h:173
This file contains definitions of terms that are used in internal routines and are unlikely to need m...
Virtual base class for the calculation of multiple-species thermodynamic reference-state property man...
doublereal m_p0
Reference pressure.
Pure Virtual base class for the species thermo manager classes.
virtual void reportParams(size_t index, int &type, doublereal *const c, doublereal &minTemp, doublereal &maxTemp, doublereal &refPressure) const
SpeciesThermoDuo & operator=(const SpeciesThermoDuo &right)
Assignment operator.
UnknownSpeciesThermo(const std::string &proc, int type)
constructor
virtual void install(const std::string &name, size_t sp, int type, const doublereal *c, doublereal minTemp, doublereal maxTemp, doublereal refPressure)
Install a new species thermodynamic property parameterization for one species.
virtual void install_STIT(SpeciesThermoInterpType *stit_ptr)
Install a new species thermodynamic property parameterization for one species.
SpeciesThermoDuo(const SpeciesThermoDuo &right)
copy constructor
Base class for exceptions thrown by Cantera classes.
Definition: ctexceptions.h:68
virtual doublereal refPressure(size_t k=npos) const
The reference-state pressure for species k.
SpeciesThermoDuo()
Constructor.
virtual SpeciesThermo * duplMyselfAsSpeciesThermo() const
Duplication routine for objects derived from SpeciesThermo.
This species thermo manager requires that all species have one of two parameterizations.
Unknown species thermo manager string error.
Contains declarations for string manipulation functions within Cantera.
T1 m_thermo1
Thermo Type 1.
virtual void update(doublereal t, doublereal *cp_R, doublereal *h_RT, doublereal *s_R) const
Compute the reference-state properties for all species.
Definitions for the classes that are thrown when Cantera experiences an error condition (also contain...
virtual int reportType(size_t k) const
This utility function reports the type of parameterization used for the species with index number ind...
std::map< size_t, int > speciesToType
map from species to type