Skip to content

Commit

Permalink
Avoid class destructors from deleting already-deleted objects.
Browse files Browse the repository at this point in the history
  • Loading branch information
ssun30 authored and speth committed May 11, 2023
1 parent 7e6f9c9 commit 6e8ab95
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 16 deletions.
38 changes: 27 additions & 11 deletions interfaces/matlab_experimental/Base/Interface.m
Expand Up @@ -11,13 +11,18 @@
% - src: YAML file containing the interface or edge phase.
% - id: Name of the interface or edge phase in the YAML file.
% Optional:
% - p1: 1st Adjoining phase to the interface.
% - p2: 2nd Adjoining phase to the interface.
% - p3: 3rd Adjoining phase to the interface.
% - p4: 4th Adjoining phase to the interface.
% - 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.
% :return:
% Instance of class :mat:class:`Interface`.

properties (SetAccess = immutable)
phaseID
interfaceName
end

properties (SetAccess = public)

% Surface coverages of the species on an interface.
Expand All @@ -28,6 +33,7 @@

properties (SetAccess = protected)
concentrations % Concentrations of the species on an interface.
nAdjacent % Number of adjacent phases.
end

methods
Expand All @@ -39,15 +45,20 @@
ctIsLoaded;

src = varargin{1};
id = varargin{2};

t = ThermoPhase(src, id);
s@ThermoPhase(src, id);
name = varargin{2};
na = nargin - 2;

args = varargin(3:end);
adj = [];
for i = 3:nargin
adj(i-2) = varargin{i}.phaseID;
end

s@Kinetics(t, src, id, args{:});
s.tpID = t.tpID;
ID = ctFunc('soln_newInterface', src, name, na, adj);
s@ThermoPhase('CreateFromSolution', ID);
s@Kinetics('CreateFromSolution', ID);
s.phaseID = ID;
s.interfaceName = name;
s.nAdjacent = ctFunc('soln_nAdjacent', ID);
end

%% Interface Class Destructor
Expand All @@ -59,6 +70,11 @@ 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);
end

function c = coverages(s)
% Surface coverages of the species on an interface.

Expand Down
10 changes: 10 additions & 0 deletions interfaces/matlab_experimental/Base/Kinetics.m
Expand Up @@ -144,6 +144,16 @@
kin.kinID = ctFunc('kin_newFromFile', src, id, ph, neighbours{:});
end

%% Kinetics Class Destructor

function delete(kin)
% Delete the :mat:class:`Sim1D` object.

if ~isa(kin, 'Solution') && ~isa(kin, 'Interface')
ctFunc('kin_del', kin.kinID);
end
end

%% Get scalar attributes

function n = kineticsSpeciesIndex(kin, name, phase)
Expand Down
8 changes: 4 additions & 4 deletions interfaces/matlab_experimental/Base/Solution.m
Expand Up @@ -49,7 +49,7 @@
% Instance of class :mat:class:`Solution`.

properties (SetAccess = immutable)
solnID
phaseID
solnName
end

Expand Down Expand Up @@ -79,16 +79,16 @@
s@ThermoPhase('CreateFromSolution', ID);
s@Kinetics('CreateFromSolution', ID);
s@Transport('CreateFromSolution', ID);
s.solnID = ID;
s.solnName = ctString('soln_name', s.solnID);
s.phaseID = ID;
s.solnName = ctString('soln_name', s.phaseID);
s.th = s.tpID;
end

%% Solution Class Destructor

function delete(s)
% Delete :mat:class:`Solution` object.
ctFunc('soln_del', s.solnID);
ctFunc('soln_del', s.phaseID);
disp('Solution class object has been deleted');
end

Expand Down
12 changes: 11 additions & 1 deletion interfaces/matlab_experimental/Base/ThermoPhase.m
Expand Up @@ -434,6 +434,16 @@
tp.basis = 'molar';
end

%% ThermoPhase class Destructor

function delete(tp)
% Delete the :mat:class:`ThermoPhase` object.

if ~isa(tp, 'Solution') && ~isa(tp, 'Interface')
ctFunc('thermo_del', tp.tpID);
end
end

%% ThermoPhase Utility Methods

function display(tp)
Expand Down Expand Up @@ -911,7 +921,7 @@ function display(tp)
end

function v = get.isIdealGas(tp)
v = strcmp(tp.eosType, 'IdealGas');
v = strcmp(tp.eosType, 'ideal-gas');
end

function b = get.isothermalCompressibility(tp)
Expand Down
10 changes: 10 additions & 0 deletions interfaces/matlab_experimental/Base/Transport.m
Expand Up @@ -90,6 +90,16 @@

end

%% Transport Destructor Methods

function delete(tr)
% Delete the :mat:class:`Transport` object.

if ~isa(tr, 'Solution')
ctFunc('trans_del', tr.trID);
end
end

%% Transport Get Methods

function v = get.viscosity(tr)
Expand Down

0 comments on commit 6e8ab95

Please sign in to comment.