Skip to content

Commit

Permalink
Modify to allow mf6 autotest to pass
Browse files Browse the repository at this point in the history
  • Loading branch information
langevin-usgs committed Nov 21, 2023
1 parent 78d67c9 commit 47b080f
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 31 deletions.
2 changes: 1 addition & 1 deletion autotest/test_gridutil.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def test_get_lni_infers_layer_count_when_int_ncpl(ncpl, nodes, expected):
)
def test_get_disu_kwargs(nlay, nrow, ncol, delr, delc, tp, botm):
kwargs = get_disu_kwargs(
nlay=nlay, nrow=nrow, ncol=ncol, delr=delr, delc=delc, tp=tp, botm=botm
nlay=nlay, nrow=nrow, ncol=ncol, delr=delr, delc=delc, tp=tp, botm=botm, return_vertices=True
)

from pprint import pprint
Expand Down
65 changes: 35 additions & 30 deletions flopy/utils/gridutil.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ def get_disu_kwargs(
delc,
tp,
botm,
return_vertices=False,
):
"""
Create args needed to construct a DISU package for a regular
Expand All @@ -89,6 +90,8 @@ def get_disu_kwargs(
Top elevation(s) of cells in the model's top layer
botm : numpy.ndarray
Bottom elevation(s) for each layer
return_vertices: bool
If true, then include vertices and cell2d in kwargs
"""

def get_nn(k, i, j):
Expand Down Expand Up @@ -178,37 +181,39 @@ def get_nn(k, i, j):
hwva = np.array(hwva, dtype=float)

# build vertices
xv = np.cumsum(delr)
xv = np.array([0] + list(xv))
ymax = delc.sum()
yv = np.cumsum(delc)
yv = ymax - np.array([0] + list(yv))
xmg, ymg = np.meshgrid(xv, yv)
nvert = xv.shape[0] * yv.shape[0]
verts = np.array(list(zip(xmg.flatten(), ymg.flatten())))
vertices = []
for i in range(nvert):
vertices.append((i, verts[i, 0], verts[i, 1]))

cell2d = []
icell = 0
for k in range(nlay):
for i in range(nrow):
for j in range(ncol):
iv0 = j + i * (ncol + 1) # upper left vertex
iv1 = iv0 + 1 # upper right vertex
iv3 = iv0 + ncol + 1 # lower left vertex
iv2 = iv3 + 1 # lower right vertex
iverts = [iv0, iv1, iv2, iv3]
vlist = [(verts[iv, 0], verts[iv, 1]) for iv in iverts]
xc, yc = centroid_of_polygon(vlist)
cell2d.append([icell, xc, yc, len(iverts)] + iverts)
icell += 1
nvert = None
if return_vertices:
xv = np.cumsum(delr)
xv = np.array([0] + list(xv))
ymax = delc.sum()
yv = np.cumsum(delc)
yv = ymax - np.array([0] + list(yv))
xmg, ymg = np.meshgrid(xv, yv)
nvert = xv.shape[0] * yv.shape[0]
verts = np.array(list(zip(xmg.flatten(), ymg.flatten())))
vertices = []
for i in range(nvert):
vertices.append((i, verts[i, 0], verts[i, 1]))

cell2d = []
icell = 0
for k in range(nlay):
for i in range(nrow):
for j in range(ncol):
iv0 = j + i * (ncol + 1) # upper left vertex
iv1 = iv0 + 1 # upper right vertex
iv3 = iv0 + ncol + 1 # lower left vertex
iv2 = iv3 + 1 # lower right vertex
iverts = [iv0, iv1, iv2, iv3]
vlist = [(verts[iv, 0], verts[iv, 1]) for iv in iverts]
xc, yc = centroid_of_polygon(vlist)
cell2d.append([icell, xc, yc, len(iverts)] + iverts)
icell += 1

kw = {}
kw["nodes"] = nodes
kw["nja"] = nja
kw["nvert"] = None
kw["nvert"] = nvert
kw["top"] = top
kw["bot"] = bot
kw["area"] = area
Expand All @@ -217,9 +222,9 @@ def get_nn(k, i, j):
kw["ihc"] = ihc
kw["cl12"] = cl12
kw["hwva"] = hwva
kw["nvert"] = nvert
kw["vertices"] = vertices
kw["cell2d"] = cell2d
if return_vertices:
kw["vertices"] = vertices
kw["cell2d"] = cell2d
return kw


Expand Down

0 comments on commit 47b080f

Please sign in to comment.