Cantera  2.1.2
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 
9 using namespace std;
10 
11 namespace Cantera
12 {
13 
14 FlowReactor::FlowReactor() :
15  Reactor(),
16  m_dist(0.0),
17  m_fctr(1.0e10),
18  m_speed0(0.0)
19 {
20 }
21 
22 void FlowReactor::getInitialConditions(double t0, size_t leny, double* y)
23 {
24  m_init = true;
25  if (m_thermo == 0) {
26  writelog("Error: reactor is empty.\n");
27  return;
28  }
29  m_thermo->restoreState(m_state);
30 
31  m_thermo->getMassFractions(y+2);
32 
33  y[0] = 0.0; // distance
34 
35  // set the second component to the initial speed
36  y[1] = m_speed0;
37 }
38 
39 void FlowReactor::initialize(doublereal t0)
40 {
41  m_thermo->restoreState(m_state);
42  m_nv = m_nsp + 2;
43  m_init = true;
44 }
45 
46 void FlowReactor::updateState(doublereal* y)
47 {
48 
49  // Set the mass fractions and density of the mixture.
50  m_dist = y[0];
51  m_speed = y[1];
52  doublereal* mss = y + 2;
53  // doublereal mass = accumulate(y+2, y+2+m_nsp, 0.0);
54  m_thermo->setMassFractions(mss);
55 
56  doublereal rho = m_rho0 * m_speed0/m_speed;
57 
58  // assumes frictionless
59  doublereal pmom = m_P0 - rho*m_speed*m_speed;
60 
61  doublereal hmom;
62  // assumes adiabatic
63  if (m_energy) {
64  hmom = m_h0 - 0.5*m_speed*m_speed;
65  m_thermo->setState_HP(hmom, pmom);
66  } else {
67  m_thermo->setState_TP(m_T, pmom);
68  }
69  m_thermo->saveState(m_state);
70 }
71 
72 void FlowReactor::evalEqs(doublereal time, doublereal* y,
73  doublereal* ydot, doublereal* params)
74 {
75  m_thermo->restoreState(m_state);
76 
77  double mult;
78  size_t n, npar;
79 
80  // process sensitivity parameters
81  if (params) {
82  npar = nSensParams();
83  for (n = 0; n < npar; n++) {
84  mult = m_kin->multiplier(m_pnum[n]);
85  m_kin->setMultiplier(m_pnum[n], mult*params[n]);
86  }
87  }
88 
89  // distance equation
90  ydot[0] = m_speed;
91 
92  // speed equation. Set m_fctr to a large value, so that rho*u is
93  // held fixed
94  ydot[1] = m_fctr*(m_speed0 - m_thermo->density()*m_speed/m_rho0);
95 
96  /* species equations */
97  const doublereal* mw = DATA_PTR(m_thermo->molecularWeights());
98 
99  if (m_chem) {
100  m_kin->getNetProductionRates(ydot+2); // "omega dot"
101  } else {
102  fill(ydot + 2, ydot + 2 + m_nsp, 0.0);
103  }
104  doublereal rrho = 1.0/m_thermo->density();
105  for (n = 0; n < m_nsp; n++) {
106  ydot[n+2] *= mw[n]*rrho;
107  }
108 
109  // reset sensitivity parameters
110  if (params) {
111  npar = nSensParams();
112  for (n = 0; n < npar; n++) {
113  mult = m_kin->multiplier(m_pnum[n]);
114  m_kin->setMultiplier(m_pnum[n], mult/params[n]);
115  }
116  }
117 }
118 
119 size_t FlowReactor::componentIndex(const string& nm) const
120 {
121  if (nm == "X") {
122  return 0;
123  }
124  if (nm == "U") {
125  return 1;
126  }
127  // check for a gas species name
128  size_t k = m_thermo->speciesIndex(nm);
129  if (k != npos) {
130  return k + 2;
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:534
void restoreState(const vector_fp &state)
Restore a state saved on a previous call to saveState.
Definition: Phase.cpp:289
virtual size_t nSensParams()
Number of sensitivity parameters associated with this reactor (including walls)
Definition: Reactor.cpp:102
void getMassFractions(doublereal *const y) const
Get the species mass fractions.
Definition: Phase.cpp:561
const size_t npos
index returned by functions to indicate "no position"
Definition: ct_defs.h:173
virtual void getNetProductionRates(doublereal *wdot)
Species net production rates [kmol/m^3/s or kmol/m^2/s].
Definition: Kinetics.h:600
virtual void updateState(doublereal *y)
Set the state of the reactor to correspond to the state vector y.
Definition: FlowReactor.cpp:46
doublereal multiplier(size_t i) const
The current value of the multiplier for reaction i.
Definition: Kinetics.h:840
void setMultiplier(size_t i, doublereal f)
Set the multiplier for reaction i to f.
Definition: Kinetics.h:849
virtual size_t componentIndex(const std::string &nm) const
Return the index in the solution vector for this reactor of the component named nm.
Kinetics * m_kin
Pointer to the homogeneous Kinetics object that handles the reactions.
Definition: Reactor.h:149
size_t speciesIndex(const std::string &name) const
Returns the index of a species named 'name' within the Phase object.
Definition: Phase.cpp:229
virtual void evalEqs(doublereal t, doublereal *y, doublereal *ydot, doublereal *params)
Definition: FlowReactor.cpp:72
virtual void getInitialConditions(doublereal t0, size_t leny, doublereal *y)
Called by ReactorNet to get the initial conditions.
Definition: FlowReactor.cpp:22
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:505
#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:213
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:277
virtual void setMassFractions(const doublereal *const y)
Set the mass fractions to the specified values and normalize them.
Definition: Phase.cpp:374
void writelog(const std::string &msg)
Write a message to the screen.
Definition: global.cpp:43
virtual void initialize(doublereal t0=0.0)
Initialize the reactor.
Definition: FlowReactor.cpp:39