%general calculations
%step 1
% clearing workspace,command window & closing all plots
clear my fun;
close all;
clc;
% step 2
% print discriptipon of all process
fprintf('RANKINE CYCLES SIMULATOR \n')
fprintf('\n 1-2 is isentropic expansion in the turbine \n')
fprintf('2-3 is constant presure heat rejection by the condenser \n')
fprintf('3-4 is isentropic compresion in pump \n')
fprintf('4-1 is constant presure heat addition bye the boiler \n')
% user inputs
P1=input('\n 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 presure at the turbine outlet(in bar): ');
% state point 1
% enthalpy
H1 = XSteam('h_pt',P1,T1);
% entropy
S1=XSteam('s_pt',P1,T1);
% enthalpy of saturated liquid
Hf1=XSteam('hL_p',P1);
% enthalpy of saturated vapour
Hg1=XSteam('hV_p',P1);
% saturation temprature
Ts1=XSteam('Tsat_p',P1);
% entropy of saturated liquid
Sf1=XSteam('sL_p',P1);
% entropy of saturated vapour
Sg1=XSteam('sV_p',P1);
%state point 2
S2=S1;
Sf2=XSteam('sL_P',P2);
Sg2=XSteam('sV_p',P2);
% dryness fraction
X=(S2-Sf2)/(Sg2-Sf2);
Hf2=XSteam('hL_p',P2);
Hg2=XSteam('hV_p',P2);
H2=Hf2+X*(Hg2-Hf2);
T2=XSteam('T_ph',P2,H2);
Ts2=XSteam('Tsat_p',P2);
% state point 3
H3=Hf2;
S3=Sf2;
T3=T2;
P3=P2;
% state point 4
P4=P1;
S4=S3;
H4=XSteam('h_ps',P4,S4);
T4=XSteam('T_ps',P4,S4);
%temperature for ploting saturated curves
t=linspace(0,374,500);
% ploting T-s diagram
figure(1)
hold on
% for ploting saturation curve
for i=1:length(t)
plot(XSteam('sL_T',t(i)),t(i),'+','color','b');
plot(XSteam('sV_T',t(i)),t(i),'+','color','b');
end
% for plot cycle
plot([S1 S2],[T1 T2],'LineWidth',2,'Color','r');
if X>1
T3=Ts2;
plot([S2 Sg2 S3 S4],[T2 Ts2 T3 T4],'LineWidth',2,'Color','r');
T2=Ts2;
else
plot([S2 S3 S4],[T2 T3 T4],'LineWidth',2,'Color','b');
end
l=linspace(T1,T2,1000);
for i=1:length(l)
plot(XSteam('S_pT',P1,l(i)),l(i),'+','Color','r');
end
plot([Sf1 Sg1],[Ts1 Ts1],'LineWidth',2,'Color','r');
xlabel('Entropy in[kj/kg-k]')
ylabel('Temprature in[k]')
title('T-S Diagram')
% for ploting H-S Diagram
for j=1:length(t)
plot(XSteam('sL_T',t(j)),XSteam('hL_T',t(j)),'.','Color','r');
plot(XSteam('sV_T',t(j)),XSteam('hV_T',t(j)),'.','Color','b');
end
% plot cycle
plot([S1 S2 S3 S4 S1],[H1 H2 H3 H4 H1],'LineWidth',2,'Color','r');
xlabel('Entropy in [kj/kg-k] ')
ylabel('Enthalpy in [kj/kg] &Temperature[K]')
title(' H-S and T-S Diagram ')
% for calculation
% Turbine work
Wt=H1-H2;
% Pump work
Wp=H4-H3;
% Heat addition
Qin=H1-H4;
% Heat rejection
Qout=H2-H3;
% Net work
Wnet=Wt-Wp;
% efficiency
Ntherm=(Wnet/Qin)*100;
%Specific steam consumption
SSC=3600/Wnet;
% back work ratio
BWR=Wp/Wt;
% for printing results
fprintf('\n\nresults\n')
fprintf('At state point 1:\n')
fprintf('P1 is :%.2f bar\n',P1)
fprintf('T1 is :%.2f deg celcius\n',T1)
fprintf('H1 is :%.2f kj/kg\n',H1)
fprintf('S1 is :%.2f kj/kg-k\n',S1)
fprintf('\nAt state point 2:\n')
fprintf('P2 is :%.2f bar\n',P2)
fprintf('T2 is :%.2f deg celcius\n',T2)
fprintf('H2 is :%.2f kj/kg\n',H2)
fprintf('S2 is :%.2f kj/kg-k\n',S2)
fprintf('\nAt state point 3:\n')
fprintf('P3 is :%.2f bar\n',P3)
fprintf('T3 is :%.2f deg celcius\n',T3)
fprintf('H3 is :%.2f kj/kg\n',H3)
fprintf('S3 is :%.2f kj/kg-k\n',S3)
fprintf('\nAt state point 4:\n')
fprintf('P4 is :%.2f bar\n',P4)
fprintf('T4 is :%.2f deg celcius\n',T4)
fprintf('H4 is :%.2f kj/kg\n',H4)
fprintf('S4 is :%.2f kj/kg-k\n',S4)
fprintf('\nWt turbinr work is :%.2f kj/kg\n',Wt)
fprintf('Wp pump work is :%.2f kj/kg\n',Wp)
fprintf('Wnet net work is :%.2f kj/kg\n',Wnet)
fprintf('Thermal efficiency is :%.2f percent\n',Ntherm)
fprintf('S.S.C specific heat consumption is :%.2f kg/kWh\n',SSC)
fprintf(' Back work ratio is : %.3f \n',BWR)