Project

Python Project 3 : Air Standard Cycle : Otto Cycle

AIM:

To Plot P-V diagram of Air Standard Cycle

Problem Statement :-

Write Python code that can solve an Otto cycle and make plots for it.

Answer should include a PV diagram and Output the thermal efficiency of cycle.

Theory :-

An Otto cycle is an idealized thermodynamic cycle that describes the functioning of a typical spark ignition piston engine. Otto cycle is made up from four processes as shown in figure.

Process 1-2 Isentropic Compression Process

Process 2-3 Constant volume heat addition process

process 3-4 Isentropic Expansion Process

Process 4-1 Constant volume heat rejection process.

On this four processes an Otto cycle works.

Main Formula Used:-

  • For Isentropic process pv^gamma=constant
  • Volume Trace V = (1 + {0.5*(cr-1)}{R + 1 - cos(theta)- (R^2 -sin(theta)^2)^0.5}
  • Theramal efficiency = 1- 1/(cr^(gamma-1))

Procedure to create Python program :-

  • To plot the data on PV diagram first we define some data related to cycle and then calculate other required data.
  • Let we assume that we already know following data i.e. P1 , T1 , T3, Bore diameter, Stroke Length, Connecting Rod Length, Compression ratio. We treat this data as predefine data.
  • We also take some standard data i.g value of Gamma for air.
  • After the defining all this data we will calculate other data using standard formulas.
  • After calulation the various state data we use plot command to plot this data in graphical form.
  • A function is created for calculation volume trace by using volume trace formula.
  • All this data is ploted and get desire result.

Python Codes : -

Following codes are use to plot the PV diagram and thermal efficiency.(Google Colab is use for this analysis)

''' Air Standard Cycle : Otto Cycle Project'''
import math
import matplotlib.pyplot as plt

# Input Values
# Value of Gamma (for Air gamma value is 1.4)
gamma = 1.4 

# State number 1 variable
p1 = 101125  
t1 = 550 

# Assume that at the end of the combustion process temperature of charge is 2300 K, So we take it as an input
t3 = 2300 

# Engine Geometric Parameters

bore = 0.1         # Bore Diameter
stroke = 0.1       # Stroke Length
con_rod = 0.15     # Connecting Rod Length
cr = 12            # Compression Ratio

# Caculating the Swept volume and Clearance Volume
v_swept = (math.pi/4)*bore*bore*stroke
v_clearance = v_swept/(cr-1)

# v1 is Total volume of Cylinder which is equal to the sum of Swept volume and Clearance volume
v1 = v_swept+v_clearance

# v2 is volume at TDC position which is equal to clearance volume
v2 = v_clearance

# Calculating State variable at state point 2
# Isentropic compression process from State 1 to state 2

# For Isentropic compression process {p1v1^gamma = p2v2^gamma} 
# By above equation we get p2 = p1*(v1/v2)^gamma = p1*cr^gamma  
# cr is known as (v1/v2)

p2 = p1*pow(cr,gamma) 

# Using Ideal gas law { pv/t =constant }
# p1v1/t1 = p2v2/t2
# From above equation t2 = (p2*v2*t1)/(p1*v1)
t2 = (p2*v2*t1)/(p1*v1)

# It is known that for Isentropic compression process pv^gamma = constant
# Here calculating the constant c
constant_c = p1*pow(v1,gamma)

# Defining function of engine kinematics

def engine_kinematics(bore, stroke, con_rod, cr, start_crank, end_crank) :
  crank = stroke/2                             # Crank Radius
  # Angle define
  sc = math.radians(start_crank)
  ec = math.radians(end_crank)
  numvalues=100
  theta_difference=(ec-sc)/(numvalues-1)
  
  R = con_rod / crank 

  # Caculating the Swept volume and Clearance Volume
  v_swept = (math.pi/4)*bore*bore*stroke
  v_clearance = v_swept/(cr-1)


  # Define the equation 
  # V = (1 + {0.5*(cr-1)}{R + 1 - cos(theta)- (R^2 -sin(theta)^2)^0.5}
  # Divide this equation in various term and then calculate
  V = []
  for i in range(0,numvalues):
    theta=sc+i*theta_difference
    term1 = 0.5*(cr-1)
    term2 = R + 1 - math.cos(theta)
    term3 = (R*R - math.sin(theta)**2)**0.5

    V.append((1 + term1*(term2 - term3))*v_clearance)
  return V

# Compression Volume Trace through function calling
V_compression = engine_kinematics(bore, stroke, con_rod, cr, 180, 0)

# Compute pressure change with volume trace through equation pv^gamma =constant
P_compression=[]
for j in V_compression :
  P_compression.append(constant_c/pow(j,gamma))


# Calculating State variable at state point 3
# Constant volume heat addition process from State 2 to state 3

# Volume at state 2 is equal to volume at state 3
v3 = v2  

# Pressure at state 3 is determine by ideal gas law (pv/t =constant)
# p2v2/t2 = p3v3/t3 
# From above equation p3 = p2v2t3/v3t2
p3 = p2*(t3/t2)


# Calculating State variable at state point 4
# Isentropic expansion process from State 3 to state 4

# Volume of state 4 is equal to volume of state 1
v4 = v1 

# It is known that for Isentropic expansion process pv^gamma = constant
# Here calculating the constant c
constant_c1 = p3*v3**gamma

# Expansion Volume Trace through function calling
V_expansion = engine_kinematics(bore, stroke, con_rod, cr, 0, 180)

# Compute pressure change with volume trace through equation pv^gamma =constant
P_expansion=[]
for k in V_expansion:
  P_expansion.append(constant_c1/pow(k,gamma))

# For isentropic expansion process {p3v3^gamma = p4v4^gamma} 
# By above equation we get p4 = p3*(v3/v4)^gamma
p4 = p3*(v3/v4)**gamma 

# Calculationg Thermal Efficiency of Cycle
# Formula used efficiency = 1- 1/(cr^(gamma-1))
efficiency = (1- 1/(cr**(gamma-1)))*100
eff = "{:.2f}".format(efficiency)
print("Efficiency of Cycle is",eff,"%")
 
# Plot the Cycle

plt.plot(v1,p1,'*r')
plt.plot(V_compression,P_compression)
plt.plot(v2,p2,'*r')
plt.plot([v2,v3],[p2,p3])
plt.plot(v3,p3,'*r')
plt.plot(V_expansion,P_expansion)
plt.plot(v4,p4,'*r')
plt.plot([v4,v1],[p4,p1])

plt.xlabel('volume')
plt.ylabel('pressure')
plt.title('Otto Cycle')
plt.show()

Result :-

After the run the program following output of program is displayed.

Conclusion :

Successfully analysis thermal efficiency of Otto cycle and plot P-V diagram of 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.