# Chapter 5 - Second law of themodynamics¶

## Example: 5.1 Page: 150¶

In [5]:
from __future__ import division
print "Example: 5.1 - Page: 150\n\n"

# Solution

#*****Data*****#
Th = 550 + 273## [K]
Tl = 27 + 273## [K]
#************#

# The theoretical efficiency of a heat engine is given by:
# eta = Net Work Output/Net Work Input
# eta = Wnet/Qin
# eta = (Qin - Qout)/Qin = (Th - Tl)/Th
eta = (Th - Tl)/Th#
print "The theoretical efficiency of heat engine is %.1f %%"%(eta * 100)

Example: 5.1 - Page: 150

The theoretical efficiency of heat engine is 63.5 %


## Example: 5.2 Page: 150¶

In [6]:
from __future__ import division
print "Example: 5.2 - Page: 150\n\n"

# Solution

#*****Data*****#
Th = 810## [K]
Tl = 300## [K]
#*************#

# Solution (a)
eta = (Th - Tl)/Th#
print "(a) The efficiency of the heat engine is %.1f %%\n"%(eta*100)#

# Solution (b)
Th = 1366## [K]
Tl = 300## [K]
eta = (Th - Tl)/Th#
print "(b) The efficiency of the heat engine is %.1f %%\n"%(eta*100)#

# Solution (c)
Th = 810## [K]
Tl = 344## [K]
eta = (Th - Tl)/Th#
print "(c) The efficiency of the heat engine is %.1f %%\n"%(eta*100)#

Example: 5.2 - Page: 150

(a) The efficiency of the heat engine is 63.0 %

(b) The efficiency of the heat engine is 78.0 %

(c) The efficiency of the heat engine is 57.5 %



## Example: 5.3 Page: 151¶

In [7]:
from __future__ import division
print "Example: 5.3 - Page: 151\n\n"

# Solution

#*****Data*****#
Th = 650 + 273## [K]
Tl = 30 + 273## [K]
Qh = 585## [kJ/cycle]
#*************#

# Solution (a)
# From Eqn. (5.9)
eta = (Th - Tl)/Th#
print "(a) The efficiency of the Carnot engine is %.1f %%\n"%(eta*100)#

# Soluton (b)
# From the knowledge of the ratio of heat and temperature between the two regions:
Ql = Qh*Tl/Th## [kJ]
print "(b) Heat released to cold reservoir is %d kJ\n"%(Ql)#

Example: 5.3 - Page: 151

(a) The efficiency of the Carnot engine is 67.2 %

(b) Heat released to cold reservoir is 192 kJ



## Example: 5.4 Page: 151¶

In [8]:
from __future__ import division
print "Example: 5.4 - Page: 151\n\n"

# Solution

#*****Data*****#
m = 1## [kg]
Tl = 273## [K]
Th = 295## [K]
Ql = 335## [kJ/kg]
#*************#

# Solution (a)
# The coeffecient of performance of refrigerating machine is:
# COP = Ql/Wnet = Tl/(Th - Tl)
Wnet = Ql*(Th - Tl)/Tl## [kJ]
print "Minimum Work requirement is %d kJ\n"%(round(Wnet))#

# Solution (b)
# Amount of heat released:
# Wnet = Qh - Ql
Qh = Wnet + Ql## [kJ]
print "Amount of heat released to the surrounding is %d kJ\n"%(round(Qh))#

Example: 5.4 - Page: 151

Minimum Work requirement is 27 kJ

Amount of heat released to the surrounding is 362 kJ



## Example: 5.5 Page: 152¶

In [9]:
from __future__ import division
print "Example: 5.5 - Page: 152\n\n"

# Solution

#*****Data*****#
Th = 373## [K]
Tl = 275## [K]
Qh = 50## [kJ]
#*************#

# Solution (a)
# Theral Efficiency of the engine can be given as:
# eta_HE = Wnet/Qh#
# Wnet = Qh*COP = Qh*(Th - Tl)/Th#
Wnet = Qh*(Th - Tl)/Th## [kJ]
print "Minimum Work Required is %.1f kJ\n"%(Wnet)#

# Solution (b)
eta = (Th - Tl)/Th#
print "The efficiency of Heat Engine is %.3f\n"%(eta)#

