Solving an Otto cycle to visualize its PV Diagram and to find its efficiency using  Matlab
Solving an Otto cycle to visualize its PV Diagram and to find its efficiency using Matlab
AIM
To Solving an Otto cycle to visualize its PV Diagram and to find its efficiency using Matlab.
PROCEDURE
* The otto cycle is basically a four stroke cycle where the power is generated by four step wise process
* The process from 1 to 4 is explained
1 to 2 - Isentropic compression process
2 to 3 - Constant volume heat addition
3 to 4 - Isentropic expansion process
4 to 1 - Constant volume heat rejection
* Since process 1 & 3 is isentropic the entropy is constant and in process 2 & 4 the volume is made constant in an otto cycle
*Then we give all the input parameters value
gamma=1.4
t3=2300K
p1=101325 pascal(1 atm)
t1=500K
*Then the engine geomentric value is specified
bore=0.1
stroke=0.1
cr=12
con_length=0.15
1. Bore- The diameter of the piston
2. Stroke- The vertical length where the piston moves
3. (cr) compression ratio - The ratio of (Max volume inside the combustion chamber)/ (Min volume inside the combustion chamber)
4. con_length= The length of the connecting rod
*Then the swept volume and the clearence volume is found using the engine geomentric values
*Swept volume is nothing but the volume between the TDC(top dead centre) & BDC(bottom dead centre),where the piston moves up and down .
Swept volume = (pi/4)*bore^2*stroke
* Clearence volume is the volume above the piston when the piston is at TDC position while on the compression process
Clearence volume = swept volume/(cr-1)
* Then we use a formula to measure the volume inside the engine chamber with respect to crank angle
v/vc = 1 + 0.5*(cr-1)*[R + 1 - cosd(theta) - (R^2 - sind(theta)^2).^0.5
Here R - It is the ratio of = (con_length)/(crank pin radius)
Crank pin radius (a) = stroke/2
* Then with all of these values we can bring the pv diagram of otto cycle using matlab codes.
MATLAB Codes to visualize pv diagram and to find the efficiency of this otto cycle:
clear all
close all
clc
%inputs temp in (K)
gamma=1.4
t3=2300
% State variables in (pas)&(K)
p1=101325
t1=500
%v1=v_swept+v_clearence
%Engine geomentric values all in (M)
bore=0.1
stroke=0.1
cr=12
con_length=0.15
%calculating the swept volume & clearence volume(m^3)
v_swept=(pi/4)*bore^2*stroke
v_clearence=v_swept/(cr-1)
v2=v_clearence
v1=v_swept+v_clearence
%State variable 2
%p1v1^gamma=p2v2^gamma
%p2=p1*(v1/v2)^gamma=p1*(cr)^gamma
p2=p1*(cr)^gamma
%(p1v1)/t1=(p2v2)/t2;(p2v2)*t1/(p1v1)=t2
t2=(p2*v2*t1)/(p1*v1)
constant_c=p1*v1^gamma
V_compression=engine_kinematics(0.1,0.1,12,0.15,180,0)
P_compression=constant_c./V_compression.^gamma
%state variable 3
v3=v2
%(p2*v2)/t2=(p3*v3)/t3;p3=(p2*v2*t3)/(v3*t2)
p3=(p2*v2*t3)/(v3*t2)
%state variable 4
v4=v1
%p3v3^gamma=p4v4^gamma
p4=p3*(v3/v4)^gamma
%p3v3/t3=p4v4/t4;t4=(p4*v4*t3)/(p3*v3)
t4=(p4*v4*t3)/(p3*v3)
constant_c=p3*v3^gamma
V_expansion=engine_kinematics(0.1,0.1,12,0.15,0,180)
P_expansion=constant_c./V_expansion.^gamma
%efficiency of the otto cycle
efficiency_otto=1-((t4-t1)/(t3-t2))
figure(1)
hold on
plot(v1,p1,'*','color','r')
plot(V_compression,P_compression)
plot(v2,p2,'*','color','r')
plot(v3,p3,'*','color','r')
plot(V_expansion,P_expansion)
plot(v4,p4,'*','color','r')
line([v2 v3],[p2 p3],'linewidth',0.5,'color','r')
line([v1 v4],[p1 p4],'linewidth',0.5,'color','r')
xlabel('volume(m^3)')
ylabel('pressure(Pas)')
MATLAB Codes to create the function engine_kinematics:
function [V] = engine_kinematics(bore,stroke,cr,con_length,start_crank,end_crank)
a = stroke/2
R = con_length/a
v_swept=(pi/4)*bore^2*stroke;
v_clearence=v_swept/(cr-1);
theta = linspace(start_crank,end_crank,180)
term1=0.5*(cr-1);
term2=R+1-cosd(theta);
term3=(R^2-sind(theta).^2).^0.5 ;
V=(1+term1*(term2-term3)).*v_clearence;
end
Screenshots of the output:
Stepwise explanation of the codes:
1.Firstly we are assingning the values for the input parameters of the first process in otto cycle,like pressure ,temperature, gamma . The pressure is taken as 1 Atmospheric pressure which is,
p1=101325pascal ,
temperature as,
t1= 500 K and
gamma = 1.4
The temperature at third process (which is the heat input given)
t3=2300 K
2. Then we are giving the engine geomentric values that is the dimensions of the cylinder and some of its components in meters ,
bore=0.1
stroke=0.1
cr=12
con_length=0.15
3. After that we are we are calculating the swept volume ,clearence volume at volume at the 1st & 2nd process as v1 and v2.
v_swept=(pi/4)*bore^2*stroke
v_clearence=v_swept/(cr-1)
v2=v_clearence
v1=v_swept+v_clearence
4. Since the process 1 to 2 is isentropic we can use this expression to calculate the pressure(p2) at process 2,
p1v1^gamma=p2v2^gamma
p2=p1*(v1/v2)^gamma=p1*(cr)^gamma ( as cr = v1/v2)
p2=p1*(cr)^gamma
*After calulation the pressure and volume at 2nd process we can find the temperature (t2)there using the Ideal gas equation which is ,
P.V = mr t (which is a constant ) so,
(p1v1)/t1=(p2v2)/t2
(p2v2)*t1/(p1v1)=t2
t2=(p2*v2*t1)/(p1*v1)
5. Since the process 2 to 3 is constant volume process the volume v3 = v2. The temperature (t3) is given as the input ,so with that we can calulate the pressure (p3) using the Ideal gas equation,
(p2*v2)/t2=(p3*v3)/t3
p3=(p2*v2*t3)/(v3*t2)
6. Then we need to calculate the parameters at process 4. Since the process 1 & 4 is constant volume process
v4 = v1
as the process 3 to 4 is a isoentropic process, we use this expression to find (p4)
p3v3^gamma=p4v4^gamma
p4=p3*(v3/v4)^gamma
*After calulation the pressure and volume at 4th process we can find the temperature (t4)there using the Ideal gas equation which is ,
p3v3/t3=p4v4/t4
t4=(p4*v4*t3)/(p3*v3)
7. Then by knowing all the pressure temperature values at all 4 process we can plot the points using (p1 v1, p2 2, p3 v3 , p4 v4). we get a figure like this,
8. We cannot join the points using straigt lines that is wrong, as the volume varies inside the cylinder with the change in the crank angle so we will definitely also have a pressure change at each points corresponding to the volume change
*To determine the change of volume with respect to crankangle we need to use this formula
v/vc = 1 + 0.5*(cr-1)*[R + 1 - cosd(theta) - (R^2 - sind(theta)^2).^0.5
Here R - It is the ratio of = (con_length)/(crank pin radius)
Crank pin radius (a) = stroke/2
9.We can have the theta to be from 0 to 180 degree which tells that the piston is moving from TDC to BDC or we can have theta to be from 180 to 0 degree which happens when the piston is moving from the BDC to TDC,anything as per the process,for this program we select the theta to be from 0 to 180 with 100 values inbetween using the linspace command
10. In order to cutshort the length of the program we can save the value as v and put this into a function called 'engine-kinematics' and call this function into to program where ever required by giving all the input values we can find the volume corresponding to the crank angle.
11. To measure the volume corresponding to the crank angle during compression we can give the angles
*Start_crank = 180 degree
* End crank = 0 degree in the linspace command , because during compression the piston is moving from the BDC to TDC and save the value of v as 'V_compression'. After this by using v_compression we can find p_compression ,since it is an isentropic process using the relation ,
constant_c=p1*v1^gamma (finding the constant value)
constant=p_compression*v_compression^gamma (using the constant to find p_compression)
P_compression=constant_c./V_compression.^gamma
*similarly to measure the volume corresponding to the crank angle during expansion we can give the angles
*Start_crank = 0 degree
* End crank = 180 degree in the linspace command , because during expansion the piston is moving from the TDC to BDC and save the value of v as 'V_expansion'. After this by using v_expansion we can find p_expansion. since it is isoentropic process using the relation,
constant_c = p3*v3^gamma (finding the constant value)
constant = p_expansion*v_expansion^gamma (using the constant to find p_expansion)
P_expansion = constant_c./V_expansion.^gamma
12 . Then in the ottocycle program we are calling the function 'engine_kinematics' and we are executing the program to find the volume change with respect to the crank revolution movement.
13. Then we need to plot the v_compression & p_compression then v_expansion & p_expansion and now we are getting the curve in the right way then using the line command we connect both the constant volume process to complete the pv diagram.
The PV Diagram of OTTO Cycle:
14. Then to find the efficiency of otto cycle ,
*efficiency = Work done / Amount of Heat added
*work done = Amount of Heat added- Amount of Heat rejected
( gives the amount of heat utilized to convert into mechanical work.)
*Amount of Heat added = t3 - t2
* Efficiency = [(t3 - t2) - (t4 - t1)] / (t3 - t2)
* Efficiency = 1-((t4-t1)/(t3-t2)) will give the efficiency.
RESULT:
*The matlab codes were done to visualize the pv diagram of a otto cycle
* The results are given below for the volume at pressures at all the four process, volume in (m^3) , temperature in (K) & a in (m),
t1= 500
p1 = 101325
v_swept =7.8540e-04
v_clearence =7.1400e-05
v1 =8.5680e-04
v2 =7.1400e-05
p2 =3.2853e+06
t2 =1.3510e+03
constant_c =5.1493 ( 1 to 2 process)
a =0.0500
R =3.0000
V_compression =1.0e-03 *
P_compression =1.0e+06 *
v3 =7.1400e-05
p3 =5.5931e+06
v4 =8.5680e-04
p4 =1.7251e+05
t4 =851.2465
constant_c =8.7666 (3 to 4 process)
V_expansion =1.0e-03 *
P_expansion =1.0e+06 *
*The efficiency of the otto cycle is calculated to be = 0.6299 .
*In percentage the effiency of otto cycle is 62.99 %.