Skip to content

fix(LBIE): cvc::hexahedralize returns untwisted hexahedra; a cube's scaled Jacobian is 1 - #802

Merged
transfix merged 1 commit into
masterfrom
fix/lbie-hex-corner-order
Oct 26, 2026
Merged

transfix merged 1 commit into
masterfrom
fix/lbie-hex-corner-order

Conversation

@transfix

Copy link
Copy Markdown
Owner

What was wrong

Every hexahedron from cvc::hexahedralize was twisted. geoframe stores a hexahedron as six quad faces, and LBIE winds the second face against the first:

  • Octree::add_hexa writes them that way.
  • saveHexa and the optimizer in octree.cpp read the top corners back as v5 v4 v7 v6.

The Week-4 geoframe_adapter decoded and encoded both faces in plain order. So corner k + 4 was never over corner k, and every hexahedron came out twisted. As a result:

  • Hex Jacobians, quality stats and filters, extract_surface and the cvcGL HEXS wireframe were all computed on twisted elements.
  • geometry::quality_improve on a hex mesh handed LBIE's optimizer twisted elements.

The older convert() path (decode_hexs_from_quads) always had it right.

hex_scaled_jacobian scored a perfect cube 0.024. It divided the centre Jacobian by the space diagonal cubed. Its docs say 1 for a cube, and the tests already noted the mismatch. So filter_hexs_by_quality's documented default threshold of 0.2 rejected every cube.

The fix

  • geoframe_adapter: reads and writes LBIE's own layout, through one encode_hex / decode_hex pair. It replaces four hand-unrolled copies.
  • hex_scaled_jacobian: is now the Verdict definition, the worst corner's determinant of its three unit edges. A box scores 1, a cube sheared by twice its height scores 1/√5, and its mirror image scores −1.

Bunny SDF at 65³, 12,769 hexahedra:

before after
hexes right-handed at every corner ~0% 98.6%
mean scaled Jacobian ≈ 0 0.85

Tests

New test LbieMesherTest.AdapterKeepsLbiesHexahedronCorners checks three things on a sphere's LBIE hex mesh:

  • to_geometry gives exactly LBIE's corners for every hexahedron.
  • to_geoframe and the geoframe_adapter class write those corners back the way LBIE reads them.
  • At least 90% of the hexahedra are right-handed, and the mean scaled Jacobian is above 0.5.

Updated tests:

  • HexUtilityFunctions and HexJacobianMetric now expect a cube to score 1, a sheared cube 1/√5 and the mirror image −1. They also use the documented 0.2 default threshold.
  • In pycvc's test_unit_hex_metrics, a cube now scores 1.

Run locally on Windows Release (MSVC, shared): lbie_mesher_test 46/46, geometry_test 111/111, algorithm_test 10/10.

Not fixed here

These are other LBIE problems found while rendering the meshes for #803's gallery:

  • Collapsed hexahedra: on the TexMol head and the vh4 CT, adaptive hexahedralization gives about half the hexahedra repeated corners.
  • Staircase tet boundary: the TETRA boundary is a grid staircase.
  • Geometric flow on tets: the minimum dihedral angle falls from 26.6° to 0.75°.
  • Interval meshes: tetrahedralize2 leaves fans of slivers and holes.

…caled Jacobian is 1

geoframe stores a hexahedron as its six faces, and LBIE winds the second
face against the first (Octree::add_hexa); saveHexa and the optimizer in
octree.cpp read the top corners from it as v5 v4 v7 v6. The geoframe_adapter
read and wrote both faces in plain order, so every hexahedron from
cvc::hexahedralize was twisted (corner k + 4 not over corner k), and
geometry::quality_improve handed LBIE's optimizer twisted hexahedra. The older
convert() path (decode_hexs_from_quads) had it right. The adapter now reads and
writes LBIE's layout: on the bunny at 65^3 the mean scaled Jacobian goes from
~0 to 0.85, with 97-99% of the hexahedra right-handed at every corner.

hex_scaled_jacobian divided the centre Jacobian by the space diagonal cubed, so
a unit cube scored 1/sqrt(27) = 0.024, though its docs say 1 and
filter_hexs_by_quality's default threshold of 0.2 rejected every cube. It is now
the worst corner's determinant of unit edges (the Verdict definition): 1 for a
box, 1/sqrt(5) for a cube sheared by twice its height, -1 for its mirror image.
@transfix
transfix merged commit 4393a8a into master Oct 26, 2026
44 of 47 checks passed
transfix added a commit that referenced this pull request Oct 26, 2026
#802 (its base) landed on master as a squash; this merges master on the branch's real base, fc9220a, so #803 carries only its own changes.
transfix added a commit that referenced this pull request Oct 26, 2026
…s/live-gallery

