Project

PV - Diagram of Otto Cycle is plotted using Python

OTTO CYCLE

Program:

\"\"\"
Otto cycle
\"\"\"

import math
import matplotlib.pyplot as plt



def engine_kinematic (bore,stroke,con_rod,cr,Start_crank,end_crank):
	\"\"\"
	engine kinematics
	\"\"\"

	#geomentric parameters
	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)

	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 
t1 = 500
gamma = 1.4
t3 = 2300

#geometric parameters 
bore    = 0.1
stroke  = 0.1
con_rod = 0.15
cr      = 12


#volume
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)

#p2v2/t2 = p1v1/t1 | rhs =p1v1/t1

rhs= p1*v1/t1
t2 = p2*v2/rhs
V_compression =engine_kinematic (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

#p3v3/t3 = p2v2/t2| rhs = p2*v2/t2
rhs = p2*v2/t2
p3 = rhs*t3/v3

V_expansion =engine_kinematic (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

#p4v4^gamma = p3v3^gamma

p4 = p3*pow(v3,gamma)/pow(v4,gamma)

#p4v4/t4 = p3v3/t3 | rhs = p3*v3/t3

rhs = p3*v3/t3

t4 = p4*v4/rhs

#Thermal Efficiency 
cp = 1.00
cv = 0.718
k = cp/cv
thermal_efficiency = 1 - (1/pow(cr,(k-1)))
print(thermal_efficiency)

#plotting
plt.plot([v2,v3],[p2,p3])
plt.plot([v4,v1],[p4,p1])
plt.plot(V_compression,P_compression)
plt.plot(V_expansion,P_expansion)
plt.show()

Description :

Step 1: To import the library we need to use the below commands

import math
import matplotlib.pyplot as plt

Step 2:

The function is defined as an engine kinematics and function inputs are bore, stroke, con_rod, start_crank, end_crank values. Geometric parameters are also defined here , swept volume and clearance volume is also calculated. For loop is used to get the repeated values of the theta. And the formula is implemented in the form of terms and calculated the V, to get the value of V return command is used.

def engine_kinematic (bore,stroke,con_rod,cr,Start_crank,end_crank):
\"\"\"
engine kinematics
\"\"\"

#geomentric parameters
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)

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

Step 3:

Here the main inputs are defined such as gamma, intial temperature, initial pressure, and some geometric parameters like bore,stroke, con_rod, compression ratio.


p1 = 101325
t1 = 500
gamma = 1.4
t3 = 2300

#geometric parameters
bore = 0.1
stroke = 0.1
con_rod = 0.15
cr = 12

Step 4:

The volumes are calculated here swept volume and clearance volume and volume at state point 1


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

Step 5:

Here volume 2 is equal to the clearance volume and using ideal gas constant law we defined p2 and t2 and at state point 2 compression of engine takes place and V_compression is also calculated.

#State point 2
v2 = v_c

#p1v1^gamma=p2v2^gamma
p2 = p1*pow(v1,gamma)/pow(v2,gamma)

#p2v2/t2 = p1v1/t1 | rhs =p1v1/t1

rhs= p1*v1/t1
t2 = p2*v2/rhs

V_compression =engine_kinematic (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))

Step 6:

Here volume 3 is equal to volume 2 and using ideal gas constant law we defined p3 and at state point 3 expansion of engine takes place and V_expansion is also calculated.


#state point 3

v3 = v2

#p3v3/t3 = p2v2/t2| rhs = p2*v2/t2
rhs = p2*v2/t2
p3 = rhs*t3/v3

V_expansion =engine_kinematic (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))

Step 7:

Here volume 4 is equal to volume 1 and using ideal gas constant law we defined p4 and t4 also calculated.


#state point 4
v4 = v1

#p4v4^gamma = p3v3^gamma

p4 = p3*pow(v3,gamma)/pow(v4,gamma)

#p4v4/t4 = p3v3/t3 | rhs = p3*v3/t3

rhs = p3*v3/t3

t4 = p4*v4/rhs

Step 8:

To find out the thermal efficiency of the otto cycle the required inputs is given and formula is calculated and to view the answer we used the print command


cp = 1.00
cv = 0.718
k = cp/cv
thermal_efficiency = 1 - (1/pow(cr,(k-1)))
print(thermal_efficiency)

Step 9:

By using the below commands the p-v diagram is plotted.

plt.plot([v2,v3],[p2,p3])
plt.plot([v4,v1],[p4,p1])
plt.plot(V_compression,P_compression)
plt.plot(V_expansion,P_expansion)
plt.show()

Results:

PV-Diagram

Thermal efficiency is 0.62317

Conclusion :

Using python the PV- diagram is plotted and the program is generated and executed successfully

Your portfolio, next

Ship work like this
in your own course.

Talk to a career counsellor

Free 20-minute call. We'll map the right course to where you want to work.

By submitting you agree to our Terms and Privacy Policy.

Talk to a career counsellor

Free 20-minute call. We'll map the right course to where you want to work.

By submitting you agree to our Terms and Privacy Policy.