In [1]:

```
# Determine Head loss
from math import *
# Given
S = 1.26 # specific gravity
mu = 0.826 # kinematic viscosity in Ns/m**2
# for water
rho = 998 # density of water in kg/m**3
mu1 = 1.005*10**-3 # viscosity in Ns/m**2
# for glycerine
rho1 = S*rho # density of glycerine in kg/m**3
Q = 0.1 # discharge in m**3/s
d1 = 0.2 # diameter in m
A = pi*d1**2/4 # area in m**2
g = 9.81 # acceleration due to gravity in m/s**2
l =100 # length of the pipe
# Solution
V = Q/A
R = rho1*V*d1/mu
print "It is a laminar flow"
f = 64/R # friction factor
Hf = f*l*V**2/(2*g*d1) # head loss due to friction
print "(a) Head loss due to flow for glycerine =",round(Hf,1),"m "
R1 = rho*V*d1/mu1
print "The flow is turbulent"
e = 0.025
r = e/(d1*100)
f = 0.021
hf = f*l*V**2/(2*g*d1)
print "(a) Head loss due to flow for water =",round(hf,2),"m "
```

In [2]:

```
# Discharge of water
from math import *
# Given
# for water
nu = 1.007*10**-6 # viscosity in m**2/s
e = 0.025 # for cast iron in cm
L = 100 # length of the pipe in m
D = 0.2 # diameter in m
hf = 5.43 # head loss due to friction
r = e/(D*100)
g = 9.81 # acceleration due to gravity in m/s**2
# Solution
A = sqrt(2*g*D*hf/L)
B = D/nu
f = 0.021 # from moodys diagram
V = A/sqrt(f)
print V
R = B*f
A = pi*D**2/4
Q = A*V
print "Discharge =",round(Q,2),"m**3/s"
```

In [3]:

```
# Size of the case iron
from math import *
# Given
Q =0.1 # discharge in m**3/s
hf = 5.43 # friction loss head in m
L = 100 # length of pipe
nu = 1.00*10**-6 # viscosity in m**2/s
e = 0.025 # for cast iron in cm
g = 9.81 # acceleration due to gravity in m/s**2
# Solution
A = 8*L*Q**2/(hf*g*pi**2)
B = 4*Q/(pi*nu)
# for D = 0.172 ; f=0.01
D = 0.172
r = e/D
Re = B/D
f = 0.022 # for Re and r
# for D1=0.199 ; f=0.021
D1 = 0.199
r1 = e/D1
R = B/D1
f = 0.021 # for R and r
print "Hence the convergence is attained, D=",round(D1,1),"m"
```

In [4]:

```
# Head loss
from math import *
# Given
L = 500 # length of the pipe in ft
D= 9*2.54/100 # diameter in cm
C = 100 # constant
S = 0.004
# Solution
Hf = S*L
print "Head loss =",round(Hf,0),"ft"
```

In [6]:

```
# Head loss of water
from math import *
# Given
Q = 0.1 # water flow rate in m**3/s
d = 30 # diameter in m
l = 500 # length in m
e = 0.025 # for cast iron
g = 9.81 # acceleration due to gravity in m/s**2
# Solution
r = log(d/e,10)
K = (pi/4)*sqrt(2*g)*(2*r+1.14)*(0.3)**(2.5)
S = (Q/K)**2
hf = S*l
print "Head loss of water =",round(hf,1),"m"
```

In [8]:

```
# Head loss by conveyance method
from math import *
# Given
Q = 0.1 # water flow rate in m**3/s
d = 20 # diameter in cm
l = 500 # length in m
e = 0.025 # for cast iron
g = 9.81 # acceleration due to gravity in m/s**2
S = 5.43
# Solution
r = log(d/e,10)
K = (pi/4)*sqrt(2*g)*(2*r+1.14)*(0.2)**2.5
Q=K*sqrt(S/100)
print "Head loss of water =",round(Q,2),"m**3/s"
```

In [10]:

```
# Solve using the conveyence method
from math import *
# given
eps = 0.025*10**-2 # for cast iron epsilon = 0.0025 cm
# we get the value of K = 0.432 m**2/s
# we need to do trial and error to find the value of D
# we use the value of D = 0.2 m
D = 0.2 # value in m
g = 9.81
# Solution
K = (pi/4)*sqrt(2*g)*(2*log10(D/(eps))+1.14)*D**(2.5)
print "K = ",round(K,3)," from trial and error"
```

In [11]:

