Skip to content

Refinement moves the internal sphere of a shell onto its sphere (#949 item 3) - #1173

Merged
lmoresi merged 5 commits into
developmentfrom
bugfix/spherical-internal-refinement-snap-949
Nov 14, 2026
Merged

lmoresi merged 5 commits into
developmentfrom
bugfix/spherical-internal-refinement-snap-949

Conversation

@lmoresi

@lmoresi lmoresi commented Nov 13, 2026 •

Copy link
Copy Markdown
Member

Refinement moves the internal sphere of a shell onto its sphere (#949 item 3)

Stacked on #1148 (feature/mesh-analytic-surface); the base of this PR is that branch. It removes #1148's temporary release of the Internal declaration on a refined SphericalShellInternalBoundary, and the TODO(BUG) with it, because the refined mesh is now on that sphere.

What it reverses from #1148, in full:

  • src/underworld3/meshing/spherical.py: the block after the registration in SphericalShellInternalBoundary that released Internal when refinement was set, and its comment, are removed.
  • The same file: the TODO(BUG) on the refinement callback naming Spherical mesh generators: five defects found while fixing #946, left open #949 item 3 is replaced by a comment saying the callback moves all three surfaces.
  • tests/test_1179_mesh_analytic_surface.py: test_a_refined_shell_does_not_declare_its_internal_sphere becomes test_a_refined_shell_declares_its_internal_sphere, asserting radius 0.8 from the accessor where it asserted the refusal.
  • docs/developer/design/boundary-slip-strategy.md: the sentence saying a refined SphericalShellInternalBoundary withdraws its Internal sphere now says it declares it, because refinement moves that surface onto it (commit d2aa1f2).

What changed and why

SphericalShellInternalBoundary embeds a sphere of radius radiusInternal between its walls. Refinement places the new vertices of every surface on the chords of the coarse one. The constructor's refinement callback moved the new vertices of Lower and Upper back onto their spheres but not those of Internal, which stayed up to 2.9e-02 of its radius inside the sphere (#949 item 3), while the mesh registered that sphere for it and mesh.Gamma on Internal resolves to the analytic radial normal.

The callback now moves the vertices of all three surfaces onto their spheres, with one loop over the three labels (it was two copies of the same block). AnnulusInternalBoundary already does this for its internal circle.

One detail: the old Lower line divided by 1e-16 + R; the loop divides by R for all three surfaces, as Upper did. The guard mattered only for a vertex at the origin, which no vertex of a sphere of positive radius is; radiusInner = 0 was not tried. On the fixtures below this moves Lower vertices by round-off only (largest 3.0e-16 of the radius) and puts them closer to the sphere (largest distance 3.3e-16 before, 2.2e-16 after).

What a user's run gets now that it did not

  • A refined SphericalShellInternalBoundary declares its Internal sphere: mesh.analytic_surface("Internal") returns it (on Mesh.analytic_surface: read the declared circle, sphere or plane of a boundary, or refuse #1148 alone it refuses on a refined mesh).
  • Answers on a refined shell with an internal boundary change, because the vertices of that surface move. Measured (below): about 1 % in the velocity rms of a solve loaded on the Internal surface.
  • Nothing can newly refuse: no library code calls analytic_surface yet.

The vertices moved

SphericalShellInternalBoundary(radiusOuter=1.0, radiusInternal=0.8, radiusInner=0.5, cellSize=0.3), per level of the hierarchy, relative to radiusInternal. Distances compare the same vertex (same topology) on the base and on this branch.

refinement level Internal vertices moved (more than 1e-12) largest move interior vertices moved largest
1 0 130 0 2.9e-16 0 of 0
1 1 514 384 2.898e-02 0 of 1026
2 1 514 384 2.898e-02 0 of 1026
2 2 2050 1920 2.934e-02 3260 of 12256 1.449e-02

At refinement 2 the interior vertices of level 2 move because level 2 is refined from a level 1 whose Internal vertices are now on the sphere. Lower and Upper move by round-off only (at most 3.1e-16).

Distance of each surface from its sphere, largest over its vertices, relative to the radius:

base (#1148, 41521d4) this branch
Internal, level 1 2.898e-02 2.8e-16
Internal, level 2 2.934e-02 4.2e-16
Lower / Upper, any level 3.3e-16 / 2.2e-16 2.2e-16 / 2.2e-16

No vertex is held back by the hierarchy's guard against inverted cells (#946) on these fixtures: no warning at refinement 1 or 2. (With #1152, a held-back Internal vertex would release the declaration; without #1152 the hierarchy warns as before.)

Cell quality of the finest level:

refinement cells min volume, base / branch min / max volume, base / branch min dihedral angle, base / branch
1 12224 8.35e-05 / 7.40e-05 0.130 / 0.106 9.36 / 8.25 degrees
2 97792 1.03e-05 / 8.36e-06 0.128 / 0.090 8.22 / 8.16 degrees

The region labels (Inner / Outer, by topology from the Internal facets) are unchanged: 4448 / 7776 cells at refinement 1 and 35584 / 62208 at refinement 2, on both.

One answer, before and after

Stokes on the refined shell (refinement 1, cell size 0.3), with an l = 2 load on the Internal surface and rotated free slip on both walls (the setup of the Zhong case in test_1018, with radii 0.5 / 0.8 / 1.0), tolerance 1e-8, converged (reason 2) on both:

base this branch change
velocity rms 1.130342e-02 1.118308e-02 -1.06 %
largest nodal speed 2.295746e-02 2.231051e-02 -2.82 %
pressure rms 3.264673e+00 3.211540e+00 -1.63 %

The base number is the same on development eb3d2f0.

Tests

  • tests/test_1190_spherical_internal_refinement_snap.py (level 1, tier b), at refinement 1 and 2: every vertex of the three surfaces on its sphere to 64 machine epsilon relative to the radius, on every level; the refined shell declares Internal with radius 0.8; the cells of each region fill exactly the volume between that region's two surface polyhedra (a cell turned over by the snap would overlap its neighbours; measured 2.2e-16 relative at most, against a bound of 1.4e-14).
  • tests/parallel/test_1190_spherical_internal_refinement_snap_parallel.py (level 2, tier b): every local copy, owned or not, of a surface vertex on its sphere on every level; every copy has its owner's coordinates; every rank gets the declaration.
  • tests/test_1179_mesh_analytic_surface.py: the refined-shell case now asserts the declaration instead of its release.

What was run

On a 96-thread Linux workstation (single system image, Intel Xeon Gold 6240R, MPICH).

what result
new tests on the base (fails first) serial: 4 failed, 2 passed (the two volume cases pass on the base, as they should: the chordal mesh has no inverted cell); np 2: 2 failed, 1 passed on each rank
new tests and test_1179 on this branch serial 15 passed; parallel file 3 passed on every rank at np 2, 3 and 4
volume test against a mutant that pushes one interior vertex through the Internal sphere after the callback killed (3.2e-03 relative); the on-sphere test does not see it, as expected
neighbouring serial files (every test file building a spherical shell, 24 files) 199 passed, 1 skipped (tier c and level 3 deselected: the five deselected cases are in test_1064_constrained_spherical_shell_response.py, which builds no refined mesh, so this change cannot reach it). A first run with them included reached its 30-minute limit and was stopped
neighbouring parallel files at np 2 test_1175 6, test_1071 1, test_0001_sphere_refinement_folds 5, test_0765 3, test_0773 2, test_1069 7 passed and 1 skipped, test_1064_rotated_freeslip 7 passed and 2 skipped, on each rank
scripts/check_test_coverage.py OK
scripts/check_deprecated_patterns.py no new hits

What was not run

Checklist (UW3 Style Charter — docs/developer/UW3_STYLE_CHARTER.md)

  • I have read the Style Charter and followed it over the surrounding code (S2)
  • No drive-by refactors, renames, or "while I was here" cleanups (S9) — the callback's two copies of one block became one loop over three labels, since a third copy was needed
  • Bug fixes ship the regression test, written first, with level_* and tier_* markers (S8)
  • No hedging names (maybe_ / try_ / do_) and no commented-out code (S3, S4) — the callback's commented-out prints are removed with the block
  • Every exception swallow states its sanctioned failure mode in a comment (S4)
  • New data access uses .array / mesh.X.coords — not applicable: the callback works on the DM's coordinates, as every refinement callback does
  • Parallel safety considered — np 2, 3, 4 checked
  • No pixi.toml / pixi.lock or other dependency changes riding in an unrelated PR
  • AI-assisted work carries the attribution line below

Reviewer: H5 (one of the AI-assisted development sessions; it owns the mesh generators).

Underworld development team with AI support from Claude Code

…949 item 3)

On every level of the hierarchy, serially and on every rank at np 2 and
more, the vertices of Lower, Internal and Upper lie on their spheres to
64 eps of the radius, every copy has its owner's coordinates, and the
refined shell declares its Internal sphere. The regions fill the volume
between their surfaces, which a cell turned over by the snap would not.

Fail on the base: Internal is 2.9e-02 of the radius off its sphere at
level 1 and the declaration is released.

Underworld development team with AI support from Claude Code
…item 3)

The refinement callback of SphericalShellInternalBoundary moved the new
vertices of Lower and Upper onto their spheres but left those of the
embedded Internal surface on the chords of the coarse one, up to 2.9e-02
of its radius off. It now moves all three, so the refined mesh is on the
spheres it registers, and the temporary release of the Internal
declaration on refinement (#1148) goes. Lower loses its 1e-16 guard on
the radius, which no vertex of a shell wall can need.

Underworld development team with AI support from Claude Code
@lmoresi

lmoresi commented Nov 14, 2026

Copy link
Copy Markdown
Member Author

READY at 80aea76. Review by H5, a debugging session, run on a 96-thread Linux workstation (single system image; Intel Xeon Gold 6240R, AVX-512; MPICH), on a build of this head.

  1. One rule, not two. The callback is one loop over Upper, Lower and Internal, each scaled radially, x * r / |x|. That is the projection the generator already used for Upper and Lower, and the projection of the radial surface registered for Internal. Dropping the 1e-16 from Lower's denominator is safe, because the generator refuses radiusInner <= 0.
  2. Every level. _build_refined_hierarchy applies the callback to each refined DM. The surface test reads every DM in dm_hierarchy for all three labels, at refinement 1 and 2. The volume test runs on the finest DM of each fixture, so levels 1 and 2 are both covered.
  3. No inversion found. Coarse Internal vertices come out of gmsh already on the sphere, so only the new vertices move, outward by the sagitta.
    • I checked signed volume at levels 0 to 2 on four shells: no cell is turned against the majority.
    • The four shells, as cellSize / radiusInternal with radiusInner 0.5 and radiusOuter 1: 0.3 / 0.8 (this PR's), 0.15 / 0.9 (a thin outer layer), 0.25 / 0.65, and 0.2 / 0.8.
    • The smallest cell, as a fraction of the mean, falls by under 0.02 per level (0.29, then 0.25, then 0.22 on this PR's shell).
  4. test_1190_spherical_internal_refinement_snap.py: 6 passed serially.

A note that is not this PR's: the generator refuses several reasonable parameter sets at gmsh time.

  • At cellSize 0.4 to 0.7 with radiusInternal 0.8, it raises "Could not identify the spherical-shell volume".
  • At radiusInternal 0.92 or 0.58 (cellSize 0.3), it raises that error or "Could not identify Lower, Internal, and Upper".

This PR only touches the refinement callback, so these come from the generator itself. Worth an issue.

Underworld development team with AI support from Claude Code

The two comments #1148 changed on the Internal surface are the ones this
branch removes with the stopgap; the snap's comment stands.

Underworld development team with AI support from Claude Code
Underworld development team with AI support from Claude Code
@lmoresi
lmoresi changed the base branch from feature/mesh-analytic-surface to development November 14, 2026 03:43
Copilot AI balanced review requested due to automatic review settings November 14, 2026 06:11

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

@lmoresi
lmoresi merged commit f3568c6 into development Nov 14, 2026
10 checks passed
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.

3 participants