Week 2 Air standard Cycle
Project Aim: Solve otto cycle and make plot of it.
Objective: 1. solve otto cycle
2. plot the otto cycle
What is ottto cycle?
An Otto cycle is an idealized thermodynamic cycle that describes the functioning of a typical spark ignition piston engine. It is the thermodynamic cycle most commonly found in automobile engines.
The Otto cycle is a description of what happens to a mass of gas as it is subjected to changes of pressure, temperature, volume, the addition of heat, and removal of heat. The mass of gas that is subjected to those changes is called the system. The system, in this case, is defined to be the fluid (gas) within the cylinder. By describing the changes that take place within the system, it will also describe in the inverse, the system's effect on the environment. In the case of the Otto cycle, the effect will be to produce enough net work from the system so as to propel an automobile and its occupants in the environment.
Fig 1 Otto cycle
Code
"""
Programme for generating otto cycle
By Rahul Date
"""
from math import *
from numpy import *
from matplotlib.pyplot import *
def engine_kinematics(bore,stroke,con_rod,cr,start_crank,end_crank):
a = stroke/2
r = con_rod/a
v_s = (pi/4)*pow(bore,2)*stroke
v_c = v_s/(cr-1)
sc = radians(start_crank)
ec = radians(end_crank)
n= 100
dtheta = (ec-sc)/(n-1)
v =[]
for i in range(0,n):
theta = sc+i*dtheta
term1 = 0.5*(cr-1)
term2 = r+1-cos(theta)
term3 = pow(pow(r,2)-pow(sin(theta),2),0.5)
v.append((1+term1*(term2-term3))*v_c)
return v
# initial condition
p1 = 101325
t1 = 500
t3 = 2300
# Geometric parameters
bore = 0.1
stroke = 0.1
con_rod = 0.15
cr = 5
gamma = 1.4
# Sewpt and clearence volume
v_s = (pi/4)*pow(bore,2)*stroke
v_c = v_s/(cr-1)
v1 = v_s+v_c
# State 2
v2 = v_c
p2 = p1*pow(v1,gamma)/pow(v2,gamma)
rhs = (p1*v1)/t1
t2 = (p2*v2)/rhs
v_com =engine_kinematics(bore,stroke,con_rod,cr,180,0)
constant = p1*pow(v1,gamma)
p_com = []
for v in v_com:
p_com.append(constant/pow(v,gamma))
# State 3
v3 = v2
rhs = (p2*v2)/t2
p3 = (rhs*t3)/v3
v_exp =engine_kinematics(bore,stroke,con_rod,cr,0,180)
constant = p3*pow(v3,gamma)
p_exp = []
for v in v_exp:
p_exp.append(constant/pow(v,gamma))
# State 4
v4 = v1
p4 = p3*pow(v3,gamma)/pow(v4,gamma)
rhs = (p3*v3)/t3
t4 = (p4*v4)/rhs
# Efficiency of otto cycle
eff = 1-(1/(pow(cr,(gamma-1))))
print(eff)
plot([v2,v3,],[p2,p3])
plot(v_com,p_com)
plot(v_exp,p_exp)
plot([v4,v1,],[p4,p1])
xlabel('Volume')
ylabel('Pressure')
title('Otto cycle')
show()
Code description
from math import * ............................................................................. import math library
from numpy import * ........................................................................... import numpy library
from matplotlib.pyplot import * ............................................................ import matplotlib library
def engine_kinematics(bore,stroke,con_rod,cr,start_crank,end_crank): ....... engine kinematics function
# initial condition
p1 = 101325 ....................................................................................... pressure at starting of the compression
t1 = 500 ............................................................................................. temperature at starting of the compression
t3 = 2300 ........................................................................................... temperature at starting of the expansion
# Geometric parameters
bore = 0.1 .......................................................................................... cylinder bore diameter
stroke = 0.1 ........................................................................................ cylinder height
con_rod = 0.15 .....................................................................................connecting rod length
cr = 5 ..................................................................................................compression ratio
gamma = 1.4 ........................................................................................gamma constant
# Sewpt and clearence volume
v_s = (pi/4)*pow(bore,2)*stroke .............................................................Sewpt volume
v_c = v_s/(cr-1) ....................................................................................clearence volume
v1 = v_s+v_c ...................................................................................... volume at starting of the compression
# State 2
v2 = v_c .............................................................................................. volume at end of the compression
p2 = p1*pow(v1,gamma)/pow(v2,gamma) .............................................. pressure at end of the compression
rhs = (p1*v1)/t1
t2 = (p2*v2)/rhs .................................................................................. temperature at end of the compression
v_com =engine_kinematics(bore,stroke,con_rod,cr,180,0) ......................... volume during the compression
constant = p1*pow(v1,gamma)
p_com = [] .......................................................................................... pressure empty array during the compression
for v in v_com:
p_com.append(constant/pow(v,gamma)) ................................................. pressure during the compression
# State 3
v3 = v2 ............................................................................................... volume at the start of the expansion
rhs = (p2*v2)/t2
p3 = (rhs*t3)/v3 .................................................................................. pressure at the start of the expansion
v_exp =engine_kinematics(bore,stroke,con_rod,cr,0,180) ........................ volume during the expansion
constant = p3*pow(v3,gamma)
p_exp = [] ......................................................................................... pressure empty array during the expansion
for v in v_exp:
p_exp.append(constant/pow(v,gamma)) ................................................ pressure during the expanstion
# State 4
v4 = v1 .............................................................................................. volume at the end of expansion
p4 = p3*pow(v3,gamma)/pow(v4,gamma) ............................................. pressure at the end of expansion
rhs = (p3*v3)/t3
t4 = (p4*v4)/rhs ................................................................................. temperature at the end of expansion
# Efficiency of otto cycle
eff = 1-(1/(pow(cr,(gamma-1)))) ........................................................... The efficiency of otto cycle
print(eff)
plot([v2,v3,],[p2,p3])
plot(v_com,p_com)
plot(v_exp,p_exp)
plot([v4,v1,],[p4,p1])
xlabel('Volume')
ylabel('Pressure')
title('Otto cycle')
show()
engine kinematic function code
def engine_kinematics(bore,stroke,con_rod,cr,start_crank,end_crank):
a = stroke/2
r = con_rod/a
v_s = (pi/4)*pow(bore,2)*stroke
v_c = v_s/(cr-1)
sc = radians(start_crank)
ec = radians(end_crank)
n= 100
dtheta = (ec-sc)/(n-1)
v =[]
for i in range(0,n):
theta = sc+i*dtheta
term1 = 0.5*(cr-1)
term2 = r+1-cos(theta)
term3 = pow(pow(r,2)-pow(sin(theta),2),0.5)
v.append((1+term1*(term2-term3))*v_c)
return v
Function code description
def engine_kinematics(bore,stroke,con_rod,cr,start_crank,end_crank): ........................ engine kinekatics function
a = stroke/2 ......................................................................................................... crank pin
r = con_rod/a ....................................................................................................... variable
v_s = (pi/4)*pow(bore,2)*stroke ............................................................................. swept volume
v_c = v_s/(cr-1) .................................................................................................... clearance volume
sc = radians(start_crank) ........................................................................................ start crank angle
ec = radians(end_crank) .......................................................................................... end crank angle
n= 100 .................................................................................................................. Steps
dtheta = (ec-sc)/(n-1) ............................................................................................. delta theta
v =[] ...................................................................................................................... empty array for volume
for i in range(0,n): .................................................................................................... for loop to calculate the volume value during
theta = sc+i*dtheta .................................................................................................. theta calculation
term1 = 0.5*(cr-1) ................................................................................................... First term of volume calculation
term2 = r+1-cos(theta) ............................................................................................. Second term of volume calculation
term3 = pow(pow(r,2)-pow(sin(theta),2),0.5) ............................................................... Third term of volume calculation
v.append((1+term1*(term2-term3))*v_c) .................................................................... volume array during the compression and expansion process
return v .................................................................................................................... return the value of volume
Output
PV plot
The efficiency of the otto cycle