Skip to content

Commit

Permalink
[Matlab] Fixed issue causing crash when getting diffusion coefficients
Browse files Browse the repository at this point in the history
Other miscellaneous updates
  • Loading branch information
ssun30 authored and speth committed May 11, 2023
1 parent 5adbb0c commit 4e122e4
Show file tree
Hide file tree
Showing 24 changed files with 165 additions and 70 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@
% Set the profile of the flame with the estimated axial velocities,
% radial velocities, temperature, and mass fractions calculated above.
flame = Stack([left flow right]);
flame.setProfile(2, {'u', 'V'}, [zrel; u; v]);
flame.setProfile(2, {'velocity', 'spread_rate'}, [zrel; u; v]);
flame.setProfile(2, 'T', [zrel; t] );
for n = 1:nsp
nm = tp_f.speciesName(n);
Expand Down
12 changes: 6 additions & 6 deletions interfaces/matlab_experimental/1D/Domain1D.m
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ function clear(d)
end
end

function n = componentName(d, index)
function s = componentName(d, index)
% Get the name of a component given its index.
%
% n = d.componentName(index)
Expand All @@ -219,7 +219,7 @@ function clear(d)
% Cell array of component names.
%
n = length(index);
s = cell(m);
s = cell(1, n);
for i = 1:n
id = index(i)-1;
output = callct2('domain_componentName', d.domainID, id);
Expand Down Expand Up @@ -650,7 +650,7 @@ function setSteadyTolerances(d, component, rtol, atol)
nc = d.nComponents;
for ii = 1:nc
callct('domain_setSteadyTolerances', ...
d.domainID, ii, rtol, atol);
d.domainID, ii-1, rtol, atol);
end
elseif iscell(component)
nc = length(component);
Expand All @@ -662,7 +662,7 @@ function setSteadyTolerances(d, component, rtol, atol)
else
n = d.componentIndex(component);
callct('domain_setSteadyTolerances', ...
d.domainID, ii, rtol, atol);
d.domainID, n, rtol, atol);
end
end

Expand All @@ -686,7 +686,7 @@ function setTransientTolerances(d, component, rtol, atol)
nc = d.nComponents;
for ii = 1:nc
callct('domain_setTransientTolerances', ...
d.domainID, ii, rtol, atol);
d.domainID, ii-1, rtol, atol);
end
elseif iscell(component)
nc = length(component);
Expand All @@ -698,7 +698,7 @@ function setTransientTolerances(d, component, rtol, atol)
else
n = d.componentIndex(component);
callct('domain_setTransientTolerances', ...
d.domainID, ii, rtol, atol);
d.domainID, n, rtol, atol);
end
end

Expand Down
4 changes: 2 additions & 2 deletions interfaces/matlab_experimental/1D/Sim1D.m
Original file line number Diff line number Diff line change
Expand Up @@ -355,12 +355,12 @@ function setProfile(s, name, comp, p)
for j = 1:np
ic = d.componentIndex(c{j});
callct('sim1D_setProfile', s.stID, ...
n - 1, ic - 1, sz(1), p(1, :), sz(1), p(j+1, :));
n - 1, ic - 1, sz(2), p(1, :), sz(2), p(j+1, :));
end
elseif sz(2) == np + 1;
ic = d.componentIndex(c{j});
callct('sim1D_setProfile', s.stID, ...
n - 1, ic - 1, sz(2), p(:, 1), sz(2), p(:, j+1));
n - 1, ic - 1, sz(1), p(:, 1), sz(1), p(:, j+1));
else
error('Wrong profile shape.');
end
Expand Down
18 changes: 8 additions & 10 deletions interfaces/matlab_experimental/Base/Solution.m
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,11 @@
% >> s = Solution('input.yaml'[, phase_name[, transport_model]])
%
% constructs a :mat:func:`Solution` object from a specification contained in
% file ``input.yaml``. Optionally, the name of the phase to be imported
% can be specified with ``phase_name``. If a :mat:func:`Transport` model is
% included in ``input.yaml``, it will be included in the :mat:func:`Solution`
% instance with the default transport modeling as set
% in the input file. To specify the transport modeling, set the input
% argument ``trans`` to one of ``'default'``, ``'None'``, ``'Mix'``, or ``'Multi'``.
% file ``input.yaml`` with the name of the phase to be imported specified with
% ``phase_name``. If a :mat:func:`Transport` model is included in ``input.yaml``,
% it will be included in the :mat:func:`Solution` instance with the default transport modeling as set
% in the input file. To specify the transport modeling, set the input argument
% ``trans`` to one of ``'default'``, ``'None'``, ``'Mix'``, or ``'Multi'``.
% In this case, the phase name must be specified as well. Alternatively,
% change the ``transport`` node in the YAML file, or ``transport``
% property in the CTI file before loading the phase. The transport
Expand All @@ -47,16 +46,15 @@
% :param src:
% Input string of YAML file name.
% :param id:
% Optional unless ``trans`` is specified. ID of the phase to
% import as specified in the YAML file.
% ID of the phase to import as specified in the YAML file.
% :param trans:
% String, transport modeling. Possible values are ``'default'``, ``'None'``,
% ``'Mix'``, or ``'Multi'``. If not specified, ``'default'`` is used.
% :return:
% Instance of class :mat:func:`Solution`

