Skip to content

Commit

Permalink
update more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mjreno authored and mjreno committed Mar 9, 2024
1 parent 54a07b1 commit d2d2fa4
Show file tree
Hide file tree
Showing 17 changed files with 375 additions and 151 deletions.
33 changes: 23 additions & 10 deletions autotest/test_gwf_exgmvr01.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
gwf 1 2 3 4 5 6 7 gwfgwf => 1 2 3 4 5 6 7
"""


import flopy
import numpy as np
import pytest
Expand All @@ -35,7 +34,7 @@
Kv = 20.0


def build_simulation(idx, sim_ws, sim_type="single"):
def build_simulation(idx, sim_ws, sim_type="single", netcdf=None):
name = cases[idx]
sim = flopy.mf6.MFSimulation(
sim_name=name,
Expand All @@ -62,15 +61,15 @@ def build_simulation(idx, sim_ws, sim_type="single"):
else:
gwf_types = ("left", "right")
for gwf_type in gwf_types:
gwf = build_gwf(sim, gwf_type=gwf_type)
gwf = build_gwf(sim, gwf_type=gwf_type, netcdf=netcdf)

if sim_type != "single":
build_exchanges(sim)

return sim


def build_gwf(sim, gwf_type="single"):
def build_gwf(sim, gwf_type="single", netcdf=None):
if gwf_type == "single":
nc = ncol
else:
Expand All @@ -92,10 +91,15 @@ def build_gwf(sim, gwf_type="single"):
delc=delc,
top=top,
botm=botm,
filename=f"{gwf_type}.nc" if netcdf else f"{gwf_type}.dis",
)

# initial conditions
ic = flopy.mf6.ModflowGwfic(gwf, strt=0.0)
ic = flopy.mf6.ModflowGwfic(
gwf,
strt=0.0,
filename=f"{gwf_type}.nc" if netcdf else f"{gwf_type}.ic",
)

# node property flow
npf = flopy.mf6.ModflowGwfnpf(
Expand All @@ -104,6 +108,7 @@ def build_gwf(sim, gwf_type="single"):
icelltype=0,
k=Kh,
k33=Kv,
filename=f"{gwf_type}.nc" if netcdf else f"{gwf_type}.npf",
)

# add chd to right edge
Expand All @@ -115,6 +120,7 @@ def build_gwf(sim, gwf_type="single"):
gwf,
stress_period_data=chdlist,
pname="chd_right",
filename=f"{gwf_type}.nc" if netcdf else f"{gwf_type}.chd",
)

# inject water into left edge
Expand All @@ -126,6 +132,7 @@ def build_gwf(sim, gwf_type="single"):
gwf,
stress_period_data=wellist,
pname="well_left",
filename=f"{gwf_type}.nc" if netcdf else f"{gwf_type}.wel",
)

# pak_data = [<rno> <cellid(ncelldim)> <rlen> <rwid> <rgrd> <rtp> <rbth> <rhk> <man> <ncon> <ustrf> <ndv> [<aux(naux)>] [<boundname>]]
Expand Down Expand Up @@ -266,10 +273,12 @@ def build_exchanges(sim):
)


def build_models(idx, test):
def build_models(idx, test, netcdf=None):
sim_ws = test.workspace / "mf6"
sim_base = build_simulation(idx, sim_ws)
sim = build_simulation(idx, test.workspace, sim_type="split")
sim_base = build_simulation(idx, sim_ws, netcdf=netcdf)
sim = build_simulation(
idx, test.workspace, sim_type="split", netcdf=netcdf
)
return sim, sim_base


Expand Down Expand Up @@ -297,13 +306,17 @@ def check_output(idx, test):


@pytest.mark.parametrize("idx, name", enumerate(cases))
def test_mf6model(idx, name, function_tmpdir, targets):
@pytest.mark.parametrize(
"netcdf", [0, pytest.param(1, marks=pytest.mark.netcdf)]
)
def test_mf6model(idx, name, function_tmpdir, targets, netcdf):
test = TestFramework(
name=name,
workspace=function_tmpdir,
targets=targets,
build=lambda t: build_models(idx, t),
build=lambda t: build_models(idx, t, netcdf),
check=lambda t: check_output(idx, t),
netcdf=netcdf,
compare=None,
)
test.run()
32 changes: 22 additions & 10 deletions autotest/test_gwf_exgmvr02.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
The "single" model is also constructed as a reference.
"""


import flopy
import numpy as np
import pytest
Expand Down Expand Up @@ -91,7 +90,7 @@ def make_sfr_data(sfr_cells, ireach_offset=0):
return pak_data, con_data


