Project

Otto cycle simulation using python

AIM : To write a program in python to plot the P-V diagram of the otto cycle and calculate the thermal efficiency of the cycle.

THEORY :

\"\"

  • 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 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. In the case of the Otto cycle, the effect will be to produce enough net work from the system so as to propel an automobile and its occupants in the environment.
  • The Otto cycle is constructed from:
Top and bottom of the loop: a pair of quasi-parallel and isentropic processes (frictionless, adiabatic reversible).
Left and right sides of the loop: a pair of parallel isochoric processes (constant volume).
  • 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. Hence the cylinder, and piston are assumed 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.
  • The processes are described by:

    • Process 0–1 a mass of air is drawn into piston/cylinder arrangement at constant pressure.
    • Process 1–2 is an adiabatic (isentropic) compression of the charge as the piston moves from bottom dead centre (BDC) to top dead centre (TDC).
    • Process 2–3 is a constant-volume heat transfer to the working gas from an external source while the piston is at top dead centre. This process is intended to represent the ignition of the fuel-air mixture and the subsequent rapid burning.
    • Process 3–4 is an adiabatic (isentropic) expansion (power stroke).
    • Process 4–1 completes the cycle by a constant-volume process in which heat is rejected from the air while the piston is at bottom dead centre.
    • Process 1–0 the mass of air is released to the atmosphere in a constant pressure process.

    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.

PROCEDURE FOR WRITTING THE CODE:

(1)First we create a function (‘piston_kinematics’) which creates an array of chamber volume as a function of crank angle.

(2)The inputs of the function are bore, stroke, connecting rod length (‘con_rod’), compression ratio (‘cr’), crank start angle, crank end angle.

(3)After that the state point formulas were defined.

(4)Finally the engine kinematics function was used the get the compression expansion line.

(5)After that the plot was made.

(6)Finally the thermal efficiency formula was defined and printed out.

MAIN CODE:

#Otto cycle simulator
import math
import matplotlib.pyplot as plt

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


  
	  a = stroke/2
	  n = con_rod/a

      # swept volume
	  v_s = p1*pow(bore,2)*stroke/4

	  #Clearance volume
	  v_c = v_s/(cr-1) 

	  #Defining the starting crank angle
	  starting_crank = math.radians(start_crank)

	  #Defining the ending crank angle
	  ending_crank = math.radians(end_crank) 

	  #Number of values of theta
	  num_values = 50

	  #For different values of theta we need to make an empty array of v and then append it each time the loop iterates
	  v = []

	  for i in range(0,num_values):
	    theta = starting_crank+i*(ending_crank-starting_crank)/(num_values-1)
	    
	 
	# Using v/v_c = 1+0.5*(cr-1)*[n+1-cos(theta)-(n^2-sin^2(theta))^0.5]
	# where v is the volume inside the cylinder at any crank angle 

	#splitting the equation into smaller parts
	    t1 = 0.5*(cr-1)
	    t2 = n+1-math.cos(theta)
	    t3 = pow(pow(n,2)-pow(math.sin(theta),2),0.5)
	    v.append((1+t1*(t2-t3))*v_c)
	   
	  return v
  
 
#Inputs

#Pressure at state 1
p1 = 101325

#Temperature at state 1
t1 = 500

#Maximum temperature of the cycle
t3 = 2500

gamma = 1.4
bore = 0.1
stroke = 0.2

#Length of connecting rod
con_rod = 0.15

#compression ratio
cr = 8

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

v1 = v_s+v_c
v2 = v_c

#1-2 is an adiabatic process (PV^gamma=constant)
p2 = p1*pow(v1/v2,gamma)

#Using the ideal gas equation
t2 = p2*v2*t1/(p1*v1)

#At state point 3
v3 = v2
p3 = p2*v2*t3/(v3*t2)

#At state point 4
v4 = v1

#3-4 is an adiabatic process
p4 = p3*pow(v3/v4,gamma)

#Using the ideas gas equation
t4 = p4*v4*t3/(p3*v3)

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

#using constant=P1*V1^gamma
c1 = p1*pow(v1,gamma)

#For each vale of volume compression calculating the value of pressure compression
p_compression = []
for volume in v_compression:
     p_compression.append(c1/pow(volume,gamma))
     
#calling the function to calculate the value of v_expansion
v_expansion = engine_kinematics(bore,stroke,con_rod,cr,0,180)

#using constant=P3*V3^gamma
c3 = p3*pow(v3,gamma)

p_expansion = []
#For each vale of volume expansion calculating the value of pressure expansion
for volume in v_expansion:
  p_expansion.append(c3/pow(volume,gamma))

#Plotting the graph to visualise the cycle
plt.plot(v_compression,p_compression)
plt.plot([v2,v3],[p2,p3])
plt.plot(v_expansion,p_expansion)
plt.plot([v4,v1],[p4,p1])
plt.xlabel(\'Volume\')
plt.ylabel(\'Pressure\')
plt.show()

#calculating efficiency of the cycle
Efficiency_of_cycle=1-pow(cr,-(gamma-1))
print(\'Efficiency_of_cycle=\',Efficiency_of_cycle)

OUPUT GRAPH:

\"\"

THERMAL EFFICIENCY:

\"\"

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.