Modeling and Design Optimization of Looped Water Distribution Networks using MS Excel: Developing the Open-Source X-WHAT Model

[1]organization=University of São Paulo, Department of Hydraulic Engineering and Sanitation, São Carlos School of Engineering,
addressline=Av. Trab. São Carlense, 400 - Centro,
city=São Carlos,

state=São Paulo,

[2]organization=The University of Texas at San Antonio, College of Engineering and Integrated Design, School of Civil & Environmental Engineering and Construction Management,
addressline=One UTSA Circle, BSE 1.310,
city=San Antonio,

country=United States of America

[3]organization=Vanderbilt University, Department of Civil and Environmental Engineering,
addressline=24th Avenue South,

country=United States of America

1,2]Marcus Nóbrega Gomes Jr.

1]Igor Matheus Benites

3]Salma M. Elsherif

3]Ahmad F. Taha

2]Marcio H. Giacomoni

Cost-effective water distribution network design with acceptable pressure performance is crucial for the management of drinking water in cities. This paper presents a Microsoft Excel tool to model, simulate, and optimize water distribution networks with looped pipelines under steady-state incompressible flow simulations. Typically, the hardy-cross method is applied using spreadsheet calculations to estimate discharges. This method requires mass-conservative initial estimates and requires successive iterations to converge. In this paper, however, we develop an alternative method that uses the built-in solver capabilities of Excel, does not require initial mass-conservative estimation, and is free of flow corrections. The main objective of this paper is to develop an open-source accessible tool for simulating hydraulic networks also adapted for teaching and learning purposes. The governing equations and the mathematical basis for the hydraulic modeling of the system are mathematically described, considering the topology of the network, mass and energy conservation, cost of tank material, foundation, and cost of pumping energy to fill the tank. The use of this tool is encouraged at the undergraduate and graduate engineering levels, as it offers the opportunity to address complex concepts such as hydraulic modeling and network optimization in a comprehensive way using a spreadsheet that does not require coding expertise. Hence, users can debug all cells and understand all equations used in the hydraulic model, as well as modify them. To demonstrate the model capabilities, three practical examples are presented, with the first one solved step by step, and the results are compared with the EPANET and with the results reported in the literature. Using the optimization method presented in this paper, it was possible to achieve a cost reduction of 151,790 USD (9.8% of the total cost) in a network that supplies a 44,416 population. A detailed step-by-step guide on how to use the developed tool is presented in the supplemental material.

* We develop a hydraulic solver for water distribution networks using Excel

* The model does not require coding expertise and only uses built-in functions

* We apply the model to 3 different networks and compare results with EPANET and with reported results in the literature

* The optimization framework can identify optimal tank water depths, potentially resulting in cost reductions of approximately 10% compared to standard design procedure.

* The cost function used to optimize the design considers pipeline, pump, tank material, and tank foundation costs.

Looped Hydraulic Networks WDN Optimization Hardy Cross Method WDN Design WDN Spreadsheet

§ INTRODUCTION

Water distribution networks (WDNs) are essential infrastructure systems responsible for delivering water to residences, commercial establishments, and various other users. The efficient planning and effective design, operation, and maintenance of WDNs are critical to meet the growing demands of growing populations. Engineers and utility managers face the complex task of providing sustainable water resource management in WDNs that requires multiple factors, such as hydraulic performance and implementation and operation costs <cit.>.

Headloss/gain models are nonlinear, which complicates decision making and network optimization. To address this, the use of specific software and tools to aid in the design of WDNs is fundamental, especially with the advance of computational resources and optimization capabilities. Such modeling packages usually perform a variety of tasks related to the design (e.g., choosing optimal network diameters), modeling, sensitivity analysis, scenario simulation, and optimization of either operation and/or implementation of WDNs <cit.>. A wide variety of software, open source codes, and even Excel spreadsheets are available in the literature and are comprehensively described in Tab. <ref>. Most of the software options listed (7 out of 11) require a paid license, which can present accessibility challenges. Although these tools offer advanced functionalities and are capable of handling larger and more complex networks, they tend to be expensive and require extensive training. The research conducted in <cit.> states that the cost of selecting feasible and easy-to-use software is crucially important, especially in educational and research environments where multiple users can take advantage of the software package. Therefore, for smaller organizations, municipalities, or educational institutions, free or low-cost alternatives may provide feasible and sometimes more flexible solutions <cit.>.

Water Distribution Network modeling tools and software available

Main features
1cOptimization   features
Open Source
Base Platform
Development   Purpose
5*c]@c@WaterGEMS and
Platform interoperability, model Building, and data connection
Model calibration

Hydraulic, operations and water quality simulations
Identify leak locations

Great data presentation and visualization
Optimized design and rehabilitation

Optimization (using genetic algorithm)
Optimized pump scheduling

Energy and capital-cost analysis

4*Pipe Flow Expert
Intuitive user interface

Piping design and pipeline modeling system

2D and 3D isometric presentations

Robust calculation engine

Pipe 2022
CAD, GIS, Google Earth Import/Export/Background Images
Optimal Pump Scheduling

Powerful software package
Optimal Design Module (cost)

Optimization features
Optimized Calibration (based on filed test data)

Special Analyses and Network Types

Powerful and versatile application (Extensively tested and reliable)
Only   with third party plugins

Hydraulic and water quality simulation

Integration with different platforms

Extended period simulation

Open source and powerful simulation and modelling engine

5*c]@c@Urbano 11
Google Maps import and Digital Terrain Model features
Pipe diameter (through genetic algorithms)
5*Autodesk AutoCAD®

Drawing and editing CAD functions

Intersection analysis of pipe systems

Uses EPANET engine/libraries for hydraulic calculations

Trenches, cross sections, and excavation calculation

Analyzing existing water supply systems
AutoCAD® integration

Deficiency Identification and Correction

Uses EPANET engine/libraries for hydraulic and water quality analysis

Infrastructure Maintenance Management

Graphic Information System (GIS) Integration

5*InfoWater PRO
Pressure zone manager
Many options including energy use
5*c]@c@Esri ArcGIS

3*c]@l@(through genetic algorithms
particle swarm optimization)

Calculations and calibrations of pipes, pumps, valves, and water quality

Transient analysis

What-if scenarios

GIS Integration
Minimize capital expenditure

Simplified model building

Uses EPANET engine/libraries for for hydraulic calculations

Extended Period Time Simulation and Water Quality Modelling

Optimization Module

5*UFC System
5*c]@c@Free for universities
paid for companies
Complete package for designing WDNs
2*c]@l@Determine diameters to obtain the most
cost-effective network

Uses EPANET engine/libraries for hydraulic and water quality analysis

Compatibilisation of water, sewage, and drainage network projects

Generation of constructive drawings for tanks, trenches, and cross sections

Highly detailed quantification of materials and connections

5*WDNetXL System
Advanced and robust WDN hydraulic simulation distributed as MS-Excel® add-ins
Multi-objective genetic algorithm
5*Microsof Excel®

Topological analysis
Sizing of pipes and pumping system

Allocation of pressure  measurement devices

2*c]@l@Demand and pressure-driven analysis; Private local water storages;
Multi-floor buildings; Remote control of pressure reduction
Design of segments/modules

MATLAB environment that provides a programming interface with EPANET
4*c]@l@There are no built-in functions, but a wide range of
optimization tools available in the MATLAB
environment can be used

View, modify, simulate, and plot EPANET library results

Modular architecture allows to use of the functions in other Matlab   projects

Uses EPANET engine/libraries for hydraulic and water quality analysis

7l* WaterCAD is a   subset of WaterGEMS.

Research conducted in <cit.> and <cit.> argue that open-source software plays an important role in facilitating collaboration, promoting innovation, and providing accessible tools, which has implications for encouraging innovation in any field or industry. For instance, the Environmental Protection Agency Network Evaluation Tool (EPANET) <cit.> has been a critical asset in the modeling of WDNs for more than two decades. Its importance lies in its accessibility and powerful capabilities. As an open-source tool, it is freely available, making it a valuable resource not only for regular users but also for advanced users who can use the open-source availability to adapt to more complex scenarios and simulations. Several other free and paid software tools use the EPANET Engine/Libraries Toolkit to perform hydraulic and water quality calculations (see Table <ref>).

In terms of development platform, commercial software options consist of either a proprietary standalone platform or integration with Autodesk AutoCAD. Among the three open source tools listed in Tab. <ref>, one uses the Microsoft Excel environment <cit.> while another uses the MATLAB environment <cit.>. The study developed in <cit.> presents an open-source software connecting MATLAB to EPANET, in an intuitive and relatively easy-to-use way. The Toolkit allows the user to access EPANET through their shared object libraries, as well as their executables. In summary, their application provides a programming interface with EPANET directly from the MATLAB environment, where it is possible to visualize, modify, and plot results from the EPANET library. Furthermore, its modular architecture makes it possible to use the functions in other MATLAB projects.

Another example is the WDNetXL that is developed in <cit.>. It is an advanced tool that uses MS-Excel add-ins for WDNs analysis including hydraulic simulation, valve system analysis, pipe failure scenarios, optimal pipe sizing, and optimal valve system design. Although listed as free in Tab. <ref>, the software is no longer available in their website to the date of this paper. Several studies have shown that Excel-based tools can be effective in conveying complex hydraulic concepts and principles in an easy-to-understand comprehensive way. For instance, the study conducted in <cit.> has shown that Excel is useful in analyzing WDNs and can help students understand the fundamental concepts and principles of hydraulic network analysis and design. Similarly, another study presented in <cit.> proposes a method of using Excel for WDNs analysis based on linear theory, highlighting its accessibility and efficiency in teaching and learning. Furthermore, authors in <cit.> emphasize Excel's role in introducing students to concepts in thermodynamics and hydraulic engineering. Their results show the performance of Excel as an alternative tool to simulate relatively complex problems, not only for solving real-world problems but also for educational purposes.

Other studies have addressed similar issues. However, they have focused on the use of Excel solver for analysis of WDNs. Research conducted in <cit.> demonstrates the effectiveness of using the Hardy-Cross <cit.> method with the solver to estimate pipe flow. They present an example of a network with a single loop, demonstrating how efficiently the solver optimizes flow correction factors for a relatively small WDN. In addition, <cit.> uses the solver and a studio classroom setting to teach hydraulic design for water distribution systems and open channel flow and has concluded that these tools can improve student learning and engagement. Research presented in <cit.> recommends Microsoft Excel Solver as an optimal approach to solving linear equations in pipe network analysis. Furthermore, <cit.> presents a Visual Basic Application (VBA) that implements the Hardy-Cross algorithm to solve a given WDN by balancing head losses in a looped network system. In addition, the study <cit.> shows an MS Excel tool, called YTUSU, developed for teaching hydraulic analysis and aiding the design of water distribution networks in environmental engineering education. However, these studies exclusively use the Hardy Cross method within an Excel environment. In other words, they manually implement it through a trial-and-error approach rather than providing a dedicated tool or software solution.

It is noteworthy that several studies <cit.> have explored performing these calculations using tools beyond Excel, including programming languages like MATLAB and C#. Excel is a powerful software that is widely used in different applications. It serves a multitude of functions, including basic calculations, data analysis, design, and visualization. Using Excel to model and optimize WDNs has several advantages. First, it is a cost-effective tool. Second, its user-friendly interface ensures accessibility to individuals, including students and engineers, with limited programming experience. Third, its license cost is relatively low compared to dedicated commercial WDN design software and users can utilize Excel for a variety of other applications rather than just hydraulic simulation, making the license cost virtually negligible.

§.§ Paper objectives and Contributions

As seen above, several studies have explored the use of Excel and MATLAB to model and analyze WDNs. However, most of these studies focus only on the implementation of the Hardy-Cross algorithm in these environments that require successive iterations and initial mass-conservative flow estimations in all network nodes. In addition, currently, there is no publicly available tool in Excel that offers a rapid and easy-to-access tool for hydraulic simulation and preliminary design of WDNs, whether for applying it in classroom examples or in real-world case studies. Therefore, this paper introduces a new Microsoft Excel tool that can be used to design, simulate, and optimize tank design used to provide water to water distribution networks under a variety of network topology and boundary conditions.

The fundamental contributions of this paper are:

* We developed an open-source model, the Excel for Water system Hydraulic Analysis Tool  (X-WHAT) to aid in the simulation and design of WDNs.

* We develop a novel WDN cost function that considers more realistic factors rather than just the hydraulic features of the WDN, such as pipeline costs, pumping costs associated with filling the tanks, and tank material and foundation costs.

* The foundation cost function used in this paper considers structural design factors, such as lateral non-linear wind forces, for ground and elevated tanks.

* The methodology presented in the numerical model herein developed merges fundamental concepts of hydraulics and structural design, allowing an interdisciplinary application for teaching in engineering classes.

* The methods presented in this paper are solved in a simple Excel spreadsheet, without requiring any other software package, and do not require coding expertise since the model uses only built-in Excel functions.

The remainder of the paper is structured into five sections. Section <ref> presents the fundamental equations used in the model, including the conservation of mass in junctions, tanks, tanks, and pumps. In addition, it details the methods to compute the conservation of energy in loops. The estimation of the forces acting on the foundation and the function describing the foundation cost is also explained in this section. Finally, two optimization problems are formulated to deal with the problem of finding flows in a given WDN and optimizing the tanks design given a set of constraints. Section <ref> presents three numerical case studies where the methods and the developed tool are applied. Section <ref> and Section <ref> present the results and discussion, respectively. Finally, Section <ref> presents the conclusions of the paper.

§ MATERIALS AND METHODS

In this section, we provide a brief introduction and explanation of the governing equations, conservation laws, methods, and materials used to build our models and obtain the subsequent results.

§.§ WDNs Components and Topology

The main elements of the pressurized looped hydraulic networks under steady-state flow distribution of an incompressible fluid are the nodes and links. Nodes include tanks, junctions, and tanks, while links include pipes, pumps, and valves. They can have known boundary conditions, such as observed heads of and flows. A junction connects two or more links and is defined by an elevation value from a reference datum. For the steady-state simulation, tanks and tanks are assumed to have a fixed piezometric pressure (known or optimized in the algorithm), such that their levels are assumed to be constant. Therefore, for the sake of the WDN hydraulic simulation, tanks or tanks are defined by their piezometric head at their surface. Tanks are storage elements with changing volumes and heads but since we are only modeling the steady-state case for the so-called design conditions, tanks can also be assumed with a fixed head that could represent a critical condition for the tank.

In addition, a pipe is a conveying element having a constant slope and is defined by the pipe diameter ($D$), pipe length ($L$), and friction properties that are later defined in the following sections. The pump elements, as well as valves, can be used to control the network dynamics <cit.>. However, in this paper, pumps are only considered to be connected to tanks or tanks to fill them up to the required level. Therefore, for a given tank or tank known head, the pumps do not alter the network dynamics; nonetheless, the pump energy costs are associated with the tank heads, which ultimately are directly connected to the network performance to maintain acceptable heads, velocities, and pressures. The smaller the designed tank head, the lower the pump energy costs; however, the higher the chances of having a storage node that provides the minimum required pressure in the network.

In this paper, and in the models developed herein, we focus only on junctions, links, tanks, and pumps. We assume that the valves are fully open and we neglect the minor losses in the network. Moreover, we do not attempt to use pumps as a controlling factor of network dynamics; rather, we consider the pumps to calculate the associated energy costs that influence the overall cost design optimization of the whole network. The notation used in the paper to describe the network components is shown in Fig. <ref>.

Notation used in the paper for describing the WDNs Components. Nodes and links are continuous numbered. Loops follow the clockwise convection. Nodes, tanks, and pumps are defined by their topographic elevation. Tanks have their dynamic pressure defined by $P_{\mr{r}}/\gamma$.

§.§ Conservation Laws

WDNs are governed by laws of conservation of mass and energy, described in this section.

§.§.§ Conservation of Mass

The principle of mass conservation ensures that the continuity equation is satisfied for all nodes; the change in storage is null (i.e., steady-state) and is equal to the algebraic difference between the inflows and outflows.

Junctions They are considered elements with no storage volume connecting one or more links and allow direct demand withdraws from them.
The conservation of mass for junctions is expressed as:

\begin{equation}~\label{equ:JuncMass}
\sum_{k = 1}^{n_k}  Q_{\mr{in}}^{i} - \sum_{m = 1}^{n_m} Q_{\mr{o}}^{i} - Q_\mathrm{d}^i = 0,~\text{For junctions from i = 1, 2, $\cdots$ $n_d$}
\end{equation}

where $Q_{\mr{i}}$ are the inflows and $Q_{\mr{o}}$ the outflows. The counters $n_k$ and $n_m$ represent the number of pipes entering and leaving the node $i$. The demands in each junction are given by $q_\mathrm{d}$ where positive values represent water consumption in the network.

Reservoirs They are assumed to be an infinite source of water with fixed heads, $h_\mathrm{r} = \mathrm{constant}$. However, in a design optimization simulation, $h_{\mr{r}}$ can be estimated to minimize network costs.

Tanks Although tanks can have a varying water depth under unsteady state simulations, since we are only modeling the steady-state dynamics, we consider a fixed head in tanks. From now on, tanks and reservoirs are considered interchangeably.

Pumping Flow Rate
Although all the equations developed in this paper are defined for a steady-state case where demands and supply are equal, the pumping flow rates are different from the supply released by the tank in the WDN simulation. The hour factor in the demand ($k_2$), as well as the duration at which the pumps work ($n_p$) are considered to calculate the pump flow rate ($Q_{\mr{p,r}}$), which can be calculated as:

\begin{equation} \label{equ:pump_flow}
Q^i_{\mr{p,r}} = \frac{Q^i_d}{k_2}\Bigl (\frac{n_{\mr{WDN}}}{n^i_{\mr{p}}} \Bigr),~\text{For tanks/reservoirs from $i = 1, 2, \cdots n_{\mr{r}}$}
\end{equation}

where $Q_d$ is the tank outflow rate, $n_{\mr{WDN}}$ is the duration per day ($\leq 24~\mr{h}$) that the water distribution network is operating (i.e., typically 24 h) and $k_2$ is a statistical factor related to the average demand with the maximum expected demand, herein assumed as 1.5.

§.§.§ Conservation of Energy

Conservation of energy over links is classified into two main principles, energy loss and energy gain. Energy loss is either due to friction loss distributed over pipes' length or localized at sources of change (e.g., valves and bends). In our paper, we neglect the effect of the localized energy losses and convert valves' losses into equivalent friction losses <cit.>. On another hand, energy gain is provided by pumps—more details on pumps operation are briefly explained in the following sections.

Head Loss
Head loss models are non-linear functions dependent of the flow discharge in a pipe $(q_o^i)$ due to the friction between the fluid and the walls of the conduit. The discharge in a pipe is now denoted by $Q$. The friction loss equation can be expressed as:

\begin{equation} \label{equ:friction_model}
\Delta h_f = k Q | Q |^ {n-1}
\end{equation}

where $\Delta h_f$ is the head drop due to friction losses, $k$ is a term dependent on the link properties such as diameter, length, and rugosity. The exponent $n$ is a parameter that depends on the friction model used, and $Q$ is the flow rate in the link. Minor losses in junctions are not considered. In the following sections, we introduce two friction models and the corresponding derivation of $k$ and $n$.

– Darcy-Weisbach (D-W) Friction Model.
The physically-based head loss model of Darcy-Weisbach is given by

\begin{equation} \label{equ:D_W}
\Delta h_f \Big|_\text{D-W} = \frac{fLv^2}{2gD},
\end{equation}

where $f$ is the friction factor, $v$ is the average flow velocity in the pipe, $D$ and $L$ are the pipe's diameter and length, and $g$ is the gravity acceleration.

