Project 2 - Rankine cycle Simulator
#10 /Project 2 – Rankine Cycle Simulator.
AIM: To Programme a Rankine Cycle Simulator using MATLAB.
OBJECTIVE:
- To write a code in MATLAB that creates a ‘T-S’ and ‘H-S’ diagram for Rankine Cycle.
- To calculate the Net Work & back work ratio of the Rankine Cycle based on user inputs.
THEORY:
The Rankine cycle is the fundamental operating cycle of all power plants where an operating fluid is continuously evaporated and condensed. The selection of operating fluid depends mainly on the available temperature range.

There are four processes in the Rankine cycle. The states are identified by numbers (in brown) in the T-s diagram.
- Process 1–2: The working fluid is pumped from low to high pressure. As the fluid is a liquid at this stage, the pump requires little input energy. Process 1-2 is isentropic compression.
- Process 2–3: The high-pressure liquid enters a boiler, where it is heated at constant pressure by an external heat source to become a dry saturated vapour. The input energy required can be easily calculated graphically, using an enthalpy-entropy chart (h-s chart, or Mollier diagram), or numerically, using steam tables or software. Process 2-3 is constant pressure heat addition in boiler.
- Process 3–4: The dry saturated vapour expands through a turbine, generating power. This decreases the temperature and pressure of the vapour, and some condensation may occur. The output in this process can be easily calculated using the chart or tables noted above. Process 3-4 is isentropic expansion.
- Process 4–1: The wet vapour then enters a condenser, where it is condensed at a constant pressure to become a saturated liquid. Process 4-1 is constant pressure heat rejection in condenser.

1 – 2 : Isentropic Compression in a Pump.
2 – 3 : Constant Pressure Heat Addition in a Boiler.
3 – 4 : Isentropic Expansion in a Turbine.
4 – 1 : Constant Pressure Heat Rejection in Condenser.
Water enters in the pump at state1 as saturated liquid and it compressed isentropically to the operating pressure of the boiler. The water temp. increases during this isentropic compression process due to a slight decrease in the specific volume of water.
>> Wpumps = H2 – H1 ,
Water enters the boiler as a compressed liquid at state2 and leaves as a superheated vapor at state3. The boiler is basically a large heat exchanger where the heat originating from combustion gases, nuclear reactors, or other sources is transferred to the water essentially at constant pressure. The boiler, together with the section where the steam is superheated, is often called the steam generator.
>> Qadd = H3 – H2 ,
The superheated vapor at state3 enters the turbine, where it expands isentropically and produceds work by rotating the shaft connected to an electric generator. The pressure and the temp. of steam drop during this process to the values at state4, where steam enters in the condenser. At this state, steam is usually a saturated liquid-vapor mixture with a high quantity.
>> WT = H4 – H3 ,
Steam is condensed at constant pressure in the condenser, which is basically a large heat exchanger, by rejecting heat to a cooling medium such as water body or atmosphere. Steam leaves the condenser as saturated liquid and enters the pump, completing the cycle. In areas where water is precious, the power plants are cooled by air instead of water. This method of cooling, which is also used car engines, is called dry cooling.
>> Qre = H4 – H1 ,
During a Rankine Cycle, work is done on the fluid by the pumps between states 1 and 2 , ( isentropic compression). Work is done b the fluid in the turbine between stages 3 and 4 (isentropic expansion). The difference between the work done by the fluid and the work done on the fluid is the net work produced by the cycle and it corresponds to the area enclosed by the cycle curve (in PV diagram). The working fluid in a Rankine Cycle follows a closed loop and reused constantly.
As can be seen, it is convenient to use enthalpy and the first law in terms of enthalpy in analysis of this thermodynamic cycle. This form of the law simplifies the description of energy transfer. At constant pressure, the enthalpy change equals the energy transferred from the environment through heating :
Isobaric process (Vdp = 0) :
dH = dQ à Q = H2 – H1 ;
At constant entropy, i.e., in isentropic process, the enthalpy change equals the flow process work done on or by the system :
Isentropic process (dQ = 0) :
dH = Vdp à W = H2 – H1 ;

