Challenge

PYTHON Week 2 Air standard Cycle

WEEK 2 CHALLENGE: AIR CYLINDER CYCLE

AIM:

To write a program in python for the air cylinder cycle (Otto cycle), output thermal efficiency, and plot PV diagram.

OBJECTIVE:

1) To plot a PV diagram of the otto cycle using code variables in python programming, putting the proper values and command in the functioning.

2) Also to solve the thermal efficiency using appropriate formulae and doing them accordingly.

THEORY:

The Otto cycle is also called the thermodynamics cycle that describes the functioning of the typical spark ignition piston engine. It is a thermodynamic cycle most found in automotive engines.

Otto cycle description of what happens to a mass of gas as it is subjected to changes of pressure, temperature, volume, the 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 fluid (gas) within the cylinder. By describing the changes that take place within the system, it will also describe in the inverse, the system's effect on 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 parallel isochoric processes.

Fig 1: Otto cycle

The processes of the otto cycle system are explained in the detail below and it would understand the coding to be written in the python program.

Fig 2: Processes of the Otto cycle

Process 0-1: Intake stroke (blue shade):

A mass of air(working fluid) is drawn into the cylinder or piston, the arrangement at constant pressure.

Process 1-2: compression stroke (B on diagrams):

Is an adiabatic(Isentropic) compression of the charge as the piston moves from the bottom dead center to top dead center

Process 2-3: Ignition phase (C on the diagram):

Is a constant-volume heat transfer to the working gas from the external source while the piston is at the top dead center. This process is intended to represent the ignition of the fuel-air mixture and subsequent rapid burning.

Process 3-4: Expansion stroke (D on diagram):

Is an adiabatic (Isentropic) expansion (power stroke).

Process 4-1: Idealized heat rejection (A diagram):

The mass of air is released into the atmosphere in a constant pressure process.

PROCEDURE

Coding the otto cycle:

1) First import math for mathematical function such as sin, cos, and angle. and port math plot lib. for plotting the P-V diagram.

2) Giving function to the engine_kinematics (bore, stroke, connecting_rod, cr, strat_crank, end_crank):

3) Giving value to the geometric parameter, writing code for volume parameters and stating start crak and end crank:

  • a = stroke/2
  • R = connecting_ rod
  • V_s = math.pi*(1/4)*pow(bore,2)*stroke
  • V_c = V_s/(cr-1)
  • sc = math.radians(start_crank)
  • ec = math.radians(end crank)

4) Equation for calculating volume during isentropic compression and expansion process:

v = [1+1/2.(Cr-1)[R+1 - Cosθ - √(R^2 - (sinθ) ^2)] . v_clearance.

Expanding the above formulae, so that python can recognize it through inputs and give the outputs, so the formula is a divide in A, A2, and A3 and in ti function range (0 to num values).

5) The initial inputs values of the intake stroke and geometric parameters are given to the process:

  • P1 = 10135
  • T1 = 500
  • γ = 1.4
  • T3 = 2500
  • bore = 0.1
  • stroke = 0.1
  • connecting_rod = 0.15
  • cr = 8

6) Computing the volume for v1 and v2 and for process (2-3) and

Pressure p2 = p1*pow(v1, gamma)/pow(v2, gamma) and for t2 =rhs = (p1*v1)/t1
t2 = (p2*v2)/rhs.

7) For volume and compression process between (180 to 0), calculating the P.cpmression in volume compression by giving append to it and the th code as:

V_compression = engine_kinematics (bore, stroke, connecting_rod, cr, 180, 0)

constant = p1*pow(v1,gamma)

P_compression = []

for v in V_compression:
P_compression.append(constant/pow(v,gamma)).

8) Coding for the output of P3, P4, T4, V3, and V4 and also the adiabatic expansion process where it follows the same codes:


V_expansion = engine_kinematics (bore, stroke, connecting_rod, cr, 0, 180)

constant = p3*pow(v3,gamma)

