In [1]:

```
# -*- coding: utf8 -*-
from __future__ import division
#Example: 6.01
''' Air is flowing in a 0.2-m-diameter pipe at a uniform velocity of 0.1 m/s. The temperature
is 25◦C and the pressure is 150 kPa. Determine the mass flow rate. '''
from math import pi
#Variable Declaration:
R = 0.287 #in kJ/kg-K
T = 25 #temperature in celsius
P = 150 #pressure in kPa
v = R*(T+273.2)/P#specific volume in m**3/kg
D = 0.2 #diameter of pipe in metre
V = 0.1 #velocity of air in m/s
#Calculations:
A = pi*D**2/4 #cross sectional area in m**2
m = V*A/v #mass flow rate in kg/s
#Results:
print "The mass flow rate is:",round(m,4),"kg/s."
```

In [2]:

```
# -*- coding: utf8 -*-
from __future__ import division
#Example: 6.02
''' Assume we are standing next to the local city’s main water line. The liquid water inside
flows at a pressure of 600 kPa (6 atm) with a temperature of about 10◦C. We want to add
a smaller amount, 1 kg, of liquid to the line through a side pipe and valve mounted on the
main line. How much work will be involved in this process? '''
#Variable Declaration:
P = 600 #pressure in kPa
m = 1 #in kg
v = 0.001 #specific volume in m**3/kg
#Calculations:
W = P*m*v #necessary work in kJ for adding the fluid
#Results:
print "The work involved in this process is:",round(W,2),"kJ"
```

In [3]:

```
# -*- coding: utf8 -*-
from __future__ import division
#Example: 6.03
''' Consider a water-cooled condenser in a large refrigeration system in which R-134a is the
refrigerant fluid. The refrigerant enters the condenser at 1.0 MPa and 60◦C, at the rate of
0.2 kg/s, and exits as a liquid at 0.95 MPa and 35◦C. Cooling water enters the condenser
at 10◦C and exits at 20◦C. Determine the rate at which cooling water flows through the
condenser.
Control volume: Condenser.
Sketch: Fig. 6.6
Inlet states: R-134a—fixed; water—fixed.
Exit states: R-134a—fixed; water—fixed.
Process: Steady-state.
Model: R-134a tables; steam tables. '''
#Variable Declaration:
hir = 441.89 #in kJ/kg for refrigerant using steam table
her = 249.10 #in kJ/kg for refrigerant using steam table
hiw = 42 #in kJ/kg for water using steam table
hew = 83.95 #in kJ/kg for water using steam table
mr = 0.2 #the rate at which refrigerant enters the condenser in kg/s
#Calculations:
mw = mr*(hir-her)/(hew-hiw) #rate of flow of water in kg/s
#Results:
print "The rate at which cooling water flows thorugh the condenser is:",round( mw,3),"kg/s"
```

In [4]:

```
# -*- coding: utf8 -*-
from __future__ import division
#Example: 6.04
''' Steam at 0.6 MPa and 200◦C enters an insulated nozzle with a velocity of 50 m/s. It leaves
at a pressure of 0.15 MPa and a velocity of 600 m/s. Determine the final temperature if
the steam is superheated in the final state and the quality if it is saturated.
Control volume: Nozzle.
Inlet state: Fixed (see Fig. 6.7).
Exit state: Pe known.
Process: Steady-state.
Model: Steam tables. '''
#Variable Declaration:
hi = 2850.1 #initial specific heat enthalpy for steam in kJ/kg
Vi = 50 #initial velocity of steam in m/s
Ve = 600 #final velocity of steam in m/s
hf = 467.1 #at final state in kJ/kg
hfg = 2226.5 #at final state in kJ/kg
#Calculations:
he = hi+Vi**2/(2*1000)-Ve**2/(2*1000) #final specific heat enthalpy for steam in kJ/kg
xe = (he-hf)/hfg #quality of steam in final state
#Results:
print "The quality is: ",round(xe,2)
```

In [5]:

