| Cantera 3.0.0

Loading...
Searching...
No Matches
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 namespace Cantera
13{
14
15ReactorBase::ReactorBase(const string& name)
16{
17 m_name = name;
18}
19
20 void ReactorBase::setThermoMgr(ThermoPhase& thermo)
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
30 void ReactorBase::syncState()
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) {
37 m_net->setNeedsReinit();
38 }
39}
40
41 void ReactorBase::addInlet(FlowDevice& inlet)
42{
43 m_inlet.push_back(&inlet);
44}
45
46 void ReactorBase::addOutlet(FlowDevice& outlet)
47{
48 m_outlet.push_back(&outlet);
49}
50
51 void ReactorBase::addWall(WallBase& w, int lr)
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
61 WallBase& ReactorBase::wall(size_t n)
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
74 ReactorSurface* ReactorBase::surface(size_t n)
75{
76 return m_surfaces[n];
77}
78
79 void ReactorBase::restoreState() {
80 if (!m_thermo) {
81 throw CanteraError("ReactorBase::restoreState", "No phase defined.");
82 }
83 m_thermo->restoreState(m_state);
84}
85
86 ReactorNet& ReactorBase::network()
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
96 void ReactorBase::setNetwork(ReactorNet* net)
97{
98 m_net = net;
99}
100
101 double ReactorBase::residenceTime()
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
110 FlowDevice& ReactorBase::inlet(size_t n)
111{
112 return *m_inlet[n];
113}
114 FlowDevice& ReactorBase::outlet(size_t n)
115{
116 return *m_outlet[n];
117}
118
119}
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:66
Cantera::FlowDevice
Base class for 'flow devices' (valves, pressure regulators, etc.) connecting reactors.
Definition FlowDevice.h:24
Cantera::Phase::restoreState
void restoreState(const vector< double > &state)
Restore a state saved on a previous call to saveState.
Definition Phase.cpp:275
Cantera::Phase::nSpecies
size_t nSpecies() const
Returns the number of species in the phase.
Definition Phase.h:245
Cantera::Phase::saveState
void saveState(vector< double > &state) const
Save the current internal state of the phase.
Definition Phase.cpp:251
Cantera::Phase::pressure
virtual double pressure() const
Return the thermodynamic pressure (Pa).
Definition Phase.h:680
Cantera::ReactorBase::outlet
FlowDevice & outlet(size_t n=0)
Return a reference to the n-th outlet FlowDevice connected to this reactor.
Definition ReactorBase.cpp:114
Cantera::ReactorBase::wall
WallBase & wall(size_t n)
Return a reference to the n-th Wall connected to this reactor.
Definition ReactorBase.cpp:61
Cantera::ReactorBase::addOutlet
void addOutlet(FlowDevice &outlet)
Connect an outlet FlowDevice to this reactor.
Definition ReactorBase.cpp:46
Cantera::ReactorBase::m_pressure
double m_pressure
Current pressure in the reactor [Pa].
Definition ReactorBase.h:259
Cantera::ReactorBase::m_net
ReactorNet * m_net
The ReactorNet that this reactor is part of.
Definition ReactorBase.h:272
Cantera::ReactorBase::addWall
void addWall(WallBase &w, int lr)
Insert a Wall between this reactor and another reactor.
Definition ReactorBase.cpp:51
Cantera::ReactorBase::setNetwork
void setNetwork(ReactorNet *net)
Set the ReactorNet that this reactor belongs to.
Definition ReactorBase.cpp:96
Cantera::ReactorBase::inlet
FlowDevice & inlet(size_t n=0)
Return a reference to the n-th inlet FlowDevice connected to this reactor.
Definition ReactorBase.cpp:110
Cantera::ReactorBase::m_lr
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
Cantera::ReactorBase::addInlet
void addInlet(FlowDevice &inlet)
Connect an inlet FlowDevice to this reactor.
Definition ReactorBase.cpp:41
Cantera::ReactorBase::syncState
virtual void syncState()
Set the state of the reactor to correspond to the state of the associated ThermoPhase object.
Definition ReactorBase.cpp:30
Cantera::ReactorBase::m_intEnergy
double m_intEnergy
Current internal energy of the reactor [J/kg].
Definition ReactorBase.h:258
Cantera::ReactorBase::m_nsp
size_t m_nsp
Number of homogeneous species in the mixture.
Definition ReactorBase.h:253
Cantera::ReactorBase::mass
double mass() const
Returns the mass (kg) of the reactor's contents.
Definition ReactorBase.h:229
Cantera::ReactorBase::setThermoMgr
virtual void setThermoMgr(ThermoPhase &thermo)
Specify the mixture contained in the reactor.
Definition ReactorBase.cpp:20
Cantera::ReactorBase::restoreState
void restoreState()
Set the state of the Phase object associated with this reactor to the reactor's current state.
Definition ReactorBase.cpp:79
Cantera::ReactorBase::network
ReactorNet & network()
The ReactorNet that this reactor belongs to.
Definition ReactorBase.cpp:86
Cantera::ReactorBase::residenceTime
double residenceTime()
Return the residence time (s) of the contents of this reactor, based on the outlet mass flow rates an...
Definition ReactorBase.cpp:101
Cantera::ReactorBase::surface
ReactorSurface * surface(size_t n)
Return a reference to the n-th ReactorSurface connected to this reactor.
Definition ReactorBase.cpp:74
Cantera::ReactorBase::m_enthalpy
double m_enthalpy
Current specific enthalpy of the reactor [J/kg].
Definition ReactorBase.h:257
Cantera::ReactorBase::name
string name() const
Return the name of this reactor.
Definition ReactorBase.h:64
Cantera::ReactorNet
A class representing a network of connected reactors.
Definition ReactorNet.h:30
Cantera::ReactorNet::setNeedsReinit
void setNeedsReinit()
Called to trigger integrator reinitialization before further integration.
Definition ReactorNet.h:272
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:42
Cantera::ThermoPhase
Base class for a phase with thermodynamic properties.
Definition ThermoPhase.h:390
Cantera::ThermoPhase::intEnergy_mass
double intEnergy_mass() const
Specific internal energy. Units: J/kg.
Definition ThermoPhase.h:1048
Cantera::ThermoPhase::enthalpy_mass
double enthalpy_mass() const
Specific enthalpy. Units: J/kg.
Definition ThermoPhase.h:1043
Cantera::WallBase
Base class for 'walls' (walls, pistons, etc.) connecting reactors.
Definition Wall.h:22
Cantera
Namespace for the Cantera kernel.
Definition AnyMap.cpp:564