In [1]:

```
import math
from __future__ import division
#Variable declaration
m=100; # Mass of water in kg
T0=90; # Initial temperature of water in degree celcius
T=30; # temperature of Surroundings in degree celcius
C=4.1868; # Specific heat in kJ/kg K
#Calculation
AE=m*C*((T0-T)-(T+273)*math.log ((T0+273)/(T+273))); # Available energy
Q=m*C*(T0-T); # Heat supplied
UE=Q-AE; # Unavailable energy
#Result
print "Available energy =",round(AE,0),"kJ"
print "Heat supplied = ",round(Q,0),"kJ","\nUnavailable energy = ",round(UE,0),"kJ"
```

In [2]:

```
import math
from __future__ import division
#Variable declaration
T=250; # Evaporation teemperature of water in degree celcius
Ta=1250; # Initial temperature of combustion gas in degree celcius
Tb=350; # Final temperature of combustion gas in degree celcius
C=1.08; # Specific heat of gas in kJ/kg K
T0=30; # temperature of Surroundings in degree celcius
hfg=1716.2; # Enthalpy of evaporation at T temperature
#Calculation
del_SH2O=hfg/(T+273); # Entropy change of water
mgas=hfg/(C*(Ta-Tb)); # Mass of gas
del_Sgas=mgas*C*math.log ((Tb+273)/(Ta+273)); # Enthalpy change of gas
del_Stotal=del_SH2O+del_Sgas; # Total entropy change
l_AE=(T0+273)*del_Stotal; # Loss of available energy
#Result
print "Loss of available energy = ",round(l_AE,1),"kJ"
```

In [3]:

```
import math
from __future__ import division
#Variable declaration
Cp=1.1; # Specific heat of combustion gas in kJ/kg K
T3=1600; # Initial temperature of combustion gas in Kelvin
T4=1150; # Final temperature of combustion gas in Kelvin
p1=0.1; # Pressure at inlet of boiler in MPa
p2=8;# Pressure at outlet of boiler in MPa
T2=600; # Temperature at outlet of boiler in degree celcius
m=1; # Mass of water in kg
T0=298; # temperature of Surroundings in kelvin
#Calculation for (b)
# (b).mass flow rate of gases per kg of water
# From steam table
h1=2758; h2=3642;# specific enthalpy in kJ/kg
s1=5.7432; s2=7.0206; # specific entropy in kJ/kg K
mgas=(h2-h1)/(Cp*(T3-T4)); #mass flow rate of gases per kg of water
#Result for (b)
print "(b).mass flow rate of gases per kg of water =",round(mgas,3),"kg gas / kg water"
#Calculation for (c)
# (c). Degrease in Available energy
S21=s2-s1; # Change in entropy of water
S34=mgas*Cp*math.log (T3/T4); # Change in entropy of gases
UEgases=T0*S34; # UnAvailable energy of gas
UEsteam=T0*S21; # UnAvailable energy of steam
d_AE=UEsteam-UEgases; # Degrease in Available energy
#Result for (c)
print "\n(c).","\nChange in entropy of water = ",round(S21,4),"kJ/K","\nChange in entropy of gas = ",round(-S34,4),"kJ/K"
print "Unavailable energy of gas = ",round(UEgases,1),"kJ","\nUnavailable energy of steam =",round(UEsteam,1),"kJ"
print "Degrease in Available energy = ",round(d_AE,1),"kJ"
```

In [4]:

```
import math
from __future__ import division
#Variable declaration
T=700;# Exhaust gas temperature in degree celcius
p=120;# Exhaust gas pressure in kPa
Cpo=1.089; # Specific heat at constant pressure in kJ/kg K
R=0.287; # characteristic gas constant in kJ/kg K
p0=100; # Pressure of Surroundings in kPa
T0=30; # temperature of Surroundings in degree celcius
#Calculation
Cvo=Cpo-R; # Specific heat at constant volume
AE=(Cvo*(T-T0))+(p0*R*((T+273)/p-(T0+273)/p0))-((T0+273)*((Cpo*math.log((T+273)/(T0+273)))-(R*math.log (p/p0)))); # Available energy
#Result
print "Available energy in Exhaust gas =",round(AE,0),"kJ"
```

In [5]:

