Skip to content

Commit

Permalink
State solvability requirements for discrete-valued variables
Browse files Browse the repository at this point in the history
According to phone meeting decision on #2639.
  • Loading branch information
henrikt-ma committed Nov 2, 2020
1 parent de55f8b commit 46f79ed
Showing 1 changed file with 43 additions and 26 deletions.
69 changes: 43 additions & 26 deletions chapters/dae.tex
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,19 @@ \chapter{Modelica DAE Representation}\label{modelica-dae-representation}

As a result of this transformation process, a set of equations is
obtained consisting of differential, algebraic and discrete equations of
the following form where ($v := \lbrack \dot{x}; x; y; t; m; \text{\lstinline!pre!}(m); p\rbrack$):
the following form where ($v := \lbrack p; t; \dot{x}; x; y; z; m; \text{\lstinline!pre!}(z); \text{\lstinline!pre!}(m)\rbrack$):
\begin{subequations}
\begin{equation}\label{eq:crossing}
c := f_{\mathrm{c}}(\mathit{relation}(v))
\begin{equation}\label{eq:dae}
0 = f_{\mathrm{x}}(v, c)
\end{equation}
\begin{equation}\label{eq:dae-discrete-real}
0 = f_{\mathrm{z}}(v, c)
\end{equation}
\begin{equation}
\begin{equation}\label{eq:dae-discrete-valued}
m := f_{\mathrm{m}}(v, c)
\end{equation}
\begin{equation}\label{eq:dae}
0 = f_{\mathrm{x}}(v, c)
\begin{equation}\label{eq:crossing}
c := f_{\mathrm{c}}(\mathit{relation}(v))
\end{equation}
\label{eq:hydrid-dae}
\end{subequations}
Expand All @@ -47,11 +50,14 @@ \chapter{Modelica DAE Representation}\label{modelica-dae-representation}
\item $x(t)$:
Modelica variables of type \lstinline!Real!, appearing differentiated.

\item $m(t_{\mathrm{e}})$:
Modelica variables of type \lstinline!discrete Real!, \lstinline!Boolean!, \lstinline!Integer! which are unknown. These variables change their value only at event instants t\textsubscript{e}. \lstinline!pre(m)! are the values of $m$ immediately before the current event occurred.

\item $y(t)$:
Modelica variables of type \lstinline!Real! which do not fall into any other category (= algebraic variables).
Continuous-time modelica variables of type \lstinline!Real! that do not appear differentiated (= algebraic variables).

\item $z(t_{\mathrm{e}})$:
Discrete-time modelica variables of type \lstinline!Real!. These variables change their value only at event instants $t_{\mathrm{e}}$. \lstinline!pre(z)! are the values of $z$ immediately before the current event occurred.

\item $m(t_{\mathrm{e}})$:
Modelica variables of discrete-valued types (\lstinline!Boolean!, \lstinline!Integer!, etc) which are unknown. These variables change their value only at event instants $t_{\mathrm{e}}$. \lstinline!pre(m)! are the values of $m$ immediately before the current event occurred.

\item $c(t_{\mathrm{e}})$:
The conditions of all if-expressions generated including when-clauses after conversion, see \cref{when-equations}).
Expand All @@ -63,6 +69,21 @@ \chapter{Modelica DAE Representation}\label{modelica-dae-representation}
For simplicity, the special cases of \lstinline!noEvent! and \lstinline!reinit! are not contained in the equations
above and are not discussed below.

The key difference between the two groups of discrete-time variables $z$ and and $m$ here is how they are determined. The interpretation of the solved form of \eqref{eq:dae-discrete-valued} is that given values for everything else, there is a closed-form solution for $m$ in the form of a sequence of assignments to each of the variables of $m$ in turn -- there must be no cyclic dependencies between the equations used to solve for $m$. Further, each of the original model equations behind \eqref{eq:dae-discrete-valued} must be given in solved form, at most requiring flipping sides of the equation to obtain the used assignment form. The interpretation of the non-solved form of \eqref{eq:dae-discrete-real}, on the other hand, is that at events, the discrete-time \lstinline!Real! variables $z$ are solved together with the continuous-time variables using \eqref{eq:dae-discrete-real} and \eqref{eq:dae}.

\begin{example}
The following model is illegal since there is no equation in solved form that can be used in \eqref{eq:dae-discrete-valued} to solve for the discrete-valued variable \lstinline!y!:
\begin{lstlisting}[language=modelica]
model M
Boolean x;
Boolean y;
equation
x = time >= 1.0;
not y = x; /* Equation in solved form, but not with respect to y. */
end M;
\end{lstlisting}
\end{example}

