Otto Cycle using Python

OBJECTIVE - To write a code for P_V diagram of an Otto cycle and calculate thermal efficiency




  • Initially state variables p1,t1,t3 and gamma are assumed.
  • Necessary Engine geometric parameters are also assumed.



  • First the required inputs are given and with the help of the inputs sept volume(vs) and clearance volume(vc) are calculated.
  • Then volume at state point 1 and 2 are calculated using the formula given below.

V1=vs+vs   v2=vc

  • Then state variables at state point 2,3 and 4 are caluclated and stored respectively .
  • To capture the processes on the final P-V plot,a function named piston_kinematics is used,in which the relation between the volume covered by the piston in the combustion chamber during the compression and expansion processes and the clearance volume is expressed as a function of crank angle(theta).The relation is given by:


  =1+1/2(rc-1){R+1-cosө -(R2-sin2ө)1/2}


Where ,

             V= volume covered by the piston

             Vc=clearance volume

              rc=compression ratio


             R= length of connecting rod*2/stroke length

  • After obtaining the respective values of V and P for both compression and expansion processes.Values of P-compression are stored in empty array.
  • All the state points are plotted on P-V diagram, with (Pcompression,Vcompression) and (Pexpansion ,Vexpansiom) plotted instead of (p3 v3) and (p4 v4).
  • Thermal Efficiency also calculated.
# Otto Cycle Simulator
import math
import matplotlib.pyplot as plt
p1 = 101325 
t1 = 500
gamma = 1.4
t3 = 2300
#geometric parameters
bore = 0.1
stroke = 0.1
con_rod = 0.15
cr = 12 

#Volume calculation
v_s = (math.pi/4)*pow(bore,2)*stroke
v_c = v_s/(cr-1)
v1 = v_s + v_c

def engine_kinematics(bore, stroke, con_rod, cr, start_crank, end_crank):

 a = stroke/2
 R = con_rod/a
 V_s = math.pi*(1/4)*pow(bore,2)*stroke
 V_c = V_s/(cr-1)

 sc = math.radians(start_crank)
 ec = math.radians(end_crank)

 numvalues = 100
 dtheta = (ec-sc)/(numvalues-1)
 V = []
 for i in range (0,numvalues):
			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)
			return V

#state point 2
v2 = v_c
p2 = p1*pow(v1,gamma)/pow(v2,gamma)
rhs = p1*v1/t1
t2 = p2*v2/rhs
V_compression = engine_kinematics(bore, stroke, con_rod, cr, 180, 0)
constant1 = p1*pow(v1,gamma)
P_compression = []
for v in V_compression:

#state point 3
v3 = v2
rhs = p2*v2/t2
p3 = rhs*t3/v3
V_expansion = engine_kinematics(bore, stroke, con_rod, cr, 0, 180)
constant2 = p3*pow(v3,gamma)
P_expansion = []
for v in V_expansion:
v4 =v1
p4 = p3*pow(v3,gamma)/pow(v4,gamma)
t4 = p4*v4/rhs  

#Thermal Efficiency
Thermal_eff = (1-((t4-t1)/(t3-t2)))*100
print('Thermal efficiency =')

plt.plot(V_compression, P_compression)
plt.plot(V_expansion, P_expansion)




Thus the code was written and P-V diagram was plotted and thermal efficiency was calculated using PYTHON.



Projects by Habishek Umapathy

AIM – To run a pipe flow simulation with an inlet Reynolds number of 100, 1000 and 10000. For each of these cases do the following Place the line probes at 95%, 90%, 85%of the pipe length. Compare the normalized velocity profile at each of these locations. N Read more

OBJECTIVE – We have to write the script which should take column numbers as the input and plot the respective columns as separate images. The plot labels should be extracted from the file. If there is a request for a plot between column 1(crank angle) and column 8 Read more

  OBJECTIVE – To write a program to perform curve fitting.   Curve Fitting is the process of constructing a curve or mathematical functions, which possess the closest proximity to the real series of data. By curve fitting, we can mathematically constr Read more

The Newton Raphson method is an iterative technique that is used to find out the roots of a real valued function. It uses the idea that a continuous and differentiable function can be approximated by a straight-line tangent to it. In this case Newton Raphson method is Read more

OBJECTIVE – To write a program to simulate the transient behaviour of a simple pendulum and to create an animation of its motion.   PROCEDURE – In Engineering, ODE is used to describe the transient behavior of a system. A simple example is a pendulum Read more

OBJECTIVE - 1. Write a function that extracts the 14 co-efficient and calculates the enthalpy, entropy and specific heats for all the species in the data file. Calculate the molecular weight of each species and display it in the command window. Plot the Cp, Ent Read more

OBJECTIVE - Write a code in MATLAB to optimise the stalagmite function and find the global maxima of the function. PROCEDURE- The genetic algorithm is a method for solving both constrained and unconstrained optimization problems that is based on natural sele Read more

OBJECTIVE – To write code to fit a linear and cubic polynomial for the Cp data and plot the linear and cubic fit curves along with the raw data points.   PROCEDURE – Curve Fitting is the process of constructing a curve or mathematical functions, whic Read more


The End