## 2 Theoretical Background
### Epanet  
EPANET is open-source software that was developed by the US Environmental Protection Agency (EPA) in 1994 to model the hydraulics and water quality dynamics of water distribution systems. EPANET was designed as a research tool to better understand the dynamics of drinking water constituents, taking into account bulk flow and pipe wall reactions [4]. EPANET conducts simulations considering a geometric representation of a pipe network, along with a set of initial conditions (e.g., water levels in tanks) and rules on how the system is operated, and uses this information to compute flows, pressures, and water quality (e.g., disinfectant concentrations and water age) throughout the network for a certain period of time.  
EPANET model pipes are links that convey water from one point in the network to another, and are assumed to be full at all times. The flow direction is from the higher hydraulic head (internal energy per weight of water) point to the lower head point. The principal hydraulic input parameters for the pipes are the start and end nodes, diameter, length, roughness coefficient (for determining head loss), and current status. Then, the computed outputs for the pipes include the flow rate, velocity, head loss, and friction factor.  
The hydraulic head lost by water flowing in a pipe due to friction with the pipe walls can be computed using one of three different formulas given by Hazen-Williams, Darcy-Weisbach, and Chezy-Manning. The Hazen-Williams formula cannot be used for liquids other than water and was originally developed for turbulent flow only. The Darcy-Weisbach formula is the most theoretically correct, and applies over all flow regimes and to all liquids. The Chezy-Manning formula is more commonly used for open-channel flow.  
Each formula uses the following equation to compute the head loss between the start and end nodes of the pipe:  
\[h_{L}=Aq^{B} \tag{4}\]  
where \(h_{L}=\) head loss (Length), \(q=\) flow rate (volume/time), \(A=\) the resistance coefficient, and \(B=\) the flow exponent. Table 1 lists the expressions for the resistance coefficient and values for the flow exponent for each of the formulas. Each formula uses a different pipe roughness coefficient, which must be empirically determined.  
In the table, \(C=\) Hazen-Williams roughness coefficient, \(\epsilon=\) Darcy-Weisbach roughness coefficient, \(f=\) friction factor, \(n=\) Manning roughness coefficient, \(d=\) pipe diameter, \(L=\) pipe length, and \(q=\) flow rate.  
From a software engineering viewpoint, EPANET is used within procedural programs through a series of direct calls to its library. This requires the user to be aware of all the different functions offered by EPANET (as well as the sequence of function calls) in order to successfully implement a simulation cycle.  
To solve this difficulty, an open-source software package was developed to interface EPANET with the MATLAB technical computing language, called the EPANET-MATLAB Toolkit [3]. This software uses an object-oriented approach by defining a MATLAB Class, which provides a standardized way to handle the network structure, to call all functions as well as procedures using multiple functions to simulate and, in general, perform different types of analyses in the network through the corresponding object.