Skip to content

Commit d465cfe

Browse files
committed
only one store_error call, add test case
1 parent 57a3cac commit d465cfe

3 files changed

Lines changed: 101 additions & 22 deletions

File tree

autotest/test_gwf_errors.py

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,85 @@ def test_disu_errors(function_tmpdir, targets):
242242
run_mf6_error(str(function_tmpdir), mf6, err_str)
243243

244244

245+
def run_mf6_normalized(ws, exe):
246+
"""Run mf6 and return (returncode, whitespace-normalized stdout)."""
247+
returncode, buff = run_mf6([exe], ws)
248+
return returncode, " ".join(" ".join(buff).split())
249+
250+
251+
def test_dis_passthrough_thickness_error(function_tmpdir, targets):
252+
"""A cell left with a nonpositive thickness beneath a vertical pass-through
253+
cell reports a single, self-explanatory THICKNESS <= 0 error that names the
254+
overlying cell and points at its IDOMAIN status."""
255+
mf6 = targets["mf6"]
256+
257+
nlay, nrow, ncol = 4, 1, 3
258+
botm = np.empty((nlay, nrow, ncol))
259+
botm[0] = 30.0
260+
botm[1] = 20.0
261+
botm[2] = 10.0
262+
botm[2, 0, 1] = 4.0 # stale BOTM on the pass-through cell, below layer 4
263+
botm[3] = 5.0
264+
idomain = np.ones((nlay, nrow, ncol), dtype=int)
265+
idomain[2, 0, 1] = -1 # vertical pass-through at layer 3, column 2
266+
267+
diskwargs = {
268+
"nlay": nlay,
269+
"nrow": nrow,
270+
"ncol": ncol,
271+
"top": 40.0,
272+
"botm": botm,
273+
"idomain": idomain,
274+
}
275+
sim = get_minimal_gwf_simulation(str(function_tmpdir), exe=mf6, diskwargs=diskwargs)
276+
sim.write_simulation()
277+
278+
returncode, output = run_mf6_normalized(str(function_tmpdir), mf6)
279+
assert returncode != 0, "mf6 should have failed on a nonpositive thickness"
280+
281+
# only the pass-through column fails ...
282+
assert "CELL (4,1,2) THICKNESS <= 0." in output
283+
assert "CELL (4,1,1)" not in output
284+
assert "CELL (4,1,3)" not in output
285+
# ... and the explanation is folded into that one numbered item
286+
assert "2. CELL (" not in output
287+
assert (
288+
"The top of this cell is the bottom elevation specified for the "
289+
"cell directly above it, cell (3,1,2)." in output
290+
)
291+
assert "inactive or a vertical pass-through cell (IDOMAIN <= 0)" in output
292+
assert "ERROR OCCURRED WHILE READING FILE 'test.dis'" in output
293+
294+
295+
def test_dis_thickness_error_without_passthrough_note(function_tmpdir, targets):
296+
"""An ordinary nonpositive thickness between two active cells names the
297+
overlying cell but does not mention pass-through cells."""
298+
mf6 = targets["mf6"]
299+
300+
diskwargs = {
301+
"nlay": 3,
302+
"nrow": 1,
303+
"ncol": 1,
304+
"top": 10.0,
305+
"botm": [5.0, 2.0, 4.0], # layer 3 bottom sits above layer 2 bottom
306+
}
307+
chdkwargs = {"stress_period_data": {0: [[(0, 0, 0), 5.0]]}}
308+
sim = get_minimal_gwf_simulation(
309+
str(function_tmpdir), exe=mf6, diskwargs=diskwargs, chdkwargs=chdkwargs
310+
)
311+
sim.write_simulation()
312+
313+
returncode, output = run_mf6_normalized(str(function_tmpdir), mf6)
314+
assert returncode != 0, "mf6 should have failed on a nonpositive thickness"
315+
316+
assert "CELL (3,1,1) THICKNESS <= 0." in output
317+
assert (
318+
"The top of this cell is the bottom elevation specified for the "
319+
"cell directly above it, cell (2,1,1)." in output
320+
)
321+
assert "pass-through" not in output
322+
323+
245324
def test_drn_options_error_file(function_tmpdir, targets):
246325
"""Errors in DRN options are reported for the DRN input file."""
247326
mf6 = targets["mf6"]

