OTTO CYCLE SIMULATOR USING PYTHON
OBJECTIVE
- To write a program of otto cycle in python and to plot the P-V diagram.
- To show the output of thermal efficiency of the engine.
THEORY ABOUT 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.
The Otto cycle is a description of what happens to a mass of gas as it is subjected to changes of pressure, temperature, volume, addition of heat, and removal of heat. The mass of gas that is subjected to those changes is called the system. The system, in this case, is defined to be the fluid (gas) within the cylinder. By describing the changes that take place within the system, it will also describe in inverse, the system's effect on the environment. In the case of the Otto cycle, the effect will be to produce enough net work from the system so as to propel an automobile and its occupants in the environment.
The processes are described by
- Process 0–1 a mass of air is drawn into piston/cylinder arrangement at constant pressure.
- Process 1–2 is an adiabatic (isentropic) compression of the charge as the piston moves from bottom dead center (BDC) to top dead center (TDC).
- Process 2–3 is a constant-volume heat transfer to the working gas from an external source while the piston is at top dead center. This process is intended to represent the ignition of the fuel-air mixture and the subsequent rapid burning.
- Process 3–4 is an adiabatic (isentropic) expansion (power stroke).
- Process 4–1 completes the cycle by a constant-volume process in which heat is rejected from the air while the piston is at bottom dead center.
- Process 1–0 the mass of air is released to the atmosphere in a constant pressure process.
The Otto cycle consists of isentropic compression, heat addition at constant volume, isentropic expansion, and rejection of heat at constant volume. In the case of a four-stroke Otto cycle, technically there are two additional processes: one for the exhaust of waste heat and combustion products at constant pressure (isobaric), and one for the intake of cool oxygen-rich air also at constant pressure; however, these are often omitted in a simplified analysis. Even though those two processes are critical to the functioning of a real engine, wherein the details of heat transfer and combustion chemistry are relevant, for the simplified analysis of the thermodynamic cycle, it is more convenient to assume that all of the waste-heat is removed during a single volume change.
Since the Otto cycle uses isentropic processes during the compression (process 1 to 2) and expansion (process 3 to 4) the isentropic equations of ideal gases and the constant pressure/volume relations can be used to yield Equations 3 & 4.
Where
Thermal efficiency
PROCEDURE
- Initially we are going to import the “matplotlib.pyplot” and “math” library to plot the graphs and to do the maths calculations.
- Then just input the given parameters are pressure, temperature etc. to calculate the other parameters.
- Using the calling function command we are going to calculate the compression and expansion of pressure and volume to draw the plot.
- Using the “append” command we just get the values at the same array.
- And then we calculate the pressure and volume of the other state and plot the graph according to the calculated values.
PROGRAM
#program of otto cycle simulator
#by sallavoddin
import matplotlib.pyplot as plt
import math
def engine_kinematics(bore, stroke,con_rod,cr,start_crank,end_crank):
"""
Engine Kinematics
"""
#geometri parameters
a=stroke/2
R=con_rod/a
#volume
v_s=(math.pi)/4*pow(bore,2)*stroke
v_c=v_s/(cr-1)
sc=math.radians(start_crank)
ec=math.radians(end_crank)
n_theta=100
dtheta=(ec-sc)/(n_theta-1)
V=[]
for i in range(0,n_theta):
theta=sc+(i*dtheta)
term1=0.5*(cr-1)
term2=R+1 -math.cos(theta)
term3=pow(pow(R,2) - pow(math.sin(theta),2),0.5)
V.append((1+term1*(term2-term3))*v_c)
return V
#input parameters
p1=101325
t1=500
t3=2300
gamma=1.4
#geometri parameters
bore=0.1
stroke=0.1
con_rod=0.15
cr=12
#volume
v_s=(math.pi)/4*pow(bore,2)*stroke
v_c=v_s/(cr-1)
v1=v_s+v_c
v2=v_c
#state2 p1v1^gamma=p2v2^gamma
p2=p1*pow(cr,gamma)
#p2v2/t2=p3v3/t3 | rhs=p2v2/t2 | t2=p2v2/rhs
rhs=p1*v1/t1
t2=p2*v2/rhs
V_compression=engine_kinematics(bore,stroke,con_rod,cr,180,0)
constant=p1*pow(v1,gamma)
#P_compression*V_compression^gamma=constant
P_compression=[]
for v in V_compression:
P_compression.append(constant/pow(v,gamma))
#state3
v3=v2
#p3v3/t3=p2v2/t2 | p2v2/t2=rhs | t2=p2v2/rhs
rhs=p2*v2/t2
p3=rhs*t3/v3
V_expansion=engine_kinematics(bore,stroke,con_rod,cr,0,180)
constant=p3*pow(v3,gamma)
#P_expanssion*V_expansion^gamma=constant
P_expansion=[]
for v in V_expansion:
P_expansion.append(constant/pow(v,gamma))
#state4
v4=v1
p4=p3*pow((v3/v4),gamma)
t4=p4*v4/rhs
#Thaermal efficiency
eff=1-1/(pow(cr,(gamma-1)))
eff=str(eff*100)
print("Thermal efficiency="+eff+"%")
#plot
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.xlabel('Volume m3')
plt.ylabel('Pressure Pa')
plt.title('PV Diagram')
plt.show()
RESULT
plot
Thermal Efficiency=62.98%
CONCLUSION
- we can see that the PV diagram of otto cycle is drawn and calcualted the Thermal efficiency.
REFFERENCES