```
# -*- coding: utf8 -*-
from __future__ import division
#Example: 6.05
''' Consider the throttling process across the expansion valve or through the capillary tube
in a vapor-compression refrigeration cycle. In this process the pressure of the refrigerant
drops from the high pressure in the condenser to the low pressure in the evaporator,
and during this process some of the liquid flashes into vapor. If we consider this
process to be adiabatic, the quality of the refrigerant entering the evaporator can be
calculated.
Consider the following process, in which ammonia is the refrigerant. The ammonia
enters the expansion valve at a pressure of 1.50MPa and a temperature of 35◦C. Its pressure
on leaving the expansion valve is 291 kPa. Calculate the quality of the ammonia leaving
the expansion valve.
Control volume: Expansion valve or capillary tube.
Inlet state: Pi, Ti known; state fixed.
Exit state: Pe known.
Process: Steady-state.
Model: Ammonia tables. '''
#Variable Declaration:
hi = 346.8 #specific heat enthalpy for ammonia at initial state in kJ/kg
hf = 134.4 #at final state in kJ/kg
hfg = 1296.4 #at final state in kJ/kg
#Calculations:
he = hi #specific heat enthalpy for ammonia at final state will be equal that at initial state because it is a throttling process
xe = (he-hf)/hfg #quality at final state
#Results:
print "Quality of the ammonia leaving the expansion valve is:",round(xe*100,2),"%"
```

In [6]:

```
# -*- coding: utf8 -*-
from __future__ import division
#Example:
''' The mass rate of flow into a steam turbine is 1.5 kg/s, and the heat transfer from the
turbine is 8.5 kW. The following data are known for the steam entering and leaving the
turbine.
Inlet Conditions Exit Conditions
Pressure 2.0 MPa 0.1 MPa
Temperature 350◦C
Quality 100%
Velocity 50 m/s 100 m/s
Elevation above 6 m 3 m
reference plane
g = 9.8066 m/s2
Determine the power output of the turbine.
Control volume: Turbine (Fig. 6.9).
Inlet state: Fixed (above).
Exit state: Fixed (above).
Process: Steady-state.
Model: Steam tables. '''
#Variable Declaration:
hi = 3137 #initial specific heat of enthalpy in kJ/kg
he = 2675.5 #final specific heat of enthalpy in kJ/kg
Vi = 50 #initial velocity of steam in m/s
Ve = 100 #final velocity of steam in m/s
Zi = 6 #height of inlet conditions in metres
Ze = 3 #height of exit conditions in metres
m = 1.5 #mass flow rate of steam in kg/s
g = 9.8066 #acc. due to gravity in m/s**2
Qcv = -8.5 #heat transfer rate from turbine in kW
#Calculations:
Wcv = Qcv+m*(hi+Vi**2/(2*1000)+g*Zi/1000)-m*(he+Ve**2/(2*1000)+g*Ze/1000) #power output of turbine in kW
#Results:
print "The power output of the turbine is:",round(Wcv,1),"kW"
```

In [7]:

```
# -*- coding: utf8 -*-
from __future__ import division
#Example: 6.07
''' The compressor in a plant (see Fig. 6.10) receives carbon dioxide at 100 kPa, 280 K,
with a low velocity. At the compressor discharge, the carbon dioxide exits at 1100 kPa,
500 K, with velocity of 25 m/s and then flows into a constant-pressure aftercooler (heat
exchanger) where it is cooled down to 350 K. The power input to the compressor is
50 kW. Determine the heat transfer rate in the aftercooler. '''
#Variable Declaration:
V1 = 0 #we assume initial velocity to be zero because its given that it enters with a low velocity
V2 = 25 #final velocity with which carbon dioxide exits in m/s
h2 = 401.52 #final specific enthalpy of heat when carbon dioxide exits in kJ/kg
h1 = 198 #initial specific enthalpy of heat in kJ/kg
Wc = -50 #power input to the compressor in kW
h3 = 257.9 #final specific enthalpy of heat when carbon dioxide flows into a constant pressure aftercooler
#Calculations:
w = h1-h2-V2**2/(2*1000)#in kJ/kg
m = Wc/w #mass flow rate of carbon dioxide in kg/s
Qcool = -m*(h3-h2) #heat transfer rate in the aftercooler in kW
#Results:
print "Heat transfer rate in the aftercooler is:",round(Qcool,1),"kW"
```

