Skip to content

Commit 7ef9f37

Browse files
authored
chore: remove cvfdutil.gridlist_to_disv_gridprops function (#2667)
Close #2660, this function is deprecated and due for removal
1 parent ada6e63 commit 7ef9f37

5 files changed

Lines changed: 135 additions & 460 deletions

File tree

autotest/test_export.py

Lines changed: 52 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1788,51 +1788,51 @@ def test_vtk_export_disv1_model(function_tmpdir):
17881788
idomain=np.ones((nlay, nrow, ncol)),
17891789
)
17901790

1791-
with pytest.deprecated_call():
1792-
from flopy.utils.cvfdutil import gridlist_to_disv_gridprops
1793-
1794-
gridprops = gridlist_to_disv_gridprops([mg])
1795-
gridprops["top"] = 0
1796-
gridprops["botm"] = np.zeros((nlay, nrow * ncol), dtype=float) - 1
1797-
gridprops["nlay"] = nlay
1798-
1799-
disv = ModflowGwfdisv(gwf, **gridprops)
1800-
ic = ModflowGwfic(gwf, strt=10)
1801-
npf = ModflowGwfnpf(gwf)
1802-
1803-
# Export model without specifying packages_names parameter
1804-
# create the vtk output
1805-
gwf = sim.get_model()
1806-
vtkobj = Vtk(gwf, binary=False)
1807-
vtkobj.add_model(gwf)
1808-
f = function_tmpdir / "gwf.vtk"
1809-
vtkobj.write(f)
1810-
1811-
# load the output using the vtk standard library
1812-
gridreader = vtkUnstructuredGridReader()
1813-
gridreader.SetFileName(str(f))
1814-
gridreader.Update()
1815-
grid = gridreader.GetOutput()
1816-
1817-
# get the points
1818-
vtk_points = grid.GetPoints()
1819-
vtk_points = vtk_points.GetData()
1820-
vtk_points = vtk_to_numpy(vtk_points)
1821-
1822-
# get cell locations (ia format of point to cell relationship)
1823-
cell_locations = vtk_to_numpy(grid.GetCellLocationsArray())
1824-
cell_locations_answer = np.array([0, 8, 16, 24, 32, 40, 48, 56, 64])
1825-
print(f"Found cell locations {cell_locations} in vtk file.")
1826-
print(f"Expecting cell locations {cell_locations_answer}")
1827-
errmsg = "vtk cell locations do not match expected result."
1828-
assert np.allclose(cell_locations, cell_locations_answer), errmsg
1829-
1830-
cell_types = vtk_to_numpy(grid.GetCellTypesArray())
1831-
cell_types_answer = np.array(9 * [42])
1832-
print(f"Found cell types {cell_types} in vtk file.")
1833-
print(f"Expecting cell types {cell_types_answer}")
1834-
errmsg = "vtk cell types do not match expected result."
1835-
assert np.allclose(cell_types, cell_types_answer), errmsg
1791+
from flopy.utils.cvfdutil import get_disv_gridprops, gridlist_to_verts
1792+
1793+
verts, iverts = gridlist_to_verts([mg])
1794+
gridprops = get_disv_gridprops(verts, iverts)
1795+
gridprops["top"] = 0
1796+
gridprops["botm"] = np.zeros((nlay, nrow * ncol), dtype=float) - 1
1797+
gridprops["nlay"] = nlay
1798+
1799+
disv = ModflowGwfdisv(gwf, **gridprops)
1800+
ic = ModflowGwfic(gwf, strt=10)
1801+
npf = ModflowGwfnpf(gwf)
1802+
1803+
# Export model without specifying packages_names parameter
1804+
# create the vtk output
1805+
gwf = sim.get_model()
1806+
vtkobj = Vtk(gwf, binary=False)
1807+
vtkobj.add_model(gwf)
1808+
f = function_tmpdir / "gwf.vtk"
1809+
vtkobj.write(f)
1810+
1811+
# load the output using the vtk standard library
1812+
gridreader = vtkUnstructuredGridReader()
1813+
gridreader.SetFileName(str(f))
1814+
gridreader.Update()
1815+
grid = gridreader.GetOutput()
1816+
1817+
# get the points
1818+
vtk_points = grid.GetPoints()
1819+
vtk_points = vtk_points.GetData()
1820+
vtk_points = vtk_to_numpy(vtk_points)
1821+
1822+
# get cell locations (ia format of point to cell relationship)
1823+
cell_locations = vtk_to_numpy(grid.GetCellLocationsArray())
1824+
cell_locations_answer = np.array([0, 8, 16, 24, 32, 40, 48, 56, 64])
1825+
print(f"Found cell locations {cell_locations} in vtk file.")
1826+
print(f"Expecting cell locations {cell_locations_answer}")
1827+
errmsg = "vtk cell locations do not match expected result."
1828+
assert np.allclose(cell_locations, cell_locations_answer), errmsg
1829+
1830+
cell_types = vtk_to_numpy(grid.GetCellTypesArray())
1831+
cell_types_answer = np.array(9 * [42])
1832+
print(f"Found cell types {cell_types} in vtk file.")
1833+
print(f"Expecting cell types {cell_types_answer}")
1834+
errmsg = "vtk cell types do not match expected result."
1835+
assert np.allclose(cell_types, cell_types_answer), errmsg
18361836

