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