Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed setter errors with unit conversions
Browse files Browse the repository at this point in the history
ssun30 committed Oct 3, 2023
1 parent 05d6aac commit 1acdc3f
Showing 4 changed files with 42 additions and 34 deletions.
6 changes: 3 additions & 3 deletions interfaces/matlab_experimental/Base/Kinetics.m
Original file line number Diff line number Diff line change
@@ -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
@@ -342,7 +342,7 @@ function delete(kin)
for k = krange

for i = irange

if iscell(k)
kk = kin.kineticsSpeciesIndex(k{:});
else
@@ -363,7 +363,7 @@ function delete(kin)
n = nonzeros(temp);
elseif nnz(temp) == 0
n = 0;
else
else
n = temp;
end
end
44 changes: 34 additions & 10 deletions interfaces/matlab_experimental/Base/ThermoPhase.m
Original file line number Diff line number Diff line change
@@ -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.

@@ -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
@@ -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
@@ -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)
@@ -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

@@ -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

@@ -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

@@ -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

@@ -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

@@ -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)
@@ -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

@@ -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

@@ -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

@@ -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

2 changes: 1 addition & 1 deletion test/matlab_experimental/ctTestKinetics.m
Original file line number Diff line number Diff line change
@@ -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
24 changes: 4 additions & 20 deletions test/matlab_experimental/ctTestThermo.m
Original file line number Diff line number Diff line change
@@ -233,8 +233,8 @@ function testNAtoms(self)
self.verifyEqual(n2, n);
end

self.getInvalidValue('nAtoms', {'C', 'H2'}, 'outside valid range');
self.getInvalidValue('nAtoms', {'H', 'CH4'}, 'outside valid range');
self.getInvalidValue('nAtoms', {'C', 'H2'}, 'No such species');
self.getInvalidValue('nAtoms', {'H', 'CH4'}, 'No such element');
end

function testElementalMassFraction(self)
@@ -251,7 +251,7 @@ function testElementalMassFraction(self)
self.verifyEqual(Zh, exp2, 'AbsTol', self.atol);
self.verifyEqual(Zar, exp3, 'AbsTol', self.atol);

self.getInvalidValue('elementalMassFraction', {'C'}, 'outside valid range');
self.getInvalidValue('elementalMassFraction', {'C'}, 'No such element');
self.getInvalidValue('elementalMassFraction', {5}, 'Wrong type');
end

@@ -322,16 +322,6 @@ function testSingleGetters(self)
(GasConstant * self.phase.T);
self.verifyEqual(val, exp, 'RelTol', self.rtol);

self.phase.basis = 'mass';
val = self.phase.V;
exp = 1/exp;
self.verifyEqual(val, exp, 'RelTol', self.rtol);

self.phase.basis = 'molar';
val = self.phase.V;
exp = exp * self.phase.meanMolecularWeight;
self.verifyEqual(val, exp, 'RelTol', self.rtol);

val = self.phase.molarDensity;
exp = self.phase.D/self.phase.meanMolecularWeight;
self.verifyEqual(val, exp, 'RelTol', self.rtol);
@@ -411,20 +401,14 @@ function testSetCompositionStringBad(self)
end

function testSetStateMole(self)
self.assumeFail(['Fails because multi-property setters could not', ...
' set correct values']);

self.checkSetters(750, 0.07, [0.2, 0.1, 0.0, 0.3, 0.1, ...
0.0, 0.0, 0.2, 0.1, 0.0]);
end

function testSetStateMass(self)
self.assumeFail(['Fails because multi-property setters could not', ...
' set correct values']);

self.phase.basis = 'mass';
self.checkSetters(500, 1.5, [0.1, 0.0, 0.0, 0.1, 0.4, ...
0.2, 0.0, 0.0, 0.2, 0.0]);
0.2, 0.0, 0.0, 0.2, 0.0]);
end

function testSetterErrors(self)

0 comments on commit 1acdc3f

Please sign in to comment.