Challenge

Air standard Cycle using python

AIM:

To write a python code that can solve an otto cycle and to plot a PV diagram and also to show the the thermal efficiency of the engine.

THEORY:

An Otto cycle is an idealized thermodynamic cycle that describes the functioning of a typical spark ignition piston engine. The Otto cycle is a description of what happens to a mass of gas as it is subjected to changes of pressure, temperature, volume, addition of heat, and removal of heat. The mass of gas that is subjected to those changes is called the system. The system, in this case, is defined to be the fluid (gas) within the cylinder. By describing the changes that take place within the system, it will also describe in inverse, the system's effect on the environment.

Otto Cycle is a constant volume cycle on which petrol and gas engines work. The Otto cycle consists of 4 processes and are as follows.

  • Process 1-2: Reversible Adiabatic Compression or Isentropic Compression
  • Process 2-3: Constant Volume heat supply
  • Process 3-4: Reversible Adiabatic Expansion or Isentropic Expansion
  • Process 4-1: Constant Volume Heat Rejection

Governing equation:

  • Swept volume (Vs) ,

  • clearance volume(Vc)

  • Volume trace,

  • Isentropic process equation,

  • combined gas equation,

  • Thermal effiiciency of Otto cycle,

PROGRAM

INPUTS:

1. Engine geometric parameters;

Bore diameter=0.1m

Stroke length =0.1m

Connecting rod length= 0.15m

Compression ratio =12

2. Static variables at state point 1;

pressure=101.325 kPa

Temperature=500k

3.Static variables at state point 3;

Temperature=2300k

4.Ratio of specific heat;

gamma=1.4(for air)

CODE:

#Otto cycle simmulator
import math
import matplotlib.pyplot as py
import numpy

def engine_kinematics(bore,stroke,con_rod,cr,start_angle,end_angle):
    #engine parameters
	a=stroke/2
	R=con_rod/a

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

	sc=math.radians(start_angle)
	ec=math.radians(end_angle)
    
	num_values=50
	dtheta=(sc-ec) / (num_values - 1)
    

    #volume trace
	v=[]
	for i in range(0,num_values):
		theta=sc+(i*dtheta)
		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)
#inputs
p1=101325
t1=500
gamma=1.4
t3=2300

#engine parameters
bore=0.1
stroke=0.1
con_rod=0.15
cr=8

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

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

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

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))

#stage4
v4=v1
p4=p3*pow(v3,gamma)/pow(v4,gamma)
t4=p4*v4/rhs

#thermal efficiency 
n=(1-(1/pow(cr,(gamma-1))))*100
print('Thermal efficiency of Otto cycle=',n,'%')

py.plot([v2,v3],[p2,p3])
py.plot(v_compression,p_compression)
py.plot(v_expansion,p_expansion)
py.plot([v4,v1],[p4,p1])
py.title('AIR STANDARD OTTO CYCLE')
py.xlabel('VOLUME')
py.show()

OUTPUT:

Thermal efficiency of Otto cycle = 56.472%

PV diagram:

OBSERVATION:

The PV diagram has been plotted using process equations and the thermal efficiency has been calculated. It can be observed that the efficiency varies inversely with the compression ratio.

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.