From e6c638b2fd45bf9810706cf2c361767527ca64fd Mon Sep 17 00:00:00 2001 From: Ingmar Schoegl Date: Sat, 3 Aug 2024 07:53:21 -0500 Subject: [PATCH] [MATLAB] Fix Interface.adjacent --- .../matlab_experimental/Base/Interface.m | 17 +++++++++++--- .../matlab_experimental/Base/Solution.m | 22 +++++++++++-------- samples/matlab_experimental/surf_reactor.m | 12 +++++----- 3 files changed, 33 insertions(+), 18 deletions(-) diff --git a/interfaces/matlab_experimental/Base/Interface.m b/interfaces/matlab_experimental/Base/Interface.m index 4b57e049c8c..6a8a8d166cc 100644 --- a/interfaces/matlab_experimental/Base/Interface.m +++ b/interfaces/matlab_experimental/Base/Interface.m @@ -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 @@ -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 @@ -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) diff --git a/interfaces/matlab_experimental/Base/Solution.m b/interfaces/matlab_experimental/Base/Solution.m index f3068dfbf14..cfbca1f28bf 100644 --- a/interfaces/matlab_experimental/Base/Solution.m +++ b/interfaces/matlab_experimental/Base/Solution.m @@ -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); 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;