Challenge

Week 2 Air standard Cycle

AIM :-

To write code that can solve an otto cycle and make plots for it.

OBJECTIVES :-

1. Write a code to plot a PV diagram.

2. Find the thermal efficiency of the engine.

THEORY :-

The Otto cycle is the ideal cycle for spark-ignition engines, in honor of Nikolaus Otto, who invented it in 1867.

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. In ideal Otto cycles, air-standard assumption is used.

PROGRAM :-

"""
Air Standard Cycle Simulator
Program by Saurabh Kshirsagar
"""

import math
import matplotlib.pyplot as plt 

def engine_kinematics(bore,stroke,con_rod,cr,start_crank,end_crank):

	"""
	Engine Kinematics
	"""

	#Geometric Parameters
	a = stroke/2
	R = con_rod/a

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

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

	for i in range(0,num_values):
		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)
	return V

#inputs
p1 = 101325
t1 = 500
gamma = 1.4
t3 = 2300

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

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

#state point 2
v2 = v_c

#p2v2^gamma = p1v1^gamma
p2 = p1*pow(v1,gamma)/pow(v2,gamma)

#p2v2/t2=p1v1/t1 | rhs=p1v1/t1 | p2v2/t2=rhs | t2=p2v2/rhs
rhs = p1*v1/t1
t2 = p2*v2/rhs
v_compression = engine_kinematics(bore,stroke,con_rod,cr,180,0)

#p_compression*v_compression^gamma = constant
constant = p1*pow(v1,gamma)
p_compression = []
for v in v_compression:
	p_compression.append(constant/pow(v,gamma))

#state point 3
v3 = v2

#p3v3/t3=p2v2/t2 | rhs=p2v2/t2 | p3=rhs*t3/v3
rhs = p2*v2/t2
p3 = rhs*t3/v3
v_expansion = engine_kinematics(bore,stroke,con_rod,cr,0,180)

#p_compression*v_compression^gamma = constant
constant = p3*pow(v3,gamma)
p_expansion = []
for v in v_expansion:
	p_expansion.append(constant/pow(v,gamma))


#state point 4
v4 = v1

#p4v4^gamma = p3v3^gamma
p4 = p3*pow(v3,gamma)/pow(v4,gamma)

#p4v4/t4=rhs
t4 = p4*v4/rhs

#plotting
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('PV Diagram of Otto Cycle')
plt.show()

#Thermal Efficiency
efficiency = 1-(pow(cr,(1-gamma)))
print(efficiency)

PROGRAM EXPLANATION :-

1. Inputs:

  • p1 = pressure at state point 1 = 101325 pascals
  • t1 = temperature at state point 1 = 500 K
  • gamma = 1.4
  • t3 = temperature at state point 3 = 2300 K

2. Geometric Parameters:

  • bore = 0.1m
  • stroke = 0.1m
  • con_rod = connecting rod = 0.15m
  • cr = compression ratio = 6
  • a = crank pin radius = stroke/2
  • R = constant = connecting rod / crank pin radius

3. Volume Parameters :

  • v_s = swept volume = pi/4 x bore2 x stroke
  • v_c = clearance volume = swept volume / (clearance ratio-1)

4. start_crank and end_crank are the starting and ending angles of crank which gives movement of crank.

5. Total 50 values are taken between starting and ending crank angles and it is denoted by num_values.

6. Below formula give relationship between crank angle and volume inside combustion chamber. If we solve this equation we get volume trace. This formula is breaked into term1,term2 and term3 for easy programming.

7. At state point 1 , pressure p1 is defined and volume v1 is equal to addition of clearance volume and swept volume.

8. At state point 2, volume v2 is equal to clearance volume, pressure p2 is found using relation p2v2^gamma = p1v1^gamma and temperature t2 is found using relation p2v2/t2=p1v1/t1. We find v_compression and p_compression for start crank angle 180 degree and end crank angle 0 degree.

9. At state point 3, volume v3 is equal to volume v2, temperature t3 is defined and pressure p3 is found using relation p3v3/t3=p2v2/t2. We find v_expansion and p_compression for start crank angle 0 degree and end crank angle 180 degree.

10. At state point 4. volume v4 is equal to v1, temperature t4 is found using relation p3v3/t3=p4v4/t4 and pressure p4 is found using relation p4v4^gamma = p3v3^gamma.

11. Finally, we add commands for plotting of PV graph.

12. Thermal efficiency is found using given formula.

OUTPUT:-

1. PV plot of otto cycle.

2. Thermal Efficiency of the engine.

CONCLUSION:-

PV Plot of otto cycle is plotted successfully and thermal efficiency of engine is 51.16% .

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.