0% found this document useful (0 votes)
2 views44 pages

Project Python Ashfak 11111

Uploaded by

sohil khan
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views44 pages

Project Python Ashfak 11111

Uploaded by

sohil khan
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

A

Project report

On

AutoCAD

Submitted in partial fulfilment for the award of

the degree of

Bachelor of Technology

in

Department of Mechanical Engineering

Submitted to: - submitted by:-

Dr. Rajesh Kumar Ojha Mohammed Ashfak (22EBUME001)

(Head of Department)

Supervisor:-

Dr. Parbant Singh Sandhu

(Assistant professor)

Department of Mechanical Engineering

University College of Engineering and Technology Bikaner

Bikaner Technical University

i
ACKNOWLEDGEMENT

It is pleased acknowledge indebtedness to Dr. Parbant Singh Sandhu ,Asst. Professor of


Department Mechanical Engineering for his kind cooperation and guidance accomplish the
project “ AutoCAD”. Further we are thankful to the Dr. Rajesh Kumar Ojha
(H.O.D.) and entire staff of the department of Mechanical Engineering of
Mechanical engineering for their kind cooperation and providing adequate facilities for
successful completion of this project and to our friends for their moral support.

Finally, we would like to add a few heartfelt words for the people who were the part of the
project in various ways, especially our friends and classmates who gave us unending support
right from the beginning. Our family has been the most significant in our life so far and this part
of our life is no exception. Without their support, persistence and love we would not be where
we are today.

Mohammed Ashfak(22EBUME001)

ii
DECLARATION

It is hereby declare that the work, which is being presented in the project report, is entitled
― AutoCAD" In partial fulfillment for the award of degree of the ‖. In partial fulfillment for the
award of degree of ―Bachelor of Technology" in department of Mechanical engineering is
submitted to the Department of Mechanical Engineering, College of Engineering and
Technology Bikaner, affiliated from " Bikaner Technical University" is a cord of my own
investigation carried under the supervision of Dr. Parbant Singh Sandhu , Department of
Mechanical Engineering, College of Engineering and Technology Bikaner. We have not
submitted the matter presented in this project report anywhere for the award of any other degree.

Mohammed Ashfak(22EBUME001)

iii
CERTIFICATE

Project entitled as "" by Mohammed Ashfak(22EBUME001),

is done in partial fulfilment of the requirement for the award of the degree of Bachelor of
Engineering in Mechanical to Bikaner Technical University, Bikaner, India is a record of
student's own work carried out under my supervision and guidance. To the best of my
knowledge, this project has not been submitted in part or full to any other university or
institution for the award of any degree or diploma.

Dr. Parbant Singh Sandhu

(Assistant professor)

Dr. Rajesh Kumar Ojha

(Head of department)

iv
Table of Contents
Chapter -1 Introduction .....................................................................................................................1
1.1 Introduction to the Otto Cycle Simulator ........................................................................................... 1
1.2 Objective of the Project: ..................................................................................................................... 1
1.3 Theory and Fundamentals of the Otto Cycle ...................................................................................... 1
1.4 Key Parameters of the Otto Cycle ....................................................................................................... 2
Chapter -2 Diagrams of the Otto Cycle ................................................................................................4
2.1 PV Diagram:......................................................................................................................................... 4
2.2 T-S Diagram: ........................................................................................................................................ 5
Chapter-3 Mathematical Modeling .....................................................................................................6
3.1 Overview of the Mathematical Model ................................................................................................ 6
3.2 Code Snippet: Mathematical Implementation in Python ................................................................... 9
3.3 Diagram: Work Done and Heat in the Otto Cycle ............................................................................. 10
Chapter-4 System Design and Architecture ....................................................................................... 11
4.1 Overview of the System Architecture ............................................................................................... 11
4.2 System Components ......................................................................................................................... 11
4.3 High-Level System Design ................................................................................................................. 11
4.4 Detailed Architecture ....................................................................................................................... 12
4.5 System Architecture Diagram .......................................................................................................... 15
Chapter-5 Code Implementation ...................................................................................................... 17
5.1 Overview of the Code Structure ....................................................................................................... 17
5.2 Flask Application ([Link]) ................................................................................................................. 17
5.3 Otto Cycle Calculation Logic ([Link]) ..................................................................................... 18
5.4 Visualization ([Link]) ............................................................................................................... 20
5.5 User Interface (HTML Templates) ..................................................................................................... 21
Chapter-6 User Interface and Visualizations ...................................................................................... 22
6.1 Overview of the User Interface ......................................................................................................... 22
6.2 Index Page ([Link]) .................................................................................................................... 22
6.3 Results Page ([Link]) ............................................................................................................... 25
6.4 Interactive Visualizations .................................................................................................................. 27
Chapter -7 Results and Discussion .................................................................................................... 29
7.1. Simulation Results ............................................................................................................................ 29

v
7.2 Effect of Compression Ratio (CR) ..................................................................................................... 29
7.3 Effect of Bore and Stroke ................................................................................................................. 32
7.4 Pressure-Volume Diagram Analysis .................................................................................................. 32
7.5 Pressure-Angle Diagram Analysis...................................................................................................... 33
7.6 Discussion.......................................................................................................................................... 33
Chapter- 8 Conclusion ...................................................................................................................... 34
8.1 Summary of Findings......................................................................................................................... 34
8.2 Implications for Engine Design.......................................................................................................... 34
8.3 Limitations of the Model ................................................................................................................... 35
8.4 Future Work ...................................................................................................................................... 35
8.5 Concluding Remarks.......................................................................................................................... 35
Chapter- 9 References ..................................................................................................................... 36

vi
List of Figure

Figure No. Title Page No.

Figure 2.1 PV Diagram of Otto Cycle 4

Figure 2.2 T-S diagram of Otto Cycle 5

Figure 3.1 Work Done on Otto Cycle 10

Figure 4.1 System Architecture Diagram 16

Figure 6.1 Indux page 24

Figure 7.1 Final output of the simulation 30

vii
Chapter -1 Introduction

