Cantera 2.6.0
FlowReactor.cpp
Go to the documentation of this file.
1//! @file FlowReactor.cpp A steady-state plug flow 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
10
11using namespace std;
12
13namespace Cantera
14{
15
16FlowReactor::FlowReactor() :
17 m_speed(0.0),
18 m_dist(0.0),
19 m_T(0.0),
20 m_fctr(1.0e10),
21 m_rho0(0.0),
22 m_speed0(0.0),
23 m_P0(0.0),
24 m_h0(0.0)
25{
26}
27
28void FlowReactor::getState(double* y)
29{
30 if (m_thermo == 0) {
31 throw CanteraError("FlowReactor::getState",
32 "Error: reactor is empty.");
33 }
34 m_thermo->restoreState(m_state);
35 m_thermo->getMassFractions(y+2);
36 y[0] = 0.0; // distance
37
38 // set the second component to the initial speed
39 y[1] = m_speed0;
40}
41
42void FlowReactor::initialize(doublereal t0)
43{
44 m_thermo->restoreState(m_state);
45 m_nv = m_nsp + 2;
46}
47
48void FlowReactor::updateState(doublereal* y)
49{
50 // Set the mass fractions and density of the mixture.
51 m_dist = y[0];
52 m_speed = y[1];
53 doublereal* mss = y + 2;
54 m_thermo->setMassFractions(mss);
55 doublereal rho = m_rho0 * m_speed0/m_speed;
56
57 // assumes frictionless
58 doublereal pmom = m_P0 - rho*m_speed*m_speed;
59
60 doublereal hmom;
61 // assumes adiabatic
62 if (m_energy) {
63 hmom = m_h0 - 0.5*m_speed*m_speed;
64 m_thermo->setState_HP(hmom, pmom);
65 } else {
66 m_thermo->setState_TP(m_T, pmom);
67 }
68 m_thermo->saveState(m_state);
69}
70
71void FlowReactor::setMassFlowRate(double mdot)
72{
73 m_rho0 = m_thermo->density();
74 m_speed = mdot/m_rho0;
75 m_speed0 = m_speed;
76 m_T = m_thermo->temperature();
77 m_P0 = m_thermo->pressure() + m_rho0*m_speed*m_speed;
78 m_h0 = m_thermo->enthalpy_mass() + 0.5*m_speed*m_speed;
79}
80
81void FlowReactor::eval(double time, double* LHS, double* RHS)
82{
83 m_thermo->restoreState(m_state);
84
85 // distance equation
86 RHS[0] = m_speed;
87
88 // speed equation. Set m_fctr to a large value, so that rho*u is held fixed
89 RHS[1] = m_fctr * (m_speed0 - m_thermo->density() * m_speed / m_rho0);
90
91 // species equations //
92 const vector_fp& mw = m_thermo->molecularWeights();
93
94 if (m_chem) {
95 m_kin->getNetProductionRates(RHS + 2); // "omega dot"
96 } else {
97 fill(RHS + 2, RHS + 2 + m_nsp, 0.0);
98 }
99 double rrho = 1.0 / m_thermo->density();
100 for (size_t n = 0; n < m_nsp; n++) {
101 RHS[n+2] *= mw[n] * rrho;
102 }
103}
104
105size_t FlowReactor::componentIndex(const string& nm) const
106{
107 // check for a gas species name
108 size_t k = m_thermo->speciesIndex(nm);
109 if (k != npos) {
110 return k + 2;
111 } else if (nm == "X" || nm == "distance") {
112 return 0;
113 } else if (nm == "U" || nm == "velocity") {
114 return 1;
115 } else {
116 return npos;
117 }
118}
119
120}
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.
Definition: ctexceptions.h:61
This file contains definitions for utility functions and text for modules, inputfiles,...
Namespace for the Cantera kernel.
Definition: AnyMap.h:29
const size_t npos
index returned by functions to indicate "no position"
Definition: ct_defs.h:192
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