Week 2 Air standard Cycle
AIM:
1. Your code should create a PV diagram
2. You should output the thermal efficiency of the engine.
Detail Explanation of Otto cycle:

1. Process 1-2: Isentropic Compression
This process involves the motion of piston from TDC to BDC. The air that is sucked into cylinder during suction stroke undergoes reversible adiabatic (isentropic) compression. Since the air is compressed, the pressure increases from P1 to P2, the volume decreases from V1 to V2, temperature rises from T1 to T2, and entropy remains constant.
2. Process 2-3: Constant Volume Heat Addition
This process is an isochoric process i.e. the heat is added to the air at constant volume. The piston in this process rest for a moment at TDC and during this time heat is added to the air through external source. Due to the heat addition, the pressure increases from P2 to P3, pressure, volume remains constant(i.e. V2=V3), temperature increases from T2 to T3 and entropy increases from S2 to S3.
3. Process 3-4: Isentropic Expansion
In this process, the isentropic (reversible adiabatic) expansion of air takes place. The piston moves from TDC to BDC. Power is obtained in this process which is used to do some work. Since this process involves expansion of air, so the pressure decreases from P3 to P4, volume increases from V3 to V4, temperature falls from T3 to T4 and entropy remains unchanged (i.e. S3=S4).
4. Constant Volume Heat Rejection
In this process, the piston rest for a moment at BDC and rejection of heat takes place at constant volume. The pressure decreases from P4 to P1, Volume remains constant (i.e. V4=V1), temperature falls from T4 to T1.
When this cycle is used in four stroke petrol engine than two process increases. one is suction of air fuel mixture inside the cylinder which takes place at constant atmospheric pressure and other one is exhaust of gases out of the engine cylinder at constant atmospheric pressure.
The efficiency of Otto cycle is given by

import math
import matplotlib.pyplot as plt
def engine(bore, stroke, con_rod,cr ,start_crank,end_crank):
a = stroke / 2
R = con_rod / a
v_s = (math.pi / 4) * pow(bore, 2) * stroke
v_c = v_s / (cr - 1)
#start_crank angle
sc = math.radians(start_crank)
ec = math.radians(end_crank)
num_values = 50
# formula to find the crank angle and volume inside the combustion chamber.
# to get volume trace of the process
# v/v_c = 1+(0.5(cr-1)(R+1-cos(theta)-(R^2-sin(theta)^2)^0.5)
# above equation divided into multiple terms.
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 =6
# volume computation
v_s = (math.pi/4)*pow(bore, 2)*stroke
v_c = v_s/(cr-1)
v1 = v_c+v_s
#point2
v2 = v_c
#p2v2^gamma = p1v1^gamma
p2 = p1*pow(v1, gamma)/pow(v2, gamma)
# for temperature using ideal gas law p2v2/t2 =p1v1/t1
rhs = p1*v1/t1
t2 = p2*v2/rhs
v_compression = engine(bore, stroke, con_rod,cr ,180,0)
#p_compression*v_compression^gamma = consatant
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
p3 = t3*rhs/v3
v_expansion = engine(bore, stroke, con_rod,cr ,0,180)
#p_compression*v_compression^gamma = consatant
constant = p3*pow(v3, gamma)
p_expansion = []
for v in v_expansion:
p_expansion.append(constant/pow(v, gamma))
# state point4
v4 = v1
#p4v4^gamma = p3v3^gamma
p4 = p3*pow(v3, gamma)/pow(v4, gamma)
#p4v4/t4 =p3v3/t3
t4 = p4*v4/rhs
v = engine(bore, stroke, con_rod,cr ,0,180)
# now plotting
#2. You should output the thermal efficiency of the engine.
Nther = 1- (t4-t3)/(t2-t1)
print(Nther)
plt.plot([v2,v3],[p2,p3])
plt.plot(v_compression,p_compression)
plt.plot(v_expansion,p_expansion)
plt.xlabel('Volume (V)')
plt.ylabel('Pressure(P)')
plt.plot([v4,v1],[p4,p1])
plt.show()
Algorithm:
- first, import math and import matplotlib.pyplot as plt.
- write the def function name as engine.
- inputs are given below.
a is the connecting rod pin radius.
p1 =101325
t1 = 500
gamma=1.4
t3 = 2300
- geometric parameters
bore = 0.1
stroke = 0.1
con_rod = 0.15
cr =6
- now writing the formula for clearense and swept volume.
- to find out start and end crank angle:
sc = math.radians(start_crank)
ec = math.radians(end_crank)
- number of angles are taken as 50.
- formula to find the crank angle and volume inside the combustion chamber to get volume trace of the process
v/v_c = 1+(0.5(cr-1)(R+1-cos(theta)-(R^2-sin(theta)^2)^0.5)
- above equation divided into multiple terms.
- now for loop is used to repeat it until 50 iterations.
- returning v to the function.
- now calculating state points 1,2,3,4.
- at state point 1, v1 is the total volume before combustion.
- v2 is clearence volume at point 2
- The relationship between pressure and volume of an ideal gas is expressed as pv=constant in a reversable isothermal condition.
- Show that the relationship between pressure and volume of the same gas is expressed as pV^gamma=constant in a reversible adiabatic condition,
where gamma=Cp,m/Cv,m.
- here p2 value calculated.
- for temperature using ideal gas law p2v2/t2 =p1v1/t1.
- t2 value calculated here.
- in state point 2, compression will takes place.
- so, to usinf the formula p_compression*v_compression^gamma = consatant.
- p_compression,v_compression are calculated.
- state point 3, expansion takes place:
p_expansion*v_expansion^gamma = consatant
v3 = v2,
p3v3/t3 =p2v2/t2
- using for loop for presure.
-state point 4: using the formula:
p4v4/t4 =p3v3/t3
- we can calculate t4.
- to get output the thermal efficiency of the engine formula is:
Nther = 1- (t4-t3)/(t2-t1) =3.246452972880699
- plots will be plotted for state points 1,2,3,4 and p_compression,v_compression and p_expansion,v_expansion.
- at last show command to see the p-v graph for the engine.

2. You should output the thermal efficiency of the engine.
Output the thermal efficiency of the engine:
