Project

Motion Analysis of Air Standard Cycle using Python

Aim

Write code that can solve an otto cycle and make plots for it.

Governing equations

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.

The Otto cycle is a description of what happens to a mass of gas as it is subjected to changes of pressure, temperature, volume, the addition of heat, and removal of heat. The mass of gas that is subjected to those changes is called the system. The system, in this case, is defined to be the fluid (gas) within the cylinder. By describing the changes that take place within the system, it will also describe in the inverse, the system's effect on the environment. In the case of the Otto cycle, the effect will be to produce enough net work from the system so as to propel an automobile and its occupants in the environment.

The Otto cycle is constructed from:

  • Top and bottom of the loop: a pair of quasi-parallel and isentropic processes (frictionless, adiabatic reversible).
  • Left and right sides of the loop: a pair of parallel isochoric processes (constant volume).



In the above diagrams:

p = pressure

V = Volume

T = temperature

s = Entropy

`V_c` = Clearance volume

`V_s` = Stroke Volume

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 the bottom dead center (BDC) to top dead center (TDC).

Heat Supplied = m`C_v`(`T_3`-`T_2` ; where m = mass and `C_v`= Specific heat at constant volume

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

Heat Rejected = m`C_v`(`T_4-T_1`)

  • Process 1–0 the mass of air is released to the atmosphere in a constant pressure process.

Thermal efficiency of air standard cycle (or Otto Cycle),

`eta_(th) = ( Heat Supplied - Heat Rejected)/(Heat Supplied)`

`eta_(th) = 1 - (T_4-T_1)/(T_3-T_2)`

Process 1-2 and 3-4 are isentropic and hence,

`T_4(V_1)^(gamma-1) = T_3(V_2)^(gamma-1) ; T_1V_1^(gamma - 1) = T_2V_2^(gamma-1)`

Swept volume, `V_s = (pi*b^2*stroke)/4`

Clearance volume, `V_c = V_s/(cr-1)

The Otto cycle consists of isentropic compression, heat addition at constant volume, isentropic expansion, and rejection of heat at constant volume. In the case of a four-stroke Otto cycle, technically there are two additional processes: one for the exhaust of waste heat and combustion products at constant pressure (isobaric), and one for the intake of cool oxygen-rich air also at constant pressure; however, these are often omitted in a simplified analysis. Even though those two processes are critical to the functioning of a real engine, wherein the details of heat transfer and combustion chemistry are relevant, for the simplified analysis of the thermodynamic cycle, it is more convenient to assume that all of the waste-heat is removed during a single volume change.

Given:

bore = 0.8

stroke = 0.2

connecting rod length = 0.15

compression ratio = 12

p1 = 101325

gamma = 1.4

t1 = 550

t3 = 2800

Python code

"""
Otto cycle simulator
"""

import math
import matplotlib.pyplot as plt
import numpy as np

# Geometric parameter
bore = 0.8
stroke = 0.2
con_rod = 0.15
cr = 12

def engine_kinematics(bore, stroke, con_rod, cr, theta1, theta2):
	
	a = stroke/2
	R = con_rod/a


	# Volume parameters
	V_str = math.pi*(1/4)*pow(bore,2)*stroke
	V_clr = V_str/(cr-1)
	
	theta = np.linspace(theta1,theta2,180)
	V = []

	for d in theta:
		
		term1 = 0.5*(cr-1)
		term2 = R + 1 - math.cos(d)
		term3 = pow(R,2) - pow(math.sin(d),2)
		term3 = pow(term3, 0.5)

		V.append((1 + term1*(term2-term3))*V_clr)
	return V
		

# Inputs
p1 = 101325
t1 = 550	
gamma = 1.4
t3 = 2800

# Volume computation
V_str = (math.pi/4)*pow(bore,2)*stroke
V_clr = V_str/(cr-1)

# state point 1 
v1 = V_str + V_clr

# state point 2
v2 = V_clr

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

# state point 3
v3 = v2
p3 = p2*(t3/t2)
v_compression = engine_kinematics(bore, stroke, con_rod, cr, 180, 0)
c1 = p1*pow(v1,gamma)
p_compression = []

for v_c in v_compression:
	p_compression.append(c1/pow(v_c,gamma))


# state point 4
v4 = v1

# p4v4^gamma = p3v3^gamma

p4 = p3*pow(v3/v4, gamma)
t4 = pow(v3/v4, (gamma-1))
v_expansion = engine_kinematics(bore, stroke, con_rod, cr, 0, 180)
c2 = p3*pow(v3, gamma)
p_expansion = []

for v_e in v_expansion:
	p_expansion.append(c2/pow(v_e,gamma))


# Thermal efficiency calculation
n = 1 - ((t4/t1)/(t3-t2))
print("Efficiency of engine = ", n)

# PLotting the state points
plt.plot(v1,p1, "*")
plt.plot(v2,p2, "*")
plt.plot(v3,p3, "*")
plt.plot(v4,p4, "*")

plt.plot(v_compression, p_compression, "b", linewidth =2.5, label = "Compression stroke")
plt.plot([v2,v3], [p2,p3], "r", linewidth = 2.5, label = "Heat Addition")
plt.plot(v_expansion, p_expansion, "y", linewidth = 2.5, label = "Expansion stroke")
plt.plot([v4,v1], [p4,p1], "g", linewidth = 2.5, label = "Heat Rejection")

plt.xlabel('Volume(m^3)')
plt.ylabel('Pressure(pa)')
plt.legend()
plt.title('Otto Cycle')
plt.grid()
plt.show() 

Code explanation:

  1. All known geometric parameters and state variables are defined
  2. The formula for clearance volume and swept volume was provided.
  3. For process 1-2 and 3-4, all state variables were calculated using Isentropic formulae.
  4. Now, we obtained all four points but we need to define the changes in volume.
  5. For this, a function engine_kinematics was defined which calculates the swept volume for isentropic processes for each value of angle covered.
  6. Bore, stroke, length of connecting rod, compression ratio, and swept volume are given as arguments.
  7. The thermal efficiency formula is also defined before plotting.
  8. A P-V diagram is obtained with the help of plot command.

Errors faced

Faced errors due to typos in certain instances, resolved them by correcting the typos.

Output

The program outputs the efficiency of the Otto cycle and plot p-V diagram. We can see that for heat addition and heat rejection process, the volume is constant and for the isentropic processes, the graph follows an isentropic path.





Conclusion

The thermal efficiency was calculated with the help of a python program and a p-V diagram was plotted as well.

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.