Cantera  2.4.0
MultiSpeciesThermo.cpp
Go to the documentation of this file.
1 /**
2  * @file MultiSpeciesThermo.cpp
3  * Declarations for a thermodynamic property manager for multiple species
4  * in a phase (see \ref spthermo and
5  * \link Cantera::MultiSpeciesThermo MultiSpeciesThermo\endlink).
6  */
7 
8 // This file is part of Cantera. See License.txt in the top-level directory or
9 // at http://www.cantera.org/license.txt for license and copyright information.
10 
14 #include "cantera/base/utilities.h"
16 
17 namespace Cantera
18 {
20  m_tlow_max(0.0),
21  m_thigh_min(1.0E30),
22  m_p0(OneAtm)
23 {
24 }
25 
27  shared_ptr<SpeciesThermoInterpType> stit_ptr)
28 {
29  if (!stit_ptr) {
30  throw CanteraError("MultiSpeciesThermo::install_STIT",
31  "null pointer");
32  }
33  AssertThrowMsg(m_speciesLoc.find(index) == m_speciesLoc.end(),
34  "MultiSpeciesThermo::install_STIT",
35  "Index position isn't null, duplication of assignment: {}", index);
36  int type = stit_ptr->reportType();
37  m_speciesLoc[index] = {type, m_sp[type].size()};
38  m_sp[type].emplace_back(index, stit_ptr);
39  if (m_sp[type].size() == 1) {
40  m_tpoly[type].resize(stit_ptr->temperaturePolySize());
41  }
42 
43  // Calculate max and min T
44  m_tlow_max = std::max(stit_ptr->minTemp(), m_tlow_max);
45  m_thigh_min = std::min(stit_ptr->maxTemp(), m_thigh_min);
46  markInstalled(index);
47 }
48 
50  shared_ptr<SpeciesThermoInterpType> spthermo)
51 {
52  if (!spthermo) {
53  throw CanteraError("MultiSpeciesThermo::modifySpecies",
54  "null pointer");
55  }
56  if (m_speciesLoc.find(index) == m_speciesLoc.end()) {
57  throw CanteraError("MultiSpeciesThermo::modifySpecies",
58  "Species with this index not previously added: {}",
59  index);
60  }
61  int type = spthermo->reportType();
62  if (m_speciesLoc[index].first != type) {
63  throw CanteraError("MultiSpeciesThermo::modifySpecies",
64  "Type of parameterization changed: {} != {}", type,
65  m_speciesLoc[index].first);
66  }
67  if (spthermo->minTemp() > m_tlow_max) {
68  throw CanteraError("MultiSpeciesThermo::modifySpecies",
69  "Cannot increase minimum temperature for phase from {} to {}",
70  m_tlow_max, spthermo->minTemp());
71  }
72  if (spthermo->maxTemp() < m_thigh_min) {
73  throw CanteraError("MultiSpeciesThermo::modifySpecies",
74  "Cannot increase minimum temperature for phase from {} to {}",
75  m_thigh_min, spthermo->maxTemp());
76  }
77 
78  m_sp[type][m_speciesLoc[index].second] = {index, spthermo};
79 }
80 
81 void MultiSpeciesThermo::update_one(size_t k, doublereal t, doublereal* cp_R,
82  doublereal* h_RT, doublereal* s_R) const
83 {
84  warn_deprecated("MultiSpeciesThermo::update_one",
85  "Use update_single instead. To be removed after Cantera 2.4");
86  const SpeciesThermoInterpType* sp_ptr = provideSTIT(k);
87  if (sp_ptr) {
88  sp_ptr->updatePropertiesTemp(t, cp_R+k, h_RT+k, s_R+k);
89  }
90 }
91 
92 void MultiSpeciesThermo::update_single(size_t k, double t, double* cp_R,
93  double* h_RT, double* s_R) const
94 {
95  const SpeciesThermoInterpType* sp_ptr = provideSTIT(k);
96  if (sp_ptr) {
97  sp_ptr->updatePropertiesTemp(t, cp_R, h_RT, s_R);
98  }
99 }
100 
101 void MultiSpeciesThermo::update(doublereal t, doublereal* cp_R,
102  doublereal* h_RT, doublereal* s_R) const
103 {
104  auto iter = m_sp.begin();
105  auto jter = m_tpoly.begin();
106  for (; iter != m_sp.end(); iter++, jter++) {
107  const std::vector<index_STIT>& species = iter->second;
108  double* tpoly = &jter->second[0];
109  species[0].second->updateTemperaturePoly(t, tpoly);
110  for (size_t k = 0; k < species.size(); k++) {
111  size_t i = species[k].first;
112  species[k].second->updateProperties(tpoly, cp_R+i, h_RT+i, s_R+i);
113  }
114  }
115 }
116 
117 int MultiSpeciesThermo::reportType(size_t index) const
118 {
119  const SpeciesThermoInterpType* sp = provideSTIT(index);
120  if (sp) {
121  return sp->reportType();
122  }
123  return -1;
124 }
125 
126 void MultiSpeciesThermo::reportParams(size_t index, int& type,
127  doublereal* const c, doublereal& minTemp_, doublereal& maxTemp_,
128  doublereal& refPressure_) const
129 {
130  const SpeciesThermoInterpType* sp = provideSTIT(index);
131  size_t n;
132  if (sp) {
133  sp->reportParameters(n, type, minTemp_, maxTemp_,
134  refPressure_, c);
135  } else {
136  type = -1;
137  }
138 }
139 
140 doublereal MultiSpeciesThermo::minTemp(size_t k) const
141 {
142  if (k != npos) {
143  const SpeciesThermoInterpType* sp = provideSTIT(k);
144  if (sp) {
145  return sp->minTemp();
146  }
147  }
148  return m_tlow_max;
149 }
150 
151 doublereal MultiSpeciesThermo::maxTemp(size_t k) const
152 {
153  if (k != npos) {
154  const SpeciesThermoInterpType* sp = provideSTIT(k);
155  if (sp) {
156  return sp->maxTemp();
157  }
158  }
159  return m_thigh_min;
160 }
161 
162 doublereal MultiSpeciesThermo::refPressure(size_t k) const
163 {
164  if (k != npos) {
165  const SpeciesThermoInterpType* sp = provideSTIT(k);
166  if (sp) {
167  return sp->refPressure();
168  }
169  }
170  return m_p0;
171 }
172 
174 {
175  try {
176  const std::pair<int, size_t>& loc = m_speciesLoc.at(k);
177  return m_sp.at(loc.first)[loc.second].second.get();
178  } catch (std::out_of_range&) {
179  return 0;
180  }
181 }
182 
184 {
185  try {
186  const std::pair<int, size_t>& loc = m_speciesLoc.at(k);
187  return m_sp.at(loc.first)[loc.second].second.get();
188  } catch (std::out_of_range&) {
189  return 0;
190  }
191 }
192 
193 doublereal MultiSpeciesThermo::reportOneHf298(const size_t k) const
194 {
195  const SpeciesThermoInterpType* sp_ptr = provideSTIT(k);
196  doublereal h = -1.0;
197  if (sp_ptr) {
198  h = sp_ptr->reportHf298(0);
199  }
200  return h;
201 }
202 
203 void MultiSpeciesThermo::modifyOneHf298(const size_t k, const doublereal Hf298New)
204 {
206  if (sp_ptr) {
207  sp_ptr->modifyOneHf298(k, Hf298New);
208  }
209 }
210 
211 void MultiSpeciesThermo::resetHf298(const size_t k)
212 {
214  if (sp_ptr) {
215  sp_ptr->resetHf298();
216  }
217 }
218 
219 bool MultiSpeciesThermo::ready(size_t nSpecies) {
220  if (m_installed.size() < nSpecies) {
221  return false;
222  }
223  for (size_t k = 0; k < nSpecies; k++) {
224  if (!m_installed[k]) {
225  return false;
226  }
227  }
228  return true;
229 }
230 
232  if (k >= m_installed.size()) {
233  m_installed.resize(k+1, false);
234  }
235  m_installed[k] = true;
236 }
237 
238 }
Header for a general species thermodynamic property manager for a phase (see MultiSpeciesThermo).
virtual doublereal maxTemp(size_t k=npos) const
Maximum temperature.
Abstract Base class for the thermodynamic manager for an individual species&#39; reference state...
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 doublereal reportHf298(doublereal *const h298=0) const
Report the 298 K Heat of Formation of the standard state of one species (J kmol-1) ...
const doublereal OneAtm
One atmosphere [Pa].
Definition: ct_defs.h:69
bool ready(size_t nSpecies)
Check if data for all species (0 through nSpecies-1) has been installed.
virtual doublereal minTemp() const
Returns the minimum temperature that the thermo parameterization is valid.
virtual void resetHf298(const size_t k)
Restore the original heat of formation of one or more species.
Various templated functions that carry out common vector operations (see Templated Utility Functions)...
virtual void modifySpecies(size_t index, shared_ptr< SpeciesThermoInterpType > spec)
Modify the species thermodynamic property parameterization for a species.
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 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 ...
const size_t npos
index returned by functions to indicate "no position"
Definition: ct_defs.h:165
void warn_deprecated(const std::string &method, const std::string &extra)
Print a warning indicating that method is deprecated.
Definition: global.cpp:54
virtual doublereal refPressure(size_t k=npos) const
The reference-state pressure for species k.
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) ...
doublereal m_p0
reference pressure (Pa)
virtual int reportType() const =0
Returns an integer representing the type of parameterization.
std::map< size_t, std::pair< int, size_t > > m_speciesLoc
Map from species index to location within m_sp, such that m_sp[m_speciesLoc[k].first][m_speciesLoc[k]...
virtual int reportType(size_t index) const
This utility function reports the type of parameterization used for the species with index number ind...
doublereal m_tlow_max
Maximum value of the lowest temperature.
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...
void markInstalled(size_t k)
Mark species k as having its thermodynamic data installed.
SpeciesThermoInterpType * provideSTIT(size_t k)
Provide the SpeciesthermoInterpType object.
Base class for exceptions thrown by Cantera classes.
Definition: ctexceptions.h:65
STIT_map m_sp
This is the main data structure, which contains the SpeciesThermoInterpType objects, sorted by the parameterization type.
doublereal m_thigh_min
Minimum value of the highest temperature.
virtual doublereal minTemp(size_t k=npos) const
Minimum temperature.
virtual doublereal refPressure() const
Returns the reference pressure (Pa)
#define AssertThrowMsg(expr, procedure,...)
Assertion must be true or an error is thrown.
Definition: ctexceptions.h:264
Header for factory functions to build instances of classes that manage the standard-state thermodynam...
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.
Contains declarations for string manipulation functions within Cantera.
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.
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) ...
virtual doublereal maxTemp() const
Returns the maximum temperature that the thermo parameterization is valid.
virtual void resetHf298()
Restore the original heat of formation for this species.
virtual void install_STIT(size_t index, shared_ptr< SpeciesThermoInterpType > stit)
Install a new species thermodynamic property parameterization for one species.
Namespace for the Cantera kernel.
Definition: AnyMap.cpp:8
virtual void update_single(size_t k, double T, double *cp_R, double *h_RT, double *s_R) const
Like update_one, but without applying offsets to the output pointers.
tpoly_map m_tpoly
Temperature polynomials for each thermo parameterization.
Definitions for the classes that are thrown when Cantera experiences an error condition (also contain...
std::vector< bool > m_installed
indicates if data for species has been installed