Cantera  2.5.1
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 
10 
11 using namespace std;
12 namespace Cantera
13 {
14 
15 ReactorBase::ReactorBase(const string& name) : m_nsp(0),
16  m_thermo(0),
17  m_vol(1.0),
18  m_enthalpy(0.0),
19  m_intEnergy(0.0),
20  m_pressure(0.0),
21  m_net(0)
22 {
23  m_name = name;
24 }
25 
26 void ReactorBase::setThermoMgr(thermo_t& thermo)
27 {
28  m_thermo = &thermo;
29  m_nsp = m_thermo->nSpecies();
30  m_thermo->saveState(m_state);
31  m_enthalpy = m_thermo->enthalpy_mass();
32  m_intEnergy = m_thermo->intEnergy_mass();
33  m_pressure = m_thermo->pressure();
34 }
35 
36 void ReactorBase::syncState()
37 {
38  m_thermo->saveState(m_state);
39  m_enthalpy = m_thermo->enthalpy_mass();
40  m_intEnergy = m_thermo->intEnergy_mass();
41  m_pressure = m_thermo->pressure();
42  if (m_net) {
43  m_net->setNeedsReinit();
44  }
45 }
46 
47 void ReactorBase::addInlet(FlowDevice& inlet)
48 {
49  m_inlet.push_back(&inlet);
50 }
51 
52 void ReactorBase::addOutlet(FlowDevice& outlet)
53 {
54  m_outlet.push_back(&outlet);
55 }
56 
57 void ReactorBase::addWall(WallBase& w, int lr)
58 {
59  m_wall.push_back(&w);
60  if (lr == 0) {
61  m_lr.push_back(0);
62  } else {
63  m_lr.push_back(1);
64  }
65 }
66 
67 WallBase& ReactorBase::wall(size_t n)
68 {
69  return *m_wall[n];
70 }
71 
72 void ReactorBase::addSurface(ReactorSurface* surf)
73 {
74  if (find(m_surfaces.begin(), m_surfaces.end(), surf) == m_surfaces.end()) {
75  m_surfaces.push_back(surf);
76  surf->setReactor(this);
77  }
78 }
79 
80 ReactorSurface* ReactorBase::surface(size_t n)
81 {
82  return m_surfaces[n];
83 }
84 
85 ReactorNet& ReactorBase::network()
86 {
87  if (m_net) {
88  return *m_net;
89  } else {
90  throw CanteraError("ReactorBase::network",
91  "Reactor is not part of a ReactorNet");
92  }
93 }
94 
95 void ReactorBase::setNetwork(ReactorNet* net)
96 {
97  m_net = net;
98 }
99 
100 doublereal ReactorBase::residenceTime()
101 {
102  doublereal mout = 0.0;
103  for (size_t i = 0; i < m_outlet.size(); i++) {
104  mout += m_outlet[i]->massFlowRate();
105  }
106  return mass()/mout;
107 }
108 
109 FlowDevice& ReactorBase::inlet(size_t n)
110 {
111  return *m_inlet[n];
112 }
113 FlowDevice& ReactorBase::outlet(size_t n)
114 {
115  return *m_outlet[n];
116 }
117 
118 }
Header file for class ReactorSurface.
Base class for exceptions thrown by Cantera classes.
Definition: ctexceptions.h:61
Base class for 'flow devices' (valves, pressure regulators, etc.) connecting reactors.
Definition: FlowDevice.h:31
size_t nSpecies() const
Returns the number of species in the phase.
Definition: Phase.h:285
A class representing a network of connected reactors.
Definition: ReactorNet.h:24
Base class for a phase with thermodynamic properties.
Definition: ThermoPhase.h:102
Base class for 'walls' (walls, pistons, etc.) connecting reactors.
Definition: Wall.h:29
Namespace for the Cantera kernel.
Definition: AnyMap.cpp:264