173f4d377SMatthew Knepley /* $Id: petscmat.h,v 1.228 2001/09/07 20:09:08 bsmith Exp $ */ 22eac72dbSBarry Smith /* 32eac72dbSBarry Smith Include file for the matrix component of PETSc 42eac72dbSBarry Smith */ 50a835dfdSSatish Balay #ifndef __PETSCMAT_H 60a835dfdSSatish Balay #define __PETSCMAT_H 70a835dfdSSatish Balay #include "petscvec.h" 82eac72dbSBarry Smith 99cd28387SBarry Smith #define MAT_COOKIE PETSC_COOKIE+5 10f0479e8cSBarry Smith 11d9274352SBarry Smith /*S 12d9274352SBarry Smith Mat - Abstract PETSc matrix object 132eac72dbSBarry Smith 14d91e6319SBarry Smith Level: beginner 15d91e6319SBarry Smith 16d9274352SBarry Smith Concepts: matrix; linear operator 17d9274352SBarry Smith 18d9274352SBarry Smith .seealso: MatCreate(), MatType, MatSetType() 19d9274352SBarry Smith S*/ 20d9274352SBarry Smith typedef struct _p_Mat* Mat; 21d9274352SBarry Smith 22d9274352SBarry Smith /*E 23d9274352SBarry Smith MatType - String with the name of a PETSc matrix or the creation function 24d9274352SBarry Smith with an optional dynamic library name, for example 25d9274352SBarry Smith http://www.mcs.anl.gov/petsc/lib.a:mymatcreate() 26d9274352SBarry Smith 27d9274352SBarry Smith Level: beginner 28d9274352SBarry Smith 29d9274352SBarry Smith .seealso: MatSetType(), Mat 30d91e6319SBarry Smith E*/ 31273d9f13SBarry Smith #define MATSAME "same" 32273d9f13SBarry Smith #define MATSEQMAIJ "seqmaij" 33273d9f13SBarry Smith #define MATMPIMAIJ "mpimaij" 34273d9f13SBarry Smith #define MATIS "is" 35273d9f13SBarry Smith #define MATMPIROWBS "mpirowbs" 36273d9f13SBarry Smith #define MATSEQDENSE "seqdense" 37273d9f13SBarry Smith #define MATSEQAIJ "seqaij" 38273d9f13SBarry Smith #define MATMPIAIJ "mpiaij" 39273d9f13SBarry Smith #define MATSHELL "shell" 40273d9f13SBarry Smith #define MATSEQBDIAG "seqbdiag" 41273d9f13SBarry Smith #define MATMPIBDIAG "mpibdiag" 42273d9f13SBarry Smith #define MATMPIDENSE "mpidense" 43273d9f13SBarry Smith #define MATSEQBAIJ "seqbaij" 44273d9f13SBarry Smith #define MATMPIBAIJ "mpibaij" 45273d9f13SBarry Smith #define MATMPIADJ "mpiadj" 46273d9f13SBarry Smith #define MATSEQSBAIJ "seqsbaij" 47273d9f13SBarry Smith #define MATMPISBAIJ "mpisbaij" 48cebc7f6cSBarry Smith #define MATDAAD "daad" 49cebc7f6cSBarry Smith #define MATMFFD "mffd" 50273d9f13SBarry Smith typedef char* MatType; 51d91e6319SBarry Smith 52*c06d978dSMatthew Knepley #define MAT_SER_SEQAIJ_BINARY "seqaij_binary" 53*c06d978dSMatthew Knepley #define MAT_SER_MPIAIJ_BINARY "mpiaij_binary" 54*c06d978dSMatthew Knepley typedef char *MatSerializeType; 55*c06d978dSMatthew Knepley 56*c06d978dSMatthew Knepley #ifdef PETSC_USE_NEW_LOGGING 57*c06d978dSMatthew Knepley /* Logging support */ 58*c06d978dSMatthew Knepley extern int MAT_COOKIE; 59*c06d978dSMatthew Knepley extern int MAT_FDCOLORING_COOKIE; 60*c06d978dSMatthew Knepley extern int MATPARTITIONING_COOKIE; 61*c06d978dSMatthew Knepley enum {MAT_Mult, MAT_MultMultiple, MAT_MultConstrained, MAT_MultTrans, MAT_MultAdd, MAT_MultTransAdd, MAT_MultMatrixFree, 62*c06d978dSMatthew Knepley MAT_Solve, MAT_SolveMultiple, MAT_SolveAdd, MAT_SolveTrans, MAT_SolveTransAdd, MAT_Relax, MAT_ForwardSolve, 63*c06d978dSMatthew Knepley MAT_BackwardSolve, MAT_LUFactor, MAT_LUFactorSymbolic, MAT_LUFactorNumeric, MAT_CholeskyFactor, 64*c06d978dSMatthew Knepley MAT_CholeskyFactorSymbolic, MAT_CholeskyFactorNumeric, MAT_ILUFactor, MAT_ILUFactorSymbolic, 65*c06d978dSMatthew Knepley MAT_IncompleteCholeskyFactorSymbolic, MAT_Copy, MAT_Convert, MAT_Scale, MAT_AssemblyBegin, MAT_AssemblyEnd, 66*c06d978dSMatthew Knepley MAT_SetValues, MAT_GetValues, MAT_GetRow, MAT_GetSubMatrices, MAT_GetColoring, MAT_GetOrdering, MAT_IncreaseOverlap, 67*c06d978dSMatthew Knepley MAT_Partitioning, MAT_ZeroEntries, MAT_Load, MAT_View, MAT_AXPY, MAT_MAX_EVENTS}; 68*c06d978dSMatthew Knepley extern int MatEvents[MAT_MAX_EVENTS]; 69*c06d978dSMatthew Knepley #define MatLogEventBegin(e,o1,o2,o3,o4) PetscLogEventBegin(MatEvents[e],o1,o2,o3,o4) 70*c06d978dSMatthew Knepley #define MatLogEventEnd(e,o1,o2,o3,o4) PetscLogEventEnd(MatEvents[e],o1,o2,o3,o4) 71*c06d978dSMatthew Knepley 72*c06d978dSMatthew Knepley #else 73*c06d978dSMatthew Knepley 74*c06d978dSMatthew Knepley enum {MAT_MultConstrained}; 75*c06d978dSMatthew Knepley #define MatLogEventBegin(e,o1,o2,o3,o4) PetscLogEventBegin(e,o1,o2,o3,o4) 76*c06d978dSMatthew Knepley #define MatLogEventEnd(e,o1,o2,o3,o4) PetscLogEventEnd(e,o1,o2,o3,o4) 77*c06d978dSMatthew Knepley #endif 78*c06d978dSMatthew Knepley 79273d9f13SBarry Smith EXTERN int MatCreate(MPI_Comm,int,int,int,int,Mat*); 80273d9f13SBarry Smith EXTERN int MatSetType(Mat,MatType); 81273d9f13SBarry Smith EXTERN int MatSetFromOptions(Mat); 82273d9f13SBarry Smith EXTERN int MatSetUpPreallocation(Mat); 83273d9f13SBarry Smith EXTERN int MatRegisterAll(char*); 84273d9f13SBarry Smith EXTERN int MatRegister(char*,char*,char*,int(*)(Mat)); 85*c06d978dSMatthew Knepley EXTERN int MatSerializeRegister(const char [], const char [], const char [], int (*)(MPI_Comm, Mat *, PetscViewer, PetscTruth)); 86273d9f13SBarry Smith #if defined(PETSC_USE_DYNAMIC_LIBRARIES) 87273d9f13SBarry Smith #define MatRegisterDynamic(a,b,c,d) MatRegister(a,b,c,0) 88*c06d978dSMatthew Knepley #define MatSerializeRegisterDynamic(a,b,c,d) MatSerializeRegister(a,b,c,0) 89273d9f13SBarry Smith #else 90273d9f13SBarry Smith #define MatRegisterDynamic(a,b,c,d) MatRegister(a,b,c,d) 91*c06d978dSMatthew Knepley #define MatSerializeRegisterDynamic(a,b,c,d) MatSerializeRegister(a,b,c,d) 92273d9f13SBarry Smith #endif 93273d9f13SBarry Smith extern PetscTruth MatRegisterAllCalled; 94b0a32e0cSBarry Smith extern PetscFList MatList; 9528988994SBarry Smith 96*c06d978dSMatthew Knepley EXTERN PetscFList MatSerializeList; 97*c06d978dSMatthew Knepley EXTERN int MatSerializeRegisterAll(const char []); 98*c06d978dSMatthew Knepley EXTERN int MatSerializeRegisterDestroy(); 99*c06d978dSMatthew Knepley EXTERN int MatSerializeRegisterAllCalled; 100*c06d978dSMatthew Knepley EXTERN int MatSerialize(MPI_Comm, Mat *, PetscViewer, PetscTruth); 101*c06d978dSMatthew Knepley EXTERN int MatSetSerializeType(Mat, MatSerializeType); 102*c06d978dSMatthew Knepley 103ca44d042SBarry Smith EXTERN int MatCreate(MPI_Comm,int,int,int,int,Mat*); 10487828ca2SBarry Smith EXTERN int MatCreateSeqDense(MPI_Comm,int,int,PetscScalar*,Mat*); 10587828ca2SBarry Smith EXTERN int MatCreateMPIDense(MPI_Comm,int,int,int,int,PetscScalar*,Mat*); 106ca44d042SBarry Smith EXTERN int MatCreateSeqAIJ(MPI_Comm,int,int,int,int*,Mat*); 107ca44d042SBarry Smith EXTERN int MatCreateMPIAIJ(MPI_Comm,int,int,int,int,int,int*,int,int*,Mat*); 108c4f061fbSSatish Balay EXTERN int MatCreateMPIRowbs(MPI_Comm,int,int,int,int*,Mat*); 10987828ca2SBarry Smith EXTERN int MatCreateSeqBDiag(MPI_Comm,int,int,int,int,int*,PetscScalar**,Mat*); 11087828ca2SBarry Smith EXTERN int MatCreateMPIBDiag(MPI_Comm,int,int,int,int,int,int*,PetscScalar**,Mat*); 111ca44d042SBarry Smith EXTERN int MatCreateSeqBAIJ(MPI_Comm,int,int,int,int,int*,Mat*); 112ca44d042SBarry Smith EXTERN int MatCreateMPIBAIJ(MPI_Comm,int,int,int,int,int,int,int*,int,int*,Mat*); 113ca44d042SBarry Smith EXTERN int MatCreateMPIAdj(MPI_Comm,int,int,int*,int*,int *,Mat*); 114ca44d042SBarry Smith EXTERN int MatCreateSeqSBAIJ(MPI_Comm,int,int,int,int,int*,Mat*); 115ca44d042SBarry Smith EXTERN int MatCreateMPISBAIJ(MPI_Comm,int,int,int,int,int,int,int*,int,int*,Mat*); 116ca44d042SBarry Smith EXTERN int MatCreateShell(MPI_Comm,int,int,int,int,void *,Mat*); 1173a7fca6bSBarry Smith EXTERN int MatCreateAdic(MPI_Comm,int,int,int,int,int,void (*)(void),Mat*); 118435da068SBarry Smith EXTERN int MatDestroy(Mat); 11921c89e3eSBarry Smith 120ca44d042SBarry Smith EXTERN int MatPrintHelp(Mat); 1218a124369SBarry Smith EXTERN int MatGetPetscMaps(Mat,PetscMap*,PetscMap*); 122ec0117caSBarry Smith 1238ed539a5SBarry Smith /* ------------------------------------------------------------*/ 12487828ca2SBarry Smith EXTERN int MatSetValues(Mat,int,int*,int,int*,PetscScalar*,InsertMode); 12587828ca2SBarry Smith EXTERN int MatSetValuesBlocked(Mat,int,int*,int,int*,PetscScalar*,InsertMode); 12684cb2905SBarry Smith 1272ef4de8bSBarry Smith /*S 1282ef4de8bSBarry Smith MatStencil - Data structure (C struct) for storing information about a single row or 1292ef4de8bSBarry Smith column of a matrix as index on an associated grid. 1302ef4de8bSBarry Smith 1312ef4de8bSBarry Smith Level: beginner 1322ef4de8bSBarry Smith 1332ef4de8bSBarry Smith Concepts: matrix; linear operator 1342ef4de8bSBarry Smith 1352ef4de8bSBarry Smith .seealso: MatSetValuesStencil(), MatSetStencil() 1362ef4de8bSBarry Smith S*/ 137435da068SBarry Smith typedef struct { 138435da068SBarry Smith int k,j,i,c; 139435da068SBarry Smith } MatStencil; 1402ef4de8bSBarry Smith 14187828ca2SBarry Smith EXTERN int MatSetValuesStencil(Mat,int,MatStencil*,int,MatStencil*,PetscScalar*,InsertMode); 14287828ca2SBarry Smith EXTERN int MatSetValuesBlockedStencil(Mat,int,MatStencil*,int,MatStencil*,PetscScalar*,InsertMode); 143435da068SBarry Smith EXTERN int MatSetStencil(Mat,int,int*,int*,int); 144435da068SBarry Smith 1453a7fca6bSBarry Smith EXTERN int MatSetColoring(Mat,ISColoring); 1463a7fca6bSBarry Smith EXTERN int MatSetValuesAdic(Mat,void*); 1473a7fca6bSBarry Smith EXTERN int MatSetValuesAdifor(Mat,int,void*); 1483a7fca6bSBarry Smith 149d91e6319SBarry Smith /*E 150d91e6319SBarry Smith MatAssemblyType - Indicates if the matrix is now to be used, or if you plan 151d91e6319SBarry Smith to continue to add values to it 152d91e6319SBarry Smith 153d91e6319SBarry Smith Level: beginner 154d91e6319SBarry Smith 155d91e6319SBarry Smith .seealso: MatAssemblyBegin(), MatAssemblyEnd() 156d91e6319SBarry Smith E*/ 1576d4a8577SBarry Smith typedef enum {MAT_FLUSH_ASSEMBLY=1,MAT_FINAL_ASSEMBLY=0} MatAssemblyType; 158ca44d042SBarry Smith EXTERN int MatAssemblyBegin(Mat,MatAssemblyType); 159ca44d042SBarry Smith EXTERN int MatAssemblyEnd(Mat,MatAssemblyType); 160ca44d042SBarry Smith EXTERN int MatAssembled(Mat,PetscTruth*); 1614f9c727eSBarry Smith 162b951964fSBarry Smith #define MatSetValue(v,i,j,va,mode) \ 163ea709b57SSatish Balay 0; {int _ierr,_row = i,_col = j; PetscScalar _va = va; \ 164b951964fSBarry Smith _ierr = MatSetValues(v,1,&_row,1,&_col,&_va,mode);CHKERRQ(_ierr); \ 165b951964fSBarry Smith } 166ea06a074SBarry Smith #define MatGetValue(v,i,j,va) \ 167d91e6319SBarry Smith 0; {int _ierr,_row = i,_col = j; \ 168ea06a074SBarry Smith _ierr = MatGetValues(v,1,&_row,1,&_col,&va);CHKERRQ(_ierr); \ 169ea06a074SBarry Smith } 170d91e6319SBarry Smith #define MatSetValueLocal(v,i,j,va,mode) \ 171ea709b57SSatish Balay 0; {int _ierr,_row = i,_col = j; PetscScalar _va = va; \ 172d91e6319SBarry Smith _ierr = MatSetValuesLocal(v,1,&_row,1,&_col,&_va,mode);CHKERRQ(_ierr); \ 173d91e6319SBarry Smith } 174d91e6319SBarry Smith /*E 175d91e6319SBarry Smith MatOption - Options that may be set for a matrix and its behavior or storage 176d91e6319SBarry Smith 177d91e6319SBarry Smith Level: beginner 178d91e6319SBarry Smith 1790a835dfdSSatish Balay Any additions/changes here MUST also be made in include/finclude/petscmat.h 180d91e6319SBarry Smith 181d91e6319SBarry Smith .seealso: MatSetOption() 182d91e6319SBarry Smith E*/ 1836d4a8577SBarry Smith typedef enum {MAT_ROW_ORIENTED=1,MAT_COLUMN_ORIENTED=2,MAT_ROWS_SORTED=4, 1846d4a8577SBarry Smith MAT_COLUMNS_SORTED=8,MAT_NO_NEW_NONZERO_LOCATIONS=16, 1856d4a8577SBarry Smith MAT_YES_NEW_NONZERO_LOCATIONS=32,MAT_SYMMETRIC=64, 1866ca9ecd3SBarry Smith MAT_STRUCTURALLY_SYMMETRIC=65,MAT_NO_NEW_DIAGONALS=66, 1876ca9ecd3SBarry Smith MAT_YES_NEW_DIAGONALS=67,MAT_INODE_LIMIT_1=68,MAT_INODE_LIMIT_2=69, 1886ca9ecd3SBarry Smith MAT_INODE_LIMIT_3=70,MAT_INODE_LIMIT_4=71,MAT_INODE_LIMIT_5=72, 1896ca9ecd3SBarry Smith MAT_IGNORE_OFF_PROC_ENTRIES=73,MAT_ROWS_UNSORTED=74, 1904787f768SSatish Balay MAT_COLUMNS_UNSORTED=75,MAT_NEW_NONZERO_LOCATION_ERR=76, 1917c922b88SBarry Smith MAT_NEW_NONZERO_ALLOCATION_ERR=77,MAT_USE_HASH_TABLE=78, 1922bad1931SBarry Smith MAT_KEEP_ZEROED_ROWS=79,MAT_IGNORE_ZERO_ENTRIES=80,MAT_USE_INODES=81, 1938b43beb6SKris Buschelman MAT_DO_NOT_USE_INODES=82,MAT_USE_SINGLE_PRECISION_SOLVES=83} MatOption; 194ca44d042SBarry Smith EXTERN int MatSetOption(Mat,MatOption); 195273d9f13SBarry Smith EXTERN int MatGetType(Mat,MatType*); 19684cb2905SBarry Smith 19787828ca2SBarry Smith EXTERN int MatGetValues(Mat,int,int*,int,int*,PetscScalar*); 19887828ca2SBarry Smith EXTERN int MatGetRow(Mat,int,int *,int **,PetscScalar**); 19987828ca2SBarry Smith EXTERN int MatRestoreRow(Mat,int,int *,int **,PetscScalar**); 20087828ca2SBarry Smith EXTERN int MatGetColumn(Mat,int,int *,int **,PetscScalar**); 20187828ca2SBarry Smith EXTERN int MatRestoreColumn(Mat,int,int *,int **,PetscScalar**); 202ca44d042SBarry Smith EXTERN int MatGetColumnVector(Mat,Vec,int); 20387828ca2SBarry Smith EXTERN int MatGetArray(Mat,PetscScalar **); 20487828ca2SBarry Smith EXTERN int MatRestoreArray(Mat,PetscScalar **); 205ca44d042SBarry Smith EXTERN int MatGetBlockSize(Mat,int *); 2067b80b807SBarry Smith 207ca44d042SBarry Smith EXTERN int MatMult(Mat,Vec,Vec); 208ca44d042SBarry Smith EXTERN int MatMultAdd(Mat,Vec,Vec,Vec); 209ca44d042SBarry Smith EXTERN int MatMultTranspose(Mat,Vec,Vec); 210ca44d042SBarry Smith EXTERN int MatMultTransposeAdd(Mat,Vec,Vec,Vec); 211*c06d978dSMatthew Knepley EXTERN int MatMultConstrained(Mat,Vec,Vec); 2122eac72dbSBarry Smith 213d91e6319SBarry Smith /*E 214d91e6319SBarry Smith MatDuplicateOption - Indicates if a duplicated sparse matrix should have 215d91e6319SBarry Smith its numerical values copied over or just its nonzero structure. 216d91e6319SBarry Smith 217d91e6319SBarry Smith Level: beginner 218d91e6319SBarry Smith 219d91e6319SBarry Smith Any additions/changes here MUST also be made in include/finclude/petscmat.h 220d91e6319SBarry Smith 221d91e6319SBarry Smith .seealso: MatDuplicate() 222d91e6319SBarry Smith E*/ 2232e8a6d31SBarry Smith typedef enum {MAT_DO_NOT_COPY_VALUES,MAT_COPY_VALUES} MatDuplicateOption; 2242e8a6d31SBarry Smith 225273d9f13SBarry Smith EXTERN int MatConvertRegister(char*,char*,char*,int (*)(Mat,MatType,Mat*)); 226273d9f13SBarry Smith #if defined(PETSC_USE_DYNAMIC_LIBRARIES) 227273d9f13SBarry Smith #define MatConvertRegisterDynamic(a,b,c,d) MatConvertRegister(a,b,c,0) 228273d9f13SBarry Smith #else 229273d9f13SBarry Smith #define MatConvertRegisterDynamic(a,b,c,d) MatConvertRegister(a,b,c,d) 230273d9f13SBarry Smith #endif 231273d9f13SBarry Smith EXTERN int MatConvertRegisterAll(char*); 232273d9f13SBarry Smith EXTERN int MatConvertRegisterDestroy(void); 233273d9f13SBarry Smith extern PetscTruth MatConvertRegisterAllCalled; 234b0a32e0cSBarry Smith extern PetscFList MatConvertList; 235ca44d042SBarry Smith EXTERN int MatConvert(Mat,MatType,Mat*); 236ca44d042SBarry Smith EXTERN int MatDuplicate(Mat,MatDuplicateOption,Mat*); 23794a9d846SBarry Smith 238d91e6319SBarry Smith /*E 239d91e6319SBarry Smith MatStructure - Indicates if the matrix has the same nonzero structure 240d91e6319SBarry Smith 241d91e6319SBarry Smith Level: beginner 242d91e6319SBarry Smith 243d91e6319SBarry Smith Any additions/changes here MUST also be made in include/finclude/petscmat.h 244d91e6319SBarry Smith 245d91e6319SBarry Smith .seealso: MatCopy(), SLESSetOperators(), PCSetOperators() 246d91e6319SBarry Smith E*/ 247cb5b572fSBarry Smith typedef enum {SAME_NONZERO_PATTERN,DIFFERENT_NONZERO_PATTERN,SAME_PRECONDITIONER} MatStructure; 248cb5b572fSBarry Smith 249ca44d042SBarry Smith EXTERN int MatCopy(Mat,Mat,MatStructure); 250b0a32e0cSBarry Smith EXTERN int MatView(Mat,PetscViewer); 251273d9f13SBarry Smith 252b0a32e0cSBarry Smith EXTERN int MatLoadRegister(char*,char*,char*,int (*)(PetscViewer,MatType,Mat*)); 253273d9f13SBarry Smith #if defined(PETSC_USE_DYNAMIC_LIBRARIES) 254273d9f13SBarry Smith #define MatLoadRegisterDynamic(a,b,c,d) MatLoadRegister(a,b,c,0) 255273d9f13SBarry Smith #else 256273d9f13SBarry Smith #define MatLoadRegisterDynamic(a,b,c,d) MatLoadRegister(a,b,c,d) 257273d9f13SBarry Smith #endif 258273d9f13SBarry Smith EXTERN int MatLoadRegisterAll(char*); 259273d9f13SBarry Smith EXTERN int MatLoadRegisterDestroy(void); 260273d9f13SBarry Smith extern PetscTruth MatLoadRegisterAllCalled; 261b0a32e0cSBarry Smith extern PetscFList MatLoadList; 262b0a32e0cSBarry Smith EXTERN int MatLoad(PetscViewer,MatType,Mat*); 2637b80b807SBarry Smith 264ca44d042SBarry Smith EXTERN int MatGetRowIJ(Mat,int,PetscTruth,int*,int **,int **,PetscTruth *); 265ca44d042SBarry Smith EXTERN int MatRestoreRowIJ(Mat,int,PetscTruth,int *,int **,int **,PetscTruth *); 266ca44d042SBarry Smith EXTERN int MatGetColumnIJ(Mat,int,PetscTruth,int*,int **,int **,PetscTruth *); 267ca44d042SBarry Smith EXTERN int MatRestoreColumnIJ(Mat,int,PetscTruth,int *,int **,int **,PetscTruth *); 268d4fbbf0eSBarry Smith 269d91e6319SBarry Smith /*S 270d91e6319SBarry Smith MatInfo - Context of matrix information, used with MatGetInfo() 271d91e6319SBarry Smith 272d91e6319SBarry Smith In Fortran this is simply a double precision array of dimension MAT_INFO_SIZE 273d91e6319SBarry Smith 274d91e6319SBarry Smith Level: intermediate 275d91e6319SBarry Smith 276d91e6319SBarry Smith Concepts: matrix^nonzero information 277d91e6319SBarry Smith 278d9274352SBarry Smith .seealso: MatGetInfo(), MatInfoType 279d91e6319SBarry Smith S*/ 2804e220ebcSLois Curfman McInnes typedef struct { 281b0a32e0cSBarry Smith PetscLogDouble rows_global,columns_global; /* number of global rows and columns */ 282b0a32e0cSBarry Smith PetscLogDouble rows_local,columns_local; /* number of local rows and columns */ 283b0a32e0cSBarry Smith PetscLogDouble block_size; /* block size */ 284b0a32e0cSBarry Smith PetscLogDouble nz_allocated,nz_used,nz_unneeded; /* number of nonzeros */ 285b0a32e0cSBarry Smith PetscLogDouble memory; /* memory allocated */ 286b0a32e0cSBarry Smith PetscLogDouble assemblies; /* number of matrix assemblies called */ 287b0a32e0cSBarry Smith PetscLogDouble mallocs; /* number of mallocs during MatSetValues() */ 288b0a32e0cSBarry Smith PetscLogDouble fill_ratio_given,fill_ratio_needed; /* fill ratio for LU/ILU */ 289b0a32e0cSBarry Smith PetscLogDouble factor_mallocs; /* number of mallocs during factorization */ 2904e220ebcSLois Curfman McInnes } MatInfo; 2914e220ebcSLois Curfman McInnes 292d9274352SBarry Smith /*E 293d9274352SBarry Smith MatInfoType - Indicates if you want information about the local part of the matrix, 294d9274352SBarry Smith the entire parallel matrix or the maximum over all the local parts. 295d9274352SBarry Smith 296d9274352SBarry Smith Level: beginner 297d9274352SBarry Smith 298d9274352SBarry Smith Any additions/changes here MUST also be made in include/finclude/petscmat.h 299d9274352SBarry Smith 300d9274352SBarry Smith .seealso: MatGetInfo(), MatInfo 301d9274352SBarry Smith E*/ 3027b80b807SBarry Smith typedef enum {MAT_LOCAL=1,MAT_GLOBAL_MAX=2,MAT_GLOBAL_SUM=3} MatInfoType; 303ca44d042SBarry Smith EXTERN int MatGetInfo(Mat,MatInfoType,MatInfo*); 304ca44d042SBarry Smith EXTERN int MatValid(Mat,PetscTruth*); 305ca44d042SBarry Smith EXTERN int MatGetDiagonal(Mat,Vec); 306273d9f13SBarry Smith EXTERN int MatGetRowMax(Mat,Vec); 307ca44d042SBarry Smith EXTERN int MatTranspose(Mat,Mat*); 308ca44d042SBarry Smith EXTERN int MatPermute(Mat,IS,IS,Mat *); 309*c06d978dSMatthew Knepley EXTERN int MatPermuteSparsify(Mat,int,double,double,IS,IS,Mat *); 310ca44d042SBarry Smith EXTERN int MatDiagonalScale(Mat,Vec,Vec); 31106ef90c2SBarry Smith EXTERN int MatDiagonalSet(Mat,Vec,InsertMode); 312ca44d042SBarry Smith EXTERN int MatEqual(Mat,Mat,PetscTruth*); 3137b80b807SBarry Smith 31487828ca2SBarry Smith EXTERN int MatNorm(Mat,NormType,PetscReal *); 315ca44d042SBarry Smith EXTERN int MatZeroEntries(Mat); 31687828ca2SBarry Smith EXTERN int MatZeroRows(Mat,IS,PetscScalar*); 31787828ca2SBarry Smith EXTERN int MatZeroColumns(Mat,IS,PetscScalar*); 3187b80b807SBarry Smith 319ca44d042SBarry Smith EXTERN int MatUseScaledForm(Mat,PetscTruth); 320ca44d042SBarry Smith EXTERN int MatScaleSystem(Mat,Vec,Vec); 321ca44d042SBarry Smith EXTERN int MatUnScaleSystem(Mat,Vec,Vec); 3225ef9f2a5SBarry Smith 323ca44d042SBarry Smith EXTERN int MatGetSize(Mat,int*,int*); 324ca44d042SBarry Smith EXTERN int MatGetLocalSize(Mat,int*,int*); 325ca44d042SBarry Smith EXTERN int MatGetOwnershipRange(Mat,int*,int*); 3267b80b807SBarry Smith 327d91e6319SBarry Smith /*E 328d91e6319SBarry Smith MatReuse - Indicates if matrices obtained from a previous call to MatGetSubMatrices() 329d91e6319SBarry Smith or MatGetSubMatrix() are to be reused to store the new matrix values. 330d91e6319SBarry Smith 331d91e6319SBarry Smith Level: beginner 332d91e6319SBarry Smith 333d91e6319SBarry Smith Any additions/changes here MUST also be made in include/finclude/petscmat.h 334d91e6319SBarry Smith 335d91e6319SBarry Smith .seealso: MatGetSubMatrices(), MatGetSubMatrix(), MatDestroyMatrices() 336d91e6319SBarry Smith E*/ 3377b2a1423SBarry Smith typedef enum {MAT_INITIAL_MATRIX,MAT_REUSE_MATRIX} MatReuse; 338ca44d042SBarry Smith EXTERN int MatGetSubMatrices(Mat,int,IS *,IS *,MatReuse,Mat **); 339ca44d042SBarry Smith EXTERN int MatDestroyMatrices(int,Mat **); 340ca44d042SBarry Smith EXTERN int MatGetSubMatrix(Mat,IS,IS,int,MatReuse,Mat *); 3418efafbd8SBarry Smith 342ca44d042SBarry Smith EXTERN int MatIncreaseOverlap(Mat,int,IS *,int); 3437b80b807SBarry Smith 34487828ca2SBarry Smith EXTERN int MatAXPY(PetscScalar *,Mat,Mat); 34587828ca2SBarry Smith EXTERN int MatAYPX(PetscScalar *,Mat,Mat); 346ca44d042SBarry Smith EXTERN int MatCompress(Mat); 3477b80b807SBarry Smith 34887828ca2SBarry Smith EXTERN int MatScale(PetscScalar *,Mat); 34987828ca2SBarry Smith EXTERN int MatShift(PetscScalar *,Mat); 350052efed2SBarry Smith 351ca44d042SBarry Smith EXTERN int MatSetLocalToGlobalMapping(Mat,ISLocalToGlobalMapping); 352ca44d042SBarry Smith EXTERN int MatSetLocalToGlobalMappingBlock(Mat,ISLocalToGlobalMapping); 35387828ca2SBarry Smith EXTERN int MatZeroRowsLocal(Mat,IS,PetscScalar*); 35487828ca2SBarry Smith EXTERN int MatSetValuesLocal(Mat,int,int*,int,int*,PetscScalar*,InsertMode); 35587828ca2SBarry Smith EXTERN int MatSetValuesBlockedLocal(Mat,int,int*,int,int*,PetscScalar*,InsertMode); 35690f02eecSBarry Smith 357ca44d042SBarry Smith EXTERN int MatSetStashInitialSize(Mat,int,int); 358649db694SBarry Smith 359ca44d042SBarry Smith EXTERN int MatInterpolateAdd(Mat,Vec,Vec,Vec); 360ca44d042SBarry Smith EXTERN int MatInterpolate(Mat,Vec,Vec); 361ca44d042SBarry Smith EXTERN int MatRestrict(Mat,Vec,Vec); 3627c922b88SBarry Smith 3637c922b88SBarry Smith /* 364c4f061fbSSatish Balay These three (or four) macros MUST be used together. The third one closes the open { of the first one 3657c922b88SBarry Smith */ 366c4f061fbSSatish Balay #define MatPreallocateInitialize(comm,nrows,ncols,dnz,onz) 0; \ 3677c922b88SBarry Smith { \ 368ef66eb69SBarry Smith int _4_ierr,__tmp = (nrows),__ctmp = (ncols),__rstart,__start,__end; \ 369ef66eb69SBarry Smith _4_ierr = PetscMalloc(2*__tmp*sizeof(int),&dnz);CHKERRQ(_4_ierr);onz = dnz + __tmp;\ 370ef66eb69SBarry Smith _4_ierr = PetscMemzero(dnz,2*__tmp*sizeof(int));CHKERRQ(_4_ierr);\ 371ef66eb69SBarry Smith _4_ierr = MPI_Scan(&__ctmp,&__end,1,MPI_INT,MPI_SUM,comm);CHKERRQ(_4_ierr); __start = __end - __ctmp;\ 372ef66eb69SBarry Smith _4_ierr = MPI_Scan(&__tmp,&__rstart,1,MPI_INT,MPI_SUM,comm);CHKERRQ(_4_ierr); __rstart = __rstart - __tmp; 3737c922b88SBarry Smith 374c4f061fbSSatish Balay #define MatPreallocateSetLocal(map,nrows,rows,ncols,cols,dnz,onz) 0;\ 375c4f061fbSSatish Balay {\ 376c4f061fbSSatish Balay int __l;\ 377ef66eb69SBarry Smith _4_ierr = ISLocalToGlobalMappingApply(map,nrows,rows,rows);CHKERRQ(_4_ierr);\ 378ef66eb69SBarry Smith _4_ierr = ISLocalToGlobalMappingApply(map,ncols,cols,cols);CHKERRQ(_4_ierr);\ 379c4f061fbSSatish Balay for (__l=0;__l<nrows;__l++) {\ 380ef66eb69SBarry Smith _4_ierr = MatPreallocateSet((rows)[__l],ncols,cols,dnz,onz);CHKERRQ(_4_ierr);\ 381c4f061fbSSatish Balay }\ 382c4f061fbSSatish Balay } 383c4f061fbSSatish Balay 384c4f061fbSSatish Balay #define MatPreallocateSet(row,nc,cols,dnz,onz) 0;\ 3857c922b88SBarry Smith { int __i; \ 3867c922b88SBarry Smith for (__i=0; __i<nc; __i++) {\ 3877c922b88SBarry Smith if (cols[__i] < __start || cols[__i] >= __end) onz[row - __rstart]++; \ 3887c922b88SBarry Smith }\ 3897c922b88SBarry Smith dnz[row - __rstart] = nc - onz[row - __rstart];\ 3907c922b88SBarry Smith } 3917c922b88SBarry Smith 392ef66eb69SBarry Smith #define MatPreallocateFinalize(dnz,onz) 0;_4_ierr = PetscFree(dnz);CHKERRQ(_4_ierr);} 3937c922b88SBarry Smith 3947b80b807SBarry Smith /* Routines unique to particular data structures */ 395435da068SBarry Smith EXTERN int MatShellGetContext(Mat,void **); 396435da068SBarry Smith 39787828ca2SBarry Smith EXTERN int MatBDiagGetData(Mat,int*,int*,int**,int**,PetscScalar***); 398ca44d042SBarry Smith EXTERN int MatSeqAIJSetColumnIndices(Mat,int *); 399ca44d042SBarry Smith EXTERN int MatSeqBAIJSetColumnIndices(Mat,int *); 40087828ca2SBarry Smith EXTERN int MatCreateSeqAIJWithArrays(MPI_Comm,int,int,int*,int*,PetscScalar *,Mat*); 4017b80b807SBarry Smith 402273d9f13SBarry Smith EXTERN int MatSeqBAIJSetPreallocation(Mat,int,int,int*); 403273d9f13SBarry Smith EXTERN int MatSeqSBAIJSetPreallocation(Mat,int,int,int*); 404273d9f13SBarry Smith EXTERN int MatSeqAIJSetPreallocation(Mat,int,int*); 40587828ca2SBarry Smith EXTERN int MatSeqDensePreallocation(Mat,PetscScalar*); 40687828ca2SBarry Smith EXTERN int MatSeqBDiagSetPreallocation(Mat,int,int,int*,PetscScalar**); 40787828ca2SBarry Smith EXTERN int MatSeqDenseSetPreallocation(Mat,PetscScalar*); 408273d9f13SBarry Smith 409273d9f13SBarry Smith EXTERN int MatMPIBAIJSetPreallocation(Mat,int,int,int*,int,int*); 410273d9f13SBarry Smith EXTERN int MatMPISBAIJSetPreallocation(Mat,int,int,int*,int,int*); 411273d9f13SBarry Smith EXTERN int MatMPIAIJSetPreallocation(Mat,int,int*,int,int*); 41287828ca2SBarry Smith EXTERN int MatMPIDensePreallocation(Mat,PetscScalar*); 41387828ca2SBarry Smith EXTERN int MatMPIBDiagSetPreallocation(Mat,int,int,int*,PetscScalar**); 414273d9f13SBarry Smith EXTERN int MatMPIAdjSetPreallocation(Mat,int*,int*,int*); 41587828ca2SBarry Smith EXTERN int MatMPIDenseSetPreallocation(Mat,PetscScalar*); 416273d9f13SBarry Smith EXTERN int MatMPIRowbsSetPreallocation(Mat,int,int*); 417435da068SBarry Smith EXTERN int MatMPIAIJGetSeqAIJ(Mat,Mat*,Mat*,int**); 418435da068SBarry Smith EXTERN int MatMPIBAIJGetSeqBAIJ(Mat,Mat*,Mat*,int**); 4193a7fca6bSBarry Smith EXTERN int MatAdicSetLocalFunction(Mat,void (*)(void)); 420273d9f13SBarry Smith 421ca44d042SBarry Smith EXTERN int MatStoreValues(Mat); 422ca44d042SBarry Smith EXTERN int MatRetrieveValues(Mat); 4232e8a6d31SBarry Smith 4243a7fca6bSBarry Smith EXTERN int MatDAADSetCtx(Mat,void*); 4253a7fca6bSBarry Smith 4267b80b807SBarry Smith /* 4277b80b807SBarry Smith These routines are not usually accessed directly, rather solving is 4287b80b807SBarry Smith done through the SLES, KSP and PC interfaces. 4297b80b807SBarry Smith */ 4307b80b807SBarry Smith 431d9274352SBarry Smith /*E 432d9274352SBarry Smith MatOrderingType - String with the name of a PETSc matrix ordering or the creation function 433d9274352SBarry Smith with an optional dynamic library name, for example 434d9274352SBarry Smith http://www.mcs.anl.gov/petsc/lib.a:orderingcreate() 435d9274352SBarry Smith 436d9274352SBarry Smith Level: beginner 437d9274352SBarry Smith 438d9274352SBarry Smith .seealso: MatGetOrdering() 439d9274352SBarry Smith E*/ 440b12f92e5SBarry Smith typedef char* MatOrderingType; 441b12f92e5SBarry Smith #define MATORDERING_NATURAL "natural" 442b12f92e5SBarry Smith #define MATORDERING_ND "nd" 443b12f92e5SBarry Smith #define MATORDERING_1WD "1wd" 444b12f92e5SBarry Smith #define MATORDERING_RCM "rcm" 445b12f92e5SBarry Smith #define MATORDERING_QMD "qmd" 446b12f92e5SBarry Smith #define MATORDERING_ROWLENGTH "rowlength" 44762152c8bSBarry Smith #define MATORDERING_DSC_ND "dsc_nd" 44862152c8bSBarry Smith #define MATORDERING_DSC_MMD "dsc_mmd" 44962152c8bSBarry Smith #define MATORDERING_DSC_MDF "dsc_mdf" 450*c06d978dSMatthew Knepley #define MATORDERING_CONSTRAINED "constrained" 451*c06d978dSMatthew Knepley #define MATORDERING_IDENTITY "identity" 452*c06d978dSMatthew Knepley #define MATORDERING_REVERSE "reverse" 453b12f92e5SBarry Smith 454ca44d042SBarry Smith EXTERN int MatGetOrdering(Mat,MatOrderingType,IS*,IS*); 455ca44d042SBarry Smith EXTERN int MatOrderingRegister(char*,char*,char*,int(*)(Mat,MatOrderingType,IS*,IS*)); 456aa482453SBarry Smith #if defined(PETSC_USE_DYNAMIC_LIBRARIES) 457f1af5d2fSBarry Smith #define MatOrderingRegisterDynamic(a,b,c,d) MatOrderingRegister(a,b,c,0) 458b12f92e5SBarry Smith #else 459f1af5d2fSBarry Smith #define MatOrderingRegisterDynamic(a,b,c,d) MatOrderingRegister(a,b,c,d) 460b12f92e5SBarry Smith #endif 461ca44d042SBarry Smith EXTERN int MatOrderingRegisterDestroy(void); 462ca44d042SBarry Smith EXTERN int MatOrderingRegisterAll(char*); 4632bad1931SBarry Smith extern PetscTruth MatOrderingRegisterAllCalled; 464b0a32e0cSBarry Smith extern PetscFList MatOrderingList; 465d4fbbf0eSBarry Smith 46687828ca2SBarry Smith EXTERN int MatReorderForNonzeroDiagonal(Mat,PetscReal,IS,IS); 467a2ce50c7SBarry Smith 46887828ca2SBarry Smith EXTERN int MatCholeskyFactor(Mat,IS,PetscReal); 46987828ca2SBarry Smith EXTERN int MatCholeskyFactorSymbolic(Mat,IS,PetscReal,Mat*); 470ca44d042SBarry Smith EXTERN int MatCholeskyFactorNumeric(Mat,Mat*); 471a2ce50c7SBarry Smith 472d91e6319SBarry Smith /*S 473d91e6319SBarry Smith MatILUInfo - Data based into the matrix ILU factorization routines 4745ef9f2a5SBarry Smith 475d91e6319SBarry Smith In Fortran these are simply double precision arrays of size MAT_ILUINFO_SIZE 47614822f30SBarry Smith 477d91e6319SBarry Smith Notes: These are not usually directly used by users, instead use the PC type of ILU 478d91e6319SBarry Smith All entries are double precision. 479d91e6319SBarry Smith 480d91e6319SBarry Smith Level: developer 481d91e6319SBarry Smith 482d91e6319SBarry Smith .seealso: MatILUFactorSymbolic(), MatILUFactor(), MatLUInfo, MatCholeskyInfo 483d91e6319SBarry Smith 484d91e6319SBarry Smith S*/ 4855ef9f2a5SBarry Smith typedef struct { 486f6275e2eSBarry Smith PetscReal levels; /* ILU(levels) */ 487f6275e2eSBarry Smith PetscReal fill; /* expected fill; nonzeros in factored matrix/nonzeros in original matrix*/ 488f6275e2eSBarry Smith PetscReal diagonal_fill; /* force diagonal to fill in if initially not filled */ 489f6275e2eSBarry Smith PetscReal dt; /* drop tolerance */ 490f6275e2eSBarry Smith PetscReal dtcol; /* tolerance for pivoting */ 491f6275e2eSBarry Smith PetscReal dtcount; /* maximum nonzeros to be allowed per row */ 492f6275e2eSBarry Smith PetscReal damping; /* scaling of identity added to matrix to prevent zero pivots */ 493f6275e2eSBarry Smith PetscReal damp; /* if is 1.0 and factorization fails, damp until successful */ 494f6275e2eSBarry Smith PetscReal zeropivot; /* pivot is called zero if less than this */ 4955ef9f2a5SBarry Smith } MatILUInfo; 4965ef9f2a5SBarry Smith 497d91e6319SBarry Smith /*S 498d91e6319SBarry Smith MatLUInfo - Data based into the matrix LU factorization routines 499d91e6319SBarry Smith 500d91e6319SBarry Smith In Fortran these are simply double precision arrays of size MAT_LUINFO_SIZE 501d91e6319SBarry Smith 502d91e6319SBarry Smith Notes: These are not usually directly used by users, instead use the PC type of LU 503d91e6319SBarry Smith All entries are double precision. 504d91e6319SBarry Smith 505d91e6319SBarry Smith Level: developer 506d91e6319SBarry Smith 507d91e6319SBarry Smith .seealso: MatLUFactorSymbolic(), MatILUInfo, MatCholeskyInfo 508d91e6319SBarry Smith 509d91e6319SBarry Smith S*/ 51014822f30SBarry Smith typedef struct { 511f6275e2eSBarry Smith PetscReal fill; /* expected fill; nonzeros in factored matrix/nonzeros in original matrix */ 512f6275e2eSBarry Smith PetscReal dtcol; /* tolerance for pivoting; pivot if off_diagonal*dtcol > diagonal */ 513f6275e2eSBarry Smith PetscReal damping; /* scaling of identity added to matrix to prevent zero pivots */ 514f6275e2eSBarry Smith PetscReal damp; /* if this is 1.0 and factorization fails, damp until successful */ 515f6275e2eSBarry Smith PetscReal zeropivot; /* pivot is called zero if less than this */ 51614822f30SBarry Smith } MatLUInfo; 51714822f30SBarry Smith 518d91e6319SBarry Smith /*S 519d91e6319SBarry Smith MatCholeskyInfo - Data based into the matrix Cholesky factorization routines 520d91e6319SBarry Smith 521d91e6319SBarry Smith In Fortran these are simply double precision arrays of size MAT_CHOLESKYINFO_SIZE 522d91e6319SBarry Smith 523d91e6319SBarry Smith Notes: These are not usually directly used by users, instead use the PC type of Cholesky 524d91e6319SBarry Smith All entries are double precision. 525d91e6319SBarry Smith 526d91e6319SBarry Smith Level: developer 527d91e6319SBarry Smith 528d91e6319SBarry Smith .seealso: MatCholeskyFactorSymbolic(), MatLUInfo, MatILUInfo 529d91e6319SBarry Smith 530d91e6319SBarry Smith S*/ 531ffa6d0a5SLois Curfman McInnes typedef struct { 532f6275e2eSBarry Smith PetscReal fill; /* expected fill; nonzeros in factored matrix/nonzeros in original matrix */ 533f6275e2eSBarry Smith PetscReal damping; /* scaling of identity added to matrix to prevent zero pivots */ 534f6275e2eSBarry Smith PetscReal damp; /* if this is 1.0 and factorization fails, damp until successful */ 535ffa6d0a5SLois Curfman McInnes } MatCholeskyInfo; 536ffa6d0a5SLois Curfman McInnes 53714822f30SBarry Smith EXTERN int MatLUFactor(Mat,IS,IS,MatLUInfo*); 538ca44d042SBarry Smith EXTERN int MatILUFactor(Mat,IS,IS,MatILUInfo*); 53914822f30SBarry Smith EXTERN int MatLUFactorSymbolic(Mat,IS,IS,MatLUInfo*,Mat*); 540ca44d042SBarry Smith EXTERN int MatILUFactorSymbolic(Mat,IS,IS,MatILUInfo*,Mat*); 54187828ca2SBarry Smith EXTERN int MatICCFactorSymbolic(Mat,IS,PetscReal,int,Mat*); 54287828ca2SBarry Smith EXTERN int MatICCFactor(Mat,IS,PetscReal,int); 543ca44d042SBarry Smith EXTERN int MatLUFactorNumeric(Mat,Mat*); 544ca44d042SBarry Smith EXTERN int MatILUDTFactor(Mat,MatILUInfo*,IS,IS,Mat *); 545a2ce50c7SBarry Smith 546ca44d042SBarry Smith EXTERN int MatSolve(Mat,Vec,Vec); 547ca44d042SBarry Smith EXTERN int MatForwardSolve(Mat,Vec,Vec); 548ca44d042SBarry Smith EXTERN int MatBackwardSolve(Mat,Vec,Vec); 549ca44d042SBarry Smith EXTERN int MatSolveAdd(Mat,Vec,Vec,Vec); 550ca44d042SBarry Smith EXTERN int MatSolveTranspose(Mat,Vec,Vec); 551ca44d042SBarry Smith EXTERN int MatSolveTransposeAdd(Mat,Vec,Vec,Vec); 5528ed539a5SBarry Smith 553ca44d042SBarry Smith EXTERN int MatSetUnfactored(Mat); 554bb5a7306SBarry Smith 555bb1eb677SSatish Balay /* MatSORType may be bitwise ORd together, so do not change the numbers */ 556d91e6319SBarry Smith /*E 557d91e6319SBarry Smith MatSORType - What type of (S)SOR to perform 558bb1eb677SSatish Balay 559d91e6319SBarry Smith Level: beginner 560d91e6319SBarry Smith 561d9274352SBarry Smith May be bitwise ORd together 562d9274352SBarry Smith 563d91e6319SBarry Smith Any additions/changes here MUST also be made in include/finclude/petscmat.h 564d91e6319SBarry Smith 565d91e6319SBarry Smith .seealso: MatRelax() 566d91e6319SBarry Smith E*/ 567ee50ffe9SBarry Smith typedef enum {SOR_FORWARD_SWEEP=1,SOR_BACKWARD_SWEEP=2,SOR_SYMMETRIC_SWEEP=3, 568ee50ffe9SBarry Smith SOR_LOCAL_FORWARD_SWEEP=4,SOR_LOCAL_BACKWARD_SWEEP=8, 569ee50ffe9SBarry Smith SOR_LOCAL_SYMMETRIC_SWEEP=12,SOR_ZERO_INITIAL_GUESS=16, 57084cb2905SBarry Smith SOR_EISENSTAT=32,SOR_APPLY_UPPER=64,SOR_APPLY_LOWER=128} MatSORType; 57187828ca2SBarry Smith EXTERN int MatRelax(Mat,Vec,PetscReal,MatSORType,PetscReal,int,Vec); 5728ed539a5SBarry Smith 573d4fbbf0eSBarry Smith /* 574639f9d9dSBarry Smith These routines are for efficiently computing Jacobians via finite differences. 575639f9d9dSBarry Smith */ 576b12f92e5SBarry Smith 577d9274352SBarry Smith /*E 578d9274352SBarry Smith MatColoringType - String with the name of a PETSc matrix coloring or the creation function 579d9274352SBarry Smith with an optional dynamic library name, for example 580d9274352SBarry Smith http://www.mcs.anl.gov/petsc/lib.a:coloringcreate() 581d9274352SBarry Smith 582d9274352SBarry Smith Level: beginner 583d9274352SBarry Smith 584d9274352SBarry Smith .seealso: MatGetColoring() 585d9274352SBarry Smith E*/ 586b12f92e5SBarry Smith typedef char* MatColoringType; 587b12f92e5SBarry Smith #define MATCOLORING_NATURAL "natural" 588b12f92e5SBarry Smith #define MATCOLORING_SL "sl" 589b12f92e5SBarry Smith #define MATCOLORING_LF "lf" 590b12f92e5SBarry Smith #define MATCOLORING_ID "id" 591b12f92e5SBarry Smith 592ca44d042SBarry Smith EXTERN int MatGetColoring(Mat,MatColoringType,ISColoring*); 593ca44d042SBarry Smith EXTERN int MatColoringRegister(char*,char*,char*,int(*)(Mat,MatColoringType,ISColoring *)); 594aa482453SBarry Smith #if defined(PETSC_USE_DYNAMIC_LIBRARIES) 595f1af5d2fSBarry Smith #define MatColoringRegisterDynamic(a,b,c,d) MatColoringRegister(a,b,c,0) 596b12f92e5SBarry Smith #else 597f1af5d2fSBarry Smith #define MatColoringRegisterDynamic(a,b,c,d) MatColoringRegister(a,b,c,d) 598b12f92e5SBarry Smith #endif 599ca44d042SBarry Smith EXTERN int MatColoringRegisterAll(char *); 6002bad1931SBarry Smith extern PetscTruth MatColoringRegisterAllCalled; 601ca44d042SBarry Smith EXTERN int MatColoringRegisterDestroy(void); 602b9617806SBarry Smith EXTERN int MatColoringPatch(Mat,int,int,int *,ISColoring*); 603639f9d9dSBarry Smith 6041a0a18cdSSatish Balay #define MAT_FDCOLORING_COOKIE PETSC_COOKIE + 23 605d9274352SBarry Smith /*S 606d9274352SBarry Smith MatFDColoring - Object for computing a sparse Jacobian via finite differences 607d9274352SBarry Smith and coloring 608639f9d9dSBarry Smith 609d9274352SBarry Smith Level: beginner 610d9274352SBarry Smith 611d9274352SBarry Smith Concepts: coloring, sparse Jacobian, finite differences 612d9274352SBarry Smith 613d9274352SBarry Smith .seealso: MatFDColoringCreate() 614d9274352SBarry Smith S*/ 615e2a1c21fSSatish Balay typedef struct _p_MatFDColoring *MatFDColoring; 616639f9d9dSBarry Smith 617ca44d042SBarry Smith EXTERN int MatFDColoringCreate(Mat,ISColoring,MatFDColoring *); 618ca44d042SBarry Smith EXTERN int MatFDColoringDestroy(MatFDColoring); 619b0a32e0cSBarry Smith EXTERN int MatFDColoringView(MatFDColoring,PetscViewer); 620ca44d042SBarry Smith EXTERN int MatFDColoringSetFunction(MatFDColoring,int (*)(void),void*); 62187828ca2SBarry Smith EXTERN int MatFDColoringSetParameters(MatFDColoring,PetscReal,PetscReal); 622ca44d042SBarry Smith EXTERN int MatFDColoringSetFrequency(MatFDColoring,int); 623ca44d042SBarry Smith EXTERN int MatFDColoringGetFrequency(MatFDColoring,int*); 624ca44d042SBarry Smith EXTERN int MatFDColoringSetFromOptions(MatFDColoring); 625ca44d042SBarry Smith EXTERN int MatFDColoringApply(Mat,MatFDColoring,Vec,MatStructure*,void *); 62687828ca2SBarry Smith EXTERN int MatFDColoringApplyTS(Mat,MatFDColoring,PetscReal,Vec,MatStructure*,void *); 62762152c8bSBarry Smith EXTERN int MatFDColoringSetRecompute(MatFDColoring); 6283a7fca6bSBarry Smith EXTERN int MatFDColoringSetF(MatFDColoring,Vec); 629639f9d9dSBarry Smith 630639f9d9dSBarry Smith /* 6310752156aSBarry Smith These routines are for partitioning matrices: currently used only 6323eda8832SBarry Smith for adjacency matrix, MatCreateMPIAdj(). 6330752156aSBarry Smith */ 63491e9ee9fSBarry Smith #define MATPARTITIONING_COOKIE PETSC_COOKIE + 25 635ca161407SBarry Smith 636d9274352SBarry Smith /*S 637d9274352SBarry Smith MatPartitioning - Object for managing the partitioning of a matrix or graph 638d9274352SBarry Smith 639d9274352SBarry Smith Level: beginner 640d9274352SBarry Smith 641d9274352SBarry Smith Concepts: partitioning 642d9274352SBarry Smith 643d9274352SBarry Smith .seealso: MatParitioningCreate(), MatPartitioningType 644d9274352SBarry Smith S*/ 64591e9ee9fSBarry Smith typedef struct _p_MatPartitioning *MatPartitioning; 646d9274352SBarry Smith 647d9274352SBarry Smith /*E 648d9274352SBarry Smith MatPartitioningType - String with the name of a PETSc matrix partitioing or the creation function 649d9274352SBarry Smith with an optional dynamic library name, for example 650d9274352SBarry Smith http://www.mcs.anl.gov/petsc/lib.a:partitioningcreate() 651d9274352SBarry Smith 652d9274352SBarry Smith Level: beginner 653d9274352SBarry Smith 654d9274352SBarry Smith .seealso: MatPartitioingCreate(), MatPartitioning 655d9274352SBarry Smith E*/ 6562aabb6bbSBarry Smith typedef char* MatPartitioningType; 6572aabb6bbSBarry Smith #define MATPARTITIONING_CURRENT "current" 6582aabb6bbSBarry Smith #define MATPARTITIONING_PARMETIS "parmetis" 659ca161407SBarry Smith 660ca44d042SBarry Smith EXTERN int MatPartitioningCreate(MPI_Comm,MatPartitioning*); 661ca44d042SBarry Smith EXTERN int MatPartitioningSetType(MatPartitioning,MatPartitioningType); 662ca44d042SBarry Smith EXTERN int MatPartitioningSetAdjacency(MatPartitioning,Mat); 663ca44d042SBarry Smith EXTERN int MatPartitioningSetVertexWeights(MatPartitioning,int*); 664ca44d042SBarry Smith EXTERN int MatPartitioningApply(MatPartitioning,IS*); 665ca44d042SBarry Smith EXTERN int MatPartitioningDestroy(MatPartitioning); 6662aabb6bbSBarry Smith 667ca44d042SBarry Smith EXTERN int MatPartitioningRegister(char*,char*,char*,int(*)(MatPartitioning)); 668aa482453SBarry Smith #if defined(PETSC_USE_DYNAMIC_LIBRARIES) 669f1af5d2fSBarry Smith #define MatPartitioningRegisterDynamic(a,b,c,d) MatPartitioningRegister(a,b,c,0) 6702aabb6bbSBarry Smith #else 671f1af5d2fSBarry Smith #define MatPartitioningRegisterDynamic(a,b,c,d) MatPartitioningRegister(a,b,c,d) 6722aabb6bbSBarry Smith #endif 6732aabb6bbSBarry Smith 674ca44d042SBarry Smith EXTERN int MatPartitioningRegisterAll(char *); 6752bad1931SBarry Smith extern PetscTruth MatPartitioningRegisterAllCalled; 676ca44d042SBarry Smith EXTERN int MatPartitioningRegisterDestroy(void); 6772bad1931SBarry Smith 678b0a32e0cSBarry Smith EXTERN int MatPartitioningView(MatPartitioning,PetscViewer); 679ca44d042SBarry Smith EXTERN int MatPartitioningSetFromOptions(MatPartitioning); 680ca44d042SBarry Smith EXTERN int MatPartitioningGetType(MatPartitioning,MatPartitioningType*); 681ca161407SBarry Smith 682ca44d042SBarry Smith EXTERN int MatPartitioningParmetisSetCoarseSequential(MatPartitioning); 6830752156aSBarry Smith 6840752156aSBarry Smith /* 6850a835dfdSSatish Balay If you add entries here you must also add them to finclude/petscmat.h 686d4fbbf0eSBarry Smith */ 6871c1c02c0SLois Curfman McInnes typedef enum { MATOP_SET_VALUES=0, 6881c1c02c0SLois Curfman McInnes MATOP_GET_ROW=1, 6891c1c02c0SLois Curfman McInnes MATOP_RESTORE_ROW=2, 6901c1c02c0SLois Curfman McInnes MATOP_MULT=3, 6911c1c02c0SLois Curfman McInnes MATOP_MULT_ADD=4, 6927c922b88SBarry Smith MATOP_MULT_TRANSPOSE=5, 6937c922b88SBarry Smith MATOP_MULT_TRANSPOSE_ADD=6, 6941c1c02c0SLois Curfman McInnes MATOP_SOLVE=7, 6951c1c02c0SLois Curfman McInnes MATOP_SOLVE_ADD=8, 6967c922b88SBarry Smith MATOP_SOLVE_TRANSPOSE=9, 6977c922b88SBarry Smith MATOP_SOLVE_TRANSPOSE_ADD=10, 6981c1c02c0SLois Curfman McInnes MATOP_LUFACTOR=11, 6991c1c02c0SLois Curfman McInnes MATOP_CHOLESKYFACTOR=12, 7001c1c02c0SLois Curfman McInnes MATOP_RELAX=13, 7011c1c02c0SLois Curfman McInnes MATOP_TRANSPOSE=14, 7021c1c02c0SLois Curfman McInnes MATOP_GETINFO=15, 7031c1c02c0SLois Curfman McInnes MATOP_EQUAL=16, 7041c1c02c0SLois Curfman McInnes MATOP_GET_DIAGONAL=17, 7051c1c02c0SLois Curfman McInnes MATOP_DIAGONAL_SCALE=18, 7061c1c02c0SLois Curfman McInnes MATOP_NORM=19, 7071c1c02c0SLois Curfman McInnes MATOP_ASSEMBLY_BEGIN=20, 7081c1c02c0SLois Curfman McInnes MATOP_ASSEMBLY_END=21, 7091c1c02c0SLois Curfman McInnes MATOP_COMPRESS=22, 7101c1c02c0SLois Curfman McInnes MATOP_SET_OPTION=23, 7111c1c02c0SLois Curfman McInnes MATOP_ZERO_ENTRIES=24, 7121c1c02c0SLois Curfman McInnes MATOP_ZERO_ROWS=25, 7131c1c02c0SLois Curfman McInnes MATOP_LUFACTOR_SYMBOLIC=26, 7141c1c02c0SLois Curfman McInnes MATOP_LUFACTOR_NUMERIC=27, 7151c1c02c0SLois Curfman McInnes MATOP_CHOLESKY_FACTOR_SYMBOLIC=28, 7161c1c02c0SLois Curfman McInnes MATOP_CHOLESKY_FACTOR_NUMERIC=29, 7171c1c02c0SLois Curfman McInnes MATOP_GET_SIZE=30, 7181c1c02c0SLois Curfman McInnes MATOP_GET_LOCAL_SIZE=31, 7191c1c02c0SLois Curfman McInnes MATOP_GET_OWNERSHIP_RANGE=32, 7201c1c02c0SLois Curfman McInnes MATOP_ILUFACTOR_SYMBOLIC=33, 7214d101231SSatish Balay MATOP_ICCFACTOR_SYMBOLIC=34, 7221c1c02c0SLois Curfman McInnes MATOP_GET_ARRAY=35, 7231c1c02c0SLois Curfman McInnes MATOP_RESTORE_ARRAY=36, 7247bf97ca4SSatish Balay 725005c665bSBarry Smith MATOP_CONVERT_SAME_TYPE=37, 726005c665bSBarry Smith MATOP_FORWARD_SOLVE=38, 727005c665bSBarry Smith MATOP_BACKWARD_SOLVE=39, 728005c665bSBarry Smith MATOP_ILUFACTOR=40, 7294d101231SSatish Balay MATOP_ICCFACTOR=41, 730005c665bSBarry Smith MATOP_AXPY=42, 731005c665bSBarry Smith MATOP_GET_SUBMATRICES=43, 732005c665bSBarry Smith MATOP_INCREASE_OVERLAP=44, 733005c665bSBarry Smith MATOP_GET_VALUES=45, 734005c665bSBarry Smith MATOP_COPY=46, 735005c665bSBarry Smith MATOP_PRINT_HELP=47, 736005c665bSBarry Smith MATOP_SCALE=48, 737005c665bSBarry Smith MATOP_SHIFT=49, 738005c665bSBarry Smith MATOP_DIAGONAL_SHIFT=50, 739005c665bSBarry Smith MATOP_ILUDT_FACTOR=51, 740005c665bSBarry Smith MATOP_GET_BLOCK_SIZE=52, 741005c665bSBarry Smith MATOP_GET_ROW_IJ=53, 742005c665bSBarry Smith MATOP_RESTORE_ROW_IJ=54, 743005c665bSBarry Smith MATOP_GET_COLUMN_IJ=55, 744005c665bSBarry Smith MATOP_RESTORE_COLUMN_IJ=56, 745005c665bSBarry Smith MATOP_FDCOLORING_CREATE=57, 746005c665bSBarry Smith MATOP_COLORING_PATCH=58, 747005c665bSBarry Smith MATOP_SET_UNFACTORED=59, 748005c665bSBarry Smith MATOP_PERMUTE=60, 749005c665bSBarry Smith MATOP_SET_VALUES_BLOCKED=61, 750*c06d978dSMatthew Knepley MATOP_GET_SUBMATRIX=62, 751*c06d978dSMatthew Knepley MATOP_GET_MAPS=65, 752*c06d978dSMatthew Knepley MATOP_USE_SCALED_FORM=66, 753*c06d978dSMatthew Knepley MATOP_SCALE_SYSTEM=67, 754*c06d978dSMatthew Knepley MATOP_UNSCALE_SYSTEM=68, 755*c06d978dSMatthew Knepley MATOP_SET_LOCAL_TO_GLOBAL_MAPPING=69, 756*c06d978dSMatthew Knepley MATOP_SET_VALUES_LOCAL=70, 757*c06d978dSMatthew Knepley MATOP_ZERO_ROWS_LOCAL=71, 758*c06d978dSMatthew Knepley MATOP_GET_ROW_MAX=72, 759*c06d978dSMatthew Knepley MATOP_CONVERT=73, 760*c06d978dSMatthew Knepley MATOP_SET_COLORING=74, 761*c06d978dSMatthew Knepley MATOP_SET_VALUES_ADIC=75, 762*c06d978dSMatthew Knepley MATOP_SET_VALUES_ADIFOR=76, 763*c06d978dSMatthew Knepley MATOP_FD_COLORING_APPLY=77, 764*c06d978dSMatthew Knepley MATOP_SET_FROM_OPTIONS=78, 765*c06d978dSMatthew Knepley MATOP_MULT_CONSTRAINED=79, 766*c06d978dSMatthew Knepley MATOP_ILU_FACTOR_SYMBOLIC_CONSTRAINED=80, 767*c06d978dSMatthew Knepley MATOP_SERIALIZE=81, 768*c06d978dSMatthew Knepley MATOP_PERMUTE_SPARSIFY=82, 769*c06d978dSMatthew Knepley MATOP_MULT_MULTIPLE=83, 770*c06d978dSMatthew Knepley MATOP_SOLVE_MULTIPLE=84, 7711c1c02c0SLois Curfman McInnes MATOP_DESTROY=250, 7721c1c02c0SLois Curfman McInnes MATOP_VIEW=251 773fae171e0SBarry Smith } MatOperation; 774ca44d042SBarry Smith EXTERN int MatHasOperation(Mat,MatOperation,PetscTruth*); 77537bd1cefSSatish Balay EXTERN int MatShellSetOperation(Mat,MatOperation,void(*)()); 77637bd1cefSSatish Balay EXTERN int MatShellGetOperation(Mat,MatOperation,void(**)()); 777273d9f13SBarry Smith EXTERN int MatShellSetContext(Mat,void*); 778112a2221SBarry Smith 77990ace30eSBarry Smith /* 78090ace30eSBarry Smith Codes for matrices stored on disk. By default they are 78190ace30eSBarry Smith stored in a universal format. By changing the format with 782fb9695e5SSatish Balay PetscViewerSetFormat(viewer,PETSC_VIEWER_BINARY_NATIVE); the matrices will 78390ace30eSBarry Smith be stored in a way natural for the matrix, for example dense matrices 78490ace30eSBarry Smith would be stored as dense. Matrices stored this way may only be 78590ace30eSBarry Smith read into matrices of the same time. 78690ace30eSBarry Smith */ 78790ace30eSBarry Smith #define MATRIX_BINARY_FORMAT_DENSE -1 78890ace30eSBarry Smith 7893f1d51d7SBarry Smith /* 7903f1d51d7SBarry Smith New matrix classes not yet distributed 7913f1d51d7SBarry Smith */ 7923f1d51d7SBarry Smith /* 7933f1d51d7SBarry Smith MatAIJIndices is a data structure for storing the nonzero location information 7943f1d51d7SBarry Smith for sparse matrices. Several matrices with identical nonzero structure can share 7953f1d51d7SBarry Smith the same MatAIJIndices. 7963f1d51d7SBarry Smith */ 797e2a1c21fSSatish Balay typedef struct _p_MatAIJIndices* MatAIJIndices; 7983f1d51d7SBarry Smith 799ca44d042SBarry Smith EXTERN int MatCreateAIJIndices(int,int,int*,int*,PetscTruth,MatAIJIndices*); 800ca44d042SBarry Smith EXTERN int MatCreateAIJIndicesEmpty(int,int,int*,PetscTruth,MatAIJIndices*); 801ca44d042SBarry Smith EXTERN int MatAttachAIJIndices(MatAIJIndices,MatAIJIndices*); 802ca44d042SBarry Smith EXTERN int MatDestroyAIJIndices(MatAIJIndices); 803ca44d042SBarry Smith EXTERN int MatCopyAIJIndices(MatAIJIndices,MatAIJIndices*); 804ca44d042SBarry Smith EXTERN int MatValidateAIJIndices(int,MatAIJIndices); 805ca44d042SBarry Smith EXTERN int MatShiftAIJIndices(MatAIJIndices); 806ca44d042SBarry Smith EXTERN int MatShrinkAIJIndices(MatAIJIndices); 807ca44d042SBarry Smith EXTERN int MatTransposeAIJIndices(MatAIJIndices,MatAIJIndices*); 8083f1d51d7SBarry Smith 809ca44d042SBarry Smith EXTERN int MatCreateSeqCSN(MPI_Comm,int,int,int*,int,Mat*); 810ca44d042SBarry Smith EXTERN int MatCreateSeqCSN_Single(MPI_Comm,int,int,int*,int,Mat*); 81187828ca2SBarry Smith EXTERN int MatCreateSeqCSNWithPrecision(MPI_Comm,int,int,int*,int,PetscScalarPrecision,Mat*); 8123f1d51d7SBarry Smith 813ca44d042SBarry Smith EXTERN int MatCreateSeqCSNIndices(MPI_Comm,MatAIJIndices,int,Mat *); 814ca44d042SBarry Smith EXTERN int MatCreateSeqCSNIndices_Single(MPI_Comm,MatAIJIndices,int,Mat *); 81587828ca2SBarry Smith EXTERN int MatCreateSeqCSNIndicesWithPrecision(MPI_Comm,MatAIJIndices,int,PetscScalarPrecision,Mat *); 8163f1d51d7SBarry Smith 8176d053be9SSatish Balay EXTERN int MatMPIBAIJSetHashTableFactor(Mat,PetscReal); 818ca44d042SBarry Smith EXTERN int MatSeqAIJGetInodeSizes(Mat,int *,int *[],int *); 81908918a0eSSatish Balay EXTERN int MatMPIRowbsGetColor(Mat,ISColoring *); 820860d1616SSatish Balay 821d9274352SBarry Smith /*S 822d9274352SBarry Smith MatNullSpace - Object that removes a null space from a vector, i.e. 823d9274352SBarry Smith orthogonalizes the vector to a subsapce 824d9274352SBarry Smith 825d9274352SBarry Smith Level: beginner 826d9274352SBarry Smith 827d9274352SBarry Smith Concepts: matrix; linear operator, null space 828d9274352SBarry Smith 829d9274352SBarry Smith .seealso: MatNullSpaceCreate() 830d9274352SBarry Smith S*/ 83174637425SBarry Smith typedef struct _p_MatNullSpace* MatNullSpace; 832d9274352SBarry Smith 83374637425SBarry Smith #define MATNULLSPACE_COOKIE PETSC_COOKIE+17 83474637425SBarry Smith 83574637425SBarry Smith EXTERN int MatNullSpaceCreate(MPI_Comm,int,int,Vec *,MatNullSpace*); 83674637425SBarry Smith EXTERN int MatNullSpaceDestroy(MatNullSpace); 83774637425SBarry Smith EXTERN int MatNullSpaceRemove(MatNullSpace,Vec,Vec*); 83874637425SBarry Smith EXTERN int MatNullSpaceAttach(Mat,MatNullSpace); 83974637425SBarry Smith EXTERN int MatNullSpaceTest(MatNullSpace,Mat); 84074637425SBarry Smith 841273d9f13SBarry Smith EXTERN int MatReorderingSeqSBAIJ(Mat A,IS isp); 842273d9f13SBarry Smith EXTERN int MatMPISBAIJSetHashTableFactor(Mat,PetscReal); 843273d9f13SBarry Smith EXTERN int MatSeqSBAIJSetColumnIndices(Mat,int *); 844273d9f13SBarry Smith 8453f1d51d7SBarry Smith 846f069c275SSatish Balay EXTERN int MatCreateMAIJ(Mat,int,Mat*); 847c4f061fbSSatish Balay EXTERN int MatMAIJRedimension(Mat,int,Mat*); 848c4f061fbSSatish Balay EXTERN int MatMAIJGetAIJ(Mat,Mat*); 849c4f061fbSSatish Balay 850273d9f13SBarry Smith EXTERN int MatMPIAdjSetValues(Mat,int*,int*,int*); 851f069c275SSatish Balay 852b0a32e0cSBarry Smith EXTERN int MatComputeExplicitOperator(Mat,Mat*); 853b0a32e0cSBarry Smith 8542eac72dbSBarry Smith #endif 8552eac72dbSBarry Smith 8562eac72dbSBarry Smith 8579d00d63dSBarry Smith 858