Air standard Cycle: otto cycle
Objective:
1. To write a code that can solve an otto cycle and to make plots for it.
2. To create a PV diagram
3. To output the thermal efficiency of the engine.
Otto cycle :
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
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).
Thermal efficiency is the quotient of the net work from the system, to the heat added to system.
The equation of thermal efficiency:

Code:
'''
otto cycle simulator
'''
import math
import matplotlib.pyplot as plt
#inputs
p1 = 101325
t1 = 500
gamma = 1.4
t3 = 2300
#geometric parameters
cr = 12
bore = 0.1
stroke = 0.1
con_rad = 0.15
a= stroke/2
R = con_rad/a
# volumetric calculations
v_s = (math.pi)*pow(bore,2)*stroke/4
v_c = v_s/(cr-1)
v1 = v_s+v_c
def engine_kinematics(bore,stroke,con_rad,cr,start_crank,end_crank):
a= stroke/2
R = con_rad/a
# volumetric calculations
v_s = (math.pi)*pow(bore,2)*stroke/4
v_c = v_s/(cr-1)
sc = math.radians(start_crank)
ed = math.radians(end_crank)
n_values = 50
d_theta = (ed-sc)/(n_values-1)
v =[]
for i in range(0,50):
theta = sc + i*d_theta
term1 = cr-1
term2 = R+1-math.cos(theta)
term3 = pow(pow(R,2)-pow(math.sin(theta),2),0.5)
v.append(v_c*(1+(0.5*term1*(term2-term3))))
return v
#state point 2
v2= v_c
p2 = p1*pow(v1,gamma)/pow(v2,gamma)
v_compression = engine_kinematics(bore,stroke,con_rad,cr,180,0)
#p*v^gamma = constant
constant = p1*pow(v1,gamma)
p_compression = []
for v in v_compression:
p_compression.append(constant/pow(v,gamma))
# pv/t = constant2
constant2 = p1*v1/t1
#t2 = p2*v2/constant2
# state point 3
v3 = v2
# pv/t = constant
p3 = constant2*t3/v3
# state point 4
v4 = v1
# pv^r =constant
p4 = p3*pow(v3,gamma)/pow(v4,gamma)
# pv/t = constant
t4 = p4*v4/constant2
v_expansion = engine_kinematics(bore,stroke,con_rad,cr,0,180)
#p*v^gamma = constant
constant = p3*pow(v3,gamma)
p_expansion = []
for v in v_expansion:
p_expansion.append(constant/pow(v,gamma))
Thermal_efficiency = (1-(1/pow(cr,gamma-1)))*100
print(Thermal_efficiency)
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.show()
Function:
import math
import matplotlib.pyplot as plt
def v = engine kinematics(bore,stroke,con_rad,cr,start_crank,end_crank):
#inputs
p1 = 101325
t1 = 500
gamma = 1.4
t3 = 2300
#geometric parameters
cr = 12
bore = 0.1
stroke = 0.1
con_rad = 0.15
a= stroke/2
R = con_rad/a
# volumetric calculations
v_s = (math.pi)*pow(bore,2)*stroke/4
v_c = v_s/(cr-1)
theta = math.radians(0)
term1 = cr-1
term2 = R+1-math.cos(theta)
term3 = pow(pow(R,2)-pow(math.sin(theta),2),0.5)
v = v_c*(1+(0.5*term1*(term2-term3)))
Output: