In [13]:

```
#Input data
d=20.0 #Cylinder bore diameter in cm
L=25.0 #Stroke length in cm
Vc=1570.0 #The clearance volume in cm**3
P1=1.0 #Pressure at the beginning of the compression in bar
T1=300.0 #Temperature at the beginning of the compression in K
T3=1673 #The maximum temperature of the cycle in K
Cv=0.718 #specific heat at constant volume for air in kJ/kgK
R=0.287 #Real gas constant in kJ/kgK
g=1.4 #Isentropic index
c=500.0 #Number of cycles per minute
#Calculations
import math
Vs=(math.pi/4.0)*d**2*L
V1=Vs+Vc
V2=Vc #cm**3
r=V1/V2 #Compression ratio
T2=T1*r**(g-1)
P2=P1*r**g
P3=P2*(T3/T2) #In constant volume, process Pressure at point 3 in bar
T4=T3*(1/r)**(g-1) #In isentropic process, Temperature at point 4 in degree centigrade
P4=P3*(1/r)**(g) #In isentropic process, Pressure at point 4 in bar
no=(1-(1/r)**(g-1))*100 #Air standard efficiency of otto cycle
Q1=Cv*(T3-T2) #Heat supplied in kJ/kg
Q2=Cv*(T4-T1) #Heat rejected in kJ/kg
W=Q1-Q2 #Work done per unit mass in kJ/kg
m=((P1*10**5*V1*10**-6)/(R*T1))/1000.0 #The amount of mass in kg
W1=W*m #Work done in kJ
pm=((W1*10**3)/(Vs*10.0**-6))/10.0**5 #Mean effective pressure in N/m**2
P=W1*(c/60.0) #Power developed in kW
#Output
print"Temperature at point 2 = ",round(T2-273.15,1),"C"
print"Pressure at point 2 =" ,round(P2,2)," bar"
print"Pressure at point 3 = ",round(P3,2),"bar"
print"Temperature at point 4 = ",round(T4-273.15)," C \nPressure at point 4 = ",round(P4,3),"bar"
print"Air standard efficiency of otto cycle = ",round(no,2)," percent "
print"Work done = ",round(W1,2)," kJ"
print"Mean effective pressure = ",round(pm,2),"bar "
print"Power developed = ",round(P,1),"kW "
```

In [15]:

```
#Input data
CV=42000.0 #The calorific value of the fuel in kJ/kg
pa=5.0 #Percentage of compression
Pa=1.2 #Pressure in the cylinder at 5% compression stroke
pb=75 #Percentage of compression
Pb=4.8 #Pressure in the cylinder at 75% compression stroke
g=1.3 #polytropic index
g1=1.4 #Isentropic index
n=0.6 #Air standard efficiency
#Calculations
V=(Pb/Pa)**(1/1.3)#Ratio of volumes
r=(V*(pb/100.0)-(pa/100.0))/((1-(pa/100.0))-(V*(1-(pb/100.0)))) #Compression ratio
n1=((1-(1/r)**(g1-1)))*100 #Relative efficiency
nthj=n*(n1/100.0) #Indicated thermal efficiency
x=(1/(CV*nthj))*3600 #Specific fuel consumption in kg/kW.h
#Output
print"The compression ratio of the engine is ",round(r,1)
print"The specific fuel consumption is ",round(x,3),"kg/kwh"
```

In [29]:

