From 099ccb7795cfbc324eeabbef5e3b0760e1af0d14 Mon Sep 17 00:00:00 2001 From: HOS Date: Wed, 6 May 2026 16:47:33 +0200 Subject: [PATCH 01/11] Clarify simple function call. --- chapters/equations.tex | 3 +++ 1 file changed, 3 insertions(+) diff --git a/chapters/equations.tex b/chapters/equations.tex index ff800852b..170dc80c4 100644 --- a/chapters/equations.tex +++ b/chapters/equations.tex @@ -59,6 +59,9 @@ \subsection{Simple Equality Equations}\label{simple-equality-equations} Also compare with \cref{assignments-from-called-functions-with-multiple-results} about calling functions with multiple outputs in assignment statements. \end{nonnormative} +Note that there is also \lstinline!function_name(inexpr1, inexpr2);! which calls the given function or operator. +It behaves similarly to a simple equation (calling the function or operator but ignoring any potential output), even if it uses a different production in the grammar. +It is used for special operators like \lstinline!reinit! (\cref{reinit}), \lstinline!assert! (\cref{assert}), and \lstinline!terminate! (\cref{terminate}). \subsection{For-Equations -- Repetitive Equation Structures}\label{for-equations-repetitive-equation-structures} From c1cff5bbc435379b5a194d16a80f6e439541cda8 Mon Sep 17 00:00:00 2001 From: Hans Olsson Date: Thu, 7 May 2026 14:27:10 +0200 Subject: [PATCH 02/11] Update chapters/equations.tex Co-authored-by: Henrik Tidefelt --- chapters/equations.tex | 1 + 1 file changed, 1 insertion(+) diff --git a/chapters/equations.tex b/chapters/equations.tex index 170dc80c4..70a0dac0f 100644 --- a/chapters/equations.tex +++ b/chapters/equations.tex @@ -63,6 +63,7 @@ \subsection{Simple Equality Equations}\label{simple-equality-equations} It behaves similarly to a simple equation (calling the function or operator but ignoring any potential output), even if it uses a different production in the grammar. It is used for special operators like \lstinline!reinit! (\cref{reinit}), \lstinline!assert! (\cref{assert}), and \lstinline!terminate! (\cref{terminate}). + \subsection{For-Equations -- Repetitive Equation Structures}\label{for-equations-repetitive-equation-structures} The syntax of a \lstinline!for!-equation\index{for@\robustinline{for}!equation}\index{loop@\robustinline{loop}!for-equation@\robustinline{for}-equation} is given by \productionref{for-equation} in the grammar. From 6e984276ffa1d212e9f26b9e1ac84852766e8787 Mon Sep 17 00:00:00 2001 From: Hans Olsson Date: Thu, 4 Jun 2026 17:40:05 +0200 Subject: [PATCH 03/11] Update chapters/equations.tex --- chapters/equations.tex | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/chapters/equations.tex b/chapters/equations.tex index 70a0dac0f..54f2ca18f 100644 --- a/chapters/equations.tex +++ b/chapters/equations.tex @@ -60,7 +60,11 @@ \subsection{Simple Equality Equations}\label{simple-equality-equations} \end{nonnormative} Note that there is also \lstinline!function_name(inexpr1, inexpr2);! which calls the given function or operator. -It behaves similarly to a simple equation (calling the function or operator but ignoring any potential output), even if it uses a different production in the grammar. +It behaves similarly to a simple equation (calling the function or operator), even if it uses a different production in the grammar. +\begin{nonnormative} +If the function has any outputs they will be ignored. +That case is not recommended, but it is allowed to avoid having special rules in function-subtyping \cref{function-compatibility-or-function-subtyping-for-functions}. +\end{nonnormative} It is used for special operators like \lstinline!reinit! (\cref{reinit}), \lstinline!assert! (\cref{assert}), and \lstinline!terminate! (\cref{terminate}). From cb549b6a26e62122985b933d7b789726e72f50b3 Mon Sep 17 00:00:00 2001 From: Hans Olsson Date: Tue, 9 Jun 2026 13:37:57 +0200 Subject: [PATCH 04/11] Apply suggestion from @HansOlsson --- chapters/equations.tex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/chapters/equations.tex b/chapters/equations.tex index 54f2ca18f..f54d8d4cb 100644 --- a/chapters/equations.tex +++ b/chapters/equations.tex @@ -61,11 +61,11 @@ \subsection{Simple Equality Equations}\label{simple-equality-equations} Note that there is also \lstinline!function_name(inexpr1, inexpr2);! which calls the given function or operator. It behaves similarly to a simple equation (calling the function or operator), even if it uses a different production in the grammar. +It is used for special operators like \lstinline!reinit! (\cref{reinit}), \lstinline!assert! (\cref{assert}), and \lstinline!terminate! (\cref{terminate}). \begin{nonnormative} If the function has any outputs they will be ignored. That case is not recommended, but it is allowed to avoid having special rules in function-subtyping \cref{function-compatibility-or-function-subtyping-for-functions}. \end{nonnormative} -It is used for special operators like \lstinline!reinit! (\cref{reinit}), \lstinline!assert! (\cref{assert}), and \lstinline!terminate! (\cref{terminate}). \subsection{For-Equations -- Repetitive Equation Structures}\label{for-equations-repetitive-equation-structures} From f58e998505453fa2c757667baf55ff90ca54a39f Mon Sep 17 00:00:00 2001 From: Hans Olsson Date: Wed, 8 Jul 2026 16:10:08 +0200 Subject: [PATCH 05/11] Apply suggestions from code review Co-authored-by: Henrik Tidefelt --- chapters/equations.tex | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/chapters/equations.tex b/chapters/equations.tex index f54d8d4cb..5f670668d 100644 --- a/chapters/equations.tex +++ b/chapters/equations.tex @@ -59,9 +59,16 @@ \subsection{Simple Equality Equations}\label{simple-equality-equations} Also compare with \cref{assignments-from-called-functions-with-multiple-results} about calling functions with multiple outputs in assignment statements. \end{nonnormative} -Note that there is also \lstinline!function_name(inexpr1, inexpr2);! which calls the given function or operator. + +\subsection{Side-Effect Equations}\label{side-effect-equations} + +An equation in the following form calls the given function or operator: +\begin{itemize} +\item \lstinline!function_name(inexpr1, inexpr2);! +\end{itemize} It behaves similarly to a simple equation (calling the function or operator), even if it uses a different production in the grammar. It is used for special operators like \lstinline!reinit! (\cref{reinit}), \lstinline!assert! (\cref{assert}), and \lstinline!terminate! (\cref{terminate}). + \begin{nonnormative} If the function has any outputs they will be ignored. That case is not recommended, but it is allowed to avoid having special rules in function-subtyping \cref{function-compatibility-or-function-subtyping-for-functions}. From 22ad4cf067e6cb4be32563aceff0bae92e1201b9 Mon Sep 17 00:00:00 2001 From: Hans Olsson Date: Mon, 24 Aug 2026 17:06:42 +0200 Subject: [PATCH 06/11] Update chapters/equations.tex Co-authored-by: Henrik Tidefelt --- chapters/equations.tex | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/chapters/equations.tex b/chapters/equations.tex index 5f670668d..0a6ad0c15 100644 --- a/chapters/equations.tex +++ b/chapters/equations.tex @@ -62,7 +62,8 @@ \subsection{Simple Equality Equations}\label{simple-equality-equations} \subsection{Side-Effect Equations}\label{side-effect-equations} -An equation in the following form calls the given function or operator: +An equation in the form of just a \productionref{function-call} in the grammar calls the given function or operator. +Example: \begin{itemize} \item \lstinline!function_name(inexpr1, inexpr2);! \end{itemize} From 94fd5c9019434f28997227ee6fca323b76c5220c Mon Sep 17 00:00:00 2001 From: Hans Olsson Date: Mon, 24 Aug 2026 17:06:52 +0200 Subject: [PATCH 07/11] Update chapters/equations.tex Co-authored-by: Henrik Tidefelt --- chapters/equations.tex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/chapters/equations.tex b/chapters/equations.tex index 0a6ad0c15..d0725745e 100644 --- a/chapters/equations.tex +++ b/chapters/equations.tex @@ -68,7 +68,7 @@ \subsection{Side-Effect Equations}\label{side-effect-equations} \item \lstinline!function_name(inexpr1, inexpr2);! \end{itemize} It behaves similarly to a simple equation (calling the function or operator), even if it uses a different production in the grammar. -It is used for special operators like \lstinline!reinit! (\cref{reinit}), \lstinline!assert! (\cref{assert}), and \lstinline!terminate! (\cref{terminate}). +Besides calling user-defined functions for the side-effects, it is used for special operators like \lstinline!reinit! (\cref{reinit}), \lstinline!assert! (\cref{assert}), and \lstinline!terminate! (\cref{terminate}). \begin{nonnormative} If the function has any outputs they will be ignored. From def91e143e819b8705f2ee9434b6a359e0b33ac1 Mon Sep 17 00:00:00 2001 From: HOS Date: Wed, 2 Sep 2026 09:44:45 +0200 Subject: [PATCH 08/11] UpdateGrammar --- chapters/syntax.tex | 28 ++++++++-------------------- 1 file changed, 8 insertions(+), 20 deletions(-) diff --git a/chapters/syntax.tex b/chapters/syntax.tex index c8bb4d415..28388adc2 100644 --- a/chapters/syntax.tex +++ b/chapters/syntax.tex @@ -442,23 +442,17 @@ \subsection{Equations}\label{equations1} \begin{production}{some-equation} \begin{lstlisting} -( equation-or-procedure +( simple-equation + | function-call + | connect-equation | if-equation | for-equation - | connect-equation | when-equation ) description \end{lstlisting} \end{production} -\begin{production}{equation-or-procedure} -\begin{lstlisting} -simple-equation -| function-call -\end{lstlisting} -\end{production} - \begin{production}{simple-equation} \begin{lstlisting} simple-expression "=" expression @@ -467,7 +461,9 @@ \subsection{Equations}\label{equations1} \begin{production}{statement} \begin{lstlisting} -( statement-or-procedure +( function-call + | component-reference ":=" expression + | der "(" component-reference ")" ":=" expression | "(" output-expression-list ")" ":=" function-call | break @@ -481,14 +477,6 @@ \subsection{Equations}\label{equations1} \end{lstlisting} \end{production} -\begin{production}{statement-or-procedure} -\begin{lstlisting} -function-call -| component-reference ":=" expression -| der "(" component-reference ")" ":=" expression -\end{lstlisting} -\end{production} - \begin{production}{function-call} \begin{lstlisting} component-reference function-call-args @@ -588,8 +576,8 @@ \subsection{Equations}\label{equations1} \end{production} \begin{nonnormative} -The productions \productionref{equation-or-procedure} and \productionref{statement-or-procedure} are not suitable for recursive descent parsers. -A work-around is to left-factor them and for \productionref{equation-or-procedure} introduce semantic checks to ensure that only the grammar above is accepted. +The productions \productionref{some-equation} and \productionref{statement} are not suitable for recursive descent parsers, since the function name in a function call could be a component reference. +A work-around is to left-factor them and for \productionref{some-equation} introduce semantic checks to ensure that only the grammar above is accepted. \end{nonnormative} From 8d9dc7dee1c36035347ba474bf95bf4ef39bd1a3 Mon Sep 17 00:00:00 2001 From: HOS Date: Wed, 2 Sep 2026 09:55:39 +0200 Subject: [PATCH 09/11] UnrelatedSpelling --- chapters/equations.tex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/chapters/equations.tex b/chapters/equations.tex index d0725745e..7cae74b85 100644 --- a/chapters/equations.tex +++ b/chapters/equations.tex @@ -34,7 +34,7 @@ \section{Flattening and Lookup in Equations}\label{flattening-and-lookup-in-equa \section{Equations in Equation Sections}\label{equations-in-equation-sections} An equation section is comprised of the keyword \lstinline!equation!\index{equation@\robustinline{equation}} followed by a sequence of equations. -The syntax is given by \productionref{equation-section} in the grammar, and the different kinds of equatins that may occur within are given by \productionref{some-equation}. +The syntax is given by \productionref{equation-section} in the grammar, and the different kinds of equations that may occur within are given by \productionref{some-equation}. No statements are allowed in equation sections, including the assignment statement using the \lstinline!:=! operator. From c3c6a00c96f82187c4ad7ab795aefb40f440adbb Mon Sep 17 00:00:00 2001 From: HOS Date: Wed, 2 Sep 2026 10:01:50 +0200 Subject: [PATCH 10/11] Rebased, and moved subsections to subsubsections again to keep changes. --- chapters/equations.tex | 244 ++++++++++++++++++++--------------------- 1 file changed, 122 insertions(+), 122 deletions(-) diff --git a/chapters/equations.tex b/chapters/equations.tex index 7cae74b85..a5aafc7f3 100644 --- a/chapters/equations.tex +++ b/chapters/equations.tex @@ -76,6 +76,128 @@ \subsection{Side-Effect Equations}\label{side-effect-equations} \end{nonnormative} +\subsubsection{reinit}\label{reinit} + +\lstinline!reinit! can only be used in a \lstinline!when!-equation body. +It has the following syntax: +\begin{lstlisting}[language=modelica] +reinit(x, expr); +\end{lstlisting} + +The operator reinitializes \lstinline!x! with \lstinline!expr! at an event instant. +\lstinline!x! is a component-reference (where any subscripts are evaluable) referring to a \lstinline!Real! variable (or an array of \lstinline!Real! variables) that must be selected as a state (resp., states), i.e., \lstinline!reinit! on \lstinline!x! implies \lstinline!stateSelect = StateSelect.always! on \lstinline!x!. +\lstinline!expr! needs to be type-compatible with \lstinline!x!. +For any given variable (possibly an array variable), \lstinline!reinit! can only be applied (either to an individual variable or to a part of an array variable) in one \lstinline!when!-equation (applying \lstinline!reinit! to a variable in several branches of the same \lstinline!when!-equation is allowed). +If there are multiple \lstinline!reinit! for a variable inside one \lstinline!when!-equation body, they must appear in different branches of an \lstinline!if!-equation (in order that at most one \lstinline!reinit! for the variable is active at any event). +In case of \lstinline!reinit! active during initialization (due to \lstinline!when initial()!), see \cref{initialization-initial-equation-and-initial-algorithm}. + +\lstinline!reinit! does not break the single assignment rule, because \lstinline!reinit(x, expr)! in equations evaluates \lstinline!expr! to a value, then at the end of the current event iteration step it assigns this value to \lstinline!x! (this copying from values to reinitialized state(s) is done after all other evaluations of the model and before copying \lstinline!x! to \lstinline!pre(x)!). + +\begin{example} +If a higher index system is present, i.e., constraints between state variables, some state variables need to be redefined to non-state variables. +During simulation, non-state variables should be chosen in such a way that variables with an applied \lstinline!reinit! are selected as states at least during the events when the \lstinline!reinit!-equation is active. +If this is not possible, an error occurs, since otherwise \lstinline!reinit! would be applied to a non-state variable. + +Example for the usage of \lstinline!reinit! (bouncing ball): +\begin{lstlisting}[language=modelica] +der(h) = v; +der(v) = if flying then -g else 0; +flying = not (h <= 0 and v <= 0); +when h < 0 then + reinit(v, -e * pre(v)); +end when +\end{lstlisting} +\end{example} + + +\subsubsection{assert}\label{assert} + +An equation or statement of one of the following forms is an assertion\index{assert@\robustinline{assert}!equation}: +\begin{lstlisting}[language=modelica] +assert(condition, message); // Uses level=AssertionLevel.error +assert(condition, message, assertionLevel); +assert(condition, message, level = assertionLevel); +\end{lstlisting} +Here, \lstinline!condition! is a \lstinline!Boolean! expression, \lstinline!message! is a \lstinline!String! expression, and \lstinline!assertionLevel! is an optional evaluable expression of the built-in enumeration type \lstinline!AssertionLevel!. +It can be used in equation sections or algorithm sections. + +\begin{nonnormative} +This means that \lstinline!assert! can be called as if it were a function with three formal parameters, the third formal parameter has the name \lstinline!level! and the default value \lstinline!AssertionLevel.error!. +\end{nonnormative} + +If the \lstinline!condition! of an assertion is true, \lstinline!message! is not evaluated and the procedure call is ignored. +If the \lstinline!condition! evaluates to false, different actions are taken depending on the \lstinline!level! input: +\begin{itemize} +\item + \lstinline!level = AssertionLevel.error!: + The current evaluation is aborted. + The simulation may continue with another evaluation. + If the simulation is aborted, \lstinline!message! indicates the cause of the error. + \begin{nonnormative} + Ways to continue simulation with another evaluation include using a shorter step-size, or changing the values of iterationvariables. + \end{nonnormative} + Failed assertions take precedence over successful termination, such that if the model first triggers the end of successful analysis by reaching the stop-time or explicitly with \lstinline!terminate!, but the evaluation with \lstinline!terminal()=true! triggers an assert, the analysis failed. +\item + \lstinline!level = AssertionLevel.warning!: + The current evaluation is not aborted. + \lstinline!message! indicates the cause of the warning. + \begin{nonnormative} + It is recommended to report the warning only once when the condition becomes false, and it is reported that the condition is no longer violated when the condition returns to true. + The \lstinline!assert!-statement shall have no influence on the behavior of the model. + For example, by evaluating the condition and reporting the message only after accepted integrator steps. + \lstinline!condition! needs to be implicitly treated with \lstinline!noEvent! since otherwise events might be triggered that can lead to slightly changed simulation results. + \end{nonnormative} +\end{itemize} +Tools are recommended to provide more information than just the given message of a failed assertion, in particular the condition and the values of variables used in it. + +\begin{nonnormative} +The \lstinline!AssertionLevel.error! case can be used to avoid evaluating a model outside its limits of validity; for instance, a function to compute the saturated liquid temperature cannot be called with a pressure lower than the triple point value. + +The \lstinline!AssertionLevel.warning! case can be used when the boundary of validity is not hard: for instance, a fluid property model based on a polynomial interpolation curve might give accurate results between temperatures of 250 K and 400 K, but still give reasonable results in the range 200 K and 500 K. +When the temperature gets out of the smaller interval, but still stays in the largest one, the user should be warned, but the simulation should continue without any further action. +The corresponding code would be: +\begin{lstlisting}[language=modelica] +assert(T > 250 and T < 400, "Medium model outside full accuracy range", + AssertionLevel.warning); +assert(T > 200 and T < 500, "Medium model outside feasible region"); +\end{lstlisting} + +It is recommended that asserts have a simple message as above, formulated with the recommended tool behavior in mind. +Writing \lstinline!assert(T<500, "Temperature = "+String(T)+" was above 500")! is thus not recommended, and is likely to lead to duplicated information. +\end{nonnormative} + + +\subsubsection{terminate}\label{terminate} + +The \lstinline!terminate!\index{terminate@\robustinline{terminate}!equation@\robustinline{equation}}-equation or statement (using function syntax) successfully terminates the analysis which was carried out, see also \cref{assert}. +The termination is not immediate at the place where it is defined since not all variable results might be available that are necessary for a successful stop. +Instead, the termination actually takes place when the current integrator step is successfully finalized or at an event instant after the event handling has been completed before restarting the integration. + +\lstinline!terminate! takes a string argument indicating the reason for the success. + +\begin{example} +The intention of \lstinline!terminate! is to give more complex stopping criteria than a fixed point in time: +\begin{lstlisting}[language=modelica] +model ThrowingBall + Real x(start = 0); + Real y(start = 1); +equation + der(x) = $\ldots$; + der(y) = $\ldots$; +algorithm + when y < 0 then + terminate("The ball touches the ground"); + end when; +end ThrowingBall; +\end{lstlisting} +\end{example} + + +\subsubsection{Equation Operators for Overconstrained Connection-Based Equation Systems}\label{equation-operators-for-overconstrained-connection-based-equation-systems} + +See \cref{equation-operators-for-overconstrained-connection-based-equation-systems1} for a description of this topic. + + \subsection{For-Equations -- Repetitive Equation Structures}\label{for-equations-repetitive-equation-structures} The syntax of a \lstinline!for!-equation\index{for@\robustinline{for}!equation}\index{loop@\robustinline{loop}!for-equation@\robustinline{for}-equation} is given by \productionref{for-equation} in the grammar. @@ -415,128 +537,6 @@ \subsubsection{Single Assignment Rule Applied to When-Equations}\label{applicati \end{itemize} -\subsection{reinit}\label{reinit} - -\lstinline!reinit! can only be used in a \lstinline!when!-equation body. -It has the following syntax: -\begin{lstlisting}[language=modelica] -reinit(x, expr); -\end{lstlisting} - -The operator reinitializes \lstinline!x! with \lstinline!expr! at an event instant. -\lstinline!x! is a component-reference (where any subscripts are evaluable) referring to a \lstinline!Real! variable (or an array of \lstinline!Real! variables) that must be selected as a state (resp., states), i.e., \lstinline!reinit! on \lstinline!x! implies \lstinline!stateSelect = StateSelect.always! on \lstinline!x!. -\lstinline!expr! needs to be type-compatible with \lstinline!x!. -For any given variable (possibly an array variable), \lstinline!reinit! can only be applied (either to an individual variable or to a part of an array variable) in one \lstinline!when!-equation (applying \lstinline!reinit! to a variable in several branches of the same \lstinline!when!-equation is allowed). -If there are multiple \lstinline!reinit! for a variable inside one \lstinline!when!-equation body, they must appear in different branches of an \lstinline!if!-equation (in order that at most one \lstinline!reinit! for the variable is active at any event). -In case of \lstinline!reinit! active during initialization (due to \lstinline!when initial()!), see \cref{initialization-initial-equation-and-initial-algorithm}. - -\lstinline!reinit! does not break the single assignment rule, because \lstinline!reinit(x, expr)! in equations evaluates \lstinline!expr! to a value, then at the end of the current event iteration step it assigns this value to \lstinline!x! (this copying from values to reinitialized state(s) is done after all other evaluations of the model and before copying \lstinline!x! to \lstinline!pre(x)!). - -\begin{example} -If a higher index system is present, i.e., constraints between state variables, some state variables need to be redefined to non-state variables. -During simulation, non-state variables should be chosen in such a way that variables with an applied \lstinline!reinit! are selected as states at least during the events when the \lstinline!reinit!-equation is active. -If this is not possible, an error occurs, since otherwise \lstinline!reinit! would be applied to a non-state variable. - -Example for the usage of \lstinline!reinit! (bouncing ball): -\begin{lstlisting}[language=modelica] -der(h) = v; -der(v) = if flying then -g else 0; -flying = not (h <= 0 and v <= 0); -when h < 0 then - reinit(v, -e * pre(v)); -end when -\end{lstlisting} -\end{example} - - -\subsection{assert}\label{assert} - -An equation or statement of one of the following forms is an assertion\index{assert@\robustinline{assert}!equation}: -\begin{lstlisting}[language=modelica] -assert(condition, message); // Uses level=AssertionLevel.error -assert(condition, message, assertionLevel); -assert(condition, message, level = assertionLevel); -\end{lstlisting} -Here, \lstinline!condition! is a \lstinline!Boolean! expression, \lstinline!message! is a \lstinline!String! expression, and \lstinline!assertionLevel! is an optional evaluable expression of the built-in enumeration type \lstinline!AssertionLevel!. -It can be used in equation sections or algorithm sections. - -\begin{nonnormative} -This means that \lstinline!assert! can be called as if it were a function with three formal parameters, the third formal parameter has the name \lstinline!level! and the default value \lstinline!AssertionLevel.error!. -\end{nonnormative} - -If the \lstinline!condition! of an assertion is true, \lstinline!message! is not evaluated and the procedure call is ignored. -If the \lstinline!condition! evaluates to false, different actions are taken depending on the \lstinline!level! input: -\begin{itemize} -\item - \lstinline!level = AssertionLevel.error!: - The current evaluation is aborted. - The simulation may continue with another evaluation. - If the simulation is aborted, \lstinline!message! indicates the cause of the error. - \begin{nonnormative} - Ways to continue simulation with another evaluation include using a shorter step-size, or changing the values of iterationvariables. - \end{nonnormative} - Failed assertions take precedence over successful termination, such that if the model first triggers the end of successful analysis by reaching the stop-time or explicitly with \lstinline!terminate!, but the evaluation with \lstinline!terminal()=true! triggers an assert, the analysis failed. -\item - \lstinline!level = AssertionLevel.warning!: - The current evaluation is not aborted. - \lstinline!message! indicates the cause of the warning. - \begin{nonnormative} - It is recommended to report the warning only once when the condition becomes false, and it is reported that the condition is no longer violated when the condition returns to true. - The \lstinline!assert!-statement shall have no influence on the behavior of the model. - For example, by evaluating the condition and reporting the message only after accepted integrator steps. - \lstinline!condition! needs to be implicitly treated with \lstinline!noEvent! since otherwise events might be triggered that can lead to slightly changed simulation results. - \end{nonnormative} -\end{itemize} -Tools are recommended to provide more information than just the given message of a failed assertion, in particular the condition and the values of variables used in it. - -\begin{nonnormative} -The \lstinline!AssertionLevel.error! case can be used to avoid evaluating a model outside its limits of validity; for instance, a function to compute the saturated liquid temperature cannot be called with a pressure lower than the triple point value. - -The \lstinline!AssertionLevel.warning! case can be used when the boundary of validity is not hard: for instance, a fluid property model based on a polynomial interpolation curve might give accurate results between temperatures of 250 K and 400 K, but still give reasonable results in the range 200 K and 500 K. -When the temperature gets out of the smaller interval, but still stays in the largest one, the user should be warned, but the simulation should continue without any further action. -The corresponding code would be: -\begin{lstlisting}[language=modelica] -assert(T > 250 and T < 400, "Medium model outside full accuracy range", - AssertionLevel.warning); -assert(T > 200 and T < 500, "Medium model outside feasible region"); -\end{lstlisting} - -It is recommended that asserts have a simple message as above, formulated with the recommended tool behavior in mind. -Writing \lstinline!assert(T<500, "Temperature = "+String(T)+" was above 500")! is thus not recommended, and is likely to lead to duplicated information. -\end{nonnormative} - - -\subsection{terminate}\label{terminate} - -The \lstinline!terminate!\index{terminate@\robustinline{terminate}!equation@\robustinline{equation}}-equation or statement (using function syntax) successfully terminates the analysis which was carried out, see also \cref{assert}. -The termination is not immediate at the place where it is defined since not all variable results might be available that are necessary for a successful stop. -Instead, the termination actually takes place when the current integrator step is successfully finalized or at an event instant after the event handling has been completed before restarting the integration. - -\lstinline!terminate! takes a string argument indicating the reason for the success. - -\begin{example} -The intention of \lstinline!terminate! is to give more complex stopping criteria than a fixed point in time: -\begin{lstlisting}[language=modelica] -model ThrowingBall - Real x(start = 0); - Real y(start = 1); -equation - der(x) = $\ldots$; - der(y) = $\ldots$; -algorithm - when y < 0 then - terminate("The ball touches the ground"); - end when; -end ThrowingBall; -\end{lstlisting} -\end{example} - - -\subsection{Equation Operators for Overconstrained Connection-Based Equation Systems}\label{equation-operators-for-overconstrained-connection-based-equation-systems} - -See \cref{equation-operators-for-overconstrained-connection-based-equation-systems1} for a description of this topic. - - \section{Synchronous Data-Flow Principle and Single Assignment Rule}\label{synchronous-data-flow-principle-and-single-assignment-rule} Modelica is based on the synchronous data flow principle and the single assignment rule, which are defined in the following way: From 8a4a532895e3e40d0ca202ceb54beb1f37479cd8 Mon Sep 17 00:00:00 2001 From: HOS Date: Wed, 2 Sep 2026 10:08:03 +0200 Subject: [PATCH 11/11] RestructureStatements Rebased by removing the moved part. There was no actual change in in on main. --- chapters/statements.tex | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/chapters/statements.tex b/chapters/statements.tex index 05de59804..887cb11d4 100644 --- a/chapters/statements.tex +++ b/chapters/statements.tex @@ -140,6 +140,22 @@ \subsubsection{Assigned Variables - Restrictions}\label{restrictions-on-assigned Only components of the specialized classes \lstinline!type!, \lstinline!record!, \lstinline!operator record!, and \lstinline!connector! may appear as left-hand side in algorithms. This applies both to simple assignment statements, and the parenthesized, comma-separated list of variables for functions with multiple outputs. +\subsection{Side-Effect Statements}\label{side-effect-statements} + +A statement in the form of just a \productionref{function-call} in the grammar calls the given function or operator. +Besides calling user-defined functions for the side-effects, it is used for special operators listed below, similarly as for equations. +These side-effect statements have the same form and semantics as the corresponding equations, apart from the general difference in semantics between equations and statements. + +\subsubsection{Assert-Statement}\label{assert-statement} + +See \cref{assert}. +A failed \lstinline!assert!\index{assert@\robustinline{assert}!statement} stops the execution of the current algorithm. + +\subsubsection{Terminate-Statement}\label{terminate-statement} + +See \cref{terminate}. +The \lstinline!terminate!\index{terminate@\robustinline{terminate}!statement@\robustinline{statement}}-statement shall not be used in functions. +In an algorithm outside a function it does not stop the execution of the current algorithm. \subsection{For-Statement}\label{for-statement} @@ -432,17 +448,3 @@ \subsubsection{Defining When-Statements by If-Statements}\label{defining-when-st with \lstinline!edge(A) = A and not pre(A)! and the additional guarantee, that the statements within this special \lstinline!if!-statement are only evaluated at event instants. The difference compared to the \lstinline!when!-statements is that, e.g., \lstinline!pre! may only be used on continuous-time real variables inside a \lstinline!when!-clause body and not inside these \lstinline!if!-statements. -\subsection{Special Statements}\label{special-statements} - -These special statements have the same form and semantics as the corresponding equations, apart from the general difference in semantics between equations and statements. - -\subsubsection{Assert-Statement}\label{assert-statement} - -See \cref{assert}. -A failed \lstinline!assert!\index{assert@\robustinline{assert}!statement} stops the execution of the current algorithm. - -\subsubsection{Terminate-Statement}\label{terminate-statement} - -See \cref{terminate}. -The \lstinline!terminate!\index{terminate@\robustinline{terminate}!statement@\robustinline{statement}}-statement shall not be used in functions. -In an algorithm outside a function it does not stop the execution of the current algorithm.