Cantera  3.1.0b1
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 stirred reactors. Allows using any substance model, with
44 * arbitrary inflow, outflow, heat loss/gain, surface chemistry, and volume
45 * change.
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 void setSolution(shared_ptr<Solution> sol);
84
85 //! @name Methods to set up a simulation
86 //! @{
87
88 //! Set the initial reactor volume. By default, the volume is 1.0 m^3.
89 void setInitialVolume(double vol) {
90 m_vol = vol;
91 }
92
93 //! @deprecated To be removed after %Cantera 3.1. Superseded by setSolution.
94 void insert(shared_ptr<Solution> sol);
95
96 //! Specify the mixture contained in the reactor. Note that a pointer to
97 //! this substance is stored, and as the integration proceeds, the state of
98 //! the substance is modified.
99 //! @deprecated To be removed after %Cantera 3.1. Superseded by setSolution.
100 void setThermoMgr(ThermoPhase& thermo);
101
102 //! @deprecated To be removed after %Cantera 3.1. Superseded by setSolution.
103 void setKineticsMgr(Kinetics& kin);
104
105 //! Enable or disable changes in reactor composition due to chemical reactions.
106 virtual void setChemistry(bool cflag = true) {
107 throw NotImplementedError("ReactorBase::setChemistry");
108 }
109
110 //! Set the energy equation on or off.
111 virtual void setEnergy(int eflag = 1) {
112 throw NotImplementedError("ReactorBase::setEnergy");
113 }
114
115 //! Connect an inlet FlowDevice to this reactor
117
118 //! Connect an outlet FlowDevice to this reactor
120
121 //! Return a reference to the *n*-th inlet FlowDevice connected to this
122 //! reactor.
123 FlowDevice& inlet(size_t n = 0);
124
125 //! Return a reference to the *n*-th outlet FlowDevice connected to this
126 //! reactor.
127 FlowDevice& outlet(size_t n = 0);
128
129 //! Return the number of inlet FlowDevice objects connected to this reactor.
130 size_t nInlets() {
131 return m_inlet.size();
132 }
133
134 //! Return the number of outlet FlowDevice objects connected to this
135 //! reactor.
136 size_t nOutlets() {
137 return m_outlet.size();
138 }
139
140 //! Return the number of Wall objects connected to this reactor.
141 size_t nWalls() {
142 return m_wall.size();
143 }
144
145 //! Insert a Wall between this reactor and another reactor.
146 /*!
147 * `lr` = 0 if this reactor is to the left of the wall and `lr` = 1 if
148 * this reactor is to the right of the wall. This method is called
149 * automatically for both the left and right reactors by WallBase::install.
150 */
151 void addWall(WallBase& w, int lr);
152
153 //! Return a reference to the *n*-th Wall connected to this reactor.
154 WallBase& wall(size_t n);
155
156 virtual void addSurface(ReactorSurface* surf);
157
158 //! Return a reference to the *n*-th ReactorSurface connected to this
159 //! reactor
160 ReactorSurface* surface(size_t n);
161
162 //! Return the number of surfaces in a reactor
163 virtual size_t nSurfs() {
164 return m_surfaces.size();
165 }
166
167 /**
168 * Initialize the reactor. Called automatically by ReactorNet::initialize.
169 */
170 virtual void initialize(double t0 = 0.0) {
171 throw NotImplementedError("ReactorBase::initialize");
172 }
173
174 //! @}
175
176 //! Set the state of the Phase object associated with this reactor to the
177 //! reactor's current state.
178 void restoreState();
179
180 //! Set the state of the reactor to correspond to the state of the
181 //! associated ThermoPhase object. This is the inverse of restoreState().
182 //! Calling this will trigger integrator reinitialization.
183 virtual void syncState();
184
185 //! return a reference to the contents.
187 if (!m_thermo) {
188 throw CanteraError("ReactorBase::contents",
189 "Reactor contents not defined.");
190 }
191 return *m_thermo;
192 }
193
194 const ThermoPhase& contents() const {
195 if (!m_thermo) {
196 throw CanteraError("ReactorBase::contents",
197 "Reactor contents not defined.");
198 }
199 return *m_thermo;
200 }
201
202 //! Return the residence time (s) of the contents of this reactor, based
203 //! on the outlet mass flow rates and the mass of the reactor contents.
204 double residenceTime();
205
206 //! @name Solution components
207 //!
208 //! The values returned are those after the last call to ReactorNet::advance
209 //! or ReactorNet::step.
210 //! @{
211
212 //! Returns the current volume (m^3) of the reactor.
213 double volume() const {
214 return m_vol;
215 }
216
217 //! Returns the current density (kg/m^3) of the reactor's contents.
218 double density() const {
219 if (m_state.empty()) {
220 throw CanteraError("ReactorBase::density",
221 "Reactor state empty and/or contents not defined.");
222 }
223 return m_state[1];
224 }
225
226 //! Returns the current temperature (K) of the reactor's contents.
227 double temperature() const {
228 if (m_state.empty()) {
229 throw CanteraError("ReactorBase::temperature",
230 "Reactor state empty and/or contents not defined.");
231 }
232 return m_state[0];
233 }
234
235 //! Returns the current enthalpy (J/kg) of the reactor's contents.
236 double enthalpy_mass() const {
237 return m_enthalpy;
238 }
239
240 //! Returns the current internal energy (J/kg) of the reactor's contents.
241 double intEnergy_mass() const {
242 return m_intEnergy;
243 }
244
245 //! Returns the current pressure (Pa) of the reactor.
246 double pressure() const {
247 return m_pressure;
248 }
249
250 //! Returns the mass (kg) of the reactor's contents.
251 double mass() const {
252 return m_vol * density();
253 }
254
255 //! Return the vector of species mass fractions.
256 const double* massFractions() const {
257 if (m_state.empty()) {
258 throw CanteraError("ReactorBase::massFractions",
259 "Reactor state empty and/or contents not defined.");
260 }
261 return m_state.data() + 2;
262 }
263
264 //! Return the mass fraction of the *k*-th species.
265 double massFraction(size_t k) const {
266 if (m_state.empty()) {
267 throw CanteraError("ReactorBase::massFraction",
268 "Reactor state empty and/or contents not defined.");
269 }
270 return m_state[k+2];
271 }
272
273 //! @}
274
275 //! The ReactorNet that this reactor belongs to.
277
278 //! Set the ReactorNet that this reactor belongs to.
279 void setNetwork(ReactorNet* net);
280
281protected:
282 //! Specify the mixture contained in the reactor. Note that a pointer to
283 //! this substance is stored, and as the integration proceeds, the state of
284 //! the substance is modified.
285 //! @since New in %Cantera 3.1.
286 virtual void setThermo(ThermoPhase& thermo);
287
288 //! Specify the kinetics manager for the reactor. Called by setSolution().
289 //! @since New in %Cantera 3.1.
290 virtual void setKinetics(Kinetics& kin) {
291 throw NotImplementedError("ReactorBase::setKinetics");
292 }
293
294 //! Number of homogeneous species in the mixture
295 size_t m_nsp = 0;
296
297 ThermoPhase* m_thermo = nullptr;
298 double m_vol = 1.0; //!< Current volume of the reactor [m^3]
299 double m_enthalpy = 0.0; //!< Current specific enthalpy of the reactor [J/kg]
300 double m_intEnergy = 0.0; //!< Current internal energy of the reactor [J/kg]
301 double m_pressure = 0.0; //!< Current pressure in the reactor [Pa]
302 vector<double> m_state;
303 vector<FlowDevice*> m_inlet, m_outlet;
304
305 vector<WallBase*> m_wall;
306 vector<ReactorSurface*> m_surfaces;
307
308 //! Vector of length nWalls(), indicating whether this reactor is on the left (0)
309 //! or right (1) of each wall.
310 vector<int> m_lr;
311 string m_name; //!< Reactor name.
312 bool m_defaultNameSet = false; //!< `true` if default name has been previously set.
313
314 //! The ReactorNet that this reactor is part of
315 ReactorNet* m_net = nullptr;
316
317 //! Composite thermo/kinetics/transport handler
318 shared_ptr<Solution> m_solution;
319};
320}
321
322#endif
Base class for exceptions thrown by Cantera classes.
Base class for 'flow devices' (valves, pressure regulators, etc.) connecting reactors.
Definition FlowDevice.h:24
Public interface for kinetics managers.
Definition Kinetics.h:125
An error indicating that an unimplemented function has been called.
Base class for stirred reactors.
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.
void setInitialVolume(double vol)
Set the initial reactor volume. By default, the volume is 1.0 m^3.
Definition ReactorBase.h:89
double pressure() const
Returns the current pressure (Pa) of the reactor.
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.
void insert(shared_ptr< Solution > sol)
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.
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.
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 void setChemistry(bool cflag=true)
Enable or disable changes in reactor composition due to chemical reactions.
void addInlet(FlowDevice &inlet)
Connect an inlet FlowDevice to this reactor.
void setSolution(shared_ptr< Solution > sol)
Set the Solution specifying the ReactorBase content.
void setKineticsMgr(Kinetics &kin)
virtual void syncState()
Set the state of the reactor to correspond to the state of the associated ThermoPhase object.
double m_intEnergy
Current internal energy of the reactor [J/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.
double volume() const
Returns the current volume (m^3) of the reactor.
void setThermoMgr(ThermoPhase &thermo)
Specify the mixture contained in the reactor.
void restoreState()
Set the state of the Phase object associated with this reactor to the reactor's current state.
virtual size_t nSurfs()
Return the number of surfaces in a reactor.
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.
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:22
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
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