Modflow API
Modflow API
A R T I C L E I N F O A B S T R A C T
Keywords: The MODFLOW API allows other programs to control MODFLOW and interactively change variables without
MODFLOW 6 having to modify the source code. The MODFLOW API is based on the Basic Model Interface (BMI), which is a set
MODFLOW API of conventions that define how to initialize a simulation, update the model state by advancing in time, and
Basic model interface
finalize the run. For many existing MODFLOW coupling applications, the information provided to MODFLOW
MetaSWAP
PRMS
must be updated multiple times in a time step. As this capability to modify variables within a time step is not
MODSIM defined by the BMI, an extension to BMI was developed. This eXtended Model Interface is part of the MODFLOW
API and allows such a tight coupling to other models. Examples are included for a variety of use cases, including
new flexibility for users to develop custom packages without modifying the MODFLOW source code and coupling
MODFLOW with other models and optimization libraries.
1. Introduction including MOC3D (Winston et al., 2018) and MT3D (Langevin et al.,
2008). Optimization routines have been coupled with MODFLOW to
For over 30 years, the MODFLOW program has been widely used by maximize groundwater extraction subject to various constraints (Ahlfeld
academics, private consultants, and government scientists to accurately, et al., 2005) and to identify optimum surface water deliveries in order to
reliably, and efficiently simulate groundwater flow and related pro meet water demands (Morway et al., 2016). MODFLOW has been
cesses. Due to its widespread popularity, modular structure, and thor extended to include pipe flow models to represent karst conditions
ough documentation, MODFLOW has been successfully coupled with (Shoemaker et al., 2008) and flow in the unsaturated zone (Twarakavi
many other physical process models and programs. For example, et al., 2008). MODFLOW has also been coupled to hydrodynamic
MODFLOW has been coupled with watershed models, including PRMS surface-water models, including HEC-RAS (Rodriguez et al., 2008),
(Markstrom et al., 2008), SWAT (Kim et al., 2008), and HSPF (Davis, SWIFT2D (Wang et al., 2007), and BRANCH (Swain and Wexler, 1996).
2001). MODFLOW has been combined with solute transport models, The majority of previous coupling approaches used with MODFLOW
Abbreviations: API, Application Programming Interface; BMI, Basic Model Interface; CCA, Common Component Architecture; CSDMS, Community Surface Dy
namics Modeling System; ESMF, Earth System Modeling Framework; EVT, Evapotranspiration; GWF, Groundwater Flow; GWT, Groundwater Transport; HRU,
Hydrologic Response Unit; OpenMI, Open Modeling Interface; PRMS, Precipitation-Runoff Modeling System; SFR, Streamflow Routing; UZF, Unsaturated Zone Flow;
XMI, eXtended Model Interface.
* Corresponding author.
E-mail addresses: jdhughes@[Link] (J.D. Hughes), [Link]@[Link] (M.J. Russcher), langevin@[Link] (C.D. Langevin), emorway@[Link]
(E.D. Morway), rmcd@[Link] (R.R. McDonald).
1
[Link]
2
[Link]
3
[Link]
4
[Link]
[Link]
Received 28 May 2021; Received in revised form 22 September 2021; Accepted 16 November 2021
Available online 30 November 2021
1364-8152/Published by Elsevier Ltd. This is an open access article under the CC BY license ([Link]
J.D. Hughes et al. Environmental Modelling and Software 148 (2022) 105257
have been to combine the codes into a single program. This additional functionality was required to allow for a tighter coupling with
single-program coupling approach has often led to coupled programs other process models than is possible with the standard BMI functions.
that could not keep up with advances of the individual codes. As a result, Specifically, there was a need to allow other components to be coupled
many of these custom MODFLOW-variants have become stale over time with MODFLOW within the non-linear Picard iteration loop (see, for
and do not support recent MODFLOW advances or advances to the other example, Ferziger and Peric (1996) for a treatment of this type of
process model. coupling and the Picard iteration). For example, GSFLOW (Markstrom
Efforts to couple MODFLOW with other process models requires et al., 2008) is a coupled version of MODFLOW and PRMS (Markstrom
extensive knowledge of both models, an understanding of the types of et al., 2015). A key feature of GSFLOW is the tight coupling of the PRMS
information needed for the coupling, performance objectives, and a soil zone and overland flow components with the MODFLOW ground
clear purpose for the resulting coupled MODFLOW program. These water flow component. It is implemented in GSFLOW by allowing the
broader model integration issues are described by Belete et al. (2017) in soil zone component to be calculated as part of the MODFLOW Picard
a comprehensive overview. The overview outlines phases of the model iteration until convergence is achieved. In the MODFLOW API, the BMI
integration effort, summarizes capabilities of existing frameworks for was extended to support this same type of tight component coupling that
coupling models, and describes the challenges of designing a generalized was used in GSFLOW, but in a generic way that allows other models to
integration framework. Overcoming these challenges can allow for new be solved simultaneously with MODFLOW.
and innovative ways for coupling models, including sharing models and The purpose of this paper is to describe the new MODFLOW API,
data over the web (Chen et al., 2020). which is implemented in MODFLOW6 (subsequent MODFLOW refer
MODFLOW6 is the most recent version of MODFLOW and is ences in this paper refer specifically to the MODFLOW6 version).
currently the core version of MODFLOW distributed and released by the Although the focus of the paper is on coupling MODFLOW with other
U.S. Geological Survey. MODFLOW6 is an object-oriented program and process models, the API is general and will allow MODFLOW to be called
framework written in Fortran. The MODFLOW6 software provides a by a wide variety of software programs, such as by plotting programs or
platform for supporting multiple models and multiple types of models Geographical Information Systems, for example. The paper first shows
within the same simulation (Langevin et al., 2017; Hughes et al., 2017). how the BMI was implemented in MODFLOW, including an explanation
These models can be independent of one another with no interaction, of how a MODFLOW simulation can be controlled by an external pro
they can exchange information, or they can be tightly coupled at the gram written in another language (e.g., Python, C#, etc.) using model
matrix level by adding them to the same numerical solution. Transfer of control and time functions and the way MODFLOW variables can be
information between models is isolated to exchange objects, which accessed during the simulation. The paper then describes extensions to
contain the data and code needed to couple models. This design feature the BMI that allow MODFLOW to be tightly coupled with other process
allow models to be developed, maintained, and used independently models. Finally, five examples are presented to demonstrate a variety of
without having custom information about other models in the frame uses for the MODFLOW API, including new flexibility for users to
work. Within this new framework, a regional-scale groundwater model develop custom packages without modifying the MODFLOW source
may be coupled with multiple local-scale groundwater models, or a code and coupling MODFLOW with other process models and optimi
groundwater transport model may be coupled with a groundwater flow zation libraries.
model (Langevin et al., 2020).
MODFLOW6 currently includes the Groundwater Flow (GWF) Model 2. Development of the MODFLOW API
and the Groundwater Transport (GWT) Model each with packages to
represent surface water processes, groundwater extraction, external Development of the MODFLOW API required refactoring the source
boundaries, mass sources and sinks, and mass sorption and reactions. code into the core component. This core component can be compiled
Morway et al. (2021) show how the advanced packages in MODFLOW 6 into an executable program (Fig. 1), which is provided as part of the
can be connected to represent watershed processes in managed basins. standard distribution released by the U.S. Geological Survey. The core
MODFLOW6 also includes advanced capabilities to simulate component can also be compiled with the API routines into a shared
three-dimensional anisotropy and dispersion and correct grid errors for library that can be used for interoperable applications. The refactoring
cell connections that violate generalized control-volume finite- effort focused on ensuring that the routines and calls for the executable
difference assumptions (Panday et al., 2013; Provost et al., 2017). corresponded exactly to calls made to the shared library through the API
To facilitate coupling with other models, including those written in and that none of the routines were duplicated. Extensive testing was
another language, an Application Programming Interface (API) was performed and continues to be performed through continuous integra
developed for MODFLOW. The API was developed using the established tion practices to ensure that the executable and library versions give
Basic Model Interface (BMI) standard. The BMI was developed by identical numerical results and have equivalent run times with multiple
Community Surface Dynamics Modeling System (CSDMS) to provide a compilers on the supported operating systems: Windows, Linux, and
standard component-based interface for Earth-science models (Peckham macOS.
et al., 2013). The Common Component Architecture (CCA; Armstrong As shown in Fig. 1 the API layer builds on the MODFLOW core.
et al., 1999), the Earth System Modeling Framework (ESMF; Collins MODFLOW is considered to be either the executable version or the
et al., 2005), and the Open Modeling Interface (OpenMI; Gregersen shared library version as the latter can be initiated and run in a manner
et al., 2007) are examples of other coupling standards. The BMI standard that gives the same results as the executable. Fig. 1 shows three different
was selected for the MODFLOW API because it was developed specif implementations of an interoperable layer that sits between the MOD
ically for Earth-science models, and it was clear how the BMI could be FLOW API and applications based on it. An interoperable layer, such as
used to couple MODFLOW with the types of process models needed by the modflowapi Python package, makes it easier to control MODFLOW
the community. Some example applications of the BMI with and transfer information. The purpose of this section is to describe the
Earth-science models include the coupling of 1) a river sediment trans API layer shown in Fig. 1 including both the BMI and the eXtended
port model to a delta model that distributes the sediment (Ratliff et al., Model Interface (XMI). The subsequent section contains examples on
2018) and 2) a hydrologic model to a hydrodynamic model to improve how to use the MODFLOW API in practice.
flood inundation simulations (Hoch et al., 2019). Since its initial release, As shown in Fig. 1 the API layer builds on the MODFLOW core. It
development of the BMI has continued and updates have included currently contains the eXtended Model Interface (XMI), which is the
functions for accessing variable metadata and for working with struc Basic Model Interface (BMI) and the extensions described below, plus
tured and unstructured grids (Hutton et al., 2020). supporting functionality. However, it is expected that it will continue to
Although the BMI provides the foundation for the MODFLOW API, grow, exposing more internal MODFLOW functionality for use in other
2
J.D. Hughes et al. Environmental Modelling and Software 148 (2022) 105257
realize that its value is not updated until the internal time update (TU) is
called. The current time-step length can be queried with a call to
get_time_step.
The other part of the BMI implementation is its ability to access in
ternal model component data. Nearly all array and scalar variables in
MODFLOW are declared as Fortran pointers (Metcalf et al., 2018) and
managed by a dedicated module called the Memory Manager, which
allocates variables and tags them with a unique address string composed
of the variable’s name and a memory path identifying the unique name
of the MODFLOW component type and for MODFLOW package variables
the unique name of the package it belongs to. Examples of the address
string for a number of characteristic variables is shown in Table 1.
MODFLOW component types include timing, solution, model, exchange,
and utility components (see Hughes et al., 2017, for more information).
For user convenience and to assure future compatibility with the library,
the get_var_address utility function is available to construct this string
based on the syntax used internally by the Memory Manager. An in
Fig. 1. Overview of software components and applications in relation to the
ventory of all accessible variables can be retrieved with the BMI function
MODFLOW API. The Core contains all simulation code and can be compiled
get_input_var_names (or get_output_var_names as no distinction has been
with a driver program into the MODFLOW executable (mf6. exe) and with the
API into a shared library (libmf6. dll). An interoperability layer sits between
made between input or output variables in the MODFLOW API) or by
MODFLOW and possible software applications. The interaction from Python is setting MEMORY_PRINT_OPTION to ALL in the options block of the
facilitated with the modflowapi package which extends the bindings for the simulation namefile.
XMI available in xmipy. As potential developments, the API can be exposed to Although in principle it is possible to modify all variables inside the
C#.NET ([Link]) or connected to the PyMT framework (see Hutton and Memory Manager, this should be used with caution. For instance, the
Piper (2020) for more information on PyMT). The Apps layer shows external BMI could be used to change horizontal hydraulic conductivity (k11)
simulation programs that can interact with the MODFLOW API. Developments inside the Node Property Flow (NPF) Package after the initialization
that concern the connection of imod_coupler, MODSIM, and GSFLOW to the phase in an attempt to simulate time-varying hydraulic properties.
MODFLOW API are ongoing and presented in section 3. However, the saturated conductance (condsat) is used to calculate terms
in the coefficient matrix and although it depends on k11, it is calculated
applications. MODFLOW is considered to be either the executable only once at the beginning of the simulation (during initialize). There
version or the shared library version as the latter can be initiated and run fore, modifying k11 after initialization would have no effect on the
in a manner that gives the same results as the executable. Fig. 1 shows simulation results. Other parameters, such as those related to the
three different implementations of an interoperable layer that sits be dimensionality of the coefficient matrices or to the time discretization,
tween the MODFLOW API and applications based on it. An interoperable should probably not be modified to avoid undefined behavior and
layer, such as the modflowapi Python package, makes it easier to control possible program failure. Section 3 contains multiple validated use cases
MODFLOW and transfer information. The purpose of this section is to of reading and writing data using the MODFLOW API procedures. In
describe the API layer shown in Fig. 1 including both the BMI and the general, the user should consult the source code to confirm the validity
eXtended Model Interface (XMI). The subsequent section contains ex of a specific application.
amples on how to use the MODFLOW API in practice. The implementation of the interface functions follows the CSDMS
Fortran 2003 BMI specification (Piper, 2020). However, with the goal of
2.1. Implementation of the basic Model Interface developing a universally accessible library in mind, small modifications
had to be made, mostly avoiding the use of Fortran-specific data types.
In order to expose the MODFLOW functionality with the main BMI The resulting API is ensured to have Standard C (Kernighan and Ritchie,
control functions (initialize, update, finalize), the source code has been 1988) interoperability.
refactored. A high-level API is developed to aggregate the traditional
MODFLOW subroutines into functional units that can be mapped 2.2. Development of the eXtended Model Interface
directly to the BMI initialize, update, and finalize functions as shown by
the diagram in Fig. 2. The main reason for the code refactoring is the BMI only allows a sequential, loose coupling of process models. To
requirement that the same program code is executed regardless of enable a tighter coupling, at the iteration level, but also to provide more
whether the simulation is run with the executable or with the shared fine-grained control of the simulation, we have developed the eXtended
library containing the newly developed BMI. Model Interface (XMI) which consists of all BMI functionality plus the
As implied by the control flow in Fig. 2, the caller of the BMI control necessary extensions. A first extension is the subdivision of the update
functions is also responsible for implementing the time-step loop. The function into smaller units to allow the interactive modification of time-
simulation time inside MODFLOW is divided into stress periods which varying data. These data are read from file for each time step in a
are subdivided into time steps. Stress periods are intervals during which dedicated Read and Prepare (RP) step, as shown in Fig. 3. In the XMI
external stresses can be redefined and are provided as a convenience for function prepare_time_step the data are read and before an external call
users. The time steps constitute the potentially non-equidistant dis to do_time_step is made, they can still be changed using the BMI
cretization of time used to solve the numerical models in the simulation. functions.
Note that as opposed to previous versions of the code, there is no explicit A second extension is the explicit exposure of the non-linear
loop over stress periods anymore in MODFLOW which complies with the convergence loop of a numerical solution. This is shown schematically
interpretation of the time loop as prescribed by the BMI. A call to the in Fig. 4. With such fine grained control, it is now possible to tightly-
update function advances the simulation by a single time step. The start couple MODFLOW to other model components and have the solution
time of the simulation (get_start_time) is fixed at 0.0 for all simulations. converge at the outer iteration level, i.e., within a single time step. This
The end time (get_end_time) is set to the total simulation time which is is often preferable to a loosely-coupled sequential alternative, where one
equal to the summed lengths of the individual time steps. The current model finishes a time step and only then provides data that is used as
time can be queried with a call to get_current_time but it is important to boundary conditions for the other model. The latter can cause the
3
J.D. Hughes et al. Environmental Modelling and Software 148 (2022) 105257
Table 1
The composition of MODFLOW API memory addresses for variables inside a
solution (SLN), the dependent variable for the groundwater flow and transport
models, three distinct MODFLOW model packages (GWF/NPF, GWF/RIV, and
GWT/MST), and a groundwater flow exchange (GWF-GWF). Note that the
MODFLOW component and package types have unique names, which are used as
part of the address string. This is not an exhaustive list of MODFLOW variables.
MODFLOW MODFLOW
4
J.D. Hughes et al. Environmental Modelling and Software 148 (2022) 105257
5
J.D. Hughes et al. Environmental Modelling and Software 148 (2022) 105257
Fig. 6. Python code used to run the MODFLOW model with the selected head-
dependent evapotranspiration function as part of the non-linear outer iteration
loop. Although this code snippet does not run on its own, it demonstrates the
concept of getting and setting MODFLOW variables, such as the node number
(nodelist array of the API Package) and the evapotranspiration terms (hcof and
rhs arrays of the API Package). The Python code has been modified slightly
from the working example for illustrative purposes.
6
J.D. Hughes et al. Environmental Modelling and Software 148 (2022) 105257
7
J.D. Hughes et al. Environmental Modelling and Software 148 (2022) 105257
Minimize Z = ct x The Python code used to solve this optimization problem formulates
subject to Ax = b (5) the terms shown in equation (5) and then uses the revised simplex
where 0 ≤ x ≤ u, method in scipy. optimize to solve for the well withdrawal rates using
8
J.D. Hughes et al. Environmental Modelling and Software 148 (2022) 105257
enabled and extracts water from model layer 3 of the MODFLOW model instead of being recalculated each MODFLOW outer non-linear iteration
component using the WEL Package. The soil type for the MetaSWAP as is done in GSFLOW.
model component is specified as peat, which is type number 1 in the As part of a separate effort, the BMI was recently implemented in
MetaSWAP soil database. PRMS with the program being split into separate surface, soil, ground
Precipitation and actual evapotranspiration (ETact) are shown in water, and streamflow domain components. The surface and soil domain
Fig. 10A. Actual evapotranspiration is greatest during the growing sea components were the only PRMS domain components used in this
son with peaks appearing at weekly intervals, resulting from increased example.
soil water evaporation during the sprinkler irrigation, which is modeled The PRMS surface domain component was used to simulate processes
to occur on weekly basis. The simulated recharge from the unsaturated above the soil surface including: 1) rain and snow; 2) potential evapo
zone to the groundwater model (qrch) for the centermost cell in the top transpiration; 3) snow sublimation; 4) canopy interception, storage,
layer is shown in Fig. 10B. The inset in Fig. 10B shows how the system evaporation, and throughfall; and 5) surface runoff. The PRMS soil
transitions from the unsaturated zone being a source of water for the domain component was used to simulate storage, inflow, and outflow
groundwater system to a sink for the groundwater system, as a result of within the soil zone reservoir. Soil zone inflows include infiltration and
capillary rise, during the dry summer period. Simulated groundwater outflows include: 1) evapotranspiration; 2) interflow and preferential
head in the centermost cell in the top layer is shown in Fig. 10C and flow; and 3) groundwater recharge. The MODFLOW UZF Package was
shows the response of the water table to groundwater recharge (qrch). used to simulate vertical unsaturated groundwater flow below the PRMS
Irrigation effects are not noticeable in Fig. 10C because the well extracts soil domain component soil-zone and subsurface reservoirs. The MOD
water from model layer 3. FLOW SFR Package was used to simulate streamflow in a total of 201
Although this example is hypothetical and oversimplified, it does connected reaches. The MODFLOW drain (DRN) Package was used to
illustrate how the MODFLOW API enables seamless coupling of two simulate groundwater seepage to land surface in areas where the
existing component models without needing to modify the source code groundwater levels exceed land surface.
of either component model. In this example, MetaSWAP makes it PRMS HRUs and parameters are from Markstrom et al. (2006); the
possible to simulate the unsaturated zone in more detail than possible HRUs simulated in this model application are shown in Fig. 11. MOD
with the MODFLOW UZF Package and to simulate groundwater irriga FLOW parameters are from GSFLOW Sagehen Creek model application.
tion that is a function of soil moisture. The explicit control of the outer The groundwater domain component has a total of 2 layers, 73 rows,
iteration loop, a specific feature of XMI, is required for this example and and 81 columns and was discretized using a constant grid cell size of 90
can serve as a blueprint for other applications that require tight coupling m in the row and column directions. The active model domain is
with MODFLOW. restricted to the lateral extent of the Sagehen Creek watershed, with a
total of 3392 active cells per layer and covering a 27,475,200 m2 area.
UZF Package cells were included in active cells in both model layers and
3.4. Coupling MODFLOW to PRMS in cases where the water level in cells in model layer 1 is below the
bottom of the cell, unsaturated zone flow at the bottom of the cell is
The MODFLOW API and BMI for PRMS were used to simulate inte routed to the underlying UZF cell in layer 2. Lateral groundwater
grated surface-water and groundwater processes in the Sagehen Creek discharge out of the watershed was simulated using the Time-Varying
watershed located on the east slope of the northern Sierra Nevada Constant Head (CHD) Package and constant head cells at the down
mountains in California. The Sagehen Creek application described here stream end of the watershed; a constant head of 1915 m and 1900 m was
is based on the GSFLOW model of the same area (Markstrom et al., specified in 3 cells in model layer 1 and 3 cells in model layer 2,
2008). Some key differences between this Sagehen Creek application respectively. See Markstrom et al. (2006) and Markstrom et al. (2008)
and the GSFLOW Sagehen Creek model application include: 1) 128 for additional information on PRMS and MODFLOW parameters.
watershed-based hydrologic response units (HRUs) were used instead of MODFLOW and PRMS were sequentially coupled during a time step
cell based HRUs, 2) the PRMS cascade module was not used to route by first running the update() functions for the PRMS surface and soil
surface runoff and interflow from upslope HRUs to downslope HRUs, domain components, extracting results from PRMS and mapping PRMS
and 3) the PRMS soil component is only solved once per time step
9
J.D. Hughes et al. Environmental Modelling and Software 148 (2022) 105257
Fig. 11. Simulated average infiltration and groundwater recharge for October 1992 through September 1996. A. Average infiltration rate in mm d− 1. B. Average
groundwater recharge rate in mm d− 1. The location of the 128 HRUs and the SFR stream network are also shown.
HRU results to MODFLOW grid cells, and finally running the MODFLOW GSFLOW Sagehen Creek model application. Significant storage changes
update() function. Groundwater recharge calculated by the PRMS soil were observed in the unsaturated and saturated zones in MODFLOW
domain component for the soil zone and subsurface reservoirs for each results during the first two years of the simulation. As a result, the period
of the 128 HRUs was applied as infiltration to 3386 underlying UZF from October 1980 to October 1982 is considered a warm-up period and
Package cells in model layer 1. Unsatisfied potential evapotranspiration, has been excluded from model result analyses.
calculated as the difference between the potential evapotranspiration The average infiltration, which is calculated as the difference be
calculated in the PRMS surface domain component and the actual tween the groundwater recharge calculated by the PRMS soil domain
evapotranspiration calculated by the PRMS surface and soil domain component and rejected infiltration calculated by the UZF Package, is
components, was applied as potential evapotranspiration to underlying shown in Fig. 11A. Rejected infiltration occurs near the surface-water
the UZF cells in model layer 1. The HRUs were intersected with the network and is shown in Fig. 11A as areas where average infiltration
MODFLOW grid to calculate the area-based HRU-UZF weights used to rates are different from the groundwater recharge rate calculated by
map PRMS results to UZF cells. The HRUs were also intersected with the PRMS for a HRU. Average groundwater recharge rates exceed average
stream network to map PRMS runoff and interflow from 128 HRUs as infiltration rates near topographic divides for several HRUs and in cells
runoff to 201 SFR reaches; equal weighting rather than reach-length with elevations much higher than surrounding cells as a result of
based weighting was applied to calculate HRU-SFR weights. In addi drainage of initial soil moisture in the unsaturated zone.
tion to mapping PRMS HRU data to MODFLOW UZF cells and SFR Simulated and observed streamflow is shown in Fig. 12A. The model
reaches, unit conversions were made to convert PRMS inch and acre application over-simulates streamflow, especially during high flow
units to MODFLOW m and m2 units. events. The contribution of runoff, interflow, groundwater seepage, and
The MODFLOW Mover (MVR) Package was used to route rejected baseflow to streamflow is shown in 12B. Interflow was the largest
infiltration, calculated by the UZF Package, and groundwater seepage to contributor to streamflow at the end of the evaluation period followed
the surface, calculated by the DRN Package, to the reaches in the SFR by baseflow, groundwater seepage, and runoff. The contribution of
Package. The same approach used to develop the HRU-SFR weights was PRMS, unsaturated zone, and saturated zone evapotranspiration to the
used to connect UZF cells to SFR reaches using the MVR Package. UZF total evapotranspiration is shown in 12C. Evapotranspiration from the
cells in model layer 2 were also routed to the same SFR reach as UZF surface and soil PRMS component accounted for more the 99% of the
cells in model layer 1 using the MVR Package to route excess unsatu total evapotranspiration.
rated zone flow from the overlying UZF cell (rejected infiltration) to the
surface-water network. 3.5. Coupling MODFLOW to MODSIM
The model application simulation period extends from October 1,
1980 through September 30, 1996 and included 5844 daily time steps. Three recent publications showcased the integration of a river
The Sagehen Creek watershed model application used daily precipita operation model with a physically-based distributed parameter hydro
tion and air temperature data from the GSFLOW Sagehen Creek model logic model (Brookfield et al., 2017; Dogrul et al., 2016; Morway et al.,
application. Precipitation in the Sagehen Creek watershed is highly 2016). In all three integrations, reservoir release and ditch diversion(s)
variable in form and intensity and generally increases with altitude. as calculated by the river/reservoir operation model override values
Initial groundwater levels for the simulation were based on steady-state within the hydrologic model and specified by a user prior to running the
heads calculated by a stand-alone MODFLOW model with specified UZF model. The groundwater surface-water exchange rates resulting from
Package infiltration rates from the GSFLOW Sagehen Creek model those operational decisions (i.e., releases and diversions) are then
application and an initial moisture content of 0.08 in each UZF cell. re-calculated by the hydrologic model for updating the appropriate
Although model application parameters are based on previous values within the operations model. In summary, the respective spe
Sagehen Creek model applications, this model application is considered cialty of each model complements a known weakness of the other,
uncalibrated because of the previously stated differences from the resulting in a modeling platform that better equips water resource
10
J.D. Hughes et al. Environmental Modelling and Software 148 (2022) 105257
Fig. 13. Schematic of the hypothetical model used to test the integration of
MODSIM with MODFLOW. MODSIM-calculated values include the reservoir
release (red circle) and amount of water to divert (red squares) into four ditches
used to deliver irrigation water. The BMI interface is used to retrieve the
groundwater surface-water exchange volumes calculated by MODFLOW for
overwriting user-specified groundwater gains and losses inside MODSIM.
11
J.D. Hughes et al. Environmental Modelling and Software 148 (2022) 105257
12
J.D. Hughes et al. Environmental Modelling and Software 148 (2022) 105257
• MODFLOW is supported by several commercial graphical user in Brookfield, A., Gnau, C., Wilson, B., 2017. Incorporating surface water operations in an
integrated hydrologic model: model development and application to the lower
terfaces (GUIs) that allow users to develop, run, and post-process
republican river basin, United States. J. Hydrol. Eng. 22 [Link]
groundwater models. The MODFLOW API provides a new way for (ASCE)HE.1943-5584.0001486, 04016065 – 15.
these GUIs to run a simulation, monitor its progress, even at the Chen, M., Voinov, A., Ames, D.P., Kettner, A.J., Goodall, J.L., Jakeman, A.J., Barton, M.
iteration level, and provide instantaneous feedback to the user. C., Harpham, Q., Cuddy, S.M., DeLuca, C., Yue, S., Wang, J., Zhang, F., Wen, Y.,
Lu, G., 2020. Position paper: open web-distributed integrated geographic modelling
and simulation to enable broader participation and applications. Earth Sci. Rev. 207,
This paper describes the initial release of the MODFLOW API, and 103223. [Link] URL: [Link]
there are several limitations to mention. Although the API allows the [Link]/science/article/pii/S0012825220302695.
Collins, N., Theurich, G., DeLuca, C., Suarez, M., Trayanov, A., Balaji, V., Li, P., Yang, W.,
user to interact with time steps individually they must be executed Hill, C., Da Silva, A., 2005. Design and implementation of components in the Earth
sequentially from the first to the last time step (i.e., a time step that has system modeling framework. Int. J. High Perform. Comput. Appl. 19, 341–350.
been finalized using update or finalize_time_step can not be rerun). [Link]
Davis, P.R., 2001. ISGW—the integrated hydrologic model coupling HSPF and
Development of restart capability for MODFLOW is a high priority but MODFLOW. In: Panigrahi, B.K., Singh, U.P. (Eds.), Integrated Surface and Ground
being able to rerun a time step and correctly synchronize file based input Water Management. American Society of Civil Engineers, pp. 100–109. [Link]
and output during run time is challenging. Another limitation is, the org/10.1061/40562(267)11.
De Lange, W.J., Prinsen, G.F., Hoogewoud, J.C., Veldhuizen, A.A., Verkaik, J., Oude
current version of the MODFLOW API requires that the user has intimate Essink, G.H., van Walsum, P.E., Delsman, J.R., Hunink, J.C., Massop, H.T., Kroon, T.,
knowledge of the underlying MODFLOW program, variables, and order 2014. An operational, multi-scale, multi-model system for consensus-based,
of operations. For coupling another model with MODFLOW, the user integrated water management and policy analysis: The Netherlands Hydrological
Instrument. Environ. Model. Software 59, 98–108. [Link]
must be familiar with both programs, have a firm understanding of
envsoft.2014.05.009.
variable names, which variables to exchange, when to exchange infor Dogrul, E.C., Kadir, T.N., Brush, C.F., Chung, F.I., 2016. Linking groundwater simulation
mation, the scientific units used in the models, and so forth. Work is and reservoir system analysis models: the case for California’s Central Valley.
ongoing to better document the internal functioning of MODFLOW in Environ. Model. Software 77, 168–182. [Link]
envsoft.2015.12.006.
order to make it easier to use the MODFLOW API. For example, it may be Farthing, M.W., Ogden, F.L., 2017. Numerical solution of Richards’ equation: a review of
possible to use standard names for common variables, as suggested by advances and challenges. Soil Sci. Soc. Am. J. 81, 1257–1269. [Link]
Peckham et al. (2013) and Peckham (2014), and allow users to access 10.2136/sssaj2017.02.0058.
Ferziger, J.H., Peric, M., 1996. Computational Methods for Fluid Dynamics. [Link]
data using these standard names. There is also ongoing work to allow org/10.1007/978-3-642-56026-2.
model simulations to be created in memory, rather than being created Gregersen, J., Gijsbers, P., Westen, S., 2007. OpenMI: open modelling interface.
from input files, as is required in the current version. These limitations J. Hydroinf. 9, 175–191. [Link]
Harbaugh, A.W., 2005. MODFLOW-2005, the U.S. Geological Survey Modular Ground-
will continue to be addressed by the MODFLOW development team as Water Model—The Ground-Water Flow Process. U.S. Geological Survey Techniques
the MODFLOW API is used in practice and the latest developments will and Methods, Book 6, A16. [Link]
be available at the urls listed in Section 4. Harris, C.R., Millman, K.J., van der Walt, S.J., Gommers, R., Virtanen, P.,
Cournapeau, D., Wieser, E., Taylor, J., Berg, S., Smith, N.J., Kern, R., Picus, M.,
Hoyer, S., van Kerkwijk, M.H., Brett, M., Haldane, A., Fernandez del Rio, J.,
Wiebe, M., Peterson, P., Gerard-Marchant, P., Sheppard, K., Reddy, T.,
Declaration of competing interest Weckesser, W., Abbasi, H., Gohlke, C., Oliphant, T.E., 2020. Array programming
with NumPy. Nature 585, 357–362. [Link]
The authors declare that they have no known competing financial Hill, M.C., Cooley, R.L., Pollock, D.W., 1998. A controlled experiment in ground water
flow model calibration. Groundwater 36, 520–535. [Link]
interests or personal relationships that could have appeared to influence 6584.1998.tb02824.x.
the work reported in this paper. Hoch, J.M., Eilander, D., Ikeuchi, H., Baart, F., Winsemius, H.C., 2019. Evaluating the
impact of model complexity on flood wave propagation and inundation extent with a
hydrologic–hydrodynamic model coupling framework. Nat. Hazards Earth Syst. Sci.
Acknowledgements 19, 1723–1735. [Link]
Hughes, J.D., Langevin, C.D., Banta, E.R., 2017. Documentation for the MODFLOW 6
The authors would like to acknowledge Mark Piper and Eric Hutton Framework. U.S. Geological Survey Techniques and Methods, Book 6, A57, p. 36.
[Link]
from CSDMS for their help in implementing the BMI standard in PRMS Hughes, J.D., Russcher, M.J., Langevin, C.D., Hofer, J., 2021. Modflowapi–An Extension
and for discussions during the development of the MODFLOW API. The to Xmipy for the MODFLOW API Version 0.0.1 [Computer Software]. U.S. Geological
authors would also like to acknowledge Michael Fienen from the U.S. Survey Software Release. [Link]
Hutton, E.W., Piper, M.D., 2020. The python Modeling Toolkit (Version v1.0.0)
Geological Survey for early discussions about the development of the [Computer Software]. [Link]
MODFLOW API and for his review of the manuscript, Laura Schachter Hutton, E.W., Piper, M.D., Tucker, G.E., 2020. The basic model interface 2.0: a standard
from the U.S. Geological Survey for her review of the manuscript, Joeri interface for coupling numerical models in the geosciences. Journal of Open Source
Software 5, 2317. [Link]
van Engelen from Deltares for his review of the manuscript, and four
Kernighan, B.W., Ritchie, D.M., 1988. The C Programming Language, second ed.
anonymous reviewers at the journal. Kim, N.W., Chung, I.M., Won, Y.S., Arnold, J.G., 2008. Development and application of
Any use of trade, firm, or product names is for descriptive purposes the integrated SWAT–MODFLOW model. J. Hydrol. 356, 1–16. [Link]
10.1016/[Link].2008.02.024.
only and does not imply endorsement by the U.S. Government.
Kluyver, T., Ragan-Kelley, B., Pérez, F., Granger, B., Bussonnier, M., Frederic, J.,
Kelley, K., Hamrick, J., Grout, J., Corlay, S., Ivanov, P., Avila, D., Abdalla, S.,
References Willing, C., 2016. Jupyter notebooks – a publishing format for reproducible
computational workflows. In: Loizides, F., Schmidt, B. (Eds.), Positioning and Power
in Academic Publishing: Players, Agents and Agendas. IOS Press, pp. 87–90. https://
Ahlfeld, D.P., Barlow, P.M., Mulligan, A.E., 2005. GWM—a ground-water management
[Link]/10.3233/978-1-61499-649-1-87.
process for the U.S. Geological Survey modular ground-water model (MODFLOW-
Labadie, J.W., Baldo, M.L., Larson, R., 2000. MODSIM: Decision Support System for
2000). U.S. Geological Survey Open-File Report 2005–1072 130. [Link]
River Basin Management: Documentation and User Manual. Technical Report.
10.3133/ofr20051072.
Colorado State University, Department of Civil Engineering.
Armstrong, R., Gannon, D., Geist, A., Keahey, K., Kohn, S., McInnes, L., Parker, S.,
Langevin, C.D., Hughes, J.D., Provost, A.M., Banta, E.R., Niswonger, R.G., Panday, S.,
Smolinski, B., 1999. Toward a common component architecture for high-
2017. Documentation for the MODFLOW 6 Groundwater Flow (GWF) Model. U.S.
performance scientific computing. In: Proceedings. The Eighth International
Geological Survey Techniques and Methods, Book 6, A55, p. 197. [Link]
Symposium on High Performance Distributed Computing (Cat. No. 99TH8469),
10.3133/tm6A55.
IEEE, pp. 115–124. [Link]
Langevin, C.D., Panday, S., Provost, A.M., 2020. Hydraulic-head formulation for density-
Bakker, M., Post, V., Langevin, C.D., Hughes, J.D., White, J., Starn, J., Fienen, M.N.,
dependent flow and transport. Groundwater 58, 349–362.
2016. Scripting modflow model development using python and flopy. Groundwater
Langevin, C.D., Thorne, D.T., Dausman, A.M., Sukop, M.C., Guo, W., 2008. SEAWAT
54, 733–739. [Link]
Version 4: A Computer Program for Simulation of Multi-Species Solute and Heat
Belete, G.F., Voinov, A., Laniak, G.F., 2017. An overview of the model integration
Transport. U.S. Geological Survey Techniques and Methods, Book 6, A22, p. 39.
process: from pre-integration assessment to testing. Environ. Model. Software 87,
[Link]
49–63. [Link] URL: [Link]
[Link]/science/article/pii/S1364815216308805.
13
J.D. Hughes et al. Environmental Modelling and Software 148 (2022) 105257
Makkink, G.F., 1957. Testing the penman formula by means of lysimeters. J. Inst. Water Ratliff, K.M., Hutton, E.H., Murray, A.B., 2018. Exploring wave and sea-level rise effects
Eng. 11, 277–288. on delta morphodynamics with a coupled river-ocean model. J. Geophys. Res.: Earth
Markstrom, S.L., Niswonger, R.G., Regan, R.S., Prudic, D.E., Barlow, P.M., 2008. Surface 123, 2887–2900. [Link]
GSFLOW-coupled Ground-Water and Surface-Water FLOW Model Based on the Rodriguez, L.B., Cello, P.A., Vionnet, C.A., Goodrich, D., 2008. Fully conservative
Integration of the Precipitation-Runoff Modeling System (PRMS) and the Modular coupling of HEC-RAS with MODFLOW to simulate stream–aquifer interactions in a
Ground-Water Flow Model (MODFLOW-2005). Volume 6-D1 of U.S. Geological drainage basin. J. Hydrol. 353, 129–142. [Link]
Survey Techniques and Methods, Book 6, D1, p. 240. [Link] jhydrol.2008.02.002.
tm6D1. Russcher, M.J., Hofer, J., Hughes, J.D., 2020. xmipy–Python Bindings for the eXtended
Markstrom, S.L., Regan, R.S., Hay, L.E., Viger, R.J., Webb, R.M., Payn, R.A., Model Interface Version 1.0.0 [Computer Software]. Deltares software release.
LaFontaine, J.H., 2015. PRMS-IV, the Precipitation-Runoff Modeling System, [Link]
Version 4. U.S. Geological Survey Techniques and Methods, Book 6, B7, p. 158. Shoemaker, W.B., Kuniansky, E.L., Birk, S., Bauer, S., Swain, E.D., 2008. Documentation
[Link] of a Conduit Flow Process (CFP) for MODFLOW-2005. U.S. Geological Survey
Markstrom, S.L., Regan, R.S., Niswonger, R.G., Prudic, D.E., Viger, R.J., 2006. Techniques and Methods, Book 6, A24, p. 50. [Link]
GSFLOW–A basin scale model for coupled simulation of ground-water and surface- Swain, E.D., Wexler, E.J., 1996. A Coupled Surface-Water and Ground-Water Flow Model
water–Part A. Concepts for modeling surface-water flow with the U.S. Geological (MODBRANCH) for Simulation of Stream-Aquifer Interaction. U.S. Geological
Survey Precipitation-Runoff Modeling System. In: Proceedings of the Third Federal Survey Techniques of Water-Resources Investigations 06-A6, p. 125. [Link]
Interagency Hydrologic Modeling Conference, Reno, Nevada, USA. URL: https 10.3133/twri06a6.
://[Link]/hydrology/mtsconfwkshops/conf_proceedings/3rdFIHMC/7F_Markstro Twarakavi, N.K.C., Šimůnek, J., Seo, S., 2008. Evaluating interactions between
[Link]. groundwater and vadose zone using the HYDRUS-based flow package for
Metcalf, M., Reid, J., Cohen, M., 2018. Modern Fortran Explained. [Link] MODFLOW. Vadose Zone J. 7, 757–768. [Link]
10.1093/oso/9780198811893.001.0001. Vermeulen, P., Roelofsen, F., Hunink, J., Janssen, G., Romero Verastegui, B., Van
Morway, E.D., Langevin, C.D., Hughes, J.D., 2021. Use of the MODFLOW 6 water mover Engelen, J., Russcher, M., 2020. iMOD user manual version 5.2. Deltares.
package to represent natural and managed hydrologic connections. Groundwater. Virtanen, P., Gommers, R., Oliphant, T.E., Haberland, M., Reddy, T., Cournapeau, D.,
[Link] Burovski, E., Peterson, P., Weckesser, W., Bright, J., van der Walt, S.J., Brett, M.,
Morway, E.D., Niswonger, R.G., Triana, E., 2016. Toward improved simulation of river Wilson, J., Millman, K.J., Mayorov, N., Nelson, A.R.J., Jones, E., Kern, R., Larson, E.,
operations through integration with a hydrologic model. Environ. Model. Software Carey, C.J., Polat, İ., Feng, Y., Moore, E.W., VanderPlas, J., Laxalde, D., Perktold, J.,
82, 255–274. [Link] Cimrman, R., Henriksen, I., Quintero, E.A., Harris, C.R., Archibald, A.M., Ribeiro, A.
Panday, S., Langevin, C.D., Niswonger, R.G., Ibaraki, M., Hughes, J.D., 2013. H., Pedregosa, F., van Mulbregt, P., SciPy 1.0 contributors, 2020. SciPy 1.0:
MODFLOW-USG Version 1—An Unstructured Grid Version of MODFLOW for fundamental algorithms for scientific computing in Python. Nat. Methods 17,
Simulating Groundwater Flow and Tightly Coupled Processes Using a Control 261–272. doi:10.1038/s41592-019-0686-2.
Volume Finite-Difference Formulation. U.S. Geological Survey Techniques and van Walsum, P., Veldhuizen, A., 2011. Integration of models using shared state variables:
Methods, Book 6, A45, p. 66. URL: [Link] implementation in the regional hydrologic modelling system SIMGRO. J. Hydrol.
Peckham, S.D., 2014. The CSDMS standard names: cross-domain naming conventions for 409, 363–370. [Link]
describing process models, data sets and their associated variables. In: Ames, D.P., van Walsum, P.E.V., Groenendijk, P., 2008. Quasi steady-state simulation of the
T, Q.N.W., Rizzoli, A.E. (Eds.), 7th International Congress on Environmental unsaturated zone in groundwater modeling of lowland regions. Vadose Zone J. 7,
Modelling and Software, International Environmental Modelling and Software 769–781. [Link]
Society (iEMSs), San Diego, California, USA. URL: [Link] Wang, J.D., Swain, E.D., Wolfert, M.A., Langevin, C.D., James, D.E., Telis, P.A., 2007.
images/Peckham_2014_iEMSs.pdf. Application of FTLOADDS to Simulate Flow, Salinity, and Surface-Water Stage in the
Peckham, S.D., Hutton, E.W., Norris, B., 2013. A component-based approach to Southern Everglades, Florida. U.S. Geological Survey Scientific Investigations Report
integrated modeling in the geosciences: the design of CSDMS. Comput. Geosci. 53, 2007-5010, p. 112. [Link]
3–12. [Link] White, J.T., Fienen, M.N., Barlow, P.M., Welter, D.E., 2018. A tool for efficient, model-
Pérez, F., Granger, B.E., 2007. IPython: a system for interactive scientific computing. independent management optimization under uncertainty. Environ. Model. Software
Comput. Sci. Eng. 9, 21–29. [Link] 100, 213–221. [Link] URL: [Link]
Piper, M.D., 2020. The Fortran Specification, Created with Fortran 2003, for the CSDMS [Link]/science/article/pii/S1364815217306965.
Basic Model Interface (BMI) (Version v2.0) [Computer Software]. [Link] Winston, R.B., Konikow, L.F., Hornberger, G.Z., 2018. Volume-weighted particle-
10.5281/zenodo.3637641. tracking method for solute-transport modeling. In: Implementation in MODFLOW-
Provost, A.M., Langevin, C.D., Hughes, J.D., 2017. Documentation for the “XT3D” Option GWT. U.S. Geological Survey Techniques and Methods, Book 6, A58, p. 44. https://
in the Node Property Flow (NPF) Package of MODFLOW 6. U.S. Geological Survey [Link]/10.3133/tm6a58.
Techniques and Methods, Book 6, A56, p. 46. [Link] Winter, T.C., Harvey, J.W., Franke, O.L., Alley, W.M., 1998. Ground water and surface
water: a single resource. US Geol. Surv. Circular 1139, 79. [Link]
cir1139.
14