In [3]:

```
from __future__ import division
#Variable Declaration:
p1 = 1.6 #Pressure of entering steam(in MPa):
T1 = 300+273 #Temperature of entering steam(in K):
p2 = 0.1 #Pressure of leaving steam(in MPa):
T2 = 150+273 #Temperature of leaving steam(in K):
c2 = 150 #Velocity of the leaving steam(in m/s):
m = 2.5 #Mass flow rate(in kg/s):
#From steam tables:
h1 = 3034.8 #kJ/kg
s1 = 6.8844 #kJ/kg.K
h2 = 2776.4 #kJ/kg
s2 = 7.6134 #kJ/kg.K
#Calculations:
T0 = 15+273 #Surrounding temperature(in K):
Wmax = (h1-h2)-T0*(s1-s2)-(c2**2)/2*10**(-3) #Maxiimum work possible(in kW):
#Results:
print "Maximum work possible: ",round(m*Wmax,2),"kW"
```

In [4]:

```
from __future__ import division
from math import log
#Variable Declaration:
pa = 1 #Pressure of air(in bar) for tank A:
m = 1 #Mass of air(in kg):
Cv = 0.717 #Value of Cv(in kJ/kg.K):
T = 50+273 #Temperature(in K):
R = 0.287 #Gas costant(in kJ/kg.K):
p0 = 1 #Atmospheric pressure(in bar):
T0 = 15+273 #Atmosphere temperature(in K):
Cp = 1.004 #Value of Cp(in kJ/kg.K):
pb = 3 #Pressure(in bar) for tank B:
#Calculations:
AA = m*(Cv*(T-T0)+R*(p0/pa*T-T0)-T0*Cp*log(T/T0)+T0*R*log(pa/p0)) #Availability of air in tank A(in kJ):
AB = m*(Cv*(T-T0)+R*(p0/pb*T-T0)-T0*Cp*log(T/T0)+T0*R*log(pb/p0)) #Availability of air in tank B(in kJ):
#Results:
print "Availabiltiy of air in tank A: ",round(AA,2),"kJ"
print "Availability of air in tank B: ",round(AB,2),"kJ"
```

In [5]:

```
from __future__ import division
#Variable Declaration:
m = 15 #Mass of steam(in kg):
p1 = 10 #Pressure of entering steam(in bar):
T1 = 300+273 #Temperature(in K):
p2 = 0.05 #Pressure of leaving steam(in bar):
x = 0.95 #Dryness fraction:
v2 = 160 #Velocity(in m/s):
p0 = 1 #Atmosheric pressure(in bar):
T0 = 15+273 #Atmospheric temperature(in K):
#From steam tables:
h1 = 3051.2 #kJ/kg
s1 = 7.1229 #kJ/kg.K
sf = 0.4764 #kJ/kg.K
sfg = 7.9187 #kJ/kg.K
hf = 137.82 #kJ/kg
hfg = 2423.7 #kJ/kg
h0 = 62.99 #kJ/kg
s0 = 0.2245 #kJ/kg.K
#Calculations:
h2 = hf+x*hfg #Enthalpy at exit of turbine(in kJ/kg):
s2 = sf+x*sfg #Entropy at exit of turbine(in kJ/kg.K):
W = (h1-h2)-v2**2/2*10**(-3) #Work output(in kJ/kg):
pW = m*W #Power output(in kW):
Wmax = (h1-T0*s1)-(h2+v2**2/2*10**(-3)-T0*s2) #Maximum work given end states(in kW):
Ae = (h2-h0)+v2**2/2*10**(-3)-T0*(s2-s0) #Maximum wor kavailable from exhaust steam(in kJ/kg):
Wme = m*Ae #Maximum power that could be obtained from exhaust steam(in kW):
#Results:
print "Power output: ",round(pW,1), "kW"
print "Maximum power output: " ,round(m*Wmax,1), "kW"
print "Maximum power from exhaust steam: ",round(Wme,1), "kW"
```

