# Chapter 4 : The Second law of thermodynamics and its applications¶

## Example 4.1 page : 101¶

In [2]:

# Variables
T = 500. 			#K
Qr = 5.*10**6 			#kJ
T2 = 600. 			#K

# Calculations
dSS = Qr/T
dSS2 = -Qr/T2
Ds = dSS+dSS2

# Results
print "Entropy change of the system  =  %d kJ/K"%(dSS)
print " Entropy change of the surroundings  =  %d kJ/K"%(dSS2)
print " Entropy change if the universe  =  %.f kJ/K"%(Ds)

Entropy change of the system  =  10000 kJ/K
Entropy change of the surroundings  =  -8333 kJ/K
Entropy change if the universe  =  1667 kJ/K


## Example 4.2 page : 104¶

In [4]:
import math

# Variables
p1 = 2.758 			#Mpa
p2 = 0.552 			#Mpa
T1 = 700. 			#K
T2 = 700. 			#K
n = 1.
R = 8.3143
Cv = 21.
Cp = 29.3

# Calculations
dsa = n*R*math.log(p1/p2)
T3 = 437.5 			#K
dsb = Cv*math.log(T3/T2)
T4 = 350. 			#K
dsc = Cp*math.log(T4/T3)
T5 = 634. 			#K
dsd = 0.
T6 = 700. 			#K
dse = Cp*math.log(T6/T5)
dstotal = dsa+dsb+dsc+dsd+dse

# Results
print "Entropy change in case a  =  %.3f kJ/kmol K"%(dsa)
print " Entropy change in case b  =  %.3f kJ/kmol K"%(dsb)
print " Entropy change in case c  =  %.3f kJ/kmol K"%(dsc)
print " Entropy change in case d  =  %.3f kJ/kmol K"%(dsd)
print " Entropy change in case e  =  %.3f kJ/kmol K"%(dse)
print " Entropy change in total process  =  %.3f kJ/kmol K"%(dstotal)

Entropy change in case a  =  13.375 kJ/kmol K
Entropy change in case b  =  -9.870 kJ/kmol K
Entropy change in case c  =  -6.538 kJ/kmol K
Entropy change in case d  =  0.000 kJ/kmol K
Entropy change in case e  =  2.902 kJ/kmol K
Entropy change in total process  =  -0.131 kJ/kmol K


## Example 4.3 page : 105¶

In [5]:
import math

# Variables
ratio = 1./2
R = 8.314
p1 = 0.5 			#kPa
p2 = 0.1 			#kPa

# Calculations
ya = ratio/(1+ratio)
ds = -ya*R*math.log(ya) - (1-ya)*R*math.log(1-ya)
dss = R*math.log(p1/p2)

# Results
print "Entropy of mixing  =  %.3f kJ/kmol K"%(ds)
print " Total entropy change of the universe  =  %.2f kJ/kmol K"%(dss)

Entropy of mixing  =  5.292 kJ/kmol K
Total entropy change of the universe  =  13.38 kJ/kmol K


## Example 4.4 page : 106¶

In [7]:
import math

# Variables
s1 = 7.096 			#kJ/kg K
s2 = 7.915  			#kJ/kg K
s3 = 7.16  			#kJ/kg K
s4 = 7.014  			#kJ/kg K
s5 = 6.999  			#kJ/kg K

# Calculations
dsa = s2-s1
dsb = s3-s2
dsc = s4-s3
dsd = s5-s4
dse = s1-s5
dstotal = dsa+dsb+dsc+dsd+dse

# Results
print "Change in entropy in process a  = %.3f  kJ/kg K"%(dsa)
print " Change in entropy in process b  = %.3f  kJ/kg K"%(dsb)
print " Change in entropy in process c  = %.2f  kJ/kg K"%(dsc)
print " Change in entropy in process d  = %.3f  kJ/kg K"%(dsd)
print " Change in entropy in process e  = %.3f  kJ/kg K"%(dse)
print " Change in entropy in total process   = %.3f  kJ/kg K"%(dstotal)

Change in entropy in process a  = 0.819  kJ/kg K
Change in entropy in process b  = -0.755  kJ/kg K
Change in entropy in process c  = -0.15  kJ/kg K
Change in entropy in process d  = -0.015  kJ/kg K
Change in entropy in process e  = 0.097  kJ/kg K
Change in entropy in total process   = 0.000  kJ/kg K


## Example 4.5 page : 106¶

In [9]:
import math

