GithubHelp home page GithubHelp logo

upc-ghs / flopyrw Goto Github PK

View Code? Open in Web Editor NEW
4.0 3.0 0.0 493 KB

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

License: MIT License

Python 100.00%
modpath-rw flopy hydrogeology particles python solute-transport

flopyrw's Introduction

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

flopyrw's People

Contributors

rodrperezi avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.