xref: /petsc/src/mat/interface/matreg.c (revision 9fb22e1a5a92dd4c1f6b11e8d40bcaba12a7ec6d)
1be1d678aSKris Buschelman #define PETSCMAT_DLL
2be1d678aSKris Buschelman 
37e14e8a7SBarry Smith /*
499cd5145SBarry Smith      Mechanism for register PETSc matrix types
57e14e8a7SBarry Smith */
67c4f633dSBarry Smith #include "private/matimpl.h"      /*I "petscmat.h" I*/
77e14e8a7SBarry Smith 
891af72abSBarry Smith PetscTruth MatRegisterAllCalled = PETSC_FALSE;
97e14e8a7SBarry Smith 
107e14e8a7SBarry Smith /*
1199cd5145SBarry Smith    Contains the list of registered Mat routines
127e14e8a7SBarry Smith */
13b0a32e0cSBarry Smith PetscFList MatList = 0;
147e14e8a7SBarry Smith 
154a2ae208SSatish Balay #undef __FUNCT__
164a2ae208SSatish Balay #define __FUNCT__ "MatSetType"
177e14e8a7SBarry Smith /*@C
1899cd5145SBarry Smith    MatSetType - Builds matrix object for a particular matrix type
197e14e8a7SBarry Smith 
2099cd5145SBarry Smith    Collective on Mat
217e14e8a7SBarry Smith 
227e14e8a7SBarry Smith    Input Parameters:
2399cd5145SBarry Smith +  mat      - the matrix object
2499cd5145SBarry Smith -  matype   - matrix type
257e14e8a7SBarry Smith 
267e14e8a7SBarry Smith    Options Database Key:
2799cd5145SBarry Smith .  -mat_type  <method> - Sets the type; use -help for a list
2899cd5145SBarry Smith     of available methods (for instance, seqaij)
297e14e8a7SBarry Smith 
307e14e8a7SBarry Smith    Notes:
3199cd5145SBarry Smith    See "${PETSC_DIR}/include/petscmat.h" for available methods
327e14e8a7SBarry Smith 
337e14e8a7SBarry Smith   Level: intermediate
347e14e8a7SBarry Smith 
35c2bf8781Svictorle .keywords: Mat, MatType, set, method
367e14e8a7SBarry Smith 
376e0d5acbSBarry Smith .seealso: PCSetType(), VecSetType(), MatCreate(), MatType, Mat
387e14e8a7SBarry Smith @*/
39a313700dSBarry Smith PetscErrorCode PETSCMAT_DLLEXPORT MatSetType(Mat mat, const MatType matype)
407e14e8a7SBarry Smith {
41dfbe8321SBarry Smith   PetscErrorCode ierr,(*r)(Mat);
4299cd5145SBarry Smith   PetscTruth     sametype;
437e14e8a7SBarry Smith 
447e14e8a7SBarry Smith   PetscFunctionBegin;
450700a824SBarry Smith   PetscValidHeaderSpecific(mat,MAT_CLASSID,1);
46117016b1SBarry Smith 
4799cd5145SBarry Smith   ierr = PetscTypeCompare((PetscObject)mat,matype,&sametype);CHKERRQ(ierr);
4892ff6ae8SBarry Smith   if (sametype) PetscFunctionReturn(0);
4992ff6ae8SBarry Smith 
507adad957SLisandro Dalcin   ierr =  PetscFListFind(MatList,((PetscObject)mat)->comm,matype,(void(**)(void))&r);CHKERRQ(ierr);
51e32f2f54SBarry Smith   if (!r) SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_ARG_UNKNOWN_TYPE,"Unknown Mat type given: %s",matype);
527e14e8a7SBarry Smith 
5335d8aa7fSBarry Smith   /* free the old data structure if it existed */
5435d8aa7fSBarry Smith   if (mat->ops->destroy) {
5535d8aa7fSBarry Smith     ierr = (*mat->ops->destroy)(mat);CHKERRQ(ierr);
560dd8e64fSKris Buschelman     mat->ops->destroy = PETSC_NULL;
5735d8aa7fSBarry Smith   }
58a2ec6df8SKris Buschelman 
5935d8aa7fSBarry Smith   /* create the new data structure */
6099cd5145SBarry Smith   ierr = (*r)(mat);CHKERRQ(ierr);
61*9fb22e1aSBarry Smith #if defined(PETSC_HAVE_AMS)
62*9fb22e1aSBarry Smith   if (PetscAMSPublishAll) {
63*9fb22e1aSBarry Smith     ierr = PetscObjectAMSPublish((PetscObject)mat);CHKERRQ(ierr);
64*9fb22e1aSBarry Smith   }
65*9fb22e1aSBarry Smith #endif
667e14e8a7SBarry Smith   PetscFunctionReturn(0);
677e14e8a7SBarry Smith }
687e14e8a7SBarry Smith 
6935d8aa7fSBarry Smith 
704a2ae208SSatish Balay #undef __FUNCT__
714a2ae208SSatish Balay #define __FUNCT__ "MatRegisterDestroy"
727e14e8a7SBarry Smith /*@C
7399cd5145SBarry Smith    MatRegisterDestroy - Frees the list of matrix types that were
743cea93caSBarry Smith    registered by MatRegister()/MatRegisterDynamic().
757e14e8a7SBarry Smith 
767e14e8a7SBarry Smith    Not Collective
777e14e8a7SBarry Smith 
787e14e8a7SBarry Smith    Level: advanced
797e14e8a7SBarry Smith 
8099cd5145SBarry Smith .keywords: Mat, register, destroy
817e14e8a7SBarry Smith 
823cea93caSBarry Smith .seealso: MatRegister(), MatRegisterAll(), MatRegisterDynamic()
837e14e8a7SBarry Smith @*/
84be1d678aSKris Buschelman PetscErrorCode PETSCMAT_DLLEXPORT MatRegisterDestroy(void)
857e14e8a7SBarry Smith {
86dfbe8321SBarry Smith   PetscErrorCode ierr;
877e14e8a7SBarry Smith 
887e14e8a7SBarry Smith   PetscFunctionBegin;
891441b1d3SBarry Smith   ierr = PetscFListDestroy(&MatList);CHKERRQ(ierr);
900e9836bfSBarry Smith   MatRegisterAllCalled = PETSC_FALSE;
917e14e8a7SBarry Smith   PetscFunctionReturn(0);
927e14e8a7SBarry Smith }
937e14e8a7SBarry Smith 
944a2ae208SSatish Balay #undef __FUNCT__
954a2ae208SSatish Balay #define __FUNCT__ "MatGetType"
967e14e8a7SBarry Smith /*@C
97f87b78b8SBarry Smith    MatGetType - Gets the matrix type as a string from the matrix object.
987e14e8a7SBarry Smith 
997e14e8a7SBarry Smith    Not Collective
1007e14e8a7SBarry Smith 
1017e14e8a7SBarry Smith    Input Parameter:
10299cd5145SBarry Smith .  mat - the matrix
1037e14e8a7SBarry Smith 
1047e14e8a7SBarry Smith    Output Parameter:
10599cd5145SBarry Smith .  name - name of matrix type
1067e14e8a7SBarry Smith 
1077e14e8a7SBarry Smith    Level: intermediate
1087e14e8a7SBarry Smith 
109c2bf8781Svictorle .keywords: Mat, MatType, get, method, name
1107e14e8a7SBarry Smith 
11199cd5145SBarry Smith .seealso: MatSetType()
1127e14e8a7SBarry Smith @*/
113a313700dSBarry Smith PetscErrorCode PETSCMAT_DLLEXPORT MatGetType(Mat mat,const MatType *type)
1147e14e8a7SBarry Smith {
1157e14e8a7SBarry Smith   PetscFunctionBegin;
1160700a824SBarry Smith   PetscValidHeaderSpecific(mat,MAT_CLASSID,1);
117c4e43342SLisandro Dalcin   PetscValidPointer(type,2);
1187adad957SLisandro Dalcin   *type = ((PetscObject)mat)->type_name;
1197e14e8a7SBarry Smith   PetscFunctionReturn(0);
1207e14e8a7SBarry Smith }
1217e14e8a7SBarry Smith 
1227e14e8a7SBarry Smith 
1234a2ae208SSatish Balay #undef __FUNCT__
1244a2ae208SSatish Balay #define __FUNCT__ "MatRegister"
1253cea93caSBarry Smith /*@C
1263cea93caSBarry Smith   MatRegister - See MatRegisterDynamic()
1273cea93caSBarry Smith 
1287f6c08e0SMatthew Knepley   Level: advanced
1293cea93caSBarry Smith @*/
130be1d678aSKris Buschelman PetscErrorCode PETSCMAT_DLLEXPORT MatRegister(const char sname[],const char path[],const char name[],PetscErrorCode (*function)(Mat))
1317e14e8a7SBarry Smith {
132dfbe8321SBarry Smith   PetscErrorCode ierr;
133e10c49a3SBarry Smith   char           fullname[PETSC_MAX_PATH_LEN];
1347e14e8a7SBarry Smith 
1357e14e8a7SBarry Smith   PetscFunctionBegin;
136b0a32e0cSBarry Smith   ierr = PetscFListConcat(path,name,fullname);CHKERRQ(ierr);
137c134de8dSSatish Balay   ierr = PetscFListAdd(&MatList,sname,fullname,(void (*)(void))function);CHKERRQ(ierr);
13899cd5145SBarry Smith   PetscFunctionReturn(0);
13999cd5145SBarry Smith }
14099cd5145SBarry Smith 
14199cd5145SBarry Smith 
14299cd5145SBarry Smith 
14399cd5145SBarry Smith 
144273d9f13SBarry Smith 
145273d9f13SBarry Smith 
146273d9f13SBarry Smith 
147273d9f13SBarry Smith 
148273d9f13SBarry Smith 
149273d9f13SBarry Smith 
150