Week 2 Air standard Cycle
import math
import matplotlib.pyplot as plt
def engine_kinemetics_function_for_volume_trace(bore,stroke,cr,con_rod,theta_start,theta_end,theta_n):
a = stroke/2
R = con_rod/a
# Volumetric parameters
v_s = (math.pi)/4 * pow(bore,2) * stroke
v_c = v_s / (cr-1)
theta_n = 10
theta = []
v = []
for i in range (0,theta_n):
temp = theta_start + i*(theta_end-theta_start)/(theta_n - 1)
theta.append(math.radians(temp))
for th1 in theta:
t1 = 0.5 * (cr - 1)
t2 = R + 1 - math.cos(th1)
t3 = pow(((pow(R, 2)) - pow(math.sin(th1), 2)), 0.5)
v_trace = v_c * (1 + (t1*(t2 - t3)))
v.append(v_trace)
return(v)
# input
bore = 0.1
stroke = 0.1
cr = 8
con_rod = 0.15
gamma = 1.4
t3 = 2000
# state 1
p1 = 101325.6
t1 = 400
v_s = (math.pi)/4 * pow(bore,2) * stroke
v_c = v_s / (cr-1)
v1 = v_c + v_s
# state 2
v2 = v_c
rhs = p1*pow(v1, gamma)
p2 = rhs / pow(v2,gamma)
t2 = (p2*v2*t1)/(p1*v1)
pcompression = []
vcompression = engine_kinemetics_function_for_volume_trace(0.1,0.1,10,0.50,180,0,10)
for v2c in vcompression:
p2c = rhs / pow(v2c,gamma)
pcompression.append(p2c)
# state 3
v3 = v2
p3 = (p2*t3)/t2
pexpansion = []
vexpansion = engine_kinemetics_function_for_volume_trace(0.1,0.1,8,0.15,0,180,20)
for v3e in vexpansion:
rhse = p3*pow(v3,gamma)
p3e = rhse / pow(v3e,gamma)
pexpansion.append(p3e)
# state 4
v4 = v1
p4 = p3*pow(v3,gamma)/pow(v4,gamma)
t4 = (t3*p4*v4)/(p3*v3)
n_thermal = 1-(((t3-t2)-(t4-t1))/(t3-t2))
print(n_thermal)
print(pow(v_c/v_s,(gamma-1)))
plt.plot([v2,v3],[p2,p3],'r')
plt.plot([v4,v1],[p4,p1],'r')
plt.plot(vcompression,pcompression,'r')
plt.plot(vexpansion,pexpansion,'r')
plt.title('p-v diagram for otto cycle using volume tracing at cr = 10')
plt.xlabel('Volume')
plt.ylabel('Pressure')
plt.grid()
plt.show()
objective:
1. Your code should create a PV diagram
2. You should output the thermal efficiency of the engine.