Download as pdf or txt
Download as pdf or txt
You are on page 1of 12

Environmental Modelling & Software 83 (2016) 143e154

Contents lists available at ScienceDirect

Environmental Modelling & Software


journal homepage: www.elsevier.com/locate/envsoft

MatSWMM e An open-source toolbox for designing real-time control


of urban drainage systems
~ o a, b, *, J. Barreiro-Gomez a, c, A. Ramirez-Jaime a, N. Quijano a,
~ o-Bricen
G. Rian
C. Ocampo-Martinez c
a
Departamento de Ingeniera El nica, Universidad de los Andes, Carrera 1 No 18A-10, Bogota
ectrica y Electro , Colombia
b
Departamento de Ingeniera Civil, Universidad de los Andes, Carrera 1 No 18A-10, Bogota , Colombia
c
Automatic Control Department, Universitat Polit tica Industrial (CSIC-UPC), Llorens i Artigas, 4-6, 08028
tica i Informa
ecnica de Catalunya, Institut de Robo
Barcelona, Spain

a r t i c l e i n f o a b s t r a c t

Article history: This manuscript describes the MatSWMM toolbox, an open-source Matlab, Python, and LabVIEW-based
Received 17 November 2015 software package for the analysis and design of real-time control (RTC) strategies in urban drainage
Received in revised form systems (UDS). MatSWMM includes control-oriented models of UDS, and the storm water management
1 March 2016
model (SWMM) of the US Environmental Protection Agency (EPA), as well as systematic-system edition
Accepted 6 May 2016
functionalities. Furthermore, MatSWMM is also provided with a population-dynamics-based controller
for UDS with three of the fundamental dynamics, i.e., the Smith, projection, and replicator dynamics. The
simulation algorithm, and a detailed description of the features of MatSWMM are presented in this
Keywords:
Open-source toolbox
manuscript in order to illustrate the capabilities that the tool has for educational and research purposes.
Urban drainage system integrated model 2016 Elsevier Ltd. All rights reserved.
Real-time control
Matlab
Python
LabVIEW

Software availability 1. Introduction