# Solution (c)
# Amount of heat released can be calculated as:
# eta = Net Work Output/Net Work Input#
# eta = Wnet/Qin#
# eta = (Qin - Qout)/Qin#
Qin = Qh## [kJ]
Qout = Qin*(1 - eta)#
print "Amount of Heat released is %.1f kJ\n"%(Qout)#

Example: 5.5 - Page: 152

Minimum Work Required is 13.1 kJ

The efficiency of Heat Engine is 0.263

Amount of Heat released is 36.9 kJ



## Example: 5.6 Page: 153¶

In [10]:
from __future__ import division
print "Example: 5.6 - Page: 153\n\n"

# Solution

#*****Data*****#
W = 5## [hp]
Q = 7000## [J/s]
Th = 400 + 273## [K]
Tl = 24 + 273## [K]
#*************#

W = 5*745.7## [W]
thermal_eta = W/Q#
theoretical_eta = (Th - Tl)/Th#

if theoretical_eta <= thermal_eta:
print "Claim is Valid"
else:
print "Claim is not Valid"

Example: 5.6 - Page: 153

Claim is not Valid


## Example: 5.7 Page: 162¶

In [11]:
from __future__ import division
print "Example: 5.7 - Page: 162\n\n"

# Solution

#*****Data*****#
n = 1## [mol]
deltaH_fusion = 6500## [J/mol]
T_Tr = 273## [transition temperature, K]
P = 1## [atm]
#************#

# By Eqn. (9.40)
deltaS_fusion = deltaH_fusion/T_Tr## [J/mol K]
print "Change in Entropy is %.2f J/mol K"%(deltaS_fusion)#

Example: 5.7 - Page: 162

Change in Entropy is 23.81 J/mol K


## Example: 5.8 Page: 164¶

In [12]:
from __future__ import division
from math import log
print "Example: 5.8 - Page: 164\n\n"

# Solution

#*****Data*****#
V1 = 5## [L]
V2 = 50## [L]
n = 5## [moles]
R = 1.987## [cal/mol K]
#**************#

# Change in entropy for an isothermal change for an ideal gas:
# deltaS = n*R*log(P1/P2) = n*R*log(V2/V1)
deltaS = n*R*log(V2/V1)## [cal/degree]
print "Change in Entropy is %.3f eu"%(deltaS)#

Example: 5.8 - Page: 164

Change in Entropy is 22.876 eu


## Example: 5.9 Page: 164¶

In [13]:
from __future__ import division
from math import log
print "Example: 5.9 - Page: 164\n\n"

# Solution

#*****Data*****#
n = 8## [mol]
R = 8.314## [J/mol K]
T2 = 700## [K]
T1 = 350## [K]
Cp = (5/2)*R## [J/mol K]
#*************#

deltaS = n*Cp*log(T2/T1)## [J/K]
print "deltaS is %.2f J/K"%(deltaS)#

R*log(V2/V1)#// [cal/degree]
print "Change in Entropy is %.3f eu"%(deltaS)#

Example: 5.9 - Page: 164

deltaS is 115.26 J/K
Change in Entropy is 115.257 eu


## Example: 5.10 Page: 164¶

In [14]:
from __future__ import division
from math import log
print "Example: 5.10 - Page: 164\n\n"

# Solution

#*****Data*****#
n = 5## [moles]
T1 = 300## [K]
T2 = 400## [K]
P1 = 3## [bars]
P2 = 12## [bars]
Cp = 26.73## [J/mol K]
R = 8.314## [K/mol K]
#*************#

deltaS = n*((Cp*log(T2/T1)) + (R*log(P1/P2)))## [kJ/K]
print "Change in Entropy is %f kJ/K"%(deltaS)#

Example: 5.10 - Page: 164

Change in Entropy is -19.179548 kJ/K


## Example: 5.11 Page: 166¶

In [15]:
from __future__ import division
from math import log
print "Example: 5.11 - Page: 166\n\n"

# Solution

#*****Data*****#
N = 1## [kmol]
xA = 0.21## [for Oxygen]
xB = 0.79## [for Nitrogen]
R = 8.314## [kJ/kmol K]
#*************#

deltaS = - (N*R*(xA*log(xA) + xB*log(xB)))## [kJ/mol K]
print "Entropy Change is %.2f kJ/kmol K"%(deltaS)#

Example: 5.11 - Page: 166

