Modelica® Language Specification version 3.7-dev

Chapter 19 Unit Expressions

Unless otherwise stated, the syntax and semantics of unit expressions in Modelica (for example, section 4.9.1 or section 18.2.2.1) conform with the international standards International System of Units (SI) by BIPM superseding parts of ISO 31/0-1992 General principles concerning quantities, units and symbols and ISO 1000-1992 SI units and recommendations for the use of their multiples and of certain other units. Unfortunately, these standards do not define a formal syntax for unit expressions. There are recommendations and Modelica exploits them.

Note that this document uses the American spelling meter, whereas the SI specification from BIPM uses the British spelling metre.

Examples for the syntax of unit expressions used in Modelica: "N.m", "kg.m/s2", "kg.m.s-2", "1/rad", "mm/s".

19.1 The Syntax of Unit Expressions

The Modelica unit string syntax allows neither comments nor white-space, and a unit string shall match the unit-expression rule:

unit-expression :
   unit-numerator [ "/" unit-denominator ]
unit-numerator :
   "1" | unit-factors | "(" unit-expression ")"
unit-denominator:
   unit-factor | "(" unit-expression ")"

The unit of measure of a dimension free quantity is denoted by "1". The SI standard does not define any precedence between multiplications and divisions. The SI standard does not allow multiple units to the right of the division-symbol (/) since the result is ambiguous; either the divisor shall be enclosed in parentheses, or negative exponents used instead of division, for example, "J/(kg.K)" may be written as "J.kg-1.K-1".

unit-factors :
   unit-factor [ "." unit-factors ]

The SI standard specifies that a multiplication operator symbol is written as space or as a dot. The SI standard requires that this dot is a bit above the base line: ‘·’, which is not part of ASCII. The ISO standard also prefers ‘·’, but Modelica supports the ISO alternative ‘.’, which is an ordinary dot on the base line.

For example, Modelica does not support "Nm" for newton-meter, but requires it to be written as "N.m".

unit-factor :
  unit-operand [ unit-exponent ]
unit-exponent :
   [ "+" | "-" ] ( UNSIGNED-INTEGER | "(" UNSIGNED-INTEGER "/" UNSIGNED-INTEGER ")" )

The SI standard uses super-script for the exponentation, and does thus not define any operator symbol for exponentiation. A unit-factor consists of a unit-operand possibly suffixed by a possibly signed integer or rational number, which is interpreted as an exponent. There must be no spacing between the unit-operand and a possible unit-exponent. It is recommended to use the simplest representation of exponents, meaning that the explicit + sign should be avoided, that leading zeros should be avoided, that rational exponents are reduced to not have common factors in the numerator and denominator, that rational exponents with denominator 1 should be avoided in favor of plain integer exponents, that the exponent 1 is omitted, and that entire factors with exponent 0 are omitted.

unit-operand :
   unit-symbol | unit-prefix unit-symbol
unit-prefix :
   "Y" | "Z" | "E" | "P" | "T" | "G" | "M" | "k" | "h" | "da"
   | "d" | "c" | "m" | "u" | "n" | "p" | "f" | "a" | "z" | "y"
unit-symbol :
   unit-char { unit-char }
unit-char :
   NON-DIGIT

It is required that basic and derived units of the SI system are recognized, but tools are allowed to additionally support user-defined unit symbols. The required unit symbols do not make use of Greek letters, but a unit such as Ω is spelled out as "Ohm". Similarly degree is spelled out as "deg", both on its own (for angles) and as part of "degC", "degF" and "degRk" for temperatures (Celsius, Fahrenheit and Rankine).

A unit-operand should first be interpreted as a unit-symbol and only if not successful the second alternative assuming a prefixed operand should be exploited. There must be no spacing between the unit-symbol and a possible unit-prefix. The values of the prefixes are according to the ISO standard. The letter u is used as a symbol for the prefix micro.

[A tool may present "Ohm" as Ω and the prefix "u" as μ. Exponents such as "m2" may be presented as m2. Degrees may be presented as , both for "deg" on its own (for angles) and for temperatures – e.g., "degC" can be presented as C. Note that BIPM have specific recommendations for formatting using these symbols.]

[Example: The unit expression "m" means meter and not milli (10-3), since prefixes cannot be used in isolation. For millimeter use "mm" and for square meter, m2, write "m2".

The expression "mm2" means (10-3m)2 = 10-6m2. Note that exponentiation includes the prefix.

The unit expression "T" means tesla, but note that the letter T is also the symbol for the prefix tera which has a multiplier value of 1012.]