Cantera  2.2.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ReactorBase.h
Go to the documentation of this file.
1 /**
2  * @file ReactorBase.h
3  */
4 // Copyright 2001 California Institute of Technology
5 
6 #ifndef CT_REACTORBASE_H
7 #define CT_REACTORBASE_H
8 
10 
11 //! Namespace for classes implementing zero-dimensional reactor networks.
12 namespace Cantera
13 {
14 class FlowDevice;
15 class Wall;
16 class ReactorNet;
17 
18 const int ReservoirType = 1;
19 const int ReactorType = 2;
20 const int FlowReactorType = 3;
21 const int ConstPressureReactorType = 4;
22 const int IdealGasReactorType = 5;
23 const int IdealGasConstPressureReactorType = 6;
24 
25 /**
26  * Base class for stirred reactors. Allows using any substance model, with
27  * arbitrary inflow, outflow, heat loss/gain, surface chemistry, and volume
28  * change.
29  */
31 {
32 public:
33  explicit ReactorBase(const std::string& name = "(none)");
34  virtual ~ReactorBase() {}
35 
36  //! Return a constant indicating the type of this Reactor
37  virtual int type() const {
38  return 0;
39  }
40 
41  //! Return the name of this reactor
42  std::string name() const {
43  return m_name;
44  }
45 
46  //! Set the name of this reactor
47  void setName(const std::string& name) {
48  m_name = name;
49  }
50 
51  /** @name Methods to set up a simulation. */
52  //@{
53 
54  /**
55  * Set the initial reactor volume. By default, the volume is
56  * 1.0 m^3.
57  */
58  void setInitialVolume(doublereal vol) {
59  m_vol = vol;
60  }
61 
62  /**
63  * Specify the mixture contained in the reactor. Note that
64  * a pointer to this substance is stored, and as the integration
65  * proceeds, the state of the substance is modified.
66  */
67  virtual void setThermoMgr(thermo_t& thermo);
68 
69  //! Connect an inlet FlowDevice to this reactor
70  void addInlet(FlowDevice& inlet);
71 
72  //! Connect an outlet FlowDevice to this reactor
74 
75  //! Return a reference to the *n*-th inlet FlowDevice connected to this
76  //! reactor.
77  FlowDevice& inlet(size_t n = 0);
78 
79  //! Return a reference to the *n*-th outlet FlowDevice connected to this
80  //! reactor.
81  FlowDevice& outlet(size_t n = 0);
82 
83  //! Return the number of inlet FlowDevice objects connected to this
84  //! reactor.
85  size_t nInlets() {
86  return m_inlet.size();
87  }
88 
89  //! Return the number of outlet FlowDevice objects connected to this
90  //! reactor.
91  size_t nOutlets() {
92  return m_outlet.size();
93  }
94 
95  //! Return the number of Wall objects connected to this reactor.
96  size_t nWalls() {
97  return m_wall.size();
98  }
99 
100  //! Insert a Wall between this reactor and another reactor.
101  /*!
102  * `lr` = 0 if this reactor is to the left of the wall and `lr` = 1 if
103  * this reactor is to the right of the wall. This method is called
104  * automatically for both the left and right reactors by Wall::install.
105  */
106  void addWall(Wall& w, int lr);
107 
108  //! Return a reference to the *n*-th Wall connected to this reactor.
109  Wall& wall(size_t n);
110 
111  /**
112  * Initialize the reactor. Called automatically by ReactorNet::initialize.
113  */
114  virtual void initialize(doublereal t0 = 0.0) {
115  throw NotImplementedError("ReactorBase::initialize");
116  }
117 
118  //@}
119 
120  //! Set the state of the Phase object associated with this reactor to the
121  //! reactor's current state.
122  void restoreState() {
123  if (!m_thermo) {
124  throw CanteraError("ReactorBase::restoreState", "No phase defined.");
125  }
126  m_thermo->restoreState(m_state);
127  }
128 
129  //! Set the state of the reactor to correspond to the state of the
130  //! associated ThermoPhase object. This is the inverse of restoreState().
131  //! Calling this will trigger integrator reinitialization.
132  virtual void syncState();
133 
134  //! return a reference to the contents.
136  if (!m_thermo) {
137  throw CanteraError("ReactorBase::contents",
138  "Reactor contents not defined.");
139  }
140  return *m_thermo;
141  }
142 
143  const thermo_t& contents() const {
144  if (!m_thermo) {
145  throw CanteraError("ReactorBase::contents",
146  "Reactor contents not defined.");
147  }
148  return *m_thermo;
149  }
150 
151  //! Return the residence time (s) of the contents of this reactor, based
152  //! on the outlet mass flow rates and the mass of the reactor contents.
153  doublereal residenceTime();
154 
155  /**
156  * @name Solution components.
157  * The values returned are those after the last call to ReactorNet::advance
158  * or ReactorNet::step.
159  */
160  //@{
161 
162  //! Returns the current volume (m^3) of the reactor.
163  doublereal volume() const {
164  return m_vol;
165  }
166 
167  //! Returns the current density (kg/m^3) of the reactor's contents.
168  doublereal density() const {
169  return m_state[1];
170  }
171 
172  //! Returns the current temperature (K) of the reactor's contents.
173  doublereal temperature() const {
174  return m_state[0];
175  }
176 
177  //! Returns the current enthalpy (J/kg) of the reactor's contents.
178  doublereal enthalpy_mass() const {
179  return m_enthalpy;
180  }
181 
182  //! Returns the current internal energy (J/kg) of the reactor's contents.
183  doublereal intEnergy_mass() const {
184  return m_intEnergy;
185  }
186 
187  //! Returns the current pressure (Pa) of the reactor.
188  doublereal pressure() const {
189  return m_pressure;
190  }
191 
192  //! Returns the mass (kg) of the reactor's contents.
193  doublereal mass() const {
194  return m_vol * density();
195  }
196 
197  //! Return the vector of species mass fractions.
198  const doublereal* massFractions() const {
199  return DATA_PTR(m_state) + 2;
200  }
201 
202  //! Return the mass fraction of the *k*-th species.
203  doublereal massFraction(size_t k) const {
204  return m_state[k+2];
205  }
206 
207  //@}
208 
209  //! The ReactorNet that this reactor belongs to.
210  ReactorNet& network();
211 
212  //! Set the ReactorNet that this reactor belongs to.
213  void setNetwork(ReactorNet* net);
214 
215 protected:
216  //! Number of homogeneous species in the mixture
217  size_t m_nsp;
218 
219  thermo_t* m_thermo;
220  doublereal m_vol;
221  doublereal m_enthalpy;
222  doublereal m_intEnergy;
223  doublereal m_pressure;
224  vector_fp m_state;
225  std::vector<FlowDevice*> m_inlet, m_outlet;
226  std::vector<Wall*> m_wall;
227  vector_int m_lr;
228  std::string m_name;
229 
230  //! The ReactorNet that this reactor is part of
232 };
233 }
234 
235 #endif
A class representing a network of connected reactors.
Definition: ReactorNet.h:23
virtual void initialize(doublereal t0=0.0)
Initialize the reactor.
Definition: ReactorBase.h:114
void restoreState(const vector_fp &state)
Restore a state saved on a previous call to saveState.
Definition: Phase.cpp:314
doublereal enthalpy_mass() const
Returns the current enthalpy (J/kg) of the reactor's contents.
Definition: ReactorBase.h:178
doublereal pressure() const
Returns the current pressure (Pa) of the reactor.
Definition: ReactorBase.h:188
Base class for 'flow devices' (valves, pressure regulators, etc.) connecting reactors.
Definition: FlowDevice.h:28
An error indicating that an unimplemented function has been called.
Definition: ctexceptions.h:213
ReactorNet * m_net
The ReactorNet that this reactor is part of.
Definition: ReactorBase.h:231
doublereal density() const
Returns the current density (kg/m^3) of the reactor's contents.
Definition: ReactorBase.h:168
ReactorNet & network()
The ReactorNet that this reactor belongs to.
Definition: ReactorBase.cpp:72
size_t nInlets()
Return the number of inlet FlowDevice objects connected to this reactor.
Definition: ReactorBase.h:85
void addOutlet(FlowDevice &outlet)
Connect an outlet FlowDevice to this reactor.
Definition: ReactorBase.cpp:52
void addInlet(FlowDevice &inlet)
Connect an inlet FlowDevice to this reactor.
Definition: ReactorBase.cpp:47
Base class for a phase with thermodynamic properties.
Definition: ThermoPhase.h:97
std::vector< int > vector_int
Vector of ints.
Definition: ct_defs.h:159
const doublereal * massFractions() const
Return the vector of species mass fractions.
Definition: ReactorBase.h:198
size_t nWalls()
Return the number of Wall objects connected to this reactor.
Definition: ReactorBase.h:96
Wall & wall(size_t n)
Return a reference to the n-th Wall connected to this reactor.
Definition: ReactorBase.cpp:67
Represents a wall between between two ReactorBase objects.
Definition: Wall.h:27
virtual void syncState()
Set the state of the reactor to correspond to the state of the associated ThermoPhase object...
Definition: ReactorBase.cpp:36
void setInitialVolume(doublereal vol)
Set the initial reactor volume.
Definition: ReactorBase.h:58
doublereal intEnergy_mass() const
Returns the current internal energy (J/kg) of the reactor's contents.
Definition: ReactorBase.h:183
Base class for exceptions thrown by Cantera classes.
Definition: ctexceptions.h:99
Base class for stirred reactors.
Definition: ReactorBase.h:30
void restoreState()
Set the state of the Phase object associated with this reactor to the reactor's current state...
Definition: ReactorBase.h:122
void addWall(Wall &w, int lr)
Insert a Wall between this reactor and another reactor.
Definition: ReactorBase.cpp:57
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:135
std::string name() const
Return the name of this reactor.
Definition: ReactorBase.h:42
FlowDevice & inlet(size_t n=0)
Return a reference to the n-th inlet FlowDevice connected to this reactor.
Definition: ReactorBase.cpp:96
void setNetwork(ReactorNet *net)
Set the ReactorNet that this reactor belongs to.
Definition: ReactorBase.cpp:82
doublereal residenceTime()
Return the residence time (s) of the contents of this reactor, based on the outlet mass flow rates an...
Definition: ReactorBase.cpp:87
virtual int type() const
Return a constant indicating the type of this Reactor.
Definition: ReactorBase.h:37
doublereal mass() const
Returns the mass (kg) of the reactor's contents.
Definition: ReactorBase.h:193
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
doublereal massFraction(size_t k) const
Return the mass fraction of the k-th species.
Definition: ReactorBase.h:203
#define DATA_PTR(vec)
Creates a pointer to the start of the raw data for a vector.
Definition: ct_defs.h:36
size_t m_nsp
Number of homogeneous species in the mixture.
Definition: ReactorBase.h:217
size_t nOutlets()
Return the number of outlet FlowDevice objects connected to this reactor.
Definition: ReactorBase.h:91
FlowDevice & outlet(size_t n=0)
Return a reference to the n-th outlet FlowDevice connected to this reactor.
Header file for class ThermoPhase, the base class for phases with thermodynamic properties, and the text for the Module thermoprops (see Thermodynamic Properties and class ThermoPhase).
void setName(const std::string &name)
Set the name of this reactor.
Definition: ReactorBase.h:47
doublereal temperature() const
Returns the current temperature (K) of the reactor's contents.
Definition: ReactorBase.h:173
doublereal volume() const
Returns the current volume (m^3) of the reactor.
Definition: ReactorBase.h:163