1.5 The pipenet module#

With the entire script as a module, we just load the module when we need it. To do this we simply took the contents of the def pipenet() cell and copy and paste into a text file, then name the textfile something memorableful - in my case pipenet.py

To use the module either load it into your python kernel or locate it in the directory where you are working and import the module as illustrated below, because our desired entry point shares the same name as the file, i used a weird syntax. The more convential method is also shown.

# Now import the module (observe the semi-weird syntax)
from pipenet import pipenet
# Now run the simulation 
pipenet('PN-E2.txt') 
####ECHO INPUT################
Input File:  PN-E2.txt
number of nodes :  4
number of pipes :  6
viscosity       :  1.1e-05
-----------------------------
node id: 0 , elevation : 0.0  head : 0.0
node id: 1 , elevation : 0.0  head : 0.0
node id: 2 , elevation : 0.0  head : 0.0
node id: 3 , elevation : 0.0  head : 0.0
-----------------------------
pipe id: 0 , diameter :  10.0 , distance :  10.0 , roughness :  1e-05 , flow  :  1.0
pipe id: 1 , diameter :  0.67 , distance :  800.0 , roughness :  1e-05 , flow  :  1.0
pipe id: 2 , diameter :  0.67 , distance :  700.0 , roughness :  1e-05 , flow  :  1.0
pipe id: 3 , diameter :  0.67 , distance :  700.0 , roughness :  1e-05 , flow  :  1.0
pipe id: 4 , diameter :  0.67 , distance :  800.0 , roughness :  1e-05 , flow  :  1.0
pipe id: 5 , diameter :  0.5 , distance :  600.0 , roughness :  1e-05 , flow  :  1.0
-----------------------------
node-arc incidence matrix
[1.0, -1.0, 0.0, -1.0, 0.0, 0.0]
[0.0, 1.0, -1.0, 0.0, 0.0, 1.0]
[0.0, 0.0, 0.0, 1.0, -1.0, -1.0]
[0.0, 0.0, 1.0, 0.0, 1.0, 0.0]
-----------------------------
###EXIT TYPE###
Update not changing --exit and report current update
iteration 39
#####SIMULATION RESULTS#####
Results at iteration = : 39
number of nodes :  4
number of pipes :  6
viscosity       :  1.1e-05
-----------------------------
node id: 1 , elevation (feet) : 0.0  head (feet) : 100.0  pressure (psi) : 44.697
node id: 2 , elevation (feet) : 0.0  head (feet) : 90.292  pressure (psi) : 40.358
node id: 3 , elevation (feet) : 0.0  head (feet) : 91.673  pressure (psi) : 40.975
node id: 4 , elevation (feet) : 0.0  head (feet) : 89.815  pressure (psi) : 40.145
-----------------------------
pipe id: 1 , diameter (feet) :  10.0 , distance (feet) :  10.0 , friction factor :  0.03 , flow (cfs) :  10.0
pipe id: 2 , diameter (feet) :  0.67 , distance (feet) :  800.0 , friction factor :  0.016 , flow (cfs) :  4.04
pipe id: 3 , diameter (feet) :  0.67 , distance (feet) :  700.0 , friction factor :  0.016 , flow (cfs) :  0.227
pipe id: 4 , diameter (feet) :  0.67 , distance (feet) :  700.0 , friction factor :  0.016 , flow (cfs) :  3.96
pipe id: 5 , diameter (feet) :  0.67 , distance (feet) :  800.0 , friction factor :  0.016 , flow (cfs) :  0.773
pipe id: 6 , diameter (feet) :  0.5 , distance (feet) :  600.0 , friction factor :  0.015 , flow (cfs) :  0.187
-----------------------------
# Now import the module (conventional syntax)
import pipenet
# Now run the simulation 
pipenet.pipenet('PN-E2.txt') 
####ECHO INPUT################
Input File:  PN-E2.txt
number of nodes :  4
number of pipes :  6
viscosity       :  1.1e-05
-----------------------------
node id: 0 , elevation : 0.0  head : 0.0
node id: 1 , elevation : 0.0  head : 0.0
node id: 2 , elevation : 0.0  head : 0.0
node id: 3 , elevation : 0.0  head : 0.0
-----------------------------
pipe id: 0 , diameter :  10.0 , distance :  10.0 , roughness :  1e-05 , flow  :  1.0
pipe id: 1 , diameter :  0.67 , distance :  800.0 , roughness :  1e-05 , flow  :  1.0
pipe id: 2 , diameter :  0.67 , distance :  700.0 , roughness :  1e-05 , flow  :  1.0
pipe id: 3 , diameter :  0.67 , distance :  700.0 , roughness :  1e-05 , flow  :  1.0
pipe id: 4 , diameter :  0.67 , distance :  800.0 , roughness :  1e-05 , flow  :  1.0
pipe id: 5 , diameter :  0.5 , distance :  600.0 , roughness :  1e-05 , flow  :  1.0
-----------------------------
node-arc incidence matrix
[1.0, -1.0, 0.0, -1.0, 0.0, 0.0]
[0.0, 1.0, -1.0, 0.0, 0.0, 1.0]
[0.0, 0.0, 0.0, 1.0, -1.0, -1.0]
[0.0, 0.0, 1.0, 0.0, 1.0, 0.0]
-----------------------------
###EXIT TYPE###
Update not changing --exit and report current update
iteration 39
#####SIMULATION RESULTS#####
Results at iteration = : 39
number of nodes :  4
number of pipes :  6
viscosity       :  1.1e-05
-----------------------------
node id: 1 , elevation (feet) : 0.0  head (feet) : 100.0  pressure (psi) : 44.697
node id: 2 , elevation (feet) : 0.0  head (feet) : 90.292  pressure (psi) : 40.358
node id: 3 , elevation (feet) : 0.0  head (feet) : 91.673  pressure (psi) : 40.975
node id: 4 , elevation (feet) : 0.0  head (feet) : 89.815  pressure (psi) : 40.145
-----------------------------
pipe id: 1 , diameter (feet) :  10.0 , distance (feet) :  10.0 , friction factor :  0.03 , flow (cfs) :  10.0
pipe id: 2 , diameter (feet) :  0.67 , distance (feet) :  800.0 , friction factor :  0.016 , flow (cfs) :  4.04
pipe id: 3 , diameter (feet) :  0.67 , distance (feet) :  700.0 , friction factor :  0.016 , flow (cfs) :  0.227
pipe id: 4 , diameter (feet) :  0.67 , distance (feet) :  700.0 , friction factor :  0.016 , flow (cfs) :  3.96
pipe id: 5 , diameter (feet) :  0.67 , distance (feet) :  800.0 , friction factor :  0.016 , flow (cfs) :  0.773
pipe id: 6 , diameter (feet) :  0.5 , distance (feet) :  600.0 , friction factor :  0.015 , flow (cfs) :  0.187
-----------------------------

Now that we have a compact (to us) tool we can explore different problems.

Example 2:#

For the given source and loads shown, how will the flow be distributed in the network, and what will be the pressures at the nodes, if the source pressure is \(60~psi\). The pipes are all horizontal, and the pipes are HDPE?

../../_images/example2-15.png

Fig. 8 Pipe network for Example 2#

Known#

  1. Node-arc matrix

  2. Pipe lengths

  3. Pipe diameters

  4. Material

  5. Node elevations (we will have to assume a value)

Unknown#

  1. Pressures at each node

  2. Discharge in each pipe

Governing Principles#

  1. Continunity at nodes

  2. Head loss in pipes (Darcy-Weisbach model)

  3. Energy unique at nodes

Analysis#

Use method of Hamam, Y.M., and Brameller, A. (1971).

Build Input File#

../../_images/IMG-6194.png

Fig. 9 Pipe network notations for Example 2 input file build#

  • 5 nodes (plus a 6-th supply node in this example it is node 0)

  • 7 pipes (the supply pipe (pink arrow) at node 1 is set as a short and large diameter pipe, pipe P7)

5
7
  • node elevations

0 0 0 0 0 0

Pipe diameters

2.0 0.83 1.0 1.0 0.75 0.83 10.0
  • Pipe lengths

1000 1410 1000 1000 1000 1000 10
  • Pipe roughness heights (based on material)

../../_images/HDPE-roughness.png

Fig. 10 Source for HDPE roughness approximation#

0.00001 0.00001 0.00001 0.00001 0.00001 0.00001 0.00001
  • Viscosity

0.000011
  • Initial Discharge Vector (just use ones)

1 1 1 1 1 1
  • The node-arc matrix

-1 -1  0  0  0  0  1
1 0 -1 0 1 0 0
0 0  1 0 0 -1 0
0 0  0 -1 0 1 0 
0 1 0 1 -1 0 0 
  • The right-hand side (demands and node 0 head)

0  0 10  5  0  0  0  0  0  0  0 -134.25  # we will change the last value to get desired pressure at node 1

Save this into a file named L15-E2.txt

L15-E2.txt

5
7
0 0 0 0 0 0
2.0 0.83 1.0 1.0 0.75 0.83 10.0
1000 1410 1000 1000 1000 1000 10.0
0.00001 0.00001 0.00001 0.00001 0.00001 0.00001 0.00001
0.000011
1 1 1 1 1 1 1 1 1 1 1 1
-1 -1  0  0  0  0  1
1 0 -1 0 1 0 0
0 0  1 0 0 -1 0
0 0  0 -1 0 1 0 
0 1 0 1 -1 0 0 
0  0 10  5  0  0  0  0  0  0  0 -134.25 

As before now run the script to generate the input file

# A simple script to generate L15-E2.txt
data = """5
7
0 0 0 0 0 0
2.0 0.83 1.0 1.0 0.75 0.83 10.0
1000 1410 1000 1000 1000 1000 10.0
0.00001 0.00001 0.00001 0.00001 0.00001 0.00001 0.00001
0.000011
1 1 1 1 1 1 1 1 1 1 1 1
-1 -1  0  0  0  0  1
1 0 -1 0 1 0 0
0 0  1 0 0 -1 0
0 0  0 -1 0 1 0 
0 1 0 1 -1 0 0 
0  0 10  5  0  0  0  0  0  0  0 -134.25"""

with open("L15-E2.txt", "w") as file:
    file.write(data)