```
import math
from __future__ import division
#Variable declaration
p1=450; # Initial pressure in kPa
T=600; # Initial temperature in kelvin
V1=0.01; # Initial volume in m^3
TR=1200; # Temperature of heat source in Kelvin
V2=0.02; # Final volume in m^3
p0=100; # Pressure of Surroundings in kPa
T0=300; # temperature of Surroundings in kelvin
#Calculation
# Useful Work
W=p1*V1*math.log (V2/V1); # Actual work
Wsurr=p0*(V2-V1); # Surrounding work
Wu=W-Wsurr; # Useful work
# Reversible work
Q=W; # For isothermal process
S21=Q/T; # Entropy change of system
Wrev=T0*S21-Wsurr+Q*(1-T0/TR); # reversible work
# Irreversibility of the process
I=Wrev-Wu; # Irreversibility
# Entropy generation
del_Sgen=S21-Q/TR;#Entropy generation
#Results
print "Useful Work for the process =",round(Wu,2),"kJ"
print "Reversible work for the provess =",round(Wrev,1),"kJ"
print "Irreversibility of the process = ",round(I,2),"kJ"
print "Entropy generation of the process = ",round(del_Sgen,4),"kJ/kg"
```

In [6]:

```
#Variable declaration for (i)
# (i).Irreversibility in Turbine
p1=9; # Steam pressure at turbine inlet in MPa
T1=450; # Steam temperature at turbine inlet in degree celcius
p2=50; # Steam pressure at turbine outlet in MPa
x2=0.95; # Quality of steam
p0=100; # Pressure of Surroundings in kPa
T0=300; # temperature of Surroundings in kelvin
q=-10; # Heat loss in kJ/kg
#Calculation for (a)
# (a).Decrease in availability
# from steam table
h1=3256.6; h2=2415.4;# specific enthalpy in kJ/kg
s1=6.4844; s2=6.944; # specific entropy in kJ/kg K
d_AE=(h1-h2)-(T0*(s1-s2)); # Decrease in availability
#Result for (a)
print "(i).Irreversibility in turbine","\n (a).Decrease in availability =",round(d_AE,1),"kJ/kg"
#Calculation for (b)
# (b).Maxximum work output
wrev=d_AE; #Maxximum work output
#Result for (b)
print " (b).Maxximum work output =",round(wrev,1),"kJ/kg"
#Calculation for (c)
# (c).Actual work output
w=(h1-h2)+q; # From SSSF energy equation
#Result for (c)
print " (c).Actual work output = ",round(w,1),"kJ/kg"
#Calculation for (d)
# (d).Irreversibility
I=wrev-w; #Irreversibility
#Result for (d)
print " (d).Irreversibility = ",round(I,1),"kJ/kg"
#Variable declaration for (ii)
# (ii).Ammonia compressor
T1=-10; # Temperature at inlet in degree celcius
p2=1.554; # Pressure at outlet in MPa
T2=140; # Temperature at outlet in degree celcius
T0=298; # temperature of Surroundings in kelvin
#from ammonia tables
h1=1433; h2=1752;# specific enthalpy in kJ/kg
s1=5.477; s2=5.655; # specific entropy in kJ/kg K
#Calculation for (ii)
wactual=-(h2-h1); # Actual work
wmin=-((h2-h1)-(T0*(s2-s1)));# mimimum work
I=wmin-wactual;# Irreversibility
#Result for (ii)
print "\n(ii).Ammonia compressor","\nActual work = ",wactual,"kJ/kg"
print "Minimum work =",round(wmin,0),"kJ/kg","\nIrreversibility =",round(I,0),"kJ/kg"
```

In [7]:

```
import math
from __future__ import division
#Variable declaration
Cp=1.1; # Specific heat of combustion gas in kJ/kg K
T3=1600; # Initial temperature of combustion gas in Kelvin
T4=1150; # Final temperature of combustion gas in Kelvin
p1=0.1; # Pressure at inlet of boiler in MPa
p2=8;# Pressure at outlet of boiler in MPa
T2=600; # Temperature at outlet of boiler in degree celcius
m=1; # Mass of water in kg
T0=298; # temperature of Surroundings in kelvin
# From steam table
h1=2758; h2=3642;# specific enthalpy in kJ/kg
s1=5.7432; s2=7.0206; # specific entropy in kJ/kg K
#Calculation
mgas=(h2-h1)/(Cp*(T3-T4)); #mass flow rate of gases per kg of water
S21=s2-s1; # Change in entropy of water
S34=mgas*Cp*math.log (T3/T4); # Change in entropy of gases
# (a).Decrease in availability of gases
d_AEgas=mgas*Cp*(T3-T4)-T0*S34#Decrease in availability of gases
#Result for (a)
print "(a).Decrease in availability of gases = ",round(d_AEgas,2),"kJ"
#Calculation for (b)
# (b).Decrease in availability of water
d_AEwater=(h1-h2)-T0*(s1-s2);# Decrease in availability of water
#Result for (b)
print "(b).Decrease in availability of water =",round(d_AEwater,1),"kJ"
#Calculation for (c)
# (c).Reversible work for the process
Wrev=d_AEgas+d_AEwater; #Reversible work for the process
#Result for (c)
print "(c).Reversible work for the process=",round(Wrev,1),"kJ"
#Calculation for (d)
# (d).Actual work for the process
W=0; # Actual work
#Result for (d)
print "(d).Actual work for the process =",W,"kJ"
#Calculation for (e)
# (e).Irreversibility
I=Wrev-W; #Irreversibility
#Result for (e)
print "(e).Irreversibility = ",round(I,1),"kJ"
```

