Skip to content

Commit

Permalink
[Reactor] Add flow-device-specific methods for setting coefficients
Browse files Browse the repository at this point in the history
  • Loading branch information
speth committed Jun 23, 2016
1 parent 7d18120 commit c64b714
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 6 deletions.
4 changes: 3 additions & 1 deletion include/cantera/zeroD/FlowDevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
20 changes: 20 additions & 0 deletions include/cantera/zeroD/flowControllers.h
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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()) {
Expand Down
3 changes: 2 additions & 1 deletion interfaces/cython/cantera/_cantera.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -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*)


Expand Down
5 changes: 2 additions & 3 deletions interfaces/cython/cantera/reactor.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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):
"""
Expand Down
2 changes: 1 addition & 1 deletion samples/cxx/combustor/combustor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit c64b714

Please sign in to comment.