Skip to content

The boundary-condition wrapper checks its label and PETSc's answer; a rewire replaces boundary kernels (#1138, #1069) - #1211

Merged
lmoresi merged 6 commits into
developmentfrom
bugfix/boundary-wrapper-checks-and-replaces
Nov 19, 2026
Merged

lmoresi merged 6 commits into
developmentfrom
bugfix/boundary-wrapper-checks-and-replaces

Conversation

@lmoresi

@lmoresi lmoresi commented Nov 16, 2026 •

Copy link
Copy Markdown
Member

Fixes #1138, with its second face found in the review of PR #1170, and #1069. Both are from the probe sweep of 2026-11-15, which ran on development 176958a.

What changes

#1138: PetscDSAddBoundary_UW checks what it is given and what PETSc says. The wrapper looked a condition's label up by name, handed the result to DMAddBoundary unchecked, and returned the boundary index as its error code. That had two consequences:

  • A mesh wrapped around a bare DMPlex lists All_Boundaries, but the DM holds no such label. An essential condition on it went in on a null label, and the solve ended in a segmentation fault (exit 59).
  • A field number the solver's DM does not have was refused by DMAddBoundary. The refusal was discarded, and the solve converged without the condition.

Now:

  • The wrapper returns PETSc's error code, with the index as an out-parameter.
  • It checks the label and the return of DMAddBoundary.
  • Every condition, essential or natural, whatever label it is keyed on, goes through _add_boundary. It refuses with a ValueError naming what is wrong when no rank holds the label; when the label values mark no point on any rank (a boundary the mesh lists but has no faces for; natural conditions keyed on UW_Boundaries were dropped silently there); or when the field is not one of the solver's DM fields. It raises on any other PETSc error.
  • Each test is decided over the ranks before any rank refuses. A label made after distribution exists only on the ranks that hold its points; once the ranks agree it exists, a rank without it creates it empty, so every rank adds the condition.

Conditions library code puts on the whole boundary. EulerianSUPG's weak inflow condition and LevelSetSolver's far field were put on every member of mesh.boundaries. That broke in two ways:

  • Boundaries with no faces. Many stock meshes list one: Centre on an Annulus marks nothing. The rule above refuses a condition on it, so on an Annulus the inflow case was refused, and the far field had been a segmentation fault on development.
  • Faces counted twice. Every stock mesh also lists All_Boundaries, which shares every exterior face with the named boundaries, so each face's term went in twice.

Now both loops use Mesh._boundaries_covering_the_exterior_once(): All_Boundaries alone where it marks faces, otherwise every boundary that marks a face (height-1 points of UW_Boundaries, summed over the ranks).

This changes every EulerianSUPG result with an inflow_value on development. It corrects two things.

  1. The inflow term was doubled on every exterior face. Development applied it once under the face's own boundary and once under All_Boundaries.
    • Measured by the reviewer over four steps on an Annulus: max |S01| 0.287 with the term doubled, 0.311 with it once.
    • Measured here over two steps in the test below: the two differ by up to 0.074.
  2. A spurious inflow condition on interior surfaces. The term also went in on internal boundaries, where it acts wherever the flow crosses the surface. All_Boundaries is the exterior faces only, so the term is gone there. The reviewer measured this on a 2-D AnnulusInternalBoundary with a uniform flow and a field of 0.25:
    • Where it acted: ∫ -min(u·n, 0) over Internal is 0.649, against 1.0 over Upper.
    • What it did: on the crossed half of Internal, development pulled S01 to 0.120, against -0.0007 without the term.
    • How far the answer moves without it: by 0.144 on Internal and 0.095 in the interior. At the walls, removing the interior term moves the answer by about 1e-3, and removing the doubling by about 0.05.

The far field is a Dirichlet value, so applying it twice gave the same answer; the reviewer found it identical to the last bit.

#1069: a narrow rewire replaces the boundary kernels. They were registered with PetscWeakFormAdd*, which appends. After N rewires each boundary key listed N + 1 kernels; all of them ran at every boundary quadrature point, and the last overwrote the rest.

Now:

  • They are registered with PetscWeakFormSet*, which replaces.
  • A NULL kernel is passed to PETSc as a NULL array, which deletes the key. A non-NULL array of length 0 would keep a kernel already there, and would leave a zero-length entry that PETSc cannot enlarge later.
  • The setters return PETSc's code, and all 34 calls check it.
  • UW_PetscDSSetBdTerms, which had no caller, is removed.

We checked that no solver means two kernels on one key to be summed:

  • Every condition gets its own DMAddBoundary and so its own weak form (PetscDSAddBoundary creates one).
  • Within one weak form, every key registered in one setup pass is distinct.
  • The pairs of registrations on one key in the source are the two branches of an if (with or without the gradient term).

Tolerances and coordinate matches

  • The Robin test compares the rewired answer with a fresh build at 1e-9 absolute; the solver tolerance is 1e-10.
  • The inflow test compares the default with the run applied once at 1e-10 absolute (measured: equal to the bit), and requires the doubled run to differ by more than 1e-3 (measured 0.074). On the inflow and the outflow side it checks the inner-circle mean above 0.5 and the outer circle below 1e-8.
  • The level-set test checks that the wall values are equal to each other to the bit, and equal to 0 for SUPG. The volume is held to 1e-10 relative for SLCN and to 2 % for SUPG (measured drift 0.7 %).
  • Coordinate matches: the walls are selected by radius, with r < 0.31 and r > 0.99 in the inflow test, and within 1e-6 of 0.3 and 1 in the level-set test. The radii are 0.3 and 1.

Tests

tests/test_1069_boundary_wrapper_checks_and_replaces.py:

  • An essential condition on All_Boundaries of a bare DMPlex raises a ValueError naming the label. On development 176958a this case ends the process with SEGV; that is the sweep probe issue-sweep/sweep-2026-11-15/p1138_bare_dm.py in the campaigns repository.

  • A condition on field 2 of a two-field Stokes solver raises, naming the field and the valid range. On development fb75e9e it is not raised.

  • A natural condition on a boundary with no faces raises. On development the flux is dropped.

  • A label made only on the ranks that hold cells (tests/parallel/test_1069_boundary_label_on_some_ranks_parallel.py, the empty-rank triangle): Poisson against the exact solution x + y. Every rank marks a scratch label, because markBoundaryFaces is collective, and the real label is made where faces are. The test runs from np 3 and asserts that some rank lacks the label. At np 2 the fixture's one cell is spread onto both ranks. scripts/test.sh runs it at np 3. It is run under MPI by the reviewer (H1, the session that runs our parallel tests on a Linux workstation), who measured the development crash at np 2 and 3.

  • On an Annulus:

    • the boundaries covering the exterior once;
    • the inflow applied once per face, compared with runs on Lower and Upper (once by construction) and on Lower, Upper and All_Boundaries (twice);
    • the level-set far field with SUPG and with SLCN.

    On the previous head the first two fail. The level-set test failed with the Centre refusal on the head before that.

  • Two narrow rewires of a Robin coefficient leave one kernel on the boundary key, and the answer equals a fresh build's. On development there were 2 kernels after the first rewire.

Runs, serial, on macOS (12-core Apple M4):

  • Level 1 and 2 tests on the final build: 4183 passed. The one failure is test_1123's walk on this machine's gmsh mesh, as on development.

Not in this PR

Review

One round of adversarial review, then three rounds of the reviewer's review. Both records are posted below.

Issue state

Underworld development team with AI support from Claude Code

