Week 2 Air standard Cycle
- AIM:
The main aim of the challenge is to code a program to plot P-V diagram of Air Standard cycle using python.
- OBJECTIVE:
Otto cycle or constant volume cycle,on this cycle petrol engine ,gas and many types of engine work.It is a standard or comparision cycle to the internal combustion engine.The p-v and T-s diagram are shown in the figure.

- THERMAL EFFICIENCY OF AN OTTO CYCLE:
Let us consider 1kg of air(working substance)
Heat supplied at constant volume = c_v*(t3-t2) c_v = specific heat at constant volume in j/kg-k
Heat rejected at constant pressure = c_v*(t4-t1)
efficiency = workdone/heat supplied
= 1-(t4-t1)/(t3-t2) ............................. (1)
compression ratio c_r = v1/v2
from 1 - 2
As it is isentropic compression p1*v1^gamma = p2*v2^gamma gamma = c_p/c_v
t2/t1 = (v1/v2)^(gamma-1) ........................(2)
from 3-4
As it is isentropic expansion p3*v3^gamma = p4*v4^gamma
t3/t4 = (v4/v3)^(gamma-1)........................(3)
substitute the equation (2) and (3) in equation (1)
EFFICIENCY = 1-1/(C_R)^(GAMMA-1)
This expression is known as air standard or thermal efficiency of an otto cycle.
- CODING:
#Importing the required modules
import math
import matplotlib.pyplot as plt
#Defining the function
def engine_kinematics(bore,stroke,con_rod,cr,start_crank,end_crank):
#Geometric parameters
a = stroke/2
R=con_rod/a
#Volume calculation
V_s = (math.pi/4)*pow(bore,2)*stroke #swept volume
V_c = V_s/(cr-1) #clearence volume
sc = math.radians(start_crank)
ec = math.radians(end_crank)
num_values = 50
dtheta = (ec-sc)/(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
#Inputs
P1 = 0.1 #pressure at state1
t1 = 500 #Temperature at state1
gamma = 1.4
t3=2300 #Temperature at state 3
#Geometric parameters
bore = 0.1
stroke = 0.1
con_rod = 0.15
cr = 12
#Volume calculation
V_s = (math.pi/4)*pow(bore,2)*stroke #swept volume
V_c = V_s/(cr-1) #clearence volume
V1 = V_c+V_s
#At state point2
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))
#At stste point3
V3 = V2
#P3V3/t3 = P2V2/t2 |rhs = P2V2/t2 | P2 = 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))
#At state point4
V4 = V1
#P4V4^gamma = P3V3^gamma
P4 = P3*pow(V3,gamma)/pow(V4,gamma)
t4 = P4*V4/rhs
#Thermal Efficiency of engine
Thermal_eff = 1-(pow(cr,(1-gamma)))
print(Thermal_eff)
#Plotting
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('Otto Cycle')
plt.show()
- EXPLANATION:
- Import math and plot module because the code has to plot p-v diagram of otto cycle.
- Enter the initial conditions `P_1`,`t_1`and `t_3` and `gamma=1.4`.
- Enter all the geometrical parameters which consists of bore,stroke,length of connecting rod and compression ratio and calculate swept volume and clearence volume using the formula.
- State variables are calculated using Adiabatic relation and ideal gas equation.
- Volume change during compression and expansion process is determined by the relation.
- Plot pressure vs volume using plot command as shown.
- Calculate the thermal efficiency using the relation.
- PLOT:

- OUTPUT:

- CONCLUSION:
Thermal efficiency of an otto cycle is found to be 62.98% and p-v diagram of otto cycle has been plotted.