-
-
Notifications
You must be signed in to change notification settings - Fork 232
Include root-finding equations in ODESystem
#1337
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
Conversation
RuntimeGeneratedFunction handles arbitrary functions without closures in-place or not. Try to read |
ODESystem
ODESystem
And catch `root_eqs` in the constructor for NonlinearSystem`
I changed the implementation to use |
After offline discussions, it was decided that we should add The remaining step is to allow symbolic affect expressions that are automatically compiled to an |
One can now model events including effects like so ## Test bouncing ball with equation affect
@variables t x(t)=1 v(t)=0
D = Differential(t)
root_eqs = [x ~ 0]
affect = [v ~ -v]
@named ball = ODESystem([
D(x) ~ v
D(v) ~ -9.8
], t, events = root_eqs => affect)
ball = structural_simplify(ball)
tspan = (0.0,5.0)
prob = ODEProblem(ball, Pair[], tspan)
sol = solve(prob,Tsit5())
@test 0 <= minimum(sol[x]) <= 1e-10 # the ball never went through the floor but got very close
plot(sol) some restrictions apply on the |
While we're at it, to finish #38 we should have a way of designating an event condition in the discrete sense as well. |
Could the symbolic conditions and affects be stored in the current continuous and discrete callbacks provided by DiffEqBase? It might be nice to reuse those structures since users are already familiar with them. |
Such callbacks are generated internally and are available through the created |
I meant that users create and pass the symbolic callbacks using the same structures (but built with symbolic equations), and use |
@baggepinnen we should at least thing of the naming scheme so that way the next PR isn't immediately breaking. Is it |
|
Sounds reasonable to me. Yeah, let's get that together and merge, and then follow up with the discrete. |
Could you add a test with multiple affects for a given condition? i.e. changing more than one variable? |
also renames the kwarg to `continuous_events`
How is this working when a system with an event is used as a subsystem in another system? Where is it appropriately renamespacing the events? |
There is a test that the event equations have been renamespaced here and there is a method to renamespace events here |
Missed it thanks. |
callbacks = map(cbs) do eq_aff | ||
generate_rootfinding_callback(eq_aff, sys, dvs, ps; kwargs...) | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you map here, won't it not fuse into a single VectorContinuousCallback?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It only returns VectorContinuousCallback
if there is an event with multiple equations. If there are several events, they are treated as separate callbacks. So this kind of event leads to VectorContinuousCallback
https://github.com/SciML/ModelingToolkit.jl/pull/1337/files#diff-4ff6b77a6fa947c70cfd3bcaf373b11d61ad04f2f1a74022ea9250e386459f74R194
while this kind
https://github.com/SciML/ModelingToolkit.jl/pull/1337/files#diff-4ff6b77a6fa947c70cfd3bcaf373b11d61ad04f2f1a74022ea9250e386459f74R132-R133
leads to a CallbackSet.
I kept them apart in order to make the following check
https://github.com/SciML/ModelingToolkit.jl/pull/1337/files#diff-7195a73d9d71f7a993fe71086614d700629ebc22306be7b602f60fbc054bcdb7R219-R220
I couldn't prove for myself that there couldn't be bad outcomes from having one state affected by multiple equations in the same event since the ordering of the affect equations would then matter etc.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How do you make a VectorContinuousCallback which have a different affect based on the condition that is fired? Why not fuse anyways since it's more efficient?
@YingboMa you got anything else? |
LGTM |
Cool stuff. Any chance it could be expanded to cover |
This PR adds a vector of equations to an
ODESystem
that can be used for root-finding when solving anODEProblem
.The intended usage is to specify such equations when an ODESystem is created rather than when the
ODEProblem
is created, for example, when a component in a component library contains discountinous dynamics etc.The provided tests pass locally, but there are a number of points I would like to get feedback on
root_eqs
field was added toODESystem
only, how should all otherAbstractSystems
be treated?VectorContinuousCallback
here, can theRuntimeGeneratedFunction
somehow be generated in an inplace form as well?Fixes #38