diff --git a/interfaces/matlab/toolbox/@Reactor/setChemistry.m b/interfaces/matlab/toolbox/@Reactor/setChemistry.m new file mode 100644 index 000000000..3fb14062e --- /dev/null +++ b/interfaces/matlab/toolbox/@Reactor/setChemistry.m @@ -0,0 +1,29 @@ +function setChemistry(r, flag) +% SETCHEMISTRY Enable or disable changing reactor composition by reactions. +% setChemistry(r, flag) +% If the chemistry is disabled, then the reactor composition is +% constant. The parameter should be the string ``'on'`` to enable the +% species equations, or ``'off'`` to disable it. +% +% By default, Reactor objects are created with the species equations +% enabled if there are reactions present in the mechanism file, and +% disabled otherwise. :: +% +% >> setChemistry(r, 'on'); +% >> setChemistry(r, 'off'); +% +% :param r: +% Instance of class :mat:func:`Reactor` +% :param flag: +% String, either ``'on'`` or ``'off'`` to enable and disable +% solving the energy equation, respectively +% + +if strcmp(flag, {'on'}) + iflag = true; +elseif strcmp(flag, {'off'}) + iflag = false; +else + error('Input to setChemistry not understood. It must be either "on" or "off".'); +end +reactormethods(8, r.index, iflag); diff --git a/interfaces/matlab/toolbox/@Reactor/setEnergy.m b/interfaces/matlab/toolbox/@Reactor/setEnergy.m index 80ef46849..71d71675b 100644 --- a/interfaces/matlab/toolbox/@Reactor/setEnergy.m +++ b/interfaces/matlab/toolbox/@Reactor/setEnergy.m @@ -15,7 +15,7 @@ function setEnergy(r, flag) % :param r: % Instance of class :mat:func:`Reactor` % :param flag: -% String, either ``'on'`` or ``'off`` to enable and disable +% String, either ``'on'`` or ``'off'`` to enable and disable % solving the energy equation, respectively % diff --git a/src/clib/ctreactor.cpp b/src/clib/ctreactor.cpp index 6937fad79..f97f92392 100644 --- a/src/clib/ctreactor.cpp +++ b/src/clib/ctreactor.cpp @@ -169,6 +169,19 @@ extern "C" { } } + int reactor_setChemistry(int i, bool cflag) + { + try { + // @todo This should not fail silently + if (ReactorCabinet::item(i).type() >= ReactorType) { + ReactorCabinet::get(i).setChemistry(cflag); + } + return 0; + } catch (...) { + return handleAllExceptions(-1, ERR); + } + } + int reactor_setEnergy(int i, int eflag) { try { diff --git a/src/clib/ctreactor.h b/src/clib/ctreactor.h index e8733f21f..06eb9178b 100644 --- a/src/clib/ctreactor.h +++ b/src/clib/ctreactor.h @@ -11,6 +11,7 @@ extern "C" { CANTERA_CAPI int reactor_del(int i); CANTERA_CAPI int reactor_copy(int i); CANTERA_CAPI int reactor_setInitialVolume(int i, double v); + CANTERA_CAPI int reactor_setChemistry(int i, bool cflag); CANTERA_CAPI int reactor_setEnergy(int i, int eflag); CANTERA_CAPI int reactor_setThermoMgr(int i, int n); CANTERA_CAPI int reactor_setKineticsMgr(int i, int n); diff --git a/src/matlab/reactormethods.cpp b/src/matlab/reactormethods.cpp index 5bdc06f6d..b151fe4cd 100644 --- a/src/matlab/reactormethods.cpp +++ b/src/matlab/reactormethods.cpp @@ -48,6 +48,9 @@ void reactormethods(int nlhs, mxArray* plhs[], case 7: iok = reactor_setKineticsMgr(i, int(v)); break; + case 8: + iok = reactor_setChemistry(i, bool(v)); + break; case 9: iok = reactor_setEnergy(i, int(v)); break;