Skip to content

Fix thermal convection units tutorial#263

Open
ss2098 wants to merge 1 commit into
underworldcode:developmentfrom
ss2098:ss2098/fix-thermal-convection-units-tutorial
Open

Fix thermal convection units tutorial#263
ss2098 wants to merge 1 commit into
underworldcode:developmentfrom
ss2098:ss2098/fix-thermal-convection-units-tutorial

Conversation

@ss2098

@ss2098 ss2098 commented Jun 20, 2026

Copy link
Copy Markdown

This updates docs/examples/Tutorial_Thermal_Convection_Units.py so that it runs with the current unit-aware array and strict-units behavior.

The previous tutorial failed in several places under the current API:

  1. The buoyancy expression mixed a MeshVariable symbolic field with a unit-bearing reference temperature, producing a dimensional compatibility error.
  2. The initial temperature assignment attempted to assign unit-aware evaluate() output directly into MeshVariable storage, which required explicit conversion to a plain numeric array.
  3. The semi-Lagrangian advection step encountered incompatible coordinate and timestep units unless the velocity field carried physical velocity units.
  4. The final reporting attempted to convert model-unit temperature quantities directly to offset Celsius units, which raised a Pint OffsetUnitCalculusError.
  5. The initial temperature profile could become incorrectly scaled because unit-aware coordinates needed to be normalized before constructing the model-unit temperature field.

The updated tutorial keeps the physical inputs in units, but uses explicit model-unit numeric values in solver expressions. It also converts unit-aware arrays before assignment, constructs the initial temperature field from normalized coordinates, and reports original physical parameters for interpretation.

No solver behavior is changed.

Tested with:

pixi run python docs/examples/Tutorial_Thermal_Convection_Units.py

Result: script completes successfully.

@ss2098 ss2098 requested a review from lmoresi as a code owner June 20, 2026 07:49
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.

1 participant