OTTO CYCLE CODE USING MATLAB
AIM:
- Writing code in MATLAB to solve an otto cycle.
BRIEF DESCRIPTION ABOUT OTTO CYCLE:
An Otto cycle is an idealized thermodynamic cycle that describes the functioning of a typical spark ignition piston engine. It is the thermodynamic cycle most commonly found in automobile engines. Otto cycle describes the changes that occur to a mass of gas when it is subjected to change of pressure, volume, temperature, heat addition, and heat rejection.
Otto cycle is consists of four main processes or four strokes.
PROCESSES OF OTTO CYCLE:
- Process 0-1 - Constant pressure air-fuel mixture intake – intake stroke.
- Process 1-2 - Reversible adiabatic compression – compression stroke.
- Process 2-3 - Constant volume heat addition – ignition phase.
- Process 3-4 - Reversible adiabatic expansion – power stroke.
- Process 4-1-Constant volume gas temperature decreases - Heat rejection phase.
- Process 1-0 - Constant pressure gas escape - exhaust stroke.
ASSUMPTION OF OTTO CYCLE (AIR-STANDARD CYCLE):
- Air is working fluid.
- Air behaves as an ideal gas.
- Mass of air remains constant i.e. closed system analysis.
- The specific heat of air remains constant.
- The working fluid does not undergo any chemical changes.
- All processes are reversible.
GOVERNING EQUATIONS:
- Adiabatic process equation:
`PV^γ = "constant"`
An adiabatic process transfers energy to the surroundings only as work that no transfer so mass or heat. The adiabatic process is used for the expansion and compression process so that no inefficiency ( loss in mechanical energy) and heat transfer occur.
This equation is used to calculate the pressure of the compression and expansion process.
- Compression and expansion volume:
`V/V_c =1+ 1/2 (r-1)(R+1-cosθ- √(R^2-〖sin〗^2 θ) )`
This is the most important equation of code. This equation will calculate compression and expansion volume which will help in the calculation of the pressure of compression and expansion process.
- Thermal efficiency equation:
`η = 1- 1/r^((γ-1) )`
Thermal efficiency is required as output. Thermal efficiency is a ratio of output and input.
Nomenclature:
η = Thermal efficiency;
P = Pressure (in kg/m3);
V = Volume (in m3);
γ (Gamma) = ratio of specific heats;
n = Number of moles;
R = Gas constant (in kJ/kg K);
`r = "Compression ratio"= ("Volume before compression")/("Volume after compression")= V_1 / V_2`
Vc = Clearance volume = Vtotal - Vswept = total volume – swept volume;
`V_c= V_(swept)/((r - 1) )`, (in m3); `V_(swept)= π/4 D^2 L`,(in m3);
D = bore (nominal inner diameter of cylinder or piston diameter) (in m);
L = stroke = length travelled between TDC & BDC;
Top Dead Centre (TDC) = It is dead centre where the piston is farthest from the crankshaft.
Bottom Dead Centre (BDC) = It is a dead center where the piston is nearest to the crankshaft.
OBJECTIVE OF THE PROJECT:
- To plot the PV diagram of the otto cycle.
- Output thermal efficiency.
The workflow of the project:
- We will consider only the main four processes- i.e., compression, heat addition, expansion, heat rejection. The suction and exhaust process get nullified so will not be considered while programming.
- We will define all the basic parameters of the engine which is required as input. That is a bore, compression ratio, stroke, crankshaft rotation, connecting rod length, etc.
- Define equations required to calculate pressure and volume for all for states.
- For the compression and expansion process, we will form a supplementary program as a function.
- After calculating all state variables using them to plot the PV diagram.
- The final step is to calculate thermal efficiency.
BODY OF THE CONTENT:
- The programming language used in this program is C/C++.
- Code to solve an otto cycle–
% A program to solve Otto Cycle
close all
clear all
clc
%% Processes of otto cycle
%%State 1-2 - Reversible adiabatic compression
%%State 2-3 - Constant volume heat addition
%%State 3-4 - Reversible adiabatic Expansion
%%State 4-1 - Constant volume heat rejection
% Inputs
gamma = 1.4;
t3 = 2300;
% State variable at point 1
p1 = 101325;
t1 = 500;
% Engine parameters
% Nominal inner diameter of cylinder or piston diameter
bore = 0.1;
stroke = 0.1;
con_rod = 0.15;
% compression ratio (cr)
cr = 12;
start_crank = 180;
end_crank = 0;
% Calculating swept & clearance Volume
v_swept = (pi/4)*bore^2*stroke;
v_clearance = v_swept/(cr-1);
v1 = v_swept + v_clearance
v2 = v_clearance
% Compression process
constant_c = p1*v1^gamma;
% Volume and Pressure Arroy for Compression
V_compression = engine_kinematics(bore, stroke, con_rod, cr, start_crank, end_crank);
P_compression = constant_c./V_compression.^gamma;
% State variable for point 2
% p1v1^gamma = p2v2^gamma
% p1/p2 = (v2/v1)^gamma| p2 = p1*cr^gamma
p2 = p1*cr^gamma
% p1v1/t1 = p2v2/t2| t2= t1*cr^(gamma - 1)
t2 = t1*cr^(gamma-1)
% State variable for point 3
v3 = v2
% p2/t2 = p3/t3 | p3 = p2*(t3/t2)
p3 = p2*(t3/t2)
% Expansion process
constant_c = p3*v3^gamma;
% Volume and Pressure Arroy for expansion
V_expansion = engine_kinematics(bore, stroke, con_rod, cr, start_crank, end_crank);
P_expansion = constant_c./V_expansion.^gamma;
% State variable for point 4
v4 = v1
% p4v4^gamma = p3v3^gamma |
% p4 = p3*(v3/v4)^gamma
p4 = p3*(v3/v4)^gamma
% p3v3/t3 = p4v4/t4 | t4 = t3*p4*v4/(p3*v3)
t4 = t3*p4*v4/(p3*v3)
%% 1st objective - plot PV diagram for the otto cycle
figure(1)
% Correct plot
hold on
plot(v1,p1,'*','color','m')
plot(V_compression,P_compression)
plot(v2,p2,'*','color','m')
plot([v2 v3],[p2 p3],'color','r')
plot(v3,p3,'*','color','m')
plot(V_expansion,P_expansion)
plot(v4,p4,'*','color','m')
plot([v4 v1],[p4 p1],'color','r')
xlabel('Volume')
ylabel('Pressure')
figure(2)
% Not correct plot
plot([v1 V_compression v2 v3 V_expansion v4 v1],[p1 P_compression p2 p3 P_expansion p4 p1])
xlabel('Volume')
ylabel('Pressure')
%% 2nd objective - Output thermal efficiency
% efficiency = 1 - 1/(cr)^(gamma-1)
% thermal_efficiency=1 - 1/(rp)^((gamma-1)/gamma)=1-(p1/p2)^((gamma-1)/gamma)
% Pressure Ratio = rp = p1/p2
efficiency = 1 - 1/(cr)^(gamma-1)
rp = p2/p1
thermal_efficiency = 1 - 1/(rp)^((gamma-1)/gamma)
- The function of ‘engine kinematics’ –
% function for compression and expansion of volume in otto cycle
function [V] = engine_kinematics(bore, stroke, con_rod, cr, start_crank, end_crank)
%Inputs
a = stroke/2;
R = con_rod/a;
theta = linspace(start_crank,end_crank,100);
% swept volume and clearance volume
v_s = pi/4*bore^2*stroke;
v_c = v_s/(cr-1);
%Compression and expansion volume
% V = v_c[1+0.5(cr-1){R + 1 - cos(theta) - (R^2 - sin(theta)^2)^0.5}]
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;
end
- Stepwise explanation of the code –
- Define the basic parameter of the engine - i.e., bore, compression ratio, stroke, crankshaft rotation, connecting rod length, etc. as input.
- Provide state – 1 pressure and temperature values to calculate other state variables.
- Swept volume and clearance volume equation to calculate state – 1 volume (total volume).
- Mention function in the code.
- State – 2,3,4 pressure and volume calculation equation i.e., adiabatic equation & constant volume equation.
- Compression and expansion volume array that will result in a proper adiabatic curve.
- The plot of the PV diagram using all four state variables.
- The thermal efficiency of the cycle through the efficiency equation.
RESULTS:
- Output thermal efficiency-
Thermal efficiency is the measure of the effectiveness of the cycle. It also indicates how economical will be the cycle for application. Thermal efficiency is the ratio of output to input. It is directly proportional to the compression ratio.
- The plot of PV diagram –
The plot of the PV diagram Indicates the variation in pressure and volume concerning processes. The adiabatic curve has slope = `γ P/V` & for air `γ`= 1.4 so slope will be greater and a steeper.
CONCLUSION:
Compression and expansion volume is an array of 100 values and can be adjusted to achieve more or less fine curvature. The compression and expansion process both are adiabatic and adiabatic process has slope = `gamma(P/V)` value of gamma is greater than 1 which makes the slope steeper. Constant volume process slope depends on pressure only, hence make a straight line varies with pressure.