Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No documented way to set rootfind=RightRootFind in continuous Event. #2351

Closed
HKruenaegel opened this issue Nov 12, 2023 · 8 comments
Closed

Comments

@HKruenaegel
Copy link

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.

@ChrisRackauckas
Copy link
Member

Good point, we should add that. It wouldn't be hard.

@ChrisRackauckas ChrisRackauckas added the good first issue Good for newcomers label Nov 12, 2023
@isaacsas
Copy link
Member

isaacsas commented Nov 12, 2023

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).

@paulflang
Copy link
Member

Thanks @isaacsas . Linking the issue here: #1715

@HKruenaegel
Copy link
Author

HKruenaegel commented Nov 18, 2023

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.

@ChrisRackauckas
Copy link
Member

This seems like it ended up being a more difficult issue than I imagined.

@ChrisRackauckas ChrisRackauckas removed the good first issue Good for newcomers label Dec 27, 2023
@ChrisRackauckas
Copy link
Member

#2225 is related.

@isaacsas
Copy link
Member

isaacsas commented Aug 5, 2024

#2911 should handle this now?

@BenChung
Copy link
Contributor

BenChung commented Aug 5, 2024

It should, yes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants