Skip to content

Fix/2521 curvilinear pic spherical#2598

Merged
fluidnumericsJoe merged 3 commits intomainfrom
fix/2521-curvilinear-pic-spherical
Apr 28, 2026
Merged

Fix/2521 curvilinear pic spherical#2598
fluidnumericsJoe merged 3 commits intomainfrom
fix/2521-curvilinear-pic-spherical

Conversation

@fluidnumericsJoe
Copy link
Copy Markdown
Contributor

Description

This PR resolves #2521 . When mesh.type="spherical" for curvilinear grids, the spatial hash search is done on a 3-D cartesian grid where the lat,lon are mapped to x,y,z on the surface of a unit sphere. The previous particle-in-cell (PIC) check was being done still in lat-lon space. This required awkward contortions to handle the antimeridian; @noemieplanat uncovered another issue in the vicinity of the polar caps where lat,lon elements are essentially co-linear (nearly identical latitude) causing a failure in the particle lookup .

To more cleanly handle antimeridian and polar caps, this PR changes the PIC check for curvilinear grids with spherical mesh type to match what we do for unstructured grids with spherical mesh type. We map from lat,lon -> x,y,z and perform the search on the unit sphere. For each queried cell, we construct a local tangent plane on the unit sphere and project particle positions onto that plane in order to calculate their computational coordinates.

Checklist

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 tidy up my initial implementation of the PIC check for spherical mesh-types.

…ical"

When the mesh type is "spherical" for a curvilinear structured grid, we
now use a PIC check that maps the curvilinear cell to x,y,z space on the
unit sphere. Within the cell, we construct an orthonormal basis for the
cell using vectors that point between edge centers in the xsi and eta
directions. Particle positions are converted to x,y,z space and
projected onto the cell plane. This approach is identical to what is
done for unstructure "spherical" grids; it is robust across the polar
caps and across the antimeridians. This change removes the need for consistency
checking in the _xinterpolator.py for curvilinear grids for points in
the vicinity of the antimeridian
After the curvilinear PIC moved to a tangent-plane bilinear inverse, the
old "lat/lon-bilinear blend of corner lons reconstructs query lon" check
no longer holds. Replace it with a blend of corner 3D unit-sphere vectors,
renormalized onto the sphere, and compare the recovered lat/lon to the
query. Tolerance 1e-5 gives ~30x headroom over the worst observed error
(~3e-7) on the 1/4 degree NEMO test grid.
Copy link
Copy Markdown
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! Curious to see whether this new code impacts on performance, but we'll see that in the benchmarks, I guess?

One small comment below

Comment thread src/parcels/interpolators/_xinterpolators.py
@fluidnumericsJoe
Copy link
Copy Markdown
Contributor Author

@VeckoTheGecko - these failures seem unrelated to the changes in this PR; they only came in after merging with main. Looking into it, there's 502 errors showing up on attempts to retrieve data for tests...

@fluidnumericsJoe fluidnumericsJoe merged commit 4be7c1d into main Apr 28, 2026
23 of 29 checks passed
@fluidnumericsJoe fluidnumericsJoe deleted the fix/2521-curvilinear-pic-spherical branch April 28, 2026 17:43
@github-project-automation github-project-automation Bot moved this from Backlog to Done in Parcels development Apr 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

Out of memory error during initialization of hash table - CREG12 curvilinear grid

2 participants