Cantera  3.0.0
Loading...
Searching...
No Matches
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
11namespace 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.
double outletSpeciesMassFlowRate(size_t k)
Mass flow rate (kg/s) of outlet species k.
bool install(ReactorBase &in, ReactorBase &out)
Install a flow device between two reactors.
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
ReactorBase & in() const
Return a reference to the upstream reactor.
Definition FlowDevice.h:71
virtual void setPressureFunction(Func1 *f)
Set a function of pressure that is used in determining the mass flow rate through the device.
const ReactorBase & out() const
Return a const reference to the downstream reactor.
Definition FlowDevice.h:76
double evalTimeFunction()
Return current value of the time function.
virtual void setTimeFunction(Func1 *g)
Set a function of time that is used in determining the mass flow rate through the device.
double evalPressureFunction()
Return current value of the pressure function.
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:96
virtual double eval(double t) const
Evaluate the function.
Definition Func1.cpp:61
size_t nSpecies() const
Returns the number of species in the phase.
Definition Phase.h:245
string speciesName(size_t k) const
Name of the species with index k.
Definition Phase.cpp:151
size_t speciesIndex(const string &name) const
Returns the index of a species named 'name' within the Phase object.
Definition Phase.cpp:138
Base class for stirred reactors.
Definition ReactorBase.h:50
double massFraction(size_t k) const
Return the mass fraction of the k-th species.
double pressure() const
Returns the current pressure (Pa) of the reactor.
void addOutlet(FlowDevice &outlet)
Connect an outlet FlowDevice to this reactor.
void addInlet(FlowDevice &inlet)
Connect an inlet FlowDevice to this reactor.
ThermoPhase & contents()
return a reference to the contents.
double enthalpy_mass() const
Returns the current enthalpy (J/kg) of the reactor's contents.
Base class for a phase with thermodynamic properties.
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:195