Cantera 2.6.0

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
9#include "cantera/base/global.h"
10#include "cantera/base/ctexceptions.h"
11
12//! Namespace for classes implementing zero-dimensional reactor networks.
13 namespace Cantera
14{
15
16//! @defgroup ZeroD Zero-dimensional reactor networks
17//!
18//! See https://cantera.org/science/reactors.html for a description of the governing
19//! equations for specific reactor types and the methods used for solving networks of
20// interconnected reactors.
21
22 class FlowDevice;
23 class WallBase;
24 class ReactorNet;
25 class ReactorSurface;
26 class Kinetics;
27 class ThermoPhase;
28
29 enum class SensParameterType {
30 reaction,
31 enthalpy
32};
33
34 struct SensitivityParameter
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 ZeroD
47 */
48 class ReactorBase
49{
50 public:
51 explicit ReactorBase(const std::string& name = "(none)");
52 virtual ~ReactorBase() {}
53 ReactorBase(const ReactorBase&) = delete;
54 ReactorBase& operator=(const ReactorBase&) = delete;
55
56 //! String indicating the reactor model implemented. Usually
57 //! corresponds to the name of the derived class.
58 //! @deprecated To be removed after Cantera 2.6. Use type() instead.
59 virtual std::string typeStr() const {
60 warn_deprecated("ReactorBase::typeStr",
61 "To be removed after Cantera 2.6. Use type() instead.");
62 return "ReactorBase";
63 }
64
65 //! String indicating the reactor model implemented. Usually
66 //! corresponds to the name of the derived class.
67 virtual std::string type() const {
68 return "ReactorBase";
69 }
70
71 //! Return the name of this reactor
72 std::string name() const {
73 return m_name;
74 }
75
76 //! Set the name of this reactor
77 void setName(const std::string& name) {
78 m_name = name;
79 }
80
81 //! @name Methods to set up a simulation.
82 //! @{
83
84 //! Set the initial reactor volume. By default, the volume is 1.0 m^3.
85 void setInitialVolume(doublereal vol) {
86 m_vol = vol;
87 }
88
89 //! Specify the mixture contained in the reactor. Note that a pointer to
90 //! this substance is stored, and as the integration proceeds, the state of
91 //! the substance is modified.
92 virtual void setThermoMgr(ThermoPhase& thermo);
93
94 //! Specify chemical kinetics governing the reactor.
95 virtual void setKineticsMgr(Kinetics& kin) {
96 throw NotImplementedError("ReactorBase::setKineticsMgr");
97 }
98
99 //! Enable or disable changes in reactor composition due to chemical reactions.
100 virtual void setChemistry(bool cflag = true) {
101 throw NotImplementedError("ReactorBase::setChemistry");
102 }
103
104 //! Set the energy equation on or off.
105 virtual void setEnergy(int eflag = 1) {
106 throw NotImplementedError("ReactorBase::setEnergy");
107 }
108
109 //! Connect an inlet FlowDevice to this reactor
110 void addInlet(FlowDevice& inlet);
111
112 //! Connect an outlet FlowDevice to this reactor
113 void addOutlet(FlowDevice& outlet);
114
115 //! Return a reference to the *n*-th inlet FlowDevice connected to this
116 //! reactor.
117 FlowDevice& inlet(size_t n = 0);
118
119 //! Return a reference to the *n*-th outlet FlowDevice connected to this
120 //! reactor.
121 FlowDevice& outlet(size_t n = 0);
122
123 //! Return the number of inlet FlowDevice objects connected to this reactor.
124 size_t nInlets() {
125 return m_inlet.size();
126 }
127
128 //! Return the number of outlet FlowDevice objects connected to this
129 //! reactor.
130 size_t nOutlets() {
131 return m_outlet.size();
132 }
133
134 //! Return the number of Wall objects connected to this reactor.
135 size_t nWalls() {
136 return m_wall.size();
137 }
138
139 //! Insert a Wall between this reactor and another reactor.
140 /*!
141 * `lr` = 0 if this reactor is to the left of the wall and `lr` = 1 if
142 * this reactor is to the right of the wall. This method is called
143 * automatically for both the left and right reactors by WallBase::install.
144 */
145 void addWall(WallBase& w, int lr);
146
147 //! Return a reference to the *n*-th Wall connected to this reactor.
148 WallBase& wall(size_t n);
149
150 void addSurface(ReactorSurface* surf);
151
152 //! Return a reference to the *n*-th ReactorSurface connected to this
153 //! reactor
154 ReactorSurface* surface(size_t n);
155
156 /**
157 * Initialize the reactor. Called automatically by ReactorNet::initialize.
158 */
159 virtual void initialize(doublereal t0 = 0.0) {
160 throw NotImplementedError("ReactorBase::initialize");
161 }
162
163 //! @}
164
165 //! Set the state of the Phase object associated with this reactor to the
166 //! reactor's current state.
167 void restoreState();
168
169 //! Set the state of the reactor to correspond to the state of the
170 //! associated ThermoPhase object. This is the inverse of restoreState().
171 //! Calling this will trigger integrator reinitialization.
172 virtual void syncState();
173
174 //! return a reference to the contents.
175 ThermoPhase& contents() {
176 if (!m_thermo) {
177 throw CanteraError("ReactorBase::contents",
178 "Reactor contents not defined.");
179 }
180 return *m_thermo;
181 }
182
183 const ThermoPhase& contents() const {
184 if (!m_thermo) {
185 throw CanteraError("ReactorBase::contents",
186 "Reactor contents not defined.");
187 }
188 return *m_thermo;
189 }
190
191 //! Return the residence time (s) of the contents of this reactor, based
192 //! on the outlet mass flow rates and the mass of the reactor contents.
193 doublereal residenceTime();
194
195 /**
196 * @name Solution components.
197 * The values returned are those after the last call to ReactorNet::advance
198 * or ReactorNet::step.
199 */
200 //! @{
201
202 //! Returns the current volume (m^3) of the reactor.
203 doublereal volume() const {
204 return m_vol;
205 }
206
207 //! Returns the current density (kg/m^3) of the reactor's contents.
208 doublereal density() const {
209 return m_state[1];
210 }
211
212 //! Returns the current temperature (K) of the reactor's contents.
213 doublereal temperature() const {
214 return m_state[0];
215 }
216
217 //! Returns the current enthalpy (J/kg) of the reactor's contents.
218 doublereal enthalpy_mass() const {
219 return m_enthalpy;
220 }
221
222 //! Returns the current internal energy (J/kg) of the reactor's contents.
223 doublereal intEnergy_mass() const {
224 return m_intEnergy;
225 }
226
227 //! Returns the current pressure (Pa) of the reactor.
228 doublereal pressure() const {
229 return m_pressure;
230 }
231
232 //! Returns the mass (kg) of the reactor's contents.
233 doublereal mass() const {
234 return m_vol * density();
235 }
236
237 //! Return the vector of species mass fractions.
238 const doublereal* massFractions() const {
239 return m_state.data() + 2;
240 }
241
242 //! Return the mass fraction of the *k*-th species.
243 doublereal massFraction(size_t k) const {
244 return m_state[k+2];
245 }
246
247 //! @}
248
249 //! The ReactorNet that this reactor belongs to.
250 ReactorNet& network();
251
252 //! Set the ReactorNet that this reactor belongs to.
253 void setNetwork(ReactorNet* net);
254
255 protected:
256 //! Number of homogeneous species in the mixture
257 size_t m_nsp;
258
259 ThermoPhase* m_thermo;
260 double m_vol; //!< Current volume of the reactor [m^3]
261 double m_enthalpy; //!< Current specific enthalpy of the reactor [J/kg]
262 double m_intEnergy; //!< Current internal energy of the reactor [J/kg]
263 double m_pressure; //!< Current pressure in the reactor [Pa]
264 vector_fp m_state;
265 std::vector<FlowDevice*> m_inlet, m_outlet;
266
267 std::vector<WallBase*> m_wall;
268 std::vector<ReactorSurface*> m_surfaces;
269
270 //! Vector of length nWalls(), indicating whether this reactor is on the left (0)
271 //! or right (1) of each wall.
272 vector_int m_lr;
273 std::string m_name;
274
275 //! The ReactorNet that this reactor is part of
276 ReactorNet* m_net;
277};
278}
279
280#endif
Cantera::CanteraError
Base class for exceptions thrown by Cantera classes.
Definition: ctexceptions.h:61
Cantera::FlowDevice
Base class for 'flow devices' (valves, pressure regulators, etc.) connecting reactors.
Definition: FlowDevice.h:24
Cantera::Kinetics
Public interface for kinetics managers.
Definition: Kinetics.h:114
Cantera::NotImplementedError
An error indicating that an unimplemented function has been called.
Definition: ctexceptions.h:187
Cantera::ReactorBase
Base class for stirred reactors.
Definition: ReactorBase.h:49
Cantera::ReactorBase::setKineticsMgr
virtual void setKineticsMgr(Kinetics &kin)
Specify chemical kinetics governing the reactor.
Definition: ReactorBase.h:95
Cantera::ReactorBase::massFraction
doublereal massFraction(size_t k) const
Return the mass fraction of the k-th species.
Definition: ReactorBase.h:243
Cantera::ReactorBase::outlet
FlowDevice & outlet(size_t n=0)
Return a reference to the n-th outlet FlowDevice connected to this reactor.
Definition: ReactorBase.cpp:121
Cantera::ReactorBase::nWalls
size_t nWalls()
Return the number of Wall objects connected to this reactor.
Definition: ReactorBase.h:135
Cantera::ReactorBase::name
std::string name() const
Return the name of this reactor.
Definition: ReactorBase.h:72
Cantera::ReactorBase::wall
WallBase & wall(size_t n)
Return a reference to the n-th Wall connected to this reactor.
Definition: ReactorBase.cpp:68
Cantera::ReactorBase::addOutlet
void addOutlet(FlowDevice &outlet)
Connect an outlet FlowDevice to this reactor.
Definition: ReactorBase.cpp:53
Cantera::ReactorBase::pressure
doublereal pressure() const
Returns the current pressure (Pa) of the reactor.
Definition: ReactorBase.h:228
Cantera::ReactorBase::typeStr
virtual std::string typeStr() const
String indicating the reactor model implemented.
Definition: ReactorBase.h:59
Cantera::ReactorBase::initialize
virtual void initialize(doublereal t0=0.0)
Initialize the reactor.
Definition: ReactorBase.h:159
Cantera::ReactorBase::m_pressure
double m_pressure
Current pressure in the reactor [Pa].
Definition: ReactorBase.h:263
Cantera::ReactorBase::m_net
ReactorNet * m_net
The ReactorNet that this reactor is part of.
Definition: ReactorBase.h:276
Cantera::ReactorBase::addWall
void addWall(WallBase &w, int lr)
Insert a Wall between this reactor and another reactor.
Definition: ReactorBase.cpp:58
Cantera::ReactorBase::setNetwork
void setNetwork(ReactorNet *net)
Set the ReactorNet that this reactor belongs to.
Definition: ReactorBase.cpp:103
Cantera::ReactorBase::residenceTime
doublereal residenceTime()
Return the residence time (s) of the contents of this reactor, based on the outlet mass flow rates an...
Definition: ReactorBase.cpp:108
Cantera::ReactorBase::inlet
FlowDevice & inlet(size_t n=0)
Return a reference to the n-th inlet FlowDevice connected to this reactor.
Definition: ReactorBase.cpp:117
Cantera::ReactorBase::m_vol
double m_vol
Current volume of the reactor [m^3].
Definition: ReactorBase.h:260
Cantera::ReactorBase::setChemistry
virtual void setChemistry(bool cflag=true)
Enable or disable changes in reactor composition due to chemical reactions.
Definition: ReactorBase.h:100
Cantera::ReactorBase::addInlet
void addInlet(FlowDevice &inlet)
Connect an inlet FlowDevice to this reactor.
Definition: ReactorBase.cpp:48
Cantera::ReactorBase::syncState
virtual void syncState()
Set the state of the reactor to correspond to the state of the associated ThermoPhase object.
Definition: ReactorBase.cpp:37
Cantera::ReactorBase::setName
void setName(const std::string &name)
Set the name of this reactor.
Definition: ReactorBase.h:77
Cantera::ReactorBase::m_intEnergy
double m_intEnergy
Current internal energy of the reactor [J/kg].
Definition: ReactorBase.h:262
Cantera::ReactorBase::type
virtual std::string type() const
String indicating the reactor model implemented.
Definition: ReactorBase.h:67
Cantera::ReactorBase::setInitialVolume
void setInitialVolume(doublereal vol)
Set the initial reactor volume. By default, the volume is 1.0 m^3.
Definition: ReactorBase.h:85
Cantera::ReactorBase::setEnergy
virtual void setEnergy(int eflag=1)
Set the energy equation on or off.
Definition: ReactorBase.h:105
Cantera::ReactorBase::m_nsp
size_t m_nsp
Number of homogeneous species in the mixture.
Definition: ReactorBase.h:257
Cantera::ReactorBase::m_lr
vector_int m_lr
Vector of length nWalls(), indicating whether this reactor is on the left (0) or right (1) of each wa...
Definition: ReactorBase.h:272
Cantera::ReactorBase::volume
doublereal volume() const
Returns the current volume (m^3) of the reactor.
Definition: ReactorBase.h:203
Cantera::ReactorBase::setThermoMgr
virtual void setThermoMgr(ThermoPhase &thermo)
Specify the mixture contained in the reactor.
Definition: ReactorBase.cpp:27
Cantera::ReactorBase::restoreState
void restoreState()
Set the state of the Phase object associated with this reactor to the reactor's current state.
Definition: ReactorBase.cpp:86
Cantera::ReactorBase::density
doublereal density() const
Returns the current density (kg/m^3) of the reactor's contents.
Definition: ReactorBase.h:208
Cantera::ReactorBase::network
ReactorNet & network()
The ReactorNet that this reactor belongs to.
Definition: ReactorBase.cpp:93
Cantera::ReactorBase::intEnergy_mass
doublereal intEnergy_mass() const
Returns the current internal energy (J/kg) of the reactor's contents.
Definition: ReactorBase.h:223
Cantera::ReactorBase::nOutlets
size_t nOutlets()
Return the number of outlet FlowDevice objects connected to this reactor.
Definition: ReactorBase.h:130
Cantera::ReactorBase::temperature
doublereal temperature() const
Returns the current temperature (K) of the reactor's contents.
Definition: ReactorBase.h:213
Cantera::ReactorBase::nInlets
size_t nInlets()
Return the number of inlet FlowDevice objects connected to this reactor.
Definition: ReactorBase.h:124
Cantera::ReactorBase::enthalpy_mass
doublereal enthalpy_mass() const
Returns the current enthalpy (J/kg) of the reactor's contents.
Definition: ReactorBase.h:218
Cantera::ReactorBase::surface
ReactorSurface * surface(size_t n)
Return a reference to the n-th ReactorSurface connected to this reactor.
Definition: ReactorBase.cpp:81
Cantera::ReactorBase::massFractions
const doublereal * massFractions() const
Return the vector of species mass fractions.
Definition: ReactorBase.h:238
Cantera::ReactorBase::m_enthalpy
double m_enthalpy
Current specific enthalpy of the reactor [J/kg].
Definition: ReactorBase.h:261
Cantera::ReactorBase::contents
ThermoPhase & contents()
return a reference to the contents.
Definition: ReactorBase.h:175
Cantera::ReactorBase::mass
doublereal mass() const
Returns the mass (kg) of the reactor's contents.
Definition: ReactorBase.h:233
Cantera::ReactorNet
A class representing a network of connected reactors.
Definition: ReactorNet.h:27
Cantera::ReactorSurface
A surface where reactions can occur that is in contact with the bulk fluid of a Reactor.
Definition: ReactorSurface.h:21
Cantera::ThermoPhase
Base class for a phase with thermodynamic properties.
Definition: ThermoPhase.h:102
Cantera::WallBase
Base class for 'walls' (walls, pistons, etc.) connecting reactors.
Definition: Wall.h:25
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,...
Cantera
Namespace for the Cantera kernel.
Definition: AnyMap.cpp:557
Cantera::warn_deprecated
void warn_deprecated(const std::string &source, const AnyBase &node, const std::string &message)
A deprecation warning for syntax in an input file.
Definition: AnyMap.cpp:1901
Cantera::vector_int
std::vector< int > vector_int
Vector of ints.
Definition: ct_defs.h:186
Cantera::vector_fp
std::vector< double > vector_fp
Turn on the use of stl vectors for the basic array type within cantera Vector of doubles.
Definition: ct_defs.h:184