Cantera 2.6.0

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