(Rankine Cycle in a Nuclear Power Plant)
MATHEMATICAL EQUATIONs:
- Net Work done (WNet) = WTurbine – Wpump ;
- Thermal Efficiency (η) = WNet / Qin ;
- Work Ratio (WR) = WNet / WTurbine ;
- Back Work Ratio (BWR) = WPump / WTurbine ;
- WR + BWR = 1 ;
- Heat Rate (HR) = 1/ η ;
- Steam Rate (SSC) = 1 / WNet ;
CODE EXPLANATIONs / PROCEDURE :
NOTE:
- To simulate and find out different state variables, all the processes parameters are to be described such as all four processes occurring and inputs parameters.
- From the standard ‘X-steam’ data is used to extract steam and water properties of Enthalpy, Entropy at specific pressure and temperatures for saturated liquid and vapour conditions etc.
- The program requires the input of pressure (in bar) at turbine inlet, Temperature at turbine inlet (degree C) and pressure at the turbine outlet(in bar)
Like I put….>>
Enter the Pressure at the Turbine Inlet (in bar): -> 30
Enter the Temperature at the Turbine Inlet (in Degree C ): -> 400
Enter the Pressure at the Turbine Outlet (in bar): -> 0.05
- With the help of these inlets & from ‘Xsteam’ data, the program calculates all the state points of the Rankine cycle.
The ‘Xsteam’ data works as, h1=XSteam(h_pT,p1,T1) it returns the Enthalpy, Entropy at specific pressure and temperatures in bar and Degree C respectively.
- As we extract the data, we use thermodynamics relations to further find state points and extract their data from XSteam data file which are mentioned after studying the Rankine cycle.
- ‘sf’ and ‘sg’ & ‘hf’ and ‘hg’, where f and g stands for saturated liquid and vapour respectively are calculated after studying the plots of Rankine cycles and extracting data from Xsteam file.
- The net work done, work done by turbine, work by pump, thermal efficiency, back work ratio, work ratio, heat rate, heat in, heat out, specific steam consumption are calculated using standard thermodynamics relations and mentioning them in program using those relations.
- To plot the property diagram of water, i.e., saturation liquid and vapour line, an array is created using ‘linspace’ command from 0 to value of T1 with 5000 evenly spaced points in between them and suitable state variables are iterated using ‘for’ loop.
- T, s and h are extracted at vapour and liquid line for plotting purpose, after 4th point for the variation observed in the plot.
- Saturation curve is plotted in ‘----’ for saturated liquid & gas in T-s and h-s graph’s, also with all the required points are plotted and marked using ‘text’ command
- The plots changes as the user input changes for the above mentioned inputs.
- Results are displayed in the command window by using ‘fprintf’ command.
Start programming in MATLAB with these three commands, as all the previous calculations are erased.
Clear all: for clears all the data stored in the workspace previously.
Close all: for closes all the previous figures and plots.
clc: for clears the command window.
- Line6-19// mentions all 4 processes using ‘fprintf’ command.
- Line21-24// create input state variables at point1.(for p1,T1,p2)
- Line26-139// calculating state variables at all points from given datafile (XSteam),
Get those data form ‘XSteam’ file and calculate those data using standard thermodynamic formulas for finding ‘p,T,h,s’ etc. at all state points (1,2,3,4) & print those final ‘p,T,h,s’ values using ‘fprintf’ command at all points.
- Line143-175// calculating Net work output, net heat, back work ratio, Thermal efficiency, heat rate & specific steam consumption using formula and print it for getting the output results.
- Line177-185// for saturation liquid and vapour line, an array is created using ‘linspace’ command from 0 to value of T1 with 5000 evenly spaced points in between them and suitable state variables are iterated using ‘for’ loop.
- Line187-190// plotting of saturated curve for T-s diagram using ‘plot’ command.
- Line192-211// for figure1 (T-s diagram) plot all following paths and put ‘color’ and ‘linewidth’ commands after that using ‘legend’ command for mention the saturated liquid and vapour curve.
- Line213-225// using ‘text’ command for mark those all four state points. & use ‘fontsize’ command for give a suitable size of all those lines.
- Line227-231// put a proper dimension of the figure using ‘axis’ command, ‘title’ command for giving a title of the graph, label it with specific parameters, ‘grid on’ command is enable.
- Line234-258// at last for figure2 (h-s diagram) do the same process, plot all points, give text for mark state points, then give the title and label it properly with specific parameters for fig2. ‘legend’ also use for mark saturated curve in the diagram & enable the grid.
CODE FOR RANKINE CYCLE SIMULATOR:-
%Program for simulating Rankine Cycle and plot required graphs.
clear all
close all
clc
%Subscript for different state points.
% 1= Turbine inlet or Boiler outlet, 2= Condenser inlet or Turbine outlet,
% 3= Pump inlet or Condenser outlet, 4= Boiler inlet or Pump outlet.
%input parameters-
% p1 = Turbine inlet pressure (bar),
% T1 = Temperature at Turbine inlet (deg C),
% p2 = Turbine outlet pressure (bar),
fprintf('Process (1-2) - Isentropic Expansion in the Turbine \n');
fprintf('Process (2-3) - Isentropic Heat Rejection by the Condenser \n');
fprintf('Process (3-2) - Isentropic Compression in the Pump \n');
fprintf('Process (4-1) - Isentropic Heat Addition by the Boiler \n');
%input state variables at point1,
p1 = input('Enter the Pressure at the Turbine Inlet (in bar): -> \n');
T1 = input ('Enter the Temperature at the Turbine Inlet (in Degree C ): -> \n');
p2 = input('Enter the Pressure at the Turbine Outlet (in bar): -> \n');
%Calculating state variables at all points from given datafile.
%getting cp & cv values from 'XSteam' data file,
%for vapour
high_cpV=XSteam('CpV_p',p1);
low_cpV=XSteam('CpV_p',p2);
high_cvV=XSteam('CvV_p',p1);
low_cvV=XSteam('CvV_p',p2);
%for liquid
high_cpL=XSteam('CpL_p',p1);
low_cpL=XSteam('CpL_p',p2);
high_cvL=XSteam('CvL_p',p1);
low_cvL=XSteam('CvL_p',p2);
%getting important parameters from 'XSteam' data file.
%for high pressure,
T1s=XSteam('Tsat_p',p1);
s1g=XSteam('sV_p',p1);
s1f=XSteam('sL_p',p1);
s1fg=s1g-s1f;
h1f=XSteam('hL_p',p1);
h1g=XSteam('hV_p',p1);
h1fg=h1g - h1f;
%for low pressure,
T2s=XSteam('Tsat_p',p2);
s2g=XSteam('sV_p',p2);
s2f=XSteam('sL_p',p2);
s2fg=s2g-s2f;
h2f=XSteam('hL_p',p2);
h2g=XSteam('hV_p',p2);
h2fg=h2g-h2f;
%state variables at point1,---------------
fprintf('At State 1 :----------> \n');
fprintf('p1 is : %f bar \n',p1);
fprintf('T1 is : %f Degree C \n',T1);
h1 = XSteam('h_pT',p1,T1);
fprintf('h1 is : %f kJ/kg \n',h1);
s1 = XSteam('s_pT',p1,T1);
fprintf('s1 is : %f kJ/kgK \n',s1);
%state variables at point2,----------------
fprintf('At state 2 :----------> \n');
fprintf('p2 is : %f bar \n', p2);
%Entropy remains the same through Turbibe(ideal).
s2=s1;
fprintf('s2 is : %f kJ/kgK \n', s2);
%clculate value of 'x'(dryness fraction).
if (s2 <= s2g)
x2=(s2 - s2f) / (s2fg);
else
x2=1;
end
fprintf('x2 is : %f \n', x2);
%calculate value of 'T2',
if (x2 < 1)
T2=T2s;
else
T2=(T2s + 273.15)*exp((s2-s2g) / low_cpV);
T2=T2 - 273.15;
end
fprintf('T2 is : %f Degree C \n',T2)
% s2=sg_2+Cp2_V*(log(T2/Tsat_P2)) -formula dor calculate entropy (superheat region)
%for calculate value of h2,
if (x2 < 1)
h2=h2f + x2*h2fg;
else
h2=h2g+low_cpV*(T2-T2s);
end
fprintf('h2 is : %f kJ/kg \n',h2)
%state variables at point3,-----------------
fprintf('At state3 :----------> \n')
p3=p2;
fprintf('p3 is : %f bar \n', p3)
V3=XSteam('vL_p',p3);
T3=T2s;
fprintf('T3 is : %f Degree C \n',T3);
h3=h2f;
fprintf('h3 is : %f kJ/kg \n',h3)
s3=s2f;
fprintf('s3 is :%f kJ/kgK \n',s3)
%state variables at point4,-----------------
fprintf('At state4 :----------> \n')
p4=p1;
fprintf('p4 is : %f bar \n',p4)
s4=s3; % Isentropic pumping process.
fprintf('s4 is : %f kj/kgk \n',s4)
T4=XSteam('T_ps',p4,s4);
fprintf('T4 is : %f Degree C \n',T4)
W_p=V3*(p4-p3)*100;
h4=W_p + h3; %work done by pump(W_p = h4-h3).
fprintf('h4 is : %f kJ/kg \n',h4)
%calculations of Net Work output, Net heat, Back Work ratio and Thermal efficiency.
% Work Done by Turbine,
W_T=h1-h2;
fprintf('Work by Turbine is : %f kJ/kg \n',W_T)
fprintf('Work by Pump is : %f kJ/kg \n',W_p)
%Net Work Done,
Wnet=W_T - W_p;
fprintf('Net Work done is : %f kJ/kg \n',Wnet)
%Net Heat supplied,
Qin=h1-h4;
Qout=h2-h3;
%Thermal Efficiency
eff_thermal=Wnet/Qin;
fprintf('Thermal Efficiency is : %f \n',eff_thermal);
%Back Work Ratio
b_w_r=(W_p/W_T);
fprintf('Back work ratio is : %f \n',b_w_r)
%Work Ratio,
w_r=(Wnet/W_T);
fprintf('Work ratio is : %f \n',w_r)
%summation of b_w_r and w_r should be 1,
fprintf('Back work ratio + Work ratio is : %f \n',(b_w_r+w_r))
%Heat rate and specific steam consumption,
H_R=(1/eff_thermal);
fprintf('Heat Rate is : %f kJ/kWs \n',H_R)
ssc=(3600/W_T);
fprintf('Specific steam consumption is : %f kg/kWh \n',ssc)
%Iterating saturation liquid and vapour lines from 0 to value of T1 for plot property diagram of water.
temperature=linspace(0,T1,5000);
for i= 1 : length(temperature)
h_L(i) = XSteam('hL_T',temperature(i));
h_V(i) = XSteam('hV_T',temperature(i));
s_L(i) = XSteam('sL_T',temperature(i));
s_V(i) = XSteam('sV_T',temperature(i));
end
% Plotting of saturated curve for T-s diagram
plot(s_L,temperature,'red','LineStyle','--','LineWidth',1)
hold on
plot(s_V,temperature,'blue','LineStyle','--','LineWidth',1)
%plot T-s Diagram,
figure(1)
hold on
plot([s1 s2],[T1 T2],'Color','yellow','LineWidth',4)
plot([s2 s2g],[T2 T2s],'Color','green','LineWidth',4)
plot ([s2g s3],[T2s T3],'Color','green','LineWidth',4)
plot([s3 s4],[T3 T4],'Color','yellow','LineWidth',4)
plot([s4 s1f],[T4 T1s],'Color','yellow','LineWidth',4)
plot([s1f s1g],[T1s T1s],'Color','green','LineWidth',4)
plot([s1g s1],[T1s T1],'Color','green','LineWidth',4)
legend('Saturated liquid curve','Saturated vapour curve')
text (s1,T1,' 1' ,'FontSize',15)
text (s2,T2,' 2' ,'FontSize',15)
text (s2g,T2s,' 2s','FontSize',15)
text (s3,T3,' 3','FontSize',15)
text (s4,T4,' 4','FontSize',15)
text(s1f,T1s,' 4s','FontSize',15)
text(s1g,T1s,' 1s','FontSize',15)
%making directions,
text(s1,(T1+T2)/2,'\vee','Color','yellow')
text((s2g+s2f)/2,T3,'\angle','Color','yellow')
text(s3,(T3+T4)/2,'\wedge','Color','yellow')
text((s1f+s1g)/2,T1s,'\angle','Color','yellow')
axis([0 10 0 500])
title('T-s Diagram of Ideal Rankine Cycle')
xlabel('Specific Entropy (kJ/kgK)')
ylabel('Temperature (degree C)')
grid on
%plot h-s Diagram,
figure(2)
plot(s_L,h_L,'Color','black','LineStyle','--','LineWidth',1)
hold on
plot(s_V,h_V,'Color','red','LineStyle','--','LineWidth',1)
plot([s1 s2],[h1 h2],'Color','yellow','LineWidth',4)
plot([s2 s3],[h2 h3],'Color','green','LineWidth',4)
plot([s3 s4],[h3 h4],'Color','yellow','LineWidth',4)
plot([s4 s1],[h4 h1],'Color','green','LineWidth',4)
text(s1,h1,' 1','FontSize',15)
text(s2,h2,' 2','FontSize',15)
text(s3,h3,' 3','FontSize',15)
text(s4,h4,' 4','FontSize',15)
title('h-s Diagram of Ideal Rankine Cycle')
xlabel('Specific Entropy (kJ/kgK)')
ylabel('Specific Enthalpy (kJ/kg)')
legend('Saturated liquid curve','Saturated vapour curve')
grid on
OUTPUTs:
COMMAND WINDOW’s OUTPUT RESULTs:
- To run the program first user have to put inputs values, inlet pressure(p1), turbine inlet temperature(T1), outlet pressure(p2), and accordingly all the results will be calculated.
Here we put, p1 = 30 bar.
T1 = 400 degree C.
p2 = 0.05 bar.
- The output obtained in command window:-


Assign Inputs:-
Turbine Inlet temperature = 400° C
Turbine Inlet Pressure = 30 bars
Turbine Outlet Pressure = 0.05 bars = Condenser Inlet Pressure
Calculated the followings,
- Net work output = 1117.851878 kJ/kg.
- Back work ratio = 0.002686
FIGURE 1/ T-s plot of Rankine Cycle.

FIGURE 2/ h-s plot of Rankine Cycle.

CONCLUSIONs:
In this program, reheat and regenerative cycles of Rankine cycle can be simulated.
From it we get the values of all state points, & program also generate all it's simulation equations behalf of my primary input values. Also we get T-s & h-s plots of Rankine cycle.
REFERENCEs: