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