Skip to content

Commit

Permalink
Fixed setter errors with unit conversions
Browse files Browse the repository at this point in the history
  • Loading branch information
ssun30 committed Oct 3, 2023
1 parent 05d6aac commit be01c64
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 63 deletions.
6 changes: 3 additions & 3 deletions interfaces/matlab_experimental/Base/Kinetics.m
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@

reactionEquations % All reaction equations within the Kinetics object.

reactionPhaseIndex % The index of the phase where the reactions occur.
reactionPhaseIndex % The index of the phase where the reactions occur.
end

methods
Expand Down Expand Up @@ -342,7 +342,7 @@ function delete(kin)
for k = krange

for i = irange

if iscell(k)
kk = kin.kineticsSpeciesIndex(k{:});
else
Expand All @@ -363,7 +363,7 @@ function delete(kin)
n = nonzeros(temp);
elseif nnz(temp) == 0
n = 0;
else
else
n = temp;
end
end
Expand Down
44 changes: 34 additions & 10 deletions interfaces/matlab_experimental/Base/ThermoPhase.m
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
% String. Can be 'mole'/'molar'/'Molar'/'Mole' or 'mass'/'Mass'.
basis

phaseName % Name of the phase.
phaseName % Name of the phase.

electricPotential % Electric potential. Units: V.

Expand Down Expand Up @@ -176,8 +176,8 @@

refPressure % Reference pressure for standard-state. Units: Pa.

% Generate a report describing the thermodynamic state of this phase.
% To print the report to the terminal, simply call the phase object.
% Generate a report describing the thermodynamic state of this phase.
% To print the report to the terminal, simply call the phase object.
% The following two statements are equivalent ::
%
% >> phase
Expand Down Expand Up @@ -997,7 +997,7 @@ function display(tp)
aa = char(ones(1, buflen));
ptr = libpointer('cstring', aa);
[iok, bb] = calllib(ctLib, 'thermo_report', tp.tpID, buflen, ptr, 1);

if iok < 0
error(ctGetErr);
end
Expand Down Expand Up @@ -1030,11 +1030,7 @@ function display(tp)
end

function volume = get.V(tp)
if strcmp(tp.basis, 'molar')
volume = 1 / tp.molarDensity;
else
volume = 1 / tp.D;
end
volume = 1 / tp.D;
end

function moleFractions = get.X(tp)
Expand Down Expand Up @@ -1404,6 +1400,9 @@ function display(tp)
function set.HP(tp, input)
h = input{1};
p = input{2};
if strcmp(tp.basis, 'molar')
h = h/tp.meanMolecularWeight;
end
ctFunc('thermo_set_HP', tp.tpID, [h, p]);
end

Expand Down Expand Up @@ -1442,6 +1441,10 @@ function display(tp)
function set.SH(tp, input)
s = input{1};
h = input{2};
if strcmp(tp.basis, 'molar')
s = s/tp.meanMolecularWeight;
h = h/tp.meanMolecularWeight;
end
ctFunc('thermo_set_SH', tp.tpID, [s, h]);
end

Expand All @@ -1458,6 +1461,9 @@ function display(tp)
function set.SP(tp, input)
s = input{1};
p = input{2};
if strcmp(tp.basis, 'molar')
s = s/tp.meanMolecularWeight;
end
ctFunc('thermo_set_SP', tp.tpID, [s, p]);
end

Expand All @@ -1474,6 +1480,9 @@ function display(tp)
function set.ST(tp, input)
s = input{1};
t = input{2};
if strcmp(tp.basis, 'molar')
s = s/tp.meanMolecularWeight;
end
ctFunc('thermo_set_ST', tp.tpID, [s, t]);
end

Expand All @@ -1490,6 +1499,9 @@ function display(tp)
function set.SV(tp, input)
s = input{1};
v = input{2};
if strcmp(tp.basis, 'molar')
s = s/tp.meanMolecularWeight;
end
ctFunc('thermo_set_SV', tp.tpID, [s, v]);
end

Expand All @@ -1500,7 +1512,7 @@ function display(tp)

function set.SVY(tp, input)
tp.Y = input{3};
tp.SP = input(1:2);
tp.SV = input(1:2);
end

function set.TD(tp, input)
Expand All @@ -1522,6 +1534,9 @@ function display(tp)
function set.TH(tp, input)
t = input{1};
h = input{2};
if strcmp(tp.basis, 'molar')
h = h/tp.meanMolecularWeight;
end
ctFunc('thermo_set_TH', tp.tpID, [t, h]);
end

Expand Down Expand Up @@ -1576,6 +1591,9 @@ function display(tp)
function set.UP(tp, input)
u = input{1};
p = input{2};
if strcmp(tp.basis, 'molar')
u = u/tp.meanMolecularWeight;
end
ctFunc('thermo_set_UP', tp.tpID, [u, p]);
end

Expand All @@ -1592,6 +1610,9 @@ function display(tp)
function set.UV(tp, input)
u = input{1};
v = input{2};
if strcmp(tp.basis, 'molar')
u = u/tp.meanMolecularWeight;
end
ctFunc('thermo_set_UV', tp.tpID, [u, v]);
end

Expand All @@ -1608,6 +1629,9 @@ function display(tp)
function set.VH(tp, input)
v = input{1};
h = input{2};
if strcmp(tp.basis, 'molar')
h = h/tp.meanMolecularWeight;
end
ctFunc('thermo_set_VH', tp.tpID, [v, h]);
end

Expand Down
2 changes: 1 addition & 1 deletion test/matlab_experimental/ctTestKinetics.m
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ function testIsReversible(self)
for i = 1:self.phase.nReactions
self.verifyTrue(self.phase.isReversible(i));
end

diamond = Solution('diamond.yaml', 'diamond_100', 'none');
self.verifyFalse(diamond.isReversible(20));
clear diamond
Expand Down
Loading

0 comments on commit be01c64

Please sign in to comment.