You are on page 1of 12

Flow in Pipe

Networks
General
The analysis of water flow through a closed, pressurized piping system represents a common
task in hydraulic engineering. Development of a computer system to perform the analysis requires application of the networking concepts explored in class in addition to numerical methods to solve nonlinear equations. The first semester project requires development of a software
system to perform analysis for piping networks. These notes describe the theory of pipe flow
and network analysis needed for the project.
A representative piping network is shown in Fig.1. Pipes are connected in closed loops with
a single reservoir supplying water at one of the junctions. Each pipe is full of water and pressurized. Specified amounts (flow rates) of water may be withdrawn or supplied to the system at
all nodes except the reservoir node. The fundamental quantities in the analysis are the flow
rate in each pipe and the pressure (head) at each node. The reservoir is modeled as a source
capable of supplying any required flow rate to the system and at a constant head. The analysis
determines the flow rate in each pipe and the head at each node.
The engineer describes the network for analysis by providing this information:
(1)

the number of nodes and pipes in the network;

(2)

the length, diameter and construction material for each pipe;

(3)

the network connectivity, i.e., the branch incidences;

(4)

the known external flow rate at each node (equals zero when no external withdrawal or supply is imposed at node);

(5)

the node number at which the reservoir is attached to the network.

We require consecutive pipe and node numbers from 1...np and 1...nn. Each pipe in the network is assigned a positive direction by the order of nodes specified for the pipe incidences. For
example, pipe 2 in Fig. 1 is specified to have the incidences 2, 5 which implies a positive flow
in the pipe transports water from node 2 to node 5. A negative flow for pipe 2 denotes water
flow in the direction from node 5 to node 2.

CEE-490, CSE-491

Pipe Flow Theory

Hazen--Williams Factor =120 All Pipes

Reservoir @ 200 Head

1.0 cfs

0.5 cfs

[2]

8-- 2000

[5]

8-- 1500

1
8-- 1500

[1]

8-- 2000

[3]
1.0 cfs

6-- 3000

5
6

[4]

8-- 2000

[6]

6-- 1500

10-- 1000

10-- 2000

1.5 cfs

[7]

1.5 cfs

Figure 1, Example Pipe Network

Notation
The following notation is adopted to simplify development of the governing equations and computational procedures. A subscript k denotes a pipe quantity, i.e., qk is the flow rate in the k th
pipe. Subscripts i, j and m denote node quantities, i.e., Hi --Hj is the change in head (pressure)
between nodes i and j (relative to node j). The number of pipes is given by np; the number of
nodes by nn. Other quantities are defined below.
pipe lengths

Lk (units in feet)

pipe diameters

Dk (units in inches)

pipe flow rates

qk (units in cubic feet per second, cfs)

Hazen-Williams coefficient HWk (no units)


hydraulic head at nodes

Hi (units in feet)

reservoir node subscript

Ci > 0
[i]

known external nodal flow Ci (units in cubic feet per second, cfs. A positive value
implies flow is being withdraw from system)

Physical Model for a Single Pipe


Consider the k th pipe that connects nodes i and j as shown in Fig. 2.For positive flow, qk >0, the
head at node i must be larger than the head at node j. Flow through a pipe causes a head loss

CEE-490, CSE-491

Pipe Flow Theory


due to frictional forces between the water and the inner wall of the pipe. The head loss, Hi - Hj , is
related to the flow rate, pipe length, pipe diameter and pipe material by the expression
qk =

Hi Hj
fk

Hi Hj

(1)

where =0.54 and fk quantifies the frictional resistance to flow. To derive the above model, water is treated as an incompressible fluid. The frictional resistance, fk , is given by
fk =

8.52 10 5 L k
(independent of the flow rate)
HW 1.852
D 4.87
k
k

(2)

The factor of 8.52 also reflects the conversion of various units for terms in the equation (L must
be in feet, D in inches, H in feet, HW is dimensionless). In the above equations, Hi must be algebraically Hj otherwise the exponentiation operator is not defined. When Hi < Hj , Eq. (1) is
recast in the form
qk =

Hj Hi
fk

H j > H i

(3)

The following example employs realistic numbers for a pipe: Hi =26.3, Hj =1.0, L=1500,
HW=130, D=6. Equation (1) yields a flow rate q=1.0 cfs for the head loss of 25.3 over the
1500 length of the pipe. Both Eqs. (1) and (3) may be inverted to solve for the head loss given the
flow rate.
The head loss-flow rate relationship given by Eqs. (1) or (3) is highly nonlinear since 1.0.
This contrasts markedly to similar relationships in structural engineering, for example. In
structural problems, Hi and Hj are the nodal displacements, fk represents the element flexibility (inverse of stiffness) with qk representing the element force. In most structural models,
=1.0, and the resulting system of simultaneous equations is linear. In pipe flow problems,
the system of simultaneous equations is nonlinear which precludes a trivial solution.

System Level Model


While the flow in each pipe must obey the model described by Eqs. (1) and (3), two system level
requirements must also be satisfied: (1) the algebraic sum of the head (pressure) change in each
Hi

Pipe k

[i]

Hj

Flow rate q k

[j]

Figure 2, Analysis of a Single Pipe

CEE-490, CSE-491

Pipe Flow Theory


pipe around any closed loop must be zero, and (2) the continuity of mass must be preserved at
each node. We adopt the mass continuity requirement to develop a system level set of governing
equations. With this approach, the hydraulic head, Hi , at each node becomes the unknown
quantity. This is analogous to structural models analyzed by the stiffness method; force equilibrium requirements at the nodes generate equations with displacements as the unknown
quantities. The number of unknowns in pipe networks is nn- 1; the head is always known at the
reservoir node, r. The resulting set of nodal heads computed with this approach automatically
satisfy the loop head loss requirement of (1).
C 4 > 0 (withdraws water)

[3]

Continuity Equation for Node 4:


F4 = q 8 q 9 C4 = 0

[4]

Net Flow Into Node

[5]

Figure 3, Example Continuity Equation


As an example, consider the portion of a network shown in Fig. 3. We adopt the convention
that flow rates into the node from a pipe are positive while specified external flow rates that
withdraw water are also positive. The flow rates, rather than mass transport rates, may be
used in the continuity equations because (1) the fluid is homogenous (water) and (2) the flow
is idealized as incompressible. A continuity equation is written at all but the reservoir node (it
supplies any required flow rate needed by the system as a whole).
Each nodal continuity equation has the general form
np

Fm =

q k Cm = 0

(4)

k=1

where np denotes all pipes connecting to node m. In matrix form, Eq. (4) becomes
F = {0 } .

(5)

The flow rate, qk , for each pipe connected to the node is substituted from Eq. (1) or (3) into
Eq. (4). The Fm continuity equation for the node then contains the heads, Hj , at adjacent nodes
as the unknowns. Thus, {F}={0} represents a set of nn- 1, nonlinear simultaneous equations
for the unknown nodal heads Hi .
Figure 4 defines a simple 3 node, 3 pipe system used to develop the solution process in detail. The continuity equations at nodes 2 and 3 are:

CEE-490, CSE-491

Pipe Flow Theory

1.5 cfs

Reservoir @ 100 Head


Pipe L
D
1 1000 10

[2]

HW
f
120 1.622

1000 12

120 0.667

1500 10

120 2.432

1
3

[1]

H 1 = 100; C 2 = 1.5; C3 = 3.0


[3]

3.0 cfs

Figure 4, Example for Constructing System Continuity Equations

F2 = q 1 q 2 C2 = 0

(6a)

F3 = q 2 + q 3 C3 = 0 .

(6b)

The flow rates in each pipe are given by

H1 H2
q1 =
f1

H2 H3
q2 =
f2

H1 H3
q3 =
f3

(7a)

(7b)

(7c)

where we have assumed that H1>H2, H1>H3 and H2>H3 (H1 is a known value) with the result that each q>0. Upon substitution of Eqs. (7) into Eqs. (6), we have

H1 H2
F2 =
f1

H2 H3
F3 =
f2

H2 H3

f2
H1 H3
+
f3

C2 = 0

(8a)

C3 = 0

(8b)

where the only unknowns are H2 and H3. Using numerical values for the example network in
Fig. 4, Eqs. (8) become

100 H 2
F2 =
1.622

CEE-490, CSE-491

0.54

H2 H3

0.667

0.54

1.5 = 0

(9a)

Pipe Flow Theory

H2 H3
F3 =
0.667

0.54

100 H 3
+
2.432

0.54

3.0 = 0 .

(9b)

This pair of nonlinear, simultaneous equations is solved using Newtons method as described in
the next section. The solution procedure requires an initial estimate for each unknown Hi .
These values are supplied by the engineer based on previous experience with solving pipe flow
problems. Fortunately, convergence of the iterative solution procedure is not overly dependent
on the selection of starting values for Hi .
Equations (6)-(9) assume the head at node 2 is greater than the head at node 3. During the
iterative solution process, the reverse condition may be found. To accommodate this situation,
Eq. (7) is generally evaluated using the absolute value of the term Hi --Hj with the sign of the
resulting flow rate determined by the sign of Hi --Hj . The resulting flow rates (with appropriate
sign) are then substituted into Eq. (6). In no case can the nodal heads H2, H3 be greater than
the head of the reservoir.

Newtons Method for Solution of Pipe Flow Equations


The nn- 1 set of nodal continuity equations, {F}={0}, is nonlinear in the unknown nodal heads,
denoted {H}. Newtons method is employed to solve these equations given a starting estimate
for {H}. Let {H(i)} denote the current estimate of the solution vector after i iterations of the solution process. Newtons method provides the basis to compute a correction, {H(i)}, to {H(i)} that
improves the satisfaction of {F}={0}; i.e., the exact vector {H} satisfies this relation. The improved solution vector for use in the i+1 iteration is {H(i+1)}={H(i)} + {H(i)}. The iterative process continues to improve {H} until the set of equations {F}={0} is satisfied within a specified
tolerance.
The development of Newtons method proceeds as follows. When the current (i th) estimate
of the nodal heads, {H(i)}, does not satisfy the continuity equations, the result is a vector of unbalanced or residual flows, {R(i)}, at the nodes

F(H (i)) = R (i)

(10)

nn1

where the bold character indicates a vector of length nn- 1. Newtons method seeks to find a
correction {H(i)} such that

F(H (i) + H (i)) = {0}

(11)

Subtract Eq. (10) from Eq. (11) to yield

F(H (i) + H (i)) F(H(i)) + R (i) = {0}

(12)

The leading two terms in Eq. (12) are denoted by


F (i) = F(H (i) + H (i)) F(H (i)) .

(13)

To first order, the incremental change {F(i)} is approximated by the differential, {dF(i)}, where

F (i) dF (i) = J(H (i)) dH(i)


CEE-490, CSE-491

(14)

Pipe Flow Theory


The nn- 1 by nn- 1 matrix [J(i)] is the Jacobian of the vector function {F}. The terms of [J(i)] are
given by
dF 1 =

F 1
F
F
dH1 + 1 dH2 + + 1 dHs
H 1
H 2
H s

(15a)

dF s =

F s
F s
F
dH1 +
dH2 + + s dHs
H 1
H 2
H s

(15b)

where s=nn- 1. Row r and column r of [J(i)] corresponding to the reservoir node are omitted;
dHr 0 since the reservoir provides a fixed hydraulic head for the water supply. Note also that
the specified nodal flows Cm do not appear as dCm =0 as well.
The product [J(i)]{H(i)}[J(i)]{dH(i)} provides a linearized approximation to {F(i)} at {H(i)}
that remains valid over a small change in {H}. Use of this approximation for {F(i)} in Eq. (12)
leads to the nn- 1 set of linear, simultaneous equations
[J(H (i))]H (i) = R (i) .

(16)

The symbolic solution for this set of equations is written using the inverse of the Jacobian as

H(i) = [J(H (i))]1R(i)

(17)

For all practical problems, the solution of Eq. (16) for the head corrections is accomplished using a standard linear equation solver, for example, Gauss elimination. The specific form of {F}
in the pipe flow model leads to a symmetric Jacobian matrix, i.e., Ji,j =Jj,i . Finally, the new estimate for the solution vector is given by {H(i+1)}={H(i)} + {H(i)}.
The iterative solution continues until the residual nodal flows, {R(i+1)}, computed with the
updated nodal heads approach zero. Since the residual flows have units of cubic feet per second,
an absolute convergence test is applicable and straightforward. The iterations continue until
each term in {R(i+1)} is tol, where tol is specified by the engineering analyst (a typical value
might be 0.01). (Note: in convergence tests of this type, the absolute value of each term in
{R(i+1)} is compared with tol).

Example
Newtons method is applied here to complete the example problem defined in Fig. 4. Eq. (15) is
applied to Eq. (8) to obtain the Jacobian matrix in symbolic form as

100 H 2
dF 2 =
f1
f1

H2 H3
dF 3 =
f2
f2

H2 H3
dH2
f2
f2

H2 H3
dH 2
f2
f2

H 2 H3
dH 2 +
f2
f2

100 H 3
dH 3
f3
f3

dH 3

(18a)

dH 3

(18b)

where =--1=--0.46. Substitution of numerical values for this problem yields

100 H 2
J 1,1 = 0.3329
1.622

