Skip to content

Commit

Permalink
update(MFModel, UnstructuredGrid): updates to filter None type from i…
Browse files Browse the repository at this point in the history
…verts recarrays
  • Loading branch information
jlarsen-usgs committed Dec 6, 2021
1 parent b0b2223 commit 87d7e35
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 4 deletions.
53 changes: 53 additions & 0 deletions autotest/t080_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import os
import platform
import numpy as np

try:
from shapely.geometry import Polygon
Expand Down Expand Up @@ -128,5 +129,57 @@ def test_mfusg():
return


def test_usg_iverts():
iverts = [
[4, 3, 2, 1, 0, None],
[7, 0, 1, 6, 5, None],
[11, 10, 9, 8, 2, 3],
[1, 6, 13, 12, 8, 2],
[15, 14, 13, 6, 5, None],
[10, 9, 18, 17, 16, None],
[8, 12, 20, 19, 18, 9],
[22, 14, 13, 12, 20, 21],
[24, 17, 18, 19, 23, None],
[21, 20, 19, 23, 25, None]
]
verts = [
[0.0, 22.5],
[5.1072, 22.5],
[7.5, 24.0324],
[7.5, 30.0],
[0.0, 30.0],
[0.0, 7.5],
[4.684, 7.5],
[0.0, 15.0],
[14.6582, 21.588],
[22.5, 24.3766],
[22.5, 30.0],
[15.0, 30.0],
[15.3597, 8.4135],
[7.5, 5.6289],
[7.5, 0.0],
[0.0, 0.0],
[30.0, 30.0],
[30.0, 22.5],
[25.3285, 22.5],
[24.8977, 7.5],
[22.5, 5.9676],
[22.5, 0.0],
[15.0, 0.0],
[30.0, 7.5],
[30.0, 15.0],
[30.0, 0.0]
]

grid = flopy.discretization.UnstructuredGrid(
verts, iverts, ncpl=[len(iverts)]
)

iverts = grid.iverts
if any(None in l for l in iverts):
raise ValueError("None type should not be returned in iverts list")


if __name__ == "__main__":
test_mfusg()
test_usg_iverts()
7 changes: 4 additions & 3 deletions flopy/discretization/unstructuredgrid.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,8 @@ def nvert(self):

@property
def iverts(self):
return self._iverts
if self._iverts is not None:
return [list(filter((None).__ne__, i)) for i in self._iverts]

@property
def verts(self):
Expand Down Expand Up @@ -559,11 +560,11 @@ def _build_grid_geometry_info(self):
yvertices = []

# build xy vertex and cell center info
for iverts in self._iverts:
for iverts in self.iverts:

xcellvert = []
ycellvert = []
for ix in (iv for iv in iverts if iv is not None):
for ix in iverts:
xcellvert.append(vertexdict[ix][0])
ycellvert.append(vertexdict[ix][1])

Expand Down
2 changes: 1 addition & 1 deletion flopy/mf6/mfmodel.py
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,7 @@ def modelgrid(self):
xcenters = None
ycenters = None
else:
iverts = [list(i)[4:] for i in cell2d]
iverts = [list(filter((None).__ne__, i))[4:] for i in cell2d]
xcenters = dis.cell2d.array["xc"]
ycenters = dis.cell2d.array["yc"]
vertices = dis.vertices.array
Expand Down

0 comments on commit 87d7e35

Please sign in to comment.