Chapter 4 : The Secomd Law and Its Applications

Example 4.1 Page Number : 148

In [1]:
 
import math

# Variables
n = 1000.;			#[mol]
T = 400.;			#[K]
P_1 = 100.;			#[kPa]
P_2 = 1000.;			#[kPa]
R = 8.314;			#[J/mol*K] - Universal gas constant

# Calculations and Results
			#(a)
T_surr = 400.;			#[K] - surrounding temperature
			# Total change in entropy of the system is given by
			# delta_S_sys = n*(Cp_0*math.log(T_2/T_1) - R*math.log(P_2/P_1))
			# The process being isothermal the first term is zero and the total entropy change of the system is
delta_S_sys_a = - n*R*math.log(P_2/P_1);			#[J/K]
delta_S_sys_a = delta_S_sys_a*10**(-3);			#[kJ/K]

			# Since the process is reversible therefore
Q_sys = T_surr*delta_S_sys_a;			#[kJ] - Heat change in the system

Q_surr = - Q_sys;			#[kJ] - Heat change in the surrounding
delta_S_surr_a = Q_surr/T_surr;			#[kJ/K]

delta_S_univ_a = delta_S_sys_a + delta_S_surr_a;			#[kJ/K]
			# We get delta_S_univ = 0, which is true for a reversible process

print " a).The entropy change of the gas is given by  delta_S_sys = %f kJ/K "%(delta_S_sys_a);
print "     The entropy change of the surrounding is delta_S_surr = %f kJ/K "%(delta_S_surr_a);
print "     The total entropy change of the gas is  delta_S_univ = %f kJ/K "%(delta_S_univ_a);

			#(b)
T_surr_b = 300.;			#[K] - surrounding temperature

delta_S_sys_b = delta_S_sys_a;

			# Work done under reversible condition is given by
			# W = integral(P*dV) = integral(((R*T)/V)*dV) = R*T*math.log(V_2/V_1)
			# For ideal gas we have, P1*V1/T1 = P2*V2/T2 or, V2/V1 = P1/P2 (for isothermal conditions)
W = R*T*math.log(P_1/P_2);			#[J/mol]
W = W*10**(-3);			#[kJ/mol]

W = W*(120./100);			#[kJ/mol]
W = W*n;			#[kJ] - Total work done for n moles

			# Using the first law we have  delta_U = Q - W. Now under isothermal conditions for ideal gas, delta_U = 0. Therefore,
Q = -W;

			# Since heat is gained by the surroundings therefore
delta_S_surr_b = Q/T_surr_b;			#[kJ/K]

delta_S_univ_b = delta_S_sys_b + delta_S_surr_b;			#[kJ/K]

print " b).The entropy change of the gas is given by  delta_S_sys = %f kJ/K "%(delta_S_sys_b);
print "     The entropy change of the surrounding is delta_S_surr = %f kJ/K "%(delta_S_surr_b);
print "     The total entropy change of the gas is delta_S_univ = %f kJ/K "%(delta_S_univ_b);
 a).The entropy change of the gas is given by  delta_S_sys = -19.143692 kJ/K 
     The entropy change of the surrounding is delta_S_surr = 19.143692 kJ/K 
     The total entropy change of the gas is  delta_S_univ = 0.000000 kJ/K 
 b).The entropy change of the gas is given by  delta_S_sys = -19.143692 kJ/K 
     The entropy change of the surrounding is delta_S_surr = 30.629908 kJ/K 
     The total entropy change of the gas is delta_S_univ = 11.486215 kJ/K 

Example 4.2 Page Number : 148

In [2]:
 
# Variables
T = 400.;			#[K] - Temperature
P_1 = 500.*10**(3);			#[Pa] - Initial pressure
P_2 = 100.*10**(3);			#[Pa] -  Final pressure
V_1 = 750.*10**(-6);			#[m**(3)] - Initial volume
W_actual = 0.55*10**(3);			#[J] - Actual work done
R = 8.314;			#[J/mol*K] - Universal fas constant

# Calculations
			# Suppose that the surroundings are at 400 K.

			# The number of moles is given by
n = (P_1*V_1)/(R*T);			#[mol]
			# The entropy change of ideal gas under isothermal condition is given by
delta_S_sys = - n*R*math.log(P_2/P_1);			#[J/mol]

			# The heat supplied to the system in the internally reversible process is
Q_theot = T*delta_S_sys;			#[J]
			# Since the process is isothermal therefore, workdone is given by
W_theot = Q_theot;			#[J] - Theoritical work done
			# Since actual work done by the gas is 0.55 kJ therefore actual heat supplied is also 0.55 kJ because under isothermal conditions delta_U = 0
Q_actual = W_actual;

# Results
			# Since Q_theot > Q_actual, so the process is irreversible
print " Since Q_theot = %f J  is greater than  Q_actual = %f J"%(Q_theot,Q_actual);
print " Therefore, the process is internally irreversible"


			# delta_S_sys = Q/T_b + S_gen
S_gen = delta_S_sys - (Q_theot/T);			#[J/K]
			# The entropy generated may be due to friction and other dissipayive effects or due to non-quasi-static expansion
 Since Q_theot = 603.539217 J  is greater than  Q_actual = 550.000000 J
 Therefore, the process is internally irreversible

Example 4.3 Page Number : 150

In [3]:
 
R = 8.314;			#[J/mol*K] - Universal gas constant
			# For side A
V_A = 1;			#[L] - Volume
V_A = V_A*10**(-3);			#[m**(3)]
T_A = 300;			#[K] - Temperature
P_A = 2;			#[atm] - Pressure
P_A = P_A*101325;			#[Pa]

			# For side B
V_B = 1;			#[L] - volume
V_B = V_B*10**(-3);			#[m**(3)]
T_B = 300;			#[K] - Temperature
P_B = 1;			#[atm] - Pressure
P_B = P_B*101325;			#[Pa]

# Calculations and Results
			# From first law final temperature and pressure are given by (example 3.30)
			# T = ((n_A*T_A) + (n_B*T_B))/(n_A + n_B)
			# P = ((P_A*V_A) + (P_A*V_B))/(V_A + V_B)

			# Since in this case T_A = T_B, therefore final pressure is given by
P = ((P_A*V_A) + (P_B*V_B))/(V_A + V_B);			#[Pa]
P = P/101325;			#[atm]

print " The final temperature is %f K"%(T_A);
print " The final pressure is %f atm"%(P);

			# The number of moles of air on each side are
n_A = (P_A*V_A)/(R*T_A);			#[mol]
n_B = (P_B*V_B)/(R*T_B);			#[mol]

