All Courses
All Courses
Courses by Software
Courses by Semester
Courses by Domain
Tool-focused Courses
Machine learning
POPULAR COURSES
Success Stories
AIM: To write a program in PYTHON to solve the Otto Cycle and Plot the PV Diagram. The code should create a PV diagram Find the 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…
Ashwin Deepak
updated on 31 Aug 2021
To write a program in PYTHON to solve the Otto Cycle and Plot the PV Diagram.
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 following describes what occurs during each step on the PV diagram, in which the combustion of the working fluid gasoline and air (oxygen), changes the motion in the piston:
Process 1 to 2: During this phase the piston will be drawn up, so it can compress the fuel-air mixture that entered the chamber. The compression causes the mixture to increase slightly in pressure and temperature—however, no heat is exchanged. In terms of thermodynamics, this is referred to as an adiabatic process. When the cycle reaches point 2, that is when the fuel is met by the spark plug to be ignited.
Process 2 to 3: This is where combustion occurs due to the ignition of fuel by the spark plug. The combustion of the gas is complete at point 3, which results in a highly pressurized chamber that has a lot of heat (thermal energy). In terms of thermodynamics, this is referred to as an isochoric process.
Process 3 to 4: The thermal energy in the chamber as a result of combustion is used to do work on the piston—which pushes the piston down—increasing the volume of the chamber. This is also known as the power stoke because it is when the thermal energy is turned into motion to power the machine or vehicle.
Purple line (Process 4 to 1 and exhaust phase): From process 4 to 1, all waste heat is expelled from the engine chamber. As the heat leaves the gas, the molecules lose kinetic energy causing the decrease in pressure. Then the exhaust phase occurs when the remaining mixture in the chamber is compressed by the piston to be "exhausted" out, without changing the pressure.
import math # Library for math functions
import matplotlib.pyplot as plt # Library for plotting functions
# Function Definition
def Engine_kinematics(bore,stroke,con_rod,cr,start_crank,end_crank):
a=stroke/2
R=con_rod/a
#volume parameters
V_S=(math.pi/4)*(pow(bore,2))*stroke
V_C=V_S/(cr-1)
V1=V_C+V_S
sc=math.radians(start_crank)
ec=math.radians(end_crank)
num_values=100 #no. of points
dtheta=(ec-sc)/(cr-1)
V=[] #empty array
for i in range(0,num_values):
'''Main equation is divided into terms term1,term2,term3
V/Vc = 1+0.5*[Rc-1]*[R+1-cos(theta)]-[[R^2-sin(theta)^2]^0.5]
'''
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) #append is used to retain each values
return V # Returning value of V
#Input parameters
T1=600
P1=101325
gamma=1.4
T3=2400
#geometric parameter
bore=0.1
stroke=0.1
con_rod=0.15
cr=10
#Stage 1
V_S=(math.pi/4)*(pow(bore,2))*stroke
V_C=V_S/(cr-1)
V1=V_C+V_S
#Stage 2 PV^GAMMA=C
V2=V_C
P2=P1*(pow(V1,gamma)/pow(V2,gamma))
RHS=(P1*V1)/T1
term2=(P2*V2)/RHS
V_compression=Engine_kinematics(bore,stroke,con_rod,cr,180,0) #Function call - Compression stroke
CONSTANT=P1*pow(V1,gamma)
P_compression=[]
for v in V_compression:
P_compression.append(CONSTANT/pow(v,gamma))
#Stage 3
V3=V2
#p3v3/term3=p2v2/term2
P3=(T3*RHS)/V3
V_expansion=Engine_kinematics(bore,stroke,con_rod,cr,0,180) #Function call - Expansion stroke
CONSTANT=P3*pow(V3,gamma)
P_expansion=[]
for v in V_expansion:
P_expansion.append(CONSTANT/pow(v,gamma))
#STAGE4
V4=V1
#[p3v3^GAMMA] = [p4v4^GAMMA]
P4=P3*(pow(V3,gamma)/pow(V4,gamma))
#[p4v4/t4] = [p3v3/term3]
T4=P4*V4/RHS
def cal_eff(cr,gamma): #Function for Thermal Efficiency of Engine
Thermal_Eff = (1-(1/pow(cr,gamma-1)))*100
return Thermal_Eff
s=cal_eff(12,1.4) #Function call for Thermal Efficiency cal.
print('thermal efficiency= ',s)
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.xlabel('Volume')
plt.ylabel('Pressure')
plt.title('Otto cycle')
plt.grid()
plt.show()
Leave a comment
Thanks for choosing to leave a comment. Please keep in mind that all the comments are moderated as per our comment policy, and your email will not be published for privacy reasons. Please leave a personal & meaningful conversation.
Other comments...
Solving second order ODE's using PYTHON Programming
AIM: To write a program in PYTHON that solves the Second order ODE corresponding to motion of a simple pendulum and plot its Angular Displacement and Angular Velocity. Create an animation of the motion of pendulum by simulating the motion between 0-20sec with angular displacement = 0, angular velocity = 3rad/sec at time…
04 Sep 2021 08:24 AM IST
OTTO CYCLE SOLVING USING PYTHON
AIM: To write a program in PYTHON to solve the Otto Cycle and Plot the PV Diagram. The code should create a PV diagram Find the 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…
31 Aug 2021 08:14 PM IST
Meshing of Hood using Hypermesh
Aim : The aim is to generate a mid-surface and to create a mesh for the given Hood Model. FILE : HOOD_MODEL Quality Criteria : S.N Quality Criteria Value 1 Aspect Ratio 5 2 Skewness 45 3 Warping 15 4 Taper 0.5 5 Min. Length 2 Units 6 Max. Length 8 Units 7 Min angle Quad 45…
26 Apr 2021 06:53 PM IST
Static Structural Simulation of Bending of iPhone (ANSYS WORKBENCH)
Aim : Simulate the bending of Iphone as per the given cases : CASE 1 : Simulate the model with the given conditions CASE 2 : Move the bottom fingers from their defined position to the given position X= 22.5mm & Z= 10mm and obtain the results for the simulation. Also define the S-N curve for…
14 Apr 2021 02:47 PM IST
Related Courses
Skill-Lync offers industry relevant advanced engineering courses for engineering students by partnering with industry experts.
© 2025 Skill-Lync Inc. All Rights Reserved.