Using MATLAB plot P-V Diagram of Otto Cycle and calculate thermal efficiency of the engine
Objective:
To plot a P-V Diagram of Otto Cycle and output the thermal efficiency of the engine.
Theory:
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.
The Otto cycle is a description of what happens to a mass of gas as it is subjected to changes of pressure, temperature, volume, addition of heat, and removal of heat. The mass of gas that is subjected to those changes is called the system. The system, in this case, is defined to be the fluid (gas) within the cylinder. In the case of the Otto cycle, the effect will be to produce enough net work from the system so as to propel an automobile and its occupants in the environment.
The various processes involved in the otto cycle are as follows:
Process 1-2: Isentropic Compression Process
Process 2-3: Constant Heat Addition Process
Process 3-4: Isentropic Expansion Process
Process 4-1: Constant Heat Rejection Process
--------------------------------------------------------------------------------------------------------
Explanation of the code:
The engine geometric parameteres, state variables of state 1 and gamma are assumed to be provided.
Through engine parameters, the swept volume and clearance volume is calculated.
All the state variables (pressure, volume, temperature) for isentropic process (state 2 and 4) can be calculated using the relation `P1*V1^gamma = P2*V2^gamma` , `P3*V3^gamma = P4*V4^gamma` , `(P1V1)/(T1) = (P2V2)/(T2)` and `(P3V3)/(T3) = (P4V4)/(T4)`.
Due to constant volume heat addition and rejection process, V2=V3 and V1=V4.
Since the volume doesn't vary linearly with the pressure for isentropic process, the state path for isentropic process is calculated using `V/(Vc)=1+1/2(cr-1)[R+1-costheta-(R^2-sin^2theta)^(1/2)]` and `PV^gamma = cons`
It is done with a user defined function named as engine_kinematics.
This function solves this equation `V/(Vc)=1+1/2(cr-1)[R+1-costheta-(R^2-sin^2theta)^(1/2)]`
This function is invoked two times, first for compression and second for expansion.
Seperate plot commands are used to plot each process.
Thermal Efficiency of the engine is calculated by `eta=1-(1/(cr^(gamma-1)))`
--------------------------------------------------------------------------------------------------------
MATLAB Code
The MATLAB code is to plot a P-V diagram of Otto Cycle and calculate the thermal efficiency of the engine.
% Program to plot P-V diagram of Otto Cycle and calculate the thermal
% efficiency of the engine
clear all
close all
clc
% Inputs
gamma = 1.4;
t3 = 2300;
% STate variables at state 1
p1 = 101325;
t1 = 500;
% Engine Geometric Parameters
bore = 0.1;
stroke = 0.1;
con_rod = 0.15;
cr = 12;
% Calculating the swept and clearance volume
v_swept = (pi/4)*bore^2*stroke;
v_clearance = v_swept/(cr-1);
v1 = v_swept + v_clearance;
v2 = v_clearance;
% State variables at state point 2
% p2v2^gamma = p1v1^gamma
% p2 = p1*(v1/v2)^gamma
p2 = p1*cr^gamma;
% p1v1/t1 = p2v2/t2
t2 = t1*p2*v2/(p1*v1);
% State path from state 1 to state 2
constant_c = p1*v1^gamma;
V_compression = engine_kinematics(bore,stroke,con_rod,cr,180,0);
P_compression = constant_c./ V_compression.^gamma;
% State variables at state point 3
v3 = v2;
% p3v3/t3 = p2v2/t2
p3 = t3*p2/t2;
% State path from state 3 to state 4
constant_c = p3*v3^gamma;
V_expansion = engine_kinematics( bore, stroke, con_rod, cr, 0, 180);
P_expansion = constant_c ./ V_expansion.^gamma;
% State variables at state point 4
v4 = v1;
% p3v3^gamma = p4v4^gamma
p4 = p3*(v3/v4)^gamma;
figure (1)
hold on
grid on
% plotting all the 4 points
plot([v1 v2 v3 v4],[p1 p2 p3 p4],'*')
% Plotting Isentropic Compression Process 1-2
plot( V_compression, P_compression,'color','m','linewidth',2)
% Plotting Constant Volume Heat Addition Process 2-3
plot([v2 v3],[p2 p3],'color','r','linewidth',2)
% Plotting Isentropic Expansion Process 3-4
plot( V_expansion, P_expansion,'linewidth',2)
% Plotting Constant Heat Rejection Process 4-1
plot([v4 v1],[p4 p1],'color','b','linewidth',2)
xlabel('Volume')
ylabel('Pressure')
title('PV Diagram of Otto Cycle')
legend('State Points','Isentropic Compression Process 1-2','Constant Volume Heat Addition Process 2-3','Isentropic Expansion Process 3-4','Constant Heat Rejection Process 4-1')
thermal_efficiency = 1- (1/cr^(gamma-1));
sprintf('Thermal Efficiency of the otto cycle is %d',thermal_efficiency)
User-Defined Function or Sub-Program:
function [V] = engine_kinematics(bore, stroke, con_rod, cr, start_crank, end_crank)
% crank pin radius 'a'
a = stroke/2;
R = con_rod/a;
v_s = pi/4*bore^2*stroke;
v_c = v_s/(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_c;
end
OUTPUT:
-------------------------------------------------------------------------------------------------------
No error was generated in the code else two typo errors.
-------------------------------------------------------------------------------------------------------
CONCLUSION:
In the processes 1–2 the piston does work on the gas and in process 3–4 the gas does work on the piston during those isentropic compression and expansion processes, respectively. Processes 2–3 and 4–1 are isochoric processes; heat is transferred into the system from 2—3 and out of the system from 4—1 but no work is done on the system or extracted from the system during those processes.
P-V Diagram for Otto cycle has been plotted and the thermal efficiency of the engine is observed to be 0.6298 i.e.62.98%.