Name of software: MatSWMM. Software packages for urban drainage systems (UDS) can be
Contact address: Gerardo Rian ~ o-Bricen
~ o, School of Engineering, categorized into two classes of tools: commercial and open source.
Universidad de los Andes, Carrera 1E 19A e 40; ga. The former ones are popular among industry and utilities because
riano949@uniandes.edu.co. of their all-in-one capabilities and their efciency. Some of the
Year rst available: 2015. commercial packages available in the market are CivilStorm, Info-
Software requirements: Windows x86 and x64 environments with Works CS, MOUSE, MIKE, SewerCAD, SOBEK-Urban, MicroDrainage,
Matlab 2008 (or higher), Python (2.5), and/or LabVIEW and SIMBA (Price and Vojinovic, 2011). Most of these are holistic
2012 (or higher). (Butler and Schtze, 2005), i.e., these packages allow to model not
Program size: 1e5 Mb. only ow-routing through a drainage network, but also real-time
Availability: Open-source repository, licensed under the GNU control (RTC), rainfall, runoff, water quality, street ooding (1D
General Public License v3.0 (https://github.com/water- and 2D), and many other features. Despite of the completeness of
systems/MatSWMM). commercial packages, these tools can be inappropriate for educa-
tional and research purposes, since they are closed, i.e., they do not
allow modications over the source code or the addition of new
algorithms, a feature that is crucial when testing new theories,
* Corresponding author. Departamento de Ingeniera Ele ctrica y Electro  nica,
specially new RTC strategies. Additionally, commercial tools can be
Universidad de los Andes, Carrera 1 No 18A-10, Bogot
a, Colombia.
~ o-Bricen
~ o), j.
expensive despite allowing integration with coding tools.
E-mail addresses: ga.riano949@uniandes.edu.co (G. Rian
barreiro135@uniandes.edu.co, jbarreiro@iri.upc.edu (J. Barreiro-Gomez), af. On the other hand, there are open-source tools aimed to give
ramirez236@uniandes.edu.co (A. Ramirez-Jaime), nquijano@uniandes.edu.co exibility to the simulation algorithm, allowing the integration of
(N. Quijano), cocampo@iri.upc.edu (C. Ocampo-Martinez).

http://dx.doi.org/10.1016/j.envsoft.2016.05.009
1364-8152/ 2016 Elsevier Ltd. All rights reserved.
144 ~ o-Bricen
G. Rian ~ o et al. / Environmental Modelling & Software 83 (2016) 143e154

several features related to UDS, like the ones stated before (Garca 2. Preliminaries
et al., 2015). Some tools of this type are CITY DRAIN (Achleitner
et al., 2007) and SWMM (Huber et al., 2010). CITY DRAIN has In this section, important aspects for hydraulics computation
been developed to operate with Simulink and Matlab in order to and RTC with MatSWMM are presented. First, a brief explanation of
enhance its functionality with already developed control systems the SWMM model is given, highlighting the modications that are
blocks and toolboxes for Matlab. CITY DRAIN includes simplied done to the SWMM ow-routing algorithm, and how several
ow-routing models like the Muskingum model (Te Chow, 1959). enhanced functionalities have been adapted to it. Then, it is
SWMM is the storm water management model of the US Envi- emphasized how RTC can be designed with MatSWMM, and how it
ronmental Protection Agency (EPA). It is oriented to model with can be scalable for large-scale systems. It is important to consider
high level of precision, using the one-dimensional Saint Venant that MatSWMM can be only executed through command-line in-
equations (SVE), runoff processes that take place in UDS. Addi- structions when using Matlab and Python. In contrast, if LabVIEW is
tionally, SWMM can be useful for rule-based RTC modeling. preferred, functions are called like typical LabVIEW blocks with
However, open-source tools can be also limited, since extending their corresponding inputs and outputs.
and/or modifying SWMM for RTC purposes requires programming
skills with a low-level programming language such as C, and 2.1. The SWMM model
adding a more complex model to the CITY DRAIN framework
(like the SVE-based model) can be difcult in some cases. Addi- SWMM is a dynamic rainfall-runoff simulation model that is
tionally, Pathirana (Pathirana, 2015) developed a Python-based used for planning, analysis, and design of infrastructure related to
toolbox to extract easily results from SWMM, attempting to stormwater runoff, combined and sanitary sewers, and other
satisfy this need. However, it is not possible to design RTC with it, drainage systems in urban areas (Huber et al., 2010). The platform
since that tool only simplies the extraction of simulation results consists of an interface where a drainage network can be created by
from SWMM. using elements such as pipes, canals, storage units, sub-
For this reason, in order to facilitate the design and testing catchments, among others. Additionally, it has a calculation mod-
processes of real-time controllers for UDS, MatSWMM, an open ule that uses the one-dimensional SVE to simulate runoff
source tool has been created. MatSWMM is a exible tool, i.e., a throughout the network (Te Chow, 1959).
software package that gives the user the possibility to manipu- SWMM has been also equipped with dynamic and static control
late the simulation results easily for data analysis and/or system elements. Static elements such as weirs and outlets, whose purpose
edition functionalities, since it has been structured for three is to limit water levels along the system, work as barriers that
high-level programming languages (i.e., Matlab, Python, and reduce the energy of the ow. Dynamic control elements, such as
LabVIEW), guaranteeing the possibility of implementing easily orices and gates, can be programmed to operate with either
interfaces, and physical applications, taking advantage of matrix- logical or rule-based control. Additionally, local PID controllers can
oriented programming, plotting capabilities, optimization and be implemented to set operation points for valves and gates set-
control toolboxes. The toolbox works as a co-simulation engine, tings in order to manage water levels, cumulative volumes, and
which is based on SWMM and it has been developed as a ow directions.
collection of functions in order to facilitate the expansion of the The RTC default functionalities of SWMM have become limited
framework. for large-scale control of UDS, as the ones developed in (Barreiro-
An important but often missed issue is that both Matlab and Gomez et al., 2015) (Martin, 2012), and (Ocampo-Martinez, 2010).
LabVIEW environments are commercial and closed products, thus However, it has a big potential as an open-source software since it is
their kernel and libraries cannot be neither modied nor freely possible to enhance its functionality in order to include new
distributed. To allow exchanging ideas effectively improving sci- methods that allow users to simulate complex RTC strategies, and
entic research, both the toolbox and the platform on which to edit systematically any UDS implemented on it.
MatSWMM runs should be free (Stallman, 2002). At this aim,
MatSWMM can run on Python, which is open source and has a 2.2. Structure of the MatSWMM toolbox
great variety of optimization, data analysis, control and numerical
analysis libraries, e.g., NumPy, SciPy and python-control. It is also A special structure of folders and work-les, presented in Fig. 1,
possible to work with ArcPy, which is a GIS library that can be used has been designed for MatSWMM in order to maintain an orga-
to enhance the functionality of MatSWMM in the future, in order to nized environment while working with the toolbox. The structure
offer the same geographical positioning capabilities of commercial of MatSWMM can be categorized in three main parts: the SWMM
packages such as InfoWorks CS or MIKE. les, the MatSWMM les, and the simulation results. The SWMM
In this manuscript, a detailed description of the toolbox les (i.e., the input, report, and output les), are stored in a single
functionalities is presented and some applications for it are folder called swmm_les. In order to run a simulation, it is only
suggested, emphasizing on the RTC design and modeling appli- required to store the input le created with SWMM, and the path to
cations. The remainder of the manuscript is organized as follows. the input le must be described through code.
Section 2 introduces some preliminaries related to the simulation The simulation results are stored in four different folders that
algorithm and the MatSWMM environment. Section 3 gives a are related to the simulation time and the three main types of el-
detailed description of all the functionalities of MatSWMM, ements in UDS (i.e., links, nodes, and subcatchments). The results of
which is complemented in Section 4 with the description of the the simulation are stored in .csv les that contain information of
population-dynamics-based controller for UDS that is included different attributes depending on the type of object as exposed in
into the toolbox. Section 5 gives a brief description of the models Fig. 1.
that are adapted to MatSWMM in order to implement model- Moreover, the MatSWMM les that are required to compute a
based controllers. Section 6 presents an application example simulation vary depending on the programming language. Since
and some realizable applications with the toolbox. Finally, in Matlab and Python can be used for object-oriented programming
Section 7, some conclusions are drawn and a discussion is made (OOP), the MatSWMM environment has been conceived as a class
about further applications of the co-simulation by using this le with several methods. In contrast, MatSWMM for LabVIEW is
novel tool. composed by a set of .vi les related to the functionalities of the
~ o-Bricen
G. Rian ~ o et al. / Environmental Modelling & Software 83 (2016) 143e154 145

Fig. 1. Corresponding folders and les of the MatSWMM toolbox. Basic functionalities inherited from SWMM are highlighted in blue. (For interpretation of the references to colour
in this gure legend, the reader is referred to the web version of this article.)

toolbox. There are basic functions and enhanced functions that can process is carried out, and memory is allocated to store the
be used to reproduce the simulation algorithm (these are high- computation results of the simulation as well as IDs,1 and other
lighted in Fig. 1), extract information, and modify the state of ac- object attributes. Secondly, the RK algorithm is invoked and a loop
tuators from the simulation. It is important to notice that a dynamic is created in order to calculate runoff results for a time interval; this
link library (DLL) with a modied version of SWMM has to be saved is denominated as the main loop of the simulation. Finally, the al-
at the workspace regardless the programming language used. gorithm nds solutions for the ow routing problem and two les
are generated, i.e., a report le and an output le whose extensions
are .rpt and .out respectively. The rst le gives a summary of
2.3. Computational aspects for hydraulics the main simulation results in plain text, while the second one is a
binary le that stores the values of the results, in order to make the
It is emphasized that SWMM is a physically-based discrete-time data storage and retrieving processes efciently when large data-
simulation model that uses principles of conservation of mass, sets are generated.
energy and momentum (Huber et al., 2010). As a discrete-time tool, In order to solve the ow routing problem, it is necessary to
its algorithm nds iteratively solutions for the ow-routing prob- compute the lateral inow at each node (manhole). This estimation
lem described by the SVE, using a fth-order accurate Runge-Kutta is provided by a rainfall-runoff model that is embedded into the
method (RK) with adaptative step size control (Eslamian, 2014). subcathment object of SWMM. Even though, it is also possible to
This RK algorithm is based on the embedded Runge-Kutta formulas, provide the direct runoff information as a parameter. On the one
originally formulated by Fehlberg (Press et al., 1996). hand, if a subcatchment model is used to compute the lateral inow
Hydraulics in SWMM are computed through several models of at each manhole, then SWMM uses a non-linear reservoir model
subsystems related to physical processes taking place in the UDS, based on one out of the three possible inltration models provided
such as, surface runoff, groundwater, ow routing, water quality by SWMM, i.e., the Horton equation, the Green-Ampt method, and
routing, inltration, snowmelt, and surface ponding (Huber et al., the curve number method. Each inltration model has its own
2010). Since the purpose of the toolbox is to facilitate the design parameters that need to be dened by the user, as explained in
of control strategies for UDS composed of actuators (e.g., weirs, (Huber et al., 2010). Likewise, if the user decides to specify the
valves, gates) within conduits and storage structures, emphasis is lateral inows at each node, it is necessary to create a time series
placed on the ow routing calculation module.
MatSWMM offers the possibility to manipulate the SWMM ow
routing calculation module, whose algorithm can be decomposed
1
into three parts as presented in Fig. 2a. First, an initialization Identication names for the UDS components.
146 ~ o-Bricen
G. Rian ~ o et al. / Environmental Modelling & Software 83 (2016) 143e154

Fig. 2. a) The MatSWMM algorithm composed of three main parts; and b) closed-loop scheme with co-simulation.

