Cantera  2.2.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Reactor.h
Go to the documentation of this file.
1 /**
2  * @file Reactor.h
3  */
4 
5 // Copyright 2001 California Institute of Technology
6 
7 #ifndef CT_REACTOR_H
8 #define CT_REACTOR_H
9 
10 #include "ReactorBase.h"
12 
13 namespace Cantera
14 {
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  */
39 class Reactor : public ReactorBase
40 {
41 public:
42  Reactor();
43 
44  virtual int type() const {
45  return ReactorType;
46  }
47 
48  /**
49  * Insert something into the reactor. The 'something' must
50  * belong to a class that is a subclass of both ThermoPhase
51  * and Kinetics.
52  */
53  template<class G>
54  void insert(G& contents) {
55  setThermoMgr(contents);
56  setKineticsMgr(contents);
57  }
58 
59  void setKineticsMgr(Kinetics& kin) {
60  m_kin = &kin;
61  if (m_kin->nReactions() == 0) {
63  } else {
65  }
66  }
67 
68  //! Disable changes in reactor composition due to chemical reactions.
70  m_chem = false;
71  }
72 
73  //! Enable changes in reactor composition due to chemical reactions.
74  void enableChemistry() {
75  m_chem = true;
76  }
77 
78  //! Set the energy equation on or off.
79  void setEnergy(int eflag = 1) {
80  if (eflag > 0) {
81  m_energy = true;
82  } else {
83  m_energy = false;
84  }
85  }
86 
87  //! Returns `true` if solution of the energy equation is enabled.
88  bool energyEnabled() const {
89  return m_energy;
90  }
91 
92  //! Number of equations (state variables) for this reactor
93  virtual size_t neq() {
94  return m_nv;
95  }
96 
97  //! Called by ReactorNet to get the initial conditions.
98  /*!
99  * @param[in] t0 Time at which initial conditions are determined
100  * @param[in] leny Length of *y* (unused)
101  * @param[out] y state vector representing the initial state of the reactor
102  */
103  virtual void getInitialConditions(doublereal t0, size_t leny,
104  doublereal* y);
105 
106  virtual void initialize(doublereal t0 = 0.0);
107 
108  /*!
109  * Evaluate the reactor governing equations. Called by ReactorNet::eval.
110  * @param[in] t time.
111  * @param[in] y solution vector, length neq()
112  * @param[out] ydot rate of change of solution vector, length neq()
113  * @param[in] params sensitivity parameter vector, length ReactorNet::nparams()
114  */
115  virtual void evalEqs(doublereal t, doublereal* y,
116  doublereal* ydot, doublereal* params);
117 
118  virtual void syncState();
119 
120  //! Set the state of the reactor to correspond to the state vector *y*.
121  virtual void updateState(doublereal* y);
122 
123  //! Number of sensitivity parameters associated with this reactor
124  //! (including walls)
125  virtual size_t nSensParams();
126 
127  //! Add a sensitivity parameter associated with the reaction number *rxn*
128  //! (in the homogeneous phase).
129  virtual void addSensitivityReaction(size_t rxn);
130 
131  //! Return a vector specifying the ordering of objects to use when
132  //! determining sensitivity parameter indices.
133  /*!
134  * Used to construct ReactorNet::m_sensOrder.
135  *
136  * @return A vector of pairs where the first element of each pair is a
137  * pointer to either a Reactor object or a Wall object and the second
138  * element is either 0 (in the case of a Reactor) or in the case of a
139  * Wall indicates that the sensitivity parameters are associated with
140  * surface chemistry on the left (0) or right (1) side of the wall.
141  */
142  std::vector<std::pair<void*, int> > getSensitivityOrder() const;
143 
144  //! Return the index in the solution vector for this reactor of the
145  //! component named *nm*. Possible values for *nm* are "m", "V", "T", the
146  //! name of a homogeneous phase species, or the name of a surface species.
147  virtual size_t componentIndex(const std::string& nm) const;
148 
149 protected:
150  //! Set reaction rate multipliers based on the sensitivity variables in
151  //! *params*.
152  virtual void applySensitivity(double* params);
153  //! Reset the reaction rate multipliers
154  virtual void resetSensitivity(double* params);
155 
156  //! Return the index in the solution vector for this reactor of the species
157  //! named *nm*, in either the homogeneous phase or a surface phase, relative
158  //! to the start of the species terms. Used to implement componentIndex for
159  //! specific reactor implementations.
160  virtual size_t speciesIndex(const std::string& nm) const;
161 
162  //! Evaluate terms related to Walls
163  //! Calculates #m_vdot and #m_Q based on wall movement and heat transfer
164  //! @param t the current time
165  virtual void evalWalls(double t);
166 
167  //! Evaluate terms related to surface reactions
168  //! Calculates #m_sdot and rate of change in surface species coverages
169  //! @param t the current time
170  //! @param[out] ydot array of d(coverage)/dt for surface species
171  //! @returns Net mass flux from surfaces
172  virtual double evalSurfaces(double t, double* ydot);
173 
174  //! Update the state of SurfPhase objects attached to this reactor
175  virtual void updateSurfaceState(double* y);
176 
177  //! Get initial conditions for SurfPhase objects attached to this reactor
178  virtual void getSurfaceInitialConditions(double* y);
179 
180  //! Pointer to the homogeneous Kinetics object that handles the reactions
182 
183  doublereal m_vdot; //!< net rate of volume change from moving walls [m^3/s]
184  doublereal m_Q; //!< net heat transfer through walls [W]
185  doublereal m_mass; //!< total mass
186  vector_fp m_work;
187 
188  //! Production rates of gas phase species on surfaces [kmol/s]
190 
191  vector_fp m_wdot; //!< Species net molar production rates
192  vector_fp m_uk; //!< Species molar internal energies
193  bool m_chem;
194  bool m_energy;
195  size_t m_nv;
196 
197  size_t m_nsens;
198  std::vector<size_t> m_pnum;
199  std::vector<size_t> m_nsens_wall;
200  vector_fp m_mult_save;
201 };
202 }
203 
204 #endif
virtual void getInitialConditions(doublereal t0, size_t leny, doublereal *y)
Called by ReactorNet to get the initial conditions.
Definition: Reactor.cpp:30
vector_fp m_sdot
Production rates of gas phase species on surfaces [kmol/s].
Definition: Reactor.h:189
doublereal m_mass
total mass
Definition: Reactor.h:185
virtual size_t nSensParams()
Number of sensitivity parameters associated with this reactor (including walls)
Definition: Reactor.cpp:107
vector_fp m_wdot
Species net molar production rates.
Definition: Reactor.h:191
void setEnergy(int eflag=1)
Set the energy equation on or off.
Definition: Reactor.h:79
virtual void addSensitivityReaction(size_t rxn)
Add a sensitivity parameter associated with the reaction number rxn (in the homogeneous phase)...
Definition: Reactor.cpp:329
bool energyEnabled() const
Returns true if solution of the energy equation is enabled.
Definition: Reactor.h:88
virtual void evalWalls(double t)
Evaluate terms related to Walls Calculates m_vdot and m_Q based on wall movement and heat transfer...
Definition: Reactor.cpp:281
virtual void resetSensitivity(double *params)
Reset the reaction rate multipliers.
Definition: Reactor.cpp:415
void enableChemistry()
Enable changes in reactor composition due to chemical reactions.
Definition: Reactor.h:74
virtual void initialize(doublereal t0=0.0)
Initialize the reactor.
Definition: Reactor.cpp:68
virtual void updateState(doublereal *y)
Set the state of the reactor to correspond to the state vector y.
Definition: Reactor.cpp:128
Kinetics * m_kin
Pointer to the homogeneous Kinetics object that handles the reactions.
Definition: Reactor.h:181
void insert(G &contents)
Insert something into the reactor.
Definition: Reactor.h:54
virtual void applySensitivity(double *params)
Set reaction rate multipliers based on the sensitivity variables in params.
Definition: Reactor.cpp:395
doublereal m_Q
net heat transfer through walls [W]
Definition: Reactor.h:184
virtual double evalSurfaces(double t, double *ydot)
Evaluate terms related to surface reactions Calculates m_sdot and rate of change in surface species c...
Definition: Reactor.cpp:292
Public interface for kinetics managers.
Definition: Kinetics.h:128
Base class for kinetics managers and also contains the kineticsmgr module documentation (see Kinetics...
Base class for stirred reactors.
Definition: ReactorBase.h:30
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:353
virtual void setThermoMgr(thermo_t &thermo)
Specify the mixture contained in the reactor.
Definition: ReactorBase.cpp:26
void disableChemistry()
Disable changes in reactor composition due to chemical reactions.
Definition: Reactor.h:69
thermo_t & contents()
return a reference to the contents.
Definition: ReactorBase.h:135
virtual void syncState()
Set the state of the reactor to correspond to the state of the associated ThermoPhase object...
Definition: Reactor.cpp:122
virtual int type() const
Return a constant indicating the type of this Reactor.
Definition: Reactor.h:44
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
size_t nReactions() const
Number of reactions in the reaction mechanism.
Definition: Kinetics.h:193
std::vector< std::pair< void *, int > > getSensitivityOrder() const
Return a vector specifying the ordering of objects to use when determining sensitivity parameter indi...
Definition: Reactor.cpp:341
virtual size_t neq()
Number of equations (state variables) for this reactor.
Definition: Reactor.h:93
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:379
virtual void evalEqs(doublereal t, doublereal *y, doublereal *ydot, doublereal *params)
Definition: Reactor.cpp:206
doublereal m_vdot
net rate of volume change from moving walls [m^3/s]
Definition: Reactor.h:183
vector_fp m_uk
Species molar internal energies.
Definition: Reactor.h:192
virtual void updateSurfaceState(double *y)
Update the state of SurfPhase objects attached to this reactor.
Definition: Reactor.cpp:194
virtual void getSurfaceInitialConditions(double *y)
Get initial conditions for SurfPhase objects attached to this reactor.
Definition: Reactor.cpp:56
Class Reactor is a general-purpose class for stirred reactors.
Definition: Reactor.h:39