Skip to content

Commit

Permalink
test: test Vtk.to_pyvista() method, fmt test_grid.py
Browse files Browse the repository at this point in the history
  • Loading branch information
wpbonelli committed Apr 30, 2023
1 parent 7d55dc6 commit 608aae3
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 4 deletions.
30 changes: 30 additions & 0 deletions autotest/test_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -1265,6 +1265,36 @@ def test_vtk_unstructured(function_tmpdir, example_data_path):
assert np.allclose(np.ravel(top), top2), "Field data not properly written"


@requires_pkg("pyvista")
def test_vtk_to_pyvista(function_tmpdir, example_data_path):
from autotest.test_mp7_cases import Mp7Cases

case_mf6 = Mp7Cases.mf6(function_tmpdir)
success, buff = case_mf6.run_model()
assert success, f"MP7 model ({case_mf6.name}) failed"

gwf = case_mf6.flowmodel
plf = PathlineFile(Path(case_mf6.model_ws) / f"{case_mf6.name}.mppth")
pls = plf.get_alldata()

vtk = Vtk(model=gwf, binary=True, smooth=False)
assert not any(vtk.to_pyvista())

vtk.add_model(gwf)
grid = vtk.to_pyvista()
assert grid.n_cells == gwf.modelgrid.nnodes

vtk.add_pathline_points(pls)
grid, pathlines = vtk.to_pyvista()
n_pts = sum([pl.shape[0] for pl in pls])
assert pathlines.n_points == n_pts
assert pathlines.n_cells == n_pts + len(pls)

# uncomment to debug
# grid.plot()
# pathlines.plot()


@pytest.mark.mf6
@requires_pkg("vtk")
def test_vtk_vertex(function_tmpdir, example_data_path):
Expand Down
16 changes: 12 additions & 4 deletions autotest/test_grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -1037,7 +1037,9 @@ def test_structured_thickness(structured_grid):
thickness = structured_grid.cell_thickness
assert np.allclose(thickness, 5.0), "thicknesses != 5."

sat_thick = structured_grid.saturated_thickness(structured_grid.botm + 10.0)
sat_thick = structured_grid.saturated_thickness(
structured_grid.botm + 10.0
)
assert np.allclose(sat_thick, thickness), "saturated thicknesses != 5."

sat_thick = structured_grid.saturated_thickness(structured_grid.botm + 5.0)
Expand All @@ -1049,7 +1051,9 @@ def test_structured_thickness(structured_grid):
sat_thick = structured_grid.saturated_thickness(structured_grid.botm)
assert np.allclose(sat_thick, 0.0), "saturated thicknesses != 0."

sat_thick = structured_grid.saturated_thickness(structured_grid.botm - 100.0)
sat_thick = structured_grid.saturated_thickness(
structured_grid.botm - 100.0
)
assert np.allclose(sat_thick, 0.0), "saturated thicknesses != 0."


Expand Down Expand Up @@ -1082,10 +1086,14 @@ def test_unstructured_thickness(unstructured_grid):
)
assert np.allclose(sat_thick, thickness), "saturated thicknesses != 5."

sat_thick = unstructured_grid.saturated_thickness(unstructured_grid.botm + 5.0)
sat_thick = unstructured_grid.saturated_thickness(
unstructured_grid.botm + 5.0
)
assert np.allclose(sat_thick, thickness), "saturated thicknesses != 5."

sat_thick = unstructured_grid.saturated_thickness(unstructured_grid.botm + 2.5)
sat_thick = unstructured_grid.saturated_thickness(
unstructured_grid.botm + 2.5
)
assert np.allclose(sat_thick, 2.5), "saturated thicknesses != 2.5"

sat_thick = unstructured_grid.saturated_thickness(unstructured_grid.botm)
Expand Down

0 comments on commit 608aae3

Please sign in to comment.