In [10]:

```
from __future__ import division
#Variable Declaration:
m = 5 #Mass of steam(in kg):
z1 = 10 #Initial elevation(in m):
V1 = 25 #Initial velocity(in m/s):
z2 = 2 #Final elevation(in m):
V2 = 10 #Final velocity(in m/s):
#Dead state of water
u0 = 104.86 #kJ/kg
v0 = 1.0029*10**(-3)#m3/kg
s0 = 0.3673 #kJ/kg·K
p0 = 100 #kPa
T0 = 25+273 #K
#Initial state
u1 = 2550 #kJ/kg
v1 = 0.5089 #m3/kg
s1 = 6.93 #kJ/kg·K
#Final state
u2 = 83.94 #kJ/kg
v2 = 1.0018*10**(-3)#m3/kg
s2 = 0.2966 #kJ/kg·K
g = 9.81 #Acceleration due to gravity(in m/s**2):
#Calculation:
A1 = m*((u1-u0)*10**3+p0*10**3*(v1-v0)-T0*(s1-s0)*10**3+V1**2/2+g*z1)#Availability at initial state(in kJ):
A2 = m*((u2-u0)*10**3+p0*10**3*(v2-v0)-T0*(s2-s0)*10**3+V2**2/2+g*z2)#Availability at final state(in kJ):
dA = A2-A1 #Change in availability(in kJ)
#Results:
print "Initial availabilty: ",round(A1/10**3,2), "kJ"
print "Final availabilty:",round(A2/10**3,2),"kJ"
print "Availability decreases by: ",round(-dA/10**3,2), "kJ"
```

In [15]:

```
from __future__ import division
#Variable Declaration:
T1 = 800+273 #Temperature of IC engine(in K):
W = 1050 #Work per kg of gas in engine(in kJ/kg):
Cp = 1.1 #Cp of gas(in kJ/kg.K):
#Calculations:
T0 = 30+273 #Temperature of the surroundings(in K):
dSsys = W/T1 #Change in entropy of system(in kJ/kg.K):
dSsurr = -Cp*(T1-T0)/T0 #Change in entropy of surroundings(in kJ/kg.K):
L = -T0*(dSsys+dSsurr) #Loss of available energy(in kJ/kg):
r = L/W #Ratio of lost available exhaust energy to engine work:
#Results:
print "Ratio of available exhaust energy to engine work: ",round(r,3)
```

In [18]:

```
from __future__ import division
#Variable Declaration:
m = 10 #Mass of water(in kg):
T1 = 150+273 #Initial temperature(in K):
V1 = 25 #Initial velocity(in m/s):
z1 = 10 #Initial elevation(in m):
T2 = 20+273 #Final temperature(in K):
V2 = 10 #Final velocity(in m/s):
z2 = 3 #Final elevation(in m):
p0 = 0.1 #Pressure of environment(in MPa):
T0 = 25+273.13 #Temperature of environment(in K):
g = 9.8 #Acceleration due to gravity(in m/s**2):
#Dead state of water, From steam tables:
u0 = 104.88 #kJ/kg
v0 = 1.003*10**(-3) #m3/kg
s0 = 0.3674 #kJ/kg·K
u1 = 2559.5 #kJ/kg
v1 = 0.3928 #m3/kg
s1 = 6.8379 #kJ/kg·K
u2 = 83.95 #kJ/kg
v2 = 0.001002 #m3/kg
s2 = 0.2966 #kJ/kg·K
A1 = m*((u1-u0)+p0*10**3*(v1-v0)-T0*(s1-s0)+(V1**2/2+g*z1)*10**-3)#Availability at initial state(in kJ):
A2 = m*((u2-u0)+p0*10**3*(v2-v0)-T0*(s2-s0)+(V2**2/2+g*z2)*10**-3)#Availability at final state(in kJ):
dA = A2-A1 #Change in availability(in kJ):
#Results:
print "Initial availabilty: ",round(A1,2),"kJ"
print "Final availabilty: ",round(A2,2),"kJ"
print "Availability decreases: ",round(-dA,2),"kJ"
```

