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

Add PeriodicCallback. #23

Merged
merged 5 commits into from
Oct 16, 2017
Merged

Conversation

tkoolen
Copy link
Contributor

@tkoolen tkoolen commented Oct 14, 2017

This is to support stuff like JuliaRobotics/RigidBodySim.jl#5.

I'm aware of http://docs.juliadiffeq.org/latest/features/diffeq_arrays.html#Example:-A-Control-Problem-1, but I wasn't satisfied with simply using the tstops kwarg to solve. Reasons:

  1. I want support for infinite tspans (where integration continues indefinitely until some callback terminate!s the integrator, in my case a stop button in a GUI)
  2. Even for finite tspans you'd end up with a length of the internal tstops collection that is linear in the length of the integration time interval with the other method; that's not the end of the world, but it seems unnecessary.
  3. With PeriodicCallbacks, you only have to pass the callback into solve or init. I think this is cleaner than having to pass in both a callback and tstops, especially if there are multiple callbacks that each have a different period.

src/periodic.jl Outdated

# Schedule next call to `f` using `add_tstops!`, but be careful not to keep integrating forever
t_new = t_next[] + Δt
if any(t -> t > t_new, integrator.opts.tstops.valtree) # TODO: accessing internal data...
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, there must be a better way to iterate through a heap

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I guess it would at least be better to reverse-iterate.

Could also:

  • store the maximum time in the integrator options, in addition to tstops (although it then becomes possible to have bugs where tstops is out of sync with that maximum time).
  • switch to a min-max heap (not yet implemented in DataStructures.jl and perhaps overkill)

@coveralls
Copy link

coveralls commented Oct 14, 2017

Coverage Status

Coverage increased (+0.5%) to 94.048% when pulling 35f6b4c on tkoolen:periodic-callback into e602c07 on JuliaDiffEq:master.

@codecov
Copy link

codecov bot commented Oct 14, 2017

Codecov Report

Merging #23 into master will increase coverage by 0.6%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff            @@
##           master      #23     +/-   ##
=========================================
+ Coverage   93.54%   94.15%   +0.6%     
=========================================
  Files           5        6      +1     
  Lines         155      171     +16     
=========================================
+ Hits          145      161     +16     
  Misses         10       10
Impacted Files Coverage Δ
src/periodic.jl 100% <100%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update e602c07...b5c7a24. Read the comment docs.

@coveralls
Copy link

coveralls commented Oct 14, 2017

Coverage Status

Coverage increased (+0.6%) to 94.152% when pulling 0552862 on tkoolen:periodic-callback into e602c07 on JuliaDiffEq:master.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.6%) to 94.186% when pulling b5c7a24 on tkoolen:periodic-callback into e602c07 on JuliaDiffEq:master.

@tkoolen
Copy link
Contributor Author

tkoolen commented Oct 15, 2017

Added README.md entry, made it so that passing in an initialize kwarg also works, and made things work for negative tdir (requires SciML/OrdinaryDiffEq.jl#210).

Are you satisfied with the tstops.valtree iteration changes? Anything else?

@ChrisRackauckas
Copy link
Member

I wish there was a more generic way to iterate through a heap than that, but that's an issue for DataStructures.jl. Works for now.

@ChrisRackauckas ChrisRackauckas merged commit d099203 into SciML:master Oct 16, 2017
@tkoolen tkoolen deleted the periodic-callback branch October 16, 2017 23:08
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

Successfully merging this pull request may close these issues.

None yet

3 participants