Theoretical Framework

The Mathematics Behind X-WHAT

This page condenses the governing equations, the cost model, and the two optimization problems implemented in the Excel engine. Equation numbers follow the publication, so every result shown here can be traced to its full derivation in the paper available at the end of the page.

Scope Components Conservation Laws Head Loss Cost Model WFP and DOM Excel Implementation Validation The Paper

1. Scope and Assumptions

X-WHAT simulates pressurized looped water distribution networks under steady-state flow of an incompressible fluid. Given the topology, the pipe properties, and the boundary conditions, the model determines the discharge and direction of flow in every link together with the piezometric head and pressure at every node. In design mode it also searches the tank configuration of minimum total cost.

Steady-state flow Incompressible fluid Valves fully open Minor losses neglected Fixed tank heads Pumps only fill the tanks

Since pumps are used exclusively to supply the storage tanks, they do not interfere with the hydraulic state of the network. Their role appears in the cost function through the energy consumed to lift water into the tanks. Tanks and reservoirs are treated interchangeably because both reduce to a fixed piezometric head under the steady-state design condition.

2. Network Components and Topology

The network is described by nodes and links. Nodes comprise junctions and tanks. Links comprise pipes and pumps. Nodes and links are numbered continuously and every loop follows the clockwise convention, which fixes the sign of each flow in the energy balance.

hr hb Tank (fixed head) Pump Qp,r /5/ 1 2 3 4 /1/ /2/ /3/ /4/ L1 Qd,2 Qd,3
Notation used to describe the network. Nodes and links carry a continuous numbering, loops follow the clockwise convention, the tank is defined by its water depth hr and tower height hb, and the pump lifts the flow Qp,r into the tank. Demands Qd withdraw water at the junctions.
Element Class Definition in the model
Junction Node Connects two or more links. Defined by its ground elevation \(z\) from a reference datum. Direct demand withdrawals \(Q_d\) are assigned here, with positive values representing consumption.
Tank / Reservoir Node Storage element defined by the piezometric head at its surface. It holds a fixed head \(h_r\) during a simulation and becomes a decision variable during design optimization.
Pipe Link Conveying element with constant slope, defined by its diameter \(D\), length \(L\), and one friction property, the roughness \(\epsilon\) for Darcy-Weisbach or the coefficient \(C\) for Hazen-Williams.
Pump Link Supplies the tanks. Defined by its daily operating hours \(n_p\), efficiency \(\eta_p\), ground elevation \(z_p\), and a linear head loss coefficient \(k_p\) for the supply line.
Full description in Section 2.1 of the paper.

3. Conservation Laws

Mass Conservation at Junctions

Under steady-state conditions the storage change at every junction is null, so the algebraic sum of inflows, outflows, and demand must vanish. For every junction \(i\),

(1) \[ \sum_{k=1}^{n_k} Q_{in}^{\,i} \;-\; \sum_{m=1}^{n_m} Q_{o}^{\,i} \;-\; Q_{d}^{\,i} \;=\; 0 \]

\(Q_{in}\) are the inflows, \(Q_o\) the outflows, and \(Q_d\) the nodal demand, positive when water is withdrawn from the network.

Pump Flow Rate

The design demand already carries the peak hour factor \(k_2\), while the pumps run \(n_p\) hours per day to deliver the daily volume. The pumping flow rate that fills each tank is therefore

(2) \[ Q_{p,r}^{\,i} \;=\; \frac{Q_d^{\,i}}{k_2}\, \frac{n_{WDN}}{n_p^{\,i}} \]

\(n_{WDN}\) is the daily duration of network operation, typically 24 hours. Shorter pumping windows raise \(Q_{p,r}\) and with it the pumping power and energy cost.

Energy Conservation in Loops

The head losses accumulated around any closed loop must cancel out. For a loop \(v\) containing \(m_v\) pipes, with signs assigned by the clockwise convention,

(11) \[ \sum_{i=1}^{m_v} k_{v_i}\, Q_{v_i} \left| Q_{v_i} \right|^{n-1} = 0, \qquad \text{for all loops } v = 1, \dots, c \]

