forked from modelica/ModelicaSpecification
-
Notifications
You must be signed in to change notification settings - Fork 2
/
dae.tex
157 lines (141 loc) · 7.82 KB
/
dae.tex
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
\chapter{Modelica DAE Representation}\label{modelica-dae-representation}
In this appendix, the mapping of a Modelica model into an appropriate
mathematical description form is discussed.
In a first step, a Modelica translator transforms a hierarchical
Modelica simulation model into a ``flat'' set of Modelica
``statements'', consisting of the equation and algorithm sections of all
used components by:
\begin{itemize}
\item
Expanding all class definitions (flattening the inheritance tree) and
adding the equations and assignment statements of the expanded classes
for every instance of the model.
\item
Replacing all connect-equations by the corresponding equations of the
connection set (see \cref{generation-of-connection-equations}).
\item
Mapping all algorithm sections to equation sets.
\item
Mapping all when-clauses to equation sets (see \cref{when-equations}).
\end{itemize}
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$):
\begin{subequations}
\begin{equation}\label{eq:crossing}
c := f_{\mathrm{c}}(\mathit{relation}(v))
\end{equation}
\begin{equation}
m := f_{\mathrm{m}}(v, c)
\end{equation}
\begin{equation}\label{eq:dae}
0 = f_{\mathrm{x}}(v, c)
\end{equation}
\label{eq:hydrid-dae}
\end{subequations}
and where
\begin{itemize}
\item $p$:
Modelica variables declared as \lstinline!parameter! or \lstinline!constant!, i.e., variables without any time-dependency.
\item $t$:
Modelica variable \lstinline!time!, the independent (real) variable.
\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).
\item $c(t_{\mathrm{e}})$:
The conditions of all if-expressions generated including when-clauses after conversion, see \cref{when-equations}).
\item $\mathit{relation}(v)$:
A relation containing variables $v_{i}$, e.g.\ $v_{1} > v_{2}$, $v_{3} \geq 0$.
\end{itemize}
For simplicity, the special cases of \lstinline!noEvent! and \lstinline!reinit! are not contained in the equations
above and are not discussed below.
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}.
The equations define a DAE (Differential Algebraic Equations) which may
have discontinuities, a variable structure and/or which are controlled
by a discrete-event system. Such types of systems are called
\emph{hybrid DAEs}. Simulation is performed in the following way:
\begin{enumerate}
\item
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 variables $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
During integration, all relations from \eqref{eq:crossing} are monitored. If one of
the relations changes its value an event is triggered, i.e., the exact
time instant of the change is determined and the integration is
halted. As discussed in \cref{events-and-synchronization}, relations which depend only on
time are usually treated in a special way, because this allows to
determine the time instant of the next event in advance.
\item
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.
\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
an event instant and that these variables remain constant during
continuous integration. At every event instant, new values of the
discrete variables $m$ and of new initial values for the states $x$ are
determined. The change of discrete 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,
algebraic variables and residue equations of a DAE may change at event
instants by disabling the appropriate part of the DAE. For clarity of
the equations, this is not explicitly shown by an additional index in
\eqref{eq:hydrid-dae}.
At an event instant, including the initial event, the model equations
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
// pre(m) = value of m before event occured
loop
solve (1) for the unknowns, with pre(m) fixed
if m == pre(m) then break
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.
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.
Therefore, direct simulation of \eqref{eq:hydrid-dae} requires sparse matrix methods.
However, solving this initial set of equations directly with a numerical
method is both unreliable and inefficient. One reason is that many
Modelica models, like the mechanical ones, have a DAE index of 2 or 3,
i.e., the overall number of states of the model is less than the sum of
the states of the sub-components. In such a case, every direct numerical
method has the difficulty that the numerical condition becomes worse, if
the integrator step size is reduced and that a step size of zero leads
to a singularity. Another problem is the handling of idealized elements,
such as ideal diodes or Coulomb friction. These elements lead to mixed
systems of equations having both Real and Boolean unknowns. Specialized
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
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
algorithms, can be used to solve \eqref{eq:dae}, after the index of \eqref{eq:dae} has been
reduced by the Pantelides algorithm: During continuous integration, the
integrator provides $x$ and $t$. Then, \eqref{eq:dae} is a linear or nonlinear system
of equations to compute the algebraic variables $y$ and the state
% TODO: Structured formatting of inline "upright 'd' fraction".
derivatives $\mathrm{d}x/\mathrm{d}t$ and the model returns $\mathrm{d}x/\mathrm{d}t$ to the integrator by
solving these systems of equations. Often, \eqref{eq:dae} is just a linear system
of equations in these unknowns, so that the solution is straightforward.
This procedure is especially useful for real-time simulation where
usually explicit one-step methods are used.