Challenge

Project 2 - Rankine cycle Simulator

%% 
clear all
close all
clc

%%
fprintf('         RANKINE CYCLE SIMULATOR \n\n         ');
fprintf('\n A brief introduction about rankine cycle \n\n')
fprintf('It is one of the vapour cycle based on which the power plants like coal, diesel or nuclear powerplants works.\n')
fprintf('In this cycle a fuel source (coal or diesel or nuclear fuel) is burnt to produce heat. \n')
fprintf(' This heat is supplied to a coil of tubes carrying water, where it converted into a super heated steam.\n')
fprintf('This super heated steam is directed on a turbine which is coupled to a generator, which produces electricity.\n')
fprintf('These process takes place in four steps which are mentioned below.\n\n')
fprintf('1-2 is Isentropic Expansion in the Turbine \n\n');
fprintf('2-3 is Constant Pressure Heat Rejection by the Condenser \n\n');
fprintf('3-4 is Isentropic Compression in the Pump \n\n');
fprintf('4-1 is Constant Pressure Heat Addition by the Boiler \n\n');

%% Getting inputs from user
P1 = input('Enter the Pressure at the Turbine Inlet(in bar):');
fprintf('\n')
T1 = input('Enter the Temperature at the Turbine Inlet(in Degree Celcius):');
fprintf('\n')
P2 = input('Enter the Pressure at the Condenser (in bar):');
fprintf('\n')

% Calculating Pressure,Temperature,Enthalpy & Entropy at each state points

%% At state point 1
H1 = XSteam('h_pT',P1,T1);    % Xsteam is inbuilt function which includes its own steam table values, pressure values from 0-200 bar and temperature values from 0-2000 deg celcius
S1 = XSteam('s_pT',P1,T1);    % Entropy with respect to pressure & temperature
H_L1 = XSteam('hL_p',P1);     % Enthalpy of liquid at stage 1 with respect to pressure at stage 1
H_G1 = XSteam('hV_p',P1);     % Enthalpy of vapour at stage 1 with respect to pressure at stage 1
S_L1 = XSteam('sL_p',P1);     % Entropy of liquid at stage 1 with respect to pressure at stage 1
S_G1 = XSteam('sV_p',P1);     % Entropy of vapour with respect to pressure at stage 1 
T_sat1 = XSteam('Tsat_p',P1); % Saturation temperature with respect to pressure at stage 1

%% All the parameters such as Temperature, Entropy & Enthalpy of water and steam at stage are calculated with the help of Xsteam library
S2 = S1;
S_L2 = XSteam('sL_p',P2);
S_G2 = XSteam('sV_p',P2);
D = (S2-S_L2)/(S_G2-S_L2); %Calculating the dryness fraction
H_L2 = XSteam('hL_p',P2);
H_G2 = XSteam('hV_p',P2);
H2 = H_L2 + D*(H_G2 - H_L2);  %Calculating the enthalpy at point 2
T2 = XSteam('T_ph',P2,H2);
T_sat2 = XSteam('Tsat_p',P2);

%% At stage 3
P3 = P2;  
T3 = T2;
H3 = H_L2;
S3 = S_L2;

%% At state point 4
P4 = P1;
S4 = S3;
T4 = XSteam('T_ps',P4,S4); % Temperature as a function of pressure & entropy
H4 = XSteam('H_ps',P4,S4); % Enthalpy as a functionof pressure & entropy

%% Calculating Work and Efficiency of the Rankine Cycle

% Turbine Work
W_T = H1 - H2;

%Pump Work
W_P = H4 - H3;

%Net Work
W_NET = W_T - W_P;

%Thermal Efficiency of the Rankine Cycle
EFF = (W_NET/(H1 - H4))*100 ;

%Back Work Ratio
BWR = W_P/W_T;

%Specific Steam Conductivity
SSC = 3600/W_T;

%% Displaying the results
% Values of state point 1
fprintf('                    RESULTS \n\n                ');
fprintf('At State point 1 \n')
fprintf('P1 = %.2f Bar \t\n',P1); % %.2f Indicates the no. of digits to be printed after the decimal points,which means after dot 2 digits will be printed
fprintf('T1 = %.2f Deg Celcius \t\n',T1);
fprintf('H1 = %.2f KJ/kg \t\n',H1);
fprintf('S1 = %.2f KJ/kgK \t\n',S1);
fprintf('\n');

