Week 2 Air standard Cycle
AIM: To create a PV diagram and display the thermal efficiency of the engine working in otto cycle using Python.
METHODOLOGY:
Otto Cycle
Used in SI engines. The four-stroke Otto cycle is made up of the following four reversible processes:
1–2, Isentropic compression
2–3, constant-volume heat addition
3–4,Isentropic Expansion
4–1, constant-volume heat rejection.

Equation to calcuate the Combustion chamber volume for a given crank angle:
`V=V_c*{1+1/2*(r_c-1)*[R+1-costheta-(R^2-sin^2theta)^(1/2)]}`
Thermal efficiency of Otto Cycle `η_(th) = 1-1/(r)^(gamma-1)`
r - compression ratio
gamma - specific heat ratio
PYTHON CODE
# PV Diagram - Otto Cycle
import math
import matplotlib.pyplot as plt
# define function
def Engine_kinematics(bore,stroke,con_rod,cr,start_crank,end_crank):
# Input Parameters
a = 0.5*stroke # crank pin radius
R = con_rod/a # slenderness Ratio
v_s = math.pi*pow(bore,2)*stroke/4 #Stroke volume
v_c = v_s/(cr-1) # Compression Volume
sc = math.radians(start_crank)
ec = math.radians(end_crank)
num_theta = 100
dtheta = (ec-sc)/(num_theta-1) # note that the start and end values by default are among the 100
V = []
for i in range(0,num_theta):
term1 = 0.5*(cr-1)
term2 = R + 1 - math.cos(sc+i*dtheta)
term3 = pow(pow(R,2) - pow(math.sin(sc+i*dtheta),2),1/2)
V.append(v_c*(1+term1*(term2-term3)))
return V
# Inputs
p1 = 101325
t1 = 500
t3 = 2300
gamma = 1.4
bore = 0.1
stroke = 0.1
con_rod = 0.15
cr = 12
v_s = (math.pi)*pow(bore,2)*stroke/4
v_c = v_s/(cr-1)
v1 = v_s+v_c
# State point 2. 1-2 Isentropic compression
v2 = v_c
p2 = p1*pow(cr,gamma)
t2 = t1*pow(cr,gamma-1)
# State point 3
v3 = v2
p3 = (p2*v2/t2)*(t3/v3)
# State point 4. 3-4 Isentropic expansion
v4 = v1
p4 = p3*pow(1/cr,gamma)
t4 = t3*pow(1/cr,gamma-1)
# Compression stroke- caling the function Engine_kinematics
V_compression = Engine_kinematics(bore,stroke,con_rod,cr,180,0)
V_expansion = Engine_kinematics(bore,stroke,con_rod,cr,0,180)
P_compression = []
for i in range(0,len(V_compression)):
P_compression.append(p1*pow(v1,gamma)/pow(V_compression[i],gamma))
P_expansion = []
for i in range(0,len(V_expansion)):
P_expansion.append(p3*(pow(v3,gamma)/pow(V_expansion[i],gamma)))
thermalefficiency = 1-(1/pow(cr,gamma-1))
print('The thermal efficiency of the engine with compression ratio',cr,'is',thermalefficiency*100,'%')
plt.plot(v1,p1,'o')
plt.plot(v2,p2,'o')
plt.plot(v3,p3,'o')
plt.plot(v4,p4,'o')
plt.plot([v2,v3],[p2,p3])
plt.plot([v4,v1],[p4,p1])
plt.plot(V_compression,P_compression)
plt.plot(V_expansion,P_expansion)
plt.xlabel('Volume in m^3')
plt.ylabel('Pressure in Pascal')
plt.title('P-V diagram')
plt.show()
PLOT

CONCLUSION: The program to Calucate Thermal Efficiency and plot PV diagram for a given Otto Cycle is developed and executed successfully.