Skip to content

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

Open

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

Activity

  1. lmoresi commented on Aug 19, 2026

    @lmoresi
    MemberAuthor

    Fixed on feature/fault-outcrop-3d-cap (first commit of b76bb85 pair): a reach-aware spatial hash with PER-POINT thresholds (the reaches scale with local cell size, so a single cutoff cannot cull a graded mesh) behind _sheet_distance_within, wired into the placement's nine hot sites including the carve's straddle sweep. Decisions identical — bit-identical placed mesh on the 452k-cell benchmark — and place_sheet drops 555 s -> 67 s (the distance share from 446 s to under a second). Closing when the PR merges.

    Underworld development team with AI support from Claude Code

  2. lmoresi commented on Nov 10, 2026

    @lmoresi
    MemberAuthor

    Verified fixed on development: _sheet_distance_within makes the same decisions as the full per-triangle sweep, 75 times faster, on a graded point set.

    Probe on development a6eebb61 (serial), /mnt/nvme0n1p4/home/lmorese/hyperion-work/runs/2026-11-10-sweep/A/probes/p613.py. A curved sheet of 4,608 triangles sits in 200,000 points with a graded per-point reach, reach = 0.6 h + h with h = 0.01 + 0.04 x. _sheet_distance_within is compared with _sheet_distance:

    4608 triangles x 200000 points; near-band points 13759
    full sweep 333.9 s, reach-culled 4.44 s, speed-up 75x
    decisions (d < reach) identical: True; max |diff| inside reach 0.00e+00; all far points above reach: True
    

    Distances are bit-identical wherever they are below the reach, and every point beyond the reach gets a value above it. Thresholded decisions are therefore unchanged. place_surface.py calls _sheet_distance_within at 10 sites.

    Outside this issue: remove_embedded (place_surface.py:7081 and 7108) still calls the full _sheet_distance over every vertex against the embedded face soup, and then thresholds at reach_v + h. It has the same shape and could take the same culling if that path becomes hot.

    Underworld development team with AI support from Claude Code

  3. added
    fixed-in-development
    on Nov 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    fixed-in-development

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions