PYTHON - Air standard Cycle
Air Standard Otto Cycle Simulator Using Python
AIM:
To solve an otto cycle to find thermal efficiency and make PV plot using python programming language.
PROBLEM STATEMENT:
Otto cycle is a air standard cycle.
Though it is ideal cycle due to few assumptions made, still it is basis for current petrol/gasoline engines.
Using the concept of gas laws and other thermodynamic properties, we have to find the pressure, temperature and volume for all state points, by which we've to find thermal efficiency of the cycle and PV plot with them.
AIR STANDARD OTTO CYCLE ASSUMPTIONS:
- The working fluid is air( considered as ideal gas), which continuously circulates in a closed loop (cycle).
- All the processes in (ideal) power cycles are internally reversible
- Combustion process is modeled by a heat-addition process from an external source.
- The exhaust process is modeled by a heat-rejection process that restores the working fluid (air) at its initial state.
- Constant specific heats
AIR STANDARD OTTO CYCLE PROCESSES:
1-2: Isentropic compression
2-3: Constant volume heat addition
3-4: Isentropic expansion
4-1: Constant pressure heat extraction
credits: wikipedia
FORMULA:
`volume_(displacement)=pi/4xxB^2xxS =From (pixxr^2xxl)`
`CR=(V_s-V_c)/V_c`
`PV=nRT`
`PV^gamma=`constant (for isentropic process)`
`eta_(thermal)=(Output)/(Input)=(T_4-T_1)/(T_3-T_2)=1-(1/(CR))^(gamma-1)`
Where
B-Bore diameter
S-Stroke length
CR-Compression ratio
`V_c`-Clearance volume
`V_s`-Swept volume
R-Universal gas constant
P-Pressure
V-Volume
T-Temperature
CODE WITH EXPLANATION:
- Import modules (math-Mathematical functons like sin, cos etc; matplotlib.pyplot-plots; numpy-linspace)
- Define function for piston kinematics for finding volume (using the formula mentioned above) for different crank angles(inputs:bore, stroke, connecting rod length, compression ratio, starting angle, ending angle; output - volume array).
- Define bore, stroke, connecting rod length, compression ratio, specific heat ratio,
- Calculate swept volume and clearance volume.
- Define p1, t1 with inputs and v1 as summation of swept and clearance volumes.
- Define v2=clearance volume, find p2 using using isentropic process formula, t2 using ideal gas law.
- Define t3 with input, v3=v2(constant volume process), p3 using ideal gas law.
- Define v4=v1(constant volume process), p4 using isentropic process formula, t4 using ideal gas law.
- Call piston_kinematics function for process 1-2 and 3-4 and store it in vcomp and vexp arrays.
- Using isentropic process formula, find pcomp and pexp.
- Find efficiency using formula mention above.
- Plot the graph as shown including axes labels, title, legends.
- Save the plot.
- End of program.
CODE with necessary comments (#) for better explanation for each line
#Air standard Otto cycle simulator
import math
import matplotlib.pyplot as plt
import numpy as np
#Function for finding volume for different crank angles using piston kinematics
def piston_kinematics(bore,stroke,con_len,comp_ratio,s_a,e_a):
a=stroke/2
r=con_len/a
vs=math.pi*(1/4)*pow(bore,2)*stroke
vc=vs/(comp_ratio-1)
v=[]
s_a=math.radians(s_a)
e_a=math.radians(e_a)
theta=np.linspace(s_a,e_a,50)
for i in theta:
term1=0.5*(comp_ratio-1)
term2=r+1-math.cos(i)
term3=(r*r) - pow(math.sin(i),2)
term4=pow(term3,0.5)
v.append((1+term1*(term2-term4))*vc)
return v
#end of function
#inputs
#bore diameter
b=0.1
#stroke length
s=0.1
#connecting rod length
crl=0.15
#compression ratio
cr=12
#specific heats ratio
gamma=1.4
#swept volume
vs=math.pi*(1/4)*pow(b,2)*s
#clearance volume
vc=vs/(cr-1)
"""
PROCESSES IN AIR STANDARD OTTO CYCLE
1-2: Isentropic compression
2-3: Constant volume heat addition
3-4: Isentropic expansion
4-1: Constant pressure heat extraction
"""
#State 1
p1=101325 #input
t1=500 #input
v1=vs+vc
#State 2
v2=vc
p2=p1*pow(v1,gamma)/pow(v2,gamma) #1-2:isentropic process, so p1*v1^gamma=p2*v2^gamma
t2=p2*v2*t1/(p1*v1) #Ideal gas law((p*v)/t=n*R=constant if n=1)
#1-2:Isentropic compression
constant1=p1*pow(v1,gamma)
vcomp=piston_kinematics(b,s,crl,cr,180,0) #calling function for isentropic process values
pcomp=[]
for j in vcomp:
pcomp.append(constant1/pow(j,gamma))
#State 3
t3=2000 #input
v3=v2 #2-3:Constant volume process
p3=p2*v2*t3/(v3*t2) #Ideal gas law((p*v)/t=n*R=constant if n=1)
#State 4
v4=v1 #4-1:Constant volume process
p4=p3*pow(v3,gamma)/pow(v4,gamma) #3-4:isentropic process, so p3*v3^gamma=p4*v4^gamma
t4=p4*v4*t3/(p3*v3) #Ideal gas law((p*v)/t=n*R=constant if n=1)
#3-4:Isentropic expansion
constant2=p3*pow(v3,gamma)
vexp=piston_kinematics(b,s,crl,cr,0,180) #calling function for isentropic process values
pexp=[]
for i in vexp:
pexp.append(constant2/pow(i,gamma))
#Efficiency
eff=100*(1-pow((1/cr),(gamma-1)))
#Display
print('Air Standard Otto Cycle Simulator')
print('\nProcesss:\n1-2: Isentropic compression\n2-3: Constant volume heat addition')
print('3-4: Isentropic expansion\n4-1: Constant pressure heat extraction')
print('\nState1:\nP1= %.2f pa \nT1= %.2f deg C \nV1 = %f cubic m'%(p1,t1,v1))
print('\nState2:\nP2= %.2f pa \nT2= %.2f deg C \nV2 = %f cubic m'%(p2,t2,v2))
print('\nState3:\nP3= %.2f pa \nT3= %.2f deg C \nV3 = %f cubic m'%(p3,t3,v3))
print('\nState4:\nP4= %.2f pa \nT4= %.2f deg C \nV4 = %f cubic m'%(p4,t4,v4))
print('\nEfficiency of this otto cycle:%.2f percentage'%eff)
#plotting begins
plt.plot(vcomp,pcomp)
plt.plot(vexp,pexp)
plt.plot([v2,v3],[p2,p3])
plt.plot([v4,v1],[p4,p1])
#Labelling axes
plt.ylabel('Pressure in N/m^2')
plt.xlabel('Volume in cubic m')
#Title for plot
plt.title('Otto Cycle PV Diagram')
#Legend for plot
plt.legend(['1-2: Isentropic compression','2-3: Constant volume heat addition','3-4: Isentropic expansion','4-1: Constant pressure heat extraction'])
#Saving figure
plt.savefig('PV diagram')
#Display plot
plt.show()
RESULT:
OUTPUT:
PV Diagram:
CONCLUSION:
From the output, the efficiency is ~63% i.e., Around times of input is converted to useful output.
It is also clear that by increasing compression ratio, The efficiency of the cycle increases.
Peak pressure arise at the end of constant volume heat addition process (state point 3).
Change in pressure(pressure drop)in constant volume heat extraction is less compared to change in pressure(increasing pressure) during constant volume heat addition.