Skip to content

The level set's interface thickness is the same at any rank count - #1239

Open
lmoresi wants to merge 4 commits into
developmentfrom
bugfix/level-set-epsilon-at-any-rank-count
Open

lmoresi wants to merge 4 commits into
developmentfrom
bugfix/level-set-epsilon-at-any-rank-count

Conversation

@lmoresi

@lmoresi lmoresi commented Nov 19, 2026 •

Copy link
Copy Markdown
Member

A follow-up to the review of #1234, which found it. No issue is filed.

What changes

level_set.interface_thickness computes a thickness per cell and carries it to the level set's nodes. It took each node's value from the nearest cell centroid among the rank's own cells. That depended on the partition in two ways:

  • Near a partition boundary, the nearest cell can be on another rank.
  • At ties: on a regular mesh a vertex is often equidistant from several centroids, and the tie went by the local cell order.

The reviewer measured the effect on the initial level set's volume, relative to serial: 1.4e-5 (box, np 2), 3.7e-4 (box, np 3) and 1.3e-3 (Annulus, np 2). So a parallel run started from a different field and target volume.

Now a node takes the mean over the cells that hold it:

  • Each rank adds its owned cells' values and counts at their nodes, in the layout of the basis coordinate DM that _get_coords_for_basis reads.
  • The sums are added over the ranks with localToGlobal(ADD_VALUES).
  • Every cell around a node counts once, whichever rank holds it, so the rule is topological and has no ties.

This changes serial results too. The thickness at a node is now the mean of its cells, not one cell's. Measured by the reviewer, serially:

  • a node's thickness moves by up to 21 % on a box, 24 % on an Annulus and 37 % on a graded mesh, where cells of different sizes meet;
  • the initial enclosed volume moves by 0.8 to 1.9 %;
  • on the test's graded fixture, ∫ε moves from 0.039525 (development) to 0.040477.

Saved level-set results will not reproduce exactly. docs/developer/CHANGELOG.md says so.

