Project

OTTO CYCLE SIMULATOR using PYTHON

We need some known parameters in order to simulate otto cycle like

diameter of the bore, length of the stroke, length of connecting rod, compression ratio, initial temperature and pressure, etc.

For tracing the actual compression and expansion, we are using engine kinematic function.

we are calculating the state points that is (p1,v1),(p2,v2),(p3,v3),(p4,v4) and joining them using plot command

import math
import matplotlib.pyplot as plt

def engine_kinematics(bore,stroke,con_rod,cr,crank_start,crank_end):
    #volume computation
    v_s=math.pi*(1/4)*pow(bore,2)*stroke       #swept volume
    v_c=v_s/(cr-1)                             #clearance volume
    
    sc=math.radians(crank_start)               #converting the starting crank angle into radians
    ec=math.radians(crank_end)                 #converting the ending crank angle into radians
    num_values=100
    dtheta=(ec-sc)/(num_values-1)
    
    a=stroke/2                                 #a-radius of crank
    R=con_rod/a                                #R-constant
    v=[]
    
    for i in range(0,num_values):           #in this loop we are calculating the engine kinematics
        theta=sc+i*dtheta                   #in other words the actual compression and expansion path
        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
    
bore=0.1                #diameter of bore
stroke=0.1              #length of stroke
con_rod=0.15            #length of connecting rod
cr=12                   #compression ratio

p1=101325               #initial pressure
t1=500                  #initial temperature
t3=2300                 #temperature after constant volume heat addition
gamma=1.4
    

v_s=math.pi*(1/4)*pow(bore,2)*stroke
v_c=v_s/(cr-1)
    
v1=v_c+v_s

#state point 2
v2=v_c
p2=p1*pow(v1,gamma)/(pow(v2,gamma))
t2=(p2*v2*t1)/(p1*v1)

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
p3=(p2*v2*t3)/(v3*t2)


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
p4=p3*pow(v3,gamma)/(pow(v4,gamma))
t4=(p4*v4*t3)/(p3*v3)
thermal_efficiency=1-((t4-t1)/(t3-t2))
print(thermal_efficiency)

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

Thermal_efficiency comes out as 0.6298 or 62.98%

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.