Week 2 Air standard Cycle
Aim- Simulation of otto cycle using python and sublime text.
The otto cycle actually used in the Spark Ignition engine contains a pair of isentropic and isochoric processes.

In the above picture, the red and green lines represent the isentropic process and the blue and black lines represent an isochoric process.
Process 1–2 compression stroke
The piston moves from the crank end (BDC, bottom dead center and maximum volume) to cylinder head end (TDC, top dead center and minimum volume) as the working gas with initial state 1 is compressed isentropically to state point 2, through compression ratio (V1/V2). Mechanically this is the isentropic compression of the air/fuel mixture in the cylinder, also known as the compression stroke. This isentropic process assumes that no mechanical energy is lost due to friction and no heat is transferred to or from the gas, hence the process is reversible. The compression process requires that mechanical work be added to the working gas. Generally, the compression ratio is around 9–10:1 (V1:V2) for a typical engine.
Process 2–3 ignition phase
The piston is momentarily at rest at TDC. During this instant, which is known as the ignition phase, the air/fuel mixture remains in a small volume at the top of the compression stroke. Heat is added to the working fluid by the combustion of the injected fuel, with the volume essentially being held constant. The pressure rises and the ratio p3/p2is called the "explosion ratio".
Process 3–4 expansion stroke
The increased high pressure exerts a force on the piston and pushes it towards the BDC. Expansion of working fluid takes place isentropically and work is done by the system on the piston. The volume ratio v4/v3 is called the "isentropic expansion ratio". (For the Otto cycle is the same as the compression ratio v1/v2. Mechanically this is the expansion of the hot gaseous mixture in the cylinder known as expansion (power) stroke.
Process 4–1 idealized heat rejection
The piston is momentarily at rest at BDC. The working gas pressure drops instantaneously from point 4 to point 1 during a constant volume process as heat is removed to an idealized external sink that is brought into contact with the cylinder head. In modern internal combustion engines, the heat-sink may be surrounding air (for low-powered engines), or a circulating fluid, such as coolant. The gas has returned to state 1.
Thermal Efficiency-

Program----
import math
import matplotlib.pyplot as plt
def engine_kinematics( bore, stroke, con_rod, comp_ratio, start_crank, end_crank): #defining the fuction
a= stroke/2
R= con_rod/a
swept_v= (math.pi/4)*pow(bore,2)*stroke #swept volume
com_v= swept_v/(comp_ratio-1) #compression volume
sc= math.radians(start_crank) # start cfranck angle in radian
ec= math.radians(end_crank) # end crank angle in radian
num_values= 50
dtheta= (ec-sc)/(num_values-1)
v= []
for i in range (0,num_values):
theta= sc + i*dtheta
term1= 0.5*(comp_ratio-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))*com_v)
return v
p1= 0.1
t1= 498
gamma= 1.4
t3= 2400
bore= 0.10
stroke= 0.12
con_rod= 0.15
comp_ratio=12
swept_v= (math.pi/4)*pow(bore,2)*stroke
comp_v= swept_v/(comp_ratio-1)
v1= swept_v+comp_v
v2= comp_v
p2= p1*pow(v1,gamma)/pow(v2,gamma)
rhs= p1*v1/t1
t2= p2*v2/rhs
v_comprsn= engine_kinematics(bore,stroke,con_rod,comp_ratio,180,0)
constant1= p1*pow(v1,gamma)
p_compresn= []
for v in v_comprsn:
p_compresn.append(constant1/pow(v,gamma))
v3=v2
rhs= p2*v2/t2
p3= rhs*t3/v3
v_expnsn= engine_kinematics(bore,stroke,con_rod,comp_ratio,0,180)
constant2= p3*pow(v3,gamma)
p_expensn= []
for v in v_expnsn:
p_expensn.append(constant2/pow(v,gamma))
v4=v1
p4=p3*pow(v3,gamma)/pow(v4,gamma)
t4= p4*v4/rhs
thermal_eff= (1-((t4-t1)/(t3-t2)))*100
print(thermal_eff)
plt.grid()
plt.plot([v2,v3],[p2,p3])
plt.plot(v_expnsn,p_expensn)
plt.plot(v_comprsn,p_compresn)
plt.plot([v4,v1],[p4,p1])
plt.xlabel('volume')
plt.ylabel('pressure')
plt.title('otto cycle')
plt.show()
Thermal Efficiency---- 62.98%

Result-----