1.1 Introduction to the Otto Cycle Simulator

The Otto cycle is the thermodynamic cycle commonly used in gasoline engines. This cycle
consists of four processes. Out of four processes of the cycle, there are two constant-volume
processes and two adiabatic processes. The heat addition and heat rejection of the cycle take
place at constant volume processes; expansion and compression of the cycle take place
adiabatically. The efficiency and performance of engine is based on the Otto cycle, mainly
depend on the design parameters such as compression ratio, bore, stroke, and engine
temperature.

The main aim of this project is to investigate the effect of the parameters on the efficiency of
Otto cycle. Hence, the computational tools are used to find out the efficiency of the cycle by
varying different parameters. In this way, the engine performance is determined with varying
different parameters such as pressure, volume, and temperature by using Python programming.

1.2 Objective of the Project:

The primary objectives of this project are:

 To develop a Python-based simulation model of the Otto cycle.


 To visualize the thermodynamic processes involved using interactive diagrams.
 To provide a user-friendly web interface for inputting engine parameters and viewing
results.
 To analyze the effects of different engine parameters on performance metrics.

1.3 Theory and Fundamentals of the Otto Cycle

The Otto Cycle in Internal Combustion Engines

The Otto cycle is the thermodynamic cycle employed by most gasoline engines. The engine
works by compressing a mixture of air and fuel, igniting it through a spark plug, and allowing
the combustion gases to expand, pushing a piston to do work. The cycle then ends with heat
rejection as the exhaust gases are expelled.

The Otto cycle consists of four main processes:

1. Isentropic Compression: the air-fuel mixture is compressed adiabatically, increasing both


pressure and temperature while decreasing volume.

1
2. Constant volume Heat Addition: At the top of the compression stroke, the spark plug
ignites the compressed air-fule mixture, rapidly increasing pressure and temperature at a
constant volume.

3. Isentropic Expansion: The combustion gases expand adiabatically, performing work on


the piston while cooling down

4. Constant Volume Heat Rejection: The exhaust gases are expelled from the engine at a
constant volume, completing the cycle.

1.4 Key Parameters of the Otto Cycle

The performance of an Otto engine depends on several parameters:

 Bore: The diameter of the cylinder in the engine. It affects the displacement volume and,
ultimately, the engine's power output.

 Stroke: The distance the piston travels inside the cylinder during one cycle.

 Compression Ratio (CR): The ratio of the volume of the cylinder at the bottom of the
stroke to the volume at the top of the stroke. Higher compression ratios typically improve
efficiency.

 Specific Heat Ratio (γ): The ratio of specific heat at constant pressure to specific heat at
constant volume. For air, γ is typically around 1.4.

The following key equations govern the Otto cycle:

1 Adiabatic compression and expansion:

where:

 P is the pressure,

 V is the volume,

2
 γ is the specific heat ratio.

 Thermal Efficiency: The thermal efficiency of an ideal Otto cycle is given by:

 η is the thermal efficiency,

 CR is the compression ratio,

 γ is the specific heat ratio.

Work and Heat: Work done during compression and expansion can be calculated using the area
under the pressure-volume curve, while heat added is calculated based on the change in
temperature and specific heat at constant volume.

3
Chapter -2 Diagrams of the Otto Cycle

The Otto cycle is commonly represented on a Pressure-Volume diagram and a Temperature-


Entropy diagram. These diagrams provide a visual representation of the work done during each
of the four processes in the cycle.

2.1 PV Diagram:

The PV diagram represents the relationship between pressure and volume as the system
undergoes the four processes. Here’s a general PV diagram for the Otto cycle:

Figure 2.1 PV diagram of Otto Cycle

 Process 2-3 (Compression): The volume decreases, and pressure increases as the air-fuel
mixture is compressed adiabatically.

 Process 3-4 (Constant Volume Heat Addition): The pressure increases dramatically at a
constant volume due to the ignition of the air-fuel mixture.

 Process 4-5 (Expansion): The volume increases, and pressure decreases as the
combustion gases expand and perform work.

4
 Process 5-6 (Constant Volume Heat Rejection): The exhaust gases are expelled at
constant volume.

2.2 T-S Diagram:

This diagram represents the relationship between temperature and entropy for each state. While it
is not as commonly used in the Otto cycle, it helps visualize the changes in entropy during the
heat addition and rejection processes.

Figure 2.2 T-S Diagram of Otto Cycle

5
Chapter-3 Mathematical Modeling

3.1 Overview of the Mathematical Model

It is important to develop a mathematical representation of the thermodynamic processes that


govern the operation of an internal combustion engine to simulate the Otto cycle. The Otto cycle
consists of four idealized processes: isentropic compression, constant-volume heat addition,
isentropic expansion, and constant-volume heat rejection. In addition to modeling these
thermodynamic processes, it is necessary to account for the piston kinematics, as the cylinder
volume varies with respect to the crank angle. This chapter outlines the key assumptions,
governing equations, and analytical relationships used to model the Otto cycle.

This section covers the mathematical modeling of each process in the Otto cycle, as well as the
calculations used to simulate the cycle and generate performance metrics.

1 Adiabatic Compression and Expansion

Both the compression and expansion processes in the Otto cycle are adiabatic. The pressure and
volume at each state point are related by the following equation, which is derived from the first
law of thermodynamics:

Where:

 P is the pressure at a given state,

 V is the volume at that state,

 γ is the specific heat ratio and for air, it typically has a value of 1.4.

During the compression process (2-3), the volume decreases, and the pressure increases. The
temperature also rises because of the work done on the gas. Similarly, during the expansion
process (4-5), the volume increases, and the pressure decreases.

For an adiabatic process, the relationship between the initial and final states is given by:

Or:

6
Where:

 P1 and P2 are the pressures at the initial and final states,

 V1 and V2 are the volumes at the initial and final states,

 T1 and T2 are the temperatures at the initial and final states.

2. Heat Addition

In the Otto cycle, heat is added at constant volume . The pressure rises sharply as the air-fuel
mixture is ignited by the spark plug. This process is modeled as:

