xref: /petsc/src/mat/interface/matreg.c (revision 4b91b6eae087708c6d6dc4e372cbc7b84f10f223)
1be1d678aSKris Buschelman 
27e14e8a7SBarry Smith /*
399cd5145SBarry Smith      Mechanism for register PETSc matrix types
47e14e8a7SBarry Smith */
5c6db04a5SJed Brown #include <private/matimpl.h>      /*I "petscmat.h" I*/
67e14e8a7SBarry Smith 
7ace3abfcSBarry Smith PetscBool  MatRegisterAllCalled = PETSC_FALSE;
87e14e8a7SBarry Smith 
97e14e8a7SBarry Smith /*
1099cd5145SBarry Smith    Contains the list of registered Mat routines
117e14e8a7SBarry Smith */
12b0a32e0cSBarry Smith PetscFList MatList = 0;
137e14e8a7SBarry Smith 
144a2ae208SSatish Balay #undef __FUNCT__
154a2ae208SSatish Balay #define __FUNCT__ "MatSetType"
167e14e8a7SBarry Smith /*@C
1799cd5145SBarry Smith    MatSetType - Builds matrix object for a particular matrix type
187e14e8a7SBarry Smith 
1999cd5145SBarry Smith    Collective on Mat
207e14e8a7SBarry Smith 
217e14e8a7SBarry Smith    Input Parameters:
2299cd5145SBarry Smith +  mat      - the matrix object
2399cd5145SBarry Smith -  matype   - matrix type
247e14e8a7SBarry Smith 
257e14e8a7SBarry Smith    Options Database Key:
2699cd5145SBarry Smith .  -mat_type  <method> - Sets the type; use -help for a list
2799cd5145SBarry Smith     of available methods (for instance, seqaij)
287e14e8a7SBarry Smith 
297e14e8a7SBarry Smith    Notes:
3099cd5145SBarry Smith    See "${PETSC_DIR}/include/petscmat.h" for available methods
317e14e8a7SBarry Smith 
327e14e8a7SBarry Smith   Level: intermediate
337e14e8a7SBarry Smith 
34c2bf8781Svictorle .keywords: Mat, MatType, set, method
357e14e8a7SBarry Smith 
366e0d5acbSBarry Smith .seealso: PCSetType(), VecSetType(), MatCreate(), MatType, Mat
377e14e8a7SBarry Smith @*/
387087cfbeSBarry Smith PetscErrorCode  MatSetType(Mat mat, const MatType matype)
397e14e8a7SBarry Smith {
40dfbe8321SBarry Smith   PetscErrorCode ierr,(*r)(Mat);
41ace3abfcSBarry Smith   PetscBool      sametype;
427e14e8a7SBarry Smith 
437e14e8a7SBarry Smith   PetscFunctionBegin;
440700a824SBarry Smith   PetscValidHeaderSpecific(mat,MAT_CLASSID,1);
45117016b1SBarry Smith 
4699cd5145SBarry Smith   ierr = PetscTypeCompare((PetscObject)mat,matype,&sametype);CHKERRQ(ierr);
4792ff6ae8SBarry Smith   if (sametype) PetscFunctionReturn(0);
4892ff6ae8SBarry Smith 
49*4b91b6eaSBarry Smith   ierr =  PetscFListFind(MatList,((PetscObject)mat)->comm,matype,PETSC_TRUE,(void(**)(void))&r);CHKERRQ(ierr);
50e32f2f54SBarry Smith   if (!r) SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_ARG_UNKNOWN_TYPE,"Unknown Mat type given: %s",matype);
517e14e8a7SBarry Smith 
5235d8aa7fSBarry Smith   /* free the old data structure if it existed */
5335d8aa7fSBarry Smith   if (mat->ops->destroy) {
5435d8aa7fSBarry Smith     ierr = (*mat->ops->destroy)(mat);CHKERRQ(ierr);
550dd8e64fSKris Buschelman     mat->ops->destroy = PETSC_NULL;
5635d8aa7fSBarry Smith   }
57a2ec6df8SKris Buschelman 
5835d8aa7fSBarry Smith   /* create the new data structure */
5999cd5145SBarry Smith   ierr = (*r)(mat);CHKERRQ(ierr);
609fb22e1aSBarry Smith #if defined(PETSC_HAVE_AMS)
619fb22e1aSBarry Smith   if (PetscAMSPublishAll) {
6242eaa7f3SBarry Smith     /*    ierr = PetscObjectAMSPublish((PetscObject)mat);CHKERRQ(ierr); */
639fb22e1aSBarry Smith   }
649fb22e1aSBarry Smith #endif
657e14e8a7SBarry Smith   PetscFunctionReturn(0);
667e14e8a7SBarry Smith }
677e14e8a7SBarry Smith 
6835d8aa7fSBarry Smith 
694a2ae208SSatish Balay #undef __FUNCT__
704a2ae208SSatish Balay #define __FUNCT__ "MatRegisterDestroy"
717e14e8a7SBarry Smith /*@C
7299cd5145SBarry Smith    MatRegisterDestroy - Frees the list of matrix types that were
733cea93caSBarry Smith    registered by MatRegister()/MatRegisterDynamic().
747e14e8a7SBarry Smith 
757e14e8a7SBarry Smith    Not Collective
767e14e8a7SBarry Smith 
777e14e8a7SBarry Smith    Level: advanced
787e14e8a7SBarry Smith 
7999cd5145SBarry Smith .keywords: Mat, register, destroy
807e14e8a7SBarry Smith 
813cea93caSBarry Smith .seealso: MatRegister(), MatRegisterAll(), MatRegisterDynamic()
827e14e8a7SBarry Smith @*/
837087cfbeSBarry Smith PetscErrorCode  MatRegisterDestroy(void)
847e14e8a7SBarry Smith {
85dfbe8321SBarry Smith   PetscErrorCode ierr;
867e14e8a7SBarry Smith 
877e14e8a7SBarry Smith   PetscFunctionBegin;
881441b1d3SBarry Smith   ierr = PetscFListDestroy(&MatList);CHKERRQ(ierr);
890e9836bfSBarry Smith   MatRegisterAllCalled = PETSC_FALSE;
907e14e8a7SBarry Smith   PetscFunctionReturn(0);
917e14e8a7SBarry Smith }
927e14e8a7SBarry Smith 
934a2ae208SSatish Balay #undef __FUNCT__
944a2ae208SSatish Balay #define __FUNCT__ "MatGetType"
957e14e8a7SBarry Smith /*@C
96f87b78b8SBarry Smith    MatGetType - Gets the matrix type as a string from the matrix object.
977e14e8a7SBarry Smith 
987e14e8a7SBarry Smith    Not Collective
997e14e8a7SBarry Smith 
1007e14e8a7SBarry Smith    Input Parameter:
10199cd5145SBarry Smith .  mat - the matrix
1027e14e8a7SBarry Smith 
1037e14e8a7SBarry Smith    Output Parameter:
10499cd5145SBarry Smith .  name - name of matrix type
1057e14e8a7SBarry Smith 
1067e14e8a7SBarry Smith    Level: intermediate
1077e14e8a7SBarry Smith 
108c2bf8781Svictorle .keywords: Mat, MatType, get, method, name
1097e14e8a7SBarry Smith 
11099cd5145SBarry Smith .seealso: MatSetType()
1117e14e8a7SBarry Smith @*/
1127087cfbeSBarry Smith PetscErrorCode  MatGetType(Mat mat,const MatType *type)
1137e14e8a7SBarry Smith {
1147e14e8a7SBarry Smith   PetscFunctionBegin;
1150700a824SBarry Smith   PetscValidHeaderSpecific(mat,MAT_CLASSID,1);
116c4e43342SLisandro Dalcin   PetscValidPointer(type,2);
1177adad957SLisandro Dalcin   *type = ((PetscObject)mat)->type_name;
1187e14e8a7SBarry Smith   PetscFunctionReturn(0);
1197e14e8a7SBarry Smith }
1207e14e8a7SBarry Smith 
1217e14e8a7SBarry Smith 
1224a2ae208SSatish Balay #undef __FUNCT__
1234a2ae208SSatish Balay #define __FUNCT__ "MatRegister"
1243cea93caSBarry Smith /*@C
1253cea93caSBarry Smith   MatRegister - See MatRegisterDynamic()
1263cea93caSBarry Smith 
1277f6c08e0SMatthew Knepley   Level: advanced
1283cea93caSBarry Smith @*/
1297087cfbeSBarry Smith PetscErrorCode  MatRegister(const char sname[],const char path[],const char name[],PetscErrorCode (*function)(Mat))
1307e14e8a7SBarry Smith {
131dfbe8321SBarry Smith   PetscErrorCode ierr;
132e10c49a3SBarry Smith   char           fullname[PETSC_MAX_PATH_LEN];
1337e14e8a7SBarry Smith 
1347e14e8a7SBarry Smith   PetscFunctionBegin;
135b0a32e0cSBarry Smith   ierr = PetscFListConcat(path,name,fullname);CHKERRQ(ierr);
136c134de8dSSatish Balay   ierr = PetscFListAdd(&MatList,sname,fullname,(void (*)(void))function);CHKERRQ(ierr);
13799cd5145SBarry Smith   PetscFunctionReturn(0);
13899cd5145SBarry Smith }
13999cd5145SBarry Smith 
14099cd5145SBarry Smith 
14199cd5145SBarry Smith 
14299cd5145SBarry Smith 
143273d9f13SBarry Smith 
144273d9f13SBarry Smith 
145273d9f13SBarry Smith 
146273d9f13SBarry Smith 
147273d9f13SBarry Smith 
148273d9f13SBarry Smith 
149