Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
104 changes: 52 additions & 52 deletions autotest/test_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -1788,51 +1788,51 @@ def test_vtk_export_disv1_model(function_tmpdir):
idomain=np.ones((nlay, nrow, ncol)),
)

with pytest.deprecated_call():
from flopy.utils.cvfdutil import gridlist_to_disv_gridprops

gridprops = gridlist_to_disv_gridprops([mg])
gridprops["top"] = 0
gridprops["botm"] = np.zeros((nlay, nrow * ncol), dtype=float) - 1
gridprops["nlay"] = nlay

disv = ModflowGwfdisv(gwf, **gridprops)
ic = ModflowGwfic(gwf, strt=10)
npf = ModflowGwfnpf(gwf)

# Export model without specifying packages_names parameter
# create the vtk output
gwf = sim.get_model()
vtkobj = Vtk(gwf, binary=False)
vtkobj.add_model(gwf)
f = function_tmpdir / "gwf.vtk"
vtkobj.write(f)

# load the output using the vtk standard library
gridreader = vtkUnstructuredGridReader()
gridreader.SetFileName(str(f))
gridreader.Update()
grid = gridreader.GetOutput()

# get the points
vtk_points = grid.GetPoints()
vtk_points = vtk_points.GetData()
vtk_points = vtk_to_numpy(vtk_points)

# get cell locations (ia format of point to cell relationship)
cell_locations = vtk_to_numpy(grid.GetCellLocationsArray())
cell_locations_answer = np.array([0, 8, 16, 24, 32, 40, 48, 56, 64])
print(f"Found cell locations {cell_locations} in vtk file.")
print(f"Expecting cell locations {cell_locations_answer}")
errmsg = "vtk cell locations do not match expected result."
assert np.allclose(cell_locations, cell_locations_answer), errmsg

cell_types = vtk_to_numpy(grid.GetCellTypesArray())
cell_types_answer = np.array(9 * [42])
print(f"Found cell types {cell_types} in vtk file.")
print(f"Expecting cell types {cell_types_answer}")
errmsg = "vtk cell types do not match expected result."
assert np.allclose(cell_types, cell_types_answer), errmsg
from flopy.utils.cvfdutil import get_disv_gridprops, gridlist_to_verts

verts, iverts = gridlist_to_verts([mg])
gridprops = get_disv_gridprops(verts, iverts)
gridprops["top"] = 0
gridprops["botm"] = np.zeros((nlay, nrow * ncol), dtype=float) - 1
gridprops["nlay"] = nlay

disv = ModflowGwfdisv(gwf, **gridprops)
ic = ModflowGwfic(gwf, strt=10)
npf = ModflowGwfnpf(gwf)

# Export model without specifying packages_names parameter
# create the vtk output
gwf = sim.get_model()
vtkobj = Vtk(gwf, binary=False)
vtkobj.add_model(gwf)
f = function_tmpdir / "gwf.vtk"
vtkobj.write(f)

# load the output using the vtk standard library
gridreader = vtkUnstructuredGridReader()
gridreader.SetFileName(str(f))
gridreader.Update()
grid = gridreader.GetOutput()

# get the points
vtk_points = grid.GetPoints()
vtk_points = vtk_points.GetData()
vtk_points = vtk_to_numpy(vtk_points)

# get cell locations (ia format of point to cell relationship)
cell_locations = vtk_to_numpy(grid.GetCellLocationsArray())
cell_locations_answer = np.array([0, 8, 16, 24, 32, 40, 48, 56, 64])
print(f"Found cell locations {cell_locations} in vtk file.")
print(f"Expecting cell locations {cell_locations_answer}")
errmsg = "vtk cell locations do not match expected result."
assert np.allclose(cell_locations, cell_locations_answer), errmsg

cell_types = vtk_to_numpy(grid.GetCellTypesArray())
cell_types_answer = np.array(9 * [42])
print(f"Found cell types {cell_types} in vtk file.")
print(f"Expecting cell types {cell_types_answer}")
errmsg = "vtk cell types do not match expected result."
assert np.allclose(cell_types, cell_types_answer), errmsg


