Skip to content

A datum's net flux into a declared-enclosed domain: refused, warned or attributed by its surface integral (UNFILED 36) - #1296

Merged
lmoresi merged 6 commits into
developmentfrom
bugfix/rotated-datum-floor-diagnosis
Nov 24, 2026
Merged

lmoresi merged 6 commits into
developmentfrom
bugfix/rotated-datum-floor-diagnosis

Conversation

@lmoresi

@lmoresi lmoresi commented Nov 20, 2026 •

Copy link
Copy Markdown
Member

A wall-normal datum's net flux through a boundary the user declared enclosed is now measured by the datum's own surface integral. A real flux is refused or warned about by size, and a discretisation-level one is reported as such. Part of UNFILED 36.

The case

Setting petsc_use_pressure_nullspace = True declares the domain enclosed: no open or traction wall. An incompressible flow there has no net boundary flux, so a rotated free-slip datum g = u·n with a nonzero surface integral has no solution. Development solved such cases in the pressure-gauge quotient space and warned after the solve, or ended in KSP_DIVERGED_DTOL.

Development's post-solve warning ("carries a net boundary flux ... violates mass conservation") also fired on legitimate runs, whose walls' nodes were slid along an unchanged circle.

The test

With the null space declared and a datum present: F = ∫ g ds and S = ∫ |g| ds over the walls that carry it, by facet quadrature at the mesh's qdegree (uw.maths.BdIntegral, collective, the same on every rank). Then:

F/S action
> 2e-2 refused at the cold-start lift, before any iteration: the net flux, its fraction of S, and both remedies (make the integral zero on the walls as they are, or open a wall and unset the null space)
1e-3 to 2e-2 warned before the solve: a real net flux of the datum on the walls as they are (a moved wall changes it), so the solution violates mass conservation by that amount
<= 1e-3 a large projected-out gauge component after the solve is put down to the wall discretisation (nodes moved along the wall), with its size, instead of a conservation violation

Nothing changes without the declared null space.

Measured (macOS, 12-core Apple M4, serial)

The annulus runs are 0.5 to 1.0, moved with mesh.deform: a radial wobble off the circle, r(1 + off·cos3θ·(r - 0.5)/0.5), and a slide along it, θ + slide·sin 2θ. The datum is 0.1 cos(2·atan2(y, x)) on Upper.

off slide h F S F/S reading this PR
0 0 0.2 1.8e-13 0.399 4.6e-13 zero silent
0.1 0 0.2 5.0e-10 0.408 1.2e-9 zero silent
0 0.1 0.2 -2.0e-4 0.400 5.1e-4 discretisation (h²) note
0 0.1 0.1 -5.0e-5 0.400 1.3e-4 discretisation (h²) note
0.1 0.1 0.2 -2.9e-3 0.408 7.1e-3 real, independent of h warned
0.1 0.1 0.1 -2.8e-3 0.409 6.9e-3 real warned
0.2 0.2 0.2 -2.1e-2 0.435 4.8e-2 real refused
0.2 0.2 0.1 -2.1e-2 0.436 4.9e-2 real refused
box, 0.1 sin πx on Top 0.1, 0.05 6.37e-2 6.37e-2 1.00 real (0.2/π) refused

Why sliding plus moving off the circle is a real flux. Sliding nodes that sit at θ-dependent radii changes the wall's shape. u·n = 0.1 cos 2θ on that wall has a net flux, unlike on the circle.

Thresholds:

  • The refusal threshold, 2e-2, is 40x above the coarse discretisation level (5.1e-4 at h 0.2) and 50x below the box.
  • From 1e-3 it warns rather than refuses, because real and discretisation fluxes can mix at coarse h.
  • Two orders of margin on each side is not available in this range, and the warning band is the answer to that.

A first version of this PR used the discrete sum of the lifted right-hand side over the pressure rows. It refused the slide-only runs (ratios 5.7e-3 to 0.41, not falling with h), and was replaced before merge.

