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