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; 45*0700a824SBarry 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); 51958c9bccSBarry Smith if (!r) SETERRQ1(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) { 55b50b34bdSBarry Smith ierr = MatPreallocated(mat);CHKERRQ(ierr); 5635d8aa7fSBarry Smith ierr = (*mat->ops->destroy)(mat);CHKERRQ(ierr); 570dd8e64fSKris Buschelman mat->ops->destroy = PETSC_NULL; 58a2ec6df8SKris Buschelman mat->preallocated = PETSC_FALSE; 5935d8aa7fSBarry Smith } 60a2ec6df8SKris Buschelman 6135d8aa7fSBarry Smith /* create the new data structure */ 62117016b1SBarry Smith if (mat->rmap->n < 0 && mat->rmap->N < 0 && mat->cmap->n < 0 && mat->cmap->N < 0) { 63117016b1SBarry Smith mat->ops->create = r; 64117016b1SBarry Smith } else { 6599cd5145SBarry Smith ierr = (*r)(mat);CHKERRQ(ierr); 66117016b1SBarry Smith } 6735d8aa7fSBarry Smith ierr = PetscPublishAll(mat);CHKERRQ(ierr); 687e14e8a7SBarry Smith PetscFunctionReturn(0); 697e14e8a7SBarry Smith } 707e14e8a7SBarry Smith 7135d8aa7fSBarry Smith 724a2ae208SSatish Balay #undef __FUNCT__ 734a2ae208SSatish Balay #define __FUNCT__ "MatRegisterDestroy" 747e14e8a7SBarry Smith /*@C 7599cd5145SBarry Smith MatRegisterDestroy - Frees the list of matrix types that were 763cea93caSBarry Smith registered by MatRegister()/MatRegisterDynamic(). 777e14e8a7SBarry Smith 787e14e8a7SBarry Smith Not Collective 797e14e8a7SBarry Smith 807e14e8a7SBarry Smith Level: advanced 817e14e8a7SBarry Smith 8299cd5145SBarry Smith .keywords: Mat, register, destroy 837e14e8a7SBarry Smith 843cea93caSBarry Smith .seealso: MatRegister(), MatRegisterAll(), MatRegisterDynamic() 857e14e8a7SBarry Smith @*/ 86be1d678aSKris Buschelman PetscErrorCode PETSCMAT_DLLEXPORT MatRegisterDestroy(void) 877e14e8a7SBarry Smith { 88dfbe8321SBarry Smith PetscErrorCode ierr; 897e14e8a7SBarry Smith 907e14e8a7SBarry Smith PetscFunctionBegin; 911441b1d3SBarry Smith ierr = PetscFListDestroy(&MatList);CHKERRQ(ierr); 920e9836bfSBarry Smith MatRegisterAllCalled = PETSC_FALSE; 937e14e8a7SBarry Smith PetscFunctionReturn(0); 947e14e8a7SBarry Smith } 957e14e8a7SBarry Smith 964a2ae208SSatish Balay #undef __FUNCT__ 974a2ae208SSatish Balay #define __FUNCT__ "MatGetType" 987e14e8a7SBarry Smith /*@C 99f87b78b8SBarry Smith MatGetType - Gets the matrix type as a string from the matrix object. 1007e14e8a7SBarry Smith 1017e14e8a7SBarry Smith Not Collective 1027e14e8a7SBarry Smith 1037e14e8a7SBarry Smith Input Parameter: 10499cd5145SBarry Smith . mat - the matrix 1057e14e8a7SBarry Smith 1067e14e8a7SBarry Smith Output Parameter: 10799cd5145SBarry Smith . name - name of matrix type 1087e14e8a7SBarry Smith 1097e14e8a7SBarry Smith Level: intermediate 1107e14e8a7SBarry Smith 111c2bf8781Svictorle .keywords: Mat, MatType, get, method, name 1127e14e8a7SBarry Smith 11399cd5145SBarry Smith .seealso: MatSetType() 1147e14e8a7SBarry Smith @*/ 115a313700dSBarry Smith PetscErrorCode PETSCMAT_DLLEXPORT MatGetType(Mat mat,const MatType *type) 1167e14e8a7SBarry Smith { 1177e14e8a7SBarry Smith PetscFunctionBegin; 118*0700a824SBarry Smith PetscValidHeaderSpecific(mat,MAT_CLASSID,1); 119c4e43342SLisandro Dalcin PetscValidPointer(type,2); 1207adad957SLisandro Dalcin *type = ((PetscObject)mat)->type_name; 1217e14e8a7SBarry Smith PetscFunctionReturn(0); 1227e14e8a7SBarry Smith } 1237e14e8a7SBarry Smith 1247e14e8a7SBarry Smith 1254a2ae208SSatish Balay #undef __FUNCT__ 1264a2ae208SSatish Balay #define __FUNCT__ "MatRegister" 1273cea93caSBarry Smith /*@C 1283cea93caSBarry Smith MatRegister - See MatRegisterDynamic() 1293cea93caSBarry Smith 1307f6c08e0SMatthew Knepley Level: advanced 1313cea93caSBarry Smith @*/ 132be1d678aSKris Buschelman PetscErrorCode PETSCMAT_DLLEXPORT MatRegister(const char sname[],const char path[],const char name[],PetscErrorCode (*function)(Mat)) 1337e14e8a7SBarry Smith { 134dfbe8321SBarry Smith PetscErrorCode ierr; 135e10c49a3SBarry Smith char fullname[PETSC_MAX_PATH_LEN]; 1367e14e8a7SBarry Smith 1377e14e8a7SBarry Smith PetscFunctionBegin; 138b0a32e0cSBarry Smith ierr = PetscFListConcat(path,name,fullname);CHKERRQ(ierr); 139c134de8dSSatish Balay ierr = PetscFListAdd(&MatList,sname,fullname,(void (*)(void))function);CHKERRQ(ierr); 14099cd5145SBarry Smith PetscFunctionReturn(0); 14199cd5145SBarry Smith } 14299cd5145SBarry Smith 14399cd5145SBarry Smith 14499cd5145SBarry Smith 14599cd5145SBarry Smith 146273d9f13SBarry Smith 147273d9f13SBarry Smith 148273d9f13SBarry Smith 149273d9f13SBarry Smith 150273d9f13SBarry Smith 151273d9f13SBarry Smith 152