Project 2 - Rankine cycle Simulator
OBJECTIVES :
- Writing a code to simulate rankine cycle.
- Extracting steam and water properties from Xsteam data.
- Calculating all state points of the cycle using user inputs.
- Plotting T Vs S and H Vs S plots for the given inputs.
THEORY :
The ideal Rankine cycle consists of followin four processes :
- Process 1-2 : Isentropic expansion in the turbine.
- Process 2-3 : Constant Pressure heat rejection in the condenser.
- Process 3-4 : Isentropic compression in the compresser.
- Process 4-1 : Constant pressure heat addition in the boiler.

Process 1–2 : Saturated dry steam expands through a steam turbine, generating energy. From a thermodynamic point of view, this lowers the temperature and pressure of the steam, and some condensation can occur. The output in this process can be easily calculated using the graph or tables indicated above. In other words, Process 1-2 is isentropic turbine expansion, isentropic process.
Wturbine, out = h2 - h1
Process 2–3 : Wet steam enters a condenser, where it condenses at a constant pressure to become a saturated liquid. In other words, Process 2-3 is rejection of heat at constant pressure in the condenser, isobaric process.
Qout = h2 - h3
Process 3–4 : The working fluid is pumped from low to high pressure. Since the fluid is a liquid at this stage, the pump requires little input energy. In other words, Process 3-4 involves isentropic compression in the pump, isentropic process.
Wpump, in = h4 - h3
Process 4–1 : The high pressure liquid enters a boiler, where it is heated at constant pressure by an isobaric process by an external heat source to become a saturated dry steam. The required input energy can be easily calculated graphically, using an enthalpy-entropy graph (hs graph or Mollier diagram), or numerically, using steam tables. In other words, Process 4-1 is the addition of heat at constant pressure in the boiler, an isobaric process.
Qin = h1 - h4
MATLAB CODE :
clear all
close all
clc
%inputs of user
fprintf('%75s','Rankine cycle simulator');
fprintf('\n \n \n')
fprintf('1-2 is Isentropic Expansion in the Turbine \n');
fprintf('2-3 is Constant Pressure heat rejection by the Condenser \n');
fprintf('3-4 is Isentropic Compression in the Pump \n');
fprintf('4-1 is Constant Pressure Heat addition by the boiler \n \n');
%inputs
p1 = input('Enter the pressure at the inlet of the Turbine :');
t1 = input('Enter the Temperature at the inlet of the Turbine :');
p2 = input('Enter the pressure at the inlet of the Condenser :');
s1 = XSteam('s_pT',p1,t1);
h1 = XSteam('h_pT',p1,t1);
%condenser inlet
s2 = s1;
sf2 = XSteam('sL_p',p2);
sg2 = XSteam('sL_p',p2);
hf2 = XSteam('hL_p',p2);
hg2 = XSteam('hL_p',p2);
%calculating dryness fraction
if(s2<=sg2)
x2 = ((s2 -sf2)/(sg2-sf2));
else
x2 = 1;
end
h2 = hf2 + (x2*(hg2-hf2));
%condenser exit
p3 =p2;
t3 = XSteam('Tsat_p',p3);
s3 = XSteam('sL_p',p3);
h3 = XSteam('hL_p',p3);
v3 = XSteam('vL_p',p3);
t2 =t3;
%boiler inlet
p4 = p1;
s4 = s3;
h4 = XSteam('h_ps',p4,s4);
cp4 = XSteam('Cp_ps',p4,s4);
cv4 = XSteam('Cv_ps',p4,s4);
g4 = (cp4/cv4);
t4 = (t3*((p3/p4)^((1-g4)/g4)));
%Calculating
%work done by the turbine
Wt = h1-h2;
%work done by the pump
Wp = h4-h3;
%net work done
W_net = Wt-Wp;
%heat addition in the boiler
q_in = h1-h4;
%heat rejection in the condenser
q_out = h2-h3;
%Thermal Efficiency
n = (W_net/q_in)*100
%plotting
figure(1)
t = linspace(1,t1,1000);
for i=1:length(t)
s_l(i) = XSteam('sL_T',t(i));
end
for i=1:length(t)
s_v(i) = XSteam('sV_T',t(i));
end
hold on
plot(s_l,t,'linewidth',2,'linestyle','- -','color','r');
plot(s_v,t,'linewidth',2,'linestyle','- -','color','r');
grid on
%process 1-2
plot([s1,s2],[t1,t2],'linewidth',2,'color','k')
hold on
title('T-S diagram of Rankine cycle')
xlabel('Entropy KJ/KgK')
ylabel('Temperature K')
%process2-3
plot([s2,s3],[t2,t3],'linewidth',2,'color','k')
hold on
%process 3-4
plot([s3,s4],[t3,t4],'linewidth',2,'color','k')
hold on
%process 4-1
tp = XSteam('Tsat_p',p4);
sp = XSteam('sL_T',tp);
plot([s4,sp],[t4,tp],'linewidth',2,'color','k')
hold on
tq = tp;
sq = XSteam('sV_T',tq);
plot([sp,sq],[tp,tq],'linewidth',2,'color','k')
hold on
plot([sq,s1],[tq,t1],'linewidth',2,'color','k')
hold on
%Indicating states
text(s1,t1,'1');
text(s2,t2,'2');
text(s3,t3,'3');
text(s4,t4,'4');
%Enthalpy Vs Entropy
figure(2)
plot([s1,s2],[h1,h2],'linewidth',2,'color','k')
grid on
title('H-S diagram')
xlabel('Entropy KJ/KgK')
ylabel('Enthalpy KJ/Kg')
hold on
plot([s2,s3],[h2,h3],'linewidth',2,'color','k')
hold on
plot([s3,s4],[h3,h4],'linewidth',2,'color','k')
hold on
plot([s4,s1],[h4,h1],'linewidth',2,'color','k')
%liquid Vs vapour saturation curve
t = linspace(1,t1,1000);
for j=1:length(t)
h_l(j) = XSteam('hL_T',t(j));
end
for j=1:length(t)
h_v(j) = XSteam('hV_T',t(j));
end
plot(s_l,h_l,'linewidth',2,'color','r')
hold on
plot(s_v,h_v,'linewidth',2,'color','r')
text(s1,h1,'1');
text(s2,h2,'2');
text(s3,h3,'3');
text(s4,h4,'4');
%output results
fprintf('%40s \n \n \n','RESULTS');
fprintf('%10s %54s \n','At state point 1','At state point 2');
fprintf('%s %.2f%s %44s %.2f%s \n','P1:',p1,'bar','P2:',p2,'bar');
fprintf('%s %.2f%s %35s %.2f%s \n','T1:',t1,'deg celcius','T2:',t2,'deg celcius');
fprintf('%s %.2f%s %40s %.2f%s \n','H1:',h1,'KJ/Kg','H2:',h2,'KJ/Kg');
fprintf('%s %.2f%s %42s %.2f%s \n','S1:',s1,'KJ/KgK','S2:',s2,'KJ/KgK');
fprintf('%58s %.2f \n \n','X2:',x2);
fprintf('%10s %54s \n','At state point 3','At state point 4');
fprintf('%s %.2f%s %45s %.2f%s \n','P3:',p3,'bar','P4:',p4,'bar');
fprintf('%s %.2f%s %35s %.2f%s \n','T3:',t3,'deg celcius','T4:',t4,'deg celcius');
fprintf('%s %.2f%s %41s %.2f%s \n','H3:',h3,'KJ/Kg','H4:',h4,'KJ/Kg');
fprintf('%s %.2f%s %42s %.2f%s \n','S3:',s3,'KJ/KgK','S4:',s4,'KJ/KgK');
fprintf('%40s %.2f %s \n','Work output by Turbine(Wt):',Wt,'KJ/Kg');
fprintf('%40s %.2f %s \n','Work input by pump(Wp):',Wp,'KJ/Kg');
fprintf('%40s %.2f %s \n','Net Work(Wnet):',W_net,'KJ/Kg');
fprintf('%40s %.2f %s \n','Thermodynamic Efficiency(Ntherm):',n,'Percentage');
fprintf('%40s %.2f %s \n','Heat input in Boiler:',q_in,'KJ/Kg');
fprintf('%40s %.2f %s \n','Heat rejection in condenser:',q_out,'KJ/Kg');
fprintf('%40s %.2f %s \n','S.S.C.:',p3,'Kg/KWh');
RESULTS & PLOTS :

Figure 1 :

Figure 2 :
