xref: /petsc/include/petscmat.h (revision fae171e0928a68051052473fbd80ecaec6ec1e7e)
1*fae171e0SBarry Smith /* $Id: mat.h,v 1.100 1996/03/19 21:30:28 bsmith Exp bsmith $ */
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,
151f3bdca4SBarry Smith                MATMPIDENSE, MATSEQBAIJ } 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*);
269717bf64SBarry Smith 
277b80b807SBarry Smith extern int MatDestroy(Mat);
287b80b807SBarry Smith 
29052efed2SBarry Smith extern int MatCreateShell(MPI_Comm,int,int,void *,Mat*);
3017116c71SBarry Smith extern int MatShellGetContext(Mat,void **);
31aabeff55SBarry Smith extern int MatShellSetMult(Mat,int (*)(void*,Vec,Vec));
32b9fa9cd0SBarry Smith extern int MatShellSetDestroy(Mat,int (*)(void*));
33aabeff55SBarry Smith extern int MatShellSetMultTrans(Mat,int (*)(void*,Vec,Vec));
34f0479e8cSBarry Smith extern int MatShellSetMultTransAdd(Mat,int (*)(void*,Vec,Vec,Vec));
352eac72dbSBarry Smith 
36ec0117caSBarry Smith extern int MatPrintHelp(Mat);
37ec0117caSBarry Smith 
388ed539a5SBarry Smith /* ------------------------------------------------------------*/
39ee50ffe9SBarry Smith extern int MatSetValues(Mat,int,int*,int,int*,Scalar*,InsertMode);
407b80b807SBarry Smith typedef enum {FLUSH_ASSEMBLY=1,FINAL_ASSEMBLY=0} MatAssemblyType;
41ee50ffe9SBarry Smith extern int MatAssemblyBegin(Mat,MatAssemblyType);
42ee50ffe9SBarry Smith extern int MatAssemblyEnd(Mat,MatAssemblyType);
43ee50ffe9SBarry Smith 
44ee50ffe9SBarry Smith typedef enum {ROW_ORIENTED=1,COLUMN_ORIENTED=2,ROWS_SORTED=4,
45ee50ffe9SBarry Smith               COLUMNS_SORTED=8,NO_NEW_NONZERO_LOCATIONS=16,
4602834360SBarry Smith               YES_NEW_NONZERO_LOCATIONS=32,SYMMETRIC_MATRIX=64,
47c0bbcb79SLois Curfman McInnes               STRUCTURALLY_SYMMETRIC_MATRIX,NO_NEW_DIAGONALS,
48429c0c78SLois Curfman McInnes               YES_NEW_DIAGONALS,INODE_LIMIT_1,INODE_LIMIT_2,
49429c0c78SLois Curfman McInnes               INODE_LIMIT_3,INODE_LIMIT_4,INODE_LIMIT_5} MatOption;
50ee50ffe9SBarry Smith extern int MatSetOption(Mat,MatOption);
514b0e389bSBarry Smith extern int MatGetType(Mat,MatType*,char**);
5277c4ece6SBarry Smith extern int MatGetTypeFromOptions(MPI_Comm,char*,MatType*,int*);
53ee50ffe9SBarry Smith extern int MatGetValues(Mat,int,int*,int,int*,Scalar*);
548ed539a5SBarry Smith extern int MatGetRow(Mat,int,int *,int **,Scalar**);
558ed539a5SBarry Smith extern int MatRestoreRow(Mat,int,int *,int **,Scalar**);
5677c4ece6SBarry Smith extern int MatGetColumn(Mat,int,int *,int **,Scalar**);
5777c4ece6SBarry Smith extern int MatRestoreColumn(Mat,int,int *,int **,Scalar**);
5864e87e97SBarry Smith extern int MatGetArray(Mat,Scalar **);
5909883261SBarry Smith extern int MatRestoreArray(Mat,Scalar **);
607b80b807SBarry Smith 
618ed539a5SBarry Smith extern int MatMult(Mat,Vec,Vec);
628ed539a5SBarry Smith extern int MatMultAdd(Mat,Vec,Vec,Vec);
638ed539a5SBarry Smith extern int MatMultTrans(Mat,Vec,Vec);
648ed539a5SBarry Smith extern int MatMultTransAdd(Mat,Vec,Vec,Vec);
652eac72dbSBarry Smith 
667b80b807SBarry Smith extern int MatConvert(Mat,MatType,Mat*);
677b80b807SBarry Smith extern int MatCopy(Mat,Mat);
687b80b807SBarry Smith extern int MatView(Mat,Viewer);
697b80b807SBarry Smith extern int MatLoad(Viewer,MatType,Mat*);
707b80b807SBarry Smith 
717b80b807SBarry Smith typedef enum {MAT_LOCAL=1,MAT_GLOBAL_MAX=2,MAT_GLOBAL_SUM=3} MatInfoType;
727b80b807SBarry Smith extern int MatGetInfo(Mat,MatInfoType,int*,int*,int*);
7377c4ece6SBarry Smith extern int MatValid(Mat,PetscTruth*);
747b80b807SBarry Smith extern int MatGetDiagonal(Mat,Vec);
75cd8486b4SBarry Smith extern int MatTranspose(Mat,Mat*);
76f4c33d5aSBarry Smith extern int MatDiagonalScale(Mat,Vec,Vec);
778b3e568eSBarry Smith extern int MatDiagonalShift(Mat,Vec);
7877c4ece6SBarry Smith extern int MatEqual(Mat,Mat, PetscTruth*);
797b80b807SBarry Smith 
807b80b807SBarry Smith extern int MatNorm(Mat,NormType,double *);
817b80b807SBarry Smith extern int MatZeroEntries(Mat);
827b80b807SBarry Smith extern int MatZeroRows(Mat,IS,Scalar*);
837b80b807SBarry Smith extern int MatZeroColumns(Mat,IS,Scalar*);
847b80b807SBarry Smith 
857b80b807SBarry Smith extern int MatGetSize(Mat,int*,int*);
867b80b807SBarry Smith extern int MatGetLocalSize(Mat,int*,int*);
877b80b807SBarry Smith extern int MatGetOwnershipRange(Mat,int*,int*);
887b80b807SBarry Smith 
897b80b807SBarry Smith typedef enum {MAT_INITIAL_MATRIX, MAT_REUSE_MATRIX} MatGetSubMatrixCall;
907b80b807SBarry Smith extern int MatGetSubMatrix(Mat,IS,IS,MatGetSubMatrixCall,Mat*);
917b80b807SBarry Smith extern int MatGetSubMatrixInPlace(Mat,IS,IS);
927b80b807SBarry Smith extern int MatGetSubMatrices(Mat,int,IS *,IS *,MatGetSubMatrixCall,Mat **);
937b80b807SBarry Smith extern int MatIncreaseOverlap(Mat,int,IS *,int);
947b80b807SBarry Smith 
957b80b807SBarry Smith extern int MatAXPY(Scalar *,Mat,Mat);
967b80b807SBarry Smith extern int MatCompress(Mat);
977b80b807SBarry Smith 
98052efed2SBarry Smith extern int MatScale(Scalar *,Mat);
99052efed2SBarry Smith extern int MatShift(Scalar *,Mat);
100052efed2SBarry Smith 
1017b80b807SBarry Smith /* Routines unique to particular data structures */
1027b80b807SBarry Smith extern int MatBDiagGetData(Mat,int*,int*,int**,int**,Scalar***);
1037b80b807SBarry Smith 
1047b80b807SBarry Smith /*
1057b80b807SBarry Smith   These routines are not usually accessed directly, rather solving is
1067b80b807SBarry Smith   done through the SLES, KSP and PC interfaces.
1077b80b807SBarry Smith */
1087b80b807SBarry Smith 
10983f0b094SBarry Smith typedef enum {ORDER_NATURAL=0,ORDER_ND=1,ORDER_1WD=2,
11009883261SBarry Smith               ORDER_RCM=3,ORDER_QMD=4,ORDER_ROWLENGTH=5,ORDER_APPLICATION_1,
111464493b3SBarry Smith               ORDER_APPLICATION_2} MatOrdering;
112ee50ffe9SBarry Smith extern int MatGetReordering(Mat,MatOrdering,IS*,IS*);
113d7b056bfSBarry Smith extern int MatGetReorderingTypeFromOptions(char *,MatOrdering*);
114832a8ecbSBarry Smith extern int MatReorderForNonzeroDiagonal(Mat,double,IS,IS);
11571aaadd7SBarry Smith extern int MatReorderingRegister(MatOrdering *,char*,PetscTruth,int,
11609883261SBarry Smith                                  int (*)(int*,int*,int*,int*,int*));
117464493b3SBarry Smith extern int MatReorderingRegisterAll();
118464493b3SBarry Smith extern int MatReorderingRegisterDestroy();
11909883261SBarry Smith extern int MatReorderingGetName(MatOrdering,char **);
12009883261SBarry Smith extern PetscTruth MatReorderingRequiresSymmetric[];
12109883261SBarry Smith extern int MatReorderingIndexShift[];
1222eac72dbSBarry Smith 
12349d8b64dSBarry Smith extern int MatLUFactor(Mat,IS,IS,double);
124d7b056bfSBarry Smith extern int MatILUFactor(Mat,IS,IS,double,int);
12549d8b64dSBarry Smith extern int MatCholeskyFactor(Mat,IS,double);
12664051cb3SBarry Smith extern int MatLUFactorSymbolic(Mat,IS,IS,double,Mat*);
12764051cb3SBarry Smith extern int MatILUFactorSymbolic(Mat,IS,IS,double,int,Mat*);
12864051cb3SBarry Smith extern int MatCholeskyFactorSymbolic(Mat,IS,double,Mat*);
12964051cb3SBarry Smith extern int MatIncompleteCholeskyFactorSymbolic(Mat,IS,double,int,Mat*);
13020563c6bSBarry Smith extern int MatLUFactorNumeric(Mat,Mat*);
13120563c6bSBarry Smith extern int MatCholeskyFactorNumeric(Mat,Mat*);
1328ed539a5SBarry Smith 
1338ed539a5SBarry Smith extern int MatSolve(Mat,Vec,Vec);
13422169318SLois Curfman McInnes extern int MatForwardSolve(Mat,Vec,Vec);
13522169318SLois Curfman McInnes extern int MatBackwardSolve(Mat,Vec,Vec);
1368ed539a5SBarry Smith extern int MatSolveAdd(Mat,Vec,Vec,Vec);
13728988994SBarry Smith extern int MatSolveTrans(Mat,Vec,Vec);
13828988994SBarry Smith extern int MatSolveTransAdd(Mat,Vec,Vec,Vec);
1398ed539a5SBarry Smith 
140ee50ffe9SBarry Smith typedef enum {SOR_FORWARD_SWEEP=1,SOR_BACKWARD_SWEEP=2,SOR_SYMMETRIC_SWEEP=3,
141ee50ffe9SBarry Smith               SOR_LOCAL_FORWARD_SWEEP=4,SOR_LOCAL_BACKWARD_SWEEP=8,
142ee50ffe9SBarry Smith               SOR_LOCAL_SYMMETRIC_SWEEP=12,SOR_ZERO_INITIAL_GUESS=16,
143ca9b4cbeSLois Curfman McInnes               SOR_EISENSTAT=32,SOR_APPLY_UPPER=64,SOR_APPLY_LOWER=128
144ca9b4cbeSLois Curfman McInnes               } MatSORType;
145ca9b4cbeSLois Curfman McInnes extern int MatRelax(Mat,Vec,double,MatSORType,double,int,Vec);
1468ed539a5SBarry Smith 
147*fae171e0SBarry Smith typedef enum { MAT_SET_VALUES=0,
148*fae171e0SBarry Smith                MAT_GET_ROW=1,
149*fae171e0SBarry Smith                MAT_RESTORE_ROW=2,
150*fae171e0SBarry Smith                MAT_MULT=3,
151*fae171e0SBarry Smith                MAT_MULT_ADD=4,
152*fae171e0SBarry Smith                MAT_MULT_TRANS=5,
153*fae171e0SBarry Smith                MAT_MULT_TRANS_ADD=6,
154*fae171e0SBarry Smith                MAT_SOLVE=7,
155*fae171e0SBarry Smith                MAT_SOLVE_ADD=8,
156*fae171e0SBarry Smith                MAT_SOLVE_TRANS=9,
157*fae171e0SBarry Smith                MAT_SOLVE_TRANS_ADD=10,
158*fae171e0SBarry Smith                MAT_LUFACTOR=11,
159*fae171e0SBarry Smith                MAT_CHOLESKYFACTOR=12,
160*fae171e0SBarry Smith                MAT_RELAX=13,
161*fae171e0SBarry Smith                MAT_TRANSPOSE=14,
162*fae171e0SBarry Smith                MAT_GETINFO=15,
163*fae171e0SBarry Smith                MAT_EQUAL=16,
164*fae171e0SBarry Smith                MAT_GET_DIAGONAL=17,
165*fae171e0SBarry Smith                MAT_DIAGONAL_SCALE=18,
166*fae171e0SBarry Smith                MAT_NORM=19,
167*fae171e0SBarry Smith                MAT_ASSEMBLY_BEGIN=20,
168*fae171e0SBarry Smith                MAT_ASSEMBLY_END=21,
169*fae171e0SBarry Smith                MAT_COMPRESS=22,
170*fae171e0SBarry Smith                MAT_SET_OPTION=23,
171*fae171e0SBarry Smith                MAT_ZERO_ENTRIES=24,
172*fae171e0SBarry Smith                MAT_ZERO_ROWS=25,
173*fae171e0SBarry Smith                MAT_GET_REORDERING=26,
174*fae171e0SBarry Smith                MAT_LUFACTOR_SYMBOLIC=27,
175*fae171e0SBarry Smith                MAT_LUFACTOR_NUMERIC=28,
176*fae171e0SBarry Smith                MAT_CHOLESKY_FACTOR_SYMBOLIC=29,
177*fae171e0SBarry Smith                MAT_CHOLESKY_FACTOR_NUMERIC=30,
178*fae171e0SBarry Smith                MAT_GET_SIZE=31,
179*fae171e0SBarry Smith                MAT_GET_LOCAL_SIZE=32,
180*fae171e0SBarry Smith                MAT_GET_OWNERSHIP_RANGE=33,
181*fae171e0SBarry Smith                MAT_ILUFACTOR_SYMBOLIC=34,
182*fae171e0SBarry Smith                MAT_INCOMPLETECHOLESKYFACTOR_SYMBOLIC=35,
183*fae171e0SBarry Smith                MAT_GET_ARRAY=36,
184*fae171e0SBarry Smith                MAT_RESTORE_ARRAY=37,
185*fae171e0SBarry Smith                MAT_CONVERT=38,
186*fae171e0SBarry Smith                MAT_GET_SUBMATRIX=39,
187*fae171e0SBarry Smith                MAT_GET_SUBMATRIX_INPLACE=40,
188*fae171e0SBarry Smith                MAT_CONVERT_SAME_TYPE=41,
189*fae171e0SBarry Smith                MAT_FORWARD_SOLVE=42,
190*fae171e0SBarry Smith                MAT_BACKWARD_SOLVE=43,
191*fae171e0SBarry Smith                MAT_ILUFACTOR=44,
192*fae171e0SBarry Smith                MAT_INCOMPLETECHOLEKSYFACTOR=45,
193*fae171e0SBarry Smith                MAT_AXPY=46,
194*fae171e0SBarry Smith                MAT_GET_SUBMATRICES=47,
195*fae171e0SBarry Smith                MAT_INCREASE_OVERLAP=48,
196*fae171e0SBarry Smith                MAT_GET_VALUES=49,
197*fae171e0SBarry Smith                MAT_COPY=50,
198*fae171e0SBarry Smith                MAT_PRINT_HELP=51,
199*fae171e0SBarry Smith                MAT_SCALE=52,
200*fae171e0SBarry Smith                MAT_SHIFT=53,
201*fae171e0SBarry Smith                MAT_DIAGONAL_SHIFT=54,
202*fae171e0SBarry Smith                MAT_DESTROY=250,
203*fae171e0SBarry Smith                MAT_VIEW=251
204*fae171e0SBarry Smith              } MatOperation;
205112a2221SBarry Smith extern int MatHasOperation(Mat,MatOperation,PetscTruth*);
206*fae171e0SBarry Smith extern int MatShellSetOperation(Mat,MatOperation,void *);
207112a2221SBarry Smith 
208037ecd73SBarry Smith /*  Not currently supported!
209037ecd73SBarry Smith #define MAT_SCATTER_COOKIE PETSC_COOKIE+15
210037ecd73SBarry Smith typedef struct _MatScatter* MatScatter;
211037ecd73SBarry Smith 
212037ecd73SBarry Smith extern int MatScatterBegin(Mat,Mat,InsertMode,MatScatter);
213037ecd73SBarry Smith extern int MatScatterEnd(Mat,Mat,InsertMode,MatScatter);
214037ecd73SBarry Smith extern int MatScatterCreate(Mat,IS,IS,Mat,IS,IS,MatScatter*);
215037ecd73SBarry Smith extern int MatScatterDestroy(MatScatter);
216037ecd73SBarry Smith */
2172eac72dbSBarry Smith 
21890ace30eSBarry Smith /*
21990ace30eSBarry Smith    Codes for matrices stored on disk. By default they are
22090ace30eSBarry Smith  stored in a universal format. By changing the format with
22190ace30eSBarry Smith  ViewerSetFormat(viewer,BINARY_FORMAT_NATIVE); the matrices will
22290ace30eSBarry Smith  be stored in a way natural for the matrix, for example dense matrices
22390ace30eSBarry Smith  would be stored as dense. Matrices stored this way may only be
22490ace30eSBarry Smith  read into matrices of the same time.
22590ace30eSBarry Smith */
22690ace30eSBarry Smith #define MATRIX_BINARY_FORMAT_DENSE -1
22790ace30eSBarry Smith 
2282eac72dbSBarry Smith #endif
2292eac72dbSBarry Smith 
2302eac72dbSBarry Smith 
2319d00d63dSBarry Smith 
232