Cantera  2.3.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::getInitialConditions(double t0, size_t leny, double* y)
27 {
28  warn_deprecated("FlowReactor::getInitialConditions",
29  "Use getState instead. To be removed after Cantera 2.3.");
30  getState(y);
31 }
32 
33 void FlowReactor::getState(double* y)
34 {
35  if (m_thermo == 0) {
36  throw CanteraError("getState",
37  "Error: reactor is empty.");
38  }
39  m_thermo->restoreState(m_state);
40  m_thermo->getMassFractions(y+2);
41  y[0] = 0.0; // distance
42 
43  // set the second component to the initial speed
44  y[1] = m_speed0;
45 }
46 
47 void FlowReactor::initialize(doublereal t0)
48 {
49  m_thermo->restoreState(m_state);
50  m_nv = m_nsp + 2;
51 }
52 
53 void FlowReactor::updateState(doublereal* y)
54 {
55  // Set the mass fractions and density of the mixture.
56  m_dist = y[0];
57  m_speed = y[1];
58  doublereal* mss = y + 2;
59  m_thermo->setMassFractions(mss);
60  doublereal rho = m_rho0 * m_speed0/m_speed;
61 
62  // assumes frictionless
63  doublereal pmom = m_P0 - rho*m_speed*m_speed;
64 
65  doublereal hmom;
66  // assumes adiabatic
67  if (m_energy) {
68  hmom = m_h0 - 0.5*m_speed*m_speed;
69  m_thermo->setState_HP(hmom, pmom);
70  } else {
71  m_thermo->setState_TP(m_T, pmom);
72  }
73  m_thermo->saveState(m_state);
74 }
75 
76 void FlowReactor::evalEqs(doublereal time, doublereal* y,
77  doublereal* ydot, doublereal* params)
78 {
79  m_thermo->restoreState(m_state);
80  applySensitivity(params);
81 
82  // distance equation
83  ydot[0] = m_speed;
84 
85  // speed equation. Set m_fctr to a large value, so that rho*u is held fixed
86  ydot[1] = m_fctr*(m_speed0 - m_thermo->density()*m_speed/m_rho0);
87 
88  // species equations //
89  const vector_fp& mw = m_thermo->molecularWeights();
90 
91  if (m_chem) {
92  m_kin->getNetProductionRates(ydot+2); // "omega dot"
93  } else {
94  fill(ydot + 2, ydot + 2 + m_nsp, 0.0);
95  }
96  doublereal rrho = 1.0/m_thermo->density();
97  for (size_t n = 0; n < m_nsp; n++) {
98  ydot[n+2] *= mw[n]*rrho;
99  }
100  resetSensitivity(params);
101 }
102 
103 size_t FlowReactor::componentIndex(const string& nm) const
104 {
105  // check for a gas species name
106  size_t k = m_thermo->speciesIndex(nm);
107  if (k != npos) {
108  return k + 2;
109  } else if (nm == "X" || nm == "distance") {
110  return 0;
111  } else if (nm == "U" || nm == "velocity") {
112  return 1;
113  } else {
114  return npos;
115  }
116 }
117 
118 }
const vector_fp & molecularWeights() const
Return a const reference to the internal vector of molecular weights.
Definition: Phase.cpp:513
void restoreState(const vector_fp &state)
Restore a state saved on a previous call to saveState.
Definition: Phase.cpp:309
void getMassFractions(doublereal *const y) const
Get the species mass fractions.
Definition: Phase.cpp:584
virtual void getState(doublereal *y)
Get the the current state of the reactor.
Definition: FlowReactor.cpp:33
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:251
void saveState(vector_fp &state) const
Save the current internal state of the phase.
Definition: Phase.cpp:297
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:53
void warn_deprecated(const std::string &method, const std::string &extra)
Print a warning indicating that method is deprecated.
Definition: global.cpp:54
virtual void resetSensitivity(double *params)
Reset the reaction rate multipliers.
Definition: Reactor.cpp:429
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:473
Kinetics * m_kin
Pointer to the homogeneous Kinetics object that handles the reactions.
Definition: Reactor.h:195
virtual void evalEqs(doublereal t, doublereal *y, doublereal *ydot, doublereal *params)
Definition: FlowReactor.cpp:76
virtual void getInitialConditions(doublereal t0, size_t leny, doublereal *y)
Definition: FlowReactor.cpp:26
virtual void applySensitivity(double *params)
Set reaction rate multipliers based on the sensitivity variables in params.
Definition: Reactor.cpp:407
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.
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:231
virtual void setMassFractions(const doublereal *const y)
Set the mass fractions to the specified values and normalize them.
Definition: Phase.cpp:387
Namespace for the Cantera kernel.
Definition: application.cpp:29
virtual void initialize(doublereal t0=0.0)
Initialize the reactor.
Definition: FlowReactor.cpp:47