Skip to content

Reuse extrapolation weights for multiple variables#732

Open
trhille wants to merge 1 commit into
MPAS-Dev:masterfrom
trhille:landice/reuse_extrapolation_weights
Open

Reuse extrapolation weights for multiple variables#732
trhille wants to merge 1 commit into
MPAS-Dev:masterfrom
trhille:landice/reuse_extrapolation_weights

Conversation

@trhille
Copy link
Copy Markdown
Collaborator

@trhille trhille commented Jun 2, 2026

This merge calculates IDW weights during the first extrapolation of a variable across the MPAS domain when converting from a Albany exodus file and then reuses those weights for the extrapolation of subsequent variables. This eliminates the repeated wave-front search that can be slow on large meshes, replacing an effectively O(N^1.5) operation with O(N) operation.

Calculate extrapolation pattern only once, and reuse for extrapolation
of subsequent variables.
@trhille
Copy link
Copy Markdown
Collaborator Author

trhille commented Jun 2, 2026

Using these changes on a fairly small 4–40km GIS mesh (nCells = 55928), I get:

Time taken for extrapolation and smoothing muFriction: 15.169 seconds
Time taken for extrapolation and smoothing stiffnessFactor: 0.974 seconds

Without these changes:

Time taken for extrapolation and smoothing muFriction: 8.124 seconds
Time taken for extrapolation and smoothing stiffnessFactor: 14.412 seconds

(I ran this three times for each configuration. Times varied within about ±1.5s compared with those reported above.)
So, that's a large fractional savings, but a small absolute savings. However, as we go to larger meshes, this savings should become considerable. Here is Claude's estimate:

"The key is the algorithmic complexity of each approach:

Original (per variable): O(N × R), where R is the number of wave-front rings needed to fill all empty cells. For a 2D mesh, R ≈ √N (the "radius" of the extrapolation region in cells). So effectively O(N^1.5) — each of the 24 iterations scans all remaining empty cells (O(N)), and there are O(√N) such iterations.

Cached replay: A single ordered pass over all filled cells — O(N).

So the savings ratio grows as O(√N). Concretely:

image

For typical large Antarctic meshes (hundreds of thousands to millions of cells), the cache turns a multi-hour extrapolation into minutes for the second and third variables. The first variable still pays full cost — which itself grows as O(N^1.5) — so on very large meshes, the pattern-building step will also become a bottleneck."

@trhille trhille added the landice label Jun 2, 2026
@trhille
Copy link
Copy Markdown
Collaborator Author

trhille commented Jun 2, 2026

Testing

These changes yields BFB behavior with the current behavior in master for variables with min extrapolation (i.e., muFriction):
image

There are roundoff-level differences with the stiffnessFactor field, which uses IDW extrapolation, but these can be ignored:
image

@trhille trhille requested a review from matthewhoffman June 2, 2026 19:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant