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