Simulation of Otto cycle
The project is to write a python code which solves an Otto cycle problem, calculates the efficiency and makes a p-v diagram plot for it.
I have chosen a problem which has the pressure p1 = 0.1 Mpa, temperature t1 = 300K, t3 = 2800K, volume v1 = 0.5 m^3, compression ratio r = 8 and isentropic expansion factor gamma γ = 1.4 as the inputs for the problem. With the given inputs i had solved the problem to find p2,v2,t2,p3,v3,p4,v4 and the overall efficiency η.
The problem is solved by considering the equations for the particular processes,
1-2 isentropic expansion PV^γ = constant
2-3 constant volume heat addition V2=V3
3-4 isentropic compression PV^γ = constant
4-1 constant volume heat rejection V4=V1
Thus the efficiency calculated using the formula η = 1 - 1/(r^(γ-1)).
The P-V diagram is plotted using the appropriate pressure and volume values.
#simulation of otto cycle
import math
import matplotlib.pyplot as plt
#pressure p1 in Megapascal
p1 = 0.1
#compression ratio
r = 8
#temperature t1 in kelvin
t1 = 300
#temperature t3 in kelvin
t3 = 2800
#volume v1 in m^3
v1 = 0.5
#gas constant
g = 1.4
#v2
v2 = v1/r
n=10
volume = []
pressure = []
for i in range(0,n):
tmp = v1 -i*((v1 -v2)/(n-1))
volume.append(tmp)
pressure.append(p1*(v1/tmp)**g)
#p2
p2 = p1*r**g
#t2
t2 = r**(g-1)*t1
#p3
p3 = (t3/t2)*p2
#v3
v3 = v2
#v4
v4 = v1
volume1 = []
pressure1 = []
for i in range(0,n):
tmp1 = v3 + i*(v4-v3)/(n-1)
volume1.append(tmp1)
pressure1.append(p3*(v3/tmp1)**g)
#p4
p4 = r**-g*p3
efficiency = 1-(1/r**(g-1))
efficiency = efficiency * 100
print ('p2 =',p2,'v2 =', v2, 'p3 =', p3, 'v3 =',v3,'p4 =',p4,'v4 =', v4)
print('thermal efficiency =', efficiency)
plt.figure()
plt.plot(volume,pressure)
plt.plot([v2,v3],[p2,p3])
plt.plot(volume1, pressure1)
plt.plot([v4,v1],[p4,p1])
plt.xlabel('volume')
plt.ylabel('pressure')
plt.show()
The pressure, volume and the efficiency are printed as output of the program.
p2 = 1.8379173679952558 v2 = 0.0625 p3 = 7.466666666666668 v3 = 0.0625 p4 = 0.4062569295381914 v4 = 0.5
thermal efficiency = 56.472471835193794
[Finished in 8.2s]
The plot of the P-V diagram is shown below in the Image below.