Challenge

Week 2 Air standard Cycle

INTRODUCTION

Otto cycle is the air standard cycle behind the working of gasoline engines. The Otto cycle consists of two isentropic and two constant volume processes. Heat addition and rejection takes place at a constant volume. The expansion and compression are adiabatic processes.

AIM

The aim of this challenge is to write a code to generate the indicator diagram (p-v) diagram of the Otto cycle using python and also to calculate the thermal efficiency of the cycle.

RESULTS

The Otto cycle is an air standard cycle which has an ideal gas as the working fluid, which means all the process obeys the ideal gas law i.e `\frac{pv}{T} = constant`.

Where p, v, T represents the pressure, volume and temperature respectively and `gamma` is the ratio of specific heats.

The process 1 to 2 is a reversible adiabatic process also known as an isentropic process, so for the state points 1 and 2 we can say that `p_1v_1^\gamma = p_2v_2^\gamma`. The process 2 to 3 is a constant volume process, i.e `v_2 = v_3`. The temperature at state point 2 can be found out using the ideal gas law.

The temperature at state point 3 is the maximum temperature and it is a design limit, which should be properly assumed.

For process 3 to 4, we have the equation `p_3v_3^\gamma = p_4v_4^\gamma` and the volume at the state point 4 is the same as the volume at state point 1, i.e `v_1 = v_4`. The temperature at state point 4 can be found using the ideal gas law.

For an ideal Otto cycle, the thermal efficiency is a function of compression ratio only, which can be expressed using the following equation `eta = 1 - \frac{1}{r^(gamma -1)]`

The isentropic process the volume trace can be found out using the engine kinematics where the equation of x displacement is calculated which can be modified to calculate the swept volume for the given instant:

`\frac{V}{V_c} = 1 +\frac{1}{2}(r_c-1)[R + 1 -cos\theta - (R^2 - sin^2\theta)^2]`

The pressure at each point for the given volume can be found out using the relationship for an isentropic process i.e

`pv^gamma = constant`

The python code for plotting the otto cycle indicator diagram is given below:

"""
Otto Cycle 
"""
import matplotlib.pyplot as plt
import math
import numpy as np


#inputs
p1 = 1.01325 #Pa
T1 = 300 #K
T3 = 2300 #K
# geometric parameters
stroke = 0.2 # stroke length in m
bore = 0.2 # bore in m
cr  = 12 # compression ratio
gamma = 1.4 # ratio of specific heats
con_rod = 0.3 # connecting rod length


def engine_kinematics(bore,stroke,con_rod,cr,start_crank,end_crank):
    
    V_s = (math.pi/4)*stroke*pow(bore,2)
    V_c = V_s/(cr-1)



    a = stroke/2 #crank radius
    R = con_rod/a #
    
    sc = math.radians(start_crank)
    ec = math.radians(end_crank)
    
    num_values = 50
    
    theta = np.linspace(sc,ec,num_values)
    
    V = []
    
    for dtheta in theta:
         term2 = R + 1 - math.cos(dtheta)
         term3 = pow(R,2)-pow(math.sin(dtheta),2)
         term3 = pow(term3,0.5)
         term1 = 0.5*(cr-1)
         V.append((1 + term1*(term2-term3))*V_c)
         
    
    return V
    
# Calculation of swept volume
V_s = (math.pi/4)*stroke*pow(bore,2)

# Calculation of clearance volume
V_c = V_s/(cr-1)

v1 = V_s + V_c

"""
For an ideal gas p1v1/T1 = constant
"""

constant = (p1*v1)/T1

"""
For the process 1--->2 p1v1^gamma = p2v2^gamma

For any ideal process p1v1/T1 = constant = p2v2/T2
"""

v2 = V_c

p2 = (p1*pow(v1,gamma))/pow(v2,gamma)

T2 = (p2*v2)/constant

V_compression = engine_kinematics(bore,stroke,con_rod,cr,180,0)

P_compression = []

"""
p1v1^gamma = con
"""
con1 = p1*pow(v1,gamma)

for v in V_compression:
    P_compression.append(con1/pow(v,gamma))

""""
For the process 2--->3 v2 = v3

For any ideal process p2v2/T2 = constant = p3v3/T3


"""

v3 = v2
p3 = (constant*T3)/v3

"""
For the process 3--->4 p3v3^gamma = p4v4^gamma
v4 = v1
p4v4/T4 = constant
"""

V_expansion = engine_kinematics(bore,stroke,con_rod,cr,0,180)

P_expansion = []

"""
p3v3^gamma = con
"""
con2 = p3*pow(v3,gamma)

for v in V_expansion:
    P_expansion.append(con2/pow(v,gamma))


v4 = v1
p4 = (p3*pow(v3,gamma))/pow(v4,gamma)
T4 = (p4*v4)/constant

plt.plot([v2,v3],[p2,p3])
plt.plot(V_compression,P_compression)
plt.plot(V_expansion,P_expansion)
plt.plot([v1,v4],[p1,p4])
plt.xlabel('Volume ($m^3$)')
plt.ylabel('Pressure ($MPa$)')

plt.show()




The Otto cycle indicator diagram generated using the above code is given below:

A function engine_kinematics is used to calculate the volume at each position of the crank. The initial temperature and pressure are assumed to be 1.01325 MPa and the initial temperature to be 300 K. The maximum temperature is assumed to be 2300 K. The state points at all the four different points are calculated using the ideal gas law and the expressions mentioned as above. Matplotlib library is used for plotting the indicator diagram.

CONCLUSION

The indicator diagram for the Otto cycle is plotted using the python code.

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.