Cantera  2.4.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 http://www.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("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 }
const vector_fp & molecularWeights() const
Return a const reference to the internal vector of molecular weights.
Definition: Phase.cpp:437
void restoreState(const vector_fp &state)
Restore a state saved on a previous call to saveState.
Definition: Phase.cpp:233
void getMassFractions(doublereal *const y) const
Get the species mass fractions.
Definition: Phase.cpp:508
virtual void getState(doublereal *y)
Get the the current state of the reactor.
Definition: FlowReactor.cpp:26
size_t speciesIndex(const std::string &name) const
Returns the index of a species named &#39;name&#39; within the Phase object.
Definition: Phase.cpp:175
void saveState(vector_fp &state) const
Save the current internal state of the phase.
Definition: Phase.cpp:221
const size_t npos
index returned by functions to indicate "no position"
Definition: ct_defs.h:165
virtual void updateState(doublereal *y)
Set the state of the reactor to correspond to the state vector y.
Definition: FlowReactor.cpp:46
virtual void resetSensitivity(double *params)
Reset the reaction rate multipliers.
Definition: Reactor.cpp:411
STL namespace.
virtual doublereal density() const
Density (kg/m^3).
Definition: Phase.h:607
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.
This file contains definitions for utility functions and text for modules, inputfiles, logs, textlogs, (see Input File Handling, Diagnostic Output, and Writing messages to the screen).
virtual void getNetProductionRates(doublereal *wdot)
Species net production rates [kmol/m^3/s or kmol/m^2/s].
Definition: Kinetics.cpp:418
Kinetics * m_kin
Pointer to the homogeneous Kinetics object that handles the reactions.
Definition: Reactor.h:167
virtual void evalEqs(doublereal t, doublereal *y, doublereal *ydot, doublereal *params)
Definition: FlowReactor.cpp:69
virtual void applySensitivity(double *params)
Set reaction rate multipliers based on the sensitivity variables in params.
Definition: Reactor.cpp:389
Base class for exceptions thrown by Cantera classes.
Definition: ctexceptions.h:65
virtual void setState_TP(doublereal t, doublereal p)
Set the temperature (K) and pressure (Pa)
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: FlowReactor.cpp:96
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:157
size_t m_nsp
Number of homogeneous species in the mixture.
Definition: ReactorBase.h:233
virtual void setMassFractions(const doublereal *const y)
Set the mass fractions to the specified values and normalize them.
Definition: Phase.cpp:311
Namespace for the Cantera kernel.
Definition: AnyMap.cpp:8
virtual void initialize(doublereal t0=0.0)
Initialize the reactor.
Definition: FlowReactor.cpp:40