In [20]:

```
from __future__ import division
#Variable Declaration:
m = 5 #Mass flow rate(in kg/s):
#At inlet to turbine,
p1 = 5 #MPa
T1 = 500+273.15 #K
h1 = 3433.8 #kJ/kg
s1 = 6.9759 #kJ/kg.K
#At exit from turbine.
p2 = 0.2 #MPa
T2 = 140+273.15 #K
h2 = 2748 #kJ/kg
s2 = 7.228 #kJ/kg·K
#At dead state,
p0 = 101.3 #kPa
T0 = 25+273.15 #K
h0 = 104.96 #kJ/kg
s0 = 0.3673 #kJ/kg·K
Q = 600 #Heat loss(in kJ/s):
#Calculation:
A1 = m*((h1-h0)-T0*(s1-s0)) #Availablity of steam at inlet(in kJ):
W = m*(h1-h2)-Q #Turbine output(in kW):
Wmax = m*((h1-h2)-T0*(s1-s2)) #Maximum output(in kW):
I = Wmax-W #Irreversibilty(in kW):
#Results:
print "Availability of steam at inlet: ",round(A1,2),"kJ"
print "Turbine output: ",round(W),"kW"
print "Maximum output: ",round(Wmax,2),"kW"
print "Irreversibility: ",round(I,2),"kW"
print "_____Please Check there is a calculation mistake in Wmax hence answer differs_____"
```

In [26]:

```
from __future__ import division
#Variable Declaration:
Q = 500 #Heat removed(in kJ):
T1 = 835 #Temperature of the heat reservoir(in K):
T2 = 720 #Temperature of the system(in K):
T0 = 280 #Temperature of surroundings(in K):
#Calculation:
A1 = T0*Q/T1 #Availability for heat reservoir(in kJ/kg.K):
A2 = T0*Q/T2 #Availability for system(in kJ/kg.K):
Anet = A1-A2 #Net loss of available energy(in kJ/kg.K):
#Results:
print "Loss of available energy: ",round(-Anet,2),"kJ/kg.K"
```

In [28]:

```
from __future__ import division
#Variable Declaration:
h1 = 4142 #Enthalpy at entrance(in kJ/kg):
h2 = 2585 #Enthalpy at exit(in kJ/kg):
A1 = 1787 #Availability of steam at entrance(in kJ/kg):
A2 = 140 #Availability of steam at exit(in kJ):
#Calculation:
Wmax = A1-A2 #Maximum work possible(in kJ/kg):
Wact = h1-h2 #Actual work from turbine(in kJ/kg):
#Results:
print "Actual work: ",round(Wact),"kJ/kg"
print "Maximum possible work: ",round(Wmax),"kJ/kg"
```

In [30]:

```
from __future__ import division
#Variable Declaration:
Tmin = 20+273 #Minimum temperature(in K):
Tmax = 500+273 #Maximum temperature(in K):
n = 0.25 #Efficiency of heat engine:
#Calculations:
nrev = 1-Tmin/Tmax #Reversible engine efficiency:
n2 = n/nrev #Second law efficiency:
#Result:
print "Second law efficiency: ",round(n2*100,2),"%"
```

In [33]:

