Cantera  3.1.0a1
ReactorBase.cpp
Go to the documentation of this file.
1 //! @file ReactorBase.cpp
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 
11 
12 namespace Cantera
13 {
14 
15 ReactorBase::ReactorBase(const string& name)
16 {
17  m_name = name;
18 }
19 
21 {
22  m_thermo = &thermo;
23  m_nsp = m_thermo->nSpecies();
24  m_thermo->saveState(m_state);
25  m_enthalpy = m_thermo->enthalpy_mass();
26  m_intEnergy = m_thermo->intEnergy_mass();
27  m_pressure = m_thermo->pressure();
28 }
29 
31 {
32  m_thermo->saveState(m_state);
33  m_enthalpy = m_thermo->enthalpy_mass();
34  m_intEnergy = m_thermo->intEnergy_mass();
35  m_pressure = m_thermo->pressure();
36  if (m_net) {
38  }
39 }
40 
42 {
43  m_inlet.push_back(&inlet);
44 }
45 
47 {
48  m_outlet.push_back(&outlet);
49 }
50 
52 {
53  m_wall.push_back(&w);
54  if (lr == 0) {
55  m_lr.push_back(0);
56  } else {
57  m_lr.push_back(1);
58  }
59 }
60 
62 {
63  return *m_wall[n];
64 }
65 
66 void ReactorBase::addSurface(ReactorSurface* surf)
67 {
68  if (find(m_surfaces.begin(), m_surfaces.end(), surf) == m_surfaces.end()) {
69  m_surfaces.push_back(surf);
70  surf->setReactor(this);
71  }
72 }
73 
75 {
76  return m_surfaces[n];
77 }
78 
80  if (!m_thermo) {
81  throw CanteraError("ReactorBase::restoreState", "No phase defined.");
82  }
83  m_thermo->restoreState(m_state);
84 }
85 
87 {
88  if (m_net) {
89  return *m_net;
90  } else {
91  throw CanteraError("ReactorBase::network",
92  "Reactor is not part of a ReactorNet");
93  }
94 }
95 
97 {
98  m_net = net;
99 }
100 
102 {
103  double mout = 0.0;
104  for (size_t i = 0; i < m_outlet.size(); i++) {
105  mout += m_outlet[i]->massFlowRate();
106  }
107  return mass()/mout;
108 }
109 
111 {
112  return *m_inlet[n];
113 }
115 {
116  return *m_outlet[n];
117 }
118 
119 }
Header file for class ReactorSurface.
Header file for class ThermoPhase, the base class for phases with thermodynamic properties,...
Base class for exceptions thrown by Cantera classes.
Definition: ctexceptions.h:66
Base class for 'flow devices' (valves, pressure regulators, etc.) connecting reactors.
Definition: FlowDevice.h:24
void restoreState(const vector< double > &state)
Restore a state saved on a previous call to saveState.
Definition: Phase.cpp:260
size_t nSpecies() const
Returns the number of species in the phase.
Definition: Phase.h:231
void saveState(vector< double > &state) const
Save the current internal state of the phase.
Definition: Phase.cpp:236
virtual double pressure() const
Return the thermodynamic pressure (Pa).
Definition: Phase.h:580
FlowDevice & outlet(size_t n=0)
Return a reference to the n-th outlet FlowDevice connected to this reactor.
WallBase & wall(size_t n)
Return a reference to the n-th Wall connected to this reactor.
Definition: ReactorBase.cpp:61
void addOutlet(FlowDevice &outlet)
Connect an outlet FlowDevice to this reactor.
Definition: ReactorBase.cpp:46
double m_pressure
Current pressure in the reactor [Pa].
Definition: ReactorBase.h:259
ReactorNet * m_net
The ReactorNet that this reactor is part of.
Definition: ReactorBase.h:272
void addWall(WallBase &w, int lr)
Insert a Wall between this reactor and another reactor.
Definition: ReactorBase.cpp:51
void setNetwork(ReactorNet *net)
Set the ReactorNet that this reactor belongs to.
Definition: ReactorBase.cpp:96
FlowDevice & inlet(size_t n=0)
Return a reference to the n-th inlet FlowDevice connected to this reactor.
vector< int > m_lr
Vector of length nWalls(), indicating whether this reactor is on the left (0) or right (1) of each wa...
Definition: ReactorBase.h:268
void addInlet(FlowDevice &inlet)
Connect an inlet FlowDevice to this reactor.
Definition: ReactorBase.cpp:41
virtual void syncState()
Set the state of the reactor to correspond to the state of the associated ThermoPhase object.
Definition: ReactorBase.cpp:30
double m_intEnergy
Current internal energy of the reactor [J/kg].
Definition: ReactorBase.h:258
size_t m_nsp
Number of homogeneous species in the mixture.
Definition: ReactorBase.h:253
double mass() const
Returns the mass (kg) of the reactor's contents.
Definition: ReactorBase.h:229
virtual void setThermoMgr(ThermoPhase &thermo)
Specify the mixture contained in the reactor.
Definition: ReactorBase.cpp:20
void restoreState()
Set the state of the Phase object associated with this reactor to the reactor's current state.
Definition: ReactorBase.cpp:79
ReactorNet & network()
The ReactorNet that this reactor belongs to.
Definition: ReactorBase.cpp:86
double residenceTime()
Return the residence time (s) of the contents of this reactor, based on the outlet mass flow rates an...
ReactorSurface * surface(size_t n)
Return a reference to the n-th ReactorSurface connected to this reactor.
Definition: ReactorBase.cpp:74
double m_enthalpy
Current specific enthalpy of the reactor [J/kg].
Definition: ReactorBase.h:257
string name() const
Return the name of this reactor.
Definition: ReactorBase.h:64
A class representing a network of connected reactors.
Definition: ReactorNet.h:30
void setNeedsReinit()
Called to trigger integrator reinitialization before further integration.
Definition: ReactorNet.h:272
A surface where reactions can occur that is in contact with the bulk fluid of a Reactor.
void setReactor(ReactorBase *reactor)
Set the reactor that this Surface interacts with.
Base class for a phase with thermodynamic properties.
Definition: ThermoPhase.h:390
double intEnergy_mass() const
Specific internal energy. Units: J/kg.
Definition: ThermoPhase.h:1033
double enthalpy_mass() const
Specific enthalpy. Units: J/kg.
Definition: ThermoPhase.h:1028
Base class for 'walls' (walls, pistons, etc.) connecting reactors.
Definition: Wall.h:22
Namespace for the Cantera kernel.
Definition: AnyMap.cpp:564