The callbacks of DiffEqCallbacks.jl, for solve() and init() of ODE,
DAE and SDE problems (pass them as callback, alone or in a
CallbackSet()).
Usage
SavedValues()
SavingCallback(
save_func,
saved_values,
saveat = numeric(),
save_everystep = !length(saveat),
save_start = save_everystep || !length(saveat) || length(saveat) == 1L,
save_end = save_everystep || !length(saveat) || length(saveat) == 1L,
tdir = 1
)
FunctionCallingCallback(
func,
funcat = numeric(),
func_everystep = !length(funcat),
func_start = TRUE,
tdir = 1
)
IndependentlyLinearizedSolution(prob, num_derivatives = 0)
LinearizingSavingCallback(
ils,
interpolate_mask = NULL,
abstol = NULL,
reltol = NULL
)
PositiveDomain(u = NULL, save = TRUE, abstol = NULL, scalefactor = NULL)
GeneralDomain(
g,
u = NULL,
save = TRUE,
abstol = NULL,
scalefactor = NULL,
autonomous = NULL,
domain_jacobian = NULL,
...
)
ManifoldProjection(
g,
nlsolve = NULL,
save = TRUE,
autonomous = NULL,
manifold_jacobian = NULL,
...
)
AutoAbstol(save = TRUE, init_curmax = 0)
StepsizeLimiter(
dtFE,
safety_factor = 9/10,
max_step = FALSE,
cached_dtcache = 0
)
TerminateSteadyState(
abstol = 1e-08,
reltol = 1e-06,
test = .all_deriv_pass,
min_t = NULL,
wrap_test = TRUE
)
ProbIntsUncertainty(sigma, order, save = TRUE)
AdaptiveProbIntsUncertainty(order, save = TRUE)
IterativeCallback(
time_choice,
affect,
initial_affect = FALSE,
save_positions = c(TRUE, TRUE)
)
IntegrandValues()
IntegrandValuesSum()
IntegratingCallback(
integrand_func,
integrand_values,
integrand_prototype = NULL
)
IntegratingSumCallback(
integrand_func,
integrand_values,
integrand_prototype = NULL
)
IntegratingGKCallback(
integrand_func,
integrand_values,
integrand_prototype = NULL,
abstol = 1e-06,
reltol = 0.001
)
IntegratingGKSumCallback(
integrand_func,
integrand_values,
integrand_prototype = NULL,
abstol = 1e-06,
reltol = 0.001
)Arguments
- save_func, func
Functions
(u, t, integ).- saved_values
A
SavedValues()object.- saveat, funcat
Times (or, as one number, an interval).
- save_everystep, func_everystep
Call after every step.
- save_start, save_end, func_start
Call at the start or the end.
- tdir
Direction of time.
- prob
An ODE problem.
- num_derivatives
Number of derivatives to store with each point (0 or 1).
- ils
An
IndependentlyLinearizedSolution().- interpolate_mask
Logical vector: the unknowns whose interpolant is refined (others are stored at the step ends).
- abstol, reltol
Tolerances (default: those of the integrator).
- u
Unused cache argument of the Julia signature.
- save
Save after the callback acts.
- scalefactor
Factor by which a step is shortened (default
1/2).- g
A residual function
(u, p, t)or(u, p).- autonomous
Whether
gtakes no time argument (default: from the number of arguments).- nlsolve, ...
Unused options of the Julia signature.
- manifold_jacobian, domain_jacobian
Optional Jacobian of
g.- init_curmax
Initial largest absolute values for
AutoAbstol().- dtFE
Function
(u, p, t)giving the largest stable step.- safety_factor
Fraction of
dtFEallowed.- max_step
Always propose the largest allowed step.
- cached_dtcache
Unused option of the Julia signature.
- test
Function
(integ, abstol, reltol, min_t).- min_t
Earliest time to stop.
- wrap_test
Pass
testas the condition(u, t, integ)itself whenFALSE.- sigma, order
Noise scale and order of the method.
- time_choice
Function
(integ)returning the next time orNULL.- affect
Function
(integ).- initial_affect
Apply
affectat the start.- save_positions
Save the state before and after the affect.
- integrand_func
Function
(u, t, integ).- integrand_values
An
IntegrandValues()(orIntegrandValuesSum()) object.- integrand_prototype
Unused (the integrand's shape is taken from its first value).
Details
SavingCallback(save_func, saved_values)callssave_func(u, t, integ)after every step (or atsaveat) and stores the results insaved_values, aSavedValues()object with elementstandsaveval.FunctionCallingCallback(func)callsfunc(u, t, integ)the same way without storing anything.LinearizingSavingCallback(ils)stores, in anIndependentlyLinearizedSolution(prob), for each unknown separately the fewest time points such that linear interpolation is withinabstolandreltolof the solver's interpolant.ils(t)interpolates,ils$tsandils$ushold the points of each unknown.PositiveDomain()keeps the solution non negative: the next step is shortened until the extrapolated state is above-abstol, and negative values are set to zero.GeneralDomain(g)keepsg(u, p, t)(org(u, p)) belowabstolthe same way and projects ontog = 0.ManifoldProjection(g)projects the state onto the manifoldg(u, p, t) = 0(org(u, p)) after every step, the closest point in the Euclidean norm (Newton on the Lagrange conditions).AutoAbstol()sets the absolute tolerance to the relative tolerance times the largest absolute value of each unknown so far.StepsizeLimiter(dtFE)limits each step tosafety_factor * dtFE(u, p, t).TerminateSteadyState(abstol, reltol)stops when every derivative is belowmax(abstol, reltol |u|)(aftermin_t), or whentest(integ, abstol, reltol, min_t)isTRUE.ProbIntsUncertainty(sigma, order)adds Gaussian noise of standard deviationsigma dt^orderafter each step (the ProbInts method of Conrad et al.);AdaptiveProbIntsUncertainty(order)uses the error estimate of the step forsigma.IterativeCallback(time_choice, affect)appliesaffect(integ)at the timestime_choice(integ)returns one after the other (NULLends it).IntegratingCallback(integrand_func, integrand_values)integratesintegrand_func(u, t, integ)over each step by Gauss-Legendre quadrature on the interpolant and stores one integral per step inIntegrandValues();IntegratingSumCallback()accumulates the total inIntegrandValuesSum(). TheGKversions use adaptive Gauss-Kronrod quadrature withabstolandreltol.
Examples
prob <- ODEProblem(function(u, p, t) -u, c(1, 2), c(0, 1))
sv <- SavedValues()
sol <- solve(prob, Tsit5(), callback = SavingCallback(function(u, t, integ) sum(u), sv,
saveat = 0.25))
unlist(sv$saveval)
#> [1] 3.000000 2.336402 1.819591 1.417098 1.103639
iv <- IntegrandValuesSum()
sol <- solve(prob, Tsit5(), callback = IntegratingSumCallback(function(u, t, integ) u, iv))
iv$integrand # 1 - exp(-1) times c(1, 2)
#> [1] 0.6321204 1.2642408