Project

Otto Cycle

AIM: To solve an otto cycle and make plots with the given information

OBJECTIVE:

1. To code and create a PV diagram for Otto cycle

2. To compute and output the thermal efficiency of the engine.

Otto Cycle:

On this cycle, petrol, gas and many types of oil engines work.

  • 1→2: Adiabatic compression
  • 2→3: Heat addition at constant volume
  • 3→4: Adiabatic expansion
  • 4→1: Heat rejection at constant volume
  • Efficiency`η=1-(1/r^(γ-1))`

PROGRAMMING LANGUAGE USED: PYTHON

CODE:

#OTTO CYCLE SIMULATOR

import math
import matplotlib.pyplot as plt
#import engine_kinematics.py as exg
def engine_kinematics(bore,stroke,con_rod,cr,start_crank,end_crank):
	
	import math
	#ENGINE KINEMATICS
	#geometric parameters
	
	a=stroke/2
	R=con_rod/a
	#volume computation
	v_s=(math.pi/4)*pow(bore,2)*stroke
	v_c=v_s/(cr-1)
	v1 = v_c + v_s

	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
p1=101325 # pressure in pascals
t1=500 # temperature in Kelvin
t3=2300

#geomentric parameters
bore= 0.1
stroke = 0.1
con_rod=0.15
cr = 5
gama=1.4

#volume computation
v_s=(math.pi/4)*pow(bore,2)*stroke
v_c=v_s/(cr-1)
v1 = v_c + v_s
"""
STATES
"""

#state point 1
p1
v1
t1

#state point 2
v2=v_c
#to calcuate pressure
#pv^gama=const >> p2=p1(v1/v2)^gama
p2=(p1*pow(v1,gama))/pow(v2,gama)
#to calculate temperature
#pv/t = const >> p1v1/t1=p2v2/t2
const=(p1*v1)/t1
t2=(p2*v2)/const


#state point 3
v3=v2 #constant volume
t3 # is known
#pv/t = const >> p3v3/t3=p2v2/t2
const=(p2*v2)/t2
p3=const*(t3/v3)

#state point 4
v4=v1 #constant volume
#to calculate pressure
#pv^gama=const >> p4=p3(v3/v4)^gama
p4=(p3*pow(v3,gama))/pow(v4,gama)
#to calculate temperature
#pv/t = const >> p3v3/t3=p4v4/t4
t4=(p4*v4)/const

#variation of pressure and volume in adiabatic compression
V_compression = engine_kinematics(bore,stroke,con_rod,cr,180,0)
constant=p1*pow(v1,gama)
P_compression=[]
#P_compression*V_compression^gama=constant
for v in V_compression:
	P_compression.append(constant/pow(v,gama))

#variation of pressure and volume in adiabatic expansion
V_expansion = engine_kinematics(bore,stroke,con_rod,cr,0,180)
constant=p3*pow(v3,gama)
P_expansion=[]
#P_compression*V_compression^gama=constant
for v in V_expansion:
	P_expansion.append(constant/pow(v,gama))

#calculating the efficency
efficency_of_Otto_cycle=1-(1/pow(cr,(gama-1)))
print(efficency_of_Otto_cycle)	


plt.plot([v1,v2,v3,v4],[p1,p2,p3,p4],'ro')
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('volume')
plt.ylabel('pressure')
plt.title('P-V Diagram of Otto cycle')
filename='Otto_cycle.png'
plt.savefig(filename)
plt.show()



EXPLANATION TO THE CODE:

  • Import math and matplotlib modules after creating a new file with .py extension.
  • Calculate all the state points based on thermodynamic relations.
  • Create a separate function to calculate the variation volume during the adiabatic process and thereby compute the variations of pressure.
  • Make use of the engine kinematics to calculate the initial volume.
  • Keep the code in the same line to avoid indentation errors while using for loop and defining the function.
  • After computing all the state points and volume, pressure variations use the plot command to plot the indicator diagram.
  • add the additional information like x-axis, y-axis labels and title using matplotlib.

RESULTS:

efficiency: My efficiency is less as my compression ratio is less, I took less compression ratio because my 4 to 1 process is visible

efficiency=0.47469443911924647

INDICATOR DIAGRAM:

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.