Summary
Subtracting (or adding) a UWQuantity to/from an EnhancedMeshVariable raises even when the units are compatible:
TypeError: Cannot subtract UWQuantity from EnhancedMeshVariable. Check dimensional compatibility.
(with an upstream SympifyError: 0.633... [kilokelvin] — the quantity can't be sympified into the variable's expression path).
Minimal repro
m = uw.get_default_model(); m.set_reference_quantities(...) # units active
T = uw.discretisation.MeshVariable('T', mesh, 1, degree=2, units='K')
T - uw.quantity(500.0, 'K') # FAILS (TypeError) — units ARE compatible
T - uw.quantity(0.5, 'kK') # FAILS too (not a unit-mismatch)
T.sym[0,0] - 500.0 # OK (workaround: drop to .sym + model-unit value)
Both compatible-unit cases fail, so it is not a dimensional-mismatch — the variable's arithmetic (MathematicalMixin / EnhancedMeshVariable) just doesn't accept a UWQuantity operand.
Why it matters
T − T_ref (a reference-temperature offset) is fundamental to buoyancy: F = ρ₀ α g (T − T_ref) ẑ. This blocks any units-active convection model, and is the current blocker for the thermal-convection units tutorial (PR #263) now that the SL trace-back crash (#267) is fixed.
Expected
meshvar ± UWQuantity (and the reverse) should work for compatible units — non-dimensionalise the quantity into the variable's ND expression and compose — relates to [[bare-variable composition]] (#137) / the MathematicalMixin units handling.
Exposed by PR #263.
Underworld development team with AI support from Claude Code
Summary
Subtracting (or adding) a
UWQuantityto/from anEnhancedMeshVariableraises even when the units are compatible:(with an upstream
SympifyError: 0.633... [kilokelvin]— the quantity can't be sympified into the variable's expression path).Minimal repro
Both compatible-unit cases fail, so it is not a dimensional-mismatch — the variable's arithmetic (MathematicalMixin / EnhancedMeshVariable) just doesn't accept a
UWQuantityoperand.Why it matters
T − T_ref(a reference-temperature offset) is fundamental to buoyancy:F = ρ₀ α g (T − T_ref) ẑ. This blocks any units-active convection model, and is the current blocker for the thermal-convection units tutorial (PR #263) now that the SL trace-back crash (#267) is fixed.Expected
meshvar ± UWQuantity(and the reverse) should work for compatible units — non-dimensionalise the quantity into the variable's ND expression and compose — relates to [[bare-variable composition]] (#137) / the MathematicalMixin units handling.Exposed by PR #263.
Underworld development team with AI support from Claude Code