@pytest.mark.mf6
Expand Down Expand Up @@ -2228,7 +2228,7 @@ def test_mf6_chd_shapefile_export_unstructured(function_tmpdir, use_pandas, spar

def disv_sim(name, tmpdir):
from flopy.discretization import StructuredGrid
from flopy.utils.cvfdutil import gridlist_to_disv_gridprops
from flopy.utils.cvfdutil import get_disv_gridprops, gridlist_to_verts

nlay, nrow, ncol = 3, 3, 3
mg = StructuredGrid(
Expand All @@ -2239,12 +2239,12 @@ def disv_sim(name, tmpdir):
idomain=np.ones((nlay, nrow, ncol)),
)

with pytest.deprecated_call():
gridprops = gridlist_to_disv_gridprops([mg])
gridprops["top"] = 0
ncpl = gridprops["ncpl"]
gridprops["botm"] = np.zeros((nlay, ncpl), dtype=float) - 1
gridprops["nlay"] = nlay
verts, iverts = gridlist_to_verts([mg])
gridprops = get_disv_gridprops(verts, iverts)
gridprops["top"] = 0
ncpl = gridprops["ncpl"]
gridprops["botm"] = np.zeros((nlay, ncpl), dtype=float) - 1
gridprops["nlay"] = nlay

sim = MFSimulation(sim_name=name, sim_ws=tmpdir, exe_name="mf6")
tdis = ModflowTdis(sim)
Expand Down
50 changes: 26 additions & 24 deletions autotest/test_grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@
from flopy.utils.cvfdutil import (
area_of_polygon,
centroid_of_polygon,
gridlist_to_disv_gridprops,
to_cvfd,
)
from flopy.utils.lgrutil import Lgr
from flopy.utils.triangle import Triangle
from flopy.utils.voronoi import VoronoiGrid

Expand Down Expand Up @@ -1015,9 +1015,10 @@ def test_tocvfd3():
delc = 100.0 * np.ones(nrow)
tp = np.zeros((nrow, ncol))
bt = -100.0 * np.ones((nlay, nrow, ncol))
idomain = np.ones((nlay, nrow, ncol))
idomain[:, 2:5, 2:5] = 0
sg1 = StructuredGrid(delr=delr, delc=delc, top=tp, botm=bt, idomain=idomain)
# Create refine_mask: cells with value 0 will be refined
refine_mask = np.ones((nlay, nrow, ncol))
refine_mask[:, 2:5, 2:5] = 0
sg1 = StructuredGrid(delr=delr, delc=delc, top=tp, botm=bt)
# inner grid
nlay = 1
nrow = ncol = 9
Expand All @@ -1036,26 +1037,27 @@ def test_tocvfd3():
idomain=idomain,
)

with pytest.deprecated_call():
gridprops = gridlist_to_disv_gridprops([sg1, sg2])
assert "ncpl" in gridprops
assert "nvert" in gridprops
assert "vertices" in gridprops
assert "cell2d" in gridprops

ncpl = gridprops["ncpl"]
nvert = gridprops["nvert"]
vertices = gridprops["vertices"]
cell2d = gridprops["cell2d"]
assert ncpl == 121
assert nvert == 148
assert len(vertices) == nvert
assert len(cell2d) == 121

# spot check information for cell 28 (zero based)
answer = [28, 250.0, 150.0, 7, 38, 142, 143, 45, 46, 44, 38]
for i, j in zip(cell2d[28], answer):
assert i == j, f"{i} not equal {j}"
# Use Lgr class to create DISV grid from nested grids
lgr = Lgr.from_parent_grid(sg1, refine_mask, ncpp=3, ncppl=1)
gridprops = lgr.to_disv_gridprops()
assert "ncpl" in gridprops
assert "nvert" in gridprops
assert "vertices" in gridprops
assert "cell2d" in gridprops

ncpl = gridprops["ncpl"]
nvert = gridprops["nvert"]
vertices = gridprops["vertices"]
cell2d = gridprops["cell2d"]
assert ncpl == 121
assert nvert == 148 # Lgr includes hanging vertices and deduplicates vertices
assert len(vertices) == nvert
assert len(cell2d) == 121

# spot check information for cell 28 (zero based)
answer = [28, 250.0, 150.0, 6, 42, 142, 143, 43, 51, 50]
for i, j in zip(cell2d[28], answer):
assert i == j, f"{i} not equal {j}"


@requires_pkg("shapely")
Expand Down
Loading
Loading