Cantera  3.1.0b1
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(name)
22{
23 if (!sol || !(sol->thermo())) {
24 warn_deprecated("ReactorBase::ReactorBase",
25 "Creation of empty reactor objects is deprecated in Cantera 3.1 and will "
26 "raise\nexceptions thereafter; reactor contents should be provided in the "
27 "constructor.");
28 return;
29 }
30 setSolution(sol);
31}
32
33ReactorBase::~ReactorBase()
34{
35 if (m_solution) {
36 m_solution->thermo()->removeSpeciesLock();
37 }
38}
39
40bool ReactorBase::setDefaultName(map<string, int>& counts)
41{
42 if (m_defaultNameSet) {
43 return false;
44 }
45 m_defaultNameSet = true;
46 if (m_name == "(none)" || m_name == "") {
47 m_name = fmt::format("{}_{}", type(), counts[type()]);
48 }
49 counts[type()]++;
50 return true;
51}
52
53void ReactorBase::setSolution(shared_ptr<Solution> sol) {
54 if (!sol || !(sol->thermo())) {
55 throw CanteraError("ReactorBase::setSolution",
56 "Missing or incomplete Solution object.");
57 }
58 if (m_solution) {
59 m_solution->thermo()->removeSpeciesLock();
60 }
61 m_solution = sol;
62 setThermo(*sol->thermo());
63 try {
64 setKinetics(*sol->kinetics());
65 } catch (NotImplementedError&) {
66 // kinetics not used (example: Reservoir)
67 }
68 m_solution->thermo()->addSpeciesLock();
69}
70
71void ReactorBase::insert(shared_ptr<Solution> sol)
72{
73 warn_deprecated("ReactorBase::insert",
74 "To be removed after Cantera 3.1. Superseded by 'setSolution'.");
75 setSolution(sol);
76}
77
79{
80 m_thermo = &thermo;
81 m_nsp = m_thermo->nSpecies();
82 m_thermo->saveState(m_state);
83 m_enthalpy = m_thermo->enthalpy_mass();
84 m_intEnergy = m_thermo->intEnergy_mass();
85 m_pressure = m_thermo->pressure();
86}
87
89{
90 warn_deprecated("ReactorBase::setThermoMgr",
91 "To be removed after Cantera 3.1. Superseded by 'setSolution'.");
92 setThermo(thermo);
93}
96{
97 warn_deprecated("ReactorBase::setKineticsMgr",
98 "To be removed after Cantera 3.1. Superseded by 'setSolution'.");
99 setKinetics(kin);
100}
101
103{
104 m_thermo->saveState(m_state);
105 m_enthalpy = m_thermo->enthalpy_mass();
106 m_intEnergy = m_thermo->intEnergy_mass();
107 m_pressure = m_thermo->pressure();
108 if (m_net) {
110 }
111}
112
114{
115 m_inlet.push_back(&inlet);
116}
117
119{
120 m_outlet.push_back(&outlet);
121}
122
124{
125 m_wall.push_back(&w);
126 if (lr == 0) {
127 m_lr.push_back(0);
128 } else {
129 m_lr.push_back(1);
130 }
131}
132
134{
135 return *m_wall[n];
136}
137
138void ReactorBase::addSurface(ReactorSurface* surf)
139{
140 if (find(m_surfaces.begin(), m_surfaces.end(), surf) == m_surfaces.end()) {
141 m_surfaces.push_back(surf);
142 surf->setReactor(this);
143 }
144}
145
147{
148 return m_surfaces[n];
149}
150
152 if (!m_thermo) {
153 throw CanteraError("ReactorBase::restoreState", "No phase defined.");
154 }
155 m_thermo->restoreState(m_state);
156}
157
159{
160 if (m_net) {
161 return *m_net;
162 } else {
163 throw CanteraError("ReactorBase::network",
164 "Reactor is not part of a ReactorNet");
165 }
166}
167
169{
170 m_net = net;
171}
172
174{
175 double mout = 0.0;
176 for (size_t i = 0; i < m_outlet.size(); i++) {
177 mout += m_outlet[i]->massFlowRate();
178 }
179 return mass()/mout;
180}
181
183{
184 return *m_inlet[n];
185}
187{
188 return *m_outlet[n];
189}
190
191}
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:24
Public interface for kinetics managers.
Definition Kinetics.h:125
void restoreState(const vector< double > &state)
Restore a state saved on a previous call to saveState.
Definition Phase.cpp:260
size_t nSpecies() const
Returns the number of species in the phase.
Definition Phase.h:231
void saveState(vector< double > &state) const
Save the current internal state of the phase.
Definition Phase.cpp:236
virtual double pressure() const
Return the thermodynamic pressure (Pa).
Definition Phase.h:580
Base class for stirred reactors.
Definition ReactorBase.h:49
virtual void setThermo(ThermoPhase &thermo)
Specify the mixture contained in the reactor.
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.
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:63
ReactorNet * m_net
The ReactorNet that this reactor is part of.
void insert(shared_ptr< Solution > sol)
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.
virtual void setKinetics(Kinetics &kin)
Specify the kinetics manager for the reactor.
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...
void addInlet(FlowDevice &inlet)
Connect an inlet FlowDevice to this reactor.
void setSolution(shared_ptr< Solution > sol)
Set the Solution specifying the ReactorBase content.
void setKineticsMgr(Kinetics &kin)
virtual void syncState()
Set the state of the reactor to correspond to the state of the associated ThermoPhase object.
double m_intEnergy
Current internal energy of the reactor [J/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.
void setThermoMgr(ThermoPhase &thermo)
Specify the mixture contained in the reactor.
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].
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:272
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.
double intEnergy_mass() const
Specific internal energy. Units: J/kg.
double enthalpy_mass() const
Specific enthalpy. Units: J/kg.
Base class for 'walls' (walls, pistons, etc.) connecting reactors.
Definition Wall.h:22
Namespace for the Cantera kernel.
Definition AnyMap.cpp:595
void warn_deprecated(const string &source, const AnyBase &node, const string &message)
A deprecation warning for syntax in an input file.
Definition AnyMap.cpp:1997