Skip to content

mk3: mesh deletion with polygon performance was significantly reduced #103

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

Closed
veenstrajelmer opened this issue Oct 20, 2023 · 0 comments · Fixed by Deltares/MeshKernel#246
Labels
bug Something isn't working

Comments

@veenstrajelmer
Copy link
Collaborator

veenstrajelmer commented Oct 20, 2023

Describe the bug
The performance of mesh deletion was significantly reduced. In mk2 the ALL_FACE_CIRCUMCENTERS was used and in mk3 there is the new INSIDE_NOT_INTERSECTED. This is 16 to 70 times as slow, timings are in the comments at the lon/lat min/max values.

To Reproduce
This is a dfm_tools testcase, so not standalone. This is because it is a realistic usecase.

import dfm_tools as dfmt
import numpy as np
import meshkernel
import datetime as dt

lon_min,lon_max,lat_min,lat_max = -6,2,48.5,51.2 # mk2 5.8 sec, mk3 403.9 sec
# lon_min,lon_max,lat_min,lat_max = -2,2,48.5,49.2 # mk2 1.07 sec, mk3 16.27 sec
dxy = 0.2

# generate a simple rectangular grid of 4480 cells
mk = dfmt.make_basegrid(lon_min, lon_max, lat_min, lat_max, dx=dxy, dy=dxy)

# remove cells with custom ldb_gdf (can also come from polyfile)
bbox = (lon_min, lat_min, lon_max, lat_max)
coastlines_gdf = dfmt.get_coastlines_gdb(bbox=bbox, res='h')

print('>> deleting grid with coastlines: ',end='')
dtstart = dt.datetime.now()

for coastline_geom in coastlines_gdf['geometry']:
    xx, yy = coastline_geom.exterior.coords.xy
    xx = np.array(xx)
    yy = np.array(yy)
    try:
        delete_option = meshkernel.DeleteMeshOption.INSIDE_NOT_INTERSECTED # mk 3.0.0
    except AttributeError:
        delete_option = meshkernel.DeleteMeshOption.ALL_FACE_CIRCUMCENTERS # mk 2.1.0
    
    delete_pol_geom = meshkernel.GeometryList(x_coordinates=xx, y_coordinates=yy)
    mk.mesh2d_delete(geometry_list=delete_pol_geom, 
                     delete_option=delete_option,
                     invert_deletion=False)

print(f'{(dt.datetime.now()-dtstart).total_seconds():.2f} sec')

Expected behavior
Better performance.

Version info (please complete the following information):

  • OS: [e.g. Windows]
  • Version mk 2.1.0 and 3.0.0

Additional context
Add any other context about the problem here.

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

Successfully merging a pull request may close this issue.

2 participants