Project

OTTO CYCLE P-V DIAGRAM AND EFFICIENCY python

1) Main Program

\"\"\"
Otto cycle by MAK
\"\"\"
import math
import matplotlib.pyplot as plt
import numpy as np

#function definition

def eng_varfunc(bore,stroke,con_rod,cr,start_crank,end_crank):

			a=stroke/2
			r=con_rod/a
			v_s=math.pi/4*pow(bore,2)*stroke
			v_c=v_s/(cr-1)
			v_1=[]


			theta=np.linspace(start_crank,end_crank,100)
			theta=np.radians(theta)
			for t in theta:

				term1=0.5*(cr-1)
				term2=r+1-math.cos(t)
				term3=pow((pow(r,2)-pow(math.sin(t),2)),0.5)
				v_1.append((1+term1*(term2-term3))*v_c)
			    
			return v_1






p1=202650
t1=500
t3=2500

#geometric parameters

bore=0.1
stroke=0.1
con_rod=0.15
cr=16
gam=1.4

#volume computation

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


#state 1

p1=101325
v1=v_c+v_s
print(\"p1 is:\",p1)
print(\"v1 is:\",v1)

#state 2

p2=p1*pow(cr,gam)
v2=v1/cr
print(\"p2 is:\",p2)
print(\"v2 is:\",v2)

t2=t1*pow(cr,gam-1)

#state 3

v3=v2
p3=t3*(p2/t2)
print(\"p3 is:\",p3)
print(\"v3 is:\",v3)

v_comp=eng_varfunc(bore,stroke,con_rod,cr,180,0)
const1=p1*pow(v1,gam)
p_comp=const1/np.power(v_comp,gam)

#state 4

v4=v1
p4=p3*(pow(cr,-gam))
print(\"p4 is:\",p4)
print(\"v4 is:\",v4)

v_exp=eng_varfunc(bore,stroke,con_rod,cr,0,180)
const2=p3*pow(v3,gam)
p_exp=const2/np.power(v_exp,gam)

#efficiency calculation

rk=v1/v2
ntherm=1-(1/pow(rk,gam-1))
print(\"EFFICIENCY OF THE ENGINE IS:    \",ntherm)


#plotting
	
plt.plot(v_comp,p_comp)
plt.plot(v_exp,p_exp)
plt.plot([v2,v3],[p2,p3])
plt.plot([v1,v4],[p1,p4])
plt.title(\'Otto Cycle: P-V diagram\')
plt.xlabel(\'Volume\')
plt.ylabel(\'Pressure\')
plt.show()

2) Output and Plot

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.