In [3]:

```
#given
r=8.5 #The compression ratio
sv=1.4 #The specific heat at constant volume in percent
#Calculations
import math
n=1-(1/r)**(sv-1)
ef=(((1-n)/n)*(sv-1)*(math.log(r))*(sv/100.0))*100
#Output
print"The efficiency decreases by ",round(ef,3),"percent"
```

In [5]:

```
#given
r=18.0 #The compression ratio
l=6.0 #The cut off taking place corresponding of the stroke in percent
sc=2.0 #The specific heat at constant volume increases in percent
cv=0.717 #The specific heat at constant volume in kJ/kgK
R=0.287 #Gas constant in kJ/kgK
#Calculations
import math
Vs=(r-1)
B=((l/100.0)*Vs)+1
cp=cv+R
R1=cp/cv
n=1-(((((1/r)**(R1-1))*(B**R1-1))/(R1*(B-1))))
dn=(((1-n)/n)*((R1-1)*((math.log(r))-(((B**R1)*math.log(B))/(B**R1-1))+(1/B)))*(sc/100.0))*100
#Output
print"The efficiency decreases by ",round(dn,1),"percent"
```

In [4]:

```
#given
r=8 #The compression ratio
af=15 #Air/fuel ratio
p1=1 #The pressure at the beginning of a compression stroke in bar
t=60 #The temperature at the beginning of a compression stroke in degree centigrade
cv=44000 #The calorific value of the fuel in kJ/kg
n=1.32 #The index of the compression
Cv=0.717 #specific heat at constant volume in kJ/kgK
#Calculations
T1=t+273
p2=p1*(r)**n
T2=T1*r**(n-1)
f=(1/(af+1))
a=(af/(af+1))
q23=cv/(af+1)
T3=((-10430+((10430)**2+(4*494.8*10**5))**(1/2.0))/2.0)
p3=(T3/T1)*(r)*p1
T31=(q23/Cv)+T2
p31=(T31/T1)*r*p1
#Output
print"(a) The Maximum temperature in the cylinder = ",round(T3,0),"K"
print"The Maximum pressure in the cylinder P3 = ",round(p3,0),"bar"
print"(b)With constant value of Cv "
print"The Maximum temperature in the cylinder = ",round(T31,0),"K"
print"The Maximum pressure in the cylinder P3 = ",round(p31,1),"bar"
```

In [10]:

```
#given
r=21 #The compression ratio
af=29 #Air/fuel ratio
T=1000 #The temperature at the end of compression in K
cv=42000 #The calorific value of the in kJ/kg
R=0.287 #Gas constant in kJ/kgK
#Calculations
q23=cv/(af+1)
T3=(-0.997+(((0.997)**2)+(4*2411*14*10**-6))**(1/2.0))/(28.0*10.0**-6)
V3=(T3/T)
Vs=(r-1)
V=V3-1
pc=(V/Vs)*100
#Output
print"The percentage of stroke at which combustion is complete = ",round(pc,3),"percent"
```

In [32]:

```
#given
r=16.0 #The compression ratio
l=6.0 #The cut-off of the stroke in percent
p3=70.0 #The maximum pressure obtained in bar
p1=1.0 #The pressure at the beginning of compression in bar
T1=(100.0+273.0) #The temperature at the beginning of compression in K
R=0.287 #Gas constant in kJ/kgK
g=1.4 #Assume the isentropic index
#Calculations
T2=T1*(r)**(g-1)
Cv=(1/(T2-T1))*(0.716+125*10**-6*(T2**2-T1**2))
Cp=Cv+R
g1=Cp/Cv
T21=T1*(r)**(g1-1)
Cv1=(1/(T21-T1))*((0.716+125*10**-6*(T21**2-T1**2)))
Cp1=Cv1+R
g2=Cp1/Cv1
gm=1.358 #mean value
T22=T1*(r)**(gm-1)
p2=(T22/T1)*r*p1
T3=(p3/p2)*T22
V=((l/100.0)*(r-1))+1
T4=(V)*T3
p4=p3
g3=1.3
V5=r/V
T5=T4*(1/V5)**(g3-1)
Cv2=((0.716*(T5-T4))+(62.5*10**-6*(T5**2-T4**2)))/(T5-T4)
Cp2=Cv2+R
g4=Cp2/Cv2
T51=T4*(1/V5)**(g4-1)
Cv3=((0.716*(T51-T4))+(62.5*10**-6*(T51**2-T4**2)))/(T51-T4)
Cp3=Cv3+R
g5=Cp3/Cv3
T52=T4*(1/V5)**(g5-1)
p5=(T52/T1)*p1
#Output
print"The pressure and temperature at all points of the cycle \nat point 2: Temperature T2 = ",round(T22,0),"K and Pressure P2 = ",round(p2,2)," bar"
print"at point 3 :Temperature T3 = ",round(T3,1)," K and Pressure P3 = ",p3," bar"
print"at point 4 : Temperature T4 = ",T4," K and Pressure P4 = ",p4,"bar"
print"at point 5 :Temperature T5 = ",round(T52,0)," K and Pressure P5 = ",round(p5,2),"bar"
```

In [8]:

```
#given
r=8 #Compression ratio
lcv=44000 #The lower heating value of the fuel in kJ/kg
af=15 #The air/fuel ratio
Cv=0.71 #The specific heat at constant volume in kJ/kgK
p=1 #The pressure at the beginning of the compression in bar
t=60 #The temperature at the beginning of the compression in degree centigrade
Mo=32 #Molecular weight of oxygen
Mn=28.161 #Molecular weight of nitrogen
Mh=18 #Molecular weight of water
n=1.3 #Polytrpic index
#Calculations
T1=(t+273)
sa=(12.5*(Mo+(3.76*Mn)))/((12*8)+(1*Mh))
Y=af*(((12*8)+(1*Mh))/(Mo+(3.76*Mn)))
x=(12.5-Y)*2
nb=1+Y+(Y*3.76)
na=x+7.8+9+46.624
Me=((na-nb)/nb)*100
T2=T1*(r)**(n-1)
T3=(lcv/(af+1))*(1/Cv)+(T2)
p3=r*(T3/T1)*p
p31=p3*(na/nb)
#Output
print"The percentage molecular expansion is ",round(Me,0),"percent"
print"(a) Without considering the molecular expansion "
print" The maximum temperature is ",round(T3,0),"K"
print"The maximum pressure is ",round(p3,0),"bar"
print"(b) With molecular expansion "
print"The maximum temperature is ",round(T3,0),"K"
print"The maximum pressure is ",round(p31,1),"bar"
```

In [11]:

```
#given
f=0.03 #The residual fraction of an engine
e=1.2 #The equivalence ratio
F=0.0795 #Fuel/air ratio for corresponding equivalence ratio
#Calculations
T=1+F
fa=1-f
ff=F*(fa)
ra=f
rf=ra*F
#Output
print"Fresh air = ",fa,"kg"
print"Fresh fuel = ",ff,"kg"
print"Air in residual = ",ra,"kg"
print"Fuel in residual = ",rf,"kg"
```

In [14]:

```
#given
T=800 #The given temperature in K
e=1 #The equivalence ratio
hi=154.723 #Sensible Enthalpy for isooctane at 800 K in MJ/kmol
ho=15.841 #Sensible Enthalpy for oxygen at 800 K in MJ/kmol
hn=15.046 #Sensible Enthalpy for nitrogen at 800 K in MJ/kmol
nc=0.00058 #Number of kmoles of C8H18 for equivalence ratio for 1 kg of air
no=0.00725 #Number of kmoles of oxygen for equivalence ratio for 1 kg of air
nn=0.0273 #Number of kmoles of nitrogen for equivalence ratio for 1 kg of air
R=8.314 #Gas constant in kJ/kgK
#Calculations
Hs=(nc*hi)+(no*ho)+(nn*hn)
Hs1=Hs*1000
n=nc+no+nn
Us=Hs-(n*R*10**-3*(T-298))
Us1=Us*1000
#Output
print"Total sensible enthalpy of reactants = ",round(Hs1,3),"kJ/kg air"
print"Sensible internal energy of reactants = ",round(Us1,3),"kJ/kg air"
```

In [8]:

```
#given
T=500.0 #The given temperature in K
e=1.0 #Equivalence ratio
Ai=0.0662 #The amount of isooctane for 1 kg of air in kg
Ta=298.0 #Consider the ambient temperature in K
R=8.314 #Gas constant in kJ/kgK
#Calculations
import math
E=((0.0662*((0.44*math.log(T/Ta))+(3.67*10**-3*(T-Ta))))+((0.921*math.log(T/Ta))+(2.31*10**-4*(T-Ta))))*1000
Ri=Ri/114.0
W=(0.5874-(0.662*Ri*math.log(T/Ta))-(0.287*math.log(T/Ta)))*1000
#Output
print"The isentropic compression functions at 500 K for the unburned"
print"isooctsne-air mixture are ",round(E,1),"J/kg air and",round(W,1),"J/kg air"
```

In [13]:

```
#given
r=7.8 #Compression ratio
p=1.0 #The pressure at the start of compression in atm
T1=335.0 #The temperature at the start of compression in K
W1=100 #Isentropic compression function for T1 in J/kg air K
T2=645 #The temperature corresponding to isentropic compression function in J/kg air K
U1=35 #Internal energy corresponding to temp T1 in kJ/kg air
U2=310 #Internal energy corresponding to temp T2 in kJ/kg air
E1=120 #Isentropic compression function at T1
E2=910 #Isentropic compression function at T2
#Calculations
import math
W2=W1-(292*math.log(1/r))
V1=(292*T1)/(p*10.0**5)
p2=p*(T2/T1)*r
V2=V1/r
W=U2-U1
p21=(math.exp((E2-E1)/292.0))
#Output
print"(a)At the end of the compression stroke"
print"The temperature is ",T2,"K"
print"The pressure is ",round(p2,0),"atm"
print"The volume per unit mass of air is ",round(V2,3),"m**3/kg air"
print"The pressure is ",round(p21,0),"atm"
print"(b)The work input during compression is ",W,"kJ/kg air"
```

In [22]:

```
#given
p=65 #The pressure in the cylinder in bar
r=10 #The compression ratio
V3=0.1 #The volume per unit mass of air at the start of expansion in m**3/kg air
p3=p*100 #The pressure in the cylinder after the completion of combustion in kN/m**2
T3=2240 #The temperature from the chart corresponding to p3,V3 in K
u3=-1040 #The energy from the chart in kJ/kg air
s3=8.87 #The entropy from the chart in kJ/kg air K
T4=1280 #The temperature from the chart corresponding to p4,V4 in K
u4=-2220 #The energy from the chart in kJ/kg air
p4=4.25 #The pressure from the chart in bar
#Calculations
s4=s3
V4=r*V3
W=-(u4-u3)
#Output
print"(a)At the end of expansion stroke"
print"The pressure is ",p4,"bar"
print"The temperature is ",T4,"K"
print"The volume is ",V4,"m**3/kg air"
print"(b)The work during the expansion stroke is ",W,"kJ/kg air"
```

In [31]:

```
#Given
#From Table 4.4
H1=-224.1*1000 #MJ/mol, Enthalpy of C8H18
H2=-393.52*1000 #Enthalpy of CO2
H3=-241.82*1000 #Enthalpy of H2O
U1=-204.1*1000 #MJ/mol, Internal energyof C8H18
U2=-393.52*1000 #Internal energy of CO2
U3=-240.6*1000 #Internal energy of H2O
M1=114.0 #g, molecular wt of C8H18
M2=32.0 #g, molecular wt of O2
M3=28.0 #g, molecular wt of N2
M4=44.0 #g, molecular wt of CO2
M5=18.0 #g, molecular wt of H2O
#For 1 kg air, from the eq., the fraction of wt are
x1=0.0661
x2=0.232
x3=0.768
x4=0.204
x5=0.094
#Calculation
import sympy
f=sympy.Symbol("f")
n1=(x1/M1)*(1-f) #No. of kmoles of C8H18
n2=x2/M2*(1-f)
n3=x3/M3
n4=x4/M4*f
n5=x5/M5*f
N1=(n1*H1+n4*H2+n5*H3)
N2=n1*U1+n4*U2+n5*U3
#Result
print "Standard Enthalpy of formation is",N1
print "Internal energy of formation is",N2
```