# Variables
m1 = 5000. 			#kg/h
cp1 = 3.2 			#kJ/kg K
cp2 = 4.186 			#kJ/kg K
t1 = 220. 			#C
t2 = 30. 			#C
T1 = 210. 			#C
T2 = 20. 			#C

# Calculations
m2 = m1*cp1*(t1-t2)/(cp2*(T1-T2))
ds = m1*cp1*math.log((t2+273.1)/(t1+273.1)) + m2*cp2*math.log((T1+273.1)/(T2+273.1))

# Results
print "Change in entropy  =  %.f kJ/h K"%(ds)

Change in entropy  =  209 kJ/h K


## Example 4.6 page : 111¶

In [10]:

# Variables
s1 = 218.8 			#kJ/kmol K
s2 = 188.85 			#kJ/kmol K
s3 = 237.8 			#kJ/kmol K
s4 = 205.2 			#kJ/kmol K

# Calculations
ds = s1+s2-s3-0.5*s4

# Results
print "Entropy change   =  %.2f kJ/kmol K"%(ds)

Entropy change   =  67.25 kJ/kmol K


## Example 4.7 page : 112¶

In [11]:

# Variables
Q = 6. 			#kJ/kg
p1 = 1.5 			#Mpa
p2 = 0.1 			#Mpa
t1 = 500. 			#C
t2 = 140.8 			#C
h1 = 3473.1 			#kJ
h2 = 2758.1 			#kJ
s1 = 7.5698 			#kJ/K
s2 = 7.5698 			#kJ/K
eff = 0.85
Ts = 293.1 			#K

# Calculations
Wideal = h2-h1
Ws = eff*Wideal
dH = -Q-Ws
H2 = h1+dH
S2 = 7.8005
ds = S2-s1
Wlost = Ts*ds+Q

# Results
print "lost work  =  %.1f kJ"%(Wlost)

lost work  =  73.6 kJ


## Example 4.8 page : 113¶

In [14]:
import math

# Variables
m = 5000. 			#/kg/h
cp = 3.2 			#kJ/kg K
Ts = 30.+273.1 			#K
t1 = 220. 			#C
t2 = 40. 			#C
Q = 2.88*10**6 			#kJ

# Calculations
Q = m*cp*(t2-t1)
dss = m*cp*math.log((t2+273.1)/(t1+273.1))
Wlost = Ts*dss-Q
eff = Ts*dss/Q

# Results
print "Lost work  =  %d kJ"%round(Wlost,-4)
print " Efficiency  =  %.3f"%(eff)

Lost work  =  680000 kJ
Efficiency  =  0.765


## Example 4.9 page : 114¶

In [15]:
import math

# Variables
R = 8.314
cp = 35.58
n = 100./16
T1 = 300. 			#K
T2 = 500. 			#K
k = 1.305
P2 = 3. 			#Mpa
P1 = 0.5 			#Mpa
Ts = 290. 			#K

# Calculations
cv = cp-R
Wi = n*R*T1/(k-1) *((P2/P1)**((k-1)/k) -1)
Hi = Wi
Ha = n*cp*(T2-T1)
eta = abs(Hi/Ha)
dss1 = cp*math.log(T2/T1) - R*math.log(P2/P1)
Wl1 = Ts*dss1
dss2 = n*cp*math.log(T2/T1)
dss3 = abs(Ha/Ts)
dsst = dss2+dss3
Wl2 = -Ts*dss2 +Ha
Wlost = Wl1+Wl2

# Results
print "Thermodynamic efficiency  =  %.3f"%(eta)
print " Net work lost  =  %d kJ"%(Wlost)

Thermodynamic efficiency  =  0.598
Net work lost  =  12483 kJ


## Example 4.10 page : 119¶

In [16]:

# Variables
T1 = 673. 			#K
T2 = 293. 			#K

# Calculations
eta = (T1-T2)/T1

# Results
if eta >= 0.5:
print "Max efficiency   =  %.3f and an efficiency of 0.5 is possible"%(eta)
else:
print "Max efficiency   =  %.3f and an efficiency of 0.5 is not possible"%(eta)

Max efficiency   =  0.565 and an efficiency of 0.5 is possible


## Example 4.11 page : 121¶

In [17]:

# Variables
T1 = 280. 			#K
T2 = 300. 			#K

# Calculations
cop = T1/(T2-T1)

# Results
print "coefficient of performance  =  %.1f"%(cop)

coefficient of performance  =  14.0


## Example 4.12 page : 123¶

