Skip to contents

Linear operators with the interface of SciMLOperators.jl, accepted where the solvers take a matrix (linear problems, mass matrices, Jacobian prototypes, the linear part of split and exponential methods). MatrixOperator(A, update_func) wraps a matrix whose entries may depend on (u, p, t) through update_func(A, u, p, t); DiagonalOperator(d), ScalarOperator(alpha), IdentityOperator(n) and NullOperator(n) are the special cases; AffineOperator(A, B, b) is v -> A v + B b (AddVector(b) is v -> v + b); FunctionOperator(op, input, output) is an operator given by its action op(v, u, p, t) (with op_inverse and op_adjoint when known); InvertibleOperator(L, F) attaches a factorization; TensorProductOperator(A, B) is the Kronecker product A x B acting on vectors of length ncol(A) ncol(B), TensorSumOperator(A, B) and kronsum(A, B) the Kronecker sum A x I + I x B; BlockDiagonalOperator(...) stacks operators on the diagonal; WOperator(mass_matrix, gamma, J) is the matrix J - M / gamma of the implicit solvers, with jacobian_stale(), mark_jacobian_updated() and mark_jacobian_current() tracking changes of J; StaticWOperator(W) a factorized fixed W.

Usage

op_apply(L, v, u = NULL, p = NULL, t = NULL)

MatrixOperator(A, update_func = NULL)

DiagonalOperator(d, update_func = NULL)

ScalarOperator(alpha, update_func = NULL)

IdentityOperator(n, ...)

NullOperator(n)

AffineOperator(A, B, b, update_func = NULL)

AddVector(b, update_func = NULL)

FunctionOperator(
  op,
  input,
  output = input,
  op_inverse = NULL,
  op_adjoint = NULL,
  islinear = TRUE
)

InvertibleOperator(L, F = NULL)

TensorProductOperator(A, B)

TensorSumOperator(A, B)

kronsum(A, B)

BlockDiagonalOperator(...)

WOperator(mass_matrix, gamma, J, u = NULL)

StaticWOperator(W, callinv = TRUE)

jacobian_stale(L)

mark_jacobian_updated(L)

mark_jacobian_current(L)

update_coefficients(L, u = NULL, p = NULL, t = NULL, ...)

cache_operator(L, u = NULL)

concretize(L)

islinear(L)

issquare(L)

has_adjoint(L)

has_mul(L)

has_ldiv(L)

has_exp(L)

has_expmv(L)

iscached(L)

isconvertible(L)

has_concretization(L)

AddedOperator(...)

ComposedOperator(...)

ScaledOperator(lambda, L)

InvertedOperator(L)

AdjointOperator(L)

TransposedOperator(L)

AddedScalarOperator(...)

ComposedScalarOperator(...)

InvertedScalarOperator(alpha)

Arguments

L

An operator.

v, u, p, t

Vector to act on and the state, parameters and time.

A, B, J

Matrices or operators.

update_func

Coefficient update f(A, u, p, t); it may take further named arguments (such as gamma) passed to update_coefficients().

d

Diagonal entries.

alpha

Scalar value.

n

Size.

...

Operators or options. IdentityOperator() without a numeric n hands its arguments to symcompR's quantum IdentityOperator().

b

Vector.

op, op_inverse, op_adjoint

Actions f(v, u, p, t).

input, output

Prototype input and output vectors.

islinear

Whether the function operator is linear.

F

A factorization (any object with a solve() method).

mass_matrix, gamma

Mass matrix and step factor of WOperator().

W, callinv

The matrix of StaticWOperator() and whether it is applied through its factorization.

lambda

A number or scalar operator.

Value

An operator, a vector, a matrix or a logical.

Details

The lazy combinations have constructors of their own: AddedOperator(...) (sum), ComposedOperator(...) (product, applied right to left), ScaledOperator(lambda, L) (lambda L with a number or scalar operator lambda), InvertedOperator(L) (applies L^-1 through solve), AdjointOperator(L) and TransposedOperator(L) (equal for the real operators of R); AddedScalarOperator(...), ComposedScalarOperator(...) and InvertedScalarOperator(alpha) are the sum, product and reciprocal of scalar operators, updated with them.

Operators combine with +, -, * (composition and scaling) and apply with L %*% v (R 4.4 and later), op_apply(L, v, u, p, t), or L(v, u, p, t) semantics through op_apply; solve(L, b) applies the inverse, as.matrix(L) or concretize(L) gives the matrix and exp(L) its exponential. update_coefficients(L, u, p, t, ...) returns the operator at (u, p, t); named arguments in ... (such as the gamma of the AMF operators, AMFOperator()) reach the update functions that take them. The traits islinear(), isconstant(), issquare(), has_adjoint(), has_mul(), has_ldiv(), has_exp(), has_expmv(), iscached(), isconvertible() and has_concretization() answer questions about an operator; cache_operator(L, u) marks it cached.

Examples

L <- MatrixOperator(matrix(c(2, 0, 1, 3), 2))
op_apply(L, c(1, 1))
#> [1] 3 3
D <- DiagonalOperator(c(1, 2))
as.matrix(L + 2 * D)
#>      [,1] [,2]
#> [1,]    4    1
#> [2,]    0    7
solve(L, c(3, 3))
#> [1] 1 1
T <- update_coefficients(MatrixOperator(diag(2), function(A, u, p, t) t * diag(2)), NULL, NULL, 3)
as.matrix(T)
#>      [,1] [,2]
#> [1,]    3    0
#> [2,]    0    3
as.matrix(ComposedOperator(L, InvertedOperator(L)))
#>      [,1] [,2]
#> [1,]    1    0
#> [2,]    0    1
InvertedScalarOperator(ScalarOperator(4))$value
#> [1] 0.25