Description
I'm gradually learning to use MTK by converting some examples I have from Modelica to MTK. It is great fun (:grinning:). As part of this, I'd like to understand what I'm doing (:open_mouth:); I'm not reporting any issues -- it is more to get some clarification from more experienced users...
Below, I attempt to describe my understanding in sections 1. Variables and equations, 2. Model and index reduction. Observables, and 3. MTK vs. Modelica. I close with 4. Questions. Sorry for the lengthy/wordy/technical post.
Variables and equations
I define my independent variable t
as well as dependent variables which I will refer to as unknowns, let us denote them
@variables t υ(t)
I have "cheated" in that there can be many unknowns.
My model will also have a number of externally driving "force" functions @register_symbolic
macro:
@register_symbolic ϕ(t)
Again, I'm simplifying: I need one line of register_symbolic
for each element in
I finally write my equations:
D = Differential(t)
eqs = [ D(υ) .~ F(υ, ϕ(t)) ;
G(υ, ϕ(t)) .~ 0]
where the equation is meant to be a vector of equations.
Model and Index reduction. Observables
With the above, I create the model as:
mod = ODESystem(eqs)
I then simplify the structure of the model, including index reduction to a DAE of index 0 (= ODE), or a DAE of index 1 using function structural_simplify
:
mod_simp = structural_simplify(mod)
The resulting simplified model has the generic form:
$$
\frac{d \varsigma}{d t} = f\left(\varsigma,\bar{\varsigma},\phi(t)\right) \
0 = g\left(\varsigma, \bar{\varsigma}, \phi(t) \right)
$$
If the result is an index 0 DAE (= ODE), then
In MTK, the state
Initial value for mod_simp
to a numeric model using ODEProblem()
, which is then solved.
If we go back to unknowns
$$
\omega = h(\sigma, \phi(t))
$$
The observables
MTK vs. Modelica
Modelica tools do something similar to what MTK does wrt. structural simplification, but normally under the hood.
In principle, it is sufficient to provide initial values for
$$
\frac{d \varsigma}{d t} = f\left(\varsigma,\bar{\varsigma},\phi(t)\right) \
0 = g\left(\varsigma, \bar{\varsigma}, \phi(t) \right)
$$
With value for
In practice, this is slightly more complicated in that the algebraic constraint may admit multiple solutions.
Modelica
In Modelica, it is sufficient to provide initial value for fixed = true
), or meant to be an approximate guess (attribute fixed = false
) -- attribute fixed
can be used for both
In practice, it may be necessary to provide initial guesses for
In principle, I guess, all initial values can be specified as fixed = false
, and then Modelica uses some least squares algorithm to make sure that the algebraic contraint
MTK
As far as I understand it, the user has to specify initial values for all of
What is not clear to me is whether
Questions
- Is there anything wrong in my "understanding" of the operation of MTK? [Probably...]
- For index 1 DAEs, is it required to use an ODE solver that supports mass matrix? [...when I convert it to an
ODESystem
...] - Is there a list of ODE solvers with support for mass matrix?
- The initial state (
$\sigma$ in my notation...) -- is it required that the algebraic constraints ($0 = g(\sigma, \phi(t))$ are satisfied exactly?