xref: /petsc/include/petscmat.h (revision d4fbbf0ea49bb599f06790484d06b33562a2b638)
1 /* $Id: mat.h,v 1.113 1996/08/22 22:25:21 curfman Exp bsmith $ */
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 { MAT_SET_VALUES=0,
180                MAT_GET_ROW=1,
181                MAT_RESTORE_ROW=2,
182                MAT_MULT=3,
183                MAT_MULT_ADD=4,
184                MAT_MULT_TRANS=5,
185                MAT_MULT_TRANS_ADD=6,
186                MAT_SOLVE=7,
187                MAT_SOLVE_ADD=8,
188                MAT_SOLVE_TRANS=9,
189                MAT_SOLVE_TRANS_ADD=10,
190                MAT_LUFACTOR=11,
191                MAT_CHOLESKYFACTOR=12,
192                MAT_RELAX=13,
193                MAT_TRANSPOSE=14,
194                MAT_GETINFO=15,
195                MAT_EQUAL=16,
196                MAT_GET_DIAGONAL=17,
197                MAT_DIAGONAL_SCALE=18,
198                MAT_NORM=19,
199                MAT_ASSEMBLY_BEGIN=20,
200                MAT_ASSEMBLY_END=21,
201                MAT_COMPRESS=22,
202                MAT_SET_OPTION=23,
203                MAT_ZERO_ENTRIES=24,
204                MAT_ZERO_ROWS=25,
205                MAT_LUFACTOR_SYMBOLIC=26,
206                MAT_LUFACTOR_NUMERIC=27,
207                MAT_CHOLESKY_FACTOR_SYMBOLIC=28,
208                MAT_CHOLESKY_FACTOR_NUMERIC=29,
209                MAT_GET_SIZE=30,
210                MAT_GET_LOCAL_SIZE=31,
211                MAT_GET_OWNERSHIP_RANGE=32,
212                MAT_ILUFACTOR_SYMBOLIC=33,
213                MAT_INCOMPLETECHOLESKYFACTOR_SYMBOLIC=34,
214                MAT_GET_ARRAY=35,
215                MAT_RESTORE_ARRAY=36,
216                MAT_CONVERT=37,
217                MAT_GET_SUBMATRIX=38,
218                MAT_GET_SUBMATRIX_INPLACE=39,
219                MAT_CONVERT_SAME_TYPE=40,
220                MAT_FORWARD_SOLVE=41,
221                MAT_BACKWARD_SOLVE=42,
222                MAT_ILUFACTOR=43,
223                MAT_INCOMPLETECHOLESKYFACTOR=44,
224                MAT_AXPY=45,
225                MAT_GET_SUBMATRICES=46,
226                MAT_INCREASE_OVERLAP=47,
227                MAT_GET_VALUES=48,
228                MAT_COPY=49,
229                MAT_PRINT_HELP=50,
230                MAT_SCALE=51,
231                MAT_SHIFT=52,
232                MAT_DIAGONAL_SHIFT=53,
233                MAT_ILUDT_FACTOR=54,
234                MAT_GET_BLOCK_SIZE=55,
235                MAT_DESTROY=250,
236                MAT_VIEW=251
237              } MatOperation;
238 extern int MatHasOperation(Mat,MatOperation,PetscTruth*);
239 extern int MatShellSetOperation(Mat,MatOperation,void *);
240 
241 /*
242    Codes for matrices stored on disk. By default they are
243  stored in a universal format. By changing the format with
244  ViewerSetFormat(viewer,BINARY_FORMAT_NATIVE); the matrices will
245  be stored in a way natural for the matrix, for example dense matrices
246  would be stored as dense. Matrices stored this way may only be
247  read into matrices of the same time.
248 */
249 #define MATRIX_BINARY_FORMAT_DENSE -1
250 
251 #endif
252 
253 
254 
255