Week 2 Air standard Cycle
AIM: To write a program in python to solve an otto cycle and make plots for it
OBJECTIVE:
- To solve and find out different state variables in the otto cycle and plot its p-V diagram.
- to calculate the thermal efficiency of the given otto cycle.
THEORY:
The Otto Cycle is the ideal cycle for a spark-ignition reciprocating engine. In most spark-ignition engines, the piston executes four complete strokes (two mechanical cycles) within the cylinder and the crankshaft completes two revolutions for each thermodynamic cycle. these engines are called four-stroke internal combustion engine
- Intake: This stroke of the piston begins at the top dead center (T.D.C.) and ends at the bottom dead center (B.D.C.). In this stroke, the intake valve must be in the open position while the piston pulls an air-fuel mixture into the cylinder by producing vacuum pressure into the cylinder through its downward motion. The piston is moving down as air is being sucked in by the downward motion against the piston.
- Compression: This stroke begins at B.D.C, or just at the end of the suction stroke, and ends at T.D.C. In this stroke, the piston compresses the air-fuel mixture in preparation for ignition during the power stroke (below). Both the intake and exhaust valves are closed during this stage.
- Combustion: Also known as power or ignition. This is the start of the second revolution of the four-stroke cycle. At this point, the crankshaft has completed a full 360-degree revolution. While the piston is at T.D.C. (the end of the compression stroke) the compressed air-fuel mixture is ignited by a spark plug forcefully returning the piston to B.D.C. This stroke produces mechanical work from the engine to turn the crankshaft.
- Exhaust: Also known as an outlet. During the exhaust stroke, the piston, once again, returns from B.D.C. to T.D.C. while the exhaust valve is open. This action expels the spent air-fuel mixture through the exhaust valve.

A four-stroke engine
The four processes in an Otto cycle are:
- Isentropic compression process or reversible adiabatic compression of air (Process 1-2)
- Constant volume heat addition process (Process 2-3),
- isentropic expansion process or reversible adiabatic expansion of air (Process 3-4)
- constant volume heat rejection process (Process 4-1)
BODY OF THE CONTENT :
EXPLANATION OF THE PYTHON CODE:
- Since the Otto cycle is an air-standard cycle the specific heat of air is 1.4.
- Initial conditions, such as temperature (t1) and pressure (p1) of the surrounding are assumed to be 350K and 101.325 kPa respectively.
- The geometrical design of the engine cylinder which consists of bore diameter, stroke length, and length of the connecting rod is also known and according to vs and vc calculated.
- Other state variables are calculated using the adiabatic processes equation and the ideal gas equation.
- Similarly, the thermal efficiency is also calculated accordingly using the formula given.
- For plotting the calculating state variable on a p-v diagram with just using 'plt.ploy' the command will yield into the incorrect p-v diagram,i.e, compression and expansion stroke is represented by a straight line.
- So to rectify this, different function is created for storing the different stroke or cycle. This function is called the main program and accordingly, the plot is drawn from various points obtained.
- For this number of values for which the program will iterate is 100, and accordingly, the V array is set as null and after every iteration using for loop, a new value will be and will be returned back after receiving desired values.
PYTHON CODE FOR SOLVING AND PLOTTING CURVE:
"""
A program on otto cycle simulation
"""
import math
import matplotlib.pyplot as plt
def enging_kinematics(bore,stroke,connecting_rod,c_r,start_crank_angle,end_crank_angle):
# Engine gomentry properties
r= stroke/2
n = connecting_rod/r
#volume parameters
v_swept = (math.pi/4)*pow(bore,2)*stroke
v_clearnce = v_swept/(c_r - 1)
theta_startcrank = math.radians(start_crank_angle)
theta_endcrank = math.radians(end_crank_angle)
num_val = 100
dtheta = (theta_endcrank - theta_startcrank)/(num_val - 1)
v= []
for i in range(0,num_val):
theta = theta_startcrank + i*dtheta
term_1 = 0.5*(c_r - 1)
term_2 = n + 1 - math.cos(theta)
term_3 = (pow(n,2) - pow(math.sin(theta),2))
term_3 = pow(term_3,0.5)
v.append((1 + term_1*(term_2 - term_3))*v_clearnce)
return v
# input variable
# for air gamma = 1.4
gamma = 1.4
# max temp inside enging cyr
t3 = 2000
# state variable
# ambient atomospheric condition assumed
p1 = 101325
t1 = 350
# Engine geometry properties
bore = 0.15
stroke = 0.2
connecting_rod = 0.8
c_r = 10
# calculating swept volume and clearnce volume
v_swept = (math.pi/4)*pow(bore,2)*stroke
v_clearnce = v_swept/(c_r - 1)
v1 = v_swept + v_clearnce
v2 = v_clearnce
# state variable at state point 2
# p2*v2*gamma = p1*v1*gamma --- isentropic compression
p2 = p1* pow(c_r,gamma)
#(p1*v1)/t1 = (p2*v2)/t2 | t2 = p2*v2*t1/(p1*v1)
t2 = p2*v2*t1/(p1*v1)
v_comp = enging_kinematics(bore,stroke,connecting_rod,c_r,180,0)
c_const = p1* pow(v1,gamma)
p_comp = []
for v in v_comp:
p_comp.append(c_const/pow(v,gamma))
# state variable at state points
# Isochromic process
v3 = v2
"""(p3*v3)/t3 = (p2*v2)/t2 | p3 = p2*t3/(t2)"""
p3 = p2*t3/(t2)
v_expp = enging_kinematics(bore,stroke,connecting_rod,c_r,0,180)
c_const = p3*pow(v3,gamma)
p_expp = []
for v in v_expp:
p_expp.append(c_const/pow(v,gamma))
# state variable at state point 4
# isochoric process
v4 = v1
# isotropic expansion process
"""p3*v3^gamma = p4*v4^gamma"""
p4 = p3*pow(v3,gamma)/pow(v4,gamma)
"""(p3*v3)/t3 = (p4*v4)/t4 | t4 = p4*v4*t3/(p3*v3)"""
t4 = p4*v4*t3/(p3*v3)
plt.plot(v_comp,p_comp)
plt.plot([v2,v3],[p2,p3])
plt.plot(v_expp,p_expp)
plt.plot([v4,v1],[p4,p1])
plt.ylim([-500000,8000000])
plt.xlim([0,0.005])
plt.xlabel('volume(m^3)')
plt.ylabel('pressure(pa)')
plt.title('p_v diagram of an otto cycle')
plt.text(0.00385, -2500000,r'$ 1 $')
plt.text(0.0002,2000000,r'$ 2 $')
plt.text(0.0002,5850000,r'$ 3 $')
plt.text(0.00385,400000,r'$ 4 $')
plt.grid()
plt.show()
# calculating thermal efficiancy
thermel_efficincy = 1 - (1/pow((c_r),(gamma - 1)))
print ('thermel efficincy og given otto cycle :',thermel_efficincy)
RESULTS:
Upon executing the program, the following plot for the p-V cure was observed:

The thermal efficiency calculated:

CONCLUSION: The desired and correct p-V diagram of the Otto cycle was obtained using an array of volume inside the engine cylinder at a different crank angle.
CODE LINK:
https://drive.google.com/drive/folders/1L_jJjI1jKD1EFDmKfs47gVqBfiJhPIiJ?usp=sharing