representing the pattern of direct runoff that goes into the node set of state variables H and modify parameters during the simu-
(Huber et al., 2010). lation, through the set of control actions U , as shown in Fig. 2b).
Once the lateral inow is computed, it is possible to use the It is important to notice that for RTC design, a control strategy
well-known SVE (Te Chow, 1959) to estimate the ows throughout can be implemented and tested for one of the base languages of
the drainage network (see Fig. 3). The SWMM user has a choice of MatSMWM under the assumption of instantaneous execution.
the level of sophistication used to solve these equations, i.e., the Since the loop is stopped until the setting points are changed as
steadyeow routing, the kinematicewave routing, and the desired, the setting of actuators is changed as it would be an
dynamicewave routing (Huber et al., 2010). instantaneous action, which is not what happens in reality. How-
MatSWMM has been thought to be portable, therefore, the ever, due to the exibility of the coding scheme, if a hydraulic
modied version of the SWMM model has been compiled as a C- structure requires a large amount of time (i.e., larger than the
language-based DLL, which can be used from any C-based pro- sampling time) to move from one state to another, the delay can be
gramming language such as Matlab, Python, or LabVIEW. Because modeled taking advantage of the time resolution of the simulation,
of this, MatSWMM can be easily extended for other programming since the change of setting of gates and valves in UDS tends to occur
languages using the base code.2 in minutes.
MatSWMM can be considered as a co-simulation engine that Another relevant issue is the time complexity of the MatSWMM
retrieves information of hydraulic variables from SWMM, and al- algorithm, and its computational burden when large-scale systems
lows to modify attributes in order to perform data analysis ef- are required to be managed. This issue is directly related to the time
ciently with the libraries provided for its base languages (Matlab, complexity of the proposed functionality for controlling UDSs with a
Python, and LabVIEW). With that fact in mind, the main loop of the population-dynamics-based approach. If the system has m partitions
algorithm presented in Fig. 2 can be adapted for RTC modeling, and (Barreiro-Gomez et al., 2015), the time complexity of the control
the initialization process for systematic system edition, i.e., using
the functionalities of the toolbox to modify attributes of the UDS
model programmatically and/or automatically.

2.4. Computational aspects for real-time control

Taking into consideration the MatSWMM algorithm shown in


Fig. 2a, it is possible to explain how the toolbox can be used for RTC
design. After the computation of each ow-routing step, the
enhanced functionality is executed, i.e., it is possible to retrieve a

2
The source code can be downloaded from: https://github.com/water-systems/ Fig. 3. Flow routing scheme adopted by SWMM. The lateral inow QL is computed for
MatSWMM and the documentation of the developed functionalities is available each manhole of the network, and then, it is summed up with the inow Qin , in order
at https://github.com/water-systems/MatSWMM/wiki. to compute Qout using the Saint Venant equations (SVE).
~ o-Bricen
G. Rian ~ o et al. / Environmental Modelling & Software 83 (2016) 143e154 147

