Cantera  3.1.0a2
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)
17{
18 m_name = name;
19}
20
21ReactorBase::ReactorBase(shared_ptr<Solution> sol, const string& name)
22{
23 m_name = name;
24 setSolution(sol);
25}
26
27ReactorBase::~ReactorBase()
28{
29 if (m_solution) {
30 m_solution->thermo()->removeSpeciesLock();
31 }
32}
33
34void ReactorBase::setSolution(shared_ptr<Solution> sol) {
35 if (!sol || !(sol->thermo())) {
36 throw CanteraError("ReactorBase::setSolution",
37 "Missing or incomplete Solution object.");
38 }
39 if (m_solution) {
40 m_solution->thermo()->removeSpeciesLock();
41 }
42 m_solution = sol;
43 setThermo(*sol->thermo());
44 try {
45 setKinetics(*sol->kinetics());
46 } catch (NotImplementedError&) {
47 // kinetics not used (example: Reservoir)
48 }
49 m_solution->thermo()->addSpeciesLock();
50}
51
52void ReactorBase::insert(shared_ptr<Solution> sol)
53{
54 warn_deprecated("ReactorBase::insert",
55 "To be removed after Cantera 3.1. Superseded by 'setSolution'.");
56 setSolution(sol);
57}
60{
61 m_thermo = &thermo;
62 m_nsp = m_thermo->nSpecies();
63 m_thermo->saveState(m_state);
64 m_enthalpy = m_thermo->enthalpy_mass();
65 m_intEnergy = m_thermo->intEnergy_mass();
66 m_pressure = m_thermo->pressure();
67}
68
70{
71 warn_deprecated("ReactorBase::setThermoMgr",
72 "To be removed after Cantera 3.1. Superseded by 'setSolution'.");
73 setThermo(thermo);
74}
75
77{
78 warn_deprecated("ReactorBase::setKineticsMgr",
79 "To be removed after Cantera 3.1. Superseded by 'setSolution'.");
80 setKinetics(kin);
81}
82
84{
85 m_thermo->saveState(m_state);
86 m_enthalpy = m_thermo->enthalpy_mass();
87 m_intEnergy = m_thermo->intEnergy_mass();
88 m_pressure = m_thermo->pressure();
89 if (m_net) {
91 }
92}
95{
96 m_inlet.push_back(&inlet);
97}
98
100{
101 m_outlet.push_back(&outlet);
102}
103
105{
106 m_wall.push_back(&w);
107 if (lr == 0) {
108 m_lr.push_back(0);
109 } else {
110 m_lr.push_back(1);
111 }
112}
113
115{
116 return *m_wall[n];
117}
118
119void ReactorBase::addSurface(ReactorSurface* surf)
120{
121 if (find(m_surfaces.begin(), m_surfaces.end(), surf) == m_surfaces.end()) {
122 m_surfaces.push_back(surf);
123 surf->setReactor(this);
124 }
125}
126
128{
129 return m_surfaces[n];
130}
131
133 if (!m_thermo) {
134 throw CanteraError("ReactorBase::restoreState", "No phase defined.");
135 }
136 m_thermo->restoreState(m_state);
137}
138
140{
141 if (m_net) {
142 return *m_net;
143 } else {
144 throw CanteraError("ReactorBase::network",
145 "Reactor is not part of a ReactorNet");
146 }
147}
148
150{
151 m_net = net;
152}
153
155{
156 double mout = 0.0;
157 for (size_t i = 0; i < m_outlet.size(); i++) {
158 mout += m_outlet[i]->massFlowRate();
159 }
160 return mass()/mout;
161}
162
164{
165 return *m_inlet[n];
166}
168{
169 return *m_outlet[n];
170}
171
172}
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
An error indicating that an unimplemented function has been called.
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
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.
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].
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.
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.
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].
string name() const
Return the name of this reactor.
Definition ReactorBase.h:70
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:564
void warn_deprecated(const string &source, const AnyBase &node, const string &message)
A deprecation warning for syntax in an input file.
Definition AnyMap.cpp:1926