Skip to content

Add monotone_mode kwarg to AdvDiffusionSLCN constructor#189

Merged
lmoresi merged 1 commit into
developmentfrom
feature/advdiff-monotone-mode-kwarg
May 14, 2026
Merged

Add monotone_mode kwarg to AdvDiffusionSLCN constructor#189
lmoresi merged 1 commit into
developmentfrom
feature/advdiff-monotone-mode-kwarg

Conversation

@lmoresi
Copy link
Copy Markdown
Member

@lmoresi lmoresi commented May 14, 2026

Summary

PR #186 landed the monotone-limiter functionality on SemiLagrangian_DDt (instance attribute and per-call kwarg). To use it via the AdvDiffusionSLCN solver, users had to construct the solver and then mutate the DDt instances after the fact:

adv_diff = uw.systems.AdvDiffusionSLCN(mesh, u_Field=T, V_fn=v.sym)
adv_diff.DuDt.monotone_mode = \"clamp\"
adv_diff.DFDt.monotone_mode = \"clamp\"

This PR adds a one-line constructor idiom:

adv_diff = uw.systems.AdvDiffusionSLCN(
    mesh, u_Field=T, V_fn=v.sym, monotone_mode=\"clamp\")

The kwarg forwards to both internally-constructed SemiLagrangian_DDt instances (DuDt and DFDt). Default None preserves legacy behaviour exactly.

Caller-supplied DuDt

If the caller passes a pre-built DuDt, that DDt's monotone_mode is preserved (the supplied DDt is the source of truth). The monotone_mode kwarg then only takes effect on the internally-constructed DFDt. Documented in the class docstring.

Test plan

  • tests/test_1054_advdiff_monotone_mode_kwarg.py — 4 cases:
    • default None propagates to both DDts
    • \"clamp\" propagates to both
    • \"pick\" propagates to both
    • caller-supplied DuDt with explicit mode is preserved (kwarg applies only to internal DFDt)
  • CI suite — default unchanged, expect bit-identical results for existing tests

Files changed

  • src/underworld3/systems/solvers.py (+33 lines, docstring + kwarg + two forward calls)
  • tests/test_1054_advdiff_monotone_mode_kwarg.py (+70 lines, new test file)

Underworld development team with AI support from Claude Code

PR #186 landed the monotone limiter on SemiLagrangian_DDt. To use it
via the high-level solver, users had to construct the solver and
then mutate the DDt instances after the fact:

    adv_diff = uw.systems.AdvDiffusionSLCN(mesh, u_Field=T, V_fn=v.sym)
    adv_diff.DuDt.monotone_mode = "clamp"
    adv_diff.DFDt.monotone_mode = "clamp"

This change adds a one-line constructor idiom:

    adv_diff = uw.systems.AdvDiffusionSLCN(
        mesh, u_Field=T, V_fn=v.sym, monotone_mode="clamp")

The new kwarg forwards to both internally-constructed SemiLagrangian
DDts (DuDt and DFDt). When the caller supplies a pre-built DuDt
explicitly, that DDt's monotone_mode is preserved as the source of
truth — the kwarg only takes effect for the internally-constructed
DFDt in that case (documented in the class docstring).

Default unchanged (None = pure FE trace-back). No behaviour change
for code that doesn't pass the kwarg.

Regression test in tests/test_1054_advdiff_monotone_mode_kwarg.py
covers: default None, clamp forwarded to both DuDt and DFDt, pick
forwarded to both, and the explicit-DuDt-preserves-its-own-mode case.

Underworld development team with AI support from Claude Code
Copilot AI review requested due to automatic review settings May 14, 2026 21:05
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds a monotone_mode keyword argument to the SNES_AdvectionDiffusion (AdvDiffusionSLCN) constructor, forwarding it to the internally-constructed SemiLagrangian_DDt instances for DuDt and DFDt. Defaults to None to preserve legacy behavior. When the caller supplies a pre-built DuDt, the kwarg only applies to the internally-built DFDt.

Changes:

  • New monotone_mode kwarg on SNES_AdvectionDiffusion.__init__, plumbed through both internal SemiLagrangian_DDt constructions.
  • Class docstring documents the new kwarg, its three modes, and the user-supplied-DuDt precedence rule.
  • New regression tests verifying default, "clamp", "pick", and caller-supplied-DuDt precedence.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
src/underworld3/systems/solvers.py Adds monotone_mode kwarg, docstring entry, and forwards it to both SemiLagrangian_DDt instances.
tests/test_1054_advdiff_monotone_mode_kwarg.py New regression tests covering default, clamp, pick, and caller-supplied-DuDt precedence.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@lmoresi lmoresi merged commit ca7d1e0 into development May 14, 2026
5 checks passed
@lmoresi lmoresi deleted the feature/advdiff-monotone-mode-kwarg branch May 14, 2026 21:19
lmoresi added a commit that referenced this pull request May 15, 2026
smooth_mesh_interior auto-pinning iterated every label in
mesh.boundaries, but Annulus exposes a "Centre" pressure-pin
label whose underlying DMLabel has an invalid communicator —
any PETSc call on it (getNumValues, getValueIS, view) hard-aborts
the interpreter (not a Python-catchable exception). Add "Centre"
to the auto-pin skip list (it's a single-point pressure marker,
not a geometric boundary) and keep the existing try/except guards
in _pinned_mask for any future similar quirks. Annulus + smoother
now runs end-to-end.

AdvDiffusionSLCN.__init__: forward a new `theta` kwarg to both
internally-constructed SemiLagrangian_DDt instances, mirroring
the existing monotone_mode forwarding from #189. Lets callers
configure the Adams-Moulton θ at construction time instead of
patching adv_diff.DuDt.theta / DFDt.theta after the fact.
Tested in the free-surface convection zoo: rk4 + theta=1.0 (BE)
+ monotone_mode="clamp" + smooth_mesh_interior every 2 steps
runs 6 steps with T staying in [0,1] and no integrator
instability.

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