Abstract
Dimensional analysis and physical unit checking are important tools for helping users to detect and correct mistakes in dynamic mathematical models. To make tools useful in a broad range of domains, it is important to also support other units than the SI standard. For instance, such units are common in biochemical or financial modeling. Furthermore, if two or more units turn out be in conflict after checking, it is vital that the reported unit information is given in an understandable format for the user, e.g., "N.m" should preferably be shown instead of "m2.kg.s-2", even if they represent the same unit. Presently, there is no standardized solution to handle these problems for Modelica models. The contribution presented in this paper is twofold. Firstly, we propose an extension to the Modelica language that makes it possible for a library designer to define both new base units and derived units within Modelica models and packets. Secondly, we describe and analyze a solution to the problem of presenting units to users in a more convenient way, based on an algorithm using Mixed Integer Programming (MIP).
Introduction
In large-scale physical modeling, dimensional consistency is a critical safeguard. If a modeler accidentally adds a force to a pressure, the compiler should ideally flag the error. However, current Modelica implementations suffer from three major gaps: SI rigidity (lack of support for non-SI units like "Money" or "Items"), the "Alphabet Soup" problem (reporting errors in cryptic base units like m2.kg.s-2A-1 instead of Wb), and tool inconsistency across different software vendors.
The defineunit Language Extension
To address the rigidity of current systems, the authors propose a new keyword, defineunit. This allows library creators to explicitly define base and derived units within the Modelica code itself.
- Base Units: e.g.,
defineunit m; - Derived Units: e.g.,
defineunit N(exp="m.kg.s-2"); - Weighting: Designers can assign a
weightparameter to units. A higher weight signals to the compiler that a specific unit is preferred for error reporting within that domain.
Unit Reporting via Mixed Integer Programming (MIP)
To solve the "Alphabet Soup" problem, the authors treat unit reporting as an optimization task. When a unit mismatch occurs, the tool must find the simplest combination of known derived units that matches the target dimension vector.
The system uses a Mixed Integer Programming (MIP) solver to minimize a cost function. This algorithm prioritizes derived units over base units, respects user-defined weights, and seeks expressions that are "closer" to the target dimension to maximize human readability. As shown in the table above, units are represented as vectors (e.g., length, mass, time), which the MIP solver uses to calculate the optimal output string.
Evaluation and Results
The implementation was benchmarked using the Modelica Standard Library (MSL) v2.2.1 and custom extensions for non-SI units (e.g., USD for currency).
Key results include:
- Parity and Beyond: The prototype successfully identified all unit errors previously found by industry-standard tools like Dymola.
- Improved Detection: The tool flagged additional errors in the MSL related to transcendental functions (like
expandlog), which mathematically require dimensionless arguments but were being used with units. - Successful Simplification: The MIP algorithm effectively converted complex base-unit strings into clean, derived-unit expressions (e.g., preferring
s.Pa.Jover raw SI base units based on assigned weights).
Conclusion
By combining a flexible language extension with an optimization-based reporting algorithm, this approach bridges the gap between rigorous physical checking and human intuition. Future work will focus on formalizing these semantics within the official Modelica specification and conducting broader usability testing to ensure the algorithm's selections align with diverse engineering contexts.
Summary updated