Skip to main content

Algorithm for water hammer using MOC

Short answer

Read data, set grid with dx=L/N and dt=dx/a, and compute constants Bp and Rp. Initialize steady Q and H including friction. At each time step compute interior K1, K2, Q_P, H_P; apply reservoir C- and valve C+ with valve law; update and store until t<T.

Write an algorithm for simulation of the water hammer process using the method of characteristics.

Problem: a reservoir at the upstream end, a pipe of length LL with a valve at the downstream end that closes in a given time.

Algorithm

  1. Input data: LL, DD, wave speed aa, friction factor ff, reservoir head HresH_{res}, initial steady discharge Q0Q_0, valve closure law τ(t)\tau(t) (relative opening), total simulation time TT.
  2. Grid: choose the number of reaches NN; set Δx=L/N\Delta x=L/N and Δt=Δx/a\Delta t=\Delta x/a (characteristics along the diagonal).
  3. Constants: Ap=πD2/4A_p=\pi D^2/4, Bp=a/(gAp)B_p=a/(gA_p), Rp=fΔx/(2gDAp2)R_p=f\Delta x/(2gDA_p^2).
  4. Initial conditions (t=0t=0): Qi=Q0Q_i=Q_0 at all nodes i=1,…,N+1i=1,\dots,N+1; Hi=Hres−RpQ02(i−1)H_i=H_{res}-R_pQ_0^2(i-1) (steady friction loss along the pipe).
  5. Time loop: set t=t+Δtt=t+\Delta t.
  6. Interior nodes i=2,…,Ni=2,\dots,N:
    • K1=Hi−1+BpQi−1−RpQi−1∣Qi−1∣K_1=H_{i-1}+B_pQ_{i-1}-R_pQ_{i-1}|Q_{i-1}|
    • K2=Hi+1−BpQi+1+RpQi+1∣Qi+1∣K_2=H_{i+1}-B_pQ_{i+1}+R_pQ_{i+1}|Q_{i+1}|
    • QPi=(K1−K2)/(2Bp)Q_{P_i}=(K_1-K_2)/(2B_p), HPi=(K1+K2)/2H_{P_i}=(K_1+K_2)/2
  7. Upstream node (i=1i=1, reservoir): HP1=HresH_{P_1}=H_{res}; K2=H2−BpQ2+RpQ2∣Q2∣K_2=H_2-B_pQ_2+R_pQ_2|Q_2|; QP1=(HP1−K2)/BpQ_{P_1}=(H_{P_1}-K_2)/B_p.
  8. Downstream node (i=N+1i=N+1, valve): K1=HN+BpQN−RpQN∣QN∣K_1=H_N+B_pQ_N-R_pQ_N|Q_N|. With the valve law QP=Q0τHP/H0Q_P=Q_0\tau\sqrt{H_P/H_0} the solution is QP=−BpCv+(BpCv)2+2CvK1,Cv=(Q0τ)22H0,HP=K1−BpQPQ_P=-B_pC_v+\sqrt{(B_pC_v)^2+2C_vK_1},\qquad C_v=\frac{(Q_0\tau)^2}{2H_0},\qquad H_P=K_1-B_pQ_P For complete closure (τ=0\tau=0): QP=0Q_P=0, HP=K1H_P=K_1.
  9. Update: replace old values by the new ones, Qi←QPiQ_i\leftarrow Q_{P_i}, Hi←HPiH_i\leftarrow H_{P_i}.
  10. Store/print HiH_i and QiQ_i (especially the maximum HH at the valve and mid-pipe).
  11. If t<Tt<T go to step 5; otherwise stop. Plot HH against tt to read the maximum pressure rise.
 Start -> read data -> grid, B, R -> initial Q, H
   -> t = t + dt
   -> interior nodes (C+ and C-)
   -> reservoir node (C-) , valve node (C+ and valve law)
   -> update Q, H -> output
   -> t < T ?  yes: back to "t = t + dt"   no: stop

✓ Answer checked by Claude Opus 5.5 (high effort)

All Computational Techniques in Civil Engineering chapter 6 questions →