CEE-490, CSE-491

0.46

H H3
0.8096 2
0.667

0.46

(19a)

Pipe Flow Theory

H H3
J 1,2 = 0.8096 2
0.667

0.46

(19b)
(19c)

J 2,1 = J 1,2
J 2,2 = 0.8096

H
H0.667

0.46

0.2220

H
1002.432

0.46

(19d)

Note also Eq. (19) requires H2H3 otherwise the exponentiation operator is undefined. By re-deriving terms of [J] using the form of Eq. (6) with changed signs for q2 (which implies H3H2),
we find the form of Eq. (19) is identical with only the H2 - H3 terms replaced by H3 - H2.
To initialize the iterative solution, assume {H(1)}=95, 85. When substituted into Eq. (9),
the corresponding residual flows are {R(1)}=--3.9774, 3.9858. Using {H(1)} to form [J] in Eq.
(19), solve the set of linear equations
--0.431359

0.233005

H 2

0.233005

--0.329160

H 3

--3.9774

(20)

3.9858

to find {H(1)}=--4.3387, 9.03775and thus {H(2)}=90.6612, 94.0377. After 7 iterations,


the converged heads are {H(7)}=91.444, 90.858with {R(7)}=0.023, --0.0231.

Implementation
The core tasks in the software implementation of pipe flow analysis are:
(1)

computation of {R(i)} using the current estimate of the nodal heads {H(i)};

(2)

formation of the Jacobian matrix [J(i)] using the current estimate of the nodal
heads {H(i)};

(3)

solution of the simultaneous equations [J(i)]{H(i)}={--R(i)} to determine the corrective nodal heads.

This section describes tasks (1) and (2). Task (3) is performed with a standard Gauss elimination subroutine. The C++ code for task (3) will be provided and does need to be written as part of
the project.
The incidences table and the link_point- nodal_incidences data structure are employed to
complete tasks (1) and (2). We have previously used the names node, ipt and link for these arrays.

Computation of {R(i)}
Two algorithms are available. The first algorithm employs the link_point- nodal_incidences
data structure to compute Rm at node m completely before processing node m+1. The driving
loop spans over all nodes. The second algorithm employs the incidences table to include the contribution of the flow rate in each pipe on {R(i)}. The driving loop spans over all pipes. We adopt
the second algorithm in this project although neither algorithm has a decided advantage for
problems with all data resident in memory. The pseudo-code to generate {R(i)} using the second
algorithm is provided in Fig. 5.

CEE-490, CSE-491

Pipe Flow Theory


Once the generation of {R} is completed, a second loop over all terms in {R} is executed to
determine the maximum value (use absolute value of Rm ) for convergence testing and to negate
each term as required in the equation solving Task (3).

Computation of [J(i)]
Several algorithms are available to construct [J(i)]. The approached outlined here employs the
link_point- nodal_incidences data structure. This data structure provides the list of pipes connected to each node in the network. Each row of [J(i)] is constructed sequentially beginning at
row 1 for node 1 (the reservoir node is simply skipped). The differential of the continuity equation at node m, see Eq. (4), is given by
np

dF m =

dqk

(21)

k=1

where the same result for dFm is also given by row m of [J(i)] multiplied into the column vector
{dH(i)}. Thus,
np

dF m =

nn

dqk = Jm, j dHj .

k=1

(22)

j=1

In large networks, most terms Jm,j are zero due to small number of pipes connected to a
node. To illustrate this, consider the portion of the network around node m shown in Fig. 6.
Node m is connected by pipes to nodes 2, 3 and 8. Consequently, the term dFm (the differential flow-rate at node m) is affected only by dH changes at nodes 2, 3, and 8. For node m, we
have
dF m = dq 5 dq 2 dq 10
(1) Initialize {R} with zeros
(2) Insert negative of the specified nodal flows into {R}
(3) Loop over all pipes; pipe=1, np

(23)
start
Hi
pipe

(3a)

set the starting node, start, for the pipe;


start=incidences(pipe,1).

(3b)

set the ending node, end, for the pipe; end=incidences(pipe,2).

(3c)

compute the flow rate, q, in the pipe using Eq. (1). q is negative if
the flow direction is opposite the positive pipe direction.

(3d)

add q to Rend ; Rend =Rend + q.

(3e)

subtract q from Rstart; Rstart =Rstart - q.

end
Hj

(4) Zero the entry in {R} for the reservoir node; Rr =0


Note: we have referred to the incidences array as the node array previously
Figure 5, Pseudo-Code for Computation of Residual Flows, {R}