delta_S_A = -n_A*R*math.log((P*101325)/P_A);			#[J/K] - Entropy change on side A
delta_S_B = -n_B*R*math.log((P*101325)/P_B);			#[J/K] - Entropy change on side B
delta_S_sys = delta_S_A + delta_S_B;			#[J/K] - Total entropy change of system

			# Since the system is insulated there is no heat exchange with the surroundings, therefore entropy change of surrounding is zero
delta_S_surr = 0;			#[J/K]
delta_S_univ = delta_S_sys + delta_S_surr;			#[J/K]
print " The total increase in entropy is %f J/K"%(delta_S_univ);

			# The entropy change of the system can also be writtten as
			# delta_s_sys = Q/T_b + S_gen
			# Since there is no heat transfer, therefore
S_gen = delta_S_univ;			#[J/K]
			# The process is reversible because of entropy generation due to spontaneous release of piston.
 The final temperature is 300.000000 K
 The final pressure is 1.500000 atm
 The total increase in entropy is 0.057383 J/K

Example 4.4 Page Number : 151

In [4]:
 
V_vessel = 0.2;			#[m**(3)] - Volume of the vessel
P_1 = 10;			#[bar] - Initial pressure inside the vessel
P_1 = P_1*10**(5);			#[Pa]
P_2 = 3.5;			#[bar] - Final pressure inside the vessel
P_2 = P_2*10**(5);			#Pa
T_1 = 250 + 273.15;			#[K] - Initial temperature of the vesssel
R = 8.314;			#[J/mol*K] - Universal gas constant

# Calculations and Results
			# (a)
			# At 10 bar and 250 C the steam is superheated. From steam table as reported in book we have
V_1 = 0.2327;			#[m**(3)/kg] - specific volume
U_1 = 2709.9;			#[kJ/kg] - specific internal energy
H_1 = 2942.6;			#[kj/kg] - Specific enthalpy
S_1 = 6.9247;			#[kJ/kg-K] - Specific entropy
			# the quantity of steam is given by
m = V_vessel/V_1;			#[kg]

			# At final state 
V_2 = 0.2327;			#[m**(3)/kg] - Molar volume
V_liq_2 = 0.001079;			# [m**(3)/kg]
V_vap_2 = 0.5243;			# [m**(3)/kg]
			# Since overall volume lies between saturated liquid and saturated vapour therefore the steam is saturated and its dryness fraction at final state is given by
x = (V_2 - V_liq_2)/(V_vap_2 - V_liq_2);
			# Final temperature  = T_sat (at 3 bar) from steam table
T_final = 138.88;			#[C]

			# At 3.5 bar saturated conditions 
S_liq = 1.7275;			#[kJ/kg-K]  - Entropy of saturated liquid
S_vap = 6.9405;			#[kJ/kg-K]  - Entropy of saturated vapour
U_liq = 583.95;			#[kJ/kg]  - Internal energy of saturated liquid
U_vap = 2548.9;			#[kJ/kg]  - Internal energy of saturated vapour
			# Therefore at final state 
U_2 = U_liq*(1 - x) + x*U_vap;			#[kJ/kg]
S_2 = S_liq*(1 - x) + x*S_vap;			#[kJ/kg-K]
Q_1 = m*(U_2 - U_1);			#[kJ]
delta_S_1 = m*(S_2 - S_1);			#[kJ/kg-K]

print " a).The final temperature is %f C"%(T_final);
print "     The amount of heat transfer is %f kJ"%(Q_1);
print "     The change of entropy is %f kJ/kg-K"%(delta_S_1);

			# (b)
Y = 1.4;			# Ratio of heat capacities for air
			# (P_1*V_1)/T_1 = (P_2*V_2)/T_2   and since   V_1 = V_2
T_2 = (P_2/P_1)*T_1;			#[K]

			# Since the volume is fixed therefore work done (W) = 0 and from first law we get
			# Q = delta_U = n*Cv_0*(T_2 - T_1)
Cv_0 = R/(Y - 1);			#[J/mol-K] - Heat capacity at constant volume
Cp_0 = (Y*R)/(Y - 1);			#[J/mol-K] - Heat capacity at constant pressure
n = (P_1*V_vessel)/(R*T_1);			#[mol] - No. of moles
Q_2 = n*Cv_0*(T_2 - T_1);			#[J] - Heat change
Q_2 = Q_2*10**(-3);			#[kJ]

delta_S_2 = Cp_0*math.log(T_2/T_1) - R*math.log(P_2/P_1);			#[J/mol-K]
delta_S_2 = n*delta_S_2*10**(-3);			#[kJ/K]

print " b).The final temperature is %f C"%(T_2);
print "     The amount of heat transfer is %f kJ"%(Q_2);
print "     The change of entropy is %f kJ/K"%(delta_S_2);
 a).The final temperature is 138.880000 C
     The amount of heat transfer is -1079.587621 kJ
     The change of entropy is -2.483450 kJ/kg-K
 b).The final temperature is 183.102500 C
     The amount of heat transfer is -325.000000 kJ
     The change of entropy is -1.003366 kJ/K

Example 4.5 Page Number : 153

In [4]:
 
from math import *
# Variables
m = 1000.;			#[g] - Mass of fluid
P_1 = 20.;			#[bar] - Initial pressure
P_1 = P_1*10.**(5);			#[Pa]
P_2 = 2;			#[bar] - Final pressure
P_2 = P_2*10.**(5);			#Pa
T_1 = 250 + 273.15;			#[K] - Initial temperature
n = 1.25;
R = 8.314;			#[J/mol*-] - Universal gas constant
Y = 1.4;			# Index of expansion
Cv_0 = R/(Y- 1);			#[J/mol-K]
Cp_0 = R + Cv_0;			#[J/mol-K]

# Calculations and Results
			#(a)
			# For steam at 20 bar and 250 C, from steam table as reported in the book
V_1 = 0.11144;			#[m**(3)/kg]
U_1 = 2679.6;			#[kJ/kg]
S_1 = 6.5453;			#[kJ/kg-K]
			# P_1*V_1**(n) = P_2*V_2**(n)
V_2 = ((P_1*V_1**(n))/P_2)**(1/n);			#[m**(3)/kg]

			# At 2 bar under saturated conditions,from steam table as reported in the book
V_liq = 0.001061;			#[m**(3)/kg]
V_vap = 0.8857;			#[m**(3)/kg]
x = (V_2 - V_liq)/(V_vap - V_liq);			# Dryness fraction
T_sat = 120.23;			#[C] - The final temperature
U_liq  = 504.49;			#[kJ/kg] - Internal energy of saturate liquid
U_vap = 2529.5;			#[kJ/kg] - Internal energy of saturate vapour
			# Therefore, internal energy at state 2 is given by
U_2 = U_liq*(1 - x) + x*U_vap;			#[kJ/kg]

			# Work transfer is given by
