Cantera  3.1.0b1
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
14bool FlowDevice::setDefaultName(map<string, int>& counts)
15{
16 if (m_defaultNameSet) {
17 return false;
18 }
19 m_defaultNameSet = true;
20 string typ(type());
21 if (m_name == "(none)" || m_name == "") {
22 m_name = fmt::format("{}_{}", type(), counts[type()]);
23 }
24 counts[type()]++;
25 return true;
26}
27
29{
30 if (m_in || m_out) {
31 throw CanteraError("FlowDevice::install", "Already installed");
32 }
33 m_in = &in;
34 m_out = &out;
35 m_in->addOutlet(*this);
36 m_out->addInlet(*this);
37
38 // construct adapters between inlet and outlet species
39 const ThermoPhase& mixin = m_in->contents();
40 const ThermoPhase& mixout = m_out->contents();
41
42 m_nspin = mixin.nSpecies();
43 m_nspout = mixout.nSpecies();
44 string nm;
45 size_t ki, ko;
46 for (ki = 0; ki < m_nspin; ki++) {
47 nm = mixin.speciesName(ki);
48 ko = mixout.speciesIndex(nm);
49 m_in2out.push_back(ko);
50 }
51 for (ko = 0; ko < m_nspout; ko++) {
52 nm = mixout.speciesName(ko);
53 ki = mixin.speciesIndex(nm);
54 m_out2in.push_back(ki);
55 }
56 return true;
57}
58
60{
61 m_pfunc = f;
62}
63
65{
66 double delta_P = in().pressure() - out().pressure();
67 if (m_pfunc) {
68 return m_pfunc->eval(delta_P);
69 }
70 return delta_P;
71}
72
74{
75 m_tfunc = g;
76}
77
79{
80 if (m_tfunc) {
81 return m_tfunc->eval(m_time);
82 }
83 return 1.;
84}
85
87{
88 if (k >= m_nspout) {
89 return 0.0;
90 }
91 size_t ki = m_out2in[k];
92 if (ki == npos) {
93 return 0.0;
94 }
95 return m_mdot * m_in->massFraction(ki);
96}
97
99{
100 return m_in->enthalpy_mass();
101}
102
103}
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 m_defaultNameSet
true if default name has been previously set.
Definition FlowDevice.h:137
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:145
virtual string type() const
String indicating the flow device implemented.
Definition FlowDevice.h:34
double m_time
Current reactor network time.
Definition FlowDevice.h:151
bool setDefaultName(map< string, int > &counts)
Set the default name of a flow device. Returns false if it was previously set.
double enthalpy_mass()
specific enthalpy
ReactorBase & in() const
Return a reference to the upstream reactor.
Definition FlowDevice.h:84
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:89
double evalTimeFunction()
Return current value of the time function.
string m_name
Flow device name.
Definition FlowDevice.h:136
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:142
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:49
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:595
const size_t npos
index returned by functions to indicate "no position"
Definition ct_defs.h:180