Week 2 Air standard Cycle
Objective:
To write a code that can solve an otto cycle and make plots for the same.
Problem Statements:
The python program should satisfy the following requirement
- Create a PV diagram
-
Output the thermal efficiency of the engine.
-
Create a project in projects.skill-lync.com after completion.
THEORY:
Otto cycle is also known as constant volume cycle is an air standard cycle on which the working of a petrol (Spark Ignition) engine is fully dependent. However, there is a vast difference between the Ideal Otto cycle and the actual Otto cycle due to the consideration of the external environmental factors and practical possibilities. But the Otto cycle is very essential to understand the working and also based on which the whole of the petrol engine technologies were developed.
PYTHON PROGRAM:
MAIN PROGRAM:
#Program for plotting the P-V Diagram for Otto Cycle
import math
import matplotlib.pyplot as plt
def Engine_Kinematics(bore, stroke, con_rod, cr, start_crank, end_crank):
a = stroke/2
R = con_rod/a
#Calculation of swpet volume and clearnace volume
v_s = math.pi*(1/4)*pow(bore,2)*(stroke)
v_c = (v_s)/(cr-1)
sc = math.radians(start_crank)
ec = math.radians(end_crank)
num_values = 50
dtheta = (ec - sc)/(num_values-1)
v = []
for i in range(0,num_values):
theta = sc + i*dtheta
term1 = 0.5*(cr-1)
term2 = R+1-math.cos(theta)
term3 = pow(R,2)-pow(math.sin(theta),2)
term3 = pow(term3,0.5)
v.append((1 + term1 * (term2 - term3) )* v_c)
return v
#Initial State Points
P1 = 101325 #Pa
T1 = 500 #Kelvin
gamma = 1.2 #Ratio of Cp and Cv
#Engine Dimensions
bore = 0.067 #meter
stroke = 0.0624 #meter
con_rod = 0.107 #meter
cr = 12.8
#Calculation of swept volume and clearnace volume
v_s = (math.pi/4)*pow(bore,2)*(stroke)
v_c = (v_s)/(cr-1)
v1 = v_s + v_c
v2 = v_c
#Variables at state point 2
#p1v1^gamma = p2v2^gamma
P2 = P1*pow(cr,gamma) # (v1/v2) = cr
#Pv = mRT p1v1 = mRT1 p2v2 = mRT2 p1v1/T1 = mR p2v2/T2 = mR
rhs = (P1*v1)/T1
T2 = (P2*v2)/rhs
v_compression = Engine_Kinematics(bore, stroke, con_rod, cr, 180, 0)
constant = P1*pow(v1,gamma)
P_compression = []
for v in v_compression:
P_compression.append(constant/(pow(v, gamma)))
#Variables at state point 3
v3 = v2
rhs = (P2*v2)/T2
T3 = 2300 #Kelvin
P3 = rhs*T3/v3
v_expansion = Engine_Kinematics(bore, stroke, con_rod, cr, 0, 180)
constant = P3*pow(v3,gamma)
P_expansion = []
for v in v_expansion:
P_expansion.append(constant/(pow(v, gamma)))
#Variables at State Point 4
v4 = v1
#P3v3^gamma = P4v4^gamma
P4 = (P3*pow(v3,gamma))/pow(v4,gamma)
#P3v3 = mRT3 || P4v4 = mRT4 || P3v3/T3 = P4v4/T4
rhs = (P3*v3)/T3
T4 = (P4*v4)/rhs
#Efficiency of Otto Cycle
#Efficiency = (workdone/heat supplied) = cv((T3-T2)-(T4-T1))/cv(T3-T2)
Efficiency_otto = 1-((T4-T1)/(T3-T2))
#(OR)
#Efficiency_otto = 1-(1/pow(cr,(gamma-1)));
print(Efficiency_otto)
#P-V Plot
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.show()
plt.savefig('P-V Diagram for Otto Cycle')
- Initially, the required inputs are typed in the program and based on the derivation and relations in Otto cycle the appropriate formulas are applied to calculate the unknown values like V1, V2, V3, V4, P2, P3, P4, T2, T3, T4.
- The Engine dimension values are typed in the program.
- Then in order to create the correct plot indicating the adiabatic curve we create a program to define the function 'Engine_Kinematics' as shown below.
FUNCTION PROGRAM:
import math
#Engine Dimensions
bore = 0.067 #meter
stroke = 0.0624 #meter
con_rod = 0.107 #meter
cr = 12.8
a = stroke/2
R = con_rod/a
#Calculation of swpet volume and clearnace volume
v_s = math.pi*(1/4)*pow(bore,2)*(stroke)
v_c = (v_s)/(cr-1)
theta = math.radians(180)
term1 = 0.5*(cr-1)
term2 = R+1-math.cos(theta)
term3 = pow(R,2)-pow(math.sin(theta),2)
term3 = pow(term3,0.5)
v = (1 + term1 * (term2 - term3) )* v_c
SOLUTION PROCEDURE:
- This program is copied and pasted in the main program.
- Now, we want adiabatic curves to be indicated in the plot, so after defining the Variables of state 2 and state 4 the expressions v_compression, P_compression, v_expansion and P_expansion are created respectively.
- The v_compression and v_expansion variables are equated to the defined function as shown in the above program.
- Then an empty array for P_compression and P_exapansion are created and then the constant value is appended into this array.
- Then a for loop is established such that for every value of v in v_compression, P_compression is computed.
- A total of 50 values of theta is executed between 0 and 180 as defined to obtain a smooth adiabatic curve.
- Finally, a total of 50 points between state 1 and state 2 are formulated and joined together to obtain a smooth adiabatic curve.
- The similar process is repeated for the adiabatic curve (Here adiabatic expansion) between state points 3 and 4.
- Finally, the plots are plotted and the graph is obtained.
RESULTS AND DISCUSSIONS:
PLOT:
OUTPUT:
The thermal efficiency of the otto cycle for the conditions defined in the above program is obtained as 39.944%.