18371837

18381838
@pytest.mark.mf6
@@ -2228,7 +2228,7 @@ def test_mf6_chd_shapefile_export_unstructured(function_tmpdir, use_pandas, spar
22282228

22292229
def disv_sim(name, tmpdir):
22302230
from flopy.discretization import StructuredGrid
2231-
from flopy.utils.cvfdutil import gridlist_to_disv_gridprops
2231+
from flopy.utils.cvfdutil import get_disv_gridprops, gridlist_to_verts
22322232

22332233
nlay, nrow, ncol = 3, 3, 3
22342234
mg = StructuredGrid(
@@ -2239,12 +2239,12 @@ def disv_sim(name, tmpdir):
22392239
idomain=np.ones((nlay, nrow, ncol)),
22402240
)
22412241

2242-
with pytest.deprecated_call():
2243-
gridprops = gridlist_to_disv_gridprops([mg])
2244-
gridprops["top"] = 0
2245-
ncpl = gridprops["ncpl"]
2246-
gridprops["botm"] = np.zeros((nlay, ncpl), dtype=float) - 1
2247-
gridprops["nlay"] = nlay
2242+
verts, iverts = gridlist_to_verts([mg])
2243+
gridprops = get_disv_gridprops(verts, iverts)
2244+
gridprops["top"] = 0
2245+
ncpl = gridprops["ncpl"]
2246+
gridprops["botm"] = np.zeros((nlay, ncpl), dtype=float) - 1
2247+
gridprops["nlay"] = nlay
22482248

22492249
sim = MFSimulation(sim_name=name, sim_ws=tmpdir, exe_name="mf6")
22502250
tdis = ModflowTdis(sim)

autotest/test_grid.py

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@
2323
from flopy.utils.cvfdutil import (
2424
area_of_polygon,
2525
centroid_of_polygon,
26-
gridlist_to_disv_gridprops,
2726
to_cvfd,
2827
)
28+
from flopy.utils.lgrutil import Lgr
2929
from flopy.utils.triangle import Triangle
3030
from flopy.utils.voronoi import VoronoiGrid
3131

@@ -1015,9 +1015,10 @@ def test_tocvfd3():
10151015
delc = 100.0 * np.ones(nrow)
10161016
tp = np.zeros((nrow, ncol))
10171017
bt = -100.0 * np.ones((nlay, nrow, ncol))
1018-
idomain = np.ones((nlay, nrow, ncol))
1019-
idomain[:, 2:5, 2:5] = 0
1020-
sg1 = StructuredGrid(delr=delr, delc=delc, top=tp, botm=bt, idomain=idomain)
1018+
# Create refine_mask: cells with value 0 will be refined
1019+
refine_mask = np.ones((nlay, nrow, ncol))
1020+
refine_mask[:, 2:5, 2:5] = 0
1021+
sg1 = StructuredGrid(delr=delr, delc=delc, top=tp, botm=bt)
10211022
# inner grid
10221023
nlay = 1
10231024
nrow = ncol = 9
@@ -1036,26 +1037,27 @@ def test_tocvfd3():
10361037
idomain=idomain,
10371038
)
10381039

1039-
with pytest.deprecated_call():
1040-
gridprops = gridlist_to_disv_gridprops([sg1, sg2])
1041-
assert "ncpl" in gridprops
1042-
assert "nvert" in gridprops
1043-
assert "vertices" in gridprops
1044-
assert "cell2d" in gridprops
1045-
1046-
ncpl = gridprops["ncpl"]
1047-
nvert = gridprops["nvert"]
1048-
vertices = gridprops["vertices"]
1049-
cell2d = gridprops["cell2d"]
1050-
assert ncpl == 121
1051-
assert nvert == 148
1052-
assert len(vertices) == nvert
1053-
assert len(cell2d) == 121
1054-
1055-
# spot check information for cell 28 (zero based)
1056-
answer = [28, 250.0, 150.0, 7, 38, 142, 143, 45, 46, 44, 38]
1057-
for i, j in zip(cell2d[28], answer):
1058-
assert i == j, f"{i} not equal {j}"
1040+
# Use Lgr class to create DISV grid from nested grids
1041+
lgr = Lgr.from_parent_grid(sg1, refine_mask, ncpp=3, ncppl=1)
1042+
gridprops = lgr.to_disv_gridprops()
1043+
assert "ncpl" in gridprops
1044+
assert "nvert" in gridprops
1045+
assert "vertices" in gridprops
1046+
assert "cell2d" in gridprops
1047+
1048+
ncpl = gridprops["ncpl"]
1049+
nvert = gridprops["nvert"]
1050+
vertices = gridprops["vertices"]
1051+
cell2d = gridprops["cell2d"]
1052+
assert ncpl == 121
1053+
assert nvert == 148 # Lgr includes hanging vertices and deduplicates vertices
1054+
assert len(vertices) == nvert
1055+
assert len(cell2d) == 121
1056+
1057+
# spot check information for cell 28 (zero based)
1058+
answer = [28, 250.0, 150.0, 6, 42, 142, 143, 43, 51, 50]
1059+
for i, j in zip(cell2d[28], answer):
1060+
assert i == j, f"{i} not equal {j}"
10591061

10601062

10611063
@requires_pkg("shapely")

0 commit comments

Comments
 (0)