Project 2 - Rankine cycle Simulator
CODE:
% Rankine Cycle Code:
close all
clear all
clc
% Displaying the Four Processes in Rankine Cycle
fprintf('1-2 Isobaric heat Transfer\n')
fprintf('2-3 Isentropic Expansion\n')
fprintf('3-4 Isobaric heat Rejection\n')
fprintf('4-1 Isentropic Compression\n')
% The Code is divided into various Steps for easy Explanation
% Step 1
% Providing the Inputs
p1=input ('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 Pressure at the Condensor (in bar): ');
% Step 2
% Calculation of the 4 State Point Values by applying the data obtained from Xstam and basic Laws Including
% p2v2^gamma=p1v1^gamma and p1v1/t1=p2v2/t2
% state point1
h1=XSteam('h_pt',p1,t1);
s1=XSteam('s_pt',p1,t1);
% Values obtained from XSteam.m file
% state point2
s2=s1;
sf2=XSteam('sL_p',p2);
sg2=XSteam('sv_p',p2);
hf2=XSteam('hL_p',p2);
hg2=XSteam('hv_p',p2);
s2=sg2;
h2=hg2;
t2=XSteam('T_hs',h2, s2);
% state point3
t3=t2;
p3= p2;
s3=XSteam('sL_T',t3);
h3=XSteam('hL_T',t3);
v3=XSteam('vL_p',p2);
% state point4
p4 =p1;
s4= s3;
Cp4=XSteam('Cp_ps',p4,s4);
Cv4=XSteam('Cv_ps',p4, s4);
gamma=Cp4/Cv4;
r=(gamma-1)/gamma;
t4=t3 *(p4/p3)^r;
% state point 5 & 6
t5=XSteam('Tsat_p',p1);
t6=t5;
s5=XSteam('sL_p',p1);
s6=XSteam('sV_p',p1);
h5=XSteam('hL_p',p1);
h6=XSteam('hv_p',p1);
% Step 3
% Calculation of other output values.
%Turbine Work
wt=h1-h2;
%Pump Work
wp=v3* (p1-p2)*100;
h4=wp+h3;
%Net Work unit in kj/kg
w_net=wt-wp;
%heat suppied
Qs=h1-h4;
%Efficiency
Eff=(w_net/Qs)*100;
%steam rate per second
steam_rate=3600/ (wt-wp);
% Step 4
% Displaying The Obtained state Point Values.
printf("\n State Point Values \n");
printf('At State point 1:\n P1 is:%4.2f Bar\n T1 is:%4.2f Degree Celcius\n H1 is:%4.2f kJ/kg\n S1 is:%4.2f kJ/kgk\n\n',p1,t1, h1, s1)
printf('At State point 2:\n P2 is:%4.2f Bar\n T2 is:%4.2f Degree Celcius\n H2 is:%4.2f kJ/kg\n S2 is:%4.2f kJ/kgk\n\n',p2,t2, h2, s2)
printf('At State point 3:\n P3 is:%4.2f Bar\n T3 is:%4.2f Degree Celcius\n H3 is:%4.2f kJ/kg\n S3 is:%4.2f kJ/kgk\n\n',p3,t3, h3, s3)
printf('At State point 4:\n P4 is:%4.2f Bar\n T4 is:%4.2f Degree Celcius\n H4 is:%4.2f kJ/kg\n S4 is:%4.2f kJ/kgk\n\n',p4,t4, h4, s4)
printf('\n Pump work is :%4.2f kJ/kg\n Turbine Work is :$4.2f kJ/kg\n Net Work is :%4.2f kJ/kg\n Efficiency is :%4.2f percent\n Steam rate :%4.2f Kg/KWh ',wp, wt, w_net, Eff, steam_rate)
% Step 5
% Plotting the T-S Diagram
subplot(1,2,1)
T_rankine=linspace(t5,t1,5000);
% Determining Corresponding values for S with respect to t from xstream data
for i=1:length(T_rankine)
s_rankine (i)=XSteam('s_pT',p1,T_rankine(i));
end
plot ([s1 s2 s3 s4 s5 s6 s_rankine], [t1 t2 t3 t4 t5 t6 T_rankine], 'linewidth',1.5);
hold on
T_curve=linspace(1,400, 500);
for i=1:length(T_curve)
s_l(i)=XSteam('sL_T',T_curve(i));
s_v(i)=XSteam('sV_T',T_curve(i));
h_l(i)=XSteam('hL_T',T_curve(i));
h_v(i)=XSteam('hv_T',T_curve(i));
end
% Plotting the curves
plot (s_l,T_curve);
plot (s_v,T_curve);
text(s1,t1,'1','Fontsize', 15)
text(s2,t2,'2','Fontsize',15)
text(s3,t3,'3','FontSize',15, 'HorizontalAlignment', 'right','VerticalAlignment','top')
text(s4,t4,'4','FontSize',15, 'HorizontalAlignment', 'right','VerticalAlignment','bottom')
text(s5,t5,'5','Fontsize',15)
text (s6,t6,'6','FontSize',15)
xlabel('Entropy in kJ/KgK');
ylabel('Temperature in Degree Celcius');
% Step 6
% Plotting H-S Diagram
subplot (1,2,2)
plot ([s1 s2 s3 s4 s1], [h1 h2 h3 h4 h1], 'linewidth',2)
hold on
plot (s_v,h_v, 'color','r')
plot (s_l,h_l,'color','r')
text(s1, h1,'1','Fontsize',15)
text(s2, h2,'2','Fontsize',15)
text(s3, h3,'3','Fontsize',15, 'HorizontalAlignment', 'right','VerticalAlignment','top')
text(s4, h4,'4','Fontsize',15, 'HorizontalAlignment', 'right','verticalAlignment','bottom')
xlabel('Entropy in kJ/KgK')
ylabel('Enthalpy in kJ/kg')
AIM:
Developing a program to Simulate Rankine Cycle using the provided values and generate Temperature vs Entropy and Entropy vs Enthalpy Graphs.
THEORY:
RANKINE CYCLE
The Rankine cycle is an idealized thermodynamic cycle describing the process by which certain heat engines, such as steam turbines or reciprocating steam engines, allow mechanical work to be extracted from a fluid as it moves between a heat source and heat sink.
Heat energy is supplied to the system via a boiler where the working fluid (typically water) is converted to a high-pressure gaseous state (steam) in order to turn a turbine. After passing over the turbine the fluid is allowed to condense back into a liquid state as waste heat energy is rejected before being returned to boiler, completing the cycle. Friction losses throughout the system are often neglected for the purpose of simplifying calculations as such losses are usually much less significant than thermodynamic losses, especially in larger systems.
There are four processes in the Rankine cycle.
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.
EQUATIONS USED:
- p2v2^gamma=p1v1^gamma
- p1v1/t1=p2v2/t2
- Turbine Work
- wt=h1-h2;
- Pump Work
- wp=v3* (p1-p2)*100;
- Net Work unit in kj/kg
- w_net=wt-wp;
- heat suppied
- Qs=h1-h4;
- Efficiency
- Eff=(w_net/Qs)*100;
- steam rate per second
- steam_rate=3600/ (wt-wp);
STEPS:
- Gaining knowledge on the steps involved in Rankine Cycle.
- Developing the code to accept user inputs for the basic values required for execution of code.
- Obtaining the required Entropy, Enthalpy, Temperature and Pressure values by using basic thermodynamic relations and also extracting data using the XSteam Function provided in the Test Case.
- Printing the calculated State point values.
- Calculation and printing of other output value including efficiency, net work etc..
- Plotting Temperature vs Entropy and Entropy vs Enthalpy Graphs
- Capturing the Graphs and Outputs.
CODE
__________________________________________________________________________
close all
clear all
clc
% Displaying the Four Processes in Rankine Cycle
fprintf('1-2 Isobaric heat Transfer\n')
fprintf('2-3 Isentropic Expansion\n')
fprintf('3-4 Isobaric heat Rejection\n')
fprintf('4-1 Isentropic Compression\n')
% The Code is divided into various Steps for easy Explanation
% Step 1
% Providing the Inputs
p1=input ('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 Pressure at the Condensor (in bar): ');
% Step 2
% Calculation of the 4 State Point Values by applying the data obtained from Xstam and basic Laws Including
% p2v2^gamma=p1v1^gamma and p1v1/t1=p2v2/t2
% state point1
h1=XSteam('h_pt',p1,t1);
s1=XSteam('s_pt',p1,t1);
% Values obtained from XSteam.m file
% state point2
s2=s1;
sf2=XSteam('sL_p',p2);
sg2=XSteam('sv_p',p2);
hf2=XSteam('hL_p',p2);
hg2=XSteam('hv_p',p2);
s2=sg2;
h2=hg2;
t2=XSteam('T_hs',h2, s2);
% state point3
t3=t2;
p3= p2;
s3=XSteam('sL_T',t3);
h3=XSteam('hL_T',t3);
v3=XSteam('vL_p',p2);
% state point4
p4 =p1;
s4= s3;
Cp4=XSteam('Cp_ps',p4,s4);
Cv4=XSteam('Cv_ps',p4, s4);
gamma=Cp4/Cv4;
r=(gamma-1)/gamma;
t4=t3 *(p4/p3)^r;
% state point 5 & 6
t5=XSteam('Tsat_p',p1);
t6=t5;
s5=XSteam('sL_p',p1);
s6=XSteam('sV_p',p1);
h5=XSteam('hL_p',p1);
h6=XSteam('hv_p',p1);
% Step 3
% Calculation of other output values.
%Turbine Work
wt=h1-h2;
%Pump Work
wp=v3* (p1-p2)*100;
h4=wp+h3;
%Net Work unit in kj/kg
w_net=wt-wp;
%heat suppied
Qs=h1-h4;
%Efficiency
Eff=(w_net/Qs)*100;
%steam rate per second
steam_rate=3600/ (wt-wp);
% Step 4
% Displaying The Obtained state Point Values.
printf("\n State Point Values \n");
printf('At State point 1:\n P1 is:%4.2f Bar\n T1 is:%4.2f Degree Celcius\n H1 is:%4.2f kJ/kg\n S1 is:%4.2f kJ/kgk\n\n',p1,t1, h1, s1)
printf('At State point 2:\n P2 is:%4.2f Bar\n T2 is:%4.2f Degree Celcius\n H2 is:%4.2f kJ/kg\n S2 is:%4.2f kJ/kgk\n\n',p2,t2, h2, s2)
printf('At State point 3:\n P3 is:%4.2f Bar\n T3 is:%4.2f Degree Celcius\n H3 is:%4.2f kJ/kg\n S3 is:%4.2f kJ/kgk\n\n',p3,t3, h3, s3)
printf('At State point 4:\n P4 is:%4.2f Bar\n T4 is:%4.2f Degree Celcius\n H4 is:%4.2f kJ/kg\n S4 is:%4.2f kJ/kgk\n\n',p4,t4, h4, s4)
printf('\n Pump work is :%4.2f kJ/kg\n Turbine Work is :$4.2f kJ/kg\n Net Work is :%4.2f kJ/kg\n Efficiency is :%4.2f percent\n Steam rate :%4.2f Kg/KWh ',wp, wt, w_net, Eff, steam_rate)
% Step 5
% Plotting the T-S Diagram
subplot(1,2,1)
T_rankine=linspace(t5,t1,5000);
% Determining Corresponding values for S with respect to t from xstream data
for i=1:length(T_rankine)
s_rankine (i)=XSteam('s_pT',p1,T_rankine(i));
end
plot ([s1 s2 s3 s4 s5 s6 s_rankine], [t1 t2 t3 t4 t5 t6 T_rankine], 'linewidth',1.5);
hold on
T_curve=linspace(1,400, 500);
for i=1:length(T_curve)
s_l(i)=XSteam('sL_T',T_curve(i));
s_v(i)=XSteam('sV_T',T_curve(i));
h_l(i)=XSteam('hL_T',T_curve(i));
h_v(i)=XSteam('hv_T',T_curve(i));
end
% Plotting the curves
plot (s_l,T_curve);
plot (s_v,T_curve);
text(s1,t1,'1','Fontsize', 15)
text(s2,t2,'2','Fontsize',15)
text(s3,t3,'3','FontSize',15, 'HorizontalAlignment', 'right','VerticalAlignment','top')
text(s4,t4,'4','FontSize',15, 'HorizontalAlignment', 'right','VerticalAlignment','bottom')
text(s5,t5,'5','Fontsize',15)
text (s6,t6,'6','FontSize',15)
xlabel('Entropy in kJ/KgK');
ylabel('Temperature in Degree Celcius');
% Step 6
% Plotting H-S Diagram
subplot (1,2,2)
plot ([s1 s2 s3 s4 s1], [h1 h2 h3 h4 h1], 'linewidth',2)
hold on
plot (s_v,h_v, 'color','r')
plot (s_l,h_l,'color','r')
text(s1, h1,'1','Fontsize',15)
text(s2, h2,'2','Fontsize',15)
text(s3, h3,'3','Fontsize',15, 'HorizontalAlignment', 'right','VerticalAlignment','top')
text(s4, h4,'4','Fontsize',15, 'HorizontalAlignment', 'right','verticalAlignment','bottom')
xlabel('Entropy in kJ/KgK')
ylabel('Enthalpy in kJ/kg')
CODE Explanation:
The Code Has been Divided into Six Seps for better Explanation
Step 1: Providing the Input parameters like Pressure at Turbine Inlet, Temperature at Turbine Inlet and Pressure at Turbine Inlet.
Step 2: Calculation of the 4 State Point Values by applying the data obtained from Xsteam and basic Laws Including p2v2^gamma=p1v1^gamma and p1v1/t1=p2v2/t2.
Step 3: Values Including Efficiency, Net Work, Pump Work, Heat Supplied etc. are calculated using the equations mentioned in the on equations used section.
Step 4: The Obtained Output values along with the temperature, pressure, enthalpy and entropy values at each state-points are displayed to the users.
Step 5: For Loop and linspace command are used for generating T and S values and these values are plotted along with which the values obtained from Xsteam are also plotted using another for looping thus plotting the required T vs S Graphs.
Step 6: H-S Diagram is plotted using the available Enthalpy and Entropy values to obtained the require graph
RESULT:
Applied the data read from user and Xsteam function to obtain the required state-point and Efficiency values along with the other required Outputs and also Plotted T-S and H-S diagram for the corresponding case.
OUTPUT SCREEN:
Errors:
- Typo errors.
Error Resolutions:
- Typo errors were rectified by referring to syntaxes.
I have attached the Screenshots for your reference.
Resources:
- https://en.wikipedia.org/wiki/Rankine_cycle
- https://in.mathworks.com/matlabcentral/answers/362446-load-files-from-user-input
- https://in.mathworks.com/help/matlab/creating_plots/combine-multiple-plots.html
# Detailed Code explanations have been provided with as comments with the code.
# Have attached the doc file ocf report as pictures are unable to be inserted onto the provided space.