Skip to content

Commit

Permalink
Merge pull request modelica#3013 from henrikt-ma/cleanup/unit-syntax
Browse files Browse the repository at this point in the history
Clean up chapter 'Unit Expressions'
  • Loading branch information
HansOlsson committed Oct 26, 2021
2 parents 8c381e3 + d781303 commit bff744f
Showing 1 changed file with 50 additions and 69 deletions.
119 changes: 50 additions & 69 deletions chapters/unitexpressions.tex
@@ -1,105 +1,86 @@
\chapter{Unit Expressions}\label{unit-expressions}

Unless otherwise stated, the syntax and semantics of unit expressions in
Modelica conform with the international standards
\emph{International System of Units (SI)} by BIPM superseding parts of
ISO 31/0-1992
\emph{General principles concerning quantities, units and symbols} and ISO
1000-1992 \emph{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: \lstinline!"N.m"!,
\lstinline!"kg.m/s2"!, \lstinline!"kg.m.s-2"! \lstinline!"1/rad"!,
\lstinline!"mm/s"!.
Unless otherwise stated, the syntax and semantics of unit expressions in Modelica conform with the international standards \emph{International System of Units (SI)} by BIPM superseding parts of ISO 31/0-1992 \emph{General principles concerning quantities, units and symbols} and ISO 1000-1992 \emph{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 \emph{meter}, whereas the SI specification from BIPM uses the British spelling \emph{metre}.

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

\section{The Syntax of Unit Expressions}\label{the-syntax-of-unit-expressions}

The Modelica unit string syntax allows neither comments nor white-space, and a unit string shall match the \lstinline[language=grammar]!unit-expression! rule:
\begin{lstlisting}[language=grammar]
unit_expression:
unit_numerator [ "/" unit_denominator ]
unit-expression :
unit-numerator [ "/" unit-denominator ]

unit_numerator:
"1" | unit_factors | "(" unit_expression ")"
unit-numerator :
"1" | unit-factors | "(" unit-expression ")"

unit_denominator:
unit_factor | "(" unit_expression ")"
unit-denominator:
unit-factor | "(" unit-expression ")"
\end{lstlisting}

The unit of measure of a dimension free quantity is denoted by \lstinline!"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 (\lstinline!/!) since the result is ambiguous; either the divisor shall be enclosed in parentheses,
or negative exponents used instead of division, for example, \lstinline!"J/(kg.K)"! may be written as \lstinline!"J.kg-1.K-1"!.
The unit of measure of a dimension free quantity is denoted by \lstinline!"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 (\lstinline!/!) since the result is ambiguous; either the divisor shall be enclosed in parentheses, or negative exponents used instead of division, for example, \lstinline!"J/(kg.K)"! may be written as \lstinline!"J.kg-1.K-1"!.

\begin{lstlisting}[language=grammar]
unit_factors:
unit_factor [ unit_mulop unit_factors ]

unit_mulop:
"."
unit-factors :
unit-factor [ "." unit-factors ]
\end{lstlisting}

The SI standard specifies that a multiplication operator symbol is written as space
or as a dot. The SI standard requires that this \emph{dot} is a bit above the base line: `·', which is not part of ASCII.
The SI standard specifies that a multiplication operator symbol is written as space or as a dot.
The SI standard requires that this \emph{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 \emph{dot} on the base line.

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

\begin{lstlisting}[language=grammar]
unit_factor:
unit_operand [ unit_exponent ]
unit-factor :
unit-operand [ unit-exponent ]

unit_exponent:
[ "+" | "-" ] integer
unit-exponent :
[ "+" | "-" ] UNSIGNED-INTEGER
\end{lstlisting}

The SI standard uses super-script for the exponentation, and does thus not define any operator symbol for exponentiation.
A \lstinline!unit_factor! consists of a \lstinline!unit_operand! possibly suffixed by a
possibly signed integer number, which is interpreted as an exponent.
There must be no spacing between the \lstinline!unit_operand! and a possible
\lstinline!unit_exponent!.
A \lstinline[language=grammar]!unit-factor! consists of a \lstinline[language=grammar]!unit-operand! possibly suffixed by a possibly signed integer number, which is interpreted as an exponent.
There must be no spacing between the \lstinline[language=grammar]!unit-operand! and a possible \lstinline[language=grammar]!unit-exponent!.

\begin{lstlisting}[language=grammar]
unit_operand:
unit_symbol | unit_prefix unit_symbol
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_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 }
\end{lstlisting}

A \lstinline!unit_symbol! is a string of letters. A basic support of units in
Modelica should know the basic and derived units of the SI system. It is
possible to support user defined unit symbols. In the base version Greek
letters is not supported, but full names must then be written, for
example \lstinline!"Ohm"!.
A \lstinline[language=grammar]!unit-symbol! is a non-empty string of \lstinline[language=grammar]!unit-char! characters.
The set of allowed characters is currently not defined.
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 $\Omega$ is spelled out as \lstinline!"Ohm"!.

A \lstinline!unit_operand! should first be interpreted as a \lstinline!unit_symbol! and only
if not successful the second alternative assuming a prefixed operand
should be exploited. There must be no spacing between the \lstinline!unit_symbol!
and a possible \lstinline!unit_prefix!. The values of the prefixes are according to
the ISO standard. The letter \lstinline!u! is used as a symbol for the prefix
micro.
A \lstinline[language=grammar]!unit-operand! should first be interpreted as a \lstinline[language=grammar]!unit-symbol! and only if not successful the second alternative assuming a prefixed operand should be exploited.
There must be no spacing between the \lstinline[language=grammar]!unit-symbol! and a possible \lstinline[language=grammar]!unit-prefix!.
The values of the prefixes are according to the ISO standard.
The letter \lstinline!u! is used as a symbol for the prefix \emph{micro}.

\begin{nonnormative}
A tool may present \lstinline!Ohm! as $\Omega$ and the prefix \lstinline!u! as $\mu$, and similarly \lstinline!m2! as $m^2$.
A tool may present \lstinline!Ohm! as $\Omega$ and the prefix \lstinline!u! as $\mu$, and similarly \lstinline!m2! as m\textsuperscript{2}.
\end{nonnormative}

\section{Examples}\label{examples2}

The unit expression \lstinline!"m"! means meter and not milli
(10\textsuperscript{-3}), since prefixes cannot be used in isolation.
For millimeter use \lstinline!"mm"! and for square meter, m\textsuperscript{2}, write
\lstinline!"m2"!.
The unit expression \lstinline!"m"! means meter and not milli (10\textsuperscript{-3}), since prefixes cannot be used in isolation.
For millimeter use \lstinline!"mm"! and for square meter, m\textsuperscript{2}, write \lstinline!"m2"!.

The expression \lstinline!"mm2"! means (10\textsuperscript{-3}m)2 =
10\textsuperscript{-6}m\textsuperscript{2}. Note that exponentiation
includes the prefix.
The expression \lstinline!"mm2"! means (10\textsuperscript{-3}m)\textsuperscript{2} = 10\textsuperscript{-6}m\textsuperscript{2}.
Note that exponentiation includes the prefix.

The unit expression \lstinline!"T"! means tesla, but note that the letter \lstinline!T! is
also the symbol for the prefix tera which has a multiplier value of
10\textsuperscript{12}.
The unit expression \lstinline!"T"! means tesla, but note that the letter \lstinline!T! is also the symbol for the prefix tera which has a multiplier value of 10\textsuperscript{12}.

0 comments on commit bff744f

Please sign in to comment.