Challenge

Week 2 Air standard Cycle

Aim: 
Write a program in Python to solve and graph the Otto cycle.
Objective :
Solve and capture the various state variables of the Otto cycle and plot its p-V diagram. Calculation of the thermal efficiency of a given Otto cycle. 

Theory:
 The Otto cycle is the ideal cycle for a spark-ignited reciprocating engine. In most spark-ignited engines, the piston completes four strokes (two mechanical cycles) in the cylinder, and the crankshaft completes two revolutions in each thermodynamic cycle. These engines are called 4-stroke internal combustion engines.
 Initially, both the intake and exhaust valves are closed and the piston is in its lowest position (BDC). On the compression stroke, the piston rises and compresses the air-fuel mixture. Just before the piston reaches its top position (TDC), the spark plug and mixture are ignited.
It ignites and increases system pressure and temperature. High pressure gas pushes the piston down, which rotates the crankshaft, creating useful work during the expansion or power stroke. At the end of this stroke, the piston is in its lowest position (completed).
of the first mechanical cycle), the cylinder fills with combustion products. Here, the piston rises again to expel exhaust gases through the exhaust valve (exhaust stroke) and then descends a second time to draw in fresh mixture through the intake valve (intake).
stroke).
 Note that the pressure in the cylinder is slightly higher than atmospheric pressure during the exhaust stroke and slightly lower during the intake stroke. 
The four processes in an Otto cycle are:
 Isentropic compression process or Reversible adiabatic compression of air (Process 1-2),
Constant volume heat addition process (Process 2-3),
Isentropic expansion process or Reversible adiabatic expansion of air (Process 3-4),
Constant volume heat rejection process (Process 4-1). 
Explanation of the Python code:
 1.Since the Otto cycle is a standard air cycle, the specific heat of air (γ) is assumed to be 1.4.
2. Initial conditions such as ambient temperature (T1) and pressure (p1) are assumed to be 350 K and 101.325 kPa, respectively. 
3.The engine cylinder geometry, consisting of bore diameter, stroke length, and connecting rod length, is also known, and vs and vc are calculated accordingly. 
4.We also know the maximum temperature (T3) that will occur in the cylinder. 
5. Other state variables are calculated using the adiabatic process equation and the ideal gas equation. 
6. Thermal efficiency is calculated accordingly using the given formula. 
7.Plotting state variables computed using only the plt.plot command on a p-v plot produces an incorrect p-v plot. H. Compression stroke and expansion stroke are represented by straight lines. 
8.To correct this, another feature is provided to store different values of crank angle rotation when compression and expansion occur on different strokes or cycles. This function is then called by the main program and accordingly the figure is drawn from the various points obtained. 
9.This number of values that the program iterates over is 100, so the v array is zeroed out and after each iteration in the for loop the new values are stored as an array with the "append" command and after getting the desired value returned. 
CONCLUSION : 
The desired and correct p-V diagram of Otto cycle was obtained using an array of volume inside the engine cylinder at different crank angle.

MAIN CODE:


''' A program to calculate different  variables in an Otto Cycle and 
to calculate its thermal efficiency and plot it on p-v diagram '''

import math
import matplotlib.pyplot as plt 

def engine_kinematics(bore,stroke,connecting_rod,c_r,start_crank_angle,end_crank_angle):

	# Engine geometry properties
	r = stroke/2
	n = connecting_rod/r

	# Volume parameters

	v_swept = (math.pi/4)*pow(bore,2)*stroke
	v_clearance = v_swept/(c_r -1) 

	theta_startcrank = math.radians(start_crank_angle)
	theta_endcrank   = math.radians(end_crank_angle)  

	num_val = 100
	dtheta = (theta_endcrank - theta_startcrank)/(num_val - 1)
	V = []
	for i in range(0,num_val):
		theta = theta_startcrank + i*dtheta
		term_1 = 0.5*(c_r - 1)                               
		term_2 = n + 1 - math.cos(theta)
		term_3 = (pow(n,2) - pow(math.sin(theta),2))
		term_3 = pow(term_3,0.5)
		V.append((1 + term_1* (term_2 -term_3))*v_clearance)

	return V

# Inputs varibale

gamma = 1.4                                  # for air gamma= 1.4
T3 = 2000                                    # max temp inside engine cyr

# State variable
# ambient atmospheric conditions assumed
p1 = 101325                            
T1 = 350                                    
 
# Engine geometry properties
 
bore = 0.15
stroke = 0.2
connecting_rod = 0.8
c_r = 10

# Calculating swept volume and clearance volume
 
v_swept = (math.pi/4)*pow(bore,2)*stroke
v_clearance = v_swept/(c_r -1) 
v1 = v_swept + v_clearance
v2 = v_clearance
  
# state variables at state point 2          
# p2*v2^gamma = p1*v1^gamma --- Isentropic compression
 
p2 = p1* pow(c_r,gamma)

# (p1*v1)/T1 = (p2*v2)/T2 | T2 = p2*v2*T1/(p1*v1)
 
T2 = p2*v2*T1/(p1*v1)
 
V_comp = engine_kinematics(bore,stroke,connecting_rod,c_r,180,0)
C_const = p1*pow(v1,gamma)
P_comp = []
for v in V_comp:
	P_comp.append(C_const/pow(v,gamma))

 
# State variables at state point 3
 
v3 = v2                                        # Isochoric process
  
''' (p3*v3)/T3 = (p2*v2)/T2 | p3 = p2*T3/(T2) '''
 
p3 = p2*T3/(T2)

V_expp = engine_kinematics(bore,stroke,connecting_rod,c_r,0,180)
C_const = p3*pow(v3,gamma)
P_expp = []
for v in V_expp:
	P_expp.append(C_const/pow(v,gamma)) 
	
# state variables at state point 4
v4 = v1                                       # Isochoric process  
 
''' p3*v3^gamma = p4*v4^gamma '''             # Isentropic expansion process
p4 = p3*pow(v3,gamma)/pow(v4,gamma)

''' (p3*v3)/T3 = (p4*v4)/T4 | T4 = p4*v4*T3/(p3*v3) '''
T4 = p4*v4*T3/(p3*v3)

plt.plot(V_comp,P_comp)
plt.plot([v2,v3],[p2,p3])
plt.plot(V_expp,P_expp)
plt.plot([v4,v1],[p4,p1])
plt.ylim([-500000,8000000])
plt.xlim([0,0.005])
plt.xlabel('Volume (m^3)')
plt.ylabel('Pressure(Pa)')
plt.title('p-V diagram of an Otto Cycle')
plt.text(0.00385,-250000,r'$ \ 1 \ $')
plt.text(0.0002,2000000,r'$ \ 2 \ $')
plt.text(0.0002,5850000,r'$ \ 3 \ $')
plt.text(0.00385,400000,r'$ \ 4 \ $')
plt.grid()
plt.show()


#Calculating thermal efficiency

thermal_efficincy = 1- (1/pow((c_r),(gamma-1)))
print('Thermal efficiency of given Otto Cycle is :',thermal_efficincy)
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.