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 ::
|
||||
%
|
||||
% >> s = Interface(src, name, p1, p2)
|
||||
@ -13,11 +13,6 @@ classdef Interface < handle & ThermoPhase & Kinetics
|
||||
% :return:
|
||||
% Instance of class :mat:class:`Interface`.
|
||||
|
||||
properties (SetAccess = immutable)
|
||||
solnID % ID of the interface.
|
||||
interfaceName % Name of the interface.
|
||||
end
|
||||
|
||||
properties (SetAccess = public)
|
||||
|
||||
% 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);
|
||||
|
||||
% Inherit methods and properties from ThermoPhase and Kinetics
|
||||
s@ThermoPhase(ID);
|
||||
s@Kinetics(ID);
|
||||
s.solnID = ID;
|
||||
s.interfaceName = name;
|
||||
% Inherit methods and properties from Solution
|
||||
s@Solution(ID);
|
||||
s.nAdjacent = ctFunc('soln_nAdjacent', ID);
|
||||
s.adjacentNames = {};
|
||||
for i = 1:s.nAdjacent
|
||||
@ -62,13 +54,6 @@ classdef Interface < handle & ThermoPhase & Kinetics
|
||||
end
|
||||
end
|
||||
|
||||
%% Interface Class Destructor
|
||||
|
||||
function delete(s)
|
||||
% Delete :mat:class:`Interface` object.
|
||||
ctFunc('soln_del', s.solnID);
|
||||
end
|
||||
|
||||
%% Interface Get Methods
|
||||
|
||||
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 ::
|
||||
%
|
||||
% >> x = FlowDevice(typ, name)
|
||||
@ -25,21 +25,16 @@ classdef FlowDevice < handle
|
||||
|
||||
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
|
||||
|
||||
% Downstream object of type :mat:class:`Reactor` or :mat:class:`Reservoir`.
|
||||
downstream
|
||||
|
||||
end
|
||||
|
||||
properties (SetAccess = public)
|
||||
|
||||
% 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
|
||||
@ -60,79 +55,28 @@ classdef FlowDevice < handle
|
||||
methods
|
||||
%% FlowDevice Class Constructor
|
||||
|
||||
function x = FlowDevice(typ, name)
|
||||
function x = FlowDevice(typ, upstream, downstream, name)
|
||||
% Create a :mat:class:`FlowDevice` object.
|
||||
|
||||
ctIsLoaded;
|
||||
|
||||
if nargin == 0
|
||||
error('please specify the type of flow device to be created');
|
||||
end
|
||||
if nargin < 2
|
||||
if nargin < 4
|
||||
name = '(none)';
|
||||
end
|
||||
|
||||
x.type = typ;
|
||||
x.id = ctFunc('flowdev_new', typ, name);
|
||||
x.upstream = -1;
|
||||
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
|
||||
|
||||
x@Connector(typ, upstream, downstream, name)
|
||||
x.upstream = upstream;
|
||||
x.downstream = downstream;
|
||||
end
|
||||
|
||||
%% 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')
|
||||
|
@ -31,8 +31,7 @@ classdef MassFlowController < FlowDevice
|
||||
name = '(none)';
|
||||
end
|
||||
|
||||
m@FlowDevice('MassFlowController', name);
|
||||
m.install(upstream, downstream)
|
||||
m@FlowDevice('MassFlowController', upstream, downstream, name);
|
||||
end
|
||||
|
||||
end
|
||||
|
@ -2,13 +2,14 @@ classdef Reactor < handle
|
||||
|
||||
properties (SetAccess = immutable)
|
||||
|
||||
type % Type of Reactor.
|
||||
id % ID of Reactor.
|
||||
|
||||
end
|
||||
|
||||
properties (SetAccess = public)
|
||||
|
||||
type % Reactor type.
|
||||
|
||||
name % Name of reactor.
|
||||
|
||||
contents
|
||||
@ -131,8 +132,8 @@ classdef Reactor < handle
|
||||
error('Reactor contents must be an object of type "Solution"');
|
||||
end
|
||||
|
||||
r.type = char(typ);
|
||||
r.id = ctFunc('reactor_new', typ, content.solnID, name);
|
||||
r.contents = content;
|
||||
end
|
||||
|
||||
%% Reactor Class Destructor
|
||||
@ -160,6 +161,10 @@ classdef Reactor < handle
|
||||
|
||||
%% Reactor Get Methods
|
||||
|
||||
function typ = get.type(r)
|
||||
typ = ctString('reactor_type', r.id);
|
||||
end
|
||||
|
||||
function name = get.name(r)
|
||||
name = ctString('reactor_name', r.id);
|
||||
end
|
||||
|
@ -40,8 +40,7 @@ classdef Valve < FlowDevice
|
||||
name = '(none)';
|
||||
end
|
||||
|
||||
v@FlowDevice('Valve', name);
|
||||
v.install(upstream, downstream)
|
||||
v@FlowDevice('Valve', upstream, downstream, name);
|
||||
end
|
||||
|
||||
end
|
||||
|
@ -1,4 +1,4 @@
|
||||
classdef Wall < handle
|
||||
classdef Wall < Connector
|
||||
% Wall Class ::
|
||||
%
|
||||
% >> x = Wall(l, r, name)
|
||||
@ -47,15 +47,6 @@ classdef Wall < handle
|
||||
|
||||
properties (SetAccess = immutable)
|
||||
|
||||
id
|
||||
type
|
||||
|
||||
end
|
||||
|
||||
properties (SetAccess = protected)
|
||||
|
||||
name % Name of wall.
|
||||
|
||||
left % Reactor on the left.
|
||||
right % Reactor on the right.
|
||||
|
||||
@ -93,49 +84,26 @@ classdef Wall < handle
|
||||
|
||||
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, name);
|
||||
|
||||
% Install the wall between left and right reactors
|
||||
w@Connector('Wall', l, r, name)
|
||||
w.left = l;
|
||||
w.right = r;
|
||||
ctFunc('wall_install', w.id, l.id, r.id);
|
||||
|
||||
% Set default values.
|
||||
w.area = 1.0;
|
||||
w.expansionRateCoeff = 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
|
||||
|
||||
%% 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
|
||||
@ -150,10 +118,6 @@ classdef Wall < handle
|
||||
|
||||
%% 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
|
||||
|
@ -73,8 +73,7 @@ function periodic_cstr
|
||||
sccm = 1.25;
|
||||
vdot = sccm * 1.0e-6/60.0 * ((OneAtm / gas.P) * (gas.T / 273.15)); % m^3/s
|
||||
mdot = gas.D * vdot; % kg/s
|
||||
mfc = MassFlowController;
|
||||
mfc.install(upstream, cstr);
|
||||
mfc = MassFlowController(upstream, cstr);
|
||||
mfc.massFlowRate = mdot;
|
||||
|
||||
% 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
|
||||
% set the coefficient sufficiently large to keep the reactor pressure
|
||||
% close to the downstream pressure of 60 Torr.
|
||||
v = Valve;
|
||||
v.install(cstr, downstream);
|
||||
v = Valve(cstr, downstream);
|
||||
v.valveCoeff = 1.0e-9;
|
||||
|
||||
% create the network
|
||||
|
Loading…
Reference in New Issue
Block a user