xref: /petsc/include/petscmat.h (revision 7bf97ca44850e1a250eb4e644f3d2d8ba6412f32)
1*7bf97ca4SSatish Balay /* $Id: mat.h,v 1.114 1996/09/12 16:28:47 bsmith Exp balay $ */
22eac72dbSBarry Smith /*
32eac72dbSBarry Smith      Include file for the matrix component of PETSc
42eac72dbSBarry Smith */
51eb62cbbSBarry Smith #ifndef __MAT_PACKAGE
61eb62cbbSBarry Smith #define __MAT_PACKAGE
78ed539a5SBarry Smith #include "vec.h"
82eac72dbSBarry Smith 
99cd28387SBarry Smith #define MAT_COOKIE         PETSC_COOKIE+5
10f0479e8cSBarry Smith 
112eac72dbSBarry Smith typedef struct _Mat*           Mat;
122eac72dbSBarry Smith 
134ac9ca07SLois Curfman McInnes typedef enum { MATSAME=-1, MATSEQDENSE, MATSEQAIJ, MATMPIAIJ, MATSHELL,
14c456f294SBarry Smith                MATMPIROWBS, MATSEQBDIAG, MATMPIBDIAG,
15a20e3d60SSatish Balay                MATMPIDENSE, MATSEQBAIJ, MATMPIBAIJ} MatType;
1628988994SBarry Smith 
170e998a85SBarry Smith extern int MatCreate(MPI_Comm,int,int,Mat*);
18df6e0191SLois Curfman McInnes extern int MatCreateSeqDense(MPI_Comm,int,int,Scalar*,Mat*);
19d5bc1036SLois Curfman McInnes extern int MatCreateMPIDense(MPI_Comm,int,int,int,int,Scalar*,Mat*);
20de7da479SBarry Smith extern int MatCreateSeqAIJ(MPI_Comm,int,int,int,int*,Mat*);
219717bf64SBarry Smith extern int MatCreateMPIAIJ(MPI_Comm,int,int,int,int,int,int*,int,int*,Mat*);
22cfe223acSLois Curfman McInnes extern int MatCreateMPIRowbs(MPI_Comm,int,int,int,int*,void*,Mat*);
23f26ada1bSBarry Smith extern int MatCreateSeqBDiag(MPI_Comm,int,int,int,int,int*,Scalar**,Mat*);
24f26ada1bSBarry Smith extern int MatCreateMPIBDiag(MPI_Comm,int,int,int,int,int,int*,Scalar**,Mat*);
25df8a92d1SBarry Smith extern int MatCreateSeqBAIJ(MPI_Comm,int,int,int,int,int*,Mat*);
26eba03b66SLois Curfman McInnes extern int MatCreateMPIBAIJ(MPI_Comm,int,int,int,int,int,int,int*,int,int*,Mat*);
279717bf64SBarry Smith 
287b80b807SBarry Smith extern int MatDestroy(Mat);
297b80b807SBarry Smith 
307ddc982cSLois Curfman McInnes extern int MatCreateShell(MPI_Comm,int,int,int,int,void *,Mat*);
3117116c71SBarry Smith extern int MatShellGetContext(Mat,void **);
3221c89e3eSBarry Smith 
332eac72dbSBarry Smith 
34ec0117caSBarry Smith extern int MatPrintHelp(Mat);
35ec0117caSBarry Smith 
368ed539a5SBarry Smith /* ------------------------------------------------------------*/
37ee50ffe9SBarry Smith extern int MatSetValues(Mat,int,int*,int,int*,Scalar*,InsertMode);
386d4a8577SBarry Smith typedef enum {MAT_FLUSH_ASSEMBLY=1,MAT_FINAL_ASSEMBLY=0} MatAssemblyType;
39ee50ffe9SBarry Smith extern int MatAssemblyBegin(Mat,MatAssemblyType);
40ee50ffe9SBarry Smith extern int MatAssemblyEnd(Mat,MatAssemblyType);
41ee50ffe9SBarry Smith 
426d4a8577SBarry Smith typedef enum {MAT_ROW_ORIENTED=1,MAT_COLUMN_ORIENTED=2,MAT_ROWS_SORTED=4,
436d4a8577SBarry Smith               MAT_COLUMNS_SORTED=8,MAT_NO_NEW_NONZERO_LOCATIONS=16,
446d4a8577SBarry Smith               MAT_YES_NEW_NONZERO_LOCATIONS=32,MAT_SYMMETRIC=64,
456d4a8577SBarry Smith               MAT_STRUCTURALLY_SYMMETRIC,MAT_NO_NEW_DIAGONALS,
466d4a8577SBarry Smith               MAT_YES_NEW_DIAGONALS,MAT_INODE_LIMIT_1,MAT_INODE_LIMIT_2,
476d4a8577SBarry Smith               MAT_INODE_LIMIT_3,MAT_INODE_LIMIT_4,MAT_INODE_LIMIT_5} MatOption;
48ee50ffe9SBarry Smith extern int MatSetOption(Mat,MatOption);
494b0e389bSBarry Smith extern int MatGetType(Mat,MatType*,char**);
5077c4ece6SBarry Smith extern int MatGetTypeFromOptions(MPI_Comm,char*,MatType*,int*);
51ee50ffe9SBarry Smith extern int MatGetValues(Mat,int,int*,int,int*,Scalar*);
528ed539a5SBarry Smith extern int MatGetRow(Mat,int,int *,int **,Scalar**);
538ed539a5SBarry Smith extern int MatRestoreRow(Mat,int,int *,int **,Scalar**);
5477c4ece6SBarry Smith extern int MatGetColumn(Mat,int,int *,int **,Scalar**);
5577c4ece6SBarry Smith extern int MatRestoreColumn(Mat,int,int *,int **,Scalar**);
5664e87e97SBarry Smith extern int MatGetArray(Mat,Scalar **);
5709883261SBarry Smith extern int MatRestoreArray(Mat,Scalar **);
58870582ebSSatish Balay extern int MatGetBlockSize(Mat,int *);
597b80b807SBarry Smith 
608ed539a5SBarry Smith extern int MatMult(Mat,Vec,Vec);
618ed539a5SBarry Smith extern int MatMultAdd(Mat,Vec,Vec,Vec);
628ed539a5SBarry Smith extern int MatMultTrans(Mat,Vec,Vec);
638ed539a5SBarry Smith extern int MatMultTransAdd(Mat,Vec,Vec,Vec);
642eac72dbSBarry Smith 
657b80b807SBarry Smith extern int MatConvert(Mat,MatType,Mat*);
667b80b807SBarry Smith extern int MatCopy(Mat,Mat);
677b80b807SBarry Smith extern int MatView(Mat,Viewer);
687b80b807SBarry Smith extern int MatLoad(Viewer,MatType,Mat*);
697b80b807SBarry Smith 
70d4fbbf0eSBarry Smith extern int MatGetRowIJ(Mat,int,PetscTruth,int*,int **,int **,PetscTruth *);
71d4fbbf0eSBarry Smith extern int MatRestoreRowIJ(Mat,int,PetscTruth,int *,int **,int **,PetscTruth *);
72d4fbbf0eSBarry Smith extern int MatGetColumnIJ(Mat,int,PetscTruth,int*,int **,int **,PetscTruth *);
73d4fbbf0eSBarry Smith extern int MatRestoreColumnIJ(Mat,int,PetscTruth,int *,int **,int **,PetscTruth *);
74d4fbbf0eSBarry Smith 
751d607229SLois Curfman McInnes /*
761d607229SLois Curfman McInnes    Context of matrix information, used with MatGetInfo()
771d607229SLois Curfman McInnes    Note: If any entries are added to this context, be sure
781d607229SLois Curfman McInnes          to adjust MAT_INFO_SIZE in FINCLUDE/mat.h
791d607229SLois Curfman McInnes  */
804e220ebcSLois Curfman McInnes typedef struct {
814e220ebcSLois Curfman McInnes   double rows_global, columns_global;         /* number of global rows and columns */
824e220ebcSLois Curfman McInnes   double rows_local, columns_local;           /* number of local rows and columns */
834e220ebcSLois Curfman McInnes   double block_size;                          /* block size */
844e220ebcSLois Curfman McInnes   double nz_allocated, nz_used, nz_unneeded;  /* number of nonzeros */
854e220ebcSLois Curfman McInnes   double memory;                              /* memory allocated */
864e220ebcSLois Curfman McInnes   double assemblies;                          /* number of matrix assemblies */
874e220ebcSLois Curfman McInnes   double mallocs;                             /* number of mallocs during MatSetValues() */
884e220ebcSLois Curfman McInnes   double fill_ratio_given, fill_ratio_needed; /* fill ration for LU/ILU */
894e220ebcSLois Curfman McInnes   double factor_mallocs;                      /* number of mallocs during factorization */
904e220ebcSLois Curfman McInnes } MatInfo;
914e220ebcSLois Curfman McInnes 
927b80b807SBarry Smith typedef enum {MAT_LOCAL=1,MAT_GLOBAL_MAX=2,MAT_GLOBAL_SUM=3} MatInfoType;
934e220ebcSLois Curfman McInnes extern int MatGetInfo(Mat,MatInfoType,MatInfo*);
9477c4ece6SBarry Smith extern int MatValid(Mat,PetscTruth*);
957b80b807SBarry Smith extern int MatGetDiagonal(Mat,Vec);
96cd8486b4SBarry Smith extern int MatTranspose(Mat,Mat*);
97f4c33d5aSBarry Smith extern int MatDiagonalScale(Mat,Vec,Vec);
988b3e568eSBarry Smith extern int MatDiagonalShift(Mat,Vec);
9977c4ece6SBarry Smith extern int MatEqual(Mat,Mat, PetscTruth*);
1007b80b807SBarry Smith 
1017b80b807SBarry Smith extern int MatNorm(Mat,NormType,double *);
1027b80b807SBarry Smith extern int MatZeroEntries(Mat);
1037b80b807SBarry Smith extern int MatZeroRows(Mat,IS,Scalar*);
1047b80b807SBarry Smith extern int MatZeroColumns(Mat,IS,Scalar*);
1057b80b807SBarry Smith 
1067b80b807SBarry Smith extern int MatGetSize(Mat,int*,int*);
1077b80b807SBarry Smith extern int MatGetLocalSize(Mat,int*,int*);
1087b80b807SBarry Smith extern int MatGetOwnershipRange(Mat,int*,int*);
1097b80b807SBarry Smith 
1107b80b807SBarry Smith typedef enum {MAT_INITIAL_MATRIX, MAT_REUSE_MATRIX} MatGetSubMatrixCall;
1117b80b807SBarry Smith extern int MatGetSubMatrices(Mat,int,IS *,IS *,MatGetSubMatrixCall,Mat **);
112905e6a2fSBarry Smith extern int MatDestroyMatrices(int, Mat **);
1137b80b807SBarry Smith extern int MatIncreaseOverlap(Mat,int,IS *,int);
1147b80b807SBarry Smith 
1157b80b807SBarry Smith extern int MatAXPY(Scalar *,Mat,Mat);
1167b80b807SBarry Smith extern int MatCompress(Mat);
1177b80b807SBarry Smith 
118052efed2SBarry Smith extern int MatScale(Scalar *,Mat);
119052efed2SBarry Smith extern int MatShift(Scalar *,Mat);
120052efed2SBarry Smith 
1217b80b807SBarry Smith /* Routines unique to particular data structures */
1227b80b807SBarry Smith extern int MatBDiagGetData(Mat,int*,int*,int**,int**,Scalar***);
1237b80b807SBarry Smith 
1247b80b807SBarry Smith /*
1257b80b807SBarry Smith   These routines are not usually accessed directly, rather solving is
1267b80b807SBarry Smith   done through the SLES, KSP and PC interfaces.
1277b80b807SBarry Smith */
1287b80b807SBarry Smith 
12983f0b094SBarry Smith typedef enum {ORDER_NATURAL=0,ORDER_ND=1,ORDER_1WD=2,
130a2ce50c7SBarry Smith               ORDER_RCM=3,ORDER_QMD=4,ORDER_ROWLENGTH=5,ORDER_FLOW,
131a2ce50c7SBarry Smith               ORDER_APPLICATION_1,ORDER_APPLICATION_2} MatReordering;
132a2ce50c7SBarry Smith extern int MatGetReordering(Mat,MatReordering,IS*,IS*);
133a2ce50c7SBarry Smith extern int MatGetReorderingTypeFromOptions(char *,MatReordering*);
134d4fbbf0eSBarry Smith extern int MatReorderingRegister(MatReordering *,char*,int (*)(Mat,MatReordering,IS*,IS*));
135464493b3SBarry Smith extern int MatReorderingRegisterAll();
136464493b3SBarry Smith extern int MatReorderingRegisterDestroy();
137a2ce50c7SBarry Smith extern int MatReorderingGetName(MatReordering,char **);
138d4fbbf0eSBarry Smith 
139d4fbbf0eSBarry Smith typedef enum {COLORING_NATURAL, COLORING_SL, COLORING_LD, COLORING_IF,
140d4fbbf0eSBarry Smith               COLORING_APPLICATION_1,COLORING_APPLICATION_2} MatColoring;
141d4fbbf0eSBarry Smith extern int MatGetColoring(Mat,MatColoring,int *,IS**);
142d4fbbf0eSBarry Smith extern int MatGetColoringTypeFromOptions(char *,MatColoring*);
143d4fbbf0eSBarry Smith extern int MatColoringRegister(MatColoring *,char*,int (*)(Mat,MatColoring,int*,IS**));
144d4fbbf0eSBarry Smith extern int MatColoringRegisterAll();
145d4fbbf0eSBarry Smith extern int MatColoringRegisterDestroy();
1462eac72dbSBarry Smith 
147a2ce50c7SBarry Smith extern int MatReorderForNonzeroDiagonal(Mat,double,IS,IS);
148a2ce50c7SBarry Smith 
149a2ce50c7SBarry Smith extern int MatCholeskyFactor(Mat,IS,double);
150a2ce50c7SBarry Smith extern int MatCholeskyFactorSymbolic(Mat,IS,double,Mat*);
151a2ce50c7SBarry Smith extern int MatCholeskyFactorNumeric(Mat,Mat*);
152a2ce50c7SBarry Smith 
15349d8b64dSBarry Smith extern int MatLUFactor(Mat,IS,IS,double);
154d7b056bfSBarry Smith extern int MatILUFactor(Mat,IS,IS,double,int);
15564051cb3SBarry Smith extern int MatLUFactorSymbolic(Mat,IS,IS,double,Mat*);
15664051cb3SBarry Smith extern int MatILUFactorSymbolic(Mat,IS,IS,double,int,Mat*);
15764051cb3SBarry Smith extern int MatIncompleteCholeskyFactorSymbolic(Mat,IS,double,int,Mat*);
15820563c6bSBarry Smith extern int MatLUFactorNumeric(Mat,Mat*);
159a2ce50c7SBarry Smith extern int MatILUDTFactor(Mat,double,int,IS,IS,Mat *);
160a2ce50c7SBarry Smith 
1618ed539a5SBarry Smith 
1628ed539a5SBarry Smith extern int MatSolve(Mat,Vec,Vec);
16322169318SLois Curfman McInnes extern int MatForwardSolve(Mat,Vec,Vec);
16422169318SLois Curfman McInnes extern int MatBackwardSolve(Mat,Vec,Vec);
1658ed539a5SBarry Smith extern int MatSolveAdd(Mat,Vec,Vec,Vec);
16628988994SBarry Smith extern int MatSolveTrans(Mat,Vec,Vec);
16728988994SBarry Smith extern int MatSolveTransAdd(Mat,Vec,Vec,Vec);
1688ed539a5SBarry Smith 
169ee50ffe9SBarry Smith typedef enum {SOR_FORWARD_SWEEP=1,SOR_BACKWARD_SWEEP=2,SOR_SYMMETRIC_SWEEP=3,
170ee50ffe9SBarry Smith               SOR_LOCAL_FORWARD_SWEEP=4,SOR_LOCAL_BACKWARD_SWEEP=8,
171ee50ffe9SBarry Smith               SOR_LOCAL_SYMMETRIC_SWEEP=12,SOR_ZERO_INITIAL_GUESS=16,
172ca9b4cbeSLois Curfman McInnes               SOR_EISENSTAT=32,SOR_APPLY_UPPER=64,SOR_APPLY_LOWER=128
173ca9b4cbeSLois Curfman McInnes               } MatSORType;
174ca9b4cbeSLois Curfman McInnes extern int MatRelax(Mat,Vec,double,MatSORType,double,int,Vec);
1758ed539a5SBarry Smith 
176d4fbbf0eSBarry Smith /*
177d4fbbf0eSBarry Smith     If you add entries here you must also add them to FINCLUDE/mat.h
178d4fbbf0eSBarry Smith */
179fae171e0SBarry Smith typedef enum { MAT_SET_VALUES=0,
180fae171e0SBarry Smith                MAT_GET_ROW=1,
181fae171e0SBarry Smith                MAT_RESTORE_ROW=2,
182fae171e0SBarry Smith                MAT_MULT=3,
183fae171e0SBarry Smith                MAT_MULT_ADD=4,
184fae171e0SBarry Smith                MAT_MULT_TRANS=5,
185fae171e0SBarry Smith                MAT_MULT_TRANS_ADD=6,
186fae171e0SBarry Smith                MAT_SOLVE=7,
187fae171e0SBarry Smith                MAT_SOLVE_ADD=8,
188fae171e0SBarry Smith                MAT_SOLVE_TRANS=9,
189fae171e0SBarry Smith                MAT_SOLVE_TRANS_ADD=10,
190fae171e0SBarry Smith                MAT_LUFACTOR=11,
191fae171e0SBarry Smith                MAT_CHOLESKYFACTOR=12,
192fae171e0SBarry Smith                MAT_RELAX=13,
193fae171e0SBarry Smith                MAT_TRANSPOSE=14,
194fae171e0SBarry Smith                MAT_GETINFO=15,
195fae171e0SBarry Smith                MAT_EQUAL=16,
196fae171e0SBarry Smith                MAT_GET_DIAGONAL=17,
197fae171e0SBarry Smith                MAT_DIAGONAL_SCALE=18,
198fae171e0SBarry Smith                MAT_NORM=19,
199fae171e0SBarry Smith                MAT_ASSEMBLY_BEGIN=20,
200fae171e0SBarry Smith                MAT_ASSEMBLY_END=21,
201fae171e0SBarry Smith                MAT_COMPRESS=22,
202fae171e0SBarry Smith                MAT_SET_OPTION=23,
203fae171e0SBarry Smith                MAT_ZERO_ENTRIES=24,
204fae171e0SBarry Smith                MAT_ZERO_ROWS=25,
205d4fbbf0eSBarry Smith                MAT_LUFACTOR_SYMBOLIC=26,
206d4fbbf0eSBarry Smith                MAT_LUFACTOR_NUMERIC=27,
207d4fbbf0eSBarry Smith                MAT_CHOLESKY_FACTOR_SYMBOLIC=28,
208d4fbbf0eSBarry Smith                MAT_CHOLESKY_FACTOR_NUMERIC=29,
209d4fbbf0eSBarry Smith                MAT_GET_SIZE=30,
210d4fbbf0eSBarry Smith                MAT_GET_LOCAL_SIZE=31,
211d4fbbf0eSBarry Smith                MAT_GET_OWNERSHIP_RANGE=32,
212d4fbbf0eSBarry Smith                MAT_ILUFACTOR_SYMBOLIC=33,
213d4fbbf0eSBarry Smith                MAT_INCOMPLETECHOLESKYFACTOR_SYMBOLIC=34,
214d4fbbf0eSBarry Smith                MAT_GET_ARRAY=35,
215d4fbbf0eSBarry Smith                MAT_RESTORE_ARRAY=36,
216d4fbbf0eSBarry Smith                MAT_CONVERT=37,
217*7bf97ca4SSatish Balay 
218d4fbbf0eSBarry Smith                MAT_CONVERT_SAME_TYPE=40,
219d4fbbf0eSBarry Smith                MAT_FORWARD_SOLVE=41,
220d4fbbf0eSBarry Smith                MAT_BACKWARD_SOLVE=42,
221d4fbbf0eSBarry Smith                MAT_ILUFACTOR=43,
222d4fbbf0eSBarry Smith                MAT_INCOMPLETECHOLESKYFACTOR=44,
223d4fbbf0eSBarry Smith                MAT_AXPY=45,
224d4fbbf0eSBarry Smith                MAT_GET_SUBMATRICES=46,
225d4fbbf0eSBarry Smith                MAT_INCREASE_OVERLAP=47,
226d4fbbf0eSBarry Smith                MAT_GET_VALUES=48,
227d4fbbf0eSBarry Smith                MAT_COPY=49,
228d4fbbf0eSBarry Smith                MAT_PRINT_HELP=50,
229d4fbbf0eSBarry Smith                MAT_SCALE=51,
230d4fbbf0eSBarry Smith                MAT_SHIFT=52,
231d4fbbf0eSBarry Smith                MAT_DIAGONAL_SHIFT=53,
232d4fbbf0eSBarry Smith                MAT_ILUDT_FACTOR=54,
233d4fbbf0eSBarry Smith                MAT_GET_BLOCK_SIZE=55,
234fae171e0SBarry Smith                MAT_DESTROY=250,
235fae171e0SBarry Smith                MAT_VIEW=251
236fae171e0SBarry Smith              } MatOperation;
237112a2221SBarry Smith extern int MatHasOperation(Mat,MatOperation,PetscTruth*);
238fae171e0SBarry Smith extern int MatShellSetOperation(Mat,MatOperation,void *);
239112a2221SBarry Smith 
24090ace30eSBarry Smith /*
24190ace30eSBarry Smith    Codes for matrices stored on disk. By default they are
24290ace30eSBarry Smith  stored in a universal format. By changing the format with
24390ace30eSBarry Smith  ViewerSetFormat(viewer,BINARY_FORMAT_NATIVE); the matrices will
24490ace30eSBarry Smith  be stored in a way natural for the matrix, for example dense matrices
24590ace30eSBarry Smith  would be stored as dense. Matrices stored this way may only be
24690ace30eSBarry Smith  read into matrices of the same time.
24790ace30eSBarry Smith */
24890ace30eSBarry Smith #define MATRIX_BINARY_FORMAT_DENSE -1
24990ace30eSBarry Smith 
2502eac72dbSBarry Smith #endif
2512eac72dbSBarry Smith 
2522eac72dbSBarry Smith 
2539d00d63dSBarry Smith 
254