def build_gwf(sim, gwf_type="single"):
def build_gwf(sim, gwf_type="single", netcdf=None):
if gwf_type == "single":
nc = ncol
else: # left or right
Expand All @@ -113,10 +112,15 @@ def build_gwf(sim, gwf_type="single"):
delc=delc,
top=top,
botm=botm,
filename=f"{gwf_type}.nc" if netcdf else f"{gwf_type}.dis",
)

# initial conditions
ic = flopy.mf6.ModflowGwfic(gwf, strt=0.0)
ic = flopy.mf6.ModflowGwfic(
gwf,
strt=0.0,
filename=f"{gwf_type}.nc" if netcdf else f"{gwf_type}.ic",
)

# node property flow
npf = flopy.mf6.ModflowGwfnpf(
Expand All @@ -125,6 +129,7 @@ def build_gwf(sim, gwf_type="single"):
icelltype=0,
k=Kh,
k33=Kv,
filename=f"{gwf_type}.nc" if netcdf else f"{gwf_type}.npf",
)

# add chd to right edge
Expand All @@ -134,6 +139,7 @@ def build_gwf(sim, gwf_type="single"):
gwf,
stress_period_data=chdlist,
pname="chd_right",
filename=f"{gwf_type}.nc" if netcdf else f"{gwf_type}.chd",
)

left_sfr1 = [(0, 1, icol) for icol in range(ncol_split)]
Expand Down Expand Up @@ -275,7 +281,7 @@ def build_exchanges(sim):
)


def build_simulation(idx, sim_ws, sim_type="single"):
def build_simulation(idx, sim_ws, sim_type="single", netcdf=None):
name = cases[idx]
sim = flopy.mf6.MFSimulation(
sim_name=name,
Expand All @@ -302,18 +308,20 @@ def build_simulation(idx, sim_ws, sim_type="single"):
else:
gwf_types = ("left", "right")
for gwf_type in gwf_types:
gwf = build_gwf(sim, gwf_type=gwf_type)
gwf = build_gwf(sim, gwf_type=gwf_type, netcdf=netcdf)

if sim_type != "single":
build_exchanges(sim)

return sim


def build_models(idx, test):
def build_models(idx, test, netcdf=None):
sim_ws = test.workspace / "mf6"
sim_base = build_simulation(idx, sim_ws)
sim = build_simulation(idx, test.workspace, sim_type="split")
sim_base = build_simulation(idx, sim_ws, netcdf=netcdf)
sim = build_simulation(
idx, test.workspace, sim_type="split", netcdf=netcdf
)
return sim, sim_base


Expand Down Expand Up @@ -343,13 +351,17 @@ def check_output(idx, test):


@pytest.mark.parametrize("idx, name", enumerate(cases))
def test_mf6model(idx, name, function_tmpdir, targets):
@pytest.mark.parametrize(
"netcdf", [0, pytest.param(1, marks=pytest.mark.netcdf)]
)
def test_mf6model(idx, name, function_tmpdir, targets, netcdf):
test = TestFramework(
name=name,
workspace=function_tmpdir,
targets=targets,
build=lambda t: build_models(idx, t),
build=lambda t: build_models(idx, t, netcdf),
check=lambda t: check_output(idx, t),
netcdf=netcdf,
compare=None,
)
test.run()
74 changes: 56 additions & 18 deletions autotest/test_gwf_ifmod_idomain.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@
chd_spd_right = {0: rchd_right}


def get_model(idx, dir):
def get_model(idx, dir, netcdf=None):
name = cases[idx]

# parameters and spd
Expand Down Expand Up @@ -142,18 +142,18 @@ def get_model(idx, dir):
)

# the full gwf model as a reference
add_refmodel(sim)
add_refmodel(sim, netcdf)

# now add two coupled models with the interface model enabled,
# to be stored in the same solution as the reference model
add_leftmodel(sim)
add_rightmodel(sim)
add_leftmodel(sim, netcdf)
add_rightmodel(sim, netcdf)
add_gwfexchange(sim)

return sim


def add_refmodel(sim):
def add_refmodel(sim, netcdf=None):
global mname_ref
global nlay, nrow, ncol
global idomain
Expand All @@ -177,21 +177,31 @@ def add_refmodel(sim):
top=tops[0],
botm=tops[1:],
idomain=idomain,
filename=f"{mname_ref}.nc" if netcdf else f"{mname_ref}.dis",
)

# initial conditions
ic = flopy.mf6.ModflowGwfic(gwf, strt=h_start)
ic = flopy.mf6.ModflowGwfic(
gwf,
strt=h_start,
filename=f"{mname_ref}.nc" if netcdf else f"{mname_ref}.ic",
)

