Skip to content

Commit

Permalink
Make it possible for Evaluate = false to override Evaluate = true
Browse files Browse the repository at this point in the history
Addressing use case suggested by Hans.
  • Loading branch information
henrikt-ma committed Dec 9, 2020
1 parent 7b3343e commit 1be7531
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 4 deletions.
31 changes: 28 additions & 3 deletions chapters/annotations.tex
Expand Up @@ -340,9 +340,9 @@ \section{Annotations for Code Generation}\label{annotations-for-code-generation}
In the case of multiple conflicting annotations it is handled similarly to modifiers (e.g., an \lstinline!Evaluate! annotation on the component declaration takes precedence).
The annotation \lstinline!Evaluate! is only allowed for parameters and constants.

Setting \lstinline!Evaluate = true! is only allowed for structural parameters and constants.
For a structural parameter, it means that its value must be determined during translation, similar to a constant.
For both parameters and constants, the model developer further proposes to utilize the value for symbolic processing.
Setting \lstinline!Evaluate = true! for a structural parameter, means that its value must be determined during translation, similar to a constant.
For a normal parameter, it has no impact, and it is recommended to issue a warning (except when the parameter is normal due to dependency on a parameter with \lstinline!Evaluate = false!, as this could be a sign of intentional overriding of \lstinline!Evaluate = true!, see example below).
For both structural parameters and constants, the model developer further proposes to utilize the value for symbolic processing.
A constant can never be changed after translation, and it is normal for its value to be used for symbolic processing even without \lstinline!Evaluate = true!.

For a parameter, \lstinline!Evaluate = false! ensures that the parameter is a normal parameter according to \cref{component-variability-prefixes-discrete-parameter-constant} (meaning it is not allowed to be used where a structural expression (\cref{structural-expressions}) is expected).
Expand All @@ -351,6 +351,31 @@ \section{Annotations for Code Generation}\label{annotations-for-code-generation}
\begin{nonnormative}
\lstinline!Evaluate! is for example used for axis of rotation parameters in the \lstinline!Modelica.Mechanics.MultiBody! library in order to improve the efficiency of the generated code.
\end{nonnormative}

\begin{example}
When a parameter has \lstinline!Evaluate = true! has for optimization reasons (not because it needs to be structural), it is possible to prevent the value from being determined during translation without modifying the original model:
\begin{lstlisting}[language=modelica]
model M_structural
/* Here, 'b' is structural, and will be evaluated. */
parameter Boolean b = false annotation(Evaluate = true);
Real x(start = 1.0, fixed = true);
equation
if b then /* No need for b to be structural. */
der(x) = x;
else
der(x) = -x;
end if;
end M_structural;

model M_normal
/* Here, 'bn' is normal, which in turn will cause 'b' to be normal,
* thereby preventing it from being determined during translation.
*/
extends M_structural(b = bn);
parameter Boolean bn = false annotation(Evaluate = false);
end M_normal;
\end{lstlisting}
\end{example}
\end{semantics}
\end{annotationdefinition}

Expand Down
3 changes: 2 additions & 1 deletion chapters/classes.tex
Expand Up @@ -356,7 +356,8 @@ \subsection{Component Variability Prefixes discrete, parameter, constant}\label{
\end{nonnormative}

\begin{nonnormative}
For a parameter in a valid model, presence of \lstinline!Evaluate! (\cref{modelica:Evaluate}) makes it possible to tell immediately whether it is a structural or normal parameter, since \lstinline!Evaluate = false! makes it a normal parameter by definition, and \lstinline!Evaluate = true! is only allowed if the parameter is structural.
For a parameter in a valid model, presence of \lstinline!Evaluate! (\cref{modelica:Evaluate}) makes it possible to tell immediately whether it is a structural or normal parameter, at least as long as the warning described in \cref{modelica:Evaluate} isn't triggered.
To see this, note that \lstinline!Evaluate = false! makes it a normal parameter by definition, and that \lstinline!Evaluate = true! would trigger the warning if the parameter is normal.
\end{nonnormative}

By the acyclic binding rule in \cref{acyclic-bindings-of-constants-and-parameters}, it follows that the value of a constant or structural parameter to be used in simplifications is possible to obtain by evaluation of a structural expression where values are available for all component subexpressions.
Expand Down

0 comments on commit 1be7531

Please sign in to comment.