xref: /petsc/include/petscmat.h (revision 3eabe8db401bbff7041e223a9402ea67a1165093)
1 /* $Id: mat.h,v 1.135 1997/05/23 18:27:24 balay Exp bsmith $ */
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 _p_Mat*           Mat;
12 
13 #define MAX_MATRIX_TYPES 12
14 /*
15    The default matrix data storage formats and routines to create them.
16 */
17 typedef enum { MATSAME=-1,  MATSEQDENSE, MATSEQAIJ,   MATMPIAIJ,   MATSHELL,
18                MATMPIROWBS, MATSEQBDIAG, MATMPIBDIAG, MATMPIDENSE, MATSEQBAIJ,
19                MATMPIBAIJ,  MATMPICSN,   MATSEQCSN} MatType;
20 
21 extern int MatCreate(MPI_Comm,int,int,Mat*);
22 extern int MatCreateSeqDense(MPI_Comm,int,int,Scalar*,Mat*);
23 extern int MatCreateMPIDense(MPI_Comm,int,int,int,int,Scalar*,Mat*);
24 extern int MatCreateSeqAIJ(MPI_Comm,int,int,int,int*,Mat*);
25 extern int MatCreateMPIAIJ(MPI_Comm,int,int,int,int,int,int*,int,int*,Mat*);
26 extern int MatCreateMPIRowbs(MPI_Comm,int,int,int,int*,void*,Mat*);
27 extern int MatCreateSeqBDiag(MPI_Comm,int,int,int,int,int*,Scalar**,Mat*);
28 extern int MatCreateMPIBDiag(MPI_Comm,int,int,int,int,int,int*,Scalar**,Mat*);
29 extern int MatCreateSeqBAIJ(MPI_Comm,int,int,int,int,int*,Mat*);
30 extern int MatCreateMPIBAIJ(MPI_Comm,int,int,int,int,int,int,int*,int,int*,Mat*);
31 
32 extern int MatDestroy(Mat);
33 
34 extern int MatCreateShell(MPI_Comm,int,int,int,int,void *,Mat*);
35 extern int MatShellGetContext(Mat,void **);
36 
37 extern int MatPrintHelp(Mat);
38 
39 /* ------------------------------------------------------------*/
40 extern int MatSetValues(Mat,int,int*,int,int*,Scalar*,InsertMode);
41 extern int MatSetValuesBlocked(Mat,int,int*,int,int*,Scalar*,InsertMode);
42 
43 typedef enum {MAT_FLUSH_ASSEMBLY=1,MAT_FINAL_ASSEMBLY=0} MatAssemblyType;
44 extern int MatAssemblyBegin(Mat,MatAssemblyType);
45 extern int MatAssemblyEnd(Mat,MatAssemblyType);
46 #define MatSetValue(v,i,j,va,mode) \
47 {int _ierr,_row = i,_col = j; Scalar _va = va; \
48   _ierr = MatSetValues(v,1,&_row,1,&_col,&_va,mode);CHKERRQ(_ierr); \
49 }
50 
51 typedef enum {MAT_ROW_ORIENTED=1,MAT_COLUMN_ORIENTED=2,MAT_ROWS_SORTED=4,
52               MAT_COLUMNS_SORTED=8,MAT_NO_NEW_NONZERO_LOCATIONS=16,
53               MAT_YES_NEW_NONZERO_LOCATIONS=32,MAT_SYMMETRIC=64,
54               MAT_STRUCTURALLY_SYMMETRIC,MAT_NO_NEW_DIAGONALS,
55               MAT_YES_NEW_DIAGONALS,MAT_INODE_LIMIT_1,MAT_INODE_LIMIT_2,
56               MAT_INODE_LIMIT_3,MAT_INODE_LIMIT_4,MAT_INODE_LIMIT_5,
57               MAT_IGNORE_OFF_PROC_ENTRIES,MAT_ROWS_UNSORTED,
58               MAT_COLUMNS_UNSORTED,MAT_NEW_NONZERO_LOCATION_ERROR,
59               MAT_NEW_NONZERO_ALLOCATION_ERROR} MatOption;
60 extern int MatSetOption(Mat,MatOption);
61 extern int MatGetType(Mat,MatType*,char**);
62 extern int MatGetTypeFromOptions(MPI_Comm,char*,MatType*,int*);
63 
64 extern int MatGetValues(Mat,int,int*,int,int*,Scalar*);
65 extern int MatGetRow(Mat,int,int *,int **,Scalar**);
66 extern int MatRestoreRow(Mat,int,int *,int **,Scalar**);
67 extern int MatGetColumn(Mat,int,int *,int **,Scalar**);
68 extern int MatRestoreColumn(Mat,int,int *,int **,Scalar**);
69 extern int MatGetArray(Mat,Scalar **);
70 extern int MatRestoreArray(Mat,Scalar **);
71 extern int MatGetBlockSize(Mat,int *);
72 
73 extern int MatMult(Mat,Vec,Vec);
74 extern int MatMultAdd(Mat,Vec,Vec,Vec);
75 extern int MatMultTrans(Mat,Vec,Vec);
76 extern int MatMultTransAdd(Mat,Vec,Vec,Vec);
77 
78 extern int MatConvert(Mat,MatType,Mat*);
79 extern int MatConvertRegister(MatType,MatType,int (*)(Mat,MatType,Mat*));
80 extern int MatConvertRegisterAll();
81 
82 extern int MatCopy(Mat,Mat);
83 extern int MatView(Mat,Viewer);
84 extern int MatLoad(Viewer,MatType,Mat*);
85 extern int MatLoadRegister(MatType,int (*)(Viewer,MatType,Mat*));
86 extern int MatLoadRegisterAll();
87 
88 extern int MatGetRowIJ(Mat,int,PetscTruth,int*,int **,int **,PetscTruth *);
89 extern int MatRestoreRowIJ(Mat,int,PetscTruth,int *,int **,int **,PetscTruth *);
90 extern int MatGetColumnIJ(Mat,int,PetscTruth,int*,int **,int **,PetscTruth *);
91 extern int MatRestoreColumnIJ(Mat,int,PetscTruth,int *,int **,int **,PetscTruth *);
92 
93 /*
94    Context of matrix information, used with MatGetInfo()
95    Note: If any entries are added to this context, be sure
96          to adjust MAT_INFO_SIZE in FINCLUDE/mat.h
97  */
98 typedef struct {
99   PLogDouble rows_global, columns_global;         /* number of global rows and columns */
100   PLogDouble rows_local, columns_local;           /* number of local rows and columns */
101   PLogDouble block_size;                          /* block size */
102   PLogDouble nz_allocated, nz_used, nz_unneeded;  /* number of nonzeros */
103   PLogDouble memory;                              /* memory allocated */
104   PLogDouble assemblies;                          /* number of matrix assemblies */
105   PLogDouble mallocs;                             /* number of mallocs during MatSetValues() */
106   PLogDouble fill_ratio_given, fill_ratio_needed; /* fill ratio for LU/ILU */
107   PLogDouble factor_mallocs;                      /* number of mallocs during factorization */
108 } MatInfo;
109 
110 typedef enum {MAT_LOCAL=1,MAT_GLOBAL_MAX=2,MAT_GLOBAL_SUM=3} MatInfoType;
111 extern int MatGetInfo(Mat,MatInfoType,MatInfo*);
112 extern int MatValid(Mat,PetscTruth*);
113 extern int MatGetDiagonal(Mat,Vec);
114 extern int MatTranspose(Mat,Mat*);
115 extern int MatPermute(Mat,IS,IS,Mat *);
116 extern int MatDiagonalScale(Mat,Vec,Vec);
117 extern int MatDiagonalShift(Mat,Vec);
118 extern int MatEqual(Mat,Mat, PetscTruth*);
119 
120 extern int MatNorm(Mat,NormType,double *);
121 extern int MatZeroEntries(Mat);
122 extern int MatZeroRows(Mat,IS,Scalar*);
123 extern int MatZeroColumns(Mat,IS,Scalar*);
124 
125 extern int MatGetSize(Mat,int*,int*);
126 extern int MatGetLocalSize(Mat,int*,int*);
127 extern int MatGetOwnershipRange(Mat,int*,int*);
128 
129 typedef enum {MAT_INITIAL_MATRIX, MAT_REUSE_MATRIX} MatGetSubMatrixCall;
130 extern int MatGetSubMatrices(Mat,int,IS *,IS *,MatGetSubMatrixCall,Mat **);
131 extern int MatDestroyMatrices(int, Mat **);
132 extern int MatIncreaseOverlap(Mat,int,IS *,int);
133 
134 extern int MatAXPY(Scalar *,Mat,Mat);
135 extern int MatCompress(Mat);
136 
137 extern int MatScale(Scalar *,Mat);
138 extern int MatShift(Scalar *,Mat);
139 
140 extern int MatSetLocalToGlobalMapping(Mat, int,int *);
141 extern int MatSetLocalToGlobalMappingBlocked(Mat, int,int *);
142 extern int MatZeroRowsLocal(Mat,IS,Scalar*);
143 extern int MatSetValuesLocal(Mat,int,int*,int,int*,Scalar*,InsertMode);
144 extern int MatSetValuesBlockedLocal(Mat,int,int*,int,int*,Scalar*,InsertMode);
145 
146 /* Routines unique to particular data structures */
147 extern int MatBDiagGetData(Mat,int*,int*,int**,int**,Scalar***);
148 
149 /*
150   These routines are not usually accessed directly, rather solving is
151   done through the SLES, KSP and PC interfaces.
152 */
153 
154 typedef enum {ORDER_NATURAL=0,ORDER_ND=1,ORDER_1WD=2,ORDER_RCM=3,
155               ORDER_QMD=4,ORDER_ROWLENGTH=5,ORDER_FLOW,ORDER_NEW} MatReordering;
156 extern int MatGetReordering(Mat,MatReordering,IS*,IS*);
157 extern int MatGetReorderingTypeFromOptions(char *,MatReordering*);
158 extern int MatReorderingRegister(MatReordering,MatReordering*,char*,int(*)(Mat,MatReordering,IS*,IS*));
159 extern int MatReorderingGetName(MatReordering,char **);
160 extern int MatReorderingRegisterDestroy();
161 extern int MatReorderingRegisterAll();
162 extern int MatReorderingRegisterAllCalled;
163 
164 extern int MatReorderForNonzeroDiagonal(Mat,double,IS,IS);
165 
166 extern int MatCholeskyFactor(Mat,IS,double);
167 extern int MatCholeskyFactorSymbolic(Mat,IS,double,Mat*);
168 extern int MatCholeskyFactorNumeric(Mat,Mat*);
169 
170 extern int MatLUFactor(Mat,IS,IS,double);
171 extern int MatILUFactor(Mat,IS,IS,double,int);
172 extern int MatLUFactorSymbolic(Mat,IS,IS,double,Mat*);
173 extern int MatILUFactorSymbolic(Mat,IS,IS,double,int,Mat*);
174 extern int MatIncompleteCholeskyFactorSymbolic(Mat,IS,double,int,Mat*);
175 extern int MatLUFactorNumeric(Mat,Mat*);
176 extern int MatILUDTFactor(Mat,double,int,IS,IS,Mat *);
177 
178 extern int MatSolve(Mat,Vec,Vec);
179 extern int MatForwardSolve(Mat,Vec,Vec);
180 extern int MatBackwardSolve(Mat,Vec,Vec);
181 extern int MatSolveAdd(Mat,Vec,Vec,Vec);
182 extern int MatSolveTrans(Mat,Vec,Vec);
183 extern int MatSolveTransAdd(Mat,Vec,Vec,Vec);
184 
185 extern int MatSetUnfactored(Mat);
186 
187 typedef enum {SOR_FORWARD_SWEEP=1,SOR_BACKWARD_SWEEP=2,SOR_SYMMETRIC_SWEEP=3,
188               SOR_LOCAL_FORWARD_SWEEP=4,SOR_LOCAL_BACKWARD_SWEEP=8,
189               SOR_LOCAL_SYMMETRIC_SWEEP=12,SOR_ZERO_INITIAL_GUESS=16,
190               SOR_EISENSTAT=32,SOR_APPLY_UPPER=64,SOR_APPLY_LOWER=128} MatSORType;
191 extern int MatRelax(Mat,Vec,double,MatSORType,double,int,Vec);
192 
193 /*
194     These routines are for efficiently computing Jacobians via finite differences.
195 */
196 typedef enum {COLORING_NATURAL, COLORING_SL, COLORING_LF, COLORING_ID,
197               COLORING_NEW} MatColoring;
198 extern int MatGetColoring(Mat,MatColoring,ISColoring*);
199 extern int MatGetColoringTypeFromOptions(char *,MatColoring*);
200 extern int MatColoringRegister(MatColoring,MatColoring*,char*,int(*)(Mat,MatColoring,ISColoring *));
201 extern int MatColoringRegisterAll();
202 extern int MatColoringRegisterAllCalled;
203 extern int MatColoringRegisterDestroy();
204 extern int MatColoringPatch(Mat,int,int *,ISColoring*);
205 
206 /*
207     Data structures used to compute Jacobian vector products
208   efficiently using finite differences.
209 */
210 #define MAT_FDCOLORING_COOKIE PETSC_COOKIE + 22
211 
212 typedef struct _p_MatFDColoring *MatFDColoring;
213 
214 extern int MatFDColoringCreate(Mat,ISColoring,MatFDColoring *);
215 extern int MatFDColoringDestroy(MatFDColoring);
216 extern int MatFDColoringView(MatFDColoring,Viewer);
217 extern int MatFDColoringSetParameters(MatFDColoring,double,double);
218 extern int MatFDColoringSetFromOptions(MatFDColoring);
219 extern int MatFDColoringPrintHelp(MatFDColoring);
220 extern int MatFDColoringApply(Mat,MatFDColoring,Vec,Vec,Vec,Vec,int (*)(void *,Vec,Vec,void*),
221                               void *,void *);
222 
223 /*
224     If you add entries here you must also add them to FINCLUDE/mat.h
225 */
226 typedef enum { MATOP_SET_VALUES=0,
227                MATOP_GET_ROW=1,
228                MATOP_RESTORE_ROW=2,
229                MATOP_MULT=3,
230                MATOP_MULT_ADD=4,
231                MATOP_MULT_TRANS=5,
232                MATOP_MULT_TRANS_ADD=6,
233                MATOP_SOLVE=7,
234                MATOP_SOLVE_ADD=8,
235                MATOP_SOLVE_TRANS=9,
236                MATOP_SOLVE_TRANS_ADD=10,
237                MATOP_LUFACTOR=11,
238                MATOP_CHOLESKYFACTOR=12,
239                MATOP_RELAX=13,
240                MATOP_TRANSPOSE=14,
241                MATOP_GETINFO=15,
242                MATOP_EQUAL=16,
243                MATOP_GET_DIAGONAL=17,
244                MATOP_DIAGONAL_SCALE=18,
245                MATOP_NORM=19,
246                MATOP_ASSEMBLY_BEGIN=20,
247                MATOP_ASSEMBLY_END=21,
248                MATOP_COMPRESS=22,
249                MATOP_SET_OPTION=23,
250                MATOP_ZERO_ENTRIES=24,
251                MATOP_ZERO_ROWS=25,
252                MATOP_LUFACTOR_SYMBOLIC=26,
253                MATOP_LUFACTOR_NUMERIC=27,
254                MATOP_CHOLESKY_FACTOR_SYMBOLIC=28,
255                MATOP_CHOLESKY_FACTOR_NUMERIC=29,
256                MATOP_GET_SIZE=30,
257                MATOP_GET_LOCAL_SIZE=31,
258                MATOP_GET_OWNERSHIP_RANGE=32,
259                MATOP_ILUFACTOR_SYMBOLIC=33,
260                MATOP_INCOMPLETECHOLESKYFACTOR_SYMBOLIC=34,
261                MATOP_GET_ARRAY=35,
262                MATOP_RESTORE_ARRAY=36,
263 
264                MATOP_CONVERT_SAME_TYPE=39,
265                MATOP_FORWARD_SOLVE=40,
266                MATOP_BACKWARD_SOLVE=41,
267                MATOP_ILUFACTOR=42,
268                MATOP_INCOMPLETECHOLESKYFACTOR=43,
269                MATOP_AXPY=44,
270                MATOP_GET_SUBMATRICES=45,
271                MATOP_INCREASE_OVERLAP=46,
272                MATOP_GET_VALUES=47,
273                MATOP_COPY=48,
274                MATOP_PRINT_HELP=49,
275                MATOP_SCALE=50,
276                MATOP_SHIFT=51,
277                MATOP_DIAGONAL_SHIFT=52,
278                MATOP_ILUDT_FACTOR=53,
279                MATOP_GET_BLOCK_SIZE=54,
280                MATOP_GET_ROW_IJ=55,
281                MATOP_RESTORE_ROW_IJ=56,
282                MATOP_GET_COLUMN_IJ=57,
283                MATOP_RESTORE_COLUMN_IJ=58,
284                MATOP_FDCOLORING_CREATE=59,
285                MATOP_DESTROY=250,
286                MATOP_VIEW=251
287              } MatOperation;
288 extern int MatHasOperation(Mat,MatOperation,PetscTruth*);
289 extern int MatShellSetOperation(Mat,MatOperation,void *);
290 
291 /*
292    Codes for matrices stored on disk. By default they are
293  stored in a universal format. By changing the format with
294  ViewerSetFormat(viewer,VIEWER_FORMAT_BINARY_NATIVE); the matrices will
295  be stored in a way natural for the matrix, for example dense matrices
296  would be stored as dense. Matrices stored this way may only be
297  read into matrices of the same time.
298 */
299 #define MATRIX_BINARY_FORMAT_DENSE -1
300 
301 /*
302      New matrix classes not yet distributed
303 */
304 /*
305     MatAIJIndices is a data structure for storing the nonzero location information
306   for sparse matrices. Several matrices with identical nonzero structure can share
307   the same MatAIJIndices.
308 */
309 typedef struct _p_MatAIJIndices* MatAIJIndices;
310 
311 extern int MatCreateAIJIndices(int,int,int*,int*,PetscTruth,MatAIJIndices*);
312 extern int MatCreateAIJIndicesEmpty(int,int,int*,PetscTruth,MatAIJIndices*);
313 extern int MatAttachAIJIndices(MatAIJIndices,MatAIJIndices*);
314 extern int MatDestroyAIJIndices(MatAIJIndices);
315 extern int MatCopyAIJIndices(MatAIJIndices,MatAIJIndices*);
316 extern int MatValidateAIJIndices(int,MatAIJIndices);
317 extern int MatShiftAIJIndices(MatAIJIndices);
318 extern int MatShrinkAIJIndices(MatAIJIndices);
319 extern int MatTransposeAIJIndices(MatAIJIndices, MatAIJIndices*);
320 
321 extern int MatCreateSeqCSN(MPI_Comm,int,int,int*,int,Mat*);
322 extern int MatCreateSeqCSN_Single(MPI_Comm,int,int,int*,int,Mat*);
323 extern int MatCreateSeqCSNWithPrecision(MPI_Comm,int,int,int*,int,ScalarPrecision,Mat*);
324 
325 extern int MatCreateSeqCSNIndices(MPI_Comm,MatAIJIndices,int,Mat *);
326 extern int MatCreateSeqCSNIndices_Single(MPI_Comm,MatAIJIndices,int,Mat *);
327 extern int MatCreateSeqCSNIndicesWithPrecision(MPI_Comm,MatAIJIndices,int,ScalarPrecision,Mat *);
328 
329 
330 #endif
331 
332 
333 
334