Challenge

Week 2 Air standard Cycle

Aim:

To write a code for Otto cycle and extract the p-v plot and efficiency of otto cycle using python script.

Theory:

Internal Combustio Engine OTTO cycle:

The Otto cycle is a set of processes used by spark ignition internal combustion engines (2-stroke or 4-stroke cycles). These engines a) ingest a mixture of fuel and air, b) compress it, c) cause it to react, thus effectively adding heat through converting chemical energy into thermal energy, d) expand the combustion products, and then e) eject the combustion products and replace them with a new charge of fuel and air. The different processes are shown in Figure:

  1. Intake stroke, gasoline vapor and air drawn into engine ( ).
  2. Compression stroke, , increase ( ).
  3. Combustion (spark), short time, essentially constant volume ( ). Model: heat absorbed from a series of reservoirs at temperatures to .
  4. Power stroke: expansion ( ).
  5. Valve exhaust: valve opens, gas escapes.
  6. ( ) Model: rejection of heat to series of reservoirs at temperatures to .
  7. Exhaust stroke, piston pushes remaining combustion products out of chamber ( ).

Efficiency of ideal otto cycle:

The starting point is the general expression for the thermal efficiency of a cycle:

The convention, as previously, is that heat exchange is positive if heat is flowing into the system or engine, so is negative. The heat absorbed occurs during combustion when the spark occurs, roughly at constant volume. The heat absorbed can be related to the temperature change from state 2 to state 3 as:

The heat rejected is given by (for a perfect gas with constant specific heats)

Substituting the expressions for the heat absorbed and rejected in the expression for thermal efficiency yields

We can simplify the above expression using the fact that the processes from 1 to 2 and from 3 to 4 are isentropic:

The quantity is called the compression ratio. In terms of compression ratio, the efficiency of an ideal Otto cycle is:

The ideal Otto cycle efficiency is shown as a function of the compression ratio in Figure 3.11. As the compression ratio, , increases, increases, but so does . If is too high, the mixture will ignite without a spark (at the wrong location in the cycle).

Procedure:

1. Open sublime python script editor and save the file as otto cycle and first write the commands for the importing the math and plot.

2. Now define the engine parameters using 'def' command and calculate the Volume of the cylinder and append the volume up to 50 values. Here vvolume formulae is split into three terms and then calculated.

3. Now define the input parameters like pressure, temperature and air constant gamma and also define the compression ratio, stroke length, bore diameter and connecting rod length.

4. After defining all input parameters now start calculting the pressure, volume and temperature and write the code in the format of code.

5. To calculate pressure and volume at the compression and expansion process write a 'for' loop function and append the pressure with respective to volume at the compression and expansion.

6. Now write the command to calculate the thermal efficiency of this cycle.

7. Now write the commands to plot the p-v diagram and mention legends at x-axis and y-axis.

8. Now save the file again and run the whole script and we get the plot and thermal efficiency.

Code and Results:

#otto cycle simulator
#Engine kinematics
#By Mahesh

#import

import math
import matplotlib.pyplot as plt 

def engine_kinematics(bore,stroke,conn_rod,c_r,start_crank,end_crank):

    #Engine parameters
	a = stroke/2
	R = conn_rod/a
	c_r = 10

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

	#strating crank angle and ending crank angle
	sc = math.radians(start_crank)
	ec = math.radians(end_crank)

	num_values = 50
	dtheta = (ec-sc)/(num_values-1)

	V =[]

	#write the 'for' loop command to calculate volume
	for i in range(0,num_values-1):

		theta = sc + i*dtheta

		term1 = 0.5*(c_r-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)

	return V
#intial inputs of pressure,temperature and value of isentropic expansion factor gamma
p1 = 101325
t1 = 500
gamma = 1.4
t3 = 2300

#engine parameters 
bore = 0.15
stroke = 0.2
conn_rod = 0.8
c_r = 10


#volume calculations for swept volume and compression volume
v_s = (math.pi/4)*pow(bore,2)*stroke
v_c = v_s/(c_r-1)
v1 = v_c + v_s

#constant volume process
v2 = v_c
#from isentropic process p2v2^gamma = p1v1^gamma
p2 = p1*pow(v1,gamma)/pow(v2,gamma)

#to find temperature value at 2nd use ideal gas equation
rhs = p1*v1/t1
t2 = p2*v2/rhs
V_compression = engine_kinematics(bore,stroke,conn_rod,c_r,180,0)

constant = p1*pow(v1,gamma)

P_compression = []

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

#at stage 3
v3 = v2
rhs_1 = p2*v2/t2
p3 = t3*rhs_1/v3

V_expansion = engine_kinematics(bore,stroke,conn_rod,c_r,0,180)

constant = p3*pow(v3,gamma)

P_expansion = []

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


#at stage 4
v4 = v1
p4 = p3*pow(v3,gamma)/(pow(v4,gamma))

#final temperature
rhs_2 = p3*v3/t3 
t4 = p4*v4/rhs_2

#calcuate efficiency of otto cycle = n
n = 1 - (1/pow((c_r),(gamma -1)))
print(n)


#write the commands for plotting

plt.plot(V_compression,P_compression)
plt.plot([v2,v3,],[p2,p3])
plt.plot(V_expansion,P_expansion)
plt.plot([v4,v1],[p4,p1])
plt.ylim([-500000,8000000])
plt.xlim([0,0.005])
plt.ylabel('Pressure')
plt.xlabel('Volume')
plt.title('Otto Cycle')
plt.grid()
plt.show()


Thermal efficiency of this cycle is 60% and p-v diagram of otto cycle is plotted perfectly.

Conclusion:

Thus otto cycle thermal efficiecy and p-v diagram is plotted using the python script and sublime script editor.

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.