Ifpack Package Browser (Single Doxygen Collection)  Development
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Ifpack_IKLU_Utils.h
Go to the documentation of this file.
1 /*@HEADER
2 // ***********************************************************************
3 //
4 // Ifpack: Object-Oriented Algebraic Preconditioner Package
5 // Copyright (2002) Sandia Corporation
6 //
7 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
8 // license for use of this work by or on behalf of the U.S. Government.
9 //
10 // Redistribution and use in source and binary forms, with or without
11 // modification, are permitted provided that the following conditions are
12 // met:
13 //
14 // 1. Redistributions of source code must retain the above copyright
15 // notice, this list of conditions and the following disclaimer.
16 //
17 // 2. Redistributions in binary form must reproduce the above copyright
18 // notice, this list of conditions and the following disclaimer in the
19 // documentation and/or other materials provided with the distribution.
20 //
21 // 3. Neither the name of the Corporation nor the names of the
22 // contributors may be used to endorse or promote products derived from
23 // this software without specific prior written permission.
24 //
25 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
26 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
29 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
30 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
31 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
32 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 //
37 // Questions? Contact Michael A. Heroux (maherou@sandia.gov)
38 //
39 // ***********************************************************************
40 //@HEADER
41 */
42 
43 #ifndef IFPACK_IKLU_UTILS_H
44 #define IFPACK_IKLU_UTILS_H
45 
46 #if defined(Ifpack_SHOW_DEPRECATED_WARNINGS)
47 #ifdef __GNUC__
48 #warning "The Ifpack package is deprecated"
49 #endif
50 #endif
51 
52 #include <stdlib.h>
53 #include <limits.h>
54 #include <math.h>
55 #include <stdio.h>
56 
57 /* The code found in this file is adapted from CSparse Version 2.0.0
58  written by Tim Davis, UFL
59 */
60 
61 /* --- primary CSparse routines and data structures ------------------------- */
62 
63 typedef struct row_matrix /* matrix in compressed-row or triplet form */
64 {
65  int nzmax ; /* maximum number of entries */
66  int m ; /* number of rows */
67  int n ; /* number of columns */
68  int *p ; /* row pointers (size m+1) or col indices (size nzmax) */
69  int *j ; /* col indices, size nzmax */
70  double *x ; /* numerical values, size nzmax */
71  int nz ; /* # of entries in triplet matrix, -1 for compressed-row */
72 } csr ;
73 
74 csr *csr_add (const csr *A, const csr *B, double alpha, double beta) ;
75 csr *csr_multiply (const csr *A, const csr *B) ;
76 double csr_norm (const csr *A) ;
77 int csr_print (const csr *A, int brief) ;
78 csr *csr_transpose (const csr *A, int values) ;
79 
80 /* utilities */
81 void *csr_realloc (void *p, int n, size_t size, int *ok) ;
82 
83 /* csr utilities */
84 csr *csr_spalloc (int m, int n, int nzmax, int values, int triplet) ;
85 csr *csr_spfree (csr *A) ;
86 int csr_sprealloc (csr *A, int nzmax) ;
87 
88 
89 
90 /* --- secondary CSparse routines and data structures ----------------------- */
91 typedef struct cs_symbolic /* symbolic Cholesky, LU, or QR analysis */
92 {
93  int *pinv ; /* inverse row perm. for QR, fill red. perm for Chol */
94  int *q ; /* fill-reducing column permutation for LU and QR */
95  int *parent ; /* elimination tree for Cholesky and QR */
96  int *cp ; /* column pointers for Cholesky, row counts for QR */
97  int *leftmost ; /* leftmost[i] = min(find(A(i,:))), for QR */
98  int m2 ; /* # of rows for QR, after adding fictitious rows */
99  double lnz ; /* # entries in L for LU or Cholesky; in V for QR */
100  double unz ; /* # entries in U for LU; in R for QR */
101 } css ;
102 
103 typedef struct csr_numeric /* numeric Cholesky, LU, or QR factorization */
104 {
105  csr *L ; /* L for LU and Cholesky, V for QR */
106  csr *U ; /* U for LU, R for QR, not used for Cholesky */
107  int *pinv ; /* partial pivoting for LU */
108  int *perm ; /* partial pivoting for LU */
109  double *B ; /* beta [0..n-1] for QR */
110 } csrn ;
111 
112 typedef struct csr_dmperm_results /* csr_dmperm or csr_scc output */
113 {
114  int *p ; /* size m, row permutation */ /* may be back wards */
115  int *q ; /* size n, column permutation */
116  int *r ; /* size nb+1, block k is rows r[k] to r[k+1]-1 in A(p,q) */
117  int *s ; /* size nb+1, block k is cols s[k] to s[k+1]-1 in A(p,q) */
118  int nb ; /* # of blocks in fine dmperm decomposition */
119  int rr [5] ; /* coarse row decomposition */
120  int cc [5] ; /* coarse column decomposition */
121 } csrd ;
122 
123 int *csr_amd (int order, const csr *A) ;
124 
125 int csr_droptol (csr *A, double tol);
126 int csr_dropzeros (csr *A);
127 int csr_lsolve (const csr *L, double *x);
128 csrn *csr_lu (const csr *A, const css *S, double tol);
129 csr *csr_permute (const csr *A, const int *pinv, const int *q, int values);
130 css *csr_sqr (int order, const csr *A);
131 int csr_usolve (const csr *U, double *x);
132 
133 /* utilities */
134 css *csr_sfree (css *S) ;
135 csrd *csr_dfree (csrd *D);
136 csrn *csr_nfree (csrn *N);
137 
138 
139 
140 /* --- tertiary CSparse routines -------------------------------------------- */
141 double csr_cumsum (int *p, int *c, int n) ;
142 int csr_dfs (int j, csr *G, int top, int *xi, int *pstack, const int *pinv);
143 int csr_reach (csr *G, const csr *B, int k, int *xi, const int *pinv);
144 int csr_scatter (const csr *A, int j, double beta, int *w, double *x, int mark,
145  csr *C, int nz) ;
146 csrd *csr_scc (csr *A);
147 int csr_spsolve (csr *G, const csr *B, int k, int *xi,
148  double *x, const int *pinv, int up);
149 int csr_tdfs (int j, int k, int *head, const int *next, int *post,
150  int *stack) ;
151 /* utilities */
152 csrd *csr_dalloc (int m, int n);
153 /* csr utilities */
154 csrd *csr_ddone (csrd *D, csr *C, void *w, int ok) ;
155 csr *csr_done (csr *C, void *w, void *x, int ok) ;
156 int *csr_idone (int *p, csr *C, void *w, int ok) ;
157 csrn *csr_ndone (csrn *N, csr *C, void *w, void *x, int ok) ;
158 
159 int csr_fkeep (csr *A, int (*fkeep) (int, int, double, void *), void *other);
160 
161 #define CS_MAX(a,b) (((a) > (b)) ? (a) : (b))
162 #define CS_MIN(a,b) (((a) < (b)) ? (a) : (b))
163 #define CS_FLIP(i) (-(i)-2)
164 #define CS_UNFLIP(i) (((i) < 0) ? CS_FLIP(i) : (i))
165 #define CS_MARKED(w,j) (w [j] < 0)
166 #define CS_MARK(w,j) { w [j] = CS_FLIP (w [j]) ; }
167 #define CS_CSC(A) (A && (A->nz == -1))
168 #define CS_TRIPLET(A) (A && (A->nz >= 0))
169 
170 #endif // IFPACK_IKLU_UTILS_H
int * csr_amd(int order, const csr *A)
csrn * csr_lu(const csr *A, const css *S, double tol)
csrd * csr_dfree(csrd *D)
csrd * csr_dalloc(int m, int n)
csrn * csr_ndone(csrn *N, csr *C, void *w, void *x, int ok)
csr * csr_spfree(csr *A)
csr * csr_spalloc(int m, int n, int nzmax, int values, int triplet)
struct cs_symbolic css
int csr_sprealloc(csr *A, int nzmax)
int csr_tdfs(int j, int k, int *head, const int *next, int *post, int *stack)
csrd * csr_ddone(csrd *D, csr *C, void *w, int ok)
css * csr_sfree(css *S)
struct csr_dmperm_results csrd
int csr_droptol(csr *A, double tol)
csr * csr_permute(const csr *A, const int *pinv, const int *q, int values)
struct csr_numeric csrn
void * csr_realloc(void *p, int n, size_t size, int *ok)
const double tol
csrd * csr_scc(csr *A)
int csr_dropzeros(csr *A)
int csr_dfs(int j, csr *G, int top, int *xi, int *pstack, const int *pinv)
int csr_print(const csr *A, int brief)
csrn * csr_nfree(csrn *N)
csr * csr_done(csr *C, void *w, void *x, int ok)
const int N
csr * csr_add(const csr *A, const csr *B, double alpha, double beta)
int csr_fkeep(csr *A, int(*fkeep)(int, int, double, void *), void *other)
csr * csr_transpose(const csr *A, int values)
int * csr_idone(int *p, csr *C, void *w, int ok)
double csr_norm(const csr *A)
int csr_scatter(const csr *B, int i, double alpha, int *w, double *x, int mark, csr *C, int nz)
struct row_matrix csr
css * csr_sqr(int order, const csr *A)
int csr_usolve(const csr *U, double *x)
double csr_cumsum(int *p, int *c, int n)
int csr_spsolve(csr *G, const csr *B, int k, int *xi, double *x, const int *pinv, int up)
csr * csr_multiply(const csr *A, const csr *B)
int csr_reach(csr *G, const csr *B, int k, int *xi, const int *pinv)
int csr_lsolve(const csr *L, double *x)