Challenge

Week 2 Air standard Cycle

AIM:

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

  1. Your code should create a PV diagram
  2. You should output the thermal efficiency of the engine.

OBJECTIVE:

  1. To solve and find out different state variables in the Otto cycle and plot its p-V diagram.
  2. To calculate the thermal efficiency of the given Otto cycle.

THEORY: The Otto cycle is the ideal cycle for spark-ignition reciprocating engines. In most spark-ignition engines, the piston executes four complete strokes (two mechanical cycles) within the cylinder, and the crankshaft completes two revolutions for each thermodynamic cycle. These engines are called four-stroke internal combustion engines.

Initially, both the intake and the exhaust valves are closed, and the piston is at its lowest position (BDC). During the compression stroke, the piston moves upward, compressing the air-fuel mixture. Shortly before the piston reaches its highest position (TDC), the spark plug fires and the mixture
ignites, increasing the pressure and temperature of the system. The high-pressure gases force the piston down, which in turn forces the crankshaft to rotate, producing a useful work output during the expansion or power stroke. At the end of this stroke, the piston is at its lowest position (the completion
of the first mechanical cycle), and the cylinder is filled with combustion products. Now the piston moves upward one more time, purging the exhaust gases through the exhaust valve (the exhaust stroke), and down a second time, drawing in the fresh air-fuel mixture through the intake valve (the intake
stroke). Notice that the pressure in the cylinder is slightly above the atmospheric value during the exhaust stroke and slightly below during the intake stroke.

The four processes in an Otto cycle are:

  1. Isentropic compression process or Reversible adiabatic compression of air (Process 1-2),
  2. Constant volume heat addition process (Process 2-3),
  3. Isentropic expansion process or Reversible adiabatic expansion of air (Process 3-4),
  4. Constant volume heat rejection process (Process 4-1).

GOVERNING EQUATIONS :

Various equations of Otto cycle are involved in this project. These are :

  • Compression ratio (rcrc) , rc=(V1V2)rc=(V1V2) or 1+VsVc1+VsVc,
  • Swept volume (VsVs) = π4⋅d2⋅lπ4⋅d2⋅l, where d is bore diameter and l is stroke length,
  • VVcVVc = 1 + 12(rc−1) [R+1−cosθ−(R2−sin2θ)12]12(rc-1) [R+1-cosθ-(R2-sin2θ)12],

where R = length of connecting rod/crank radius,

  • Adiabatic process equation = p⋅vγp⋅vγ = constant,
  • Ideal Gas equation = p⋅v=m⋅R⋅Tp⋅v=m⋅R⋅T,
  • Thermal efficiency of Otto cycle(ηη)= 1−1rγ−1c1-1rcγ-1,
  • From the figure, v1v1 = vs+vcvs+vc, v2=vcv2=vc.

NOTE: -

  • pp = pressure,
  • vv = volume of engine cylinder,
  • TT = temperature,
  • vcvc = clearance volume, (Clearance volume is a volume between the cylinder head and the piston top when the piston is at top dead centre (TDC).),
  • vsvs = swept volume, (Swept volume is the displacement of one cylinder. It is the volume between top dead centre (TDC) and bottom dead centre (BDC).),
  • γγ= specific heat,
  • dd = bore diameter (diameter of each cylinder)
  • ll= stroke length (The stroke length is how far the piston travels in the cylinder, which is determined by the cranks on the crankshaft.)
  • ηη= thermal efficiency,

EXPLANATION OF PYTHON CODES:

  1. Since the Otto cycle is an air-standard cycle, the specific heat (γγ) of air is taken as 1.4.
  2. Initial conditions, such as temperature (T1) and pressure (p1p1) of the surrounding is assumed to be 350K and 101.325 kPa respectively.
  3. The geometrical design of the engine cylinder which consists of bore diameter, stroke length, and length of connecting rod is also known and accordingly vsvs and vcvc are calculated.
  4. The maximum temperature (T3) occurring inside the cylinder is also known.
  5. Other state variables are calculated using Adiabatic processes equations and ideal gas equations.
  6. Similarly, the thermal efficiency is also calculated accordingly using the formula given.
  7. For plotting the calculated state variables on a p-v diagram with just using 'plt. plot' the command will yield into the incorrect p-v diagrammed, compression and expansion stroke is represented by a straight line.
  8. So to rectify this, a different function is created for storing the different values of crank angle rotation as compression and expansion occur in different strokes or cycles. This function is then called to the main program and accordingly, the plot is drawn from various points obtained.
  9. For this number of values for which the program will iterate is 100, and accordingly, the V array is set as null and after every iteration using for loop, a new value will be stored as an array using 'append' command and will be returned back after receiving desired values.

"""

program otto cycle

by prasad

"""

import math

import matplotlib.pyplot as plt

import numpy as np

def engine_kinematics(bore,stroke,con_rod,cr,start_crank,end_crank):

"""

engine_kinematics

"""

#geometric parameters

#crank pin radius

a=stroke/2

R=con_rod/a

#volume comutation

v_s=(math.pi/4)*pow(bore,2)*stroke

v_c=v_s/(cr-1)

sc=math.radians(start_crank)

ec=math.radians(end_crank)

num_value=50

dtheta=(ec-sc)/(num_value-1)

V=[]

