Cantera  3.3.0a1
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
12
13namespace Cantera
14{
15
16ReactorBase::ReactorBase(const string& name) : m_name(name)
17{
18}
19
20ReactorBase::ReactorBase(shared_ptr<Solution> sol, const string& name)
21 : ReactorBase(sol, true, name)
22{
23}
24
25ReactorBase::ReactorBase(shared_ptr<Solution> sol, bool clone, const string& name)
26 : ReactorBase(name)
27{
28 if (!sol || !(sol->thermo())) {
29 throw CanteraError("ReactorBase::ReactorBase",
30 "Missing or incomplete Solution object.");
31 }
32 if (clone) {
33 m_solution = sol->clone({}, true, false);
34 } else {
35 m_solution = sol;
36 }
37 m_solution->thermo()->addSpeciesLock();
38 m_thermo = m_solution->thermo().get();
39 m_nsp = m_thermo->nSpecies();
40 m_thermo->saveState(m_state);
41 m_enthalpy = m_thermo->enthalpy_mass(); // Needed for flow and wall interactions
42 m_pressure = m_thermo->pressure(); // Needed for flow and wall interactions
43}
44
45
46ReactorBase::~ReactorBase()
47{
48 if (m_solution) {
49 m_solution->thermo()->removeSpeciesLock();
50 }
51}
52
53bool ReactorBase::setDefaultName(map<string, int>& counts)
54{
56 return false;
57 }
58 m_defaultNameSet = true;
59 if (m_name == "(none)" || m_name == "") {
60 m_name = fmt::format("{}_{}", type(), counts[type()]);
61 }
62 counts[type()]++;
63 return true;
64}
65
67{
68 m_inlet.push_back(&inlet);
69}
70
72{
73 m_outlet.push_back(&outlet);
74}
75
77{
78 m_wall.push_back(&w);
79 if (lr == 0) {
80 m_lr.push_back(0);
81 } else {
82 m_lr.push_back(1);
83 }
84}
85
87{
88 return *m_wall[n];
89}
90
92{
93 if (find(m_surfaces.begin(), m_surfaces.end(), surf) == m_surfaces.end()) {
94 m_surfaces.push_back(surf);
95 }
96}
97
99{
100 return m_surfaces[n];
101}
102
104 if (!m_thermo) {
105 throw CanteraError("ReactorBase::restoreState", "No phase defined.");
106 }
107 m_thermo->restoreState(m_state);
108}
109
111{
112 m_thermo->saveState(m_state);
113 m_enthalpy = m_thermo->enthalpy_mass();
114 m_pressure = m_thermo->pressure();
115 m_mass = m_thermo->density() * m_vol;
116 if (m_net) {
118 }
119}
120
122{
123 if (m_net) {
124 return *m_net;
125 } else {
126 throw CanteraError("ReactorBase::network",
127 "Reactor is not part of a ReactorNet");
128 }
129}
130
132{
133 m_net = net;
134}
135
137{
138 double mout = 0.0;
139 for (size_t i = 0; i < m_outlet.size(); i++) {
140 mout += m_outlet[i]->massFlowRate();
141 }
142 return mass()/mout;
143}
144
146{
147 return *m_inlet[n];
148}
150{
151 return *m_outlet[n];
152}
153
154}
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.
Base class for 'flow devices' (valves, pressure regulators, etc.) connecting reactors.
Definition FlowDevice.h:25
void restoreState(const vector< double > &state)
Restore a state saved on a previous call to saveState.
Definition Phase.cpp:283
size_t nSpecies() const
Returns the number of species in the phase.
Definition Phase.h:245
void saveState(vector< double > &state) const
Save the current internal state of the phase.
Definition Phase.cpp:263
virtual double density() const
Density (kg/m^3).
Definition Phase.h:623
virtual double pressure() const
Return the thermodynamic pressure (Pa).
Definition Phase.h:616
Base class for reactor objects.
Definition ReactorBase.h:49
FlowDevice & outlet(size_t n=0)
Return a reference to the n-th outlet FlowDevice connected to this reactor.
shared_ptr< Solution > m_solution
Composite thermo/kinetics/transport handler.
bool m_defaultNameSet
true if default name has been previously set.
WallBase & wall(size_t n)
Return a reference to the n-th Wall connected to this reactor.
virtual void addOutlet(FlowDevice &outlet)
Connect an outlet FlowDevice to this reactor.
double m_pressure
Current pressure in the reactor [Pa].
virtual string type() const
String indicating the reactor model implemented.
Definition ReactorBase.h:74
ReactorNet * m_net
The ReactorNet that this reactor is part of.
virtual void addWall(WallBase &w, int lr)
Insert a Wall between this reactor and another reactor.
void setNetwork(ReactorNet *net)
Set the ReactorNet that this reactor belongs to.
bool setDefaultName(map< string, int > &counts)
Set the default name of a reactor. Returns false if it was previously set.
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...
double m_vol
Current volume of the reactor [m^3].
virtual void addInlet(FlowDevice &inlet)
Connect an inlet FlowDevice to this reactor.
virtual void syncState()
Set the state of the reactor to the associated ThermoPhase object.
double m_mass
Current mass of the reactor [kg].
size_t m_nsp
Number of homogeneous species in the mixture.
string m_name
Reactor name.
double mass() const
Returns the mass (kg) of the reactor's contents.
ReactorBase(shared_ptr< Solution > sol, const string &name="(none)")
Instantiate a ReactorBase object with Solution contents.
virtual void restoreState()
Set the state of the Phase object associated with this reactor to the reactor's current state.
ReactorNet & network()
The ReactorNet that this reactor belongs to.
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.
double m_enthalpy
Current specific enthalpy of the reactor [J/kg].
virtual void addSurface(ReactorSurface *surf)
Add a ReactorSurface object to a Reactor object.
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:331
A surface where reactions can occur that is in contact with the bulk fluid of a Reactor.
double enthalpy_mass() const
Specific enthalpy. Units: J/kg.
Base class for 'walls' (walls, pistons, etc.) connecting reactors.
Definition Wall.h:23
Namespace for the Cantera kernel.
Definition AnyMap.cpp:595