Air standard Cycle using Python
Aim: To develop a PYTHON program to solve an Otto cycle problem and
- Plot a PV diagram
- Find the thermal Efficiency of the cycle
Theory:
The Otto Cycle, describes how heat engines turn gasoline into motion. Like other thermodynamic cycles, this cycle turns chemical energy into thermal energy and then into motion. The Otto cycle describes how internal combustion engines (that use gasoline) work, like automobiles and lawn mowers.
The diagram below shows PV plot of a Standard Otto Cycle. For further reading, kindly refer to encyclopedia/Otto_cycle
|
Given input Parameters: |
Assumptions: |
|
Bore: 100mm = 0.10m |
Adiabatic index of air = 1.4 |
|
Stroke: 100mm = 0.10m |
Connecting rod length = 0.15 m |
|
Initial Pressure: 1 bar = 101325 Pa |
|
|
Initial Temperature: 50⁰C = 323 K |
|
|
Maximum Temperature = 2300 K |
Program
"""
Otto Cycle program
By Saurav Sankhe
"""
# Importing Libraries
import matplotlib.pyplot as plt
import math
# Inputs
"""
Units for each parameters are as follows:
Bore and Stroke in metres
Pressure in Pascals
Temperature in Kelvin
Connecting rod length in metres
"""
bore = 0.10
stroke = 0.1
rc = 8
gamma = 1.4
P1 = 101325
T1 = 500
T3 = 2300
Con_rod = 0.15
# Calculating Stroke Volume
V_s = (math.pi)/4*pow(bore,2)*stroke
V_c = V_s/(rc - 1)
# Calculating Compression Ratio
V1 = V_c + V_s
# Defining Function
def engine_kinematics(bore,stroke,Con_rod,rc,start_crank,end_crank):
# Geometric Parameters
a = stroke/2
R = Con_rod/a
V_s = math.pi*(1/4)*pow(bore,2)*stroke
V_c = V_s/(rc - 1)
sc = math.radians(start_crank)
ec = math.radians(end_crank)
num_values = 100
dtheta = (ec - sc)/(num_values - 1)
V = []
for i in range(0,num_values):
theta = sc + i*dtheta
term1 = 0.5*(rc - 1)
term2 = R + 1 - math.cos(theta)
term3 = pow((pow(R,2)-pow(math.sin(theta),2)),0.5)
V.append((1 + term1*(term2 - term3))*V_c)
return V
# State variables at State 2
P2 = P1*pow(rc,gamma)
V2 = V_c
T2 = (P2*V2*T1)/(P1*V1)
V_compression = engine_kinematics(bore,stroke,Con_rod,rc,180,0)
# P_compression*V_compression^gamma = constant
constant = P1*pow(V1,gamma)
P_compression = []
for v in V_compression:
P_compression.append(constant/pow(v , gamma))
# State variables at State 3
V3 = V2
P3 = (P2*V2*T3)/ (T2*V3);
# P_expansion*V_expansion^gamma = constant
V_expansion = engine_kinematics(bore,stroke,Con_rod,rc,0,180)
constant = P3*pow(V3,gamma)
P_expansion = []
for v in V_expansion:
P_expansion.append(constant/pow(v , gamma))
# State Variables at State 4
V4 = V1
P4 = P3*pow((V3/V4),gamma)
# Thermal Efficiency of the Cycle
Eta_th = 1 - pow((1/rc),(gamma-1))
print('Otto Cycle by Saurav Sankhe')
print('Thermal Efficiency of Otto Cycle is',Eta_th*100, 'percent')
# Plotting the PV Graph
plt.title('PV Diagram of Otto Cycle')
plt.xlabel('Volume m^3')
plt.ylabel('Pressure Pa')
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.savefig('PV Diagram of Otto Cycle')
plt.show()
Output
Otto Cycle by Saurav Sankhe
Thermal Efficiency of Otto Cycle is 56.47247183519378 percent
[Finished in 5.1s]
Program Explanation:
- Program was started by importing matplotlib and math libraries.
- Then Input variables and Assumptions for the problem were defined.
- Then each state variables were calculated at respective state points using necessary equations as follows:
- `PV^γ="constant"`
- `(PV)/T="constant"`
- Then the thermal efficiency was calculated and printed by using the following formula
- `1-1/(r_c )^(γ-1)`
- Finally, the state points were plotted on PV plot using plot command along with its library specification.
- In order to understand the nature of curve during expansion and compression, we used piston volume relation. The relation being a complex one, it was converted into a function.
- `V/V_c =1+1/2 (r_c-1)[R+1-cos(θ)-[(R^2-(sin)^2 (θ))^(1/2) ]`