Project

Air Standard Cycle Simulator using Python

AIM: To create an air standard simulator for an Otto Cycle using Python

OBJECTIVES

  • To generate a P-V diagram for the Otto Cycle based on the given inputs
  • To calculate the thermal efficiency of the Otto Cycle

INTRODUCTION

PV Diagram of an Otto Cycle

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 engines.

The sub-processes that take place during an Otto cycle are:

  • Process 1-2: Isentropic compression
  • Process 2-3: Constant Volume Heat Addition
  • Process 3-4: Isentropic expansion
  • Process 4-1: Constant Volume Heat Rejection

The isentropic process of compression or expansion implies that there will be no inefficiency (loss of mechanical energy), and there be no transfer of heat into or out of the system during that process. The cylinder and piston are assumed to be impermeable to heat during that time. Work is performed on the system during the lower isentropic compression process.

Heat flows into the Otto cycle through the left pressurizing process and some of it flows back out through the right depressurizing process. The summation of the work added to the system plus the heat added minus the heat removed yields the net mechanical work generated by the system.

INPUTS

1. Temperature(T1) and Pressure(P1) at the beginning of the compression stroke. This usually corresponds to the ambient temperature and pressure.

2. Temeperature(T3) at the end of heat addition/ignition process. This temperature is usually limited by the metallurgical limits of the material used.

3. Specific heat ratio(gamma)

4. Engine geometric parameters like bore diameter,stroke length,connecting rod length and compression ratio.

FORMULA

1)`PV^(gamma)= C`

where

P = pressure

V = volume

`gamma= (Cp)/(Cv)`

`Cp`= specific heat(Constant pressure)

`Cv`= specific heat(Constant volume)

2)`V /(V c )= 1 + 1 /2 ( C R − 1 ) [ R + 1 − cos ( θ ) − ( R ^2 − ( sin ( θ ) )^ 2 )^0.5]`

where

`V` - volume during compression or expansion

`Vc` - clearance volume

`theta`- crank angle

`CR` - compression ratio

`R=(CR)/(alpha)`, where `alpha`=crank pin radius

3)`η = 1 − (1/(C R)^( γ − 1))`

where

`η` = thermal efficiency

PROGRAM CODE & PROCEDURE

Engine kinematics function

def engine_kinematics(bore,stroke,con_rod,cr,start_crank,end_crank):
	"""
	Engine Kinematics function
	"""

	#Geometric Parameters
	bore=0.1 #radius
	stroke=0.1 #length
	con_rod=0.15 #connecting rod length
	cr=12  #compression ratio
	a=stroke/2 #crankpin radius
	R=con_rod/a

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

	sc=math.radians(start_crank) #start crank
	ec=math.radians(end_crank) #end crank
	num_value=10000 #no of values

	dtheta=(ec-sc)/(num_value-1) #crank angle spacing

	#Volume trace 
	#calculating volume for particular crank angle
	
	V=[]
	for i in range(0,num_value):
		theta=sc+i*dtheta
		#dividing the formula into 3 terms
		term1=(1/2)*(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

MAIN PROGRAM CODE

# Otto cycle simulator
import math #importing math module
import matplotlib.pyplot as plt #importing module for plotting graphs

#Inputs
p1=101325 #pressure at state point 1
t1=500 #temp at state point 1
j=math.pi #value of pi saed to a variable
t3=2300

#Geometric Parameters
bore=0.1 #radius
stroke=0.1 #length
con_rod=0.15 #connecting rod length
cr=12  #compression ratio
gamma=1.4

#Volume Computation
v_s=(j/4)*pow(bore,2)*stroke #swept volume
v_c=v_s/(cr-1) #clearence volume
v1=v_c+v_s #volume at state point 1

#State Point 2
g=1.4
v2 = v_c #volume at state point 2
#p1*v1^gamma=p2*v2^gamma
p2=p1*pow(v1,g)/pow(v2,g) #pressure at state point 2
#p2v2/t2=p1v1/t1
rhs=(p1*v1)/t1#initialising RHS
t2=(p2*v2)/rhs

#Calling the function to calculate the value of v_compression for different crank angles
V_compression = engine_kinematics(bore,stroke,con_rod,cr,180,0)

constant = p1*pow(v1,gamma)
#P_compression*V_compression^gamma=constant
P_compression = []
for v in V_compression:
	P_compression.append(constant/pow(v,gamma))

#State Point 3
v3=v2

#p3v3/t3=p2v2/tw2
rhs=(p2*v2)/t2 #initialising RHS based on formula
p3=(rhs*t3)/v3 #pressure at state point 3
#Calling the function to calculate the value of v_expansion for different crank angles
V_expansion = engine_kinematics(bore,stroke,con_rod,cr,180,0)

constant = p3*pow(v3,gamma)
#P_compression*V_compression^gamma=constant
P_expansion = []
for v in V_expansion:
	P_expansion.append(constant/pow(v,gamma))

#State point 4

v4=v1 #constant volume process

#p4v4^gamma=p3v3^gamma
p4=p3*pow(v3,g)/pow(v4,g)

#p4v4/t4 = rhs4
t4 = (p4*v4)/rhs

#plotting the graph
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.title("P-V Digram of an Otto cycle")#plot header 
#Axis labels
plt.xlabel('Volume')
plt.ylabel('Pressure')

plt.show() #displays the plot

#Efficiency of the cycle
efficiency=1-pow(cr,-(gamma-1))
print("The efficiency of this cycle is",efficiency*100,"%")

EXPLANATION OF THE CYCLE

The Otto cycle consists of isentropic compression, heat addition at constant volume, isentropic expansion, and rejection of heat at constant volume. In the case of a four-stroke Otto cycle, technically there are two additional processes: one for the exhaust of waste heat and combustion products at constant pressure (isobaric), and one for the intake of cool oxygen-rich air also at constant pressure; however, these are often omitted in a simplified analysis.

Even though those two processes are critical to the functioning of a real engine, wherein the details of heat transfer and combustion chemistry are relevant, for the simplified analysis of the thermodynamic cycle, it is more convenient to assume that all of the waste-heat is removed during a single volume change.

RESULTS

  • Process 1-2: Isentropic compression - ORANGE
  • Process 2-3: Constant Volume Heat Addition- BLUE
  • Process 3-4: Isentropic expansion- GREEN
  • Process 4-1: Constant Volume Heat Rejection- RED

THERMAL EFFICIENCY

****NO ERRORS WERE GENERATED****

OBSERVATIONS

  • The efficiency of the cycle is calculated to be 63%. Hence we can assume that the given input/conditions are favourable as efficiency is greater than 50%
  • From the plot generated, we can observe that process 2-3 and 4-1 are depicted linearly due to their constant nature, whereas 1-2 and 3-4 are represented parabolicaly,owing to their isentropic nature.

CONCLUSION

Hence, using the program code above, we were able to succesfully generate a PV diagram for an Otto cycle and also calculate the thermal efficiency of the 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.