Challenge

PYTHON Program to plot P-V diagram for OTTO cycle & find its thermal efficiency.

Aim:- To plot P-V diagram for OTTO cycle & find the thermal efficiency.

Theory:- An Otto cycle is an idealized thermodynamic cycle that describes the functioning of a typical spark ignition engine. It consists of four processes.

  1. Isentropic compression
  2. Constant volume heat addition
  3. Isentropic expansion
  4. Constant volume heat rejection

Governing equations:-

For isentropic process `PV^gamma= cons t ant`

The values of swept volume and clearance volume are calculated as follows

`v_s=pi/4**bo r e^2**stroke`

`v_c=v_s/(r_c-1)`

To find thermal efficiency

`eta_(th) =1-1/r_c^(gamma-1)` (or) `eta_(th) =(1-(t4-t1)/(t3-t2))**100`

Where,

`v_s=`swept volume

`v_c=`clearance volume

`r_c=`compression ratio

`eta_(th)=`thermal efficiency

`gamma=C_p/C_v=1.4`

Code:-

"""
OTTO Cycle
"""
import math
import matplotlib.pyplot as plt

def engine_kinematics(bore,stroke,con_rod,start_crank,end_crank):

	sc=math.radians(start_crank)
	ec=math.radians(end_crank)

	num_values=50
	dtheta=(ec-sc)/(num_values-1)
	
	V=[]

	for i in range(0,num_values):
		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

#inputs
gamma=1.4

#Engine geometric parameters
bore=0.1        # Bore diameter
stroke=0.1      # Stroke length
con_rod=.15     # Connecting rod length
cr=8    		# compression ratio
a=stroke/2
R=con_rod/a
	
#calculating swept volume(v_s) and clearance volume(v_c)
v_s=(math.pi/4)*pow(bore,2)*stroke
v_c=v_s/(cr-1)

#state variables at pt 1
p1=101325
t1=500
v1=v_s+v_c

#state variables at pt 2
v2=v_c
#p2v2^gamma=p1v1^gamma  |  p2=p1*(v1/v2)^gamma
p2=p1*pow(cr,gamma)
#p1v1/t1=p2v2/t2 | t2=p2*v2*t1/(p1*v1)
t2=p2*v2*t1/(p1*v1)

V_compression=engine_kinematics(bore,stroke,con_rod,180,0)

constant=p1*pow(v1,gamma)

P_compression=[]
for v in V_compression:
	P_compression.append(constant/pow(v,gamma))

#state variables at pt 3
v3=v2
t3=2300
#p3v3/t3=p2v2/t2 | p3=p2*t3/t2
p3=p2*t3/t2

V_expansion=engine_kinematics(bore,stroke,con_rod,0,180)

constant=p3*pow(v3,gamma)

P_expansion=[]
for v in V_expansion:
	P_expansion.append(constant/pow(v,gamma))

#state variables at pt 4
v4=v1
#p3v3^gamma=p4v4^gamma  |  p4=p3*(v3/v4)^gamma
p4=p3*pow((v3/v4),gamma)
t4=p4*v4*t3/(p3*v3)

# Thermal Efficency
Th_eff=(1-((t4-t1)/(t3-t2)))*100
print('Thermal Efficency =',Th_eff,'%')

# Plotting PV diagram
plt.plot(V_compression,P_compression,label='Isentropic compression')
plt.plot([v2,v3],[p2,p3],label='Const. volume heat addition')
plt.plot(V_expansion,P_expansion,label='Isentropic expansion')
plt.plot([v4,v1],[p4,p1],label='Const. volume heat rejection')
plt.title('P-V diagram of OTTO cycle')
plt.xlabel('Volume (m^3)')
plt.ylabel('Pressure (Pa)')
plt.legend(loc='best')
plt.show()

Explanation:-

  • First the libraries are imported.
  • The we define function called 'engine_kinematics' which is used to calculate the volume during the isentropic processes with (bore,stroke,connecting-rod length,start_crank angle,end_crank angle) as inputs to this function.
  • In function firstly, the starting and ending crank angles are converted into radians. Then the no. of values required between them are specified. Then empty array of volume is defined.
  • The values of volume are later calculated by using the for loop and the values are appended into the array. At last the values of volume are returned by the function.

Main code

  • The value of gamma, engine parameters are defined. And the formula for calculaation of swept and clearance volume are defined.
  • Then the state valiables at point 1, 2, 3 and 4 are defined. And the thermal efficiency is calculated.
  • At last the P-V diagram is plotted with appropriate labels and title.

Output:-

We can see the P-V diagram of OTTO cycle displayed as output. And the thermal efficiency that is 56.47% displayed in output window.

Your portfolio, next

Ship work like this
in your own course.

Talk to a career counsellor

Free 20-minute call. We'll map the right course to where you want to work.

By submitting you agree to our Terms and Privacy Policy.

Talk to a career counsellor

Free 20-minute call. We'll map the right course to where you want to work.

By submitting you agree to our Terms and Privacy Policy.