You are on page 1of 15

Environmental Modelling & Software 52 (2014) 207e221

Contents lists available at ScienceDirect

Environmental Modelling & Software

journal homepage:

Vectorized simulation of groundwater ow and streamline transport

George Kourakos, Thomas Harter*
Dept. of Land Air and Water Resources, University of California Davis, Davis, 95616 CA, USA

a r t i c l e i n f o

a b s t r a c t

Article history:
Received 11 April 2013
Received in revised form
21 October 2013
Accepted 26 October 2013
Available online 27 November 2013

We describe a modeling suite of Matlab functions for simulating nonpoint source (NPS) pollution in
groundwater aquifers. The NPS model simulates groundwater ow and contaminant transport from a
large array (order of 102 e 107) of spatially distributed sources with time-varying pollution strength to a
similarly large array of spatially distributed production wells (receptors) using the streamline transport
approach. The code solves three equations: steady-state groundwater ow, particle tracking, and transient advection dispersion contaminant transport. The code performs convolution integration in its
predictive step. Written in highly efcient vectorized form to avoid time consuming for/while loops,
the code is also suitable for other groundwater ow and transport problems. The code is veried against
analytical solutions and nite element software Comsol. An application illustrates 200 years of transient
nitrate transport in the 2000 km2 Tule River aquifer sub-basin of the Central Valley, California, with 9000
individual nitrate sources and 1920 wells.
 2013 Elsevier Ltd. All rights reserved.

Non-point source pollution
Finite element method
Streamline transport
Groundwater modeling

Software availability
Name of Software: mSim
Developers: George Kourakos, Thomas Harter
First available year: 2013
Program Language: Matlab, C/C
Primary contacts: George Kourakos, Thomas Harter
E-mail:,, thharter@
1. Introduction
Numerical simulation models have been established as standard
methods for studying a vast variety of physical phenomena and
environmental processes including water resources (Moriasi et al.,
2012; Bobba, 2012; Bennett et al., 2013). In many countries, water
management decisions are based, to a large extent, on simulation
with numerical models (Refsgaard and Henriksen, 2004). Hence,
numerical models have found broad applicability in research and
education as well as in consulting, decision making, and industry.
Following this trend, groundwater hydrologists also have a long
history of developing and using numerical models for simulating

* Corresponding author.
E-mail addresses:, (G. Kourakos), (T. Harter).
1364-8152/$ e see front matter  2013 Elsevier Ltd. All rights reserved.

groundwater ow and contaminant transport i.e. Modow

(Harbaugh et al., 2000), Parow (Ashby and Falgout, 1996),
HydroGeoSphere (Therrien et al., 2007), Feow (Trefry and Muffels,

2007), SUTRA (Voss, 1984), HYDRUS (Simunek
et al., 2012), IWFM
(Integrated Water Flow Model, 2012), FEMWATER (Lin et al., 1997)
In general, numerical models can be divided into two broad
categories: Open source, where the code is available to the user
under certain license types (e.g. Modow, IWFM, FEMWATER) and
closed source (e.g. HydroGeoSphere, Feow, Comsol (COMSOL,
2008)) where the user has no access to the original code. Typically,
closed source software products are commercial products supported
through license sales (Feow, Comsol). Neither type is necessarily
preferable. The choice depends on user experience and needs and on
budget constraints. Closed source models, especially those available
commercially, are typically accompanied by user-friendly graphical
user interfaces, which attempt to assist and protect the user from
dealing with many of the details involved in a numerical simulation,
i.e. grid generation, assembly process, preconditioners, solvers,
parallel implementation, etc. While this is desirable in many cases, it
is also very important, especially in research, that users have access
and be able to deepen and intervene with the numerical codes. In
addition, open source codes allow widespread reproduction of results, which is fundamental to science and useful to a wider audience
than closed source codes. Hence, open source codes are more
common in education and research, while commercial products are
more popular in consulting and industry. Open source codes, while
transparent to the user, are not always user friendly. For example,


G. Kourakos, T. Harter / Environmental Modelling & Software 52 (2014) 207e221

open source codes such as MODFLOW and FEMWATER, which

simulate the groundwater ow equation and saturated/unsaturated,
density driven, ow and transport respectively, require a tedious
input data preparation process, even for relatively simple applications. For the aforementioned codes, pre- and post-processors have
been developed that assist in the data input and output processing,
e.g. GroundwaterVista, Visual Modow, GMS, ModelMuse
(Winston, 2009), etc.
The majority of open source codes is written in FORTRAN
(Modow, IWFM, Hydrogeosphere, SUTRA, FEMWATER) or C/C
(Comsol, OpenFoam (OpenFoam, 2013), Dune (Dedner et al., 2011)),
which provide strong computational efciency. However reading
and understanding languages such as FORTRAN and C/C requires signicant experience and knowledge of the programming
language itself. Implementing and testing research ideas that
require modications to an existing code are potentially difcult
and error prone tasks. In addition, most recent codes are likely to
use an object oriented programming style e.g. C, which is
convenient for the experienced developer, yet adds another level of
difculty to users that are not programmers.
In addition to products based on high performance languages
such as Fortran and C/C, there is a number of high-level scripting
languages that promise to increase productivity without compromising performance on high performance computing systems
(Chaves et al., 2006) such as Python, Matlab, Octave etc. In addition
these languages are thought to have less steep learning curves when
compared to Fortran or C/C. In particular, Matlab is a proprietary
platform that is very popular among engineering and environmental
sciences students. It provides an interactive environment for numerical computation, visualization, and programming, yet the code
is visible to the user and available for further modications. Octave
on the other hand is an open source programming language under
the GNU license, which is quite similar to Matlab, so that most
programs are easily portable to Matlab. But Octave currently lacks an
interactive and user friendly debugging environment.
Matlab and Octave codes are not considered as efcient as codes
written in compiled programming languages, yet there is a growing
number of examples where Matlab is used to carry out computationally intensive tasks, such as mesh generation (Persson and
Strang, 2004; Talischi et al., 2012), model emulation (Tych and
Young, 2012), remote sensing (Teza et al., 2012), numerical simulations (Lee et al., 2004; Kattan, 2008; Louwyck et al., 2012; Lie
et al., 2012; Kumar and Dodagoudar, 2010), optimization
(Kourakos and Mantoglou, 2008; Kourakos and Mantoglou, 2012a),
neural networks (Kourakos and Mantoglou, 2012b), parallel
computing (Kepner, 2009) etc. The major drawback of Matlab and
Octave is that the execution of repeated tasks in the form of for and
while loop becomes very time consuming when compared to
compiled languages. To alleviate this shortcoming, Matlab and
Octave provide a vectorized formulation of loops. According to
Matlabs denition, vectorization is the conversion of for and
while loops to equivalent vector or matrix operations which can
be performed in Matlab at a speed comparable to FORTRAN and C/
C. The efciency of vectorized implementation for assembling
system matrices that arise from the numerical solution of partial
differential equation has been reported by various studies (Higham,
2002; Koko, 2007; Funken et al., 2011; Andreassen et al., 2011),
while Aslam and Hendren (2012) developed a framework to optimize Matlab code.
In this paper we develop a Matlab program, which we will refer
to as mSim. The code is intended for the simulation of Non-Point
Source (NPS) pollution in groundwater aquifers. The majority of
the Matlab code is portable to Octave without any modication. Yet
there is a small number of preprocessing functions, which are used
to convert the geometrical description of a study area to a