# node property flow
npf = flopy.mf6.ModflowGwfnpf(
gwf,
save_specific_discharge=True,
icelltype=0,
k=hk,
filename=f"{mname_ref}.nc" if netcdf else f"{mname_ref}.npf",
)

# chd file
chd = flopy.mf6.ModflowGwfchd(gwf, stress_period_data=chd_spd)
chd = flopy.mf6.ModflowGwfchd(
gwf,
stress_period_data=chd_spd,
filename=f"{mname_ref}.nc" if netcdf else f"{mname_ref}.chd",
)

# output control
oc = flopy.mf6.ModflowGwfoc(
Expand All @@ -205,7 +215,7 @@ def add_refmodel(sim):
return gwf


def add_leftmodel(sim):
def add_leftmodel(sim, netcdf=None):
global mname_left
global nlay, nrow, ncol_left
global idomain_left
Expand All @@ -226,16 +236,26 @@ def add_leftmodel(sim):
top=tops[0],
botm=tops[1:],
idomain=idomain_left,
filename=f"{mname_left}.nc" if netcdf else f"{mname_left}.dis",
)
ic = flopy.mf6.ModflowGwfic(
gwf,
strt=h_start,
filename=f"{mname_left}.nc" if netcdf else f"{mname_left}.ic",
)
ic = flopy.mf6.ModflowGwfic(gwf, strt=h_start)
npf = flopy.mf6.ModflowGwfnpf(
gwf,
save_specific_discharge=True,
save_flows=True,
icelltype=0,
k=hk,
filename=f"{mname_left}.nc" if netcdf else f"{mname_left}.npf",
)
chd = flopy.mf6.ModflowGwfchd(
gwf,
stress_period_data=chd_spd_left,
filename=f"{mname_left}.nc" if netcdf else f"{mname_left}.chd",
)
chd = flopy.mf6.ModflowGwfchd(gwf, stress_period_data=chd_spd_left)
oc = flopy.mf6.ModflowGwfoc(
gwf,
head_filerecord=f"{mname_left}.hds",
Expand All @@ -247,7 +267,7 @@ def add_leftmodel(sim):
return gwf


def add_rightmodel(sim):
def add_rightmodel(sim, netcdf=None):
global mname_right
global nlay, nrow, ncol_right
global idomain_right
Expand All @@ -271,12 +291,26 @@ def add_rightmodel(sim):
top=tops[0],
botm=tops[1:],
idomain=idomain_right,
filename=f"{mname_right}.nc" if netcdf else f"{mname_right}.dis",
)
ic = flopy.mf6.ModflowGwfic(
gwf,
strt=h_start,
filename=f"{mname_right}.nc" if netcdf else f"{mname_right}.ic",
)
ic = flopy.mf6.ModflowGwfic(gwf, strt=h_start)
npf = flopy.mf6.ModflowGwfnpf(
gwf, save_specific_discharge=True, save_flows=True, icelltype=0, k=hk
gwf,
save_specific_discharge=True,
save_flows=True,
icelltype=0,
k=hk,
filename=f"{mname_right}.nc" if netcdf else f"{mname_right}.npf",
)
chd = flopy.mf6.ModflowGwfchd(
gwf,
stress_period_data=chd_spd_right,
filename=f"{mname_right}.nc" if netcdf else f"{mname_right}.chd",
)
chd = flopy.mf6.ModflowGwfchd(gwf, stress_period_data=chd_spd_right)
oc = flopy.mf6.ModflowGwfoc(
gwf,
head_filerecord=f"{mname_right}.hds",
Expand Down Expand Up @@ -325,8 +359,8 @@ def add_gwfexchange(sim):
)


def build_models(idx, test):
sim = get_model(idx, test.workspace)
def build_models(idx, test, netcdf=None):
sim = get_model(idx, test.workspace, netcdf)
return sim, None


Expand Down Expand Up @@ -374,13 +408,17 @@ def check_output(idx, test):


@pytest.mark.parametrize("idx, name", enumerate(cases))
@pytest.mark.parametrize(
"netcdf", [0, pytest.param(1, marks=pytest.mark.netcdf)]
)
@pytest.mark.developmode
def test_mf6model(idx, name, function_tmpdir, targets):
def test_mf6model(idx, name, function_tmpdir, targets, netcdf):
test = TestFramework(
name=name,
workspace=function_tmpdir,
build=lambda t: build_models(idx, t),
build=lambda t: build_models(idx, t, netcdf),
check=lambda t: check_output(idx, t),
targets=targets,
netcdf=netcdf,
)
test.run()
Loading

0 comments on commit d2d2fa4

Please sign in to comment.