Project

Otto cycle simulator using python

The otto cycle is an ideal cycle that refers to the functioning of a petrol or SI engine.

The cycle is made up of 4 cycles that are made up of 4 salient points.

From point 1-2 it is a reversible adiabatic compression process.

From 2-3 it is a constant volume heat transfer into the system.

From 3-4 it is a reversible adiabatic expansion process.

From 4-1 it is a constant volume heat rejection process.

From the above mentioned process we will try to derive the p-V diagram for an Otto cycle using python

Inputs:

Gamma = 1.4
bore radius = 0.1m;
stroke length= 0.1m;
connecting rod length = 0.15m;
compression ratio = 8;

The code used to create the p-V plot. A function has been defined to calculate the pressure and volume during the compression and expansion cycles to plot the curves.

import matplotlib.pyplot as plt
import math

#Inputs
g = 1.4
T3 = 2300

#Engine geometry
bore = 0.1
stroke = 0.1
con_rod = 0.15
cr = 8



def ekine(bore, stroke, con_rod, cr, start_crank, end_crank):

	a = stroke/2
	R = con_rod/a

	V_s = (math.pi/4)*pow(bore,2)*(stroke)
	V_c = V_s/(cr-1)

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

	n = 50
	dtheta = (ec - sc)/(n-1) 

	v = []

	for i in range(0,n):

		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

#State variables at point 1
p1 = 101325
T1 = 500

#Swept and clearance volumes
V_s = (math.pi/4)*pow(bore,2)*(stroke)
V_c = V_s/(cr-1)

v1 = V_s + V_c
v2 = V_c

#State variables at point 2
#p1v1^g = p2v2^g

p2 = p1*pow((v1/v2),g)

#p1v1/t1 = p2v2/t2

T2 = (p2*v2*T1)/(p1*v1)

c1 = p1*pow(v1,g)

V_comp = ekine(bore, stroke, con_rod, cr, 180, 0)
P_comp = []

for v in V_comp:
	P_comp.append(c1/pow(v,g))

#State variables at point 3
v3 = v2

#p3v3/t3 = p2v2/t2
p3 = p2*T3/T2

c2 = p3*pow(v3,g)
V_exp = ekine(bore, stroke, con_rod, cr, 0, 180)
P_exp = []

for v in V_exp:
	P_exp.append(c2/pow(v,g))

#State variables at point 4
v4 = v1

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

T4 = (p4*v4*T3)/(p3*v3)
#thermal efficiency

Thermal_eff = (1 - ((T4-T1)/(T3-T2)))*100

plt.figure()
plt.plot([v2,v3], [p2,p3])
plt.plot([v4,v1], [p4,p1])
plt.plot(V_comp, P_comp)
plt.plot(V_exp, P_exp)
plt.xlabel(\'Pressure\')
plt.ylabel(\'Velocity\')
plt.show()

The function solves for the volume changes during the adiabatic processes. The equation used has been split into 3 parts for convenience. The function takes in the values of stroke, bore, connecting rod length, compression ratio and the start and end crank angle during the process.

Thermal efficiency was found using the formula `(1 - ((T4-T1)/(T3-T2)))*100` and was found to be 56%.

The p-V diagram as obtained using the code:

\"\"

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.