Challenge

Week 2 Air standard Cycle

Aim: To solve a program on Air Standard cycle in Python to solve an Otto cycle

Objective: 1. To find thermal efficiency

2. To find and solve variables in the Otto cycle and plot its P-V diagram.

Program -

"""
Air Standard Cycle : Otto Cycle Project
"""
import math
import matplotlib.pyplot as plt

#Input Values
#Values Of Gamma (for Air gamma value is 1.6)
gamma = 1.6
p1 = 112236
t1 = 550

#Assume that at the end of the combustion process temperature of charge is
t3 = 2400

#Engine Parameters
bore = 0.2 #Bore Diameter
stroke = 0.2 #Stroke Length
con_rod = 0.17 #Connecting Rod Length
cr = 14 #Compression Ratio

#Swept Volume and Clearance Volume
v_swept = (math.pi/4)*bore*bore*stroke
v_clearance = v_swept/(cr-1)

#v1 is total volume of cylinder which is equal to the sum of Swept volume
v1=v_swept+v_clearance

#v2 is volume at TDC position which is equal to clearance volume
v2=v_clearance
p2 = p1*pow(cr,gamma)

#Using Ideal gas law{pv/t=constant}
#p1v1/t1=p2v2/t2
#From above equation t2 = (p2*v2*t1)/(p1*v1)
t2 = (p2*v2*t1)/(p1*v1)

#Calculate constant c
constant_c = p1*pow(v1,gamma)

#Defining function of Engine kinematics

def engine_kinematics(bore,stroke,con_rod,cr,start_crank,end_crank):
crank=stroke/2
#Angle define
sc=math.radians(start_crank)
ec=math.radians(end_crank)
num_values=100
theta_difference = (ec-sc)/(num_values-1)

R=con_rod/crank

#Calculate Swept volume and Clearance Volume
v_swept = (math.pi/4)*bore*bore*stroke
v_clearance=v_swept/(cr-1)
v=[]

for i in range(0, num_values):
theta = sc + i * theta_difference
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_clearance)
return v

#Compression Volume
v_compression= engine_kinematics(bore,stroke,con_rod,cr,180,0)

p_compression = []

for j in v_compression :
p_compression.append(constant_c/pow(j,gamma))

#Volume at state 2 is equal to volume at stage 3
v3 = v2

#Pressure at stage 3 is determine by ideal gas law (pv/t=constant)
#p2v2/t2 = p3v3/t3
#from above equation p3=p2v2t3/v3t2
p3 = p2*(t3/t2)

#Volume of stage 4 is equal to volume of stage 1
v4=v1

constant_c1 = (p3*v3)*gamma

#Expansion Volume Trace through function
v_expansion = engine_kinematics(bore,stroke,con_rod,cr,0,180)

p_expansion = []

for k in v_expansion:
p_expansion.append(constant_c1/pow(k,gamma))

#For isnetropic expansion process{p3v3^gamma=p4v4^gamma}
#By above equation we get p4 = p3*(v3/v4)^gamma
p4 = (p3*(v3/v4)*gamma)

#Calculate thermal efficiency of cycle

efficiency = (1-(1/cr*(gamma-1)))*100

eff = "{:.2f}".format(efficiency)

print ("Efficiency of Cycle is",eff,"%")

plt.plot(v1,p1,'*r')
plt.plot(v_compression,p_compression)
plt.plot(v2,p2,'*r')
plt.plot([v2,v3],[p2,p3])
plt.plot(v3,p3,'*r')
plt.plot(v_expansion,p_expansion)
plt.plot(v4,p4,'*r')

plt.xlabel('volume')
plt.ylabel('pressure')
plt.title('Otto Cycle')
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.