| Cantera 3.0.0

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