In [14]:

```
#given
Tu=645.0 #The temperature at the end of compression process in K
usu=310.0 #The internal energy at the end of compression process in kJ/kg air
pu=(15.4*1.013) #The pressure at the end of the compression process in bar
Vu=0.124 #The volume at the end of the compression process in m**3/kg air
e=1.0 #Equivalence ratio
f=0.065 #Burned gas fraction
Tb=2820.0 #The temperature for constant volume
pb=6500.0 #The pressure for constant volume
hsu=440.0 #The enthalpy from chart corresponding to temp Tu in kJ/kg air
pb1=1560.0 #The pressure for constant pressure adiabatic combustion in kN/m**2
ub1=-700.0 #Trail and error along the pb internal energy in kJ/kg air
Tb1=2420.0 #The temperature for constant pressure
#Calculations
ufu=-118.5-(2963*f)
ub=usu-ufu
Vb=Vu
hfu=-129.9-(2958*f)
hb=hsu+hfu
vb1=(118-ub1)/pb
#Output
print"(a)For constant volume adiabatic combustion"
print"The temperature is ",Tb,"K"
print"The pressure is ",pb,"kN/m**2"
print"(b)For constant pressure adiabatic combustion"
print"The temperature is ",Tb1,"K"
print"The pressure is ",pb1,"kN/m**2"
```

In [4]:

```
#given
r=8.0 #The compression ratio
T1=350.0 #The given temperature at the start of compression in K
p=1.0 #The given pressure at the start of compression in bar
f=0.08 #The exhaust residual fraction
cv=44000 #The calorific value in kJ/kg
W1=150 #Isentropic compression functions for corresponding temp T1 in J/kg air K
T2=682 #The temperature corresponding to isentropic compression function in K
us2=350 #The internal energy corresponding to temp T2 in K
us1=40 #The internal energy corresponding to temp T1 in K
T3=2825 #The temperature at point 3 corresponding to u3,V3 on the burned gas chart in K
p3=7100 #The pressure at point 3 in kN/m**2
s3=9.33 #Entropy at point 3 in kJ/kg air K
u4=-1540 #The internal energy at point 4 corresponding to V4,s4 in kJ/kg air
p4=570 #The pressure at point 4 in kN/m**2
T4=1840 #The temperature at point 4 in K
#Calculations
import math
W2=W1-(292*math.log(1/r))
V1=(292*T1)/(p*10.0**5)
p2=p*(T2/T1)*r
V2=V1/r
Wc=us2-us1
ufu=-118.5-(2963*f)
u3=us2+ufu
V3=V2
s4=s3
V4=V1
We=u3-u4
Wn=We-Wc
nth=((Wn)/((1-f)*0.0662*cv))*100
imep=((Wn*1000)/(V1-V2))/10.0**5
nv=(((1-f)*287*298)/(1.013*10**5*(1-0.125)))*100
#Output
print"(a)At point 2, \nThe temperature is ",T2," K \nThe pressure is ",round(p2,1),"atm"
print"At point 3, \nThe temperature is ",T3," K \nThe pressure is ",p3,"kN/m**2"
print"At point 4, \nThe temperature is ",T4," K \nThe pressure is ",p4,"kN/m**2"
print"(b)The indicated thermal efficiency is ",round(nth,1),"percent"
print"(c)The indicated mean effective pressure is ",round(imep,0)," bar"
print"(d)The volumetric efficiency is ",round(nv,2), "percent"
```