\(k\) is the resistance term of each pipe and \(n\) the exponent of the friction model, both defined in the next section. Writing the losses as \(Q\lvert Q\rvert^{n-1}\) keeps the sign of the flow, so reversed discharges are handled naturally.

Incidence Matrices

The topology enters the model through two matrices that occupy their own sheets in the workbook. The node incidence matrix \(\mathbf{F_d}\) maps links to nodes,

(12) \[ F_d(i,j) = \begin{cases} -1 & \text{if pipe } j \text{ leaves junction } i \\[2pt] \phantom{-}0 & \text{if pipe } j \text{ is not connected to junction } i \\[2pt] +1 & \text{if pipe } j \text{ enters junction } i \end{cases} \]

and the loop incidence matrix \(\mathbf{F_l}\) maps links to loops,

(13) \[ F_l(i,j) = \begin{cases} -1 & \text{if pipe } j \text{ is in loop } i \text{ against the loop direction} \\[2pt] \phantom{-}0 & \text{if pipe } j \text{ is not in loop } i \\[2pt] +1 & \text{if pipe } j \text{ is in loop } i \text{ along the loop direction} \end{cases} \]

With \(\mathbf{q}\) as the vector of link discharges and \(\mathbf{d}\) as the vector of nodal demands, the conservation laws for the entire network collapse into the compact system \(\mathbf{F_d}\,\mathbf{q} - \mathbf{d} = \mathbf{0}\) for mass and \(\mathbf{F_l}\,\boldsymbol{\Delta h_f}(\mathbf{q}) = \mathbf{0}\) for energy. These two residual blocks are exactly the constraint ranges handed to the Excel Solver.

Full derivation in Sections 2.2 and 2.3 of the paper.

4. Head Loss Models

Friction losses in every pipe follow the general monomial form

(3) \[ \Delta h_f = k\, Q \left| Q \right|^{n-1} \]

where \(k\) gathers the geometric and friction properties of the link. The user chooses between two friction models.

Darcy-Weisbach

The physically based option, valid for any Newtonian fluid and flow regime. Rearranging the classical formulation with \(v = Q/(\pi D^2/4)\) gives

(5) \[ k^{\text{D-W}} = \frac{8 f L}{D^5 \pi^2 g}, \qquad n = 2 \]

The friction factor \(f\) is evaluated with an explicit full-range formulation, free of iteration and valid across laminar, transition, and turbulent regimes,

(6) \[ f = \left\{ \left( \frac{64}{Re} \right)^{8} + 9.5 \left[ \ln\!\left( \frac{\epsilon}{3.7 D} + \frac{5.74}{Re^{0.9}} \right) - \left( \frac{2500}{Re} \right)^{6} \right]^{-16} \right\}^{0.125} \]

\(Re = vD/\nu\) is the Reynolds number and \(\nu\) the kinematic viscosity entered in the model parameters.

Hazen-Williams

The empirical option, standard practice for water at ordinary temperatures, with tabulated coefficients \(C\) for each pipe material,

(7) \[ k^{\text{H-W}} = \frac{10.67\, L}{C^{1.85}\, D^{4.87}}, \qquad n = 1.85 \]

Node Heads and Pressures

Applying Bernoulli's equation between the two end nodes of every link \(l\) gives

(8) \[ h_i - h_j = k_f^{\,l}\, Q_l \left| Q_l \right|^{n-1}, \qquad \text{for all links } l = 1, \dots, n_l \]

\(h := P/\gamma + z\) is the piezometric head. Subtracting the ground elevation \(z\) from the head recovers the pressure head at each node, the quantity bounded in the design problem.

Head Gain from Pumps

The manometric head that each pump must supply combines the geometric lift and the friction loss of the supply line,

(9) \[ H_p = h_g + k_p\, Q_{p,r} \left| Q_{p,r} \right|^{n-1}, \qquad h_g = h_r + (z_b - z_p) \]
Full derivation in Section 2.2.2 of the paper.