Entropy Change is 4.27 kJ/kmol K


## Example: 5.12 Page: 167¶

In [16]:
from __future__ import division
from math import log
print "Example: 5.12 - Page: 167\n\n"

# Solution

#*****Data*****#
Vol_O2 = 5.6## [L]
Vol_H2 = 16.8## [L]
R = 1.987## [cal/mol K]
#*************#

xA = Vol_O2/22.4## [mole fraction O2]
xB = Vol_H2/22.4## [mle fraaction H2]
N = xA + xB## [total number of moles]
# From Eqn. 5.21:
deltaS = - (N*R*(xA*log(xA) + xB*log(xB)))## [cal/K]
print "Change in Entropy is %.3f cal/K"%(deltaS)#

Example: 5.12 - Page: 167

Change in Entropy is 1.117 cal/K


## Example: 5.13 Page: 168¶

In [17]:
from __future__ import division
from math import log
print "Example: 5.13 - Page: 168\n\n"

# Solution

#*****Data*****#
m = 80## [mass of Argon, g]
T1 = 300## [K]
T2 = 500## [K]
Cv = 0.3122## [kJ/kg K]
#**************#

Mw = 40## [Molecular Weight of Argon]
n = m/Mw## [moles]
deltaS = n*Cv*log(T2/T1)## [kJ/K]
print "Entropy Change is %.3f kJ/K"%(deltaS)#

Example: 5.13 - Page: 168

Entropy Change is 0.319 kJ/K


## Example: 5.14 Page: 168¶

In [18]:
from __future__ import division
from math import log,exp
print "Example: 5.14 - Page: 168\n\n"

# Solution

#*****Data*****#
deltaS = 1## [kJ/kg K]
Cv = 0.918## [kJ/kg K]
T1 = 273 + 18## [K]
#*************#

# Let the upper temperature be T.
# deltaS = integrate('Cv/T','T',T1,T)#
# deltaS = Cv*log(T/T1)
T = T1*exp(deltaS/Cv)## [K]
print "The upper temperature of the process is %.3f K"%(T)#

Example: 5.14 - Page: 168

The upper temperature of the process is 864.929 K


## Example: 5.15 Page: 169¶

In [19]:
from __future__ import division
from scipy.optimize import fsolve

print "Example: 5.15 - Page: 169\n\n"

# Solution

#*****Data*****#
m1 = 5## [kg]
m2 = 20## [kg]
C = 4.2## [kJ/kg K]
T1 = 350## [K]
T2 = 250## [K]
#**************#

# Suppose the final temperature is T
#deff('[y] = f(T)','y = m1*C*(T1 - T) - m2*C*(T - T2)')#
def f(T):
y = m1*C*(T1 - T) - m2*C*(T - T2)
return y

T = fsolve(f, 7)[0]## [K]
# Change in entropy of Hot Water:
# Change in Entopy of Hot Water:
deltaS = deltaS1 + deltaS2## [kJ/K]
print "Change in Entropy is %.3f kJ/K"%(deltaS)#

Example: 5.15 - Page: 169

Change in Entropy is -5.450 kJ/K


## Example: 5.16 Page: 169¶

In [20]:
from __future__ import division
from scipy.optimize import fsolve

print "Example: 5.16 - Page: 169\n\n"

# Solution

#*****Data*****#
m = 12## [g]
T1 = 294## [K]
T2 = 574## [K]
T = 505## [melting point, K]
H_fusion = 4.5## [cal/K]
C_solid = 0.052## [cal/g K]
C_liquid = 0.062## [cal/g K]
#*************#

# Entropy Change in heating 12 g of metal from T1 to T
# Entropy Change in fusion of metal:
deltaS2 = m*H_fusion/T## [kJ/K]
# Entropy Change in heating liquid metal from 505 K to 574 K
deltaS = deltaS1 + deltaS2 + deltaS3## [kJ/K]
print "Change in Entropy is %.3f kJ/K"%(deltaS)#

Example: 5.16 - Page: 169

Change in Entropy is 0.540 kJ/K


## Example: 5.17 Page: 170¶

In [21]:
from __future__ import division
from scipy.optimize import fsolve
print "Example: 5.17 - Page: 170\n\n"

# Solution

