Plotting P-V diagram and calculating thermal efficiency of an otto cycle using Python
AIM:
Write a Python code to plot a PV diagram for otto cycle and calculate its thermal efficiency.
GOVERNING EUQATIONS:
- Ideal gas equation:`P*V=m*R*T`
P = Pressure in pascals
V = Volume in m^3
m = mass of the gas in Kg
R = Ideal gas constant KJ/Kg K
T = Temperature in kelvin (K)
- Volume at a particular instance in the engine cylinder (V):
`V/V_c =1+1/2 (r_c-1)[R+1-cosθ-(R^2-(sinθ)^2 )^(1/2) ]`
V = Volume at a particular instance in the engine cylinder.
`V_c`= Clearance Volume
`r_c`= Compression ratio
R = length of connecting rod/crank pin radius
`θ` = Crank angle
- Isotropic process: `PV^γ=`constant
- Compression ratio in otto cycle: `r_c=V_1/V_2`
- Thermal efficiency of otto cycle: `η=1-1/r_c^(γ-1)`= net work done / heat added
- Volume swept: `V_s=π/4*d^2*l`
d = bore diameter
l = stroke length
- Clearance volume: `V_c=V_s/(r_c-1)`
OBJECTIVES:
- Plot a PV diagram for otto cycle.
- Calculation of thermal efficiency.
THEORY:
In this project we consider the thermodynamics of a four-stroke internal combustion engine. The engine is called a four-stroke engine because there are four movements, or strokes, of the piston during one cycle. A stroke refers to the full travel of the piston along the cylinder, in either direction. The four separate strokes are termed:
- Intake: The fuel is taken inside the engine cylinder.
- Compression: The air fuel mixture is compressed and a spark is ignited (heat addition).
- Combustion: Due to spark ignition combustion of the fuel takes place which results in a power stroke (expansion).
- Exhaust: This action expels the spent air-fuel mixture and the combustion products through the exhaust valve (heat rejection).
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. We have considered an ideal Otto cycle in which there is no heat entering (or leaving) the gas during the compression and power strokes, no friction losses, and instantaneous burning occurring at constant volume.
Processes involve in an ideal otto cycle:
- Process 1–2 is an adiabatic (isentropic) compression of the charge as the piston moves from bottom dead centre (BDC) to top dead centre (TDC).
- Process 2–3 is a constant-volume (isochoric) heat transfer to the working gas from an external source while the piston is at top dead centre. This process is intended to represent the ignition of the fuel-air mixture and the subsequent rapid burning.
- Process 3–4 is an adiabatic (isentropic) expansion (power stroke).
- Process 4–1 completes the cycle by a constant-volume (isochoric) process in which heat is rejected from the air while the piston is at bottom dead centre.
PROGRAM:
Programming language used is Python.
Code for calculating state variables and plotting PV diagram for otto cycle:
# Program to calculate different state variables in an Otto Cycle, calculate its thermal efficiency and plot its p-v diagram
import math
import matplotlib.pyplot as plt
# Function for determining the behaviour of volume during isentropic process
def engine_kinematics(bore,stroke,cr_length,compression_ratio,start_crank_angle,end_crank_angle):
# Engine geometry properties
a = stroke/2
R = cr_length/a
# Volume parameters
v_swept = (math.pi/4)*pow(bore,2)*stroke
v_clearance = v_swept/(compression_ratio -1)
theta_startcrank = math.radians(start_crank_angle)
theta_endcrank = math.radians(end_crank_angle)
num_val = 100
dtheta = (theta_endcrank - theta_startcrank)/(num_val - 1)
V = []
for i in range(0,num_val):
theta = theta_startcrank + i*dtheta
term_1 = 0.5*(compression_ratio - 1)
term_2 = R + 1 - math.cos(theta)
term_3 = (pow(R,2) - pow(math.sin(theta),2))
term_3 = pow(term_3,0.5)
V.append((1 + term_1* (term_2 -term_3))*v_clearance)
return V
# Taking Inputs varibale
# Engine geometry properties
bore = 0.16
stroke = 0.2
cr_length = 0.8
compression_ratio = 10
gamma = 1.4 # for air gamma= 1.4
c_v = 0.714; # specfic heat of air at constant volume KJ/Kg K
# State variables assumed
p1 = 101325
T1 = 350
T3 = 2000 # max temp inside engine cyr
# Calculating swept volume and clearance volume
v_swept = (math.pi/4)*pow(bore,2)*stroke
v_clearance = v_swept/(compression_ratio -1)
v1 = v_swept + v_clearance
v2 = v_clearance
# Calculating state variables at different points
# State variables at point 2
# Process 1-2 is an isentropic compression process (pv^gamma=constant)
p2 = p1* pow(compression_ratio,gamma)
# (p1*v1)/T1 = (p2*v2)/T2 | T2 = p2*v2*T1/(p1*v1)
T2 = p2*v2*T1/(p1*v1)
V_comp = engine_kinematics(bore,stroke,cr_length,compression_ratio,180,0)
C_const = p1*pow(v1,gamma)
P_comp = []
for v in V_comp:
P_comp.append(C_const/pow(v,gamma))
# State variables at point 3
# Process 2-3 is an isochoric heat addition process (volume=constant)
v3 = v2
# Isochoric process ''' (p3*v3)/T3 = (p2*v2)/T2 | p3 = p2*T3/(T2) '''
p3 = p2*T3/(T2)
V_expansion = engine_kinematics(bore,stroke,cr_length,compression_ratio,0,180)
C_const = p3*pow(v3,gamma)
P_expansion = []
for v in V_expansion:
P_expansion.append(C_const/pow(v,gamma))
# State variables at point 4
# Process 3-4 is an isentropic expansion process (pv^gamma=constant)
v4 = v1
p4 = p3*pow(v3,gamma)/pow(v4,gamma)
''' (p3*v3)/T3 = (p4*v4)/T4 | T4 = p4*v4*T3/(p3*v3) '''
T4 = p4*v4*T3/(p3*v3)
#Calculating thermal efficiency
thermal_efficincy = 1- (1/pow((compression_ratio),(gamma-1)))
print('Thermal efficiency of given Otto Cycle is :',thermal_efficincy*100,"%")
# Plotting
plt.plot(V_comp,P_comp,label=r'$1-2 isentropic compression$')
plt.plot([v2,v3],[p2,p3],label=r'$2-3 isochoric heat addition$')
plt.plot(V_expansion,P_expansion,label=r'$3-4 isentropic expansion$')
plt.plot([v4,v1],[p4,p1],label=r'$4-1 isochoric heat rejection$')
plt.ylim([-500000,6500000])
plt.xlim([0,0.005])
plt.xlabel('Volume (m^3)')
plt.ylabel('Pressure(Pa)')
plt.title('P-V diagram of an Otto Cycle')
plt.text(0.00385,-250000,r'$ 1 $')
plt.text(0.0002,2000000,r'$ 2 $')
plt.text(0.0002,5850000,r'$ 3 $')
plt.text(0.00385,400000,r'$ 4 $')
plt.text(0.00385,400000,r'$ 4 $')
plt.legend(loc='best')
plt.show()
EXPLATION OF THE PROGRAM:
- Program starts defining the function ‘engine_kinematics’, and taking in various inputs. Which are required for further calculations.
- Then the swept volume and clearance volume is calculated using the formulae mentioned above.
- After that the state variables are calculated at point-2 in the otto cycle, with help of the inputs and the formulae mentioned above.
- Using the ‘engine_kinematics’ function, behavior of volume during isentropic compression process is determined. And using this volume behavior the pressure behavior is also determined for the isentropic compression process (Process 1-2).
- Then state variables are calculated at point-3 and point-4 in the otto cycle, with help of the inputs and the formulae mentioned above.
- Again using the ‘engine_kinematics’ function, behavior of volume during isentropic expansion process is determined. And using this volume behavior the pressure behavior is also determined for the isentropic expansion process (Process 3-4).
- We print the thermal efficiency in the command window using the ‘print’ function.
- Then we plot the four processes in the otto cycle.
- Thermal efficiency is calculated using the formula.
RESULT:
The PV diagram for otto cycle
Thermal Efficiency displayed on the screen:
CONCLUSION:
We understood the thermodynamics of a four-stroke internal combustion engine and plotted a P-V digram of an otto cycle for the same. And calculated the thermal efficiency for the otto cycle using a Python program.