Skip to content

Spatialhash regional spherical improvements#2744

Open
fluidnumericsJoe wants to merge 3 commits into
mainfrom
spatialhash-regional-spherical-improvements
Open

Spatialhash regional spherical improvements#2744
fluidnumericsJoe wants to merge 3 commits into
mainfrom
spatialhash-regional-spherical-improvements

Conversation

@fluidnumericsJoe

Copy link
Copy Markdown
Contributor

Description

This PR changes the spatialhash initialization for spherical mesh types. Previously the bounding box was set to the unit cube for spherical mesh types. However, spherical mesh types might be desirable for regional simulations (e.g. for improved accuracy in barycentric coordinates, dealing with regions close to the poles, or for leveraging built in unit conversions in Parcels velocity field interpolators).

The main problem with the unit cube for regional configurations is that the hash grid resolution is often far too coarse for a regional domain. This results in a high number of mesh cells being aligned with a single morton key. Calling spatialhash.query() then results in an abnormally high number of particle in cell checks.

This is remedied here by choosing the extents of the hash grid as the bounding cube (x,y,z) of the regional domain.

Checklist

  • Tests added
  • This PR targets the correct branch (main for normal development, v3-support for v3 support)

AI Disclosure

  • This PR contains AI-generated content.
    • I have tested any AI-generated content in my PR.
    • I take responsibility for any AI-generated content in my PR.
    • Describe how you used it (e.g., by pasting your prompt): Claude Code was used to identify and implement documentation changes.

When the mesh type is spherical, we now use the actual x,y,z bounding
box rather than the unit cube. For regional runs that leverage the
spherical barycentric coordinates and built in unit conversion in the
velocity field interpolators, this reduces the hit count per hash cell
and can improve the search time in the spatialhash.query()

Note that quantize_coordinates now clips in float space before casting to uint32.
This matters now that spherical queries can fall outside the hash-grid bounds
(previously impossible with the unit cube). A negative normalized value cast to
uint32 wraps to a huge number, which would have mapped below-range queries to the
top bin (with morton code 2^32) erroneously.

For spherical grids, points outside the regional box now quantize to edge bins
rather than interior bins. In this case, they either fail the exact Morton-key
match or are rejected by the point-in-cell check; either case results in the
same outcome as before (GRID_SEARCH_ERROR)
Tests for both points inside the domain and explicitly outside the domain
to confirm correct behavior for out of bounds PIC checks
@fluidnumericsJoe

Copy link
Copy Markdown
Contributor Author

I still need to test this out on the example you shared @erikvansebille, but wanted to get this in and make sure that existing tests all pass

@fluidnumericsJoe

Copy link
Copy Markdown
Contributor Author

looks like there's a few tests to clean up here.

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.

1 participant