At np 1 to 3, ε and the initial volume now equal serial to about 1e-16, with a random partition and with an empty rank (the reviewer's runs).

The guide's band table (docs/advanced/level-set-transport.md) is re-measured with the new rule. The drifts are unchanged to the digits shown, and the thickness column now has a stated definition. test_1105_levelset_rotation passes on its thresholds.

test_1105_levelset_rotation's band-share and contour-mismatch checks now count nodes over every rank. This is the review's low finding: a rank-local share failed on one rank at np 2.

Tolerances and coordinate matches

  • The new test asserts ∫ε and the initial ∫ψ against values measured serially, to 1e-12 relative. The fixture is the cell-list triangle of empty_rank_fixtures, shared among every rank and graded by x ↦ x², not a gmsh mesh, so the values do not depend on the machine.
  • Coordinate matches: none. The node mean is by closure rows.

Tests

  • tests/parallel/test_1105_level_set_epsilon_at_any_rank_count_parallel.py: a second case compares ∫ε on the triangle with one rank empty against the same triangle on every rank, at the same rank count (from np 3), to 1e-12. The file is reached by the tests/parallel/test_*.py glob in scripts/test.sh:
    • Serially: it passes on this branch and fails on development (∫ε 0.039525 against 0.040477).
    • In parallel: at np 2 and 3 it is the reviewer's run. We do not run MPI on this machine (macOS, 12-core Apple M4).
  • Checked serially: the basis DM's rows equal MeshVariable.coords for degree 1 and 2, continuous and discontinuous, on triangles and quadrilaterals. ε is finite everywhere.
  • Serial runs: the level-set, material and swarm-proxy files (test_1105, 0071, 0073, 0116, 0132, 1069) gave 57 passed, 1 skipped (shapely is not installed). test_1105 with the global shares: 6 passed, 1 skipped.

Adversarial review (author's pass)

  • Rank asymmetry. interface_thickness is collective now: the local-to-global and global-to-local run on every rank, including a rank with no cells, which adds nothing. It is called where the level set is set up, on every rank.
  • Ghost cells. Only owned cells add (_get_owned_cells_mask), so a ghost cell is not counted twice.
  • Count. Every node is in at least one cell, so the count is at least 1 and there is no division by zero.
  • Left out: the other low from the The level set's mass correction is one shift on every rank #1234 review, that the mass correction's band fraction counts ghost nodes, belongs to The level set's mass correction is one shift on every rank #1234's code and is not changed here. It only seeds the secant.

Underworld development team with AI support from Claude Code

…s, the same at any rank count

interface_thickness carried each cell's thickness to the nodes from the
nearest cell centroid among a rank's own cells. Near a partition boundary the
nearest cell can be on another rank, and on a regular mesh a vertex is often
equidistant from several centroids, decided by the local cell order: the
initial level set depended on the partition, its volume by up to 1.3e-3
relative at np 2 (review of #1234). A node now takes the mean over the cells
holding it, summed over every rank's owned cells through the basis
coordinate DM's local-to-global with ADD_VALUES.

test_1105's band and contour shares are counted over every rank.

Underworld development team with AI support from Claude Code
Copilot AI balanced review requested due to automatic review settings November 19, 2026 22:09

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.

…kness

The drifts are unchanged to the digits shown but the last (-0.86% for -0.85%
at scale 3). The thickness column is now defined: the node mean of epsilon
over the cell size.

Underworld development team with AI support from Claude Code
@lmoresi

lmoresi commented Nov 19, 2026

Copy link
Copy Markdown
Member Author

The level-set guide's band-thickness table (docs/advanced/level-set-transport.md) is re-measured on this branch with the same setup: 32 cells across, one revolution in 200 steps, SUPG, no mass correction, reinitialisation every fifth step.

The drifts are +0.844 %, +0.281 %, -0.183 % and -0.862 % at scale 0.35, 1, 2 and 3. The table had +0.84 %, +0.28 %, -0.18 % and -0.85 %.

The thickness column is now defined as the node mean of ε divided by the cell size: 0.16, 0.46, 0.92 and 1.38. The old column's definition of h was not recorded, so its values (0.12 to 1.07) are replaced rather than compared.

Underworld development team with AI support from Claude Code

@lmoresi

lmoresi commented Nov 19, 2026

Copy link
Copy Markdown
Member Author

Review from the Underworld development team with AI support from Claude Code (H1: review and parallel test runs on a 96-thread Linux workstation (Intel Xeon Gold 6240R, AVX-512; MPICH))

(H1 is the session that reviews pull requests and runs the parallel tests.)

Verdict

Head b7953dd: ready to merge on green from this review.

ε and the initial volume are now the same at every rank count to round-off. We checked three meshes, default and random partitions, and an empty rank.

The wall shift still differs from serial, by 0.2 to 0.6 %. That comes from a separate partition dependence in the SLCN transport, not from ε (finding 1). It needs its own issue.

Build. The merge base is development 246d6ce. The PR changes no compiled source, so we copied its level_set.py over the build of 246d6ce. For the wall probe we three-way merged level_set.py from development, #1234 (b1b46d3, not yet merged) and this PR, with no conflict.

Results

check np development 246d6ce PR b7953dd
New test_1105_level_set_epsilon_at_any_rank_count_parallel 1, 2, 3 fails at every np (the constants are the new serial values) passes on every rank. Its serial constants are reproduced exactly on Linux
∫ε, simplex box (-1..1, 0.1) 1 / 2 / 3 0.364730 / 0.364773 / 0.364811 0.36868760497712372 / ...383 / ...372
V0, simplex box 1 / 2 / 3 0.1425385 / 0.1425404 / 0.1425917 0.14367769066272582 / ...587 / ...601
∫ε and V0, Annulus(0.3, 1, 0.1) 1 / 2 / 3 ∫ε 0.243684 / 0.243782 / 0.243832 ∫ε 0.24900585132213637 / ...637 / ...632; V0 equal to 1e-15
∫ε and V0, the graded triangle 1 / 2 / 3 ∫ε 0.0395254 / 0.0395834 / 0.0395834 equal to the last digit or two
Random partition (rand1), box and Annulus 3 ∫ε off by 0.7 % and 1.4 % equal to serial to 1e-16
An empty rank: box under emptyband, and the triangle with its last rank empty 3 box ∫ε 0.364842 equal to serial. localToGlobal(ADD) completes on the empty rank, no hang
One SLCN step, far field 0, development + #1234 + this PR: box wall value 1 / 2 / 3 1.19192e-4 / 1.19405e-4 / 1.19404e-4. One value on every rank, and V0 identical
The same, Annulus 1 / 2 / 3 2.86189e-4 / 2.84551e-4 / 2.84552e-4
test_1105_levelset_rotation, development + #1234 + this PR 2 (one rank failed the rank-local share) 6 passed, 1 skipped on both ranks
Level-set and SLCN files, serial (test_1105, 1056_units_slcn_traceback, 0610_navier_stokes_slcn_projection, 0066, 1071_slcn_moving_mesh, 1164, the new file, test_1069) 1 55 passed, 1 skipped

Behaviour change (serial)

A node's ε is now the mean over the cells around it, not the value of the nearest cell centroid. Serially, before against after:

mesh nodes largest change at a node mean change ∫ε
simplex box 1973 21 % +1.3 % +1.1 %
Annulus 1608 24 % +2.6 % +2.2 %
graded triangle 153 37 % +5.5 % +2.4 %

The largest changes are at nodes between cells of different sizes. The initial volume moves by 0.8 % (box) and 1.9 % (Annulus). The docs page's band table was re-measured in the PR. Results saved with the old ε will not be reproduced exactly.

The test_1105 change moves no threshold and loosens nothing.

  • The two limits stay at 0.2 (band share) and 0.01 (indicator mismatch).
  • Only the share is now counted over every rank (an allreduce of counts) rather than on each rank's own nodes.
  • Serially it is the same number as before.
  • In parallel a ghost node counts once on each rank that holds it, which changes the share by a negligible amount.

Findings

1. Medium (older than this PR, needs an issue): the SLCN transport step depends on the partition

With ε and V0 now equal, the wall shift still differs between serial and parallel. np 2 and np 3 agree with each other to 1e-5 relative, but not with np 1: box 1.19405e-4 against 1.19192e-4 (0.18 %), Annulus 2.84551e-4 against 2.86189e-4 (0.57 %).

Isolating it: one SLCN step on the box with the mass correction off, from identical initial fields (they agree to 1.1e-16 at np 1 and np 2).

  • After the step, 1199 nodes differ, by up to 1.09e-4, the largest at (0.810, -0.081) in the interior. The wall nodes do not differ.
  • The volume after transport is 1.43200923e-1 serially and 1.43200070e-1 at np 2.
  • It is not the solver tolerance: with the transport tolerance at 1e-11 (default 1e-4) the difference is still 1.09e-4.

So it is in the semi-Lagrangian departure-point evaluation, or in its use across ranks. This PR does not touch it. It is the remaining reason the wall shift is not serial's.

2. Low: the new test's fixture has no empty rank

right_triangle_of_cells(8, uw.mpi.size) shares the cells among every rank. We ran the same fixture with its last rank empty, and the box under emptyband, at np 3. Both give the serial values and do not hang. The fixture's own empty-rank mode (max(size - 1, 1)) would cover it in the test.

Not run

  • 3-D;
  • a degree-1 or discontinuous level set (the per-node table assumes two components);
  • np 4.

Logs are kept by the reviewer.

Underworld development team with AI support from Claude Code

… an empty rank (review of #1239)

Underworld development team with AI support from Claude Code
@lmoresi

lmoresi commented Nov 19, 2026

Copy link
Copy Markdown
Member Author

Review from the Underworld development team with AI support from Claude Code (H1: review and parallel test runs on a 96-thread Linux workstation (Intel Xeon Gold 6240R, AVX-512; MPICH))

(H1 is the session that reviews pull requests and runs the parallel tests.)

Head 116b0a0: ready to merge on green from this review.

What changed. Since b7953dd the diff is docs/developer/CHANGELOG.md (+13) and the new parallel test file (+20). No source changed.

The test file.

  • np 3: both cases pass on all three ranks. The new case asserts 0 in counts_empty and 0 not in counts_full, so the run had an empty rank.
  • np 2: the first case passes on both ranks, and the new case skips with its stated reason.

The CHANGELOG matches what we measured:

  • the change at a node, up to 21 % (box), 24 % (Annulus) and 37 % (graded mesh);
  • the initial volume, 0.8 to 1.9 %;
  • the partition effect it removes, up to 1.3e-3 relative at np 2;
  • agreement with serial to about 1e-16 at np 1 to 3.

One low point on the new case. It also passes on development (np 3, all ranks), so it cannot catch the defect.

  • Why: its triangle is not graded, so every cell has the same size and ε is the same constant under the old rule and the new one.
  • Fix: grade the coordinates as the first case does (x → x²). The empty rank's contribution to the node sums would then be tested against cells of different sizes.
  • This does not block the PR.

Logs are kept by the reviewer.

Underworld development team with AI support from Claude Code

…art (review of #1239)

Underworld development team with AI support from Claude Code

This branch has not been deployed

No deployments
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