Cantera 2.6.0
Reactor.h
Go to the documentation of this file.
1//! @file Reactor.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_REACTOR_H
7#define CT_REACTOR_H
8
9#include "ReactorBase.h"
10
11namespace Cantera
12{
13
14class Solution;
15
16/**
17 * Class Reactor is a general-purpose class for stirred reactors. The reactor
18 * may have an arbitrary number of inlets and outlets, each of which may be
19 * connected to a "flow device" such as a mass flow controller, a pressure
20 * regulator, etc. Additional reactors may be connected to the other end of
21 * the flow device, allowing construction of arbitrary reactor networks.
22 *
23 * The reactor class integrates the same governing equations no matter what
24 * type of reactor is simulated. The differences among reactor types are
25 * completely specified by the attached flow devices and the time-dependent
26 * user-specified boundary conditions.
27 *
28 * If an instance of class Reactor is used directly, it will simulate an
29 * adiabatic, constant volume reactor with gas-phase chemistry but no surface
30 * chemistry. Other reactor types may be simulated by deriving a class from
31 * Reactor. This method allows specifying the following in terms of the
32 * instantaneous reactor state:
33 *
34 * - rate of change of the total volume (m^3/s)
35 * - surface heat loss rate (W)
36 * - species surface production rates (kmol/s)
37 *
38 * @ingroup ZeroD
39 */
40class Reactor : public ReactorBase
41{
42public:
43 Reactor();
44
45 virtual std::string typeStr() const {
46 warn_deprecated("Reactor::typeStr",
47 "To be removed after Cantera 2.6. Use type() instead.");
48 return "Reactor";
49 }
50
51 virtual std::string type() const {
52 return "Reactor";
53 }
54
55 /**
56 * Insert something into the reactor. The 'something' must belong to a class
57 * that is a subclass of both ThermoPhase and Kinetics.
58 */
59 template<class G>
60 void insert(G& contents) {
63 }
64
65 void insert(shared_ptr<Solution> sol);
66
67 virtual void setKineticsMgr(Kinetics& kin);
68
69 void setChemistry(bool cflag=true) {
70 m_chem = cflag;
71 }
72
73 //! Returns `true` if changes in the reactor composition due to chemical reactions are enabled.
74 bool chemistryEnabled() const {
75 return m_chem;
76 }
77
78 void setEnergy(int eflag=1) {
79 if (eflag > 0) {
80 m_energy = true;
81 } else {
82 m_energy = false;
83 }
84 }
85
86 //! Returns `true` if solution of the energy equation is enabled.
87 bool energyEnabled() const {
88 return m_energy;
89 }
90
91 //! Number of equations (state variables) for this reactor
92 size_t neq() {
93 if (!m_nv) {
94 initialize();
95 }
96 return m_nv;
97 }
98
99 //! Get the the current state of the reactor.
100 /*!
101 * @param[out] y state vector representing the initial state of the reactor
102 */
103 virtual void getState(doublereal* y);
104
105 virtual void initialize(doublereal t0 = 0.0);
106
107 /*!
108 * Evaluate the reactor governing equations. Called by ReactorNet::eval.
109 * @param[in] t time.
110 * @param[in] y solution vector, length neq()
111 * @param[out] ydot rate of change of solution vector, length neq()
112 * @param[in] params sensitivity parameter vector, length ReactorNet::nparams()
113 * @deprecated Replaced by eval(double t, double* LHS, double* RHS). To be removed after
114 * Cantera 2.6.
115 */
116 virtual void evalEqs(double t, double* y, double* ydot, double* params) {
117 throw NotImplementedError("Reactor::evalEqs", "Deprecated");
118 }
119
120 //! Evaluate the reactor governing equations. Called by ReactorNet::eval.
121 //! @param[in] t time.
122 //! @param[out] LHS pointer to start of vector of left-hand side
123 //! coefficients for governing equations, length m_nv, default values 1
124 //! @param[out] RHS pointer to start of vector of right-hand side
125 //! coefficients for governing equations, length m_nv, default values 0
126 virtual void eval(double t, double* LHS, double* RHS);
127
128 virtual void syncState();
129
130 //! Set the state of the reactor to correspond to the state vector *y*.
131 virtual void updateState(doublereal* y);
132
133 //! Number of sensitivity parameters associated with this reactor
134 //! (including walls)
135 virtual size_t nSensParams();
136
137 //! Add a sensitivity parameter associated with the reaction number *rxn*
138 //! (in the homogeneous phase).
139 virtual void addSensitivityReaction(size_t rxn);
140
141 //! Add a sensitivity parameter associated with the enthalpy formation of
142 //! species *k* (in the homogeneous phase)
143 virtual void addSensitivitySpeciesEnthalpy(size_t k);
144
145 //! Return the index in the solution vector for this reactor of the
146 //! component named *nm*. Possible values for *nm* are "mass", "volume",
147 //! "int_energy", the name of a homogeneous phase species, or the name of a
148 //! surface species.
149 virtual size_t componentIndex(const std::string& nm) const;
150
151 //! Return the name of the solution component with index *i*.
152 //! @see componentIndex()
153 virtual std::string componentName(size_t k);
154
155 //! Set absolute step size limits during advance
156 //! @param limits array of step size limits with length neq
157 void setAdvanceLimits(const double* limits);
158
159 //! Check whether Reactor object uses advance limits
160 //! @returns True if at least one limit is set, False otherwise
162 return !m_advancelimits.empty();
163 }
164
165 //! Retrieve absolute step size limits during advance
166 //! @param[out] limits array of step size limits with length neq
167 //! @returns True if at least one limit is set, False otherwise
168 bool getAdvanceLimits(double* limits);
169
170 //! Set individual step size limit for component name *nm*
171 //! @param nm component name
172 //! @param limit value for step size limit
173 void setAdvanceLimit(const std::string& nm, const double limit);
174
175 //! Set reaction rate multipliers based on the sensitivity variables in
176 //! *params*.
177 virtual void applySensitivity(double* params);
178 //! Reset the reaction rate multipliers
179 virtual void resetSensitivity(double* params);
180
181protected:
182 //! Return the index in the solution vector for this reactor of the species
183 //! named *nm*, in either the homogeneous phase or a surface phase, relative
184 //! to the start of the species terms. Used to implement componentIndex for
185 //! specific reactor implementations.
186 virtual size_t speciesIndex(const std::string& nm) const;
187
188 //! Evaluate terms related to Walls. Calculates #m_vdot and #m_Q based on
189 //! wall movement and heat transfer.
190 //! @param t the current time
191 virtual void evalWalls(double t);
192
193 //! Evaluate terms related to surface reactions.
194 //! @param[out] LHS Multiplicative factor on the left hand side of ODE for surface
195 //! species coverages
196 //! @param[out] RHS Right hand side of ODE for surface species coverages
197 //! @param[out] sdot array of production rates of bulk phase species on surfaces
198 //! [kmol/s]
199 virtual void evalSurfaces(double* LHS, double* RHS, double* sdot);
200
201 //! Update the state of SurfPhase objects attached to this reactor
202 virtual void updateSurfaceState(double* y);
203
204 //! Update the state information needed by connected reactors and flow
205 //! devices. Called from updateState().
206 //! @param updatePressure Indicates whether to update #m_pressure. Should
207 //! `true` for reactors where the pressure is a dependent property,
208 //! calculated from the state, and `false` when the pressure is constant
209 //! or an independent variable.
210 virtual void updateConnected(bool updatePressure);
211
212 //! Get initial conditions for SurfPhase objects attached to this reactor
213 virtual void getSurfaceInitialConditions(double* y);
214
215 //! Pointer to the homogeneous Kinetics object that handles the reactions
217
218 doublereal m_vdot; //!< net rate of volume change from moving walls [m^3/s]
219
220 //! net heat transfer out of the reactor, through walls [W]
221 //! @deprecated To be removed after Cantera 2.6. Replaced with #m_Qdot, which
222 //! has the opposite sign convention.
223 double m_Q;
224
225 double m_Qdot; //!< net heat transfer into the reactor, through walls [W]
226
227 doublereal m_mass; //!< total mass
228 vector_fp m_work;
229
230 //! Production rates of gas phase species on surfaces [kmol/s]
232
233 vector_fp m_wdot; //!< Species net molar production rates
234 vector_fp m_uk; //!< Species molar internal energies
235 bool m_chem;
236 bool m_energy;
237 size_t m_nv;
238 size_t m_nv_surf; //!!< Number of variables associated with reactor surfaces
239
240 vector_fp m_advancelimits; //!< Advance step limit
241
242 // Data associated each sensitivity parameter
243 std::vector<SensitivityParameter> m_sensParams;
244};
245}
246
247#endif
Public interface for kinetics managers.
Definition: Kinetics.h:114
An error indicating that an unimplemented function has been called.
Definition: ctexceptions.h:187
Base class for stirred reactors.
Definition: ReactorBase.h:49
virtual void setThermoMgr(ThermoPhase &thermo)
Specify the mixture contained in the reactor.
Definition: ReactorBase.cpp:27
ThermoPhase & contents()
return a reference to the contents.
Definition: ReactorBase.h:175
Class Reactor is a general-purpose class for stirred reactors.
Definition: Reactor.h:41
virtual size_t componentIndex(const std::string &nm) const
Return the index in the solution vector for this reactor of the component named nm.
Definition: Reactor.cpp:362
bool chemistryEnabled() const
Returns true if changes in the reactor composition due to chemical reactions are enabled.
Definition: Reactor.h:74
virtual void updateState(doublereal *y)
Set the state of the reactor to correspond to the state vector y.
Definition: Reactor.cpp:127
virtual void evalSurfaces(double *LHS, double *RHS, double *sdot)
Evaluate terms related to surface reactions.
Definition: Reactor.cpp:279
virtual void updateSurfaceState(double *y)
Update the state of SurfPhase objects attached to this reactor.
Definition: Reactor.cpp:175
void insert(G &contents)
Insert something into the reactor.
Definition: Reactor.h:60
virtual void applySensitivity(double *params)
Set reaction rate multipliers based on the sensitivity variables in params.
Definition: Reactor.cpp:404
Kinetics * m_kin
Pointer to the homogeneous Kinetics object that handles the reactions.
Definition: Reactor.h:216
bool getAdvanceLimits(double *limits)
Retrieve absolute step size limits during advance.
Definition: Reactor.cpp:462
virtual void eval(double t, double *LHS, double *RHS)
Evaluate the reactor governing equations.
Definition: Reactor.cpp:203
virtual void evalWalls(double t)
Evaluate terms related to Walls.
Definition: Reactor.cpp:267
double m_Q
net heat transfer out of the reactor, through walls [W]
Definition: Reactor.h:223
virtual std::string typeStr() const
String indicating the reactor model implemented.
Definition: Reactor.h:45
bool energyEnabled() const
Returns true if solution of the energy equation is enabled.
Definition: Reactor.h:87
size_t neq()
Number of equations (state variables) for this reactor.
Definition: Reactor.h:92
virtual void addSensitivitySpeciesEnthalpy(size_t k)
Add a sensitivity parameter associated with the enthalpy formation of species k (in the homogeneous p...
Definition: Reactor.cpp:325
virtual void evalEqs(double t, double *y, double *ydot, double *params)
Definition: Reactor.h:116
double m_Qdot
net heat transfer into the reactor, through walls [W]
Definition: Reactor.h:225
virtual void getState(doublereal *y)
Get the the current state of the reactor.
Definition: Reactor.cpp:49
doublereal m_mass
total mass
Definition: Reactor.h:227
virtual void addSensitivityReaction(size_t rxn)
Add a sensitivity parameter associated with the reaction number rxn (in the homogeneous phase).
Definition: Reactor.cpp:312
void setEnergy(int eflag=1)
Set the energy equation on or off.
Definition: Reactor.h:78
virtual std::string componentName(size_t k)
Return the name of the solution component with index i.
Definition: Reactor.cpp:378
vector_fp m_sdot
Production rates of gas phase species on surfaces [kmol/s].
Definition: Reactor.h:231
virtual void setKineticsMgr(Kinetics &kin)
Specify chemical kinetics governing the reactor.
Definition: Reactor.cpp:39
void setAdvanceLimit(const std::string &nm, const double limit)
Set individual step size limit for component name nm
Definition: Reactor.cpp:473
virtual void syncState()
Set the state of the reactor to correspond to the state of the associated ThermoPhase object.
Definition: Reactor.cpp:121
bool hasAdvanceLimits()
Check whether Reactor object uses advance limits.
Definition: Reactor.h:161
void setAdvanceLimits(const double *limits)
Set absolute step size limits during advance.
Definition: Reactor.cpp:447
virtual std::string type() const
String indicating the reactor model implemented.
Definition: Reactor.h:51
virtual void resetSensitivity(double *params)
Reset the reaction rate multipliers.
Definition: Reactor.cpp:426
virtual void initialize(doublereal t0=0.0)
Initialize the reactor.
Definition: Reactor.cpp:84
virtual void getSurfaceInitialConditions(double *y)
Get initial conditions for SurfPhase objects attached to this reactor.
Definition: Reactor.cpp:75
virtual size_t nSensParams()
Number of sensitivity parameters associated with this reactor (including walls)
Definition: Reactor.cpp:112
virtual size_t speciesIndex(const std::string &nm) const
Return the index in the solution vector for this reactor of the species named nm, in either the homog...
Definition: Reactor.cpp:340
void setChemistry(bool cflag=true)
Enable or disable changes in reactor composition due to chemical reactions.
Definition: Reactor.h:69
vector_fp m_wdot
Species net molar production rates.
Definition: Reactor.h:233
vector_fp m_advancelimits
!< Number of variables associated with reactor surfaces
Definition: Reactor.h:240
vector_fp m_uk
Species molar internal energies.
Definition: Reactor.h:234
virtual void updateConnected(bool updatePressure)
Update the state information needed by connected reactors and flow devices.
Definition: Reactor.cpp:184
doublereal m_vdot
net rate of volume change from moving walls [m^3/s]
Definition: Reactor.h:218
Namespace for the Cantera kernel.
Definition: AnyMap.h:29
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
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