From a5d178fa446008aa66f57ae3f2992b5e2585a041 Mon Sep 17 00:00:00 2001 From: Henrik Tidefelt Date: Tue, 6 Dec 2022 22:14:56 +0100 Subject: [PATCH 1/3] Initial attempt at defining 'inUnit' conversion operator --- chapters/operatorsandexpressions.tex | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/chapters/operatorsandexpressions.tex b/chapters/operatorsandexpressions.tex index 289806ec8..1aa4a04cf 100644 --- a/chapters/operatorsandexpressions.tex +++ b/chapters/operatorsandexpressions.tex @@ -417,6 +417,7 @@ \subsection{Numeric Functions and Conversion Functions}\label{numeric-functions- {\lstinline!Integer($e$)!} & Conversion from enumeration to {\lstinline!Integer!} & \Cref{modelica:integer-of-enumeration} \\ {\lstinline!EnumTypeName($i$)!} & Conversion from {\lstinline!Integer!} to enumeration & \Cref{modelica:enumeration-of-integer} \\ {\lstinline!String($\ldots$)!} & Conversion to {\lstinline!String!} & \Cref{modelica:to-String} \\ +{\lstinline!inUnit($e$, $u$)!} & Convert to unit & \Cref{modelica:inUnit} \\ \hline \end{tabular} \end{center} @@ -540,6 +541,24 @@ \subsection{Numeric Functions and Conversion Functions}\label{numeric-functions- \end{semantics} \end{operatordefinition*} +\begin{functiondefinition}[inUnit] +\begin{synopsis}\begin{lstlisting} +inUnit($e$, $u$) +\end{lstlisting}\end{synopsis} +\begin{semantics} +Convert the \lstinline!Real! expression $e$ to unit $u$. +The unit $u$ shall be a \lstinline!String! parameter expression following the unit string syntax described in \cref{the-syntax-of-unit-expressions}. +Unit symbols in $u$ shall be interpreted as belonging to a relative quantity when $e$ has a unit corresponding to \lstinline!absoluteValue = false!, and otherwise as belonging to an absolute quantity (see \lstinline!absoluteValue!-annotation in \cref{graphical-user-interface}). +The unit of $e$ must be compatible with $u$. +\end{semantics} +\begin{nonnormative} +As described in \cref{the-syntax-of-unit-expressions}, there may be user-defined unit symbols in addition to the ones that must be recognized. +Hence, unit symbols that are recongized in one modeling environment may not be recognized in another. +Often, this results in an error since it prevents verifying unit compatibility. +It is a quality of implementation whether conversions that only involve changes of unit symbol prefixes are supported even when some unit symbols are unrecognized. +\end{nonnormative} +\end{functiondefinition} + \subsection{Event Triggering Mathematical Functions}\label{event-triggering-mathematical-functions} From fd38344ef2aa1db0de8c4eeee959ec46f03111f1 Mon Sep 17 00:00:00 2001 From: Henrik Tidefelt Date: Tue, 6 Dec 2022 22:50:35 +0100 Subject: [PATCH 2/3] Give semantics for converting expression with empty unit --- chapters/operatorsandexpressions.tex | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/chapters/operatorsandexpressions.tex b/chapters/operatorsandexpressions.tex index 1aa4a04cf..d3236b753 100644 --- a/chapters/operatorsandexpressions.tex +++ b/chapters/operatorsandexpressions.tex @@ -543,13 +543,18 @@ \subsection{Numeric Functions and Conversion Functions}\label{numeric-functions- \begin{functiondefinition}[inUnit] \begin{synopsis}\begin{lstlisting} -inUnit($e$, $u$) +inUnit($e$, $u$, absoluteValue = $a$) \end{lstlisting}\end{synopsis} \begin{semantics} Convert the \lstinline!Real! expression $e$ to unit $u$. The unit $u$ shall be a \lstinline!String! parameter expression following the unit string syntax described in \cref{the-syntax-of-unit-expressions}. -Unit symbols in $u$ shall be interpreted as belonging to a relative quantity when $e$ has a unit corresponding to \lstinline!absoluteValue = false!, and otherwise as belonging to an absolute quantity (see \lstinline!absoluteValue!-annotation in \cref{graphical-user-interface}). -The unit of $e$ must be compatible with $u$. +Unit symbols in $u$ shall be interpreted as belonging to an absolute quantity when $a$, and otherwise as belonging to a relative quantity. +To specify $a$, the named argument form must be used, and if omitted it is determined based on $e$ as described below. + +If $e$ has empty unit, \lstinline!absoluteValue! defaults to \lstinline!true!, and the unit $u$ gets attached to the value of $e$ without conversion. + +When $e$ has non-empty unit, \lstinline!absoluteValue! defaults to \lstinline!false! if $e$ is a relative quantity (corresponding to \lstinline!absoluteValue = false!, see \lstinline!absoluteValue!-annotation in \cref{graphical-user-interface}), and to true otherwise. +The non-empty unit of $e$ must be compatible with $u$. \end{semantics} \begin{nonnormative} As described in \cref{the-syntax-of-unit-expressions}, there may be user-defined unit symbols in addition to the ones that must be recognized. From aaa9dcf0af25c58749920fd59f5e5a2d10203a54 Mon Sep 17 00:00:00 2001 From: Henrik Tidefelt Date: Mon, 19 Dec 2022 22:10:29 +0100 Subject: [PATCH 3/3] Stress that the unit of the argument to 'inUnit' must be defined --- chapters/operatorsandexpressions.tex | 2 ++ 1 file changed, 2 insertions(+) diff --git a/chapters/operatorsandexpressions.tex b/chapters/operatorsandexpressions.tex index d3236b753..f63a75f6b 100644 --- a/chapters/operatorsandexpressions.tex +++ b/chapters/operatorsandexpressions.tex @@ -547,6 +547,8 @@ \subsection{Numeric Functions and Conversion Functions}\label{numeric-functions- \end{lstlisting}\end{synopsis} \begin{semantics} Convert the \lstinline!Real! expression $e$ to unit $u$. +It is required that the unit of $e$ is defined, possibly as being empty. +(Details of \emph{how} the unit is defined is a quality of implementation.) The unit $u$ shall be a \lstinline!String! parameter expression following the unit string syntax described in \cref{the-syntax-of-unit-expressions}. Unit symbols in $u$ shall be interpreted as belonging to an absolute quantity when $a$, and otherwise as belonging to a relative quantity. To specify $a$, the named argument form must be used, and if omitted it is determined based on $e$ as described below.