Skip to content

Commit

Permalink
Cleanup related to 'Real'
Browse files Browse the repository at this point in the history
  • Loading branch information
henrikt-ma committed Oct 13, 2020
1 parent 657b9fb commit 24c173d
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 133 deletions.
26 changes: 5 additions & 21 deletions chapters/classes.tex
Expand Up @@ -1566,36 +1566,20 @@ \subsubsection{Unspecified enumeration}\label{unspecified-enumeration}

\subsection{Attributes start, fixed, nominal, and unbounded}\label{attributes-start-fixed-nominal-and-unbounded}

The attributes \lstinline!start! and \lstinline!fixed! define the initial conditions for a
variable. \lstinline!fixed=false! means an initial guess, i.e., value may be
changed by static analyzer. \lstinline!fixed=true! means a required value. The
resulting consistent set of values for \emph{all} model variables is used as
initial values for the analysis to be performed.

The attribute \lstinline!nominal! gives the nominal value for the variable. The user
need not set it even though the standard does not define a default
value. The lack of default allows the tool to propagate the nominal
attribute based on equations, and if there is no value to propagate the
tool should use a non-zero value, it may use additional information
(e.g.\ min-attribute) to find a suitable value, and as last resort use 1.
If \lstinline!unbounded=true! it indicates that the state may grow without
bound, and the error in absolute terms shall be controlled.
The attributes \lstinline!start! and \lstinline!fixed! define the initial conditions for a variable. \lstinline!fixed = false! means an initial guess, i.e., value may be changed by static analyzer. \lstinline!fixed = true! means a required value. The resulting consistent set of values for \emph{all} model variables is used as initial values for the analysis to be performed.

The attribute \lstinline!nominal! gives the nominal value for the variable. The user need not set it even though the standard does not define a default value. The lack of default allows the tool to propagate the nominal attribute based on equations, and if there is no value to propagate the tool should use a non-zero value, it may use additional information (e.g.\ \lstinline!min! attribute) to find a suitable value, and as last resort use 1. If \lstinline!unbounded = true! it indicates that the state may grow without bound, and the error in absolute terms shall be controlled.

\begin{nonnormative}
The nominal value can be used by an analysis tool to determine appropriate tolerances or epsilons, or may be used for scaling. For example,
the tolerance for an integrator could be computed as \lstinline!tol*(abs(nominal)+(if x.unbounded then 0 else abs(x)))!. A default value
is not provided in order that in cases such as \lstinline!a=b!, where \lstinline!b! has a nominal value but not \lstinline!a!, the nominal
value can be propagated to the other variable).
The nominal value can be used by an analysis tool to determine appropriate tolerances or epsilons, or may be used for scaling. For example, the tolerance for an integrator could be computed as \lstinline!tol * (abs(nominal) + (if x.unbounded then 0 else abs(x)))!. A default value is not provided in order that in cases such as \lstinline!a = b!, where \lstinline!b! has a nominal value but not \lstinline!a!, the nominal value can be propagated to the other variable).
\end{nonnormative}


\subsection{Other Predefined Types}\label{other-predefined-types}

\subsubsection{StateSelect}\label{stateselect}

The predefined \lstinline!StateSelect! enumeration type is the type of the
\lstinline!stateSelect! attribute of the \lstinline!Real! type. It is used to explicitly control
state selection.
The predefined \lstinline!StateSelect! enumeration type is the type of the \lstinline!stateSelect! attribute of the \lstinline!Real! type. It is used to explicitly control state selection.

\begin{lstlisting}[language=modelica]
type StateSelect = enumeration(
Expand Down
7 changes: 1 addition & 6 deletions chapters/equations.tex
Expand Up @@ -554,12 +554,7 @@ \section{Events and Synchronization}\label{events-and-synchronization}
crosses zero. At the event instant, the correct if-branch is
selected and the integration is restarted.

Numerical integration methods of order $n$ ($n \geq 1$) require
continuous model equations which are differentiable up to order $n$. This
requirement can be fulfilled if Real elementary relations are not
treated literally but as defined above, because discontinuous changes
can only occur at event instants and no longer during continuous
integration.
Numerical integration methods of order $n$ ($n \geq 1$) require continuous model equations which are differentiable up to order $n$. This requirement can be fulfilled if \lstinline!Real! elementary relations are not treated literally but as defined above, because discontinuous changes can only occur at event instants and no longer during continuous integration.
\end{example}

\begin{nonnormative}
Expand Down
22 changes: 7 additions & 15 deletions chapters/functions.tex
Expand Up @@ -1495,35 +1495,27 @@ \subsection{Partial Derivatives of Functions}\label{partial-derivatives-of-funct
\begin{lstlisting}[language=grammar]
IDENT "=" der "(" name "," IDENT { "," IDENT } ")" comment
\end{lstlisting}
is the partial derivative of a function, and may only be used as
declarations of functions.
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 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).
The comment allows a user to comment the function (in the info-layer and as one-line description, and as icon).

\begin{example}
The specific enthalpy can be computed from a Gibbs-function as follows:
\begin{lstlisting}[language=modelica]
function Gibbs
input Real p,T;
input Real p, T;
output Real g;
algorithm
...
end Gibbs;
function Gibbs_T=der(Gibbs, T);
function Gibbs_T = der(Gibbs, T);
function specificEnthalpy
input Real p,T;
input Real p, T;
output Real h;
algorithm
h:=Gibbs(p,T)-T*Gibbs_T(p,T);
h := Gibbs(p, T) - T * Gibbs_T(p, T);
end specificEnthalpy;
\end{lstlisting}
\end{example}
Expand Down
78 changes: 25 additions & 53 deletions chapters/operatorsandexpressions.tex
Expand Up @@ -251,10 +251,7 @@ \section{Equality, Relational, and Logical Operators}\label{equality-relational-
In relations of the form \lstinline!v1 == v2 or v1 <> v2!,
\lstinline!v1! or \lstinline!v2! shall, unless used in a function, not be a subtype of \lstinline!Real!.
\begin{nonnormative}
The reason for this rule is that relations with \lstinline!Real! arguments are transformed to state events (see Events, \cref{events-and-synchronization})
and this transformation becomes unnecessarily complicated for the \lstinline!==! and \lstinline!<>! relational operators (e.g.\ two crossing functions instead
of one crossing function needed, epsilon strategy needed even at event instants). Furthermore, testing on equality of Real variables is questionable on machines
where the number length in registers is different to number length in main memory.
The reason for this rule is that relations with \lstinline!Real! arguments are transformed to state events (see Events, \cref{events-and-synchronization}) and this transformation becomes unnecessarily complicated for the \lstinline!==! and \lstinline!<>! relational operators (e.g.\ two crossing functions instead of one crossing function needed, epsilon strategy needed even at event instants). Furthermore, testing on equality of \lstinline!Real! variables is questionable on machines where the number length in registers is different to number length in main memory.
\end{nonnormative}
\item
Relational operators can generate events, see \cref{discrete-time-expressions}.
Expand Down Expand Up @@ -821,28 +818,14 @@ \subsubsection{spatialDistribution}\label{spatialdistribution}
initialPoints = {0.0, 1.0},
initialValues = {0.0, 0.0});
\end{lstlisting}
where \lstinline!in0!, \lstinline!in1!, \lstinline!out0!, \lstinline!out1!, \lstinline!x!, \lstinline!v! are all subtypes of Real,
\lstinline!positiveVelocity! is a Boolean, \lstinline!initialPoints! and \lstinline!initialValues! are
arrays of subtypes of Real of equal size, containing the y coordinates
and the $z$ values of a finite set of points describing the initial
distribution of $z(y, \mathit{t0})$. The \lstinline!out0! and \lstinline!out1! are given by
the solutions at $z(0.0, t)$ and $z(1.0, t)$; and \lstinline!in0! and \lstinline!in1!
are the boundary conditions at $z(0.0, t)$ and $z(1.0, t)$ (at
each point in time only one of in0 and in1 is used). Elements in the
initialPoints array must be sorted in non-descending order. The operator
can not be vectorized according to the vectorization rules described in
\cref{scalar-functions-applied-to-array-arguments}. The operator can be vectorized only with respect to the
arguments in0 and in1 (which must have the same size), returning
vectorized outputs out0 and out1 of the same size; the arguments
initialPoints and initialValues are vectorized accordingly.
where \lstinline!in0!, \lstinline!in1!, \lstinline!out0!, \lstinline!out1!, \lstinline!x!, \lstinline!v! are all subtypes of \lstinline!Real!, \lstinline!positiveVelocity! is a \lstinline!Boolean!, \lstinline!initialPoints! and \lstinline!initialValues! are arrays of subtypes of \lstinline!Real! of equal size, containing the y coordinates and the $z$ values of a finite set of points describing the initial distribution of $z(y, \mathit{t0})$. The \lstinline!out0! and \lstinline!out1! are given by the solutions at $z(0.0, t)$ and $z(1.0, t)$; and \lstinline!in0! and \lstinline!in1! are the boundary conditions at $z(0.0, t)$ and $z(1.0, t)$ (at each point in time only one of in0 and in1 is used). Elements in the initialPoints array must be sorted in non-descending order. The operator can not be vectorized according to the vectorization rules described in \cref{scalar-functions-applied-to-array-arguments}. The operator can be vectorized only with respect to the arguments in0 and in1 (which must have the same size), returning vectorized outputs out0 and out1 of the same size; the arguments initialPoints and initialValues are vectorized accordingly.

The solution, $z$, can be described in terms of characteristics:
\begin{equation*}
z(y+\int_{t}^{t+\beta} v(\alpha) \mathrm{d}\alpha, t+\beta) = z(y, t),\quad\text{for all $\beta$ as long as staying inside the domain}
\end{equation*}

This allows the direct computation of the solution based on interpolating the
boundary conditions.
This allows the direct computation of the solution based on interpolating the boundary conditions.

\lstinline!spatialDistribution! can be described in terms of the pseudo-code given as a block:
\begin{lstlisting}[language=modelica]
Expand All @@ -862,65 +845,54 @@ \subsubsection{spatialDistribution}\label{spatialdistribution}
Integer m;
algorithm
if positiveVelocity then
out1:=interpolate(points, values, 1-(x-x0));
out0:=values[1]; // similar to in0 but avoiding algebraic loop
out1 := interpolate(points, values, 1-(x-x0));
out0 := values[1]; // similar to in0 but avoiding algebraic loop
else
out0:=interpolate(points, values, 0-(x-x0));
out1:=values[end]; // similar to in1 but avoiding algebraic loop
out0 := interpolate(points, values, 0-(x-x0));
out1 := values[end]; // similar to in1 but avoiding algebraic loop
end if;
when <acceptedStep> then
if x>x0 then
m:=size(points,1);
m := size(points, 1);
while (if m>0 then points[m]+(x-x0)>=1 else false) then
m:=m-1;
m := m-1;
end while;
values:=cat(1, {in0}, values[1:m], {interpolate(points, values,1-(x-x0))} );
points:=cat(1, {0}, points[1:m] .+ (x-x0), {1} );
values := cat(1, {in0}, values[1:m], {interpolate(points, values,1-(x-x0))});
points := cat(1, {0}, points[1:m] .+ (x-x0), {1});
elseif x<x0 then
m:=1;
while (if m<size(points,1) then points[m]+(x-x0)<=0 else false) then
m:=m+1;
m := 1;
while (if m < size(points, 1) then points[m] + (x - x0) <= 0 else false) then
m := m+1;
end while;
values:=cat(1, {interpolate(points, values, 0-(x-x0))},values[m:end],{in1});
points:=cat(1, {0}, points[m:end] .+ (x-x0), {1});
values := cat(1, {interpolate(points, values, 0 - (x - x0))}, values[m:end], {in1});
points := cat(1, {0}, points[m:end] .+ (x-x0), {1});
end if;
x0:=x;
x0 := x;
end when;
initial algorithm
x0:=x;
points:=initialPoints;
values:=initialValues;
x0 := x;
points := initialPoints;
values := initialValues;
end spatialDistribution;
\end{lstlisting}

\begin{nonnormative}
Note that the implementation has an internal state and thus
cannot be described as a function in Modelica; initialPoints and
initialValues are declared as parameters to indicate that they are only
used during initialization.
Note that the implementation has an internal state and thus cannot be described as a function in Modelica; \lstinline!initialPoints! and \lstinline!initialValues! are declared as parameters to indicate that they are only used during initialization.

The infinite-dimensional problem stated above can then be formulated in the following way:
\begin{lstlisting}[language=modelica]
der(x) = v;
(out0, out1) = spatialDistribution(in0, in1, x, v >=0, initialPoints, initialValues);
(out0, out1) = spatialDistribution(in0, in1, x, v >= 0, initialPoints, initialValues);
\end{lstlisting}

Events are generated at the exact instants when the velocity
changes sign -- if this is not needed, \lstinline!noEvent! can be used to
suppress event generation.
Events are generated at the exact instants when the velocity changes sign -- if this is not needed, \lstinline!noEvent! can be used to suppress event generation.

If the velocity is known to be always positive, then \lstinline!out0! can be omitted, e.g.:
\begin{lstlisting}[language=modelica]
der(x) = v;
(,out1) = spatialDistribution(in0, 0, x, true, initialPoints, initialValues);
\end{lstlisting}
Technically relevant use cases for the use of
\lstinline!spatialDistribution! are modeling of electrical
transmission lines, pipelines and pipeline networks for gas, water and
district heating, sprinkler systems, impulse propagation in elongated
bodies, conveyor belts, and hydraulic systems. Vectorization is needed
for pipelines where more than one quantity is transported with velocity
v in the example above.
Technically relevant use cases for the use of \lstinline!spatialDistribution! are modeling of electrical transmission lines, pipelines and pipeline networks for gas, water and district heating, sprinkler systems, impulse propagation in elongated bodies, conveyor belts, and hydraulic systems. Vectorization is needed for pipelines where more than one quantity is transported with velocity \lstinline!v! in the example above.
\end{nonnormative}

\subsubsection{cardinality (deprecated)}\label{cardinality-deprecated}
Expand Down Expand Up @@ -1254,7 +1226,7 @@ \subsection{Event-Related Operators with Function Syntax}\label{event-related-op
noEvent($\mathit{expr}$)
\end{lstlisting}\end{synopsis}
\begin{semantics}
Real elementary relations within $\mathit{expr}$ are taken literally, i.e., no state or time event is triggered. No zero crossing functions shall be used to monitor any of the normally event-generating subexpressions inside $\mathit{expr}$. See also \crefnameref{modelica:smooth} and \cref{events-and-synchronization}.
\lstinline!Real! elementary relations within $\mathit{expr}$ are taken literally, i.e., no state or time event is triggered. No zero crossing functions shall be used to monitor any of the normally event-generating subexpressions inside $\mathit{expr}$. See also \crefnameref{modelica:smooth} and \cref{events-and-synchronization}.
\end{semantics}
\end{operatordefinition}

Expand Down

0 comments on commit 24c173d

Please sign in to comment.