Project

Air Standard Cycle using Python

AIM :

To write a Python code that can solve Otto Cycle and make plots for it.

  • Should contain PV diagram.
  • Should output thermal efficiency of the engine.

INTRODUCTION :

An otto cycle is an idealized thermodynamic cycle which helps us in understanding the theoretical limits of a particular cycle. It typically describes the functioning of a Spark Ignition (SI) piston engine.

It is a description of what happens to a mass of gas subjected to changes in pressure, volume, temperature, heat addition and heat removal and thereby giving us an idea of real world systems such as I.C engines and gas turbines.

When the piston in the cylinder of Internal Combustion Engine (SI Engine) moves from BDC (Bottom Dead Centre) to TDC (Top Dead Centre), the pressure and volume relatively change, which is represented on the diagram known as PV-diagram as shown above.

The various processes involved in the above mentioned figure are as follows :

1. PROCESS 1 – 2 : ADIABATIC COMPRESSION

During this process, piston moves from `BDC` (or crank end) to `TDC` (or cylinder head) and the air-fuel mixture that has entered the chamber gets compressed. The compression causes the mixture to increase in pressure from `P_1` to `P_2`, volume to reduce from `V_1` to `V_2` and temperature to increase from `T_1` to `T_2`.

2. PROCESS 2 – 3 : CONSTANT VOLUME HEAT ADDITION

This is where combustion occurs due to ignition of fuel by spark plug. The piston in this process rests for a moment at `TDC` and during this time, heat is added to the working fluid by combustion of injected fuel, with the volume being held constant. Due to heat addition, the pressure increases from `P_2` to `P_3`, volume remains constant (i.e, `V_2` `= V_3`) and the temperature increases from `T_2` to `T_3`.

3. PROCESS 3 – 4 : ADIABATIC EXPANSION

The thermal energy in the chamber as a result of combustion exerts a force on piston and pushes it from `TDC`to `BDC`. This is also known as power stroke as power obtained in this process is used to do some work. Since the process involves expansion of air, the pressure decreases from `P_3` to `P_4`, volume increases from `V_3` to `V_4` and temperature falls from `T_3` to `T_4`.

4. PROCESS 4 – 1 : CONSTANT VOLUME HEAT REJECTION

In this process, the piston rests for a moment at `BDC` and rejection of heat takes place at constant volume (i.e, `V_4 = V_1`). All the waste heat is expelled from the engine chamber leading to temperature fall from `T_4` to `T_1`. As heat leaves the gas, the molecules lose kinetic energy causing a decrease in pressure from `P_4` to `P_1`.

TERMINOLOGIES :

1. Bore :- Bore in an engine refers to the diameter of each cylinder.

2. Stroke :- Stroke refers to the distance within the cylinder which the piston travels.

3. Compression Ratio (CR) :-

It is the ratio of volume before compression (with the piston at BDC) to the volume after compression (with the piston at TDC). High compression ratios give increased efficiency but lead to knocking of the engine.

`(CR) = (V_s+V_c)/(V_c) = (V_1)/(V_2)`

Where,

`V_1` = Volume before compression = `V_s + V_c`

`V_2` = Volume after compression = `V_c`

`V_s` = Swept volume

`V_c` = Clearance volume

4. Swept Volume (`V_s`) :-

Swept volume can be defined as the volume swept by the engine piston during one stroke.

`V_s = (pi/4) * D² * L`

Where,

`D` = Bore Diameter

`L` = Stroke Length

5. Clearance Volume (`V_c`) :-

Clearance volume can be defined as the volume that remains in the cylinder when the engine piston is in the top centre position.

`V_c = (V_s) / (CR – 1)`

Where,

`V_s` = Swept volume

`CR` = Compression ratio

6. Thermal Efficiency :-

The thermal efficiency of any heat engine can be defined as the ratio of work done to the heat input.

`eta = "work done"/"heat input" = 1 – ( 1 / (CR^(γ-1)))`

Where,

`γ = (C_p)/(C_v) = "Specific heat at constant pressure"/"Specific heat at constant volume"`

PROGRAM & EXPLANATION :

