# Chapter 7 - Entropy¶

## Example 1: pg 159¶

In :
#pg 159
print('Example 7.1');
import math
#  aim : To determine
#  the specific enthalpy of water

#  Given values
Tf = 273.+100;#  Temperature,[K]

#  solution
#  from steam table
cpl = 4.187;# [kJ/kg K]
#  using equation 
sf = cpl*math.log(Tf/273.16);#  [kJ/kg*K]
print ' The specific entropy of water is (kJ/kg K) = ',round(sf,3)

#  using steam table
sf = 1.307;#  [kJ/kg K]
print ' From table The accurate value of sf in this case is (kJ/kg K) = ',sf

print "There is small error in book's final value of sf"

#  End

Example 7.1
The specific entropy of water is (kJ/kg K) =  1.304
From table The accurate value of sf in this case is (kJ/kg K) =  1.307
There is small error in book's final value of sf


## Example 2: pg 160¶

In :
#pg 160
print('Example 7.2');

#  aim : To determine
#  the specific entropy
import math
#  Given values
P = 2.;#  pressure,[MN/m^2]
x = .8;#  dryness fraction

#  solution
#  from steam table at given pressure
Tf = 485.4;#  [K]
cpl = 4.187;#  [kJ/kg K]
hfg = 1888.6;#  [kJ/kg]

#  (a) finding entropy by calculation
s = cpl*math.log(Tf/273.16)+x*hfg/Tf;#  formula for entropy calculation

print ' (a) The specific entropy of wet steam is (kJ/kg K) = ',round(s,2)

#  (b) calculation of entropy using steam table
#  from steam table at given pressure
sf = 2.447;#  [kJ/kg K]
sfg = 3.89;#  [kJ/kg K]
#  hence
s = sf+x*sfg;#  [kJ/kg K]

print ' (b) The specific entropy using steam table is (kJ/kg K) = ',s

#  End

Example 7.2
(a) The specific entropy of wet steam is (kJ/kg K) =  5.52
(b) The specific entropy using steam table is (kJ/kg K) =  5.559


## Example 3: pg 161¶

In :
#pg 161
print('Example 7.3');
import math
#  aim : To determine
#  the specific entropy of steam

#  Given values
P = 1.5;#pressure,[MN/m^2]
T = 273.+300;#temperature,[K]

#  solution

#  (a)
#  from steam table
cpl = 4.187;#  [kJ/kg K]
Tf = 471.3;#  [K]
hfg = 1946.;#  [kJ/kg]
cpv = 2.093;#  [kJ/kg K]

#  usung equation 
s = cpl*math.log(Tf/273.15)+hfg/Tf+cpv*math.log(T/Tf);#  [kJ/kg K]
print ' (a) The specific entropy of steam is (kJ/kg K) = ',round(s,3)

#  (b)
#  from steam tables
s = 6.919;#  [kJ/kg K]
print ' (b) The accurate value of specific entropy from steam table is (kJ/kg K) = ',s

#  End

Example 7.3
(a) The specific entropy of steam is (kJ/kg K) =  6.822
(b) The accurate value of specific entropy from steam table is (kJ/kg K) =  6.919


## Example 4: pg 164¶

In :
#pg 164
print('Example 7.4');

#  aim : To determine
#  the dryness fraction of steam

#  Given values
P1 = 2.;#  initial pressure, [MN/m^2]
t = 350.;#  temperature, [C]
P2 = .28;#  final pressure, [MN/m^2]

#  solution
#  at 2 MN/m^2 and 350 C,steam is superheated because the saturation temperature is 212.4 C
#  From steam table
s1 = 6.957;#  [kJ/kg K]

#  for isentropic process
s2 = s1;
#  also
sf2 = 1.647;#  [kJ/kg K]
sfg2 = 5.368;#  [kJ/kg K]

#  using
#  s2 = sf2+x2*sfg2, where x2 is dryness fraction of steam
#  hence
x2 = (s2-sf2)/sfg2;
print ' The final dryness fraction of steam is x2  = ',round(x2,3)

#  End

Example 7.4
The final dryness fraction of steam is x2  =  0.989


## Example 5: pg 165¶

In :
#pg 165
print('Example 7.5');

