Project

TO STUDY ENGINE KINEMATICS AND PLOTTING OF P-V DIAGRAM USING PYTHON

AIM

To write the code of Otto cycle simulator using Python

  1. Plot the PV diagram of a Otto cycle.
  2. Find the thermal efficiency of a cycle.

GOVERNING EQUATIONS

1. `PV^gamma`=constant for adiabatic process

2. PV =RT

3. `Vswept = π/4 .stroke.dia^2`

4. `V/V_c` = `1+ 1/2(compression ratio-1). {r + 1-costheta-( r^2-(sintheta)^2)^(1/2)}`

5. efficiency= `1- 1/(compressionratio^(gamma-1))`

Where P = Pressure unit - `(N/m^2 )`

V = Volume unit - (`m^3`)

`gamma`= Index

r =`(conrod)/a` conrod is connecting rod

a =`(stroke )/2`

`theta` = crank angle unit - degree

OBJECTIVES OF THE PROJECT

By the help of PYTHON programming code, we are going to plot a PV diagram of an Otto cycle and find out the efficiency of Otto cycle.

BODY OF THE CONTENT

Introduction

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.

It is having thermodynamics process are discussed below

  • 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.

STEPS OF PRAGRAM

Here I have used Python programming language to write the program to plot the PV diagram. In which the codes call a function which is used to find the volume by taking the values of a bore, crank, connecting rod, compression ratio, start crank angle, end crank angle which is discussed below.

After that plot command is used to plot the PV diagram by the help of function and find out the efficiency of the Otto cycle. It is discussed below

1. Provide topic of the code which is under comment

2. Calling of library which will used for plotting and calculating i.e. math and matplotlib.pyplot library.

3. Making of function name as engine_kinematics which take inputs bore, stroke, connecting rod, compression ratio, starting crank angle, end crank angle

4. After that giving geometric and volume parameter which will be used in the function to calculate the volume.

5. Now defining of start crank angle and end crank angle as sc,ec which are the starting crank angle and end crank angle in radians

6. num_vaues are the steps which is used to divide the theta in equal interval.

Here V is the empty array for the volume.

7. Now by the help of for loop we calculate the volume by giving equation of volume which is named as term1, term2, term3.

Append command is used to store the value of volume in the empty array of volume V in line 59.

In line 62 return V is used to give the value of volume back to the function.

8. From line 66 to 76 geometric parameter and input of the cylinder and cycle is provided which helps in calculating the volume and efficiency of the Otto cycle.

9. Line 80 to 82 contain calculation for the stage 1 of volume.

10. From line 85 to 105 calculation of stage 2 is done which include the calculation of volume and pressure compression data.

In line 105 append command is used to store the values in the P_compression empty array.

11. From line 110 to 132 calculation of stage 3 is done in which we calculate the expansion volume, expansion pressure.

In line 132 append command is used to store the values in the P_compression empty array.

12. After that calculation of stage 4 is done

13. Now the calculation of efficiency is done from line 145 to 149

14. At last the following command is used to plot all the curve.

Plot command is used to plotting the data whereas show command is used to show the image which is plotted.

xlabel and ylabel is used to give the axis name whereas grid command is used to show the grid lines in the plot.

PROGRAM OF THE OTTO CYCLE

"""
OTTO CYCLE SIMULATOR
"""

#importing of libraries 
import math
import matplotlib.pyplot as plt


#Making function name as engine_kinematics which take inputs bore, stroke,connecting rod,compression ratio,starting crank angle,end crank angle
def engine_kinematics(bore,stroke,con_rod,cr,start_crank,end_crank):
	
	"""
	Function of engine kinematics
	"""

	#Geometric parameter
	a = stroke/2
	r = con_rod/a

	
	#VOLUME PARAMETER
	#Swept volume as V_s
	V_s = math.pi*(1/4)*pow(bore,2)*stroke
	#clearance volume as V_c
	V_c = V_s/(cr-1)

	
	#sc and ec are the starting crank angle and end crank angle in radians
	sc = math.radians(start_crank)                          #start_crank in degree
	ec = math.radians(end_crank)                            #end_crank in degree

	
	#num_values is the numbers in which theta to be break
	num_values = 50

	
	#dheta is the equal increament of theta value
	dtheta = (ec-sc)/(num_values-1)

	
	#V is the empty array of volume
	V =[]

	
	#for loop of i within the range of 0 to num_values
	for i in range(0,num_values):
		
		#theta is the angle which keeps on increasing in every for loop with dtheta term
		theta = sc + i*dtheta
		
		#term1,term2,term3 are the valuess which used in calculating of volume equation
		term1 = 0.5*(cr-1)
		term2 = r + 1 - math.cos(theta)
		term = pow(r,2) - pow(math.sin(theta),2)
		term3 = pow(term,0.5)

		#Storing of volume data inside the empty array V
		V.append((1+ term1*(term2-term3))*V_c)

	#return the values to function
	return V	


