Challenge

Week 2 Air standard Cycle

AIM: To write PYTHON code that can solve an Otto Cycle, make plots and find efficiency of that.

OTTO CYCLE

Otto cycle is description of thermodynamic cycle which is based on the function of spark ignition piston engine. Name of this cycle is dedicated to the Nicolaus Otto, German Engineer who build the first working four stroke engine. Most of the automobile engines follows this cycle for process. There are 4 process in the cycle.

Process 1-2: Isentropic compression

Process 2-3: Constant volume heat addition

Process 3-4: Isentropic expansion

Process 4-1: Constant volume heat rejection

To generate above mentioned P-V diagram, we need state points, that can be achieved at different states. This state points are basically P(Pressure), V(Volume) and T(Temperature). There are total 4 stages for that first we need to find the value of above-mentioned state points.

STEP-BY-STEP EXPLANATION OF PYTHON CODE TO OBTAIN ALL STATE POINTS

  1. Firstly, we need to get basic inputs and value of γ (gamma). These inputs are P1, T1, and T3. Where P1: Initial Pressure, T1: Initial Temperature, T3: Temperature after heat addition and γ = 1.4 constant.
  2. Secondly, we need some engine parameters, these parameters are Bore (Engine bore diameter), Stroke (Stroke length), Connecting rod (Length of connecting rod) and r (Engine Compression Ratio).
  3. We need to obtain value of Vc (Clearance Volume) and Vs (Swept Volume) using engine parameters.
  4. With the addition of Vc and Vs, we can get V1 (Initial Volume), we already have other inputs (P1 and T1) for State 1.
  5. For values of state points of State 2,
    1. V2 = Vc (Clearance Volume)
    2. P2 = by using `P_1 V_1^γ=P_2 V_2^γ`
    3. T2 = by using Ideal gas equation`(P_1 V_1)/T_1 =(P_2 V_2)/T_2`
  6. For values of state points of State 3,
    1. V3 = V2 (Constant Volume)
    2. P3 = by using Ideal gas equation `(P_2 V_2)/T_2 =(P_3 V_3)/T_3`
    3. T3= already taken as input
  7. For values of state points of State 4,
    1. V4 = V1 (Get back to initial volume)
    2. P4 = by using `P_3 V_3^γ=P_4 V_4^γ`
  8. To find the efficiency, we use following equation:

Efficiency = `1-(1/r^((γ-1)) )`

where r = Engine Compression Ratio

γ = Gamma (is 1.4 in our case)

9.At the end, we have all state points values at States and Efficiency.

PROCEDURE FOR CONNECT STATE POINT IS AS FOLLOWING

  1. After plotting all four point on graph, we can’t just connect them with plot command, otherwise we can-not get output as required. So, we have to create the function to calculate changes occurs in V during the compression and expansion process.
  2. We can divide connection of lines by each process:
    1. 1 – 2: Isentropic Compression Process
    2. 2 – 3: Constant Volume Heat Addition
    3. 3 – 4: Isentropic Expansion Process
    4. 4 – 1: Constant Volume Heat Rejection
  3. By using Engine Kinematics Function V,

`V/V_c = 1+1/2 (r-1)[R+1-cos⁡θ- (R^2-〖sin⁡θ〗^2 )^(1⁄2) ]`

Where, V indicates the rate of change in Volume from one state to other state

This function can use to determine How value of V changes in compression and expansion Process.

  1. Now, For the compression process we calculate the V_compression using this function. For isentropic process `PV^γ=Constant`. So, we calculate first the value of constant with the value of P1 and V1.V_compression indicates how the volume changes during compression.
  2. Then we determine the value of P_compression according to V_compression using for loop.
  3. For the expansion process, we calculate the V_expansion and P_expansion same as V_compression and P_compression.
  4. Now, we simply connect the state point 2 and 3 with plot command. Also connect the state point 4 and 1.
  5. we connect 1 and 2 point using V_compression and P_compression and 3 and 4 point using V_expansion and P_expansion.
  6. So, we obtain complete P-V diagram.

MAIN PROGRAM

#otto cycle simulator
import math
import matplotlib.pyplot as plt
import numpy as np


def engine_kinematics(bore,stroke,con_rod,cr,start_angle,end_angle):

	a=stroke/2
	R=con_rod/a
	sa=math.radians(start_angle)
	ea=math.radians(end_angle)

	theta=np.linspace(sa,ea,100)
	
	V=[]

	for i in theta:
		term1=0.5*(cr-1)
		term2= R+1-math.cos(i)
		term3= pow(R,2)-pow(math.sin(i),2)

		V_temp=(1+term1*(term2-pow(term3,0.5)))*v_c
		V.append(V_temp)

	return V

#input
p1=95000            # initial pressure in Pa
T1=288              # initial temperature in K
T3=1473             # temperature after heat addition in K
gamma=1.4

#engine parameters
bore=0.1                 #engine bore diameter in meter
stroke= 0.15             #engine stroke length in meter
con_rod=0.2              #engine connecting rod length in meter
cr = 8                   #engine compression ratio

#calculating clearance volume(v_c) and swept volume(v_s)
v_s = (math.pi/4)*pow(bore,2)*stroke
v_c = v_s/(cr-1)

#state variable at state 1
v1 = v_s + v_c

#state variable at state 2
v2 = v_c
p2=p1*pow(cr,gamma)          #according to p1*v1^gamma=p2*v2^gamma
T2 = p2*v2*T1/(p1*v1)         #p1*v1/T1=p2*v2/T2 (ideal gas eqation)

constant_c = p1*pow(v1,gamma)
v_compression = engine_kinematics(bore,stroke,con_rod,cr,180,0)

p_compression=[]
for v in v_compression:
	p = constant_c/pow(v,gamma)
	p_compression.append(p)

#state variable at state 3
v3=v2                   #constant volume
p3=p2*T3/T2           #p2*v2/T2=p3*v3/T3 (ideal gas eqation)

constant_c = p3*pow(v3,gamma)
v_expansion = engine_kinematics(bore,stroke,con_rod,cr,0,180)

p_expansion=[]
for v in v_expansion:
	p= constant_c/pow(v,gamma)
	p_expansion.append(p)

#state variable at state 4
v4=v1
p4=p3/pow(cr,gamma)      #according to p3*v3^gamma=p4*v4^gamma

#efficiency of otto cycle
efficiency=(1-(1/pow(cr,(gamma-1))))*100
print(efficiency)

plt.plot(v1,p1,'ro')
plt.plot(v2,p2,'ro')
plt.plot(v3,p3,'ro')
plt.plot(v4,p4,'ro')

plt.plot(v_compression,p_compression,'g')
plt.plot([v2,v3],[p2,p3],'g')
plt.plot(v_expansion,p_expansion,'g')
plt.plot([v4,v1],[p4,p1],'g')

plt.xlabel('V(volume)')
plt.ylabel('P(pressure)')
plt.title('P-V Diagram')
plt.savefig('P-V Diagram')
plt.show()

OUTPUT OF THE ABOVE PROGRAM

1.EFFICIENCY OF OTTO CYCLE IN PERCENTAGE

2.P-V DIAGRAM

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.