Project 2 - Rankine cycle Simulator
clear all
close all
clc
% Ranking cycle description
disp(' RANKINE CYCLE SIMULATOR ')
disp('1-2 is Isentroptic Expansion in the Turbine')
disp('2-3 is Constant Pressure Heat Rejection by the Condenser')
disp('3-4 is Isentropic Compression in the Pump')
disp('4-1 is Constant Pressure Heat Addition by the Boiler\n\n')
% Operating pressure inputs for the rankine cylce
p1 = input('Enter the Pressure at Turbine Inlet (in bar) : ');
t1 = input('Enter the Temperature at Turbine Inlet (in Celsius) : ');
p2 = input('Enter the Pressure at Condenser Inlet (in bar) : ');
% Extracting the values for (state 1) h1 and s1 from XSteam file
h1 = XSteam('h_pT',p1,t1);
s1 = XSteam('s_pT',p1,t1);
% Displaying state point 1
fprintf('p1 = %5.3f bar\n',p1)
fprintf('t1 = %5.3f c\n',t1)
fprintf('h1 = %5.3f KJ/kg\n',h1)
fprintf('s1 = %5.3f kJ/kg.k\n\n\n',s1)
% for state 2
s2 = s1;
sf2 = XSteam('sL_p',p2);
sg2 = XSteam('sV_p',p2);
x2 = (s2-sf2)/(sg2-sf2);
hf2 = XSteam('hL_p',p2);
hg2 = XSteam('hV_p',p2);
h2 = hf2 + (x2*(hg2 - hf2));
% for state 3
p3 = p2;
s3 = XSteam('sL_p',p3);
h3 = XSteam('hL_p',p3);
% for state 4
s4 = s3;
p4 = p1;
wt = h1 - h2; %workdone by turbine
v3 = XSteam('vL_p',p3);
wp = v3*(p4 - p3)*100;
h4 = h3 + wp; % work done to run pump
% net work done
wnet = wt - wp;
% heat added to the system
qin = h1 - h4;
% heat out of the system
qout = h2 - h3;
% Thermal efficiency
th_eff = (wnet/qin)*100;
% Specific steam consumption
SSC = (3600/wnet);
% temperatures at state points
t3 = XSteam('Tsat_p',p3);
t2 = t3;
cp4 = XSteam('Cp_ps',p4,s4);
cv4 = XSteam('Cv_ps',p4,s4);
k = cp4/cv4;
t4 = t3/((p3/p4)^((k-1)/k));
% Values for temperature,enthalpy and entropy at saturation curve
t6 = XSteam('Tsat_p',p1);
s5 = XSteam('sL_p',p1);
s6 = XSteam('sV_p',p1);
h5 = XSteam('hL_p',p1);
h6 = XSteam('hV_p',p1);
t5 = t6;
% Calculating values for saturation curve
T = linspace(1,400,1000);
sf = 0;
sg = 0;
hf = 0;
hg = 0;
for i = 1:length(T)
sf(i) = XSteam('sL_T',T(i));
sg(i) = XSteam('sV_T',T(i));
hf(i) = XSteam('hL_T',T(i));
hg(i) = XSteam('hV_T',T(i));
end
% plotting T-s diagram
figure(1)
hold on
plot(sf,T,'r','linewidth',1)
plot(sg,T,'r','linewidth',1)
plot([s1 s2],[t1 t2],'linewidth',3)
plot([s2 s3],[t2 t3],'linewidth',3)
plot([s3 s4],[t3 t4],'linewidth',3)
plot([s4 s5],[t4 t5],'linewidth',3)
plot([s5 s6],[t5 t6],'linewidth',3)
sp1 = linspace(s6,s1,1000);
for i = 1:length(sp1)
tp1(i) = XSteam('T_ps',p1,sp1(i));
end
plot(sp1,tp1,'k','linewidth',2);
text(s1+0.1,t1,'1');
text(s2+0.1,t2,'2');
text(s3,t3-20,'3');
text(s4,t4+20,'4');
title('Temperature vs Entropy')
xlabel('Entropy (S) in KJ/kg.k')
ylabel('Temperature in celsius')
legend('Saturation curve')
% Plot H vs S diagram
figure(2)
hold on
plot(sf,hf,'r','linewidth',1)
plot(sg,hg,'r','linewidth',1)
plot([s1 s2],[h1 h2],'linewidth',3)
plot([s2 s3],[h2 h3],'linewidth',3)
plot([s3 s4],[h3 h4],'linewidth',3)
hp1 = linspace(h4,h5,100);
for j = 1:length(hp1)
sch(j) = XSteam('S_ph',p1,hp1(j));
end
plot(sch,hp1,'k','linewidth',2);
plot([s5 s6],[h5 h6],'k','linewidth',2)
for k = 1:length(sp1)
hc1(k) = XSteam('h_ps',p1,sp1(k));
end
plot(sp1,hc1,'k','linewidth',2)
text(s1+0.1,h1,'1');
text(s2+0.1,h2,'2');
text(s3,h3-100,'3');
text(s4,h4+200,'4');
title('Enthalpy vs Entropy')
xlabel('Entropy (S) in KJ/kg.k')
ylabel('Enthalpy (H) in KJ/kg')
legend('Saturation curve')
% Displaying state point 2
fprintf('p2 = %5.3f bar\n',p2)
fprintf('t2 = %5.3f c\n',t2)
fprintf('h2 = %5.3f KJ/kg\n',h2)
fprintf('s2 = %5.3f kJ/kg.k\n',s2)
fprintf('x2 = %5.3f \n\n\n',x2)
% Displaying state point 3
fprintf('p3 = %5.3f bar\n',p3)
fprintf('t3 = %5.3f c\n',t3)
fprintf('h3 = %5.3f KJ/kg\n',h3)
fprintf('s3 = %5.3f kJ/kg.k\n\n\n',s3)
% Displaying state point 4
fprintf('p4 = %5.3f bar\n',p4)
fprintf('t4 = %5.3f c\n',t4)
fprintf('h4 = %5.3f KJ/kg\n',h4)
fprintf('s4 = %5.3f kJ/kg.k\n\n\n',s4)
% Displaying other calculated parameters
fprintf('Turbine work = %5.3f KJ/kg',wt);
fprintf('pump work = %5.3f KJ/kg',wp);
fprintf('net work done = %5.3f KJ/kg',wnet);
fprintf('Thermal Efficiency = %5.3f KJ/kg',th_eff);
fprintf('Specific Steam consumption = %5.3f KJ/kwh',SSC);