#*****Data*****#
#deff('[y] = Cp(T)','y = 7.25 + 2.28*10**(-3)*T')#
def Cp(T):
y = (7.25 + 2.28*10**(-3)*T)/T
return y
T1 = 273 + 137## [K]
T2 = 273 + 877## [K]
#************#

print "Change in Entropy is %.3f cal/K"%(deltaS)#

Example: 5.17 - Page: 170

Change in Entropy is 9.165 cal/K


## Example: 5.18 Page: 170¶

In [22]:
from __future__ import division
from scipy.optimize import fsolve
from math import log
print "Example: 5.18 - Page: 170\n\n"

# Solution

#*****Data*****#
m_iron = 40## [kg]
T1 = 625## [K]
m_water = 160## [kg]
T2 = 276## [K]
C_iron = 0.45## [kJ/kg K]
C_water = 4.185## [kJ/kg K]
#**************#

#deff('[y] = f(T)','y = m_iron*C_iron*(T1 - T) - m_water*C_water*(T - T2)')#
def f(T):
y = m_iron*C_iron*(T1 - T) - m_water*C_water*(T - T2)
return y

T = fsolve(f, 7)## [K]
# Change in Entropy of the iron casting can be estimated as:
deltaS1 = m_iron*C_iron*log(T/T1)## [kJ/K]
# Change in Entropy of Water is given by:
deltaS2 = m_water*C_water*log(T/T2)## [kJ/K]
deltaS = deltaS1 + deltaS2## [kJ/K]
print "Total Entropy Change is %.2f kJ/K"%(deltaS)#

Example: 5.18 - Page: 170

Total Entropy Change is 7.68 kJ/K


## Example: 5.19 Page: 172¶

In [23]:
from __future__ import division
from math import log
print "Example: 5.19 - Page: 172\n\n"

# Solution

#*****Data*****#
Cp = 21## [J/kmol]
T1 = 300## [K]
T2 = 500## [K]
S1 = 150## [Entropy at T1, J/kmol]
#*************#

# This is a constant Entropy process. Therefore:
deltaS = Cp*log(T2/T1)## [J/kmol]
S2 = S1 + deltaS## [J/kmol]
print "Entropy at 500 K is %.2f J/kmol"%(S2)#

Example: 5.19 - Page: 172

Entropy at 500 K is 160.73 J/kmol


## Example: 5.20 Page: 173¶

In [24]:
from __future__ import division
print "Example: 5.20 - Page: 173\n\n"

# Solution

#*****Data*****#
T1_oil = 273 + 150## [K]
T2_oil = 50 +273## [K]
m_water = 4000## [kg]
T1_water = 273 + 20## [K]
T2_water = 273 + 130## [K]
C_water = 4.185## [kJ/kg K]
C_oil = 2.5## [kJ/kg K]
#***************#

# For oil:
deltaT_oil = T1_oil - T2_oil## [K]
# For water:
deltaT_water = T2_water - T1_water## [K]
# The mass flow rate of oil can be measured by the enthalpy balance over the process:
m_oil = m_water*C_water*deltaT_water/(deltaT_oil*C_oil)## [kg]
# Change in the Entropy of oil:
deltaS_oil = m_oil*C_oil*log(T2_oil/T1_oil)## [kJ/K]
# Change in Entropy of water:
deltaS_water = m_water*C_water*log(T2_water/T1_water)## [kJ/K]
deltaS = deltaS_oil + deltaS_water## [kJ/K]
print "Total Entropy Change is %.2f kJ/K"%(deltaS)#

Example: 5.20 - Page: 173

Total Entropy Change is 369.49 kJ/K


## Example: 5.21 Page: 174¶

In [25]:
from __future__ import division
print "Example: 5.21 - Page: 174\n\n"

# Solution

#*****Data*****#
t = 20*60## [s]
P = 650## [W]
T = 273 + 250## [K]
#*************#

Q = P*t/1000## [kJ]
deltaS = Q/T## [kJ/K]
print "Change in Entropy is %.2f kJ/K"%(deltaS)#

Example: 5.21 - Page: 174

Change in Entropy is 1.49 kJ/K


## Example: 5.22 Page: 174¶

In [26]:
from __future__ import division
print "Example: 5.22 - Page: 174\n\n"

# Solution

#*****Data*****#
T1 = 400## [K]
P1 = 300## [kPa]
V1 = 1## [cubic m]
V2 =2## [cubic m]
R = 8.314## [kJ/kmol K]
#**************#

