Skip to content

A plain number on a field with units is refused as a boundary value (UNFILED 33) - #1312

Open
lmoresi wants to merge 1 commit into
developmentfrom
fix/plain-bc-numbers-on-fields-with-units
Open

lmoresi wants to merge 1 commit into
developmentfrom
fix/plain-bc-numbers-on-fields-with-units

Conversation

@lmoresi

@lmoresi lmoresi commented Nov 25, 2026

Copy link
Copy Markdown
Member

What changes for users: in a model with reference quantities, a boundary value on a field with units is given with units (uw.quantity(5, "mm/yr")). A nonzero plain number there is refused as ambiguous, and the message shows the quantity form. Zero, and values on fields without units, are unchanged. A lone uw.expression is accepted as a boundary value.

UNFILED 33 (a) to (c), with the ruling of 2026-11-14 extended to boundary values: "a bare number used as a viscosity in a unit-aware environment is ambiguous and should be refused". A boundary value on a field with units has the same ambiguity. By the units desk (a Claude session). Runs were on a 96-thread Linux workstation (single system image; Intel Xeon Gold 6240R, AVX-512; MPICH), on development 7091a93.

Why a plain number was ambiguous

A full serial run with a probe on add_condition logged what plain numbers meant on development:

  • on a field with units and the scaling switched on, SI, divided by the field's scaling coefficient;
  • on a field without units, model units;
  • as a traction, divided by the field's velocity scale.

The same 0.5 could mean three things.

The change

  • (a) On a field with units, in a model with reference quantities, a nonzero plain number is refused. That holds for essential and natural conditions, outside library-internal work. The message names the condition and the component, and shows uw.quantity(v, "<the field's units>"). Zero means the same in any units, and stays accepted. So do infinity and None for a free component, and symbolic values.
  • (b) The older path that divided plain numbers by scaling_coefficient is removed. On a field with units it no longer receives a plain number, and on a field without units the coefficient is 1. One gate remains, with a refinement that test_0817 showed. With the model's scaling switched off (uw.use_nondimensional_scaling(False)), fields run unscaled, in SI. So a quantity's model value is its SI magnitude there, and its non-dimensional value otherwise.
  • (c) A lone uw.expression, or a sympy expression, given as the value is one entry. Before, it raised "Unknown quantity type" or "Unsupported BC conds".
  • From the review of A quantity boundary value is non-dimensionalised in a units model (#1238) #1264:
    • the units rule is in the add_essential_bc and add_dirichlet_bc docstrings;
    • the degC tests check the recorded value, and read it back after a solve: 1300 K, 1026.85 degC, and 0 degC as 273.15 K.

What it breaks, counted first

The probe found 13 nonzero plain numbers on fields with units, in 3 test files: test_0817, test_0818 and test_1450. They now give their walls as quantities. A static scan of the docs found two more candidates:

  • Ex_Convection_Annulus_Recorded's 1.0 is on a temperature field without units;
  • tutorial 13's (1.0, 0.0) is in its section without reference quantities.

Both are legal, and both run on this branch (below).

Tests

tests/test_0774_boundary_condition_quantities_in_a_units_model.py gains:

  • a plain number refused, essential and natural, with the message;
  • zero accepted;
  • a lone expression accepted, and recorded in model units;
  • the degC values checked.

Without this branch, the refusal and the lone-expression tests fail.

Regression runs

  • Serial: every tests/test_*.py except tier C, 6 xdist workers, on f943846: 4567 passed, and 4 failed, all test_1086_mmpde_seam_matches_serial, whose spawned runs time out under load. Run alone on f943846: 20 passed.
  • Parallel: scripts/test.sh --parallel-only --p 2 on f943846: all passed.
  • Docs: Ex_Convection_Annulus_Recorded and tutorial 13 both run to the end on f943846 (exit 0).

Checklist (UW3 Style Charter)

  • Followed the Style Charter over the surrounding code (S2)
  • No drive-by refactors (S9)
  • Regression tests written first, with level_* and tier_* markers (S8)
  • No hedging names, no commented-out code (S3, S4)
  • No new exception swallow (S4)
  • Parallel safety: the refusal is decided from values and units, the same on every rank (S11)
  • No dependency changes
  • AI-assisted work carries the attribution line

Underworld development team with AI support from Claude Code

UNFILED 33, with the ruling of 2026-11-14 extended to boundary values: in a
model with reference quantities a nonzero plain number on a field with units
is ambiguous and is refused, for essential and natural conditions, with a
message showing the quantity form. Zero means the same in any units, and a
field without units keeps its plain numbers. The older path that divided
plain numbers by the field's scaling coefficient is gone: on a field with
units it no longer receives one, and on a field without units its
coefficient is 1. A quantity's model value follows the model's scaling
switch: in SI when uw.use_nondimensional_scaling(False), as the field then
runs. A lone uw.expression (or sympy expression) is one entry (33c).

From the review of #1264: the units rule is in the add_essential_bc and
add_dirichlet_bc docstrings, and the degC tests check the recorded value and
read it back after a solve.

test_0817, test_0818 and test_1450 give their walls as quantities.

Underworld development team with AI support from Claude Code
Copilot AI balanced review requested due to automatic review settings November 25, 2026 01:46

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.

This branch has not been deployed

No deployments
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