Skip to content

Issue 2521 emit warning#2543

Open
fluidnumerics-joe wants to merge 5 commits intomainfrom
issue-2521-emit-warning
Open

Issue 2521 emit warning#2543
fluidnumerics-joe wants to merge 5 commits intomainfrom
issue-2521-emit-warning

Conversation

@fluidnumerics-joe
Copy link
Contributor

This PR adds a helper function to spatialhash.py to create a mask for degenerate cells. In the spatialhash initialization, this method is called for the case when the grid is an xgrid object with spherical mesh type. In the event any degenerate faces are found, a warning is emitted. This is related to the action items in #2521

Copy link
Member

@erikvansebille erikvansebille left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me. Just one suggestion below

degeneracy_count = np.sum(_find_degenerate_xgrid_faces(x, y, z))
if degeneracy_count > 0:
warnings.warn(
f"Grid contains {degeneracy_count} degenerate faces that span a large portion of the "
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any way we can provide more information? E.g. also list the IDs of the (first few) degenerate cells? It wil be cumbersome for users to find out which cells are degenerate

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point. I can surface that information

@VeckoTheGecko
Copy link
Contributor

Looks good from a code POV

@fluidnumerics-joe am i right to say that all incomplete meshes (i.e., where there are 0s in for lon and lat) will have these incomplete "genereate" cells and hence raise this warning?

Just good to know one way or another - we can't really detect whether these cells are in coastal regions or not anyway so there's a limit to what we can do

fluidnumerics-joe and others added 2 commits March 13, 2026 11:05
Co-authored-by: Nick Hodgskin <36369090+VeckoTheGecko@users.noreply.github.com>
Co-authored-by: Nick Hodgskin <36369090+VeckoTheGecko@users.noreply.github.com>
@fluidnumerics-joe
Copy link
Contributor Author

fluidnumerics-joe commented Mar 13, 2026

Looks good from a code POV

@fluidnumerics-joe am i right to say that all incomplete meshes (i.e., where there are 0s in for lon and lat) will have these incomplete "genereate" cells and hence raise this warning?

Just good to know one way or another - we can't really detect whether these cells are in coastal regions or not anyway so there's a limit to what we can do

In #2521 , it was indeed the case that the location of lat,lon = 0 locations corresponded to land cells and this mesh was "incomplete". these incomplete meshes will definitely have degenerate cells. In general, any face that is abnormally large in comparison to others will cause problems. Remember that we're constructing faces over the stencil [i:i+1,j:j+1] for lat and lon; if that face ends up spanning the entire grid, that will likely get picked up as a degenerate cell.

The best we could do, is filter out the degenerate cells in the hash table construction. This would prevent them from ever being used in a search and would guard against unnecessary large memory allocations.

After throwing the warning, I'm wondering if we would want to go ahead and filter these out and then construct the hash table. In this case, if a particle ever landed in a degenerate face, the spatial hashing search would just fail to find it.

Right now, we throw a warning and then an oom error will be thrown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Backlog

Development

Successfully merging this pull request may close these issues.

3 participants