Skip to content

Commit

Permalink
Density/specific volume are now basis dependent
Browse files Browse the repository at this point in the history
  • Loading branch information
ssun30 committed Oct 13, 2023
1 parent f526c4a commit e213360
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 14 deletions.
33 changes: 26 additions & 7 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.
name % Name of the phase.

electricPotential % Electric potential. Units: V.

Expand Down Expand Up @@ -78,7 +78,7 @@

P % Pressure. Units: Pa.

D % Density. Units: kg/m^3.
D % Density depending on the basis. Units: kmol/m^3 (molar) kg/m^3 (mass)

H % Enthalpy depending on the basis. Units: J/kmol (molar) J/kg (mass).

Expand Down Expand Up @@ -251,7 +251,7 @@

properties (Dependent = true)

V % Get Specific volume. Units: m^3/kg.
V % Basis-dependent specific volume. Units: m^3/kmol (molar) m^3/kg (mass).

% Get/Set density [kg/m^3 or kmol/m^3] and pressure [Pa].
DP
Expand Down Expand Up @@ -459,7 +459,7 @@ function delete(tp)
%% ThermoPhase Utility Methods

function display(tp)
ctFunc('thermo_print', tp.tpID, 1, 1);
disp(tp.report);
end

function tp = equilibrate(tp, xy, solver, rtol, maxsteps, maxiter, loglevel)
Expand Down Expand Up @@ -988,7 +988,7 @@ function display(tp)

end

function s = get.phaseName(tp)
function s = get.name(tp)
s = ctString('thermo_getName', tp.tpID);
end

Expand Down Expand Up @@ -1026,7 +1026,11 @@ function display(tp)
end

function density = get.D(tp)
density = ctFunc('thermo_density', tp.tpID);
if strcmp(tp.basis, 'mass')
density = ctFunc('thermo_density', tp.tpID);
else
density = tp.molarDensity;
end
end

function volume = get.V(tp)
Expand Down Expand Up @@ -1314,7 +1318,7 @@ function display(tp)

end

function set.phaseName(tp, str)
function set.name(tp, str)
ctFunc('thermo_setName', tp.tpID, str);
end

Expand Down Expand Up @@ -1384,6 +1388,9 @@ function display(tp)
function set.DP(tp, input)
d = input{1};
p = input{2};
if strcmp(tp.basis, 'molar')
d = d*tp.meanMolecularWeight;
end
ctFunc('thermo_set_DP', tp.tpID, [d, p]);
end

Expand Down Expand Up @@ -1419,6 +1426,9 @@ function display(tp)
function set.PV(tp, input)
p = input{1};
v = input{2};
if strcmp(tp.basis, 'molar')
v = v/tp.meanMolecularWeight;
end
ctFunc('thermo_set_PV', tp.tpID, [p, v]);
end

Expand Down Expand Up @@ -1501,6 +1511,7 @@ function display(tp)
v = input{2};
if strcmp(tp.basis, 'molar')
s = s/tp.meanMolecularWeight;
v = v/tp.meanMolecularWeight;
end
ctFunc('thermo_set_SV', tp.tpID, [s, v]);
end
Expand All @@ -1518,6 +1529,9 @@ function display(tp)
function set.TD(tp, input)
t = input{1};
d = input{2};
if strcmp(tp.basis, 'molar')
d = d*tp.meanMolecularWeight;
end
ctFunc('thermo_set_TD', tp.tpID, [t, d]);
end

Expand Down Expand Up @@ -1575,6 +1589,9 @@ function display(tp)
function set.TV(tp, input)
t = input{1};
v = input{2};
if strcmp(tp.basis, 'molar')
v = v/tp.meanMolecularWeight;
end
ctFunc('thermo_set_TV', tp.tpID, [t, v]);
end

Expand Down Expand Up @@ -1612,6 +1629,7 @@ function display(tp)
v = input{2};
if strcmp(tp.basis, 'molar')
u = u/tp.meanMolecularWeight;
v = v/tp.meanMolecularWeight;
end
ctFunc('thermo_set_UV', tp.tpID, [u, v]);
end
Expand All @@ -1630,6 +1648,7 @@ function display(tp)
v = input{1};
h = input{2};
if strcmp(tp.basis, 'molar')
v = v/tp.meanMolecularWeight;
h = h/tp.meanMolecularWeight;
end
ctFunc('thermo_set_VH', tp.tpID, [v, h]);
Expand Down
16 changes: 9 additions & 7 deletions test/matlab_experimental/ctTestThermo.m
Original file line number Diff line number Diff line change
Expand Up @@ -188,9 +188,9 @@ function testBaseAttributes(self)
self.phase.basis = 'mass';
self.verifyMatches(self.phase.basis, 'mass');

self.verifyInstanceOf(self.phase.phaseName, 'char');
self.phase.phaseName = 'spam';
self.verifyMatches(self.phase.phaseName, 'spam');
self.verifyInstanceOf(self.phase.name, 'char');
self.phase.name = 'spam';
self.verifyMatches(self.phase.name, 'spam');
end

function testPhases(self)
Expand Down Expand Up @@ -293,7 +293,7 @@ function testCharges(self)
function testReport(self)
str = self.phase.report;

self.verifySubstring(str, self.phase.phaseName);
self.verifySubstring(str, self.phase.name);
self.verifySubstring(str, 'temperature');

for i = 1:self.phase.nSpecies
Expand All @@ -317,6 +317,8 @@ function testSingleGetters(self)
exp = OneAtm;
self.verifyEqual(val, exp, 'RelTol', self.rtol);

self.phase.basis = 'mass';

val = self.phase.D;
exp = self.phase.P * self.phase.meanMolecularWeight / ...
(GasConstant * self.phase.T);
Expand All @@ -341,12 +343,12 @@ function testSingleGetters(self)
val1 = [self.phase.H, self.phase.S, ...
self.phase.U, self.phase.G, ...
self.phase.cp, self.phase.cv];
self.phase.basis = 'mass';
self.phase.basis = 'molar';
val2 = [self.phase.H, self.phase.S, ...
self.phase.U, self.phase.G, ...
self.phase.cp, self.phase.cv];
exp = val2.*self.phase.meanMolecularWeight;
tol = ones(1, 9).*self.rtol;
exp = val2./self.phase.meanMolecularWeight;
tol = ones(1, 6).*self.rtol;
self.verifyEqual(val1, exp, 'RelTol', tol);

val = self.phase.isothermalCompressibility;
Expand Down

0 comments on commit e213360

Please sign in to comment.