17e14e8a7SBarry Smith #ifdef PETSC_RCS_HEADER 273f4d377SMatthew Knepley static char vcid[] = "$Id: matreg.c,v 1.18 2001/07/20 21:19:21 bsmith Exp $"; 37e14e8a7SBarry Smith #endif 47e14e8a7SBarry Smith /* 599cd5145SBarry Smith Mechanism for register PETSc matrix types 67e14e8a7SBarry Smith */ 7aa59fb91SSatish Balay #include "src/mat/matimpl.h" /*I "petscmat.h" I*/ 899cd5145SBarry Smith #include "petscsys.h" 97e14e8a7SBarry Smith 1091af72abSBarry Smith PetscTruth MatRegisterAllCalled = PETSC_FALSE; 117e14e8a7SBarry Smith 127e14e8a7SBarry Smith /* 1399cd5145SBarry Smith Contains the list of registered Mat routines 147e14e8a7SBarry Smith */ 15b0a32e0cSBarry Smith PetscFList MatList = 0; 167e14e8a7SBarry Smith 174a2ae208SSatish Balay #undef __FUNCT__ 184a2ae208SSatish Balay #define __FUNCT__ "MatSetType" 197e14e8a7SBarry Smith /*@C 2099cd5145SBarry Smith MatSetType - Builds matrix object for a particular matrix type 217e14e8a7SBarry Smith 2299cd5145SBarry Smith Collective on Mat 237e14e8a7SBarry Smith 247e14e8a7SBarry Smith Input Parameters: 2599cd5145SBarry Smith + mat - the matrix object 2699cd5145SBarry Smith - matype - matrix type 277e14e8a7SBarry Smith 287e14e8a7SBarry Smith Options Database Key: 2999cd5145SBarry Smith . -mat_type <method> - Sets the type; use -help for a list 3099cd5145SBarry Smith of available methods (for instance, seqaij) 317e14e8a7SBarry Smith 327e14e8a7SBarry Smith Notes: 3399cd5145SBarry Smith See "${PETSC_DIR}/include/petscmat.h" for available methods 347e14e8a7SBarry Smith 357e14e8a7SBarry Smith Level: intermediate 367e14e8a7SBarry Smith 3799cd5145SBarry Smith .keywords: Mat, set, method 387e14e8a7SBarry Smith 396e0d5acbSBarry Smith .seealso: PCSetType(), VecSetType(), MatCreate(), MatType, Mat 407e14e8a7SBarry Smith @*/ 41273d9f13SBarry Smith int MatSetType(Mat mat,MatType matype) 427e14e8a7SBarry Smith { 4399cd5145SBarry Smith int ierr,(*r)(Mat); 4499cd5145SBarry Smith PetscTruth sametype; 457e14e8a7SBarry Smith 467e14e8a7SBarry Smith PetscFunctionBegin; 4799cd5145SBarry Smith PetscValidHeaderSpecific(mat,MAT_COOKIE); 487e14e8a7SBarry Smith 4999cd5145SBarry Smith ierr = PetscTypeCompare((PetscObject)mat,matype,&sametype);CHKERRQ(ierr); 5035d8aa7fSBarry Smith if (!sametype) { 5199cd5145SBarry Smith /* Get the function pointers for the matrix requested */ 5299cd5145SBarry Smith if (!MatRegisterAllCalled) {ierr = MatRegisterAll(PETSC_NULL);CHKERRQ(ierr);} 53c134de8dSSatish Balay ierr = PetscFListFind(mat->comm,MatList,matype,(void(**)(void))&r);CHKERRQ(ierr); 5429bbc08cSBarry Smith if (!r) SETERRQ1(1,"Unknown Mat type given: %s",matype); 557e14e8a7SBarry Smith 5635d8aa7fSBarry Smith /* free the old data structure if it existed */ 5735d8aa7fSBarry Smith if (mat->ops->destroy) { 58*a2ec6df8SKris Buschelman MatPreallocated(mat); 5935d8aa7fSBarry Smith ierr = (*mat->ops->destroy)(mat);CHKERRQ(ierr); 600dd8e64fSKris Buschelman mat->ops->destroy = PETSC_NULL; 61*a2ec6df8SKris Buschelman mat->preallocated = PETSC_FALSE; 6235d8aa7fSBarry Smith } 63*a2ec6df8SKris Buschelman 6435d8aa7fSBarry Smith if (mat->rmap) { 658a124369SBarry Smith ierr = PetscMapDestroy(mat->rmap);CHKERRQ(ierr); 6635d8aa7fSBarry Smith mat->rmap = 0; 6735d8aa7fSBarry Smith } 6835d8aa7fSBarry Smith if (mat->cmap) { 698a124369SBarry Smith ierr = PetscMapDestroy(mat->cmap);CHKERRQ(ierr); 7035d8aa7fSBarry Smith mat->cmap = 0; 7135d8aa7fSBarry Smith } 725694455fSKris Buschelman if (mat->qlist) { 735694455fSKris Buschelman ierr = PetscFListDestroy(&mat->qlist);CHKERRQ(ierr); 745694455fSKris Buschelman mat->qlist = 0; 755694455fSKris Buschelman } 765694455fSKris Buschelman if (mat->olist) { 775694455fSKris Buschelman ierr = PetscOListDestroy(&mat->olist);CHKERRQ(ierr); 785694455fSKris Buschelman mat->olist = 0; 795694455fSKris Buschelman } 8035d8aa7fSBarry Smith /* create the new data structure */ 8199cd5145SBarry Smith ierr = (*r)(mat);CHKERRQ(ierr); 827e14e8a7SBarry Smith 83b9b97703SBarry Smith ierr = PetscObjectChangeTypeName((PetscObject)mat,matype);CHKERRQ(ierr); 8435d8aa7fSBarry Smith } 8535d8aa7fSBarry Smith ierr = PetscPublishAll(mat);CHKERRQ(ierr); 867e14e8a7SBarry Smith PetscFunctionReturn(0); 877e14e8a7SBarry Smith } 887e14e8a7SBarry Smith 8935d8aa7fSBarry Smith 904a2ae208SSatish Balay #undef __FUNCT__ 914a2ae208SSatish Balay #define __FUNCT__ "MatRegisterDestroy" 927e14e8a7SBarry Smith /*@C 9399cd5145SBarry Smith MatRegisterDestroy - Frees the list of matrix types that were 943cea93caSBarry Smith registered by MatRegister()/MatRegisterDynamic(). 957e14e8a7SBarry Smith 967e14e8a7SBarry Smith Not Collective 977e14e8a7SBarry Smith 987e14e8a7SBarry Smith Level: advanced 997e14e8a7SBarry Smith 10099cd5145SBarry Smith .keywords: Mat, register, destroy 1017e14e8a7SBarry Smith 1023cea93caSBarry Smith .seealso: MatRegister(), MatRegisterAll(), MatRegisterDynamic() 1037e14e8a7SBarry Smith @*/ 10499cd5145SBarry Smith int MatRegisterDestroy(void) 1057e14e8a7SBarry Smith { 1067e14e8a7SBarry Smith int ierr; 1077e14e8a7SBarry Smith 1087e14e8a7SBarry Smith PetscFunctionBegin; 10999cd5145SBarry Smith if (MatList) { 110b0a32e0cSBarry Smith ierr = PetscFListDestroy(&MatList);CHKERRQ(ierr); 11199cd5145SBarry Smith MatList = 0; 1127e14e8a7SBarry Smith } 1130e9836bfSBarry Smith MatRegisterAllCalled = PETSC_FALSE; 1147e14e8a7SBarry Smith PetscFunctionReturn(0); 1157e14e8a7SBarry Smith } 1167e14e8a7SBarry Smith 1174a2ae208SSatish Balay #undef __FUNCT__ 1184a2ae208SSatish Balay #define __FUNCT__ "MatGetType" 1197e14e8a7SBarry Smith /*@C 120f87b78b8SBarry Smith MatGetType - Gets the matrix type as a string from the matrix object. 1217e14e8a7SBarry Smith 1227e14e8a7SBarry Smith Not Collective 1237e14e8a7SBarry Smith 1247e14e8a7SBarry Smith Input Parameter: 12599cd5145SBarry Smith . mat - the matrix 1267e14e8a7SBarry Smith 1277e14e8a7SBarry Smith Output Parameter: 12899cd5145SBarry Smith . name - name of matrix type 1297e14e8a7SBarry Smith 1307e14e8a7SBarry Smith Level: intermediate 1317e14e8a7SBarry Smith 13299cd5145SBarry Smith .keywords: Mat, get, method, name 1337e14e8a7SBarry Smith 13499cd5145SBarry Smith .seealso: MatSetType() 1357e14e8a7SBarry Smith @*/ 136273d9f13SBarry Smith int MatGetType(Mat mat,MatType *type) 1377e14e8a7SBarry Smith { 1387e14e8a7SBarry Smith PetscFunctionBegin; 13999cd5145SBarry Smith *type = mat->type_name; 1407e14e8a7SBarry Smith PetscFunctionReturn(0); 1417e14e8a7SBarry Smith } 1427e14e8a7SBarry Smith 1437e14e8a7SBarry Smith 1444a2ae208SSatish Balay #undef __FUNCT__ 1454a2ae208SSatish Balay #define __FUNCT__ "MatRegister" 1463cea93caSBarry Smith /*@C 1473cea93caSBarry Smith MatRegister - See MatRegisterDynamic() 1483cea93caSBarry Smith 1497f6c08e0SMatthew Knepley Level: advanced 1503cea93caSBarry Smith @*/ 15199cd5145SBarry Smith int MatRegister(char *sname,char *path,char *name,int (*function)(Mat)) 1527e14e8a7SBarry Smith { 1537e14e8a7SBarry Smith int ierr; 154e10c49a3SBarry Smith char fullname[PETSC_MAX_PATH_LEN]; 1557e14e8a7SBarry Smith 1567e14e8a7SBarry Smith PetscFunctionBegin; 157b0a32e0cSBarry Smith ierr = PetscFListConcat(path,name,fullname);CHKERRQ(ierr); 158c134de8dSSatish Balay ierr = PetscFListAdd(&MatList,sname,fullname,(void (*)(void))function);CHKERRQ(ierr); 15999cd5145SBarry Smith PetscFunctionReturn(0); 16099cd5145SBarry Smith } 16199cd5145SBarry Smith 16299cd5145SBarry Smith 16399cd5145SBarry Smith 16499cd5145SBarry Smith 165273d9f13SBarry Smith 166273d9f13SBarry Smith 167273d9f13SBarry Smith 168273d9f13SBarry Smith 169273d9f13SBarry Smith 170273d9f13SBarry Smith 171