EPANET-MSX 2.0 User Manual
United States
Environmental Protection
Agency
EPA/600/R-22/199 | July 2023 | www.epa.gov/research
Office of Research and Development
Center for Environmental Solutions and Emergency Response

-------
4%	United States
Ai n>i Environmental Protection
^1 Mm Agency
EPA/600/R-22/199
EPANET-MSX 2.0 User Manual
Feng Shang
Lewis A. Rossman
James G. Uber
Water Infrastructure Division
Center for Environmental Solutions and Emergency Response
U.S. Environmental Protection Agency
Cincinnati, Ohio 45268
\7 :
PANET

-------
CONTENTS
DISCLAIMER	i
1	INTRODU CTTION	1
2	CONCEPTUAL FRAMEWORK	3
2.1	Material Transport		4
2.2	Chemical Reactions		4
2.3	Full Network Solution		5
2.4	Reaction System Solution		7
2.5	Pipe Surface Discretization		7
2.6	Dispersion Modeling		8
2.7	Model Implementation		9
3	PROGRAM USAGE	10
3.1	Example Command Line Run		11
3.2	Example Toolkit Usage		20
3.3	Using Compiled Reaction Models 		23
4	INPUT FILE FORMAT	24
4.1	[TITLE] 		26
4.2	[OPTIONS]		26
4.3	[SPECIES]		27
4.4	[COEFFICIENTS]		28
4.5	[TERMS]		29
4.6	[PIPES]		30
4.7	[TANKS]		31
4.8	[SOURCES] 		31
4.9	[QUALITY] 		32
4.10	[PARAMETERS] 		33
4.11	[PATTERNS]		34
4.12	[DIFFUSIVITY]		34
4.13	[REPORT]		35
5	EXAMPLE REACTION SYSTEMS	37
5.1	Multi-Source Chlorine Decay		37
5.2	Decay and Dispersion Modeling of Chlorine		39
5.3	Oxidation, Mass Transfer, and Adsorption		41
5.4	Bacterial Regrowth with Chlorine Inhibition		44
5.5	Chloramine Decomposition		47

-------
A MSX TOOLKIT FUNCTIONS	52
A.l MSXopen		53
A.2 MSXclose		54
A.3 MSXsolveH		55
A.4 MSXusehydfile		56
A. 5 MSXsolveQ		57
A.6 MSXinit		58
A.7 MSXstep 		58
A.8 MSXsaveoutfile		59
A. 9 MSXsavemsxfile		60
A. 10 MSXreport		61
A. 11 MSXgetindex		61
A. 12 MSXgetlDlen		62
A. 13 MSXgetID		63
A. 14 MSXgetcount		64
A. 15 MSXgetspecies		65
A. 16 MSXgetinitqual		66
A. 17 MSXgetqual		67
A. 18 MSXgetconstant		68
A. 19 MSXgetparameter		69
A.20 MSXgetsource 		70
A.21 MSXgetpatternlen		71
A.22 MSXgetpatternvalue 		72
A.23 MSXgeterror		73
A.24 MSXsetconstant		74
A.25 MSXsetparameter		74
A.26 MSXsetinitqual		75
A.27 MSXsetsource		76
A.28 MSXsetpattern 		77
A.29 MSXsetpatternvalue		78
A. 30 MSXaddpattern		79
B BINARY OUTPUT FILE FORMAT	80
C MSX ERROR CODES	81
BIBLIOGRAPHY	83

-------
LIST OF FIGURES
2.1	Example of reactions in the mobile bulk phase and at the fixed pipe surface phase		3
2.2	Node-link representation of a simple distribution system		4
2.3	Illustration of the 5-step water quality transport method for pipe networks. The upper pipe segments contain flow-
ing water while the lower segments are the pipe wall surface. The numbers in each segment represent hypothetical
bulk and surface species concentrations, respectively.		6
3.1	Schematic of the example pipe network 		12
3.2	Command line execution of EPANET-MSX		16
5.1	Example of a two-source water distribution system showing the average percent of water originating from the
River source		37
5.2	Schematic of the mass transfer limited arsenic oxidation/adsorption system		41
5.3	Conceptual diagram of bacterial regrowth within a pipeline. Dashed arrows represent reactions with chlorine
while solid arrows represent transformation processes		44
iii

-------
LIST OF TABLES
3.1	Files distributed with EPANET-MSX		10
3.2	Nodal properties of the example pipe network		12
3.3	Pipe properties of the example pipe network		12
4.1	EPANET-MSX input file section keywords		24
5.1	Monochloramine decay model based on Vikesland et al. (2001) and Duirk et al. (2005)		48
A. 1	EPANET-MSX toolkit processing functions		52
A.2	EPANET-MSX toolkit data retrieval functions		53
A.3	EPANET-MSX data modification functions		53
B.l	Format of the EPANET-MSX binary output file		80
C.l	EPANET-MSX Error Codes 		81
iv

-------
LIST OF LISTINGS
3.1	Contents of the examplel.inp input file		12
3.2	Contents of the examplel.msx input file		13
3.3	EPANET-MSX results for the example network		16
3.4	C source code for the command line version of EPANET-MSX		20
4.1	EPANET-MSX input file template		24
5.1	EPANET-MSX input file for modeling two-source chlorine decay		38
5.2	EPANET-MSX input file for modeling chlorine decay and dispersion (example2.msx)		40
5.3	MSX input file for the mass transfer limited arsenic oxidation/adsorption system		43
5.4	MSX input file for a bacterial regrowth model with chlorine inhibition		45
5.5	EPANET-MSX input file of the monochloramine decomposition model		48
v

-------
DISCLAIMER STATEMENT
This User's Manual is an updated version of the EPANET MSX User's Manual (EPA/600/S-07/021) written by the same authors.
The information in this document has been funded wholly or in part by the U.S. Environmental Protection Agency (EPA). It
has been subjected to the Agency's peer and administrative review, and has been approved for publication as an EPA document.
Approval does not signify that the contents reflect the views of the Agency, nor does mention of trade names or commercial
products constitute endorsement or recommendation for use.
The computer programs described in this manual are free software that can be redistributed and/or modified under the terms of
the MIT License.
These programs are distributed in the hope that they will be useful, but without any warranty; without even the implied warranty of
merchantability or fitness for a particular purpose. The authors and the U.S. Environmental Protection Agency are not responsible
and assume no liability whatsoever for any results or any use made of the results obtained from these programs, nor for any
damages or litigation that result from the use of these programs for any purpose.

-------
CHAPTER
ONE
INTRODU CTTION
EPANET [Rossman, 2000, Rossman et al., 2020] is a widely used program for modeling the hydraulic and water quality behavior
of drinking water distribution systems. Its water quality component is limited to tracking the transport and fate of just a single
chemical species, such as fluoride used in a tracer study or free chlorine used in a disinfectant decay study. In addition, the
longitudinal dispersion process, which can play an important role in affecting the water qualities at the dead ends of a water
distribution system, is not modeled in EPANET. This manual describes an extension to the original EPANET that allows it to model
the advection, dispersion and reaction of any system of multiple, interacting chemical and biological species. This capability has
been incorporated into both a stand-alone executable program as well as a toolkit library of functions that programmers can use
to build custom applications. This set of software tools is referred to as EPANET-MSX, where MSX stands for Multi-Species
Extension.
Many water quality problems in distribution systems can only be analyzed by using a multi-species approach. Consider the
following descriptive examples:
•	Free chlorine disinfectant is lost in bulk solution due mainly to oxidation-reduction reactions involving HOC1 and OC1", and
natural organic matter (NOM). The NOM itself is a heterogeneous mixture of organic compounds (e.g., humic and fulvic
acids) of varying chemical characteristics. Current single-species models, however, must model free chlorine loss under the
assumption that all other reactants are in excess and thus their concentrations can be considered constant. This limitation
is responsible for the widespread observation that the water-specific decay rate constant of the common first-order model
is not a constant at all, but rather varies significantly with chlorine dose (a clear indication of model structure error). The
formation of regulated chlorination by-products, which result from free chlorine and NOM interactions, presents yet another
set of reaction mechanisms involving multiple interacting species.
•	Mono-, di-, and tri-chloramine result from interactions between free chlorine species and ammonia, and are increasingly
used as residual disinfectants. These chloramines also interact with NOM, though the reactions are slower than those for
free chlorine. Thus chloramine decay in distribution systems involves multiple interacting chemical species, which a single-
species model is forced to simplify as a quasi-first order reaction. Further, ammonia may be produced by auto-decomposition
of chloramines, which is of significant practical importance for understanding nitrification episodes in distribution systems
and storage tanks. Nitrification models may need to consider attached-growth nitrifying biofilms, suspended nitrifying
biomass, and the electron donor (ammonia), electron acceptor (oxygen), and carbon source that supports microbial growth.
•	For the relatively common situation where more than one water source supplies a distribution system, current models are not
able to represent meaningful differences in source water quality, as they relate to water quality evolution in the distribution
system. Modelers must try to compensate for this limitation by assigning bulk decay rate coefficients to specific pipes,
according to which source supplies them. Such an approach has obvious deficiencies when attempting to model distribution
system zones where sources blend together, and these zones are sometimes the focus of water quality issues.
None of these examples can be accurately modeled by using the single-species capabilities of the current EPANET program. This
shortcoming provides the motivation to extend EPANET so that it can model reaction systems of any level of complexity.
Another feature in EPANET-MSX 2.0 is the option to include the dispersion process in the water quality modeling analysis of
a water distribution system. Both EPANET and the original EPANET MSX model the transport of a single species by solving
the one-dimensional advection-reaction equation; while EPAENT-MSX 2.0 solves a set of one-dimensional advection-dispersion-
reaction equations to analyze water quality transport of mutiple interacting species.
1

-------
EPANETMSX USERS MANUAL, Release 2.0
The changes and updates that have been made in version 2.0 of EPANET-MSX include:
•	Improved water quality mass balance and mass balance reporting as in EPANET 2.2.
•	Dispersion modeling as an option to be included in water quality simulation.
•	OPENMP parallelization for both reaction and dispersion simulation codes.
•	A batch file (runvc.bat) is provided to automatically launch the Visual Studio C/C++ compiler and compile the reaction
equations.
The following sections of this manual describe the conceptual framework used by EPANET-MSX to model multiple reacting
species within a distribution system, provide instructions on how to use both the command line and toolkit versions of EPANET-
MSX, give a complete description of the format of an MSX input file, and describe several example applications in detail. The
appendices describe each function in the EPANET-MSX toolkit, the format of its binary output file, and the meaning of its error
codes.
2

-------
CHAPTER
TWO
CONCEPTUAL FRAMEWORK
From a water quality modeling perspective, two significant physical phases exist within a water distribution system: a mobile bulk
water phase and a fixed pipe surface phase. Bulk phase species are chemical or biological components that exist within the bulk
water phase and are transported through the system with the average water velocity. Surface phase species are components that
are attached or incorporated into the pipe wall and are thus rendered immobile. Fig. 2.1 shows an example of bulk phase chlorine
(HOC1) reacting with bulk phase NOM (natural organic matter) to produce a bulk phase disinfectant by-product (DBP), while also
oxidizing ferrous iron to ferric iron in the fixed surface phase at the pipe wall.
Fig. 2.1: Example of reactions in the mobile bulk phase and at the fixed pipe surface phase.
Examples of bulk species include dissolved constituents (individual compounds or ions, such as HOC1 and OC1", as well as aggre-
gate components such as TOC), suspended constituents (such as bacterial cells and inorganic particulates), and chemicals adsorbed
onto particles. Examples of surface species include bacteria incorporated within biofilm, oxidized forms of iron contained within
corrosion scale, particulate material that settles out due to gravity or is attached to the pipe wall surface through ionic or molecular
(i.e., van der Waal) forces, and organic compounds that can diffuse into or out of plastic pipes or be adsorbed onto or desorbed
from iron oxide pipe surfaces. Some components, such as bacteria and particulates, can exist in both the bulk and surface phases
and transfer from one phase to another by such mechanisms as physical attachment/detachment, chemical adsorption or molecular
diffusion. In such situations, the component is modeled as two species: one bulk and the other surface.
Additional phases that might exist within a distribution system, such as a mobile bed sediment phase, an immobile water phase
within the pore structure of pipe scale, or an air phase overlying the water surface in a storage tank, could also be included within
this modeling framework.
3

-------
EPANETMSX USERS MANUAL, Release 2.0
2.1 Material Transport
A water distribution system consists of pipes, pumps, valves, fittings, and storage facilities that convey water from source points
to consumers. This physical system is modeled as a network of links connected together at nodes in some particular branched or
looped arrangement. Fig. 2.2 provides an example of a network representation of a very simple distribution system. Links represent
pipes, pumps, and valves; nodes serve as source points, consumption points and storage facilities. The following phenomena all
influence the quality of water contained in the system and can be modeled using principles of conservation of mass coupled with
reaction kinetics:
Reservoir
Junction
Valve
Fig. 2.2: Node-link representation of a simple distribution system.
a.	Advective transport in pipes: bulk species are transported down the length of a pipe with the same average velocity as the
carrier fluid while at the same time reacting with other bulk species and with the pipe wall surface.
b.	Dispersive transport in pipes: due to the differences of concentration and the distribution of the radial flow velocity, bulk
species spread from highly concentrated to less concentrated areas.
c.	Mixing at pipe junctions: at junctions receiving inflow from two or more links the flows are assumed to undergo complete
and instantaneous mixing.
d.	Mixing in storage nodes: all inflows to storage nodes mix completely with the existing contents in storage while these
contents are subjected to possible bulk phase reactions (alternative schemes are available for modeling plug flow storage
tanks).
2.2 Chemical Reactions
Reactions can be divided into two classes based on reaction rates. Some reactions are reversible and fast enough in comparison
with the system's other processes so that a local equilibrium can be assumed; others are not sufficiently fast and/or irreversible
and it is inappropriate to use an equilibrium formulation to represent them. Theoretically, very large backward and forward rate
constants (with their ratio equaling the equilibrium constant) can be used to model fast/equilibrium reactions and therefore both
fast/equilibrium and slow/kinetic reaction dynamics can be written as a single set of ordinary differential equations (ODEs) that
can be integrated over time to simulate changes in species concentrations. This approach can result in reaction rates that may range
over several orders of magnitude and lead to such small integration time steps so as to make a numerical solution impractical.
In EPANET-MSX, algebraic equations are used to represent the fast/equilibrium reactions and mass conservation. Thus it is
assumed that all reaction dynamics can be described by a set of differential-algebraic equations (DAEs) in semi-explicit form.
2.1. Material Transport
4

-------
EPANETMSX USERS MANUAL, Release 2.0
The system of DAEs that defines the interactions between bulk species, surface species, and parameter values can be written in
general terms as:
^ = f(xb, xs, zb, za,p)	(2.1)
- =g(xb,xs, zb, za,p)	(2.2)
dt
0 = h(x5, xs, zb, zs, p)	(2.3)
where the vectors of time-varying differential variables xb and xs are associated with the bulk water and pipe surface, respectively,
the time-varying algebraic variables zb and zs are similarly associated, and the model parameters p are time invariant. The
algebraic variables are assumed to reach equilibrium in the system within a much smaller time scale compared to the numerical
time step used to integrate the ODEs. The dimension of the algebraic equations h must agree with that of the algebraic variables
z = [zb zs], so that the total number of equations in (2.1)-(2.3) equals the total number of time-varying species ([ajj, xs zb zs]).
As a simple example of a reaction/equilibrium system modeled as a set of DAEs, consider the oxidation of arsenite (As+3)
to arsenate (As+5) by a monochloramine disinfectant residual in the bulk flow and the subsequent adsorption of arsenate onto
exposed iron on the pipe wall. (Arsenite adsorption is not significant at the pH's typically found in drinking water.) A more
complete explanation and extension of this model is presented in EXAMPLE REACTION SYSTEMS (Section 5) of this manual.
This system consists of four species (arsenite, arsenate, and monochloramine in the bulk flow, and sorbed arsenate on the pipe
surface). It can be modeled with three differential rate equations and one equilibrium equation:
A A o+3
__ = -kaAs+3(NH2Cl)	(2.4)
fl A e + 5
kaAs+3(NH2Cl) -AvMSmax -Asf)As+5 - k2Asf5}	(2.5)
-kb{NH2Cl)	(2.6)
dt
d(NH2Cl)
dt
= 77^	<17'
where As+3 is the bulk phase concentration of arsenite, As+Z is the bulk phase concentration of arsenate, As+5 is surface phase
concentration of arsenate, and NH2Cl is the bulk phase concentration of monochloramine. The parameters in these equations
are as follows: ka is a rate coefficient for arsenite oxidation, kb is a monochloramine decay rate coefficient, Av is the pipe surface
area per liter pipe volume, and k2 are arsenate adsorption and desorption rate coefficients, Smax is the maximum pipe surface
concentration of arsenate, and ks = k\jk2. Thus in terms of the notation used in (2.1 )-(2.3), xb = {As+3, As+5, NH2Cl},
xs = {0}, zb = {0}, zs = {As+5}, p = {ka,kb,Av,ki,k2,Smax}. Example input files for this form of the model are
included with the standard EPANET-MSX distribution, while the input file for a more complex version of the model is presented
in EXAMPLE REACTION SYSTEMS (Section 5).
2.3 Full Network Solution
Dynamic models of water quality within water distribution systems can be classified spatially as either Eulerian or Lagrangian.
Eulerian models divide the network into a series of fixed control elements and record the changes at the boundaries and within
these elements, while Lagrangian models track changes of discrete parcels of water as they travel through the network. EPANET-
MSX utilizes the Lagrangian transport algorithm as used by EPANET. It tracks the movement and reaction of chemicals in discrete
water volumes, or segments. These segments are transported through network pipes by the bulk velocity, and completely mix at
junction nodes. This method is relatively efficient because the number and size of the segments in a pipe can change as hydraulic
conditions change. In addition, EPANET-MSX adds the effect of longitudinal dispersion to EPANET's Lagrangian transport
algorithm.The details of the Lagranigain algorithm to model advection, dispersion and reaction are described in [Shang et al.,
2021],
In summary form, the following steps, depicted visually in Fig. 2.3, are performed for each water quality time step:
2.3. Full Network Solution
5

-------
EPANETMSX USERS MANUAL, Release 2.0
1.	React: Apply reaction dynamics within each pipe segment and storage tank over the time step to compute new concentrations
throughout the network.
2.	Advect: Within each pipe, compute the flow volume transported over the time step and transfer this amount of volume and its
associated bulk species mass from the pipe's leading segments into accumulated mass and volume totals at the downstream
node.
3.	Mix: Compute new bulk species concentrations at each node based on its accumulated mass and volume inputs from the
advection step as well as any external sources.
4.	Release: Create a new segment at the upstream end of each pipe whose size equals the pipe's flow volume and whose bulk
species concentrations equal that of the upstream node (or if the difference in quality between the most upstream segment
and the upstream node is below some tolerance, simply increase the size of the current upstream segment).
5.	Disperse: Solve the disperison process equation and update both nodal and segment concentrations.
At Start of Time Step
V
10
6 6
W 20
16

