Physical units are fundamental to scientific computing. However, many finite element frameworks lack built-in support for dimensional analysis. In this work, we present a systematic framework for integrating physical units into the Unified Form Language (UFL). We implement a symbolic Quantity class to track units within variational forms. The implementation exploits the abelian group structure of physical dimensions. We represent them as vectors in $\mathbb{Q}^n$ to simplify operations and improve performance. A graph-based visitor pattern traverses the expression tree to automate consistency checks and factorization. We demonstrate that this automated nondimensionalization functions as the simplest form of Full Operator Preconditioning. It acts as a physics-aware diagonal preconditioner that equilibrates linear systems prior to assembly. Numerical experiments with the Navier--Stokes equations show that this improves the condition number of the saddle-point matrix. Analysis of Neo-Hooke hyperelasticity highlights the detection of floating-point cancellation errors in small deformation regimes. Finally, the Poisson--Nernst--Planck system example illustrates the handling of coupled multiphysics problems with derived scaling parameters. Although the implementation targets the FEniCSx framework, the concepts are general and easily adaptable to other finite element libraries using UFL, such as Firedrake or DUNE.
翻译:物理单位是科学计算的基础。然而,许多有限元框架缺乏对量纲分析的内置支持。在本工作中,我们提出了一个将物理单位集成到统一形式语言(UFL)中的系统框架。我们实现了一个符号化的Quantity类来跟踪变分形式中的单位。该实现利用了物理量纲的阿贝尔群结构。我们将它们表示为$\mathbb{Q}^n$中的向量,以简化运算并提高性能。一个基于图的访问者模式遍历表达式树,以自动化一致性检查和因式分解。我们证明这种自动无量纲化可作为全算子预处理的最简形式。它充当一种物理感知的对角预处理器,在组装前平衡线性系统。针对Navier--Stokes方程的数值实验表明,这改善了鞍点矩阵的条件数。对Neo-Hooke超弹性的分析突出了在小变形区域中浮点抵消误差的检测。最后,Poisson--Nernst--Planck系统示例说明了如何处理具有派生缩放参数的耦合多物理场问题。尽管该实现针对FEniCSx框架,但其概念具有通用性,可轻松适配其他使用UFL的有限元库,例如Firedrake或DUNE。