Where:

 Qin is the heat added to the working fluid ,


 ΔU is the change in internal energy,
 m is the mass of the gas,
 cv is the specific heat at constant volume,
 T2 and T3 are the temperatures before and after combustion.

At the end of the compression stroke, the mixture is compressed to a small volume and then
ignited, causing the temperature and pressure to increase drastically at constant volume.

3. Heat Rejection

The heat rejection process occurs at constant volume as the exhaust gases are expelled. Similar to
heat addition, the temperature of the exhaust gases decreases as the engine expels them, and the
pressure drops. Heat rejected is calculated using the temperature change between state 5 and
state 6.

The heat rejected, Q is given by:

7
Where:

 Cv is the specific heat at constant volume,

 T6 and T5 are the temperatures at states 6 and 5, respectively.

4. Work Done by the Engine

The work done during the compression and expansion strokes is found using the area under the
pressure-volume curve, which is an integral of the pressure with respect to volume. The work for
each process is calculated using numerical integration techniques like Simpson's rule.

 Compression Work: The compression work is the area under the curve from state 2 to
state 3 on the PV diagram. It’s computed by integrating the pressure over the volume
change during compression.

 Expansion Work: Similarly, the expansion work is the area under the curve from state 3
to state 4 on the PV diagram.

5. Thermal Efficiency

The thermal efficiency of the Otto cycle is the ratio of the net work output to the heat added to
the system. It is calculated using the following formula:

8
Where:

 η is the thermal efficiency,

 CR is the compression ratio,

 γ is the specific heat ratio.

This equation gives the theoretical maximum efficiency of an ideal Otto engine. In practice, the
efficiency is often lower due to real-world factors like friction, heat losses, and imperfect
combustion.

6. Engine Kinematics

In the Otto cycle, the volume changes as the piston moves up and down inside the cylinder. The
relationship between the crank angle and the volume is critical for simulating the cycle
accurately. The kinematics of the engine is described by the following equation:

Where:

 V(θ) is the volume as a function of the crank angle θ\thetaθ,

 Vc is the clearance volume,

 r is the compression ratio,

 θ is the crank angle.

This equation is used to simulate the volume change during the compression and expansion
strokes and calculate the associated pressures and temperatures.

3.2 Code Snippet: Mathematical Implementation in Python

Here’s how some of these equations are implemented in Python in your Otto Cycle class:

python

def calculate_state_points(self):

9
self.p2 = self.p1 * ([Link]) ** [Link]
self.t2 = self.t1 * ([Link]) ** ([Link] - 1)
self.p3 = self.p2 * (self.t3 / self.t2)
self.p4 = self.p3 * (1 / [Link]) ** [Link]
self.t4 = self.t3 * (1 / [Link]) ** ([Link] - 1)
[Link] = 1 - (1 / [Link]) ** ([Link] - 1)

3.3 Diagram: Work Done and Heat in the Otto Cycle

Here’s a visual representation of the work done and heat in the Otto cycle:

 The area under the compression curve represents the work done on the gas

The area under the expansion curve represents the work done by the gas.

Figure 3.1 Work Done in the Otto Cycle

10
Chapter-4 System Design and Architecture

4.1 Overview of the System Architecture

The Otto Cycle Simulator is a software tool designed to simulate the behavior of an internal
combustion engine based on the Otto cycle. The system is composed of three main components:
Calculation, Visualization, and User Interface

The system is implemented using Python for computation and modeling, Flask for web-based
interactivity, and Plotly for dynamic, interactive visualizations. The architecture is modular,
meaning the calculation logic, visualization logic, and web interface are separated, allowing easy
maintenance and updates.

4.2 System Components

1. Calculator (Backend)

o The backend is responsible for the computation of the Otto cycle processes. The
calculations are encapsulated in the OttoCycle class, which takes user inputs and
simulates the four processes of the Otto cycle. This component handles the
thermodynamic calculations, such as pressures, temperatures, volumes, work
done, and thermal efficiency.

2. Visualizer

o The visualizer is responsible for creating interactive graphs to represent the results
of the simulation. The create_pv_diagram and create_pressure_angle_diagram
functions generate the PV diagram and the pressure vs. crank angle diagram,
respectively. These visualizations are created using the Plotly library, which
allows for interactive and zoomable graphs.

3. Web Interface (Frontend)

o The frontend is built using Flask, HTML, CSS, and Bootstrap. It provides an
interactive user interface where the user can input engine parameters. The results
of the simulation, including the performance metrics and the visualizations, are
presented in a web browser. Flask routes handle communication between the
user’s inputs and the backend calculations.

4.3 High-Level System Design

The high-level architecture can be visualized as follows:

11
1. User Input:

o The user accesses a web page which is hosted by Flask.

o They enter engine parameters into a form.

2. Data Processing:

o The form data is sent to the backend via a POST request.

o The backend receives the parameters and creates an instance of the OttoCycle
class.

o The class performs the necessary calculations, including the simulation of the
cycle processes and the calculation of key performance metrics.

o The visualizer functions generate the graphs representing the Otto cycle
processes.

3. Output Presentation:

o The results and graphs are sent to the frontend and displayed to the user.

o The user can interact with the graphs by zoom in/out, hover to see details, etc. and
view detailed performance metrics.

4. Feedback Loop:

o The user can adjust the input parameters and rerun the simulation with new values
to compare the results.

4.4 Detailed Architecture

Here is a more detailed breakdown of the system's components:

1. Flask Backend ([Link]):

o The [Link] file defines the main routes of the Flask application. The main route
(/) handles both GET and POST requests.

 On a GET request, the user is presented with the input form ([Link]).

 On a POST request (when the user submits the form), the backend
processes the form data, creates an OttoCycle object, runs the simulation,
and renders the [Link] page with the calculated results.

12
o Flask serves as the bridge between the user interface (HTML) and the backend
calculations (Python).

Code Snippet from [Link]:

python

@[Link]('/', methods=['GET', 'POST'])


def index():
if [Link] == 'POST':
# Get form data
params = {
'bore': float([Link]['bore']),
'stroke': float([Link]['stroke']),
'con_rod': float([Link]['con_rod']),
'cr': float([Link]['cr']),
'p1': float([Link]['p1']),
't1': float([Link]['t1']),
't3': float([Link]['t3']),
'gamma': float([Link]['gamma'])
}

# Create and calculate cycle


cycle = OttoCycle(**params)
cycle.simulate_cycle_processes()

# Prepare results
results = {
'efficiency': [Link],
'net_work': cycle.net_work,
'heat_added': cycle.heat_added
}

# Create visualizations
pv_graph = create_pv_diagram(cycle)
pressure_angle_graph = create_pressure_angle_diagram(cycle)

return render_template('[Link]',
results=results,
pv_graph=pv_graph,
pressure_angle_graph=pressure_angle_graph,
params=params)

return render_template('[Link]')

13
2. Calculation Logic (Backend):

o The OttoCycle class contains all the methods necessary to calculate the various
thermodynamic properties of the Otto cycle. The class takes the input parameters
and runs simulations based on these inputs.

o Methods such as calculate_state_points, simulate_cycle_processes, and


engine_kinematics are responsible for the calculations that define the cycle.

Code Snippet from [Link]:

python

class OttoCycle:
def __init__(self, bore=0.1, stroke=0.1, con_rod=0.15, cr=9,
p1=101325, t1=300, t3=2300, gamma=1.4, num_points=100):
[Link] = bore
[Link] = stroke
self.con_rod = con_rod
[Link] = cr
self.p1 = p1
self.t1 = t1
self.t3 = t3
[Link] = gamma
self.num_points = num_points
self.R = 8.314

self.calculate_volumes()
self.calculate_state_points()

def calculate_state_points(self):
self.p2 = self.p1 * ([Link]) ** [Link]
self.t2 = self.t1 * ([Link]) ** ([Link] - 1)
self.p3 = self.p2 * (self.t3 / self.t2)
self.p4 = self.p3 * (1 / [Link]) ** [Link]
self.t4 = self.t3 * (1 / [Link]) ** ([Link] - 1)
[Link] = 1 - (1 / [Link]) ** ([Link] - 1)

4. Visualization (Frontend):

o The [Link] file handles the creation of the PV and pressure-angle diagrams
using Plotly. These diagrams are embedded in the HTML templates and displayed
interactively on the results page.

14
Code Snippet from [Link]:

python

def create_pv_diagram(cycle):
# Create figure
fig = [Link]()

# Add traces for each process


fig.add_trace([Link](
x=cycle.compression_volumes,
y=cycle.compression_pressures / 1000,
mode='lines',
name='Isentropic compression (1-2)',
line=dict(color='red', width=2)
))

fig.add_trace([Link](
x=[cycle.v2, cycle.v3],
y=[cycle.p2 / 1000, cycle.p3 / 1000],
mode='lines',
name='Constant volume heat addition (2-3)',
line=dict(color='blue', width=2)
))

# Add state points


for i, (v, p) in enumerate([(cycle.v1, cycle.p1),
(cycle.v2, cycle.p2),
(cycle.v3, cycle.p3),
(cycle.v4, cycle.p4)], 1):
fig.add_trace([Link](
x=[v],
y=[p / 1000],
mode='markers+text',
name=f'Point {i}',
text=[f' {i}'],
textposition='top right',
marker=dict(size=10, color='black'),
showlegend=False
))

return fig.to_html(full_html=False)

4.5 System Architecture Diagram

To provide a clearer understanding of the overall system architecture, here’s a high-level block
diagram:

15
Figure 4.1 System Architecture Diagram

16
Chapter-5 Code Implementation

5.1 Overview of the Code Structure

The code for the Otto Cycle Simulator is divided into multiple modules, each responsible for a
specific task. The structure of the project is as follows:

1. [Link]: The main Flask application that handles user requests, processes form data, runs
the Otto cycle simulation, and renders the results.

2. [Link]: Contains the core logic of the Otto cycle simulation, including the
thermodynamic calculations, engine kinematics, and the simulation of the cycle
processes.

3. [Link]: Responsible for generating interactive diagrams using the Plotly library.

4. templates/: Contains HTML files for the user interface like [Link], [Link], etc. .

5. static/: Contains static files, such as CSS and JavaScript files, for styling and additional
functionality.

Each module is designed to be independent and can be tested or updated individually.

5.2 Flask Application ([Link])

The Flask application serves as the web server, handling user input, running simulations, and
displaying results. The main route (/) receives form data from the user, calculates the Otto cycle,
and renders the results.

Code Snippet from [Link]:

python

from flask import Flask, render_template, request, redirect, url_for


from [Link] import OttoCycle
from [Link] import create_pv_diagram, create_pressure_angle_diagram

app = Flask(__name__)

@[Link]('/', methods=['GET', 'POST'])


def index():
if [Link] == 'POST':
# Get form data
params = {
'bore': float([Link]['bore']),

17
'stroke': float([Link]['stroke']),
'con_rod': float([Link]['con_rod']),
'cr': float([Link]['cr']),
'p1': float([Link]['p1']),
't1': float([Link]['t1']),
't3': float([Link]['t3']),
'gamma': float([Link]['gamma'])
}

# Create and calculate cycle


cycle = OttoCycle(**params)
cycle.simulate_cycle_processes()

# Prepare results
results = {
'efficiency': [Link],
'net_work': cycle.net_work,
'heat_added': cycle.heat_added
}

# Create visualizations
pv_graph = create_pv_diagram(cycle)
pressure_angle_graph = create_pressure_angle_diagram(cycle)

return render_template('[Link]',
results=results,
pv_graph=pv_graph,
pressure_angle_graph=pressure_angle_graph,
params=params)

return render_template('[Link]')

 GET Request: When the user first visits the page, the [Link] form is displayed.

 POST Request: When the user submits the form, the parameters are sent to the server, the
Otto cycle is simulated, and the results are rendered on the [Link] page.

5.3 Otto Cycle Calculation Logic ([Link])

