Challenge

Project 2 - Rankine cycle Simulator

%Writing a MATLAB program to perform simulation of Rankine Cycle by
%obtaining different state variables as well as plotting the T-s and h-s
%curves using XSteam library
close all
clear all
clc

%providing the initial conditions to the inlet of turbine and for the
%condenser
p1 = input('Pressure at the inlet of Turbine(bar) :  ');
T1 = input('Temperature at the inlet of the Turbine(Celsius) : ');
p2 = input('Pressure at the outlet of turbine or inlet of the condenser(bar) : ');
disp(' ')

%To find the other state variables at state 1 at the inlet to turbine by
%getting the values from XSteam library
h1 = XSteam('h_pT',p1,T1) ; %Get the superheated steam state specific enthalpy at given pressure           %and temperature
s1 = XSteam('s_pT',p1,T1) ; %Get the superheated steam state specific entropy at given pressure and %temperature
hf1 = XSteam('hL_p',p1) ; %Get the saturated liquid/fluid state specific enthalpy at given pressure
sf1 = XSteam('sL_p',p1) ; %get the saturated liquid state specific entropy at given pressure
hg1 = XSteam('hV_p',p1) ; %Get the saturated vapour state specific enthalpy at given pressure
sg1 = XSteam('sV_p',p1) ;%Get the saturated vapour state specific entropy at given pressure
Tsat1 = XSteam('Tsat_p',p1) ;%get the saturated vapour state temperature

%To find the variables at state 2 at the inlet of the condenser
s2 = s1 ; %constant entropy process 1 to 2
hf2 = XSteam('hL_p',p2);
sf2 = XSteam('sL_p' ,p2) ;
hg2 = XSteam('hV_p',p2) ;
sg2 = XSteam('sV_p',p2) ;
sfg2 = sg2 - sf2 ; % specific entropy of evaporation
x2 = (s2 - sf2)/(sfg2) ; % x is dryness fraction
hfg2 = (hg2 - hf2) ; %specific enthalpy of evaporation
h2 = hf2 + (x2 * hfg2 ) ;
T2 =XSteam('T_ph',p2,h2); % saturated vapour state temperature after coming out of turbine
Tsat2 = XSteam('Tsat_p',p2); % saturated vapour state temperature at pressure

%To find the state variables at point 3  at the inlet to feed pump
T3 = T2 ;
p3 = p2 ;
h3 = XSteam('hL_p',p3)  ; %saturated liquid enthalpy coming out of the condenser
s3 = XSteam('sL_p',p3) ; %saturated liquid entropy coming out of the condenser

%To find the state variables at point 4 at the inlet to the boiler
s4 = s3 ;
p4 = p1 ;
h4 = XSteam('h_ps',p4,s4) ; %specific enthalpy of the mixture at pressure and entropy
T4 = XSteam('T_ps',p4,s4) ; % temperature of the mixture at pressure and entropy

%To display the result which are the state variables at all points.

%state 1
disp('State variables at state point 1 are = ')
fprintf('p1 = %.2f (bar) \n',p1)
fprintf('T1 = %.2f (degree C) \n',T1)
fprintf('h1 = %.2f (KJ/kg) \n',h1 )
fprintf('s1 = %.2f (KJ/kgK) \n',s1)
disp(' ')

%state 2
disp('State variables at state point 2 are = ')
fprintf('p2 = %.2f (bar) \n',p2)
fprintf('T2 = %.2f (degree C) \n',T2)
fprintf('h2 = %.2f (KJ/kg) \n',h2 )
fprintf('s2 = %.2f (KJ/kgK) \n',s2)
disp(' ')

%state 3.
disp('State variables at state point 3 are = ')
fprintf('p3 = %.2f (bar) \n',p3)
fprintf('T3 = %.2f (degree C) \n',T3)
fprintf('h3 = %.2f (KJ/kg) \n',h3)
fprintf('s3 = %.2f (KJ/kgK) \n',s3)
disp(' ')

%state 4.
disp('State variables at state point 1 are = ')
fprintf('p4 = %.2f (bar) \n',p4)
fprintf('T4 = %.2f (degree C) \n',T4)
fprintf('h4 = %.2f (KJ/kg) \n',h4)
fprintf('s4 = %.2f (KJ/kgK) \n',s4)
disp(' ')

%to plot the T-s graph
figure(1) ,clf
hold on

