Skip to content

Commit

Permalink
Adding example, and trying to clarify based on review.
Browse files Browse the repository at this point in the history
  • Loading branch information
HansOlsson committed Mar 16, 2021
1 parent 6d253c1 commit ba837d7
Showing 1 changed file with 21 additions and 3 deletions.
24 changes: 21 additions & 3 deletions chapters/classes.tex
Expand Up @@ -383,9 +383,27 @@ \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.
There may be additional \lstinline!Real! variables that are piecewise constant without being declared as \lstinline!discrete!.
Those additional variables may not be used where a \lstininline!discrete! variable is required, but tools may optimize code to only compute them at events.
For \lstinline!Real! variables we can distinguish two subtly different categories: discrete-time and piecewise constant.
The discrete-time \lstinline!Real! variables must be assigned in a when-clause.
The discrete-time variables can be used as argument to \lstinline!pre!.
The discrete-time variables are a subset of all variables that are piecewise constant and only change at events.
Tools may optimize code to only compute piecewise constant variables at events.

\begin{lstlisting}[language=modelica]
model ShowDiscrete
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 piece-wise constant";
equation
when sample(1,1) then
xd1 = pre(xd1) + 1;
xd2 = pre(xd2) + 1;
end when;
// It is legal to use pre for discrete variable outside of when
xc3 = xd1 + pre(xd2);
// But pre(xc3) would not be legal
end ShowDiscrete;
\end{lstlisting}

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.

Expand Down

0 comments on commit ba837d7

Please sign in to comment.