PYTHON - Project - 1 Otto Cycle Simulator
OTTO CYCLE – SIMULATOR USING PYTHON
OBJECTIVE:
Otto cycle is a basic engine cycle which added heat at constant volume. Using python here program develops an Otto cycle and plots a P-V Diagram with obtained results.
PROBLEM STATEMENT:
Using thermodynamic properties, an Otto cycle is representing the engine works. It will develop a report consist of pressure, volume, andtemperature. With some state points and thermodynamic relations, the otto cycle can be defined. Solutions are given below.
THERMODYNAMIC OPERATIONS:
Process 0: Intake of atmospheric air at constant pressure.
Process 1: Isentropic compression (Compression of gases in relation
P*V^GAMMA=Constant)
Process 2: Isochoric, (Heat addition in a constant volume).
Process 3: Isentropic expansion, Power stroke (P*V^GAMMA=Constant).
Process 4: Constant volume of heat rejection.
Process 5: Exhaust gases at constant pressure.
PROGRAM:
The program did in python, steps involved in python given below.
Initial values assigned.
Using the formula of thermodynamics other state variables are defined
Volume values for compression and expansion defined by a formulawhich added as a function.
It's separated by crank angles
Finally, values are plotted using matplotlib.pyplot
Efficiency displayed using “print()” command
PYTHON CODE :
import math
import numpy as np
import matplotlib.pyplot as plt
#Function to find Volume respect to cranck angle
def V(Con_Rod,s,r,V_Clr,theta):
Vq=[]
a=s/2
R=Con_Rod/a
A1=(r-1)/2
for i in theta:
A2=R+1-math.cos(i)
A3_1=pow(R,2)-pow(math.sin(i),2)
A3=pow(A3_1,0.5)
V_1=1+A1*(A2-A3)
V_2=V_1*V_Clr #Volume value calculated
Vq.append(V_2) #Create matrix for volume
return(Vq) #Return value
#Initilaize constant
G=1.4 #Gamma value
b=0.1 #Bore
s=0.1 #Stroke
Con_Rod=0.15 #Connecting rod length
r=12 #Compression ratio
pi=math.pi
V_Swept=(pi/4)*s*pow(b,2) #Swept volume
V_Clr=V_Swept/(r-1) #Clearance volume
#State point 1 Pressure,Volume=Swept volume + Clearance Volume,Temperature
P1=101325
V1=V_Swept+V_Clr
T1=500
#State point 2 Isentropic process PV*V= Constant
P2=P1*pow(r,G)
V2=V_Clr
T2=(P2*V2*T1)/(P1*V1)
#State point 3 Isochoric process (Constant Volume)
V3=V2
T3=2300
P3=(P2*T3)/T2
#State point 4
V4=V1
P4=P3*pow((V3/V4),G)
#Efficiency
Temp4=pow((r),(G-1)); #Temporary value
Eff=1-(1/Temp4) #Efficiency calculation
print('Thermal Efficiency:',Eff*100,'Percentage') #display value
#Compression curve
theta=np.linspace(0,pi,180) #Create angle between 0 to 180
V_Comp=V(Con_Rod,s,r,V_Clr,theta) #Function creates volume values with respect to crank angle
c1=P1*pow(V1,G); #Find constant for isentropic PV^c= Constant
P_Comp=[] #Initiate null matrix
for i in V_Comp: #Loop for Volume values
Temp=c1/pow(i,G) #Temperory value of pressure with respect to volume
P_Comp.append(Temp) #Pressure for compression saved in matrix
plt.plot(V_Comp,P_Comp,'r') #Plot compression
#Expansion curve
theta=np.linspace(pi,2*pi,180) #Create angle between 0 to 180
V_Expan=V(Con_Rod,s,r,V_Clr,theta) #Function creates volume values with respect to crank angle
c2=P3*pow(V3,G); #Find constant for isentropic PV^c= Constant
P_Expan=[] #Initiate null matrix
for j in V_Expan: #Loop for Volume values
Temp_2=c2/pow(j,G) #Temperory value of pressure with respect to volume
P_Expan.append(Temp_2) #Pressure for compression saved in matrix
plt.plot(V_Expan,P_Expan,'r') #Plot compression
#Plot points
plt.plot([V2,V3],[P2,P3],[V4,V1],[P4,P1],'b') #Plot Isochoric lines
#Titels and axis labeel
plt.title("P-V Diagram for Otto cycle")
plt.xlabel('Volume[m]')
plt.ylabel('Pressure[N/m^2]')
plt.show()
FORMULAE USED IN PROGRAM:
1. Swept volume=`(pi/4)*BD^2*L`,
2.Clearance volume=Swept volume/(Compression ratio-1),
3.R=Connecting rod length/crank pin radius,4.Volume=`{(1+(0.5(r-1)(R+1+cos(theta))-([R^2-sin(theta)^2])^0.5}*Clearance volume,`volume,
OUTPUT
Using python Otto cycle created and values plotted below.
It represents isentropic and isochoric operations. P-V diagram plotted which represents pressure values with respect to volumes.
RESULT:
Otto cycle state points calculated and P V Diagram plotted.