From a0adcc7e3a0311dfa6c171f6aa6260204f1d71a3 Mon Sep 17 00:00:00 2001 From: Henrik Tidefelt Date: Wed, 11 Aug 2021 07:56:23 +0200 Subject: [PATCH] Sentence-based line breaking in statements.tex This file was already mostly in good shape, so this is a low hanging fruit. --- chapters/statements.tex | 60 +++++++++++++++-------------------------- 1 file changed, 21 insertions(+), 39 deletions(-) diff --git a/chapters/statements.tex b/chapters/statements.tex index 3ac8a0b80..1fd06dd52 100644 --- a/chapters/statements.tex +++ b/chapters/statements.tex @@ -1,9 +1,7 @@ \chapter{Statements and Algorithm Sections}\label{statements-and-algorithm-sections} -Whereas equations are very well suited for physical modeling, there are -situations where computations are more conveniently expressed as -algorithms, i.e., sequences of statements. In this chapter we describe -the algorithmic constructs that are available in Modelica. +Whereas equations are very well suited for physical modeling, there are situations where computations are more conveniently expressed as algorithms, i.e., sequences of statements. +In this chapter we describe the algorithmic constructs that are available in Modelica. Statements are imperative constructs allowed in algorithm sections. @@ -30,11 +28,8 @@ \subsection{Initial Algorithm Sections}\label{initial-algorithm-sections} \subsection{Execution of an algorithm in a model}\label{execution-of-an-algorithm-in-a-model} -An algorithm section is conceptually a code fragment that remains -together and the statements of an algorithm section are executed in the -order of appearance. Whenever an algorithm section is invoked, all -variables appearing on the left hand side of the assignment operator -\lstinline!:=! are initialized (at least conceptually): +An algorithm section is conceptually a code fragment that remains together and the statements of an algorithm section are executed in the order of appearance. +Whenever an algorithm section is invoked, all variables appearing on the left hand side of the assignment operator \lstinline!:=! are initialized (at least conceptually): \begin{itemize} \item A continuous-time variable is initialized with the value of its \lstinline!start!-attribute. @@ -47,19 +42,12 @@ \subsection{Execution of an algorithm in a model}\label{execution-of-an-algorith \end{itemize} \begin{nonnormative} -Initialization is performed, in order that an algorithm section -cannot introduce a ``memory'' (except in the case of discrete-time variables assigned in the algorithm), which could invalidate the assumptions of a -numerical integration algorithm. Note, a Modelica tool may change the -evaluation of an algorithm section, provided the result is identical to -the case, as if the above conceptual processing is performed. - -An algorithm section is treated as an atomic vector-equation, -which is sorted together with all other equations. For the sorting -process (BLT), every algorithm section with N different left-hand side -variables, is treated as an atomic N-dimensional vector-equation -containing all variables appearing in the algorithm section. This -guarantees that all N equations end up in an algebraic loop and the -statements of the algorithm section remain together. +Initialization is performed, in order that an algorithm section cannot introduce a ``memory'' (except in the case of discrete-time variables assigned in the algorithm), which could invalidate the assumptions of a numerical integration algorithm. +Note, a Modelica tool may change the evaluation of an algorithm section, provided the result is identical to the case, as if the above conceptual processing is performed. + +An algorithm section is treated as an atomic vector-equation, which is sorted together with all other equations. +For the sorting process (BLT), every algorithm section with N different left-hand side variables, is treated as an atomic N-dimensional vector-equation containing all variables appearing in the algorithm section. +This guarantees that all N equations end up in an algebraic loop and the statements of the algorithm section remain together. Example: \begin{lstlisting}[language=modelica] @@ -82,22 +70,17 @@ \subsection{Execution of the algorithm in a function}\label{execution-of-the-alg \section{Statements}\label{statements} -Statements are imperative constructs allowed in algorithm sections. A -flattened statement is identical to the corresponding nonflattened -statement. +Statements are imperative constructs allowed in algorithm sections. +A flattened statement is identical to the corresponding nonflattened statement. Names in statements are found as follows: \begin{itemize} \item - If the name occurs inside an expression: it is first found among the - lexically enclosing reduction functions (see \cref{reduction-functions-and-operators}) in order - starting from the inner-most, and if not found it proceeds as if it - were outside an expression: + If the name occurs inside an expression: it is first found among the lexically enclosing reduction functions (see \cref{reduction-functions-and-operators}) in order starting from the inner-most, and if not found it proceeds as if it were outside an expression: \item Names in a statement are first found among the lexically enclosing \lstinline!for!-statements in order starting from the inner-most, and if not found: \item - Names in a statement shall be found by looking up in the partially - flattened enclosing class of the algorithm section. + Names in a statement shall be found by looking up in the partially flattened enclosing class of the algorithm section. \end{itemize} The syntax of statements is as follows: @@ -151,21 +134,20 @@ \subsubsection{Assignments from Called Functions with Multiple Results}\label{as (a, b, c) := f(1.0, 2.0); (x[1], x[2], x[1]) := f(3, 4); \end{lstlisting} -In the second example above \lstinline!x[1]! is assigned twice: first with the first output, and then with the third output. For that case the following will give the same result: +In the second example above \lstinline!x[1]! is assigned twice: first with the first output, and then with the third output. +For that case the following will give the same result: \begin{lstlisting}[language=modelica] (, x[2], x[1]) := f(3,4); \end{lstlisting} \end{example} -The syntax of an assignment statement with a call to a function with -multiple results is as follows: +The syntax of an assignment statement with a call to a function with multiple results is as follows: \begin{lstlisting}[language=grammar] "(" output-expression-list ")" ":=" component-reference function-call-args \end{lstlisting} \begin{nonnormative} -Also see \cref{simple-equality-equations} regarding calling functions with -multiple results within equations. +Also see \cref{simple-equality-equations} regarding calling functions with multiple results within equations. \end{nonnormative} \subsubsection{Restrictions on assigned variables}\label{restrictions-on-assigned-variables} @@ -203,7 +185,8 @@ \subsection{For-statement}\label{for-statement} for i in TwoEnums loop // i takes the values TwoEnums.one, TwoEnums.two // for TwoEnums = enumeration(one, two) \end{lstlisting} -The loop-variable may hide other variables as in the following example. Using another name for the loop-variable is, however, strongly recommended. +The loop-variable may hide other variables as in the following example. +Using another name for the loop-variable is, however, strongly recommended. \begin{lstlisting}[language=modelica] constant Integer j = 4; Real x[j]; @@ -221,8 +204,7 @@ \subsubsection{Implicit Iteration Ranges}\label{implicit-iteration-ranges} If it is used to subscript several expressions, their ranges must be identical. The \lstinline!IDENT! may also, inside a reduction expression, array constructor expression, \lstinline!for!-statement, or \lstinline!for!-equation, occur freely outside of subscript positions, but only as a reference to the variable \lstinline!IDENT!, and not for deducing ranges. -The \lstinline!IDENT! may also be used as a subscript for an array in a component of an expandable connector -but it is only seen as a reference to the variable \lstinline!IDENT! and cannot be used for deducing ranges. +The \lstinline!IDENT! may also be used as a subscript for an array in a component of an expandable connector but it is only seen as a reference to the variable \lstinline!IDENT! and cannot be used for deducing ranges. \begin{example} \begin{lstlisting}[language=modelica]