Sparse direct minimum-norm linear solver, using a Cholesky factorization of (no external dependencies).
Computes the minimum-norm solution of the compatible system ,
where A is an m x n sparse matrix (normally n >= m) in coordinate (triplet) format:
With damp , this is the solution of the regularized problem
subject to
(useful if A is rank deficient).
A change, see factor):
is formed directly in the envelope storage from the sparse
rows of A (the dense matrix is never formed), and factored as
using a row-oriented envelope Cholesky factorization.L, followed
by x = A^T y. Since forming squares the condition number, a few steps
of iterative refinement are performed using the residual of the original system.
Each correction stays in the range of , so the minimum-norm property is kept.The cost of the factorization is , where b is the (average) bandwidth
of the reordered . This is very efficient for banded or "mostly banded"
Jacobians (even if the rows are not numbered in banded order). For general sparse
matrices with large fill-in (e.g., 2D/3D meshes), a nested-dissection based solver
(such as qr_mumps) will be faster.
| Type | Visibility | Attributes | Name | Initial | |||
|---|---|---|---|---|---|---|---|
| integer, | private, | parameter | :: | wp | = | real64 |
real kind used by this module [8 bytes] |
| integer, | private, | parameter | :: | ip | = | int64 |
integer kind for indexing the envelope storage |
| real(kind=wp), | private, | parameter | :: | zero | = | 0.0_wp | |
| real(kind=wp), | private, | parameter | :: | eps | = | epsilon(1.0_wp) | |
| integer, | public, | parameter | :: | CHOLESKY_SUCCESS | = | 0 |
success |
| integer, | public, | parameter | :: | CHOLESKY_ERR_INPUT | = | -1 |
invalid inputs (e.g., |
| integer, | public, | parameter | :: | CHOLESKY_ERR_MEMORY | = | -2 |
out of memory (envelope too large) |
| integer, | public, | parameter | :: | CHOLESKY_ERR_NOT_PD | = | -3 |
is not positive definite ( |
| integer, | public, | parameter | :: | CHOLESKY_ERR_NOT_READY | = | -4 |
|
Sparse direct minimum-norm solver class.
| Type | Visibility | Attributes | Name | Initial | |||
|---|---|---|---|---|---|---|---|
| logical, | private | :: | analyzed | = | .false. |
if |
|
| logical, | private | :: | factored | = | .false. |
if |
|
| integer, | private | :: | m | = | 0 |
number of rows in |
|
| integer, | private | :: | n | = | 0 |
number of columns in |
|
| integer, | private | :: | nnz | = | 0 |
number of nonzeros in |
|
| real(kind=wp), | private | :: | damp | = | zero |
damping parameter used in the factorization |
|
| integer, | private, | dimension(:), allocatable | :: | rowptr |
row pointers (size |
||
| integer, | private, | dimension(:), allocatable | :: | colidx |
column indices (size |
||
| integer, | private, | dimension(:), allocatable | :: | map |
index into the user's |
||
| real(kind=wp), | private, | dimension(:), allocatable | :: | val |
values of |
||
| integer, | private, | dimension(:), allocatable | :: | adjptr |
(size |
||
| integer, | private, | dimension(:), allocatable | :: | adj |
(size |
||
| integer, | private, | dimension(:), allocatable | :: | perm |
|
||
| integer, | private, | dimension(:), allocatable | :: | iperm |
|
||
| integer, | private, | dimension(:), allocatable | :: | first |
first column in each row (size |
||
| integer(kind=ip), | private, | dimension(:), allocatable | :: | ptr |
start of each row in |
||
| real(kind=wp), | private, | dimension(:), allocatable | :: | env |
envelope values |
| procedure, public :: analyze | |
| procedure, public :: factor | |
| procedure, public :: solve | |
| procedure, public :: destroy | |
| procedure, public :: is_analyzed | |
| procedure, public :: envelope_size | |
| procedure, public :: bandwidth | |
| procedure, public :: get_permutation | |
| procedure, private :: lower_solve |
Returns true if analyze has been called successfully.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| class(cholesky_minnorm_solver), | intent(in) | :: | me |
Number of elements in the envelope of the Cholesky factor
(i.e., the storage required for L, in reals). Returns 0 if not analyzed.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| class(cholesky_minnorm_solver), | intent(in) | :: | me |
Maximum bandwidth of the reordered . Returns -1 if not analyzed.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| class(cholesky_minnorm_solver), | intent(in) | :: | me |
Destroy the solver (deallocate all the arrays).
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| class(cholesky_minnorm_solver), | intent(out) | :: | me |
Returns the row ordering computed by analyze:
perm(new) = old. Returns an unallocated array if not analyzed.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| class(cholesky_minnorm_solver), | intent(in) | :: | me | |||
| integer, | intent(out), | dimension(:), allocatable | :: | perm |
Symbolic analysis of the sparsity pattern of A.
This only has to be called once for a given sparsity pattern.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| class(cholesky_minnorm_solver), | intent(inout) | :: | me | |||
| integer, | intent(in) | :: | m |
number of rows in |
||
| integer, | intent(in) | :: | n |
number of columns in |
||
| integer, | intent(in), | dimension(:) | :: | irow |
row indices of the nonzero elements of |
|
| integer, | intent(in), | dimension(:) | :: | icol |
column indices of the nonzero elements of |
|
| integer, | intent(out) | :: | istat |
status code ( |
Reverse Cuthill-McKee ordering of a symmetric graph.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| integer, | intent(in) | :: | m |
number of nodes |
||
| integer, | intent(in), | dimension(:) | :: | adjptr |
adjacency pointers (size |
|
| integer, | intent(in), | dimension(:) | :: | adj |
adjacency lists |
|
| integer, | intent(out), | dimension(m) | :: | perm |
the ordering: |
Numeric factorization: form in the envelope storage and compute its Cholesky factorization .
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| class(cholesky_minnorm_solver), | intent(inout) | :: | me | |||
| real(kind=wp), | intent(in), | dimension(:) | :: | a |
nonzero elements of |
|
| real(kind=wp), | intent(in) | :: | damp |
damping parameter ( |
||
| integer, | intent(out) | :: | istat |
status code ( |
Solve using the Cholesky factor.
c and y are in the original row ordering.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| class(cholesky_minnorm_solver), | intent(in) | :: | me | |||
| real(kind=wp), | intent(in), | dimension(me%m) | :: | c | ||
| real(kind=wp), | intent(out), | dimension(me%m) | :: | y |
Solve for the minimum-norm solution: , .
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| class(cholesky_minnorm_solver), | intent(inout) | :: | me | |||
| real(kind=wp), | intent(in), | dimension(:) | :: | b |
right-hand side (size |
|
| real(kind=wp), | intent(out), | dimension(:) | :: | x |
minimum-norm solution (size |
|
| integer, | intent(out) | :: | istat |
status code ( |
||
| integer, | intent(in), | optional | :: | n_refine |
maximum number of iterative refinement steps (default is 2) |
|
| real(kind=wp), | intent(out), | optional | :: | rnorm |
final residual norm |