The OttoCycle class in [Link] is responsible for the core calculation of the Otto cycle. It
models the thermodynamic processes and calculates the work done, heat added, and thermal
efficiency.

Code Snippet from [Link]:

18
python

import math
import numpy as np
from [Link] import simpson

class OttoCycle:
def __init__(self, bore=0.1, stroke=0.1, con_rod=0.15, cr=9,
p1=101325, t1=300, t3=2300, gamma=1.4, num_points=100):
[Link] = bore
[Link] = stroke
self.con_rod = con_rod
[Link] = cr
self.p1 = p1
self.t1 = t1
self.t3 = t3
[Link] = gamma
self.num_points = num_points
self.R = 8.314 # Universal gas constant

self.calculate_volumes()
self.calculate_state_points()

def calculate_volumes(self):
self.v_s = ([Link] / 4) * [Link] ** 2 * [Link] # Swept volume
self.v_c = self.v_s / ([Link] - 1) # Clearance volume
self.v1 = self.v_s + self.v_c
self.v2 = self.v_c
self.v3 = self.v2
self.v4 = self.v1

def calculate_state_points(self):
self.p2 = self.p1 * ([Link]) ** [Link]
self.t2 = self.t1 * ([Link]) ** ([Link] - 1)
self.p3 = self.p2 * (self.t3 / self.t2)
self.p4 = self.p3 * (1 / [Link]) ** [Link]
self.t4 = self.t3 * (1 / [Link]) ** ([Link] - 1)
[Link] = 1 - (1 / [Link]) ** ([Link] - 1)

def simulate_cycle_processes(self):
# Compression process (180° to 0°)
self.compression_angles, self.compression_volumes = self.engine_kinematics(180, 0)
self.compression_pressures = self.p1 * (self.v1 / self.compression_volumes) ** [Link]

# Expansion process (0° to 180°)


self.expansion_angles, self.expansion_volumes = self.engine_kinematics(0, 180)

19
self.expansion_pressures = self.p3 * (self.v3 / self.expansion_volumes) ** [Link]

# Calculate work and heat


self.compression_work = simpson(self.compression_pressures, self.compression_volumes)
self.expansion_work = simpson(self.expansion_pressures, self.expansion_volumes)
self.net_work = self.expansion_work - self.compression_work
self.heat_added = (self.t3 - self.t2) * (self.R / ([Link] - 1))

 calculate_volumes(): Calculates the swept and clearance volumes based on the bore,
stroke, and compression ratio.

 calculate_state_points(): Calculates the pressures and temperatures at each state point


based on the initial conditions.

 simulate_cycle_processes(): Simulates the compression and expansion processes,


calculates work, and determines the thermal efficiency.

5.4 Visualization ([Link])

The [Link] module generates interactive diagrams using Plotly. The two key visualizations
are the PV diagram and the Pressure-Angle diagram.

Code Snippet from [Link]:

Python

import plotly.graph_objects as go

def create_pv_diagram(cycle):
fig = [Link]()

# Add traces for each process


fig.add_trace([Link](
x=cycle.compression_volumes,
y=cycle.compression_pressures / 1000,
mode='lines',
name='Isentropic compression (1-2)',
line=dict(color='red', width=2)
))

fig.add_trace([Link](
x=[cycle.v2, cycle.v3],
y=[cycle.p2 / 1000, cycle.p3 / 1000],
mode='lines',

20
name='Constant volume heat addition (2-3)',
line=dict(color='blue', width=2)
))

fig.add_trace([Link](
x=cycle.expansion_volumes,
y=cycle.expansion_pressures / 1000,
mode='lines',
name='Isentropic expansion (3-4)',
line=dict(color='green', width=2)
))

fig.add_trace([Link](
x=[cycle.v4, cycle.v1],
y=[cycle.p4 / 1000, cycle.p1 / 1000],
mode='lines',
name='Constant volume heat rejection (4-1)',
line=dict(color='purple', width=2)
))

return fig.to_html(full_html=False)

This function generates the PV diagram, showing the four processes of the cycle: compression,
heat addition, expansion, and heat rejection. The to_html() method converts the Plotly figure into
HTML that can be embedded in the webpage.

5.5 User Interface (HTML Templates)

The user interface is designed using Flask templates. The [Link] template provides a form
for user input, while [Link] displays the results and visualizations. These templates use
Bootstrap for styling and Plotly for dynamic charts.

Code Snippet from [Link]:

html

<form method="POST">
<div class="form-group">
<label for="bore">Bore diameter (m):</label>
<input type="number" class="form-control" id="bore" name="bore" required>
</div>
<!-- Additional input fields for other parameters -->
<button type="submit" class="btn btn-primary">Run Simulation</button>
</form>

This form collects input from the user and sends it to the backend for processing.

21
Chapter-6 User Interface and Visualizations

6.1 Overview of the User Interface

The user interface for the Otto Cycle Simulator is built using Flask and Bootstrap. It consists of
two main pages:

1. Index Page ([Link]): A form where users can input various parameters related to the
engine. After the user submits the form, the data is sent to the Flask backend, which
processes it and calculates the Otto cycle results.

2. Results Page ([Link]): Displays the results of the simulation, including the
calculated performance metrics, input parameters, and visualizations.

6.2 Index Page ([Link])

The index page is designed to allow users to enter input parameters for the simulation. These
parameters include the bore diameter, stroke length, compression ratio, initial pressure, initial
temperature, and others.

Code Snippet from [Link]:

html

{% extends "[Link]" %}

{% block content %}
<div class="row justify-content-center">
<div class="col-md-8">
<div class="card">
<div class="card-header">
<h2>Simulation Parameters</h2>
</div>
<div class="card-body">
<form method="POST">
<div class="row g-3">
<div class="col-md-6">
<label for="bore" class="form-label">Bore diameter (m)</label>
<input type="number" step="0.001" class="form-control" id="bore"
name="bore" value="0.1" required>
</div>
<div class="col-md-6">
<label for="stroke" class="form-label">Stroke length (m)</label>

