Week 2 Air standard Cycle
AIM
To write a code that can solve an otto cycle and make plots for it and also to find thermal efficiency of the given cycle.
INITIAL STUDY
An Otto cycle is an idealized thermodynamic 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. By describing the changes that take place within the system, it will also describe in inverse, the system's effect on the environment. 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 Otto cycle is constructed from:
Top and bottom of the loop: a pair of quasi-parallel and isentropic processes (frictionless, adiabatic reversible).
Left and right sides of the loop: a pair of parallel isochoric processes (constant volume).
figure 1:P V Diagram of otto cycle
The processes are described by:
- Process 0–1 a mass of air is drawn into piston/cylinder arrangement at constant pressure.
- Process 1–2 is an adiabatic (isentropic) compression of the charge as the piston moves from bottom dead center(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 adiabatic (isentropic) expansion (power stroke).
- 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 released to the atmosphere in a constant pressure process
GOVERNING EQUATION
isentropic equation:

Ideal gas equation:
PV=nRT
P=pressure
V=volume
R=Universal gas constant
T=temperature
n=no of moles
Formula connecting volume and theta:

Vc=clearance volume
cr=compression ratio
Thermal efficiency:
CR=compression ratio K=adiabatic index
T1,T2,T3,T4 are the temperatures at the respective states
PROGRAM CODE
#PROGRAM TO CREATE P V DIAGRAM OF AIR STANDARD OTTO CYCLE AND FIND ITS THERMAL EFFICIENCY
#CREATED BY LAKSHMI RAJAN P
#import the necessary modules for running the program,math to do the mathematical calculations and matplotlib to plot the pv diagram
import math
import matplotlib.pyplot as plt
#Defining a function to recieve the volume values using the formula
#V/v_c=1+0.5(cr-1)[R+1-cos(theta)-(R^2-sin^2(theta))^0.5]
#This function is carried out to get the values of volume during the isentropic compression and isentropic expansion
def engine_kinematics(bore, stroke, con_rod, cr, start_crank, end_crank):
#crank pin radius is denoted by a
a = stroke / 2
R = con_rod / a
#swept volume is denoted by v_s and clearance volume as v_c
v_s = (math.pi / 4) * pow(bore, 2) * stroke
v_c = v_s / (cr - 1)
#start crank angle and the end crank angle obtained is converted to radians by command below
sc = math.radians(start_crank)
ec = math.radians(end_crank)
numvalues = 50
dtheta = (ec - sc) / (numvalues - 1)
V = []
for i in range(0, numvalues):
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)
# Inputs
# Pressure
p1 = 101325
# Temperature
t1 = 500
gamma = 1.4
t3 = 2300
# Geometry
cr = 8
stroke = 0.1
bore = 0.10
con_rod = 0.15
# Volume calculation
v_s = (math.pi / 4) * pow(bore, 2) * stroke
v_c = v_s / (cr - 1)
v1 = v_s + v_c
#state point 2
v2 = v_c
# p2v2 ^ gamma = p1v1^gamma
p2 = (p1 * pow(v1, gamma)) / pow(v2, gamma)
# Temperature
# p1v1/t1 = p2v2/t2
rhs = (p1 * v1) / t1
t2 = (p2 * v2) / rhs
#calling function
v_compression = engine_kinematics(bore, stroke, con_rod, cr, 180, 0)
p_compression = []
constant = p1 * pow(v1, gamma)
for v in v_compression:
p_compression.append(constant / pow(v, gamma))
# State point 3
v3 = v2
# p3v3/T3 = p2v2/T2
rhs = p2 * v2 / t2
p3 = rhs * (t3 / v3)
#state point 4
v4 = v1
# p4v4^gamma = p3v4^gamma
rhs = p3 * pow(v3, gamma)
p4 = rhs / pow(v4, gamma)
# p4v4/T4 = p3v3/T3
rhs = p3 * v3 / t3
t4 = (p4 * v4) / rhs
#calling function
v_expansion = engine_kinematics(bore, stroke, con_rod, cr, 0, 180)
p_expansion = []
constant = p3 * pow(v3, gamma)
for v in v_expansion:
p_expansion.append(constant / pow(v, gamma))
#Computing thermal efficiency
# We can also use:
# eta_thermal = 1 - 1/(pow(cr,gamma-1))
eta_thermal=1-(t4-t1)/(t3-t2)
print("The thermal efficiency of otto cycle is =",round(eta_thermal*100,2 )," % ")
#plotting the required pv diagram of Air standard otto cycle
plt.figure("Otto cyce",figsize=(10,5))
plt.plot([v1,v2,v3,v4,v1],[p1,p2,p3,p4,p1],'.',c='r')
plt.plot([v2, v3], [p2, p3],'-',c='g')
plt.plot(v_compression, p_compression,'-',c='y')
plt.plot(v_expansion, p_expansion,'-',c='r')
plt.plot([v4, v1], [p4, p1],'-',c='b')
plt.xlabel("Volume [m^3]")
plt.ylabel("Pressure [Pa]")
plt.text(0.000897,1.2e+05,r'$ 1 $')
plt.text(0.000111,1.87e+06,r'$ 2 $')
plt.text(0.000112,3.75e+06,r'$ 3 $')
plt.text(0.000898,2.1e+05,r'$ 4 $')
plt.text(0.000208,2.4e+05,r'$ isentropic compression $')
plt.text(0.000266,1.43e+06,r'$ isentropic expansion $')
plt.text(0.000911,1.7e+05,r'$ isochoric heat rej. $')
plt.text(0.000118,2.78e+06,r'$ isochoric heat addition. $')
plt.title("P-V Diagram for Air standard Otto cycle")
plt.show()
PROCEDURE
1)First of we have to import the required modules necessary for running the program,ie., matplolib to plot the diagram and math module to perform the mathematical calculations.
2)We define the statepoints for each states and the required thermodynamic relations were formed.But these relations follows a linear relationship and thus the isentropic compression and expansion areas are not plotted well.
3)So we define a function called engine_kinematics to calculate volume values during isentropic compression and isentropic expansion.This volume values are found by following the formula mentioned in the governing equations.This volume values are now stored to an empty array and is then used to find the pressure values.
4)Provide the initial values and the values of the constants as given.
5)Now use the thermal efficiency equation mentioned in the governing equations to find the thermal efficiency of the air standard otto cycle.
6)The values are plotted using matplotlib plot command.
OUTPUT
The thermal efficiency of otto cycle is = 56.47 %
[Finished in 6.8s]

figure 2:PLOT OBTAINED