In [1]:

```
# -*- coding: utf8 -*-
from __future__ import division
#Example: 9.1
'''Steam enters a steam turbine at a pressure of 1 MPa, a temperature of 300
◦C, and avelocity of 50 m/s. The steam leaves the turbine at a pressure of 150 kPa and a velocity of
200 m/s. Determine the work per kilogram of steam ﬂowing through the turbine, assuming
the process to be reversible and adiabatic.
Control volume: Turbine.
Sketch: Fig. 9.2.
Inlet state: Fixed (Fig. 9.2).
Exit state: P e , V e known.
Process: Steady state, reversible and adiabatic.
Model: Steam tables.'''
#Variable Declaration:
hi = 3051.2 #initial specific heat of enthalpy of steam in kJ/kg
si = 7.1228 #initial specific entropy of steam in kJ/kg-K
Pe = 0.15 #final pressure in MPa
se = si #specific entropy in final state in kJ/kg-K
sf = 1.4335 #in kJ/kg-K
sfg = 5.7897 #in kJ/kg-K
vi = 50 #velocity with which steam enters turbine in m/s
ve = 200 #velocity with which steam leaves the turbine in m/s
hf = 467.1 #in kJ/kg
hfg = 2226.5 #in kJ/kg
#Calculations:
xe = (se-sf)/sfg #quality of steam in final state
he = hf+xe*hfg #final specific heat of enthalpy of steam in kJ/kg
w = hi+vi**2/(2*1000)-he-ve**2/(2*1000) #work of steam for isentropic process in kJ/kg
#Results
print "Work per kilogram of steam for this isentropic process: ",round(w,1),"KJ/Kg-K"
```

In [2]:

```
# -*- coding: utf8 -*-
from __future__ import division
#Example: 9.2
''' Consider the reversible adiabatic ﬂow of steam through a nozzle. Steam enters the nozzle
at 1 MPa and 300◦C, with a velocity of 30 m/s. The pressure of the steam at the nozzle
exit is 0.3 MPa. Determine the exit velocity of the steam from the nozzle, assuming a
reversible, adiabatic, steady-state process.'''
#Variable Declaration:
hi = 3051.2 #initial specific heat of enthalpy in kJ/kg
si = 7.1228 #initial specific entropy in kJ/kg-K
Pe = 0.3 #final pressure in MPa
he = 2780.2 #final specific heat of enthalpy in kJ/kg-K
Te = 159.1 #final temperature in celsius
vi = 30 #velocity with which steam enters the nozzle in m/s
#Calculations:
se = si #final specific entropy
ve = ((2*(hi-he)+(vi**2/1000))*1000)**0.5 #final velocity of steam with which it exits in m/s
#Results
print "Exit velocity of the steam from the nozzle:",round(ve),'m/s'
```

In [3]:

```
# -*- coding: utf8 -*-
from __future__ import division
#Example: 9.4
''' An air compressor in a gas station (see Fig. 9.4) takes in a ﬂow of ambient air at 100 kPa,
290 K and compresses it to 1000 kPa in a reversible adiabatic process. We want to know
the speciﬁc work required and the exit air temperature.'''
#Variable Declaration:
Cp = 1.004 #specific heat of air at constant pressure in kJ/kg-K
Ti = 290 #initial temperature in kelvins
Pi = 100 #initial pressure in kPa
Pe = 1000 #final pressure in kPa
k = 1.4
#Calculations:
Te = Ti*(Pe/Pi)**((k-1)/k) #final temperature in kelvins
we = Cp*(Ti-Te) #required specific work in kJ/kg
#Results:
print "Specific work required: ",round(we),'KJ/Kg'
```

In [4]:

