Challenge

Week 2 Air standard Cycle

Aim:

  1. To write a code that can solve an Otto Cycle.
  2. Plot the PV diagram of the Otto Cycle.
  3. Ouput the thermal efficiency of the SI engine.

Background:

Otto Cycle:

The Otto cycle is a set of processes used by spark ignition internal combustion engines. There are four thermodynamic processes in the cycle:

Process 1-2: Isentropic compression

Process 2-3: Constant volume heat addition

ProcesS 3-4: Isentropic expansion

Process 4-1: Constant volume heat rejection

After the air-fuel mixture is sucked into the combustion chamber, the piston moves from bottom dead centre (BDC) to top dead center (TDC)and the charge is compressed isentropically. While the piston is at TDC, heat is added at constant pressure. Then the piston moves from TDC to BDC assisting isentropic expansion process during the power stroke. Finally, the cycle is completed by a constant colume heat rejection process while the piston is at BDC.

In the following code, we assume pressure and temperature values for some state points and use formulae and known relationships for calculating unknown values of pressure and temperature at other state points.

Python Code:

#Title - Air Standard Cycle

import math
import matplotlib.pyplot as plt

#ENGINE KINEMATICS

#defining the fuction engine_kinematics 
def engine_kinematics(bore, stroke, con_rod, cr, start_crank, end_crank):

	# Geometric parameters

	a = stroke/2	 #a - crank pin radius
	R = con_rod/a 	 #R - constant

#Relationship between the crank angle and the volume inside the combustion chamber	#to obtain volume trace
#V/Vc = 1 + 1/2(rc-1)[R + 1 - cos0 - (R^2 - sin^2 0)^(1/2)]
	
	# Volume parameters
	V_s = math.pi * (1/4) * pow(bore,2) * stroke	#swept volume
	V_c = V_s/(cr-1)	#clearance volume

	sc = math.radians(start_crank)	#starting crank angle in radians
	ec = math.radians(end_crank)	#ending crank angle in radians

	num_values = 50	#number of values for volume

	dtheta = (ec-sc) / (num_values - 1)	#generating values for dtheta

	V = []	#creating empty array for volume

	#using for loop to generate values for theta and to append the correponding volume values into V array
	for i in range(0, num_values):
		theta = sc + i*dtheta	#generating values for theta

		#different terms in the above crank angle and volume relationship
		term1 = 0.5*(cr-1)
		term2 = R + 1 - math.cos(theta)
		term3 = pow(R,2) - pow(math.sin(theta),2)
		term4 = pow(term3,0.5)

		V.append((1 + term1 * (term2 - term4)) * V_c)	#appending volume values into array V

	return(V)	#returning value of V



#OTTO CYCLE

# inputs
p1 = 101325
t1 = 500
gamma = 1.4
t3 = 2300

# geometric parameters
bore = 0.1
stroke = 0.1
con_rod = 0.15
cr = 8

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

# state point 2
v2 = v_c

# p2v2^gamma = p1v1^gamma
p2 = p1 * pow(v1,gamma) / pow(v2,gamma)

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

V_compression = engine_kinematics(bore, stroke, con_rod, cr, 180, 0)	#calling the above defined engine_kinematics function to determine values for volume during the compression process.

constant = p1 * pow(v1, gamma)

P_compression = []	#creating emty array for pressure values during compression

for vc in V_compression:
	P_compression.append(constant / pow(vc, gamma))		#calculating and appending pressures corresponding to the volumes during compression process.


# state point 3
v3 = v2

# p3v3/t3 = p2v2/t2 | rhs2 = p2v2/t2 | p3 =rhs2*t3/v3

rhs2 = p2*v2/t2
p3 = rhs2*t3/v3


V_expansion = engine_kinematics(bore, stroke, con_rod, cr, 0, 180)	#calling the above defined engine_kinematics function to determine values for volume during the expansion process.

constant = p3 * pow(v3, gamma)

P_expansion = []	#creating emty array for pressure values during expansion

for ve in V_expansion:
	P_expansion.append(constant / pow(ve, gamma))	#calculating and appending pressures corresponding to the volumes during expansion process.



# state point 4
v4 = v1

# p4v4^gamma = p3v3^gamma

p4 = p3 * pow(v3,gamma) / pow(v4,gamma)

# p4v4/t4 = rhs2

t4 = p4*v4/rhs2

#Thermal efficiency calculation
eta = 1 - (t4 - t1)/(t3 - t2)
print(eta)

#Plotting the four different processes in the Otto cycle

plt.figure()
plt.plot(V_compression, P_compression)
plt.plot([v2,v3], [p2,p3])
plt.plot(V_expansion, P_expansion)
plt.plot([v4,v1], [p4,p1])
plt.title('Otto cycle - PV diagram')
plt.savefig('W2_PVdiagram')

Result:

  • PV diagram of the Otto cycle (cr = 8)

  • Thermal efficiency of the engine (η)

η = 0.5647 = 56.47%

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.