CEE-490, CSE-491

Pipe Flow Theory


or equivalently using the Jacobian, Eq. (15),
dF m = J m,2 dH 2 + J m,3 dH 3 + J m,m dH m + J m,8 dH 8

(24)

with all other Jm,j terms=0. Each of the non--zero Jm,j terms has a simple physical interpretation. For example, Jm, 2 is the differential change in flow rate at node m caused by a unit value of
the head change (dH2) at node 2. The Jm,j coefficients are found by substituting expressions for
dq5, dq2 and dq10 into Eq. (23).

[3]
2
5
[2]

[m]

10

[8]

Figure 6, Network Region to Demonstrate Generation of [J]


The differential flow rate, dq, in a pipe is given by the total differential of the the flow rate,
q, defined by Eq. (1), and is repeated here
qk =

Hi Hj
fk

(H i H j) .

(25)

The total differential is then

Hi Hj
dq k =
fk
fk

(dH i dHj) (H i H j) .

(26)

To simplify subsequent discussion, define k as

Hi Hj
k =
fk
fk

(H i H j)

(27)

(H i H j) .

(28)

which reduces Eq. (26) to the form


dq k = k dH i k dH j
For pipe 5 in Fig. 6,
dq 5 = 5 dH 2 5 dH m .
CEE-490, CSE-491

(29)

10

Pipe Flow Theory


Similarly, the differential flow rates for pipes 2 and 10 are
dq 2 = 2 dH m 2 dH 3

(30a)

dq 10 = 10 dH m 10 dH 8 .

(30b)

Upon substituting these expressions for dq into Eq. (23) and gathering common terms multiplying the differential heads, dH2, dH3, dHm and dH8, we have
dF m = 5 dH 2 + 2 dH 3 + ( 2 5 10)dH m + 10 dH 8

(31)

from which the terms on row m of [J(i)] are seen to be


J m,2 = 5 ; J m,3 = 2 ;

(32)

J m,m = 2 5 10 ; J m,8 = 10 .
The value for each pipe connected to node m appears twice on row m; the sign of the value
depends on (1) the connectivity of the pipe to node m and (2) the sign of the head difference for
the pipe. In the above example, the proper sign for the connectivity is included directly in Eq.
(23). In computing k , the head difference Hi - Hj is assumed to be positive. Fortunately, the
combinations of sign changes caused by the two connectivities (+,--) and the head difference
(+,--) cancel in two of the four possible cases, leaving only two cases for implementation. k is
always computed as a positive value by using |Hi - Hj | rather than Hi - Hj in Eq. (27). The sign of
the connectivity of the pipe to node m alone then sets the sign applied to k in forming a term
Jm,j .
In the above development, the equation corresponding to the reservoir node r is omitted.
However, to simplify the numerical implementation we construct [J(i)] with size nn by nn. Row
r and column r are zeroed; a value of 1.0 is then placed into term Jr,r. The corresponding term
in the residual flow vector is also zeroed (see step (3) in Fig. 5). When the corrective heads are
computed by solving Eq. (16), the head change at the reservoir node is then zero. The pseudo-code to generate [J(i)] using the above procedure is provided in Fig. 7.

CEE-490, CSE-491

11

Pipe Flow Theory

(1) Zero all terms in [J]: Ji,l =0; l=1...nn, i=1...nn


(2) Loop over nodes (skip node r); node=1, nn
(2a)

Loop over all pipes incident on node;


k=link_point(node), link_point(node+1)--1
(2a--1) Get pipe number pipe from nodal_incidences(k)
(2a--2) Save sign (+,--) of pipe. Then pipe=|pipe|
(2a--3) Set start, end nodes for pipe;
start=incidences(pipe,1),
end=incidences(pipe,2)
(2a--4) Compute for pipe using current solution vector {H(i)}
Use |..| of head difference so >0.
(2a--5) Include value twice on row node of [J]:
sign>0: Jnode,start =Jnode,start +
Jnode,end =Jnode,end -
sign<0: Jnode,start =Jnode,start -
Jnode,end =Jnode,end +

(2b)

End of k loop over pipes on node

(3) End of node loop over all nodes


(4) Zero row r and column r of [J]
(5) Set Jr,r =1.0
Note:

We have referred to the incidences array as the node array previously.


Also note the assumed ordering of columns in the array for the start & end
nodes for each pipe.

Figure 7, Pseudo-code for Computation of Jacobian Matrix [J]

CEE-490, CSE-491

12

You might also like