file.close()
# Now run the simulation 
pipenet.pipenet('L15-E2.txt') 
####ECHO INPUT################
Input File:  L15-E2.txt
number of nodes :  5
number of pipes :  7
viscosity       :  1.1e-05
-----------------------------
node id: 0 , elevation : 0.0  head : 0.0
node id: 1 , elevation : 0.0  head : 0.0
node id: 2 , elevation : 0.0  head : 0.0
node id: 3 , elevation : 0.0  head : 0.0
node id: 4 , elevation : 0.0  head : -134.25
-----------------------------
pipe id: 0 , diameter :  2.0 , distance :  1000.0 , roughness :  1e-05 , flow  :  1.0
pipe id: 1 , diameter :  0.83 , distance :  1410.0 , roughness :  1e-05 , flow  :  1.0
pipe id: 2 , diameter :  1.0 , distance :  1000.0 , roughness :  1e-05 , flow  :  1.0
pipe id: 3 , diameter :  1.0 , distance :  1000.0 , roughness :  1e-05 , flow  :  1.0
pipe id: 4 , diameter :  0.75 , distance :  1000.0 , roughness :  1e-05 , flow  :  1.0
pipe id: 5 , diameter :  0.83 , distance :  1000.0 , roughness :  1e-05 , flow  :  1.0
pipe id: 6 , diameter :  10.0 , distance :  10.0 , roughness :  1e-05 , flow  :  1.0
-----------------------------
node-arc incidence matrix
[-1.0, -1.0, 0.0, 0.0, 0.0, 0.0, 1.0]
[1.0, 0.0, -1.0, 0.0, 1.0, 0.0, 0.0]
[0.0, 0.0, 1.0, 0.0, 0.0, -1.0, 0.0]
[0.0, 0.0, 0.0, -1.0, 0.0, 1.0, 0.0]
[0.0, 1.0, 0.0, 1.0, -1.0, 0.0, 0.0]
-----------------------------
###EXIT TYPE###
Update not changing --exit and report current update
iteration 40
#####SIMULATION RESULTS#####
Results at iteration = : 40
number of nodes :  5
number of pipes :  7
viscosity       :  1.1e-05
-----------------------------
node id: 1 , elevation (feet) : 0.0  head (feet) : 134.25  pressure (psi) : 60.006
node id: 2 , elevation (feet) : 0.0  head (feet) : 134.051  pressure (psi) : 59.917
node id: 3 , elevation (feet) : 0.0  head (feet) : 129.393  pressure (psi) : 57.835
node id: 4 , elevation (feet) : 0.0  head (feet) : 128.712  pressure (psi) : 57.53
node id: 5 , elevation (feet) : 0.0  head (feet) : 130.623  pressure (psi) : 58.384
-----------------------------
pipe id: 1 , diameter (feet) :  2.0 , distance (feet) :  1000.0 , friction factor :  0.02 , flow (cfs) :  12.6
pipe id: 2 , diameter (feet) :  0.83 , distance (feet) :  1410.0 , friction factor :  0.017 , flow (cfs) :  2.4
pipe id: 3 , diameter (feet) :  1.0 , distance (feet) :  1000.0 , friction factor :  0.017 , flow (cfs) :  10.636
pipe id: 4 , diameter (feet) :  1.0 , distance (feet) :  1000.0 , friction factor :  0.017 , flow (cfs) :  -4.364
pipe id: 5 , diameter (feet) :  0.75 , distance (feet) :  1000.0 , friction factor :  0.016 , flow (cfs) :  -1.964
pipe id: 6 , diameter (feet) :  0.83 , distance (feet) :  1000.0 , friction factor :  0.017 , flow (cfs) :  0.636
pipe id: 7 , diameter (feet) :  10.0 , distance (feet) :  10.0 , friction factor :  0.03 , flow (cfs) :  15.0
-----------------------------

Interpret Results and Discussion#

The script handles calculations, the designer has to set-up the input file and create a naming convention for building the input file. Typically would transfer output back to a visual representation as below:

../../_images/IMG-6195.png

Fig. 11 Pipe network solution for Example 2#

Professional network software makes building the input file a matter of selecting elements from a menu (i.e. nodes = hamburgers, pipes = fries) and laying them out on a table. The FGN is a soft drink piped into the network either by a straw or a french fry.

Example 3:#

This example is just another case.

../../_images/Example3-15.png

Fig. 12 Pipe network data for Example 3#

The engineer sets up the problem

../../_images/example3-15-setup.png

Fig. 13 Pipe network worksheet for Example 3 (US Units)#

Following the same protocol as prior examples, build an input file

L15-E3.txt

6
8
170.0 180.0 165.0 155.0 150.0 145.0
0.83 0.83 1.00 2.00 0.83 1.50 0.83 1.00
4000 6000 6000 6000 7000 3000 5000 300.0
0.00001 0.00001 0.00001 0.00001 0.00001 0.00001 0.00001 0.00001
0.000011
1 1 1 1 1 1 1 1 1 1 1 1
1   0 -1  0  0  0  0  0
-1 -1  0 -1  0  0  0  1
0   1  0  0 -1  0  0  0
0   0  1  0  0 -1  0  0
0   0  0  1  0  1  1  0
0   0  0  0  1  0 -1  0
1.114 1.114 1.114 3.347 2.228 3.347 0  0  0  0  0  0  0  -315

