diff --git a/chapters/classes.tex b/chapters/classes.tex index d79032e2c..1f01e2e63 100644 --- a/chapters/classes.tex +++ b/chapters/classes.tex @@ -383,14 +383,33 @@ \subsection{Component Variability Prefixes discrete, parameter, constant}\label{ definition equations is given in \cref{variability-of-expressions}. \begin{nonnormative} -A discrete-time variable is a piecewise constant signal which -changes its values only at event instants during simulation. Such types -of variables are needed in order that special algorithms, such as the -algorithm of Pantelides for index reduction, can be applied (it must be -known that the time derivative of these variables is identical to zero). -Furthermore, memory requirements can be reduced in the simulation -environment, if it is known that a component can only change at event -instants. +For \lstinline!Real! variables we can distinguish two subtly different categories: discrete-time and piecewise constant, where the discrete-time variables are a subset of all piecewise constant variables. +The \lstinline!Real! variables declared with the prefix \lstinline!discrete! is a subset of the discrete-time \lstinline!Real! variables. +For a \lstinline!Real! variable, being discrete-time is equivalent to being assigned in a when-clause. +A variable used as argument to \lstinline!pre! outside a when-clause must be discrete-time. + +\begin{lstlisting}[language=modelica] +model PiecewiseConstantReals + discrete Real xd1 "Must be assigned in a when-clause, discrete-time"; + Real xd2 "Assigned in a when-clause (below) and thus discrete-time"; + Real xc3 "Not discrete-time, but piecewise constant"; + Real x4 "Piecewise constant, but changes between events"; +equation + when sample(1, 1) then + xd1 = pre(xd1) + 1; + xd2 = pre(xd2) + 1; + end when; + // It is legal to use pre for a discrete-time variable outside of when + xc3 = xd1 + pre(xd2); + // But pre(xc3) would not be legal + x4 = if noEvent(cos(time) > 0.5) then 1.0 else -1.0; +end PiecewiseConstantReals; +\end{lstlisting} + +Tools may optimize code to only compute and store discrete-time variables at events. +Tools may extend that optimization to piece-wise constant variables that only change at events (in the example above \lstinline!xc3!). +As shown above variables can be piecewise constant, but change at times that are not events (in the example above \lstinline!x4!). +It is not clear how a tool could detect and optimize the latter case. A \lstinline!parameter! variable is constant during simulation. This prefix gives the library designer the possibility to express that the physical equations in a library are only valid if some of the used components are constant during simulation. The same also holds for discrete-time and constant variables. Additionally, the \lstinline!parameter! prefix allows a convenient graphical user interface in an experiment environment, to support quick changes of the most important constants of a compiled model. In combination with an if-clause, a \lstinline!parameter! prefix allows removing parts of a model before the symbolic processing of a model takes place in order to avoid variable causalities in the model (similar to \lstinline!#ifdef! in C). Class parameters can be sometimes used as an alternative.