Week 2 Air standard Cycle
P-V diagram of Otto cycle using Python
Aim: To create P-V diagram of Otto cycle using Python and calculate the efficiency
Objective:
- Create a program to plot P-V diagram of Otto cycle.
- Calculate the thermal efficiency of given cycle.
Theory:
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. The Otto cycle is a description of what happens to a mass of gas as it is subjected to changes of pressure, temperature, volume, addition of heat, and removal of heat. The mass of gas that is subjected to those changes is called the system. The isentropic process of compression or expansion implies that there will be no inefficiency (loss of mechanical energy), and there be no transfer of heat into or out of the system during that process. The cylinder and piston are assumed to be impermeable to heat during that time. Work is performed on the system during the lower isentropic compression process. The summation of the work added to the system plus the heat added minus the heat removed yields the net mechanical work generated by the system.
In this project a program is written to calculate the quantities at all state points to create a P-V diagram.
Flow of the procedure:
First of all, useful libraries like math and matplotlib are imported.
Next is to input the data required for calculations. The data given contain pressure at state 1, temperature at state 1 and 3. Also, data for engine geometry is specified. Next step is to calculate the swept volume and clearance volume. Further all the data is calculated which is required to plot the P-V diagram.
Thermal efficiency of the cycle is also calculated.
Program:
# Program to plot P-V diagram if air standard cycle.
# Importing libraries
import math
import matplotlib.pyplot as plt
# Input data
# Pressure at state 1 in Pa
p1 = 101325
# Temperature at state 1 in K
t1 = 300
# Constant
gamma = 1.4
# Temperature at state 3 in K
t3 = 2300
# Engine geometry in meter
bore = 0.1
stroke = 0.1
# Length of connecting rod
con_rod = 0.15
# Compression ratio
c_r = 12
# Swept volume
v_s = math.pi/4*pow(bore,2)*stroke
# Clearance volume
v_c = v_s/(c_r-1)
# Creating function
def engine_kinematics(bore,stroke,con_rod,start_crank,end_crank):
a = stroke/2
# Constant
R = con_rod/a
# Start and end angles of crank
start_crank = math.radians(start_crank)
end_crank = math.radians(end_crank)
n = 50
d_theta = (end_crank-start_crank)/(n-1)
# Creating an empty array
v = []
# Creating for loop
for i in range(n):
theta = (start_crank+i*d_theta)
t1 = 0.5*(c_r-1)
t2 = R+1-math.cos(theta)
t3 = pow(R,2)-pow(math.sin(theta),2)
t3 = pow(t3,0.5)
v.append((1+t1*(t2-t3))*v_c)
return v
# State 1
# Volume
v1 = v_s + v_c
# State 2
# Volume
v2 = v_c
# Pressure
# p1*v1^gamma = p2*v2^gamma
p2 = (p1*pow(v1,gamma))/pow(v2,gamma)
# Temperature
# p1*v1/t1 = p2*v2/t2
t2 = (p2*v2)/(p1*v1/t1)
# volume and pressure at compression
v_compression = engine_kinematics(bore,stroke,con_rod,180,0)
p_compression = []
constant = p1*pow(v1,gamma)
for v in v_compression:
p_compression.append(constant/pow(v,gamma))
# State 3
# Volume
v3 = v2
# Pressure
p3 = (p2*v2*t3)/(v3*t2)
# volume and pressure at compression
v_expansion = engine_kinematics(bore,stroke,con_rod,0,180)
p_expansion = []
constant = p3*pow(v3,gamma)
for v in v_expansion:
p_expansion.append(constant/pow(v,gamma))
# State 4
# Volume
v4 = v1
# Pressure
p4 = (p3*pow(v3,gamma))/pow(v4,gamma)
# Temperature
t4 = (p4*v4)/(p1*v1/t1)
# Thermal efficiency
A = (1-1/pow(c_r,(gamma-1)))*100
print('Thermal efficiency of given Otto cycle is',A,'%')
# Plotting
plt.figure()
plt.plot([v2,v3],[p2,p3],label = 'Constant volume')
plt.plot(v_compression,p_compression,label = 'Compression')
plt.plot(v_expansion,p_expansion, label= 'Expansion')
plt.plot([v4,v1],[p4,p1], label = 'Constant volume')
plt.xlabel('Volume in m^3')
plt.ylabel('Pressure in Pa')
plt.title('P-V diagram of Otto cycle')
plt.legend()
plt.savefig('p-v diagram.png'+'.png')
plt.show()
# End
P-V diagram:
Thermal efficiency:
RESULT:
It is observed that thermal efficiency of the cycle can be increased by increasing the value of compression ratio.
Reference: