Project

OTTO CYCLE

  • PV DIAGRAM PLOTTING AND TO FIND THERMAL EFFICIENCY
\"\"\"

otto cycle
Engine Kinematics

\"\"\"

import math 
import matplotlib.pyplot as plt 

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

	#geometric parameters
	#bore=bore diameter in m ; stroke in m ; connecting rod in m ; cr is compression ratio ; a= cran pin radius ; R is a constant

	a        = stroke/2
	R        = con_rod/a

	#volume computation
	#v_s = swept volume ; v_c = clearence volume
	v_s = math.pi/4*stroke*pow(bore,2)
	v_c = v_s/(cr-1)
	
	sc = math.radians(start_crank)
	ec = math.radians(end_crank)

	num_values = 1000

	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 in Bar ;temperature in kelvin
p1	  = 11
t1	  = 300
t3	  = 1370
gamma = 1.4
print(p1,\'=p1\')
print(t1,\'=t1\')
print(t3,\'=t3\')
#geometric parameters
#bore=bore diameter in cm ; stroke in cm ; connecting rod in cm ; cr is compression ratio
bore	 = 10
stroke 	 = 20
con_rod  = 150
cr       = 10

#volume computation
#v_s = swept volume ; v_c = clearence volume
v_s = math.pi/4*stroke*pow(bore,2)
v_c = v_s/(cr-1)
v1  = v_c + v_s
print(v1,\'=v1\')
print(v_c,\'=v2\')
print(v_c,\'=v3\')

#state point 2 
v2 = v_c

#for p2, p2v2^gama = p1v1^gama
p2 = p1*pow(v1/v2,gamma)
print(p2,\'=p2\')

#for t2, p2v2/t2 = p1v1/t1 ; rhs = p1v1/t1 ;t2 = p2*v2/rhs
rhs = p1*v1/t1
t2 = p2*v2/rhs
print(t2,\'=t2\')

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

constant = p1*pow(v1,gamma)
#p_compression*v_compression^gamma = constant
p_compression = []

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

 #state point 3
v3 = v2 

#t3 is given hence p3=?
#p3v3/t3=p2v2/t2 ; rhs=p2v2/t2=p1*v1/t1 ; p3=rhs*t3/v3
p3= rhs*t3/v3
print(p3,\"= p3\")


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
print(v4,\"= v4\")

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

#t4=? ;p3v3/t3 = p4v4/t4
t4=p4*v4/rhs
print(t4,\"= t4\")

#thermal efficiency=1-((t4-t1)/(t3-t2))
t_e = (1 - ((t4-t1)/(t3-t2)))
t_e = t_e *100 
print(t_e,\'= % thermal_efficiency \')

#thermal_efficiency = 1- 1/pow(r,(gamma-1))
\"\"\"
r=pow(p2/p1,1/gamma)
print(r)

thermal_efficiency = 1- 1/pow(r,(gamma-1))
print(thermal_efficiency)
\"\"\"

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.xlim(0,1800)
plt.ylim(0,530)
plt.ylabel(\'pressure\')
plt.xlabel(\"volume\")
plt.savefig(\'otto cycle\')
plt.show()



​

  • EXPLANATION

the modules should be imported.

definition is made on the variables

the formula for volume is divided into terms for esay usage

for volume calculation a loop is used,append it

return the value of volume

the inputs are given

use gas equations to find (p,v,t) at 4 state points

at compression process we define it

create an empty array for the volume compression

give a loop to find volume

similarly for expansion process we define it (note that angle changes)

create an empty array for the pressure expansion

give a loop to find pressure

after finding all the points to plot the graph

plot the graph using plt as the library

give names to the axis and limit as well

save the file and then show

the equation for thermal efficiency is known as well

input the formula and print it

RESULT= THE PROGRAM WORKED FINE AND GAVE REQUIRED GRAPH AND SHOWED THE THERMAL EFFICIENCY

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.