Air standard Cycle by using Python
Aim: To write program to plot p-v diagram of otto cycle and calculate thermal efficiency of cycle using python
Governing Equations:
1] Combined gas law: we derive this law by combining law of Charles, Boyle and Gay-Lussac law this equation will help to find property at point 2 and point 3 .
`Pv/T=C`
where
p = pressure in pascal
V = volume in m3
T = temperature in kelvin
C = constant
2] The mathematical equation for an ideal gas undergoing a reversible (i.e., no entropy generation) adiabatic process can be represented by the polytropic process equation. This equation will help in finding property related to isentropic compression and isentropic expansion.
`pv^Y=c`
where
p =pressure in pascal
V =volume in m3
Y= (Cp/Cv) =ratio of specific heat
C = constant
3] thermal efficiency of Otto cycle is given by: from analyzing equation it is evident that thermal efficiency depends directly upon compression ratio r. Since y for air is 1.4, an increase in r produce increase in ƞ.
`n=1-1/r^((Y-1) )`
where
Ƞ=thermal efficiency
r = compression ratio
y= ratio of specific heat
4) Swept volume : is the measure of the cylinder volume displaced by all of the pistons of a piston engine .
Swept volume = (π/4) *(bore^2) *stroke length
Where
Bore = diameter of each cylinder in piston engine
Stroke length = distance travelled by the piston in each cycle.
5) Clearance volume: This is the volume of the space in the cylinder left at the end of the compression stroke.
Clearance volume = (swept volume) / (compression ratio -1)
Where
Compression ratio = the ratio of the volume of the cylinder and the combustion chamber when the piston is at the bottom, and the volume of the combustion chamber when the piston is at the top
6 this equation tells about how combustion chamber volume changes as function of
crank angle.
`v/v_c =1+1/2 (r_c-1)[1+R-cosθ-(R^2-〖sin〗^2θ )^(1/2) ]`
Where
ϴ = crank angle
rc = compression ratio
Objective:
1] To write program to plot air standard Otto cycle.
2] To understand difference between theoretical and actual Otto cycle
3] To calculate thermal efficiency
Therotical background:
An Otto cycle is an idealized thermodynamic cycle that describes the functioning of a typical spark ignition petrol engine. It is the thermodynamic cycle most commonly found in automobile engines.
Processes:
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 centre (BDC) to top dead Centre (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 Centre. 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 Centre.
- Process 1–0 the mass of air is released to the atmosphere in a constant pressure process.
Code:
# otto cycle simulator
import math
import matplotlib.pyplot as plt
def engine_kinematics(bore,stroke,con_rod,cr,start_crank,end_crank):
a= stroke/2
R = con_rod/a
# swept volume and clearance volume calculation
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=50
V=[]
dtheta = (ec-sc)/(n-1)
for i in range (0,n):
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
# input
p1=101325
t1=500
gamma=1.4
t3=2300
# geometric parameter
bore=0.1
stroke=0.1
con_rod=0.15
cr=10
# swept volume and clearance volume calculation
v_s=(math.pi/4)*pow(bore,2)*stroke
v_c=v_s/(cr-1)
v_1=v_s+v_c
v_2=v_c
# pressure at point 2
# p2v2^gamma=p1v1^gamma
p2=p1*(pow(v_1,gamma)/pow(v_2,gamma))
# temp at2
# p1v1/t1 =p2v2/t2 | p1v1/t1 = rhs | t2=p2v2/rhs
rhs=p1*v_1/t1
t2= p2*v_2/rhs
V_comprssion=engine_kinematics(bore,stroke,con_rod,cr,180,0)
constant=p1*pow(v_1,gamma)
p_compression=[]
for v in V_comprssion:
p_compression.append(constant/pow(v,gamma))
# pressure at state 3
v_3=v_2
# p3v3/t3=rhs
p3= rhs*t3/v_3
# pressure and temp at state 4
# p3v3^gamma=p4v4^gamma
# p4v4/t4=rhs
v_4=v_1
p4=p3*pow(v_3,gamma)/pow(v_4,gamma)
V_expansion=engine_kinematics(bore,stroke,con_rod,cr,0,180)
constant=p3*pow(v_3,gamma)
p_expansion=[]
for v in V_expansion:
p_expansion.append(constant/pow(v,gamma))
thermal_efficiency=(1-1/pow(cr,0.4) )*100
print(thermal_efficiency)
plt.plot([v_2,v_3],[p2,p3])
plt.plot(V_comprssion,p_compression)
plt.plot([v_4,v_1],[p4,p1])
plt.plot(V_expansion,p_expansion)
plt.xlabel('volume')
plt.ylabel('pressure')
plt.title('P-V Diagram')
plt.show()
Procedure:
- import math and matplotlib module.
- define the function which takes bore ,stroke,connecting rod length and cr and starting crank angle and ending crank angle.
- in function we are calculating volume in isentropic process as function of crank angle.
- we have used this function in compression and expansion process to get variation of volume.
- use the thermodyanamic relation to calculate pressure ,volume and temprature at each state point .
- plot the state point and also calculate thermal efficiency.
Error Encountered :
- Indentation Error
- Name Error
Plot:
Thermal efficiency: 60.18%
Result:
- Program to plot p-v diagram has been successfully executed.