PV diagram of Otto Cycle using Python
Objective: To write a program to plot the PV diagram of an otto cycle.
Program:
#otto cycle
import math
import matplotlib.pyplot as plt
import numpy as np
P1 = 101325 #presure at stage 1
T1 = 500 #temperature at stage 1
T3 = 2500 #temperature after combustion (stage 3)
G = 1.4 #heat capacity ratio (gamma)
D = 0.1 #bore diameter
L = 0.2 #stroke length
C = 0.15 #connecting rod length
CR = 12 #compression ratio
Vs = (math.pi*D*D*L)/4 #swept volume
Vc = Vs/(CR-1) #clearance volume
def crank_angle(start_angle,end_angle): #function for volume points on isentropic curve for given crank angles
Sa = math.radians(start_angle)
Ea = math.radians(end_angle)
theta = np.linspace (Sa,Ea,50)
V = []
for i in theta:
X1 = 0.5*(CR-1)
X2 = (2*C/L)+ 1 - math.cos(i)
X3 = pow((2*C)/L,2)-pow(math.sin(i),2)
X4 = pow(X3,0.5)
Z = Vc*(1+X1*(X2-X4))
V.append(Z)
return V
V1 = Vs+Vc #stage 1
V2 = Vc #stage 2
P2 = (P1*pow(V1,G))/pow(V2,G)
k = (P1*V1)/T1
T2 = (P2*V2)/k
V3 = V2 #stage 3
P3 = (k*T3)/V3
V4 = V1 #stage 4
P4 = (P3*pow(V3,G))/pow(V4,G)
T4 = (P4*V4)/k
V_comp = crank_angle(180,0) #isentropic compression curve points
P_comp = []
for v in V_comp:
x = (P1*pow(V1,G))/pow(v,G)
P_comp.append(x)
V_exp = crank_angle(0,180) #isentropic exoansion curve points
P_exp = []
for v in V_exp:
y = (P3*pow(V3,G))/pow(v,G)
P_exp.append(y)
plt.plot([V2,V3],[P2,P3])
plt.plot([V4,V1],[P4,P1])
plt.plot(V_comp,P_comp)
plt.plot(V_exp,P_exp)
plt.show()
N = (1 - (T4-T1)/(T3-T2))*100 # efficiency of otto cycle
print(\'The efficiency is \'+str(N))
Procedure:
- math, matplotlib.pyplot and numpy modules were imported for using mathematical functions, plotting and using linspace command respectively.
- The inputs given for the program are as follows:
- Pressure at stage 1 (P1) = 1 bar
- Temperature at stage 1 (T1) = 500K
- Temperature after combustion (T3) = 2500K
- Heat capacity ratio (`gamma`) = 1.4
- Bore diameter (D) = 0.1 m
- Stroke length (L) = 0.2 m
- Connecting rod length (C) = 0.15 m
- Compression ratio (CR) = 12
- Swept and clearnce volumes were calculated by the following formula:
- `Vs = (pi*D^2*L)/4`
- `Vc = V_s/(CR-1)`
- The values of volume, pressure and temperaure were calculated at the 4 stages of the otto cycle by using the ideal gas equation `(P.V )/T =`constant.
- For plotting the points on the isentropic expansion and compression curves a function was created with the start and end crank angles as the input. The range between the crank angles was split in 50 parts for a smooth curve. This angle was used as the input in the formula `V /V_c = 1+0.5(CR-1)[R+1-costheta-(R^2-sin^2theta)]^(1/2)` where `R= (2*C)/L`, to find the value of volume. These values were stored in a volume array.
- To calculate the volume values the function was called with input angles 180 to 0 (BDC to TDC) for the compression process and 0 to 180 for the expansion process. A loop was created to input the values from volume array and form the corresponding pressure array using the formula `P*V^gamma =`constant.
- The calculated values of 4 stages of the otto cycle and the isentropic curves were plotted.
- Efficiency was calculated using the formula `eta = (1 - (T4-T1)/(T3-T2))*100`
Results:
- The P-V diagram of the otto cycle with the given inputs was created as shown in the figure below.
- The efficiency value for the given inputs was found to be 62.99%.