Cantera  3.2.0a2
Loading...
Searching...
No Matches
ReactorBase.h
Go to the documentation of this file.
1//! @file ReactorBase.h
2
3// This file is part of Cantera. See License.txt in the top-level directory or
4// at https://cantera.org/license.txt for license and copyright information.
5
6#ifndef CT_REACTORBASE_H
7#define CT_REACTORBASE_H
8
11
12namespace Cantera
13{
14
15//! @defgroup zerodGroup Zero-Dimensional Reactor Networks
16//!
17//! @details See the [Reactor Science](../reference/reactors/index.html) section of the
18//! %Cantera website for a description of the governing equations for specific reactor
19//! types and the methods used for solving networks of interconnected reactors.
20
21class FlowDevice;
22class WallBase;
23class ReactorNet;
24class ReactorSurface;
25class Kinetics;
26class ThermoPhase;
27class Solution;
28
29enum class SensParameterType {
30 reaction,
31 enthalpy
32};
33
35{
36 size_t local; //!< local parameter index
37 size_t global; //!< global parameter index
38 double value; //!< nominal value of the parameter
39 SensParameterType type; //!< type of sensitivity parameter
40};
41
42/**
43 * Base class for reactor objects. Allows using any substance model, with arbitrary
44 * inflow, outflow, heat loss/gain, surface chemistry, and volume change, whenever
45 * defined.
46 * @ingroup reactorGroup
47 */
49{
50public:
51 explicit ReactorBase(const string& name="(none)");
52 //! Instantiate a ReactorBase object with Solution contents.
53 //! @param sol Solution object to be set.
54 //! @param name Name of the reactor.
55 //! @since New in %Cantera 3.1.
56 ReactorBase(shared_ptr<Solution> sol, const string& name="(none)");
57 virtual ~ReactorBase();
58 ReactorBase(const ReactorBase&) = delete;
59 ReactorBase& operator=(const ReactorBase&) = delete;
60
61 //! String indicating the reactor model implemented. Usually
62 //! corresponds to the name of the derived class.
63 virtual string type() const {
64 return "ReactorBase";
65 }
66
67 //! Return the name of this reactor
68 string name() const {
69 return m_name;
70 }
71
72 //! Set the name of this reactor
73 void setName(const string& name) {
74 m_name = name;
75 }
76
77 //! Set the default name of a reactor. Returns `false` if it was previously set.
78 bool setDefaultName(map<string, int>& counts);
79
80 //! Set the Solution specifying the ReactorBase content.
81 //! @param sol Solution object to be set.
82 //! @since New in %Cantera 3.1.
83 //! @deprecated To be removed after %Cantera 3.2. Superseded by instantiation of
84 //! ReactorBase with Solution object.
85 void setSolution(shared_ptr<Solution> sol);
86
87 //! @name Methods to set up a simulation
88 //! @{
89
90 //! Set the initial reactor volume.
91 virtual void setInitialVolume(double vol) {
92 throw NotImplementedError("ReactorBase::setInitialVolume",
93 "Volume is undefined for reactors of type '{}'.", type());
94 }
95
96 //! Enable or disable changes in reactor composition due to chemical reactions.
97 virtual void setChemistry(bool cflag = true) {
98 throw NotImplementedError("ReactorBase::setChemistry");
99 }
100
101 //! Set the energy equation on or off.
102 virtual void setEnergy(int eflag = 1) {
103 throw NotImplementedError("ReactorBase::setEnergy");
104 }
105
106 //! Connect an inlet FlowDevice to this reactor
107 virtual void addInlet(FlowDevice& inlet);
108
109 //! Connect an outlet FlowDevice to this reactor
110 virtual void addOutlet(FlowDevice& outlet);
111
112 //! Return a reference to the *n*-th inlet FlowDevice connected to this reactor.
113 FlowDevice& inlet(size_t n = 0);
114
115 //! Return a reference to the *n*-th outlet FlowDevice connected to this reactor.
116 FlowDevice& outlet(size_t n = 0);
117
118 //! Return the number of inlet FlowDevice objects connected to this reactor.
119 size_t nInlets() {
120 return m_inlet.size();
121 }
122
123 //! Return the number of outlet FlowDevice objects connected to this reactor.
124 size_t nOutlets() {
125 return m_outlet.size();
126 }
127
128 //! Return the number of Wall objects connected to this reactor.
129 size_t nWalls() {
130 return m_wall.size();
131 }
132
133 //! Insert a Wall between this reactor and another reactor.
134 /*!
135 * `lr` = 0 if this reactor is to the left of the wall and `lr` = 1 if
136 * this reactor is to the right of the wall. This method is called
137 * automatically for both the left and right reactors by WallBase::install.
138 */
139 virtual void addWall(WallBase& w, int lr);
140
141 //! Return a reference to the *n*-th Wall connected to this reactor.
142 WallBase& wall(size_t n);
143
144 //! Add a ReactorSurface object to a Reactor object.
145 virtual void addSurface(ReactorSurface* surf);
146
147 //! Add a ReactorSurface object to a Reactor object.
148 void addSurface(shared_ptr<ReactorBase> surf);
149
150 //! Return a reference to the *n*-th ReactorSurface connected to this reactor.
151 ReactorSurface* surface(size_t n);
152
153 //! Return the number of surfaces in a reactor
154 virtual size_t nSurfs() const {
155 return m_surfaces.size();
156 }
157
158 /**
159 * Initialize the reactor. Called automatically by ReactorNet::initialize.
160 */
161 virtual void initialize(double t0 = 0.0) {
162 throw NotImplementedError("ReactorBase::initialize");
163 }
164
165 //! @}
166
167 //! Set the state of the Phase object associated with this reactor to the
168 //! reactor's current state.
169 void restoreState();
170
171 //! Set the state of the reactor to the associated ThermoPhase object.
172 //! This method is the inverse of restoreState() and will trigger integrator
173 //! reinitialization.
174 virtual void syncState();
175
176 //! return a reference to the contents.
178 if (!m_thermo) {
179 throw CanteraError("ReactorBase::contents",
180 "Reactor contents not defined.");
181 }
182 return *m_thermo;
183 }
184
185 const ThermoPhase& contents() const {
186 if (!m_thermo) {
187 throw CanteraError("ReactorBase::contents",
188 "Reactor contents not defined.");
189 }
190 return *m_thermo;
191 }
192
193 //! Return the residence time (s) of the contents of this reactor, based
194 //! on the outlet mass flow rates and the mass of the reactor contents.
195 double residenceTime();
196
197 //! @name Solution components
198 //!
199 //! The values returned are those after the last call to ReactorNet::advance
200 //! or ReactorNet::step.
201 //! @{
202
203 //! Returns the current volume (m^3) of the reactor.
204 double volume() const {
205 return m_vol;
206 }
207
208 //! Returns the current density (kg/m^3) of the reactor's contents.
209 double density() const {
210 if (m_state.empty()) {
211 throw CanteraError("ReactorBase::density",
212 "Reactor state empty and/or contents not defined.");
213 }
214 return m_state[1];
215 }
216
217 //! Returns the current temperature (K) of the reactor's contents.
218 double temperature() const {
219 if (m_state.empty()) {
220 throw CanteraError("ReactorBase::temperature",
221 "Reactor state empty and/or contents not defined.");
222 }
223 return m_state[0];
224 }
225
226 //! Returns the current enthalpy (J/kg) of the reactor's contents.
227 double enthalpy_mass() const {
228 return m_enthalpy;
229 }
230
231 //! Returns the current internal energy (J/kg) of the reactor's contents.
232 //! @deprecated To be removed after %Cantera 3.2.
233 double intEnergy_mass() const {
234 warn_deprecated("ReactorBase::intEnergy_mass",
235 "To be removed after Cantera 3.2.");
236 return m_intEnergy;
237 }
238
239 //! Returns the current pressure (Pa) of the reactor.
240 double pressure() const {
241 return m_pressure;
242 }
243
244 //! Returns the mass (kg) of the reactor's contents.
245 double mass() const {
246 return m_mass;
247 }
248
249 //! Return the vector of species mass fractions.
250 const double* massFractions() const {
251 if (m_state.empty()) {
252 throw CanteraError("ReactorBase::massFractions",
253 "Reactor state empty and/or contents not defined.");
254 }
255 return m_state.data() + 2;
256 }
257
258 //! Return the mass fraction of the *k*-th species.
259 double massFraction(size_t k) const {
260 if (m_state.empty()) {
261 throw CanteraError("ReactorBase::massFraction",
262 "Reactor state empty and/or contents not defined.");
263 }
264 return m_state[k+2];
265 }
266
267 //! @}
268
269 //! The ReactorNet that this reactor belongs to.
271
272 //! Set the ReactorNet that this reactor belongs to.
273 void setNetwork(ReactorNet* net);
274
275 //! Add a sensitivity parameter associated with the reaction number *rxn*
276 virtual void addSensitivityReaction(size_t rxn) {
277 throw NotImplementedError("ReactorBase::addSensitivityReaction");
278 }
279
280 //! Number of sensitivity parameters associated with this reactor.
281 virtual size_t nSensParams() const {
282 return m_sensParams.size();
283 }
284
285protected:
286 //! Specify the mixture contained in the reactor. Note that a pointer to
287 //! this substance is stored, and as the integration proceeds, the state of
288 //! the substance is modified.
289 //! @since New in %Cantera 3.1.
290 virtual void setThermo(ThermoPhase& thermo);
291
292 //! Specify the kinetics manager for the reactor. Called by setSolution().
293 //! @since New in %Cantera 3.1.
294 //! @deprecated To be removed after %Cantera 3.2. Superseded by instantiation of
295 //! ReactorBase with Solution object.
296 virtual void setKinetics(Kinetics& kin) {
297 throw NotImplementedError("ReactorBase::setKinetics");
298 }
299
300 //! Number of homogeneous species in the mixture
301 size_t m_nsp = 0;
302
303 ThermoPhase* m_thermo = nullptr;
304 double m_vol = 0.0; //!< Current volume of the reactor [m^3]
305 double m_mass = 0.0; //!< Current mass of the reactor [kg]
306 double m_enthalpy = 0.0; //!< Current specific enthalpy of the reactor [J/kg]
307
308 //! Current internal energy of the reactor [J/kg]
309 //! @deprecated To be removed after %Cantera 3.2
310 double m_intEnergy = 0.0;
311 double m_pressure = 0.0; //!< Current pressure in the reactor [Pa]
312 vector<double> m_state;
313 vector<FlowDevice*> m_inlet, m_outlet;
314
315 vector<WallBase*> m_wall;
316 vector<ReactorSurface*> m_surfaces;
317
318 //! Vector of length nWalls(), indicating whether this reactor is on the left (0)
319 //! or right (1) of each wall.
320 vector<int> m_lr;
321 string m_name; //!< Reactor name.
322 bool m_defaultNameSet = false; //!< `true` if default name has been previously set.
323
324 //! The ReactorNet that this reactor is part of
325 ReactorNet* m_net = nullptr;
326
327 //! Composite thermo/kinetics/transport handler
328 shared_ptr<Solution> m_solution;
329
330 // Data associated each sensitivity parameter
331 vector<SensitivityParameter> m_sensParams;
332};
333}
334
335#endif
Base class for exceptions thrown by Cantera classes.
Base class for 'flow devices' (valves, pressure regulators, etc.) connecting reactors.
Definition FlowDevice.h:25
Public interface for kinetics managers.
Definition Kinetics.h:126
An error indicating that an unimplemented function has been called.
Base class for reactor objects.
Definition ReactorBase.h:49
virtual void setThermo(ThermoPhase &thermo)
Specify the mixture contained in the reactor.
FlowDevice & outlet(size_t n=0)
Return a reference to the n-th outlet FlowDevice connected to this reactor.
double massFraction(size_t k) const
Return the mass fraction of the k-th species.
shared_ptr< Solution > m_solution
Composite thermo/kinetics/transport handler.
bool m_defaultNameSet
true if default name has been previously set.
size_t nWalls()
Return the number of Wall objects connected to this reactor.
WallBase & wall(size_t n)
Return a reference to the n-th Wall connected to this reactor.
double density() const
Returns the current density (kg/m^3) of the reactor's contents.
double pressure() const
Returns the current pressure (Pa) of the reactor.
virtual void addOutlet(FlowDevice &outlet)
Connect an outlet FlowDevice to this reactor.
double m_pressure
Current pressure in the reactor [Pa].
virtual string type() const
String indicating the reactor model implemented.
Definition ReactorBase.h:63
ReactorNet * m_net
The ReactorNet that this reactor is part of.
virtual void addWall(WallBase &w, int lr)
Insert a Wall between this reactor and another reactor.
void setNetwork(ReactorNet *net)
Set the ReactorNet that this reactor belongs to.
bool setDefaultName(map< string, int > &counts)
Set the default name of a reactor. Returns false if it was previously set.
virtual void addSensitivityReaction(size_t rxn)
Add a sensitivity parameter associated with the reaction number rxn
void setName(const string &name)
Set the name of this reactor.
Definition ReactorBase.h:73
virtual void setKinetics(Kinetics &kin)
Specify the kinetics manager for the reactor.
virtual size_t nSurfs() const
Return the number of surfaces in a reactor.
FlowDevice & inlet(size_t n=0)
Return a reference to the n-th inlet FlowDevice connected to this reactor.
double temperature() const
Returns the current temperature (K) of the reactor's contents.
vector< int > m_lr
Vector of length nWalls(), indicating whether this reactor is on the left (0) or right (1) of each wa...
double m_vol
Current volume of the reactor [m^3].
virtual size_t nSensParams() const
Number of sensitivity parameters associated with this reactor.
virtual void setChemistry(bool cflag=true)
Enable or disable changes in reactor composition due to chemical reactions.
Definition ReactorBase.h:97
virtual void addInlet(FlowDevice &inlet)
Connect an inlet FlowDevice to this reactor.
void setSolution(shared_ptr< Solution > sol)
Set the Solution specifying the ReactorBase content.
virtual void syncState()
Set the state of the reactor to the associated ThermoPhase object.
double m_intEnergy
Current internal energy of the reactor [J/kg].
double m_mass
Current mass of the reactor [kg].
virtual void setEnergy(int eflag=1)
Set the energy equation on or off.
const double * massFractions() const
Return the vector of species mass fractions.
size_t m_nsp
Number of homogeneous species in the mixture.
string m_name
Reactor name.
double intEnergy_mass() const
Returns the current internal energy (J/kg) of the reactor's contents.
double mass() const
Returns the mass (kg) of the reactor's contents.
virtual void setInitialVolume(double vol)
Set the initial reactor volume.
Definition ReactorBase.h:91
double volume() const
Returns the current volume (m^3) of the reactor.
void restoreState()
Set the state of the Phase object associated with this reactor to the reactor's current state.
ReactorNet & network()
The ReactorNet that this reactor belongs to.
double residenceTime()
Return the residence time (s) of the contents of this reactor, based on the outlet mass flow rates an...
size_t nOutlets()
Return the number of outlet FlowDevice objects connected to this reactor.
virtual void initialize(double t0=0.0)
Initialize the reactor.
size_t nInlets()
Return the number of inlet FlowDevice objects connected to this reactor.
ReactorSurface * surface(size_t n)
Return a reference to the n-th ReactorSurface connected to this reactor.
double m_enthalpy
Current specific enthalpy of the reactor [J/kg].
ThermoPhase & contents()
return a reference to the contents.
string name() const
Return the name of this reactor.
Definition ReactorBase.h:68
double enthalpy_mass() const
Returns the current enthalpy (J/kg) of the reactor's contents.
virtual void addSurface(ReactorSurface *surf)
Add a ReactorSurface object to a Reactor object.
A class representing a network of connected reactors.
Definition ReactorNet.h:30
A surface where reactions can occur that is in contact with the bulk fluid of a Reactor.
Base class for a phase with thermodynamic properties.
Base class for 'walls' (walls, pistons, etc.) connecting reactors.
Definition Wall.h:23
Definitions for the classes that are thrown when Cantera experiences an error condition (also contain...
This file contains definitions for utility functions and text for modules, inputfiles and logging,...
Namespace for the Cantera kernel.
Definition AnyMap.cpp:595
void warn_deprecated(const string &source, const AnyBase &node, const string &message)
A deprecation warning for syntax in an input file.
Definition AnyMap.cpp:1997
size_t global
global parameter index
Definition ReactorBase.h:37
SensParameterType type
type of sensitivity parameter
Definition ReactorBase.h:39
size_t local
local parameter index
Definition ReactorBase.h:36
double value
nominal value of the parameter
Definition ReactorBase.h:38