The generated set of equations is used for simulation and other analysis
activities. Simulation means that an initial value problem is solved,
i.e., initial values have to be provided for the states $x$, \cref{initialization-initial-equation-and-initial-algorithm}.
Expand All @@ -71,10 +92,10 @@ \chapter{Modelica DAE Representation}\label{modelica-dae-representation}
by a discrete-event system. Such types of systems are called
\emph{hybrid DAEs}. Simulation is performed in the following way:
\begin{enumerate}
\item
\item\label{perform-simulation-integrate}
The DAE \eqref{eq:dae} is solved by a numerical integration method. In this
phase the conditions $c$ of the if- and when-clauses, as well as the
discrete-time variables $m$ are kept constant. Therefore, \eqref{eq:dae} is a
discrete-time variables $z$ and $m$ are kept constant. Therefore, \eqref{eq:dae} is a
continuous function of continuous variables and the most basic
requirement of numerical integrators is fulfilled.
\item
Expand All @@ -88,14 +109,14 @@ \chapter{Modelica DAE Representation}\label{modelica-dae-representation}
At an event instant, \eqref{eq:hydrid-dae} is a mixed set of algebraic equations which
is solved for the Real, Boolean and Integer unknowns.
\item
After an event is processed, the integration is restarted with 1.
After an event is processed, the integration is restarted with \ref{perform-simulation-integrate}.
\end{enumerate}

Note, that both the values of the conditions $c$ as well as the values of
$m$ (all \lstinline!discrete Real!, \lstinline!Boolean! and \lstinline!Integer! variables) are only changed at
$z$ and $m$ (all discrete-time \lstinline!Real!, \lstinline!Boolean! and \lstinline!Integer! variables) are only changed at
an event instant and that these variables remain constant during
continuous integration. At every event instant, new values of the
discrete-time variables $m$ and of new initial values for the states $x$ are
discrete-time variables $z$ and $m$, as well as of new initial values for the states $x$, are
determined. The change of discrete-time variables may characterize a new
structure of a DAE where elements of the state vector $x$ are
\emph{disabled}. In other words, the number of state variables,
Expand All @@ -108,22 +129,18 @@ \chapter{Modelica DAE Representation}\label{modelica-dae-representation}
are reinitialized according to the following iteration procedure:
\begin{lstlisting}[language=modelica]
known variables: x, t, p
unkown variables: dx/dt, y, m, pre(m), c
unkown variables: dx/dt, y, z, m, pre(z), pre(m), c

// pre(z) = value of z before event occured
// pre(m) = value of m before event occured
loop
solve (1) for the unknowns, with pre(m) fixed
if m == pre(m) then break
solve (1) for the unknowns, with pre(z) and pre(m) fixed
if z == pre(z) and m == pre(m) then break
pre(z) := z
pre(m) := m
end loop
\end{lstlisting}
Solving \eqref{eq:hydrid-dae} for the unknowns is non-trivial, because this set of
equations contains not only Real, but also Boolean and Integer unknowns.
Usually, in a first step these equations are sorted and in many cases
the Boolean and Integer unknowns can be just computed by a forward
evaluation sequence. In some cases, there remain systems of equations
(e.g.\ for ideal diodes, Coulomb friction elements) and specialized
algorithms have to be used to solve them.
Solving \eqref{eq:hydrid-dae} for the unknowns is non-trivial, because this set of equations contains not only \lstinline!Real!, but also discrete-valued unknowns. Usually, in a first step these equations are sorted and in many cases the discrete-valued unknowns $m$ can be just computed by a forward evaluation sequence. In some cases, there remain systems of equations involving $m$ due to cyclic dependencies with $y$ and $z$ (e.g.\ for ideal diodes, Coulomb friction elements), and specialized algorithms have to be used to solve them.

Due to the construction of the equations by \emph{flattening} a Modelica
model, the hybrid DAE \eqref{eq:hydrid-dae} contains a huge number of sparse equations.
Expand All @@ -141,7 +158,7 @@ \chapter{Modelica DAE Representation}\label{modelica-dae-representation}
algorithms are needed to solve such systems.

To summarize, symbolic transformation techniques are needed to transform
(1) in a set of equations which can be numerically solved reliably. Most
\eqref{eq:hydrid-dae} into a set of equations which can be numerically solved reliably. Most
important, the algorithm of Pantelides should to be applied to
differentiate certain parts of the equations in order to reduce the
index. Note, that also explicit integration methods, such as Runge-Kutta
Expand Down

0 comments on commit 46f79ed

Please sign in to comment.