Rearranging Eq. (<ref>) following Eq. (<ref>) and using $v = Q/(\pi D^ 2/ 4)$, we can derive that:

\begin{equation}~\label{equ:kDW}
k \Big|_\text{D-W} = \frac{8 f L}{D^5 \pi^2 g},\; ~ n = 2.
\end{equation}

Several formulations for the friction factor are available in the literature. Some of them are implicit; others are limited in terms of the Reynolds number (Re), such as the Swamee-Jain formulation <cit.>. A more recent formulation, however, allows an explicit and not bounded by Reynolds number and can be written as <cit.>:

\begin{equation} \label{equ:friction_factor}
f=\Bigg(\left(\frac{64}{\mathrm{Re}}\right)^8+9.5\left[\operatorname{ln}\left(\frac{\epsilon}{3.7 D}+\frac{5,74}{\mathrm{Re}^{0.9}}\right)-\left(\frac{2500}{\mathrm{Re}}\right)\right]^{-16}\Bigg)^{0.125}.
\end{equation}

where $\epsilon$ is the length of the rugosity and $D$ is the diameter. $Re$ is the Reynolds number, defined by $Re = \frac{v D}{\nu}$, where $v$ is the flow velocity and $\nu$ the kinematic viscosity.

– Hazzen-Willians (H-W) Friction Model.
The Hazzen-William equation is considered an empirical model, where $k$ and $n$ in Eq. (<ref>) are expressed as:

\begin{equation}~\label{equ:kHW}
k \Big|_\text{H-W} = \frac{10.67}{C^{1.85}D^{4.87}},\; ~ n = 1.85,
\end{equation}

where $C$ is the H-W friction coefficient and depends on the material of the pipe.

Node Pressures
Within 2 consecutive nodes (i.e., a link), we can apply the Bernoulli's equation to determine the heads in each node such that:

\begin{equation}
h_{\mr i} - h_{\mr j}  =  k_{{f}}^{\mr l} |Q_{\mr l}| Q_{\mr l}^{n-1},~\text{For all links from $i$ = 1,~2,$\cdots$,~$n_l$}
\end{equation}

where $h_{\mr i}$ and $h_{\mr j}$ := ($P/\gamma + z)$ are the piezometric heads at nodes $i$ and $j$

The pressures heads of the nodes can hence be calculated by subtracting the elevation level ($z$) from the head.

Head Gain
Each WDN has its unique topology and layout. Although pumps can actively change the WDN dynamics by adding pressure head to the nodes, in this paper, we only consider pumps that provide water to tanks. The network is driven by the gravitational gradients from the tank that are filled by pumps. Therefore, pumping in our model, does not change the pressure and flow dynamics in the network; however, they influence the overall cost of the network, especially if relatively high manometric pressures are required to pump the water into the tanks. A schematic of the pump system to provide water to tanks is shown in Fig. <ref>

Pump to tank scheme, where the manometric head gain $H_{\mr{m}}$ is calculated accounting for the head losses in the pipe and the geometric differences within the pump level ($z_{\mr{p}}$) and the bottom of the tank $z_{\mr{b}}$.

The pumps have a manometric pressure $H_{m}^p$ and a friction coefficient $k^p$. The manometric head gain $(H_{\mr{p}})$ can be calculated considering the pump elevation $(z_{\mr{p}})$, the geometric elevation within the pump and the tank ($h_{\mr{g}}$), and accounting for the linear friction loss in the pipe connecting the pump and the tank, such that:

\begin{equation}
H_{\mr{p}} = h_{\mr{g}} + k^p Q_{\mr{p,r}} \abs{Q_{\mr{p,r}}}^{n-1}
\end{equation}

Note that the geometric elevation within the pump and the tank plus the pressure head at the entrance of the tank ($h_{\mr{g}}$) depends on the tank head ($h_{\mr{r}}$) and is calculated as $h_{\mr{g}} = h_{\mr{r}} + (z_b - z_{\mr{p}})$.

§.§.§ Loop Energy Conservation

Let $c$ be the number of loops in the network system. Given a junction $i$, the sum of all head losses within the network returning to node $i$ must be zero to maintain energy conservation. Each loop in the network results in one conservation of energy equation. For given loop $v$ containing $m$ pipes defined by $v_1,~v_2, \cdots v_m$ , and assuming an arbitrary flow convention (e.g., clockwise), one can assign which pipes are in the expected flow direction or not by the signal of the flow discharge, resulting in the energy conservation at loop $v$ as follows:

\begin{equation}
k_{v_1} Q_{v_1} |Q_{v_1}|^{n-1} + k_{v_2} Q_{v_2} |Q_{v_2}|^{n-1} \cdots + k_{v_m} Q_{v_m} |Q_{v_m}|^{n-1} = 0
\end{equation}

Expanding for $\mathcal{L}$ loops, the equations can be rearranged in a non-linear system of equations summarized in vector form as:

\begin{equation} \label{equ:energy_conservation}
0=\sum_{i = 1}^{m_{v}}k_{{v_i}} Q_{v_i}\left|Q_{v_i} \right|^{n-1},~\text{For all loops from $v = 1$ to ${c}$}
\end{equation}

where $m_{v}$ is the number of pipes in loop $v$.

Eq. (<ref>) can be solved in state-space format by having a topologic matrix that collects the pipes (i.e., columns) in terms of each loop (i.e., rows), with a value of 1 given for flows following the clockwise convention, 0 for pipes that do not belong to the loop, and -1 for pipes that follow the convention.

§.§ Incidence Matrices

The topology of the problem relates pipes and nodes by defining two representative matrices: $\m F_d$ and $\mF_l$. The matrix $\m F_d$ represents the connection of every node with respect to the links, such that:

\begin{equation}
{\mathbf{F}}_{d}(i, j)= \begin{cases}-1 & \text { if pipe } j \text { leaves juntion } i \\ 0 & \text { if pipe } j \text { is not connected to juntion } i \\ +1 & \text { if pipe } j \text { enters juntion } i\end{cases}
\end{equation}

By multiplying this matrix with the decision vector for discharges $\m q$ and subtracting by the node demands $\m d$, we define the first constraint to the problem, given in Eq. (<ref>).

The other matrix required to solve the fundamental conservation equations is the loop incidence matrix ($\m F_l$), given by:

\begin{equation}
\mathbf{F}_{l}(i, j)= \begin{cases}-1 & \text { if pipe } j \text { is in loop } i \text { and their directions are opposed } \\ 0 & \text { if pipe } j \text { is notin loop } i \\ +1 & \text { if pipe } j \text { is in loop } i \text { and their directions }\end{cases}
\end{equation}

Using $\m F_l$ and the flow discharges $\m q$, we solve the energy conservation in all loops given by Eq. (<ref>).

§.§ Cost Functions

Typically, studies developing optimization techniques to enhance the design of WDN consider only the pipeline costs. In this paper, we include three new associated costs, in addition to the pipeline costs, to define the overall WDN cost: the tank material, the tank foundation, and the pumping energy costs. The functions to calculate these costs are described in this section.

§.§.§ Tank Costs

Tank Material
The tank material cost is composed of the lateral, bottom, and top areas, and is a function of the cost of the tank material, given by:

\begin{equation} \label{equ:reservoir_material}
C_{\mr r}^{\mr m} = c_\mr{m} \Bigl(\pi D_{\mr r}(D_{\mr r}^2/2+h_{\mr r})\Bigr)
\end{equation}

where $c_{\mr{m}}$ [$\mr{USD} \cdot \mr{L}^{-2}$] is the cost per square unit of the tank material.

Tank Foundation
A simplified schematic representation of the forces acting on the lateral surface of the tank is presented in Fig. <ref>. Other forces, rather than the lateral wind forces acting at the tank, can also be important, such as the hydrostatic pressure against the wind direction, which would reduce the foundation bending moment and the weight of the pillars, resulting in a more complex formulation for an explicit cost definition. Herein we attempt to focus on the most important one, which, for elevated tanks, is the wind forces acting at the lateral surface of the tank. The bending moment at the foundation is derived, neglecting the reducing effect of the hydrostatic pressure. The resulting general spandrel formulation is:

\begin{equation}
M_{\mr r} = \frac{1}{2}\pi D_{\mr r} k_{\mr w}\Bigl[\frac{(h_{\mr b}+ h_{\mr r})^{p+2}-h_{\mr b}^{p+2}}{p+2} \Bigr]
\end{equation}

where $k_{\mr w}$ is the wind dynamic drag coefficient [$\mr{F\cdot L^{-(2+p)}}$] that depends on the air density, the expected wind speed and $p$ is an exponent that increases with the topographic elevation and can be estimated in terms of the wind speed $v_{\mr w}$, such that $k_{\mr w} = 0.613\frac{0.75^2 \mr{v}_{\mr w}^2}{10^p}$, with $v_{\mr k}$ in [$\mr{m}\cdot \mr s^{-1}$] and $k_{\mr w}$ in [$\mr{N}\cdot \mr{m}^{-(2+p)}$]. Values of p vary between 0.12 to 0.035 with mean values around 0.20, and they shape the curvature of the lateral forces in the tank, as shown in Fig. <ref>. For a wind velocity of $\mr{40}~\mr{m\cdot s^{-1}}$ and $p = 0.30$, $k_{\mr w} = 348~\mr{N}\cdot \mr{m}^{-2.3}$

Static representation of the lateral forces acting in the tank surface, where (a) shows the lateral forces acting in the tank. The hydrodynamic force is modeled through $k_{\mathrm{w}} (h_b + h)^p$, with $k_{\mr w}$ being wind drag coefficient [$\mr{F}\cdot \mr{L}^{-1(2+p)}$], resulting in a force per unit elevation [$\mr{F}\cdot \mr{L}^{-1}$]. This force is integrated to produce $F_{\mr w}$ that represents the total force per unit of tank width that if multiplied by the diameter of the tank, gives the total lateral force at the foundation. This lateral force can be used with the lever arm $r_c$ to calculate the bending moment at the foundation. Alternatively, the total bending moment using static moment formulation is presented in (b), where $M_{\mr r}$ is the total bending moment projected at the tank lateral surface as a function of the tank diameter and pressures. At the foundation level, the normal force is the tank weight, and the horizontal force equals $F_{\mr k}$. The variable $r_c$ is the lever arm and $\gamma_{\mr{H_2O}}$ is the specific weight of the water..

