Week 2 Air standard Cycle
Aim : To write a program in python to calculate thermal efficiency and to plot P-V diagram for an otto cycle.
Objective : The main objective of the project is to calculate the presssure and volume for a given crank angles during isentropic compression and expansion process and plotting PV diagram suitably and to calculate thermal efficiency.
Brief explanation of otto cycle :
As we all know, otto cycle is a ideal cycle which describes the working or the function of a spark ignition IC engine.
In general in PV plot there will be four process such as
process 1-2 : Here there will be isentropic compression of the air drawn into cylinder.
process 2-3 : Here the fuel air mixture will be added so it get ignited and it results in constant volume heat addition process
process 3_4 : In this process there will be isentropic expansion process known as power stroke.
process 4-1 : Here the constant volume heat rejection process will happen and it completes the cycle. After this air is released to atmosphere.
Equations used :
1. V = (1 + 0.5*(cr-1) * (R+1-cos(Θ)-(R^2-sin(Θ)^2)^0.5)*v_c
where Θ is crank angle and v_c is clearance volume
2. for isentropic process :
pv^gamma = constant
3. pv/t = constant (from ideal gas law)
4. to find thermal efficiency:
thermal_efficiency = (1-((t4-t1)/(t3-t2)))*100
Solution procedure :
1. After importing some needed libraries .we define a function called engine_kinmeatics, here it computes volume for corresponding crank angles given respectively and we will store it in an array.
2. Then we give all the input parameters required initially such as geometric parameters, volume parameters and some state variables.
3. Then we define formulas for swept volume and clearance volume.
4. Now, we just go on calculating the state variables p,v,t i.e pressure, volume, temparature at all state points by using the equation mentioned above.
5. While calculating the state points of process 2 , we have to calculate pressure values in isentropic compression process for the corresponding volume. Here crank angle varies from 180 to 0 degrees. we can do this by calling the function we defined above and with some equations mentioned above.
6. Similarly while calculating the state points of process 3 , we have to calculate pressure values in isentropic expansion process for the corresponding volume. Here crank angle varies from 0 to 180 degrees. we can do this by calling the function we defined above and with some equations.
7. Now calculate thermal efficiency using formula.
8. Then plot the PV diagram for the entire process of an otto cycle.
Python program for an otto cycle is as follows:
"""
otto cycle simulator
"""
#importing some suitable libraries
import math
import matplotlib.pyplot as plt
#defining the funnction
def engine_kinematics(bore,stroke,con_rod,cr,start_crank,end_crank):
#geometric parameters
a=stroke/2
R=con_rod/a
#volume parameters
v_s=(math.pi/4)*pow(bore,2)*stroke
v_c=v_s/(cr-1)
#crank angle
sc=math.radians(start_crank)
ec=math.radians(end_crank)
#number of angles to be taken
num_values=50
dtheta=(ec-sc)/(num_values-1)
V=[]
#calculating theta and corresponding volume
for i in range(0,num_values):
theta=sc+i*dtheta
term1=0.5*(cr-1)
term2=R+1-math.cos(theta)
term3=pow(R,2)-pow(math.sin(theta),2)
term3=pow(term3,0.5)
V.append((1+term1*(term2-term3))*v_c)
return V
#inputs
p1=101325
t1=500
gamma=1.4
t3=2300
#geometric parameters
bore=0.1
stroke=0.1
con_rod=0.15
cr=12
#volume computation
v_s=(math.pi/4)*pow(bore,2)*stroke
v_c=v_s/(cr-1)
v1=v_c+v_s
#statepoint2
v2=v_c
#p2v2^gamma=p1v1^gamma
p2=p1*pow(v1,gamma)/pow(v2,gamma)
#p2v2/t2=p1v1/t1
rhs=p1*v1/t1
t2=p2*v2/rhs
#compression process
V_compression=engine_kinematics(bore,stroke,con_rod,cr,180,0)
constant=p1*pow(v1,gamma)
p_compression=[]
for v in V_compression:
p_compression.append(constant/pow(v,gamma))
#statepoint3
v3=v2
#p3v3/t3=p2v2/t2
rhs=p2*v2/t2
p3=rhs*t3/v3
#expansion process
V_expansion=engine_kinematics(bore,stroke,con_rod,cr,0,180)
constant=p3*pow(v3,gamma)
p_expansion=[]
for v in V_expansion:
p_expansion.append(constant/pow(v,gamma))
#statepoint4
v4=v1
#p4v4^gamma=p3v3^gamma
p4=p3*pow(v3,gamma)/pow(v4,gamma)
#p4v4/t4=p3v3/t3
rhs=p3*v3/t3
t4=p4*v4/rhs
#thermal efficiency
thermal_efficiency=(1-((t4-t1)/(t3-t2)))*100
print(thermal_efficiency)
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")
plt.ylabel("pressure")
plt.show()
Result :
1. The calculated thermal efficiency of an otto cycle is 62.98%
2. we obtained P-V diagram for the complete process and screenshot of that is attached below.
Conclusion : Here obtained P-V diagram clearly shows curve lines in isentropic processes which looks realstic. This is a simple program to learn and explore with some libraries and it enhances indentation technique, here we just obtained P-V diagram and thermal efficiency by calculating the state variables of each processes, given that initial state variable values are known.