```
# -*- coding: utf8 -*-
from __future__ import division
#Example: 9.5
''' A de-superheater works by injecting liquid water into a ﬂow of superheated steam. With
2 kg/s at 300 kPa, 200◦C, steam ﬂowing in, what mass ﬂow rate of liquid water at 20◦C
should be added to generate saturated vapor at 300 kPa? We also want to know the rate of
entropy generation in the process.'''
#Variable Declaration:
h1 = 2865.54 #specific heat of enthalpy at state 1 in kJ/kg
h2 = 83.94 #specific heat of enthalpy at state 2 in kJ/kg
h3 = 2725.3 #specific heat of enthalpy at state 3 in kJ?kg
s1 = 7.3115 #specific entropy at state 1 in kJ/kg-K
s2 = 0.2966 #specific entropy at state 2 in kJ/kg-K
s3 = 6.9918 #specific entropy at state 3in kJ/kg-K
m1 = 2 #mass flow rate at state 1 in kg/s
#Calculations:
m2 = m1*(h1-h3)/(h3-h2) #mass flow rate at state 2 in kg/s
m3 = m1+m2 #mass flow rate at state 3 in kg/s
Sgen = m3*s3-m1*s1-m2*s2#entropy generation in the process
#Results:
print "Entropy generated in this process: ",round(Sgen,3),'KW/K'
```

In [5]:

```
# -*- coding: utf8 -*-
from __future__ import division
from math import log
#Example: 9.6
'''Assume an air tank has 40 L of 100 kPa air at ambient temperature 17◦C. The adiabatic
and reversible compressor is started so that it charges the tank up to a pressure of 1000
kPa and then it shuts off. We want to know how hot the air in the tank gets and the total
amount of work required to ﬁll the tank.'''
#Variable Declaration:
T1 = 17+273 #initial temperature of tank in Kelvins
sT1 = 6.83521 #specific entropy in kJ/kg-K
R = 0.287 #gas constant in kJ/kg-K
P1 = 100 #initial pressure in kPa
P2 = 1000 #final pressure in kPa
T2 = 555.7 #from interplotation
V1 = 0.04 #volume of tank in m**3
V2 = V1 #final volume is equal to initial volume
u1 = 207.19 #initial specific heat of enthalpy in kJ/kg
u2 = 401.49 #final specific heat of enthalpy in kJ/kg
hin = 290.43 #in kJ/kg
#Calculations:
sT2 = sT1+R*log(P2/P1) #specific entropy at temperature T2 in kJ/kg-K
m1 = P1*V1/(R*T1) #initial mass of air in tank in kg
m2 = P2*V2/(R*T2) #final mass of air in tank in kg
Min = m2-m1 #in kg
W12 = Min*hin+m1*u1-m2*u2 #work required to fill the tank in kJ
#Results:
print "Total amount of work required to fill the tank: ",round(W12,1),'KJ'
```

In [6]:

```
# -*- coding: utf8 -*-
from __future__ import division
#Example: 9.7
''' Calculate the work per kilogram to pump water isentropically from 100 kPa, 30◦C to 5 MPa.'''
#Variable Declaration:
P1 = 100 #initial pressure in kPa
P2 = 5000 #final pressure in kPa
v = 0.001004 #specific volume in m**3/kg
#Calculations:
w = v*(P2-P1) #work required to pump water isentropically
#Results:
print "Work required to pump water isentropically: ",round(w,2),'KJ/Kg'
```

In [7]:

```
# -*- coding: utf8 -*-
from __future__ import division
#Example: 9.8
'''Consider a nozzle used to spray liquid water. If the line pressure is 300 kPa and the water
temperature is 20◦C, how high a velocity can an ideal nozzle generate in the exit ﬂow?'''
#Variable Declaration:
vf = 0.001002 #in m**3/kg
Pi = 300 #Line pressure in kPa
Po = 100 #in kPa
#Calculations:
v = vf
Ve = (2*v*(Pi-Po)*1000)**0.5 #velocity in the exit flow
#Results:
print "Ideal nozzle can generate upto Ve = ",round(Ve),'m/s in the exit flow.'
```

In [8]:

```
# -*- coding: utf8 -*-
from __future__ import division
#Example: 9.9
'''Saturated vapor R-410a enters the uninsulated compressor of a home central air-
conditioning system at 5◦C. The ﬂow rate of refrigerant through the compressor is 0.08
kg/s, and the electrical power input is 3 kW. The exit state is 65◦C, 3000 kPa. Any heat transfer from the compressor is with the ambient at 30◦C. Determine the rate of entropy
generation for this process.
Control volume: Compressor out to ambient T 0 .
Inlet state: T i , x i known; state ﬁxed.
Exit state: P e , T e known; state ﬁxed.
Process: Steady-state, single ﬂuid ﬂow.
Model: R-410a tables, B.4.'''
#Variable Declaration:
hi = 280.6 #in kJ/kg
he = 307.8 #in kJ/kg
si = 1.0272 #in kJ/kg
se = 1.0140 #in kJ/kg
m = 0.08 #flow rate of refrigerant in kg/s
P = 3 #electrical power input in kW
To = 30 #in °C
#Calculations:
Qcv = m*(he-hi)-P #in kW
Sgen = m*(se-si)-Qcv/(To+273.2) #Rate of entropy generation
#Results:
print "Rate of entropy generation for this process: ",round(Sgen,5),'KW/K'
```