P_expansion = []

for v in V_expansion:
P_expansion.append(constant/pow(v,gamma))

8) As the otto cycle also result for the thermal efficiency which is written by the following formula in python code:

thermal_efficiency = 1 - (1/pow((connecting_rod), (gamma-1)))
print ('Thermal Efficiency of given air cylinder cycle is :', thermal_efficiency).

'''
Air standard cycle - code for otto cycle, create PV diagram, and output the thermal efficiency
By Deven Ahire
'''
import math
import matplotlib.pyplot as plt 

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

	# Geometric parameters
	a = stroke/2
	R = connecting_rod/a

	# Volume parameters
	V_s = math.pi*(1/4)*pow(bore,2)*stroke                    #V_s (swept volume)
	V_c = V_s /(cr-1)                                         #V_c (Clearance volume)

	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
		A1 = 0.5*(cr-1)
		A2 = R + 1 - math.cos(theta)
		A3 = pow(R,2) - pow(math.sin(theta),2)
		A3 = pow(A3, 0.5)

		V.append((1+ A1*(A2-A3))*V_c)

	return V 

#Inputs
p1 =101325                #Units are in (Pa)
t1 = 500                  #units are in (K)
gamma = 1.4
t3 = 2500

#Engine germotric parameters
bore = 0.1
stroke = 0.1
connecting_rod = 0.15
cr = 8

#Volume computation
V_s = (math.pi/4)*pow(bore,2)*stroke
V_c = V_s /(cr-1)
v1 = V_c + V_s                                                 #Volume at point 1

# Constant volume heat aadition process (Process 2- 3)
v2 = V_c                                                       #Volume at point 2

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

#p2v2/t2 = p1v1/t1| rhs = p2v2/t2| p3 = rhs*t3/v3
rhs = (p1*v1)/t1
t2 = (p2*v2)/rhs                                               #Temperature at point 2

# Volume and pressure compression process
V_compression = engine_kinematics (bore, stroke, connecting_rod, cr, 180, 0)  

constant = p1*pow(v1,gamma)

P_compression = []

for v in V_compression:
	P_compression.append(constant/pow(v,gamma))

#Isentropic expansion process or reverisble adabatic expansion of air (Process 3-4)

v3 = v2                                                        #Volume at point 3

#p3v3/t3 = p2v2/t2 | rhs = p2v2/t2 | p3 = rhs*t3/v3
rhs = p2*v2/t2
p3 = rhs*t3/v3                                                 #Pressure at point 3

#Volume and pressure expansion process

V_expansion = engine_kinematics (bore, stroke, connecting_rod, cr, 0, 180)  

constant = p3*pow(v3,gamma)

P_expansion = []

for v in V_expansion:
	P_expansion.append(constant/pow(v,gamma))

#Constant volume heat rejection process (Process 4-1)
v4 = v1                                                        #Volume at point 4

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

#p4v4/t4 = rhs
t4 = p4*v4/rhs                                                 #tempearture at point 4

#Calculating the thermal efficiency
thermal_efficiency = 1 - (1/pow((connecting_rod), (gamma-1)))
print ('Thermal Efficiency of given air cylinder cycle is :', thermal_efficiency)

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.xlabel("Volume")
plt.ylabel("Pressure")
plt.title("PV Diagram of otto cycle")
plt.show()

RESULTS:

For PV diagram of the otto cycle plotting by volume and pressure diagram, writing by code mentioned below.

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.xlabel("Volume")
plt.ylabel("Pressure")
plt.title("PV Diagram of otto cycle")
plt.show()

Fig 3: P-V Diagram of the otto cycle

The thermal efficiency of a given air cylinder cycle is:( -1.1358143316912037).

The python code screenshot:

--------------------------------------------------------------------------------------------------------------------Model and file link: https://drive.google.com/drive/folders/1u2ShnQJwfw-n383_A7g3wABO0oQDWNJR?usp=sharing

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.