-
-
Notifications
You must be signed in to change notification settings - Fork 260
Implement Discontinuity Detection Algorithm #3121
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
Open
Shreyas-Ekanathan
wants to merge
29
commits into
SciML:master
Choose a base branch
from
Shreyas-Ekanathan:fresh-disco
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
29 commits
Select commit
Hold shift + click to select a range
2aa615c
add disco to core
Shreyas-Ekanathan f485bdc
radau version
Shreyas-Ekanathan cbd2b1c
bdf and rodas
Shreyas-Ekanathan aff9da0
refactor disco into controllers
Shreyas-Ekanathan 9d306b7
add disco to BDF controller
Shreyas-Ekanathan 2158f3b
fix small edits
Shreyas-Ekanathan 2b9a509
Update algorithms.jl
Shreyas-Ekanathan d8c1a3b
update disco scheme by caching problems in integrator
Shreyas-Ekanathan a293d6b
small optimization
Shreyas-Ekanathan 6aa6dfa
update disco to new approach
Shreyas-Ekanathan b3fa9e8
update benchmarks
Shreyas-Ekanathan af7c3a5
further optimizations
Shreyas-Ekanathan f24f124
Merge branch 'master' into fresh-disco
Shreyas-Ekanathan 3bd834f
fix benchmarks and merge issues
Shreyas-Ekanathan 90a9bca
update vector continuous callback handling
Shreyas-Ekanathan 6902dce
update tests
Shreyas-Ekanathan b472c7c
add steps for vern, BS, etc
Shreyas-Ekanathan ecd6d40
Merge branch 'master' into fresh-disco
Shreyas-Ekanathan 77ea57e
fix rebase errors
Shreyas-Ekanathan 8ac29b1
controller fix
Shreyas-Ekanathan 5b1069d
fix bug
Shreyas-Ekanathan e9d4d3c
controller edits, still WIP
Shreyas-Ekanathan fc9a970
docstring and renaming
Shreyas-Ekanathan b9584cf
some edits
Shreyas-Ekanathan 300e59e
tests
Shreyas-Ekanathan 191b42f
bdf controllers
Shreyas-Ekanathan ee0b2bc
whoops
Shreyas-Ekanathan 914a1d4
revert bdf edits
Shreyas-Ekanathan 414eb2c
composite controller fix
Shreyas-Ekanathan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| function set_discontinuity(u, uprev, integrator, cache) | ||
| breakpointθ = find_discontinuity(u, uprev, integrator, cache) | ||
| dt = integrator.dt | ||
| t = integrator.t | ||
| if !isnan(breakpointθ) && 1e-6 < breakpointθ < 1.0 | ||
| #println("Discontinuity detected at t = ", t + breakpointθ * dt) | ||
| return breakpointθ * dt | ||
| end | ||
| return -1 | ||
| end | ||
|
|
||
| function find_discontinuity(u, uprev, integrator, cache) | ||
| cb = integrator.opts.callback | ||
| cb === nothing && return -1 | ||
| isempty(cb.continuous_callbacks) && return -1 | ||
| p = integrator.p | ||
| t = integrator.t | ||
| dt = integrator.dt | ||
| save_idxs = integrator.opts.save_idxs | ||
| k = integrator.k | ||
| cache = integrator.cache | ||
| differential_vars = integrator.differential_vars | ||
| θlo = zero(dt) | ||
| θhi = one(dt) | ||
| bracket = [θlo, θhi] | ||
| breakpointθ = -one(dt) | ||
| idx = 1 | ||
| for i in cb.continuous_callbacks | ||
| if (!(i.maybe_discontinuity)) | ||
| continue | ||
| end | ||
| disco_prob = integrator.disco_probs[idx] | ||
| disco_zero = disco_prob.f.f | ||
| disco_zero.dt = dt | ||
| disco_zero.uprev = uprev | ||
| disco_zero.u = u | ||
| disco_zero.k = k | ||
| disco_zero.cache = cache | ||
| disco_zero.differential_vars = differential_vars | ||
| disco_zero.idxs = save_idxs | ||
| disco_zero.tprev = t | ||
| disco_zero.f = integrator.f | ||
| disco_zero.p = p | ||
| if (i isa VectorContinuousCallback) | ||
| len_cb = i.len | ||
| out_prev = similar(u) | ||
| out_curr = similar(u) | ||
| i.condition(out_prev, uprev, t, integrator) | ||
| i.condition(out_curr, u, t + dt, integrator) | ||
| for j in 1:len_cb | ||
| if (out_prev[j] * out_curr[j] < zero(out_prev[j])) | ||
| disco_zero.ind = j | ||
| sol = solve(disco_prob; bracket = bracket) | ||
| tmp = sol[] | ||
| if (!isnan(tmp) && (breakpointθ == -1 || tmp < breakpointθ)) | ||
| breakpointθ = tmp | ||
| end | ||
| end | ||
| end | ||
| else | ||
| out_prev = i.condition(uprev, t, integrator) | ||
| out_curr = i.condition(u, t + dt, integrator) | ||
| if (out_prev * out_curr < zero(out_prev)) | ||
| sol = solve(disco_prob; bracket = bracket) | ||
| tmp = sol[] | ||
| if (!isnan(tmp) && (breakpointθ == -1 || tmp < breakpointθ)) | ||
| breakpointθ = tmp | ||
| end | ||
| end | ||
| end | ||
| idx += 1 | ||
| end | ||
| breakpointθ | ||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
this isn't concrete
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.
yeah what Oscar and I had discussed was that once the callbacks are function wrapped we would store a single disco_prob and remake it each time, instead of storing a vector of all of them. Not sure if you had another approach in mind though