Cantera  2.3.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  m_tpoly(b.m_tpoly),
28  m_speciesLoc(b.m_speciesLoc),
29  m_tlow_max(b.m_tlow_max),
30  m_thigh_min(b.m_thigh_min),
31  m_p0(b.m_p0)
32 {
33  warn_deprecated("MultiSpeciesThermo copy constructor",
34  "To be removed after Cantera 2.3");
35  m_sp.clear();
36  // Copy SpeciesThermoInterpTypes from 'b'
37  for (const auto& sp : b.m_sp) {
38  for (size_t k = 0; k < sp.second.size(); k++) {
39  size_t i = sp.second[k].first;
40  shared_ptr<SpeciesThermoInterpType> spec(
41  sp.second[k].second->duplMyselfAsSpeciesThermoInterpType());
42  m_sp[sp.first].emplace_back(i, spec);
43  }
44  }
45 }
46 
49 {
50  warn_deprecated("MultiSpeciesThermo assignment operator",
51  "To be removed after Cantera 2.3");
52  if (&b == this) {
53  return *this;
54  }
55 
56  m_sp.clear();
57  // Copy SpeciesThermoInterpType objects from 'b'
58  for (const auto& sp : b.m_sp) {
59  for (size_t k = 0; k < sp.second.size(); k++) {
60  size_t i = sp.second[k].first;
61  shared_ptr<SpeciesThermoInterpType> spec(
62  sp.second[k].second->duplMyselfAsSpeciesThermoInterpType());
63  m_sp[sp.first].emplace_back(i, spec);
64  }
65  }
66 
67  m_tpoly = b.m_tpoly;
71  m_p0 = b.m_p0;
72  return *this;
73 }
74 
76 {
77  warn_deprecated("MultiSpeciesThermo::duplMyselfAsSpeciesThermo",
78  "To be removed after Cantera 2.3");
79  return new MultiSpeciesThermo(*this);
80 }
81 
83  shared_ptr<SpeciesThermoInterpType> stit_ptr)
84 {
85  if (!stit_ptr) {
86  throw CanteraError("MultiSpeciesThermo::install_STIT",
87  "null pointer");
88  }
89  AssertThrowMsg(m_speciesLoc.find(index) == m_speciesLoc.end(),
90  "MultiSpeciesThermo::install_STIT",
91  "Index position isn't null, duplication of assignment: {}", index);
92  int type = stit_ptr->reportType();
93  m_speciesLoc[index] = {type, m_sp[type].size()};
94  m_sp[type].emplace_back(index, stit_ptr);
95  if (m_sp[type].size() == 1) {
96  m_tpoly[type].resize(stit_ptr->temperaturePolySize());
97  }
98 
99  // Calculate max and min T
100  m_tlow_max = std::max(stit_ptr->minTemp(), m_tlow_max);
101  m_thigh_min = std::min(stit_ptr->maxTemp(), m_thigh_min);
102  markInstalled(index);
103 }
104 
106  shared_ptr<SpeciesThermoInterpType> spthermo)
107 {
108  if (!spthermo) {
109  throw CanteraError("MultiSpeciesThermo::modifySpecies",
110  "null pointer");
111  }
112  if (m_speciesLoc.find(index) == m_speciesLoc.end()) {
113  throw CanteraError("MultiSpeciesThermo::modifySpecies",
114  "Species with this index not previously added: {}",
115  index);
116  }
117  int type = spthermo->reportType();
118  if (m_speciesLoc[index].first != type) {
119  throw CanteraError("MultiSpeciesThermo::modifySpecies",
120  "Type of parameterization changed: {} != {}", type,
121  m_speciesLoc[index].first);
122  }
123  if (spthermo->minTemp() > m_tlow_max) {
124  throw CanteraError("MultiSpeciesThermo::modifySpecies",
125  "Cannot increase minimum temperature for phase from {} to {}",
126  m_tlow_max, spthermo->minTemp());
127  }
128  if (spthermo->maxTemp() < m_thigh_min) {
129  throw CanteraError("MultiSpeciesThermo::modifySpecies",
130  "Cannot increase minimum temperature for phase from {} to {}",
131  m_thigh_min, spthermo->maxTemp());
132  }
133 
134  m_sp[type][m_speciesLoc[index].second] = {index, spthermo};
135 }
136 
138  VPSSMgr* vpssmgr_ptr)
139 {
140  auto stit_ptr = make_shared<STITbyPDSS>(vpssmgr_ptr, PDSS_ptr);
141  install_STIT(k, stit_ptr);
142 }
143 
144 void MultiSpeciesThermo::update_one(size_t k, doublereal t, doublereal* cp_R,
145  doublereal* h_RT, doublereal* s_R) const
146 {
147  const SpeciesThermoInterpType* sp_ptr = provideSTIT(k);
148  if (sp_ptr) {
149  sp_ptr->updatePropertiesTemp(t, cp_R+k, h_RT+k, s_R+k);
150  }
151 }
152 
153 void MultiSpeciesThermo::update(doublereal t, doublereal* cp_R,
154  doublereal* h_RT, doublereal* s_R) const
155 {
156  auto iter = m_sp.begin();
157  auto jter = m_tpoly.begin();
158  for (; iter != m_sp.end(); iter++, jter++) {
159  const std::vector<index_STIT>& species = iter->second;
160  double* tpoly = &jter->second[0];
161  species[0].second->updateTemperaturePoly(t, tpoly);
162  for (size_t k = 0; k < species.size(); k++) {
163  size_t i = species[k].first;
164  species[k].second->updateProperties(tpoly, cp_R+i, h_RT+i, s_R+i);
165  }
166  }
167 }
168 
169 int MultiSpeciesThermo::reportType(size_t index) const
170 {
171  const SpeciesThermoInterpType* sp = provideSTIT(index);
172  if (sp) {
173  return sp->reportType();
174  }
175  return -1;
176 }
177 
178 void MultiSpeciesThermo::reportParams(size_t index, int& type,
179  doublereal* const c, doublereal& minTemp_, doublereal& maxTemp_,
180  doublereal& refPressure_) const
181 {
182  const SpeciesThermoInterpType* sp = provideSTIT(index);
183  size_t n;
184  if (sp) {
185  sp->reportParameters(n, type, minTemp_, maxTemp_,
186  refPressure_, c);
187  } else {
188  type = -1;
189  }
190 }
191 
192 doublereal MultiSpeciesThermo::minTemp(size_t k) const
193 {
194  if (k != npos) {
195  const SpeciesThermoInterpType* sp = provideSTIT(k);
196  if (sp) {
197  return sp->minTemp();
198  }
199  }
200  return m_tlow_max;
201 }
202 
203 doublereal MultiSpeciesThermo::maxTemp(size_t k) const
204 {
205  if (k != npos) {
206  const SpeciesThermoInterpType* sp = provideSTIT(k);
207  if (sp) {
208  return sp->maxTemp();
209  }
210  }
211  return m_thigh_min;
212 }
213 
214 doublereal MultiSpeciesThermo::refPressure(size_t k) const
215 {
216  if (k != npos) {
217  const SpeciesThermoInterpType* sp = provideSTIT(k);
218  if (sp) {
219  return sp->refPressure();
220  }
221  }
222  return m_p0;
223 }
224 
226 {
227  try {
228  const std::pair<int, size_t>& loc = m_speciesLoc.at(k);
229  return m_sp.at(loc.first)[loc.second].second.get();
230  } catch (std::out_of_range&) {
231  return 0;
232  }
233 }
234 
236 {
237  try {
238  const std::pair<int, size_t>& loc = m_speciesLoc.at(k);
239  return m_sp.at(loc.first)[loc.second].second.get();
240  } catch (std::out_of_range&) {
241  return 0;
242  }
243 }
244 
245 doublereal MultiSpeciesThermo::reportOneHf298(const size_t k) const
246 {
247  const SpeciesThermoInterpType* sp_ptr = provideSTIT(k);
248  doublereal h = -1.0;
249  if (sp_ptr) {
250  h = sp_ptr->reportHf298(0);
251  }
252  return h;
253 }
254 
255 void MultiSpeciesThermo::modifyOneHf298(const size_t k, const doublereal Hf298New)
256 {
258  if (sp_ptr) {
259  sp_ptr->modifyOneHf298(k, Hf298New);
260  }
261 }
262 
263 void MultiSpeciesThermo::resetHf298(const size_t k)
264 {
266  if (sp_ptr) {
267  sp_ptr->resetHf298();
268  }
269 }
270 
271 bool MultiSpeciesThermo::ready(size_t nSpecies) {
272  if (m_installed.size() < nSpecies) {
273  return false;
274  }
275  for (size_t k = 0; k < nSpecies; k++) {
276  if (!m_installed[k]) {
277  return false;
278  }
279  }
280  return true;
281 }
282 
284  if (k >= m_installed.size()) {
285  m_installed.resize(k+1, false);
286  }
287  m_installed[k] = true;
288 }
289 
290 }
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 base class for the classes that manage the calculation of standard state properties for all t...
Definition: VPSSMgr.h:228
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 installPDSShandler(size_t k, PDSS *PDSS_ptr, VPSSMgr *vpssmgr_ptr)
Install a PDSS object to handle the reference state thermodynamics calculation.
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 MultiSpeciesThermo * duplMyselfAsSpeciesThermo() const
Duplication routine for objects derived from MultiSpeciesThermo.
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:270
Header for factory functions to build instances of classes that manage the standard-state thermodynam...
Virtual base class for a species with a pressure dependent standard state.
Definition: PDSS.h:176
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.
MultiSpeciesThermo & operator=(const MultiSpeciesThermo &b)
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.
A species thermodynamic property manager for a phase.
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: application.cpp:29
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