Skip to content

A mesh move stays in its frame in a units model, and the monotone limiter compares like with like - #1003

Merged
lmoresi merged 10 commits into
developmentfrom
bugfix/mesh-move-units
Nov 12, 2026
Merged

lmoresi merged 10 commits into
developmentfrom
bugfix/mesh-move-units

Conversation

@lmoresi

@lmoresi lmoresi commented Nov 7, 2026

Copy link
Copy Markdown
Member

In a model with reference quantities, a mesh move now stays in its frame and transfers values correctly, and the monotone limiter compares like with like. Fixes the mesh-move part of #979, and #989. Stacked on #988: merge #959, #982 and #988 first.

What was wrong

In a units model mesh.X.coords is physical, the DM holds model coordinates, evaluate returns dimensional values, and var.data holds non-dimensional ones. Several sites crossed those boundaries without converting:

Site Effect, measured on an annulus with reference length 1000 km
The remesh transaction read mesh.X.coords and wrote it to the DM mesh.deform and the mover left the mesh scaled to metres: DM coordinate max 1 to 1e6
The remap evaluated at physical coordinates read as model ones, and wrote dimensional values into var.data Remapped values wrong
ephemeral_coords, sync_coordinates_from_parent, _refine_prolongate / _refine_restrict The same frame mix-up: a submesh written in metres; restores in the wrong frame
_apply_monotone_limit bounded a dimensional value by non-dimensional data, then labelled the result with units (#989) T at 1500 K came back as 1.5 K

The change

  • The transaction, ephemeral_coords, submesh sync and the refine transfers read and write model coordinates. The remap evaluates at coords_nd and non-dimensionalises the result before writing var.data.
  • Mesh.deform converts coordinates that carry units through uw.non_dimensionalise, in any length unit, a pint Quantity included. It refuses a unit that is not a length. A plain array is model coordinates, as evaluate reads one. A plain array the size of the physical domain is refused, where before it would have been read as model coordinates and silently scaled the mesh.
  • The limiter compares in model units and gives the value its own units back. The old TODO(units) there is removed.

In a model without units nothing changes: coords_nd is coords, _coords is X.coords, and non_dimensionalise returns its input.

Tests

  • tests/test_0770_mesh_move_in_a_units_model.py (tier B, 10 tests): deform in metres, km and model coordinates; a units field remapped; the mover; ephemeral_coords; a submesh; the refusals; a pint quantity; the clamp. 9 fail on the SwarmVariable reads a non-symmetric matrix back in the order it was written; global_evaluate stops transposing tensors #988 build. The plain model-coordinate case passes there too, because it takes no remap.
  • tests/parallel/test_0770_mesh_move_in_a_units_model_parallel.py: np 2, 4, 8.
  • 98 test files touching units, monotone, deform, ephemeral_coords or submeshes: 982 passed, 15 skipped, 10 xfailed. 123 files that move meshes or use global_evaluate and swarm variables passed on the commit before the last review round. Their parallel files at np 4 pass.

Not in this PR

Checklist (UW3 Style Charter)

  • Read the Style Charter and followed it over the surrounding code
  • No drive-by refactors, renames or cleanups
  • Bug fixes ship the regression test, written first, with level_* and tier_* markers
  • No hedging names and no commented-out code
  • No new exception swallows
  • New data access uses .array / mesh.X.coords
  • Parallel safety checked at np 2, 4 and 8
  • No dependency changes
  • AI-assisted work carries the attribution line

Underworld development team with AI support from Claude Code

mesh.X.coords is physical in a model with reference quantities and the DM holds model
coordinates. The remesh transaction read the first and wrote the second, so mesh.deform
and the mover left the mesh scaled by the length scale. It also remapped at physical
points read as model points, and wrote the dimensional answer into the raw values.
deform now converts from the frame of mesh.X.coords, and the transaction works in the
DM's frame. Fixes the mesh-move part of #979.

Underworld development team with AI support from Claude Code
…esh and refine transfers in the DM's frame

A plain array given to deform is model coordinates, as evaluate reads one, and coordinates
with units are converted in any length unit. A submesh followed its parent through the
physical coordinates, and the refine transfers evaluated at them; both now use the DM's.

Underworld development team with AI support from Claude Code
…aces coordinates it can and refuses the rest

The monotone limiter bounded a dimensional value by non-dimensional data and then
labelled the result with units (#989); it now compares both in model units and gives
the value its units back. deform converts coordinates in any length unit, including a
pint Quantity, refuses one that is not a length, and refuses a plain array the size of
the physical domain rather than reading it as model coordinates.

Underworld development team with AI support from Claude Code
@lmoresi

lmoresi commented Nov 7, 2026

Copy link
Copy Markdown
Member Author

Adversarial review

Three independent reviews, by reading code; none ran anything. The last commit (0b14c68b) answers the third and was not reviewed again.

Round 1 (first commit). The deform frame did not convert coordinates with units, and a model-frame array collapsed the mesh. Submesh sync had the same bug. The free surface still failed. ephemeral_coords was untested. All fixed and tested except the free surface, which is #998.

Round 2 (the follow-up):

  1. With REMESH_MONOTONE=clamp, this branch made global_evaluate with monotone clamp returns wrong values in a units model, and mesh.deform uses it #989 far worse: the limiter labelled non-dimensional numbers with units, and the remap then non-dimensionalised them again, so T came out about 1000 times too small. Fixed: the limiter now compares in one frame. A test runs deform under the clamp; that test and the global_evaluate check fail on the SwarmVariable reads a non-symmetric matrix back in the order it was written; global_evaluate stops transposing tensors #988 build.
  2. A plain physical-sized array was silently read as model coordinates. Fixed: it is refused, with a message.
  3. A pint Quantity crashed deform. Fixed and tested.
  4. A non-length unit was accepted. Fixed: refused. Also, non_dimensionalise uses the default model, not the mesh's: left as is and noted.
  5. The free surface is pre-existing: FreeSurface fails in a units model: ring coordinates are physical, the plex coordinates are model #998.

Attacks that found nothing

  • _coords always matches the DM after _deform_mesh rebinds it.
  • CoordinateSystem._length_scale and non_dimensionalise use the same fundamental length.
  • RemeshContext consumers need the model frame. The semi-Lagrangian old-frame path was broken in units before.
  • Smoothing uses X.coords only for scale-invariant checks.
  • A model without units is unchanged.

Issue verdicts: #989 fixed. #979 partly fixed and still open, for the free surface (#998) and the mesh.units label mismatch.

Underworld development team with AI support from Claude Code

@lmoresi

lmoresi commented Nov 10, 2026

Copy link
Copy Markdown
Member Author

Review of the final commit only (pre-rebase)

This round covers only the final commit, which answered earlier review rounds and had not itself been reviewed. Each PR's own tests run again on its rebased head once H2 has rebased the stack onto development (#959 is merged). That record will follow as a separate comment. Paths under runs/ are on hyperion.


#1003, final commit 0b14c68: adversarial review

Commit: 0b14c68 "Review of the units fix: the limiter compares in one frame; deform places coordinates it can and refuses the rest". Parent 5151468. Runtime base: #988 head e0d220b (wt-s988).

Verdict: changes requested. The limiter fix is right. It is in one frame in a units model and in a no-units model, serially and at np 2, and for every unit tried. deform now converts coordinates in any length unit, a pint Quantity included, and mesh.X.coords comes back right. The new placement helper has two defects, though. It hangs when a rank has no vertices. It also refuses the non-dimensional array that uw.non_dimensionalise returns, which worked before the commit.

Method

  • Tests were run from git archive copies, with PYTHONDONTWRITEBYTECODE=1 and -p no:cacheprovider. MPI ran under mpi_supervisor.py.
  • We checked that the installed site-packages files of wt-s1003 and wt-s988 match their commits byte for byte.
  • The commit's parent was emulated in-process on the s1003 build (plugins/mut1003.py). That plugin compiles the parent's _apply_monotone_limit and Mesh.deform into the installed modules. The same mechanism gives the partial mutants.
  • Logs are in logs/ and probes in probes/.

What it answers

From round 2 of the PR's review:

  1. The clamp made global_evaluate with monotone clamp returns wrong values in a units model, and mesh.deform uses it #989 worse. Answered.
  2. A plain array the size of the physical domain was read as model coordinates. Answered. It is now refused, but see F3.
  3. A pint Quantity crashed deform. Answered.
  4. A unit that is not a length was accepted. Answered. It is now refused, but see F2.

Evidence:

  • Limiter probe (p_limiter.py). Off-node points on an annulus, P1 linear and P2 sharp fields. The clamped result, non-dimensionalised, is compared with an independent oracle: the plain result clipped into the dim+1-nearest range of var.data.
case final, np 1 / np 2 parent, np 1 / np 2
units model, K, P1, model coords 0 / 0 0.475 / 0.475
units model, K, P2 sharp, model or physical coords 2.2e-16 / 2.2e-16 2.0 / 2.0
units model, Pa 2.2e-16 / 2.2e-16 2.0, labelled pascal
units model, m/s 2.2e-16 / 2.2e-16 2.0e12
units model, degC 2.2e-16 / 2.2e-16 1.7, labelled degree_Celsius
units model, variable without units 0 / 0 0 / 0
no-units model, variable without units 0 / 0 0 / 0
  • The clamped result carries the value's own units on the final, and n_clipped is 25 serial and 24 at np 2.
  • A no-units model refuses a variable with units (strict units mode), so that branch cannot be reached.
  • degC (p_degc.py). evaluate labels a degC variable's values kelvin. That is pre-existing. The final limiter is consistent with it: nd(clamp) - data is 6e-17. On SwarmVariable reads a non-symmetric matrix back in the order it was written; global_evaluate stops transposing tensors #988 it is 0.22 and the result is labelled degree_Celsius.
  • Deform under REMESH_MONOTONE=clamp (p_clampdeform_pick.py). The raw-value error is 1.4e-3 on the final at np 1 and np 2. With the parent's limiter it is 0.48 (np 1) and 0.48 / 0.476 (np 2). The test's bound of 1e-2 sits between the two.

The commit's own tests

tests/test_0770_mesh_move_in_a_units_model.py (10 tests). The parallel file is unchanged by the commit.

build serial np 2 (both test_0770 files)
final (s1003) 10 passed 11 passed
parent 5151468 (emulated) 3 failed: refuses, pint, clamp the same 3 fail on both ranks
#988 (s988) 9 failed, 1 passed (model form) 10 failed, 1 passed

Mutants on the final, serial:

mutant caught by
parent's limiter test_the_clamp_compares_in_one_frame (0.4995 vs 1e-9)
limiter compares raw magnitudes (to_model = 1) the same test
parent's deform refuses, pint
no physical-size refusal refuses
no not-a-length refusal refuses

Every part of the change is caught by a test. The parallel test does not exercise the clamp or the refusals.

Findings

F1. High: a units-model deform hangs when a rank has no vertices.

  • In Mesh._model_coordinates_from (discretisation_mesh.py, added by this commit), two allreduce calls sit under if scale != 1.0 and model.size:. model.size is rank-local, so a rank with no vertices skips the collectives while the others wait in them.
  • Reproduced in probes/p_emptyrank.py, at np 4, with StructuredQuadBox(elementRes=(1, 1)) in a units model:
    • The local vertex counts are [0, 0, 0, 4].
    • With the parent's deform, all four ranks return.
    • On the final, the supervisor reports "stuck", rank 3 in _model_coordinates_from(), and timeout gives exit 124 (logs/empty_quad_none.log, empty_quad_def_parent.log).
    • The triangle box at np 4 (counts [4, 0, 4, 0]) also hangs.
  • The reach is narrow: it needs an empty rank. But it hangs rather than failing.
  • Fix: gate only on scale != 1.0, which is global, and keep the .size guards inside the reductions, as extent already does.

F2. Medium, a regression: a dimensionless array is refused.

  • mesh.deform(uw.non_dimensionalise(new_X)), or any UnitAwareArray with units="dimensionless", now raises ValueError: mesh coordinates must be a length, not dimensionless.
  • It placed the mesh exactly on the parent and on SwarmVariable reads a non-symmetric matrix back in the order it was written; global_evaluate stops transposing tensors #988 (dm_err 6e-15).
  • A dimensionless array is model coordinates, and the message is wrong about it.
  • Fix: treat a dimensionless unit as model coordinates, as a plain array is.
  • No src caller does this today [read]: free_surface.py:1847 passes X.coords + disp. It is still the obvious user idiom.

F3. Low to medium: the physical-size heuristic refuses legitimate model-frame moves when the reference length is near the domain size.

  • The rule refuses when |log(size/(extent·L))| < |log(size/extent)|. That is any plain array whose extent changes by more than √L.
  • Measured with an interior or uniform scaling (p_deform.py); all three are accepted by the parent:
reference length move result
2 m uniform grow 1.5× refused
10 m grow 4× refused
0.1 m shrink 0.25× refused
  • At L = 1000 km the threshold is about 1000×, and a 1500× grow is refused, which is harmless.
  • Lab-scale models with a reference length of a few metres would hit this when stretching a mesh, for example building a unit box and deforming it to aspect 4. The message then blames "the size of the physical domain".
  • Fix: apply the heuristic only when L is far from 1, for example |log L| > log 100. Otherwise, document the rule in deform's docstring.

Notes, not findings against the commit:

  • A no-units model takes unit-carrying coordinates as model coordinates. A UnitAwareArray in km is read as model units (dm_err 0 against the km magnitudes), because non_dimensionalise passes through with no reference quantities. The parent does the same.
  • mesh.X.coords comes back right for metres, km, a pint Quantity and a plain model array: units meter, max 1.0e6, at np 1 and np 2. On SwarmVariable reads a non-symmetric matrix back in the order it was written; global_evaluate stops transposing tensors #988 it is 1e12 for metres and 1e9 for km.
  • The refinement ≥ 1 defect appears here. On an Annulus(refinement=1) in a units model, after deform, dm_hierarchy[-1] differs from dm by 1.9e-2 on the final and on the parent. On SwarmVariable reads a non-symmetric matrix back in the order it was written; global_evaluate stops transposing tensors #988 it is 1e6, the frame bug on top. This is the known, separately assigned defect (dm_hierarchy[-1] not updated by a move), and the commit does not touch it.
  • monotone="pick" could not discriminate the change. In a units model, serial, the final is in bounds in kelvin. The parent's pick is also in bounds, because every point is judged out of bounds and re-evaluated by the bounded RBF. The * to_model on the RBF re-evaluation is therefore not shown to matter by any run here.
  • non_dimensionalise uses the default model, not the mesh's, as the PR already notes.

Merge conditions

  • F1: the reductions in _model_coordinates_from run on every rank. An np ≥ 3 test with an empty rank would hold that; the StructuredQuadBox(elementRes=(1, 1)) at np 4 case above is one.
  • F2: a dimensionless array is accepted as model coordinates, with a test.
  • F3: narrow the heuristic or document it. This one can be a should-fix.

What we could not test

  • Partial reach. A vector or tensor variable with units under the clamp at np 2 was not run: the limiter's component layout path was exercised only for scalars.
  • Not run, unit-system reach. A variable whose units the reference quantities cannot reduce. A model whose mesh model differs from the default model.
  • Not run, solver and transcript reach. A free surface in a units model, which is FreeSurface fails in a units model: ring coordinates are physical, the plex coordinates are model #998 and pre-existing. A semi-Lagrangian DDt with ALE in a units model.
  • [read] That CoordinateSystem._length_scale and non_dimensionalise share one length scale. The earlier review attacked this; it is consistent with every dm_err of 1e-14 above.
  • The full 98-file units suite was not re-run here. It will be re-run after the rebase onto development.

Underworld development team with AI support from Claude Code

The two conflicts combine both sides: the evaluation stays at the
non-dimensional coordinates the DM holds (this branch), and the result is
laid out by development's _evaluated_in_storage_layout, which also reduces a
dimensional evaluation to the non-dimensional values var.data holds.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
With #1003 a move stays in the model frame, so 0.99 * mesh.X.coords keeps a
constant field exactly with no limiter. The plain metre-sized array the case
used before is now refused; assert that instead of the clamped number.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The physical-size check in _model_coordinates_from gated its two allreduces on
the local array size, so a rank holding no vertices skipped them and the move
hung (H1 review F1, np 4). Every rank now enters both reductions.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A UnitAwareArray or pint Quantity in dimensionless units was refused as not a
length. It says the values are model coordinates, as a plain array is read,
so take it that way, without the physical-size check (H1 review F2).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A dimensionless array holding metre magnitudes was accepted and scaled the
mesh up; a plain array with the same numbers is refused. Read dimensionless
values as a plain array, so both take the same check (H1 review, medium).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@lmoresi
lmoresi changed the base branch from bugfix/remap-sym-tensor to development November 12, 2026 01:13
@lmoresi lmoresi closed this Nov 12, 2026
@lmoresi lmoresi reopened this Nov 12, 2026
@lmoresi
lmoresi merged commit dd92c70 into development Nov 12, 2026
10 checks passed
gthyagi pushed a commit to gthyagi/underworld3 that referenced this pull request Nov 13, 2026
…nly-978

Underworld development team with AI support from Claude Code
jcgraciosa pushed a commit to jcgraciosa/underworld3 that referenced this pull request Nov 17, 2026
…#991)

underworldcode#1003 moved both parallel sites to coords_nd and the storage layout, so the
refusal underworldcode#1002 added is no longer needed: the transfers are exact for every
shape at np 2 and 3. test_0785's refusal tests now assert exactness, over
scalar, vector, 2x3 MATRIX, TENSOR and SYM_TENSOR.

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