Skip to main content

Algorithm for unsteady pipe flow FD equations

Short answer

Set up grid with Δt=Δx/a. At interior nodes, equate the C+ and C− equations to solve for Q_{P_i}=[H_{i-1}−H_{i+1}+B(Q_{i-1}+Q_{i+1})−R(Q_{i-1}|Q_{i-1}|+Q_{i+1}|Q_{i+1}|)]/(2B), then compute H_{P_i} from either. Upstream boundary uses C− with known head; downstream uses C+ with given condition. Update all nodes and march in time.

Prepare an algorithm to compute discharge and head based on the following form of finite difference equations for unsteady pipe flow problem using a rectangular grid.

HPi=Hi−1−B(QPi−Qi−1)−RQi−1∣Qi−1∣H_{P_i} = H_{i-1} - B(Q_{P_i} - Q_{i-1}) - R Q_{i-1}|Q_{i-1}|

HPi=Hi+1+B(QPi−Qi+1)+RQi+1∣Qi+1∣H_{P_i} = H_{i+1} + B(Q_{P_i} - Q_{i+1}) + R Q_{i+1}|Q_{i+1}|

where HH = head, QQ = discharge, HPiH_{P_i} and QPiQ_{P_i} = head and discharge at the point of intersection of two characteristics, BB and RR = coefficients.

Given: the two finite difference (characteristic) equations on a rectangular grid, with Δt=Δx/a\Delta t=\Delta x/a:

HPi=Hi−1−B(QPi−Qi−1)−R Qi−1∣Qi−1∣(C+)H_{P_i}=H_{i-1}-B\left(Q_{P_i}-Q_{i-1}\right)-R\,Q_{i-1}|Q_{i-1}|\qquad(C^+) HPi=Hi+1+B(QPi−Qi+1)+R Qi+1∣Qi+1∣(C−)H_{P_i}=H_{i+1}+B\left(Q_{P_i}-Q_{i+1}\right)+R\,Q_{i+1}|Q_{i+1}|\qquad(C^-)

with B=agApB=\dfrac{a}{gA_p} and R=fΔx2gDAp2R=\dfrac{f\Delta x}{2gDA_p^2}.

Solution of the two equations at an interior node

Equate the two expressions for HPiH_{P_i} and solve for QPiQ_{P_i}:

QPi=Hi−1−Hi+1+B(Qi−1+Qi+1)−R(Qi−1∣Qi−1∣+Qi+1∣Qi+1∣)2BQ_{P_i}=\frac{H_{i-1}-H_{i+1}+B\left(Q_{i-1}+Q_{i+1}\right)-R\left(Q_{i-1}|Q_{i-1}|+Q_{i+1}|Q_{i+1}|\right)}{2B}

Then HPiH_{P_i} follows by substituting QPiQ_{P_i} in either equation. Equivalently, HPi=12(K1+K2)H_{P_i}=\tfrac12\left(K_1+K_2\right), with K1=Hi−1+BQi−1−RQi−1∣Qi−1∣K_1=H_{i-1}+BQ_{i-1}-RQ_{i-1}|Q_{i-1}| and K2=Hi+1−BQi+1+RQi+1∣Qi+1∣K_2=H_{i+1}-BQ_{i+1}+RQ_{i+1}|Q_{i+1}|.

Algorithm

  1. Read LL, DD, aa, ff, the number of reaches NN, the total time TT, the initial Qi0Q_i^0 and Hi0H_i^0 for i=1,…,N+1i=1,\dots,N+1, and the boundary conditions (upstream and downstream).
  2. Compute Δx=L/N\Delta x=L/N, Δt=Δx/a\Delta t=\Delta x/a, Ap=πD2/4A_p=\pi D^2/4, BB and RR.
  3. Set t=0t=0 and store the initial values.
  4. Repeat while t<Tt<T:
    1. t=t+Δtt=t+\Delta t.
    2. For i=2,…,Ni=2,\dots,N (interior nodes):
      • QPi=(Hi−1−Hi+1)+B(Qi−1+Qi+1)−R(Qi−1∣Qi−1∣+Qi+1∣Qi+1∣)2BQ_{P_i}=\dfrac{(H_{i-1}-H_{i+1})+B(Q_{i-1}+Q_{i+1})-R(Q_{i-1}|Q_{i-1}|+Q_{i+1}|Q_{i+1}|)}{2B}
      • HPi=Hi−1−B(QPi−Qi−1)−RQi−1∣Qi−1∣H_{P_i}=H_{i-1}-B(Q_{P_i}-Q_{i-1})-RQ_{i-1}|Q_{i-1}|
    3. Upstream boundary (i=1i=1): only the C−C^- equation is available. Use it with the boundary condition (e.g. a reservoir, HP1=HresH_{P_1}=H_{res}):
      • QP1=HP1−H2B+Q2−RBQ2∣Q2∣Q_{P_1}=\dfrac{H_{P_1}-H_2}{B}+Q_2-\dfrac{R}{B}Q_2|Q_2|
    4. Downstream boundary (i=N+1i=N+1): only the C+C^+ equation is available: HP=HN−B(QP−QN)−RQN∣QN∣H_{P}=H_N-B(Q_P-Q_N)-RQ_N|Q_N|, used together with the boundary condition (for a closed end QP=0Q_P=0, so HP=HN+BQN−RQN∣QN∣H_P=H_N+BQ_N-RQ_N|Q_N|; otherwise a valve, pump or reservoir relation).
    5. Update: Qi←QPiQ_i\leftarrow Q_{P_i}, Hi←HPiH_i\leftarrow H_{P_i} for all ii.
    6. Output HiH_i and QiQ_i at the required nodes and times.
  5. Stop when t≥Tt\ge T.
 read data; compute dx, dt, B, R; set initial Q, H; t = 0
 while t < T:
     t = t + dt
     for i = 2..N:   Q_P(i) from the C+ / C- pair, then H_P(i)
     upstream node:    C-  + boundary condition
     downstream node:  C+  + boundary condition
     Q(i) = Q_P(i);  H(i) = H_P(i)   for all i
     print / store results
 end while

The time step must satisfy Δt=Δx/a\Delta t=\Delta x/a (Courant number 1) so that the characteristics pass through the grid points and no interpolation is needed.

✓ Answer checked by Claude Opus 5.5 (high effort)

All Computational Techniques in Civil Engineering chapter 6 questions →