```
from __future__ import division
from math import log
#Variable Declaration:
Va = 6 #Volume of compartment A(in m**3):
Vb = 4 #Volume of compartment B(in m**3):
p1 = 6 #Pressure in compartment A(in bar):
T1 = 600 #Temperature in compartment A(in K):
p0 = 1 #Atmosheric pressure(in bar):
T0 = 300 #Atmosheric temperature(in K):
r = 1.4 #Adiabatic index of compression:
R = 0.287 #Gas constant(in J/kg.K):
Cv = 0.718 #Value of Cv(in kJ/kg.K):
#Calculation:
V2 = Va+Vb #Final volume(in m**3):
T2 = T1*(Va/V2)**(r-1) #Final temperature(in K):
m = p1*10**5*Va/(R*10**3*T1) #Mass of air(in kg):
dSs = round(m*(Cv*log(T2/T1)+R*log(V2/Va)),3)#Change in entropy of control system(in kJ/kg.K):
I = T0*dSs #Loss of available energy or irreversibilty(in kJ):
#Results:
print "Loss of available energy: ",round(-I,3),"kJ"
```

In [37]:

```
from __future__ import division
#Variable Declaration:
Tmin = 30+273 #Minimum temperature(in K):
Tmax = 700+273 #Maximum temperature(in K):
T0 = 17+273 #Temperature of surroundings(in K):
Q1 = 2*10**4 #Rate at which engine receives heat(in kJ/min):
Wu = 0.13*10**3 #Measured output of the engine(in kW):
#Calculation:
nrev = 1-Tmin/Tmax #Efficiency:
Wrev = nrev*Q1/60 #Availability or reversible work(in kJ/s):
I = Wrev-Wu #Rate of irreversibility(in kJ/s):
n2 = Wu/Wrev #Second law efficiency:
#Results:
print "Availability: ",round(Wrev*60/10**4,2)," x 10^4 kJ/min"
print "Rate of irreversibility: ",round(I,2),"kW"
print "Second Law Efficiency: ",round(n2*100,2),"%"
```

In [39]:

```
from __future__ import division
#Variable Declaration:
p1 = 1.5 #Initial pressure(in bar):
T1 = 60+273 #Initial temperature(in K):
p2 = 2.5 #Final pressure(in bar):
Tres = 400+273 #Temperature of the reservoir(in K):
T0 = 27+273 #Temperature of surroundings(in K):
Cp = 1.005 #Cp of air(in kJ/kg.K):
#Calculations:
T2 = T1*p2/p1 #Final temperature(in K):
Q = Cp*(T2-T1) #Heat addition to air in the tank(in kJ/kg):
dSs = Q/T1 #Change in entropy of the system(in kJ/kg.K):
dSe = -Q/Tres #Change in entropy of environment(in kJ/kg.K):
dS = dSs+dSe #Total change in entropy(in kJ/kg.K):
L = T0*dS #Loss of available energy(in kJ/kg):
#Results:
print "Loss of available energy:",round(L,1),"kJ/kg.K"
```

In [45]:

```
from __future__ import division
#Variable Declaration:
#From steam tables:
vg = 0.12736
vf = 0.001157
p205 = 1.7230
p195 = 1.3978
T = 200+273
hfga = 1940.7
#Calculation:
vfg = vg-vf #Value of vfg(in m**3/kg):
r = (p205-p195)/(205-195) #Value of dp/dT(in MPa/K):
hfg = T*vfg*r*10**3 #By Clapeyron equation(in kJ/kg):
#Results:
print "Calculated enthalpy of vaporization: ",round(hfg,2),"kJ/kg"
print "Enthalpy of vaporization from steam table:",round(hfga,1),"kJ/kg"
```

In [48]:

```
from math import log
#Variable Declaration:
#From steam tables:
p5 = 260.96 #kPa
p15 = 182.60 #kPa
vg10 = 0.07665 #m**3/kg
vf10 = 0.00070 #m**3/kg
R = 0.06876 #kJ/kg.K
hfg10 = 156.3 #kJ/kg
#Calculation:
T = -5+273
T1 = -15+273
T2 = -5+273
hfg = T*(vg10-vf10)*(p5-p15)/(15-5) #Value of hfg, by Clapeyron equation:
hfg1 = log(p5/p15)*R*(T1*T2)/((T2-T1)) #By Clapeyron-Clausius equation:
d = (hfg1-hfg)/hfg*100 #Deviation:
#Results:
print "hfg by Clapeyron equation: ",round(hfg,2),"kJ/kg"
print "hfg by Clapeyron-Clausius equation: ",round(hfg1,2),"kJ/kg"
print "Percentage deviation in hfg value by Clapeyron-Clausius equation compared to the value from Clapeyron equation: ",round(d,2),"%"
```

