All Courses
All Courses
Courses by Software
Courses by Semester
Courses by Domain
Tool-focused Courses
Machine learning
POPULAR COURSES
Success Stories
objective: To code a python program to obtain the presssure-volume curve of a four-stroke si engine. (otto - cycle) Otto cycle: 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.…
Tilak S
updated on 07 May 2020
objective:
To code a python program to obtain the presssure-volume curve of a four-stroke si engine. (otto - cycle)
Otto cycle:
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 Otto cycle is a description of what happens to a mass of gas as it is subjected to changes of pressure, temperature, volume, the addition of heat, and removal of heat. The mass of gas that is subjected to those changes is called the system. The system, in this case, is defined to be the fluid (gas) within the cylinder. By describing the changes that take place within the system, it will also describe in the inverse, the system\'s effect on the environment. In the case of the Otto cycle, the effect will be to produce enough net work from the system so as to propel an automobile and its occupants in the environment.
The Otto cycle is constructed from:
Top and bottom of the loop: a pair of quasi-parallel and isentropic processes (frictionless, adiabatic reversible).
Left and right sides of the loop: a pair of parallel isochoric processes (constant volume).
The isentropic process of compression or expansion implies that there will be no inefficiency (loss of mechanical energy), and there be no transfer of heat into or out of the system during that process. The cylinder and piston are assumed to be impermeable to heat during that time. Work is performed on the system during the lower isentropic compression process. Heat flows into the Otto cycle through the left pressurizing process and some of it flows back out through the right depressurizing process. The summation of the work added to the system plus the heat added minus the heat removed yields the net mechanical work generated by the system.
Processes in otto cycle:
The processes are described by:
Process 0–1 a mass of air is drawn into piston/cylinder arrangement at constant pressure.
Process 1–2 is an adiabatic (isentropic) compression of the charge as the piston moves from the bottom dead center (BDC) to top dead center (TDC).
Process 2–3 is a constant-volume heat transfer to the working gas from an external source while the piston is at top dead center. This process is intended to represent the ignition of the fuel-air mixture and the subsequent rapid burning.
Process 3–4 is an adiabatic (isentropic) expansion (power stroke).
Process 4–1 completes the cycle by a constant-volume process in which heat is rejected from the air while the piston is at bottom dead center.
Process 1–0 the mass of air is released to the atmosphere in a constant pressure process.
The Otto cycle consists of isentropic compression, heat addition at constant volume, isentropic expansion, and rejection of heat at constant volume. In the case of a four-stroke Otto cycle, technically there are two additional processes: one for the exhaust of waste heat and combustion products at constant pressure (isobaric), and one for the intake of cool oxygen-rich air also at constant pressure; however, these are often omitted in a simplified analysis. Even though those two processes are critical to the functioning of a real engine, wherein the details of heat transfer and combustion chemistry are relevant, for the simplified analysis of the thermodynamic cycle, it is more convenient to assume that all of the waste-heat is removed during a single volume change.
The python code is attached below and the steps used to obtain the code is mentioned in comments before each line:
\"\"\"
Otto -cycle program
\"\"\"
import math
import matplotlib.pyplot as plt
#defining the inputs
#a. pressure and temperature at state point1
p1 = 101325
t1 = 500
t3 = 2300
gamma = 1.4
#geometric specifications of the engine cylinder
bore = 0.1
stroke = 0.1
con_rod = 0.15
cr = 12
\"\"\"
where,
con_rod = conneting rod length
cr = compression ratio
\"\"\"
#volume computation at state point 1
v_s = (math.pi)*(1/4)*pow(bore,2)*stroke #(swept volume)
v_c = v_s/(cr-1) #(clearance volume)
#w.k.t volume at state point 1 is the sum of swept volume and clearance volume, Therefore
v1 = v_c + v_s
#volume(v2), pressure(p2) and temperature(t2) computation at state point 2
# At TDC volume is equal to clearance volume, Therefore
v2 = v_c
#according to ideal gas law, p2v2^gamma = p1v1^gamma, therefore
p2 = p1*pow(v1,gamma)/(pow(v2,gamma))
#according to ideal gas law, p2v2/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))
#volume(v3), pressure(p3) and temperature(t3) computation at state point 3
v3 = v2 #(w.k.t it is a constant volume heat addition process)
#according to ideal gas law, p3v3/t3 = p2v2/t2 | rhs = p2v2/t2 | p3v3/t3 = rhs | 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))
#volume(v4), pressure(p4) and temperature(t4) computation at state point 4
v4 = v1
#according to ideal gas law, p4v4^gamma = p3v3^gamma, therefore
p4 = p3*pow(v3,gamma)/(pow(v4,gamma))
#according to ideal gas law, p4v4/t4 = p3v3/t3 | rhs = p3v3/t3 | p4v4/t4 = rhs | t4 = p4v4/rhs
t4 = p4*v4/rhs
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 (m^3)\')
plt.ylabel(\'Pressure (N/m^2)\')
plt.title(\'PV diagram\')
plt.show()
# Finding Thermal efficiency of Otto cycle for the given data
t_eff = (1-pow((1/cr),(gamma-1)))*100
print(\'P1 = \',p1)
print(\'P2 = \',p2)
print(\'P3 = \',p3)
print(\'P4 = \',p4)
print(\'V1 = \',v1)
print(\'V2 = \',v2)
print(\'V3 = \',v3)
print(\'V4 = \',v4)
print(\'T1 = \',t1)
print(\'T2 = \',t2)
print(\'T3 = \',t3)
print(\'T4 = \',t4)
print(\'Thermal efficiency = \',t_eff)
The above shown code can generate the p-v curve by obtaining the pressure and volume arrays generated by a user-defined function engine kinematics shown below:
Code for defining the function engine kinematics:
\"\"\"
engine kinematics function
\"\"\"
def engine_kinematics(bore, stroke, con_rod, cr ,start_crank, end_crank):
#geometric specifications of the engine cylinder
a = stroke/2
R = con_rod/a
\"\"\"
where,
con_rod = conneting rod length
cr = compression ratio
a = crank pin radius
\"\"\"
#volume parameters
v_s = (math.pi)*(1/4)*pow(bore,2)*stroke #(swept volume)
v_c = v_s/(cr-1) #(clearance volume)
sc = math.radians(start_crank)
ec = math.radians(end_crank)
num_values = 100
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
The below formula is used to obtain the volume array \'v\'
this formula is split up into three terms for convenience purposes as shown in the code.
Output:
Thus the python program for generating the p-v curve for an otto cycle engine is coded. The thermal efficiency of the engine is found to be 62.99%.
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...
Week 6
Objective: The goal is to clean the surface geometry to avoid errors and carry on the solid meshing (3-D) process and provide connections using connection managers that accurately captures the input domain geometry(side door) with high-quality cells so as to make subsequent calculations intractable.…
23 Jul 2020 03:36 PM IST
Week 5
Objective: The goal is to clean the surface geometry to avoid errors and carry on the solid meshing (3-D) process and create a mesh that accurately captures the input domain geometry(rear view mirror) with high-quality cells so as to make subsequent calculations intractable. The…
13 Jul 2020 02:14 PM IST
Mid-surface mesh generation of plastic bottle cap using ANSA
Objective: The goal is to clean the surface geometry to avoid errors and carry on the hemming process and create a mesh that accurately captures the input domain geometry(A plastic bottle cap) with high-quality cells so as to make subsequent calculations intractable. The above-said…
23 Jun 2020 09:43 AM IST
Analysis of air standard cycle with python
objective: To code a python program to obtain the presssure-volume curve of a four-stroke si engine. (otto - cycle) Otto cycle: 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.…
07 May 2020 09:28 AM IST
Related Courses
0 Hours of Content
Skill-Lync offers industry relevant advanced engineering courses for engineering students by partnering with industry experts.
© 2025 Skill-Lync Inc. All Rights Reserved.