Week 2 Air standard Cycle
AIM:
To write a program in Python to solve an Otto cycle and make plots for it.
OBJECTIVE:
1. To solve and find out different state variables in the Otto cycle and plot its a p-V diagram.
2. To calculate the thermal efficiency of the given Otto cycle.
Otto cycle:
- An Otto cycle is an idealized thermodyanamic cycle that describes the functioning of a typical spark ignition piston engine. It is the thermodynamic cycle most commonly found in automobile engines.
- The Otto cycle is a description of what happens to a mass of gas as it is subjected to changes of pressure, temperature,volume, addition of heat, and removal of heat. The mass of gas that is subjected to those changes is called the system.
- In the case of the Otto cycle, the effect will be to produce enough net work from the system so as to propel an automobileand its occupants in the environment.
- The otto cycle is basically a four stroke cycle where the power is generated by four step wise process.
- The process from 0 to 4 is explained below.

Engine Parameters:
Bore and Stroke:
- In a piston engine, the bore (or cylinder bore) is the diameter of each cylinder. In the context of an internal combustion engine, the term stroke has the following related meanings.
- A phase of the engine's cycle (e.g. compression stroke, exhaust stroke), during which the piston travels from top to bottomor vice versa.
- The type of power cycle used by a piston engine (e.g. two-stroke engine, four-stroke engine).
"Stroke length", the distance traveled by the piston during each cycle. The stroke length––along with bore diameter––determines the engine's displacement.
Connecting rod:
- A connecting rod also called acon rod, is the part of a piston engine that connects the piston to the crankshaft. Together withthe crank, the connecting rod converts the reciprocating motion of the piston into the rotation of the crankshaft. The connectingrod is required to transmit the compressive and tensile forces from the piston, and rotate at both ends.
Compression rartio:
- In a combustion engine, the static compression ratio is calculated based on the relative volumes of the combustion chamberand the cylinder; that is, the ratio between the volume of the cylinder and combustion chamber when the piston is at thebottom of its stroke, and the volume of the combustion chamber when the piston is at the top of its stroke. The dynamiccompression ratio is a more advanced calculation which also takes into account gasses entering and exiting the cylinder duringthe compression phase. The compression ratio is a fundamental specification for combustion engines.
Crank radius:
- Crank radius is the distance between the crank pin and crank center, i.e. half stroke.
Swept Volume:
- Swept volume can be defined as the volume swept by the engine piston during one stroke.
- .Swept volume is also the product of piston area and stroke.
Clearance Volume:
- Clearance volume can be defined as the volume that remains in the cylinder when the engine piston is in the top centreposition.
- Clearance volume can also be defined as the difference between the total cylinder volume and the swept volume. The spacecovered by the clearance volume also forms the combustion chamber.

0 to 1 - Suction stroke:
- A mass of air (working fluid) is drawn into the cylinder, from 0 to 1, at atmospheric pressure (constant pressure) through the open intake valve, while the exhaust valve is closed during this process.
1 to 2 - Isentropic compression process:
- Piston moves from crank end (BDC, bottom dead centre and maximum volume) to cylinder head end (TDC, topdead centre and minimum volume) as the working gas with initial state 1 is compressed isentropically to state point 2, through compression ratio(V/V).Mechanically this is the isentropic compression of the air/fuel mixture in the cylinder, also known as the compression stroke.
2 to 3 - Constant volume heat addition:
- The piston is momentarily at rest at TDC. During this instant, which is known as the ignition phase, the air/fuelmixture remains in a small volume at the top of the compression stroke. Heat is added to the working fluid by the combustionof the injected fuel, with the volume essentially being held constant.
3 to 4 - Isentropic expansion process:
- The increased high pressure exerts a force on the piston and pushes it towards the BDC. Expansion of workingfluid takes place isentropically and work is done by the system on the piston.
- Mechanically this is the expansion of the hot gaseous mixture in the cylinder known as expansion power stroke.
4 to 1 - Constant volume heat rejection:
- The piston is momentarily at rest at BDC. The working gas pressure drops instantaneously from point 4 to point 1during a constant volume process as heat is removed to an idealized external sink that is brought into contact with the cylinderhead. The gas has returned to state 1.
1 to 0 - Exhaust stroke:
- The exhaust valve opens at point 1. As the piston moves from "BDC" (point 1) to "TDC" (point 0) with the exhaustvalve opened, the gaseous mixture is vented to the atmosphere and the process starts anew.Since process 1 & 3 is isentropic the entropy is constant and in process 2 & 4 the volume is made constant in an otto cycle.
Since processes 1-2 and 3-4 are adiabatic processes, the heat transfer during the cycle takes place only during processes 2-3and 4-1 respectively. Therefore, the thermal efficiency
can be written as,

Following ideal gas equations are used to calculate the pressure and temperature:


Volume of the cylinder at any given crank angle is given by the expression:

