import math
T0 = 35.0 # Heat rejection temperature in degree Celsius
T1 = 420 # Vapor condensation temperature in degree Celsius
T1_ = 250 # water vapor temperature in degree Celsius
print "\n Example 8.1"
f = ((T0+273)*((T1+273)-(T1_+273)))/((T1_+273)*((T1+273)-(T0+273)))# fraction of energy lost
print "\n The fraction of energy that becomes unavailable due to irreversible heat transfer is ",f
#The answers vary due to round off error
from scipy import integrate
import math
lhw = 1858.5 # Latent heat of water in kJ/kg
Tew = 220 # Water evaporation temperature in degree Celsius
Tig = 1100 # Initial temperature of the gas in degree Celsius
Tfg = 550 # Final temperature of the gas in degree Celsius
T0 = 303 # Atmospheric temperature in degree Celsius
Tg2 = 823
Tg1 = 1373
print "\n Example 8.2"
Sw = lhw/(Tew+273) # Entropy generation in water
Sg,error = integrate.quad(lambda T:3.38/T,Tg1,Tg2)
St = Sg+Sw
print "\n Total change in entropy is ",St ," kJ/K"
print "\n Increase in unavailable energy is ",T0*St ," kJ"
#The answers vary due to round off error
import math
from scipy import integrate
Ts_ = 15 # Ambient temperature in degree Celsius
Tw1_ = 95 # Temperature of water sample 1 in degree Celsius
Tw2_ = 35# Temperature of water sample 2 in degree Celsius
m1 = 25 # Mass of water sample 1 in kg
m2 = 35 # Mass of water sample 2 in kg
cp = 4.2 # Specific heat capacity of water in kJ/kgK
print "\n Example 8.4"
Ts = Ts_+273# Ambient temperature in K
Tw1 = Tw1_+273 # Temperature of water sample 1 in K
Tw2 = Tw2_+273# Temperature of water sample 2 in K
AE25,er = integrate.quad(lambda T:m1*cp*(1-(Ts/T)),Ts,Tw1)
AE35,er2 = integrate.quad(lambda T:m2*cp*(1-(Ts/T)),Ts,Tw2)
AEt = AE25 + AE35
Tm = (m1*Tw1+m2*Tw2)/(m1+m2) # Temperature after mixing
AE60,er3 = integrate.quad(lambda T:(m1+m2)*cp*(1-(Ts/T)),Ts,Tm)
AE = AEt - AE60
print "\n The decrease in the available energy is ",AE ," kJ"
import math
from scipy import integrate
N1 = 3000 # Speed of rotation of flywheel in RPM
I = 0.54 # Moment of inertia of flywheel in kgm**2
ti_ = 15 # Temperature of insulated system in degree Celsius
m = 2 # Water equivalent of shaft
print "\n Example 8.5"
w1 = (2*math.pi*N1)/60 # Angular velocity of rotation in rad/s
Ei = 0.5*I*w1**2 # rotational kinetic energy
dt = Ei/(1000*2*4.187) # temperature change
ti = ti_+273# Temperature of insulated system in Kelvin
tf = ti+dt # final temperature
AE,er = integrate.quad(lambda T: m*4.187*(1-(ti/T)),ti,tf)
UE = Ei/1000 - AE # Unavailable enrgy
w2 = math.sqrt(AE*1000*2/I) # Angular speed in rad/s
N2 = (w2*60)/(2*math.pi) # Speed of rotation in RPM
print "\n The final RPM of the flywheel would be ",N2 ," RPM"
import math
from scipy import integrate
T1_ = 80.0 # Initial temperature of air in degree Celsius
T2_ = 5.0 # Final temperature of air in degree Celsius
V2 = 2.0 # Assumed final volume
V1 = 1.0 # Assumed initial volume
P0 = 100.0 # Final pressure of air in kPa
P1 = 500.0 # Initial pressure of air in kPa
R = 0.287 # Gas constant
cv = 0.718 # Specific heat capacity at constant volume for gas in kJ/kg K
m = 2.0 # Mass of gas in kg
print "\n Example 8.6"
T1= T1_+273 # Initial temperature of air in K
T2 = T2_+273 # Final temperature of air in K
S= integrate.quad(lambda T:(m*cv)/T,T1,T2)[0] + integrate.quad(lambda V: (m*R)/V,V1,V2)[0] # Entropy change
U = m*cv*(T1-T2)# Change in internal energy
Wmax = U-(T2*(-S)) # Maximum possible work
V1_ = (m*R*T1)/P1 # volume calculation
CA = Wmax-P0*(V1_) # Change in availability
I = T2*S # Irreversibility
print "\n The maximum work is ",Wmax ," kJ"
print "\n Change in availability is ",CA ," kJ"
print "\n Irreversibility is ",I ," kJ"
#The answers vary due to round off error
import math
P1 = 500.0 # Initial pressure of steam in kPa
P2 = 100.0# Final pressure of steam in kPa
T1_ = 520.0 #Initial temperature of steam in degree Celsius
T2_ = 300.0 #Final temperature of steam in degree Celsius
cp = 1.005 # Specific heat capacity of steam in kJ/kgK
t0 = 20.0 # Atmospheric temperature in degree Celsius
R = 0.287 # Gas constant
Q = -10.0 # Heat loss to surrounding in kJ/kg
print "\n Example 8.7"
T1 = T1_+273 #Initial temperature of steam in degree Celsius
T2 = T2_+273 #Final temperature of steam in degree Celsius
S21 = (R*math.log(P2/P1))-(cp*math.log(T2/T1))
T0 = t0+273
CA = cp*(T1-T2)-T0*S21 # Change in availability
Wmax = CA # Maximum possible work
W = cp*(T1-T2)+Q # net work
I = Wmax-W # Irreversibility
# Altenatively
Ssystem = -Q/T0
Ssurr = -S21
I1 = T0*(Ssystem+Ssurr)
print "\n The decrease in availability is ",CA ," kJ/kg"
print "\n The maximum work is ",Wmax ," kJ/kg"
print "\n The irreversibility is ",I ," kJ/kg"
print "\n Alternatively, The irreversibility is ",I1 ," kJ/kg"
import math
T0 = 300.0 # Atmospheric temperature in K
Tg1_ = 300.0 # Higher temperature of combustion product in degree Celcius
Tg2_ = 200.0 # Lower temperature of combustion product in degree Celcius
Ta1 = 40.0 # Initial air temperature in K
cpg = 1.09 # Specific heat capacity of combustion gas in kJ/kgK
cpa = 1.005# Specific heat capacity of air in kJ/kgK
mg = 12.5 # mass flow rate of product in kg/s
ma = 11.15# mass flow rate of air in kg/s
print "\n Example 8.8"
Tg1 = Tg1_+273 # Higher temperature of combustion product in K
Tg2 = Tg2_+273 # Lower temperature of combustion product in K
f1 = cpg*(Tg1-T0)-T0*cpg*(math.log(Tg1/T0)) # Initial availability of product
f2 = cpg*(Tg2-T0)-T0*cpg*(math.log(Tg2/T0)) # Final availabilty of product
print "\n The initial and final availbility of the products are ",f1 ," kJ/Kg and ",f2 ," kJ/Kg respectively"
#The answer provided in the textbook is wrong
# Part (b)
Dfg = f1-f2 # Decrease in availability of products
Ta2 = (Ta1+273) + (mg/ma)*(cpg/cpa)*(Tg1-Tg2) # Exit temperature of air
Ifa = cpa*(Ta2-(Ta1+273))-T0*cpa*(math.log(Ta2/(Ta1+273))) # Increase in availability of air
I = mg*Dfg-ma*Ifa # Irreversibility
print "\n The irreversibility of the process is ",I ," kW"
##The answer provided in the textbook contains round off error
# Part (c)
Ta2_ = (Ta1+273)*(Tg1/Tg2)**((12.5*1.09)/(11.5*1.005))
Q1 = mg*cpg*(Tg1-Tg2) # Heat supply rate from gas to working fluid
Q2 = ma*cpa*(Ta2_-(Ta1+273))# Heat rejection rate from the working fluid in heat engine
W = Q1-Q2 # Power developed by heat engine
print "\n Total power generated by the heat engine is ",W ," kW"
#The answer provided in the textbook contains round off error
import math
T2 = 790.0 # Final temperature of gas in degree Celsius
T1 = 800.0 # Initial temperature of gas in degree Celsius
m = 2.0 # Mass flow rate in kg/s
cp = 1.1 # Specific heat capacity in kJ/KgK
T0 = 300.0 # Ambient temperature in K
print "\n Example 8.9"
I = m*cp*(((T1+273)-(T2+273))-T0*(math.log((T1+273)/(T2+273)))) # irreversibility rate
print "\n The irreversibility rate is ",I ," kW"
# At lower temperature
T1_ = 80.0 # Initial temperature of gas in degree Celsius
T2_ = 70.0 # Initial temperature of gas in degree Celsius
I_ = m*cp*(((T1_+273)-(T2_+273))-T0*(math.log((T1_+273)/(T2_+273)))) # irreversibility rate
print "\n The irreversibility rate at lower temperature is ",I_ ," kW"
#The answers vary due to round off error
import math
m = 3 # Mass flow rate in kg/s
R = 0.287 # Gas constant
T0 = 300 # Ambient temperature in K
k = 0.10 # Fractional pressure drop
print "\n Example 8.10"
Sgen = m*R*k # Entropy generation
I = Sgen*T0 # Irreversibility Calculation
print "\n The rate of energy loss because of the pressure drop due to friction ",I ," kW"
import math
m1 = 2.0 # Flow rate of water in kg/s
m2 = 1.0 # Flow rate of another stream in kg/s
T1 = 90.0 # Temperature of water in degree Celsius
T2 = 30.0# Temperature of another stream in degree Celsius
T0 =300.0 # Ambient temperature in K
cp = 4.187 # Specific heat capacity of water in kJ/kgK
print "\n Example 8.11"
m = m1+m2 # Net mass flow rate
x = m1/m # mass fraction
t = (T2+273)/(T1+273) # Temperature ratio
Sgen = m*cp*math.log((x+t*(1-x))/(t**(1-x))) # Entropy generation
I = T0*Sgen # Irreversibility production
# Alternatively
T = (m1*T1+m2*T2)/(m1+m2) # equilibrium temperature
Sgen1 = m1*cp*math.log((T+273)/(T1+273))+m2*cp*math.log((T+273)/(T2+273))# Entropy generation
I1 = T0*Sgen1 # Irreversibility production
print "\n The rate of entropy generation is ",Sgen ," kW/K"
print "\n The rate of energy loss due to mixing is ",I ," kW"
print "\n The rate of energy loss due to mixing is ",I1 ," kW" # Calculation from alternative way
#The answers vary due to round off error
import math
Qr = 500.0 # Heat release in kW
Tr = 2000.0 # Fuel burning temperature in K
T0 = 300.0 # Ambient temperature in K
# Part (a)
print "\n Example 8.12"
Qa = 480.0 # Energy absorption by furnace in kW
Ta = 1000.0 # Furnace temperature in K
n1a = (Qa/Qr) # first law efficiency
n2a = n1a*(1.0-(T0/Ta))/(1.0-(T0/Tr)) #second law efficiency
#The answers vary due to round off error
print " \n\n PART (A)"
print "\n The first law efficiency is ",n1a*100 ," percent"
print "\n The second law efficiency is ",n2a*100 ," percent"
# Part (b)
Qb = 450.0 # Energy absorption in steam generation in kW
Tb = 500.0# steam generation temperature in K
n1b = (Qb/Qr)# first law efficiency
n2b = n1b*(1.0-(T0/Tb))/(1.0-(T0/Tr))#second law efficiency
print " \n\n PART (B)"
print "\n The first law efficiency is ",n1b*100 ," percent"
print "\n The second law efficiency is ",n2b*100 ," percent"
# Part (c)
Qc = 300.0 # Energy absorption in chemical process in kW
Tc = 320.0 # chemical process temperature in K
n1c = (Qc/Qr) # first law efficiency
n2c = n1c*(1.0-(T0/Tc))/(1.0-(T0/Tr))#second law efficiency
print " \n\n PART (C)"
print "\n The first law efficiency is ",n1c*100 ," percent"
print "\n The second law efficiency is ",n2c*100 ," percent"
# Part (d)
Qd = 450.0
n1d = (Qd/Qr)
n2a_= n1d*(1.0-(T0/Ta))/(1.0-(T0/Tr))
n2b_= n1d*(1.0-(T0/Tb))/(1.0-(T0/Tr))
n2c_= n1d*(1.0-(T0/Tc))/(1.0-(T0/Tr))
print " \n\n PART (D)"
print "\n The First law efficiency for all the three cases would remain same and here is ",n1d*100 ," percent" #The answer provided in the textbook is wrong
print "\n The Second law efficiency of part (a) is ",n2a_*100 ," percent"
print "\n The Second law efficiency of part (b) is ",n2b_*100 ," percent"
print "\n The Second law efficiency of part (c) is ",n2c_*100 ," percent"
import math
cp = 1.005 # Specific heat capacity of air in kJ/kgK
T2 = 160.0 # Compressed air temperature in degree Celsius
T1 = 25.0 # Ambient temperature
T0 = 25.0 # Ambient temperature
R = 0.287 # Gas constant
P2 = 8.0 # Pressure ratio
P1 = 1.0 # Initial pressure of gas in bar
Q = -100.0 # Heat loss to surrounding in kW
m = 1.0 # Mass flow rate in kg/s
print "\n Example 8.14"
W = Q + m*cp*((T1+273)-(T2+273)) # power input
AF = cp*((T2+273)- (T1+273))-(T0+273)*((cp*math.log((T2+273)/(T1+273))-(R*math.log(P2/P1)))) # Availability
e = AF/-W # efficiency
print "\n The power input is ",W ," kW"
print " \n The second law efficiency of the compressor is ",e*100 ," percent"
#The answers vary due to round off error
import math
# Since vacuum has zero mass
U = 0 # Initial internal energy in kJ/kg
H0 = 0 # Initial enthalpy in kJ/kg
S = 0 # Initial entropy in kJ/kgK
# If the vacuum has reduced to dead state
U0 = 0 # Final internal energy in kJ/kg
H0 = 0 # Final enthalpy in kJ/kg
S0 = 0 # Final entropy in kJ/kgK
V0 = 0 # Final volume in m**3
P0 = 1.0 # Pressure in bar
V = 1.0 # Volume of space in m**3
fi = P0*1e5*V
print "\n Example 8.15"
print "\n The exergy of the complete vacuum is ",fi/1e3 ," kJ"
import math
m = 1000.0 # Mass of fish in kg
T0 = 300.0 # Ambient temperature in K
P0 = 1.0 # Ambient pressure in bar
T1 = 300.0 # Initial temperature of fish in K
T2_ = -20.0 # Final temperature of fish in degree Celsius
Tf_ = -2.2 # Freezing point temperature of fish in degree Celsius
Cb = 1.7 # Specific heat of fish below freezing point in kJ/kg
Ca = 3.2 # Specific heat of fish above freezing point in kJ/kg
Lh = 235.0 # Latent heat of fusion of fish in kJ/kg
print "\n Example 8.16"
T2 = T2_+273 # Final temperature of fish in K
Tf = Tf_+273 # Freezing point temperature of fish in K
H12 = m*((Cb*(Tf-T2))+Lh+(Ca*(T1-Tf))) # Enthalpy change
H21 = -H12 # Enthalpy change
S12 = m*((Cb*math.log(Tf/T2))+(Lh/Tf)+(Ca*math.log(T1/Tf))) # Entropy change
S21 = -S12 # Entropy change
E = H21-T0*S21 #Exergy produced
print "\n Exergy produced is ",E/1e3 ," MJ or ",E/3600 ," kWh"
#The answers vary due to round off error
import math
cv = 0.718 # Specific heat capacity of air in kJ/kg
T2 = 500.0 # Final temperature of air in K
T1 = 300.0# Initial temperature of air in K
m = 1.0 # Mass of air in kg
T0 = 300.0 # Ambient temperature
# Case (a)
print "\n Example 8.17"
Sua = cv*math.log(T2/T1) # Entropy change of universe
Ia = T0*Sua # irreversibility
print "\n The irreversibility in case a is ",Ia ," kJ/kg"
# Case (b)
Q = m*cv*(T2-T1) # Heat transfer
T = 600 # Temperature of thermal reservoir in K
Sub = Sua-(Q/T) # Entropy change of universe
Ib = T0*Sub # irreversibility
print "\n The irreversibility in case b is ",Ib ," kJ/kg"
#The answers vary due to round off error
import math
h1 = 3230.9 # Enthalpy of steam at turbine inlet in kJ/kg
s1 = 6.69212# Entropy of steam at turbine inlet in kJ/kgK
V1 = 160.0 # Velocity of steam at turbine inlet in m/s
T1 = 400.0 # Temperature of steam at turbine inlet in degree Celsius
h2 = 2676.1 # Enthalpy of steam at turbine exit in kJ/kg
s2 = 7.3549 # Entropy of steam at turbine exit in kJ/kgK
V2 = 100.0 # Velocity of steam at turbine exit in m/s
T2 = 100.0 # Temperature of steam at turbine exit in degree Celsius
T0 = 298.0 # Ambient temperature in K
W = 540.0 # Work developed by turbine in kW
Tb = 500.0 # Average outer surface temperature of turbine in K
print "\n Example 8.18"
Q = (h1-h2)+((V1**2-V2**2)/2)*1e-03-W # Heat loss
I = 151.84-Q*(0.404) # Irreversibility
AF = W + Q*(1.0-(T0/Tb)) + I # Exergy transfer
n2 = W/AF # second law efficiency
print "\n Irreversibility per unit mass is ",I ," kJ/kg"
print "\n The second law efficiency of the turbine is ",n2*100 ," percent"
import math
T0 = 300.0 # Ambient temperature in K
T = 1500.0 # Resistor temperature in K
Q = -8.5 # Power supply in kW
# Case (a)
W = -Q # work transfer
I = Q*(1.0-T0/T) + W # Irreversibility
R = Q*(1.0-T0/T) # availability
print "\n Example 8.19"
print "\n Case A:"
print "\n Rate of availability transfer with heat and the irreversibility rate are \n ",I ," kW and ",R ," kW respectively."
# Case (b)
T1 = 500.0 # Furnace wall temperature
Ib = - Q*(1.0-T0/T) + Q*(1.0-T0/T1) # Irreversibility
print "\n Case B:"
print "\n Rate of availability in case b is ",Ib ," kW "
import math
p1 = 1 # Air pressure at compressure inlet in bar
t1 = 30 # Air temperature at compressure inlet in degree Celsius
p2 = 3.5 # Air pressure at compressure exit in bar
t2 = 141 # Air temperature at compressure exit in degree Celsius
v = 90 # Air velocity at compressure exit in m/s
cp = 1.0035 # Specific heat capacity of air in kJ/kg
y = 1.4 # Heat capacity ratio
R = 0.287 # Gas constant
print "\n Example 8.20\n"
T2s = (t1+273)*(p2/p1)**((y-1)/y)
if T2s>(t2+273):
print "\n Part A:"
print "\n There is heat loss to surrounding."
n =(1/(1-((math.log((t2+273)/(t1+273)))/(math.log(p2/p1)))))
print "\n\n Part B:"
print "\n The polytropic index is ",n
Wa = cp*(t1-t2)-(v**2)/2000 # Actual work
Wt = -R*(t1+273)*math.log(p2/p1) - (v**2)/2000 # Isothermal work
nt =Wt/Wa # Isothermal efficency
print "\n\n Part C:"
print "\n Isothermal efficiency is ",nt*100 ," percent "
df = cp*(t1-t2) + (t1+273)*(R*math.log(p2/p1) - cp*math.log((t2+273)/(t1+273))) -(v**2)/2000
Wm = df # Minimum work input
I = Wm-Wa # Irreversibility
print "\n\n Part D:"
print "\n The minimum work input is ",Wm," kJ/kg, and irreversibility is ",I ," kJ/kg"
# The answers given in the book contain round off error
neta = Wm/Wa
print "\n\n Part E:"
print "\n Second law efficiency is ",math. ceil(neta*100) ," percent"