Project

Air standard cycle

Objective:

To write code that can solve an otto cycle and the requirements are

1.Code should create a PV diagram

2.Output the thermal efficiency of the engine

Introduction:

An otto cycle is an idealized thermodynamic cycle which describes the function of a typical spark ignition piston engine. It is the thermodynamic cycle most commonly found in automobile engine.

Assumptions:

  • The working fluid is assumed to be a perfect gas.
  • There is no change in the mass of the working medium.
  • All the process that constitutes the cycle is reversible.
  • Some amount of heat will be rejected at the constant low temperature source sink during the cycle.
  • It is assumed that there are no heat losses.
  • The working medium has constant specific heats throughout the cycle.

Processes of an otto cycle:

Process 0-1 is an constant pressure mass intake.

Process 1-2 is an adiabatic compression.

Process 2-3 is an constant volume heat addition.

Process 3-4 is an adiabatic expansion.

Process 4-1 is an constant volume heat rejection.

Main program:

#otto cylcle simulation 

#importing modules
import math
import matplotlib.pyplot as plt

#defining a function
def enginekinematics(bore,stroke,con_rod,cr,start_crank,end_crank):
	a=stroke/2
	R=con_rod/a

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

	sc=math.radians(start_crank)
	ec=math.radians(end_crank)
	num=50

	dtheta=(ec-sc)/(num-1)
	v=[]
	for i in range(0,num):
		theta=sc+i*dtheta
		term1=0.5*(cr-1)
		term2=R+1- math.cos(theta)
		term3=pow((pow(R,2))-(pow(math.sin(theta),2)),0.5)
		v.append((1+term1*(term2-term3))*v_c)
	return(v)

#Main program

#inputs
gamma=1.4
bore=0.1
stroke=0.1
con_rod=0.15
cr=12

#given
p1=101325
t1=500
t3=2300

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

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

#Using engine kinematics to define volume change with pressure
constant=p1*pow(v1,gamma)
v_com=enginekinematics(bore,stroke,con_rod,cr,180,0)
p_com=[]
for j in v_com:
	p_com.append(constant/pow(j,gamma))


#state point 3
v3=v2
rhs=p2*v2/t2
p3=rhs*t3/v3

v_exp=enginekinematics(bore,stroke,con_rod,cr,0,180)
constant=p3*pow(v3,gamma)
p_exp=[]
for k in v_exp:
	p_exp.append(constant/pow(k,gamma))


#state point 4
v4=v1
p4=p3*pow(v3,gamma)/pow(v4,gamma)
rhs=p3*v3/t3
t4=p4*v4/rhs

#plotting required pv graph
plt.plot([v2,v3],[p2,p3])
plt.plot(v_com,p_com)
plt.plot(v_exp,p_exp)
plt.plot([v4,v1],[p4,p1])
plt.xlabel(\'volume\')
plt.ylabel(\'pressure\')
plt.show()

#Thermal efficiency calculation 
Thermal_efficiency=(1-(1/pow(cr,gamma-1)))*100
print(\'Thermal_efficiency=\',Thermal_efficiency)

Code explanation:

  • Initially, we are importing required modules like \'math\' and \'matplotlib.pyplot\'.
  • A function named \'enginekinematics\' is defined.
  • In which, we make use of standard formula and calculate volume change inside the cylinder during the process.
  • Then we define engine geometric parameters.
  • For state point 1 , pressure and temperatures are given as inputs so using them we calculate initial volume.
  • Simillarly we calculate for state 2 , 3 and 4.
  • Finally using the data we plot PV diagram using \'plt\' command.

Screenshot of output:

Error faced:

  • Invalid module name-

  • Invalid syntax for pow-

Errors are eazily rectified and solved.

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.