Challenge

Week 2 Air standard Cycle

AIM: write code that can solve an otto cycle and make plots of it

introduction:

This assignment is about making a plot Otto cycle which derived by Nicolaus Otto, An Otto cycle is an idealized thermodynamic cycle that describes the functioning of a typical spark ignition piston engine. It is the thermodynamic cycle most commonly found in automobile engine.by working on this assignment, makes us understand how the equation is represented in the form of graph thermal efficiency of the engine is to calculated as the part of the assignment .

Code:

'''
otto cycle
'''
import math
import matplotlib.pyplot as plt
def engine_kinematics(dia,stoke,con_rod,cr,crank_start,crank_end):
    a=stoke/2
    r=con_rod/a
    cr=12
    vs=(math.pi/4)*pow(dia,2)*stoke
    vc=vs/(cr-1)
    theta_start=math.radians(crank_start)
    theta_end=math.radians(crank_end)
    num_range=150
    theta=[]
    for i in range(0,num_range):
        theta.append(theta_start+i*(theta_start-theta_end)/num_range)
    v=[]
    for j in theta:
            term1=0.5*(cr-1)
            term2=r+1-math.cos(j)
            term3=pow(r,2)-pow(math.sin(j),2)
            term3=pow(term3,0.5)
            v.append((1+term1*(term2-term3))*vc)

    return v   

#inputs
dia=0.1
stoke=0.1
con_rod=0.15
cr=12
t3=2300
vs=(math.pi/4)*pow(dia,2)*stoke
vc=vs/(cr-1)
#state point1(piston at bdc)
t1=500
p1=101325
gamma=1.4
v1=vs+vc
const=p1*v1/t1
#statepoint2(piston at tdc)
v2=vc
v_compression=engine_kinematics(dia,stoke,con_rod,cr,0,180)#(1-2 isentropic conmpression)(p1*v1^gamma=p2*v2^gamma)
p_compression=[]
for i in v_compression:
	p_compression.append(p1*pow(v1,gamma)/pow(i,gamma))
p2=p1*pow(v1,gamma)/pow(v2,gamma)
x=(v1/v2)
y=gamma-1
t2=t1*pow(x,y)
#state point 3
v3=v2
p3=p2*t3/t2
#statepoint 4
v4=v1
v_expansion=engine_kinematics(dia,stoke,con_rod,cr,180,360)
p_expansion=[]
for i in v_expansion:
	p_expansion.append(p3*pow(v3,gamma)/pow(i,gamma))


p4=p3*pow(v3,gamma)/pow(v4,gamma)
t4=p4*v4/const
efficiency=1-1/pow(cr,(gamma-1));

plt.plot([v1,v2,v3,v4],[p1,p2,p3,v4],'*')
plt.plot([v2,v3],[p2,p3])
plt.plot([v4,v1],[p4,p1])
plt.plot(v_compression,p_compression)
plt.plot(v_expansion,p_expansion)
plt.xlabel('volume')
plt.title('otto cycle')
plt.ylabel('pressure')
plt.text(v1,p1,'1')
plt.text(v2,p2,'2')
plt.text(v3,p3,'3')
plt.text(v4,p4,'4')
plt.text(0.0006,4e+6, '1-2,3-4 isentropic process')
plt.text(0.0006,5e+6,'2-3,3-4 isochoric process')
print("efficiency of otto cycle is ",efficiency)

plt.show() 

explanation:

>first we start by importing all the nessary modules and then we create a function to calculate the volume at different values of theta

>then i have declared all the necessary input parameters

>then we make equation to calculate state variables at different position of crank

>thus with the help of the function we get he values of the isentropic function

>getting all the nesssary values of state variables at different points we make a plot of it to understand it in a better way

> then efficiency of the otto cycle is calculated

conclusion :

this code makes the Otto cycle represent in the form of pv diagram and print the efficiency of the Otto cycle

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.