Challenge

Week 2 Air standard Cycle

import math 
import matplotlib.pyplot as plt

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

	#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)
	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
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)
#p2v2/t2 = p1v1/t1 | rhs = p1v1/t1 | p2v2/t2 = rhs | t2 = p2v2/rhs
rhs = p1*v1/t1
t2 = p2*v2/rhs

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 point 3
v3 = v2 
#p3v3/t3 = p2v2/t2 | rhs = p2v2/t2 | p3 = rhs*t3/v3
rhs = p2*v2/t2
p3 = rhs*t3/v3

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 = rhs
t4 = p4*v4/rhs

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.show()

#calculating thermal efficiency | where n = efficiency | n = (1-(1/(cr^gamma-1)))*100
#gamma - 1 = b
b = gamma - 1
n = (1-(1/pow(cr,b)))*100
print(n)

Objetive :

Based on the concepts you have learnt during the forward kinematics routine, go ahead and write code that can solve an otto cycle and make plots for it.

  1. Your code should create a PV diagram
  2. You should output the thermal efficiency of the engine.

Problem statement :

Based on the concepts you have learnt during the forward kinematics routine, go ahead and write code that can solve an otto cycle and make plots for it

Solution procedure :

Step wise explanation of engine kinematics :

  1. First of all we have to make the otto cycle function code in which we have to define the geometric parameters which are bore , stroke , cr, con_rod
  2. Now we have to define equation , for that we do one thing which is divide that equation in 3 parts and name its as term1 , term2, term3 and then arrange 3 of them according to equation by equalizing it as V
  3. Now our function part is over lets move to main script in this scripts first lets import libraries then lets calculate swept volume and clearance volume
  4. Next to that we have to find the pressure , volume , and temperature for all the four points (p1,v1,t2|p2,v2,t2|p3,v3,t3|p4,v4,t4) by using ideal equation (p1v1/t1 = p2v2/t2 |p3v3/t3 = p3v2/t2 | p4v4^gamma = p3v3^gamma ) in which we have the data of p1 ,t1 ,gamma ,and t3 using those parameters we have to find other parameters.
  5. Now after ploting this above details we got the plot but that plot is not that much good or clear so to make it look good and actual PV chart we create the function now its time to use that function in our main script so we give this following command in main script to define function

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

  1. And after giving that statement we have to copy all the data from function script and paste it in main script under the function statement and yes one more important thing to do in this which is take that all the 3 term of equation in for loop just like given below by taking the full care of spaces. The following code we do for defining our theta and range of crank from starting point to ending point (num values is the number of values lies between starting point and ending point which we gives to 50)

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

  1. And yes all these things we have to do just below the Imports statements (between imported libraries and p1)
  2. now as our point 2 and point 3 is compression and expansion part respectively so leaving state point 1 and 4 as it is we have to make slight changes in point 2 and 3 first lets go to state point 2 where we define V_compression as it is compression stage by using the statement ” V_compression = engine_kinematics(bore, stroke, con_rod, cr, 180, 0) “ while doing this we have to keep thing in mind that we have to arrange the statement as it is in function statement with same format. We completed v_compression now its time for p_compression and for that we have to create the for loop cause we need number of values in that hence we gives it with append command “P_compression.append(constant/pow(v,gamma)) ” in which constant is define by equation constant=p2v2^gamma
  3. now we completed compression part lets move to expansion for that we have to go through same path just replace the expansion in place of compression and change points in constant formula (constant=p3v3^gamma)
  4. and now our last and final point which is plot the chart for which we use the set of plot statements which are follows in which we can see that point 2 to 3 And 4 to 1 is straight line so we plot it directly and 1 to 2 and 3 to 4 is curved part which is compression and expansion

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.show()

  1. one more thing is asked in question which is to calculate thermal efficiency of above air standard program so to calculate thermal efficiency first lets take n as thermal efficiency then we have equation to calculate the thermal efficiency n = (1-(1/(cr^gamma-1)))*100 . to make it look simple we take b = gamma – 1 so our new equation in make will be

n = (1-(1/(cr^b)))*100 using this we can easily get thermal efficiency .

Result :

In result we create a pv diagram for air standard cycle and find its 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.