Module Sundials_LinearSolver.Iterative.Custom

module Custom: sig .. end

Custom iterative linear solvers.


type 'lsolver tag = [ `Custom of 'lsolver ] 

Used to distinguish custom linear solvers

type ('data, 'kind) atimesfn = ('data, 'kind) Nvector.t -> ('data, 'kind) Nvector.t -> unit 

A function atimesfn v z computes the action of the system matrix on the vector v, storing the result in z. The matrix is represented implicitly by the effect of the function.

If a problem occurs the function raises Sundials_LinearSolver.ATimesFailure.

type psetupfn = unit -> unit 

Functions that set up any problem data in preparation for calls to psolvefn.

If a problem occurs the function raises Sundials_LinearSolver.PSetFailure.

type ('data, 'kind) psolvefn = ('data, 'kind) Nvector.t -> ('data, 'kind) Nvector.t -> float -> bool -> unit 

A function psolvefn r z tol lr that solves the preconditioner equation $Pz = r$ for the vector z such that $\left\lVert Pz - r \right\rVert_\mathrm{wrms} < \mathit{tol}$ . If lr is true then $P$ should be treated as a left preconditioner and otherwise as a right preconditioner.

If a problem occurs the function raises Sundials_LinearSolver.PSolveFailure.

type ('data, 'kind, 'lsolver) ops = {
   init : 'lsolver -> unit; (*

Performs linear solver initalization.

*)
   setup : 'lsolver -> unit; (*

Performs linear solver setup.

*)
   solve : 'lsolver -> 'data -> 'data -> float -> unit; (*

The call solve ls x b tol should solve the linear system $Ax = b$ to within the weight 2-norm tolerance tol. $A$ is only available indirectly via the atimes function.

*)
   set_atimes : ('lsolver ->
('data, 'kind) atimesfn -> unit)
option
;
(*

Provides the linear solver with a problem-specific Sundials_LinearSolver.Iterative.Custom.atimesfn. The given function may only be used within init, setup, and solve.

*)
   set_preconditioner : ('lsolver ->
psetupfn option ->
('data, 'kind) psolvefn option ->
unit)
option
;
(*

Provides the linear solver with preconditioner routines. The given functions may only be used within init, setup, and solve.

*)
   set_scaling_vectors : ('lsolver -> 'data option -> 'data option -> unit) option; (*

Passes the left/right scaling vectors for use in solve. The call set_scaling_vectors ls s1 s2 provides diagonal matrices of scale factors for solving the system $\tilde{A}\tilde{x} = \tilde{b}$ where $\tilde{A} = S_1 P_1^{-1} A P_2^{-1} S_2^{-1}$ , $\tilde{b} = S_1 P_1^{-1} b$ , and $\tilde{x} = S_2 P_2 x$ . A None argument indicates an identity scaling matrix.

*)
   get_num_iters : ('lsolver -> int) option; (*

The number of linear iterations performed in the last solve call.

*)
   get_res_norm : ('lsolver -> float) option; (*

The final residual norm from the last solve call.

*)
   get_res_id : ('lsolver -> ('data, 'kind) Nvector.t) option; (*

The preconditioned initial residual vector. This vector may be requested if the iterative method computes the preconditioned initial residual and returns from solve successfully without performing any iterations (i.e., either the initial guess or the preconditioner is sufficiently accurate).

*)
   get_work_space : ('lsolver -> int * int) option; (*

Return the storage requirements for the linear solver. The result (lrw, liw) gives the number of words used for storing real values (lrw) and the number of words used for storing integer values (liw). *

*)
}

The operations required to implement an iterative linear solver. Failure should be indicated by raising an exception (preferably one of the exceptions in this package). Raising Sundials.RecoverableFailure indicates a generic recoverable failure.

val make : ('data, 'kind, 'lsolver) ops ->
'lsolver ->
('data, 'kind, 'lsolver tag)
Sundials_LinearSolver.Iterative.linear_solver

Create an iterative linear solver given a set of operations and an internal state.

NB: This feature is only available for Config.sundials_version >= 3.0.0.

val unwrap : ('data, 'kind, 'lsolver tag)
Sundials_LinearSolver.Iterative.linear_solver -> 'lsolver

Return the internal state from an custom iterative linear solver.