W = (P_1*V_1 - P_2*V_2)/(n - 1);			#[J/kg]
W = W*10**(-3);			#[kJ/kg]
delta_U = U_2 - U_1;			#[kJ/kg]

			# From first law, q - W = delta_U
q = W + delta_U;			#[kJ/kg]

			# At final state (2 bar saturated), as reported in the book
S_liq = 1.5301;			#[kJ/kg-K] - Entropy of saturated liquid
S_vap = 7.1271;			#[kJ/kg-K] - Entropy of saturated vapour
			# Therefore, entropy at state 2 is given by
S_2 = S_liq*(1 - x) + x*S_vap;			#[kJ/kg-K]
delta_S = S_2 - S_1;			#[kJ/kg-K]

print " a).The final temperature is %f C"%(T_sat);
print "     The work done is equal to %f kJ/kg"%(W);
print "     The heat change is equal to %f kJ/kg"%(q);
print "     The entropy change is equal to %f kJ/kg-K"%(delta_S);

			#(b)
			# P*V**(n) = constant
			# Since the gas behaves as ideal we can write
			# P_1**(1-n)*T_1**(n) = P_2**(1-n)*T_2**(n)
T_2 = T_1*(P_1/P_2)**((1-n)/n);			#[K]

			# Molar volume is given by
V_2_1 = (R*T_1)/P_1;			#[m**(3)/mol] - At state 1
V_2_2 = (R*T_2)/P_2;			#[m**(3)/mol] - At state 2

			# Work transfer is given by
w_2 = ((P_1*V_2_1) - (P_2*V_2_2))/(n-1);			#[J/mol]
Mol_wt_air = 0.21*32 + 0.79*28;			#[g/mol] - Molecular weight of air
n_mole = m/Mol_wt_air;
			# Total work transfer is given by
W_2 = w_2*n_mole*10**(-3);			#[kJ]
			# Internal energy change is given by
delta_U = n_mole*Cv_0*(T_2 - T_1)*10**(-3);			#[kJ]

			# Heat transfer is given by
Q = W_2 + delta_U;			#[kJ]

			# Entropy change is given by
delta_S_2 = Cp_0*log(T_2/T_1) - R*log(P_2/P_1);			#[J/mol-K]
delta_S_2 = delta_S_2*n_mole;			#[J/mol]

print " b).The final temperature is %f C"%(T_2);
print "     The work done is equal to %f kJ/kg"%(W_2);
print "     The total heat change is equal to %f kJ"%(Q);
print "     The entropy change is equal to %f J/kg-K"%(delta_S_2);
 a).The final temperature is 120.230000 C
     The work done is equal to 329.008908 kJ/kg
     The heat change is equal to -238.988250 kJ/kg
     The entropy change is equal to -0.573241 kJ/kg-K
 b).The final temperature is 330.085335 C
     The work done is equal to 222.626855 kJ/kg
     The total heat change is equal to 83.485071 kJ
     The entropy change is equal to 199.136884 J/kg-K

Example 4.6 Page Number : 154

In [6]:
 
# Variables
m = 1000;			#[g] - Mass of fluid
P_1 = 20;			#[bar] - Initial pressure
P_2 = 2;			#[bar] - Final ressure
T_1 = 250 + 273.15;			#[K] - Initial tempearture
R = 8.314;			#[J/mol*K] - Universal gas constant

			# (a).
			# At 20 bar and 250 C as reported in the book
V_1 = 0.11144;			#[m**(3)/kg] - Specific volume
U_1 = 2679.6;			#[kJ/kg] - Specific internal energy
S_1 = 6.5453;			#[kJ/kg-K] - Specific entropy
S_2 = S_1;			# Isentropic expansion

# Calculations and Results
			# At 2 bar under saturated conditions 
S_liq = 1.5301;			#[kJ/kg-K]
S_vap = 7.1271;			#[kJ/kg-K]
U_liq = 504.49;			#[kJ/kg-K]
U_vap = 2529.5;			#[kJ/kg-K]
			# Therefore dryness factor can be determined as
x = (S_1 - S_liq)/(S_vap - S_liq);
U_2 = U_liq*(1 - x) + x*U_vap;			#[kJ/kg] - Specific internal energy at final state
delta_U = U_2 - U_1;			#[kJ/kg] - change in internal energy
W = - delta_U;			# - Work done

			# The final saturated temperature at 2 bar from steam table is
T_2 = 120.23;			#[C]

print " a).The final temperature is %f C"%(T_2);
print "     The work done is equal to %f kJ/kg"%(W);

			# (b).
Y = 1.4;			# Index of expansion for air
Cv_0 = R/(Y-1);			#[J/mol*K] - Specific heat capacity at constant volume
			# Ideal gas under isentropic expansion    P_1**(1-Y)*T_1**(Y) =P_2**(1-Y)*T_2**(Y)
T_2_prime = T_1*(P_1/P_2)**((1-Y)/Y);			#[K] - Final temperature
delta_U_prime = Cv_0*(T_2_prime - T_1);			#[J/mol] - change in internal energy

			# Number of moles is given by
n = m/28.84;			#[mol]
delta_U_prime = delta_U_prime*n*10**(-3);			#[kJ]
W_prime = - delta_U_prime;			# Work done

print " b).The final temperature is %f C"%(T_2_prime);
print "     The work done is equal to %f kJ/kg"%(W_prime);
 a).The final temperature is 120.230000 C
     The work done is equal to 360.596841 kJ/kg
 b).The final temperature is 270.964218 C
     The work done is equal to 181.750398 kJ/kg

Example 4.7 Page Number : 155

In [17]:
 
# Variables
P_1 = 15.;			#[bar] - Initial pressure
P_2 = 0.15;			#[bar] - Final pressure

			# We know that during isentropic expansion
			# W = ((P_1*V_1) - (P_2*V_2))/(Y - 1)

			# At 15 bar (saturated vapour), from steam table as reported in the book
V_1 = 0.13177;			#[m**(3)/kg]
U_1 = 2594.5;			#[kJ/kg]
S_1 = 6.4448;			#[kJ/kg-K]

			# Now at state 2 (P_2 = 0.15 bar),from steam table as reported in the book
S_2 = S_1;			# Isentropic expansion
S_liq = 0.7549;			#[kJ/kg-K]
S_vap = 8.0085;			#[kJ/kg-K]
U_liq = 225.92;			#[kJ/kg]
U_vap = 2448.7;			#[kJ/kg]
V_liq = 0.001014;			#[m**(3)/kg]
V_vap = 10.02;			#[m**(3)/kg]

# Calculations
			# Therefore dryness factor can be calculated as
x = round((S_1 - S_liq)/(S_vap - S_liq),3);
U_2 = round(U_liq*(1 - x) + x*U_vap,2);			#[kJ/kg] - Specific internal energy at final state
delta_U = U_2 - U_1;			#[kJ/kg] - change in internal energy
W = - delta_U;			# - Work done

			# The specific volume at the final state is