Then run the script

# A simple script to generate L15-E3.txt
data = """6
8
170.0 180.0 165.0 155.0 150.0 145.0
0.83 0.83 1.00 2.00 0.83 1.50 0.83 1.00
4000 6000 6000 6000 7000 3000 5000 300.0
0.00001 0.00001 0.00001 0.00001 0.00001 0.00001 0.00001 0.00001
0.000011
1 1 1 1 1 1 1 1 1 1 1 1
1   0 -1  0  0  0  0  0
-1 -1  0 -1  0  0  0  1
0   1  0  0 -1  0  0  0
0   0  1  0  0 -1  0  0
0   0  0  1  0  1  1  0
0   0  0  0  1  0 -1  0
1.114 1.114 1.114 3.347 2.228 3.347 0  0  0  0  0  0  0  -315"""

with open("L15-E3.txt", "w") as file:
    file.write(data)
file.close()
# Now run the simulation 
pipenet.pipenet('L15-E3.txt') 
####ECHO INPUT################
Input File:  L15-E3.txt
number of nodes :  6
number of pipes :  8
viscosity       :  1.1e-05
-----------------------------
node id: 0 , elevation : 170.0  head : 0.0
node id: 1 , elevation : 180.0  head : 0.0
node id: 2 , elevation : 165.0  head : 0.0
node id: 3 , elevation : 155.0  head : 0.0
node id: 4 , elevation : 150.0  head : 0.0
node id: 5 , elevation : 145.0  head : -315.0
-----------------------------
pipe id: 0 , diameter :  0.83 , distance :  4000.0 , roughness :  1e-05 , flow  :  1.0
pipe id: 1 , diameter :  0.83 , distance :  6000.0 , roughness :  1e-05 , flow  :  1.0
pipe id: 2 , diameter :  1.0 , distance :  6000.0 , roughness :  1e-05 , flow  :  1.0
pipe id: 3 , diameter :  2.0 , distance :  6000.0 , roughness :  1e-05 , flow  :  1.0
pipe id: 4 , diameter :  0.83 , distance :  7000.0 , roughness :  1e-05 , flow  :  1.0
pipe id: 5 , diameter :  1.5 , distance :  3000.0 , roughness :  1e-05 , flow  :  1.0
pipe id: 6 , diameter :  0.83 , distance :  5000.0 , roughness :  1e-05 , flow  :  1.0
pipe id: 7 , diameter :  1.0 , distance :  300.0 , roughness :  1e-05 , flow  :  1.0
-----------------------------
node-arc incidence matrix
[1.0, 0.0, -1.0, 0.0, 0.0, 0.0, 0.0, 0.0]
[-1.0, -1.0, 0.0, -1.0, 0.0, 0.0, 0.0, 1.0]
[0.0, 1.0, 0.0, 0.0, -1.0, 0.0, 0.0, 0.0]
[0.0, 0.0, 1.0, 0.0, 0.0, -1.0, 0.0, 0.0]
[0.0, 0.0, 0.0, 1.0, 0.0, 1.0, 1.0, 0.0]
[0.0, 0.0, 0.0, 0.0, 1.0, 0.0, -1.0, 0.0]
-----------------------------
###EXIT TYPE###
Update not changing --exit and report current update
iteration 41
#####SIMULATION RESULTS#####
Results at iteration = : 41
number of nodes :  6
number of pipes :  8
viscosity       :  1.1e-05
-----------------------------
node id: 1 , elevation (feet) : 170.0  head (feet) : 310.612  pressure (psi) : 62.849
node id: 2 , elevation (feet) : 180.0  head (feet) : 313.389  pressure (psi) : 59.621
node id: 3 , elevation (feet) : 165.0  head (feet) : 302.355  pressure (psi) : 61.394
node id: 4 , elevation (feet) : 155.0  head (feet) : 311.838  pressure (psi) : 70.102
node id: 5 , elevation (feet) : 150.0  head (feet) : 312.555  pressure (psi) : 72.657
node id: 6 , elevation (feet) : 145.0  head (feet) : 297.841  pressure (psi) : 68.315
-----------------------------
pipe id: 1 , diameter (feet) :  0.83 , distance (feet) :  4000.0 , friction factor :  0.017 , flow (cfs) :  0.648
pipe id: 2 , diameter (feet) :  0.83 , distance (feet) :  6000.0 , friction factor :  0.017 , flow (cfs) :  1.716
pipe id: 3 , diameter (feet) :  1.0 , distance (feet) :  6000.0 , friction factor :  0.017 , flow (cfs) :  -0.466
pipe id: 4 , diameter (feet) :  2.0 , distance (feet) :  6000.0 , friction factor :  0.02 , flow (cfs) :  8.787
pipe id: 5 , diameter (feet) :  0.83 , distance (feet) :  7000.0 , friction factor :  0.017 , flow (cfs) :  0.602
pipe id: 6 , diameter (feet) :  1.5 , distance (feet) :  3000.0 , friction factor :  0.019 , flow (cfs) :  -3.813
pipe id: 7 , diameter (feet) :  0.83 , distance (feet) :  5000.0 , friction factor :  0.017 , flow (cfs) :  -2.745
pipe id: 8 , diameter (feet) :  1.0 , distance (feet) :  300.0 , friction factor :  0.017 , flow (cfs) :  12.264
-----------------------------

