Skip to content

Commit

Permalink
[MATLAB] Update API & docstrings
Browse files Browse the repository at this point in the history
  • Loading branch information
ischoegl committed Aug 10, 2024
1 parent dfd1758 commit 266f862
Show file tree
Hide file tree
Showing 11 changed files with 82 additions and 92 deletions.
13 changes: 7 additions & 6 deletions interfaces/matlab_experimental/Reactor/ConstPressureReactor.m
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
classdef ConstPressureReactor < Reactor
% Create a constant pressure reactor object. ::
%
% >> r = ConstPressureReactor(contents)
% >> r = ConstPressureReactor(contents, name)
%
% A :mat:class:`ConstPressureReactor` is an instance of class
% :mat:class:`Reactor` where the pressure is held constant. The volume
Expand All @@ -10,26 +10,27 @@
%
% .. code-block:: matlab
%
% r1 = ConstPressureReactor % an empty reactor
% r2 = ConstPressureReactor(contents) % a reactor containing contents
%
% See also: :mat:class:`Reactor`
%
% :param contents:
% Cantera :mat:class:`Solution` to be set as the contents of the reactor.
% :param name:
% Reactor name (optional; default is ``(none)``).
% :return:
% Instance of class :mat:class:`ConstPressureReactor`.

methods

function r = ConstPressureReactor(contents)
function r = ConstPressureReactor(contents, name)
% Constructor

if nargin == 0
contents = 0;
if nargin < 2
name = '(none)'
end

r@Reactor(contents, 'ConstPressureReactor');
r@Reactor(contents, 'ConstPressureReactor', name);
end

end
Expand Down
6 changes: 4 additions & 2 deletions interfaces/matlab_experimental/Reactor/FlowDevice.m
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
classdef FlowDevice < handle
% FlowDevice Class ::
%
% >> x = FlowDevice(typ)
% >> x = FlowDevice(typ, name)
%
% Base class for devices that allow flow between reactors.
% :mat:class:`FlowDevice` objects are assumed to be adiabatic,
Expand All @@ -18,6 +18,8 @@
% Type of :mat:class:`FlowDevice` to be created. ``typ='MassFlowController'``
% for :mat:class:`MassFlowController`, ``typ='PressureController'`` for
% :mat:class:`PressureController`, and ``typ='Valve'`` for :mat:class:`Valve`.
% :param name:
% Reactor name (optional; default is ``(none)``).
% :return:
% Instance of class :mat:class:`FlowDevice`.

Expand All @@ -30,7 +32,7 @@

properties (SetAccess = public)

name % name of flow device.
name % Name of flow device.

% Upstream object of type :mat:class:`Reactor` or :mat:class:`Reservoir`.
upstream
Expand Down
13 changes: 7 additions & 6 deletions interfaces/matlab_experimental/Reactor/FlowReactor.m
Original file line number Diff line number Diff line change
@@ -1,33 +1,34 @@
classdef FlowReactor < Reactor
% Create a flow reactor object. ::
%
% >> r = FlowReactor(contents)
% >> r = FlowReactor(contents, name)
%
% A reactor representing adiabatic plug flow in a constant-area
% duct. Examples:
%
% .. code-block:: matlab
%
% r1 = FlowReactor % an empty reactor
% r2 = FlowReactor(gas) % a reactor containing a gas
%
% See also: :mat:class:`Reactor`
%
% :param contents:
% Cantera :mat:class:`Solution` to be set as the contents of the reactor.
% :param name:
% Reactor name (optional; default is ``(none)``).
% :return:
% Instance of class :mat:class:`FlowReactor`.

methods

function r = FlowReactor(contents)
function r = FlowReactor(contents, name)
% Constructor

if nargin == 0
contents = 0;
if nargin < 2
name = '(none)'
end

r@Reactor(contents, 'FlowReactor');
r@Reactor(contents, 'FlowReactor', name);
end

