In [1]:

```
# Variables
tsat = 179.91; # celsius
vf = 0.001127; # m**3/kg
vg = 0.19444; #m**3/kg
# Calculation
vfg = vg-vf;
sf = 2.1387;
sg = 6.5865;
sfg = sg-sf;
# Results
print "At 1 Mpa saturation temperature is",tsat,"degree"
print "Changes in specific volume is",vfg,"m3/kg"
print "Change in entropy during evaporation is",sfg,"kJ/kg K"
```

In [1]:

```
# Variables
v = 0.09
vf = 0.001177
vg = 0.09963;
# Calculation
x = (v-vf)/(vg-vf);
hf = 908.79; hfg = 1890.7;
sf = 2.4474; sfg = 3.8935;
h = hf+(x*hfg);
s = sf+(x*sfg);
# Results
print "The enthalpy and entropy of the system are %.4f and %.2f kJ/kg and kJ/kg K respectively"%(s,h)
# rounding off error. please check.
```

In [2]:

```
from numpy import interp
# Variables
# for T = 350 degree
T1 = 350;
v1 = 0.2003;
h1 = 3149.5;
s1 = 7.1369;
# for T = 400 degree
T2 = 400;
v2 = 0.2178;
h2 = 3257.5;
s2 = 7.3026;
# Calculation
# Interpolation for T = 380;
T = [T1 ,T2];
v = [v1 ,v2];
h = [h1 ,h2];
s = [s1 ,s2];
v3 = interp(380,T,v);
h3 = interp(380,T,h);
s3 = interp(380,T,s);
# Results
print "The entropy, enthalpy and volume of stem at 1.4MPa and 380 degree is %.4f kJ/Kg, %.1f kJ/Kg, %.4f kJ/Kg respectively"%(s3,h3,v3)
```

In [13]:

```
# Variables
Psat = 3.973e06;
vf = 0.0012512
vg = 0.05013;
hf = 1085.36
hfg = 1716.2;
sf = 2.7927
sfg = 3.2802;
mf = 9 # liquid in kg
V = 0.04; # volume
# Calculation
Vf = mf*vf;
Vg = V-Vf;
mg = Vg/vg;
m = mf+mg;
x = mg/m;
v = vf+x*(vg-vf);
h = hf+x*hfg;
s = sf+(x*sfg);
u = h-Psat*v*1e-03;
# at T = 250
uf = 1080.39
ufg = 1522;
u_ = uf+x*ufg;
# Results
print "The pressure is %.3f Mpa"%(Psat/1000000)
print "The mass is %.3f Kg"%m
print "Specific volume is %.5f m3/Kg"%v
print "Enthalpy is %.2f kJ/Kg"%h
print "The entropy is %.4f kJ/Kg K"%s
print "The interal energy is %.2f kJ/Kg"%u
print "u = %.2f kJ/kg"%u_ #incorrect answer in the textbook
# rounding off error. please check. book answers may wrong.
```

In [3]:

```
import math
from numpy import interp
# Part (a)
vg1_ = 0.8919
T1_ = 120;
vg2_ = 0.77076
T2_ = 125;
vg_ = [vg1_, vg2_]
T_ = [T1_, T2_];
v1 = 0.7964;
h1 = 2967.6;
P1 = 0.3e03; # in Kpa
# Calculation and Results
T1 = interp(v1,vg_,T_);
print "The steam become saturated at ",T1,"degree"
# Part (b)
vf = 0.001029
vg = 3.407;
hf = 334.91
hfg = 2308.8;
Psat = 47.39; # In kPa
v2 = v1;
x2 = (v1-vf)/(vg-vf);
h2 = hf+x2*hfg;
P2 = Psat;
Q12 = (h2-h1)+v1*(P1-P2);
print "The quality factor at t=80 degree is %.4f"%x2
print "The heat transfered per kg of steam in cooling from 250 degree to 80 degree %.2f kJ/Kg"%Q12
# rounding off error. interp function gives slightly different answer.
```

