xref: /petsc/src/mat/interface/matreg.c (revision 647798804180922dfb980ca29d2b49fa46af1416)
1 #define PETSCMAT_DLL
2 
3 /*
4      Mechanism for register PETSc matrix types
5 */
6 #include "private/matimpl.h"      /*I "petscmat.h" I*/
7 
8 PetscBool  MatRegisterAllCalled = PETSC_FALSE;
9 
10 /*
11    Contains the list of registered Mat routines
12 */
13 PetscFList MatList = 0;
14 
15 #undef __FUNCT__
16 #define __FUNCT__ "MatSetType"
17 /*@C
18    MatSetType - Builds matrix object for a particular matrix type
19 
20    Collective on Mat
21 
22    Input Parameters:
23 +  mat      - the matrix object
24 -  matype   - matrix type
25 
26    Options Database Key:
27 .  -mat_type  <method> - Sets the type; use -help for a list
28     of available methods (for instance, seqaij)
29 
30    Notes:
31    See "${PETSC_DIR}/include/petscmat.h" for available methods
32 
33   Level: intermediate
34 
35 .keywords: Mat, MatType, set, method
36 
37 .seealso: PCSetType(), VecSetType(), MatCreate(), MatType, Mat
38 @*/
39 PetscErrorCode  MatSetType(Mat mat, const MatType matype)
40 {
41   PetscErrorCode ierr,(*r)(Mat);
42   PetscBool      sametype;
43 
44   PetscFunctionBegin;
45   PetscValidHeaderSpecific(mat,MAT_CLASSID,1);
46 
47   ierr = PetscTypeCompare((PetscObject)mat,matype,&sametype);CHKERRQ(ierr);
48   if (sametype) PetscFunctionReturn(0);
49 
50   ierr =  PetscFListFind(MatList,((PetscObject)mat)->comm,matype,(void(**)(void))&r);CHKERRQ(ierr);
51   if (!r) SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_ARG_UNKNOWN_TYPE,"Unknown Mat type given: %s",matype);
52 
53   /* free the old data structure if it existed */
54   if (mat->ops->destroy) {
55     ierr = (*mat->ops->destroy)(mat);CHKERRQ(ierr);
56     mat->ops->destroy = PETSC_NULL;
57   }
58 
59   /* create the new data structure */
60   ierr = (*r)(mat);CHKERRQ(ierr);
61 #if defined(PETSC_HAVE_AMS)
62   if (PetscAMSPublishAll) {
63     /*    ierr = PetscObjectAMSPublish((PetscObject)mat);CHKERRQ(ierr); */
64   }
65 #endif
66   PetscFunctionReturn(0);
67 }
68 
69 
70 #undef __FUNCT__
71 #define __FUNCT__ "MatRegisterDestroy"
72 /*@C
73    MatRegisterDestroy - Frees the list of matrix types that were
74    registered by MatRegister()/MatRegisterDynamic().
75 
76    Not Collective
77 
78    Level: advanced
79 
80 .keywords: Mat, register, destroy
81 
82 .seealso: MatRegister(), MatRegisterAll(), MatRegisterDynamic()
83 @*/
84 PetscErrorCode  MatRegisterDestroy(void)
85 {
86   PetscErrorCode ierr;
87 
88   PetscFunctionBegin;
89   ierr = PetscFListDestroy(&MatList);CHKERRQ(ierr);
90   MatRegisterAllCalled = PETSC_FALSE;
91   PetscFunctionReturn(0);
92 }
93 
94 #undef __FUNCT__
95 #define __FUNCT__ "MatGetType"
96 /*@C
97    MatGetType - Gets the matrix type as a string from the matrix object.
98 
99    Not Collective
100 
101    Input Parameter:
102 .  mat - the matrix
103 
104    Output Parameter:
105 .  name - name of matrix type
106 
107    Level: intermediate
108 
109 .keywords: Mat, MatType, get, method, name
110 
111 .seealso: MatSetType()
112 @*/
113 PetscErrorCode  MatGetType(Mat mat,const MatType *type)
114 {
115   PetscFunctionBegin;
116   PetscValidHeaderSpecific(mat,MAT_CLASSID,1);
117   PetscValidPointer(type,2);
118   *type = ((PetscObject)mat)->type_name;
119   PetscFunctionReturn(0);
120 }
121 
122 
123 #undef __FUNCT__
124 #define __FUNCT__ "MatRegister"
125 /*@C
126   MatRegister - See MatRegisterDynamic()
127 
128   Level: advanced
129 @*/
130 PetscErrorCode  MatRegister(const char sname[],const char path[],const char name[],PetscErrorCode (*function)(Mat))
131 {
132   PetscErrorCode ierr;
133   char           fullname[PETSC_MAX_PATH_LEN];
134 
135   PetscFunctionBegin;
136   ierr = PetscFListConcat(path,name,fullname);CHKERRQ(ierr);
137   ierr = PetscFListAdd(&MatList,sname,fullname,(void (*)(void))function);CHKERRQ(ierr);
138   PetscFunctionReturn(0);
139 }
140 
141 
142 
143 
144 
145 
146 
147 
148 
149 
150