Challenge

Week 2 Air standard Cycle

"""
kinematics of engine simulation
this code is for simulating the otto cycle 
"""
import math 
import matplotlib.pyplot as plt

#defiining the function
# this is to define basic air standard equation,,
def engine_kinematics(bore, stroke, cr, con_rod, start_crank, end_crank): #we used def as func by name of engine_kinematic
	# further listed the paramters involved in equation 

	a = stroke/2 # pin radius
	R = con_rod/a #constant

	#volume parameter
	V_s = math.pi*(1/4)*pow(bore,2)*stroke # sewpt volume
	V_c = V_s/(cr-1)  # clearance volume

	sc = math.radians(start_crank)  # start point for cycle
	ec = math.radians(end_crank)  #end point of cycle
	
	num_value = 50  # no. of insant point we will capture to study the behavior

	dtheta = ec-sc/(num_value - 1)	 
	
	
	V = [] # this is to append calculated vol. value from equation 
	
	#the formulae provided to calculate the trace of volume
	for i in range(0, num_value):
		theta = sc + i*dtheta
		term1 = 0.5*(cr-1)
		term2 = R + 1 - math.cos(theta)
		term3 = pow(R,2) - pow(math.sin(theta),2)
		term4 = pow(term3,0.5)
		V.append((1 + term1*(term2 - term4))*V_c)
	return(V)

# below are some standard consideration for the values
# defining the inputs
p1 = 101325
t1 = 500
gamma = 1.4
t3 = 2300 # after combustion

#geometry parameters
cr = 12
con_rod = 0.15
bore = 0.1
stroke = 0.1

# volume computation
# using standard formulae for finding out theh values
v_s = (math.pi/4)*pow(bore,2)*stroke
v_c = v_s/(cr-1)
v1 = v_s + v_c


# state 2
#after compression completion

v2 = v_c

#p2v2^gamma = p1v1^gamma

p2 = (p1*pow(v1,gamma))/(pow(v2,gamma))

""" using ideal gas equation |
p2v2/t2 = p1v1/t1 = x
hence
t2 = p2v2/x
x = one of the constants
"""
x = p1*v1/t1    
t2 = p2*v2/x

V_compression = engine_kinematics(bore, stroke, cr , con_rod, 180, 0)
constant = p1*pow(v1,gamma) #p1v1^gamma = p_compression*v_compression^gamma = constant
P_compression = []

for v in V_compression:
	P_compression.append(constant/pow(v,gamma))


#lets see state point 3
""" 
since its contant volume heat addition v2 = v3
as per idealgas equation
p2v2/t2 = p3v3/t3 = x
"""
v3 = v2
x = p2*v2/t2
p3 = x*t3/v3

V_expansion = engine_kinematics(bore, stroke, cr , con_rod, 180, 0)
constant2 = p3*pow(v3,gamma) #p1v1^gamma = p_compression*v_compression^gamma = constant
P_expansion = []
for v in V_expansion:
	P_expansion.append(constant2/pow(v,gamma))


#conditions at state 4
""" 
v4 = v1
p4v4^gamma = p3v3^gamma
"""
v4 = v1
p4 = (p3*pow(v3,gamma))/pow(v4,gamma)

#p4v4/t4 = p3v3/t3 = x
x = p3*v3/t3
t4 = p4*v4/x


#Aim - to derice thermal efficiency for the otto cycle
# thermal eff = 1 - temp@state1 - temp@state2 
e = (1 - (t4 - t1)/(t3 - t2)) * 100

#after deriving all the paramter value  from the above equation
# we will pot the same for PV DIAGRAM of thegiven ottocycle
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.legend(["Compression", "Constant Vol. Heat add","Expansion", "Exhaust"])
plt.title(['Thermal Efficiency in % = ' + str(round(e,2),)], loc = 'right')
plt.show()

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.