if nargin == 1
id = '-';
if nargin < 2 || nargin > 3
error('Solution class constructor expects 2 or 3 input arguments.');
end
tp = ThermoPhase(src, id);
s@ThermoPhase(src, id);
Expand Down
16 changes: 5 additions & 11 deletions interfaces/matlab_experimental/Base/ThermoPhase.m
Original file line number Diff line number Diff line change
Expand Up @@ -68,31 +68,25 @@
% t = ThermoPhase(src, id)
%
% :param src:
% Input string of YAML, CTI, or XML file name.
% Input string of YAML file name.
% :param id:
% ID of the phase to import as specified in the input file. (optional)
% ID of the phase to import as specified in the input file.
% :return:
% Instance of class :mat:func:`ThermoPhase`
%
checklib;
if nargin > 2
error('ThermoPhase expects 1 or 2 input arguments.');
end
if nargin == 1
id = '-';
if nargin ~= 2
error('ThermoPhase expects 2 input arguments.');
end
tp.tpID = callct('thermo_newFromFile', src, id);
tp.basis = 'molar';
end

%% Utility methods

function display(tp, threshold)
function display(tp)
% Display thermo properties

if nargin < 2 || ~isnumeric(threshold)
threshold = 1e-14;
end
buflen = 0 - calllib(ct, 'thermo_report', tp.tpID, 0, '', 1);
aa = char(ones(1, buflen));
ptr = libpointer('cstring', aa);
Expand Down
4 changes: 2 additions & 2 deletions interfaces/matlab_experimental/Base/Transport.m
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ function trClear(tr)
% symmetric: d(i, j) = d(j, i). Unit: m^2/s.

nsp = tr.th.nSpecies;
xx = zeros(1, nsp);
xx = zeros(nsp, nsp);
pt = libpointer('doublePtr', xx);
callct('trans_getBinDiffCoeffs', tr.trID, nsp, pt);
v = pt.Value;
Expand All @@ -137,7 +137,7 @@ function trClear(tr)
% diffusion coefficients. Unit: m^2/s.

nsp = tr.th.nSpecies;
xx = zeros(1, nsp);
xx = zeros(nsp, nsp);
pt = libpointer('doublePtr', xx);
callct('trans_getMultiDiffCoeffs', tr.trID, nsp, pt);
v = pt.Value;
Expand Down
12 changes: 6 additions & 6 deletions samples/matlab_experimental/catcomb.m
Original file line number Diff line number Diff line change
Expand Up @@ -132,10 +132,10 @@
sim1D = Stack([inlt, flow, surf]);

% set the initial profiles.
sim1D.setProfile(2, {'u', 'V', 'T'}, [0.0, 1.0 % z/zmax
0.06, 0.0 % u
0.0, 0.0 % V
tinlet, tsurf]); % T
sim1D.setProfile(2, {'velocity', 'spread_rate', 'T'}, [0.0, 1.0 % z/zmax
0.06, 0.0 % u
0.0, 0.0 % V
tinlet, tsurf]); % T
names = gas.speciesNames;

for k = 1:gas.nSpecies
Expand Down Expand Up @@ -207,11 +207,11 @@
title('Temperature [K]');

subplot(3, 3, 2);
sim1D.plotSolution('flow', 'u');
sim1D.plotSolution('flow', 'velocity');
title('Axial Velocity [m/s]');

subplot(3, 3, 3);
sim1D.plotSolution('flow', 'V');
sim1D.plotSolution('flow', 'spread_rate');
title('Radial Velocity / Radius [1/s]');

subplot(3, 3, 4);
Expand Down
7 changes: 5 additions & 2 deletions samples/matlab_experimental/diff_flame.m
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@

%% Initialization

help diff_flame

clear all
close all
cleanup
clc

tic % total running time of the script
help diff_flame

runtime = cputime; % Record the starting time

