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