Conversation
When interpolating from a higher-dimensional field to a field on a grid with Flat dimensions, the destination grid must have a stored coordinate for each Flat dimension where the source grid has size > 1. Without this, flatten_node strips the missing coordinates and FractionalIndices receives a tuple of the wrong size, causing a BoundsError. This adds an early validation check in interpolate! that produces a clear error message instead. Closes #5473 Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
| if topology(to_grid, d) === Flat && isnothing(to_coords[d]) && size(from_grid, d) > 1 | ||
| throw(ArgumentError( | ||
| "Cannot interpolate! to a field on a grid that is Flat in $name " * | ||
| "without a specified $name coordinate, because the source grid " * | ||
| "has size $(size(from_grid, d)) > 1 in that dimension. " * | ||
| "Specify $name on the destination grid.")) |
There was a problem hiding this comment.
Can this be caught with dispatch rather than if?
Also I don't think we should support interpolation to Flat dimensions from grids that have size==1, even though mathematically this is possible. Basically I think that interpolation of any kind to a Flat dimension should be disallowed, ie we only support Flat to Flat.
glwagner
left a comment
There was a problem hiding this comment.
I suggest tightening the error so that interpolation to Flat dimensions only works if the source grid dimension is also Flat. This should result in a simpler error condition.
I am also wondering if dispatch would work (but it might be too complex, so the if is better).
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #5474 +/- ##
==========================================
- Coverage 73.76% 73.74% -0.03%
==========================================
Files 402 402
Lines 22880 22887 +7
==========================================
Hits 16878 16878
- Misses 6002 6009 +7
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
| to_coords = (ξnode(1, 1, 1, to_grid, ℓ, ℓ, ℓ), | ||
| ηnode(1, 1, 1, to_grid, ℓ, ℓ, ℓ), | ||
| rnode(1, 1, 1, to_grid, ℓ, ℓ, ℓ)) |
There was a problem hiding this comment.
This is most likely not GPU-safe
Summary
interpolate!for cross-dimensionality interpolation (e.g., 3D field to a column field)Flatdimensions without stored coordinates and the source grid has size > 1 in those dimensions, throws a clearArgumentErrorinstead of a crypticBoundsErrorFlatdimension of the destination grid, e.g.,RectilinearGrid(size=Nz, x=0.5, y=0.5, z=(0, 1), topology=(Flat, Flat, Bounded))Closes #5473
Test plan
interpolate!from 3D to column grid with specified x, y coordinates produces correct resultsinterpolate!without coordinates throwsArgumentErrorwith helpful message🤖 Generated with Claude Code