1be1d678aSKris Buschelman #define PETSCMAT_DLL 2be1d678aSKris Buschelman 37e14e8a7SBarry Smith /* 499cd5145SBarry Smith Mechanism for register PETSc matrix types 57e14e8a7SBarry Smith */ 6aa59fb91SSatish Balay #include "src/mat/matimpl.h" /*I "petscmat.h" I*/ 799cd5145SBarry Smith #include "petscsys.h" 87e14e8a7SBarry Smith 991af72abSBarry Smith PetscTruth MatRegisterAllCalled = PETSC_FALSE; 107e14e8a7SBarry Smith 117e14e8a7SBarry Smith /* 1299cd5145SBarry Smith Contains the list of registered Mat routines 137e14e8a7SBarry Smith */ 14b0a32e0cSBarry Smith PetscFList MatList = 0; 157e14e8a7SBarry Smith 164a2ae208SSatish Balay #undef __FUNCT__ 174a2ae208SSatish Balay #define __FUNCT__ "MatSetType" 187e14e8a7SBarry Smith /*@C 1999cd5145SBarry Smith MatSetType - Builds matrix object for a particular matrix type 207e14e8a7SBarry Smith 2199cd5145SBarry Smith Collective on Mat 227e14e8a7SBarry Smith 237e14e8a7SBarry Smith Input Parameters: 2499cd5145SBarry Smith + mat - the matrix object 2599cd5145SBarry Smith - matype - matrix type 267e14e8a7SBarry Smith 277e14e8a7SBarry Smith Options Database Key: 2899cd5145SBarry Smith . -mat_type <method> - Sets the type; use -help for a list 2999cd5145SBarry Smith of available methods (for instance, seqaij) 307e14e8a7SBarry Smith 317e14e8a7SBarry Smith Notes: 3299cd5145SBarry Smith See "${PETSC_DIR}/include/petscmat.h" for available methods 337e14e8a7SBarry Smith 347e14e8a7SBarry Smith Level: intermediate 357e14e8a7SBarry Smith 36c2bf8781Svictorle .keywords: Mat, MatType, set, method 377e14e8a7SBarry Smith 386e0d5acbSBarry Smith .seealso: PCSetType(), VecSetType(), MatCreate(), MatType, Mat 397e14e8a7SBarry Smith @*/ 40f69a0ea3SMatthew Knepley PetscErrorCode PETSCMAT_DLLEXPORT MatSetType(Mat mat, MatType matype) 417e14e8a7SBarry Smith { 42dfbe8321SBarry Smith PetscErrorCode ierr,(*r)(Mat); 4399cd5145SBarry Smith PetscTruth sametype; 447e14e8a7SBarry Smith 457e14e8a7SBarry Smith PetscFunctionBegin; 464482741eSBarry Smith PetscValidHeaderSpecific(mat,MAT_COOKIE,1); 47*899cda47SBarry Smith if (mat->rmap.n < 0 && mat->rmap.N < 0 && mat->cmap.n < 0 && mat->cmap.N < 0) SETERRQ(PETSC_ERR_ARG_WRONGSTATE,"Must call MatSetSizes() first"); 4899cd5145SBarry Smith ierr = PetscTypeCompare((PetscObject)mat,matype,&sametype);CHKERRQ(ierr); 4935d8aa7fSBarry Smith if (!sametype) { 5099cd5145SBarry Smith /* Get the function pointers for the matrix requested */ 5199cd5145SBarry Smith if (!MatRegisterAllCalled) {ierr = MatRegisterAll(PETSC_NULL);CHKERRQ(ierr);} 52c134de8dSSatish Balay ierr = PetscFListFind(mat->comm,MatList,matype,(void(**)(void))&r);CHKERRQ(ierr); 53958c9bccSBarry Smith if (!r) SETERRQ1(PETSC_ERR_ARG_UNKNOWN_TYPE,"Unknown Mat type given: %s",matype); 547e14e8a7SBarry Smith 5535d8aa7fSBarry Smith /* free the old data structure if it existed */ 5635d8aa7fSBarry Smith if (mat->ops->destroy) { 57b50b34bdSBarry Smith ierr = MatPreallocated(mat);CHKERRQ(ierr); 5835d8aa7fSBarry Smith ierr = (*mat->ops->destroy)(mat);CHKERRQ(ierr); 590dd8e64fSKris Buschelman mat->ops->destroy = PETSC_NULL; 60a2ec6df8SKris Buschelman mat->preallocated = PETSC_FALSE; 6135d8aa7fSBarry Smith } 62a2ec6df8SKris Buschelman 6335d8aa7fSBarry Smith /* create the new data structure */ 6499cd5145SBarry Smith ierr = (*r)(mat);CHKERRQ(ierr); 65b9b97703SBarry Smith ierr = PetscObjectChangeTypeName((PetscObject)mat,matype);CHKERRQ(ierr); 6635d8aa7fSBarry 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; 9199cd5145SBarry Smith if (MatList) { 92b0a32e0cSBarry Smith ierr = PetscFListDestroy(&MatList);CHKERRQ(ierr); 9399cd5145SBarry Smith MatList = 0; 947e14e8a7SBarry Smith } 950e9836bfSBarry Smith MatRegisterAllCalled = PETSC_FALSE; 967e14e8a7SBarry Smith PetscFunctionReturn(0); 977e14e8a7SBarry Smith } 987e14e8a7SBarry Smith 994a2ae208SSatish Balay #undef __FUNCT__ 1004a2ae208SSatish Balay #define __FUNCT__ "MatGetType" 1017e14e8a7SBarry Smith /*@C 102f87b78b8SBarry Smith MatGetType - Gets the matrix type as a string from the matrix object. 1037e14e8a7SBarry Smith 1047e14e8a7SBarry Smith Not Collective 1057e14e8a7SBarry Smith 1067e14e8a7SBarry Smith Input Parameter: 10799cd5145SBarry Smith . mat - the matrix 1087e14e8a7SBarry Smith 1097e14e8a7SBarry Smith Output Parameter: 11099cd5145SBarry Smith . name - name of matrix type 1117e14e8a7SBarry Smith 1127e14e8a7SBarry Smith Level: intermediate 1137e14e8a7SBarry Smith 114c2bf8781Svictorle .keywords: Mat, MatType, get, method, name 1157e14e8a7SBarry Smith 11699cd5145SBarry Smith .seealso: MatSetType() 1177e14e8a7SBarry Smith @*/ 118be1d678aSKris Buschelman PetscErrorCode PETSCMAT_DLLEXPORT MatGetType(Mat mat,MatType *type) 1197e14e8a7SBarry Smith { 1207e14e8a7SBarry Smith PetscFunctionBegin; 12199cd5145SBarry Smith *type = mat->type_name; 1227e14e8a7SBarry Smith PetscFunctionReturn(0); 1237e14e8a7SBarry Smith } 1247e14e8a7SBarry Smith 1257e14e8a7SBarry Smith 1264a2ae208SSatish Balay #undef __FUNCT__ 1274a2ae208SSatish Balay #define __FUNCT__ "MatRegister" 1283cea93caSBarry Smith /*@C 1293cea93caSBarry Smith MatRegister - See MatRegisterDynamic() 1303cea93caSBarry Smith 1317f6c08e0SMatthew Knepley Level: advanced 1323cea93caSBarry Smith @*/ 133be1d678aSKris Buschelman PetscErrorCode PETSCMAT_DLLEXPORT MatRegister(const char sname[],const char path[],const char name[],PetscErrorCode (*function)(Mat)) 1347e14e8a7SBarry Smith { 135dfbe8321SBarry Smith PetscErrorCode ierr; 136e10c49a3SBarry Smith char fullname[PETSC_MAX_PATH_LEN]; 1377e14e8a7SBarry Smith 1387e14e8a7SBarry Smith PetscFunctionBegin; 139b0a32e0cSBarry Smith ierr = PetscFListConcat(path,name,fullname);CHKERRQ(ierr); 140c134de8dSSatish Balay ierr = PetscFListAdd(&MatList,sname,fullname,(void (*)(void))function);CHKERRQ(ierr); 14199cd5145SBarry Smith PetscFunctionReturn(0); 14299cd5145SBarry Smith } 14399cd5145SBarry Smith 14499cd5145SBarry Smith 14599cd5145SBarry Smith 14699cd5145SBarry Smith 147273d9f13SBarry Smith 148273d9f13SBarry Smith 149273d9f13SBarry Smith 150273d9f13SBarry Smith 151273d9f13SBarry Smith 152273d9f13SBarry Smith 153