ModelingToolkit.jl
ModelingToolkit.jl copied to clipboard
Feature Request: allow references to integrator `dt` in `ODESystem`, automatically generate callback
As in the title, I'm faced with a problem implementing flux limiters in MethodOfLines where I need to apply a callback step_limiter!(uarr, integrator, p, t)
to handle situations where the timestep dt
appears in a discretization scheme, and therefore in the system of equations.
I will essentially be forced to implement this feature which would need to reuse a lot of MTK code in MOL. I would need to copy much of structural_simplify
to make sure that the callback is applied to the correct elements of uarr
. So in the interests of reuse I request that this feature be allowed to go in MTK.
This would take allowing an additional symbolic argument div
to ODESystem
which will be bound to integrator.dt
on generation of the callback. In the call to ODEProblem
, terms in the equations which contain references to div
will be removed and equations to additively update the correct variables with these terms in the callback will be generated. Of course this adds the restriction that these terms do not contain references to the time derivative, but that is ok for my use case.
Finally, the callback function will be generated, and stored in the ODEProblem
.
How does this sound? Is there a much easier way of achieving the same thing?
I'm happy to implement this, but would appreciate ideas/assistance.
cc @ChrisRackauckas
@YingboMa
I thought we already have something similar for the discrete callback thing. @baggepinnen
The symbolic callbacks are generated based on additional information provided to ODESystem
s and these callbacks have machinery to handle state indices etc. so you might be able to reuse some of that functionality. I can't say that I fully understand all the details of what is discussed here, would you call ODESystem(..., div=symbolic_dt)
where symbolic_dt
is a regular @parameter
that appears in equations, and this parameter is substituted for the integrator time step during solving? The callback appears because the time step is continuously changing?
I'm not sure I understand the issue either, but if it could help @shashi had previously setup the ability to use integrators as part of build_function
constructed callbacks for jump affect functions, see
https://github.com/SciML/ModelingToolkit.jl/blob/490dc28b35c9cc804fc6e79fc892af4ac207d5b9/src/systems/jumps/jumpsystem.jl#L115-L128
@baggepinnen Yes that's exactly right.
I'm not sure I understand the issue either, but if it could help @shashi had previously setup the ability to use integrators as part of
build_function
constructed callbacks for jump affect functions, seehttps://github.com/SciML/ModelingToolkit.jl/blob/490dc28b35c9cc804fc6e79fc892af4ac207d5b9/src/systems/jumps/jumpsystem.jl#L115-L128
If I can make a symbolic integrator, and pass its dt
through ODESystem
to ODEFunction
via ODEProblem
That could work, right?
just add a function on top that passes dt = integrator.dt
in and symbolically generates the function directly on the arguments.