22
<input type="number" step="0.001" class="form-control" id="stroke"
name="stroke" value="0.1" required>
</div>
<div class="col-md-6">
<label for="con_rod" class="form-label">Connecting rod length (m)</label>
<input type="number" step="0.001" class="form-control" id="con_rod"
name="con_rod" value="0.15" required>
</div>
<div class="col-md-6">
<label for="cr" class="form-label">Compression ratio</label>
<input type="number" step="0.1" class="form-control" id="cr" name="cr"
value="9" required>
</div>
<div class="col-md-6">
<label for="p1" class="form-label">Initial pressure (Pa)</label>
<input type="number" step="1000" class="form-control" id="p1" name="p1"
value="101325" required>
</div>
<div class="col-md-6">
<label for="t1" class="form-label">Initial temperature (K)</label>
<input type="number" step="1" class="form-control" id="t1" name="t1"
value="300" required>
</div>
<div class="col-md-6">
<label for="t3" class="form-label">Maximum temperature (K)</label>
<input type="number" step="10" class="form-control" id="t3" name="t3"
value="2300" required>
</div>
<div class="col-md-6">
<label for="gamma" class="form-label">Specific heat ratio (γ)</label>
<input type="number" step="0.01" class="form-control" id="gamma"
name="gamma" value="1.4" required>
</div>
</div>
<div class="text-center mt-4">
<button type="submit" class="btn btn-primary btn-lg">Run Simulation</button>
</div>
</form>
</div>
</div>
</div>
</div>
{% endblock %}

Key Features:

23
 Form Inputs: The page contains input fields for various parameters such as bore diameter,
stroke length, compression ratio, etc.
 Bootstrap Grid Layout: The form is organized using Bootstrap’s grid system, which
ensures a responsive layout for different screen sizes.
 Submit Button: After the user fills out the form, they can click the "Run Simulation"
button to submit the form and trigger the simulation.

When the form is submitted, the data is sent to the Flask backend, which processes the input and
calculates the Otto cycle results.

Figure 6.1 Index page

24
6.3 Results Page ([Link])

The results page displays the simulation results, including performance metrics, input
parameters, and two interactive visualizations. These visualizations are rendered using Plotly,
and they allow the user to interact with the graphs by zoom, hover for values, etc.

Code Snippet from [Link]:

html

{% extends "[Link]" %}

{% block content %}
<div class="row mb-4">
<div class="col">
<div class="card">
<div class="card-header">
<h2>Simulation Results</h2>
</div>
<div class="card-body">
<div class="row">
<div class="col-md-6">
<h4>Performance Metrics</h4>
<ul class="list-group">
<li class="list-group-item d-flex justify-content-between align-items-center">
Thermal Efficiency
<span class="badge bg-primary rounded-pill">{{
"%.2f"|format([Link] * 100) }}%</span>
</li>
<li class="list-group-item d-flex justify-content-between align-items-center">
Net Work Output
<span class="badge bg-primary rounded-pill">{{
"%.2f"|format(results.net_work) }} J</span>
</li>
<li class="list-group-item d-flex justify-content-between align-items-center">
Heat Added
<span class="badge bg-primary rounded-pill">{{
"%.2f"|format(results.heat_added) }} J</span>
</li>
</ul>
</div>
<div class="col-md-6">
<h4>Input Parameters</h4>
<ul class="list-group">
{% for key, value in [Link]() %}
<li class="list-group-item d-flex justify-content-between align-items-center">
{{ key|replace('_', ' ')|title }}

25
<span class="badge bg-secondary rounded-pill">{{ value }}</span>
</li>
{% endfor %}
</ul>
</div>
</div>
</div>
</div>
</div>
</div>

<div class="row mb-4">


<div class="col">
<div class="card">
<div class="card-header">
<h3>PV Diagram</h3>
</div>
<div class="card-body">
<div id="pv-diagram">
{{ pv_graph|safe }}
</div>
</div>
</div>
</div>
</div>

<div class="row">
<div class="col">
<div class="card">
<div class="card-header">
<h3>Pressure vs. Crank Angle</h3>
</div>
<div class="card-body">
<div id="pressure-angle-diagram">
{{ pressure_angle_graph|safe }}
</div>
</div>
</div>
</div>
</div>

<div class="text-center mt-4">


<a href="{{ url_for('index') }}" class="btn btn-secondary">Run New Simulation</a>
</div>
{% endblock %}

26
Key Features:

 Performance Metrics: The simulation results, such as thermal efficiency, net work output,
and heat added, are displayed in a list format with badges for easy comparison.

 Input Parameters: The parameters entered by the user are displayed in a list, allowing
users to quickly review the values they entered.

 Interactive Plotly Graphs: The PV diagram and pressure-angle diagram are rendered
using Plotly. The {{ pv_graph|safe }} and {{ pressure_angle_graph|safe }} placeholders
embed the interactive charts directly into the HTML page.

 Navigation: A button at the bottom of the page allows users to return to the index page
and run a new simulation with different parameters.

6.4 Interactive Visualizations

The visualizations are the key feature of the results page. These graphs help users visually
understand the thermodynamic processes of the Otto cycle.

Code Snippet for PV Diagram:

python

def create_pv_diagram(cycle):
fig = [Link]()

fig.add_trace([Link](
x=cycle.compression_volumes,
y=cycle.compression_pressures / 1000,
mode='lines',
name='Isentropic compression (1-2)',
line=dict(color='red', width=2)
))

fig.add_trace([Link](
x=[cycle.v2, cycle.v3],
y=[cycle.p2 / 1000, cycle.p3 / 1000],
mode='lines',
name='Constant volume heat addition (2-3)',
line=dict(color='blue', width=2)
))

fig.add_trace([Link](
x=cycle.expansion_volumes,

27
y=cycle.expansion_pressures / 1000,
mode='lines',
name='Isentropic expansion (3-4)',
line=dict(color='green', width=2)
))

fig.add_trace([Link](
x=[cycle.v4, cycle.v1],
y=[cycle.p4 / 1000, cycle.p1 / 1000],
mode='lines',
name='Constant volume heat rejection (4-1)',
line=dict(color='purple', width=2)
))

