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 494b91b6eaSBarry 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 } 57*67d6de01SJed Brown mat->preallocated = PETSC_FALSE; 58a2ec6df8SKris Buschelman 5935d8aa7fSBarry Smith /* create the new data structure */ 6099cd5145SBarry Smith ierr = (*r)(mat);CHKERRQ(ierr); 619fb22e1aSBarry Smith #if defined(PETSC_HAVE_AMS) 629fb22e1aSBarry Smith if (PetscAMSPublishAll) { 6342eaa7f3SBarry Smith /* ierr = PetscObjectAMSPublish((PetscObject)mat);CHKERRQ(ierr); */ 649fb22e1aSBarry Smith } 659fb22e1aSBarry 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 @*/ 847087cfbeSBarry Smith PetscErrorCode 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 @*/ 1137087cfbeSBarry Smith PetscErrorCode 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 @*/ 1307087cfbeSBarry Smith PetscErrorCode 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