# Since the system is well insulated, there is no scope of transferring heat between system & surrounding.
deltaQ = 0## [kJ]
deltaW = 0## [kJ]
# By first law of thermodynamics:
deltaU =deltaQ - deltaW## [kJ]
# As the internal energy of the gas depends only on temperature,
deltaT = 0## [K]
T2 = T1 + deltaT## [K]
P2 = (P1*V1/T1)*(T2/V2)## [kPa]
n = P1*V1/(R*T1)## [kmol]
deltaS_system = n*R*log(P1/P2)## [kJ/K]
deltaS_surrounding = 0## [kJ/K]
deltaS = deltaS_system + deltaS_surrounding## [kJ/K]
print "Change in Entropy of the gas is %.4f kJ/K"%(deltaS)#

Example: 5.22 - Page: 174

Change in Entropy of the gas is 0.5199 kJ/K


## Example: 5.23 Page: 174¶

In [27]:
print "Example: 5.23 - Page: 174\n\n"

# This problem involves proving a relation in which no mathematics and no calculations are involved.
# For prove refer to this example 5.23 on page number 174 of the book.

print " This problem involves proving a relation in which no mathematics and no calculations are involved.\n\n"
print " For prove refer to this example 5.23 on page 174 of the book."

Example: 5.23 - Page: 174

This problem involves proving a relation in which no mathematics and no calculations are involved.

For prove refer to this example 5.23 on page 174 of the book.


## Example: 5.24 Page: 182¶

In [28]:
from __future__ import division
from scipy.optimize import fsolve
print "Example: 5.24 - Page: 182\n\n"

# Solution

# From Example 5.18 (Pg: 170)
#*****Data*****#
m_iron = 40## [kg]
T1 = 625## [K]
m_water = 160## [kg]
T2 = 276## [K]
C_iron = 0.45## [kJ/kg K]
C_water = 4.185## [kJ/kg K]
#**************#

#deff('[y] = f(T)','y = m_iron*C_iron*(T1 - T) - m_water*C_water*(T - T2)')#
def f(T):
y = m_iron*C_iron*(T1 - T) - m_water*C_water*(T - T2)
return y
T = fsolve(f, 7)[0]## [K]
# Change in Entropy of the iron casting can be estimated as:
# Change in Entropy of Water is given by:
deltaS = deltaS1 + deltaS2## [kJ/K]
# By Eqn. 5.63:
W_lost = T2 * deltaS## [kJ]
print "Work lost is %.2f kJ"%(W_lost)#

Example: 5.24 - Page: 182

Work lost is 2119.67 kJ


## Example: 5.25 Page: 182¶

In [29]:
from __future__ import division
from scipy.optimize import fsolve
print "Example: 5.25 - Page: 182\n\n"

# Solution

# *****Data******#
m_oil = 4750## [kg]
T1_oil = 515## [K]
T2_oil = 315## [K]
m_water = 9500## [kg]
T1_water = 290## [K]
Cp_oil = 3.2## [kJ/kg K]
Cp_water = 4.185## [kJ/kg K]
#*****************#

# From enthalpy Balance:
#def('[y] = f(T2_water)','y = m_oil*Cp_oil*(T1_oil - T2_oil) - m_water*Cp_water*(T2_water - T1_water)')#
def f(T2_water):
y = m_oil*Cp_oil*(T1_oil - T2_oil) - m_water*Cp_water*(T2_water - T1_water)
return y
T2_water = fsolve(f, 7)[0]## [K]
# Change in the Entropy of oil:
deltaS_oil = m_oil*Cp_oil*quad(lambda T : (1/T),[T1_oil,T2_oil])## [kJ/K]
# Change in Entropy of water:
deltaS_water = m_water*Cp_water*quad(lambda T: (1/T),[T1_water,T2_water])## [kJ/K]
deltaS = deltaS_oil + deltaS_water## [kJ/K]
print "Total Entropy Change is %.2f kJ/K\n"%(deltaS)#
if deltaS > 0:
print "Since deltaS is a positive quantity, process is irreversible\n"
else:
print "Since deltaS is a negative quantity, process is reversible\n"

Example: 5.25 - Page: 182

Total Entropy Change is 1831.74 kJ/K

Since deltaS is a positive quantity, process is irreversible