end
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
classdef IdealGasConstPressureReactor < Reactor
% Create a constant pressure reactor with an ideal gas. ::
%
% >> r = IdealGasConstPressureReactor(contents)
% >> r = IdealGasConstPressureReactor(contents, name)
%
% An :mat:class:`IdealGasConstPressureReactor` is an instance of
% :mat:class:`Reactor` where the pressure is held constant.
Expand All @@ -13,26 +13,27 @@
%
% .. code-block:: matlab
%
% r1 = IdealGasConstPressureReactor % an empty reactor
% r2 = IdealGasConstPressureReactor(gas) % a reactor containing a gas
%
% See also: :mat:class:`Reactor`
%
% :param contents:
% Cantera :mat:class:`Solution` to be set as the contents of the reactor.
% :param name:
% Reactor name (optional; default is ``(none)``).
% :return:
% Instance of class :mat:class:`IdealGasConstPressureReactor`.

methods

function r = IdealGasConstPressureReactor(contents)
function r = IdealGasConstPressureReactor(contents, name)
% Constructor

if nargin == 0
contents = 0;
if nargin < 2
name = '(none)';
end

r@Reactor(contents, 'IdealGasConstPressureReactor');
r@Reactor(contents, 'IdealGasConstPressureReactor', name);
end

end
Expand Down
13 changes: 7 additions & 6 deletions interfaces/matlab_experimental/Reactor/IdealGasReactor.m
Original file line number Diff line number Diff line change
@@ -1,34 +1,35 @@
classdef IdealGasReactor < Reactor
% Create a reactor with an ideal gas. ::
%
% >> r = IdealGasReactor(contents)
% >> r = IdealGasReactor(contents, name)
%
% An :mat:class:`IdealGasReactor` is an instance of :mat:class:`Reactor` where
% the governing equations are specialized for the ideal gas equation of state
% (and do not work correctly with other thermodynamic models). Examples:
%
% .. code-block:: matlab
%
% r1 = IdealGasReactor % an empty reactor
% r2 = IdealGasReactor(gas) % a reactor containing a gas
%
% See also: :mat:class:`Reactor`
%
% :param contents:
% Cantera :mat:class:`Solution` to be set as the contents of the reactor.
% :param name:
% Reactor name (optional; default is ``(none)``).
% :return:
% Instance of class :mat:class:`IdealGasReactor`.

methods

function r = IdealGasReactor(contents)
function r = IdealGasReactor(contents, name)
% Constructor

if nargin == 0
contents = 0;
if nargin < 2
name = '(none)';
end

r@Reactor(contents, 'IdealGasReactor');
r@Reactor(contents, 'IdealGasReactor', name);
end

end
Expand Down
14 changes: 8 additions & 6 deletions interfaces/matlab_experimental/Reactor/MassFlowController.m
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
classdef MassFlowController < FlowDevice
% Create a mass flow controller. ::
%
% >> m = MassFlowController(upstream, downstream)
% >> m = MassFlowController(upstream, downstream, name)
%
% Creates an instance of class :mat:class:`FlowDevice` configured to
% simulate a mass flow controller that maintains a constant mass flow
Expand All @@ -17,20 +17,22 @@
% Upstream :mat:class:`Reactor` or :mat:class:`Reservoir`.
% :param downstream:
% Downstream :mat:class:`Reactor` or :mat:class:`Reservoir`.
% :param name:
% Flow device name (optional; default is ``(none)``).
% :return:
% Instance of class :mat:class:`FlowDevice`.

methods

function m = MassFlowController(upstream, downstream)
function m = MassFlowController(upstream, downstream, name)
% Constructor

m@FlowDevice('MassFlowController');

if nargin == 2
m.install(upstream, downstream)
if nargin < 3
name = '(none)';
end

m@FlowDevice('MassFlowController', name);
m.install(upstream, downstream)
end

