Cantera  2.4.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 http://www.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 int type() const {
43  return ReactorType;
44  }
45 
46  /**
47  * Insert something into the reactor. The 'something' must belong to a class
48  * that is a subclass of both ThermoPhase and Kinetics.
49  */
50  template<class G>
51  void insert(G& contents) {
53  setKineticsMgr(contents);
54  }
55 
56  void setKineticsMgr(Kinetics& kin);
57 
58  //! Enable or disable changes in reactor composition due to chemical reactions.
59  void setChemistry(bool cflag = true) {
60  m_chem = cflag;
61  }
62 
63  //! Returns `true` if changes in the reactor composition due to chemical reactions are enabled.
64  bool chemistryEnabled() const {
65  return m_chem;
66  }
67 
68  //! Set the energy equation on or off.
69  void setEnergy(int eflag = 1) {
70  if (eflag > 0) {
71  m_energy = true;
72  } else {
73  m_energy = false;
74  }
75  }
76 
77  //! Returns `true` if solution of the energy equation is enabled.
78  bool energyEnabled() const {
79  return m_energy;
80  }
81 
82  //! Number of equations (state variables) for this reactor
83  virtual size_t neq() {
84  if (!m_nv) {
85  initialize();
86  }
87  return m_nv;
88  }
89 
90  //! Get the the current state of the reactor.
91  /*!
92  * @param[out] y state vector representing the initial state of the reactor
93  */
94  virtual void getState(doublereal* y);
95 
96  virtual void initialize(doublereal t0 = 0.0);
97 
98  /*!
99  * Evaluate the reactor governing equations. Called by ReactorNet::eval.
100  * @param[in] t time.
101  * @param[in] y solution vector, length neq()
102  * @param[out] ydot rate of change of solution vector, length neq()
103  * @param[in] params sensitivity parameter vector, length ReactorNet::nparams()
104  */
105  virtual void evalEqs(doublereal t, doublereal* y,
106  doublereal* ydot, doublereal* params);
107 
108  virtual void syncState();
109 
110  //! Set the state of the reactor to correspond to the state vector *y*.
111  virtual void updateState(doublereal* y);
112 
113  //! Number of sensitivity parameters associated with this reactor
114  //! (including walls)
115  virtual size_t nSensParams();
116 
117  //! Add a sensitivity parameter associated with the reaction number *rxn*
118  //! (in the homogeneous phase).
119  virtual void addSensitivityReaction(size_t rxn);
120 
121  //! Add a sensitivity parameter associated with the enthalpy formation of
122  //! species *k* (in the homogeneous phase)
123  virtual void addSensitivitySpeciesEnthalpy(size_t k);
124 
125  //! Return the index in the solution vector for this reactor of the
126  //! component named *nm*. Possible values for *nm* are "mass", "volume",
127  //! "int_energy", the name of a homogeneous phase species, or the name of a
128  //! surface species.
129  virtual size_t componentIndex(const std::string& nm) const;
130 
131  //! Return the name of the solution component with index *i*.
132  //! @see componentIndex()
133  virtual std::string componentName(size_t k);
134 
135 protected:
136  //! Set reaction rate multipliers based on the sensitivity variables in
137  //! *params*.
138  virtual void applySensitivity(double* params);
139  //! Reset the reaction rate multipliers
140  virtual void resetSensitivity(double* params);
141 
142  //! Return the index in the solution vector for this reactor of the species
143  //! named *nm*, in either the homogeneous phase or a surface phase, relative
144  //! to the start of the species terms. Used to implement componentIndex for
145  //! specific reactor implementations.
146  virtual size_t speciesIndex(const std::string& nm) const;
147 
148  //! Evaluate terms related to Walls. Calculates #m_vdot and #m_Q based on
149  //! wall movement and heat transfer.
150  //! @param t the current time
151  virtual void evalWalls(double t);
152 
153  //! Evaluate terms related to surface reactions. Calculates #m_sdot and rate
154  //! of change in surface species coverages.
155  //! @param t the current time
156  //! @param[out] ydot array of d(coverage)/dt for surface species
157  //! @returns Net mass flux from surfaces
158  virtual double evalSurfaces(double t, double* ydot);
159 
160  //! Update the state of SurfPhase objects attached to this reactor
161  virtual void updateSurfaceState(double* y);
162 
163  //! Get initial conditions for SurfPhase objects attached to this reactor
164  virtual void getSurfaceInitialConditions(double* y);
165 
166  //! Pointer to the homogeneous Kinetics object that handles the reactions
168 
169  doublereal m_vdot; //!< net rate of volume change from moving walls [m^3/s]
170  doublereal m_Q; //!< net heat transfer through walls [W]
171  doublereal m_mass; //!< total mass
172  vector_fp m_work;
173 
174  //! Production rates of gas phase species on surfaces [kmol/s]
176 
177  vector_fp m_wdot; //!< Species net molar production rates
178  vector_fp m_uk; //!< Species molar internal energies
179  bool m_chem;
180  bool m_energy;
181  size_t m_nv;
182 
183  // Data associated each sensitivity parameter
184  std::vector<SensitivityParameter> m_sensParams;
185 };
186 }
187 
188 #endif
void setChemistry(bool cflag=true)
Enable or disable changes in reactor composition due to chemical reactions.
Definition: Reactor.h:59
vector_fp m_sdot
Production rates of gas phase species on surfaces [kmol/s].
Definition: Reactor.h:175
doublereal m_mass
total mass
Definition: Reactor.h:171
virtual size_t nSensParams()
Number of sensitivity parameters associated with this reactor (including walls)
Definition: Reactor.cpp:108
vector_fp m_wdot
Species net molar production rates.
Definition: Reactor.h:177
void setEnergy(int eflag=1)
Set the energy equation on or off.
Definition: Reactor.h:69
virtual void addSensitivityReaction(size_t rxn)
Add a sensitivity parameter associated with the reaction number rxn (in the homogeneous phase)...
Definition: Reactor.cpp:297
virtual void evalWalls(double t)
Evaluate terms related to Walls.
Definition: Reactor.cpp:251
virtual void resetSensitivity(double *params)
Reset the reaction rate multipliers.
Definition: Reactor.cpp:411
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:325
virtual std::string componentName(size_t k)
Return the name of the solution component with index i.
Definition: Reactor.cpp:363
virtual void initialize(doublereal t0=0.0)
Initialize the reactor.
Definition: Reactor.cpp:75
bool chemistryEnabled() const
Returns true if changes in the reactor composition due to chemical reactions are enabled.
Definition: Reactor.h:64
virtual void updateState(doublereal *y)
Set the state of the reactor to correspond to the state vector y.
Definition: Reactor.cpp:123
Kinetics * m_kin
Pointer to the homogeneous Kinetics object that handles the reactions.
Definition: Reactor.h:167
void insert(G &contents)
Insert something into the reactor.
Definition: Reactor.h:51
virtual void applySensitivity(double *params)
Set reaction rate multipliers based on the sensitivity variables in params.
Definition: Reactor.cpp:389
doublereal m_Q
net heat transfer through walls [W]
Definition: Reactor.h:170
virtual double evalSurfaces(double t, double *ydot)
Evaluate terms related to surface reactions.
Definition: Reactor.cpp:262
Public interface for kinetics managers.
Definition: Kinetics.h:110
virtual void getState(doublereal *y)
Get the the current state of the reactor.
Definition: Reactor.cpp:40
Base class for kinetics managers and also contains the kineticsmgr module documentation (see Kinetics...
Base class for stirred reactors.
Definition: ReactorBase.h:44
virtual void setThermoMgr(thermo_t &thermo)
Specify the mixture contained in the reactor.
Definition: ReactorBase.cpp:26
thermo_t & contents()
return a reference to the contents.
Definition: ReactorBase.h:151
virtual void syncState()
Set the state of the reactor to correspond to the state of the associated ThermoPhase object...
Definition: Reactor.cpp:117
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:157
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:347
bool energyEnabled() const
Returns true if solution of the energy equation is enabled.
Definition: Reactor.h:78
virtual int type() const
Return a constant indicating the type of this Reactor.
Definition: Reactor.h:42
virtual size_t neq()
Number of equations (state variables) for this reactor.
Definition: Reactor.h:83
virtual void evalEqs(doublereal t, doublereal *y, doublereal *ydot, doublereal *params)
Definition: Reactor.cpp:185
doublereal m_vdot
net rate of volume change from moving walls [m^3/s]
Definition: Reactor.h:169
vector_fp m_uk
Species molar internal energies.
Definition: Reactor.h:178
Namespace for the Cantera kernel.
Definition: AnyMap.cpp:8
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:310
virtual void updateSurfaceState(double *y)
Update the state of SurfPhase objects attached to this reactor.
Definition: Reactor.cpp:176
virtual void getSurfaceInitialConditions(double *y)
Get initial conditions for SurfPhase objects attached to this reactor.
Definition: Reactor.cpp:66
Class Reactor is a general-purpose class for stirred reactors.
Definition: Reactor.h:37