Week 2 Air standard Cycle
Question:
Based on the concepts you have learnt during the forward kinematics routine, go ahead and write code that can solve an Otto cycle and make plots for it.
Here are the requirements
- Your code should create a PV diagram
- You should output the thermal efficiency of the engine.
Objective: To write a python program to plot a ‘p-v diagram’ for an Otto-cycle for given geometric and volumetric parameters at a particular compression ratio and calculate the thermal efficiency of the system as well.
Solution:
Otto-cycle is the basis on which a gasoline I.C. engine works. For the calculation of state variable p, v and t namely pressure, volume and temperature the geometric and volumetric parameters such as swept volume, bore and stroke lengths etc are used. For all the 4 processes: 1. Isentropic compression, 2. Constant volume heat addition, 3. Isentropic expansion and 4.Constant volume heat rejection, the co-ordinates for ‘p’ and ‘v’ are calculated and the plot is computed. Thermal efficiency of the system is calculated as the ratio of net heat of the system with heat added to the system, which can be calculated using the temperature figures at the 4 states.
Python code:
# Plotting a 'p-v' diagram of an otto-cycle for given parameters
import math
import matplotlib.pyplot as plt
def engine_kinemetics_function_for_volume_trace(bore,stroke,cr,con_rod,theta0,thetax,theta_n):
# a = crank pin radius
a = stroke/2
# R a mathematical constant
R = con_rod/a
# Volumetric parameters
v_s = (math.pi)/4 * pow(bore,2) * stroke
v_c = v_s / (cr-1) # as cr = (v_s + v_c)/v_c
# Using the crank angle-cylinder volume relation, v/v_c = 1+ 0.5(cr - 1)[R + 1 - cos(theta)-(R^2 - sin^2(theta))^0.5]
# theta being the angle of rotation of the crank can be defined
#theta_n = 10
theta = []
#theta0 = 0
#thetax = 180
v = []
for i in range (0,theta_n):
temp = theta0 + i*(thetax-theta0)/(theta_n - 1)
theta.append(math.radians(temp))
# print(theta)
for th1 in theta:
t1 = 0.5 * (cr - 1)
t2 = R + 1 - math.cos(th1)
t3 = pow(((pow(R, 2)) - pow(math.sin(th1), 2)), 0.5)
v_trace = v_c * (1 + (t1*(t2 - t3)))
v.append(v_trace)
return(v)
# Geometric parameters of the engine
bore = 0.1
stroke = 0.1
cr = 8
con_rod = 0.15
gamma = 1.4
t3 = 2000 #tmax
# state 1 parameters at atmospheric conditions
p1 = 101325.6
t1 = 400
# Volumetric parameters
v_s = (math.pi)/4 * pow(bore,2) * stroke
v_c = v_s / (cr-1) # as cr = (v_s + v_c)/v_c
v1 = v_c + v_s
#print(v_c)
#print(v_s)
#print(v1)
# state 2 parameters after isentropic compression
v2 = v_c
# p2*pow(v2, gamma) = p1*pow(v1, gamma), let rhs = p1*pow(v1, gamma)
rhs = p1*pow(v1, gamma)
#print(rhs)
p2 = rhs / pow(v2,gamma)
#print(p2)
#p1*v1/t1 = p2*v2/t2, t2 = p2*v2*t1/p1*v1
t2 = (p2*v2*t1)/(p1*v1)
#print(t2)
pcompression = []
vcompression = engine_kinemetics_function_for_volume_trace(0.1,0.1,8,0.15,180,0,20)
#print(vcompression)
for v2c in vcompression:
p2c = rhs / pow(v2c,gamma)
pcompression.append(p2c)
#print(pcompression)
# state 3 parameters after constant volume heat addition
v3 = v2
# p3*v3/t3 = p2*v2/t2, p3 = p2*t3/t2
p3 = (p2*t3)/t2
#print(p3)
# t3 is given as the maximum temperature of the system
pexpansion = []
vexpansion = engine_kinemetics_function_for_volume_trace(0.1,0.1,8,0.15,0,180,20)
#print(vexpansion)
for v3e in vexpansion:
rhse = p3*pow(v3,gamma)
p3e = rhse / pow(v3e,gamma)
pexpansion.append(p3e)
#print(pexpansion)
# state 4 parameters after isentropic expansion
v4 = v1 # as 4-1 is constant volume heat rejection process
# p4*pow(v4,gamma) = p3*pow(v3,gamma), rhs = p3*pow(v3,gamma)
p4 = p3*pow(v3,gamma)/pow(v4,gamma)
#print(p4)
'''
rhs = p3*v3/t3 = p2*v2/t2 = p1*v1/t1 = p4*v4/t4
print(p1*v1/t1)
print(p2*v2/t2)
print(p3*v3/t3)
'''
t4 = (t3*p4*v4)/(p3*v3)
# print(t4)
#thermal efficiency of thecycle is the net heat of the system divided by the heat added to the system - n_thermal = ((t3-t2)+(t1-t4))/(t3-t2)
n_thermal = 1-(((t3-t2)-(t4-t1))/(t3-t2))
print(n_thermal)
print(pow(v_c/v_s,(gamma-1)))
#plt.plot([v1,v2,v3,v4,v1],[p1,p2,p3,p4,p1],'b')
plt.plot([v2,v3],[p2,p3],'r')
plt.plot([v4,v1],[p4,p1],'r')
plt.plot(vcompression,pcompression,'r')
plt.plot(vexpansion,pexpansion,'r')
plt.title('p-v diagram for otto cycle using volume tracing at cr = 8')
plt.xlabel('Volume')
plt.ylabel('Pressure')
plt.grid()
plt.show()
Procedure:
1. Using the formulas for volume the clearance and swept volume are calculated from bore and stroke. Using a formula for relation between instantaneous cylinder volume per clearance volume ratio and crank rotation angle, the trace for cylinder volume was calculated for the compression and expansion processes, namely process 1-2 and 3-4.
2. A function ‘engine_kinemetics_function_for_volume_trace’ is defined initially which uses the mentioned relation for a crank rotation of 180֯ as an array to calculate the instantaneous cylinder volume for a given setup in user defined iterations/steps. The starting crank angle – Θ0 and final crank angle Θx are also to be input by user when the function is called. Using the ‘return’ command the value ‘v’ from the function can be stored in any given variable.
3. Now, using the relations p1v1/t1 = p2v2/t2 for a closed system with ideal gas conditions, and p1v1gamma = p2v2gamma for isentropic condition, the variables p,v and t are calculated for each of the states. The heat addition and rejection is assumed to be a constant volume process hence, v1 = v4 and v2=v3.
4. Finally, the pressure traces w.r.t. the calculated volume traces for compression and expansion processes are calculated using for loop and above mentioned isentropic relation and are stored as an array.
5. Thermal efficiency of the system is calculated as the ratio of net heat of the system with heat added to the system – [1- ((t3-t2)+(t1-t4)) / (t3-t2)], which is calculated using the temperature figures at the 4 states and comes out to be around 44%.
6. To get the ‘p-v’ diagram plot, the ‘v’-volume figures and ‘p’-pressure figures at each of the 4 state are plotted using the ‘matplotlib’ module by importing it at the start of the program and later calling it as ‘plt’. This gives out the straight line plot which suggests the compression and expansion is linear which is incorrect. As calculated using the crank angle and cylinder volume relation, the processes are exponential. To visualise that, only the heat addition and rejection processes – v2 – v3 and v4-v1 are plotted using the respective state co-ordinates. For the compression and expansion processes, the ‘p’ and ‘v’ arrays are plotted giving a more accurate plot.
Plots:
1. Using state variables:
2. Using volume traces:
3. A combined plot:
Conclusion:
1. Using this program as a template, for various combinations of geometric parameters - stroke and bore, connecting rod length, crank pin radius etc. and volumetric parameters - clearance volume, swept volume etc. , a output showing 'p-v' and with adding entropy calculations, a 't-s' diagram and thermal efficiancy can be acquired which could save time and effort of the designers. The same program with some changes can be used for diesel cycle and other similar cyclic processes for ease of calculations.
2. It can also be used to observe changes in efficiency or peak figures for temperature and pressure of alterations in say compression ratio, stroke length, bore etc. which could help in optimizing for specified targets.