Skip to content

Fix dimensionality demo for strict units#261

Merged
lmoresi merged 1 commit into
underworldcode:developmentfrom
ss2098:ss2098/fix-dimensionality-demo-strict-units
Jun 22, 2026
Merged

Fix dimensionality demo for strict units#261
lmoresi merged 1 commit into
underworldcode:developmentfrom
ss2098:ss2098/fix-dimensionality-demo-strict-units

Conversation

@ss2098

@ss2098 ss2098 commented Jun 20, 2026

Copy link
Copy Markdown
Contributor

This updates docs/examples/Dimensionality-Demo.py so that it runs with the current strict-units behavior.

The example previously failed because it:

  1. created unit-bearing MeshVariable objects before reference quantities were set,
  2. assigned plain dimensional values directly into .array, and
  3. used older .to_nd(), .from_nd(), and UWQuantity reference-scaling calls that are not available in the current API.

The updated example keeps the dimensionality-tracking demonstration, but uses the current strict-units pattern:

  • set reference quantities before creating unit-bearing variables,
  • write non-dimensional values into .data,
  • use scaling coefficients for dimensional/non-dimensional conversion.

No solver behavior is changed.

Tested with:

pixi run python docs/examples/Dimensionality-Demo.py

Result: script completes successfully.

@ss2098 ss2098 requested a review from lmoresi as a code owner June 20, 2026 07:16

@lmoresi lmoresi left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks @ss2098 — verified it runs end-to-end on current development (the dead to_nd/nd_array/from_nd API is correctly removed — those were dropped in the units simplification). Merging since a running demo is a clear win over the broken one.

Follow-up suggestion (non-blocking): since this is specifically the Dimensionality demo, it would showcase the units interface better to assign dimensional quantities via .array rather than manual value / scaling_coefficient.data. I verified this works once reference quantities are set:

with uw.synchronised_array_update():
    T.array[...] = uw.quantity(1300.0, "kelvin")   # dimensional assignment
print(T.data[...])   # -> 1.3  (non-dimensional, == 1300/1000)

i.e. .array = dimensional (UnitAware), .data = non-dimensional — the manual scaling then isn't needed. Happy to push that polish as a follow-up if you'd like; not blocking this merge.

@lmoresi lmoresi merged commit 1404e60 into underworldcode:development Jun 22, 2026
1 check passed
@ss2098

ss2098 commented Jun 22, 2026

Copy link
Copy Markdown
Contributor Author

Thanks Professor @lmoresi that makes sense. I created a small follow-up PR with the polished version here: #268.

It updates the demo to assign dimensional quantities through .array and then shows the corresponding non-dimensional values stored in .data, following your suggestion.

Kindly check when you have a chance and see if it works as intended.

Thanks,
Saurabh

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