constructive solid geometry object, that are written in the new style
of Matlab classes introduced in the 2008a edition, which is
currently not supported by Octave.
Generally, tools applied to non-point source assessment can be
grouped into three categories (NRC, 1993): 1) Index-based methods
which combine spatial properties of the study area such as soil
type, slope, climate, depth to groundwater, etc. and provide
vulnerability maps (Aller et al., 1987); 2) statistical methods such as
regression models (Nolan and Hitt, 2006), neural networks (AlMahallawi et al., 2012), etc. 3) physically based methods attempt
to simulate the fate of contaminants in groundwater by solving the
ow and transport equations. Due to the large extent of NPS
pollution in groundwater basins, full 3D transport simulation is
limited by the available computational resources to simplied cases
(Gallardo et al., 2005; Jiang and Somers, 2009). A promising alternative to full 3D transport simulation is the application of
streamline transport methods (Fogg et al., 1999; McMahon et al.,
2008; Starn et al., 2012).
To simulate NPS we utilize the streamline modeling framework
proposed by Kourakos et al. (2012) (NPSAT e NonPoint Source
Assessment Toolbox). The NPSAT consists of three major processes:
i) simulation of steady state groundwater ow, ii) backward particle
tracking, and iii) 1D transient transport simulation along the
streamlines. Note that the governing equations used in the NPSAT
also describe a variety of environmental processes, therefore the
code can be used for simulations other than NPS modeling that are
governed by the same equations.
In our implementation we take advantage of the capabilities of
Matlab and develop a highly vectorized code, minimizing the
number of loops as much as possible. Hence we are able to solve
problems up to several million degrees of freedom, while keeping
the assembly and solution processes on the order of minutes.
Matlab/Octave-provided solvers are only used for the solution of
relatively small sparse systems. For large systems, a variety of
existing solvers can seamlessly be combined with mSim, for
example, pyAMG (Bell et al., 2011), which is a python implementation of the Algebraic Multigrid solvers, and HYPRE (HYPRE,
2012) and Trilinos (Heroux et al., 2003), which provide rich libraries for solving large sparse linear systems of equations on
massively parallel computers.
This paper is divided into six sections. The second section presents an overview of mSim. The third section briey describes the
governing equations employed by NPSAT and its nite element
formulation. The fourth section discusses the vectorized implementation. We then describe a validation of mSim against analytical and numerical codes and apply mSim to a real case study in
south-central California, USA. The last section summarizes the
key points of this study.
2. Overview of mSim
The mSim code is a collection of Matlab functions that are primarily intended for the simulation of non-point source (NPS)
pollution in agricultural groundwater basins. The modeling
approach, assumptions and justications are described in detailed
in Kourakos et al. (2012). In this paper we focus on efcient code
development based on the high-level language Matlab/Octave. The
processes that are involved with the NPS pollution modeling are
the simulation of groundwater ow, of particle tracking and of
solute transport along particle streamlines based on the solution of
the advectionedispersion equation.
The Matlab/Octave functions are organized into ve groups: i)
mFlow, ii) mPart, iii) mTrans, iv) mUtil and v) mNPSAT, where each
group is actually a directory that contains the required les for the
simulation of ow, the particle tracking, the simulation of transport,

G. Kourakos, T. Harter / Environmental Modelling & Software 52 (2014) 207e221

various utility functions, and functions related to non-point source

assessment toolbox (NPSAT), respectively. A detailed description of
the functions provided is beyond the scope of this paper. Instead,
details of the implementation can be found in the help les of mSim
and the website
The workow of mSim is similar to any nite element method
(FEM)-based models. First the simulation domain is dened
through a set of primitive objects (e.g. points, lines etc) and then a
mesh is generated. For the mesh generation we use the Gmsh
software (Geuzaine and Remacle, 2009), which is an open source
code for mesh generation. Although Gmsh has its own GUI, all of its
options can be scripted. This allows us to write suitable Matlab
functions that prepare the input les for mesh generation using
Gmsh. In the current version of mSim, Gmsh is used to generate a
2D mesh only, and the 3D mesh is obtained by extruding the 2D
mesh in the vertical direction within mSim.
The mSim is a scripting toolbox, (i.e. without GUI). Therefore, the
assignment of boundary conditions, which involves the selection of
appropriate element faces, lines or points, and the assignment of
properties to these, may become challenging in complex geometries.
But based on our experience, the lack of a GUI provides an advantage
in terms of modeling exibility as GUIs can be useful when geometries
are relatively simple and users have to interactively select only few
planes, which correspond to the boundary conditions. However in
realistic aquifer simulation, where boundaries may be consist of
hundreds of different planes, interactive selection becomes very
inefcient. Typically, GUIs therefore support linking to GIS databases
to assist with the assignment of complex boundary conditions. With
mSim, few lines of Matlab code allow the user to obtain and process
data from almost any available database format.
After the assignment of boundary conditions, the matrices are
assembled and solved using three main commands Assemble_LHS, Assemble_RHS and solve_system, which are used to
assemble the left-hand side matrix of the linear system, then the
right hand side of the system, and nally solve the system,
The nal simulation step is the interpretation of the result.
Matlab and Octave provide a large variety of toolboxes for postprocessing analysis such as statistics, tting, optimization. It also
has a large number of built-in visualization functions. However,
few of these are suitable for visualization of very complex domains or for large scale visualizations which involve simulations
with many degrees of freedom. We therefore use ParaView, which
is an open source visualization software. mSim provides a set of
functions that assist the data preparation for visualization using
Although mSim was initially developed for the simulation of
NPS pollution using a very specic modeling framework (Kourakos
et al., 2012), the code is intended also as an educational and
research tool for studying and experimenting with highly efcient
nite element methods in the broader context of groundwater
hydrology. Since it is written in Matlab/Octave, the code is portable
to any platform and can be readily run on different architectures. In
addition it provides immediate access to linear system matrices,
therefore it can be combined with many solver libraries to increase
the solution efciency.
The mSim Code is available from http://groundwater.ucdavis.
edu/mSim/. The code is provided free of charge and can be redistributed and modied under the terms of the GNU General Public
License version 2 (GPL-2.0).
3. Mathematical framework of NPSAT
In this section we will briey discuss the main components of
the NPSAT approach, which are simulated by mSim. The same set of


