Project

Python Report on: - Solve an otto cycle and make respective plots for it.

-Objective: - write code that can solve an otto cycle and make plots for it.

  • An otto standard cycle works on ideal thermodynamics cycle which applies on spark ignition piston engine. We have to plot two graphs on Pressure-Volume and Efficiency-Compression. There are a few constant values given to calculate the efficiency and other processes.

There are four processes involved in the otto cycle as mentioned below: -
Process (1-2) - Isentropic Compression
Process (2-3) - Constant volume heat addition
Process (3-4) - Isentropic Expansion
Process (4-1) - Constant volume heat rejection

Step 1: Write code for otto cycle graph

\"\"\"
Code by Ravi Thakur
Subject: Write a program to plot PV diagram for Otto cycle

\"\"\"

import math
import matplotlib.pyplot as pyplot

def otto_standard_cycle(bore, stroke, con_rod, cr, start_crank, end_crank):
	
	a = stroke/2
	R = con_rod/a

	# volume parameters
	V_s = math.pi*(1/4)*pow(bore,2)*stroke
	V_c = V_s/(cr-1)

	# Crank angle
	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))
		term4 = pow(term3,0.5)
		V.append((1 + term1*(term2 - term4)) * V_c)

	return V

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

# given values
bore = 0.1
stroke = 0.1
con_rod = 0.15
cr = 12

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

# state process 2
v2 = v_c
p2 = p1*pow(v1,gamma)/pow(v2,gamma)
rhs = p1*v1/t1
t2 = p2*v2/rhs

# compression process
V_compression = otto_standard_cycle (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 process 3
v3 = v2
rhs = p2*v2/t2
p3 = rhs*t3/v3

#expansion process
V_expansion = otto_standard_cycle (bore, stroke, con_rod, cr, 180,360)
Constant = p3*pow(v3,gamma)
P_expansion = []
for V in V_expansion:
	P_expansion.append(Constant/pow(V,gamma))

# state process 4
v4 = v1
p4 = p3*pow(v3,gamma)/pow(v4,gamma)
t4 = p4*v4/rhs

#Thermal Efficiency
n = 1 - ((t4-t1)/(t3-t2))
print(n)

#plot pv daigram
pyplot.plot([v2,v3],[p2,p3],\'-b\', label=\'Heat Addition\')
pyplot.plot(V_compression,P_compression,\'-r\', label=\'Compression\')
pyplot.plot(V_expansion,P_expansion, \'-y\', label=\'Expansion\')
pyplot.plot([v4,v1],[p4,p1], \'-g\', label=\'Heat Rejection\')
pyplot.legend()
pyplot.xlabel(\'Volume, m^3\')
pyplot.ylabel(\'Pressure, Bar\')
pyplot.title(\'Otto cycle Constant PV daigram\')
pyplot.grid()
pyplot.show()

Step 2: Results

The plot shows the Pressure-Volume diagram which shows the constant process of the otto cycle. (Note: The compression and expansion process doesn\'t move linearly. so, to solve it more accurately we have calculated volume and pressure for varying the crank angle.)

The plot shows an accurate moment of crank angle during the compression and expansion process in an otto cycle. (Note: As volume is powered by gamma value it forms a curve at the compression and expansion process in the otto cycle.)

Image shows Thermal efficiency of the Otto cycle.

Step 3: Command used

  • Def - Functions are a construct to structure programs. They are known in most programming languages, sometimes also called subroutines or procedures. Functions are used to utilize code in more than one place in a program. The only way without functions to reuse code consists of copying the code.
  • Return command is like if a return statement is followed by an expression list, that expression list is evaluated and the value is returned:

Step 4: Conclusion

  • We understood the behavior of the otto cycle during expansion and compression process and how to code it.
  • We understood how to convert linear moment of compression and expansion process into curve format.

Step 5: Reference

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.