V_2 = round(V_liq*(1 - x) + x*V_vap,3);			#[m**(3)/kg]

			# From work done under adiabatic conditions we get
			# W = ((P_1*V_1) - (P_2*V_2))/(Y - 1)
Y = (((P_1*V_1) - (P_2*V_2))*10**2/W) + 1;

# Results
print " The index of expansion is given by Y = %.4f"%(Y);
 The index of expansion is given by Y = 1.1275

Example 4.8 Page Number : 157

In [8]:
 
P_1 = 40;			#[bar] - Initial pressure
T_1 = 500;			#[C] - Initial temperature
Vel_1 = 140;			#[m/s] - Initial velocity
T_2 = 100;			#[C] - Final temperature
Vel_2 = 80;			#[m/s] - Final velocity
W = 746.0;			#[kJ/kg] - Work output

# Calculations and Results
			# (a).
			# From steam table as reported in the book
H_1 = 3445.3;			#[kJ/kg]
H_2 = 2676.1;			#[kJ/kg]
S_1 = 7.0901;			#[kJ/kh-K]
S_2 = 7.3549;			#[kJ/kg-K]

			# The temperature at which heat exchange take place is given by 
T_b =(T_1 + T_2)/2 + 273.15;			#[K]

			# From first law in a control volume 
			# q - W = delta_H + (delta_V**(2))/2 , therefore
q = W*10**(3) + (H_2 - H_1)*10**(3) + (Vel_2**(2) - Vel_1**(2))/2;			#[J/kg]
q = q*10**(-3);			#[kJ/kg]

S_gen = (S_2 - S_1) - (q/T_b);			#[kJ/kg-K]

print " a).The specific entropy production within turbine is %f kJ/kg-K"%(S_gen);

			#(b)
			# If control volume is too large to include the turbine and the environment then T_b becomes equal to 289 K. In this case
T_b_prime = 298;			#[K]

			# The entropy change of the sysytem is given by 
			#delta_S = q/T_b + S_gen
S_gen = (S_2 - S_1) - (q/T_b_prime);			#[kJ/kg-K]

print " b).The specific entropy production within turbine is %f kJ/kg-K"%(S_gen);

			# In the first part only irreversibilities within the turbine are evaluated
			# whereas in part (2) irreversible heat transfer between the turbine cover and environment  are also included.
 a).The specific entropy production within turbine is 0.316793 kJ/kg-K
 b).The specific entropy production within turbine is 0.364800 kJ/kg-K

Example 4.9 Page Number : 160

In [30]:
 
P_1 = 1.;			#[MPa] - Initial pressure
T_1 = 200 + 273.15;			#[K] - Initial temperature
P_2 = 8.;			#[MPa] - Final pressure
Y = 1.4;			# Index of expansion of gas
R = 8.314;			#[J/mol-K] - Universal gas constant

# Calculations and Results
			#(1)
			# The exit temperature for ideal gas under isentropic conditions is given by 
T_2 = round(T_1*(round((P_2/P_1)**((Y-1)/Y),2)),1);			#[K] - Exit temperature

Cp_0 = round(Y*R/(Y-1),1);			#[J/mol-K] - Specific heat capacity at constant pressure
			# For isentropic conditions the enthalpy change for ideal gas is given by
delta_H_s = Cp_0*(T_2 - T_1);			#[J/mol]
			# Therefore work is given by
W = - delta_H_s;			#[J/mol]

print " 1).The exit temperature of steam is %.2f K"%(T_2);
print "     The required work is %.2f J/mol"%(W);

			#(2)
eff = 0.8;			# Adiabatic efficiency
			# delta_H_s/delta_H_a = 0.8
delta_H_a = delta_H_s/eff;			#[J/mol] - Actual enthalpy change
W_a = - delta_H_a;			#[J/mol]

			# The ideal gas enthalpy is a function only of temperature,therefore actual exit temperature T_2a is given by 
			# delta_H_a = Cp_0*(T_2a - T_1)
T_2a = (delta_H_a/Cp_0) + T_1;

print " 2).The exit temperature of steam is %.2f K"%(T_2a);
print "     The required work is %.2f J/mol"%(W_a);
 1).The exit temperature of steam is 856.40 K
     The required work is -11152.58 J/mol
 2).The exit temperature of steam is 952.21 K
     The required work is -13940.72 J/mol

Example 4.10 Page Number : 161

In [31]:
 
from scipy.optimize import fsolve 
import math 
from scipy.integrate import quad 
			

# Variables
P_1 = 1;			#[MPa] - Initial pressure
T_1 = 200 + 273.15;			#[K] - Initial temperature
P_2 = 8;			#[MPa] - Final pressure
Y = 1.4;			# Index of expansion of gas
R = 1.987;			#[cal/mol*K] - Universal gas constant
			# Cp_0 = 7.7 + 0.04594*10**(-2)*T + 0.2521*10**(-5)*T**(2) - 0.8587*10**(-9)*T**(3), here T is in K and Cp_0 is in  cal/mol-K
a = 7.7;
b = 0.04594*10**(-2);
c = 0.2521*10**(-5);
d = - 0.8587*10**(-9);

# Calculations and Results
			# delta_S = integral((Cp_0/T)*dT) - R*math.log(P_2/P_1) = 0
			# delta_S = integral(((a + b*T + c*T**(2) + d*T**(3))/T)*dT) - R*math.log(P_2/P_1) = 0
			# delta_S = a*math.log(T_2/T_1) + b*(T_2 - T_1) + (c/2)*(T_2**(2) - T_1**(2)) + (d/3)*(T_2**(3) - T_1**(3)) - R*math.log(P_2/P_1) = 0
			# Solving for T_2 in the above equation we get
def f(T_2): 
	 return a*math.log(T_2/T_1)+b*(T_2-T_1)+(c/2)*(T_2**(2)-T_1**(2))+(d/3)*(T_2**(3)-T_1**(3))-R*math.log(P_2/P_1)
T_2 = fsolve(f,100)

			# Now let us calculate the enthalpy change under these conditions 

def f0(T): 
	 return 7.7+0.04594*10**(-2)*T+0.2521*10**(-5)*T**(2)-0.8587*10**(-9)*T**(3)

delta_H_s =  quad(f0,T_1,T_2)[0]

delta_H_s = delta_H_s*4.184;			#[J/mol]
			# Therefore isentropic work done is
W = - delta_H_s;

print " 1).The exit temperature of steam is %f K"%(T_2);
print "     The required work is %f J/mol"%(W);

			#(2)
eff = 0.8;
delta_H_a = delta_H_s/eff;			#[J/mol] - Actual enthalpy change
			# Therefore actual work done is given by 