We run a structural reinforced concrete footing model to calculate the concrete and rebar costs for different values of tank volume, height, and elevation. Effects such as tipping, sliding, and concrete shear resistance are considered, and the minimum cost design is searched. Details of the foundation model can be found in the supplemental material. We assume that the cost of the foundation is a function of the forces and bending moments at the surface of the foundation, such that:

\begin{equation} \label{equ:foundation_costs}
C_{\mr f}^{\mr r} = \alpha_1 V_r^{\beta_1} + \alpha_2 M_k^{\beta_2} + \alpha_3 H_k^{\beta_3}
\end{equation}

where all parameters are fitted using a dataset of varied values of strengths. The results of the varied simulation tested (each strength value from 10, 100, 1000 $\mr{kN}$ or $\mr{kN.m}$) are shown in Fig. <ref> and the parameters in equation (<ref>).

Foundation cost model in comparison with a regression model, where a structural foundation model was run for combinations of 10, 100, and 1000 $\mr{m^3}$, $\mr{kN.m}$, or $\mr{kN}$ of tank volume, lateral bending moment, and horizontal wind force. The regression parameters of Eq. (<ref>) are presented in the figure.

Tank Total Cost

The total tank cost is the sum of the material cost (Eq. (<ref>)) and the foundation cost (Eq. (<ref>)):

\begin{equation} \label{equ:reservoir_cost}
C_{\mr r}(V_{\mr r},z_{\mr b}, h_{\mr r}) = C_{\mr r}^{\mr m}(V_{\mr r},~h_{\mr r}) + C_{\mr{r}}^{\mr f}(V_{\mr r},h_{\mr b},h_{\mr r})
\end{equation}

where $C_{\mr r}^{\mr f}$ is the foundation cost.

In WDNs with only one tank, the total water demand is only from it. However, in networks with more than one tank, a decision is made to distribute the volumes of the tank based on zonation studies such that each tank would make available a percentage of the total volume. Alternatively, a linear relationship between the water heads or water volumes of the tanks can be used in the design <cit.>.

To solve Eq. (<ref>), we can derive a relationship between $D_{\mr r}$ and $h_{\mr r}$ by using the tank volume and use this relationship to reduce the number of decision variables in the problem. The tank volume is typically defined by local regulations. In this paper, we assume the tank volumes as 1/3 of the total demanded volume on the day of the highest demand within the period ($V^i_{\mr r} = 1/3 k_1 \sum d^i 86400$), thus, for a given tank depth $h_{\mr r}$, the diameter is:

\begin{equation}
D_{\mr r} = \sqrt{\frac{4 V_{\mr r}}{\pi h_{\mr r}}}
\end{equation}

where the tank volume $V_{\mr r}$ is calculated with the demanded volume of the tank within one day.

§.§.§ Pump Energy Cost

The pumping energy cost depends on the pump gain, the average daily duration that the pump is operated, the cost of kWh of energy, and  the pump efficiency, such that:

\begin{equation} \label{equ:daily_energy_pump}
C_e = P_e \overbrace{\frac{H_{\mr{p}} Q_{\mathrm{p,r}} \gamma n_h} {\eta_{\mr{p}}}}^{E_{\mr{p}}}
\end{equation}

where $C_e$ is the daily cost of energy, $P_e$ is the average energy cost ($\mr{USD/kWh}$), $\eta_h$ is the pump daily number of working hours, $\eta_{\mr{p}}$ is the pump efficiency, and $E_{\mr{p}}$ is the pump daily energy consumption ($\mr{kWh}$).

The pump energy cost, as opposed to the pipeline cost and tank cost, which are capital investments, is charged throughout the years. We can define the pump energy cost in terms of the net present value. To this end, the useful life of the network ($n_l$) and the interest rate ($i_{\mr{r}}$) of the project, as well as the annual increase rate in the energy price ($i_e$) are considered to calculate the net present value (NPV) of the pumping energy, such that the conversion rate is given by:

\begin{equation}
{\left[\frac{1-\left(1+i_e\right)^{n_{\mr l}}\left(1+i_{\mr{r}}\right)^{-n_l}}{i_{\mr{r}}-i_e}\right]} & \text { if } i_{\mr{r}} \neq i_e \\
{\left[\frac{n_l}{1+i_{\mr{r}}}\right]} & \text { if } i_{\mr{r}}=i_e
\end{array}\right.
\end{equation}

where $I_{\mr{NPV}}$ [$\mr{year^{-1}}$] converts the total annual energy costs during the lifespan ($E_a$) into a present value that can be summed with the network implementation costs. One can estimate the annual energy cost by multiplying $C_e$ (i.e., the daily pumping cost from Eq. (<ref>)) by 365 days, such that the pump net present value cost ($C_{\mr{p}}$) is:

\begin{equation} \label{equ:pump_cost}
C_{\mr{p}} = I_{\mr{NPV}} C_e \times 365
\end{equation}

§.§.§ Pipeline Cost

The implementation cost of pipelines is typically a function of the pipe diameters. We approximate the pipeline costs using a high-degree polynomial equation <cit.> (i.e., herein we assume a 7-order polynomial), expressing the pipeline cost as:

\begin{equation} \label{equ:pipeline_cost}
C_l(D) = \sum_{s = 1}^{n_d} \alpha_l D^{s}
\end{equation}

where $\alpha_l$ are the least square fit parameters that can be derived in Excel using functions such as $\mathtt{LINEST}$.

§.§ WDN Overall Cost

Combining Eq. (<ref>), Eq. (<ref>), and Eq. (<ref>) we can define the design optimization cost function given by:

\begin{equation} \label{equ:overall_cost}
C_t = \sum_{i = 1}^{n_l} L_i C_l + \sum_{j = 1}^{n_{\mr{p}}} C_{\mr{p}}^j  + \sum_{k = 1}^{n_{\mr{r}}} C_{\mr{r}}^k
\end{equation}

where $C_t$ is the total net present value of the network, $L_i$ is the pipeline length for link $i$, $n_l$ is the number of links, $n_{\mr{p}}$ is the number of pumps, assumed equals the number of tanks $n_{\mr{r}}$, and $h_{\mr{r}}$ is the tank head.

§.§ Water Flow Problem (WFP)

Two problems are formulated. The first problem (WDN Water Flow Problem) is a hydraulic simulation of a given network with known pipe diameters and tank boundary conditions and consists of finding the discharges and flow directions <cit.>. This problem doesn't require an objective function and the solution to this problem is a vector that satisfies a system of linear and non-linear equations. This problem is relatively less complex to solve in classes, as opposed to typical approaches that use the Hardy-Cross method, because it doesn't require an initial, mass-balance conservative, estimations of the flows in all pipes, which can be time-consuming  <cit.>. The lack of mass-conservative initial values is a major advantage of using a matrix-wise formulation approach via optimization, although mass-conservation solutions are desired to accelerate gradient-based solvers.

The second problem (WDN Design Optimization Modeling) is, for a given network with known diameters, to find not only the correct flow discharges that satisfy energy and mass conservation laws but also minimize the network's overall costs while being constrained by maximum and minimum pressure boundaries. This problem is more oriented toward a real-world engineering application as it uses hydraulic simulation as a tool to find cost-effective solutions. Following, the two problems are mathematically described.

WDP Water Flow Problem
This problem is mathematically written as:

[Water Flow Problem]

\begin{equation} \label{equ:opt_problem_hydraulics}
\begin{array}{llr}
{\mbox{find}} & \m{q} \\
\mbox{subject to} & \m F_{\mr d} \m q - \m d = \m 0, & ~~~~~~\textit{Mass Conservation}\\
& \m F_{\mr l} \m q = \m 0, & ~~~~~~~~~~~~\textit{Energy Conservation}\\
& \m q \in \mathbb{R}^n,~\m F_d \in \mathbb{R}^n \times \mathbb{R}^{n_{\mr{p}}},~\m F_l \in \mathbb{R}^n \times \mathbb{R}^{n_l}, \m d \in \mathbb{R}^n\\
\end{array}
\end{equation}

and determines the flow discharges such that the energy and mass balance are satisfied. This problem is non-convex, non-smooth, and non-linear due to the friction losses.

WDN Design Optimization Modeling (DOM)
The decision variables for this problem are the flows $\m q$, the tank heads $\m h_{\mr{r}}$, and the height of the tanks ($\m h_{\mr b}$). All pipes are constrained by a minimum ($\m p_{\mr{min}}$) and maximum ($\m p_{\mr{max}}$) pressure. For the cases of designing the pipe diameters altogether while satisfying mass and energy constraints, a new constraint in the flow velocities would also be required to allow minimum and maximum values. This problem, however, is untractable to solve with simple gradient solvers available in Excel and is hence outside of the scope of this paper. The objective function of the problem is the network net present value that considers the pipeline costs, the pump energy costs, and the tank costs such that the network can deliver acceptable flow pressures while having a reduced overall cost. This problem is stated in Eq. (<ref>).

[WDN Design Optimization Modeling]

