Skip to content

Optimizations to Discontinuity Detection Scheme#3720

Open
Shreyas-Ekanathan wants to merge 4 commits into
SciML:masterfrom
Shreyas-Ekanathan:disco-optimizations
Open

Optimizations to Discontinuity Detection Scheme#3720
Shreyas-Ekanathan wants to merge 4 commits into
SciML:masterfrom
Shreyas-Ekanathan:disco-optimizations

Conversation

@Shreyas-Ekanathan

Copy link
Copy Markdown
Contributor

Checklist

  • Appropriate tests were added
  • Any code changes were done in a way that does not break public API
  • All documentation related to code changes were updated
  • The new code follows the
      contributor guidelines, in particular the SciML Style Guide and
      COLPRAC.
  • Any new documentation only uses public API

Additional context

Optimizations:

  • Add a tstop on the first identification of a discontinuity to help with step-resizing and prevent excessively large steps after finding a discontinuity. This should help us not take unreasonable steps, as Oscar suggested, and helps with error resetting after passing a discontinuity (since we are effectively in a new regime) to begin stepping anew.
  • Shrink the solve window for the interval nonlinear problem after finding a discontinuity
  • Move _ode_addsteps! out of the zero_func_struct call and only call it once per discontinuity detection run

Comment thread lib/OrdinaryDiffEqBDF/src/controllers.jl Outdated
Comment thread lib/OrdinaryDiffEqCore/src/integrators/controllers.jl
Comment on lines +178 to +179
is_disco_step::Bool
disco_checkpoint::tType

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

We want to rename both of these.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

what would you name them?

function set_discontinuity(integrator)
breakpointθ = find_discontinuity(integrator)
dt = integrator.dt
if 1.0e-10 < breakpointθ < 1.0

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

why 1e-10?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

pretty arbitrary, just don't want to take a tiny step (I think this is reasonable?)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think that's both smaller than we want (I think we probably never want and the wrong result if we hit it. I think it does make sense to clamp breakpointθ to (0.1, 0.9) because if we are on the wrong side of a disco point very close to the edge, we don't shrink the interval, but I think we still want to use disco if we have a sign crossing that we think is very close to an edge.

end
disco_zero.ind = j
sol = solve(disco_prob)
sol = solve(disco_prob, tspan = (0.0, breakpointθ == -one(dt) ? 1.0 : breakpointθ); save_everystep = false)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

does save_everystep do anything here? I didn't think any steps exist for NonlinearProblems. Also I wonder if using breakpointθ=-1 as the default makes sense. Could we use 1 to mean "no restriction"?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I think using 1 is a little dicey since it potentially creates some numerical issues? whereas -1 is a cleaner sentinel imo.

save_everystep does prevent the solve from tracking every internal step I believe, so it should help?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The argument for 1 is that it deosn't need to be a sentinel. 1.0 naturally means no restriction on the timestep. I don't think we track internal steps for a nonlinear solve.

is_disco = integrator.is_disco_step
if is_disco
integrator.is_disco_step = false
cache.nconsteps = 0

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

what is this line doing?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

because it's not a standard timestep BDF shouldn't really count this step towards its order selection logic right?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@ChrisRackauckas thoughts on this? I don't know how we want disco to interact with BDF well enough here.

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.

2 participants