governing equations can be used to simulate a variety of phenomena. Therefore the simulation of diffuse pollution will be the
starting point of the mSim development but the methods and
subsequently the code can be extended to simulate other, similar
phenomena. Details and the rationale behind the NPSAT approach
can be found in Kourakos et al. (2012). The NPSAT is implemented
in two phases a) The construction phase which solves the governing equations for user-specied ow boundary conditions and a
unit solute pulse boundary condition to obtain a unit response
function and b) the implementation or forward phase where the
model is used for predictions using convolution of the unit
response functions with complex NPS pollution boundary
The rst phase involves three main steps i) the groundwater
ow equation is solved under the steady state assumption; ii)
based on the computed velocity eld, backward particle tracking
is performed with the starting points of the particles distributed
around Compliance Discharge Surfaces (CDS) of interest (e.g.
wells, gaining streams etc.) and the contributing recharge and
pollution sources to the CDS are identied; iii) a 1D transport
simulation is performed along each streamline to compute the
travel time and magnitude of the pollution at the CDS. In the
transport model we assume a unit Heaviside step loading
function at the recharge boundary, thus the output of the 1D
transport simulation is an ensemble of unit response functions
(URFs) at the CDS. During the implementation phase the URFs
are convoluted with actual loading scenarios (space-time maps
of loading concentration). Since convolution involves only
analytical computation, NPSAT can be used for rapid evaluation
of many alternative loading scenarios (Kourakos et al., 2011,
3.1. Groundwater ow
The governing equation that describes groundwater ow in
steady state is expressed as:



Q 0


where h(x, y, z) is the unknown hydraulic head eld, Kxx, Kyy, Kzz are
the values of the hydraulic conductivity tensor along the major
anisotropy x, y, z axes, and Q represents the various sources and
sinks. Note that the same equation can also be used to simulate heat
transfer, diffusion etc. Eq. (1) can be solved analytically only in very
special cases. To obtain a general solution we solve Eq. (1)with
numerical methods after discretizing the physical domain. The
mSim utilizes a nite element discretization method, where the
continuous hydraulic head eld h(x, y, z) is approximated as the
hx; y; z
N1 h1 N2 h2 . Nn hn . Here hi is the approximate head at the
discretization node and Ni is an interpolation function also known
as shape function.
After the domain discretization, the partial differential equations are simplied into a system of n linear equations (see details
in Istok, 1989; Pepper and Heinrich, 2006; Fish and Belytschko,
2007) in the form of



where A is the conductance matrix with dimensions n  n, H is a

vector of the unknown head n  1, and F is the ux vector n  1 that
contains the stresses and boundary conditions.
Based on the Galerkin nite element discretization (Fairweather,
1978) the matrix A is expressed as:


G. Kourakos, T. Harter / Environmental Modelling & Software 52 (2014) 207e221




and the ux vector F is

F  N T qB dG NT qI dU


3.3. Advectionedispersion
The last step of the construction phase of the NPSAT is the quasi3D transport simulation, which involves the solution of the 1D
advection dispersion equation along each streamline.
The governing equation that describes the contaminant transport assuming advection and dispersion is expressed as:

where B is the derivative matrix of the shape functions, K is the

hydraulic conductivity tensor, N denotes the shape functions, qB
and qI represents the sources and sinks from the boundaries and
internal to domain (e.g. diffuse groundwater recharge, stream interactions pumping etc.) respectively.
Hence, to transform Eq. (1) to a system of linear equations, the
domain is rst discretized into elements. Next, for each element we
compute the element contributions of the conductance and ux
matrices Aei ; Fie i1; .; n via Eqs. (3) and (4) to global matrices A
and F and nally the element matrices are assembled to formulate
the linear system.
3.2. Streamlines and particle tracking
After the computation of a steady state velocity eld, backward
particle tracking is performed which links the polluting sources
with the discharge surfaces within the ow domain (e.g. wells)
based on streamline computation.
Streamlines are a family of curves that are instantaneously
tangent to the velocity vector. The streamlines are computed via
particle tracking by introducing a particle into the velocity eld and
then tracking its trajectory through the domain. Particle tracking
has been used extensively in groundwater hydrology, e.g. for well
protection zone delineation (Moutsopoulos et al., 2008), simulation
of contaminant transport (Perianez, 2005; Morio et al., 2010),
computation of travel times (Green et al., 2010; Eberts et al., 2012)
and visualization (Chen et al., 2011).
Mathematically, particle tracking is an initial value problem of
an ordinary differential equation:

Vx xs ; ys ; zs ; t;
Vy xs ; ys ; zs ; t;
Vz xs ; ys ; zs ; t
where xs, ys, zs are known for some initial time t 0. xs, ys, zs are the
particles coordinates, vx, vy, vz are the components of the velocity
vectors at each point s and Vx, Vy, Vz are functions which dene the
velocity as functions of time and 3D space. To solve this problem, a
variety of numerical methods exist. The simplest method is the
Eulers method (Butcher, 2008), whereby the position of the next
point is a function of the velocity of the previous point. More
advanced techniques such as RungeeKutta (Butcher, 2008)
methods take multiple samples of the velocity space, and the actual
velocity is a weighted average of the sampled velocities. Hence all
methods require the interpolation of the velocity from hydraulic
head eld.
The velocity within a groundwater ow eld is expressed as
v KVh/q where q is the porosity of the porous medium. However
in a discretized solution obtained by FEM the continuous hydraulic
head eld is approximated ashx; y; z N1 h1 . Nn hn , hence
the gradient of the head can be computed using the shape function
derivatives multiplied by the approximated nodal heads
vhx; y; z vN1 h1 . vNn hn . Note that this scheme, where
velocity is directly computed from the derivative of the head eld is
known to produce a discontinuous velocity eld along the
boundaries of the elements (Cordes and Kinzelbach, 1992).

VDVc  Vvc G


where c is the concentration of the contaminant, v is the velocity

which is computed by Eq. (5), and particle tracking, D is the
dispersion tensor, R is the retardation factor, G represents the
additional contaminants sources or sinks and t represents time. Eq.
(6) is generic in terms of dimensionality, however in NPSAT we
solve Eq. (6) in 1D assuming a constant unit input from the loading
(recharge) side of the streamline and compute the unit breakthrough curve at the discharge side of a streamline. The unit
breakthrough curve is subsequently converted to a unit response
Similarly to the solution of the groundwater ow equation, the
ADE domain is discretized into a number of elements and the ADE
is simplied to a linear system of the form AC F. In this case matrix
A is expressed as:




Note that the rst part of the right hand side of Eq. (7) is identical to groundwater ow integral (Eq. (3)). In addition it can be
seen that the contribution of the advection term leads to a
nonsymmetric matrix as opposed to pure diffusion problem.
The expression for the vector F is practically identical to Eq. (4):

F  NT cB dG N T ci dU


where cB and cI represent the contributions to concentration from

external sources and sinks from the boundaries and domain
respectively. To formulate the linear system AC F we rst compute
the element matrices which dene dispersivity Ae and forcing Fe for
each element. Then the matrices are assembled into a global system
of equations.

3.4. Implementation phase

The implementation phase of NPSAT involves only analytical
computations. The output of the construction phase is an ensemble
of URFs that describe the response of the groundwater aquifer
system to a unit input pulse. To compute the breakthrough curves
for actual diffuse pollution we convolute the URFs with the actual
loading scenarios (a transient, spatially variable signal at the
recharge boundary). Convolution is an analytical computation
which mathematically is expressed as:



lt  d$Ud



where c(t) is the streamline breakthrough curve, l is the loading

function, U is the unit response function, and d increases in the
summation at time step intervals. Finally the streamline breakthrough curves associated with an individual CDS (e.g. a well)
are averaged according to their ow contribution to the

G. Kourakos, T. Harter / Environmental Modelling & Software 52 (2014) 207e221

discharge surface, to obtain the nal discharge surface breakthrough curve.

Among the three aforementioned processes (e.g. simulation of
ow, particle tracking and 1D simulation of the ADE) the most
computationally demanding are those associated with the solution
of the partial differential equations, i.e. the simulation of ow. This
requires the assembly of a system of matrices and their solution.
The next section describes a highly vectorized Matlab implementation of the matrix assembly process. It also describes the
similarly vectorized Matlab implementation of the particle tracking
4. Vectorized implementation
4.1. Matrix assembly
Using Eqs. (3) and (4), the individual element matrices Ae and Fe,
are computed and assembled to nal matrices of the linear system
PNel eT e e
Eq. (2) A and F based on the formulas A
e 1 L A L and
PNel eT e
e 1 L F where the matrix L is a gather matrix operator
which consist of 0s and 1s and actually maps the elements of


matrix Ae to the global matrix A. Fig. 1(left) illustrates the owchart

for the serial assembly by iterating through each element. The
gure shows the assembly of 2D isoparametric triangular quadratic
element using Gaussian quadrature for the evaluation of the integrals of Eqs. (3) and (4).
The code consists of two nested loops. The outer loops iterates
through Nel elements. Initially the element coordinates are
extracted and the local element matrix is initialized to a zero matrix
with dimensions Nsh  Nsh, where Nsh is the number of shape
functions that are used for the element interpolation. In the case of
a 2D quadratic triangular element Nsh 6. The integrals in Eq. (3)
and Eq. (4) can be evaluated analytically only for simple linear elements, thus Gauss quadrature is typically used, where the integrals are estimated by the weighted average of point evaluations
of the function to be integrated. Therefore, an additional inner loop
is needed to iterate through Nq sampling points of the Gauss
quadrature. Every loop requires the computation of the shape
function derivatives vN with respect to the parametric coordinates,
the Jacobian J and the inverse Jacobian J1 of the transformation
between parametric and physical coordinates. If the hydraulic
conductivity is variable within the element, then one needs to

Fig. 1. Flowchart of Serial (left) and vectorized (right) assembly of matrix A.


G. Kourakos, T. Harter / Environmental Modelling & Software 52 (2014) 207e221

compute the value at the sampled point and nally add the
weighted elements on the local matrix Ael. After the code exits the
inner loop, the local element contributions are added to the global
matrix. This serial method becomes very inefcient in Matlab or
Octave as the problem of the size grows, due to the fact that the
iterations of the outer loop increase linearly with the size of the
To alleviate this inefciency we employed a vectorized implementation of the assembly process. The owchart of the vectorized
assembly is illustrated in Fig. 1 (right side). In the vectorized
implementation we split the process into two loops. First we iterate
through the Gauss quadrature sampling points and compute the
elements of the local matrices. A second independent loop is used
for assembling the global matrix.
The code starts by extracting the element coordinates outside of
the loop. In the vectorized implementation the matrices X and Y are
vectors with dimensions Nel  Nsh, where Nel is the number of elements, therefore the element coordinates need to be read only
Next for each Gauss quadrature point (x, h) the computations are
performed in a vectorized (parallel) manner. For example, in serial
implementation, the dimensions of the Jacobian matrix J are
Ndim  Ndim where Ndim is the dimension of the problem (e.g. 1D, 2D
or 3D). In the vectorized implementation however, the dimensions
of the Jacobian matrix are Nel  Ndim
where for each element the
values of the Jacobian are stored in a row-major order in a single
row and each column contains the values of Jacobian for a different
element. Similarly the determinant and the inverse Jacobian matrix
are computed in an element wise manner. The shape function derivatives are then multiplied with the elements of the inverse Jacobian matrix, and the outcome is stored into a matrix variable (B)
with dimensions Nel  (Ndim  Nsh)
The hydraulic conductivity is also stored into a matrix Nel  m
where m depends on the hydraulic conductivity anisotropy. The
vectorized implementation is limited to anisotropy along the main
diagonal Kxx s Kyy s Kzz and off diagonal terms are always zero.
However, it is important that hydraulic conductivity K is always
stored in a row-major order to allow for efcient vectorized computations. Finally the contribution of each local element Ae to the
global matrix A is computed simultaneously for all elements and
stored into a matrix in row major order, i.e. the dimensions of Ae
2 . In the
based on the vectorized implementation are Nel  Ndim
vectorized implementation, we rst compute the product of Eq. (3)
BTKB and store it temporarily for each quadrature point and then
we add the weighted contribution of the integrating point to matrix
Ae. At the end of the rst loop matrix, Ae contains the nal values
that need to be gathered to the global matrix A.
To gather the values of matrix Ae, simultaneously for all elements, into the global matrix we iterate through the columns of the
2 iterations. During the assembly of the global
matrix Ae e.g. Nsh
matrix we take advantage of the additive property of the sparse
function (i.e. when two different rows map a local value at the same
entrie of the global matrix, then these values are added).
Although the vectorized assembly is signicantly faster, it requires more storage than the serial implementation. Fig. 2 shows
the number of oating numbers that need to be stored as a function
of the number of elements. For all 2D elements and 3D linear elements the required extra storage is practically negligible, given the
memory that commodity computers offer. However in 3D hexahedral quadratic elements the storage requirement increases
signicantly with the number of elements. For example for 9000
elements we need to store 9000  272 6.5$106 oating point
numbers, while for quadratic prism elements we would need
9000  182 2.9$106. A possible remedy to this problem is the use
of serendipity (incomplete) elements which use less control points

Fig. 2. Memory requirements for the vectorized assembly.

(e.g. 20 instead of 27 for quadratic hexahedral) per elements at the

expense of less exible elements.
An alternative approach is to use a semi-vectorized assembly
which we refer to as nested assembly. In nested implementation
the assembly is performed in three nested loops, where the two
outer loops iterate Nsh times and the inner loop iterates through the
integration points. Therefore the nested implementation requires
Nsh  Nsh  Nint, where Nint is the number of integration points, as
opposed to vectorized approach which requires Nint independent
iterations and Nsh  Nsh iterations.
Despite the additional storage, the assembly time using the
vectorized method is at least 1e2 orders of magnitude less than the
nested and serial assembly. The efciency increases with the
number of elements and as their complexity increases. Fig. 3
compares the assembly time for several common element types
as a function of the number of elements. The family of red, green,
and blue lines correspond to serial, nested and vectorized
In all cases, vectorization signicantly reduces the assembly
time. The solid lines correspond to 3D elements. By comparing the
green solid lines (nested assembly for 3D elements) with the red
solid lines (serial assembly of 3D elements) we observe that the
serial assembly was faster than the nested in the case of relatively
few elements. Yet, in every case the vectorized approach is the
preferred method. If the number of elements is very large, then it is
preferable to use parallel vectorized implementation (under
The assembly process for the transport ADE is practically identical with the process for the groundwater ow equation. The only
difference is that an additional matrix needs to be assembled that
contains the entries of the advective term. Therefore the analysis
presented is identical for the assembly of the ADE.
4.2. Particle tracking
The particle tracking is a strictly serial process as the next position of the particle is a function of the previous position. However,
if the particles do not interact among each other, as is the case here,
it is possible to vectorize the particle tracking so that streamlines
can be computed simultaneously. In our implementation we provide both a serial and a vectorized version of the code. The total
simulation time in the vectorized implementation is dictated by the
time of the particle with the largest trajectory. Particle

G. Kourakos, T. Harter / Environmental Modelling & Software 52 (2014) 207e221


Fig. 3. Comparison between the different assembly methods for various types of elements. The blue, green and red lines correspond to vectorized, nested and serial assembly
respectively. The solid lines correspond to 3D elements and the dotted lines to 2D elements. (For interpretation of the references to colour in this gure legend, the reader is referred
to the web version of this article.)

vectorization is a relatively complex process and we repeatedly

utilize similar techniques as the ones described in the previous
section. The code is approximately 700 lines and a detailed explanation is omitted from this paper. Currently, four options are
available for particle tracking. The simplest is the Euler method, but
the code also offers the option of second order and fourth order
Runge Kutta schemes. To obtain good streamline approximations,
the streamlines must be computed in very small steps. As a fourth
option we therefore provide an adaptive step approach based on
the Runge Kutta Fehlberg scheme or Runge Kutta 45. Although the
latter requires six interpolations of the velocity for each time step it
can be signicantly faster and more accurate compared to the other
integration methods.
The efciency of the vectorized particle tracking is shown in
Fig. 4. In a hypothetical ow eld we release particles, which are

tracked until they exit the ow eld. Note that special care is taken
to ensure that the paths of the particles are approximately equal
(i.e. the particles were released from the same elevation). All scenarios are performed with the adaptive Runge Kutta 45 scheme. As
expected, the CPU time for the serial implementation (Fig. 4, blue
line (in web version)) increases linearly with the number of particles. The CPU time for the vectorized particle tracking (Fig. 4, green
line) is consistently 3e4 times faster than the serial implementation. Due to the fact that particle tracking is in essence a serial
process and that the main while loop cannot be avoided, it is advantageous to convert this part of the code into a C/C version
that can be executed within Matlab. The red line in Fig. 4 shows the
particle tracking time using the C implementation of the code. It
can be seen that it is consistently faster than the vectorized
In summary, mSim offers three modes of particle tracking. i)
Serial in matlab, which is relatively slow, but very useful for
debugging and experimenting. ii) Vectorized in matlab, which is
recommended approach if debugging is necessary. iii) A serial C
implementation called from matlab, which is the most efcient
approach, but also most difcult in terms of debugging and of
adding code to investigate and understand the ow eld and
simulated particle tracks (e.g. multi-dimensional visualization of
particle tracks and velocity vectors).

