Skip to content

place_surface: _sheet_distance's per-triangle loop is the placement bottleneck once sheets are resampled fine #613

Description

@lmoresi

The resampler (place_sheet(size=), 925b34f) broke _sheet_distance's design assumption — its docstring says "the sheet is small (hundreds of triangles) and the mesh is what is large". Measured on the just-short-of-surface megathrust (blind 5 km at 2 km cells, 1.19M-cell adapted shell, sheet resampled to ~16k triangles): place_sheet took 3,705 s, of which _sheet_distance was 3,217 s across 4 calls — a per-triangle Python loop, each iteration vectorised over every mesh vertex, ~16k x ~1M point-triangle tests per call. The same run's adapt was 1,204 s (the #610 scaling), so the placement's marking is now the dominant cost at exactly the configurations the ruling targets.

The fix is spatial culling, not C: each triangle only ever matters within the carve's reach (clearance*h plus the crossing margin), so a cKDTree over mesh vertices queried per triangle bbox — or binning vertices to triangles by cell — reduces the work to the near-fault band, which is O(sheet area / h^2), independent of the background mesh. The distances beyond the reach are never used: the callers threshold at reach_v everywhere, so a capped distance (clipped at reach) is exact where it is read.

Same pattern as #610: a whole-domain sweep where only a thin band is consumed.

Underworld development team with AI support from Claude Code

https://claude.ai/code/session_01WDKP73LD3dCFQSNgEXbbw9

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions