From b345cb72b8310802c20035dd03d5a9fa1fbd7cd5 Mon Sep 17 00:00:00 2001 From: Hans Olsson Date: Wed, 22 Jun 2022 13:14:07 +0200 Subject: [PATCH] Table fine (#3208) * Also need to handle first argument, or separator is lost. Closes #3156 * All including first. * Mistake * FixLatex --- chapters/annotations.tex | 20 +- chapters/arrays.tex | 46 +-- chapters/connectors.tex | 12 +- chapters/functions.tex | 408 +++++++++++++-------------- chapters/inheritance.tex | 18 +- chapters/lexicalstructure.tex | 22 +- chapters/operatorsandexpressions.tex | 114 ++++---- chapters/statemachines.tex | 10 +- chapters/synchronous.tex | 36 +-- chapters/syntax.tex | 8 +- 10 files changed, 347 insertions(+), 347 deletions(-) diff --git a/chapters/annotations.tex b/chapters/annotations.tex index e99488c41..bf9f95b5c 100644 --- a/chapters/annotations.tex +++ b/chapters/annotations.tex @@ -219,8 +219,8 @@ \subsubsection{Escape Sequences}\label{text-markup-escape-sequences} \tablehead{Sequence} & \tablehead{Encoded character} & \tablehead{Comment}\\ \hline \hline -\lstinline!%%! & `\%' & Only way to encode character. \\ -\lstinline!%]! & `]' & Prevents termination of markup delimited by \lstinline![$\ldots$]!. \\ +{\lstinline!%%!} & `\%' & Only way to encode character. \\ +{\lstinline!%]!} & `]' & Prevents termination of markup delimited by {\lstinline![$\ldots$]!}. \\ \hline \end{tabular} \end{center} @@ -243,10 +243,10 @@ \subsubsection{Variable Replacements}\label{variable-replacements} \tablehead{Attribute} & \tablehead{Annotation}\\ \hline \hline -\lstinline!title! & \lstinline!Figure! and \lstinline!Plot! \\ -\lstinline!caption! & \lstinline!Figure! \\ -\lstinline!legend! & \lstinline!Curve! \\ -\lstinline!label! & \lstinline!Axis! \\ +{\lstinline!title!} & {\lstinline!Figure!} and {\lstinline!Plot!} \\ +{\lstinline!caption!} & {\lstinline!Figure!} \\ +{\lstinline!legend!} & {\lstinline!Curve!} \\ +{\lstinline!label!} & {\lstinline!Axis!} \\ \hline \end{tabular} \end{center} @@ -352,7 +352,7 @@ \section{Symbolic Processing}\label{annotations-for-symbolic-processing}\label{s \tablehead{Annotation} & \tablehead{Description} & \tablehead{Details}\\ \hline \hline -\lstinline!Evaluate! & Use parameter value for symbolic processing & \Cref{modelica:Evaluate}\\ +{\lstinline!Evaluate!} & Use parameter value for symbolic processing & \Cref{modelica:Evaluate}\\ \hline \end{tabular} \end{center} @@ -387,9 +387,9 @@ \section{Simulations}\label{annotations-for-simulations}\label{simulations} \tablehead{Annotation} & \tablehead{Description} & \tablehead{Details}\\ \hline \hline -\lstinline!experiment! & Simulation experiment settings & \Cref{modelica:experiment}\\ -\lstinline!HideResult! & Don't show component's simulation result & \Cref{modelica:HideResult}\\ -\lstinline!TestCase! & Information for model used as test case & \Cref{modelica:TestCase}\\ +{\lstinline!experiment!} & Simulation experiment settings & \Cref{modelica:experiment}\\ +{\lstinline!HideResult!} & Don't show component's simulation result & \Cref{modelica:HideResult}\\ +{\lstinline!TestCase!} & Information for model used as test case & \Cref{modelica:TestCase}\\ \hline \end{tabular} \end{center} diff --git a/chapters/arrays.tex b/chapters/arrays.tex index d1aa7a78e..7049ae91b 100644 --- a/chapters/arrays.tex +++ b/chapters/arrays.tex @@ -211,7 +211,7 @@ \section{Built-in Array Functions}\label{built-in-array-functions} \tablehead{Expression} & \tablehead{Description} & \tablehead{Details}\\ \hline \hline -\lstinline!promote($A$, $n$)! & Append dimensions of size 1 & \Cref{modelica:promote} \\ +{\lstinline!promote($A$, $n$)!} & Append dimensions of size 1 & \Cref{modelica:promote} \\ \hline \end{tabular} \end{center} @@ -256,9 +256,9 @@ \subsection{Dimension and Size Functions}\label{array-dimension-and-size-functio \tablehead{Expression} & \tablehead{Description} & \tablehead{Details}\\ \hline \hline -\lstinline!ndims($A$)! & Number of dimensions & \Cref{modelica:ndims} \\ -\lstinline!size($A$, $i$)! & Size of single array dimension & \Cref{modelica:size-of-dim} \\ -\lstinline!size($A$)! & Sizes of all array dimensions & \Cref{modelica:size-vector} \\ +{\lstinline!ndims($A$)!} & Number of dimensions & \Cref{modelica:ndims} \\ +{\lstinline!size($A$, $i$)!} & Size of single array dimension & \Cref{modelica:size-of-dim} \\ +{\lstinline!size($A$)!} & Sizes of all array dimensions & \Cref{modelica:size-vector} \\ \hline \end{tabular} \end{center} @@ -303,9 +303,9 @@ \subsection{Dimensionality Conversion Functions}\label{dimensionality-conversion \tablehead{Expression} & \tablehead{Description} & \tablehead{Details}\\ \hline \hline -\lstinline!scalar($A$)! & Extract only element & \Cref{modelica:scalar} \\ -\lstinline!vector($A$)! & Vector of all elements & \Cref{modelica:vector} \\ -\lstinline!matrix($A$)! & Two-dimensional array & \Cref{modelica:matrix} \\ +{\lstinline!scalar($A$)!} & Extract only element & \Cref{modelica:scalar} \\ +{\lstinline!vector($A$)!} & Vector of all elements & \Cref{modelica:vector} \\ +{\lstinline!matrix($A$)!} & Two-dimensional array & \Cref{modelica:matrix} \\ \hline \end{tabular} \end{center} @@ -353,12 +353,12 @@ \subsection{Specialized Array Constructor Functions}\label{specialized-array-con \tablehead{Expression} & \tablehead{Description} & \tablehead{Details}\\ \hline \hline -\lstinline!identity($n$)! & Identity matrix & \Cref{modelica:identity} \\ -\lstinline!diagonal($v$)! & Diagonal matrix & \Cref{modelica:diagonal} \\ -\lstinline!zeros($n_{1}$, $n_{2}$, $n_{3}$, $\ldots$)! & Array with all elements being 0 & \Cref{modelica:zeros} \\ -\lstinline!ones($n_{1}$, $n_{2}$, $n_{3}$, $\ldots$)! & Array with all elements being 1 & \Cref{modelica:ones} \\ -\lstinline!fill($s$, $n_{1}$, $n_{2}$, $n_{3}$, $\ldots$)! & Array with all elements equal & \Cref{modelica:fill} \\ -\lstinline!linspace($x_{1}$, $x_{2}$, $n$)! & Vector with equally spaced elements & \Cref{modelica:linspace} \\ +{\lstinline!identity($n$)!} & Identity matrix & \Cref{modelica:identity} \\ +{\lstinline!diagonal($v$)!} & Diagonal matrix & \Cref{modelica:diagonal} \\ +{\lstinline!zeros($n_{1}$, $n_{2}$, $n_{3}$, $\ldots$)!} & Array with all elements being 0 & \Cref{modelica:zeros} \\ +{\lstinline!ones($n_{1}$, $n_{2}$, $n_{3}$, $\ldots$)!} & Array with all elements being 1 & \Cref{modelica:ones} \\ +{\lstinline!fill($s$, $n_{1}$, $n_{2}$, $n_{3}$, $\ldots$)!} & Array with all elements equal & \Cref{modelica:fill} \\ +{\lstinline!linspace($x_{1}$, $x_{2}$, $n$)!} & Vector with equally spaced elements & \Cref{modelica:linspace} \\ \hline \end{tabular} \end{center} @@ -440,18 +440,18 @@ \subsection{Reduction Functions and Operators}\label{reduction-functions-and-ope \tablehead{Expression} & \tablehead{Description} & \tablehead{Details}\\ \hline \hline -\lstinline!min($A$)! & Least element or array & \Cref{modelica:min-of-array} \\ -\lstinline!min($x$, $y$)! & Least of two scalars & \Cref{modelica:min-binary} \\ -\lstinline!min($\ldots$ for $\ldots$)! & Reduction to least value & \Cref{modelica:min-reduction} \\ -\lstinline!max($A$)! & Greatest element or array & \Cref{modelica:max-of-array} \\ -\lstinline!max($x$, $y$)! & Greatest of two scalars & \Cref{modelica:max-binary} \\ -\lstinline!max($\ldots$ for $\ldots$)! & Reduction to greatest value & \Cref{modelica:max-reduction} \\ +{\lstinline!min($A$)!} & Least element or array & \Cref{modelica:min-of-array} \\ +{\lstinline!min($x$, $y$)!} & Least of two scalars & \Cref{modelica:min-binary} \\ +{\lstinline!min($\ldots$ for $\ldots$)!} & Reduction to least value & \Cref{modelica:min-reduction} \\ +{\lstinline!max($A$)!} & Greatest element or array & \Cref{modelica:max-of-array} \\ +{\lstinline!max($x$, $y$)!} & Greatest of two scalars & \Cref{modelica:max-binary} \\ +{\lstinline!max($\ldots$ for $\ldots$)!} & Reduction to greatest value & \Cref{modelica:max-reduction} \\ % Not saying "scalar sum" for symmetry with the product case below: -\lstinline!sum($A$)! & Sum of scalar array elements & \Cref{modelica:sum-of-array} \\ -\lstinline!sum($\ldots$ for $\ldots$)! & Sum reduction & \Cref{modelica:sum-reduction} \\ +{\lstinline!sum($A$)!} & Sum of scalar array elements & \Cref{modelica:sum-of-array} \\ +{\lstinline!sum($\ldots$ for $\ldots$)!} & Sum reduction & \Cref{modelica:sum-reduction} \\ % Not saying "scalar product" to avoid confusion with inner products: -\lstinline!product($A$)! & Product of scalar array elements & \Cref{modelica:product-of-array} \\ -\lstinline!product($\ldots$ for $\ldots$)! & Product reduction & \Cref{modelica:product-reduction} \\ +{\lstinline!product($A$)!} & Product of scalar array elements & \Cref{modelica:product-of-array} \\ +{\lstinline!product($\ldots$ for $\ldots$)!} & Product reduction & \Cref{modelica:product-reduction} \\ \hline \end{tabular} \end{center} diff --git a/chapters/connectors.tex b/chapters/connectors.tex index 72589658c..0c43d4b56 100644 --- a/chapters/connectors.tex +++ b/chapters/connectors.tex @@ -790,12 +790,12 @@ \subsection{Connection Graphs and Their Operators}\label{overconstrained-equatio \tablehead{Expression} & \tablehead{Description} & \tablehead{Details}\\ \hline \hline -\lstinline!connect(A, B)! & Optional spanning-tree edge & \Cref{modelica:optional-spanning-tree-edge}\\ -\lstinline!Connections.branch(A.R, B.R)! & Required spanning-tree edge & \Cref{modelica:Connections.branch}\\ -\lstinline!Connections.root(A.R)! & Definite root node & \Cref{modelica:Connections.root}\\ -\lstinline!Connections.potentialRoot(A.R, $\ldots$)! & Potential root node & \Cref{modelica:Connections.potentialRoot}\\ -\lstinline!Connections.isRoot(A.R)! & Predicate for being selected as root & \Cref{modelica:Connections.isRoot}\\ -\lstinline!Connections.rooted(A.R)! & Predicate for being closer to root & \Cref{modelica:Connections.rooted}\\ +{\lstinline!connect(A, B)!} & Optional spanning-tree edge & \Cref{modelica:optional-spanning-tree-edge}\\ +{\lstinline!Connections.branch(A.R, B.R)!} & Required spanning-tree edge & \Cref{modelica:Connections.branch}\\ +{\lstinline!Connections.root(A.R)!} & Definite root node & \Cref{modelica:Connections.root}\\ +{\lstinline!Connections.potentialRoot(A.R, $\ldots$)!} & Potential root node & \Cref{modelica:Connections.potentialRoot}\\ +{\lstinline!Connections.isRoot(A.R)!} & Predicate for being selected as root & \Cref{modelica:Connections.isRoot}\\ +{\lstinline!Connections.rooted(A.R)!} & Predicate for being closer to root & \Cref{modelica:Connections.rooted}\\ \hline \end{tabular} \end{center} diff --git a/chapters/functions.tex b/chapters/functions.tex index 1bb5bc941..b7b4f194d 100644 --- a/chapters/functions.tex +++ b/chapters/functions.tex @@ -1201,9 +1201,9 @@ \section{Derivatives and Inverses of Functions}\label{derivatives-and-inverses-o \tablehead{Annotation} & \tablehead{Description} & \tablehead{Details}\\ \hline \hline -\lstinline!smoothOrder! & Function smoothness guarantee & \Cref{modelica:smoothOrder}\\ -\lstinline!derivative! & Provide function derivative & \Cref{modelica:derivative}\\ -\lstinline!inverse! & Provide closed-form inverses & \Cref{modelica:inverse}\\ +{\lstinline!smoothOrder!} & Function smoothness guarantee & \Cref{modelica:smoothOrder}\\ +{\lstinline!derivative!} & Provide function derivative & \Cref{modelica:derivative}\\ +{\lstinline!inverse!} & Provide closed-form inverses & \Cref{modelica:inverse}\\ \hline \end{tabular} \end{center} @@ -1221,25 +1221,25 @@ \section{Derivatives and Inverses of Functions}\label{derivatives-and-inverses-o \begin{semantics} This annotation has only an effect within a function declaration. -\lstinline!smoothOrder! defines the number of differentiations of the function, in order that all of the differentiated outputs are continuous provided all input arguments and their derivatives up to order \lstinline!smoothOrder! are continuous. +{\lstinline!smoothOrder!} defines the number of differentiations of the function, in order that all of the differentiated outputs are continuous provided all input arguments and their derivatives up to order {\lstinline!smoothOrder!} are continuous. \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 compute an analytic Jacobian, the function can be differentiated analytically at least \lstinline!smoothOrder! times. +{\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 compute an analytic Jacobian, the function can be differentiated analytically at least {\lstinline!smoothOrder!} times. \end{nonnormative} -The optional argument \lstinline!normallyConstant! of \lstinline!smoothOrder! defines that the function argument \lstinline!IDENT! is usually constant. +The optional argument {\lstinline!normallyConstant!} of {\lstinline!smoothOrder!} defines that the function argument {\lstinline!IDENT!} is usually constant. \begin{nonnormative} -A tool might check whether the actual argument to \lstinline!IDENT! is a parameter expression at the place where the function is called. +A tool might check whether the actual argument to {\lstinline!IDENT!} is a parameter expression at the place where the function is called. If this is the case, the derivative of the function might be constructed under the assumption that the corresponding argument is constant, to enhance efficiency. Typically, a tool would generate at most two different derivative functions of a function: -One, under the assumption that all \lstinline!normallyConstant! arguments are actually constant. +One, under the assumption that all {\lstinline!normallyConstant!} arguments are actually constant. And one, under the assumption that all input arguments are time varying. Based on the actual arguments of the function call either of the two derivative functions is used. -This annotation is used by many functions of the \lstinline!Modelica.Fluid! library, such as\linebreak[4] \lstinline!Modelica.Fluid.Dissipation.PressureLoss.StraightPipe.dp_laminar_DP!, since geometric arguments to these functions are usually constant. +This annotation is used by many functions of the {\lstinline!Modelica.Fluid!} library, such as\linebreak[4] {\lstinline!Modelica.Fluid.Dissipation.PressureLoss.StraightPipe.dp_laminar_DP!}, since geometric arguments to these functions are usually constant. \end{nonnormative} \end{semantics} \end{annotationdefinition} @@ -1259,14 +1259,14 @@ \section{Derivatives and Inverses of Functions}\label{derivatives-and-inverses-o \begin{semantics} This annotation has only an effect within a function declaration. -The \lstinline!derivative! annotation can influence simulation time and accuracy, can be applied to both functions written in Modelica and to external functions, and may be used several times for the same function declaration. +The {\lstinline!derivative!} annotation can influence simulation time and accuracy, can be applied to both functions written in Modelica and to external functions, and may be used several times for the same function declaration. -Each use of the \lstinline!derivative! annotation points to another \firstuse{derivative-function} that expresses a derivative of the declared function, and the annotation can state that it is only valid under certain restrictions on the input arguments. -These restrictions are defined using the optional attributes \lstinline!order!, \lstinline!noDerivative!, and \lstinline!zeroDerivative!. -The \lstinline!order! may be specified at most once for each \lstinline!derivative! annotation, must be at least 1, and defaults to 1. -Specifying \lstinline!order! is only considered a restriction if $\text{\lstinline!order!} > 1$. +Each use of the {\lstinline!derivative!} annotation points to another \firstuse{derivative-function} that expresses a derivative of the declared function, and the annotation can state that it is only valid under certain restrictions on the input arguments. +These restrictions are defined using the optional attributes {\lstinline!order!}, {\lstinline!noDerivative!}, and {\lstinline!zeroDerivative!}. +The {\lstinline!order!} may be specified at most once for each {\lstinline!derivative!} annotation, must be at least 1, and defaults to 1. +Specifying {\lstinline!order!} is only considered a restriction if $\text{{\lstinline!order!}} > 1$. -For details abouts using the \lstinline!derivative! annotation, see \cref{using-the-derivative-annotation}. +For details abouts using the {\lstinline!derivative!} annotation, see \cref{using-the-derivative-annotation}. \end{semantics} \end{annotationdefinition} @@ -1278,16 +1278,16 @@ \section{Derivatives and Inverses of Functions}\label{derivatives-and-inverses-o IDENT "=" type-specifier function-call-args" \end{lstlisting}\end{synopsis} \begin{semantics} -A function with one output formal parameter may have one or more \lstinline!inverse! annotations to define inverses of this function. +A function with one output formal parameter may have one or more {\lstinline!inverse!} annotations to define inverses of this function. -For details abouts using the \lstinline!inverse! annotation, see \cref{using-the-inverse-annotation}. +For details abouts using the {\lstinline!inverse!} annotation, see \cref{using-the-inverse-annotation}. \end{semantics} \end{annotationdefinition} \subsection{Using the Derivative Annotation}\label{using-the-derivative-annotation} -The given derivative-function must be a valid derivative if the \lstinline!derivative! annotation restrictions are satisfied, and can thus be used to compute the derivative in those cases. +The given derivative-function must be a valid derivative if the {\lstinline!derivative!} annotation restrictions are satisfied, and can thus be used to compute the derivative in those cases. There may be multiple restrictions on the derivative, in which case they must all be satisfied. The restrictions also imply that some derivatives of some inputs are excluded from the call of the derivative (since they are not necessary). When a function supplies multiple derivative-functions subject to different restrictions, the first one that can be used (i.e., satisfying the restrictions) will be used for each call. @@ -1298,7 +1298,7 @@ \subsection{Using the Derivative Annotation}\label{using-the-derivative-annotati \begin{example} The following model illustrates the requirement that a provided derivative must be valid. -That \lstinline!fder! is a valid derivative of \lstinline!f! means that it can be used safely to compute \lstinline!x2! by numeric integration: the function value, \lstinline!x1!, will up to numerical precision be matched by the integral of the derivative, \lstinline!x2!. +That {\lstinline!fder!} is a valid derivative of {\lstinline!f!} means that it can be used safely to compute {\lstinline!x2!} by numeric integration: the function value, {\lstinline!x1!}, will up to numerical precision be matched by the integral of the derivative, {\lstinline!x2!}. \begin{lstlisting}[language=modelica] function f input Real x; @@ -1321,7 +1321,7 @@ \subsection{Using the Derivative Annotation}\label{using-the-derivative-annotati \end{example} \begin{example} -Use of \lstinline!order! to specify a second order derivative: +Use of {\lstinline!order!} to specify a second order derivative: \begin{lstlisting}[language=modelica] function foo0 annotation(derivative = foo1); end foo0; @@ -1333,7 +1333,7 @@ \subsection{Using the Derivative Annotation}\label{using-the-derivative-annotati \end{lstlisting} \end{example} -The inputs to the derivative function of \lstinline!order! 1 are constructed as +The inputs to the derivative function of {\lstinline!order!} 1 are constructed as follows: \begin{itemize} \item @@ -1348,10 +1348,10 @@ \subsection{Using the Derivative Annotation}\label{using-the-derivative-annotati and its derivative. \end{itemize} -If the Modelica function call is a $n$th derivative ($n \geq 1$), i.e.\ this function call has been derived from an $(n-1)$th derivative by differentiation inside the tool, an \lstinline!annotation(derivative(order=$n+1$) = $\ldots$)!, specifies the $(n+1)$th derivative, and the $(n+1)$th derivative call is constructed as follows: +If the Modelica function call is a $n$th derivative ($n \geq 1$), i.e.\ this function call has been derived from an $(n-1)$th derivative by differentiation inside the tool, an {\lstinline!annotation(derivative(order=$n+1$) = $\ldots$)!}, specifies the $(n+1)$th derivative, and the $(n+1)$th derivative call is constructed as follows: \begin{itemize} \item - The input arguments are appended with the $(n+1)$th derivative, which are constructed in order from the $n$th \lstinline!order! derivatives. + The input arguments are appended with the $(n+1)$th derivative, which are constructed in order from the $n$th {\lstinline!order!} derivatives. \item The output arguments are similar to the output argument for the $n$th derivative, but each output is one higher in derivative order. The outputs must have the same type and declaration order for the function and its derivative. @@ -1359,9 +1359,9 @@ \subsection{Using the Derivative Annotation}\label{using-the-derivative-annotati \begin{nonnormative} The restriction that only the result of differentiation can use -higher-order derivatives ensures that the derivatives \lstinline!x!, \lstinline!der_x!, +higher-order derivatives ensures that the derivatives {\lstinline!x!}, {\lstinline!der_x!}, \ldots{} are in fact derivatives of each other. Without that restriction -we would have both \lstinline!der(x)! and \lstinline!x_der! as inputs (or perform advanced +we would have both {\lstinline!der(x)!} and {\lstinline!x_der!} as inputs (or perform advanced tests to verify that they are the same). \end{nonnormative} @@ -1404,25 +1404,25 @@ \subsection{Using the Derivative Annotation}\label{using-the-derivative-annotati \end{lstlisting} the equation \begin{align*} -(\ldots,\, y(t),\, \ldots) &= \text{\lstinline!foo0!}(\ldots,\, x(t),\, b,\ldots) +(\ldots,\, y(t),\, \ldots) &= \text{{\lstinline!foo0!}}(\ldots,\, x(t),\, b,\ldots) \intertext{implies that:} (\ldots,\, \udfrac{y(t)}{t},\, \ldots) &= -\text{\lstinline!foo1!}(\ldots,\, x(t),\, b,\, \ldots,\, \ldots,\, \udfrac{x(t)}{t},\, \ldots) +\text{{\lstinline!foo1!}}(\ldots,\, x(t),\, b,\, \ldots,\, \ldots,\, \udfrac{x(t)}{t},\, \ldots) \\ (\ldots,\, \udfrac[2]{y(t)}{t},\, \ldots) &= -\text{\lstinline!foo2!}(\ldots,\, x(t),\, b,\, \ldots,\, \udfrac{x(t)}{t},\, \ldots,\, \ldots,\, \udfrac[2]{x(t)}{t},\, \ldots) +\text{{\lstinline!foo2!}}(\ldots,\, x(t),\, b,\, \ldots,\, \udfrac{x(t)}{t},\, \ldots,\, \ldots,\, \udfrac[2]{x(t)}{t},\, \ldots) \end{align*} \end{example} -An input or output to the function may be any simple type (\lstinline!Real!, \lstinline!Boolean!, \lstinline!Integer!, \lstinline!String! and enumeration types) or a record. -For a record containing \lstinline!Real! values, the corresponding derivative uses a derivative record that only contains the real-predefined types and sub-records containing reals (handled recursively) from the original record. -When using \lstinline!smoothOrder!, then the derivative record is automatically constructed. +An input or output to the function may be any simple type ({\lstinline!Real!}, {\lstinline!Boolean!}, {\lstinline!Integer!}, {\lstinline!String!} and enumeration types) or a record. +For a record containing {\lstinline!Real!} values, the corresponding derivative uses a derivative record that only contains the real-predefined types and sub-records containing reals (handled recursively) from the original record. +When using {\lstinline!smoothOrder!}, then the derivative record is automatically constructed. The function must have at least one input containing reals. The output list of the derivative function shall not be empty. \begin{example} -Here is one example use case with records mixing \lstinline!Real! and -non-\lstinline!Real! as inputs and outputs: +Here is one example use case with records mixing {\lstinline!Real!} and +non-{\lstinline!Real!} as inputs and outputs: \begin{lstlisting}[language=modelica] record ThermodynamicState "Thermodynamic state" SpecificEnthalpy h "Specific enthalpy"; @@ -1483,22 +1483,22 @@ \subsection{Using the Derivative Annotation}\label{using-the-derivative-annotati \begin{itemize} \item - \lstinline[language=grammar]!"zeroDerivative" "=" $\mathit{inputVar}_{1}$ { "," "zeroDerivative" "=" $\mathit{inputVar}_{2}$ }! + {\lstinline[language=grammar]!"zeroDerivative" "=" $\mathit{inputVar}_{1}$ { "," "zeroDerivative" "=" $\mathit{inputVar}_{2}$ }!} \end{itemize} The derivative function is only valid if $\mathit{inputVar}_{1}$ (and $\mathit{inputVar}_{2}$ etc.) are independent of the variables the function call is differentiated with respect to (i.e.\ that the derivative of $\mathit{inputVar}_{1}$ is zero). The derivative of $\mathit{inputVar}_{1}$ (and $\mathit{inputVar}_{2}$ 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 \lstinline!zeroDerivative!. +If the derivative-function also specifies a derivative the common variables should have consistent {\lstinline!zeroDerivative!}. \begin{nonnormative} -Assume that function \lstinline!f! takes a matrix and a scalar. +Assume that function {\lstinline!f!} takes a matrix and a scalar. Since the matrix argument is usually a parameter expression it is then useful to define the function as follows (the additional derivative = -\lstinline!fGeneralDer! is optional and can be used when the derivative of -the matrix or offset is non-zero). Note that the derivative annotation of \lstinline!fDer! must specify -\lstinline!zeroDerivative! for both \lstinline!y! and \lstinline!offset! as below, but the derivative annotation of \lstinline!fGeneralDer! shall not have -\lstinline!zeroDerivative! for either of them (it may specify \lstinline!zeroDerivative! for \lstinline!x_der!, -\lstinline!y_der!, or \lstinline!offset_der!). +{\lstinline!fGeneralDer!} is optional and can be used when the derivative of +the matrix or offset is non-zero). Note that the derivative annotation of {\lstinline!fDer!} must specify +{\lstinline!zeroDerivative!} for both {\lstinline!y!} and {\lstinline!offset!} as below, but the derivative annotation of {\lstinline!fGeneralDer!} shall not have +{\lstinline!zeroDerivative!} for either of them (it may specify {\lstinline!zeroDerivative!} for {\lstinline!x_der!}, +{\lstinline!y_der!}, or {\lstinline!offset_der!}). \begin{lstlisting}[language=modelica] function f "Simple table lookup" @@ -1549,32 +1549,32 @@ \subsection{Using the Derivative Annotation}\label{using-the-derivative-annotati //annotation(derivative(order=2) = fGeneralDer2); end fGeneralDer; \end{lstlisting} -In the example above \lstinline!zeroDerivative=y! and \lstinline!zeroDerivative=offset! imply that +In the example above {\lstinline!zeroDerivative=y!} and {\lstinline!zeroDerivative=offset!} imply that \begin{equation*} \begin{aligned} -\udfrac{}{t}\text{\lstinline!f!}(x(t),\, y(t),\, o(t)) -&= \pdfrac{\text{\lstinline!f!}}{x} \udfrac{x}{t} + \pdfrac{\text{\lstinline!f!}}{y} \udfrac{y}{t} + \pdfrac{\text{\lstinline!f!}}{o} \udfrac{o}{t}\\ -&= \pdfrac{\text{\lstinline!f!}}{x} \udfrac{x}{t} + \pdfrac{\text{\lstinline!f!}}{y} \cdot 0 + \pdfrac{\text{\lstinline!f!}}{o} \cdot 0\\ -&= \pdfrac{\text{\lstinline!f!}}{x} \udfrac{x}{t}\\ -&= \text{\lstinline!fDer!} \cdot \udfrac{x}{t} +\udfrac{}{t}\text{{\lstinline!f!}}(x(t),\, y(t),\, o(t)) +&= \pdfrac{\text{{\lstinline!f!}}}{x} \udfrac{x}{t} + \pdfrac{\text{{\lstinline!f!}}}{y} \udfrac{y}{t} + \pdfrac{\text{{\lstinline!f!}}}{o} \udfrac{o}{t}\\ +&= \pdfrac{\text{{\lstinline!f!}}}{x} \udfrac{x}{t} + \pdfrac{\text{{\lstinline!f!}}}{y} \cdot 0 + \pdfrac{\text{{\lstinline!f!}}}{o} \cdot 0\\ +&= \pdfrac{\text{{\lstinline!f!}}}{x} \udfrac{x}{t}\\ +&= \text{{\lstinline!fDer!}} \cdot \udfrac{x}{t} \end{aligned} \end{equation*} \end{nonnormative} \begin{itemize} \item - \lstinline[language=grammar]!"noDerivative" "=" $\mathit{inputVar}_{1}$! + {\lstinline[language=grammar]!"noDerivative" "=" $\mathit{inputVar}_{1}$!} \end{itemize} The derivative of $\mathit{inputVar}_{1}$ is excluded from the argument list of the derivative-function. This relies on assumptions on the arguments to the function; and the function should document these assumptions (it is not always straightforward to verify them). In many cases even the undifferentiated function will only behave correctly under these assumptions. -The inputs excluded using \lstinline!zeroDerivative! or \lstinline!noDerivative! may be of any type (including types not containing reals). +The inputs excluded using {\lstinline!zeroDerivative!} or {\lstinline!noDerivative!} may be of any type (including types not containing reals). \begin{nonnormative} -Assume that function \lstinline!fg! is defined as a composition \lstinline!f(x, g(x))!. -When differentiating \lstinline!f! it is useful to give the derivative under the +Assume that function {\lstinline!fg!} is defined as a composition {\lstinline!f(x, g(x))!}. +When differentiating {\lstinline!f!} it is useful to give the derivative under the assumption that the second argument is defined in this way: \begin{lstlisting}[language=modelica] function fg @@ -1602,17 +1602,17 @@ \subsection{Using the Derivative Annotation}\label{using-the-derivative-annotati $\ldots$ end h; \end{lstlisting} -This is useful if \lstinline!g! represents the major computational -effort of \lstinline!fg!. +This is useful if {\lstinline!g!} represents the major computational +effort of {\lstinline!fg!}. -Therefore \lstinline!h! indirectly includes the derivative with respect to \lstinline!y! as follows: +Therefore {\lstinline!h!} indirectly includes the derivative with respect to {\lstinline!y!} as follows: \begin{equation*} \begin{aligned} -\udfrac{}{t}\text{\lstinline!fg!}(x(t)) -&= \udfrac{}{t}\text{\lstinline!f!}(x(t),\, \text{\lstinline!g!}(x(t)))\\ -&= \pdfrac{\text{\lstinline!f!}}{x} \udfrac{x}{t} + \pdfrac{\text{\lstinline!f!}}{y} \pdfrac{\text{\lstinline!g!}}{x} \udfrac{x}{t}\\ -&= \left(\pdfrac{\text{\lstinline!f!}}{x} + \pdfrac{\text{\lstinline!f!}}{y} \pdfrac{\text{\lstinline!g!}}{x} \right) \udfrac{x}{t}\\ -&= \text{\lstinline!h!}(x(t),\, y(t))) \udfrac{x}{t} +\udfrac{}{t}\text{{\lstinline!fg!}}(x(t)) +&= \udfrac{}{t}\text{{\lstinline!f!}}(x(t),\, \text{{\lstinline!g!}}(x(t)))\\ +&= \pdfrac{\text{{\lstinline!f!}}}{x} \udfrac{x}{t} + \pdfrac{\text{{\lstinline!f!}}}{y} \pdfrac{\text{{\lstinline!g!}}}{x} \udfrac{x}{t}\\ +&= \left(\pdfrac{\text{{\lstinline!f!}}}{x} + \pdfrac{\text{{\lstinline!f!}}}{y} \pdfrac{\text{{\lstinline!g!}}}{x} \right) \udfrac{x}{t}\\ +&= \text{{\lstinline!h!}}(x(t),\, y(t))) \udfrac{x}{t} \end{aligned} \end{equation*} \end{nonnormative} @@ -1626,7 +1626,7 @@ \subsection{Partial Derivatives of Functions}\label{partial-derivatives-of-funct \end{lstlisting} is the partial derivative of a function, and may only be used as declarations of functions. -The semantics is that a function (and only a function) can be specified in this form, defining that it is the partial derivative of the function to the right of the equal sign (looked up in the same way as a short class definition, and the looked up name must be a function), and partially differentiated with respect to each \lstinline!IDENT! in order (starting from the first one). The \lstinline!IDENT! must be \lstinline!Real! inputs to the function. +The semantics is that a function (and only a function) can be specified in this form, defining that it is the partial derivative of the function to the right of the equal sign (looked up in the same way as a short class definition, and the looked up name must be a function), and partially differentiated with respect to each {\lstinline!IDENT!} in order (starting from the first one). The {\lstinline!IDENT!} must be {\lstinline!Real!} inputs to the function. The comment allows a user to comment the function (in the info-layer and as one-line description, and as icon). @@ -1654,7 +1654,7 @@ \subsection{Using the Inverse Annotation}\label{using-the-inverse-annotation} If a function $f_1$ with one output formal parameter $y$ can be restricted to an informally defined domain and codomain, such that the mapping of the input formal parameter $u_{k}$ to $y$ is bijective for any fixed assignment to the other input formal parameters in the domain (see examples below), then it can be given an \fmtannotationindex{inverse} annotation to provide an explicit inverse $f_2$ to this mapping, provided that the function is only applied on this domain: -The \lstinline!inverse! annotation takes the following form in a function declaration: +The {\lstinline!inverse!} annotation takes the following form in a function declaration: \begin{lstlisting}[language=modelica] function $f_1$ input $A_1$ $u_1$; @@ -1674,7 +1674,7 @@ \subsection{Using the Inverse Annotation}\label{using-the-inverse-annotation} In addition to $y$, the formal call to $f_2$ in the annotation shall also pass the other formal parameters (excluding $u_{k}$) needed determine the inverse, see below. The function $f_2$ must be an actual inverse, meaning that if $u_k$ is calculated as $u_k = f_2(\ldots,\, y,\, \ldots)$, then the equality $y = f_1(\ldots,\, u_k,\, \ldots)$ is satisfied up to a certain precision, for all values of the input arguments of $f_2(\ldots,\, y,\, \ldots)$ in the range and informal domain of $f_1$. -More than one inverse can be defined within the same \lstinline!inverse! annotation, separated by commas: +More than one inverse can be defined within the same {\lstinline!inverse!} annotation, separated by commas: \begin{lstlisting}[language=modelica] annotation(inverse($u_k$ = $f_2$($\ldots$, $y$, $\ldots$), $u_i$ = $f_3$($\ldots$, $y$, $\ldots$), $\ldots$)); \end{lstlisting} @@ -1736,17 +1736,17 @@ \subsection{Using the Inverse Annotation}\label{using-the-inverse-annotation} There is no guarantee that a provided inverse will be used, and no rule for at which stage of symbolic processing it could be applied. Inlining a function means that the possibility to apply provided inverses is lost. -Hence, the recommended inlining annotations -- if any -- for use together with the \lstinline!inverse!-annotation is either \lstinline!Inline = false! or \lstinline!LateInline = true!. +Hence, the recommended inlining annotations -- if any -- for use together with the {\lstinline!inverse!}-annotation is either {\lstinline!Inline = false!} or {\lstinline!LateInline = true!}. \begin{example} If an inverse is provided, but the injectiveness part of the bijectiveness requirement is not fulfilled, this may introduce additional ambiguity to the solution of equations with multiple solutions. -Consider the following invalid use of the \lstinline!inverse! annotation: +Consider the following invalid use of the {\lstinline!inverse!} annotation: \begin{lstlisting}[language=modelica] model NotInjective function square input Real x; output Real y = x^2; - annotation(inverse(x = sqrt(y))); // Invalid! + annotation(inverse(x = sqrt(y))); // Invalid!} end square; parameter Real y0 = -1.0; @@ -1757,15 +1757,15 @@ \subsection{Using the Inverse Annotation}\label{using-the-inverse-annotation} square(x) = abs(y); // Expecting continuous solution for x. end NotInjective; \end{lstlisting} -That the parameter \lstinline!y0! may have any sign means the sign of \lstinline!x! cannot be restricted in the informal domain of \lstinline!square!, and hence that the injectiveness requirement cannot be fulfilled. -Without the \lstinline!inverse! annotation, the nonlinear equation in \lstinline!x! and \lstinline!y! has an ambiguity, but it is generally expected that this is handled so that a continuous solution for \lstinline!x! is obtained, meaning that it will keep the same sign as \lstinline!y! throughout the simulation. -The additional ambiguity introduced by the \lstinline!inverse! annotation is that if the provided inverse is used to solve the nonlinear equation instead of using a generic nonlinear equation solver based on local search, then the solution with positive sign is always obtained. -The lack of guarantees that a provided inverse will be used thus implies a worse ambiguity than what was present in the model before introducing the \lstinline!inverse! annotation. +That the parameter {\lstinline!y0!} may have any sign means the sign of {\lstinline!x!} cannot be restricted in the informal domain of {\lstinline!square!}, and hence that the injectiveness requirement cannot be fulfilled. +Without the {\lstinline!inverse!} annotation, the nonlinear equation in {\lstinline!x!} and {\lstinline!y!} has an ambiguity, but it is generally expected that this is handled so that a continuous solution for {\lstinline!x!} is obtained, meaning that it will keep the same sign as {\lstinline!y!} throughout the simulation. +The additional ambiguity introduced by the {\lstinline!inverse!} annotation is that if the provided inverse is used to solve the nonlinear equation instead of using a generic nonlinear equation solver based on local search, then the solution with positive sign is always obtained. +The lack of guarantees that a provided inverse will be used thus implies a worse ambiguity than what was present in the model before introducing the {\lstinline!inverse!} annotation. \end{example} \begin{example} If an inverse is provided, but the surjectiveness part of the bijectiveness requirement is not fulfilled, this may introduce an invalid solution to equations that do not have a solution at all. -Consider the following invalid use of the \lstinline!inverse! annotation: +Consider the following invalid use of the {\lstinline!inverse!} annotation: \begin{lstlisting}[language=modelica] model NotSurjective function cube @@ -1779,7 +1779,7 @@ \subsection{Using the Inverse Annotation}\label{using-the-inverse-annotation} algorithm assert(y > 0, "Argument must be positive."); x := exp(log(y) / 3); - annotation(inverse(y = cube(x))); // Invalid! + annotation(inverse(y = cube(x))); // Invalid!} end cbrtPos; Real x = 0.5 + sin(time); @@ -1789,13 +1789,13 @@ \subsection{Using the Inverse Annotation}\label{using-the-inverse-annotation} annotation(experiment(StopTime = 10.0)); end NotSurjective; \end{lstlisting} -As the value of \lstinline!x! varies over the interval $[-1,\, 1]$, but the range of \lstinline!cbrtPos! is only $(0, \infty)$, the informal codomain of \lstinline!cbrtPos! cannot be restricted such that the surjectiveness is fulfilled. -A valid solution to the equation in \lstinline!x! and \lstinline!y! must satisfy $\text{\lstinline!y!} > 0$, and when no \lstinline!inverse! annotation is given, a violation will be detected by a nonlinear solver applied directly to the equation. -When the (invalid) inverse provided by the \lstinline!inverse! annotation is used, however, the equation gets transformed into +As the value of {\lstinline!x!} varies over the interval $[-1,\, 1]$, but the range of {\lstinline!cbrtPos!} is only $(0, \infty)$, the informal codomain of {\lstinline!cbrtPos!} cannot be restricted such that the surjectiveness is fulfilled. +A valid solution to the equation in {\lstinline!x!} and {\lstinline!y!} must satisfy $\text{{\lstinline!y!}} > 0$, and when no {\lstinline!inverse!} annotation is given, a violation will be detected by a nonlinear solver applied directly to the equation. +When the (invalid) inverse provided by the {\lstinline!inverse!} annotation is used, however, the equation gets transformed into \begin{lstlisting}[language=modelica] y = cube(x); \end{lstlisting} -where the requirement $\text{\lstinline!y!} > 0$ can no longer be detected, resulting in a simulation result that does not fulfill the original model equations. +where the requirement $\text{{\lstinline!y!}} > 0$ can no longer be detected, resulting in a simulation result that does not fulfill the original model equations. \end{example} \section{Function Inlining and Event Generation}\label{function-inlining-and-event-generation} @@ -1806,10 +1806,10 @@ \section{Function Inlining and Event Generation}\label{function-inlining-and-eve \tablehead{Annotation} & \tablehead{Description} & \tablehead{Details}\\ \hline \hline -\lstinline!Inline! & Inline function & \Cref{modelica:Inline}\\ -\lstinline!LateInline! & Inline after all symbolic transformations & \Cref{modelica:LateInline}\\ -\lstinline!InlineAfterIndexReduction! & Inline after index reduction & \Cref{modelica:InlineAfterIndexReduction}\\ -\lstinline!GenerateEvents! & Generate events for zero crossings in function & \Cref{modelica:GenerateEvents}\\ +{\lstinline!Inline!} & Inline function & \Cref{modelica:Inline}\\ +{\lstinline!LateInline!} & Inline after all symbolic transformations & \Cref{modelica:LateInline}\\ +{\lstinline!InlineAfterIndexReduction!} & Inline after index reduction & \Cref{modelica:InlineAfterIndexReduction}\\ +{\lstinline!GenerateEvents!} & Generate events for zero crossings in function & \Cref{modelica:GenerateEvents}\\ \hline \end{tabular} \end{center} @@ -1825,13 +1825,13 @@ \section{Function Inlining and Event Generation}\label{function-inlining-and-eve \begin{semantics} Has only an effect within a function declaration. -If \lstinline!Inline = true!, the model developer proposes to inline the function. +If {\lstinline!Inline = true!}, the model developer proposes to inline the function. This means, that the body of the function is included at all places where the function is called. -If \lstinline!Inline = false!, the model developer proposes to not inline the function. +If {\lstinline!Inline = false!}, the model developer proposes to not inline the function. \begin{nonnormative} -\lstinline!Inline = true! is for example used in \lstinline!Modelica.Mechanics.MultiBody.Frames! and in functions of \lstinline!Modelica.Media! to have no overhead for function calls such as resolving a vector in a different coordinate system and at the same time the function can be analytically differentiated, e.g., for index reduction needed for mechanical systems. +{\lstinline!Inline = true!} is for example used in {\lstinline!Modelica.Mechanics.MultiBody.Frames!} and in functions of {\lstinline!Modelica.Media!} to have no overhead for function calls such as resolving a vector in a different coordinate system and at the same time the function can be analytically differentiated, e.g., for index reduction needed for mechanical systems. \end{nonnormative} \end{semantics} \end{annotationdefinition} @@ -1843,23 +1843,23 @@ \section{Function Inlining and Event Generation}\label{function-inlining-and-eve \begin{semantics} Has only an effect within a function declaration. -If \lstinline!LateInline = true!, the model developer proposes to inline the function after all symbolic transformations have been performed. +If {\lstinline!LateInline = true!}, the model developer proposes to inline the function after all symbolic transformations have been performed. \begin{nonnormative} Late inlining is especially useful for differentiation and inversion of functions; for efficiency reasons it is then useful to replace all function calls with identical input arguments by one function call, before the inlining. \end{nonnormative} -If \lstinline!LateInline = false!, the model developer proposes to not inline the function after symbolic transformations have been performed. +If {\lstinline!LateInline = false!}, the model developer proposes to not inline the function after symbolic transformations have been performed. -\lstinline!Inline = true, LateInline = false! is identical to \lstinline!Inline = true!. +{\lstinline!Inline = true, LateInline = false!} is identical to {\lstinline!Inline = true!}. -\lstinline!Inline = true, LateInline = true! is identical to \lstinline!LateInline = true!. +{\lstinline!Inline = true, LateInline = true!} is identical to {\lstinline!LateInline = true!}. -\lstinline!Inline = false, LateInline = true! is identical to \lstinline!LateInline = true!. +{\lstinline!Inline = false, LateInline = true!} is identical to {\lstinline!LateInline = true!}. \begin{nonnormative} -This annotation is for example used in \lstinline!Modelica.Media.Water.IF97_Utilities.T_props_ph! to provide in combination with common subexpression elimination the automatic caching of function calls. -Furthermore, it is used in order that a tool is able to propagate specific enthalpy over connectors in the \lstinline!Modelica.Fluid! library. +This annotation is for example used in {\lstinline!Modelica.Media.Water.IF97_Utilities.T_props_ph!} to provide in combination with common subexpression elimination the automatic caching of function calls. +Furthermore, it is used in order that a tool is able to propagate specific enthalpy over connectors in the {\lstinline!Modelica.Fluid!} library. \end{nonnormative} \end{semantics} \end{annotationdefinition} @@ -1871,8 +1871,8 @@ \section{Function Inlining and Event Generation}\label{function-inlining-and-eve \begin{semantics} Has only an effect within a function declaration. -If \lstinline!true!, the model developer proposes to inline the function after the function is differentiated for index reduction, and before any other symbolic transformations are performed. -This annotation cannot be combined with annotations \lstinline!Inline! and \lstinline!LateInline!. +If {\lstinline!true!}, the model developer proposes to inline the function after the function is differentiated for index reduction, and before any other symbolic transformations are performed. +This annotation cannot be combined with annotations {\lstinline!Inline!} and {\lstinline!LateInline!}. \end{semantics} \end{annotationdefinition} @@ -1883,14 +1883,14 @@ \section{Function Inlining and Event Generation}\label{function-inlining-and-eve \begin{semantics} Has only an effect within a function declaration. -By default, \lstinline!GenerateEvents = false! and expressions in the function body that would normally be event-generating shall not generate events, similar to inlining the function body while wrapping all expressions in \lstinline!noEvent!, see \cref{modelica:noEvent}. -By specifying \lstinline!GenerateEvents = true!, event-generating expressions in the function body shall generate events as normal, similar to inlining the function body without wrapping all expressions in \lstinline!noEvent!. -Having \lstinline!GenerateEvents = true! implies \lstinline!Inline = true! unless overridden by specifying one of the inlining annotations with value \lstinline!true! (in particular, \lstinline!GenerateEvents = true! cannot be combined with \lstinline!Inline = false!). +By default, {\lstinline!GenerateEvents = false!} and expressions in the function body that would normally be event-generating shall not generate events, similar to inlining the function body while wrapping all expressions in {\lstinline!noEvent!}, see \cref{modelica:noEvent}. +By specifying {\lstinline!GenerateEvents = true!}, event-generating expressions in the function body shall generate events as normal, similar to inlining the function body without wrapping all expressions in {\lstinline!noEvent!}. +Having {\lstinline!GenerateEvents = true!} implies {\lstinline!Inline = true!} unless overridden by specifying one of the inlining annotations with value {\lstinline!true!} (in particular, {\lstinline!GenerateEvents = true!} cannot be combined with {\lstinline!Inline = false!}). \begin{nonnormative} -In case a given inlining annotation proposes to inline at a stage when the tool cannot process \lstinline!GenerateEvents = true!, it is recommended to give a diagnostic and instead perform inlining of the function at the nearest stage where \lstinline!GenerateEvents = true! can still be respected. +In case a given inlining annotation proposes to inline at a stage when the tool cannot process {\lstinline!GenerateEvents = true!}, it is recommended to give a diagnostic and instead perform inlining of the function at the nearest stage where {\lstinline!GenerateEvents = true!} can still be respected. -If the function is called in a context where events will not be generated (e.g., inside another function without \lstinline!GenerateEvents = true!) no special action is needed. +If the function is called in a context where events will not be generated (e.g., inside another function without {\lstinline!GenerateEvents = true!}) no special action is needed. \end{nonnormative} \end{semantics} \end{annotationdefinition} @@ -1939,25 +1939,25 @@ \section{External Function Interface}\label{external-function-interface} \end{lstlisting}% \indexinline{external} -Components in the public part of an external function declaration shall be declared either as \lstinline!input! or \lstinline!output!. +Components in the public part of an external function declaration shall be declared either as {\lstinline!input!} or {\lstinline!output!}. \begin{nonnormative} This is just as for any other function. The components in the protected part allow local variables for temporary storage to be declared. \end{nonnormative} -The \lstinline[language=grammar]!language-specification! must currently be one of \lstinline!"builtin"! (deprecated), \lstinline!"C"!, \lstinline!"C$\ldots$"! (for one of the specific C standards like C89, C99, and C11 -- specifying -that it relies on the C standard library of that version) or \lstinline!"FORTRAN 77"!. -Unless the external language is specified, it is assumed to be \lstinline!"C"!. +The {\lstinline[language=grammar]!language-specification!} must currently be one of {\lstinline!"builtin"!} (deprecated), {\lstinline!"C"!}, {\lstinline!"C$\ldots$"!} (for one of the specific C standards like C89, C99, and C11 -- specifying +that it relies on the C standard library of that version) or {\lstinline!"FORTRAN 77"!}. +Unless the external language is specified, it 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. \end{nonnormative} -The deprecated \lstinline!"builtin"! specification is only used for the elementary mathematical functions described in \cref{built-in-mathematical-functions-and-external-built-in-functions}. -The external function call mechanism for \lstinline!"builtin"! functions is implementation-defined. +The deprecated {\lstinline!"builtin"!} specification is only used for the elementary mathematical functions described in \cref{built-in-mathematical-functions-and-external-built-in-functions}. +The external function call mechanism for {\lstinline!"builtin"!} functions is implementation-defined. \begin{nonnormative} -Typically, for functions from the standard C library, the prototype of the function is provided but no \lstinline!Library! annotation. Currently, there are no other builtin functions defined in Modelica. +Typically, for functions from the standard C library, the prototype of the function is provided but no {\lstinline!Library!} annotation. Currently, there are no other builtin functions defined in Modelica. \end{nonnormative} \begin{example} @@ -1979,21 +1979,21 @@ \section{External Function Interface}\label{external-function-interface} \end{lstlisting} \end{example} -The \lstinline[language=grammar]!external-function-call! specification allows functions whose prototypes do not match the default assumptions as defined below to be called. It also gives the name used to call the external function. If the external call is not given explicitly, this name is assumed to be the same as the Modelica name. +The {\lstinline[language=grammar]!external-function-call!} specification allows functions whose prototypes do not match the default assumptions as defined below to be called. It also gives the name used to call the external function. If the external call is not given explicitly, this name is assumed to be the same as the Modelica name. -The only permissible kinds of expressions in the argument list are component references, scalar constants, and the function \lstinline!size! applied to an array and a constant dimension number. +The only permissible kinds of expressions in the argument list are component references, scalar constants, and the function {\lstinline!size!} applied to an array and a constant dimension number. The annotations are used to pass additional information to the compiler when necessary. A component reference to a component that is part of an input or output is treated the same way as a top-level input or output in the external call. -If the function has \lstinline!annotation(Include="includeDirective")!, \cref{annotations-for-external-libraries-and-include-files} it is assumed that it contains an actual prototype and no prototype shall be automatically generated. In that case the input argument pointers shall be const pointers (indicating that they do not modify the inputs), and non-const pointers are deprecated. The optional \lstinline[language=grammar]!external-function-call! is still used for determining the name of the function, and order of arguments, as described below. +If the function has {\lstinline!annotation(Include="includeDirective")!}, \cref{annotations-for-external-libraries-and-include-files} it is assumed that it contains an actual prototype and no prototype shall be automatically generated. In that case the input argument pointers shall be const pointers (indicating that they do not modify the inputs), and non-const pointers are deprecated. The optional {\lstinline[language=grammar]!external-function-call!} is still used for determining the name of the function, and order of arguments, as described below. \subsection{Argument type Mapping}\label{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 passed in the same way as outputs, whereas constants and \lstinline!size! calls are passed as inputs. +Protected variables (i.e.\ temporaries) are passed in the same way as outputs, whereas constants and {\lstinline!size!} calls are passed as inputs. \subsubsection{Simple Types}\label{simple-types} @@ -2014,23 +2014,23 @@ \subsubsection{Simple Types}\label{simple-types} \end{tabular} \end{center} -An exception is made when the argument is of the form \lstinline!size($\ldots$, $\ldots$)!. In this case the corresponding C type is \lstinline!size_t!. +An exception is made when the argument is of the form {\lstinline!size($\ldots$, $\ldots$)!}. In this case the corresponding C type is {\lstinline!size_t!}. -Strings are \textsc{nul}-terminated (i.e., terminated by \lstinline[language=C]!'\0'!) and are encoded using UTF-8 (assuming \lstinline[language=C]!CHAR_BIT==8! in C) to facilitate calling of C functions. -The valid return values for an external function returning a \lstinline!String! are: +Strings are \textsc{nul}-terminated (i.e., terminated by {\lstinline[language=C]!'\0'!}) and are encoded using UTF-8 (assuming {\lstinline[language=C]!CHAR_BIT==8!} in C) to facilitate calling of C functions. +The valid return values for an external function returning a {\lstinline!String!} are: \begin{itemize} -\item A string given as \lstinline!String! input to the external function. +\item A string given as {\lstinline!String!} input to the external function. \item A pointer to a C string literal. \item A pointer returned by one of the string allocation functions in \cref{utility-functions-for-allocating-strings}. \end{itemize} \begin{nonnormative} -The reason why it is not allowed to return a string allocated with, for instance, \lstinline[language=C]!malloc! is that there is no transfer of ownership when a string is returned from the external function. +The reason why it is not allowed to return a string allocated with, for instance, {\lstinline[language=C]!malloc!} is that there is no transfer of ownership when a string is returned from the external function. The external code would remain the owner of such a string, and would be responsible for eventually releasing the memory at some point. Consequently, the Modelica simulation environment would not be able to assume that only its own string deallocation routines could invalidate any of the strings returned by external functions. \end{nonnormative} -\lstinline!Boolean! values are mapped to C such that \lstinline!false! in Modelica is 0 in C and \lstinline!true! in Modelica is 1 in C. If the returned value from C is 0 it is treated as \lstinline!false! in Modelica; otherwise as \lstinline!true!. +{\lstinline!Boolean!} values are mapped to C such that {\lstinline!false!} in Modelica is 0 in C and {\lstinline!true!} in Modelica is 1 in C. If the returned value from C is 0 it is treated as {\lstinline!false!} in Modelica; otherwise as {\lstinline!true!}. \begin{nonnormative} It is recommended that the C function should interpret any non-zero value as true. @@ -2057,7 +2057,7 @@ \subsubsection{Simple Types}\label{simple-types} String are UTF-8 encoded, even though the support for non-ASCII characters in FORTRAN~77 is unclear and it is not relevant for the LAPACK/BLAS-routines. Returning strings from FORTRAN~77 subroutines/functions is currently not supported. -Enumeration types used as arguments are mapped to type int when calling an external C function, and to type \lstinline!INTEGER! when calling an external FORTRAN function. +Enumeration types used as arguments are mapped to type int when calling an external C function, and to type {\lstinline!INTEGER!} when calling an external FORTRAN function. The $i$th enumeration literal is mapped to integer value $i$, starting at 1. Return values are mapped to enumeration types analogously: integer value @@ -2067,16 +2067,16 @@ \subsubsection{Simple Types}\label{simple-types} \subsubsection{Arrays}\label{arrays-1} -Unless an explicit function call is present in the \lstinline!external!-clause, an array is passed by its address followed by $n$ arguments of type \lstinline!size_t! with the corresponding array dimension sizes, where $n$ is the number of dimensions. +Unless an explicit function call is present in the {\lstinline!external!}-clause, an array is passed by its address followed by $n$ arguments of type {\lstinline!size_t!} with the corresponding array dimension sizes, where $n$ is the number of dimensions. \begin{nonnormative} -The type \lstinline[language=C]!size_t! is a C unsigned integer type. +The type {\lstinline[language=C]!size_t!} is a C unsigned integer type. \end{nonnormative} -Arrays are by default stored in row-major order when calling C functions and in column-major order when calling FORTRAN~77 functions. These defaults can be overridden by the \lstinline!arrayLayout! annotation. See the example below. +Arrays are by default stored in row-major order when calling C functions and in column-major order when calling FORTRAN~77 functions. These defaults can be overridden by the {\lstinline!arrayLayout!} annotation. See the example below. The table below shows the mapping of an array argument in the absence of an explicit external function call when calling a C function. -The type \lstinline!T! is allowed to be any of the simple types which can be passed to C as defined in \cref{simple-types} or a record type as defined in \cref{records} and it is mapped to the type $T'$ as defined in these sections for input arguments. +The type {\lstinline!T!} is allowed to be any of the simple types which can be passed to C as defined in \cref{simple-types} or a record type as defined in \cref{records} and it is mapped to the type $T'$ as defined in these sections for input arguments. Array inputs to C-functions are const-pointers, indicating that the arrays shall not be changed. \begin{center} @@ -2086,17 +2086,17 @@ \subsubsection{Arrays}\label{arrays-1} & \multicolumn{1}{c}{\tablehead{Input}} & \multicolumn{1}{c}{\tablehead{Output}} \\ \hline \hline -\lstinline!T[$\mathit{dim}_{1}$]! & -\lstinline[language=C]!const $T'$ *, size_t $\mathit{dim}_{1}$! & -\lstinline[language=C]!$T'$ *, size_t $\mathit{dim}_{1}$! +{\lstinline!T[$\mathit{dim}_{1}$]!} & +{\lstinline[language=C]!const $T'$ *, size_t $\mathit{dim}_{1}$!} & +{\lstinline[language=C]!$T'$ *, size_t $\mathit{dim}_{1}$!} \\ -\lstinline!T[$\mathit{dim}_{1}$, $\mathit{dim}_{2}$]! & -\lstinline[language=C]!const $T'$ *, size_t $\mathit{dim}_{1}$, size_t $\mathit{dim}_{2}$! & -\lstinline[language=C]!$T'$ *, size_t $\mathit{dim}_{1}$, size_t $\mathit{dim}_{2}$! +{\lstinline!T[$\mathit{dim}_{1}$, $\mathit{dim}_{2}$]!} & +{\lstinline[language=C]!const $T'$ *, size_t $\mathit{dim}_{1}$, size_t $\mathit{dim}_{2}$!} & +{\lstinline[language=C]!$T'$ *, size_t $\mathit{dim}_{1}$, size_t $\mathit{dim}_{2}$!} \\ -\lstinline!T[$\ldots$, $\mathit{dim}_{n}$]! & -\lstinline[language=C]!const $T'$ *, $\ldots$, size_t $\mathit{dim}_{n}$! & -\lstinline[language=C]!$T'$ *, $\ldots$, size_t $\mathit{dim}_{n}$! +{\lstinline!T[$\ldots$, $\mathit{dim}_{n}$]!} & +{\lstinline[language=C]!const $T'$ *, $\ldots$, size_t $\mathit{dim}_{n}$!} & +{\lstinline[language=C]!$T'$ *, $\ldots$, size_t $\mathit{dim}_{n}$!} \\ \hline \end{tabular} @@ -2113,14 +2113,14 @@ \subsubsection{Arrays}\label{arrays-1} & \multicolumn{1}{c}{\tablehead{Input and output}}\\ \hline \hline -\lstinline!T[$\mathit{dim}_{1}$]! & -\lstinline[language=FORTRAN77]!$T'$, INTEGER $\mathit{dim}_{1}$! +{\lstinline!T[$\mathit{dim}_{1}$]!} & +{\lstinline[language=FORTRAN77]!$T'$, INTEGER $\mathit{dim}_{1}$!} \\ -\lstinline!T[$\mathit{dim}_{1}$, $\mathit{dim}_{2}$]! & -\lstinline[language=FORTRAN77]!$T'$, INTEGER $\mathit{dim}_{1}$, INTEGER $\mathit{dim}_{2}$! +{\lstinline!T[$\mathit{dim}_{1}$, $\mathit{dim}_{2}$]!} & +{\lstinline[language=FORTRAN77]!$T'$, INTEGER $\mathit{dim}_{1}$, INTEGER $\mathit{dim}_{2}$!} \\ -\lstinline!T[$\mathit{dim}_{1}$, $\ldots$, $\mathit{dim}_{n}$]! & -\lstinline[language=FORTRAN77]!$T'$, INTEGER $\mathit{dim}_{1}$, $\ldots$, INTEGER $\mathit{dim}_{n}$! +{\lstinline!T[$\mathit{dim}_{1}$, $\ldots$, $\mathit{dim}_{n}$]!} & +{\lstinline[language=FORTRAN77]!$T'$, INTEGER $\mathit{dim}_{1}$, $\ldots$, INTEGER $\mathit{dim}_{n}$!} \\ \hline \end{tabular} @@ -2263,7 +2263,7 @@ \subsection{Return Type Mapping}\label{return-type-mapping} Mapping of the return type of functions is performed as indicated in the table below. Storage for arrays as return values is allocated by the calling routine, so the dimensions of the returned array are fixed at call time. -See \cref{simple-types} regarding returning of \lstinline!String! values. +See \cref{simple-types} regarding returning of {\lstinline!String!} values. \begin{nonnormative} In the case of an external function not returning anything, argument type mapping according to \cref{simple-types} is performed in the absence @@ -2288,7 +2288,7 @@ \subsection{Return Type Mapping}\label{return-type-mapping} \end{tabular} \end{center} -The element type \lstinline!T! of an array can be any simple type as defined in \cref{simple-types} or, for C, a record type is returned as a value of the record type defined in \cref{records}. +The element type {\lstinline!T!} of an array can be any simple type as defined in \cref{simple-types} or, for C, a record type is returned as a value of the record type defined in \cref{records}. \subsection{Aliasing}\label{aliasing} @@ -2336,11 +2336,11 @@ \subsection{Aliasing}\label{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 -would have to change the interface function \lstinline!foo! to: +would have to change the interface function {\lstinline!foo!} to: \begin{lstlisting}[language=modelica] function foo input Real x; @@ -2357,55 +2357,55 @@ \subsection{Aliasing}\label{aliasing} aliasing between any pair of arguments to a function (Section 15.9.3.6 of X3J3/90.4). For the few (if any) FORTRAN~77 compilers that strictly follow the standard and are unable to handle aliasing between input -variables the tool must transform the first call of \lstinline!foo! into: +variables the tool must transform the first call of {\lstinline!foo!} into: \begin{lstlisting}[language=C] temp1 = a; /* Temporary to avoid aliasing */ myfoo_(&a, &temp1, &b); \end{lstlisting} -The use of the function \lstinline!foo! in Modelica is uninfluenced by these considerations. +The use of the function {\lstinline!foo!} in Modelica is uninfluenced by these considerations. \end{example} \subsection{Annotations for External Functions}\label{annotations-for-external-libraries-and-include-files} -The following annotations are useful in the context of calling external functions from Modelica, and they should occur on the \lstinline!external!-clause and no other standard annotations should occur on the \lstinline!external!-clause. -They can all specify either a scalar value or an array of values as indicated below for the \lstinline!Library! annotation: +The following annotations are useful in the context of calling external functions from Modelica, and they should occur on the {\lstinline!external!}-clause and no other standard annotations should occur on the {\lstinline!external!}-clause. +They can all specify either a scalar value or an array of values as indicated below for the {\lstinline!Library!} annotation: \begin{itemize} \item - The \lstinline!annotation(Library="libraryName")!\annotationindex{Library}, used by the linker to include the library file where the compiled external function is available. + The {\lstinline!annotation(Library="libraryName")!}\annotationindex{Library}, used by the linker to include the library file where the compiled external function is available. \item - The \lstinline!annotation(Library={"libraryName1", "libraryName2"})!, used by the linker to include the library files where the compiled external function is available and additional libraries used to implement it. + The {\lstinline!annotation(Library={"libraryName1", "libraryName2"})!}, used by the linker to include the library files where the compiled external function is available and additional libraries used to implement it. For shared libraries it is recommended to include all non-system libraries in this list. \item - The \lstinline!annotation(Include="includeDirective")!\annotationindex{Include}, used to include source files needed for calling the external function in the code generated by the Modelica compiler. + The {\lstinline!annotation(Include="includeDirective")!}\annotationindex{Include}, used to include source files needed for calling the external function in the code generated by the Modelica compiler. The included code should be valid C89 code. \begin{nonnormative} Examples of files that can be included are header files or source files that contain the functions referenced in the external function declaration. \end{nonnormative} \item The - \lstinline!annotation(IncludeDirectory="modelica://ModelicaLibraryName/Resources/Include")!\annotationindex{IncludeDirectory}, used to specify a location for header files. + {\lstinline!annotation(IncludeDirectory="modelica://ModelicaLibraryName/Resources/Include")!}\annotationindex{IncludeDirectory}, used to specify a location for header files. The preceding one is the default and need not be specified; but another location could be specified by using an URI name for the include directory, see \cref{external-resources}. \item The - \lstinline!annotation(LibraryDirectory="modelica://ModelicaLibraryName/Resources/Library")!\annotationindex{LibraryDirectory}, used to specify a location for library files. + {\lstinline!annotation(LibraryDirectory="modelica://ModelicaLibraryName/Resources/Library")!}\annotationindex{LibraryDirectory}, used to specify a location for library files. The preceding one is the default and need not be specified; but another location could be specified by using an URI name for the library directory, see \cref{external-resources}. - Different versions of one object library can be provided (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!. + Different versions of one object library can be provided (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 standardized: \begin{itemize} \item - \lstinline!"win32"! (Microsoft Windows 32 bit) + {\lstinline!"win32"!} (Microsoft Windows 32 bit) \item - \lstinline!"win64"! (Microsoft Windows 64 bit) + {\lstinline!"win64"!} (Microsoft Windows 64 bit) \item - \lstinline!"linux32"! (Linux Intel 32 bit) + {\lstinline!"linux32"!} (Linux Intel 32 bit) \item - \lstinline!"linux64"! (Linux Intel 64 bit) + {\lstinline!"linux64"!} (Linux Intel 64 bit) \end{itemize} \item The - \lstinline!annotation(SourceDirectory="modelica://ModelicaLibraryName/Resources/Source")!\annotationindex{SourceDirectory}, gives the location for source files. + {\lstinline!annotation(SourceDirectory="modelica://ModelicaLibraryName/Resources/Source")!}\annotationindex{SourceDirectory}, gives the location for source files. The preceding one is the default and need not be specified; but another location could be specified by using an URI name for the source directory, see \cref{external-resources}. It is not specified how they are built. \end{itemize} @@ -2426,7 +2426,7 @@ \subsection{Annotations for External Functions}\label{annotations-for-external-l 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 compatible with vs2005. \end{nonnormative} -The \lstinline!ModelicaLibraryName! used for \lstinline!IncludeDirectory!, \lstinline!LibraryDirectory!, and \lstinline!SourceDirectory! indicates the top-level class where the annotation is found in the Modelica source code. +The {\lstinline!ModelicaLibraryName!} used for {\lstinline!IncludeDirectory!}, {\lstinline!LibraryDirectory!}, and {\lstinline!SourceDirectory!} indicates the top-level class where the annotation is found in the Modelica source code. \begin{example} Use of external functions and of object libraries: @@ -2507,7 +2507,7 @@ \subsection{Annotations for External Functions}\label{annotations-for-external-l \quad\quad\quad\filename{Func2.c} \>-- \>C source for \filename{ExternalLib2.lib}\\ \quad\quad\quad\filename{HelperFunc.c} \>-- \>C source also included in \filename{ExternalLib2.lib}\\ \filename{MyExternalFunctions}\\ -\quad\filename{package.mo}% No line break on last line! +\quad\filename{package.mo}% No line break on last line!} \end{tabbing}} % Adding paragraph break (line break isn't allowed after empty line) below tabbing environment to work around LaTeXML issue (fixed on master 2021-12-17): % - https://github.com/brucemiller/LaTeXML/issues/1719 (marked as fixed as of commit 3e8e2e15) @@ -2515,19 +2515,19 @@ \subsection{Annotations for External Functions}\label{annotations-for-external-l \else \par \fi -Note that calling the function \lstinline!MyExternalFunctions.ExternalFunc1! will use -the header and library files from \lstinline!ExternalFunction!, the \lstinline!ExternalFunctions.Example! will not use \filename{ExternalFunc3.c}, +Note that calling the function {\lstinline!MyExternalFunctions.ExternalFunc1!} will use +the header and library files from {\lstinline!ExternalFunction!}, the {\lstinline!ExternalFunctions.Example!} will not use \filename{ExternalFunc3.c}, and one library file may contain multiple functions. The C-source \filename{ExternalFunc3.c} will be included fully, and is not part of any library. That is not ideal for C-code, but it works for small functions. -It is not specified how the C-sources in the specified \lstinline!SourceDirectory! will be used to build the libraries. +It is not specified how the C-sources in the specified {\lstinline!SourceDirectory!} will be used to build the libraries. Header file for the function in the dynamic link / shared library \filename{ExternalLib2} so that the desired functions are defined to be exported for Microsoft VisualStudio and for GNU C compiler (note, for Linux it is -recommended to use the compiler option \lstinline!-fPIC! to build shared +recommended to use the compiler option {\lstinline!-fPIC!} to build shared libraries or object libraries that are later transformed to a shared library): \begin{lstlisting}[language=C] @@ -2560,7 +2560,7 @@ \subsection{Annotations for External Functions}\label{annotations-for-external-l \end{lstlisting} \end{example} -The \lstinline!Library! name and the \lstinline!LibraryDirectory! name in the function annotation are mapped to a linkage directive in a compiler-dependent way thereby selecting the object library suited for the respective computer platform. +The {\lstinline!Library!} name and the {\lstinline!LibraryDirectory!} name in the function annotation are mapped to a linkage directive in a compiler-dependent way thereby selecting the object library suited for the respective computer platform. \subsection{Examples}\label{examples1} @@ -2569,7 +2569,7 @@ \subsubsection{Input Parameters, Function Value}\label{input-parameters-function \begin{example} Here all parameters to the external function are input parameters. One function value is returned. If the external language is -not specified, the default is \lstinline!"C"!, as below. +not specified, the default is {\lstinline!"C"!}, as below. \begin{lstlisting}[language=modelica] function foo input Real x; @@ -2666,17 +2666,17 @@ \subsubsection{Error Reporting Utility Functions}\label{utility-functions-for-re \tablehead{Expression} & \tablehead{Description} & \tablehead{Details}\\ \hline \hline -\lstinline[language=C]!ModelicaMessage($\mathit{string}$)! & Message with fixed string & \multirow{3}{*}{\Cref{modelica:ModelicaMessage-et-al}} \\ -\lstinline[language=C]!ModelicaWarning($\mathit{string}$)! & Warning with fixed string & \\ -\lstinline[language=C]!ModelicaError($\mathit{string}$)! & Error with fixed string & \\ +{\lstinline[language=C]!ModelicaMessage($\mathit{string}$)!} & Message with fixed string & \multirow{3}{*}{\Cref{modelica:ModelicaMessage-et-al}} \\ +{\lstinline[language=C]!ModelicaWarning($\mathit{string}$)!} & Warning with fixed string & \\ +{\lstinline[language=C]!ModelicaError($\mathit{string}$)!} & Error with fixed string & \\ \hline -\lstinline[language=C]!ModelicaFormatMessage($\mathit{format}$, $\ldots$)! & Message with \lstinline[language=C]!printf! style formatting & \multirow{3}{*}{\Cref{modelica:ModelicaFormatMessage-et-al}} \\ -\lstinline[language=C]!ModelicaFormatWarning($\mathit{format}$, $\ldots$)! & Warning with \lstinline[language=C]!printf! style formatting & \\ -\lstinline[language=C]!ModelicaFormatError($\mathit{format}$, $\ldots$)! & Error with \lstinline[language=C]!printf! style formatting & \\ +{\lstinline[language=C]!ModelicaFormatMessage($\mathit{format}$, $\ldots$)!} & Message with {\lstinline[language=C]!printf!} style formatting & \multirow{3}{*}{\Cref{modelica:ModelicaFormatMessage-et-al}} \\ +{\lstinline[language=C]!ModelicaFormatWarning($\mathit{format}$, $\ldots$)!} & Warning with {\lstinline[language=C]!printf!} style formatting & \\ +{\lstinline[language=C]!ModelicaFormatError($\mathit{format}$, $\ldots$)!} & Error with {\lstinline[language=C]!printf!} style formatting & \\ \hline -\lstinline[language=C]!ModelicaVFormatMessage($\mathit{format}$, $\mathit{ap}$)! & Message with \lstinline[language=C]!vprintf! style formatting & \multirow{3}{*}{\Cref{modelica:ModelicaVFormatMessage-et-al}} \\ -\lstinline[language=C]!ModelicaVFormatWarning($\mathit{format}$, $\mathit{ap}$)! & Warning with \lstinline[language=C]!vprintf! style formatting & \\ -\lstinline[language=C]!ModelicaVFormatError($\mathit{format}$, $\mathit{ap}$)! & Error with \lstinline[language=C]!vprintf! style formatting & \\ +{\lstinline[language=C]!ModelicaVFormatMessage($\mathit{format}$, $\mathit{ap}$)!} & Message with {\lstinline[language=C]!vprintf!} style formatting & \multirow{3}{*}{\Cref{modelica:ModelicaVFormatMessage-et-al}} \\ +{\lstinline[language=C]!ModelicaVFormatWarning($\mathit{format}$, $\mathit{ap}$)!} & Warning with {\lstinline[language=C]!vprintf!} style formatting & \\ +{\lstinline[language=C]!ModelicaVFormatError($\mathit{format}$, $\mathit{ap}$)!} & Error with {\lstinline[language=C]!vprintf!} style formatting & \\ \hline \end{tabular} \end{center} @@ -2684,11 +2684,11 @@ \subsubsection{Error Reporting Utility Functions}\label{utility-functions-for-re The \emph{Message}-functions only produce the message, but the \emph{Warning}- and \emph{Error}-functions combine this with error handling as follows. The \emph{Warning}-functions view the message as a warning and can skip -duplicated messages similarly as an \lstinline!assert! with -\lstinline!level = AssertionLevel.Warning! in the Modelica code. +duplicated messages similarly as an {\lstinline!assert!} with +{\lstinline!level = AssertionLevel.Warning!} in the Modelica code. The \emph{Error}-functions never return to the calling function, but handle the -error similarly to an \lstinline!assert! with \lstinline!level = AssertionLevel.Error! in the +error similarly to an {\lstinline!assert!} with {\lstinline!level = AssertionLevel.Error!} in the Modelica code. \begin{functiondefinition*}[ModelicaMessage, ModelicaWarning, ModelicaError]\label{modelica:ModelicaMessage-et-al}% @@ -2713,7 +2713,7 @@ \subsubsection{Error Reporting Utility Functions}\label{utility-functions-for-re void ModelicaFormatError(const char* $\mathit{format}$, ...) \end{lstlisting}\end{synopsis} \begin{semantics} -Output the message under the same format control as the C function \lstinline[language=C]!printf!. +Output the message under the same format control as the C function {\lstinline[language=C]!printf!}. \end{semantics} \end{functiondefinition*} @@ -2725,7 +2725,7 @@ \subsubsection{Error Reporting Utility Functions}\label{utility-functions-for-re void ModelicaVFormatError(const char* $\mathit{format}$, va_list $\mathit{ap}$) \end{lstlisting}\end{synopsis} \begin{semantics} -Output the message under the same format control as the C function \lstinline[language=C]!vprintf!. +Output the message under the same format control as the C function {\lstinline[language=C]!vprintf!}. \end{semantics} \end{functiondefinition*} @@ -2738,10 +2738,10 @@ \subsubsection{String Allocation Utility Functions}\label{utility-functions-for- \tablehead{Expression} & \tablehead{Description} & \tablehead{Details}\\ \hline \hline -\lstinline[language=C]!ModelicaAllocateString($\mathit{len}$)! & Allocate or error & \Cref{modelica:ModelicaAllocateString} \\ -\lstinline[language=C]!ModelicaAllocateStringWithErrorReturn($\mathit{len}$)! & Allocate or null& \Cref{modelica:ModelicaAllocateStringWithErrorReturn} \\ -\lstinline[language=C]!ModelicaDuplicateString($\mathit{str}$)! & Duplicate or error & \Cref{modelica:ModelicaDuplicateString} \\ -\lstinline[language=C]!ModelicaDuplicateStringWithErrorReturn($\mathit{str}$)! & Duplicate or null& \Cref{modelica:ModelicaDuplicateStringWithErrorReturn} \\ +{\lstinline[language=C]!ModelicaAllocateString($\mathit{len}$)!} & Allocate or error & \Cref{modelica:ModelicaAllocateString} \\ +{\lstinline[language=C]!ModelicaAllocateStringWithErrorReturn($\mathit{len}$)!} & Allocate or null& \Cref{modelica:ModelicaAllocateStringWithErrorReturn} \\ +{\lstinline[language=C]!ModelicaDuplicateString($\mathit{str}$)!} & Duplicate or error & \Cref{modelica:ModelicaDuplicateString} \\ +{\lstinline[language=C]!ModelicaDuplicateStringWithErrorReturn($\mathit{str}$)!} & Duplicate or null& \Cref{modelica:ModelicaDuplicateStringWithErrorReturn} \\ \hline \end{tabular} \end{center} @@ -2749,10 +2749,10 @@ \subsubsection{String Allocation Utility Functions}\label{utility-functions-for- As described in \cref{simple-types}, an external function wanting to return a newly constructed string must allocate this string with one of the string allocation functions in this section. The allocated memory is owned by the Modelica simulation environment, and may only be accessed by the external function during the currently executing external function call. The string allocation functions can also be used to allocate temporary strings that are not returned from the external function, with the convenience of the Modelica simulation environment being responsible for deallocation after the return of the external function. -(This is particularly convenient for avoiding memory leaks in the event of abnormal termination of the external function, for example, via \lstinline[language=C]!ModelicaError!). +(This is particularly convenient for avoiding memory leaks in the event of abnormal termination of the external function, for example, via {\lstinline[language=C]!ModelicaError!}). \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~\cref{external-objects}, may be allocated with the standard C mechanisms, like \lstinline[language=C]!malloc!. +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~\cref{external-objects}, may be allocated with the standard C mechanisms, like {\lstinline[language=C]!malloc!}. \end{nonnormative} \begin{functiondefinition}[ModelicaAllocateString] @@ -2761,7 +2761,7 @@ \subsubsection{String Allocation Utility Functions}\label{utility-functions-for- \end{lstlisting}\end{synopsis} \begin{semantics} Allocates $\mathit{len}+1$ characters, and sets the last one to \textsc{nul}. -If an error occurs, this function does not return, but calls \lstinline[language=C]!ModelicaError!. +If an error occurs, this function does not return, but calls {\lstinline[language=C]!ModelicaError!}. \end{semantics} \end{functiondefinition} @@ -2770,9 +2770,9 @@ \subsubsection{String Allocation Utility Functions}\label{utility-functions-for- char* ModelicaAllocateStringWithErrorReturn(size_t $\mathit{len}$) \end{lstlisting}\end{synopsis} \begin{semantics} -Same as \lstinline[language=C]!ModelicaAllocateString!, except that in case of error, the function returns 0. +Same as {\lstinline[language=C]!ModelicaAllocateString!}, except that in case of error, the function returns 0. This allows the external function to close files and free other open resources in case of error. -After cleaning up resources, use \lstinline[language=C]!ModelicaError! or \lstinline[language=C]!ModelicaFormatError! to signal the error. +After cleaning up resources, use {\lstinline[language=C]!ModelicaError!} or {\lstinline[language=C]!ModelicaFormatError!} to signal the error. \end{semantics} \end{functiondefinition} @@ -2782,7 +2782,7 @@ \subsubsection{String Allocation Utility Functions}\label{utility-functions-for- \end{lstlisting}\end{synopsis} \begin{semantics} Returns a writeable duplicate of the \textsc{nul}-terminated string $\mathit{str}$. -If an error occurs, this function does not return, but calls \lstinline[language=C]!ModelicaError!. +If an error occurs, this function does not return, but calls {\lstinline[language=C]!ModelicaError!}. \end{semantics} \end{functiondefinition} @@ -2791,38 +2791,38 @@ \subsubsection{String Allocation Utility Functions}\label{utility-functions-for- char* ModelicaDuplicateStringWithErrorReturn(const char* $\mathit{str}$) \end{lstlisting}\end{synopsis} \begin{semantics} -Same as \lstinline[language=C]!ModelicaDuplicateString!, except that in case of error, the function returns 0. +Same as {\lstinline[language=C]!ModelicaDuplicateString!}, except that in case of error, the function returns 0. This allows the external function to close files and free other open resources in case of error. -After cleaning up resources, use \lstinline[language=C]!ModelicaError! or \lstinline[language=C]!ModelicaFormatError! to signal the error. +After cleaning up resources, use {\lstinline[language=C]!ModelicaError!} or {\lstinline[language=C]!ModelicaFormatError!} to signal the error. \end{semantics} \end{functiondefinition} \subsection{External Objects}\label{external-objects} External functions may need to store their internal memory between function calls. -Within Modelica this memory is defined as instance of the predefined class \lstinline!ExternalObject! according to the following rules: +Within Modelica this memory is defined as instance of the predefined class {\lstinline!ExternalObject!} according to the following rules: \begin{itemize} \item - There is a predefined partial class \lstinline!ExternalObject!\indexinline{ExternalObject}. + There is a predefined partial class {\lstinline!ExternalObject!}\indexinline{ExternalObject}. \begin{nonnormative} Since the class is partial, it is not possible to define an instance of this class. \end{nonnormative} \item - An external object class shall be directly extended from \lstinline!ExternalObject!, shall have exactly two function definitions, called \lstinline!constructor! and \lstinline!destructor!, and shall not contain other elements. - The functions \lstinline!constructor! and \lstinline!destructor! shall not be replaceable. - It is not legal to call the \lstinline!constructor! and \lstinline!destructor! functions explicitly. + An external object class shall be directly extended from {\lstinline!ExternalObject!}, shall have exactly two function definitions, called {\lstinline!constructor!} and {\lstinline!destructor!}, and shall not contain other elements. + The functions {\lstinline!constructor!} and {\lstinline!destructor!} shall not be replaceable. + It is not legal to call the {\lstinline!constructor!} and {\lstinline!destructor!} functions explicitly. \item - The \lstinline!constructor! function is called exactly once before the first use of the object. - The \lstinline!constructor! shall have exactly one output argument in which the constructed instance derived from \lstinline!ExternalObject! is returned. + The {\lstinline!constructor!} function is called exactly once before the first use of the object. + The {\lstinline!constructor!} shall have exactly one output argument in which the constructed instance derived from {\lstinline!ExternalObject!} is returned. The arguments to the constructor must not -- directly nor indirectly -- depend on the external object being constructed. The constructor shall initialize the object, and 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 constructor shall not assume that pointers sent 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. \item - For each completely constructed object, the \lstinline!destructor! is called exactly once, after the last use of the object, even if an error occurs. - The \lstinline!destructor! shall have no output arguments and the only input argument of the destructor shall be of the type derived from \lstinline!ExternalObject!. - 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). + For each completely constructed object, the {\lstinline!destructor!} is called exactly once, after the last use of the object, even if an error occurs. + The {\lstinline!destructor!} shall have no output arguments and the only input argument of the destructor shall be of the type derived from {\lstinline!ExternalObject!}. + 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). \begin{nonnormative} 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. @@ -2833,12 +2833,12 @@ \subsection{External Objects}\label{external-objects} The function input shall not have a default value using the constructor. \end{nonnormative} \item - An external object class shall be of the specialized class \lstinline!class!. + An external object class shall be of the specialized class {\lstinline!class!}. \begin{nonnormative} - This is the only use of \lstinline!class!. + This is the only use of {\lstinline!class!}. \end{nonnormative} \item - Classes derived from \lstinline!ExternalObject! can neither be used in an \lstinline!extends!-clause nor in a short class definition. + Classes derived from {\lstinline!ExternalObject!} can neither be used in an {\lstinline!extends!}-clause nor in a short class definition. \item Only the constructor may return external objects and an external object can only be bound in component declarations and neither modified later @@ -2848,13 +2848,13 @@ \subsection{External Objects}\label{external-objects} \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 + of an {\lstinline!ExternalObject!}. An {\lstinline!ExternalObject!} used as input argument or return value of an external C function is mapped to the C type - \lstinline!void*!. + {\lstinline!void*!}. \end{itemize} \begin{example} -A user-defined table may be defined in the following way as an \lstinline!ExternalObject! +A user-defined table may be defined in the following way as an {\lstinline!ExternalObject!} (the table is read in a user-defined format from file and has memory for the last used table interval): \begin{lstlisting}[language=modelica] class MyTable diff --git a/chapters/inheritance.tex b/chapters/inheritance.tex index 91186503a..846ed55b3 100644 --- a/chapters/inheritance.tex +++ b/chapters/inheritance.tex @@ -400,15 +400,15 @@ \subsection{Merging of Modifications}\label{merging-of-modifications} \tablehead{Variable} & \tablehead{Default value}\\ \hline \hline -\lstinline!x1! & \textit{none}\\ % Look of \emph won't be as expected inside example. -\lstinline!x2! & 22\\ -\lstinline!x3.a! & 33\\ -\lstinline!x4.b! & 4\\ -\lstinline!x4.c! & 44\\ -\lstinline!x5.a! & \lstinline!x3.a!\\ -\lstinline!a! & 55\\ -\lstinline!b! & 66\\ -\lstinline!c! & 77\\ +{\lstinline!x1!} & \textit{none}\\ % Look of \emph won't be as expected inside example. +{\lstinline!x2!} & 22\\ +{\lstinline!x3.a!} & 33\\ +{\lstinline!x4.b!} & 4\\ +{\lstinline!x4.c!} & 44\\ +{\lstinline!x5.a!} & {\lstinline!x3.a!}\\ +{\lstinline!a!} & 55\\ +{\lstinline!b!} & 66\\ +{\lstinline!c!} & 77\\ \hline \end{tabular} \end{center} diff --git a/chapters/lexicalstructure.tex b/chapters/lexicalstructure.tex index 36ae1bcdc..57566e5f3 100644 --- a/chapters/lexicalstructure.tex +++ b/chapters/lexicalstructure.tex @@ -188,17 +188,17 @@ \subsection{Strings}\label{strings} \tablehead{Character} & \tablehead{Description}\\ \hline \hline -\lstinline!\'! & Single quote, may also appear without backslash in string constants\\ -\lstinline!\"! & Double quote\\ -\lstinline!\?! & Question-mark, may also appear without backslash in string constants\\ -\lstinline!\\! & Backslash itself\\ -\lstinline!\a! & Alert (bell, code 7, ctrl-G)\\ -\lstinline!\b! & Backspace (code 8, ctrl-H)\\ -\lstinline!\f! & Form feed (code 12, ctrl-L)\\ -\lstinline!\n! & Newline (code 10, ctrl-J), same as literal newline\\ -\lstinline!\r! & Carriage return (code 13, ctrl-M)\\ -\lstinline!\t! & Horizontal tab (code 9, ctrl-I)\\ -\lstinline!\v! & Vertical tab (code 11, ctrl-K)\\ +{\lstinline!\'!} & Single quote, may also appear without backslash in string constants\\ +{\lstinline!\"!} & Double quote\\ +{\lstinline!\?!} & Question-mark, may also appear without backslash in string constants\\ +{\lstinline!\\!} & Backslash itself\\ +{\lstinline!\a!} & Alert (bell, code 7, ctrl-G)\\ +{\lstinline!\b!} & Backspace (code 8, ctrl-H)\\ +{\lstinline!\f!} & Form feed (code 12, ctrl-L)\\ +{\lstinline!\n!} & Newline (code 10, ctrl-J), same as literal newline\\ +{\lstinline!\r!} & Carriage return (code 13, ctrl-M)\\ +{\lstinline!\t!} & Horizontal tab (code 9, ctrl-I)\\ +{\lstinline!\v!} & Vertical tab (code 11, ctrl-K)\\ \hline \end{tabular} \end{center} diff --git a/chapters/operatorsandexpressions.tex b/chapters/operatorsandexpressions.tex index a09bb6948..c24e86b33 100644 --- a/chapters/operatorsandexpressions.tex +++ b/chapters/operatorsandexpressions.tex @@ -198,11 +198,11 @@ \section{Arithmetic Operators}\label{arithmetic-operators} \tablehead{Operator} & \tablehead{Description} \\ \hline \hline -\lstinline!^! & Exponentiation\\ -\lstinline!*! & Multiplication\\ -\lstinline!/! & Division\\ -\lstinline!+! & Addition\\ -\lstinline!-! & Subtraction\\ +{\lstinline!^!} & Exponentiation\\ +{\lstinline!*!} & Multiplication\\ +{\lstinline!/!} & Division\\ +{\lstinline!+!} & Addition\\ +{\lstinline!-!} & Subtraction\\ \hline \end{tabular} \end{center} @@ -235,12 +235,12 @@ \section{Equality, Relational, and Logical Operators}\label{equality-relational- \tablehead{Operator} & \tablehead{Description} \\ \hline \hline -\lstinline!>! & Greater than\\ -\lstinline!>=! & Greater than or equal\\ -\lstinline!! & Inequality\\ +{\lstinline!>!} & Greater than\\ +{\lstinline!>=!} & Greater than or equal\\ +{\lstinline!!} & Inequality\\ \hline \end{tabular} \end{center} @@ -253,9 +253,9 @@ \section{Equality, Relational, and Logical Operators}\label{equality-relational- \tablehead{Operator} & \tablehead{Description} \\ \hline \hline -\lstinline!not!\indexinline{not} & Logical negation (unary operator)\\ -\lstinline!and!\indexinline{and} & Logical \emph{and} (conjunction)\\ -\lstinline!or!\indexinline{or} & Logical \emph{or} (disjunction)\\ +{\lstinline!not!}\indexinline{not} & Logical negation (unary operator)\\ +{\lstinline!and!}\indexinline{and} & Logical \emph{and} (conjunction)\\ +{\lstinline!or!}\indexinline{or} & Logical \emph{or} (disjunction)\\ \hline \end{tabular} \end{center} @@ -411,12 +411,12 @@ \subsection{Numeric Functions and Conversion Functions}\label{numeric-functions- \tablehead{Expression} & \tablehead{Description} & \tablehead{Details}\\ \hline \hline -\lstinline!abs($v$)! & Absolute value (event-free) & \Cref{modelica:abs} \\ -\lstinline!sign($v$)! & Sign of argument (event-free) & \Cref{modelica:sign} \\ -\lstinline!sqrt($v$)! & Square root & \Cref{modelica:sqrt} \\ -\lstinline!Integer($e$)! & Conversion from enumeration to \lstinline!Integer! & \Cref{modelica:integer-of-enumeration} \\ -\lstinline!EnumTypeName($i$)! & Conversion from \lstinline!Integer! to enumeration & \Cref{modelica:enumeration-of-integer} \\ -\lstinline!String($\ldots$)! & Conversion to \lstinline!String! & \Cref{modelica:to-String} \\ +{\lstinline!abs($v$)!} & Absolute value (event-free) & \Cref{modelica:abs} \\ +{\lstinline!sign($v$)!} & Sign of argument (event-free) & \Cref{modelica:sign} \\ +{\lstinline!sqrt($v$)!} & Square root & \Cref{modelica:sqrt} \\ +{\lstinline!Integer($e$)!} & Conversion from enumeration to {\lstinline!Integer!} & \Cref{modelica:integer-of-enumeration} \\ +{\lstinline!EnumTypeName($i$)!} & Conversion from {\lstinline!Integer!} to enumeration & \Cref{modelica:enumeration-of-integer} \\ +{\lstinline!String($\ldots$)!} & Conversion to {\lstinline!String!} & \Cref{modelica:to-String} \\ \hline \end{tabular} \end{center} @@ -537,12 +537,12 @@ \subsection{Event Triggering Mathematical Functions}\label{event-triggering-math \tablehead{Expression} & \tablehead{Description} & \tablehead{Details}\\ \hline \hline -\lstinline!div($x$, $y$)! & Division with truncation toward zero & \Cref{modelica:div} \\ -\lstinline!mod($x$, $y$)! & Integer modulus & \Cref{modelica:mod} \\ -\lstinline!rem($x$, $y$)! & Integer remainder & \Cref{modelica:rem} \\ -\lstinline!ceil($x$)! & Smallest integer \lstinline!Real! not less than $x$ & \Cref{modelica:ceil} \\ -\lstinline!floor($x$)! & Largest integer \lstinline!Real! not greater than $x$ & \Cref{modelica:floor} \\ -\lstinline!integer($x$)! & Largest \lstinline!Integer! not greater than $x$ & \Cref{modelica:integer} \\ +{\lstinline!div($x$, $y$)!} & Division with truncation toward zero & \Cref{modelica:div} \\ +{\lstinline!mod($x$, $y$)!} & Integer modulus & \Cref{modelica:mod} \\ +{\lstinline!rem($x$, $y$)!} & Integer remainder & \Cref{modelica:rem} \\ +{\lstinline!ceil($x$)!} & Smallest integer {\lstinline!Real!} not less than $x$ & \Cref{modelica:ceil} \\ +{\lstinline!floor($x$)!} & Largest integer {\lstinline!Real!} not greater than $x$ & \Cref{modelica:floor} \\ +{\lstinline!integer($x$)!} & Largest {\lstinline!Integer!} not greater than $x$ & \Cref{modelica:integer} \\ \hline \end{tabular} \end{center} @@ -649,19 +649,19 @@ \subsection{Elementary Mathematical Functions}\label{built-in-mathematical-funct \tablehead{Expression} & \tablehead{Description} & \tablehead{Details}\\ \hline \hline -\lstinline!sin($x$)! \indexinline{sin} & Sine & \\ -\lstinline!cos($x$)! \indexinline{cos} & Cosine & \\ -\lstinline!tan($x$)! \indexinline{tan} & Tangent ($x$ shall not be: $\ldots$, -$\pi/2$, $\pi/2$, $3\pi/2$, $\ldots$) & \\ -\lstinline!asin($x$)! \indexinline{asin} & Inverse sine ($-1 \le x \le 1$) & \\ -\lstinline!acos($x$)! \indexinline{acos} & Inverse cosine ($-1 \le x \le 1$) & \\ -\lstinline!atan($x$)! \indexinline{atan} & Inverse tangent & \\ -\lstinline!atan2($y$, $x$)! \indexinline{atan2} & Principal value of the arc tangent of $y/x$ & \Cref{modelica:atan2} \\ -\lstinline!sinh($x$)! \indexinline{sinh} & Hyperbolic sine & \\ -\lstinline!cosh($x$)! \indexinline{cosh} & Hyperbolic cosine & \\ -\lstinline!tanh($x$)! \indexinline{tanh} & Hyperbolic tangent & \\ -\lstinline!exp($x$)! \indexinline{exp} & Exponential, base $\mathrm{e}$ & \\ -\lstinline!log($x$)! \indexinline{log} & Natural (base $\mathrm{e}$) logarithm ($x > 0$) & \\ -\lstinline!log10($x$)! \indexinline{log10} & Base 10 logarithm ($x > 0$) & \\ +{\lstinline!sin($x$)!} \indexinline{sin} & Sine & \\ +{\lstinline!cos($x$)!} \indexinline{cos} & Cosine & \\ +{\lstinline!tan($x$)!} \indexinline{tan} & Tangent ($x$ shall not be: $\ldots$, -$\pi/2$, $\pi/2$, $3\pi/2$, $\ldots$) & \\ +{\lstinline!asin($x$)!} \indexinline{asin} & Inverse sine ($-1 \le x \le 1$) & \\ +{\lstinline!acos($x$)!} \indexinline{acos} & Inverse cosine ($-1 \le x \le 1$) & \\ +{\lstinline!atan($x$)!} \indexinline{atan} & Inverse tangent & \\ +{\lstinline!atan2($y$, $x$)!} \indexinline{atan2} & Principal value of the arc tangent of $y/x$ & \Cref{modelica:atan2} \\ +{\lstinline!sinh($x$)!} \indexinline{sinh} & Hyperbolic sine & \\ +{\lstinline!cosh($x$)!} \indexinline{cosh} & Hyperbolic cosine & \\ +{\lstinline!tanh($x$)!} \indexinline{tanh} & Hyperbolic tangent & \\ +{\lstinline!exp($x$)!} \indexinline{exp} & Exponential, base $\mathrm{e}$ & \\ +{\lstinline!log($x$)!} \indexinline{log} & Natural (base $\mathrm{e}$) logarithm ($x > 0$) & \\ +{\lstinline!log10($x$)!} \indexinline{log10} & Base 10 logarithm ($x > 0$) & \\ \hline \end{tabular} \end{center} @@ -697,15 +697,15 @@ \subsection{Derivative and Special Purpose Operators with Function Syntax}\label \tablehead{Expression} & \tablehead{Description} & \tablehead{Details}\\ \hline \hline -\lstinline!der($\mathit{expr}$)! & Time derivative & \Cref{modelica:der} \\ -\lstinline!delay($\mathit{expr}$, $\ldots$)! & Time delay & \Cref{modelica:delay} \\ -\lstinline!cardinality($c$)! & Number of occurrences in \lstinline!connect!-equations & \Cref{modelica:cardinality} \\ -\lstinline!homotopy($\mathit{actual}$, $\mathit{simplified}$)! & Homotopy initialization & \Cref{modelica:homotopy} \\ -\lstinline!semiLinear($x$, $k^{+}$, $k^{-}$)! & Sign-dependent slope & \Cref{modelica:semiLinear} \\ -\lstinline!inStream($v$)! & Stream variable flow into component & \Cref{modelica:inStream} \\ -\lstinline!actualStream($v$)! & Actual value of stream variable & \Cref{modelica:actualStream} \\ -\lstinline!spatialDistribution($\ldots$)! & Variable-speed transport & \Cref{modelica:spatialDistribution} \\ -\lstinline!getInstanceName()! & Name of instance at call site & \Cref{modelica:getInstanceName} \\ +{\lstinline!der($\mathit{expr}$)!} & Time derivative & \Cref{modelica:der} \\ +{\lstinline!delay($\mathit{expr}$, $\ldots$)!} & Time delay & \Cref{modelica:delay} \\ +{\lstinline!cardinality($c$)!} & Number of occurrences in {\lstinline!connect!}-equations & \Cref{modelica:cardinality} \\ +{\lstinline!homotopy($\mathit{actual}$, $\mathit{simplified}$)!} & Homotopy initialization & \Cref{modelica:homotopy} \\ +{\lstinline!semiLinear($x$, $k^{+}$, $k^{-}$)!} & Sign-dependent slope & \Cref{modelica:semiLinear} \\ +{\lstinline!inStream($v$)!} & Stream variable flow into component & \Cref{modelica:inStream} \\ +{\lstinline!actualStream($v$)!} & Actual value of stream variable & \Cref{modelica:actualStream} \\ +{\lstinline!spatialDistribution($\ldots$)!} & Variable-speed transport & \Cref{modelica:spatialDistribution} \\ +{\lstinline!getInstanceName()!} & Name of instance at call site & \Cref{modelica:getInstanceName} \\ \hline \end{tabular} \end{center} @@ -1225,15 +1225,15 @@ \subsection{Event-Related Operators with Function Syntax}\label{event-related-op \tablehead{Expression} & \tablehead{Description} & \tablehead{Details}\\ \hline \hline -\lstinline!initial()! & Predicate for the initialization phase & \Cref{modelica:initial}\\ -\lstinline!terminal()! & Predicate for the end of a successful analysis & \Cref{modelica:terminal}\\ -\lstinline!noEvent($\mathit{expr}$)! & Evaluate $\mathit{expr}$ without triggering events & \Cref{modelica:noEvent}\\ -\lstinline!smooth($p$, $\mathit{expr}$)! & Treat $\mathit{expr}$ as $p$ times continuously differentiable & \Cref{modelica:smooth}\\ -\lstinline!sample($\mathit{start}$, $\mathit{interval}$)! & Periodic triggering of events & \Cref{modelica:event-sample}\\ -\lstinline!pre($y$)! & Left limit $y(t^{-})$ of variable $y(t)$ & \Cref{modelica:pre}\\ -\lstinline!edge($b$)! & Expands into \lstinline!($b$ and not pre($b$))! & \Cref{modelica:edge}\\ -\lstinline!change($v$)! & Expands into \lstinline!($v$ <> pre($v$))! & \Cref{modelica:change}\\ -\lstinline!reinit($x$, $\mathit{expr}$)! & Reinitialize $x$ with $\mathit{expr}$ & \Cref{modelica:reinit}\\ +{\lstinline!initial()!} & Predicate for the initialization phase & \Cref{modelica:initial}\\ +{\lstinline!terminal()!} & Predicate for the end of a successful analysis & \Cref{modelica:terminal}\\ +{\lstinline!noEvent($\mathit{expr}$)!} & Evaluate $\mathit{expr}$ without triggering events & \Cref{modelica:noEvent}\\ +{\lstinline!smooth($p$, $\mathit{expr}$)!} & Treat $\mathit{expr}$ as $p$ times continuously differentiable & \Cref{modelica:smooth}\\ +{\lstinline!sample($\mathit{start}$, $\mathit{interval}$)!} & Periodic triggering of events & \Cref{modelica:event-sample}\\ +{\lstinline!pre($y$)!} & Left limit $y(t^{-})$ of variable $y(t)$ & \Cref{modelica:pre}\\ +{\lstinline!edge($b$)!} & Expands into {\lstinline!($b$ and not pre($b$))!} & \Cref{modelica:edge}\\ +{\lstinline!change($v$)!} & Expands into {\lstinline!($v$ <> pre($v$))!} & \Cref{modelica:change}\\ +{\lstinline!reinit($x$, $\mathit{expr}$)!} & Reinitialize $x$ with $\mathit{expr}$ & \Cref{modelica:reinit}\\ \hline \end{tabular} \end{center} diff --git a/chapters/statemachines.tex b/chapters/statemachines.tex index 2f7b335ee..93f684e9e 100644 --- a/chapters/statemachines.tex +++ b/chapters/statemachines.tex @@ -53,8 +53,8 @@ \section{Transitions}\label{transitions} \tablehead{Expression} & \tablehead{Description} & \tablehead{Details}\\ \hline \hline -\lstinline!transition($\mathit{from}$, $\mathit{to}$, $\mathit{condition}$, $\ldots$)! & State machine transition between states & \Cref{modelica:transition}\\ -\lstinline!initialState($\mathit{state}$)! & State machine initial state & \Cref{modelica:initialState}\\ +{\lstinline!transition($\mathit{from}$, $\mathit{to}$, $\mathit{condition}$, $\ldots$)!} & State machine transition between states & \Cref{modelica:transition}\\ +{\lstinline!initialState($\mathit{state}$)!} & State machine initial state & \Cref{modelica:initialState}\\ \hline \end{tabular} \end{center} @@ -68,9 +68,9 @@ \section{Transitions}\label{transitions} \tablehead{Expression} & \tablehead{Description} & \tablehead{Details}\\ \hline \hline -\lstinline!activeState($\mathit{state}$)! & Predicate for active state & \Cref{modelica:activeState}\\ -\lstinline!ticksInState()! & Ticks since activation & \Cref{modelica:ticksInState}\\ -\lstinline!timeInState()! & Time since activation & \Cref{modelica:timeInState}\\ +{\lstinline!activeState($\mathit{state}$)!} & Predicate for active state & \Cref{modelica:activeState}\\ +{\lstinline!ticksInState()!} & Ticks since activation & \Cref{modelica:ticksInState}\\ +{\lstinline!timeInState()!} & Time since activation & \Cref{modelica:timeInState}\\ \hline \end{tabular} \end{center} diff --git a/chapters/synchronous.tex b/chapters/synchronous.tex index 9cd0c6935..9e07c1cfe 100644 --- a/chapters/synchronous.tex +++ b/chapters/synchronous.tex @@ -304,11 +304,11 @@ \section{Clock Constructors}\label{clock-constructors} \tablehead{Expression} & \tablehead{Description} & \tablehead{Details}\\ \hline \hline -\lstinline!Clock()! & Inferred clock & \Cref{modelica:clock-inferred}\\ -\lstinline!Clock(intervalCounter, resolution)! & Rational interval clock & \Cref{modelica:clock-rational}\\ -\lstinline!Clock(interval)! & Real interval clock & \Cref{modelica:clock-interval}\\ -\lstinline!Clock(condition, startInterval)! & Event clock & \Cref{modelica:clock-event}\\ -\lstinline!Clock(c, solverMethod)! & Solver clock & \Cref{modelica:clock-solver}\\ +{\lstinline!Clock()!} & Inferred clock & \Cref{modelica:clock-inferred}\\ +{\lstinline!Clock(intervalCounter, resolution)!} & Rational interval clock & \Cref{modelica:clock-rational}\\ +{\lstinline!Clock(interval)!} & Real interval clock & \Cref{modelica:clock-interval}\\ +{\lstinline!Clock(condition, startInterval)!} & Event clock & \Cref{modelica:clock-event}\\ +{\lstinline!Clock(c, solverMethod)!} & Solver clock & \Cref{modelica:clock-solver}\\ \hline \end{tabular} \end{center} @@ -529,7 +529,7 @@ \section{Clocked State Variables}\label{clocked-state-variables} \tablehead{Expression} & \tablehead{Description} & \tablehead{Details}\\ \hline \hline -\lstinline!previous($u$)! & Previous value of clocked state variable & \Cref{modelica:previous} \\ +{\lstinline!previous($u$)!} & Previous value of clocked state variable & \Cref{modelica:previous} \\ \hline \end{tabular} \end{center} @@ -563,8 +563,8 @@ \subsection{Base-Clock Conversion Operators}\label{base-clock-conversion-operato \tablehead{Expression} & \tablehead{Description} & \tablehead{Details}\\ \hline \hline -\lstinline!sample($u$, $\mathit{clock}$)! & Sample continuous-time expression & \Cref{modelica:clocked-sample} \\ -\lstinline!hold($u$)! & Zeroth order hold of clocked-time variable & \Cref{modelica:clocked-sample} \\ +{\lstinline!sample($u$, $\mathit{clock}$)!} & Sample continuous-time expression & \Cref{modelica:clocked-sample} \\ +{\lstinline!hold($u$)!} & Zeroth order hold of clocked-time variable & \Cref{modelica:clocked-sample} \\ \hline \end{tabular} \end{center} @@ -640,11 +640,11 @@ \subsection{Sub-Clock Conversion Operators}\label{sub-clock-conversion-operators \tablehead{Expression} & \tablehead{Description} & \tablehead{Details}\\ \hline \hline -\lstinline!subSample($u$, factor)! & Clock that is slower by a factor & \Cref{modelica:subSample}\\ -\lstinline!superSample($u$, factor)! & Clock that is faster by a factor & \Cref{modelica:superSample}\\ -\lstinline!shiftSample($u$, shiftCounter, resolution)! & Clock with time-shifted ticks & \Cref{modelica:shiftSample}\\ -\lstinline!backSample($u$, backCounter, resolution)! & Inverse of \lstinline!shiftSample! & \Cref{modelica:backSample}\\ -\lstinline!noClock($u$)! & Clock that is always inferred & \Cref{modelica:noClock}\\ +{\lstinline!subSample($u$, factor)!} & Clock that is slower by a factor & \Cref{modelica:subSample}\\ +{\lstinline!superSample($u$, factor)!} & Clock that is faster by a factor & \Cref{modelica:superSample}\\ +{\lstinline!shiftSample($u$, shiftCounter, resolution)!} & Clock with time-shifted ticks & \Cref{modelica:shiftSample}\\ +{\lstinline!backSample($u$, backCounter, resolution)!} & Inverse of {\lstinline!shiftSample!} & \Cref{modelica:backSample}\\ +{\lstinline!noClock($u$)!} & Clock that is always inferred & \Cref{modelica:noClock}\\ \hline \end{tabular} \end{center} @@ -1181,19 +1181,19 @@ \subsection{Solver Methods}\label{solver-methods} \tablehead{\lstinline!SolverMethod!} & \tablehead{Solution method} \\ \hline \hline -\lstinline!"ExplicitEuler"! & +{\lstinline!"ExplicitEuler"!} & $\begin{aligned} x_{i} &:= x_{i-1}+h\cdot\dot{x}_{i-1}\\ \dot{x}_{i} &:= f(x_i,u_{c,i},u_{d,i},t_i) \end{aligned}$ \\ \hline -\lstinline!"ExplicitMidPoint2"! & +{\lstinline!"ExplicitMidPoint2"!} & $\begin{aligned} x_{i} &:= x_{i-1}+h\cdot f(x_{i-1}+\frac{1}{2}\cdot h \cdot\dot{x}_{i-1},\frac{u_{c,i-1}+u_{c,i}}{2},u_{d,i-1},t_{i-1}+\tfrac{1}{2}\cdot h)\\ \dot{x}_{i} &:= f(x_i,u_{c,i},u_{d,i},t_i) \end{aligned}$ \\ \hline -\lstinline!"ExplicitRungeKutta4"! & +{\lstinline!"ExplicitRungeKutta4"!} & $\begin{aligned} k_1 &:= h\cdot \dot{x}_{i-1}\\ k_2 &:= h\cdot f(x_{i-1}+\tfrac{1}{2}k_1,\frac{u_{c,i-1}+u_{c,i}}{2},u_{d,i-1},t_{i-1}+\tfrac{1}{2}\cdot h)\\ @@ -1355,8 +1355,8 @@ \section{Other Operators}\label{other-operators} \tablehead{Expression} & \tablehead{Description} & \tablehead{Details}\\ \hline \hline -\lstinline!firstTick($u$)! & Test for first clock tick & \Cref{modelica:firstTick}\\ -\lstinline!interval($u$)! & Interval between previous and present tick & \Cref{modelica:interval}\\ +{\lstinline!firstTick($u$)!} & Test for first clock tick & \Cref{modelica:firstTick}\\ +{\lstinline!interval($u$)!} & Interval between previous and present tick & \Cref{modelica:interval}\\ \hline \end{tabular} \end{center} diff --git a/chapters/syntax.tex b/chapters/syntax.tex index 704f236ec..864bc2fc6 100644 --- a/chapters/syntax.tex +++ b/chapters/syntax.tex @@ -9,10 +9,10 @@ \section{Lexical conventions}\label{lexical-conventions} \tablehead{Syntax} & \tablehead{Description}\\ \hline \hline -\lstinline[language=grammar]![ $\ldots$ ]! & Optional\\ -\lstinline[language=grammar]!{ $\ldots$ }! & Repeat zero or more times\\ -\lstinline[language=grammar]!$\ldots$ | $\ldots$! & Alternatives\\ -\lstinline[language=grammar]!"$\mathit{text}$"! & The $\mathit{text}$ is treated as a single token (no white-space between any characters)\\ +{\lstinline[language=grammar]![ $\ldots$ ]!} & Optional\\ +{\lstinline[language=grammar]!{ $\ldots$ }!} & Repeat zero or more times\\ +{\lstinline[language=grammar]!$\ldots$ | $\ldots$!} & Alternatives\\ +{\lstinline[language=grammar]!"$\mathit{text}$"!} & The $\mathit{text}$ is treated as a single token (no white-space between any characters)\\ \hline \end{tabular} \end{center}