Skip to content

fix(ddt): units-active semi-Lagrangian trace-back (#267)#277

Merged
lmoresi merged 1 commit into
developmentfrom
bugfix/units-slcn-traceback-267
Jun 24, 2026
Merged

fix(ddt): units-active semi-Lagrangian trace-back (#267)#277
lmoresi merged 1 commit into
developmentfrom
bugfix/units-slcn-traceback-267

Conversation

@lmoresi

@lmoresi lmoresi commented Jun 24, 2026

Copy link
Copy Markdown
Member

Summary

Fixes #267SemiLagrangian.update_pre_solve crashed for any unit-bearing model in the time loop:

ValueError: Cannot subtract arrays with incompatible units: 'meter' and 'meter / second'

Root cause

The SL trace-back is performed in the mesh's non-dimensional (DM) coordinate space — evaluate/global_evaluate treat plain arrays as DM coords, and DM point-location uses DM values (0..L_model, not dimensional metres). The has_units branch instead kept dimensional coords (mesh.X.coords ≈ metres, ~1e9) and velocity (m/s) and left dt a unitless float, so coords[m] − v[m/s]·dt[dimensionless] raised — and even patched, dimensional coords fed to a DM that locates in 0..1000 space would mislocate.

Fix

Route the whole trace-back through ND/DM space regardless of units:

  • departure point from psi_star[i].coords_nd (== .coords for a non-units model; the ND reduction of dimensional coords when units are active),
  • velocity non-dimensionalised,
  • dt non-dimensional.

Both RK2 legs (node-velocity and midpoint-velocity) corrected. The non-units path is unchanged — it already used exactly this ND logic; the fix just removes the broken parallel dimensional branch.

Verification

  • Units-active AdvDiffusionSLCN now runs and tracks the equivalent non-dimensional run to ~1e-3 (the small residual is the constitutive diffusivity scaling under units — a separate concern, not the trace-back; advection-magnitude-independent).
  • Non-units SL regression unchanged: test_0855 (oldframe SL), test_0610 (NS SLCN), test_1054, test_1100 pass.
  • test_1110_advDiffAnnulus fails identically with and without this change — a pre-existing PCSetUp_MG/DMCreateInjection multigrid issue, unrelated.
  • New regression: tests/test_1056_units_slcn_traceback.py (runs + nondim-equivalence).

Unblocks the time-loop half of #263 (Tutorial_Thermal_Convection_Units).

Underworld development team with AI support from Claude Code

SemiLagrangian.update_pre_solve crashed for any unit-bearing model in the time
loop:
  ValueError: Cannot subtract arrays with incompatible units:
              'meter' and 'meter / second'

Root cause: the trace-back is performed in the mesh's NON-DIMENSIONAL (DM)
coordinate space (evaluate()/global_evaluate treat plain arrays as DM coords,
and DM point-location uses DM values 0..L_model, NOT dimensional metres). But
the has_units branch kept dimensional coords (mesh.X.coords ~ metres) and
velocity (m/s) and left dt a unitless float, so:
  - coords[m] - v[m/s]*dt[dimensionless] -> unit subtraction crash, and
  - even patched, dimensional coords (~1e9) fed to a DM that locates in 0..1000
    space would mislocate.

Fix: route the whole trace-back through ND/DM space regardless of units —
departure point from psi_star[i].coords_nd (== .coords for a non-units model;
the ND reduction of the dimensional coords when units are active), velocity
non-dimensionalised, dt non-dimensional. Both the node-velocity and
midpoint-velocity legs are corrected. The non-units path is unchanged (it
already used exactly this ND logic).

Verified: units-active AdvDiffusionSLCN now runs and tracks the equivalent
non-dimensional run to ~1e-3 (the small residual is the constitutive diffusivity
scaling under units, a separate concern, not the trace-back). Non-units SL
regression unchanged (test_0855/0610/1054/1100 pass; test_1110 fails identically
with/without this change — a pre-existing MG DMCreateInjection issue). New
regression: tests/test_1056_units_slcn_traceback.py.

Unblocks the time-loop half of #263 (Tutorial_Thermal_Convection_Units).

Underworld development team with AI support from Claude Code
Copilot AI review requested due to automatic review settings June 24, 2026 00: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 reached their quota limit.

@lmoresi

lmoresi commented Jun 24, 2026

Copy link
Copy Markdown
Member Author

Self-review: routes the SL trace-back through ND/DM space (the non-units path's existing logic); removes the broken dimensional branch. Repro fixed, regression test passes (2/2), non-units SL suite unchanged (the one annulus failure is a pre-existing MG issue, identical with/without). Merging for the release.

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