Challenge

OTTO CYCLE SOLVING USING PYTHON

AIM:

To write a program in PYTHON to solve the Otto Cycle and Plot the PV Diagram.

  1. The code should create a PV diagram
  2. Find 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. It is the thermodynamic cycle most commonly found in automobile engines.

The following describes what occurs during each step on the PV diagram, in which the combustion of the working fluid gasoline and air (oxygen), changes the motion in the piston:

Process 1 to 2: During this phase the piston will be drawn up, so it can compress the fuel-air mixture that entered the chamber. The compression causes the mixture to increase slightly in pressure and temperature—however, no heat is exchanged. In terms of thermodynamics, this is referred to as an adiabatic process. When the cycle reaches point 2, that is when the fuel is met by the spark plug to be ignited.


Process 2 to 3: This is where combustion occurs due to the ignition of fuel by the spark plug. The combustion of the gas is complete at point 3, which results in a highly pressurized chamber that has a lot of heat (thermal energy). In terms of thermodynamics, this is referred to as an isochoric process.

Process 3 to 4: The thermal energy in the chamber as a result of combustion is used to do work on the piston—which pushes the piston down—increasing the volume of the chamber. This is also known as the power stoke because it is when the thermal energy is turned into motion to power the machine or vehicle.


Purple line (Process 4 to 1 and exhaust phase): From process 4 to 1, all waste heat is expelled from the engine chamber. As the heat leaves the gas, the molecules lose kinetic energy causing the decrease in pressure. Then the exhaust phase occurs when the remaining mixture in the chamber is compressed by the piston to be "exhausted" out, without changing the pressure.

PYTHON PROGRAM:

import math							# Library for math functions
import matplotlib.pyplot as plt 	# Library for plotting functions

# Function Definition
def Engine_kinematics(bore,stroke,con_rod,cr,start_crank,end_crank):
		a=stroke/2
		R=con_rod/a

		#volume parameters
		V_S=(math.pi/4)*(pow(bore,2))*stroke
		V_C=V_S/(cr-1)
		V1=V_C+V_S

		sc=math.radians(start_crank)
		ec=math.radians(end_crank)

		num_values=100 #no. of points
		dtheta=(ec-sc)/(cr-1) 
		V=[]		   #empty array
		for i in range(0,num_values):
			'''Main equation is divided into terms term1,term2,term3
			   V/Vc = 1+0.5*[Rc-1]*[R+1-cos(theta)]-[[R^2-sin(theta)^2]^0.5]
			'''
			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) #append is used to retain each values

		return V  	# Returning value of V


#Input parameters
T1=600
P1=101325
gamma=1.4
T3=2400

#geometric parameter
bore=0.1
stroke=0.1
con_rod=0.15
cr=10


#Stage 1
V_S=(math.pi/4)*(pow(bore,2))*stroke
V_C=V_S/(cr-1)
V1=V_C+V_S


#Stage 2 PV^GAMMA=C
V2=V_C
P2=P1*(pow(V1,gamma)/pow(V2,gamma))
RHS=(P1*V1)/T1
term2=(P2*V2)/RHS

V_compression=Engine_kinematics(bore,stroke,con_rod,cr,180,0) #Function call - Compression stroke
CONSTANT=P1*pow(V1,gamma)
P_compression=[]
for v in V_compression:
		P_compression.append(CONSTANT/pow(v,gamma))


#Stage 3
V3=V2
#p3v3/term3=p2v2/term2 
P3=(T3*RHS)/V3
V_expansion=Engine_kinematics(bore,stroke,con_rod,cr,0,180) #Function call - Expansion stroke
CONSTANT=P3*pow(V3,gamma)
P_expansion=[]
for v in V_expansion:
		P_expansion.append(CONSTANT/pow(v,gamma))


#STAGE4
V4=V1

#[p3v3^GAMMA] = [p4v4^GAMMA]
P4=P3*(pow(V3,gamma)/pow(V4,gamma))

#[p4v4/t4] = [p3v3/term3]
T4=P4*V4/RHS

def cal_eff(cr,gamma):		#Function for Thermal Efficiency of Engine
 		Thermal_Eff = (1-(1/pow(cr,gamma-1)))*100
 		return Thermal_Eff

s=cal_eff(12,1.4) #Function call for Thermal Efficiency cal.
print('thermal efficiency= ',s)

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('Otto cycle')
plt.grid()
plt.show()

RESULT:

  • Otto Cycle PV diagram:





  • Thermal Efficiency of Engine = 63%


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.