Where,
V = Volume of the cylinder at any given instance
Vc = Clearance volume
rc = Compression ratio
R = Ratio of connecting rod to the crank radius
θ = Crank angle
Program to calculate the engine efficiency and plot the otto cycle:
# Program to simulate the otto cycle
import math
import matplotlib.pyplot as plt
def engine_kinematics(bore,stroke,con_rod,cr,start_crank,end_crank):
#geometric parameters
#(a) is the Crank pin radius
#R - Constant to know the crank angle and piston movement
a = stroke/2
R = con_rod/a
#volume parameters
#swept Volume
#Clearence Volume
v_s = (math.pi/4)*pow(bore,2)*stroke
v_c = v_s/(cr-1)
sc = math.radians(start_crank)
ec = math.radians(end_crank)
# number of theta between start & 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)
term3 = pow(term3,0.5)
V.append((1 + term1*(term2 - term3)) * v_c)
return V
# Inputs
p1 = 101325 # in N/m^2
t1 = 500 # in Kelvin
gamma = 1.4
t3 = 2300 # in Kelvin
# geometric parameters
bore = 0.1
stroke = 0.1
con_rod = 0.15
cr = 12
# Volume computation
v_s = (math.pi/4)*pow(bore,2)*stroke
v_c = v_s/(cr-1)
v1 = v_s + v_c
# state point 2
v2 = v_c
# p1v1^gamma = p2v2^gamma
p2 = p1 * pow(v1,gamma)/pow(v2,gamma)
# calculate t2 | p2v2/t2 = p1v1/t1 | rhs = p1v1/t1 | p2v2/t2 = rhs
rhs = p1*v1/t1
t2 = p2*v2/rhs
V_compression = engine_kinematics(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 point 3
v3 = v2
# calculate p3 | p3v3/t3 = p2v2/t2 = rhs
rhs = p2*v2/t2
p3 = rhs*t3/v3
V_expansion = engine_kinematics(bore,stroke,con_rod,cr,0,180)
constant = p3 * pow(v3,gamma)
P_expansion = []
for V in V_expansion:
P_expansion.append(constant/(pow(V,gamma)))
# State point 4
v4 = v1
#calculate p4 | p4v4^gamma = p3v3^gamma
p4 = p3*pow(v3,gamma)/pow(v4,gamma)
# calculating t4
t4 = p4*v4/rhs
# Calculating the thermal efficiency of the otto cycle
p = gamma-1
eta = (1 - 1/(pow(cr,p)))*100
print('The thermal efficiency of the otto cycle is:',eta)
Efficiency = 1-((t4-t1)/(t3-t2))
print('The Efficiency of the otto cycle for the given input condition is:',Efficiency)
print('At state point 1:', 'Pressure(p1) =',p1,'; temperature(t1) =',t1, '; volume(v1) =',v1)
print('At state point 2:', 'Pressure(p2) =',p2,'; temperature(t2) =',t2, '; volume(v2) =',v2)
print('At state point 3:', 'Pressure(p3) =',p3,'; temperature(t3) =',t3, '; volume(v3) =',v3)
print('At state point 4:', 'Pressure(p4) =',p4,'; temperature(t4) =',t4, '; volume(v4) =',v4)
# plotting the results
plt.plot(V_compression,P_compression, label="1 to 2 - Isentropic compression process")
plt.plot([v2,v3],[p2,p3], label="2 to 3 - Constant volume heat addition")
plt.plot(V_expansion,P_expansion, label = "3 to 4 - Isentropic expansion process")
plt.plot([v4,v1],[p4,p1],label ="4 to 1 - Constant volume heat rejection")
plt.legend()
plt.grid()
plt.xlabel('Volume in m^3')
plt.ylabel('Pressure in Pascal')
plt.title('PV Diagram of Otto Cycle')
plt.show()

Procedure :
* Firstly we are assingning the values for the input parameters of the first process in otto cycle,like pressure, temperature,gamma. The temperature at third process, which is the heat input given during combustion is assigned.
* Then we are giving the engine geomentric values that is the dimensions of the cylinder and some of its components in meter.
* After that we are we are calculating the swept volume ,clearence volume at volume at the 1st & 2nd process as v1 and v2.

* Since the process 1 to 2 is isentropic, we can use this expression to calculate the pressure (p2) at process 2,
p1 * v1^gamma = p2 * v2^gamma
p2 = p1 * v1^gamma / v2^gamma
*After calulation the pressure and volume at 2nd process we can find the temperature (t2) there using the Ideal gas equationwhich is, P.V = mr t (which is a constant ) so,
(p1 * v1) / t1 = (p2 * v2) / t2
t2 = ((p2 * v2) * t1) / (p1 * v1)

* Since the process 2 to 3 is constant volume process the volume v3 = v2. The temperature (t3) is given as the input, so with thatwe can calulate the pressure (p3) using the Ideal gas equation,
(p2 * v2) / t2 = (p3 * v3) / t3
p3 = ((p2 * v2) *t3) / (v3 * t2)

* Then we need to calculate the parameters at process 4. Since the process 1 & 4 is constant volume process, v4 = v1
* As the process 3 to 4 is a isoentropic process, we use this expression to find (p4)
p3 * v3^gamma = p4 * v4^gamma
p4 = p3 * (v3/v4)^gamma

* After calulation the pressure and volume at 4th process we can find the temperature (t4), using the Ideal gas equation which is,
p3 * v3 / t3 = p4 * v4 / t4
t4 = ((p4 * v4 )*t3) / p3*v3
* Then by knowing all the pressure temperature values at all 4 process we can plot the points using (p1 v1, p2 2, p3 v3 , p4 v4).
* But to connect the points (i.e) to trace the change in pressure and volume during the four process of an otto cycle we are usingthis mathematical expression, in a seperate function program.
v/vc = 1 + 0.5*(cr-1) * [R + 1 - cos(theta) - (R^2 - sin(theta)^2).^0.5]

* Where we take the inputs of bore, stroke, connecting rod length, starting crank and ending crank angle. The staring crank andeneding crank angle is converted to radians.

* Then the number of points (n), we need between stating crank angle and ending crank angle is taken as 50.

* Then the position of the crank is expressed using its momentary angle, by term d_theta, which is calculated by subtracting thecurrent crank value with the starting crank values and dividing it by n-1
* Then we are giving the formula under a 'for loop' with the loop counting from 0 to 50, where the actual theta values whichis the current angle of rotation is specified by d_theta value with respect to each iteration.

* The volume change with repect to the crank angle from (TDC to BDC) is calculated using the function program.
* To trace the change in the volume during the compression ( BDC to TDC which is 180 Degree to 0 Degree) and expansionstroke ( TDC to BDC which is 0 Degree to 180 Degree) is calculated by calling the function at the appropriate places and givingthe starting crank and ending crank angle.


* To find the pressure change with repect to the crank angle, the volume change is related to the pressure change using theisentropic expression inside the for loop. The volume change is used to find the trace of the pressure change too here using theabove mentioned process.
* Now the plotting is made to connect the pressure and volume points using the appropriate change in pressure and volumethat we have calculated using the formula to visualize the actuall PV Diagram of the otto cycle.
* Then the efficiency of the otto cycle is calculated using the below expression,
Efficiency = work done / Amount of Heat added
work done = Amount of Heat added (t3 -t2) - Amount of Heat rejected (t4 -t1),Which gives the amount of heat utilized to convert it into mechanical work.
Efficiency = [(t3 - t2) - (t4 - t1)] / (t3 - t2)
* Finally the efficiency is calculated using this expreesion, Efficiency = 1-((t4-t1)/(t3-t2)).

* Then the plotting of results,

Explanation of the codes:
- All the libraries are imported first.
- A function is created using def engine_kinematics(bore,stroke,con_rod,cr,start_crank,end_crank):command in which allthe variables are the parenthesis.
- Inside the function all the neccessary caculations has been done to store the values in the array V.
- return V command is used to submit all the values in the array V calculated using the for loop.
- Outside the function,all the inputs has been entered.
- Then computing the volume parametrs.
- Then calculating state point 2 and temprature t1.
- Now the function has been called in an array V_compression in which the start crank angle is 180 and end crank angle is 0.
- Using the isentropic process expressions P_compression is also calculated.
- Similarly calculate the V_expansion and P_expansion.
- Calculating the thermal efficiency of the otto cycle.
- plotting all the results in the graph.
Results:


Output :
The Efficiency of the otto cycle for the given input condition is: 0.6298928275128466
At state point 1: Pressure(p1) = 101325 ; temperature(t1) = 500 ; volume(v1) = 0.0008567979964335801
At state point 2: Pressure(p2) = 3285264.621674427 ; temperature(t2) = 1350.960038520613 ; volume(v2) = 7.139983303613168e-05
At state point 3: Pressure(p3) = 5593140.0 ; temperature(t3) = 2300 ; volume(v3) = 7.139983303613168e-05
At state point 4: Pressure(p4) = 172505.1025603998 ; temperature(t4) = 851.246496720453 ; volume(v4) = 0.0008567979964335801
Conclusion :
- The efficiency of the otto cycle is calculated to be = 0.6298, which is 62.98 %.
- Thus the python program is coded to find the otto cycle's efficiency and also to visualize the PV Diagram of the otto cycle.
- The logic used in this python program is the base and for further studies in otto cycle engines this program can be used with
the change of the input parameters as per the study, to find the efficiency and also the pressure, volume at all the four state
points of an otto cycle. - From the above observation and calculated output, we, clearly, can infer that the process of isentropic compression andexpansion is not linear. And the area under the curve also differs between the Ideal and actual Otto cycle.
- As we can see in the thermal Efficiency vs Compression ratio graph, as the compression ratio goes up, thermal efficiencyalso goes up. The efficiency of the Otto cycle is mainly the function of compression ratio for the given gamma value i.e
γ= Cp/Cv.