\begin{equation} \label{equ:design_optimization}
\begin{array}{ll}
\underset{\m q, \m h_{\mr{r}},\m z_{\mr b}}{\mbox{minimize}} & \text{Eq}.~\eqref{equ:overall_cost} \\
\mbox{subject to} & \m F_{\mr d} \m q - \m d = \m 0,  ~~~~~~\textit{Mass Conservation}\\
& \m F_{\mr l} \m q = \m 0,  ~~~~~~~~~~~~\textit{Energy Conservation}\\
& \m p_{\mr{min}} \leq \m p \leq \m p_{\mr{max}} \\
& \m h_{r_{\mr{min}}} \leq \m h_{\mr{r}} \leq \m h_{r_{\mr{max}}} \\
& \m 0 \leq \m z_{\mr b} + \m h_{\mr{r}} - \m z_{\mr r} \leq \m z_{\mr{max}} \\
& \m q \in \mathbb{R}^n, \m d \in \mathbb{R}^n, \m q \in \mathbb{R}^{n_{\mr d}},
\m p \in \mathbb{R}^{n_{\mr d}},
\m h_{\mr r} \in \mathbb{R}^{n_{\mr r}},
\m z_{\mr b} \in \mathbb{R}^{n_{\mr r}}, \\
& \m F_d \in \mathbb{R}^n \times \mathbb{R}^{n_{\mr{p}}}, \m F_l \in \mathbb{R}^n \times \mathbb{R}^{n_l},\\

\end{array}
\end{equation}

§.§ Excel Framework and data entry

Excel WDN Sheet - X-WHAT.xlsx
In this section, we describe the Looped Hydraulic Network simple Excel sheet used to solve WDN problems using Excel solvers. Only Microsoft Excel is required to run the model; although other solvers can be coupled with the network model, such as Open Solver <cit.>. Users can define solver properties such as using Multi-Start points to test the objective function from multiple initial points of the decision space, hence increasing the chances, although not guaranteeing, of finding the global optima. In addition, users can define a different cost function that can represent other quantities that are not monetary costs, such as the average pressure in the network.

General data entry flowchart. No macros or VBA coding are required to run the model. Boundary conditions can be specified for nodes where the pressure is known.

The data entry procedure is systematic and involves three sheets: Main, Mass Balance, and Energy Balance. Fig. <ref> outlines the general steps for entering all necessary information. The process can be divided into five main sections, with the first section on the main sheet dedicated to setting the model parameters listed in Tab. <ref>. Note that it is not mandatory to fill in all the parameters listed.  The essential parameters vary depending on the analysis to be performed.  For example, for a basic hydraulic simulation that is typically addressed in a classroom environment, only the first six parameters are required.

Required Parameters     3cDescription
D-W or H-W              Head loss method (H-W: Hazen-Williams; D-W: Darcy-Weisbach)                             6*90WFP             17*90DOM

$\nu$                       Represents the kinematic viscosity of the fluid in $\mr{m^2 \cdot s^{-1}}$

$\rho$                       Represents the density of the fluid, measured in kg/m³.

Links                   Indicates the total number of links within the hydraulic network.

Nodes                   Refers to the total number of nodes or junction points within the network.

Loops                   Indicates the total number of loops within the hydraulic network.
$P_c$                      2lStands for the cost per kilowatt-hour (kWh) of energy in USD/kWh.

$i_r$                      2lRepresents the annual increase rate in energy costs, expressed as a percentage.

Years                   2lIndicates the lifespan of the system being analyzed, measured in years.

Rate              2lRefers to the interest rate applicable to investments or loans related to the project, expressed as a percentage.

$\alpha$                 2lRepresents the operational cost rate associated with maintenance and operation expenses over time; it’s expressed as a percentage.

$k_1$                      2lThe day factor used for calculations related to daily operations or impacts within the system.

$k_2$                      2lThe hour factor, similar to k1 but applied on an hourly basis for more granular analysis.

$D_{tr}$               2lDuration to fill the reservoir, indicating the time required (in days) to completely fill up storage reservoirs within the system.

Material Cost     2lRefers to the cost per cubic meter (USD/m³) associated with materials required for construction of the reservoirs.

$V_k$                2lWind speed velocity (m/s) used to calculate mechanical stresses on structures exposed above the surface level (reservoirs).

$p$                 2lp is an exponent that increases with the topographic elevation and can be estimated in terms of the wind speed

Model parameters required according to the type of analysis to be performed.

In the second section, the network node parameters and boundary conditions are defined. Each node must have its ground elevation specified, along with the identification of whether it is a manhole or a tank. Pumps are included in the analysis by entering information such as daily operating hours, efficiency, ground elevation, and linear head loss coefficient. Tank specifications, including elevation and height above ground, must be provided. However, the height above the ground can also be included as a decision variable in the optimization design modeling (DOM). Furthermore, demands for each network node are defined by specifying whether flows enter or leave a node. Boundary conditions are defined specifying whether a node has a fixed head or not. When the type of node is designated as a tank, it requires a fixed head.

Following the specification of the node parameters, the third section should be used to enter detailed information on the links. For each link in the network, the upstream and downstream nodes must be specified, as well as the pipe length and diameter.

Sections four and five involve completing the mass and energy balance incidence matrices. The mass-balance sheet includes the mass balance incidence matrix ($F_d$) for carrying out the mass balance calculation, while the energy-balance sheet requires completion of the energy balance incidence matrix ($F_l$). The order of completion is not mandatory. More details of how to enter the input data in the file are presented in the supplemental material.

After completing the data entry process through the Main, Mass-Balance, and Energy-Balance sheets, users can proceed to perform the desired analysis using the Excel Solver. In WFP, the objective is to determine the correct discharges and flow directions based on the principles of mass and energy conservation as described in Eq. (<ref>). Users may also choose a DOM approach which usually involves minimizing the cost function as described in Eq. (<ref>). However, different analyses can be performed depending on the design parameters to be optimized.

Once the analysis is complete, the results are presented in both tabular and graphical formats. Additional information on potential analyses can be found in Section 3 - Numerical Case Studies.

§.§.§ Mean Average Error Metric

To  compare the modeling results from the spreadsheet with EPANET or with available solutions in published literature, we use the mean absolute error (MAE), written as:

\begin{equation} \label{equ:MAE}
\mr{MAE} = \frac{\sum_{i=1}^n\left|x_{\mr m}-x_{\mr{obs}}\right|}{n}
\end{equation}

where $n$ is the number of observations, $x_{\mr m}$ is the modeled state and $x_{\mr{obs}}$ is the observed or truth-based state. This metric is applied for head pressures in all nodes and flow discharges in all links and the units are the same as the state evaluated.

§ NUMERICAL CASE STUDIES

In this section we detail the case studies used to test the model developed. We choose three different testing cases (a), (b), and (c), with increasing complexity. For all tested cases, a lifespan ($n_\mr{l}$) of 25 years, $i_{\mr{r}} = 12\%$, and $i_{\mr e} = 6\%$ is assumed. The pipeline cost function can be approximated with 7-order polynomial coefficients of <cit.>:

$$C_l(D) = 2.27\times 10^{-13}D^7 - 3.32\times 10^{-10}D^6 + 1.85\times 10^{-7}D^5 - 4.74\times 10^{-5}D^4 + 5.76\times 10^{-3}D^3 - 1.87\times 10^{-1}D^2 + 4.1$$

with $D$ in mm, which is a continuous function with derivatives calculated and later used in the gradient solver for the optimization problem. The pump elevation $z_{\mr p}$ is assumed 5 m below the tank ground elevation $z_{\mr r}$.

The tank material cost is assumed as 60 $\mr{USD\cdot m^{-2}}$.

§.§ Numerical Case Study 1: Water Flow Problem of Eq. (<ref>)

All problems presented in this numerical case study are only simulated to estimate flow discharges and flow directions. The values of the tank water depths are manually designed (i.e., by trial and error) to be the minimum value to allow for a pressure head in all nodes within 10 to 30 m. The ground elevations of the tanks are the same as those of the node to which they are connected. For this analysis, all tanks are leaned on the ground (i.e., $h_b = 0$). This is typically the case for tanks with relatively large volumes. The lengths of the pumps to the tanks are fixed in 500 m and the pumping flow discharges are calculated using Eq. (<ref>).

The testing cases presented in the following subsection are representative of different scales. The first is a small rural community with a population of 160 inhabitants. The second represents a larger network that could accommodate a population of 12,800
inhabitants. Finally, the last case study is a city with a population of 44,416 inhabitants. The rationale for simulating varied cases is to test the modeling capacity for different demands, tank volumes, and increase the reliability of the model.

§.§.§ Testing Case (a) - The 2-loop, 5-nodes, 1-tank network

To illustrate the numerical procedures to solve a water distribution network problem using a simple spreadsheet, in this case study, we develop a step-by-step mathematical definition of the problem and solve it numerically in Excel. In addition, we compare the results obtained by the simple spreadsheet with the EPANET solver.

The network of this case study has 5 nodes, with pipe segments of 100 m and Hazzen Willians coefficients of 130. The network is supplied by an upstream tank that has a fixed-head boundary condition of 20.84 meters above the ground elevation. In this case, all pipes are fixed with a 40 mm diameter. The pipeline cost is USD 1,949.24. The tank volume is 17.28 $\mr{m^3}$.

The problem consists in defining the flow directions and discharges in the network such that the conservation of energy and mass is satisfied for all loops and nodes.

Network of Numerical Case Study 1, testing case (a), where $P_{\mr{r}}/\gamma$ is the tank water depth and the tank head is given by $z_{\mr{r}} + P_{\mr{r}}/\gamma.$ The tank is elevated $h_{\mr b}$ from the ground elevation. Nodes 2 and 3 are 10 m above all other nodes, increasing the required energy to allow sufficient dynamic pressure at them.

hline1-2,7 = -,

Node     Ground Elevation [m]     Demand [L/s]     $P_r/\gamma$

1        100       0      -

2        110       0.2       -

3        110       0            -

4        100       0.3

5        100          -0.5         20.84

Node data for numerical case study 1 (a). The pressure head in the tank was determined by trial and error aiming to find the minimum pressure, with the tank leaned in the ground, that satisfy a pressure within 10 and 30 $\mr{mH_2O}$ in all nodes.

Link data for numerical case study 1.

hline1-2,8 = -,

Link ID     Upstream
Node     Downstream
Node     L [m]     C       D [mm]     $Q_{m}$ [L/s]         $Q_{obs}$ [L/s]

/1/         1                     2                       100       130     40         0.249      0.250

/2/         2                     3                       100       130     40         0.020      0.250

