Week 2 Air standard Cycle
OBJECTIVE
In this code, we will simply calculate the thermal efficiency and create an OTTO-CYCLE curve which shows V-P diagram
of an internal combustion engine which has compression ratio=8 and gamma=1.4 values.
PROBLEM STATEMENT
Otto cycle is an idealized thermo-dynamic cycle used to understand how change Volume and Pressure in internal combustine engine.
In this cycle, adiabatic assumptions are done for compression and expansion phases. During these phases V-P curve is not linear
and changing as parabolic depending on crank angle. The effect of changing the crank angle on Volume and Pressure must be consider
to obtain more realistic diagram.
SOLUTION PROCEDURE
Adiabatic compression and expression are similar in terms of their curve characteristic. In order to not to write two times their codes,
functions in python can be preferred with "def" syntax then can be called whenever it is needed.
RESULTS
Moving from State Point 1 to State Point 2(Compression phase) , Volume decrease while pressure increase based on adiabatic assumptions and relations. Inverse effect of that
is seen in expansion process.
moving From State 2 to 3(igniton phase), and moving from 4 to 1(heat rejection phase) Volume is constant while pressure increasing.
DISCUSSION
To use function in a code make its length short to provide the code easy-to-read.

"""
OTTO CYCLE SIMULATOR
Provided by omerfarukgumus
"""
import math
import matplotlib.pyplot as plt
#Definiton of function to obtain more realistic V-P diagram.
#It can be used to create infinite Volume and Pressure values depending on crank angle
#This function can represent both compression(From State 1 to State 2) and expansion(From State 3 to State 4)
def engine_kinematics(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)
sc=math.radians(start_crank)
ec=math.radians(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)
V.append((1+term1*(term2-pow(term3,0.5)))*V_c)
return V
#INPUTS for OTTO-CYCLE
#CHAMBER CONDITIONS
p1=101325 #Pa
t1=500 #Kelvin
gamma=1.4
t3=2300
#GEOMETRIC PARAMETERS
bore= 0.1 #meter
stroke= 0.1 #meter
con_rod=0.15 #meter
cr=8 #compression ratio, =Total volume/Clearence volume
#rhs = Characteristic Gas Constant
#VOLUME COMPUTING
Vs=(math.pi/4)*pow(bore,2)*stroke #Swept Volume(Displacement Volume) It is the volume swept through by the piston in moving between TDC and BDC
Vc=Vs/(cr-1) #Clearence Volume
V1=Vs+Vc #Volume at state point Number 1
# ADIABATIC COMPRESSION PROCESS DEPENDING ON CRANK ANGLE
V_compression=engine_kinematics(bore, stroke, con_rod, cr, 0,180)
constant=p1*pow(V1,gamma)
P_compression=[]
for vcomp in V_compression:
P_compression.append(constant/pow(vcomp,gamma))
#STATE 2 (IGNITION PHASE)
V2 = Vc
#p2v2^gamma=p1v1^gamma izontropic relation
p2=p1*pow(V1,gamma)/pow(V2,gamma)
#p2v2/t2=p1v1/t1 | rhs=p1v1/t1 | p2v2/t2=rhs | t2=p2v2/rhs
rhs=p2*V2/t1
t2=p2*V2/rhs
#STATE 3
V3=V2
#p3v3/t2=p2v2/t2 | rhs=p2v2/t2 | p3=rhs*t3/V3 | t3=p3v3/rhs
rhs=p2*V2/t2
p3=rhs*t3/V3
#ADIABATIC EXPANSION PROCESS DEPENDING ON CRANK ANGLE
V_expansion=engine_kinematics(bore, stroke, con_rod, cr, 180,0)
constant=p3*pow(V3,gamma)
P_expansion=[]
for vexp in V_expansion:
P_expansion.append(constant/pow(vexp,gamma))
#STATE 4 (HEAT REJECTION PHASE)
V4=V1
#p4V4^gamma=p3v3^gamma
p4=p3*pow(V3,gamma)/pow(V4,gamma)
#p4v4/t4=rhs
t4=p4*V4/rhs
#THERMAL EFFICIENCY
# n_eff=1-(1/Compression Ratio^(gamma-1)
n_eff=1-1/pow(cr,gamma-1)
print('Thermal Efficiency=',n_eff)
plt.plot([V2, V3],[p2,p3])
plt.plot([V4,V1],[p4,p1])
plt.plot(V_compression,P_compression)
plt.plot(V_expansion,P_expansion)
plt.show()