W_a = - delta_H_a;			#[J/mol]

			# Now we have to determine the exit temperature under actual conditions
			# delta_H_a = integral(Cp_0*dT)  from limit T_1 = 473.15 K to T_2
			# On putting the values and simplifying we get
			# 7.7*T_2 + 0.02297*10**(-2)*T_2**(2) + 0.084*10**(-5)*T_2**(3) - 0.214675*10**(-9)*T_2**(4) - 6907.106 = 0

def f1(T_2_prime): 
	 return a*(T_2_prime-T_1)+(b/2)*(T_2_prime**(2)-T_1**(2))+(c/3)*(T_2_prime**(3)-T_1**(3))+(d/4)*(T_2_prime**(4)-T_1**(4))-(delta_H_a/4.184)
T_2_prime = fsolve(f1,100)

print " 2).The exit temperature of steam is %f K"%(T_2_prime);
print "     The required work is %f J/mol"%(W_a);

# Answers are vary because of rounding error. Calculations are correct. 
 1).The exit temperature of steam is 760.037501 K
     The required work is -10499.128839 J/mol
 2).The exit temperature of steam is 828.044888 K
     The required work is -13123.911049 J/mol

Example 4.11 Page Number : 162

In [11]:
 
# Variables
P_1 = 1;			#[MPa] - Initial pressure
T_1 = 200 + 273.15;			#[K] - Initial temperature
P_2 = 8;			#[MPa] - Final pressure
Y = 1.4;			# Index of expansion of gas

			# At state 1 (1 MPa and 200 C) from steam table as reported in the book
H_1 = 2827.9;			#[kJ/kg]
S_1 = 6.694;			#[kJ/kg]
			# At state 2 (8 MPa)
S_2 = S_1;			# Isentropic process
			# From steam table at 8 MPa and 450 C
S_21 = 6.5551;			#[kJ/kg-K]
			# From steam table at 8 MPa and 500 C
S_22 = 6.7240;			#[kJ/kg-K]
			# Therefore temperature at which entropy of steam is 6.694 kJ/kg-K is given by
T_2 = 450 + (500-450)/(S_22-S_21)*(S_2-S_21);			#[C]
T_2 = T_2 + 273.15;			#[K]


# Calculations and Results
			# Enthalpy of steam at 8 MPa and 450 C from steam table as reported in the book 
H_21 = 3272.0;			#[kJ/kg]
			# And at 8 MPA and 500 C
H_22 = 3398.3;			#[kJ/kg]
			# Therefore enthalpy of steam at 8 MPa and T_2 
H_2 = H_21 + ((H_22-H_21)/(500-450))*((T_2-273.15) - 450); 
			# Work done is given by 
			# W = - delta_H_s
W = - (H_2 - H_1);			#[J/g]
W = W*18.015;			#[J/mol]
delta_H_s = - W;

print " 1).The exit temperature of steam is %f K"%(T_2);
print "     The required work is %f J/mol"%(W);

			#(2)
eff = 0.8;			# Adiabatic efficiency
			# delta_H_s/delta_H_a = 0.8
delta_H_a = delta_H_s/eff;			#[J/mol] - Actual enthalpy change
			# Therefore actual work done 
W_a = - delta_H_a;			#[J/mol]
			# Enthalpy at actual exit conditions is 
H_2_a = H_1 + delta_H_a/18.015;			#[kJ/kg]

			# Enthalpy of steam at 8 MPa and 500 C from steam table as reported in the book 
H_21_a = 3398.3;			#[kJ/kg]
			# And at 8 MPA and 550 C
H_22_a = 3521.0;			#[kJ/kg]
			# Therefore temperature at H_22_a is given by
T_2_a = 500 + ((550-500)*(H_2_a - H_21_a))/(H_22_a - H_21_a);			#[C]
T_2_a = T_2_a + 273.15;			#[K]

print " 2).The exit temperature of steam is %f K"%(T_2_a);
print "     The required work is %f J/mol"%(W_a);
 1).The exit temperature of steam is 764.269005 K
     The required work is -9871.618433 J/mol
 2).The exit temperature of steam is 819.832257 K
     The required work is -12339.523042 J/mol

Example 4.12 Page Number : 163

In [12]:
 
P_1 = 140.;			#[kPa] - Initial pressure
T_1 = 20. + 273.15;			#[K] - Initial temperature
P_2 = 560.;			#[kPa] - Final pressure
eff = 0.75;			# Compressor efficiency
R = 1.987;			#[cal/mol*K] - Universal gas constant
			# Cp_0 = 4.750 + 1.200*10**(-2)*T + 0.3030*10**(-5)*T**(2) - 2.630*10**(-9)*T**(3), here T is in K and Cp_0 is in  cal/mol-K
a = 7.7;
b = 0.04594*10**(-2);
c = 0.2521*10**(-5);
d = - 0.8587*10**(-9);

# Calculations and Results
# At 20 C,as reported in the book
Cp_0 = 8.46;			#[cal/mol-K] - Specific heat capacity at constant pressure
Cv_0 = Cp_0 - R;			#[cal/mol-K] - Specific heat capacity at constant volume
Y = Cp_0/Cv_0;			# Index of expansion

			# Assuming 100 % efficiency,for reversible and adiabatic process the final temperature is given by
			# P*V**(Y) = constant or, P*((R*T)/P)**(Y) = constant
T_2 = ((P_1/P_2)**((1-Y)/Y))*T_1;			#[K]

			# Since at final temperature the value of heat capacity ratio would have changed 
			# So let us determine Y at mean temperature and then calculating final temperature
T_mean = (T_1 + T_2)/2;			#[K]

			# At T_mean,as reported in the book
Cp_0_new = 9.153;			#[cal/mol-K]
Cv_0_new = Cp_0_new - R;			#[cal/mol-K]
Y_new = Cp_0_new/Cv_0_new;
T_2_new = T_1*((P_1/P_2)**((1-Y_new)/Y_new));			#[K]

			# The enthalpy change is given by 

def f23(T): 
	 return 4.750+1.200*10**(-2)*T+0.3030*10**(-5)*T**(2)-2.630*10**(-9)*T**(3)

delta_H =  quad(f23,T_1,T_2_new)[0]


			#For adiabatic process
W = - delta_H;			#[cal/mol]
			# Now actual work done on the system is given by 
W_a = W/eff;			#[cal/mol]


			# Therefore actual change in enthalpy is - W_a, or
			# - W_a = 4.750*(T_2-T_1) + (1.2*10**(-2)/2)*(T_2**(2)-T_1**(2)) + (0.3030*10**(-5)/3)*(T_2**(3)-T_1**(3)) - (2.63*10**(-9)/4)*(T_2***(4)-T_1**(4));
			# Solving for T_2 in the above equation