Interpret Results and Discussion#

The script handles calculations, the designer has to set-up the input file and create a naming convention for building the input file. Typically would transfer output back to a visual representation as below:

../../_images/example3-15solve.png

Fig. 14 Pipe network solution for Example 3#

Readings#

  1. Hibbeler, R.C, Fluid Mechanics, 2ed. Prentice Hall, 2018. ISBN: 9780134655413 pp. 469-490

  2. DF Elger, BC Williams, Crowe, CT and JA Roberson, Engineering Fluid Mechanics 10th edition, John Wiley & Sons, Inc., 2013. http://54.243.252.9/ce-3305-webroot/3-Readings/EFM-15.pdf

  3. Cleveland, T. G. (2014) Fluid Mechanics Notes to Accompany CE 3305 at Jade-Holshule (TTU Study Abroad 2015-2019), Department of Civil, Environmental, and Construction Engineering, Whitacre College of Engineering. http://54.243.252.9/ce-3305-webroot/3-Readings/ce3305-lecture12.pdf

  4. Pipe Networks Chin, D. (2006). pp. 27-48 in “Water Resources Engineering, 2 ed.” Prentice Hall, Inc. Chin_27-48

  5. Hydraulics of Pipelines and Pipe Networks Wurbs, R.A., and James, W. P. (2002) Water Resources Engineering, Prentice Hall; pp.130-156; and 156-198. Wurbs and James

  6. Hamam, Y.M., and Brameller, A. (1971) “Hybrid method for the solution of piping networks.” Proc. IEEE, Vol. 118, No. 11, pp 1607-1612. HamamAndBrameller

  7. Jeppson, R.W. (1977) Analysis of Flow in Pipe Networks, Ann Arbor Science pp. 115-129 NewtonRaphsonTheory

  8. Jeppson, R.W. (1977) Analysis of Flow in Pipe Networks, Ann Arbor Science pp. 53-69 FlowInPipeNetworks

  9. Computational Hydraulics in R (for CE 3305) PCHinR

  10. Yoo, D.H. and Singh V. P. (2005) Two Methods for the Computation of Commercial Pipe Friction Factors. ASCE Journal of Hydraulic Engineering, 2005, 131(8): 694-704 FrictionFactors