/3/         4                     3                       100       130     40         -0.020     0.020

/4/         1                     4                       100       130     40         0.251      -0.020

/5/         2                     4                       100       130     40         0.029      0.030

/6/         5                     1                       100       130     40         0.500      0.250

Input data of testing case (a) and modeled and observed flow discharges at the links.

The flow direction matrix that for each node (cols 1 to 5) matches the links that are associated with by the columns from 1 to 6 results in:

\m F_d = \left[\begin{array}{cccccc}
-1 & 0 & 0 & -1 & 0 & 1 \\
1 & -1 & 0 & 0 & -1 & 0 \\
0 & 1 & 1 & 0 & 0 & 0 \\
0 & 0 & -1 & 1 & 1 & 0 \\
0 & 0 & 0 & 0 & 0 & -1.
\end{array}\right]

The incidence loop matrix that associate every loop (from 1 to 2 in the lines) with every pipe (from columns 1 to:

\m F_l = \left[\begin{array}{ccccc}
1 & 0 & 0 & -1 & 1 \\
0 & 1 & -1 & 0 & -1
\end{array}\right]

All pipes have the same length (100 m) and Hazzen-Willians coefficient, resulting in:

k \Big|_\text{H-W} = \frac{10.67}{130^{1.85}[(40/1000)/100]^{4.87}} = 842,048.4

Therefore, the mass balance and energy constraints are written as:

\begin{aligned}
& {\left[\begin{array}{cccccc}
-1 & 0 & 0 & -1 & 0 & 1 \\
1 & -1 & 0 & 0 & -1 & 0 \\
0 & 1 & 1 & 0 & 0 & 0 \\
0 & 0 & -1 & 1 & 1 & 0 \\
0 & 0 & 0 & 0 & 0 & -1
\end{array}\right]\left[\begin{array}{l}
Q_1 \\
Q_2 \\
Q_3 \\
Q_4 \\
\end{array}\right]-\left[\begin{array}{c}
0 \\
0.2 \\
0 \\
0.3 \\
\end{array}\right]=\left[\begin{array}{l}
0 \\
0 \\
0 \\
0 \\
\end{array}\right]} \\
& {\left[\begin{array}{ccccc}
1 & 0 & 0 & -1 & 1 \\
0 & 1 & -1 & 0 & -1
\end{array}\right]\left[\begin{array}{l}
842,048.4 Q_1\left|Q_1\right|^{0.85} \\
842,048.4 Q_2\left|Q_2\right|^{0.85} \\
842,048.4 Q_3\left|Q_3\right|^{0.85} \\
842,048.4 Q_4\left|Q_4\right|^{0.85} \\
842,048.4 Q_5\left|Q_5\right|^{0.85}
\end{array}\right]=\left[\begin{array}{l}
0 \\
\end{array}\right]}
\end{aligned}

and can be applied in the WDN purely hydraulic network model from Eq. (<ref>), resulting in a non-convex, non-linear and non-smooth problem due to the friction modeling, although the mass balance equations are linear. Students can derive the aforementioned system of equations in class without excessive effort and the techniques to solve the problem can be discussed. To solve the problem in the Excel, we use the GRG non-linear <cit.> solver, which is a gradient based solver that has shown acceptable results for relatively small networks.

§.§.§ Testing Case (b) - Porto (2004) Network

This case study is a 2-loop network supplied by a tank adapted from <cit.>. All pipes have rugosity of 0.0015 mm and the friction losses are hence modeled with the Darcy-Weisbach model. The kinematic viscosity of the water is assumed to be $10^{-6}~\mr{m^2 \cdot s^{-1}}$. The input data for the nodes are presented in Tab. <ref>. The pressure head is $16.11~\mathrm{mH_2O}$. The link input data are presented in Tab. <ref>. The schematic of the problem is presented in Fig. <ref>. To illustrate the entry of matrices $\m F_d$ and $\m F_l$ in the developed Excel spreadsheet, Fig. <ref> is presented. The network pipeline cost is 126,509.50 USD. The tank volume is 1,382.4 $\mr{m^3}$.

hline1-2,10 = -,

Node     Ground Elevation [m]     Demand [L/s]     $P/\gamma$ [mH2O]

1        463.20            0             -

2        460.20            10            -

3        468.90            8            -

4        471.20            5            -

5        467.70            10            -

6        463.20            5             -

7        459.20            2             -

8        463.20            -40           28.7

Node data of Numerical Case Study 1 for the Porto (2004) network.

Link input data for the testing case (b) <cit.>.

hline1-2,11 = -,

Link ID     Upstream Node     Downstream Node     L [m]     D [mm]     $\epsilon$ [mm]     $Q_{\mr{m}}$ [L/s]     $Q_{\mr{obs}}$ [L/s]

/1/         1                 2                   1850      150        0.0015              13.97              13.98

/2/         2                 3                   790       125        0.0015              8.72               8.72

/3/         7                 3                   700       100        0.0015              -0.72              -0.72

/4/         4                 7                   600       100        0.0015              1.28               1.28

/5/         5                 4                   980       100        0.0015              6.28               6.28

/6/         2                 5                   850       100        0.0015              -4.74              -4.74

/7/         6                 5                   650       200        0.0015              21.03              21.02

/8/         1                 6                   850       200        0.0015              26.03              26.02

/9/         8                 1                   520       250        0.0015              40.00              40.00

Schematic of the testing case (b), adapted from <cit.>.

Incidence matrices used to simulate the testing case (b). Part (a) is the flow direction matrix and (b) is the loop incidence matrix. Each matrix is entered in a different Excel sheet.

§.§.§ Testing Case (c) - Huddlestone (2004) Network

This numerical case study shows a larger network with 8 loops, 12 internal nodes, 2 tanks, and a total of 21 links <cit.>. All nodes have the same elevation. Tank 1 (node 13) is $\mr{3.66}~\mr{mH_2O}$ above Tank 2 (node 14) (see Fig. <ref>). Demands are taken in four nodes of the network and the problem consists of finding the discharges and flow directions in all pipes subject to known tank head boundary conditions. The topological matrices $\m F_d$ and $\m F_l$ of this problem are shown in the Supplementary Material. The network pipeline cost is USD 2,093,182.81 USD. The pipe information is given in Tab. <ref>. The tank 1 and 2 volumes are 3,572.03 and 1,224.89, $\mr{m^3}$ respectively.

$\left(L / \mathrm{s}\right)$

$\left(L / \mathrm{s}\right)$

/1/      305      457.2     0.26     55.8      55.5

/2/      203      304.8     0.26     40.0      39.8

/3/      203      365.8     0.26     16.5      16.4

/4/      203      609.6     0.26     -10.3     -10.4

/5/      203      853.4     0.26     -8.7      -8.7

/6/      203      335.3     0.26     12.6      12.5

/7/      203      304.8     0.26     15.0      14.9

/8/      203      762       0.26     9.7       9.6

/9/      203      243.8     0.26     48.0      47.8

/10/     152      396.2     0.26     0.4       0.3

/11/     152      304.8     0.26     10.8      10.7

/12/     254      335.3     0.26     -7.4      -7.6

/13/     254      304.8     0.26     -16.0     -16.3

/14/     152      548.6     0.26     5.3       5.3

/15/     152      335.3     0.26     15.7      15.7

/16/     152      548.6     0.26     -2.4      -2.4

/17/     254      365.9     0.26     23.6      23.5

/18/     152      548.6     0.26     4.0       4.0

/19/     152      396.2     0.26     -4.7      -4.7

/20/     1000     25        0.26     103.7     103.4

/21/     1000     25        0.26     35.1      35.4

Input data for Huddlestone Network (first 4 columns), where $Q_h$ is the modeled results from the paper and $Q_m$ are the results with the modeled developed in this paper.

Network schematics of testing case (c), adapted from <cit.>.

§.§ Numerical Case Study 2 - Design Optimization using Eq. (<ref>)

We solve the design optimizatin problem using the network presented in testing cases cases (a), (b), and (c) from Numerical Case Study 1, but now optimizing the tank pressure head and height from the ground. In all testing cases in this numerical case study, pressure heads in the internal nodes of the network are ensured to be higher than $10~\mr{mH_2O}$ and lower than $30~\mr{mH_2O}$.

In addition, tanks have a minimum and maximum static pressure of 0.25 and 40 m. The tank height is limited by a minimum of 0 and a maximum of 39.5 m. The pipelines connecting the pumps to the tanks are 500 m in length and their diameters are designed not to allow flow velocities greater than $2\mr{m\cdot s^{-1}}$, hence finding the closest diameter that satisfies this condition. The values of $k$ are calculated using the headloss model of each testing case (i.e., using H-W (<ref>) for (a), and D-W (<ref>) for (b) and (c)). The pump discharge, the diameter of the supply link, and the friction coefficient are shown in Tab. <ref> for all the testing cases. All pumps operate 12 h per day ($n_h = 12$) with an average efficiency of 85% ($\eta_p$). The Hazzen-Willians coefficient or the rugosity of the Darcy-Weisbach model is assumed to be the same as the WDN simulated. The interest rate is 12% ($i_r$), the annual increase in energy costs is 6% ($i_e$) and the lifespan of the WDN is 25 years.

Case Study     Tank     $Q_{\mr{p,r}}$ [L/s]     $D$ [mm]     $k^p$

(a)              1             133.3         40        4,210,242.04

(b)              1             53.33          200        3655.84

(c)              1             137.81         300        336.78

(c)              2             47.26          175        5641.59

Input data used to simulate the head losses in the pumping to the tank.

§ RESULTS

In this section, we summarize the results of the numerical case studies presented in this paper. It is important to note that we have included and listed detailed results, such as friction factors, Reynolds numbers, head loss coefficients, piezometric heads, and pressure heads, for all numerical testing cases in the supplemental material of the paper. This decision was made to maintain brevity in the main text and to focus on the major outcomes.

§.§ Numerical Case Study 1

§.§.§ Testing Case (a) - The 2-loop, 5-nodes, 1-tank network

The network hydraulic simulation results are presented in Tab. <ref>. The MAEs for flows and pressures are, in comparison with EPANET, 0.074 $\mr{L\cdot s^{-1}}$ and 0.016 $\mr{m}$, respectively.

§.§.§ Testing Case (b) - Porto (2004)

The results of the solution of the problem in Eq. (<ref>) are presented in Tab. <ref>. The MAEs of flows and pressures, compared to EPANET, are 0.004 $\mr{L\cdot s^{-1}}$ and 0.058 $\mr m$, respectively.

§.§.§ Testing Case (c) - Huddlestone (2004) Network

The results of the network Water Flow Problem are presented in Tab. <ref>. The MAE of the flow simulated compared to the ones reported in <cit.> is 0.13 $\mr L \cdot \mr s^{-1}$, less than 0.1% of the maximum flow.

§.§ Numerical Case Study 2

The foundation states modeled for the optimization design problem of testing cases (a), (b), and (c) are presented in Tab. <ref>. The pump states are shown in Tab. <ref>. The overall cost composition including foundation, tank material, and pump energy costs is presented in Tab. <ref>.

cell11 = r=2,
cell12 = c=2,
cell14 = c=2,
cell16 = c=2,
cell18 = c=2,
cell110 = c=2,
hline1,3,7 = -,

Study     D [m]               $h_{b}$ [m]              $h_r$ [m]               $H_k$ [kN]                $M_k$ [$\mr{kN \cdot m}$]

DOM       WFP       DOM        WFP      DOM        WFP       DOM         WFP        DOM           WFP

(a) - R1         2.15      1.03      16.07      0.00     4.77       20.84     10.67       17.79      197.14        209.57

(b) - R1         7.83      7.83      0.00       0.00     28.70      28.70     205.56      205.57     3334.45       3334.68

(c) - R1         14.65     18.03     0.00       0.00     21.19      13.99     259.27      185.97     3105.64       1470.55

(c) - R2         9.43      12.29     0.00       0.00     17.53      10.33     130.46      85.44      1292.82       498.86

Foundation states for all case studies simulated, where DOM = Design Optimization Modeling [Eq. (<ref>)] and WFP = Water Flow Problem [Eq. (<ref>)].

cell11 = r=2,
cell12 = c=2,
cell14 = c=2,
cell16 = c=2,
hline1,3,7 = -,

Study     $h_g$ [m]               $H_{\mr{m,p}}$ [m]               $P$ [kW]

DOM        WFP       DOM          WFP       DOM          WFP

(a) - R1         25.84      25.84     31.44        31.44     0.24         0.24

(b) - R1         33.70      33.70     44.10        44.10     27.14        27.14

(c) - R1         26.19      18.99     32.59        25.39     51.83        40.38

(c) - R2         22.53      15.33     35.13        27.93     19.16        15.23

Pump states for all testing cases, where DOM = Design Optimization Modeling [Eq. (<ref>)] and WFP = Water Flow Problem [Eq. (<ref>)].

cell11 = r=2,
cell12 = c=2,
cell14 = c=2,
cell16 = c=2,
cell18 = c=2,
cell110 = c=2,
hline1,3,6 = -,

Case     $C_{\mr p}$ [$10^3$USD]                $C_{\mr m}$ [$10^3$USD]                $C_{\mr f}$ [$10^3$USD]                $C_{\mr t} - C_{\mr p}$ [$10^3$USD]                 $C_{\mr t}$ [$10^3$USD]

DOM              WFP        DOM                WFP        DOM                  WFP        DOM               WFP         DOM           WFP

(a)     0.53      0.53      2.86       4.14       1.52       1.74       10.99       12.48       12.93       14.43

(b)     23.78     23.78     87.63      87.63      55.43      55.43      439.31      439.31      565.81      565.82

(c)     48.71     62.19     465.05     798.75     169.88     155.89     1409.76     1561.55     3502.94     3654.73

Modeling results of Numerical Case Study 2, where $\mr{DOM}$ is the design optimization problem results from solving Eq. (<ref>) and $\mr{WFP}$ are the results of solving Eq. (<ref>).

hline1-2,5 = -,

Case Study     Energy     Material      Foundation      $C_t - C_p$

(a)            0.0%          30.8%           12.7%             12.0%

(b)            0.0%          0.0%            0.0%              0.0%

(c)            -27.6%        41.7%           -8.9%             9.8%

Cost variation between two simulations tested, where positive values indicate that the design optimization problem provide a percentual cost reduction compared to the manual design approach.

§ DISCUSSION

All MAE errors between modeled results and true-based results are almost negligible, which indicates that the X-WHAT solver finds very similar, although not equal solutions to the EPANET solver. The differences are primarily due to the way the friction factor is considered. While in X-WHAT we use an explicit equation to estimate $f$ (see Eq. (<ref>)), EPANET uses a mix within the Hagen–Poiseuille, Swamee and Jain, and a cubic interpolation formulation for different values of Reynolds number.

All initial flow estimates for the gradient-based solver used to solve the problem were equal 10% of the total demand. Although a non-mass-conservative guess for the solver was employed, it was still possible to find the correct answer for the flow discharges. This is an advantage of applying the method presented here in comparison with typical spreadsheet solutions of the Hardy-Cross method. For the network presented in testing case (c), it can be very tedious and time-consuming to find initial mass-conservative estimates.

From the design optimization case studies, we found that using a leaned-on-the-ground tank, for a relatively small network (i.e., 160 inhabitants but with geometrical challenges as two nodes 10 meters higher than the tank level) was not cost-effective, see Tab. <ref> and Tab. <ref>. Due to the relatively small volume and relatively high node elevations, the solver found that it was more cost-effective to build an elevated tank. This is a typical solution applied in practice in cases like that, and it was interesting that the solver found it. However, finding a solution like that was only possible when the wind forces acting on the lateral of the tank were considered and by transforming the forces acting on the tank into foundation and material costs. With the optimization procedure, costs could have been reduced 12% for testing case (a) (see Tab. <ref>) simply by elevating the tank from the ground 16.07 m, as shown in Tab. <ref>.

The other testing cases (b) and (c) are larger networks. For both cases, it was more cost-effective to use a ground tank due to the large wind forces and the foundation cost associated with an elevated tank solution. For the testing case (b), designing the tank with trial and error and looking for a minimum tank depth to satisfy the pressure constraints resulted in the exact same solution found by the X-WHAT model. However, as shown in testing case (c), the same procedure would have resulted in an increase in costs of 151,790 USD, which represents 9.8% of the overall cost, indicating that choosing the minimum head to satisfy the minimum pressure in the network might not be the most cost-effective solution. The non-linearities in the foundation and tank material costs make the problem of deciding the tank depths and height from the ground, especially for cases with more than 1 tank, a complex task to approach with trial and error. The optimization tool can then facilitate the design procedure.

§.§ Limitation of this Modeling Approach

The X-WHAT tool is a simplified Excel tool to solve steady-state WDN problems. It has the capacity to deal with relatively small networks with a maximum of 200 links. This limitation is raised by a bound in the number of maximum variables that the Excel solver supports. Although the solver packages presented in <cit.> find a solution to this issue, we decided not to require any other software package in lieu of Excel. In addition, having 200 links might be outside the scope of using this tool for teaching and for solving relatively small WDN systems, which is the focus of X-WHAT model.

The problem of designing the pipes, while maintaining energy and mass conservation, appears untractable to Excel basic solvers. We have extensively tried to use the simple gradient-based solvers of Excel to solve the pipeline design problem with no success. The pipeline optimization design problem has been solved in the literature with branch-and-cut algorithms that deal with mixed integer problems, increasing the complexity of such a simple tool as the one presented in this paper. However, the addition of this capability is desirable for future studies and applications of this tool.

§.§ Advantages of the X-WHAT

The file is less than 2 mb and works in Excel versions above 2013. We developed the tool using only Excel built-in functions to solve the WDN Water Flow Problem. Users and students are generally familiar with spreadsheet calculations and Excel functions, making it relatively easier to debug the functions and understand the steps required to solve the problems. Hence, the tool does not require coding expertise and is an advantage compared to other tools presented in the literature. All cells of input data are commented and step-by-step material on how to use the tool is provided in the supplemental information, aiding users in how to run the model. The creation of incidence matrices can be performed by flow direction algorithms, but more importantly, can be derived in class for relatively small networks; which is often the case of hydraulic exams and examples taught in classes.

The tool allows a rapid sensitivity analysis, and users can assess the effect of different demands, or lack of them, in the network, as well as assess the cost effects of different network configurations. Another interesting application of the tool is to use the hydraulic solver to calibrate the rugosity of the pipes, given a set of known pressures and/or flows in the network. Although not scoped in this paper, this analysis can be easily adapted in the tool. By changing the cost function to an error metric such as MAE or root-mean-square error within modeled and observed pressures or flows, users can define a new optimization problem with the rugosity of the pipes as the decision variable. By having the WDN numerical solver in a simple yet user-effective way, several other applications can arise.

§.§ Tentative Class Organization

To allow for wider application in engineering classes, we attempt to provide a tentative class organization to introduce and solve the problems presented in this paper. The methods and results presented here encompass all materials required for teaching purposes. The organization of the class is as follows

* Introduction to WDN Modeling and Design: Two 1-h classes of fundamentals of WDN Modeling, including head loss modeling, fundamental equations of energy and mass conservation, and network topology modeling.

* Solving a Looped-Network Manually: One 1-h class for solving testing case (a), manually, step-by-step in the blackboard.

* Applying X-WHAT Solver to a larger network: One 1-h class to explain to the students how to use the X-WHAT tool and apply the tool to solve testing case (a), solved manually in the previous class, and testing case (b). A homework assignment to solve testing case (c).

* Optimizing Tank Design: One 1-h class to introduce design optimization and to solve test case (a) by trial and error and optimization. Homework assigned to solve testing case (c).

In addition, we provide a unit design for this by applying the Understanding by Design (UbD) approach proposed in <cit.>. UbD is a framework for designing curriculum units with a focus on student understanding and performance. This unit design can be adapted or expanded to align with the instructors' objectives, class size, and available resources. However, we are confident that it provides valuable insights into the practical application of the methods and tools proposed in our paper within an engineering classroom setting.

Unit Design using UbD for an Engineering Classroom on the Design and Simulation of Looped WDNs using X-WHAT Solver

2|c|[HTML]BFBFBFSTAGE 1 — DESIRED RESULTS
2|l|[HTML]FEFEFEc]@l@Established Goals:

