AutoSwitch(nonstiffalg, stiffalg) builds a composite algorithm that
starts with the nonstiff method and switches to the stiff one after
maxstiffstep consecutive steps flagged as stiff (the stiffness estimate
times the step size exceeds the nonstiff method's stability region), and
back after maxnonstiffstep steps flagged as nonstiff, as
AutoAlgSwitch in OrdinaryDiffEq.jl. AutoTsit5(alg) and AutoVern7(alg)
pair Tsit5() or Vern7() with a stiff method.
Usage
AutoSwitch(
nonstiffalg,
stiffalg,
maxstiffstep = 10L,
maxnonstiffstep = 3L,
nonstifftol = 9/10,
stifftol = 9/10,
dtfac = 2,
stiffalgfirst = FALSE
)
AutoTsit5(alg, ...)
AutoVern7(alg, ...)
AutoVern6(alg, ...)
AutoVern8(alg, ...)
AutoVern9(alg, ...)Arguments
- nonstiffalg, stiffalg
Algorithms.
- maxstiffstep, maxnonstiffstep
Consecutive steps before switching.
- nonstifftol, stifftol
Stiffness thresholds.
- dtfac
Step size factor applied when switching.
- stiffalgfirst
Start with the stiff method.
- alg
A stiff algorithm such as
Rosenbrock23().- ...
Options for
AutoSwitch().
Examples
f <- function(u, p, t) c(-0.04 * u[1] + 1e4 * u[2] * u[3],
0.04 * u[1] - 1e4 * u[2] * u[3] - 3e7 * u[2]^2,
3e7 * u[2]^2)
prob <- ODEProblem(f, c(1, 0, 0), c(0, 1))
sol <- solve(prob, AutoTsit5(Rosenbrock23()))
table(sol$alg_choice)
#>
#> 1 2
#> 22 9