%simulation of ranklinecycle
clear all
close all
clc
%process description
fprintf('1-2 isentropic heat transfer\n')
fprintf('2-3 isentropic expansion\n')
fprintf('3-4 isentropic heat rejection\n')
fprintf('4-1 isentropic compression\n')
%inputs
p1=input('pressure at turbine inlet(in bar):');
t1=input('temperature at inlet(in degree celcius):');
p2=input('pressure at condenser(in bar):');
%input conditions
t = XSteam('Tsat_p',p1);
h1 = XSteam('h_pT',p1,t1);
s1 = XSteam('s_pT',p1,t1);
%state point evaluation
%step 1
p4 = p1;
p3 = p2;
h3 = XSteam('hL_p',p3);
s3 = XSteam('sL_p',p3);
t3 = XSteam('Tsat_p',p3);
%setep 2
s2=s1;
t2=t3;
sf2=XSteam('sL_p',p2);
sg2=XSteam('sV_p',p2);
%step 3
x2 = (s2 - sf2)/(sg2 - sf2);
hf2=XSteam('hL_p',p2);
hg2=XSteam('hV_p',p2);
h2=hf2+x2*(hg2 - hf2);
%step 4
s4 = s3;
h4 = XSteam('h_ps',p4,s4);
cp4 = XSteam('cp_ps',p4,s4);
cv4 = XSteam('cv_ps',p4,s4);
g4=cp4/cv4;
o = (g4-1)/g4;
t4 =t3*((p4/p3)^o);
%turbine and pumpwork
wt = h1 -h2;
wp = h4 -h3;
%net work
wnet = wt - wp;
%heat supplied
qs = h1 - h4;
%efficiency
n_per = (wnet/qs)*100;
%steam rate per sec
stm_rate = 3600/(wt - wp);
%for isentropic expression
t5 = XSteam('Tsat_p',p1);
s5 = XSteam('sL_p',p1);
s6 = XSteam('sV_p',p1);
%output
fprintf('\n\tRESULT\n')
fprintf('At state point 1:\np1 is :%4.2f bar\nT1 is :4.2f degree celcius\nh1 is :%4.2f kj/kg\ns1 is :%4.2f kj/kgk\n\n',p1,t1,h1);
fprintf('At state point 2:\np2 is :%4.2f bar\nT2 is :4.2f degree celcius\nh2 is :%4.2f kj/kg\ns2 is :%4.2f kj/kgk\n\n',p2,t2,h2);
fprintf('At state point 3:\np3 is :%4.2f bar\nT3 is :4.2f degree celcius\nh3 is :%4.2f kj/kg\ns3 is :%4.2f kj/kgk\n\n',p3,t3,h3);
fprintf('At state point 4:\np4 is :%4.2f bar\nT4 is :4.2f degree celcius\nh4 is :%4.2f kj/kg\ns4 is :%4.2f kj/kgk\n\n',p4,t4,h4);
fprintf('wt is :%4.2f kj/kg\nwp is :%4.2f kj/kg\nNtherm is :4.2f percent\nS.S.C is :%4.2f kg/kwh',wt,wp,wnet);
%vapour line
temp = linspace(1,t1,100);
for i=1:length(temp)
h_l(i) = XSteam('sL_T',temp(i));
h_v(i) = XSteam('sV_T',temp(i));
s_l(i) = XSteam('hL_T',temp(i));
s_v(i) = XSteam('hV_T',temp(i));
end
%plotting
subplot(1,2,1)
plot([s1 s2 s3 s4 s5 s6 s1],[t1 t2 t3 t4 t5 t5 t1],'color','g','linewidth',2,'MarkerSize',2,'markerfacecolor','b')
hold on
plot(h_l,temp,'color','r')
plot(h_v,temp,'color','r')
axis([0 10 0 800])
text(s1,t1,'1','FontSize',15)
text(s2,t2,'2','FontSize',15)
text(s3,t3,'3','FontSize',15,'HorizontalAlignment','right')
text(s4,t4,'4','FontSize',15,'HorizontalAlignment','right')
xlabel('entropy')
ylabel('temperature')
title('T-S Diagram')
subplot(1,2,2)
plot([s1 s2 s3 s4 s1],[h1 h2 h3 h4 h1],'color','g','linewidth',2,'MarkerSize',2,'MarkerFacecolor','b')
hold on
plot(h_l,s_l,'color','r')
plot(h_v,s_v,'color','r')
axis([0 10 300 4000])
text(s1,h1,'1','FontSize',15)
text(s2,h2,'2','FontSize',15)
text(s3,h3,'3','FontSize',15,'HorizontalAlignment','right','VerticalAlignment','top')
text(s4,h4,'4','FontSize',15,'HorizontalAlignment','right','VerticalAlignment','bottom')
xlabel('entropy')
ylabel('entholpy')
title('H-S Diagram')