- Develop a comprehensive understanding of water distribution network (WDN) modeling and design principles.

- Master the application of fundamental equations of energy and mass conservation in WDN analysis.

- Master the design factors and structural aspects influencing the design process and optimization of WDNs.

- Acquire the skills to utilize the X-WHAT Solver for analyzing and optimizing WDNs of varying scales and complexities.

Students will understand that:

- Role of WDNs as an important infrastructure system, part of our urban development

- The complexity inherent in designing, operating, and management of WDNs.

- Insight into the significance of network topology in designing efficient water distribution systems.                                                                                c]@l@Essential Questions:

- What are the key equations and principles governing energy and mass conservation in WDNs?
- What are the design factors in WDNs?

- How to design WDNs and optimize these factors?

- How does the structural aspect affect the design process of WDN?

- How to formulate a design optimization problem that merges fundamental concepts of hydraulics
and structural design for WDNs?

- How to utilize the X-WHAT Solver for different WDN networks with different topologies and scales?

Students will know:

- Knowledge of the key equations and principles governing energy and mass conservation in WDNs.
- Understanding of the design factors and structural considerations influencing WDN design and optimization.

- Familiarity with the formulation of design optimization problems that merge hydraulic concepts  with structural
design principles for WDNs.

- Simulate the hydraulics of the system using X-WHAT Solver, as well as solve the design optimization problem