In [22]:

```
# Variables
# At T = 40 degree
Psat = 7.384e06;
sf = 0.5725
sfg = 7.6845;
hf = 167.57
hfg = 2406.7;
s1 = 6.9189
h1 = 3037.6;
# Calculation
x2 = round((s1-sf)/sfg,3) ;
h2 = hf+(x2*hfg);
W = h1-h2;
# Results
print "The ideal work output of the turbine is %.2f kJ/Kg"%W
# rounding off error. please check using calculator.
```

In [25]:

```
import math
from numpy import interp
# Variables
w3 = 2.3 #adiabatic mixing
w1 = 1.0;
w2 = w3-w1;
h1 = 2950.0;
# At 0.8MPa, 0.95 dry
x = 0.95;
hf = 721.11
hfg = 2048;
# Calculation
h2 = hf + (x*hfg);
h3 = ((w1*h1)+(w2*h2))/w3;
# Interpolation
H = [2769.1, 2839.3];
T = [170.43, 200];
t3 = interp(2790,H,T);
s3 = 6.7087;
s4 = s3;
x4 = (s3-1.7766)/5.1193;
h4 = 604.74+(x4*2133.8);
V4 = math.sqrt(2000*(h3-h4));
# Results
print "The condition of superheat after mixing %.2f degree"%(t3-T[0])
print "The velocity of steam leaving the nozzle is %.1f m/sec"%V4
# rounding off error. please check.
```

In [26]:

```
# Variables
h2 = 2716.2
hf = 844.89
hfg = 1947.3;
# Calculation
x1 = (h2-hf)/hfg;
h3 = 2685.5;
x4 = (h3-hf)/hfg;
# Results
print "The quality of steam in pipe line is %.3f"%x1
print "Maximum moisture is %.2f %%"%(100-(x4*100))
# rounding off error.
```

In [8]:

```
# Variables
# At 0.1Mpa, 110 degree
h2 = 2696.2
hf = 844.89
hfg = 1947.3;
# Calculation
x2 = (h2-hf)/hfg;
vf = 0.001023; # at T = 70 degree
V = 0.000150; # In m3
m1 = V/vf;
m2 = 3.24;
x1 = (x2*m2)/(m1+m2);
# Results
print "The quality of the steam in the pipe line is %.3f"%x1
```

In [5]:

```
# Variables
# P = 1MPa
vf = 0.001127
vg = 0.1944;
hg = 2778.1
uf = 761.68;
ug = 2583.6
ufg = 1822;
# Initial anf final mass
Vis = 5.
Viw = 5.;
Vfs = 6.
Vfw = 4.
# Calculation
ms = ((Viw/vf)+(Vis/vg)) - ((Vfw/vf)+(Vfs/vg)) ;
U1 = ((Viw*uf/vf)+(Vis*ug/vg));
Uf = ((Vfw*uf/vf)+(Vfs*ug/vg));
Q = Uf-U1+(ms*hg)
# Results
print "The heat transfer during the process is",round(Q/1000,3),"kJ"
# It seems book answer is wrong. please check using calculator.
```

In [32]:

```
import math
# Variables
m = 0.02
d = 0.28
l = 0.305;
P1 = 0.6e06
P2 = 0.12e06;
# Calculation and Results
# At 0.6MPa, t = 200 degree
v1 = 0.352
h1 = 2850.1;
V1 = m*v1;
Vd = (math.pi/4)*d**2*l;
V2 = V1+Vd ;
n = math.log(P1/P2)/math.log(V2/V1);
W12 = ((P1*V1)-(P2*V2))/(n-1);
print "The value of n is %.2f"%n
print "The work done by the steam is %.1f kJ"%(W12/1000)
v2 = V2/m;
vf = 0.0010476
vfg = 1.4271;
x2 = (v2-vf)/vfg ;
# At 0.12MPa
uf = 439.3
ug = 2512.0;
u2 = uf + (x2*(ug-uf));
u1 = h1-(P1*v1*1e-03);
Q12 = m*(u2-u1)+ (W12/1000);
print "The heat transfer is %.3f kJ"%Q12
# rounding off error. please check.
```

