diff --git a/chapters/functions.tex b/chapters/functions.tex index 87bf5a57b..3ea3135cc 100644 --- a/chapters/functions.tex +++ b/chapters/functions.tex @@ -171,7 +171,7 @@ \section{Function as a Specialized Class}\label{function-as-a-specialized-class} \item For initialization of local variables of a function see \cref{initialization-and-binding-equations-of-components-in-functions}). \item - Components of a function will inside the function behave as though they had discrete-time variability. + Components of a function will inside the function with some exceptions behave as though they had discrete-time variability, see \cref{discrete-time-expressions} for details. \end{itemize} Modelica functions have the following enhancements compared to a general Modelica \lstinline!class!: diff --git a/chapters/operatorsandexpressions.tex b/chapters/operatorsandexpressions.tex index 6f55a2efb..955f9ca2b 100644 --- a/chapters/operatorsandexpressions.tex +++ b/chapters/operatorsandexpressions.tex @@ -1582,7 +1582,7 @@ \subsection{Evaluable Expressions}\label{evaluable-expressions} \item Evaluable parameter variables, see \cref{component-variability}. \item - Input variables in functions behave as though they were evaluable expressions. + Input variables in functions not having annotation \lstinline!GenerateEvents = true! (\Cref{modelica:GenerateEvents}) behave as though they were evaluable expressions. \item Except for the special built-in operators \lstinline!initial!, \lstinline!terminal!, \lstinline!der!, \lstinline!edge!, \lstinline!change!, \lstinline!sample!, and \lstinline!pre!, a function or operator with evaluable subexpressions is an evaluable expression. \item @@ -1593,7 +1593,7 @@ \subsection{Evaluable Expressions}\label{evaluable-expressions} \item \lstinline!cardinality(c)!, see restrictions for use in \cref{cardinality-deprecated}. \item - \lstinline!size(A)! (including \lstinline!size(A, j)! where \lstinline!j! is an evaluable expression) if \lstinline!A! is variable declared in a non-function class. + \lstinline!size(A)! (including \lstinline!size(A, j)! where \lstinline!j! is an evaluable expression) if \lstinline!A! is variable declared in a non-function class, or as input in a function having annotation \lstinline!GenerateEvents = true! (\Cref{modelica:GenerateEvents}). \item \lstinline!Connections.isRoot(A.R)! \item @@ -1644,10 +1644,14 @@ \subsection{Discrete-Time Expressions}\label{discrete-time-expressions} Note that \lstinline!rem! and \lstinline!mod! generate events but are not discrete-time expressions. In other words, relations inside \lstinline!noEvent!, such as \lstinline!noEvent(x>1)!, are not discrete-time expressions. \end{nonnormative} +\item + Unless inside \lstinline!noEvent!: Function calls where the function has annotation \lstinline!GenerateEvents = true! (\Cref{modelica:GenerateEvents}) and the output does not contain a subtype of \lstinline!Real!. + For a function call returning multiple return values (see \cref{output-formal-parameters-of-functions}) the variability is decided separately for each output. + These calls will generate events, \Cref{modelica:GenerateEvents}. \item The functions \lstinline!pre!, \lstinline!edge!, and \lstinline!change! result in discrete-time expressions. \item - Expressions in functions behave as though they were discrete-time expressions. + Expressions in functions not having annotation \lstinline!GenerateEvents = true! (\Cref{modelica:GenerateEvents}), behave as though they were discrete-time expressions. \end{itemize} Inside an \lstinline!if!-expression, \lstinline!if!-clause, \lstinline!while!-statement or \lstinline!for!-clause, that is controlled by a non-discrete-time (that is continuous-time, but not discrete-time) switching expression and not in the body of a \lstinline!when!-clause, it is not legal to have assignments to discrete-time variables, equations between discrete-time expressions, or real elementary relations/functions that should generate events.