%% Parameter values of inlet streams
Expand Down Expand Up @@ -139,3 +140,5 @@
plot(z, y(j, :), 'r', z, y(k, :), 'g', z, y(l, :), 'm', z, y(m, :), 'b');
ylabel('Mass Fraction');
legend('T', 'O2', 'H2O', 'C2H6', 'CO2');

toc
10 changes: 9 additions & 1 deletion samples/matlab_experimental/equil.m
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,19 @@ function equil(g)
%
% This example computes the adiabatic flame temperature and equilibrium
% composition for a methane/air mixture as a function of equivalence ratio.

clear all
close all
cleanup
clc

tic
help equil

if nargin == 1
gas = g;
else
gas = Solution('gri30.yaml');
gas = GRI30;
end

nsp = gas.nSpecies;
Expand Down Expand Up @@ -60,4 +67,5 @@ function equil(g)
ylabel('Mole Fraction');
title('Equilibrium Composition');

toc
end
6 changes: 3 additions & 3 deletions samples/matlab_experimental/flame.m
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@
else
t1 = right.T;
end
f.setProfile(2, {'u', 'V'}, [0.0 1.0
mdot0/rho0 -mdot1/rho0
0.0 0.0]);
f.setProfile(2, {'velocity', 'spread_rate'}, [0.0 1.0
mdot0/rho0 -mdot1/rho0
0.0 0.0]);
f.setProfile(2, 'T', [0.0, 1.0
t0, t1]);

Expand Down
9 changes: 6 additions & 3 deletions samples/matlab_experimental/flame1.m
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@

%% Initialization

help flame1

clear all
close all
cleanup
clc

tic
help flame1

t0 = cputime; % record the starting time

%% Set parameter values
Expand Down Expand Up @@ -112,11 +113,13 @@
plotSolution(fl, 'flow', 'T');
title('Temperature [K]');
subplot(2, 2, 2);
plotSolution(fl, 'flow', 'u');
plotSolution(fl, 'flow', 'velocity');
title('Axial Velocity [m/s]');
subplot(2, 2, 3);
plotSolution(fl, 'flow', 'H2O');
title('H2O Mass Fraction');
subplot(2, 2, 4);
plotSolution(fl, 'flow', 'O2');
title('O2 Mass Fraction');

toc
11 changes: 7 additions & 4 deletions samples/matlab_experimental/flame2.m
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@

%% Initialization

help flame2

clear all
close all
cleanup
clc

tic
help flame2

t0 = cputime; % record the starting time

%% Set parameter values
Expand Down Expand Up @@ -119,8 +120,10 @@
plotSolution(fl, 'flow', 'CH');
title('CH Mass Fraction');
subplot(2, 3, 5);
plotSolution(fl, 'flow', 'V');
plotSolution(fl, 'flow', 'spread_rate');
title('Radial Velocity / Radius [s^-1]');
subplot(2, 3, 6);
plotSolution(fl, 'flow', 'u');
plotSolution(fl, 'flow', 'velocity');
title('Axial Velocity [m/s]');

toc
7 changes: 7 additions & 0 deletions samples/matlab_experimental/ignite_hp.m
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@ function ignite_hp(gas)
% IGNITE_HP Solves the same ignition problem as 'ignite', but uses
% function conhp instead of reactor.

clear all
close all
cleanup
clc

tic
help ignite_hp

if nargin == 0
Expand Down Expand Up @@ -35,4 +41,5 @@ function ignite_hp(gas)
title('OH Mass Fraction');
end

toc
end
7 changes: 7 additions & 0 deletions samples/matlab_experimental/ignite_uv.m
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@ function ignite_uv(gas)
% IGNITE_UV Solves the same ignition problem as 'ignite2', except
% function conuv is used instead of reactor.
%
clear all
close all
cleanup
clc

tic
help ignite_uv

if nargin == 0
Expand Down Expand Up @@ -35,4 +41,5 @@ function ignite_uv(gas)
title('OH Mass Fraction');
end

toc
end
8 changes: 8 additions & 0 deletions samples/matlab_experimental/isentropic.m
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ function isentropic(g)
% In this example, the area ratio vs. Mach number curve is
% computed for a hydrogen/nitrogen gas mixture.
%
clear all
close all
cleanup
clc

tic
help isentropic

if nargin == 1
Expand Down Expand Up @@ -56,4 +62,6 @@ function isentropic(g)
ylabel('Area Ratio');
xlabel('Mach Number');
title('Isentropic Flow: Area Ratio vs. Mach Number');

toc
end

0 comments on commit 4e122e4

Please sign in to comment.