Otto Cycle simulator using Python
Aim: A python program to simulate the Otto Cycle
Otto cycle is also termed as a constant volume power cycle. It contains a pair of isentropic processes and a pair of isochoric processes. This cycle basically used for spark ignition engines.
As shown in figure red and green lines indicate the isentropic compression and expansion respectively and blue and black lines indicate the constant volume heat addition.
The Otto cycle contains 4 state processes:-
- Process 1-2 Isentropic compression
- Process 2-3 constant volume heat addition
- Process 3-4 isentropic expansion
- Process 4-1 constant volume heat rejection
The arrangement of piston, cylinder, and crank are as follows.
Process 1–2 Compression stroke
Piston moves from crank end (BDC, bottom dead centre and maximum volume) to cylinder head end (TDC, top dead centre and minimum volume) as the working gas with initial state 1 is compressed isentropically to state point 2, through compression volume (V1/V2). Mechanically this is the isentropic compression of the air/fuel mixture in the cylinder, also known as the compression stroke. This isentropic process assumes that no mechanical energy is lost due to friction and no heat is transferred to or from the gas, hence the process is reversible. The compression process requires that mechanical work be added to the working gas. Generally the compression ratio is around 9–10:1 (V1:V2) for a typical engine.
Process 2–3 Combustion stroke
The piston is momentarily at rest at TDC. During this instant, which is known as the ignition phase, the air/fuel mixture remains in a small volume at the top of the compression stroke. Heat is added to the working fluid by the combustion of the injected fuel, with the volume essentially being held constant. The pressure rises and the ratio (P3/P2.) is called the "explosion ratio".
Process 3–4 expansion stroke
The increased high pressure exerts a force on the piston and pushes it towards the BDC. Expansion of working fluid takes place isentropically and work is done by the system on the piston. The volume ratio V4/V3 is called the "isentropic expansion ratio". (For the Otto cycle is the same as the compression ratio V1/V2.) Mechanically this is the expansion of the hot gaseous mixture in the cylinder known as expansion (power) stroke.
Process 4–1 idealized heat rejection
The piston is momentarily at rest at BDC. The working gas pressure drops instantaneously from point 4 to point 1 during a constant volume process as heat is removed to an idealized external sink that is brought into contact with the cylinder head. In modern internal combustion engines, the heat-sink may be surrounding air (for low powered engines), or a circulating fluid, such as coolant. The gas has returned to state 1.
The Python Program to calculate the state point is otto cycle to plot the P_V diagram and to find the thermal efficiency of the cycle.
"""
A program on Otto cycle simulation
By Rupesh
"""
# importing the required libraries
import math
import matplotlib.pyplot as plt
def engine_kinematics(Bore, stroke, con_rod, cr, start_crank, end_crank):
#Geometric parameters
a = stroke/2 # Crank pin radius
R = con_rod/a # constant
#Volume computation
V_s = (math.pi/4)*pow(Bore,2)*stroke # swept volume
V_c = V_s/(cr-1) # clearance volume
sc = math.radians(start_crank)
ec = math.radians(end_crank)
num_values = 50
dtheta = (ec-sc)/(num_values-1)
V = []
for i in range(0,num_values):
theta = sc + i*dtheta
term1 = 0.5*(cr-1)
term2 = R+1-math.cos(theta)
term3 = pow(R,2)-pow(math.sin(theta),2)
term3 = pow(term3,0.5)
V.append ((1+term1*(term2-term3))*V_c)
return V
# inputing the initial parameters
P1 = 0.1 # pressure at state-1
t1 = 500 # temperature at state-1
gamma = 1.4
t3 = 2300
#geometric parameters
Bore = 0.10
stroke = 0.1
con_rod = 0.15
cr = 12
#Volume computation
V_s = (math.pi/4)*pow(Bore,2)*stroke # swept volume
V_c = V_s/(cr-1) # clearance volume
V1 = V_c + V_s
# at state point-2
V2 = V_c
# P2V2^gamma = P1V1^gamma
P2 = P1*pow(V1,gamma)/pow(V2,gamma)
# P2V2/t2 = P1V1/t1 | rhs = P1V1/t1 | P2V2/t2 = rhs | t2 = P2V2/rhs
rhs = P1*V1/t1
t2 = P2*V2/rhs
V_compression = engine_kinematics(Bore,stroke,con_rod,cr,180,0)
constant = P1*pow(V1,gamma)
P_compression = []
for V in V_compression:
P_compression.append(constant/pow(V,gamma))
# at state point 3
V3 = V2
# P3V3/t3 = P2V2/t2 | rhs = P2V2/t2 | P2 = rhs*t3/V3
rhs = P2*V2/t2
P3 = rhs*t3/V3
V_expansion = engine_kinematics(Bore,stroke,con_rod,cr,0,180)
constant = P3*pow(V3,gamma)
P_expansion = []
for V in V_expansion:
P_expansion.append(constant/pow(V,gamma))
# at state point 4
V4 = V1
# P4V4^gamma=P3V3^gamma
P4 = P3*pow(V3,gamma)/pow(V4,gamma)
# P4V4/t4 = rhs
t4 = P4*V4/rhs
#Thermal efficiency of the Otto cycle
#thermal efficiency is referred as Ther_eff
Ther_eff = (1 - ((t4-t1)/(t3-t2)))*100
print(Ther_eff)
#plotting the P_V diagram from otto cycle
plt.grid()
plt.plot([V2,V3],[P2,P3])
plt.plot(V_compression,P_compression)
plt.plot(V_expansion,P_expansion)
plt.plot([V4,V1],[P4,P1])
plt.xlabel('Volume')
plt.ylabel('Pressure')
plt.title('Otto cycle')
plt.show()
The thermal efficiency obtained from the programm for the compression ratio 12 is 62.989%
The P_V Diagram obtained as below.