Project

Otto Cycle

PYTHON PROGRAM FOR CALCULATING THE EFFICIENCY OF OTTO CYCLE AND PLOTTING OF PV DIAGRAM

OBJECTIVE:-

  • To plot a PV Diagram of Otto Cycle.
  • To calculate the efficiency of Otto Cycle.

TERMS & PHASES:-

OTTO CYCLE:- The otto cycle is a thermodynamic process of the engine which requires in 4 strokes of the piston, namely Induction, Compression, Ignition and Exhaust. The fuel-air mixture is compressed before combustion is started by an electric spark or other means.

The cycle takes place in 4 phases:-

  1. Adiabatic Compression/Isentropic Compression
  2. Constant Volume Heat Addition
  3. Adiabatic Expansion/Isentropic Expansion
  4. Constant Volume Heat Rejection

PROCEDURE:-

Following is the code which I wrote for the calculation of efficiency of the engine and the plotting of PV Diagram.

\"\"\"
Code by- Rishav Raj Sinha
Program: WAP to create a PV diagram of Otto Cycle and print the efficiency of the engine
\"\"\"

import math
import matplotlib.pyplot as plt 

# Defining of a function
def engine_kinematics(bore, stroke, con_rod, cr, start_crank, end_crank):
	a = stroke/2
	R = con_rod/a

	
	# Calculation of Volumes parameters
	V_s = math.pi*(1/4)*pow(bore,2)*stroke
	V_c = V_s/(cr-1)

	# Calculation of crank angles
	sc = math.radians(start_crank)
	ec = math.radians(end_crank)

	num = 50                                          # Defining the number of iterations to be performed

	dtheta = (ec-sc)/(num-1)

	V = []                                            # Array for the Volumes to be stored of the changing theta

	for i in range(0,num):
		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                 # State Point 1 Pressure
t1 = 500                    # State Point 1 Temperature
y = 1.4                     # Value for Gamma
t3 = 2300                   # State point 3 Temperature

# Geometric parameters
bore = 0.1
stroke = 0.1
con_rod = 0.15              # Length of Connecting Rod
cr = 12                     # Commpression-Ratio

# Computing Volumes
v_s = math.pi*(1/4)*pow(bore,2)*stroke               # Swept Volume
v_c = v_s/(cr-1)                                     # Clearance Volume
v1 = v_s + v_c                                       # Volume at State Point 1

# State variables at point 2
v2 = v_c
p2 = p1*pow(v1,y)/pow(v2,y)
rhs = p1*v1/t1
t2 = p2*v2/rhs

V_compression = engine_kinematics(bore, stroke, con_rod, cr, 180, 0)
Constant = p1 * pow(v1, y)

P_compression = []
for V in V_compression:
	P_compression.append(Constant/pow(V, y))

# State variables at point 3
v3 = v2
rhs=p2*v2/t2
p3 = rhs*t3/v3

V_expansion = engine_kinematics(bore, stroke, con_rod, cr, 0, 180)
Constant = p3 * pow(v3, y)

P_expansion = []
for V in V_expansion:
	P_expansion.append(Constant/pow(V, y))

# State variables at point 4
v4 = v1
p4 = p3*pow(v3,y)/pow(v4,y)
t4 = p4*v4/rhs

# Calculating Thermal Efficiency(n) of the Engine
n = 1 - ((t4-t1)/(t3-t2))
print(\'The Thermal Efficiency of the Otto Engine is\', (n*100), \'%\')

# Plotting PV Diagram
plt.plot([v2,v3],[p2,p3], \'-b\', label=\'Heat Addition\')
plt.plot(V_compression, P_compression, \'-r\', label=\'Compression\')
plt.plot(V_expansion, P_expansion, \'-c\', label=\'Expansion\')
plt.plot([v4,v1], [p4,p1], \'-m\', label=\'Heat Rejection\')
plt.legend()
plt.xlabel(\'Volume (m^3)\')
plt.ylabel(\'Pressure (Bar)\')
plt.title(\'PV Diagram of Otto Cycle\')
plt.savefig(\'Otto Cycle\')
plt.show()

OUTPUT:-

The above image shows the efficiency (n) as output as per calculated.

The above image shows the relation between Pressure and Volume of the Otto Cycle, which is accurate. We got a curve at expansion and compression because we have a variable value of y (gamma). The other 2 have a straight plots because they are the case of constant Volume.

LEARNING OUTCOME:-

  • In this challenge, I learnt the use of function in a program and with the help of a function we generated an accurate PV Diagram of an Otto Engine and also calculated its efficiency.

CONCLUSION:-

  • We successfully plotted an accurate PV Diagram for an Otto Engine.
  • We got the accurate result of the efficiency of the Otto Engine.
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.