diff --git a/include/cantera/clib/ctreactor.h b/include/cantera/clib/ctreactor.h index 1567e3f4022..8d2e746d140 100644 --- a/include/cantera/clib/ctreactor.h +++ b/include/cantera/clib/ctreactor.h @@ -16,6 +16,8 @@ extern "C" { CANTERA_CAPI int reactor_new(const char* type, int n, const char* name); CANTERA_CAPI int reactor_del(int i); + CANTERA_CAPI int reactor_name(int i, int len, char* nbuf); + CANTERA_CAPI int reactor_setName(int i, const char* name); CANTERA_CAPI int reactor_setInitialVolume(int i, double v); CANTERA_CAPI int reactor_setChemistry(int i, int cflag); CANTERA_CAPI int reactor_setEnergy(int i, int eflag); @@ -46,8 +48,10 @@ 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(const char* type); + CANTERA_CAPI int flowdev_new(const char* type, const char* name); CANTERA_CAPI int flowdev_del(int i); + CANTERA_CAPI int flowdev_name(int i, int len, char* nbuf); + CANTERA_CAPI int flowdev_setName(int i, const char* name); CANTERA_CAPI int flowdev_install(int i, int n, int m); CANTERA_CAPI int flowdev_setPrimary(int i, int n); CANTERA_CAPI double flowdev_massFlowRate(int i); @@ -57,8 +61,10 @@ extern "C" { CANTERA_CAPI int flowdev_setPressureFunction(int i, int n); CANTERA_CAPI int flowdev_setTimeFunction(int i, int n); - CANTERA_CAPI int wall_new(const char* type); + CANTERA_CAPI int wall_new(const char* type, const char* name); CANTERA_CAPI int wall_del(int i); + CANTERA_CAPI int wall_name(int i, int len, char* nbuf); + CANTERA_CAPI int wall_setName(int i, const char* name); CANTERA_CAPI int wall_install(int i, int n, int m); CANTERA_CAPI double wall_expansionRate(int i); CANTERA_CAPI double wall_heatRate(int i); @@ -72,8 +78,10 @@ extern "C" { CANTERA_CAPI int wall_setEmissivity(int i, double epsilon); CANTERA_CAPI int wall_ready(int i); - CANTERA_CAPI int reactorsurface_new(int type); + CANTERA_CAPI int reactorsurface_new(); CANTERA_CAPI int reactorsurface_del(int i); + CANTERA_CAPI int reactorsurface_name(int i, int len, char* nbuf); + CANTERA_CAPI int reactorsurface_setName(int i, const char* name); CANTERA_CAPI int reactorsurface_install(int i, int n); CANTERA_CAPI int reactorsurface_setkinetics(int i, int n); CANTERA_CAPI double reactorsurface_area(int i); diff --git a/interfaces/matlab_experimental/Reactor/FlowDevice.m b/interfaces/matlab_experimental/Reactor/FlowDevice.m index fcd645ad539..0069902a173 100644 --- a/interfaces/matlab_experimental/Reactor/FlowDevice.m +++ b/interfaces/matlab_experimental/Reactor/FlowDevice.m @@ -30,6 +30,8 @@ properties (SetAccess = public) + name % name of flow device. + % Upstream object of type :mat:class:`Reactor` or :mat:class:`Reservoir`. upstream @@ -56,7 +58,7 @@ methods %% FlowDevice Class Constructor - function x = FlowDevice(typ) + function x = FlowDevice(typ, name) % Create a :mat:class:`FlowDevice` object. ctIsLoaded; @@ -64,9 +66,12 @@ if nargin == 0 error('please specify the type of flow device to be created'); end + if nargin < 2 + name = '(none)'; + end x.type = typ; - x.id = ctFunc('flowdev_new', typ); + x.id = ctFunc('flowdev_new', typ, name); x.upstream = -1; x.downstream = -1; end @@ -112,12 +117,20 @@ function install(f, upstream, downstream) %% FlowDevice Get Methods + function name = get.name(f) + name = ctString('flowdev_name', f.id); + end + function mdot = get.massFlowRate(f) mdot = ctFunc('flowdev_massFlowRate2', f.id); end %% FlowDevice Set Methods + function set.name(f, name) + ctFunc('flowdev_setName', f.id, name); + end + function set.massFlowRate(f, mdot) if strcmp(f.type, 'MassFlowController') diff --git a/interfaces/matlab_experimental/Reactor/Reactor.m b/interfaces/matlab_experimental/Reactor/Reactor.m index 8f7b3d15114..14043868942 100644 --- a/interfaces/matlab_experimental/Reactor/Reactor.m +++ b/interfaces/matlab_experimental/Reactor/Reactor.m @@ -9,6 +9,8 @@ properties (SetAccess = public) + name % Name of reactor. + contents % Density of the reactor contents at the end of the last call to @@ -158,6 +160,10 @@ function addSensitivityReaction(r, m) %% Reactor Get Methods + function name = get.name(r) + name = ctString('reactor_name', r.id); + end + function temperature = get.T(r) temperature = ctFunc('reactor_temperature', r.id); end @@ -213,6 +219,10 @@ function addSensitivityReaction(r, m) %% Reactor set methods + function set.name(r, name) + ctFunc('reactor_setName', r.id, name); + end + function set.V(r, v0) ctFunc('reactor_setInitialVolume', r.id, v0); diff --git a/interfaces/matlab_experimental/Reactor/Wall.m b/interfaces/matlab_experimental/Reactor/Wall.m index 05721aaddbd..4712dc1e2da 100644 --- a/interfaces/matlab_experimental/Reactor/Wall.m +++ b/interfaces/matlab_experimental/Reactor/Wall.m @@ -52,6 +52,8 @@ properties (SetAccess = protected) + name % Name of wall. + left % Reactor on the left. right % Reactor on the right. @@ -87,15 +89,18 @@ methods %% Wall Class Constructor - function w = Wall(l, r) + function w = Wall(l, r, name) % Create a :mat:class:`Wall` object. ctIsLoaded; % At the moment, only one wall type is implemented typ = 'Wall'; + if nargin < 3 + name = '(none)'; + end w.type = char(typ); - w.id = ctFunc('wall_new', w.type); + w.id = ctFunc('wall_new', w.type, name); % Install the wall between left and right reactors w.left = l; @@ -127,6 +132,10 @@ function delete(w) %% ReactorNet get methods + function name = get.name(w) + name = ctString('wall_name', w.id); + end + function a = get.area(w) a = ctFunc('wall_area', w.id); end @@ -141,6 +150,10 @@ function delete(w) %% ReactorNet set methods + function set.name(w, name) + ctFunc('wall_setName', w.id, name); + end + function set.area(w, a) ctFunc('wall_setArea', w.id, a); end diff --git a/src/clib/ctreactor.cpp b/src/clib/ctreactor.cpp index 096a5f2680b..b8877a1d06b 100644 --- a/src/clib/ctreactor.cpp +++ b/src/clib/ctreactor.cpp @@ -12,6 +12,7 @@ #include "cantera/thermo/ThermoPhase.h" #include "cantera/kinetics/Kinetics.h" #include "cantera/zerodim.h" +#include "cantera/base/stringUtils.h" #include "clib_utils.h" using namespace Cantera; @@ -59,6 +60,26 @@ extern "C" { } } + int reactor_name(int i, int len, char* nbuf) + { + try { + return static_cast( + copyString(ReactorCabinet::item(i).name(), nbuf, len)); + } catch (...) { + return handleAllExceptions(-1, ERR); + } + } + + int reactor_setName(int i, const char* name) + { + try { + ReactorCabinet::item(i).setName(name); + return 0; + } catch (...) { + return handleAllExceptions(-1, ERR); + } + } + int reactor_setInitialVolume(int i, double v) { try { @@ -349,10 +370,10 @@ extern "C" { // flow devices - int flowdev_new(const char* type) + int flowdev_new(const char* type, const char* name) { try { - return FlowDeviceCabinet::add(newFlowDevice(type)); + return FlowDeviceCabinet::add(newFlowDevice(type, name)); } catch (...) { return handleAllExceptions(-1, ERR); } @@ -368,6 +389,26 @@ extern "C" { } } + int flowdev_name(int i, int len, char* nbuf) + { + try { + return static_cast( + copyString(FlowDeviceCabinet::item(i).name(), nbuf, len)); + } catch (...) { + return handleAllExceptions(-1, ERR); + } + } + + int flowdev_setName(int i, const char* name) + { + try { + FlowDeviceCabinet::item(i).setName(name); + return 0; + } catch (...) { + return handleAllExceptions(-1, ERR); + } + } + int flowdev_install(int i, int n, int m) { try { @@ -455,10 +496,10 @@ extern "C" { ///////////// Walls /////////////////////// - int wall_new(const char* type) + int wall_new(const char* type, const char* name) { try { - return WallCabinet::add(newWall(type)); + return WallCabinet::add(newWall(type, name)); } catch (...) { return handleAllExceptions(-1, ERR); } @@ -474,6 +515,26 @@ extern "C" { } } + int wall_name(int i, int len, char* nbuf) + { + try { + return static_cast( + copyString(WallCabinet::item(i).name(), nbuf, len)); + } catch (...) { + return handleAllExceptions(-1, ERR); + } + } + + int wall_setName(int i, const char* name) + { + try { + WallCabinet::item(i).setName(name); + return 0; + } catch (...) { + return handleAllExceptions(-1, ERR); + } + } + int wall_install(int i, int n, int m) { try { @@ -593,7 +654,7 @@ extern "C" { // ReactorSurface - int reactorsurface_new(int type) + int reactorsurface_new() { try { return ReactorSurfaceCabinet::add(make_shared()); @@ -612,6 +673,26 @@ extern "C" { } } + int reactorsurface_name(int i, int len, char* nbuf) + { + try { + return static_cast( + copyString(ReactorSurfaceCabinet::item(i).name(), nbuf, len)); + } catch (...) { + return handleAllExceptions(-1, ERR); + } + } + + int reactorsurface_setName(int i, const char* name) + { + try { + ReactorSurfaceCabinet::item(i).setName(name); + return 0; + } catch (...) { + return handleAllExceptions(-1, ERR); + } + } + int reactorsurface_install(int i, int n) { try { diff --git a/test/clib/test_ctreactor.cpp b/test/clib/test_ctreactor.cpp index 179f0326d3e..cd841743834 100644 --- a/test/clib/test_ctreactor.cpp +++ b/test/clib/test_ctreactor.cpp @@ -13,6 +13,15 @@ TEST(ctreactor, reactor_soln) int sol = soln_newSolution("gri30.yaml", "gri30", "none"); int reactor = reactor_new("IdealGasReactor", sol, "test"); ASSERT_EQ(reactor, 0); + + int ret = reactor_setName(reactor, "spam"); + ASSERT_EQ(ret, 0); + int buflen = reactor_name(reactor, 0, 0); + char* buf = new char[buflen]; + reactor_name(reactor, buflen, buf); + string rName = buf; + ASSERT_EQ(rName, "spam"); + delete[] buf; } vector T_ctreactor = {