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