5. Cost Model

Optimization studies of water networks usually price the pipelines alone. X-WHAT builds a broader objective that adds the tank material, the tank foundation under wind loading, and the pumping energy brought to present value. This turns the design exercise into an interdisciplinary problem that couples hydraulics, structural reasoning, and engineering economics.

Pipeline Cost

The unit cost of pipe is approximated by a high order polynomial of the diameter, fitted by least squares over a catalog of commercial sizes,

(22) \[ C_l(D) = \sum_{s=1}^{n_d} \alpha_l\, D^s \]

A continuous cost function keeps derivatives available to the gradient-based Solver. The fit can be reproduced in Excel with the LINEST function, and the default catalog can be replaced by local market prices in the project settings.

Tank Material Cost

For a cylindrical tank of diameter \(D_r\) and water depth \(h_r\), the material cost covers the lateral, bottom, and top surfaces,

(14) \[ C_r^m = c_m \left[ \pi D_r \left( \frac{D_r}{2} + h_r \right) \right] \]

The required storage volume \(V_r\) ties the diameter to the water depth and removes one variable from the search,

(18) \[ D_r = \sqrt{\frac{4 V_r}{\pi h_r}} \]

The tank volume follows local regulation. The paper adopts one third of the total demanded volume on the day of highest demand.

Tank Foundation Cost

For elevated tanks the dominant structural action is the lateral wind load. Integrating the wind pressure profile over the wetted height of the tank gives the bending moment at the foundation,

(15) \[ M_r = \frac{1}{2} \pi D_r k_w \left[ \frac{(h_b + h_r)^{p+2} - h_b^{\,p+2}}{p+2} \right] \]

\(k_w\) is a wind drag coefficient derived from the design wind speed and \(p\) is an exponent that shapes the growth of wind pressure with elevation, with typical values around 0.20. For a wind speed of 40 m/s and \(p = 0.30\), \(k_w = 348\) N·m-2.3.

The foundation cost itself comes from a regression fitted over a reinforced concrete footing model that accounts for tipping, sliding, and shear resistance,

(16) \[ C_f^r = \alpha_1 V_r^{\beta_1} + \alpha_2 M_k^{\beta_2} + \alpha_3 H_k^{\beta_3} \]

and the total tank cost gathers material and foundation, \(C_r = C_r^m + C_f^r\), Eq. (17) of the paper.

Pump Energy Cost

The daily energy expense follows from the hydraulic power delivered during the pumping window,

(19) \[ C_e = P_e\, \frac{H_p\, Q_{p,r}\, \gamma\, n_h}{\eta_p} \]

Energy is an operational expense charged throughout the project life, so the annual amount is converted to present value with a factor built from the lifespan \(n_l\), the interest rate \(i_r\), and the annual energy price increase \(i_e\),

(20) \[ I_{NPV} = \begin{cases} \dfrac{1 - (1+i_e)^{n_l}(1+i_r)^{-n_l}}{i_r - i_e} & \text{if } i_r \neq i_e \\[10pt] \dfrac{n_l}{1+i_r} & \text{if } i_r = i_e \end{cases} \]

so the pumping cost entering the objective is \(C_p = I_{NPV}\, C_e \times 365\), Eq. (21) of the paper.

Total Network Cost

(23) \[ C_t = \sum_{i=1}^{n_l} L_i\, C_l \;+\; \sum_{j=1}^{n_p} C_p^{\,j} \;+\; \sum_{k=1}^{n_r} C_r^{\,k} \]
Full derivation in Sections 2.4 and 2.5 of the paper.

6. The Two Problems Solved by X-WHAT

Simulation

Water Flow Problem (WFP)

Given the pipe diameters, the demands, and the fixed tank heads, find the discharge vector that satisfies mass and energy conservation. No objective function is required, the Solver only searches a feasible point.

