Skip to content

ThinCurr: Fix runaway HODLR partitioning when vertices tie at the median - #13

Closed
hansec wants to merge 1 commit into
mainfrom
claude/laughing-heisenberg-95x74l
Closed

hansec wants to merge 1 commit into
mainfrom
claude/laughing-heisenberg-95x74l

Conversation

@hansec

@hansec hansec commented Nov 10, 2026

Copy link
Copy Markdown
Owner

Primary changes

Fixes tw_part_mesh → subdivide_leaf (src/physics/thin_wall_hodlr.F90) recursing until it aborts with "Maximum recursion".

Cause: the split along the chosen axis is the median vertex coordinate, nudged upward by 1e-4*(bounds width) if any vertex lies on it. Child 1 takes x >= split and child 2 takes x < split. When more than half of a block's vertices share the largest coordinate along that axis, the nudge moves the split past every vertex. One child then gets all of the vertices, and the same split repeats forever. Example: the flange plane z = 0 of the junction ring() mesh, which aborted for target_size <= 60.

Fix:

  • Splits that already leave vertices on both sides are unchanged (same axis choice, same nudged median), so existing partitions are identical.
  • If one side would be empty, the split is placed halfway between the tied median value and the nearest distinct value below it, or above it if there is none below.
  • If all of a block's vertices lie in one plane normal to that axis, the next axis by spread is tried.
  • A block of coincident vertices (not possible on a valid mesh) is left as a leaf with a warning instead of recursing.
  • The "Lost element in partitioning" check is kept.

The split is still a single plane strictly between two vertex values inside the parent's region. So the leaf cells from the unmerged HODLR leaf-adjacency work (claude/thincurr-adjacent-leaves-1lc3dw) will still tile the root box. When the two branches are combined, the cells should be split at split (in place of locs(j)). I checked this on that branch: test_hodlr_leaves passes, and its tiling and adjacency checks also pass on the junction ring at target sizes 10, 30 and 60.

Test: the new test_hodlr_small_leaves[30, 60] in src/tests/physics/test_ThinCurr_junctions.py builds HODLR on the junction ring. It compares the HODLR L to the dense L on random vectors, with a 1e-5 relative threshold. HODLR differs from the dense L by about 3e-6 on this mesh for every target size, including a single block. Both cases abort with "Maximum recursion" without the fix and pass with it.

Verified locally (Ubuntu 24.04 system libraries, OpenMPI + OpenMP): all 140 tests in test_ThinCurr.py and test_ThinCurr_junctions.py pass. The Fortran stack lint passes.

Secondary changes

None.

API changes

None. No changes to Python/Fortran APIs or input files.


Generated by Claude Code

In tw_part_mesh::subdivide_leaf the split along the chosen axis is the
median vertex coordinate, nudged upward off any vertex lying on it. When
more than half of a block's vertices share the largest coordinate along
that axis (eg. the flange plane of the junction ring mesh), the nudge
moves the split past every vertex, one child gets all of them, and the
same split repeats until "Maximum recursion" aborts.

The split is now checked to leave vertices on both sides. If it does
not, it is placed halfway between the median value and the nearest
distinct value below it (or above it), and if all vertices lie on one
plane normal to the axis the next axis (by spread) is tried. Splits that
already separated the vertices are unchanged, so existing partitions are
identical. A block of coincident vertices is left as a leaf with a
warning instead of recursing.

Adds a regression test building HODLR on the junction ring with
target_size 30 and 60 (previously aborted for target_size <= 60).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01NKQvs8bWWKcfS7nRhwabX5
@hansec hansec closed this Nov 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants