Skip to content

Commit

Permalink
[MATLAB] Fix Interface.adjacent
Browse files Browse the repository at this point in the history
  • Loading branch information
ischoegl committed Aug 3, 2024
1 parent 8017a12 commit e6c638b
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 18 deletions.
17 changes: 14 additions & 3 deletions interfaces/matlab_experimental/Base/Interface.m
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
properties (SetAccess = protected)
concentrations % Concentrations of the species on an interface.
nAdjacent % Number of adjacent phases.
adjacentNames % Names of adjacent phases.
end

methods
Expand Down Expand Up @@ -62,6 +63,10 @@
s.solnID = ID;
s.interfaceName = name;
s.nAdjacent = ctFunc('soln_nAdjacent', ID);
s.adjacentNames = {};
for i = 1:s.nAdjacent
s.adjacentNames{i} = ctString('soln_adjacentName', ID, i-1)
end
end

%% Interface Class Destructor
Expand All @@ -73,9 +78,15 @@ function delete(s)

%% Interface Get Methods

function phase = adjacent(s, n)
% Get the nth adjacent phase of an interface.
phase = ctFunc('soln_adjacent', s, n);
function adj = adjacent(s, name)
% Get adjacent phase of an interface by name.
exact_match = strcmp(s.adjacentNames, name);
if sum(exact_match) ~= 1
error(['No adjacent phase with name ''' name ''' found.'])
end
location = find(exact_match);
id = ctFunc('soln_adjacent', s.solnID, location-1);
adj = Solution(id);
end

function c = coverages(s)
Expand Down
22 changes: 13 additions & 9 deletions interfaces/matlab_experimental/Base/Solution.m
Original file line number Diff line number Diff line change
Expand Up @@ -62,19 +62,23 @@

ctIsLoaded;

if nargin == 0 || ~ischar(src)
error("Invalid argument: Solution requires name of input file.")
end
if ischar(src)
% New C++/MATLAB object from YAML source
if nargin < 2
name = '';
end

if nargin < 2
name = '';
end
if nargin < 3
transport_model = 'none';
end

ID = ctFunc('soln_newSolution', src, name, transport_model);

if nargin < 3
transport_model = 'none';
elseif isnumeric(src)
% New MATLAB object from existing C++ Solution
ID = src;
end

ID = ctFunc('soln_newSolution', src, name, transport_model);
% Inherit methods and properties from ThermoPhase, Kinetics, and Transport
s@ThermoPhase(ID);
s@Kinetics(ID);
Expand Down
12 changes: 6 additions & 6 deletions samples/matlab_experimental/surf_reactor.m
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,17 @@
tic
help surf_reactor

% The surface reaction mechanism describes catalytic combustion of
% methane on platinum, and is from Deutschmann et al., 26th
% Symp. (Intl.) on Combustion,1996, pp. 1747-1754
surf = Interface('ptcombust.yaml', 'Pt_surf');
gas = surf.adjacent('gas');

%% Set the initial conditions

t = 870.0;
gas = Solution('ptcombust.yaml', 'gas');

gas.TPX = {t, OneAtm, 'CH4:0.01, O2:0.21, N2:0.78'};

% The surface reaction mechanism describes catalytic combustion of
% methane on platinum, and is from Deutschmann et al., 26th
% Symp. (Intl.) on Combustion,1996, pp. 1747-1754
surf = Interface('ptcombust.yaml', 'Pt_surf', gas);
surf.TP = {t, surf.P};

nsp = gas.nSpecies;
Expand Down

0 comments on commit e6c638b

Please sign in to comment.