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