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