1 #define PETSCMAT_DLL 2 3 /* 4 Mechanism for register PETSc matrix types 5 */ 6 #include "include/private/matimpl.h" /*I "petscmat.h" I*/ 7 #include "petscsys.h" 8 9 PetscTruth MatRegisterAllCalled = PETSC_FALSE; 10 11 /* 12 Contains the list of registered Mat routines 13 */ 14 PetscFList MatList = 0; 15 16 #undef __FUNCT__ 17 #define __FUNCT__ "MatSetType" 18 /*@C 19 MatSetType - Builds matrix object for a particular matrix type 20 21 Collective on Mat 22 23 Input Parameters: 24 + mat - the matrix object 25 - matype - matrix type 26 27 Options Database Key: 28 . -mat_type <method> - Sets the type; use -help for a list 29 of available methods (for instance, seqaij) 30 31 Notes: 32 See "${PETSC_DIR}/include/petscmat.h" for available methods 33 34 Level: intermediate 35 36 .keywords: Mat, MatType, set, method 37 38 .seealso: PCSetType(), VecSetType(), MatCreate(), MatType, Mat 39 @*/ 40 PetscErrorCode PETSCMAT_DLLEXPORT MatSetType(Mat mat, MatType matype) 41 { 42 PetscErrorCode ierr,(*r)(Mat); 43 PetscTruth sametype; 44 45 PetscFunctionBegin; 46 PetscValidHeaderSpecific(mat,MAT_COOKIE,1); 47 if (mat->rmap.n < 0 && mat->rmap.N < 0 && mat->cmap.n < 0 && mat->cmap.N < 0) SETERRQ(PETSC_ERR_ARG_WRONGSTATE,"Must call MatSetSizes() first"); 48 ierr = PetscTypeCompare((PetscObject)mat,matype,&sametype);CHKERRQ(ierr); 49 if (sametype) PetscFunctionReturn(0); 50 51 ierr = PetscFListFind(mat->comm,MatList,matype,(void(**)(void))&r);CHKERRQ(ierr); 52 if (!r) SETERRQ1(PETSC_ERR_ARG_UNKNOWN_TYPE,"Unknown Mat type given: %s",matype); 53 54 /* free the old data structure if it existed */ 55 if (mat->ops->destroy) { 56 ierr = MatPreallocated(mat);CHKERRQ(ierr); 57 ierr = (*mat->ops->destroy)(mat);CHKERRQ(ierr); 58 mat->ops->destroy = PETSC_NULL; 59 mat->preallocated = PETSC_FALSE; 60 } 61 62 /* create the new data structure */ 63 ierr = (*r)(mat);CHKERRQ(ierr); 64 ierr = PetscPublishAll(mat);CHKERRQ(ierr); 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 PETSCMAT_DLLEXPORT MatRegisterDestroy(void) 84 { 85 PetscErrorCode ierr; 86 87 PetscFunctionBegin; 88 if (MatList) { 89 ierr = PetscFListDestroy(MatList);CHKERRQ(ierr); 90 MatList = 0; 91 } 92 MatRegisterAllCalled = PETSC_FALSE; 93 PetscFunctionReturn(0); 94 } 95 96 #undef __FUNCT__ 97 #define __FUNCT__ "MatGetType" 98 /*@C 99 MatGetType - Gets the matrix type as a string from the matrix object. 100 101 Not Collective 102 103 Input Parameter: 104 . mat - the matrix 105 106 Output Parameter: 107 . name - name of matrix type 108 109 Level: intermediate 110 111 .keywords: Mat, MatType, get, method, name 112 113 .seealso: MatSetType() 114 @*/ 115 PetscErrorCode PETSCMAT_DLLEXPORT MatGetType(Mat mat,MatType *type) 116 { 117 PetscFunctionBegin; 118 *type = 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 PETSCMAT_DLLEXPORT 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