Challenge

Week 2 Air standard Cycle

AIM: To write a program in Python to solve an Otto cycle and make plots for it.

OBJECTIVE :

  1. To solve and find out different state variables in the Otto cycle and plot its p-V diagram.
  2. To calculate the thermal efficiency of the given Otto cycle.

Theory:

Thermodynamic cycles are the most fundamental part of any powerplant or engine. The otto, diesel, and dual cycles are different thermodynamic cycles. rankine cycle etc. Among all these PV diagrams of the otto cycle are being visualized with Matlab here.

The Otto cycle consists of four processes: two constant pressure processes and two adiabatic processes. Here ideal cycle is considered for PV diagram visualization. The Four processes are as follows:

1. Process(1-2) -- Adiabatic Compression

2. Process(2-3) -- Constant pressure heat addition

3. Process(3-4) -- Adiabatic Expansion

4. Process(4-1) -- Constant pressure heat rejection

Code:

# Air Standard Otto Cycle Simulator

import math
import matplotlib.pyplot as plt

def engine_kinematics(bore,stroke,con_rod,cr,start_angle,end_angle):
	

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

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

	sc = math.radians(start_angle)				# start crank
	ec = math.radians(end_angle)				# end crank

	num_values = 50

	dtheta = (sc-ec)/(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


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

# engine parameters
bore = 0.1
stroke = 0.1
con_rod = 0.15
cr = 8


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

# stage 2
v2 = v_c

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

# p1v1/t1 = p2v2/t2 | 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)

constant = p1*pow(v1,gamma)

P_compression = []

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


# stage 3
v3 = v2
#P3V3/T3 = P2V2/T2 | rhs = p2v2/t2 | p3v3/t3 = rhs | p3 = rhs*t3/v3
rhs = p2*v2/t2
p3 = rhs*t3/v3

V_expansion = engine_kinematics(bore,stroke,con_rod,cr,0,180)

constant = p3*pow(v3,gamma)

P_expansion = []

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


# stage 4
v4 = v1

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

t4 = p4*v4/rhs

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 (m^3)')
plt.ylabel('Pressure (Pa)')
plt.show()

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

Code Explanation:

  1. First of all, we need to identify the state variables of each point in the Otto cycle and how the volume and pressure change from each state.
  2. The initial pressure, volume, and temperature of atmospheric air are p1, v1, and t1.
  3. During Suction Stroke, the inlet valve opens and the air intake occurs, and the state variable changes from p1v1 to p2v2. After the intake process the inlet valve closes, Compression Stroke takes place, during this stroke the charge (air-fuel mixture) is compressed, and the state variables change from p2v2 to p3v3. After the compression process Power Stroke takes place the state variables change from p3v3 to p4v4. then Exhaust Stroke, the exhaust valve opens and the burned gas is expelled. The state variables change from p4v4 to p1v1.
  4. A function engine_kinematics is defined which returns volume for different crank angles during the compression and expansion process.
  5. In the function we use the loop and append function. We write a code by which we find different values of volume (i.e. volume at compression and volume at expansion) at different theta values in a range of 0 degrees to 180 degrees)
  6. Then the state variables are calculated using thermodynamic relations of each process,
  7. Since the state change from p2v2 to p3v3 is not linear we have to create a curve that relates to the process. In order to achieve that, the code has a function call with the function name “engine_kinematics” this function call is done for creating the curve of adiabatic compression and adiabatic expansion process which are not straight lines. With function call and thermodynamic relation, the v_compression and v_expansion are calculated.
  8. After calculating the values of the state variable use matplotlib (__) to plot the PV diagram of the Otto-Cycle. plt.show() command is used to display the plot
  9. We call the define function, by which we get different values of volume, and then we can calculate the pressure by using the Otto cycle formula.
  10. After finding all values of volume, pressure, and temperature at different stages or process of the Otto cycle, we can find the thermal efficiency of the Otto cycle by using the n-th or n-otto formula.
  11. Print function use for printing the value of thermal efficiency
  12. Add labels for the axis and give a title to the PV-diagram by using plt.xlabel (‘__’), and plt.ylabel (‘__’)

Errors:

1. During first execution of the code it throughs an error because of not presence of .py extension in its file name.

2. Python throws an error 1 time because of indentation mismatching.

Results:

1. PV Diagram

2. Thermal efficiency of the engine is 56.47 %

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.