diff --git a/interfaces/matlab_experimental/Base/Interface.m b/interfaces/matlab_experimental/Base/Interface.m index 4b57e049c8c..172ce9560b7 100644 --- a/interfaces/matlab_experimental/Base/Interface.m +++ b/interfaces/matlab_experimental/Base/Interface.m @@ -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 `__ % and `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`. @@ -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); @@ -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 @@ -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) diff --git a/interfaces/matlab_experimental/Base/Solution.m b/interfaces/matlab_experimental/Base/Solution.m index 7663ed661ac..9ad53dac727 100644 --- a/interfaces/matlab_experimental/Base/Solution.m +++ b/interfaces/matlab_experimental/Base/Solution.m @@ -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); diff --git a/samples/matlab_experimental/surf_reactor.m b/samples/matlab_experimental/surf_reactor.m index d9536665160..a7ead24530d 100644 --- a/samples/matlab_experimental/surf_reactor.m +++ b/samples/matlab_experimental/surf_reactor.m @@ -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;