Conflicts: src/cvc/CMakeLists.txt (master's new conference and physics sources, plus this branch's ariadne/keys.cpp) and src/cvcGL/CameraController.cpp (both includes).
transfix added a commit that referenced this pull request Oct 27, 2026
…sphere (#830)

Master fails LbieMesherTest.AdapterKeepsLbiesHexahedronCorners on every
platform: mean scaled Jacobian 0.49893 < 0.5. #802 added the test and #808
merged 13 minutes later from a branch that never had it, so neither PR's CI
ran the two together.

The mesh is fine; the threshold was set on the wrong mesh. The test's
sphere (17^3 samples over [-1,1]^3, voxels 0.125 across) meshes as 27
hexahedra, a 3x3x3 block with 64 vertices, before and after #808. Measured:

- #802's LBIE: the block was a cube inside the sphere. Its 56 outer
  vertices were 0.31-0.50 from the centre (radius 0.5), every hexahedron
  ~1.0, mean 0.9996.
- #808's LBIE: the 56 outer vertices are on the sphere (0.491-0.513). The
  edge and corner hexahedra become wedges: mean 0.499, worst 0.218, none
  inverted.
- The pre-#802 twisted adapter on today's mesh: every hexahedron inside out,
  mean -0.78.

So the check that matters is that no hexahedron is inverted. The test now
requires every hexahedron to be right-handed (it allowed a tenth to be
inverted) and a mean above 0.4 instead of 0.5. The twisted layout still
fails both by far.
transfix added a commit that referenced this pull request Oct 27, 2026
…terrupts (#825)

* fix(volume): run HDF5 work on the caller's app and stop swallowing interrupts

volume_io_test segfaulted intermittently when the whole binary ran as one
process, in a test after CvcRawRoundTrip. It took two lifetime bugs:

- hdf5_io kept the app that registered it and worked through that app
  instead of the one each call passes. Every cvc::app registers another
  hdf5_io into the process-wide handler map, and the first one registered
  serves every later call. So once the process's first app was destroyed,
  every HDF5 call ran through freed memory, and writeVolumeFile started its
  build_hierarchy thread on that dead app, where the writing app's ~app
  never saw it. hdf5_io now keeps no app; the maxdim default its
  constructor set moves to register_hdf5_io.

- thread_info, thread_feedback and hdf5_utils::library_lock call app
  methods that are interruption points inside catch-alls. An interrupt that
  arrived there was thrown and swallowed, and boost clears the request when
  it throws, so the thread kept running. ~app gave up joining the hierarchy
  thread after 5 s and freed the app under it. They now hold interruption
  off (disable_interruption) while they keep their books, so the request
  stays pending for the thread's next interruption point.

New tests, each failing without its fix:
- Hdf5VolumeTest.HierarchyThreadRunsOnTheCallersApp
- Hdf5VolumeTest.LibraryLockKeepsAnInterruptPending
- AppTest.ThreadBookkeepingKeepsAnInterruptPending

hdf5_volume_test's comment on its shared app described the first bug as
the reason for sharing; it now says the sharing is no longer needed.

* test(LBIE): AdapterKeepsLbiesHexahedronCorners expects #808's fitted sphere

Master fails LbieMesherTest.AdapterKeepsLbiesHexahedronCorners on every
platform: mean scaled Jacobian 0.49893 < 0.5. #802 added the test and #808
merged 13 minutes later from a branch that never had it, so neither PR's CI
ran the two together.

The mesh is fine; the threshold was set on the wrong mesh. The test's
sphere (17^3 samples over [-1,1]^3, voxels 0.125 across) meshes as 27
hexahedra, a 3x3x3 block with 64 vertices, before and after #808. Measured:

- #802's LBIE: the block was a cube inside the sphere. Its 56 outer
  vertices were 0.31-0.50 from the centre (radius 0.5), every hexahedron
  ~1.0, mean 0.9996.
- #808's LBIE: the 56 outer vertices are on the sphere (0.491-0.513). The
  edge and corner hexahedra become wedges: mean 0.499, worst 0.218, none
  inverted.
- The pre-#802 twisted adapter on today's mesh: every hexahedron inside out,
  mean -0.78.

So the check that matters is that no hexahedron is inverted. The test now
requires every hexahedron to be right-handed (it allowed a tenth to be
inverted) and a mean above 0.4 instead of 0.5. The twisted layout still
fails both by far.
@transfix
transfix deleted the fix/lbie-hex-corner-order branch October 29, 2026 20:53
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.

1 participant