diff --git a/include/cantera/clib/ctreactor.h b/include/cantera/clib/ctreactor.h index 7bcbc37b320..5e105257a78 100644 --- a/include/cantera/clib/ctreactor.h +++ b/include/cantera/clib/ctreactor.h @@ -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); @@ -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); @@ -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); diff --git a/include/cantera/zeroD/ConstPressureReactor.h b/include/cantera/zeroD/ConstPressureReactor.h index f791dabe385..987ce51611e 100644 --- a/include/cantera/zeroD/ConstPressureReactor.h +++ b/include/cantera/zeroD/ConstPressureReactor.h @@ -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; } diff --git a/include/cantera/zeroD/FlowDevice.h b/include/cantera/zeroD/FlowDevice.h index 57aec071177..5bf5caed777 100644 --- a/include/cantera/zeroD/FlowDevice.h +++ b/include/cantera/zeroD/FlowDevice.h @@ -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; @@ -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; } @@ -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; diff --git a/include/cantera/zeroD/FlowDeviceFactory.h b/include/cantera/zeroD/FlowDeviceFactory.h index d519940dd6e..fbe4e1183fe 100644 --- a/include/cantera/zeroD/FlowDeviceFactory.h +++ b/include/cantera/zeroD/FlowDeviceFactory.h @@ -46,6 +46,8 @@ class FlowDeviceFactory : public Factory * @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; @@ -53,6 +55,7 @@ class FlowDeviceFactory : public Factory protected: //! Map containing flow device type identifier / type name pairs. + //! @deprecated To be removed after Cantera 2.5. std::unordered_map m_types; private: diff --git a/include/cantera/zeroD/FlowReactor.h b/include/cantera/zeroD/FlowReactor.h index 16a09b5687f..e5b03b5601e 100644 --- a/include/cantera/zeroD/FlowReactor.h +++ b/include/cantera/zeroD/FlowReactor.h @@ -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; } diff --git a/include/cantera/zeroD/IdealGasConstPressureReactor.h b/include/cantera/zeroD/IdealGasConstPressureReactor.h index 505d6fc0b7f..2eca3c393a4 100644 --- a/include/cantera/zeroD/IdealGasConstPressureReactor.h +++ b/include/cantera/zeroD/IdealGasConstPressureReactor.h @@ -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; } diff --git a/include/cantera/zeroD/IdealGasReactor.h b/include/cantera/zeroD/IdealGasReactor.h index b9ef027b1b9..60538a709ae 100644 --- a/include/cantera/zeroD/IdealGasReactor.h +++ b/include/cantera/zeroD/IdealGasReactor.h @@ -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; } diff --git a/include/cantera/zeroD/Reactor.h b/include/cantera/zeroD/Reactor.h index 54ea826c013..a4bd8e05243 100644 --- a/include/cantera/zeroD/Reactor.h +++ b/include/cantera/zeroD/Reactor.h @@ -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; } @@ -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*. diff --git a/include/cantera/zeroD/ReactorBase.h b/include/cantera/zeroD/ReactorBase.h index 054079c0ad2..87cea10cd60 100644 --- a/include/cantera/zeroD/ReactorBase.h +++ b/include/cantera/zeroD/ReactorBase.h @@ -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; @@ -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; } @@ -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; diff --git a/include/cantera/zeroD/ReactorFactory.h b/include/cantera/zeroD/ReactorFactory.h index 23b21cd8cfe..02161f51335 100644 --- a/include/cantera/zeroD/ReactorFactory.h +++ b/include/cantera/zeroD/ReactorFactory.h @@ -46,6 +46,8 @@ class ReactorFactory : public Factory * @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; @@ -53,6 +55,7 @@ class ReactorFactory : public Factory protected: //! Map containing reactor type identifier / reactor type name pairs. + //! @deprecated To be removed after Cantera 2.5. std::unordered_map m_types; private: diff --git a/include/cantera/zeroD/Reservoir.h b/include/cantera/zeroD/Reservoir.h index ed0812b93a0..427fa9380e1 100644 --- a/include/cantera/zeroD/Reservoir.h +++ b/include/cantera/zeroD/Reservoir.h @@ -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) {} diff --git a/include/cantera/zeroD/Wall.h b/include/cantera/zeroD/Wall.h index ae0996551d5..a7619c9bbbb 100644 --- a/include/cantera/zeroD/Wall.h +++ b/include/cantera/zeroD/Wall.h @@ -17,6 +17,8 @@ class Kinetics; class SurfPhase; class Func1; +//! Magic numbers +//! @deprecated To be removed after Cantera 2.5. const int WallType = 1; /** diff --git a/include/cantera/zeroD/WallFactory.h b/include/cantera/zeroD/WallFactory.h index 45040cd796c..55135f09ba2 100644 --- a/include/cantera/zeroD/WallFactory.h +++ b/include/cantera/zeroD/WallFactory.h @@ -46,6 +46,8 @@ class WallFactory : public Factory * @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; @@ -53,6 +55,7 @@ class WallFactory : public Factory protected: //! Map containing wall type identifier / wall type name pairs. + //! @deprecated To be removed after Cantera 2.5. std::unordered_map m_types; private: diff --git a/include/cantera/zeroD/flowControllers.h b/include/cantera/zeroD/flowControllers.h index 72097c4389f..4b1efb3826f 100644 --- a/include/cantera/zeroD/flowControllers.h +++ b/include/cantera/zeroD/flowControllers.h @@ -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; } @@ -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; } @@ -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); } diff --git a/interfaces/cython/cantera/_cantera.pxd b/interfaces/cython/cantera/_cantera.pxd index d024f33df22..ded63dc2556 100644 --- a/interfaces/cython/cantera/_cantera.pxd +++ b/interfaces/cython/cantera/_cantera.pxd @@ -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 @@ -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*) diff --git a/interfaces/cython/cantera/reactor.pyx b/interfaces/cython/cantera/reactor.pyx index 7d495271ccb..ade9de5d7a0 100644 --- a/interfaces/cython/cantera/reactor.pyx +++ b/interfaces/cython/cantera/reactor.pyx @@ -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): @@ -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()) @@ -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* diff --git a/interfaces/cython/cantera/test/test_reactor.py b/interfaces/cython/cantera/test/test_reactor.py index b39c77c3c46..784906133d1 100644 --- a/interfaces/cython/cantera/test/test_reactor.py +++ b/interfaces/cython/cantera/test/test_reactor.py @@ -77,6 +77,10 @@ def test_names(self): self.r1.name = 'hello' self.assertEqual(self.r1.name, 'hello') + def test_types(self): + self.make_reactors() + self.assertEqual(self.r1.type, self.reactorClass.__name__) + def test_component_index(self): self.make_reactors(n_reactors=1) self.net.step() @@ -438,6 +442,7 @@ def test_mass_flow_controller(self): mfc = ct.MassFlowController(reservoir, self.r1) mfc.set_mass_flow_rate(lambda t: 0.1 if 0.2 <= t < 1.2 else 0.0) + self.assertEqual(mfc.type, type(mfc).__name__) self.assertEqual(len(reservoir.inlets), 0) self.assertEqual(len(reservoir.outlets), 1) self.assertEqual(reservoir.outlets[0], mfc) diff --git a/interfaces/matlab/toolbox/@FlowDevice/FlowDevice.m b/interfaces/matlab/toolbox/@FlowDevice/FlowDevice.m index d34c78afcd5..311e9aa41f0 100644 --- a/interfaces/matlab/toolbox/@FlowDevice/FlowDevice.m +++ b/interfaces/matlab/toolbox/@FlowDevice/FlowDevice.m @@ -13,16 +13,24 @@ % See also: :mat:func:`MassFlowController`, :mat:func:`Valve` % % :param typ: -% Type of :mat:func:`FlowDevice` to be created. ``typ=1`` for -% :mat:func:`MassFlowController` and ``typ=3`` for +% Type of :mat:func:`FlowDevice` to be created. ``typ='MassFlowController'`` +% for :mat:func:`MassFlowController`, ``typ='MassFlowController'`` for +% :mat:func:`PressureController` and ``typ='Valve'`` for % :mat:func:`Valve` % :return: % Instance of class :mat:func:`FlowDevice` % if nargin == 0 - typ = 1; + typ = 'MassFlowController'; end + +if ~isstring(typ) + warning('Definition via integer type to be deprecated after Cantera 2.5') + device_types = ['MassFlowController' 'PressureController' 'Valve']; + typ = device_types(typ); +end + x.index = flowdevicemethods(0, typ); if x.index < 0 error(geterr); diff --git a/interfaces/matlab/toolbox/@Reactor/Reactor.m b/interfaces/matlab/toolbox/@Reactor/Reactor.m index a5e528953b3..e4b416f8d9d 100644 --- a/interfaces/matlab/toolbox/@Reactor/Reactor.m +++ b/interfaces/matlab/toolbox/@Reactor/Reactor.m @@ -18,14 +18,14 @@ % Instance of class :mat:func:`Solution` representing the contents of the % reactor % :param typ: -% Integer, reactor type. Options are: +% String, reactor type. Options are: % -% 1. Reservoir -% 2. Reactor -% 3. Flow Reactor -% 4. Constant Pressure Reactor -% 5. Ideal Gas Reactor -% 6. Ideal Gas Constant Pressure Reactor +% 'Reservoir' +% 'Reactor' +% 'FlowReactor' +% 'ConstPressureReactor' +% 'IdealGasReactor' +% 'IdealGasConstPressureReactor' % % :return: % Instance of class :mat:func:`Reactor` @@ -33,13 +33,21 @@ if nargin == 0 contents = 0; - typ = 2; + typ = 'Reactor'; elseif nargin == 1 - typ = 2; + typ = 'Reactor'; elseif nargin > 2 error('too many arguments'); end +if ~isstring(typ) + warning('Definition via integer type to be deprecated after Cantera 2.5') + reactor_types = ['Reservoir' 'Reactor' 'FlowReactor' ... + 'ConstPressureReactor' 'IdealGasReactor' ... + 'IdealGasConstPressureReactor']; + typ = reactor_types(typ); +end + x.index = reactormethods(0, typ); if x.index < 0 error(geterr); diff --git a/interfaces/matlab/toolbox/@Wall/Wall.m b/interfaces/matlab/toolbox/@Wall/Wall.m index f575d56d7a1..157ba26afac 100644 --- a/interfaces/matlab/toolbox/@Wall/Wall.m +++ b/interfaces/matlab/toolbox/@Wall/Wall.m @@ -57,8 +57,8 @@ % :return: % Instance of class :mat:func:`Wall` -% This is a dummy argument, it is not actually used by wall_new in ctreactor.cpp -typ = 1; +% At the moment, only one wall type is implemented +typ = "Wall"; x.index = wallmethods(0, typ); diff --git a/interfaces/matlab/toolbox/ConstPressureReactor.m b/interfaces/matlab/toolbox/ConstPressureReactor.m index 18987968c22..45c80acd853 100644 --- a/interfaces/matlab/toolbox/ConstPressureReactor.m +++ b/interfaces/matlab/toolbox/ConstPressureReactor.m @@ -23,4 +23,4 @@ if nargin == 0 contents = 0; end -r = Reactor(contents, 4); +r = Reactor(contents, 'ConstPressureReactor'); diff --git a/interfaces/matlab/toolbox/FlowReactor.m b/interfaces/matlab/toolbox/FlowReactor.m index 07cb67a84d9..c1b6a16e653 100644 --- a/interfaces/matlab/toolbox/FlowReactor.m +++ b/interfaces/matlab/toolbox/FlowReactor.m @@ -21,4 +21,4 @@ if nargin == 0 contents = 0; end -r = Reactor(contents, 3); +r = Reactor(contents, 'FlowReactor'); diff --git a/interfaces/matlab/toolbox/IdealGasConstPressureReactor.m b/interfaces/matlab/toolbox/IdealGasConstPressureReactor.m index 80f9db1ff45..89b13f3ef7d 100644 --- a/interfaces/matlab/toolbox/IdealGasConstPressureReactor.m +++ b/interfaces/matlab/toolbox/IdealGasConstPressureReactor.m @@ -25,4 +25,4 @@ if nargin == 0 contents = 0; end -r = Reactor(contents, 6); +r = Reactor(contents, 'IdealGasConstPressureReactor'); diff --git a/interfaces/matlab/toolbox/IdealGasReactor.m b/interfaces/matlab/toolbox/IdealGasReactor.m index 8427053983e..769daf68b0a 100644 --- a/interfaces/matlab/toolbox/IdealGasReactor.m +++ b/interfaces/matlab/toolbox/IdealGasReactor.m @@ -22,4 +22,4 @@ if nargin == 0 contents = 0; end -r = Reactor(contents, 5); +r = Reactor(contents, 'IdealGasReactor'); diff --git a/interfaces/matlab/toolbox/MassFlowController.m b/interfaces/matlab/toolbox/MassFlowController.m index ae3708d6487..e006cf96293 100644 --- a/interfaces/matlab/toolbox/MassFlowController.m +++ b/interfaces/matlab/toolbox/MassFlowController.m @@ -19,7 +19,7 @@ % Instance of class :mat:func:`FlowDevice` % -m = FlowDevice(1); +m = FlowDevice('MassFlowController'); if nargin == 2 install(m, upstream, downstream) end diff --git a/interfaces/matlab/toolbox/Reservoir.m b/interfaces/matlab/toolbox/Reservoir.m index 6f75162bc99..f27c4d5c1c8 100644 --- a/interfaces/matlab/toolbox/Reservoir.m +++ b/interfaces/matlab/toolbox/Reservoir.m @@ -27,4 +27,4 @@ if nargin == 0 contents = 0; end -r = Reactor(contents, 1); +r = Reactor(contents, 'Reservoir'); diff --git a/interfaces/matlab/toolbox/Valve.m b/interfaces/matlab/toolbox/Valve.m index b330c009644..029dc43aec4 100644 --- a/interfaces/matlab/toolbox/Valve.m +++ b/interfaces/matlab/toolbox/Valve.m @@ -30,7 +30,7 @@ % Instance of class :mat:func:`FlowDevice` % -v = FlowDevice(3); +v = FlowDevice('Valve'); if nargin == 2 install(v, upstream, downstream) end diff --git a/src/clib/ctreactor.cpp b/src/clib/ctreactor.cpp index 80221cf9192..674a77085a7 100644 --- a/src/clib/ctreactor.cpp +++ b/src/clib/ctreactor.cpp @@ -35,7 +35,22 @@ extern "C" { // reactor + //! @deprecated To be changed after Cantera 2.5. int reactor_new(int type) + { + warn_deprecated("reactor_new(int)", + "To be changed after Cantera 2.5. " + "Argument changed to string instead of int; use" + "reactor_new2(char*) during transition."); + try { + ReactorBase* r = ReactorFactory::factory()->newReactor(type); + return ReactorCabinet::add(r); + } catch (...) { + return handleAllExceptions(-1, ERR); + } + } + + int reactor_new2(const char* type) { try { ReactorBase* r = ReactorFactory::factory()->newReactor(type); @@ -79,7 +94,7 @@ extern "C" { { try { // @todo This should not fail silently - if (ReactorCabinet::item(i).type() >= ReactorType) { + if (ReactorCabinet::item(i).hasEquations()) { ReactorCabinet::get(i).setKineticsMgr(KineticsCabinet::item(n)); } return 0; @@ -164,7 +179,7 @@ extern "C" { { try { // @todo This should not fail silently - if (ReactorCabinet::item(i).type() >= ReactorType) { + if (ReactorCabinet::item(i).hasEquations()) { ReactorCabinet::get(i).setChemistry(cflag != 0); } return 0; @@ -177,7 +192,7 @@ extern "C" { { try { // @todo This should not fail silently - if (ReactorCabinet::item(i).type() >= ReactorType) { + if (ReactorCabinet::item(i).hasEquations()) { ReactorCabinet::get(i).setEnergy(eflag); } return 0; @@ -345,6 +360,20 @@ extern "C" { // flow devices int flowdev_new(int type) + { + warn_deprecated("flowdev_new(int)", + "To be changed after Cantera 2.5. " + "Argument changed to string instead of int; use" + "flowdev_new2(char*) during transition."); + try { + FlowDevice* f = FlowDeviceFactory::factory()->newFlowDevice(type); + return FlowDeviceCabinet::add(f); + } catch (...) { + return handleAllExceptions(-1, ERR); + } + } + + int flowdev_new2(const char* type) { try { FlowDevice* f = FlowDeviceFactory::factory()->newFlowDevice(type); @@ -431,6 +460,20 @@ extern "C" { ///////////// Walls /////////////////////// int wall_new(int type) + { + warn_deprecated("wall_new(int)", + "To be changed after Cantera 2.5. " + "Argument changed to string instead of int; use" + "wall_new2(char*) during transition."); + try { + WallBase* w = WallFactory::factory()->newWall(type); + return WallCabinet::add(w); + } catch (...) { + return handleAllExceptions(-1, ERR); + } + } + + int wall_new2(const char* type) { try { WallBase* w = WallFactory::factory()->newWall(type); diff --git a/src/matlab/flowdevicemethods.cpp b/src/matlab/flowdevicemethods.cpp index 98b74dba8cb..bcab8cb69cd 100644 --- a/src/matlab/flowdevicemethods.cpp +++ b/src/matlab/flowdevicemethods.cpp @@ -10,8 +10,6 @@ void flowdevicemethods(int nlhs, mxArray* plhs[], { int m, iok = 0, n; int job = getInt(prhs[1]); - int i = getInt(prhs[2]); - double r = Undef; double v = Undef; if (nrhs > 3) { @@ -20,7 +18,9 @@ void flowdevicemethods(int nlhs, mxArray* plhs[], // constructor if (job == 0) { - n = flowdev_new(i); + char* type = getInt(prhs[2]); + + n = flowdev_new2(type); plhs[0] = mxCreateNumericMatrix(1,1,mxDOUBLE_CLASS,mxREAL); double* h = mxGetPr(plhs[0]); *h = double(n); @@ -32,7 +32,9 @@ void flowdevicemethods(int nlhs, mxArray* plhs[], // options that do not return a value + int i = getInt(prhs[2]); if (job < 20) { + switch (job) { case 1: iok = flowdev_del(i); diff --git a/src/matlab/reactormethods.cpp b/src/matlab/reactormethods.cpp index 5254377101c..ba381813a54 100644 --- a/src/matlab/reactormethods.cpp +++ b/src/matlab/reactormethods.cpp @@ -14,7 +14,6 @@ void reactormethods(int nlhs, mxArray* plhs[], { int iok = 0, n; int job = getInt(prhs[1]); - int i = getInt(prhs[2]); double r = Undef; double v = Undef; if (nrhs > 3) { @@ -23,7 +22,9 @@ void reactormethods(int nlhs, mxArray* plhs[], // constructor if (job == 0) { - n = reactor_new(i); + char* type = getInt(prhs[2]); + + n = reactor_new2(type); plhs[0] = mxCreateNumericMatrix(1,1,mxDOUBLE_CLASS,mxREAL); double* h = mxGetPr(plhs[0]); *h = double(n); @@ -34,6 +35,8 @@ void reactormethods(int nlhs, mxArray* plhs[], } // options that do not return a value + + int i = getInt(prhs[2]); if (job < 20) { switch (job) { case 1: diff --git a/src/matlab/wallmethods.cpp b/src/matlab/wallmethods.cpp index 6feefb575af..b018091bc0f 100644 --- a/src/matlab/wallmethods.cpp +++ b/src/matlab/wallmethods.cpp @@ -14,7 +14,6 @@ void wallmethods(int nlhs, mxArray* plhs[], { int m, iok = 0, n; int job = getInt(prhs[1]); - int i = getInt(prhs[2]); double r = Undef; double v = Undef; if (nrhs > 3) { @@ -23,7 +22,8 @@ void wallmethods(int nlhs, mxArray* plhs[], // constructor if (job == 0) { - n = wall_new(i); + char* type = getInt(prhs[2]); + n = wall_new2(i); plhs[0] = mxCreateNumericMatrix(1,1,mxDOUBLE_CLASS,mxREAL); double* h = mxGetPr(plhs[0]); *h = double(n); @@ -34,6 +34,8 @@ void wallmethods(int nlhs, mxArray* plhs[], } // options that do not return a value + + int i = getInt(prhs[2]); if (job < 20) { switch (job) { case 1: diff --git a/src/zeroD/ReactorNet.cpp b/src/zeroD/ReactorNet.cpp index 389da711234..fc07dee13da 100644 --- a/src/zeroD/ReactorNet.cpp +++ b/src/zeroD/ReactorNet.cpp @@ -91,7 +91,7 @@ void ReactorNet::initialize() writelog("Reactor {:d}: {:d} variables.\n", n, nv); writelog(" {:d} sensitivity params.\n", r.nSensParams()); } - if (r.type() == FlowReactorType && m_reactors.size() > 1) { + if (r.typeStr() == "FlowReactor" && m_reactors.size() > 1) { throw CanteraError("ReactorNet::initialize", "FlowReactors must be used alone."); } diff --git a/test_problems/clib_test/clib_test.c b/test_problems/clib_test/clib_test.c index 17fc7bd1bb3..24cb1a6a353 100644 --- a/test_problems/clib_test/clib_test.c +++ b/test_problems/clib_test/clib_test.c @@ -72,7 +72,7 @@ int main(int argc, char** argv) assert(ret == 0); printf("\ntime Temperature\n"); - int reactor = reactor_new(5); + int reactor = reactor_new2("IdealGasReactor"); int net = reactornet_new(); ret = reactor_setThermoMgr(reactor, thermo); assert(ret == 0);