From b68df7da3925934746891c0f49bf58b3f73eb82c Mon Sep 17 00:00:00 2001 From: Henrik Tidefelt Date: Mon, 1 Jun 2020 23:55:49 +0200 Subject: [PATCH 01/78] Avoid use of \texttt in arrays.tex --- chapters/arrays.tex | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/chapters/arrays.tex b/chapters/arrays.tex index dccce5718..78c5a8f9d 100644 --- a/chapters/arrays.tex +++ b/chapters/arrays.tex @@ -295,35 +295,35 @@ \subsection{Specialized Array Constructor Functions}\doublelabel{specialized-arr \hline \tablehead{Modelica} & \tablehead{Explanation}\\ \hline \endhead -\lstinline!identity(n)! +\lstinline[mathescape=true]!identity($n$)! & -Returns the n x n Integer identity matrix, with ones on the diagonal and +Returns the $n \times n$ \lstinline!Integer! identity matrix, with ones on the diagonal and zeros at the other places.\\ \hline \lstinline!diagonal(v)! & Returns a square matrix with the elements of vector v on the diagonal and all other elements zero.\\ \hline -\texttt{zeros(n\textsubscript 1,n\textsubscript 2,n\textsubscript 3,...)} & -Returns the $n_1$ x $n_2$ x $n_3$ x ... \lstinline!Integer! array with all elements equal to zero ($n_i \geq 0$). -The function need one or more arguments, that is \lstinline!zeros()! is not legal.\\ \hline -\texttt{ones(n\textsubscript 1,n\textsubscript 2,n\textsubscript 3,...)} & -Return the $n_1$ x $n_2$ x $n_3$ x ... Integer array with all elements equal to one ($n_i \geq 0$). -The function need one or more arguments, that is \lstinline!ones()! is not legal.\\ \hline -\texttt{fill(s,n\textsubscript 1,n\textsubscript 2,n\textsubscript 3,...)} & -Returns the $n_1$ x $n_2$ x $n_3$ x ... array with all elements equal to scalar or array expression s -($n_i \geq 0$). The returned array has the same type as \lstinline!s!. +\lstinline[mathescape=true]!zeros($n_{1}$, $n_{2}$, $n_{3}$, $\ldots$)! & +Returns the $n_{1} \times n_{2} \times n_{3} \times \ldots$ \lstinline!Integer! array with all elements equal to zero ($n_{i} \geq 0$). +The function needs one or more arguments, that is \lstinline!zeros()! is not legal.\\ \hline +\lstinline[mathescape=true]!ones($n_{1}$, $n_{2}$, $n_{3}$, $\ldots$)! & +Return the $n_{1} \times n_{2} \times n_{3} \times \ldots$ \lstinline!Integer! array with all elements equal to one ($n_{i} \geq 0$). +The function needs one or more arguments, that is \lstinline!ones()! is not legal.\\ \hline +\lstinline[mathescape=true]!fill(s, $n_{1}$, $n_{2}$, $n_{3}$, $\ldots$)! & +Returns the $n_{1} \times n_{2} \times n_{3} \times \ldots$ array with all elements equal to scalar or array expression $s$ +($n_{i} \geq 0$). The returned array has the same type as \lstinline!s!. Recursive definition: -\lstinline!fill!(s,$n_1$,$n_2$,$n_3$,...) = -\lstinline!fill!(\lstinline!fill!(s,$n_2$,$n_3$, ...), -$n_1$,); \lstinline!fill!(s,n)=\{s,s,\ldots{}, s\} +\lstinline[mathescape=true]!fill(s, $n_{1}$, $n_{2}$, $n_{3}$, $\ldots$)! = +\lstinline[mathescape=true]!fill(fill(s, $n_{2}$, $n_{3}$, $\ldots$), $n_{1}$)!; +\lstinline[mathescape=true]!fill(s, $n$)! = \lstinline[mathescape=true]!{s, s, $\ldots$, s}! The function needs two or more arguments; that is \lstinline!fill(s)! is not legal.\\ \hline -\lstinline!linspace(x1,x2,n)! +\lstinline[mathescape=true]!linspace(x1, x2, $n$)! & -Returns a \lstinline!Real! vector with \lstinline!n! equally spaced elements, such that -$v = \text{\lstinline!linspace(x1, x2, n)!}$ results in -\lstinline!v[i] = x1 + (x2-x1)*(i-1)/(n-1)! for $1 \leq \text{\lstinline!i!} \leq \text{\lstinline!n!}$. -It is required that $\text{\lstinline!n!} \geq 2$. The arguments \lstinline!x1! and \lstinline!x2! shall +Returns a \lstinline!Real! vector with $n$ equally spaced elements, such that +\lstinline[mathescape=true]!v = linspace(x1, x2, $n$)! results in +\lstinline[mathescape=true]!v[$i$] = x1 + (x2-x1)*($i$-1)/($n$-1)! for $1 \leq i \leq n$. +It is required that $n \geq 2$. The arguments \lstinline!x1! and \lstinline!x2! shall be numeric scalar expressions.\\ \hline \end{longtable} From 694794c784cbdea2bd6243f0750715baa19a7601 Mon Sep 17 00:00:00 2001 From: Henrik Tidefelt Date: Mon, 1 Jun 2020 23:56:08 +0200 Subject: [PATCH 02/78] Avoid use of \texttt in connectors.tex --- chapters/connectors.tex | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/chapters/connectors.tex b/chapters/connectors.tex index 00e717161..879ac3728 100644 --- a/chapters/connectors.tex +++ b/chapters/connectors.tex @@ -435,13 +435,13 @@ \section{Generation of Connection Equations}\doublelabel{generation-of-connectio (zero-sum) variables of the form \begin{itemize} \item -\lstinline!a1 = a2 = ... = an; // neither flow nor stream variables! +$a_{1} = a_{2} = \ldots = a_{n}$ (neither flow nor stream variables) \item -\lstinline!z1 + z2 + (-z3) + ... + zn =! \small{\textbf{0}} \lstinline!; // flow-variables! +$z_{1} + z_{2} + (-z_{3}) + \ldots + z_{n} = \mathbf{0}$ (flow-variables) \end{itemize} -The bold-face \textbf{0} represents an array or scalar zero of -appropriate dimensions (i.e. the same size as z). +The bold-face $\mathbf{0}$ represents an array or scalar zero of +appropriate dimensions (i.e. the same size as $z$). For an \lstinline!operator record! type this uses the operator \lstinline!'0'! -- which must be defined in the operator record; and all of the flow-variables for the @@ -452,8 +452,8 @@ \section{Generation of Connection Equations}\doublelabel{generation-of-connectio In order to generate equations for flow variables (using the \lstinline!flow! prefix), the sign used for the connector variable -\texttt{z\textsubscript{i}} above is +1 for inside connectors and -1 for outside -connectors (\texttt{z\textsubscript{3}} in the example above). +$z_{i}$ above is +1 for inside connectors and -1 for outside +connectors ($z_{3}$ in the example above). \begin{example} Simple example: From ade428db9da60e9b144a15d1f24f8dd537c703be Mon Sep 17 00:00:00 2001 From: Henrik Tidefelt Date: Mon, 1 Jun 2020 23:56:27 +0200 Subject: [PATCH 03/78] Avoid use of \texttt in functions.tex --- chapters/functions.tex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/chapters/functions.tex b/chapters/functions.tex index 4ec47eaea..b5fd51812 100644 --- a/chapters/functions.tex +++ b/chapters/functions.tex @@ -2068,7 +2068,7 @@ \subsection{Return Type Mapping}\doublelabel{return-type-mapping} \lstinline!Integer! & \lstinline!int! & \lstinline!INTEGER!\\ \hline \lstinline!Boolean! & \lstinline!int! & \lstinline!LOGICAL!\\ \hline \lstinline!String! & \lstinline!const char*! & Not allowed.\\ \hline -\texttt{T}{[}$\texttt{dim}_1$, \ldots{}, $\texttt{dim}_{n}${]} & Not allowed. & Not allowed.\\ \hline +\lstinline[mathescape=true]!T[$\mathit{dim}_{1}$, $\ldots$, $\mathit{dim}_{n}$]! & Not allowed. & Not allowed.\\ \hline Enumeration type & \lstinline!int! & \lstinline!INTEGER!\\ \hline Record & See \autoref{records}. & Not allowed.\\ \hline \end{longtable} From a48d5978c364981b9ca282c67acf3d99100c43d3 Mon Sep 17 00:00:00 2001 From: Henrik Tidefelt Date: Mon, 1 Jun 2020 23:56:41 +0200 Subject: [PATCH 04/78] Avoid use of \texttt in stream.tex To get consistent formatting of subscripted variables inside Modelica source code, this involves changes in many places besides those where there used to be a \texttt --- chapters/stream.tex | 184 +++++++++++++++++++++----------------------- preamble.tex | 1 + 2 files changed, 89 insertions(+), 96 deletions(-) diff --git a/chapters/stream.tex b/chapters/stream.tex index b7f81eb69..273560fa4 100644 --- a/chapters/stream.tex +++ b/chapters/stream.tex @@ -1,9 +1,5 @@ \chapter{Stream Connectors}\doublelabel{stream-connectors} -%TODO-FORMAT This chapter uses _ in code blocks and inline code. -%This is no real Modelica code, but indicates a mathematical index. -%We currently use \texttt{m\textsubscript j} instead of \lstinline!m_j! - The two basic variable types in a connector -- \emph{potential} (or \emph{across}) variable and \emph{flow} (or \emph{through}) variable -- are not sufficient to describe in a numerically sound way the bi-directional flow of matter @@ -99,9 +95,9 @@ \section{Stream Operator inStream and Connection Equations}\doublelabel{stream-o from the stream connection equations of the flow variables and of the stream variables. -For the following definition it is assumed that \lstinline!N! inside connectors -\texttt{m\textsubscript{j}.c} (j=1,2,...,N) and \lstinline!M! outside connectors -\texttt{c\textsubscript{k}} (k=1,2,...,M) belonging to the same connection set +For the following definition it is assumed that $N$ inside connectors +\lstinline[mathescape=true]!$m_{j}$.c! ($j = 1, 2, \ldots, N$) and $M$ outside connectors +\lstinline[mathescape=true]!$c{k}$! ($k = 1, 2, \ldots, M$) belonging to the same connection set (see definition in \autoref{inside-and-outside-connectors}) are connected together and a stream variable \lstinline!h_outflow! is associated with a flow variable \lstinline!m_flow! in connector \lstinline!c!. @@ -130,7 +126,7 @@ \section{Stream Operator inStream and Connection Equations}\doublelabel{stream-o end FluidSystem; \end{lstlisting} \begin{figure}[H] -\caption{Examplary FluidSystem with N=3 and M=2} +\caption{Examplary FluidSystem with $N$=3 and $M$=2} \begin{center} \includegraphics[width=2.3in,height=2.08125in]{fluidsystem} \end{center} @@ -143,8 +139,8 @@ \section{Stream Operator inStream and Connection Equations}\doublelabel{stream-o \end{nonnormative} With these prerequisites, the semantics of the expression -\texttt{inStream(m\textsubscript i.c.h\_outflow)} is given implicitly by -defining an additional variable \texttt{h\_mix\_in\textsubscript{i}}, and by +\lstinline[mathescape=true]!inStream($m_{i}$.c.h_outflow)! is given implicitly by +defining an additional variable $\mathit{h\_mix\_in}_{i}$, and by adding to the model the conservation equations for mass and energy corresponding to the infinitesimally small volume spanning the connection set. The connection equation for the flow variables has @@ -153,7 +149,7 @@ \section{Stream Operator inStream and Connection Equations}\doublelabel{stream-o \begin{lstlisting}[language=modelica,mathescape=true] // Standard connection equation for flow variables -0 = sum(m_j.c.m_flow for j in 1:N) + sum(-ck.m_flow for k in 1:M); +0 = sum($m_{j}$.c.m_flow for j in 1:N) + sum(-$c_{k}$.m_flow for k in 1:M); \end{lstlisting} Whenever the \lstinline!inStream()! operator is applied to a stream @@ -161,18 +157,21 @@ \section{Stream Operator inStream and Connection Equations}\doublelabel{stream-o property must be added under the assumption of flow going into the connector -\begin{lstlisting}[language=modelica] -// Implicit definition of the inStream() operator applied to inside connector i -0 = sum(mj.c.m_flow*(if mj.c.m_flow > 0 or j==i then h_mix_ini else mj.c.h_outflow) - for j in 1:N) + - sum(-ck.m_flow* (if -ck.m_flow > 0 then h_mix_ini else inStream(ck.h_outflow) - for k in 1:M); -inStream(mi.c.h_outflow) = h_mix_ini; +\begin{lstlisting}[language=modelica,mathescape=true] +// Implicit definition of the inStream() operator applied to inside connector $i$ +0 = + sum($m_{j}$.c.m_flow * + (if $m_{j}$.c.m_flow > 0 or $j$==$i$ then $\mathit{h\_mix\_in}_{i}$ else $m_{j}$.c.h_outflow) + for $j$ in 1:N) + + sum(-$c_{k}$.m_flow * + (if -$c_{k}$.m_flow > 0 then $\mathit{h\_mix\_in}_{i}$ else inStream($c_{k}$.h_outflow) + for $k$ in 1:M); +inStream($m_{i}$.c.h_outflow) = $\mathit{h\_mix\_in}_{i}$; \end{lstlisting} Note that the result of the -\texttt{inStream(m\textsubscript{i}.c.h\_outflow)} operator is different -for each port \lstinline!i!, because the assumption of flow entering the port is +\lstinline[mathescape=true]!inStream($m_{i}$.c.h_outflow)! operator is different +for each port $i$, because the assumption of flow entering the port is different for each of them. Additional equations need to be generated for the stream variables of @@ -181,38 +180,37 @@ \section{Stream Operator inStream and Connection Equations}\doublelabel{stream-o \begin{lstlisting}[language=modelica,mathescape=true] // Additional connection equations for outside connectors for q in 1:M loop - 0 = sum($m_j$.c.m_flow*(if - $m_j$.c.m_flow > 0 then - h_mix_out_q - else $m_j$.c.h_outflow) for j - in 1:N) + - sum(-$c_k$.m_flow* (if - -$c_k$.m_flow > 0 or k==q - then h_mix_out$_q$ - else inStream($c_k$.h_outflow) - for k in 1:M); - $c_q$.h_outflow = h_mix_out$_q$; - end for; + 0 = + sum($m_j$.c.m_flow * + (if $m_j$.c.m_flow > 0 then $\mathit{h\_mix\_out}_{q}$ else $m_j$.c.h_outflow) + for j in 1:N) + + sum(-$c_k$.m_flow * + (if -$c_k$.m_flow > 0 or k==q then $\mathit{h\_mix\_out}_{q}$ else inStream($c_k$.h_outflow)) + for k in 1:M); + $c_q$.h_outflow = $\mathit{h\_mix\_out}_{q}$; +end for; \end{lstlisting} Neglecting zero flow conditions, the solution of the above-defined -stream connection equations for inStream values of inside connectors and +stream connection equations for \lstinline!inStream! values of inside connectors and outflow stream variables of outside connectors is (for a derivation, see \autoref{derivation-of-stream-equations}): \begin{lstlisting}[language=modelica,mathescape=true] inStream($m_i$.c.h_outflow) := - (sum(max(-$m_j$.c.m_flow,0)*$m_j$.c.h_outflow for j in cat(1,1:i-1, i+1:N) + - sum(max( $c_k$.m_flow,0)*inStream($c_k$.h_outflow) for k in 1:M))/ - (sum(max(-$m_j$.c.m_flow,0) for j in cat(1,1:i-1, i+1:N) + + (sum(max(-$m_j$.c.m_flow,0)*$m_j$.c.h_outflow for j in cat(1, 1:i-1, i+1:N) + + sum(max( $c_k$.m_flow,0)*inStream($c_k$.h_outflow) for k in 1:M)) + / + (sum(max(-$m_j$.c.m_flow,0) for j in cat(1, 1:i-1, i+1:N) + sum(max( $c_k$.m_flow ,0) for k in 1:M)); // Additional equations to be generated for outside connectors q for q in 1:M loop $c_q$.h_outflow := (sum(max(-$m_j$.c.m_flow,0)*$m_j$.c.h_outflow for j in 1:N) + - sum(max( $c_k$.m_flow,0)*inStream($c_k$.h_outflow) for k in cat(1,1:q-1, q+1:M))/ - (sum(max(-$m_j$.c.m_flow,0) for j in 1:N) + - sum(max( $c_k$.m_flow ,0) for k in cat(1,1:q-1, q+1:M))); + sum(max( $c_k$.m_flow,0)*inStream($c_k$.h_outflow) for k in cat(1, 1:q-1, q+1:M)) + / + (sum(max(-$m_j$.c.m_flow,0) for j in 1:N) + + sum(max( $c_k$.m_flow ,0) for k in cat(1, 1:q-1, q+1:M))); end for; \end{lstlisting} @@ -251,10 +249,9 @@ \section{Stream Operator inStream and Connection Equations}\doublelabel{stream-o equation system identically (upto the usual numerical accuracy), provided the absolute value of every flow variable in the connection set is greater than a small value - (\texttt{\textbar{}m\textsubscript{1}.c.m\_flow\textbar{} \textgreater{} eps - \textbf{and} \textbar{}m\textsubscript{2}.c.m\_flow\textbar{} - \textgreater{} eps \textbf{and} ... \textbf{and} - \textbar{}c\textsubscript{M}.m\_flow\textbar{} \textgreater{} eps}). + ($\abs{m_{1}\text{\lstinline!.c.m_flow!}} > \text{\lstinline!eps!}$ + and $\abs{m_{2}\text{\lstinline!.c.m_flow!}} > \text{\lstinline!eps!}$ and \ldots and + $\abs{m_{M}\text{\lstinline!.c.m_flow!}} > \text{\lstinline!eps!}$). \end{enumerate} \begin{nonnormative} @@ -265,25 +262,25 @@ \section{Stream Operator inStream and Connection Equations}\doublelabel{stream-o \raggedright \item \textbf{N = 1, M = 0:}\newline \begin{lstlisting}[language=modelica,mathescape=true] -inStream($m_1$.c.h_outflow) =$m_1$.c.h_outflow; +inStream($m_1$.c.h_outflow) = $m_1$.c.h_outflow; \end{lstlisting} \item \textbf{N = 2, M = 0:}\newline \begin{lstlisting}[language=modelica,mathescape=true] -inStream($m_1$.c.h_outflow) =$m_2$.c.h_outflow; -inStream($m_2$.c.h_outflow) =$m_1$.c.h_outflow; +inStream($m_1$.c.h_outflow) = $m_2$.c.h_outflow; +inStream($m_2$.c.h_outflow) = $m_1$.c.h_outflow; \end{lstlisting} \item \textbf{N = 1, M = 1:}\newline \begin{lstlisting}[language=modelica,mathescape=true] -inStream($m_1$.c.h_outflow) =inStream($c_1$.h_outflow); +inStream($m_1$.c.h_outflow) = inStream($c_1$.h_outflow); // Additional equation to be generated $c_1$.h_outflow = $m_1$.c.h_outflow; \end{lstlisting} \item \textbf{N = 0, M = 2:}\newline \begin{lstlisting}[language=modelica,mathescape=true] // Additional equation to be generated -c1.h_outflow = inStream(c2.h_outflow); -c2.h_outflow = inStream(c1.h_outflow); +$c_{1}$.h_outflow = inStream($c_{2}$.h_outflow); +$c_{2}$.h_outflow = inStream($c_{1}$.h_outflow); \end{lstlisting} \item\textbf{All other cases:}\newline @@ -322,37 +319,38 @@ \section{Stream Operator inStream and Connection Equations}\doublelabel{stream-o \end{itemize} The operator -\texttt{positiveMax(-m\textsubscript{j}.c.m\_flow,s\textsubscript{i})} +\lstinline[mathescape=true]!positiveMax(-$m_{j}$.c.m_flow, $s_{i}$)! should be such that: \begin{itemize} \item - positiveMax(-m\textsubscript{j}.c.m\_flow,s\textsubscript{i}) = - -m\textsubscript{j}.c\_m\_flow if - -m\textsubscript{j}.c.m\_flow\textgreater{}eps1\textsubscript{j}\textgreater{}=0, - where eps1\textsubscript{j} are small flows, compared to typical - problem-specific value, + \lstinline[mathescape=true]!positiveMax(-$m_{j}$.c.m_flow, $s_{i}$)! = + \lstinline[mathescape=true]!-$m_{j}$.c.m_flow! if + $-m_{j}\text{\lstinline!.c.m_flow!} > \mathit{eps1}_{j} \geq 0$, + where $\mathit{eps1}_{j}$ are small flows, compared to typical + problem-specific values, \item - all denominators should be \textgreater{} eps2 \textgreater{} 0, - where eps2 is also a small flow, compared to typical problem-specific + all denominators should be $> \mathit{eps2} > 0$, + where $\mathit{eps2}$ is also a small flow, compared to typical problem-specific values. \end{itemize} -Trivial implementation of positiveMax guarantees continuity of \lstinline!inStream()!: +Trivial implementation of \lstinline!positiveMax! guarantees continuity of \lstinline!inStream()!: \begin{lstlisting}[language=modelica,mathescape=true] -postiveMax(-$m_j$.c.m_flow, $s_i$)= max(-m_j.c.m_flow, eps1); // so $s_i$ is not needed +postiveMax(-$m_j$.c.m_flow, $s_i$) = max(-$m_j$.c.m_flow, $\mathit{eps1}$); // so $s_i$ is not needed \end{lstlisting} More sophisticated implementation, with smooth approximation, applied only when {all} flows are small: \begin{lstlisting}[language=modelica,escapechar=!,mathescape=true] // Define a "small number" eps (!\textbf{nominal}!(v) is the nominal value of v !--! see !\autoref{attributes-start-fixed-nominal-and-unbounded}!) - eps := relativeTolerance*min(nominal($m_j$.c.m_flow)); +eps := relativeTolerance*min(nominal($m_j$.c.m_flow)); // Define a smooth curve, such that alpha($s_i>=eps$)=1 and alpha($s_i<0$)=0 - alpha := smooth(1, if $s_i$ > eps then 1 else - if $s_i$ > 0 then ( $s_i$/eps)^2*(3-2* $s_i$/eps)) else 0); +alpha := smooth(1, if $s_i$ > eps then 1 + else if $s_i$ > 0 then ($s_i$/eps)^2*(3-2* $s_i$/eps) + else 0); - // Define function positiveMax(v,s_i) as a linear combination of max (v,0) - // and of eps along alpha - positiveMax((-$m_j$.c.m_flow,s_i) := alpha*max(-$m_j$.c.m_flow,0) + (1-alpha)*eps; +// Define function positiveMax(v,s_i) as a linear combination of max (v,0) +// and of eps along alpha +positiveMax((-$m_j$.c.m_flow,s_i) := alpha*max(-$m_j$.c.m_flow,0) + (1-alpha)*eps; \end{lstlisting} The derivation of this implementation is discussed in @@ -366,44 +364,38 @@ \section{Stream Operator inStream and Connection Equations}\doublelabel{stream-o \begin{itemize} \item \lstinline!inStream(..)! is continuous (and differentiable), - provided that \texttt{m\textsubscript{j}.c.h\_outflow, - m\textsubscript{j}.c.m\_flow, - c\textsubscript{k}.h\_outflow}, and - \texttt{c\textsubscript{k}.m\_flow} are continuous and differentiable. + provided that \lstinline[mathescape=true]!$m_{j}$.c.h_outflow!, + \lstinline[mathescape=true]!$m_{j}$.c.m_flow!, \lstinline[mathescape=true]!$c_{k}$.h_outflow!, and + \lstinline[mathescape=true]!$c_{k}$.m_flow! are continuous and differentiable. \end{itemize} \begin{itemize} \item - A division by zero can no longer occur (since \texttt{sum(positiveMax(-m\textsubscript{j}.c.m\_flow,s\textsubscript{i}))\textgreater{}=eps2} - \textgreater{} 0), so the result is always well-defined. + A division by zero can no longer occur (since \lstinline[mathescape=true]!sum(positiveMax(-$m_{j}$.c.m_flow, $s_{i}$))! $\geq \mathit{eps2} > 0$), + so the result is always well-defined. \item - The balance equations are exactly fulfilled if the denominator - is not close to zero\\ - (since the exact formula is used, if - \texttt{sum(positiveMax(-m\textsubscript{j}.c.m\_flow,s\textsubscript{i})) \textgreater{} eps}). + The balance equations are exactly fulfilled if the denominator is not close to zero (since the exact formula is used, if + \lstinline[mathescape=true]!sum(positiveMax(-$m_{j}$.c.m_flow, $s_{i}$))! $> \mathit{eps}$). \item If all flows are zero, - \texttt{inStream(m\textsubscript{i}.c.h\_outflow) = - sum(m\textsubscript{j}.c.h\_outflow for - j\textless{}\textgreater{}i and m\textsubscript{j}.c.m\_flow.min \textless{} - 0)/Np}, i.e., it is the mean value of all the \lstinline!Np! variables - \texttt{m\textsubscript{j}.c.h\_outflow}, such that \texttt{ - j\textless{}\textgreater{}i} and - \texttt{m\textsubscript{j}.c.m\_flow.min \textless{} 0}. This is a + \lstinline[mathescape=true]!inStream($m_{i}$.c.h_outflow)! = + \lstinline[mathescape=true]!sum($m_{j}$.c.h_outflow for $j \neq i$ and $m_{j}$.c.m_flow.min < 0) / $N_{\mathrm{p}}$!, + i.e., it is the mean value of all the $N_{\mathrm{p}}$ variables + \lstinline[mathescape=true]!$m_{j}$.c.h_outflow!, such that $j \neq i$ and + $m_{j}\text{\lstinline!.c.m_flow.min!} < 0$. This is a meaningful approximation, considering the physical diffusion effects that are relevant at small flow rates in a small connection volume (thermal conduction for enthalpy, mass diffusion for mass fractions). \end{itemize} -The value of relativeTolerance should be larger than the relative +The value of \lstinline!relativeTolerance! should be larger than the relative tolerance of the nonlinear solver used to solve the implicit algebraic equations. As a final remark, further symbolic simplifications could be carried out by taking into account equations that affect the flows in -the connection set (i.e., equivalent to m\textsubscript{j}.c.m\_flow = -0, which then implies m\textsubscript{j}.c.m\_flow.min \textgreater{}= -0). This is interesting, e.g., in the case of a valve when the stem +the connection set (i.e., equivalent to $m_{j}\text{\lstinline!.c.m_flow!} = +0$, which then implies $m_{j}\text{\lstinline!.c.m_flow.min!} \geq 0$). This is interesting, e.g., in the case of a valve when the stem position is set identically to closed by its controller. \end{nonnormative} @@ -425,27 +417,27 @@ \section{Stream Operator actualStream}\doublelabel{stream-operator-actualstream} The \textbf{actualStream}(v) operator is typically used in two contexts: \begin{lstlisting}[language=modelica] - der(U) = c.m_flow*actualStream(c.h_outflow); // (1)energy balance equation - h_c = actualStream(c.h); // (2)monitoring the enthalpy at port c + der(U) = c.m_flow*actualStream(c.h_outflow); // (1) energy balance equation + h_c = actualStream(c.h); // (2) monitoring the enthalpy at port c \end{lstlisting} -In the case of equation (1), although the actualStream() operator +In the case of equation (1), although the \lstinline!actualStream()! operator is discontinuous, the product with the flow variable is not, because -actualStream() is discontinuous when the flow is zero by construction. -Therefore, a tool might infer that the expression is smooth(0, ...) +\lstinline!actualStream()! is discontinuous when the flow is zero by construction. +Therefore, a tool might infer that the expression is \lstinline!smooth(0, ...)! automatically, and decide whether or not to generate an event. If a user wants to avoid events entirely, he/she may enclose the right-hand side -of (1) with the noEvent() operator. +of (1) with the \lstinline!noEvent()! operator. Equations like (2) might be used for monitoring purposes (e.g. plots), in order to inspect what the actual enthalpy of the fluid flowing through a port is. In this case, the user will probably want to see the change due to flow reversal at the exact instant, so an event should be generated. If the user doesn't bother, then he/she should -enclose the right-hand side of (2) with noEvent(). Since the output of -actualStream() will be discontinuous, it should not be used by itself to +enclose the right-hand side of (2) with \lstinline!noEvent()!. Since the output of +\lstinline!actualStream()! will be discontinuous, it should not be used by itself to model physical behaviour (e.g., to compute densities used in momentum -balances) - inStream() should be used for this purpose. The operator -actualStream() should be used to model physical behaviour only when +balances) --- \lstinline!inStream()! should be used for this purpose. The operator +\lstinline!actualStream()! should be used to model physical behaviour only when multiplied by the corresponding flow variable (like in the above energy balance equation), because this removes the discontinuity. \end{nonnormative} diff --git a/preamble.tex b/preamble.tex index f853c493c..de72ad7ac 100644 --- a/preamble.tex +++ b/preamble.tex @@ -275,6 +275,7 @@ \fi% } \makeatother +\newcommand{\abs}[1]{\left\lvert #1{} \right\rvert} % Text mode additions \newcommand{\textgreatereq}{$\geq$} From 97e9d1bf952afadbfb677bdf80c85d9a63729d53 Mon Sep 17 00:00:00 2001 From: Henrik Tidefelt Date: Tue, 2 Jun 2020 22:08:28 +0200 Subject: [PATCH 05/78] Restore list of inequalities in 'Every solution of the implicit equation...' It was a mistake to think that the last entry in this list was a typo. In a subsequent commit, I'll suggest writing it in a way with less risk of misinterpretation. --- chapters/stream.tex | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/chapters/stream.tex b/chapters/stream.tex index 273560fa4..4eb3b0457 100644 --- a/chapters/stream.tex +++ b/chapters/stream.tex @@ -249,9 +249,9 @@ \section{Stream Operator inStream and Connection Equations}\doublelabel{stream-o equation system identically (upto the usual numerical accuracy), provided the absolute value of every flow variable in the connection set is greater than a small value - ($\abs{m_{1}\text{\lstinline!.c.m_flow!}} > \text{\lstinline!eps!}$ - and $\abs{m_{2}\text{\lstinline!.c.m_flow!}} > \text{\lstinline!eps!}$ and \ldots and - $\abs{m_{M}\text{\lstinline!.c.m_flow!}} > \text{\lstinline!eps!}$). + ($\abs{m_{1}\text{\lstinline!.c.m_flow!}} > \text{\lstinline!eps!}$ and + $\abs{m_{2}\text{\lstinline!.c.m_flow!}} > \text{\lstinline!eps!}$ and \ldots and + $\abs{c_{M}\text{\lstinline!.m_flow!}} > \text{\lstinline!eps!}$). \end{enumerate} \begin{nonnormative} From 470724d545b97a1768d09f0089f9506054cc1b26 Mon Sep 17 00:00:00 2001 From: Henrik Tidefelt Date: Tue, 2 Jun 2020 22:13:59 +0200 Subject: [PATCH 06/78] Rewrite sequence of inequalities in a more compact and less confusing way --- chapters/stream.tex | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/chapters/stream.tex b/chapters/stream.tex index 4eb3b0457..a2fc94c20 100644 --- a/chapters/stream.tex +++ b/chapters/stream.tex @@ -249,9 +249,8 @@ \section{Stream Operator inStream and Connection Equations}\doublelabel{stream-o equation system identically (upto the usual numerical accuracy), provided the absolute value of every flow variable in the connection set is greater than a small value - ($\abs{m_{1}\text{\lstinline!.c.m_flow!}} > \text{\lstinline!eps!}$ and - $\abs{m_{2}\text{\lstinline!.c.m_flow!}} > \text{\lstinline!eps!}$ and \ldots and - $\abs{c_{M}\text{\lstinline!.m_flow!}} > \text{\lstinline!eps!}$). + ($\abs{m_{i}\text{\lstinline!.c.m_flow!}} > \text{\lstinline!eps!}$ for $1 \leq i \leq N$ and + $\abs{c_{i}\text{\lstinline!.m_flow!}} > \text{\lstinline!eps!}$ for $1 \leq i \leq M$). \end{enumerate} \begin{nonnormative} From adb76ee49a9df1b46e510faa1a2ee28d1efb549c Mon Sep 17 00:00:00 2001 From: Henrik Tidefelt Date: Tue, 2 Jun 2020 22:16:22 +0200 Subject: [PATCH 07/78] Say 'greater than' instead of '>' at border of text and math --- chapters/stream.tex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/chapters/stream.tex b/chapters/stream.tex index a2fc94c20..85c843dcd 100644 --- a/chapters/stream.tex +++ b/chapters/stream.tex @@ -328,7 +328,7 @@ \section{Stream Operator inStream and Connection Equations}\doublelabel{stream-o where $\mathit{eps1}_{j}$ are small flows, compared to typical problem-specific values, \item - all denominators should be $> \mathit{eps2} > 0$, + all denominators should be greater than $\mathit{eps2} > 0$, where $\mathit{eps2}$ is also a small flow, compared to typical problem-specific values. \end{itemize} From 12e5f461d667add0dfc51ddfd569d5d9fa0b03b6 Mon Sep 17 00:00:00 2001 From: Henrik Tidefelt Date: Tue, 2 Jun 2020 22:28:17 +0200 Subject: [PATCH 08/78] Say just 'inStream' instead of 'the inStream operator' Similarly also for actualSteram. --- chapters/derivationofstream.tex | 20 +++++++------- chapters/stream.tex | 46 ++++++++++++++------------------- 2 files changed, 28 insertions(+), 38 deletions(-) diff --git a/chapters/derivationofstream.tex b/chapters/derivationofstream.tex index 8bffccdc7..5d62eb205 100644 --- a/chapters/derivationofstream.tex +++ b/chapters/derivationofstream.tex @@ -47,11 +47,10 @@ \section{Reasons for avoiding the actual mixing enthalpy in connector definition \end{center} \end{figure} -\section{Rationale for the formulation of the inStream() operator}\doublelabel{rationale-for-the-formulation-of-the-instream-operator} +\section{Rationale for the formulation of \lstinline!inStream!}\doublelabel{rationale-for-the-formulation-of-the-instream-operator} -For simplicity, the derivation of the inStream() operator is shown at -hand of 3 model components that are connected together. The case for N -connections follows correspondingly. +For simplicity, the derivation of \lstinline!inStream! is shown at hand of 3 model components that are connected together. +The case for $N$ connections follows correspondingly. The energy and mass balance equations for the connection set for 3 components are (see above): @@ -150,9 +149,9 @@ \section{Rationale for the formulation of the inStream() operator}\doublelabel{r inStream(h_{outflow,i})=\frac{\sum_{j=1,...,n;j\neq i}\text{max}(-\dot{m}_j,0)h_{outflow,j}}{\sum_{j=1,...,n;j\neq i}\text{max}(-\dot{m}_j,0)} \end{equation*} -\section{Special cases covered by the inStream() operator definition}\doublelabel{special-cases-covered-by-the-instream-operator-definition} -\subsection{Stream connector is not connected (N=1):}\doublelabel{stream-connector-is-not-connected-n-1} -For this case, the return value of the \lstinline!inStream()! operator is arbitrary. +\section{Special cases covered by \lstinline!inStream! definition}\doublelabel{special-cases-covered-by-the-instream-operator-definition} +\subsection{Stream connector is not connected ($N = 1$):}\doublelabel{stream-connector-is-not-connected-n-1} +For this case, the return value of \lstinline!inStream! is arbitrary. Therefore, it is set to the outflow value. \subsection{Connection of 2 stream connectors, one to one connections (N=2):}\doublelabel{connection-of-2-stream-connectors-one-to-one-connections-n-2} @@ -162,7 +161,7 @@ \subsection{Connection of 2 stream connectors, one to one connections (N=2):}\do inStream(h_{outflow,2})&=&\frac{\text{max}(-\dot{m}_1,0)h_{outflow,1}}{\text{max}(-\dot{m}_1,0)}=h_{outflow,1} \end{eqnarray*} -In this case, \lstinline!inStream()! is continuous (contrary to $h_{mix}$) and does not +In this case, \lstinline!inStream! is continuous (contrary to $h_{mix}$) and does not depend on flow rates. The latter result means that this transformation may remove nonlinear systems of equations, which requires that either simplifications of the form $a * b / a = b$ must be provided, or that this @@ -232,14 +231,13 @@ \subsection{Connection of 3 stream connectors where two mass flow rates are posi inStream(h_{outflow,1})=\frac{\text{max}(-\dot{m}_2,0)h_{outflow,2}+\text{max}(-\dot{m}_3,0)h_{outflow,3}}{\text{max}(-\dot{m}_2,0)+\text{max}(-\dot{m}_3,0)}=\frac{0}{0} \end{equation*} -The \lstinline!inStream()! operator cannot be evaluated for a connector, on which +\lstinline!inStream! cannot be evaluated for a connector, on which the mass flow rate has to be negative by definition. The reason is that the value is arbitrary, which is why it is defined as follows. \begin{equation*} inStream(h_{outflow,1}):=h_{outflow,1} \end{equation*} -For the remaining connectors the inStream() operator reduces to a simple -result. +For the remaining connectors, \lstinline!inStream! reduces to a simple result. \begin{eqnarray*} inStream(h_{outflow,2})&=\frac{\text{max}(-\dot{m}_1,0)h_{outflow,1}+\text{max}(-\dot{m}_3,0)h_{outflow,3}}{\text{max}(-\dot{m}_1,0)+\text{max}(-\dot{m}_3,0)}=h_{outflow,1}\\ inStream(h_{outflow,3})&=\frac{\text{max}(-\dot{m}_1,0)h_{outflow,1}+\text{max}(-\dot{m}_2,0)h_{outflow,2}}{\text{max}(-\dot{m}_1,0)+\text{max}(-\dot{m}_2,0)}=h_{outflow,1} diff --git a/chapters/stream.tex b/chapters/stream.tex index 85c843dcd..96527c415 100644 --- a/chapters/stream.tex +++ b/chapters/stream.tex @@ -51,10 +51,8 @@ \section{Definition of Stream Connectors}\doublelabel{definition-of-stream-conne For inside connectors (see \autoref{inside-and-outside-connectors}), variables with the \lstinline!stream! prefix do not lead to connection equations. \item - Connection equations with stream variables are generated in a model - when using the \lstinline!inStream()! operator or the - \lstinline!actualStream()! operator, see \autoref{stream-operator-instream-and-connection-equations} - and \autoref{stream-operator-actualstream}. + Connection equations with stream variables are generated in a model when using \lstinline!inStream! or \lstinline!actualStream!, + see \autoref{stream-operator-instream-and-connection-equations} and \autoref{stream-operator-actualstream}. \end{itemize} \begin{example} @@ -76,16 +74,15 @@ \section{Definition of Stream Connectors}\doublelabel{definition-of-stream-conne \lstinline!X_outflow! are the stream properties inside the component close to the boundary, when fluid flows out of the component into the connection point. The stream properties for the other flow direction can be -inquired with the built-in operator \lstinline!inStream()!. The value of +inquired with the built-in \lstinline!inStream!. The value of the stream variable corresponding to the actual flow direction can be -inquired through the built-in operator \lstinline!actualStream()!, see +inquired through the built-in \lstinline!actualStream!, see \autoref{stream-operator-actualstream}. \end{example} \section{Stream Operator inStream and Connection Equations}\doublelabel{stream-operator-instream-and-connection-equations} -In combination with the stream variables of a connector, the -\lstinline!inStream()! operator is designed to describe in a numerically +In combination with the stream variables of a connector, \lstinline!inStream! is designed to describe in a numerically reliable way the bi-directional transport of specific quantities carried by a flow of matter. @@ -152,13 +149,11 @@ \section{Stream Operator inStream and Connection Equations}\doublelabel{stream-o 0 = sum($m_{j}$.c.m_flow for j in 1:N) + sum(-$c_{k}$.m_flow for k in 1:M); \end{lstlisting} -Whenever the \lstinline!inStream()! operator is applied to a stream -variable of an inside connector, the balance equation of the transported -property must be added under the assumption of flow going into the -connector +Whenever \lstinline!inStream! is applied to a stream variable of an inside connector, the balance equation of the transported +property must be added under the assumption of flow going into the connector \begin{lstlisting}[language=modelica,mathescape=true] -// Implicit definition of the inStream() operator applied to inside connector $i$ +// Implicit definition of inStream applied to inside connector $i$ 0 = sum($m_{j}$.c.m_flow * (if $m_{j}$.c.m_flow > 0 or $j$==$i$ then $\mathit{h\_mix\_in}_{i}$ else $m_{j}$.c.h_outflow) @@ -220,8 +215,8 @@ \section{Stream Operator inStream and Connection Equations}\doublelabel{stream-o to compute it. \end{nonnormative} -If the argument of \lstinline!inStream()! is an array, the implicit -equation system holds elementwise, i.e., \lstinline!inStream()! is +If the argument of \lstinline!inStream! is an array, the implicit +equation system holds elementwise, i.e., \lstinline!inStream! is vectorizable. The stream connection equations have singularities and/or multiple @@ -233,11 +228,8 @@ \section{Stream Operator inStream and Connection Equations}\doublelabel{stream-o For example, assume that \lstinline[mathescape=true]!$m_{j}$.c.m_flow = $c_{k}$.m_flow = 0!, then all equations above are identically fulfilled and \lstinline!inStream(..)! can have any value. \end{nonnormative} -However, specific optimizations may be applied to avoid the regularization if the -flow through one port is zero or non-negative, see \autoref{derivation-of-stream-equations}. It is -required that the \lstinline!inStream()! operator is appropriately -approximated when regularization is needed and the approximation must -fulfill the following requirements: +However, specific optimizations may be applied to avoid the regularization if the flow through one port is zero or non-negative, see \autoref{derivation-of-stream-equations}. +It is required that \lstinline!inStream! is appropriately approximated when regularization is needed and the approximation must fulfill the following requirements: \begin{enumerate} \item \lstinline[mathescape=true]!inStream($m_{i}$.c.h_outflow)! and @@ -333,7 +325,7 @@ \section{Stream Operator inStream and Connection Equations}\doublelabel{stream-o values. \end{itemize} -Trivial implementation of \lstinline!positiveMax! guarantees continuity of \lstinline!inStream()!: +Trivial implementation of \lstinline!positiveMax! guarantees continuity of \lstinline!inStream!: \begin{lstlisting}[language=modelica,mathescape=true] postiveMax(-$m_j$.c.m_flow, $s_i$) = max(-$m_j$.c.m_flow, $\mathit{eps1}$); // so $s_i$ is not needed \end{lstlisting} @@ -355,7 +347,7 @@ \section{Stream Operator inStream and Connection Equations}\doublelabel{stream-o The derivation of this implementation is discussed in \autoref{derivation-of-stream-equations}. Note that in the cases N = 1, M =0 (unconnected port, physically corresponding to a plugged-up flange), and N = 2, M=0 -(one-to-one connection), the result of \lstinline!inStream()! is trivial +(one-to-one connection), the result of \lstinline!inStream! is trivial and no non-linear equations are left in the model, despite the fact that the original definition equations are nonlinear. @@ -419,9 +411,9 @@ \section{Stream Operator actualStream}\doublelabel{stream-operator-actualstream} der(U) = c.m_flow*actualStream(c.h_outflow); // (1) energy balance equation h_c = actualStream(c.h); // (2) monitoring the enthalpy at port c \end{lstlisting} -In the case of equation (1), although the \lstinline!actualStream()! operator +In the case of equation (1), although \lstinline!actualStream! is discontinuous, the product with the flow variable is not, because -\lstinline!actualStream()! is discontinuous when the flow is zero by construction. +\lstinline!actualStream! is discontinuous when the flow is zero by construction. Therefore, a tool might infer that the expression is \lstinline!smooth(0, ...)! automatically, and decide whether or not to generate an event. If a user wants to avoid events entirely, he/she may enclose the right-hand side @@ -433,10 +425,10 @@ \section{Stream Operator actualStream}\doublelabel{stream-operator-actualstream} see the change due to flow reversal at the exact instant, so an event should be generated. If the user doesn't bother, then he/she should enclose the right-hand side of (2) with \lstinline!noEvent()!. Since the output of -\lstinline!actualStream()! will be discontinuous, it should not be used by itself to +\lstinline!actualStream! will be discontinuous, it should not be used by itself to model physical behaviour (e.g., to compute densities used in momentum -balances) --- \lstinline!inStream()! should be used for this purpose. The operator -\lstinline!actualStream()! should be used to model physical behaviour only when +balances) --- \lstinline!inStream! should be used for this purpose. +\lstinline!actualStream! should be used to model physical behaviour only when multiplied by the corresponding flow variable (like in the above energy balance equation), because this removes the discontinuity. \end{nonnormative} From adb0972d4c02eae834ab5734ef0489d4b8f3344c Mon Sep 17 00:00:00 2001 From: Henrik Tidefelt Date: Tue, 2 Jun 2020 22:45:21 +0200 Subject: [PATCH 09/78] Cleanup some formatting of math in derivationofstream.tex --- chapters/derivationofstream.tex | 53 +++++++++++++++++---------------- 1 file changed, 28 insertions(+), 25 deletions(-) diff --git a/chapters/derivationofstream.tex b/chapters/derivationofstream.tex index 5d62eb205..766cbdc17 100644 --- a/chapters/derivationofstream.tex +++ b/chapters/derivationofstream.tex @@ -127,15 +127,15 @@ \section{Rationale for the formulation of \lstinline!inStream!}\doublelabel{rati it is therefore the mixing enthalpy under the assumption of fluid flowing into said model. -We establish this quantity using a dedicated operator $inStream(h_{outflow,i})=h_{mix}$ assuming that $\dot{m}_{i} >= 0$. This leads to +We establish this quantity using a dedicated operator $\text{\lstinline!inStream!}(h_{outflow,i})=h_{mix}$ assuming that $\dot{m}_{i} >= 0$. This leads to three different incarnations of (n in the general case). This is illustrated in the figure below. For the present example of three components in a connection set, this means the following. -\begin{eqnarray*} -inStream(h_{outflow,1})&=&\frac{\text{max}(-\dot{m}_2,0)h_{outflow,2}+\text{max}(-\dot{m}_3,0)h_{outflow,3}}{\text{max}(-\dot{m}_2,0)+\text{max}(-\dot{m}_3,0)}\\ -inStream(h_{outflow,2})&=&\frac{\text{max}(-\dot{m}_1,0)h_{outflow,1}+\text{max}(-\dot{m}_3,0)h_{outflow,3}}{\text{max}(-\dot{m}_1,0)+\text{max}(-\dot{m}_3,0)}\\ -inStream(h_{outflow,3})&=&\frac{\text{max}(-\dot{m}_1,0)h_{outflow,1}+\text{max}(-\dot{m}_2,0)h_{outflow,2}}{\text{max}(-\dot{m}_1,0)+\text{max}(-\dot{m}_2,0)} -\end{eqnarray*} +\begin{align*} +\text{\lstinline!inStream!}(h_{outflow,1}) &= \frac{\text{max}(-\dot{m}_2,0)h_{outflow,2}+\text{max}(-\dot{m}_3,0)h_{outflow,3}}{\text{max}(-\dot{m}_2,0)+\text{max}(-\dot{m}_3,0)}\\ +\text{\lstinline!inStream!}(h_{outflow,2}) &= \frac{\text{max}(-\dot{m}_1,0)h_{outflow,1}+\text{max}(-\dot{m}_3,0)h_{outflow,3}}{\text{max}(-\dot{m}_1,0)+\text{max}(-\dot{m}_3,0)}\\ +\text{\lstinline!inStream!}(h_{outflow,3}) &= \frac{\text{max}(-\dot{m}_1,0)h_{outflow,1}+\text{max}(-\dot{m}_2,0)h_{outflow,2}}{\text{max}(-\dot{m}_1,0)+\text{max}(-\dot{m}_2,0)} +\end{align*} \begin{figure}[H] \caption{Exemplary connection set with three connected components} \begin{center} @@ -146,7 +146,7 @@ \section{Rationale for the formulation of \lstinline!inStream!}\doublelabel{rati In the general case of a connection set with \emph{n} components, similar considerations lead to the following. \begin{equation*} -inStream(h_{outflow,i})=\frac{\sum_{j=1,...,n;j\neq i}\text{max}(-\dot{m}_j,0)h_{outflow,j}}{\sum_{j=1,...,n;j\neq i}\text{max}(-\dot{m}_j,0)} +\text{\lstinline!inStream!}(h_{outflow,i})=\frac{\sum_{j=1,...,n;j\neq i}\text{max}(-\dot{m}_j,0)h_{outflow,j}}{\sum_{j=1,...,n;j\neq i}\text{max}(-\dot{m}_j,0)} \end{equation*} \section{Special cases covered by \lstinline!inStream! definition}\doublelabel{special-cases-covered-by-the-instream-operator-definition} @@ -154,12 +154,12 @@ \subsection{Stream connector is not connected ($N = 1$):}\doublelabel{stream-con For this case, the return value of \lstinline!inStream! is arbitrary. Therefore, it is set to the outflow value. -\subsection{Connection of 2 stream connectors, one to one connections (N=2):}\doublelabel{connection-of-2-stream-connectors-one-to-one-connections-n-2} +\subsection{Connection of 2 stream connectors, one to one connections ($N = 2$):}\doublelabel{connection-of-2-stream-connectors-one-to-one-connections-n-2} -\begin{eqnarray*} -inStream(h_{outflow,1})&=&\frac{\text{max}(-\dot{m}_2,0)h_{outflow,2}}{\text{max}(-\dot{m}_2,0)}=h_{outflow,2}\\ -inStream(h_{outflow,2})&=&\frac{\text{max}(-\dot{m}_1,0)h_{outflow,1}}{\text{max}(-\dot{m}_1,0)}=h_{outflow,1} -\end{eqnarray*} +\begin{align*} +\text{\lstinline!inStream!}(h_{outflow,1}) &= \frac{\text{max}(-\dot{m}_2,0)h_{outflow,2}}{\text{max}(-\dot{m}_2,0)}=h_{outflow,2}\\ +\text{\lstinline!inStream!}(h_{outflow,2}) &= \frac{\text{max}(-\dot{m}_1,0)h_{outflow,1}}{\text{max}(-\dot{m}_1,0)}=h_{outflow,1} +\end{align*} In this case, \lstinline!inStream! is continuous (contrary to $h_{mix}$) and does not depend on flow rates. The latter result means that this transformation @@ -177,15 +177,16 @@ \subsection{Connection of 3 stream connectors where one mass flow rate is identi The suggested implementation results in the following equations, and as indicated the last formula can be simplified further by using $\dot{m}_3=0$: -\begin{eqnarray*} -inStream(h_{outflow,1})&=&h_{outflow,2}\\ -inStream(h_{outflow,2})&=&h_{outflow,1}\\ -inStream(h_{outflow,3})&=&\frac{\text{max}(-\dot{m}_1,0)h_{outflow,1}+\text{max}(-\dot{m}_2,0)h_{outflow,2}}{\text{max}(-\dot{m}_1,0)+\text{max}(-\dot{m}_2,0)}\\ -&=&\begin{cases} +\begin{align*} +\text{\lstinline!inStream!}(h_{outflow,1}) &= h_{outflow,2}\\ +\text{\lstinline!inStream!}(h_{outflow,2}) &= h_{outflow,1}\\ +\text{\lstinline!inStream!}(h_{outflow,3}) &= \frac{\text{max}(-\dot{m}_1,0)h_{outflow,1}+\text{max}(-\dot{m}_2,0)h_{outflow,2}}{\text{max}(-\dot{m}_1,0)+\text{max}(-\dot{m}_2,0)}\\ +&= +\begin{cases} h_{outflow,2}&\text{if $\dot{m}_1>=0$}\\ h_{outflow,1}&\text{if $\dot{m}_1<0$ and $\dot{m}_3=0$} \end{cases} -\end{eqnarray*} +\end{align*} \begin{figure}[H] \caption{Example series connection of multiple models with stream connectors } \begin{center} @@ -197,7 +198,7 @@ \subsection{Connection of 3 stream connectors where one mass flow rate is identi properties discussed for two connected components still hold. The connection set equations reflect that the sensor does not any influence by discarding the flow rate of the latter. In several cases a non-linear -equation system is removed by this transformation. However, \lstinline!inStream(..)! +equation system is removed by this transformation. However, \lstinline!inStream! results in a discontinuous equation for the sensor, which is consistent with modeling the convective phenomena only. The discontinuous equation is uncritical, if the sensor variable is not used in a feedback loop @@ -228,20 +229,22 @@ \subsection{Connection of 3 stream connectors where two mass flow rates are posi \end{lstlisting} results in the following equation: \begin{equation*} -inStream(h_{outflow,1})=\frac{\text{max}(-\dot{m}_2,0)h_{outflow,2}+\text{max}(-\dot{m}_3,0)h_{outflow,3}}{\text{max}(-\dot{m}_2,0)+\text{max}(-\dot{m}_3,0)}=\frac{0}{0} +\text{\lstinline!inStream!}(h_{outflow,1})=\frac{\text{max}(-\dot{m}_2,0)h_{outflow,2}+\text{max}(-\dot{m}_3,0)h_{outflow,3}}{\text{max}(-\dot{m}_2,0)+\text{max}(-\dot{m}_3,0)}=\frac{0}{0} \end{equation*} \lstinline!inStream! cannot be evaluated for a connector, on which the mass flow rate has to be negative by definition. The reason is that the value is arbitrary, which is why it is defined as follows. \begin{equation*} -inStream(h_{outflow,1}):=h_{outflow,1} +\text{\lstinline!inStream!}(h_{outflow,1}):=h_{outflow,1} \end{equation*} For the remaining connectors, \lstinline!inStream! reduces to a simple result. -\begin{eqnarray*} -inStream(h_{outflow,2})&=\frac{\text{max}(-\dot{m}_1,0)h_{outflow,1}+\text{max}(-\dot{m}_3,0)h_{outflow,3}}{\text{max}(-\dot{m}_1,0)+\text{max}(-\dot{m}_3,0)}=h_{outflow,1}\\ -inStream(h_{outflow,3})&=\frac{\text{max}(-\dot{m}_1,0)h_{outflow,1}+\text{max}(-\dot{m}_2,0)h_{outflow,2}}{\text{max}(-\dot{m}_1,0)+\text{max}(-\dot{m}_2,0)}=h_{outflow,1} -\end{eqnarray*} +\begin{align*} +\text{\lstinline!inStream!}(h_{outflow,2}) &= \frac{\text{max}(-\dot{m}_1,0)h_{outflow,1}+\text{max}(-\dot{m}_3,0)h_{outflow,3}}{\text{max}(-\dot{m}_1,0)+\text{max}(-\dot{m}_3,0)} + = h_{outflow,1}\\ +\text{\lstinline!inStream!}(h_{outflow,3}) &= \frac{\text{max}(-\dot{m}_1,0)h_{outflow,1}+\text{max}(-\dot{m}_2,0)h_{outflow,2}}{\text{max}(-\dot{m}_1,0)+\text{max}(-\dot{m}_2,0)} + = h_{outflow,1} +\end{align*} Again, the previous non-linear algebraic system of equations is removed. This means that utilizing the information about uni-directional flow is very important. From 2bcbe1695ffcb01c87db02b1b698f87283467cc1 Mon Sep 17 00:00:00 2001 From: Henrik Tidefelt Date: Tue, 2 Jun 2020 23:06:09 +0200 Subject: [PATCH 10/78] Use align* instead of eqnarray* This gives more consistent spacing around the aligned equality operator, compared with all the other equation* environments. --- chapters/classes.tex | 24 ++++++++++++------------ chapters/operatorsandexpressions.tex | 10 +++++----- 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/chapters/classes.tex b/chapters/classes.tex index d26725058..7b3484e6a 100644 --- a/chapters/classes.tex +++ b/chapters/classes.tex @@ -1142,11 +1142,11 @@ \section{Balanced Models}\doublelabel{balanced-models} %TODO-FORMAT Should this be verbatim code instead? Local equations: -\begin{eqnarray*} -0 &=& p.i + n.i;\\ -u &=& p.v - n.v;\\ -C \cdot \text{der}(u) &=& p.i; -\end{eqnarray*} +\begin{align*} +0 &= p.i + n.i;\\ +u &= p.v - n.v;\\ +C \cdot \text{der}(u) &= p.i; +\end{align*} and 2 equations corresponding to the 2 flow-variables \lstinline!p.i! and \lstinline!n.i!. These are 5 equations in 5 unknowns (\textbf{locally} @@ -1213,13 +1213,13 @@ \section{Balanced Models}\doublelabel{balanced-models} flow variables for \lstinline!t! (\lstinline!t.p.i!, \lstinline!t.n.i!), and 2 flow variables for \lstinline!c! (\lstinline!c.p.i!, \lstinline!c.n.i!). Local equations: -\begin{eqnarray*} \text{p.v} &=& \text{t.p.v};\\ -0 &=& \text{p.i}-\text{t.p.i};\\ -\text{c.p.v} &=& \text{t.n.v};\\ -0 &=& \text{c.p.i}+\text{t.n.i};\\ -\text{n.v} &=& \text{c.n.v};\\ -0 &=& \text{n.i}-\text{c.n.i}; -\end{eqnarray*} +\begin{align*} \text{p.v} &= \text{t.p.v};\\ +0 &= \text{p.i}-\text{t.p.i};\\ +\text{c.p.v} &= \text{t.n.v};\\ +0 &= \text{c.p.i}+\text{t.n.i};\\ +\text{n.v} &= \text{c.n.v};\\ +0 &= \text{n.i}-\text{c.n.i}; +\end{align*} and 2 equation corresponding to the flow variables \lstinline!p.i!, \lstinline!n.i!. In total we have 8 scalar unknowns and 8 scalar equations, i.e., a diff --git a/chapters/operatorsandexpressions.tex b/chapters/operatorsandexpressions.tex index 5c0d03677..a14723882 100644 --- a/chapters/operatorsandexpressions.tex +++ b/chapters/operatorsandexpressions.tex @@ -714,11 +714,11 @@ \subsubsection{spatialDistribution}\doublelabel{spatialdistribution} The \lstinline!spatialDistribution!() operator allows to approximate efficiently the solution of the infinite-dimensional problem -\begin{eqnarray*} -\frac{\partial z(y,t)}{\partial t}+v(t)\frac{\partial z(y,t)}{\partial y}&=&0.0\\ -z(0.0, t)=\mathrm{in}_0(t) \text{ if $v\ge 0$}\\ -z(1.0, t)=\mathrm{in}_1(t) \text{ if $v<0$} -\end{eqnarray*} +\begin{align*} +\frac{\partial z(y,t)}{\partial t}+v(t)\frac{\partial z(y,t)}{\partial y} &= 0.0\\ +z(0.0, t) &= \mathrm{in}_0(t) \text{ if $v\ge 0$}\\ +z(1.0, t) &= \mathrm{in}_1(t) \text{ if $v<0$} +\end{align*} where $z(y, t)$ is the transported quantity, $y$ is the normalized spatial coordinate ($0.0 \le y \le 1.0$), $t$ is the time, $v(t)=\mathrm{der}(x)$ is the normalized From e92375527c4ec766e0c5522b6408f40acbd7bc3e Mon Sep 17 00:00:00 2001 From: Henrik Tidefelt Date: Tue, 2 Jun 2020 23:10:21 +0200 Subject: [PATCH 11/78] More rephrasing of operator mentions Following the style recentry introduced in stream.tex. --- chapters/derivationofstream.tex | 2 +- chapters/equations.tex | 11 ++-- chapters/operatorsandexpressions.tex | 75 +++++++++++++--------------- chapters/revisions.tex | 2 +- 4 files changed, 41 insertions(+), 49 deletions(-) diff --git a/chapters/derivationofstream.tex b/chapters/derivationofstream.tex index 766cbdc17..906fc84cb 100644 --- a/chapters/derivationofstream.tex +++ b/chapters/derivationofstream.tex @@ -255,7 +255,7 @@ \subsection{Connection of 3 stream connectors where two mass flow rates are posi mathematical solution does not exist. This specification only requires that a solution fulfills the balance equations. Additionally, a recommendation is given to compute all unknowns in a unique way, by -providing an explicit formula for the \lstinline!inStream! operator. Due to the +providing an explicit formula for \lstinline!inStream!. Due to the definition, that only flows where the corresponding \lstinline!min! attribute is neither zero nor positive enter this formula, a meaningful physcial result is always obtained, even in case of zero mass flow rate. As a diff --git a/chapters/equations.tex b/chapters/equations.tex index 2def808d4..f144eed99 100644 --- a/chapters/equations.tex +++ b/chapters/equations.tex @@ -416,8 +416,7 @@ \subsubsection{Application of the Single-assignment Rule to When-Equations}\doub \subsection{reinit}\doublelabel{reinit} -The \lstinline!reinit! operator can only be used in the body of a when-equation. It -has the following syntax: +\lstinline!reinit! can only be used in the body of a when-equation. It has the following syntax: \begin{lstlisting}[language=modelica] reinit(x, expr); \end{lstlisting} @@ -444,12 +443,12 @@ \subsection{reinit}\doublelabel{reinit} 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! operator are +such a way that variables with an applied \lstinline!reinit! are selected as states at least when the corresponding when-clauses become -active. If this is not possible, an error occurs, since otherwise the -\lstinline!reinit! operator would be applied on a non-state variable. +active. If this is not possible, an error occurs, since otherwise +\lstinline!reinit! would be applied on a non-state variable. -Example for the usage of the \lstinline!reinit! operator (bouncing ball): +Example for the usage of \lstinline!reinit! (bouncing ball): \begin{lstlisting}[language=modelica] der(h) = v; der(v) = if flying then -g else 0; diff --git a/chapters/operatorsandexpressions.tex b/chapters/operatorsandexpressions.tex index a14723882..e17eeba22 100644 --- a/chapters/operatorsandexpressions.tex +++ b/chapters/operatorsandexpressions.tex @@ -375,7 +375,7 @@ \section{Built-in Intrinsic Operators with Function Syntax}\doublelabel{built-in Note that when the specification references a function having the name of a built-in function it references the built-in function, not a user-defined function having the same name, see also \autoref{built-in-functions}. With -exception of built-in operator \lstinline!String(..)!, all operators in this section +exception of the built-in \lstinline!String! operator, all operators in this section can only be called with positional arguments. \subsection{Numeric Functions and Conversion Functions}\doublelabel{numeric-functions-and-conversion-functions} @@ -637,17 +637,17 @@ \subsection{Derivative and Special Purpose Operators with Function Syntax}\doubl \hline % inStream -\lstinline!inStream(v)! & The operator \lstinline!inStream(v)! is only allowed on stream -variables v defined in stream connectors, and is the value of the stream -variable v close to the connection point assuming that the flow is from +\lstinline!inStream(v)! & \lstinline!inStream(v)! is only allowed for stream +variables \lstinline!v! defined in stream connectors, and is the value of the stream +variable \lstinline!v! close to the connection point assuming that the flow is from the connection point into the component. This value is computed from the stream connection equations of the flow variables and of the stream variables. The operator is vectorizable. For more details see \autoref{stream-operator-instream-and-connection-equations}.\\ \hline % actualStream -\lstinline!actualStream(v)! & The \lstinline!actualStream(v)! operator returns the actual value -of the stream variable v for any flow direction. The operator is +\lstinline!actualStream(v)! & \lstinline!actualStream(v)! returns the actual value +of the stream variable \lstinline!v! for any flow direction. The operator is vectorizable. For more details, see \autoref{stream-operator-actualstream}.\\ \hline @@ -659,8 +659,7 @@ \subsection{Derivative and Special Purpose Operators with Function Syntax}\doubl \lstinline! initialPoints=...,!\\ \lstinline! initialValues=...)! \end{tabular} & -The \lstinline!spatialDistribution(...)! operator allows approximation of -variable-speed transport of properties, see \autoref{spatialdistribution}.\\ +\lstinline!spatialDistribution! allows approximation of variable-speed transport of properties, see \autoref{spatialdistribution}.\\ \hline % getInstanceName @@ -675,7 +674,7 @@ \subsection{Derivative and Special Purpose Operators with Function Syntax}\doubl \subsubsection{delay}\doublelabel{delay} \begin{nonnormative} -The \lstinline!delay()! operator allows a numerical sound +\lstinline!delay! allows a numerical sound implementation by interpolating in the (internal) integrator polynomials, as well as a more simple realization by interpolating linearly in a buffer containing past values of expression expr. Without @@ -689,7 +688,7 @@ \subsubsection{delay}\doublelabel{delay} integrators are used, this information is sufficient to allocate the necessary storage for the internal buffer before the simulation starts. For variable step size integrators, the buffer size is dynamic during -integration. In principle, a \lstinline!delay! operator could break algebraic +integration. In principle, \lstinline!delay! could break algebraic loops. For simplicity, this is not supported because the minimum delay time has to be give as additional argument to be fixed at compile time. Furthermore, the maximum step size of the integrator is limited by this @@ -705,15 +704,13 @@ \subsubsection{spatialDistribution}\doublelabel{spatialdistribution} system is to approximate it by an ODE, but this requires a large number of state variables and might introduce either numerical diffusion or numerical oscillations. Another option is to use a built-in operator -that keeps track of the spatial distribution of z(x, t), by suitable +that keeps track of the spatial distribution of $z(x, t)$, by suitable sampling, interpolation, and shifting of the stored distribution. In this case, the internal state of the operator is hidden from the ODE solver. \end{nonnormative} -The \lstinline!spatialDistribution!() operator allows to approximate efficiently the -solution of the infinite-dimensional problem - +\lstinline!spatialDistribution! allows to approximate efficiently the solution of the infinite-dimensional problem \begin{align*} \frac{\partial z(y,t)}{\partial t}+v(t)\frac{\partial z(y,t)}{\partial y} &= 0.0\\ z(0.0, t) &= \mathrm{in}_0(t) \text{ if $v\ge 0$}\\ @@ -751,8 +748,7 @@ \subsubsection{spatialDistribution}\doublelabel{spatialdistribution} This allows to directly compute the solution based on interpolating the boundary conditions. -The \textbf{spatialDistribution} operator can be described in terms of -the pseudo-code given as a block: +\textbf{spatialDistribution} can be described in terms of the pseudo-code given as a block: \begin{lstlisting}[language=modelica] block spatialDistribution input Real in0; @@ -822,8 +818,8 @@ \subsubsection{spatialDistribution}\doublelabel{spatialdistribution} der(x) = v; (,out1) = spatialDistribution(in0, 0, x, true, initialPoints, initialValues); \end{lstlisting} -Technically relevant use cases for the use of the -\lstinline!spatialDistribution! operator are modeling of electrical +Technically relevant use cases for the use of +\lstinline!spatialDistribution! are modeling of electrical transmission lines, pipelines and pipeline networks for gas, water and district heating, sprinkler systems, impulse propagation in elongated bodies, conveyor belts, and hydraulic systems. Vectorization is needed @@ -834,8 +830,7 @@ \subsubsection{spatialDistribution}\doublelabel{spatialdistribution} \subsubsection{cardinality (deprecated)}\doublelabel{cardinality-deprecated} \begin{nonnormative} -The cardinality operator is deprecated for the following -reasons and will be removed in a future release: +\lstinline!cardinality! is deprecated for the following reasons and will be removed in a future release: \begin{itemize} \item Reflective operator may make early type checking more difficult. @@ -847,8 +842,7 @@ \subsubsection{cardinality (deprecated)}\doublelabel{cardinality-deprecated} \end{nonnormative} \begin{nonnormative} -The \lstinline!cardinality()! operator allows the definition of -connection dependent equations in a model, for example: +\lstinline!cardinality! allows the definition of connection dependent equations in a model, for example: \begin{lstlisting}[language=modelica] connector Pin Real v; @@ -867,7 +861,7 @@ \subsubsection{cardinality (deprecated)}\doublelabel{cardinality-deprecated} The cardinality is counted after removing conditional components. and may not be applied to expandable connectors, elements in expandable connectors, or to arrays of connectors (but can be applied to the scalar -elements of array of connectors). The cardinality operator should only +elements of array of connectors). \lstinline!cardinality! should only be used in the condition of assert and if-statements -- that do not contain connect (and similar operators -- see \autoref{clocked-discrete-time-and-clocked-discretized-continuous-time-partition}). @@ -900,12 +894,12 @@ \subsubsection{homotopy}\doublelabel{homotopy} respective non-linear algebraic equation systems. The reason is that the following structure can be present: \begin{lstlisting}[language=modelica, mathescape=true] -w= $f_1$(x) // has homotopy operator +w = $f_1$(x) // has homotopy 0 = $f_2$(der(x), x, z, w) \end{lstlisting} Here, a non-linear equation system $f_2$ -is present. The homotopy operator is, however used on a variable +is present. \lstinline!homotopy! is, however used on a variable that is an ``input'' to the non-linear algebraic equation system, and modifies the characteristics of the non-linear algebraic equation system. The only useful way is to perform the homotopy iteration over @@ -913,11 +907,11 @@ \subsubsection{homotopy}\doublelabel{homotopy} The suggested approach is ``conceptual'', because more efficient implementations are possible, e.g. by determining the smallest iteration -loop, that contains the equations of the first BLT block in which a -homotopy operator is present and all equations up to the last BLT block +loop, that contains the equations of the first BLT block in which +\lstinline!homotopy! is present and all equations up to the last BLT block that describes a non-linear algebraic equation system. -A trivial implementation of the homotopy operator is obtained by +A trivial implementation of \lstinline!homotopy! is obtained by defining the following function in the global scope: \begin{lstlisting}[language=modelica] function homotopy @@ -933,8 +927,8 @@ \subsubsection{homotopy}\doublelabel{homotopy} \textbf{Example 1.} In electrical systems it is often difficult to solve non-linear algebraic equations if switches are part of the algebraic loop. An idealized diode model might be implemented in the following way, by -starting with a ``flat'' diode characteristic and then move with the -homotopy operator to the desired ``steep'' characteristic: +starting with a ``flat'' diode characteristic and then move with +\lstinline!homotopy! to the desired ``steep'' characteristic: \begin{lstlisting}[language=modelica] model IdealDiode ... @@ -986,7 +980,7 @@ \subsubsection{homotopy}\doublelabel{homotopy} end PressureLoss; \end{lstlisting} -\textbf{Example 4.} Note that the homotopy operator \textbf{shall not} be used to +\textbf{Example 4.} Note that \lstinline!homotopy! \textbf{shall not} be used to combine unrelated expressions, since this can generate singular systems from combining two well-defined systems. \begin{lstlisting}[language=modelica] @@ -1161,7 +1155,7 @@ \subsection{Event-Related Operators with Function Syntax}\doublelabel{event-rela \lstinline!pre(y)! & Returns the \emph{left limit} $y(t\textsuperscript{pre})$ of variable $y(t)$ at a time instant $t$. At an event instant, $y(t\textsuperscript{pre})$ is the value of y after the last event -iteration at time instant $t$ (see comment below). The \lstinline!pre()! operator can +iteration at time instant $t$ (see comment below). \lstinline!pre! can be applied if the following three conditions are fulfilled simultaneously: (a) variable $y$ is either a subtype of a simple type or is a record component, (b) $y$ is a discrete-time expression (c) the @@ -1174,12 +1168,11 @@ \subsection{Event-Related Operators with Function Syntax}\doublelabel{event-rela % edge \lstinline!edge(b)! & Is expanded into \lstinline!(b and not pre(b))! for Boolean variable -\lstinline!b!. The same restrictions as for the \lstinline!pre()! operator apply (e.g. not to be +\lstinline!b!. The same restrictions as for \lstinline!pre! apply (e.g. not to be used in function classes).\\ \hline % change -\lstinline!change(v)! & Is expanded into \lstinline!(v<>pre(v))!. The -same restrictions as for the \lstinline!pre()! operator apply.\\ \hline +\lstinline!change(v)! & Is expanded into \lstinline!(v<>pre(v))!. The same restrictions as for \lstinline!pre! apply.\\ \hline % reinit \lstinline!reinit(x, expr)! & In the body of a when clause, reinitializes \lstinline!x! with @@ -1187,11 +1180,11 @@ \subsection{Event-Related Operators with Function Syntax}\doublelabel{event-rela \begin{nonnormative} It is an error if the variable cannot be selected as a state. \end{nonnormative} -\lstinline!expr! needs to be type-compatible with \lstinline!x!. The -reinit operator can only be applied once for the same variable - either +\lstinline!expr! needs to be type-compatible with \lstinline!x!. +\lstinline!reinit! can only be applied once for the same variable --- either as an individual variable or as part of an array of variables. It can only be applied in the body of a when clause in an equation section. See -also \autoref{reinit} .\\ \hline +also \autoref{reinit}.\\ \hline \end{longtable} @@ -1224,9 +1217,9 @@ \subsubsection{pre}\doublelabel{pre} \subsubsection{noEvent and smooth}\doublelabel{noevent-and-smooth} -The \lstinline!noEvent! operator implies that real elementary relations/functions +\lstinline!noEvent! implies that real elementary relations/functions are taken literally instead of generating crossing functions, \autoref{events-and-synchronization}. -The \lstinline!smooth! operator should be used instead of \lstinline!noEvent!, in order to +\lstinline!smooth! should be used instead of \lstinline!noEvent!, in order to avoid events for efficiency reasons. A tool is free to not generate events for expressions inside \lstinline!smooth!. However, \lstinline!smooth! does not guarantee that no events will be generated, and thus it can be necessary to use @@ -1383,7 +1376,7 @@ \subsection{Discrete-Time Expressions}\doublelabel{discrete-time-expressions} test. \begin{nonnormative} -This restriction guarantees that the \lstinline!noEvent()! operator cannot be applied to \lstinline!Boolean!, \lstinline!Integer!, \lstinline!String!, or \lstinline!enumeration! +This restriction guarantees that \lstinline!noEvent! cannot be applied to \lstinline!Boolean!, \lstinline!Integer!, \lstinline!String!, or \lstinline!enumeration! equations outside of a \lstinline!when!-clause, because then one of the two expressions is not discrete-time. \end{nonnormative} diff --git a/chapters/revisions.tex b/chapters/revisions.tex index 6de47da79..9f51453b0 100644 --- a/chapters/revisions.tex +++ b/chapters/revisions.tex @@ -1278,7 +1278,7 @@ \subsection{Contributors to the Modelica Language, Version 3.2}\doublelabel{cont The global name lookup was proposed by Stefan Vorkoetter. The support for Unicode was initiated by Rui Gao and Hoyoun Kim.\\ -The \lstinline!homotopy! operator was proposed by Martin Otter, Michael Sielemann +\lstinline!homotopy! was proposed by Martin Otter, Michael Sielemann and Francesco Casella. Michael Sielemann demonstrated with benchmark problems that non-linear solvers are not able to solve reliably initialization problems and that the homotopy operator is therefore From 5d9fa9d133ebb3de12e02220b212c1b96f5d1c1f Mon Sep 17 00:00:00 2001 From: Henrik Tidefelt Date: Tue, 2 Jun 2020 23:19:58 +0200 Subject: [PATCH 12/78] Don't use \textbf directly for glossary items --- chapters/glossary.tex | 124 +++++++++++++++++++++--------------------- preamble.tex | 2 + 2 files changed, 64 insertions(+), 62 deletions(-) diff --git a/chapters/glossary.tex b/chapters/glossary.tex index 7021bcb54..e42d0e127 100644 --- a/chapters/glossary.tex +++ b/chapters/glossary.tex @@ -1,5 +1,5 @@ \chapter{Glossary}\doublelabel{glossary} -\textbf{algorithm section}: part of a class definition consisting of the +\glossaryitem{algorithm section}: part of a class definition consisting of the keyword \lstinline!algorithm! followed by a sequence of statements. Like an equation, an algorithm section relates variables, i.e. constrains the values that these variables can take simultaneously. In contrast to an @@ -10,7 +10,7 @@ \chapter{Glossary}\doublelabel{glossary} outputs, e.g. by search (generate and test), or by deriving an inverse algorithm symbolically. (See \autoref{statements-and-algorithm-sections}.) -\textbf{array} or array variable: a component whose components are array +\glossaryitem{array} or array variable: a component whose components are array elements. For an array, the ordering of its components matters: The kth element in the sequence of components of an array x is the array element with index \lstinline!k!, denoted \lstinline!x[k]!. All elements of an array have the same @@ -19,19 +19,19 @@ \chapter{Glossary}\doublelabel{glossary} is the number of dimensions of the array. Special cases are matrix (n=2) and vector (n=1). Integer indices start with 1, not zero. (See \autoref{arrays}.) -\textbf{array constructor}: an array can be built using the +\glossaryitem{array constructor}: an array can be built using the array-function -- with the shorthand \{a, b, \ldots{}\}, and can also include an iterator to build an array of expressions. (See \autoref{vector-matrix-and-array-constructors}.) -\textbf{array element}: a component contained in an array. An array +\glossaryitem{array element}: a component contained in an array. An array element has no identifier. Instead they are referenced by array access expressions called indices that use enumeration values or positive integer index values. (See \autoref{arrays}.) -\textbf{assignment}: a statement of the form \lstinline!x := expr!. The expression +\glossaryitem{assignment}: a statement of the form \lstinline!x := expr!. The expression \lstinline!expr! must not have higher variability than~x. (See \autoref{simple-assignment-statements}.) -\textbf{attribute}: a component contained in a scalar component, such as +\glossaryitem{attribute}: a component contained in a scalar component, such as \lstinline!min!, \lstinline!max!, and \lstinline!unit!. All attributes are predefined and attribute values can only be defined using a modification, such as in \lstinline!Real x(unit="kg")!. Attributes cannot be accessed using dot notation, and are not @@ -40,35 +40,35 @@ \chapter{Glossary}\doublelabel{glossary} but not their unit attributes, nor any other attribute of \lstinline!x! and \lstinline!y!. (See \autoref{predefined-types-and-classes}.) -\textbf{base class}: class A is called a base class of B, if class B +\glossaryitem{base class}: class A is called a base class of B, if class B extends class A. This relation is specified by an extends clause in B or in one of B's base classes. A class inherits all elements from its base classes, and may modify all non-final elements inherited from base classes. (See \autoref{inheritance-extends-clause}.) -\textbf{binding equation}: Either a declaration equation or an element +\glossaryitem{binding equation}: Either a declaration equation or an element modification for the value of the variable. In a non-function a component with a binding equation has its value bound to some expression. (See \autoref{equation-categories}.) In a function an input component uses the value of the binding equation as default value, a non-input component starts with that value. (See \autoref{initialization-and-binding-equations-of-components-in-functions}.) -\textbf{class}: a description that generates an object called instance. +\glossaryitem{class}: a description that generates an object called instance. The description consists of a class definition, a modification environment that modifies the class definition, an optional list of dimension expressions if the class is an array class, and a lexically enclosing class for all classes. (See \autoref{class-declarations}.) -\textbf{class type} or \textbf{inheritance interface}: property of a +\glossaryitem{class type} or \glossaryitem{inheritance interface}: property of a class, consisting of a number of attributes and a set of public or protected elements consisting of element name, element type, and element attributes. (See \autoref{inheritance-interface-or-class-type}.) -\textbf{component} or \textbf{variable}: an instance (object) generated +\glossaryitem{component} or \glossaryitem{variable}: an instance (object) generated by a component declaration. Special kinds of components are scalar, array, and attribute. (See \autoref{component-declarations}.) -\textbf{component declaration}: an element of a class definition that +\glossaryitem{component declaration}: an element of a class definition that generates a component. A component declaration specifies (1) a component name, i.e., an identifier, (2) the class to be flattened in order to generate the component, and (3) an optional Boolean parameter @@ -76,7 +76,7 @@ \chapter{Glossary}\doublelabel{glossary} expression evaluates to false. A component declaration may be overridden by an element-redeclaration. (See \autoref{component-declarations}.) -\textbf{component reference}: An expression containing a sequence of +\glossaryitem{component reference}: An expression containing a sequence of identifiers and indices. A component reference is equivalent to the referenced object, which must be a component. A component reference is resolved (evaluated) in the scope of a class (or expression for the case @@ -84,35 +84,35 @@ \chapter{Glossary}\doublelabel{glossary} components and classes. Example reference: \lstinline!Ele.Resistor.u[21].r! (See \autoref{component-declarations} and \autoref{slice-operation}.) -\textbf{declaration assignment}: Deprecated name for binding equation in function. +\glossaryitem{declaration assignment}: Deprecated name for binding equation in function. -\textbf{declaration equation}: Equation of the form \lstinline!x = expression! +\glossaryitem{declaration equation}: Equation of the form \lstinline!x = expression! defined by a component declaration. The expression must not have higher variability than the declared component x. Unlike other equations, a declaration equation can be overridden (replaced or removed) by an element modification. (See \autoref{declaration-equations}.) -\textbf{derived class} or \textbf{subclass} or \textbf{extended class}: +\glossaryitem{derived class} or \glossaryitem{subclass} or \glossaryitem{extended class}: class B is called derived from A, if B extends A. (See \autoref{inheritance-modification-and-redeclaration}.) -\textbf{element}: part of a class definition, one of: class definition, +\glossaryitem{element}: part of a class definition, one of: class definition, component declaration, or extends clause. Component declarations and class definitions are called named elements. An element is either inherited from a base class or local. -\textbf{element modification}: part of a modification, overrides the +\glossaryitem{element modification}: part of a modification, overrides the declaration equation in the class used by the instance generated by the modified element. Example: \lstinline!vcc(unit="V")=1000!. (See \autoref{modifications}.) -\textbf{element-redeclaration}: part of a modification, replaces one of +\glossaryitem{element-redeclaration}: part of a modification, replaces one of the named elements possibly used to build the instance geneated by the element that contains the redeclaration. Example: \lstinline!redeclare type Voltage = Real(unit="V")! replaces \lstinline!type Voltage!. (See \autoref{redeclaration}.) -\textbf{encapsulated}: a class that does not depend on where it is +\glossaryitem{encapsulated}: a class that does not depend on where it is placed in the package-hierarchy, since its lookup is stopped at the encapsulated boundary. (See \autoref{simple-name-lookup}). -\textbf{equation}: part of a class definition. A scalar equation relates +\glossaryitem{equation}: part of a class definition. A scalar equation relates scalar variables, i.e. constrains the values that these variables can take simultaneously. When n-1 variables of an equation containing n variables are known, the value of the nth variable can be inferred @@ -121,157 +121,157 @@ \chapter{Glossary}\doublelabel{glossary} Special cases are: initial equations, instantaneous equations, declaration equations. (See \autoref{equations}.) -\textbf{event}: something that occurs instantaneously at a specific time +\glossaryitem{event}: something that occurs instantaneously at a specific time or when a specific condition occurs. Events are for example defined by the condition occurring in a when clause, if clause, or if expression. (See \autoref{events-and-synchronization}.) -\textbf{expression}: a term built from operators, function references, +\glossaryitem{expression}: a term built from operators, function references, components, or component references (referring to components) and literals. Each expression has a type and a variability. (See \autoref{operators-and-expressions}.) -\textbf{extends clause}: an unnamed element of a class definition that +\glossaryitem{extends clause}: an unnamed element of a class definition that uses a name and an optional modification to specify a base class of the class defined using the class definition. (See \autoref{inheritance-modification-and-redeclaration}.) -\textbf{flattening}: the computation that creates a flattened class of a +\glossaryitem{flattening}: the computation that creates a flattened class of a given class, where all inheritance, modification, etc. has been performed and all names resolved, consisting of a flat set of equations, algorithm sections, component declarations, and functions. (See \autoref{flattening-process}.) -\textbf{function}: a class of the specialized class function. (See \autoref{functions}.) +\glossaryitem{function}: a class of the specialized class function. (See \autoref{functions}.) -\textbf{function subtype} or \textbf{function compatible interface}: A +\glossaryitem{function subtype} or \glossaryitem{function compatible interface}: A is a function subtype of B iff A is a subtype of B and the additional arguments of function A that are not in function B are defined in such a way (e.g. additional arguments need to have default values), that A can be called at places where B is called. (See \autoref{function-compatibility-or-function-subtyping-for-functions}.) -\textbf{identifier} or ident: an atomic (not composed) name. Example: +\glossaryitem{identifier} or ident: an atomic (not composed) name. Example: \lstinline!Resistor! (See \autoref{identifiers-names-and-keywords}.) -\textbf{index} or \textbf{subscript}: An expression, typically of +\glossaryitem{index} or \glossaryitem{subscript}: An expression, typically of Integer type or the colon symbol (:), used to reference a component (or a range of components) of an array. (See \autoref{array-indexing}.) -\textbf{inheritance interface} or \textbf{class type}: property of a +\glossaryitem{inheritance interface} or \glossaryitem{class type}: property of a class, consisting of a number of attributes and a set of public or protected elements consisting of element name, element type, and element attributes. (See \autoref{inheritance-interface-or-class-type}.) -\textbf{instance}: the object generated by a class. An instance contains +\glossaryitem{instance}: the object generated by a class. An instance contains zero or more components (i.e. instances), equations, algorithms, and local classes. An instance has a type. Basically, two instances have same type, if their important attributes are the same and their public components and classes have pair wise equal identifiers and types. More specific type equivalence definitions are given e.g. for functions. -\textbf{instantaneous}: An equation or statement is instantaneous if it +\glossaryitem{instantaneous}: An equation or statement is instantaneous if it holds only at events, i.e., at single points in time. The equations and statements of a when-clause are instantaneous. (See \autoref{when-equations} and \autoref{when-statements}.) -\textbf{interface}: see type. (See \autoref{interface-or-type}.) +\glossaryitem{interface}: see type. (See \autoref{interface-or-type}.) -\textbf{literal}: a real, integer, boolean, enumeration, or string +\glossaryitem{literal}: a real, integer, boolean, enumeration, or string literal. Used to build expressions. (See \autoref{literal-constants}.) -\textbf{matrix}: an array where the number of dimensions is 2. (See +\glossaryitem{matrix}: an array where the number of dimensions is 2. (See \autoref{arrays}.) -\textbf{modification}: part of an element. Modifies the instance +\glossaryitem{modification}: part of an element. Modifies the instance generated by that element. A modification contains element modifications and element redeclarations. (See \autoref{modifications}.) -\textbf{modification environment}: the modification environment of a +\glossaryitem{modification environment}: the modification environment of a class defines how to modify the corresponding class definition when flattening the class. (See \autoref{modification-environment}.) -\textbf{name}: Sequence of one or more identifiers. Used to reference a +\glossaryitem{name}: Sequence of one or more identifiers. Used to reference a class. A class name is resolved in the scope of a class, which defines a set of visible classes. Example name: \lstinline!Ele.Resistor!. (See \autoref{names}.) -\textbf{operator record}: A record with user-defined operations; +\glossaryitem{operator record}: A record with user-defined operations; defining e.g. multiplication and addition see \autoref{overloaded-operators}. -\textbf{partial}: a class that is incomplete and cannot be instantiated +\glossaryitem{partial}: a class that is incomplete and cannot be instantiated in a simulation model; useful e.g. as a base-class. (See \autoref{component-declaration-static-semantics}.) -\textbf{partial flattening}: first find the names of declared local +\glossaryitem{partial flattening}: first find the names of declared local classes and components. Modifiers, if present, are merged to the local elements and redeclarations are performed. Then base-classes are looked up, flattened and inserted into the class. See also flattening, which additionally flattens local elements and performs modifications. (See \autoref{flattening-process}.) -\textbf{plug-compatibility}: see restricted subtyping and \autoref{plug-compatibility-or-restricted-subtyping}. +\glossaryitem{plug-compatibility}: see restricted subtyping and \autoref{plug-compatibility-or-restricted-subtyping}. -\textbf{predefined type}: one of the types \lstinline!Real!, \lstinline!Boolean!, \lstinline!Integer!, +\glossaryitem{predefined type}: one of the types \lstinline!Real!, \lstinline!Boolean!, \lstinline!Integer!, \lstinline!String! and types defined as \lstinline!enumeration! types. The component declarations of the predefined types define attributes such as \lstinline!min!, \lstinline!max!, and \lstinline!unit!. (See \autoref{predefined-types-and-classes}.) -\textbf{prefix}: property of an element of a class definition which can +\glossaryitem{prefix}: property of an element of a class definition which can be present or not be present, e.g. \lstinline!final!, \lstinline!public!, \lstinline!flow!. (See \autoref{prefix-rules}.) -\textbf{primitive type}: one of the built-in types \lstinline!RealType!, +\glossaryitem{primitive type}: one of the built-in types \lstinline!RealType!, \lstinline!BooleanType!, \lstinline!IntegerType!, \lstinline!StringType!, \lstinline!EnumType!. The primitive types are used to define attributes and value of predefined types and enumeration types. (See \autoref{predefined-types-and-classes}.) -\textbf{redeclare}: the modifier that changes a replaceable element. +\glossaryitem{redeclare}: the modifier that changes a replaceable element. (See \autoref{redeclaration}) -\textbf{replaceable}: an element that can be replaced by a different +\glossaryitem{replaceable}: an element that can be replaced by a different element having a compatible interface. (See \autoref{redeclaration}) -\textbf{restricted subtyping} or \textbf{plug-compatibility}: a type A +\glossaryitem{restricted subtyping} or \glossaryitem{plug-compatibility}: a type A is a restricted subtype of type B iff A is a subtype of B, and all public components present in A but not in B must be default-connectable. This is used to avoid introducing, via a redeclaration, an un-connected connector in the object/class of type A at a level where a connection is not possible. (See \autoref{plug-compatibility-or-restricted-subtyping}.) -\textbf{scalar} or scalar variable: a variable that is not an array. +\glossaryitem{scalar} or scalar variable: a variable that is not an array. -\textbf{simple type:} Real, Boolean, Integer, String and enumeration +\glossaryitem{simple type:} Real, Boolean, Integer, String and enumeration types -\textbf{specialized class}: one of: model, connector, package, record, +\glossaryitem{specialized class}: one of: model, connector, package, record, block, function, type. The class restriction of a class represents an assertion regarding the content of the class and restricts its use in other classes. For example, a class having the package class restriction must only contain classes and constants. (See \autoref{specialized-classes}.) -\textbf{subtype} or \textbf{interface compatible}: relation between +\glossaryitem{subtype} or \glossaryitem{interface compatible}: relation between types. A is a subtype of (interface compatible with) B iff a number of properties of A and B are the same and all important elements of B have corresponding elements in A with the same names and their types being subtypes of the corresponding element types in B. See also restricted subtyping and function restricted subtyping. (See \autoref{interface-compatibility-or-subtyping}.) -\textbf{supertype}: relation between types. The inverse of subtype. A is +\glossaryitem{supertype}: relation between types. The inverse of subtype. A is a subtype of B means that B is a supertype of A. (See \autoref{interface-compatibility-or-subtyping}.) -\textbf{transitively nonreplaceable}: a class reference is considered +\glossaryitem{transitively nonreplaceable}: a class reference is considered transitively non-replaceable if there are no replaceable elements in the referenced class, or any of its base classes or constraining types transitively at any level. (See \autoref{transitively-non-replaceable}.) -\textbf{type} or interface: property of an instance, expression, consisting of a number of attributes and a set of public +\glossaryitem{type} or interface: property of an instance, expression, consisting of a number of attributes and a set of public elements consisting of element name, element type, and element attributes. Note: The concept of class type is a property of a class definition. (See \autoref{interface-or-type}.) -\textbf{variability}: property of an expression: one of +\glossaryitem{variability}: property of an expression: one of \begin{itemize} -\item \textbf{continuous}: an expression that may change its value at any +\item \glossaryitem{continuous}: an expression that may change its value at any point in time. -\item \textbf{discrete}: may change its value only at events during +\item \glossaryitem{discrete}: may change its value only at events during simulation. -\item \textbf{parameter}: constant during the entire simulation, recommended +\item \glossaryitem{parameter}: constant during the entire simulation, recommended to change for a component. -\item \textbf{constant}: constant during the entire simulation (can be used +\item \glossaryitem{constant}: constant during the entire simulation (can be used in a package) . \end{itemize} @@ -279,7 +279,7 @@ \chapter{Glossary}\doublelabel{glossary} variability constraint: The expression must not have a higher variability than component x. (See \autoref{variability-of-expressions}.) -\textbf{variable}: synonym for component. (See \autoref{component-declarations}.) +\glossaryitem{variable}: synonym for component. (See \autoref{component-declarations}.) -\textbf{vector}: an array where the number of dimensions is 1. (See +\glossaryitem{vector}: an array where the number of dimensions is 1. (See \autoref{arrays}.) diff --git a/preamble.tex b/preamble.tex index de72ad7ac..e13102f9e 100644 --- a/preamble.tex +++ b/preamble.tex @@ -132,6 +132,8 @@ \newcommand{\autonameref}[1]{\autoref{#1}~\emph{\nameref*{#1}}} +\newcommand{\glossaryitem}[1]{\textbf{#1}} + \setcounter{secnumdepth}{5} % Note: Toc changed for appendex \setcounter{tocdepth}{1} From b59318d18d6e7366202c2c2c2d862ed3f4011c8b Mon Sep 17 00:00:00 2001 From: Henrik Tidefelt Date: Tue, 2 Jun 2020 23:38:10 +0200 Subject: [PATCH 13/78] More operator mentions --- chapters/classes.tex | 3 +-- chapters/dae.tex | 5 ++--- chapters/equations.tex | 14 +++++++------- chapters/statements.tex | 3 +-- chapters/stream.tex | 8 ++++---- 5 files changed, 15 insertions(+), 18 deletions(-) diff --git a/chapters/classes.tex b/chapters/classes.tex index 7b3484e6a..194e624ec 100644 --- a/chapters/classes.tex +++ b/chapters/classes.tex @@ -378,8 +378,7 @@ \subsection{Component Variability Prefixes discrete, parameter, constant}\double A \emph{discrete-time} variable \lstinline!vd! has a vanishing time derivative between events. Note that this is not the same as saying that \lstinline!der(vd)=0! almost everywhere, as the derivative is not even defined at the events, and it is not legal - to apply the \lstinline!der()! operator - to discrete-time variables as they are not continuous. During transient analysis the variable + to apply \lstinline!der()! to discrete-time variables as they are not continuous. During transient analysis the variable can only change its value at event instants (see \autoref{events-and-synchronization}). \item diff --git a/chapters/dae.tex b/chapters/dae.tex index 589f345f0..f6f2b7859 100644 --- a/chapters/dae.tex +++ b/chapters/dae.tex @@ -62,9 +62,8 @@ \chapter{Modelica DAE Representation}\doublelabel{modelica-dae-representation} \end{longtable} -For simplicity, the special cases of the \lstinline!noEvent()! operator and of the -\lstinline!reinit()! operator are not contained in the equations above and are not -discussed below. +For simplicity, the special cases of \lstinline!noEvent! and \lstinline!reinit! are not contained in the equations +above and are not discussed below. The generated set of equations is used for simulation and other analysis activities. Simulation means that an initial value problem is solved, diff --git a/chapters/equations.tex b/chapters/equations.tex index f144eed99..fbbf44af8 100644 --- a/chapters/equations.tex +++ b/chapters/equations.tex @@ -628,10 +628,10 @@ \section{Events and Synchronization}\doublelabel{events-and-synchronization} Relations are taken literally also during continuous integration, if the relation or the expression in which the relation is present, are the -argument of the \lstinline!noEvent(..)! function. The \lstinline!smooth(p,x)! operator also +argument of \lstinline!noEvent!. \lstinline!smooth! also allows relations used as argument to be taken literally. The \lstinline!noEvent! feature is propagated to all subrelations in the scope of the \lstinline!noEvent! -function. For \lstinline!smooth! the liberty to not allow literal evaluation is +application. For \lstinline!smooth! the liberty to not allow literal evaluation is propagated to all subrelations, but the smooth-property itself is not propagated. @@ -755,8 +755,8 @@ \section{Initialization, initial equation, and initial algorithm}\doublelabel{in all equations and algorithms that are utilized in the intended operation (such as simulation or linearization). The equations of a when-clause are active during initialization, if and only if they are -explicitly enabled with the \lstinline!initial()! operator; and only in one of the -two forms \lstinline!when initial() then! or \lstinline!when {...,initial(),...} then! +explicitly enabled with \lstinline!initial()!; and only in one of the +two forms \lstinline!when initial() then! or \lstinline[mathescape=true]!when {$\ldots$, initial(), $\ldots$} then! (and similarly for algorithms see below). In this case, the when-clause equations remain active during the whole initialization phase. In case of a \lstinline!reinit(x, expr)! being active during initialization (due to being inside @@ -770,8 +770,8 @@ \section{Initialization, initial equation, and initial algorithm}\doublelabel{in \end{nonnormative} The algorithmic statements within a when-statement are active during initialization, if and only they are -explicitly enabled with the \lstinline!initial()! operator; and only in one of the -two forms \lstinline!when initial() then! or \lstinline!when {...,initial(),...} then!. +explicitly enabled with \lstinline!initial()!; and only in one of the +two forms \lstinline!when initial() then! or \lstinline[mathescape=true]!when {$\ldots$, initial(), $\ldots$} then!. In this case, the algorithmic statements within the when-statement remain active during the whole initialization phase. \begin{nonnormative} @@ -861,7 +861,7 @@ \section{Initialization, initial equation, and initial algorithm}\doublelabel{in It may be difficult for a user to figure out how many initial equations have to be added, especially if the system has a higher index. A tool may add or remove initial equations automatically such that the resulting system is structurally nonsingular. In these cases diagnostics are appropriate since the result is not unique and may not be what the user expects. A missing initial value of a discrete variable which does not influence the simulation result, may be automatically set to the start value or its default without -informing the user. For example, variables assigned in a when-clause which are not accessed outside of the when-clause and where the \lstinline!pre()! operator is not explicitly +informing the user. For example, variables assigned in a when-clause which are not accessed outside of the when-clause and where \lstinline!pre! is not explicitly used on these variables, do not have an effect on the simulation. \end{nonnormative} diff --git a/chapters/statements.tex b/chapters/statements.tex index 8a29aa5e3..d48a4c4c4 100644 --- a/chapters/statements.tex +++ b/chapters/statements.tex @@ -471,9 +471,8 @@ \subsubsection{Defining When-Statements by If-Statements}\doublelabel{defining-w ... end when; \end{lstlisting} -is similar to the following special if-statement, where \lstinline!Boolean b1[N];! and \lstinline!Boolean b2;! are necessary because the \lstinline!edge()! operator can +is similar to the following special if-statement, where \lstinline!Boolean b1[N];! and \lstinline!Boolean b2;! are necessary because \lstinline!edge! can only be applied to variables - \begin{lstlisting}[language=modelica] Boolean b1[N](start={x.start>1, ..., y.start>p}); diff --git a/chapters/stream.tex b/chapters/stream.tex index 96527c415..6067b7b2f 100644 --- a/chapters/stream.tex +++ b/chapters/stream.tex @@ -164,8 +164,8 @@ \section{Stream Operator inStream and Connection Equations}\doublelabel{stream-o inStream($m_{i}$.c.h_outflow) = $\mathit{h\_mix\_in}_{i}$; \end{lstlisting} -Note that the result of the -\lstinline[mathescape=true]!inStream($m_{i}$.c.h_outflow)! operator is different +Note that the result of +\lstinline[mathescape=true]!inStream($m_{i}$.c.h_outflow)! is different for each port $i$, because the assumption of flow entering the port is different for each of them. @@ -392,7 +392,7 @@ \section{Stream Operator inStream and Connection Equations}\doublelabel{stream-o \section{Stream Operator actualStream}\doublelabel{stream-operator-actualstream} -The \lstinline!actualStream(v)! operator is provided for convenience, in +\lstinline!actualStream! is provided for convenience, in order to return the actual value of the stream variable, depending on the actual flow direction. The only argument of this built-in operator needs to be a reference to a stream variable. The operator is @@ -417,7 +417,7 @@ \section{Stream Operator actualStream}\doublelabel{stream-operator-actualstream} Therefore, a tool might infer that the expression is \lstinline!smooth(0, ...)! automatically, and decide whether or not to generate an event. If a user wants to avoid events entirely, he/she may enclose the right-hand side -of (1) with the \lstinline!noEvent()! operator. +of (1) with \lstinline!noEvent!. Equations like (2) might be used for monitoring purposes (e.g. plots), in order to inspect what the actual enthalpy of the fluid From 5d74a8e3af7e1ee98aa54cb1a8c70d82065c89c4 Mon Sep 17 00:00:00 2001 From: Henrik Tidefelt Date: Tue, 2 Jun 2020 23:58:15 +0200 Subject: [PATCH 14/78] Remove some empty lines at the bottom of tables --- chapters/annotations.tex | 2 -- chapters/arrays.tex | 7 ------- chapters/functions.tex | 1 - chapters/operatorsandexpressions.tex | 1 - chapters/synchronous.tex | 1 - 5 files changed, 12 deletions(-) diff --git a/chapters/annotations.tex b/chapters/annotations.tex index 996aab7da..067e7d4eb 100644 --- a/chapters/annotations.tex +++ b/chapters/annotations.tex @@ -222,7 +222,6 @@ \section{Annotations for Code Generation}\doublelabel{annotations-for-code-gener the output should generate an event when it changes. \end{nonnormative} \\ \hline - \end{longtable} \begin{lstlisting}[language=grammar] smoothOrder-annotation: @@ -1909,7 +1908,6 @@ \section{Annotations for Access Control to Protect Intellectual Property}\double \hline \textbf{Licensing} & Restrict the use of an encrypted package for particular users for a specified period of time.\\ \hline - \end{longtable} In this section annotations are defined for protection and diff --git a/chapters/arrays.tex b/chapters/arrays.tex index 78c5a8f9d..fe84e3889 100644 --- a/chapters/arrays.tex +++ b/chapters/arrays.tex @@ -482,7 +482,6 @@ \subsubsection{Reduction Expressions}\doublelabel{reduction-expressions} \begin{tabular}{@{}p{6cm}@{}} Least value of type\\ ( \lstinline!-Modelica.Constants.inf! for Real) \end{tabular}\\ \hline - \end{longtable} \begin{example} @@ -956,7 +955,6 @@ \subsection{Array Element-wise Addition, Subtraction, and String Concatenation}\ Array{[}n, m, \ldots{}{]} & Array{[}n, m, \ldots{}{]} & Array{[}n, m, \ldots{}{]} & c {[}j, k, \ldots{}{]} := a{[}j, k, \ldots{}{]} +/- b{[}j, k, \ldots{}{]}\\ \hline - \end{longtable} \begin{longtable}[]{|l|l|l|} @@ -968,7 +966,6 @@ \subsection{Array Element-wise Addition, Subtraction, and String Concatenation}\ Scalar & Scalar & c := +/- a\\ \hline Array{[}n, m, \ldots{}{]} & Array{[}n, m, \ldots{}{]} & c{[}j, k, \ldots{}{]} := +/-a{[}j, k, \ldots{}{]}\\ \hline - \end{longtable} \subsection{Array Element-wise Multiplication}\doublelabel{array-element-wise-multiplication} @@ -1030,7 +1027,6 @@ \subsection{Matrix and Vector Multiplication of Numeric Arrays}\doublelabel{matr Matrix {[}n, m{]} & Matrix {[}m, p{]} & Matrix {[}n, p{]} & c{[}i, j{]} = $\textrm{sum}_k$(a{[}i, k{]}*b{[}k, j{]}), i=1:n, k=1:m, j=1:p\\ \hline - \end{longtable} \begin{example} @@ -1063,7 +1059,6 @@ \subsection{Division of Scalars or Numeric Arrays by Numeric Scalars}\doublelabe k{]} / s\\ \hline Array{[}n, m, \ldots{}{]} & Scalar & Array{[}n, m, \ldots{}{]} & c{[}j, k, \ldots{}{]} := a{[}j, k, \ldots{}{]} / s\\ \hline - \end{longtable} \subsection{Array Element-wise Division}\doublelabel{array-element-wise-division} @@ -1087,7 +1082,6 @@ \subsection{Array Element-wise Division}\doublelabel{array-element-wise-division Array{[}n, m, \ldots{}{]} & Array{[}n, m, ...{]} & Array {[}n, m, ...{]} & c{[}j, k, \ldots{}{]} := a{[}j, k, \ldots{}{]} / b{[}j, k, \ldots{}{]}\\ \hline - \end{longtable} \begin{example} @@ -1128,7 +1122,6 @@ \subsection{Exponentiation of Scalars of Numeric Elements}\doublelabel{exponenti Array{[}n, m, \ldots{}{]} & Array{[}n, m, ...{]} & Array {[}n, m, ...{]} & c{[}j, k, \ldots{}{]} := a{[}j, k, \ldots{}{]} \^{} b{[}j, k, \ldots{}{]}\\ \hline - \end{longtable} \begin{example} diff --git a/chapters/functions.tex b/chapters/functions.tex index b5fd51812..13d68f2db 100644 --- a/chapters/functions.tex +++ b/chapters/functions.tex @@ -2457,7 +2457,6 @@ \subsubsection{Utility Functions for Reporting Errors}\doublelabel{utility-funct ModelicaVFormat\{Message,Warning,Error\}\newline (const char*string, va\_list)}}\hbox{\strut Output the message under the same format control as the C-function \lstinline!vprintf!.}}\\ \hline - \end{longtable} \subsubsection{Utility Functions for Allocating Strings}\doublelabel{utility-functions-for-allocating-strings} diff --git a/chapters/operatorsandexpressions.tex b/chapters/operatorsandexpressions.tex index e17eeba22..2d1b60f3e 100644 --- a/chapters/operatorsandexpressions.tex +++ b/chapters/operatorsandexpressions.tex @@ -1185,7 +1185,6 @@ \subsection{Event-Related Operators with Function Syntax}\doublelabel{event-rela as an individual variable or as part of an array of variables. It can only be applied in the body of a when clause in an equation section. See also \autoref{reinit}.\\ \hline - \end{longtable} A few of these operators are described in more detail in the following. diff --git a/chapters/synchronous.tex b/chapters/synchronous.tex index 8ac1d3c5e..e7b4c9a63 100644 --- a/chapters/synchronous.tex +++ b/chapters/synchronous.tex @@ -512,7 +512,6 @@ \section{Clock Constructors}\doublelabel{clock-constructors} \strut \end{tabular} \\ \hline - \end{longtable} Besides inferred clocks and solver clocks, one of the following mutually From 9e3eb8522b3ba91f42a261dc5f093a690367ca37 Mon Sep 17 00:00:00 2001 From: Henrik Tidefelt Date: Wed, 3 Jun 2020 00:00:18 +0200 Subject: [PATCH 15/78] Remove inconsistent use of \textbf in dae.tex In the past, these vector variables used to be formatted in boldface. Now, I don't know how we want it, but this commit at least makes formatting consistent. If we want boldface, we should use \mathbf. --- chapters/dae.tex | 89 +++++++++++++++++++++++------------------------- 1 file changed, 42 insertions(+), 47 deletions(-) diff --git a/chapters/dae.tex b/chapters/dae.tex index f6f2b7859..7b5a50fc7 100644 --- a/chapters/dae.tex +++ b/chapters/dae.tex @@ -9,57 +9,51 @@ \chapter{Modelica DAE Representation}\doublelabel{modelica-dae-representation} used components by: \begin{itemize} \item - expanding all class definitions (flattening the inheritance tree) and + Expanding all class definitions (flattening the inheritance tree) and adding the equations and assignment statements of the expanded classes for every instance of the model. \item - replacing all connect-equations by the corresponding equations of the + Replacing all connect-equations by the corresponding equations of the connection set (see \autoref{generation-of-connection-equations}). \item - mapping all algorithm sections to equation sets. + Mapping all algorithm sections to equation sets. \item - mapping all when-clauses to equation sets (see \autoref{when-equations}). + Mapping all when-clauses to equation sets (see \autoref{when-equations}). \end{itemize} As a result of this transformation process, a set of equations is obtained consisting of differential, algebraic and discrete equations of -the following form where ($v:=\lbrack \dot{x}; x; y; t; m; \text{pre}(m); p\rbrack$ ): +the following form where ($v := \lbrack \dot{x}; x; y; t; m; \text{\lstinline!pre!}(m); p\rbrack$): \begin{subequations} \begin{equation} -c:=f_c(relation(v))\label{eq:crossing} +c:=f_{\mathrm{c}}(\mathit{relation}(v))\label{eq:crossing} \end{equation} \begin{equation} -\dot{m}:=f_m(v, v) +\dot{m}:=f_m(v, c) \end{equation} \begin{equation} -0=f_x(v, v)\label{eq:dae} +0=f_x(v, c)\label{eq:dae} \end{equation} \label{eq:hydrid-dae} \end{subequations} and where - \begin{longtable}[]{|p{2cm}|p{12cm}|} \hline \endhead -\textbf{p} & Modelica variables declared as \lstinline!parameter! or -\lstinline!constant!, i.e., variables without any -time-dependency.\\ \hline -\emph{t} & Modelica variable \lstinline!time!, the independent (real) -variable.\\ \hline -\textbf{x}(t) & Modelica variables of type \lstinline!Real!, appearing -differentiated.\\ \hline -\textbf{m}(t\textsubscript{e}) & Modelica variables of type -\lstinline!discrete Real!, \lstinline!Boolean!, \lstinline!Integer! which are unknown. These -variables change their value only at event instants t\textsubscript{e}. -\lstinline!pre(m)! are the values of m immediately before the current event -occurred.\\ \hline -\textbf{y}(t) & Modelica variables of type \lstinline!Real! which do not fall -into any other category (= algebraic variables).\\ \hline -c\textbf{(}t\textsubscript{e}) & The conditions of all if-expressions -generated including when-clauses after conversion, see \autoref{when-equations}).\\ \hline -\emph{relation}(\textbf{v}) & A relation containing variables -v\textsubscript{i}, e.g. v\textsubscript{1} \textgreater{} -v\textsubscript{2}, v\textsubscript{3} \textgreater{}= 0.\\ \hline - +$p$ & Modelica variables declared as \lstinline!parameter! or \lstinline!constant!, i.e., variables without any time-dependency.\\ +\hline +$t$ & Modelica variable \lstinline!time!, the independent (real) variable.\\ +\hline +$x(t)$ & Modelica variables of type \lstinline!Real!, appearing differentiated.\\ +\hline +$m(t_{\mathrm{e}})$ & Modelica variables of type \lstinline!discrete Real!, \lstinline!Boolean!, \lstinline!Integer! which are unknown. +These variables change their value only at event instants t\textsubscript{e}. \lstinline!pre(m)! are the values of $m$ immediately before the current event occurred.\\ +\hline +$y(t)$ & Modelica variables of type \lstinline!Real! which do not fall into any other category (= algebraic variables).\\ +\hline +$c(t_{\mathrm{e}})$ & The conditions of all if-expressions generated including when-clauses after conversion, see \autoref{when-equations}).\\ +\hline +$\mathit{relation}(v)$ & A relation containing variables $v_{i}$, e.g. $v_{1} > v_{2}$, $v_{3} \geq 0$.\\ +\hline \end{longtable} For simplicity, the special cases of \lstinline!noEvent! and \lstinline!reinit! are not contained in the equations @@ -67,7 +61,7 @@ \chapter{Modelica DAE Representation}\doublelabel{modelica-dae-representation} The generated set of equations is used for simulation and other analysis activities. Simulation means that an initial value problem is solved, -i.e., initial values have to be provided for the states x, \autoref{initialization-initial-equation-and-initial-algorithm}. +i.e., initial values have to be provided for the states $x$, \autoref{initialization-initial-equation-and-initial-algorithm}. The equations define a DAE (Differential Algebraic Equations) which may have discontinuities, a variable structure and/or which are controlled by a discrete-event system. Such types of systems are called @@ -75,8 +69,8 @@ \chapter{Modelica DAE Representation}\doublelabel{modelica-dae-representation} \begin{enumerate} \item The DAE (\ref{eq:dae}) is solved by a numerical integration method. In this - phase the conditions c of the if- and when-clauses, as well as the - discrete variables m are kept constant. Therefore, (\ref{eq:dae}) is a + phase the conditions $c$ of the if- and when-clauses, as well as the + discrete variables $m$ are kept constant. Therefore, (\ref{eq:dae}) is a continuous function of continuous variables and the most basic requirement of numerical integrators is fulfilled. \item @@ -93,13 +87,13 @@ \chapter{Modelica DAE Representation}\doublelabel{modelica-dae-representation} After an event is processed, the integration is restarted with 1. \end{enumerate} -Note, that both the values of the conditions c as well as the values of -m (all \lstinline!discrete Real!, \lstinline!Boolean! and \lstinline!Integer! variables) are only changed at +Note, that both the values of the conditions $c$ as well as the values of +$m$ (all \lstinline!discrete Real!, \lstinline!Boolean! and \lstinline!Integer! variables) are only changed at an event instant and that these variables remain constant during continuous integration. At every event instant, new values of the -discrete variables m and of new initial values for the states x are +discrete variables $m$ and of new initial values for the states $x$ are determined. The change of discrete variables may characterize a new -structure of a DAE where elements of the state vector x are +structure of a DAE where elements of the state vector $x$ are \emph{disabled}. In other words, the number of state variables, algebraic variables and residue equations of a DAE may change at event instants by disabling the appropriate part of the DAE. For clarity of @@ -109,15 +103,15 @@ \chapter{Modelica DAE Representation}\doublelabel{modelica-dae-representation} At an event instant, including the initial event, the model equations are reinitialized according to the following iteration procedure: \begin{lstlisting}[language=modelica] - known variables: x, t, p - unkown variables: dx/dt, y, m, pre(m), c +known variables: x, t, p +unkown variables: dx/dt, y, m, pre(m), c - // pre(m) = value of m before event occured - loop - solve (1) for the unknowns, with pre(m) fixed - if m == pre(m) then break - pre(m) := m - end loop +// pre(m) = value of m before event occured +loop + solve (1) for the unknowns, with pre(m) fixed + if m == pre(m) then break + pre(m) := m +end loop \end{lstlisting} Solving (\ref{eq:hydrid-dae}) for the unknowns is non-trivial, because this set of equations contains not only Real, but also Boolean and Integer unknowns. @@ -149,9 +143,10 @@ \chapter{Modelica DAE Representation}\doublelabel{modelica-dae-representation} index. Note, that also explicit integration methods, such as Runge-Kutta algorithms, can be used to solve (\ref{eq:dae}), after the index of (\ref{eq:dae}) has been reduced by the Pantelides algorithm: During continuous integration, the -integrator provides x and t. Then, (\ref{eq:dae}) is a linear or nonlinear system -of equations to compute the algebraic variables y and the state -derivatives dx/dt and the model returns dx/dt to the integrator by +integrator provides $x$ and $t$. Then, (\ref{eq:dae}) is a linear or nonlinear system +of equations to compute the algebraic variables $y$ and the state +% TODO: Structured formatting of inline "upright 'd' fraction". +derivatives $\mathrm{d}x/\mathrm{d}t$ and the model returns $\mathrm{d}x/\mathrm{d}t$ to the integrator by solving these systems of equations. Often, (\ref{eq:dae}) is just a linear system of equations in these unknowns, so that the solution is straightforward. This procedure is especially useful for real-time simulation where From 862d926af0e63c7d9a6e5604161e5ddb700e28a3 Mon Sep 17 00:00:00 2001 From: Henrik Tidefelt Date: Wed, 3 Jun 2020 00:24:42 +0200 Subject: [PATCH 16/78] Avoid \textbf for starting examples --- chapters/connectors.tex | 7 +++++-- chapters/equations.tex | 6 ++++-- chapters/operatorsandexpressions.tex | 14 +++++++++----- preamble.tex | 8 ++++---- 4 files changed, 22 insertions(+), 13 deletions(-) diff --git a/chapters/connectors.tex b/chapters/connectors.tex index 879ac3728..c72cafd8f 100644 --- a/chapters/connectors.tex +++ b/chapters/connectors.tex @@ -310,7 +310,10 @@ \subsection{Expandable Connectors}\doublelabel{expandable-connectors} \lstinline!inner! scope qualifier, all outer instances must also be taken into account during elaboration. \end{enumerate} -\textbf{Example.} Engine system with sensors, controllers, actuator and plant that +\end{nonnormative} + +\begin{example} +Engine system with sensors, controllers, actuator and plant that exchange information via a bus (i.e. via expandable connectors): \begin{lstlisting}[language=modelica] import Modelica.Units.SI; @@ -368,7 +371,7 @@ \subsection{Expandable Connectors}\doublelabel{expandable-connectors} CylinderBus cylinder_bus[3]; CylinderBus cylinder_bus[4]; \end{lstlisting} -\end{nonnormative} +\end{example} \section{Generation of Connection Equations}\doublelabel{generation-of-connection-equations} diff --git a/chapters/equations.tex b/chapters/equations.tex index fbbf44af8..a98fb58b4 100644 --- a/chapters/equations.tex +++ b/chapters/equations.tex @@ -945,8 +945,10 @@ \subsection{The Number of Equations Needed for Initialization}\doublelabel{the-n derivative variables. At initialization of an ODE we will need to find the values of 2n+m variables, in contrast to just n+m variables to be solved for during simulation. +\end{nonnormative} -\textbf{Example.} Consider the following simple equation system: +\begin{example} +Consider the following simple equation system: \begin{lstlisting}[language=modelica] der(x1) = f1(x1); der(x2) = f2(x2); @@ -968,7 +970,7 @@ \subsection{The Number of Equations Needed for Initialization}\doublelabel{the-n variables n. As noted in \autoref{initialization-initial-equation-and-initial-algorithm} a tool may add/remove initial equations to fulfill this requirement, if appropriate diagnostics are given. -\end{nonnormative} +\end{example} \subsection{Recommended selection of start-values}\doublelabel{recommended-selection-of-start-values} diff --git a/chapters/operatorsandexpressions.tex b/chapters/operatorsandexpressions.tex index 2d1b60f3e..b7a32a369 100644 --- a/chapters/operatorsandexpressions.tex +++ b/chapters/operatorsandexpressions.tex @@ -923,8 +923,9 @@ \subsubsection{homotopy}\doublelabel{homotopy} annotation(Inline = true); end homotopy; \end{lstlisting} +\end{nonnormative} -\textbf{Example 1.} In electrical systems it is often difficult to solve non-linear +\begin{example}[1] In electrical systems it is often difficult to solve non-linear algebraic equations if switches are part of the algebraic loop. An idealized diode model might be implemented in the following way, by starting with a ``flat'' diode characteristic and then move with @@ -944,8 +945,9 @@ \subsubsection{homotopy}\doublelabel{homotopy} ... end IdealDiode; \end{lstlisting} +\end{example} -\textbf{Example 2.} In electrical systems it is often useful that all voltage sources +\begin{example}[2] In electrical systems it is often useful that all voltage sources start with zero voltage and all current sources with zero current, since steady state initialization with zero sources can be easily obtained. A typical voltage source would then be defined as: @@ -957,8 +959,9 @@ \subsubsection{homotopy}\doublelabel{homotopy} v = homotopy(actual=V, simplified=0.0); end ConstantVoltageSource; \end{lstlisting} +\end{example} -\textbf{Example 3.} In fluid system modelling, the pressure/flowrate relationships are +\begin{example}[3] In fluid system modelling, the pressure/flowrate relationships are highly nonlinear due to the quadratic terms and due to the dependency on fluid properties. A simplified linear model, tuned on the nominal operating point, can be used to make the overall model less nonlinear @@ -979,8 +982,9 @@ \subsubsection{homotopy}\doublelabel{homotopy} ... end PressureLoss; \end{lstlisting} +\end{example} -\textbf{Example 4.} Note that \lstinline!homotopy! \textbf{shall not} be used to +\begin{example}[4] Note that \lstinline!homotopy! \textbf{shall not} be used to combine unrelated expressions, since this can generate singular systems from combining two well-defined systems. \begin{lstlisting}[language=modelica] @@ -999,7 +1003,7 @@ \subsubsection{homotopy}\doublelabel{homotopy} and you can solve the two equations to give $$ x=\frac{\lambda+(\lambda-1)x_0}{2\lambda-1}$$ which has the correct value of $x_0$ at $\lambda = 0$ and of 1 at $\lambda= 1$, but unfortunately has a singularity at $\lambda = 0.5 $. -\end{nonnormative} +\end{example} \subsubsection{semiLinear}\doublelabel{semilinear} diff --git a/preamble.tex b/preamble.tex index e13102f9e..ac5651c19 100644 --- a/preamble.tex +++ b/preamble.tex @@ -105,13 +105,13 @@ } % Example environment, as a special case of non-normative content. -\newenvironment{example*}[0]{% -\begin{nonnormative*}Example: +\newenvironment{example*}[1][\unskip]{% +\begin{nonnormative*}Example #1: }{% \end{nonnormative*} } -\newenvironment{example}[0]{% -\begin{nonnormative}Example: +\newenvironment{example}[1][\unskip]{% +\begin{nonnormative}Example #1: }{% \end{nonnormative} } From 16f659f7b4edba6b05124840beacafbb83b134e7 Mon Sep 17 00:00:00 2001 From: Henrik Tidefelt Date: Wed, 3 Jun 2020 00:31:23 +0200 Subject: [PATCH 17/78] Apply some math formatting --- chapters/equations.tex | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/chapters/equations.tex b/chapters/equations.tex index a98fb58b4..c55b397d2 100644 --- a/chapters/equations.tex +++ b/chapters/equations.tex @@ -939,11 +939,11 @@ \subsection{The Number of Equations Needed for Initialization}\doublelabel{the-n \begin{nonnormative} In general, for the case of a pure (first order) ordinary -differential equation (ODE) system with n state variables and m output -variables, we will have n+m unknowns in the simulation problem. The ODE -initialization problem has n additional unknowns corresponding to the +differential equation (ODE) system with $n$ state variables and $m$ output +variables, we will have $n+m$ unknowns in the simulation problem. The ODE +initialization problem has $n$ additional unknowns corresponding to the derivative variables. At initialization of an ODE we will need to find -the values of 2n+m variables, in contrast to just n+m variables to be +the values of $2n+m$ variables, in contrast to just $n+m$ variables to be solved for during simulation. \end{nonnormative} @@ -957,17 +957,17 @@ \subsection{The Number of Equations Needed for Initialization}\doublelabel{the-n Here we have three variables with unknown values: two dynamic variables that also are state variables, \lstinline!x1! and \lstinline!x2!, i.e., -n=2, one output variable \lstinline!y!, i.e., m=1, and one input variable \lstinline!u! with +$n=2$, one output variable \lstinline!y!, i.e., $m=1$, and one input variable \lstinline!u! with known value. A consistent solution of the initial value problem providing initial values for \lstinline!x1!, \lstinline!x2!, \lstinline!der(x1)!, \lstinline!der(x2)!, and \lstinline!y! needs to be found. Two additional initial equations thus need to be provided to solve the initialization problem. -Regarding DAEs, only that at most n additional equations are -needed to arrive at 2n+m equations in the initialization system. The +Regarding DAEs, only that at most $n$ additional equations are +needed to arrive at $2n+m$ equations in the initialization system. The reason is that in a higher index DAE problem the number of dynamic continuous-time state variables might be less than the number of state -variables n. As noted in \autoref{initialization-initial-equation-and-initial-algorithm} a tool may add/remove +variables $n$. As noted in \autoref{initialization-initial-equation-and-initial-algorithm} a tool may add/remove initial equations to fulfill this requirement, if appropriate diagnostics are given. \end{example} From ca5afe9caec6b5128ab9ed812697b3ba20da9154 Mon Sep 17 00:00:00 2001 From: Henrik Tidefelt Date: Wed, 3 Jun 2020 00:59:47 +0200 Subject: [PATCH 18/78] Remove empty parentheses that don't mean empty parentheses This change is related to the other changes where operators with function calling syntax are mentioned. --- chapters/classes.tex | 2 +- chapters/equations.tex | 2 +- chapters/operatorsandexpressions.tex | 8 ++++---- chapters/statemachines.tex | 2 +- chapters/stream.tex | 9 ++++----- 5 files changed, 11 insertions(+), 12 deletions(-) diff --git a/chapters/classes.tex b/chapters/classes.tex index 194e624ec..4499ff789 100644 --- a/chapters/classes.tex +++ b/chapters/classes.tex @@ -378,7 +378,7 @@ \subsection{Component Variability Prefixes discrete, parameter, constant}\double A \emph{discrete-time} variable \lstinline!vd! has a vanishing time derivative between events. Note that this is not the same as saying that \lstinline!der(vd)=0! almost everywhere, as the derivative is not even defined at the events, and it is not legal - to apply \lstinline!der()! to discrete-time variables as they are not continuous. During transient analysis the variable + to apply \lstinline!der! to discrete-time variables as they are not continuous. During transient analysis the variable can only change its value at event instants (see \autoref{events-and-synchronization}). \item diff --git a/chapters/equations.tex b/chapters/equations.tex index c55b397d2..6f6d6bb7f 100644 --- a/chapters/equations.tex +++ b/chapters/equations.tex @@ -311,7 +311,7 @@ \subsubsection{Restrictions on Equations within When-Equations}\doublelabel{rest \item \lstinline!v = expr;! \item \lstinline!(out1, out2, out3, ...) = function_call_name(in1, in2, ...);! \item - operators \lstinline!assert()!, \lstinline!terminate()!, \lstinline!reinit()! + operators \lstinline!assert!, \lstinline!terminate!, \lstinline!reinit! \item For- and if-equations if the equations within the for- and if-equations satisfy these requirements. diff --git a/chapters/operatorsandexpressions.tex b/chapters/operatorsandexpressions.tex index b7a32a369..85fd8f706 100644 --- a/chapters/operatorsandexpressions.tex +++ b/chapters/operatorsandexpressions.tex @@ -481,7 +481,7 @@ \subsubsection{Event Triggering Mathematical Functions}\doublelabel{event-trigge \lstinline!div(x,y)! & Returns the algebraic quotient \lstinline!x/y! with any fractional part discarded (also known as truncation toward zero). \begin{nonnormative} -This is defined for \lstinline!/! in C99; in C89 the result for negative numbers is implementation-defined, so the standard function \lstinline!div()! must be used. +This is defined for \lstinline!/! in C99; in C89 the result for negative numbers is implementation-defined, so the standard function \lstinline[language=C]!div! must be used. \end{nonnormative} Result and arguments shall have type \lstinline!Real! or \lstinline!Integer!. If either of the arguments is \lstinline!Real! the result is \lstinline!Real! otherwise @@ -810,7 +810,7 @@ \subsubsection{spatialDistribution}\doublelabel{spatialdistribution} \end{lstlisting} Events are generated at the exact instants when the velocity -changes sign -- if this is not needed, \lstinline!noEvent()! can be used to +changes sign --- if this is not needed, \lstinline!noEvent! can be used to suppress event generation. If the velocity is known to be always positive, then \lstinline!out0! can be omitted, e.g.: @@ -1009,7 +1009,7 @@ \subsubsection{homotopy}\doublelabel{homotopy} \subsubsection{semiLinear}\doublelabel{semilinear} (See definition of \lstinline!semiLinear! in \autoref{derivative-and-special-purpose-operators-with-function-syntax}). In some situations, -equations with the \lstinline!semiLinear()! function become underdetermined if the +equations with \lstinline!semiLinear! become underdetermined if the first argument (\lstinline!x!) becomes zero, i.e., there are an infinite number of solutions. It is recommended that the following rules are used to transform the equations during the translation phase in order to select @@ -1363,7 +1363,7 @@ \subsection{Discrete-Time Expressions}\doublelabel{discrete-time-expressions} argument is non-discrete time expression and subtype of \lstinline!Real!. \begin{nonnormative} These will generate events, see \autoref{events-and-synchronization}. 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. + expressions. In other words, relations inside \lstinline!noEvent!, such as \lstinline!noEvent(x>1)!, are not discrete-time expressions. \end{nonnormative} \item The functions \lstinline!pre!, \lstinline!edge!, and \lstinline!change! result in discrete-time diff --git a/chapters/statemachines.tex b/chapters/statemachines.tex index 4d7a74a5d..4f18b98e5 100644 --- a/chapters/statemachines.tex +++ b/chapters/statemachines.tex @@ -157,7 +157,7 @@ \section{State Machine Graphics}\doublelabel{state-machine-graphics} lines. \end{nonnormative} -The annotation for graphics of \lstinline!transition()! has the following +The annotation for graphics of \lstinline!transition! has the following structure: \lstinline[mathescape=true]!annotation(Line($\ldots$), Text($\ldots$))!; and for \lstinline!initialState()!: \emph{graphical-primitives}\lstinline[mathescape=true]!(Line($\ldots$))!; with \lstinline!Line! and \lstinline!Text! annotations defined in \autoref{annotations}. diff --git a/chapters/stream.tex b/chapters/stream.tex index 6067b7b2f..6dd11d3c2 100644 --- a/chapters/stream.tex +++ b/chapters/stream.tex @@ -405,11 +405,10 @@ \section{Stream Operator actualStream}\doublelabel{stream-operator-actualstream} \end{lstlisting} \begin{nonnormative} -The \textbf{actualStream}(v) operator is typically used in two -contexts: +\lstinline!actualStream! is typically used in two contexts: \begin{lstlisting}[language=modelica] - der(U) = c.m_flow*actualStream(c.h_outflow); // (1) energy balance equation - h_c = actualStream(c.h); // (2) monitoring the enthalpy at port c + der(U) = c.m_flow * actualStream(c.h_outflow); // (1) energy balance equation + h_c = actualStream(c.h); // (2) monitoring the enthalpy at port c \end{lstlisting} In the case of equation (1), although \lstinline!actualStream! is discontinuous, the product with the flow variable is not, because @@ -424,7 +423,7 @@ \section{Stream Operator actualStream}\doublelabel{stream-operator-actualstream} flowing through a port is. In this case, the user will probably want to see the change due to flow reversal at the exact instant, so an event should be generated. If the user doesn't bother, then he/she should -enclose the right-hand side of (2) with \lstinline!noEvent()!. Since the output of +enclose the right-hand side of (2) with \lstinline!noEvent!. Since the output of \lstinline!actualStream! will be discontinuous, it should not be used by itself to model physical behaviour (e.g., to compute densities used in momentum balances) --- \lstinline!inStream! should be used for this purpose. From 19dec4e200ad9228e948bed8a09ab6a99d9e9e33 Mon Sep 17 00:00:00 2001 From: Henrik Tidefelt Date: Wed, 3 Jun 2020 01:00:29 +0200 Subject: [PATCH 19/78] Avoid \textbf when showing syntax of connect-equation --- chapters/connectors.tex | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/chapters/connectors.tex b/chapters/connectors.tex index c72cafd8f..72886df9d 100644 --- a/chapters/connectors.tex +++ b/chapters/connectors.tex @@ -9,8 +9,9 @@ \section{Connect-Equations and Connectors}\doublelabel{connect-equations-and-con Connections between objects are introduced by connect-equations in the equation part of a class. A connect-equation has the following syntax: - -\textbf{connect} "(" component-reference "," component-reference ")" ";" +\begin{lstlisting}[language=modelica,mathescape=true] +connect(component-reference, component-reference); +\end{lstlisting} \begin{nonnormative} A \emph{connector} is an instance of a connector class. From 53d8c7da8e34d2013ae7681822545b4e3d6798c6 Mon Sep 17 00:00:00 2001 From: Henrik Tidefelt Date: Wed, 3 Jun 2020 01:01:34 +0200 Subject: [PATCH 20/78] Change one \textbf into \lstinline --- chapters/statements.tex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/chapters/statements.tex b/chapters/statements.tex index d48a4c4c4..9889e296c 100644 --- a/chapters/statements.tex +++ b/chapters/statements.tex @@ -36,7 +36,7 @@ \subsection{Execution of an algorithm in a model}\doublelabel{execution-of-an-al A non-discrete variable is initialized with its start value (i.e. the value of the start-attribute). \item - A discrete variable v is initialized with \textbf{pre}(v). + A discrete variable \lstinline!v! is initialized with \lstinline!pre(v)!. \item If at least one element of an array appears on the left hand side of the assignment operator, then the complete array is initialized in From 89074590237de5da1d896c93bb5461a3f35312f3 Mon Sep 17 00:00:00 2001 From: Henrik Tidefelt Date: Wed, 3 Jun 2020 01:02:40 +0200 Subject: [PATCH 21/78] Don't use text escape with \textbf inside lstlisting The use of boldface was inconsistent with the rest of the listing anyway. --- chapters/stream.tex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/chapters/stream.tex b/chapters/stream.tex index 6dd11d3c2..f2654194a 100644 --- a/chapters/stream.tex +++ b/chapters/stream.tex @@ -331,7 +331,7 @@ \section{Stream Operator inStream and Connection Equations}\doublelabel{stream-o \end{lstlisting} More sophisticated implementation, with smooth approximation, applied only when {all} flows are small: \begin{lstlisting}[language=modelica,escapechar=!,mathescape=true] -// Define a "small number" eps (!\textbf{nominal}!(v) is the nominal value of v !--! see !\autoref{attributes-start-fixed-nominal-and-unbounded}!) +// Define a "small number" eps (nominal(v) is the nominal value of v -- see !\autoref{attributes-start-fixed-nominal-and-unbounded}!) eps := relativeTolerance*min(nominal($m_j$.c.m_flow)); // Define a smooth curve, such that alpha($s_i>=eps$)=1 and alpha($s_i<0$)=0 From d00b7cd0262d24c4538b4f10b3b55580f88e5a14 Mon Sep 17 00:00:00 2001 From: Henrik Tidefelt Date: Wed, 3 Jun 2020 01:03:12 +0200 Subject: [PATCH 22/78] Minor cleanup of ellipsis --- chapters/stream.tex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/chapters/stream.tex b/chapters/stream.tex index f2654194a..4ead7e322 100644 --- a/chapters/stream.tex +++ b/chapters/stream.tex @@ -413,7 +413,7 @@ \section{Stream Operator actualStream}\doublelabel{stream-operator-actualstream} In the case of equation (1), although \lstinline!actualStream! is discontinuous, the product with the flow variable is not, because \lstinline!actualStream! is discontinuous when the flow is zero by construction. -Therefore, a tool might infer that the expression is \lstinline!smooth(0, ...)! +Therefore, a tool might infer that the expression is \lstinline[mathescape=true]!smooth(0, $\ldots$)! automatically, and decide whether or not to generate an event. If a user wants to avoid events entirely, he/she may enclose the right-hand side of (1) with \lstinline!noEvent!. From 35874f62c01d26ca1679197baf9c627fb0ef4553 Mon Sep 17 00:00:00 2001 From: Henrik Tidefelt Date: Wed, 3 Jun 2020 21:29:42 +0200 Subject: [PATCH 23/78] Minor style improvement inside code listing comment --- chapters/stream.tex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/chapters/stream.tex b/chapters/stream.tex index 4ead7e322..49a5cf01f 100644 --- a/chapters/stream.tex +++ b/chapters/stream.tex @@ -331,7 +331,7 @@ \section{Stream Operator inStream and Connection Equations}\doublelabel{stream-o \end{lstlisting} More sophisticated implementation, with smooth approximation, applied only when {all} flows are small: \begin{lstlisting}[language=modelica,escapechar=!,mathescape=true] -// Define a "small number" eps (nominal(v) is the nominal value of v -- see !\autoref{attributes-start-fixed-nominal-and-unbounded}!) +// Define a "small number" eps (nominal(v) is the nominal value of v - see !\autoref{attributes-start-fixed-nominal-and-unbounded}!) eps := relativeTolerance*min(nominal($m_j$.c.m_flow)); // Define a smooth curve, such that alpha($s_i>=eps$)=1 and alpha($s_i<0$)=0 From 7d466da33a980dfdfd3acfd4137160471995c744 Mon Sep 17 00:00:00 2001 From: Henrik Tidefelt Date: Wed, 3 Jun 2020 21:32:50 +0200 Subject: [PATCH 24/78] Customize 'description' environment so that \item style can replace direct use of \textbf --- chapters/synchronous.tex | 14 +++++--------- preamble.tex | 9 +++++++++ 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/chapters/synchronous.tex b/chapters/synchronous.tex index e7b4c9a63..eac229067 100644 --- a/chapters/synchronous.tex +++ b/chapters/synchronous.tex @@ -277,8 +277,7 @@ \subsection{Argument Restrictions (Component Expression)}\doublelabel{argument-r not present for Modelica functions. To define the restrictions, the following term is defined: \begin{description} -\item{\textbf{Component expression}:} -\par +\item[Component expression:] A Component Reference which is an Expression, i.e. does not refer to models or blocks with equations. It is an instance of a (a) base type, (b) derived type, (c) record, (d) an array of such an instance (a-c), @@ -296,8 +295,7 @@ \subsection{Argument Restrictions (Component Expression)}\doublelabel{argument-r % This should ideally be a set of definitions instead \begin{description} -\item{The input argument is a \textbf{component expression}:} -\par +\item[The input argument is a \emph{component expression}:] The meaning is that the input argument when calling the operator must be a \emph{component expression}. \begin{nonnormative} @@ -305,7 +303,6 @@ \subsection{Argument Restrictions (Component Expression)}\doublelabel{argument-r possible for a general expression. \end{nonnormative} \begin{example} - \end{example} \begin{lstlisting}[language=modelica] Real u1; Real u2[4]; @@ -319,8 +316,8 @@ \subsection{Argument Restrictions (Component Expression)}\doublelabel{argument-r y5 = previous(2*u); // error (general expression, no Component Expression) y6 = previous(R); // error (component, no Component Expression) \end{lstlisting} -\item{The input argument is a \textbf{parameter expression}:} -\par + \end{example} +\item[The input argument is a \emph{parameter expression}:] The meaning is that the input argument when calling the operator must have parameter variability, that is the argument must depend directly or indirectly only on parameters, constants or literals, see @@ -338,8 +335,7 @@ \subsection{Argument Restrictions (Component Expression)}\doublelabel{argument-r y3 = subSample(u, factor=3*u); // error (general expression) \end{lstlisting} \end{example} -\item{The input argument is an \textbf{expression}:} -\par +\item[The input argument is an \emph{expression}:] There is no restriction on the input argument when calling the operator. This notation is used to emphasis when a standard function call is used (is an \emph{expression}), instead of restricting the input diff --git a/preamble.tex b/preamble.tex index ac5651c19..30ba54d64 100644 --- a/preamble.tex +++ b/preamble.tex @@ -71,6 +71,7 @@ \usepackage{longtable} \usepackage{multirow} % for multirow entries in tables \usepackage{listings} +\usepackage{enumitem} \usepackage{color} \usepackage[table]{xcolor} %\def\doublelabel#1{\label{#1}\hypertarget{#1}{}} @@ -289,6 +290,14 @@ \def\paragraphautorefname{section} \def\subparagraphautorefname{section} +% Make all description lists break the line after each key. +\setlist[description]{ + style=nextline, + labelwidth=0pt, + leftmargin=15pt, + itemindent=\dimexpr-5pt-\labelsep\relax, +} + \title{ \ifpdf \begin{center} From 1d34f0e29b1bbb50eb9b1038b9142d4455954886 Mon Sep 17 00:00:00 2001 From: Henrik Tidefelt Date: Wed, 3 Jun 2020 21:36:52 +0200 Subject: [PATCH 25/78] Remove unnecessary use of \textbf for itemize items Since most of these should use math, it also looks better if none of the items use boldface. --- chapters/stream.tex | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/chapters/stream.tex b/chapters/stream.tex index 49a5cf01f..5ba7b5896 100644 --- a/chapters/stream.tex +++ b/chapters/stream.tex @@ -248,33 +248,28 @@ \section{Stream Operator inStream and Connection Equations}\doublelabel{stream-o \begin{nonnormative} Based on the above requirements, the following implementation is recommended: \begin{itemize} -% This shouldn't be an itemized list, but a list of definitions -% faking that by using raggedright -\raggedright -\item \textbf{N = 1, M = 0:}\newline +\item $N = 1,\, M = 0$:\hfill \begin{lstlisting}[language=modelica,mathescape=true] inStream($m_1$.c.h_outflow) = $m_1$.c.h_outflow; \end{lstlisting} -\item -\textbf{N = 2, M = 0:}\newline +\item $N = 2,\, M = 0$:\hfill \begin{lstlisting}[language=modelica,mathescape=true] inStream($m_1$.c.h_outflow) = $m_2$.c.h_outflow; inStream($m_2$.c.h_outflow) = $m_1$.c.h_outflow; \end{lstlisting} -\item \textbf{N = 1, M = 1:}\newline +\item $N = 1,\, M = 1$:\hfill \begin{lstlisting}[language=modelica,mathescape=true] inStream($m_1$.c.h_outflow) = inStream($c_1$.h_outflow); // Additional equation to be generated $c_1$.h_outflow = $m_1$.c.h_outflow; \end{lstlisting} -\item \textbf{N = 0, M = 2:}\newline +\item $N = 0,\, M = 2$:\hfill \begin{lstlisting}[language=modelica,mathescape=true] // Additional equation to be generated $c_{1}$.h_outflow = inStream($c_{2}$.h_outflow); $c_{2}$.h_outflow = inStream($c_{1}$.h_outflow); \end{lstlisting} - -\item\textbf{All other cases:}\newline +\item All other cases:\hfill \begin{lstlisting}[language=modelica,mathescape=true] if $m_j$.c.m_flow.min >= 0 for all j = 1:N with j <> i and $c_k$.m_flow.max <= 0 for all k = 1:M @@ -345,8 +340,8 @@ \section{Stream Operator inStream and Connection Equations}\doublelabel{stream-o \end{lstlisting} The derivation of this implementation is discussed in -\autoref{derivation-of-stream-equations}. Note that in the cases N = 1, M =0 (unconnected port, -physically corresponding to a plugged-up flange), and N = 2, M=0 +\autoref{derivation-of-stream-equations}. Note that in the cases $N = 1,\, M = 0$ (unconnected port, +physically corresponding to a plugged-up flange), and $N = 2,\, M = 0$ (one-to-one connection), the result of \lstinline!inStream! is trivial and no non-linear equations are left in the model, despite the fact that the original definition equations are nonlinear. From f3efe1fe86616966371b2e8938431eae7b8771a1 Mon Sep 17 00:00:00 2001 From: Henrik Tidefelt Date: Wed, 3 Jun 2020 21:55:56 +0200 Subject: [PATCH 26/78] Fix formatting of definition of 'cat' --- chapters/arrays.tex | 29 +++++++++++++---------------- 1 file changed, 13 insertions(+), 16 deletions(-) diff --git a/chapters/arrays.tex b/chapters/arrays.tex index fe84e3889..23f3739b6 100644 --- a/chapters/arrays.tex +++ b/chapters/arrays.tex @@ -633,28 +633,25 @@ \subsubsection{Array Constructor with Several Iterators}\doublelabel{array-const \subsection{Array Concatenation}\doublelabel{array-concatenation} - -The function \lstinline!cat(k,A,B,C,...)! concatenates arrays -\lstinline!A!,\lstinline!B!,\lstinline!C!,... along -dimension k according to the following rules: +The function \lstinline[mathescape=true]!cat($k$, A, B, C, $\ldots$)! concatenates arrays +\lstinline!A!, \lstinline!B!, \lstinline!C!, \ldots along +dimension $k$ according to the following rules: \begin{itemize} \item - Arrays A, B, C, ... must have the same number of dimensions, i.e., - \lstinline!ndims(A)! = \lstinline!ndims(B)! = ... + Arrays \lstinline!A!, \lstinline!B!, \lstinline!C!, \ldots must have the same number of dimensions, i.e., + \lstinline!ndims(A)! = \lstinline!ndims(B)! = \ldots \item - Arrays A, B, C, ... must be type compatible expressions (\autoref{type-compatible-expressions}) + Arrays \lstinline!A!, \lstinline!B!, \lstinline!C!, \ldots must be type compatible expressions (\autoref{type-compatible-expressions}) giving the type of the elements of the result. The maximally expanded - types should be equivalent. Real and Integer subtypes can be mixed - resulting in a Real result array where the Integer numbers have been - transformed to Real numbers. + types should be equivalent. \lstinline!Real! and \lstinline!Integer! subtypes can be mixed + resulting in a \lstinline!Real! result array where the \lstinline!Integer! numbers have been + transformed to \lstinline!Real! numbers. \item - k has to characterize an existing dimension, i.e., 1 $<=$ k - $<=$ \lstinline!ndims(A)! = \lstinline!ndims(B)! = \lstinline!ndims(C)!; k shall be a parameter expression of \lstinline!Integer! type. + $k$ has to characterize an existing dimension, i.e., $1 \leq k \leq \text{\lstinline!ndims(A)!} = \text{\lstinline!ndims(B)!} = \text{\lstinline!ndims(C)!}$; $k$ shall be a parameter expression of \lstinline!Integer! type. \item - Size matching: Arrays A, B, C, ... must have identical array sizes - with the exception of the size of dimension k, i.e., \lstinline!size(A,j)! = - \lstinline!size(B,j)!, for 1 $<=$ j $<=$ \lstinline!ndims(A)! and j - $\neq$ k. + Size matching: Arrays \lstinline!A!, \lstinline!B!, \lstinline!C!, \ldots must have identical array sizes + with the exception of the size of dimension $k$, i.e., \lstinline!size(A,j)! = + \lstinline!size(B,j)!, for $1 \leq j \leq \text{\lstinline!ndims(A)!}$ and $j \neq k$. \end{itemize} \begin{example} From e9a451cb34f87aec3faf7b203c46ce37642e9753 Mon Sep 17 00:00:00 2001 From: Henrik Tidefelt Date: Wed, 3 Jun 2020 21:57:25 +0200 Subject: [PATCH 27/78] Fix latexml issue with \neq in \lstinline math --- chapters/stream.tex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/chapters/stream.tex b/chapters/stream.tex index 5ba7b5896..8c444341b 100644 --- a/chapters/stream.tex +++ b/chapters/stream.tex @@ -365,7 +365,7 @@ \section{Stream Operator inStream and Connection Equations}\doublelabel{stream-o \item If all flows are zero, \lstinline[mathescape=true]!inStream($m_{i}$.c.h_outflow)! = - \lstinline[mathescape=true]!sum($m_{j}$.c.h_outflow for $j \neq i$ and $m_{j}$.c.m_flow.min < 0) / $N_{\mathrm{p}}$!, + \lstinline[mathescape=true]!sum($m_{j}$.c.h_outflow for $j \neq{} i$ and $m_{j}$.c.m_flow.min < 0) / $N_{\mathrm{p}}$!, i.e., it is the mean value of all the $N_{\mathrm{p}}$ variables \lstinline[mathescape=true]!$m_{j}$.c.h_outflow!, such that $j \neq i$ and $m_{j}\text{\lstinline!.c.m_flow.min!} < 0$. This is a From 29aec56205104416f2d4e321641bc699182f898e Mon Sep 17 00:00:00 2001 From: Henrik Tidefelt Date: Wed, 3 Jun 2020 21:59:28 +0200 Subject: [PATCH 28/78] Replace \textbf with \firstuse when making definitions for 'Protection' annotation --- chapters/annotations.tex | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/chapters/annotations.tex b/chapters/annotations.tex index 067e7d4eb..ebdda0f3b 100644 --- a/chapters/annotations.tex +++ b/chapters/annotations.tex @@ -1891,22 +1891,22 @@ \section{Annotations for Access Control to Protect Intellectual Property}\double different encryption formats. \end{nonnormative} -\textbf{Definitions:} +Definitions: \begin{longtable}[]{|p{2.5cm}|p{12cm}|} \hline \tablehead{Term} & \tablehead{Description}\\ \hline \endhead -\textbf{Protection} & Define what parts of a class are visible.\\ +\firstuse{Protection} & Define what parts of a class are visible.\\ \hline -\textbf{Obfuscation} & Changing a Modelica class or generated code so that it is difficult to inspect by a user +\firstuse{Obfuscation} & Changing a Modelica class or generated code so that it is difficult to inspect by a user (e.g. by automatically renaming variables to non-meaningful names).\\ \hline -\textbf{Encryption} & Encoding of a model or a package in a form so that +\firstuse{Encryption} & Encoding of a model or a package in a form so that the modeler cannot inspect any content of a class without an appropriate key. An encrypted package that has the \lstinline!Protection! annotation is read-only; the way to modify it is to generate a new encrypted version.\\ \hline -\textbf{Licensing} & Restrict the use of an encrypted package for particular users for a specified period of time.\\ +\firstuse{Licensing} & Restrict the use of an encrypted package for particular users for a specified period of time.\\ \hline \end{longtable} From b984de68bb5270ae81a2466e7dee6e9eacf08d69 Mon Sep 17 00:00:00 2001 From: Henrik Tidefelt Date: Wed, 3 Jun 2020 22:06:06 +0200 Subject: [PATCH 29/78] Remove unused one-off arguments to lstlisting, including emphstyle=\textbf --- chapters/annotations.tex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/chapters/annotations.tex b/chapters/annotations.tex index ebdda0f3b..766e4d302 100644 --- a/chapters/annotations.tex +++ b/chapters/annotations.tex @@ -665,7 +665,7 @@ \subsection{Connections}\doublelabel{connections1} connection line. It has the following definition (\emph{it is not equal to the Text-primitive as part of graphics -- the differences are marked as bold lines}): % NOTE: Technically just the names - not the entire lines are marked in bold -\begin{lstlisting}[language=modelica,escapechar=!,emph={horizontalAlignment,string,index}, emphstyle=\textbf] +\begin{lstlisting}[language=modelica] record Text extends GraphicItem; extends FilledShape; From a7903213032d25a506555924798ebf60873dff41 Mon Sep 17 00:00:00 2001 From: Henrik Tidefelt Date: Wed, 3 Jun 2020 22:22:48 +0200 Subject: [PATCH 30/78] Remove some misplaced paragraph breaks right before itemize environments --- chapters/revisions.tex | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/chapters/revisions.tex b/chapters/revisions.tex index 9f51453b0..f3b563471 100644 --- a/chapters/revisions.tex +++ b/chapters/revisions.tex @@ -722,7 +722,6 @@ \subsection{Main changes in Modelica 3.3}\doublelabel{main-changes-in-modelica-3 Multiple definition import, \autoref{importing-definitions-from-a-package}. \item Additional annotations allowing: - \begin{itemize} \item Functions to generate events, \autoref{annotations-for-code-generation}. @@ -1187,7 +1186,6 @@ \subsection{Main changes in Modelica 3.2}\doublelabel{main-changes-in-modelica-3 Functions as formal inputs to functions (see new \autoref{functional-input-arguments-to-functions}). \item Overloaded operators have been refined (see \autoref{overloaded-operators}): - \begin{itemize} \item A new specialized class \lstinline!operator record! is introduced -- with @@ -1226,7 +1224,6 @@ \subsection{Main changes in Modelica 3.2}\doublelabel{main-changes-in-modelica-3 simplify message formatting in external functions (see \autoref{utility-functions}) \item Additional annotations allowing: - \begin{itemize} \item Inclusion of C-header and object library files in packages and @@ -1493,7 +1490,6 @@ \subsection{Main changes in Modelica 3.1}\doublelabel{main-changes-in-modelica-3 \lstinline!transformation!, as was originally the intention. \item The Connection set section was rewritten: - \begin{itemize} \item Connection set is clearly defined including examples. @@ -1858,7 +1854,6 @@ \subsection{Main Changes in Modelica 3.0}\doublelabel{main-changes-in-modelica-3 The following changes in the Modelica 3.0 graphical annotations are also \textbf{not backwards compatible:} - \begin{itemize} \item Changed the definition of icon placement (record Transformation), so @@ -2212,7 +2207,6 @@ \subsection{Main Changes in Modelica 2.0}\doublelabel{main-changes-in-modelica-2 A detailed description of the enhancements introduced by Modelica 2.0 is given in the papers - \begin{itemize} \item M. Otter, H. Olsson: New Features in Modelica 2.0. 2nd International @@ -2483,7 +2477,6 @@ \subsection{Contributors up to Modelica 1.3}\doublelabel{contributors-up-to-mode \subsection{Main Changes in Modelica 1.3}\doublelabel{main-changes-in-modelica-1-3} Modelica 1.3 was released December 15, 1999. - \begin{itemize} \item Defined connection semantics for \lstinline!inner!/\lstinline!outer! connectors. @@ -2498,8 +2491,8 @@ \subsection{Main Changes in Modelica 1.3}\doublelabel{main-changes-in-modelica-1 \end{itemize} \subsection{Main Changes in Modelica 1.2}\doublelabel{main-changes-in-modelica-1-2} -Modelica 1.2 was released June 15, 1999. +Modelica 1.2 was released June 15, 1999. \begin{itemize} \item Changed the external function interface to give greater flexibility. From b9bbf289150b239905df32ea8579539aa03998d4 Mon Sep 17 00:00:00 2001 From: Henrik Tidefelt Date: Wed, 3 Jun 2020 22:24:01 +0200 Subject: [PATCH 31/78] Avoid use of \textbf in revisions.tex, using some \emph instead --- chapters/revisions.tex | 33 +++++++++++---------------------- 1 file changed, 11 insertions(+), 22 deletions(-) diff --git a/chapters/revisions.tex b/chapters/revisions.tex index f3b563471..d4d5bce7e 100644 --- a/chapters/revisions.tex +++ b/chapters/revisions.tex @@ -689,8 +689,7 @@ \section{Modelica 3.3}\doublelabel{modelica-3-3} \subsection{Main changes in Modelica 3.3}\doublelabel{main-changes-in-modelica-3-3} -The following \textbf{backward compatible extensions} have been -introduced with Modelica 3.3: +The following \emph{backward compatible extensions} have been introduced with Modelica 3.3: \begin{itemize} \item Language elements for describing synchronous behavior suited for @@ -743,8 +742,7 @@ \subsection{Main changes in Modelica 3.3}\doublelabel{main-changes-in-modelica-3 \end{itemize} \end{itemize} -The following \textbf{changes} in Modelica 3.3 are \textbf{not} -\textbf{backwards compatible}: +The following changes in Modelica 3.3 are \emph{not} backwards compatible: \begin{itemize} \item \autonameref{synchronous-language-elements} from @@ -1176,8 +1174,7 @@ \section{Modelica 3.2}\doublelabel{modelica-3-2} \subsection{Main changes in Modelica 3.2}\doublelabel{main-changes-in-modelica-3-2} -The following \textbf{backward compatible extensions} have been -introduced with Modelica 3.2: +The following \emph{backward compatible extensions} have been introduced with Modelica 3.2: \begin{itemize} \item Homotopy function for making it easier to solve initialization @@ -1243,8 +1240,7 @@ \subsection{Main changes in Modelica 3.2}\doublelabel{main-changes-in-modelica-3 \end{itemize} \end{itemize} -The following \textbf{changes} in Modelica 3.2 are \textbf{not} -\textbf{backwards compatible}: +The following changes in Modelica 3.2 are \emph{not} backwards compatible: \begin{itemize} \item The new built-in operator name \lstinline!homotopy!. In rare cases this might @@ -1406,8 +1402,7 @@ \section{Modelica 3.1}\doublelabel{modelica-3-1} \subsection{Main changes in Modelica 3.1}\doublelabel{main-changes-in-modelica-3-1} -The following \textbf{backward compatible extensions} have been -introduced with Modelica 3.1: +The following \emph{backward compatible extensions} have been introduced with Modelica 3.1: \begin{itemize} \item Overloading of operators like \lstinline!'+'! or \lstinline!'*'! to allow convenient usage of @@ -1465,8 +1460,7 @@ \subsection{Main changes in Modelica 3.1}\doublelabel{main-changes-in-modelica-3 build is needed for a used library. \end{itemize} -The following \textbf{defects} have been \textbf{fixed} in the Modelica -specification: +The following defects have been fixed in the Modelica specification: \begin{itemize} \item Modifier with subscripts were previously allowed, but not clearly @@ -1522,8 +1516,7 @@ \subsection{Main changes in Modelica 3.1}\doublelabel{main-changes-in-modelica-3 meant. \end{itemize} -The following \textbf{changes} in Modelica 3.1 are not \textbf{backwards -compatible}: +The following changes in Modelica 3.1 are \emph{not} backwards compatible: \begin{itemize} \item A class-level annotation can only be placed before the end-statement. @@ -1801,8 +1794,7 @@ \subsection{Main Changes in Modelica 3.0}\doublelabel{main-changes-in-modelica-3 provide (semi-) automatic mechanisms for conversion of models and libraries. -The following main changes in Modelica 3.0 are \textbf{not backwards -compatible}: +The following main changes in Modelica 3.0 are \emph{not} backwards compatible: \begin{itemize} \item Restrictions to connectors (see \autoref{restrictions-of-connections-and-connectors}): For each non-partial @@ -1852,8 +1844,7 @@ \subsection{Main Changes in Modelica 3.0}\doublelabel{main-changes-in-modelica-3 removed. \end{itemize} -The following changes in the Modelica 3.0 graphical annotations are also -\textbf{not backwards compatible:} +The following changes in the Modelica 3.0 graphical annotations are also \emph{not} backwards compatible: \begin{itemize} \item Changed the definition of icon placement (record Transformation), so @@ -1868,8 +1859,7 @@ \subsection{Main Changes in Modelica 3.0}\doublelabel{main-changes-in-modelica-3 unit for fonts). \end{itemize} -The following main changes in Modelica 3.0 are \textbf{backwards -compatible}: +The following main changes in Modelica 3.0 are \emph{backwards compatible}: \begin{itemize} \item New element-wise operators: \lstinline!.+!, \lstinline!.-!, \lstinline!.*!, \lstinline!./!, \lstinline!.^!. @@ -1916,8 +1906,7 @@ \subsection{Main Changes in Modelica 3.0}\doublelabel{main-changes-in-modelica-3 interactively set the variable of a class during simulation. \end{itemize} -The following \textbf{errors} have been \textbf{fixed} in the Modelica -specification: +The following errors have been fixed in the Modelica specification: \begin{itemize} \item Syntax rule for a function call (e.g., according to the grammar in From 009ff7e63f6ba603e8fb7c292aa0ec58f163f4df Mon Sep 17 00:00:00 2001 From: Henrik Tidefelt Date: Wed, 3 Jun 2020 22:27:20 +0200 Subject: [PATCH 32/78] Use \emph rather than \textbf to put emphasis on 'not' --- chapters/annotations.tex | 2 +- chapters/synchronous.tex | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/chapters/annotations.tex b/chapters/annotations.tex index 766e4d302..43c7aefd8 100644 --- a/chapters/annotations.tex +++ b/chapters/annotations.tex @@ -1967,7 +1967,7 @@ \subsection{Protection of Classes}\doublelabel{protection-of-classes} the class, or part of the class, can be copied. \item \lstinline!Access.packageText!\\ - Same as \lstinline!Access.diagram! (note: \textbf{not} including all rights of + Same as \lstinline!Access.diagram! (note: \emph{not} including all rights of \lstinline!Access.nonPackageDuplicate!) and additionally the whole class definition can be accessed (but that text cannot be copied, i.e., you can see but not copy the source code). \item diff --git a/chapters/synchronous.tex b/chapters/synchronous.tex index eac229067..4bb0803f1 100644 --- a/chapters/synchronous.tex +++ b/chapters/synchronous.tex @@ -570,10 +570,10 @@ \section{Clock Constructors}\doublelabel{clock-constructors} \end{example} \item Clock variables can be declared in models, blocks, connectors, and - records,. A Clock variable can be declared with the prefixes - \textbf{input}, \textbf{output}, \textbf{inner}, \textbf{outer}, but - \textbf{not} with the prefixes \textbf{flow}, \textbf{stream}, - \textbf{discrete}, \textbf{parameter}, or \textbf{constant}. + records. A \lstinline!Clock! variable can be declared with the prefixes + \lstinline{input}, \lstinline{output}, \lstinline{inner}, \lstinline{outer}, but + \emph{not} with the prefixes \lstinline{flow}, \lstinline{stream}, + \lstinline{discrete}, \lstinline{parameter}, or \lstinline{constant}. \begin{example} \lstinline!connector ClockInput = input Clock;! \end{example} @@ -1220,7 +1220,7 @@ \subsection{Solver Methods}\doublelabel{solver-methods} a case, the solution method might be a variable step solver with step-size control that integrates between two clock ticks. The simulation environment might also combine all partitions associated with method \lstinline!"External"!, as well as all continuous-time partitions, and integrate them together with the solver selected by the simulation environment. \end{nonnormative} -If the solver method is \textbf{not} \lstinline!"External"!, then the partition is +If the solver method is \emph{not} \lstinline!"External"!, then the partition is integrated using the given method with the step-size \lstinline!interval()!. \begin{nonnormative} From 4c1b9cbc9e990e6e7e1d90a42a3230d668d16682 Mon Sep 17 00:00:00 2001 From: Henrik Tidefelt Date: Wed, 3 Jun 2020 22:58:54 +0200 Subject: [PATCH 33/78] Get rid of some redundant parentheses just filled with dots This is similar to how we simplified 'the der() operator' to just 'der'. --- chapters/annotations.tex | 4 +-- chapters/arrays.tex | 14 ++++---- chapters/classes.tex | 2 +- chapters/connectors.tex | 15 ++++----- chapters/equations.tex | 6 ++-- chapters/functions.tex | 13 ++++---- chapters/inheritance.tex | 6 ++-- chapters/introduction.tex | 2 +- chapters/operatorsandexpressions.tex | 6 ++-- chapters/overloaded.tex | 8 ++--- chapters/revisions.tex | 20 +++++------- chapters/statemachines.tex | 2 +- chapters/stream.tex | 4 +-- chapters/synchronous.tex | 49 ++++++++++++++-------------- 14 files changed, 75 insertions(+), 76 deletions(-) diff --git a/chapters/annotations.tex b/chapters/annotations.tex index 43c7aefd8..fbcd4b4ae 100644 --- a/chapters/annotations.tex +++ b/chapters/annotations.tex @@ -1914,8 +1914,8 @@ \section{Annotations for Access Control to Protect Intellectual Property}\double licensing. Obfuscation and encryption are not standardized. protection and licensing are both defined inside the \lstinline!Protection! annotation: -\begin{lstlisting}[language=modelica] -annotation(Protection(...)); +\begin{lstlisting}[language=modelica,mathescape=true] +annotation(Protection($\ldots$)); \end{lstlisting} \subsection{Protection of Classes}\doublelabel{protection-of-classes} diff --git a/chapters/arrays.tex b/chapters/arrays.tex index 23f3739b6..77c055835 100644 --- a/chapters/arrays.tex +++ b/chapters/arrays.tex @@ -472,15 +472,17 @@ \subsubsection{Reduction Expressions}\doublelabel{reduction-expressions} \hline \tablehead{Function-name} & \tablehead{Restriction on expression1} & \tablehead{Result if expression2 is empty}\\ \hline \endhead -\lstinline!sum! & Integer or Real & \lstinline!zeros(...)!\\ \hline -\lstinline!product! & Scalar Integer or Real & \lstinline!1!\\ \hline -\lstinline!min! & Scalar enumeration, Boolean, Integer or Real & +\lstinline!sum! & \lstinline!Integer! or \lstinline!Real! & \lstinline[mathescape=true]!zeros($\ldots$)!\\ \hline +\lstinline!product! & Scalar \lstinline!Integer! or \lstinline!Real! & \lstinline!1!\\ \hline +\lstinline!min! & Scalar enumeration, \lstinline!Boolean!, \lstinline!Integer! or \lstinline!Real! & \begin{tabular}{@{}p{6cm}@{}} -Greatest value of type\\( \lstinline!Modelica.Constants.inf! for Real) +Greatest value of type\\ +(\lstinline!Modelica.Constants.inf! for \lstinline!Real!) \end{tabular}\\ \hline -\lstinline!max! & Scalar enumeration, Boolean, Integer or Real & +\lstinline!max! & Scalar enumeration, \lstinline!Boolean!, \lstinline!Integer! or \lstinline!Real! & \begin{tabular}{@{}p{6cm}@{}} -Least value of type\\ ( \lstinline!-Modelica.Constants.inf! for Real) +Least value of type\\ +(\lstinline!-Modelica.Constants.inf! for \lstinline!Real!) \end{tabular}\\ \hline \end{longtable} diff --git a/chapters/classes.tex b/chapters/classes.tex index 4499ff789..37f57c53c 100644 --- a/chapters/classes.tex +++ b/chapters/classes.tex @@ -837,7 +837,7 @@ \section{Specialized Classes}\doublelabel{specialized-classes} components (i.e., equation, algorithm, initial equation, initial algorithm and protected sections are not allowed). -Enhanced to allow \lstinline!connect!(..) to components of connector classes. The +Enhanced to allow \lstinline!connect! to components of connector classes. The elements of a connector may not have prefixes \lstinline!inner!, or \lstinline!outer.! May only contain components of specialized class connector, record and type.\\ \hline diff --git a/chapters/connectors.tex b/chapters/connectors.tex index 72886df9d..e769ba89d 100644 --- a/chapters/connectors.tex +++ b/chapters/connectors.tex @@ -820,7 +820,7 @@ \section{Equation Operators for Overconstrained Connection-Based Equation System \subsection{Overconstrained Equation Operators for Connection Graphs}\doublelabel{overconstrained-equation-operators-for-connection-graphs} A type or record declaration may have an optional definition of function -\lstinline!equalityConstraint(..)! that shall have the following prototype: +\lstinline!equalityConstraint! that shall have the following prototype: \begin{lstlisting}[language=modelica] type Type // overdetermined type extends ; @@ -851,8 +851,7 @@ \subsection{Overconstrained Equation Operators for Connection Graphs}\doublelabe \lstinline!R2!, respectively, with a non-redundant number $n \ge 0$ of equations. The residues of these equations are returned in vector \lstinline!residue! of size $n$. The set of n non-redundant equations stating that \lstinline!R1 = R2! is given by -the equation (\textbf{0} characterizes a vector of zeros of appropriate -size): +the equation (\lstinline!0! represents a vector of zeros of appropriate size): \begin{lstlisting}[language=modelica] Record R1, R2; equation @@ -876,13 +875,13 @@ \subsection{Overconstrained Equation Operators for Connection Graphs}\doublelabe connector is a node in a virtual connection graph that is used to determine when the standard equation \lstinline!R1 = R2! or when the equation \lstinline!0 = equalityConstraint(R1, R2)! has to be used for the generation of -\lstinline!connect(...)! equations. The edges of the virtual connection graph are -implicitly defined by \lstinline!connect(..)! and explicitly by -\lstinline!Connections.branch(...)! statements, see table below. \lstinline!Connections! is a +\lstinline!connect! equations. The edges of the virtual connection graph are +implicitly defined by \lstinline!connect! and explicitly by +\lstinline!Connections.branch! statements, see table below. \lstinline!Connections! is a built-in package in global scope containing built-in operators. Additionally, corresponding nodes of the virtual connection graph have to be defined as roots or as potential roots with functions -\lstinline!Connections.root(...)! and \lstinline!Connections.potentialRoot(...)!, respectively. +\lstinline!Connections.root! and \lstinline!Connections.potentialRoot!, respectively. In the following table, \lstinline!A! and \lstinline!B! are connector instances that may be hierarchically structured, e.g., \lstinline!A! may be an abbreviation for \lstinline!EnginePort.Frame!. @@ -965,7 +964,7 @@ \subsection{Overconstrained Equation Operators for Connection Graphs}\doublelabe \subsection{Converting the Connection Graph into Trees and Generating Connection Equations}\doublelabel{converting-the-connection-graph-into-trees-and-generating-connection-equations} -Before \lstinline!connect(...)! equations are generated, the virtual connection +Before \lstinline!connect! equations are generated, the virtual connection graph is transformed into a set of spanning trees by removing optional spanning tree edges from the graph. This is performed in the following way: \begin{enumerate} diff --git a/chapters/equations.tex b/chapters/equations.tex index 6f6d6bb7f..780adfd32 100644 --- a/chapters/equations.tex +++ b/chapters/equations.tex @@ -490,7 +490,7 @@ \subsection{assert}\doublelabel{assert} \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 + reaching the stop-time or explicitly with \lstinline!terminate!, but the evaluation with \lstinline!terminal()=true! triggers an assert, the analysis failed. \item @@ -519,14 +519,14 @@ \subsection{assert}\doublelabel{assert} 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 > 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} \end{nonnormative} \subsection{terminate}\doublelabel{terminate} -The \lstinline!terminate(...)! equation or statement (using function +The \lstinline!terminate! equation or statement (using function syntax) successfully terminates the analysis which was carried out, see also \autoref{assert}. The termination is not immediate at the place where it is defined since not all variable results might be available diff --git a/chapters/functions.tex b/chapters/functions.tex index 13d68f2db..0af705a57 100644 --- a/chapters/functions.tex +++ b/chapters/functions.tex @@ -16,11 +16,11 @@ \section{Function Declaration}\doublelabel{function-declaration} \begin{nonnormative} The structure of a typical function declaration is sketched by the following schematic function example: -\begin{lstlisting}[language=modelica,escapechar=!] +\begin{lstlisting}[language=modelica,mathescape=true,escapechar=!] function !\emph{functionname}! input TypeI1 in1; input TypeI2 in2; - input TypeI3 in3 = !\emph{default\_expr1}! "Comment" annotation(...); + input TypeI3 in3 = !\emph{default\_expr1}! "Comment" annotation($\ldots$); ... output TypeO1 out1; output TypeO2 out2 = !\emph{default\_expr2}!; @@ -318,7 +318,7 @@ \section{Pure Modelica Functions}\doublelabel{pure-modelica-functions} \item a when-statement, \item - \lstinline!pure(impureFunctionCall(...))! - which allows calling impure + \lstinline[mathescape=true]!pure(impureFunctionCall($\ldots$))! --- which allows calling impure functions in any pure context, \item in initial equations and initial algorithms, @@ -684,7 +684,7 @@ \subsection{Output Formal Parameters of Functions}\doublelabel{output-formal-par the equation or assignment shall contain a list of component references within parentheses: -\lstinline!(out1, out2, out3) = f(...);! +\lstinline[mathescape=true]!(out1, out2, out3) = f($\ldots$);! The component references are associated with the output components according to their position in the list. Thus output component i is set @@ -2517,7 +2517,7 @@ \subsubsection{Utility Functions for Allocating Strings}\doublelabel{utility-fun \begin{nonnormative} Memory that is not passed to the Modelica simulation environment, such as memory that is freed before leaving the function, or in an \lstinline!ExternalObject!, -see~\autoref{external-objects}, should be allocated with the standard C-mechanisms, like \lstinline[language=C]!calloc(..)!. +see~\autoref{external-objects}, should be allocated with the standard C-mechanisms, like \lstinline[language=C]!calloc!. \end{nonnormative} \begin{nonnormative} @@ -2554,8 +2554,7 @@ \subsection{External Objects}\doublelabel{external-objects} must not require any other calls to be made for the initialization to be complete (e.g., from an initial algorithm or initial equation). The destructor shall delete the object, and must not require any other - calls to be made for the deletion to be complete (e.g., from a 'when - terminal()' clause). The constructor may not assume that pointers sent + calls to be made for the deletion to be complete (e.g., from a \lstinline!when terminal()! clause). The constructor may not assume that pointers sent to the external object will remain valid for the life-time of the external object. \begin{nonnormative} diff --git a/chapters/inheritance.tex b/chapters/inheritance.tex index 46b95e0f3..0418365f8 100644 --- a/chapters/inheritance.tex +++ b/chapters/inheritance.tex @@ -685,12 +685,12 @@ \section{Redeclaration}\doublelabel{redeclaration} \subsection{The class extends Redeclaration Mechanism}\doublelabel{the-class-extends-redeclaration-mechanism} -A class declaration of the type \lstinline!redeclare class extends B(...)! , +A class declaration of the type \lstinline[mathescape=true]!redeclare class extends B($\ldots$)! , where \lstinline!class! as usual can be replaced by any other specialized class, replaces the inherited class \lstinline!B! with another declaration that extends the inherited class where the optional class-modification is applied to the inherited class. Inherited \lstinline!B! here means that the class -containing \lstinline!redeclare class extends B(...)! should also inherit +containing \lstinline[mathescape=true]!redeclare class extends B($\ldots$)! should also inherit another declaration of \lstinline!B! from one of its extends-clauses. The new declaration should explicitly include redeclare. @@ -699,7 +699,7 @@ \subsection{The class extends Redeclaration Mechanism}\doublelabel{the-class-ext to apply modifiers to the new declaration. \end{nonnormative} -For \lstinline!redeclare class extends B(...)! the inherited class is subject +For \lstinline[mathescape=true]!redeclare class extends B($\ldots$)! the inherited class is subject to the same restrictions as a redeclare of the inherited element, and the original class \lstinline!B! should be replaceable, and the new element is only replaceable if the new definition is replaceable. In contrast to normal diff --git a/chapters/introduction.tex b/chapters/introduction.tex index 14a4f8105..936199935 100644 --- a/chapters/introduction.tex +++ b/chapters/introduction.tex @@ -125,6 +125,6 @@ \section{Notation and Grammar}\doublelabel{notation-and-grammar} reserved words and may not be used as identifiers, with the exception of \lstinline!initial! which is a keyword in section headings, and \lstinline!der! which is a keyword for declaration functions, but it is also possible to call the -functions \lstinline!initial()! and \lstinline!der(...)!. +functions \lstinline!initial! and \lstinline!der!. See \autoref{modelica-concrete-syntax} for a full lexical specification and grammar. diff --git a/chapters/operatorsandexpressions.tex b/chapters/operatorsandexpressions.tex index 85fd8f706..c41a93e7d 100644 --- a/chapters/operatorsandexpressions.tex +++ b/chapters/operatorsandexpressions.tex @@ -742,8 +742,10 @@ \subsubsection{spatialDistribution}\doublelabel{spatialdistribution} vectorized outputs out0 and out1 of the same size; the arguments initialPoints and initialValues are vectorized accordingly. -The solution, z(..), can be described in terms of characteristics:\\ -$z(y+\int_t^{t+\beta}v(\alpha)d\alpha,t+\beta)=z(y,t),$ for all $\beta$ as long as staying inside the domain. +The solution, $z$, can be described in terms of characteristics: +\begin{equation*} +z(y+\int_{t}^{t+\beta} v(\alpha) \mathrm{d}\alpha, t+\beta) = z(y, t),\quad\text{for all $\beta$ as long as staying inside the domain} +\end{equation*} This allows to directly compute the solution based on interpolating the boundary conditions. diff --git a/chapters/overloaded.tex b/chapters/overloaded.tex index 3c21a80b8..b1a9bb636 100644 --- a/chapters/overloaded.tex +++ b/chapters/overloaded.tex @@ -538,15 +538,15 @@ \section{Example of Overloading for Complex Numbers}\doublelabel{example-of-over different operations; thus ComplexVoltage and ComplexCurrent still use the operations from Complex. The restriction that it is not legal to extend from any of its enclosing scopes implies that: -\begin{lstlisting}[language=modelica] +\begin{lstlisting}[language=modelica,mathescape=true] package A extends Icon; //Ok. - operator record B ... end B; + operator record B $\ldots$ end B; end A; package A2 - extends A(...); // Not legal + extends A($\ldots$); // Not legal end A2; - package A3=A(...); // Not legal + package A3=A($\ldots$); // Not legal \end{lstlisting} \end{example} diff --git a/chapters/revisions.tex b/chapters/revisions.tex index d4d5bce7e..26a4ee1f1 100644 --- a/chapters/revisions.tex +++ b/chapters/revisions.tex @@ -1830,8 +1830,8 @@ \subsection{Main Changes in Modelica 3.0}\doublelabel{main-changes-in-modelica-3 Prefixes \lstinline!input!, \lstinline!output!, \lstinline!inner!, \lstinline!outer!, \lstinline!flow! are not allowed in a record \item - The built-in operators \lstinline!abs(...)! and \lstinline!sign(...)! do no longer - generate events but are implicitly defined with a \lstinline!noEvent(...)! + The built-in operators \lstinline!abs! and \lstinline!sign! do no longer + generate events but are implicitly defined with a \lstinline!noEvent! operator. \item The constraining clause of a replaceable class or component is changed @@ -1840,8 +1840,7 @@ \subsection{Main Changes in Modelica 3.0}\doublelabel{main-changes-in-modelica-3 model must inherit from the constraining class, but this is not the case). \item - The \lstinline!isPresent!(...) construct, which was not implemented in tools, was - removed. + The \lstinline!isPresent! construct, which was not implemented in tools, was removed. \end{itemize} The following changes in the Modelica 3.0 graphical annotations are also \emph{not} backwards compatible: @@ -1899,8 +1898,7 @@ \subsection{Main Changes in Modelica 3.0}\doublelabel{main-changes-in-modelica-3 \item New annotations for schematic animation and interactive user input in \autoref{annotations-for-graphical-objects}:\\ - \lstinline!DynamicSelect!(..) to modify annotation literals by the actual values - of variables.\\ + \lstinline!DynamicSelect! to modify annotation literals by the actual values of variables.\\ \lstinline!OnMouseDownSetBoolean!, \lstinline!OnMouseUpSetBoolean!, \lstinline!OnMouseMoveXSetReal!, \lstinline!OnMouseMoveYSetReal!, \lstinline!OnMouseDownEditReal!, \lstinline!OnMouseDownEditString! to interactively set the variable of a class during simulation. @@ -1911,7 +1909,7 @@ \subsection{Main Changes in Modelica 3.0}\doublelabel{main-changes-in-modelica-3 \item Syntax rule for a function call (e.g., according to the grammar in Modelica 2.2 a function call of the form - \lstinline!Modelica.Math.Matrices.eig(...)! was invalid because the function name + \lstinline[mathescape=true]!Modelica.Math.Matrices.eig($\ldots$)! was invalid because the function name could not have `\lstinline!.!'. However, all Modelica tools supported the desired ``full Modelica name'' also for function calls). \end{itemize} @@ -2086,7 +2084,7 @@ \subsection{Main Changes in Modelica 2.1}\doublelabel{main-changes-in-modelica-2 \item Optional output arguments of Modelica functions. The presence of actual input and/or output arguments can be inquired with the new - built-in function \lstinline!isPresent(..)!. The previous built-in function and + built-in function \lstinline!isPresent!. The previous built-in function and attribute \lstinline!enable! was removed. \item Making the default constraining type more useful by inheriting the @@ -2104,13 +2102,13 @@ \subsection{Main Changes in Modelica 2.1}\doublelabel{main-changes-in-modelica-2 \item Statement \lstinline!return! in a Modelica function. \item - Built-in function \lstinline!String(..)! to provide a string representation of + Built-in function \lstinline!String! to provide a string representation of \lstinline!Boolean!, \lstinline!Integer!, \lstinline!Real! and \lstinline!Enumeration! types. \item - Built-in function \lstinline!Integer(..)! to provide the \lstinline!Integer! representation of + Built-in function \lstinline!Integer! to provide the \lstinline!Integer! representation of an \lstinline!Enumeration! type. \item - Built-in function \lstinline!semiLinear(..)! to define a characteristics with two + Built-in function \lstinline!semiLinear! to define a characteristics with two slopes and a set of rules for symbolic transformations, especially when the function becomes underdetermined (this function is used in the Modelica Fluid library under development to define reversing flow diff --git a/chapters/statemachines.tex b/chapters/statemachines.tex index 4f18b98e5..e922b02fc 100644 --- a/chapters/statemachines.tex +++ b/chapters/statemachines.tex @@ -31,7 +31,7 @@ \chapter{State Machines}\doublelabel{state-machines} For this reason, the state machines in this chapter use \emph{immediate} (= the same as \emph{strong}) and \emph{delayed} transitions. Delayed transitions are \emph{immediate} transitions where the condition is - automatically delayed with an implicit \lstinline!previous(..)!. + automatically delayed with an implicit \lstinline!previous!. \item Parallel state machines can be explicitly synchronized with a language element (similarly as parallel branches in Sequential diff --git a/chapters/stream.tex b/chapters/stream.tex index 8c444341b..717b6e3fc 100644 --- a/chapters/stream.tex +++ b/chapters/stream.tex @@ -225,7 +225,7 @@ \section{Stream Operator inStream and Connection Equations}\doublelabel{stream-o approximate the solution in an open neighbourhood of that point. \begin{nonnormative} -For example, assume that \lstinline[mathescape=true]!$m_{j}$.c.m_flow = $c_{k}$.m_flow = 0!, then all equations above are identically fulfilled and \lstinline!inStream(..)! can have any value. +For example, assume that \lstinline[mathescape=true]!$m_{j}$.c.m_flow = $c_{k}$.m_flow = 0!, then all equations above are identically fulfilled and \lstinline!inStream! can have any value. \end{nonnormative} However, specific optimizations may be applied to avoid the regularization if the flow through one port is zero or non-negative, see \autoref{derivation-of-stream-equations}. @@ -349,7 +349,7 @@ \section{Stream Operator inStream and Connection Equations}\doublelabel{stream-o The following properties hold for this implementation: \begin{itemize} \item - \lstinline!inStream(..)! is continuous (and differentiable), + \lstinline!inStream! is continuous (and differentiable), provided that \lstinline[mathescape=true]!$m_{j}$.c.h_outflow!, \lstinline[mathescape=true]!$m_{j}$.c.m_flow!, \lstinline[mathescape=true]!$c_{k}$.h_outflow!, and \lstinline[mathescape=true]!$c_{k}$.m_flow! are continuous and differentiable. diff --git a/chapters/synchronous.tex b/chapters/synchronous.tex index 4bb0803f1..46113837b 100644 --- a/chapters/synchronous.tex +++ b/chapters/synchronous.tex @@ -25,19 +25,19 @@ \subsection{Overview}\doublelabel{overview} \begin{itemize} \item A periodic clock is defined with \textbf{Clock}(3). The argument - of \textbf{Clock}(..) defines the sampling interval (for details see \autoref{clock-constructors}). + of \textbf{Clock} defines the sampling interval (for details see \autoref{clock-constructors}). \item Clocked variables (such as yd, xd, ud) are associated uniquely with a clock and can only be directly accessed when the associated clock is active. Since all variables in a clocked equation must belong to the same clock, clocking errors can be detected at compile time. If variables from different clocks shall be used in an equation, explicit - cast operators must be used, such as \textbf{sample}(..) to convert - from continuous-time to clocked discrete-time or \textbf{hold}(..) to + cast operators must be used, such as \textbf{sample} to convert + from continuous-time to clocked discrete-time or \textbf{hold} to convert from clocked discrete-time to continuous-time. \item - A continuous-time variable is sampled at a clock tick with the - \textbf{sample}(..) operator. The operator returns the value of the + A continuous-time variable is sampled at a clock tick with + \lstinline!sample!. The operator returns the value of the continuous-time variable when the clock is active. \item When no argument is defined for \textbf{Clock}(), the clock is @@ -66,8 +66,7 @@ \subsection{Overview}\doublelabel{overview} the previous clock tick. At the first sample instant, the start value of xd is returned. \item - A discrete-time signal (such as ud) is converted to a - continuous-time signal with the \textbf{hold}(..) operator. + A discrete-time signal (such as ud) is converted to a continuous-time signal with \lstinline!hold!. \item If a variable belongs to a particular clock, then all other equations where this variable is used, with the exception of as @@ -162,7 +161,7 @@ \subsection{Rationale for Clocked Semantics}\doublelabel{rationale-for-clocked-s \item At a sample instant, an event iteration occurs (as for any other event). A clocked partition, as well as a when-clause with a - sample(..) is evaluated exactly once at such an event instant. + \lstinline!sample! is evaluated exactly once at such an event instant. However, the continuous-time model to which the sampled data controller is connected, will be evaluated several times when the overall system is simulated. With when-clauses, the continuous-time @@ -220,10 +219,10 @@ \subsection{Clocks and Clocked Variables}\doublelabel{clocks-and-clocked-variabl clocks, see \autoref{base-clock-conversion-operators}. \begin{example} -\begin{lstlisting}[language=modelica] - Clock c1 = Clock(...); +\begin{lstlisting}[language=modelica,mathescape=true] + Clock c1 = Clock($\ldots$); Clock c2 = c1; - Clock c3 = subSample(c2,4); + Clock c3 = subSample(c2, 4); \end{lstlisting} \end{example} @@ -552,7 +551,7 @@ \section{Clock Constructors}\doublelabel{clock-constructors} \end{example} % Ok, that bug in pdflatex was weird: \emph{Example: \lstinline!Clock c1[3] ={Clock(1), Clock(2), Clock(3)}!} {]} \item - Array constructors of clocks: \lstinline!{}, [], cat(...)!. + Array constructors of clocks: \lstinline!{}!, \lstinline![]!, \lstinline!cat!. \item Array access of clocks. \begin{example} @@ -571,9 +570,9 @@ \section{Clock Constructors}\doublelabel{clock-constructors} \item Clock variables can be declared in models, blocks, connectors, and records. A \lstinline!Clock! variable can be declared with the prefixes - \lstinline{input}, \lstinline{output}, \lstinline{inner}, \lstinline{outer}, but - \emph{not} with the prefixes \lstinline{flow}, \lstinline{stream}, - \lstinline{discrete}, \lstinline{parameter}, or \lstinline{constant}. + \lstinline!input!, \lstinline!output!, \lstinline!inner!, \lstinline!outer!, but + \emph{not} with the prefixes \lstinline!flow!, \lstinline!stream!, + \lstinline!discrete!, \lstinline!parameter!, or \lstinline!constant!. \begin{example} \lstinline!connector ClockInput = input Clock;! \end{example} @@ -629,9 +628,9 @@ \subsection{Base-clock conversion operators}\doublelabel{base-clock-conversion-o constant, a parameter or a piecewise constant expression. Note that \textbf{sample}() is an overloaded function: If -\textbf{sample}(..) has two positional input arguments and the second argument is +\lstinline!sample! has two positional input arguments and the second argument is of type Real, it is the operator from \autoref{event-related-operators-with-function-syntax}. If -\textbf{sample}(..) has one input argument, or it has two input +\lstinline!sample! has one input argument, or it has two input arguments and the second argument if of type Clock, it is the base-clock conversion operator from this section. \end{nonnormative*} @@ -821,12 +820,12 @@ \subsection{Sub-clock conversion operators}\doublelabel{sub-clock-conversion-ope \end{longtable} \begin{nonnormative} -Clarification of backSample(..) operator: +Clarification of \lstinline!backSample!: -Let a and b be positive integers with a \textless{} b, and -\begin{lstlisting}[language=modelica] -yb = backSample (u, a , b) -ys = shiftSample(u, b-a, b) +Let $a$ and $b$ be positive integers with $a < b$, and +\begin{lstlisting}[language=modelica,mathescape=true] +yb = backSample (u, $a$, $b$) +ys = shiftSample(u, $b-a$, $b$) \end{lstlisting} Then when \lstinline!ys! exists, also \lstinline!yb! exists and \lstinline!ys = yb!. @@ -837,7 +836,7 @@ \subsection{Sub-clock conversion operators}\doublelabel{sub-clock-conversion-ope \end{nonnormative} \begin{nonnormative} -Clarification of noClock(..) operator: +Clarification of \lstinline!noClock! operator: Note, that noClock(u) is not equivalent to sample(hold(u)). Consider the following model: \begin{lstlisting}[language=modelica] @@ -1161,7 +1160,7 @@ \subsection{Clocked Discrete-Time and Clocked Discretized Continuous-Time Partit If a clocked partition contains no operator \lstinline!der!, \lstinline!delay!, \textbf{spatialDistribution}, no event related operators -from \autoref{event-related-operators-with-function-syntax} (with exception of \textbf{noEvent}(..)), and no +from \autoref{event-related-operators-with-function-syntax} (with exception of \lstinline!noEvent!), and no \lstinline!when!-clause with a \lstinline!Boolean! condition, it is a \firstuse{clocked discrete-time} partition. \begin{nonnormative} @@ -1472,7 +1471,7 @@ \section{Other Operators}\doublelabel{other-operators} end when; end ClockedPI; \end{lstlisting} -A continuous-time model is inverted, discretized and used as feedforward controller for a PI controller (der(..), previous, interval are used in the same partition): +A continuous-time model is inverted, discretized and used as feedforward controller for a PI controller (\lstinline!der!, \lstinline!previous!, \lstinline!interval! are used in the same partition): \begin{lstlisting}[language=modelica] block MixedController parameter Real T "Time constant of continuous PI controller"; From 27b450d47553e50fc5360f708174b4dafdf6f682 Mon Sep 17 00:00:00 2001 From: Henrik Tidefelt Date: Wed, 3 Jun 2020 23:07:40 +0200 Subject: [PATCH 34/78] Introduce \bibitemtitle to replace \textbf for titles in the bibliography --- chapters/literature.tex | 41 ++++++++++++++++++----------------------- preamble.tex | 2 ++ 2 files changed, 20 insertions(+), 23 deletions(-) diff --git a/chapters/literature.tex b/chapters/literature.tex index 7914053ce..78958f580 100644 --- a/chapters/literature.tex +++ b/chapters/literature.tex @@ -1,40 +1,35 @@ \chapter{Literature}\doublelabel{literature} -Benveniste A., Caspi P., Edwards S.A., Halbwachs N., Le Guernic P., and -Simone R. (2003): \textbf{The Synchronous Languages Twelve Years Later}. +Benveniste A., Caspi P., Edwards S.A., Halbwachs N., Le Guernic P., and Simone R. (2003): +\bibitemtitle{The Synchronous Languages Twelve Years Later}. Proc. of the IEEE, Vol., 91, No. 1. \url{https://doi.org/10.1109/JPROC.2002.805826} -Colaco J.-L., and Pouzet M. (2003): \textbf{Clocks as First Class -Abstract Types}. In Third International Conference on Embedded Software -(EMSOFT'03), Philadelphia, Pennsylvania, USA, October 2003.\\ +Colaco J.-L., and Pouzet M. (2003): +\bibitemtitle{Clocks as First Class Abstract Types}. +In Third International Conference on Embedded Software (EMSOFT'03), Philadelphia, Pennsylvania, USA, October 2003.\\ \url{http://www.di.ens.fr/~pouzet/lucid-synchrone/papers/emsoft03.ps.gz} -Elmqvist H., Otter M. and Cellier F.E. (1995): \textbf{Inline -Integration: A New Mixed Symbolic/Numeric Approach for Solving -Differential-Algebraic Equation Systems}. Keynote Address, Proceedings -ESM'95, European Simulation Multiconference, Prague, Czech Republic, -June 5-8, 1995, pp. xxiii-xxxiv. +Elmqvist H., Otter M. and Cellier F.E. (1995): +\bibitemtitle{Inline Integration: A New Mixed Symbolic/Numeric Approach for Solving Differential-Algebraic Equation Systems}. +Keynote Address, Proceedings ESM'95, European Simulation Multiconference, Prague, Czech Republic, June 5-8, 1995, pp. xxiii-xxxiv. \url{http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.127.3787\&rep=rep1\&type=pdf} -Forget J., F. Boniol, D. Lesens, C. Pagetti (2008): \textbf{A -Multi-Periodic Synchronous Data-Flow Language}. In -11\textsuperscript{th} IEEE High Assurance Systems Engineering Symposium -(HASE'08), Dec. 3-5 2008, Nanjing, China, pp. 251-260. +Forget J., F. Boniol, D. Lesens, C. Pagetti (2008): +\bibitemtitle{A Multi-Periodic Synchronous Data-Flow Language}. +In 11\textsuperscript{th} IEEE High Assurance Systems Engineering Symposium (HASE'08), Dec. 3-5 2008, Nanjing, China, pp. 251-260. \url{https://doi.org/10.1109/HASE.2008.47} -Harel, D. (1987): \textbf{Statecharts: A Visual Formalism for Complex -Systems}\emph{.} Science of Computer Programming 8, 231-274. Department -of Applied Mathematics, The Weizmann Institute of Science, Rehovot, -Israel. +Harel, D. (1987): +\bibitemtitle{Statecharts: A Visual Formalism for Complex Systems}. +Science of Computer Programming 8, 231-274. Department of Applied Mathematics, The Weizmann Institute of Science, Rehovot, Israel. \href{http://www.inf.ed.ac.uk/teaching/courses/seoc1/2005_2006/resources/statecharts.pdf}{www.inf.ed.ac.uk/teaching/courses/seoc1/-2005\_2006/resources/statecharts.pdf} Looye G., Thümmel M., Kurze M., Otter M., and Bals J. (2005): -\textbf{Nonlinear Inverse Models for Control}. Proceedings of -4\textsuperscript{th} International Modelica Conference, ed. G. Schmitz, -Hamburg, March 7-8.\\ +\bibitemtitle{Nonlinear Inverse Models for Control}. +Proceedings of 4\textsuperscript{th} International Modelica Conference, ed. G. Schmitz, Hamburg, March 7-8.\\ \url{https://www.modelica.org/events/Conference2005/online_proceedings/Session3/Session3c3.pdf} -Pouzet M. (2006): \textbf{Lucid Synchrone, Version 3.0, Tutorial and -Reference Manual}.\\ +Pouzet M. (2006): +\bibitemtitle{Lucid Synchrone, Version 3.0, Tutorial and Reference Manual}.\\ \url{http://www.di.ens.fr/~pouzet/lucid-synchrone/} diff --git a/preamble.tex b/preamble.tex index 30ba54d64..416c3d685 100644 --- a/preamble.tex +++ b/preamble.tex @@ -135,6 +135,8 @@ \newcommand{\glossaryitem}[1]{\textbf{#1}} +\newcommand{\bibitemtitle}[1]{\emph{#1}} + \setcounter{secnumdepth}{5} % Note: Toc changed for appendex \setcounter{tocdepth}{1} From 1d14b07522fd7c9eeccc021b6f9a9bc7b8e3724b Mon Sep 17 00:00:00 2001 From: Henrik Tidefelt Date: Wed, 3 Jun 2020 23:25:22 +0200 Subject: [PATCH 35/78] Replace some \textbf in tables with \tablehead --- chapters/inheritance.tex | 6 +++--- chapters/interface.tex | 2 +- chapters/statemachines.tex | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/chapters/inheritance.tex b/chapters/inheritance.tex index 0418365f8..71fc95557 100644 --- a/chapters/inheritance.tex +++ b/chapters/inheritance.tex @@ -154,10 +154,10 @@ \subsection{Restrictions on the Kind of Base Class}\doublelabel{restrictions-on- \begin{tabular}{|c|c|c|c|c|c|c|c|c|c|c|c|c|} \hline - & \multicolumn{12}{c|}{\textbf{Base Class}} \\ + & \multicolumn{12}{c|}{\tablehead{Base Class}} \\ \hline - \textbf{Derived} & \multirow{2}{*}{package} & \multirow{2}{*}{operator} & \multirow{2}{*}{function} & operator & \multirow{2}{*}{type} & \multirow{2}{*}{record} & operator & expandable & \multirow{2}{*}{connector} & \multirow{2}{*}{block} & \multirow{2}{*}{model} & \multirow{2}{*}{class} \\ - \textbf{Class} & & & & function & & & record & connector & & & & \\ + \tablehead{Derived} & \multirow{2}{*}{package} & \multirow{2}{*}{operator} & \multirow{2}{*}{function} & operator & \multirow{2}{*}{type} & \multirow{2}{*}{record} & operator & expandable & \multirow{2}{*}{connector} & \multirow{2}{*}{block} & \multirow{2}{*}{model} & \multirow{2}{*}{class} \\ + \tablehead{Class} & & & & function & & & record & connector & & & & \\ \hline package & yes & & & & & & & & & & & \cellcolor{lightgray}yes \\ \hline diff --git a/chapters/interface.tex b/chapters/interface.tex index fd40b6876..66c60b1ff 100644 --- a/chapters/interface.tex +++ b/chapters/interface.tex @@ -18,7 +18,7 @@ \chapter{Interface or Type Relationships}\doublelabel{interface-or-type-relation \begin{longtable}{|p{4cm}|p{8cm}|} \hline \endhead -\textbf{term} & \textbf{description}\\ \hline +\tablehead{Term} & \tablehead{Description}\\ \hline type or interface & The ``essential'' part of the public declaration sections of a class that is needed to decide whether \lstinline!A! can be used instead of \lstinline!B!. diff --git a/chapters/statemachines.tex b/chapters/statemachines.tex index e922b02fc..8823137d5 100644 --- a/chapters/statemachines.tex +++ b/chapters/statemachines.tex @@ -59,7 +59,7 @@ \section{Transitions}\doublelabel{transitions} states and to define the initial state: \begin{longtable}[]{|p{4cm}|p{10cm}|} \hline \endhead -\multicolumn{2}{|p{12cm}|}{\textbf{Statements to define a state machine}}\\ \hline +\multicolumn{2}{|p{12cm}|}{\tablehead{Statements to define a state machine}}\\ \hline \begin{tabular}{@{}p{4cm}@{}} \textbf{transition}(from, to, \\ condition,\\ immediate, reset,\\ From d780a86be58f3336f540e0746aed62b6728e72e0 Mon Sep 17 00:00:00 2001 From: Henrik Tidefelt Date: Wed, 3 Jun 2020 23:26:07 +0200 Subject: [PATCH 36/78] Remove stray non-normative closing bracket --- chapters/synchronous.tex | 2 -- 1 file changed, 2 deletions(-) diff --git a/chapters/synchronous.tex b/chapters/synchronous.tex index 46113837b..1e22e2cb6 100644 --- a/chapters/synchronous.tex +++ b/chapters/synchronous.tex @@ -250,8 +250,6 @@ \subsection{Clocks and Clocked Variables}\doublelabel{clocks-and-clocked-variabl \end{tabular}\\ \hline \end{longtable} -{]} - \subsection{Base-Clock and Sub-Clock Partitions}\doublelabel{base-clock-and-sub-clock-partitions} The following concepts are used: From f3277e417fc159a8272645a9b483fbaa6f238b23 Mon Sep 17 00:00:00 2001 From: Henrik Tidefelt Date: Wed, 3 Jun 2020 23:26:43 +0200 Subject: [PATCH 37/78] Use \emph instead of \textbf on 'shall not' --- chapters/operatorsandexpressions.tex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/chapters/operatorsandexpressions.tex b/chapters/operatorsandexpressions.tex index c41a93e7d..8a17bdeb8 100644 --- a/chapters/operatorsandexpressions.tex +++ b/chapters/operatorsandexpressions.tex @@ -986,7 +986,7 @@ \subsubsection{homotopy}\doublelabel{homotopy} \end{lstlisting} \end{example} -\begin{example}[4] Note that \lstinline!homotopy! \textbf{shall not} be used to +\begin{example}[4] Note that \lstinline!homotopy! \emph{shall not} be used to combine unrelated expressions, since this can generate singular systems from combining two well-defined systems. \begin{lstlisting}[language=modelica] From b2b83d0bec25caf36f2b542d4b4f4993575e5702 Mon Sep 17 00:00:00 2001 From: Henrik Tidefelt Date: Thu, 4 Jun 2020 00:08:34 +0200 Subject: [PATCH 38/78] Remove more parentheses with only dots inside --- chapters/connectors.tex | 10 +++++----- chapters/equations.tex | 8 ++++---- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/chapters/connectors.tex b/chapters/connectors.tex index e769ba89d..98f722647 100644 --- a/chapters/connectors.tex +++ b/chapters/connectors.tex @@ -844,7 +844,7 @@ \subsection{Overconstrained Equation Operators for Connection Graphs}\doublelabe end equalityConstraint; end Record; \end{lstlisting} -The \lstinline!residue! output of the \lstinline!equalityConstraint(..)! function shall have +The \lstinline!residue! output of the \lstinline!equalityConstraint! function shall have known size, say constant n. The function shall express the equality between the two type instances \lstinline!T1! and \lstinline!T2! or the record instances \lstinline!R1! and @@ -900,7 +900,7 @@ \subsection{Overconstrained Equation Operators for Connection Graphs}\doublelabe from the overdetermined type or record instance \lstinline!R! in connector instance \lstinline!A! to the corresponding overdetermined type or record instance \lstinline!R! in connector instance \lstinline!B! for a virtual connection graph. This function can -be used at all places where a \lstinline!connect(..)! statement is allowed. +be used at all places where a \lstinline!connect! statement is allowed. \par \begin{nonnormative*} E.g., it is not allowed to use this function in a when-clause. This definition shall be used if in a model with connectors \lstinline!A! and \lstinline!B! the overdetermined @@ -969,7 +969,7 @@ \subsection{Converting the Connection Graph into Trees and Generating Connection from the graph. This is performed in the following way: \begin{enumerate} \item - Every root node defined via the \lstinline!Connections.root(..)! statement is + Every root node defined via the \lstinline!Connections.root! statement is a definite root of one spanning tree. \item The virtual connection graph may consist of sets of subgraphs that are @@ -978,7 +978,7 @@ \subsection{Converting the Connection Graph into Trees and Generating Connection graph of this set does not contain any root node, then one potential root node in this subgraph that has the lowest priority number is selected to be the root of that subgraph. The selection can be - inquired in a class with function \lstinline!Connections.isRoot(..)!, see table + inquired in a class with function \lstinline!Connections.isRoot!, see table above. \item If there are n selected roots in a subgraph, then optional spanning-tree edges @@ -1062,7 +1062,7 @@ \subsubsection{An Overdetermined Connector for Power Systems}\doublelabel{an-ove end AC_Inductor \end{lstlisting} At the place where the source frequency, i.e., essentially -variable theta, is defined, a \lstinline!Connections.root(..)! must be present: +variable theta, is defined, a \lstinline!Connections.root! must be present: \begin{lstlisting}[language=modelica] AC_plug p; equation diff --git a/chapters/equations.tex b/chapters/equations.tex index 780adfd32..46f262f68 100644 --- a/chapters/equations.tex +++ b/chapters/equations.tex @@ -498,9 +498,9 @@ \subsection{assert}\doublelabel{assert} \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. + 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. + be implicitly treated with \lstinline!noEvent! since otherwise events might be triggered that can lead to slightly changed simulation results. \end{nonnormative} \end{itemize} @@ -750,7 +750,7 @@ \section{Initialization, initial equation, and initial algorithm}\doublelabel{in Before any operation is carried out with a Modelica model (e.g., simulation or linearization), initialization takes place to assign consistent values for all variables present in the model. During this -phase, also the derivatives, \lstinline!der(..)!, and the pre-variables, \lstinline!pre(..)!, +phase, also the derivatives (\lstinline!der!), and the pre-variables (\lstinline!pre!), are interpreted as unknown algebraic variables. The initialization uses all equations and algorithms that are utilized in the intended operation (such as simulation or linearization). The equations of a @@ -854,7 +854,7 @@ \section{Initialization, initial equation, and initial algorithm}\doublelabel{in A Modelica translator may first transform the continuous equations of a model, at least conceptually, to state space form. This may require to differentiate equations for index reduction, i.e., additional equations and, in some cases, additional unknown variables are introduced. This whole set of equations, together with the additional constraints -defined above, should lead to an algebraic system of equations where the number of equations and the number of all variables (including \lstinline!der(..)! and \lstinline!pre(..)! +defined above, should lead to an algebraic system of equations where the number of equations and the number of all variables (including \lstinline!der! and \lstinline!pre! variables) is equal. Often, this is a nonlinear system of equations and therefore it may be necessary to provide appropriate guess values (i.e., \lstinline!start! values and \lstinline!fixed=false!) in order to compute a solution numerically. From 5c6e174f553fe6622a3eb8c055ce286c50a9644e Mon Sep 17 00:00:00 2001 From: Henrik Tidefelt Date: Thu, 4 Jun 2020 00:08:54 +0200 Subject: [PATCH 39/78] Move period out of \lstinline --- chapters/classes.tex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/chapters/classes.tex b/chapters/classes.tex index 37f57c53c..2c7899995 100644 --- a/chapters/classes.tex +++ b/chapters/classes.tex @@ -838,7 +838,7 @@ \section{Specialized Classes}\doublelabel{specialized-classes} algorithm and protected sections are not allowed). Enhanced to allow \lstinline!connect! to components of connector classes. The -elements of a connector may not have prefixes \lstinline!inner!, or \lstinline!outer.! May only +elements of a connector may not have prefixes \lstinline!inner!, or \lstinline!outer!. May only contain components of specialized class connector, record and type.\\ \hline \lstinline!package! & May only contain declarations of classes and From ecc61113b9e35a6d46d9f1717a383cec38f28855 Mon Sep 17 00:00:00 2001 From: Henrik Tidefelt Date: Thu, 4 Jun 2020 00:09:37 +0200 Subject: [PATCH 40/78] Replace lots of \textbf with \lstinline --- chapters/operatorsandexpressions.tex | 2 +- chapters/statemachines.tex | 30 ++-- chapters/synchronous.tex | 215 +++++++++++++-------------- 3 files changed, 121 insertions(+), 126 deletions(-) diff --git a/chapters/operatorsandexpressions.tex b/chapters/operatorsandexpressions.tex index 8a17bdeb8..fc2480bb0 100644 --- a/chapters/operatorsandexpressions.tex +++ b/chapters/operatorsandexpressions.tex @@ -750,7 +750,7 @@ \subsubsection{spatialDistribution}\doublelabel{spatialdistribution} This allows to directly compute the solution based on interpolating the boundary conditions. -\textbf{spatialDistribution} can be described in terms of the pseudo-code given as a block: +\lstinline!spatialDistribution! can be described in terms of the pseudo-code given as a block: \begin{lstlisting}[language=modelica] block spatialDistribution input Real in0; diff --git a/chapters/statemachines.tex b/chapters/statemachines.tex index 8823137d5..975dd8958 100644 --- a/chapters/statemachines.tex +++ b/chapters/statemachines.tex @@ -50,18 +50,19 @@ \section{Transitions}\doublelabel{transitions} Any Modelica block instance without continuous-time equations or algorithms can potentially be a state of a state machine. A cluster of -instances which are coupled by \textbf{transition} statements makes a +instances which are coupled by \lstinline!transition! statements makes a state machine. All parts of a state machine must have the same clock. All transitions leaving one state must have different priorities. One and only one instance in each state machine must be marked as initial by -appearing in an \textbf{initialState} statement. The following special +appearing in an \lstinline!initialState! statement. The following special kinds of connect-statements are used to define transitions between states and to define the initial state: \begin{longtable}[]{|p{4cm}|p{10cm}|} \hline \endhead \multicolumn{2}{|p{12cm}|}{\tablehead{Statements to define a state machine}}\\ \hline \begin{tabular}{@{}p{4cm}@{}} -\textbf{transition}(from, to, \\ condition,\\ +\lstinline!transition!(from, to,\\ +condition,\\ immediate, reset,\\ synchronize, priority) \end{tabular} @@ -69,30 +70,29 @@ \section{Transitions}\doublelabel{transitions} Arguments \lstinline!from! and \lstinline!to! are block instances and \lstinline!condition! is a \lstinline!Boolean! argument. The optional arguments \lstinline!immediate!, \lstinline!reset!, and \lstinline!synchronize! are of type \lstinline!Boolean!, have parametric variability and a -default of \textbf{true, true, false} respectively. The optional +default of \lstinline!true!, \lstinline!true!, \lstinline!false! respectively. The optional argument \lstinline!priority! is of type \lstinline!Integer!, has parametric variability and a default of 1. This operator defines a transition from instance \lstinline!from! to instance \lstinline!to!. The \lstinline!from! and \lstinline!to! instances become states of a state -machine. The transition fires when condition = \textbf{true} if -immediate = \textbf{true} (this is called an \firstuse{immediate transition}) -or \textbf{previous}(condition) when immediate = \textbf{false} (this is +machine. The transition fires when \lstinline!condition = true! if +\lstinline!immediate = true! (this is called an \firstuse{immediate transition}) +or \lstinline!previous(condition)! when \lstinline!immediate = false! (this is called a \firstuse{delayed transition}). Argument \lstinline!priority! defines the priority of firing when several transitions could fire. In this case the transition with the smallest value of \lstinline!priority! fires. It is required that $\textrm{priority}\ge 1$ and that for all transitions from the same state, the -priorities are different. If reset = \textbf{true}, the states of the +priorities are different. If \lstinline!reset = true!, the states of the target state are reinitialized, i.e. state machines are restarted in initial state and state variables are reset to their start values. If synchronize=true, any transition is disabled until all state machines of the from-state have reached final states, i.e. states without outgoing transitions. For the precise details about firing a transition, see \autoref{state-machine-semantics}.\\ \hline -\textbf{initialState}(state) & Argument \lstinline!state! is the block instance +\lstinline!initialState(state)! & Argument \lstinline!state! is the block instance that is defined to be the initial state of a state machine. At the first -clock tick of the state machine, this state becomes -active.\\ \hline +clock tick of the state machine, this state becomes active.\\ \hline \end{longtable} The transition-, and initialState-equations may only be used in @@ -103,11 +103,11 @@ \section{Transitions}\doublelabel{transitions} following operators: \begin{longtable}[]{|p{4cm}|p{10cm}|} \hline \endhead -\textbf{activeState}(state)& +\lstinline!activeState(state)!& Argument \lstinline!state! is a block instance. The operator returns -\textbf{true}, if this instance is a state of a state machine and this +\lstinline!true!, if this instance is a state of a state machine and this state is active at the actual clock tick. If it is not active, the -operator returns \textbf{false}. +operator returns \lstinline!false!. It is an error if the instance is not a state of a state machine.\\ \hline \lstinline!ticksInState()! & Returns the number of ticks of the clock of the state machine @@ -413,7 +413,7 @@ \subsection{Merging Variable Definitions}\doublelabel{merging-variable-definitio v := if activeState(state!\textsubscript{1}!) then expre!\textsubscript{1}! elseif activeState(state!\textsubscript{2}!) then expre!\textsubscript{2}! elseif ... else last(v) \end{lstlisting} -\textbf{last}() is special internal semantic operator returning its +\lstinline!last! is special internal semantic operator returning its input. It is just used to mark for the sorting that the incidence of its argument should be ignored. A start value must be given to the variable if not assigned in the initial state. diff --git a/chapters/synchronous.tex b/chapters/synchronous.tex index 1e22e2cb6..795a48c9d 100644 --- a/chapters/synchronous.tex +++ b/chapters/synchronous.tex @@ -24,23 +24,23 @@ \subsection{Overview}\doublelabel{overview} \begin{itemize} \item - A periodic clock is defined with \textbf{Clock}(3). The argument - of \textbf{Clock} defines the sampling interval (for details see \autoref{clock-constructors}). + A periodic clock is defined with \lstinline!Clock(3)!. The argument + of \lstinline!Clock! defines the sampling interval (for details see \autoref{clock-constructors}). \item Clocked variables (such as yd, xd, ud) are associated uniquely with a clock and can only be directly accessed when the associated clock is active. Since all variables in a clocked equation must belong to the same clock, clocking errors can be detected at compile time. If variables from different clocks shall be used in an equation, explicit - cast operators must be used, such as \textbf{sample} to convert - from continuous-time to clocked discrete-time or \textbf{hold} to + cast operators must be used, such as \lstinline!sample! to convert + from continuous-time to clocked discrete-time or \lstinline!hold! to convert from clocked discrete-time to continuous-time. \item A continuous-time variable is sampled at a clock tick with \lstinline!sample!. The operator returns the value of the continuous-time variable when the clock is active. \item - When no argument is defined for \textbf{Clock}(), the clock is + When no argument is defined for \lstinline!Clock!, the clock is deduced by clock inference. \item For a \lstinline!when!-clause with an associated clock, all @@ -62,9 +62,9 @@ \subsection{Overview}\doublelabel{overview} ud = C*previous(xd) + D*yd; \end{lstlisting} \item - The operator \textbf{previous}(xd) returns the value of xd at + \lstinline!previous(xd)! returns the value of \lstinline!xd! at the previous clock tick. At the first sample instant, the start value - of xd is returned. + of \lstinline!xd! is returned. \item A discrete-time signal (such as ud) is converted to a continuous-time signal with \lstinline!hold!. \item @@ -168,11 +168,11 @@ \subsection{Rationale for Clocked Semantics}\doublelabel{rationale-for-clocked-s part is typically evaluated three times at a sample instant (once, when the sample instant is reached, once to evaluate the continuous equations at the sample instant, and once when an event iteration - occurs since a discrete variable v is changed and \textbf{pre}(v) + occurs since a discrete variable \lstinline!v! is changed and \lstinline!pre(v)! appears in the equations). With clocked equations, no event iteration - is triggered if a clocked variable v is changed and - \textbf{previous}(v) appears in the equations, because the event - iteration cannot change the value of v. As a result, typically the + is triggered if a clocked variable \lstinline!v! is changed and + \lstinline!previous(v)! appears in the equations, because the event + iteration cannot change the value of \lstinline!v!. As a result, typically the simulation model is evaluated twice at a sample instant and therefore the simulation is more efficient with clocked equations. \end{enumerate} @@ -197,14 +197,12 @@ \subsection{Clocks and Clocked Variables}\doublelabel{clocks-and-clocked-variabl \includegraphics[width=3in,height=1.875in]{piecewise} \end{tabular}&\begin{tabular}{p{7cm}}\textbf{Piecewise-constant variables (see \autoref{discrete-time-expressions})} -% henrikt-ma: Get rid of the use of \underline below. -Variables \textbf{m}(t) of base type Real, Integer, Boolean, -enumeration, and String that are \underline{constant} inside each interval +Variables \lstinline!m(t)! of base type \lstinline!Real!, \lstinline!Integer!, \lstinline!Boolean!, +enumeration, and \lstinline!String! that are \emph{constant} inside each interval t\textsubscript{i} $\le$ t \textless{} t\textsubscript{i+1} (= piecewise -constant continuous-time variables). In other words, \textbf{m}(t) -\underline{changes} value \underline{only at events}. This means, \textbf{m}(t) = -\textbf{m}(t\textsubscript{i}), for t\textsubscript{i} $\le$ t \textless{} -t\textsubscript{i+1}. Such variables depend continuously on time and +constant continuous-time variables). In other words, \lstinline!m(t)! +\emph{changes} value \emph{only at events}. This means, \lstinline[mathescape=true]!m($t$)! = +\lstinline[mathescape=true]!m($t_{i}$)!, for $t_{i} \leq t < t_{i+1}$. Such variables depend continuously on time and they are discrete-time variables. \end{tabular}\\ \hline \begin{tabular}{p{7cm}} @@ -212,8 +210,8 @@ \subsection{Clocks and Clocked Variables}\doublelabel{clocks-and-clocked-variabl \end{tabular}& \begin{tabular}{p{7cm}}\textbf{Clock variables} -Clock variables \textbf{c}(t\textsubscript{i}) are of base type Clock. A -clock is either defined by a constructor (such as Clock(3)) +Clock variables \lstinline[mathescape=true]!c($t_{i}$)! are of base type \lstinline!Clock!. A +clock is either defined by a constructor (such as \lstinline!Clock(3)!) that defines when the clock ticks (is active) at a particular time instant, or it is defined with clock operators relatively to other clocks, see \autoref{base-clock-conversion-operators}. @@ -231,9 +229,9 @@ \subsection{Clocks and Clocked Variables}\doublelabel{clocks-and-clocked-variabl \includegraphics[width=3in,height=1.875in]{clocked} \end{tabular}& \begin{tabular}{p{7cm}}\textbf{Clocked variables} -The elements of clocked variables \textbf{r}(t\textsubscript{i}) are of -base type Real, Integer, Boolean, enumeration, String that are -associated uniquely with a clock \textbf{c}(t\textsubscript{i}). A +The elements of clocked variables \lstinline[mathescape=true]!r($t_{i}$)! are of +base type \lstinline!Real!, \lstinline!Integer!, \lstinline!Boolean!, enumeration, \lstinline!String! that are +associated uniquely with a clock \lstinline[mathescape=true]!c($t_{i}$)!. A clocked variable can only be directly accessed at the event instant where the associated clock is \textbf{active}. A constant and a parameter can always be used at a place where a clocked variable is @@ -348,7 +346,7 @@ \section{Clock Constructors}\doublelabel{clock-constructors} it is possible to call them with the specified named arguments, or with positional arguments (according to the order below): \begin{longtable}[]{|p{3cm}|p{12cm}|} \hline \endhead -\textbf{Clock}() +\lstinline!Clock()! & \begin{tabular}{@{}p{119mm}@{}} \textbf{Inferred Clock}\\ @@ -372,7 +370,7 @@ \section{Clock Constructors}\doublelabel{clock-constructors} \end{example} \end{tabular}\\ \hline \begin{tabular}{@{}p{29mm}@{}} -\textbf{Clock}(\newline +\lstinline!Clock!(\newline intervalCounter,\newline resolution) \end{tabular} @@ -382,7 +380,7 @@ \section{Clock Constructors}\doublelabel{clock-constructors} The first input argument, \lstinline!intervalCounter!, is a clocked Component Expression (see \autoref{argument-restrictions-component-expression}) or a parameter expression of type -\textbf{Integer} with min=0. The optional second argument \lstinline!resolution! +\lstinline!Integer! with \lstinline!min=0!. The optional second argument \lstinline!resolution! (default=1) is a parameter expression of type Integer with \lstinline!min=1! and \lstinline!unit="Hz"!. If \lstinline!intervalCounter! is a parameter expression with value zero, the period of the clock is derived by clock inference, see @@ -422,38 +420,37 @@ \section{Clock Constructors}\doublelabel{clock-constructors} \end{lstlisting} \end{nonnormative} -Note that operator interval(c) of Clock c = -Clock(nextInterval,resolution) returns:\newline -previous(intervalCounter)/resolution; // in seconds +Note that operator \lstinline!interval(c)! of \lstinline!Clock c = Clock(nextInterval, resolution)! returns:\newline +\lstinline!previous(intervalCounter) / resolution; // in seconds! \end{tabular}\\ \hline -\textbf{Clock}(interval) +\lstinline!Clock(interval)! & \begin{tabular}{@{}p{119mm}@{}} \textbf{Clock with Real Interval}\\ The input argument, \lstinline!interval!, is a clocked Component Expression (see \autoref{argument-restrictions-component-expression}) or a parameter expression. -The \lstinline!interval! must be strictly positive (\lstinline!interval>0.0!) of type \textbf{Real} with \lstinline!unit="s"!. +The \lstinline!interval! must be strictly positive (\lstinline!interval>0.0!) of type \lstinline!Real! with \lstinline!unit="s"!. The output argument is of base type Clock that ticks when time becomes t\textsubscript{start}, t\textsubscript{start}+interval1, t\textsubscript{start}+interval1+interval2, ... The clock starts at the start of the simulation t\textsubscript{start} or when the controller is switched on. Here the next clock tick is scheduled at interval1 = -\textbf{previous}(interval) = interval.start. At the second clock tick +\lstinline!previous(interval) = interval.start!. At the second clock tick at time t\textsubscript{start}+interval1, the next clock tick is -scheduled at interval2 = \textbf{previous}(interval), and so on. If +scheduled at \lstinline!interval2 = previous(interval)!, and so on. If interval is a parameter expression, the clock defines a periodic clock. \begin{nonnormative} -Note, the clock is defined with \textbf{previous}(interval). Therefore, for sorting the input argument is treated as known. The given interval and time shift can be modified +Note, the clock is defined with \lstinline!previous(interval)!. Therefore, for sorting the input argument is treated as known. The given interval and time shift can be modified by using the subSample, superSample, shiftSample and backSample operators on the returned clock, see \autoref{sub-clock-conversion-operators}. There are restrictions where this operator can be used, see Clock expressions below. \end{nonnormative} \end{tabular}\\ \hline \begin{tabular}{@{}p{29mm}@{}} -\textbf{Clock}(\newline - condition,\newline - startInterval) +\lstinline!Clock!(\newline + \lstinline!condition!,\newline + \lstinline!startInterval!) \end{tabular} & \begin{tabular}{@{}p{119mm}@{}} @@ -461,9 +458,9 @@ \section{Clock Constructors}\doublelabel{clock-constructors} The input argument, \lstinline!condition!, is a continuous-time expression of type Boolean. The optional \lstinline!startInterval! argument (default = 0.0) is the -value returned by the operator \textbf{interval}() at the first tick of +value returned by \lstinline!interval()! at the first tick of the clock, see \autoref{initialization-of-clocked-partitions}. The output argument is of base type Clock -that ticks when \textbf{edge}(condition) becomes true. +that ticks when \lstinline!edge(condition)! becomes true. \begin{nonnormative} This clock is used to trigger a clocked partition due to a state event, that is a zero-crossing of a Real variable, in a continuous-time partition or due to a hardware interrupt @@ -480,9 +477,9 @@ \section{Clock Constructors}\doublelabel{clock-constructors} \end{nonnormative} \end{tabular}\\ \hline \begin{tabular}{@{}p{29mm}@{}} -\textbf{Clock}(\newline - c,\newline - solverMethod)\newline +\lstinline!Clock!(\newline + \lstinline!c!,\newline + \lstinline!solverMethod!)\newline \end{tabular} & \begin{tabular}{@{}p{119mm}@{}} @@ -583,7 +580,7 @@ \section{Discrete States}\doublelabel{discrete-states} \begin{longtable}[]{|l|p{12cm}|} \hline \endhead -\textbf{previous}(u) & The input argument is a \emph{component expression} (see +\lstinline!previous(u)! & The input argument is a \emph{component expression} (see \autoref{argument-restrictions-component-expression}) or a parameter expression. The return argument has the same type as the input argument. Input and return arguments are on the same clock. At the first tick of the clock of u or after a reset @@ -603,7 +600,7 @@ \subsection{Base-clock conversion operators}\doublelabel{base-clock-conversion-o clocked-time representation and vice versa: \begin{longtable}[]{|l|p{12cm}|} \hline \endhead -\textbf{sample}(u, clock) & +\lstinline!sample(u, clock)! & Input argument u is a continuous-time expression according to \autoref{continuous-time-expressions}. The optional input argument clock is of type Clock, and can in a call be given as a named argument (with the name clock), or as positional argument. @@ -625,7 +622,7 @@ \subsection{Base-clock conversion operators}\doublelabel{base-clock-conversion-o is continuous-time and therefore has always a value. It can also be a constant, a parameter or a piecewise constant expression. -Note that \textbf{sample}() is an overloaded function: If +Note that \lstinline!sample! is an overloaded function: If \lstinline!sample! has two positional input arguments and the second argument is of type Real, it is the operator from \autoref{event-related-operators-with-function-syntax}. If \lstinline!sample! has one input argument, or it has two input @@ -633,7 +630,7 @@ \subsection{Base-clock conversion operators}\doublelabel{base-clock-conversion-o conversion operator from this section. \end{nonnormative*} \\ \hline -\textbf{hold}(u) & +\lstinline!hold(u)! & Input argument u is a clocked Component Expression (see \autoref{argument-restrictions-component-expression}) or a parameter expression. The operator returns a piecewise constant signal of the same type of u. When the clock of u ticks, the operator @@ -706,23 +703,22 @@ \subsection{Sub-clock conversion operators}\doublelabel{sub-clock-conversion-ope The input arguments \lstinline!shiftCounter! and \lstinline!backCounter! are parameter expressions of type Integer (min=0).} \\ \hline -\textbf{subSample}(u, factor) +\lstinline!subSample(u, factor)! & -The clock of y = \textbf{subSample}(u,factor) is factor-times slowerthan the clock of u. At every factor ticks of the clock of u, the -operator returns the value of u.. The first activation of the clock of y -coincides with the first activation of the clock of u, and then every activation of the clock of y -coincides with the every factor-th activativation of the clock of u. If argument -factor is not provided or is equal to zero, it is inferred, see -\autoref{sub-clock-inferencing}. +The clock of \lstinline!y = subSample(u, factor)! is factor-times slower than the clock of \lstinline!u!. At every factor ticks of the clock of \lstinline!u!, the +operator returns the value of \lstinline!u!. The first activation of the clock of \lstinline!y! +coincides with the first activation of the clock of \lstinline!u!, and then every activation of the clock of \lstinline!y! +coincides with the every factor-th activativation of the clock of \lstinline!u!. If argument +factor is not provided or is equal to zero, it is inferred, see \autoref{sub-clock-inferencing}. \\ \hline -\textbf{superSample}(u, factor) +\lstinline!superSample(u, factor)! & -The clock of y = \textbf{superSample}(u,factor) is factor-times faster -than the clock of u. At every tick of the clock of y, the operator -returns the value of u from the last tick of the clock of u. The first -activation of the clock of y coincides with the first activation of the -clock of u, and then the interval between activations of the clock of u is split equidistantly -into factor activations, such that the activation 1+k*factor of y coincides with the 1+k activation of u. +The clock of \lstinline!y = superSample(u, factor)! is factor-times faster +than the clock of \lstinline!u!. At every tick of the clock of \lstinline!y!, the operator +returns the value of \lstinline!u! from the last tick of the clock of \lstinline!u!. The first +activation of the clock of \lstinline!y! coincides with the first activation of the +clock of \lstinline!u!, and then the interval between activations of the clock of \lstinline!u! is split equidistantly +into factor activations, such that the activation 1+k*factor of \lstinline!y! coincides with the \lstinline!1+k! activation of \lstinline!u!. \begin{nonnormative} Thus \lstinline!subSample(superSample(u, factor), factor)=u! \end{nonnormative} @@ -743,8 +739,8 @@ \subsection{Sub-clock conversion operators}\doublelabel{sub-clock-conversion-ope \end{example*} \\ \hline \begin{tabular}{@{}p{4cm}@{}} -\textbf{shiftSample}(u,\\ -shiftCounter, resolution) +\lstinline!shiftSample(u!,\\ +\lstinline!shiftCounter, resolution)! \end{tabular} & The operator \lstinline!c=shiftSample(u,k,resolution)! splits the interval between ticks of \lstinline!u! into \lstinline!resolution! equidistant intervals \lstinline!i!. @@ -771,8 +767,8 @@ \subsection{Sub-clock conversion operators}\doublelabel{sub-clock-conversion-ope \end{nonnormative*} \\ \hline \begin{tabular}{@{}p{4cm}@{}} -\textbf{backSample}(u,\\ -backCounter, resolution) +\lstinline!backSample(u,!\\ +\lstinline!backCounter, resolution)! \end{tabular} & The input argument u is either a \emph{component expression} (see @@ -809,12 +805,12 @@ \subsection{Sub-clock conversion operators}\doublelabel{sub-clock-conversion-ope \end{lstlisting} \end{example*} \\ \hline -\textbf{noClock}(u) +\lstinline!noClock(u)! & -The clock of y = \textbf{noClock}(u) is always inferred. At every tick -of the clock of y, the operator returns the value of u from the last -tick of the clock of u. If \textbf{noClock}(u) is called before the -first tick of the clock of u, the start value of u is returned.\\ \hline +The clock of \lstinline!y = noClock(u)! is always inferred. At every tick +of the clock of \lstinline!y!, the operator returns the value of \lstinline!u! from the last +tick of the clock of \lstinline!u!. If \lstinline!noClock(u)! is called before the +first tick of the clock of \lstinline!u!, the start value of \lstinline!u! is returned.\\ \hline \end{longtable} \begin{nonnormative} @@ -960,10 +956,10 @@ \subsection{Base-clock Partitioning}\doublelabel{base-clock-partitioning} % This is not how you are supposed to format things in LaTeX \begin{tabular}{p{1cm}p{1cm}p{1cm}p{12cm}} -\multicolumn{4}{p{15cm}}{\textbf{incidence}(e) = the \emph{unknown} variables, as well as -variables x in \textbf{der}(x), \textbf{pre}(x), and \textbf{previous}(x),}\\ -&\multicolumn{3}{p{14cm}}{which lexically appear in e}\\ -&&\multicolumn{2}{p{13cm}}{except as first argument of base-clock conversion operators: sample() and hold() and Clock(condition,startInterval).} +\multicolumn{4}{p{15cm}}{\lstinline!incidence(e)! = the \emph{unknown} variables, as well as +variables \lstinline!x! in \lstinline!der(x)!, \lstinline!pre(x)!, and \lstinline!previous(x)!,}\\ +&\multicolumn{3}{p{14cm}}{which lexically appear in \lstinline!e!}\\ +&&\multicolumn{2}{p{13cm}}{except as first argument of base-clock conversion operators: \lstinline!sample! and \lstinline!hold! and \lstinline!Clock(condition, startInterval)!.} \end{tabular} The resulting set of connected components, is the partitioning of the @@ -978,10 +974,13 @@ \subsection{Base-clock Partitioning}\doublelabel{base-clock-partitioning} A variable u in \lstinline!sample(u)!, a variable y in y = \lstinline!hold(ud)!, and a variable b in \lstinline!Clock(b, startInterval)! where b is of \lstinline!Boolean! type is in a continuous-time partition. -Correspondingly, variables u and y in y = \textbf{sample}(uc), y = -\textbf{subSample}(u), y = \textbf{superSample}(u), y = -\textbf{shiftSample}(u), y = \textbf{backSample}(u), y = -\textbf{previous}(u), are in a clocked partition. Equations in a clocked +Correspondingly, variables \lstinline!u! and \lstinline!y! in +\lstinline!y = sample(uc)!, +\lstinline!y = subSample(u)!, +\lstinline!y = superSample(u)!, +\lstinline!y = shiftSample(u)!, +\lstinline!y = backSample(u)!, +\lstinline!y = previous(u)!, are in a clocked partition. Equations in a clocked when clause are also in a clocked partition. Other partitions where none of the variables in the partition are associated with any of the operators above have an unspecified partition @@ -1034,9 +1033,8 @@ \subsection{Sub-clock Partitioning}\doublelabel{sub-clock-partitioning} % This is not how you are supposed to format things in LaTeX \begin{tabular}{p{1cm}p{1cm}p{1cm}p{12cm}} -\multicolumn{4}{p{15cm}}{\textbf{incidence}(e) = the \emph{unknown} variables, as well as -variables x in \textbf{der}(x), \textbf{pre}(x), and -\textbf{previous}(x),}\\ +\multicolumn{4}{p{15cm}}{\lstinline!incidence(e)! = the \emph{unknown} variables, as well as +variables \lstinline!x! in \lstinline!der(x)!, \lstinline!pre(x)!, and \lstinline!previous(x)!,}\\ &\multicolumn{3}{p{14cm}}{which lexically appear in e}\\ &&\multicolumn{2}{p{13cm}}{except as first argument of sub-clock conversion operators:}\\ &&&\multicolumn{1}{p{12cm}}{subSample, superSample, shiftSample, backSample, noClock, and Clock with first argument of \lstinline!Boolean! type.} @@ -1157,7 +1155,7 @@ \subsection{Clocked Discrete-Time and Clocked Discretized Continuous-Time Partit partition. If a clocked partition contains no operator \lstinline!der!, -\lstinline!delay!, \textbf{spatialDistribution}, no event related operators +\lstinline!delay!, \lstinline!spatialDistribution!, no event related operators from \autoref{event-related-operators-with-function-syntax} (with exception of \lstinline!noEvent!), and no \lstinline!when!-clause with a \lstinline!Boolean! condition, it is a \firstuse{clocked discrete-time} partition. @@ -1226,36 +1224,33 @@ \subsection{Solver Methods}\doublelabel{solver-methods} The solvers are defined with respect to the underlying ordinary differential equation in state space form to which the continuous-time -partition can be transformed, at least conceptually (\emph{t} is time, -\textbf{u}\textsubscript{c}(\emph{t}) is the continuous-time Real vector -of input variables, \textbf{u}\textsubscript{d}(\emph{t}) is the -discrete-time Real/Integer/Boolean/String vector of input variables, -\textbf{x}(\emph{t}) is the continuous-time real vector of states, and -\textbf{y}(\emph{t}) is the continuous-time or discrete-time -Real/Integer/Boolean/String vector of algebraic and/or output -variables): -\begin{eqnarray*} -\dot{x}&=&f(x, u, t)\\ -y&=&g(x, u, t) -\end{eqnarray*} +partition can be transformed, at least conceptually ($t$ is time, +$u_{c}(t)$ is the continuous-time \lstinline!Real! vector +of input variables, $u_{d}(t)$ is the +discrete-time \lstinline!Real!/\lstinline!Integer!/\lstinline!Boolean!/\lstinline!String! vector of input variables, +$x(t)$ is the continuous-time real vector of states, and +$y(t)$ is the continuous-time or discrete-time +\lstinline!Real!/\lstinline!Integer!/\lstinline!Boolean!/\lstinline!String! vector of algebraic and/or output variables): +\begin{align*} +\dot{x} &= f(x, u, t)\\ +y &= g(x, u, t) +\end{align*} A solver method is applied on a subclock partition. Such a partition has -explicit inputs \textbf{u} marked by \lstinline!sample(u)!, -\lstinline!subSample(u)!, \lstinline!superSample(u)!, \lstinline!shiftSample(u)! -and/or \lstinline!backSample(u)!. Furthermore, the outputs \textbf{y} of -such a partition are marked by \lstinline!hold(y)!, \lstinline!subSample(y)!, -\lstinline!superSample(y)!, \lstinline!shiftSample(y)!, and/or -\lstinline!backSample(y)!. The arguments of these operators are to be used -as input signals \textbf{u} and output signals \textbf{y} in the +explicit inputs $u$ marked by \lstinline[mathescape=true]!sample($u$)!, +\lstinline[mathescape=true]!subSample($u$)!, \lstinline[mathescape=true]!superSample($u$)!, \lstinline[mathescape=true]!shiftSample($u$)! +and/or \lstinline[mathescape=true]!backSample($u$)!. Furthermore, the outputs $y$ of +such a partition are marked by \lstinline[mathescape=true]!hold($y$)!, \lstinline[mathescape=true]!subSample($y$)!, +\lstinline[mathescape=true]!superSample($y$)!, \lstinline[mathescape=true]!shiftSample($y$)!, and/or +\lstinline[mathescape=true]!backSample($y$)!. The arguments of these operators are to be used +as input signals $u$ and output signals $y$ in the conceptual ordinary differential equation above, and in the discretization formulae below, respectively. The solver methods (with exception of \lstinline!"External"!) are defined by -integrating from clock tick \emph{t}\textsubscript{i-1} to clock tick -\emph{t}\textsubscript{i} and computing the desired variables at -\emph{t}\textsubscript{i}, with \emph{h} = \emph{t}\textsubscript{i} -- -\emph{t}\textsubscript{i-1} = \lstinline!interval(u)! and -\textbf{x}\emph{\textsubscript{i}} = -\textbf{x}(\emph{t\textsubscript{i}}): +integrating from clock tick $t_{i-1}$ to clock tick +$t_{i}$ and computing the desired variables at +$t_{i}$, with $h = t_{i} - t_{i-1} = \text{\lstinline!interval!}(u)!$ and +$x_{i} = x(t_{i})$: \begin{longtable}[]{|p{3.5cm}|p{11cm}|} \hline \emph{SolverMethod} & @@ -1417,8 +1412,8 @@ \section{Initialization of Clocked Partitions}\doublelabel{initialization-of-clo initial algorithm sections. \item Attribute \lstinline!fixed! cannot be applied on clocked discrete-time - variables. The attribute \lstinline!fixed! is true for variables to which the - \textbf{previous} operator is applied, otherwise false. + variables. The attribute \lstinline!fixed! is true for variables to which + \lstinline!previous! is applied, otherwise false. \end{itemize} \section{Other Operators}\doublelabel{other-operators} @@ -1426,12 +1421,12 @@ \section{Other Operators}\doublelabel{other-operators} The following additional utility operators are provided: \begin{longtable}[]{|l|p{12cm}|} \hline \endhead -\textbf{firstTick}(u)& +\lstinline!firstTick(u)! & This operator returns true at the first tick of the clock of the expression, in which this operator is called. The operator returns false at all subsequent ticks of the clock. The optional argument u is only used for clock inference, see \autoref{clock-partitioning}.\\ \hline -\textbf{interval}(u)& +\lstinline!interval(u)! & This operator returns the interval between the previous and present tick of the clock of the expression, in which this operator is called. The optional argument u is only used for clock inference, see \autoref{clock-partitioning}. From 28f3c601e95d5c90450dd4e1b330bc867cace44a Mon Sep 17 00:00:00 2001 From: Henrik Tidefelt Date: Sun, 7 Jun 2020 23:11:35 +0200 Subject: [PATCH 41/78] Remove \textbf from two cases where no special formatting fits I considered \emph, but didn't find it appropriate. --- chapters/synchronous.tex | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/chapters/synchronous.tex b/chapters/synchronous.tex index 795a48c9d..53a596f57 100644 --- a/chapters/synchronous.tex +++ b/chapters/synchronous.tex @@ -1115,7 +1115,7 @@ \section{Continuous-Time Equations in Clocked Partitions}\doublelabel{continuous equations are solved with the defined integration method between clock ticks. -From the \textbf{view of the continuous-time partition}, the clock ticks are not interpreted as events, but as step-sizes of the integrator that the integrator must exactly hit. +From the view of the continuous-time partition, the clock ticks are not interpreted as events, but as step-sizes of the integrator that the integrator must exactly hit. Hence, no event handling is triggered at clock ticks (provided an explicit event is not triggered from the model at this time instant). \begin{nonnormative} @@ -1128,7 +1128,7 @@ \section{Continuous-Time Equations in Clocked Partitions}\doublelabel{continuous as needed for hard real-time requirements). \end{nonnormative} -From the \textbf{view of the clocked partition}, the continuous-time +From the view of the clocked partition, the continuous-time partition is discretized and the discretized continuous-time variables have only a value at a clock tick. Therefore, such a partition is handled in the same way as any other clocked partition. Especially, From cc46a8e5d19c329c3b03edb7015adef1acf9fe06 Mon Sep 17 00:00:00 2001 From: Henrik Tidefelt Date: Sun, 7 Jun 2020 23:14:04 +0200 Subject: [PATCH 42/78] Fix some formatting of examples and nonnormative content in tables --- chapters/synchronous.tex | 38 ++++++++++++++++++++------------------ 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/chapters/synchronous.tex b/chapters/synchronous.tex index 53a596f57..8e877843e 100644 --- a/chapters/synchronous.tex +++ b/chapters/synchronous.tex @@ -215,15 +215,14 @@ \subsection{Clocks and Clocked Variables}\doublelabel{clocks-and-clocked-variabl that defines when the clock ticks (is active) at a particular time instant, or it is defined with clock operators relatively to other clocks, see \autoref{base-clock-conversion-operators}. - -\begin{example} +\par +\begin{example*} \begin{lstlisting}[language=modelica,mathescape=true] Clock c1 = Clock($\ldots$); Clock c2 = c1; Clock c3 = subSample(c2, 4); \end{lstlisting} -\end{example} - +\end{example*} \end{tabular}\\ \hline \begin{tabular}{p{7cm}} \includegraphics[width=3in,height=1.875in]{clocked} @@ -352,8 +351,8 @@ \section{Clock Constructors}\doublelabel{clock-constructors} \textbf{Inferred Clock}\\ The operator returns a clock that is inferred. - -\begin{example} +\par +\begin{example*} \begin{lstlisting}[language=modelica] when Clock() then // equations are on the same clock x = A*previous(x) + B*u; @@ -367,7 +366,7 @@ \section{Clock Constructors}\doublelabel{clock-constructors} This style is useful if a modeler would clearly like to mark the equations that must belong to one clock (although a tool could figure this out as well, if the when-clause is not present). -\end{example} +\end{example*} \end{tabular}\\ \hline \begin{tabular}{@{}p{29mm}@{}} \lstinline!Clock!(\newline @@ -399,8 +398,9 @@ \section{Clock Constructors}\doublelabel{clock-constructors} \begin{nonnormative} The given interval and time shift can be modified by using the subSample, superSample, shiftSample and backSample operators on the returned clock, see \autoref{sub-clock-conversion-operators}. +\end{nonnormative} -Example: +\begin{example} \begin{lstlisting}[language=modelica] // first clock tick: previous(nextInterval)=2 Integer nextInterval(start=2); @@ -418,7 +418,7 @@ \section{Clock Constructors}\doublelabel{clock-constructors} y2 = previous(y2) + 1; end when; \end{lstlisting} -\end{nonnormative} +\end{example} Note that operator \lstinline!interval(c)! of \lstinline!Clock c = Clock(nextInterval, resolution)! returns:\newline \lstinline!previous(intervalCounter) / resolution; // in seconds! @@ -441,11 +441,12 @@ \section{Clock Constructors}\doublelabel{clock-constructors} at time t\textsubscript{start}+interval1, the next clock tick is scheduled at \lstinline!interval2 = previous(interval)!, and so on. If interval is a parameter expression, the clock defines a periodic clock. -\begin{nonnormative} +\par +\begin{nonnormative*} Note, the clock is defined with \lstinline!previous(interval)!. Therefore, for sorting the input argument is treated as known. The given interval and time shift can be modified by using the subSample, superSample, shiftSample and backSample operators on the returned clock, see \autoref{sub-clock-conversion-operators}. There are restrictions where this operator can be used, see Clock expressions below. -\end{nonnormative} +\end{nonnormative*} \end{tabular}\\ \hline \begin{tabular}{@{}p{29mm}@{}} \lstinline!Clock!(\newline @@ -461,10 +462,12 @@ \section{Clock Constructors}\doublelabel{clock-constructors} value returned by \lstinline!interval()! at the first tick of the clock, see \autoref{initialization-of-clocked-partitions}. The output argument is of base type Clock that ticks when \lstinline!edge(condition)! becomes true. - \begin{nonnormative} This clock is used to trigger a clocked partition due to a state event, that is a zero-crossing of a Real variable, in a continuous-time partition or due to a hardware interrupt -that is modeled as Boolean in the simulation model. Example: +that is modeled as Boolean in the simulation model. +\end{nonnormative} +\par +\begin{example*} \begin{lstlisting}[language=modelica] Clock c = Clock(angle > 0, 0.1) // before first tick of c: // interval(c) = 0.1 @@ -474,7 +477,7 @@ \section{Clock Constructors}\doublelabel{clock-constructors} using the subsample, superSample, shiftSample and backSample operators on the returned clock, see \autoref{sub-clock-conversion-operators}, provided the base interval is not smaller than the implicitly given interval. -\end{nonnormative} +\end{example*} \end{tabular}\\ \hline \begin{tabular}{@{}p{29mm}@{}} \lstinline!Clock!(\newline @@ -490,16 +493,15 @@ \section{Clock Constructors}\doublelabel{clock-constructors} of type String \lstinline!solverMethod!. The meaning of solverMethod is defined in \autoref{solver-methods}. If the second input argument solverMethod is an empty String, then this Clock-construct does not associate an integrator with the returned clock. - -\begin{example} +\par +\begin{example*} \begin{lstlisting}[language=modelica] Clock c1 = Clock(1,10) // 100 ms, no solver Clock c2 = Clock(c1, "ImplicitTrapezoid"); // 100 ms, ImplicitTrapezoid solver Clock c3 = Clock(c2, ""); // 100 ms, no solver \end{lstlisting} -\end{example} -\strut +\end{example*} \end{tabular} \\ \hline \end{longtable} From a1290c5145c4a3afa2e18da6f2473569c0538f64 Mon Sep 17 00:00:00 2001 From: Henrik Tidefelt Date: Sun, 7 Jun 2020 23:15:30 +0200 Subject: [PATCH 43/78] Use \firstuse instead of \textbf when introducing base clock partition types --- chapters/synchronous.tex | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/chapters/synchronous.tex b/chapters/synchronous.tex index 8e877843e..fa3786529 100644 --- a/chapters/synchronous.tex +++ b/chapters/synchronous.tex @@ -969,9 +969,7 @@ \subsection{Base-clock Partitioning}\doublelabel{base-clock-partitioning} \textless{}E\textsubscript{i}, V\textsubscript{i}\textgreater{}, according to base-clocks and continuous-time partitions. -The base clock partitions are identified as \textbf{clocked} or as -\textbf{continuous-time partitions} according to the following -properties: +The base clock partitions are identified as \firstuse{clocked} or as \firstuse{continuous-time partitions} according to the following properties: A variable u in \lstinline!sample(u)!, a variable y in y = \lstinline!hold(ud)!, and a variable b in \lstinline!Clock(b, startInterval)! where b is of \lstinline!Boolean! type is in a continuous-time partition. From 7d68fbd3005bea5ee8e488310a14a791265c75a8 Mon Sep 17 00:00:00 2001 From: Henrik Tidefelt Date: Sun, 7 Jun 2020 23:18:10 +0200 Subject: [PATCH 44/78] Remove \textbf on 'active' where it is neither introduced nor deserving emphasis This instance of 'active' doesn't seem to differ in any significant way from the other nearby uses of 'active' that have no special formatting. --- chapters/synchronous.tex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/chapters/synchronous.tex b/chapters/synchronous.tex index fa3786529..d9689ccb0 100644 --- a/chapters/synchronous.tex +++ b/chapters/synchronous.tex @@ -232,7 +232,7 @@ \subsection{Clocks and Clocked Variables}\doublelabel{clocks-and-clocked-variabl base type \lstinline!Real!, \lstinline!Integer!, \lstinline!Boolean!, enumeration, \lstinline!String! that are associated uniquely with a clock \lstinline[mathescape=true]!c($t_{i}$)!. A clocked variable can only be directly accessed at the event instant -where the associated clock is \textbf{active}. A constant and a +where the associated clock is active. A constant and a parameter can always be used at a place where a clocked variable is required. From 4a979d8dc1396a626086ff24e8f7b195e79d0e34 Mon Sep 17 00:00:00 2001 From: Henrik Tidefelt Date: Sun, 7 Jun 2020 23:19:27 +0200 Subject: [PATCH 45/78] Use \tablehead instead of \textbf for some kind of table title --- chapters/synchronous.tex | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/chapters/synchronous.tex b/chapters/synchronous.tex index d9689ccb0..b1f538f45 100644 --- a/chapters/synchronous.tex +++ b/chapters/synchronous.tex @@ -189,9 +189,11 @@ \subsection{Clocks and Clocked Variables}\doublelabel{clocks-and-clocked-variabl defined. In this chapter, two additional kinds of discrete-time expressions/variables are defined that are associated to clocks and are therefore called \firstuse{clocked discrete-time} expressions: +% henrikt-ma: Misusing \tablehead inside the table below to act as some sort of table title. +% This is all different than how things are done elsewhere, but fixing this is considered a topic for issue #2562. \begin{longtable}[]{|p{7.3cm}|p{7.3cm}|} \hline -\multicolumn{2}{|p{14.6cm}|}{\textbf{The different kinds of discrete-time variables in Modelica}}\\ \hline +\multicolumn{2}{|p{14.6cm}|}{\tablehead{The different kinds of discrete-time variables in Modelica}}\\ \hline \endhead \begin{tabular}{p{7cm}} \includegraphics[width=3in,height=1.875in]{piecewise} From 3e94d51fd3f2b4c5c8ba4a1123ca2cc5f9e040f3 Mon Sep 17 00:00:00 2001 From: Henrik Tidefelt Date: Sun, 7 Jun 2020 23:20:23 +0200 Subject: [PATCH 46/78] Replace \textbf by \firstuse when terms are introduced in tables --- chapters/synchronous.tex | 27 +++++++++++---------------- 1 file changed, 11 insertions(+), 16 deletions(-) diff --git a/chapters/synchronous.tex b/chapters/synchronous.tex index b1f538f45..a7bc3e07d 100644 --- a/chapters/synchronous.tex +++ b/chapters/synchronous.tex @@ -190,6 +190,8 @@ \subsection{Clocks and Clocked Variables}\doublelabel{clocks-and-clocked-variabl expressions/variables are defined that are associated to clocks and are therefore called \firstuse{clocked discrete-time} expressions: % henrikt-ma: Misusing \tablehead inside the table below to act as some sort of table title. +% Similarly, while this table is actually a list of definitions, the styling of the terms being described +% should probably use something else than \firstuse, perhaps more like a 'description' environment. % This is all different than how things are done elsewhere, but fixing this is considered a topic for issue #2562. \begin{longtable}[]{|p{7.3cm}|p{7.3cm}|} \hline @@ -197,9 +199,8 @@ \subsection{Clocks and Clocked Variables}\doublelabel{clocks-and-clocked-variabl \endhead \begin{tabular}{p{7cm}} \includegraphics[width=3in,height=1.875in]{piecewise} -\end{tabular}&\begin{tabular}{p{7cm}}\textbf{Piecewise-constant variables (see \autoref{discrete-time-expressions})} - -Variables \lstinline!m(t)! of base type \lstinline!Real!, \lstinline!Integer!, \lstinline!Boolean!, +\end{tabular}&\begin{tabular}{p{7cm}}\firstuse{Piecewise-constant variables}\\ +(See \autoref{discrete-time-expressions}.) Variables \lstinline!m(t)! of base type \lstinline!Real!, \lstinline!Integer!, \lstinline!Boolean!, enumeration, and \lstinline!String! that are \emph{constant} inside each interval t\textsubscript{i} $\le$ t \textless{} t\textsubscript{i+1} (= piecewise constant continuous-time variables). In other words, \lstinline!m(t)! @@ -210,8 +211,7 @@ \subsection{Clocks and Clocked Variables}\doublelabel{clocks-and-clocked-variabl \begin{tabular}{p{7cm}} \includegraphics[width=3in,height=1.875in]{clock} \end{tabular}& -\begin{tabular}{p{7cm}}\textbf{Clock variables} - +\begin{tabular}{p{7cm}}\firstuse{Clock variables}\\ Clock variables \lstinline[mathescape=true]!c($t_{i}$)! are of base type \lstinline!Clock!. A clock is either defined by a constructor (such as \lstinline!Clock(3)!) that defines when the clock ticks (is active) at a particular time @@ -229,7 +229,7 @@ \subsection{Clocks and Clocked Variables}\doublelabel{clocks-and-clocked-variabl \begin{tabular}{p{7cm}} \includegraphics[width=3in,height=1.875in]{clocked} \end{tabular}& -\begin{tabular}{p{7cm}}\textbf{Clocked variables} +\begin{tabular}{p{7cm}}\firstuse{Clocked variables}\\ The elements of clocked variables \lstinline[mathescape=true]!r($t_{i}$)! are of base type \lstinline!Real!, \lstinline!Integer!, \lstinline!Boolean!, enumeration, \lstinline!String! that are associated uniquely with a clock \lstinline[mathescape=true]!c($t_{i}$)!. A @@ -350,8 +350,7 @@ \section{Clock Constructors}\doublelabel{clock-constructors} \lstinline!Clock()! & \begin{tabular}{@{}p{119mm}@{}} -\textbf{Inferred Clock}\\ - +\firstuse{Inferred Clock}\\ The operator returns a clock that is inferred. \par \begin{example*} @@ -377,8 +376,7 @@ \section{Clock Constructors}\doublelabel{clock-constructors} \end{tabular} & \begin{tabular}{@{}p{119mm}@{}} -\textbf{Clock with Rational Interval}\\ - +\firstuse{Clock with Rational Interval}\\ The first input argument, \lstinline!intervalCounter!, is a clocked Component Expression (see \autoref{argument-restrictions-component-expression}) or a parameter expression of type \lstinline!Integer! with \lstinline!min=0!. The optional second argument \lstinline!resolution! @@ -428,8 +426,7 @@ \section{Clock Constructors}\doublelabel{clock-constructors} \lstinline!Clock(interval)! & \begin{tabular}{@{}p{119mm}@{}} -\textbf{Clock with Real Interval}\\ - +\firstuse{Clock with Real Interval}\\ The input argument, \lstinline!interval!, is a clocked Component Expression (see \autoref{argument-restrictions-component-expression}) or a parameter expression. The \lstinline!interval! must be strictly positive (\lstinline!interval>0.0!) of type \lstinline!Real! with \lstinline!unit="s"!. @@ -457,8 +454,7 @@ \section{Clock Constructors}\doublelabel{clock-constructors} \end{tabular} & \begin{tabular}{@{}p{119mm}@{}} -\textbf{Event Clock}\\ - +\firstuse{Event Clock}\\ The input argument, \lstinline!condition!, is a continuous-time expression of type Boolean. The optional \lstinline!startInterval! argument (default = 0.0) is the value returned by \lstinline!interval()! at the first tick of @@ -488,8 +484,7 @@ \section{Clock Constructors}\doublelabel{clock-constructors} \end{tabular} & \begin{tabular}{@{}p{119mm}@{}} -\textbf{Solver Clock}\\ - +\firstuse{Solver Clock}\\ The first input argument \lstinline!c! is a clock and the operator returns this clock. The returned clock is associated with the second input argument of type String \lstinline!solverMethod!. The meaning of solverMethod is defined From 9e19079bdb1b6c47899576e29b079c78e74561e9 Mon Sep 17 00:00:00 2001 From: Henrik Tidefelt Date: Sun, 7 Jun 2020 23:34:22 +0200 Subject: [PATCH 47/78] Use item list instead of beginning each semiLinear rule with \textbf{Rule X} --- chapters/operatorsandexpressions.tex | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/chapters/operatorsandexpressions.tex b/chapters/operatorsandexpressions.tex index fc2480bb0..b188f2bfc 100644 --- a/chapters/operatorsandexpressions.tex +++ b/chapters/operatorsandexpressions.tex @@ -1016,9 +1016,9 @@ \subsubsection{semiLinear}\doublelabel{semilinear} solutions. It is recommended that the following rules are used to transform the equations during the translation phase in order to select one meaningful solution in such cases: - -\textbf{Rule 1}: The equations - +\begin{itemize} +\item +The equations \begin{lstlisting}[language=modelica] y = semiLinear(x, sa, s1); y = semiLinear(x, s1, s2); @@ -1027,7 +1027,6 @@ \subsubsection{semiLinear}\doublelabel{semilinear} y = semiLinear(x, sN, sb); ... \end{lstlisting} - may be replaced by \begin{lstlisting}[language=modelica, mathescape=true] s1 = if x >= 0 then sa else sb @@ -1038,19 +1037,20 @@ \subsubsection{semiLinear}\doublelabel{semilinear} y = semiLinear(x, sa, sb); \end{lstlisting} -\textbf{Rule 2}: The equations +\item +The equations \begin{lstlisting}[language=modelica] x = 0; y = 0; y = semiLinear(x, sa, sb); \end{lstlisting} - may be replaced by \begin{lstlisting}[language=modelica] x = 0 y = 0; sa = sb; \end{lstlisting} +\end{itemize} \begin{nonnormative} For symbolic transformations, the following property is useful From b0548ba3690437db5e4a8c1879a0483215875d94 Mon Sep 17 00:00:00 2001 From: Henrik Tidefelt Date: Mon, 8 Jun 2020 00:12:25 +0200 Subject: [PATCH 48/78] Introduce \numbereddefinition instead of \textbf for numbered definitions --- chapters/classes.tex | 8 ++++---- chapters/interface.tex | 6 +++--- preamble.tex | 9 +++++++++ 3 files changed, 16 insertions(+), 7 deletions(-) diff --git a/chapters/classes.tex b/chapters/classes.tex index 2c7899995..970648d02 100644 --- a/chapters/classes.tex +++ b/chapters/classes.tex @@ -960,7 +960,7 @@ \section{Balanced Models}\doublelabel{balanced-models} components are included -- possibly modified. The corresponding restrictions on connectors and connections are in \autoref{restrictions-of-connections-and-connectors}. -\textbf{Definition 1: Local Number of Unknowns} +\numbereddefinition{Local Number of Unknowns} The \firstuse{local number of unknowns} of a model or block class is the sum based on the components: @@ -991,7 +991,7 @@ \section{Balanced Models}\doublelabel{balanced-models} scalars of primitive types). \end{itemize} -\textbf{Definition 2: Local Equation Size} +\numbereddefinition{Local Equation Size} The \firstuse{local equation size} of a model or block class is the sum of the following numbers: @@ -1034,7 +1034,7 @@ \section{Balanced Models}\doublelabel{balanced-models} supplied when using the model. \end{nonnormative} -\textbf{Definition 3: Locally Balanced} +\numbereddefinition{Locally Balanced} A model or block class is \firstuse{locally balanced} if the \emph{local number of unknowns} is identical to the \emph{local equation size} for all legal @@ -1046,7 +1046,7 @@ \section{Balanced Models}\doublelabel{balanced-models} arrays of (locally) undefined sizes, conditional declarations, for loops etc. \end{nonnormative} -\textbf{Definition 4: Globally Balanced} +\numbereddefinition{Globally Balanced} Similarly as locally balanced, but including all unknowns and equations from all components. The global number of unknowns is computed by diff --git a/chapters/interface.tex b/chapters/interface.tex index 66c60b1ff..33fbc9675 100644 --- a/chapters/interface.tex +++ b/chapters/interface.tex @@ -462,7 +462,7 @@ \section{Plug-Compatibility or Restricted Subtyping}\doublelabel{plug-compatibil connected by default. \end{nonnormative} -\textbf{Definition 5: Plug-compatibility (= restricted subtyping)} +\numbereddefinition{Plug-compatibility (= restricted subtyping)} An interface \lstinline!A! is plug-compatible with (a restricted subtype of) an interface \lstinline!B! (or the constraining interface of \lstinline!B!) iff: @@ -474,7 +474,7 @@ \section{Plug-Compatibility or Restricted Subtyping}\doublelabel{plug-compatibil default-connectable (as defined below). \end{itemize} -\textbf{Definition 6: Default connectable} +\numbereddefinition{Default connectable} A component of an interface is default-connectable iff: \begin{itemize} @@ -577,7 +577,7 @@ \section{Function-Compatibility or Function-Subtyping for Functions}\doublelabel existing calls. \end{nonnormative} -\textbf{Definition 7: Function-Compatibility or Function-Subtyping for Functions} +\numbereddefinition{Function-Compatibility or Function-Subtyping for Functions} A function class \lstinline!A! is \emph{function-compatible with or a function subtype of} function class \lstinline!B! iff (the terms \emph{function-compatible} diff --git a/preamble.tex b/preamble.tex index 416c3d685..f9bfaa879 100644 --- a/preamble.tex +++ b/preamble.tex @@ -137,6 +137,15 @@ \newcommand{\bibitemtitle}[1]{\emph{#1}} +% henrikt-ma: Introducing semantic macro for 7 definitions spread out over two chapters +% that for unclear reasons use their own style, including numbering. Sorting out if numbered +% definitions should be used more or not at all is part of issue #2570. +\newcounter{defnumber} +\newcommand{\numbereddefinition}[1]{% +\stepcounter{defnumber}% +\paragraph*{Definition~\thedefnumber: #1.}% +} + \setcounter{secnumdepth}{5} % Note: Toc changed for appendex \setcounter{tocdepth}{1} From 2ce6fa1d1b7f9f4598e8ec4238455ee3e9377190 Mon Sep 17 00:00:00 2001 From: Henrik Tidefelt Date: Mon, 8 Jun 2020 00:22:05 +0200 Subject: [PATCH 49/78] Use item list instead of \textbf for the only 'Proposition' there is --- chapters/classes.tex | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/chapters/classes.tex b/chapters/classes.tex index 970648d02..80a2e349a 100644 --- a/chapters/classes.tex +++ b/chapters/classes.tex @@ -1104,12 +1104,10 @@ \section{Balanced Models}\doublelabel{balanced-models} \end{nonnormative} \end{itemize} -Based on these restrictions, the following strong guarantee can be given -for simulation models and blocks: - -\textbf{Proposition 1:} - -All simulation models and blocks are globally balanced. +Based on these restrictions, the following strong guarantee can be given: +\begin{itemize} +\item All simulation models and blocks are globally balanced. +\end{itemize} \begin{nonnormative} Therefore the number of unknowns equal to the number of equations of a simulation model or block, provided that every used From a6e287196cc96b0b8f5b11a8a817942ac39fa2e0 Mon Sep 17 00:00:00 2001 From: Henrik Tidefelt Date: Mon, 8 Jun 2020 00:33:55 +0200 Subject: [PATCH 50/78] Remove \textbf on the single restriction that has it in a list of five --- chapters/classes.tex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/chapters/classes.tex b/chapters/classes.tex index 80a2e349a..a17f5f9bb 100644 --- a/chapters/classes.tex +++ b/chapters/classes.tex @@ -1098,7 +1098,7 @@ \section{Balanced Models}\doublelabel{balanced-models} modifiers for components may in these cases only be for parameters, constants, inputs and variables having a default binding equation. \item - \textbf{All non-partial model and block classes must be locally balanced.} + All non-partial model and block classes must be locally balanced. \begin{nonnormative} This means that the local number of unknowns equals the local equation size. \end{nonnormative} From 7d24d5dc25af90d75020b8d0236e5f865a87cf73 Mon Sep 17 00:00:00 2001 From: Henrik Tidefelt Date: Mon, 8 Jun 2020 01:01:37 +0200 Subject: [PATCH 51/78] Remove exaggerated emphasis with \textbf in equation/variable balance examples As it's clear from the context that these examples are all about these concepts anyway, it didn't seem motivated to make these terms stand out more with something like \emph. --- chapters/classes.tex | 59 +++++++++++++++----------------------------- 1 file changed, 20 insertions(+), 39 deletions(-) diff --git a/chapters/classes.tex b/chapters/classes.tex index a17f5f9bb..b32e1b7a6 100644 --- a/chapters/classes.tex +++ b/chapters/classes.tex @@ -1146,25 +1146,16 @@ \section{Balanced Models}\doublelabel{balanced-models} \end{align*} and 2 equations corresponding to the 2 flow-variables \lstinline!p.i! and \lstinline!n.i!. -These are 5 equations in 5 unknowns (\textbf{locally} -\textbf{balanced model}). A more detailed analysis would reveal that -this is \textbf{structurally non-singular}, i.e. that the hybrid DAE -will not contain a singularity independent of actual values. - -If the equation \lstinline!u = p.v - n.v! would be missing in the -Capacitor model, there would be 4 equations in 5 unknowns and the model -would be \textbf{locally} \textbf{unbalanced} and thus simulation models -in which this model is used would be usually structurally singular and -thus not solvable. - -If the equation \lstinline!u = p.v - n.v! would be replaced by the -equation \lstinline!u = 0! and the equation \lstinline!C*der(u) = p.i! would -be replaced by the equation \lstinline!C*der(u) = 0!, there would be 5 -equations in 5 unknowns (\textbf{locally} \textbf{balanced}), but the -equations would be \textbf{singular}, regardless of how the equations -corresponding to the flow-variables are constructed because the -information that \lstinline!u! is constant is given twice in a slightly -different form. +These are 5 equations in 5 unknowns (locally balanced model). A more detailed analysis would reveal that this is structurally non-singular, i.e. that +the hybrid DAE will not contain a singularity independent of actual values. + +If the equation \lstinline!u = p.v - n.v! would be missing in the \lstinline!Capacitor! model, there would be 4 equations in 5 unknowns and the model +would be locally unbalanced and thus simulation models in which this model is used would be usually structurally singular and thus not solvable. + +If the equation \lstinline!u = p.v - n.v! would be replaced by the equation \lstinline!u = 0! and the equation \lstinline!C*der(u) = p.i! would be +replaced by the equation \lstinline!C*der(u) = 0!, there would be 5 equations in 5 unknowns (locally balanced), but the equations would be singular, +regardless of how the equations corresponding to the flow-variables are constructed because the information that \lstinline!u! is constant is given twice +in a slightly different form. \end{example} \begin{example} @@ -1200,9 +1191,7 @@ \section{Balanced Models}\doublelabel{balanced-models} end Circuit; \end{lstlisting} -Since \lstinline!t! is partial we cannot check whether this is a -\textbf{globally balanced model}, but we can check that \lstinline!Circuit! -is \textbf{locally balanced}. +Since \lstinline!t! is partial we cannot check whether this is a globally balanced model, but we can check that \lstinline!Circuit! is locally balanced. Counting on model \lstinline!Circuit! results in the following balance sheet: @@ -1219,9 +1208,7 @@ \section{Balanced Models}\doublelabel{balanced-models} \end{align*} and 2 equation corresponding to the flow variables \lstinline!p.i!, \lstinline!n.i!. -In total we have 8 scalar unknowns and 8 scalar equations, i.e., a -\textbf{locally} \textbf{balanced model} (and this feature holds for any -models used for the replaceable component \lstinline!t!). +In total we have 8 scalar unknowns and 8 scalar equations, i.e., a locally balanced model (and this feature holds for any models used for the replaceable component \lstinline!t!). Some more analysis reveals that this local set of equations and unknowns is structurally non-singular. However, this does not provide @@ -1359,7 +1346,7 @@ \section{Balanced Models}\doublelabel{balanced-models} $2 + \text{\lstinline!nXi!}$ flow variables in the \lstinline!port! connector. \end{itemize} -Therefore, \lstinline!DynamicVolume! is a \textbf{locally balanced} model. +Therefore, \lstinline!DynamicVolume! is a locally balanced model. Note, when the \lstinline!DynamicVolume! is used and the \lstinline!Medium! model is redeclared to \lstinline!SimpleAir!, then a tool will try @@ -1410,19 +1397,13 @@ \section{Balanced Models}\doublelabel{balanced-models} $2 + \text{\lstinline!nXi!}$ flow variables in the \lstinline!port! connector. \end{itemize} -Therefore, \lstinline!FixedBoundary_pTX! is a \textbf{locally -balanced} model. The predefined boundary variables \lstinline!p! and \lstinline!Xi! -are provided via equations to the input arguments \lstinline!medium.p! -and \lstinline!medium.Xi!, in addition there is an equation for \lstinline!T! -in the same way -- even though \lstinline!T! is not an input. Depending -on the flow direction, either the specific enthalpy in the port -(\lstinline!port.h!) or h is used to compute the enthalpy flow rate -\lstinline!H_flow!. \lstinline!h! is provided as binding equation to the medium. With -the equation \lstinline!medium.T = T!, the specific enthalpy \lstinline!h! of the -reservoir is indirectly computed via the medium equations. Again, this -demonstrates, that an \lstinline!input! just defines the number of equations -have to be provided, but that it not necessarily defines the -computational causality. +Therefore, \lstinline!FixedBoundary_pTX! is a locally balanced model. The predefined boundary variables \lstinline!p! and \lstinline!Xi! are +provided via equations to the input arguments \lstinline!medium.p! and \lstinline!medium.Xi!, in addition there is an equation for \lstinline!T! +in the same way --- even though \lstinline!T! is not an input. Depending on the flow direction, either the specific enthalpy in the port +(\lstinline!port.h!) or \lstinline!h! is used to compute the enthalpy flow rate \lstinline!H_flow!. \lstinline!h! is provided as binding equation +to the medium. With the equation \lstinline!medium.T = T!, the specific enthalpy \lstinline!h! of the reservoir is indirectly computed via the +medium equations. Again, this demonstrates, that an \lstinline!input! just defines the number of equations have to be provided, but that it not +necessarily defines the computational causality. \end{example} \section{Predefined Types and Classes}\doublelabel{predefined-types-and-classes} From 5889480e353921833b84a9f70e30590bd21b10f4 Mon Sep 17 00:00:00 2001 From: Henrik Tidefelt Date: Mon, 8 Jun 2020 01:18:11 +0200 Subject: [PATCH 52/78] Remove use of enumitem.sty to fix continuous integration builds This leaves the 'description' lists with some poor formatting, which we should return to later. --- preamble.tex | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/preamble.tex b/preamble.tex index f9bfaa879..e45491611 100644 --- a/preamble.tex +++ b/preamble.tex @@ -71,7 +71,7 @@ \usepackage{longtable} \usepackage{multirow} % for multirow entries in tables \usepackage{listings} -\usepackage{enumitem} +%\usepackage{enumitem} % Package not available for continuous integration builds. \usepackage{color} \usepackage[table]{xcolor} %\def\doublelabel#1{\label{#1}\hypertarget{#1}{}} @@ -302,12 +302,13 @@ \def\subparagraphautorefname{section} % Make all description lists break the line after each key. -\setlist[description]{ - style=nextline, - labelwidth=0pt, - leftmargin=15pt, - itemindent=\dimexpr-5pt-\labelsep\relax, -} +% henrikt-ma: Commenting out use of the enumitem package, see above. +%\setlist[description]{ +% style=nextline, +% labelwidth=0pt, +% leftmargin=15pt, +% itemindent=\dimexpr-5pt-\labelsep\relax, +%} \title{ \ifpdf From 9d8f0ddd03e6216e0e3afe33afd1309c8d8e7bbf Mon Sep 17 00:00:00 2001 From: Henrik Tidefelt Date: Sat, 13 Jun 2020 00:15:42 +0200 Subject: [PATCH 53/78] Fix strange uses of \emph for external objects Fixes #2557 --- chapters/functions.tex | 34 +++++++++++++--------------------- 1 file changed, 13 insertions(+), 21 deletions(-) diff --git a/chapters/functions.tex b/chapters/functions.tex index 0af705a57..523c240cb 100644 --- a/chapters/functions.tex +++ b/chapters/functions.tex @@ -2555,35 +2555,27 @@ \subsection{External Objects}\doublelabel{external-objects} be complete (e.g., from an initial algorithm or initial equation). The destructor shall delete the object, and must not require any other calls to be made for the deletion to be complete (e.g., from a \lstinline!when terminal()! clause). The constructor may not assume that pointers sent - to the external object will remain valid for the life-time of the - external object. + to the external object will remain valid for the life-time of the external object. An exception is that if the pointer to another external object is + given as argument to the constructor, that pointer will remain valid as long as the other external object lives. \begin{nonnormative} - An exception is that if the pointer to another external object is given as argument to the constructor, that pointer will remain valid as long as the other external object lives. + External objects may be a protected component (or part of one) in a function. The constructor is in that case called at the start of the function call, + and the destructor when the function returns, or when recovering from errors in the function. + \end{nonnormative} + \begin{nonnormative} + External objects may be an input (or part of an input) to a function, in that case the destructor is not called (since the external object is active before + and after the function call). Normally this is an external function, but it could be a non-external function as well (e.g.\ calling external functions one + or more times). The function input may not have a default value using the constructor. \end{nonnormative} - - \emph{External objects may be a protected component (or part of one) - in a function. The constructor is in that case called at the start of - the function call, and the destructor when the function returns, or - when recovering from errors in the function.} - - \emph{External objects may be an input (or part of an input) to a - function, in that case the destructor is not called (since the - external object is active before and after the function call). - Normally this is an external function, but it could be a non-external - function as well (e.g. calling external functions one or more times). - The function input may not have a default value using the - constructor.} \item Classes derived from \lstinline!ExternalObject! can neither be used in an extends-clause nor in a short class definition. \item - Only the constructor may return external objects and external object + Only the constructor may return external objects and an external object can only be bound in component declarations and neither modified later nor assigned to. - - \emph{No function may return a component containing an external object - (since only the constructor may return an external object and the - constructor exactly returns the external object).} + \begin{nonnormative} + It follows that a function cannot return a component containing an external object, since only the constructor may return an external object and the constructor exactly returns the external object. + \end{nonnormative} \item External functions may be defined which operate on the internal memory of an \lstinline!ExternalObject!. An \lstinline!ExternalObject! used as input argument or From 0edfe79710ee4e9eee15fe150ae972ba1c47c177 Mon Sep 17 00:00:00 2001 From: Henrik Tidefelt Date: Sat, 13 Jun 2020 00:27:22 +0200 Subject: [PATCH 54/78] Fix hybrid DAE discrete-time Real equation --- chapters/dae.tex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/chapters/dae.tex b/chapters/dae.tex index 7b5a50fc7..dbb8a6ae6 100644 --- a/chapters/dae.tex +++ b/chapters/dae.tex @@ -29,7 +29,7 @@ \chapter{Modelica DAE Representation}\doublelabel{modelica-dae-representation} c:=f_{\mathrm{c}}(\mathit{relation}(v))\label{eq:crossing} \end{equation} \begin{equation} -\dot{m}:=f_m(v, c) +m := f_{\mathrm{m}}(v, c) \end{equation} \begin{equation} 0=f_x(v, c)\label{eq:dae} From 670478f0f1386460293136182aeebea4b70104a0 Mon Sep 17 00:00:00 2001 From: Henrik Tidefelt Date: Sat, 13 Jun 2020 00:28:16 +0200 Subject: [PATCH 55/78] Don't use function name subscripts formatted as variable names --- chapters/dae.tex | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/chapters/dae.tex b/chapters/dae.tex index dbb8a6ae6..114ab6683 100644 --- a/chapters/dae.tex +++ b/chapters/dae.tex @@ -25,14 +25,14 @@ \chapter{Modelica DAE Representation}\doublelabel{modelica-dae-representation} obtained consisting of differential, algebraic and discrete equations of the following form where ($v := \lbrack \dot{x}; x; y; t; m; \text{\lstinline!pre!}(m); p\rbrack$): \begin{subequations} -\begin{equation} -c:=f_{\mathrm{c}}(\mathit{relation}(v))\label{eq:crossing} +\begin{equation}\label{eq:crossing} +c := f_{\mathrm{c}}(\mathit{relation}(v)) \end{equation} \begin{equation} m := f_{\mathrm{m}}(v, c) \end{equation} -\begin{equation} -0=f_x(v, c)\label{eq:dae} +\begin{equation}\label{eq:dae} +0 = f_{\mathrm{x}}(v, c) \end{equation} \label{eq:hydrid-dae} \end{subequations} From 9aa9b3cf655441b03c494b46084463efaf464961 Mon Sep 17 00:00:00 2001 From: Henrik Tidefelt Date: Sat, 13 Jun 2020 00:31:55 +0200 Subject: [PATCH 56/78] Rewrite to avoid starting sentence with 'homotopy' --- chapters/revisions.tex | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/chapters/revisions.tex b/chapters/revisions.tex index 26a4ee1f1..bf2b05a3b 100644 --- a/chapters/revisions.tex +++ b/chapters/revisions.tex @@ -1271,8 +1271,8 @@ \subsection{Contributors to the Modelica Language, Version 3.2}\doublelabel{cont The global name lookup was proposed by Stefan Vorkoetter. The support for Unicode was initiated by Rui Gao and Hoyoun Kim.\\ -\lstinline!homotopy! was proposed by Martin Otter, Michael Sielemann -and Francesco Casella. Michael Sielemann demonstrated with benchmark +Martin Otter, Michael Sielemann and Francesco Casella proposed \lstinline!homotopy!. +Michael Sielemann demonstrated with benchmark problems that non-linear solvers are not able to solve reliably initialization problems and that the homotopy operator is therefore needed. He provided a prototype implementation of the homotopy-operator From a9f34b947486b2a039df30e7d77f3774330b9457 Mon Sep 17 00:00:00 2001 From: Henrik Tidefelt Date: Sat, 13 Jun 2020 01:36:23 +0200 Subject: [PATCH 57/78] Fix issues found when looking for un-protected in-sentence periods --- chapters/annotations.tex | 32 ++++++++--------- chapters/arrays.tex | 40 +++++++++++----------- chapters/classes.tex | 32 ++++++++--------- chapters/connectors.tex | 18 +++++----- chapters/dae.tex | 4 +-- chapters/equations.tex | 28 +++++++-------- chapters/functions.tex | 32 ++++++++--------- chapters/glossary.tex | 26 +++++++------- chapters/inheritance.tex | 14 ++++---- chapters/interface.tex | 51 +++++++++++++--------------- chapters/introduction.tex | 4 +-- chapters/lexicalstructure.tex | 6 ++-- chapters/library.tex | 2 +- chapters/literature.tex | 4 +-- chapters/operatorsandexpressions.tex | 26 ++++++-------- chapters/overloaded.tex | 8 ++--- chapters/packages.tex | 32 +++++++---------- chapters/revisions.tex | 10 +++--- chapters/scoping.tex | 44 +++++++++++------------- chapters/statemachines.tex | 27 +++++++-------- chapters/statements.tex | 6 ++-- chapters/stream.tex | 18 ++++------ chapters/synchronous.tex | 18 +++++----- chapters/syntax.tex | 2 +- 24 files changed, 225 insertions(+), 259 deletions(-) diff --git a/chapters/annotations.tex b/chapters/annotations.tex index fbcd4b4ae..cbc7697e4 100644 --- a/chapters/annotations.tex +++ b/chapters/annotations.tex @@ -239,7 +239,7 @@ \section{Annotations for Code Generation}\doublelabel{annotations-for-code-gener \begin{nonnormative} This means that the function is at least C\textsuperscript{smoothOrder}. \lstinline!smoothOrder = 1! means that the function can be differentiated at least once in order that all output arguments are still continuous, provided -the input arguments are continuous. If a tool needs the derivative of a function, e.g. for index reduction or to +the input arguments are continuous. If a tool needs the derivative of a function, e.g.\ for index reduction or to compute an analytic Jacobian, the function can be differentiated analytically at least \lstinline!smoothOrder! times. \end{nonnormative} @@ -340,7 +340,7 @@ \section{Annotations for Graphical Objects}\doublelabel{annotations-for-graphica \end{nonnormative} These Icon, Diagram, and Documentation annotations are only allowed -directly in classes (e.g. not on components or connections). The allowed +directly in classes (e.g.\ not on components or connections). The allowed annotations for a short class definition is the union of the allowed annotations in classes and on extends-clauses. @@ -394,7 +394,7 @@ \subsubsection{Coordinate Systems}\doublelabel{coordinate-systems} application may use a different default value of \lstinline!initialScale!. The attribute \lstinline!grid! specifies the spacing between grid points which can -be used by tools for alignment of points in the coordinate system, e.g. ``snap-to-grid''. +be used by tools for alignment of points in the coordinate system, e.g.\ ``snap-to-grid''. Its use and default value is tool-dependent. \begin{lstlisting}[language=modelica] @@ -411,7 +411,7 @@ \subsubsection{Coordinate Systems}\doublelabel{coordinate-systems} \begin{lstlisting}[language=modelica] CoordinateSystem(extent = {{-10, -10}, {10, 10}}); \end{lstlisting} -i.e. a coordinate system with width 20 units and height 20 units. +i.e.\ a coordinate system with width 20 units and height 20 units. \end{example} The coordinate systems for the icon and diagram layers are by default @@ -861,7 +861,7 @@ \subsubsection{Text}\doublelabel{text} \item \%\% replaced by \% \item - \%name replaced by the name of the component (i.e. the identifier for + \%name replaced by the name of the component (i.e.\ the identifier for it in in the enclosing class). \item \%class replaced by the name of the class (only the last part of the hierarchical name). @@ -1128,7 +1128,7 @@ \section{Annotations for the Graphical User Interface}\doublelabel{annotations-f definition of "structurally inconsistent" see the article: \href{http://epubs.siam.org/doi/abs/10.1137/0909014}{Pantelides C.C.: The Consistent Initialization of Differential-Algebraic Systems, SIAM - J. Sci. and Stat. Comput. Volume 9, Issue 2, pp. 213--231 (March + J.\ Sci.\ and Stat.\ Comput.\ Volume 9, Issue 2, pp. 213--231 (March 1988)}}. A "default connection" is constructed by instantiating the respective \lstinline!model! or \lstinline!block! and for every input \lstinline!u! providing an equation \lstinline!0=f(u)!, and for every (potential,flow) pair of the form \lstinline!(v,i)!, providing @@ -1538,7 +1538,7 @@ \subsubsection{Conversion rules}\doublelabel{conversion-rules} corresponding to the old version. \begin{nonnormative} -Whenever possible tools should preserve the original style of the model, e.g. use of imports. +Whenever possible tools should preserve the original style of the model, e.g.\ use of imports. \end{nonnormative} These functions can be called with literal strings or array of strings @@ -1549,7 +1549,7 @@ \subsubsection{Conversion rules}\doublelabel{conversion-rules} conversions of base-classes will require multiple conversion-calls; this ensures that the conversion is independent of the new library structure. The class-name used as argument to \lstinline!convertElement! and \lstinline!convertModifiers! -is similarly the old name of the class, i.e. the name before it is +is similarly the old name of the class, i.e.\ the name before it is possibly converted by \lstinline!convertClass!. \begin{nonnormative} @@ -1587,7 +1587,7 @@ \subsubsection{Conversion rules}\doublelabel{conversion-rules} The old element should be of a \lstinline!Boolean!, \lstinline!Integer!, \lstinline!String!, or enumeration type and the match is based on the literal value of the modifier. -For string elements the value argument to \lstinline!convertClassIf! shall be up-quoted, e.g. \lstinline!"\"My String\""!, +For string elements the value argument to \lstinline!convertClassIf! shall be up-quoted, e.g.\ \lstinline!"\"My String\""!, and for enumeration literals only the enumeration literal part of the old value matters, e.g., \lstinline!red! for \lstinline!"Colors.red"!. @@ -1688,7 +1688,7 @@ \subsubsection{Conversion rules}\doublelabel{conversion-rules} connector \lstinline!B! is connected, there will be a parameter for enabling connector \lstinline!B!, and the conversion ensures that each component of model \lstinline!A! will have this parameter set accordingly. -In case a parameter is simply renamed it is preferable to use \lstinline!convertElement!, since that also handles e.g. binding equations +In case a parameter is simply renamed it is preferable to use \lstinline!convertElement!, since that also handles e.g.\ binding equations using the parameter. \end{nonnormative} @@ -1851,7 +1851,7 @@ \subsection{Version Date and Build Information}\doublelabel{version-date-and-bui \end{nonnormative} \item \lstinline!revisionId! is a tool specific revision identifier - possibly generated by a source code management system (e.g. Subversion + possibly generated by a source code management system (e.g.\ Subversion or CVS). This information allows to exactly identify the library source code in the source code management system. \end{itemize} @@ -1899,7 +1899,7 @@ \section{Annotations for Access Control to Protect Intellectual Property}\double \firstuse{Protection} & Define what parts of a class are visible.\\ \hline \firstuse{Obfuscation} & Changing a Modelica class or generated code so that it is difficult to inspect by a user -(e.g. by automatically renaming variables to non-meaningful names).\\ +(e.g.\ by automatically renaming variables to non-meaningful names).\\ \hline \firstuse{Encryption} & Encoding of a model or a package in a form so that the modeler cannot inspect any content of a class without an appropriate @@ -1910,10 +1910,8 @@ \section{Annotations for Access Control to Protect Intellectual Property}\double \hline \end{longtable} -In this section annotations are defined for protection and -licensing. Obfuscation and encryption are not standardized. -protection and licensing are both defined inside the -\lstinline!Protection! annotation: +In this section annotations are defined for protection and licensing. Obfuscation and encryption are not standardized. +Protection and licensing are both defined inside the \lstinline!Protection! annotation: \begin{lstlisting}[language=modelica,mathescape=true] annotation(Protection($\ldots$)); \end{lstlisting} @@ -2088,7 +2086,7 @@ \subsection{Licensing}\doublelabel{licensing} record License String licensee ="" "Optional string to show information about the licensee"; - String id[:] "Unique machine identifications, e.g. MAC addresses"; + String id[:] "Unique machine identifications, e.g.\ MAC addresses"; String features[:] =fill("", 0) "Activated library license features"; String startDate ="" "Optional start date in UTCformat YYYY-MM-DD"; String expirationDate="" "Optional expiration date in UTCformat YYYY-MM-DD"; diff --git a/chapters/arrays.tex b/chapters/arrays.tex index 77c055835..65bd9b5a9 100644 --- a/chapters/arrays.tex +++ b/chapters/arrays.tex @@ -44,7 +44,7 @@ \section{Array Declarations}\doublelabel{array-declarations} The following table shows the two possible forms of declarations and defines the terminology. C is a placeholder for any class, including the built-in type classes \lstinline!Real!, \lstinline!Integer!, \lstinline!Boolean!, \lstinline!String!, and enumeration -types. The type of a dimension upper bound expression, e.g. n, m, p,... +types. The type of a dimension upper bound expression, e.g.\ $n$, $m$, $p$, \ldots in the table below, need to be a subtype of \lstinline!Integer! or EB for a class EB that is an enumeration type or subtype of the \lstinline!Boolean! type. @@ -58,7 +58,7 @@ \section{Array Declarations}\doublelabel{array-declarations} An array indexed by Boolean or enumeration type can only be used in the following ways: \begin{itemize} \item - Subscripted using expressions of the appropriate type (i.e. Boolean or + Subscripted using expressions of the appropriate type (i.e.\ Boolean or the enumerated type) \item Binding equations of the form \lstinline!x1 = x2! as well as declaration @@ -74,11 +74,10 @@ \section{Array Declarations}\doublelabel{array-declarations} \tablehead{Modelica form 1} & \tablehead{Modelica form 2} & \tablehead{\# dimensions} & \tablehead{Designation} & \tablehead{Explanation}\\ \hline \endhead C x; & C x; & 0 & Scalar & Scalar\\ \hline -C{[}n{]} x; & C x{[}n{]}; & 1 & Vector & n -- Vector\\ \hline +C{[}$n${]} x; & C x{[}$n${]}; & 1 & Vector & $n$ -- Vector\\ \hline C{[}EB{]} x; & C x{[}EB{]} & 1 & Vector & Vector index by enumeration or Boolean type EB\\ \hline -C{[}n, m{]} x; & C x{[}n, m{]}; & 2 & Matrix & n x m -Matrix\\ \hline +C{[}$n$, $m${]} x; & C x{[}$n$, $m${]}; & 2 & Matrix & $n \times m$ Matrix\\ \hline C{[}$n_1$, $n_{2}$,\ldots{},$n_k${]} x; & C x{[}$n_1$, $n_2$,\ldots{},$n_k${]}; & $k$ & Array & Array with $k$ dimensions ($k \geq 0$).\\ \hline \end{longtable} @@ -595,7 +594,7 @@ \subsection{Array Constructor with Iterators}\doublelabel{array-constructor-with for-clauses. The loop-variable has the same type as the type of the elements of array\_expression; and can be simple type as well as a record type. The loop-variable will have the same type for the entire -loop - i.e. for an array\_expression \{1,3.2\} the iterator will have +loop - i.e.\ for an array\_expression \{1,3.2\} the iterator will have the type of the type-compatible expression (Real) for all iterations. For deduction of ranges, see \autoref{implicit-iteration-ranges}; and for using types as range see \autoref{types-as-iteration-ranges}. @@ -704,7 +703,7 @@ \subsubsection{Array Concatenation along First and Second Dimensions}\doublelabe more dimensions, and it is a matrix with the elements of A, if A is a scalar or a vector. \item - There must be at least one argument (i.e. \lstinline![]! is not defined) + There must be at least one argument (i.e.\ \lstinline![]! is not defined) \end{itemize} \begin{example} @@ -808,6 +807,7 @@ \section{Array Indexing}\doublelabel{array-indexing} \end{nonnormative} \begin{example} +% henrikt-ma: This listing needs to be cleaned up from confusing punctuation. \begin{lstlisting}[language=modelica, escapechar=!] a[:, j] !\emph{is a vector of the j-th column of a,}! a[j] !\emph{is a vector of the j-th row of a:}! a[j, :] @@ -824,7 +824,7 @@ \section{Array Indexing}\doublelabel{array-indexing} \begin{example} Array slicing given the declaration \lstinline!x[n,m], v[k], z[i,j,p]!. \begin{longtable}[]{|l|l|l|} -\caption{Examples of scalars vs. array slices created with the colon index.}\\ +\caption{Examples of scalars vs.\ array slices created with the colon index.}\\ \hline \tablehead{Expression} & \tablehead{\# dimensions} & \tablehead{Type of value}\\ \hline \endhead @@ -1128,9 +1128,8 @@ \subsection{Exponentiation of Scalars of Numeric Elements}\doublelabel{exponenti 2.^[1,2;3,4] // error, since 2.0^[1,2;3,4] 2 .^[1,2;3,4] // fine, element wise exponentiation \end{lstlisting} -This is a consequence of the parsing rules, i.e. since 2. could be -a lexical unit it seen as a lexical unit; using a space after literals -solves the problem. +This is a consequence of the parsing rules, i.e.\ since \lstinline!2.! could be a lexical unit it seen as a lexical unit; using a space after +literals solves the problem. \end{example} \subsection{Scalar Exponentiation of Square Matrices of Numeric Elements}\doublelabel{scalar-exponentiation-of-square-matrices-of-numeric-elements} @@ -1161,7 +1160,7 @@ \subsection{Slice Operation}\doublelabel{slice-operation} \item If \lstinline!m! is also an array component, the slice operation is valid only if \lstinline!size(a[1].m)=size(a[2].m)=...! \item - The slicing operation can be combined with indexing, e.g. \lstinline!a.m[1]!. + The slicing operation can be combined with indexing, e.g.\ \lstinline!a.m[1]!. It returns the array of components \lstinline!{a[1].m[1], a[2].m[1], ...}!, and does not require that \lstinline!size(a[1].m)=size(a[2].m)!. The number of subscripts on m must not be greater than the number of array dimension for m (the number @@ -1173,21 +1172,20 @@ \subsection{Slice Operation}\doublelabel{slice-operation} The size-restriction on the operand is only applicable if the indexing on the second operand uses vectors or colon as in the example: -\begin{lstlisting}[language=modelica] +\begin{lstlisting}[language=modelica,mathescape=true] constant Integer m=3; Modelica.Blocks.Continuous.LowpassButterworth tf[m](n=2:(m+1)); Real y[m]; Real y2,y3; equation // Extract the x1 slice even though different x1's have different lengths - y=tf.x1[1] ; // Legal, ={tf[1].x1[1], tf[2].x1[1], - ... tf[m].x1[1]}; - y2=sum(tf.x1[:]); // Illegal to extract all elements since they have - // different lengths. Does not satisfy: - // size(tf[1].x1[:])=size(tf[2].x1[:])=...=size(tf[m].x1[:]) - y3=sum(tf.x1[1:2]); // Legal. - // Since x1 has at least 2 elements in all tf, and - // size(tf[1].x1[1:2])=size(tf[2].x1[1:2])=...=size(tf[m].x1[1:2])={2} + y = tf.x1[1] ; // Legal, = {tf[1].x1[1], tf[2].x1[1], $\ldots$ tf[m].x1[1]}; + y2 = sum(tf.x1[:]); // Illegal to extract all elements since they have + // different lengths. Does not satisfy: + // size(tf[1].x1[:]) = size(tf[2].x1[:]) = $\ldots$ = size(tf[m].x1[:]) + y3 = sum(tf.x1[1:2]); // Legal. + // Since x1 has at least 2 elements in all tf, and + // size(tf[1].x1[1:2]) = size(tf[2].x1[1:2]) = $\ldots$ = size(tf[m].x1[1:2]) = {2} \end{lstlisting} In this example the different \lstinline!x1! vectors have different lengths, but it is still possible to perform some operations on them. diff --git a/chapters/classes.tex b/chapters/classes.tex index b32e1b7a6..2feb1d25c 100644 --- a/chapters/classes.tex +++ b/chapters/classes.tex @@ -47,7 +47,7 @@ \section{Access Control -- Public and Protected Elements}\doublelabel{access-con \end{example} All elements defined under the heading \lstinline!protected! are regarded as protected. All other elements (i.e., defined -under the heading \lstinline!public!, without headings or in a separate file) are public (i.e. not protected). Regarding +under the heading \lstinline!public!, without headings or in a separate file) are public (i.e.\ not protected). Regarding inheritance of protected and public elements, see \autoref{inheritance-of-protected-and-public-elements}. @@ -238,7 +238,7 @@ \subsubsection{Prefix Rules}\doublelabel{prefix-rules} and \lstinline!output! of a structured component (except as described above) are also applied to the elements of the component (this is done after verifying that the type prefixes -occurring on elements of the component are correct; e.g. the \lstinline!flow! prefix +occurring on elements of the component are correct; e.g.\ the \lstinline!flow! prefix can be used on a record component and all the record elements will generate zero-sum equations, even if elements of a record may not be declared with the flow prefix). When any of the type prefixes \lstinline!flow!, @@ -863,13 +863,13 @@ \section{Specialized Classes}\doublelabel{specialized-classes} record. \begin{nonnormative} A function declaration -\begin{lstlisting}[language=modelica] -operator function foo ... end foo; +\begin{lstlisting}[language=modelica,mathescape=true] +operator function foo $\ldots$ end foo; \end{lstlisting} is conceptually treated as -\begin{lstlisting}[language=modelica] +\begin{lstlisting}[language=modelica,mathescape=true] operator foo function foo1 - ... + $\ldots$ end foo1; end foo; \end{lstlisting} \end{nonnormative} @@ -884,11 +884,11 @@ \section{Specialized Classes}\doublelabel{specialized-classes} \begin{example} Use of \lstinline!operator!: -\begin{lstlisting}[language=modelica] +\begin{lstlisting}[language=modelica,mathescape=true] operator record Complex Real re; Real im; - ... + $\ldots$ encapsulated operator function '*' import Complex; input Complex c1; @@ -956,7 +956,7 @@ \section{Balanced Models}\doublelabel{balanced-models} redeclaration cannot lead to an unbalanced model any more. \end{nonnormative} -The restrictions below apply after flattening -- i.e. inherited +The restrictions below apply after flattening -- i.e.\ inherited components are included -- possibly modified. The corresponding restrictions on connectors and connections are in \autoref{restrictions-of-connections-and-connectors}. @@ -997,7 +997,7 @@ \section{Balanced Models}\doublelabel{balanced-models} following numbers: \begin{itemize} \item - The number of equations defined locally (i.e. not in any model or + The number of equations defined locally (i.e.\ not in any model or block component), including binding equations, and equations generated from connect-equations. \begin{nonnormative} @@ -1050,7 +1050,7 @@ \section{Balanced Models}\doublelabel{balanced-models} Similarly as locally balanced, but including all unknowns and equations from all components. The global number of unknowns is computed by -expanding all unknowns (i.e. excluding parameters and constants) into a +expanding all unknowns (i.e.\ excluding parameters and constants) into a set of scalars of primitive types. This should match the global equation size defined as: \begin{itemize} @@ -1073,7 +1073,7 @@ \section{Balanced Models}\doublelabel{balanced-models} In a non-partial model or block, all non-connector inputs of model or block components must have binding equations. \begin{nonnormative} - E.g. if the model contains a component, \lstinline!firstOrder! (of specialized class \lstinline!model!) and \lstinline!firstOrder! has + E.g.\ if the model contains a component, \lstinline!firstOrder! (of specialized class \lstinline!model!) and \lstinline!firstOrder! has \lstinline!input Real u! then there must be a binding equation for \lstinline!firstOrder.u!. \end{nonnormative} \item @@ -1146,7 +1146,7 @@ \section{Balanced Models}\doublelabel{balanced-models} \end{align*} and 2 equations corresponding to the 2 flow-variables \lstinline!p.i! and \lstinline!n.i!. -These are 5 equations in 5 unknowns (locally balanced model). A more detailed analysis would reveal that this is structurally non-singular, i.e. that +These are 5 equations in 5 unknowns (locally balanced model). A more detailed analysis would reveal that this is structurally non-singular, i.e.\ that the hybrid DAE will not contain a singularity independent of actual values. If the equation \lstinline!u = p.v - n.v! would be missing in the \lstinline!Capacitor! model, there would be 4 equations in 5 unknowns and the model @@ -1412,7 +1412,7 @@ \section{Predefined Types and Classes}\doublelabel{predefined-types-and-classes} \lstinline!String!) and \lstinline!enumeration! types are described below with Modelica syntax although they are predefined. Attributes cannot be accessed using dot notation, and are not constrained by equations and algorithm sections. -E.g. in \lstinline!Real x(unit="kg") = y;! only the values of \lstinline!x! and \lstinline!y! are declared +E.g.\ in \lstinline!Real x(unit="kg") = y;! only the values of \lstinline!x! and \lstinline!y! are declared to be equal, but not their \lstinline!unit! attributes, nor any other attribute of \lstinline!x! and \lstinline!y!. It is not possible to combine extends from the predefined types, enumeration types, or this \lstinline!Clock! type with other components. The names @@ -1424,7 +1424,7 @@ \section{Predefined Types and Classes}\doublelabel{predefined-types-and-classes} \end{nonnormative} \begin{nonnormative} -It also follows that the only way to declare a subtype of e.g. \lstinline!Real! is to use the \lstinline!extends! mechanism. +It also follows that the only way to declare a subtype of e.g.\ \lstinline!Real! is to use the \lstinline!extends! mechanism. \end{nonnormative} The definitions use \lstinline!RealType!, \lstinline!IntegerType!, \lstinline!BooleanType!, \lstinline!StringType!, \lstinline!EnumType! @@ -1691,7 +1691,7 @@ \subsection{Attributes start, fixed, nominal, and unbounded}\doublelabel{attribu value. The lack of default allows the tool to propagate the nominal attribute based on equations, and if there is no value to propagate the tool should use a non-zero value, it may use additional information -(e.g. min-attribute) to find a suitable value, and as last resort use 1. +(e.g.\ min-attribute) to find a suitable value, and as last resort use 1. If \lstinline!unbounded=true! it indicates that the state may grow without bound, and the error in absolute terms shall be controlled. diff --git a/chapters/connectors.tex b/chapters/connectors.tex index 98f722647..76430bb81 100644 --- a/chapters/connectors.tex +++ b/chapters/connectors.tex @@ -139,13 +139,13 @@ \subsection{Expandable Connectors}\doublelabel{expandable-connectors} created, and a connection to the specific array element is performed. Introducing elements in an array gives an array with at least the specified elements, other elements are either not created or have a - default value (i.e. as if they were only potentially present). + default value (i.e.\ as if they were only potentially present). \item If the variable on the other side of the connect-equation is input or output the new component will be either input or output to satisfy the restrictions in \autoref{restrictions-of-connections-and-connectors} for a non-expandable connector. \begin{nonnormative} - If the existing side refers to an inside connector (i.e. a connector of a component) the new variable will copy its causality, i.e. input + If the existing side refers to an inside connector (i.e.\ a connector of a component) the new variable will copy its causality, i.e.\ input if input and output if output, since the expandable connector must be an outside connector. \end{nonnormative} For an array the input/output property can be deduced separately for each array element. @@ -157,7 +157,7 @@ \subsection{Expandable Connectors}\doublelabel{expandable-connectors} until all connected expandable connector instances have matching variables. \begin{nonnormative} - I.e. each of the connector instances is expanded to be the union of all connector variables. + I.e.\ each of the connector instances is expanded to be the union of all connector variables. \end{nonnormative} \item The variables introduced in the elaboration follow additional rules @@ -196,7 +196,7 @@ \subsection{Expandable Connectors}\doublelabel{expandable-connectors} All components in an expandable connector are seen as connector instances even if they are not declared as such. \begin{nonnormative} - I.e. it is possible to connect to e.g. a \lstinline!Real! variable. + I.e.\ it is possible to connect to e.g.\ a \lstinline!Real! variable. \end{nonnormative} \begin{example} @@ -289,7 +289,7 @@ \subsection{Expandable Connectors}\doublelabel{expandable-connectors} they do not contain the same components. \begin{nonnormative} -A tool may remove undefined variables in an expandable connector, or set them to the default value, e.g. zero for \lstinline!Real! variables. +A tool may remove undefined variables in an expandable connector, or set them to the default value, e.g.\ zero for \lstinline!Real! variables. \end{nonnormative} \begin{nonnormative} @@ -315,7 +315,7 @@ \subsection{Expandable Connectors}\doublelabel{expandable-connectors} \begin{example} Engine system with sensors, controllers, actuator and plant that -exchange information via a bus (i.e. via expandable connectors): +exchange information via a bus (i.e.\ via expandable connectors): \begin{lstlisting}[language=modelica] import Modelica.Units.SI; import Modelica.Blocks.Interfaces.RealInput; @@ -389,7 +389,7 @@ \section{Generation of Connection Equations}\doublelabel{generation-of-connectio the primitive components of \lstinline!a! and \lstinline!b! form a connection set -- together with an indication of whether they are from an inside or an outside connector; the primitive elements are of simple types -- or of types -defined as \lstinline!operator record! (i.e. a component of an \lstinline!operator record! type +defined as \lstinline!operator record! (i.e.\ a component of an \lstinline!operator record! type is not split into sub-components). The elements of the connection sets are tuples of primitive variables together with an indication of inside or outside; if the same tuple belongs to two connection sets those two @@ -445,7 +445,7 @@ \section{Generation of Connection Equations}\doublelabel{generation-of-connectio \end{itemize} The bold-face $\mathbf{0}$ represents an array or scalar zero of -appropriate dimensions (i.e. the same size as $z$). +appropriate dimensions (i.e.\ the same size as $z$). For an \lstinline!operator record! type this uses the operator \lstinline!'0'! -- which must be defined in the operator record; and all of the flow-variables for the @@ -637,7 +637,7 @@ \section{Restrictions of Connections and Connectors}\doublelabel{restrictions-of \item Variables from a protected outside connector must be part of a connection set containing at least one inside connector or one - declared public outside connector (i.e. it may not be an implicitly + declared public outside connector (i.e.\ it may not be an implicitly defined part of an expandable connector). \begin{nonnormative} Otherwise it would not be possible to deduce the causality for the expandable connector element. diff --git a/chapters/dae.tex b/chapters/dae.tex index 114ab6683..3f9547342 100644 --- a/chapters/dae.tex +++ b/chapters/dae.tex @@ -52,7 +52,7 @@ \chapter{Modelica DAE Representation}\doublelabel{modelica-dae-representation} \hline $c(t_{\mathrm{e}})$ & The conditions of all if-expressions generated including when-clauses after conversion, see \autoref{when-equations}).\\ \hline -$\mathit{relation}(v)$ & A relation containing variables $v_{i}$, e.g. $v_{1} > v_{2}$, $v_{3} \geq 0$.\\ +$\mathit{relation}(v)$ & A relation containing variables $v_{i}$, e.g.\ $v_{1} > v_{2}$, $v_{3} \geq 0$.\\ \hline \end{longtable} @@ -118,7 +118,7 @@ \chapter{Modelica DAE Representation}\doublelabel{modelica-dae-representation} Usually, in a first step these equations are sorted and in many cases the Boolean and Integer unknowns can be just computed by a forward evaluation sequence. In some cases, there remain systems of equations -(e.g. for ideal diodes, Coulomb friction elements) and specialized +(e.g.\ for ideal diodes, Coulomb friction elements) and specialized algorithms have to be used to solve them. Due to the construction of the equations by \emph{flattening} a Modelica diff --git a/chapters/equations.tex b/chapters/equations.tex index 46f262f68..1c1673860 100644 --- a/chapters/equations.tex +++ b/chapters/equations.tex @@ -424,20 +424,18 @@ \subsection{reinit}\doublelabel{reinit} The operator reinitializes \lstinline!x! with \lstinline!expr! at an event instant. \lstinline!x! is a \lstinline!Real! variable (or an array of \lstinline!Real! variables) that must be selected as a -state (resp., states) , i.e. reinit on x implies +state (resp., states) , i.e.\ reinit on x implies stateSelect=StateSelect.always on x. \lstinline!expr! needs to be type-compatible -with \lstinline!x!. The reinit operator can for the same variable (resp. array of +with \lstinline!x!. \lstinline!reinit! can for the same variable (resp.\ array of variables) only be applied (either as an individual variable or as part -of an array of variables) in one equation (having reinit of the same +of an array of variables) in one equation (having \lstinline!reinit! of the same variable in when and else-when of the same variable is allowed). In case -of reinit active during initialization (due to when initial), see +of \lstinline!reinit! active during initialization (due to when initial), see \autoref{initialization-initial-equation-and-initial-algorithm}. -The reinit operator does not break the single assignment rule, because -reinit(x,expr) in equations evaluates expr to a value (value), then at -the end of the current event iteration step it assigns this value to x -(this copying from values to reinitialized state(s) is done after all -other evaluations of the model and before copying x to pre(x)). +\lstinline!reinit! does not break the single assignment rule, because \lstinline!reinit(x, expr)! in equations evaluates expr to a value (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 @@ -584,7 +582,7 @@ \section{Synchronous Data-flow Principle and Single Assignment Rule}\doublelabel \section{Events and Synchronization}\doublelabel{events-and-synchronization} The integration is halted and an event occurs whenever an event -generation expression, e.g. \lstinline!x > 2! o or \lstinline!floor(x)!, changes +generation expression, e.g.\ \lstinline!x > 2! o or \lstinline!floor(x)!, changes its value. An event generating expression has an internal buffer, and the value of the expression can only be changed at event instants. If the evaluated expression is inconsistent with the buffer, that will @@ -645,11 +643,11 @@ \section{Events and Synchronization}\doublelabel{events-and-synchronization} In this case \lstinline!x = y = z!, but a tool might generate events for \lstinline!z!. The if-expression is taken literally without inducing state events. -The \lstinline!smooth! function is useful, if e.g. the modeler can guarantee that +The \lstinline!smooth! function is useful, if e.g.\ the modeler can guarantee that the used if-clauses fulfill at least the continuity requirement of integrators. In this case the simulation speed is improved, since no state event iterations occur during integration. The \lstinline!noEvent! function is -used to guard against \emph{outside domain} errors, e.g. \lstinline!y = if noEvent(x>= 0) then sqrt(x) else 0.! +used to guard against \emph{outside domain} errors, e.g.\ \lstinline!y = if noEvent(x>= 0) then sqrt(x) else 0.! \end{example} All equations and assignment statements within when-clauses and all @@ -675,7 +673,7 @@ \section{Events and Synchronization}\doublelabel{events-and-synchronization} \begin{nonnormative} The rules for the synchronous data flow principle guarantee that variables are always defined by a unique set of equations. It is -not possible that a variable is e.g. defined by two equations, which +not possible that a variable is e.g.\ defined by two equations, which would give rise to conflicts or non-deterministic behavior. Furthermore, the continuous and the discrete parts of a model are always automatically ``synchronized''. Example: @@ -714,7 +712,7 @@ \section{Events and Synchronization}\doublelabel{events-and-synchronization} \begin{nonnormative} As a consequence, synchronization of events has to be -explicitly programmed in the model, e.g. via counters. Example: +explicitly programmed in the model, e.g.\ via counters. Example: \begin{lstlisting}[language=modelica] Boolean fastSample, slowSample; Integer ticks(start=0); @@ -839,7 +837,7 @@ \section{Initialization, initial equation, and initial algorithm}\doublelabel{in \end{nonnormative} All variables declared as parameter having \lstinline!fixed = false! are treated as -unknowns during the initialization phase, i.e. there must be additional +unknowns during the initialization phase, i.e.\ there must be additional equations for them -- and the start-value can be used as a guess-value during initialization. diff --git a/chapters/functions.tex b/chapters/functions.tex index 523c240cb..d3373393e 100644 --- a/chapters/functions.tex +++ b/chapters/functions.tex @@ -124,7 +124,7 @@ \section{Function as a Specialized Class}\doublelabel{function-as-a-specialized- \begin{nonnormative} The syntax and semantics of a function have many similarities to those of the \lstinline!block! specialized class. A function has many of the properties -of a general class, e.g. being able to inherit other functions, or to redeclare or modify elements of a function declaration. +of a general class, e.g.\ being able to inherit other functions, or to redeclare or modify elements of a function declaration. \end{nonnormative} Modelica functions have the following restrictions compared to a general @@ -241,7 +241,7 @@ \section{Pure Modelica Functions}\doublelabel{pure-modelica-functions} \item \emph{Pure} Modelica functions always give the same output values or errors for the same input values and only the output values influence - the simulation result, i.e. is seen as equivalent to a mathematical + the simulation result, i.e.\ is seen as equivalent to a mathematical map from input values to output values. Some input values may map to errors. Pure functions are thus allowed to fail by calling assert, or ModelicaError in C-code, or dividing by zero. Such errors will only be @@ -293,7 +293,7 @@ \section{Pure Modelica Functions}\doublelabel{pure-modelica-functions} containing function calls while still preserving their semantics. For example, a tool may use common subexpression elimination to call a pure function just once, if it is called several times with identical input -arguments. However, since functions may fail we can e.g. only move a +arguments. However, since functions may fail we can e.g.\ only move a common function call from inside a loop to outside the loop if the loop is run at least once. \end{nonnormative} @@ -303,7 +303,7 @@ \section{Pure Modelica Functions}\doublelabel{pure-modelica-functions} maintaining this property for pure non-external functions. Regarding external functions, the external function implementor is responsible. Note that external functions can have side-effects as long as they do -not influence the internal Modelica simulation state, e.g. caching +not influence the internal Modelica simulation state, e.g.\ caching variables for performance or printing trace output to a log file. \end{nonnormative} @@ -775,7 +775,7 @@ \subsection{Initialization and Binding Equations of Components in Functions} (before executing the algorithm section or calling the external function). These bindings must be executed in an order where a variable is not used before its binding equations has been executed; it is -an error if no such order exists (i.e. the binding must be acyclic). +an error if no such order exists (i.e.\ the binding must be acyclic). Binding equations can only be used for components of a function. If no binding equation is given for a non-input component the @@ -850,7 +850,7 @@ \subsection{Flexible Array Sizes and Resizing of Arrays in Functions}\doublelabe \subsection{Scalar Functions Applied to Array Arguments}\doublelabel{scalar-functions-applied-to-array-arguments} Functions with one scalar return value can be applied to arrays -element-wise, e.g. if \lstinline!A! is a vector of reals, then \lstinline!sin(A)! is a vector +element-wise, e.g.\ if \lstinline!A! is a vector of reals, then \lstinline!sin(A)! is a vector where each element is the result of applying the function \lstinline!sin! to the corresponding element in \lstinline!A!. Only function classes that are transitively non-replaceable (\autoref{transitively-non-replaceable} and \autoref{restrictions-on-base-classes-and-constraining-types-to-be-transitively-non-replaceable}) may be called vectorized. @@ -1253,7 +1253,7 @@ \subsection{Using the Derivative Annotation}\doublelabel{using-the-derivative-an some derivatives of some inputs are excluded from the call of the derivative (since they are not necessary). A function may supply multiple derivative functions subject to different restrictions, the -first one that can be used (i.e. satisfying the restrictions) will be +first one that can be used (i.e.\ satisfying the restrictions) will be used for each call. \begin{nonnormative} @@ -1288,7 +1288,7 @@ \subsection{Using the Derivative Annotation}\doublelabel{using-the-derivative-an \end{itemize} If the Modelica function call is a nth derivative (n\textgreater{}=1), -i.e. this function call has been derived from an (n-1)th derivative by +i.e.\ this function call has been derived from an (n-1)th derivative by differentiation inside the tool, an \lstinline!annotation(order=n+1)=...!, specifies the (n+1)th derivative, and the (n+1)th derivative call is constructed as follows: @@ -1437,7 +1437,7 @@ \subsection{Using the Derivative Annotation}\doublelabel{using-the-derivative-an The derivative function is only valid if \lstinline!inputVar1! (and \lstinline!inputVar2! etc.) are independent of the variables the function call is differentiated -with respect to (i.e. that the derivative of \lstinline!inputVar1! is zero). The +with respect to (i.e.\ that the derivative of \lstinline!inputVar1! is zero). The derivative of \lstinline!inputVar1! (and \lstinline!inputVar2! etc.) are excluded from the argument list of the derivative-function. If the derivative-function also specifies a derivative the common variables should have consistent @@ -1691,7 +1691,7 @@ \section{External Function Interface}\doublelabel{external-function-interface} \begin{itemize} \item Support for external functions written in C (specifically C89) and - FORTRAN~77. Other languages, e.g. C++ and Fortran 90, may be supported + FORTRAN~77. Other languages, e.g.\ C++ and Fortran 90, may be supported in the future, and provided the function is link-compatible with C89 or FORTRAN~77 it can be written in any language. \item @@ -1739,7 +1739,7 @@ \section{External Function Interface}\doublelabel{external-function-interface} is assumed to be \lstinline!"C"!. \begin{nonnormative} -The intended use of e.g. C99 is to detect if the user tries to link with a C99-function using a C89 compiler. +The intended use of e.g.\ C99 is to detect if the user tries to link with a C99-function using a C89 compiler. \end{nonnormative} The \lstinline!"builtin"! specification is only used for functions that are defined @@ -1794,7 +1794,7 @@ \subsection{Argument type Mapping}\doublelabel{argument-type-mapping} The arguments of the external function are declared in the same order as in the Modelica declaration, unless specified otherwise in an explicit -external function call. Protected variables (i.e. temporaries) are +external function call. Protected variables (i.e.\ temporaries) are passed in the same way as outputs, whereas constants and size-expression are passed as inputs. @@ -2022,7 +2022,7 @@ \subsubsection{Records}\doublelabel{records} Arrays cannot be mapped. \end{itemize} -Records are passed by reference (i.e. a pointer to the record is being +Records are passed by reference (i.e.\ a pointer to the record is being passed). \begin{example} @@ -2122,7 +2122,7 @@ \subsection{Aliasing}\doublelabel{aliasing} inputs is to ensure that inputs can be stored in static memory and to avoid superfluous copying (especially of matrices). If the routine does not satisfy the requirements the interface must copy the input argument -to a temporary. This is rare but occurs e.g. in \lstinline!dormlq! in some +to a temporary. This is rare but occurs e.g.\ in \lstinline!dormlq! in some Lapack implementations. In those special cases the writer of the external interface have to copy the input to a temporary. If the first input was changed internally in myfoo the designer of the interface @@ -2188,7 +2188,7 @@ \subsection{Annotations for External Libraries and Include Files}\doublelabel{an default and need not be specified; but another location could be specified by using an URI name for the library directory, see \autoref{external-resources}. Different versions of one object library can be provided - (e.g. for Windows and for Linux) by providing a + (e.g.\ for Windows and for Linux) by providing a \emph{platform} directory below the \lstinline!LibraryDirectory!. If no platform directory is present, the object library must be present in the \lstinline!LibraryDirectory!. The following \emph{platform} names are @@ -2218,7 +2218,7 @@ \subsection{Annotations for External Libraries and Include Files}\doublelabel{an \begin{nonnormative} A tool may give diagnostics if the directory corresponding to the selected compiler version is missing. The directories may use symbolic links or use -a text-file as described below: e.g. a text-file \filename{vs2008} containing the text \emph{../win32/vs2005} (or \emph{vs2005}) suggesting that it is +a text-file as described below: e.g.\ a text-file \filename{vs2008} containing the text \emph{../win32/vs2005} (or \emph{vs2005}) suggesting that it is compatible with vs2005. \end{nonnormative} diff --git a/chapters/glossary.tex b/chapters/glossary.tex index e42d0e127..c16ab6bc7 100644 --- a/chapters/glossary.tex +++ b/chapters/glossary.tex @@ -1,20 +1,20 @@ \chapter{Glossary}\doublelabel{glossary} \glossaryitem{algorithm section}: part of a class definition consisting of the keyword \lstinline!algorithm! followed by a sequence of statements. Like an -equation, an algorithm section relates variables, i.e. constrains the +equation, an algorithm section relates variables, i.e.\ constrains the values that these variables can take simultaneously. In contrast to an equation section, an algorithm section distinguishes inputs from outputs: An algorithm section specifies how to compute output variables as a function of given input variables. A Modelica processor may -actually invert an algorithm section, i.e. compute inputs from given -outputs, e.g. by search (generate and test), or by deriving an inverse +actually invert an algorithm section, i.e.\ compute inputs from given +outputs, e.g.\ by search (generate and test), or by deriving an inverse algorithm symbolically. (See \autoref{statements-and-algorithm-sections}.) \glossaryitem{array} or array variable: a component whose components are array elements. For an array, the ordering of its components matters: The kth element in the sequence of components of an array x is the array element with index \lstinline!k!, denoted \lstinline!x[k]!. All elements of an array have the same - type. An array element may again be an array, i.e. arrays can be nested. + type. An array element may again be an array, i.e.\ arrays can be nested. An array element is hence referenced using n indices in general, where n is the number of dimensions of the array. Special cases are matrix (n=2) and vector (n=1). Integer indices start with 1, not zero. (See \autoref{arrays}.) @@ -35,7 +35,7 @@ \chapter{Glossary}\doublelabel{glossary} \lstinline!min!, \lstinline!max!, and \lstinline!unit!. All attributes are predefined and attribute values can only be defined using a modification, such as in \lstinline!Real x(unit="kg")!. Attributes cannot be accessed using dot notation, and are not -constrained by equations and algorithm sections. E.g. in \lstinline!Real x(unit="kg") = y;! only the values of \lstinline!x! and +constrained by equations and algorithm sections. E.g.\ in \lstinline!Real x(unit="kg") = y;! only the values of \lstinline!x! and \lstinline!y! are declared to be equal, but not their unit attributes, nor any other attribute of \lstinline!x! and \lstinline!y!. (See \autoref{predefined-types-and-classes}.) @@ -113,7 +113,7 @@ \chapter{Glossary}\doublelabel{glossary} encapsulated boundary. (See \autoref{simple-name-lookup}). \glossaryitem{equation}: part of a class definition. A scalar equation relates -scalar variables, i.e. constrains the values that these variables can +scalar variables, i.e.\ constrains the values that these variables can take simultaneously. When n-1 variables of an equation containing n variables are known, the value of the nth variable can be inferred (solved for). In contrast to a statement in an algorithm section, an @@ -135,7 +135,7 @@ \chapter{Glossary}\doublelabel{glossary} class defined using the class definition. (See \autoref{inheritance-modification-and-redeclaration}.) \glossaryitem{flattening}: the computation that creates a flattened class of a -given class, where all inheritance, modification, etc. has been +given class, where all inheritance, modification, etc.\ has been performed and all names resolved, consisting of a flat set of equations, algorithm sections, component declarations, and functions. (See \autoref{flattening-process}.) @@ -144,7 +144,7 @@ \chapter{Glossary}\doublelabel{glossary} \glossaryitem{function subtype} or \glossaryitem{function compatible interface}: A is a function subtype of B iff A is a subtype of B and the additional arguments of function A that are not in function B are defined in such a -way (e.g. additional arguments need to have default values), that A can +way (e.g.\ additional arguments need to have default values), that A can be called at places where B is called. (See \autoref{function-compatibility-or-function-subtyping-for-functions}.) \glossaryitem{identifier} or ident: an atomic (not composed) name. Example: @@ -160,11 +160,11 @@ \chapter{Glossary}\doublelabel{glossary} attributes. (See \autoref{inheritance-interface-or-class-type}.) \glossaryitem{instance}: the object generated by a class. An instance contains -zero or more components (i.e. instances), equations, algorithms, and +zero or more components (i.e.\ instances), equations, algorithms, and local classes. An instance has a type. Basically, two instances have same type, if their important attributes are the same and their public components and classes have pair wise equal identifiers and types. More -specific type equivalence definitions are given e.g. for functions. +specific type equivalence definitions are given e.g.\ for functions. \glossaryitem{instantaneous}: An equation or statement is instantaneous if it holds only at events, i.e., at single points in time. The equations and @@ -192,10 +192,10 @@ \chapter{Glossary}\doublelabel{glossary} set of visible classes. Example name: \lstinline!Ele.Resistor!. (See \autoref{names}.) \glossaryitem{operator record}: A record with user-defined operations; -defining e.g. multiplication and addition see \autoref{overloaded-operators}. +defining e.g.\ multiplication and addition see \autoref{overloaded-operators}. \glossaryitem{partial}: a class that is incomplete and cannot be instantiated -in a simulation model; useful e.g. as a base-class. (See \autoref{component-declaration-static-semantics}.) +in a simulation model; useful e.g.\ as a base-class. (See \autoref{component-declaration-static-semantics}.) \glossaryitem{partial flattening}: first find the names of declared local classes and components. Modifiers, if present, are merged to the local @@ -212,7 +212,7 @@ \chapter{Glossary}\doublelabel{glossary} and \lstinline!unit!. (See \autoref{predefined-types-and-classes}.) \glossaryitem{prefix}: property of an element of a class definition which can -be present or not be present, e.g. \lstinline!final!, \lstinline!public!, \lstinline!flow!. (See \autoref{prefix-rules}.) +be present or not be present, e.g.\ \lstinline!final!, \lstinline!public!, \lstinline!flow!. (See \autoref{prefix-rules}.) \glossaryitem{primitive type}: one of the built-in types \lstinline!RealType!, \lstinline!BooleanType!, \lstinline!IntegerType!, \lstinline!StringType!, \lstinline!EnumType!. The primitive types are diff --git a/chapters/inheritance.tex b/chapters/inheritance.tex index 71fc95557..b216c4032 100644 --- a/chapters/inheritance.tex +++ b/chapters/inheritance.tex @@ -213,7 +213,7 @@ \subsection{Restrictions on the Kind of Base Class}\doublelabel{restrictions-on- own kind and from \lstinline!class!. \begin{nonnormative} -E.g. a package can only be base class for packages. All other kinds of classes can use the import statement to use the contents of a package. +E.g.\ a package can only be base class for packages. All other kinds of classes can use the import statement to use the contents of a package. \end{nonnormative} \begin{example} @@ -250,7 +250,7 @@ \subsection{Restrictions on Base Classes and Constraining Types to be Transitive non-replaceable. \begin{nonnormative} -The requirement to use a transitively non-replaceable name excludes the long form of redeclare, i.e. \lstinline!redeclare model extends M...! where +The requirement to use a transitively non-replaceable name excludes the long form of redeclare, i.e.\ \lstinline!redeclare model extends M...! where \lstinline!M! must be an inherited replaceable class. \end{nonnormative} @@ -285,7 +285,7 @@ \section{Modifications}\doublelabel{modifications} \end{lstlisting} \end{example} -A modification (e.g. \lstinline!C1 c1(x = 5)!) is considered a modification equation, +A modification (e.g.\ \lstinline!C1 c1(x = 5)!) is considered a modification equation, if the modified variable (here: \lstinline!c1.x!) is a non-parameter variable. \begin{nonnormative} @@ -829,7 +829,7 @@ \subsection{The class extends Redeclaration Mechanism}\doublelabel{the-class-ext the modifier to redeclare \lstinline!PartialMedium.BaseProperties! to \lstinline!MoistAir2.MoistAir_BaseProperties!. Besides the drawback that the namespace is polluted by elements that have different names but the same -implementation (e.g. \lstinline!MoistAir2.BaseProperties! is identical to +implementation (e.g.\ \lstinline!MoistAir2.BaseProperties! is identical to \lstinline!MoistAir2.MoistAir_BaseProperties!) the whole construction does not work if arrays are present that depend on constants in \lstinline!PartialMedium! , such as \lstinline!X[nX]!: The problem is that \lstinline!MoistAir_BaseProperties! extends from @@ -990,9 +990,9 @@ \subsection{Constraining Type}\doublelabel{constraining-type} In these examples the number of dimensions must be the same in \lstinline!T1! and \lstinline!T2!, as well as in a redeclaration. Normally \lstinline!T1! and \lstinline!T2! are scalar types, but both could also be defined as array types -- with the same -number of dimensions. Thus if \lstinline!T2! is a scalar type (e.g. \lstinline!type T2 = Real!) +number of dimensions. Thus if \lstinline!T2! is a scalar type (e.g.\ \lstinline!type T2 = Real!) then \lstinline!T1! must also be a scalar type; and if \lstinline!T2! is defined as vector type - (e.g. \lstinline!type T2 = Real[3]!) then \lstinline!T1! must also be vector type. + (e.g.\ \lstinline!type T2 = Real[3]!) then \lstinline!T1! must also be vector type. \end{example} \subsubsection{Constraining-clause annotations}\doublelabel{constraining-clause-annotations} @@ -1096,7 +1096,7 @@ \subsection{Annotation Choices for Suggested Redeclarations and Modifications}\d annotation (choicesAllMatching=true); \end{lstlisting} -It can also be applied to nonreplaceable declarations, e.g. to +It can also be applied to nonreplaceable declarations, e.g.\ to describe enumerations. \begin{lstlisting}[language=modelica] type KindOfController=Integer(min=1,max=3) diff --git a/chapters/interface.tex b/chapters/interface.tex index 33fbc9675..d011c4856 100644 --- a/chapters/interface.tex +++ b/chapters/interface.tex @@ -1,7 +1,7 @@ \chapter{Interface or Type Relationships}\doublelabel{interface-or-type-relationships} -A class or component, e.g. denoted \lstinline!A!, can in some cases be used at a -location designed for another class or component, e.g. denoted \lstinline!B!. In +A class or component, e.g.\ denoted \lstinline!A!, can in some cases be used at a +location designed for another class or component, e.g.\ denoted \lstinline!B!. In Modelica this is the case for replaceable classes (see \autoref{redeclaration}) and for \lstinline!inner!/\lstinline!outer! elements (see \autoref{instance-hierarchy-name-lookup-of-inner-declarations}). Replaceable classes are the @@ -12,7 +12,7 @@ \chapter{Interface or Type Relationships}\doublelabel{interface-or-type-relation also be viewed as sub-typing (\autoref{the-concepts-of-type-interface-and-subtype}). In this chapter, two kinds of terminology is used for identical concepts -to get better understanding (e.g. by both engineers and computer +to get better understanding (e.g.\ by both engineers and computer scientists). A short summary of the terms is given in the following table. The details are defined in the rest of this chapter. @@ -24,7 +24,7 @@ \chapter{Interface or Type Relationships}\doublelabel{interface-or-type-relation that is needed to decide whether \lstinline!A! can be used instead of \lstinline!B!. \par \begin{nonnormative*} -E.g. a declaration \lstinline!Real x! is part of the type (also called \emph{interface}), but \lstinline!import A! is not. +E.g.\ a declaration \lstinline!Real x! is part of the type (also called \emph{interface}), but \lstinline!import A! is not. \end{nonnormative*} \\ \hline \begin{tabular}{@{}p{4cm}@{}} @@ -57,7 +57,7 @@ \chapter{Interface or Type Relationships}\doublelabel{interface-or-type-relation plug compatible to the interface of \lstinline!B!, if \lstinline!A! is a subtype of \lstinline!B! and if connector components in \lstinline!A! that are not in \lstinline!B!, are default connectable. \begin{nonnormative} -E.g. it is not allowed that these connectors have variables with the \lstinline!input! prefix, because then they must be connected. +E.g.\ it is not allowed that these connectors have variables with the \lstinline!input! prefix, because then they must be connected. \end{nonnormative} A model or block \lstinline!A! cannot be used instead of \lstinline!B!, if the particular situation does not allow to make a connection to these additional @@ -73,7 +73,7 @@ \chapter{Interface or Type Relationships}\doublelabel{interface-or-type-relation defined in such a way, that \lstinline!A! can be called at places where \lstinline!B! is called. \par \begin{nonnormative*} -E.g. an additional argument must have a default value. +E.g.\ an additional argument must have a default value. \end{nonnormative*} \\ \hline \end{longtable} @@ -107,7 +107,7 @@ \section{The Concepts of Type, Interface and Subtype}\doublelabel{the-concepts-o An element is characterized by its interface defined by some attributes (\autoref{interface-or-type}). The \emph{type} of the element is the set of values -having the same interface, i.e. the same attributes. +having the same interface, i.e.\ the same attributes. A \emph{subtype} \lstinline!A1! in relation to another type \lstinline!A!, means that the elements of the set corresponding to \lstinline!A1! is a subset of the set @@ -125,7 +125,7 @@ \section{The Concepts of Type, Interface and Subtype}\doublelabel{the-concepts-o The type \lstinline!R! of \lstinline!r! can be viewed as the set of all record values having the attributes defined by the interface of -\lstinline!R!, e.g. the infinite set \lstinline!{R(b=false,x=1.2)!, \lstinline!R(b=false, x=3.4)!, +\lstinline!R!, e.g.\ the infinite set \lstinline!{R(b=false,x=1.2)!, \lstinline!R(b=false, x=3.4)!, \lstinline!R(b=true, x=1.2)!, \lstinline!R(b=true, x=1.2, y=2)!, \lstinline!R(b=true, x=1.2, a=2),...)!. The statement that \lstinline!r! has the type (or interface) \lstinline!R! means that the value of \lstinline!r! s to this @@ -188,13 +188,11 @@ \section{Interface or Type}\doublelabel{interface-or-type} \lstinline!IntegerType!, \lstinline!StringType! or \lstinline!BooleanType!). \end{itemize} \item - Only for an \lstinline!operator record! class and classes derived from - \lstinline!ExternalObject!: the full name of the operator record base-class (i.e. - the one containing the operations), or the derived class. See - \autoref{overloaded-operators} and \autoref{external-objects}.\\ - The following item does not apply for an \lstinline!operator record! class or - class derived from \lstinline!ExternalObject!, since the type is already uniquely - defined by the full name. + Only for an \lstinline!operator record! class and classes derived from \lstinline!ExternalObject!: the full name of the operator record base-class + (i.e.\ the one containing the operations), or the derived class. See \autoref{overloaded-operators} and \autoref{external-objects}. + + The following item does not apply for an \lstinline!operator record! class or class derived from \lstinline!ExternalObject!, since the type is already + uniquely defined by the full name. \item For each named public element of the class or component (including both local and inherited named elements) a tuple comprised of: @@ -221,11 +219,8 @@ \section{Interface or Type}\doublelabel{interface-or-type} \end{nonnormative} \begin{nonnormative} -The public interface does not contain all of the information -about the class or component. When using a class as a base-class we also -need protected elements, and for internal type-checking we need e.g. -import-elements. However, the information is sufficient for checking -compatibility and for using the class to flatten components. +The public interface does not contain all of the information about the class or component. When using a class as a base-class we also need protected elements, and +for internal type-checking we need e.g.\ import-elements. However, the information is sufficient for checking compatibility and for using the class to flatten components. \end{nonnormative} \subsection{Transitively non-Replaceable}\doublelabel{transitively-non-replaceable} @@ -237,21 +232,21 @@ \subsection{Transitively non-Replaceable}\doublelabel{transitively-non-replaceab non-replaceable. \end{nonnormative} -A class reference is transitively non-replaceable iff (i.e. \emph{if and +A class reference is transitively non-replaceable iff (i.e.\ \emph{if and only if}) all parts of the name satisfy the following: \begin{itemize} \item If the class definition is long it is transitively non-replaceable if not declared replaceable. \item - If the class definition is short (i.e. \lstinline!class A = P.B!) it is + If the class definition is short (i.e.\ \lstinline!class A = P.B!) it is transitively non-replaceable if it is non-replaceable and equal to class reference (\lstinline!P.B!) that is transitively non-replaceable. \end{itemize} \begin{nonnormative} According to \autoref{restrictions-on-base-classes-and-constraining-types-to-be-transitively-non-replaceable}, for a hierarchical name all -parts of the name must be transitively non-replaceable, i.e. in \lstinline!extends A.B.C! this implies that \lstinline!A.B.C! must be transitively +parts of the name must be transitively non-replaceable, i.e.\ in \lstinline!extends A.B.C! this implies that \lstinline!A.B.C! must be transitively non-replaceable, as well as \lstinline!A! and \lstinline!A.B!, with the exception of the \emph{class extends redeclaration mechanism} see \autoref{the-class-extends-redeclaration-mechanism}. \end{nonnormative} @@ -376,7 +371,7 @@ \section{Interface Compatibility or Subtyping}\doublelabel{interface-compatibili only compatible with \lstinline!B! if the declared variability in \lstinline!A! is less than or equal the variability in \lstinline!B!. \begin{nonnormative} - For a redeclaration of an element the variability prefix is as default inherited by the redeclaration (i.e. no need to repeat \lstinline!parameter! + For a redeclaration of an element the variability prefix is as default inherited by the redeclaration (i.e.\ no need to repeat \lstinline!parameter! when redeclaring a parameter). \end{nonnormative} \item @@ -655,8 +650,8 @@ \section{Type Compatible Expressions}\doublelabel{type-compatible-expressions} Certain expressions consist of an operator applied to two or more type compatible sub-expressions (\lstinline!A! and \lstinline!B!), including binary operators, e.g. -\lstinline!A + B!, if-expressions, e.g. \lstinline!if x then A else B!, and array expressions, -e.g. \lstinline!{A, B}!. The resulting type of the expression in case of two type +\lstinline!A + B!, if-expressions, e.g.\ \lstinline!if x then A else B!, and array expressions, +e.g.\ \lstinline!{A, B}!. The resulting type of the expression in case of two type compatible subexpressions \lstinline!A! and \lstinline!B! is defined as follows: \begin{itemize} \item @@ -704,11 +699,11 @@ \section{Type Compatible Expressions}\doublelabel{type-compatible-expressions} If \lstinline!A! has an \lstinline!operator record! base-class then \lstinline!B! must also have an \lstinline!operator record! base-class, and it must be the same, and otherwise neither \lstinline!A! nor \lstinline!B! may have an \lstinline!operator record! base-class. This is also - the \lstinline!operator record! base-class for the expression e.g. for + the \lstinline!operator record! base-class for the expression e.g.\ for \lstinline!if (cond) then A else B!. \item If \lstinline!A! is derived from \lstinline!ExternalObject! then \lstinline!B! must also be derived from \lstinline!ExternalObject! and they must have the same full name; and otherwise neither \lstinline!A! nor \lstinline!B! may be derived from \lstinline!ExternalObject!. The common full - name also defines the type of the expression, e.g. for \lstinline!if (cond) then A else B!. + name also defines the type of the expression, e.g.\ for \lstinline!if (cond) then A else B!. \end{itemize} diff --git a/chapters/introduction.tex b/chapters/introduction.tex index 936199935..25bfd84de 100644 --- a/chapters/introduction.tex +++ b/chapters/introduction.tex @@ -79,13 +79,13 @@ \section{Scope of the Specification}\doublelabel{scope-of-the-specification} \end{itemize} Therefore, a flat hybrid DAE is seen as a set of equations where some of -the equations are only conditionally evaluated (e.g. instantaneous +the equations are only conditionally evaluated (e.g.\ instantaneous equations are only evaluated when the corresponding when-condition becomes true). Initial setup of the model is specified using start-values and instantaneous equations that hold at the initial time only. -A Modelica class may also contain annotations, i.e. formal comments, +A Modelica class may also contain annotations, i.e.\ formal comments, which specify graphical representations of the class (icon and diagram), documentation text for the class, and version information. diff --git a/chapters/lexicalstructure.tex b/chapters/lexicalstructure.tex index bdcce51d1..c7506d236 100644 --- a/chapters/lexicalstructure.tex +++ b/chapters/lexicalstructure.tex @@ -78,7 +78,7 @@ \subsection{Identifiers}\doublelabel{identifiers} \lstinline!Inductor! and \lstinline!inductor! are different. The second form \lstinline!(Q-IDENT)! starts with a single quote, followed by a sequence of any printable ASCII character, where single-quote must be preceded by backslash, and -terminated by a single quote, e.g. \lstinline!'12H'!, \lstinline!'13\'H'!, +terminated by a single quote, e.g.\ \lstinline!'12H'!, \lstinline!'13\'H'!, \lstinline!'+foo'!. Control characters in quoted identifiers have to use string escapes. The single quotes are part of the identifier, i.e., \lstinline!'x'! and \lstinline!x! @@ -158,7 +158,7 @@ \subsection{Floating Point Numbers}\doublelabel{floating-point-numbers} \subsection{Integer Literals}\doublelabel{integer-literals} -Literals of type \lstinline!Integer! are sequences of decimal digits, e.g. as in the +Literals of type \lstinline!Integer! are sequences of decimal digits, e.g.\ as in the integer numbers \lstinline!33!, \lstinline!0!, \lstinline!100!, \lstinline!30030044!. The minimal recommended number range is from -2147483648 to +2147483647 corresponding to a two's-complement 32-bit integer implementation. @@ -203,7 +203,7 @@ \subsection{Strings}\doublelabel{strings} \end{lstlisting} Concatenation of string literals in certain situations (see the Modelica -grammar) is denoted by the + operator in Modelica, e.g. \lstinline!"a"! + \lstinline!"b"! +grammar) is denoted by the + operator in Modelica, e.g.\ \lstinline!"a"! + \lstinline!"b"! becomes \lstinline!"ab"!. This is useful for expressing long string literals that need to be written on several lines. diff --git a/chapters/library.tex b/chapters/library.tex index 554bcf650..5917510ca 100644 --- a/chapters/library.tex +++ b/chapters/library.tex @@ -12,7 +12,7 @@ \chapter{The Modelica Standard Library}\doublelabel{the-modelica-standard-librar commercial Modelica simulation environments. The Modelica Standard Library is tool-neutral, and relies on a small library, ModelicaServices, that each conformant tool must implement to handle -tool-specific couplings e.g. for animation. Furthermore, other people +tool-specific couplings e.g.\ for animation. Furthermore, other people and organizations are developing free and commercial Modelica libraries. For information about these libraries and for downloading the free libraries see \url{https://www.modelica.org/libraries/}. diff --git a/chapters/literature.tex b/chapters/literature.tex index 78958f580..6166bbe5d 100644 --- a/chapters/literature.tex +++ b/chapters/literature.tex @@ -2,7 +2,7 @@ \chapter{Literature}\doublelabel{literature} Benveniste A., Caspi P., Edwards S.A., Halbwachs N., Le Guernic P., and Simone R. (2003): \bibitemtitle{The Synchronous Languages Twelve Years Later}. -Proc. of the IEEE, Vol., 91, No. 1. +Proc.\ of the IEEE, Vol., 91, No. 1. \url{https://doi.org/10.1109/JPROC.2002.805826} Colaco J.-L., and Pouzet M. (2003): @@ -12,7 +12,7 @@ \chapter{Literature}\doublelabel{literature} Elmqvist H., Otter M. and Cellier F.E. (1995): \bibitemtitle{Inline Integration: A New Mixed Symbolic/Numeric Approach for Solving Differential-Algebraic Equation Systems}. -Keynote Address, Proceedings ESM'95, European Simulation Multiconference, Prague, Czech Republic, June 5-8, 1995, pp. xxiii-xxxiv. +Keynote Address, Proceedings ESM'95, European Simulation Multiconference, Prague, Czech Republic, June 5-8, 1995, pp.\ xxiii-xxxiv. \url{http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.127.3787\&rep=rep1\&type=pdf} Forget J., F. Boniol, D. Lesens, C. Pagetti (2008): diff --git a/chapters/operatorsandexpressions.tex b/chapters/operatorsandexpressions.tex index b188f2bfc..8f545727d 100644 --- a/chapters/operatorsandexpressions.tex +++ b/chapters/operatorsandexpressions.tex @@ -23,7 +23,7 @@ \section{Expressions}\doublelabel{expressions} Modelica equations, assignments and declaration equations contain expressions. -Expressions can contain basic operations, \lstinline!+!, \lstinline!-!, \lstinline!*!, \lstinline!/!, \lstinline!^!, etc. with +Expressions can contain basic operations, \lstinline!+!, \lstinline!-!, \lstinline!*!, \lstinline!/!, \lstinline!^!, etc.\ with normal precedence as defined in the Table in \autoref{operator-precedence-and-associativity} and the grammar in \autoref{modelica-concrete-syntax}. The semantics of the operations is defined for both scalar and array arguments in \autoref{scalar-vector-matrix-and-array-operator-functions}. @@ -116,13 +116,9 @@ \section{Operator Precedence and Associativity}\doublelabel{operator-precedence- \section{Evaluation Order}\doublelabel{evaluation-order} -A tool is free to solve equations, reorder expressions and to not -evaluate expressions if their values do not influence the result (e.g. -short-circuit evaluation of Boolean expressions). If-statements and -if-expressions guarantee that their clauses are only evaluated if the -appropriate condition is true, but relational operators generating state -or time events will during continuous integration have the value from -the most recent event. +A tool is free to solve equations, reorder expressions and to not evaluate expressions if their values do not influence the result (e.g.\ short-circuit +evaluation of Boolean expressions). If-statements and if-expressions guarantee that their clauses are only evaluated if the appropriate condition is true, +but relational operators generating state or time events will during continuous integration have the value from the most recent event. If a numeric operation overflows the result is undefined. For literals it is recommended to automatically convert the number to another type @@ -249,7 +245,7 @@ \section{Equality, Relational, and Logical Operators}\doublelabel{equality-relat \lstinline!v1! or \lstinline!v2! shall, unless used in a function, not be a subtype of \lstinline!Real!. \begin{nonnormative} The reason for this rule is that relations with \lstinline!Real! arguments are transformed to state events (see Events, \autoref{events-and-synchronization}) - and this transformation becomes unnecessarily complicated for the \lstinline!==! and \lstinline!<>! relational operators (e.g. two crossing functions instead + and this transformation becomes unnecessarily complicated for the \lstinline!==! and \lstinline!<>! relational operators (e.g.\ two crossing functions instead of one crossing function needed, epsilon strategy needed even at event instants). Furthermore, testing on equality of Real variables is questionable on machines where the number length in registers is different to number length in main memory. \end{nonnormative} @@ -468,12 +464,12 @@ \subsubsection{Event Triggering Mathematical Functions}\doublelabel{event-trigge \autoref{clocked-discrete-time-and-clocked-discretized-continuous-time-partition}). These expression for \lstinline!div!, \lstinline!ceil!, \lstinline!floor!, and \lstinline!integer! are event generating expression. The event generating expression for -\lstinline!mod(x,y)! is \lstinline!floor(x/y)!, and for \lstinline!rem(x,y)! it is \lstinline!div(x,y)! --- i.e. events +\lstinline!mod(x,y)! is \lstinline!floor(x/y)!, and for \lstinline!rem(x,y)! it is \lstinline!div(x,y)! --- i.e.\ events are not generated when \lstinline!mod! or \lstinline!rem! changes continuously in an interval, but when they change discontinuously from one interval to the next. \begin{nonnormative} -If this is not desired, the \lstinline!noEvent! function can be applied to them. E.g. \lstinline!noEvent(integer(v))!. +If this is not desired, the \lstinline!noEvent! function can be applied to them. E.g.\ \lstinline!noEvent(integer(v))!. \end{nonnormative} \begin{longtable}{|p{2cm}|p{12cm}|} \hline @@ -860,7 +856,7 @@ \subsubsection{cardinality (deprecated)}\doublelabel{cardinality-deprecated} \end{lstlisting} \end{nonnormative} -The cardinality is counted after removing conditional components. and +The cardinality is counted after removing conditional components, and may not be applied to expandable connectors, elements in expandable connectors, or to arrays of connectors (but can be applied to the scalar elements of array of connectors). \lstinline!cardinality! should only @@ -908,7 +904,7 @@ \subsubsection{homotopy}\doublelabel{homotopy} $f_1$ and $f_2$ together. The suggested approach is ``conceptual'', because more efficient -implementations are possible, e.g. by determining the smallest iteration +implementations are possible, e.g.\ by determining the smallest iteration loop, that contains the equations of the first BLT block in which \lstinline!homotopy! is present and all equations up to the last BLT block that describes a non-linear algebraic equation system. @@ -1100,7 +1096,7 @@ \subsubsection{getInstanceName}\doublelabel{getinstancename} returns \lstinline!"Vehicle.engine.controller"!. \end{example} -If this function is not called inside a model or block (e.g. the +If this function is not called inside a model or block (e.g.\ the function is called in a function or in a constant of a package), the return value is not specified. @@ -1174,7 +1170,7 @@ \subsection{Event-Related Operators with Function Syntax}\doublelabel{event-rela % edge \lstinline!edge(b)! & Is expanded into \lstinline!(b and not pre(b))! for Boolean variable -\lstinline!b!. The same restrictions as for \lstinline!pre! apply (e.g. not to be +\lstinline!b!. The same restrictions as for \lstinline!pre! apply (e.g.\ not to be used in function classes).\\ \hline % change diff --git a/chapters/overloaded.tex b/chapters/overloaded.tex index b1a9bb636..aaf5658c0 100644 --- a/chapters/overloaded.tex +++ b/chapters/overloaded.tex @@ -67,7 +67,7 @@ \section{Matching Function}\doublelabel{matching-function} All functions defined inside the \lstinline!operator! class must return one output (based on the restriction above), and may include functions with -optional arguments, i.e. functions of the form +optional arguments, i.e.\ functions of the form \begin{lstlisting}[language=modelica,mathescape=true] function f @@ -297,8 +297,8 @@ \section{Overloaded Binary Operations}\doublelabel{overloaded-binary-operations} Otherwise the expression is erroneous. \end{enumerate} -For an element-wise operator, a .op b, items 1, 4, and 5 are used; e.g. -the operator \lstinline!.+! will always be defined in terms of \lstinline!'+'!. +%henrikt-ma: Insane to refer to items by hard-coded numbers. +For an element-wise operator, \lstinline!a .op b!, items 1, 4, and 5 are used; e.g.\ the operator \lstinline!.+! will always be defined in terms of \lstinline!'+'!. Restrictions: \begin{itemize} @@ -540,7 +540,7 @@ \section{Example of Overloading for Complex Numbers}\doublelabel{example-of-over extend from any of its enclosing scopes implies that: \begin{lstlisting}[language=modelica,mathescape=true] package A - extends Icon; //Ok. + extends Icon; // Ok operator record B $\ldots$ end B; end A; diff --git a/chapters/packages.tex b/chapters/packages.tex index 5e57b58e3..f7e4a3f26 100644 --- a/chapters/packages.tex +++ b/chapters/packages.tex @@ -78,7 +78,7 @@ \subsection{Importing Definitions from a Package}\doublelabel{importing-definiti \lstinline!import! $\mathit{shortpackagename}$ \lstinline!=! $\mathit{packagename}$\lstinline!;! (renaming import) -\lstinline!import! $\mathit{shortpackagename}$ \lstinline!=! ${[}\mathit{packagename}$\lstinline!.!${]}\mathit{definitionname}$\lstinline!;! (renaming single def. import) +\lstinline!import! $\mathit{shortpackagename}$ \lstinline!=! ${[}\mathit{packagename}$\lstinline!.!${]}\mathit{definitionname}$\lstinline!;! (renaming single def.\ import) Here $\mathit{packagename}$ is the fully qualified name of the imported package including possible dot notation and $\mathit{definitionname}$ is the @@ -92,7 +92,7 @@ \subsubsection{Lookup of Imported Names}\doublelabel{lookup-of-imported-names} import clause. For lookup in general -- including how import clauses are used, see \autoref{static-name-lookup}. -Lookup of the name of an imported package or class, e.g. \lstinline!A.B.C! in the +Lookup of the name of an imported package or class, e.g.\ \lstinline!A.B.C! in the clauses \lstinline!import A.B.C; import D=A.B.C; import A.B.C.*!, deviates from the normal lexical lookup by starting the lexical lookup of the first part of the name at the top-level. @@ -210,7 +210,7 @@ \subsubsection{Mapping a Package/Class Hierarchy into a Directory Hierarchy (Str \subsubsection{Mapping a Package/Class Hierarchy into a Single File (Nonstructured Entity)}\doublelabel{mapping-a-package-class-hierarchy-into-a-single-file-nonstructured-entity} -When mapping a package or class-hierarchy to a file (e.g. the file \filename{A.mo}), that file shall only define a single class \lstinline!A! with a +When mapping a package or class-hierarchy to a file (e.g.\ the file \filename{A.mo}), that file shall only define a single class \lstinline!A! with a name matching the name of the nonstructured entity. In a file hierarchy the files shall have the extension \filename{.mo}. A \filename{.mo} file defining more than one class cannot be part of the mapping @@ -271,21 +271,13 @@ \subsection{External resources}\doublelabel{external-resources} that precedes it. The first part of the path may not be the name of a class in the package given by the authority. -When Modelica packages are stored hierarchically in a file-system (i.e. -package \lstinline!A! in a directory \filename{A} containing \filename{package.mo}) the resource -\filename{modelica://A/Resources/C.jpg} should be stored in the file -\filename{A/Resources/C.jpg}, it is not recommend to use \filename{modelica://A.B/C.jpg} -for referencing resources; it could be stored in the file \filename{A/B/C.jpg} -- -which is counter-intuitive if \lstinline!A.B! is stored together with \lstinline!A!. When -Modelica packages are stored in other formats a similar mapping should -be defined, such that a resource with a given path should be unique for -any package name that precedes it. The first part of the path may not be -the name of a class in the package given by the authority. As above for -\filename{Modelica 3.2.1/package.mo} i.e. resources starting from \filename{Modelica -3.2.1}, and \filename{modelica://Modelica.Mechanics/C.jpg} is \filename{Modelica -3.2.1/Mechanics/C.jpg} - regardless of whether \lstinline!Modelica.Mechanics! is -stored in \filename{Modelica 3.2.1/package.mo}, \filename{Modelica -3.2.1/Mechanics/package.mo}, or \filename{Modelica 3.2.1/Mechanics.mo}. +When Modelica packages are stored hierarchically in a file-system (i.e.\ package \lstinline!A! in a directory \filename{A} containing \filename{package.mo}) the resource +\filename{modelica://A/Resources/C.jpg} should be stored in the file \filename{A/Resources/C.jpg}, it is not recommend to use \filename{modelica://A.B/C.jpg} for referencing +resources; it could be stored in the file \filename{A/B/C.jpg} --- which is counter-intuitive if \lstinline!A.B! is stored together with \lstinline!A!. When Modelica packages +are stored in other formats a similar mapping should be defined, such that a resource with a given path should be unique for any package name that precedes it. The first +part of the path may not be the name of a class in the package given by the authority. As above for \filename{Modelica 3.2.1/package.mo} i.e.\ resources starting from +\filename{Modelica 3.2.1}, and \filename{modelica://Modelica.Mechanics/C.jpg} is \filename{Modelica 3.2.1/Mechanics/C.jpg} --- regardless of whether \lstinline!Modelica.Mechanics! +is stored in \filename{Modelica 3.2.1/package.mo}, \filename{Modelica 3.2.1/Mechanics/package.mo}, or \filename{Modelica 3.2.1/Mechanics.mo}. For a Modelica-package stored as a single file, \filename{A.mo}, the resource \filename{modelica://A/C.jpg} refers to a file \filename{C.jpg} stored in the same @@ -324,7 +316,7 @@ \subsection{The Modelica Library Path -- MODELICAPATH}\doublelabel{the-modelica- in general not advisable for a program installation to modify global environment variables. The version information for a library (as defined in \autoref{annotations-for-version-handling}) may also be used during this search to search for a -specific version of the library (e.g. if Modelica library version 2.2 is +specific version of the library (e.g.\ if Modelica library version 2.2 is needed and the first directory in \lstinline!MODELICAPATH! contain Modelica library version 2.1, whereas the second directory contains Modelica version 2.2, then Modelica library version 2.2 is loaded from the second directory.). @@ -356,7 +348,7 @@ \subsubsection{Example of Searching MODELICAPATH}\doublelabel{example-of-searchi \includegraphics[width=6in,height=2in]{modelicapath} \end{figure} -Assume that we want to access the package \lstinline!MyLib.Pack2! in \autoref{fig:roots} above, e.g. through an \lstinline!import!-clause \lstinline!import MyLib.Pack2;!. +Assume that we want to access the package \lstinline!MyLib.Pack2! in \autoref{fig:roots} above, e.g.\ through an \lstinline!import!-clause \lstinline!import MyLib.Pack2;!. During lookup we first try to find a package \lstinline!MyLib! corresponding to the first part of the import name. It is not found in the top-level scope since it has not previously been loaded into the environment. diff --git a/chapters/revisions.tex b/chapters/revisions.tex index bf2b05a3b..aca51fea3 100644 --- a/chapters/revisions.tex +++ b/chapters/revisions.tex @@ -511,7 +511,7 @@ \subsection{Main changes in Modelica 3.3 Revision 1}\doublelabel{main-changes-in \href{https://github.com/modelica/ModelicaSpecification/issues/1459}{\#1459}, \href{https://github.com/modelica/ModelicaSpecification/issues/1497}{\#1497}. \item - Added definition of AssertionLevel, \autoref{assertionlevel}. ticket + Added definition of AssertionLevel, \autoref{assertionlevel}. Ticket \href{https://github.com/modelica/ModelicaSpecification/issues/962}{\#962}. \item Corrected typos at end of loops in examples,\autoref{enumeration-types} and @@ -1889,7 +1889,7 @@ \subsection{Main Changes in Modelica 3.0}\doublelabel{main-changes-in-modelica-3 New attribute \lstinline!Smooth = enumeration(None, Bezier)! for graphical objects and connection lines (Bezier defines a Bezier spline).\\ New attribute \lstinline!visible! in \lstinline!record Placement! allows to make a graphical - annotation invisible (e.g. after inheritance).\\ + annotation invisible (e.g.\ after inheritance).\\ New attributes \lstinline!startAngle!, \lstinline!endAngle! in record ellipse to define part of an ellipse.\\ New layer specific annotations \lstinline!IconMap! and \lstinline!DiagramMap! for extends.\\ @@ -2091,7 +2091,7 @@ \subsection{Main Changes in Modelica 2.1}\doublelabel{main-changes-in-modelica-2 base constraining type automatically to modifications. \item Enhanced redeclaration as needed, e.g., in the Modelica.Media library - under development (e.g. \lstinline!redeclare model name! or \lstinline!model extends name ()!). + under development (e.g.\ \lstinline!redeclare model name! or \lstinline!model extends name ()!). \item Handling of overdetermined connectors (needed, e.g., for multi-body systems and electrical power systems) including the new built-in @@ -2115,7 +2115,7 @@ \subsection{Main Changes in Modelica 2.1}\doublelabel{main-changes-in-modelica-2 in a mathematically clean way). \item More general identifiers by having any character in single quotes, - e.g. \lstinline!'+'! or '123.456\#1' are valid identifiers. \lstinline!'x'! and \lstinline!x! are + e.g.\ \lstinline!'+'! or '123.456\#1' are valid identifiers. \lstinline!'x'! and \lstinline!x! are different identifiers. This is useful for a direct mapping of product identifiers to model names and for having the usual symbols for digital electrical signals as enumerations (such as \lstinline!'+'!, \lstinline!'-'!, \lstinline!'0'!, @@ -2370,7 +2370,7 @@ \subsection{Main Changes in Modelica 1.4}\doublelabel{main-changes-in-modelica-1 \item Quantity attribute also for base types Boolean, Integer, String (and not only for Real), in order to allow abstracted variables to refer to - physical quantities (e.g. \lstinline!Boolean i(quantity="Current")! is true if + physical quantities (e.g.\ \lstinline!Boolean i(quantity="Current")! is true if current is flowing and is false if no current is flowing). \item \lstinline!final! keyword also allowed in declaration, to prevent modification. diff --git a/chapters/scoping.tex b/chapters/scoping.tex index 261646010..84c4266ce 100644 --- a/chapters/scoping.tex +++ b/chapters/scoping.tex @@ -95,12 +95,11 @@ \subsection{Simple Name Lookup}\doublelabel{simple-name-lookup} this step produces matches from several unqualified imports. \end{itemize} -Import statements defined in inherited classes are ignored for the lookup, i.e. import statements are not inherited. +Import statements defined in inherited classes are ignored for the lookup, i.e.\ import statements are not inherited. \subsection{Composite Name Lookup}\doublelabel{composite-name-lookup} -For a composite name of the form \lstinline!A.B! or \lstinline!A.B.C!, etc. lookup is performed -as follows: +For a composite name of the form \lstinline!A.B! or \lstinline!A.B.C!, etc.\ lookup is performed as follows: \begin{itemize} \item The first identifier (\lstinline!A!) is looked up as defined above. @@ -150,7 +149,7 @@ \subsection{Global Name Lookup}\doublelabel{global-name-lookup} If the name is simple then the class \lstinline!A! is the result of lookup. \item If the name is a composite name then the class \lstinline!A! is temporarily - flattened with an empty environment (i.e. no modifiers, see + flattened with an empty environment (i.e.\ no modifiers, see \autoref{modification-environment}) and using the enclosing classes of the denoted class. The rest of the name (e.g., \lstinline!B! or \lstinline!B.C!) is looked up among the declared named elements of the temporary flattened class. If the class does not @@ -190,7 +189,7 @@ \section{Instance Hierarchy Name Lookup of Inner Declarations}\doublelabel{insta If there is one (or more) \lstinline!outer! declarations of a partial class it is an error. \item - In other cases, i.e. if a unique non-partial class is used for all + In other cases, i.e.\ if a unique non-partial class is used for all \lstinline!outer! declarations of the same name lacking a matching inner declaration, then an \lstinline!inner! declaration of that class is automatically added at the top of the model and diagnostics is given. @@ -409,7 +408,7 @@ \subsection{Instantiation}\doublelabel{instantiation} \subsubsection{The Class Tree}\doublelabel{the-class-tree} All necessary libraries including the model which is to be instantiated -are loaded from e.g. file system and form a so called \firstuse{class tree}. +are loaded from e.g.\ file system and form a so called \firstuse{class tree}. This tree represents the syntactic information from the class definitions. It contains also all modifications at their original locations in syntactic form. The builtin classes are put into the unnamed root of the class tree. @@ -496,7 +495,7 @@ \subsubsection{Steps of Instantiation}\doublelabel{steps-of-instantiation} \paragraph*{The element itself}\doublelabel{the-element-itself} A partially instantiated class or component is an element that is ready -to be instantiated; a partially instantiated element (i.e. class or +to be instantiated; a partially instantiated element (i.e.\ class or component) is comprised of a reference to the original element (from the class tree) and the modifiers for that element (including a possible redeclaration). @@ -524,7 +523,7 @@ \subsubsection{Steps of Instantiation}\doublelabel{steps-of-instantiation} declaration are copied to the instance without merging. \begin{nonnormative} -The annotations can be relevant for simulations, e.g. annotations for code generation (\autoref{annotations-for-code-generation}.), simulation experiments +The annotations can be relevant for simulations, e.g.\ annotations for code generation (\autoref{annotations-for-code-generation}.), simulation experiments (\autoref{annotations-for-simulation-experiments}) or functions (\autoref{declaring-derivatives-of-functions}, \autoref{declaring-inverses-of-functions} and \autoref{external-function-interface}). \end{nonnormative} @@ -658,7 +657,7 @@ \subsection{Generation of the flat equation system}\doublelabel{generation-of-th \begin{nonnormative} This identifier is normally constructed from the names of the instances along a path in the instance tree (and omitting the unnamed nodes of extends clauses), separated by dots. Either the referenced instance belongs to the model to be simulated the path starts at the model itself, or if not, it starts at the unnamed root of the instance -tree, e.g. in case of a constant in a package. +tree, e.g.\ in case of a constant in a package. \end{nonnormative} \begin{nonnormative} @@ -685,7 +684,6 @@ \subsection{Generation of the flat equation system}\doublelabel{generation-of-th At each visited component instance, the name is inserted into the variables list. Then the conditional declaration expression is evaluated if applicable. - \begin{itemize} \item The variable list is updated with the actual instance @@ -697,9 +695,8 @@ \subsection{Generation of the flat equation system}\doublelabel{generation-of-th instances are resolved and attached to the variable to define their complete dimension. \item - If it is of record or simple type (Boolean, Integer, enumeration, - Real, String, Clock, ExternalObject): - + If it is of record or simple type (\lstinline!Boolean!, \lstinline!Integer!, enumeration, + \lstinline!Real!, \lstinline!String!, \lstinline!Clock!, \lstinline!ExternalObject!): \begin{itemize} \item In the modifications of \emph{value} attribute references are @@ -710,13 +707,12 @@ \subsection{Generation of the flat equation system}\doublelabel{generation-of-th overridden by the value for an entire record; \autoref{merging-of-modifications}. \end{itemize} \item - If it is of simple type (Boolean, Integer, enumeration, Real, - String, Clock, ExternalObject): - + If it is of simple type (\lstinline!Boolean!, \lstinline!Integer!, enumeration, \lstinline!Real!, + \lstinline!String!, \lstinline!Clock!, \lstinline!ExternalObject!): \begin{itemize} \item - In the modifications of \emph{non-value} attributes, e.g. start, - fixed etc. references are resolved using the instance scope of the + In the modifications of \emph{non-value} attributes, e.g.\ \lstinline!start!, + \lstinline!fixed! etc.\ references are resolved using the instance scope of the modification. An equation is formed from a reference to the name of the instance appended by a dot and the attribute name and the resolved modification value of the instance, and included into the @@ -728,7 +724,7 @@ \subsection{Generation of the flat equation system}\doublelabel{generation-of-th \item If there are equation or algorithm sections in the class definition of the instance, references are resolved using the instance scope of the - instance and are included in the equation system. Some references -- + instance and are included in the equation system. Some references --- in particular to non simple, non record objects like connectors in connect statements and states in transition statements are not resolved yet and handled afterwards. @@ -748,10 +744,10 @@ \subsection{Generation of the flat equation system}\doublelabel{generation-of-th Conditional components with false condition are removed afterwards and they are not part of the simulation model. \begin{nonnormative} - Thus e.g. parameters don't need values in them. However, type-error can be detected. + Thus e.g.\ parameters don't need values in them. However, type-error can be detected. \end{nonnormative} \item - Each reference is checked, whether it is a valid reference, e.g. the + Each reference is checked, whether it is a valid reference, e.g.\ the referenced object belongs to or is an instance, where all existing conditional declaration expressions evaluate to true or it is a constant in a package. @@ -761,8 +757,8 @@ \subsection{Generation of the flat equation system}\doublelabel{generation-of-th \end{itemize} This leads to a flattened equation system, except for connect and transition statements. These have to be transformed as described in -\autoref{connectors-and-connections} and \autoref{state-machines}. This may lead to further changes in the instance tree (e.g. from expandable connectors -(\autoref{expandable-connectors})) and additional equations in the flattened equation system (e.g. connect equations (\autoref{generation-of-connection-equations}), +\autoref{connectors-and-connections} and \autoref{state-machines}. This may lead to further changes in the instance tree (e.g.\ from expandable connectors +(\autoref{expandable-connectors})) and additional equations in the flattened equation system (e.g.\ connect equations (\autoref{generation-of-connection-equations}), generated equations for state machine semantics (\autoref{semantics-summary})). \begin{nonnormative} @@ -770,6 +766,6 @@ \subsection{Generation of the flat equation system}\doublelabel{generation-of-th contained and covers all information needed to transform it to a simulatable model, but the class and instance trees are still needed: in the transformation process, there might be the need to instantiate -further functions, e.g. from \lstinline!derivative! annotation or from \lstinline!inverse! +further functions, e.g.\ from \lstinline!derivative! annotation or from \lstinline!inverse! annotation etc., on demand. \end{nonnormative} diff --git a/chapters/statemachines.tex b/chapters/statemachines.tex index 975dd8958..3274b5fb4 100644 --- a/chapters/statemachines.tex +++ b/chapters/statemachines.tex @@ -84,10 +84,10 @@ \section{Transitions}\doublelabel{transitions} transition with the smallest value of \lstinline!priority! fires. It is required that $\textrm{priority}\ge 1$ and that for all transitions from the same state, the priorities are different. If \lstinline!reset = true!, the states of the -target state are reinitialized, i.e. state machines are restarted in +target state are reinitialized, i.e.\ state machines are restarted in initial state and state variables are reset to their start values. If synchronize=true, any transition is disabled until all state machines of -the from-state have reached final states, i.e. states without outgoing +the from-state have reached final states, i.e.\ states without outgoing transitions. For the precise details about firing a transition, see \autoref{state-machine-semantics}.\\ \hline \lstinline!initialState(state)! & Argument \lstinline!state! is the block instance @@ -112,13 +112,13 @@ \section{Transitions}\doublelabel{transitions} It is an error if the instance is not a state of a state machine.\\ \hline \lstinline!ticksInState()! & Returns the number of ticks of the clock of the state machine for which the currently active state has maintained its active state without interruption, -i.e. without local or hierarchical transitions from this state. +i.e.\ without local or hierarchical transitions from this state. In the case of a self-transition to the currently active state or to an active enclosing state, the number is reset to one. This function can only be used in state machines.\\ \hline \lstinline!timeInState()! & Returns the time duration as \lstinline!Real! in {[}s{]} for which the currently active state has maintained its active state without interruption, -i.e. without local or hierarchical transitions from this state. +i.e.\ without local or hierarchical transitions from this state. In the case of a self-transition to the currently active state or to an active enclosing state, the time is reset to zero. This function can only be used in state machines.\\ \hline @@ -240,15 +240,14 @@ \section{State Machine Semantics}\doublelabel{state-machine-semantics} \subsection{State Activation}\doublelabel{state-activation} -The state update starts from nextState, i.e., what has been determined -to be the next state at the previous time. selectedState takes into -account if a reset of the state machine is to be done. +The state update starts from \lstinline!nextState!, i.e., what has been determined to be the next state at the previous time. +\lstinline!selectedState! takes into account if a reset of the state machine is to be done. \begin{lstlisting}[language=modelica] output Integer selectedState = if reset then 1 else previous(nextState); \end{lstlisting} The integer fired is calculated as the index of the transition to be -fired by checking that selectedState is the from-state and the condition +fired by checking that \lstinline!selectedState! is the from-state and the condition is true for an immediate transition or previous(condition) is true for a delayed transition. The max function returns the index of the transition with highest priority or 0. @@ -268,7 +267,7 @@ \subsection{State Activation}\doublelabel{state-activation} of one integer variable delayed. The integer immediate is calculated as the index of the immediate -transition to potentially be fired by checking that selectedState is the +transition to potentially be fired by checking that \lstinline!selectedState! is the from-state and the condition is true. The max function returns the index of the transition with true condition and highest priority or 0. @@ -283,9 +282,9 @@ \subsection{State Activation}\doublelabel{state-activation} \end{lstlisting} In a similar way, the \lstinline!Integer delayed! is calculated as the index for a -potentially delayed transition, i.e. a transition taking place at the +potentially delayed transition, i.e.\ a transition taking place at the next clock tick. In this case the from-state needs to be equal to -nextState: +\lstinline!nextState!: \begin{lstlisting}[language=modelica] Integer delayed = max(if (if not t[i].immediate and t[i].from == nextState @@ -301,7 +300,7 @@ \subsection{State Activation}\doublelabel{state-activation} \begin{lstlisting}[language=modelica] Integer fired = max(previous(delayed), immediate); \end{lstlisting} -nextState is set to the found transitions to-state: +\lstinline!nextState! is set to the found transitions to-state: \begin{lstlisting}[language=modelica] Integer nextState = if active then (if fired > 0 @@ -310,7 +309,7 @@ \subsection{State Activation}\doublelabel{state-activation} else previous(nextState); \end{lstlisting} In order to define synchronize transitions, each state machine must -determine which are the final states, i.e. states without +determine which are the final states, i.e.\ states without from-transitions and to determine if the state machine is in a final state currently: \begin{lstlisting}[language=modelica] @@ -471,7 +470,7 @@ \subsection{Example}\doublelabel{example} \lstinline!state1! is a meta state with two parallel state machines in it. \item \lstinline!stateA! declares \lstinline!v! as \lstinline!outer output!. \lstinline!state1! is on an intermediate - level and declares \lstinline!v! as \lstinline!inner outer output!, i.e. matches lower level + level and declares \lstinline!v! as \lstinline!inner outer output!, i.e.\ matches lower level \lstinline!outer v! by being \lstinline!inner! and also matches higher level \lstinline!inner v! by being \lstinline!outer!. The top level declares \lstinline!v! as \lstinline!inner! and gives the start value. \item diff --git a/chapters/statements.tex b/chapters/statements.tex index 9889e296c..7ec4341cb 100644 --- a/chapters/statements.tex +++ b/chapters/statements.tex @@ -33,7 +33,7 @@ \subsection{Execution of an algorithm in a model}\doublelabel{execution-of-an-al \lstinline!:=! are initialized (at least conceptually): \begin{itemize} \item - A non-discrete variable is initialized with its start value (i.e. the + A non-discrete variable is initialized with its start value (i.e.\ the value of the start-attribute). \item A discrete variable \lstinline!v! is initialized with \lstinline!pre(v)!. @@ -261,7 +261,7 @@ \subsubsection{Implicit Iteration Ranges}\doublelabel{implicit-iteration-ranges} \subsubsection{Types as Iteration Ranges }\doublelabel{types-as-iteration-ranges} The iteration range can be specified as \lstinline!Boolean! or as an enumeration -type. This means iteration over the type from min to max, i.e. for +type. This means iteration over the type from min to max, i.e.\ for Boolean it is the same as \lstinline!false:true! and for an enumeration E it is the same as E.min:E.max. This can be used for \lstinline!for! loops and reduction expressions. @@ -489,7 +489,7 @@ \subsubsection{Defining When-Statements by If-Statements}\doublelabel{defining-w \end{lstlisting} with \lstinline!edge(A)= A and not pre(A)! and the additional guarantee, that the statements within this special if-statement are only evaluated at event -instants. The difference compared to the when-statements is that e.g. \lstinline!pre! may only be used on continuous-time real variables inside the body +instants. The difference compared to the when-statements is that e.g.\ \lstinline!pre! may only be used on continuous-time real variables inside the body of a when-clause and not inside these if-statements. \subsection{Special Statements}\doublelabel{special-statements} diff --git a/chapters/stream.tex b/chapters/stream.tex index 717b6e3fc..575d3793a 100644 --- a/chapters/stream.tex +++ b/chapters/stream.tex @@ -413,16 +413,10 @@ \section{Stream Operator actualStream}\doublelabel{stream-operator-actualstream} wants to avoid events entirely, he/she may enclose the right-hand side of (1) with \lstinline!noEvent!. -Equations like (2) might be used for monitoring purposes (e.g. -plots), in order to inspect what the actual enthalpy of the fluid -flowing through a port is. In this case, the user will probably want to -see the change due to flow reversal at the exact instant, so an event -should be generated. If the user doesn't bother, then he/she should -enclose the right-hand side of (2) with \lstinline!noEvent!. Since the output of -\lstinline!actualStream! will be discontinuous, it should not be used by itself to -model physical behaviour (e.g., to compute densities used in momentum -balances) --- \lstinline!inStream! should be used for this purpose. -\lstinline!actualStream! should be used to model physical behaviour only when -multiplied by the corresponding flow variable (like in the above energy -balance equation), because this removes the discontinuity. +Equations like (2) might be used for monitoring purposes (e.g.\ plots), in order to inspect what the actual enthalpy of the fluid flowing through a port is. +In this case, the user will probably want to see the change due to flow reversal at the exact instant, so an event should be generated. If the user doesn't +bother, then he/she should enclose the right-hand side of (2) with \lstinline!noEvent!. Since the output of \lstinline!actualStream! will be discontinuous, +it should not be used by itself to model physical behaviour (e.g., to compute densities used in momentum balances) --- \lstinline!inStream! should be used +for this purpose. \lstinline!actualStream! should be used to model physical behaviour only when multiplied by the corresponding flow variable (like in the +above energy balance equation), because this removes the discontinuity. \end{nonnormative} diff --git a/chapters/synchronous.tex b/chapters/synchronous.tex index a7bc3e07d..e0d748ac0 100644 --- a/chapters/synchronous.tex +++ b/chapters/synchronous.tex @@ -80,9 +80,9 @@ \subsection{Overview}\doublelabel{overview} inference system proposed by (Colaco and Pouzet 2003) and implemented in Lucid Synchrone version 2 and 3 (Pouzet 2006). However, the Modelica approach also uses multi-rate periodic clocks based on - rational arithmetic introduced by (Forget et. al. 2008), as an + rational arithmetic introduced by (Forget et.~al.\ 2008), as an extension of the Lucid Synchrone semantics. These approaches belong to - the class of synchronous languages (Benveniste et. al. 2002). + the class of synchronous languages (Benveniste et.~al.\ 2002). \end{itemize} \end{nonnormative} @@ -150,9 +150,9 @@ \subsection{Rationale for Clocked Semantics}\doublelabel{rationale-for-clocked-s place, and otherwise is automatically propagated by clock inference. \item It is not possible to use a continuous-time model in when - clauses (e.g. some advanced controllers use an inverse model of a - plant in the feedforward path of the controller, see (Thümmel et. al. - 2005)). This powerful feature of Modelica to use a nonlinear plant + clauses (e.g.\ some advanced controllers use an inverse model of a + plant in the feedforward path of the controller, see (Thümmel et.~al.\ 2005)). + This powerful feature of Modelica to use a nonlinear plant model in a controller would require to export the continuous-time model with an embedded integration method and then import it in an environment where the rest of the controller is defined. With clocked @@ -274,7 +274,7 @@ \subsection{Argument Restrictions (Component Expression)}\doublelabel{argument-r following term is defined: \begin{description} \item[Component expression:] -A Component Reference which is an Expression, i.e. does not refer to +A Component Reference which is an Expression, i.e.\ does not refer to models or blocks with equations. It is an instance of a (a) base type, (b) derived type, (c) record, (d) an array of such an instance (a-c), (e) one or more elements of such an array (d) defined by index @@ -695,7 +695,7 @@ \subsection{Sub-clock conversion operators}\doublelabel{sub-clock-conversion-ope The optional input arguments \lstinline!factor! (default=0, min=0), and \lstinline!resolution! (default=1, min=1) are parameter expressions of type Integer. -Calls of the operators can use named arguments for the multi-letter arguments (i.e. not for u) with the given names, or positional arguments. +Calls of the operators can use named arguments for the multi-letter arguments (i.e.\ not for u) with the given names, or positional arguments. \begin{nonnormative} Named arguments can make the calls easier to understand. \end{nonnormative} @@ -930,7 +930,7 @@ \subsection{Flattening of Model}\doublelabel{flattening-of-model} \subsection{Connected Components of the Equations and Variables Graph}\doublelabel{connected-components-of-the-equations-and-variables-graph} Consider the set E of equations and the set V of unknown variables (not -constants and parameters) in a flattened model, i.e. M = \textless{}E, +constants and parameters) in a flattened model, i.e.\ M = \textless{}E, V\textgreater{}. The partitioning is described in terms of an undirected graph \textless{}N,~F\textgreater{} with the nodes N being the set of equations and variables, N = E + V. The set \lstinline!incidence(e)! for an equation @@ -1324,7 +1324,7 @@ \subsection{Solver Methods}\doublelabel{solver-methods} \begin{nonnormative} For the implicit integration methods the efficiency can be enhanced by utilizing the discretization formula during the symbolic transformation of the equations. For example, linear differential equations are then mapped to linear and not non-linear algebraic equation systems, and also the structure of the equations can be utilized. For details see -(Elmqvist et. al. 1995). It might be necessary to associate additional data for an implicit integration method, e.g. the relative tolerance to solve the non-linear algebraic +(Elmqvist et.~al.\ 1995). It might be necessary to associate additional data for an implicit integration method, e.g.\ the relative tolerance to solve the non-linear algebraic equation systems, or the maximum number of iterations in case of hard realtime requirements. This data is tool specific and is typically either defined with a vendor annotation or is given in the simulation environment. \end{nonnormative} diff --git a/chapters/syntax.tex b/chapters/syntax.tex index 3e8f6ccd6..d063ab1a9 100644 --- a/chapters/syntax.tex +++ b/chapters/syntax.tex @@ -33,7 +33,7 @@ \section{Lexical conventions}\doublelabel{lexical-conventions} (\url{http://www.unicode.org}; see \autoref{mapping-package-class-structures-to-a-hierarchical-file-system} for storing as UTF-8 on files) except double-quote """, and backslash "\textbackslash{}" For identifiers the redundant escapes (`\lstinline!\?!' and `\lstinline!\"!') are the same as the corresponding non-escaped -variants (`\lstinline!?!' and '\lstinline!"!'). The single quotes are part of an identifier. E.g. \lstinline!'x'! and +variants (`\lstinline!?!' and '\lstinline!"!'). The single quotes are part of an identifier. E.g.\ \lstinline!'x'! and \lstinline!x! are different IDENTs. Note: From e143772ae655c2c1551892b5fca0bbb67a6f772e Mon Sep 17 00:00:00 2001 From: Henrik Tidefelt Date: Tue, 16 Jun 2020 23:09:10 +0200 Subject: [PATCH 58/78] Change one instance of incorrect use of math into \lstinline --- chapters/arrays.tex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/chapters/arrays.tex b/chapters/arrays.tex index 65bd9b5a9..aa03060b1 100644 --- a/chapters/arrays.tex +++ b/chapters/arrays.tex @@ -309,7 +309,7 @@ \subsection{Specialized Array Constructor Functions}\doublelabel{specialized-arr Return the $n_{1} \times n_{2} \times n_{3} \times \ldots$ \lstinline!Integer! array with all elements equal to one ($n_{i} \geq 0$). The function needs one or more arguments, that is \lstinline!ones()! is not legal.\\ \hline \lstinline[mathescape=true]!fill(s, $n_{1}$, $n_{2}$, $n_{3}$, $\ldots$)! & -Returns the $n_{1} \times n_{2} \times n_{3} \times \ldots$ array with all elements equal to scalar or array expression $s$ +Returns the $n_{1} \times n_{2} \times n_{3} \times \ldots$ array with all elements equal to scalar or array expression \lstinline!s! ($n_{i} \geq 0$). The returned array has the same type as \lstinline!s!. Recursive definition: \lstinline[mathescape=true]!fill(s, $n_{1}$, $n_{2}$, $n_{3}$, $\ldots$)! = From 32f8c4f9b24b91d068c2876be1c0ac85dd9cb665 Mon Sep 17 00:00:00 2001 From: Henrik Tidefelt Date: Tue, 16 Jun 2020 23:10:10 +0200 Subject: [PATCH 59/78] Fix misc styling of array reductions --- chapters/arrays.tex | 83 +++++++++++++++++++++------------------------ 1 file changed, 39 insertions(+), 44 deletions(-) diff --git a/chapters/arrays.tex b/chapters/arrays.tex index aa03060b1..0dc0dec82 100644 --- a/chapters/arrays.tex +++ b/chapters/arrays.tex @@ -350,87 +350,82 @@ \subsection{Reduction Functions and Operators}\doublelabel{reduction-functions-a \lstinline!min(A)! & Returns the least element of array expression \lstinline!A!; as defined by \lstinline!!.\\ \hline -\lstinline!max(x,y)! +\lstinline!max(x, y)! & Returns the greatest element of the scalars \lstinline!x! and \lstinline!y!; as defined by \lstinline!>!.\\ \hline \begin{tabular}{@{}p{4cm}@{}} -\lstinline!max(e(i, ..., j)!\\ -\lstinline! for i in u,!\\ -\lstinline! ..., j in v)! +\lstinline[mathescape=true]!max(e(i, $\ldots$, j)!\\ +\lstinline[mathescape=true]! for i in u, $\ldots$,!\\ +\lstinline[mathescape=true]! j in v)! \end{tabular} & \begin{tabular}{@{}p{10cm}@{}} -Also described in \autoref{reduction-expressions} -Returns the greatest value (as defined by \lstinline!>!) of the scalar -expression \lstinline!e(i, ..., j)! evaluated for all combinations of \lstinline!i! in \lstinline!u!, \ldots, \lstinline!j! -in \lstinline!v!: +Also described in \autoref{reduction-expressions}. Returns the greatest value (as defined by \lstinline!>!) of the scalar expression +\lstinline[mathescape=true]!e(i, $\ldots$, j)! evaluated for all combinations of \lstinline!i! in \lstinline!u!, \ldots, \lstinline!j! in \lstinline!v!. \end{tabular}\\ \hline \lstinline!sum(A)! & \begin{tabular}{@{}p{10cm}@{}} -Returns the scalar sum of all the elements of array expression:\\ -\lstinline!=sum(A[j,k,...]) for j,k,...! +Returns the scalar sum of all the elements of array expression \lstinline!A!:\\ +\lstinline[mathescape=true]!= sum(A[j, k, $\ldots$] for j, k, $\ldots$)! \end{tabular}\\ \hline \begin{tabular}{@{}p{5cm}@{}} -\lstinline!sum(e(i, ..., j)!\\ -\lstinline! for i in u,!\\ -\lstinline! ..., j in v)! +\lstinline[mathescape=true]!sum(e(i, $\ldots$, j)!\\ +\lstinline[mathescape=true]! for i in u, $\ldots$,!\\ +\lstinline[mathescape=true]! j in v)! \end{tabular} & \begin{tabular}{@{}p{10cm}@{}} -Also described in \autoref{reduction-expressions}\\ -Returns the sum of the expression e(i, ..., j) evaluated for all -combinations of i in u, ..., j in v: For \lstinline!Integer! indexing this is - e(u{[}1{]},... - ,v{[}1{]})+e(u{[}2{]},... ,v{[}1{]})+... +e(u{[}end{]},... - ,v{[}1{]})+...+e(u{[}end{]},... ,v{[}end{]}) - For non-\lstinline!Integer! indexing this uses all valid indices instead of 1..\lstinline!end!. - The type of sum(e(i, ..., j) for i in u, ..., j - in v) is the same as the type of e(i,...j). +Also described in \autoref{reduction-expressions}. Returns the sum of the expression \lstinline[mathescape=true]!e(i, $\ldots$, j)! evaluated for all +combinations of \lstinline[mathescape=true]!i in u!, $\ldots$, \lstinline[mathescape=true]!j in v!: For \lstinline!Integer! indexing this is +\begin{lstlisting}[language=modelica,mathescape=true] +e(u[1], $\ldots$, v[1]) + e(u[2], $\ldots$, v[1]) + $\ldots$ + + e(u[end], $\ldots$, v[1]) + $\ldots$ + + e(u[end], $\ldots$, v[end]) +\end{lstlisting} +For non-\lstinline!Integer! indexing this uses all valid indices instead of 1..\lstinline!end!. +The type of \lstinline[mathescape=true]!sum(e(i, $\ldots$, j) for i in u, $\ldots$, j in v)! is the same as the type of \lstinline[mathescape=true]!e(i, $\ldots$, j)!. \end{tabular}\\ \hline \lstinline!product(A)! & \begin{tabular}{@{}p{10cm}@{}} -Returns the scalar product of all the elements of array expression A.\\ - \lstinline!=product(A[j,k,...] for j,k,...! +Returns the scalar product of all the elements of array expression \lstinline!A!:\\ +\lstinline[mathescape=true]!= product(A[j, k, $\ldots$] for j, k, $\ldots$)! \end{tabular}\\ \hline \begin{tabular}{@{}p{4cm}@{}} -\lstinline!product(e(i, ..., j)!\\ -\lstinline! for i in u,!\\ -\lstinline! ..., j in v)! +\lstinline[mathescape=true]!product(e(i, $\ldots$, j)!\\ +\lstinline[mathescape=true]! for i in u, $\ldots$,!\\ +\lstinline[mathescape=true]! j in v)! \end{tabular} & \begin{tabular}{@{}p{10cm}@{}} -Also described in \autoref{reduction-expressions}.\\ -Returns the product of the scalar expression e(i, ..., j) evaluated for -all combinations of i in u, ..., j in v: For \lstinline!Integer! indexing this is -\begin{lstlisting}[language=modelica] - e(u[1],...,v[1])*e(u[2],...,v[1])*... - *(u[end],...,v[1])*...*e(u[end],...,v[end]) +Also described in \autoref{reduction-expressions}. Returns the product of the scalar expression \lstinline[mathescape=true]!e(i, $\ldots$, j)! evaluated for +all combinations of \lstinline!i in u!, \ldots, \lstinline!j in v!: For \lstinline!Integer! indexing this is +\begin{lstlisting}[language=modelica,mathescape=true] +e(u[1], $\ldots$, v[1]) * e(u[2], $\ldots$, v[1]) * $\ldots$ + * e(u[end], $\ldots$, v[1]) * $\ldots$ + * e(u[end], $\ldots$, v[end]) \end{lstlisting} - For non-\lstinline!Integer! indexing this uses all valid indices instead of 1..\lstinline!end!. - The type of product(e(i, ..., j) for i in u, ..., j - in v) is the same as the type of e(i,...j). +For non-\lstinline!Integer! indexing this uses all valid indices instead of 1..\lstinline!end!. +The type of \lstinline[mathescape=true]!product(e(i, $\ldots$, j) for i in u, $\ldots$, j in v)! is the same as the type of \lstinline[mathescape=true]!e(i, $\ldots$, j)!. \end{tabular} \\ \hline \end{longtable} From 6f85e67a74af29ae0bd70ecf34a937bb10b1f9a1 Mon Sep 17 00:00:00 2001 From: Henrik Tidefelt Date: Wed, 17 Jun 2020 00:06:02 +0200 Subject: [PATCH 60/78] Misc style cleanup of matrix and vector algebra functions and constructors --- chapters/arrays.tex | 76 +++++++++++++++++++++++++++------------------ preamble.tex | 3 +- 2 files changed, 48 insertions(+), 31 deletions(-) diff --git a/chapters/arrays.tex b/chapters/arrays.tex index 0dc0dec82..364298460 100644 --- a/chapters/arrays.tex +++ b/chapters/arrays.tex @@ -493,59 +493,75 @@ \subsubsection{Reduction Expressions}\doublelabel{reduction-expressions} \subsection{Matrix and Vector Algebra Functions}\doublelabel{matrix-and-vector-algebra-functions} -The following set of built-in matrix and vector algebra functions are -available. The function transpose and symmetric can be applied to any matrix. The -functions outerProduct, cross and skew require Real/Integer -vector(s) or matrix as input(s) and returns a Real/Integer vector or matrix (the result is only Integer -if the input/all inputs are Integer): +The following set of built-in matrix and vector algebra functions are available. The function transpose and symmetric can be applied to any matrix. +The functions \lstinline!outerProduct!, \lstinline!cross! and \lstinline!skew! require \lstinline!Real!/\lstinline!Integer! vector(s) or matrix as input(s) +and returns a \lstinline!Real!/\lstinline!Integer! vector or matrix (the result is only \lstinline!Integer! if the input/all inputs are \lstinline!Integer!): \begin{longtable}[]{|p{3.5cm}|p{11.5cm}|} \caption{Matrix and vector algebra functions.}\\ \hline \tablehead{Modelica} & \tablehead{Explanation}\\ \hline \endhead \lstinline!transpose(A)! -& Permutes the first two dimensions of array A. It is an error, if array A +& Permutes the first two dimensions of array \lstinline!A!. It is an error, if array \lstinline!A! does not have at least 2 dimensions.\\ \hline -\lstinline!outerProduct(v1,v2)! -& Returns the outer product of vectors v1 and v2 ( = matrix(v1)*transpose( -matrix(v2) ) ).\\ \hline +\lstinline!outerProduct(v1, v2)! +& +\begin{tabular}{@{}p{10cm}@{}} +Returns the outer product of vectors \lstinline!v1! and \lstinline!v2!:\\ +\lstinline!= matrix(v1) * transpose(matrix(v2))! +\end{tabular}\\ \hline \lstinline!symmetric(A)! & Returns a symmetric matrix which is identical to the square matrix \lstinline!A! -on and above the diagonal, i.e., \lstinline!B := symmetric(A) ->! - \lstinline!B[i,j] := A[i,j], if i <= j, ! \lstinline! B[i,j] := A[j,i], if i > j!.\\ \hline -\lstinline!cross(x,y)! -& Returns the cross product of the 3-vectors x and y, i.e. -\lstinline!cross(x,y) = vector( [ x[2]*y[3]-x[3]*y[2]; x[3]*y[1]-x[1]*y[3]; x[1]*y[2]-x[2]*y[1] ] );!\\ \hline +on and above the diagonal, i.e., \lstinline!B := symmetric(A)! implies +\begin{equation*} +\text{\lstinline[mathescape=true]!B[$i$, $j$]!} = +\begin{cases} +\text{\lstinline[mathescape=true]!A[$i$, $j$]!} & \text{if $i \leq j$}\\ +\text{\lstinline[mathescape=true]!A[$j$, $i$]!} & \text{if $i > j$} +\end{cases} +\end{equation*}\\ \hline +\lstinline!cross(x, y)! +& +\begin{tabular}{@{}p{10cm}@{}} +Returns the cross product of the 3-vectors \lstinline!x! and \lstinline!y!: +\begin{lstlisting}[frame=none,aboveskip=-\parskip,belowskip=-\medskipamount] += vector([ x[2] * y[3] - x[3] * y[2]; + x[3] * y[1] - x[1] * y[3]; + x[1] * y[2] - x[2] * y[1] ]) +\end{lstlisting} +\end{tabular}\\ \hline \lstinline!skew(x)! -& Returns the 3 x 3 skew symmetric matrix associated with a 3-vector, - i.e., \lstinline!cross(x,y) = skew(x)*y; skew(x) = [0, -x[3], x[2]; x[3], 0, -x[1]; -x[2], x[1], 0];!\\ \hline +& +\begin{tabular}{@{}p{10cm}@{}} +Returns the $3 \times 3$ skew symmetric matrix associated with a 3-vector, i.e., \lstinline!cross(x, y) = skew(x) * y!, or --- equivalently --- \lstinline!skew(x)! +\begin{lstlisting}[frame=none,aboveskip=-\parskip,belowskip=-\medskipamount] += [ 0, -x[3], x[2] ; + x[3], 0, -x[1] ; + -x[2], x[1], 0 ] +\end{lstlisting} +\end{tabular}\\ \hline \end{longtable} \section{Vector, Matrix and Array Constructors}\doublelabel{vector-matrix-and-array-constructors} -The constructor function \lstinline!array(A,B,C,...)! constructs an array from its -arguments according to the following rules: +The constructor function \lstinline[mathescape=true]!array(A, B, C, $\ldots$)! constructs an array from its arguments according to the following rules: \begin{itemize} \item Size matching: All arguments must have the same sizes, i.e., - \lstinline!size(A)=size(B)=size(C)=!... + \lstinline!size(A)! = \lstinline!size(B)! = \lstinline!size(C)! = \ldots \item - All arguments must be type compatible expressions (\autoref{type-compatible-expressions}) giving - the type of the elements. The data type of the result array is the - maximally expanded type of the arguments. Real and Integer subtypes - can be mixed resulting in a Real result array where the Integer - numbers have been transformed to Real numbers. + All arguments must be type compatible expressions (\autoref{type-compatible-expressions}) giving the type of the elements. The data type of the result array is the + maximally expanded type of the arguments. \lstinline!Real! and \lstinline!Integer! subtypes can be mixed resulting in a \lstinline!Real! result array where the + \lstinline!Integer! numbers have been transformed to \lstinline!Real! numbers. \item - Each application of this constructor function adds a one-sized - dimension to the left in the result compared to the dimensions of the - argument arrays, i.e., \lstinline!ndims(array(A,B,C)) = ndims(A) + 1 = ndims(B) + 1, ...! + Each application of this constructor function adds a one-sized dimension to the left in the result compared to the dimensions of the argument arrays, i.e., + \lstinline[mathescape=true]!ndims(array(A, B, C)) = ndims(A) + 1 = ndims(B) + 1, $\ldots$! \item - \lstinline!{A, B, C, ...}! is a shorthand notation for \lstinline!array(A, B, C, ...)!. + \lstinline[mathescape=true]!{A, B, C, $\ldots$}! is a shorthand notation for \lstinline[mathescape=true]!array(A, B, C, $\ldots$)!. \item There must be at least one argument. \begin{nonnormative} - The reason \lstinline!array()! or \lstinline!{}! is not defined is that at least one argument is - needed to determine the type of the resulting array. + The reason \lstinline!array()! or \lstinline!{}! is not defined is that at least one argument is needed to determine the type of the resulting array. \end{nonnormative} \end{itemize} diff --git a/preamble.tex b/preamble.tex index e45491611..09e071981 100644 --- a/preamble.tex +++ b/preamble.tex @@ -213,7 +213,8 @@ \lstset{ % backgroundcolor=\color{white}, % choose the background color - breaklines=true, % automatic line breaking only at whitespace + breaklines=true, % automatic line breaking only at whitespace + keepspaces, % don't remove space such as those after closing parenthesis captionpos=b, % sets the caption-position to bottom commentstyle=\color[rgb]{0,0.4,0}\sffamily, % comment style keywordstyle=\color{blue}\ttfamily\bfseries, % keyword style From a1c6a50eac81ed96db23d562f5428b68603a91fe Mon Sep 17 00:00:00 2001 From: Henrik Tidefelt Date: Wed, 17 Jun 2020 00:09:20 +0200 Subject: [PATCH 61/78] Add missing math styling on array concatenation helper variables --- chapters/arrays.tex | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/chapters/arrays.tex b/chapters/arrays.tex index 364298460..93fcda1da 100644 --- a/chapters/arrays.tex +++ b/chapters/arrays.tex @@ -662,8 +662,8 @@ \subsection{Array Concatenation}\doublelabel{array-concatenation} $k$ has to characterize an existing dimension, i.e., $1 \leq k \leq \text{\lstinline!ndims(A)!} = \text{\lstinline!ndims(B)!} = \text{\lstinline!ndims(C)!}$; $k$ shall be a parameter expression of \lstinline!Integer! type. \item Size matching: Arrays \lstinline!A!, \lstinline!B!, \lstinline!C!, \ldots must have identical array sizes - with the exception of the size of dimension $k$, i.e., \lstinline!size(A,j)! = - \lstinline!size(B,j)!, for $1 \leq j \leq \text{\lstinline!ndims(A)!}$ and $j \neq k$. + with the exception of the size of dimension $k$, i.e., \lstinline[mathescape=true]!size(A, $j$)! = + \lstinline[mathescape=true]!size(B, $j$)!, for $1 \leq j \leq \text{\lstinline!ndims(A)!}$ and $j \neq k$. \end{itemize} \begin{example} From bf340dabfc1f1d7990b53800151da66a63a9c909 Mon Sep 17 00:00:00 2001 From: Henrik Tidefelt Date: Wed, 17 Jun 2020 01:04:10 +0200 Subject: [PATCH 62/78] Clean up so-called "formal" definition of array concatenation --- chapters/arrays.tex | 56 ++++++++++++++++++++++----------------------- 1 file changed, 28 insertions(+), 28 deletions(-) diff --git a/chapters/arrays.tex b/chapters/arrays.tex index 93fcda1da..6767cfe96 100644 --- a/chapters/arrays.tex +++ b/chapters/arrays.tex @@ -673,48 +673,48 @@ \subsection{Array Concatenation}\doublelabel{array-concatenation} \end{lstlisting} \end{example} -Concatenation is formally defined according to: -\begin{lstlisting}[language=modelica, escapechar=!] -!Let! R = cat(k,A,B,C,...)!, and let! n = ndims(A) = ndims(B) = ndims(C) = -....!, then! - size(R,k) = size(A,k) + size(B,k) + size(C,k) + ... - size(R,j) = size(A,j) = size(B,j) = size(C,j) = ...., for 1 <=j <= n and j <> k. - - R[i_1, ..., i_k, ..., i_n] = A[i_1, ..., i_k, ..., i_n], for i_k <= size(A,k), - R[i_1, ..., i_k, ..., i_n] = B[i_1, ..., i_k - size(A,i), ..., i_n], for i_k <= size(A,k) + size(B,k), - .... - where 1 <= i_j <= size(R,j) for 1 <= j <= n. +Formally, the concatenation \lstinline[mathescape=true]!R = cat($k$, A, B, C, $\ldots$)! is defined as follows. Let $n$ = \lstinline!ndims(A)! = \lstinline!ndims(B)! = \lstinline!ndims(C)! = \ldots Then the size of \lstinline!R! is given by +\begin{lstlisting}[language=modelica,escapechar=!,mathescape=true,frame=none,xleftmargin=1em] +size(R,$k$) = size(A,$k$) + size(B,$k$) + size(C,$k$) + $\ldots$ +size(R,$j$) = size(A,$j$) = size(B,$j$) = size(C,$j$) = $\ldots$ !for! $1 \leq j \leq n$ and $j \neq k$ +\end{lstlisting} +and the array elements of \lstinline!R! are given by +\begin{lstlisting}[language=modelica,escapechar=!,mathescape=true,frame=none,xleftmargin=1em] +R[$i_{1}$, $\ldots$, $i_{k}$, $\ldots$, $i_{n}$] = A[$i_{1}$, $\ldots$, $i_{k}$, $\ldots$, $i_{n}$] + !for! $0 < i_{k} \leq$ size(A,$k$) +R[$i_{1}$, $\ldots$, $i_{k}$, $\ldots$, $i_{n}$] = B[$i_{1}$, $\ldots$, $i_{k}$ - size(A,$k$), $\ldots$, $i_{n}$] + !for! size(A,$k$) $< i_{k} \leq$ size(A,$k$) + size(B,$k$) +R[$i_{1}$, $\ldots$, $i_{k}$, $\ldots$, $i_{n}$] = C[$i_{1}$, $\ldots$, $i_{k}$ - size(A,$k$) - size(B,$k$), $\ldots$, $i_{n}$] + !for! size(A,$k$) + size(B,$k$) $< i_{k} \leq$ size(A,$k$) + size(B,$k$) + size(C,$k$) +$\ldots$ \end{lstlisting} +where $1 \leq i_{j} \leq$ \lstinline[mathescape=true]!size(R,$j$)! for $1 \leq j \leq n$. \subsubsection{Array Concatenation along First and Second Dimensions}\doublelabel{array-concatenation-along-first-and-second-dimensions} -For convenience, a special syntax is supported for the concatenation -along the first and second dimensions. - +For convenience, a special syntax is supported for the concatenation along the first and second dimensions: \begin{itemize} \item \emph{Concatenation along first dimension}:\\ -\lstinline![A; B; C; ...] = cat(1, promote(A,n), promote(B,n), promote(C,n), ...)! -where \lstinline!n = max(2, ndims(A), ndims(B), ndims(C), ....)!. If necessary, 1-sized - dimensions are added to the right of A, B, C before the operation is - carried out, in order that the operands have the same number of - dimensions which will be at least two. + \lstinline[mathescape=true]![A; B; C; $\ldots$] = cat(1, promote(A, n), promote(B, n), promote(C, n), $\ldots$)! + where \lstinline[mathescape=true]!n = max(2, ndims(A), ndims(B), ndims(C), $\ldots$)!. If necessary, 1-sized + dimensions are added to the right of \lstinline!A!, \lstinline!B!, \lstinline!C! before the operation is + carried out, in order that the operands have the same number of dimensions which will be at least two. \item \emph{Concatenation along second dimension}:\\ -\lstinline![A, B, C, ...] = cat(2, promote(A,n), promote(B,n), promote(C,n), ...)! -where \lstinline!n = max(2, ndims(A), ndims(B), ndims(C), ....)!. If necessary, 1-sized - dimensions are added to the right of A, B, C before the operation is + \lstinline[mathescape=true]![A, B, C, $\ldots$] = cat(2, promote(A, n), promote(B, n), promote(C, n), $\ldots$)! + where \lstinline[mathescape=true]!n = max(2, ndims(A), ndims(B), ndims(C), $\ldots$)!. If necessary, 1-sized + dimensions are added to the right of \lstinline!A!, \lstinline!B!, \lstinline!C! before the operation is carried out, especially that each operand has at least two dimensions. \item - The two forms can be mixed. \lstinline![...,...]! has higher precedence than - \lstinline![...;...]!, e.g., \lstinline![a, b; c, d]! is parsed as \lstinline![[a,b];[c,d]]!. + The two forms can be mixed. \lstinline[mathescape=true]![$\ldots$, $\ldots$]! has higher precedence than + \lstinline[mathescape=true]![$\ldots$; $\ldots$]!, e.g., \lstinline![a, b; c, d]! is parsed as \lstinline![[a, b]; [c, d]]!. \item -\lstinline![A] = promote(A,max(2,ndims(A)))!, i.e., \lstinline![A] = A!, if A has 2 or - more dimensions, and it is a matrix with the elements of A, if A is a - scalar or a vector. + \lstinline![A] = promote(A, max(2, ndims(A)))!, i.e., \lstinline![A] = A!, if \lstinline!A! has 2 or more dimensions, and it is a matrix + with the elements of \lstinline!A!, if \lstinline!A! is a scalar or a vector. \item - There must be at least one argument (i.e.\ \lstinline![]! is not defined) + There must be at least one argument (i.e.\ \lstinline![]! is not defined). \end{itemize} \begin{example} From 3c4dd00fefa2349e9c412f1d116ee1312f8a225f Mon Sep 17 00:00:00 2001 From: Henrik Tidefelt Date: Wed, 17 Jun 2020 01:06:54 +0200 Subject: [PATCH 63/78] Set belowskip=0pt for code listings I skimmed the document, and as far as I could tell, this always gives a better result. --- preamble.tex | 1 + 1 file changed, 1 insertion(+) diff --git a/preamble.tex b/preamble.tex index 09e071981..60ce46653 100644 --- a/preamble.tex +++ b/preamble.tex @@ -227,6 +227,7 @@ frame=lrtb, % xleftmargin=\fboxsep, % xrightmargin=-\fboxsep, % + belowskip=0pt, % } % Duplicate this definition here to avoid issue - and name it "fortran77" to avoid problem in LatexML From 223d09f557d56ce2194e91af984d615f94a9b082 Mon Sep 17 00:00:00 2001 From: Henrik Tidefelt Date: Wed, 17 Jun 2020 01:18:24 +0200 Subject: [PATCH 64/78] Remove some excess space --- chapters/arrays.tex | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/chapters/arrays.tex b/chapters/arrays.tex index 6767cfe96..c4c49aeca 100644 --- a/chapters/arrays.tex +++ b/chapters/arrays.tex @@ -355,8 +355,8 @@ \subsection{Reduction Functions and Operators}\doublelabel{reduction-functions-a Returns the least element of the scalars \lstinline!x! and \lstinline!y!; as defined by \lstinline!!.\\ \hline \begin{tabular}{@{}p{4cm}@{}} \lstinline[mathescape=true]!max(e(i, $\ldots$, j)!\\ -\lstinline[mathescape=true]! for i in u, $\ldots$,!\\ -\lstinline[mathescape=true]! j in v)! +\lstinline[mathescape=true]! for i in u, $\ldots$,!\\ +\lstinline[mathescape=true]! j in v)! \end{tabular} & \begin{tabular}{@{}p{10cm}@{}} @@ -389,8 +389,8 @@ \subsection{Reduction Functions and Operators}\doublelabel{reduction-functions-a \end{tabular}\\ \hline \begin{tabular}{@{}p{5cm}@{}} \lstinline[mathescape=true]!sum(e(i, $\ldots$, j)!\\ -\lstinline[mathescape=true]! for i in u, $\ldots$,!\\ -\lstinline[mathescape=true]! j in v)! +\lstinline[mathescape=true]! for i in u, $\ldots$,!\\ +\lstinline[mathescape=true]! j in v)! \end{tabular} & \begin{tabular}{@{}p{10cm}@{}} @@ -412,8 +412,8 @@ \subsection{Reduction Functions and Operators}\doublelabel{reduction-functions-a \end{tabular}\\ \hline \begin{tabular}{@{}p{4cm}@{}} \lstinline[mathescape=true]!product(e(i, $\ldots$, j)!\\ -\lstinline[mathescape=true]! for i in u, $\ldots$,!\\ -\lstinline[mathescape=true]! j in v)! +\lstinline[mathescape=true]! for i in u, $\ldots$,!\\ +\lstinline[mathescape=true]! j in v)! \end{tabular} & \begin{tabular}{@{}p{10cm}@{}} From 59e52043293c6c20e412c35360048de6f3c15f1e Mon Sep 17 00:00:00 2001 From: Henrik Tidefelt Date: Wed, 17 Jun 2020 21:21:33 +0200 Subject: [PATCH 65/78] Use math also for the 'x1' and 'x2' of linspace --- chapters/arrays.tex | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/chapters/arrays.tex b/chapters/arrays.tex index c4c49aeca..07204bcf8 100644 --- a/chapters/arrays.tex +++ b/chapters/arrays.tex @@ -317,13 +317,13 @@ \subsection{Specialized Array Constructor Functions}\doublelabel{specialized-arr \lstinline[mathescape=true]!fill(s, $n$)! = \lstinline[mathescape=true]!{s, s, $\ldots$, s}! The function needs two or more arguments; that is \lstinline!fill(s)! is not legal.\\ \hline -\lstinline[mathescape=true]!linspace(x1, x2, $n$)! +\lstinline[mathescape=true]!linspace($x_{1}$, $x_{2}$, $n$)! & -Returns a \lstinline!Real! vector with $n$ equally spaced elements, such that -\lstinline[mathescape=true]!v = linspace(x1, x2, $n$)! results in -\lstinline[mathescape=true]!v[$i$] = x1 + (x2-x1)*($i$-1)/($n$-1)! for $1 \leq i \leq n$. -It is required that $n \geq 2$. The arguments \lstinline!x1! and \lstinline!x2! shall -be numeric scalar expressions.\\ \hline +Returns a \lstinline!Real! vector with $n$ equally spaced elements, such that \lstinline[mathescape=true]!v = linspace($x_{1}$, $x_{2}$, $n$)! results in +\begin{equation*} +\text{\lstinline[mathescape=true]!v[$i$]!} = x_{1} + (x_{2} - x_{1}) \frac{i - 1}{n - 1} \quad \text{for $1 \leq i \leq n$} +\end{equation*} +It is required that $n \geq 2$. The arguments $x_{1}$ and $x_{2}$ shall be numeric scalar expressions.\\ \hline \end{longtable} \subsection{Reduction Functions and Operators}\doublelabel{reduction-functions-and-operators} From 319b7861cbaf8bd9a7cb3bccf31b089e7772535b Mon Sep 17 00:00:00 2001 From: Henrik Tidefelt Date: Wed, 17 Jun 2020 21:25:16 +0200 Subject: [PATCH 66/78] Remove asymmetric paragraph break in table Similar sentences in other rows of the table are not written as separate paragraph, so this just makes the treatment equal across the table rows. --- chapters/arrays.tex | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/chapters/arrays.tex b/chapters/arrays.tex index 07204bcf8..571e84faa 100644 --- a/chapters/arrays.tex +++ b/chapters/arrays.tex @@ -314,8 +314,7 @@ \subsection{Specialized Array Constructor Functions}\doublelabel{specialized-arr Recursive definition: \lstinline[mathescape=true]!fill(s, $n_{1}$, $n_{2}$, $n_{3}$, $\ldots$)! = \lstinline[mathescape=true]!fill(fill(s, $n_{2}$, $n_{3}$, $\ldots$), $n_{1}$)!; -\lstinline[mathescape=true]!fill(s, $n$)! = \lstinline[mathescape=true]!{s, s, $\ldots$, s}! - +\lstinline[mathescape=true]!fill(s, $n$)! = \lstinline[mathescape=true]!{s, s, $\ldots$, s}!. The function needs two or more arguments; that is \lstinline!fill(s)! is not legal.\\ \hline \lstinline[mathescape=true]!linspace($x_{1}$, $x_{2}$, $n$)! & From 70478590aad0a3600e9be8d0404d01f9b9738e73 Mon Sep 17 00:00:00 2001 From: Henrik Tidefelt Date: Wed, 17 Jun 2020 21:25:28 +0200 Subject: [PATCH 67/78] Insert comma after 'that is' --- chapters/arrays.tex | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/chapters/arrays.tex b/chapters/arrays.tex index 571e84faa..1e54b34bd 100644 --- a/chapters/arrays.tex +++ b/chapters/arrays.tex @@ -304,10 +304,10 @@ \subsection{Specialized Array Constructor Functions}\doublelabel{specialized-arr and all other elements zero.\\ \hline \lstinline[mathescape=true]!zeros($n_{1}$, $n_{2}$, $n_{3}$, $\ldots$)! & Returns the $n_{1} \times n_{2} \times n_{3} \times \ldots$ \lstinline!Integer! array with all elements equal to zero ($n_{i} \geq 0$). -The function needs one or more arguments, that is \lstinline!zeros()! is not legal.\\ \hline +The function needs one or more arguments, that is, \lstinline!zeros()! is not legal.\\ \hline \lstinline[mathescape=true]!ones($n_{1}$, $n_{2}$, $n_{3}$, $\ldots$)! & Return the $n_{1} \times n_{2} \times n_{3} \times \ldots$ \lstinline!Integer! array with all elements equal to one ($n_{i} \geq 0$). -The function needs one or more arguments, that is \lstinline!ones()! is not legal.\\ \hline +The function needs one or more arguments, that is, \lstinline!ones()! is not legal.\\ \hline \lstinline[mathescape=true]!fill(s, $n_{1}$, $n_{2}$, $n_{3}$, $\ldots$)! & Returns the $n_{1} \times n_{2} \times n_{3} \times \ldots$ array with all elements equal to scalar or array expression \lstinline!s! ($n_{i} \geq 0$). The returned array has the same type as \lstinline!s!. From 572d1a9332db900f217bc49e4f6c35f9b310040e Mon Sep 17 00:00:00 2001 From: Henrik Tidefelt Date: Wed, 17 Jun 2020 21:36:47 +0200 Subject: [PATCH 68/78] Add escape around 'and' that's considered natural language This makes sense when thinking of this lstlisting as a quick and dirty way of writing an equation with lots of inline code, and then this 'and' would have been inside \text{...}. --- chapters/arrays.tex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/chapters/arrays.tex b/chapters/arrays.tex index 1e54b34bd..c097e696e 100644 --- a/chapters/arrays.tex +++ b/chapters/arrays.tex @@ -675,7 +675,7 @@ \subsection{Array Concatenation}\doublelabel{array-concatenation} Formally, the concatenation \lstinline[mathescape=true]!R = cat($k$, A, B, C, $\ldots$)! is defined as follows. Let $n$ = \lstinline!ndims(A)! = \lstinline!ndims(B)! = \lstinline!ndims(C)! = \ldots Then the size of \lstinline!R! is given by \begin{lstlisting}[language=modelica,escapechar=!,mathescape=true,frame=none,xleftmargin=1em] size(R,$k$) = size(A,$k$) + size(B,$k$) + size(C,$k$) + $\ldots$ -size(R,$j$) = size(A,$j$) = size(B,$j$) = size(C,$j$) = $\ldots$ !for! $1 \leq j \leq n$ and $j \neq k$ +size(R,$j$) = size(A,$j$) = size(B,$j$) = size(C,$j$) = $\ldots$ !for! $1 \leq j \leq n$ !and! $j \neq k$ \end{lstlisting} and the array elements of \lstinline!R! are given by \begin{lstlisting}[language=modelica,escapechar=!,mathescape=true,frame=none,xleftmargin=1em] From d56fd72b69f1ccb1ea83de4ad15c49f5f490f24d Mon Sep 17 00:00:00 2001 From: Henrik Tidefelt Date: Thu, 18 Jun 2020 00:37:41 +0200 Subject: [PATCH 69/78] Lots of more or less font markup related fixes to chapter 'Arrays' I've now taken the time to go through this chapter more carefully than the other chapters, hoping that this will be possible to use as example when later returning to do more careful cleanup of the other chapters. --- chapters/arrays.tex | 689 +++++++++++++++++++------------------------- 1 file changed, 302 insertions(+), 387 deletions(-) diff --git a/chapters/arrays.tex b/chapters/arrays.tex index c097e696e..34a01cc2a 100644 --- a/chapters/arrays.tex +++ b/chapters/arrays.tex @@ -38,48 +38,44 @@ \section{Array Declarations}\doublelabel{array-declarations} of dimensions, ndim=2), and arrays of more than two dimensions. \begin{nonnormative} -There is no distinguishing between a row and column vector. +There is no distinction between a row and column vector. \end{nonnormative} The following table shows the two possible forms of declarations and -defines the terminology. C is a placeholder for any class, including the +defines the terminology. \lstinline!C! is a placeholder for any class, including the built-in type classes \lstinline!Real!, \lstinline!Integer!, \lstinline!Boolean!, \lstinline!String!, and enumeration types. The type of a dimension upper bound expression, e.g.\ $n$, $m$, $p$, \ldots -in the table below, need to be a subtype of \lstinline!Integer! or EB for a class EB +in the table below, need to be a subtype of \lstinline!Integer! or \lstinline!EB! for a class \lstinline!EB! that is an enumeration type or subtype of the \lstinline!Boolean! type. -Colon (:) indicates that the dimension upper bound is unknown and is a subtype of +Colon (\lstinline!:!) indicates that the dimension upper bound is unknown and is a subtype of \lstinline!Integer!. The size of such a variable can be determined from its binding equation, or the size -of any of its array attributes - see also \autoref{flexible-array-sizes-and-resizing-of-arrays-in-functions}. +of any of its array attributes --- see also \autoref{flexible-array-sizes-and-resizing-of-arrays-in-functions}. The size cannot be determined from other equations or algorithm. Upper and lower array dimension index bounds are described in \autoref{array-dimension-lower-and-upper-index-bounds}. -An array indexed by Boolean or enumeration type can only be used in the following ways: +An array indexed by \lstinline!Boolean! or enumeration type can only be used in the following ways: \begin{itemize} \item - Subscripted using expressions of the appropriate type (i.e.\ Boolean or - the enumerated type) + Subscripted using expressions of the appropriate type (i.e.\ \lstinline!Boolean! or the enumerated type). \item - Binding equations of the form \lstinline!x1 = x2! as well as declaration - assignments of the form \lstinline!x1 := x2! are allowed for arrays independent of - whether the index types of dimensions are subtypes of Integer, - Boolean, or enumeration types. + Binding equations of the form \lstinline!x1 = x2! as well as declaration assignments of the form \lstinline!x1 := x2! are allowed for arrays independent of + whether the index types of dimensions are subtypes of \lstinline!Integer!, \lstinline!Boolean!, or enumeration types. \end{itemize} % IMPROVETOP \begin{longtable}{|l|l|l|l|p{4cm}|} \caption{General forms of declaration of arrays.}\\ \hline -\tablehead{Modelica form 1} & \tablehead{Modelica form 2} & \tablehead{\# dimensions} & \tablehead{Designation} & \tablehead{Explanation}\\ \hline +\tablehead{Modelica form 1} & \tablehead{Modelica form 2} & \tablehead{\# dims} & \tablehead{Designation} & \tablehead{Explanation}\\ \hline \endhead -C x; & C x; & 0 & Scalar & Scalar\\ \hline -C{[}$n${]} x; & C x{[}$n${]}; & 1 & Vector & $n$ -- Vector\\ \hline -C{[}EB{]} x; & C x{[}EB{]} & 1 & Vector & Vector index by enumeration or -Boolean type EB\\ \hline -C{[}$n$, $m${]} x; & C x{[}$n$, $m${]}; & 2 & Matrix & $n \times m$ Matrix\\ \hline -C{[}$n_1$, $n_{2}$,\ldots{},$n_k${]} x; & C x{[}$n_1$, $n_2$,\ldots{},$n_k${]}; & $k$ & Array & Array with $k$ dimensions -($k \geq 0$).\\ \hline +\lstinline[mathescape=true]!C x!; & \lstinline[mathescape=true]!C x!; & $0$ & Scalar & Scalar\\ \hline +\lstinline[mathescape=true]!C[$n$] x;! & \lstinline[mathescape=true]!C x[$n$];! & $1$ & Vector & $n$-Vector\\ \hline +\lstinline[mathescape=true]!C[EB] x;! & \lstinline[mathescape=true]!C x[EB]! & $1$ & Vector & Vector index by enumeration or \lstinline!Boolean! type \lstinline!EB!\\ \hline +\lstinline[mathescape=true]!C[$n$, $m$] x;! & \lstinline[mathescape=true]!C x[$n$, $m$];! & $2$ & Matrix & $n \times m$ Matrix\\ \hline +\lstinline[mathescape=true]!C[$n_1$, $n_{2}$, $\ldots$, $n_k$] x;! & +\lstinline[mathescape=true]!C x[$n_{1}$, $n_{2}$, $\ldots$, $n_{k}$];! & $k$ & Array & Array with $k$ dimensions ($k \geq 0$).\\ \hline \end{longtable} \begin{example} @@ -90,26 +86,25 @@ \section{Array Declarations}\doublelabel{array-declarations} languages such as Fortran, C, C++. \begin{lstlisting}[language=modelica] - Real[:] v1, v2 // vectors v1 and v2 have unknown sizes. The actual sizes may be different. +Real[:] v1, v2 // vectors v1 and v2 have unknown sizes. The actual sizes may be different. \end{lstlisting} It is possible to mix the two declaration forms although it might be confusing. \begin{lstlisting}[language=modelica] - Real[3,2] x[4,5]; // x has type Real[4,5,3,2]; +Real[3, 2] x[4, 5]; // x has type Real[4, 5, 3, 2]; \end{lstlisting} The reason for this order is given by examples such as: \begin{lstlisting}[language=modelica] - type R3=Real[3]; - R3 a; - R3 b[1]={a}; - Real[3] c[1]=b; +type R3 = Real[3]; +R3 a; +R3 b[1] = {a}; +Real[3] c[1] = b; \end{lstlisting} -Using a type for \lstinline!a! and \lstinline!b! in this way is normal, and -substituting a type by its definition allow \lstinline!c!. +Using a type for \lstinline!a! and \lstinline!b! in this way is normal, and substituting a type by its definition allows \lstinline!c!. A vector \lstinline!y! indexed by enumeration values \begin{lstlisting}[language=modelica] - type TwoEnums = enumeration(one,two); - Real[TwoEnums] y; +type TwoEnums = enumeration(one,two); +Real[TwoEnums] y; \end{lstlisting} \end{example} @@ -118,82 +113,66 @@ \section{Array Declarations}\doublelabel{array-declarations} \begin{nonnormative} Special cases: \begin{longtable}{|l|l|l|l|p{3cm}|} -\caption{Declaration of arrays as 1-vectors, row-vectors, or -column-vectors of arrays.}\\ +\caption{Declaration of arrays as 1-vectors, row-vectors, or column-vectors of arrays.}\\ \hline -\tablehead{Modelica form 1} & \tablehead{Modelica form 2} & \tablehead{\# dimensions} & -\tablehead{Designation} & \tablehead{Explanation}\\ \hline +\tablehead{Modelica form 1} & \tablehead{Modelica form 2} & \tablehead{\# dims} & \tablehead{Designation} & \tablehead{Explanation}\\ \hline \endhead -C{[}1{]} x; & C x{[}1{]}; & 1 & Vector & 1 -- Vector, representing a scalar\\ \hline -C{[}1,1{]} x; & C x{[}1, 1{]}; & 2 & Matrix & 1 x 1 -- Matrix, representing a scalar\\ \hline -C{[}n,1{]} x; & C x{[}n, 1{]}; & 2 & Matrix & n x 1 -- Matrix, representing a column\\ \hline -C{[}1,n{]} x; & C x{[}1, n{]}; & 2 & Matrix & 1 x n -- Matrix, representing a row\\ \hline +\lstinline[mathescape=true]!C[1] x;! & \lstinline[mathescape=true]!C x[1];! & $1$ & Vector & 1-Vector, representing a scalar\\ \hline +\lstinline[mathescape=true]!C[1, 1] x;! & \lstinline[mathescape=true]!C x[1, 1];! & $2$ & Matrix & $(1 \times 1)$-Matrix, representing a scalar\\ \hline +\lstinline[mathescape=true]!C[$n$, 1] x;! & \lstinline[mathescape=true]!C x[$n$, 1];! & $2$ & Matrix & $(n \times 1)$-Matrix, representing a column\\ \hline +\lstinline[mathescape=true]!C[1, $n$] x;! & \lstinline[mathescape=true]!C x[1, $n$];! & $2$ & Matrix & $(1 \times n)$-Matrix, representing a row\\ \hline \end{longtable} \end{nonnormative} -The type of an array of array is the multidimensional array which is -constructed by taking the first dimensions from the component -declaration and subsequent dimensions from the maximally expanded -component type. A type is maximally expanded, if it is either one of the -built-in types (Real, Integer, Boolean, String, enumeration type) or it -is not a type class. Before operator overloading is applied, a type -class of a variable is maximally expanded. +The type of an array of array is the multidimensional array which is constructed by taking the first dimensions from the component declaration and subsequent dimensions +from the maximally expanded component type. A type is maximally expanded, if it is either one of the built-in types (\lstinline!Real!, \lstinline!Integer!, \lstinline!Boolean!, +\lstinline!String!, enumeration type) or it is not a type class. Before operator overloading is applied, a type class of a variable is maximally expanded. \begin{example} \begin{lstlisting}[language=modelica] - type Voltage = Real(unit = "V"); - type Current = Real(unit = "A"); - connector Pin - Voltage v; // type class of v = Voltage, type of v = Real - flow Current i; // type class of i = Current, type of i = Real - end Pin; - type MultiPin = Pin[5]; - MultiPin[4] p; // type class of p is MultiPin, type of p is Pin[4,5]; - type Point = Real[3]; - Point p1[10]; - Real p2[10,3]; +type Voltage = Real(unit = "V"); +type Current = Real(unit = "A"); +connector Pin + Voltage v; // type class of v = Voltage, type of v = Real + flow Current i; // type class of i = Current, type of i = Real +end Pin; +type MultiPin = Pin[5]; +MultiPin[4] p; // type class of p is MultiPin, type of p is Pin[4, 5]; +type Point = Real[3]; +Point p1[10]; +Real p2[10, 3]; \end{lstlisting} -The components p1 and p2 have identical types. +The components \lstinline!p1! and \lstinline!p2! have identical types. \begin{lstlisting}[language=modelica] - p2[5] = p1[2]+ p2[4]; // equivalent to p2[5,:] = p1[2,:] + p2[4,:] - Real r[3] = p1[2]; // equivalent to r[3] = p1[2,:] +p2[5] = p1[2] + p2[4]; // equivalent to p2[5, :] = p1[2, :] + p2[4, :] +Real r[3] = p1[2]; // equivalent to r[3] = p1[2, :] \end{lstlisting} \end{example} \begin{nonnormative} Automatic assertions at simulation time: -Let \lstinline!A! be a declared array and \lstinline!i! be the declared maximum dimension -size of the \lstinline!di!-dimension, then an assert statement -\lstinline!assert(i>=0, ...)! is generated provided this -assertion cannot be checked at compile time. It is a quality of -implementation issue to generate a good error message if the assertion -fails. +Let \lstinline!A! be a declared array and \lstinline!i! be the declared maximum dimension size of the \lstinline!di!-dimension, then an assert statement +\lstinline[mathescape=true]!assert(i >= 0, $\ldots$)! is generated provided this assertion cannot be checked at compile time. It is a quality of implementation +issue to generate a good error message if the assertion fails. -Let \lstinline!A! be a declared array and \lstinline!i! be an index accessing an index of -the \lstinline!di!-dimension. Then for every such index-access an assert -statement \lstinline!assert(i>=1 and i<=size(A,di), ...! -) is generated, provided this assertion cannot be checked at -compile time. +Let \lstinline!A! be a declared array and \lstinline!i! be an index accessing an index of the \lstinline!di!-dimension. Then for every such index-access an assert +statement \lstinline[mathescape=true]!assert(1 <= i and i <= size(A, di), $\ldots$)! is generated, provided this assertion cannot be checked at compile time. -For efficiency reasons, these implicit assert statement may be optionally suppressed. +For efficiency reasons, these implicit assert statements may be optionally suppressed. \end{nonnormative} \subsection{Array Dimension Lower and Upper Index Bounds}\doublelabel{array-dimension-lower-and-upper-index-bounds} -The lower and upper index bounds for a dimension of an array indexed by -\lstinline!Integer!, \lstinline!Boolean!, or \lstinline!enumeration! values are as follows: +The lower and upper index bounds for a dimension of an array indexed by \lstinline!Integer!, \lstinline!Boolean!, or \lstinline!enumeration! values are as follows: \begin{itemize} \item - An array dimension indexed by integers has a lower bound of 1 and an - upper bound being the size of the dimension. + An array dimension indexed by \lstinline!Integer! values has a lower bound of 1 and an upper bound being the size of the dimension. \item - An array dimension indexed by \lstinline!Boolean! values has the lower bound \lstinline!false! - and the upper bound \lstinline!true!. + An array dimension indexed by \lstinline!Boolean! values has the lower bound \lstinline!false! and the upper bound \lstinline!true!. \item - An array dimension indexed by \lstinline!enumeration! values of the type - \lstinline!E=enumeration!(\lstinline!e1!, \lstinline!e2!, ..., \lstinline!en!) has the lower bound \lstinline!E.e1! and the upper - bound \lstinline!E.en!. + An array dimension indexed by \lstinline!enumeration! values of the type \lstinline[mathescape=true]!E = enumeration(e1, e2, $\ldots$, en)! + has the lower bound \lstinline!E.e1! and the upper bound \lstinline!E.en!. \end{itemize} \section{Flexible Array Sizes}\doublelabel{flexible-array-sizes} @@ -203,37 +182,37 @@ \section{Flexible Array Sizes}\doublelabel{flexible-array-sizes} \section{Built-in Array Functions}\doublelabel{built-in-array-functions} -Modelica provides a number of built-in functions that are applicable to -arrays. +Modelica provides a number of built-in functions that are applicable to arrays. The following \lstinline!promote! function cannot be used in Modelica, but is utilized below to define other array operators and functions: \begin{longtable}[]{|l|p{9cm}|} \caption{Promote function (cannot be used in Modelica).}\\ \hline \endhead -\lstinline!promote(A, n)! & Fills dimensions of size 1 from the right to array \lstinline!A! upto -dimension $n$, where $n \geq$ \lstinline!ndims(A)! is required. Let \lstinline!C = promote(A, n)!, with \lstinline!nA = ndims(A)!, then \lstinline!ndims(C) = n!, \lstinline!size(C, j) = size(A, j)! for $1 \leq \text{\lstinline!j!} \leq \text{\lstinline!nA!}$, $\text{\lstinline!size(C, j)!} = 1$ for $\text{\lstinline!nA!} + 1 \leq \text{\lstinline!j!} \leq \text{\lstinline!n!}$, \lstinline!C[i_1, ..., i_nA, 1, ..., 1]! = \lstinline!A[i_1, ..., i_nA]!\\ \hline +\lstinline[mathescape=true]!promote(A, $n$)! & Fills dimensions of size 1 from the right to array \lstinline!A! upto +dimension $n$, where $n \geq$ \lstinline!ndims(A)! is required. Let \lstinline[mathescape=true]!C = promote(A, $n$)!, with $n_{\mathrm{A}}$ = \lstinline!ndims(A)!, +then \lstinline[mathescape=true]!ndims(C) = $n$!, \lstinline[mathescape=true]!size(C, $j$) = size(A, $j$)! for $1 \leq j \leq n_{\mathrm{A}}$, +\lstinline[mathescape=true]!size(C, $j$)! = $1$ for $n_{\mathrm{A}} + 1 \leq j \leq n$, \lstinline[mathescape=true]!C[$i_{1}$, $\ldots$, $i_{n_{\mathrm{A}}}$, 1, $\ldots$, 1]! = +\lstinline[mathescape=true]!A[$i_{1}$, $\ldots$, $i_{n_{\mathrm{A}}}$]!\\ \hline \end{longtable} \begin{nonnormative} -The function \lstinline!promote! cannot be used in Modelica, because -the number of dimensions of the returned array cannot be determined at -compile time if \lstinline!n! is a variable. Below, \lstinline!promote! is only used for -constant \lstinline!n!. +The function \lstinline!promote! cannot be used in Modelica, because the number of dimensions of the returned array cannot be determined at compile time +if $n$ is a variable. Below, \lstinline!promote! is only used for constant $n$. \end{nonnormative} \begin{nonnormative} Some examples of using the functions defined in the following \autoref{array-dimension-and-size-functions} to \autoref{matrix-and-vector-algebra-functions}: \begin{lstlisting}[language=modelica] - Real x[4,1,6]; - size(x,1) = 4; - size(x); // vector with elements 4, 1, 6 - size(2*x+x ) = size(x); - Real[3] v1 = fill(1.0, 3); - Real[3,1] m = matrix(v1); - Real[3] v2 = vector(m); - Boolean check[3,4] = fill(true, 3, 4); +Real x[4,1,6]; +size(x,1) = 4; +size(x); // vector with elements 4, 1, 6 +size(2*x+x ) = size(x); +Real[3] v1 = fill(1.0, 3); +Real[3,1] m = matrix(v1); +Real[3] v2 = vector(m); +Boolean check[3,4] = fill(true, 3, 4); \end{lstlisting} \end{nonnormative} @@ -249,8 +228,8 @@ \subsection{Array Dimension and Size Functions}\doublelabel{array-dimension-and- \lstinline!ndims(A)! & Returns the number of dimensions $k$ of expression \lstinline!A!, with $k \geq 0$. \\ \hline -\lstinline!size(A, i)! & -Returns the size of dimension \lstinline!i! of array expression \lstinline!A! where $0 \leq \text{\lstinline!i!} \leq \text{\lstinline!ndims(A)!}$.\\ \hline +\lstinline[mathescape=true]!size(A, $i$)! & +Returns the size of dimension $i$ of array expression \lstinline!A! where $0 \leq i \leq \text{\lstinline!ndims(A)!}$.\\ \hline \lstinline!size(A)! & Returns a vector of length \lstinline!ndims(A)! containing the dimension sizes of \lstinline!A!.\\ \hline \end{longtable} @@ -327,18 +306,13 @@ \subsection{Specialized Array Constructor Functions}\doublelabel{specialized-arr \subsection{Reduction Functions and Operators}\doublelabel{reduction-functions-and-operators} -A reduction function ``reduces'' an array (or several scalars) to one -value (normally a scalar - but the sum reduction function may give an -array as result and also be applied to an operator record). Note that -none of these operators (particularly min and max) generate events -themselves (but arguments could generate events). The restriction on the -type of the input in \autoref{reduction-expressions} for reduction expressions also -apply to the array elements/scalar inputs for the reduction operator -with the same name. +A reduction function ``reduces'' an array (or several scalars) to one value (normally a scalar, but the \lstinline!sum! reduction function may give an array as result +and also be applied to an operator record). Note that none of these operators (particularly \lstinline!min! and \lstinline!max!) generate events themselves (but arguments +could generate events). The restriction on the type of the input in \autoref{reduction-expressions} for reduction expressions also applies to the array elements/scalar +inputs for the reduction operator with the same name. -The sum reduction function (both variants) may be applied to an operator -record, provided that the operator record defines '0' and '+'. It is -then assumed to form an additive group. +The \lstinline!sum! reduction function (both variants) may be applied to an operator record, provided that the operator record defines \lstinline!'0'! and \lstinline!'+'!. +It is then assumed to form an additive group. The following reduction functions are available: \begin{longtable}{|p{4.1cm}|p{10.1cm}|} @@ -482,11 +456,11 @@ \subsubsection{Reduction Expressions}\doublelabel{reduction-expressions} \begin{example} % No frame since the math would break it. \begin{lstlisting}[language=modelica, mathescape=true, frame=none] - sum(i for i in 1:10) // Gives $\sum_{i=1}^{10}i=$1+2+...+10=55 - // Read it as: compute the sum of i for i in the range 1 to 10. - sum(i^2 for i in {1,3,7,6}) // Gives $\sum_{i\in \begin{Bmatrix}1&3&7&6\end{Bmatrix}}i^2=$1+9+49+36=95 - {product(j for j in 1:i) for i in 0:4} // Gives {1,1,2,6,24} - max(i^2 for i in {3,7,6}) // Gives 49 +sum(i for i in 1:10) // Gives $\sum_{i=1}^{10}i=$1+2+...+10=55 +// Read it as: compute the sum of i for i in the range 1 to 10. +sum(i^2 for i in {1,3,7,6}) // Gives $\sum_{i\in \begin{Bmatrix}1&3&7&6\end{Bmatrix}}i^2=$1+9+49+36=95 +{product(j for j in 1:i) for i in 0:4} // Gives {1,1,2,6,24} +max(i^2 for i in {3,7,6}) // Gives 49 \end{lstlisting} \end{example} @@ -503,15 +477,15 @@ \subsection{Matrix and Vector Algebra Functions}\doublelabel{matrix-and-vector-a \lstinline!transpose(A)! & Permutes the first two dimensions of array \lstinline!A!. It is an error, if array \lstinline!A! does not have at least 2 dimensions.\\ \hline -\lstinline!outerProduct(v1, v2)! +\lstinline!outerProduct(x, y)! & \begin{tabular}{@{}p{10cm}@{}} -Returns the outer product of vectors \lstinline!v1! and \lstinline!v2!:\\ -\lstinline!= matrix(v1) * transpose(matrix(v2))! +Returns the outer product of vectors \lstinline!x! and \lstinline!y!:\\ +\lstinline!= matrix(x) * transpose(matrix(y))! \end{tabular}\\ \hline \lstinline!symmetric(A)! & Returns a symmetric matrix which is identical to the square matrix \lstinline!A! -on and above the diagonal, i.e., \lstinline!B := symmetric(A)! implies +on and above the diagonal. I.e., \lstinline!B := symmetric(A)! implies \begin{equation*} \text{\lstinline[mathescape=true]!B[$i$, $j$]!} = \begin{cases} @@ -566,15 +540,15 @@ \section{Vector, Matrix and Array Constructors}\doublelabel{vector-matrix-and-ar \begin{example} \begin{lstlisting}[language=modelica, escapechar=!] - {1,2,3} !\emph{is a 3-vector of type Integer}.! - {{11,12,13}, {21,22,23}} !\emph{is a 2x3 matrix of type Integer}! - {{{1.0, 2.0, 3.0}}} !\emph{is a 1x1x3 array of type Real}.! - - Real[3] v = array(1, 2, 3.0); - type Angle = Real(unit="rad"); - parameter Angle alpha = 2.0; // type of alpha is Real. - // array(alpha, 2, 3.0) or {alpha, 2, 3.0} is a 3-vector of type Real. - Angle[3] a = {1.0, alpha, 4}; // type of a is Real[3]. +{1, 2, 3} !\emph{is a 3-vector of type Integer}.! +{{11, 12, 13}, {21, 22, 23}} !\emph{is a 2 x 3 matrix of type Integer}! +{{{1.0, 2.0, 3.0}}} !\emph{is a 1 x 1 x 3 array of type Real}.! + +Real[3] v = array(1, 2, 3.0); +type Angle = Real(unit="rad"); +parameter Angle alpha = 2.0; // type of alpha is Real. +// array(alpha, 2, 3.0) or {alpha, 2, 3.0} is a 3-vector of type Real. +Angle[3] a = {1.0, alpha, 4}; // type of a is Real[3]. \end{lstlisting} \end{example} @@ -637,8 +611,8 @@ \subsubsection{Array Constructor with Several Iterators}\doublelabel{array-const \begin{example} \begin{lstlisting}[language=modelica] - Real hilb[:,:]= { 1/(i+j-1) for i in 1:n, j in 1:n}; - Real hilb2[:,:]={{ 1/(i+j-1) for j in 1:n} for i in 1:n}; +Real hilb[:,:]= { 1/(i+j-1) for i in 1:n, j in 1:n}; +Real hilb2[:,:]={{ 1/(i+j-1) for j in 1:n} for i in 1:n}; \end{lstlisting} \end{example} @@ -667,8 +641,8 @@ \subsection{Array Concatenation}\doublelabel{array-concatenation} \begin{example} \begin{lstlisting}[language=modelica] - Real[2,3] r1 = cat(1, {{1.0, 2.0, 3}}, {{4, 5, 6}}); - Real[2,6] r2 = cat(2, r1, 2*r1); +Real[2,3] r1 = cat(1, {{1.0, 2.0, 3}}, {{4, 5, 6}}); +Real[2,6] r2 = cat(2, r1, 2*r1); \end{lstlisting} \end{example} @@ -718,24 +692,24 @@ \subsubsection{Array Concatenation along First and Second Dimensions}\doublelabe \begin{example} \begin{lstlisting}[language=modelica] - Real s1, s2, v1[n1], v2[n2], M1[m1,n], - M2[m2,n], M3[n,m1], M4[n,m2], K1[m1,n,k], - K2[m2,n,k]; - [v1;v2] is a (n1+n2) x 1 matrix - [M1;M2] is a (m1+m2) x n matrix - [M3,M4] is a n x (m1+m2) matrix - [K1;K2] is a (m1+m2) x n x k array - [s1;s2] is a 2 x 1 matrix - [s1,s1] is a 1 x 2 matrix - [s1] is a 1 x 1 matrix - [v1] is a n1 x 1 matrix - Real[3] v1 = array(1, 2, 3); - Real[3] v2 = {4, 5, 6}; - Real[3,2] m1 = [v1, v2]; - Real[3,2] m2 = [v1, [4;5;6]]; // m1 = m2 - Real[2,3] m3 = [1, 2, 3; 4, 5, 6]; - Real[1,3] m4 = [1, 2, 3]; - Real[3,1] m5 = [1; 2; 3]; +Real s1, s2, v1[n1], v2[n2], M1[m1,n], +M2[m2,n], M3[n,m1], M4[n,m2], K1[m1,n,k], +K2[m2,n,k]; +[v1;v2] is a (n1+n2) x 1 matrix +[M1;M2] is a (m1+m2) x n matrix +[M3,M4] is a n x (m1+m2) matrix +[K1;K2] is a (m1+m2) x n x k array +[s1;s2] is a 2 x 1 matrix +[s1,s1] is a 1 x 2 matrix +[s1] is a 1 x 1 matrix +[v1] is a n1 x 1 matrix +Real[3] v1 = array(1, 2, 3); +Real[3] v2 = {4, 5, 6}; +Real[3,2] m1 = [v1, v2]; +Real[3,2] m2 = [v1, [4;5;6]]; // m1 = m2 +Real[2,3] m3 = [1, 2, 3; 4, 5, 6]; +Real[1,3] m4 = [1, 2, 3]; +Real[3,1] m5 = [1; 2; 3]; \end{lstlisting} \end{example} @@ -743,48 +717,43 @@ \subsection{Vector Construction}\doublelabel{vector-construction} Vectors can be constructed with the general array constructor, e.g., \begin{lstlisting}[language=modelica] - Real[3] v = {1,2,3}. +Real[3] v = {1, 2, 3}; \end{lstlisting} -The range vector operator or colon operator of simple-expression can be -used instead of or in combination with this general constructor to -construct Real, Integer, Boolean or enumeration type vectors. Semantics -of the colon operator: +The range vector operator or colon operator of simple-expression can be used instead of or in combination with this general constructor to construct \lstinline!Real!, \lstinline!Integer!, \lstinline!Boolean! or enumeration type vectors. Semantics of the colon operator: \begin{itemize} \item - \lstinline!j : k! is the \lstinline!Integer! vector \lstinline!{j, j+1, ..., k}!, if \lstinline!j! and \lstinline!k! are of type + \lstinline[mathescape=true]!$j$ : $k$! is the \lstinline!Integer! vector \lstinline[mathescape=true]!{$j$, $j+1$, $\ldots$, $k$}!, if $j$ and $k$ are of type \lstinline!Integer!. \item - \lstinline!j : k! is the \lstinline!Real! vector \lstinline!{j, j+1.0, ..., j+n}!, with \lstinline!n = floor(k - j)!, if - \lstinline!j! and/or \lstinline!k! are of type \lstinline!Real!. + \lstinline[mathescape=true]!$j$ : $k$! is the \lstinline!Real! vector \lstinline[mathescape=true]!{$j$, $j+1.0$, $\ldots$, $j+n$}!, with $n = \text{\lstinline!floor!}(k - j)$, if + $j$ and/or $k$ are of type \lstinline!Real!. \item - \lstinline!j : k! is a \lstinline!Real!, \lstinline!Integer!, \lstinline!Boolean!, or \lstinline!enumeration! type vector with - zero elements, if $\text{\lstinline!j!} > \text{\lstinline!k!}$. + \lstinline[mathescape=true]!$j$ : $k$! is a \lstinline!Real!, \lstinline!Integer!, \lstinline!Boolean!, or \lstinline!enumeration! type vector with zero elements, if $j > k$. \item - \lstinline!j : d : k! is the \lstinline!Integer! vector \lstinline!{j, j+d, ..., j+n*d}!, with \lstinline!n = div(k - j, d)!, if \lstinline!j!, \lstinline!d!, and \lstinline!k! are of type \lstinline!Integer!. + \lstinline[mathescape=true]!$j$ : $d$ : $k$! is the \lstinline!Integer! vector \lstinline[mathescape=true]!{$j$, $j+d$, $\ldots$, $j + n d$}!, with $n = \text{\lstinline!div!}(k - j, d$, if $j$, $d$, and $k$ are of type \lstinline!Integer!. \item - \lstinline!j : d : k! is the \lstinline!Real! vector \lstinline!{j, j+d, ..., j+n*d}!, with \lstinline!n = floor((k-j)/d)!, if \lstinline!j!, \lstinline!d!, or \lstinline!k! are of type \lstinline!Real!. In order to avoid rounding issues for the length it is recommended to use \lstinline!{j+d*i for i in 0:n}! or \lstinline!linspace(j, k, n+1)! --- if the number of elements are - known. + \lstinline[mathescape=true]!$j$ : $d$ : $k$! is the \lstinline!Real! vector \lstinline[mathescape=true]!{$j$, $j+d$, $\ldots$, $j + n d$}!, with $n = \text{\lstinline!floor!}((k-j)/d)$, + if $j$, $d$, or $k$ are of type \lstinline!Real!. In order to avoid rounding issues for the length it is recommended to use \lstinline!{j+d*i for i in 0:n}! or + \lstinline!linspace(j, k, n+1)! --- if the number of elements are known. \item - \lstinline!j : d : k! is a \lstinline!Real! or \lstinline!Integer! vector with zero elements, if $\text{\lstinline!d!} - > 0$ and $\text{\lstinline!j!} > \text{\lstinline!k!}$ or if $\text{\lstinline!d!} < 0$ and $\text{\lstinline!j!} - < \text{\lstinline!k!}$. + \lstinline[mathescape=true]!$j$ : $d$ : $k$! is a \lstinline!Real! or \lstinline!Integer! vector with zero elements, if $d > 0$ and $j > k$ or if $d < 0$ and $j < k$. \item - \lstinline!false : true! is the Boolean vector \lstinline!{false, true}!. + \lstinline!false : true! is the \lstinline!Boolean! vector \lstinline!{false, true}!. \item - \lstinline!j : j! is \lstinline!{j}! if \lstinline!j! is \lstinline!Real!, \lstinline!Integer!, \lstinline!Boolean!, or \lstinline!enumeration! type. + \lstinline[mathescape=true]!$j$ : $j$! is \lstinline[mathescape=true]!{$j$}! if $j$ is \lstinline!Real!, \lstinline!Integer!, \lstinline!Boolean!, or \lstinline!enumeration! type. \item - \lstinline!E.ei : E.ej! is the enumeration type vector \lstinline!{E.ei, ... E.ej}! where + \lstinline!E.ei : E.ej! is the enumeration type vector \lstinline[mathescape=true]!{E.ei, $\ldots$, E.ej}! where $\text{\lstinline!E.ej!} > \text{\lstinline!E.ei!}$, and \lstinline!ei! and \lstinline!ej! belong to some enumeration type - \lstinline!E = enumeration(...ei, ...ej, ...)!. + \lstinline[mathescape=true]!E = enumeration($\ldots$, ei, $\ldots$, ej, $\ldots$)!. \end{itemize} \begin{example} \begin{lstlisting}[language=modelica] - Real v1[5] = 2.7 : 6.8; - Real v2[5] = {2.7, 3.7, 4.7, 5.7, 6.7}; // = same as v1 - Boolean b1[2] = false:true; - Colors = enumeration (red,blue,green); - Colors ec[3] = Colors.red : Colors.green; +Real v1[5] = 2.7 : 6.8; +Real v2[5] = {2.7, 3.7, 4.7, 5.7, 6.7}; // = same as v1 +Boolean b1[2] = false:true; +Colors = enumeration (red,blue,green); +Colors ec[3] = Colors.red : Colors.green; \end{lstlisting} \end{example} @@ -819,43 +788,42 @@ \section{Array Indexing}\doublelabel{array-indexing} \begin{example} % henrikt-ma: This listing needs to be cleaned up from confusing punctuation. \begin{lstlisting}[language=modelica, escapechar=!] - a[:, j] !\emph{is a vector of the j-th column of a,}! - a[j] !\emph{is a vector of the j-th row of a:}! a[j, :] - a[j : k] is {[a[j], a[j+1], ... , a[k]} - a[:,j : k] is [a[:,j], a[:,j+1], ... , a[:,k]], - v[2:2:8] = v[ {2,4,6,8} ] . - v[{j,k}]:={2,3}; // Same as v[j]:=2; v[k]:=3; - v[{1,1}]:={2,3}; // Same as v[1]:=3; +a[:, j] !\emph{is a vector of the j-th column of a,}! +a[j] !\emph{is a vector of the j-th row of a:}! a[j, :] +a[j : k] is {[a[j], a[j+1], ... , a[k]} +a[:,j : k] is [a[:,j], a[:,j+1], ... , a[:,k]], +v[2:2:8] = v[ {2,4,6,8} ] . +v[{j,k}] := {2,3}; // Same as v[j] := 2; v[k] := 3; +v[{1,1}] := {2,3}; // Same as v[1] := 3; \end{lstlisting} If \lstinline!x! is a vector, \lstinline!x[1]! is a scalar, but the slice \lstinline!x[1:5]! is a vector (a vector-valued or colon index expression causes a vector to be returned). \end{example} \begin{example} -Array slicing given the declaration \lstinline!x[n,m], v[k], z[i,j,p]!. +Array slicing given the declarations \lstinline[mathescape=true]!x[$n$, $m$]!, \lstinline[mathescape=true]!v[$k$]!, \lstinline[mathescape=true]!z[$i$, $j$, $p$]!. \begin{longtable}[]{|l|l|l|} \caption{Examples of scalars vs.\ array slices created with the colon index.}\\ \hline -\tablehead{Expression} & \tablehead{\# dimensions} & \tablehead{Type of value}\\ \hline +\tablehead{Expression} & \tablehead{\# dims} & \tablehead{Type of value}\\ \hline \endhead -\lstinline!x[1, 1]! & \lstinline!0! & Scalar\\ \hline -\lstinline!x[:, 1]! & \lstinline!1! & n -- Vector\\ \hline -\lstinline!x[1, :] or x[1]! & \lstinline!1! & m -- Vector\\ \hline -\lstinline!v[1:p]! & \lstinline!1! & p -- Vector\\ \hline -\lstinline!x[1:p, :]! & \lstinline!2! & p x m -- Matrix\\ \hline -\lstinline!x[1:1, :]! & \lstinline!2! & 1 x m - ``row'' matrix\\ \hline -\lstinline!x[{1, 3, 5}, :]! & \lstinline!2! & 3 x m -- Matrix\\ \hline -\lstinline!x[: , v]! & \lstinline!2! & n x k -- Matrix\\ \hline -\lstinline!z[: , 3, :]! & \lstinline!2! & i x p -- Matrix\\ \hline -\lstinline!x[scalar([1]), :]! & \lstinline!1! & m -- Vector\\ \hline -\lstinline!x[vector([1]), :]! & \lstinline!2! & 1 x m - ``row'' matrix\\ \hline +\lstinline[mathescape=true]!x[1, 1]! & $0$ & Scalar\\ \hline +\lstinline[mathescape=true]!x[:, 1]! & $1$ & $n$-Vector\\ \hline +\lstinline[mathescape=true]!x[1, :]! or \lstinline!x[1]! & $1$ & $m$-Vector\\ \hline +\lstinline[mathescape=true]!v[1:$p$]! & $1$ & $p$-Vector\\ \hline +\lstinline[mathescape=true]!x[1:$p$, :]! & $2$ & $(p \times m)$-Matrix\\ \hline +\lstinline[mathescape=true]!x[1:1, :]! & $2$ & $1 \times m$ ``row'' matrix\\ \hline +\lstinline[mathescape=true]!x[{1, 3, 5}, :]! & $2$ & $(3 \times m)$-Matrix\\ \hline +\lstinline[mathescape=true]!x[:, v]! & $2$ & $(n \times k)$-Matrix\\ \hline +\lstinline[mathescape=true]!z[:, 3, :]! & $2$ & $(i \times p)$-Matrix\\ \hline +\lstinline[mathescape=true]!x[scalar([1]), :]! & $1$ & $m$-Vector\\ \hline +\lstinline[mathescape=true]!x[vector([1]), :]! & $2$ & $1 \times m$ ``row'' matrix\\ \hline \end{longtable} \end{example} \subsection{Indexing with Boolean or Enumeration Values}\doublelabel{indexing-with-boolean-or-enumeration-values} -Arrays can be indexed using values of enumeration types or the \lstinline!Boolean! -type, not only by integers. The type of the index should correspond to +Arrays can be indexed using values of enumeration types or the \lstinline!Boolean! type, not only by \lstinline!Integer!. The type of the index should correspond to the type used for declaring the dimension of the array. \begin{example} @@ -873,29 +841,27 @@ \subsection{Indexing with Boolean or Enumeration Values}\doublelabel{indexing-wi \subsection{Indexing with end}\doublelabel{indexing-with-end} -The expression \lstinline!end! may only appear inside array subscripts, and if used -in the i:th subscript of an array expression \lstinline!A! it is equivalent to -\lstinline!size(A,i)! provided indices to A are a subtype of Integer. If used inside -nested array subscripts it refers to the most closely nested array. +The expression \lstinline!end! may only appear inside array subscripts, and if used in the $i$:th subscript of an array expression \lstinline!A! it is equivalent +to \lstinline[mathescape=true]!size(A, $i$)! provided indices to \lstinline!A! are a subtype of \lstinline!Integer!. If used inside nested array subscripts it refers +to the most closely nested array. \begin{example} \begin{lstlisting}[language=modelica, escapechar=!] - A[end -1,end] is A[size(A,1)-1,size(A,2)] - A[v[end ],end] is A[v[size(v,1)],size(A,2)] // !\emph{since the first}! end !\emph{is referring to end of v.}! +A[end - 1, end] !is! A[size(A,1) - 1, size(A,2)] +A[v[end], end] !is! A[v[size(v,1)], size(A,2)] // !\emph{First}! end !\emph{is referring to end of v.}! \end{lstlisting} \end{example} \section{Scalar, Vector, Matrix, and Array Operator Functions}\doublelabel{scalar-vector-matrix-and-array-operator-functions} -The mathematical operations defined on scalars, vectors, and matrices -are the subject of linear algebra. +The mathematical operations defined on scalars, vectors, and matrices are the subject of linear algebra. -The term numeric or numeric class is used below for a subtype of the -Real or Integer type classes. The standard type coercion defined in \autoref{standard-type-coercion} apply. +The term numeric or numeric class is used below for a subtype of the \lstinline!Real! or \lstinline!Integer! type classes. The standard type coercion defined +in \autoref{standard-type-coercion} applies. \subsection{Equality and Assignment}\doublelabel{equality-and-assignment} -Equality \lstinline!a=b! and assignment \lstinline!a:=b! of scalars, vectors, matrices, and +Equality \lstinline!a = b! and assignment \lstinline!a := b! of scalars, vectors, matrices, and arrays is defined element-wise and require both objects to have the same number of dimensions and corresponding dimension sizes. The operands need to be type equivalent. This is legal for the simple types and all @@ -905,16 +871,12 @@ \subsection{Equality and Assignment}\doublelabel{equality-and-assignment} \begin{longtable}[]{|l|l|l|l|} \caption{Equality and assignment of arrays and scalars.}\\ \hline -\tablehead{Type of a} & \tablehead{Type of b} & \tablehead{Result of} a = b & \tablehead{Operation} (j=1:n, k=1:m)\\ \hline +\tablehead{Type of \lstinline!a!} & \tablehead{Type of \lstinline!b!} & \tablehead{Result of} \lstinline!a = b! & \tablehead{Operation} (j=1:n, k=1:m)\\ \hline \endhead Scalar & Scalar & Scalar & a = b\\ \hline -Vector{[}n{]} & Vector{[}n{]} & Vector{[}n{]} & a{[}j{]} = -b{[}j{]}\\ \hline -Matrix{[}n, m{]} & Matrix{[}n, m{]} & Matrix{[}n, m{]} & a{[}j, k{]} = -b{[}j, k{]}\\ \hline -Array{[}n, m, \ldots{}{]} & Array{[}n, m, \ldots{}{]} & Array{[}n, m, -\ldots{}{]} & a{[}j, k, \ldots{}{]} = b{[}j, k, -\ldots{}{]}\\ \hline +Vector{[}n{]} & Vector{[}n{]} & Vector{[}n{]} & a{[}j{]} = b{[}j{]}\\ \hline +Matrix{[}n, m{]} & Matrix{[}n, m{]} & Matrix{[}n, m{]} & a{[}j, k{]} = b{[}j, k{]}\\ \hline +Array{[}n, m, \ldots{}{]} & Array{[}n, m, \ldots{}{]} & Array{[}n, m, \ldots{}{]} & a{[}j, k, \ldots{}{]} = b{[}j, k, \ldots{}{]}\\ \hline \end{longtable} \subsection{Array Element-wise Addition, Subtraction, and String Concatenation}\doublelabel{array-element-wise-addition-subtraction-and-string-concatenation} @@ -929,34 +891,27 @@ \subsection{Array Element-wise Addition, Subtraction, and String Concatenation}\ \begin{longtable}[]{|l|l|l|l|} \caption{Array addition, subtraction, and string concatenation.}\\ \hline -\tablehead{Type of a} & \tablehead{Type of b} & \tablehead{Result of a +/- b} & -\tablehead{Operation c := a +/- b (j=1:n, k=1:m)}\\ \hline +\tablehead{Type of \lstinline!a!} & \tablehead{Type of \lstinline!b!} & \tablehead{Result of \lstinline!a! +/- \lstinline!b!} & +\tablehead{Operation \lstinline!c := a +/- b!} (j=1:n, k=1:m)\\ \hline \endhead -Scalar & Scalar & Scalar & c := a +/- b\\ \hline -Vector{[}n{]} & Vector{[}n{]} & Vector{[}n{]} & c{[}j{]} := a{[}j{]} +/- -b{[}j{]}\\ \hline -Matrix{[}n, m{]} & Matrix{[}n, m{]} & Matrix{[}n, m{]} & c{[}j, k{]} := -a{[}j, k{]} +/- b{[}j, k{]}\\ \hline -Array{[}n, m, \ldots{}{]} & Array{[}n, m, \ldots{}{]} & Array{[}n, m, -\ldots{}{]} & c {[}j, k, \ldots{}{]} := a{[}j, k, \ldots{}{]} +/- b{[}j, -k, \ldots{}{]}\\ \hline +Scalar & Scalar & Scalar & \lstinline!c := a +/- b!\\ \hline +Vector{[}n{]} & Vector{[}n{]} & Vector{[}n{]} & c{[}j{]} := a{[}j{]} +/- b{[}j{]}\\ \hline +Matrix{[}n, m{]} & Matrix{[}n, m{]} & Matrix{[}n, m{]} & c{[}j, k{]} := a{[}j, k{]} +/- b{[}j, k{]}\\ \hline +Array{[}n, m, \ldots{}{]} & Array{[}n, m, \ldots{}{]} & Array{[}n, m, \ldots{}{]} & c {[}j, k, \ldots{}{]} := a{[}j, k, \ldots{}{]} +/- b{[}j, k, \ldots{}{]}\\ \hline \end{longtable} -Element-wise addition \lstinline!a.+b! and subtraction \lstinline!a.-b! of numeric scalars, -vectors, matrices or arrays a and b requires a numeric type class for a -and b and either size(a) = size(b) or scalar a or scalar b. Element-wise -addition \lstinline!a.+b! of string scalars, vectors, matrices, and arrays is -defined as element-wise string concatenation of corresponding elements -from a and b, and require either size(a) = size(b) or scalar a or scalar -b. +Element-wise addition \lstinline!a .+ b! and subtraction \lstinline!a .- b! of numeric scalars, vectors, matrices or arrays \lstinline!a! and \lstinline!b! requires a +numeric type class for \lstinline!a! and \lstinline!b! and either \lstinline!size(a) = size(b)! or scalar \lstinline!a! or scalar \lstinline!b!. Element-wise addition +\lstinline!a .+ b! of string scalars, vectors, matrices, and arrays is defined as element-wise string concatenation of corresponding elements from \lstinline!a! and +\lstinline!b!, and require either \lstinline!size(a) = size(b)! or scalar \lstinline!a! or scalar \lstinline!b!. \begin{longtable}[]{|l|l|l|l|} \caption{Array element-wise addition, subtraction, and string concatenation.}\\ \hline -\tablehead{Type of a} & \tablehead{Type of b} & \tablehead{Result of a} \lstinline!.+/.-! \tablehead{b} -& \tablehead{Operation c := a .+/.- b (j=1:n, k=1:m)}\\ \hline +\tablehead{Type of \lstinline!a!} & \tablehead{Type of \lstinline!b!} & \tablehead{Result of a} \lstinline!.+/.-! \tablehead{b} +& \tablehead{Operation \lstinline!c := a .+/.- b!} (j=1:n, k=1:m)\\ \hline \endhead -Scalar & Scalar & Scalar & c := a +/- b\\ \hline +Scalar & Scalar & Scalar & \lstinline!c := a +/- b!\\ \hline Scalar & Array{[}n, m, \ldots{}{]} & Array{[}n, m, \ldots{}{]} & c{[}j, k, \ldots{}{]} := a +/- b{[}j, k, \ldots{}{]}\\ \hline Array{[}n, m, \ldots{}{]} & Scalar & Array{[}n, m, \ldots{}{]} & c{[}j, @@ -967,14 +922,12 @@ \subsection{Array Element-wise Addition, Subtraction, and String Concatenation}\ \end{longtable} \begin{longtable}[]{|l|l|l|} -\caption{Unary operators. The element-wise (.+, .-) and normal (+, -) operators give the same results.}\\ +\caption{Unary operators. The element-wise (\lstinline!.+!, \lstinline!.-!) and normal (\lstinline!+!, \lstinline!-!) operators give the same results.}\\ \hline -\tablehead{Type of a} & \tablehead{Result of} \lstinline!+/-! \tablehead{a} & \tablehead{Operation c := -+/- a (j=1:n, k=1:m)}\\ \hline +\tablehead{Type of \lstinline!a!} & \tablehead{Result of} \lstinline!+/-! \tablehead{a} & \tablehead{Operation \lstinline!c := +/- a!} (j=1:n, k=1:m)\\ \hline \endhead -Scalar & Scalar & c := +/- a\\ \hline -Array{[}n, m, \ldots{}{]} & Array{[}n, m, \ldots{}{]} & c{[}j, k, -\ldots{}{]} := +/-a{[}j, k, \ldots{}{]}\\ \hline +Scalar & Scalar & \lstinline!c := +/- a!\\ \hline +Array{[}n, m, \ldots{}{]} & Array{[}n, m, \ldots{}{]} & c{[}j, k, \ldots{}{]} := +/-a{[}j, k, \ldots{}{]}\\ \hline \end{longtable} \subsection{Array Element-wise Multiplication}\doublelabel{array-element-wise-multiplication} @@ -982,32 +935,28 @@ \subsection{Array Element-wise Multiplication}\doublelabel{array-element-wise-mu Scalar multiplication \lstinline!s*a! or \lstinline!a*s! with numeric scalar s and numeric scalar, vector, matrix or array \lstinline!a! is defined element-wise: \begin{longtable}[]{|l|l|l|l|} -\caption{Scalar and scalar to array multiplication of numeric elements}\\ +\caption{Scalar and scalar to array multiplication of numeric elements.}\\ \hline -\tablehead{Type of s} & \tablehead{Type of a} & \tablehead{Type of s* a and a*s} & -\tablehead{Operation} c := s*a or c := a*s (j=1:n, k=1:m)\\ \hline +\tablehead{Type of \lstinline!s!} & \tablehead{Type of \lstinline!a!} & \tablehead{Type of \lstinline!s * a! and \lstinline!a * s!} & +\tablehead{Operation \lstinline!c := s * a! or \lstinline!c := a * s!} (j=1:n, k=1:m)\\ \hline \endhead -Scalar & Scalar & Scalar & c := s * a\\ \hline -Scalar & Vector {[}n{]} & Vector {[}n{]} & c{[}j{]} := s* -a{[}j{]}\\ \hline -Scalar & Matrix {[}n, m{]} & Matrix {[}n, m{]} & c{[}j, k{]} := s* -a{[}j, k{]}\\ \hline -Scalar & Array{[}n, m, ...{]} & Array {[}n, m, ...{]} & c{[}j, k, ...{]} -:= s*a{[}j, k, ...{]}\\ \hline +Scalar & Scalar & Scalar & \lstinline!c := s * a!\\ \hline +Scalar & Vector {[}n{]} & Vector {[}n{]} & c{[}j{]} := s * a{[}j{]}\\ \hline +Scalar & Matrix {[}n, m{]} & Matrix {[}n, m{]} & c{[}j, k{]} := s * a{[}j, k{]}\\ \hline +Scalar & Array{[}n, m, ...{]} & Array {[}n, m, ...{]} & c{[}j, k, ...{]} := s * a{[}j, k, ...{]}\\ \hline \label{tab:product} \end{longtable} -Element-wise multiplication \lstinline!a.*b! of numeric scalars, vectors, matrices -or arrays a and b requires a numeric type class for a and b and either -size(a) = size(b) or scalar a or scalar b. +Element-wise multiplication \lstinline!a .* b! of numeric scalars, vectors, matrices or arrays \lstinline!a! and \lstinline!b! requires a numeric type class +for \lstinline!a! and \lstinline!b! and either \lstinline!size(a) = size(b)! or scalar \lstinline!a! or scalar \lstinline!b!. \begin{longtable}[]{|l|l|l|l|} -\caption{Array element-wise multiplication}\\ +\caption{Array element-wise multiplication.}\\ \hline -\tablehead{Type of a} & \tablehead{Type of b} & \tablehead{Type of a .* b} & -\tablehead{Operation} c:=a .* b (j=1:n, k=1:m)\\ \hline +\tablehead{Type of \lstinline!a!} & \tablehead{Type of \lstinline!b!} & \tablehead{Type of \lstinline!a .* b!} & +\tablehead{Operation} \lstinline!c := a .* b! (j=1:n, k=1:m)\\ \hline \endhead -Scalar & Scalar & Scalar & c := a * b\\ \hline +Scalar & Scalar & Scalar & \lstinline!c := a * b!\\ \hline Scalar & Array{[}n, m, \ldots{}{]} & Array{[}n, m, \ldots{}{]} & c{[}j, k, \ldots{}{]} := a* b{[}j, k, \ldots{}{]}\\ \hline Array{[}n, m, \ldots{}{]} & Scalar & Array{[}n, m, \ldots{}{]} & c{[}j, @@ -1019,49 +968,41 @@ \subsection{Array Element-wise Multiplication}\doublelabel{array-element-wise-mu \subsection{Matrix and Vector Multiplication of Numeric Arrays}\doublelabel{matrix-and-vector-multiplication-of-numeric-arrays} -Multiplication \lstinline!a*b! of numeric vectors and matrices is defined only for -the following combinations: +Multiplication \lstinline!a * b! of numeric vectors and matrices is defined only for the following combinations: \begin{longtable}[]{|l|l|l|l|} \caption{Matrix and vector multiplication of arrays with numeric elements.}\\ \hline -\tablehead{Type of a} & \tablehead{Type of b} & \tablehead{Type of a* b} & -\tablehead{Operation c := a*b}\\ \hline +\tablehead{Type of \lstinline!a!} & \tablehead{Type of \lstinline!b!} & \tablehead{Type of \lstinline!a * b!} & +\tablehead{Operation \lstinline!c := a * b!}\\ \hline \endhead -Vector {[}n{]} & Vector {[}n{]} & Scalar & c := -$\textrm{sum}_k$(a{[}k{]}*b{[}k{]}), k=1:n\\ \hline -Vector {[}n{]} & Matrix {[}n, m{]} & Vector {[}m{]} & c{[}j{]} := -$\textrm{sum}_k$(a{[}k{]}*b{[}k, j{]}), j=1:m, k=1:n\\ \hline -Matrix {[}n, m{]} & Vector {[}m{]} & Vector {[}n{]} & c{[}j{]} := -$\textrm{sum}_k$(a{[}j, k{]}*b{[}k{]})\\ \hline -Matrix {[}n, m{]} & Matrix {[}m, p{]} & Matrix {[}n, p{]} & c{[}i, j{]} -= $\textrm{sum}_k$(a{[}i, k{]}*b{[}k, j{]}), i=1:n, k=1:m, -j=1:p\\ \hline +Vector {[}n{]} & Vector {[}n{]} & Scalar & c := $\textrm{sum}_k$(a{[}k{]}*b{[}k{]}), k=1:n\\ \hline +Vector {[}n{]} & Matrix {[}n, m{]} & Vector {[}m{]} & c{[}j{]} := $\textrm{sum}_k$(a{[}k{]}*b{[}k, j{]}), j=1:m, k=1:n\\ \hline +Matrix {[}n, m{]} & Vector {[}m{]} & Vector {[}n{]} & c{[}j{]} := $\textrm{sum}_k$(a{[}j, k{]}*b{[}k{]})\\ \hline +Matrix {[}n, m{]} & Matrix {[}m, p{]} & Matrix {[}n, p{]} & c{[}i, j{]} = $\textrm{sum}_k$(a{[}i, k{]}*b{[}k, j{]}), i=1:n, k=1:m, j=1:p\\ \hline \end{longtable} \begin{example} \begin{lstlisting}[language=modelica] - Real A[3,3], x[3], b[3], v[3]; - A*x = b; - x*A = b; // same as transpose([x])*A*b - [v]*transpose([v]) // outer product - v*A*v // scalar - tranpose([v])*A*v // vector with one element +Real A[3, 3], x[3], b[3], v[3]; +A * x = b; +x * A = b; // same as transpose([x])*A*b +[v] * transpose([v]) // outer product +v * A * v // scalar +tranpose([v]) * A * v // vector with one element \end{lstlisting} \end{example} \subsection{Division of Scalars or Numeric Arrays by Numeric Scalars}\doublelabel{division-of-scalars-or-numeric-arrays-by-numeric-scalars} -Division \lstinline!a/s! of numeric scalars, vectors, matrices, or arrays \lstinline!a! and -numeric scalars \lstinline!s! is defined element-wise. The result is always of real -type. In order to get integer division with truncation use the function -\lstinline!div!. +Division \lstinline!a / s! of numeric scalars, vectors, matrices, or arrays \lstinline!a! and numeric scalars \lstinline!s! is defined element-wise. +The result is always of \lstinline!Real! type. In order to get integer division with truncation, use the function \lstinline!div!. \begin{longtable}[]{|l|l|l|l|} \caption{Division of scalars and arrays by numeric elements.}\\ \hline \endhead -\tablehead{Type of a} & \tablehead{Type of s} & \tablehead{Result of a / s} & -\tablehead{Operation c := a / s (j=1:n, k=1:m)}\\ \hline -Scalar & Scalar & Scalar & c := a / s\\ \hline +\tablehead{Type of \lstinline!a!} & \tablehead{Type of \lstinline!s!} & \tablehead{Result of \lstinline!a / s!} & +\tablehead{Operation \lstinline!c := a / s!} (j=1:n, k=1:m)\\ \hline +Scalar & Scalar & Scalar & \lstinline!c := a / s!\\ \hline Vector{[}n{]} & Scalar & Vector{[}n{]} & c{[}k{]} := a{[}k{]} / s\\ \hline Matrix{[}n, m{]} & Scalar & Matrix{[}n, m{]} & c{[}j, k{]} := a{[}j, @@ -1072,18 +1013,16 @@ \subsection{Division of Scalars or Numeric Arrays by Numeric Scalars}\doublelabe \subsection{Array Element-wise Division}\doublelabel{array-element-wise-division} -Element-wise division \lstinline!a./b! of numeric scalars, vectors, matrices or -arrays a and b requires a numeric type class for a and b and either -size(a) = size(b) or scalar a or scalar b. The result is always of real -type. In order to get integer division with truncation use the function -\lstinline!div!. +Element-wise division \lstinline!a ./ b! of numeric scalars, vectors, matrices or arrays \lstinline!a! and \lstinline!b! requires a numeric type class for \lstinline!a! and \lstinline!b! +and either \lstinline!size(a) = size(b)! or scalar \lstinline!a! or scalar \lstinline!b!. The result is always of \lstinline!Real! type. In order to get integer division with truncation, +use the function \lstinline!div!. \begin{longtable}[]{|l|l|l|l|} -\caption{Element-wise division of arrays}\\ +\caption{Element-wise division of arrays.}\\ \hline \endhead -\tablehead{Type of a} & \tablehead{Type of b} & \tablehead{Type of a ./ b} & -\tablehead{Operation} c:=a ./ b (j=1:n, k=1:m)\\ \hline -Scalar & Scalar & Scalar & c := a / b\\ \hline +\tablehead{Type of \lstinline!a!} & \tablehead{Type of \lstinline!b!} & \tablehead{Type of \lstinline!a ./ b!} & +\tablehead{Operation} \lstinline!c := a ./ b! (j=1:n, k=1:m)\\ \hline +Scalar & Scalar & Scalar & \lstinline!c := a / b!\\ \hline Scalar & Array{[}n, m, \ldots{}{]} & Array{[}n, m, \ldots{}{]} & c{[}j, k, \ldots{}{]} := a / b{[}j, k, \ldots{}{]}\\ \hline Array{[}n, m, \ldots{}{]} & Scalar & Array{[}n, m, \ldots{}{]} & c{[}j, @@ -1094,49 +1033,40 @@ \subsection{Array Element-wise Division}\doublelabel{array-element-wise-division \end{longtable} \begin{example} -Element-wise division by scalar (\lstinline!./!) and division by scalar (\lstinline!/!) -are identical: \lstinline!a./s = a/s!: +Element-wise division by scalar (\lstinline!./!) and division by scalar (\lstinline!/!) are identical: \lstinline!a ./ s = a / s!: \begin{lstlisting}[language=modelica] - 2./[1,2;3,4] // error, since 2.0/[1,2;3,4] - 2 ./[1,2;3,4] // fine, element-wise division +2./[1, 2; 3, 4] // error; same as 2.0 / [1, 2; 3, 4] +2 ./[1, 2; 3, 4] // fine; element-wise division \end{lstlisting} -This is a consequence of the parsing rules, since `\lstinline!2!' is a lexical -unit. Using a space after the literal solves the problem. +This is a consequence of the parsing rules, since `\lstinline!2.!' is a lexical unit. Using a space after the literal solves the problem. \end{example} \subsection{Exponentiation of Scalars of Numeric Elements}\doublelabel{exponentiation-of-scalars-of-numeric-elements} -Exponentiation \lstinline!a^b! is defined as \lstinline!pow(double a, double b)! in the ANSI -C library if both \lstinline!a! and \lstinline!b! are \lstinline!Real! scalars. A \lstinline!Real! scalar value is -returned. If \lstinline!a! or \lstinline!b! are \lstinline!Integer! scalars, they are automatically -promoted to \lstinline!Real!. Consequences of exceptional situations, such as -($\text{\lstinline!a!} = 0.0$ and $\text{\lstinline!b!} \leq 0.0$, $\text{\lstinline!a!} < 0$ and \lstinline!b! is -not an integer) or overflow are undefined. +Exponentiation \lstinline!a ^ b! is defined as \lstinline[language=C]!pow(double a, double b)! in the ANSI~C library if both \lstinline!a! and \lstinline!b! are +\lstinline!Real! scalars. A \lstinline!Real! scalar value is returned. If \lstinline!a! or \lstinline!b! are \lstinline!Integer! scalars, they are +automatically promoted to \lstinline!Real!. Consequences of exceptional situations, such as ($\text{\lstinline!a!} = 0.0$ and $\text{\lstinline!b!} \leq 0.0$, +$\text{\lstinline!a!} < 0$ and \lstinline!b! is not an integer) or overflow are undefined. -Element-wise exponentiation \lstinline!a.^b! of numeric scalars, vectors, -matrices, or arrays a and b requires a numeric type class for a and b -and either size(a) = size(b) or scalar a or scalar b. +Element-wise exponentiation \lstinline!a .^ b! of numeric scalars, vectors, matrices, or arrays \lstinline!a! and \lstinline!b! requires a numeric type class for +\lstinline!a! and \lstinline!b! and either \lstinline!size(a) = size(b)! or scalar \lstinline!a! or scalar \lstinline!b!. \begin{longtable}[]{|l|l|l|l|} -\caption{Element-wise exponentiation of arrays}\\ +\caption{Element-wise exponentiation of arrays.}\\ \hline -\tablehead{Type of a} & \tablehead{Type of b} & \tablehead{Type of a .\^{} b} & -\tablehead{Operation} c:=a .\^{} b (j=1:n, k=1:m)\\ \hline +\tablehead{Type of \lstinline!a!} & \tablehead{Type of \lstinline!b!} & \tablehead{Type of \lstinline!a .^ b!} & +\tablehead{Operation} \lstinline!c := a .^ b! (j=1:n, k=1:m)\\ \hline \endhead -Scalar & Scalar & Scalar & c := a \^{} b\\ \hline -Scalar & Array{[}n, m, \ldots{}{]} & Array{[}n, m, \ldots{}{]} & c{[}j, -k, \ldots{}{]} := a \^{} b{[}j, k, \ldots{}{]}\\ \hline -Array{[}n, m, \ldots{}{]} & Scalar & Array{[}n, m, \ldots{}{]} & c{[}j, -k, \ldots{}{]} := a{[}j, k, \ldots{}{]} \^{} b\\ \hline -Array{[}n, m, \ldots{}{]} & Array{[}n, m, ...{]} & Array {[}n, m, ...{]} -& c{[}j, k, \ldots{}{]} := a{[}j, k, \ldots{}{]} \^{} b{[}j, k, -\ldots{}{]}\\ \hline +Scalar & Scalar & Scalar & \lstinline!c := a ^ b!\\ \hline +Scalar & Array{[}n, m, \ldots{}{]} & Array{[}n, m, \ldots{}{]} & c{[}j, k, \ldots{}{]} := a \^{} b{[}j, k, \ldots{}{]}\\ \hline +Array{[}n, m, \ldots{}{]} & Scalar & Array{[}n, m, \ldots{}{]} & c{[}j, k, \ldots{}{]} := a{[}j, k, \ldots{}{]} \^{} b\\ \hline +Array{[}n, m, \ldots{}{]} & Array{[}n, m, ...{]} & Array {[}n, m, ...{]} & c{[}j, k, \ldots{}{]} := a{[}j, k, \ldots{}{]} \^{} b{[}j, k, \ldots{}{]}\\ \hline \end{longtable} \begin{example} \begin{lstlisting}[language=modelica] - 2.^[1,2;3,4] // error, since 2.0^[1,2;3,4] - 2 .^[1,2;3,4] // fine, element wise exponentiation +2.^[1, 2; 3, 4] // error; same as 2.0 ^ [1, 2; 3, 4] +2 .^[1, 2; 3, 4] // fine; element-wise exponentiation \end{lstlisting} This is a consequence of the parsing rules, i.e.\ since \lstinline!2.! could be a lexical unit it seen as a lexical unit; using a space after literals solves the problem. @@ -1144,14 +1074,13 @@ \subsection{Exponentiation of Scalars of Numeric Elements}\doublelabel{exponenti \subsection{Scalar Exponentiation of Square Matrices of Numeric Elements}\doublelabel{scalar-exponentiation-of-square-matrices-of-numeric-elements} -Exponentiation \lstinline!a^s! is defined if \lstinline!a! is a square numeric matrix and \lstinline!s! -is a scalar as a subtype of Integer with \lstinline!s>=0!. The -exponentiation is done by repeated multiplication, e.g.: +Exponentiation \lstinline!a ^ s! is defined if \lstinline!a! is a square numeric matrix and \lstinline!s! is a scalar as a subtype of \lstinline!Integer! +with $\text{\lstinline!s!} \geq 0$. The exponentiation is done by repeated multiplication, e.g.: \begin{lstlisting}[language=modelica] - a^3 = a * a * a; - a^0 = identity(size(a, 1)); - assert(size(a, 1) == size(a, 2), "Matrix must be square"); - a^1 = a; +a^3 = a * a * a; +a^0 = identity(size(a, 1)); +assert(size(a, 1) == size(a, 2), "Matrix must be square"); +a^1 = a; \end{lstlisting} \begin{nonnormative} @@ -1165,23 +1094,19 @@ \subsection{Slice Operation}\doublelabel{slice-operation} The following holds for slice operations: \begin{itemize} \item - If \lstinline!a! is an array containing scalar components and \lstinline!m! is a component of - those components, the expression \lstinline!a.m! is interpreted as a slice operation. It returns the array of components \lstinline!{a{[1].m, ...}!. + If \lstinline!a! is an array containing scalar components and \lstinline!m! is a component of those components, the expression \lstinline!a.m! is interpreted as a + slice operation. It returns the array of components \lstinline[mathescape=true]!{a[1].m, $\ldots$}!. \item - If \lstinline!m! is also an array component, the slice operation is valid only if \lstinline!size(a[1].m)=size(a[2].m)=...! + If \lstinline!m! is also an array component, the slice operation is valid only if \lstinline!size(a[1].m)! = \lstinline!size(a[2].m)! = \ldots \item - The slicing operation can be combined with indexing, e.g.\ \lstinline!a.m[1]!. - It returns the array of components \lstinline!{a[1].m[1], a[2].m[1], ...}!, and does not require that - \lstinline!size(a[1].m)=size(a[2].m)!. The number of subscripts on m must - not be greater than the number of array dimension for m (the number - can be smaller, in which case the missing trailing indices are assumed - to be `\lstinline!:!'), and is only valid if \lstinline!size(a[1].m[...]) = size(a[2].m[...])!.. + The slicing operation can be combined with indexing, e.g.\ \lstinline!a.m[1]!. It returns the array of components \lstinline[mathescape=true]!{a[1].m[1], a[2].m[1], $\ldots$}!, + and does not require that \lstinline!size(a[1].m) = size(a[2].m)!. The number of subscripts on \lstinline!m! must not be greater than the number of array dimension + for \lstinline!m! (the number can be smaller, in which case the missing trailing indices are assumed to be `\lstinline!:!'), and is only valid if + \lstinline[mathescape=true]!size(a[1].m[$\ldots$]) = size(a[2].m[$\ldots$])!. \end{itemize} \begin{example} -The size-restriction on the operand is only applicable -if the indexing on the second operand uses vectors or colon as in the -example: +The size-restriction on the operand is only applicable if the indexing on the second operand uses vectors or colon as in the example: \begin{lstlisting}[language=modelica,mathescape=true] constant Integer m=3; Modelica.Blocks.Continuous.LowpassButterworth tf[m](n=2:(m+1)); @@ -1209,82 +1134,72 @@ \subsection{Relational Operators}\doublelabel{relational-operators} \subsection{Boolean Operators}\doublelabel{boolean-operators} -The operators, \lstinline!and! and \lstinline!or! take expressions of Boolean type, which are -either scalars or arrays of matching dimensions. The operator \lstinline!not! takes -an expression of Boolean type, which is either scalar or an array. The -result is the element-wise logical operation. For short-circuit -evaluation of \lstinline!and! and \lstinline!or! see \autoref{evaluation-order}. +The operators \lstinline!and! and \lstinline!or! take expressions of \lstinline!Boolean! type, which are either scalars or arrays of matching dimensions. The operator \lstinline!not! +takes an expression of \lstinline!Boolean! type, which is either scalar or an array. The result is the element-wise logical operation. For short-circuit evaluation of \lstinline!and! +and \lstinline!or!, see \autoref{evaluation-order}. \subsection{Vectorized Calls of Functions}\doublelabel{vectorized-calls-of-functions} See \autoref{scalar-functions-applied-to-array-arguments}. \subsection{Standard Type Coercion}\doublelabel{standard-type-coercion} -In all contexts that require an expression which is a subtype of Real, -an expression which is a subtype of Integer can also be used; the -Integer expression is automatically converted to Real. +In all contexts that require an expression which is a subtype of \lstinline!Real!, an expression which is a subtype of \lstinline!Integer! can also be used; +the \lstinline!Integer! expression is automatically converted to \lstinline!Real!. -This also applies to arrays of Reals, and for fields of record expressions -There is no similar rule for sub-typing. +This also applies to arrays of \lstinline!Real!, and for fields of record expressions. There is no similar rule for sub-typing. \begin{example} \begin{lstlisting}[language=modelica] - record RealR - Real x,y; - end RealR; - record IntegerR - Integer x,y; - end IntegerR; - parameter Integer a=1; - Real y(start=a); // Ok, a is automatically coerced to Real - RealR r1=IntegerR(a,a); // Ok, record is automatically coerced - RealR r2=RealR(a,a); // Ok, a is automatically coerced to Real +record RealR + Real x,y; +end RealR; +record IntegerR + Integer x,y; +end IntegerR; +parameter Integer a = 1; +Real y(start=a); // Ok, a is automatically coerced to Real +RealR r1 = IntegerR(a, a); // Ok, record is automatically coerced +RealR r2 = RealR(a, a); // Ok, a is automatically coerced to Real \end{lstlisting} \end{example} \section{Empty Arrays}\doublelabel{empty-arrays} -Arrays may have dimension sizes of 0. E.g. - +Arrays may have dimension sizes of 0. For example: \begin{lstlisting}[language=modelica] - Real x[0]; // an empty vector - Real A[0, 3], B[5, 0], C[0, 0]; // empty matrices +Real x[0]; // an empty vector +Real A[0, 3], B[5, 0], C[0, 0]; // empty matrices \end{lstlisting} -Empty matrices can be constructed with the fill function. E.g. +Empty matrices can be constructed with the fill function. For example: \begin{lstlisting}[language=modelica] - Real A[:,:] = fill(0.0, 0, 1); // a Real 0 x 1 matrix - Boolean B[:, :, :] = fill(false, 0, 1, 0); // a Boolean 0 x 1 x 0 matrix +Real A[:,:] = fill(0.0, 0, 1); // a Real 0 x 1 matrix +Boolean B[:, :, :] = fill(false, 0, 1, 0); // a Boolean 0 x 1 x 0 matrix \end{lstlisting} -It is not possible to access an element of an empty matrix, e.g. - \lstinline!v[j,k]! cannot be evaluated if \lstinline!v=[]! because the assertion fails -that the index must be bigger than one. -Size-requirements of operations, such as +, -, have also to be fulfilled -if a dimension is zero. E.g. +It is not possible to access an element of an empty matrix, e.g.\ \lstinline!v[j, k]! cannot be evaluated if \lstinline!v = []! because the assertion fails +that the index must be bigger than one. +Size-requirements of operations, such as \lstinline!+!, \lstinline!-!, must also be fulfilled if a dimension is zero. For example: \begin{lstlisting}[language=modelica] - Real[3,0] A, B; - Real[0,0] C; - A + B // fine, result is an empty matrix - A + C // error, sizes do not agree +Real[3, 0] A, B; +Real[0, 0] C; +A + B // fine, result is an empty matrix +A + C // error, sizes do not agree \end{lstlisting} -Multiplication of two empty matrices results in a zero matrix of -corresponding numeric type if the result matrix has no zero dimension -sizes, i.e., +Multiplication of two empty matrices results in a zero matrix of corresponding numeric type if the result matrix has no zero dimension sizes, i.e., \begin{lstlisting}[language=modelica] - Real[0,m]*Real[m,n] = Real[0,n] (empty matrix) - Real[m,n]*Real[n,0] = Real[m,0] (empty matrix) - Real[m,0]*Real[0,n] = fill(0.0, m, n) (non-empty matrix, with zero elements). +Real[0, m] * Real[m, n] = Real[0, n] (empty matrix) +Real[m, n] * Real[n, 0] = Real[m, 0] (empty matrix) +Real[m, 0] * Real[0, n] = fill(0.0, m, n) (non-empty matrix, with zero elements). \end{lstlisting} \begin{example} \begin{lstlisting}[language=modelica] - Real u[p], x[n], y[q], A[n,n], B[n,p], C[q,n], - D[q,p]; - der(x) = A*x + B*u - y = C*x + D*u +Real u[p], x[n], y[q], A[n, n], B[n, p], C[q, n], D[q, p]; +der(x) = A * x + B * u +y = C * x + D * u \end{lstlisting} -Assume $\text{\lstinline!n!} = 0$, $\text{\lstinline!p!} > 0$, $\text{\lstinline!q!} > 0$: Results in \lstinline!y = D*u!. +Assume $\text{\lstinline!n!} = 0$, $\text{\lstinline!p!} > 0$, $\text{\lstinline!q!} > 0$: Results in \lstinline!y = D * u!. \end{example} From d7a838d3b626695c2d18c6bb4026bc95119a0b94 Mon Sep 17 00:00:00 2001 From: Henrik Tidefelt Date: Thu, 18 Jun 2020 01:29:04 +0200 Subject: [PATCH 70/78] Fix LaTeXML problems with unbalanced parentheses/brackets in math --- chapters/arrays.tex | 2 +- chapters/packages.tex | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/chapters/arrays.tex b/chapters/arrays.tex index 34a01cc2a..c6162fbad 100644 --- a/chapters/arrays.tex +++ b/chapters/arrays.tex @@ -730,7 +730,7 @@ \subsection{Vector Construction}\doublelabel{vector-construction} \item \lstinline[mathescape=true]!$j$ : $k$! is a \lstinline!Real!, \lstinline!Integer!, \lstinline!Boolean!, or \lstinline!enumeration! type vector with zero elements, if $j > k$. \item - \lstinline[mathescape=true]!$j$ : $d$ : $k$! is the \lstinline!Integer! vector \lstinline[mathescape=true]!{$j$, $j+d$, $\ldots$, $j + n d$}!, with $n = \text{\lstinline!div!}(k - j, d$, if $j$, $d$, and $k$ are of type \lstinline!Integer!. + \lstinline[mathescape=true]!$j$ : $d$ : $k$! is the \lstinline!Integer! vector \lstinline[mathescape=true]!{$j$, $j+d$, $\ldots$, $j + n d$}!, with $n = \text{\lstinline!div!}(k - j, d)$, if $j$, $d$, and $k$ are of type \lstinline!Integer!. \item \lstinline[mathescape=true]!$j$ : $d$ : $k$! is the \lstinline!Real! vector \lstinline[mathescape=true]!{$j$, $j+d$, $\ldots$, $j + n d$}!, with $n = \text{\lstinline!floor!}((k-j)/d)$, if $j$, $d$, or $k$ are of type \lstinline!Real!. In order to avoid rounding issues for the length it is recommended to use \lstinline!{j+d*i for i in 0:n}! or diff --git a/chapters/packages.tex b/chapters/packages.tex index feb1ad254..69d2f8d03 100644 --- a/chapters/packages.tex +++ b/chapters/packages.tex @@ -70,15 +70,15 @@ \subsection{Importing Definitions from a Package}\doublelabel{importing-definiti \lstinline!import! $\mathit{packagename}$\lstinline!;! (qualified import) -\lstinline!import! ${[}\mathit{packagename}$\lstinline!.!${]}\mathit{definitionname}$\lstinline!;! (single definition import) +\lstinline!import! ${[}\mathit{packagename}\text{\lstinline!.!}{]}\mathit{definitionname}$\lstinline!;! (single definition import) -\lstinline!import! ${[}\mathit{packagename}$\lstinline!.!${]}$\lstinline!{!$\mathit{def}_{1}$\lstinline!,! $\mathit{def}_{2}$\lstinline!,! $\ldots$\lstinline!,! $\mathit{def}_{n}$\lstinline!};! (multiple definition import) +\lstinline!import! ${[}\mathit{packagename}\text{\lstinline!.!}{]}$\lstinline!{!$\mathit{def}_{1}$\lstinline!,! $\mathit{def}_{2}$\lstinline!,! $\ldots$\lstinline!,! $\mathit{def}_{n}$\lstinline!};! (multiple definition import) \lstinline!import! $\mathit{packagename}$\lstinline!.*;! (unqualified import) \lstinline!import! $\mathit{shortpackagename}$ \lstinline!=! $\mathit{packagename}$\lstinline!;! (renaming import) -\lstinline!import! $\mathit{shortpackagename}$ \lstinline!=! ${[}\mathit{packagename}$\lstinline!.!${]}\mathit{definitionname}$\lstinline!;! (renaming single def.\ import) +\lstinline!import! $\mathit{shortpackagename}$ \lstinline!=! ${[}\mathit{packagename}\text{\lstinline!.!}{]}\mathit{definitionname}$\lstinline!;! (renaming single def.\ import) Here $\mathit{packagename}$ is the fully qualified name of the imported package including possible dot notation and $\mathit{definitionname}$ is the From 531dd8c26888c9ec7ca39d0ec4d11bdfbcf6ada0 Mon Sep 17 00:00:00 2001 From: Henrik Tidefelt Date: Thu, 18 Jun 2020 01:30:09 +0200 Subject: [PATCH 71/78] Minor cleanup or range operator --- chapters/arrays.tex | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/chapters/arrays.tex b/chapters/arrays.tex index c6162fbad..d2648b2bf 100644 --- a/chapters/arrays.tex +++ b/chapters/arrays.tex @@ -733,8 +733,8 @@ \subsection{Vector Construction}\doublelabel{vector-construction} \lstinline[mathescape=true]!$j$ : $d$ : $k$! is the \lstinline!Integer! vector \lstinline[mathescape=true]!{$j$, $j+d$, $\ldots$, $j + n d$}!, with $n = \text{\lstinline!div!}(k - j, d)$, if $j$, $d$, and $k$ are of type \lstinline!Integer!. \item \lstinline[mathescape=true]!$j$ : $d$ : $k$! is the \lstinline!Real! vector \lstinline[mathescape=true]!{$j$, $j+d$, $\ldots$, $j + n d$}!, with $n = \text{\lstinline!floor!}((k-j)/d)$, - if $j$, $d$, or $k$ are of type \lstinline!Real!. In order to avoid rounding issues for the length it is recommended to use \lstinline!{j+d*i for i in 0:n}! or - \lstinline!linspace(j, k, n+1)! --- if the number of elements are known. + if $j$, $d$, or $k$ are of type \lstinline!Real!. In order to avoid rounding issues for the length it is recommended to use \lstinline!{j + d * i for i in 0 : n}! or + \lstinline!linspace(j, k, n + 1)! --- if the number of elements are known. \item \lstinline[mathescape=true]!$j$ : $d$ : $k$! is a \lstinline!Real! or \lstinline!Integer! vector with zero elements, if $d > 0$ and $j > k$ or if $d < 0$ and $j < k$. \item From 2c10df2f5610ec2840e3b7cbe79e7e43800c4330 Mon Sep 17 00:00:00 2001 From: Henrik Tidefelt Date: Thu, 18 Jun 2020 01:57:47 +0200 Subject: [PATCH 72/78] Remove ':' at end of section headings A heading is a heading even without a trailing colon. Maybe the colons were a rest from a time when these weren't normal headings, but some sort of boldface at the start of a paragram... --- chapters/derivationofstream.tex | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/chapters/derivationofstream.tex b/chapters/derivationofstream.tex index 906fc84cb..53925617f 100644 --- a/chapters/derivationofstream.tex +++ b/chapters/derivationofstream.tex @@ -150,11 +150,11 @@ \section{Rationale for the formulation of \lstinline!inStream!}\doublelabel{rati \end{equation*} \section{Special cases covered by \lstinline!inStream! definition}\doublelabel{special-cases-covered-by-the-instream-operator-definition} -\subsection{Stream connector is not connected ($N = 1$):}\doublelabel{stream-connector-is-not-connected-n-1} +\subsection{Stream connector is not connected ($N = 1$)}\doublelabel{stream-connector-is-not-connected-n-1} For this case, the return value of \lstinline!inStream! is arbitrary. Therefore, it is set to the outflow value. -\subsection{Connection of 2 stream connectors, one to one connections ($N = 2$):}\doublelabel{connection-of-2-stream-connectors-one-to-one-connections-n-2} +\subsection{Connection of 2 stream connectors, one to one connections ($N = 2$)}\doublelabel{connection-of-2-stream-connectors-one-to-one-connections-n-2} \begin{align*} \text{\lstinline!inStream!}(h_{outflow,1}) &= \frac{\text{max}(-\dot{m}_2,0)h_{outflow,2}}{\text{max}(-\dot{m}_2,0)}=h_{outflow,2}\\ @@ -167,7 +167,7 @@ \subsection{Connection of 2 stream connectors, one to one connections ($N = 2$): simplifications of the form $a * b / a = b$ must be provided, or that this case is treated directly. -\subsection{Connection of 3 stream connectors where one mass flow rate is identical to zero:}\doublelabel{connection-of-3-stream-connectors-where-one-mass-flow-rate-is-identical-to-zero-n-3-and} +\subsection{Connection of 3 stream connectors where one mass flow rate is identical to zero}\doublelabel{connection-of-3-stream-connectors-where-one-mass-flow-rate-is-identical-to-zero-n-3-and} The case where N=3 and $\dot{m}_3=0$ occurs when a one-port sensor (like a temperature sensor) is connected to two connected components. For the sensor, the min attribute of the mass flow rate should be set to zero (no fluid exiting the From 7cbb535506d48a7aca7078cbb2437a63377c3b11 Mon Sep 17 00:00:00 2001 From: OLSSON Hans Date: Thu, 11 Jun 2020 10:25:23 +0200 Subject: [PATCH 73/78] Try to remove lstinline from section names --- chapters/derivationofstream.tex | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/chapters/derivationofstream.tex b/chapters/derivationofstream.tex index 53925617f..067c1baa6 100644 --- a/chapters/derivationofstream.tex +++ b/chapters/derivationofstream.tex @@ -47,7 +47,7 @@ \section{Reasons for avoiding the actual mixing enthalpy in connector definition \end{center} \end{figure} -\section{Rationale for the formulation of \lstinline!inStream!}\doublelabel{rationale-for-the-formulation-of-the-instream-operator} +\section{Rationale for the formulation of inStream}\doublelabel{rationale-for-the-formulation-of-the-instream-operator} For simplicity, the derivation of \lstinline!inStream! is shown at hand of 3 model components that are connected together. The case for $N$ connections follows correspondingly. @@ -149,7 +149,7 @@ \section{Rationale for the formulation of \lstinline!inStream!}\doublelabel{rati \text{\lstinline!inStream!}(h_{outflow,i})=\frac{\sum_{j=1,...,n;j\neq i}\text{max}(-\dot{m}_j,0)h_{outflow,j}}{\sum_{j=1,...,n;j\neq i}\text{max}(-\dot{m}_j,0)} \end{equation*} -\section{Special cases covered by \lstinline!inStream! definition}\doublelabel{special-cases-covered-by-the-instream-operator-definition} +\section{Special cases covered by inStream definition}\doublelabel{special-cases-covered-by-the-instream-operator-definition} \subsection{Stream connector is not connected ($N = 1$)}\doublelabel{stream-connector-is-not-connected-n-1} For this case, the return value of \lstinline!inStream! is arbitrary. Therefore, it is set to the outflow value. From 984b2a4d9a6befe22247d184b77b1ec2e728273f Mon Sep 17 00:00:00 2001 From: OLSSON Hans Date: Thu, 11 Jun 2020 10:39:25 +0200 Subject: [PATCH 74/78] And no math in section-headings --- chapters/derivationofstream.tex | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/chapters/derivationofstream.tex b/chapters/derivationofstream.tex index 067c1baa6..e6a1744e0 100644 --- a/chapters/derivationofstream.tex +++ b/chapters/derivationofstream.tex @@ -150,11 +150,11 @@ \section{Rationale for the formulation of inStream}\doublelabel{rationale-for-th \end{equation*} \section{Special cases covered by inStream definition}\doublelabel{special-cases-covered-by-the-instream-operator-definition} -\subsection{Stream connector is not connected ($N = 1$)}\doublelabel{stream-connector-is-not-connected-n-1} +\subsection{Stream connector is not connected (N = 1)}\doublelabel{stream-connector-is-not-connected-n-1} For this case, the return value of \lstinline!inStream! is arbitrary. Therefore, it is set to the outflow value. -\subsection{Connection of 2 stream connectors, one to one connections ($N = 2$)}\doublelabel{connection-of-2-stream-connectors-one-to-one-connections-n-2} +\subsection{Connection of 2 stream connectors, one to one connections (N = 2)}\doublelabel{connection-of-2-stream-connectors-one-to-one-connections-n-2} \begin{align*} \text{\lstinline!inStream!}(h_{outflow,1}) &= \frac{\text{max}(-\dot{m}_2,0)h_{outflow,2}}{\text{max}(-\dot{m}_2,0)}=h_{outflow,2}\\ From df1a91779c493d86cf0432e17aad9f099f187491 Mon Sep 17 00:00:00 2001 From: Henrik Tidefelt Date: Thu, 18 Jun 2020 13:47:02 +0200 Subject: [PATCH 75/78] Rewrite paragraph on lookup in import clasuses to improve readability in the presence of lots of punctuation symbols --- chapters/packages.tex | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/chapters/packages.tex b/chapters/packages.tex index 69d2f8d03..6e02ec76d 100644 --- a/chapters/packages.tex +++ b/chapters/packages.tex @@ -92,10 +92,8 @@ \subsubsection{Lookup of Imported Names}\doublelabel{lookup-of-imported-names} import clause. For lookup in general -- including how import clauses are used, see \autoref{static-name-lookup}. -Lookup of the name of an imported package or class, e.g.\ \lstinline!A.B.C! in the -clauses \lstinline!import A.B.C; import D=A.B.C; import A.B.C.*!, deviates from the -normal lexical lookup by starting the lexical lookup of the first part -of the name at the top-level. +Lookup of the name of an imported package or class deviates from the normal lexical lookup. For example, consider \lstinline!A.B.C! in the clauses \lstinline!import A.B.C;!, \lstinline!import D = A.B.C;!, or \lstinline!import A.B.C.*;!. +Here, lookup starts with the lexical lookup of the first part of the name (\lstinline!A!) at the top-level. Qualified import clauses may only refer to packages or elements of packages, i.e., in \lstinline!import A.B.C;! or \lstinline!import D=A.B.C;!, From 4e3fddaba69964e6a74598f663989ed9d5f4a0e5 Mon Sep 17 00:00:00 2001 From: Henrik Tidefelt Date: Thu, 18 Jun 2020 13:50:07 +0200 Subject: [PATCH 76/78] Re-write the list of possible import clause forms as suggested by Hans --- chapters/packages.tex | 29 +++++++++++------------------ 1 file changed, 11 insertions(+), 18 deletions(-) diff --git a/chapters/packages.tex b/chapters/packages.tex index 6e02ec76d..a6b8a3589 100644 --- a/chapters/packages.tex +++ b/chapters/packages.tex @@ -68,23 +68,20 @@ \subsection{Importing Definitions from a Package}\doublelabel{importing-definiti % Instead, we need to break up the \lstinline at each piece of math (taking the opportunity to leave the whitespace % outside both \lstinline and math). -\lstinline!import! $\mathit{packagename}$\lstinline!;! (qualified import) +\lstinline[mathescape=true]!import $\mathit{definitionname}$;! (qualified import of top-level definition) -\lstinline!import! ${[}\mathit{packagename}\text{\lstinline!.!}{]}\mathit{definitionname}$\lstinline!;! (single definition import) +\lstinline[mathescape=true]!import $\mathit{packagename}$.$\mathit{definitionname}$;! (qualified import) -\lstinline!import! ${[}\mathit{packagename}\text{\lstinline!.!}{]}$\lstinline!{!$\mathit{def}_{1}$\lstinline!,! $\mathit{def}_{2}$\lstinline!,! $\ldots$\lstinline!,! $\mathit{def}_{n}$\lstinline!};! (multiple definition import) +\lstinline[mathescape=true]!import $\mathit{packagename}$.{$\mathit{def}_{1}$, $\mathit{def}_{2}$, $\ldots$, $\mathit{def}_{n}$};! (multiple definition import) -\lstinline!import! $\mathit{packagename}$\lstinline!.*;! (unqualified import) +\lstinline[mathescape=true]!import $\mathit{packagename}$.*;! (unqualified import) -\lstinline!import! $\mathit{shortpackagename}$ \lstinline!=! $\mathit{packagename}$\lstinline!;! (renaming import) +\lstinline[mathescape=true]!import $\mathit{shortname}$ = $\mathit{definitionname}$;! (renaming import of top-level definition) -\lstinline!import! $\mathit{shortpackagename}$ \lstinline!=! ${[}\mathit{packagename}\text{\lstinline!.!}{]}\mathit{definitionname}$\lstinline!;! (renaming single def.\ import) +\lstinline[mathescape=true]!import $\mathit{shortname}$ = $\mathit{packagename}$.$\mathit{definitionname}$;! (renaming import) -Here $\mathit{packagename}$ is the fully qualified name of the imported -package including possible dot notation and $\mathit{definitionname}$ is the -name of an element in a package. The multiple definition import is -equivalent to multiple single definition imports with corresponding -packagename and definition names. +Here $\mathit{packagename}$ is the fully qualified name of the imported package including possible dot notation and $\mathit{definitionname}$ is the name of an element in a package. The multiple definition import is equivalent +to multiple single definition imports with corresponding $\mathit{packagename}$ and definition names. \subsubsection{Lookup of Imported Names}\doublelabel{lookup-of-imported-names} @@ -106,13 +103,9 @@ \subsubsection{Lookup of Imported Names}\doublelabel{lookup-of-imported-names} \end{nonnormative} \begin{nonnormative} -For example, if the package \lstinline!ComplexNumbers! would have -been declared as a subpackage inside the package \lstinline!Modelica.Math!, -its fully qualified name would be \lstinline!Modelica.Math.ComplexNumbers!. -Definitionname is the simple name without dot notation of a single -definition that is imported. A shortpackagename is a simple name without -dot notation that can be used to refer to the package after import -instead of the presumably much longer packagename. +For example, if the package \lstinline!ComplexNumbers! would have been declared as a subpackage inside the package \lstinline!Modelica.Math!, its fully qualified name would be +\lstinline!Modelica.Math.ComplexNumbers!. $\mathit{definitionname}$ is the simple name without dot notation of a single definition that is imported. A $\mathit{shortname}$ is +a simple name without dot notation that can be used to refer to the package after import instead of the presumably much longer $\mathit{packagename}$. The forms of \lstinline!import! are exemplified below assuming that we want to access the addition operation of the hypothetical package \lstinline!Modelica.Math.ComplexNumbers!: From 19f9ce04e8c285e3b41155a718fea82147012b8e Mon Sep 17 00:00:00 2001 From: Henrik Tidefelt Date: Thu, 18 Jun 2020 13:52:19 +0200 Subject: [PATCH 77/78] Reflow some lines on import clauses --- chapters/packages.tex | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/chapters/packages.tex b/chapters/packages.tex index a6b8a3589..f6a9eb546 100644 --- a/chapters/packages.tex +++ b/chapters/packages.tex @@ -92,11 +92,8 @@ \subsubsection{Lookup of Imported Names}\doublelabel{lookup-of-imported-names} Lookup of the name of an imported package or class deviates from the normal lexical lookup. For example, consider \lstinline!A.B.C! in the clauses \lstinline!import A.B.C;!, \lstinline!import D = A.B.C;!, or \lstinline!import A.B.C.*;!. Here, lookup starts with the lexical lookup of the first part of the name (\lstinline!A!) at the top-level. -Qualified import clauses may only refer to packages or elements of -packages, i.e., in \lstinline!import A.B.C;! or \lstinline!import D=A.B.C;!, -\lstinline!A.B! must be a -package. Unqualified import clauses may only import from packages, i.e., -in \lstinline!import A.B.*;!, \lstinline!A.B! must be a package. +Qualified import clauses may only refer to packages or elements of packages, i.e., in \lstinline!import A.B.C;! or \lstinline!import D = A.B.C;!, \lstinline!A.B! must be a package. Unqualified import clauses may only import +from packages, i.e., in \lstinline!import A.B.*;!, \lstinline!A.B! must be a package. \begin{nonnormative} In \lstinline!import A;! the class \lstinline!A! can be any class which is an element of the unnamed top-level package. @@ -107,8 +104,7 @@ \subsubsection{Lookup of Imported Names}\doublelabel{lookup-of-imported-names} \lstinline!Modelica.Math.ComplexNumbers!. $\mathit{definitionname}$ is the simple name without dot notation of a single definition that is imported. A $\mathit{shortname}$ is a simple name without dot notation that can be used to refer to the package after import instead of the presumably much longer $\mathit{packagename}$. -The forms of \lstinline!import! are exemplified below assuming that we want to -access the addition operation of the hypothetical package \lstinline!Modelica.Math.ComplexNumbers!: +The forms of \lstinline!import! are exemplified below assuming that we want to access the addition operation of the hypothetical package \lstinline!Modelica.Math.ComplexNumbers!: \begin{lstlisting}[language=modelica] import Modelica.Math.ComplexNumbers; // Accessed by ComplexNumbers.Add import Modelica.Math.ComplexNumbers.Add; // Accessed by Add From 601c5fd76217d22009f26af680940150de0bd66b Mon Sep 17 00:00:00 2001 From: Henrik Tidefelt Date: Thu, 18 Jun 2020 13:52:33 +0200 Subject: [PATCH 78/78] Fix em-dash/comma mismatch --- chapters/packages.tex | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/chapters/packages.tex b/chapters/packages.tex index f6a9eb546..ef0f528ee 100644 --- a/chapters/packages.tex +++ b/chapters/packages.tex @@ -85,9 +85,7 @@ \subsection{Importing Definitions from a Package}\doublelabel{importing-definiti \subsubsection{Lookup of Imported Names}\doublelabel{lookup-of-imported-names} -This section only defines how the imported name is looked up in the -import clause. For lookup in general -- including how import clauses are -used, see \autoref{static-name-lookup}. +This section only defines how the imported name is looked up in the import clause. For lookup in general --- including how import clauses are used --- see \autoref{static-name-lookup}. Lookup of the name of an imported package or class deviates from the normal lexical lookup. For example, consider \lstinline!A.B.C! in the clauses \lstinline!import A.B.C;!, \lstinline!import D = A.B.C;!, or \lstinline!import A.B.C.*;!. Here, lookup starts with the lexical lookup of the first part of the name (\lstinline!A!) at the top-level.