```
#Input data
d=0.2 #The diameter of the cylinder bore in m
L=0.3 #The length of the stroke in m
P1=1 #The pressure at the beginning of the compression in bar
T1=300.0 #The temperature at the beginning of the compression in K
r=16.0 #Compression ratio
V=0.08 #Cutt off takes place at 8& of the stroke
R=0.287 #Real gas constant in kJ/kgK
g=1.4 #Isentropic index
Cp=1.005 #Specific heat at constant prassure in kJ/kgK
Cv=0.718 #specific heat at constant volume for air in kJ/kgK
#Calculations
import math
Vs=(math.pi/4.0)*d**2*L #Swept volume in m**3
Vc=Vs/(r-1) #Clearance volume in m**3
V2=Vc #Volume at point 2 in m**3
V1=Vs+Vc #Volume at point 1 in m**3
m=(P1*10**5*V1)/(R*T1) #The amount of mass in kg
P2=P1*(r**g) #Pressure at point 2 in bar
P3=P2 #Pressure at point 3 in bar
T2=T1*r**(g-1) #Temperature at point 2 in K
V3=(V*Vs)+V2 #Volume at point 3 in m**3
C=V3/V2 #Cut off ratio
T3=C*T2 #Temperature at point 3 in K
P4=P3*(C/r)**g #Pressure at the point 4 in bar
T4=T3*(C/r)**(g-1) #Temperature at point 4 in K
V4=V1 #Volume at point 4 in m**3
Q1=(m*Cp*(T3-T2))/1000.0 #Heat supplied in kJ
Q2=(m*Cv*(T4-T1))/1000.0 #Heat rejected in kJ
W=(Q1-Q2) #Work done per cycle in kJ
na=(W/Q1)*100 #Air standard efficiency
Pm=(W*1000/Vs)/10.0**5 #Mean effective pressure in bar
#Output
print"(a) Volume at point 2 = ",round(V2,5)," m**3 \nVolume at point 1 = ",round(V1,5),"m**3 "
print"Pressure at point 2 = ",round(P2,1)," bar"
print"Temperature at point 2 = ",round(T2,1),"K"
print"beeta is",C,"\nTemperature at point 3 = ",round(T3,0)," K \nPressure at point 4 =",round(P4,3)," bar"
print"Temperature at point 4 = ",round(T4,1)," K \nVolume at point 4 = ",round(V4,5),"m**3"
print"(b) cut off ratio = ",round(c,1)
print"(c) Work done per cycle = ",round(W,3),"kJ"
print"(d) air smath.tandard efficiency = ",round(na,1)," percent"
print"(e)Mean effective pressure = ",round(Pm,2)," bar "
```

In [22]:

```
#given
P1=7
g=1.4
r=12
import numpy as np
from scipy.optimize import fsolve
def f(b):
return P1-1/((g-1)*(r-1))*(g*r**g*(b-1)-r*(b**1.4-1))
b = fsolve(f, 1)
f(b)
na=(1-(1/(r**(g-1)))*(((b**g)-1)/(g*(b-1))))*100 #Air standard efficiency
#Output
print"The cut off ratio = ",round(b,1)," \n The air standard efficiency =",na,"percent"
#NOTE:In the book Answer is wrong for Air standard efficiency .
```

In [30]:

```
#given
m=30.0 #The air fuel ratio by mass
T1=300 #The temperature of air at the beginning of the compression in K
r=16 #The compression ratio
CV=42000 #The calorific value of the fuel in kJ/kg
g=1.4 #Isentropic index
Cp=1.005 #Specific heat at constant prassure in kJ/kgK
#Calculations
T2=T1*(r**(g-1)) #Temperature at point 2 in K
T3=((1/m)*(CV/Cp))+T2 #Temperature at point 3 in K
C=T3/T2 #The cut off ratio
n=(1-((1/r**(g-1))*(((C**g)-1)/(g*(C-1)))))*100#The ideal efficiency of the engine based on the air standard cycle
#Output
print" The ideal efficiency of the engine based on the air standard cycle = ",round(n,1)
```

In [31]:

```
#given
p1=1.0 #Inlet pressure in bar
p2=32.425 #Pressure at the end of isentropic compression in bar
r=6.0 #Ratio of expansion
r1=1.4 #Isentropic index
#Calculations
rc=(p2/p1)**(1/r1) #Compression ratio
b=(rc/r) #cut-off ratio
n=(1-((b**r1-1)/(rc**(r1-1)*r1*(b-1))))*100
pm=((p1*rc**r1*n/100.0*r1*(b-1))/((r1-1)*(rc-1)))
#Output
print"Air-smath efficiency is ",round(n,3),"percent"
print"Mean effective pressure is ",round(pm,3),"bar"
```

In [29]:

