Challenge

Week 2 Air standard Cycle

Aim: To model and analyze the thermodynamic processes of an Air Standard Cycle using Python

Problem Statement:

  • To create PV Diagram
  • To calculate the thermal efficiency of the engine.

Python Code:

import math
import matplotlib.pyplot as plt

# Input parameters
bore = 0.069
stroke = 0.0768
compression_ratio = 8
p1 = 100000
t1 = 308
t3 = 1373
gamma = 1.4
Cv = 0.718
connecting_rod_length = 0.1

def swept_volume(bore, stroke):
    return (math.pi / 4) * bore ** 2 * stroke

def clearance_volume(swept_volume, compression_ratio):
    return swept_volume / (compression_ratio - 1)

def engine_kinematics(bore, stroke, connecting_rod_length, compression_ratio, start_crank, end_crank):
    crank_radius = stroke / 2
    R = connecting_rod_length / crank_radius
    n_theta = 50
    sc = math.radians(start_crank)
    ec = math.radians(end_crank)
    v_c = clearance_volume(swept_volume(bore, stroke), compression_ratio)

    V = []

    for i in range(n_theta):
        theta = sc + i * (ec - sc) / (n_theta - 1)
        term1 = 0.5 * (compression_ratio - 1)
        term2 = R + 1 - math.cos(theta)
        term3 = R ** 2 - math.sin(theta) ** 2
        term3 = math.sqrt(term3)
        V.append((1 + term1 * (term2 - term3)) * v_c)

    return V

def calculate_pressure(volumes, gamma, constant, p_ref):
    pressures = []
    for v in volumes:
        pressures.append(constant / v ** gamma)
    return pressures

def otto_cycle_efficiency(t1, t3, t2, t4, Cv):
    q_in = Cv * (t3 - t2)  # Heat Input
    q_out = Cv * (t4 - t1)  # Heat Output
    w_net = q_in - q_out  # Net work done
    efficiency = (w_net / q_in) * 100
    return efficiency

def plot_cycle(v1, p1, v2, p2, v3, p3, v4, p4, v_compression, p_compression, v_expansion, p_expansion):
    plt.xlabel('Volume (m^3)')
    plt.ylabel('Pressure (Pa)')
    plt.plot([v2, v3], [p2, p3], label='Constant Volume Heat Addition', color='green')
    plt.plot([v4, v1], [p4, p1], label='Constant Volume Heat Rejection', color='violet')
    plt.plot(v_compression, p_compression, label='Compression', color='red')
    plt.plot(v_expansion, p_expansion, label='Expansion', color='blue')
    plt.title('Otto Cycle on P-V Diagram')
    plt.legend()
    plt.grid(True)
    plt.show()



# Calculate volumes
v_s = swept_volume(bore, stroke)
v_c = clearance_volume(v_s, compression_ratio)
v1 = v_s + v_c
v2 = v_c
v3 = v2
v4 = v1

# Calculate pressures and temperatures
p2 = p1 * (v1 / v2) ** gamma
p3 = p2 * (t3 / t1)
p4 = pow((v3 / v4), gamma) * p3
t2 = t1 * (v1 / v2) ** (gamma - 1)
t4 = t3 * (v3 / v4) ** (gamma - 1)

# Calculate constants
constant_compression = p1 * v1 ** gamma
constant_expansion = p3 * v3 ** gamma

# Calculate volumes and pressures during compression and expansion processes
v_compression = engine_kinematics(bore, stroke, connecting_rod_length, compression_ratio, 180, 0)
p_compression = calculate_pressure(v_compression, gamma, constant_compression, p1)

v_expansion = engine_kinematics(bore, stroke, connecting_rod_length, compression_ratio, 0, 180)
p_expansion = calculate_pressure(v_expansion, gamma, constant_expansion, p3)

# Calculate efficiency
efficiency = otto_cycle_efficiency(t1, t3, t2, t4, Cv)

# Print efficiency
print("The Efficiency of Otto Cycle is {:.2f}%".format(efficiency))

# Plot cycle
plot_cycle(v1, p1, v2, p2, v3, p3, v4, p4, v_compression, p_compression, v_expansion, p_expansion)


Solution Procedure:

1. Input Parameters:

  • Define the necessary input parameters, such as bore diameter, stroke length, compression ratio, initial pressure, initial and final temperatures, specific heat capacity at constant volume, and connecting rod length.

2. Functions Definitions:

  • swept_volume: computes the swept volume of the engine using the bore and stroke.
  • clearance_volume: calculates the clearance volume based on the swept volume and compression ratio.
  • engine_kinematics: Determines the engine kinematics, specifically volume changes during the compression and expansion strokes.
  • calculate_pressure: computes pressure values using the provided volumes, gamma (specific heat ratio), a constant, and a reference pressure.
  • otto_cycle_efficiency: calculates the efficiency of the Otto cycle based on the heat input and output.

3. Calculation of Volumes:

  • swept volume and clearance volume.
  • Determine the total volume at points 1 and 2.

4. Pressure and Temperature Calculations:

  • Compute pressures at points 2, 3, and 4 using the given formulas based on the ideal gas law.
  • Calculate temperatures at points 2 and 4 using the relation between pressure, volume, and temperature for an ideal gas.

5. Constant Calculations:

  • Compute constants for compression and expansion processes.

6. Compression and Expansion Process Simulation:

  • Using engine kinematics, calculate volumes during compression and expansion processes.
  • Determine pressures during these processes using the calculated constants and the ideal gas law.

7. Efficiency Calculation:

  • Calculate the efficiency of the Otto cycle based on the heat input and output during the processes.

8. Plotting a PV Diagram:

  • Plot the PV diagram showing the compression, expansion, constant volume heat addition, and constant volume heat rejection processes.

9. Output:

  • Display the efficiency of the Otto cycle as a percentage.

Results and Discussion:

  • The Efficiency of Otto Cycle is 56.47%

Conclusion

  • In conclusion, the provided code successfully analyzes an Otto cycle engine, incorporating efficiency calculation and visualization of the engine's performance through a pressure-volume (PV) diagram. Here's a summary with a comment about the calculated efficiency:
  • Efficiency Calculation: The code accurately computes the thermal efficiency of the Otto cycle, resulting in an efficiency value of approximately 56.47%. This efficiency value represents the engine's ability to convert heat energy into useful work, indicating its effectiveness in utilizing fuel.
  • PV Diagram Visualization: By plotting the PV diagram, the code visually illustrates the engine's compression and expansion strokes, as well as the constant volume heat addition and rejection processes, providing valuable insights into the engine's thermodynamic behavior.
  • Insightful Analysis: Through the efficiency output and PV diagram, one can gain valuable insights into the performance and characteristics of the Otto cycle engine, facilitating informed decisions for design optimization and performance enhancement.
  • Conclusion: The calculated efficiency value of 56.47% reflects the engine's efficiency in converting heat energy into mechanical work. This value serves as a benchmark for evaluating the engine's performance and guiding further improvements in efficiency and design. Overall, the code offers a comprehensive analysis of the Otto cycle engine, enabling a deeper understanding of its operation and 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.