module Sundials_NonlinearSolver:sig
..end
Generic nonlinear solvers.
Sundials provides generic nonlinear solvers of two main types:
Sundials_NonlinearSolver.Newton
and Sundials_NonlinearSolver.FixedPoint
. An instance of a nonlinear
solver may only be associated with at most one integrator session at
a time.
This module supports calling both Sundials and custom OCaml nonlinear solvers from both Sundials integrators and OCaml applications.
This documentation is structured as follows.
type('data, 'kind, 's, 'v)
t =('data, 'kind, 's, 'v) nonlinear_solver
A generic nonlinear solver. The type variables specify
'data
, the Nvector.nvector
data,'kind
, the Nvector.nvector
kind,'s
, the type of of session data to be passed
into the nonlinear solver and through to callbacks, and,'v
, a type indicating that the solver manipulates nvectors (`Nvec
)
or senswrappers (`Sens
).module Senswrapper:sig
..end
A limited interface to arrays of Nvector.nvector
s required
to apply nonlinear solvers to sensitivity problems.
type
nonlinear_solver_type =
| |
RootFind |
(* | Solves $F(y) = 0$ | *) |
| |
FixedPoint |
(* | Solves $G(y) = y$ | *) |
The problem specification expected by a nonlinear solver.
val get_type : ('d, 'k, 's, 'v) t ->
nonlinear_solver_type
Returns the type of a nonlinear solver.
val init : ('d, 'k, 's, 'v) t -> unit
Initializes a nonlinear solver.
val setup : ('d, 'k, 's, [ `Nvec ]) t ->
y:('d, 'k) Nvector.t -> 's -> unit
Setup a nonlinear solver with an initial iteration value.
val solve : ('d, 'k, 's, [ `Nvec ]) t ->
y0:('d, 'k) Nvector.t ->
ycor:('d, 'k) Nvector.t ->
w:('d, 'k) Nvector.t -> float -> bool -> 's -> unit
Solves a nonlinear system.
The call solve ls ~y0 ~y ~w tol callLSetup s
solves the
nonlinear system $F(y) = 0$ or $G(y) = y$ , given the following
arguments.
y0
, a predicted value for the new solution state (which must not be
modified),ycor
, on input, an initial guess for the correction to the predicted
states, and on output, the final correction to the predicted state,w
, a solution error-weight vector used for computing weighted error
norms,tol
, the requested solution tolerance in the weighted
root-mean-squared norm,callLSetup
, a flag indicating whether the integrator recommends
calling the setup function, and,s
, the state to pass through to callbacks.type('nv, 's)
sysfn ='nv -> 'nv -> 's -> unit
A function sysfn y fg mem
to evaluate the nonlinear system
$F(y)$ (for RootFind)
or $G(y)$ (for FixedPoint).
The contents of y
must not be modified.
This function raises Sundials.RecoverableFailure
to
indicate a recoverable failure. Other exceptions signal unrecoverable
failures.
val set_sys_fn : ('d, 'k, 's, [ `Nvec ]) t ->
('d, 's) sysfn -> unit
Specify a system function callback. The system function specifies the problem, either $F(y)$ or $G(y)$ .
type's
lsetupfn =bool -> 's -> bool
A function to setup linear solves. For direct linear solvers, sets up the system $Ax = b$ where $A = \frac{\partial F}{\partial y}$ is the linearization of the nonlinear residual function $F(y) = 0$ . For iterative linear solvers, calls a preconditioner setup function.
The call jcur = lsetupfn jbad mem
has as arguments jbad
, which
indicates if the solver believes that $A$ has gone stale, and mem
,
a token passed by the function provider. A true return value (jcur
)
signals that the Jacobian $A$ has been updated.
This function raises Sundials.RecoverableFailure
to
indicate a recoverable failure. Other exceptions signal unrecoverable
failures.
val set_lsetup_fn : ('d, 'k, 's, 'v) t ->
's lsetupfn -> unit
Specify a linear solver setup callback.
type('nv, 's)
lsolvefn ='nv -> 's -> unit
A function to solve linear systems. Solves the system $Ax = b$ where $A = \frac{\partial F}{\partial y}$ is the linearization of the nonlinear residual function $F(y)= 0$ .
The call lsolvefn b mem
has as arguments
b
, on input: the right-hand-side vector for the linear solve,
set on output to the solution $x$ ; and,mem
, a token passed by the function provider.This function raises Sundials.RecoverableFailure
to
indicate a recoverable failure. Other exceptions signal unrecoverable
failures.
val set_lsolve_fn : ('d, 'k, 's, [ `Nvec ]) t ->
('d, 's) lsolvefn -> unit
Specify a linear solver callback.
type
convtest =
| |
Success |
(* | Converged ( | *) |
| |
Continue |
(* | Not converged, keep iterating ( | *) |
| |
Recover |
(* | Appears to diverge, try to recover ( | *) |
Values returned by convergence tests.
type('nv, 's)
convtestfn' ='nv -> 'nv -> float -> 'nv -> 's -> convtest
A function providing a convergence test.
The call convtestfn y del tol ewt mem
has as arguments
y
, the current nonlinear iterate,del
, the difference between current and prior nonlinear iterates,tol
, the nonlinear solver tolerance (in a weighted root-mean-squared
norm with the given error-weight vector),ewt
, the error-weight vector used in computing weighted norms, and,mem
, a token passed by the function provider.type 's
convtest_callback = {
|
f : |
}
A convergence test callback provided by an integrator. Such callbacks require an additional first argument, the nonlinear solver invoking the function, and otherwise expect nvector arguments. They access the linear solver and nvector arguments using generic functions, which is why the type variables are universally quantified.
type 's
convtest_callback_sens = {
|
f : |
}
A convergence test callback provided by an integrator with sensitivities. Such callbacks require an additional first argument, the nonlinear solver invoking the function, and otherwise expect senswrapper arguments. They access the linear solver and senswrapper arguments using generic functions, which is why the type variables are universally quantified.
type ('nv, 's, 'v)
convtestfn =
| |
CConvTest : |
| |
CSensConvTest : |
| |
OConvTest of |
A convergence test provided either by an integrator or a user program.
The OCaml interface distinguishes callback functions set by the
underlying library (CConvTest
) from those supplied by user programs
(OConvTest
). This reflects the different underlying mechanisms used
to create and invoke such functions. Callback functions provied by the
underlying library can be invoked with any kind of linear solver and
(homogeneous) nvectors since they manipulate these values generically.
val assert_not_oconvtestfn : ('nv1, 's, [ `Nvec ]) convtestfn ->
('nv2, 's, [ `Nvec ]) convtestfn
Ignore the nvector type argument in a convtestfn.
Invalid_argument
if the value was constructed with OConvTest
val set_convtest_fn : ('d, 'k, 's, [ `Nvec ]) t ->
('d, 's, [ `Nvec ]) convtestfn -> unit
Specify a convergence test callback for the nonlinear solver iteration.
module Sens:sig
..end
Support for nonlinear solvers with sensitivities.
val set_max_iters : ('d, 'k, 's, 'v) t -> int -> unit
Sets the maximum number of nonlinear solver iterations.
val set_info_file : ('d, 'k, 's, 'v) t ->
?print_level:bool -> Sundials.Logfile.t -> unit
Sets the output file for informative (non-error) messages. The default
is to send such messages to stdout.
The optional argument is a convenience for invoking Sundials_NonlinearSolver.set_print_level
.
Sundials must be built with (SUNDIALS_BUILD_WITH_MONITORING) to use this function.
val set_print_level : ('d, 'k, 's, 'v) t -> bool -> unit
Sets the level of output verbosity. When false
(the default) no
information is printed, when true
the residual norm is printed for
each nonlinear iteration.
Sundials must be built with (SUNDIALS_BUILD_WITH_MONITORING) to use this function.
val get_num_iters : ('d, 'k, 's, 'v) t -> int
Returns the number of nonlinear solver iterations in the most recent solve.
val get_cur_iter : ('d, 'k, 's, 'v) t -> int
Returns the iteration index of the current nonlinear solve.
val get_num_conv_fails : ('d, 'k, 's, 'v) t -> int
Returns the number of nonlinear solver convergence failures in the most recent solve.
module Newton:sig
..end
Generic nonlinear solver based on Newton's method.
module FixedPoint:sig
..end
Generic nonlinear solver for fixed-point (functional) iteration with optional Anderson acceleration.
module Custom:sig
..end
Custom nonlinear solvers.
exception VectorOpError
An error occurred in a vector operation.
exception IncorrectUse
Raised when a nonlinear solver is used incorrectly.
For example, calling Sundials_NonlinearSolver.solve
without having first called Sundials_NonlinearSolver.set_sys_fn
(SUN_NLS_MEM_NULL
).
exception ExtFail
Raised if an external library call fails.
exception NonlinearSolverInUse
Raised on an attempt to associate a nonlinear solver instance with more than one session.