Cantera  2.2.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
FlowReactor.cpp
Go to the documentation of this file.
1 /**
2 * @file FlowReactor.cpp A steady-state plug flow reactor
3 */
4 
5 // Copyright 2001 California Institute of Technology
6 
8 #include "cantera/base/global.h"
9 
10 using namespace std;
11 
12 namespace Cantera
13 {
14 
15 FlowReactor::FlowReactor() :
16  m_speed(0.0),
17  m_dist(0.0),
18  m_T(0.0),
19  m_fctr(1.0e10),
20  m_rho0(0.0),
21  m_speed0(0.0),
22  m_P0(0.0),
23  m_h0(0.0)
24 {
25 }
26 
27 void FlowReactor::getInitialConditions(double t0, size_t leny, double* y)
28 {
29  if (m_thermo == 0) {
30  writelog("Error: reactor is empty.\n");
31  return;
32  }
33  m_thermo->restoreState(m_state);
34 
35  m_thermo->getMassFractions(y+2);
36 
37  y[0] = 0.0; // distance
38 
39  // set the second component to the initial speed
40  y[1] = m_speed0;
41 }
42 
43 void FlowReactor::initialize(doublereal t0)
44 {
45  m_thermo->restoreState(m_state);
46  m_nv = m_nsp + 2;
47 }
48 
49 void FlowReactor::updateState(doublereal* y)
50 {
51 
52  // Set the mass fractions and density of the mixture.
53  m_dist = y[0];
54  m_speed = y[1];
55  doublereal* mss = y + 2;
56  m_thermo->setMassFractions(mss);
57 
58  doublereal rho = m_rho0 * m_speed0/m_speed;
59 
60  // assumes frictionless
61  doublereal pmom = m_P0 - rho*m_speed*m_speed;
62 
63  doublereal hmom;
64  // assumes adiabatic
65  if (m_energy) {
66  hmom = m_h0 - 0.5*m_speed*m_speed;
67  m_thermo->setState_HP(hmom, pmom);
68  } else {
69  m_thermo->setState_TP(m_T, pmom);
70  }
71  m_thermo->saveState(m_state);
72 }
73 
74 void FlowReactor::evalEqs(doublereal time, doublereal* y,
75  doublereal* ydot, doublereal* params)
76 {
77  m_thermo->restoreState(m_state);
78 
79  double mult;
80  size_t n, npar;
81 
82  // process sensitivity parameters
83  if (params) {
84  npar = nSensParams();
85  for (n = 0; n < npar; n++) {
86  mult = m_kin->multiplier(m_pnum[n]);
87  m_kin->setMultiplier(m_pnum[n], mult*params[n]);
88  }
89  }
90 
91  // distance equation
92  ydot[0] = m_speed;
93 
94  // speed equation. Set m_fctr to a large value, so that rho*u is
95  // held fixed
96  ydot[1] = m_fctr*(m_speed0 - m_thermo->density()*m_speed/m_rho0);
97 
98  /* species equations */
99  const doublereal* mw = DATA_PTR(m_thermo->molecularWeights());
100 
101  if (m_chem) {
102  m_kin->getNetProductionRates(ydot+2); // "omega dot"
103  } else {
104  fill(ydot + 2, ydot + 2 + m_nsp, 0.0);
105  }
106  doublereal rrho = 1.0/m_thermo->density();
107  for (n = 0; n < m_nsp; n++) {
108  ydot[n+2] *= mw[n]*rrho;
109  }
110 
111  // reset sensitivity parameters
112  if (params) {
113  npar = nSensParams();
114  for (n = 0; n < npar; n++) {
115  mult = m_kin->multiplier(m_pnum[n]);
116  m_kin->setMultiplier(m_pnum[n], mult/params[n]);
117  }
118  }
119 }
120 
121 size_t FlowReactor::componentIndex(const string& nm) const
122 {
123  // check for a gas species name
124  size_t k = m_thermo->speciesIndex(nm);
125  if (k != npos) {
126  return k + 2;
127  } else if (nm == "X" || nm == "distance") {
128  return 0;
129  } else if (nm == "U" || nm == "velocity") {
130  return 1;
131  } else {
132  return npos;
133  }
134 }
135 
136 }
virtual void setState_HP(doublereal h, doublereal p, doublereal tol=1.e-4)
Set the internally stored specific enthalpy (J/kg) and pressure (Pa) of the phase.
virtual doublereal density() const
Density (kg/m^3).
Definition: Phase.h:608
void restoreState(const vector_fp &state)
Restore a state saved on a previous call to saveState.
Definition: Phase.cpp:314
virtual size_t nSensParams()
Number of sensitivity parameters associated with this reactor (including walls)
Definition: Reactor.cpp:107
void getMassFractions(doublereal *const y) const
Get the species mass fractions.
Definition: Phase.cpp:598
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:49
doublereal multiplier(size_t i) const
The current value of the multiplier for reaction i.
Definition: Kinetics.h:875
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 size_t componentIndex(const std::string &nm) const
Return the index in the solution vector for this reactor of the component named nm.
virtual void getNetProductionRates(doublereal *wdot)
Species net production rates [kmol/m^3/s or kmol/m^2/s].
Definition: Kinetics.cpp:501
Kinetics * m_kin
Pointer to the homogeneous Kinetics object that handles the reactions.
Definition: Reactor.h:181
size_t speciesIndex(const std::string &name) const
Returns the index of a species named 'name' within the Phase object.
Definition: Phase.cpp:257
virtual void evalEqs(doublereal t, doublereal *y, doublereal *ydot, doublereal *params)
Definition: FlowReactor.cpp:74
virtual void getInitialConditions(doublereal t0, size_t leny, doublereal *y)
Called by ReactorNet to get the initial conditions.
Definition: FlowReactor.cpp:27
virtual void setState_TP(doublereal t, doublereal p)
Set the temperature (K) and pressure (Pa)
const vector_fp & molecularWeights() const
Return a const reference to the internal vector of molecular weights.
Definition: Phase.cpp:515
#define DATA_PTR(vec)
Creates a pointer to the start of the raw data for a vector.
Definition: ct_defs.h:36
size_t m_nsp
Number of homogeneous species in the mixture.
Definition: ReactorBase.h:217
void saveState(vector_fp &state) const
Save the current internal state of the phase Write to vector 'state' the current internal state...
Definition: Phase.cpp:302
virtual void setMassFractions(const doublereal *const y)
Set the mass fractions to the specified values and normalize them.
Definition: Phase.cpp:390
void writelog(const std::string &msg)
Write a message to the screen.
Definition: global.cpp:33
virtual void setMultiplier(size_t i, doublereal f)
Set the multiplier for reaction i to f.
Definition: Kinetics.h:884
virtual void initialize(doublereal t0=0.0)
Initialize the reactor.
Definition: FlowReactor.cpp:43