```
# Determine head loss
from math import *
# Given
d = 0.1 # diameter of the pipe
Q= 0.075 # discharge in m**3/s
L = 30 # length in m
A = pi*d**2/4
g = 9.81 # acceleration due to gravity in m/s**2
# for water
nu = 1.007*10**-6 # viscosity in m**2/s
e = 0.025
r = e/(10*d)
# Solution
V = Q/A
Re = V*d/nu
f = 0.025 # firction factor from moodys diagram
hf = f*L*V**2/(2*g*d)
K= 0.5 # contraction constant
hc = K*V**2/(2*g)
K1 =10 # loss of the globe valve
hg = K1*V**2/(2*g)
Th = hf+hc+hg
print "Total head loss =",round(Th,1),"m"
```

In [12]:

```
# discharge through the pipe
from math import *
# Given
# for water
nu = 1.007*10**-6 # viscosity in m**2/s
d1 = 0.3 # diameter of pipe 1 in m
d2 = 0.15 # diameter of pipe 2 in m
d3 = 0.08 # diameter of pipe 3 in m
g = 9.81 # acclelration due to gravity in m/s**2
e = 0.025 # for cast iron
f1 = 0.019 # foe e/d1
f2 = 0.022 # foe e/d2
# Solution
V3 = sqrt(2*g*100/((8.4*(f1)+268.85*(f2)+4.85)))
V1 = (d3/d1)**2*V3
V2 = (d3/d2)**2*V3
# reynolds number for pipe BC
R1 = V1*d1/nu
R2 = V2*d2/nu
Q = V3*pi*d3**2/4
print "Discharge through the pipe =",round(Q,3),"m**3/s"
```

In [13]:

```
# Replace the flow system
from math import *
# Given
D = 0.2 # diameter of pipe 1
D1 = 0.15 # diameter of pipe 2
Q = 0.1 # discharge in m**3/s
nu = 1.007*10**-6 # viscosity in m**2/s
e = 0.025 # e for cast iron
r = e/(100*D)
# Solution
V = Q/(pi*(0.2)**2/4)
R = V*D/nu
f = 0.021 # from moodys law
r2 = e/D1
V1 = Q/(pi*D1**2/4)
R1 = V*D1/nu
f2 = 0.023 # from moodys law
L2 = 28562*D1**5/f2
print "Replacement of the flow system =",round(L2,2),"m"
```

In [14]:

```
# Discharge through each branch
from math import *
# Given
e = 0.025 # in cm
nu = 1.007*10**-6 # viscosity in m**2/s
Q1 = 0.5 # discharge in m**3/s
D1 = 50
L1 = 500 # length in m
g = 9.81
# Pipe 1
r1 = e/D # r1 for pipe 1
V1 = Q1/(pi*(0.5)**2/4)
R = V*(0.5)/nu
f1 = 0.018 # for the reynolds no
hf1 = f*L1*V1**2/(2*g*D1)
# pipe 2
hf2 = hf1
L2 =200 # length in m
D2 = 0.3 # diameter in m
r2 = e/D2
f2 = 0.02
V2 = 0.419/sqrt(f2)
R2 = V2*D2/nu
Q2 = V2*(pi*D2**2/4)
#pipe 3
hf3=hf1
L3 = 300 # length of pipe 3 in m
D3 =0.15 # diameter of pipe 3 in m
r3 = e/D3
f = 0.022 # from moody's law
V3 = 0.242/sqrt(f2)
R3 = V3*D3/nu
Q3 = V3*(pi*D3**2/4)
Td = Q1+Q2+Q3
q1 = Q1*(2.0/Td)
q2 = Q2*(2.0/Td)
q3 = Q3*(2.0/Td)
print "Discharge through branch 1 =",round(q1,2),"m**3/s"
print "Discharge through branch 2 =",round(q2,3),"m**3/s"
print "Discharge through branch 3 =",round(q3,3),"m**3/s"
# Actual head loss
d = 0.5
v1 = q1/(pi*(d)**2/4)
R4 = v1*d/nu
r4 = 0.0005 # ratio of e/D
f = 0.018
Hf1 = f*L1*v1**2/(2*g*d)
print "It is found that hf1=hf2=hf3 =",round(Hf1,1),"The distribution od discharge is correct"
```

In [15]:

```
# Find minimum depth below the ridge
from math import *
# Given
e = 0.00015 # from moody's chart
D = 2 # depth in ft
r = e/D
z1 = 100 # elevation in ft
mu = 1.084*10**-5 # viscosity in Ns/ft**2
p1 = 34 # pressure head in ft
p2 = 10 # pressure head in ft
g = 32.2 # acclelration due to gravity in ft/s**2
L = 1000 # length in ft
# Solution
f = 0.011 # assume
V = sqrt(100/(10000/(2*2*g)))/sqrt(f)
R = V*D/mu
V1 = 10.15
f1 = 0.0125
Q = V1*pi*D**2/4
x = p1-p2-(V1**2/(2*g))-(f1*L*V1**2/(2*g*D))
Dp = 30 - x
print "Minimum depth =",round(Dp,2),"ft"
```

In [ ]:

```
```