Cantera  3.2.0a5
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 shared_ptr<Solution> phase() { return m_solution; }
104
105 //! Access the Solution object used to represent the contents of this reactor.
106 //! @since New in %Cantera 3.2
107 shared_ptr<const Solution> phase() const { return m_solution; }
108
109 //! @name Methods to set up a simulation
110 //! @{
111
112 //! Set the initial reactor volume.
113 virtual void setInitialVolume(double vol) {
114 throw NotImplementedError("ReactorBase::setInitialVolume",
115 "Volume is undefined for reactors of type '{}'.", type());
116 }
117
118 //! Returns an area associated with a reactor [m²].
119 //! Examples: surface area of ReactorSurface or cross section area of FlowReactor.
120 virtual double area() const {
121 throw NotImplementedError("ReactorBase::area",
122 "Area is undefined for reactors of type '{}'.", type());
123 }
124
125 //! Set an area associated with a reactor [m²].
126 //! Examples: surface area of ReactorSurface or cross section area of FlowReactor.
127 virtual void setArea(double a) {
128 throw NotImplementedError("ReactorBase::setArea",
129 "Area is undefined for reactors of type '{}'.", type());
130 }
131
132 //! Returns `true` if changes in the reactor composition due to chemical reactions
133 //! are enabled.
134 //! @since New in %Cantera 3.2.
135 virtual bool chemistryEnabled() const {
136 throw NotImplementedError("ReactorBase::chemistryEnabled",
137 "Not implemented for reactor type '{}'.", type());
138 }
139
140 //! Enable or disable changes in reactor composition due to chemical reactions.
141 //! @deprecated To be removed after %Cantera 3.2. Renamed to setChemistryEnabled().
142 void setChemistry(bool cflag = true) {
143 warn_deprecated("ReactorBase::setChemistry",
144 "To be removed after Cantera 3.2. Renamed to setChemistryEnabled.");
145 setChemistryEnabled(cflag);
146 }
147
148 //! Enable or disable changes in reactor composition due to chemical reactions.
149 //! @since New in %Cantera 3.2.
150 virtual void setChemistryEnabled(bool cflag = true) {
151 throw NotImplementedError("ReactorBase::setChemistryEnabled",
152 "Not implemented for reactor type '{}'.", type());
153 }
154
155 //! Returns `true` if solution of the energy equation is enabled.
156 //! @since New in %Cantera 3.2.
157 virtual bool energyEnabled() const {
158 throw NotImplementedError("ReactorBase::energyEnabled",
159 "Not implemented for reactor type '{}'.", type());
160 }
161
162 //! Set the energy equation on or off.
163 //! @deprecated To be removed after %Cantera 3.2. Renamed to setEnergyEnabled().
164 void setEnergy(int eflag = 1) {
165 warn_deprecated("ReactorBase::setEnergy",
166 "To be removed after Cantera 3.2. Renamed to setEnergyEnabled.");
167 setEnergyEnabled(eflag > 0);
168 }
169
170 //! Set the energy equation on or off.
171 //! @since New in %Cantera 3.2.
172 virtual void setEnergyEnabled(bool eflag = true) {
173 throw NotImplementedError("ReactorBase::setEnergyEnabled",
174 "Not implemented for reactor type '{}'.", type());
175 }
176
177 //! Connect an inlet FlowDevice to this reactor
178 virtual void addInlet(FlowDevice& inlet);
179
180 //! Connect an outlet FlowDevice to this reactor
181 virtual void addOutlet(FlowDevice& outlet);
182
183 //! Return a reference to the *n*-th inlet FlowDevice connected to this reactor.
184 FlowDevice& inlet(size_t n = 0);
185
186 //! Return a reference to the *n*-th outlet FlowDevice connected to this reactor.
187 FlowDevice& outlet(size_t n = 0);
188
189 //! Return the number of inlet FlowDevice objects connected to this reactor.
190 size_t nInlets() {
191 return m_inlet.size();
192 }
193
194 //! Return the number of outlet FlowDevice objects connected to this reactor.
195 size_t nOutlets() {
196 return m_outlet.size();
197 }
198
199 //! Return the number of Wall objects connected to this reactor.
200 size_t nWalls() {
201 return m_wall.size();
202 }
203
204 //! Insert a Wall between this reactor and another reactor.
205 /*!
206 * `lr` = 0 if this reactor is to the left of the wall and `lr` = 1 if
207 * this reactor is to the right of the wall. This method is called
208 * automatically for both the left and right reactors by WallBase::install.
209 */
210 virtual void addWall(WallBase& w, int lr);
211
212 //! Return a reference to the *n*-th Wall connected to this reactor.
213 WallBase& wall(size_t n);
214
215 //! Add a ReactorSurface object to a Reactor object.
216 //! @attention This method should generally not be called directly by users.
217 //! Reactor and ReactorSurface objects should be connected by providing adjacent
218 //! reactors to the newReactorSurface factory function.
219 virtual void addSurface(ReactorSurface* surf);
220
221 //! Add a ReactorSurface object to a Reactor object.
222 //! @attention This method should generally not be called directly by users.
223 //! Reactor and ReactorSurface objects should be connected by providing adjacent
224 //! reactors to the newReactorSurface factory function.
225 //! @deprecated Unused. To be removed after %Cantera 3.2.
226 void addSurface(shared_ptr<ReactorBase> surf);
227
228 //! Return a reference to the *n*-th ReactorSurface connected to this reactor.
229 ReactorSurface* surface(size_t n);
230
231 //! Return the number of surfaces in a reactor
232 virtual size_t nSurfs() const {
233 return m_surfaces.size();
234 }
235
236 /**
237 * Initialize the reactor. Called automatically by ReactorNet::initialize.
238 */
239 virtual void initialize(double t0 = 0.0) {
240 throw NotImplementedError("ReactorBase::initialize");
241 }
242
243 //! @}
244
245 //! Set the state of the Phase object associated with this reactor to the
246 //! reactor's current state.
247 virtual void restoreState();
248
249 //! Set the state of the reactor to the associated ThermoPhase object.
250 //! This method is the inverse of restoreState() and will trigger integrator
251 //! reinitialization.
252 virtual void syncState();
253
254 //! return a reference to the contents.
255 //! @deprecated To be removed after Cantera 3.2. Replaceable by
256 //! ReactorBase->phase()->thermo().
258 warn_deprecated("ReactorBase::contents", "To be removed after Cantera 3.2. "
259 "Replaceable by ReactorBase->phase()->thermo().");
260 if (!m_thermo) {
261 throw CanteraError("ReactorBase::contents",
262 "Reactor contents not defined.");
263 }
264 return *m_thermo;
265 }
266
267 //! return a reference to the contents.
268 //! @deprecated To be removed after Cantera 3.2. Replaceable by
269 //! ReactorBase->phase()->thermo().
270 const ThermoPhase& contents() const {
271 warn_deprecated("ReactorBase::contents", "To be removed after Cantera 3.2. "
272 "Replaceable by ReactorBase->phase()->thermo().");
273 if (!m_thermo) {
274 throw CanteraError("ReactorBase::contents",
275 "Reactor contents not defined.");
276 }
277 return *m_thermo;
278 }
279
280 //! Return the residence time (s) of the contents of this reactor, based
281 //! on the outlet mass flow rates and the mass of the reactor contents.
282 double residenceTime();
283
284 //! @name Solution components
285 //!
286 //! The values returned are those after the last call to ReactorNet::advance
287 //! or ReactorNet::step.
288 //! @{
289
290 //! Returns the current volume (m^3) of the reactor.
291 double volume() const {
292 return m_vol;
293 }
294
295 //! Returns the current density (kg/m^3) of the reactor's contents.
296 double density() const {
297 if (m_state.empty()) {
298 throw CanteraError("ReactorBase::density",
299 "Reactor state empty and/or contents not defined.");
300 }
301 return m_state[1];
302 }
303
304 //! Returns the current temperature (K) of the reactor's contents.
305 double temperature() const {
306 if (m_state.empty()) {
307 throw CanteraError("ReactorBase::temperature",
308 "Reactor state empty and/or contents not defined.");
309 }
310 return m_state[0];
311 }
312
313 //! Returns the current enthalpy (J/kg) of the reactor's contents.
314 double enthalpy_mass() const {
315 return m_enthalpy;
316 }
317
318 //! Returns the current internal energy (J/kg) of the reactor's contents.
319 //! @deprecated To be removed after %Cantera 3.2.
320 double intEnergy_mass() const {
321 warn_deprecated("ReactorBase::intEnergy_mass",
322 "To be removed after Cantera 3.2.");
323 return m_intEnergy;
324 }
325
326 //! Returns the current pressure (Pa) of the reactor.
327 double pressure() const {
328 return m_pressure;
329 }
330
331 //! Returns the mass (kg) of the reactor's contents.
332 double mass() const {
333 return m_mass;
334 }
335
336 //! Return the vector of species mass fractions.
337 const double* massFractions() const {
338 if (m_state.empty()) {
339 throw CanteraError("ReactorBase::massFractions",
340 "Reactor state empty and/or contents not defined.");
341 }
342 return m_state.data() + 2;
343 }
344
345 //! Return the mass fraction of the *k*-th species.
346 double massFraction(size_t k) const {
347 if (m_state.empty()) {
348 throw CanteraError("ReactorBase::massFraction",
349 "Reactor state empty and/or contents not defined.");
350 }
351 return m_state[k+2];
352 }
353
354 //! @}
355
356 //! The ReactorNet that this reactor belongs to.
358
359 //! Set the ReactorNet that this reactor belongs to.
360 void setNetwork(ReactorNet* net);
361
362 //! Add a sensitivity parameter associated with the reaction number *rxn*
363 virtual void addSensitivityReaction(size_t rxn) {
364 throw NotImplementedError("ReactorBase::addSensitivityReaction");
365 }
366
367 //! Number of sensitivity parameters associated with this reactor.
368 virtual size_t nSensParams() const {
369 return m_sensParams.size();
370 }
371
372protected:
373 //! Specify the mixture contained in the reactor. Note that a pointer to
374 //! this substance is stored, and as the integration proceeds, the state of
375 //! the substance is modified.
376 //! @since New in %Cantera 3.1.
377 //! @deprecated To be removed after %Cantera 3.2. Superseded by instantiation of
378 //! ReactorBase with Solution object.
379 virtual void setThermo(ThermoPhase& thermo);
380
381 //! Specify the kinetics manager for the reactor. Called by setSolution().
382 //! @since New in %Cantera 3.1.
383 //! @deprecated To be removed after %Cantera 3.2. Superseded by instantiation of
384 //! ReactorBase with Solution object.
385 virtual void setKinetics(Kinetics& kin) {
386 throw NotImplementedError("ReactorBase::setKinetics");
387 }
388
389 //! Number of homogeneous species in the mixture
390 size_t m_nsp = 0;
391
392 ThermoPhase* m_thermo = nullptr;
393 double m_vol = 0.0; //!< Current volume of the reactor [m^3]
394 double m_mass = 0.0; //!< Current mass of the reactor [kg]
395 double m_enthalpy = 0.0; //!< Current specific enthalpy of the reactor [J/kg]
396
397 //! Current internal energy of the reactor [J/kg]
398 //! @deprecated To be removed after %Cantera 3.2
399 double m_intEnergy = 0.0;
400 double m_pressure = 0.0; //!< Current pressure in the reactor [Pa]
401 vector<double> m_state;
402 vector<FlowDevice*> m_inlet, m_outlet;
403
404 vector<WallBase*> m_wall;
405 vector<ReactorSurface*> m_surfaces;
406
407 //! Vector of length nWalls(), indicating whether this reactor is on the left (0)
408 //! or right (1) of each wall.
409 vector<int> m_lr;
410 string m_name; //!< Reactor name.
411 bool m_defaultNameSet = false; //!< `true` if default name has been previously set.
412
413 //! The ReactorNet that this reactor is part of
414 ReactorNet* m_net = nullptr;
415
416 //! Composite thermo/kinetics/transport handler
417 shared_ptr<Solution> m_solution;
418
419 // Data associated each sensitivity parameter
420 vector<SensitivityParameter> m_sensParams;
421};
422}
423
424#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< 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.
virtual void setArea(double a)
Set an area associated with a reactor [m²].
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
virtual double area() const
Returns an area associated with a reactor [m²].
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.
virtual bool chemistryEnabled() const
Returns true if changes in the reactor composition due to chemical reactions are enabled.
void setEnergy(int eflag=1)
Set the energy equation on or off.
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 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 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 setEnergyEnabled(bool eflag=true)
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 setChemistryEnabled(bool cflag=true)
Enable or disable changes in reactor composition due to chemical reactions.
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].
virtual bool energyEnabled() const
Returns true if solution of the energy equation is enabled.
ThermoPhase & contents()
return a reference to the contents.
void setChemistry(bool cflag=true)
Enable or disable changes in reactor composition due to chemical reactions.
shared_ptr< Solution > phase()
Access the Solution object used to represent the contents of this reactor.
shared_ptr< const Solution > phase() const
Access the Solution object used to represent the contents of this reactor.
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