… rewire replaces boundary kernels (#1138, #1069)

#1138: PetscDSAddBoundary_UW looked a condition's label up by name and
handed the result to DMAddBoundary unchecked, and returned the boundary
index as its error code. A mesh wrapped around a bare DMPlex lists
All_Boundaries with no such label on the DM, so an essential condition on it
went in on a null label and the solve ended in a segmentation fault. A field
number the solver's DM does not have (found in the review of PR #1170) was
refused by DMAddBoundary, the refusal discarded, and the solve converged
without the condition.

The wrapper now returns PETSc's error code with the index as an
out-parameter, checks the label (agreed over the ranks, since a label made
after distribution may exist only where it has points) and DMAddBoundary's
return. Every caller goes through _add_boundary, which refuses a missing
label with a ValueError naming the labels the DM holds, and raises on any
other error.

#1069: the boundary kernels were registered with PetscWeakFormAdd*, which
appends, so every narrow rewire left the previous modules' kernels on the
boundary: N + 1 kernels per key after N rewires, each called, the last
overwriting the rest. They are registered with PetscWeakFormSet* now. A NULL
kernel is passed as a NULL array, which deletes the key; a zero-length array
would keep a kernel already there. The setters return PETSc's code and every
call checks it. UW_PetscDSSetBdTerms, which had no caller, is removed.

Tests: tests/test_1069_boundary_wrapper_checks_and_replaces.py. The field and
rewire tests fail on development fb75e9e (no raise; two kernels after one
rewire); the label case ends the process there. Level 1 and 2 tests pass (4182),
and the 89 test files that set boundary conditions pass on the final build (886).

Underworld development team with AI support from Claude Code
Copilot AI balanced review requested due to automatic review settings November 16, 2026 05:45

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 commented Nov 16, 2026

Copy link
Copy Markdown
Member Author

Adversarial review record

One round, by a fresh reviewer that read the code through git without running it, against PETSc 3.25's dtweakform.c and dtds.c. The measurements below were made by the author, serially, on macOS (12-core Apple M4).

Findings, fixed in de0d303

  • A NULL kernel did not register "none". PetscWeakFormSetFunction_Private deletes a key only when the function-array pointer is NULL; it never reads the count. The first version passed a non-NULL pointer with a count of 0. On a fresh key that stores a zero-length entry. On a key that already holds a kernel it keeps the stale one. A zero-length entry later set to a real kernel loops forever in PetscChunkBufferEnlargeChunk. No path reached the last two, but the zero-length entries were made on every build. A NULL kernel now goes in as a NULL array, which deletes the key.
  • The label check was rank-local. A label made after distribution through setLabelValue can exist only where it has points, so one rank could raise while the others went into the collective solve. The ranks now agree (an MPI_LOR reduce, in C and in the Python check) before any rank refuses.
  • Comments and dead code. A duplicate comment is removed. The field-number case was cited as "A Stokes solver reads its fields by the solver's numbers (#1147) #1170", which is a PR; it now reads "found in the review of PR A Stokes solver reads its fields by the solver's numbers (#1147) #1170". UW_PetscDSSetBdTerms, with no caller and still appending, is removed. The test docstring now says what each refusal names.
  • The test_1123 guard was out of scope and hid a fixture defect. It is removed from this branch and raised separately.

Attacks that found nothing

  • Replace semantics: no caller sums two kernels on one key (details in the PR body).
  • The script conversion: all 11 _add_boundary calls drop only the ctx argument, and the 34 CHKERRQ wraps each enclose one call.
  • except? -1 is safe: a boundary index is never -1.
  • No caller used the old return value.

Noted, not this branch

pp_G0, and pu when there is no fn_p, are registered on the velocity boundary's weak form, whose key PETSc never reads for field 1. The behaviour is unchanged.

Issues

Underworld development team with AI support from Claude Code

@lmoresi

lmoresi commented Nov 16, 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 de0d303: changes requested.

The replace semantics (#1069) and the field-number refusal are right at every rank count we ran. The parallel label agreement is not. When a label is held by some ranks only, the ranks agree that it exists, and then the ranks without it pass a null label to DMAddBoundary. Those ranks end with SEGV, at np 2 and np 3, for Poisson and for Stokes. The PR body says this case is handled. The fix is small (finding 1), and we tested a stand-in for it.

The baseline is the merge base, development fb75e9e, built on its own. There are compiled differences between fb75e9e and 176958a (petsc_generic_snes_solvers.pyx, function/_function.pyx), so 176958a could not stand in for it. The only .py difference between the merge base and the head is the new test.

Results

The runs use two fixtures:

  • Label fixture: the right triangle from tests/parallel/empty_rank_fixtures.py (6 x 6 cells), partitioned in rows. After distribution, Rim (the x = 0 side and the hypotenuse) is created on every rank. Base (y = 0) is made with setLabelValue only where it has faces, so at np 2 and np 3 only rank 0 holds it. All_Boundaries is in the enum and on no rank.
  • Band fixture: a gmsh UnstructuredSimplexBox (cell size 0.1), shell-partitioned by height. Under band at np 3 the middle rank has no Top or Bottom facet. Under emptyband the last rank has no cells.
check np layout development fb75e9e PR de0d303
1. Poisson, essential on Base (held by rank 0 only) 1 label fixture solves, int T = -2.261183220953e-01 same
1. Poisson, essential on Base 2, 3 label fixture SEGV, exit 59 SEGV on the ranks without the label, exit 59
1. Stokes, essential on Base 2, 3 label fixture SEGV, exit 59 SEGV, exit 59
1. Poisson and Stokes, essential on Base, with Base created empty on every rank first (a stand-in for the fix) 2, 3 label fixture not run the np 1 answer to 3e-13 (Poisson, int T) and 7e-11 relative (Stokes, int v_x)
1. Poisson, natural on Base 1, 2, 3 label fixture int T = -2.2386291306e-02 at each np same
1. Stokes, natural on Base 1, 2, 3 label fixture not run int |v|^2 = 5.94711182224e-06 at each np
1. Poisson, essential on All_Boundaries (held by no rank) 1 label fixture SEGV ValueError naming the label
1. Poisson, essential on All_Boundaries 2, 3 label fixture SEGV, exit 59 the same ValueError on every rank, no hang
1. Poisson, natural flux 5.0 on All_Boundaries 1, 2, 3 label fixture solves; answer equals the run with no natural condition (1.303974123354e-02) same: the condition is dropped silently
1. Vector projection, essential (5, 5) on All_Boundaries 1, 2, 3 label fixture solves; the condition is dropped (int |u|^2 = 0.2539) same
1. Poisson, essential on Bottom, Robin on Top 1, 2, 3 band, emptyband int T = -1.893199801482e-01 at each np and layout same
1. Stokes, essential on three walls, traction on Top 1, 2, 3 band, emptyband int p = -4.18309886184e-01; int v_x agrees to 1.4e-10 relative same
2. Poisson Robin, kernels per boundary key after a flag rewire and two jit_route rewires 1, 2 default 1, 2, 3, 4 1, 1, 1, 1 (rank 1 read through a COMM_SELF view)
2. Rewired Poisson against a fresh solver with the new coefficient 1, 2, 3 default max difference 1.1e-14 (np 2; np 3 not run) max difference 1.1e-14 (np 2), 1.8e-14 (np 3)
3. add_condition(p.field_id, ...) with the pressure at mesh position 2 1, 2, 3 default solves without the condition RuntimeError: PETSc error code '63' on every rank (allgathered)
3. The same condition on field 1 (contrast) 1, 2, 3 default solves solves, same answer
3. #1138 bare DMPlex, Stokes essential on All_Boundaries 1, 2, 3 rank 0 holds the cells SEGV the same ValueError on every rank
4. New test file 1 all three tests fail (SEGV; DID NOT RAISE; 2 kernels after the first rewire) 3 passed
4. New test file 2 not run 2 passed; the rewire test fails on rank 1 and the job hangs (finding 3)
4. New test file, the two refusal tests 3 not run 2 passed

Findings

1. High: a label held by some ranks reaches DMAddBoundary as a null label on the other ranks

The C wrapper and _add_boundary reduce "is the label held?" with a logical OR, and refuse only when no rank holds it. When some rank holds it, every rank goes on to DMAddBoundary. The ranks without the label pass the NULL they got from DMGetLabel. In PETSc 3.25.3, PetscDSAddBoundary calls PetscObjectGetName((PetscObject)label, ...) on it, and with a non-debug PETSc that is a segmentation fault.

  • Failure case: the label fixture, Base made by setLabelValue after distribution, so only rank 0 holds it. Poisson.add_essential_bc(0.0, "Base") at np 2 gives [1]PETSC ERROR: Caught signal number 11 SEGV and exit 59. Stokes add_essential_bc((0.0, 0.0), "Base") does the same, at np 2 and np 3.

  • Development crashes here too, so this is not a regression. But the PR body and the comment in petsc_compat.h describe this case ("a label made after distribution can exist only on the ranks that hold its points") as the reason for the reduction. It is not handled, and no test runs it.

  • Proposed fix: after the reduction, on a rank where the label is missing, create it empty before DMAddBoundary:

    if (!label) {
      PetscCall(DMCreateLabel(dm, labelname));
      PetscCall(DMGetLabel(dm, labelname, &label));
    }

    An empty label is what such a rank holds: no points. With the label on every rank, the completion in DMAddBoundary (DMPlexLabelComplete, which communicates over the point SF) runs on every rank.

    • We tested a stand-in, mesh.dm.createLabel("Base") on every rank before the solve.
    • Poisson and Stokes then match np 1 at np 2 and np 3, to 3e-13 for Poisson and 7e-11 relative for Stokes.
    • We did not build the C change itself.
  • Asked for: a test at np 2 (tests/parallel/, mpi(min_size=2)) with the triangle fixture and a label made only where it has faces, comparing the solve with np 1.

2. Medium: the refusal for a missing label covers two of the eight registration paths; the others drop the condition silently

_add_boundary checks the label it is given. Only the essential conditions of SNES_Scalar and SNES_Stokes_SaddlePt pass the condition's own label name. Every other path passes "UW_Boundaries", which every mesh holds:

  • the natural conditions of all four classes;
  • the essential conditions of SNES_Vector and SNES_MultiComponent;
  • the Stokes continuity and constraint boundaries.

On those paths, a boundary with no label gets an empty stratum of UW_Boundaries and integrates nothing.

3. Low: the rewire test is not safe under MPI

_boundary_kernels writes the DS view through a COMM_WORLD ASCII viewer into each rank's own tmp_path, and then reads it back on every rank.

  • Only rank 0's file is written. At np 2, rank 1 raises FileNotFoundError on its own ds_build.txt, and rank 0 goes on into the next solve. The job hangs until the supervisor kills it.
  • CI runs tests/ serially, so CI is not affected.
  • Asked for: a viewer on PETSc.COMM_SELF. We used one in the probes, and each rank reads its own boundary weak form through it. Alternatively, make the test serial-only.

4. Low: the field-number refusal does not say what was refused

At every np, the Python exception is RuntimeError: PETSc error code '63' was encountered. The field number and the condition appear only in PETSc's stderr ("Field number 2 must be in [0, 2)").

  • A check in _add_boundary against cdm.getNumFields() would raise a ValueError naming the condition, the field number and the fields the solver has. The value is the same on every rank, so it needs no reduction.
  • This is optional; the refusal itself is right.

Note on check 2

The second requested check assumed doubled kernels would double the flux. They do not. The generated boundary kernels assign (out[0] = ...), so on development, after three rewires with 4 kernels on each key, the answer still equals a fresh solver's to 1.1e-14. What the PR changes is the count, as #1069 says. The count is what we checked, at np 1 and np 2.

Confirmed correct

  • Replace semantics: one kernel per boundary key for f0, g0 and g1 after a flag rewire and after two jit_route rewires, at np 1 and np 2, on every rank. Development lists 2, 3 and 4. The rewired answer equals a fresh solver's.
  • The Set calls:
    • A NULL kernel goes in as a NULL array with count 0. Read against PETSc 3.25.3's dtweakform.c, that deletes the key.
    • The Stokes else branch that registers NULL for field 1 on the velocity boundary therefore deletes rather than keeps.
  • The field-number refusal is raised on every rank at np 1, 2 and 3. The correct field number still solves, with the same answer as development.
  • The Essential condition on All_Boundaries segfaults on a mesh wrapped around a bare DMPlex: the name is listed, the DM has no such label #1138 bare-DMPlex case is refused on every rank at np 1, 2 and 3, with the same message, and nothing hangs.
  • Labels present everywhere, with points on some ranks only:
    • Under band and emptyband, at np 2 and np 3, essential and natural conditions on Top and Bottom match np 1 on both builds (Poisson to every printed digit, Stokes to 1.4e-10 relative).
    • So does a natural condition on the label held by one rank.
  • The new test fails on the merge base in all three cases and passes on the head, serially.

What was run

  • Builds: the head, and the merge base fb75e9e, each in a fresh worktree. The solver extension's timestamp was fresh in each build.
  • Serial, 20 files:
    • The files: the new test, test_1000_poissonCart, test_1000_poissonNaturalBC, test_1001_poissonSph, test_1001_poisson_constants, test_1010_stokesCart, test_1011_stokesSph, test_1012_stokesImportedDMPlex, both test_1013, test_1066_rotated_meets_essential, test_1162, test_1166, test_0810, test_0856_remove_embedded, test_1154_a_deleted_solver_is_freed, test_0786_stokes_jacobian..., test_1069_pressure_gauge_is_recorded, test_1019_boundary_flux and parallel/test_0856_boundary_label....
    • Results: 151 passed on the head. On the merge base, without the new file, 148 passed.
  • tests/parallel/ at np 2 and np 3, with --with-mpi, one file per job, on both builds:
    • The files: test_0856_boundary_label... (14), test_0786_stokes_rank_without_cells (4 + 1 skipped at np 2, 5 at np 3), test_0786_global_evaluate_outside_domain (4), test_1154_stokes_active_region_refused (1), test_1069_boundary_normal (7 + 1 skipped), test_0768_unowned_boundary_natural_bc (4), test_1065_boundary_flux (4) and test_1167 (1). The counts are per rank.
    • Results: all passed on both builds.
  • Serial files under mpirun at np 2 and np 3, on the head:
    • Passed on every rank: test_1000_poissonNaturalBC (3), test_1010_stokesCart (6), test_1162 (8 + 3 skipped) and test_1066_rotated_meets_essential (19).
    • Fail on both builds alike, because they compare global sizes or need the whole mesh on one rank: test_1013_stokes_fields_by_solver_number (9 failures at np 2) and test_1019_boundary_flux (1 failure at np 2, a hang in _desmear at np 3). This is not this PR.
  • Probes: the label, band, field and rewire probes, at np 1, 2 and 3 on both builds, under the MPI supervisor. Logs are kept by the reviewer.

Not run:

  • The C form of the fix in finding 1 (only its Python stand-in).
  • A narrow rewire of SNES_Stokes_SaddlePt or SNES_MultiComponent. A viscosity change and a jit_route change on Stokes did not take the narrow path: development showed one kernel after each.
  • 3-D.
  • np 4.
  • The Level 1 and 2 suites in full.
  • A PETSc debug build. There PetscValidHeaderSpecific would refuse the null label in finding 1 with an error on those ranks only, not a crash; we did not check what the other ranks would do.

Underworld development team with AI support from Claude Code

…k is given them empty (review of #1211)

H1's review of de0d303:
- High: a label made after distribution, held by rank 0 only, still ended
  in a segmentation fault at np 2 and 3: the ranks agreed that it existed,
  and the others passed a null label to DMAddBoundary. A rank without the
  label now creates it empty once the ranks agree it exists.
- Medium: the missing-label refusal covered only the essential paths keyed
  on a boundary's own label. Natural conditions, and the vector and
  multicomponent essential ones, are keyed on UW_Boundaries by value, so a
  boundary the mesh lists with no faces dropped the condition silently (a
  flux of 5 on All_Boundaries gave the no-condition answer). _add_boundary
  now refuses, for every path, a label no rank holds, label values that mark
  no point on any rank, and a field the solver's DM does not have, each
  decided over the ranks, each naming what is wrong.
- Lows: the field refusal names the field and the valid range; the rewire
  test's viewer writes one file for every rank.

Tests: a natural condition on a boundary with no faces is refused; and
tests/parallel/test_1069_boundary_label_on_some_ranks_parallel.py solves a
Poisson problem with the label made on the ranks that hold cells only, on the
empty-rank triangle, against the exact solution x + y. It runs serially here
(no rank empty); under MPI it has not run on this machine. Level 1 and 2
tests: 4183 passed; the one failure is test_1123's walk on this host's gmsh
mesh, as on development.

Underworld development team with AI support from Claude Code
@lmoresi

lmoresi commented Nov 16, 2026

Copy link
Copy Markdown
Member Author

41bc3d4: answers the change request

  • High: a label held by some ranks only. Once the ranks agree that the label exists, a rank without it creates it empty (DMCreateLabel) before DMAddBoundary. Test: tests/parallel/test_1069_boundary_label_on_some_ranks_parallel.py. It uses the empty-rank triangle, makes the label only on ranks that hold cells, and checks a Poisson problem against the exact solution x + y.
  • Medium: one rule for every path. _add_boundary now refuses three things, for natural and essential conditions alike and whatever label they are keyed on:
    • a label no rank holds;
    • label values that mark no point on any rank (your flux of 5 on All_Boundaries);
    • a field the solver's DM lacks.
      Each is decided over the ranks first. The test is test_a_natural_condition_on_a_boundary_with_no_faces_is_refused.
  • A solid disc declares a Lower boundary its mesh has no label for, and asking for that label is a segmentation fault #1163: it is about asking a mesh for a label it lacks, in the mesh's label lookup. It is already labelled fixed-in-development. For A solid disc declares a Lower boundary its mesh has no label for, and asking for that label is a segmentation fault #1163's case, a condition on a declared boundary with no label, this now gives a clear refusal at setup.
  • Lows:
    • the field refusal reads "is on field 2, and the solver's DM has fields 0 to 1";
    • the rewire test's viewer writes one file, broadcast from rank 0, on the DS's communicator.

Runs. Serial, on macOS (12-core Apple M4): level 1 and 2 tests, 4183 passed. The one failure is test_1123's walk, a gmsh mesh difference on this machine, as on development. The new parallel test runs here only serially, with no rank empty. Please re-check at np 2 and 3: the new test, your rank-0-only label case for Poisson and Stokes, and the rewire test.

Underworld development team with AI support from Claude Code

@lmoresi

lmoresi commented Nov 16, 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 41bc3d4: changes requested.

Round 2 fixes what round 1 asked for:

  • A label held by some ranks: the ranks that lack it now get it empty. The rank-0-only case solves at np 2 and 3 and matches np 1.
  • One rule for every path: missing labels and empty values are refused on every path, on every rank.
  • The bad field number: refused on every rank, naming the valid range.

Two things stop it:

  1. The new parallel test cannot run in parallel. Its empty rank skips a collective call, so at np 2 and 3 MPI aborts before the solve, on this branch and on development alike.
  2. The one rule refuses a case development solves. EulerianSUPG with an inflow_value puts a natural condition on every member of mesh.boundaries. On an Annulus that includes Centre, which marks nothing, so the solve is now refused.

Both fixes are small (below).

The merge base is unchanged (development fb75e9e), so the round-1 baseline build stands. The head was built fresh, and the solver extension's timestamp was fresh.

Item by item

The label fixture is the one from round 1: the right triangle of empty_rank_fixtures, partitioned in rows. Base is made with setLabelValue only where it has faces, so at np 2 and 3 only rank 0 holds it.

item np development fb75e9e round 1 de0d303 round 2 41bc3d4
Poisson, essential on Base 1 int T = -2.261183220953e-01 same same
Poisson, essential on Base 2, 3 SEGV SEGV solves, -2.261183220951e-01 (np 2) and -2.261183220950e-01 (np 3), on every rank
Stokes, essential on Base 2, 3 SEGV SEGV solves; int v_x matches np 1 to 7e-11 relative
Poisson, natural on Base 1, 2, 3 solves, the same at each np same same
Natural flux 5.0 on All_Boundaries (no faces) 1, 2, 3 dropped silently dropped silently ValueError on every rank ("mark no point of this mesh")
Vector_Projection, essential (5, 5) on All_Boundaries 1, 2, 3 dropped silently dropped silently ValueError on every rank
Poisson essential, and #1138's bare DMPlex Stokes, on All_Boundaries (held by no rank) 1, 2, 3 SEGV ValueError on every rank ValueError on every rank
add_condition(p.field_id, ...), pressure at mesh position 2 1, 2, 3 solves without the condition RuntimeError: PETSc error code '63' ValueError on every rank: "is on field 2, and the solver's DM has fields 0 to 1"
The same condition on field 1 (contrast) 1, 2, 3 solves solves solves, the same answer
Rewire: kernels per boundary key (f0, g0, g1) after a flag rewire and two jit_route rewires 1, 2, 3 1, 2, 3, 4 1, 1, 1, 1 1, 1, 1, 1 on every rank; rewired minus fresh is 1.1e-14 (np 2) and 1.8e-14 (np 3)
tests/test_1069_boundary_wrapper_checks_and_replaces.py 1 fails 3 passed 4 passed
the same file under mpirun 2, 3 not run fails on rank 1 at np 2, then hangs 4 passed on every rank
tests/parallel/test_1069_boundary_label_on_some_ranks_parallel.py, with --with-mpi 2, 3 MPI abort before the solve not in the branch MPI abort before the solve (finding 1)
The same test with the collective fixed (our copy) 2 passes (the mesh is redistributed, so the case is not reached) not run passes
The same test with the collective fixed (our copy) 3 SEGV not run passes, error 7.1e-13
EulerianSUPG with inflow_value, Annulus 1 runs, max |S01| = 2.763e-01 not run ValueError: 'Centre[0 1 2]' ... mark no point (finding 2)
EulerianSUPG with inflow_value, UnstructuredSimplexBox 1 runs, 2.766240e-01 not run same
LevelSetSolver(far_field=0.0), Annulus, SUPG and SLCN 1 SEGV not run ValueError: "names the label 'Centre'" (finding 2)

Findings

1. High: the new parallel test aborts at np 2 and 3 on both builds, before it reaches the code it tests

The fixture calls dm.createLabel("All_Boundaries") and dm.markBoundaryFaces(...) only on ranks that hold cells.

  • Why it aborts: markBoundaryFaces communicates over the point SF, so it is collective. The empty rank skips it and enters the next collective instead.

  • What MPICH reports: Fatal error in internal_Allreduce_c: Message truncated ... 4 bytes received but buffer size is 8, exit 142, at np 2 and at np 3.

  • Where it stops: with a print after each step, rank 0 never returns from markBoundaryFaces and rank 1 has already moved on. The solve is never reached.

  • Proposed fix: mark the faces on every rank, then copy them into the real label only where they exist:

    dm.createLabel("faces_tmp")
    dm.markBoundaryFaces("faces_tmp", ALL_BOUNDARIES_VALUE)        # every rank
    faces = dm.getLabel("faces_tmp").getStratumIS(ALL_BOUNDARIES_VALUE)
    if c_end > c_start and faces is not None and faces.getSize():
        for f in faces.getIndices():
            dm.setLabelValue("All_Boundaries", int(f), ALL_BOUNDARIES_VALUE)
    dm.removeLabel("faces_tmp")
  • How that copy runs:

    • np 3: the label is on ranks 0 and 1 only. Development fails with SEGV; this branch passes with max error 7.1e-13.
    • np 2: the fixture's single cell makes Mesh redistribute, which puts the label on every rank. It passes on both builds and does not test the case; the test should say so, or run its check only from np 3.

2. Medium: the one rule refuses library code that puts a condition on every boundary in the enum, including names the mesh has no faces for

Two places loop over every member of mesh.boundaries:

  • ddt.EulerianSUPG adds a natural inflow condition to each one (systems/ddt.py, the _inflow_value branch).
  • LevelSetSolver with far_field adds a Dirichlet condition to each one (level_set.py).

Many stock meshes list Centre, with no label behind it. We built each constructor and checked every enum member against the rule. These would be refused:

  • Centre on Annulus, QuarterAnnulus, SegmentofAnnulus, AnnulusWithSpokes, AnnulusInternalBoundary, SphericalShell, SphericalShellInternalBoundary, SegmentedSphericalShell and SegmentedSphericalBall;
  • Centre on a refined Annulus;
  • Lower and Centre on the solid disc, and Lower on the solid ball.

These pass: the boxes (2-D and 3-D, with and without refinement), BoxInternalBoundary, SegmentofSphere, CubedSphere, and extract_region("Inner") of AnnulusInternalBoundary.

  • Newly refused: EulerianSUPG with inflow_value on an Annulus (radius 0.3 to 1, cell size 0.1).
    • Development runs it, max |S01| = 2.763e-01. The natural condition on Centre went in on an empty stratum and did nothing.
    • This branch raises ValueError: The boundary condition 'Centre[0 1 2]' is on label 'UW_Boundaries' with value(s) [10], which mark no point of this mesh.
    • On a box it runs on both builds with the same answer.
  • Already broken, now a clean refusal: LevelSetSolver(far_field=0.0) on the same Annulus is a SEGV on development; this branch refuses Centre by name.
  • No test or example uses either combination, so the suite does not see this.
  • Proposed fix: the two loops add conditions only on boundaries that mark points, for example [b for b in mesh.boundaries if <global stratum of b in UW_Boundaries> > 0]. A mesh method that lists the boundaries with faces would serve both. The rule for a user's own condition can stay as it is.
  • Asked for: a test of each loop on an Annulus.

3. Low: the label list in the "does not hold" message differs between ranks

For a label held on some ranks only, each rank lists its own labels. Rank 0 names Base, the others do not. It is the same refusal on every rank, but the text differs by rank. Gathering the union of names would make the message one string.

Confirmed correct

  • The C fix: a rank without the label gets it empty after the ranks agree it exists, so DMAddBoundary and its label completion run on every rank. Poisson and Stokes on a rank-0-only label match np 1 at np 2 and 3.
  • The value rule is decided over all ranks with a sum. A boundary whose faces are all on one rank, under the round-1 band and emptyband layouts, is not refused (see the parallel files below).
  • The field rule checks against the solver DM's own field count, before any PETSc call. The message names the range and the difference between a solver field number and field_id.
  • The rewire test now uses one file, and its four tests pass at np 2 and 3 under mpirun.

What was run

  • Probes, at np 1, 2 and 3 on the head (the label, field and rewire probes from round 1, plus the new-test copy and the loop probes), and on the merge base where the table says so.
  • The mesh survey: every enum member of 20 stock meshes against the rule, serially. Three constructors did not build with the arguments we gave them (BoxInternalPatch, DiscInternalBoundaries, RegionalSphericalBox).
  • Broad serial slice, 168 files: Stokes, Poisson, advection-diffusion, VE, free surface, Navier-Stokes, rotated, Nitsche, constraints and BC tests.
    • First pass, all 168 files, 3 pytest workers: it reached the 7000 s limit before it finished, with one F among about 1450 tests. The run was too slow to finish on the shared cores, so we cut the list.
    • Second pass, the 108 solver and BC files (units, save/load, swarm, visualisation and similar files dropped), with a 600 s limit per test: 821 passed, 6 skipped, 2 xfailed, 2 failed. No test in either pass was refused by the new rule: the log has no "mark no point" or "does not hold" text.
    • The two failures were our 600 s limit, not the PR: test_1061_stress_forward_history::...maxwell_start_up ("Timeout >600 s"), and test_1064_constrained_spherical_shell_response::test_default_constrained_matches_zhong_velocity_response. The second shows as PETSc error 101, which is the timeout raised inside the KSP monitor. Run alone, each was still running after 30 min on both builds, and we stopped them; they are slow, not refused.
  • Round 1's tests/parallel/ files at np 2 and 3 with --with-mpi, one file per job: test_0856_boundary_label... (14), test_0786_stokes_rank_without_cells (4 + 1 skipped at np 2, 5 at np 3), test_0786_global_evaluate_outside_domain (4), test_1154_stokes_active_region_refused (1), test_1069_boundary_normal (7 + 1 skipped), test_0768_unowned_boundary_natural_bc (4), test_1065_boundary_flux (4) and test_1167 (1). All passed on every rank, at both rank counts.
  • Logs are kept by the reviewer.

Not run: the full 168-file slice to completion; np 4; 3-D probes; a PETSc debug build; the full Level 1 and 2 suites; the examples under docs/, which were grepped only.

Underworld development team with AI support from Claude Code

…marks on every rank (review of #1211, round 2)

- EulerianSUPG's inflow condition and LevelSetSolver's far field loop over
  Mesh._boundaries_that_mark_points(), the enum members whose value marks a
  point of UW_Boundaries on some rank. An Annulus lists Centre and has no
  faces for it; the one refusal rule refused the inflow case, which
  development ran, and the far field was a segmentation fault on development.
  A condition a user names on such a boundary is still refused.
- The "does not hold" message lists the union of every rank's labels, so it
  is the same text on every rank.
- test_1069_boundary_label_on_some_ranks: markBoundaryFaces is collective, so
  every rank marks a scratch label and the real label is made where faces are.
  It runs from np 3 (at np 2 the one-cell fixture is redistributed onto both
  ranks) and asserts some rank lacks the label; test.sh runs it at np 3.
- Annulus tests of the boundary list, the Eulerian inflow and the level-set
  far field (SUPG and SLCN); the last three fail on the previous head.

Underworld development team with AI support from Claude Code
@lmoresi

lmoresi commented Nov 16, 2026 •

Copy link
Copy Markdown
Member Author

Response to the round-2 review (head aae8d88)

1. The parallel test.

  • Every rank now marks a scratch label, since markBoundaryFaces is collective, and the real label is made only on the ranks that hold faces. This is the reviewer's fix.
  • The test skips below np 3, because at np 2 the fixture's single cell is redistributed onto both ranks.
  • It now asserts that some rank lacks the label, so a pass means the case was reached.
  • scripts/test.sh runs it at np 3.
  • We have not run it under MPI on this machine. The np 3 run is with the reviewer.

2. Library loops over every boundary.

  • EulerianSUPG's inflow condition and LevelSetSolver's far field now loop over Mesh._boundaries_that_mark_points(). These are the enum members whose value marks a point of UW_Boundaries on some rank, summed over the ranks.
  • On the Annulus this list is Lower, Upper and All_Boundaries.
  • A condition a user names on Centre is still refused.
  • We added four serial tests on that Annulus (radius 0.3 to 1, cell size 0.1):
test previous head 41bc3d4 this head
the boundary list AttributeError passes
EulerianSUPG inflow value 1 under radial outflow, one step of 0.05 ValueError: 'Centre[0]' ... mark no point mean on the inner circle 0.83873 (baseline, rel 1e-6); outer circle below 1e-8
LevelSetSolver(far_field=0.0), SUPG ValueError: names the label 'Centre' volume 0.129452 to 0.128539 (baseline, rel 1e-6)
the same, SLCN the same ValueError volume 0.129452, held to 1e-15

3. The message. The "does not hold" message now lists the union of every rank's labels, so the text is the same on every rank.

Run here, serially:

  • tests/test_1069_boundary_wrapper_checks_and_replaces.py: 8 passed.
  • The transport and level-set files: test_1055, 1056, 1057, 1059, 1105, 1078 and 0075. 74 passed and 1 skipped (shapely is not installed).

Tolerances and coordinate matches in this commit:

  • the two baselines at rel 1e-6;
  • the outer circle selected by r > 0.99 and the inner by r < 0.31 (the radii are 1 and 0.3).

Left as it is: the loops still include All_Boundaries, as they did on development. On this Annulus, the 84 points of All_Boundaries in UW_Boundaries are all also in Lower (20) or Upper (64). So every such face carries the condition under two values. We have not measured whether that doubles the integrated term. It is outside this PR, and we have passed it on separately.

Underworld development team with AI support from Claude Code

@lmoresi

lmoresi commented Nov 16, 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 aae8d88: changes requested.

The three items from round 2 are fixed:

  • The parallel test now reaches its case and passes from np 3. Development fails it with SEGV at np 3 and np 4.
  • The library loops run on an Annulus again. The inflow answer equals development's.
  • The "does not hold" message is now the same text on every rank.

Two things remain, both in the new tests and their surroundings:

  1. Medium: three of the four new Annulus tests fail on Linux. They compare with constants to a relative 1e-6, and the constants come from another machine's mesh.
  2. Medium: the weak inflow term of EulerianSUPG is applied twice on every wall face. This is the case on development too. The new tests' constants record the doubled answer. The measurement has its own section below.

The merge base is unchanged (development fb75e9e), so the earlier baseline build stands. The head was built fresh, and the solver extension's timestamp was fresh.

Item by item

item np development fb75e9e round 3 aae8d88
test_1069_boundary_label_on_some_ranks_parallel, --with-mpi 2 skipped skipped, with the stated reason (one cell, redistributed onto both ranks)
the same 3 SEGV, exit 59 passed on every rank
the same 4 (4 ranks on 4 cores) SEGV, exit 59 passed on every rank
EulerianSUPG(inflow_value), Annulus(0.3, 1, cellSize 0.1), 2 steps 1 max |S01| = 2.763164e-01 2.763164e-01, the same
LevelSetSolver(far_field=0.0), the same Annulus, SUPG and SLCN 1 SEGV runs (volume 1.83158e-01 and 1.84659e-01)
_boundaries_that_mark_points() against an independent collective count of UW_Boundaries, 23 meshes 1 the same list for every mesh, and the same on every rank
the same, box and Annulus with an empty rank (emptyband) 3 the same list on all three ranks (the empty rank included), equal to the count
the "does not hold" message, on a label held by rank 0 only 2, 3 one text on every rank (the union: Base, Rim, UW_Boundaries, celltype, depth)
Poisson and Stokes essential on the rank-0-only Base label 2, 3 SEGV match np 1 (as in round 2)
Natural flux 5.0 and Vector_Projection essential on All_Boundaries 2, 3 dropped silently refused, the same text on every rank
Field number 2 on a two-field Stokes 2, 3 solves without it refused on every rank, naming fields 0 to 1
Rewire: kernels per boundary key, rewired against fresh 2 1, 2, 3, 4 kernels 1 kernel on every rank; difference 1.1e-14
tests/test_1069_boundary_wrapper_checks_and_replaces.py 1 5 passed, 3 failed (finding 1)
the same file under mpirun 2 the same 3 fail on both ranks
the same file under mpirun 3 the ranks diverge on the failures, and MPI aborts (exit 63)
Round 1's 8 tests/parallel/ files, --with-mpi 2, 3 all pass on every rank
test_1059_stress_transport -k inflow 1 1 passed

Findings

1. Medium: three of the new Annulus tests fail on Linux

The three tests are test_the_eulerian_inflow_value_on_an_annulus and test_the_level_set_far_field_on_an_annulus[supg] and [slcn]. Each compares with a constant to a relative 1e-6:

  • inflow mean near the inner wall: 0.8387198 obtained, 0.8387283 expected;
  • level set: 0.1301395 obtained, 0.1294521 expected.

The level-set volume differs by 0.5 % before any solve. So the gmsh mesh (762 cells here) or the initial field differs from the machine where the constants were taken. The PR body already notes that gmsh builds different meshes on macOS and Linux. CI on Linux would fail these.

Under mpirun at np 3 the three failures diverge the ranks, and MPI aborts. That does not matter for CI, which runs this file serially.

Proposed fix: compare each run with a reference built in the same test, on the same mesh, rather than with a constant:

  • Inflow: a run with the condition imposed once by hand on one boundary name (see below).
  • Level set: the property the test cares about, that it runs and the volume is unchanged by the far field.

2. Medium: the inflow term of EulerianSUPG acts twice on every wall face (also on development)

Details in the next section. In short:

  • _boundaries_that_mark_points() returns Lower, Upper, All_Boundaries on an Annulus. Every face of All_Boundaries is also a face of Lower or Upper, so the weak inflow term is added twice on every wall face.
  • The answer moves by up to 0.054 at the wall and 0.0055 inside, on a field of size 0.25.
  • The new test's constant was measured with the doubled term, so it locks the doubling in.
  • Fix: leave All_Boundaries out of the library loops when the other boundaries cover it. Or, more simply, loop over All_Boundaries alone where the mesh has it, since the term vanishes where the flow does not enter.
  • The far field of LevelSetSolver is a Dirichlet value, and repeating it changes nothing (measured).

This is older than the PR, but the PR's helper and its new tests now carry it forward. Your call whether it is fixed here or in an issue. If it goes to an issue, the test constants still need finding 1's change.

3. Low: _boundaries_that_mark_points() counts points, not faces

The helper counts any point of UW_Boundaries. Its comment says boundaries "with faces". Two of our meshes show the difference:

  • The solid SphericalShell (radiusInner=0): the helper returns Centre, which is a vertex with no face.
  • AnnulusInternalBoundary(...).extract_region("Inner"): the helper returns Inner, which is a region label.

On these, the level-set far field would add a Dirichlet condition on the centre vertex, or on the region's points, if those labels carry their points through DMPlexLabelComplete. We have not run either case. Development loops over the whole enum and does the same, so nothing new breaks. A count restricted to height-1 points (faces) would match the name and the comment.

The doubling measurement

Setup: Annulus(radiusInner=0.3, radiusOuter=1.0, cellSize=0.1), 762 cells, on the head. The PR's helper returns Lower, Upper, All_Boundaries.

  • Face counts: UW_Boundaries value 1001 (All_Boundaries) holds 84 faces. All 84 are also in value 1 (Lower, 20 faces) or value 2 (Upper, 64 faces). A DMLabel point can sit in several strata, and each natural condition has its own DMAddBoundary and weak form, so each such face is integrated once per condition.
  • The flow: EulerianSUPG on a symmetric tensor, velocity (0.5, 0), inflow value [[1, 0.25], [0.25, -1]], 4 steps of 0.05.
  • The variants: we replaced the helper's list:
variant list max |S01| mean S01 on the inlet wall (r > 0.99, x < -0.5; target 0.25)
A, development's loop and the PR's helper Lower, Upper, All_Boundaries 0.28735643 0.25045442
B, each face once Lower, Upper 0.31132529 0.25369929
C, once, imposed by hand on one name All_Boundaries 0.31132529 0.25369929
D, each face twice on purpose Lower, Upper, Lower, Upper 0.28735643 0.25045442
  • The term doubles. A equals D to every bit, and B equals C to every bit; A and B differ.
  • Size of the effect:
    • The largest difference, A against B, is 0.054, on the outer wall at x = 0 (A 0.158, B 0.103), where the inflow switches on.
    • Away from the walls (x > 0.2, 0.4 < r < 0.9) it is 5.5e-3.
    • The field's scale is 0.25.
  • Which is wrong: the term as written in ddt.py is meant once per face. B and C are the stated formulation, and A is twice the penalty. The doubled run is not obviously worse by these two measures (its inlet mean is nearer 0.25), but it is a different discretisation from the one documented.
  • Every mesh: every stock mesh lists All_Boundaries and marks it on the file paths, so every EulerianSUPG inflow run has the doubled term, on development and on this head.
  • Development: its loop is the whole enum (the same as A, plus an empty Centre). At 2 steps it gives the same max |S01| as A on the head (2.763164e-01).

Level set, far field 0.0, 4 steps of 0.02, the same Annulus:

advection A (with All_Boundaries) B (Lower, Upper) C (All_Boundaries only)
SUPG volume 1.817511578818e-01 the same the same
SLCN volume 1.846586924874e-01 the same the same

The fields are identical to every bit (the largest difference is 0). A Dirichlet value imposed twice is the same constraint, so this is idempotent and harmless.

What was run

  • Build: the head, fresh in its worktree, against the earlier merge-base build.
  • Probes:
    • the new parallel test at np 2, 3 and 4 on both builds;
    • the loop, label, field and rewire probes;
    • the helper survey of 23 meshes at np 1, and box and Annulus at np 3 with an empty rank;
    • the doubling variants A to D and the level-set variants.
  • Tests:
    • the PR's test file at np 1, 2 and 3;
    • round 1's 8 parallel files at np 2 and 3 (all pass);
    • test_1059 -k inflow.
  • Logs are kept by the reviewer.

Not run:

  • the broad serial slice again (round 2 ran it, and this round changes only the loops, the helper and a message);
  • test_1105_levelset_rotation (200 steps);
  • the level-set far field on the solid shell or the extracted region (finding 3);
  • 3-D doubling;
  • a PETSc debug build.

The full survey under emptyband at np 3 stopped in our own probe's face-count code on the empty rank, not in the helper; the helper itself was checked there with the staged probe.

Underworld development team with AI support from Claude Code

…#1211, round 3)

EulerianSUPG's weak inflow condition went in on every boundary that marks
faces, which includes All_Boundaries and the named boundaries sharing its
faces, so each exterior face's term went in twice; on development it was on
every enum member, with the same doubling. Both whole-boundary loops now use
Mesh._boundaries_covering_the_exterior_once(): All_Boundaries alone where it
marks faces, otherwise every boundary that marks a face. This changes every
EulerianSUPG result with an inflow_value; the level-set far field is a
Dirichlet value and is unchanged.

Mesh._boundaries_that_mark_faces() counts height-1 points, so a boundary of
vertices (Centre on a solid shell) or of cells is left out.

The Annulus tests compare with in-test references: the inflow default
against a run on Lower and Upper (once by construction), and the doubled run
must differ; the level-set walls hold the far field (one value under SLCN's
mass shift) and the volume is held. No constant from this machine's mesh.

Underworld development team with AI support from Claude Code
@lmoresi

lmoresi commented Nov 16, 2026

Copy link
Copy Markdown
Member Author

Response to the round-3 review (head 3509177)

The doubled inflow.

  • Both whole-boundary loops now use Mesh._boundaries_covering_the_exterior_once(): All_Boundaries alone where it marks faces, otherwise every boundary that marks a face.
  • The PR body now says that this changes every EulerianSUPG result with an inflow_value on development, and that internal surfaces no longer get the inflow term.
  • The test runs the default, then a run on Lower and Upper (once by construction), then a run on Lower, Upper and All_Boundaries (twice), each for two steps:
comparison measured asserted
default against once 0.0 1e-10 absolute
twice against once, max difference 0.074 above 1e-3
  • On the previous head the test fails, because there the default is the doubled run.

Constants from this machine's mesh.

  • These are gone from the tests. The inflow test is the comparison above, plus an inner-circle mean above 0.5 and the outer circle below 1e-8.
  • The level-set test checks that the wall values are equal to each other to the bit, and equal to 0 for SUPG. SLCN's mass correction shifts the whole field by one constant, so its walls carry that constant. The volume is held to 1e-10 relative for SLCN and to 2 % for SUPG (measured 0.7 %).

Points against faces. Mesh._boundaries_that_mark_faces() counts height-1 points of UW_Boundaries, so a boundary of vertices or of cells is left out. We tested it on the Annulus only. The solid shell and extract_region cases are not in a test.

Run here, serially: test_1069 and the transport and level-set files (1055, 1056, 1057, 1059, 1105, 1078, 0075): 82 passed, 1 skipped (shapely is not installed).

Underworld development team with AI support from Claude Code

@lmoresi

lmoresi commented Nov 16, 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 3509177: ready to merge on green from this review.

This head changes every EulerianSUPG inflow result, on every mesh:

  • Each exterior face once: the inflow term goes on each exterior face once, not twice.
  • No term on internal surfaces: on a mesh with an internal surface, the term is no longer added there.

Both are corrections of development's behaviour, measured below. The PR body should say so, since every saved inflow result moves.

The LevelSetSolver far field is unchanged (Dirichlet; measured identical).

One defect older than this PR is outside it and needs an issue: LevelSetSolver's SLCN mass correction is applied per rank (finding 1). The PR's new level-set test asserts the property that defect breaks, so the test fails under mpirun. CI runs that file serially, so it does not block.

Build: the merge base is unchanged (development fb75e9e). This round changes only .py files since aae8d88: discretisation_mesh.py, level_set.py and systems/ddt.py. We copied those three files over the aae8d88 build and compared each copy byte for byte with the head.

Item by item

item np development fb75e9e 3509177
tests/test_1069_boundary_wrapper_checks_and_replaces.py 1 8 passed (round 3's three Linux failures are gone)
the same file under mpirun 2 7 passed, 1 failed on one rank (level_set_far_field_on_an_annulus[slcn], finding 1), then a hang until the supervisor kills it
the same file under mpirun 3 the ranks diverge on the same test; MPI abort
test_1069_boundary_label_on_some_ranks_parallel, --with-mpi 3, 4 SEGV (round 3) passed on every rank
_boundaries_that_mark_faces() against an independent collective count of faces in UW_Boundaries 1 (20 meshes), 3 with an empty rank (7 meshes) matches on every mesh, and gives the same list on every rank
solid SphericalShell: is Centre listed? 1, 3 no (only Upper, All_Boundaries)
AnnulusInternalBoundary(...).extract_region("Inner"): is Inner listed? 1, 3 no (Lower, Internal, All_Boundaries; Inner marks 0 faces)
_boundaries_covering_the_exterior_once() 1, 3 [All_Boundaries] on every mesh; on all 20 meshes its face count equals the number of faces with one cell (the exterior)
Doubling variants on Annulus(0.3, 1, 0.1): default against B (Lower, Upper) and C (All_Boundaries) 1 default = A (doubled) default = B = C, bit for bit; A = D differs by 5.4e-2
Level-set far field, default list, SUPG and SLCN 1 volumes 1.817511578818e-01 and 1.846586924874e-01, as in every variant of round 3
Internal surface: inflow term dropped from Internal 1 development equals the old loop, bit for bit see the section below
Poisson and Stokes essential on the rank-0-only Base label 2, 3 SEGV match np 1
Refusals: All_Boundaries held by no rank; natural flux 5.0 and Vector_Projection essential on it 2, 3 SEGV, or dropped silently refused, with one text on every rank
Field number 2 on two-field Stokes 2, 3 solves without it refused on every rank, naming fields 0 to 1
Rewire: kernels per key, rewired against fresh 2 1, 2, 3, 4 1 on every rank; difference 1.1e-14
The 11 test files that use inflow_value, EulerianSUPG, LevelSetSolver or a far field (test_0075, 1057_ddt_transport_plugin, 1055, 1059, both 1056, 1078, 1105, 1020, 0014, 0015) 1 156 passed, 1 skipped

The internal surface

Setup:

  • Mesh: AnnulusInternalBoundary(radiusInner=0.3, radiusInternal=0.65, radiusOuter=1.0, cellSize=0.1).
  • Flow: EulerianSUPG on a symmetric tensor, velocity (0.5, 0), inflow value [[1, 0.25], [0.25, -1]], 4 steps of 0.05.

The inflow mask on Internal is not zero. The integral of -min(u·n, 0) over Internal (with mesh.Gamma) is 0.649. It is 1.000 over Upper. A uniform flow crosses the internal circle, so u·n < 0 on half of it whichever way the normal points.

  • The old loop: Lower, Internal, Upper, All_Boundaries, which is aae8d88's list and the same as development's whole enum. It applied the inflow penalty there and pulled the field towards the inflow value where the flow merely passes through.
  • Measured: on the x < 0 half of Internal, the mean S01 is 0.120 with the term on Internal, against -0.0007 without it.
comparison everywhere on Upper on Lower on Internal interior (away from the three circles)
this head against Lower + Upper by name 0 0 0 0 0
this head against this head + Internal 0.147 1.1e-3 1.3e-3 0.144 0.095
this head against the old loop (= development, bit for bit) 0.147 0.051 0.046 0.144 0.095

What changes:

  • Dropping the term on Internal is a correction, not a no-op. The term moved the answer by up to 0.144 on the surface and 0.095 inside, on a field of size 0.25.
  • The exterior condition itself is unchanged. This head equals the exterior named once, bit for bit.
  • The wall values still move a little: about 1e-3 between this head and the head plus Internal. That comes through the transported interior, not through the wall term.
  • Against development the walls move by 0.05. Most of that is the removed doubling of the exterior term.

Findings

1. Medium (older than this PR, needs an issue): LevelSetSolver's SLCN mass correction shifts each rank by its own constant

After one step, the far-field walls should all hold one value, the far field plus the correction shift. At np 2 they do not.

mesh np 1 development, np 2 this head, np 2
Annulus(0.3, 1, 0.1) one value, 3.1265e-4 SEGV 2.7547e-4 on rank 0's owned nodes, 3.3257e-4 on rank 1 and on rank 0's ghosts
UnstructuredSimplexBox(-1..1, 0.1) 1.4350e-4 1.3734e-4 and 1.5134e-4 the same as development
  • Same on the box: the box gives the same numbers on both builds, so the defect is not in this PR.
  • Rank-local: the shift is computed or applied per rank. Ghost nodes carry the neighbour's shift, and neither rank's value is the serial one.
  • The PR's test: test_the_level_set_far_field_on_an_annulus[slcn] asserts walls.max() == walls.min() on the local array. So it fails on one rank under mpirun, and the ranks then diverge. In CI the file runs serially, so this does not block the PR.
  • Asked for: an issue for the mass correction. Optionally, a note in that test that it is serial-only until the issue is fixed.

2. Low: the fallback in _boundaries_covering_the_exterior_once() can double a face again

Where All_Boundaries marks no face, the helper returns every boundary that marks faces. That list can include internal surfaces and overlapping sets:

  • Internal on the internal-boundary meshes;
  • LowerPlus and UpperPlus on AnnulusWithSpokes (27 and 42 faces, against 18 for Lower and 33 for Upper);
  • Slices on the segmented shells.

On every stock mesh we built, All_Boundaries marks exactly the exterior faces, so the fallback is never taken. A DMPlex wrapped without All_Boundaries would take it. Read only, not run. Marking the exterior faces where the label is missing, as the file paths do, would remove the fallback.

Confirmed correct

  • Doubling fixed: _boundaries_covering_the_exterior_once() returns All_Boundaries alone on all 20 meshes. Its face count equals the exterior face count on every one, so each exterior face carries the inflow term once. The default answer equals the by-name and by-hand single imposition bit for bit.
  • _boundaries_that_mark_faces() counts height-1 points only. Centre (a vertex on the solid shell, nothing on the annulus) and Inner (a region) are left out. It is collective, and identical on every rank, including an empty rank at np 3.
  • The new parallel test passes at np 3 and 4. It skips at np 2 with its stated reason. Development gives SEGV at np 3 and 4 (round 3).
  • The new test file no longer uses constants from another machine, and passes serially on Linux (8 of 8).
  • Round 1 and 2 behaviour holds at np 2 and 3: the rank-0-only label, the refusals, the field number and the rewire.

What was run

  • Probes:
    • the helper survey with an independent face count and an exterior check, at np 1 (20 meshes) and np 3 with an empty rank (7 meshes);
    • the doubling variants;
    • the internal-surface variants, with development for the old loop;
    • the level-set wall probe on an annulus and a box, at np 1 and 2 on both builds;
    • the regression probes at np 2 and 3.
  • Tests:
    • the PR's file at np 1, 2 and 3;
    • the new parallel test at np 3 and 4;
    • the 11 files that touch the changed loops, serially with 3 workers (156 passed, 1 skipped).
  • Logs are kept by the reviewer.

Not run:

  • the fallback path of finding 2;
  • SphericalShellInternalBoundary with an inflow (the 2-D internal annulus stood in for it);
  • the broad slice of round 2 again;
  • a PETSc debug build.

Underworld development team with AI support from Claude Code

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 6f0bfdd (development merged in): ready to merge on green from this review.

The merge brings in compiled changes from development (petsc_generic_snes_solvers.pyx, petsc_quadrature_fe.pyx, function/_function.pyx), so the head was rebuilt fresh. The build ended with "BUILD EXIT 0", and the solver extension carries the build's timestamp.

check np result
tests/parallel/test_1069_boundary_label_on_some_ranks_parallel.py, --with-mpi, under the supervisor 3 passed on all 3 ranks
the same 4 passed on all 4 ranks
tests/test_1069_boundary_wrapper_checks_and_replaces.py, serial 1 8 passed, including test_the_eulerian_inflow_is_applied_once_per_face_on_an_annulus and test_the_boundaries_covering_the_exterior_once_on_an_annulus
Poisson essential on a label held by rank 0 only 3 the np 1 answer on every rank (int T = -2.261183220950e-01)
Stokes essential on the same label 3 the np 1 answer on every rank (int v_x agrees to 7e-11 relative)
Rewire: kernels per boundary key after three rewires, rewired against fresh 3 1 kernel on every rank; difference 1.8e-14

LevelSetSolver's rank-local SLCN mass correction, in the previous comment, still needs its own issue. It is older than this PR and does not affect these checks. Logs are kept by the reviewer.

Underworld development team with AI support from Claude Code

…field_id

The style gate's field-number rule refuses add_condition(var.field_id, ...)
in tests too. The test now passes 2 for the two-field solver, standing for
the #1170 mistake, and needs no third variable.

Underworld development team with AI support from Claude Code
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