Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
Lewis A. Rossman
US Environmental Protection Agency
Cincinnati, Ohio 45268
Abstract
The EPANET Programmer’s Toolkit is a collection of functions that helps
simplify computer programming of water distribution network analyses. The
functions can be used to read in a pipe network description file, modify selected
component properties, run multiple hydraulic and water quality analyses, retrieve
selected output results, and write formatted output reports. The toolkit is especially
useful for developing applications, such as optimization models, that require running
many network analyses with modified input parameters. It can also simplify adding
analysis capabilities to integrated network modeling environments based on CAD,
GIS, and database packages.
Introduction
EPANET (Rossman, 1994) is a computer program that analyzes hydraulic and
water quality behavior in water distribution systems. It is one of the few full-featured
pipe network analysis packages for which source code is readily available. This code,
which contains both a stand-alone network solver and a graphical user interface, has
made it possible for different research and application groups around the world to
adapt the model to their own specific needs. Typical custom uses of EPANET which
have embedded the solver in other pieces of software have included linkages to GIS,
network parameter estimation programs, and several types of network optimization
models. In addition, several commercial vendors have adopted portions of the
EPANET engine in their products.
These uses of the model by third party researchers and developers were not
foreseen when the original code was first written. Thus the organization of its code
was not optimized for what might be termed “plug and play” use by others. Recently,
the entire EPANET package has been upgraded to a full 32-bit Windows application
that corrects some of the shortcomings in the original release. Advantage has been
taken of this opportunity to re-engineer the network solver into a programmer’s
toolkit. The toolkit consists of a collection of function calls residing in a dynamic link
formats. For extended period simulations both of these files contain results only at
fixed time intervals as specified by the user. The actual simulations can proceed at
much smaller time steps.
Toolkit Functions
The toolkit consists of a library of functions that developers can call to
perform various network modeling tasks. A description of the major functions in the
toolkit follows.
ENopenH()
This function initializes the hydraulic solver included in EPANET. It must be called
once prior to initiating a hydraulic analysis.
ENsolveH(saveflag)
This function runs a complete hydraulic analysis. The saveflag argument indicates
whether results for a steady state run should be saved to an internal scratch file or not
number for the parameter of interest, and a variable to contain the retrieved value of
the parameter. Node parameters that can be retrieved with this function include
elevation, demand, hydraulic head, and pressure. Link parameters include diameter,
length, roughness coefficient, status, flow rate, velocity, and headloss.
ENcloseH()
This function closes down the hydraulic solver and frees all memory associated with
it. It should be called after all hydraulic processing has been finished.
ENsaveH()
This function saves the results generated from a single hydraulic analysis (steady state
or extended period) to a binary output file. Only results for a user-specified reporting
time interval are saved. This function must be called if a binary output file is to be
saved for post-processing or if the ENreport() function will be used to generate a
hydraulics output report (see below). It does not have to be called if a water quality
analysis will be made subsequently.
ENsolveQ()
This function uses the results from an extended period hydraulic simulation to run a
water quality simulation. It automatically saves both hydraulic and water quality
results at specified reporting intervals to the binary output file.
ENreport()
This function writes output results as readable text to the report file specified in the
ENopen() function. The format of the report is specified through commands supplied
in the input file.
ENclose()
This function closes down the EPANET modeling system. It frees all allocated
memory and closes all open files. It should be the last function called after all
processing has been made.
All of these functions return an integer code indicating what type of error, if
any occurred. A more complete description of these functions, including argument
types and parameter codes, is available in the EPANET Programmer’s Toolkit
Manual (Rossman, 1999). A simple example of how these functions can be pieced
together is provided by the code that comprises the ENepanet() function. In C the
function looks as follows:
Example Application
A simple application that shows off the advantages of the toolkit is the
construction of an interactive fire flow analyzer that can be run under Microsoft Excel
or other spreadsheet programs with macro language capabilities. Network fire flow
analysis asks what is the maximum flow available at a specific node at a given
pressure (typically 20 psi [138 kPa]). One can always determine this value through
trial and error by running a succession of simulations, increasing the demand at the
node of interest until the pressure drops to the required value. Boulos et al. (1997)
presented a more systematic method for carrying out this process that usually
converges in 4 to 6 iterations. The EPANET Programmers Toolkit was used in
conjunction with Microsoft Excel and Visual Basic for Applications (VBA) to
implement this procedure. This application is purely for demonstration purposes since
a number of commercial network modeling packages already include automated fire
flow analysis capabilities much more powerful than what is presented here.
Figure 3 shows the Excel workbook developed for this application. It consists
of a worksheet where the EPANET input file is created and edited, an additional
menu item added to Excel’s Tools menu that initiates the fire flow analysis, and a Fire
Flow dialog form that implements the procedure. In the dialog form the user enters
the ID label of the junction to be analyzed and the desired pressure target. Clicking
the Fire Flow button begins the calculations and reports the result. This process can
be repeated for different junctions and pressure targets. Clicking the Close button
dismisses the dialog and returns the user to the worksheet.
The main VBA code that implements the process is contained in three
procedures:
1. The dialog form’s OnShow procedure is called when the user selects the Fire
Flow option off of Excel’s Tools menu. The procedure copies the network
description from the worksheet into a temporary input file, calls ENopen() to open
the EPANET modeling system, and calls ENopenH() to initialize the hydraulics
solver.
2. The OnClick procedure is called when the user clicks the Fire Flow button on the
dialog form. This procedure retrieves the junction ID and pressure values entered
by the user and then makes repeated calls to the following functions until the
search for the fire flow converges:
Conclusions
The Programmer’s Toolkit provides the flexibility that network modelers need
to employ EPANET’s computational engine in a variety of pipe network modeling
and analysis efforts without the burden of having to modify its source code. It is
particularly useful for running large numbers of simulations efficiently. It also
simplifies the task of embedding the EPANET engine in integrated network modeling
environments that utilize CAD, GIS, and database packages. The toolkit can improve
the productivity of researchers and developers involved in water distribution system
modeling.
References
Downloaded from ascelibrary.org by DEAKIN UNIVERSITY on 08/10/15. Copyright ASCE. For personal use only; all rights reserved.
Boccelli, D.L. et al. (1998). “Optimal scheduling model for booster disinfection in
water distribution networks”, Jour. Water Res. Planning & Mgmt., 124:99.
Boulos, P.F., Rossman, L.A., Orr, C-H., Heath, J.E., and Meyer, M.S. (1997). “Fire
flow computation with network models”, Jour. AWWA, 89(2):51-56.
Dandy, G.C., Simpson, A.R., and Murphy, L.J. (1996). “An improved genetic
algorithm for pipe network optimization”, Water Resour. Res., 32(2):449-458.
TANK
WRPMD'99
VALVE
JUNCTION
PUMP
WRPMD 1999
[TITLE]
Sample Pipe Network
[JUNCTIONS]
; Elev. Demand
;ID ft. gpm
;----------------------------
1 1090
101 1090
2 1122
Downloaded from ascelibrary.org by DEAKIN UNIVERSITY on 08/10/15. Copyright ASCE. For personal use only; all rights reserved.
3 1138
4 1157 500
5 1180
< etc.>
[TANKS]
; Elev. Init. Min. Max. Diam.
;ID ft. Level Level Level ft.
;-------------------------------------
17 910
18 080 10 0 20 50
[PIPES]
; From To Length Diam.
;ID Node Node ft. in. C-factor
;----------------------------------------
1 1 2 1500 12 130
2 2 3 1000 8 130
3 3 4 1200 10 120
4 4 5 2000 10 120
< etc. >
[PUMPS]
; From To Head Flow
;ID Node Node ft. gpm
;-------------------------------
171 17 101 456 2700
[VALVES]
; From To Setting
;ID Node Node Type psi
;--------------------------------
25 21 23 PRV 75
[END]
WRPMD'99
Figure 3. Interactive Fire Flow Analyzer
WRPMD 1999