In [18]:

# Variables
P = 2. 			#Mpa
T1 = 212.4+273.1 			#K
T2 = 25+273.1 			#K
h1 = 2799.5
h2 = 104.89
s1 = 6.3409
s2 = 0.3674

# Calculations
dh = h1-h2
ds = s1-s2
exergy = dh-T2*ds

# Results
print "exergy  =  %.1f kJ/kg"%(exergy)

exergy  =  913.9 kJ/kg


## Example 4.13 page : 126¶

In [22]:
import math

# Variables
R = 8314.3
T = 700. 			#K
T2 = 437.5 			#K
T3 = 350. 			#K
T4 = T3
p2 = 0.552 			#Mpa
p1 = 2.758 			#Mpa
p3 = 0.345  			#Mpa
cp = 29.3
R0 = 8.3143
k = 1.4
n = 1.
P0 = 0.103 			#Mpa

# Calculations
cv = cp-R0
p3 = p2*T3/T2
p3 = 0.345
T5 = T4*(p1/p3)**((k-1)/k)
G1 = n*R*T*math.log(p2/p1)
V700 = R*10**3 *T/(p2*10**9)
Sa =  209.
Sb = 199.2
Sc = 204.7
S2 = (T2-T)/6 *(Sa+4*Sc+Sb    )
G2 = V700*(p3-p2)*10**3 -S2
saa = 199.2
sbb = 192.6
savg = (saa+sbb)*0.5
G3 = -savg*(T3-T2)
pmid = (p3+p2)/2
vmid = 2.88
sav = 192.7
v4 = 8.435 			#m**3
v5 = 1.911 			#m**3
integ = (p1-p3)*10**3 /6 *(v4+4*vmid+v5)
G4 = integ - sav*(T5-T3)
Sav = 194.25
G5 =  -Sav*(T-T5)
Gt = G1/10**3 +G2+G3+G4+G5

# Results
print "in case 1, Change in gibbs free energy  =  %.f kJ"%(G1/10**3)
print " in case 2, Change in gibbs free energy  =  %.f kJ"%(G2)
print " in case 3, Change in gibbs free energy  =  %d kJ"%(G3)
print " in case 4, Change in gibbs free energy  =  %d kJ"%(G4)
print " in case 5, Change in gibbs free energy  =  %d kJ"%(G5)
print " Net change in gibbs energy  =  %d kJ"%(Gt)

# note : rounding off error.

in case 1, Change in gibbs free energy  =  -9363 kJ
in case 2, Change in gibbs free energy  =  51499 kJ
in case 3, Change in gibbs free energy  =  17141 kJ
in case 4, Change in gibbs free energy  =  -45908 kJ
in case 5, Change in gibbs free energy  =  -12844 kJ
Net change in gibbs energy  =  523 kJ


## Example 4.14 page : 130¶

In [23]:
import math

# Variables
v = 1./430
pi = 4.08 			#Mpa
pf = 10. 			#Mpa
pf2 = 1. 			#Mpa
pii = 0.1 			#Mpa
R = 8314.3
n = 1./28
T = 273.1

# Calculations
logpr = v*(pf-pii)*10**6 /(R*T*n)
pr = math.exp(logpr)
p = pr*pi
logpr = v*(pf2-pii)*10**6 /(R*T*n)
pr = math.exp(logpr)
p2 = pr*pi

# Results
print "Final pressure  =  %.2f Mpa"%(p)
print " Final pressure in case 2  =  %.2f Mpa"%(p2)

Final pressure  =  5.42 Mpa
Final pressure in case 2  =  4.19 Mpa


## Example 4.15 page : 131¶

In [24]:
import math

# Variables
Hvap = 338.14 			#kJ/kg
T = 409.3 			#K

# Calculations
dss = Hvap/T
dg = 0

# Results
print "change in entropy and gibbs energy of system are %.3f kJ/kg K and %d kJ/kg respectivey"%(dss,dg)
print " change in entropy and gibbs energy of universe are %.3f kJ/kg K and %d kJ/kg respectivey"%(-dss,-dg)

change in entropy and gibbs energy of system are 0.826 kJ/kg K and 0 kJ/kg respectivey
change in entropy and gibbs energy of universe are -0.826 kJ/kg K and 0 kJ/kg respectivey


## Example 4.16 page : 134¶

In [26]:
import math

# Variables
T = 373.1 			#K
R = 8314.3
Pd = 0.1013*10**6 			#Pa
P = 10. 			#Mpa
p3 = 5.*10**6 			#Pa
vf = 0.0373
a = 424.447

