set_discontinuity(integrator) returns the step size with which the
current step of integrator should be tried again so that it ends near
the first root of a continuous callback inside the step, or -1 when no
callback changes sign in the step. Only callbacks with
maybe_discontinuity = TRUE (the default of ContinuousCallback()) are
considered. With the root at the fraction theta of the step, the new
step is (0.5 + 1.2372 (theta - 0.5) - 1.7487 (theta - 0.5)^3) dt, a
smooth version of (0.5 + 0.4 sin(pi (theta - 0.5))) dt.
Arguments
- integrator
An integrator from
init(). Its current step is the last step taken (or attempted, inside the solver).
Details
solve(prob, alg, discontinuity_detection = TRUE) applies it after every
rejected step of the integral, PI, PID and predictive controllers (as the
discontinuity_detection option of the controllers of OrdinaryDiffEq), so
that a step rejected because it jumped over a discontinuity of the right
hand side retries just before the discontinuity instead of shrinking by
the controller's factor.
Examples
f <- function(u, p, t) c(if (u[2] < 0.5) u[1] else -u[1] * u[1], 1)
cb <- ContinuousCallback(function(u, t, integ) u[2] - 0.5, function(integ) NULL)
prob <- ODEProblem(f, c(1, 0), c(0, 1))
sol <- solve(prob, Tsit5(), callback = cb, discontinuity_detection = TRUE)
sol$stats$nreject
#> [1] 3