In [8]:

```
# -*- coding: utf8 -*-
from __future__ import division
#Example: 6.08
''' A small liquid water pump is located 15 m down in a well (see Fig. 6.11), taking water
in at 10◦C, 90 kPa at a rate of 1.5 kg/s. The exit line is a pipe of diameter 0.04 m that
goes up to a receiver tank maintaining a gauge pressure of 400 kPa. Assume the process
is adiabatic with the same inlet and exit velocities and the water stays at 10◦C. Find the
required pump work. '''
#Variable Declaration:
m = 1.5 #mass flow rate of water in kg/s
g = 9.807 #acceleration due to gravity in m/s**2
Zin = -15 #depth of water pump in well in metres
Zex = 0 #in metres
v = 0.001001 #specific volume in m**3/kg
Pin = 90 #in kPa
#Calculations:
Pex = 400+101.3 #exit pressure in kPa
W = m*(g*(Zin-Zex)*0.001-(Pex-Pin)*v) #power input in kW
#Results:
print "The pump requires power input of",-round(W,2)*1000,"W"
```

In [9]:

```
# -*- coding: utf8 -*-
from __future__ import division
#Example: 6.09
''' Consider the simple steam power plant, as shown in Fig. 6.12. The following data are for
such a power plant.
Location Pressure Temperature or Quality
Leaving boiler 2.0 MPa 300◦C
Entering turbine 1.9 MPa 290◦C
Leaving turbine,entering condenser 15 kPa 90%
Leaving condenser,entering pump 14 kPa 45◦C
Pump work = 4 kJ/kg
Determine the following quantities per kilogram flowing through the unit:
a. Heat transfer in the line between the boiler and turbine.
b. Turbine work.
c. Heat transfer in the condenser.
d. Heat transfer in the boiler. '''
#Variable Declaration:
h1 = 3023.5 #specific heat of enthalpy of steam leaving boiler in kJ/kg
h2 = 3002.5 #specific heat of enthalpy of steam entering turbine in kJ/kg
x = 0.9 #quality of steam entering condenser
hf = 226 #in kJ/kg
hfg = 2373.1 #in kJ/kg
h4 = 188.5 #specific heat of enthalpy of steam entering pump in kJ/kg
w45 = -4 #pump work in kJ/kg
#Calculations:
h3 = hf+x*hfg #specific heat of enthalpy of steam entering condenser in kJ/kg
q12 = h2-h1 #heat transfer in line between boiler and turbine in kJ/kg
w23 = h2-h3 #turbine work in kJ/kg
q34 = h4-h3 #heat transfer in condenser
h5 = h4-w45 #in kJ/kg
q51 = h1-h5 #heat transfer in boiler in kJ/kg
#Results:
print "Heat transfer in line between boiler and turbine is:",round(q12,2),"kJ/kg"
print "Turbine work is:",round(w23,1),"kJ/kg"
print "Heat transfer in condenser is:",round(q34,1),"kJ/kg"
print "Heat transfer in boiler is:",round(q51,2),"kJ/kg. "
```

In [10]:

