Cantera  2.1.2
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  //! Set the state of the reactor to correspond to the state vector *y*.
119  virtual void updateState(doublereal* y);
120 
121  //! Number of sensitivity parameters associated with this reactor
122  //! (including walls)
123  virtual size_t nSensParams();
124 
125  //! Add a sensitivity parameter associated with the reaction number *rxn*
126  //! (in the homogeneous phase).
127  virtual void addSensitivityReaction(size_t rxn);
128 
129  //! Return a vector specifying the ordering of objects to use when
130  //! determining sensitivity parameter indices.
131  /*!
132  * Used to construct ReactorNet::m_sensOrder.
133  *
134  * @return A vector of pairs where the first element of each pair is a
135  * pointer to either a Reactor object or a Wall object and the second
136  * element is either 0 (in the case of a Reactor) or in the case of a
137  * Wall indicates that the sensitivity parameters are associated with
138  * surface chemistry on the left (0) or right (1) side of the wall.
139  */
140  std::vector<std::pair<void*, int> > getSensitivityOrder() const;
141 
142  //! Return the index in the solution vector for this reactor of the
143  //! component named *nm*. Possible values for *nm* are "m", "V", "T", the
144  //! name of a homogeneous phase species, or the name of a surface species.
145  virtual size_t componentIndex(const std::string& nm) const;
146 
147 protected:
148  //! Pointer to the homogeneous Kinetics object that handles the reactions
150 
151  //! Tolerance on the temperature
152  doublereal m_vdot, m_Q;
153  doublereal m_mass; //!< total mass
154  vector_fp m_work;
155  vector_fp m_sdot; // surface production rates
156  vector_fp m_wdot; //!< Species net molar production rates
157  vector_fp m_uk; //!< Species molar internal energies
158  bool m_chem;
159  bool m_energy;
160  size_t m_nv;
161 
162  size_t m_nsens;
163  std::vector<size_t> m_pnum;
164  std::vector<size_t> m_nsens_wall;
165  vector_fp m_mult_save;
166 };
167 }
168 
169 #endif
virtual void getInitialConditions(doublereal t0, size_t leny, doublereal *y)
Called by ReactorNet to get the initial conditions.
Definition: Reactor.cpp:29
doublereal m_mass
total mass
Definition: Reactor.h:153
virtual size_t nSensParams()
Number of sensitivity parameters associated with this reactor (including walls)
Definition: Reactor.cpp:102
vector_fp m_wdot
Species net molar production rates.
Definition: Reactor.h:156
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:326
bool energyEnabled() const
Returns true if solution of the energy equation is enabled.
Definition: Reactor.h:88
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:64
virtual void updateState(doublereal *y)
Set the state of the reactor to correspond to the state vector y.
Definition: Reactor.cpp:117
Kinetics * m_kin
Pointer to the homogeneous Kinetics object that handles the reactions.
Definition: Reactor.h:149
void insert(G &contents)
Insert something into the reactor.
Definition: Reactor.h:54
Public interface for kinetics managers.
Definition: Kinetics.h:131
Base class for kinetics managers and also contains the kineticsmgr module documentation (see Kinetics...
Base class for stirred reactors.
Definition: ReactorBase.h:30
virtual void setThermoMgr(thermo_t &thermo)
Specify the mixture contained in the reactor.
Definition: ReactorBase.cpp:32
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:134
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:165
size_t nReactions() const
Number of reactions in the reaction mechanism.
Definition: Kinetics.h:196
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:338
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:350
virtual void evalEqs(doublereal t, doublereal *y, doublereal *ydot, doublereal *params)
Definition: Reactor.cpp:179
doublereal m_vdot
Tolerance on the temperature.
Definition: Reactor.h:152
vector_fp m_uk
Species molar internal energies.
Definition: Reactor.h:157
Class Reactor is a general-purpose class for stirred reactors.
Definition: Reactor.h:39