1 #ifdef PETSC_RCS_HEADER 2 static char vcid[] = "$Id: matreg.c,v 1.18 2001/07/20 21:19:21 bsmith Exp $"; 3 #endif 4 /* 5 Mechanism for register PETSc matrix types 6 */ 7 #include "src/mat/matimpl.h" /*I "petscmat.h" I*/ 8 #include "petscsys.h" 9 10 PetscTruth MatRegisterAllCalled = PETSC_FALSE; 11 12 /* 13 Contains the list of registered Mat routines 14 */ 15 PetscFList MatList = 0; 16 17 #undef __FUNCT__ 18 #define __FUNCT__ "MatSetType" 19 /*@C 20 MatSetType - Builds matrix object for a particular matrix type 21 22 Collective on Mat 23 24 Input Parameters: 25 + mat - the matrix object 26 - matype - matrix type 27 28 Options Database Key: 29 . -mat_type <method> - Sets the type; use -help for a list 30 of available methods (for instance, seqaij) 31 32 Notes: 33 See "${PETSC_DIR}/include/petscmat.h" for available methods 34 35 Level: intermediate 36 37 .keywords: Mat, set, method 38 39 .seealso: PCSetType(), VecSetType(), MatCreate(), MatType, Mat 40 @*/ 41 int MatSetType(Mat mat,MatType matype) 42 { 43 int ierr,(*r)(Mat); 44 PetscTruth sametype; 45 46 PetscFunctionBegin; 47 PetscValidHeaderSpecific(mat,MAT_COOKIE); 48 49 ierr = PetscTypeCompare((PetscObject)mat,matype,&sametype);CHKERRQ(ierr); 50 if (!sametype) { 51 MatPreallocated(mat); 52 /* Get the function pointers for the matrix requested */ 53 if (!MatRegisterAllCalled) {ierr = MatRegisterAll(PETSC_NULL);CHKERRQ(ierr);} 54 ierr = PetscFListFind(mat->comm,MatList,matype,(void(**)(void))&r);CHKERRQ(ierr); 55 if (!r) SETERRQ1(1,"Unknown Mat type given: %s",matype); 56 57 /* free the old data structure if it existed */ 58 if (mat->ops->destroy) { 59 ierr = (*mat->ops->destroy)(mat);CHKERRQ(ierr); 60 mat->ops->destroy = PETSC_NULL; 61 } 62 if (mat->rmap) { 63 ierr = PetscMapDestroy(mat->rmap);CHKERRQ(ierr); 64 mat->rmap = 0; 65 } 66 if (mat->cmap) { 67 ierr = PetscMapDestroy(mat->cmap);CHKERRQ(ierr); 68 mat->cmap = 0; 69 } 70 if (mat->qlist) { 71 ierr = PetscFListDestroy(&mat->qlist);CHKERRQ(ierr); 72 mat->qlist = 0; 73 } 74 if (mat->olist) { 75 ierr = PetscOListDestroy(&mat->olist);CHKERRQ(ierr); 76 mat->olist = 0; 77 } 78 /* create the new data structure */ 79 ierr = (*r)(mat);CHKERRQ(ierr); 80 81 ierr = PetscObjectChangeTypeName((PetscObject)mat,matype);CHKERRQ(ierr); 82 } 83 ierr = PetscPublishAll(mat);CHKERRQ(ierr); 84 PetscFunctionReturn(0); 85 } 86 87 88 #undef __FUNCT__ 89 #define __FUNCT__ "MatRegisterDestroy" 90 /*@C 91 MatRegisterDestroy - Frees the list of matrix types that were 92 registered by MatRegister()/MatRegisterDynamic(). 93 94 Not Collective 95 96 Level: advanced 97 98 .keywords: Mat, register, destroy 99 100 .seealso: MatRegister(), MatRegisterAll(), MatRegisterDynamic() 101 @*/ 102 int MatRegisterDestroy(void) 103 { 104 int ierr; 105 106 PetscFunctionBegin; 107 if (MatList) { 108 ierr = PetscFListDestroy(&MatList);CHKERRQ(ierr); 109 MatList = 0; 110 } 111 MatRegisterAllCalled = PETSC_FALSE; 112 PetscFunctionReturn(0); 113 } 114 115 #undef __FUNCT__ 116 #define __FUNCT__ "MatGetType" 117 /*@C 118 MatGetType - Gets the matrix type as a string from the matrix object. 119 120 Not Collective 121 122 Input Parameter: 123 . mat - the matrix 124 125 Output Parameter: 126 . name - name of matrix type 127 128 Level: intermediate 129 130 .keywords: Mat, get, method, name 131 132 .seealso: MatSetType() 133 @*/ 134 int MatGetType(Mat mat,MatType *type) 135 { 136 PetscFunctionBegin; 137 *type = mat->type_name; 138 PetscFunctionReturn(0); 139 } 140 141 142 #undef __FUNCT__ 143 #define __FUNCT__ "MatRegister" 144 /*@C 145 MatRegister - See MatRegisterDynamic() 146 147 Level: advanced 148 @*/ 149 int MatRegister(char *sname,char *path,char *name,int (*function)(Mat)) 150 { 151 int ierr; 152 char fullname[PETSC_MAX_PATH_LEN]; 153 154 PetscFunctionBegin; 155 ierr = PetscFListConcat(path,name,fullname);CHKERRQ(ierr); 156 ierr = PetscFListAdd(&MatList,sname,fullname,(void (*)(void))function);CHKERRQ(ierr); 157 PetscFunctionReturn(0); 158 } 159 160 161 162 163 164 165 166 167 168 169