Challenge

Week 2 Air standard Cycle

AIM: To write a code to solve the otto cycle and make PV diagram plot using Python.

Theory:

Otto cycle

The Otto cycle is a cycle of engine operation which requires four strokes of the piston: for induction, compression, ignition, and exhaust. The fuel and air mixture is compressed before combustion is started by an electrical spark or other means. Named after German engineer Nikolaus Otto.

The Otto cycle is a description of what happens to a mass of gas as it is subjected to changes of pressure, temperature, volume, addition of heat, and removal of heat. The mass of gas that is subjected to those changes is called the system. The system, in this case, is defined to be the fluid (gas) within the cylinder. By describing the changes that take place within the system, it will also describe in inverse, the system's effect on the environment. In the case of the Otto cycle, the effect will be to produce enough net work from the system so as to propel an automobile and its occupants in the environment.

The processes involved in the cycle are
1-2 : Isentropic (Adiabatic) Compression
2-3 : Constant Volume Heat Addition
3-4 : Isentropic (Adiabatic) Expansion
4-1 : Constamt Volume Heat Rejection

Implementation:

The geometric parameters and the initial required inputs like pressure, temperature and specific heat ratio(gamma) are given initially. Then the swept and clearance volumes are evaluated to find the volume at state 1. Then the respective pressure, volume and temperatures are found at each state following the processes involved in the otto cycle. Then from the found values plots are made using the python code.

The following are the equations used to evaluate the parameters for the processes.

`(PV)/T=` constant , which is an ideal gas law and used for the constant volume processes`

`PV^gamma=`constant , is used for the adiabatic (isentropic) processes`

The formed plot would be linear which isn't correct so to simulate the real life otto cylce we need to evaluate the parameters of the processes at various angles of the piston i.e. obeying to the piston kinematics, find the variation of the volume changes in the process. There by creating a function by name engine_kinematics with inputs as bore, stroke, connecting rod length, compression ratio, start and end angles of the piston position. Here the following equation is used to find the volume with respect to the various angles i.e. motion of the piston.

where,

V - volume at the particular angle `theta`

`V_c` - clearance volume

`r_c` - compression ratio

R - ratio of connecting rod to crank pin radius and crank pic radius is half of the stroke.

Doing so, each found value of the volume is stored in an empty array and then later this array is used to find the corresponding pressure value in order to create a plot that gives the real otto cycle PV diagram.

The following is the code for the Otto cylce simualtion that consists of the main code along with the function engine_kinematics

import math
import matplotlib.pyplot as plt

''' otto cycle simulator'''

def engine_kinematics(bore,stroke,con_rod,cr,start_crank,end_crank):
	'''
	engine kinematics
	'''
	import math
	#Geometric parameters

	a=stroke/2
	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) #to get the interval difference

	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((pow(R,2) - pow(math.sin(theta),2)),0.5)

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

	return V



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

#geometric parameters
bore= 0.1
stroke = 0.1
con_rod = 0.15
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)

# ideal gas law p2v2/t2 = p1v1/t1 | rhs = p1v1/t1 | p2v2/t2 = rhs | t2= p2v2/rhs
rhs= p1*v1/t1
t2= p2*v2/rhs

%finding the intermediate volume values between the states 1 to 2
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 3 afetr const vol heat addition
v3=v2

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

%finding the intermediate volume values between the states 3 to 4
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 = p3v3/t3 |rha= p3v3/t3|t4=p4v4/rhs
rhs=p3*v3/t3 #though rhs is same throughout the program
t4 = p4*v4/rhs 

#thermal efficiency of the otto cycle
efficiency=1-pow((v2/v1),gamma-1)
print('Thermal efficiency=',100*efficiency,'%')

plt.plot(V_compression,P_compression, label='isentropic compression')
plt.plot([v2,v3],[p2,p3],label ='constant volume heat addition')
plt.plot(V_expansion,P_expansion,label='isentropic expansion')
plt.plot([v4,v1],[p4,p1],label='constant volume heat rejection')
plt.xlabel('volume')
plt.ylabel('pressure')
plt.title('PV diagram for ottocycle')
plt.legend()
plt.savefig('pv diagram')
plt.show()

The thermal efficiency of the simulated ottocyle is also found using the followinf formula.

`eta=1-(V_2/V_1)^(gamma-1)=1-(1/r_c)^(gamma-1)`

The output from the above code

The thermal efficiency is about 62.98% for the above simulation of the code.

Conclusion : The efficiency of the otto cylce was found usinf the above code in python and also the PV diagram is also well plotted near to the real life otto cycle PV diagram.

References:

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.