Project 2 - Rankine cycle Simulator
Aim:
Creation of Rankine cycle simulator from given input and reading the data from standard thermodynamic library of steam table.
Objective:
- To create a Rankine Cycle simulator in MATLAB.
- To calculate the state point using function XSteam.
- To plot the T-S and H-S curve for given input in Rankine Cycle.
- To get output in the command window for each state point in cycle.
Introduction ;
Rankine Cycle :
- Rankine cycle is an idealized thermodynamic cycle or heat engine in which a fuel is used to produce heat within a boiler , converting water into steam which then expands through a turbine producing useful wok . This process was developed in 1859 by scottish engineer william J.m Rankine . It is a cycle which converts heat into mechanical energy which usually is converted into electrical energy .
- In this project an idealized cycle is simulated . Hence neglecting losses.
- Rankine cycle is derived out of carnot cycle. its power depends on the temperature difference between the heat source and a cold source. The more the difference the more mechanical power can be efficiently extracted out of heat energy .
- Since ideal cycles are only in theory , Efficiency of rankine cycle is limited by high heat of vaporization of the working fluid , friction losses etc.
- Water is usually the fluid of choice due to its favorable properties, such as its non-toxic and unreactive chemistry, abundance, and low cost, as well as its thermodynamic properties. By condensing the working steam vapor to a liquid the pressure at the turbine outlet is lowered and the energy required by the feed pump consumes only 1% to 3% of the turbine output power and these factors contribute to a higher efficiency for the cycle. The benefit of this is offset by the low temperatures of steam admitted to the turbine
Processes and Working :
There are four processes in the rankine cycle (order maybe varied ) :
- Process 1-2 : Isentropic Expansion in the turbine .
- Process 2-3 : Constant pressure Heat rejection in condenser
- Process 3-4 : Isentropic compression in the pump
- Process 4-1 : Constant pressure heat addition in the boiler

The Rankine cycle is one of the vapor powered cycle. This cycle is somewhat different than gas powered cycle in which working fluid remained gas throughout the entire cycle. In vapor powered cycle the working fluid is steam because of its many desirable characteristics such as low cost of production, availability and high enthalpy of vaporization. There are many impracticalities associated with Carnot cycle which can be eliminated by superheating the steam and condense in condenser which makes it best for nuclear power plants and other steam related power generation sources.
Formula