def f1(T_2_prime): 
	 return 4.750*(T_2_prime-T_1)+((1.2*10**(-2))/2)*(T_2_prime**(2)-T_1**(2))+((0.3030*10**(-5))/3)*(T_2_prime**(3)-T_1**(3))-((2.63*10**(-9))/4)*(T_2_prime**(4)-T_1**(4))+W_a
T_2_prime=fsolve(f1,100)

print " The required work is %f cal/mol"%(W_a);
print " The discharge temperature of methane is %f K"%(T_2_prime);
 The required work is -1254.158148 cal/mol
 The discharge temperature of methane is 427.374758 K

Example 4.13 Page Number : 164

In [13]:
 
P_1 = 10;			#[bar] - Initial pressure
T_1 = 500 + 273.15;			#[K] - Initial temperature
P_2 = 2;			#[psia] - Final pressure
P_2 = P_2/14.5;			#[bar]
P_2 = P_2*10**(2);			#[kPa]
m = 1.8;			#[kg/s] - Mass flux
eff = 0.8;			# Efficiency

			# At state 1, from steam table
H_1 = 3478.5;			#[kJ/kg]
S_1 = 7.7622;			#[kJ/kg-K]
S_2 = S_1;			# Adiabatic process

			# From saturated steam table at 10 kPa
S_liq_1 = 0.6493;			#[kJ/kg-K]
S_vap_1 = 8.1502;			#[kJ/kg-K]
			# From saturated steam table at 15 kPa
S_liq_2 = 0.7549;			#[kJ/kg-K]
S_vap_2 = 8.0085;			#[kJ/kg-K]

# Calculations and Results
			# Threfore at P_2 
S_liq = S_liq_1 + ((S_liq_2-S_liq_1)/(15-10))*(P_2-10);
S_vap = S_vap_1 + ((S_vap_2-S_vap_1)/(15-10))*(P_2-10);

			# The dryness fraction at exit state is
x_2 = (S_1-S_liq)/(S_vap-S_liq);
			# The enthalpy at exit to be determined. At 10 kPa
H_liq_1 = 191.83;			#[kJ/kg]
H_vap_1 = 2584.7;			#[kJ/kg]
			# At 15 kPa
H_liq_2 = 225.94;			#[kJ/kg]
H_vap_2 = 2599.1;			#[kJ/kg]
			# Therfore at P_2
H_liq = H_liq_1 + ((H_liq_2-H_liq_1)/(15-10))*(P_2-10);
H_vap = H_vap_1 + ((H_vap_2-H_vap_1)/(15-10))*(P_2-10);

			# Enthalpy at state 2
H_2_s = H_liq*(1-x_2) + x_2*H_vap;			#[kJ/kg]
W = m*(H_1 - H_2_s);			#[kW]

print " 1).The power output is %f kW"%(W);

			#(2)
			# If the process is 80 % efficient the enthalpy change is
			# H_1 - H_2_a = eff*(H_1 - H_2_s)
H_2_a = H_1 - (0.8*(H_1 - H_2_s));

			# Now under these conditions temperature and entropy have to be determined. From superheated steam tables,as reported in the book
			# At 10 kPa and 100 C
H_2_1 = 2687.5;			#[kJ/kg]
S_2_1 = 8.4479;			#[kJ/kg-k]
			# At 10 kPa and 150 C
H_2_2 = 2783.0;			#[kJ/kg]
S_2_2 = 8.6882;			#[kJ/kg-k]
			# At 50 kPa and 100 C
H_3_1 = 2682.5;			#[kJ/kg]
S_3_1 = 7.6947;			#[kJ/kg-k]
			# At 50 kPa and 150 C
H_4_1 = 2780.1;			#[kJ/kg]
S_4_1 = 7.9401;			#[kJ/kg-k]
			# Therefore at P_2 and 100 C
H_prime_1 = H_2_1 + ((H_3_1-H_2_1)/(50-10))*(P_2-10);			#[kJ/kg]
S_prime_1 = S_2_1 + ((S_3_1-S_2_1)/(50-10))*(P_2-10);			#[kJ/kg-K]
			# Therefore at P_2 and 150 C
H_prime_2 = H_2_2 + ((H_4_1-H_2_2)/(50-10))*(P_2-10);			#[kJ/kg]
S_prime_2 = S_2_2 + ((S_4_1-S_2_2)/(50-10))*(P_2-10);			#[kJ/kg-K]

			# Enthalpy at exit is H_2_a. So at this condition temperature can be nom be determined
T_exit = ((H_2_a - H_prime_1)/(H_prime_2 - H_prime_1))/(150-100) + 100;			#[C]
			# The entropy at exit is
S_exit =  ((H_2_a - H_prime_1)/(H_prime_2 - H_prime_1))/(S_prime_2 - S_prime_1) + S_prime_1;			#[kJ/kg-K]

print " 2).The entropy at exit is %f kJ/kg-K"%(S_exit);
print "     The temperature of the exit state is %f C"%(T_exit);

print "     The irreversibility is advatageous because the exit steam is superheated and therefore";
print "     the blades of the turbine are not eroded by water droplets which get formed when the process is isentropic";
 1).The power output is 1753.346828 kW
 2).The entropy at exit is 8.906311 kJ/kg-K
     The temperature of the exit state is 100.002552 C
     The irreversibility is advatageous because the exit steam is superheated and therefore
     the blades of the turbine are not eroded by water droplets which get formed when the process is isentropic

Example 4.14 Page Number : 166

In [14]:
 
P_1 = 6;			#[MPa] - Initial pressure
T_1 = 500 + 273.15;			#[K] - Initial temperature
P_2 = 10;			#[kPa] - Final pressure
out_qlty = 0.9;			# Output quality

			# At 6 MPa and 500 C, from steam table as reported in the book
H_1 = 3422.2;			#[kJ/kg]
S_1 = 6.8803;			#[kJ/kg-K]
S_2 = S_1;			# Adiabatic reversible conditions
			# At 10 kPa saturated
H_liq = 191.83;			#[kJ/kg]
H_vap = 2584.7;			#[kJ/kg]
S_liq = 0.6493;			#[kJ/kg-K]
S_vap = 8.1502;			#[kJ/kg-K]

# Calculations and Results
			# The dryness fraction is given by 
x = (S_1-S_liq)/(S_vap-S_liq);

			# Now the exit enthalpy is given by
H_2 = H_liq*(1-x) + x*H_vap;			#[kJ/kg]
W = - (H_2 - H_1);			#[kJ/kg] - Under isentropic conditions

			# We know that, delta_S = q/T_b + S_gen
			# Since delta_S = 0, therefore under isentropic conditions
S_gen = 0;			#[kJ/kg-K]

			# Now for output quality 0.9