algorithm is Om, i.e., it is executed in linear time (Cormen et al., data management, and system modeling.
2009).
Additionally, if information of the model is requested at each 3.1. Basic functionalities
time step, the computational burden of the simulation is going to
be increased proportionally to the number of variables k that are The default functionalities of MatSWMM are related to the
requested at each time step. computation module of SWMM, which is in charge of executing the
Thereby, the time complexity for the enhanced functionality is runoff model using the SVE. The basic functionalities are also
going to be Onm nk, where n is the number of time steps related to the systematic edition capabilities of MatSWMM. The
required for the simulation. With that fact in mind, the efciency of inherited functions from SWMM are: initializing SWMM, running a
a simulation with MatSWMM is going to be mostly dominated by step, ending sub-processes, calculating the mass balance error,
the simulation time (i.e., the time window for the rain scenario and writing a report le, and closing the application. However, as
runoff modeling), and the size of the time step. This can be proved if shown in Fig. 2, these functions can be grouped into three main
a performance test is carried out. For this test, several simulations processes that can be executed through the functions presented in
of a 2 h rain-scenario are executed leaving the value of n xed, and Table 1. Using these functions the SWMM algorithm can be repli-
modifying the values of m and k. The performance test is developed cated with the advantage of having greater control of the whole
using a computer with an Intel Core i3 2.53 GHz 64 processor, process.
and four gigabytes of RAM memory. With that in mind, getters and setters were developed to take
It is shown in Fig. 4 that both the population-dynamics-based advantage of the partition of the SWMM algorithm (see Table 2). On
control algorithm, and the use of getters at each iteration, can be the one hand, getters are executed at each iteration to obtain
solved in linear time independently, since a plane surface is formed. properties of the model as if they were measured by a sensor de-
Additionally, the simulations with the enhanced functionality takes vice, e.g., ow, velocity, volume, ooding, Froude number, etc. On
between three and 50 s, depending on the magnitudes of m and k. the other hand, setters are used to modify properties of the model,
However, if either the cardinality of H or the number of actu- either at each iteration or at each simulation scenario. One of the
ators are larger than the number of simulation steps, the time ef- setters that can be useful for RTC design is the one that allows to
ciency is going to be dominated by the large-scale nature of the modify the setting of actuators such as valves, gates, and orices. It
UDS network. can be done using the modify_settings function. In addition, before
In order to improve the efciency of the co-simulation algorithm, the simulation is initialized, properties of the model can be modi-
the use of getters (see Section 3.1) for the main loop must be limited ed using the modify_input function.
to RTC purposes. If information is required for data analysis, the use
of special functions after the simulation is encouraged. These func- 3.2. Data analysis
tions are efcient, since they extract information from the output le
without using signicant memory resources, and have the capability If the considered model is of large-scale nature, i.e., the number
to save the values of the main variables of all the objects in the of nodes and pipes is such that it is not possible to retrieve state
system (i.e., nodes, links, and catchments) in CSV les. The use of variables or modify the setting of actuators easily. Hence, getters
special functions for data analysis is explained in Section 3.2. and setters become inefcient to manage data, since they can only
be executed during the main loop. Therefore, there are special
methods to handle large data sets and large groups of objects (see
Table 3).
For instance, it is required to extract all the results of the
simulation, which can be saved in a .csv le that is easily readable
by using any of the base programming languages. Additionally,
special data structures were adapted to the SWMM model in order
to characterize any network with canals, tanks, and actuators.
Because of the structure of SWMM, graphs (modeled by the
SWMMGraph class) are used to t the model properly. Additionally,
when convergence topologies prevail, the structure can be simpli-
ed as a tree (modeled by the SWMMTree class). The enhanced
functionality related to these data structures is oriented to split the
model into manageable pieces. Thus, the process of extracting in-
formation and modifying parameters can be done efciently,
through breath-rst and deep-rst search algorithms (Cormen
et al., 2009) (also included in MatSWMM for Python). This can be
useful when implementing decentralized control, testing a fault-
detection strategy (Tornil-Sin et al., 2012), or simplifying the
network topology, using an equivalent one, as done in (Ocampo-
Martinez, 2010) and (Rian ~ o Bricen
~ o et al., 2015).
Fig. 4. Performance of the proposed enhanced functionality. The duration of several
simulations with a xed number of steps is computed. At each iteration k variables are
extracted from the SWMM model, and m partitions of the system are controlled. 3.3. System modeling

MatSWMM is useful to characterize UDS through a simplied


3. MatSWMM functionalities control-oriented model (COM) (Garca et al., 2015). Nowadays, two
COMs have been included in MatSWMM, i.e., the virtual-tank (VT)
In this section, a detailed explanation of the MatSWMM func- based model (Ocampo-Martinez, 2010), and the Muskingum model
tionalities is given. Emphasis is placed on basic functionalities, most (Te Chow, 1959; Bolea et al., 2007), both explained in Section 5. In
of them inherited from SWMM, e.g., systematic system edition, order to obtain a COM with MatSWMM, it is necessary to have the
148 ~ o-Bricen
G. Rian ~ o et al. / Environmental Modelling & Software 83 (2016) 143e154

Table 1
MatSWMM basic functionalities.

Function Description

initialize It opens the les required to run a SWMM simulation, and starts it.
run_step It advances the simulation by one routing time step.
is_over It determines whether or not the simulation is over.
Finish It saves all the results of the simulation and closes the program to run a new simulation.
run_simulation It runs a SWMM simulation.

Table 2
Getters and setters included in MatSWMM.

Function Description

step_get It retrieves the values of a specic property of multiple objects while running the simulation.
get_from_input It returns the value of the attribute in the .inp le.
get_all It returns all the objects IDs of a certain type (e.g., NODES, LINK, SUBCATCH, STORAGE, OUTFALL, JUNCTION) and the value of one of their properties.
modify_input It modies a specic attribute from the .inp le.
modify_settings It modies the setting of several orices during the simulation.

Table 3
Data management functionalities.

Function Description

get_incidence_matrix It returns the graph representation of the network in matrix form.


save_results It saves all the results of the simulation in .csv les, organized in four folders in the workspace directory. The folders are related to the type of
objects (Link, Node, Subcatch). A folder called Time with information of the step size is also saved.
create_graph It creates a graph data structure in Python that represents the network as a connection of nodes (manholes) and conduits (canals and pipes).

real data of input and output ows of the structure that is going to (DWN). In order to make the analogy, it is also taken into account
be characterized (e.g., canals or pipes). It is possible to use the that the UDS is mainly associated to the convergence topology
SWMM model included in MatSWMM to obtain accurate data that shown in Fig. 5a as in (Barreiro-Gomez et al., 2015), while the DWN
represents the behavior of the system, as it was a virtual reality (i.e., is mainly associated to the divergence topology shown in Fig. 5b) as
the physical behavior of the system). Furthermore, a simulation can in (Ramirez-Llanos and Quijano, 2010).
be run and data from the model can be easily extracted with First of all, the analogy between elements in the population
MatSWMM. Those data sets can be used to calibrate a COM and dynamics approach with elements in either USD or DWN is pre-
then, it can be used for the design of model-based controllers. sented in Table 4.
For instance, consider the system with the convergence topol-
4. Population-dynamics-based controllers ogy shown in Fig. 5a with m2Z source reservoirs (strategies). The
total ow through the system (population mass) is denoted by
A detailed description of the distributed controllers based on Q t2 , which corresponds to the inow of the receptor reservoir
population dynamics for MatSWMM is presented in this section. In in the convergence topology. Hence, Q t is composed of a large and
order to introduce this concept, rst a mathematical framework of nite amount of ow units (agents). Each ow-unit is assigned to
the population dynamics is presented, and then special emphasis an outow of the source reservoirs, where the set of source reser-
on the distributed replicator dynamics, the Smith dynamics, and voirs is denoted by S f1; ; mg.
the projection dynamics is made. Furthermore, a proof of concept On the other hand, regarding the divergence topology shown in
example by using the mentioned control module is shown. Finally, Fig. 5b, there are m2Z receptor reservoirs (strategies). Similarly
the results exhibit the performance of the distributed real-time as in the convergence topology case, Q t2 corresponds to the
population-dynamics-based controllers by using the developed outow of the source reservoir in the divergence topology. Each
toolbox functionalities. ow-unit is assigned to an inow of the receptor reservoirs, and
then the set of receptor reservoirs is denoted by S f1; ; mg.
4.1. Notation