src/Model/Discretization/Dis.f90

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -394,19 +394,20 @@ subroutine grid_finalize(this)
394394
integer(I4B) :: nrsize
395395
real(DP) :: top
396396
real(DP) :: dz
397+
character(len=LINELENGTH) :: cellstr
397398
! -- formats
398399
character(len=*), parameter :: fmtdz = &
399400
"('CELL (',i0,',',i0,',',i0,') THICKNESS <= 0. ', &
400401
&'TOP, BOT: ',2(1pg24.15))"
401402
character(len=*), parameter :: fmtdzt = &
402-
"(4x,'The top of this cell is the bottom elevation specified for the ',&
403+
"('. The top of this cell is the bottom elevation specified for the ',&
403404
&'cell directly above it, cell (',i0,',',i0,',',i0,').')"
404405
character(len=*), parameter :: fmtdzi = &
405-
"(4x,'That cell is inactive or a vertical pass-through cell ',&
406-
&'(IDOMAIN <= 0); making a cell inactive does not change the geometry ',&
407-
&'of its neighboring cells. Set its BOTM so this cell has positive ',&
408-
&'thickness (for a pass-through cell, set its BOTM equal to the bottom ',&
409-
&'elevation of the cell above it, giving it negligible thickness).')"
406+
' That cell is inactive or a vertical pass-through cell (IDOMAIN <= &
407+
&0); making a cell inactive does not change the geometry of its &
408+
&neighboring cells. Set its BOTM so this cell has positive thickness &
409+
&(for a pass-through cell, set its BOTM equal to the bottom elevation &
410+
&of the cell above it, giving it negligible thickness).'
410411
character(len=*), parameter :: fmtnr = &
411412
"(/1x, 'The specified IDOMAIN results in a reduced number of cells.',&
412413
&/1x, 'Number of user nodes: ',I0,&
@@ -445,15 +446,14 @@ subroutine grid_finalize(this)
445446
if (dz <= DZERO) then
446447
n = n + 1
447448
write (errmsg, fmt=fmtdz) k, i, j, top, this%bot3d(j, i, k)
448-
call store_error(errmsg)
449449
if (k > 1) then
450-
write (errmsg, fmt=fmtdzt) k - 1, i, j
451-
call store_error(errmsg)
450+
write (cellstr, fmt=fmtdzt) k - 1, i, j
451+
errmsg = trim(errmsg)//trim(cellstr)
452452
if (this%idomain(j, i, k - 1) < 1) then
453-
write (errmsg, fmt=fmtdzi)
454-
call store_error(errmsg)
453+
errmsg = trim(errmsg)//fmtdzi
455454
end if
456455
end if
456+
call store_error(errmsg)
457457
end if
458458
end do
459459
end do

src/Model/Discretization/Disv.f90

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -397,19 +397,20 @@ subroutine grid_finalize(this)
397397
integer(I4B) :: node, noder, j, k
398398
real(DP) :: top
399399
real(DP) :: dz
400+
character(len=LINELENGTH) :: cellstr
400401
! -- formats
401402
character(len=*), parameter :: fmtdz = &
402403
"('CELL (',i0,',',i0,') THICKNESS <= 0. ', &
403404
&'TOP, BOT: ',2(1pg24.15))"
404405
character(len=*), parameter :: fmtdzt = &
405-
"(4x,'The top of this cell is the bottom elevation specified for the ',&
406+
"('. The top of this cell is the bottom elevation specified for the ',&
406407
&'cell directly above it, cell (',i0,',',i0,').')"
407408
character(len=*), parameter :: fmtdzi = &
408-
"(4x,'That cell is inactive or a vertical pass-through cell ',&
409-
&'(IDOMAIN <= 0); making a cell inactive does not change the geometry ',&
410-
&'of its neighboring cells. Set its BOTM so this cell has positive ',&
411-
&'thickness (for a pass-through cell, set its BOTM equal to the bottom ',&
412-
&'elevation of the cell above it, giving it negligible thickness).')"
409+
' That cell is inactive or a vertical pass-through cell (IDOMAIN <= &
410+
&0); making a cell inactive does not change the geometry of its &
411+
&neighboring cells. Set its BOTM so this cell has positive thickness &
412+
&(for a pass-through cell, set its BOTM equal to the bottom elevation &
413+
&of the cell above it, giving it negligible thickness).'
413414
character(len=*), parameter :: fmtnr = &
414415
"(/1x, 'The specified IDOMAIN results in a reduced number of cells.',&
415416
&/1x, 'Number of user nodes: ',I0,&
@@ -444,15 +445,14 @@ subroutine grid_finalize(this)
444445
dz = top - this%bot2d(j, k)
445446
if (dz <= DZERO) then
446447
write (errmsg, fmt=fmtdz) k, j, top, this%bot2d(j, k)
447-
call store_error(errmsg)
448448
if (k > 1) then
449-
write (errmsg, fmt=fmtdzt) k - 1, j
450-
call store_error(errmsg)
449+
write (cellstr, fmt=fmtdzt) k - 1, j
450+
errmsg = trim(errmsg)//trim(cellstr)
451451
if (this%idomain(j, k - 1) < 1) then
452-
write (errmsg, fmt=fmtdzi)
453-
call store_error(errmsg)
452+
errmsg = trim(errmsg)//fmtdzi
454453
end if
455454
end if
455+
call store_error(errmsg)
456456
end if
457457
end if
458458
end do

0 commit comments

Comments
 (0)