In [10]:

```
# Variables
x1 = 1.
x2 = 0.8;
# at 0.2MPa
vg = 0.8857
v1 = vg
hg = 2706.7
h1 = hg;
m1 = 5.
V1 = m1*v1;
# Calculation
# at 0.5MPa
m2 = 10;
hf = 640.23
hfg = 2108.5
vf = 0.001093
vfg = 0.3749;
v2 = vf+(x2*vfg);
V2 = m2*v2;
Vm = V1+V2;
m = m1+m2;
vm = Vm/m;
u1 = h1;
h2 = hf+(x2*hfg);
u2 = h2;
m3 = m;
h3 = ((m1*u1)+(m2*u2))/m3;
u3 = h3;
v3 = vm;
# From mollier diagram
x3 = 0.870
p3 = 3.5
s3 = 6.29;
s1 = 7.1271;
sf = 1.8607
sfg = 4.9606;
s2 = sf+(x2*sfg);
E = m3*s3-((m1*s1)+(m2*s2));
# Results
print "Final pressure is ",p3,"bar"
print "Steam quality is",x3
print "Entropy change during the process is %.2f kJ/K"%E
```

In [11]:

```
# Variables
# At 6 MPa, 400 degree
h1 = 3177.2
s1 = 6.5408;
# At 20 degree
h0= 83.96
s0 = 0.2966;
T0 = 293.
# Calculation
f1 = (h1-h0)-T0*(s1-s0);
# By interpolation
t2 = 273. + 393;
s2 = 6.63;
h2 = h1;
f2 = (h2-h0)-T0*(s2-s0);
df = f1-f2;
x3s = (s2-1.5301)/(7.1271-1.5301);
h3s = 504.7+(x3s*2201.9);
eis = 0.82;
h3 = h2-eis*(h1-h3s);
x3 = (h3-504.7)/2201.7;
s3 = 1.5301+(x3*5.597);
f3 = (h3-h0)-T0*(s3-s0);
# Results
print "The availability of the steam before the throttle valve %.1f kJ/Kg"%f1
print "The availability of the steam after the throttle valve %.2f Kj/Kg"%f2
print "The availability of the steam at the turbine exhaust %.2f kJ/Kg"%f3
print "The specific work output from the turbine is %.1f kJ/Kg"%(h2-h3)
```

In [4]:

```
# Variables
# At 25 bar, 350 degree
h1 = 3125.87
s1 = 6.8481;
# 30 degree
h0 = 125.79
s0 = 0.4369;
h2 = 2865.5
s2 = 7.3115;
# At 0.2 bar 0.95 dry
hf = 251.4
hfg = 2358.3;
sf = 0.8320
sg = 7.0765;
# Calculation
h3 = hf+0.92*hfg;
s3 = sf+(0.92*sg);
# Part (a)
T0 = 303;
f1 = (h1-h0)-(T0*(s1-s0));
f2 = (h2-h0)-(T0*(s2-s0));
f3 = (h3-h0)-(T0*(s3-s0));
# Results
print "Availability of steam entering at state 1 is %.2f kJ/Kg"%f1
print "Availability of steam leaving at state 2 is %.2f kJ/Kg"%f2
print "Availability of steam leaving at state 3 is %.2f kJ/Kg"%f3
# Part (b)
m2m1 = 0.25
m3m1 = 0.75;
Wrev = f1-(m2m1*f2)-(m3m1*f3);
print "Maximum work is %.2f kJ/Kg"%Wrev
# Part (c)
w1 = 600.
w2 = 150.
w3 = 450.;
Q = -10.*3600; # For 1 hour
I = T0*(w2*s2+w3*s3-w1*s1)-Q;
print "Irreversibility is %.2f MJ/h"%(I/1000)
# rounding off error. please check using calcultor.
```

