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