Python Program: Air Standard Cycle (Otto Cycle)
Aim: Write a Python code for plotting PV diagram of air standard cycle.
Objectives:
- Plotting PV diagram (workflow diagram) for Otto cycle.
- Determining air standard efficiency (thermal efficiency).
Theory:
Air Standard Cycle: The cycle in which air is used as a working substance is called an air standard cycle.
Air Standard Efficiency: Ratio of work done by the system to heat input to the system is known as an "Air Standard Efficiency". This efficiency is ideal efficiency.
`eta` = Work Done / Heat Supplied
Air Standard Assusmptions:
- The working fluid is air, which continuously circulates in a closed loop and always behaves as an ideal gas.
- All the processes that make up the cycle are internally reversible.
- The combustion process is replaced by a heat-addition process from an exteranal source.
- The exhaust process is replaced by a heat-rejection process that restores the working fluid to its initial state.
- The physical constants of air are constant.
The Otto Cycle:
The Otto cycle is the Ideal cycle for spark-ignition reciprocating engines. It is named after Nikolaus A. Otto, who built a successful four stroke engine in 1876 in Germany using cycle proposed by Frenchman Beau de Rochas in 1862. In most spark-ignition engines, the piston executes four complete strokes (two mechanical cycles) within the cylinder, and the crankshaft completes two revolutions for each thermodynamic cycle. These engines are called Four-stroke Internal Combustion Engines. A schematic of each stroke as well as PV diagram for an actual four-stroke spark-ignition engine is as shown above.
The working of an Ideal Otto Cycle:
- Process 1-2: Isentropic compression of air.
- Process 2-3: Isochoric heat addition.
- Process 3-4: Isentropic expansion of air.
- Process 4-1: Isochoric heat rejection.
Formulae:
1. Governing Equations:
- Isentropic process: `PV^(gamma)` = Constant
- Isochoric process: `P/T` = Constant
2. Ideal gas equation:
`(PV)/T` = Constant
3. Compression Ratio:
CR = `(Vs + Vc)/Vc`
4. Change of Volume inside the engine combustion chamber is given by
`V/(Vc) = 1+1/2(CR-1)[R+1-cos(theta)-(R^2-(sin(theta))^2)^(1/2)]
5. Thermal Efficiency
`eta = 1- 1/(RC)^(gamma-1)`
where,
P = Pressure (`N/m^2`)
V = Volume (`m^3`)
T = Temperature (Kelvin)
`gamma` = ratio of specific heats
Vs = Swept volume
Vc = Clearance volume
V = Volume when piston moves at an angle
R = Ratio of length of connecting rod to crank pin radius
crank pin radius = stroke length/2
Program:
The program required to perform the aforementioned tasks is as follows:
"""
Air Standard Cycle (Otto Cycle)
Processes:-
1-2 Isentropic Compression
2-3 Isochoric heat addition
3-4 Isentropic Expansion
4-1 Isochoric heat rejection
"""
from numpy import *
from matplotlib.pyplot import *
# Inputs
print("AIR STANDARD CYCLE (OTTO CYCLE)\n\n")
print("Please Enter The Values For Prompted Parameters\n\n")
print("REMEBER GARBAGE INPUTS LEADS TO GARBAGE OUTPUTS\n\n")
print("Make Sure All Values Are In SI Units\n\n")
#State points
p1 = float(input("Pressure At State 1 : ")) # Pressure at state 1 (Pa)
t1 = float(input("Temperature At State 1 : ")) # Temperature at state 1 (K)
t3 = float(input("Temperature At State 3 : ")) # Temperature at state 3 (K)
#Engine geometry
cr = float(input("The Value Of Compression Ratio : ")) # Compression ratio
d = float(input("Bore Diameter : ")) # Bore diameter (m)
L = float(input("Stroke Length : ")) # Stroke length (m)
gamma = 1.4 # Ratio of specific heats
con_rod = float(input("Conrod Length : ")) # Connecting rod length (m)
crank = L/2 # Crank Radius
R = con_rod/crank
theta12 = radians(arange(180,361,1)) # Crank angles for process 1-2 in steps of 1 degree
theta34 = radians(arange(0,181,1)) # Crank angles for process 3-4 in steps of 1 degree
# State Calculations
Vs = (pi/4)*d*d*L # Swept volume (m^3)
Vc = Vs/(cr-1) # Compressed volume (m^3)
V1 = Vs+Vc # Volume at state 1 (m^3)
V4 = V1 # Volume at state 4 (m^3)
V2 = Vc # Volume at state 2 (m^3)
p2 = p1*pow((V1/V2),gamma) # Pressure at state 2 (Pa)
t2 = t1*(p2/p1)*(V2/V1) # Temperature at state 2 (K)
p3 = p2*(t3/t2) # Pressure at state 3 (Pa)
V3 = V2 # Volume at state 3 (m^3)
p4 = p3*pow((V3/V4),gamma) # Pressure at state 4 (Pa)
t4 = t3*(p4/p3)*pow((V4/V3),gamma) # Temperature at state 4 (K)
# Process Calculations
# Process 1-2 (compression)
term1 = R+1-cos(theta12) # R + 1 - cos(theta)
term2 = R*R - square(sin(theta12)) # R^2 - sin(theta)^2
term3 = term1 - sqrt(term2)
V_comp = Vc * (1 + 0.5 * (cr - 1) * term3)
p_comp = p1*pow((V1/V_comp),gamma)
# Process 3-4 (expansion)
term1 = R+1-cos(theta34) # R + 1 - cos(theta)
term2 = R*R - square(sin(theta34)) # R^2 - sin(theta)^2
term3 = term1 - sqrt(term2)
V_exp = Vc * (1 + 0.5 * (cr - 1) * term3)
p_exp = p3*pow((V3/V_exp),gamma)
# Efficiency Calculation
eff = (1 - (1/(pow(cr,gamma-1)))) * 100
print('\nEfficiency = {} %\n'.format(eff))
# Plot
plot(V_comp,p_comp,label='Isentropic Compression')
plot([V2,V3],[p2,p3],label='Isochoric Heat Addition')
plot(V_exp,p_exp,label='Isentropic Expansion')
plot([V4,V1],[p4,p1],label='Isochoric Heat Rejection')
legend()
xlabel('Volume (m^3)')
ylabel('Pressure (Pa)')
title('Air Standard Cycle - Otto Cycle')
savefig("pv-diagram.png")
show()
Working of Code:
1. The code starts with importing required libraries. We use numpy and matplotlib.pyplot libraries for calculations and plotting respectively.
2. Then we need to provide inputs. The input syntax is used to make program universal and the numeric inputs are typecasted to float to prevent loss of values due to operations on int.
3. We define crank angles as a numpy array using command called arange. Further these angle values are converted from degrees to radians.
4. The values of state variables at different state points are defined by use of governing equations and the relation given in theory.
5. Thus, when the volume in combustion chamber at different angles are calculated, it results in creation of an array of compression and expansion stroke volumes.
6. Air standard efficiency is calculated and displayed. Plotting of corresponding pressure and volume values is done to ensure that plot is embelished sequentially. This is done using plot command. Suitable labels and title is provided by use of label, legends and title command.
7. savefig command saves the PV diagram as an image file (in png format)
Outputs:
Result & Conclusion:
- The PV diagram of Otto Cycle has been plotted successfully.
- The air standard efficiency (thermal effieciency) was found to be 56.47247% (for given inputs).
- Hence, air standard efficiency depends only on compression ratio.
- For high compression ratio, air standard efficiency is high.
- But at higher compression ratios knocking occurs, hence an optimum compression ratio must be selected.
References:
- Python for Mechanical Engineers - Course provided by Skill Lync
- Google Colab - Google LLC
- JupyterLab - Jupyter Project
- Anaconda Inc.
- Supporting Material: Thermodynamics - an engineering approach (SIE) - Yunus Cengel, Michael Boles, Mehmet Kanoglu
- Supporting Material: Energy Engineering - VP Katekar Sir
Material: Python Code, Notebook and Other Resources can be accessed here