Project 2 - Rankine cycle Simulator
Aim :
- Create a Rankine Cycle Simulator using OCTAVE/MATLAB.
objective :
- Your code should calculate the state points of the Rankine Cycle (any type of your choice) based on user inputs.
- Then, plot the corresponding T-s and h-s plots for the given set of inputs. Title and axes labels are a must, while legends could be used if necessary.
Theory :
what is rankine cycle ?
The Rankine cycle or Rankine Vapor Cycle is the process widely used by power plamts such as coal fire power plants or nuclear reactor . In this mechanism, a fuel is used to produce heat within a boiler converting water into steam . which then expands through a turbine producing useful works This process was developed in 1859 by Scottish engineer William J.M. Rankine. This is a thermodynamics cycle which converted heat into mechanical energy —which usually gets transformed into electricity by electric generator.
rankine cycle layout

process :
1-2 Isentropic expansion
Superheated vapor expands isentropically in turbine and produces work.
2-3 Constant pressure
heat rejection High quality steam is condensed in the condenser
3-4 Isentropic compression
Water enters the pump as state 1 as saturated liquid
and is compressed isentropically to the operating pressure of the boiler.
4-1 Constant pressure heat addition
Saturated water enters the boiler and leaves it as superheated vapor at state 3
Thermodynamic equation and formule :
Isentropic relation between pressure and heat
`((p2)/(p1))=((T2)/(T1))^((gamma)/(gamma-1))`
`gamma` = specific heat ratio `((Cp)/(Cv))`
for net work and back work ratio (Bw_ratio):
w_net = wt -wp
Bw_ratio = wp/wt
wt = h3 - h4
wp = h2 - h1
where
h is the enthalpy at the state point(kj/kg),
wt = turbine work (kj/kg)
wp = pump work (kj/kg)
For thermal efficiency
thermal efficiency = w_net /(Qin)
Qin = h3 - h2
Qin = heat added by the boiler(j)
Qot = h4 -h1
code :
clear all
close all
clc
% printing statements
fprintf(" RANKINE CYCLE SIMULATOR \n");
fprintf("\n")
fprintf("1-2 is Isentropic Expansion in the Turbine \n");
fprintf("2-3 is const pressure heat rejection by the condenser \n");
fprintf("3-4 is the Isentropic compression in the pump \n");
fprintf("4-1 is const pressure hear addition by the boiler \n")
% input from the user
p1 = input("enter the pressure at the turbine inlet (in bar ): ");
t1 = input("enter the temperature at the turbine inlet (in degree celcius): ");
p2 = input("enter the pressure at the condenser (in bar): ");
fprintf("\n");
fprintf(" RESULT \n");
fprintf("\n");
%stage 1
s1 = XSteam('s_pT',p1,t1);
h1 = XSteam('h_pT',p1,t1);
% stage 2 condensor
sf2 = XSteam('sL_p',p2);
sg2 = XSteam('sV_p',p2);
hf2 = XSteam('hL_p',p2);
hg2 = XSteam('hV_p',p2);
s2 = s1 ;
t2 = XSteam('Tsat_p',p2);
%spliting formula
x2 = ((s2-sf2)/(sg2-sf2));
h2 = hf2+(x2*(hg2-hf2));
% stage 3
p3 = p2;
t3 = XSteam('Tsat_p',p2);
s3 = XSteam('sL_p',p3);
h3 = XSteam('hL_p',p3);
cp4 = XSteam('cpL_p',p3);
cv4 = XSteam('cvL_p',p3);
gamma = (cp4/cv4);
g = (gamma - 1)/gamma ;
% stage at (boiler)
p4 = p1;
s4 = s3;
h4 = XSteam('h_ps',p4,s4);
t4 = t3*((p4/p3)^g);
%turbine work
wd_tb = h1-h2;
%pump work
wd_pm = h4-h3;
%Net work,back work, ratio and thermal efficiency of rankine cycle
w_net = wd_tb - wd_pm ;
bwr = (h1-h4)/(h2-h3);
efficiency = w_net/(h1-h4) ;
efficiency = efficiency*100;
%state point parameters
%state point parameters
fprintf('state point 1 \n');
fprintf("p1 is %f \n",p1);
fprintf("t1 is %f \n",t1);
fprintf("h1 is %f \n",h1);
fprintf("s1 is %f \n",s1);
fprintf("\n");
%state point parameters
fprintf('state point 2\n');
fprintf("p2 is %f \n",p2);
fprintf("t2 is %f \n",t2);
fprintf("h2 is %f \n",h2);
fprintf("s2 is %f \n",s2);
fprintf("\n");
%state point parameters
fprintf('state point 3\n');
fprintf("p3 is %f \n",p3);
fprintf("t3 is %f \n",t3);
fprintf("h3 is %f \n",h3);
fprintf("s3 is %f \n",s3);
fprintf("\n");
%state point parameters
fprintf('state point 4\n');
fprintf("p4 is %f \n",p4);
fprintf("t4 is %f \n",t4);
fprintf("h4 is %f \n",h4);
fprintf("s4 is %f \n",s4);
fprintf("\n");
% performance parameter of rankine cycle
fprintf("performance parameter of rankine cycle \n");
fprintf("turbibe work %f \n",wd_tb);
fprintf("pump work %f \n",wd_pm);
fprintf("back work ratio %f \n",bwr);
fprintf("Thermal efficiency %f \n",efficiency);
tf_sat = XSteam('Tsat_p',p1);
sf_sat = XSteam('sL_p',p1);
hf_sat = XSteam('hL_p',p1);
sg_sat = XSteam('sV_p',p1);
hg_sat = XSteam('hV_p',p1);
figure(1)
hold on
temp = linspace(0,400,500);
% making saturated temp curve entropy
for i = 1:length(temp)
aa(i)=XSteam('sL_T',temp(i));
end
for j = 1:length(temp)
bb(j)= XSteam('sV_T',temp(j));
end
t5 = XSteam('Tsat_p',p4);
s5 = XSteam('sL_T',t5);
plot(aa,temp,'color','b','linewidth',1)
plot(bb,temp,'color','r','linewidth',1)
plot([s1,s2,s3,s4,s5,sf_sat,sg_sat,s1],[t1,t2,t3,t4,t5,tf_sat,tf_sat,t1],'color','g','linewidth',2)
title('temperature VS entropy')
xlabel('temperature (celcius)')
ylabel('entropy (KJ/Kg))')
grid on
hold off
figure(2)
tempo = linspace(0,400,500);
hold on
% enthalpy curve
for i=1:length(tempo)
cc(i)= XSteam('hL_T',tempo(i));
end
for j=1:length(tempo)
dd(j)= XSteam('hV_T',tempo(j));
end
plot(aa,cc,'color','b','linewidth',1);
plot(bb,dd,'color','r','linewidth',1);
plot([s1,s2,s3,s4,s1],[h1,h2,h3,h4,h1],'color','g','linewidth',2)
title('entropy VS enthalpy')
xlabel('entropy (KJ/Kg)')
ylabel('enthalpy (KJ/Kg)')
grid on
hold off
code explaination :
- using fprintf function we printed the statements.
- input function get the input from the user pressure p1 , temperature t1, condensor pressure as p2.
- next at stage 1 fetch the s1,h1 form XSteam library at the pressure p1 and t1 temperature.
- stage 2 at condesner we get sf2 ,sg2,hf2,hg2 at pressure p2 from the XSteam library.
- at stage 2 , s2=s1 then find out the t2 .
- dryness fraction x2 is find using the formula x2 = ((s2-sf2)/(sg2-sf2))
- using that dryness fraction we get the h2.
- at stage 3 p3 = p2 ,we find t3,s3,h3 at pressure p3 from the XSteam library.
- at stage boiler p4=p1 , s4=s3 .we get h4 at pressure p4 and entropy s4 and then using
`((p2)/(p1))=((T2)/(T1))^((gamma)/(gamma-1))`
`gamma` = specific heat ratio `((Cp)/(Cv))` we get t4.
- then we formulate to findout turbine work ,pump work,net work ,back work ratio and the thermal efficiency.
- using the fprintf we printed the h,s,t,p value at every state point and also performance parameter.
- then plot two figure of temperature vs entropy and entropy vs enthalpy
results :

plots :


conclusion :
Here we programmed which find pressure,enthalpy,entropy,temperature at every stage and also performance parameters.
Also it gives graph of temperature vs entropy and entropy vs enthalpy.