Cantera  4.0.0a1
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"
12
13namespace Cantera
14{
15
17{
18 // set the first component to the total mass
19 y[0] = m_thermo->density() * m_vol;
20
21 // set the second component to the temperature
22 y[1] = m_thermo->temperature();
23
24 // set components y+2 ... y+K+1 to the mass fractions Y_k of each species
25 m_thermo->getMassFractions(y.subspan(2, m_nsp));
26}
27
29{
30 //! @todo: Add a method to ThermoPhase that indicates whether a given
31 //! subclass is compatible with this reactor model
32 if (m_thermo->type() != "ideal-gas" && m_thermo->type() != "plasma") {
33 throw CanteraError("IdealGasConstPressureReactor::initialize",
34 "Incompatible phase type '{}' provided", m_thermo->type());
35 }
37 m_hk.resize(m_nsp, 0.0);
38}
39
41{
42 // The components of y are [0] the total mass, [1] the temperature,
43 // [2...K+2) are the mass fractions of each species, and [K+2...] are the
44 // coverages of surface species on each wall.
45 m_mass = y[0];
46 m_thermo->setMassFractions_NoNorm(y.subspan(2, m_nsp));
47 m_thermo->setState_TP(y[1], m_pressure);
48 m_vol = m_mass / m_thermo->density();
49 updateConnected(false);
50}
51
52void IdealGasConstPressureReactor::eval(double time, span<double> LHS, span<double> RHS)
53{
54 double& dmdt = RHS[0]; // dm/dt (gas phase)
55 double& mcpdTdt = RHS[1]; // m * c_p * dT/dt
56 auto mdYdt = RHS.subspan(2); // mass * dY/dt
57
58 dmdt = 0.0;
59 mcpdTdt = 0.0;
60
61 evalWalls(time);
63 auto mw = m_thermo->molecularWeights();
64 auto Y = m_thermo->massFractions();
65 double mdot_surf = dot(m_sdot.begin(), m_sdot.end(), mw.begin());
66 dmdt += mdot_surf;
67
69
70 if (m_chem) {
71 m_kin->getNetProductionRates(m_wdot); // "omega dot"
72 }
73
74 // external heat transfer
75 mcpdTdt += m_Qdot;
76
77 if (m_energy) {
78 mcpdTdt += m_thermo->intrinsicHeating() * m_vol;
79 }
80
81 for (size_t n = 0; n < m_nsp; n++) {
82 // heat release from gas phase and surface reactions
83 mcpdTdt -= m_wdot[n] * m_hk[n] * m_vol;
84 mcpdTdt -= m_sdot[n] * m_hk[n];
85 // production in gas phase and from surfaces
86 mdYdt[n] = (m_wdot[n] * m_vol + m_sdot[n]) * mw[n];
87 // dilution by net surface mass flux
88 mdYdt[n] -= Y[n] * mdot_surf;
89 //Assign left-hand side of dYdt ODE as total mass
90 LHS[n+2] = m_mass;
91 }
92
93 // add terms for outlets
94 for (auto outlet : m_outlet) {
95 dmdt -= outlet->massFlowRate(); // mass flow out of system
96 }
97
98 // add terms for inlets
99 for (auto inlet : m_inlet) {
100 double mdot = inlet->massFlowRate();
101 dmdt += mdot; // mass flow into system
102 mcpdTdt += inlet->enthalpy_mass() * mdot;
103 for (size_t n = 0; n < m_nsp; n++) {
104 double mdot_spec = inlet->outletSpeciesMassFlowRate(n);
105 // flow of species into system and dilution by other species
106 mdYdt[n] += mdot_spec - mdot * Y[n];
107 mcpdTdt -= m_hk[n] / mw[n] * mdot_spec;
108 }
109 }
110
111 if (m_energy) {
112 LHS[1] = m_mass * m_thermo->cp_mass();
113 } else {
114 RHS[1] = 0.0;
115 }
116}
117
118void IdealGasConstPressureReactor::evalSteady(double t, span<double> LHS,
119 span<double> RHS)
120{
121 eval(0.0, LHS, RHS);
122 RHS[0] = m_mass - m_initialMass;
123 if (!energyEnabled()) {
124 RHS[1] = m_thermo->temperature() - m_initialTemperature;
125 }
126}
127
129{
131 m_initialTemperature = m_thermo->temperature();
132 if (energyEnabled()) {
133 return {0}; // mass
134 } else {
135 return {0, 1}; // mass and temperature
136 }
137}
138
140{
141 if (nm == "mass") {
142 return 0;
143 }
144 if (nm == "temperature") {
145 return 1;
146 }
147 try {
148 return m_thermo->speciesIndex(nm) + 2;
149 } catch (const CanteraError&) {
150 throw CanteraError("IdealGasConstPressureReactor::componentIndex",
151 "Component '{}' not found", nm);
152 }
153}
154
156 if (k == 1) {
157 return "temperature";
158 } else {
160 }
161}
162
164{
165 if (k == 1) {
166 //@todo: Revise pending resolution of https://github.com/Cantera/enhancements/issues/229
167 return 1.5 * m_thermo->maxTemp();
168 } else {
170 }
171}
172
174{
175 if (k == 1) {
176 //@todo: Revise pending resolution of https://github.com/Cantera/enhancements/issues/229
177 return 0.5 * m_thermo->minTemp();
178 } else {
180 }
181}
182
183}
Base class for kinetics managers and also contains the kineticsmgr module documentation (see Kinetics...
Header file for class ThermoPhase, the base class for phases with thermodynamic properties,...
Base class for exceptions thrown by Cantera classes.
double upperBound(size_t k) const override
Get the upper bound on the k-th component of the local state vector.
double lowerBound(size_t k) const override
Get the lower bound on the k-th component of the local state vector.
string componentName(size_t k) override
Return the name of the solution component with index i.
double outletSpeciesMassFlowRate(size_t k)
Mass flow rate (kg/s) of outlet species k.
double enthalpy_mass()
specific enthalpy
double massFlowRate()
Mass flow rate (kg/s).
Definition FlowDevice.h:36
double upperBound(size_t k) const override
Get the upper bound on the k-th component of the local state vector.
void eval(double t, span< double > LHS, span< double > RHS) override
Evaluate the reactor governing equations.
void evalSteady(double t, span< double > LHS, span< double > RHS) override
Evaluate the governing equations with modifications for the steady-state solver.
size_t componentIndex(const string &nm) const override
Return the index in the solution vector for this reactor of the component named nm.
double m_initialMass
Initial mass [kg]; used for steady-state calculations.
vector< size_t > initializeSteady() override
Initialize the reactor before solving a steady-state problem.
double lowerBound(size_t k) const override
Get the lower bound on the k-th component of the local state vector.
string componentName(size_t k) override
Return the name of the solution component with index i.
void initialize(double t0=0.0) override
Initialize the reactor.
double m_initialTemperature
Initial temperature [K]; used for steady-state calculations.
void updateState(span< const double > y) override
Set the state of the reactor to correspond to the state vector y.
vector< double > m_hk
Species molar enthalpies.
void getState(span< double > y) override
Get the current state of the reactor.
virtual void getNetProductionRates(span< double > wdot)
Species net production rates [kmol/m^3/s or kmol/m^2/s].
Definition Kinetics.cpp:447
void getMassFractions(span< double > y) const
Get the species mass fractions.
Definition Phase.cpp:479
size_t speciesIndex(const string &name, bool raise=true) const
Returns the index of a species named 'name' within the Phase object.
Definition Phase.cpp:127
span< const double > molecularWeights() const
Return a const reference to the internal vector of molecular weights.
Definition Phase.cpp:401
double temperature() const
Temperature (K).
Definition Phase.h:585
span< const double > massFractions() const
Return a view of the mass fraction array.
Definition Phase.h:465
virtual double density() const
Density (kg/m^3).
Definition Phase.h:610
virtual void setMassFractions_NoNorm(span< const double > y)
Set the mass fractions to the specified values without normalizing.
Definition Phase.cpp:352
FlowDevice & outlet(size_t n=0)
Return a reference to the n-th outlet FlowDevice connected to this reactor.
double m_pressure
Current pressure in the reactor [Pa].
FlowDevice & inlet(size_t n=0)
Return a reference to the n-th inlet FlowDevice connected to this reactor.
double m_vol
Current volume of the reactor [m^3].
double m_mass
Current mass of the reactor [kg].
size_t m_nsp
Number of homogeneous species in the mixture.
virtual void updateConnected(bool updatePressure)
Update state information needed by connected reactors, flow devices, and walls.
void evalWalls(double t) override
Evaluate terms related to Walls.
Definition Reactor.cpp:194
Kinetics * m_kin
Pointer to the homogeneous Kinetics object that handles the reactions.
Definition Reactor.h:147
vector< double > m_wdot
Species net molar production rates.
Definition Reactor.h:151
bool energyEnabled() const override
Returns true if solution of the energy equation is enabled.
Definition Reactor.h:79
double m_Qdot
net heat transfer into the reactor, through walls [W]
Definition Reactor.h:150
void updateSurfaceProductionRates()
Update m_sdot to reflect current production rates of bulk phase species due to reactions on adjacent ...
Definition Reactor.cpp:291
vector< double > m_sdot
Total production rate of bulk phase species on surfaces [kmol/s].
Definition Reactor.h:155
void initialize(double t0=0.0) override
Initialize the reactor.
Definition Reactor.cpp:63
virtual void getPartialMolarEnthalpies(span< double > hbar) const
Returns an array of partial molar enthalpies for the species in the mixture.
virtual void setState_TP(double t, double p)
Set the temperature (K) and pressure (Pa)
virtual double minTemp(size_t k=npos) const
Minimum temperature for which the thermodynamic data for the species or phase are valid.
string type() const override
String indicating the thermodynamic model implemented.
virtual double maxTemp(size_t k=npos) const
Maximum temperature for which the thermodynamic data for the species are valid.
virtual double intrinsicHeating()
Intrinsic volumetric heating rate [W/m³].
double cp_mass() const
Specific heat at constant pressure and composition [J/kg/K].
double dot(InputIter x_begin, InputIter x_end, InputIter2 y_begin)
Function that calculates a templated inner product.
Definition utilities.h:96
Namespace for the Cantera kernel.
Definition AnyMap.cpp:595
Various templated functions that carry out common vector and polynomial operations (see Templated Arr...