%% Values of state point 2
fprintf('\t\t\t At State point 2 \n');
fprintf('P2 = %.2f Bar \t\n',P2);
fprintf('T2 = %.2f Deg Celcius \t\n',T2);
fprintf('H2 = %.2f KJ/kg \t\n',H2);
fprintf('S2 = %.2f KJ/kgK \t\n\n',S2);

%% Values of state point 3
fprintf('\t\t\t At State point 3 \n');
fprintf('P3 = %.2f Bar \t\n',P3);
fprintf('T3 = %.2f Deg Celcius \t\n',T3);
fprintf('H3 = %.2f KJ/kg \t\n',H3);
fprintf('S3 = %.2f KJ/kgK \t\n\n',S3);

%% Values of state point 4
fprintf('\t\t\t At State point 4 \n');
fprintf('P4 = %.2f Bar \t\n',P4);
fprintf('T4 = %.2f Deg Celcius \t\n',T4);
fprintf('H4 = %.2f KJ/kg \t\n',H4);
fprintf('S4 = %.2f KJ/kgK \t\n\n',S4);

%% Turbine Work
fprintf('Turbine work = %.2f KJ/kg \n\n',W_T);

%% Pump Work
fprintf('Pump work = %.2f KJ/kg \n\n',W_P);

%% Net Work
fprintf('Net work done = %.2f KJ/kg \n\n',W_NET);

%% Thermal Efficiency
fprintf('Thermal efficiency = %.2f Percent \n\n',EFF);

%% Specific Steam Conductivity
fprintf('Specific steam conducvity = %.2f kg/KWh \n\n',SSC);

%% Back Work ratio
fprintf('Back Work Ratio = %f \n\n',BWR);

%% plotting of T-S curve

t = linspace(0,373.5,200);
figure(1)
hold on

for i = 1:length(t)
plot(XSteam('sL_T',t(i)),t(i),'g.')
plot(XSteam('sV_T',t(i)),t(i),'g.')
end

plot([S1 S2],[T1 T2],'linewidth',2,'color','blue')
grid on
text(S1,T1,'1','FontSize',10)
if D>1
T3 = T_sat2;
plot([S2 S_G2 S3 S4],[T2 T_sat2 T3 T4],'linewidth',2,'color','blue')
T2 = T_sat2;
text(S2,T2,'2','FontSize',10)
text(S3,T3,'3','FontSize',10)
else
plot([S2 S3 S4],[T2 T3 T4],'linewidth',2,'color','blue')
text(S2,T2,'2','FontSize',10)
text(S3,T3,'3','FontSize',10)
end

n = linspace(T1,T2,500);
for i = 1:length(n)
plot(XSteam('s_pT',P1,n(i)),n(i),'.','linewidth',2,'color','blue')
end

plot([S_L1 S_G1],[T_sat1 T_sat1],'linewidth',2,'color','blue')
text(S_L1,T_sat1,'4','FontSize',10)
xlabel('Entropy(kJ/kg-K)')
ylabel('Temperature(k)')
title('T-S Graph')


%% Plotting of H-S Curve

figure(2) 
hold on
for i = 1:length(t)
 plot(XSteam('sL_T',t(i)),XSteam('hL_T',t(i)),'g.')
 plot(XSteam('sV_T',t(i)),XSteam('hV_T',t(i)),'g.')
 grid on
end
plot([S1 S2 S3 S4 S1],[H1 H2 H3 H4 H1],'linewidth',2,'color','blue')
text(S1,H1,'1','FontSize',10)
text(S2,H2,'2','FontSize',10)
text(S3,H3,'3','FontSize',10)
text(S4,H4,'4','FontSize',10)
xlabel('Entropy(kJ/kg-K)')
ylabel('Enthalpy(kJ/kg)')
title('H-S Graph')

ERROR MESSAGES

Reason for error

H_G1 = XSteam('hV_p'P1); % Enthalpy of vapour at stage 1 with respect to pressure at stage 1 - In this script line the delimiter 'comma' found missing, which throwed the above shown error
Reason for error - Tried to run the script without saving it
Reason for error - The properties for plot function was not declared properly. The error was cleared by changing the script line to " plot(Xsteam('sV_T',t(i)),Xsteam('hV_T',t(i)),'color','g.')
SOURCES OF REFERENCE

CODE EXPLANATION

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.