Challenge

Week 2 Air standard Cycle

Objective: To Plot the PV diagram for an Otto Cycle and calculate the thermal efficiency of the engine.

Problem Statement:

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

1. The code should create a PV diagram

2. To generate output the thermal efficiency of the engine.

Theory:

The Otto Cycle which is also called the 'Constant-Volume' cycle has been used in engines such as petrol, gas, and many other types of oil engines. These are the following processes which take place in the constant volume process:

From the figure shown above, we can concur that at point 1 the cylinder is full of air with Volume 1, pressure p1, and temperature T1.

The Line 1-2 represents the adiabatic compression of air due to which p1, V1 and T1 changes to
p2, V2, and T2, respectively.

In the Line 2-3, we can observe that there is a constant volume process (v2 = v3) and the heat addition takes place and the pressure and temperature also increase from p2 to p3 and t2 to t3, respectively.

Line 3-4 represents the adiabatic expansion of air which results in the change of the parameters from p3,v3,t3 to p4,v4, and t4. Because of the expansion process the volume tends to increase and the pressure reduces.

Line 4-1 represents the rejection of heat at constant volume (v4 = v1) and the further reduction in pressure and temperature from p4 to p1 and t4 to t1, respectively.

Process 1-2: Isentropic Compression

Process 2-3: Constant Volume Heat Addition

Process 3-4: Isentropic Expansion

Process 4-1: Constant Volume Heat Rejection

Formula:

The following formulae used which coding the program are mention below:

Program:

Code for the program:

"""
	otto cycle simulator
"""

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 parmeters
	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

	d_theta = (ec-sc)/(num_values-1)

	V = []

	for i in range(0,num_values):
		theta = sc +i*d_theta
		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 = 12

# 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)

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)

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

# Thermal Efficiency
thermal_eff = (1 - pow(cr,(1-gamma)))*100
print("Thermal Efficiency is ")
print(thermal_eff)

# Generate Plot

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



Procedure:

  1. In the code above we have provided the pre-defined inputs and parameters to the python which will be executed when the code is run and there are no user-defined inputs here.
  2. Then, the code is written for the formulae which are mentioned in the above section.
  3. Similarly, the code has also been written for the pressure, volume at different points in the PV diagram.
  4. The expressions for the curve when there are adiabatic compression and expansion are also written.
  5. In the end code for the thermal efficiency is also written from the formula mentioned above. The crank angle is considered to be from 0 to 180 because when the expansion happens the piston movement takes place from the BDC to TDC and similarly, for the compression the movement takes place from TDC to BDC so the angle changes from 180 to 0.
  6. Then we plot the graph for the curve and the lines which are represented on the graph along with their labels.
  7. We write the function which is used to run the parameters mentioned. Here, the following code from the above-mentioned formulae is written. The formula for volume is divided into three terms and then they are combined in the variable 'V'.

Result:

The thermal efficiency of the engine is calculated to be 62.9892 as shown above.

This is the plot of the PV diagram which is observed after executing the program.

Project Link: https://skill-lync.com/projects/air-standard-cycle-using-python-23

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.