After Reaction
V
7
• (¦
W 30
20

After Advection and Node Mixing

6
7
4 (
r -
4

30

20

18

-W 12
After Release and Surface Re-segmentation
"V
6
7
• r
W 30
25
19
18 ^
After Dispersion
11
y
7
7
' (
5
1
v.	^
§ 30
25
19

Fig. 2.3: Illustration of the 5-step water quality transport method for pipe networks. The upper pipe segments contain flowing
water while the lower segments are the pipe wall surface. The numbers in each segment represent hypothetical bulk and surface
species concentrations, respectively.
2.3. Full Network Solution
6

-------
EPANETMSX USERS MANUAL, Release 2.0
2.4 Reaction System Solution
The multi-species water quality algorithm modifies the React step (step 1) of the solution scheme described above. Within each
pipe segment, reaction dynamics are represented by the system of DAEs (2.1)-(2.3). The same applies for storage tanks, except
that the DAEs are modified to consider only bulk reactions. Although not indicated, the model parameters p can possibly vary by
pipe. For the equilibrium reactions, it is assumed that the Jacobian matrix of h with respect to z, f^, is unique and nonsingular
for all t. In this case, the implicit functions defined by (2.3),
zb = zb(xb,xs,p)	(2.8)
zs = zs(xb,xs,p)	(2.9)
exist, are continuous and unique, and possess continuous partial derivatives. These properties, and in particular the resultant
ability to evaluate (2.8)-(2.9) (numerically), are central to the numerical algorithms used for solution of (2.1)-(2.3).
Given the implicit functions (2.8)-(2.9), the solution of (2.1)-(2.3) is performed by substituting (2.8)-(2.9) into (2.1)-(2.2), thus
eliminating the algebraic equations (2.3) and leaving a reduced system of ordinary differential equations (ODEs) that can be
integrated numerically:
= f(xb, xs, zb(xb, xs,p), zs(xb, xs,p),p) = f(xb, xs,p)	(2.10)
= g(xb,xs,zb(xb,xs,p),zs(xb,xs,p),p) = g'(xb,xs,p)	(2.11)
at
Note that the above "substitution" is not performed literally, since (2.8)-(2.9) are implicit, and thus so are the reduced trajectories
f and g'. Solving (2.10)-(2.11) numerically with an explicit method, such as any of the Runge-Kutta schemes, will require that
f and g' be evaluated at intermediate values of xb and xs over the integration time step. Each such evaluation will in turn require
a solution of the nested set of algebraic equations (2.8)-(2.9). Alternative strategies for accomplishing these steps are discussed
in the Model Implementation (Section 2.7) below.
In addition to the React step, evaluation of the equilibrium equations also needs to be performed at the Mix phase of the overall
algorithm since the blending together of multiple flow streams can result in a new equilibrium condition. This process needs to
be performed at each network node, including storage tanks.
2.5 Pipe Surface Discretization
The segment bulk water state variables xb and zb have moving coordinates, due to the nature of the Lagrangian water quality
model (they move with the bulk water velocity). In contrast the associated pipe surface variables xs and zs have fixed coordinates,
since they are associated with the non-moving pipe. The lack of a common fixed coordinate system for the bulk and surface state
variables must be reconciled, since these variables interact through the common pipe-water interface (through equations (2.1)-
(2.3)). To resolve this issue a simple mass-conserving scheme is applied at every water quality time step to update the pipe surface
elements to remain consistent with the (advected) water quality segments and re-distribute the surface variable mass among the
updated elements.
As shown in Fig. 2.3, within any single water quality time step, a moving mesh divides each pipe surface into discrete-length
elements, such that each shares a common surface/water interface with the water quality segment above it. At the end of the time
step the pipe elements will, however, be inconsistent with the water quality segments, due to advection of the latter (i.e., through
the Advect step of the overall algorithm). This inconsistency is removed by updating the surface species concentrations using an
interfacial area-weighted average:
*%W=(jL;)f2(LrwnLj)xaj for i = l,...n™	(2.12)
V % J j=1
= (^) nL^ for * = 1 >-nnew	m)
2.4. Reaction System Solution
1

-------
EPANETMSX USERS MANUAL, Release 2.0
where i is the water quality segment index, n is the number of water quality segments in the pipe during the most recent React step,
Lj is the length of segment j, with corresponding vectors of surface species xsj and zsj, nnew is the updated number of water
quality segments in the pipe after advection, L"ew is the length of each updated segment, with corresponding updated surface
concentrations x"[w and znsfw. The quantity (L"ew n Lj) is the length of the overlapping intersection between segment j and
updated segment i.
2.6 Dispersion Modeling
One-dimensional mass transport in a pipe with a uniform cross-sectional area can be described as advection-dispersion-reaction
equations. For a specific species,
f)c- 3c-	cP* c-
^u — = Di— +r(c)	(2.14)
dt + dx 1 dx2 + [ '
where i = species index; q = concentration of the species i; u = flow velocity; x = distance alone the pipe's longitudinal direction;
Di = effective dispersion coefficient of the species i; r-j = reaction rate of the species i; and c = the concentration vector of all
species which includes both differential and algebraic variables as defined in Chemical Reactions (Section 2.2).
The impact of dispersion may be negligible for many parts of water distribution systems under highly turbulent conditions. How-
ever, it is important to consider dispersion when modeling dead-end segments of a system or premise plumbing systems where
the flow Reynolds number can be low. The relative importance of the dispersion can be quantified with the Peclet number:
PeH = ^	(2.15)
where I = pipe length. The Peclet number is a dimensionless measure of the relative importance of advection versus dispersion,
where a large number indicates an advection-dominated flow condition in which the dispersion is negligible.
The effective longitudinal dispersion coefficient accounts for the combined effect of molecular diffusion and shear dispersion due
to the nonuniformity of the velocity profile. For laminar flow conditions (Reynolds number less than 2300), the effective dispersion
coefficient is calcuated as an averaged value over the residence time [Lee, 2004]:
D
a?v?
48 Dm
1 -
1 - exp (-16^p^)
16
Dmtr
(2.16)
where Dm = molecular diffusion coefficient; a = pipe radius; and tr = pipe residence time (^).
For turbulent and transitional flow conditions, the effective dispersion coefficient does not depend on the molecular diffusion
coefficient and the formula used is [Basha and Malaeb, 2007]:
D = au-,_
10.1 + 577
V 1000 I
-2.21
(2.17)
where w* = shear velocity; and Re = the Reynolds number.
2.6. Dispersion Modeling
8

-------
EPANETMSX USERS MANUAL, Release 2.0
2.7 Model Implementation
EPANET-MSX offers several choices of numerical integration methods for solving the reaction system's ODEs, equations (2.1)
and (2.2). These include a forward Euler method (as used in EPANET), a fifth order Runge-Kutta method with automatic time
step control [Hairer et al., 1993], and a second order Rosenbrock method with automatic time step control [Verwer et al., 1992],
These are listed in order of the numerical work per time step required to obtain a solution. The Euler method is best applied to
non-stiff, linear reaction systems, the Runge-Kutta method to non-stiff, nonlinear systems, and the Rosenbrock method to stiff
systems (see, e.g., Golub and Ortega [1992]).
The algebraic equilibrium equations (2.3) are solved using a standard implementation of the Newton method [Press et al., 1992],
This algorithm requires that the Jacobian of h with respect to the algebraic variables zb and zs be used to iteratively solve an
approximating linear system of equations until convergence is achieved. This can be a computationally expensive procedure since
the Jacobian must be evaluated numerically and the system (2.3) is being solved within every pipe segment of every pipe at every
time step, possibly several times over, as the ODEs are integrated. To help reduce this burden EPANET-MSX offers the following
options for evaluating the nonlinear equilibrium equation system:
•	The Non-Coupled option only evaluates the equilibrium equations at the end of the time step after a new ODE solution
has been found; the algebraic variables maintain the values they had at the start of the time step while the ODEs are being
numerically integrated.
•	The Fully-Coupled option solves the algebraic equations at each stage of the ODE solution process using a fresh Jacobian
for each Newton step.
The choice of coupling involves a trade-off between computational effort and level of accuracy, the degree of which will likely be
very system dependent.
A mass balance report is provided for all species that are represented by the differential variables, xb and xs. For each species
the report lists the ratio of the total mass entering the system to the total mass leaving the system (including mass lost to reaction).
Dispersion modeling of particular species can be excluded from the network solution procedure by not assigning them a molecular
diffusivity. It can also be excluded for pipes that experience highly turbulent flow resulting in a Peclet number ((2.15)) above a
user-specified limit.
2.7. Model Implementation
9

-------
CHAPTER
THREE
PROGRAM USAGE
EPANET-MSX is a 64-bit application that runs under Microsoft Windows 7 or higher. It is distributed in a compressed archive file
named EPANETMSX.ZIP. The contents of this archive are listed in Table 3.1. The top level archive folder contains a Readme.txt
file that describes the contents of the archive and procedures for reporting bugs.
Table 3.1: Files distributed with EPANET-MSX
Readme.txt
describes the contents of the archive
\bin

runepanetmsx.exe
command line version of EPANET-MSX
epanetmsx.dll
EPANET-MSX function library
epanet2.dll
standard EPANET function library
vcompl40.dll
Visual Studio C/C++ OpenMP Runtime library
runvc.bat
batch file to launch the Visual Studio C/C++ compiler and comiple the reaction equations

(see the section Using Compiled Reaction Models)
\Examples

example l.inp
EPANET input file for example 1
example l.msx
MSX input file for example 1
example l.rpt
report file containing the MSX results for example 1
example2.inp
EPANET input file for example 2
example2.msx
MSX input file for example 2
example2.rpt
report file containing the MSX results for example 2
\Doc

epanetmsx.pdf
EPANET-MSX users manual
license.txt
licensing agreement for using EPANET-MSX
continues on next page
10

-------
EPANETMSX USERS MANUAL, Release 2.0
Table 3.1 - continued from previous page
\Include

epanetmsx.h
C/C++ header file for EPANET-MSX toolkit
epanetmsx.bas
Visual Basic declarations of EPANET-MSX functions
epanetmsx.pas
Delphi-Pascal declarations of EPANET-MSX functions
epanet2.h
C/C++ header file for EPANET2.2 toolkit
epanet2_enums.h
C/C++ header file for the symbolic constants used by EPANET2.2 Toolkit
epanet2.bas
Visual Basic declarations of EPANET2 functions
epanet2.pas
Delphi-Pascal declarations of EPANET2 functions
epanetmsx.lib
Microsoft C/C++ LIB file for epanetmsx.dll
epanet2.1ib
Microsoft C/C++ LIB file for epanet2.dll
\Src
EPANET-MSX source files
Most end users will only need to extract the files in the \bin, Vxamples, and \doc folders to a directory of their choosing. Developers
will also need the files in th eMnchide folder to write custom applications. They should also be aware of the licensing requirements
set forth in the license.txt file.
The EPANET-MSX system is supplied as both:
•	a stand-alone console application (runepanetmsx.exe) that can run standard water quality analyses without any additional
programming effort required,
•	a function library (epanetmsx.dll) that, when used in conjunction with the original EPANET function library (epanet2.dll),
can produce customized programming applications.
At this point in time the extension has not been integrated into the Windows version of EPANET. This is expected to happen at
some future date. Examples of each type of usage are provided below.
Regardless of which approach is used, the user must prepare two input files to run a multi-species analysis. One of these is
a standard EPANET input file that describes the hydraulic characteristics of the network being analyzed (EPANET-MSX will
ignore any water quality information that might be in this file). The format of this file is described in the EPANET Users Manual
[Rossman, 2000, Rossman et al., 2020], Any network file that was created, edited and then exported from the Windows version
of EPANET can serve as the EPANET input file for the multi-species extension.
The second file that must be prepared is a special EPANET-MSX file that describes the species being simulated and the chemical
reaction/equilibrium model that governs their dynamics. The format of this file is described in INPUT FILE FORMAT (Section
4) of this manual.
3.1 Example Command Line Run
In order to demonstrate the use of the command line version of EPANET-MSX we will simulate the arsenic oxidation/adsorption
reaction system that was briefly described in CONCEPTUAL FRAMEWORK (Section 2) of this manual using the simple pipe
network shown in Fig. 3.1 that was adapted from Zhang et al. [2004], Table 3.2 lists the properties associated with the nodes of
this network while Table 3.3 does the same for the pipe links.
3.1. Example Command Line Run
11

-------
EPANETMSX USERS MANUAL, Release 2.0
B
Fig. 3.1: Schematic of the example pipe network
Table 3.2: Nodal properties of the example pipe network
Node
Elevation (m)
Demand (m3//?.?•)
Source
100
-
A
0
4.1
B
0
3.4
C
0
5.5
D
0
2.3
Table 3.3: Pipe properties of the example pipe network
Pipe
Length (m)
Diameter (mm)
C-Factor
1
1000
200
100
2
800
150
100
3
1200
200
100
4
1000
150
100
5
2000
150
100
The first step in running a multi-species analysis of a water distribution system is to prepare a standard EPANET input file of the
system that contains all of the information needed to perform a hydraulic analysis of the system. The Windows version of EPANET
2 was used to draw the network layout and assign node and pipe attributes using the program's graphical editing tools. A standard
.INP file was then created by issuing the File | Export | Network command. The resulting file was named examplel.inp and is
shown in Listing 3.1 (after some editing was performed to remove empty sections and default options). Note that for this simple
application the water demands remain constant over time and that a 48 hour simulation period is requested.
Listing 3.1: Contents of the examplel.inp input file.
[TITLE]
EPANET-MSX Example Network
[JUNCTIONS]
;ID Elev Demand Pattern
A ® 4.1
(continues on next page)
3.1. Example Command Line Run
12

-------
EPANETMSX USERS MANUAL, Release 2.0
(continued from previous page)
B
8
3.4
C
8
5.5
D
8
2.3
[RESERVOIRS]
; ID Head Pattern
Source 18®
[PIPES]
ID
Nodel
Node2
Length
Diameter Roughness
1
Source
A
1888
288 188
2
A
B
888
158 188
3
A
C
1288
288 188
4
B
C
1888
158 188
5
C
D
2888
158 188
[TIMES]
Duration	48
Hydraulic Timestep	1:8®
Quality Timestep	8:85
Report Timestep	2
Report Start	8
Statistic	NONE
[OPTIONS]
Units
Headloss
Quality
[END]
CMH
H-W
NONE
The next step is to prepare the MSX input file that defines the individual water quality species of interest and the reaction expres-
sions that govern their dynamics. This was done using a text editor, following the format described in INPUT FILE FORMAT
(Section 4) of this manual. The resulting MSX input file, named examplel.msx, is shown in Listing 3.2.
Listing 3.2: Contents of the examplel.msx input file.
[TITLE]
Arsenic Oxidation/Adsorption Example
[OPTIONS]
AREA_UNITS M2
RATE_UNITS HR
SOLVER RK5
TIMESTEP 368
RTOL	8.881
ATOL	8.8881
;Surface concentration is mass/m2
;Reaction rates are concentration/hour
;5-th order Runge-Kutta integrator
;368 sec (5 min) solution time step
;Relative concentration tolerance
;Absolute concentration tolerance
[SPECIES]
BULK AS3	UG
BULK AS 5	UG
BULK AStot	UG
;Dissolved arsenite
;Dissolved arsenate
;Total dissolved arsenic
(continues on next page)
3.1. Example Command Line Run
13

-------
EPANETMSX USERS MANUAL, Release 2.0
(continued from previous page)
WALL AS5s UG	;Adsorbed arsenate
BULK NH2CL MG	;Monochloramine
[COEFFICIENTS]


CONSTANT
Ka
18.®
;Arsenite oxidation rate coefficient
CONSTANT
Kb
8.1
;Monochloramine decay rate coefficient
CONSTANT
K1
5.8
;Arsenate adsorption coefficient
CONSTANT
K2
1.8
;Arsenate desorption coefficient
CONSTANT
Smax
58
;Arsenate adsorption saturation limit
[TERMS]



Ks
K1/K2

;Equil. adsorption coeff.
[PIPES]



;Arsenite oxidation
RATE AS3 -Ka*AS3*NH2CL
;Arsenate production
RATE AS5 Ka*AS3*NH2CL - Av*(Kl*(Smax-AS5s)*AS5 - K2*AS5s)
;Monochloramine decay
RATE NH2CL -Kb*NH2CL
;Arsenate adsorption
EQUIL AS5s Ks*Smax*AS5/(l+Ks*AS5) - AS5s
;Total bulk arsenic
FORMULA AStot AS3 + AS5
[TANKS]
RATE	AS3
RATE	AS5
RATE	NH2CL
FORMULA	AStot
-Ka*AS3*NH2CL
Ka*AS3*NH2CL
-Kb*NH2CL
AS3 + AS5
[QUALITY]
;Initial conditions (= 8 if not specified here)
NODE Source AS3 18.®
NODE Source NH2CL 2.5
[REPORT]
NODES C D
LINKS 5
SPECIES AStot YES
SPECIES AS5 YES
SPECIES AS5s YES
SPECIES NH2CL YES
There are several things of note in this file:
1. The species have been named as follows:
•	AS3 is dissolved arsenite (As+3), expressed in ng/L
•	AS5 is dissolved arsenate (As+5), expressed in ng/L
•	AStot is total dissolved arsenic expressed in ng/L
•	AS5s is adsorbed arsenate, expressed in ng/m2
;Report results for nodes C and D
;Report results for pipe 5
;Report results for each specie
3.1. Example Command Line Run
14

-------
EPANETMSX USERS MANUAL, Release 2.0
• NH2CL is dissolved monochloramine, expressed in mg/L
2.	The reaction rate coefficients, Ka and Kb, and the adsorption coefficients, K\, K2, and Smax, have been designated as
constants. If instead they varied by pipe, then they could have been declared as parameters and their values could have
been adjusted on a pipe-specific basis in the [PARAMETERS] section (Section 4.10) of the file. Note that the units of these
coefficients areas follows: (L/mg-hr) for Ka\ (l/hr) for Kb, (L/fj,g-hr) for if i; (l/hr) for K2; ^g/m? for Smax.
3.	The [PIPES] section supplies the three reaction rate expressions and the single equilibrium expression for this system as
was presented previously in equations (2.4) - (2.7) of CONCEPTUAL FRAMEWORK (Section 2). For example, the rate
expression for arsenite oxidation
A A o+3
__ = -kaAs+3(NH2Cl)
is expressed in the file as:
RATE As3 -Ka* As3 *NH2CL
while the equilibrium expression
a +5 	 kgSmax-A-S^
s 1 + ksAs+5
is re-written so that it has an implied 0 on the left hand side:
EQUIL As5s Ks*Smax*As5/(l + Ks*As5) - As5s
4.	The variable Av that appears in the rate expression for AS5 is a reserved symbol for the pipe wall surface area per unit of
pipe volume. It is computed internally by EPANET-MSX and has units of area per liter, where the area units are the same
as those specified in the [OPTIONS] section of the file.
5.	Even though there are no tanks in this example, a [TANKS] section is still needed in the MSX file because both BULK and
WALL species have been defined (Tank water quality reactions can not use wall species, which are associated only with
pipes). If only BULK species were present then a redundant [TANKS] section would not be required.
6.	An initial quality is assigned to the source reservoir which remains constant over the course of the simulation. If source
quality was to vary over time or there were source injections at other locations they could be described in a [SOURCES]
section.
7.	In the [REPORT] section we ask that results for all species at nodes C and D and link 5 be written to the report file.
The final step in analyzing arsenic oxidation/adsorption for our example network is to run the EPANET-MSX command line
executable. This can be done by first opening a Command Prompt window in Windows, navigating to the folder where
runepanetmsx.exe, epanetmsx.dll, epanet2.dll and the input files were saved, and issuing the following command:
runepanetmsx.exe examplel.inp examplel.msx examplel.rpt examplel.out
where examplel.rpt is the name of the file where the results will be written. If the executable were saved to a different folder than
that of the example files, then either the full path name would have to be added to the name of the executable on the command
line or the folder name would have to be added to the user's PATH environment variable. Fig. 3.2 is a screen capture of what
appears on the screen as the program runs. The last argument of the runepanetmsx.exe is optional and specifies the binary output
file name. The details of the binary output file are described in BINARY OUTPUT FILE FORMAT.
After the program finishes, the examplel.rpt file can be opened in any text editor (such as Windows Notepad) where its contents
can be viewed. Excerpts from the results file are reproduced in Listing 3.3. The first page contains a summary of the standard
EPANET options that were chosen for the run. Following this is a table of results for each node and each link. These tables
contain the concentrations of each species at each reporting period. Note that the surface species are not listed for nodes since by
definition this class of constituent is associated only with pipe surfaces. At the end of the report file, the mass balance summaries
of the three differential variables (As+3, \As+z and NH2Cl) are provided. These mass balances reports are consistent with those
provided by EPANET 2.2, and will include all relevant species. Starting and ending mass, mass inflow, outflow, and reacted are
included.
3.1. Example Command Line Run
15

-------
EPANETMSX USERS MANUAL, Release 2.0
SB Command Prompt
~ X
I
c:\Epanet-MSX>runepanetmsx.exe examplel.inp examplel.msx examplel.rpt examplel.out
... EPANET-MSX Version 2.0.0
o	Processing EPANET input file
o	Processing MSX input file
o	Computing network hydraulics
o	Initializing network water quality
o	Computing water quality at hour 48
o	Reporting water quality results
...	EPANET-MSX completed successfully.
c:\Epanet-MSX>
Fig. 3.2: Command line execution of EPANET-MSX.
Listing 3.3: EPANET-MSX results for the example network
Page 1	Thu Feb 9 18:48:39 2823
EPANET
Hydraulic and Water Quality
Analysis for Pipe Networks
Version 2.2
EPANET-MSX Example Network
Input Data File 		examplel.inp
Number of Junctions		4
Number of Reservoirs		1
Number of Tanks 		8
Number of Pipes 		5
Number of Pumps 		8
Number of Valves 		8
Headloss Formula 		Hazen-Williams
Nodal Demand Model 		DDA
Hydraulic Timestep 		1.88 hrs
Hydraulic Accuracy 		8.881888
Status Check Frequency 		2
Maximum Trials Checked 		18
Damping Limit Threshold 		8.888888
Maximum Trials 		288
Quality Analysis 		None
(continues on next page)
3.1. Example Command Line Run
16

-------
EPANETMSX USERS MANUAL, Release 2.0
(continued from previous page)
Specific Gravity 	 1.8®
Relative Kinematic Viscosity 	 1.8®
Relative Chemical Diffusivity 	 1.88
Demand Multiplier 	 1.88
Total Duration 	 48.88 hrs
Reporting Criteria:
No Nodes
No Links
Analysis begun Thu Feb 9 18:48:39 2823
Processing MSX input file examplel.msx
Page 1	EPANET-MSX 2.8.
EPANET - MSX
Multi-Species Water Quality
Analysis for Pipe Networks
Version 2.8.8
Arsenic Oxidation/Adsorption Example
< Node
n
V
V
V


me

AS 5
AStot
NH2CL
•:min
UG/L
UG/L
MG/L
8
88
8.88
8.88
8.88
2
88
8.88
8.88
8.88
4
88
8.88
8.88
8.88
6
88
8.88
8.88
8.88
8
88
8.88
8.88
1.18
18
88
9.17
9.17
1.18
12
88
9.17
9.17
1.18
14
88
9.17
9.17
1.18
16
88
9.17
9.17
1.18
18
88
9.17
9.17
1.18
28
88
9.17
9.17
1.18
22
88
9.17
9.17
1.18
24
88
9.17
9.17
1.18
26
88
9.17
9.17
1.18
28
88
9.17
9.17
1.18
38
88
9.17
9.17
1.18
32
88
9.17
9.17
1.18
34
88
9.17
9.17
1.11
36
88
9.17
9.17
1.11
38
88
18.83
18.83
1.11
48
88
18.83
18.83
1.11
(continues on next page)
3.1. Example Command Line Run
17

-------
EPANETMSX USERS MANUAL, Release 2.0
(continued from previous page)
42
88
1®. 83
18.83
1.11
44
88
18.83
18.83
1.11
46
88
18.83
18.83
1.11
48
®8
18.83
18.83
1.11
«< Node D »>
Time	AS5	AStot	NH2CL
hr:min	UG/L	UG/L	MG/L
8
88
8
88
8
8®
8
88
2
88
8
88
8
88
8
88
4
88
8
88
8
88
8
88
6
8
88
88
8
8
88
88
8
8
88
88
8
8
88
88
18
88
8
88
8
88
8
88
12
88
8
88
8
88
8
88
14
88
8
88
8
88
8
88
16
88
8
88
8
88
8
88
18
88
8
88
8
8®
8
88
28
88
8
88
8
88
8
88
22
8®
8
88
8
88
8
88
24
88
8
88
8
88
8
24
26
88
8
88
8
88
8
24
28
8®
9
17
9
17
8
24
38
8®
9
17
9
17
8
24
32
88
9
17
9
17
8
24
34
8®
9
17
9
17
8
24
36
8®
9
17
9
17
8
24
38
88
9
17
9
17
8
24
48
88
9
17
9
17
8
24
42
88
9
17
9
17
8
24
44
88
9
17
9
17
8
24
46
88
9
17
9
17
8
24
48
88
9
17
9
17
8
24
«< Link 5 »>
NH2CL
MG/L
Time	AS5	AStot	AS5s
hr:min	UG/L	UG/L	UG/M2
8
88
8.88
8.88
-8.88
8.8®
2
88
8.88
8.8®
8.®®
®. 8®
4
88
8.88
8.88
®. 8®
®. 8®
6
88
8.8®
8.88
8.88
8.88
8
88
8.88
8.8®
8.88
8.85
18
88
8.85
8.85
4.51
8.17
12
88
1.86
1.86
9.88
8.27
14
88
2.87
2.87
15.27
8.35
16
88
3.87
3.87
28.64
8.42
18
88
4.88
4.88
26.82
8.47
28
8®
5.89
5.89
31.39
8.52
(continues on next page)
3.1. Example Command Line Run
18

-------
EPANETMSX USERS MANUAL, Release 2.0
(continued from previous page)
22
88
6.89
6.89
36.75
8. 55
24
88
7.98
7.98
42.12
8.56
26
88
8.91
8.91
47. 58
8.56
28
88
9.17
9.17
48.93
8.56
38
8®
9.17
9.17
48.93
8.56
32
8®
9.17
9.17
48.93
8.56
34
88
9.17
9.17
48.93
8.56
36
88
9.17
9.17
48.93
8.57
38
88
9.19
9.19
48.93
8.57
48
88
9.38
9.38
48.95
8.57
42
88
9.41
9.41
48.96
8.57
44
88
9.52
9.52
48.97
8.57
46
88
9.64
9.64
48.98
8.57
48
88
9.75
9.75
48.99
8.57
Water Quality Mass Balance: ASB (UG)
Initial Mass:
Mass Inflow:
Mass Outflow:
Mass Reacted:
Final Mass:
Mass Ratio:
8.88888e+88
7.344®9e+®6
5.156®9e-ll
-7.3274®e+®6
1.66911e+®4
1.888®®
Water Quality Mass Balance: AS5 (UG)
Initial Mass:
Mass Inflow:
Mass Outflow:
Mass Reacted:
Final Mass:
Mass Ratio:
8.888®8e+88
8.8®®®®e+8®
5.79736e+86
7.13763e+86
1.34827e+86
1.88888
Water Quality Mass Balance: NH2CL (MG)
Initial Mass:
Mass Inflow:
Mass Outflow:
Mass Reacted:
Final Mass:
Mass Ratio:
8.888®8e+88
1.83682e+86
8.51117 e+8 5
-8.88156e+85
1.84749e+85
1.88888
Analysis ended Thu Feb 9 18:48:39 2823
3.1. Example Command Line Run
19

-------
EPANETMSX USERS MANUAL, Release 2.0
3.2 Example Toolkit Usage
Using the EPANET-MSX function library requires some programming effort to build custom applications and must be used in
conjunction with the standard EPANET Programmer's Toolkit. Applications can be written in any programming language that can
call external functions residing in a Windows DLL (or a Linux shared object library), such as C, C++, Visual Basic, and Delphi
Pascal. Section MSX TOOLKIT FUNCTIONS describes each function included in the MSX toolkit library. The functions in the
EPANET toolkit library are documented online at http://wateranalytics.org/EPANET/.
As an example of how the library can be used to construct an application, Listing 3.4 displays the C code behind the command line
implementation of the MSX system, runepanetmsx.exe, which was just discussed. The listing begins by checking for the correct
number of command line arguments and then attempts to open and read the EPANET file supplied as the first argument. It uses
the EPANET toolkit function ENopen for this purpose.
The code then begins a do-while loop that simplifies error detection through the remainder of the program. The MSXopen function
is used to open and process the MSX file (the second command line argument), and the MSXsolveH function is used to run a
hydraulic analysis of the network whose results are saved to a scratch file. This is followed by a call to MSXinit to initialize the
water quality analysis. Note that the argument of 1 to this function tells the MSX system to save its computed water quality results
to a scratch file so that they can be used for reporting purposes later on.
The program then begins another do-while loop that will step through each water quality time step. At each such step, theMSXstep
function is called to update water quality throughout the network and save these results to the scratch output file. This function
also updates the amount of time left in the simulation (stored in the variable named tleft). The loop continues until either no more
time is left or an error condition is encountered.
If the simulation ends successfully, the MSXreport function is called to write the water quality results to the report file that was
named on the command line. If a fourth file name was supplied on the command line, then the MSXsaveoutfile is called to save
the results in a binary format to this file. Lastly, the MSX system is closed down by calling MSXclose and the same is done for
the EPANET system by calling ENclose.
If the source code in Listing 3.4 was saved to a file named epanetmsx.c then it could be compiled into an executable named
runepanetmsx.exe by first opening a Microsoft Visual Studio command prompt window (64-bit) and then using the following
commands:
CL/c epanetmsx.c
LINK epanetmsx.obj epanet2.lib epanetmsx. lib/O UT.-runepanetmsx.exe
Note that when developing MSX applications in C/C++, the header files epanet2.h, epanetmsx.h and epanet2_enums.h must be in
the same folder as the application's source codes (epanetmsx.c here), and the library modules epanet2.lib and epanetmsx.lib must
be linked in with the application's object modules. Versions of these files that are compatible with the Microsoft C/C++ compiler
(Version 6 and higher) are supplied with the EPANET-MSX distribution. Also, copies of the distributed DLL files epanet2.dll
and epanetmsx.dll must be placed in the same directory as the application's executable file or reside in a directory listed the user's
PATH environment variable.
Users using other compilers or platforms would need to use the appropriate commands to produce the required object library files
and executables.
Listing 3.4: C source code for the command line version of EPANET-
MSX
£
OI1U
fI
j£ EPAMET-l
#include
Z'XRCXUC'Q
#include
#include
12
EP.
12
(continues on next page)
3.2. Example Toolkit Usage
20

-------
EPANETMSX USERS MANUAL, Release 2.0
(continued from previous page)
int main(int argc, char* argv[])
/*
Purpose:
runs a multi-species EPANET analysis
-A" "A°
* 'A-
A- ~k
-A- -A;
-A" si'
si' >1'
>1- -/?
V
{
juinn::
argc = number of command line arguments
argv = array of command line arguments.
Returns:
an. error code (or S for no error),
rw>:es:
The command line arguments are:
-	the name of a regular EPANET input data file
-	the name of a EPANET-MSX input file
-	the name of a report file that will contain status
messages and output results
-	optionally, the name of an, output file that will
contain water quality results in binary format.
int err, done = 1;
double t, tleft;
long oldHour, newHour;
// — Check command line arguments
if (argc < 4) {
printf("\n Too few command line arguments,\n");
return is;
}
// — Open the EPANET file
printf("\n... EPANET-MSX Version 2.®\n");
printf("\n o Processing EPANET input file");
err = ENopen(argv[l], argv[3], "");
if (err) {
printf("\n\n... Cannot read EPANET file; error code = %d\n", err);
ENcloseO;
return ®;
}
// 	-- Begin an error detection loop
do {
// — Open the MSX input file
printf("\n o Processing MSX input file");
err = MSXopen(argv[2]);
if (err) {
printf("\n\n... Cannot read MSI file; error code = %d\n", err);
(continues on next page)
3.2. Example Toolkit Usage
21

-------
EPANETMSX USERS MANUAL, Release 2.0
(continued from previous page)
break;
}
// — Solve hydraulics
printf("\n o Computing network hydraulics");
err = MSXsolveHO;
if (err) {
printf(
"\n\n.,, Cannot obtain network hydraulics; error code = %d\n", err);
break;
}
// — Initialize the multi-species, analysis
printf("\n o Initializing network water quality");
err = MSXinit(l);
if (err) {
printf(
"\n\ri... Cannot initialize EPANET-MSX; error code = %d\n", err);
break;
}
t = ®;
oldHour = -1;
newHour = ®;
printf("\n");
// — Repeat for each time step
do {
// -	- Report current progress
if (oldHour != newHour) {
printf("\r o Computing water quality at hour %-4d", newHour);
oldHour = newHour;
}
// — Compute water quality
err = MSXstep(&t, frtleft);
newHour = (long) (t / 368®.®);
} while (!err && tleft > ®);
// — Report: any runtime error
if (err) {
printf("\n\n... EPANET-MSX runtime error; error code = %d\n", err);
break;
}
else
printf("\r o Computing water quality at hour %-4d", (long) (t / 36®®.®));
// 	 neuorr. results
(continues on next page)
3.2. Example Toolkit Usage
22

-------
EPANETMSX USERS MANUAL, Release 2.0
(continued from previous page)
printf("\n o Reporting water quality results");
err = MSXreportO;
if (err) {
printf(
"\n\n,., MSI report writer error; error code = %d\n", err);
break;
}
// — Save results to binary file if a file name was provided
if (argc >= 5) {
err = MSXsaveoutfile(argv[4]);
if (err > ®) {
printf(
"\n\n... Cannot save MSX results file; error code = %d\n", err);
break;
}
}
// — End of error detection loop
} while (!done);
// — Close both the multi-species & EPASET systems
MSXcloseO;
ENcloseO;
if (!err) printf("\n\n.,. EPANET-MSX completed successfully.");
printf("\n");
return err;
}
3.3 Using Compiled Reaction Models
EPANET-MSX has the option to compile the chemical reaction equations that a user specifies within their MSX input file using
a C compiler that already resides on the user's system. This can speed up execution times by a factor of 2 to 5, depending on the
nature of the reaction system and the choice of integration method. This option is available on Windows operating systems that
have either the Microsoft Visual Studio C++ compiler or the MinGW port of the Gnu C++ compiler installed, or on Linux systems
with the Gnu C++ compiler. To utilize this option, one adds the following command to the [OPTIONS] (Section 4.2) section of
the MSX input file:
COMPILER choice
where choice is VC for the Visual Studio C++ compiler, GC for the MinGW or Gnu C++ compilers, or NONE for no compiler
(the default compiler option). To determine if your Windows system has the Visual Studio C++ build tools installed you can check
to see if a Visual Studio folder appears on your Start Menu. To check for the MinGW compiler, open a Command Prompt window
and enter gcc.
The Gnu compiler comes standard with most Linux installations.
3.3. Using Compiled Reaction Models
23

-------
CHAPTER
FOUR
INPUT FILE FORMAT
The input file used by EPANET-MSX to describe the species and reaction system being modeled is organized into sections, where
each section begins with a keyword enclosed in brackets. The various section keywords are listed in Table 4.1. Listing 4.1 contains
a template of what the input file layout looks like.
Table 4.1: EPANET-MSX input file section keywords
[TITLE]
adds a descriptive title to the data set
[OPTIONS]
sets the values of computational options
[SPECIES]
names the chemical species being analyzed
[COEFFICIENTS]
names the parameters and constants used in chemical rate and equilibrium ex-
pressions
[TERMS]
defines intermediate terms used in chemical rate and equilibrium expressions
[PIPES]
supplies the rate and equilibrium expressions that govern species dynamics in
pipes
[TANKS]
supplies the rate and equilibrium expressions that govern species dynamics in
storage tanks
[SOURCES]
identifies input sources (i.e., boundary conditions) for selected species
[QUALITY]
supplies initial conditions for selected species throughout the network
[PARAMETERS]
allows parameter values to be assigned on a pipe by pipe basis
[DIFFU SIVIT Y]
specifies the relative molecular diffusivity of bulk species
[PATTERNS]
defines time patterns used with input sources
[REPORT]
specifies reporting options
Each section can contain any number of lines of data and appear in any order. Blank lines can appear anywhere in the file and the
semicolon (;) can be used to indicate what follows on the line is a comment, not data. A maximum of 1024 characters can appear
on a line. The ID labels used to identify objects can be any combination of characters and numbers that do not contain square
brackets ([]), double quotes or a semicolon, except that they cannot be the same as any reserved keyword or hydrauic variable (see
[TERMS]).
On the pages that follow the contents and formats of each input file section are described in the order shown above. Reserved
keywords are shown in bold and option choices are separated by slashes. The usage of parentheses in mathematical expressions (in
[TERMS], [PIPES], and [TANKS]) is encouraged to avoid potential misintepretations of the expression parser of EPANET-MSX.
Listing 4.1: EPANET-MSX input file template
[TITLE]

[OPTIONS]
AREA_UNITS FT2/M2/CM2
RATE_UNITS SEC/MIN/HR/DAY
(continues on next page)
24
</pre><hr><pre>
-------
EPANETMSX USERS MANUAL, Release 2.0
SOLVER
COUPLING
TIMESTEP
ATOL
RTOL
COMPILER
SEGMENTS
PECLET
EUL/RK5/ROS2
FULL/NONE
<seconds>
<value>
<value>
VC/GC/NONE
<value>
<value>
[SPECIES]
BULK	<specieID> <units>
WALL	<specieID> <units>
(<atol> <rtol>)
(<atol> <rtol>)
[COEFFICIENTS]
PARAMETER <paramID> <value>
CONSTANT <constID> <value>
[TERMS]
<termID> <expression>
[PIPES] or	[TANKS]
EQUIL	<specieID>
RATE	<specieID>
FORMULA	<specieID>
<expression>
<expression>
<expression>
[SOURCES]
<type> <nodeID>
<specieID> <strength>
(<patternID>)
[QUALITY]
GLOBAL
NODE
LINK
<specieID> <value>
<nodeID>	<bulkSpecieID> <value>
<linkID>	<wallSpecieID> <value>
[PARAMETERS]
PIPE	<pipeID>
TANK	<tankID>
[DIFFUSIVITY]
<specieID> <value>
[PATTERNS]
<patternID>
[REPORT]

NODES
ALL
NODES
<nodelID>
LINKS
ALL
LINKS
<linklID>
SPECIES
<speciesID>
FILE
<filename>
PAGESIZE
<lines>
<paramID> <value>
<paramID> <value>
<node2ID>
<link2ID>
YES/NO (<precision>)
<multiplier> <multiplier> ...
(continued from previous page)
25
</pre><hr><pre>
-------
EPANETMSX USERS MANUAL, Release 2.0
4.1	[TITLE]
Purpose:
Attaches a descriptive title to the problem being analyzed.
Format:
A single line of text.
Remarks:
The [TITLE] section is optional.
4.2	[OPTIONS]
Purpose:
Defines various simulation options.
Formats:
AREAJJNITS
RATEJJNITS
SOLVER
COUPLING
TIMESTEP
ATOL
TROL
COMPILER
SEGMENTS
PECLET
Definitions:
AREAJJNITS sets the units used to express pipe wall surface area where:
FT2 = square feet
M2 = square meters
CM2 = square centimeters
The default is FT2.
RATEJJNITS is the units in which all reaction rate terms are expressed. The default units are hours
(HR).
SOLVER is the choice of numerical integration method used to solve the reaction system where:
EUL = standard Euler integrator
RK5 = Runge-Kutta 5th order integrator
ROS2 = 2nd order Rosenbrock integrator
The default solver is EUL.
COUPLING determines to what degree the solution of any algebraic equilibrium equations is coupled
to the integration of the reaction rate equations. If coupling is NONE then the solution to the algebraic
equations is only updated at the end of each integration time step. With FULL coupling the updating
is done whenever a new set of values for the rate-dependent variables in the reaction rate expressions is
FT2/M2/CM2
SEC/MIN/HR/DAY
EUL/RK5/ROS2
FULL/NONE
seconds
value
value
NONE/VC/GC
value
value
4.1. [TITLE]
26
</pre><hr><pre>
-------
EPANETMSX USERS MANUAL, Release 2.0
computed. This can occur at several intermediate times during the normal integration time step when
using the RK5 and ROS2 integration methods. Thus the FULL coupling option is more accurate, but can
require significantly more computation time. The default is NONE.
TIMESTEP is the time step, in seconds, used to integrate the reaction system. The default time step is
300 seconds (5 minutes).
ATOL is the default absolute tolerance used to determine when two concentration levels of a species are
the same. It applies to all species included in the model. Different values for individual species can be set
in the [SPECIES] section of the input (see below). If no ATOL option is specified then it defaults to 0.01
(regardless of species concentration units).
RTOL is the default relative accuracy level on a species' concentration used to adjust time steps in the
RK5 and ROS2 integration methods. It applies to all species included in the model. Different values for
individual species can be set in the [SPECIES] section of the input (see below). If no RTOL option is
specified then it defaults to 0.001.
COMPILER determines if the chemical reaction system being modeled should first be compiled before
the simulation begins. This option is available on Windows systems that have either the Microsoft Visual
C++ or the MinGW compiler installed or on Linux systems with the Gnu C++ compiler. The VC option
is used for the Visual C++ compiler, the GC option is for the MinGW or Gnu compilers, while NONE is
the default which means that no compilation is performed. Using this option can result in faster run times
by a factor of 2 to 5.
SEGMENTS is the maximum number of water quality segments any pipe can have. The default setting is
5000. Reducing this number can speed up the simulation time but may lead to more numerical diffusion.
PECLET is the Peclet number above which the dispersion effect is neglected. The default value is 1000.0.
Reducing this number excludes more pipes from dispersion modeling.
4.3 [SPECIES]
Purpose:
Defines each chemical species being simulated.
Formats:
BULK
WALL
Definitions:
name:
units:
Atol:
Rtol:
Remarks:
•	The first format is used to define a bulk water (i.e., dissolved) species while the second is used for species
attached (i.e., adsorbed) to the pipe wall.
•	Bulk species are measured in concentration units of mass units per liter while wall species are measured in mass
units per unit area.
•	Any units can be used to represent species mass. The user is responsible for including any necessary unit
conversion factors when specifying chemical reaction and equilibrium expressions that involve several species
with different mass units.
•	Values for both Atol and Rtol must be provided to override the default tolerances.
name units {Atol) {Rtol)
name units {Atol) {Rtol)
species name
species mass units
optional absolute tolerance that overrides the global value set in the [OPTIONS] section
optional relative tolerance that overrides the global value set in the [OPTIONS] section
4.3. [SPECIES]
27
</pre><hr><pre>
-------
EPANETMSX USERS MANUAL, Release 2.0
Examples:
[SPECIES]
;Bulk chlorine in mg/L with default tolerances
BULK CL2 MG
;Bulk biomass in ug/L with specific tolerances
BULK Xb UG 8.Q881 ©.©1
;Attached biomass in ug/area with specific tolerances
WALL Xa UG ®.®8®1 ®.®1
4.4 [COEFFICIENTS]
Purpose:
Defines parameters and constants that are used in the reaction/equilibrium chemistry model.
Formats:
PARAMETER name value
CONSTANT name value
Definitions:
name: coefficient's identifying name
value: global value of the coefficient.
Remarks:
A PARAMETER is a coefficient whose value can be changed on a pipe by pipe (or tank by tank) basis (see
the [PARAMETERS] section below) while a CONSTANT coefficient maintains the same value throughout
the pipe network.
Examples:
[COEFFICIENTS]
;Kb can vary by pipe
PARAMETER Kb ®.l
;Kw is fixed for all pipes
CONSTANT Kw 1.5
4.4. [COEFFICIENTS]
28
</pre><hr><pre>
-------
EPANETMSX USERS MANUAL, Release 2.0
4.5 [TERMS]
Purpose:
Defines mathematical expressions that are used as intermediate terms in the expressions for the chemical
reaction/equilibrium model.
Formats:
termID expression
Definitions:
termID: identifying name given to the term
expression: any well-formed mathematical expression involving species, parameters, constants,
hydraulic variables or other terms.
Remarks:
Terms can be used to simplify reaction rate or equilibrium expressions that would otherwise be unwieldy
to write all on one line or have the same terms repeated in several different rate/equilibrium equations. The
definition and use of TERMS, when those terms are common and appear in multiple rate or equilibrium
expressions, may speed computation because the common term expression requires only one evaluation.
Hydraulic variables consist of the following reserved names and use the unit system specified in the
EPANET input file:
D pipe diameter (feet or meters)
Kc pipe roughness coefficient (unitless for Hazen-Williams or Chezy-Manning head loss formulas, mil-
lifeet or millimeters for Darcy-Weisbach head loss formula)
Q pipe flow rate (flow units)
U pipe flow velocity (ft/sec or m/sec)
Re flow Reynolds number
Us pipe shear velocity (ft/sec or m/sec)
Ff Darcy-Weisbach friction factor
Av Surface area per unit volume (area units/L)
Len Pipe length (feet or meters)
Examples:
[TERMS]
;A mass transfer coefficient
Kf 1.2e-4*ReA®.88/D
;A reaction term
al kl*H0CL*NH3
4.5. [TERMS]
29
</pre><hr><pre>
-------
EPANETMSX USERS MANUAL, Release 2.0
4.6 [PIPES]
Purpose:
Supplies the rate and equilibrium expressions that govern species dynamics in pipes.
Formats:
EQUIL	specielD expression
RATE	specielD expression
FORMULA specielD expression
Definitions:
specielD: a species identifier
expression: any well-formed mathematical expression involving species, parameters, constants,
hydraulic variables or terms.
Remarks:
•	There should be one expression supplied for each species defined in the model.
•	The allowable hydraulic variables were defined above in the description of the [TERMS] section.
•	The EQUIL format is used for equilibrium expressions where it is assumed that the expression supplied is being
equated to zero. Thus formally there is no need to supply the name of a species, but requiring one encourages
the user to make sure that all species are accounted for.
•	The RATE format is used to supply the equation that expresses the rate of change of the given species with
respect to time as a function of the other species in the model.
•	The FORMULA format is used when the concentration of the named species is a simple function of the re-
maining species.
Examples:
[PIPES]
;Bulk chlorine decay
RATE CL2 -Kb*CL2
;Adsorption equilibrium between Cb in bulk and Cw on wall
EQUIL Cw Cmax*k*Cb / (1 + k*Cb) - Cw
;Conversion between biomass (X) and cell numbers (N)
FORMULA N logl®(X*l.®e6)
;Bulk C formation plus non-equilibrium sorption between C and Cs
;Using hydraulic variable Av [Area-Units/Liter]
RATE C K*C - Av*(Kl*(Smax-Cs)*C - K2*Cs)
;Equivalent sorption model, using 1/hydraulic radius = 4/D
;Assumes area units are FT2 and diameter in FT
(continues on next page)
4.6. [PIPES]
30
</pre><hr><pre>
-------
EPANETMSX USERS MANUAL, Release 2.0
(continued from previous page)
;CFPL is user-defined TERM equal to FTB/Liter, thus (4*CFPL/D) == Av
RATE C K*C - (4*CFPL/D)*(Kl*(Smax-Cs)*C - K2*Cs)
4.7	[TANKS]
Purpose:
Supplies the rate and equilibrium expressions that govern species dynamics in storage tanks.
Formats:
EQUIL
RATE
FORMULA
Definitions:
specielD:
expression:
Remarks:
•	A [TANKS] section is always required when a model contains both bulk and wall species, even when there are
no tanks in the pipe network. If the model contains only bulk species, then this section can be omitted if the
reaction expressions within tanks are the same as within pipes.
•	There should be one expression supplied for each bulk species defined in the model. By definition, wall species
do not exist within tanks.
•	Hydraulic variables are associated only with pipes and cannot appear in tank expressions.
•	The EQUIL format is used for equilibrium expressions where it is assumed that the expression supplied is being
equated to zero. Thus formally there is no need to supply the name of a species but doing so allows one to make
sure that all species are accounted for.
•	The RATE format is used to supply the equation that expresses the rate of change of the given species with
respect to time as a function of the other species in the model.
•	The FORMULA format is used when the concentration of the named species is a simple function of the re-
maining species.
Examples:
See the examples listed for the [PIPES] section.
4.8	[SOURCES]
Purpose:
Defines the locations where external sources of particular species enter the pipe network.
Formats:
sourceType nodelD specielD strength (patternlD)
Definitions:
specielD expression
specielD expression
specielD expression
a species identifier
any well-formed mathematical expression involving species, parameters, constants, or terms.
4.7. [TANKS]
31
</pre><hr><pre>
-------
EPANETMSX USERS MANUAL, Release 2.0
sourceType
nodelD:
specielD:
strength:
patternID:
Remarks:
•	Use one line for each species that has non-zero source strength.
•	Only bulk species can enter the pipe network, not wall species.
•	The definitions of the different source types conform to those used in the original EPANET program are as
follows:
-	A MASS type source adds a specific mass of species per unit of time to the total flow entering the source
node from all connecting pipes.
-	A CONCEN type source sets the concentration of the species in any external source inflow (i.e., a negative
demand) entering the node. The external inflow must be established as part of the hydraulic specification
of the network model.
-	A FLOWPACED type source adds a specific concentration to the concentration that results when all inflows
to the source node from its connecting pipes are mixed together.
-	A SETPOINT type source fixes the concentration leaving the source node to a specific level as long as
the mixture concentration of flows from all connecting pipes entering the node is less than the set point
concentration.
•	If a time pattern is supplied for the source, it must be one defined in the [PATTERNS] section of the MSX file,
not a pattern from the associated EPANET input file.
Examples:
[SOURCES]
;Inject 6.5 mg/minute of chemical X into Node N1 over the period of time
;defined by pattern PAT1
MASS N1 X 6.5 PAT1
;Maintain a 1.® mg/L level of chlorine at node N18®
SETPOINT N18Q CL2 1.®
4.9 [QUALITY]
Purpose:
Specifies the initial concentrations of species throughout the pipe network.
Formats:
GLOBAL specielD concen
NODE nodelD specielD concen
LINK linkID specielD concen
either MASS, CONCEN, FLOWPACED, or SETPOINT
the ID label of the network node where the source is located
a bulk species identifier
the baseline mass inflow rarte (mass/minute) for MASS source or concentration (mass/L)
for all other source types
the name of an optional time pattern that is used to vary the source strength over time.
4.9. [QUALITY]
32
</pre><hr><pre>
-------
EPANETMSX USERS MANUAL, Release 2.0
Definitions:
specielD:	a species identifier
nodelD:	a network node ID label
linkID:	a network link ID label
concen:	a species concentration
Remarks:
•	Use as many lines as necessary to define a network's initial condition.
•	Use the GLOBAL format to set the same initial concentration at all nodes (for bulk species) or within all pipes
(for wall species).
•	Use the NODE format to set an initial concentration of a bulk species at a particular node.
•	Use the LINK format to set an initial concentration of a wall species within a particular pipe.
•	Use the NODE and LINK format after the GLOBAL format to overwrite the GLOBAL initial condition
•	The initial concentration of a bulk species within a pipe is assumed equal to the initial concentration at the
downstream node of the pipe.
•	All initial concentrations are assumed to be zero unless otherwise specified in this section.
•	Models with equilibrium equations will require that reasonable initial conditions be set so that the equations
are solvable. For example, if they contain a ratio of species concentrations then a divide by zero condition will
occur if all initial concentrations are set to zero.
Examples:
[QUALITY]
;Set concentration of bulk species Cb to 1.® at all nodes
GLOBAL Cb 1.®
;Override above condition for node N18®
NODE N18® Cb 8.5
4.10 [PARAMETERS]
Purpose:
Defines values for specific reaction rate parameters on a pipe by pipe or tank by tank basis.
Formats:
PIPE pipelD paramID value
TANK tankID paramID value
Definitions:
pipe ID:
tankID:
paramID
value:
Remarks:
• Use one line for each pipe or tank whose parameter value is different than the global value.
the ID label of a pipe link in the network
the ID label of a tank node in the network
the name of one of the reaction rate parameters listed in the [COEFFICIENTS] section
the parameter's value used for the specified pipe or tank.
4.10. [PARAMETERS]
33
</pre><hr><pre>
-------
EPANETMSX USERS MANUAL, Release 2.0
4.11 [PATTERNS]
Purpose:
Defines time patterns used to vary external source strength over time.
Formats:
name multiplier multiplier
Definitions:
name:	an identifier assigned to the time pattern
multiplier: a multiplier used to adjust a baseline value
Remarks:
•	Use one or more lines for each time pattern included in the model.
•	If extending the list of multipliers to another line remember to begin the line with the pattern name.
•	All patterns share the same time period interval (pattern time step) as defined in the [TIMES] section of the
EPANET input file being used in conjunction with the EPANET-MSX input file.
•	Each pattern can have a different number of time periods.
•	When the simulation time exceeds the pattern length the pattern wraps around to its first period.
Examples:
[PATTERNS]
;A 3-hour injection pattern over a 24 hour period
;(assuming a 1-hour pattern time interval is in use)
PI
®.® ®.c
5 ®.® ®.®
1.® 1.®
PI
1.® ®.c
5 ®.® ®.®
®.® ®.®
PI
®.® ®.c
5 ®.® ®.®
®.® ®.®
PI
®.® ®.c
5 ®.® ®.®
®.® ®.®
4.12 [DIFFUSIVITY]
Purpose:
Defines the relative diffusivity of the species to be included when modeling longitudinal dispersion.
Formats:
specielD value
Definitions:
specielD: a species identifier
value: relative diffusivity of the species.
Remarks:
4.11. [PATTERNS]
34
</pre><hr><pre>
-------
EPANETMSX USERS MANUAL, Release 2.0
The relative diffusivity is the ratio of the species' molecular diffusivity in water to that of chlorine at 20 deg.
C (0.00112 ft2/day). If the relative diffusivity of a species is not defined in this section, the dispersion of
the species is neglected.
Examples:
[DIFFUSIVITY]
; same molucular diffusivity as chlorine at 2® deg. C
H0CL 1.®
NH3 1.®
NH2CL 1.®
NHCL2 1.®
4.13 [REPORT]
Purpose:
Describes the contents of the output report produced from a simulation.
Formats:
NODES
NODES
LINKS
LINKS
SPECIES
FILE
PAGESIZE
ALL
nodel node2.
ALL
linkl link2...
speciesID
filename
lines
YES /No (precision)
Definitions:
nodel, node2, etc.:
linkl, link2, etc.:
specielD:
precision:
filename:
lines:
a list of nodes whose results are to be reported
a list of links whose results are to be reported
the name of a species to be reported on
number of decimal places used to report a species' concentration
the name of a file to which the report will be written
the number of lines per page to use in the report.
Remarks:
Use as many NODES and LINKS lines as it takes to specify which locations get reported. The default is not
to report results for any nodes or links.
Use the SPECIES line to specify which species get reported and at what precision. The default is to report no
species. Species selected for reporting have a default of two decimal places of precision.
The FILE line is used to have the report written to a specific file. If not provided the report will be written to
the same file used for reporting program errors and simulation status.
Examples:
4.13. [REPORT]
35
</pre><hr><pre>
-------
EPANETMSX USERS MANUAL, Release 2.0
[REPORT]
;Write results for all species at all nodes and links
;at all time periods to a specific file
NODES ALL
LINKS ALL
FILE "c:\my files\epanet-msx\myreport.txt"
[REPORT]
;Write nodal results for species SI and S2 using
;4 decimal places to the standard EPANET report file
SPECIES SI YES 4
SPECIES S2 YES 4
NODES ALL
4.13. [REPORT]
36
</pre><hr><pre>
-------
CHAPTER
FIVE
EXAMPLE REACTION SYSTEMS
This section demonstrates how several different multi-species reaction systems of interest can be modeled with EPANET-MSX.
5.1 Multi-Source Chlorine Decay
Multi-source networks present problems modeling a single species, such as free chlorine, when the decay rates observed in the
source waters vary quite significantly. As the sources blend differently throughout the network, it becomes difficult to assign a
single decay coefficient that accurately reflects the decay rate observed in the blended water. Consider the distribution system
shown in Fig. 5.1 that is served by two different sources. The network has been color-coded to show the average fraction of water
in each pipe that originates from the River (Source 1).
Fig. 5.1: Example of a two-source water distribution system showing the average percent of water originating from the River
source
Assume that free chlorine reacts in the bulk flow along a pipe according to the following first-order rate expression:
^ = —kC
dt
(5.1)
37
</pre><hr><pre>
-------
EPANETMSX USERS MANUAL, Release 2.0
where C" is the concentration of free chlorine at time tl and kl is a reaction rate constant. Now suppose that when analyzed
separately in bottle tests, water from Source 1 has a kL = 1.3 days"1 while Source 2's water has kL = 17.7 days"1. The issue becomes
one of determining a fc-value for each pipe of the network that will reflect the proper reactivity of the blended water from both
sources.
One approach to reconciling the vastly different chlorine decay constants in this example, without introducing a more complex
chlorine decay mechanism that attempts to represent the different reactivity of the total organics from the two sources, is to assume
that at any time the chlorine decay constant within a pipe is given by a weighted average of the two source values, where the weights
are the fraction of each source water present in the pipe. These fractions can be deduced by introducing a fictitious conservative
tracer compound at Source 1, denoted as Tl, whose concentration is fixed at a constant 1.0 mg/L. Then at any point in the network
the fraction of water from Source 1 would be the concentration of Tl while the fraction from Source 2 would be 1.0 minus that
value. The resulting chlorine decay model now consists of two-species - a tracer species TV and a free chlorine species C. The
first-order decay constant k for any pipe in the system would be given by:
k = 1.3T1 + 17.7(1.0 -Tl)	(5.2)
while the system reaction dynamics would be expressed by:
dT 1
—r- =°
dt
dC
— = —(1.3T1 + 17.7(1.0 - Tl))C
dt
(5.3)
(5.4)
Listing 5.1 is the MSX input file that defines this model for a network where the two source nodes are represented as reservoirs
with ID names "1" and "2", respectively. Note that it contains no surface species, no equilibrium species, and assumes that a
constant chlorine concentration of 1.2 mg/L is maintained at each source.
Listing 5.1: EPANET-MSX input file for modeling two-source chlorine
decay
[OPTIONS]
AREA_UNITS
RATE_UNITS
SOLVER
TIMESTEP
FT2
DAY
RK5
38®
[SPECIES]
BULK Tl MG
BULK CL2 MG
;Source 1 tracer
;Free chlorine
[COEFFICIENTS]
CONSTANT kl 1.3
CONSTANT k2 17.7
[PIPES]
;T1 is conservative
RATE Tl ®
; Source 1 decay coeff.
; Source 2 decay coeff.
;CL2 has first order decay
RATE CL2 -(kl*Tl + k2*(l-Tl))*CL2
(continues on next page)
5.1. Multi-Source Chlorine Decay
38
</pre><hr><pre>
-------
EPANETMSX USERS MANUAL, Release 2.0
[QUALITY]
;Initial	conditions (= ® if not specified here)
NODE 1	T1 1.®
NODE 1	CL2 1.2
NODE 2	CL2 1.2
(continued from previous page)
5.2 Decay and Dispersion Modeling of Chlorine
This example illustrates how to use EPANET MSX to model the advection, self-decay, and dispersion of the chlorine within a
water distrinution system. The chlorine decay model is the same as the first order decay model in EPANET 2.2. Both bulk decay
and wall decay are considered in this example.
The rate of chlorine first-order decay in bulk water is described as:
rb = —Kb * C
where Kb = a bulk reaction constant and rb = the bulk decay rate.
For first-order decay, the rate of a pipe wall reaction is expressed as:
2 KwKfC
rw = --
R{KW + Kf)
where Kw = wall reaction rate constant (length/time), rw = wall reaction rate, Kf = mass transfer coefficient
(length/time), and R = pipe radius.
Mass transfer coefficients are expressed in terms of a dimensionless Sherwood number (Sh):
K> = Shm
in which V = the molecular diffusivity of the species being transported (length 2 /time) and R = pipe radius. In fully
developed laminar flow, the average Sherwood number along the length of a pipe can be expressed as
Sh = 3.65 + 0.0668(2*/L)ifeSc
l+0M[(2R/L)Re Scf/3
in which Re = Reynolds number and Sc = Schmidt number (kinematic viscosity of water divided by the diffusivity
of the chemical).
For turbulent flow, the empirical correlation is used:
Sh = O.OU9Re088Sc1/3
Listing 5.2 is the MSX input file that defines this model for the EPANET example model NET2. In this model, Kb = 0.3/day
and Kw = 1.0ft/day. The Schmidt number is specified in the file as a dimensionless constant of 846.15, based on the kinematic
viscosity of water and molecular diffusivity of chlorine. The terms SHt and SHI are defined as the Sherwood number under the
turbulent and laminar flow condition, respectively. STEP is the step function defined inside the EPANET MSX: STEP (x<=0 ? 0
: 1). This function determines the Sherwood number based on the Reynolds number (Re). As described in Section 4.5, D, Len,
and Re are reserved keywords for the Reynolds number, pipe diameter, and pipe length, respectively. The molecular diffusivity of
chlorine is 1.3 x 10~8/t2/s. Since the rate unit here is day, it is correspondingly converted to 0.00112 ft2/day for the caluclation
of Kf.
5.2. Decay and Dispersion Modeling of Chlorine	39
</pre><hr><pre>
-------
EPANETMSX USERS MANUAL, Release 2.0
In order to model the longitudinal dispersion, the relative diffusivity of chlorine is defined in the [DIFFUSIVITY] section. It is
simply 1.0 (1.3 x 10~8/t2/s) here. It should be noted that the molecular diffusivity used in the calculation of Kf is to model
the transport of chlorine from the bulk water to the pipe wall, while the diffusivity specified in the [DIFFUSIVITY] section is to
model the longitudinal dispersion of chlorine. If the relative diffsusity of chlorine is not defined, longitudinal dispersion is ignored
and the model will be the same as the EPANET's first-order decay model.
Listing 5.2: EPANET-MSX input file for modeling chlorine decay and
dispersion (example2.msx)
[TITLE]
NET2 Chlorine Decay and Dispersion
[OPTIONS]
AREA_UNITS	FT2
RATE_UNITS	DAY
SOLVER	EUL
TIMESTEP	6®
RTOL	8.881
ATOL	8.881
[SPECIES]
BULK	CL2 MG 8.81 8.881
[COEFFICIENTS]
PARAMETER Kb 8.3
PARAMETER Kw 1.8
CONSTANT Sc 846.15
[TERMS]
SHt 8.8149*ReA8.88*ScA8.3333
Interm D*Re*Sc/LEN
SHI 3.65 + 8.8668 * Interm / (1.8 + 8.84 * IntermA8.6667)
SH STEP(Re-2388)*SHt+STEP(2388-RE)*SHl
Kf SH-8.88112/D
[PIPE]
RATE CL2 -Kb*CL2-(4/D)*Kw*Kf/(Kw+Kf)*CL2
[TANK]
RATE CL2 -Kb*CL2
[SOURCES]
CONC	1	CL2	8.8
(continues on next page)
5.2. Decay and Dispersion Modeling of Chlorine
40
</pre><hr><pre>
-------
EPANETMSX USERS MANUAL, Release 2.0
(continued from previous page)
[QUALITY]
GLOBAL	CL2 8.5
NODE	26 CL2 8.1
[DIFFUSIVITY]
CL2 1.8
[PARAMETERS]
[REPORT]
NODES 2 28 23 26 34
SPECIES CL2 YES
5.3 Oxidation, Mass Transfer, and Adsorption
This example is an extension and more complete description of the arsenic oxidation/adsorption model that was presented previ-
ously in sections CONCEPTUAL FRAMEWORK (Section 2) and PROGRAM USAGE (Section 3) of this manual. It models the
oxidation of arsenite As+3 to arsenate As+Z by a monochloramine disinfectant residual NH2CI in the bulk flow along with the
subsequent adsorption of arsenate onto exposed iron on the pipe wall. We also include a mass transfer limitation to the rate at
which arsenate can migrate to the pipe wall where it is adsorbed.
Fig. 5.2 shows a schematic of the arsenic model. Note that after arsenate is produced by the oxidation of arsenite in the bulk
solution it diffuses through a boundary layer to reach a concentration denoted as As+5 just adjacent to the pipe wall. It is this
concentration that interacts with adsorbed arsenate As+5 on the pipe wall. Thus the system contains five species (dissolved arsenite
in bulk solution, dissolved arsenate in bulk solution, monochloramine in bulk solution, dissolved arsenate just adjacent to the pipe
wall surface and sorbed arsenate on the pipe surface). One might argue that arsenate is a single species that appears in three
different forms (bulk dissolved, wall dissolved, and wall sorbed), but for the purposes of modeling it is necessary to distinguish
each form as a separate species.
As+3 + NH2CI
	> As+5
Bulk Flow
—
Asj5lw
Boundary Layer
|H Pipe Wall
Fig. 5.2: Schematic of the mass transfer limited arsenic oxidation/adsorption system
The mathematical form of this reaction system can be modeled with five differential rate equations in the case of non-equilibrium
5.3. Oxidation, Mass Transfer, and Adsorption
41
</pre><hr><pre>
-------
EPANETMSX USERS MANUAL, Release 2.0
adsorption/desorption (see, e.g., [Gu et al., 1994], for a more complete description of non-equilibrium adsorption/desorption):
A A o+3
-kaAs+3(NH2Cl)	(5.5)
dt
dAs+s
dAs+5
dt
Kf =	" 		(5.10)
d{NHdfl) = "M^D	(5.6)
dt kaAs+3(NH2Cl) - KfAv(As+5 - As+5)	(5.7)
KfAv(As+5 - As+5) - Av[ki{Smax - As+5)As+5 - k2Asf}	(5-8)
r! A
—^ = kl{Smax-Astz)Aslz-k2Asf	(5-9)
where As+3 is the bulk phase concentration of arsenite, As+Z is the bulk phase concentration of arsenate, As+5 is the bulk phase
concentration of arsenate adjacent to the pipe wall, As+5 is surface phase concentration of arsenate, and NH2Cl is the bulk phase
concentration of monochloramine. The parameters in these equations are as follows: ka is a rate coefficient for arsenite oxidation,
kb is a monochloramine decay rate coefficient due to reactions with all other reactants (including arsenite), Av is the pipe surface
area per liter of pipe volume, k\ and k2 are the arsenate adsorption and desorption rate coefficients, Smax is the maximum pipe
surface concentration, and Kf is a mass transfer rate coefficient. The mass transfer coefficient Kf will in general depend on the
amount of flow turbulence as well as the diameter of the pipe. A typical empirical relation might be:
6.67 x It)~6Re0S'
~D
where Re is the flow Reynolds number and D is the pipe diameter.
Using the notation defined in (2.1)-(2.3), xb = {As+3, As+Z, As+5, NH2Cl}, xs = {As+5}, zb = {0}, zs = {0}, and p = {ka,
kb, Av, k\, k2, Kf, Smax}. The reaction dynamics defined by (5.5)-(5.9) conserves total arsenic mass within any pipe segment of
length L (and thus bulk volume Ax L, and pipe surface area P x L, where A and P are cross sectional area and wetted perimeter,
respectively). This can be shown by summing the differential changes in the mass of all arsenic species within a pipe segment,
and assuring that they sum to zero: (A x L)(dA^3) + (A x L)(dAdst+5) + (A x L)(dA°™ ) + (P x L)(dA°° ) = 0.
It was mentioned in CONCEPTUAL FRAMEWORK (Section 2) that some reactions are reversible and fast enough in comparison
with the system's other processes so that a local equilibrium can be assumed, while others are not sufficiently fast and/or irreversible
and it is inappropriate to use an equilibrium formulation to represent them. In the case of reversible sorption processes a local
equilibrium assumption (LEA) is sometimes assumed between the adsorbed phase and its concentration in the bulk fluid (such an
assumption is not always realistic, and no such claim is made here - see, e.g., [Koopman et al., 1992]). Under the LEA, the rates
dAs
of adsorption and desorption must be much faster than the rate of change of the bulk species, and consequently, dts = 0; the
differential equation (5.9) can then be substituted with the algebraic equation:
a<5 = tzttS	(5.11)
1 + fcsA-Syj
where ks = k\/k2. In this case the DAE system is described by (5.5)-(5.8) and (5.11), and includes four differential rate equations
and one algebraic equation. Thus in terms of the notation used in (2.1)-(2.3), xb = {As+3, As+Z, As+5, NH2Cl], xs = {0}, zb
= {0}, zs = {As+5}, and p = {ka, kb, Av, k\, k2, Kf, Smax}. The LEA model could be left in this form that explicitly includes
the surface adsorbed phase (As+5) - or, because the special form of (5.11) presents an explicit solution for the adsorbed arsenate,
(5.11) could be substituted into (5.8), leaving an equivalent system of only four differential rate expressions in the four bulk-phase
variables xb = {As+3, As+Z, As+5, NH2Cl}. In this latter case, however, the adsorbed phase arsenate concentration would have
to be separately calculated after solution (if desired), using (5.11), which could be laborious if it were required at many locations
and time steps.
Listing 5.3 shows the MSX input file for this system, with the assumption of local equilibrium ((5.5)-(5.8) and (5.11)). The
[PIPES] section contains four kinetic rate reactions involving the four bulk species and one equilibrium reaction that includes the
lone surface species. The [TANKS] section contains only the bulk species reactions. To complete the model specification, the
[QUALITY] section assumes that the network has a single source which is a reservoir node labeled "1", and that the concentrations
at this source remain constant. If this were not the case then a [SOURCES] section could be added that describes the sources in
more detail.
5.3. Oxidation, Mass Transfer, and Adsorption
42
</pre><hr><pre>
-------
EPANETMSX USERS MANUAL, Release 2.0
Listing 5.3: MSX input file for the mass transfer limited arsenic oxida-
tion/adsorption system
[OPTIONS]
AREA_UNITS FT2
RATE_UNITS HR
SOLVER	RK5
TIMESTEP 18®
[SPECIES]
BULK A3 UG
BULK A5 UG
BULK A5w UG
WALL A5s UG
BULK NH2CL MG
;Dissolved arsenite
;Dissolved arsenate
;Dissolved arsenate at wall
;Adsorbed arsenate
{Monochloramine
[COEFFICIENTS]
CONSTANT
Ka
18.®
{Arsenite oxidation rate coeff.
CONSTANT
Kb
8.5®
{Monochloramine decay rate coeff
CONSTANT
Smax
58
{Arsenate adsorption coeff.
CONSTANT
K1
5.8
{Arsenate adsorption rate coeff.
CONSTANT
K2
1.8
{Arsenate desorption rate coeff.
[TERMS]
Kf 6.67e-4*ReA8.88/D
Ks K1/K2
LPERCF 28.316
{Mass transfer coefficient (Ft/Hr)
;Arsenate equil. adsorption coeff.
;Liters/Cu. Ft. (conversion for Kf)
[PIPES]
RATE A3 -Ka*A3*NH2CL	;Arsenite oxidation
;Arsenate production
RATE A5 Ka*A3*NH2CL - LPERCF*Kf*Av*(A5 - A5w)
;Arsenate at pipe wall
RATE A5w LPERCF*Kf*Av*(A5 - A5w) - Av*(Kl*(Smax-A5s)*A5w - K2*A5s)
RATE NH2CL -Kb*NH2CL	;Monochloramine oxidatio
EQUIL A5s Smax*Ks*A5w/(l.8 + Ks*A5w) - A5s ;Arsenate adsorption
[TANKS]
RATE A3 -Ka*A3*NH2CL
RATE A5 Ka*A3*NH2CL
RATE A5w ®
RATE NH2CL -Kb*NH2CL
{Arsenite oxidation
{Arsenate w/o mass tran.
;Not present in a tank
{Monochloramine oxidation
[QUALITY]
{Initial	conditions (= ®
NODE 1	A3 1®.®
NODE 1	A5 ®.®
NODE 1	NHCL 2.5
if not specified here)
Note about equation units. The modeler must understand the units of all quantities used in mathematical expressions, and ensure
that the resulting expressions are dimensionally correct. In short, a complete unit analysis for each expression and resulting RATE
or EQUIL term is an essential quality assurance step for developing MSX models. As an example, consider (5.8) above, repeated
5.3. Oxidation, Mass Transfer, and Adsorption
43
</pre><hr><pre>
-------
EPANETMSX USERS MANUAL, Release 2.0
here for convenience:
dAsw5
dt
= KfMAs+s - As+5) - MkliSmax - As+5)A8+5 - kiAsf]
The units of the left hand side are the units of the bulk species, As+5, divided by the units used for time. Since the default time
unit is hours, the left hand side has units of [fig/L-hr], and consequently each of the two main terms on the right hand side must
have these same units. Since Av was previously defined as the pipe surface area per liter pipe volume, and the default area unit is
[ft2], this quantity has units of [ft2/L] (Av is a pre-defined MSX hydraulic variable - see the description of the [TERMS] input
in INPUT FILE FORMAT (Section 4) of this manual). From this analysis we find that the mass transfer coefficient Kf in the first
term on the right hand side must have units of [L/ft2-hr]. The units of the previous expression for I\f in (5.10) are, however,
the more conventional velocity units of [ft/hr], requiring multiplication by the number of liters per cubic ft: [ft/hr] x [L/ft3]
= [L/ft2-hr], This unit analysis explains the presence of the term LPERCF in the above MSX input file; without this term the
expressions would not be dimensionally consistent and the results would be invalid. The reader should verify that the second term
on the right hand side is dimensionally correct - given the units of Av-provided that rate coefficient ki has units [L/fig-hr], and
k2 has units [l/hr] (recall that the surface species has units of [fig/ft2], since we are using the default area units).
5.4 Bacterial Regrowth with Chlorine Inhibition
This next example models bacterial regrowth as affected by chlorine inhibition within a distribution system. The regrowth model
is taken from Zhang et al. [2004] and includes the following processes depicted in Fig. 5.3:
Fig. 5.3: Conceptual diagram of bacterial regrowth within a pipeline. Dashed arrows represent reactions with chlorine while solid
arrows represent transformation processes
a. Both free bacteria in the bulk flow and bacteria attached to the pipe wall utilize the biodegradable fraction of dissolved
organic carbon (BDOC and DOC, respectively) as a growth substrate. Monod kinetics are used to describe this growth with
the following rate equations:
dX
dt growth
dS	Y/V
It = -"A/1
where A' is mass concentration of bacterial cells, S is the concentration of BDOC, Y is a yield coefficient (mass of
cells produced per unit conversion of BDOC), and fi> is a specific growth coefficient. The latter decreases with the
BDOC concentration according to:
5.4. Bacterial Regrowth with Chlorine Inhibition
44
</pre><hr><pre>
-------
EPANETMSX USERS MANUAL, Release 2.0
l^rriaxS
^ = JTk~s
where Umax is the maximum growth rate coefficient and Ks is the half-saturation constant.
b.	Both free and attached bacteria die at a first order rate:
dX
dt
where kd is a decay rate coefficient.
c.	Deposition of free bacterial cells onto the pipe wall is modeled with the following first-order rate process:
dX
= ~kdX
decay
dt
— ^depX
deposition
while detachment of attached cells into the bulk flow also depends on flow velocity:
dX
dt
= kdetXU
detachment
where kdep is a deposition rate constant, kdet is a detachment rate constant, and U is the bulk flow velocity.
d. The effect of chlorine on limiting the number of viable bacterial cells is modeled by applying an inhibition factor I to the
bacterial specific growth rate as:
'-(C-Ct)
I = exp
Cr
Here C is the chlorine concentration, Ct is a threshold chlorine concentration below which no inhibition occurs,
and Cc is a characteristic chlorine concentration that scales the degree of inhibition. Note at higher values of C, I
becomes smaller and therefore results in smaller bacterial growth rates.
e. Chlorine reacts with DOC in the bulk flow to decay at a first-order rate:
dt ~ b
where C is chlorine concentration and kb is a bulk decay rate coefficient.
The EPANET-MSX specification of the full model is shown in Figure Listing 5.4.
Listing 5.4: MSX input file for a bacterial regrowth model with chlorine
inhibition
[OPTIONS]
AREA_UNITS CM2
RATE_UNITS HR
SOLVER	RK5
TIMESTEP 38®
[SPECIES]


BULK
CL2
MG
;chlorine
BULK
S
MG
;organic substrate
BULK
Xb
UG
;mass of free bacteria
WALL
Xa
UG
;mass of attached bacteria
BULK
Nb
log(N)
;number of free bacteria
WALL
Na
log(N)
;number of attached bacteria
[COEFFICIENTS]
CONSTANT Kb	8.85 ;CL2 decay constant (1/hr)
CONSTANT CL2C 8.2® ;characteristic CL2 (mg/L)
(continues on next page)
5.4. Bacterial Regrowth with Chlorine Inhibition
45
</pre><hr><pre>
-------
EPANETMSX USERS MANUAL, Release 2.0
(continued from previous page)
CONSTANT
CL2Tb
8.83
;threshold CL2 for Xb (mg/L)
CONSTANT
CL2Ta
8.18
;threshold CL2 for Xa (mg/L)
CONSTANT
MUMAXb
8.28
;max. growth rate for Xb (1/hr)
CONSTANT
MUMAXa
8.28
;max. growth rate for Xa (1/hr)
CONSTANT
Ks
8.48
;half saturation constant (mg/L)
CONSTANT
Kdet
8.83
;detachment rate constant (l/hr/(ft/s))
CONSTANT
Kdep
8.88
;deposition rate constant (1/hr)
CONSTANT
Kd
8.86
;bacterial decay constant (1/hr)
CONSTANT
Yg
8.15
;bacterial yield coefficient (mg/mg)
[TERMS]
lb EXP(-STEP(CL2-CL2Tb)*(CL2-CL2Tb)/CL2C)
la EXP(-STEP(CL2-CL2Ta)*(CL2-CL2Ta)/CL2C)
MUb MUMAXb*S/(S+Ks)*Ib
MUa MUMAXa*S/(S+Ks)*Ia
Xb inhibition coeff.
Xa inhibition coeff.
Xb growth rate coeff.
Xa growth rate coeff.
[PIPES]
RATE CL2	-Kb*CL2
RATE S	-(MUa*Xa*Av + MUb*Xb)/Yg/1888
RATE Xb	(MUb-Kd)*Xb + Kdet*Xa*U*Av - Kdep*Xb
RATE Xa	(MUa-Kd)*Xa - Kdet*Xa*U + Kdep*Xb/Av
FORMULA Nb	L0G18(1.8e6*Xb)
FORMULA Na	L0G18(1.8e6*Xa)
[TANKS]
RATE CL2
RATE S
RATE Xb
FORMULA Nb
-Kb*CL2
-MUb*Xb/Yg/1888
(MUb-Kd)*Xb
L0G18(1.8e6*Xb)
[SOURCES]
CONCEN SrcNode	CL2	1.2
CONCEN SrcNode	S	8.4
CONCEN SrcNode	Xb	8.81
Several notes of explanation require mentioning:
1.	There are six species defined for the model: bulk chlorine (CL2), bulk biodegradable dissolved organic carbon (S), bulk
bacterial concentration (Xb), bulk bacterial cell count (Nb), attached bacterial concentration (Xa), and attached bacterial
cell count (Na). CL2 and S are measured in milligrams. The bacterial concentrations are expressed in micrograms of
equivalent carbon so that their numerical values scale more evenly. The bacterial cell counts are expressed as the logarithm
of the number of cells.
2.	The entries in the [PARAMETERS] section are based on values provided by Zhang et al. [2004] and are used only for
illustrative purposes.
3.	The [TERMS] section allows one to define intermediate mathematical terms in the model's description so that the rate
equations can be expressed more clearly and compactly.
4.	The chlorine inhibition threshold concentration is lower for the bulk phase than for the surface phase. This results in defining
separate inhibition factors, lb and la for these two phases, respectively.
5.	The special EPANET-MSX function STEP(x) used in the definitions of the inhibition factors lb and la is internally evaluated
to 1 when x > 0 and is 0 otherwise.
6.	The variables U and Av are reserved symbols (see Section 4.5) in EPANET-MSX that represent flow velocity and pipe
5.4. Bacterial Regrowth with Chlorine Inhibition	46
</pre><hr><pre>
-------
EPANETMSX USERS MANUAL, Release 2.0
surface area per unit volume, respectively, and their values are automatically computed by the program.
7.	Whenever the surface biomass species appears in the rate expression for a bulk species it is multiplied by Av to convert from
areal density to volumetric concentration. Likewise, the bulk biomass concentration is divided by Av in the rate expression
for attached biomass to convert it to an areal density.
8.	The kinetic rate expressions for tanks do not include any terms involving Xa since it is assumed that surface species do not
exist (or have reduced significance) within storage facilities.
9.	A simple FORMULA expression is used to convert from micrograms of bacterial carbon to logarithmic cell counts. It
assumes that there are 106 cells per microgram of carbon in the cell biomass.
10. The model assumes that there is a single source node named SrcNode that supplies all water to the system. The [SOURCES]
section specifies the concentrations of chlorine, biodegradable carbon, and bulk bacterial concentration in this water. The
latter value was derived from assuming that the treated source water contained 10 cells/mL (i.e., 104 cells per liter).
5.5 Chloramine Decomposition
This final example illustrates a complex chemical reaction system involving both kinetic rate expressions and nonlinear equilibrium
relationships. The system being studied is the auto-decomposition of monochloramine to ammonia in the presence of natural
organic matter (NOM). When chloramines are used as a secondary disinfectant care must be taken to avoid producing excessive
amounts of free ammonia that can contribute to biological nitrification episodes within the distribution system. The reaction
model used for this system was developed by Valentine and co-workers [Duirk et al., 2005, Vikesland et al., 2001] and is shown in
Table Table 5.1. The principal species are hypochlorous acid (HOC1), hypochlorite ion (OCL"), ammonia (NH3), ammonium ion
(NH4+), monochloramine (NH2C1), dichloramine (NHCI2), an unidentified intermediate compound (I), and total organic carbon
(TOC). Because the reactions involve acid-base dissociations and the rate coefficient of the disproportionation of NH2C1 is a
function of both pH and carbonate species, the pH-carbonate equilibrium system is also included.
Listing 5.5 shows the EPANET-MSX specification of the monochloramine decay model. There are 14 bulk species and no surface
species. The entries in the [COEFFICIENTS] section are the rate coefficients k\ through k12 listed in Table 5.1. The expression
for k5 as a function of pH and carbonate species is included in the [TERMS] section, as are the rate terms contributed by the
reactants of reactions 1 through 12 in Table 5.1. Because there are no surface species in the model, the reaction expressions listed
in the [PIPES] section apply to the storage tanks as well.
The first five rate expressions apply to the various chlorinated species, ammonia, and the un-named intermediate compound.
The next three rate expressions, all set equal to 0, state that pH, alkalinity, and TOC are assumed to remain constant. These are
followed by two equilibrium expressions that represent the dissociation reactions of hypochlorous acid and ammonia, respectively.
The final set of four equilibrium expressions model the distribution of the various carbonate species under conditions of constant
alkalinity and pH. Note that in order to solve this carbonate equilibrium sub-system it is necessary to supply initial values for pH
and alkalinity at all nodes of whatever network is being modeled. This is done in the [QUALITY] section, using the GLOBAL
specifier to set values throughout the network. (The alkalinity of 0.004 moles/L is equivalent to 200 mg/L CaC03 while the H+
value of 2.818 x 10~8 moles/L is the same as a pH of 7.55.)
5.5. Chloramine Decomposition
47
</pre><hr><pre>
-------
EPANETMSX USERS MANUAL, Release 2.0
Table 5.1: Monochloramine decay model based on Vikesland et al.
(2001) and Duirk et al. (2005).

Reaction Stoichiometiy
Rate Coefficient Equilibrium Constant
k. i
IKH I + MI ¦ Ml (1 + ll (>
ki 1.5 x III .1/ b 1
R.2
NH2CI + H2() HOCI + Nl-h
k2 = 7.6 x 10"2 h-1
R.3
HOCI + NH;CI NHCI: + H:0
k3 = 1.0 x lO6^-1 hr1
R.4
nhci2 + h2o HOCI + NH2CI
k4 = 2.3 x HT3 br1
R.5
NH:CI + NH2CI NHCI2 + NH;
k5 = 2.5 x 107[F+]+4.0 x 104[H2CO3] + m[HCO3]M-2h-1
R.6
NHCI2 + NH? NH2CI + NH2CI
k6 = 2.2 x 108M-2h-1
R.7
NHCIo + H20 I
k7 = 4.0 x 105 M~1br1
R.X
I + NHC12 —> HOCI + products
k8 = 1.0 x 108M-1h-1
R.9
I + NH2C1 —> products
kg = 3.0 x 107 M-lbrx
R. 10
NH2C1 + NHC12 —> products
kw = 55.0 M~1brl
R.ll
NH2C1 + Si x TOC ->• products15
fcn = 3.0 x 104 M~lbr1


Si = 0.02
R. 12
HOCI + S2 x TOC —> products0
ki2 = 6.5 x 10


S2 = 0.5
E.l
HOCI ^ H+ + OCI"
pKa = 7.5
E.2
NH4+ O NH;, + H+
pKa = 9.3
E.3
H2CCh <->¦ HCOr + H+
pKa =6.3
E.4
HCO: CO : ' + H+
pKa = 10.3
Notes:
a.	All rate coefficients and equilibrium constants are for 25 degrees C.
b.	Si is the fast reactive fraction of TOC.
c.	S2 is the slow reactive fraction of TOC.
Listing 5.5: EPANET-MSX input file of the monochloramine decompo-
sition model
[OPTIONS]

RATE_UNITS
HR
SOLVER
R0S2
COUPLING
NONE
TIMESTEP
38®
RT0L
8.8881
AT0L
1.8e-8
[SPECIES]


BULK
H0CL
MOLES
;hypochlorous acid
BULK
NH3
MOLES
;ammonia
BULK
NH2CL
MOLES
;monochloramine
BULK
NHCL2
MOLES
; dichloramine
BULK
I
MOLES
;unknown intermediate
BULK
OCL
MOLES
;hypochlorite ion
BULK
NH4
MOLES
;ammonium ion
BULK
ALK
MOLES
;total alkalinity
BULK
TOC
MOLES
;total organic carbon
BULK
H
MOLES
;hydrogen ion
(continues on next page)
5.5. Chloramine Decomposition
48
</pre><hr><pre>
-------
EPANETMSX USERS MANUAL, Release 2.0
(continued from previous page)
BULK OH	MOLES ;hydroxide ion
BULK C03 MOLES ;carbonate ion
BULK HCOB MOLES ;bicarbonate ion
BULK H2C03 MOLES ;dissolved carbon dioxide
[COEFFICIENTS]


PARAMETER
kl
1.5el®
PARAMETER
k2
7.6e-2
PARAMETER
kB
1. ®e6
PARAMETER
k4
2.Be-B
PARAMETER
k6
2. 2e8
PARAMETER
k7
4. ®e5
PARAMETER
k8
1. ®e8
PARAMETER
k9
3. ®e7
PARAMETER
kl®
55.®
PARAMETER
PARAMETER
CONSTANT
CONSTANT
kll 3.8E4
kl2 6.5E5
51	8.82
52	8.58
[TERMS]

k5
(2.5e7*H) + (4. 8e4*H2C03) + (888*HC03)
al
kl*H0CL*NH3
a2
k2*NH2CL
a3
k3*HOCL*NH2CL
a4
k4*NHCL2
a5
k5*NH2CL*NH2CL
a6
k6*NHCL2*NH3*H
a7
k7*NHCL2*0H
a8
k8*I*NHCL2
a9
k9*I*NH2CL
al®
kl8*NH2CL*NHCL2
all
kl 1 *S1*T0C*NH2CL
al2
kl2*S2*TOC*HOCL
[PIPES]



RATE
HOCL
-al + a2
- a3 + a4 + a8 - al2
RATE
NH3
-al + a2
+ a5 - a6 + all
RATE
NH2CL
al - a2
- a3 + a4 - a5 + a6
RATE
NHCL2
a3 - a4
+ a5 - a6 - a7 - a8
RATE
I
a7 - a8
- a9
RATE
H
8

RATE
ALK
8

RATE
TOC
8

EQUIL
OCL
H*0CL -
3.16E-8-HOCL
EQUIL
NH4
H*NH3 -
5.81E-18*NH4
EQUIL
CO 3
H*C03 -
5.81E-11*HC03
EQUIL
H2C03
H*HC03
- 5.81E-7-H2C03
EQUIL
HC03
ALK - HC03 - 2*C03 - OH + H
EQUIL
OH
H*0H -
1.8E-14
(continues on next page)
5.5. Chloramine Decomposition
49
</pre><hr><pre>
-------
EPANETMSX USERS MANUAL, Release 2.0
(continued from previous page)
[QUALITY]
GLOBAL	ALK 8.884
GLOBAL	H 2.818E-8
5.5. Chloramine Decomposition
50
</pre><hr><pre>
-------
EPANETMSX USERS MANUAL, Release 2.0
5.5. Chloramine Decomposition	51
</pre><hr><pre>
-------
APPENDIX
A
MSX TOOLKIT FUNCTIONS
The EPANET-MSX toolkit is a library of functions that programmers can use to create their own custom versions of the multi-
species extension of EPANET. The MSX functions are used in conjunction with the standard EPANET toolkit functions [Rossman,
1999] which can also provide additional flexibility for programmers. Information on using the standard EPANET toolkit is online
at http://wateranalytics.org/EPANET/. Table A. 1, Table A.2, and Table A.3 list the name of each MSX toolkit function along with
a brief description of its purpose.
These functions reside in a Windows Dynamic Link Library (DLL) named epanetmsx.dll and can be used in any programming
language that can access DLLs, such as C/C++, Delphi Pascal, Visual Basic, MATLAB and Python. The toolkit also includes
special header files that must be included in any program modules that reference the MSX functions. These header files are named
epanetmsx.h for C/C++ programs, epanetmsx.pas for Delphi/Pascal programs, and epanetmsx.bas for Visual Basic programs.
Prior to using any of the MSX toolkit functions a standard EPANET input file must be opened using the ENopen function from
the standard EPANET toolkit DLL, epanet2.dll. In addition, after all processing is completed the ENclose function from the
standard toolkit must be called. Thus the header files for the standard toolkit (epanetl.h, epanet2.pas, or epanet2.bas) must also
be included in the application's code. Finally, if a stand-alone command line executable is being produced from C/C++ then the
LIB files epanel2.lib and epanetmsx.lib must be linked in when the compiled source files are linked together.
The following pages provide a description of each toolkit function using C/C++ syntax to represent argument variables and return
types.
Table A. 1: EPANET-MSX toolkit processing functions
Function Name
Purpose
MSXopen
Opens the EPANET-MSX toolkit system.
MSXclose
Closes the EPANET-MSX toolkit system.
MSXsolveH
Solves for system hydraulics over the entire simulation period, saving results to
an internal scratch file.
MSXusehydfile
Uses a previously saved EPANET hydraulics file as the source of hydraulic
information.
MSXsolveQ
Solves for water quality over the entire simulation period and saves the results
to an internal scratch file.
MSXinit
Initializes the MSX system before solving for water quality results in a step-
wise fashion.
MSXstep
Advances the water quality solution through a single water quality time step
when performing a step-wise simulation.
MSXsaveoutfile
Saves water quality results computed for each node, link and reporting time
period to a named binary file.
MSXsavemsxfile
Saves the data associated with the current MSX project into a new MSX input
file.

52
</pre><hr><pre>
-------
EPANETMSX USERS MANUAL, Release 2.0
Table A.2: EPANET-MSX toolkit data retrieval functions
Function Name
Purpose
MSXgetindex
Retrieves the internal index number of an MSX object given its ID name.
MSXgellD
Retrieves the ID name of an MSX object given its internal index number.
MSXgetspecies
Retrieves the attributes of a chemical species given its internal index number.
MSXgetqual
MSXgetconstant
MSXgetparameter
MSXgetsource
MSXgetpatternlen
MSXgetpatternvalue
MSXgeterror
Retrieves the concentration of a chemical species at a specific node or link of
the network at the current simulation time step.
Retrieves the value of a particular reaction constant.
Retrieves the value of a particular reaction parameter for a given pipe or tank
within the pipe network.
Retrieves information on any external source of a particular chemical species
assigned to a specific node of the pipe network.
Retrieves the number of time periods within a source time pattern.
Retrieves the multiplier at a specific time period for a given source time pattern.
Returns the text for an error message given its error code.
Table A. 3: EPANET-MSX data modification functions
Function Name
Purpose
MSXsetconstant
MSXsetparameter
MSXsetinitqual
MSXsetsource
MSXsetpattern
MSXsetpatternvalue
MSXaddpattern
Assigns a new value to a specific reaction constant.
Assigns a value to a particular reaction parameter for a given pipe or tank within
the pipe network.
Assigns an initial concentration of a particular chemical species to a specific
node or link of the pipe network.
Sets the attributes of an external source of a particular chemical species to a
specific node of the pipe network.
Assigns a new set of multipliers to a given MSX source time pattern.
Assigns a new value to the multiplier for a specific time period in a given MSX
source time pattern.
Adds a new, empty MSX source time pattern to the project.
A.l MSXopen
Declaration:
int MSXopen(char * f);
Description:
Opens the EPANET-MSX toolkit system.
Arguments:
f is a C-style character string containing the name of an EPANET-MSX input file.
Returns:
A.l. MSXopen
53
</pre><hr><pre>
-------
EPANETMSX USERS MANUAL, Release 2.0
Returns an error code or 0 for no error.
Notes:
The standard EPANET toolkit function ENopen must have been called first to open the EPANET toolkit along with
an associated EPANET input file for the network being analyzed as well as to identify the name of a report file to
which results are written.
Example:
//Open the EPANET toolkit
int err = ENopen("examplel,inp", "examplel.rpt", "");
//Open the MSX toolkit
if (err == 8) err = MSXopen("examplel.msx");
//Add code to perform required analyses here
if (err == ®) ...
//Don't forget to close the toolkits
MSXcloseO ;
ENcloseQ ;
exit(err);
A.2 MSXclose
Declaration:
int MSXclose(void);
Description:
Closes the EPANET-MSX toolkit system.
Arguments:
None.
Returns:
Returns an error code or 0 for no error.
Notes:
The EPANET toolkit function ENclose should be called at some point after calling MSXclose to close the EPANET
toolkit system.
Example:
(continues on next page)
A.2. MSXclose
54
</pre><hr><pre>
-------
EPANETMSX USERS MANUAL, Release 2.0
(continued from previous page)
int err = ENopen("examplel.inp", "examplel.rpt", "");
//Open the MSX toolkit
if (err = ®) err = MSXopen("examplel.msx");
//Add code to perform required analyses here
if (err == ®)
//Don't forget to close both toolkits
MSXcloseO ;
ENcloseO;
A.3 MSXsolveH
Declaration:
int MSXsolveH(void);
Description:
Solves for system hydraulics over the entire simulation period and saves results to an internal scratch file.
Arguments:
None.
Returns:
Returns an error code or 0 for no error.
Notes:
Either this function or MSXusehydf i le (see belowMSXusehydfile) must be called before any water quality processing
is performed.
Example:
//Open the EPANET & MSX toolkits
int err = ENopen("examplel.inp", "examplel.rpt", "");
if (err == ®) MSXopen("examplel.msx");
//Solve for hydraulics
if (err == ®) err = MSXsolveHQ;
//Perform water quality analysis starting here
A.3. MSXsolveH
55
</pre><hr><pre>
-------
EPANETMSX USERS MANUAL, Release 2.0
A.4 MSXusehydfile
Declaration:
int MSXusehydfile(char * f);
Description:
Uses a previously saved EPANET hydraulics file as the source of hydraulic information.
Arguments:
f is a C-style character string containing the name of a previously saved hydraulics file for the system being analyzed.
Returns:
Returns an error code or 0 for no error.
Notes:
Either this function or MSXsolveH (see above MSXsolveH) must be called before any water quality processing is
performed.
Example:
//Open the EPANET toolkit
int err = ENopen("example1.inp", "examplel.rpt", "");
if (err > ®) return err;
//Use EPAMET to solve & save hydraulic results
ENsolveHO ;
ENsavehydfile("examplel.hyd");
//Open the MSX toolkit
err = MSXopen("examplel.msx");
if (err > ®) return err;
//Utilize the hydraulic solution just saved to file
err = MSXusehydfile("examplel.hyd");
//Perform water quality analysis starting here
A.4. MSXusehydfile
56
</pre><hr><pre>
-------
EPANETMSX USERS MANUAL, Release 2.0
A.5 MSXsolveQ
Declaration:
int MSXsolveQ(void);
Description:
Solves for water quality over the entire simulation period and saves the results to an internal scratch file.
Arguments:
None.
Returns:
Returns an error code or 0 for no error.
Notes:
This function does not allow access to computed water quality results as the simulation unfolds. If such information
is required, use MSXinit in conjunction with step-wise calls to MSXstep (see below MSXstep).
Example:
//Open the EPAMET & MSX toolkits
int err = ENopen("examplel,inp", "examplel.rpt", "");
if (err == ®) err = MSXopen("examplel.msx");
if (err > ®) return err;
//Solve for hydraulics Si water quality
MSXsolveHO ;
MSXsolveQQ ;
				resin i:s
MSXreportO ;
//Close the toolkits
MSXcloseO ;
ENclose();
A.5. MSXsolveQ
57
</pre><hr><pre>
-------
EPANETMSX USERS MANUAL, Release 2.0
A.6 MSXinit
Declaration:
int MSXinit(int saveFlag);
Purpose:
Initializes the MSX system before solving for water quality results in step-wise fashion.
Arguments:
Set saveFlag to 1 if water quality results should be saved to a scratch binary file, or to 0 if results are not saved to
file.
Returns:
Returns an error code or 0 for no error.
Notes:
This function must be called before a step-wise water quality simulation is performed using MSXstep. Do not call
this function if performing a complete simulation using MSXsolveQ.
Example:
See the example provided for MSXstep.
A.7 MSXstep
Declaration:
int MSXstep(double * t, double * tleft);
Description:
Advances the water quality solution through a single water quality time step when performing a step-wise simulation.
Arguments:
Upon returning, t will contain the current simulation time at the end of the step (in seconds) while tleft will contain
the time left in the simulation (also in seconds).
Returns:
Returns an error code or 0 for no error.
Notes:
This function should be placed in a loop that repeats until the value of tleft becomes 0. MSXinit should be called
before beginning the loop.
The water quality time step used by this function is specified in the [OPTIONS] section of the MSX input file.
Example:
//Declare time variables
double t = ®.®, tleft = ®.®;
(continues on next page)
A.6. MSXinit
58
</pre><hr><pre>
-------
EPANETMSX USERS MANUAL, Release 2.0
(continued from previous page)
int err;
//Open the EPANET & MSX toolkits
//Solve for hydraulics
MSXsolveHQ ;
//Run a water quality simulation
MSXinit(S);
do {
err = MSXstep(&t, frtleft);
//Use MSXgetqual to retrieve results at time t
} while (tleft > ®.® && err == ®);
A.8 MSXsaveoutfile
Declaration:
int MSXsaveoutfile(char * f);
Description:
Saves water quality results computed for each node, link and reporting time period to a named binary file.
Arguments:
f is a C-style character string containing the name of the permanent output results file.
Returns:
Returns an error code or 0 for no error.
Example:
//Open the EPANET & MSX toolkits
//Solve for hydraulics & water quality
MSXsolveHO;
MSXsolveQO;
//Copy saved results to a permanent file
(continues on next page)
A.8. MSXsaveoutfile
59
</pre><hr><pre>
-------
EPANETMSX USERS MANUAL, Release 2.0
(continued from previous page)
MSXsaveoutfile("example1.out");
//Close the toolkits
A.9 MSXsavemsxfile
Declaration:
int MSXsavemsxfile(char * f);
Description:
Saves the data associated with the current MSX project into a new MSX input file.
Arguments:
f is a C-style character string containing the name of the file to which data are saved.
Returns:
Returns an error code or 0 for no error.
Notes:
For a step-wise simulation using MSXstep, this function only applies if MSXinit was called with its saveFlag param-
eter set to 1 (see MSXinit).
The format of the binary results file is described in BINARY OUTPUT FILE FORMAT.
Example:
//Open the EPAMET & MSX toolkits
int err = ENopen("examplel.inp", "examplel.rpt", "");
if (err == ®) err = MSXopen("examplel.msx");
if (err > 8) return err;
//Save the current USX data to a different MSX file
MSXsavemsxfile("examplela,msx");
//i.lose tin' i:oo.lkj. ts
A.9. MSXsavemsxfile
60
</pre><hr><pre>
-------
EPANETMSX USERS MANUAL, Release 2.0
A.10 MSXreport
Declaration:
int MSXreport(void);
Description:
Writes water quality simulations results as instructed by the MSX input file to a text file.
Arguments:
None.
Returns:
Returns an error code or 0 for no error.
Notes:
Results are written to the report file specified in the ENopen function, unless a specific water quality report file is
named in the [REPORT] section of the MSX input file.
Example:
//Open the EPAMET & MSX toolkits
//Solve for hydraulics & water quality
MSXsolveHQ;
MSXsolveQO;
//Write results to the "example!,rpt" file
MSXreport();
//Close the toolkits
A. 11 MSXgetindex
Declaration:
int MSXgetindex(int type, char * name, int * index);
Description:
Retrieves the internal index number of an MSX object given its name.
Arguments:
type is the type of object being sought and must be one of the following pre-defined constants:
A.10. MSXreport
61
</pre><hr><pre>
-------
EPANETMSX USERS MANUAL, Release 2.0
MSX_SPECIES (for a chemical species)
MSX_CONSTANT (for a reaction constant)
MSX_PARAMETER (for a reaction parameter)
MSX_PATTERN (for a time pattern)
name is a C-style character string containing the object's ID name;
index is the sequence number (starting from 1) of the object in the order it was listed in the MSX input file.
Returns:
Returns an error code or 0 for no error.
Example:
//Declare an index variable
int i;
//Open the EPA.SET & MSX toolkits
//Get the index of the chemical species named "CLZ"
MSXgetindex(MSX_SPECIES, "CL2", &i) ;
A.12 MSXgetlDlen
Declaration:
int MSXgetIDlen(int type, int index, int * len);
Description:
Retrieves the number of characters in the ID name of an MSX object given its internal index number.
Arguments:
type is the type of object being sought and must be one of the following pre-defined constants:
MSX_SPECIES (for a chemical species)
MSX_C0NSTANT (for a reaction constant)
MSX_PARAMETER (for a reaction parameter)
MSX_PATTERN (for a time pattern)
index is the sequence number of the object (starting from 1 as listed in the MSX input file);
len is returned with the number of characters in the object's ID name, not counting the null termination character.
A.12. MSXgetlDlen
62
</pre><hr><pre>
-------
EPANETMSX USERS MANUAL, Release 2.0
Returns:
Returns an error code or 0 for no error.
Example:
//This code finds the longest species name within a project
//Declare some variables
int count, i, len, maxlen = ®;
//Open the EPANET & MSX toolkits
//Examine each species
MSXgetcount(MSX_SPECIES, Scount);
for (i=l; i< count; i++) {
//Update longest species name
MSXgetIDlen(MSX_SPECIES, i, &len);
if (len > maxlen) maxlen = len;
}
A.13 MSXgetID
Declaration:
int MSXgetID(int type, int index, char * id, int len);
Description:
Retrieves the ID name of an object given its internal index number.
Arguments:
type is the type of object being sought and must be one of the following pre-defined constants:
MSX_SPECIES (for a chemical species)
MSX_CONSTANT (for a reaction constant)
MSX_PARAMETER (for a reaction parameter)
MSX_PATTERN (for a time pattern)
index is the sequence number of the object (starting from 1 as listed in the MSX input file);
id is a C-style character string that is returned with the object's ID name.
A.13. MSXgetID
63
</pre><hr><pre>
-------
EPANETMSX USERS MANUAL, Release 2.0
len is the maximum number of characters that id can hold, not counting the null termination character.
Returns:
Returns an error code or 0 for no error.
Notes:
The MSXgetlDlen function can determine the number of characters in an object's ID name so that the character array
id can be properly sized (to len + 1).
Example:
//Declare a string to hold a species ID
char id[16];
//Open the EPANET & SSI toolkits
//Get the name of the 2nd species in the MSX input file
MSXgetID(MSX_SPECIES, 2, id, sizeof(id) 1);
A. 14 MSXgetcount
Declaration:
int MSXgetcount(int type, int * count);
Description:
Retrieves the number of objects of a specific type.
Arguments:
type is the type of object being sought and must be one of the following pre-defined constants:
MSX_SPECIES (for a chemical species)
MSX_C0NSTANT (for a reaction constant)
MSX_PARAMETER (for a reaction parameter)
MSX_PATTERN (for a time pattern)
count is the number of objects of that type defined in the MSX input file.
Returns:
Returns an error code or 0 for no error.
Example:
//Declare a variable for the number of chemical species
(continues on next page)
A.14. MSXgetcount
64
</pre><hr><pre>
-------
EPANETMSX USERS MANUAL, Release 2.0
(continued from previous page)
int nSpecies;
//Open the EPANET & MSX toolkits
//Get the number of species
MSXgetcount(MSX_SPECIES, &nSpecies);
A. 15 MSXgetspecies
Declaration:
int MSXgetspecies(int species, int * type, char * units, double * aTol,
double * rTol);
Description:
Retrieves the attributes of a chemical species given its internal index number.
Arguments:
species is the sequence number of the species (starting from 1 as listed in the MSX input file);
type is returned with one of the following pre-defined constants:
MSX_BULK (defined as ®) for a bulk water species
MSX_WALL (defined as 1) for a pipe wall surface species
units is a C-style character string array that is returned with the mass units that were defined for the species in
question. It must be sized to hold a maximum of 15 characters plus the terminating null character (for a total of 16).
aTol is returned with the absolute concentration tolerance defined for the species (in concentration units);
rTol is returned with the relative concentration tolerance defined for the species.
Returns:
Returns an error code or 0 for no error.
Example:
//Declare some variables
int slndex, sType, sUnits;
double
aTol, rTol;
//Open the EPA.NET & SSX toolkits
//Get attributes of the species named "Xwa.ll"
(continues on next page)
A.15. MSXgetspecies
65
</pre><hr><pre>
-------
EPANETMSX USERS MANUAL, Release 2.0
(continued from previous page)
MSXgetindex(MSX_SPECIES, "Xwall", &slndex);
MSXgetspecie(slndex, &sType, &sllnits, &aTol, &rTol);
A.16 MSXgetinitqual
Declaration:
int MSXgetinitqual(int obj, int index, int species, double * value);
Description:
Retrieves the initial concentration of a particular chemical species assigned to a specific node or link of the pipe
network.
Arguments:
obj is type of object being queried and must be either:
MSX_N0DE (defined as ®) for a node
MSX_LINK (defined as 1) for a link
index is the internal sequence number (starting from 1) assigned to the node or link;
species is the sequence number of the species (starting from 1);
value is returned with the initial concentration of the species at the node or link of interest.
Returns:
Returns an error code or 0 for no error.
Notes:
The EPANET toolkit functions ENgetnodeindex and ENgetlinkindex can be used to identify the index of a node
or link from its ID name;
Concentrations are expressed as mass units per liter for bulk species and as mass per unit area for surface species.
Example:
int n,
double
s;
c®;
//Open the EPANET & MSX toolkits
//Get initial concentration Of "CL2" in "Tank_A'
ENgetnodeindex("Tank_A", &n);
MSXgetindex(MSX_SPECIES, "CL2", &s);
(continues on next page)
A.16. MSXgetinitqual
66
</pre><hr><pre>
-------
EPANETMSX USERS MANUAL, Release 2.0
(continued from previous page)
MSXgetinitqual(MSX_N0DE, n, s, &c®);
A. 17 MSXgetqual
Declaration:
int MSXgetqual(int obj, int index, int species, double * value);
Description:
Retrieves a chemical species concentration at a given node or the average concentration along a link at the current
simulation time step.
Arguments:
obj is type of object being queried and must be either:
MSX_N0DE (defined as ®) for a node
MSX_LINK (defined as 1) for a link
index is the internal sequence number (starting from 1) assigned to the node or link;
species is the sequence number of the species (starting from 1 as listed in the MSX input file);
value is returned with the computed concentration of the species at the current time period.
Returns:
Returns an error code or 0 for no error.
Notes:
The EPANET toolkit functions ENgetnodeindex and ENgetlinkindex can be used to identify the index of a node
or link from its ID name;
Concentrations are expressed as mass units per liter for bulk species and as mass per unit area for surface species.
Example:
//Declare some variables
long t, tstep;
int n, s;
double c, cMax =8,8;
//Open, the EPANET & MSX toolkits
//Get the indexes o£ node "Tank_A" and species "CL2"
ENgetnodeindex ("Tank ..A", &n) ;
(continues on next page)
A.17. MSXgetqual
67
</pre><hr><pre>
-------
EPANETMSX USERS MANUAL, Release 2.0
(continued from previous page)
MSXgetindex(MSX_SPECIES, "CL2", &s);
//Obtain a hydraulic solution
MSXsolveHO;
//Run a step-wise water quality analysis
//without saving results to file
MSXinit(8);
do {
err = MSXstepC&t, &tleft);
//Retrieve CL2 concentration at Tank_A
MSXgetqual(MSX_N0DE, n, s, &c);
//Update the max, concentration
if (c > cMax) cMax = c;
} while (tleft > ® && err == ®);
//Close the toolkits
A.18 MSXgetconstant
Declaration:
int MSXgetconstant(int index, double * value);
Description:
Retrieves the value of a particular reaction constant.
Arguments:
index is the sequence number of the reaction constant (starting from 1) as it appeared in the MSX input file;
value is returned with the value assigned to the constant.
Returns:
Returns an error code or 0 for no error.
Example:
A.18. MSXgetconstant
68
</pre><hr><pre>
-------
EPANETMSX USERS MANUAL, Release 2.0
//Declare some variables
int i;
double kl;
//Open the EPANET & MSX toolkits
//Get the index of the constant named Kl
MSXgetindex(MSX_CONSTANT, "Kl", &i);
//Get the value of Kl
MSXgetconstant(i, &kl);
A.19 MSXgetparameter
Declaration:
int MSXgetparameter(int obj, int index, int param, double * value);
Description:
Retrieves the value of a particular reaction parameter for a given pipe or tank within the pipe network.
Arguments:
obj is type of object being queried and must be either:
MSX_N0DE (defined as ®) for a node
MSX_LINK (defined as 1) for a link
index is the internal sequence number (starting from 1) assigned to the node or link;
param is the sequence number of the parameter (starting from 1 as listed in the MSX input file);
value is returned with the value assigned to the parameter for the node or link of interest.
Returns:
Returns an error code or 0 for no error.
Notes:
Reaction parameters are only defined for storage tank nodes and pipe links. All other types of nodes and links have
parameter values of 0.
Example:
//Declare some variables
int i, j;
(continues on next page)
A.19. MSXgetparameter	69
</pre><hr><pre>
-------
EPANETMSX USERS MANUAL, Release 2.0
(continued from previous page)
double 1<2;
//Open tbe EPAHET & MSX toolkits
//Get the value of parameter "K2" for pipe "PI"
ENgetlinkindex("Pl", &i);
MSXgetindex(MSX_PARAMETER, "K2", &j);
MSXgetparameter(MSX_LINK, i, j, &k2);
A.20 MSXgetsource
Declaration:
int MSXgetsource(int node, int species, int * type, double * level, int * pat);
Description:
Retrieves information on any external source of a particular chemical species assigned to a specific node of the pipe
network.
Arguments:
node is the internal sequence number (starting from 1) assigned to the node of interest;
species is the sequence number of the species of interest (starting from 1 as listed in the MSX input file);
type is returned with the type of external source and will be one of the following pre-defined constants:
MSX_N0S0URCE (defined as -1) for no source
MSX_C0NCEN (defined as ®) for a concentration source
MSX_MASS	(defined as 1) for a mass booster source
MSX_SETP0INT (defined as 2) for a setpoint source
MSX_FL0WPACED (defined as 3) for a flow paced source
The meaning of these source types can be found in the description of the [SOURCES] section of the MSX input file
in INPUT FILE FORMAT of this manual.
level is returned with the baseline concentration (or mass flow rate) of the source;
pat is returned with the index of the time pattern used to add variability to the source's baseline level (and will be 0
if no pattern was defined for the source).
Returns:
Returns an error code or 0 for no error.
A.20. MSXgetsource
70
</pre><hr><pre>
-------
EPANETMSX USERS MANUAL, Release 2.0
Example:
//Declare some variables
int n, s, t, p;
double c;
//Open the EPANET & MSX toolkits
//Get source information for species CL2 at node N1
ENgetnodeindex("Nl", &n);
MSXgetindex(MSX_SPECIES, "CL2", &s);
MSXgetsource(n, s, &t, &c, &p);
A.21 MSXgetpatternlen
Declaration:
int MSXgetpatternlen(int pat, int * len);
Description:
Retrieves the number of time periods within a source time pattern.
Arguments:
pat is the internal sequence number (starting from 1) of the pattern as it appears in the MSX input file;
len is returned with the number of time periods (and therefore number of multipliers) that appear in the pattern.
Returns:
Returns an error code or 0 for no error.
Notes:
This function only applies to source time patterns that appear in the MSX input file. There is a comparable EPANET
toolkit function, ENgetpatternlen, which can be used for the demand patterns defined in the EPANET input file.
Example:
//Declare some variables
int i, n;
//Open the EPANET & MSS toolkits
//Get the number of multipliers (n) in pattern "PI"
(continues on next page)
A.21. MSXgetpatternlen
71
</pre><hr><pre>
-------
EPANETMSX USERS MANUAL, Release 2.0
(continued from previous page)
MSXgetindex(	&i);
MSXgetpatternlen(i, &n);
A.22 MSXgetpatternvalue
Declaration:
int MSXgetpatternvalue(int pat, int period, double * value);
Description:
Retrieves the multiplier at a specific time period for a given source time pattern.
Arguments:
pat is the internal sequence number (starting from 1) of the pattern as it appears in the MSX input file;
period is the index of the time period (starting from 1) whose multiplier is being sought;
value is returned with the value of the pattern's multiplier in the desired period.
Returns:
Returns an error code or 0 for no error.
Notes:
This function only applies to source time patterns that appear in the MSX input file. There is a comparable EPANET
toolkit function, Engetpatternvalue, which can be used for the demand patterns defined in the EPANET input file.
Example:
//Declare some variables
int i, n;
//Open the EPANET & SSX toolkits
//Get the number of multipliers (n) in pattern "PI"
MSXgetindex("Pl", &i);
MSXgetpatternlen(i, &n) ;
A.22. MSXgetpatternvalue
72
</pre><hr><pre>
-------
EPANETMSX USERS MANUAL, Release 2.0
A.23 MSXgeterror
Declaration:
int MSXgeterror(int code, char * msg, int len);
Description:
Returns the text for an error message given its error code.
Arguments:
code is the code number of an error condition generated by EPANET-MSX;
msg is a C-style character string that is returned containing the text of the error message corresponding to the error
code;
len is the maximum number of characters that msg can contain.
Returns:
Returns an error code or 0 for no error.
Notes:
msg should be sized to accept a minimum of 80 characters.
This function only applies to error codes generated by the MSX toolkit. There is a comparable EPANET toolkit
function, ENgeterror, that applies to EPANET errors.
Example:
char msg[31];
//Open the EPANET toolkit & check for errors
int err = Enopen("examplel.imp", "examplel.rpt", "");
if (err > ®) ENgeterror(err, msg);
//Open the MSX toolkit & check for errors
else {
err = MSXopen("examplel.msx");
if (err > 8) MSXgeterror(err, msg);
}
if (err > ®) printf("\n%s", msg);
return err;
A.23. MSXgeterror
73
</pre><hr><pre>
-------
EPANETMSX USERS MANUAL, Release 2.0
A.24 MSXsetconstant
Declaration:
int MSXsetconstant(int index, double value);
Description:
Assigns a new value to a specific reaction constant.
Arguments:
index is the sequence number of the reaction constant (starting from 1) as it appeared in the MSX input file;
value is the new value to be assigned to the constant.
Returns:
Returns an error code or 0 for no error.
Example:
//Declare an index variable
int i;
//Open the EPASET & MSX toolkits
//Get the index of the constant named Kl
MSXgetindex(MSX_CONSTANT, "Kl", &i);
//Set a new value of Kl
MSXsetconstant(i, 8.53);
A.25 MSXsetparameter
Declaration:
int MSXsetparameter(int type, int index, int param, double value);
Description:
Assigns a value to a particular reaction parameter for a given pipe or tank within the pipe network.
Arguments:
type is type of object being queried and must be either:
MSX_N0DE (defined as ®) for a node
MSX_LINK (defined as 1) for a link
A.24. MSXsetconstant
74
</pre><hr><pre>
-------
EPANETMSX USERS MANUAL, Release 2.0
index is the internal sequence number (starting from 1) assigned to the node or link;
param is the sequence number of the parameter (starting from 1 as listed in the MSX input file);
value is the value to be assigned to the parameter for the node or link of interest.
Returns:
Returns an error code or 0 for no error.
Notes:
Reaction parameters are only defined for storage tank nodes and pipe links. Attempts to set parameter values for other
types of nodes and links will be ignored.
Example:
//Declare some index variables
int i, j;
//Open the EMMET & MSX toolkits
//Get indexes for parameter "K2" for pipe "PI"
ENgetlinkindex("Pl", &i);
MSXgetindex(MSX_PARAMETER, "K2", &j);
//Set. a new value for the parameter
MSXsetparameter(MSX_LINK, i, j, 8,25);
A.26 MSXsetinitqual
Declaration:
int MSXsetinitqual(int type, int index, int species, double value);
Description:
Assigns an initial concentration of a particular chemical species to a specific node or link of the pipe network.
Arguments:
type is type of object being queried and must be either:
MSX_N0DE (defined as ®) for a node
MSX_LINK (defined as 1) for a link
index is the internal sequence number (starting from 1) assigned to the node or link;
species is the sequence number of the species (starting from 1 as listed in the MSX input file);
value is the initial concentration of the species to be applied at the node or link of interest.
A.26. MSXsetinitqual
75
</pre><hr><pre>
-------
	EPANETMSX USERS MANUAL, Release 2.0
Returns:
Returns an error code or 0 for no error.
Notes:
The EPANET toolkit functions ENgetnodeindex and ENgetlinkindex can be used to identify the index of a node
or link from its ID name;
Concentrations are expressed as mass units per liter for bulk species and as mass per unit area for surface species.
Example:
//Declare some index variables
int n, s;
//Open the EPANET & MSX toolkits
//Get the indexes of node "Tank_A" and species "CL2"
ENgetnodeindex("Tank_A", &n);
MSXgetindex(MSX_SPECIES, "CL2", &s);
//Then set the initial concentration
MSXsetinitqual(MSX_N0DE, n, s, 1.25);
A.27 MSXsetsource
Declaration:
int MSXsetsource(int node, int species, int type, double level, int pat);
Description:
Sets the attributes of an external source of a particular chemical species to a specific node of the pipe network.
Arguments:
node is the internal sequence number (starting from 1) assigned to the node of interest;
species is the sequence number of the species of interest (starting from 1 as listed in the MSX input file);
type is the type of external source to be utilized and will be one of the following pre-defined constants:
MSX_N0S0URCE (defined as -1) for no source
MSX_C0NCEN	(defined as ®) for a concentration source
MSX_MASS	(defined as 1) for a mass booster source
MSX_SETP0INT (defined as 2) for a setpoint source
(continues on next page)
A.27. MSXsetsource
76
</pre><hr><pre>
-------
EPANETMSX USERS MANUAL, Release 2.0
(continued from previous page)
MSX_FLOWPACED (defined as B) for a flow paced source
The meaning of these source types can be found in the description of the [SOURCES] section of the MSX input file
in INPUT FILE FORMAT of this manual.
level is the baseline concentration (or mass flow rate) of the source;
pat is the index of the time pattern used to add variability to the source's baseline level (use 0 if the source has a
constant strength).
Returns:
Returns an error code or 0 for no error.
Notes:
The EPANET toolkit function ENgetnodeindex can be used to identify the index of a node from its ID name;
Concentrations are expressed as mass units per liter for bulk species and as mass per unit area for surface species.
Example:
//Declare some index variables
int n, s;
//Open the EPANET & MSX toolkits
//Get indexes for species CL2 and node N1
ENgetnodeindex("Nl", &n);
MSXgetindex(MSX_SPECIES, "CL2", &s);
//Assign a constant source strength of 1 mg/L
MSXsetsource(n, s, MSX_SETP0INT, 1.8, ®);
A.28 MSXsetpattern
Declaration:
int MSXsetpattern(int pat, double mult[], int len);
Description:
Assigns a new set of multipliers to a given MSX source time pattern.
Arguments:
pat is the internal sequence number (starting from 1) of the pattern as it appears in the MSX input file;
mult [] is an array of multiplier values to replace those previously used by the pattern;
A.28. MSXsetpattern
77
</pre><hr><pre>
-------
EPANETMSX USERS MANUAL, Release 2.0
len is the number of entries int the multiplier array mult.
Returns:
Returns an error code or 0 for no error.
Notes:
This function only applies to source time patterns that appear in the MSX input file. There is a comparable EPANET
toolkit function, ENsetpattern, which can be used for the demand patterns defined in the EPANET input file.
Example:
//Declare an array of multipliers
double mult[6] = {1.1, 1.5, 8.8, 8.5, 8.2, 8.8};
int i;
//Open the EPANET & MSX toolkits
//Get index for pattern "PI"
MSXgetindex(MSX_PATTERN, "PI", &i);
//Assign, multipliers to the pattern
MSXsetpattern(i, mult, 6);
A.29 MSXsetpatternvalue
Declaration:
int MSXsetpatternvalue(int pat, int period, double value);
Description:
Assigns a new value to the multiplier for a specific time period in a given MSX source time pattern.
Arguments:
pat is the internal sequence number (starting from 1) of the pattern as it appears in the MSX input file;
period is the time period (starting from 1) in the pattern to be replaced;
value is the new multiplier value to use for that time period.
Returns:
Returns an error code or 0 for no error.
Notes:
This function only applies to source time patterns that appear in the MSX input file. There is a comparable EPANET
toolkit function, ENsetpatternvalue, which can be used for the demand patterns defined in the EPANET input file.
Example:
A.29. MSXsetpatternvalue
78
</pre><hr><pre>
-------
EPANETMSX USERS MANUAL, Release 2.0
A.30 MSXaddpattern
Declaration:
int MSXaddpattern(char \* id);
Description:
Adds a new, empty MSX source time pattern to an MSX project
Arguments:
id is a C-style character string containing the name of the new pattern.
Returns:
Returns an error code or 0 for no error.
Notes:
The new pattern has no time periods or multipliers assigned to it. The MSXsetpattern function can be used to assign
an array of multipliers to the pattern.
Example:
//Declare some variables
int err, p;
double mult[6] = {8.5, 8.8, 1.2, 1.8, 8.7, 8.3};
//Create a new pattern named "newPat"
err = MSXaddpattern("newPat");
//Assign multipliers to it
if (err == 8) {
MSXgetindex(MSX_PATTERN, "newPat", &p);
MSXsetpatternCp, mult, 6);
}
A.30. MSXaddpattern
79
</pre><hr><pre>
-------
APPENDIX
B
BINARY OUTPUT FILE FORMAT
The EPANET-MSX system can save the water quality results it computes to a binary output file. This file can be named and saved
to disk using the MSXsaveoutfile function. The format of the file's contents is described in Table B. 1 below.
Table B.l: Format of the EPANET-MSX binary output file
Quantity
Magic number (516114521)
Version number (currently 200000)
Number of network nodes
Number of network links
Number of water quality species
Reporting time step (seconds)
For each water quality species;
Number of characters in ID name (N)
ID name
Species units
For each reporting period:
For each water quality species:
For each network node:
Nodal water quality result
For each water quality species:
For each network link:
Link water quality result
Byte offset where water quality results begin
Error code
Size and Type
4-byle integer
4-byte integer
4-byte integer
4-byte integer
4-byte integer
4-byte integer
4-byte integer
N character bytes
16 character bytes
4-byte float
4-byte float
4-byte integer
4-byte integer
80
</pre><hr><pre>
-------
APPENDIX
c
MSX ERROR CODES
Table C.l: EPANET-MSX Error Codes
Error Code
Description
Error 200:
Cannot read EPANET-MSX file.

One or more errors were found when processing the MSX input file. See the report output file

for details.
Error 501:
insufficient memory available.

There is not enough physical memory in the computer to analyze the pipe network.
.Error 502:
no EPA NET data file supplied.

A standard EPANET input was not opened with a call to ENopen before the MSX system was

opened with MSXopen.
Error 503:
could not open MSX input tile.

The MSX input tile does not exist or cannot be opened (i.e., it may be in use by another

program).
Error 504:
could not open hydraulic results tile.

The hydraulic results file specified in the MSXusehydfile function either does not exist or

cannot be opened.
Error 505:
could not read hydraulic results tile.

The hydraulic results tile generated by the MSXsolveH function or imported by the MSXuse-

hydfile function could not be read correctly. This could happen if, for example, an imported

file was not actually a hydraulic results file.
Error 506:
could not read MSX input tile.

The contents of the MSX input file were formatted incorrectly or had other errors (such as

duplicate ID names for objects of the same type). The specific errors and the offending lines

will be listed in the report file named when calling the ENopen function.
Error 507:
too few pipe reaction expressions.

The total number of Rate, Equilibrium, and Formula expressions in the [PIPES] section of the

MSX input file must equal the total number of species defined.
Error 508:
too few tank reaction expressions.

The total number of Rate, Equilibrium, and Formula expressions in the [TANKS] section of

the MSX input file must equal the total number of bulk species defined.
Error 509:
could not open differential equation solver.

The system's differential equation solver could not be opened, possibly because of insufficient

memory available.
Error 510:
could not open algebraic solver.

The system's nonlinear equation solver could not be opened, possibly because of insufficient

memory available.
Error 511:
could not open binary results file.

The binary output file where EPANET-MSX stores its computed results could not be opened

or does not exist.
continues on next page
81
</pre><hr><pre>
-------
EPANETMSX USERS MANUAL, Release 2.0
Table C.1 - continued from previous page
Error Code
Description
Error 512:
Error 513:
Error 514:
Error 515:
Error 516:
Error 517:
Error 518:
Error 519:
Error 520:
Error 521:
Error 522:
Error 523:
Error 524:
read/write error on binary results flic.
An error occurred when either writing a result to the binary results file or reading a result from
the file.
could not integrate reaction rate expressions.
The differential equation solver employed by EPANET-MSX could not successfully integrate
the system's reaction rate equations over the current water quality time step. One could try
re-running the analysis using a smaller time step or larger values for ATOL and RTOL (as
specified in the [OPTIONS] or [SPECIES] sections of the MSX input file),
could not solve reaction equilibrium expressions.
The nonlinear equation solver employed by EPANET-MSX could not successfully solve the
system's set of equilibrium equations at the current simulation time. Users must insure that
the initial conditions set throughout the pipe network are sufficient and consistent so that a
solution exisits for the governing set of equilibrium equations,
reference made to an unknown type of object.
The object type code number supplied as an argument in one of the MSX toolkit functions
does not equal any of the predefined code numbers,
reference made to an illegal object index.
The object index number supplied as an argument in one of the MSX toolkit functions is either
< = 0 or higher than the number of objects of the type of being referenced,
reference made to an undefined object II).
The object ID name supplied as an argument in one of the MSX toolkit functions does not
belong to any object defined in the MSX input file,
invalid property values were specified.
An invalid value was supplied as an argument to one of the MSX toolkit functions that modifies
a specific property of an object (e.g., an initial or source concentration cannot be a negative
value).
an MSX project was not opened.
A call was made to an MSX toolkit function without having first successfully opened a project
with the MSXopen function,
an MSX project is already opened.
A call was made to open an MSX project without having first closed a currently opened project
with the MSXclose function,
could not open MSX report file.
The MSX report file cannot be opened (i.e., it may be in use by another program),
could not compile chemistry functions.
The compiler selected in the COMPILER option is not available on the user's file system,
could not load functions from compiled chemistry file.
There was an internal error when trying to dynamically load the compiled chemistry functions
into the running application,
illegal math operation.
An illegal operation (such as trying to raise a negative number to a power) occurred while
evaluating a mathematical expression. The species or term with the offending mathematical
expression is identified in the EPANET report file and the simulation is terminated.
82
</pre><hr><pre>
-------
BIBLIOGRAPHY
[1]	H. A. Basha and L. N. Malaeb. Eulerian-lagrangain method for constituent transport in water distribution networks. Journal
of Hydraulic Engineering, 133:1155-1166, October 2007.
[2]	S.E. Duirk, B. Gombert, J-P. Croue, and R.L. Valentine. Modeling monochloramine loss in the presence of natural organic
matter. Water Research, 39:3418-3431, September 2005.
[3]	G. H. Golub and J. M. Ortega. Scientific computing and ordinary differential equations. Academic Press, 1992.
[4]	B. Gu, J. Schmitt, Z. Chen, L. Liang, and J.F. McCarthy. Adsorption and desorption of natural organic matter on iron oxide:
mechanisms and models. Environ. Sci. Technol., 28:38—46, January 1994.
[5]	E. Hairer, S.P Norsett, and G. Warner. Solving Ordinary Differential Equations I. Nonstiff Problems. Springer Series in
Computational Mathematics. Springer-Verlag, 2 edition, 1993.
[6]	D.C. Koopman, J.V. Cole, and H.H. Lee. Assumption of local equilibrium in adsorption processes. AIChE Journal,
38:623-625, April 1992.
[7]	Y. Lee. Mass dispersion in intermittent laminar flow. PhD thesis, University of Cincinnati, Cincinnati, Ohio, USA, 2004.
[8]	W.H. Press, B.P Flannery, S.A. Teukolsky, and W.T. Vetterling. Numerical Recipes in C. Cambridge University Press, 2nd
edition, 1992.
[9]	L. A. Rossman. The epanet programmer's toolkit for analysis of water distribution systems. In Proc. 26th Annual Water
Resources Planning and Management Conference. Reston, VA, 1999. American Society of Civil Engineers.
[10]	L. A. Rossman. EPANET 2 Users Manual. U.S. Environmental Protection Agency, Cincinnati, OH, 2000.
[11]	L. A. Rossman, H. Woo, M. Tryby, F. Shang, R. Janke, and T. Haxton. EPANET 2.2 Users Manual. U.S. Environmental
Protection Agency, Cincinnati, OH, 2020.
[12]	F. Shang, H. Woo, J. B. Burkhardt, and R. Murray. Lagrangian method to model advection-dispersion-reaction transport in
drinking water pipe networks. Journal of Water Resources Planning and Management, September 2021.
[13]	J.G. Verwer, E.J. Spee, J.G. Blom, and W.H. Hundsdorfer. A second order rosenbrock method applied to photochemical
dispersion problems. SI AM Journal on Scientific Computing, 20:1456-1480, 1992.
[14]	P.J. Vikesland, K. Ozekin, and R.L. Valentine. Monochloramine decay in model and distribution system waters. Water Re-
search, 35:1766-1776, May 2001.
[15]	W. Zhang, C. T. Miller, and F. A. DiGiano. Bacterial regrowth model for water distribution systems incorporating alternating
split-operator solution technique. Journal of Environmental Engineering, 130:932-941, September 2004.
83
</pre><hr><pre>
-------</pre></td></tr></table></body></html>