return fig.to_html(full_html=False)

This function generates an interactive PV diagram that users can explore.

28
Chapter -7 Results and Discussion

This section presents an analysis of the results obtained from the Otto cycle simulation. Key
performance indicators—including thermal efficiency, net work output, and heat input—are
evaluated in detail. The impact of varying input parameters, such as compression ratio, bore
diameter, and stroke length, on these performance metrics is examined. Furthermore, the
pressure-volume and pressure–crank angle diagrams are used to analyze the thermodynamic
behavior and efficiency of the Otto cycle.

7.1. Simulation Results

The results are derived from running simulations for various sets of input parameters. Below are
the key performance metrics calculated by the simulator for different engine configurations:

 Thermal Efficiency: The ratio of net work output to the heat added to the system. It
indicates the proportion of energy that is converted into useful work in the engine.

 Net Work Output: The total work done by the engine, which is the difference between the
work done during expansion and the work required for compression.

 Heat Added: The energy required to raise the temperature of the air-fuel mixture during
the heat addition process.

For each simulation, we compute these values based on the user's input parameters, and the
results are presented as follows:

Performance Metrics:

 Thermal Efficiency: Typically ranges from 25% to 30% for a gasoline engine, depending
on the compression ratio and other factors.

 Net Work Output: The net work output increases with the compression ratio, as a higher
compression ratio allows for more efficient expansion and work generation.

 Heat Added: The heat added depends on the difference between the maximum
temperature and the temperature at the end of compression. Higher temperatures lead to
greater heat added to the system.

The figure 6.1 shows the final output of the simulation

29
Figure 7.1 Final output of the simulation

30
7.2 Effect of Compression Ratio

One of the most significant parameters in the Otto cycle is the compression ratio. The
compression ratio is the ratio of the cylinder's volume at the bottom of the stroke to the volume
at the top of the stroke.

Effect on Thermal Efficiency:

As the compression ratio increases, the thermal efficiency improves, but only up to a point. This
is due to the relationship:

Where:

 η is the thermal efficiency,

 CR is the compression ratio,

 γ is the specific heat ratio .

Effect on Work Output:

With a higher compression ratio, the engine generate more net work because the air-fuel mixture
is compressed to a smaller volume, resulting in higher pressure and temperature. This allows for
greater expansion work during the expansion stroke.

Sample Results for Different Compression Ratios:

 CR = 9: Thermal efficiency = 28%, Net work = 350 J, Heat added = 1200 J

 CR = 12: Thermal efficiency = 31%, Net work = 420 J, Heat added = 1400 J

 CR = 15: Thermal efficiency = 34%, Net work = 480 J, Heat added = 1600 J

These results demonstrate that increasing the compression ratio increases both the thermal
efficiency and the net work output, but the effect starts diminishing after a certain point.

31
7.3 Effect of Bore and Stroke

The bore and stroke of an engine determine the engine's displacement and, consequently, the
amount of air-fuel mixture that can be compressed and expanded during each cycle.

 Bore: The diameter of the engine's cylinder. A larger bore allows for more air-fuel
mixture to be compressed, leading to a larger swept volume.

 Stroke: The distance traveled by the piston inside the cylinder. A longer stroke results in
a larger displacement volume, which also increases the total amount of work done during
the expansion stroke.

Effect on Work Output:

Increasing the bore or stroke increases the total volume of air-fuel mixture that can be processed
in each cycle. This allows the engine to generate more work overall, as more energy is extracted
during the expansion stroke. However, the effect on work output is typically less significant than
that of increasing the compression ratio.

Effect on Heat Added and Efficiency:

Larger bore and stroke sizes result in larger volumes of air-fuel mixture, leading to more heat
being added to the system. While the thermal efficiency improves slightly due to a larger volume
for compression and expansion, it is not as sensitive to bore and stroke changes as it is to
compression ratio.

7.4 Pressure-Volume Diagram Analysis

The PV diagram provides a visual representation of the four key processes in the Otto cycle:

 Compression (2-3): As the piston moves up, the volume decreases and pressure increases.
The process is adiabatic, meaning no heat is exchanged.

 Heat Addition (3-4): At constant volume, the pressure rises sharply due to the ignition of
the air-fuel mixture. This process is characterized by a rapid temperature increase.

 Expansion (4-5): The combustion gases expand, performing work on the piston. As the
volume increases, the pressure decreases in an adiabatic process.

 Heat Rejection (5-6): At constant volume, the exhaust gases are expelled from the engine.
The pressure decreases, and the cycle repeats.

The area enclosed by the PV curve represents the total work done during the cycle. The work
done by the engine is the area under the expansion curve, and the work done on the gas is the
area under the compression [Link] difference between these areas gives the net work output.

32
Key Observations from PV Diagrams:

 Compression Stroke: A higher compression ratio shifts the compression curve to the
right, increasing the pressure and temperature.

 Expansion Stroke: With higher compression ratios, the expansion stroke covers a larger
area, resulting in greater work output.

 Constant Volume Processes: The sharp rise and fall in pressure during the heat addition
and heat rejection processes reflect the quick ignition and expulsion of exhaust gases.

7.5 Pressure-Angle Diagram Analysis

The pressure-angle diagram plots the pressure of the engine against the crank angle. It provides
insight into how the pressure varies throughout the engine cycle, including during compression,
heat addition, expansion, and heat rejection.

Key Observations:

 Compression Phase (180° to 0°): Pressure increases as the piston compresses the air-fuel
mixture.

 Heat Addition (3-4): Pressure jumps significantly at 0° due to ignition.

 Expansion Phase (0° to 180°): Pressure decreases as the combustion gases expand, and
the piston moves down.

 Heat Rejection (5-6): Pressure decreases as the exhaust gases are expelled.

7.6 Discussion

The Otto cycle simulator allows for the exploration of various engine configurations and
provides valuable insights into the relationship between engine parameters and performance. The
simulation shows that:

 Increasing the compression ratio results in higher thermal efficiency and net work output,
