Project

PYTHON Programme To Solve An Otto Cycle

AIM:

To write a program in PYTHON to plot an otto cycle and calculate its thermal efficiency.

GOVERNING EQUATIONS:

  • Compression ratio : Vs+Vc/Vc

Where Vs=swept volume=(pi/4)*d^2*L

Where d=bore

L=stroke

Vc=clearance volume

  • Volume change inside the cylinder due to various processes :
  • For isoentropic process, P*V^gamma=constant.
  • Thermal efficiency of otto cycle=1-(1/cr^(gamma-1))

where cr=compression ratio=10 (assumed)

gamma=specific heat of air=1.4

OBJECTIVE:

To solve the different state variables of otto cycle.

To plot a P-V diagram.

To calculate the thermal efficiency of an otto cycle.

THEORY:

OTTO CYCLE:

The Air Standard-Otto cycle is the idealized cycle for the spark-ignition Internal Combustion engines. In the Process 0-1, the piston moves from Top Dead Centre (TDC) to Bottom Dead Centre (BDC) and the mixture of fuel and air (charge) is sucked inside the combustion chamber.

Process 1-2: Isentropic compression

In this process, the piston moves from BDC to TDC. Air undergoes reversible adiabatic (isentropic) compression. Compression is a process in which volume decreases and pressure increases. Therefore, volume of air decreases from V1 to V2 and pressure increases from p1 to p2 and temperature increases from T1 to T2.

Process 2-3: Constant volume heat addition

It is an isochoric heat addition process. In this process, the piston remains at TDC for a moment. Heat is added at constant volume (V2 = V3) from an external heat source (By creating a spark by means of a spark plug). Temperature further increases from T2 to T3 and pressure also increases from p2 to p3.

Process 3-4: Isentropic Expansion

In this process, air undergoes reversible adiabatic (isentropic) expansion. The piston is pushed from TDC to BDC. Here, pressure decreases from p3 to p4, volume increases from v3 to v4 and temperature falls from T3 to T4.

Process 4-1: Constant volume heat rejection

In this process, the piston rests at BDC for a moment and heat is rejected at constant volume (V4=V1). During this process, the pressure falls from p4 to p1 and temperature further decreases from T4 to T1.

PYTHON CODE:

'''A program to calculate different state variables in an Otto Cycle and to calculate its thermal efficiency and plot it on the 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 variable

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,label='Isentropic compression')
plt.plot([v2,v3],[p2,p3],label='constant volume heat addition')
plt.plot(V_expp,P_expp,label='Isentropic expansion')
plt.plot([v4,v1],[p4,p1],label='constant volume heat rejection')
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.legend()
plt.show()


#Calculating thermal efficiency

thermal_efficiency = 1- (1/pow((c_r),(gamma-1)))
print('Thermal efficiency of given Otto Cycle is :',thermal_efficiency)

EXPLANATION OF THE CODES :

  1. Since Otto cycle is an air-standard cycle, the specific heat gamma of air is taken as 1.4.
  2. Initial conditions, such as temperature (T1) and pressure (P1) of the surrounding is assumed to be 350K and 101.325 KPa respectively.
  3. The geometrical design of the engine cylinder which consists of bore diameter, stroke length, and length of the connecting rod is also known and accordingly, VS and VC are calculated.
  4. The maximum temperature (T3) occurring inside the cylinder is also known.
  5. Other state variables are calculated using Adiabatic processes equations and ideal gas equations.
  6. Similarly, the thermal efficiency is also calculated accordingly using the formula given.
  7. For plotting the calculated state variables on a p-v diagram with just using 'plt.plot' command will yield into an incorrect p-v diagram, i.e, compression, and expansion stroke is represented by a straight line.
  8. So to rectify this, a different function is created for storing the different value of crank angle rotation as compression and expansion occurs in different stroke or cycle. This function is then called to the main program and accordingly, the plot is drawn from various points obtained.
  9. For this number of values for which the program will iterate is 100, and accordingly, the V array is set as null and after every iteration using for loop, a new value will be stored as an array using 'append' command and will be returned back after receiving desired values.

OUTPUT:

Conclusion:

Thus we plotted the P-V diagram from the given assumed information and the thermal efficiency was found to be 60.18 %

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.