In [51]:

```
from __future__ import division
#Variable Declaration:
#From steam tables:
v350 = 0.9534
v250 = 0.7964
v300 = 0.8753
v350kPa = 0.76505
v250kPa = 1.09575
#Calculation:
ve = (v350-v250)/(v300*(350-250)) #Volume expansivity(in 1/K):
ic = -(v350kPa-v250kPa)/(v300*(350-250))#Isothermal compressibility(in 1/kPa):
#Results:
print "Volume expansivity: ",round(ve*10**3,4),"x 10^-3 K^-1"
print "Isothermal compressibility: ",round(ic*10**3,3),"x 10^-3 kPa^-1"
```

In [53]:

```
from __future__ import division
from math import log
#Variable Declaration:
V = 0.5 #Volume of tank(in m**3):
p0 = 1 #Atmospheric pressure(in bar):
T0 = 25+273 #Atmospheric temperature(in K):
Cp = 1.005 #Cp of gas(in kJ/kg.K):
Cv = 0.718 #Cv of gas(in kJ/kg.K):
Ti = T0 #Initial temperature(in K):
#Calculations:
Tf = Cp/Cv*Ti #Inside final temperature(in K):
dSgen = Cp*log(Tf/Ti) #Change in entropy(in kJ/kg.K):
I = T0*dSgen #Irreversibility(in kJ/kg):
#Results:
print "Inside final temperature",round(Tf,2),"K"
print "Change in entropy: ",round(dSgen,4),"kJ/kg.K"
print "Irreversibility",round(I,2),"kJ/kg"
```

In [57]:

```
from __future__ import division
from math import log
#Variable Declaration:
m = 75 #Mass of water(in kg):
T1 = 400+273 #Temperature of hot water(in K):
T2 = 300 #Final temperature(in K):
T0 = 27+273 #Temperature of the environment(in K):
Cp = 4.18 #Specific heat of water(in kJ/kg.K):
#Calculation:
Wmax = m*Cp*(T1-T2-T0*log(T1/T2))#Maximum work(in kJ):
#Results:
print "Maximum work: ",round(Wmax,1),"kJ"
```

In [59]:

```
from __future__ import division
#Variable Declaration:
p1 = 50 #Pressure at which steam enters(in bar):
T1 = 600+273 #Temperature at which steam enters(in K):
c1 = 150 #Velocity at which steam enters(in m/s):
p2 = 0.1 #Pressure at which steam leaves(in bar):
c2 = 50 #Velocity at which steam leaves(in m/s):
W = 1000 #Work delivered(in kJ/kg):
T0 = 25+273 #Dead state temperature(in K):
#From steam tables:
h1 = 3666.5 #kJ/kg
s1 = 7.2589 #kJ/kg.K
h2 = 2584.7 #kJ/kg
s2 = 8.1502 #kJ/kg.K
#Calculations:
A1 = h1+c1**2/2*10**(-3)-T0*s1 #Inlet stream availability(in kJ/kg):
A2 = h2+c2**2/2*10**(-3)-T0*s2 #Exit stream availability(in kJ/kg):
Wrev = A1-A2 #Reversible work(in kJ/kg):
I = Wrev-W #Irreversibility(in kJ/kg):
#Results:
print "Inlet stream availability: ",round(A1,2),"kJ/kg"
print "Exit stream availability: ",round(A2,2),"kJ/kg"
print "Irreversibility: ",round(I,1),"kJ/kg"
```