-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfugacitycoef_multicomp.m
More file actions
57 lines (39 loc) · 1.54 KB
/
Copy pathfugacitycoef_multicomp.m
File metadata and controls
57 lines (39 loc) · 1.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
% CALCULATE THE FUGACITY COEFFICIENT AND Z-FACTOR OF MULTI-COMPONENT SYSTEMS
% In this function, an appropriate z-factor is automatically chosen, according to gibbs free energy if multiple roots are found.
function [fugcoef, zfactor] = fugacitycoef_multicomp(comp, press, temp, pressc, tempc, acentric, BIP, eos_type, components)
if nargin < 8 || isempty(eos_type)
eos_type = 'PR';
end
if nargin < 9
components = {};
end
[A, B] = calcab_multicomp(press, temp, pressc, tempc, acentric, eos_type, components);
[Amix, Bmix, Amix2] = calcabmix(comp, A, B, BIP);
zfactor = calczfactor(Amix, Bmix, eos_type);
if (size(zfactor,1) > 1)
zfactor = choosezfactor(zfactor, comp, A, B, Amix, Bmix, Amix2, eos_type);
end
fugcoef = calcfugcoef_multicomp(zfactor, A, B, Amix, Bmix, Amix2, eos_type);
end
%% SEARCH AND RETURN AN APPROPRIATE Z-FACTOR
% Calculate dimensionless excess gibbs free energy, and return the z
% factor which minimizes the gibbs free energy.
function minzfactor = choosezfactor(zfactor, comp, A, B, Amix, Bmix, Amix2, eos_type)
gibbsenergy = [];
for i = 1:size(zfactor,1)
fugcoef = calcfugcoef_multicomp(zfactor(i), A, B, Amix, Bmix, Amix2, eos_type);
g = calcgibbsenergy(comp, fugcoef);
gibbsenergy = cat(1, gibbsenergy, g);
end
[~, index] = sort(gibbsenergy);
minzfactor = zfactor(index(1));
end
function g = calcgibbsenergy(comp, fugcoef)
ncomp = size(comp,1);
g = 0;
for i = 1:ncomp
if comp(i) ~= 0
g = g + comp(i)*log(comp(i)*fugcoef(i));
end
end
end