**1. Introduction**

The Storm Water Management Model (EPA SWMM) is a hydrologic and hydraulic model used to simulate flows in both storm water runoff and sanitary sewers. It was developed by the United States Environmental Protection Agency (USEPA), and it is a program that is able to solve the hydraulic equations of a network by using three different algorithms: steady flow, kinematic wave, and dynamic wave [1]. While the first is insensitive to the time interval, the last one requires very short time intervals (about less than one minute). This leads a high computational time.

Research regarding the optimal design of sewerage networks and drainage is becoming more common nowadays. Most of these optimization processes require numerous simulations, which is why the speed at which the calculations and the simulations are done becomes a fundamental aspect. Network design [2,3], real time control [4], and contamination source identification [5] are some examples of applications that require a hydraulic simulation of the sewerage network. Because such applications require an elevated number of simulations, the optimization process may become very slow. This is why previous studies have worked with constant discharges entering each network node, and steady state models have been used [2,6,7]. Krebs *et al.* [8] performed a sensitivity analysis to find the balance between the simulation time step through the dynamic wave model and the computation time to find a calibration application of a rain water evacuation network.

Although it might be possible to use an external program to connect with the EPA SWMM engine, it is still necessary to handle files either to modify the data or to access the results of the simulation. In order to do this, the project file must be modified or the results binary file read, respectively. Usually, file handling requires longer times than accessing data directly from the application. Hence, EPA SWMM requires a complete Toolkit that allows the manipulation of data from the application itself.

Next, a library of functions that increases the flexibility of EPA SWMM in terms of exchanging information during run-time is presented. This library will be hereinafter referred to as the Toolkit. This Toolkit notably extends those tools already present, thereby going from 9 to 22 functions. The new functions help with simulation execution, result reading, and network characteristic modification. All these steps may be done without the need for handling archives, which means a considerable reduction in calculation times.

Furthermore, a testing protocol has been assembled in order facilitate the use and implementation of this library. This protocol consists of two phases. First, savings in calculation times due to the use of the library are measured. As a result of this first phase, only new functions that imply time saving were considered. In the second phase, the results obtained by using the library are compared to those obtained directly with EPA SWMM. This comparison was made for every new function and only those presenting an exact coincidence were validated.

A typical application where computational efforts are high is the design of hydraulic networks by means of heuristic optimization algorithms. Therefore, the work is completed by using this library for the development of an optimized design model of a sewerage network by using a genetic algorithm.

### **2. Development of the SWMM Toolkit**