In [8]:

```
#Variable declaration
TH=600; # Temperature of heat sorce in degree celcius
T3=311.06; # Boiler temperature in degree celcius
p3=10; # Boiler pressure in MPa
T4=32.88; # Condensor temperature in degree celcius
p4=5; # Condensor pressure in kPa
T0=288;# Temperature of surroundings in kelvin
# From steam table and refer figure 10.10 for states
h1=137.82; h2=147.82; h3=2724.7; hf4=197.82; hfg4=2423.7; h4=1913.6; # specific enthalpy in kJ/kg
s1=0.4764; s2=s1; s3=5.6141; s4=s3; sf4=0.4764; sfg4=7.9187; s4=6.2782; # specific entropy in kJ/kg K
#Calculation
wT=h3-h4; # Turbine work
wp=h2-h1; # Pump work
wnet=wT-wp; # Net work
qH=h3-h2; # Heat supplied in boiler
qL=h4-h1; # Heat rejected in condensor
Wrev_Wpump=T0*(s2-s1);
Wrev_Wboiler=T0*(s3-s2)-T0*qH/(TH+273);
Wrev_Wturbine=T0*(s4-s3);
Wrev_Wcondenser=T0*(s1-s4)+qL;
Wrev_Wcycle=Wrev_Wpump+Wrev_Wboiler+Wrev_Wturbine+Wrev_Wcondenser;
#Result
print "The lost (Wrev-W)for the Pump = ",Wrev_Wpump,"kJ/kg","\nThe lost (Wrev-W)for the Boiler = ",round(Wrev_Wboiler,1),"kJ/kg"
print "The lost (Wrev-W)for the Turbine = ",round(Wrev_Wturbine,1),"kJ/kg"
print "The lost (Wrev-W)for the condensor = ",round(Wrev_Wcondenser,1),"kJ/kg"
print "The lost (Wrev-W)for the overall cycle = ",round(Wrev_Wcycle,0),"kJ/kg"
```

In [9]:

```
#Variable declaration
# State after reversible adiabatic expansion
p2=50; # pressure in kPa
s2s=6.4844; s1=6.4844; s2=6.944; # specific entropy in kJ/kg K
x2s=0.829; # Quality of steam
h2s=2252.6; h1=3256.6; # specific enthalpy in kJ/kg
T2=81.33; T0=27; # Temperature in degree celcius
#Calculation
ws=h1-h2s; # Reversible adiabatic work
wa=831.2; # Actual work output in kJ/kg
d_AE=979.1; # Decrease in availability in kJ/LG
eff_I=wa/ws; # First law efficiency of turbine
eff_II=wa/d_AE; # Second law efficiency of turbine
w2srev2=(T2-T0)*(s2-s1); # Negative work
w1rev2=ws-w2srev2; # Decrease in availability
#Result
print "First law efficiency of turbine = ",round(eff_I*100,1),"%","\nSecond law efficiency of turbine = ",round(eff_II*100,1),"%"
print "Negative work = ",round(w2srev2,2),"kJ/kg","\nDcresase in Availability = ",round(w1rev2,2),"kJ/kg"
```

In [10]:

