1 #define PETSCDM_DLL 2 3 #include "private/daimpl.h" /*I "petscda.h" I*/ 4 5 PetscFList DAList = PETSC_NULL; 6 PetscBool DARegisterAllCalled = PETSC_FALSE; 7 8 #undef __FUNCT__ 9 #define __FUNCT__ "DASetType" 10 /*@C 11 DASetType - Builds a DA, for a particular DA implementation. 12 13 Collective on DA 14 15 Input Parameters: 16 + da - The DA object 17 - method - The name of the DA type 18 19 Options Database Key: 20 . -da_type <type> - Sets the DA type; use -help for a list of available types 21 22 Notes: 23 See "petsc/include/petscda.h" for available DA types (for instance, DA1D, DA2D, or DA3D). 24 25 Level: intermediate 26 27 .keywords: DA, set, type 28 .seealso: DAGetType(), DACreate() 29 @*/ 30 PetscErrorCode PETSCDM_DLLEXPORT DASetType(DA da, const DAType method) 31 { 32 PetscErrorCode (*r)(DA); 33 PetscBool match; 34 PetscErrorCode ierr; 35 36 PetscFunctionBegin; 37 PetscValidHeaderSpecific(da, DM_CLASSID,1); 38 ierr = PetscTypeCompare((PetscObject) da, method, &match);CHKERRQ(ierr); 39 if (match) PetscFunctionReturn(0); 40 41 if (!DARegisterAllCalled) {ierr = DARegisterAll(PETSC_NULL);CHKERRQ(ierr);} 42 ierr = PetscFListFind(DAList, ((PetscObject)da)->comm, method,(void (**)(void)) &r);CHKERRQ(ierr); 43 if (!r) SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_ARG_UNKNOWN_TYPE, "Unknown DA type: %s", method); 44 45 /* if (da->ops->destroy) { 46 ierr = (*da->ops->destroy)(da);CHKERRQ(ierr); 47 } */ 48 ierr = (*r)(da);CHKERRQ(ierr); 49 ierr = PetscObjectChangeTypeName((PetscObject)da,method);CHKERRQ(ierr); 50 PetscFunctionReturn(0); 51 } 52 53 #undef __FUNCT__ 54 #define __FUNCT__ "DAGetType" 55 /*@C 56 DAGetType - Gets the DA type name (as a string) from the DA. 57 58 Not Collective 59 60 Input Parameter: 61 . da - The DA 62 63 Output Parameter: 64 . type - The DA type name 65 66 Level: intermediate 67 68 .keywords: DA, get, type, name 69 .seealso: DASetType(), DACreate() 70 @*/ 71 PetscErrorCode PETSCDM_DLLEXPORT DAGetType(DA da, const DAType *type) 72 { 73 PetscErrorCode ierr; 74 75 PetscFunctionBegin; 76 PetscValidHeaderSpecific(da, DM_CLASSID,1); 77 PetscValidCharPointer(type,2); 78 if (!DARegisterAllCalled) { 79 ierr = DARegisterAll(PETSC_NULL);CHKERRQ(ierr); 80 } 81 *type = ((PetscObject)da)->type_name; 82 PetscFunctionReturn(0); 83 } 84 85 86 /*--------------------------------------------------------------------------------------------------------------------*/ 87 88 #undef __FUNCT__ 89 #define __FUNCT__ "DARegister" 90 /*@C 91 DARegister - See DARegisterDynamic() 92 93 Level: advanced 94 @*/ 95 PetscErrorCode PETSCDM_DLLEXPORT DARegister(const char sname[], const char path[], const char name[], PetscErrorCode (*function)(DA)) 96 { 97 char fullname[PETSC_MAX_PATH_LEN]; 98 PetscErrorCode ierr; 99 100 PetscFunctionBegin; 101 ierr = PetscStrcpy(fullname, path);CHKERRQ(ierr); 102 ierr = PetscStrcat(fullname, ":");CHKERRQ(ierr); 103 ierr = PetscStrcat(fullname, name);CHKERRQ(ierr); 104 ierr = PetscFListAdd(&DAList, sname, fullname, (void (*)(void)) function);CHKERRQ(ierr); 105 PetscFunctionReturn(0); 106 } 107 108 109 /*--------------------------------------------------------------------------------------------------------------------*/ 110 #undef __FUNCT__ 111 #define __FUNCT__ "DARegisterDestroy" 112 /*@C 113 DARegisterDestroy - Frees the list of DA methods that were registered by DARegister()/DARegisterDynamic(). 114 115 Not Collective 116 117 Level: advanced 118 119 .keywords: DA, register, destroy 120 .seealso: DARegister(), DARegisterAll(), DARegisterDynamic() 121 @*/ 122 PetscErrorCode PETSCDM_DLLEXPORT DARegisterDestroy(void) 123 { 124 PetscErrorCode ierr; 125 126 PetscFunctionBegin; 127 ierr = PetscFListDestroy(&DAList);CHKERRQ(ierr); 128 DARegisterAllCalled = PETSC_FALSE; 129 PetscFunctionReturn(0); 130 } 131