Air standard Cycle using Python
Aim
The aim of this program is to plot a P-V diagram for an otto cylce with given state parameters and engine design parameters and to find the efficiency of this cycle.
Formulae
- `(P*V)/T=CONSTANT`
- `P*V^(gamma)=CONSTANT`
- `V=V_c*(1+1/2*(r-1)*[R+1-costheta-(R^2-(sintheta)^2)^(1/2)])`
- `V_s=(pi)/4*(BORE)^2*stroke`
- `V_c=(V_s)/(r-1)`
- `eta=1-1/(r)^(gamma-1)`
Program
In this program the engine design parameters(bore, stroke, connecting rod) are assumed and constant. The compression ratio(r) of the cycle is 8. The swept volume(Vs) and clearance volume(Vc) are calculated using formulas 4 and 5 given above.
The sum of swept volume and clearance volume corresponds to the volume at state 1(v1) and the clearance volume corresponds to volume at state 2(v2) in the cylce. The pressure and temperature at state 1(p1 and t1) and temperature at state 3(t3) are given. Using formulas 1 and 2 given above, the pressure volume and temperature at each state(1 to 4) are calculated.
A function 'volume_variation' is created to calculate how the volume changes in the isentropic compression(1->2) and expansion(3->4) processes. In this function the variation in volume for given start and end crank angles is calculated using formula 3 given above. This array is returned to the main code. With the variation of volume, the variation in pressure can be caluclated and is then plotted to get the P-V diagram of an otto cycle.
The efficiency of the cycle is calculated using formula 6 and is equal to 56.47% for a bore=0.1m, stroke=0.1m,connecting rod length=0.15m,compression ratio=8,gamma=1.4,p1=101325 Pa, t1=500K and t3=2300K.
Results
The result of this program is that an otto cycle can be solved using this program and the corresponding P-V diagram can be plotted along with the efficiency of the cycle.
Code
import math
import matplotlib.pyplot as plt
import numpy as np
#function to calculate the variation in volume in the isentropic compression and expansion processes
def volume_variation(v_c,stroke,con_rod,r,start_angle,end_angle):
num=50
theta=np.linspace(math.radians(start_angle),math.radians(end_angle),num)
a=stroke/2
R=con_rod/a
V=[]
for i in theta:
term1=0.5*(r-1)
term2=R+1-math.cos(i)
term3=pow(pow(R,2)-pow(math.sin(i),2),0.5)
V.append(v_c*(1+term1*(term2-term3)))
return V
#inputs
p1=101325
t1=500
gamma=1.4
t3=2300
#engine parameters
bore=0.1
stroke=0.1
con_rod=0.15
r=8 #compression ratio
v_s=math.pi/4*pow(bore,2)*stroke
v_c=v_s/(r-1)
#state 1
v1=v_s+v_c
#state 2
v2=v_c
p2=p1*pow(r,gamma)
t2=t1*pow(r,gamma-1)
# volume an dpressure values during the isentropic compression process
v_compression=volume_variation(v_c,stroke,con_rod,r,180,0)
const=p1*pow(v1,gamma)
p_compression=[]
for v in v_compression:
p_compression.append(const/pow(v,gamma))
#state 3
v3=v2
p3=p2*t3/t2
#state 4
v4=v1
p4=p3*pow(1/r,gamma)
t4=p4*t3/p3
# volume and pressure values during the isentropic expansion process
v_expansion=volume_variation(v_c,stroke,con_rod,r,0,180)
const=p3*pow(v3,gamma)
p_expansion=[]
for v in v_expansion:
p_expansion.append(const/pow(v,gamma))
#plotting otto cycle
plt.plot(v_compression,p_compression,color="black")
plt.plot([v2,v3],[p2,p3],color="black")
plt.plot(v_expansion,p_expansion,color="black")
plt.plot([v4,v1],[p4,p1],color="black")
plt.plot(v1,p1,'ro',markersize=5)
plt.text(v1,p1,'1')
plt.plot(v2,p2,'ro',markersize=5)
plt.text(v2,p2,'2')
plt.plot(v3,p3,'ro',markersize=5)
plt.text(v3,p3,'3')
plt.plot(v4,p4,'ro',markersize=5)
plt.text(v4,p4,'4')
plt.xlabel("Volume(m^3)")
plt.ylabel("Pressure(Pa)")
plt.title("Otto cycle")
plt.legend(['1-2 isentropic compression','2-3 constant volume heat addition','3-4 isentropic expansion','4-1 constant volume heat rejection'])
plt.show()
efficiency=1-1/pow(r,gamma-1)
print(f"Efficiency {efficiency*100}%")