Cantera  3.1.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)
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
27void ReactorBase::setSolution(shared_ptr<Solution> sol) {
28 m_solution = sol;
29 setThermoMgr(*sol->thermo());
30 try {
31 setKineticsMgr(*sol->kinetics());
32 } catch (NotImplementedError&) {
33 // kinetics not used (example: Reservoir)
34 }
35}
36
37void ReactorBase::insert(shared_ptr<Solution> sol)
38{
39 warn_deprecated("ReactorBase::insert",
40 "To be removed after Cantera 3.1. Superseded by 'setSolution'.");
41 setSolution(sol);
42}
43
45{
46 m_thermo = &thermo;
47 m_nsp = m_thermo->nSpecies();
48 m_thermo->saveState(m_state);
49 m_enthalpy = m_thermo->enthalpy_mass();
50 m_intEnergy = m_thermo->intEnergy_mass();
51 m_pressure = m_thermo->pressure();
52}
53
55{
56 m_thermo->saveState(m_state);
57 m_enthalpy = m_thermo->enthalpy_mass();
59 m_pressure = m_thermo->pressure();
60 if (m_net) {
62 }
63}
64
66{
67 m_inlet.push_back(&inlet);
68}
69
71{
72 m_outlet.push_back(&outlet);
73}
74
76{
77 m_wall.push_back(&w);
78 if (lr == 0) {
79 m_lr.push_back(0);
80 } else {
81 m_lr.push_back(1);
82 }
83}
84
86{
87 return *m_wall[n];
88}
89
90void ReactorBase::addSurface(ReactorSurface* surf)
91{
92 if (find(m_surfaces.begin(), m_surfaces.end(), surf) == m_surfaces.end()) {
93 m_surfaces.push_back(surf);
94 surf->setReactor(this);
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 if (m_net) {
113 return *m_net;
114 } else {
115 throw CanteraError("ReactorBase::network",
116 "Reactor is not part of a ReactorNet");
117 }
118}
119
121{
122 m_net = net;
123}
124
126{
127 double mout = 0.0;
128 for (size_t i = 0; i < m_outlet.size(); i++) {
129 mout += m_outlet[i]->massFlowRate();
130 }
131 return mass()/mout;
132}
133
135{
136 return *m_inlet[n];
137}
139{
140 return *m_outlet[n];
141}
142
143}
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
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 setKineticsMgr(Kinetics &kin)
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.
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.
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.
virtual 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