1 #include <petsc-private/dmforestimpl.h> 2 #include <petsc-private/dmimpl.h> 3 #include <petscsf.h> /*I "petscsf.h" */ 4 5 #undef __FUNCT__ 6 #define __FUNCT__ "DMClone_Forest" 7 PETSC_EXTERN PetscErrorCode DMClone_Forest(DM dm, DM *newdm) 8 { 9 DM_Forest *forest = (DM_Forest *) dm->data; 10 const char *type; 11 PetscErrorCode ierr; 12 13 PetscFunctionBegin; 14 forest->refct++; 15 (*newdm)->data = forest; 16 ierr = PetscObjectGetType((PetscObject) dm, &type);CHKERRQ(ierr); 17 ierr = PetscObjectChangeTypeName((PetscObject) *newdm, type);CHKERRQ(ierr); 18 ierr = DMInitialize_Forest(*newdm);CHKERRQ(ierr); 19 PetscFunctionReturn(0); 20 } 21 22 #undef __FUNCT__ 23 #define __FUNCT__ "DMDestroy_Forest" 24 PetscErrorCode DMDestroy_Forest(DM dm) 25 { 26 DM_Forest *forest = (DM_Forest*) dm->data; 27 PetscErrorCode ierr; 28 29 PetscFunctionBegin; 30 if (--forest->refct > 0) PetscFunctionReturn(0); 31 ierr = PetscSFDestroy(&forest->cellSF);CHKERRQ(ierr); 32 if (forest->adaptCopyMode == PETSC_OWN_POINTER) { 33 ierr = PetscFree(forest->adaptMarkers);CHKERRQ(ierr); 34 } 35 if (forest->cellWeightsCopyMode == PETSC_OWN_POINTER) { 36 ierr = PetscFree(forest->cellWeights);CHKERRQ(ierr); 37 } 38 PetscFunctionReturn(0); 39 } 40 41 42 #undef __FUNCT__ 43 #define __FUNCT__ "DMForestSetType" 44 PetscErrorCode DMForestSetType(DM dm, DMForestType type) 45 { 46 DM_Forest *forest = (DM_Forest *) dm->data; 47 PetscBool isSame; 48 PetscErrorCode ierr; 49 50 PetscFunctionBegin; 51 PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 52 if (!type && !forest->type) { 53 isSame = PETSC_TRUE; 54 } 55 else if (!type || !forest->type) { 56 isSame = PETSC_FALSE; 57 } 58 else { 59 ierr = PetscStrcmp((char*)(forest->type),(char*)type,&isSame);CHKERRQ(ierr); 60 } 61 if (!isSame) { 62 ierr = DMForestReset(dm);CHKERRQ(ierr); 63 } 64 PetscFunctionReturn(0); 65 } 66 67 #undef __FUNCT__ 68 #define __FUNCT__ "DMSetFromOptions_Forest" 69 PetscErrorCode DMSetFromFromOptions_Forest(DM dm) 70 { 71 DM_Forest *forest = (DM_Forest *) dm->data; 72 PetscErrorCode ierr; 73 74 PetscFunctionBegin; 75 PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 76 forest->setFromOptions = PETSC_TRUE; 77 ierr = PetscOptionsHead("DMForest Options");CHKERRQ(ierr); 78 ierr = PetscOptionsFList("-dm_forest_type","DMForest type","DMForestSetType",DMForestList,(char*)(forest->type ? forest->type : DMFORESTP4EST),forest->type,256,&flg);CHKERRQ(ierr); 79 if (flg) { 80 ierr = DMForestSetType(dm,forest->type);CHKERRQ(ierr); 81 } 82 ierr = PetscOptionsTail();CHKERRQ(ierr); 83 PetscFunctionReturn(0); 84 } 85 86 #undef __FUNCT__ 87 #define __FUNCT__ "DMInitialize_Forest" 88 PetscErrorCode DMInitialize_Forest(DM dm) 89 { 90 PetscErrorCode ierr; 91 92 PetscFunctionBegin; 93 ierr = PetscMemzero(dm->ops, sizeof (*(dm->ops)));CHKERRQ(ierr); 94 dm->ops->setfromoptions = DMSetFromOptions_Forest; 95 dm->ops->destroy = DMDestroy_Forest; 96 PetscFunctionReturn(0); 97 } 98 99 #undef __FUNCT__ 100 #define __FUNCT__ "DMCreate_Forest" 101 PETSC_EXTERN PetscErrorCode DMCreate_Forest(DM dm) 102 { 103 DM_Forest *forest; 104 PetscErrorCode ierr; 105 106 PetscFunctionBegin; 107 PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 108 ierr = PetscNewLog(dm,&forest);CHKERRQ(ierr); 109 dm->dim = 0; 110 dm->data = forest; 111 forest->refct = 1; 112 forest->data = NULL; 113 forest->setup = 0; 114 forest->type = NULL; 115 forest->topology = NULL; 116 forest->base = NULL; 117 forest->coarse = NULL; 118 forest->fine = NULL; 119 forest->adjDim = PETSC_DEFAULT; 120 forest->overlap = PETSC_DEFAULT; 121 forest->minRefinement = PETSC_DEFAULT; 122 forest->maxRefinement = PETSC_DEFAULT; 123 forest->cStart = 0; 124 forest->cEnd = 0; 125 forest->cellSF = 0; 126 forest->adaptMarkers = NULL; 127 forest->adaptCopyMode = PETSC_USE_POINTER; 128 forest->adaptStrategy = DMFORESTADAPTALL; 129 forest->gradeFactor = 2; 130 forest->cellWeights = NULL; 131 forest->cellWeightsCopyMode = PETSC_USE_POINTER; 132 forest->weightsFactor = 1.; 133 forest->weightCapacity = 1.; 134 ierr = DMInitialize_Forest(dm);CHKERRQ(ierr); 135 PetscFunctionReturn(0); 136 } 137 138