Project

Otto Cycle - PV Diagram Visualizer using Python

AIM: write a python code that can solve an otto cycle and create a PV diagram and output the thermal efficiency of the engine.

SOLUTION:

Coding:

"""
     Otto Cycle
"""

import math
import matplotlib.pyplot as plt

#engine kinematics

def engine_kinematics(bore,stroke,con_rod,cr,start_a,end_a):
	#geometric parameters
	a=stroke/2
	r=con_rod/a

	#volume calculations
	s_v = math.pi*(1/4)*pow(bore,2)*stroke
	c_v = s_v/(cr-1)

	sc=math.radians(start_a)
	ec=math.radians(end_a)

	tot_values=50

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

	v=[]
	
	for i in range(0,tot_values):
		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))*c_v)

	return v	


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

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

#volume calculations
s_v=(math.pi/4)*pow(bore,2)*stroke
c_v=s_v/(cr-1)
v1=s_v+c_v

#calculations of state points
#state point 2
v2=c_v
p2=p1*pow(v1,gama)/pow(v2,gama)   #p2v2^gama=p1v1^gama
const=p1*v1/t1    #p2v2/t2=p1v1/t1
t2=p2*v2/const

v_compression=engine_kinematics(bore,stroke,con_rod,cr,180,0)
constant=p1*pow(v1,gama)
p_compression=[]
for v in v_compression:
	p_compression.append(constant/pow(v,gama))


#state point 3
v3=v2
const=p2*v2/t2  #p3v3/t3=p2v2/t2
p3=const*t3/v3

v_expansion=engine_kinematics(bore,stroke,con_rod,cr,0,180)
constant=p3*pow(v3,gama)
p_expansion=[]
for v in v_expansion:
	p_expansion.append(constant/pow(v,gama))


#state point 4
v4=v1
p4=p3*pow(v3,gama)/pow(v4,gama)  #p4v4^gama=p3v3^gama
t4=p4*v4/const   #p4v4/t4=const

#plotting of p-v diagram
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.xlabel('Volume')
plt.ylabel('Pressure')
plt.show()

#Thermal efficiency calculation
ct=gama-1
thermal_eff=1-pow(1/cr,ct)
print(thermal_eff)

Output:

* Thermal efficiency of the engine: 0.5647247

Report:

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

* Initally get the values of engine geometric parameters and initial state variables* Then calculating swept volume and clearance volume.

* Find out the state variables at each point.

* Plotting only state variables give wrong pv diagram.

* So we must find out the values of volume and pressure changing during compression and expansion.

*Now plot the state variables and values of volume and pressure changing during compression and expansion.

* It give a correct pv diagram as shown in the output.

* Finally calculate the thermal efficiency of the engine as shown in the coding.

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.