Week 2 Air standard Cycle
Aim:
To create a program for plotting the PV diagram of otto cycle using python and also print thermal efficiency.
Procedure:
The inputs are taken for gamma, t3, p1, t1 and engine geometrics. For volume calculation using the swept volume formula founded and
v_s = (math.pi*1/4)*pow(bore,2)*stroke
v_c = v_s/(Cr-1)
v1 = v_c + v_s
then v2 is equal to v_c so same value is stored into it. P2 is calculated using p1*pow(Cr,gamma) formula.
t2 = (p2*v2*t1)/(p1*v1)
constant = p1 * pow (v1,gamma)
we need to calculate the engine kinematics for each angle for that one function is created because we need to calculate n number times to plot actual kinematics plot 180 to 0 degree otherwise we get linear interpolation line
And P_compression is calculated using constant/pow(v,gamma) formula
v3 = v2
p_compression is calculated for each point of v_ compression so it run under the for loop here.
Pow is used for power method. Here the function is created for engine kinematics the values are given inside the bracket as per the order of suitable name and values. Geometric parameters volume parameters are calculated inside the function. math.radians is used because when we use sin theta or cos theta everything is calculated in degree so we converting into the radians.
Num values are assumed 50 for number of iteration the for loop need to run. Here the volume value at each point is calculated and append is used to create the array every time loop runs as been stored and formed as array
During the compression and expansion of cylinder the function is called and run and the array value is used for calculation and used for plotting using the thermal efficiency formula.
Thermal efficiency=(1-((t4-t1)/(t3-t2)))*100
Thermal efficiency is calculated as per the above formula and using the library ‘math’ math operation are done and matplotlib.pyplot library using it plots are created.
plt.plot([v2,v3],[p2,p3])
plt.plot(v_compression,p_compression)
import math
import matplotlib.pyplot as plt
def engine_kinematics (bore,stroke,con_rod,Cr,start_crank,end_crank):
'''
Engine Kinematics
'''
# Geametric Parameters
a = stroke/2
R = con_rod/a
# Volume Parameters
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((pow(math.sin(theta),2)),0.5)
term3 = pow(term3,0.5)
v.append((1+term1*(term2-term3))*v_c)
return (v)
# input Variables
gamma = 1.4
t3 = 2300
p1 = 101325
t1 = 500
bore = 0.1
stroke = 0.1
con_rod = 0.15
Cr = 10
#volume computation
v_s = (math.pi*1/4)*pow(bore,2)*stroke
v_c = v_s/(Cr-1)
v1 = v_c + v_s
#state point 2
v2 = v_c
#p2v2^gamma =p1v1^gamma
p2 = p1*pow(Cr,gamma)
#p2t2/t2 = p1v1/t1 | rhs =p1v1/t1 | p2v2/t1 | p2v2/t2 = rhs | t2 =p2v2/rhs
#rhs = p1*v1/t1
t2 = (p2*v2*t1)/(p1*v1)
constant = p1 * pow (v1,gamma)
v_compression = engine_kinematics(bore, stroke, con_rod, Cr, 180, 0)
p_compression = []
for v in v_compression:
p_compression.append(constant/pow(v,gamma))
#state point 3
v3=v2
# p3 v3 /t3 = p2v2/t2 | rhs = p2v2/t2 | p3 =rhs*t3/v3
p3 = p2*t3/t2
constant = p3*pow(v3,gamma)
v_expansion = engine_kinematics(bore, stroke, con_rod, Cr, 0, 180)
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/v4),gamma)
#p4 v4/t4 = rhs
t4 = p4*v4*t3/(p3*v3)
thermal_efficiency=(1-((t4-t1)/(t3-t2)))*100
print(thermal_efficiency)
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.plot(v_expansion,p_expansion)
plt.plot([v4,v1],[p4,p1])
plt.show()
Result:
As per the otto cycle pv diagram is constructed using the python and attached the output plot and working program with this report.