Global error estimation with a companion equation
Source:R/globaldiffeq-companion.R
GlobalErrorEstimation.RdGlobalErrorEstimation(alg) wraps an ODE algorithm with global error
estimation and control based on a defect driven companion equation, as
GlobalDiffEq.jl. After a dense solve with interpolant P(t), the global
error eps(t) ~ y(t) - P(t) is estimated by integrating a companion ODE
driven by the defect d(t) = f(P(t), p, t) - P'(t) of the dense output,
from eps(t0) = 0.
Usage
GlobalErrorEstimation(
alg,
equation = DefectCorrection,
mode = InterpolatingMode,
companion_alg = alg,
autodiff = AutoForwardDiff(),
gtol = NULL,
maxiters = 6,
safety = 0.8,
companion_abstol = if (is.null(gtol)) 1e-10 else min(gtol/100, 1e-10),
companion_reltol = if (is.null(gtol)) 1e-08 else min(gtol/100, 1e-08)
)Arguments
- alg
The ODE algorithm.
- equation
- mode
- companion_alg
The algorithm of the companion solve.
- autodiff
How
ErrorTransportapplies the Jacobian:AutoForwardDiff()(the exact Jacobian of the problem when it has one,jac_fnor symbolic, else a central difference along the error) orAutoFiniteDiff().- gtol
The requested absolute endpoint error, needed by
solve().- maxiters
The maximum number of tolerance refinements.
- safety
The safety factor of each tolerance reduction.
- companion_abstol, companion_reltol
Tolerances of the companion solve.
Details
equation (GlobalErrorEquation) selects the companion ODE:
DefectCorrection (the default) or its linearization ErrorTransport,
whose Jacobian vector product uses autodiff. mode
(GlobalErrorMode) selects how it is integrated: InterpolatingMode
(the default) or SimultaneousMode.
global_error_estimate(prob, alg) solves prob and returns the
estimated 2-norm of the global error at the final time (abstol and
reltol control the solve, companion_abstol and companion_reltol the
companion solve). solve(prob, GlobalErrorEstimation(alg, gtol = ...))
tightens the local tolerances (which default to gtol) until the
estimated endpoint error is at most gtol and returns the solution of
alg at those tolerances.
The solver must have a dense output with a first derivative: Tsit5, DP5,
the Verner methods, Rosenbrock23, the Rodas methods, FBDF and the methods
with cubic Hermite dense output (ImplicitEuler and Trapezoid among them).
The low storage and SSP methods, whose dense output is linear in this
package (OrdinaryDiffEq has Hermite or quadratic dense output for them),
are rejected. The companion solver defaults to alg; a method that only
evaluates f at the end of each step (ImplicitEuler) samples the defect
where it vanishes, so give such a method an explicit companion_alg.
Forward time ODEs with the standard mass matrix, real vector states and
no callbacks are supported.
References
P. E. Zadunaisky, Numerische Mathematik 27, 1976. J. R. Dormand, R. R. Duckers and P. J. Prince, Global error estimation with Runge-Kutta methods, IMA Journal of Numerical Analysis 4, 1984. J. Lang and J. Verwer, On global error estimation and control for initial value problems, SIAM Journal on Scientific Computing 29, 2007.
Examples
prob <- ODEProblem(function(u, p, t) -u, 1, c(0, 1))
alg <- GlobalErrorEstimation(Tsit5())
global_error_estimate(prob, alg, abstol = 1e-4, reltol = 1e-4)
#> [1] 3.770197e-08
sol <- solve(prob, Tsit5(), abstol = 1e-4, reltol = 1e-4)
abs(sol$u[[length(sol$t)]] - exp(-1))
#> [1] 3.77027e-08
sol <- solve(prob, GlobalErrorEstimation(Tsit5(), gtol = 1e-7))
abs(sol$u[[length(sol$t)]] - exp(-1))
#> [1] 5.205725e-10