Project

OTTO CYCLE VISUALISATION - USING PYTHON

OTTO CYCLE VISUALISATION

INTRODUCTION TO AIR STANDARD CYCLE

In gas power cycle, the working fluid remains a gas throughout the cycle. Spark-Ignition Engines, Diesel Engines are familiar examples of devices that operate on gas cycles. In all these engines energy is provided by burning fuel and air in a closed environment, hence the name Internal Combustion Engines. An Air standard Cycle is a gas power cycle in which Air is used as the working fluid. However, as air mostly contains Nitrogen, it hardly ever undergoes any chemical reaction, so the working fluid always remains air.

The actual gas-powered cycles are rather complex. To reduce the analysis to a manageable level, certain assumptions are made, commonly known as Air Standard Assumptions:

  • The working fluid is air, which continuously circulates in a closed loop and always as an ideal gas.

  • All the processes that make up the cycle are internally reversible.

  • The combustion process is replaced by heat addition process from an external source.

  • The exhaust process is replaced by a heat addition process that restores the working fluid to its initial state.

OTTO CYCLE

The Otto cycle is the ideal cycle for spark-ignition reciprocating engines. In most spark-ignition engines the piston executes 4 complete strokes. In an ideal OTTO cycle, there are 4 processes,

  • Isentropic Compression

  • Constant-volume heat addition

  • Isentropic Expansion

  • Constant-volume heat rejection

The following image shows a schematic working of a spark engine, an ideal OTTO cycle, P-V diagrams of Actual and Ideal Otto cycle.

Here, I'll be considering an ideal OTTO cycle and will be proceeding ahead. The ideal Otto cycle has two adiabatic processes and two constant volume processes. So, the structure of the PYTHON program will begin at point 1 i.e., beginning of the adiabatic compression.

Structure of the Python Program

Part A: Defining a function that returns the Volume at every point of the Adiabatic Process in the same Python script

  • The libraries 'math' and 'matplotlib' are imported before the function definition.
  • The syntax for creating a function is

def function_name(input_variables)

body of the function

return value

  • In a python script create a function as shown above with the return value being Volume in the cylinder, function name being engine_kinematics( any name can be assigned), and the input variables will be bore, stroke, length of connecting rod, compression ratio, starting crank angle, ending crank angle like this,

    def Engine_kinematics(bore, stroke,con_rod,cr,start_crank,end_crank)

  • In the body of the function calculate crankpin radius, swept volume, clearance volume and initialize the angles of the crank rotation.

  • `V=V_c*{1+1/2*(r_c-1)*[R+1-costheta-(R^2-sin^2theta)^(1/2)]}`

This is a geometrically derived equation which exactly determines the volume of the cylinder at any instant of the rotation of the crank which is found to have exact same values as determined by Adiabatic condition. Using this equation, the volume in the cylinder is returned.

  • The function is defined in the same script as that of the main body.

Part B: Creating the main program.

  • After the function definition, the main body is written.
  • Initialize the constant `gamma` as 1.4.

  • Preliminary state variables, `p_1,v_1,t_3` are initialized, and the geometric parameters such as bore, stroke, length of connecting rod and compression ratio are also initialized.

  • Using the geometric parameters, swept and clearance volumes are calculated. Now, the remaining state variables are calculated using the generalized gas law `(P*V)/T = C`, the adiabatic equation `P*V^gamma = C` and isobaric condition `P/T = C`.

  • Now, to get the values of Pressure and Volume along the adiabatic curve, the function 'Engine_kinematics' is called separately for compression and expansion processes.

  • For adiabatic compression, using one of the state points, the constant c in `p*v^gamma = c` is calculated. Now, the function 'Engine_kinematics' is called and assigned to an array 'V_compression' in which the returned values of the function gets assigned. Substituting 'V-compression' in the adiabatic equation, the corresponding pressure values get assigned to the array 'P_compression' can be calculated. This gives us the coordinates of the adiabatic compression process.

  • Similarly, the function 'Engine_kinematics' is called again to calculate 'V_expansion' and the corresponding values of 'P_expansion'.

  • Using the plot function, the state points are plot by a '*' and then the processes joining these state points are represented by respective curves. The syntax of the plot function is

plt.plot(x,y)

  • The isobaric heat transfer processes are represented by straight lines joining the adiabatic curves.

The Python code of the main program is below.

# Otto cycle 

import math
import matplotlib.pyplot as plt

def Engine_kinematics(bore,stroke,con_rod,cr,start_crank,end_crank):
	"""
	Engine kinematics

	"""
	  
	# geometric parameters
	a = 0.5*stroke
	R = con_rod/a

	# Volume parameters
	v_s = math.pi*pow(bore,2)*stroke/4
	v_c = v_s/(cr-1)

	sc = math.radians(start_crank)
	ec = math.radians(end_crank)
	num_theta = 100
	dtheta = (ec-sc)/(num_theta-1)
	V = []

	for i in range(0,num_theta):
		term1 = 0.5*(cr-1)
		term2 = R+1-math.cos(sc+i*dtheta)
		term3 = pow(pow(R,2)-pow(math.sin(sc+i*dtheta),2),1/2)
		V.append(v_c*(1+term1*(term2-term3)))
		  

	return V

# Thermodynamic constants
gamma = 1.4

# Initial condition
p1 = 101325
t1 = 500
t3 = 2300

# geometric parameters
bore = 0.1
stroke = 0.1
con_rod = 0.15
cr = 12

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

# State point 2
v2 = v_c
p2 = p1*pow(cr,gamma)
t2 = t1*pow(cr,gamma-1)

# State point 3
v3 = v2
p3 = (p2*v2/t2)*(t3/v3)

# State point 4
v4 = v1
p4 = p3*pow(1/cr,gamma)
t4 = t3*pow(1/cr,gamma-1)

# Compression stroke

V_comp = Engine_kinematics(bore,stroke,con_rod,cr,180,0)
V_exp = Engine_kinematics(bore,stroke,con_rod,cr,0,180)


P_comp = []
for i in range(0,len(V_comp)):
	P_comp.append(p1*pow(v1,gamma)/pow(V_comp[i],gamma))

P_exp = []
for i in range(0,len(V_exp)):
	P_exp.append(p3*(pow(v3,gamma)/pow(V_exp[i],gamma)))

thermalefficiency = 1-(1/pow(cr,gamma-1))
print('The thermal efficiency for compression ratio',cr,'is',thermalefficiency*100)


plt.plot(v1,p1,'*')
plt.plot(v2,p2,'*')
plt.plot(v3,p3,'*')
plt.plot(v4,p4,'*')
plt.plot([v2,v3],[p2,p3])
plt.plot([v4,v1],[p4,p1])
plt.plot(V_comp,P_comp)
plt.plot(V_exp,P_exp)
plt.xlabel('Volume(m3)')
plt.ylabel('Pressure(Pascal)')
plt.title('P-V diagram of Ideal Otto Cycle')
plt.show()

P-V diagram obtained from the above program

Thank You.

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.