Week 2 Air standard Cycle
Aim: Write a code that can solve a otto cycle and plot of it
Objectives:
- To write a basic code to solve Air standard cycle.
- To find out an efficiency of Air standard cycle and with trial and error method optimize engine efficiency.
- To plot a results obtained to visualize actual scenario.
Introduction:
An Otto cycle is an idealized thermodynamic cycle that describes the functioning of a typical spark ignition piston engine.

Process:
- Process 0–1 a mass of air is drawn into piston/cylinder arrangement at constant pressure.
- Process 1–2 is an isentropic compression of the charge as the piston moves from bottom dead centre (BDC) to top dead center (TDC).
- Process 2–3 is a constant-volume heat transfer to the working gas from an external source while the piston is at top dead center. This process is intended to represent the ignition of the fuel-air mixture and the subsequent rapid burning.
- Process 3–4 is an isentropic expansion.
- Process 4–1 completes the cycle by a constant-volume process in which heat is rejected from the air while the piston is at bottom dead center.
- Process 1–0 the mass of air is exhausted to the atmosphere in a constant pressure process.
Required formulae:
Swept volume:
Vs = n*(pi/4)*(bore)^2*stroke
where,
n= no of cylinder
Vc= cylinder swept volume [cm3 (cc)]
BDC = Bottom Dead Center TDC = Top Dead Center
Clearance volume:
Vc= Vs/(Cr-1)
V1 = Vs+ Vc
V2 = Vc
where,
Cr=compression ratio
Compression ratio:
Cr=(Vs+ Vc)/ Vc
Isentropic proccess:
P*V^γ= constant
Ideal gas equation:
PV=mRT
Efficiency:
η=(Cr-1)/Cr
Code:
import math
import matplotlib.pyplot as plt
import numpy as np
# geometric parameters
bore = 0.088
stroke = 0.083
cr = 14
con_rod = 0.14
gamma = 1.4
# inputs
p1 = 101325
t1 = 500
t3 = 2500
# swept and clearance volume
v_swp = math.pi/4 * pow(bore, 2) * stroke
v_clr = v_swp / (cr - 1)
v1 = v_swp + v_clr
# function to calculate volume at compression and volume at expansion during isentropic process
def engine_kinematics(bore, stroke, cr, con_rod, v_swp, v_clr, start_crank, end_crank):
"""
engine kinematics
"""
a = stroke / 2 # crank pin length
R = con_rod / a # constant
n = 50
theta = np.linspace(start_crank, end_crank, n)
V = []
for THETA in theta:
term1 = 0.5 * (cr - 1)
term2 = R + 1 - math.cos(math.radians(THETA))
term3 = pow((pow(R, 2) - pow(math.sin(math.radians(THETA)), 2)), 0.5)
V.append((1 + term1 * (term2 - term3)) * v_clr)
return V
# calling the function
# To calculate the pressure and volume during compression
V_comp = engine_kinematics(bore, stroke, cr, con_rod, v_swp, v_clr, 180, 0)
constant = p1 * pow(v1, gamma)
p_comp = [constant / pow(vol, gamma) for vol in V_comp]
# compression stroke
v2 = v_clr
# for isentropic process p2 * v2^gamma = p1 * v1^gamma
rhs = p1 * pow(v1, gamma)
p2 = rhs / pow(v2, gamma)
# we will use the ideal gas law to calculate the value of t2: p1 * v1 / t1 = p2 * v2 / t2
lhs = p1 * v1 / t1
t2 = p2 * v2 / lhs
# expansion stroke
# since the process here is constant volume
v3 = v2
# the temperature after the combustion of fuel is around 2500 K
# the ideal gas equation to find pressure can be given by: p2 * v2 / t2 = p3 * v3 / t3
rhs = p2 * v2 / t2
p3 = rhs * t3 / v3
# calling the function
# To calculate the pressure and volume during expansion
V_exp = engine_kinematics(bore, stroke, cr, con_rod, v_swp, v_clr, 0, 180)
constant = p3 * pow(v3, gamma)
p_exp = [constant / pow(vol, gamma) for vol in V_exp]
# suction stroke
v4 = v1
# the equation for isentropic process is given as: p3 * v3^gamma = p4 * v4^gamma
rhs = p3 * pow(v3, gamma)
p4 = rhs / pow(v4, gamma)
# efficiency
eta = 1 - (t1 / t2)
print('efficiency =', eta * 100, '%')
# plotting
plt.figure()
plt.plot([v2, v3], [p2, p3])
plt.plot(V_comp, p_comp)
plt.plot(V_exp, p_exp)
plt.plot([v4, v1], [p4, p1])
plt.xlabel('volume')
plt.ylabel('pressure')
plt.title('P-V diagram of Otto cycle')
plt.savefig('P-V diagram.png')
plt.savefig('Otto Cycles')
plt.show()
Explanation of this Code:
- Define inputs such as initial temperature, atmospheric pressure, gamma and combustion temperature.
- Calculate the compression stroke pressure, which is an isentropic process with the equation PV^gamma = constant. And calculate the unknown temperature using the ideal gas equation PV=mRT.
- For the compression and expansion phases, we have a formula to calculate the volume during compression and expansion. create a function to calculate the values.
- Call the function and calculate the compression pressure and expansion pressure values.
- After getting all the values using the plot command, we should plot all four phases.
- Finally, calculate the efficiency of the processes using the formula = 1 - (t2/t1).
Plot:

Thermal Efficeiency:

Conclusion:
The temperature and pressure of the otto cycle increases during compression process and decreases during expansion process.
File Link:
https://drive.google.com/drive/folders/1YdnfQ9bYSp3dUYK7wKwhcxUdwQLxpfSb?usp=drive_link