mirror of
https://github.com/Cantera/cantera.git
synced 2025-02-25 18:55:29 -06:00
[MATLAB] Use CLib connector functions
This commit is contained in:
parent
bd5b2e29e8
commit
0ce3a7c3e1
@ -1,4 +1,4 @@
|
|||||||
classdef Interface < handle & ThermoPhase & Kinetics
|
classdef Interface < Solution
|
||||||
% Interface Class ::
|
% Interface Class ::
|
||||||
%
|
%
|
||||||
% >> s = Interface(src, name, p1, p2)
|
% >> s = Interface(src, name, p1, p2)
|
||||||
@ -13,11 +13,6 @@ classdef Interface < handle & ThermoPhase & Kinetics
|
|||||||
% :return:
|
% :return:
|
||||||
% Instance of class :mat:class:`Interface`.
|
% Instance of class :mat:class:`Interface`.
|
||||||
|
|
||||||
properties (SetAccess = immutable)
|
|
||||||
solnID % ID of the interface.
|
|
||||||
interfaceName % Name of the interface.
|
|
||||||
end
|
|
||||||
|
|
||||||
properties (SetAccess = public)
|
properties (SetAccess = public)
|
||||||
|
|
||||||
% Surface coverages of the species on an interface.
|
% Surface coverages of the species on an interface.
|
||||||
@ -50,11 +45,8 @@ classdef Interface < handle & ThermoPhase & Kinetics
|
|||||||
|
|
||||||
ID = ctFunc('soln_newInterface', src, name, na, adj);
|
ID = ctFunc('soln_newInterface', src, name, na, adj);
|
||||||
|
|
||||||
% Inherit methods and properties from ThermoPhase and Kinetics
|
% Inherit methods and properties from Solution
|
||||||
s@ThermoPhase(ID);
|
s@Solution(ID);
|
||||||
s@Kinetics(ID);
|
|
||||||
s.solnID = ID;
|
|
||||||
s.interfaceName = name;
|
|
||||||
s.nAdjacent = ctFunc('soln_nAdjacent', ID);
|
s.nAdjacent = ctFunc('soln_nAdjacent', ID);
|
||||||
s.adjacentNames = {};
|
s.adjacentNames = {};
|
||||||
for i = 1:s.nAdjacent
|
for i = 1:s.nAdjacent
|
||||||
@ -62,13 +54,6 @@ classdef Interface < handle & ThermoPhase & Kinetics
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
%% Interface Class Destructor
|
|
||||||
|
|
||||||
function delete(s)
|
|
||||||
% Delete :mat:class:`Interface` object.
|
|
||||||
ctFunc('soln_del', s.solnID);
|
|
||||||
end
|
|
||||||
|
|
||||||
%% Interface Get Methods
|
%% Interface Get Methods
|
||||||
|
|
||||||
function adj = adjacent(s, name)
|
function adj = adjacent(s, name)
|
||||||
|
84
interfaces/matlab_experimental/Reactor/Connector.m
Normal file
84
interfaces/matlab_experimental/Reactor/Connector.m
Normal file
@ -0,0 +1,84 @@
|
|||||||
|
classdef Connector < handle
|
||||||
|
% Connector Class ::
|
||||||
|
%
|
||||||
|
% >> c = Connector(typ, r1, r2, name)
|
||||||
|
%
|
||||||
|
% Base class for walls and flow devices.
|
||||||
|
%
|
||||||
|
% See also: :mat:class:`FlowDevice`, :mat:class:`Wall`
|
||||||
|
%
|
||||||
|
% :param typ:
|
||||||
|
% Type of connector.
|
||||||
|
% :param r1:
|
||||||
|
% Reactor one.
|
||||||
|
% :param r2:
|
||||||
|
% Reactor two.
|
||||||
|
% :param name:
|
||||||
|
% Connector name (optional; default is ``(none)``).
|
||||||
|
% :return:
|
||||||
|
% Instance of class :mat:class:`Connector`.
|
||||||
|
|
||||||
|
properties (SetAccess = immutable)
|
||||||
|
|
||||||
|
id % ID of Connector object.
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
properties (SetAccess = public)
|
||||||
|
|
||||||
|
type % Name of connector.
|
||||||
|
|
||||||
|
name % Name of connector.
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
methods
|
||||||
|
%% Connector Class Constructor
|
||||||
|
|
||||||
|
function c = Connector(typ, r1, r2, name)
|
||||||
|
% Create a :mat:class:`Connector` object.
|
||||||
|
|
||||||
|
ctIsLoaded;
|
||||||
|
|
||||||
|
if nargin < 3
|
||||||
|
error('please specify type and reactors');
|
||||||
|
end
|
||||||
|
if nargin < 4
|
||||||
|
name = '(none)';
|
||||||
|
end
|
||||||
|
|
||||||
|
if ~isa(r1, 'Reactor') || ~isa(r1, 'Reactor')
|
||||||
|
error(['Connectors can only be installed between', ...
|
||||||
|
'reactors or reservoirs']);
|
||||||
|
end
|
||||||
|
|
||||||
|
c.id = ctFunc('connector_new', typ, r1.id, r2.id, name);
|
||||||
|
end
|
||||||
|
|
||||||
|
%% Connector Class Destructor
|
||||||
|
|
||||||
|
function delete(c)
|
||||||
|
% Delete the :mat:class:`Connector` object.
|
||||||
|
|
||||||
|
ctFunc('connector_del', c.id);
|
||||||
|
end
|
||||||
|
|
||||||
|
%% Connector Get Methods
|
||||||
|
|
||||||
|
function typ = get.type(c)
|
||||||
|
typ = ctString('connector_type', c.id);
|
||||||
|
end
|
||||||
|
|
||||||
|
function name = get.name(c)
|
||||||
|
name = ctString('connector_name', c.id);
|
||||||
|
end
|
||||||
|
|
||||||
|
%% Connector Set Methods
|
||||||
|
|
||||||
|
function set.name(c, name)
|
||||||
|
ctFunc('connector_setName', c.id, name);
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
@ -1,4 +1,4 @@
|
|||||||
classdef FlowDevice < handle
|
classdef FlowDevice < Connector
|
||||||
% FlowDevice Class ::
|
% FlowDevice Class ::
|
||||||
%
|
%
|
||||||
% >> x = FlowDevice(typ, name)
|
% >> x = FlowDevice(typ, name)
|
||||||
@ -25,21 +25,16 @@ classdef FlowDevice < handle
|
|||||||
|
|
||||||
properties (SetAccess = immutable)
|
properties (SetAccess = immutable)
|
||||||
|
|
||||||
type % Type of flow device.
|
|
||||||
id % ID of FlowDevice object.
|
|
||||||
|
|
||||||
end
|
|
||||||
|
|
||||||
properties (SetAccess = public)
|
|
||||||
|
|
||||||
name % Name of flow device.
|
|
||||||
|
|
||||||
% Upstream object of type :mat:class:`Reactor` or :mat:class:`Reservoir`.
|
% Upstream object of type :mat:class:`Reactor` or :mat:class:`Reservoir`.
|
||||||
upstream
|
upstream
|
||||||
|
|
||||||
% Downstream object of type :mat:class:`Reactor` or :mat:class:`Reservoir`.
|
% Downstream object of type :mat:class:`Reactor` or :mat:class:`Reservoir`.
|
||||||
downstream
|
downstream
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
properties (SetAccess = public)
|
||||||
|
|
||||||
% The mass flow rate through the :mat:class:`FlowDevice` at the current time.
|
% The mass flow rate through the :mat:class:`FlowDevice` at the current time.
|
||||||
%
|
%
|
||||||
% The setter method can either take a double value or a function represented by
|
% The setter method can either take a double value or a function represented by
|
||||||
@ -60,79 +55,28 @@ classdef FlowDevice < handle
|
|||||||
methods
|
methods
|
||||||
%% FlowDevice Class Constructor
|
%% FlowDevice Class Constructor
|
||||||
|
|
||||||
function x = FlowDevice(typ, name)
|
function x = FlowDevice(typ, upstream, downstream, name)
|
||||||
% Create a :mat:class:`FlowDevice` object.
|
% Create a :mat:class:`FlowDevice` object.
|
||||||
|
|
||||||
ctIsLoaded;
|
ctIsLoaded;
|
||||||
|
|
||||||
if nargin == 0
|
if nargin < 4
|
||||||
error('please specify the type of flow device to be created');
|
|
||||||
end
|
|
||||||
if nargin < 2
|
|
||||||
name = '(none)';
|
name = '(none)';
|
||||||
end
|
end
|
||||||
|
|
||||||
x.type = typ;
|
x@Connector(typ, upstream, downstream, name)
|
||||||
x.id = ctFunc('flowdev_new', typ, name);
|
x.upstream = upstream;
|
||||||
x.upstream = -1;
|
x.downstream = downstream;
|
||||||
x.downstream = -1;
|
|
||||||
end
|
|
||||||
|
|
||||||
%% FlowDevice Class Destructor
|
|
||||||
|
|
||||||
function delete(f)
|
|
||||||
% Delete the :mat:class:`FlowDevice` object.
|
|
||||||
|
|
||||||
ctFunc('flowdev_del', f.id);
|
|
||||||
end
|
|
||||||
|
|
||||||
%% Utility Methods
|
|
||||||
|
|
||||||
function install(f, upstream, downstream)
|
|
||||||
% Install a flow device between reactors or reservoirs. ::
|
|
||||||
%
|
|
||||||
% >> f.install(upstream, downstream)
|
|
||||||
%
|
|
||||||
% :param f:
|
|
||||||
% Instance of class :mat:class:`FlowDevice` to install.
|
|
||||||
% :param upstream:
|
|
||||||
% Upstream :mat:class:`Reactor` or :mat:class:`Reservoir`.
|
|
||||||
% :param downstream:
|
|
||||||
% Downstream :mat:class:`Reactor` or :mat:class:`Reservoir`.
|
|
||||||
% :return:
|
|
||||||
% Instance of class :mat:class:`FlowDevice`.
|
|
||||||
|
|
||||||
if nargin == 3
|
|
||||||
|
|
||||||
if ~isa(upstream, 'Reactor') || ~isa(downstream, 'Reactor')
|
|
||||||
error(['Flow devices can only be installed between', ...
|
|
||||||
'reactors or reservoirs']);
|
|
||||||
end
|
|
||||||
|
|
||||||
i = upstream.id;
|
|
||||||
j = downstream.id;
|
|
||||||
ctFunc('flowdev_install', f.id, i, j);
|
|
||||||
else error('install requires 3 arguments');
|
|
||||||
end
|
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
%% FlowDevice Get Methods
|
%% FlowDevice Get Methods
|
||||||
|
|
||||||
function name = get.name(f)
|
|
||||||
name = ctString('flowdev_name', f.id);
|
|
||||||
end
|
|
||||||
|
|
||||||
function mdot = get.massFlowRate(f)
|
function mdot = get.massFlowRate(f)
|
||||||
mdot = ctFunc('flowdev_massFlowRate2', f.id);
|
mdot = ctFunc('flowdev_massFlowRate2', f.id);
|
||||||
end
|
end
|
||||||
|
|
||||||
%% FlowDevice Set Methods
|
%% FlowDevice Set Methods
|
||||||
|
|
||||||
function set.name(f, name)
|
|
||||||
ctFunc('flowdev_setName', f.id, name);
|
|
||||||
end
|
|
||||||
|
|
||||||
function set.massFlowRate(f, mdot)
|
function set.massFlowRate(f, mdot)
|
||||||
|
|
||||||
if strcmp(f.type, 'MassFlowController')
|
if strcmp(f.type, 'MassFlowController')
|
||||||
|
@ -31,8 +31,7 @@ classdef MassFlowController < FlowDevice
|
|||||||
name = '(none)';
|
name = '(none)';
|
||||||
end
|
end
|
||||||
|
|
||||||
m@FlowDevice('MassFlowController', name);
|
m@FlowDevice('MassFlowController', upstream, downstream, name);
|
||||||
m.install(upstream, downstream)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
@ -2,13 +2,14 @@ classdef Reactor < handle
|
|||||||
|
|
||||||
properties (SetAccess = immutable)
|
properties (SetAccess = immutable)
|
||||||
|
|
||||||
type % Type of Reactor.
|
|
||||||
id % ID of Reactor.
|
id % ID of Reactor.
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
properties (SetAccess = public)
|
properties (SetAccess = public)
|
||||||
|
|
||||||
|
type % Reactor type.
|
||||||
|
|
||||||
name % Name of reactor.
|
name % Name of reactor.
|
||||||
|
|
||||||
contents
|
contents
|
||||||
@ -131,8 +132,8 @@ classdef Reactor < handle
|
|||||||
error('Reactor contents must be an object of type "Solution"');
|
error('Reactor contents must be an object of type "Solution"');
|
||||||
end
|
end
|
||||||
|
|
||||||
r.type = char(typ);
|
|
||||||
r.id = ctFunc('reactor_new', typ, content.solnID, name);
|
r.id = ctFunc('reactor_new', typ, content.solnID, name);
|
||||||
|
r.contents = content;
|
||||||
end
|
end
|
||||||
|
|
||||||
%% Reactor Class Destructor
|
%% Reactor Class Destructor
|
||||||
@ -160,6 +161,10 @@ classdef Reactor < handle
|
|||||||
|
|
||||||
%% Reactor Get Methods
|
%% Reactor Get Methods
|
||||||
|
|
||||||
|
function typ = get.type(r)
|
||||||
|
typ = ctString('reactor_type', r.id);
|
||||||
|
end
|
||||||
|
|
||||||
function name = get.name(r)
|
function name = get.name(r)
|
||||||
name = ctString('reactor_name', r.id);
|
name = ctString('reactor_name', r.id);
|
||||||
end
|
end
|
||||||
|
@ -40,8 +40,7 @@ classdef Valve < FlowDevice
|
|||||||
name = '(none)';
|
name = '(none)';
|
||||||
end
|
end
|
||||||
|
|
||||||
v@FlowDevice('Valve', name);
|
v@FlowDevice('Valve', upstream, downstream, name);
|
||||||
v.install(upstream, downstream)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
classdef Wall < handle
|
classdef Wall < Connector
|
||||||
% Wall Class ::
|
% Wall Class ::
|
||||||
%
|
%
|
||||||
% >> x = Wall(l, r, name)
|
% >> x = Wall(l, r, name)
|
||||||
@ -47,15 +47,6 @@ classdef Wall < handle
|
|||||||
|
|
||||||
properties (SetAccess = immutable)
|
properties (SetAccess = immutable)
|
||||||
|
|
||||||
id
|
|
||||||
type
|
|
||||||
|
|
||||||
end
|
|
||||||
|
|
||||||
properties (SetAccess = protected)
|
|
||||||
|
|
||||||
name % Name of wall.
|
|
||||||
|
|
||||||
left % Reactor on the left.
|
left % Reactor on the left.
|
||||||
right % Reactor on the right.
|
right % Reactor on the right.
|
||||||
|
|
||||||
@ -93,49 +84,26 @@ classdef Wall < handle
|
|||||||
|
|
||||||
function w = Wall(l, r, name)
|
function w = Wall(l, r, name)
|
||||||
% Create a :mat:class:`Wall` object.
|
% Create a :mat:class:`Wall` object.
|
||||||
ctIsLoaded;
|
|
||||||
|
|
||||||
% At the moment, only one wall type is implemented
|
% At the moment, only one wall type is implemented
|
||||||
typ = 'Wall';
|
|
||||||
if nargin < 3
|
if nargin < 3
|
||||||
name = '(none)';
|
name = '(none)';
|
||||||
end
|
end
|
||||||
|
|
||||||
w.type = char(typ);
|
|
||||||
w.id = ctFunc('wall_new', w.type, name);
|
|
||||||
|
|
||||||
% Install the wall between left and right reactors
|
% Install the wall between left and right reactors
|
||||||
|
w@Connector('Wall', l, r, name)
|
||||||
w.left = l;
|
w.left = l;
|
||||||
w.right = r;
|
w.right = r;
|
||||||
ctFunc('wall_install', w.id, l.id, r.id);
|
|
||||||
|
|
||||||
% Set default values.
|
% Set default values.
|
||||||
w.area = 1.0;
|
w.area = 1.0;
|
||||||
w.expansionRateCoeff = 0.0;
|
w.expansionRateCoeff = 0.0;
|
||||||
w.heatTransferCoeff = 0.0;
|
w.heatTransferCoeff = 0.0;
|
||||||
|
|
||||||
% Check whether the wall is ready.
|
|
||||||
ok = ctFunc('wall_ready', w.id);
|
|
||||||
if ~ok
|
|
||||||
error('The wall object is not ready.');
|
|
||||||
end
|
|
||||||
|
|
||||||
end
|
|
||||||
|
|
||||||
%% Wall Class Destructor
|
|
||||||
|
|
||||||
function delete(w)
|
|
||||||
% Clear the :mat:class:`Wall` object.
|
|
||||||
|
|
||||||
ctFunc('wall_del', w.id);
|
|
||||||
end
|
end
|
||||||
|
|
||||||
%% ReactorNet get methods
|
%% ReactorNet get methods
|
||||||
|
|
||||||
function name = get.name(w)
|
|
||||||
name = ctString('wall_name', w.id);
|
|
||||||
end
|
|
||||||
|
|
||||||
function a = get.area(w)
|
function a = get.area(w)
|
||||||
a = ctFunc('wall_area', w.id);
|
a = ctFunc('wall_area', w.id);
|
||||||
end
|
end
|
||||||
@ -150,10 +118,6 @@ classdef Wall < handle
|
|||||||
|
|
||||||
%% ReactorNet set methods
|
%% ReactorNet set methods
|
||||||
|
|
||||||
function set.name(w, name)
|
|
||||||
ctFunc('wall_setName', w.id, name);
|
|
||||||
end
|
|
||||||
|
|
||||||
function set.area(w, a)
|
function set.area(w, a)
|
||||||
ctFunc('wall_setArea', w.id, a);
|
ctFunc('wall_setArea', w.id, a);
|
||||||
end
|
end
|
||||||
|
@ -73,8 +73,7 @@ function periodic_cstr
|
|||||||
sccm = 1.25;
|
sccm = 1.25;
|
||||||
vdot = sccm * 1.0e-6/60.0 * ((OneAtm / gas.P) * (gas.T / 273.15)); % m^3/s
|
vdot = sccm * 1.0e-6/60.0 * ((OneAtm / gas.P) * (gas.T / 273.15)); % m^3/s
|
||||||
mdot = gas.D * vdot; % kg/s
|
mdot = gas.D * vdot; % kg/s
|
||||||
mfc = MassFlowController;
|
mfc = MassFlowController(upstream, cstr);
|
||||||
mfc.install(upstream, cstr);
|
|
||||||
mfc.massFlowRate = mdot;
|
mfc.massFlowRate = mdot;
|
||||||
|
|
||||||
% now create a downstream reservoir to exhaust into.
|
% now create a downstream reservoir to exhaust into.
|
||||||
@ -83,8 +82,7 @@ function periodic_cstr
|
|||||||
% connect the reactor to the downstream reservoir with a valve, and
|
% connect the reactor to the downstream reservoir with a valve, and
|
||||||
% set the coefficient sufficiently large to keep the reactor pressure
|
% set the coefficient sufficiently large to keep the reactor pressure
|
||||||
% close to the downstream pressure of 60 Torr.
|
% close to the downstream pressure of 60 Torr.
|
||||||
v = Valve;
|
v = Valve(cstr, downstream);
|
||||||
v.install(cstr, downstream);
|
|
||||||
v.valveCoeff = 1.0e-9;
|
v.valveCoeff = 1.0e-9;
|
||||||
|
|
||||||
% create the network
|
% create the network
|
||||||
|
Loading…
Reference in New Issue
Block a user