In [64]:

```
# Variables
# At dead state of 1 bar, 300K
u0 = 113.1
h0 = 113.2;
v0 = 0.001005
s0 = 0.0395;
T0 = 300.
P0 = 100.;
# Calculation and Results
K = h0-(T0*s0);
# Part (a)
u = 376.9
h = 377;
v = 0.001035
s = 1.193;
m = 3
a = h - 300 * s
fi = m*(a - (-5.3)) # As P = P0 = 1 bar
print "Energy of system in Part (a) is",fi,"kJ"
# Part (b)
u = 3099.8
h = 3446.3
v = 0.08637
s = 7.090; # At P = 4 Mpa, t = 500 degree
m = 0.2;
b = u +100* v - 300 * s
fib = m*(b-(-5.3));
print "Energy of system in Part (b) is",fib,"kJ"
# Part (c)
m = 0.4;
x = 0.85; # Quality
u = 192+x*2245;
h = 192+x*2392;
s = 0.649+x*7.499;
v = 0.001010+x*14.67;
c = round(u + 100*v - 300*s,1)
fic = m*(c - (-5.3));
print "Energy of system in Part (c) is",round(fic,1),"kJ"
# Part (d)
m = 3;
h = -354.1; s = -1.298; # at 1000kPa, -10 degree
fid = m*(h-h0-T0*(s-s0))# ((h-h0)-T0*(s-s0));
print "Energy of system in Part (d) is",fid,"kJ"
# book answer is wrong. please check.
```

In [14]:

```
# Variables
# Given
th1 = 90.+273;
tc1 = 25.+273;
tc2 = 50.+273;
mc = 1.
T0 = 300.;
th2p = 60.+273; # Parallel
th2c = 35.+273; # Counter
# Calculation
mhp = (tc2-tc1)/(th1-th2p); # Parallel
mhc = (tc2-tc1)/(th1-th2c); # Counter
h0 = 113.2
s0 = 0.395
T0 = 300; # At 300 K
h1 = 376.92
s1 = 1.1925; # At 90 degree
af1 = mhp*((h1-h0)-T0*(s1-s0));
# Parallel Flow
h2 = 251.13; s2 =0.8312; # At 60 degree
h3 = 104.89; s3 = 0.3674; # At 25 degree
h4 = 209.33; s4 = 0.7038; # At 50 degree
REG = mc*((h4-h3)-T0*(s4-s3)); # Rate of energy gain
REL = mhp*((h1-h2)-T0*(s1-s2)); # Rate of energy loss
Ia = REL-REG; # Energy destruction
n2a = REG/REL; # Second law efficiency
# Results
print ("In parallel flow")
print "The rate of irreversibility is",Ia,"kW"
print "The Second law efficiency is %.2f %%"%(n2a*100)
# Counter flow
h2 = 146.68
s2 = 0.5053; # At 35 degree
REG_b = REG; # Rate of energy gain by hot water is same in both flows
REL_b = mhc*((h1-h2)-T0*(s1-s2));
Ib = REL_b-REG_b; # Energy destruction
n2b = REG_b/REL_b; # Second law efficiency
print ("In Counter flow")
print "The rate of irreversibility is %.2f kW"%Ib
print "The Second law efficiency is %.2f %%"%(n2b*100)
```

In [15]:

```
# Variables
m = 50 ; # in kg/h
Th = 23.+273; # Home temperature
# State 1
T1 = 150.+273;
h1 = 2746.4;
s1 = 6.8387;
# State 2
h2 = 419.0;
s2 = 1.3071;
T0 = 318;
# Calculation
b1 = h1-(T0*s1);
b2 = h2-(T0*s2);
Q_max = m*(b1-b2)/(T0/Th-1);
# Results
print "The maximum cooling rate is %.0f kW"%(Q_max/3600)
```