Challenge

Week 2 Air standard Cycle

AIM:

Write code that can solve an otto cycle using Python Software.

Challenge expectation:

  • The code should create a PV diagram,

  • Code output should display the thermal efficiency of the engine.

CONCEPT:

ACTUAL

IDEAL

THEORY:

The Otto Cycle describes how heat engines turn gasoline into motion. Like other thermodynamic cycles, this cycle turns chemical energy into thermal energy and then into motion. The motion. The Otto cycle describes how internal combustion engines (that use gasoline) work, like automobiles and lawnmowers.

Otto Cycle is comprised of four processes (apart from the intake and exhaust process)

Process 1-2

This process comes after the intake process. In the case of SI engines, intake is a mixture of gasoline and air, also known as a charge. In this process, the charge is compressed in an isentropic manner.

Process 2-3

In this process, the fuel gets blasted with the help of an external spark (that is why the engine is known as a spark ignition engine). This process is a constant volume heat addition process.

Process 3-4

After the combustion process, the exhaust gases expand. This process is an isentropic expansion process.

Process 4-1

After the expansion process, the exhaust valve opens. This results in a sudden drop of pressure inside the engine cylinder. This process is a constant volume heat rejection process.

Process 0-1 is the intake process and process 1-0 is the exhaust process.

The starting point is the general expression for the thermal efficiency of a cycle:

The convention, as previously, is that heat exchange is positive if heat is flowing into the system or engine, so is negative. The heat absorbed occurs during combustion when the spark occurs, roughly at constant volume. The heat absorbed can be related to the temperature change from state 2 to state 3 as :

The heat rejected is given by (for a perfect gas with constant specific heats)

Substituting the expressions for the heat absorbed and rejected in the expression for thermal efficiency yields

We can simplify the above expression using the fact that the processes from 1 to 2 and from 3 to 4 are isentropic:

The quantity is called the compression ratio. In terms of compression ratio, the efficiency of an ideal Otto cycle is:

Function code: (Engine_kinematics code)

# Engine kinematics

import math
import matplotlib.pyplot as plt

# Geometric parameters 

bore = 0.10
stroke = 0.1
con_rod = 0.15
cr = 12
a = stroke/2 
R = con_rod/a

# Volume parameters
V_s = math.pi*(1/4)*pow(bore,2)*stroke
V_c = V_s/(cr-1)

theta = math.radians(180)

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 = (1 + term1*(term2 - term3))*V_c

Code Explanation:

  • Line 1: Adding comments for Re-collection
  • Line 3 to 4: Import math and Import matplotlib.pyplot as plt are the libraries used for calculation and plotting graphs respectively.
  • Lines 6 to 13: Adding the geometric parameters (Input parameters)
  • Lines 15 to 17: Volume parameters are defined, and swept volume and clearance volume.
  • Line 19: defining the value of theta (in radians)
  • Line 21 to 24: here the combustion formula is divided into 4 parts - term 1 term 2 and term 3 for ease of calculation.
  • Line 26: Here Calculation for Combustion volume has calculated the values from terms 1,2, and 3 are subtracted from 1.

Code for thermal efficiency:

# Otto cycle Simulator

# Importing libraries
import math
import matplotlib.pyplot as plt

def Engine_kinematics(bore, stroke, con_rod, cr, start_crank, end_crank):
    
    # Engine kinematics

    # Geometric parameters 

    a = stroke/2
    R = con_rod/a

    # Volume parameters
    V_s = math.pi*(1/4)*pow(bore,2)*stroke
    V_c = V_s/(cr-1)

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

    num_values = 80

    dtheta = (ec-sc)/(num_values-1)
    
    V =[]

    for i in range (0,num_values):
        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
# Parameters at state point 1
p1 = 1013255 # In Pascals
t1 = 500 # In kelvin
gamma = 1.4
t3 = 2300 # In Kelvin

# Geometric parameters 
bore = 0.1
stroke = 0.1
con_rod = 0.15
cr = 8


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


# For State point 2
v2 = v_c

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

#pvv2/t2 = p1v1/t1 | rhs = p1v1/t1 | p2v2/t2 = rhs | t2 = p2v2/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))

# For state point 3
v3 = v2

#p3v3/t3 = p2v2/t2 | rhs = p2v2/t2 | p3 = rhs*t3/v3

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 = rhs
t4 = p4*v4/rhs


# Thermal Efficiency of the cycle - 
thermal_efficiency = (1-pow((1/cr),(gamma-1)))*100
print(thermal_efficiency)



plt.plot([v2,v3,],[p2,p3])
plt.plot(V_compression, P_compression)
plt.plot(V_expansion, P_expansion)
plt.plot([v4,v1,],[p4,p1])
plt.title('Engine kinematics')
plt.text(0.0008,2220000,"Heat Rejection")
plt.text(0.0002,1000000,"Compression Stroke")
plt.text(0.0001,30000000,"Combustion Process Const. Volume Process")
plt.text(0.0003,15000000,"Power Stroke Adiabatic Process")
plt.show()




Code explanation:

  • Line 1: Adding comments for Re-collection
  • Line 3 to 5: Import math and Import matplotlib.pyplot as plt are the libraries used for calculation and plotting graphs respectively.
  • Lines 7 to 38: Using the Engine_kinematics code as a function code in the otto cycle for calculation.
    - Line 7: Writing the function synatx (def_(filename)) to insert the desierd code in otto cycle.
    - Lines 11 to 21: Adding the input parameters for the calculation sc and ec are the starting crank and ending crank of the cycle.
    - Line 23: defining num_values = 80 (to repeat the process n times)
    - Lines 23 to 27: calculating the value of dtheta, and creating an empty array (V = [])
    - Lines 29 to 36: creating a for loop for calculating the combustion volume (The process will repeat ) num_values = 80. the value which is calculated for V is stored (using append) command and the next iteration is started.
    - Line 38: return V is the command used to tell python to return the after calculating outside the FOR Loop.
  • Lines 43 to 54: Defining the Input parameters for state point 1 (t1,p1,t3, gamma) and defining geometric parameters (bore, stroke, con_rod, cr)
  • Lines 57 to 60: Calculating volume compression for state point 1.
  • Lines 63 to 79: calculating Volume compression and Pressure compression for state point 2.
    -
  • Line 81 to 96: calculating Volume 3 expansion and Pressure expansion for state point 3.
    -
  • Line 98 to 106: Calculating temperature for state point 4.
  • Lines 109 to 111: Calculating the thermal efficency of the cycle, adding print command to print the output of the cycle.
  • Lines 115 to 124: Giving plot command for plotting the graph.
    - plt.plot() command is used to plot 'vs' (comparison)
    - plt.title() command is use to give title to the plot.
    - plt.text() command is used to write text inside the graph.
    - plt.show() command is used to execute and display the graph.

Plot:

Thermal efficiency of the cycle:


Here the Image shows the output of the thermal efficiency of the otto cycle,
the output is shown down below in the terminal window

  • Thermal efficiency of the cycle is 56.47247183519378

REFERENCE:

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.