Tolerances and coordinate matches

  • Thresholds: refuse at F/S > 2e-2, warn from 1e-3, as measured above.
  • No coordinate matches.

Tests

  • tests/test_1295_rotated_datum_net_flux_refused.py:
    • refused: the closed box (fails on development: no raise), and the moved annulus at 4.9e-2;
    • warned: the moved annulus at 7.1e-3, with the warning text checked;
    • discretisation note, not the conservation warning: slide only;
    • silent: the annulus as built;
    • accepted: the box with one open, natural wall.
  • tests/test_1115_rotated_solve_raises_on_failure.py:
    • its datum fixture was a constant 0.1 on the inner wall of an annulus declared enclosed, a real net flux;
    • it is now 0.1 cos 2θ, which keeps a datum in its tolerated-failure test;
    • its assertions are unchanged.
  • Serial: the 50 rotated and fault test files with test_0052, at levels 1 and 2: 585 passed, 1 skipped.

Not in this PR (UNFILED 36's other parts)

  • The NaN/DTOL at tight tolerances comes from the rotated pressure sub-solve's rtol, 0.1·tol, unattainable on a noise right-hand side. A floor there changes when sub-solves stop: a register-row proposal, measured after An uncached rotated solve measures its first residual without the gauge (#884) #1262 merges.
  • The annulus residual floor (about 4e-10 relative with a datum) is under investigation.
  • Detecting an enclosed domain without the user's declaration is a proposal for the maintainers.

Underworld development team with AI support from Claude Code

… the lift (UNFILED 36)

With the pressure null space declared (petsc_use_pressure_nullspace) the
domain is enclosed, so a wall-normal datum must carry no net flux. The
lifted right-hand side carries that flux on the pressure rows: its sum is
-0.2/pi for u.n = 0.1 sin(pi x) on a unit box's top. Such a datum has no
solution; the solve converged in the pressure-gauge quotient space and only
warned afterwards. It is now refused at the cold-start lift, before any
iteration, when |sum of b_p| > 1e-8 ||b_p|| (both reductions collective),
with a message naming the net flux and the two remedies. Nothing changes
without the declared null space.

test_1295: the enclosed box with a net flux is refused (it fails on
development); the annulus with u.n = 0.1 cos 2θ and the box with one open
wall are accepted. test_1115's datum fixture was a constant 0.1 on the
inner wall of a declared-enclosed annulus, a net flux; it is now 0.1 cos 2θ,
which keeps a datum in its tolerated-failure test without one.

Underworld development team with AI support from Claude Code
Copilot AI balanced review requested due to automatic review settings November 20, 2026 13:27

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 20, 2026

Copy link
Copy Markdown
Member Author

Adversarial review, round 1 (head 8297624)

  • Rank asymmetry. use_pnull is a solver attribute, the same on every rank. bp.sum() and bp.norm() are collective reductions over the pressure sub-vector, so every rank takes the same branch. The break leaves the loop on every rank together, and test_0052 passes.
  • Teardown. The raise goes through linear_failure, which the solver raises after the post-loop teardown, the same route as Rotated free-slip solve whose preconditioner fails returns v = 0 with only a warning #907's cold failures. bhat and Fhat are destroyed before the break. No dhat or KSP exists yet at the lift; the context teardown handles ctx is None.
  • Scope. The check runs only at the cold-start lift (lift_datum and iters == 0). A warm start with an incompatible datum still reaches the existing post-solve warning: not refused, and not made worse.
  • Threshold. The measured ratios are 3.4 for a real flux and 5e-12 to 5e-13 for a flux-free datum, against 1e-8. On a deformed faceted wall the node-vs-facet normal mismatch gives a small discrete flux; the source records an unprojected floor of rel about 2e-3 there. That could exceed 1e-8·||b̂_p|| for a flux-free datum on a deformed wall. Not measured: a declared-enclosed, deformed-wall datum case. If one exists in the tree, it should be run before merge; a grep finds none in tests/.
  • Changed test. test_1115's fixture had a constant datum on an enclosed annulus. The test is about the tolerated failure path, not the datum's shape, so a flux-free shape keeps its intent.

One open finding (above): the threshold against a deformed faceted wall is not measured.

Underworld development team with AI support from Claude Code

@lmoresi
lmoresi marked this pull request as draft November 20, 2026 13:31
@lmoresi

lmoresi commented Nov 20, 2026

Copy link
Copy Markdown
Member Author

Do not merge: back to draft. A measurement on deformed annuli refutes the refusal's threshold.

Moving an annulus's nodes along its walls (mesh.deform, θ + 0.1 sin 2θ; the walls stay exact circles) gives a flux-free 0.1 cos 2θ datum a discrete Σ b̂_p / ||b̂_p|| of 5.7e-3. With the walls also moved off the circle, it reaches 0.41 (h 0.1 and 0.2). This PR refuses those runs, though their continuous flux is zero, and development solves them. A real net flux, the box, gives 3.4. The ratio doesn't fall with h, so no threshold on it separates the two.

The right test compares the datum's continuous surface integral, by quadrature on the facets, with zero. That is a design question, and goes to the maintainers with the enclosure-detection proposal. The full table is with the dev hub.

The same runs also show that development's existing post-solve warning ("carries a net boundary flux ... violates mass conservation") fires on these legitimate slid-wall runs, with a gauge residual that falls as h³. That is a false alarm, recorded under UNFILED 36.

Underworld development team with AI support from Claude Code

…ribute it by F/S (UNFILED 36)

The discrete test (the lifted right-hand side summed over the pressure rows)
refused legitimate runs: nodes slid along an unchanged circle gave a
flux-free cos 2θ datum a discrete ratio of 5.7e-3 to 0.41. The test is now
the datum's own surface integral, F = ∫ g ds against S = ∫ |g| ds over the
walls that carry it (facet quadrature, collective), when the pressure null
space is declared:

- F/S > 2e-2: refused at the cold-start lift, before any iteration;
- 1e-3 < F/S <= 2e-2: warned, as a real net flux of the datum on the walls
  as they are (a moved wall changes it), a mass-conservation violation;
- F/S <= 1e-3: a large projected-out gauge component after the solve is
  put down to the wall discretisation (nodes moved along the wall), where
  it used to be reported as a conservation violation.

Measured: slide-only 5e-4 at h 0.2, falling as h^2; walls moved off the
circle and slid, 7e-3 and 4.9e-2, independent of h; a closed box 1. The
refusal threshold is 40x above the coarse discretisation level and 50x
below the box; the middle band warns, since real and discretisation fluxes
can mix at coarse h.

test_1295: the box and a moved annulus at 4.9e-2 refused; one at 7e-3
warned (text checked); slide-only given the discretisation note; the annulus
as built silent; the box with an open wall accepted.

Underworld development team with AI support from Claude Code
@lmoresi lmoresi changed the title A datum with a net flux into a domain declared enclosed is refused at the lift (UNFILED 36) A datum's net flux into a declared-enclosed domain: refused, warned or attributed by its surface integral (UNFILED 36) Nov 20, 2026
@lmoresi

lmoresi commented Nov 20, 2026

Copy link
Copy Markdown
Member Author

Adversarial review, round 2 (head f5456ca), on the rebuilt test.

  • Rank asymmetry. F and S come from BdIntegral.evaluate(), a collective quadrature with the same value on every rank. datum_flux_ratio is therefore uniform, so the refusal's break, the warning and the note are taken alike everywhere (the prints are mpi.pprint, rank 0). test_0052 passes.
  • Cost. Two boundary integrals per datum wall per solve, computed only with the null space declared and a datum present. Each is JIT-compiled once, then cached.
  • The refusal runs at the cold-start lift. A warm start of a refused datum cannot follow a refused cold start, and a warm start of a datum changed in between gets the warning band and the post-solve note, as before.
  • Units. A dimensional datum enters BdIntegral as its expression. F/S is a ratio, so units cancel. Not tested with a units model.
  • Fails first. The box (no raise on development) and the 4.9e-2 case fail on development by the measurements above. The warning and note cases would get development's conservation message. The new tests were not run against development's build in this round.

No findings.

Underworld development team with AI support from Claude Code

@lmoresi

lmoresi commented Nov 20, 2026

Copy link
Copy Markdown
Member Author

Parallel review by H7 (a Claude review session running parallel probes on a 96-thread Linux workstation: Intel Xeon Gold 6240R, MPICH) at f5456ca. The PR changes only rotated_bc.py, so "development" below is the branch's build with the merge base's rotated_bc.py (1e10c63) placed in it. Runs were under the MPI supervisor. Empty-rank and band layouts came from a shell-partition hook: emptyband leaves rank 2 with no cells, and band gives the box's lower ranks none of the datum wall.

Verdict: passes without units; one merge condition for a units model.

(a) The new tests on development

test_1295 and test_1115: 4 failed on development (the closed box, the far wall, the warning case, the slide case), 13 passed on the branch.

(b) F and S on every rank, and the refusal

The cases are those of test_1295. Each rank's F, S and outcome were gathered:

case F/S outcome np 1, 2, 3; band np 3; emptyband np 3
closed box, 0.1 sin πx on Top 1.000 refused identical on every rank, every layout
annulus off 0.2, slide 0.2 4.825e-2 refused identical
annulus off 0.1, slide 0.1 7.108e-3 warned, converged identical
annulus slide 0.1 5.063e-4 converged identical
annulus as built 4.692e-13 converged identical
box with an open wall – (no check) converged identical

F and S agree between rank counts to the last few bits, as quadrature order allows. The refusal is the same RuntimeError on every rank; under emptyband the empty rank raises too, and nothing hangs.

(c) A units model — finding, medium, merge condition

This is the same moved annulus under test_0013's reference quantities (2200 km, 1e22 Pa s, 1e-6 m²/s, 2500 K), with the datum given as uw.quantity(1, "cm/yr") * cos 2θ. The geometry is identical, so F/S should be identical too:

case F S F/S expected F/S outcome
off 0.2, slide 0.2 -0.2098 3031.3 6.92e-5 4.83e-2 converged, not refused
off 0.1, slide 0.1 -0.02901 2845.7 1.02e-5 7.11e-3 converged, no warning

F scales with the datum's magnitude as written (1, against 0.1 without units). S does not: the integral of Abs(g) comes back in a different unit or scale from the integral of g. Results are identical at np 1, 2 and 3. As written, a dimensional datum makes the check pass anything.

Merge condition: evaluate both integrals on the same footing (both non-dimensional, or both dimensional, reduced to one unit before float()), and add a units case to test_1295. This setup is enough: off and slide of 0.2 must be refused.

(d) Rotated parallel files at np 2

The 14 rotated parallel files give 58 passed and 2 skipped, on development and on the branch alike.

Cost

The check computes two surface integrals at every solve. Ten re-solves of the datum annulus at cell size 0.1, median per solve, two runs each: development 0.395 and 0.367 s; branch 0.351 and 0.368 s. The cost is within noise.

Note

The tight-tolerance NaN/DTOL (H7's UNFILED 36 finding: datum wall at tolerance 1e-12, a pressure GASM DIVERGED_DTOL that feeds NaN into the GAMG velocity solve, serially and with any partition) is listed in the body as not in this PR. That is correct: the annulus datum 0.1 cos 2θ has F/S of about 5e-13 there, so this check does not touch it.

Underworld development team with AI support from Claude Code

…ional form

In a units model a dimensional datum integrated as given and under Abs came
back at two scales (H7: F/S 6.9e-5 for a case at 4.8e-2; here the near case
read 0.71 and was refused). The datum is now unwrapped once
(unwrap_expression, mode "nondimensional") and both integrals are taken from
it: with 1 cm/yr cos 2θ the ratios are 4.825e-2 and 7.108e-3, as without units.

test_1295: the units case, far refused and near warned (both fail before
this commit); the moved-mesh fixture deforms with model coordinates marked
dimensionless, and takes its viscosity as a quantity in a units model.

Underworld development team with AI support from Claude Code
@lmoresi
lmoresi marked this pull request as ready for review November 20, 2026 14:38
@lmoresi

lmoresi commented Nov 20, 2026

Copy link
Copy Markdown
Member Author

Pushed 6ecca46, for H7's units condition. F and S are now both taken from the datum unwrapped once to its non-dimensional form (unwrap_expression(g, mode="nondimensional")).

  • Measured, u·n = 1 cm/yr cos 2θ in a units model (length 1000 km, viscosity 1e21 Pa s, time 1 Myr): F/S = 4.825e-2 (refused) and 7.108e-3 (warned). The unitless runs give the same ratios.
  • Before this commit the near case read F/S = 0.71 and was refused.
  • test_1295 gains the units case, both directions; both fail before this commit.
  • The fixture moves the mesh with model coordinates marked dimensionless, since a units model refuses a plain array (mesh.deform in a units model decides a plain array's frame by guessing from its size #1081).

Serial (macOS, 12-core Apple M4): the 50 rotated and fault files with test_0052, levels 1 and 2, all pass. Marked ready.

Underworld development team with AI support from Claude Code

@lmoresi

lmoresi commented Nov 20, 2026

Copy link
Copy Markdown
Member Author

Re-check by H7 (a Claude review session running parallel probes on a 96-thread Linux workstation: Intel Xeon Gold 6240R, MPICH) at 6ecca46. The setup is the same as in our review: the branch's rotated_bc.py in its build, the moved annulus under test_0013's reference quantities, and the datum uw.quantity(1, "cm/yr") * cos 2θ on Upper.

case np 1, 2, 3, and np 3 with an empty rank F/S, units F/S, no units outcome
off 0.2, slide 0.2 F, S identical on every rank 4.825e-2 4.825e-2 refused on every rank
off 0.1, slide 0.1 F, S identical on every rank 7.108e-3 7.108e-3 converged (the warning case)
  • The units finding is fixed. F and S now come from the same non-dimensional datum. F/S matches the unitless run to every printed digit in both directions, at every rank count and on the empty-rank layout. (In model units F = -146.3 and S = 3031 for the far case; the ratio is what is tested.)
  • test_1295, with its units case: 8 passed on the branch, 6 failed on development.

#1296 passes. Our merge condition is met.

Underworld development team with AI support from Claude Code

The conflict in rotated_bc.py is two helpers added at the same place: this
branch's _datum_net_flux (UNFILED 36) and #1263's _refuse_a_field_normal
(UNFILED 37). Both are kept, with their call sites.

Underworld development team with AI support from Claude Code
@lmoresi

lmoresi commented Nov 24, 2026

Copy link
Copy Markdown
Member Author

Merged development, with #1263 at dbe7733, into this branch: ca4ba36.

The conflict in rotated_bc.py was two helpers added at the same place: this branch's _datum_net_flux and #1263's _refuse_a_field_normal. Both are kept, with their call sites.

Serial (macOS, 12-core Apple M4): the 50 rotated and fault test files, test_1295 included, with test_0052, levels 1 and 2: 583 passed, 1 skipped.

Underworld development team with AI support from Claude Code

@lmoresi
lmoresi merged commit 762469b into development Nov 24, 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.

2 participants