Cantera  3.1.0a1
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 
10 
11 namespace Cantera
12 {
13 
15 {
16  if (m_in || m_out) {
17  throw CanteraError("FlowDevice::install", "Already installed");
18  }
19  m_in = ∈
20  m_out = &out;
21  m_in->addOutlet(*this);
22  m_out->addInlet(*this);
23 
24  // construct adapters between inlet and outlet species
25  const ThermoPhase& mixin = m_in->contents();
26  const ThermoPhase& mixout = m_out->contents();
27 
28  m_nspin = mixin.nSpecies();
29  m_nspout = mixout.nSpecies();
30  string nm;
31  size_t ki, ko;
32  for (ki = 0; ki < m_nspin; ki++) {
33  nm = mixin.speciesName(ki);
34  ko = mixout.speciesIndex(nm);
35  m_in2out.push_back(ko);
36  }
37  for (ko = 0; ko < m_nspout; ko++) {
38  nm = mixout.speciesName(ko);
39  ki = mixin.speciesIndex(nm);
40  m_out2in.push_back(ki);
41  }
42  return true;
43 }
44 
46 {
47  m_pfunc = f;
48 }
49 
51 {
52  double delta_P = in().pressure() - out().pressure();
53  if (m_pfunc) {
54  return m_pfunc->eval(delta_P);
55  }
56  return delta_P;
57 }
58 
60 {
61  m_tfunc = g;
62 }
63 
65 {
66  if (m_tfunc) {
67  return m_tfunc->eval(m_time);
68  }
69  return 1.;
70 }
71 
73 {
74  if (k >= m_nspout) {
75  return 0.0;
76  }
77  size_t ki = m_out2in[k];
78  if (ki == npos) {
79  return 0.0;
80  }
81  return m_mdot * m_in->massFraction(ki);
82 }
83 
85 {
86  return m_in->enthalpy_mass();
87 }
88 
89 }
Header file for class ThermoPhase, the base class for phases with thermodynamic properties,...
Base class for exceptions thrown by Cantera classes.
Definition: ctexceptions.h:66
double outletSpeciesMassFlowRate(size_t k)
Mass flow rate (kg/s) of outlet species k.
Definition: FlowDevice.cpp:72
bool install(ReactorBase &in, ReactorBase &out)
Install a flow device between two reactors.
Definition: FlowDevice.cpp:14
Func1 * m_tfunc
Function set by setTimeFunction; used by updateMassFlowRate.
Definition: FlowDevice.h:124
double m_time
Current reactor network time.
Definition: FlowDevice.h:130
double enthalpy_mass()
specific enthalpy
Definition: FlowDevice.cpp:84
virtual void setPressureFunction(Func1 *f)
Set a function of pressure that is used in determining the mass flow rate through the device.
Definition: FlowDevice.cpp:45
double evalTimeFunction()
Return current value of the time function.
Definition: FlowDevice.cpp:64
virtual void setTimeFunction(Func1 *g)
Set a function of time that is used in determining the mass flow rate through the device.
Definition: FlowDevice.cpp:59
ReactorBase & in() const
Return a reference to the upstream reactor.
Definition: FlowDevice.h:71
double evalPressureFunction()
Return current value of the pressure function.
Definition: FlowDevice.cpp:50
const ReactorBase & out() const
Return a const reference to the downstream reactor.
Definition: FlowDevice.h:76
Func1 * m_pfunc
Function set by setPressureFunction; used by updateMassFlowRate.
Definition: FlowDevice.h:121
Base class for 'functor' classes that evaluate a function of one variable.
Definition: Func1.h:75
virtual double eval(double t) const
Evaluate the function.
Definition: Func1.cpp:28
size_t nSpecies() const
Returns the number of species in the phase.
Definition: Phase.h:231
string speciesName(size_t k) const
Name of the species with index k.
Definition: Phase.cpp:142
size_t speciesIndex(const string &name) const
Returns the index of a species named 'name' within the Phase object.
Definition: Phase.cpp:129
Base class for stirred reactors.
Definition: ReactorBase.h:50
double massFraction(size_t k) const
Return the mass fraction of the k-th species.
Definition: ReactorBase.h:239
double pressure() const
Returns the current pressure (Pa) of the reactor.
Definition: ReactorBase.h:224
void addOutlet(FlowDevice &outlet)
Connect an outlet FlowDevice to this reactor.
Definition: ReactorBase.cpp:46
void addInlet(FlowDevice &inlet)
Connect an inlet FlowDevice to this reactor.
Definition: ReactorBase.cpp:41
ThermoPhase & contents()
return a reference to the contents.
Definition: ReactorBase.h:172
double enthalpy_mass() const
Returns the current enthalpy (J/kg) of the reactor's contents.
Definition: ReactorBase.h:214
Base class for a phase with thermodynamic properties.
Definition: ThermoPhase.h:390
Namespace for the Cantera kernel.
Definition: AnyMap.cpp:564
const size_t npos
index returned by functions to indicate "no position"
Definition: ct_defs.h:180