The contribution of this work complements the previous studies by developing a numeric and economic evaluation of the fluid dynamic behavior optimized at the secondary circuit of a DHWS for low-income houses. A major mark of this work is that the optimization algorithm, based on the gradient method, works together with a genetic optimization that has the function to select which segments of the pipe network will be optimized by the gradient method. The genetic model basically creates a more representative “search space” that allows the gradient method to work better. The implementation methodology of the genetic algorithm is not described in this article. However, its omission does not affect the understanding of the work as a whole. The final version of the program was developed using the Software Engineering Equation Solver^{®} and utilizes the equations of fluid dynamics (mass conservation, momentum, and energy) to determine the pressures, flow rates, and diameters at each point of the network of pipes in the secondary circuit (subbranches, branches, and supply and return branches). The system is divided into a primary and secondary circuit connected by supply and return branches. The primary circuit generates and stores energy, in this case, hot water. The secondary circuit is the entire distribution network of the hot water to the consumers. Only the primary circuit is integrated into the public network of water distribution, while the secondary circuit is totally independent. To optimize the overall cost of the system, the installation costs of the materials and equipment and the costs of the electricity for the primer and recirculation pumps must be considered; however, the heat losses of the pipes are not taken into consideration for the optimization. The independent variables in this case are the pipe diameters in each network segment, which must be optimized to reduce the cost of the pipes. However, optimizing the diameters alone can lead to a loss of high-pressure in the pipes and, therefore, a higher required power for the hydraulic pumps, which necessarily leads to higher costs for the pumps and electricity. Thus, a global cost function is modeled that takes into account the configuration of each system. A multivariable optimization method, known as the gradient method, is highly recommended for this type of application. The iteration process begins with arbitrary values for the independent variables and then calculates the new values that tend to minimize the function. To do this, the value of each variable is the sum of the values of the previous iteration with a step that is proportional to the function gradient at the original point. Mathematically, the global cost function is defined as *C*_{global}(*D*_{1}, *D*_{2}, *D*_{3}, …, *D*_{ns}), where the indices 1, 2, 3,…,*ns* represent each segment of the network with continuous partial derivatives. The optimization starting point gives arbitrary values to the diameters, $Ds,0$, where the index *s* refers to the network segment and the index 0 indicates that $Ds,0$ is the initial value. The new values are calculated by Eq. (1).Display Formula

(1)$Ds,k=Ds,k-1-\alpha \u2202Cglobal(D1,D2,D3,\u2026,Dns)\u2202Ds,k-1$