# Module Ida.Spils

module Spils: sig .. end
Scaled Preconditioned Iterative Linear Solvers.
See sundials: Iterative linear solvers optional input functions.
See sundials: Iterative linear solvers optional output functions.

### Preconditioners

type 'd prec_solve_fn = ('d, 'd) Ida.jacobian_arg -> 'd -> 'd -> float -> unit
Callback functions that solve a linear system involving a preconditioner matrix. In the call prec_solve_fn jac r z delta, jac is a Ida.jacobian_arg with one work vector, r is the right-hand side vector, z is computed to solve $Pz = r$, and delta is the input tolerance. $P$ is a preconditioner matrix, which approximates, however crudely, the Jacobian matrix $\frac{\partial F}{\partial y} + \mathtt{arg.jac\_coef}\frac{\partial F}{\partial\dot{y}}$. If the solution is found via an iterative method, it must satisfy $\sqrt{\sum_i (\mathit{Res}_i \cdot \mathit{ewt}_i)^2} < \mathtt{delta}$, where $\mathit{Res} = r - Pz$ and $\mathit{ewt}$ comes from Ida.get_err_weights.

Raising Sundials.RecoverableFailure indicates a recoverable error. Any other exception is treated as an unrecoverable error.

The elements of jac, r, and z should not be accessed after the function has returned.

See sundials: IDASpilsPrecSolveFn
type 'd prec_setup_fn = ('d Ida.triple, 'd) Ida.jacobian_arg -> unit
Callback functions that preprocess or evaluate Jacobian-related data need by Ida.Spils.prec_solve_fn. The sole argument is a Ida.jacobian_arg with three work vectors.

Raising Sundials.RecoverableFailure indicates a recoverable error. Any other exception is treated as an unrecoverable error.

The elements of the argument should not be accessed after the function has returned.

See sundials: IDASpilsPrecSetupFn
type 'd jac_times_vec_fn = ('d Ida.double, 'd) Ida.jacobian_arg -> 'd -> 'd -> unit
Callback functions that compute the Jacobian times a vector. In the call jac_times_vec_fn arg v jv, arg is a Ida.jacobian_arg with two work vectors, v is the vector multiplying the Jacobian, and jv is the vector in which to store the resultâ€”$\mathtt{jv} = J\mathtt{v}$.

Raising Sundials.RecoverableFailure indicates a recoverable error. Any other exception is treated as an unrecoverable error.

Neither the elements of arg nor v or jv should be accessed after the function has returned.

See sundials: IDASpilsJacTimesVecFn
type ('d, 'k) preconditioner = ('d, 'k) SpilsTypes.preconditioner
Specifies a preconditioner and its callback functions. The following functions and those in Ida_bbd construct preconditioners.

The Ida.Spils.prec_solve_fn is mandatory. The Ida.Spils.prec_setup_fn can be omitted if not needed.

See sundials: IDASpilsSetPreconditioner
See sundials: IDASpilsPrecSolveFn
See sundials: IDASpilsPrecSetupFn
val prec_none : ('d, 'k) preconditioner
No preconditioning.
val prec_left : ?setup:'d prec_setup_fn ->
'd prec_solve_fn -> ('d, 'k) preconditioner
Left preconditioning. $Pz = r$, where $P$ approximates, perhaps crudely, $J = \frac{\partial F}{\partial y} + c_j\frac{\partial F}{\partial\dot{y}}$.

### Solvers