# Calculations
Vd = R*T/Pd
V = 0.5
dss = -R*(math.log(p3/Pd) + math.log((V-vf)/(Vd-vf)))
dhh = R*T/10**3 - p3/10**3 *V+ a/V**2

# Results
print "Change in entropy  =  %.4f kJ/kmol K"%(dss/10**3)
print " change in enthalpy =  %.f kJ/kmol"%(dhh)

Change in entropy  =  2.4285 kJ/kmol K
change in enthalpy =  2300 kJ/kmol


## Example 4.18 page : 141¶

In [27]:
import math

# Variables
Tc = 647.3 			#K
dh = 1.1
Db = -2
v2 = 0.234
v1 = 0.27

# Calculations
dh2 = dh+Db*(v2-v1)
dhh = dh2*Tc
dhbar = dhh*4.18/18
h1 = 3777.5 			#kJ/kg
h2 = 3928.2 			#kJ/kg
dhs = h2-h1
err = abs(dhs-dhbar)/dhs

# Results
print "Enthalpy departure  =  %d kJ/kg"%(dhbar)
print " Percentage error  =  %.1f "%(err*100)

Enthalpy departure  =  176 kJ/kg
Percentage error  =  16.9


## Example 4.19 page : 155¶

In [28]:

# Variables
w = 0.3448
R = 8.3143
Tc = 647.3

# Calculations
h0 = 0.57
h1 = 0.05
h2 = h0+w*h1
h3 = h2*R*Tc
dh = -h3

# Results
print "Enthalpy departure  =  %d kJ/kmol"%(dh)
print ("The answer is a bit different due to rounding off error in the textbook")

Enthalpy departure  =  -3160 kJ/kmol
The answer is a bit different due to rounding off error in the textbook


## Example 4.20 page : 164¶

In [29]:
import math

# Variables
ta = 310. 			#K
pa = 80. 			#kPa
r = 10.
k = 1.4
R = 8.3143
n = 5./29
cv = 20.93

# Calculations
Qab = 0
tb = ta*r**(k-1)
va = R*ta/pa
vb = va/r
pb = R*tb/vb
Wab =  -n*R*ta/(k-1) *((pb/pa)**((k-1)/k) -1)
vc = vb
Qbc = 500 			#kJ
Wbc = 0
tc = tb+ Qbc/(n*cv)
pc = R*tc/vc
Qcd = 0
td = tc/r**(k-1)
vd = va
pd = td/tc*(vc/vd)*pc
Wcd = -n*R*tc/(k-1) *((pd/pc)**((k-1)/k)-1)
Wda = 0
Qda = n*cv*(ta-td)
eta0 = 1-1/r**(k-1)

# Results
print "Efficiency of cycle  =  %.3f"%(eta0)
p = [pa, pb, pc, pd]
t = [ta, tb, tc, td]
Q = [Qab, Qbc, Qcd, Qda]
W = [Wab, Wbc, Wcd, Wda]
print ('Pressure (kPa)  =  ')
print (p)
print ("Temperature (K) =  ")
print (t)
print ("Heat (kJ) =  ")
print (Q)
print ("Work done (kJ)  =  ")
print (W)

Efficiency of cycle  =  0.602
Pressure (kPa)  =
[80.0, 2009.5091452076638, 2367.0758421853, 94.23498660179267]
Temperature (K) =
[310.0, 778.6847937679697, 917.2418888468039, 365.1605730819466]
Heat (kJ) =
[0, 500, 0, -199.05358527674872]
Work done (kJ)  =
[-1679.6491296659615, 0, 1978.5214153723077, 0]


## Example 4.21 page : 168¶

In [31]:

# Variables
ta = 310. 			#K
tc = 917.3 			#K
td = 365.2 			#K
n = 0.602
k = 1.4

# Calculations
lntb =  1/(1-n)/k
tb = tc- lntb*(td-ta)
rc = (tb/ta)**(1/(k-1))

# Results
print "Temperature at B  =  %.1f K"%(tb)
print " Compression ratio  =  %d "%(rc)
print ("The answer given in textbook for rc is wrong. please check using a calculator")

Temperature at B  =  818.2 K
Compression ratio  =  11
The answer given in textbook for rc is wrong. please check using a calculator


## Example 4.22 page : 170¶

In [32]:

