module Alternate:`sig`

..`end`

Alternate Linear Solvers.

See sundials: Providing Alternate Linear Solver Modules

`type `

conv_fail =

`|` |
`NoFailures` |
`(*` |
Either the first call for a step or the local error test
failed on the previous attempt at this setup but the Newton
iteration converged.
| `*)` |

`|` |
`FailBadJ` |
`(*` |
The setup routine indicates that its Jacobian related data is not
current and either the previous Newton corrector iteration did not
converge, or, during the previous Newton corrector iteration, the
linear solver's lsolve routine failed in a
recoverable manner.
| `*)` |

`|` |
`FailOther` |
`(*` |
The previous Newton iteration failed to converge even
though the linear solver was using current
Jacobian-related data.
| `*)` |

Indicates problems during the solution of nonlinear equations at a
step. Helps decide whether to update the Jacobian data kept by a
linear solver.

type`('data, 'kind)`

linit =`('data, 'kind) Cvode.session -> unit`

Functions that initialize linear solver data, like counters and
statistics.

Raising any exception in this function (including
`Sundials.RecoverableFailure`

) is treated as an unrecoverable error.

See sundials: linit

type`('data, 'kind)`

lsetup =`('data, 'kind) Cvode.session -> 'data lsetup_args -> bool`

Functions that prepare the linear solver for subsequent calls
to lsolve. This function must return

`true`

only if the Jacobian-related data is current after the call.
This function may raise a `Sundials.RecoverableFailure`

exception to
indicate that a recoverable error has occurred. Any other exception is
treated as an unrecoverable error.

The vectors

`ypred`

, `fpred`

, and those in `tmp`

should not be
accessed after the function returns.See sundials: lsetup

`type ``'data`

lsetup_args = {

` ` |
`lsetup_conv_fail : ` |
`(*` |
Indicates that a problem occurred during the solution of
the nonlinear equation at the current time step.
| `*)` |

` ` |
`lsetup_y : ` |
`(*` |
The predicted $y$ vector for the current internal step.
| `*)` |

` ` |
`lsetup_rhs : ` |
`(*` |
The value of the right-hand side at the predicted $y$ vector.
| `*)` |

` ` |
`lsetup_tmp : ` |
`(*` |
Temporary variables for use by the routine.
| `*)` |

Arguments to

`Cvode.Alternate.lsetup`

.type`('data, 'kind)`

lsolve =`('data, 'kind) Cvode.session ->`

'data lsolve_args -> 'data -> unit

Functions that solve the linear equation $Mx = b$.
$M$ is a preconditioning matrix chosen by the user, and $b$ is the
right-hand side vector calculated within the function.
$M$ should approximate $I - \gamma J$ where
$J = (\frac{\partial f}{\partial y})(t_n, y_{\text{cur}})$,
and $\gamma$ is available through

`Cvode.Alternate.get_gammas`

.
The call `lsolve s args b`

has as arguments:

`s`

, the solver session,`args`

, summarizing current approximations to the solution, and`b`

, for returning the calculated solution.

`Sundials.RecoverableFailure`

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

The vectors in

`Cvode.Alternate.lsolve_args`

should not be accessed
after the function returns.See sundials: lsolve

See sundials: IVP solution (Eq. 2.5)

`type ``'data`

lsolve_args = {

` ` |
`lsolve_ewt : ` |
`(*` |
The error weights.
| `*)` |

` ` |
`lsolve_y : ` |
`(*` |
The solver's current approximation to $y(t_n)$.
| `*)` |

` ` |
`lsolve_rhs : ` |
`(*` |
A vector containing $f(t_n, y_{\text{cur}})$.
| `*)` |

Arguments to

`Cvode.Alternate.lsolve`

.`type ``('data, 'kind)`

callbacks = {

` ` |
`linit : ` |

` ` |
`lsetup : ` |

` ` |
`lsolve : ` |

The callbacks needed to implement an alternate linear solver.

`val make : ``(('data, 'kind) Cvode.session ->`

('data, 'kind) Nvector.t -> ('data, 'kind) callbacks) ->

('data, 'kind) Cvode.linear_solver

Creates a linear solver from a function returning a set of
callbacks. The creation function is passed a session and a vector.
The latter indicates the problem size and can, for example, be
cloned.

`type `

gammas = {

` ` |
`gamma : ` |
`(*` |
The current $\gamma$ value.
| `*)` |

` ` |
`gammap : ` |
`(*` |
The value of $\gamma$ at the last setup call.
| `*)` |

Internal values used in Newton iteration.

See sundials: IVP Solution

`val get_gammas : ``('data, 'kind) Cvode.session -> gammas`

Returns the current and previous gamma values.