15FlowDevice::FlowDevice(shared_ptr<ReactorBase> r0, shared_ptr<ReactorBase> r1,
18 if (!m_nodes.first || !m_nodes.second) {
19 throw CanteraError(
"FlowDevice::FlowDevice",
20 "Reactors must be provided to FlowDevice constructor.");
24 m_in->addOutlet(*
this);
25 m_out->addInlet(*
this);
28 const ThermoPhase& mixin = *m_in->phase()->thermo();
29 const ThermoPhase& mixout = *m_out->phase()->thermo();
31 m_nspin = mixin.nSpecies();
32 m_nspout = mixout.nSpecies();
35 for (ki = 0; ki < m_nspin; ki++) {
36 nm = mixin.speciesName(ki);
37 ko = mixout.speciesIndex(nm,
false);
38 m_in2out.push_back(ko);
40 for (ko = 0; ko < m_nspout; ko++) {
41 nm = mixout.speciesName(ko);
42 ki = mixin.speciesIndex(nm,
false);
43 m_out2in.push_back(ki);
49 double delta_P =
in().pressure() -
out().pressure();
69 size_t ki = m_out2in[k];
73 return m_mdot * m_in->massFraction(ki);
77 double coeff,
bool includePressureSpecies)
85 m_in->addPressureJacobian(trips, row, coeff * alpha, includePressureSpecies);
86 m_out->addPressureJacobian(trips, row, -coeff * alpha, includePressureSpecies);
90 SparseTriplets& trips,
size_t row,
size_t k,
double coeff,
91 bool includeComposition,
bool includePressureSpecies)
96 size_t ki = m_out2in[k];
100 double Yin = m_in->massFraction(ki);
104 if (includeComposition && m_mdot != 0.0) {
105 m_in->addSpeciesMassFractionJacobian(trips, row, ki, coeff * m_mdot);
111 return m_in->enthalpy_mass();
120 return m_pfunc->derivative()->eval(deltaP);
125 double eps = std::sqrt(std::numeric_limits<double>::epsilon())
126 * std::max(1.0, std::abs(deltaP));
127 return (
m_pfunc->eval(deltaP + eps) -
m_pfunc->eval(deltaP - eps))
133 double coeff,
bool includeComposition)
136 m_in->addEnthalpyJacobian(trips, row, coeff * m_mdot, includeComposition);
Header file for class ThermoPhase, the base class for phases with thermodynamic properties,...
Base class for exceptions thrown by Cantera classes.
Base class for walls and flow devices connecting reactors.
double outletSpeciesMassFlowRate(size_t k)
Mass flow rate (kg/s) of outlet species k.
void addInletEnthalpyJacobian(SparseTriplets &trips, size_t row, double coeff, bool includeComposition=true)
Add Jacobian terms for the inlet enthalpy dependence on upstream state.
virtual void addMassFlowRateJacobian(SparseTriplets &trips, size_t row, double coeff, bool includePressureSpecies=true)
Add Jacobian terms proportional to derivatives of the mass flow rate.
double m_time
Current reactor network time.
double enthalpy_mass()
specific enthalpy
ReactorBase & in() const
Return a reference to the upstream reactor.
void addOutletSpeciesMassFlowRateJacobian(SparseTriplets &trips, size_t row, size_t k, double coeff, bool includeComposition=true, bool includePressureSpecies=true)
Add Jacobian terms proportional to derivatives of outletSpeciesMassFlowRate(k).
const ReactorBase & out() const
Return a const reference to the downstream reactor.
double evalTimeFunction()
Return current value of the time function.
virtual double massFlowRate_ddP() const
Derivative of mass flow rate with respect to pressure difference.
shared_ptr< Func1 > m_tfunc
Function set by setTimeFunction; used by updateMassFlowRate.
double evalPressureFunction()
Return current value of the pressure function.
shared_ptr< Func1 > m_pfunc
Function set by setPressureFunction; used by updateMassFlowRate.
double pressureFunction_ddP(double deltaP) const
Return the derivative of the pressure function at deltaP.
Namespace for the Cantera kernel.
const size_t npos
index returned by functions to indicate "no position"