Challenge

Week 2 Air standard Cycle

AIR STANDARD CYCLE - OTTO CYCLE SIMULATOR AND ENGINE KINEMATICS WITH PYTHON

AIM AND OBJECTIVE

  1. Write a code to simulate an otto cycle and make a plot for it.
  2. Output 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 Otto cycle is constructed from:

Top and bottom of the loop: a pair of quasi-parallel and isentropic processes. (adiabatic reversible).
Left and right sides of the loop: a pair of parallel isochoric processes. (constant volume).

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.

OTTO CYCLE - FIGURE

PROCEDURE

The first step is to define the state variables at points 1,2,3,4 and the processes respectively.

  • 1 -2 = reversible isentropic compression.
  • 2-3 = Constant volume heat addition.
  • 3-4 = Reversible isentropic expansion.
  • 4-1 = Constant volume heat rejection.

State variables

  • Cr = Compression ratio.
  • v1 = Volume at point 1.
  • t1 = Temperature at point 1.
  • p1. = Pressure at point 1.
  • v2 = Volume at point 2.
  • p2 = pressure at point 2.
  • t2 = Temperature at point 2.
  • t3 = Temperature at point 3.
  • v3 = Volume at point 3.
  • p3 = Pressure at point 3.
  • t4 = Temperature at point 4.
  • v4 = Volume at point 4.
  • p4 = Pressure at point 4.


In order to complete P-V Diagram we should know that volume changes from state 1 to state 2.and this actually depends on engine kinematics and in this particular problem one should start with the engine geometric parameters i.e.
i)Bore. ii) Stroke. iii) Connecting rod. iv) Compression Ratio.

Once all these parameters are defined, We initially introduce the temperature and pressure at point 1 and then calculate the swept volume as well as clearance volume of the cylinder. Pressure at point 1 is taken as 101325 Pa and temperature as 500K.
Swept volume is basically the volume of cylinder that is defined by the bore and stroke and that's equal to Vswept = n/4 * bore2 * stroke; Clearance volume is - Swept volume/ (Cr -1).

Defining swept volume as well as clearance volume leads obtaining volume V1 at point 1. As the process 1-2 is adiabatic, the pressure at 2 is obtained by the equation, p2v2^gamma = p1v1^gamma. After obtaining pressure P2, ideal gas law p1v1/t1 = p2v2/t2 is used for finding temperature at point 2. here, a variable "rhs" is used to store the value of p1v1/t1, hence finding t2.

At state point 3, the temperature t3 is assumed to be 2300K and ideal gas law is used to find the pressure p3, volume at 2 is same at 3 as it is a isochoric process.

The steps for state variables at 2 is repeated to find the state variables at point 4.

But the processes 1-2 and 3-4 are not linear processes because those are governed by equation PV^gamma which implies it should have a parabolic trajectory. ie, the piston kinematics will basically tells us how the piston actually moves from TDC to BDC and during this process how does the combustion volume chamber changes as the function of the crank angle.
And hence we will use the formula which will tell us how the volume inside the combustion chamber will going to change
V = 1 + 0.5*(cr — 1) [R + 1 — cos(θ) — (R^2 — sin^2(θ)) * V_c

Here θ is defined for a number of 50 intervals by defining the starting and ending crank angles defining various state points and the values for each θ is stored in an array to obtain the volume change for each crank angle. At point 2, the the piston is at TDC and the compressed volume is expressed from starting crank angle 180 to ending crank angle 0. At each change in volume, the pressure change is calculated and stored in an array for the compression process. These same steps are again repeated for finding the expansion process parameters after point 3.

Finally, these process are plotted to obtain the P-V diagram of an Otto cycle and is plotted using matplot library. Afterwhich the thermal efficiency of the system is calculated

PROGRAM CODE

#otto cycle simulator

import math
import matplotlib.pyplot as plt

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

	#engine kinematics
	#Geometric constraints
	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_crank)
	ec = math.radians(end_crank)

	num_values = 50

	dtheta = (ec-sc)/(num_values - 1)

	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
t3=2300
gamma=1.4


#Geometric constraints
bore=0.1
stroke=0.1
con_rod=0.15
cr=12

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

#state point 2
v2 = v_c

#p2v2^gamma = p1v1^gamma
p2 = p1*pow(v1,gamma)/pow(v2,gamma)

#Ideal Gas law, p2v2/t2 = p1v1/t1 | a new variable rhs = p1v1/t1 | rhs = p2v2/t2 | t2 = p2v2/rhs
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))


#state variables 3
v3 = v2

#As t3 is assummed here we use ideal gas law for p3, p3v3/t3 = p2v2/t2 | rhs = p2v2/t2 | p3v3/t3 = rhs | p3 = rhs*t3/v3
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))

#state variables 4
v4 = v1

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

#since rhs is same all the way, as it is a closed process, p4v4/t4 = rhs
t4 = p4*v4/rhs

#Thermal efficiency of the otto cycle
thermal_eff = (1-1/pow(cr,(gamma-1)))*100
print("The Thermal efficiency of the otto cycle is ",thermal_eff)

#Graphical representation
plt.figure()
plt.title("P-V Diagram of Otto cycle")
plt.xlabel("V")
plt.ylabel("P")
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.show()

RESULTS AND CONCLUSION

The PV diagram for the Otto cycle is obtained as below with pressure along the Y axis and Volume along the X axis. Here, the compression ratio value was taken as 12, bore diameter as 0.1m, stroke length as 0.1m, connecting rod length as 0.15m.

The thermal efficiency of the Otto cycle was calculated as 62.98 %

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.