#  aim : To determine
#  the  final condition of steam...
#  the change in specific entropy during hyperbolic process

#  Given values
P1 = 2;#  pressure, [MN/m^2]
t = 250.;#  temperature, [C]
P2 = .36;#  pressure, [MN/m^2]
P3 = .06;#  pressure, [MN/m^2]

#  solution

#  (a)
#  from steam table
s1 = 6.545;#  [kJ/kg K]
#  at .36 MN/m^2
sg = 6.930;#  [kJ/kg*K]

sf2 = 1.738;#  [kJ/kg K]
sfg2 = 5.192;#  [kJ/kg K]
vg2 = .510;#  [m^3]

#  so after isentropic expansion, steam is wet
#  hence, s2=sf2+x2*sfg2, where x2 is dryness fraction
#  also
s2 = s1;
#  so
x2 = (s2-sf2)/sfg2;
#  and
v2 = x2*vg2;#  [m^3]

#  for  hyperbolic process
#  P2*v2=P3*v3
#  hence
v3 = P2*v2/P3;#  [m^3]

print ' (a) From steam table at .06 MN/m^2 steam is superheated and has temperature of 100 C with specific volume is (m^3/kg) = ',round(v3,2)

#  (b)
#  at this condition
s3 = 7.609;#  [kJ/kg*K]
#  hence
change_s23 = s3-sg;#  change in specific entropy during the hyperblic process[kJ/kg*K]
print ' (b) The change in specific entropy during the hyperbolic process is (kJ/kg K) = ',change_s23

# In the book they have taken sg instead of s2 for part (b), so answer is not matching

#  End

Example 7.5
(a) From steam table at .06 MN/m^2 steam is superheated and has temperature of 100 C with specific volume is (m^3/kg) =  2.83
(b) The change in specific entropy during the hyperbolic process is (kJ/kg K) =  0.679


## Example 6: pg 166¶

In :
#pg 166
print('Example 7.6');

#  aim : To determine the
#  (a) heat transfer during the expansion and
#  (b) work done durind the expansion
%matplotlib inline
import matplotlib
from matplotlib import pyplot
#  given values
m = 4.5;  #  mass of steam,[kg]
P1 = 3.;  #  initial pressure,[MN/m^2]
T1 = 300.+273;  #  initial temperature,[K]

P2 = .1;  #  final pressure,[MN/m^2]
x2 = .96;  #  dryness fraction at final stage

#  solution
#  for state point 1,using steam table
s1 = 6.541;#  [kJ/kg/K]
u1 = 2751;# [kJ/kg]

#  for state point 2
sf2 = 1.303;#  [kJ/kg/K]
sfg2 = 6.056;#  [kJ/kg/k]
T2 = 273+99.6;#  [K]
hf2 = 417;#  [kJ/kg]
hfg2 = 2258;#  [kJ/kg]
vg2 = 1.694;#   [m^3/kg]

#  hence
s2 = sf2+x2*sfg2;# [kJ/kg/k]
h2 = hf2+x2*hfg2;# [kJ/kg]
u2 = h2-P2*x2*vg2*10**3;# [kJ/kg]

#  Diagram of example 7.6
x = ([s1, s2]);
y = ([T1, T2]);
pyplot.plot(x,y);
pyplot.title('Diagram for example 7.6(T vs s)');
pyplot.xlabel('Entropy (kJ/kg K)');
pyplot.ylabel('Temperature (K)');
x = ([s1,s1]);
y = ([0,T1]);
pyplot.plot(x,y);
x = ([s2,s2]);
y = ([0,T2]);
pyplot.plot(x,y);
pyplot.show()
#  (a)
#  Q_rev is area of T-s diagram
Q_rev = (T1+T2)/2*(s2-s1);# [kJ/kg]
#  so total heat transfer is
Q_rev = m*Q_rev;# [kJ]

#  (b)
del_u = u2-u1;#  change in internal energy, [kJ/kg]
#  using 1st law of thermodynamics
W = Q_rev-m*del_u;#  [kJ]

print ' (a) The heat transfer during the expansion is  (kJ)  (received) = ',Q_rev

print ' (b) The work done during the expansion is (kJ) = ',W

#  End

