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