Air standard Cycle (Python)
| Air standard Cycle using Python |
1. AIM : To write a program in Python to solve an Otto cycle and make plots for it.
2. OBJECTIVE :
- To solve and find out different state variables in the Otto cycle and plot its p-V diagram.
- To calculate the thermal efficiency of the given Otto cycle.
3. THEORY :
3.1 Otto Cycle: - The Otto cycle is the ideal cycle for spark-ignition reciprocating engines. 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.
Initially, both the intake and the exhaust valves are closed, and the piston is at its lowest position (BDC). During the compression stroke, the piston moves upward, compressing the air-fuel mixture. Shortly before the piston reaches its highest position (TDC), the spark plug fires and the mixtureignites, increasing the pressure and temperature of the system. The high-pressure gases force the piston down, which in turn forces the crankshaft to rotate, producing a useful work output during the expansion or power stroke. At the end of this stroke, the piston is at its lowest position (the completionof the first mechanical cycle), and the cylinder is filled with combustion products. Now the piston moves upward one more time, purging the exhaust gases through the exhaust valve (the exhaust stroke), and down a second time, drawing in the fresh air-fuel mixture through the intake valve (the intakestroke). Notice that the pressure in the cylinder is slightly above the atmospheric value during the exhaust stroke and slightly below during the intake stroke.
fig.1: Actual and ideal cycles in spark-ignition engines and their p-V diagrams
The four processes in an Otto cycle are as follows :
- Isentropic compression process or Reversible adiabatic compression of air (Process 1-2),
- Constant volume heat addition process (Process 2-3),
- Isentropic expansion process or Reversible adiabatic expansion of air (Process 3-4),
- Constant volume heat rejection process (Process 4-1).
GOVERNING EQUATIONS :
Various equations of Otto cycle are involved in this project. These are :
Compression ratio (rc) , rc=(`V_1/V_2`) or `1+(V_s/V_c)`,
Swept volume (Vs) = `π/4*d^2*l`, where d is bore diameter and l is stroke length,
`V/V_c = 1 + 1/2(rc−1)[R+1−cosθ−(R^2−sin^2θ)^(1/2)]`
where, R = length of connecting rod/crank radius,
Adiabatic process equation =`p*v^γ`= constant,
Ideal Gas equation = p⋅v=m⋅R⋅T,
4. BODY OF CONTENT :
4.1 Explanation of python Code -
- Since the Otto cycle is an air-standard cycle, the specific heat (γ) of air is taken as 1.4.
- Initial conditions, such as temperature (T1)and pressure (p1) of the surrounding is assumed to be 350K and 101.325 kPa respectively.
- The geometrical design of the engine cylinder which consists of bore diameter, stroke length, and length of connecting rod is also known and accordingly vs and vc are calculated.
- The maximum temperature (T3) occurring inside the cylinder is also known.
- Other state variables are calculated using Adiabatic processes equations and ideal gas equations.
- Similarly, the thermal efficiency is also calculated accordingly using the formula given.
- For plotting the calculated state variables on a p-v diagram with just using 'plt.plot' the command will yield into the incorrect p-v diagram,i.e, compression and expansion stroke is represented by a straight line.
- So to rectify this, a different function is created for storing the different values of crank angle rotation as compression and expansion occur in different strokes or cycles. This function is then called to the main program and accordingly, the plot is drawn from various points obtained.
- For this number of values for which the program will iterate is 100, and accordingly, the V array is set as null and after every iteration using for loop, a new value will be stored as an array using 'append' command and will be returned back after receiving desired values.
Code for plotting curve :
''' A program to calculate different state variables in an Otto Cycle and to calculate its thermal efficiency and plot it on p-v diagram '''
import math
import matplotlib.pyplot as plt
def engine_kinematics(bore,stroke,connecting_rod,c_r,start_crank_angle,end_crank_angle):
# Engine geometry properties
r = stroke/2
n = connecting_rod/r
# Volume parameters
v_swept = (math.pi/4)*pow(bore,2)*stroke
v_clearance = v_swept/(c_r -1)
theta_startcrank = math.radians(start_crank_angle)
theta_endcrank = math.radians(end_crank_angle)
num_val = 100
dtheta = (theta_endcrank - theta_startcrank)/(num_val - 1)
V = []
for i in range(0,num_val):
theta = theta_startcrank + i*dtheta
term_1 = 0.5*(c_r - 1)
term_2 = n + 1 - math.cos(theta)
term_3 = (pow(n,2) - pow(math.sin(theta),2))
term_3 = pow(term_3,0.5)
V.append((1 + term_1* (term_2 -term_3))*v_clearance)
return V
# Inputs varibale
gamma = 1.4 # for air gamma= 1.4
T3 = 2000 # max temp inside engine cyr
# State variable
# ambient atmospheric conditions assumed
p1 = 101325
T1 = 350
# Engine geometry properties
bore = 0.15
stroke = 0.2
connecting_rod = 0.8
c_r = 10
# Calculating swept volume and clearance volume
v_swept = (math.pi/4)*pow(bore,2)*stroke
v_clearance = v_swept/(c_r -1)
v1 = v_swept + v_clearance
v2 = v_clearance
# state variables at state point 2
# p2*v2^gamma = p1*v1^gamma --- Isentropic compression
p2 = p1* pow(c_r,gamma)
# (p1*v1)/T1 = (p2*v2)/T2 | T2 = p2*v2*T1/(p1*v1)
T2 = p2*v2*T1/(p1*v1)
V_comp = engine_kinematics(bore,stroke,connecting_rod,c_r,180,0)
C_const = p1*pow(v1,gamma)
P_comp = []
for v in V_comp:
P_comp.append(C_const/pow(v,gamma))
# State variables at state point 3
v3 = v2 # Isochoric process
''' (p3*v3)/T3 = (p2*v2)/T2 | p3 = p2*T3/(T2) '''
p3 = p2*T3/(T2)
V_expp = engine_kinematics(bore,stroke,connecting_rod,c_r,0,180)
C_const = p3*pow(v3,gamma)
P_expp = []
for v in V_expp:
P_expp.append(C_const/pow(v,gamma))
# state variables at state point 4
v4 = v1 # Isochoric process
''' p3*v3^gamma = p4*v4^gamma ''' # Isentropic expansion process
p4 = p3*pow(v3,gamma)/pow(v4,gamma)
''' (p3*v3)/T3 = (p4*v4)/T4 | T4 = p4*v4*T3/(p3*v3) '''
T4 = p4*v4*T3/(p3*v3)
plt.plot(V_comp,P_comp)
plt.plot([v2,v3],[p2,p3])
plt.plot(V_expp,P_expp)
plt.plot([v4,v1],[p4,p1])
plt.ylim([-500000,8000000])
plt.xlim([0,0.005])
plt.xlabel('Volume (m^3)')
plt.ylabel('Pressure(Pa)')
plt.title('p-V diagram of an Otto Cycle')
plt.text(0.00385,-250000,r'$ 1 $')
plt.text(0.0002,2000000,r'$ 2 $')
plt.text(0.0002,5850000,r'$ 3 $')
plt.text(0.00385,400000,r'$ 4 $')
plt.grid()
plt.show()
#Calculating thermal efficiency
thermal_efficincy = 1- (1/pow((c_r),(gamma-1)))
print('Thermal efficiency of given Otto Cycle is :',thermal_efficincy)
5. RESULTS :
After executing the above program, the following plot for p-V curve was obtained :
The thermal efficiency calculated and the program written as follows :
Output thermal efficiency :
Thermal Efficiency = 0.6018928294465027
6. CONCLUSON : The desired and correct p-V diagram of the Otto cycle was obtained using an array of volume inside the engine cylinder at a different crank angle.
NOTATIONS used in report :
p = pressure
v = volume of engine cylinder
T = temperature
vc = clearance volume (`V_c`), (Clearance volume is a volume between the cylinder head and the piston top when the piston is at top dead center (TDC).)
vs = swept volume (`V_s`), (Swept volume is the displacement of one cylinder. It is the volume between top dead center (TDC) and bottom dead center (BDC).)
d = bore diameter (diameter of each cylinder)
l= stroke length (The stroke length is how far the piston travels in the cylinder, which is determined by the cranks on the crankshaft.)
η= thermal efficiency .