Cantera  2.0
FlowDevice.cpp
1 
5 
6 using namespace std;
7 using namespace Cantera;
8 
9 namespace Cantera
10 {
11 
12 bool FlowDevice::install(ReactorBase& in, ReactorBase& out)
13 {
14  if (m_in || m_out) {
15  return false;
16  }
17  m_in = ∈
18  m_out = &out;
19  m_in->addOutlet(*this);
20  m_out->addInlet(*this);
21 
22  // construct adapters between inlet and outlet species
23  ThermoPhase* mixin = &m_in->contents();
24  ThermoPhase* mixout = &m_out->contents();
25  if (mixin == 0 || mixout == 0) {
26  return false;
27  }
28 
29  m_nspin = mixin->nSpecies();
30  m_nspout = mixout->nSpecies();
31  string nm;
32  size_t ki, ko;
33  for (ki = 0; ki < m_nspin; ki++) {
34  nm = mixin->speciesName(ki);
35  ko = mixout->speciesIndex(nm);
36  m_in2out.push_back(ko);
37  }
38  for (ko = 0; ko < m_nspout; ko++) {
39  nm = mixout->speciesName(ko);
40  ki = mixin->speciesIndex(nm);
41  m_out2in.push_back(ki);
42  }
43  return true;
44 }
45 
46 void FlowDevice::setFunction(Func1* f)
47 {
48  m_func = f;
49 }
50 
51 
52 /**
53  * Mass flow rate of outlet species k. Returns zero if this
54  * species is not present in the upstream mixture.
55  */
56 doublereal FlowDevice::outletSpeciesMassFlowRate(size_t k)
57 {
58  if (k >= m_nspout) {
59  return 0.0;
60  }
61  size_t ki = m_out2in[k];
62  if (ki == npos) {
63  return 0.0;
64  }
65  return m_mdot * m_in->massFraction(ki);
66 }
67 
68 doublereal FlowDevice::enthalpy_mass()
69 {
70  return m_in->enthalpy_mass();
71 }
72 
73 }