Visualizing P-V Diagram for Otto Cycle using MATLAB
AIM:
Write a code that can solve the thermal efficiency of an Otto cycle and visualize a P-V diagram for it.
GOVERNING EQUATION:
Ideal gas state equation: `PV=RT`
For a Reversible adiabatic process: `PV^γ=constant`
Compression Ratio: `c_r=V_1/V_2`
Geometric Equation derived for finding change of volume inside a combustion chamber as a function of crank angle:
`V/V_c =1+1/2 (c_r-1)[R+1-cosθ-(R^2-sinθ^2 )^(1/2) ]`
Where,
`R= l/a`
`a= s/2`
Swept Volume: `V_s=π/4*b ^2*s`
Clearance Volume: `V_c=V_s/(c_r-1)`
Efficiency: `η=1- 1/c_r^(γ-1)`
TERMINOLOGY:
p1- Pressure at point 1, `(N⁄m^2 )`
v1- Volume at point 1, `(m^3 )`
t1- Temperature at point 1, (K)
p2- Pressure at point 2, `(N⁄m^2 )`
v2- Volume at point 2, `(m^3 )`
t2- Temperature at point 2, (K)
p3- Pressure at point 3, `(N⁄m^2 )`
v3- Volume at point 3, `(m^3 )`
t3- Temperature at point 3, (K)
p4- Pressure at point 4, `(N⁄m^2 )`
v4- Volume at point 4, `(m^3 )`
con_rad- Connecting rod length (m)
cr- Compression ratio
theta- Crank angle (`degree`)
start_crank- Starting crank angle (`degree`)
end_crank- Ending crank angle (`degree`)
v_c- Clearance volume `(m^3 )`
v_s- Swept volume `(m^3 )`
a- Crank pin radius (`m`)
b- Diameter of bore (`m`)
l- Connecting rod length (`m`)
Otto Cycle
It is an idealized thermodynamic cycle that describes the functioning of a typical spark ignition piston engine. It consists of four internally reversible processes. Here heat is transferred to the working fluid (air) at constant volume.
Fig: P-V Diagram for Otto Cycle
-
1-2: Isentropic Compression
-
2-3: Isochoric heat addiction
-
3-4: Isentropic Expansion
-
4-1: Isochoric heat rejection
The compression stroke (1-2), in which fuel/air mixture is compressed to high pressure and high temperature, since its is compression the volume gets reduced. At the end of compression stroke fuel is ignited at constant volume (2-3) but the pressure increase dramatically and heat is generated inside the system. The hot high pressure gas pushes the piston from top dead centre to bottom dead centre which is a power stroke(3-4), here the volume is expanded and pressure drops. At the end of power stroke exhaust valve opens and at constant volume, pressure and heat is released through exhaust (4-1). Graphically the area within the cycle gives the work done by the engine.
These governing equations help the program to plot P-V diagram and calculate the efficiency of Otto cycle. Analysing the Otto cycle provides how engine efficiency is affected by changing operating and design parameters.
OBJECTIVE:
- To create a P-V diagram for Otto cycle and understand the theoretical limits of the cycle.
- To calculate the thermal efficiency.
PROGRAM:
Programming language used: MATLAB
1.Function code for tracing volumetric change when the piston moves inside the cylinder
This function is used to connect two state points with reference to volume change happening inside the combustion chamber with a change in crank angle.
%Function for Engine Kinematics
function [v]= engine_kinematics(bore,stroke,con_rad,cr,start_crank,end_crank);
theta=linspace(start_crank,end_crank,100);
v_s=pi/4*bore^2*stroke; %calculating swept volume
v_c=v_s/(cr-1); %calculating clearance volume
a=stroke/2; %calculating crank pin radius
R=con_rad/a; %calculating the ratio
term1=0.5*(cr-1);
term2=R+1-cosd(theta);
term3=(R^2-sind(theta).^2).^0.5;
v=(1+term1*(term2-term3)).*v_c; %calculating volume inside combustion chamber
end
Explaining the code:
-
Line 2: Defining the function with function name (engine_kinematics), input parameters and output variable (v).
-
Line 5: Storing 100 equally spaced values (linspace) between start_crank & end_crank into variable theta.
-
Line 8: Calculating swept volume and storing the value to variable v_s.
-
Line 9: Calculating clearance volume and storing the value to variable v_c
-
Line 11-12: Equation for finding the crank pin radius and ration of connecting rod length and crank pin radius.
-
Line 14-16: Breaking the equation for volume inside the chamber into 3 terms.
-
Line 18: Calculating the volume inside the chamber and storing the values as an array.
-
Line 20: For a function there should be an end keyword.
RESULT OF FUNCTION CODE:
Fig- Function is called in the command window
Fig- Volume change inside the combustion chamber for 2 cycles
MAIN CODE:
clear all
clc
close all
%Program to plot Otto Cylce
%inputs
gamma=1.4;
t1=702; %Temperature at 1 (K)
t3=3080; %Temperature at 3 (K)
p1=101233; %Pressure at 1 (N/m^2)
bore= 0.078; %Bore diameter(m)
stroke=0.084; %Stroke length(m)
con_rad=0.131;%Connecting rod length(m)
cr=10; %Compression ratio
%calculating swept volume & clearance volume
v_s=(pi/4)*bore^2*stroke; %Swept Volume
v_c=v_s/(cr-1); %Clearance volume
%state variables at point 1
v1=v_c+v_s; %Volume at 1 (m^3)
%state variable at point 2
v2=v_c; %Volume at 2 (m^3)
%p2=p1*(v1/v2)^gamma | (v1/v2)=cr
p2=p1*cr^gamma; %Pressure at 2 (N/m^2)
%(p1*v1)/t1=(p2*v2)/t2
t2=p2*v2*t1/(p1*v1);
V_compression= engine_kinematics(bore,stroke,con_rad,cr,180,0); %Calling the function
constant_c = p1*v1^gamma;
P_compression= constant_c./V_compression.^gamma;
%state variables at point 3
v3=v2; %constant volume at 2&3
%(p3*v3)/t3= (p2*v2)/t2
p3=p2*t3/t2; %Pressure at 3(N/m^2)
%state variables at point 4
v4=v1; %constant volume at 1&4
p4=p3*(v3/v4)^gamma; %Pressure at 4
V_expansion= engine_kinematics(bore,stroke,con_rad,cr,0,180); %Calling the function
constant_c = p3*v3^gamma;
P_expansion= constant_c./V_expansion.^gamma;
%Calculating the thermal efficiency
Thermal_efficiency= 1-(1/cr^(gamma-1));
Themal_efficiency_percentage = Thermal_efficiency*100;
hold on
plot(v1,p1,'*','color','b');
plot(v2,p2,'*','color','b');
plot(v3,p3,'*','color','b');
plot(v4,p4,'*','color','b');
plot(V_compression,P_compression,'color','r');
plot(V_expansion,P_expansion,'color','y');
plot([v2 v3] [p2 p3],'color','b');
plot([v4 v1] [p4 p1],'color','g');
xlabel('Volume(m^3)');
ylabel('Pressure (Pa)');
title('P-V Diagram');
grid on
Explaining the code:
-
Line 7-14: Input values for variable.
-
Line 17-18: Equation for swept volume and clearance volume.
-
Line 21: Volume at state point 1 is calculated.
-
Line 24-30: Volume, Pressure and Temperature at state point 2 are calculated.
-
Line 32: Calling the engine_kinematics function and storing the values to an array called V_compression.
-
Line 33: constant_c is calculated with respect to pressure and volume at state point 1.
-
Line 34: P_compression is calculated using data stored in constant_c and V_compression.
-
Line 37-40: Volume and pressure at state point 3 are calculated.
-
Line 43-44: Volume and pressure at state point 4 are calculated.
-
Line 46: Calling the function again but this time the start crank angle and end crank angle are different since it is calculating the volume at expansion.
-
Line 47: constant_c is over written by values with respect to pressure and volume at state point 3.
-
Line 48: P_expansion is calculated using data stored in constant_c and V_expansion.
-
Line 51: Thermal efficiency is calculated and displayed in command window.
-
Line 52: Thermal efficiency in percentage is shown in command window.
-
Line 54: Hold on command used to retain the plots on current axis without deleting the existing plot when new plots are added.
-
Line 55-58: Plot command is used to plot 4 state points marked as ‘*’ in colour blue.
-
Line 59-62: Plot command is used to connect each state point from 1-2, 2-3, 3-4 and 4-1.
-
Line 63-64: Using command xlabel and ylabel, labelled the X-axis and Y-axis.
-
Line 65: Using command title, heading for the figure is given.
-
Line 66: grid on command is used to display grid on the figure.
ERRORS DEALT WITH:
1. Error: Incorrect P-V Diagram for Otto cycle.
Solution: The equation for finding the swept volume was entered wrong (Fuction code Line 8). Correcting the equation gave the correct P-V Diagram.
2. Error: File: otto_cycle.m Line: 61 Column: 14
Invalid expression. When calling a function or indexing a variable, use parentheses. Otherwise, check for mismatched delimiters.
Solution: Comma (,) operator was missing inside plot command. Corrected by giving the operator.
RESULT:
Fig- P-V Diagram for Otto cycle
Fig: Result of thermal efficiency showing in command window
This program helps to plot P-V diagram with operational and design parameters. By changing the parameters we can observe the efficiency of the engine and variations of pressure and volume happening inside the combustion chamber.
As the compression ratio is increased the efficiency of engine increases but increasing the compression ratio higher that a certain value will result in knocking so an optimum value of compression ratio should be maintained so that efficiency is not dropped.
CONCLUSION:
The program runs successfully and gives the P-V Diagram and thermal efficiency for the given inputs.