| Cantera 3.0.0

Loading...
Searching...
No Matches
IdealGasConstPressureReactor.cpp
1//! @file ConstPressureReactor.cpp A constant pressure zero-dimensional reactor
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/IdealGasConstPressureReactor.h"
7#include "cantera/zeroD/FlowDevice.h"
8#include "cantera/zeroD/ReactorNet.h"
9#include "cantera/kinetics/Kinetics.h"
10#include "cantera/thermo/ThermoPhase.h"
11#include "cantera/base/utilities.h"
12
13 namespace Cantera
14{
15
16 void IdealGasConstPressureReactor::setThermoMgr(ThermoPhase& thermo)
17{
18 //! @todo: Add a method to ThermoPhase that indicates whether a given
19 //! subclass is compatible with this reactor model
20 if (thermo.type() != "ideal-gas") {
21 throw CanteraError("IdealGasConstPressureReactor::setThermoMgr",
22 "Incompatible phase type provided");
23 }
24 Reactor::setThermoMgr(thermo);
25}
26
27 void IdealGasConstPressureReactor::getState(double* y)
28{
29 if (m_thermo == 0) {
30 throw CanteraError("IdealGasConstPressureReactor::getState",
31 "Error: reactor is empty.");
32 }
33 m_thermo->restoreState(m_state);
34
35 // set the first component to the total mass
36 y[0] = m_thermo->density() * m_vol;
37
38 // set the second component to the temperature
39 y[1] = m_thermo->temperature();
40
41 // set components y+2 ... y+K+1 to the mass fractions Y_k of each species
42 m_thermo->getMassFractions(y+2);
43
44 // set the remaining components to the surface species
45 // coverages on the walls
46 getSurfaceInitialConditions(y + m_nsp + 2);
47}
48
49 void IdealGasConstPressureReactor::initialize(double t0)
50{
51 ConstPressureReactor::initialize(t0);
52 m_hk.resize(m_nsp, 0.0);
53}
54
55 void IdealGasConstPressureReactor::updateState(double* y)
56{
57 // The components of y are [0] the total mass, [1] the temperature,
58 // [2...K+2) are the mass fractions of each species, and [K+2...] are the
59 // coverages of surface species on each wall.
60 m_mass = y[0];
61 m_thermo->setMassFractions_NoNorm(y+2);
62 m_thermo->setState_TP(y[1], m_pressure);
63 m_vol = m_mass / m_thermo->density();
64 updateConnected(false);
65 updateSurfaceState(y + m_nsp + 2);
66}
67
68 void IdealGasConstPressureReactor::eval(double time, double* LHS, double* RHS)
69{
70 double& dmdt = RHS[0]; // dm/dt (gas phase)
71 double& mcpdTdt = RHS[1]; // m * c_p * dT/dt
72 double* mdYdt = RHS + 2; // mass * dY/dt
73
74 dmdt = 0.0;
75 mcpdTdt = 0.0;
76
77 evalWalls(time);
78
79 m_thermo->restoreState(m_state);
80 const vector<double>& mw = m_thermo->molecularWeights();
81 const double* Y = m_thermo->massFractions();
82
83 evalSurfaces(LHS + m_nsp + 2, RHS + m_nsp + 2, m_sdot.data());
84 double mdot_surf = dot(m_sdot.begin(), m_sdot.end(), mw.begin());
85 dmdt += mdot_surf;
86
87 m_thermo->getPartialMolarEnthalpies(&m_hk[0]);
88
89 if (m_chem) {
90 m_kin->getNetProductionRates(&m_wdot[0]); // "omega dot"
91 }
92
93 // external heat transfer
94 mcpdTdt += m_Qdot;
95
96 for (size_t n = 0; n < m_nsp; n++) {
97 // heat release from gas phase and surface reactions
98 mcpdTdt -= m_wdot[n] * m_hk[n] * m_vol;
99 mcpdTdt -= m_sdot[n] * m_hk[n];
100 // production in gas phase and from surfaces
101 mdYdt[n] = (m_wdot[n] * m_vol + m_sdot[n]) * mw[n];
102 // dilution by net surface mass flux
103 mdYdt[n] -= Y[n] * mdot_surf;
104 //Assign left-hand side of dYdt ODE as total mass
105 LHS[n+2] = m_mass;
106 }
107
108 // add terms for outlets
109 for (auto outlet : m_outlet) {
110 dmdt -= outlet->massFlowRate(); // mass flow out of system
111 }
112
113 // add terms for inlets
114 for (auto inlet : m_inlet) {
115 double mdot = inlet->massFlowRate();
116 dmdt += mdot; // mass flow into system
117 mcpdTdt += inlet->enthalpy_mass() * mdot;
118 for (size_t n = 0; n < m_nsp; n++) {
119 double mdot_spec = inlet->outletSpeciesMassFlowRate(n);
120 // flow of species into system and dilution by other species
121 mdYdt[n] += mdot_spec - mdot * Y[n];
122 mcpdTdt -= m_hk[n] / mw[n] * mdot_spec;
123 }
124 }
125
126 if (m_energy) {
127 LHS[1] = m_mass * m_thermo->cp_mass();
128 } else {
129 RHS[1] = 0.0;
130 }
131}
132
133 size_t IdealGasConstPressureReactor::componentIndex(const string& nm) const
134{
135 size_t k = speciesIndex(nm);
136 if (k != npos) {
137 return k + 2;
138 } else if (nm == "mass") {
139 return 0;
140 } else if (nm == "temperature") {
141 return 1;
142 } else {
143 return npos;
144 }
145}
146
147 string IdealGasConstPressureReactor::componentName(size_t k) {
148 if (k == 1) {
149 return "temperature";
150 } else {
151 return ConstPressureReactor::componentName(k);
152 }
153}
154
155}
FlowDevice.h
Kinetics.h
Base class for kinetics managers and also contains the kineticsmgr module documentation (see Kinetics...
ReactorNet.h
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::ConstPressureReactor::componentName
string componentName(size_t k) override
Return the name of the solution component with index i.
Definition ConstPressureReactor.cpp:135
Cantera::ConstPressureReactor::initialize
void initialize(double t0=0.0) override
Initialize the reactor.
Definition ConstPressureReactor.cpp:39
Cantera::FlowDevice::outletSpeciesMassFlowRate
double outletSpeciesMassFlowRate(size_t k)
Mass flow rate (kg/s) of outlet species k.
Definition FlowDevice.cpp:72
Cantera::FlowDevice::enthalpy_mass
double enthalpy_mass()
specific enthalpy
Definition FlowDevice.cpp:84
Cantera::FlowDevice::massFlowRate
double massFlowRate()
Mass flow rate (kg/s).
Definition FlowDevice.h:39
Cantera::IdealGasConstPressureReactor::setThermoMgr
void setThermoMgr(ThermoPhase &thermo) override
Specify the mixture contained in the reactor.
Definition IdealGasConstPressureReactor.cpp:16
Cantera::IdealGasConstPressureReactor::eval
void eval(double t, double *LHS, double *RHS) override
Evaluate the reactor governing equations.
Definition IdealGasConstPressureReactor.cpp:68
Cantera::IdealGasConstPressureReactor::componentIndex
size_t componentIndex(const string &nm) const override
Return the index in the solution vector for this reactor of the component named nm.
Definition IdealGasConstPressureReactor.cpp:133
Cantera::IdealGasConstPressureReactor::getState
void getState(double *y) override
Get the the current state of the reactor.
Definition IdealGasConstPressureReactor.cpp:27
Cantera::IdealGasConstPressureReactor::componentName
string componentName(size_t k) override
Return the name of the solution component with index i.
Definition IdealGasConstPressureReactor.cpp:147
Cantera::IdealGasConstPressureReactor::updateState
void updateState(double *y) override
Set the state of the reactor to correspond to the state vector y.
Definition IdealGasConstPressureReactor.cpp:55
Cantera::IdealGasConstPressureReactor::initialize
void initialize(double t0=0.0) override
Initialize the reactor.
Definition IdealGasConstPressureReactor.cpp:49
Cantera::IdealGasConstPressureReactor::m_hk
vector< double > m_hk
Species molar enthalpies.
Definition IdealGasConstPressureReactor.h:48
Cantera::Kinetics::getNetProductionRates
virtual void getNetProductionRates(double *wdot)
Species net production rates [kmol/m^3/s or kmol/m^2/s].
Definition Kinetics.cpp:435
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::setMassFractions_NoNorm
virtual void setMassFractions_NoNorm(const double *const y)
Set the mass fractions to the specified values without normalizing.
Definition Phase.cpp:370
Cantera::Phase::temperature
double temperature() const
Temperature (K).
Definition Phase.h:662
Cantera::Phase::massFractions
const double * massFractions() const
Return a const pointer to the mass fraction array.
Definition Phase.h:535
Cantera::Phase::molecularWeights
const vector< double > & molecularWeights() const
Return a const reference to the internal vector of molecular weights.
Definition Phase.cpp:501
Cantera::Phase::density
virtual double density() const
Density (kg/m^3).
Definition Phase.h:687
Cantera::Phase::getMassFractions
void getMassFractions(double *const y) const
Get the species mass fractions.
Definition Phase.cpp:584
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::m_pressure
double m_pressure
Current pressure in the reactor [Pa].
Definition ReactorBase.h:259
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_vol
double m_vol
Current volume of the reactor [m^3].
Definition ReactorBase.h:256
Cantera::ReactorBase::m_nsp
size_t m_nsp
Number of homogeneous species in the mixture.
Definition ReactorBase.h:253
Cantera::ReactorBase::setThermoMgr
virtual void setThermoMgr(ThermoPhase &thermo)
Specify the mixture contained in the reactor.
Definition ReactorBase.cpp:20
Cantera::Reactor::evalSurfaces
virtual void evalSurfaces(double *LHS, double *RHS, double *sdot)
Evaluate terms related to surface reactions.
Definition Reactor.cpp:287
Cantera::Reactor::updateSurfaceState
virtual void updateSurfaceState(double *y)
Update the state of SurfPhase objects attached to this reactor.
Definition Reactor.cpp:175
Cantera::Reactor::m_kin
Kinetics * m_kin
Pointer to the homogeneous Kinetics object that handles the reactions.
Definition Reactor.h:277
Cantera::Reactor::m_wdot
vector< double > m_wdot
Species net molar production rates.
Definition Reactor.h:289
Cantera::Reactor::evalWalls
virtual void evalWalls(double t)
Evaluate terms related to Walls.
Definition Reactor.cpp:275
Cantera::Reactor::m_Qdot
double m_Qdot
net heat transfer into the reactor, through walls [W]
Definition Reactor.h:281
Cantera::Reactor::m_mass
double m_mass
total mass
Definition Reactor.h:283
Cantera::Reactor::m_sdot
vector< double > m_sdot
Production rates of gas phase species on surfaces [kmol/s].
Definition Reactor.h:287
Cantera::Reactor::getSurfaceInitialConditions
virtual void getSurfaceInitialConditions(double *y)
Get initial conditions for SurfPhase objects attached to this reactor.
Definition Reactor.cpp:75
Cantera::Reactor::speciesIndex
virtual size_t speciesIndex(const string &nm) const
Return the index in the solution vector for this reactor of the species named nm, in either the homog...
Definition Reactor.cpp:430
Cantera::Reactor::updateConnected
virtual void updateConnected(bool updatePressure)
Update the state information needed by connected reactors, flow devices, and reactor walls.
Definition Reactor.cpp:184
Cantera::ThermoPhase
Base class for a phase with thermodynamic properties.
Definition ThermoPhase.h:390
Cantera::ThermoPhase::getPartialMolarEnthalpies
virtual void getPartialMolarEnthalpies(double *hbar) const
Returns an array of partial molar enthalpies for the species in the mixture.
Definition ThermoPhase.h:816
Cantera::ThermoPhase::setState_TP
virtual void setState_TP(double t, double p)
Set the temperature (K) and pressure (Pa)
Definition ThermoPhase.cpp:121
Cantera::ThermoPhase::type
string type() const override
String indicating the thermodynamic model implemented.
Definition ThermoPhase.h:399
Cantera::ThermoPhase::cp_mass
double cp_mass() const
Specific heat at constant pressure. Units: J/kg/K.
Definition ThermoPhase.h:1063
Cantera::dot
double dot(InputIter x_begin, InputIter x_end, InputIter2 y_begin)
Function that calculates a templated inner product.
Definition utilities.h:82
Cantera
Namespace for the Cantera kernel.
Definition AnyMap.cpp:564
Cantera::npos
const size_t npos
index returned by functions to indicate "no position"
Definition ct_defs.h:195
utilities.h
Various templated functions that carry out common vector and polynomial operations (see Templated Arr...