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
6#include "cantera/zeroD/ReactorBase.h"
7#include "cantera/zeroD/FlowDevice.h"
8#include "cantera/zeroD/ReactorNet.h"
9#include "cantera/zeroD/ReactorSurface.h"
10#include "cantera/thermo/ThermoPhase.h"
11
12 using namespace std;
13 namespace 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
27 void 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
37 void 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
48 void ReactorBase::addInlet(FlowDevice& inlet)
49{
50 m_inlet.push_back(&inlet);
51}
52
53 void ReactorBase::addOutlet(FlowDevice& outlet)
54{
55 m_outlet.push_back(&outlet);
56}
57
58 void 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
68 WallBase& ReactorBase::wall(size_t n)
69{
70 return *m_wall[n];
71}
72
73 void 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
81 ReactorSurface* ReactorBase::surface(size_t n)
82{
83 return m_surfaces[n];
84}
85
86 void ReactorBase::restoreState() {
87 if (!m_thermo) {
88 throw CanteraError("ReactorBase::restoreState", "No phase defined.");
89 }
90 m_thermo->restoreState(m_state);
91}
92
93 ReactorNet& 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
103 void 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
117 FlowDevice& ReactorBase::inlet(size_t n)
118{
119 return *m_inlet[n];
120}
121 FlowDevice& ReactorBase::outlet(size_t n)
122{
123 return *m_outlet[n];
124}
125
126}
FlowDevice.h
ReactorBase.h
ReactorNet.h
ReactorSurface.h
Header file for class ReactorSurface.
ThermoPhase.h
Header file for class ThermoPhase, the base class for phases with thermodynamic properties,...
Cantera::CanteraError
Base class for exceptions thrown by Cantera classes.
Definition: ctexceptions.h:61
Cantera::FlowDevice
Base class for 'flow devices' (valves, pressure regulators, etc.) connecting reactors.
Definition: FlowDevice.h:24
Cantera::Phase::nSpecies
size_t nSpecies() const
Returns the number of species in the phase.
Definition: Phase.h:273
Cantera::ReactorNet
A class representing a network of connected reactors.
Definition: ReactorNet.h:27
Cantera::ReactorSurface
A surface where reactions can occur that is in contact with the bulk fluid of a Reactor.
Definition: ReactorSurface.h:21
Cantera::ReactorSurface::setReactor
void setReactor(ReactorBase *reactor)
Set the reactor that this Surface interacts with.
Definition: ReactorSurface.cpp:50
Cantera::ThermoPhase
Base class for a phase with thermodynamic properties.
Definition: ThermoPhase.h:102
Cantera::WallBase
Base class for 'walls' (walls, pistons, etc.) connecting reactors.
Definition: Wall.h:25
Cantera
Namespace for the Cantera kernel.
Definition: AnyMap.cpp:557