H_2_a = H_liq*(1-out_qlty) + out_qlty*H_vap;			#[kJ/kg]
S_2_a = S_liq*(1-out_qlty) + out_qlty*S_vap;			#[kJ/kg]
W_a = - (H_2_a - H_1);			#[kJ/kg]
delta_S_a = S_2_a - S_1;			#[kJ/kg-k]
			# Again,  delta_S = q/T_b + S_gen
			# Since q = 0, therefore under isentropic conditions
S_gen_a = delta_S_a;			#[kJ/kg-K
			# Now efficiency is given by eff = delta_H_a/delta_H_s
eff = W_a/W;

print " For output quality = 0.9";
print " The work output per unit mass is %f kJ/kg"%(W_a);
print " The entropy generation is given by S_gen = %f kJ/kg-K"%(S_gen_a);
print " The efficiency with respect to reversible adiabatic case is given by eff = %f"%(eff);

			# Now for output quality 1
out_qlty_1 = 1;
H_2_a_1 = H_liq*(1-out_qlty_1) + out_qlty_1*H_vap;			#[kJ/kg]
S_2_a_1 = S_liq*(1-out_qlty_1) + out_qlty_1*S_vap;			#[kJ/kg]
W_a_1 = - (H_2_a_1 - H_1);			#[kJ/kg]
delta_S_a_1 = S_2_a_1 - S_1;			#[kJ/kg-k]
			# Again,  delta_S = q/T_b + S_gen
			# Since q = 0, therefore under isentropic conditions
S_gen_a_1 = delta_S_a_1;			#[kJ/kg-K
			# Now efficiency is given by eff = delta_H_a/delta_H_s
eff_1 = W_a_1/W;

print " For output quality = 1.0";
print " The work output per unit mass is %f kJ/kg"%(W_a_1);
print " The entropy generation is given by S_gen = %f kJ/kg-K"%(S_gen_a_1);
print " The efficiency with respect to reversible adiabatic case is given by eff = %f"%(eff_1);
 For output quality = 0.9
 The work output per unit mass is 1076.787000 kJ/kg
 The entropy generation is given by S_gen = 0.519810 kJ/kg-K
 The efficiency with respect to reversible adiabatic case is given by eff = 0.866551
 For output quality = 1.0
 The work output per unit mass is 837.500000 kJ/kg
 The entropy generation is given by S_gen = 1.269900 kJ/kg-K
 The efficiency with respect to reversible adiabatic case is given by eff = 0.673983

Example 4.15 Page Number : 168

In [15]:
 
P_1 = 3.;			#[bar] - Initial pressure
T_1 = 150. + 273.15;			#[K] - Initial temperature
Vel_1 = 90.;			#[m/s] - Initial velocity
P_2 = 1.;			#[bar] - Final pressure
eff = 0.95;			# Adiabatic effciciency of the nozzle
R = 8.314;			#[J/mol*-] - Universal gas constant

			# At 3 bar and 150 C, from steam table
S_1 = 7.0778;			#[kJ/kg-K]
H_1 = 2761.0;			#[kJ/kg]
S_2 = S_1;			# 

			# At 1 bar saturated
S_liq = 1.3026;			#[kJ/kg-K]
S_vap = 7.3594;			#[kJ/kg-K]
H_liq = 417.46;			#[kJ/kg]
H_vap = 2675.5;			#[kJ/kg]

# Calculations and Results
			# The dryness factor of exit steam can be determined as
x = (S_1-S_liq)/(S_vap-S_liq);
			# Enthalpy of exit steam is given by 
H_2 = H_liq*(1-x) + x*H_vap;			#[kJ/kg]
delta_H_s = H_2 - H_1;			#[kJ/kg] - Enthalpy change
delta_H_a = eff*delta_H_s;			#[kJ/kg]

			# Assuming no heat exchange with surroundings and since no work is done
			# delta_H + (delta_V**(2))/2 = 0
delta_Vel_square = 2*(-delta_H_a)*1000;			#[m**(2)/s**(2)]
Vel_2 = (delta_Vel_square + Vel_1**(2))**(1./2);			#[m/s]

print " 1).The final velocity when fluid is steam) is %f m/s"%(Vel_2);

			# (2)
Y = 1.4;			# Index of expansion
Cp_0 = (Y*R)/(Y-1);			#[J/mol-K] - Specific heat capacity at constant pressure

			# P_1**(1-Y)*T_1**(Y) = P_2**(1-Y)*T_2**(Y)
T_2 = T_1*(P_1/P_2)**((1-Y)/Y);			#[K]
delta_H_s_2 = Cp_0*(T_2 - T_1);			#[J/mol]
delta_H_a_2 = eff*delta_H_s_2;			#[J/mol]
delta_H_a_2 = (delta_H_a_2*1000)/28.84;			#[J/kg]

delta_Vel_square_2 = 2*(-delta_H_a_2);			#[m**(2)/s**(2)]
Vel_2_2 = (delta_Vel_square_2 + Vel_1**(2))**(1./2);			#[m/s]

print " 2).The final velocity when fluid is air which behaves as an ideal gas) is %f m/s"%(Vel_2_2);
 1).The final velocity when fluid is steam) is 608.291583 m/s
 2).The final velocity when fluid is air which behaves as an ideal gas) is 476.065890 m/s

Example 4.16 Page Number : 169

In [16]:
 
# Variables
P_1 = 300.;			#[kPa] - Initial pressure
T_1 = 450.;			#[K] - Initial temperature
Vel_1 = 90.;			#[m/s] - Initial velocity
P_2 = 180.;			#[kPa] - Final pressure
eff = 0.95;			# Adiabatic effciciency of the nozzle
R = 8.314;			#[J/mol*-] - Universal gas constant
Cp = 5.19;			#[kJ/kg-K] - Specific heat capacity at constant pressure

# Calculations and Results
			#(a)


Mol_wt_He = 4;			#[g/mol] - Molecular weight of helium
R_He = R/Mol_wt_He;			# 'R' for helium
Y = Cp/(Cp - R_He);

			# Now temperature at exit to be determined
T_2s = T_1*(P_1/P_2)**((1-Y)/Y);			#[K]
delta_H_2s = Cp*(T_2s - T_1);			#[kJ/kg]

			# Since no work is done and heat exchange is zero,from first law we get
			# delta_H + delta_Vel**(2)/2 = 0
delta_Vel_square = 2*(-delta_H_2s)*1000;			#[m**(2)/s**(2)]
Vel_2 = (delta_Vel_square)**(1./2);			#[m/s] - ( as Vel_1  <<  Vel_2)

print " a).The maximum exit velocity is %f m/s"%(Vel_2);

			#(b)
T_2a = 373;			#[K] - Measured temperature of helium
delta_H_a = Cp*(T_2a - T_1);			#[kJ/kg]
delta_Vel_square_a = 2*(-delta_H_a)*1000;			#[m**(2)/s**(2)]
Vel_2a = (delta_Vel_square_a)**(1./2);			#[m/s] - ( as Vel_1  <<  Vel_2a)