Column vectors are denoted by lower-case letters and bold style,


e.g., p. Scalars are denoted by non-bold style, e.g., n. Sets are
denoted by calligraphic style, e.g., S . The column vector of m
unitary entries is denoted by 1m 2m, i.e., 1m 1 1u . The
cardinality of a set X is denoted by jX j. The set of real numbers is
denoted by , the set of non-negative real numbers is denoted by
, and the set of strictly positive real numbers is denoted by .
Similarly, the set of positive integer numbers is denoted by Z.

4.1.1. Population dynamics Fig. 5. a) Convergence topology, i.e., m source reservoirs whose outows converge to a
The population dynamics approach is presented by making an receptor reservoir; and b) divergence topology, i.e., a source reservoir (vs ) whose
analogy with either an UDS or with a drinking water network outow diverges to m receptor reservoirs (vr ).
~ o-Bricen
G. Rian ~ o et al. / Environmental Modelling & Software 83 (2016) 143e154 149

Table 4
Equivalence between population dynamics and UDS/DWN.

Population dynamics UDS DWN

Population System System


Strategy Source reservoirs Receptor reservoirs
Population mass Total inow to receptor reservoir Total outow source reservoir
Agent Flow unit Flow unit
Proportion of agents Proportion of ow Proportion of ow
Strategic distribution Flow distribution in source reservoirs Flow distribution in receptor reservoirs
Fitness of a strategy Current volume Available volume capacity

In both the convergence and divergence topologies, the scalar


pi t is the proportion of ow units assigned to each ow associated
to the reservoir i2S as a percentage, i.e., the outow/inow for the
ith reservoir in the convergence/divergence case is given by
pi tQ t. The vector pt2m is the ow proportion distribution
involving the m reservoirs according to the topology. The set of the
possible distributions of ow is given by a simplex
 u 
D pt2m
: pt 1m 1 ;

and the interior of the set of the possible distributions of ow is


given by the set
 u 
intD pt2m
: pt 1m 1 :

Finally, the tangent space of the set of possible distributions of


ow is dened as
 
TD zt2m : ztu 1m 0 :

For the convergence topology, each ow unit is assigned to each


reservoir i2S depending on the current volume, which is
described by a function denoted by Fi pt. Then, more outow is
assigned to those reservoirs close to be lled up impeding over-
Fig. 6. Proper selection of tness functions for convergence topology a) and b), and
ows in them. In contrast, for the divergence topology, each ow
divergence topology c) and d). Correspondence is as follows: a) increasing tness
unit is assigned to each reservoir i2S depending on the current function with respect to volume; b) decreasing relation existing between proportion of
volume capacity, which is described by a function Fi pt. There- agents and volume for convergence topology; c) decreasing tness function with
fore, less inow is assigned to those reservoirs close to be lled up. respect to volume; and d) increasing relation existing between proportion of agents
and volume for divergence topology.
The design of the population-dynamics-based controllers are
given by the proper selection of the tness functions that dene the
incentives for the proportion of agents to choose a particular
game). Contrary, for the divergence topology counterpart (see
strategy. The proper selection of the tness functions is further
Fig. 5b)), the tness functions can be selected decreasing with
discussed bellow and it depends on the type of topology, i.e., an
respect to the current volume, e.g., the error with respect to the
appropriate selection of the tness function depends on if the
maximum capacity volume as in (Ramirez-Llanos and Quijano,
system has a convergence or divergence topology. Furthermore, it is
2010) (see Fig. 6c)). When a proportion of agents is increased it is
necessary that the tness functions satisfy conditions to obtain a
expected that the corresponding volume increases (see Fig. 6d)).
class of population game known as stable game (Hofbauer and
Consequently, due to the fact that tness functions are increasing
Sandholm, 2009).
with respect to the volume, the tness function decreases with
Denition 1. The game Fp is stable if the Jacobian matrix
respect to the proportion of agents (necessary condition for a stable
J DFp is negative semi-denite with respect to the tangent space
game).
T D (Hofbauer and Sandholm, 2009), i.e.,

4.1.2. Particular distributed population dynamics


zu J z  0; for all z2T D; p2D:
The traditional replicator dynamics, Smith dynamics, and pro-
Then, it implies that a game is stable if the tness functions are jection dynamics equations are part of the six fundamental popu-
decreasing with respect to the proportion of agents. lation dynamics (Sandholm, 2010), which require full information
Notice that for the convergence topology (see Fig. 5a), the tness (i.e., all strategies associated to reservoirs need information about
functions can be selected increasing with respect to the current all other reservoir states in order to evolve). However, the distrib-
volumes as in (Barreiro-Gomez et al., 2015) (see Fig. 6a)). For the uted population dynamics are deduced in (Barreiro-Gomez et al.,
convergence topology, when a proportion of agents is increased, it 2016) from a local revision protocol that only needs partial infor-
is expected that the corresponding volume decreases (see Fig. 6b)). mation. Due to the fact that only local information is needed, then
Consequently, due to the fact that the tness function is increasing there is an undirected non-complete connected graph describing
with respect to the volume, the tness function decreases with possible interaction denoted by G V ; E , where V is the set of
respect to the proportion of agents (necessary condition for a stable nodes, which represents the reservoirs, and E 3fi; j : i; j2V g is
150 ~ o-Bricen
G. Rian ~ o et al. / Environmental Modelling & Software 83 (2016) 143e154

the set of links representing the information sharing within the mains and stormwater), and the outows (to both sewage mains
system. Furthermore, the set of neighbors of the node i2V is given and street) of the reservoir. For the model developed in MatSWMM,
by N i fj : i; j2E g. Notice that i;N i , and that N i s, for all the outow of a given tank (virtual or real) is assumed to be pro-
i2V since G is connected. portional to the volume of the tank. Therefore, the model of a tank
The distributed replicator dynamics are given by is given by dVdti t qin
i t  Ki Vi t, where Vi is the volume stored in
0 1 the i-th tank, qin i is the total inow to the i-th tank, and Ki is the
dpi t X X volume/ow conversion (VFC) coefcient. As SWMM provides
pi t@Fi pt pj t pj tFj ptA; for all i2S : measures for both, the volume and the outow of the reservoirs,
dt j2N j2N
i i the VFC coefcient for each reservoir can be computed via a least-
squares algorithm given by
The distributed Smith dynamics are given by
Ztf
dpi t X    2
pj t Fi pt  Fj pt Ki arg min qout
i t  Ki Vi t dt; (1)
dt j2N i
Ki
0
X  
 pi t Fj pt  Fi pt ;
