Skip to contents

test_convergence(dts, prob, alg) solves the problem with each time step of dts (fixed steps: adaptive = FALSE, save_everystep = TRUE by default) and returns the ConvergenceSimulation() of the errors against the analytic solution of the problem (the analytic field of its function, analytic(u0, p, t), analytic(du0, u0, p, t) for DAEs, analytic(u0, h, p, t) for DDEs and analytic(u0, p, t, W) for SDE, RODE and SDDE problems). The options timeseries_errors (default TRUE) and dense_errors (default FALSE) select the errors; other options go to solve().

Usage

test_convergence(dts, prob, alg, ..., dt = NULL, p = NULL)

analyticless_test_convergence(
  dts,
  prob,
  alg,
  test_dt,
  ...,
  dt = NULL,
  p = NULL
)

Arguments

dts

Time steps, a list of problems, or a convergence setup.

prob

The problem, the convergence axis for a list of problems, or the algorithm for a setup.

alg

The algorithm.

...

Options, see Details, and solver options.

dt, p

The solver options dt and p, named in the signature so that they do not partially match dts and prob.

test_dt

The reference setup (ODE) or reference time step (SDE).

Details

For SDE, RODE and SDDE problems (or an EnsembleProblem() of one), trajectories paths are solved for each time step, with the ensemble algorithm ensemblealg (the fourth argument), and the errors are the means over the trajectories plus the weak errors weak_final (and weak_l2, weak_l_inf with weak_timeseries_errors = TRUE, weak_L2, weak_L_inf with weak_dense_errors = TRUE). With expected_value, the weak error is that of the trajectory values (the outputs of the ensemble) against it. Unless retain_solutions = TRUE each trajectory is reduced to a ConvergenceTrajectory() and only the first one is kept.

test_convergence(probs, convergence_axis, alg) solves each problem of the list probs with the options in ..., and test_convergence(setup, alg) takes probs and convergence_axis from a list setup with those fields.

analyticless_test_convergence(dts, prob, alg, setup) compares an ODE solution for each time step with a reference solution computed by solve(prob, setup$alg, ...) with the other options of setup. For a random problem, the fourth argument is the time step of the reference: each of trajectories Brownian paths on that grid (a NoiseGrid(), or with use_noise_grid = FALSE the path of the reference solve through a NoiseWrapper()) is solved with every step of dts and compared with the solution on the reference step.

Examples

f <- function(u, p, t) -u
fn <- ODEFunction(f, analytic = function(u0, p, t) u0 * exp(-t))
prob <- ODEProblem(fn, 1, c(0, 1))
sim <- test_convergence(1 / 2^(3:5), prob, Euler())
sim$Oest$final
#> [1] 1.029543
sim2 <- analyticless_test_convergence(1 / 2^(3:5), ODEProblem(f, 1, c(0, 1)), Heun(),
  list(alg = RK4(), dt = 1 / 256))
sim2$Oest$final
#> [1] 2.084709