Cantera  2.5.1
FlowDevice.cpp
Go to the documentation of this file.
1 //! @file FlowDevice.cpp
2 
3 // This file is part of Cantera. See License.txt in the top-level directory or
4 // at https://cantera.org/license.txt for license and copyright information.
5 
9 
10 namespace Cantera
11 {
12 
13 FlowDevice::FlowDevice() : m_mdot(Undef), m_pfunc(0), m_tfunc(0),
14  m_coeff(1.0), m_type(0),
15  m_nspin(0), m_nspout(0),
16  m_in(0), m_out(0) {}
17 
18 bool FlowDevice::install(ReactorBase& in, ReactorBase& out)
19 {
20  if (m_in || m_out) {
21  throw CanteraError("FlowDevice::install", "Already installed");
22  }
23  m_in = ∈
24  m_out = &out;
25  m_in->addOutlet(*this);
26  m_out->addInlet(*this);
27 
28  // construct adapters between inlet and outlet species
29  const ThermoPhase& mixin = m_in->contents();
30  const ThermoPhase& mixout = m_out->contents();
31 
32  m_nspin = mixin.nSpecies();
33  m_nspout = mixout.nSpecies();
34  std::string nm;
35  size_t ki, ko;
36  for (ki = 0; ki < m_nspin; ki++) {
37  nm = mixin.speciesName(ki);
38  ko = mixout.speciesIndex(nm);
39  m_in2out.push_back(ko);
40  }
41  for (ko = 0; ko < m_nspout; ko++) {
42  nm = mixout.speciesName(ko);
43  ki = mixin.speciesIndex(nm);
44  m_out2in.push_back(ki);
45  }
46  return true;
47 }
48 
49 void FlowDevice::setPressureFunction(Func1* f)
50 {
51  m_pfunc = f;
52 }
53 
54 void FlowDevice::setTimeFunction(Func1* g)
55 {
56  m_tfunc = g;
57 }
58 
59 double FlowDevice::outletSpeciesMassFlowRate(size_t k)
60 {
61  if (k >= m_nspout) {
62  return 0.0;
63  }
64  size_t ki = m_out2in[k];
65  if (ki == npos) {
66  return 0.0;
67  }
68  return m_mdot * m_in->massFraction(ki);
69 }
70 
71 double FlowDevice::enthalpy_mass()
72 {
73  return m_in->enthalpy_mass();
74 }
75 
76 }
Base class for exceptions thrown by Cantera classes.
Definition: ctexceptions.h:61
Base class for 'functor' classes that evaluate a function of one variable.
Definition: Func1.h:44
size_t nSpecies() const
Returns the number of species in the phase.
Definition: Phase.h:285
std::string speciesName(size_t k) const
Name of the species with index k.
Definition: Phase.cpp:229
size_t speciesIndex(const std::string &name) const
Returns the index of a species named 'name' within the Phase object.
Definition: Phase.cpp:201
Base class for stirred reactors.
Definition: ReactorBase.h:48
void addOutlet(FlowDevice &outlet)
Connect an outlet FlowDevice to this reactor.
Definition: ReactorBase.cpp:52
Base class for a phase with thermodynamic properties.
Definition: ThermoPhase.h:102
const size_t npos
index returned by functions to indicate "no position"
Definition: ct_defs.h:188
const double Undef
Fairly random number to be used to initialize variables against to see if they are subsequently defin...
Definition: ct_defs.h:157
Namespace for the Cantera kernel.
Definition: AnyMap.cpp:264