[Reactor] Add flow-device-specific methods for setting coefficients
This commit is contained in:
parent
7d18120c4d
commit
c64b714386
5 changed files with 28 additions and 6 deletions
|
|
@ -77,7 +77,9 @@ public:
|
|||
return *m_out;
|
||||
}
|
||||
|
||||
//! set parameters
|
||||
//! set parameters. Generic function used only in the Matlab interface. From
|
||||
//! Python or C++, device-specific functions like Valve::setPressureCoeff
|
||||
//! should be used instead.
|
||||
virtual void setParameters(int n, doublereal* coeffs) {
|
||||
m_coeffs.resize(n);
|
||||
std::copy(coeffs, coeffs + n, m_coeffs.begin());
|
||||
|
|
|
|||
|
|
@ -57,6 +57,16 @@ public:
|
|||
m_master = master;
|
||||
}
|
||||
|
||||
//! Set the proportionality constant between pressure drop and mass flow
|
||||
//! rate
|
||||
/*!
|
||||
* *c* has units of kg/s/Pa. The mass flow rate is computed as:
|
||||
* \f[\dot{m} = \dot{m}_{master} + c \Delta P \f]
|
||||
*/
|
||||
void setPressureCoeff(double c) {
|
||||
m_coeffs = {c};
|
||||
}
|
||||
|
||||
virtual void updateMassFlowRate(doublereal time) {
|
||||
if (!ready()) {
|
||||
throw CanteraError("PressureController::updateMassFlowRate",
|
||||
|
|
@ -90,6 +100,16 @@ public:
|
|||
return FlowDevice::ready() && (m_coeffs.size() == 1 || m_func);
|
||||
}
|
||||
|
||||
//! Set the proportionality constant between pressure drop and mass flow
|
||||
//! rate
|
||||
/*!
|
||||
* *c* has units of kg/s/Pa. The mass flow rate is computed as:
|
||||
* \f[\dot{m} = c \Delta P \f]
|
||||
*/
|
||||
void setPressureCoeff(double c) {
|
||||
m_coeffs = {c};
|
||||
}
|
||||
|
||||
/// Compute the currrent mass flow rate, based on the pressure difference.
|
||||
virtual void updateMassFlowRate(doublereal time) {
|
||||
if (!ready()) {
|
||||
|
|
|
|||
|
|
@ -536,16 +536,17 @@ cdef extern from "cantera/zeroD/flowControllers.h":
|
|||
double massFlowRate(double) except +
|
||||
cbool install(CxxReactorBase&, CxxReactorBase&) except +
|
||||
void setFunction(CxxFunc1*)
|
||||
void setParameters(int, double*)
|
||||
|
||||
cdef cppclass CxxMassFlowController "Cantera::MassFlowController" (CxxFlowDevice):
|
||||
CxxMassFlowController()
|
||||
|
||||
cdef cppclass CxxValve "Cantera::Valve" (CxxFlowDevice):
|
||||
void setPressureCoeff(double)
|
||||
CxxValve()
|
||||
|
||||
cdef cppclass CxxPressureController "Cantera::PressureController" (CxxFlowDevice):
|
||||
CxxPressureController()
|
||||
void setPressureCoeff(double)
|
||||
void setMaster(CxxFlowDevice*)
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -739,11 +739,10 @@ cdef class Valve(FlowDevice):
|
|||
>>> V.set_valve_coeff(1e-4)
|
||||
>>> V.set_valve_coeff(lambda dP: (1e-5 * dP)**2)
|
||||
"""
|
||||
cdef double kv
|
||||
cdef Func1 f
|
||||
if isinstance(k, _numbers.Real):
|
||||
kv = k
|
||||
self.dev.setParameters(1, &kv)
|
||||
(<CxxValve*>self.dev).setPressureCoeff(k)
|
||||
return
|
||||
|
||||
if isinstance(k, Func1):
|
||||
|
|
@ -782,7 +781,7 @@ cdef class PressureController(FlowDevice):
|
|||
Set the proportionality constant *k* [kg/s/Pa] between the pressure
|
||||
drop and the mass flow rate.
|
||||
"""
|
||||
self.dev.setParameters(1, &k)
|
||||
(<CxxPressureController*>self.dev).setPressureCoeff(k)
|
||||
|
||||
def set_master(self, FlowDevice d):
|
||||
"""
|
||||
|
|
|
|||
|
|
@ -92,7 +92,7 @@ void runexample()
|
|||
Valve v;
|
||||
v.install(combustor, exhaust);
|
||||
double Kv = 1.0;
|
||||
v.setParameters(1, &Kv);
|
||||
v.setPressureCoeff(Kv);
|
||||
|
||||
// the simulation only contains one reactor
|
||||
ReactorNet sim;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue