Week 2 Air standard Cycle
Question) Plot the PV diagram for the Otto cycle and further find the Thermal Efficiency.
Code:-
import math
import matplotlib.pyplot as plt
def engine_kinematics(bore, stroke, con_rod, cr, start_crank, end_crank):
# Geometric Parameters
a = stroke/2 # crank pin radius
R = con_rod/a # Ration of the lengths of connecting rod and crank pin
#Volume Parameters
V_s = (math.pi/4)*pow(bore,2)*stroke
V_c = V_s/(cr-1)
sc = math.radians(start_crank) #starting crank angle
ec = math.radians(end_crank) #ending crank angle
num_values = 60
dtheta = (ec-sc)/(num_values-1)
V = []
for i in range (0,num_values):
theta = sc + i*dtheta
print(theta)
#Relationship between the crank angle and the volume inside the combustion chamber is broken into 3 terms.
term1 = 0.5*(cr-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
#Inputs
p1 = 101325 #Pressure
t1 = 500 #Temperature
gamma = 1.4
t3 = 2300
#Geometric Parameters
bore = 0.1
stroke = 0.1
con_rod = 0.15 #Connecting rod length
cr = 7 #Compression ratio
#Volume Computation
v_s = (math.pi/4)*pow(bore,2)*stroke #Swept Volume
v_c = v_s/(cr-1) #Clearance Volume
v1 = v_c + v_s #Volume at state 1
# State point 2
v2 = v_c
# p2v2^gamma = p1v1^gamma
p2 = p1*pow(v1,gamma)/pow(v2,gamma)
# p2v2/t2 = p1v1/t1 -- (Ideal gas law)
# p1v1/t1 is taken as rhs and therefore t2 is determined by substitution
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*V_compression^gamma = constant
P_compression = []
for V in V_compression:
P_compression.append(constant/pow(V,gamma))
#state point 3
v3 = v2
# p3v3/t3 = p2v2/t2
# p2v2/t2 is taken as rhs and therefore p3 is deteremined as p3 = rhs*t3/v3
rhs = p2*v2/t2
p3 = rhs*t3/v3
V_expansion = engine_kinematics(bore, stroke, con_rod,cr,180,0)
constant = p3*pow(v3,gamma) #P_compression*V_compression^gamma = constant
P_expansion = []
for V in V_expansion:
P_expansion.append(constant/pow(V,gamma))
# state point 4
v4 = v1
# p4v4^gamma = p3v3^gamma
p4 = p3*pow(v3,gamma)/pow(v4,gamma)
# p4v4/t4 is taken as rhs (rhs is always a constant since the begining)
t4 = p4*v4/rhs
thermal_eff = (1-1/pow(cr,(gamma-1)))*100 # Thermal efficiency of Otto cycle
print("thermal efficiency =" , thermal_eff)
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.title("OTTO CYCLE")
plt.xlabel("Volume")
plt.ylabel("Pressure")
plt.show()
Command Window:-
3.141592653589793
3.0883453204781017
3.0350979873664103
2.981850654254719
2.9286033211430276
2.875355988031336
2.822108654919645
2.7688613218079534
2.715613988696262
2.6623666555845706
2.6091193224728793
2.5558719893611874
2.5026246562494965
2.4493773231378047
2.3961299900261133
2.342882656914422
2.2896353238027305
2.236387990691039
2.1831406575793477
2.1298933244676563
2.076645991355965
2.0233986582442736
1.9701513251325822
1.9169039920208908
1.8636566589091994
1.810409325797508
1.7571619926858166
1.703914659574125
1.6506673264624336
1.5974199933507423
1.5441726602390509
1.4909253271273595
1.437677994015668
1.3844306609039767
1.3311833277922853
1.277935994680594
1.2246886615689025
1.1714413284572112
1.1181939953455196
1.0649466622338282
1.0116993291221368
0.9584519960104454
0.905204662898754
0.8519573297870626
0.7987099966753712
0.7454626635636799
0.6922153304519885
0.6389679973402971
0.5857206642286057
0.5324733311169143
0.4792259980052229
0.42597866489353153
0.37273133178184015
0.31948399867014876
0.26623666555845693
0.21298933244676554
0.15974199933507416
0.10649466622338277
0.053247333111691386
0.0
3.141592653589793
3.0883453204781017
3.0350979873664103
2.981850654254719
2.9286033211430276
2.875355988031336
2.822108654919645
2.7688613218079534
2.715613988696262
2.6623666555845706
2.6091193224728793
2.5558719893611874
2.5026246562494965
2.4493773231378047
2.3961299900261133
2.342882656914422
2.2896353238027305
2.236387990691039
2.1831406575793477
2.1298933244676563
2.076645991355965
2.0233986582442736
1.9701513251325822
1.9169039920208908
1.8636566589091994
1.810409325797508
1.7571619926858166
1.703914659574125
1.6506673264624336
1.5974199933507423
1.5441726602390509
1.4909253271273595
1.437677994015668
1.3844306609039767
1.3311833277922853
1.277935994680594
1.2246886615689025
1.1714413284572112
1.1181939953455196
1.0649466622338282
1.0116993291221368
0.9584519960104454
0.905204662898754
0.8519573297870626
0.7987099966753712
0.7454626635636799
0.6922153304519885
0.6389679973402971
0.5857206642286057
0.5324733311169143
0.4792259980052229
0.42597866489353153
0.37273133178184015
0.31948399867014876
0.26623666555845693
0.21298933244676554
0.15974199933507416
0.10649466622338277
0.053247333111691386
0.0
thermal_efficiency = 54.08434500405659
Output Graphs:-

The PV graph has been plotted for the Otto Cycle. The desired shape of the graph has been obtained.
The thermal efficiency has been calculated to be 54.084%, from the formula:
Thermal Efficiency ⇒1−(1(CR)γ−1)