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 892426e
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 25 deletions.
36 changes: 30 additions & 6 deletions interfaces/matlab_experimental/Base/ThermoPhase.m
Original file line number Diff line number Diff line change
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
22 changes: 3 additions & 19 deletions test/matlab_experimental/ctTestThermo.m
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -411,17 +401,11 @@ 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]);
Expand Down

0 comments on commit 892426e

Please sign in to comment.