Skip to content

Commit

Permalink
Sentence-based line breaking in statements.tex
Browse files Browse the repository at this point in the history
This file was already mostly in good shape, so this is a low hanging fruit.
  • Loading branch information
henrikt-ma committed Aug 11, 2021
1 parent e7c6e96 commit a0adcc7
Showing 1 changed file with 21 additions and 39 deletions.
60 changes: 21 additions & 39 deletions 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.

Expand All @@ -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.
Expand All @@ -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]
Expand All @@ -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:
Expand Down Expand Up @@ -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}
Expand Down Expand Up @@ -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];
Expand All @@ -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]
Expand Down

0 comments on commit a0adcc7

Please sign in to comment.