xref: /petsc/include/petscmat.h (revision 4e220ebcc634eb0c8ccd78bed049803c9194c4d4)
1 /* $Id: mat.h,v 1.111 1996/08/06 04:04:29 bsmith Exp curfman $ */
2 /*
3      Include file for the matrix component of PETSc
4 */
5 #ifndef __MAT_PACKAGE
6 #define __MAT_PACKAGE
7 #include "vec.h"
8 
9 #define MAT_COOKIE         PETSC_COOKIE+5
10 
11 typedef struct _Mat*           Mat;
12 
13 typedef enum { MATSAME=-1, MATSEQDENSE, MATSEQAIJ, MATMPIAIJ, MATSHELL,
14                MATMPIROWBS, MATSEQBDIAG, MATMPIBDIAG,
15                MATMPIDENSE, MATSEQBAIJ, MATMPIBAIJ} MatType;
16 
17 extern int MatCreate(MPI_Comm,int,int,Mat*);
18 extern int MatCreateSeqDense(MPI_Comm,int,int,Scalar*,Mat*);
19 extern int MatCreateMPIDense(MPI_Comm,int,int,int,int,Scalar*,Mat*);
20 extern int MatCreateSeqAIJ(MPI_Comm,int,int,int,int*,Mat*);
21 extern int MatCreateMPIAIJ(MPI_Comm,int,int,int,int,int,int*,int,int*,Mat*);
22 extern int MatCreateMPIRowbs(MPI_Comm,int,int,int,int*,void*,Mat*);
23 extern int MatCreateSeqBDiag(MPI_Comm,int,int,int,int,int*,Scalar**,Mat*);
24 extern int MatCreateMPIBDiag(MPI_Comm,int,int,int,int,int,int*,Scalar**,Mat*);
25 extern int MatCreateSeqBAIJ(MPI_Comm,int,int,int,int,int*,Mat*);
26 extern int MatCreateMPIBAIJ(MPI_Comm,int,int,int,int,int,int,int*,int,int*,Mat*);
27 
28 extern int MatDestroy(Mat);
29 
30 extern int MatCreateShell(MPI_Comm,int,int,int,int,void *,Mat*);
31 extern int MatShellGetContext(Mat,void **);
32 
33 
34 extern int MatPrintHelp(Mat);
35 
36 /* ------------------------------------------------------------*/
37 extern int MatSetValues(Mat,int,int*,int,int*,Scalar*,InsertMode);
38 typedef enum {MAT_FLUSH_ASSEMBLY=1,MAT_FINAL_ASSEMBLY=0} MatAssemblyType;
39 extern int MatAssemblyBegin(Mat,MatAssemblyType);
40 extern int MatAssemblyEnd(Mat,MatAssemblyType);
41 
42 typedef enum {MAT_ROW_ORIENTED=1,MAT_COLUMN_ORIENTED=2,MAT_ROWS_SORTED=4,
43               MAT_COLUMNS_SORTED=8,MAT_NO_NEW_NONZERO_LOCATIONS=16,
44               MAT_YES_NEW_NONZERO_LOCATIONS=32,MAT_SYMMETRIC=64,
45               MAT_STRUCTURALLY_SYMMETRIC,MAT_NO_NEW_DIAGONALS,
46               MAT_YES_NEW_DIAGONALS,MAT_INODE_LIMIT_1,MAT_INODE_LIMIT_2,
47               MAT_INODE_LIMIT_3,MAT_INODE_LIMIT_4,MAT_INODE_LIMIT_5} MatOption;
48 extern int MatSetOption(Mat,MatOption);
49 extern int MatGetType(Mat,MatType*,char**);
50 extern int MatGetTypeFromOptions(MPI_Comm,char*,MatType*,int*);
51 extern int MatGetValues(Mat,int,int*,int,int*,Scalar*);
52 extern int MatGetRow(Mat,int,int *,int **,Scalar**);
53 extern int MatRestoreRow(Mat,int,int *,int **,Scalar**);
54 extern int MatGetColumn(Mat,int,int *,int **,Scalar**);
55 extern int MatRestoreColumn(Mat,int,int *,int **,Scalar**);
56 extern int MatGetArray(Mat,Scalar **);
57 extern int MatRestoreArray(Mat,Scalar **);
58 extern int MatGetBlockSize(Mat,int *);
59 
60 extern int MatMult(Mat,Vec,Vec);
61 extern int MatMultAdd(Mat,Vec,Vec,Vec);
62 extern int MatMultTrans(Mat,Vec,Vec);
63 extern int MatMultTransAdd(Mat,Vec,Vec,Vec);
64 
65 extern int MatConvert(Mat,MatType,Mat*);
66 extern int MatCopy(Mat,Mat);
67 extern int MatView(Mat,Viewer);
68 extern int MatLoad(Viewer,MatType,Mat*);
69 
70 /* Context of matrix information, used with MatGetInfo() */
71 typedef struct {
72   double rows_global, columns_global;         /* number of global rows and columns */
73   double rows_local, columns_local;           /* number of local rows and columns */
74   double block_size;                          /* block size */
75   double nz_allocated, nz_used, nz_unneeded;  /* number of nonzeros */
76   double memory;                              /* memory allocated */
77   double assemblies;                          /* number of matrix assemblies */
78   double mallocs;                             /* number of mallocs during MatSetValues() */
79   double fill_ratio_given, fill_ratio_needed; /* fill ration for LU/ILU */
80   double factor_mallocs;                      /* number of mallocs during factorization */
81 } MatInfo;
82 
83 typedef enum {MAT_LOCAL=1,MAT_GLOBAL_MAX=2,MAT_GLOBAL_SUM=3} MatInfoType;
84 extern int MatGetInfo(Mat,MatInfoType,MatInfo*);
85 extern int MatValid(Mat,PetscTruth*);
86 extern int MatGetDiagonal(Mat,Vec);
87 extern int MatTranspose(Mat,Mat*);
88 extern int MatDiagonalScale(Mat,Vec,Vec);
89 extern int MatDiagonalShift(Mat,Vec);
90 extern int MatEqual(Mat,Mat, PetscTruth*);
91 
92 extern int MatNorm(Mat,NormType,double *);
93 extern int MatZeroEntries(Mat);
94 extern int MatZeroRows(Mat,IS,Scalar*);
95 extern int MatZeroColumns(Mat,IS,Scalar*);
96 
97 extern int MatGetSize(Mat,int*,int*);
98 extern int MatGetLocalSize(Mat,int*,int*);
99 extern int MatGetOwnershipRange(Mat,int*,int*);
100 
101 typedef enum {MAT_INITIAL_MATRIX, MAT_REUSE_MATRIX} MatGetSubMatrixCall;
102 extern int MatGetSubMatrices(Mat,int,IS *,IS *,MatGetSubMatrixCall,Mat **);
103 extern int MatDestroyMatrices(int, Mat **);
104 extern int MatIncreaseOverlap(Mat,int,IS *,int);
105 
106 extern int MatAXPY(Scalar *,Mat,Mat);
107 extern int MatCompress(Mat);
108 
109 extern int MatScale(Scalar *,Mat);
110 extern int MatShift(Scalar *,Mat);
111 
112 /* Routines unique to particular data structures */
113 extern int MatBDiagGetData(Mat,int*,int*,int**,int**,Scalar***);
114 
115 /*
116   These routines are not usually accessed directly, rather solving is
117   done through the SLES, KSP and PC interfaces.
118 */
119 
120 typedef enum {ORDER_NATURAL=0,ORDER_ND=1,ORDER_1WD=2,
121               ORDER_RCM=3,ORDER_QMD=4,ORDER_ROWLENGTH=5,ORDER_FLOW,
122               ORDER_APPLICATION_1,ORDER_APPLICATION_2} MatReordering;
123 extern int MatGetReordering(Mat,MatReordering,IS*,IS*);
124 extern int MatGetReorderingTypeFromOptions(char *,MatReordering*);
125 extern int MatReorderingRegister(MatReordering *,char*,PetscTruth,int,
126                                  int (*)(int*,int*,int*,int*,int*));
127 extern int MatReorderingRegisterAll();
128 extern int MatReorderingRegisterDestroy();
129 extern int MatReorderingGetName(MatReordering,char **);
130 extern PetscTruth MatReorderingRequiresSymmetric[];
131 extern int MatReorderingIndexShift[];
132 
133 extern int MatReorderForNonzeroDiagonal(Mat,double,IS,IS);
134 
135 extern int MatCholeskyFactor(Mat,IS,double);
136 extern int MatCholeskyFactorSymbolic(Mat,IS,double,Mat*);
137 extern int MatCholeskyFactorNumeric(Mat,Mat*);
138 
139 extern int MatLUFactor(Mat,IS,IS,double);
140 extern int MatILUFactor(Mat,IS,IS,double,int);
141 extern int MatLUFactorSymbolic(Mat,IS,IS,double,Mat*);
142 extern int MatILUFactorSymbolic(Mat,IS,IS,double,int,Mat*);
143 extern int MatIncompleteCholeskyFactorSymbolic(Mat,IS,double,int,Mat*);
144 extern int MatLUFactorNumeric(Mat,Mat*);
145 extern int MatILUDTFactor(Mat,double,int,IS,IS,Mat *);
146 
147 
148 extern int MatSolve(Mat,Vec,Vec);
149 extern int MatForwardSolve(Mat,Vec,Vec);
150 extern int MatBackwardSolve(Mat,Vec,Vec);
151 extern int MatSolveAdd(Mat,Vec,Vec,Vec);
152 extern int MatSolveTrans(Mat,Vec,Vec);
153 extern int MatSolveTransAdd(Mat,Vec,Vec,Vec);
154 
155 typedef enum {SOR_FORWARD_SWEEP=1,SOR_BACKWARD_SWEEP=2,SOR_SYMMETRIC_SWEEP=3,
156               SOR_LOCAL_FORWARD_SWEEP=4,SOR_LOCAL_BACKWARD_SWEEP=8,
157               SOR_LOCAL_SYMMETRIC_SWEEP=12,SOR_ZERO_INITIAL_GUESS=16,
158               SOR_EISENSTAT=32,SOR_APPLY_UPPER=64,SOR_APPLY_LOWER=128
159               } MatSORType;
160 extern int MatRelax(Mat,Vec,double,MatSORType,double,int,Vec);
161 
162 typedef enum { MAT_SET_VALUES=0,
163                MAT_GET_ROW=1,
164                MAT_RESTORE_ROW=2,
165                MAT_MULT=3,
166                MAT_MULT_ADD=4,
167                MAT_MULT_TRANS=5,
168                MAT_MULT_TRANS_ADD=6,
169                MAT_SOLVE=7,
170                MAT_SOLVE_ADD=8,
171                MAT_SOLVE_TRANS=9,
172                MAT_SOLVE_TRANS_ADD=10,
173                MAT_LUFACTOR=11,
174                MAT_CHOLESKYFACTOR=12,
175                MAT_RELAX=13,
176                MAT_TRANSPOSE=14,
177                MAT_GETINFO=15,
178                MAT_EQUAL=16,
179                MAT_GET_DIAGONAL=17,
180                MAT_DIAGONAL_SCALE=18,
181                MAT_NORM=19,
182                MAT_ASSEMBLY_BEGIN=20,
183                MAT_ASSEMBLY_END=21,
184                MAT_COMPRESS=22,
185                MAT_SET_OPTION=23,
186                MAT_ZERO_ENTRIES=24,
187                MAT_ZERO_ROWS=25,
188                MAT_GET_REORDERING=26,
189                MAT_LUFACTOR_SYMBOLIC=27,
190                MAT_LUFACTOR_NUMERIC=28,
191                MAT_CHOLESKY_FACTOR_SYMBOLIC=29,
192                MAT_CHOLESKY_FACTOR_NUMERIC=30,
193                MAT_GET_SIZE=31,
194                MAT_GET_LOCAL_SIZE=32,
195                MAT_GET_OWNERSHIP_RANGE=33,
196                MAT_ILUFACTOR_SYMBOLIC=34,
197                MAT_INCOMPLETECHOLESKYFACTOR_SYMBOLIC=35,
198                MAT_GET_ARRAY=36,
199                MAT_RESTORE_ARRAY=37,
200                MAT_CONVERT=38,
201                MAT_GET_SUBMATRIX=39,
202                MAT_GET_SUBMATRIX_INPLACE=40,
203                MAT_CONVERT_SAME_TYPE=41,
204                MAT_FORWARD_SOLVE=42,
205                MAT_BACKWARD_SOLVE=43,
206                MAT_ILUFACTOR=44,
207                MAT_INCOMPLETECHOLESKYFACTOR=45,
208                MAT_AXPY=46,
209                MAT_GET_SUBMATRICES=47,
210                MAT_INCREASE_OVERLAP=48,
211                MAT_GET_VALUES=49,
212                MAT_COPY=50,
213                MAT_PRINT_HELP=51,
214                MAT_SCALE=52,
215                MAT_SHIFT=53,
216                MAT_DIAGONAL_SHIFT=54,
217                MAT_DESTROY=250,
218                MAT_VIEW=251
219              } MatOperation;
220 extern int MatHasOperation(Mat,MatOperation,PetscTruth*);
221 extern int MatShellSetOperation(Mat,MatOperation,void *);
222 
223 /*
224    Codes for matrices stored on disk. By default they are
225  stored in a universal format. By changing the format with
226  ViewerSetFormat(viewer,BINARY_FORMAT_NATIVE); the matrices will
227  be stored in a way natural for the matrix, for example dense matrices
228  would be stored as dense. Matrices stored this way may only be
229  read into matrices of the same time.
230 */
231 #define MATRIX_BINARY_FORMAT_DENSE -1
232 
233 #endif
234 
235 
236 
237