Air standard Otto Cycle using Python
AIM: To write a program in Python to solve an Otto cycle and make plots for it.
OBJECTIVE :
- To solve and find out different state variables in the Otto cycle and plot its a p-V diagram.
- To calculate the thermal efficiency of the given Otto cycle.
THEORY: The Otto cycle is the perfect cycle for sparkle starts responding motors. In most flash start motors, the cylinder executes four complete strokes (two mechanical cycles) inside the chamber, and the driving rod finishes two insurgencies for each thermodynamic cycle. These motors are called four-stroke interior ignition motors.
At first, both the admission and the fumes valves are shut, and the cylinder is at its most minimal position (BDC). During the pressure stroke, the cylinder moves upward, packing the air-fuel blend. Without further ado before the cylinder arrives at its most elevated position (TDC), the sparkle plug fires and the blend touches off, expanding the weight and temperature of the framework. The high-pressure gases power the cylinder down, which thus powers the driving rod to turn, creating a valuable work yield during the development or force stroke. Toward the finish of this stroke, the cylinder is at its most minimal position (the culmination of the main mechanical cycle), and the chamber is loaded up with ignition items. Presently the cylinder moves upward once again, cleansing the fumes gases through the fumes valve (the fumes stroke), and during a time, attracting the natural air-fuel blend through the admission valve (the admission stroke). Notice that the weight in the chamber is somewhat over the air an incentive during the fumes stroke and marginally underneath during the admission stroke.
Fig.1 -Actual and ideal cycles in spark-ignition engines and their p-V diagrams.
The four processes in an Otto cycle are:
- 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 the Otto cycle are involved in this project. These are :
- Compression ratio (rc">rcrc) , rc=(V1V2)">rc=(V1V2)rc=(V1V2) or 1+VsVc">1+VsVc1+VsVc,
- Swept volume (Vs">VsVs) = π4⋅d2⋅l">π4⋅d2⋅lπ4⋅d2⋅l, where d is bore diameter and l is stroke length,
- VVc">VVcVVc = 1 + 12(rc-1)[R+1-cosθ-(R2-sin2θ)12]">12(rc−1)[R+1−cosθ−(R2−sin2θ)12]12(rc-1)[R+1-cosθ-(R2-sin2θ)12],
where R = length of connecting rod/crank radius ,
- Adiabatic process equation = p⋅vγ">p⋅vγp⋅vγ = constant,
- Ideal Gas equation = p⋅v=m⋅R⋅T">p⋅v=m⋅R⋅Tp⋅v=m⋅R⋅T,
- Thermal efficiency of Otto cycle(η">ηη)= 1-1rcγ-1">1−1rγ−1c1-1rcγ-1,
- From the figure, v1">v1v1 = vs+vc">vs+vcvs+vc , v2=vc">v2=vcv2=vc.
BODY OF THE CONTENT :
EXPLANATION OF PYTHON CODES :
- Since Otto cycle is an air-standard cycle, the specific heat (γ">γγ) of air is taken as 1.4.
- Initial conditions, such as temperature (T1">T1T1)and pressure (p1">p1p1) of surroundings 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 the connecting rod is also known and accordingly vs">vsvs and vc">vcvc are calculated.
- The maximum temperature (T3">T3T3) 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 straight line.
- So to rectify this, a different function is created for storing 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.
PYTHON CODE FOR SOLVING AND 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 geometrical parameters
r = stroke/2
n = connecting_rod/r
# Engine Volume related parameters
v_swept = (math.pi/4)*pow(bore,2)*stroke
v_clearance = v_swept/(c_r -1)
# For different values of theta we have to calculate the variables
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 #After constant volume heat addition(i.e max temp inside engine cylinder)
# State variable
# ambient atmospheric conditions assumed
p1 = 101325 #(in pascals)
T1 = 350 #(in kelvin)
# 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
# Variables at state point 2
# p2*v2^gamma = p1*v1^gamma --- ..............Isentropic compression
p2 = p1* pow(c_r,gamma) #...........we know (v1/v2) is compression ratio
# (p1v1)/T1 = (p2v2)/T2 |(p1v1)/T1 = rhs | (p2v2)/T2 = rhs | 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(Volume is constant)
''' (p3*v3)/T3 = (p2*v2)/T2 |as volume is same | 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(Volume is constant)
''' p3*v3^gamma = p4*v4^gamma ''' # Isentropic expansion process(ds = 0)
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)
RESULTS :
- Upon executing the above program,the following plot for p-V curve was observed:
- The themal efficiency calculated and the program written are as follows:
CONCLUSION: 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 angles.
REFERENCES:
1.Engineering Thermodynamics by PK NAG
2 . The Internal combustion engine (Otto Cycle)
NOTATIONS :
- p">pp = pressure,
- v">vv = volume of engine cylinder,
- T">TT = temperature,
- vc">vcvc = clearance volume, (Clearance volume is a volume between the cylinder head and the piston top when the piston is at top dead center (TDC).),
- vs">vsvs = swept volume,(Swept volume is the displacement of one cylinder. It is the volume between top dead center (TDC) and bottom dead center (BDC).),
- γ">γγ= specific heat,
- d">dd = bore diameter (diameter of each cylinder)
- l">ll= 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,