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