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 4, 2024
1 parent b6aa962 commit 99262fa
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 32 deletions.
39 changes: 22 additions & 17 deletions interfaces/matlab_experimental/Base/Interface.m
Original file line number Diff line number Diff line change
@@ -1,20 +1,16 @@
classdef Interface < handle & ThermoPhase & Kinetics
% Interface Class ::
%
% >> s = Interface(src, id, p1, p2, p3, p4)
% >> s = Interface(src, name, p1, p2)
%
% See `ideal-surface <https://cantera.org/documentation/docs-2.6/sphinx/html/yaml/phases.html#sec-yaml-ideal-surface>`__
% and `Declaring adjacent phases <https://cantera.org/tutorials/yaml/phases.html#declaring-adjacent-phases>`__.
%
% :param src: YAML file containing the interface or edge phase.
% :param name: Name of the interface or edge phase in the YAML file.
% :param varargin:
% Variable number of inputs consisting of the following:
% - src: YAML file containing the interface or edge phase.
% - id: Name of the interface or edge phase in the YAML file.
% Optional:
% - p1: 1st adjacent phase to the interface.
% - p2: 2nd adjacent phase to the interface.
% - p3: 3rd adjacent phase to the interface.
% - p4: 4th adjacent phase to the interface.
% Optional list of phases pi adjacent to the interface; if omitted, adjacent
% phases are added automatically.
% :return:
% Instance of class :mat:class:`Interface`.

Expand All @@ -34,24 +30,23 @@
properties (SetAccess = protected)
concentrations % Concentrations of the species on an interface.
nAdjacent % Number of adjacent phases.
adjacentNames % Names of adjacent phases.
end

methods
%% Interface Class Constructor

function s = Interface(varargin)
function s = Interface(src, name, varargin)
% Create an :mat:class:`Interface` object.

ctIsLoaded;

src = varargin{1};
name = varargin{2};
na = nargin - 2;

% Get ID of adjacent phases
adj = [];
for i = 3:nargin
adj(i-2) = varargin{i}.solnID;
for i = 1:na
adj(i) = varargin{i}.solnID;
end

ID = ctFunc('soln_newInterface', src, name, na, adj);
Expand All @@ -62,6 +57,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 +72,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
24 changes: 15 additions & 9 deletions interfaces/matlab_experimental/Base/Solution.m
Original file line number Diff line number Diff line change
Expand Up @@ -54,19 +54,25 @@

ctIsLoaded;

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

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

if nargin < 3
transport_model = 'none';
ID = ctFunc('soln_newSolution', src, name, transport_model);
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 99262fa

Please sign in to comment.