```
# -*- coding: utf8 -*-
from __future__ import division
#Example: 6.10
''' The refrigerator shown in Fig. 6.13 uses R-134a as the working fluid. The mass flow rate
through each component is 0.1 kg/s, and the power input to the compressor is 5.0 kW. The
following state data are known, using the state notation of Fig. 6.13:
P1 = 100 kPa, T1 = −20◦C
P2 = 800 kPa, T2 = 50◦C
T3 = 30◦C, x3 = 0.0
T4 = −25◦C
Determine the following:
a. The quality at the evaporator inlet.
b. The rate of heat transfer to the evaporator.
c. The rate of heat transfer from the compressor. '''
#Variable Declaration:
hf4 = 167.4 #in kJ/kg
hfg4 = 215.6 #in kJ/kg
h3 = 241.8 #specific heat of enthalpy of R-134a entering expansion valve
h4 = h3 #specific heat of enthalpy of R-134a leaving expansion valve
h1 = 387.2 #in kJ/kg
h2 = 435.1 #in kJ/kg
m = 0.1 #mass flow rate in kg/s
Wcomp = -5 #power input to compressor in kW
#Calculations:
x4 = (h3-hf4)/hfg4 #quality of R-134a at evaporator inlet
Qevap = m*(h1-h4) #rate of heat transfer to the evaporator
Qcomp = m*(h2-h1)+Wcomp #rate of heat transfer from compressor
#Results:
print "The quality at the evaporator inlet is:",round(x4,3)
print "The rate of heat transfer to the evaporator is:",round(Qevap,2),"kW. "
print "Rate of heat transfer from the compressor is:",round(Qcomp,2),"kW. "
```

In [11]:

```
# -*- coding: utf8 -*-
from __future__ import division
#Example: 6.12
''' Let the tank of the previous example have a volume of 0.4m3 and initially contain saturated
vapor at 350 kPa. The valve is then opened, and steam from the line at 1.4 MPa and 300◦C
flows into the tank until the pressure is 1.4 MPa.
Calculate the mass of steam that flows into the tank. '''
#Variable Declaration:
V1 = 0.4 #initial volume fo tank in m**3
v1 = 0.5243 #initial specific volume in m**3/kg
h1 = 3040.4 #initial specific enthalpy in kJ/kg
u1 = 2548.9 #initial specific internal energy in kJ/kg
V2 = 0.4 #final volume in m**3
T2 = 342 #final temperature in Celsius by interpolation
v2 = 0.1974 #final specific volume in m**3/kg
#Calculations:
m1 = V1/v1 #initial mass of steam in tank in kg
m2 = V2/v2 #final mass of the steam in the tank in kg
m = m2-m1 #mass of steam that flowsinto the tank
#Results:
print "Mass of the steam that flows into the tank is:",round(m,3),"kg"
```

In [12]:

```
# -*- coding: utf8 -*-
from __future__ import division
#Example: 6.13
''' A tank of 2 m3 volume contains saturated ammonia at a temperature of 40◦C. Initially the
tank contains 50% liquid and 50% vapor by volume. Vapor is withdrawn from the top of
the tank until the temperature is 10◦C. Assuming that only vapor (i.e., no liquid) leaves
and that the process is adiabatic, calculate the mass of ammonia that is withdrawn. '''
#Variable Declaration:
vf1 = 0.001725 #in m**3/kg
vf2 = 0.0016 #in m**3/kg
uf1 = 368.7 #in kJ/kg
uf2 = 226 #in kJ/kg
vg1 = 0.08313 #in m**3/kg
vfg2 = 0.20381
ug1 = 1341 #in kJ/kg
ufg2 = 1099.7 #in kJ/kg
Vf = 1 #initial volume of liquid in m**3
Vg = 1 #initial volume of vapor in m**3
he = 1461.1 #in kJ/kg
V = 2 #volume of tank in m**3
#Calculations:
mf1 = Vf/vf1 #initial mass of liquid in kg
mg1 = Vg/vg1 #initial mass of vapor in kg
m1 = mf1+mg1 #initial mass of liquid in kg
x2 = ((2*1461.1)-(2*226)-(0.00160*634706))/((634706*0.20381)+(2*1099.7)) #quality of ammonia
v2 = 0.00160+(0.20381*x2) #final specific volume in m**3/kg
m2 = V/v2 #final mass of ammonia in kg
m = m1-m2 #mass of ammonia withdrawn
#Results:
print "Mass of ammonia withdrawn is:",round(m,1),"kg"
```