Solving and plotting an Air Standard cycle (Otto cycle) using Python
AIM
To plot the Otto cycle and find its thermal efficiency.
OBJECTIVES
- To plot the PV diagram for the Otto cycle.
- To calculate the thermal efficiency of the cycle
THEORY
An Otto cycle is an ideal thermodynamic cycle that describes the function of a spark ignition piston engine. It is the thermodynamic cycle most commonly found in automobile engines. It describes 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 process starts when a mass of air is drawn from the atmosphere into the cylinder at constant pressure(0 to1)
The Otto cycle comprises of four processes,
- States 1-2 represent the Adiabatic/Isentropic compression,
- States 2-3 represent Constant volume Heat addition,
- States 3-4 represent Adiabatic/Isentropic expansion,
- States 4-1 represent the Constant volume Heat rejection
GOVERNING EQUATIONS
Calculation of Swept Volume
Swept Volume,`V_s=frac{pi}{4}timesd^2timesL`
where d=Bore, L=Stroke
Compression Ratio`=frac{V_s +V_c}{V_c}`
where
Vs =Swept Volume
Vc =Clearance Volume
Volume change inside the cylinder due to the Adiabatic/Isentropic Process
`frac{V}{V_c}=1+frac{1}{2}(r_c-1)[R+1-costheta-sqrt(R^2-sin^2theta)`
where
rc = Compression ratio
R = ratio of length of connecting rod to crank radius
`theta` = Crank angle
For any thermodynamic process
`frac{PV}{T}=Const.`
For Adiabatic/Isentropic process
`PV^gamma=Const.`
where `gamma` = Ratio of specific heats(Cp/Cv) of air = 1.4
Thermal efficiency of Otto cycle
Thermal efficiency`=[1-(r_c)^(1-gamma)]times100`
INPUT DATA ASSUMED
Initial Pressure and Temperature, P1=101325 Pascal, T1=500 Kelvin
Maximum Temperature inside cylinder, T3=2300 Kelvin
Engine geometric parameters-
Bore=0.1 m
Stroke=0.1 m
Length of Connecting rod=0.15 m
Compression ratio=8
CODE
Programming Language used- PYTHON
#Program to solve an Otto cycle and make plots for it
#Importing the required modules
import math
import matplotlib.pyplot as plt
import numpy as np
#Input parameters
#gamma for air=1.4
gamma=1.4
#Maximum temperature inside cylinder(in Kelvin)
T3=2300
#State variables at state point 1
#Atmospheric pressure(in Pascal)
P1=101325
#Temperature(in Kelvin)
T1=500
#Engine geometric parameters(in metres), compression ratio=V1/V2(unitless)
bore=0.1
stroke=0.1
con_rod=0.15
cr=8
#Calclating swept and clearance volume
V_swept=(math.pi/4)*pow(bore,2)*stroke
V_clearance=V_swept/(cr-1)
V1=V_clearance+V_swept
#State variables at state point 2
#V2=clearance volume
#P2*V2^gamma=P1*V1^gamma, P2=P1*(V1/V2)^gamma, P2=P1*cr^gamma
V2=V_clearance
P2=P1*pow(cr,gamma)
#P1*V1/T1=P2*V2/T2, T2=(P2*V2*T1)/(P1*V1)
T2=(P2*V2*T1)/(P1*V1)
#Defining the function
def engine_kinematics(bore,stroke,con_rod,cr,start_crank,end_crank):
#Crankpin radius(r) and crank radius(R)
r=stroke/2
R=con_rod/r
#Calculating swept volume and clearance volume
V_swept=(math.pi)/4*pow(bore,2)*stroke
V_clearance=V_swept/(cr-1)
#how volume changes inside a engine cylinder
#making linearly spaced vector of crank angle
sc=math.radians(start_crank)
ec=math.radians(end_crank)
theta=np.linspace(sc,ec,100)
V=[]
for i in theta:
term1=0.5*(cr-1)
term2=R+1-math.cos(i)
term3=pow(R,2)-pow(math.sin(i),2)
term3=pow(term3,0.5)
v=(1+term1*(term2-term3))*V_clearance
V.append(v)
return V
#Calculation of variation of Pressure and volume during adiabatic compression
const=P1*pow(V1,gamma)
V_compression=engine_kinematics(bore,stroke,con_rod,cr,180,0)
P_compression=[]
for i in V_compression:
P_compression.append(const/pow(i,gamma))
#State variables at state point 3
V3=V2
#P3*V3/T3=P2*V2/T2, P3=(P2*V2*T3)/(T2*V3)
P3=(P2*V2*T3)/(T2*V3)
#Calculation of variation of Pressure and volume during adiabatic expansion
Const=P3*pow(V3,gamma)
V_expansion=engine_kinematics(bore,stroke,con_rod,cr,180,360)
P_expansion=[]
for i in V_expansion:
P_expansion.append(Const/pow(i,gamma))
#State variables at state point 4
V4=V1
#P3*V3^gamma=P4*V4^gamma, P4=P3*(V3/V4)^gamma
P4=P3*pow((V3/V4),gamma)
#Temperature at state point 4, P3*V3/T3=P4*V4/T4 T4=(P4*V4*T3)/(P3*V3)
T4=(P4*V4*T3)/(P3*V3)
#Calculating thermal efficiency, ther_eff=(1-(cr^(1-gamma)))*100
ther_eff=(1-pow(cr,(1-gamma)))*100
print('The thermal efficiency of the Otto cycle for the given parameters is',ther_eff, 'percent')
#Plotting P-V diagram from state variables
plt.figure()
plt.xlabel('Volume')
plt.ylabel('Pressure')
plt.title('P-V diagram for Otto cycle')
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.show()
PROCEDURE
- First the required modules(i.e math, matplotlib.pyplot and numpy) are imported.
- Then the input parameters(i.e. gamma,P1,T1 and T3) are declared.
- The Engine geometric parameters are declared.
- The required state variables for State point-1 and State point-2 are calculated.
- The function ‘engine_kinematics’ is defined passing the required arguments.
- Then the function is called for calculation of variation of Volume and Pressure during adiabatic compression( from State point-1 to State point-2).
- Then the required state variables for State point-3 and State point-4 are calculated.
- The function is called again for calculation of variation of Volume and Pressure during adiabatic expansion( from State point-3 to State point-4).
- Then the thermal efficiency is calculated using the formula and printed.
- Plotting the points and lines resulting in the required P-V diagram of the Otto cycle.
RESULTS
P-V Diagram for Otto cycle
Thermal efficiency of Otto cycle
DISCUSSION
- The ‘numpy’ module is used for ‘linspace()’ command for varying the crank angle. Similarly the ‘math’ and ‘matplotlib’ modules are used for trigonometric commands[math.sin(), math.cos() and math.radians()] and plotting graphs respectively.
- Engine geometry such as bore diameter, stroke length, compression ratio, and connecting rod length are utilized to determine the swept and clearance volume .
- State variables are calculated using the thermodynamic equations for the processes(Adiabatic/Constant volume Heat addition/Constant volume Heat rejection).
- A function ‘engine_kinematics’ was defined to determine the volume for varying crank angles for the compression and expansion strokes. (180° to 360° and 0° to 180°, respectively) using the formula for variation of Volume with respect to the crank angle.
- The Pressure and Volumes of the four states were plotted, along with the real time pressure-volume profile of the compression and expansion strokes.
- So, a P-V diagram for the air standard cycle and one synonymous of the Otto cycle is attained.
- The thermal efficiency is obtained by the use of the mentioned equation.
ERRORS ENCOUNTERED
The P-V diagram obtained was wrong because the start crank angle and end crank angle were not converted to radians.
CONCLUSION
The Otto cycle is plotted with all the state points and its Thermal efficiency is calculated.