Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

invert_deletion behaviour changed since meshkernel 5.0.0 #189

Open
veenstrajelmer opened this issue Sep 16, 2024 · 1 comment
Open

invert_deletion behaviour changed since meshkernel 5.0.0 #189

veenstrajelmer opened this issue Sep 16, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@veenstrajelmer
Copy link
Collaborator

veenstrajelmer commented Sep 16, 2024

Describe the bug
In meshkernelpy 4.3.0 the invert_deletion keyword for mk.mesh2d_delete() caused inverse behaviour of the deletion. With meshkernel 5.0.0 this behaviour seems mixed.

To Reproduce
Testcase bases on tests/dflowfm/test_net.py::test_create_clip_2d from hydrolib-core:

import numpy as np
from meshkernel import DeleteMeshOption, GeometryList, MeshKernel, MakeGridParameters
import matplotlib.pyplot as plt
# plt.close("all")

# fails, work if we swap the expected values
deletemeshoption, inside, nnodes, nedgenodes, nfaces = DeleteMeshOption.INSIDE_NOT_INTERSECTED, False, 22, 68, 13
# deletemeshoption, inside, nnodes, nedgenodes, nfaces = DeleteMeshOption.INSIDE_AND_INTERSECTED, False, 30, 98, 20

# works
# deletemeshoption, inside, nnodes, nedgenodes, nfaces = DeleteMeshOption.INSIDE_NOT_INTERSECTED, True, 33, 100, 19
# deletemeshoption, inside, nnodes, nedgenodes, nfaces = DeleteMeshOption.INSIDE_AND_INTERSECTED, True, 20, 62, 12

polygon = GeometryList(
    x_coordinates=np.array([0.0, 6.0, 4.0, 2.0, 0.0]),
    y_coordinates=np.array([0.0, 2.0, 7.0, 6.0, 0.0]),
)

# Define polygon
bbox = (1.0, -2.0, 3.0, 4.0)
dx=0.5
dy=0.75
mk = MeshKernel()

xmin, ymin, xmax, ymax = bbox

rows = int((ymax - ymin) / dy)
columns = int((xmax - xmin) / dx)

params = MakeGridParameters(
    num_columns=columns,
    num_rows=rows,
    origin_x=xmin,
    origin_y=ymin,
    block_size_x=dx,
    block_size_y=dy,
)
mk.curvilinear_compute_rectangular_grid(params)
mk.curvilinear_convert_to_mesh2d()

mesh2d_orig = mk.mesh2d_get()

mk.mesh2d_delete(
    geometry_list=polygon,
    delete_option=deletemeshoption,
    invert_deletion=not inside,
)
mesh2d_output = mk.mesh2d_get()

fig,ax = plt.subplots()
mesh2d_orig.plot_edges(ax=ax, color='grey')
mesh2d_output.plot_edges(ax=ax)
ax.plot(polygon.x_coordinates, polygon.y_coordinates, "r-")
ax.set_title(f"deletemeshoption={deletemeshoption.name} | invert_deletion={not inside}")

assert mesh2d_output.node_x.size == nnodes
assert mesh2d_output.edge_nodes.size == nedgenodes  # 2x nedges
assert mesh2d_output.face_x.size == nfaces

Figures for INSIDE_NOT_INTERSECTED
image
(expected)
image
(not the inverse of the figure above)

Figures for INSIDE_AND_INTERSECTED
image
(expected)
image
(not the inverse of the figure above)

Expected behavior
invert_deletion results in een invert of the resulting mesh. At the moment they seem to be mixed. The behaviour has changed compared to 4.3.0.

Version info (please complete the following information):

  • OS: Windows
  • Version 5.0.0
@veenstrajelmer
Copy link
Collaborator Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant