Week 2 Air standard Cycle
# otto cycle challange - Shashi Rastogi#
import matplotlib.pyplot as plt
import math
def otto_cycle(bore,stroke,con_rod,cr,start_crank,end_crank):
a = stroke/2
R = con_rod/a
sc = math.radians(start_crank)
ed = math.radians(end_crank)
num_value = 50
V = []
dtheta = (ed-sc)/(num_value-1)
for i in range(0,num_value):
theta = sc+i*dtheta
v_s = math.pi*(1/4)*pow(bore,2)*stroke
v_c = v_s/(cr-1)
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)
r = v_c*(1+term1*(term2-term4))
V.append(r)
return(V)
#Inputs
p1 = 202650
t1 = 700
gamma = 1.4
t3 = 2500
#geometric parameters
bore = 0.1
stroke = 0.2
con_rod = 0.25
cr = 10
#volume calculatins
v_s = (math.pi/4)*bore**2*stroke
v_c = v_s/(cr-1)
v1 = v_s+v_c
#at state point 2
v2 = v_c
#p2v2^gamma = p1v1^gamma
p2 = p1*pow(v1,gamma)/pow(v2,gamma)
# t2 = t1* cr^(gamma -1)
t2 = t1*pow(cr,(gamma-1))
#state 3
v3 = v2
p3 = (p2*t3)/t2
#state 4
v4 = v1
p4 = p3*pow(v3,gamma)/pow(v4,gamma)
t4 = t3/pow(cr,(gamma-1))
Pcomp = []
c = p1*v1**gamma
V_comp = otto_cycle(bore,stroke,con_rod,cr,0,180) # compression volume corresponding to crank angles
for v_1 in V_comp:
Pcomp.append(c/v_1**gamma)
Pexp = []
c = p3*v3**gamma
V_expan = otto_cycle(bore,stroke,con_rod,cr,180,0) # expansion volume corresponding to crank angles
for v_2 in V_expan:
Pexp.append(c/v_2**gamma)
# Thermal Efficiency of otto cycle
eta = (1-1/cr**(gamma -1))
print(eta)
plt.xlabel("Volume")
plt.ylabel("Pressure")
plt.title('Otto Cycle')
plt.plot(V_comp,Pcomp,[v2,v3],[p2,p3],V_expan,Pexp,[v4,v1],[p4,p1])
plt.show()
Report
Objective - "To make a otto cycle simulator using python coding".
Problem Statement - " We have to calculate volume for different crank angle during compression and expanison stroke and also pressure corresponding to that volume , finally we have to plot the PV curve."
Solution/Methodology - we assumed some values for bore , stroke , connecting rod , compression ratio.
also we assumed some values for cycle v1,p1 ,t1, t3.
after that we used relation for adiabatic compression and expansion to calculate the remaining parameter p3,p2,t4,v4.
for intermidiate pressure and volume we used for loop codes during compression and expansion.
for thermal efficiency we used the formula for otto cycle efficiency as shown in code.
Plot
