Challenge

Project 2 - Rankine cycle Simulator

% Program For Rankine Cycle Simulator

clear all
close all
clc


fprintf('   Rankine Cycle Simulator    \n')
fprintf('Process 1-2    Isentropic Expansion In Turbine \n')
fprintf('Process 2-3    Isobaric Heat Rejection In Condenser \n')
fprintf('Process 3-4    Isentropic Compression In Pump \n')
fprintf('Process 4-1    Isobaric Heat Addition In Boiler \n')


% Inputs
fprintf('\n')
fprintf('   Inputs   \n')
r = 1; % Gamma Value for Water, Since Working Fluid of a Rankine Cycle is Water
P1 = input('Enter the Pressure at Turbine Inlet (in bar): ');
T1 = input('Enter the Temperature at the Turbine Inlet (in degree celcius): ');
P2 = input('Enter the Pressure at the Condenser Inlet (in bar) ');

% Collecting Data from Xsteam and calculating enthalpy and entropy

% At State Point 1
H1 = XSteam('h_pT',P1,T1);  % Enthalpy from Xsteam which corresponds to P1 and T1
S1 = XSteam('s_pT',P1,T1);  % Entrpy from Xsteam which corresponds to P1 and T1

% At State Point 2
S2 = S1; % Since its an Isentropic process
Sf2 = XSteam('sL_p',P2);
Sg2 = XSteam('sV_p',P2);
Hf2 = XSteam('hL_p',P2);
Hg2 = XSteam('hV_p',P2);
X2 = ((S2 - Sf2)/(Sg2 - Sf2)); % Dryness Fraction
H2 = Hf2 + (X2*(Hg2 - Hf2));
T2 = XSteam('T_hs',H2,S2);
% Turbine Work (Wt) = H1 - H2
Wt = H1 - H2;

% At State Point 3
T3 = T2;
P3 = P2; % Isobaric Process
H3 = XSteam('hL_T',T3); % Since working fluid is now in Liquid Phase
S3 = XSteam('sL_T',T3); % Since working fluid is now in Liquid Phase
V3 = XSteam('vL_T',T3); % Specific volume corresponds to T3

% At State Point 4
S4 = S3; % Isentropic Process
P4 = P1; % Process 4-1 is an Isentropic Process
% For isentropic process T3/T4 = (P3/P4)^(1-1/r)
T4 = T3/((P3/P4)^(1-1/r));
% Pump Work Wp = H4 - H3 & Wp = V3*(P1-P2)*10^2
Wp = V3*(P1-P2)*10^2;
H4 = Wp + H3; % Since Wp = H4 - H3

% Net Work (W_net = Wt-Wp)
W_net = Wt-Wp;

% Back Work Ratio = Wp/Wt (Pump Work/Turbine Work)
B_W_R = (Wp/Wt)*100;

% At State Points 5 (Liquid Phase)
T5 = XSteam('Tsat_p',P1);
H5 = XSteam('hL_P',P1);
S5 = XSteam('sL_P',P1);

% At State Points 6 (Vapour Phase)
T6 = T5;
H6 = XSteam('hV_P',P1);
S6 = XSteam('sV_P',P1);

% Plotting

% Points For Saturation Curve
T = linspace(1,T1,50);

for i = 1:length(T)
Sv(i) = XSteam('sV_T',T(i));
Hv(i) = XSteam('hV_T',T(i));
Sl(i) = XSteam('sL_T',T(i));
Hl(i) = XSteam('hL_T',T(i));
end

% Plotting The T-S Diagram
figure(1)
plot([S1 S2],[T1 T2],[S2 S3],[T2 T3],[S3 S4],[T3 T4],[S4 S5],[T4 T5],[S5 S6],[T5 T6],[S6 S1],[T6 T1],'LineWidth',2,'Color','k')
hold on
plot(Sv,T,'LineWidth',1.5,'Color','r')
plot(Sl,T,'LineWidth',1.5,'Color','r')
text(S1+0.1,T1,'1','FontSize',10)
text(S2+0.1,T2,'2','FontSize',10)
text(S3,T3-10,'3','FontSize',10)
text(S4-0.1,T4+10,'4','FontSize',10)
text(S5,T5+10,'5','FontSize',10)
text(S6+0.1,T6,'6','FontSize',10)
xlabel('Entropy (KJ/Kg-K')
ylabel('Temperature (K)')
title('T-S Diagram of Rankine Cycle')

% Plotting The H-S Diagram
figure(2)
plot([S1 S2],[H1 H2],[S2 S3],[H2 H3],[S3 S4],[H3 H4],[S4 S1],[H4 H1],'LineWidth',2,'Color','k')
hold on
plot(Sv,Hv,'LineWidth',1.5,'Color','r')
plot(Sl,Hl,'LineWidth',1.5,'Color','r')
text(S1+0.08,H1,'1','FontSize',10)
text(S2+0.08,H2,'2','FontSize',10)
text(S3,H3-50,'3','FontSize',10)
text(S4,H4+120,'4','FontSize',10)
xlabel('Entropy (KJ/Kg-K)')
ylabel('Enthalpy (KJ/Kg)')
title('H-S Diagram of Rankine Cycle')

% Displaying Results in Command Window
fprintf('\n')
fprintf('   Results   \n')

% State Point 1
fprintf('At State Point 1: \n')
fprintf('P1 is : %4.2f Bar \n',P1)
fprintf('T1 is : %4.2f Deg Celcius \n',T1)
fprintf('H1 is : %4.2f KJ/Kg \n',H1)
fprintf('S1 is : %4.2f KJ/KgK \n',S1)
fprintf('\n')

% State Point 2
fprintf('At State Point 2: \n')
fprintf('P2 is : %4.2f Bar \n',P2)
fprintf('T2 is : %4.2f Deg Celcius \n',T2)
fprintf('H2 is : %4.2f KJ/Kg \n',H2)
fprintf('S2 is : %4.2f KJ/KgK \n',S2)
fprintf('\n')

% State Point 3
fprintf('At State Point 3: \n')
fprintf('P3 is : %4.2f Bar \n',P3)
fprintf('T3 is : %4.2f Deg Celcius \n',T3)
fprintf('H3 is : %4.2f KJ/Kg \n',H3)
fprintf('S3 is : %4.2f KJ/KgK \n',S3)
fprintf('\n')

% State Point 4
fprintf('At State Point 4 : \n')
fprintf('P4 is : %4.2f Bar \n',P4)
fprintf('T4 is : %4.2f Deg Celcius \n',T4)
fprintf('H4 is : %4.2f KJ/Kg \n',H4)
fprintf('S4 is : %4.2f KJ/KgK \n',S4)
fprintf('\n')

fprintf('Turbine Work (Wt) is : %4.2f KJ/Kg \n',Wt)
fprintf('Pump Work (Wp) is : %4.2f KJ/Kg \n',Wp)
fprintf('Net Work Done (Wnet) is : %4.2f KJ/Kg \n',W_net)
fprintf('Back Work Ratio is : %4.2f \n',B_W_R)
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.