Skip to main content

Python interface based on FloPy to configure input files for MODPATH-RW

Project description

flopyrw

An extension of FloPy to write input simulation files for MODPATH-RW with Python.

Overview

Provides classes extended from the modpath module in flopy adapted to specific structures required by MODPATH-RW. Also introduces new package writers required by the program, consistent with the Documentation of Input-Output.

Quickstart

Install

To install the package from source, clone the repository:

git clone https://github.com/upc-ghs/flopyrw

and install

pip install -e /the/path/to/flopyrw/

You can also install the current release from PyPI:

pip install flopyrw

Use it

Classes follow the same logic than flopy, configuring packages on top of a MODFLOW flow-model object. For example, the flopy quickstart case:

import os
import flopy
from flopyrw import modpathrw

ws   = './mymodel'
name = 'mymodel'
sim  = flopy.mf6.MFSimulation(sim_name=name, sim_ws=ws, exe_name='mf6')
tdis = flopy.mf6.ModflowTdis(sim)
ims  = flopy.mf6.ModflowIms(sim)
gwf  = flopy.mf6.ModflowGwf(sim, modelname=name, save_flows=True)
dis  = flopy.mf6.ModflowGwfdis(gwf, nrow=10, ncol=10)
ic   = flopy.mf6.ModflowGwfic(gwf)
npf  = flopy.mf6.ModflowGwfnpf(gwf, save_specific_discharge=True)
# Same than in flopy quickstart,
# but with an aux var for concentration.
chd  = flopy.mf6.ModflowGwfchd(
        gwf,
        auxiliary=['CONCENTRATION'],
        stress_period_data=[
            [(0, 0, 0), 1.,1.],
            [(0, 9, 9), 0.,0.]
        ]
    )
budget_file = name + '.bud'
head_file   = name + '.hds'
oc = flopy.mf6.ModflowGwfoc(gwf,
        budget_filerecord=budget_file,
        head_filerecord=head_file,
        saverecord=[('HEAD', 'ALL'), ('BUDGET', 'ALL')]
    )
sim.write_simulation()
sim.run_simulation()

# Create a modpathrw model
# By default executable is 'mpathrw'
mprw = modpathrw.ModpathRW(flowmodel=gwf)

# Random walk options
modpathrw.ModpathRWOpts(
        mprw,
        timestep = 'min',
        ctdisp   = 0.1,
        courant  = 0.1,
        dimensionsmask=[1,1,0], # Random walk in x,y and not in z
    )

# Dispersion parameters 
modpathrw.ModpathRWDsp( mprw, alphal=0.1, alphat=0.01,  dmeff=0.0 )

# Basic package
modpathrw.ModpathRWBas( mprw, porosity=0.3 )

# Define the solute source
# In forward tracking, only cells with injecting flow-rate release particles
modpathrw.ModpathRWSrc(
        mprw,
        sources=(
            'CHD', # package name
            [            
                [
                    'CONCENTRATION', # aux variable
                    0.001,           # particlesmass
                    (4,4,1)          # template
                ], 
            ],
        ),
    )

# Configure the simulation 
simconfig = {
    'simulationtype'    : 'rwendpoint', 
    'trackingdirection' : 'forward',
    'weaksinkoption'    : 'stop_at',
    'weaksourceoption'  : 'pass_through',
    'stoptimeoption'    : 'specified',
    'stoptime'          : 20.0,
}
mprwsim = modpathrw.ModpathRWSim( mprw,  **simconfig )

# Write the input files
mprw.write_input()

# And run 
mprw.run_model()

# Get output and plot
head   = gwf.output.head().get_data()
bud    = gwf.output.budget()
epoint = flopy.utils.EndpointFile( os.path.join( ws, mprwsim.endpointfilename ) ) 
spdis  = bud.get_data(text='DATA-SPDIS')[0]
qx, qy, qz = flopy.utils.postprocessing.get_specific_discharge(spdis, gwf)
pmv = flopy.plot.PlotMapView(gwf)
pmv.plot_array(head)
pmv.plot_grid(colors='white')
pmv.contour_array(head, levels=[.2, .4, .6, .8], linewidths=3.)
pmv.plot_vector(qx, qy, normalize=True, color="white")
pmv.plot_endpoint( epoint.get_alldata(), zorder=10, s=4, linewidth=0.5, edgecolor='k' )
plot

Note: In order to run a model via the interface a MODPATH-RW executable is required.

Testing

A suite of automated tests is available verifying different aspects of the interface and the program. In order to run these tests, some additional dependencies are required, which can be installed with:

pip install ".[test]"

You can follow the FloPy test guidelines for running and debugging tests.

Run the complete test suite from the folder autotest with the command:

pytest -s -v 

Resources

MIT License

Copyright (c) 2023 Hydrogeology Group - Universitat Politècnica de Catalunya

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

flopyrw-1.0.3.tar.gz (54.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

flopyrw-1.0.3-py3-none-any.whl (61.2 kB view details)

Uploaded Python 3

File details

Details for the file flopyrw-1.0.3.tar.gz.

File metadata

  • Download URL: flopyrw-1.0.3.tar.gz
  • Upload date:
  • Size: 54.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.7

File hashes

Hashes for flopyrw-1.0.3.tar.gz
Algorithm Hash digest
SHA256 17fe8b95f00f5113fe867916f9a6da5e542c867ef411c8560803161db868160b
MD5 ab6d18a1c4d5b5cff17982ffe7dfbac3
BLAKE2b-256 1e56b0f20dce7591532dfddf09f23302ac4cd1fdd43c78f5c55fbe6763ae632d

See more details on using hashes here.

File details

Details for the file flopyrw-1.0.3-py3-none-any.whl.

File metadata

  • Download URL: flopyrw-1.0.3-py3-none-any.whl
  • Upload date:
  • Size: 61.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.7

File hashes

Hashes for flopyrw-1.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 8ac9031533a0a3f3ad707c9d5e4891219f99830bb865216890b4d578a177b252
MD5 af36c243b5ea4bae247bcbb6ae1be6da
BLAKE2b-256 4bcd669c2621c6812af4a46d07c7d1e0b72aa03075898982a390d7567f96cd59

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page