val spgmr : ?maxl:int ->
?max_restarts:int ->
?jac_times_vec:'d jac_times_vec_fn ->
('d, 'k) preconditioner -> ('d, 'k) Ida.linear_solver
Krylov iterative solver using the scaled preconditioned generalized minimum residual (GMRES) method. In the call spgmr ~maxl:maxl ~max_restarts:maxr ~jac_times_vec:jtv prec,
• maxl is the maximum dimension of the Krylov subspace (defaults to 5),
• maxr is the maximum number of restarts (defaults to 5),
• jtv computes an approximation to the product between the Jacobian matrix and a vector, and
• prec is a Ida.Spils.preconditioner.
If the Ida.Spils.jac_times_vec_fn is omitted, a default implementation based on difference quotients is used.
See sundials: IDASpgmr
See sundials: IDASpilsSetPreconditioner
See sundials: IDASpilsSetMaxl
See sundials: IDASpilsSetJacTimesVecFn
See sundials: IDASpilsJacTimesVecFn
See sundials: IDASpilsSetMaxRestarts
val spbcg : ?maxl:int ->
?jac_times_vec:'d jac_times_vec_fn ->
('d, 'k) preconditioner -> ('d, 'k) Ida.linear_solver
Krylov iterative solver using the scaled preconditioned biconjugate stabilized (Bi-CGStab) method. In the call spbcg ~maxl:maxl ~jac_times_vec:jtv prec,
• maxl is the maximum dimension of the Krylov subspace (defaults to 5),
• jtv computes an approximation to the product between the Jacobian matrix and a vector, and
• prec is a Ida.Spils.preconditioner.
If the Ida.Spils.jac_times_vec_fn is omitted, a default implementation based on difference quotients is used.
See sundials: IDASpbcg
See sundials: IDASpilsSetPreconditioner
See sundials: IDASpilsSetJacTimesVecFn
See sundials: IDASpilsJacTimesVecFn
See sundials: IDASpilsSetMaxl
val sptfqmr : ?maxl:int ->
?jac_times_vec:'d jac_times_vec_fn ->
('d, 'k) preconditioner -> ('d, 'k) Ida.linear_solver
Krylov iterative with the scaled preconditioned transpose-free quasi-minimal residual (SPTFQMR) method. In the call sptfqmr ~maxl:maxl ~jac_times_vec:jtv prec,
• maxl is the maximum dimension of the Krylov subspace (defaults to 5),
• jtv computes an approximation to the product between the Jacobian matrix and a vector, and
• prec is a Ida.Spils.preconditioner.
If the Ida.Spils.jac_times_vec_fn is omitted, a default implementation based on difference quotients is used.
See sundials: IDASptfqmr
See sundials: IDASpilsSetPreconditioner
See sundials: IDASpilsSetJacTimesVecFn
See sundials: IDASpilsJacTimesVecFn
See sundials: IDASpilsSetMaxl

### Solver parameters

val set_gs_type : ('d, 'k) Ida.session -> Spils.gramschmidt_type -> unit
Sets the Gram-Schmidt orthogonalization to be used with the Spgmr Ida.linear_solver.
See sundials: IDASpilsSetGSType
val set_eps_lin : ('d, 'k) Ida.session -> float -> unit
Sets the factor by which the Krylov linear solver's convergence test constant is reduced from the Newton iteration test constant. This factor must be >= 0; passing 0 specifies the default (0.05).
See sundials: IDASpilsSetEpsLin
val set_maxl : ('d, 'k) Ida.session -> int -> unit
Resets the maximum Krylov subspace dimension for the Bi-CGStab and TFQMR methods. A value <= 0 specifies the default (5.0).
See sundials: IDASpilsSetMaxl

### Solver statistics

val get_work_space : ('d, 'k) Ida.session -> int * int
Returns the sizes of the real and integer workspaces used by the spils linear solver.
Returns (real_size, integer_size)
See sundials: IDASpilsGetWorkSpace
val get_num_lin_iters : ('d, 'k) Ida.session -> int
Returns the cumulative number of linear iterations.
See sundials: IDASpilsGetNumLinIters
val get_num_conv_fails : ('d, 'k) Ida.session -> int
Returns the cumulative number of linear convergence failures.
See sundials: IDASpilsGetNumConvFails
val get_num_prec_evals : ('d, 'k) Ida.session -> int
Returns the number of calls to the setup function.
See sundials: IDASpilsGetNumPrecEvals
val get_num_prec_solves : ('d, 'k) Ida.session -> int
Returns the cumulative number of calls to the preconditioner solve function.
See sundials: IDASpilsGetNumPrecSolves
val get_num_jtimes_evals : ('d, 'k) Ida.session -> int
Returns the cumulative number of calls to the Jacobian-vector function.
See sundials: IDASpilsGetNumJtimesEvals
val get_num_res_evals : ('d, 'k) Ida.session -> int
Returns the number of calls to the residual callback for finite difference Jacobian-vector product approximation. This counter is only updated if the default difference quotient function is used.
See sundials: IDASpilsGetNumResEvals

### Low-level solver manipulation

The Ida.init and Ida.reinit functions are the preferred way to set or change preconditioner functions. These low-level functions are provided for experts who want to avoid resetting internal counters and other associated side-effects.

val set_preconditioner : ('d, 'k) Ida.session ->
?setup:'d prec_setup_fn -> 'd prec_solve_fn -> unit
Change the preconditioner functions.
See sundials: IDASpilsSetPreconditioner
See sundials: IDASpilsPrecSolveFn
See sundials: IDASpilsPrecSetupFn
val set_jac_times_vec_fn : ('d, 'k) Ida.session -> 'd jac_times_vec_fn -> unit
Change the Jacobian-times-vector function.
See sundials: IDASpilsSetJacTimesVecFn
See sundials: IDASpilsJacTimesVecFn
val clear_jac_times_vec_fn : ('d, 'k) Ida.session -> unit
Remove a Jacobian-times-vector function and use the default implementation.
See sundials: IDASpilsSetJacTimesVecFn
See sundials: IDASpilsJacTimesVecFn