Skip to content

Commit 7bce99e

Browse files
authored
fix(sim): fix nocheck simulation oprion (#2455)
1 parent e4e78b3 commit 7bce99e

File tree

5 files changed

+175
-4
lines changed

5 files changed

+175
-4
lines changed

autotest/test_gwf_bnd_nocheck.py

Lines changed: 160 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,160 @@
1+
"""
2+
Test to make sure that mf6 is failing with head-dependent boundary conditions with
3+
elevations below the bottom of the layer (only ghb and drain are tested). Also check
4+
that the no check option works with head-dependent boundary conditions with elevations
5+
less than the cell bottom.
6+
"""
7+
8+
import flopy
9+
import numpy as np
10+
import pytest
11+
from framework import TestFramework
12+
13+
xfail = [True, True, False, False]
14+
boundaries = ["ghb", "drn", "ghb", "drn"]
15+
check = [None, None, True, True]
16+
cases = [f"{bnd}{idx:02d}" for idx, bnd in enumerate(boundaries)]
17+
18+
19+
def build_models(idx, test):
20+
ws = test.workspace
21+
22+
bnd = boundaries[idx]
23+
24+
nlay, nrow, ncol = 2, 1, 1
25+
nper = 1
26+
perlen = [1.0]
27+
nstp = [1]
28+
tsmult = [1.0]
29+
delr = 1.0
30+
delc = 1.0
31+
top = 1.0
32+
botm = [0.0, -1.0]
33+
strt = 1
34+
hk = 1.0
35+
36+
tdis_rc = []
37+
for i in range(nper):
38+
tdis_rc.append((perlen[i], nstp[i], tsmult[i]))
39+
40+
name = cases[idx]
41+
42+
sim = flopy.mf6.MFSimulation(
43+
sim_name=name,
44+
version="mf6",
45+
exe_name="mf6",
46+
sim_ws=ws,
47+
nocheck=check[idx],
48+
)
49+
50+
tdis = flopy.mf6.ModflowTdis(
51+
sim,
52+
time_units="DAYS",
53+
nper=nper,
54+
perioddata=tdis_rc,
55+
)
56+
57+
gwf = flopy.mf6.ModflowGwf(
58+
sim,
59+
modelname=name,
60+
print_input=True,
61+
)
62+
63+
ims = flopy.mf6.ModflowIms(
64+
sim,
65+
print_option="SUMMARY",
66+
complexity="simple",
67+
outer_dvclose=1e-8,
68+
outer_maximum=200,
69+
inner_dvclose=1e-9,
70+
inner_maximum=100,
71+
)
72+
sim.register_ims_package(ims, [gwf.name])
73+
74+
dis = flopy.mf6.ModflowGwfdis(
75+
gwf,
76+
length_units="feet",
77+
nlay=nlay,
78+
nrow=nrow,
79+
ncol=ncol,
80+
delr=delr,
81+
delc=delc,
82+
top=top,
83+
botm=botm,
84+
)
85+
86+
ic = flopy.mf6.ModflowGwfic(gwf, strt=strt)
87+
88+
npf = flopy.mf6.ModflowGwfnpf(
89+
gwf,
90+
icelltype=1,
91+
k=hk,
92+
)
93+
94+
spd = [((1, 0, 0), strt)]
95+
chd = flopy.mf6.ModflowGwfchd(
96+
gwf,
97+
maxbound=len(spd),
98+
stress_period_data=spd,
99+
)
100+
101+
spd = [((0, 0, 0), botm[0] - 0.1, 1.0, "bc")]
102+
if bnd == "ghb":
103+
p = flopy.mf6.ModflowGwfghb(
104+
gwf,
105+
boundnames=True,
106+
maxbound=len(spd),
107+
stress_period_data=spd,
108+
)
109+
elif bnd == "drn":
110+
p = flopy.mf6.ModflowGwfdrn(
111+
gwf,
112+
boundnames=True,
113+
maxbound=len(spd),
114+
stress_period_data=spd,
115+
)
116+
obs_data = [
117+
("obs1", f"{bnd}", "bc"),
118+
]
119+
obs_name = "bnd.obs"
120+
p.obs.initialize(
121+
filename=obs_name,
122+
continuous={f"{obs_name}.csv": obs_data},
123+
)
124+
125+
oc = flopy.mf6.ModflowGwfoc(
126+
gwf,
127+
printrecord=[("BUDGET", "ALL"), ("HEAD", "ALL")],
128+
)
129+
130+
return sim, None
131+
132+
133+
def check_results(idx, test):
134+
if not xfail[idx]:
135+
ws = test.workspace
136+
sim = flopy.mf6.MFSimulation.load(sim_ws=ws)
137+
gwf = sim.get_model()
138+
139+
bnd = boundaries[idx]
140+
if bnd == "ghb":
141+
obs = gwf.ghb.output.obs().get_data()
142+
elif bnd == "drn":
143+
obs = gwf.drn.output.obs().get_data()
144+
v = obs[0][1]
145+
print(obs)
146+
answer = -0.55
147+
assert np.allclose(v, answer), f"boundary flux ({v}) not close to {answer}"
148+
149+
150+
@pytest.mark.parametrize("idx, name", enumerate(cases))
151+
def test_mf6model(idx, name, function_tmpdir, targets):
152+
test = TestFramework(
153+
name=name,
154+
workspace=function_tmpdir,
155+
targets=targets,
156+
build=lambda t: build_models(idx, t),
157+
check=lambda t: check_results(idx, t),
158+
xfail=xfail[idx],
159+
)
160+
test.run()

doc/ReleaseNotes/develop.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,3 +67,8 @@ description = "The Particle Tracking (PRT) Model previously reported cell exit e
6767
section = "fixes"
6868
subsection = "solution"
6969
description = "Previously the Particle Tracking (PRT) Model's generalized DISV tracking method did not distinguish subcell exit events from cell exits, reporting both with the same reason code (1). Since subcell exits occur at a scale below that defined by the model's grid discretization, they are an implementation detail of the generalized tracking method, and will therefore no longer be written by default to particle tracking output. The PRT Output Control (OC) package's TRACK\\_EXIT option will now apply exclusively to features at grid-scale or above. Writing particle transitions between sub-grid-scale features to output is now opt-in with a new keyword option TRACK\\_SUBFEATURE\\_EXIT."
70+
71+
[[items]]
72+
section = "fixes"
73+
subsection = "basic"
74+
description = "Previously the NOCHECK option was used to directly set the internal isimcheck variable. When NOCHECK is specified in the simulation name file isimcheck should be set to 0, otherwise isimcheck should be 1. The code has been fixed to implement the intended behaviour."

src/SimulationCreate.f90

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,9 +119,14 @@ subroutine options_create()
119119
!
120120
! -- update sim options
121121
isimcontinue = simcontinue
122-
isimcheck = nocheck
122+
if (nocheck == 1) then
123+
isimcheck = 0
124+
else
125+
isimcheck = 1
126+
end if
127+
123128
call MaxErrors(maxerror)
124-
!
129+
125130
if (prmem /= '') then
126131
errmsg = ''
127132
call mem_set_print_option(iout, prmem, errmsg)

src/Utilities/Idm/IdmLoad.f90

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -568,7 +568,7 @@ end subroutine simnam_load_dim
568568
!<
569569
subroutine allocate_simnam_int(input_mempath, idt)
570570
use MemoryManagerModule, only: mem_allocate
571-
use SimVariablesModule, only: isimcontinue, isimcheck, simfile
571+
use SimVariablesModule, only: isimcontinue, nocheck, simfile
572572
character(len=LENMEMPATH), intent(in) :: input_mempath
573573
type(InputParamDefinitionType), pointer, intent(in) :: idt
574574
integer(I4B), pointer :: intvar
@@ -580,7 +580,7 @@ subroutine allocate_simnam_int(input_mempath, idt)
580580
case ('CONTINUE')
581581
intvar = isimcontinue
582582
case ('NOCHECK')
583-
intvar = isimcheck
583+
intvar = nocheck
584584
case ('MAXERRORS')
585585
intvar = 1000 !< MessageType max_message
586586
case ('MXITER')

src/Utilities/SimVariables.f90

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ module SimVariablesModule
3333
integer(I4B) :: iout !< file unit number for simulation output
3434
integer(I4B) :: isimcnvg !< simulation convergence flag (1) if all objects have converged, (0) otherwise
3535
integer(I4B) :: isimcontinue = 0 !< simulation continue flag (1) to continue if isimcnvg = 0, (0) to terminate
36+
integer(I4B) :: nocheck = 0 !< nocheck option (0) to check input, (1) to ignore checks
3637
integer(I4B) :: isimcheck = 1 !< simulation input check flag (1) to check input, (0) to ignore checks
3738
integer(I4B) :: numnoconverge = 0 !< number of times the simulation did not converge
3839
integer(I4B) :: ireturnerr = 0 !< return code for program (0) successful, (1) non-convergence, (2) error

0 commit comments

Comments
 (0)