# Variables
pr = 4.
k = 1.4
ta = 298. 			#K
pa = 0.1 			#Mpa
pdr = 0.01
tc = 900. 			#K
pri = 0.005 			#Mpa

# Calculations
pb = pr*pa
nji = 1- (pr)**((1-k)/k)
tb = ta*(pb/pa)**((k-1)/k)
pc = pb-pdr
pd = pa+pri
td = tc*(pd/pc)**((k-1)/k)

# Results
p = [pa, pb, pc, pd]
t = [ta, tb, tc, td]
print "ideal thermal efficiency  =  %.3f "%(nji)
print ("pressure (Mpa)  =  ")
print (p)
print ("temperature (K)  =  ")
print (t)

ideal thermal efficiency  =  0.327
pressure (Mpa)  =
[0.1, 0.4, 0.39, 0.10500000000000001]
temperature (K)  =
[298.0, 442.8262981628106, 900.0, 618.6157783525422]


## Example 4.23 page : 175¶

In [33]:
import math

# Variables
sd = 4.9269			#kJ/kg/K
sf = 1.1453			#kJ/kg/K
sg = 7.5320			#kJ/kg/K
hf = 359.86			#kJ/kg
hg = 2653.5			#kJ/kg
hd = 2409.7			#kJ/kg

# Calculations
x = (sd-sg)/(sf-sg)
he = x*hf+(1-x)*hg
etar = (hd-he)/(hd-hf)

# Results
print "Thermal efficiency  =  %.4f"%(etar)

Thermal efficiency  =  0.3375


## Example 4.23b page : 176¶

In [34]:

# Variables
sd = 6.7039			#kJ/kg/K
sf = 1.1453			#kJ/kg/K
sg = 7.5320			#kJ/kg/K
hf = 359.86			#kJ/kg
hg = 2653.5			#kJ/kg
hd = 3717.9			#kJ/kg

# Calculations
x = (sd-sg)/(sf-sg)
he = x*hf+(1-x)*hg
etar = (hd-he)/(hd-hf)

# Results
print "Thermal efficiency  =  %.4f"%(etar)

Thermal efficiency  =  0.4055


## Example 4.24 page : 178¶

In [35]:

# Variables
ha = 2510.6 			#kJ/kg
hd = 125.78 			#kJ/kg

# Calculations
kg = (10**6)/(ha-hd)

# Results
print "circulation rate  =  %d kg steam/h"%(kg)

circulation rate  =  419 kg steam/h


## Example 4.25 page : 179¶

In [36]:

# Variables
tin = 298.  			#K
tout = 273. 			#K
tout2 = 308. 			#K
tin2 = 294. 			#K

# Calculations
eta1 = (tin-tout)/tin
eta2 = abs((tin2-tout2)/tin2)

# Results
print "Efficiency in case 1  =  %.3f"%(eta1)
print " efficiency in case 2  =  %.3f"%(eta2)

Efficiency in case 1  =  0.084
efficiency in case 2  =  0.048


## Example 4.26 page : 181¶

In [37]:
import math

# Variables
ma = 500. 			#kg/h
cp1 = 3.2 			#kJ/kg K
ta = 20. 			#C
mb = 200.
mc = 300. 			#kg/h
cp2 = 2.8 			#kJ/kg K
tc = 80. 			#C
tb = 80. 			#C
me = 50. 			#kg/h
te = 120. 			#C
td = 120. 			#C
hg = 503.7
he = 2706.3

# Calculations
Ws = (mb+me)*hg + mc*cp2*(tc) - me*he -ma*cp1*(ta)

# Results
print "Net work done  =  %d kJ/h"%(Ws)

Net work done  =  25810 kJ/h


## Example 4.27 page : 184¶

In [38]:

# Variables
hc = 150. 			#Btu/lb
he = -115. 			#Btu/lb
hg = 168. 			#Btu/lb

# Calculations
frac = (hg-hc)/(hg-he)

# Results
print "Fraction of solid  =  %.3f"%(frac)

Fraction of solid  =  0.064


## Example 4.28 page : 185¶

In [39]:

# Variables
H = 2696.5 			#kJ/kg
hg = 2706.7 			#kJ/kg
hf = 504.7 			#kJ/kg

# Calculations
x =  (H-hf)/(hg-hf)
x2 = 1

# Results
print "In case 1, fraction of vapor  =  %.3f"%(x)
print " In case 2, fraction of vapor  =  %.3f"%(x2)

In case 1, fraction of vapor  =  0.995
In case 2, fraction of vapor  =  1.000