%plotting the saturation  curves
t1 = linspace(0,500,200);
for i = 1:length(t1)
    sL(i) = XSteam('sL_T',t1(i));
    sV(i) = XSteam('sV_T',t1(i));

end
plot(sL,t1,'linewidth',2,'color','r') %saturation liquid curve
plot(sV,t1,'linewidth',2,'color','g') %saturation vapour curve

%to plot the rankine cycle on T-s
plot([s1 s2],[T1 T2],'linewidth',2,'color','b')
text(s1,T1,'1','FontSize',10) % to mark the state number

if x2 > 1
    T3 = Tsat2 ;
    plot([s2 sg2 s3 s4],[T2 Tsat2 T3 T4],'linewidth',2,'color','b')
    T2 =Tsat2 ;
    text(s2,T2,'2','FontSize',10)
    text(s3,T3,'3','FontSize',10)
else
    plot([s2 s3 s4],[T2 T3 T4],'linewidth',2,'color','b')
    text(s2,T2,'2','FontSize',10)
    text(s3,T3,'3','FontSize',10)
end

t = linspace(T1,T2,500) ;
for j= 1 :length(t)
    plot(XSteam('s_pT',p1,t(j)),t(j),'.','linewidth',2,'color','b')
end

plot([sf1 sg1],[Tsat1 Tsat1],'linewidth',2,'color','b')
text(sf1,Tsat1,'4','FontSize',10)

axis([0 10 0 550])
xlabel('s-{Entropy} KJ/kgK')
ylabel('T-{Temperature} K')
title('Rankine cycle T Vs s graph')
legend('saturation liquid curve ','saturation vapour curve ','T-s curve')

% To plot h - s graph
 figure(2),clf
 hold on

 %to plot the saturation curves on h-s graph
 for k= 1:length(t1)
     sL(k)= XSteam('sL_T',t1(k));
     sV(k)= XSteam('sV_T',t1(k));
     hL(k)= XSteam('hL_T',t1(k));
     hV(k)= XSteam('hV_T',t1(k));
     %plot(XSteam('sL_T',t1(k)),XSteam('hL_T',t1(k)),'linewidth',2,'color','r'),
     %plot(XSteam('sV_T',t1(k)),XSteam('hV_T',t1(k)),'linewidth',2,'color','r'),
 end

plot(sL,hL,'linewidth',2,'color','r') %saturation liquid curve
plot(sV,hV,'linewidth',2,'color','g') %saturation vapour curve

 %to plot the rankine cycle on h-s
 plot([s1 s2 s3 s4 s1],[h1 h2 h3 h4 h1],'linewidth',2,'color','b')
 text(s1,h1,'1','FontSize',10)
 text(s2,h2,'2','FontSize',10)
 text(s3,h3,'3','FontSize',10)
 text(s4,h4+90,'4','FontSize',10)

 axis([0 10 0 4500])
 xlabel('s -{Entropy} KJ/kgK')
 ylabel('h -{Enthalpy} KJ/Kg')
 title('Rankine cycle h Vs s graph')
 legend('saturation liquid curve','saturation vapour curve','h-s curve')

%Finding the efficiency of the Rankine cycle

hf4 = h4 ;
hf3 = h3 ;
%calculating the heat supplied to boiler per kg of working fluid(KJ/Kg)
 Q1_boiler = h1 -hf4
%calculating the Workdone by the turbine per kg of working fluid(KJ/kg)
W_turbine = h1-h2
%calculating the heat taken away at condenser per kg of working fluid(KJ/kg)
Q2_condensor = h2-hf3
%Calculating the work done by pump per kg of working fluid(KJ/kg)
W_pump  = hf4 - hf3
%Net work done per kg of working fluid(KJ/kg)
W_net= (W_turbine) - (W_pump)

%Finding the efficiency of Rankine cycle(percentage)
Eff_RC=( W_net/Q1_boiler)*100

%finding the back work ratio
Work_ratio = W_net/W_turbine

%finding the specific steam consumption(kg/kWh)
SSC = 3600/W_turbine
Your portfolio, next

Ship work like this
in your own course.

Talk to a career counsellor

Free 20-minute call. We'll map the right course to where you want to work.

By submitting you agree to our Terms and Privacy Policy.

Talk to a career counsellor

Free 20-minute call. We'll map the right course to where you want to work.

By submitting you agree to our Terms and Privacy Policy.