(24) \[ \begin{aligned} \text{find} \quad & \mathbf{q} \\ \text{s.t.} \quad & \mathbf{F_d}\,\mathbf{q} - \mathbf{d} = \mathbf{0} \\ & \mathbf{F_l}\,\boldsymbol{\Delta h_f}(\mathbf{q}) = \mathbf{0} \end{aligned} \]

The classic Hardy-Cross procedure needs an initial flow guess that already conserves mass at every node, followed by successive corrections. The matrix formulation removes both requirements, since any starting vector can be handed to the Solver.

Optimization

Design Optimization Modeling (DOM)

Find the flows together with the tank water depths \(h_r\) and tower heights that minimize the total cost while all nodal pressures stay inside the allowed band.

(25) \[ \begin{aligned} \min_{\mathbf{q},\, h_r,\, z_b} \quad & C_t \\ \text{s.t.} \quad & \mathbf{F_d}\,\mathbf{q} - \mathbf{d} = \mathbf{0} \\ & \mathbf{F_l}\,\boldsymbol{\Delta h_f}(\mathbf{q}) = \mathbf{0} \\ & p_{min} \le p \le p_{max} \\ & h_{r,min} \le h_r \le h_{r,max} \end{aligned} \]

The problem is non-convex, non-smooth, and non-linear because of the friction terms, so multiple starting points are recommended to approach the global optimum.

7. Implementation in Excel

Every equation above lives in an open spreadsheet cell. The workbook is organized in three sheets. Memory gathers the model parameters, the node and link tables, and the cost cells. Mass_Balance holds the matrix \(\mathbf{F_d}\) and Energy_Balance holds the matrix \(\mathbf{F_l}\). Both problems are solved with the GRG Nonlinear engine of the Excel Solver. The WFP run asks for feasibility only, while the DOM run minimizes the total cost cell with the pressure bounds added as constraints. The Multistart option of the Solver tests several starting points of the decision space, which raises the chances of escaping local minima in the DOM problem.

Since no step of the calculation is hidden, users can audit any cell with the trace precedents and trace dependents commands of Excel, modify the cost functions, or replace the objective with a different metric such as the average network pressure. Step-by-step instructions are given in the Manual.

Full description in Section 2.7 of the paper.

8. Validation

The model was verified against EPANET and against results reported in the literature for three networks of increasing complexity. The agreement is quantified with the mean absolute error applied to the pressures at all nodes and the discharges in all links,

(26) \[ \text{MAE} = \frac{\sum_{i=1}^{n} \left| x_m - x_{obs} \right|}{n} \]
CASE (A)

Two-Loop Network

5 nodes, 6 links, 1 tank. Solved step by step in the paper and checked against EPANET.

160 inhabitants
CASE (B)

Porto (2006)

Intermediate looped network used to compare both friction models with literature results.

12,800 inhabitants
CASE (C)

Huddleston (2004)

8 loops, 12 internal nodes, 2 reservoirs, and 21 links, with known reservoir head boundary conditions.

44,416 inhabitants

Cases (b) and (c) are available as tutorial networks in the Network Builder, in both WFP and DOM configurations. For case (c), the design optimization reduced the total network cost by 151,790 USD, about 9.8% of the standard design cost, by adjusting the tank water depths under the pressure constraints.

Full results and discussion in Sections 3 to 5 of the paper.

9. The Publication

The PDF below is the current public preprint. Add the final journal citation and DOI here once the publisher record is public.

The paper presents the complete theoretical development, the foundation structural model, the three numerical case studies with EPANET comparisons, and a class organization following the Understanding by Design framework. The supplemental material includes a detailed guide for the spreadsheet.

Download the PDF View on arXiv
@article{gomes2024xwhat,
  title   = {Modeling and Design Optimization of Looped Water
             Distribution Networks using MS Excel: Developing
             the Open-Source X-WHAT Model},
  author  = {Gomes Jr., Marcus N. and Benites, Igor M. and
             Elsherif, Salma M. and Taha, Ahmad F. and
             Giacomoni, Marcio H.},
  journal = {arXiv preprint arXiv:2405.09044},
  year    = {2024}
}