```
import math
from __future__ import division
#Variable declaration
p1=100; # Pressure at inlet in kPa
T1=30; # Temperature at inlet in degree celcius
V1=0; # Velocity at inlet in m/s
p2=350; # Pressure at outlet in kPa
T2=141; # Temperature at exit in degree celcius
V2=90; # Velocity at exit in m/s
p0=100; # Pressure of Surroundings in kPa
T0=30; # temperature of Surroundings in degree celcius
k=1.4; # Index of the Isentropic compression process
Cpo=1.0035; # Specific heat at constant pressure in kJ/kg K
R=0.287; # characteristic gas constant of air in kJ/kg K
#Calculation for (a)
# (a).Adiabatic or polytropic compression
T2s=(T1+273)*(p2/p1)**((k-1)/k); # Temperature after isentropic compression
#Result for (a)
print "(a).Adiabatic or polytropic compression","\nTemperature after isentropic compression =",round(T2s,1),"K"
print "T2s>T2. Hence there is cooling . Compression is polytropic."
#Calculation for (b)
# (b).The first law efficiency of the compressor
wa=Cpo*(T1-T2)-V2**2/2000; #Actual work of compression
wT=(-R*(T1+273)*math.log (p2/p1))-(V2**2/2000); # Isothermal work
eff_Ilaw=wT/wa; # The first law efficiency of the compressor
#Result for (b)
print "\n(b).The first law efficiency of the compressor = ",round(eff_Ilaw*100,1),"%"
#Calculation for (c)
# (c).Minimum work input & Irreversibility
d_AE=(Cpo*(T1-T2))+((T0+273)*((R*math.log (p2/p1))-(Cpo*math.log ((T2+273)/(T1+273)))))-V2**2/2000; # decrease in availability
wmin=d_AE; # Minimum work input
wrev=wmin;
I=wrev-wa; # Irreversibility
#Result for (c)
print "\n(c).Minimum work input & Irreversibility","\nMinimum work input =",round(wmin,1),"kJ/kg"
print "Irreversibility =",round(I,0),"kJ/kg"
#Calculation for (d)
# (d).Second law efficiency of the compressor
eff_IIlaw=wmin/wa; # Second law efficiency of the compressor
#Result for (d)
print "\n(d).Second law efficiency of the compressor =",round(eff_IIlaw*100,0),"%"
```

In [11]:

```
import math
from __future__ import division
#Variable declaration
T0=313; # Surroundings temperature in kelvin
TL=233; # Refrigerated space temperature in kelvin
QL=3.5167; # Refrigeration load in kW
#Calculation for (a)
# (a).Carnot cycle
COPcarnot=TL/(T0-TL); # COP of carnot cycle
Wcarnot=QL/COPcarnot; # Work done
Q0=QL+Wcarnot; # Heat rejected
d_SL=-QL/TL;# Entropy change of refrigerated space
d_S0=Q0/T0; #Entropy change of surroundings
d_Sgen= d_SL+ d_S0; # Entropy generation
#Result for (a)
print "(a).Carnot cycle","\nWork done = ",round(Wcarnot,4),"kW","\nCOP of carnot cycle = ",round(COPcarnot,4)
print (" Entropy generation = %d kJ/K s ")%d_Sgen
#Variable declaration for (b)
# (b).Vapour compression cycle
# From Freon-12 property table & figure 10.17
p1=0.0642; p2=0.9607; # Pressure in MPa
h1=169.5; h3=74.5; # specific enthalpy in kJ/kg
s1=0.7269; s3=0.2716;# specific entropy in kJ/kg K
# By calculations s2=s1 gives the following from property table
t2=58.9; # Temperature in degree celcius
h2=217.6; # specific enthalpy in kJ/kg
# From h4=h3 gives the following from chart
h4=h3;
x4=0.44; # Quality of vapour
s4=0.3195;# specific entropy in kJ/kg K
#Calculation for (b)
m=QL/(h1-h4); # Mass flow rate of refrigerant
W=m*(h2-h1); # Work done of vapour compression cycle
COP=QL/W; # COP of vapour compression cycle
QH=QL+W; # Heat rejected to surroundings
d_SL=-QL/TL;# Entropy change of refrigerated space
d_S0=QH/T0; #Entropy change of surroundings
d_Sgen= d_SL+ d_S0; # Entropy generation
#Result for (b)
print "\n(b).Vapour compression cycle","Work done = ",round(W,3),"kW","\nCOP of vapour compression cycle = ",round(COP,2)
print (" Entropy generation = %f kJ/K s ")%round(d_Sgen,5)
#Calculation for (c)
# (c).Difference in work = Lost work of the cycle
d_work=W-Wcarnot; # Difference in work
LWcycle=QH-T0*QL/TL; # Lost work of the cycle
#Result for (c)
print "\n(c).Difference in work = Lost work of the cycle","\nDifference in work = ",round(d_work,4),"kW"
print "Lost work of the cycle= ",round(LWcycle,4),"kW","which is same as Difference in work"
#Calculation for (d)
# (d).Second Law efficiency of the vapour compression cycle
eff_II=COP/COPcarnot; #Second Law efficiency
#Result for (d)
print "\n(d).Second Law efficiency of the vapour compression cycle = ",round(eff_II*100,1),"%"
```