init(prob, alg, ...) returns an integrator for an ODE, DAE or SDE
problem instead of solving it, as SciMLBase's init; the options are
those of solve(). step_integrator(integ) (Julia's step!) takes one
accepted step, or, with dt, steps until dt has passed (with
stop_at_tdt = TRUE it stops exactly there). solve_integrator(integ)
(Julia's solve!) integrates to the end of the time span and returns the
solution.
Usage
init(prob, alg = NULL, ...)
step_integrator(integ, dt = NULL, stop_at_tdt = FALSE)
solve_integrator(integ)
set_u(integ, u)
set_t(integ, t)
derivative_discontinuity(integ, flag = TRUE)
set_proposed_dt(integ, dt)
get_proposed_dt(integ)
set_abstol(integ, x)
set_reltol(integ, x)
add_saveat(integ, t)
savevalues(integ)
reinit(integ, u0 = NULL, t0 = NULL, tf = NULL, erase_sol = TRUE, p = NULL)
get_du(integ)Arguments
- prob
An
ODEProblem,DAEProblemorSDEProblem.- alg
The algorithm, as for
solve().- ...
Solver options, as for
solve().- integ
An integrator returned by
init()(or given to a callback).- dt
A time span (for
step_integrator()) or a step size.- stop_at_tdt
Stop exactly after
dt.- u, t
A state and a time.
- flag
Whether there is a discontinuity.
- x
A tolerance.
- u0, t0, tf
Initial values and time span for
reinit().- erase_sol
Drop the saved values of the previous integration.
- p
New parameters (for an
OptimizationCache).
Value
init() returns the integrator; solve_integrator() the
solution; the others return the integrator invisibly (or the queried
value).
Details
The integrator is an environment with u, t, p, uprev, tprev, and
read only dt (the proposed step), sol (the solution so far), opts,
alg, iter and retcode; integ$interp(t) interpolates inside the
last step. It is the object callbacks receive, so the functions below also
work inside affects:
set_u(integ, u),set_t(integ, t)change the state; the next step restarts the method's caches.derivative_discontinuity(integ)marks a discontinuity without changing the state.set_proposed_dt(integ, dt)andget_proposed_dt(integ);set_abstol(integ, x)andset_reltol(integ, x).add_saveat(integ, t)adds save times;savevalues(integ)saves the current state now.add_tstop(),terminate()andu_modified()are documented with the callbacks.reinit(integ, u0, t0, tf)starts the integration again (by default from the problem's initial values).get_du(integ)is the derivative of the state at the current time.
Examples
prob <- ODEProblem(function(u, p, t) -p * u, 1, c(0, 1), 2)
integ <- init(prob, Tsit5(), reltol = 1e-8)
step_integrator(integ)
integ$t
#> [1] 0.01907446
step_integrator(integ, 0.25, stop_at_tdt = TRUE)
set_u(integ, 2 * integ$u)
sol <- solve_integrator(integ)
tail(sol$u, 1)
#> [[1]]
#> [1] 0.2706706
#>