| Cantera 3.0.0

Loading...
Searching...
No Matches
ConstPressureMoleReactor.cpp
Go to the documentation of this file.
1//! @file ConstPressureMoleReactor.cpp A constant pressure
2//! zero-dimensional reactor with moles as the state
3
4// This file is part of Cantera. See License.txt in the top-level directory or
5// at https://cantera.org/license.txt for license and copyright information.
6
7#include "cantera/zeroD/Wall.h"
8#include "cantera/zeroD/ReactorSurface.h"
9#include "cantera/zeroD/FlowDevice.h"
10#include "cantera/zeroD/ConstPressureMoleReactor.h"
11#include "cantera/base/utilities.h"
12#include "cantera/thermo/SurfPhase.h"
13#include "cantera/kinetics/Kinetics.h"
14
15 namespace Cantera
16{
17
18 void ConstPressureMoleReactor::getState(double* y)
19{
20 if (m_thermo == 0) {
21 throw CanteraError("ConstPressureMoleReactor::getState",
22 "Error: reactor is empty.");
23 }
24 m_thermo->restoreState(m_state);
25 // set mass to be used in getMoles function
26 m_mass = m_thermo->density() * m_vol;
27 // set the first array element to enthalpy
28 y[0] = m_thermo->enthalpy_mass() * m_thermo->density() * m_vol;
29 // get moles of species in remaining state
30 getMoles(y + m_sidx);
31 // set the remaining components to the surface species moles on the walls
32 getSurfaceInitialConditions(y+m_nsp+m_sidx);
33}
34
35 void ConstPressureMoleReactor::initialize(double t0)
36{
37 MoleReactor::initialize(t0);
38 m_nv -= 1; // const pressure system loses 1 more variable from MoleReactor
39}
40
41 void ConstPressureMoleReactor::updateState(double* y)
42{
43 // the components of y are: [0] the enthalpy, [1...K+1) are the
44 // moles of each species, and [K+1...] are the moles of surface
45 // species on each wall.
46 setMassFromMoles(y + m_sidx);
47 m_thermo->setMolesNoTruncate(y + m_sidx);
48 if (m_energy) {
49 m_thermo->setState_HP(y[0] / m_mass, m_pressure);
50 } else {
51 m_thermo->setPressure(m_pressure);
52 }
53 m_vol = m_mass / m_thermo->density();
54 updateConnected(false);
55 updateSurfaceState(y + m_nsp + m_sidx);
56}
57
58 void ConstPressureMoleReactor::eval(double time, double* LHS, double* RHS)
59{
60 double* dndt = RHS + m_sidx; // kmol per s
61
62 evalWalls(time);
63
64 m_thermo->restoreState(m_state);
65
66 const vector<double>& imw = m_thermo->inverseMolecularWeights();
67
68 if (m_chem) {
69 m_kin->getNetProductionRates(&m_wdot[0]); // "omega dot"
70 }
71
72 // evaluate reactor surfaces
73 evalSurfaces(LHS + m_nsp + m_sidx, RHS + m_nsp + m_sidx, m_sdot.data());
74
75 // external heat transfer
76 double dHdt = m_Qdot;
77
78 for (size_t n = 0; n < m_nsp; n++) {
79 // production in gas phase and from surfaces
80 dndt[n] = m_wdot[n] * m_vol + m_sdot[n];
81 }
82
83 // add terms for outlets
84 for (auto outlet : m_outlet) {
85 // determine enthalpy contribution
86 dHdt -= outlet->massFlowRate() * m_enthalpy;
87 // flow of species into system and dilution by other species
88 for (size_t n = 0; n < m_nsp; n++) {
89 dndt[n] -= outlet->outletSpeciesMassFlowRate(n) * imw[n];
90 }
91 }
92
93 // add terms for inlets
94 for (auto inlet : m_inlet) {
95 // enthalpy contribution from inlets
96 dHdt += inlet->enthalpy_mass() * inlet->massFlowRate();
97 // flow of species into system and dilution by other species
98 for (size_t n = 0; n < m_nsp; n++) {
99 dndt[n] += inlet->outletSpeciesMassFlowRate(n) * imw[n];
100 }
101 }
102
103 if (m_energy) {
104 RHS[0] = dHdt;
105 } else {
106 RHS[0] = 0.0;
107 }
108}
109
110 size_t ConstPressureMoleReactor::componentIndex(const string& nm) const
111{
112 size_t k = speciesIndex(nm);
113 if (k != npos) {
114 return k + m_sidx;
115 } else if (nm == "enthalpy") {
116 return 0;
117 } else {
118 return npos;
119 }
120}
121
122 string ConstPressureMoleReactor::componentName(size_t k) {
123 if (k == 0) {
124 return "enthalpy";
125 } else if (k >= m_sidx && k < neq()) {
126 k -= m_sidx;
127 if (k < m_thermo->nSpecies()) {
128 return m_thermo->speciesName(k);
129 } else {
130 k -= m_thermo->nSpecies();
131 }
132 for (auto& S : m_surfaces) {
133 ThermoPhase* th = S->thermo();
134 if (k < th->nSpecies()) {
135 return th->speciesName(k);
136 } else {
137 k -= th->nSpecies();
138 }
139 }
140 }
141 throw CanteraError("ConstPressureMoleReactor::componentName",
142 "Index is out of bounds.");
143}
144
145}
ConstPressureMoleReactor.h
FlowDevice.h
Kinetics.h
Base class for kinetics managers and also contains the kineticsmgr module documentation (see Kinetics...
ReactorSurface.h
Header file for class ReactorSurface.
SurfPhase.h
Header for a simple thermodynamics model of a surface phase derived from ThermoPhase,...
Wall.h
Header file for base class WallBase.
Cantera::CanteraError
Base class for exceptions thrown by Cantera classes.
Definition ctexceptions.h:66
Cantera::ConstPressureMoleReactor::eval
void eval(double t, double *LHS, double *RHS) override
Evaluate the reactor governing equations.
Definition ConstPressureMoleReactor.cpp:58
Cantera::ConstPressureMoleReactor::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 ConstPressureMoleReactor.cpp:110
Cantera::ConstPressureMoleReactor::getState
void getState(double *y) override
Get the the current state of the reactor.
Definition ConstPressureMoleReactor.cpp:18
Cantera::ConstPressureMoleReactor::componentName
string componentName(size_t k) override
Return the name of the solution component with index i.
Definition ConstPressureMoleReactor.cpp:122
Cantera::ConstPressureMoleReactor::updateState
void updateState(double *y) override
Set the state of the reactor to correspond to the state vector y.
Definition ConstPressureMoleReactor.cpp:41
Cantera::ConstPressureMoleReactor::initialize
void initialize(double t0=0.0) override
Initialize the reactor.
Definition ConstPressureMoleReactor.cpp:35
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::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::MoleReactor::evalSurfaces
void evalSurfaces(double *LHS, double *RHS, double *sdot) override
Evaluate terms related to surface reactions.
Definition MoleReactor.cpp:61
Cantera::MoleReactor::getSurfaceInitialConditions
void getSurfaceInitialConditions(double *y) override
Get initial conditions for SurfPhase objects attached to this reactor.
Definition MoleReactor.cpp:21
Cantera::MoleReactor::getMoles
void getMoles(double *y)
Get moles of the system from mass fractions stored by thermo object.
Definition MoleReactor.cpp:143
Cantera::MoleReactor::setMassFromMoles
void setMassFromMoles(double *y)
Set internal mass variable based on moles given.
Definition MoleReactor.cpp:153
Cantera::MoleReactor::initialize
void initialize(double t0=0.0) override
Initialize the reactor.
Definition MoleReactor.cpp:38
Cantera::MoleReactor::updateSurfaceState
void updateSurfaceState(double *y) override
Update the state of SurfPhase objects attached to this reactor.
Definition MoleReactor.cpp:44
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::nSpecies
size_t nSpecies() const
Returns the number of species in the phase.
Definition Phase.h:245
Cantera::Phase::setPressure
virtual void setPressure(double p)
Set the internally stored pressure (Pa) at constant temperature and composition.
Definition Phase.h:721
Cantera::Phase::speciesName
string speciesName(size_t k) const
Name of the species with index k.
Definition Phase.cpp:151
Cantera::Phase::inverseMolecularWeights
const vector< double > & inverseMolecularWeights() const
Return a const reference to the internal vector of molecular weights.
Definition Phase.cpp:506
Cantera::Phase::density
virtual double density() const
Density (kg/m^3).
Definition Phase.h:687
Cantera::Phase::setMolesNoTruncate
virtual void setMolesNoTruncate(const double *const N)
Set the state of the object with moles in [kmol].
Definition Phase.cpp:641
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::m_enthalpy
double m_enthalpy
Current specific enthalpy of the reactor [J/kg].
Definition ReactorBase.h:257
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::neq
size_t neq()
Number of equations (state variables) for this reactor.
Definition Reactor.h:103
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::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::setState_HP
virtual void setState_HP(double h, double p, double tol=1e-9)
Set the internally stored specific enthalpy (J/kg) and pressure (Pa) of the phase.
Definition ThermoPhase.cpp:211
Cantera::ThermoPhase::enthalpy_mass
double enthalpy_mass() const
Specific enthalpy. Units: J/kg.
Definition ThermoPhase.h:1043
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...