In this section, we are going to write a Python program to solve the Otto Cycle and obtain a PV – plot of the same. The first and foremost step in the program is to import the necessary modules into python. Here, we import the ‘matplotlib’, ‘numpy’ and ‘math’ modules.

Inputs :

In this step, we define the various input arguments and assumed values of the program.

State Parameters :

Specific Heat Ratio `gamma = 1.4`

Temperature at State Point-3 `T_3 = 2300` `K`

Pressure at State Point-1 `P_1 = 101325` `Pa`

Temperature at State Point-1 `T_1 = 500` `K`

Engine Geometric Parameters :

Bore `= 0.1` `m`

Stroke `= 0.1` `m`

Connecting Rod Length `= 0.15` m

Compression Ratio `= 12`

Swept & Clearance Volumes :

In this step, from the defined input data, we calculate the values of the swept volume and the clearance volume of the cycle.

  • The swept volume of the cycle is calculated by using the equation.

    `V_s = (pi/4) * ("Bore")² * "Stroke"`


  • Similarly, the clearance volume is calculated as.

    `V_c = V_s / (CR – 1)`


From these calculated values, the volumes of state points 1 & 2 are also defined as,

`V_1 = V_"swept" + V_"clearance"`

`V_2 = V_"clearance"`

State Point Parameters :

In this step, we calculate the values of Pressure (P), Volume (V) and Temperature (T) of all 4 state point variables so as to plot our P-V diagram.

  • The values of pressure (`P_1`) and temperature (`T_1`) at state point-1 has been assumed and the volume (`V_1`) has been calculated as shown above.


  • From the known values of `P_1`, `V_1` and `V_2`, we calculate the pressure at state point-2 (`P_2`) by using the equation.

    `P * V^gamma = "constant"`

    `P_1 * V_1^gamma = P_2 * V_2^gamma`

    `P_2 = P_1 * (V_1/V_2)^gamma`




    Using the ideal gas law, temperature (`T_2`) is calculated as,

    `(P_1 * V_1) / T_1 = (P_2 * V_2) / T_2`


    `T_2 = (P_2 * V_2 * T_1) / (P_1 * V_1)`





  • As process 2-3 is a constant volume heat addition process, we get.

    `V_3 = V_2`



    Also, as temperature (`T_3`) at state point-3 is known, we calculate the pressure (`P_3`) by using the equation.

    `(P_2 * V_2) / T_2 = (P_3 * V_3) / T_3`


    `P_3 = (P_2 * T_3) / T_2`





  • As process 4 – 1 is a constant volume heat rejection process, we get.

    `V_4 = V_1`



    Finally, we calculate the pressure at state point-4 (`P_4`) by using the equation,

    `P_3 * V_3^gamma = P_4 * V_4^gamma`


    `P_4 = P_3 * (V_3 / V_4)^gamma`

Piston Kinematics Equation :
In this step, we define a User - Defined Function representing the piston kinematics equation. The equation is represented as,

`V / V_c = 1 + 1/2 (r_c – 1) * [R + 1 – costheta – (R^2 – Sin^2theta)^0.5]`

Where,

`R = "connecting rod length" / a`

`a = "stroke" / 2`

`theta =` Crank Angle

  • The function takes the inputs of the bore, stroke, connecting rod length, compression ratio, starting crank angle and the ending crank angle and outputs the value of stroke volume (V).



  • The equation is calculated for each and division ranging from the start crank angle to the end crank angle. The calculated values of “V” are then appended into an empty matrix so as to obtain our final matrix.

The above defined user function is called during the compression and expansion processes so as to obtain our characteristic curve.

  • The compression volume (`V_"compression"`) and compression pressure (`P_"compression"`) are calculated by varying the crank angle from `180^o` (start crank angle) to `0^o` (end crank angle).













  • The expansion volume (`V_"expansion"`) and expansion pressure (`P_ "expansion"`) are calculated by varying the crank angle from `0^o` (start crank angle) to `180^o` (end crank angle).



Thermal Efficiency :

The thermal efficiency of the Otto Cycle is calculated by using the equation.

`eta = "work done"/"heat input" = 1 – ( 1 / (CR^(gamma-1)))`

