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