Main Code ;
% Objective of this program is to simulate the rankine cycle
% Plotting t-s and h-s diagram using data from XSteam data
% Water and steam properties according to IAPWS IF-97
close all
clc
%%
disp('RANKINE CYCLE');
% Displaying
disp('1-2 is Isentropic Expansion in the turbine');
disp('2-3 is constant pressure heat removal in the condenser');
disp('3-4 is Isentropic compression in the pump');
disp('4-1 is Constant pressure heat addition in the boiler');
%%
%Obtaining the input data
p1 = input('\nValue of pressure at turbine inlet, pl(in bar) = ');
T1 = input('\nValue of temperature at turbine inlet, T1(in degree.C) = ');
p2 = input('\nValue of temperature at condenser inlet, p2(in bar) = ');
%%
% Extracting data defining variables
% State 1
% extracting enthalpy at state pt 1
h1 =XSteam('h_pT', p1, T1);
% similarly
s1 = XSteam('s_pT', p1, T1);
% State 2
s2 = s1; % Isentropic expansion
sf2= XSteam('sL_p', p2); % Saturated liquid Entropy
sg2= XSteam('sV_p', p2); % Saturated Vapour Entropy
x2 = (s2-sf2)/(sg2-sf2);
hf2 = XSteam('hL_p', p2);
hg2= XSteam('hV_p', p2);
h2 = hf2 + (x2*(hg2-hf2));
% State 3
p3 = p2;
s3= XSteam('sL_p', p3);
h3 = XSteam ('hL_p', p3);
% State 4
S4 = s3;
p4 = p1;
%%
% Work done by turbine
Wt=h1-h2;
% Work done to run pump
v3 = XSteam ('vL_p', p3);
Wp = v3*(p4 - p3)*100;
h4=h3+ Wp;
%net work
Wnet= Wt-Wp;
%Heat into the system
Qin= h1-h4;
%Heat out of the system
Qout=h2-h3;
%Thermal efficiency
eff = (Wnet/Qin)*100;
%Specific Steam Consumption
%SSC mass flow rate/power
SSC (3600/Wnet);
%%
%calculating temperatures at the 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));
%calculating temperature, entropy and enthalpy at the vapour and liquid
%line for plotting
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;
%%
%Plotting the saturation curve
T = linspace (1,375, 1000);
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],'k', 'linewidth', 2)
plot([s2 s3], [T2 T3],'k', 'linewidth', 2)
plot([s3 s4], [T3 T4],'k', 'linewidth', 2)
plot([s4 s5], [T4 T5],'k', 'linewidth', 2)
sc1 = linspace (s6, s1, 1000);
for l = 1:length(sc1)
Tc1(1)= XSteam ('T_ps',p1,sc1(1));
end
plot(sc1, Tc1, '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('Temp vs Entropy plot')
xlabel('Entropy,S (Kj/kgk')
ylabel('Temperature (degree C) ')
legend('Saturation curve')
%%
%Plotting h-s diagram
figure(2)
hold on
plot(sf, hf, 'r', 'linewidth', 1)
plot(sg, hg, 'r', 'linewidth', 1)
plot([s1 s2], [h1 h2], 'k', 'linewidth', 2)
plot([s2 s3], [h2 h3], 'k', 'linewidth', 2)
plot([s3 s4], [h3 h4], 'k', 'linewidth', 2)
hc=linspace (h4,h5,100);
for k = 1:length(hc)
sch(k) = XSteam('s_ph', pl,hc(k));
end
plot(sch, hc, 'k', 'linewidth', 2)
plot([s5 s6], [h5 h6], 'k', 'linewidth', 2)
for m = 1:length(sc1)
hc1(m)=XSteam('h_ps', pl, sc1(m));
end
plot(scl, 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 plot')
xlabel('Entropy, S (KJ/kgk)')
ylabel('Enthalpy, H (KJ/kg)')
legend('saturation curve','location','northwest')
%%
% Displaying Results
disp(' RESULTS');
fprintf('At State Point 1:\n');
fprintf('p1: %8.3f bar\n', p1);
fprintf('T1: %8.3f C\n', T1);
fprintf('h1: %8.3f KJ/kg\n', h1);
fprintf('s1: %8.3f KJ/kgK\n\n', s1);
fprintf('At State Point 2:\n');
fprintf('p2: %8.3f bar\n', p2);
fprintf('T2: %8.3f C\n', T2);
fprintf('h2: %8.3f kJ/kg\n', h2);
fprintf('s2: %8.3f kJ/kgK\n', s2);
fprintf('x2: %8.3f\n\n', x2);
fprintf('At State Point 3:\n');
fprintf('p3: %8.3f bar\n', p3);
fprintf('T3: %8.3f K\n', T3);
fprintf('h3: %8.3f kJ/kg\n', h3);
fprintf('s3: %8.3f kJ/kgK\n\n', s3);
fprintf('At State Point 4:\n');
fprintf('p4: %8.3f bar\n', p4);
fprintf('T4: %8.3f K\n', T4);
fprintf('h4: %8.3f KJ/kg\n', h4);
fprintf('s4: %8.3f kJ/kgK\n\n', s4);
fprintf('Turbine Work: %8.3f kJ/kg\n', Wt);
fprintf('Pump Work: %8.3f kJ/kg\n', Wp);
fprintf('Wnet: %8.3f kJ/kg\n', Wnet);
fprintf('Efficiency: %8.3f Percent \n ', eff);
fprintf('S.S.C: %8.3f kJ/kWh', SSC);
Output :
T-S Diagram

H-S Diagram

Code Explanation:
- The creation of Rankine cycle simulator starts with some input value which are required to calculate the other state point in cycle eventually.
- The Rankine cycle process is displayed in the command window and then inputs are entered which are inlet pressure for turbine, temperature at turbine inlet and pressure at condenser.
- Then we are using XSteam function file for reading state point. First, we get the value of enthalpy and entropy at state point 1 from the XSteam function file.
- As process from 1-2 is isentropic compression the entropy at point 1 is equal to point 2. The term ‘(s_pT, p1, T1)’ refers to entropy at pressure and temperature point 1.
- The term ‘sg’ and ‘sf’ are referred to saturated liquid and saturated vapor entropy respectively. This value is used to calculate other function according to mathematical relations.
- Similarly, other points are taken from XSteam function file which are necessary to calculate other parameters. After that work done in turbine and pump are calculated for further getting the net work done Rankine cycle.
- After calculating the net work done the efficiency of the Rankine cycle is calculated along with specific steam consumption which is steam consumed by a locomotive cylinders per unit of output of work done.
- Then temperature at each point of cycle is calculated using input taken from start of the program and data taken from XSteam file. For given temperature range from lower to higher entropy points are calculated to create the T-S plot. Similarly, another for loop is used to create the saturation curve in each plot.
- Then plotting is done respectively for T-s and H-s graph in Rankine cycle and each state point value has been put in command window.
Errors:
Multiple errors were encountered during the coding process and mainly was occured due to invalid syntaxes or other function calling statments.
Conclusion:
So, we have created the Rankine cycle simulator for the given input, in which we have taken the data from XSteam function file.