In [9]:

```
# -*- coding: utf8 -*-
from __future__ import division
#Example: 9.10
''' A steam turbine receives steam at a pressure of 1 MPa and a temperature of 300
◦C. The steam leaves the turbine at a pressure of 15 kPa. The work output of the turbine is measured
and is found to be 600 kJ/kg of steam ﬂowing through the turbine. Determine the efﬁciency
of the turbine.
Control volume: Turbine.
Inlet state: P i , T i known; state ﬁxed.
Exit state: P e known.
Process: Steady state.
Model: Steam tables.'''
#Variable Declaration:
hi = 3051.2 #initial specific heat of enthalpy in kJ/kg
si = 7.1228 #initial specific entropy in kJ/kg-K
sf = 0.7548 #in kJ/kg-K
sfg = 7.2536 #in kJ/kg-K
hf = 225.9 #in kJ/kg
hfg = 2373.1 #in kJ/kg
wa = 600 #actual work output of turbine in kJ/kg
#Calculations:
ses = si #final specific entropy is same as the initial
xes = (si-sf)/sfg #quality of steam when it leaves the turbine
hes = hf+xes*hfg #final specific heat of enthalpy in kJ/kg
ws = hi-hes #work output of turbine calculated ideally in kJ/kg
nturbine = wa/ws #efiiciency of turbine
#Results:
print "Efficiency of the turbine: ",round(nturbine*100,1),'%'
```

In [10]:

```
# -*- coding: utf8 -*-
from __future__ import division
from math import e
#Example: 9.11
''' Air enters a gas turbine at 1600 K and exits at 100 kPa, 830 K.The turbine efﬁciency is
estimated to be 85%. What is the turbine inlet pressure?
Control volume: Turbine.
Inlet state: T i known.
Exit state: P e , T e known; state ﬁxed.
Process: Steady state.
Model: Air tables, Table A.7.'''
#Variable Declaration:
hi = 1757.3 #initial specific heat of enthalpy of air in kJ/kg
si = 8.6905 #initial specifc entropy of airin kJ/kg-K
he = 855.3 #final specific heat of enthalpy of air in kJ/kg
n = 0.85 #efficiency of turbine
Tes = 683.7 #final temperature in kelvins from air tables
ses = 7.7148 #in kJ/kg-K
R = 0.287 #gas constant in kJ/kg-K
#Calculations:
w = hi-he #actual work done by turbine in kJ/kg
ws = w/n #ideal work done by turbine in kJ/kg
hes = hi-ws #from first law of isentropic process
Pi = 100/e**((si-ses)/-R) #turbine inlet pressure in kPa
#Results:
print "Turbine inlet pressure: ",round(Pi),'Kpa'
```

In [11]:

```
# -*- coding: utf8 -*-
from __future__ import division
#Example: 9.12
'''Air enters an automotive supercharger at 100 kPa, 300 K and is compressed to 150 kPa.
The efﬁciency is 70%. What is the required work input per kilogram of air? What is the
exit temperature?
Control volume: Supercharger (compressor).
Inlet state: P i , T i known; state ﬁxed.
Exit state: P e known.
Process: Steady state.
Model: Ideal gas, 300 K speciﬁc heat, Table A.5.'''
#Variable Declaration:
Pe = 150 #final pressure of air in kPa
Pi = 100 #initial presure of air in kPa
k = 1.4
Ti = 300 #initial temperature of air in kelvis
n = 0.7 #efficiency of automotive supercharger
#Calculations:
Tes = Ti*(Pe/Pi)**((k-1)/k) #from second law
ws = 1.004*(Ti-Tes) #from first law of isentropic process
w = ws/n #real work input in kJ/kg
Te = Ti-w/1.004 #temperature at supercharger exit in K
#Results:
print "Required work input: ",round(w),'KJ/Kg'
print "Exit temperature: ",round(Te,1),'K'
```