Cantera  3.1.0a1
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
18//! [Reactor Science](https://cantera.org/science/reactors/reactors.html)
19//! section of the %Cantera website for a description of the governing equations for
20//! specific reactor types and the methods used for solving networks of interconnected
21//! reactors.
22
23class FlowDevice;
24class WallBase;
25class ReactorNet;
26class ReactorSurface;
27class Kinetics;
28class ThermoPhase;
29class Solution;
30
31enum class SensParameterType {
32 reaction,
33 enthalpy
34};
35
37{
38 size_t local; //!< local parameter index
39 size_t global; //!< global parameter index
40 double value; //!< nominal value of the parameter
41 SensParameterType type; //!< type of sensitivity parameter
42};
43
44/**
45 * Base class for stirred reactors. Allows using any substance model, with
46 * arbitrary inflow, outflow, heat loss/gain, surface chemistry, and volume
47 * change.
48 * @ingroup reactorGroup
49 */
51{
52public:
53 explicit ReactorBase(const string& name = "(none)");
54 //! Instantiate a ReactorBase object with Solution contents.
55 //! @param sol Solution object to be set.
56 //! @param name Name of the reactor.
57 //! @since New in %Cantera 3.1.
58 ReactorBase(shared_ptr<Solution> sol, const string& name = "(none)");
59 virtual ~ReactorBase() = default;
60 ReactorBase(const ReactorBase&) = delete;
61 ReactorBase& operator=(const ReactorBase&) = delete;
62
63 //! String indicating the reactor model implemented. Usually
64 //! corresponds to the name of the derived class.
65 virtual string type() const {
66 return "ReactorBase";
67 }
68
69 //! Return the name of this reactor
70 string name() const {
71 return m_name;
72 }
73
74 //! Set the name of this reactor
75 void setName(const string& name) {
76 m_name = name;
77 }
78
79 //! Set the Solution specifying the ReactorBase content.
80 //! @param sol Solution object to be set.
81 //! @since New in %Cantera 3.1.
82 void setSolution(shared_ptr<Solution> sol);
83
84 //! @name Methods to set up a simulation
85 //! @{
86
87 //! Set the initial reactor volume. By default, the volume is 1.0 m^3.
88 void setInitialVolume(double vol) {
89 m_vol = vol;
90 }
91
92 //! @deprecated To be removed after %Cantera 3.1. Superseded by setSolution.
93 void insert(shared_ptr<Solution> sol);
94
95 //! Specify the mixture contained in the reactor. Note that a pointer to
96 //! this substance is stored, and as the integration proceeds, the state of
97 //! the substance is modified.
98 //! @since After %Cantera 3.1, this method will be become a 'protected' method for
99 //! internal use only.
100 //! @todo make protected
101 virtual void setThermoMgr(ThermoPhase& thermo);
102
103 //! @since After %Cantera 3.1, this method will be become a 'protected' method for
104 //! internal use only.
105 //! @todo make protected
106 virtual void setKineticsMgr(Kinetics& kin) {
107 throw NotImplementedError("ReactorBase::setKineticsMgr");
108 }
109
110 //! Enable or disable changes in reactor composition due to chemical reactions.
111 virtual void setChemistry(bool cflag = true) {
112 throw NotImplementedError("ReactorBase::setChemistry");
113 }
114
115 //! Set the energy equation on or off.
116 virtual void setEnergy(int eflag = 1) {
117 throw NotImplementedError("ReactorBase::setEnergy");
118 }
119
120 //! Connect an inlet FlowDevice to this reactor
122
123 //! Connect an outlet FlowDevice to this reactor
125
126 //! Return a reference to the *n*-th inlet FlowDevice connected to this
127 //! reactor.
128 FlowDevice& inlet(size_t n = 0);
129
130 //! Return a reference to the *n*-th outlet FlowDevice connected to this
131 //! reactor.
132 FlowDevice& outlet(size_t n = 0);
133
134 //! Return the number of inlet FlowDevice objects connected to this reactor.
135 size_t nInlets() {
136 return m_inlet.size();
137 }
138
139 //! Return the number of outlet FlowDevice objects connected to this
140 //! reactor.
141 size_t nOutlets() {
142 return m_outlet.size();
143 }
144
145 //! Return the number of Wall objects connected to this reactor.
146 size_t nWalls() {
147 return m_wall.size();
148 }
149
150 //! Insert a Wall between this reactor and another reactor.
151 /*!
152 * `lr` = 0 if this reactor is to the left of the wall and `lr` = 1 if
153 * this reactor is to the right of the wall. This method is called
154 * automatically for both the left and right reactors by WallBase::install.
155 */
156 void addWall(WallBase& w, int lr);
157
158 //! Return a reference to the *n*-th Wall connected to this reactor.
159 WallBase& wall(size_t n);
160
161 virtual void addSurface(ReactorSurface* surf);
162
163 //! Return a reference to the *n*-th ReactorSurface connected to this
164 //! reactor
165 ReactorSurface* surface(size_t n);
166
167 //! Return the number of surfaces in a reactor
168 virtual size_t nSurfs() {
169 return m_surfaces.size();
170 }
171
172 /**
173 * Initialize the reactor. Called automatically by ReactorNet::initialize.
174 */
175 virtual void initialize(double t0 = 0.0) {
176 throw NotImplementedError("ReactorBase::initialize");
177 }
178
179 //! @}
180
181 //! Set the state of the Phase object associated with this reactor to the
182 //! reactor's current state.
183 void restoreState();
184
185 //! Set the state of the reactor to correspond to the state of the
186 //! associated ThermoPhase object. This is the inverse of restoreState().
187 //! Calling this will trigger integrator reinitialization.
188 virtual void syncState();
189
190 //! return a reference to the contents.
192 if (!m_thermo) {
193 throw CanteraError("ReactorBase::contents",
194 "Reactor contents not defined.");
195 }
196 return *m_thermo;
197 }
198
199 const ThermoPhase& contents() const {
200 if (!m_thermo) {
201 throw CanteraError("ReactorBase::contents",
202 "Reactor contents not defined.");
203 }
204 return *m_thermo;
205 }
206
207 //! Return the residence time (s) of the contents of this reactor, based
208 //! on the outlet mass flow rates and the mass of the reactor contents.
209 double residenceTime();
210
211 //! @name Solution components
212 //!
213 //! The values returned are those after the last call to ReactorNet::advance
214 //! or ReactorNet::step.
215 //! @{
216
217 //! Returns the current volume (m^3) of the reactor.
218 double volume() const {
219 return m_vol;
220 }
221
222 //! Returns the current density (kg/m^3) of the reactor's contents.
223 double density() const {
224 if (m_state.empty()) {
225 throw CanteraError("ReactorBase::density",
226 "Reactor state empty and/or contents not defined.");
227 }
228 return m_state[1];
229 }
230
231 //! Returns the current temperature (K) of the reactor's contents.
232 double temperature() const {
233 if (m_state.empty()) {
234 throw CanteraError("ReactorBase::temperature",
235 "Reactor state empty and/or contents not defined.");
236 }
237 return m_state[0];
238 }
239
240 //! Returns the current enthalpy (J/kg) of the reactor's contents.
241 double enthalpy_mass() const {
242 return m_enthalpy;
243 }
244
245 //! Returns the current internal energy (J/kg) of the reactor's contents.
246 double intEnergy_mass() const {
247 return m_intEnergy;
248 }
249
250 //! Returns the current pressure (Pa) of the reactor.
251 double pressure() const {
252 return m_pressure;
253 }
254
255 //! Returns the mass (kg) of the reactor's contents.
256 double mass() const {
257 return m_vol * density();
258 }
259
260 //! Return the vector of species mass fractions.
261 const double* massFractions() const {
262 if (m_state.empty()) {
263 throw CanteraError("ReactorBase::massFractions",
264 "Reactor state empty and/or contents not defined.");
265 }
266 return m_state.data() + 2;
267 }
268
269 //! Return the mass fraction of the *k*-th species.
270 double massFraction(size_t k) const {
271 if (m_state.empty()) {
272 throw CanteraError("ReactorBase::massFraction",
273 "Reactor state empty and/or contents not defined.");
274 }
275 return m_state[k+2];
276 }
277
278 //! @}
279
280 //! The ReactorNet that this reactor belongs to.
282
283 //! Set the ReactorNet that this reactor belongs to.
284 void setNetwork(ReactorNet* net);
285
286protected:
287 //! Number of homogeneous species in the mixture
288 size_t m_nsp = 0;
289
290 ThermoPhase* m_thermo = nullptr;
291 double m_vol = 1.0; //!< Current volume of the reactor [m^3]
292 double m_enthalpy = 0.0; //!< Current specific enthalpy of the reactor [J/kg]
293 double m_intEnergy = 0.0; //!< Current internal energy of the reactor [J/kg]
294 double m_pressure = 0.0; //!< Current pressure in the reactor [Pa]
295 vector<double> m_state;
296 vector<FlowDevice*> m_inlet, m_outlet;
297
298 vector<WallBase*> m_wall;
299 vector<ReactorSurface*> m_surfaces;
300
301 //! Vector of length nWalls(), indicating whether this reactor is on the left (0)
302 //! or right (1) of each wall.
303 vector<int> m_lr;
304 string m_name;
305
306 //! The ReactorNet that this reactor is part of
307 ReactorNet* m_net = nullptr;
308
309 //! Composite thermo/kinetics/transport handler
310 shared_ptr<Solution> m_solution;
311};
312}
313
314#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:51
virtual void setKineticsMgr(Kinetics &kin)
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.
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:88
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:65
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.
void setName(const string &name)
Set the name of this reactor.
Definition ReactorBase.h:75
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.
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.
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.
virtual 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:70
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:564
size_t global
global parameter index
Definition ReactorBase.h:39
SensParameterType type
type of sensitivity parameter
Definition ReactorBase.h:41
size_t local
local parameter index
Definition ReactorBase.h:38
double value
nominal value of the parameter
Definition ReactorBase.h:40