xref: /petsc/include/petscmat.h (revision b5758dff40dc4232f7fa9713b5481f7e0e0d5d24)
1 /* $Id: petscmat.h,v 1.213 2001/01/19 23:20:23 balay Exp bsmith $ */
2 /*
3      Include file for the matrix component of PETSc
4 */
5 #ifndef __PETSCMAT_H
6 #define __PETSCMAT_H
7 #include "petscvec.h"
8 
9 #define MAT_COOKIE         PETSC_COOKIE+5
10 
11 /*S
12      Mat - Abstract PETSc matrix object
13 
14    Level: beginner
15 
16   Concepts: matrix; linear operator
17 
18 .seealso:  MatCreate(), MatType, MatSetType()
19 S*/
20 typedef struct _p_Mat*           Mat;
21 
22 /*E
23     MatType - String with the name of a PETSc matrix or the creation function
24        with an optional dynamic library name, for example
25        http://www.mcs.anl.gov/petsc/lib.a:mymatcreate()
26 
27    Level: beginner
28 
29 .seealso: MatSetType(), Mat
30 E*/
31 #define MATSAME     "same"
32 #define MATSEQMAIJ  "seqmaij"
33 #define MATMPIMAIJ  "mpimaij"
34 #define MATIS       "is"
35 #define MATMPIROWBS "mpirowbs"
36 #define MATSEQDENSE "seqdense"
37 #define MATSEQAIJ   "seqaij"
38 #define MATMPIAIJ   "mpiaij"
39 #define MATSHELL    "shell"
40 #define MATSEQBDIAG "seqbdiag"
41 #define MATMPIBDIAG "mpibdiag"
42 #define MATMPIDENSE "mpidense"
43 #define MATSEQBAIJ  "seqbaij"
44 #define MATMPIBAIJ  "mpibaij"
45 #define MATMPIADJ   "mpiadj"
46 #define MATSEQSBAIJ "seqsbaij"
47 #define MATMPISBAIJ "mpisbaij"
48 typedef char* MatType;
49 
50 EXTERN int MatCreate(MPI_Comm,int,int,int,int,Mat*);
51 EXTERN int MatSetType(Mat,MatType);
52 EXTERN int MatSetFromOptions(Mat);
53 EXTERN int MatSetUpPreallocation(Mat);
54 EXTERN int MatRegisterAll(char*);
55 EXTERN int MatRegister(char*,char*,char*,int(*)(Mat));
56 #if defined(PETSC_USE_DYNAMIC_LIBRARIES)
57 #define MatRegisterDynamic(a,b,c,d) MatRegister(a,b,c,0)
58 #else
59 #define MatRegisterDynamic(a,b,c,d) MatRegister(a,b,c,d)
60 #endif
61 extern PetscTruth MatRegisterAllCalled;
62 extern PetscFList      MatList;
63 
64 EXTERN int MatCreate(MPI_Comm,int,int,int,int,Mat*);
65 EXTERN int MatCreateSeqDense(MPI_Comm,int,int,Scalar*,Mat*);
66 EXTERN int MatCreateMPIDense(MPI_Comm,int,int,int,int,Scalar*,Mat*);
67 EXTERN int MatCreateSeqAIJ(MPI_Comm,int,int,int,int*,Mat*);
68 EXTERN int MatCreateMPIAIJ(MPI_Comm,int,int,int,int,int,int*,int,int*,Mat*);
69 EXTERN int MatCreateMPIRowbs(MPI_Comm,int,int,int,int*,Mat*);
70 EXTERN int MatCreateSeqBDiag(MPI_Comm,int,int,int,int,int*,Scalar**,Mat*);
71 EXTERN int MatCreateMPIBDiag(MPI_Comm,int,int,int,int,int,int*,Scalar**,Mat*);
72 EXTERN int MatCreateSeqBAIJ(MPI_Comm,int,int,int,int,int*,Mat*);
73 EXTERN int MatCreateMPIBAIJ(MPI_Comm,int,int,int,int,int,int,int*,int,int*,Mat*);
74 EXTERN int MatCreateMPIAdj(MPI_Comm,int,int,int*,int*,int *,Mat*);
75 EXTERN int MatCreateSeqSBAIJ(MPI_Comm,int,int,int,int,int*,Mat*);
76 EXTERN int MatCreateMPISBAIJ(MPI_Comm,int,int,int,int,int,int,int*,int,int*,Mat*);
77 
78 EXTERN int MatDestroy(Mat);
79 
80 EXTERN int MatCreateShell(MPI_Comm,int,int,int,int,void *,Mat*);
81 EXTERN int MatShellGetContext(Mat,void **);
82 
83 EXTERN int MatPrintHelp(Mat);
84 EXTERN int MatGetMaps(Mat,Map*,Map*);
85 
86 /* ------------------------------------------------------------*/
87 EXTERN int MatSetValues(Mat,int,int*,int,int*,Scalar*,InsertMode);
88 EXTERN int MatSetValuesBlocked(Mat,int,int*,int,int*,Scalar*,InsertMode);
89 
90 /*E
91     MatAssemblyType - Indicates if the matrix is now to be used, or if you plan
92      to continue to add values to it
93 
94     Level: beginner
95 
96 .seealso: MatAssemblyBegin(), MatAssemblyEnd()
97 E*/
98 typedef enum {MAT_FLUSH_ASSEMBLY=1,MAT_FINAL_ASSEMBLY=0} MatAssemblyType;
99 EXTERN int MatAssemblyBegin(Mat,MatAssemblyType);
100 EXTERN int MatAssemblyEnd(Mat,MatAssemblyType);
101 EXTERN int MatAssembled(Mat,PetscTruth*);
102 
103 #define MatSetValue(v,i,j,va,mode) \
104 0; {int _ierr,_row = i,_col = j; Scalar _va = va; \
105   _ierr = MatSetValues(v,1,&_row,1,&_col,&_va,mode);CHKERRQ(_ierr); \
106 }
107 #define MatGetValue(v,i,j,va) \
108 0; {int _ierr,_row = i,_col = j; \
109   _ierr = MatGetValues(v,1,&_row,1,&_col,&va);CHKERRQ(_ierr); \
110 }
111 #define MatSetValueLocal(v,i,j,va,mode) \
112 0; {int _ierr,_row = i,_col = j; Scalar _va = va; \
113   _ierr = MatSetValuesLocal(v,1,&_row,1,&_col,&_va,mode);CHKERRQ(_ierr); \
114 }
115 /*E
116     MatOption - Options that may be set for a matrix and its behavior or storage
117 
118     Level: beginner
119 
120    Any additions/changes here MUST also be made in include/finclude/petscmat.h
121 
122 .seealso: MatSetOption()
123 E*/
124 typedef enum {MAT_ROW_ORIENTED=1,MAT_COLUMN_ORIENTED=2,MAT_ROWS_SORTED=4,
125               MAT_COLUMNS_SORTED=8,MAT_NO_NEW_NONZERO_LOCATIONS=16,
126               MAT_YES_NEW_NONZERO_LOCATIONS=32,MAT_SYMMETRIC=64,
127               MAT_STRUCTURALLY_SYMMETRIC=65,MAT_NO_NEW_DIAGONALS=66,
128               MAT_YES_NEW_DIAGONALS=67,MAT_INODE_LIMIT_1=68,MAT_INODE_LIMIT_2=69,
129               MAT_INODE_LIMIT_3=70,MAT_INODE_LIMIT_4=71,MAT_INODE_LIMIT_5=72,
130               MAT_IGNORE_OFF_PROC_ENTRIES=73,MAT_ROWS_UNSORTED=74,
131               MAT_COLUMNS_UNSORTED=75,MAT_NEW_NONZERO_LOCATION_ERR=76,
132               MAT_NEW_NONZERO_ALLOCATION_ERR=77,MAT_USE_HASH_TABLE=78,
133               MAT_KEEP_ZEROED_ROWS=79,MAT_IGNORE_ZERO_ENTRIES=80,MAT_USE_INODES=81,
134               MAT_DO_NOT_USE_INODES=82} MatOption;
135 EXTERN int MatSetOption(Mat,MatOption);
136 EXTERN int MatGetType(Mat,MatType*);
137 
138 EXTERN int MatGetValues(Mat,int,int*,int,int*,Scalar*);
139 EXTERN int MatGetRow(Mat,int,int *,int **,Scalar**);
140 EXTERN int MatRestoreRow(Mat,int,int *,int **,Scalar**);
141 EXTERN int MatGetColumn(Mat,int,int *,int **,Scalar**);
142 EXTERN int MatRestoreColumn(Mat,int,int *,int **,Scalar**);
143 EXTERN int MatGetColumnVector(Mat,Vec,int);
144 EXTERN int MatGetArray(Mat,Scalar **);
145 EXTERN int MatRestoreArray(Mat,Scalar **);
146 EXTERN int MatGetBlockSize(Mat,int *);
147 
148 EXTERN int MatMult(Mat,Vec,Vec);
149 EXTERN int MatMultAdd(Mat,Vec,Vec,Vec);
150 EXTERN int MatMultTranspose(Mat,Vec,Vec);
151 EXTERN int MatMultTransposeAdd(Mat,Vec,Vec,Vec);
152 
153 /*E
154     MatDuplicateOption - Indicates if a duplicated sparse matrix should have
155   its numerical values copied over or just its nonzero structure.
156 
157     Level: beginner
158 
159    Any additions/changes here MUST also be made in include/finclude/petscmat.h
160 
161 .seealso: MatDuplicate()
162 E*/
163 typedef enum {MAT_DO_NOT_COPY_VALUES,MAT_COPY_VALUES} MatDuplicateOption;
164 
165 EXTERN int MatConvertRegister(char*,char*,char*,int (*)(Mat,MatType,Mat*));
166 #if defined(PETSC_USE_DYNAMIC_LIBRARIES)
167 #define MatConvertRegisterDynamic(a,b,c,d) MatConvertRegister(a,b,c,0)
168 #else
169 #define MatConvertRegisterDynamic(a,b,c,d) MatConvertRegister(a,b,c,d)
170 #endif
171 EXTERN int MatConvertRegisterAll(char*);
172 EXTERN int MatConvertRegisterDestroy(void);
173 extern PetscTruth MatConvertRegisterAllCalled;
174 extern PetscFList      MatConvertList;
175 EXTERN int MatConvert(Mat,MatType,Mat*);
176 EXTERN int MatDuplicate(Mat,MatDuplicateOption,Mat*);
177 
178 /*E
179     MatStructure - Indicates if the matrix has the same nonzero structure
180 
181     Level: beginner
182 
183    Any additions/changes here MUST also be made in include/finclude/petscmat.h
184 
185 .seealso: MatCopy(), SLESSetOperators(), PCSetOperators()
186 E*/
187 typedef enum {SAME_NONZERO_PATTERN,DIFFERENT_NONZERO_PATTERN,SAME_PRECONDITIONER} MatStructure;
188 
189 EXTERN int MatCopy(Mat,Mat,MatStructure);
190 EXTERN int MatView(Mat,PetscViewer);
191 
192 EXTERN int MatLoadRegister(char*,char*,char*,int (*)(PetscViewer,MatType,Mat*));
193 #if defined(PETSC_USE_DYNAMIC_LIBRARIES)
194 #define MatLoadRegisterDynamic(a,b,c,d) MatLoadRegister(a,b,c,0)
195 #else
196 #define MatLoadRegisterDynamic(a,b,c,d) MatLoadRegister(a,b,c,d)
197 #endif
198 EXTERN int MatLoadRegisterAll(char*);
199 EXTERN int MatLoadRegisterDestroy(void);
200 extern PetscTruth MatLoadRegisterAllCalled;
201 extern PetscFList      MatLoadList;
202 EXTERN int MatLoad(PetscViewer,MatType,Mat*);
203 
204 EXTERN int MatGetRowIJ(Mat,int,PetscTruth,int*,int **,int **,PetscTruth *);
205 EXTERN int MatRestoreRowIJ(Mat,int,PetscTruth,int *,int **,int **,PetscTruth *);
206 EXTERN int MatGetColumnIJ(Mat,int,PetscTruth,int*,int **,int **,PetscTruth *);
207 EXTERN int MatRestoreColumnIJ(Mat,int,PetscTruth,int *,int **,int **,PetscTruth *);
208 
209 /*S
210      MatInfo - Context of matrix information, used with MatGetInfo()
211 
212    In Fortran this is simply a double precision array of dimension MAT_INFO_SIZE
213 
214    Level: intermediate
215 
216   Concepts: matrix^nonzero information
217 
218 .seealso:  MatGetInfo(), MatInfoType
219 S*/
220 typedef struct {
221   PetscLogDouble rows_global,columns_global;         /* number of global rows and columns */
222   PetscLogDouble rows_local,columns_local;           /* number of local rows and columns */
223   PetscLogDouble block_size;                         /* block size */
224   PetscLogDouble nz_allocated,nz_used,nz_unneeded;   /* number of nonzeros */
225   PetscLogDouble memory;                             /* memory allocated */
226   PetscLogDouble assemblies;                         /* number of matrix assemblies called */
227   PetscLogDouble mallocs;                            /* number of mallocs during MatSetValues() */
228   PetscLogDouble fill_ratio_given,fill_ratio_needed; /* fill ratio for LU/ILU */
229   PetscLogDouble factor_mallocs;                     /* number of mallocs during factorization */
230 } MatInfo;
231 
232 /*E
233     MatInfoType - Indicates if you want information about the local part of the matrix,
234      the entire parallel matrix or the maximum over all the local parts.
235 
236     Level: beginner
237 
238    Any additions/changes here MUST also be made in include/finclude/petscmat.h
239 
240 .seealso: MatGetInfo(), MatInfo
241 E*/
242 typedef enum {MAT_LOCAL=1,MAT_GLOBAL_MAX=2,MAT_GLOBAL_SUM=3} MatInfoType;
243 EXTERN int MatGetInfo(Mat,MatInfoType,MatInfo*);
244 EXTERN int MatValid(Mat,PetscTruth*);
245 EXTERN int MatGetDiagonal(Mat,Vec);
246 EXTERN int MatGetRowMax(Mat,Vec);
247 EXTERN int MatTranspose(Mat,Mat*);
248 EXTERN int MatPermute(Mat,IS,IS,Mat *);
249 EXTERN int MatDiagonalScale(Mat,Vec,Vec);
250 EXTERN int MatDiagonalSet(Mat,Vec,InsertMode);
251 EXTERN int MatEqual(Mat,Mat,PetscTruth*);
252 
253 EXTERN int MatNorm(Mat,NormType,double *);
254 EXTERN int MatZeroEntries(Mat);
255 EXTERN int MatZeroRows(Mat,IS,Scalar*);
256 EXTERN int MatZeroColumns(Mat,IS,Scalar*);
257 
258 EXTERN int MatUseScaledForm(Mat,PetscTruth);
259 EXTERN int MatScaleSystem(Mat,Vec,Vec);
260 EXTERN int MatUnScaleSystem(Mat,Vec,Vec);
261 
262 EXTERN int MatGetSize(Mat,int*,int*);
263 EXTERN int MatGetLocalSize(Mat,int*,int*);
264 EXTERN int MatGetOwnershipRange(Mat,int*,int*);
265 
266 /*E
267     MatReuse - Indicates if matrices obtained from a previous call to MatGetSubMatrices()
268      or MatGetSubMatrix() are to be reused to store the new matrix values.
269 
270     Level: beginner
271 
272    Any additions/changes here MUST also be made in include/finclude/petscmat.h
273 
274 .seealso: MatGetSubMatrices(), MatGetSubMatrix(), MatDestroyMatrices()
275 E*/
276 typedef enum {MAT_INITIAL_MATRIX,MAT_REUSE_MATRIX} MatReuse;
277 EXTERN int MatGetSubMatrices(Mat,int,IS *,IS *,MatReuse,Mat **);
278 EXTERN int MatDestroyMatrices(int,Mat **);
279 EXTERN int MatGetSubMatrix(Mat,IS,IS,int,MatReuse,Mat *);
280 
281 EXTERN int MatIncreaseOverlap(Mat,int,IS *,int);
282 
283 EXTERN int MatAXPY(Scalar *,Mat,Mat);
284 EXTERN int MatAYPX(Scalar *,Mat,Mat);
285 EXTERN int MatCompress(Mat);
286 
287 EXTERN int MatScale(Scalar *,Mat);
288 EXTERN int MatShift(Scalar *,Mat);
289 
290 EXTERN int MatSetLocalToGlobalMapping(Mat,ISLocalToGlobalMapping);
291 EXTERN int MatSetLocalToGlobalMappingBlock(Mat,ISLocalToGlobalMapping);
292 EXTERN int MatZeroRowsLocal(Mat,IS,Scalar*);
293 EXTERN int MatSetValuesLocal(Mat,int,int*,int,int*,Scalar*,InsertMode);
294 EXTERN int MatSetValuesBlockedLocal(Mat,int,int*,int,int*,Scalar*,InsertMode);
295 
296 EXTERN int MatSetStashInitialSize(Mat,int,int);
297 
298 EXTERN int MatInterpolateAdd(Mat,Vec,Vec,Vec);
299 EXTERN int MatInterpolate(Mat,Vec,Vec);
300 EXTERN int MatRestrict(Mat,Vec,Vec);
301 
302 /*
303       These three (or four) macros MUST be used together. The third one closes the open { of the first one
304 */
305 #define MatPreallocateInitialize(comm,nrows,ncols,dnz,onz) 0; \
306 { \
307   int __ierr,__tmp = (nrows),__ctmp = (ncols),__rstart,__start,__end; \
308   __ierr = PetscMalloc(2*__tmp*sizeof(int),&dnz);CHKERRQ(__ierr);onz = dnz + __tmp;\
309   __ierr = PetscMemzero(dnz,2*__tmp*sizeof(int));CHKERRQ(__ierr);\
310   __ierr = MPI_Scan(&__ctmp,&__end,1,MPI_INT,MPI_SUM,comm);CHKERRQ(__ierr); __start = __end - __ctmp;\
311   __ierr = MPI_Scan(&__tmp,&__rstart,1,MPI_INT,MPI_SUM,comm);CHKERRQ(__ierr); __rstart = __rstart - __tmp;
312 
313 #define MatPreallocateSetLocal(map,nrows,rows,ncols,cols,dnz,onz) 0;\
314 {\
315   int __l;\
316   __ierr = ISLocalToGlobalMappingApply(map,nrows,rows,rows);CHKERRQ(__ierr);\
317   __ierr = ISLocalToGlobalMappingApply(map,ncols,cols,cols);CHKERRQ(__ierr);\
318   for (__l=0;__l<nrows;__l++) {\
319     __ierr = MatPreallocateSet(rows[__l],ncols,cols,dnz,onz);CHKERRQ(__ierr);\
320   }\
321 }
322 
323 #define MatPreallocateSet(row,nc,cols,dnz,onz) 0;\
324 { int __i; \
325   for (__i=0; __i<nc; __i++) {\
326     if (cols[__i] < __start || cols[__i] >= __end) onz[row - __rstart]++; \
327   }\
328   dnz[row - __rstart] = nc - onz[row - __rstart];\
329 }
330 
331 #define MatPreallocateFinalize(dnz,onz) 0;__ierr = PetscFree(dnz);CHKERRQ(__ierr);}
332 
333 /* Routines unique to particular data structures */
334 EXTERN int MatBDiagGetData(Mat,int*,int*,int**,int**,Scalar***);
335 EXTERN int MatSeqAIJSetColumnIndices(Mat,int *);
336 EXTERN int MatSeqBAIJSetColumnIndices(Mat,int *);
337 EXTERN int MatCreateSeqAIJWithArrays(MPI_Comm,int,int,int*,int*,Scalar *,Mat*);
338 
339 EXTERN int MatSeqBAIJSetPreallocation(Mat,int,int,int*);
340 EXTERN int MatSeqSBAIJSetPreallocation(Mat,int,int,int*);
341 EXTERN int MatSeqAIJSetPreallocation(Mat,int,int*);
342 EXTERN int MatSeqDensePreallocation(Mat,Scalar*);
343 EXTERN int MatSeqBDiagSetPreallocation(Mat,int,int,int*,Scalar**);
344 EXTERN int MatSeqDenseSetPreallocation(Mat,Scalar*);
345 
346 EXTERN int MatMPIBAIJSetPreallocation(Mat,int,int,int*,int,int*);
347 EXTERN int MatMPISBAIJSetPreallocation(Mat,int,int,int*,int,int*);
348 EXTERN int MatMPIAIJSetPreallocation(Mat,int,int*,int,int*);
349 EXTERN int MatMPIDensePreallocation(Mat,Scalar*);
350 EXTERN int MatMPIBDiagSetPreallocation(Mat,int,int,int*,Scalar**);
351 EXTERN int MatMPIAdjSetPreallocation(Mat,int*,int*,int*);
352 EXTERN int MatMPIDenseSetPreallocation(Mat,Scalar*);
353 EXTERN int MatMPIRowbsSetPreallocation(Mat,int,int*);
354 
355 EXTERN int MatStoreValues(Mat);
356 EXTERN int MatRetrieveValues(Mat);
357 
358 /*
359   These routines are not usually accessed directly, rather solving is
360   done through the SLES, KSP and PC interfaces.
361 */
362 
363 /*E
364     MatOrderingType - String with the name of a PETSc matrix ordering or the creation function
365        with an optional dynamic library name, for example
366        http://www.mcs.anl.gov/petsc/lib.a:orderingcreate()
367 
368    Level: beginner
369 
370 .seealso: MatGetOrdering()
371 E*/
372 typedef char* MatOrderingType;
373 #define MATORDERING_NATURAL   "natural"
374 #define MATORDERING_ND        "nd"
375 #define MATORDERING_1WD       "1wd"
376 #define MATORDERING_RCM       "rcm"
377 #define MATORDERING_QMD       "qmd"
378 #define MATORDERING_ROWLENGTH "rowlength"
379 #define MATORDERING_DSC_ND    "dsc_nd"
380 #define MATORDERING_DSC_MMD   "dsc_mmd"
381 #define MATORDERING_DSC_MDF   "dsc_mdf"
382 
383 EXTERN int MatGetOrdering(Mat,MatOrderingType,IS*,IS*);
384 EXTERN int MatOrderingRegister(char*,char*,char*,int(*)(Mat,MatOrderingType,IS*,IS*));
385 #if defined(PETSC_USE_DYNAMIC_LIBRARIES)
386 #define MatOrderingRegisterDynamic(a,b,c,d) MatOrderingRegister(a,b,c,0)
387 #else
388 #define MatOrderingRegisterDynamic(a,b,c,d) MatOrderingRegister(a,b,c,d)
389 #endif
390 EXTERN int        MatOrderingRegisterDestroy(void);
391 EXTERN int        MatOrderingRegisterAll(char*);
392 extern PetscTruth MatOrderingRegisterAllCalled;
393 extern PetscFList      MatOrderingList;
394 
395 EXTERN int MatReorderForNonzeroDiagonal(Mat,double,IS,IS);
396 
397 EXTERN int MatCholeskyFactor(Mat,IS,double);
398 EXTERN int MatCholeskyFactorSymbolic(Mat,IS,double,Mat*);
399 EXTERN int MatCholeskyFactorNumeric(Mat,Mat*);
400 
401 /*S
402    MatILUInfo - Data based into the matrix ILU factorization routines
403 
404    In Fortran these are simply double precision arrays of size MAT_ILUINFO_SIZE
405 
406    Notes: These are not usually directly used by users, instead use the PC type of ILU
407           All entries are double precision.
408 
409    Level: developer
410 
411 .seealso: MatILUFactorSymbolic(), MatILUFactor(), MatLUInfo, MatCholeskyInfo
412 
413 S*/
414 typedef struct {
415   double     levels;         /* ILU(levels) */
416   double     fill;           /* expected fill; nonzeros in factored matrix/nonzeros in original matrix*/
417   double     diagonal_fill;  /* force diagonal to fill in if initially not filled */
418   double     dt;             /* drop tolerance */
419   double     dtcol;          /* tolerance for pivoting */
420   double     dtcount;        /* maximum nonzeros to be allowed per row */
421   double     damping;        /* scaling of identity added to matrix to prevent zero pivots */
422   double     damp;           /* if is 1.0 and factorization fails, damp until successful */
423 } MatILUInfo;
424 
425 /*S
426    MatLUInfo - Data based into the matrix LU factorization routines
427 
428    In Fortran these are simply double precision arrays of size MAT_LUINFO_SIZE
429 
430    Notes: These are not usually directly used by users, instead use the PC type of LU
431           All entries are double precision.
432 
433    Level: developer
434 
435 .seealso: MatLUFactorSymbolic(), MatILUInfo, MatCholeskyInfo
436 
437 S*/
438 typedef struct {
439   double     fill;    /* expected fill; nonzeros in factored matrix/nonzeros in original matrix */
440   double     dtcol;   /* tolerance for pivoting; pivot if off_diagonal*dtcol > diagonal */
441   double     damping; /* scaling of identity added to matrix to prevent zero pivots */
442   double     damp;    /* if this is 1.0 and factorization fails, damp until successful */
443 } MatLUInfo;
444 
445 /*S
446    MatCholeskyInfo - Data based into the matrix Cholesky factorization routines
447 
448    In Fortran these are simply double precision arrays of size MAT_CHOLESKYINFO_SIZE
449 
450    Notes: These are not usually directly used by users, instead use the PC type of Cholesky
451           All entries are double precision.
452 
453    Level: developer
454 
455 .seealso: MatCholeskyFactorSymbolic(), MatLUInfo, MatILUInfo
456 
457 S*/
458 typedef struct {
459   double     fill;    /* expected fill; nonzeros in factored matrix/nonzeros in original matrix */
460   double     damping; /* scaling of identity added to matrix to prevent zero pivots */
461   double     damp;    /* if this is 1.0 and factorization fails, damp until successful */
462 } MatCholeskyInfo;
463 
464 EXTERN int MatLUFactor(Mat,IS,IS,MatLUInfo*);
465 EXTERN int MatILUFactor(Mat,IS,IS,MatILUInfo*);
466 EXTERN int MatLUFactorSymbolic(Mat,IS,IS,MatLUInfo*,Mat*);
467 EXTERN int MatILUFactorSymbolic(Mat,IS,IS,MatILUInfo*,Mat*);
468 EXTERN int MatIncompleteCholeskyFactorSymbolic(Mat,IS,double,int,Mat*);
469 EXTERN int MatIncompleteCholeskyFactor(Mat,IS,double,int);
470 EXTERN int MatLUFactorNumeric(Mat,Mat*);
471 EXTERN int MatILUDTFactor(Mat,MatILUInfo*,IS,IS,Mat *);
472 
473 EXTERN int MatSolve(Mat,Vec,Vec);
474 EXTERN int MatForwardSolve(Mat,Vec,Vec);
475 EXTERN int MatBackwardSolve(Mat,Vec,Vec);
476 EXTERN int MatSolveAdd(Mat,Vec,Vec,Vec);
477 EXTERN int MatSolveTranspose(Mat,Vec,Vec);
478 EXTERN int MatSolveTransposeAdd(Mat,Vec,Vec,Vec);
479 
480 EXTERN int MatSetUnfactored(Mat);
481 
482 /*  MatSORType may be bitwise ORd together, so do not change the numbers */
483 /*E
484     MatSORType - What type of (S)SOR to perform
485 
486     Level: beginner
487 
488    May be bitwise ORd together
489 
490    Any additions/changes here MUST also be made in include/finclude/petscmat.h
491 
492 .seealso: MatRelax()
493 E*/
494 typedef enum {SOR_FORWARD_SWEEP=1,SOR_BACKWARD_SWEEP=2,SOR_SYMMETRIC_SWEEP=3,
495               SOR_LOCAL_FORWARD_SWEEP=4,SOR_LOCAL_BACKWARD_SWEEP=8,
496               SOR_LOCAL_SYMMETRIC_SWEEP=12,SOR_ZERO_INITIAL_GUESS=16,
497               SOR_EISENSTAT=32,SOR_APPLY_UPPER=64,SOR_APPLY_LOWER=128} MatSORType;
498 EXTERN int MatRelax(Mat,Vec,double,MatSORType,double,int,Vec);
499 
500 /*
501     These routines are for efficiently computing Jacobians via finite differences.
502 */
503 
504 /*E
505     MatColoringType - String with the name of a PETSc matrix coloring or the creation function
506        with an optional dynamic library name, for example
507        http://www.mcs.anl.gov/petsc/lib.a:coloringcreate()
508 
509    Level: beginner
510 
511 .seealso: MatGetColoring()
512 E*/
513 typedef char* MatColoringType;
514 #define MATCOLORING_NATURAL "natural"
515 #define MATCOLORING_SL      "sl"
516 #define MATCOLORING_LF      "lf"
517 #define MATCOLORING_ID      "id"
518 
519 EXTERN int MatGetColoring(Mat,MatColoringType,ISColoring*);
520 EXTERN int MatColoringRegister(char*,char*,char*,int(*)(Mat,MatColoringType,ISColoring *));
521 #if defined(PETSC_USE_DYNAMIC_LIBRARIES)
522 #define MatColoringRegisterDynamic(a,b,c,d) MatColoringRegister(a,b,c,0)
523 #else
524 #define MatColoringRegisterDynamic(a,b,c,d) MatColoringRegister(a,b,c,d)
525 #endif
526 EXTERN int        MatColoringRegisterAll(char *);
527 extern PetscTruth MatColoringRegisterAllCalled;
528 EXTERN int        MatColoringRegisterDestroy(void);
529 EXTERN int        MatColoringPatch(Mat,int,int *,ISColoring*);
530 
531 #define MAT_FDCOLORING_COOKIE PETSC_COOKIE + 23
532 /*S
533      MatFDColoring - Object for computing a sparse Jacobian via finite differences
534         and coloring
535 
536    Level: beginner
537 
538   Concepts: coloring, sparse Jacobian, finite differences
539 
540 .seealso:  MatFDColoringCreate()
541 S*/
542 typedef struct _p_MatFDColoring *MatFDColoring;
543 
544 EXTERN int MatFDColoringCreate(Mat,ISColoring,MatFDColoring *);
545 EXTERN int MatFDColoringDestroy(MatFDColoring);
546 EXTERN int MatFDColoringView(MatFDColoring,PetscViewer);
547 EXTERN int MatFDColoringSetFunction(MatFDColoring,int (*)(void),void*);
548 EXTERN int MatFDColoringSetParameters(MatFDColoring,double,double);
549 EXTERN int MatFDColoringSetFrequency(MatFDColoring,int);
550 EXTERN int MatFDColoringGetFrequency(MatFDColoring,int*);
551 EXTERN int MatFDColoringSetFromOptions(MatFDColoring);
552 EXTERN int MatFDColoringApply(Mat,MatFDColoring,Vec,MatStructure*,void *);
553 EXTERN int MatFDColoringApplyTS(Mat,MatFDColoring,double,Vec,MatStructure*,void *);
554 EXTERN int MatFDColoringSetRecompute(MatFDColoring);
555 
556 /*
557     These routines are for partitioning matrices: currently used only
558   for adjacency matrix, MatCreateMPIAdj().
559 */
560 #define MATPARTITIONING_COOKIE PETSC_COOKIE + 25
561 
562 /*S
563      MatPartitioning - Object for managing the partitioning of a matrix or graph
564 
565    Level: beginner
566 
567   Concepts: partitioning
568 
569 .seealso:  MatParitioningCreate(), MatPartitioningType
570 S*/
571 typedef struct _p_MatPartitioning *MatPartitioning;
572 
573 /*E
574     MatPartitioningType - String with the name of a PETSc matrix partitioing or the creation function
575        with an optional dynamic library name, for example
576        http://www.mcs.anl.gov/petsc/lib.a:partitioningcreate()
577 
578    Level: beginner
579 
580 .seealso: MatPartitioingCreate(), MatPartitioning
581 E*/
582 typedef char* MatPartitioningType;
583 #define MATPARTITIONING_CURRENT  "current"
584 #define MATPARTITIONING_PARMETIS "parmetis"
585 
586 EXTERN int MatPartitioningCreate(MPI_Comm,MatPartitioning*);
587 EXTERN int MatPartitioningSetType(MatPartitioning,MatPartitioningType);
588 EXTERN int MatPartitioningSetAdjacency(MatPartitioning,Mat);
589 EXTERN int MatPartitioningSetVertexWeights(MatPartitioning,int*);
590 EXTERN int MatPartitioningApply(MatPartitioning,IS*);
591 EXTERN int MatPartitioningDestroy(MatPartitioning);
592 
593 EXTERN int MatPartitioningRegister(char*,char*,char*,int(*)(MatPartitioning));
594 #if defined(PETSC_USE_DYNAMIC_LIBRARIES)
595 #define MatPartitioningRegisterDynamic(a,b,c,d) MatPartitioningRegister(a,b,c,0)
596 #else
597 #define MatPartitioningRegisterDynamic(a,b,c,d) MatPartitioningRegister(a,b,c,d)
598 #endif
599 
600 EXTERN int        MatPartitioningRegisterAll(char *);
601 extern PetscTruth MatPartitioningRegisterAllCalled;
602 EXTERN int        MatPartitioningRegisterDestroy(void);
603 
604 EXTERN int MatPartitioningView(MatPartitioning,PetscViewer);
605 EXTERN int MatPartitioningSetFromOptions(MatPartitioning);
606 EXTERN int MatPartitioningGetType(MatPartitioning,MatPartitioningType*);
607 
608 EXTERN int MatPartitioningParmetisSetCoarseSequential(MatPartitioning);
609 
610 /*
611     If you add entries here you must also add them to finclude/petscmat.h
612 */
613 typedef enum { MATOP_SET_VALUES=0,
614                MATOP_GET_ROW=1,
615                MATOP_RESTORE_ROW=2,
616                MATOP_MULT=3,
617                MATOP_MULT_ADD=4,
618                MATOP_MULT_TRANSPOSE=5,
619                MATOP_MULT_TRANSPOSE_ADD=6,
620                MATOP_SOLVE=7,
621                MATOP_SOLVE_ADD=8,
622                MATOP_SOLVE_TRANSPOSE=9,
623                MATOP_SOLVE_TRANSPOSE_ADD=10,
624                MATOP_LUFACTOR=11,
625                MATOP_CHOLESKYFACTOR=12,
626                MATOP_RELAX=13,
627                MATOP_TRANSPOSE=14,
628                MATOP_GETINFO=15,
629                MATOP_EQUAL=16,
630                MATOP_GET_DIAGONAL=17,
631                MATOP_DIAGONAL_SCALE=18,
632                MATOP_NORM=19,
633                MATOP_ASSEMBLY_BEGIN=20,
634                MATOP_ASSEMBLY_END=21,
635                MATOP_COMPRESS=22,
636                MATOP_SET_OPTION=23,
637                MATOP_ZERO_ENTRIES=24,
638                MATOP_ZERO_ROWS=25,
639                MATOP_LUFACTOR_SYMBOLIC=26,
640                MATOP_LUFACTOR_NUMERIC=27,
641                MATOP_CHOLESKY_FACTOR_SYMBOLIC=28,
642                MATOP_CHOLESKY_FACTOR_NUMERIC=29,
643                MATOP_GET_SIZE=30,
644                MATOP_GET_LOCAL_SIZE=31,
645                MATOP_GET_OWNERSHIP_RANGE=32,
646                MATOP_ILUFACTOR_SYMBOLIC=33,
647                MATOP_INCOMPLETECHOLESKYFACTOR_SYMBOLIC=34,
648                MATOP_GET_ARRAY=35,
649                MATOP_RESTORE_ARRAY=36,
650 
651                MATOP_CONVERT_SAME_TYPE=37,
652                MATOP_FORWARD_SOLVE=38,
653                MATOP_BACKWARD_SOLVE=39,
654                MATOP_ILUFACTOR=40,
655                MATOP_INCOMPLETECHOLESKYFACTOR=41,
656                MATOP_AXPY=42,
657                MATOP_GET_SUBMATRICES=43,
658                MATOP_INCREASE_OVERLAP=44,
659                MATOP_GET_VALUES=45,
660                MATOP_COPY=46,
661                MATOP_PRINT_HELP=47,
662                MATOP_SCALE=48,
663                MATOP_SHIFT=49,
664                MATOP_DIAGONAL_SHIFT=50,
665                MATOP_ILUDT_FACTOR=51,
666                MATOP_GET_BLOCK_SIZE=52,
667                MATOP_GET_ROW_IJ=53,
668                MATOP_RESTORE_ROW_IJ=54,
669                MATOP_GET_COLUMN_IJ=55,
670                MATOP_RESTORE_COLUMN_IJ=56,
671                MATOP_FDCOLORING_CREATE=57,
672                MATOP_COLORING_PATCH=58,
673                MATOP_SET_UNFACTORED=59,
674                MATOP_PERMUTE=60,
675                MATOP_SET_VALUES_BLOCKED=61,
676                MATOP_DESTROY=250,
677                MATOP_VIEW=251
678              } MatOperation;
679 EXTERN int MatHasOperation(Mat,MatOperation,PetscTruth*);
680 EXTERN int MatShellSetOperation(Mat,MatOperation,void *);
681 EXTERN int MatShellGetOperation(Mat,MatOperation,void **);
682 EXTERN int MatShellSetContext(Mat,void*);
683 
684 /*
685    Codes for matrices stored on disk. By default they are
686  stored in a universal format. By changing the format with
687  PetscViewerSetFormat(viewer,PETSC_VIEWER_BINARY_NATIVE); the matrices will
688  be stored in a way natural for the matrix, for example dense matrices
689  would be stored as dense. Matrices stored this way may only be
690  read into matrices of the same time.
691 */
692 #define MATRIX_BINARY_FORMAT_DENSE -1
693 
694 /*
695      New matrix classes not yet distributed
696 */
697 /*
698     MatAIJIndices is a data structure for storing the nonzero location information
699   for sparse matrices. Several matrices with identical nonzero structure can share
700   the same MatAIJIndices.
701 */
702 typedef struct _p_MatAIJIndices* MatAIJIndices;
703 
704 EXTERN int MatCreateAIJIndices(int,int,int*,int*,PetscTruth,MatAIJIndices*);
705 EXTERN int MatCreateAIJIndicesEmpty(int,int,int*,PetscTruth,MatAIJIndices*);
706 EXTERN int MatAttachAIJIndices(MatAIJIndices,MatAIJIndices*);
707 EXTERN int MatDestroyAIJIndices(MatAIJIndices);
708 EXTERN int MatCopyAIJIndices(MatAIJIndices,MatAIJIndices*);
709 EXTERN int MatValidateAIJIndices(int,MatAIJIndices);
710 EXTERN int MatShiftAIJIndices(MatAIJIndices);
711 EXTERN int MatShrinkAIJIndices(MatAIJIndices);
712 EXTERN int MatTransposeAIJIndices(MatAIJIndices,MatAIJIndices*);
713 
714 EXTERN int MatCreateSeqCSN(MPI_Comm,int,int,int*,int,Mat*);
715 EXTERN int MatCreateSeqCSN_Single(MPI_Comm,int,int,int*,int,Mat*);
716 EXTERN int MatCreateSeqCSNWithPrecision(MPI_Comm,int,int,int*,int,ScalarPrecision,Mat*);
717 
718 EXTERN int MatCreateSeqCSNIndices(MPI_Comm,MatAIJIndices,int,Mat *);
719 EXTERN int MatCreateSeqCSNIndices_Single(MPI_Comm,MatAIJIndices,int,Mat *);
720 EXTERN int MatCreateSeqCSNIndicesWithPrecision(MPI_Comm,MatAIJIndices,int,ScalarPrecision,Mat *);
721 
722 EXTERN int MatMPIBAIJSetHashTableFactor(Mat,PetscReal);
723 EXTERN int MatSeqAIJGetInodeSizes(Mat,int *,int *[],int *);
724 EXTERN int MatMPIRowbsGetColor(Mat,ISColoring *);
725 
726 /*S
727      MatNullSpace - Object that removes a null space from a vector, i.e.
728          orthogonalizes the vector to a subsapce
729 
730    Level: beginner
731 
732   Concepts: matrix; linear operator, null space
733 
734 .seealso:  MatNullSpaceCreate()
735 S*/
736 typedef struct _p_MatNullSpace* MatNullSpace;
737 
738 #define MATNULLSPACE_COOKIE    PETSC_COOKIE+17
739 
740 EXTERN int MatNullSpaceCreate(MPI_Comm,int,int,Vec *,MatNullSpace*);
741 EXTERN int MatNullSpaceDestroy(MatNullSpace);
742 EXTERN int MatNullSpaceRemove(MatNullSpace,Vec,Vec*);
743 EXTERN int MatNullSpaceAttach(Mat,MatNullSpace);
744 EXTERN int MatNullSpaceTest(MatNullSpace,Mat);
745 
746 EXTERN int MatReorderingSeqSBAIJ(Mat A,IS isp);
747 EXTERN int MatMPISBAIJSetHashTableFactor(Mat,PetscReal);
748 EXTERN int MatSeqSBAIJSetColumnIndices(Mat,int *);
749 
750 
751 EXTERN int MatCreateMAIJ(Mat,int,Mat*);
752 EXTERN int MatMAIJRedimension(Mat,int,Mat*);
753 EXTERN int MatMAIJGetAIJ(Mat,Mat*);
754 
755 EXTERN int MatMPIAdjSetValues(Mat,int*,int*,int*);
756 
757 EXTERN int MatComputeExplicitOperator(Mat,Mat*);
758 
759 #endif
760 
761 
762 
763