ModelingToolkit.jl
ModelingToolkit.jl copied to clipboard
No documented way to set rootfind=RightRootFind in continuous Event.
In DifferentialEquations.jl one can specify the rootfind option:
ContinuousCallback(condition,affect!,affect_neg!;
initialize = INITIALIZE_DEFAULT,
finalize = FINALIZE_DEFAULT,
idxs = nothing,
rootfind=LeftRootFind,
save_positions=(true,true),
interp_points=10,
abstol=10eps(),reltol=0,repeat_nudge=1//100)
In ModelingToolkit.jl it is not obvious how to do the same. Now I'm using the workaround, that I use the differentialequations.jl callback interface for setting rootfind=RightRootFind. But it would be nice to use the symbolic interface from ModelingToolkit.jl.
Good point, we should add that. It wouldn't be hard.
Generally the symbolic events are missing a lot of the normal event features. There is another issue about directionality for continuous events that @paulflang wanted for SBML model support, and for discrete events it would be nice to have a way to include symbolic tstops
involving parameter expressions with the event (i.e. that get forwarded along and handled appropriately in the solvers, so one doesn't have to manually specify them).
Thanks @isaacsas . Linking the issue here: #1715
Inspired of your "good first issue" tag, I have a first working example for this issue. In this I only give the to parameters I need to the continous event:
continuous_events = [ (([ϕ1-ϕ2~0] => (affect!, [ϕ1,ϕ2,ϕ3,ϕ4],[Rd1,Rd2,Rd3,Rd4], 1)) =>[SciMLBase.RightRootFind,20])
(([ϕ4-ϕ2~0] => (affect!, [ϕ1,ϕ2,ϕ3,ϕ4],[Rd1,Rd2,Rd3,Rd4], 2)) =>[SciMLBase.RightRootFind,20])
(([-ϕ1~0] => (affect!, [ϕ1,ϕ2,ϕ3,ϕ4],[Rd1,Rd2,Rd3,Rd4], 3)) =>[SciMLBase.RightRootFind,20])
(([-ϕ4~0] => (affect!, [ϕ1,ϕ2,ϕ3,ϕ4],[Rd1,Rd2,Rd3,Rd4], 4)) =>[SciMLBase.RightRootFind,20])]
Which is the rootfind-option and the interp_points-option.
Since the options are only given once to the VectorContinuousCallback function, it makes of course no sense to give the options for every single callback. So this in mind and to have a more general solution, the question is now, what to do. Maybe something like this:
continuous_events = [ ([ϕ1-ϕ2~0] => (affect!, [ϕ1,ϕ2,ϕ3,ϕ4],[Rd1,Rd2,Rd3,Rd4], 1))
([ϕ4-ϕ2~0] => (affect!, [ϕ1,ϕ2,ϕ3,ϕ4],[Rd1,Rd2,Rd3,Rd4], 2))
([-ϕ1~0] => (affect!, [ϕ1,ϕ2,ϕ3,ϕ4],[Rd1,Rd2,Rd3,Rd4], 3))
([-ϕ4~0] => (affect!, [ϕ1,ϕ2,ϕ3,ϕ4],[Rd1,Rd2,Rd3,Rd4], 4))] =>["rootfind"=>SciMLBase.RightRootFind,"interp_points"=>20]
Or are there better possibilities?
PS.: Another question rised on the way. I use want to use a discrete event that fires at a time which is set by the continous events resp. the affect! function. In the differentialequations.jl implementation I used a global variable to handover the time and then call the same affect! function. But since I can't define a condition function manually for the discrete event, I can't do that anymore. And I can also not mix a differentialequations.jl discrete callback with continous events since the affect! wont work anymore because of the missing symbolic definitions.
PPS.: What I described last doesn't really matter because I can do want I want with another way. But maybe it is interesting despite that to have a alternative way to define the condition function manually.
This seems like it ended up being a more difficult issue than I imagined.
https://github.com/SciML/ModelingToolkit.jl/issues/2225 is related.
https://github.com/SciML/ModelingToolkit.jl/pull/2911 should handle this now?
It should, yes.