Skip to content

Commit

Permalink
[Reactor] Deprecating magic numbers.
Browse files Browse the repository at this point in the history
 * add deprecation warning for int ReactorBase::type() (to be changed after Cantera 2.5)
 * introduce temporary std::string ReactorBase::typeStr() (to be renamed after Cantera 2.5)
 * deprecate all functions using the old call and introduce associated temporary functions
  • Loading branch information
Ingmar Schoegl committed Jun 26, 2019
1 parent ae792dd commit a381b35
Show file tree
Hide file tree
Showing 33 changed files with 255 additions and 41 deletions.
9 changes: 6 additions & 3 deletions include/cantera/clib/ctreactor.h
Expand Up @@ -14,7 +14,8 @@
extern "C" {
#endif

CANTERA_CAPI int reactor_new(int type);
CANTERA_CAPI int reactor_new2(const char* type);
CANTERA_CAPI int reactor_new(int type); //!< @deprecated To be changed after Cantera 2.5.
CANTERA_CAPI int reactor_del(int i);
CANTERA_CAPI int reactor_setInitialVolume(int i, double v);
CANTERA_CAPI int reactor_setChemistry(int i, int cflag);
Expand Down Expand Up @@ -47,7 +48,8 @@ extern "C" {
CANTERA_CAPI double reactornet_atol(int i);
CANTERA_CAPI double reactornet_sensitivity(int i, const char* v, int p, int r);

CANTERA_CAPI int flowdev_new(int type);
CANTERA_CAPI int flowdev_new2(const char* type);
CANTERA_CAPI int flowdev_new(int type); //!< @deprecated To be changed after Cantera 2.5.
CANTERA_CAPI int flowdev_del(int i);
CANTERA_CAPI int flowdev_install(int i, int n, int m);
CANTERA_CAPI int flowdev_setMaster(int i, int n);
Expand All @@ -56,7 +58,8 @@ extern "C" {
CANTERA_CAPI int flowdev_setParameters(int i, int n, const double* v);
CANTERA_CAPI int flowdev_setFunction(int i, int n);

CANTERA_CAPI int wall_new(int type);
CANTERA_CAPI int wall_new2(const char* type);
CANTERA_CAPI int wall_new(int type); //!< @deprecated To be changed after Cantera 2.5.
CANTERA_CAPI int wall_del(int i);
CANTERA_CAPI int wall_install(int i, int n, int m);
CANTERA_CAPI double wall_vdot(int i, double t);
Expand Down
11 changes: 11 additions & 0 deletions include/cantera/zeroD/ConstPressureReactor.h
Expand Up @@ -24,7 +24,18 @@ class ConstPressureReactor : public Reactor
public:
ConstPressureReactor() {}

virtual std::string typeStr() const {
return "ConstPressureReactor";
}

/*!
* @deprecated To be changed after Cantera 2.5.
*/
virtual int type() const {
warn_deprecated("ConstPressureReactor::type()",
"To be changed after Cantera 2.5. "
"Return string instead of magic number; use "
"ConstPressureReactor::typeStr() during transition");
return ConstPressureReactorType;
}

Expand Down
19 changes: 17 additions & 2 deletions include/cantera/zeroD/FlowDevice.h
Expand Up @@ -15,6 +15,8 @@ namespace Cantera
class Func1;
class ReactorBase;

//! Magic numbers
//! @deprecated To be removed after Cantera 2.5.
const int MFC_Type = 1;
const int PressureController_Type = 2;
const int Valve_Type = 3;
Expand All @@ -33,8 +35,21 @@ class FlowDevice
FlowDevice(const FlowDevice&) = delete;
FlowDevice& operator=(const FlowDevice&) = delete;

//! String indicating the flow device implemented. Usually
//! corresponds to the name of the derived class.
virtual std::string typeStr() const {
return "FlowDevice";
}

//! Return an integer indicating the type of flow device
int type() {
/*!
* @deprecated To be changed after Cantera 2.5.
*/
virtual int type() const {
warn_deprecated("FlowDevice::type()",
"To be changed after Cantera 2.5. "
"Return string instead of magic number; use "
"FlowDevice::typeStr() during transition.");
return m_type;
}

Expand Down Expand Up @@ -100,7 +115,7 @@ class FlowDevice
doublereal m_mdot;
Func1* m_func;
vector_fp m_coeffs;
int m_type;
int m_type; //!< @deprecated To be removed after Cantera 2.5.

private:
size_t m_nspin, m_nspout;
Expand Down
3 changes: 3 additions & 0 deletions include/cantera/zeroD/FlowDeviceFactory.h
Expand Up @@ -46,13 +46,16 @@ class FlowDeviceFactory : public Factory<FlowDevice>
* @param name the name of the flow device type.
* @param type the type identifier of the flow device.
* Integer type identifiers are used by clib and matlab interfaces.
*
* @deprecated To be removed after Cantera 2.5.
*/
void reg_type(const std::string& name, const int type) {
m_types[type] = name;
}

protected:
//! Map containing flow device type identifier / type name pairs.
//! @deprecated To be removed after Cantera 2.5.
std::unordered_map<int, std::string> m_types;

private:
Expand Down
11 changes: 11 additions & 0 deletions include/cantera/zeroD/FlowReactor.h
Expand Up @@ -17,7 +17,18 @@ class FlowReactor : public Reactor
public:
FlowReactor();

virtual std::string typeStr() const {
return "FlowReactor";
}

/*!
* @deprecated To be changed after Cantera 2.5.
*/
virtual int type() const {
warn_deprecated("FlowReactor::type()",
"To be changed after Cantera 2.5. "
"Return string instead of magic number; use "
"FlowReactor::typeStr() during transition");
return FlowReactorType;
}

Expand Down
12 changes: 12 additions & 0 deletions include/cantera/zeroD/IdealGasConstPressureReactor.h
Expand Up @@ -23,7 +23,19 @@ class IdealGasConstPressureReactor : public ConstPressureReactor
public:
IdealGasConstPressureReactor() {}

virtual std::string typeStr() const {
return "IdealGasConstPressureReactor";
}

/*!
* @deprecated To be changed after Cantera 2.5.
*/
virtual int type() const {
warn_deprecated("IdealGasConstPressureReactor::type()",
"To be changed after Cantera 2.5. "
"Return string instead of magic number; use "
"IdealGasConstPressureReactor::typeStr() during "
"transition");
return IdealGasConstPressureReactorType;
}

Expand Down
11 changes: 11 additions & 0 deletions include/cantera/zeroD/IdealGasReactor.h
Expand Up @@ -21,7 +21,18 @@ class IdealGasReactor : public Reactor
public:
IdealGasReactor() {}

virtual std::string typeStr() const {
return "IdealGasReactor";
}

/*!
* @deprecated To be removed after Cantera 2.5.
*/
virtual int type() const {
warn_deprecated("IdealGasReactor::type()",
"To be changed after Cantera 2.5. "
"Return string instead of magic number; use "
"IdealGasReactor::typeStr() during transition");
return IdealGasReactorType;
}

Expand Down
15 changes: 15 additions & 0 deletions include/cantera/zeroD/Reactor.h
Expand Up @@ -39,7 +39,18 @@ class Reactor : public ReactorBase
public:
Reactor();

virtual std::string typeStr() const {
return "Reactor";
}

/*!
* @deprecated To be changed after Cantera 2.5.
*/
virtual int type() const {
warn_deprecated("Reactor::type()",
"To be changed after Cantera 2.5. "
"Return string instead of magic number; use "
"Reactor::typeStr() during transition");
return ReactorType;
}

Expand Down Expand Up @@ -146,6 +157,10 @@ class Reactor : public ReactorBase
//! @param limit value for step size limit
virtual void setAdvanceLimit(const std::string& nm, const double limit);

virtual bool hasEquations() const {
return true;
}

protected:
//! Set reaction rate multipliers based on the sensitivity variables in
//! *params*.
Expand Down
18 changes: 18 additions & 0 deletions include/cantera/zeroD/ReactorBase.h
Expand Up @@ -16,6 +16,8 @@ class WallBase;
class ReactorNet;
class ReactorSurface;

//! Magic numbers
//! @deprecated To be removed after Cantera 2.5.
const int ReservoirType = 1;
const int ReactorType = 2;
const int FlowReactorType = 3;
Expand Down Expand Up @@ -49,8 +51,19 @@ class ReactorBase
ReactorBase(const ReactorBase&) = delete;
ReactorBase& operator=(const ReactorBase&) = delete;

//! String indicating the reactor model implemented. Usually
//! corresponds to the name of the derived class.
virtual std::string typeStr() const {
return "ReactorBase";
}

//! Return a constant indicating the type of this Reactor
//! * @deprecated To be changed after Cantera 2.5.
virtual int type() const {
warn_deprecated("ReactorBase::type()",
"To be changed after Cantera 2.5. "
"Return string instead of magic number; use "
"ReactorBase::typeStr() during transition");
return 0;
}

Expand Down Expand Up @@ -228,6 +241,11 @@ class ReactorBase
//! Set the ReactorNet that this reactor belongs to.
void setNetwork(ReactorNet* net);

//! Return whether ReactorBase object handles equations
virtual bool hasEquations() const {
return false;
}

protected:
//! Number of homogeneous species in the mixture
size_t m_nsp;
Expand Down
3 changes: 3 additions & 0 deletions include/cantera/zeroD/ReactorFactory.h
Expand Up @@ -46,13 +46,16 @@ class ReactorFactory : public Factory<ReactorBase>
* @param name the name of the reactor type.
* @param type the type identifier of the reactor.
* Integer type identifiers are used by clib and matlab interfaces.
*
* @deprecated To be removed after Cantera 2.5.
*/
void reg_type(const std::string& name, const int type) {
m_types[type] = name;
}

protected:
//! Map containing reactor type identifier / reactor type name pairs.
//! @deprecated To be removed after Cantera 2.5.
std::unordered_map<int, std::string> m_types;

private:
Expand Down
12 changes: 12 additions & 0 deletions include/cantera/zeroD/Reservoir.h
Expand Up @@ -15,7 +15,19 @@ class Reservoir : public ReactorBase
{
public:
Reservoir() {}

virtual std::string typeStr() const {
return "Reservoir";
}

/*!
* @deprecated To be changed after Cantera 2.5.
*/
virtual int type() const {
warn_deprecated("Reservoir::type()",
"To be changed after Cantera 2.5. "
"Return string instead of magic number; use "
"Reservoir::typeStr() during transition");
return ReservoirType;
}
virtual void initialize(doublereal t0 = 0.0) {}
Expand Down
2 changes: 2 additions & 0 deletions include/cantera/zeroD/Wall.h
Expand Up @@ -17,6 +17,8 @@ class Kinetics;
class SurfPhase;
class Func1;

//! Magic numbers
//! @deprecated To be removed after Cantera 2.5.
const int WallType = 1;

/**
Expand Down
3 changes: 3 additions & 0 deletions include/cantera/zeroD/WallFactory.h
Expand Up @@ -46,13 +46,16 @@ class WallFactory : public Factory<WallBase>
* @param name the name of the wall type.
* @param type the type identifier of the wall.
* Integer type identifiers are used by clib and matlab interfaces.
*
* @deprecated To be removed after Cantera 2.5.
*/
void reg_type(const std::string& name, const int type) {
m_types[type] = name;
}

protected:
//! Map containing wall type identifier / wall type name pairs.
//! @deprecated To be removed after Cantera 2.5.
std::unordered_map<int, std::string> m_types;

private:
Expand Down
12 changes: 12 additions & 0 deletions include/cantera/zeroD/flowControllers.h
Expand Up @@ -20,6 +20,10 @@ class MassFlowController : public FlowDevice
public:
MassFlowController();

virtual std::string typeStr() const {
return "MassFlowController";
}

virtual bool ready() {
return FlowDevice::ready() && m_mdot >= 0.0;
}
Expand All @@ -40,6 +44,10 @@ class PressureController : public FlowDevice
public:
PressureController();

virtual std::string typeStr() const {
return "PressureController";
}

virtual bool ready() {
return FlowDevice::ready() && m_master != 0 && m_coeffs.size() == 1;
}
Expand Down Expand Up @@ -76,6 +84,10 @@ class Valve : public FlowDevice
public:
Valve();

virtual std::string typeStr() const {
return "Valve";
}

virtual bool ready() {
return FlowDevice::ready() && (m_coeffs.size() == 1 || m_func);
}
Expand Down
6 changes: 4 additions & 2 deletions interfaces/cython/cantera/_cantera.pxd
Expand Up @@ -495,15 +495,16 @@ cdef extern from "cantera/zerodim.h" namespace "Cantera":
cdef cppclass CxxFlowDevice "Cantera::FlowDevice"

# factories

cdef CxxReactorBase* newReactor(string) except +translate_exception
cdef CxxFlowDevice* newFlowDevice(string) except +translate_exception
cdef CxxWallBase* newWall(string) except +translate_exception

# reactors

cdef cppclass CxxReactorBase "Cantera::ReactorBase":
CxxReactorBase()
string typeStr()
void setThermoMgr(CxxThermoPhase&) except +translate_exception
void restoreState() except +translate_exception
void syncState() except +translate_exception
Expand Down Expand Up @@ -581,6 +582,7 @@ cdef extern from "cantera/zerodim.h" namespace "Cantera":

cdef cppclass CxxFlowDevice "Cantera::FlowDevice":
CxxFlowDevice()
string typeStr()
double massFlowRate(double) except +translate_exception
cbool install(CxxReactorBase&, CxxReactorBase&) except +translate_exception
void setFunction(CxxFunc1*)
Expand Down
12 changes: 11 additions & 1 deletion interfaces/cython/cantera/reactor.pyx
Expand Up @@ -49,6 +49,11 @@ cdef class ReactorBase:
self._thermo._references[self._weakref_proxy] = True
self.rbase.setThermoMgr(deref(solution.thermo))

property type:
"""The type of the reactor."""
def __get__(self):
return pystr(self.rbase.typeStr())

property name:
"""The name of the reactor."""
def __get__(self):
Expand Down Expand Up @@ -532,7 +537,7 @@ cdef class WallBase:
self._right_reactor = right

property type:
""" The left surface of this wall. """
"""The type of the wall."""
def __get__(self):
return pystr(self.wall.type())

Expand Down Expand Up @@ -684,6 +689,11 @@ cdef class FlowDevice:
def __dealloc__(self):
del self.dev

property type:
"""The type of the flow device."""
def __get__(self):
return pystr(self.dev.typeStr())

def _install(self, ReactorBase upstream, ReactorBase downstream):
"""
Install the device between the *upstream* (source) and *downstream*
Expand Down

0 comments on commit a381b35

Please sign in to comment.