From 46f79ed8cb09851f16e72e1d20a66d26a6df00eb Mon Sep 17 00:00:00 2001 From: Henrik Tidefelt Date: Tue, 3 Nov 2020 00:02:33 +0100 Subject: [PATCH] State solvability requirements for discrete-valued variables According to phone meeting decision on #2639. --- chapters/dae.tex | 69 ++++++++++++++++++++++++++++++------------------ 1 file changed, 43 insertions(+), 26 deletions(-) diff --git a/chapters/dae.tex b/chapters/dae.tex index 8e7b212df..d11530638 100644 --- a/chapters/dae.tex +++ b/chapters/dae.tex @@ -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} @@ -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}). @@ -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}. @@ -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 @@ -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, @@ -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. @@ -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