end
Expand Down
64 changes: 21 additions & 43 deletions interfaces/matlab_experimental/Reactor/ReactorSurface.m
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
classdef ReactorSurface < handle
% ReactorSurface Class ::
%
% >> s = ReactorSurface(surf, reactor, area)
% >> s = ReactorSurface(surf, reactor, name)
%
% A surface on which heterogeneous reactions take place. The
% mechanism object (typically an instance of :mat:class:`Interface`)
Expand All @@ -10,75 +10,45 @@
% temperature on each side is taken to be equal to the
% temperature of the reactor.
%
% Note: all of the arguments are optional and can be activated
% after initial construction by using the various methods of
% the :mat:class:`ReactorSurface` class.
%
% :param surf:
% Surface reaction mechanisms for the left-facing surface.
% This must bean instance of class :mat:class:`Kinetics`, or of a class
% derived from Kinetics, such as :mat:class:`Interface`.
% :param reactor:
% Instance of class 'Reactor' to be used as the adjacent bulk phase.
% :param area:
% The area of the surface in m^2. Defaults to 1.0 m^2 if not specified.
% :param name:
% Reactor surface name (optional; default is ``(none)``).
% :return:
% Instance of class :mat:class:`ReactorSurface`.

properties (SetAccess = immutable)
surfID
end

properties (SetAccess = protected)
reactor
end

properties (SetAccess = public)
name % Name of reactor surface.

area % Area of the reactor surface in m^2.
end

methods
%% ReactorSurface Class Constructor

function s = ReactorSurface(surf, reactor, area)
function s = ReactorSurface(surf, reactor, name)
% Create a :mat:class:`ReactorSurface` object.

ctIsLoaded;

s.surfID = ctFunc('reactorsurface_new', 0);
s.reactor = -1;

if nargin >= 1
ikin = 0;

if isa(surf, 'Kinetics')
ikin = surf.kinID;
end

ctFunc('reactorsurface_setkinetics', s.surfID, ikin);
end

if nargin >= 2

if isa(reactor, 'Reactor')
s.reactor = reactor;
ctFunc('reactorsurface_install', s.surfID, reactor.id);
else
warning('Reactor was not installed due to incorrect type');
end

if ~isa(surf, 'Kinetics') || ~isa(reactor, 'Reactor')
error('Invalid parameters.')
end

if nargin >= 3

if isnumeric(area)
s.area = area;
else
warning('Area was not a number and was not set');
end

if nargin < 3
name = '(none)';
end

s.surfID = ctFunc('reactorsurface_new', name);
ctFunc('reactorsurface_setkinetics', s.surfID, surf.kinID);
ctFunc('reactorsurface_install', s.surfID, reactor.id);
end

%% ReactorSurface Class Destructor
Expand Down Expand Up @@ -106,12 +76,20 @@ function addSensitivityReaction(s, m)

%% ReactorSurface Get Methods

function name = get.name(s)
name = ctString('reactorsurface_name', s.surfID);
end

function a = get.area(s)
a = ctFunc('reactorsurface_area', s.surfID);
end

%% ReactorSurface Set Methods

function set.name(s, name)
ctFunc('reactorsurface_setName', s.surfID, name);
end

function set.area(s, a)
ctFunc('reactorsurface_setArea', s.surfID, a);
end
Expand Down
13 changes: 7 additions & 6 deletions interfaces/matlab_experimental/Reactor/Reservoir.m
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
classdef Reservoir < Reactor
% Create a :mat:class:`Reservoir` object. ::
%
% >> r = Reservoir(contents)
% >> r = Reservoir(contents, name)
%
% A :mat:class:`Reservoir` is an instance of class :mat:class:`Reactor`
% configured so that its intensive state is constant in time. A reservoir
Expand All @@ -14,26 +14,27 @@
%
% .. code-block:: matlab
%
% r1 = Reservoir % an empty reservoir
% r2 = Reservoir(gas) % a reservoir containing a gas
%
% See also: :mat:class:`Reactor`
%
% :param contents:
% Cantera :mat:class:`Solution` to be set as the contents of the reactor.
% :param name:
% Reservoir name (optional; default is ``(none)``).
% :return:
% Instance of class :mat:class:`Reactor`.

methods

function r = Reservoir(contents)
function r = Reservoir(contents, name)
% Constructor

if nargin == 0
contents = 0;
if nargin < 2
name = '(none)';
end

r@Reactor(contents, 'Reservoir');
r@Reactor(contents, 'Reservoir', name);
end

end
Expand Down
Loading

0 comments on commit 266f862

Please sign in to comment.