Deltares / dfm_tools

A Python package for pre- and postprocessing D-Flow FM model input and output files
https://deltares.github.io/dfm_tools/
GNU General Public License v3.0
70 stars 12 forks source link

merge circumcenters option? #812

Closed thopri closed 7 months ago

thopri commented 7 months ago

Hello,

I am using dfm_tools and adapting the model builder example to create a model configuration, this all works well unless the coastline is quite complicated, e.g. French coast on the English Channel. When trying to run the configuration I get the following error:

ERROR : 748 small flow links discarded. Run 'merge circumcenters' to remove small flow links or increase threshold

The merge circumcenters doesn't seem to be part of dfm_tools? I can only find references for the option in the delft3d GUI. The only solution I have found so far is to increase the cell size but this often ends with quite a large resolution before all the circumcenters are on longer too close together.

I can see that there is a threshold that can be increased? its not clear where to do this or if it is sensible to do so?

Any guidance would be appreciated.

veenstrajelmer commented 7 months ago

@lucacarniato would you have time to provide a meshkernel example for merge circumcenters?

thopri commented 7 months ago

Would the function "mkernel_mesh2d_delete_small_flow_edges_and_small_triangles";on this page

https://deltares.github.io/MeshKernel/namespacemeshkernelapi.html#a40a8202bcfaa2902b5d42aed1cec50bb

Be a solution?

veenstrajelmer commented 7 months ago

Hi @thopri, indeed, but you would need the meshkernelpy function mk.mesh2d_delete_small_flow_edges_and_small_triangles(): https://github.com/Deltares/MeshKernelPy/blob/ceba1501bd85ba56170a37665d4c5012019c614d/meshkernel/meshkernel.py#L992

Then you can just use the meshkernel instance generated by the dfm_tools modelbuilder code.

You would have to set sensible values for the two required parameters, my suggestion is to start with small_flow_edges_length_threshold=0.1 and min_fractional_area_triangles=0.2.

So something like this:

mk_object = dfmt.make_basegrid(lon_min, lon_max, lat_min, lat_max, dx=dxy, dy=dxy, crs=crs)
[do your refinement, cutting, etcetera]
mk_object.mesh2d_delete_small_flow_edges_and_small_triangles(
        small_flow_edges_length_threshold=0.1, 
        min_fractional_area_triangles=0.2)
lucacarniato commented 7 months ago

mk.mesh2d_delete_small_flow_edges_and_small_triangles is intended for deleting small flow edges. A representative flow edge length is computed from the square root of the average area of neighboring faces. The 'small_flow_edges_length_threshold' is used as a multiplier of this area for deleting the edges crossed by such small flow edges.

min_fractional_area_triangles is used as a multiplier of the average face area to determine triangles at the boundary which can be deleted.

thopri commented 7 months ago

Excellent thanks for the help, my model config now runs 😃