In the field of water distribution networks, there are many examples of tools developed in order to facilitate the incorporation of calculating engines in optimization algorithms. EPANET might be considered as the main example of this. EPANET is a program that tracks the flow of water in each pipe within a drinking water system and was also developed by the USEPA. Within its published version, EPANET includes a programming library (EPANET Programmer's Toolkit) that allows the program to be used as typical programming commands [9]. Several authors have adapted this library in order to incorporate functions that originally were not thought about being included. This is the case of Kandiah *et al.* [10], who partially modified the EPANET Programmer's Toolkit in order to include functions for control adaptation in EPANET. Another example is the CWSNet Library [11]. CWSNet expands this library so that new elements such as variable speed pumps or specific valves could be incorporated, as well as new algorithms. Savi´c *et al.* [12] continued to develop CWSNet until the creation of the GANet application. Other authors, instead, chose to internally modify EPANET in order to adjust it to their particular needs. Marchi and Simpson [13], for example, modified the energetic calculation in order to correct the energy calculation for including the efficiency variation due to affinity laws when using pumps with variable speed drives. In other cases, EPANET has been continued by other institutions that have included programming libraries in their commercial programs. Bearing all this in mind, when it comes to potable water supply, there exists a library that allows the speeding up of calculation processes that require constant change or update in the network in which the simulation is being done.

However, that is not the case for sewage systems. The internal structure of EPA SWMM is derived from the structure presented by EPANET. However, unlike EPANET, EPA SWMM has not offered a set of interfacing functions as EPANET does. It only includes some basic functions allowing running of a single event simulation.

EPA SWMM provides several interface tools [14] that allow using the model by an external application. This works as long as the network characteristics have been previously defined. The performance of the EPA SWMM program is sequential. First, an input module reads the files needed for the simulation. The network data are contained in an input or project file (INP file). These data might be complemented with auxiliary files for hot start conditions, weather data, etc. Then, if the analysis contains rain water data, a hydrologic calculation must be carried out in order to transform the rain in a runoff hydrograph. A hydraulic simulation follows, and then, if considered necessary, a follow-up on contaminant substances may be done in order to produce a quality model. All results are stored in a binary results file (OUT file). Finally, a report file (RPF file) containing some results statistics is written. The whole process is summarized on the right hand side of Figure 1.

**Figure 1.** Block diagram of EPA SWMM and the Toolkit.

The performance of the interfacing functions provided with EPA SWMM follows the same structure, that is, as soon as the project is open, the input file must be read. Afterwards, the calculation is executed, thus being able to perform a step by step analysis. Finally, the results are written in a binary file that must eventually be read. This tool has 9 functions that can be used in order to manage the project. These functions are listed in Table 1 as group 1. However, it is not possible to obtain partial results from the said simulation, or to perform data modification until the process is complete.



This performance mode was conceived in order to work with a different user interface, developed "ad-hoc" and well-integrated in other programs. Its most evident application would be the integration of the EPA SWMM engine within a geographic information system. However, the process is slowed

down because of file access. On the one hand, it is required that the input file is written for every execution. On the other, in order to process results, EPA SWMM must write the results file and the external application should read it. These two operations require a grea<sup>t</sup> deal of programming efforts, and they may consume a significant amount of time.

An alternative to this performance mode is the development of a new set of communication functions. These new functions, integrated as a Dynamic Link Library (DLL), could address a wide array of problems present in applications and programming languages. The final objective is that, eventually, both EPA SWMM and any other application based on the EPA SWMM engine use the same library. An application that is external to EPA SWMM can therefore replace file use for information exchange, thereby ensuring time savings.

The Toolkit replaces the file reading and writing operations with two new groups of functions, as shown on the left hand side of Figure 1. The first group–referred to as *Get Functions*–is composed of functions associated with retrieving information either from project data or simulation results. The second group (*Set Functions*) includes all the data modification functions. All the functions within this second group are simultaneously the most relevant and the most sensitive, since these functions will allow successive simulations by modifying data without having to access the files. For instance, by using the function *swmm\_setLinkValue,* it is possible to change the slope or the Manning roughness coefficient of a pipe during run time. Table 1 summarizes the functions included in the Toolkit.

The optimal sizing of a storm water network might be taken as a first example. This issue is typically addressed by testing different combinations of diameters and slopes, which are ranked by using an objective function. The objective function includes the cost function for the new conduits and penalization terms when the constraints of the problem are not met. However, the whole problem has seldom been studied, even more so when considering the transient flow. Most authors have usually tackled this problem with oversimplified hypotheses. For example, in order to avoid having to perform a runoff analysis for every case, some authors use a constant inflow at network nodes instead of performing the hydrological model. Another example consists of using a steady flow model based on uniform flow. In this way, no duration is defined so that the calculation process is faster. However, it leads to the appearance of inaccuracies that increase with the size of the network and the discharge increase. Therefore, the steady flow model based on uniform flow is evidently insufficient when addressing situations for which surcharge or flooding risks exist.

If the temporal distribution of the rain water is included, then it becomes unnecessary to execute the hydrologic calculation every time. First, given the modular character of EPA SWMM, it is possible to execute a preliminary hydrologic calculation to obtain runoff hydrographs that enter in each element. With these inflows to the nodes, the hydraulic calculation can be performed as many times as it is required. The repeated modification of various network parameters will be necessary, but by using the Set functions, this no longer implies the constant rewriting of the input file. Because this operation requires a significant amount of computational time, the parameters will be modified directly in memory without accessing the writing of the files.

Finally, the binary results file EPA SWMM produces is not easy to manipulate. This file presents basic statistical summaries of the results (these summaries include items such as maximum discharges, maximum levels, volume balances, etc.). If more detailed information on a specific object must be obtained, the [REPORT] section on the project file must be modified to include this information in the result file, and then filter this latter file in order to look for the specific information needed. Since this process might be complex, it has become preferable to read the results obtained after each itineration. It is no longer necessary to read the result file, and the calculation process may be done faster.

Figure 2 shows the flow chart of an optimization process that is based on the evaluation of an objective function. The left flow chart represents the process that is based on the EPA SWMM native interfacing tool. On the other hand, the right flow chart, instead, represents the same process but implemented using the Toolkit. It can be observed that several operations can be avoided. As the

number of iterations increases so will the amount of time that is saved. Bear in mind that if evolutionary algorithms are preferred, the number of evaluations of the object function might be highly elevated.

**Figure 2.** Comparison scheme of optimization algorithm performance using EPA SWMM 5 (**a**) and the Toolkit (**b**).
