|
IFPACK Development
|
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 // This library is free software; you can redistribute it and/or modify 00011 // it under the terms of the GNU Lesser General Public License as 00012 // published by the Free Software Foundation; either version 2.1 of the 00013 // License, or (at your option) any later version. 00014 // 00015 // This library is distributed in the hope that it will be useful, but 00016 // WITHOUT ANY WARRANTY; without even the implied warranty of 00017 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00018 // Lesser General Public License for more details. 00019 // 00020 // You should have received a copy of the GNU Lesser General Public 00021 // License along with this library; if not, write to the Free Software 00022 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 00023 // USA 00024 // Questions? Contact Michael A. Heroux (maherou@sandia.gov) 00025 // 00026 // *********************************************************************** 00027 //@HEADER 00028 */ 00029 00030 #ifndef IFPACK_IKLU_UTILS_H 00031 #define IFPACK_IKLU_UTILS_H 00032 00033 #include <stdlib.h> 00034 #include <limits.h> 00035 #include <math.h> 00036 #include <stdio.h> 00037 00038 /* The code found in this file is adapted from CSparse Version 2.0.0 00039 written by Tim Davis, UFL 00040 */ 00041 00042 /* --- primary CSparse routines and data structures ------------------------- */ 00043 00044 typedef struct row_matrix /* matrix in compressed-row or triplet form */ 00045 { 00046 int nzmax ; /* maximum number of entries */ 00047 int m ; /* number of rows */ 00048 int n ; /* number of columns */ 00049 int *p ; /* row pointers (size m+1) or col indices (size nzmax) */ 00050 int *j ; /* col indices, size nzmax */ 00051 double *x ; /* numerical values, size nzmax */ 00052 int nz ; /* # of entries in triplet matrix, -1 for compressed-row */ 00053 } csr ; 00054 00055 csr *csr_add (const csr *A, const csr *B, double alpha, double beta) ; 00056 csr *csr_multiply (const csr *A, const csr *B) ; 00057 double csr_norm (const csr *A) ; 00058 int csr_print (const csr *A, int brief) ; 00059 csr *csr_transpose (const csr *A, int values) ; 00060 00061 /* utilities */ 00062 void *csr_realloc (void *p, int n, size_t size, int *ok) ; 00063 00064 /* csr utilities */ 00065 csr *csr_spalloc (int m, int n, int nzmax, int values, int triplet) ; 00066 csr *csr_spfree (csr *A) ; 00067 int csr_sprealloc (csr *A, int nzmax) ; 00068 00069 00070 00071 /* --- secondary CSparse routines and data structures ----------------------- */ 00072 typedef struct cs_symbolic /* symbolic Cholesky, LU, or QR analysis */ 00073 { 00074 int *pinv ; /* inverse row perm. for QR, fill red. perm for Chol */ 00075 int *q ; /* fill-reducing column permutation for LU and QR */ 00076 int *parent ; /* elimination tree for Cholesky and QR */ 00077 int *cp ; /* column pointers for Cholesky, row counts for QR */ 00078 int *leftmost ; /* leftmost[i] = min(find(A(i,:))), for QR */ 00079 int m2 ; /* # of rows for QR, after adding fictitious rows */ 00080 double lnz ; /* # entries in L for LU or Cholesky; in V for QR */ 00081 double unz ; /* # entries in U for LU; in R for QR */ 00082 } css ; 00083 00084 typedef struct csr_numeric /* numeric Cholesky, LU, or QR factorization */ 00085 { 00086 csr *L ; /* L for LU and Cholesky, V for QR */ 00087 csr *U ; /* U for LU, R for QR, not used for Cholesky */ 00088 int *pinv ; /* partial pivoting for LU */ 00089 int *perm ; /* partial pivoting for LU */ 00090 double *B ; /* beta [0..n-1] for QR */ 00091 } csrn ; 00092 00093 typedef struct csr_dmperm_results /* csr_dmperm or csr_scc output */ 00094 { 00095 int *p ; /* size m, row permutation */ /* may be back wards */ 00096 int *q ; /* size n, column permutation */ 00097 int *r ; /* size nb+1, block k is rows r[k] to r[k+1]-1 in A(p,q) */ 00098 int *s ; /* size nb+1, block k is cols s[k] to s[k+1]-1 in A(p,q) */ 00099 int nb ; /* # of blocks in fine dmperm decomposition */ 00100 int rr [5] ; /* coarse row decomposition */ 00101 int cc [5] ; /* coarse column decomposition */ 00102 } csrd ; 00103 00104 int *csr_amd (int order, const csr *A) ; 00105 00106 int csr_droptol (csr *A, double tol); 00107 int csr_dropzeros (csr *A); 00108 int csr_lsolve (const csr *L, double *x); 00109 csrn *csr_lu (const csr *A, const css *S, double tol); 00110 csr *csr_permute (const csr *A, const int *pinv, const int *q, int values); 00111 css *csr_sqr (int order, const csr *A); 00112 int csr_usolve (const csr *U, double *x); 00113 00114 /* utilities */ 00115 css *csr_sfree (css *S) ; 00116 csrd *csr_dfree (csrd *D); 00117 csrn *csr_nfree (csrn *N); 00118 00119 00120 00121 /* --- tertiary CSparse routines -------------------------------------------- */ 00122 double csr_cumsum (int *p, int *c, int n) ; 00123 int csr_dfs (int j, csr *G, int top, int *xi, int *pstack, const int *pinv); 00124 int csr_reach (csr *G, const csr *B, int k, int *xi, const int *pinv); 00125 int csr_scatter (const csr *A, int j, double beta, int *w, double *x, int mark, 00126 csr *C, int nz) ; 00127 csrd *csr_scc (csr *A); 00128 int csr_spsolve (csr *G, const csr *B, int k, int *xi, 00129 double *x, const int *pinv, int up); 00130 int csr_tdfs (int j, int k, int *head, const int *next, int *post, 00131 int *stack) ; 00132 /* utilities */ 00133 csrd *csr_dalloc (int m, int n); 00134 /* csr utilities */ 00135 csrd *csr_ddone (csrd *D, csr *C, void *w, int ok) ; 00136 csr *csr_done (csr *C, void *w, void *x, int ok) ; 00137 int *csr_idone (int *p, csr *C, void *w, int ok) ; 00138 csrn *csr_ndone (csrn *N, csr *C, void *w, void *x, int ok) ; 00139 00140 int csr_fkeep (csr *A, int (*fkeep) (int, int, double, void *), void *other); 00141 00142 #define CS_MAX(a,b) (((a) > (b)) ? (a) : (b)) 00143 #define CS_MIN(a,b) (((a) < (b)) ? (a) : (b)) 00144 #define CS_FLIP(i) (-(i)-2) 00145 #define CS_UNFLIP(i) (((i) < 0) ? CS_FLIP(i) : (i)) 00146 #define CS_MARKED(w,j) (w [j] < 0) 00147 #define CS_MARK(w,j) { w [j] = CS_FLIP (w [j]) ; } 00148 #define CS_CSC(A) (A && (A->nz == -1)) 00149 #define CS_TRIPLET(A) (A && (A->nz >= 0)) 00150 00151 #endif // IFPACK_IKLU_UTILS_H
1.7.4