j2N
where tf is the total simulation time, and qout
i is the total outow of
i
the i-th reservoir. Finally, the maximum capacity volume of the i-th
where , max,; 0. And nally, the distributed projection dy- tank is denoted by Vimax.
namics are given by In order to solve the leastesquares algorithm to calibrate the
linear reservoir model using MatSWMM, a discretized variant of (1)
dpi t   X can be proposed as follows:
N i Fi pt  Fj pt; for all i2S :
dt j2N 2
Ki arg min qout  Ki vi :
i
i (2)
Ki
MatSWMM includes a function that can be used to implement a
population-dynamics-based controller for UDS with divergence In this way, the parameter Ki for the ith reservoir can be
and convergence topologies (i.e., the pdyncontrol function). It in- computed regardless of either the form of the outow or the
cludes the Smith, the projection, and the replicator dynamics. volume.

5. Models of UDS 5.1.2. Muskingum model


The Muskingum model describes the water ow through UDSs
It is possible to characterize any UDS as a composition of two based on the conservation mass principle. The mass balance for the
topologies, i.e., convergence and divergence. As shown in Fig. 5a, ith reservoir in the UDS is given by
the convergence topology is related to the case where the ow of
several storage units or pipes is merged in a single receptor struc- dVi t
ture. Furthermore, the divergence topology, shown in Fig. 5b, is qin out
i t  qi t;
dt
formed when the ow of a single structure is distributed along
more than one receptor. The former one prevails in stormwater UDS and the relation between its inows and outows (Te Chow, 1959)
while the latter is commonly related to drinking water networks is given by
(DWN). However, both topologies are used to build combined
sewer networks where not only stormwater is transported but also Vi t Aqin out
i t Bqi t;
sanitary and wastewater ows.
MatSWMM has been designed to characterize both topologies where A and B are parameters for the model calibration. Similarly to
easily, guaranteeing a proper modeling of the run-off phenomenon the case of the linear reservoir, the estimation of parameters A and
throughout large networks and allowing the user to handle the B for the discretized Muskingum model is done by solving (2). This
problem of ow assignation with an optimization-based controller problem has been solved analytically in (Aldama, 1990), then, both
for each case, as the one described in (Barreiro-Gomez et al., 2015). A and B can be computed in terms of the inow, outow, and stored
volume by using the following expressions:
5.1. Control-oriented models  out T out T in  out T in T out
q qi vi qi  qi qi vi qi
Ai
i
T
T 2 ; (3)
The SVE used by SWMM to simulate the run-off throughout the T
qin qin qout qout  qout qin
network describe in a quite high level of detail the behavior of the i i i i i i
system. Usually, this level of detail is not required in RTC applica-
tions and COMs are used instead. As stated before, MatSWMM in-  T in T out  out T in T in
corporates the so-called VT-based model, which is a widely used qin
i qi vi qi  qi qi v i qi
Bi

T
T 2 : (4)
COM for modeling UDS, and the Muskingum model, also used for T
qin qin qout qout  qout qin
predictive control (Gomez et al., 2002; Manteco n et al., 2002). i i i i i i

By expressing the outows as function of Vi t, qin


i t, A, and B, it
5.1.1. Virtual tanks model
is obtained that dVi t=dt qin
i t1 A=B  Vi t=B, then
In the virtual reservoir approach, the UDS is divided into a set of
interconnected real and VTs. According to (Ocampo-Martinez, dVi t
2010), a VT is a storage element that represents the total volume gqin
i t  Ki vi t;
dt
of sewage inside the sewer mains associated with a determined
portion of a given network. The volume is computed through the where g 1 A=B, and Ki 1=B. Furthermore, Ki > 0 scales the
mass balance of the stored volume, the inows (from both sewage outow, and it can be seen as the discharge coefcient of the
~ o-Bricen
G. Rian ~ o et al. / Environmental Modelling & Software 83 (2016) 143e154 151

reservoir. However, for some particular cases Ki < 0, and the UDS because of the unavailability of land for infrastructure (Barro
considered system output can show a non-minimum phase et al., 2014). Finally, as it is shown in Fig. 7, the rst division
behavior (Bolea et al., 2007). carries water to a tank with three different bodies, the second di-
vision meets an outfall and the third division is split in two
5.2. Simulation-oriented models branches, carrying water to a waste water treatment plant (WWTP)
with two storage units.
MatSWMM includes the SWMM model as its simulation- The control objective in this model is to spread efciently ows
oriented model (Garca et al., 2015). SWMM is known as an accu- at each bifurcation, handling the differences between reservoirs,
rate physically-based model that describes the propagation of a i.e., differences between their location, elevation, and dimensions.
wave in an open channel through the SVE. It is based on the con- To this end, a partition of the system is done as proposed in
servation of mass and momentum principles (Te Chow, 1959). One (Barreiro-Gomez et al., 2015) and the distributed control based on
of the best features of SWMM consists on representing the UDS as a population dynamics included into MatSWMM is used.
composition of nodes and links, which facilitates the modeling in Because of the nature of the system, the tness function that
discrete time of the physical prototype and the mathematical so- will be used by the controller to solve the optimal assignment
lution of the non-uniform ow SVE. problem is related to the occupancy rate or the capacity of each
The main variable in the links is the ow rate, and the solution to tank, which is equivalent to the normalized volume, as presented in
the ow-routing problem is for the average ow in each link, which Table 4.
is assumed to be constant over a time step. For each step of the An example of the code that can be used in Matlab with
simulation, the velocity of the ow, and the depth of each link is MatSWMM to implement the control strategy in the rst diver-
calculated. In the case of the nodes, the main variable is the pres- gence zone is outlined below:
sure head, which is assumed to be changing in time but constant First of all, some variables are declared, such as the SWMM input

over a time step (reniFerreri). le path, initial conditions for the setting of gates, and the IDs of
The continuity and the momentum SVE are reported in (Te tanks and gates. Then, the three parts of the MatSWMM algorithm
Chow, 1959). The numerical integration of the two SVE is accom- are invoked, i.e., the initialization, the main-loop, and the closing of
plished with a RK algorithm (Eslamian, 2014). It has been shown in the program. Within the main-loop the population dynamics-based
(reniFerreri) and (Huber et al., 2010) that the SWMM model and its controller is used to manage the ows of one of the partitions of the
algorithm is stable and accurate through the calculation of three system, which is composed of three on-line reservoirs, i.e., T1 , T2 ,
types of mass-balance errors, i.e., runoff, ow-routing, and water and T3 . Finally, information of the volumes at each reservoir is
quality errors. This fact guarantees that the SWMM model is extracted for data analysis.
appropriate to model UDS with a high level of precision, i.e., better The same procedure is applicable to implement RTC on the
than the one obtained with the COMs. remaining divisions. However, the controller should be tuned
depending on the speed of the dynamics, and the type of dy-
6. Examples of application namics (i.e., Smith, projection, or replicator). The results of a
scenario where no-control strategy is implemented are shown in
This section illustrates some features of MatSWMM for RTC by Fig. 8. The distribution of water volumes is not efcient, since
means of a divergent UDS case study (see Fig. 7). The system is reservoirs T2 , T3 , and T4 are overused, i.e., they are operating at its
composed by four sub-catchments that are affected by a precipi- maximum capacity, while the others are underused, i.e., their
tation event, the precipitation becomes runoff, and then, it is used capacity is less than 100%. Additionally, 6:99  103 m3 of
transported through a system of pipes that is divided into three ooding appear, due to the excess of water that ows out from the
branches. After the bifurcation, typical on-line storage units, like overused tanks. This problem may occur when designing hy-
the ones described (Barro et al., 2014), are used to handle and retain draulic infrastructure based on a static design storm, i.e., the
the rise of ow. The storage units have different dimensions and are climate variations due to the heat island effect were not consid-
located at different elevations. These differences are common in ered (Moonen et al., 2012).
152 ~ o-Bricen
G. Rian ~ o et al. / Environmental Modelling & Software 83 (2016) 143e154

Fig. 7. Divergence case study a) conceptual scheme and input direct runoff hydrograph; and b) system implementation in SWMM.

