LADEL main
Sparse LDL factorization package with rank 1 and rowadd/rowdel updates
ladel_ldl_numeric.c
Go to the documentation of this file.
1#include "ladel_types.h"
2#include "ladel_global.h"
3#include "ladel_constants.h"
4#include "ladel_pattern.h"
5#include "ladel_debug_print.h"
6
8{
9 if (!Mpp || !sym || !LD || !work) return FAIL;
10
11 ladel_int row, col, index, ncol = Mpp->ncol, start, index_in_pattern;
12 ladel_int *pattern = sym->pattern;
13 ladel_double diag_elem, temp, L_elem;
14
15 ladel_sparse_matrix *L = LD->L;
16 ladel_double *D = LD->D, *Dinv = LD->Dinv;
18 ladel_int *col_pointers = work->array_int_ncol1;
19
20 L->p[0] = col_pointers[0] = 0;
21 for (index = 1; index < ncol; index++)
22 L->p[index] = col_pointers[index] = sym->col_counts[index-1];
23
24 L->p[ncol] = sym->col_counts[ncol-1];
25
26 for (col = 0; col < ncol; col++)
27 {
28 LADEL_FOR(index, Mpp, col)
29 rhs[Mpp->i[index]] = Mpp->x[index];
30 diag_elem = rhs[col];
31 if ((LD->p && LD->p[col] < d.diag_size) || (!LD->p && col < d.diag_size)) diag_elem += d.diag_elem;
32 rhs[col] = 0;
33
34 start = ladel_nonzero_pattern_of_row_in_L(Mpp, sym, col);
35 for (index_in_pattern = start; index_in_pattern < ncol; index_in_pattern++)
36 {
37 row = pattern[index_in_pattern];
38 temp = rhs[row];
39 L_elem = Dinv[row]*temp; /*L(col,row) = rhs(row) / L(row,row) / D(row,row)*/
40 diag_elem -= L_elem*temp; /*D(col, col) -= L(col,row)*D(row,row)*L(col,row)*/
41 rhs[row] = 0;
42
43 /* Gaussian elimination */
44 for (index = L->p[row]; index < col_pointers[row]; index++)
45 rhs[L->i[index]] -= L->x[index]*temp;
46
47 index = col_pointers[row];
48 col_pointers[row]++;
49 L->i[index] = col;
50 L->x[index] = L_elem;
51 }
52 /*Return FAIL if eigenvalue (close to) zero*/
53 if (LADEL_ABS(diag_elem) < 1e-15)
54 {
55 ladel_print("LADEL ERROR: MATRIX (POSSIBLY) NOT FULL RANK (diagonal element of %le)\n", diag_elem);
56 return FAIL;
57 }
58
59 D[col] = diag_elem;
60 Dinv[col] = 1/diag_elem;
61 }
62
63 for (index = 0; index < ncol; index++) L->nz[index] = col_pointers[index] - L->p[index];
64 return SUCCESS;
65}
66
68{
69 ladel_diag d;
70 d.diag_elem = 0;
71 d.diag_size = 0;
72 return ladel_ldl_numeric_with_diag(Mpp, d, sym, LD, work);
73}
#define SUCCESS
For status returns.
#define FAIL
For status returns.
#define LADEL_FOR(index, M, col)
Loop through a column of a sparse matrix.
#define LADEL_ABS(a)
Return the absolute value a number.
Constants and macros used in LADEL.
Routines to print out matrices and vectors.
Memory allocation routines.
#define ladel_print
Print function.
Definition: ladel_global.h:97
ladel_int ladel_ldl_numeric(ladel_sparse_matrix *Mpp, ladel_symbolics *sym, ladel_factor *LD, ladel_work *work)
Numerical part of the factorization of .
ladel_int ladel_ldl_numeric_with_diag(ladel_sparse_matrix *Mpp, ladel_diag d, ladel_symbolics *sym, ladel_factor *LD, ladel_work *work)
Numerical part of the factorization of .
Routines to compute the pattern of the result of a backsolve.
ladel_int ladel_nonzero_pattern_of_row_in_L(ladel_sparse_matrix *M, ladel_symbolics *sym, ladel_int row)
Computes the pattern of the (next) row in L.
Definition: ladel_pattern.c:5
Structures and types used in LADEL routines.
int64_t ladel_int
Type for integer numbers (default: int64_t)
Definition: ladel_types.h:24
double ladel_double
Type for floating point numbers (default: double)
Definition: ladel_types.h:20
Sparse matrix in compressed column storage.
Definition: ladel_types.h:35
ladel_int ncol
number of columns
Definition: ladel_types.h:38
ladel_double * x
numerical values (size nzmax)
Definition: ladel_types.h:42
ladel_int * p
column pointers (size ncol+1)
Definition: ladel_types.h:40
ladel_int * nz
(optional) number of elements in each column (size ncol)
Definition: ladel_types.h:43
ladel_int * i
row pointers (size nzmax)
Definition: ladel_types.h:41
Structure representing a multiple of the identity matrix.
Definition: ladel_types.h:100
ladel_double diag_elem
Scalar.
Definition: ladel_types.h:101
ladel_int diag_size
Size of the matrix.
Definition: ladel_types.h:102
Factors of an factorization.
Definition: ladel_types.h:69
ladel_int * p
permutation vector
Definition: ladel_types.h:74
ladel_sparse_matrix * L
L in LDL' factorization.
Definition: ladel_types.h:71
ladel_double * Dinv
D^-1 in LDL' factorization (stored as vector)
Definition: ladel_types.h:73
ladel_double * D
D in LDL' factorization (stored as vector), not used but is useful for returning.
Definition: ladel_types.h:72
Structure capturing symbolic information used for and during the factorization.
Definition: ladel_types.h:54
ladel_int * pattern
stores the nonzero pattern of a row of L
Definition: ladel_types.h:61
ladel_int * col_counts
column counts, stored as column pointers
Definition: ladel_types.h:58
Workspace required for various routines in LADEL.
Definition: ladel_types.h:109
ladel_int * array_int_ncol1
An array of ncol integers.
Definition: ladel_types.h:116
ladel_double * array_double_all_zeros_ncol1
An array of ncol doubles, on input and output this should be all zeros.
Definition: ladel_types.h:122