ModelingToolkit.jl icon indicating copy to clipboard operation
ModelingToolkit.jl copied to clipboard

Wonky interface for Dicrete/Continious callbacks when using ModelingToolkit

Open TorkelE opened this issue 2 years ago • 2 comments

When using a ContiniousCallback or a DiscreteCallback you provide a condition function

function condition(u,t,integrator)

end

Here, if you wish to interface the state or the time, it is recommended to use the u vector or the t variable. However, u is a normal vector and cannot be interfaced with MTK variables. Hence, this doesn't work. Instead one have to use the integrator, which poses two problems:

  • According to the doc, interfacing using integrator is worse for performance.
  • It is also kind of awkward to have a function include an argument (u) that is not used.

From an interface point of view, if possible, it seems that the best solution is to make these callbacks work well with only the integrator as an argument to condition.

More generally, it seems that we have all this internal DiffEq code that depend on indexing, which doesn't mesh with the MTK approach or not using indexes. I guess it would be a homogeneous project, but is there any plan to make MTK interfacing universal through the system, instead of relying on converting MTK converting its symbolic to value maps to value arrays of the right order everywhere?

TorkelE avatar Oct 06 '23 14:10 TorkelE

It might be nice to put a small DSL over this.

ChrisRackauckas avatar Oct 06 '23 14:10 ChrisRackauckas

Yeah, that would be a solution

TorkelE avatar Oct 06 '23 14:10 TorkelE