```
#Input data
rc=15.0 #Compression ratio
p1=1 #Pressure at which compression begins in bar
T1=27.0+273.0 #Temperature in K
pm=60 #Maximum pressure in bar
h=2 #Heat transfered to air at constant volume is twice that at consmath.tant pressure
g=1.4 #Isentropic index
Cv=0.718 #specific heat at constant volume for air in kJ/kgK
Cp=1.005 #specific heat at constant pressure for air in kJ/kgK
R=0.287 #Real gas constant in kJ/kgK
#Calculations
T2=(T1*rc**(g-1)) #Temperature in K
p2=(p1*rc**g) #Pressure in bar
T3=(T2*(pm/p2)) #Temperature in K
T4=(Cv*(T3-T2))/(2*Cp)+T3 #Temperature in K
b=(T4/T3) #Cut-off ratio
T5=(T4*(b/rc)**(g-1)) #Temperature in K
p5=(p1*(T5/T1)) #Pressure in bar
Q1=(Cv*(T3-T2))+(Cp*(T4-T3))#Heat supplied per unit mass in kJ/kg
Q2=Cv*(T5-T1) #Heat rejected per unit mass in kJ/kg
W=(Q1-Q2) #Workdone in kJ/kg
n=(W/Q1)*100 #Air standard efficiency
Vs=((1*R*1000*T1)/(p1*10**5))*(1-1/rc) #Swept volume in m**3/kg
pmean=((W*1000)/Vs)/10.0**5 #Mean-effective pressure in bar
#Output
print"(a) The pressures and temperatures at the cardinal points of the cycle are "
print"T2 =",round(T2,1)," K \np2 =", round(p2,1)," bar \nT3 = ",round(T3,1), "K \np3 =",round(p3,1),"bar"
print"T4 =",round(T4,1),"K \nT5 = ",round(T5,1), "K \np5 = ",round(p5,1),"bar"
print"(b) The cycle efficiency is",round(n,0),"percent"
print"(c) The mean effective pressure of the cycle is ",round(pmean,1),"bar"
```

In [12]:

```
#Input data
r=12.0 #Compression ratio
B=1.615 #Cut off ratio
p3=52.17 #Maximum pressure in bar
p4=p3 #Maximum pressure in bar
p1=1 #Initial pressure in bar
T1=(62+273) #Initial temperature in K
n=1.35 #Indices of compression and expansion
g=1.4 #Adiabatic exponent
mR=0.287 #Real gas constant in kJ/kgK
Cv=0.718 #specific heat at constant volume for air in kJ/kgK
Cp=1.005 #specific heat at constant pressure for air in kJ/kgK
#Calculations
T2=T1*r**(n-1) #The temperature at point 2 in K
p2=p1*(r)**n #The pressure at point 2 in bar
T3=T2*(p3/p2) #The temperature at point 3 in K
T4=T3*B #The temperature at point 4 in K
T5=T4*(B/r)**(n-1) #The temperature at point 5 in K
Q12=((g-n)/(g-1))*mR*((T1-T2)/(n-1)) # kJ/kg
Q23=Cv*(T3-T2)
Q34=Cp*(T4-T3)
Q45=((g-n)/(g-1))*mR*((T4-T5)/(n-1))
Q51=Cv*(T1-T5)
Q1=Q23+Q34+Q45
Q2=-Q12+(-Q51)
W=Q1-Q2
E=(W/Q1)*100
Vs=((mR*T1)/p1)*(r-1)/r # m**3/kg
pm=(W*1000/Vs)/10.0**3 #Mean effective pressure in bar
#Output
print"(a)The temperature at cardinal points \nT2 =",round(T2,0)," K\nT3 = ",round(T3,0),"K \nT4 = ",round(T4,0),"K \nT5 = ",round(T5,0),"K "
print"(b) The cycle efficiency = ",round(E,1)," percent"
print"(c) The mean effective pressure of the cycle = ",round(pm,3),"bar"
```

In [5]:

```
#Input data
p1=1.0 #Inlet pressure in bar
T1=27.0+273.0 #Temperature in K
p2=4.0 #pressure at point 2 in bar
p3=16.0 #Maximum pressure in bar
Cv=0.573 #specific heat at constant volume for gas in kJ/kgK
Cp=0.761 #specific heat at constant pressure for gas in kJ/kgK
#Calculations
g=(Cp/Cv)
T2=(T1*(p2/p1)**((g-1)/g)) # K
T3=(p3/p2)*T2
T4=T3*(p1/p3)**((g-1)/g)
Q1=Cv*(T3-T2) #kJ/kg
Q2=Cp*(T4-T1)
W=Q1-Q2
n=(W/Q1)*100
r=(p2/p1)**(1/g)
R=(Cp-Cv) #kJ/kg.K
Vs=(R*1000*T1*(r-1))/(p1*10.0**5*r) #m**3/kg
pm=(W/(Vs*100.0))
#Output
print"(a) The work done per kg of gas is ",round(W,1),"kJ/kg"
print"(b) The efficiency of the cycle is ",round(n,1),"percent "
print"(c) Mean effective pressure is ",round(pm,1),"bar"
```