Challenge

Week 2 Air standard Cycle

Aim: To write python code that can solve an otto cycle and make plots for it.

Objective:

  1. Create a PV diagram for Otto cycle
  2. Print output as thermal efficiency of the engine.

Theory:

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 follows 4 strokes.

the intake stroke is performed by an isobaric expansion, followed by an adiabatic compression stroke. Through the combustion of fuel, heat is added in a constant volume (isochoric process) process, followed by an adiabatic expansion process power stroke. The cycle is closed by the exhaust stroke, characterized by isochoric cooling and isentropic compression processes.

Steps in code:

  • Code is written in Python using spyder notebook
  • Above code is written for Otto cycle. Fist section of code shows Engine parameters required to calculate the thermal efficiency and P-V diagram of otto cycle.
  • Engine specification parameters are such as: stroke length, bore diameter, crank angle, crank radius, crank length are explained in programmed with formulae.
  • The function Engine_kinematics written to take values of Engine specification parameters and to used calculate compression volume and expansion volume.
  • Starting and ending crank values given to programme.
  • Values of state swept volume ,clearance volume calculated ,formulas are define in programme.
  • State variables for 4 strokes of Otto cycle are calculated
  • Otto cycle has four stokes-

1.Constant volume heat addition

2.Compression

3.Combustion

4.Expansion

constants are gamma=cp/cv of fuel,

  • Thermal Efficiency of otto cycle calculated as:

Thermal_efficiency= 1-((t4-t1)/(t3-t2))

the intial temp. t1 and p1 and t3 are given on that basis other states parameters calculated as:

t2=(p2*v2*t1)/(p1*v1);

p3=p2*(t3/t2);

v3=v2;

v4=v1

t4=(p4*v4*t3)/(p3*v3)

  • Then plot P-V diagram generated.
"""
Engine Kinematics
Otto cycle
"""

import math
import matplotlib.pyplot as plt
'''
### Geometric parameters for Engine
### bore diameter , d (m)
### stroke length, l (m)
### Connecting rod length ,c_l , (m)
### Compression ratio, rc
## crank radius, a (m)
## crank pin radius, a=stroke length/2
 R= Connecting rod length / crank radius
'''
d=0.1
l=0.1
c_l=0.15
rc=8
a=l/2;
R= c_l/ a
def engine_kinematics(d,l,c_l,rc,start_crank,end_crank):
    num_values=10         
    sc=math.radians(start_crank)    ## starting crank angle 
    ec=math.radians(end_crank)
    dtheta= (ec-sc)/(num_values-1)  ## crank angle varies in this range
    
    v=[]                ##  array to store compression volume
    for i in range(0,num_values):
        theta=sc+i*dtheta
        term_1= 0.5*(rc-1)
        term_2= R+1-math.cos(theta)
        term_3=pow(R,2)- pow(math.sin(theta),2)
        term_3=pow(term_3,0.5)
        
        v.append((1+term_1*(term_2-term_3))*v_c)
    return v
    print(v)
'''
Calculation of state variables at 4 states
'''
p1=101325
t1=500
t3=2300   
gamma=1.4
## Swept volumne,v_s (m^3)
v_s=(math.pi/4)* pow(d,2)*l    
### clearance volume, v_c
v_c=v_s/(rc-1) 
## 1st state
v1=v_s+v_c 
v2=v_c
## 2nd state
p2=p1*pow(v1,gamma)/pow(v2,gamma)
t2=(p2*v2*t1)/(p1*v1)

V_compression =engine_kinematics(d,l,c_l,rc,180,0)

constant=p1*pow(v1,gamma)
p_compression=[]
for v in V_compression:
    p_compression.append(constant/pow(v,gamma))
    print(p_compression)
    
## 3rd state
p3=p2*(t3/t2)
v3=v2
### calculation of v and p for expansion stroke
V_expansion =engine_kinematics(d,l,c_l,rc,0,180) ## crank angle changes for expansion
constant=p3*pow(v3,gamma)
p_expansion=[]
for v in V_expansion:
    p_expansion.append(constant/pow(v,gamma))

## 4th state
v4=v1
p4=p3*pow(v3,gamma)/pow(v4,gamma)
t4=(p4*v4*t3)/(p3*v3)
plt.plot([v2,v3],[p2,p3])     ## const. volume heat addition phase i.e 1st stroke
plt.plot(V_compression,p_compression) ## compression i.e 2nd stroke
plt.plot(V_expansion,p_expansion)     ## expansion i.e 3rd stroke
plt.plot([v4,v1],[p4,p1])    ## const. volume heat rejection phase i.e 4th stroke
plt.show()

## calculation of thermal efficiency
Thermal_efficiency= 1-((t4-t1)/(t3-t2))
print('Thermal efficiency is:',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.

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.