Cantera  3.2.0a4
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 reactor objects. Allows using any substance model, with arbitrary
44 * inflow, outflow, heat loss/gain, surface chemistry, and volume change, whenever
45 * defined.
46 * @ingroup reactorGroup
47 */
49{
50public:
51 //! @deprecated After %Cantera 3.2, this constructor will become protected
52 explicit ReactorBase(const string& name="(none)");
53
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
60 //! Instantiate a ReactorBase object with Solution contents.
61 //! @param sol Solution object representing the contents of this reactor
62 //! @param clone Determines whether to clone `sol` so that the internal state of
63 //! this reactor is independent of the original Solution object and any Solution
64 //! objects used by other reactors in the network.
65 //! @param name Name of the reactor.
66 //! @since Added the `clone` argument in %Cantera 3.2. If not specified, the default
67 //! behavior in %Cantera 3.2 is not to clone the Solution object. This will
68 //! change after %Cantera 3.2 to default to `true`.
69 ReactorBase(shared_ptr<Solution> sol, bool clone, const string& name="(none)");
70
71 virtual ~ReactorBase();
72 ReactorBase(const ReactorBase&) = delete;
73 ReactorBase& operator=(const ReactorBase&) = delete;
74
75 //! String indicating the reactor model implemented. Usually
76 //! corresponds to the name of the derived class.
77 virtual string type() const {
78 return "ReactorBase";
79 }
80
81 //! Return the name of this reactor
82 string name() const {
83 return m_name;
84 }
85
86 //! Set the name of this reactor
87 void setName(const string& name) {
88 m_name = name;
89 }
90
91 //! Set the default name of a reactor. Returns `false` if it was previously set.
92 bool setDefaultName(map<string, int>& counts);
93
94 //! Set the Solution specifying the ReactorBase content.
95 //! @param sol Solution object to be set.
96 //! @since New in %Cantera 3.1.
97 //! @deprecated To be removed after %Cantera 3.2. Superseded by instantiation of
98 //! ReactorBase with Solution object.
99 void setSolution(shared_ptr<Solution> sol);
100
101 //! Access the Solution object used to represent the contents of this reactor.
102 //! @since New in %Cantera 3.2
103 //! @todo Transition to `contents()` method for returning `shared_ptr<Solution>`
104 //! after %Cantera 3.2.
105 shared_ptr<Solution> contents4() { return m_solution; }
106
107 //! Access the Solution object used to represent the contents of this reactor.
108 //! @since New in %Cantera 3.2
109 //! @todo Transition to `contents()` method for returning `shared_ptr<Solution>`
110 //! after %Cantera 3.2.
111 shared_ptr<const Solution> contents4() const { return m_solution; }
112
113 //! @name Methods to set up a simulation
114 //! @{
115
116 //! Set the initial reactor volume.
117 virtual void setInitialVolume(double vol) {
118 throw NotImplementedError("ReactorBase::setInitialVolume",
119 "Volume is undefined for reactors of type '{}'.", type());
120 }
121
122 //! Enable or disable changes in reactor composition due to chemical reactions.
123 virtual void setChemistry(bool cflag = true) {
124 throw NotImplementedError("ReactorBase::setChemistry");
125 }
126
127 //! Set the energy equation on or off.
128 virtual void setEnergy(int eflag = 1) {
129 throw NotImplementedError("ReactorBase::setEnergy");
130 }
131
132 //! Connect an inlet FlowDevice to this reactor
133 virtual void addInlet(FlowDevice& inlet);
134
135 //! Connect an outlet FlowDevice to this reactor
136 virtual void addOutlet(FlowDevice& outlet);
137
138 //! Return a reference to the *n*-th inlet FlowDevice connected to this reactor.
139 FlowDevice& inlet(size_t n = 0);
140
141 //! Return a reference to the *n*-th outlet FlowDevice connected to this reactor.
142 FlowDevice& outlet(size_t n = 0);
143
144 //! Return the number of inlet FlowDevice objects connected to this reactor.
145 size_t nInlets() {
146 return m_inlet.size();
147 }
148
149 //! Return the number of outlet FlowDevice objects connected to this reactor.
150 size_t nOutlets() {
151 return m_outlet.size();
152 }
153
154 //! Return the number of Wall objects connected to this reactor.
155 size_t nWalls() {
156 return m_wall.size();
157 }
158
159 //! Insert a Wall between this reactor and another reactor.
160 /*!
161 * `lr` = 0 if this reactor is to the left of the wall and `lr` = 1 if
162 * this reactor is to the right of the wall. This method is called
163 * automatically for both the left and right reactors by WallBase::install.
164 */
165 virtual void addWall(WallBase& w, int lr);
166
167 //! Return a reference to the *n*-th Wall connected to this reactor.
168 WallBase& wall(size_t n);
169
170 //! Add a ReactorSurface object to a Reactor object.
171 //! @attention This method should generally not be called directly by users.
172 //! Reactor and ReactorSurface objects should be connected by providing adjacent
173 //! reactors to the newReactorSurface factory function.
174 virtual void addSurface(ReactorSurface* surf);
175
176 //! Add a ReactorSurface object to a Reactor object.
177 //! @attention This method should generally not be called directly by users.
178 //! Reactor and ReactorSurface objects should be connected by providing adjacent
179 //! reactors to the newReactorSurface factory function.
180 //! @deprecated Unused. To be removed after %Cantera 3.2.
181 void addSurface(shared_ptr<ReactorBase> surf);
182
183 //! Return a reference to the *n*-th ReactorSurface connected to this reactor.
184 ReactorSurface* surface(size_t n);
185
186 //! Return the number of surfaces in a reactor
187 virtual size_t nSurfs() const {
188 return m_surfaces.size();
189 }
190
191 /**
192 * Initialize the reactor. Called automatically by ReactorNet::initialize.
193 */
194 virtual void initialize(double t0 = 0.0) {
195 throw NotImplementedError("ReactorBase::initialize");
196 }
197
198 //! @}
199
200 //! Set the state of the Phase object associated with this reactor to the
201 //! reactor's current state.
202 virtual void restoreState();
203
204 //! Set the state of the reactor to the associated ThermoPhase object.
205 //! This method is the inverse of restoreState() and will trigger integrator
206 //! reinitialization.
207 virtual void syncState();
208
209 //! return a reference to the contents.
210 //! @deprecated To be changed after Cantera 3.2 to return a `shared_ptr<Solution>`.
211 //! For transitional access to the Solution object, use contents4().
213 warn_deprecated("ReactorBase::contents", "Return value will change to "
214 "shared_ptr<Solution> after Cantera 3.2. Use contents4() for transition.");
215 if (!m_thermo) {
216 throw CanteraError("ReactorBase::contents",
217 "Reactor contents not defined.");
218 }
219 return *m_thermo;
220 }
221
222 //! return a reference to the contents.
223 //! @deprecated To be changed after Cantera 3.2 to return a
224 //! `shared_ptr<const Solution>`. For transitional access to the Solution
225 //! object, use contents4().
226 const ThermoPhase& contents() const {
227 warn_deprecated("ReactorBase::contents", "Return value will change to "
228 "shared_ptr<const Solution> after Cantera 3.2. Use contents4() for "
229 "transition.");
230 if (!m_thermo) {
231 throw CanteraError("ReactorBase::contents",
232 "Reactor contents not defined.");
233 }
234 return *m_thermo;
235 }
236
237 //! Return the residence time (s) of the contents of this reactor, based
238 //! on the outlet mass flow rates and the mass of the reactor contents.
239 double residenceTime();
240
241 //! @name Solution components
242 //!
243 //! The values returned are those after the last call to ReactorNet::advance
244 //! or ReactorNet::step.
245 //! @{
246
247 //! Returns the current volume (m^3) of the reactor.
248 double volume() const {
249 return m_vol;
250 }
251
252 //! Returns the current density (kg/m^3) of the reactor's contents.
253 double density() const {
254 if (m_state.empty()) {
255 throw CanteraError("ReactorBase::density",
256 "Reactor state empty and/or contents not defined.");
257 }
258 return m_state[1];
259 }
260
261 //! Returns the current temperature (K) of the reactor's contents.
262 double temperature() const {
263 if (m_state.empty()) {
264 throw CanteraError("ReactorBase::temperature",
265 "Reactor state empty and/or contents not defined.");
266 }
267 return m_state[0];
268 }
269
270 //! Returns the current enthalpy (J/kg) of the reactor's contents.
271 double enthalpy_mass() const {
272 return m_enthalpy;
273 }
274
275 //! Returns the current internal energy (J/kg) of the reactor's contents.
276 //! @deprecated To be removed after %Cantera 3.2.
277 double intEnergy_mass() const {
278 warn_deprecated("ReactorBase::intEnergy_mass",
279 "To be removed after Cantera 3.2.");
280 return m_intEnergy;
281 }
282
283 //! Returns the current pressure (Pa) of the reactor.
284 double pressure() const {
285 return m_pressure;
286 }
287
288 //! Returns the mass (kg) of the reactor's contents.
289 double mass() const {
290 return m_mass;
291 }
292
293 //! Return the vector of species mass fractions.
294 const double* massFractions() const {
295 if (m_state.empty()) {
296 throw CanteraError("ReactorBase::massFractions",
297 "Reactor state empty and/or contents not defined.");
298 }
299 return m_state.data() + 2;
300 }
301
302 //! Return the mass fraction of the *k*-th species.
303 double massFraction(size_t k) const {
304 if (m_state.empty()) {
305 throw CanteraError("ReactorBase::massFraction",
306 "Reactor state empty and/or contents not defined.");
307 }
308 return m_state[k+2];
309 }
310
311 //! @}
312
313 //! The ReactorNet that this reactor belongs to.
315
316 //! Set the ReactorNet that this reactor belongs to.
317 void setNetwork(ReactorNet* net);
318
319 //! Add a sensitivity parameter associated with the reaction number *rxn*
320 virtual void addSensitivityReaction(size_t rxn) {
321 throw NotImplementedError("ReactorBase::addSensitivityReaction");
322 }
323
324 //! Number of sensitivity parameters associated with this reactor.
325 virtual size_t nSensParams() const {
326 return m_sensParams.size();
327 }
328
329protected:
330 //! Specify the mixture contained in the reactor. Note that a pointer to
331 //! this substance is stored, and as the integration proceeds, the state of
332 //! the substance is modified.
333 //! @since New in %Cantera 3.1.
334 //! @deprecated To be removed after %Cantera 3.2. Superseded by instantiation of
335 //! ReactorBase with Solution object.
336 virtual void setThermo(ThermoPhase& thermo);
337
338 //! Specify the kinetics manager for the reactor. Called by setSolution().
339 //! @since New in %Cantera 3.1.
340 //! @deprecated To be removed after %Cantera 3.2. Superseded by instantiation of
341 //! ReactorBase with Solution object.
342 virtual void setKinetics(Kinetics& kin) {
343 throw NotImplementedError("ReactorBase::setKinetics");
344 }
345
346 //! Number of homogeneous species in the mixture
347 size_t m_nsp = 0;
348
349 ThermoPhase* m_thermo = nullptr;
350 double m_vol = 0.0; //!< Current volume of the reactor [m^3]
351 double m_mass = 0.0; //!< Current mass of the reactor [kg]
352 double m_enthalpy = 0.0; //!< Current specific enthalpy of the reactor [J/kg]
353
354 //! Current internal energy of the reactor [J/kg]
355 //! @deprecated To be removed after %Cantera 3.2
356 double m_intEnergy = 0.0;
357 double m_pressure = 0.0; //!< Current pressure in the reactor [Pa]
358 vector<double> m_state;
359 vector<FlowDevice*> m_inlet, m_outlet;
360
361 vector<WallBase*> m_wall;
362 vector<ReactorSurface*> m_surfaces;
363
364 //! Vector of length nWalls(), indicating whether this reactor is on the left (0)
365 //! or right (1) of each wall.
366 vector<int> m_lr;
367 string m_name; //!< Reactor name.
368 bool m_defaultNameSet = false; //!< `true` if default name has been previously set.
369
370 //! The ReactorNet that this reactor is part of
371 ReactorNet* m_net = nullptr;
372
373 //! Composite thermo/kinetics/transport handler
374 shared_ptr<Solution> m_solution;
375
376 // Data associated each sensitivity parameter
377 vector<SensitivityParameter> m_sensParams;
378};
379}
380
381#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:126
An error indicating that an unimplemented function has been called.
Base class for reactor objects.
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< const Solution > contents4() const
Access the Solution object used to represent the contents of this reactor.
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.
double pressure() const
Returns the current pressure (Pa) of the reactor.
virtual 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:77
ReactorNet * m_net
The ReactorNet that this reactor is part of.
const ThermoPhase & contents() const
return a reference to the contents.
virtual 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.
virtual void addSensitivityReaction(size_t rxn)
Add a sensitivity parameter associated with the reaction number rxn
void setName(const string &name)
Set the name of this reactor.
Definition ReactorBase.h:87
virtual void setKinetics(Kinetics &kin)
Specify the kinetics manager for the reactor.
virtual size_t nSurfs() const
Return the number of surfaces in a 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 size_t nSensParams() const
Number of sensitivity parameters associated with this reactor.
virtual void setChemistry(bool cflag=true)
Enable or disable changes in reactor composition due to chemical reactions.
virtual void addInlet(FlowDevice &inlet)
Connect an inlet FlowDevice to this reactor.
shared_ptr< Solution > contents4()
Access the Solution object used to represent the contents of 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 the associated ThermoPhase object.
double m_intEnergy
Current internal energy of the reactor [J/kg].
double m_mass
Current mass of the reactor [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.
virtual void setInitialVolume(double vol)
Set the initial reactor volume.
double volume() const
Returns the current volume (m^3) of the reactor.
virtual void restoreState()
Set the state of the Phase object associated with this reactor to the reactor's current state.
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:82
double enthalpy_mass() const
Returns the current enthalpy (J/kg) of the reactor's contents.
virtual void addSurface(ReactorSurface *surf)
Add a ReactorSurface object to a Reactor object.
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
void warn_deprecated(const string &source, const AnyBase &node, const string &message)
A deprecation warning for syntax in an input file.
Definition AnyMap.cpp:1997
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