5. Application
5.1. Model validation

Fig. 4. Comparison of the different modes of particle tracking. Serial and vectorized
modes are implemented in Matlab, C is written in C and runs from Matlab.

The mSim suite contains a large number of functions which have

been thoroughly tested in several applications. In this section we
are presenting two verication examples. The code is rst
compared with an analytical solution and then against the wellestablished numerical software COMSOL Inc.
Since mSim is primarily intended to be used for NPS modeling it
is very important to accurately capture the drawdown caused by
pumping wells. In the rst example we simulate the water table


G. Kourakos, T. Harter / Environmental Modelling & Software 52 (2014) 207e221

around a fully penetrating well. The analytical solution of drawdown due to constant pumping is given by


2pT r


where Sr is the drawdown at a distance r form the well, Q is the

pumping rate, T is the transmissivity and R is the radius of inuence
of the well. To simulate the head loss as function of pumping rate
we set up a hypothetical aquifer of rectangular shape with size
10 km on each side. We assume that a fully penetrated well with
pumping rate equal to Qw 5000 m3/day is located at the center of
the domain. The hydraulic head at the boundaries of the aquifer is
assumed constant and equal to 100 m. We also assumed that the
hydraulic conductivity of the aquifer is K 10 m/day, while the
depth of the aquifer is equal to b 50 m. For the discretization we
used a variable size mesh where the maximum length of the elements near the well is approximately 0.1 m and the maximum
length of the elements is 500 m near the boundaries. The elements
within the aquifer vary between these two values.
Fig. 5 shows the difference between the drawdown computed
with the mSim code and the analytical expression Eq. (10). As expected the error is large near the well and drops to zero as it approaches the prescribed head boundaries. The maximum relative
error of the model prediction is 0.12% which is typical for nite
element solutions (Donea and Huerta, 2003).
Next we compare the mSim code with the COMSOL software, a
proprietary multiphysics simulation package often used for science
and engineering applications. The domain of the problem is
described in Fig. 6. The hypothetical aquifer is a rectangular domain
with dimensions 5  2.5 km and it is divided into two zones of
hydraulic conductivity with K1 10 m/day and K2 2 m/day. The
depth of the aquifer is equal to 50 m. The top and bottom boundaries of the aquifer are considered impervious, and a constant head
boundary is assigned at the left and right boundaries with 40 m and
20 m hydraulic head, respectively. The recharge is uniform and
equal to 0.0004 m/day. In addition there are 10 wells (Fig. 6) that
pump 500 m3/day each.
The aquifer was discretized using triangular linear elements and
the nal model consists of 811 degrees of freedom. However the
actual number of unknowns is 777 as 34 nodes are located on the
constant head boundaries. The aquifer was simulated using COMSOL, which has the option of extracting the actual conductance
matrix and forcing vector of the linear system. Therefore by
comparing the conductance matrix we are able to compare not only
the nal outcome of the model (e.g. the solution) but also the numerical methods used during the assembly process such as the
Gaussian quadrature and the computation of shape function