Fig. 8. Occupancy rate, or capacity of storage tanks when no control strategy is applied, a) Capacity of reservoirs T1 , T2 , and T3 ; b) capacity of reservoirs T3 , T4 , and T5 ; c) capacity of
reservoirs T7 , and T8 .

When the distributed population-dynamics-based controller is Additionally, tunning the controller can be easily done for a
implemented at each of the nodes where the ow diverges, physical implementation (even empirically), because of the
ooding is prevented and the water is better distributed. The re- advantage of programming the SWMM model, which is accurate
sults when RTC is implemented are obtained for the projection, the (reniFerreri), through MatSWMM, in order to obtain the results of
replicator, and the Smith dynamics (see Fig. 9). several simulations systematically.
The simulation with MatSWMM allows to identify the main
advantage of implementing RTC, which is to distribute efciently
ows in divergent and convergent sections of the UDS to minimize 6.1. Other applications
the total ooding throughout the network. Throughout this
approach, it is possible to handle dynamic-rain scenarios, different Because of the capability that MatSWMM brings to its users for
to the static ones used for design, with the already built editing systematically any UDS implemented with the SWMM
infrastructure. framework, it is possible to extend the scope of MatSWMM to
optimal design of UDS, since most of the optimization problems
~ o-Bricen
G. Rian ~ o et al. / Environmental Modelling & Software 83 (2016) 143e154 153

Fig. 9. (a, b, c) capacity of tanks when the RTC strategy with the projection dynamics is applied; (d, e, f) capacity of tanks when the RTC strategy with the replicator dynamics is
applied; and (g, h, i) capacity of tanks when the RTC strategy with the Smith dynamics is applied.

Fig. 10. LabVIEW interface based on MatSWMM.


154 ~ o-Bricen
G. Rian ~ o et al. / Environmental Modelling & Software 83 (2016) 143e154

