Cantera  2.2.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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 
12 namespace Cantera
13 {
15  m_tlow_max(0.0),
16  m_thigh_min(1.0E30),
17  m_p0(OneAtm)
18 {
19 }
20 
22  SpeciesThermo(b),
23  m_tpoly(b.m_tpoly),
24  m_speciesLoc(b.m_speciesLoc),
25  m_tlow_max(b.m_tlow_max),
26  m_thigh_min(b.m_thigh_min),
27  m_p0(b.m_p0)
28 {
29  m_sp.clear();
30  // Copy SpeciesThermoInterpTypes from 'b'
31  for (STIT_map::const_iterator iter = b.m_sp.begin();
32  iter != b.m_sp.end();
33  iter++) {
34  for (size_t k = 0; k < iter->second.size(); k++) {
35  size_t i = iter->second[k].first;
36  shared_ptr<SpeciesThermoInterpType> spec(
37  iter->second[k].second->duplMyselfAsSpeciesThermoInterpType());
38  m_sp[iter->first].push_back(std::make_pair(i, spec));
39  }
40  }
41 }
42 
45 {
46  if (&b == this) {
47  return *this;
48  }
49 
50  SpeciesThermo::operator=(b);
51  m_sp.clear();
52  // Copy SpeciesThermoInterpType objects from 'b'
53  for (STIT_map::const_iterator iter = b.m_sp.begin();
54  iter != b.m_sp.end();
55  iter++) {
56  for (size_t k = 0; k < iter->second.size(); k++) {
57  size_t i = iter->second[k].first;
58  shared_ptr<SpeciesThermoInterpType> spec(
59  iter->second[k].second->duplMyselfAsSpeciesThermoInterpType());
60  m_sp[iter->first].push_back(std::make_pair(i, spec));
61  }
62  }
63 
64  m_tpoly = b.m_tpoly;
65  m_speciesLoc = b.m_speciesLoc;
68  m_p0 = b.m_p0;
69 
70  return *this;
71 }
72 
75 {
76  return new GeneralSpeciesThermo(*this);
77 }
78 
79 void GeneralSpeciesThermo::install(const std::string& name,
80  size_t index,
81  int type,
82  const doublereal* c,
83  doublereal minTemp_,
84  doublereal maxTemp_,
85  doublereal refPressure_)
86 {
87  warn_deprecated("GeneralSpeciesThermo::install",
88  "Use newSpeciesThermoInterpType and "
89  "GeneralSpeciesThermo::install_STIT instead");
90  if (minTemp_ <= 0.0) {
91  throw CanteraError("GeneralSpeciesThermo::install",
92  "T_min must be positive");
93  }
94 
95  /*
96  * Create the necessary object
97  */
98  shared_ptr<SpeciesThermoInterpType> sp(newSpeciesThermoInterpType(type,
99  minTemp_, maxTemp_, refPressure_, c));
100  sp->validate(name);
101  install_STIT(index, sp);
102 }
103 
105  shared_ptr<SpeciesThermoInterpType> stit_ptr)
106 {
107  if (!stit_ptr) {
108  throw CanteraError("GeneralSpeciesThermo::install_STIT",
109  "zero pointer");
110  }
111  AssertThrow(m_speciesLoc.find(index) == m_speciesLoc.end(),
112  "Index position isn't null, duplication of assignment: " + int2str(index));
113  int type = stit_ptr->reportType();
114  m_speciesLoc[index] = std::make_pair(type, m_sp[type].size());
115  m_sp[type].push_back(std::make_pair(index, stit_ptr));
116  if (m_sp[type].size() == 1) {
117  m_tpoly[type].resize(stit_ptr->temperaturePolySize());
118  }
119 
120  // Calculate max and min T
121  m_tlow_max = std::max(stit_ptr->minTemp(), m_tlow_max);
122  m_thigh_min = std::min(stit_ptr->maxTemp(), m_thigh_min);
123  markInstalled(index);
124 }
125 
127  VPSSMgr* vpssmgr_ptr)
128 {
129  shared_ptr<SpeciesThermoInterpType> stit_ptr(new STITbyPDSS(k, vpssmgr_ptr, PDSS_ptr));
130  install_STIT(k, stit_ptr);
131 }
132 
133 void GeneralSpeciesThermo::update_one(size_t k, doublereal t, doublereal* cp_R,
134  doublereal* h_RT, doublereal* s_R) const
135 {
136  const SpeciesThermoInterpType* sp_ptr = provideSTIT(k);
137  if (sp_ptr) {
138  sp_ptr->updatePropertiesTemp(t, cp_R+k, h_RT+k, s_R+k);
139  }
140 }
141 
142 void GeneralSpeciesThermo::update(doublereal t, doublereal* cp_R,
143  doublereal* h_RT, doublereal* s_R) const
144 {
145  STIT_map::const_iterator iter = m_sp.begin();
146  tpoly_map::iterator jter = m_tpoly.begin();
147  for (; iter != m_sp.end(); iter++, jter++) {
148  const std::vector<index_STIT>& species = iter->second;
149  double* tpoly = &jter->second[0];
150  species[0].second->updateTemperaturePoly(t, tpoly);
151  for (size_t k = 0; k < species.size(); k++) {
152  size_t i = species[k].first;
153  species[k].second->updateProperties(tpoly, cp_R+i, h_RT+i, s_R+i);
154  }
155  }
156 }
157 
158 int GeneralSpeciesThermo::reportType(size_t index) const
159 {
160  const SpeciesThermoInterpType* sp = provideSTIT(index);
161  if (sp) {
162  return sp->reportType();
163  }
164  return -1;
165 }
166 
167 void GeneralSpeciesThermo::reportParams(size_t index, int& type,
168  doublereal* const c, doublereal& minTemp_, doublereal& maxTemp_,
169  doublereal& refPressure_) const
170 {
171  const SpeciesThermoInterpType* sp = provideSTIT(index);
172  size_t n;
173  if (sp) {
174  sp->reportParameters(n, type, minTemp_, maxTemp_,
175  refPressure_, c);
176  } else {
177  type = -1;
178  }
179 }
180 
181 doublereal GeneralSpeciesThermo::minTemp(size_t k) const
182 {
183  if (k != npos) {
184  const SpeciesThermoInterpType* sp = provideSTIT(k);
185  if (sp) {
186  return sp->minTemp();
187  }
188  }
189  return m_tlow_max;
190 }
191 
192 doublereal GeneralSpeciesThermo::maxTemp(size_t k) const
193 {
194  if (k != npos) {
195  const SpeciesThermoInterpType* sp = provideSTIT(k);
196  if (sp) {
197  return sp->maxTemp();
198  }
199  }
200  return m_thigh_min;
201 }
202 
203 doublereal GeneralSpeciesThermo::refPressure(size_t k) const
204 {
205  if (k != npos) {
206  const SpeciesThermoInterpType* sp = provideSTIT(k);
207  if (sp) {
208  return sp->refPressure();
209  }
210  }
211  return m_p0;
212 }
213 
215 {
216  try {
217  const std::pair<int, size_t>& loc = getValue(m_speciesLoc, k);
218  return getValue(m_sp, loc.first)[loc.second].second.get();
219  } catch (std::out_of_range&) {
220  return 0;
221  }
222 }
223 
225 {
226  try {
227  const std::pair<int, size_t>& loc = getValue(m_speciesLoc, k);
228  return getValue(m_sp, loc.first)[loc.second].second.get();
229  } catch (std::out_of_range&) {
230  return 0;
231  }
232 }
233 
234 
235 doublereal GeneralSpeciesThermo::reportOneHf298(const size_t k) const
236 {
237  const SpeciesThermoInterpType* sp_ptr = provideSTIT(k);
238  doublereal h = -1.0;
239  if (sp_ptr) {
240  h = sp_ptr->reportHf298(0);
241  }
242  return h;
243 }
244 
245 void GeneralSpeciesThermo::modifyOneHf298(const size_t k, const doublereal Hf298New)
246 {
248  if (sp_ptr) {
249  sp_ptr->modifyOneHf298(k, Hf298New);
250  }
251 }
252 
253 }
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:39
Pure Virtual Base class for the thermodynamic manager for an individual species' reference state...
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) ...
STIT_map m_sp
This is the main data structure, which contains the SpeciesThermoInterpType objects, sorted by the parameterization type.
const doublereal OneAtm
One atmosphere [Pa].
Definition: ct_defs.h:69
SpeciesThermoInterpType * newSpeciesThermoInterpType(int type, double tlow, double thigh, double pref, const double *coeffs)
Create a new SpeciesThermoInterpType object given a corresponding constant.
virtual doublereal reportHf298(doublereal *const h298=0) const
Report the 298 K Heat of Formation of the standard state of one species (J kmol-1) ...
Virtual base class for the classes that manage the calculation of standard state properties for all t...
Definition: VPSSMgr.h:235
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:165
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:78
doublereal m_tlow_max
Maximum value of the lowest temperature.
Pure Virtual base class for the species thermo manager classes.
virtual void modifyOneHf298(const size_t k, const doublereal Hf298New)
Modify the value of the 298 K Heat of Formation of one species in the phase (J kmol-1) ...
virtual int reportType() const =0
Returns an integer representing the type of parameterization.
void markInstalled(size_t k)
Mark species k as having its thermodynamic data installed.
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...
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:283
virtual doublereal maxTemp(size_t k=npos) const
Maximum temperature.
Base class for exceptions thrown by Cantera classes.
Definition: ctexceptions.h:99
virtual doublereal minTemp(size_t k=npos) const
Minimum temperature.
virtual void install_STIT(size_t index, shared_ptr< SpeciesThermoInterpType > stit_ptr)
Install a new species thermodynamic property parameterization for one species.
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
virtual doublereal minTemp() const
Returns the minimum temperature that the thermo parameterization is valid.
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:193
virtual doublereal refPressure(size_t k=npos) const
The reference-state pressure for species k.
tpoly_map m_tpoly
Temperature polynomials for each thermo parameterization.
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.
virtual int reportType(size_t index) const
This utility function reports the type of parameterization used for the species with index number ind...
virtual void update(doublereal T, doublereal *cp_R, doublereal *h_RT, doublereal *s_R) const
Compute the reference-state properties for all species.
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
This utility function reports back the type of parameterization and all of the parameters for the spe...
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 ...
void installPDSShandler(size_t k, PDSS *PDSS_ptr, VPSSMgr *vpssmgr_ptr)
Install a PDSS object to handle the reference state thermodynamics calculation.