Week 2 Air standard Cycle
"""
otto cycle
Created on Thu May 12 14:09:25 2022
@author: veer samani
"""
import math
import matplotlib.pyplot as plt
"""
function for engine kinematics
"""
def enginekinematics(bore,stroke,con_rod_length,cr,start_angle,end_angle):
#crank pin radius m
a = stroke/2
R = con_rod_length/a
#swept volume and clearance volume
v_s = math.pi*(1/4)*pow(bore,2)*stroke
v_c = v_s/(cr-1)
sca = math.radians(start_angle)
eca = math.radians(end_angle)
theta = []
#the number of angles
num_angles = 100
dtheta = (eca-sca)/(num_angles-1)
v = []
for i in range(0,num_angles):
theta = sca+(i*dtheta)
#to solve the equation of V/V_c we divide 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
"""assigning pre compression variables
pressure in Pa and temp in K"""
p1 = 101325
t1 = 310
gamma = 1.4
t3 = 1810
"""dimensions and compression ratio of the engine in m"""
bore = 0.0875
stroke = 0.101
con_rod_length = 0.151
cr = 9.4
#Volume computations
v_s = (math.pi/4)*pow(bore,2)*stroke
v_c = v_s/(cr-1)
#state point 1
v1 = v_c + v_s
constant1 = p1*pow(v1,gamma)
#state point 2 ie after isentropic compression
v2 = v_c
# p1*v1^gamma = p2*v2^gamma
p2 = constant1/pow(v2,gamma)
#by ideal gas law
t2 = p2*v2*t1/(p1*v1)
#calling the above written function to plot the PV diagram for isentropic compression
V_compress = enginekinematics(bore,stroke,con_rod_length,cr,180,0)
P_compress = []
for VC in V_compress:
P_compress.append(constant1/pow(VC,gamma))
#state point 3 after constant volume heat addition
v3 = v2
#by ideal gas law
p3 = p2*v2*t3/(t2*v3)
constant2 = p3*pow(v3,gamma)
#state point 4 after isentropic expansion
v4=v1
#p3*v3^gamma=p4*v4^gamma
p4 = constant2/pow(v4,gamma)
#by gas law
t4=p4*v4*t3/(p3*v3)
#calling function to form P and V arrays of isentropic expansion
V_expand = enginekinematics(bore,stroke,con_rod_length,cr,0,180)
P_expand = []
for VE in V_expand:
P_expand.append(constant2/pow(VE,gamma))
#calculating and printing thermal efficiency of an otto engine (thermal efficiency = 1-(1/cr^(gamma-1)))
therm_eff = 1-(1/pow(cr,(gamma-1)))
print('Thermal efficiency of this engine is', therm_eff)
plt.plot(V_compress,P_compress,label = "Isentropic compression")
plt.plot([v2,v3],[p2,p3],label = "Constant Volume Heat Addition")
plt.plot(V_expand,P_expand, label = "Isentropic expansion")
plt.plot([v4,v1],[p4,p1], label = "Constant Volume Heat Reduction")
plt.legend(loc="upper right")
plt.xlabel("Volume (m^3)")
plt.ylabel("Pressure (N/m^2)")
plt.show()
Report:
Objective:
To simulate otto cycle, plot PV diagram and find thermal efficieny
Problem Statement:
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.
Solution Procedure:
The solution of this problem was derived by creating a program and following the given steps below:
- Function was written for the following formula:
where V is the current volume,
Vc is the clearance volume
rc is the compression ratio
This function was written to give the values of volume between the assigned angle of the process
- The engine parameters and dimensions are given where the initial and max temp are given and initial pressure is given.
- Program is written to find pressure, volume and temperature at end of each process and some lines of code are also written to fine the values of the isentropic(constant entropy) processes so that the correct curved plot can be made
- The efficiency of the engine is gotten through the given formula in the code.
- The graph is plotted and the progress of the processes can be seen through the values.
Result:
A plot is given to show the hypothetical otto cycle and the value of thermal efficiency is given.
Discussion:
This code successfully simulates a hypothetical otto cycle and can be used to find out the efficiency of an engine with any dimensions and parameters. It also returns a good plot of the thermodynamic processes seen in the cycle