-
Notifications
You must be signed in to change notification settings - Fork 3
/
compressor2.m
60 lines (60 loc) · 2.12 KB
/
compressor2.m
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
58
59
60
function [nc,pr,gc,cpc,rh,wc,pOUT,tOUTdash,tOUT,sOUT,sOUTdash]=compressor2(def_nc,def_pr,def_gc,def_cpc,once_only,m,sIN,sINdash,tIN,tINdash,pIN,rh,resln)
%calculates the work absorbed by the compressor
%PLOTs TS DIAGRAM
nc = def_nc;
pr = def_pr;
gc = def_gc;
cpc = def_cpc;
t1 = tIN;
t1dash = tINdash;
p1=pIN;
p2=p1*pr;
es = 1.7526*10^8*exp(-5315.56/t1);
% fprintf('rh before:%d',rh);
%%%%%%%%%%%%%%%%%%% calculate relative humidity variation with compression
%first time rh comes directly from user second time it is calculated, it is
%then whatever value entered by default into this function is over-written
p_sat_inlet_temp = xsteam('psat_T',tIN-273); %answer in bar
pv1 = (rh/100)*100*p_sat_inlet_temp; %converted to kPa, rh fed in as percentage
omega = (0.622*pv1)/(100-pv1); %kg of water per kg of dry air
texit = tIN*(pr)^((gc-1)/gc); %answer in kelvin
pg2 = 100*xsteam('psat_T',(texit-273)); %answer in bar, input in deg , converted to kPa by ans x 100
pv2 = omega*p2*100/(omega+0.622); %answer in kpa
rh = pv2/pg2; %answer in percentage
% fprintf('rh after:%d',rh );
density = 3.4848*(p1*10^2-0.00376960*rh*es)*10^-3/t1;
v1 = m/density;
v2 = ((1/pr)^(1/gc))*v1;
v12 = linspace(v1,v2,resln);
p12 = (p1*v1^gc)./((v12).^(gc));
%prepare to plot TS diagram
t12dash = t1.*(p12).^((gc-1)/gc); %the final value would be t2' -READ T2 DASH
t12 = t1+(t12dash-t1)./nc; %actual; tdash is isentropic
t2=t12(length(t12));
t2dash=t12dash(length(t12dash));
pOUT = p2;
tOUT = t2;
tOUTdash = t2dash;
warning('off','MATLAB:dispatcher:InexactCaseMatch');
% fprintf('\n Computing Inital entropy');
if once_only
s1 = Xsteam('s_pT',p1,t1-273); %initial entropy
s2 = s1; %isentropic compression
s12dash = linspace(s1,s2,resln);
else
s1 = sIN;
s2 = s1;
s12dash = linspace(sINdash,s2,resln);
end
% for loop = 1:resln %%%%%THIS DOESNOT WORK
% s12(loop) = Xsteam('s_pT',p12(loop),t12(loop)-273);
% end
% for loop = 1:resln
% s12dash(loop) = Xsteam('s_pT',p12(loop),t12dash(loop)-273);
% end
s12 = cpc.*log(t12dash./t1)-0.287.*log(p12./p1)+s1;
sOUT = s12(length(s12));
sOUTdash = s12dash(length(s12dash));
hold on
wc = cpc*(t2-t1);
%drawnow; %try update the plot without erase