#Geometric parameter
bore = 0.1							#bore diameter
stroke = 0.1						#stroke length
con_rod = 0.15						#connecting rod length
cr = 8								#compression ratio


# Input data 
p1 = 101325                        #pressure at point 1
t1 = 500						   #temperatue at point 1
t3 = 2300						   #temperature at point 3
gamma = 1.4						   #adiabatic index


#Volume computation
v_s = (math.pi/4)*pow(bore,2)*stroke			#Swept volume as v_s
v_c = v_s/(cr-1)								#Clearance volume as v_c
v1 = v_c + v_s 									#volume at stage 1

#state point 2 
v2 = v_c 										#volume at stage 2
p2 = p1*pow(v1,gamma)/pow(v2,gamma)				#p2v2^gamma = p1v1^gamma

#p2v2/t2 = p1v1/t1 | rhs = p1v1/t1 | p2v2/t2 = rhs | t2 = p2v2/rhs
rhs = p1*v1/t1
t2 = p2*v2/rhs


#total volume during compression stroke by calling engine kinematics function
V_compression = engine_kinematics(bore,stroke,con_rod,cr,180,0)
constant = p1*pow(v1,gamma) 						#p1v1^gamma = constant

#P_compression is the empty array of pressure during compression
P_compression = []


#for loop of v upto V_compression
for v in V_compression:
	
	#storing values of P_compression in the array
	P_compression.append(constant/pow(v,gamma))		 #P_compression*V_compression^gamma = constant



#State point 3
v3 = v2


#p3v3/t3 = p2v2/t2 | rhs = p2v2/t2 | p3 = rhs*t3/v3
rhs = p2*v2/t2
p3 = rhs*t3/v3



#total volume during expansion stroke by calling engine kinematics function
V_expansion = engine_kinematics(bore,stroke,con_rod,cr,180,0)
constant = p3*pow(v3,gamma) 						#p3v3^gamma = constant					


#P_compression is the empty array of pressure during expansion
P_expansion = []


#for loop of v upto V_expansion
for v in V_expansion:
	
	#storing values of P_expansion in the array
	P_expansion.append(constant/pow(v,gamma))



#state point4
v4 = v1


p4 = p3*pow(v3,gamma)/pow(v4,gamma)                 #p4v4^gamma = p3v3^gamma
t4 = p4*v4/rhs										#p4v4/t4 = rhs


#Calculating and printing of the efficiency of the otto cycle
efficiency=1-(1/pow(cr,gamma-1))
print('efficiency of otto cycle =',efficiency)
#Calculating and printing of the efficiency of the otto cycle in percentage
efficiency_in_percentage = efficiency*100
print('efficiency of otto cycle in percentage =',efficiency_in_percentage)


#plot of the PV diagram for otto cycle
plt.plot([v2,v3],[p2,p3])         					#Plot of the v2,v3 and p2,p3 curve
plt.plot(V_compression,P_compression)				#Plot of the V_compression and P_compression curve
plt.plot([v4,v1],[p4,p1])							#Plot of the v4,v1 and p4,p1 curve
plt.plot(V_expansion,P_expansion)					#Plot of the V_expansion and P_expansion curve

#Labelling of X and Y axis of the plot
plt.xlabel('Volume')
plt.ylabel('Pressure')
#command to show the grids
plt.grid()
#command to show the plot
plt.show()



ERROR OBTAIN WHILE PROGRAMMING

  1. By giving wrong value in line 153 (v1,v2),(p1,p2) instead of (v2,v3),(p2,p3) and in line 155 (v3,v4),(p3,p4) instead of (v4,v1),(p4,p1)

CONCLUSION

  1. Final PV diagram is shown in the fig.

2. The efficiency of the cycle is 0.5647 which means 56.47%

REFERENCES

  1. Skill lync video lecture
  2. Wikkipidia
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.