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 exampleMatrixOperator(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 partsJ_iof the Jacobian or prebuilt factorsI - gamma J_i. When both are given they must have the same length;amf_factorsthen 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.
Details
build_amf_function(f, jac, split, amf_factors)returns theODEFunction()off(u, p, t)with the Jacobian operatorjacasjac_prototype, the AMF operator asW_prototypeand the sparsity pattern (the matrix ofjacunlesssparsityis given). Givesplit, a list of operatorsJ_1, ..., J_k, for the AMF product;amf_factors, a list of prebuilt factors (eachI - gamma J_iwith agammascalar operator updated by the solver); or neither for the exactW.AMFOperator(jac)is the exact operator-(I - gamma J) / gammaof an operatorjac;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 / gammaof prebuilt factors. Thegammaof these operators is aScalarOperator()set byupdate_coefficients(W, u, p, t, gamma = dtgamma).AMF(alg, ...)builds the Rosenbrock methodalg(...)(Rosenbrock23(),Rodas4()orRodas5P();...such asautodiffgo to its constructor) withSciMLOpFactorization()as its linear solver. The problem must come frombuild_amf_function()(anODEFunctionwith aW_prototypeoperator). No Jacobian is evaluated; the time derivative is a forward difference unlessfhastgrad.SciMLOpFactorization()is the linear solver for aLinearProblem()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 (asfactorizeof 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