print " b).The actual exit velocity is %f m/s"%(Vel_2a);

			#(c)
delta_S_sys = Cp*math.log(T_2a/T_1) - R_He*math.log(P_2/P_1);
			# we know that delta_S_sys = q/T_b + S_gen and since q = 0, therfore
S_gen = delta_S_sys;			#[kJ/kg-K]

print " c).The increasse in entropy per unit mass is %f kJ/kg-K"%(S_gen);
 a).The maximum exit velocity is 929.607346 m/s
 b).The actual exit velocity is 894.013423 m/s
 c).The increasse in entropy per unit mass is 0.087748 kJ/kg-K

Example 4.17 Page Number : 170

In [17]:
 
P_1 = 1;			#[bar] - Initial pressure
T_1 = 150 + 273.15;			#[K] - Initial temperature
V_2 = 0.28;			#[m**(3)/kg] - Final specific volume
T_2 = T_1;			#[K] - Isothermal process
R = 8.314;			#[J/mol-K] - Universal gas constant

			# At 1 bar and 150 C, from steam table
S_1 = 7.6134;			#[kJ/kg-K]
H_1 = 2776.4;			#[kJ/kg]

			# At 150 C saturated
V_liq = 0.001091;			#[m**(3)/kg]
V_vap = 0.3928;			#[m**(3)/kg]
H_liq = 632.2;			#[kJ/kg]
H_vap = 2746.5;			#[kJ/kg]
S_liq = 1.8418;			#[kJ/kg-K]
S_vap = 6.8379;			#[kJ/kg-K]

# Calculations and Results
			# The dryness factor of exit steam can be determined as
x = (V_2 - V_liq)/(V_vap - V_liq);
S_2 = S_liq*(1-x) + x*S_vap;			#[kJ/kg-K] -Entropy 
H_2 = H_liq*(1-x) + x*H_vap;			#[kJ/kg] -Enthalpy 
delta_H = H_2 - H_1;			#[kJ/kg] - Enthalpy change
delta_S = S_2 - S_1;			#[kJ/kg]

			# Since the compression is reversible
q = T_1*delta_S;			#[kJ/kg] - Heat transfer
			# From first law  q - W = delta_H
W = q - delta_H;			#[kJ/kg]

print " 1).The amount of heat transfer when fluid is steam) is %f kJ/kg"%(q)
print "     The amount of work transfer when fluid is steam) is %f kJ/kg"%(W)

			#(2)
V_2 = V_2*(28.84/1000);			#[m**(3)/mol] - Molar volume at exit
			# Pressure at exit is given by 
P_2 = ((R*T_2)/V_2);			#[N/m**(2)]
P_2 = P_2*10**(-5);			#[bar]

			# Entropy change is given by, delta_S_2 = Cp*math.log(T_2/T_1) - R*math.log(P_2/P_1), but since T_1 = T_2, therfore
delta_S_2 = - R*math.log(P_2/P_1);			#[J/mol-K]

q_2 = T_1*delta_S_2;			#[J/mol] - Heat change
q_2 = q_2/28.84;			#[kJ/kg]

			# Enthalpy change is given by,  delta_H_2 = Cp*(T_2 - T_1)  = 0 (as T_1 = T_2)
delta_H_2 = 0;			#[kJ/kg]

			# From first law  q - W = delta_H, therefore
W_2 = q_2 - delta_H_2;			#[kJ/kg]

print " 2).The amount of heat transfer when fluid is ideal gas) is %f kJ/kg"%(q_2)
print "     The amount of work transfer when fluid is ideal gas) is %f kJ/kg"%(W_2)
 1).The amount of heat transfer when fluid is steam) is -936.947741 kJ/kg
     The amount of work transfer when fluid is steam) is -298.195149 kJ/kg
 2).The amount of heat transfer when fluid is ideal gas) is -179.526401 kJ/kg
     The amount of work transfer when fluid is ideal gas) is -179.526401 kJ/kg

Example 4.18 Page Number : 171

In [18]:
 
P_1 = 7*10**(5);			#[Pa] - Initial pressure
T_1 = 95 + 273.15;			#[K] - Initial temperature
P_2 = 3.5*10**(5);			#[Pa] - Final pressure
dia = 15*10**(-2);			#[m] - Diameter of pipe
m = 2;			#[kg/s] - Mass flow rate
R = 8.314;			#[J/mol-K] - Universal gas constant
Y = 1.4;			# Index of expansion
Cp_0 = (R*Y)/(Y-1);			#[J/mol-K] - Specific heat capacity at constant pressure
Cp_0 = (Cp_0/28.84)*1000;			#[J/kg-K]
rho_1 = 6.6;			#[kg/m**(3)] - Density

# Calculations and Results
			# velocity before throttling is to be determined m = rho*Vol*Area
V_1 = (R*T_1)/P_1;			#[m**(3)/mol] - Specific volume
V_1 = (V_1/28.84)*1000;			#[m**(3)/kg]
Vel_1 = m/(rho_1*3.14*(dia/2)**(2));			#[m/s] - Velocity before throttling

			# Let the temperature after throttling be T_2, then
			# Vel_2 = m/(rho_2*Area) = (m*V_2)/(3.14*(dia/2)**(2))
			# From first law, since q = W = 0, we get
			# delta_H + (delta_V**(2))/2 = 0
			#Cp_0*(T_2 - T_1) +  (((m*((((R*T_2)/P_2)/28.84)*1000))/(3.14*(dia/2)**(2)))**(2) - (Vel_1)**(2))/2 = 0
			# Solving the above equation for T_2, we get
def f1(T_2): 
	 return Cp_0*(T_2 - T_1) +  (((m*((((R*T_2)/P_2)/28.84)*1000))/(3.14*(dia/2)**(2)))**(2) - (Vel_1)**(2))/2
T_2 =fsolve(f1,100)
			# Therefore velocity of air downstream of restriction is given by 
Vel_2 = ((m*((((R*T_2)/P_2)/28.84)*1000))/(3.14*(dia/2)**(2)));			#[m/s]

print " The velocity of air downstream of restriction is %f m/s"%(Vel_2);

delta_T = (T_2 - T_1);
			# Since temperature difference (delta_T) is very small, therefore enthalpy change is also very small

			# Entropy change is given by, delta_S = Cp_0*math.log(T_2/T_1) - R*math.log(P_2/P_1), but since T_1 and T_2 are almost equal
delta_S = - R*math.log(P_2/P_1);			#[J/mol-K]

print " The change in entropy is %f kJ/mol-k"%(delta_S);
 The velocity of air downstream of restriction is 34.295216 m/s
 The change in entropy is 5.762826 kJ/mol-k