00001 /*@HEADER 00002 // *********************************************************************** 00003 // 00004 // Ifpack: Object-Oriented Algebraic Preconditioner Package 00005 // Copyright (2002) Sandia Corporation 00006 // 00007 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive 00008 // license for use of this work by or on behalf of the U.S. Government. 00009 // 00010 // Redistribution and use in source and binary forms, with or without 00011 // modification, are permitted provided that the following conditions are 00012 // met: 00013 // 00014 // 1. Redistributions of source code must retain the above copyright 00015 // notice, this list of conditions and the following disclaimer. 00016 // 00017 // 2. Redistributions in binary form must reproduce the above copyright 00018 // notice, this list of conditions and the following disclaimer in the 00019 // documentation and/or other materials provided with the distribution. 00020 // 00021 // 3. Neither the name of the Corporation nor the names of the 00022 // contributors may be used to endorse or promote products derived from 00023 // this software without specific prior written permission. 00024 // 00025 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY 00026 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00027 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 00028 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE 00029 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 00030 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 00031 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 00032 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 00033 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 00034 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 00035 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00036 // 00037 // Questions? Contact Michael A. Heroux (maherou@sandia.gov) 00038 // 00039 // *********************************************************************** 00040 //@HEADER 00041 */ 00042 00043 #ifndef IFPACK_IKLU_UTILS_H 00044 #define IFPACK_IKLU_UTILS_H 00045 00046 #include <stdlib.h> 00047 #include <limits.h> 00048 #include <math.h> 00049 #include <stdio.h> 00050 00051 /* The code found in this file is adapted from CSparse Version 2.0.0 00052 written by Tim Davis, UFL 00053 */ 00054 00055 /* --- primary CSparse routines and data structures ------------------------- */ 00056 00057 typedef struct row_matrix /* matrix in compressed-row or triplet form */ 00058 { 00059 int nzmax ; /* maximum number of entries */ 00060 int m ; /* number of rows */ 00061 int n ; /* number of columns */ 00062 int *p ; /* row pointers (size m+1) or col indices (size nzmax) */ 00063 int *j ; /* col indices, size nzmax */ 00064 double *x ; /* numerical values, size nzmax */ 00065 int nz ; /* # of entries in triplet matrix, -1 for compressed-row */ 00066 } csr ; 00067 00068 csr *csr_add (const csr *A, const csr *B, double alpha, double beta) ; 00069 csr *csr_multiply (const csr *A, const csr *B) ; 00070 double csr_norm (const csr *A) ; 00071 int csr_print (const csr *A, int brief) ; 00072 csr *csr_transpose (const csr *A, int values) ; 00073 00074 /* utilities */ 00075 void *csr_realloc (void *p, int n, size_t size, int *ok) ; 00076 00077 /* csr utilities */ 00078 csr *csr_spalloc (int m, int n, int nzmax, int values, int triplet) ; 00079 csr *csr_spfree (csr *A) ; 00080 int csr_sprealloc (csr *A, int nzmax) ; 00081 00082 00083 00084 /* --- secondary CSparse routines and data structures ----------------------- */ 00085 typedef struct cs_symbolic /* symbolic Cholesky, LU, or QR analysis */ 00086 { 00087 int *pinv ; /* inverse row perm. for QR, fill red. perm for Chol */ 00088 int *q ; /* fill-reducing column permutation for LU and QR */ 00089 int *parent ; /* elimination tree for Cholesky and QR */ 00090 int *cp ; /* column pointers for Cholesky, row counts for QR */ 00091 int *leftmost ; /* leftmost[i] = min(find(A(i,:))), for QR */ 00092 int m2 ; /* # of rows for QR, after adding fictitious rows */ 00093 double lnz ; /* # entries in L for LU or Cholesky; in V for QR */ 00094 double unz ; /* # entries in U for LU; in R for QR */ 00095 } css ; 00096 00097 typedef struct csr_numeric /* numeric Cholesky, LU, or QR factorization */ 00098 { 00099 csr *L ; /* L for LU and Cholesky, V for QR */ 00100 csr *U ; /* U for LU, R for QR, not used for Cholesky */ 00101 int *pinv ; /* partial pivoting for LU */ 00102 int *perm ; /* partial pivoting for LU */ 00103 double *B ; /* beta [0..n-1] for QR */ 00104 } csrn ; 00105 00106 typedef struct csr_dmperm_results /* csr_dmperm or csr_scc output */ 00107 { 00108 int *p ; /* size m, row permutation */ /* may be back wards */ 00109 int *q ; /* size n, column permutation */ 00110 int *r ; /* size nb+1, block k is rows r[k] to r[k+1]-1 in A(p,q) */ 00111 int *s ; /* size nb+1, block k is cols s[k] to s[k+1]-1 in A(p,q) */ 00112 int nb ; /* # of blocks in fine dmperm decomposition */ 00113 int rr [5] ; /* coarse row decomposition */ 00114 int cc [5] ; /* coarse column decomposition */ 00115 } csrd ; 00116 00117 int *csr_amd (int order, const csr *A) ; 00118 00119 int csr_droptol (csr *A, double tol); 00120 int csr_dropzeros (csr *A); 00121 int csr_lsolve (const csr *L, double *x); 00122 csrn *csr_lu (const csr *A, const css *S, double tol); 00123 csr *csr_permute (const csr *A, const int *pinv, const int *q, int values); 00124 css *csr_sqr (int order, const csr *A); 00125 int csr_usolve (const csr *U, double *x); 00126 00127 /* utilities */ 00128 css *csr_sfree (css *S) ; 00129 csrd *csr_dfree (csrd *D); 00130 csrn *csr_nfree (csrn *N); 00131 00132 00133 00134 /* --- tertiary CSparse routines -------------------------------------------- */ 00135 double csr_cumsum (int *p, int *c, int n) ; 00136 int csr_dfs (int j, csr *G, int top, int *xi, int *pstack, const int *pinv); 00137 int csr_reach (csr *G, const csr *B, int k, int *xi, const int *pinv); 00138 int csr_scatter (const csr *A, int j, double beta, int *w, double *x, int mark, 00139 csr *C, int nz) ; 00140 csrd *csr_scc (csr *A); 00141 int csr_spsolve (csr *G, const csr *B, int k, int *xi, 00142 double *x, const int *pinv, int up); 00143 int csr_tdfs (int j, int k, int *head, const int *next, int *post, 00144 int *stack) ; 00145 /* utilities */ 00146 csrd *csr_dalloc (int m, int n); 00147 /* csr utilities */ 00148 csrd *csr_ddone (csrd *D, csr *C, void *w, int ok) ; 00149 csr *csr_done (csr *C, void *w, void *x, int ok) ; 00150 int *csr_idone (int *p, csr *C, void *w, int ok) ; 00151 csrn *csr_ndone (csrn *N, csr *C, void *w, void *x, int ok) ; 00152 00153 int csr_fkeep (csr *A, int (*fkeep) (int, int, double, void *), void *other); 00154 00155 #define CS_MAX(a,b) (((a) > (b)) ? (a) : (b)) 00156 #define CS_MIN(a,b) (((a) < (b)) ? (a) : (b)) 00157 #define CS_FLIP(i) (-(i)-2) 00158 #define CS_UNFLIP(i) (((i) < 0) ? CS_FLIP(i) : (i)) 00159 #define CS_MARKED(w,j) (w [j] < 0) 00160 #define CS_MARK(w,j) { w [j] = CS_FLIP (w [j]) ; } 00161 #define CS_CSC(A) (A && (A->nz == -1)) 00162 #define CS_TRIPLET(A) (A && (A->nz >= 0)) 00163 00164 #endif // IFPACK_IKLU_UTILS_H
1.7.6.1