Example 7.6 (a) The heat transfer during the expansion is  (kJ)  (received) =  1224.986976
(b) The work done during the expansion is (kJ) =  2705.234976


## Example 7: pg 176¶

In :
#pg 176
print('Example 7.7');

#  aim : To determine the
#  (a) change of entropy
#  (b)  The approximate change of entropy obtained by dividing the heat transferred by the gas by the mean absolute temperature during the compression
import math
#  Given values
P1 = 140.;# initial pressure,[kN/m^2]
V1 = .14;# initial volume, [m^3]
T1 = 273.+25;# initial temperature,[K]
P2 = 1400.;# final pressure [kN/m^2]
n = 1.25; # polytropic index
cp = 1.041;# [kJ/kg K]
cv = .743;# [kJ/kg K]

#  solution
# (a)
R = cp-cv;# [kJ/kg/K]
#  using ideal gas equation
m = P1*V1/(R*T1);# mass of gas,[kg]
#  since gas is following law P*V^n=constant ,so
V2 = V1*(P1/P2)**(1./n);#  [m^3]

#  using eqn 
del_s = m*(cp*math.log(V2/V1)+cv*math.log(P2/P1));#  [kJ/K]
print ' (a) The change of entropy is (kJ/K) = ',round(del_s,3)

#  (b)
W = (P1*V1-P2*V2)/(n-1);# polytropic work,[kJ]
Gamma = cp/cv;# heat capacity ratio
Q = (Gamma-n)/(Gamma-1)*W;# heat transferred,[kJ]

# Again using polytropic law
T2 = T1*(V1/V2)**(n-1);# final temperature, [K]
T_avg = (T1+T2)/2;# mean absolute temperature, [K]

# so approximate change in entropy is
del_s = Q/T_avg;# [kJ/K]

print ' (b) The approximate change of entropy obtained by dividing the heat transferred by the gas by the mean absolute temperature during the compression (kJ/K) = ',round(del_s,4)

#  End

Example 7.7
(a) The change of entropy is (kJ/K) =  -0.046
(b) The approximate change of entropy obtained by dividing the heat transferred by the gas by the mean absolute temperature during the compression (kJ/K) =  -0.0448


## Example 8: pg 179¶

In :
#pg 179
print('Example 7.8');

#  aim : To determine
#  the change of entropy
import math
#  Given values
m = .3;#  [kg]
P1 = 350.;#  [kN/m^2]
T1 = 273.+35;#  [K]
P2 = 700.;#  [kN/m^2]
V3 = .2289;#  [m^3]
cp = 1.006;#  [kJ/kg K]
cv = .717;#  [kJ/kg K]

#  solution
#  for constant volume process
R = cp-cv;#  [kJ/kg K]
#  using PV=mRT
V1 = m*R*T1/P1;#  [m^3]

#  for constant volume process P/T=constant,so
T2 = T1*P2/P1;#  [K]
s21 = m*cv*math.log(P2/P1);#  formula for entropy change for constant volume process
print ' The change of entropy in constant volume process is (kJ/kg K) = ',round(s21,3)

# 'For the above part result given in the book is wrong

V2 = V1;
# for constant pressure process
T3 = T2*V3/V2;#  [K]
s32 = m*cp*math.log(V3/V2);#  [kJ/kg K]

print ' The change of entropy in constant pressure process is (kJ/kg K) = ',round(s32,3)

print "there is misprint in the book's result"

# End

Example 7.8
The change of entropy in constant volume process is (kJ/kg K) =  0.149
The change of entropy in constant pressure process is (kJ/kg K) =  0.332
there is misprint in the book's result


## Example 9: pg 181¶

In :
#pg 181
print('Example 7.9');
import math
#  aim : To determine
#  the  change of entropy

# Given values
P1 = 700.;# initial pressure, [kN/m^2]
T1 = 273.+150;#  Temperature ,[K]
V1 = .014;# initial volume, [m^3]
V2 = .084;#  final volume, [m^3]

#  solution
#  since process is isothermal so
T2 = T1;
# and using fig.7.10
del_s = P1*V1*math.log(V2/V1)/T1 ;#  [kJ/K]
#results
print ' The change of entropy is (kJ/kg K) = ',round(del_s,5)

#  End

Example 7.9
The change of entropy is (kJ/kg K) =  0.04151