This page was generated from drain_return_example.py. It's also available as a notebook.

Flopy Drain Return (DRT) capabilities

[1]:
import os
[2]:
import sys
from pprint import pformat
from tempfile import TemporaryDirectory

import matplotlib as mpl
import matplotlib.pyplot as plt
import numpy as np

import flopy

print(sys.version)
print(f"numpy version: {np.__version__}")
print(f"matplotlib version: {mpl.__version__}")
print(f"flopy version: {flopy.__version__}")
3.12.2 | packaged by conda-forge | (main, Feb 16 2024, 20:50:58) [GCC 12.3.0]
numpy version: 1.26.4
matplotlib version: 3.8.4
flopy version: 3.7.0.dev0
[3]:
# temporary directory
temp_dir = TemporaryDirectory()
modelpth = temp_dir.name

# creat the model package
m = flopy.modflow.Modflow(
    "drt_test",
    model_ws=modelpth,
    exe_name="mfnwt",
    version="mfnwt",
)
d = flopy.modflow.ModflowDis(
    m,
    nlay=1,
    nrow=10,
    ncol=10,
    nper=1,
    perlen=1,
    top=10,
    botm=0,
    steady=True,
)
b = flopy.modflow.ModflowBas(m, strt=10, ibound=1)
u = flopy.modflow.ModflowUpw(m, hk=10)
n = flopy.modflow.ModflowNwt(m)
o = flopy.modflow.ModflowOc(m)
[4]:
# create the drt package
spd = []
for i in range(m.nrow):
    spd.append([0, i, m.ncol - 1, 5.0, 50.0, 1, 1, 1, 1.0])
d = flopy.modflow.ModflowDrt(m, stress_period_data={0: spd})
[5]:
# run the drt model
m.write_input()
success, buff = m.run_model(silent=True, report=True)
assert success, pformat(buff)
[6]:
# plot heads for the drt model
hds = flopy.utils.HeadFile(os.path.join(m.model_ws, f"{m.name}.hds"))
hds.plot(colorbar=True)
[6]:
<Axes: title={'center': 'data Layer 1'}>
../_images/Notebooks_drain_return_example_6_1.png
[7]:
# remove the drt package and create a standard drain file
spd = []
for i in range(m.nrow):
    spd.append([0, i, m.ncol - 1, 5.0, 1.0])
m.remove_package("DRT")
d = flopy.modflow.ModflowDrn(m, stress_period_data={0: spd})
[8]:
# run the drain model
m.write_input()
success, buff = m.run_model(silent=True, report=True)
assert success, pformat(buff)
[9]:
# plot the heads for the model with the drain
hds = flopy.utils.HeadFile(os.path.join(m.model_ws, f"{m.name}.hds"))
hds.plot(colorbar=True)
[9]:
<Axes: title={'center': 'data Layer 1'}>
../_images/Notebooks_drain_return_example_9_1.png
[10]:
try:
    # ignore PermissionError on Windows
    temp_dir.cleanup()
except:
    pass