Plotting :

From the calculated state point variables as well as the compression and expansion parameters, we generate a plot representing the P-V diagram of an Otto Cycle. We provide the necessary labels and title as well.

OUTPUTS :

By running the above program code, we obtain the respective outputs as follows.

1. P-V Plot

2. Thermal Efficiency

The thermal efficiency of the Otto Cycle is calculated to be 62.98 %.

Final Program Code :

# AIR STANDARD CYCLE
import matplotlib.pyplot as plt
import math
import numpy as np




# PISTON KINEMATICS EQUATION
def piston_kinematic_equation(bore,stroke,connecting_rod_length,CR,start_crank,end_crank):

    #ENGINE GEOMETRIC PARAMETERS (Assumed)
    a = stroke/2
    R = connecting_rod_length/a


    # CALCULATING SWEPT VOLUME & CLEARANCE VOLUME
    V_swept = (math.pi/4) * (bore**2) * stroke
    V_clearance = V_swept / (CR-1)


    # CRANK ANGLES
    SC = math.radians(start_crank)
    EC = math.radians(end_crank) 


    theta = np.linspace(SC,EC,100)


    V = []

    for i in range(0,100):

        THETA = theta[i]


        # EQUATION
        term1 = 0.5 * (CR - 1)
        term2 = R + 1 - math.cos(THETA)
        term3 = (R**2 - (math.sin(THETA)**2))**0.5


        # FINAL EQUATION
        v = (1 + term1 * (term2 - term3))*V_clearance
        V.append(v)

    return V





# INPUT VARIABLES (Given)
# Specific Heat Ratio
gamma = 1.4

# Temperature at State-3
T3 = 2300

# Pressure & Temperature at STATE-1
P1 = 101325
T1 = 500



#ENGINE GEOMETRIC PARAMETERS (Assumed)
bore = 0.1
stroke = 0.1
connecting_rod_length = 0.15
CR = 12




# CALCULATING SWEPT VOLUME & CLEARANCE VOLUME
V_swept = (math.pi/4) * (bore**2) * stroke
V_clearance = V_swept / (CR-1)


V1 = V_swept + V_clearance
V2 = V_clearance



# STATE POINT-2
# P1 * V1^gamma = P2 * V2^gamma
# V1 / V2 = gamma
P2 = P1 * (CR**gamma)

# P1*V1/T1 = P2*V2/T2
T2 = (P2 * V2 * T1)/(P1 * V1)



constant_c = P1*(V1**gamma)
V_compression = piston_kinematic_equation(bore,stroke,connecting_rod_length,CR,180,0)
P_compression = []

for i in V_compression:
	P_compression.append(constant_c/i**gamma)




# STATE POINT-3
V3 = V2

# P2*V2/T2 = P3*V3/T3
P3 = (P2 * T3) / T2



constant_e = P3*(V3**gamma)
V_expansion = piston_kinematic_equation(bore,stroke,connecting_rod_length,CR,0,180)
P_expansion = []

for j in V_expansion:
	P_expansion.append(constant_e/j**gamma)




# STATE POINT-4
V4 = V1

# P3 * V3^gamma = P4 * V4^gamma
P4 = P3 * ((V3/V4)**gamma)




# THERMAL EFFICIENCY
eta = 1 - (1/(CR**(gamma-1)))
efficiency_in_percent = eta*100
print("Thermal Efficiency of Otto Cycle =",efficiency_in_percent)




# PLOTTING
plt.plot(V_compression,P_compression)
plt.plot(V_expansion,P_expansion)
plt.plot([V2,V3],[P2,P3])
plt.plot([V4,V1],[P4,P1])
plt.title("PV - Plot of Otto Cycle",fontweight="bold")
plt.xlabel("Volume")
plt.ylabel("Pressure")
plt.show()
 

CONCLUSIONS :

  • The python code to solve the Otto cycle has been successfully written and the respective outputs have been obtained.


  • The state point variables at all 4 points have been calculated for the Otto cycle and the respective P-V plot has been obtained as shown above.


  • The thermal efficiency of the Otto cycle is calculated to be 62.9%.
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.