Project 2 - Rankine cycle Simulator
Code for Rankine Cycle Simulator
Function used - XSteam.m
%Rankine Cycle Simulator
%Inputs for Inlet Pressure and Temperature
p1= 0;
p2=0;
t1=0;
while p1<=0
p1 = input(' Please enter the value for Pressure entering Turbine in bar \n');
if p1<=0
warndlg('Please enter value greater than 0');
end
end
while p2<=0
p2 = input(' Please enter the value for Pressure entering Condenser in bar \n');
if p2<=0 || p2>=p1
warndlg('Please enter value greater than 0 and Pressure entering Turbine');
end
end
while t1<=0
t1 = input(' Please enter the value for Temperature entering Turbine in degree C \n');
if t1<=0
warndlg('Please enter value greater than 0');
end
end
%State 1
h1 = XSteam('h_pT',p1,t1);
s1 = XSteam('s_pT',p1,t1);
%State 2
s2 = s1;
sg = XSteam('sV_p',p2);
sf = XSteam('sL_p',p2);
sfg = sg-sf;
x = (s2-sf)/sfg;
hf = XSteam('hL_p',p2);
hg = XSteam('hV_p',p2);
hfg = hg-hf;
h2 = hf+(x*hfg);
t2 = XSteam('T_ps',p2,s2);
%State 3
t3 = t2;
p3 = p2;
s3 = XSteam('sL_T',t3);
h3 = XSteam('hL_T',t3);
%State 4
p4 = p1;
s4 = s3;
h4 = XSteam('h_ps',p4,s4);
t4 = XSteam('T_ps',p4,s4);
%State 4"
p5=p4;
t5 = XSteam('Tsat_p',p5);
h5 = XSteam('hL_T',t5);
s5 = XSteam('sL_p',p5);
%State 1"
t6 = t5;
h6 = XSteam('hV_T',t6);
s6 = XSteam('sV_T',t6);
%Work, Energy and Thermal Efficiency
w_pump = h4-h3;
q_in = h1-h4;
w_turbine = h1-h2;
q_out = h2-h3;
net_work = w_turbine-w_pump;
back_work = w_pump/w_turbine;
eta = (1- ((q_out)/(q_in)))*100;
%Creating Output Text File
fid = fopen('Rankine Cycle Simulator.txt','w');
fprintf(fid,' Rankine Cycle Simulator\n\n');
fprintf(fid,'1-2 is Isentropic Expansion in the Turbine\n');
fprintf(fid,'2-3 is Constant Pressure Heat Rejection by the Condenser\n');
fprintf(fid,'3-4 is Isentropic Compression in the Pump\n');
fprintf(fid,'4-1 is Constant Pressure Heat Addition to the Boiler\n\n');
fprintf(fid,'Pressure Entering the Turbine Inlet = %.2f bar\n',p1);
fprintf(fid,'Temperature Entering the Turbine Inlet = %.2f degree C\n',t1);
fprintf(fid,'Pressure Entering the Condenser Inlet = %.2f bar\n\n',p2);
fprintf(fid,' Results\n\n');
fprintf(fid,'At State Point 1 : At State Point 3 :\n\n');
fprintf(fid,'Pressure is : %.2f bar Pressure is : %.2f bar\n',p1,p3);
fprintf(fid,'Temperature is : %.2f degree C Temperature is : %.2f degree C\n',t1,t3);
fprintf(fid,'Enthalpy is : %.2f KJ/Kg Enthalpy is : %.2f KJ/Kg\n',h1,h3);
fprintf(fid,'Entropy is : %.2f KJ/Kg.K Entropy is : %.2f KJ/Kg.K\n\n',s1,s3);
fprintf(fid,'At State Point 2 : At State Point 4 :\n\n');
fprintf(fid,'Pressure is : %.2f bar Pressure is : %.2f bar\n',p2,p4);
fprintf(fid,'Temperature is : %.2f degree C Temperature is : %.2f degree C\n',t2,t4);
fprintf(fid,'Enthalpy is : %.2f KJ/Kg Enthalpy is : %.2f KJ/Kg\n',h2,h4);
fprintf(fid,'Entropy is : %.2f KJ/Kg.K Entropy is : %.2f KJ/Kg.K\n\n',s2,s4);
fprintf(fid,'Work done on the Pump is %.2f KJ/Kg\n',w_pump);
fprintf(fid,'Work done by the Turbine is %.2f KJ/Kg\n',w_turbine);
fprintf(fid,'Net Work done by the Cycle is %.2f KJ/Kg\n',net_work);
fprintf(fid,'Back Work ratio of the Cycle is %.2f\n',back_work);
fprintf(fid,'Heat Absobed by the Boiler is %.2f J\n',q_in);
fprintf(fid,'Heat Rejected by the Condenser is %.2f J\n',q_out);
fprintf(fid,'Thermal Efficiency of the Cycle is %.2f%% \n',eta);
fclose(fid);
%Calculating values for Vapour Dome Plot for T-S
for i=1:t1
dome1(i) = XSteam('sL_T',i);
temp(i) = i;
end
for i=1:t1
dome2(i) = XSteam('sV_T',i);
end
%Calculating values for Vapour Dome Plot for H-S
for i=1:t1
dome3(i) = XSteam('hL_T',i);
end
for i=1:t1
dome4(i) = XSteam('hV_T',i);
end
%Plotting vapour dome first and then creatinng lines between states
figure(1)
hold on
plot([dome1 dome2],[temp temp],'r')
xlabel('Entropy (KJ/Kg.K)');
ylabel('Temperature (degree C)');
plot([s1 s2],[t1 t2],'color','black','linewidth',2)
plot([s3 s4],[t3 t4],'color','black','linewidth',2)
plot([s2 s3],[t2 t3],'color','black','linewidth',2)
plot([s4 s5],[t4 t5],'color','black','linewidth',2)
plot([s5 s6],[t5 t6],'color','black','linewidth',2)
plot([s6 s1],[t6 t1],'color','black','linewidth',2)
text(s1+0.5,t1,'1','color','b');
text(s2+0.5,t2,'2','color','b');
text(s3-0.5,t3,' 3','color','b');
text(s4-0.5,t4+25,' 4','color','b');
text(s5-0.5,t5,' 4"','color','b');
text(s6-0.5,t6+25,' 1"','color','b');
title('Entropy vs Temperature');
hold off
%Using hold off command to switch to terminate any further operations on
%figure 1
figure(2)
hold on
plot([dome1 dome2],[dome3 dome4],'r')
plot([s1 s2],[h1 h2],'color','black','linewidth',2)
plot([s3 s4],[h3 h4],'color','black','linewidth',2)
plot([s2 s3],[h2 h3],'color','black','linewidth',2)
plot([s1 s4],[h1 h4],'color','black','linewidth',2)
text(s1+0.5,h1,'1','color','b');
text(s2+0.5,h2,'2','color','b');
text(s3-0.5,h3+100,' 3','color','b');
text(s4-0.5,h4-100,' 4','color','b');
xlabel('Entropy (KJ/Kg.K)');
ylabel('Enthalpy (KJ/Kg)');
title('Entropy vs Enthalpy');
axis([0 s1+2 0 h1+300])
hold off