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 an Otto cycle and make plots for it. OBJECTIVE:1. To solve and find out different state variables in the Otto cycle and plot its a p-V diagram.2. To calculate the thermal efficiency of the given Otto cycle. Otto cycle: An Otto cycle is an idealized thermodyanamic cycle that describes…
Amol Anandrao Kumbhar
updated on 30 Mar 2021
AIM:
To write a program in Python to solve an Otto cycle and make plots for it.
OBJECTIVE:
1. To solve and find out different state variables in the Otto cycle and plot its a p-V diagram.
2. To calculate the thermal efficiency of the given Otto cycle.
Otto cycle:
Engine Parameters:
Bore and Stroke:
Connecting rod:
Compression rartio:
Crank radius:
Swept Volume:
Clearance Volume:
0 to 1 - Suction stroke:
1 to 2 - Isentropic compression process:
2 to 3 - Constant volume heat addition:
3 to 4 - Isentropic expansion process:
4 to 1 - Constant volume heat rejection:
1 to 0 - Exhaust stroke:
Since processes 1-2 and 3-4 are adiabatic processes, the heat transfer during the cycle takes place only during processes 2-3and 4-1 respectively. Therefore, the thermal efficiency
can be written as,
Following ideal gas equations are used to calculate the pressure and temperature:
Volume of the cylinder at any given crank angle is given by the expression:
Where,
V = Volume of the cylinder at any given instance
Vc = Clearance volume
rc = Compression ratio
R = Ratio of connecting rod to the crank radius
θ = Crank angle
Program to calculate the engine efficiency and plot the otto cycle:
# Program to simulate the otto cycle
import math
import matplotlib.pyplot as plt
def engine_kinematics(bore,stroke,con_rod,cr,start_crank,end_crank):
#geometric parameters
#(a) is the Crank pin radius
#R - Constant to know the crank angle and piston movement
a = stroke/2
R = con_rod/a
#volume parameters
#swept Volume
#Clearence Volume
v_s = (math.pi/4)*pow(bore,2)*stroke
v_c = v_s/(cr-1)
sc = math.radians(start_crank)
ec = math.radians(end_crank)
# number of theta between start & end crank
num_values = 50
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
# Inputs
p1 = 101325 # in N/m^2
t1 = 500 # in Kelvin
gamma = 1.4
t3 = 2300 # in Kelvin
# geometric parameters
bore = 0.1
stroke = 0.1
con_rod = 0.15
cr = 12
# Volume computation
v_s = (math.pi/4)*pow(bore,2)*stroke
v_c = v_s/(cr-1)
v1 = v_s + v_c
# state point 2
v2 = v_c
# p1v1^gamma = p2v2^gamma
p2 = p1 * pow(v1,gamma)/pow(v2,gamma)
# calculate t2 | p2v2/t2 = p1v1/t1 | rhs = p1v1/t1 | p2v2/t2 = 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)))
# State point 3
v3 = v2
# calculate p3 | p3v3/t3 = p2v2/t2 = rhs
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)))
# State point 4
v4 = v1
#calculate p4 | p4v4^gamma = p3v3^gamma
p4 = p3*pow(v3,gamma)/pow(v4,gamma)
# calculating t4
t4 = p4*v4/rhs
# Calculating the thermal efficiency of the otto cycle
p = gamma-1
eta = (1 - 1/(pow(cr,p)))*100
print('The thermal efficiency of the otto cycle is:',eta)
Efficiency = 1-((t4-t1)/(t3-t2))
print('The Efficiency of the otto cycle for the given input condition is:',Efficiency)
print('At state point 1:', 'Pressure(p1) =',p1,'; temperature(t1) =',t1, '; volume(v1) =',v1)
print('At state point 2:', 'Pressure(p2) =',p2,'; temperature(t2) =',t2, '; volume(v2) =',v2)
print('At state point 3:', 'Pressure(p3) =',p3,'; temperature(t3) =',t3, '; volume(v3) =',v3)
print('At state point 4:', 'Pressure(p4) =',p4,'; temperature(t4) =',t4, '; volume(v4) =',v4)
# plotting the results
plt.plot(V_compression,P_compression, label="1 to 2 - Isentropic compression process")
plt.plot([v2,v3],[p2,p3], label="2 to 3 - Constant volume heat addition")
plt.plot(V_expansion,P_expansion, label = "3 to 4 - Isentropic expansion process")
plt.plot([v4,v1],[p4,p1],label ="4 to 1 - Constant volume heat rejection")
plt.legend()
plt.grid()
plt.xlabel('Volume in m^3')
plt.ylabel('Pressure in Pascal')
plt.title('PV Diagram of Otto Cycle')
plt.show()
Procedure :
* Firstly we are assingning the values for the input parameters of the first process in otto cycle,like pressure, temperature,gamma. The temperature at third process, which is the heat input given during combustion is assigned.
* Then we are giving the engine geomentric values that is the dimensions of the cylinder and some of its components in meter.
* After that we are we are calculating the swept volume ,clearence volume at volume at the 1st & 2nd process as v1 and v2.
* Since the process 1 to 2 is isentropic, we can use this expression to calculate the pressure (p2) at process 2,
p1 * v1^gamma = p2 * v2^gamma
p2 = p1 * v1^gamma / v2^gamma
*After calulation the pressure and volume at 2nd process we can find the temperature (t2) there using the Ideal gas equationwhich is, P.V = mr t (which is a constant ) so,
(p1 * v1) / t1 = (p2 * v2) / t2
t2 = ((p2 * v2) * t1) / (p1 * v1)
* Since the process 2 to 3 is constant volume process the volume v3 = v2. The temperature (t3) is given as the input, so with thatwe can calulate the pressure (p3) using the Ideal gas equation,
(p2 * v2) / t2 = (p3 * v3) / t3
p3 = ((p2 * v2) *t3) / (v3 * t2)
* Then we need to calculate the parameters at process 4. Since the process 1 & 4 is constant volume process, v4 = v1
* As the process 3 to 4 is a isoentropic process, we use this expression to find (p4)
p3 * v3^gamma = p4 * v4^gamma
p4 = p3 * (v3/v4)^gamma
* After calulation the pressure and volume at 4th process we can find the temperature (t4), using the Ideal gas equation which is,
p3 * v3 / t3 = p4 * v4 / t4
t4 = ((p4 * v4 )*t3) / p3*v3
* Then by knowing all the pressure temperature values at all 4 process we can plot the points using (p1 v1, p2 2, p3 v3 , p4 v4).
* But to connect the points (i.e) to trace the change in pressure and volume during the four process of an otto cycle we are usingthis mathematical expression, in a seperate function program.
v/vc = 1 + 0.5*(cr-1) * [R + 1 - cos(theta) - (R^2 - sin(theta)^2).^0.5]
* Where we take the inputs of bore, stroke, connecting rod length, starting crank and ending crank angle. The staring crank andeneding crank angle is converted to radians.
* Then the number of points (n), we need between stating crank angle and ending crank angle is taken as 50.
* Then the position of the crank is expressed using its momentary angle, by term d_theta, which is calculated by subtracting thecurrent crank value with the starting crank values and dividing it by n-1
* Then we are giving the formula under a 'for loop' with the loop counting from 0 to 50, where the actual theta values whichis the current angle of rotation is specified by d_theta value with respect to each iteration.
* The volume change with repect to the crank angle from (TDC to BDC) is calculated using the function program.
* To trace the change in the volume during the compression ( BDC to TDC which is 180 Degree to 0 Degree) and expansionstroke ( TDC to BDC which is 0 Degree to 180 Degree) is calculated by calling the function at the appropriate places and givingthe starting crank and ending crank angle.
* To find the pressure change with repect to the crank angle, the volume change is related to the pressure change using theisentropic expression inside the for loop. The volume change is used to find the trace of the pressure change too here using theabove mentioned process.
* Now the plotting is made to connect the pressure and volume points using the appropriate change in pressure and volumethat we have calculated using the formula to visualize the actuall PV Diagram of the otto cycle.
* Then the efficiency of the otto cycle is calculated using the below expression,
Efficiency = work done / Amount of Heat added
work done = Amount of Heat added (t3 -t2) - Amount of Heat rejected (t4 -t1),Which gives the amount of heat utilized to convert it into mechanical work.
Efficiency = [(t3 - t2) - (t4 - t1)] / (t3 - t2)
* Finally the efficiency is calculated using this expreesion, Efficiency = 1-((t4-t1)/(t3-t2)).
* Then the plotting of results,
Explanation of the codes:
Results:
Output :
The Efficiency of the otto cycle for the given input condition is: 0.6298928275128466
At state point 1: Pressure(p1) = 101325 ; temperature(t1) = 500 ; volume(v1) = 0.0008567979964335801
At state point 2: Pressure(p2) = 3285264.621674427 ; temperature(t2) = 1350.960038520613 ; volume(v2) = 7.139983303613168e-05
At state point 3: Pressure(p3) = 5593140.0 ; temperature(t3) = 2300 ; volume(v3) = 7.139983303613168e-05
At state point 4: Pressure(p4) = 172505.1025603998 ; temperature(t4) = 851.246496720453 ; volume(v4) = 0.0008567979964335801
Conclusion :
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 - CHT Analysis on a Graphics card
Objective: To perform a steady state conjugate heat transfer analysis on a model of graphics card. Introduction :The term conjugate heat transfer (CHT) describes the process which involves variation of temperature within solids and fluids, due to thermal interaction between the solids and fluids, the exchange of thermal…
23 Mar 2022 04:17 AM IST
Week 5 - Rayleigh Taylor Instability
Rayleigh Taylor Instability INTRODUCTIONThe Rayleigh–Taylor instability, is the instability of an interface between two fluids of different densities which occurs when the lighter fluid is pushing the heavier fluid with the effect of gravity. Here we have prepared a model with two surfaces on over the above and considered…
07 Mar 2022 05:33 PM IST
Week 3 - External flow simulation over an Ahmed body.
External flow simulation over an Ahmed body. AIM:To simulate flow over ahmed body & to address the below given tasks.1. Describe Ahmed body & its importance.2. Explain the negative pressure in wake.3. Explain significance of the point of seperation. Expected results:1. Velocity & pressure contour of the Ahmed…
07 Mar 2022 02:44 PM IST
Week 4 - CHT Analysis on Exhaust port
CHT Analysis on Exhaust port Objective :In this challenge,1. brief description of why and where a CHT analysis is used.2. simulate both fluid flow and also the heat transfer to the solid i.e., CHT Analysis on an Exhaust port3.calculate the wall heat transfer coefficient on the internal solid surface & show the velocity…
27 Feb 2022 03:12 PM 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.