but with diminishing returns at very high CR values.

 Larger bore and stroke lead to increased work output, but the effect is not as pronounced
as changes in the compression ratio.

 The PV and pressure-angle diagrams provide a clear visualization of the engine’s


thermodynamic processes and work output.

The findings align with classical thermodynamic principles, and the simulation provides a
powerful tool for understanding engine performance.
33
Chapter- 8 Conclusion

8.1 Summary of Findings

The Otto Cycle Simulator provides a detailed and interactive way to explore the thermodynamic
behavior of an internal combustion engine. This simulation allows users to input various engine
parameters, such as the bore, stroke, compression ratio, and initial conditions , to observe how
they affect key performance metrics like thermal efficiency, net work output, and heat added.

Analyzing the simulation results reveals several important findings :

 Compression Ratio: The compression ratio has a significant impact on the engine's
performance. As CR increases, both thermal efficiency and net work output improve.
However, after a certain point, the gains become less pronounced, and practical
limitations may impose an upper limit on the CR.

 Bore and Stroke: Increasing the bore or stroke leads to higher work output, as larger
volumes of air-fuel mixture are processed. However, the effect on thermal efficiency is
less sensitive to bore and stroke changes than it is to compression ratio adjustments.

 Thermal Efficiency: The thermal efficiency of an ideal Otto engine is primarily


determined by the compression ratio and is constrained by the laws of thermodynamics.

8.2 Implications for Engine Design

This simulation provides useful insights for engineers and designers in optimizing engine
performance:

 Higher Compression Ratios: Engineers can use higher compression ratios to improve
engine efficiency. However, practical considerations, such as the risk of engine knocking,
must be accounted for. Modern engines often use technologies like variable valve timing
and turbocharging to mitigate the risks associated with high CRs.

 Bore and Stroke Optimization: While increasing the bore or stroke can lead to more work
output, engine size, weight, and fuel efficiency must also be considered. Designers must
strike a balance between these factors when choosing the optimal engine dimensions.

 Fuel Efficiency: The simulation highlights the importance of optimizing the


thermodynamic processes to maximize fuel efficiency. For example, improving the
thermal efficiency of an engine by optimizing the compression ratio can reduce fuel
consumption while maintaining the same power output.

34
8.3 Limitations of the Model

While the Otto Cycle Simulator provides valuable insights, there are a few limitations to
consider:

 Ideal Assumptions: The simulation assumes an idealized Otto cycle, which does not
account for real-world factors such as friction, heat losses, and imperfect combustion.
These factors can significantly reduce the actual performance of an engine.

 Simplified Kinematics: The kinematic model used in the simulation is a simplified


version that assumes ideal piston motion. In reality, the piston experiences more complex
forces, including friction and inertia.

 Specific Heat Ratio: The value of γ is assumed to be constant. However, γ can vary with
temperature and pressure in real-world conditions, affecting the accuracy of the results.

8.4 Future Work

This project offers several opportunities for future development:

1. Realistic Engine Models: Enhancing the simulation by adding realistic engine dynamics
such as friction, valve timing, and combustion efficiency improves accuracy and
performance predictions. A more detailed model would provide a closer approximation of
real engine performance.
2. Hybrid Engine Cycles: Future work could include simulations of other thermodynamic
cycles used in engines, such as the Diesel cycle or Atkinson cycle. A comparison of
different cycles could help optimize engine designs for specific applications.

3. Fuel Type and Composition: The simulation could be extended to account for different
fuel types and their effects on thermodynamic properties. This would be particularly
useful for studying alternative fuels and their impact on engine efficiency.

4. Multi-Cylinder Engines: Currently, the simulation models a single-cylinder engine.


Future versions could simulate multi-cylinder engines, which would provide a more
comprehensive view of engine behavior and performance.

8.5 Concluding Remarks

In conclusion, the Otto Cycle Simulator offers a valuable tool for understanding the fundamental
thermodynamics of internal combustion engines. By providing detailed simulations and
visualizations, the tool enables users to explore how different parameters influence engine
performance. It serves as both an educational resource and a design tool for engineers seeking to
optimize engine efficiency. With further enhancements and the inclusion of more realistic
models, this tool could become a powerful resource for advanced engine analysis and design.

35
Chapter- 9 References

Books:

1. Van Wylen, G. J., & Sonntag, R. E. (2008). Fundamentals of Thermodynamics (7th ed.).
John Wiley & Sons.

o This book provides a solid foundation in thermodynamics, with detailed


explanations of the Otto cycle and its thermodynamic processes.

2. Cengel, Y. A., & Boles, M. A. (2006). Thermodynamics: An Engineering Approach (6th


ed.). McGraw-Hill.

o A widely used textbook that covers the theory behind thermodynamic cycles,
including the Otto cycle, and is helpful for understanding the concepts of work,
heat, and efficiency.

Research Papers:

1. Heywood, J. B. (1988). Internal Combustion Engine Fundamentals. McGraw-Hill.

o A comprehensive resource for understanding the principles of internal combustion


engines, including the Otto cycle, engine kinematics, and performance analysis.

2. Hodges, A. (2001). Performance and Emissions of the Otto Cycle Engine: A Review.
Journal of Energy Resources Technology, 123(2), 109-118.

Software Libraries:

1. Flask Documentation. (2025). Flask Web Framework Documentation. Retrieved from


[Link]

o The official documentation for Flask, the web framework used to build the front-
end interface for the Otto cycle simulator.

2. SciPy Documentation. (2025). SciPy Library Documentation. Retrieved from


[Link]

36
o Documentation for the SciPy library, particularly the simpson integration method
used for calculating work in the simulation.

Miscellaneous:

1. Python Software Foundation. (2025). Python Programming Language. Retrieved from


[Link]

o The official Python programming language website, which includes


documentation and resources for Python development.

2. Bootstrap Documentation. (2025). Bootstrap Front-End Framework. Retrieved from


[Link]

o The official documentation for Bootstrap, the front-end framework used to style
the user interface of the simulator.

37

You might also like