# Qualification of Hydraulic Analysis Models for Optimal Design of Water Distribution Systems
## 2 Methodology  
The demand-driven analysis (DDA) assumes that the nodal demands will always be satisfied regardless of the nodal pressure head. The numerical model inside DDA is the gradient method, which considers a hydraulic network of \(n_{p}\) pipe with unknown flow rates, \(n_{n}\) nodes with unknown heads (internal nodes), and \(n_{0}\) nodes with known heads (e.g., tank levels). The hydraulics can be analyzed by solving the following system, which contains one nonlinear energy equation and one linear mass balance equation:  
\[A_{pp}Q_{p}+A_{pn}H_{n}=-A_{p0}H_{0}A_{np}Q_{p}=d_{n} \tag{1}\]  
The first equation in Equation (1) corresponds to the nonlinear energy equation that defines the head loss in each pipe between two nodes. The second equation in Equation (1) is a linear equation that defines the mass balance in the system and ensures continuity in the system. The elements in Equation (1) are explained in a more detailed manner as follows:  
\(A_{pp}\) = is a diagonal matrix of (\(n_{p}\times n_{p}\)) defined as:  
\[A_{pp}=\left[ \begin{array}{cccc}\alpha_{1}Q_{1}{}^{(n_{1}-1)}&0&\dots&0\\ 0&\alpha_{1}Q_{1}{}^{(n_{1}-1)}&\dots&0\\ \vdots&\vdots&\vdots&\vdots\\ 0&0&\dots&\alpha_{p}Q_{p}{}^{(n_{np}-1)}\end{array} \right] \tag{2}\]  
where \(Q_{p}\) = discharge vector of \([n_{p},1]\), \(\alpha_{p}\) = calibration parameters with relevant field data, and \(A_{pn}\) = \"connectivity matrix\" associated with each node and dimension \([n_{p},n_{n}]\). It can have only two nonzero elements in each \(i\)th row defined as follows: \(-1\) in the column corresponding to the initial node of pipe \(i\) and \(1\) in the column corresponding to the final node of pipe \(i\), \(H_{n}\) = matrix with dimensions \([n_{n},1]\) of an unknown piezometric head vector, \(H_{0}\) = fixed piezometric head vector with dimensions \([n_{s},1]\) where \(n_{s}\) is the number of fixed head nodes, and \(A_{p0}\) = matrix with dimensions \([n_{p},n_{s}]\) with \(-1\) in the rows corresponding to pipelines connected to fixed head nodes. The second equation in Equation (1) corresponds to the continuity equation for the nodes in the system:  
\[A_{np}Q_{p}=d_{n} \tag{3}\]  
where \(A_{np}\) = transpose matrix of \(A_{pn}\), and \(d_{n}\) = column vector of water demands in the nodes with a dimension of \([n_{n},1]\). Expressing the equations in the matrix is presented as:  
\[\left[ \begin{array}{cc}\big{[}A_{pp}\big{]}&\big{[}A_{pn}\big{]}\\ \big{[}A_{np}\big{]}&\big{[}0\big{]}\end{array} \right]\left[ \begin{array}{c} \big{[}Q_{p}\big{]}\\ \big{[}H_{n}\big{]}\end{array} \right]=\left[ \begin{array}{c}-\big{[}A_{p0} \big{]}[H_{0}]\\ \big{[}d_{n}\big{]}\end{array} \right] \tag{4}\]  
Because of the nonlinearity of the energy equation, an iterative approach is needed. The gradient method consists of a truncated Taylor series expansion, which computes both equations simultaneously as follows:  
\[\left[ \begin{array}{cc}\big{[}N\big{]}\big{[}A_{pp}\big{]}^{\prime}&\big{[}A _{pn}\big{]}\\ \big{[}A_{np}\big{]}&\big{[}0\big{]}\end{array} \right]\left[ \begin{array}{c} \big{[}\mathrm{d}Q_{p}\big{]}\\ \big{[}\mathrm{d}H_{n}\big{]}\end{array} \right]=\left[ \begin{array}{c} \mathrm{d}E\\ \mathrm{d}d_{n}\end{array} \right] \tag{5}\]  
where N is a diagonal matrix (\(n_{1},n_{2},\dots,n_{n_{g}}\)) with dimensions \([n_{p},n_{p}]\) and \(\big{[}A_{pp}\big{]}^{\prime}=\big{[}A_{pp}\big{]}\) in case there are no pumps in the network.