Skip to contents

Rosenbrock methods whose linear systems use an approximate matrix factorization (AMF) of the iteration matrix, as OrdinaryDiffEqAMF. For a Jacobian split as J = J_1 + ... + J_k (for example into the parts of the directions of a PDE discretization, or into triangular parts) the iteration matrix W = -(I - gamma J) / gamma of a step is replaced by -(I - gamma J_1) ... (I - gamma J_k) / gamma, whose factors are cheap to solve with.

Usage

AMF(alg, ...)

SciMLOpFactorization()

AMFOperator(jac = NULL, factors = NULL)

build_amf_function(
  f,
  jac,
  split = NULL,
  amf_factors = NULL,
  jac_cache = NULL,
  w_cache = NULL,
  sparsity = NULL
)

Arguments

alg

A Rosenbrock method constructor (Rosenbrock23, Rodas4, Rodas5P) or a Rosenbrock algorithm object.

...

Arguments of the Rosenbrock constructor (autodiff).

jac

A square SciML operator: the Jacobian of f (for example MatrixOperator(J0, update_func) or a sum of such operators).

factors

Prebuilt factors for AMFOperator().

f

The right-hand side f(u, p, t).

split, amf_factors

Lists of square operators of the size of jac: the parts J_i of the Jacobian or prebuilt factors I - gamma J_i. When both are given they must have the same length; amf_factors then builds the operator.

jac_cache, w_cache

Prototype vectors for cache_operator() of the Jacobian and the AMF operator (zero vectors by default).

sparsity

Sparsity pattern; by default the matrix of jac.

Value

An algorithm, an operator, a linear solver or an ODEFunction.

Details

  • build_amf_function(f, jac, split, amf_factors) returns the ODEFunction() of f(u, p, t) with the Jacobian operator jac as jac_prototype, the AMF operator as W_prototype and the sparsity pattern (the matrix of jac unless sparsity is given). Give split, a list of operators J_1, ..., J_k, for the AMF product; amf_factors, a list of prebuilt factors (each I - gamma J_i with a gamma scalar operator updated by the solver); or neither for the exact W.

  • AMFOperator(jac) is the exact operator -(I - gamma J) / gamma of an operator jac; AMFOperator(list(J_1, ..., J_k)) the AMF product of split operators; AMFOperator(factors = list(F_1, ..., F_k)) the operator -F_1 ... F_k / gamma of prebuilt factors. The gamma of these operators is a ScalarOperator() set by update_coefficients(W, u, p, t, gamma = dtgamma).

  • AMF(alg, ...) builds the Rosenbrock method alg(...) (Rosenbrock23(), Rodas4() or Rodas5P(); ... such as autodiff go to its constructor) with SciMLOpFactorization() as its linear solver. The problem must come from build_amf_function() (an ODEFunction with a W_prototype operator). No Jacobian is evaluated; the time derivative is a forward difference unless f has tgrad.

  • SciMLOpFactorization() is the linear solver for a LinearProblem() whose matrix is a SciML operator: a product or a multiple of operators is factorized part by part, a tensor product through its factors, and any other part through the structured factorization of its matrix (as factorize of Julia's LinearAlgebra: diagonal, bidiagonal or triangular substitution, LU of a tridiagonal matrix, Bunch-Kaufman of a symmetric matrix, else LU); the factorization is kept while the operator does not change.

As in OrdinaryDiffEq the steps are those of the in place methods (an AMF solve in Julia needs an in place f!): the Rodas methods evaluate f at the start of every step, and a fixed step Rosenbrock23 evaluates the derivative at the new state at the start of the next step.

Examples

A1 <- rbind(c(-2, 1), c(0, -3))
A2 <- rbind(c(0, 0), c(1, 0))
f <- function(u, p, t) c(-2 * u[1] + u[2], u[1] - 3 * u[2])
J1 <- MatrixOperator(A1)
J2 <- MatrixOperator(A2)
fun <- build_amf_function(f, jac = J1 + J2, split = list(J1, J2))
prob <- ODEProblem(fun, c(1, 1), c(0, 1))
sol <- solve(prob, AMF(Rodas5P))
sol$u[[length(sol$u)]]
#> [1] 0.2893863 0.1891144
W <- update_coefficients(fun$W_prototype, gamma = 0.1)
solve(LinearProblem(W, c(1, 2)), SciMLOpFactorization())$u
#> [1] -0.09615385 -0.16346154