Skip to content

Commit

Permalink
fix(mp7particledata): fix get_extent() vertical extent calculation (m…
Browse files Browse the repository at this point in the history
…odflowpy#2307)

Vertical extent is miscalculated for structured grids when providing a cell index, only the first layer is handled properly. This causes bad results from *ParticleData.to_coords() and .to_prp().
  • Loading branch information
wpbonelli authored Sep 12, 2024
1 parent 40a600c commit a0e9219
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
15 changes: 15 additions & 0 deletions autotest/test_particledata.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
ParticleGroupLRCTemplate,
ParticleGroupNodeTemplate,
)
from flopy.modpath.mp7particledata import get_extent
from flopy.modpath.mp7particlegroup import ParticleGroup
from flopy.utils.modpathfile import EndpointFile, PathlineFile

Expand All @@ -47,6 +48,20 @@ def flatten(a):
]


# test get_extent()


def test_get_extent_structured_multilayer():
grid = GridCases().structured_small()
i, j = 1, 2
for k in range(grid.nlay):
extent = get_extent(grid, k=k, i=i, j=j)
assert extent.minz == grid.botm[k, i, j]
assert extent.maxz == (
grid.top[i, j] if k == 0 else grid.botm[k - 1, i, j]
)


# test initializers


Expand Down
9 changes: 8 additions & 1 deletion flopy/modpath/mp7particledata.py
Original file line number Diff line number Diff line change
Expand Up @@ -809,7 +809,14 @@ def get_extent(grid, k=None, i=None, j=None, nn=None, localz=False) -> Extent:
# get cell coords and span in each dimension
if not (k is None or i is None or j is None):
verts = grid.get_cell_vertices(i, j)
minz, maxz = (0, 1) if localz else (grid.botm[k, i, j], grid.top[i, j])
minz, maxz = (
(0, 1)
if localz
else (
grid.botm[k, i, j],
grid.top[i, j] if k == 0 else grid.botm[k - 1, i, j],
)
)
elif nn is not None:
verts = grid.get_cell_vertices(nn)
if grid.grid_type == "structured":
Expand Down

0 comments on commit a0e9219

Please sign in to comment.