xref: /petsc/include/petscmat.h (revision e78daa7df64465c5433a8e915d2a72f3bcad4f37)
1 /* $Id: mat.h,v 1.115 1996/09/27 21:55:04 balay Exp curfman $ */
2 /*
3      Include file for the matrix component of PETSc
4 */
5 #ifndef __MAT_PACKAGE
6 #define __MAT_PACKAGE
7 #include "vec.h"
8 
9 #define MAT_COOKIE         PETSC_COOKIE+5
10 
11 typedef struct _Mat*           Mat;
12 
13 typedef enum { MATSAME=-1, MATSEQDENSE, MATSEQAIJ, MATMPIAIJ, MATSHELL,
14                MATMPIROWBS, MATSEQBDIAG, MATMPIBDIAG,
15                MATMPIDENSE, MATSEQBAIJ, MATMPIBAIJ} MatType;
16 
17 extern int MatCreate(MPI_Comm,int,int,Mat*);
18 extern int MatCreateSeqDense(MPI_Comm,int,int,Scalar*,Mat*);
19 extern int MatCreateMPIDense(MPI_Comm,int,int,int,int,Scalar*,Mat*);
20 extern int MatCreateSeqAIJ(MPI_Comm,int,int,int,int*,Mat*);
21 extern int MatCreateMPIAIJ(MPI_Comm,int,int,int,int,int,int*,int,int*,Mat*);
22 extern int MatCreateMPIRowbs(MPI_Comm,int,int,int,int*,void*,Mat*);
23 extern int MatCreateSeqBDiag(MPI_Comm,int,int,int,int,int*,Scalar**,Mat*);
24 extern int MatCreateMPIBDiag(MPI_Comm,int,int,int,int,int,int*,Scalar**,Mat*);
25 extern int MatCreateSeqBAIJ(MPI_Comm,int,int,int,int,int*,Mat*);
26 extern int MatCreateMPIBAIJ(MPI_Comm,int,int,int,int,int,int,int*,int,int*,Mat*);
27 
28 extern int MatDestroy(Mat);
29 
30 extern int MatCreateShell(MPI_Comm,int,int,int,int,void *,Mat*);
31 extern int MatShellGetContext(Mat,void **);
32 
33 
34 extern int MatPrintHelp(Mat);
35 
36 /* ------------------------------------------------------------*/
37 extern int MatSetValues(Mat,int,int*,int,int*,Scalar*,InsertMode);
38 typedef enum {MAT_FLUSH_ASSEMBLY=1,MAT_FINAL_ASSEMBLY=0} MatAssemblyType;
39 extern int MatAssemblyBegin(Mat,MatAssemblyType);
40 extern int MatAssemblyEnd(Mat,MatAssemblyType);
41 
42 typedef enum {MAT_ROW_ORIENTED=1,MAT_COLUMN_ORIENTED=2,MAT_ROWS_SORTED=4,
43               MAT_COLUMNS_SORTED=8,MAT_NO_NEW_NONZERO_LOCATIONS=16,
44               MAT_YES_NEW_NONZERO_LOCATIONS=32,MAT_SYMMETRIC=64,
45               MAT_STRUCTURALLY_SYMMETRIC,MAT_NO_NEW_DIAGONALS,
46               MAT_YES_NEW_DIAGONALS,MAT_INODE_LIMIT_1,MAT_INODE_LIMIT_2,
47               MAT_INODE_LIMIT_3,MAT_INODE_LIMIT_4,MAT_INODE_LIMIT_5} MatOption;
48 extern int MatSetOption(Mat,MatOption);
49 extern int MatGetType(Mat,MatType*,char**);
50 extern int MatGetTypeFromOptions(MPI_Comm,char*,MatType*,int*);
51 extern int MatGetValues(Mat,int,int*,int,int*,Scalar*);
52 extern int MatGetRow(Mat,int,int *,int **,Scalar**);
53 extern int MatRestoreRow(Mat,int,int *,int **,Scalar**);
54 extern int MatGetColumn(Mat,int,int *,int **,Scalar**);
55 extern int MatRestoreColumn(Mat,int,int *,int **,Scalar**);
56 extern int MatGetArray(Mat,Scalar **);
57 extern int MatRestoreArray(Mat,Scalar **);
58 extern int MatGetBlockSize(Mat,int *);
59 
60 extern int MatMult(Mat,Vec,Vec);
61 extern int MatMultAdd(Mat,Vec,Vec,Vec);
62 extern int MatMultTrans(Mat,Vec,Vec);
63 extern int MatMultTransAdd(Mat,Vec,Vec,Vec);
64 
65 extern int MatConvert(Mat,MatType,Mat*);
66 extern int MatCopy(Mat,Mat);
67 extern int MatView(Mat,Viewer);
68 extern int MatLoad(Viewer,MatType,Mat*);
69 
70 extern int MatGetRowIJ(Mat,int,PetscTruth,int*,int **,int **,PetscTruth *);
71 extern int MatRestoreRowIJ(Mat,int,PetscTruth,int *,int **,int **,PetscTruth *);
72 extern int MatGetColumnIJ(Mat,int,PetscTruth,int*,int **,int **,PetscTruth *);
73 extern int MatRestoreColumnIJ(Mat,int,PetscTruth,int *,int **,int **,PetscTruth *);
74 
75 /*
76    Context of matrix information, used with MatGetInfo()
77    Note: If any entries are added to this context, be sure
78          to adjust MAT_INFO_SIZE in FINCLUDE/mat.h
79  */
80 typedef struct {
81   double rows_global, columns_global;         /* number of global rows and columns */
82   double rows_local, columns_local;           /* number of local rows and columns */
83   double block_size;                          /* block size */
84   double nz_allocated, nz_used, nz_unneeded;  /* number of nonzeros */
85   double memory;                              /* memory allocated */
86   double assemblies;                          /* number of matrix assemblies */
87   double mallocs;                             /* number of mallocs during MatSetValues() */
88   double fill_ratio_given, fill_ratio_needed; /* fill ration for LU/ILU */
89   double factor_mallocs;                      /* number of mallocs during factorization */
90 } MatInfo;
91 
92 typedef enum {MAT_LOCAL=1,MAT_GLOBAL_MAX=2,MAT_GLOBAL_SUM=3} MatInfoType;
93 extern int MatGetInfo(Mat,MatInfoType,MatInfo*);
94 extern int MatValid(Mat,PetscTruth*);
95 extern int MatGetDiagonal(Mat,Vec);
96 extern int MatTranspose(Mat,Mat*);
97 extern int MatDiagonalScale(Mat,Vec,Vec);
98 extern int MatDiagonalShift(Mat,Vec);
99 extern int MatEqual(Mat,Mat, PetscTruth*);
100 
101 extern int MatNorm(Mat,NormType,double *);
102 extern int MatZeroEntries(Mat);
103 extern int MatZeroRows(Mat,IS,Scalar*);
104 extern int MatZeroColumns(Mat,IS,Scalar*);
105 
106 extern int MatGetSize(Mat,int*,int*);
107 extern int MatGetLocalSize(Mat,int*,int*);
108 extern int MatGetOwnershipRange(Mat,int*,int*);
109 
110 typedef enum {MAT_INITIAL_MATRIX, MAT_REUSE_MATRIX} MatGetSubMatrixCall;
111 extern int MatGetSubMatrices(Mat,int,IS *,IS *,MatGetSubMatrixCall,Mat **);
112 extern int MatDestroyMatrices(int, Mat **);
113 extern int MatIncreaseOverlap(Mat,int,IS *,int);
114 
115 extern int MatAXPY(Scalar *,Mat,Mat);
116 extern int MatCompress(Mat);
117 
118 extern int MatScale(Scalar *,Mat);
119 extern int MatShift(Scalar *,Mat);
120 
121 /* Routines unique to particular data structures */
122 extern int MatBDiagGetData(Mat,int*,int*,int**,int**,Scalar***);
123 
124 /*
125   These routines are not usually accessed directly, rather solving is
126   done through the SLES, KSP and PC interfaces.
127 */
128 
129 typedef enum {ORDER_NATURAL=0,ORDER_ND=1,ORDER_1WD=2,
130               ORDER_RCM=3,ORDER_QMD=4,ORDER_ROWLENGTH=5,ORDER_FLOW,
131               ORDER_APPLICATION_1,ORDER_APPLICATION_2} MatReordering;
132 extern int MatGetReordering(Mat,MatReordering,IS*,IS*);
133 extern int MatGetReorderingTypeFromOptions(char *,MatReordering*);
134 extern int MatReorderingRegister(MatReordering *,char*,int (*)(Mat,MatReordering,IS*,IS*));
135 extern int MatReorderingRegisterAll();
136 extern int MatReorderingRegisterDestroy();
137 extern int MatReorderingGetName(MatReordering,char **);
138 
139 typedef enum {COLORING_NATURAL, COLORING_SL, COLORING_LD, COLORING_IF,
140               COLORING_APPLICATION_1,COLORING_APPLICATION_2} MatColoring;
141 extern int MatGetColoring(Mat,MatColoring,int *,IS**);
142 extern int MatGetColoringTypeFromOptions(char *,MatColoring*);
143 extern int MatColoringRegister(MatColoring *,char*,int (*)(Mat,MatColoring,int*,IS**));
144 extern int MatColoringRegisterAll();
145 extern int MatColoringRegisterDestroy();
146 
147 extern int MatReorderForNonzeroDiagonal(Mat,double,IS,IS);
148 
149 extern int MatCholeskyFactor(Mat,IS,double);
150 extern int MatCholeskyFactorSymbolic(Mat,IS,double,Mat*);
151 extern int MatCholeskyFactorNumeric(Mat,Mat*);
152 
153 extern int MatLUFactor(Mat,IS,IS,double);
154 extern int MatILUFactor(Mat,IS,IS,double,int);
155 extern int MatLUFactorSymbolic(Mat,IS,IS,double,Mat*);
156 extern int MatILUFactorSymbolic(Mat,IS,IS,double,int,Mat*);
157 extern int MatIncompleteCholeskyFactorSymbolic(Mat,IS,double,int,Mat*);
158 extern int MatLUFactorNumeric(Mat,Mat*);
159 extern int MatILUDTFactor(Mat,double,int,IS,IS,Mat *);
160 
161 
162 extern int MatSolve(Mat,Vec,Vec);
163 extern int MatForwardSolve(Mat,Vec,Vec);
164 extern int MatBackwardSolve(Mat,Vec,Vec);
165 extern int MatSolveAdd(Mat,Vec,Vec,Vec);
166 extern int MatSolveTrans(Mat,Vec,Vec);
167 extern int MatSolveTransAdd(Mat,Vec,Vec,Vec);
168 
169 typedef enum {SOR_FORWARD_SWEEP=1,SOR_BACKWARD_SWEEP=2,SOR_SYMMETRIC_SWEEP=3,
170               SOR_LOCAL_FORWARD_SWEEP=4,SOR_LOCAL_BACKWARD_SWEEP=8,
171               SOR_LOCAL_SYMMETRIC_SWEEP=12,SOR_ZERO_INITIAL_GUESS=16,
172               SOR_EISENSTAT=32,SOR_APPLY_UPPER=64,SOR_APPLY_LOWER=128
173               } MatSORType;
174 extern int MatRelax(Mat,Vec,double,MatSORType,double,int,Vec);
175 
176 /*
177     If you add entries here you must also add them to FINCLUDE/mat.h
178 */
179 typedef enum { MATOP_SET_VALUES=0,
180                MATOP_GET_ROW=1,
181                MATOP_RESTORE_ROW=2,
182                MATOP_MULT=3,
183                MATOP_MULT_ADD=4,
184                MATOP_MULT_TRANS=5,
185                MATOP_MULT_TRANS_ADD=6,
186                MATOP_SOLVE=7,
187                MATOP_SOLVE_ADD=8,
188                MATOP_SOLVE_TRANS=9,
189                MATOP_SOLVE_TRANS_ADD=10,
190                MATOP_LUFACTOR=11,
191                MATOP_CHOLESKYFACTOR=12,
192                MATOP_RELAX=13,
193                MATOP_TRANSPOSE=14,
194                MATOP_GETINFO=15,
195                MATOP_EQUAL=16,
196                MATOP_GET_DIAGONAL=17,
197                MATOP_DIAGONAL_SCALE=18,
198                MATOP_NORM=19,
199                MATOP_ASSEMBLY_BEGIN=20,
200                MATOP_ASSEMBLY_END=21,
201                MATOP_COMPRESS=22,
202                MATOP_SET_OPTION=23,
203                MATOP_ZERO_ENTRIES=24,
204                MATOP_ZERO_ROWS=25,
205                MATOP_LUFACTOR_SYMBOLIC=26,
206                MATOP_LUFACTOR_NUMERIC=27,
207                MATOP_CHOLESKY_FACTOR_SYMBOLIC=28,
208                MATOP_CHOLESKY_FACTOR_NUMERIC=29,
209                MATOP_GET_SIZE=30,
210                MATOP_GET_LOCAL_SIZE=31,
211                MATOP_GET_OWNERSHIP_RANGE=32,
212                MATOP_ILUFACTOR_SYMBOLIC=33,
213                MATOP_INCOMPLETECHOLESKYFACTOR_SYMBOLIC=34,
214                MATOP_GET_ARRAY=35,
215                MATOP_RESTORE_ARRAY=36,
216                MATOP_CONVERT=37,
217 
218                MATOP_CONVERT_SAME_TYPE=40,
219                MATOP_FORWARD_SOLVE=41,
220                MATOP_BACKWARD_SOLVE=42,
221                MATOP_ILUFACTOR=43,
222                MATOP_INCOMPLETECHOLESKYFACTOR=44,
223                MATOP_AXPY=45,
224                MATOP_GET_SUBMATRICES=46,
225                MATOP_INCREASE_OVERLAP=47,
226                MATOP_GET_VALUES=48,
227                MATOP_COPY=49,
228                MATOP_PRINT_HELP=50,
229                MATOP_SCALE=51,
230                MATOP_SHIFT=52,
231                MATOP_DIAGONAL_SHIFT=53,
232                MATOP_ILUDT_FACTOR=54,
233                MATOP_GET_BLOCK_SIZE=55,
234                MATOP_DESTROY=250,
235                MATOP_VIEW=251
236              } MatOperation;
237 extern int MatHasOperation(Mat,MatOperation,PetscTruth*);
238 extern int MatShellSetOperation(Mat,MatOperation,void *);
239 
240 /*
241    Codes for matrices stored on disk. By default they are
242  stored in a universal format. By changing the format with
243  ViewerSetFormat(viewer,BINARY_FORMAT_NATIVE); the matrices will
244  be stored in a way natural for the matrix, for example dense matrices
245  would be stored as dense. Matrices stored this way may only be
246  read into matrices of the same time.
247 */
248 #define MATRIX_BINARY_FORMAT_DENSE -1
249 
250 #endif
251 
252 
253 
254