How does structural_simplify work?

The function structural_simplify() of the package ModelingToolkit can reduce the number of equations of a DAE a lot, often by 80%.

But how does this actually work?

  • does the order of the DAE stays the same?
  • does it introduce new variables to replace expressions in the original DAE system?

Any hints welcome!

This presentation should be a good intro

2 Likes

Thanks for sharing. But the presentation was written for Modelica, and Modelica is generating C code. Is MTK generating Julia code?

MTK and modelica work in very similar ways

yes.

1 Like

And is it possible to see or to print this code?

Kind-of, if you have generated a prob = ODEProblem(...), you can look at prof.f or prof.f.f or something like that, it’s in there somewhere.

1 Like

I like the introduction to the topic in Cellier, François E., and Ernesto Kofman. Continuous System Simulation. Softcover reprint of hardcover 1st ed. 2006. New York, NY: Springer, 2010. Continuous System Simulation | SpringerLink. In particular the chapter 7. Check it out, I guess you may have an institutional subscription.

Thanks a lot, I can access this book.

I get:

julia> prob.f
(::ODEFunction{true, SciMLBase.AutoSpecialize, ModelingToolkit.var"#f#815"{RuntimeGeneratedFunctions.RuntimeGeneratedFunction{(:ËŤâ‚‹arg1, :t), ModelingToolkit.var"#_RGF_ModTag", ModelingToolkit.var"#_RGF_ModTag", (0xe6756fb3, 0x73b9ba2c, 0x45942c73, 0x8ef0d825, 0xf7df8f64), Nothing}, RuntimeGeneratedFunctions.RuntimeGeneratedFunction{(:ËŤâ‚‹out, :ËŤâ‚‹arg1, :t), ModelingToolkit.var"#_RGF_ModTag", ModelingToolkit.var"#_RGF_ModTag", (0x5201bd46, 0xaaa9ab4a, 0x28da1c62, 0x57e60ec5, 0x99d2b9c2), Nothing}}, LinearAlgebra.UniformScaling{Bool}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, ModelingToolkit.ObservedFunctionCache{ODESystem}, Nothing, ODESystem, Nothing, Nothing}) (generic function with 1 method)

Is this Julia code? Can it be formatted nicer?

To see just the generated function code, you can create the ODEProblem and look at prob.f.f.f_oop for the out-of-place version or prob.f.f.f_iip for the in-place version.

You can see the whole expression to create the ODEProblem with

ODEProblemExpr(ode_system, u0, tspan)
1 Like