From c64b71438623d56d35eee3c46914d1cd1ec9e973 Mon Sep 17 00:00:00 2001 From: Ray Speth Date: Thu, 23 Jun 2016 11:50:07 -0400 Subject: [PATCH] [Reactor] Add flow-device-specific methods for setting coefficients --- include/cantera/zeroD/FlowDevice.h | 4 +++- include/cantera/zeroD/flowControllers.h | 20 ++++++++++++++++++++ interfaces/cython/cantera/_cantera.pxd | 3 ++- interfaces/cython/cantera/reactor.pyx | 5 ++--- samples/cxx/combustor/combustor.cpp | 2 +- 5 files changed, 28 insertions(+), 6 deletions(-) diff --git a/include/cantera/zeroD/FlowDevice.h b/include/cantera/zeroD/FlowDevice.h index 983ddd5d1a..28d1fb2883 100644 --- a/include/cantera/zeroD/FlowDevice.h +++ b/include/cantera/zeroD/FlowDevice.h @@ -77,7 +77,9 @@ class FlowDevice 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()); diff --git a/include/cantera/zeroD/flowControllers.h b/include/cantera/zeroD/flowControllers.h index 3e8e092024..5254bd8663 100644 --- a/include/cantera/zeroD/flowControllers.h +++ b/include/cantera/zeroD/flowControllers.h @@ -57,6 +57,16 @@ class PressureController : public FlowDevice 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 @@ class Valve : public FlowDevice 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()) { diff --git a/interfaces/cython/cantera/_cantera.pxd b/interfaces/cython/cantera/_cantera.pxd index bb357e269c..d77bb68c1c 100644 --- a/interfaces/cython/cantera/_cantera.pxd +++ b/interfaces/cython/cantera/_cantera.pxd @@ -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*) diff --git a/interfaces/cython/cantera/reactor.pyx b/interfaces/cython/cantera/reactor.pyx index 9e66284ff7..f0adcfc007 100644 --- a/interfaces/cython/cantera/reactor.pyx +++ b/interfaces/cython/cantera/reactor.pyx @@ -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) + (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) + (self.dev).setPressureCoeff(k) def set_master(self, FlowDevice d): """ diff --git a/samples/cxx/combustor/combustor.cpp b/samples/cxx/combustor/combustor.cpp index ce0ad24d17..4d4e2db33f 100644 --- a/samples/cxx/combustor/combustor.cpp +++ b/samples/cxx/combustor/combustor.cpp @@ -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;