proposed for UDS can be solved with heuristics, but require values for simulation of integrated urban drainage systems. Environ. Model. Softw. 22
(8), 1184e1195.
of variables from an efcient simulation-oriented model (e.g., total
Aldama, A.A., 1990. Least-squares parameter estimation for muskingum ood
ooding, volumes, etc.) (Maier et al., 2014; Marques et al., 2015; routing. J. Hydraul. Eng. 116 (4), 580e586.
Palumbo et al., 2014). Barreiro-Gomez, J., Obando, G., Rian ~ o Bricen
~ o, G., Quijano, N., Ocampo Martinez, C.,
Also, interfaces such as the one presented in Fig. 10, can be 2015. Decentralized control for urban drainage systems via population dy-
namics: bogota  case study. In: Proceedings of the 14th European Control Con-
implemented easily with the MatSWMM basic functionalities for ference, Linz, Austria, pp. 2431e2436.
LabVIEW, to characterize a physical UDS. Additionally, the ArcPy Barreiro-Gomez, J., Obando, G., Quijano, N., 2016. Distributed population dynamics:
library for Python can be used in parallel with the MatSWMM li- optimization and control applications. IEEE Trans. Syst. Man Cybern. 99, 1e11.
Barro, J., Comas, P., Malgrat, P., Sunyer, D., 2014. Manual nacional de recomenda-
brary in order to extract GIS data and solve the problem of optimal ciones para el disen ~ o de tanques de tormentas, pp. 32e33.
positioning of UDS structures, specically, on-line and off-line Bolea, Y., Puig, V., Blesa, J., 2007. On the use of the Muskingum model in real-time
storm tanks (Barro et al., 2014). sewer network control. In: Proceedings of the 6th European Control Confer-
ence, Kos, Greecde, pp. 3717e3723.
With that in mind, the capabilities of MatSWMM can be useful Butler, D., Schtze, M., 2005. Integrating simulation models with a view to optimal
for optimal design of infrastructures, considering not only the control of urban wastewater systems. Environ. Model. Softw. 20 (4), 415e426.
typical rain-scenario and a critical service operation condition, but Cormen, T.H., Leiserson, L.E., Rivest, R., Stein, C., 2009. Introduction to Algorithms.
MIT Press.
also taking into consideration the possibility of including sensors Eslamian, S., 2014. Handbook of Engineering Hydrology: Fundamentals and Ap-
and actuators before the commissioning of the system, and to plications. CRC Press.
analyze how these elements a their proper management can Garca, L., Barreiro-Gomez, J., Escobar, E., Te llez, D., Quijano, N., Ocampo-
Martinez, C., 2015. Modeling and real-time control of urban drainage systems: a
signicantly improve the performance of UDS.
review. Adv. Water Resour. 85, 120e132.
Gomez, M., Rodellar, J., Manteco  n, J.A., 2002. Predictive control method for
7. Conclusions and further work decentralized operation of irrigation canals. Appl. Math. Model. 26 (11),
1039e1056.
Hofbauer, J., Sandholm, W.H., 2009. Stable games and their dynamics. J. Econ.
This manuscript has presented a new open-source toolbox for Theory 144 (4), 1665e1693.
the design of RTC in UDS, i.e., MatSWMM, which runs on Matlab, Huber, W.C., Rossman, L.A., Dickinson, R., 2010. EPA Storm Water Management
LabVIEW, and Python. MatSWMM includes a variety of function- Model SWMM 5.0. National Risk Management Research Laboratory, Ofce of
Research and Development, US Environmental Protection Agency.
alities to edit systematically any UDS implemented on the SWMM Maier, H.R., Kapelan, Z., Kasprzyk, J., Kollat, J., Matott, L.S., Cunha, M.C., Dandy, G.C.,
framework, during and after a rainfall simulation. These features Gibbs, M.S., Keedwell, E., Marchi, A., 2014. Evolutionary algorithms and other
make MatSWMM suited for both educational and research pur- metaheuristics in water resources: current status, research challenges and
future directions. Environ. Model. Softw. 62, 271e299.
poses, specially for the design of RTC applied to UDS. Additionally, it Manteco n, J.A., Gomez, M., Rodellar, J., 2002. A Simulink-based scheme for simu-
is possible to test heuristic algorithms for optimal design and lation of irrigation canal control systems. Simulation 78 (8), 485e493.
positioning of retention structures in UDS, since the only re- Marques, J., Cunha, M., Savi c, D.A., 2015. Multi-objective optimization of water
distribution systems based on a real options approach. Environ. Model. Softw.
quirements for these tests are the results from the simulation, and a 63, 1e13.
function to edit the properties of the system elements. As a matter Martin, A., 2012. Mathematical Optimization of Water Networks. Springer Basel AG.
of fact, MatSWMM is currently used by several masters, and Ph.D. Moonen, P., Defraeye, T., Dorer, V., Blocken, B., Carmeliet, J., 2012. Urban physics:
effect of the micro-climate on comfort, health and energy demand. Front.
students, and has an active Github repository.3 Among future
Archit. Res. 1 (3), 197e228.
projects, there are supporting Linux-based OSs, adding parallel Ocampo-Martinez, C., 2010. Model Predictive Control of Wastewater Systems.
computing techniques for optimal design of UDS, and extending the Springer Verlag.
toolbox including more control strategies, such as optimization- Palumbo, A., Cimorelli, L., Covelli, C., Cozzolino, L., Mucherino, C., Pianese, D., 2014.
Optimal design of urban drainage networks. Civ. Eng. Environ. Syst. 31 (1),
based controllers (e.g., MPC, LQR, evolutionary-based controllers), 79e96.
and heuristic algorithms (e.g., rule-based, fuzzy control). The Pathirana, A., 2015. SWMM5 1.1.0.3: Python Package. https://pypi.python.org/pypi/
toolbox is going to be enhanced for realizable applications such as SWMM5.
Press, W.H., Teukolsky, S.A., Vetterling, W.T., Flannery, B.P., 1996. Numerical Recipes
optimal positioning of UDS elements (e.g., sensors, actuators, in C, vol. 2. Citeseer.
retention structures), based geographical information provided by Price, R.K., Vojinovic, Z., 2011. Urban hydroinformatics: data, models, and decision
new GIS capabilities. Also, as more features are developed, more support for integrated urban water management. IWA Publ.
Ramirez-Llanos, E., Quijano, N., 2010. A population dynamics approach for the water
case studies are going to be included into the repository. Any sug- distribution problem. Int. J. Control 83 (9), 1947e1964.
gestion and/or bug report are very welcome. G. Freni, G. B. Ferreri, P. Tomaselli, Ability of software SWMM to simulate transient
sewer smooth pressurization, NOVATECH Report.
~ o Bricen
Rian ~ o, G., Ramirez-Jaime, A., Barreiro-Gomez, J., Quijano, N., Ocampo
Acknowledgments Martinez, C., 2015. Co-simulation for the design of controllers in urban drainage
systems, in: proceedings of the 2nd Colombian Conference on Automatic
Authors would like to thank Mexichem (Colombia) for sup- Control. Manizales Colomb. 1e6.
Sandholm, W.H., 2010. Population Games and Evolutionary Dynamics, Economic
porting this research through the project Drenaje Urbano y Cambio
Learning and Social Evolution. MIT Press, Cambridge, Mass.
Climtico: hacia los sistemas de alcantarillado del futuro. Fase II. Stallman, R., 2002. Free software, free society: selected essays of Richard M. Stall-
COLCIENCIAS 633/2013. Also, this work has been partially sup- man. Lulu.
ported by the project ECOCIS (Ref. DPI2013-48243-C2-1-R). J. Te Chow, V., 1959. Open Channel Hydraulics. McGraw-Hill Book Company, Inc, New
York.
Barreiro-Gomez is partially supported by COLCIENCIAS-COLFU- Tornil-Sin, S., Ocampo-Martinez, C., Puig, V., Escobet, T., 2012. Robust fault detection
TURO and Agencia de Gestio dAjust Universitaris i de Recerca of non-linear systems using set-membership state estimation based on
AGAUR. constraint satisfaction. Eng. Appl. Artif. Intell. 25 (1), 1e10.

References

derl, M., Rauch, W., 2007. City drainean open source approach
Achleitner, S., Mo

3
The link to the repository is: https://github.com/water-systems/MatSWMM.git.

You might also like