for i in range(0,num_value):

theta=sc+i*dtheta

term1=0.5*(cr-1)

term2=R+1-math.cos(theta)

term3=pow(R,2)-pow(math.sin(theta),2)

term3=pow(term3,0.5)

V.append((1 + term1 * (term2-term3))*v_c)

return V

#inputs

p1=101325

t1=500

gamma=1.4

t3=2300

bore=0.25

stroke=0.1

con_rod=0.15

cr=10

#volume comutation

v_s=(math.pi/4)*pow(bore,2)*stroke

v_c=v_s/(cr-1)

v1=v_s+v_c

#state point 2

v2=v_c

#p1v1^gamma=p2v2^gamma

p2=p1*pow(v1,gamma)/pow(v2,gamma)

#p2v2/t2=p1v1/t1 | rhs=p1v1/t1 | p2v2/t2=rhs |

rhs=p1*v1/t1

t2=p2*v2/rhs

V_compression=engine_kinematics(bore,stroke,con_rod,cr,180,0)

constant=p1*pow(v1,gamma)

P_compression=[]

for v in V_compression:

P_compression.append(constant/pow(v,gamma))

# state point 3

v3=v2

#p3v3/t3=p2v2/t2 | rhs=p2v2/t2 | p3v3/t3=rhs |

rhs=p2*v2/t2

p3=rhs*t3/v3

V_expansion=engine_kinematics(bore,stroke,con_rod,cr,0,180)

constant=p3*pow(v3,gamma)

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,gamma)/pow(v4,gamma)

#p4v4/t4=p3v3/t3 | rhs=p3v3/t3 | p4v4/t4=rhs |

rhs=p3*v3/t3

t4=p4*v4/rhs

plt.figure(1)

plt.plot(V_compression,P_compression)

plt.plot([v2,v3],[p2,p3])

plt.plot(V_expansion,P_expansion)

plt.plot([v4,v1],[p4,p1])

plt.xlabel('volume')

plt.ylabel('pressure')

plt.legend()

plt.savefig('otto cycle')

plt.show()

#thermal efficiency

eff=1-(1/pow(cr,(gamma-1)))

thermal_efficiency=eff*100

print('thermal_efficiency= ',thermal_efficiency)

"""
program otto cycle
by prasad
"""


import math
import matplotlib.pyplot as plt
import numpy as np

def engine_kinematics(bore,stroke,con_rod,cr,start_crank,end_crank):
	"""
	engine_kinematics
	"""

	#geometric parameters
	#crank pin radius
	a=stroke/2
	R=con_rod/a

	#volume comutation
	v_s=(math.pi/4)*pow(bore,2)*stroke
	v_c=v_s/(cr-1)

	sc=math.radians(start_crank)
	ec=math.radians(end_crank)

	num_value=50

	dtheta=(ec-sc)/(num_value-1)

	V=[]

	for i in range(0,num_value):
		theta=sc+i*dtheta
		term1=0.5*(cr-1)
		term2=R+1-math.cos(theta)
		term3=pow(R,2)-pow(math.sin(theta),2)
		term3=pow(term3,0.5)

		V.append((1 + term1 * (term2-term3))*v_c)
	return V

#inputs
p1=101325
t1=500
gamma=1.4
t3=2300

bore=0.25
stroke=0.1
con_rod=0.15
cr=10


#volume comutation
v_s=(math.pi/4)*pow(bore,2)*stroke
v_c=v_s/(cr-1)
v1=v_s+v_c

#state point 2
v2=v_c

#p1v1^gamma=p2v2^gamma
p2=p1*pow(v1,gamma)/pow(v2,gamma)

#p2v2/t2=p1v1/t1 |  rhs=p1v1/t1 | p2v2/t2=rhs |

rhs=p1*v1/t1

t2=p2*v2/rhs

V_compression=engine_kinematics(bore,stroke,con_rod,cr,180,0)

constant=p1*pow(v1,gamma)

P_compression=[]

for v in V_compression:
	P_compression.append(constant/pow(v,gamma))

# state point 3

v3=v2

#p3v3/t3=p2v2/t2 | rhs=p2v2/t2 | p3v3/t3=rhs |

rhs=p2*v2/t2

p3=rhs*t3/v3

V_expansion=engine_kinematics(bore,stroke,con_rod,cr,0,180)

constant=p3*pow(v3,gamma)

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,gamma)/pow(v4,gamma)

#p4v4/t4=p3v3/t3 | rhs=p3v3/t3  | p4v4/t4=rhs |

rhs=p3*v3/t3 

t4=p4*v4/rhs


plt.figure(1)
plt.plot(V_compression,P_compression)
plt.plot([v2,v3],[p2,p3])
plt.plot(V_expansion,P_expansion)
plt.plot([v4,v1],[p4,p1])
plt.xlabel('volume')
plt.ylabel('pressure')
plt.legend()
plt.savefig('otto cycle')
plt.show()


#thermal efficiency

eff=1-(1/pow(cr,(gamma-1)))
thermal_efficiency=eff*100
print('thermal_efficiency= ',thermal_efficiency)
Your portfolio, next

Ship work like this
in your own course.

Talk to a career counsellor

Free 20-minute call. We'll map the right course to where you want to work.

By submitting you agree to our Terms and Privacy Policy.