Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(disv): improve cell area calculation #1347

Merged
merged 3 commits into from
Sep 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
127 changes: 68 additions & 59 deletions autotest/test_gwf_disu.py
Original file line number Diff line number Diff line change
@@ -1,91 +1,100 @@
"""
Test of GWF DISU Package. Use the flopy disu tool to create
a simple regular grid example, but using DISU instead of DIS.
The first case is just a simple test. For the second case, set
one of the cells inactive and test to make sure connectivity
in binary grid file is correct.

"""

import os

import flopy
import numpy as np
import pytest
from flopy.utils.gridutil import get_disu_kwargs

from framework import TestFramework
from simulation import TestSimulation

ex = ["disu01a", "disu01b"]


def test_disu_simple(tmpdir, targets):
mf6 = targets["mf6"]
name = "disu01a"
def build_model(idx, dir, mf6):
name = ex[idx]
ws = dir
nlay = 3
nrow = 3
ncol = 3
delr = 10.0 * np.ones(ncol)
delc = 10.0 * np.ones(nrow)
top = 0
botm = [-10, -20, -30]
disukwargs = get_disu_kwargs(nlay, nrow, ncol, delr, delc, top, botm)
disukwargs = get_disu_kwargs(
nlay,
nrow,
ncol,
delr,
delc,
top,
botm,
)
if idx == 1:
# for the second test, set one cell to idomain = 0
idomain = np.ones((nlay, nrow * ncol), dtype=int)
idomain[0, 1] = 0
disukwargs["idomain"] = idomain

sim = flopy.mf6.MFSimulation(
sim_name=name, version="mf6", exe_name=mf6, sim_ws=str(tmpdir)
sim_name=name,
version="mf6",
exe_name=mf6,
sim_ws=ws,
)
tdis = flopy.mf6.ModflowTdis(sim)
gwf = flopy.mf6.ModflowGwf(sim, modelname=name)
ims = flopy.mf6.ModflowIms(sim, print_option="SUMMARY")
disu = flopy.mf6.ModflowGwfdisu(gwf, **disukwargs)
ic = flopy.mf6.ModflowGwfic(gwf, strt=0.0)
npf = flopy.mf6.ModflowGwfnpf(gwf)
spd = {0: [[(0,), 1.0], [(nrow * ncol - 1,), 0.0]]}
spd = {0: [[(0,), 1.0], [(nrow * ncol - 1), 0.0]]}
chd = flopy.mf6.modflow.mfgwfchd.ModflowGwfchd(gwf, stress_period_data=spd)
sim.write_simulation()
sim.run_simulation()
return sim, None


def test_disu_idomain_simple(tmpdir, targets):
mf6 = targets["mf6"]
name = "disu01b"
nlay = 3
nrow = 3
ncol = 3
delr = 10.0 * np.ones(ncol)
delc = 10.0 * np.ones(nrow)
top = 0
botm = [-10, -20, -30]
idomain = np.ones(nlay * nrow * ncol, dtype=int)
idomain[1] = 0
disukwargs = get_disu_kwargs(nlay, nrow, ncol, delr, delc, top, botm)
disukwargs["idomain"] = idomain
sim = flopy.mf6.MFSimulation(
sim_name=name, version="mf6", exe_name=mf6, sim_ws=str(tmpdir)
)
tdis = flopy.mf6.ModflowTdis(sim)
gwf = flopy.mf6.ModflowGwf(sim, modelname=name, save_flows=True)
ims = flopy.mf6.ModflowIms(sim, print_option="SUMMARY")
disu = flopy.mf6.ModflowGwfdisu(gwf, **disukwargs)
ic = flopy.mf6.ModflowGwfic(gwf, strt=0.0)
npf = flopy.mf6.ModflowGwfnpf(gwf)
spd = {0: [[(0,), 1.0], [(nrow * ncol - 1,), 0.0]]}
chd = flopy.mf6.modflow.ModflowGwfchd(gwf, stress_period_data=spd)
oc = flopy.mf6.modflow.ModflowGwfoc(
gwf,
budget_filerecord=f"{name}.bud",
head_filerecord=f"{name}.hds",
saverecord=[("HEAD", "LAST"), ("BUDGET", "LAST")],
)
sim.write_simulation()
sim.run_simulation()
def eval_results(sim):
print("evaluating results...")

# check binary grid file
fname = os.path.join(str(tmpdir), name + ".disu.grb")
name = sim.name

fname = os.path.join(sim.simpath, name + ".disu.grb")
grbobj = flopy.mf6.utils.MfGrdFile(fname)
nodes = grbobj._datadict["NODES"]
ia = grbobj._datadict["IA"]
ja = grbobj._datadict["JA"]
assert nodes == disukwargs["nodes"]
assert np.array_equal(ia[0:4], np.array([1, 4, 4, 7]))
assert np.array_equal(ja[:6], np.array([1, 4, 10, 3, 6, 12]))
assert ia[-1] == 127
assert ia.shape[0] == 28, "ia should have size of 28"
assert ja.shape[0] == 126, "ja should have size of 126"

# load head array and ensure nodata value in second cell
fname = os.path.join(str(tmpdir), name + ".hds")
hdsobj = flopy.utils.HeadFile(fname)
head = hdsobj.get_alldata().flatten()
assert head[1] == 1.0e30
if sim.idxsim == 1:
assert np.array_equal(ia[0:4], np.array([1, 4, 4, 7]))
assert np.array_equal(ja[:6], np.array([1, 4, 10, 3, 6, 12]))
assert ia[-1] == 127
assert ia.shape[0] == 28, "ia should have size of 28"
assert ja.shape[0] == 126, "ja should have size of 126"


# load flowja to make sure it is the right size
fname = os.path.join(str(tmpdir), name + ".bud")
budobj = flopy.utils.CellBudgetFile(fname, precision="double")
flowja = budobj.get_data(text="FLOW-JA-FACE")[0].flatten()
assert flowja.shape[0] == 126
@pytest.mark.parametrize("idx, name", list(enumerate(ex)))
def test_mf6model(idx, name, function_tmpdir, targets):
ws = str(function_tmpdir)
sim, _ = build_model(idx, ws, targets.mf6)
sim.write_simulation()
sim.run_simulation()
test = TestFramework()
test.run(
TestSimulation(
name=name,
exe_dict=targets,
exfunc=eval_results,
idxsim=idx,
make_comparison=False,
),
ws,
)
106 changes: 106 additions & 0 deletions autotest/test_gwf_disv.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
"""
Test of GWF DISV Package. Use the flopy disv tool to create
a simple regular grid example, but using DISV instead of DIS.
Use a large offset for x and y vertices to ensure that the area
calculation in MODFLOW 6 is correct. For the second case, set
one of the cells inactive and test to make sure connectivity
in binary grid file is correct.

"""

import os

import flopy
import numpy as np
import pytest
from flopy.utils.gridutil import get_disv_kwargs

from framework import TestFramework
from simulation import TestSimulation

ex = ["disv01a", "disv01b"]


def build_model(idx, dir, mf6):
name = ex[idx]
ws = dir
nlay = 3
nrow = 3
ncol = 3
delr = 10.0
delc = 10.0
top = 0
botm = [-10, -20, -30]
xoff = 100000000.0
yoff = 100000000.0
disvkwargs = get_disv_kwargs(
nlay,
nrow,
ncol,
delr,
delc,
top,
botm,
xoff,
yoff,
)
if idx == 1:
# for the second test, set one cell to idomain = 0
idomain = np.ones((nlay, nrow * ncol), dtype=int)
idomain[0, 1] = 0
disvkwargs["idomain"] = idomain

sim = flopy.mf6.MFSimulation(
sim_name=name,
version="mf6",
exe_name=mf6,
sim_ws=ws,
)
tdis = flopy.mf6.ModflowTdis(sim)
gwf = flopy.mf6.ModflowGwf(sim, modelname=name)
ims = flopy.mf6.ModflowIms(sim, print_option="SUMMARY")
disv = flopy.mf6.ModflowGwfdisv(gwf, **disvkwargs)
ic = flopy.mf6.ModflowGwfic(gwf, strt=0.0)
npf = flopy.mf6.ModflowGwfnpf(gwf)
spd = {0: [[(0, 0), 1.0], [(0, nrow * ncol - 1), 0.0]]}
chd = flopy.mf6.modflow.mfgwfchd.ModflowGwfchd(gwf, stress_period_data=spd)
return sim, None


def eval_results(sim):
print("evaluating results...")

name = sim.name

fname = os.path.join(sim.simpath, name + ".disv.grb")
grbobj = flopy.mf6.utils.MfGrdFile(fname)
ncpl = grbobj._datadict["NCPL"]
ia = grbobj._datadict["IA"]
ja = grbobj._datadict["JA"]

if sim.idxsim == 1:
# assert ncpl == disvkwargs["ncpl"]
assert np.array_equal(ia[0:4], np.array([1, 4, 4, 7]))
assert np.array_equal(ja[:6], np.array([1, 4, 10, 3, 6, 12]))
assert ia[-1] == 127
assert ia.shape[0] == 28, "ia should have size of 28"
assert ja.shape[0] == 126, "ja should have size of 126"


@pytest.mark.parametrize("idx, name", list(enumerate(ex)))
def test_mf6model(idx, name, function_tmpdir, targets):
ws = str(function_tmpdir)
sim, _ = build_model(idx, ws, targets.mf6)
sim.write_simulation()
sim.run_simulation()
test = TestFramework()
test.run(
TestSimulation(
name=name,
exe_dict=targets,
exfunc=eval_results,
idxsim=idx,
make_comparison=False,
),
ws,
)
Loading