Project

OTTO CYCLE USING PYTHON

1.AIM :

TO FIND THERMAL EFFICIECNY AND PLOT PV DIAGRAM FOR OTTO CYCLE USING PYTHON

2.OBJECTIVES :

Write a python program to

  1. create a PV diagram of otto cycle.
  2. calculate the thermal efficiency of the engine.

3.PROBLEM STATEMENT :

Write a python program that can solve an otto cycle, create a PV diagram and calculate thermal efficieny

4.THEORY AND GOVERNING EQUATIONS :

An Otto cycle is an air standard cycle that describes the functioning of a spark ignition engine. The PV diagram of an otto cycle is shown below.

The processes involved are :

Process 1-2: Isentropic compression

Process 2-3: Constant volume heat addition

Process 3-4: Isentropic expansion

Process 4-1: Constant volume heat rejection

swept volume is given by

`pi/4⋅ BORE ^ 2 ⋅ STROKE`

clearance voule is given by

`("swept volume" )/( r c − 1)`

where rc is compression ratio

For isentropic process

`(p2)/ (p1) = (( v 1)/(v 2))^ γ =constant`

For heat addition and rejection process, from ideal gas equation

`(p 1 ⋅ v 1)/ (t1) = (p 2 ⋅ v 2)/( t 2)`

The thermal effciency is given by

`η = 1 − ( 1 /( r c )^ (γ − 1) )`

5.PYTHON PROGRAM :

The python program to calculate the thermal efficieny of the engine and plot the PV diagram of otto cycle is shown below.

"""
otto cycle simulator
"""

import math
import matplotlib.pyplot as plt

#function to calculate volume points during expansion and compression stoke varying with crank angle 
def engine_kinematics(bore, stroke, con_rod, cr, start_crank, end_crank):
	"""
	Engine kinematics
	"""

	#gemoetric parameters
	a=stroke/2 #crank pin radius
	R = con_rod/a

	#volume parameters
	v_s = math.pi*(1/4)*pow(bore,2)*stroke
	v_c=v_s/(cr-1)

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

	num_values = 50

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

	V=[]

	for i in range(0,num_values):
		theta = sc + i*dtheta
		term1 = 0.5*(cr-1)
		term2 = R+1-math.cos(theta)
		term3 = pow(R,2) - pow(math.sin(theta),2)
		term3 = pow(term3,0.5)

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

	return V	


#inputs
#pressure at state 1(before isentropic compression)
p1=101325
#Temperature at state 1(before isentropic compression)
t1=500
#Specific heat ratio
gamma=1.4
#Temperature at state 3(after constant volume heat addition)
t3=2300

#gemoetric parameters
#bore of cylinder
bore=0.1
#stroke length
stroke=0.1
#connecting rod length
con_rod=0.15
#compression ratio
cr=12

#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 | rhs = p1v1/t1 | p2v2/t2 = rhs | t2=p2v2/rhs
rhs=p1*v1/t1
t2=p2*v2/rhs
v_compression = engine_kinematics(bore, stroke, con_rod, cr,180, 0)

constant = p1*pow(v1,gamma)

p_compression = []

for v in v_compression:
	p_compression.append(constant/pow(v, gamma))


#state point 3
v3=v2

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

v_expansion = engine_kinematics(bore, stroke, con_rod, cr,0,180)

constant = p3*pow(v3,gamma)

p_expansion = []

for v in v_expansion:
	p_expansion.append(constant/pow(v, gamma))


#state point 4
v4=v1

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

#p4v4/t4 = rhs
t4=p4*v4/rhs


#calculating thermal efficieny
efficiency = 1-(1/(pow(cr,(gamma-1))))
print('Efficiency of otto cycle = ')
print(efficiency)

#plotting the PV diagram
plt.plot([v2, v3],[p2, p3])
plt.plot(v_compression,p_compression)
plt.plot(v_expansion,p_expansion)
plt.plot([v4,v1],[p4,p1])
plt.xlabel('V')
plt.ylabel('P')
plt.show()

Explanation:

  1. Initially a function is defined to calculate volume points during expansion and compression stoke varying with crank angle.
  2. The values of state 1 temperature and pressure, state 3 temperature, specific heat ratio (gamma), bore , stroke , connecting rod
    and compression ratio is given as an input.
  3. Then the values for swept volume and clearance volume are calculated.
  4. Volume at state 1 will be sum of swept volume and clearance volume and at state 2 will clearance volume.
  5. Using equation `(p2)/(p1)=((v1)/(v2))^gamma`, p2 is calculated and by `(p1*v1)/(t1)=(p2*v2)/(t2)` value of t2 is calulated.
  6. In otto cycle volume at state 2 is equal to the volume at state 3 and at state 4 is equal to at state 1.
  7. Pressure at state 3 is calculated using `p3=(p2*t3)/(t2)` and at state 4 is calculated using `p4=p3*((v3)/(v4))^gamma`.
  8. Thermal efficiency of the otto cycle is given by effciency, `η = 1 − ( 1 /( r c )^ (γ − 1) )`, where cr is compression ratio.
  9. After obtainig the value at all states the PV diagram can be plotted.

6.RESULTS :

Output window scheenshot showing efficiency-

PV diagram plot:-

7.CONCLUSION :

The PV diagram have been plotted and the thermal efficieny of the cycle is 0.62989

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.