Skip to content

NavierStokesSLCN commits its stress history after the solve (#742); it refuses a stress_transport it does not honour - #1256

Merged
lmoresi merged 2 commits into
developmentfrom
bugfix/slcn-stress-history-contract
Nov 20, 2026
Merged

lmoresi merged 2 commits into
developmentfrom
bugfix/slcn-stress-history-contract

Conversation

@lmoresi

@lmoresi lmoresi commented Nov 20, 2026 •

Copy link
Copy Markdown
Member

Fixes #742, and a side finding from the same sweep (no issue was filed for it).

1. After a solve, every family's stress history holds that solve's stress (#742)

On the analytic Maxwell shear box (rate 1, η = G = 1, ETD-1, five solves of 0.1), DFDt.psi_star[0] after the fifth solve read:

solver before after
Stokes 0.393469 0.393469
NavierStokes (composed) 0.393469 0.393469
NavierStokesSLCN 0.329681, one solve stale 0.393469

The exact value is $1 - e^{-0.5} = 0.393469$. The stale one is $1 - e^{-0.4} = 0.329681$.

The cause: the Stokes family commits the stress after the solve (_stress_history_post_solve). NavierStokesSLCN recorded its flux at the start of the next step, so a diagnostic or checkpoint read after a solve was a step stale. With a stress history (a model with requires_stress_history), NavierStokesSLCN now:

  • carries the history at the start of the step without recording it (store_result=False);
  • commits the flux after the solve, as Stokes does.

A purely viscous flux history keeps its record at the start of the step.

Behaviour change for NavierStokesSLCN users with a viscoelastic model:

  • what psi_star[0] holds between solves, and so what a checkpoint written after a solve stores, is now the stress just solved for;
  • the solution itself is not meant to change: the same flux is recorded, a step earlier. test_1059's pinned NavierStokesSLCN values pass unchanged.
  • test_1059's Maxwell-box helper read the constitutive flux for this solver as a workaround for After solve(), psi_star[0] holds the new stress on the Stokes family but the previous step's stress on NavierStokesSLCN #742. It now reads psi_star[0] for every family.
  • A checkpoint does not restart across this change, in either direction. A viscoelastic NavierStokesSLCN checkpoint written before this change and read after it, or the reverse, restarts from a history one step off. The parallel review measured the velocity off by 1.7e-2 at ETD-1 and 0.58 at BDF-2. Restarting within one version is unaffected. Anyone restarting an older run should restart it on the version that wrote it. A version mark on the history state would let a restart refuse the mismatch; that is a later improvement.
  • constitutive_model.flux read between solves now gives the next step's flux, as in Stokes and NavierStokes, because it is formed from the just-committed history. Code that read it for the latest stress must read DFDt.psi_star[0] instead.

Test: test_1247 runs the box on all three families. Before the fix, NavierStokesSLCN fails at 0.3296808; after it, all three pass.

2. NavierStokesSLCN refuses a stress_transport it does not honour

It accepted any stress_transport (a plain attribute) and always built a semi-Lagrangian history, so "integration_point" was ignored without a word. It now:

  • reads "semi_lagrangian";
  • accepts that value;
  • refuses any other with a ValueError naming uw.systems.NavierStokes, which carries the other flavours.

test_1247 checks this; it failed before.

Tests

Measured by H7 (the stress-history desk, a Claude session on a 96-thread Linux workstation: Intel Xeon Gold 6240R, MPICH).

  • test_1247 (4): 2 failed before, all pass after.
  • With test_1059 and the 8 files that build NavierStokesSLCN, SNES_NavierStokes or NavierStokesSwarm, on 4 xdist workers: 110 passed.

Checklist (UW3 Style Charter)

  • Style Charter followed (S2); no drive-by changes (S9)
  • Regression test written first, with level_1 and tier_a markers; it fails on development (S8)
  • No hedging names, commented-out code or exception swallows (S3, S4)
  • Parallel: the commit is the Stokes family's, taken on every rank (S11)
  • No coordinates identify entities (S12); no dependency changes
  • AI-assisted

Underworld development team with AI support from Claude Code

…ther families do (#742); it refuses a stress_transport it does not honour

After a solve, a viscoelastic history's level 0 held the solve's stress on Stokes and the
composed NavierStokes, and the previous step's on NavierStokesSLCN, which recorded the flux
at the next step's start: five ETD-1 solves of the Maxwell box read 0.329681 against
exact 0.393469. With a stress history it now carries without recording and commits after
the solve; a purely viscous flux history keeps its record. stress_transport on
NavierStokesSLCN was accepted and ignored; it now reads semi_lagrangian and refuses any
other value, naming uw.systems.NavierStokes for those.

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

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

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 at 291d579: ready to merge on green from this review.

The change does what it says. After a solve, NavierStokesSLCN's level 0 now holds the stress that solve produced, as in Stokes and NavierStokes. The solved fields move toward the Stokes and NavierStokes answers. With a changing timestep they move a lot closer. A viscous-only flux history is bit-for-bit unchanged. The stress_transport refusal works, and every rank raises it. Two things should go in the PR body before merge: checkpoints written before this change do not restart correctly after it (finding 1), and constitutive_model.flux read between solves now gives a different value (finding 4). Neither needs a code change. Finding 2 is an older instability at order 2. This PR makes it grow more slowly but does not fix it, and it should get its own issue.

What users see differently

Maxwell shear box (eta = G = 1, ETD-1, 5 solves of dt 0.1, 16x8 quads, read at the origin). The exact stress after 5 solves is 0.393469. One step old, it is 0.329681.

What is read after a solve development (e7e02b9) this PR (291d579) Stokes / NavierStokes (both sides)
DFDt.psi_star[0] 0.329681 (one step old) 0.393421 0.393469
constitutive_model.flux 0.393469 (the stress just solved) 0.451197 (one step ahead) 0.451188 / 0.451187
A checkpoint written between solves holds the stress one step old the stress just solved the stress just solved
  • psi_star[0] now holds the solved stress. It is a projection, so it is exact only to the projection's tolerance (finding 3).
  • constitutive_model.flux read between solves used to give the solved stress. It now gives the flux rebuilt from the new level 0, one step ahead. That is the same as Stokes and NavierStokes. Code that read the flux to get the latest stress, as test_1059 did before this PR, now gets the wrong number. It should read psi_star[0].
  • Checkpoints and restart. A restart with the same version continues the unbroken run to within solver tolerance, before and after the change. A checkpoint written on development and read on this PR (or the reverse) restarts one step out of phase (table C).
  • Solved fields (v, p, stress) change at the level of the time discretisation. They move toward the Stokes and NavierStokes reference (table B).
  • stress_transport. NavierStokesSLCN.stress_transport reads "semi_lagrangian". Setting any other value raises ValueError and names uw.systems.NavierStokes. On development the property does not exist on this class. Setting "integration_point" there just made a plain attribute: no error, and the history stayed semi-Lagrangian. The probe shows this: development runs the integration_point case with a SemiLagrangian history.
  • Viscous-only flux history: no change. Every printed value is identical, at order 1 and order 2, with a fixed and a changing dt.

Method

  • The PR changes only Python files. Its merge base with development is e7e02b9. A clean, built worktree at exactly e7e02b9 was reused. Its installed package was copied twice. The head and merge-base src/underworld3/*.py files were laid over the copies, and each copy was put first on PYTHONPATH. Every run prints underworld3.__file__ to confirm which copy it loaded.
  • The After solve(), psi_star[0] holds the new stress on the Stokes family but the previous step's stress on NavierStokesSLCN #742 probe: the Maxwell box for Stokes, NavierStokes and NavierStokesSLCN, reading psi_star[0] and the flux after 5 ETD-1 solves. Run at np 1, 2 and 3.
  • A heterogeneous probe: the same box with a smooth stiff inclusion (eta = 1 + 9 exp(-r^2/0.04), centred at (0.2, 0)), so v, p and the stress vary in space and in time. Solver tolerance 1e-8, rho = 1e-6 for the Navier-Stokes solvers. The probe prints v, p, psi_star[0] and the flux at 5 fixed points after every step. Runs cover 12 steps (30 for the stability check), order 1 ETD, order 2 BDF, fixed dt, and dt = 0.1 (1 + 0.4 sin 1.3k). "Solved stress" means psi_star[0] on the PR, Stokes and NavierStokes, and the flux on development (where level 0 is one step old). Differences are max |a - b| over the points divided by max |reference|, at the last step.
  • Restart: Model.save_state(file=...) after step 6, then a fresh process. It rebuilds the model, takes one solve so the lazily created variables exist, then calls load_state, which overwrites everything. It continues to step 12, and the result is compared with the unbroken run.
  • Parallel runs go through the MPI supervisor inside an outer timeout, on 4 cores. The timeout was 300 s for the probes and 900 s for the parallel test files, which hold slow but healthy solves. np 3 used a simplex mesh built by gmsh, partitioned so that the last rank holds no cells.

Results

A. #742 probe, psi_star[0] at the origin after 5 ETD-1 solves

np development SLCN PR SLCN Stokes, NavierStokes (PR)
1 0.329681 0.393421 0.393469, 0.393469
2 0.329681 0.393526 0.393469, 0.393469
3 not run 0.393429 to 0.393512 (rank-local reads) 0.393469, 0.393469

The integration_point case on the PR raises the new ValueError on every rank, at np 1, 2 and 3. Nothing hangs.

B. Heterogeneous box: SLCN against the references at step 12 (v / solved stress)

Case development vs Stokes PR vs Stokes development vs NavierStokes PR vs NavierStokes
ETD-1, fixed dt 5.5e-3 / 7.9e-3 4.9e-3 / 1.0e-2 4.3e-3 / 8.4e-3 3.7e-3 / 1.1e-2
ETD-1, changing dt 1.5e-2 / 2.0e-2 (max 1.9e-1) 4.3e-3 / 1.1e-2 2.0e-2 / 2.1e-2 3.0e-3 / 1.1e-2
BDF order 2, fixed dt 6.6 / 0.56 (diverging) 0.18 / 7.3e-3 (diverging, slower) same same
  • For scale: Stokes and NavierStokes agree to 2.7e-3 at ETD-1 and to 5e-9 at BDF order 2.
  • PR against development directly (ETD-1, fixed dt): v differs by 9.3e-4 absolute at step 12 and grows steadily. This is the projected history against the evaluated one, carried forward.
  • With a changing dt, development forms the stored stress with the new step's coefficients. That is because dt_elastic is set before the record. The PR stores it with the step's own dt. This explains why the PR is 3 to 6 times closer to the references.
  • Order 2 BDF over 30 steps: Stokes is smooth. SLCN oscillates and diverges on both sides. The v error passes 1 at step 15 on the PR and at step 10 on development. Order 1 ETD on the PR stays smooth over 30 steps.
  • ETD order 2 on SLCN is refused on both sides ("needs a stress history with a forcing slot"). This PR does not change that.
  • Stokes and NavierStokes at order 2 ETD are bit-identical between development and the PR.
  • Viscous-only SLCN (order 2 with fixed dt, order 1 with changing dt) is bit-identical between development and the PR.

C. Checkpoint and restart (save after step 6, continue to 12, compare with the unbroken run; v / stress)

Written by → read by ETD-1 BDF order 2
development → development (np 1) 3.5e-10 / 1.4e-10 1.5e-8 / 1.9e-9
PR → PR (np 1) 1.2e-6 / 2.3e-6 1.2e-5 / 4.4e-6
PR → PR (np 2) 1.5e-6 / 1.3e-6 not run
development → PR (np 1) 1.7e-2 / 1.5e-1 5.8e-1 / 3.7e-1
PR → development (np 1) 2.6e-2 / 1.8e-1 not run

D. Parallel against serial (heterogeneous box, ETD-1, v / stress, max over 12 steps)

Case development PR
np 2, quads 3.0e-5 / 1.1e-5 4.1e-4 / 4.3e-4
np 3, simplex, last rank empty 1.7e-5 / 1.3e-4 9.8e-5 / 5.5e-4
np 2, quads, BDF order 2 not run 4.1e-2 / 3.2e-3 (unstable scheme, see B)

E. Tests

Run development (e7e02b9) PR (291d579)
Serial, 4 workers: test_1247, test_1059 and 12 neighbour files (0020, 0506, 0610 SLCN projection, 1018, 1056 x2, 1060 x2, 1063, 1148, 1153, 1164) 118 passed, 1 timed out 122 passed, 1 timed out
The PR's tests run against development test_1247: SLCN level 0 = 0.329681 fails; refusal fails (no attribute); test_1059 SLCN ETD leg fails (0.85043 vs 0.86466) (these are the PR's own tests)
np 2: parallel/0780 (skipped, needs 4 ranks), 1062, 1078, 1107 5 passed, 1 skipped 5 passed, 1 skipped
np 2: test_1247 and test_1059's SLCN test test_1059 SLCN test (with the NavierStokes test in 2 of the 3 runs): all passed, 3 runs 5 passed, 4 runs; one run did not exit (see finding 5)

The test that timed out is the same one on both sides: test_1060_stress_store_smoothing::...integration_point_history. It is a 15-minute tier-c NavierStokes characterisation, and I capped each test at 600 s. This PR does not touch that path.

Findings

  1. Medium: checkpoints do not carry over across this change. A NavierStokesSLCN viscoelastic checkpoint written on development holds level 0 one step old. Read on the PR, the history is taken as current, so the run restarts a step behind. v is off by 1.7e-2 and the stress by up to 1.5e-1 at ETD-1, and v by 5.8e-1 at BDF order 2. The reverse direction is off by the same amount. A restart with the same version is fine on both sides. Please add a line to the PR body (and CHANGES if there is an entry) saying that a viscoelastic NavierStokesSLCN checkpoint written before this change must not be continued after it. A version mark on the history state would let a later reader refuse such a file. That can be a follow-up.

  2. Medium (existed before this PR; please file separately): order-2 viscoelastic NavierStokesSLCN is unstable. With BDF order 2, SLCN oscillates and diverges on the heterogeneous box. Stokes and NavierStokes agree to 5e-9 on the same case. On development the v error is 6.6 at step 12. On the PR it is 0.18 at step 12 and passes 1 at step 15. The PR slows the growth but does not remove it. The likely cause is the Adams-Moulton flux in F1 blended on top of a constitutive flux that already carries the history. That needs a separate look. ETD order 2 is refused on SLCN on both sides.

  3. Low: level 0 is a projection with tolerance 1e-4. SLCN's history is degree 2 (Stokes uses u.degree - 1). The commit projection runs at its default tolerance of 1e-4. The result is that the uniform-shear value reads 0.393421 at np 1 and 0.393526 at np 2, where Stokes and NavierStokes read exactly 0.393469. In the heterogeneous box the PR's partition spread is about 10 times development's (table D), though still well inside typical run tolerances. Setting the projection tolerance to 1e-10 after the first solve gives 0.393457 at np 1 and 0.393472 at np 2. Consider giving the commit projection a tighter tolerance, or the Stokes degree. The PR body's "0.393469" holds for SLCN only to the test's 2e-3.

  4. Low: the flux read between solves changed. constitutive_model.flux after a solve now reads one step ahead (0.451197 against 0.393469 before). That matches the other families, but it is a visible change, so the PR body should name it next to psi_star[0].

  5. Low (not attributed to this PR): one np 2 run did not exit. In 1 of 4 np 2 runs of test_1247 plus test_1059's SLCN test, both ranks passed all 5 tests and then did not exit. The 900 s timeout ended the run. In that run the supervisor had seen no output for 60 s mid-test and attached to the ranks for a stack dump. Its native dump failed ("No such process"). The other 3 runs finished in about 55 s with no silence. Development's 3 runs of the SLCN test exited cleanly, but they never reached 60 s of silence. I read this as a side effect of the stack dump, not of the change. Recorded for completeness.

On test_1059: its SLCN test compares against the analytic value (1e-3 for ETD, 0.02 for BDF, after 20 steps). It now reads psi_star[0], so it does exercise the changed path. Run against development, the ETD leg fails (one step old, 1.6 % off). The BDF leg's 2 % tolerance would not catch a one-step lag. The pins "pass unchanged" because before this PR the test read the flux, which held the solved stress, and now it reads level 0, which holds the same thing.

Diff read in full. The order is right: with a stress history, the pre-solve carry runs with store_result=False, which traces every level back without shifting or recording. After the solve, commit_flux_to_history projects the new stress into level 0 and shifts the carried old level 0 to level 1, once per step. Then update_post_solve records the dt. This is the Stokes sequence. On the first step, initialise_history fills the levels from the zero-velocity flux as before, so step 1 is bit-identical on both sides. The refusal is a pure-Python setter check with no collective, so it is rank-identical. The class is also exported as NavierStokesSwarm, which gets the same change.

What was run and not run

Run: the #742 probe at np 1, 2 and 3 on the PR, and at np 1 and 2 on development. The heterogeneous probe (about 30 serial runs, 12 to 30 steps). Restart at np 1 (same version and across versions) and at np 2 (PR). np 2 on quads and np 3 on simplex with an empty rank. A projection-tolerance check. The serial neighbour tests on both sides. The PR's tests against development. Four parallel test files at np 2 on both sides. Logs kept by the reviewer.

Not run: np 4 of parallel/0780 (it needs 4 ranks; the core budget was 4). Restart across versions at BDF order 2 from PR to development. Restart at np 3. A mesh-refinement study of the PR-against-development difference. The 15-minute tier-c smoothing test to completion.

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.

3 participants