Students will be able to:

- Ability to apply fundamental equations and principles to analyze energy and mass conservation in WDNs.

- Skill in considering design factors and structural aspects to optimize WDN performance.

- Navigating and using the X-WHAT Solver
2|c|[HTML]BFBFBFSTAGE 2 — ASSESSMENT EVIDENCE
1|l|[HTML]FEFEFEc]@l@Performance Tasks:

- Task 1: Solving Test Case (a) Manually on the Board:
Description and Criteria of Assessment:
Students will take turns to solve the looped-network problem manually on the blackboard, demonstrating their
understanding of fundamental equations and principles governing energy and mass conservation in WDNs.

- Task 2: Application and Utilization of X-WHAT Solver:
Description and Criteria of Assessment:
Students will utilize the X-WHAT Solver to analyze Test Case (c) as homework, demonstrating their
ability to apply advanced tools for WDN analysis.

- Task 3: Design Optimization Problem:
Description and Criteria of Assessment:

Students will utilize X-WHAT Solver to integrate hydraulic concepts with structural design principles
for Test Case (c) and solve the design optimization problem as the second homework, showcasing their ability
to merge theoretical knowledge into practical applications.

c]@l@Other Evidence:

- In Classroom Ongoing Discussion while Solving the Test Cases.
- During Lecture Questionnaire via Online App/Tool:
Students complete short questionnaires during lectures to assess their understanding of the concepts
covered in class.

- Think-Pair-Share:
Students respond to the results obtained from the test cases solved in class, discuss with a partner/group,
and share with the class.
2|c|[HTML]BFBFBFSTAGE 3 — LEARNING PLAN
2|l|[HTML]FEFEFEc]@l@Learning Activities:

1. Pre-first class survey about students' majors, reasons to take the class, their expected outcomes, and their background knowledge. (W, T)

2. Lecture: Introduction to WDN Modeling - 1 hour

- Start the unit by highlighting the importance of WDNs and some statistics on real-world networks. (H) - 10 minutes

-  Discuss real-world engineering problems related to WDNs. (W) - 5 minutes

- Introduce the fundamentals of WDN Modeling, including head loss modeling, fundamental equations of energy and mass conservation, and network topology modeling. (E) - 30 minutes

- Reflect on the complexity associated with simulating the WDNs and how to overcome it through open discussion. (R, E) - 10 minutes

- During the Lecture Questionnaire via an online App/tool.: Students complete short questionnaires during the lecture to assess their understanding of the introduced concepts. (E) - 5 minutes

3. Lecture: Lopped WDN Network Simulation - 1 hour

- Performance Task 1: Solve Test Case (a) manually on the board by making the students take turns to solve it step-by-step. (E) (45 minutes)

- Think-Pair-Share: Divide students into groups of two or more and ask them to discuss the results together then share with the whole group. (E, R) (15 minutes)

4.  Lecture: Navigating and Using X-WHAT Solver - 1 hour
- Navigate the X-WHAT Solver in front of the students and explain what are the inputs needed and also outputs. (E) - 15 minutes

- Simulate Test Case (a) using the solver then compare the results with the results obtained from the previous lecture. (E, R) - 15 minutes

- Show students Test Case (b) and have an open discussion about the expected differences while solving this test case in comparison to Test Case (a). (E, R) - 10 minutes

- Simulate Test Case (b) using X-WHAT Solver.

5. Performance Task 2: Application and Utilization of X-WHAT Solver on Test Case (c) - Homework. (E1)

- Students are required to perform the task individually.

6. Provide feedback on performance task 2 and address common mistakes through an announcement or an email sent to students. (R)

7. Lecture: Design Optimization Problem and Solving it Using X-WHAT Solver - 1 hour

- Introduce the optimization problem: objective function, decision variables, and problem formulation taking into account the structural design aspects. (E) - 20 minutes

- Explain how to utilize the X-WHAT Solver to solve this problem through solving Test Cases (a) and (b). (E, R) - 30 minutes

- Open discussion on results (E, R) - 10 minutes

8. Performance Task 3: Design Optimization Problem on Test Case (c) - Homework. (E1)

- Students are required to perform the task individually.

9. Provide feedback on performance task 3 and address common mistakes through an announcement or an email to students. (R)

§ CONCLUSIONS

In this paper, we develop an Excel tool to solve the steady-state flow distribution of an incompressible fluid in water distribution networks with nodes and links. Two problems were investigated: the WDN Water Flow Problem, and the WDN Design and Optimization Modeling. The first finds the correct flow values and directions in a given network with known geometry, tank, and pipe information, subject to fundamental conservations of mass and energy. The second, considering the same conservation constraints finds the near-optimal tank designs for a given network with known pipe information that minimizes the overall network cost. This cost considers the pumping energy to fill the tank, the tank material, and the tank foundation cost, which is calculated considering the weight of the tank and the wind forces acting on its lateral surface.

The results of the developed hydraulic model for testing cases (a) and (b) had mean average errors of pressures and flows below 0.08 $\mr{L\cdot s^{-1}}$ or $\mr{m}$ for flows and pressures compared to EPANET, indicating acceptable results. For testing case (c), compared to the reported results of the literature, the mean average error of flows was less than 0.1% of the maximum flow.

The results of the optimization technique presented in this paper allowed a cost reduction of 12 and 9.8% for testing cases (a) (i.e., a 2-loops, 1-tank network supplying drinking water to a small community of 160 inhabitants) and (b) (i.e., a 8-loops, 2-tanks, and 21 links network supplying drinking water for a population of 44,416 ). In the latter, costs had a reduction of 151,790 USD simply by optimizing the tank depths aiming to minimize the costs, to allow pressure constraints.

The numerical modeling results of optimizing the network of the testing case (a) suggest that elevated tanks are more cost-effective for WDN with relatively low demand (i.e., the tank volume was 17.28 $\mr{m^3}$, compared to the tanks of the testing case (c) of 3,572.03 and 1,224.89 $\mr{m^3}$) while facing relatively high topographic elevations. It was cost-effective to raise the tank 16 m and increase its diameter to 2.15 m, compared to a leaned-on-the-ground tank with a smaller diameter of 1.03 m. For both testing cases (b) and (c), however, due to the relatively higher tank volumes, the optimized solution was the tanks leaned on the ground. The solutions presented in this paper, interestingly, restate the common engineering practice performed in the cases of tanks to meet small and large demands.

Modeling, design, and simulation of WDN is possible using a simple spreadsheet tool such as Excel. The tool is applicable not only for teaching purposes but also for hydraulic simulation in a variety of WDN configurations. The gradient-based  GRG solver from Excel is able to provide, within a reasonable initial estimate of the decision variables, correct flow answers compared to the literature and EPANET. The design optimization problem shows that important cost reductions can be achieved if a more complete cost function is considered. By providing our open-source tool, the X-WHAT, that do not require any other software package other than Excel or any coding expertise, it is possible to advance spreadsheet-based WDN hydraulic simulations to a wider audience.

The toolbox can be easily adapted for other problems such as calibrating network parameters for a variety of observed input such as observed pressures and flows at particular nodes and pipes. In addition, future editions of the model can include valve and pump operations and the headloss model can be enhanced by including minor losses and singularities. Although the tool was applied to drinking water systems, it is adapted to other fields such as oil and gas networks since it is allowed to change the fluid parameters in the toolbox input data. Overall, the toolbox is simple and yet can provide a variety of analysis as presented in this paper and in the supplemental material. Future advances to make the tool more accessible not only to undergraduate and graduate students, but also for the water resources engineering community are warranted.

§ DATA AVAILABILITY STATEMENT

Some or all data, models, or code generated or used during the
study are available in a repository or online in accordance with
funder data retention policies. All software, figures, and data can be freely downloaded in <cit.>. The supplemental material also contains a user manual showcasing step-by-step how to use the developed tool.

§ SUPPLEMENTAL MATERIALS

Supplementary data related to this article can be found at <https://github.com/marcusnobrega-eng/ETHA—Clone>.

Program size: Approximately 2 MB

Required License: Excel version 2013 or above

Availability: Open source (github license)