Week 2 Air standard Cycle
AIM: Write a python program for an Otto Cycle and make plots for it.
Objective:
The objective of the project is to write a python program for an Otto Cycle and make a PV graph of their output result. Also caclulate thier thermal efficiency of the engine.
Concept of Otto Cycle
The Otto cycle is a cycle of engine operation which requires four strokes of the piston: for induction, compression, ignition, and exhaust. The fuel and air mixture is compressed before combustion is started by an electrical spark, in which the combustion of the working fluid-gasoline and air (oxygen), changes the motion in the piston.
PV and TS diagram of an Otto Cycle
For better understanding, these are the following step on the PV diagram of an Otto cycle
- Process 1 to 2: Adiabatic Compression
- Process 2 to 3: Constant pressure heat addition
- Process 3 to 4: Adiabatic Expansion
- Process 4 to 1: Constant pressure heat rejection
Basic Equation:
For Adiabatic Process:
`P.(V)^gamma = Constant`
Ideal Gas law:
`(P.V)/T = constant`
Variation of Volume in cylinder with crank angle is given by:
`V/(Vc) = 1 + 1/2*(Cr - 1)[R + 1 - costheta - (R^2 - sin^2theta)^(1/2)]`
Where, `R`= Connecting rod length / Crank pin radius
Crank pin radius = stroke/2
Cr = Compression ratio
`Vc` = Clearance volume
P = pressure
V = volume
T = temperatute
Thermal Efficiency,
`ita (%) = [1 - (1/(cr^(gamma - 1)))]* 100` (in percent)
PROCEDURE AND EXPLAINATION FOR PYTHON
Step-1: Before writing the program first we have to import command to import libraries which will be used in mathematical operation and plotting.

Step-2: Basic Program
First, we are going to do the basic program with the help of defined state variable points.
Basic_Code

Step-3: Defining Engine Kinematics function
To plot correctly, we need the following two things.
- Thermodynamic relation during compression and Expansion.
- Piston kinematics to determine How the volume change from TDC to BDC and how combustion volume changes as a function of the crank angle.
Here, we are taking all the parameters the same as discussed in step 1 and 2, but we need a different formula for the calculation of the volume change inside the combustion chamber. The required relationship we can get by the following formula. The Formula for the Engine kinematics is as follows.
`V/(Vc) = 1 + 1/2*(Cr - 1)[R + 1 - costheta - (R^2 - sin^2theta)^(1/2)]`
To use this formula in the program we simplified it. Hence, To simplify the formula we divided formula into three sub formulas (terms) as follows.
`term1 = 0.5 * (cr - 1)`
`term2 = 1 + R - costheta`
`term3 = (R^2 - sin^2theta)^(1/2)`
At last, After combining the terms to get the final formula,
`V = (1 + term1*(term2 - term3))*Vc`
After that our Engine kinematics formula is used as a function in the program is as shown below.

Where:
- We need the formula of engine kinematics to create the volume Arrays concerning the compression and Expansion Processes. After that, we can use it in our Otto cycle Program. Also, we need to calculate the pressure that corresponds to the volume. Therefore, We defined the Engine kinematics as the function.
- Since we have a function so we need not pre-define the value of the parameters related to it such as values of bore, stroke, connecting rod length, etc.
- Now defining the sc and ec (i.e starting crank angle and ending crank angle). Because we want to get several values between the starting crank and ending crank position and each of those values we need to get the volume. hence using ec and sc and assigning it to the dtheta which is known as a crank angle spacing. Also defined the number of values is equal to 50 as follows.

- Now we can form a crank angle array. to do that we are using for-loop. For loop use to repeat the set of actions multiple times. The empty volume array indicates that when for loop executed each time the value calculated in the for-loop gets store in the empty array.
- But to generate the multiple values we need one more command called as append.".append" is used to continuously append (increase) the value and store it in the empty array.
- using "return V" to get multiple output values of volume.
Step-4: Defining the Compression and Expansion processes
To define the compression and Expansion processes in the program we took help to the engine kinematic function as shown below.
State point 2 (Compression process)

State point 3 (expansion process)

Where:
For loop is used to get multiple values of the volume and pressure and store it in the empty array using Append command.
For compression, the taken starting crank angle is at 180 degrees and the ending crank angle is 0 degree (i.e piston moves from BDC to TDC). Similarly, For Expansion, the taken starting crank angle is at 0 degrees and the ending crank angle is 180 degrees (i.e piston moves from TDC to BDC).
Note: Here We took the crank angle for reference to the compression and expansion process not a movement of the piston. Also, suction and exhaust are neglected.
Step-5: Calculating Thermal Efficiency
We are using the efficiency formula for the ideal otto cycle in percentage so that we can determine the efficiency of the otto cycle. The Thermal efficiency formula in percentage is as following.
`ita (%) = [1 - (1/(cr^(gamma - 1)))]* 100`

Step-6: Creating Plot
After defining all the terms we need the output so to do that we are using the plot command and plotted all the processes.
After properly arranging the program we get out the desired program and output which is shown below.

Python Program (Final):
By Executing the Program we get our required output as,
- Otto cycle plot of PV diagram and
- Thermal efficiency in percentage.
1. PV Diagram
Compression ratio = 8

Now we can see that the compression and expansion process in the above figure is a curve, which is practically possible but in previous PV graph it shown linear which is not acceptable but now in the above figure adiabatic process is a curve.
2. Thermal Efficiency ( in percentage)
Thermal Efficincy = `56.47%`

CONCLUSION
We create a program for Air Standard Cycle (Otto Cycle) with the help of Python. And plot the output result of PV diagram, also demonstrate thermal efficiency of otto cycle.