Fig. 6. Hypothetical aquifer for validation with COMSOL inc.

derivatives. By comparing the conductance matrix obtained from

COMSOL with the one obtained from mSim we observe that they
are practically identical as the maximum relative error of the nonzero values is in the order of 1012 (Fig. 7 green line (in web
Similarly we observe that the maximum discrepancy of the
forcing vector (Fig. 7 blue line) between COMSOL and mSim is in
the order of 1015. Since both matrices are practically identical the
solution (Fig. 7 red line) returns practically identical solutions
(maximum error is approximately 1013 m).
Last we verify the solution of the one-dimensional advectione
dispersion equation. Note that the streamline model requires the
computation of multiple 1D ADE problems in order to derive unit
response functions for each streamline.
For simple geometric boundary conditions, the ADE can be
solved analytically (Ogata and Banks, 1961). The analytical solution
of the 1D ADE for a semi-innite homogeneous isotropic porous
medium with constant input concentration at the boundary can be
expressed as:

x  vt
x vt
erfc p exp
erfc p

2 Dt
2 Dt


where C(x, t) corresponds to the breakthrough curve as a result to

the constant input Co, v is the velocity, and D is the dispersion
In the example below we compare this analytical solution
against the solution obtained from mSim and Comsol for a 1D
problem with length L 10 km, longitudinal dispersivity
aL 1000 m and velocity v 0.3 m/day. In the numerical model,
the inlet boundary is set to constant unit concentration, the outlet

Fig. 5. Relative error between model predictions and analytical solution.

G. Kourakos, T. Harter / Environmental Modelling & Software 52 (2014) 207e221


5.2. Large scale application

Fig. 7. Comparison of the conductance matrices, forcing vectors, and solution vectors
obtained from COMSOL and mSim.

boundary is dened by a zero concentration gradient, and the

initial condition is set to zero.
The diffusion matrix, forcing matrix and the mass matrix are
identical for mSim and Comsol. Fig. 8aec shows the resulting
concentration along the 1D domain for 200 years. The discrepancy
between the two numerical solutions (mSim and Comsol) is
negligible. The relative difference between analytical and numerical solutions from both numerical codes (mSim and COMSOL) is
generally well below 1%, with highest relative error at the outlet
(up to 10%) due to the nite size of the numerical domain, consistent with other studies (Yeh et al., 1993). Relative error is also
higher at early times immediately in front of the solute plume
where absolute concentrations are near zero.

The motivation for the development of the mSim is the simulation of regional non-point source pollution. In this section we
illustrate an application of mSim to simulate 200 years of nitrate
contaminant transport in the Tule River aquifer, which is located in
the southern Central Valley, California, US. The Tule River basin
covers 2000 km2. It is an intensively farmed agricultural area that
relies heavily on groundwater for domestic and irrigation purposes.
Fig. 9 illustrates the outline of the simulated domain. The area is
divided into approximately 9000 land use polygons that belong to
nearly 60 different land use categories. Groundwater recharge and
groundwater pumping is polygon specic (Ruud et al., 2004).
Known pumping is distributed across 1920 virtual wells (Boyle
et al., 2012), which represent mostly irrigation wells and some
municipal supply wells, and w150 line segments that correspond
to recharging (losing) streams here considered to be free of pollution. This setting creates a highly complicated domain, which is
very challenging for mesh generation. The mSim functions were
used to prepare the input les for the mesh generation using Gmsh.
First we created a 2D triangular mesh, which consists of 309,258
triangles with edge length that varies between 50 m near the wells
and 500 m, in void of interest areas (e.g. see southwest area in
Figs. 9 and 10), which is mostly native vegetation. Although Gmsh
was instructed to generate a constrained mesh, due to complexity
of the land use surface, it was found that Gmsh sometimes failed to
follow the constraints at the benet of generating a better quality
mesh (e.g. mesh with triangles without acute angles). The mesh
was subsequently extruded in the vertical direction to formulate 11
layers of vertical prism elements (Fig. 10) e.g. (3,401,838 prism elements and 1,861,560 degrees of freedom). The hydraulic conductivity was estimated based on a previous study that employed a
pilot point optimization method and varies between 1 and 150 m/

Fig. 8. Concentration over time, along the 1D domain. (a) and (b) show the concentration distribution based on mSim and Comsol simulation. (c) shows the analytical solution and
the (d) the relative to maximum concentration error between numerical and analytical simulation.


G. Kourakos, T. Harter / Environmental Modelling & Software 52 (2014) 207e221

Fig. 9. Domain and land use cover of Tule river basin, California (modied from Ruud et al. (2004)).

day with median and mean equal to 5 m/day and 24 m/day

respectively (Larry Walker and Associates, 2010). In addition, there
is a conning layer known as Corcoran Clay member that extends
eastward from the western edge of the basin for about 20 km. To
account for the conning layer the mesh elevation was adapted in
the area above and below the Corcoran Clay layer so that the bottom of the 5th layer and the top of the 9th layer follow the elevation
of Corcoran Clay conning unit (see Fig. 10 the area inside the red

The total amount of diffuse groundwater recharge estimated

by Ruud et al. (2004) is approximately 6.4  105 m3/day, and the
estimated groundwater recharge from streams is 3.6  105 m3/
day. Therefore 36% of the total recharge occurs from streams and
64% is diffuse recharge. There are also 1920 virtual wells with a
mean and median pumping rate of 526 m3/day and 300 m3/day,
The upper portion of the Tule river basin is an unconned
aquifer. To simulate the water table elevation with an adaptive

Fig. 10. Left: Top view of nite element discretization. Right Top: Zoom to the green rectangle. Right bottom: cross section of the nite element mesh. The red rectangle shows the
area where the mesh was adapted to honor the Corcoran Clay member. (For interpretation of the references to colour in this gure legend, the reader is referred to the web version
of this article.)

G. Kourakos, T. Harter / Environmental Modelling & Software 52 (2014) 207e221

Fig. 11. Distribution of hydraulic head of the top layer. Due to iterative solution the
elevation of the top nodes is equal to their hydraulic head. Note that the lighting source
is from the north-northeast. Recharging rivers show as (elevated) ridges, while
pumping center show as cones of depression.

mesh, we utilize an iterative solution scheme to match the top

node elevation with the nal hydraulic head. A total of four iterations are adequate for the unconned problem to converge.
During each iteration, the mesh elevation is modied to match
the previous head solution, then the conductance matrix is
reassembled. Here we choose to update the entire matrix,
because the elevations of all layers are modied as a function of
the elevations of the top layer. The ux vector is assembled only
once and remains constant during the iterations. The assembly
time for the 3.4  106 element model was approximately 94 s.
The time to solve the system with 1.8  106 dofs was approximately 8 min on a Xeon 2.27 GHz, with 24 GB RAM. This time
corresponds to default Matlab solver (e.g. slash \ operator, where
Matlab identies the most appropriate solver based on the
properties of the matrix). However we found that pyAMG (Bell
et al., 2011) was signicantly faster. Fig. 11 shows the head distribution of the top layer, which also correspond to the elevation
of the top layer nodes. Note that the streams with relatively high
recharge rates appear slightly extruded as a result of the iterative
scheme for the solution of the nonlinear unconned problem.


Note also that the mesh created noticeable cones of depression

around the wells with relatively large pumping rates.
Next we apply the streamline transport model based on the ow
eld computed in the previous step. At each well, 100 particle
endpoints are uniformly distributed around the well screen. Backward particle tracking is employed until streamlines exit from the
ow eld at the point of recharge. Because the aquifer is surrounded by no ow boundary conditions, all particles originate
from the water table. Based on the sediment analysis by Faunt
(2009), porosity values were estimated to be between
f 0:07  0:15. In streamline modeling, the porosity becomes a
very important scaling factor (Kourakos et al., 2012; Starn et al.,
2013). As sensitivity analysis, the transport model was implemented for two cases, f 0:07 and f 0:15. The particle travel
time scales linearly with the porosity. Fig. 12 shows the full histogram of the particles age. Note that the x axis represents the logarithm of the travel time, therefore the age distribution in the
aquifer is approximately log-normal distributed. In both cases, the
particles travel time spans from less than a year to tens of thousands years. In general, very old water is extracted from wells
which are located in areas with relatively low recharge rate and
from deep parts of well screens. For example, wells that are located
in the western-most and southeastern part of the study area extract
very old water that originates either from streams or from remote
high recharge areas.
Streamline age patterns (Fig. 13) follow the recharge pattern
across the simulation domain. The northern part of the aquifer has
the youngest water as it receives most of the stream recharge. The
central and southern part of the aquifer, which consists of vineyards
and other crops receives primarily water from diffuse recharge.
Next, for each streamline we solved the 1D advection dispersion
equation assuming a Heaviside unit loading function at the water
table and a free advective ux (zero concentration gradient)
boundary at the well side. In the current implementation of the
streamline transport simulation, the transverse dispersivity is
neglected. The longitudinal dispersivity was set equal to
aL 0:32$L0:83 (Neuman, 1990), which denes the dispersivity
coefcient to be approximately equal to 10% of the streamline
length. For each well, each particles x, y, z position is different.
Depending on well depth and screen length, streamline length and
travel time across the well screen may vary within a narrow range
(shallow wells with short screens lengths) or have a very broad
range (deep wells with long screens). The response for shallow
wells is signicantly faster compared to the response for deep
wells. At the same time the peak concentrations for deep wells are
much lower compared to shallower wells (Fig. 14). Results are
highly sensitive to the porosity chosen (Fig. 14).

Fig. 12. Histogram of the particles travel time into the groundwater aquifer for each case. The green line corresponds to median travel time. (For interpretation of the references to
colour in this gure legend, the reader is referred to the web version of this article.)


G. Kourakos, T. Harter / Environmental Modelling & Software 52 (2014) 207e221

Fig. 13. Simulated streamlines. Blue to red colors correspond to logarithmic travel time
from the point of recharge onward. The gray anaglyph background corresponds to the
bottom of the aquifer. (For interpretation of the references to colour in this gure
legend, the reader is referred to the web version of this article.)

We also compute the age distribution of water age that enters a

well (Woolfenden and Ginn, 2009). In shallower wells with shorter
screen, pumped water is a mix of relatively young water (20e40
years) and some older water (more than 100 years). In deep wells,
water age along the intake screen ranges from 100 to 1000 years.
The nal phase of the NPSAT implementation involves convolution of the unit response functions with the actual pollutant
loading functions. Here, we illustrate the outcome of the nal phase
by convoluting the unit response functions with uniform continuous loading equal to 50 kg/ha/year. Note that this number represents the loading mass distributed across the entire surface of the
aquifer. During the convolution the mass is converted to

concentration by dividing the mass with the recharge that corresponds to the streamline point at the recharge boundary. Therefore,
although we assumed uniform loading, the actual concentration
will be variable as a function of the recharge rate. We assumed zero
loading for streamlines that originate from streams. The implementation phase involves convolution of the loading functions with
each unit response function. Hence for each well we obtain 100
breakthrough curves, where each corresponds to a different
streamline. Note that by using URFs we are able to quickly recalculate the concentration for alternative, time-varying source
loading, without again solving the entire 1D ADE problem. To
obtain the actual mixed well breakthrough curve, we calculate the
weighted average of the individual streamline breakthrough
curves. Weights reect the relative ow contribution of each
streamline to the total pumped water volume at a well.
In Fig. 15, each thin colored line corresponds to an individual,
aggregated well breakthrough curve (e.g. each plots consist of 1920
breakthrough curves), which form the basis for statistical analyses
of regional, subregional, or land use-specic impacts. Statistical
processing also allows for quantication of uncertainty or prediction reliability.
Based on well breakthrough curves we computed exceedance
probabilities for the study area for the two porosity scenarios that
were considered previously with f 0:07 and f 0:15 (shown
with yellow thick lines in Fig. 15). With 50 kg/ha/year uniform nitrate loading, it appears that 10% of the wells will exceed the
drinking water limit (10 mg NO3eN/L, shown in thick green line)
after a period of approximately 4 (Fig. 15 Left) to 8 (Fig. 15 Right)
years. One quarter of the wells in the study area are expected to
exceed the drinking water limit after 15e30 years. Approximately
half of the wells will exceed the drinking water limit after 110 years
if f 0:07 and after more than 200 years at 15% porosity.
It becomes apparent from the above analysis that prediction
uncertainty driven by imprecise porosity estimates increases
signicantly at higher design exceedance thresholds. For example
the uncertainty in estimating the exceedance probability for the
most immediately impacted 5% of wells is in the order of few years.
On the other hand the uncertainty in estimating the time at which

Fig. 14. Bottom panels: Unit response functions for an average and deep well and different values of porosity. Top panels: Age distribution for the same wells.

G. Kourakos, T. Harter / Environmental Modelling & Software 52 (2014) 207e221


Fig. 15. Left: Exceedance probability for f 0:07. Right: Exceedance probability for f 0:15. The thin colored lines correspond to individual well BTCs. The yellow lines
correspond to calculated exceedance probability based on the individual BTCs (MCL: Maximum Contaminant Level). (For interpretation of the references to colour in this gure
legend, the reader is referred to the web version of this article.)

40% of the wells exceed the drinking water threshold is in the order
of several decades. These uncertainties also depend on the exceedance threshold (here: drinking water limit) chosen, relative to
the source loading. The uncertainty increases exponentially as the
well exceedance concentration increase (Fig. 16).
6. Conclusions
In this paper we present an efcient numerical code for the
simulation of non-point source contamination based on concepts
proposed in our earlier work (Kourakos et al., 2012), but extendable
to more general groundwater ow and transport simulation problems using the nite element method.
The code is written exclusively in Matlab and is available for free
download from The equations that mSim solves in the present version are steady state
groundwater ow, particle tracking, and 1D transient advection
dispersion with up to rst order degradation and decay. mSim is
based on the nite element method using Galerkin approximation
of the partial differential equations. mSim relies on Gmsh code for
the mesh generation, and on ParaView for large scale post-processing and visualization. Note that both codes are open source and

The code is implemented in a highly vectorized manner which

allows it to be used for large scale applications. Currently the system of linear equations is solved using the Matlab solvers (i.e.
backslash operator). Several verication problems are implemented and we illustrate the potential application of mSim with a
model that estimates long-term nitrate contamination in the
southern Central valley, California. The simulated model was discretized into a grid representing 1.8 millions degrees of freedom
and was solved on a Xeon 2.27 GHz, with 24 GB RAM. Although the
example is based on hypothetical loading we draw important
conclusions regarding the uncertainty effect of porosity. For
example by comparing two porosity scenarios with 4 0:07 and
4 0:15 we found w100 years difference in the estimation of the
median travel time in the aquifer. The uncertainty due to porosity
has also signicant impact on predictions. We found that the uncertainty is less signicant for predicting concentration at wells
impacted early. Furthermore, prediction uncertainty due to unknown effective porosity increases exponentially as the exceedance
probability of interest increases. The uncertainty about the duration
until a threshold concentration is exceeded also increases as the
threshold of interest becomes higher. In this paper we used uniform loading, and future work will examine the effects of actual
loading scenarios.
mSim in its current version is potentially the starting point for
adding other capabilities. Future work will involve the intergration
of domain decomposition methods and algebraic multigrid solvers
in order to overcome the limitations imposed by the default matlab
solvers. We are also working on parallel assembly options.
We gratefully acknowledge the constructive comments provided by six anonymous reviewers. Their thorough analysis
allowed us to provide a much improved manuscript. Funding for
this project was provided through the CA State Water Resources
Control Board under agreements 04-184-555-3 and 09-122-250.

Fig. 16. Uncertainty in exceedance probability as a function of the uncertainty of


Al-Mahallawi, K., Mania, J., Hani, A., Shahrour, I., 2012. Using of neural networks for
the prediction of nitrate groundwater contamination in rural and agricultural
areas. Environ. Earth Sci. 2012 (65), 917e928.
Aller, L., Bennett, T., Lehr, J.H., Petty, R.J., Hackett, G., 1987. DRASTIC: a Standardized
System for Evaluating Groundwater Pollution Potential Using Hydrogeologic
Settings. Rep. EPA-600/2-87-035. U.S. Environ. Prot. Agency, Ada, Okla, p. 641.


G. Kourakos, T. Harter / Environmental Modelling & Software 52 (2014) 207e221

Andreassen, E., Clausen, A., Schevenels, M., Lazarov, B.S., Sigmund, O., 2011. Efcient
topology optimization in MATLAB using 88 lines of code. Struct. Multidiscip.
Optim. 43, 1e16.
Ashby, S.F., Falgout, R.D., 1996. A parallel multigrid preconditioned conjugate
gradient algorithm for groundwater ow simulations. Nucl. Sci. Eng. 124 (1),
Aslam, A., Hendren, L., 2012. McFLAT: a prole-based framework for MATLAB loop
analysis and transformations, languages and compilers for parallel computing.
In: 23rd International Workshop, LCPC 2010, vol. 6548, pp. 1e15. Revised
Selected Papers.
Bell, W.N., Olson, L.N., Schroder, J.B., 2011. PyAMG: Algebraic Multigrid Solvers in
Python v2.0.
Bennett, N.D., Croke, B.F.W., Guariso, G., Guillaume, J.H.A., Hamilton, S.H.,
Jakeman, A.J., Marsili-Libelli, S., Newham, L.T.H., Norton, J.P., Perrin, C.,
Pierce, S.A., Robson, B., Seppelt, R., Voinov, A.A., Fath, B.D., Andreassian, V., 2013.
Characterising performance of environmental models. Environ. Model. Softw.
40, 1e20.
Bobba, A.G., 2012. Ground Water-Surface Water Interface (GWSWI) modeling:
recent advances and future challenges. Water Resour. Manag. 26 (14), 4105e
Boyle, D., King, A., Kourakos, G., Lockhart, K., Mayzelle, M., Fogg, G.E., Harter, T.,
2012. Groundwater nitrate occurrence. Technical Report 4. In: Addressing Nitrate in Californias Drinking Water with a Focus on Tulare Lake Basin and
Salinas Valley Groundwater. Center for Watershed Sciences, University of California, Davis. Report for the State Water Resources Control Board Report to the
Butcher, J.C., 2008. Numerical Methods for Ordinary Differential Equations. second
ed. J. Wiley, Chichester.
Chaves, J.C., Nehrbass, Guilfoos, J.B., Gardiner, J., Ahalt, Krishnamurthy, S.A.,
Unpingco, J., Chalker, A., Warnock, A., Samsi, S., 2006. Octave and python: highlevel scripting languages productivity and performance evaluation. In: HPCMP
Users Group Conference, pp. 429e434.
Chen, C.-K., Yan, S., Yu, H., Max, N., Ma, K.-L., 2011. An Illustrative visualization
framework for 3D vector elds. Comput. Graph. Forum 30 (7), 1941e1951.
COMSOL Multiphysics, 2008. COMSOL Multiphysics Modeling Guide: Version 3.5.
COMSOL AB, Stockholm, Sweden.
Cordes, C., Kinzelbach, W., 1992. Continuous groundwater velocity elds and path
lines in linear, bilinear, and trilinear nite elements. Water Resour. Res. 28 (11),
Dedner, A., Klfkorn, R., Nolte, M., Ohlberger, M., 2011. A generic interface for
parallel and adaptive scientic computing: abstraction principles and the
DUNE-FEM module. Computing 90 (3), 165e196.
Donea, J., Huerta, A., 2003. Finite Element Methods for Flow Problems. John Wiley &
Sons Ltd., West Sussex, UK.
Eberts, S.M., Bhlke, J.K., Kauffman, L.J., Jurgens, B.C., 2012. Comparison of particletracking and lumped-parameter age-distribution models for evaluating
vulnerability of production wells to contamination. Hydrogeol. J. 20 (2), 263e
Fairweather, G., 1978. Finite Element Galerkin Methods for Differential Equations.
In: Lecture Notes in Pure and Applied Mathematics, vol. 34. CRC Press, New
York, p. 263.
Faunt, C.C. (Ed.), 2009. Groundwater Availability of the Central Valley Aquifer,
California. U.S.Geological Survey Professional Paper 1766, p. 225.
Fish, J., Belytschko, T., 2007. A First Course in Finite Elements. John Wilay & Sons
Ltd, NJ.
Fogg, G.E., Labolle, E.M., Weissmann, G.S., 1999. Groundwater vulnerability assessment: hydrogeologic perspective and example from Salinas Valley, California.
In: Corwin, D.L., Loague, K., Elisworth, T.R. (Eds.), Assessment of Non-Point
Source Pollution in the Vadose Zone, pp. 45e61.
Funken, S., Praetorius, D., Wissgott, P., 2011. Efcient implementation of adaptive
P1-FEM in matlab. Comput. Methods Appl. Math. 11 (4), 460e490. http://
Gallardo, A.H., Reyes-Borja, W., Tase, N., 2005. Flow and patterns of nitrate pollution
in groundwater: a case study of an agricultural area in Tsukuba City, Japan.
Environ. Geol. 48, 908e919.
Geuzaine, C., Remacle, J.-F., 2009. Gmsh: a three-dimensional nite element mesh
generator with built-in pre- and post-processing facilities. Int. J. Numer. Meth.
Eng. 79 (11), 1309e1331.
Green, C.G., Bhlke, J.K., Bekins, B.A., Phillips, S.P., 2010. Mixing effects on apparent
reaction rates and isotope fractionation during denitrication in a heterogeneous aquifer. Water Resour. Res. 46 (8), W08525.
Harbaugh, A.W., Banta, E.R., Hill, M.C., McDonald, M.G., 2000. MODFLOW-2000, the
U.S. Geological Survey Modular Ground-water ModeldUser Guide to Modularization Concepts and the Ground-water Flow Process. Open-File Report 00e92.
U.S. Geological Survey, p. 121.
Heroux, M., Bartlett, R., Howle, V., Hoekstra, R., Hu, J., Kolda, T., Lehoucq, R., Long, K.,
Pawlowski, R., Phipps, E., Salinger, A., Thornquist, H., Tuminaro, R.,
Willenbring, J., Williams, A., 2003. An Overview of Trilinos. Sandia National
Laboratories. SAND2003e2927.
Higham, D.J., 2002. Nine ways to implement the binomial method for option
valuation in MATLAB. SIAM Rev. 44 (4), 661e677.

HYPRE, 2012. Users Manual. Center for Applied Scientic Computing, Lawrence
Livermore National Laboratory.
Integrated Water Flow Model, 2012. Theoretical Documentation. Integrated Hydrological Models Development Unit, Modeling Support Branch, Bay-Delta Ofce, Department of Water Resources, Bay-Delta.
Istok, J.D., 1989. Groundwater Modeling by the Finite Element Method. In: Water
Resources Monograph, vol. 13. AGU, Washington, DC.
Jiang, Y., Somers, G., 2009. Modeling effects of nitrate from non-point sources on
groundwater quality in an agricultural watershed in Prince Edward Island,
Canada. Hydrogeol. J. 17 (3), 707e724.
Kattan, P.I., 2008. MATLAB Guide to Finite Elements, an Interactive Approach.
Springer, Berlin Heidelberg.
Kepner, J., 2009. In: Dongarra, J.J. (Ed.), Parallel MATLAB for Multicore and Multinode Computers. Society for Industrial and Applied Mathematics.
Koko, J., 2007. Vectorized Matlab codes for linear two-dimensional elasticity. Sci.
Program. 15, 157e172.
Kourakos, G., Mantoglou, A., 2008. Remediation of heterogeneous aquifers based
on multiobjective optimization and adaptive determination of critical realizations. Water Resour. Res. 44, W12408.
Kourakos, G., Mantoglou, A., 2012a. Inverse groundwater modeling with emphasis
on model parameterization. Water Resour. Res. 48, W05540.
Kourakos, G., Mantoglou, A., 2012b. Development of a multi-objective optimization
algorithm using surrogate models for coastal aquifer management. J. Hydrol.
479, 13e23.
Kourakos, G., Klein, F., Harter, T., 2011. A GIS-linked unit response function approach
to stochastic groundwater nonpoint source pollution modelling. In: Proceedings of ModelCARE 2011 Models-repositories of Knowledge, vol. 355. IAHS
Publ., pp. 106e112, 2012.
Kourakos, G., Klein, F., Cortis, A., Harter, T., 2012. A groundwater nonpoint source
pollution modeling framework to evaluate long-term dynamics of pollutant
exceedance probabilities in wells and other discharge locations. Water Resour.
Res. 48, W00L13.
Kumar, R.P., Dodagoudar, G.R., 2010. Two-dimensional meshfree modelling of
contaminant transport through saturated porous media using RPIM. Environ.
Earth Sci. 61 (2), 341e353.
Larry Walker and Associates, February 2010. Salt and Nitrate Sources Pilot Implementation Study Report. Final Report to the Central Valley Salinity Coalition
(CV-SALTS), p. 247.
Lee, H.S., Matthews, C.J., Braddock, R.D., Sander, G.C., Gandola, F., 2004. A MATLAB
method of lines template for transport equations. Environ. Modell. Softw. 19 (6),
Lie, K.eA., Krogstad, S., Ligaarden, I.S., Natvig, J.R., Nilsen, H.M., Skaestad, B., 2012.
Open-source MATLAB implementation of consistent discretisations on complex
grids. Comput. Geosci. 16 (2), 297e322.
Lin, H.-C.J., Richards, D.R., Talbot, C.A., Yeh, G.-T., Cheng, J.-R., Cheng, H.-P.,
Jones, N.L., 1997. A Three-dimensional Finite Element Computer Model for
Simulating Density-dependent Flow and Transport in Variable Saturated Media:
Version 3.0. U.S Army Engineer Research and Development Center, Vicksburg,
Louwyck, A., Vandenbohede, A., Bakker, M., Lebbe, L., 2012. Simulation of axisymmetric ow towards wells: a nite-difference approach. Comput. Geosci.
44, 136e145.
McMahon, P.B., Burow, K.R., Kauffman, L.J., Eberts, S.M., Bhlke, J.K., Gurdak, J.J.,
2008. Simulated response of water quality in public supply wells to land use
change. Water Resour. Res. 44, W00A06.
Moriasi, D.N., Wilson, B.N., Douglas-Mankin, K.R., Arnold, J.G., Gowda, P.H., 2012.
Hydrologic and water quality models: use, calibration, and validation. T ASABE
55 (4), 1241e1247.
Morio, M., Finkel, M., Martac, E., 2010. Flow guided interpolation e a GIS-based
method to represent contaminant concentration distributions in groundwater. Environ. Model. Softw. 25 (12), 1769e1780.
Moutsopoulos, K.N., Gemitzi, A., Tsihrintzis, V.A., 2008. Delineation of groundwater
protection zones by the backward particle tracking method: theoretical background and GIS-based stochastic analysis. Environ. Geol. 54, 1081e1090. http://
National Research Council, 1993. Groundwater Vulnerability Assessment: Predicting
Relative Contamination Potential Under Conditions of Uncertainty. National
Academy Press, Washington, D. C, p. 204.
Neuman, S.P., 1990. Universal scaling of hydraulic conductivities and dispersivities
in geologic media. Water Resour. Res. 26 (8), 1749e1758.
Nolan, B., Hitt, K.J., 2006. Vulnerability of shallow groundwater and drinkingwater wells to nitrate in the United States. Environ. Sci. Technol. 40 (24),
Ogata, A., Banks, R.B., 1961. A Solution of the Differential Equation of Longitudinal
Dispersion in Porous Media. In: US Geological Survey Professional Papers, No.
34, p. 411-A.
OpenFoam, 2013. The Open Source CFD Tool: User Guide. VErsion 2.2.1. OpenFoam

G. Kourakos, T. Harter / Environmental Modelling & Software 52 (2014) 207e221

Pepper, D.W., Heinrich, J.C., 2006. The Finite Element Method: Basic Concepts and
Applications. Taylor & Francis Group, FL.
Perianez, R., 2005. GISPART: a numerical model to simulate the dispersion of
contaminants in the Strait of Gibraltar. Environ. Model. Softw. 20 (6), 797e802.
Persson, P.O., Strang, G., 2004. A simple mesh generator in MATLAB. SIAM Rev. 46
(2), 329e345.
Refsgaard, J.C., Henriksen, H.J., 2004. Modelling guidelines - terminology and
guiding principles. Adv. Water Resour. 27 (1), 71e82.
Ruud, N.C., Harter, T., Naugle, A.W., 2004. Estimation of groundwater pumping as
closure to the water balance of a semi-arid irrigated agricultural basin. J. Hydrol.
297, 51e73.
Starn, J.J., Bagtzoglou, A.C., Robbins, G.A., 2012. Methods for simulating solute
breakthrough curves in pumping groundwater wells. Comput. Geosci. 48, 244e
Starn, J.J., Bagtzoglou, A.C., Robbins, G.A., 2013. Uncertainty in simulated groundwater quality trends in transient ow. Hydrogeol. J. 21 (4), 813e827.
Talischi, C., Paulino, G.H., Pereira, A., Menezes, I.F.M., 2012. PolyMesher: a generalpurpose mesh generator for polygonal elements written in Matlab. Struct.
Multidiscip. Optim. 45 (3), 309e328.
Teza, G., Marcato, G., Castelli, E., Galgaro, A., 2012. IRTROCK: a MATLAB toolbox for
contactless recognition of surface and shallow weakness of a rock cliff by


infrared thermography. Comput. Geosci. 45, 109e118.

Therrien, R., McLaren, R.G., Sudicky, E.A., 2007. HydroGeoSphereda Three-dimensional
Numerical Model Describing Fully Integrated Subsurface and Surface Flow and
Solute Transport. Groundwater Simulations Group, University of Waterloo.
Trefry, M.G., Muffels, C., 2007. Feow: a nite-element ground water ow and
transport modeling tool. Ground Water 45 (5), 525e528.
Tych, W., Young, P.C., 2012. A Matlab software framework for dynamic model
emulation. Environ. Model. Softw. 34, 19e29.
Voss, C.I., 1984. A Finite Element Simulation Model for Saturated-unsaturated,
Fluid Density-dependent Groundwater Flow with Energy Transport or
Chemically Reactive Single-species Solute Transport. US Geological Survey,
pp. 84e4369.
Winston, R.B., 2009. ModelMuse-A Graphical User Interface for MODFLOW-2005
and PHAST. In: U.S. Geological Survey Techniques and Methods 6eA29, p. 52.
Woolfenden, L.R., Ginn, T.R., 2009. Modeled ground water age distributions. Ground
Water 47, 547e557.
Yeh, T.C.J., Srivastava, R., Guzman, A., Harter, T., 1993. A numerical model for water
ow and chemical transport in variably saturated porous media. Groundwater
31 (4), 634e644.

J., van Genuchten, M.Th., Sejna,
M., 2012. Hydrus: model use, calibration,
and validation. T ASABE 55 (4), 1261e1274.