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 ierr = PetscPublishAll(mat);CHKERRQ(ierr); 63 PetscFunctionReturn(0); 64 } 65 66 67 #undef __FUNCT__ 68 #define __FUNCT__ "MatRegisterDestroy" 69 /*@C 70 MatRegisterDestroy - Frees the list of matrix types that were 71 registered by MatRegister()/MatRegisterDynamic(). 72 73 Not Collective 74 75 Level: advanced 76 77 .keywords: Mat, register, destroy 78 79 .seealso: MatRegister(), MatRegisterAll(), MatRegisterDynamic() 80 @*/ 81 PetscErrorCode PETSCMAT_DLLEXPORT MatRegisterDestroy(void) 82 { 83 PetscErrorCode ierr; 84 85 PetscFunctionBegin; 86 ierr = PetscFListDestroy(&MatList);CHKERRQ(ierr); 87 MatRegisterAllCalled = PETSC_FALSE; 88 PetscFunctionReturn(0); 89 } 90 91 #undef __FUNCT__ 92 #define __FUNCT__ "MatGetType" 93 /*@C 94 MatGetType - Gets the matrix type as a string from the matrix object. 95 96 Not Collective 97 98 Input Parameter: 99 . mat - the matrix 100 101 Output Parameter: 102 . name - name of matrix type 103 104 Level: intermediate 105 106 .keywords: Mat, MatType, get, method, name 107 108 .seealso: MatSetType() 109 @*/ 110 PetscErrorCode PETSCMAT_DLLEXPORT MatGetType(Mat mat,const MatType *type) 111 { 112 PetscFunctionBegin; 113 PetscValidHeaderSpecific(mat,MAT_CLASSID,1); 114 PetscValidPointer(type,2); 115 *type = ((PetscObject)mat)->type_name; 116 PetscFunctionReturn(0); 117 } 118 119 120 #undef __FUNCT__ 121 #define __FUNCT__ "MatRegister" 122 /*@C 123 MatRegister - See MatRegisterDynamic() 124 125 Level: advanced 126 @*/ 127 PetscErrorCode PETSCMAT_DLLEXPORT MatRegister(const char sname[],const char path[],const char name[],PetscErrorCode (*function)(Mat)) 128 { 129 PetscErrorCode ierr; 130 char fullname[PETSC_MAX_PATH_LEN]; 131 132 PetscFunctionBegin; 133 ierr = PetscFListConcat(path,name,fullname);CHKERRQ(ierr); 134 ierr = PetscFListAdd(&MatList,sname,fullname,(void (*)(void))function);CHKERRQ(ierr); 135 PetscFunctionReturn(0); 136 } 137 138 139 140 141 142 143 144 145 146 147