1fbbfd472SToby Isaac #include <petsc/private/dmforestimpl.h> /*I petscdmforest.h I*/ 2fbbfd472SToby Isaac #include <petsc/private/dmimpl.h> /*I petscdm.h */ 3ef19d27cSToby Isaac #include <petscsf.h> 4db4d5e8cSToby Isaac 5db4d5e8cSToby Isaac #undef __FUNCT__ 6a0452a8eSToby Isaac #define __FUNCT__ "DMForestTemplate" 7a0452a8eSToby Isaac PETSC_EXTERN PetscErrorCode DMForestTemplate(DM dm, DM tdm) 8a0452a8eSToby Isaac { 9a0452a8eSToby Isaac DM_Forest *forest = (DM_Forest *) dm->data; 10a0452a8eSToby Isaac DM base; 11a0452a8eSToby Isaac DMForestTopology topology; 12a0452a8eSToby Isaac PetscInt dim, overlap, ref, factor; 13a0452a8eSToby Isaac DMForestAdaptivityStrategy strat; 14a0452a8eSToby Isaac PetscErrorCode ierr; 15a0452a8eSToby Isaac 16a0452a8eSToby Isaac PetscFunctionBegin; 17a0452a8eSToby Isaac PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 18a0452a8eSToby Isaac PetscValidHeaderSpecific(tdm, DM_CLASSID, 2); 19a0452a8eSToby Isaac ierr = DMForestGetBaseDM(dm,&base);CHKERRQ(ierr); 20a0452a8eSToby Isaac ierr = DMForestSetBaseDM(tdm,base);CHKERRQ(ierr); 21a0452a8eSToby Isaac ierr = DMForestGetTopology(dm,&topology);CHKERRQ(ierr); 22a0452a8eSToby Isaac ierr = DMForestSetTopology(tdm,topology);CHKERRQ(ierr); 23a0452a8eSToby Isaac ierr = DMForestGetAdjacencyDimension(dm,&dim);CHKERRQ(ierr); 24a0452a8eSToby Isaac ierr = DMForestSetAdjacencyDimension(tdm,dim);CHKERRQ(ierr); 25a0452a8eSToby Isaac ierr = DMForestGetPartitionOverlap(dm,&overlap);CHKERRQ(ierr); 26a0452a8eSToby Isaac ierr = DMForestSetPartitionOverlap(tdm,overlap);CHKERRQ(ierr); 27a0452a8eSToby Isaac ierr = DMForestGetMinimumRefinement(dm,&ref);CHKERRQ(ierr); 28a0452a8eSToby Isaac ierr = DMForestSetMinimumRefinement(tdm,ref);CHKERRQ(ierr); 29a0452a8eSToby Isaac ierr = DMForestGetInitialRefinement(dm,&ref);CHKERRQ(ierr); 30a0452a8eSToby Isaac ierr = DMForestSetInitialRefinement(tdm,ref);CHKERRQ(ierr); 31a0452a8eSToby Isaac ierr = DMForestGetMaximumRefinement(dm,&ref);CHKERRQ(ierr); 32a0452a8eSToby Isaac ierr = DMForestSetMaximumRefinement(tdm,ref);CHKERRQ(ierr); 33a0452a8eSToby Isaac ierr = DMForestGetAdaptivityStrategy(dm,&strat);CHKERRQ(ierr); 34a0452a8eSToby Isaac ierr = DMForestSetAdaptivityStrategy(tdm,strat);CHKERRQ(ierr); 35a0452a8eSToby Isaac ierr = DMForestGetGradeFactor(dm,&factor);CHKERRQ(ierr); 36a0452a8eSToby Isaac ierr = DMForestSetGradeFactor(tdm,factor);CHKERRQ(ierr); 37a0452a8eSToby Isaac if (forest->ftemplate) { 38a0452a8eSToby Isaac ierr = (forest->ftemplate) (dm, tdm);CHKERRQ(ierr); 39a0452a8eSToby Isaac } 40a0452a8eSToby Isaac PetscFunctionReturn(0); 41a0452a8eSToby Isaac } 42a0452a8eSToby Isaac 43a0452a8eSToby Isaac #undef __FUNCT__ 44db4d5e8cSToby Isaac #define __FUNCT__ "DMClone_Forest" 45db4d5e8cSToby Isaac PETSC_EXTERN PetscErrorCode DMClone_Forest(DM dm, DM *newdm) 46db4d5e8cSToby Isaac { 47db4d5e8cSToby Isaac DM_Forest *forest = (DM_Forest *) dm->data; 48db4d5e8cSToby Isaac const char *type; 49db4d5e8cSToby Isaac PetscErrorCode ierr; 50db4d5e8cSToby Isaac 51db4d5e8cSToby Isaac PetscFunctionBegin; 52db4d5e8cSToby Isaac forest->refct++; 53db4d5e8cSToby Isaac (*newdm)->data = forest; 54db4d5e8cSToby Isaac ierr = PetscObjectGetType((PetscObject) dm, &type);CHKERRQ(ierr); 55db4d5e8cSToby Isaac ierr = PetscObjectChangeTypeName((PetscObject) *newdm, type);CHKERRQ(ierr); 56db4d5e8cSToby Isaac PetscFunctionReturn(0); 57db4d5e8cSToby Isaac } 58db4d5e8cSToby Isaac 59db4d5e8cSToby Isaac #undef __FUNCT__ 60db4d5e8cSToby Isaac #define __FUNCT__ "DMDestroy_Forest" 61d222f98bSToby Isaac static PetscErrorCode DMDestroy_Forest(DM dm) 62db4d5e8cSToby Isaac { 63db4d5e8cSToby Isaac DM_Forest *forest = (DM_Forest*) dm->data; 64db4d5e8cSToby Isaac PetscErrorCode ierr; 65db4d5e8cSToby Isaac 66db4d5e8cSToby Isaac PetscFunctionBegin; 67db4d5e8cSToby Isaac if (--forest->refct > 0) PetscFunctionReturn(0); 68d222f98bSToby Isaac if (forest->destroy) {ierr = forest->destroy(dm);CHKERRQ(ierr);} 69db4d5e8cSToby Isaac ierr = PetscSFDestroy(&forest->cellSF);CHKERRQ(ierr); 70db4d5e8cSToby Isaac if (forest->adaptCopyMode == PETSC_OWN_POINTER) { 71db4d5e8cSToby Isaac ierr = PetscFree(forest->adaptMarkers);CHKERRQ(ierr); 72db4d5e8cSToby Isaac } 73db4d5e8cSToby Isaac if (forest->cellWeightsCopyMode == PETSC_OWN_POINTER) { 74db4d5e8cSToby Isaac ierr = PetscFree(forest->cellWeights);CHKERRQ(ierr); 75db4d5e8cSToby Isaac } 7656ba9f64SToby Isaac ierr = DMDestroy(&forest->base);CHKERRQ(ierr); 7730f902e7SToby Isaac ierr = PetscFree(forest->topology);CHKERRQ(ierr); 7830f902e7SToby Isaac ierr = PetscFree(forest);CHKERRQ(ierr); 79db4d5e8cSToby Isaac PetscFunctionReturn(0); 80db4d5e8cSToby Isaac } 81db4d5e8cSToby Isaac 82db4d5e8cSToby Isaac #undef __FUNCT__ 83dd8e54a2SToby Isaac #define __FUNCT__ "DMForestSetTopology" 84dd8e54a2SToby Isaac PetscErrorCode DMForestSetTopology(DM dm, DMForestTopology topology) 85db4d5e8cSToby Isaac { 86db4d5e8cSToby Isaac DM_Forest *forest = (DM_Forest *) dm->data; 87db4d5e8cSToby Isaac PetscErrorCode ierr; 88db4d5e8cSToby Isaac 89db4d5e8cSToby Isaac PetscFunctionBegin; 90db4d5e8cSToby Isaac PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 91ef51cf95SToby Isaac if (dm->setupcalled) SETERRQ(PetscObjectComm((PetscObject)dm),PETSC_ERR_ARG_WRONGSTATE,"Cannot change the topology after setup"); 92dd8e54a2SToby Isaac ierr = PetscFree(forest->topology);CHKERRQ(ierr); 93dd8e54a2SToby Isaac ierr = PetscStrallocpy((const char *)topology,(char **) &forest->topology);CHKERRQ(ierr); 94db4d5e8cSToby Isaac PetscFunctionReturn(0); 95db4d5e8cSToby Isaac } 96db4d5e8cSToby Isaac 97db4d5e8cSToby Isaac #undef __FUNCT__ 98dd8e54a2SToby Isaac #define __FUNCT__ "DMForestGetTopology" 99dd8e54a2SToby Isaac PetscErrorCode DMForestGetTopology(DM dm, DMForestTopology *topology) 100dd8e54a2SToby Isaac { 101dd8e54a2SToby Isaac DM_Forest *forest = (DM_Forest *) dm->data; 102dd8e54a2SToby Isaac 103dd8e54a2SToby Isaac PetscFunctionBegin; 104dd8e54a2SToby Isaac PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 105dd8e54a2SToby Isaac PetscValidPointer(topology,2); 106dd8e54a2SToby Isaac *topology = forest->topology; 107dd8e54a2SToby Isaac PetscFunctionReturn(0); 108dd8e54a2SToby Isaac } 109dd8e54a2SToby Isaac 110dd8e54a2SToby Isaac #undef __FUNCT__ 111dd8e54a2SToby Isaac #define __FUNCT__ "DMForestSetBaseDM" 112dd8e54a2SToby Isaac PetscErrorCode DMForestSetBaseDM(DM dm, DM base) 113dd8e54a2SToby Isaac { 114dd8e54a2SToby Isaac DM_Forest *forest = (DM_Forest *) dm->data; 115dd8e54a2SToby Isaac PetscInt dim, dimEmbed; 116dd8e54a2SToby Isaac PetscErrorCode ierr; 117dd8e54a2SToby Isaac 118dd8e54a2SToby Isaac PetscFunctionBegin; 119dd8e54a2SToby Isaac PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 120ef51cf95SToby Isaac if (dm->setupcalled) SETERRQ(PetscObjectComm((PetscObject)dm),PETSC_ERR_ARG_WRONGSTATE,"Cannot change the base after setup"); 121dd8e54a2SToby Isaac ierr = PetscObjectReference((PetscObject)base);CHKERRQ(ierr); 122dd8e54a2SToby Isaac ierr = DMDestroy(&forest->base);CHKERRQ(ierr); 123dd8e54a2SToby Isaac forest->base = base; 124a0452a8eSToby Isaac if (base) { 125a0452a8eSToby Isaac PetscValidHeaderSpecific(base, DM_CLASSID, 2); 126dd8e54a2SToby Isaac ierr = DMGetDimension(base,&dim);CHKERRQ(ierr); 127dd8e54a2SToby Isaac ierr = DMSetDimension(dm,dim);CHKERRQ(ierr); 128dd8e54a2SToby Isaac ierr = DMGetCoordinateDim(base,&dimEmbed);CHKERRQ(ierr); 129dd8e54a2SToby Isaac ierr = DMSetCoordinateDim(dm,dimEmbed);CHKERRQ(ierr); 130a0452a8eSToby Isaac } 131dd8e54a2SToby Isaac PetscFunctionReturn(0); 132dd8e54a2SToby Isaac } 133dd8e54a2SToby Isaac 134dd8e54a2SToby Isaac #undef __FUNCT__ 135dd8e54a2SToby Isaac #define __FUNCT__ "DMForestGetBaseDM" 136dd8e54a2SToby Isaac PetscErrorCode DMForestGetBaseDM(DM dm, DM *base) 137dd8e54a2SToby Isaac { 138dd8e54a2SToby Isaac DM_Forest *forest = (DM_Forest *) dm->data; 139dd8e54a2SToby Isaac 140dd8e54a2SToby Isaac PetscFunctionBegin; 141dd8e54a2SToby Isaac PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 142dd8e54a2SToby Isaac PetscValidPointer(base, 2); 143dd8e54a2SToby Isaac *base = forest->base; 144dd8e54a2SToby Isaac PetscFunctionReturn(0); 145dd8e54a2SToby Isaac } 146dd8e54a2SToby Isaac 147dd8e54a2SToby Isaac #undef __FUNCT__ 148dd8e54a2SToby Isaac #define __FUNCT__ "DMForestSetCoarseForest" 149dd8e54a2SToby Isaac PetscErrorCode DMForestSetCoarseForest(DM dm,DM coarse) 150dd8e54a2SToby Isaac { 151dd8e54a2SToby Isaac PetscErrorCode ierr; 152dd8e54a2SToby Isaac 153dd8e54a2SToby Isaac PetscFunctionBegin; 154dd8e54a2SToby Isaac PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 155ef51cf95SToby Isaac if (dm->setupcalled) SETERRQ(PetscObjectComm((PetscObject)dm),PETSC_ERR_ARG_WRONGSTATE,"Cannot change the coarse forest after setup"); 15656ba9f64SToby Isaac ierr = DMSetCoarseDM(dm,coarse);CHKERRQ(ierr); 157a0452a8eSToby Isaac if (coarse) { 158a0452a8eSToby Isaac PetscValidHeaderSpecific(coarse, DM_CLASSID, 2); 159a0452a8eSToby Isaac ierr = DMForestTemplate(coarse,dm);CHKERRQ(ierr); 160a0452a8eSToby Isaac } 161dd8e54a2SToby Isaac PetscFunctionReturn(0); 162dd8e54a2SToby Isaac } 163dd8e54a2SToby Isaac 164dd8e54a2SToby Isaac #undef __FUNCT__ 165dd8e54a2SToby Isaac #define __FUNCT__ "DMForestGetCoarseForest" 166dd8e54a2SToby Isaac PetscErrorCode DMForestGetCoarseForest(DM dm, DM *coarse) 167dd8e54a2SToby Isaac { 16856ba9f64SToby Isaac PetscErrorCode ierr; 169dd8e54a2SToby Isaac 170dd8e54a2SToby Isaac PetscFunctionBegin; 17156ba9f64SToby Isaac ierr = DMGetCoarseDM(dm,coarse);CHKERRQ(ierr); 172dd8e54a2SToby Isaac PetscFunctionReturn(0); 173dd8e54a2SToby Isaac } 174dd8e54a2SToby Isaac 175dd8e54a2SToby Isaac #undef __FUNCT__ 176dd8e54a2SToby Isaac #define __FUNCT__ "DMForestSetFineForest" 177dd8e54a2SToby Isaac PetscErrorCode DMForestSetFineForest(DM dm,DM fine) 178dd8e54a2SToby Isaac { 179dd8e54a2SToby Isaac PetscErrorCode ierr; 180dd8e54a2SToby Isaac 181dd8e54a2SToby Isaac PetscFunctionBegin; 182dd8e54a2SToby Isaac PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 183ef51cf95SToby Isaac if (dm->setupcalled) SETERRQ(PetscObjectComm((PetscObject)dm),PETSC_ERR_ARG_WRONGSTATE,"Cannot change the fine forest after setup"); 18488bdff64SToby Isaac ierr = DMSetFineDM(dm,fine);CHKERRQ(ierr); 185a0452a8eSToby Isaac if (fine) { 186a0452a8eSToby Isaac PetscValidHeaderSpecific(fine, DM_CLASSID, 2); 187a0452a8eSToby Isaac ierr = DMForestTemplate(fine,dm);CHKERRQ(ierr); 188a0452a8eSToby Isaac } 189dd8e54a2SToby Isaac PetscFunctionReturn(0); 190dd8e54a2SToby Isaac } 191dd8e54a2SToby Isaac 192dd8e54a2SToby Isaac #undef __FUNCT__ 193ef51cf95SToby Isaac #define __FUNCT__ "DMForestGetFineForest" 194dd8e54a2SToby Isaac PetscErrorCode DMForestGetFineForest(DM dm, DM *fine) 195dd8e54a2SToby Isaac { 19688bdff64SToby Isaac PetscErrorCode ierr; 197dd8e54a2SToby Isaac 198dd8e54a2SToby Isaac PetscFunctionBegin; 19988bdff64SToby Isaac ierr = DMGetFineDM(dm,fine);CHKERRQ(ierr); 200dd8e54a2SToby Isaac PetscFunctionReturn(0); 201dd8e54a2SToby Isaac } 202dd8e54a2SToby Isaac 203dd8e54a2SToby Isaac #undef __FUNCT__ 204dd8e54a2SToby Isaac #define __FUNCT__ "DMForestSetAdjacencyDimension" 205dd8e54a2SToby Isaac PetscErrorCode DMForestSetAdjacencyDimension(DM dm, PetscInt adjDim) 206dd8e54a2SToby Isaac { 207dd8e54a2SToby Isaac PetscInt dim; 208dd8e54a2SToby Isaac DM_Forest *forest = (DM_Forest *) dm->data; 209dd8e54a2SToby Isaac PetscErrorCode ierr; 210dd8e54a2SToby Isaac 211dd8e54a2SToby Isaac PetscFunctionBegin; 212dd8e54a2SToby Isaac PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 213ef51cf95SToby Isaac if (dm->setupcalled) SETERRQ(PetscObjectComm((PetscObject)dm),PETSC_ERR_ARG_WRONGSTATE,"Cannot change the adjacency dimension after setup"); 214dd8e54a2SToby Isaac if (adjDim < 0) SETERRQ1(PetscObjectComm((PetscObject)dm),PETSC_ERR_ARG_OUTOFRANGE,"adjacency dim cannot be < 0: %d", adjDim); 215dd8e54a2SToby Isaac ierr = DMGetDimension(dm,&dim);CHKERRQ(ierr); 216dd8e54a2SToby Isaac if (adjDim > dim) SETERRQ2(PetscObjectComm((PetscObject)dm),PETSC_ERR_ARG_OUTOFRANGE,"adjacency dim cannot be > %d: %d", dim, adjDim); 217dd8e54a2SToby Isaac forest->adjDim = adjDim; 218dd8e54a2SToby Isaac PetscFunctionReturn(0); 219dd8e54a2SToby Isaac } 220dd8e54a2SToby Isaac 221dd8e54a2SToby Isaac #undef __FUNCT__ 222dd8e54a2SToby Isaac #define __FUNCT__ "DMForestSetAdjacencyCodimension" 223dd8e54a2SToby Isaac PetscErrorCode DMForestSetAdjacencyCodimension(DM dm, PetscInt adjCodim) 224dd8e54a2SToby Isaac { 225dd8e54a2SToby Isaac PetscInt dim; 226dd8e54a2SToby Isaac PetscErrorCode ierr; 227dd8e54a2SToby Isaac 228dd8e54a2SToby Isaac PetscFunctionBegin; 229dd8e54a2SToby Isaac PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 230dd8e54a2SToby Isaac ierr = DMGetDimension(dm,&dim);CHKERRQ(ierr); 231dd8e54a2SToby Isaac ierr = DMForestSetAdjacencyDimension(dm,dim-adjCodim);CHKERRQ(ierr); 232dd8e54a2SToby Isaac PetscFunctionReturn(0); 233dd8e54a2SToby Isaac } 234dd8e54a2SToby Isaac 235dd8e54a2SToby Isaac #undef __FUNCT__ 236dd8e54a2SToby Isaac #define __FUNCT__ "DMForestGetAdjacencyDimension" 237dd8e54a2SToby Isaac PetscErrorCode DMForestGetAdjacencyDimension(DM dm, PetscInt *adjDim) 238dd8e54a2SToby Isaac { 239dd8e54a2SToby Isaac DM_Forest *forest = (DM_Forest *) dm->data; 240dd8e54a2SToby Isaac 241dd8e54a2SToby Isaac PetscFunctionBegin; 242dd8e54a2SToby Isaac PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 243dd8e54a2SToby Isaac PetscValidIntPointer(adjDim,2); 244dd8e54a2SToby Isaac *adjDim = forest->adjDim; 245dd8e54a2SToby Isaac PetscFunctionReturn(0); 246dd8e54a2SToby Isaac } 247dd8e54a2SToby Isaac 248dd8e54a2SToby Isaac #undef __FUNCT__ 249dd8e54a2SToby Isaac #define __FUNCT__ "DMForestGetAdjacencyCodimension" 250dd8e54a2SToby Isaac PetscErrorCode DMForestGetAdjacencyCodimension(DM dm, PetscInt *adjCodim) 251dd8e54a2SToby Isaac { 252dd8e54a2SToby Isaac DM_Forest *forest = (DM_Forest *) dm->data; 253dd8e54a2SToby Isaac PetscInt dim; 254dd8e54a2SToby Isaac PetscErrorCode ierr; 255dd8e54a2SToby Isaac 256dd8e54a2SToby Isaac PetscFunctionBegin; 257dd8e54a2SToby Isaac PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 258dd8e54a2SToby Isaac PetscValidIntPointer(adjCodim,2); 259dd8e54a2SToby Isaac ierr = DMGetDimension(dm,&dim);CHKERRQ(ierr); 260dd8e54a2SToby Isaac *adjCodim = dim - forest->adjDim; 261dd8e54a2SToby Isaac PetscFunctionReturn(0); 262dd8e54a2SToby Isaac } 263dd8e54a2SToby Isaac 264dd8e54a2SToby Isaac #undef __FUNCT__ 265ef51cf95SToby Isaac #define __FUNCT__ "DMForestSetPartitionOverlap" 266dd8e54a2SToby Isaac PetscErrorCode DMForestSetPartitionOverlap(DM dm, PetscInt overlap) 267dd8e54a2SToby Isaac { 268dd8e54a2SToby Isaac DM_Forest *forest = (DM_Forest *) dm->data; 269dd8e54a2SToby Isaac 270dd8e54a2SToby Isaac PetscFunctionBegin; 271dd8e54a2SToby Isaac PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 272ef51cf95SToby Isaac if (dm->setupcalled) SETERRQ(PetscObjectComm((PetscObject)dm),PETSC_ERR_ARG_WRONGSTATE,"Cannot change the overlap after setup"); 273dd8e54a2SToby Isaac if (overlap < 0) SETERRQ1(PetscObjectComm((PetscObject)dm),PETSC_ERR_ARG_OUTOFRANGE,"overlap cannot be < 0: %d", overlap); 274dd8e54a2SToby Isaac forest->overlap = overlap; 275dd8e54a2SToby Isaac PetscFunctionReturn(0); 276dd8e54a2SToby Isaac } 277dd8e54a2SToby Isaac 278dd8e54a2SToby Isaac #undef __FUNCT__ 279dd8e54a2SToby Isaac #define __FUNCT__ "DMForestGetPartitionOverlap" 280dd8e54a2SToby Isaac PetscErrorCode DMForestGetPartitionOverlap(DM dm, PetscInt *overlap) 281dd8e54a2SToby Isaac { 282dd8e54a2SToby Isaac DM_Forest *forest = (DM_Forest *) dm->data; 283dd8e54a2SToby Isaac 284dd8e54a2SToby Isaac PetscFunctionBegin; 285dd8e54a2SToby Isaac PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 286dd8e54a2SToby Isaac PetscValidIntPointer(overlap,2); 287dd8e54a2SToby Isaac *overlap = forest->overlap; 288dd8e54a2SToby Isaac PetscFunctionReturn(0); 289dd8e54a2SToby Isaac } 290dd8e54a2SToby Isaac 291dd8e54a2SToby Isaac #undef __FUNCT__ 292dd8e54a2SToby Isaac #define __FUNCT__ "DMForestSetMinimumRefinement" 293dd8e54a2SToby Isaac PetscErrorCode DMForestSetMinimumRefinement(DM dm, PetscInt minRefinement) 294dd8e54a2SToby Isaac { 295dd8e54a2SToby Isaac DM_Forest *forest = (DM_Forest *) dm->data; 296dd8e54a2SToby Isaac 297dd8e54a2SToby Isaac PetscFunctionBegin; 298dd8e54a2SToby Isaac PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 299ef51cf95SToby Isaac if (dm->setupcalled) SETERRQ(PetscObjectComm((PetscObject)dm),PETSC_ERR_ARG_WRONGSTATE,"Cannot change the minimum refinement after setup"); 300dd8e54a2SToby Isaac forest->minRefinement = minRefinement; 301dd8e54a2SToby Isaac PetscFunctionReturn(0); 302dd8e54a2SToby Isaac } 303dd8e54a2SToby Isaac 304dd8e54a2SToby Isaac #undef __FUNCT__ 305dd8e54a2SToby Isaac #define __FUNCT__ "DMForestGetMinimumRefinement" 306dd8e54a2SToby Isaac PetscErrorCode DMForestGetMinimumRefinement(DM dm, PetscInt *minRefinement) 307dd8e54a2SToby Isaac { 308dd8e54a2SToby Isaac DM_Forest *forest = (DM_Forest *) dm->data; 309dd8e54a2SToby Isaac 310dd8e54a2SToby Isaac PetscFunctionBegin; 311dd8e54a2SToby Isaac PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 312dd8e54a2SToby Isaac PetscValidIntPointer(minRefinement,2); 313dd8e54a2SToby Isaac *minRefinement = forest->minRefinement; 314dd8e54a2SToby Isaac PetscFunctionReturn(0); 315dd8e54a2SToby Isaac } 316dd8e54a2SToby Isaac 317dd8e54a2SToby Isaac #undef __FUNCT__ 31856ba9f64SToby Isaac #define __FUNCT__ "DMForestSetInitialRefinement" 31956ba9f64SToby Isaac PetscErrorCode DMForestSetInitialRefinement(DM dm, PetscInt initRefinement) 32056ba9f64SToby Isaac { 32156ba9f64SToby Isaac DM_Forest *forest = (DM_Forest *) dm->data; 32256ba9f64SToby Isaac 32356ba9f64SToby Isaac PetscFunctionBegin; 32456ba9f64SToby Isaac PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 32556ba9f64SToby Isaac if (dm->setupcalled) SETERRQ(PetscObjectComm((PetscObject)dm),PETSC_ERR_ARG_WRONGSTATE,"Cannot change the initial refinement after setup"); 32656ba9f64SToby Isaac forest->initRefinement = initRefinement; 32756ba9f64SToby Isaac PetscFunctionReturn(0); 32856ba9f64SToby Isaac } 32956ba9f64SToby Isaac 33056ba9f64SToby Isaac #undef __FUNCT__ 33156ba9f64SToby Isaac #define __FUNCT__ "DMForestGetInitialRefinement" 33256ba9f64SToby Isaac PetscErrorCode DMForestGetInitialRefinement(DM dm, PetscInt *initRefinement) 33356ba9f64SToby Isaac { 33456ba9f64SToby Isaac DM_Forest *forest = (DM_Forest *) dm->data; 33556ba9f64SToby Isaac 33656ba9f64SToby Isaac PetscFunctionBegin; 33756ba9f64SToby Isaac PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 33856ba9f64SToby Isaac PetscValidIntPointer(initRefinement,2); 33956ba9f64SToby Isaac *initRefinement = forest->initRefinement; 34056ba9f64SToby Isaac PetscFunctionReturn(0); 34156ba9f64SToby Isaac } 34256ba9f64SToby Isaac 34356ba9f64SToby Isaac #undef __FUNCT__ 344c7eeac06SToby Isaac #define __FUNCT__ "DMForestSetMaximumRefinement" 345c7eeac06SToby Isaac PetscErrorCode DMForestSetMaximumRefinement(DM dm, PetscInt maxRefinement) 346dd8e54a2SToby Isaac { 347dd8e54a2SToby Isaac DM_Forest *forest = (DM_Forest *) dm->data; 348dd8e54a2SToby Isaac 349dd8e54a2SToby Isaac PetscFunctionBegin; 350dd8e54a2SToby Isaac PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 351ef51cf95SToby Isaac if (dm->setupcalled) SETERRQ(PetscObjectComm((PetscObject)dm),PETSC_ERR_ARG_WRONGSTATE,"Cannot change the maximum refinement after setup"); 352c7eeac06SToby Isaac forest->maxRefinement = maxRefinement; 353dd8e54a2SToby Isaac PetscFunctionReturn(0); 354dd8e54a2SToby Isaac } 355dd8e54a2SToby Isaac 356dd8e54a2SToby Isaac #undef __FUNCT__ 357c7eeac06SToby Isaac #define __FUNCT__ "DMForestGetMaximumRefinement" 358c7eeac06SToby Isaac PetscErrorCode DMForestGetMaximumRefinement(DM dm, PetscInt *maxRefinement) 359dd8e54a2SToby Isaac { 360dd8e54a2SToby Isaac DM_Forest *forest = (DM_Forest *) dm->data; 361dd8e54a2SToby Isaac 362dd8e54a2SToby Isaac PetscFunctionBegin; 363dd8e54a2SToby Isaac PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 364c7eeac06SToby Isaac PetscValidIntPointer(maxRefinement,2); 365c7eeac06SToby Isaac *maxRefinement = forest->maxRefinement; 366dd8e54a2SToby Isaac PetscFunctionReturn(0); 367dd8e54a2SToby Isaac } 368c7eeac06SToby Isaac 369c7eeac06SToby Isaac #undef __FUNCT__ 370c7eeac06SToby Isaac #define __FUNCT__ "DMForestSetAdaptivityStrategy" 371c7eeac06SToby Isaac PetscErrorCode DMForestSetAdaptivityStrategy(DM dm, DMForestAdaptivityStrategy adaptStrategy) 372c7eeac06SToby Isaac { 373c7eeac06SToby Isaac DM_Forest *forest = (DM_Forest *) dm->data; 374c7eeac06SToby Isaac PetscErrorCode ierr; 375c7eeac06SToby Isaac 376c7eeac06SToby Isaac PetscFunctionBegin; 377c7eeac06SToby Isaac PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 378c7eeac06SToby Isaac ierr = PetscFree(forest->adaptStrategy);CHKERRQ(ierr); 379*a73e2921SToby Isaac ierr = PetscStrallocpy((const char *) adaptStrategy,(char **)&forest->adaptStrategy);CHKERRQ(ierr); 380c7eeac06SToby Isaac PetscFunctionReturn(0); 381c7eeac06SToby Isaac } 382c7eeac06SToby Isaac 383c7eeac06SToby Isaac #undef __FUNCT__ 384c7eeac06SToby Isaac #define __FUNCT__ "DMForestGetAdaptivityStrategy" 385c7eeac06SToby Isaac PetscErrorCode DMForestGetAdaptivityStrategy(DM dm, DMForestAdaptivityStrategy *adaptStrategy) 386c7eeac06SToby Isaac { 387c7eeac06SToby Isaac DM_Forest *forest = (DM_Forest *) dm->data; 388c7eeac06SToby Isaac 389c7eeac06SToby Isaac PetscFunctionBegin; 390c7eeac06SToby Isaac PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 391c7eeac06SToby Isaac PetscValidPointer(adaptStrategy,2); 392c7eeac06SToby Isaac *adaptStrategy = forest->adaptStrategy; 393c7eeac06SToby Isaac PetscFunctionReturn(0); 394c7eeac06SToby Isaac } 395c7eeac06SToby Isaac 396c7eeac06SToby Isaac #undef __FUNCT__ 397c7eeac06SToby Isaac #define __FUNCT__ "DMForestSetGradeFactor" 398c7eeac06SToby Isaac PetscErrorCode DMForestSetGradeFactor(DM dm, PetscInt grade) 399c7eeac06SToby Isaac { 400c7eeac06SToby Isaac DM_Forest *forest = (DM_Forest *) dm->data; 401c7eeac06SToby Isaac 402c7eeac06SToby Isaac PetscFunctionBegin; 403c7eeac06SToby Isaac PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 404ef51cf95SToby Isaac if (dm->setupcalled) SETERRQ(PetscObjectComm((PetscObject)dm),PETSC_ERR_ARG_WRONGSTATE,"Cannot change the grade factor after setup"); 405c7eeac06SToby Isaac forest->gradeFactor = grade; 406c7eeac06SToby Isaac PetscFunctionReturn(0); 407c7eeac06SToby Isaac } 408c7eeac06SToby Isaac 409c7eeac06SToby Isaac #undef __FUNCT__ 410c7eeac06SToby Isaac #define __FUNCT__ "DMForestGetGradeFactor" 411c7eeac06SToby Isaac PetscErrorCode DMForestGetGradeFactor(DM dm, PetscInt *grade) 412c7eeac06SToby Isaac { 413c7eeac06SToby Isaac DM_Forest *forest = (DM_Forest *) dm->data; 414c7eeac06SToby Isaac 415c7eeac06SToby Isaac PetscFunctionBegin; 416c7eeac06SToby Isaac PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 417c7eeac06SToby Isaac PetscValidIntPointer(grade,2); 418c7eeac06SToby Isaac *grade = forest->gradeFactor; 419c7eeac06SToby Isaac PetscFunctionReturn(0); 420c7eeac06SToby Isaac } 421c7eeac06SToby Isaac 422c7eeac06SToby Isaac #undef __FUNCT__ 423ef51cf95SToby Isaac #define __FUNCT__ "DMForestSetCellWeightFactor" 424ef51cf95SToby Isaac PetscErrorCode DMForestSetCellWeightFactor(DM dm, PetscReal weightsFactor) 425c7eeac06SToby Isaac { 426c7eeac06SToby Isaac DM_Forest *forest = (DM_Forest *) dm->data; 427c7eeac06SToby Isaac 428c7eeac06SToby Isaac PetscFunctionBegin; 429c7eeac06SToby Isaac PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 430ef51cf95SToby Isaac if (dm->setupcalled) SETERRQ(PetscObjectComm((PetscObject)dm),PETSC_ERR_ARG_WRONGSTATE,"Cannot change the weights factor after setup"); 431c7eeac06SToby Isaac forest->weightsFactor = weightsFactor; 432c7eeac06SToby Isaac PetscFunctionReturn(0); 433c7eeac06SToby Isaac } 434c7eeac06SToby Isaac 435c7eeac06SToby Isaac #undef __FUNCT__ 436ef51cf95SToby Isaac #define __FUNCT__ "DMForestGetCellWeightFactor" 437ef51cf95SToby Isaac PetscErrorCode DMForestGetCellWeightFactor(DM dm, PetscReal *weightsFactor) 438c7eeac06SToby Isaac { 439c7eeac06SToby Isaac DM_Forest *forest = (DM_Forest *) dm->data; 440c7eeac06SToby Isaac 441c7eeac06SToby Isaac PetscFunctionBegin; 442c7eeac06SToby Isaac PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 443c7eeac06SToby Isaac PetscValidRealPointer(weightsFactor,2); 444c7eeac06SToby Isaac *weightsFactor = forest->weightsFactor; 445c7eeac06SToby Isaac PetscFunctionReturn(0); 446c7eeac06SToby Isaac } 447c7eeac06SToby Isaac 448c7eeac06SToby Isaac #undef __FUNCT__ 449c7eeac06SToby Isaac #define __FUNCT__ "DMForestGetCellChart" 450c7eeac06SToby Isaac PetscErrorCode DMForestGetCellChart(DM dm, PetscInt *cStart, PetscInt *cEnd) 451c7eeac06SToby Isaac { 452c7eeac06SToby Isaac DM_Forest *forest = (DM_Forest *) dm->data; 453c7eeac06SToby Isaac PetscErrorCode ierr; 454c7eeac06SToby Isaac 455c7eeac06SToby Isaac PetscFunctionBegin; 456c7eeac06SToby Isaac PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 457c7eeac06SToby Isaac PetscValidIntPointer(cStart,2); 458c7eeac06SToby Isaac PetscValidIntPointer(cEnd,2); 459c7eeac06SToby Isaac if (((forest->cStart == PETSC_DETERMINE) || (forest->cEnd == PETSC_DETERMINE)) && forest->createcellchart) { 460c7eeac06SToby Isaac ierr = forest->createcellchart(dm,&forest->cStart,&forest->cEnd);CHKERRQ(ierr); 461c7eeac06SToby Isaac } 462c7eeac06SToby Isaac *cStart = forest->cStart; 463c7eeac06SToby Isaac *cEnd = forest->cEnd; 464c7eeac06SToby Isaac PetscFunctionReturn(0); 465c7eeac06SToby Isaac } 466c7eeac06SToby Isaac 467c7eeac06SToby Isaac #undef __FUNCT__ 468c7eeac06SToby Isaac #define __FUNCT__ "DMForestGetCellSF" 469c7eeac06SToby Isaac PetscErrorCode DMForestGetCellSF(DM dm, PetscSF *cellSF) 470c7eeac06SToby Isaac { 471c7eeac06SToby Isaac DM_Forest *forest = (DM_Forest *) dm->data; 472c7eeac06SToby Isaac PetscErrorCode ierr; 473c7eeac06SToby Isaac 474c7eeac06SToby Isaac PetscFunctionBegin; 475c7eeac06SToby Isaac PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 476c7eeac06SToby Isaac PetscValidPointer(cellSF,2); 477c7eeac06SToby Isaac if ((!forest->cellSF) && forest->createcellsf) { 478c7eeac06SToby Isaac ierr = forest->createcellsf(dm,&forest->cellSF);CHKERRQ(ierr); 479c7eeac06SToby Isaac } 480c7eeac06SToby Isaac *cellSF = forest->cellSF; 481c7eeac06SToby Isaac PetscFunctionReturn(0); 482c7eeac06SToby Isaac } 483c7eeac06SToby Isaac 484c7eeac06SToby Isaac #undef __FUNCT__ 485c7eeac06SToby Isaac #define __FUNCT__ "DMForestSetAdaptivityMarkers" 486c7eeac06SToby Isaac PetscErrorCode DMForestSetAdaptivityMarkers(DM dm, PetscInt markers[], PetscCopyMode copyMode) 487c7eeac06SToby Isaac { 488c7eeac06SToby Isaac DM_Forest *forest = (DM_Forest *) dm->data; 489c7eeac06SToby Isaac PetscInt cStart, cEnd; 490c7eeac06SToby Isaac PetscErrorCode ierr; 491c7eeac06SToby Isaac 492c7eeac06SToby Isaac PetscFunctionBegin; 493c7eeac06SToby Isaac PetscValidHeaderSpecific(dm,DM_CLASSID,1); 494c7eeac06SToby Isaac ierr = DMForestGetCellChart(dm,&cStart,&cEnd);CHKERRQ(ierr); 495c7eeac06SToby Isaac if (cEnd < cStart) SETERRQ2(PETSC_COMM_SELF,PETSC_ERR_ARG_WRONGSTATE,"cell chart [%d,%d) is not valid",cStart,cEnd); 496c7eeac06SToby Isaac if (copyMode == PETSC_COPY_VALUES) { 497c7eeac06SToby Isaac if (forest->adaptCopyMode != PETSC_OWN_POINTER || forest->adaptMarkers == markers) { 498c7eeac06SToby Isaac ierr = PetscMalloc1(cEnd-cStart,&forest->adaptMarkers);CHKERRQ(ierr); 499c7eeac06SToby Isaac } 500c7eeac06SToby Isaac ierr = PetscMemcpy(forest->adaptMarkers,markers,(cEnd-cStart)*sizeof(*markers));CHKERRQ(ierr); 501c7eeac06SToby Isaac forest->adaptCopyMode = PETSC_OWN_POINTER; 502c7eeac06SToby Isaac PetscFunctionReturn(0); 503c7eeac06SToby Isaac } 504c7eeac06SToby Isaac if (forest->adaptCopyMode == PETSC_OWN_POINTER) { 505c7eeac06SToby Isaac ierr = PetscFree(forest->adaptMarkers);CHKERRQ(ierr); 506c7eeac06SToby Isaac } 507c7eeac06SToby Isaac forest->adaptMarkers = markers; 508c7eeac06SToby Isaac forest->adaptCopyMode = copyMode; 509c7eeac06SToby Isaac PetscFunctionReturn(0); 510c7eeac06SToby Isaac } 511c7eeac06SToby Isaac 512c7eeac06SToby Isaac #undef __FUNCT__ 513c7eeac06SToby Isaac #define __FUNCT__ "DMForestGetAdaptivityMarkers" 514c7eeac06SToby Isaac PetscErrorCode DMForestGetAdaptivityMarkers(DM dm, PetscInt **markers) 515c7eeac06SToby Isaac { 516c7eeac06SToby Isaac DM_Forest *forest = (DM_Forest *) dm->data; 517c7eeac06SToby Isaac 518c7eeac06SToby Isaac PetscFunctionBegin; 519c7eeac06SToby Isaac PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 520c7eeac06SToby Isaac PetscValidPointer(markers,2); 521c7eeac06SToby Isaac *markers = forest->adaptMarkers; 522c7eeac06SToby Isaac PetscFunctionReturn(0); 523c7eeac06SToby Isaac } 524c7eeac06SToby Isaac 525c7eeac06SToby Isaac #undef __FUNCT__ 526c7eeac06SToby Isaac #define __FUNCT__ "DMForestSetCellWeights" 527c7eeac06SToby Isaac PetscErrorCode DMForestSetCellWeights(DM dm, PetscReal weights[], PetscCopyMode copyMode) 528c7eeac06SToby Isaac { 529c7eeac06SToby Isaac DM_Forest *forest = (DM_Forest *) dm->data; 530c7eeac06SToby Isaac PetscInt cStart, cEnd; 531c7eeac06SToby Isaac PetscErrorCode ierr; 532c7eeac06SToby Isaac 533c7eeac06SToby Isaac PetscFunctionBegin; 534c7eeac06SToby Isaac PetscValidHeaderSpecific(dm,DM_CLASSID,1); 535c7eeac06SToby Isaac ierr = DMForestGetCellChart(dm,&cStart,&cEnd);CHKERRQ(ierr); 536c7eeac06SToby Isaac if (cEnd < cStart) SETERRQ2(PETSC_COMM_SELF,PETSC_ERR_ARG_WRONGSTATE,"cell chart [%d,%d) is not valid",cStart,cEnd); 537c7eeac06SToby Isaac if (copyMode == PETSC_COPY_VALUES) { 538c7eeac06SToby Isaac if (forest->cellWeightsCopyMode != PETSC_OWN_POINTER || forest->cellWeights == weights) { 539c7eeac06SToby Isaac ierr = PetscMalloc1(cEnd-cStart,&forest->cellWeights);CHKERRQ(ierr); 540c7eeac06SToby Isaac } 541c7eeac06SToby Isaac ierr = PetscMemcpy(forest->cellWeights,weights,(cEnd-cStart)*sizeof(*weights));CHKERRQ(ierr); 542c7eeac06SToby Isaac forest->cellWeightsCopyMode = PETSC_OWN_POINTER; 543c7eeac06SToby Isaac PetscFunctionReturn(0); 544c7eeac06SToby Isaac } 545c7eeac06SToby Isaac if (forest->cellWeightsCopyMode == PETSC_OWN_POINTER) { 546c7eeac06SToby Isaac ierr = PetscFree(forest->cellWeights);CHKERRQ(ierr); 547c7eeac06SToby Isaac } 548c7eeac06SToby Isaac forest->cellWeights = weights; 549c7eeac06SToby Isaac forest->cellWeightsCopyMode = copyMode; 550c7eeac06SToby Isaac PetscFunctionReturn(0); 551c7eeac06SToby Isaac } 552c7eeac06SToby Isaac 553c7eeac06SToby Isaac #undef __FUNCT__ 554c7eeac06SToby Isaac #define __FUNCT__ "DMForestGetCellWeights" 555c7eeac06SToby Isaac PetscErrorCode DMForestGetCellWeights(DM dm, PetscReal **weights) 556c7eeac06SToby Isaac { 557c7eeac06SToby Isaac DM_Forest *forest = (DM_Forest *) dm->data; 558c7eeac06SToby Isaac 559c7eeac06SToby Isaac PetscFunctionBegin; 560c7eeac06SToby Isaac PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 561c7eeac06SToby Isaac PetscValidPointer(weights,2); 562c7eeac06SToby Isaac *weights = forest->cellWeights; 563c7eeac06SToby Isaac PetscFunctionReturn(0); 564c7eeac06SToby Isaac } 565c7eeac06SToby Isaac 566c7eeac06SToby Isaac #undef __FUNCT__ 567c7eeac06SToby Isaac #define __FUNCT__ "DMForestSetWeightCapacity" 568c7eeac06SToby Isaac PetscErrorCode DMForestSetWeightCapacity(DM dm, PetscReal capacity) 569c7eeac06SToby Isaac { 570c7eeac06SToby Isaac DM_Forest *forest = (DM_Forest *) dm->data; 571c7eeac06SToby Isaac 572c7eeac06SToby Isaac PetscFunctionBegin; 573c7eeac06SToby Isaac PetscValidHeaderSpecific(dm,DM_CLASSID,1); 574ef51cf95SToby Isaac if (dm->setupcalled) SETERRQ(PetscObjectComm((PetscObject)dm),PETSC_ERR_ARG_WRONGSTATE,"Cannot change the weight capacity after setup"); 575c7eeac06SToby Isaac if (capacity < 0.) SETERRQ1(PetscObjectComm((PetscObject)dm),PETSC_ERR_ARG_OUTOFRANGE,"Cannot have negative weight capacity; %f",capacity); 576c7eeac06SToby Isaac forest->weightCapacity = capacity; 577c7eeac06SToby Isaac PetscFunctionReturn(0); 578c7eeac06SToby Isaac } 579c7eeac06SToby Isaac 580c7eeac06SToby Isaac #undef __FUNCT__ 581c7eeac06SToby Isaac #define __FUNCT__ "DMForestGetWeightCapacity" 582c7eeac06SToby Isaac PetscErrorCode DMForestGetWeightCapacity(DM dm, PetscReal *capacity) 583c7eeac06SToby Isaac { 584c7eeac06SToby Isaac DM_Forest *forest = (DM_Forest *) dm->data; 585c7eeac06SToby Isaac 586c7eeac06SToby Isaac PetscFunctionBegin; 587c7eeac06SToby Isaac PetscValidHeaderSpecific(dm,DM_CLASSID,1); 588c7eeac06SToby Isaac PetscValidRealPointer(capacity,2); 589c7eeac06SToby Isaac *capacity = forest->weightCapacity; 590c7eeac06SToby Isaac PetscFunctionReturn(0); 591c7eeac06SToby Isaac } 592c7eeac06SToby Isaac 593dd8e54a2SToby Isaac #undef __FUNCT__ 594db4d5e8cSToby Isaac #define __FUNCT__ "DMSetFromOptions_Forest" 5955c8434f9SToby Isaac PETSC_EXTERN PetscErrorCode DMSetFromOptions_Forest(PetscOptions *PetscOptionsObject,DM dm) 596db4d5e8cSToby Isaac { 597db4d5e8cSToby Isaac DM_Forest *forest = (DM_Forest *) dm->data; 59856ba9f64SToby Isaac PetscBool flg, flg1, flg2, flg3, flg4; 599dd8e54a2SToby Isaac DMForestTopology oldTopo; 600c7eeac06SToby Isaac char stringBuffer[256]; 601dd8e54a2SToby Isaac PetscViewer viewer; 602dd8e54a2SToby Isaac PetscViewerFormat format; 60356ba9f64SToby Isaac PetscInt adjDim, adjCodim, overlap, minRefinement, initRefinement, maxRefinement, grade; 604c7eeac06SToby Isaac PetscReal weightsFactor; 605c7eeac06SToby Isaac DMForestAdaptivityStrategy adaptStrategy; 606db4d5e8cSToby Isaac PetscErrorCode ierr; 607db4d5e8cSToby Isaac 608db4d5e8cSToby Isaac PetscFunctionBegin; 609db4d5e8cSToby Isaac PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 610db4d5e8cSToby Isaac forest->setFromOptions = PETSC_TRUE; 6115c8434f9SToby Isaac ierr = PetscOptionsHead(PetscOptionsObject,"DMForest Options");CHKERRQ(ierr); 612dd8e54a2SToby Isaac ierr = DMForestGetTopology(dm, &oldTopo);CHKERRQ(ierr); 61356ba9f64SToby Isaac ierr = PetscOptionsString("-dm_forest_topology","the topology of the forest's base mesh","DMForestSetTopology",oldTopo,stringBuffer,256,&flg1);CHKERRQ(ierr); 61456ba9f64SToby Isaac ierr = PetscOptionsViewer("-dm_forest_base_dm","load the base DM from a viewer specification","DMForestSetBaseDM",&viewer,&format,&flg2);CHKERRQ(ierr); 61556ba9f64SToby Isaac ierr = PetscOptionsViewer("-dm_forest_coarse_forest","load the coarse forest from a viewer specification","DMForestSetCoarseForest",&viewer,&format,&flg3);CHKERRQ(ierr); 61656ba9f64SToby Isaac ierr = PetscOptionsViewer("-dm_forest_fine_forest","load the fine forest from a viewer specification","DMForestSetFineForest",&viewer,&format,&flg4);CHKERRQ(ierr); 61756ba9f64SToby Isaac if ((PetscInt) flg1 + (PetscInt) flg2 + (PetscInt) flg3 + (PetscInt) flg4 > 1) { 61856ba9f64SToby Isaac SETERRQ(PetscObjectComm((PetscObject)dm),PETSC_ERR_ARG_INCOMP,"Specify only one of -dm_forest_{topology,base_dm,coarse_forest,fine_forest}"); 619dd8e54a2SToby Isaac } 62056ba9f64SToby Isaac if (flg1) { 62156ba9f64SToby Isaac ierr = DMForestSetTopology(dm,(DMForestTopology)stringBuffer);CHKERRQ(ierr); 62256ba9f64SToby Isaac ierr = DMForestSetBaseDM(dm,NULL);CHKERRQ(ierr); 62356ba9f64SToby Isaac ierr = DMForestSetCoarseForest(dm,NULL);CHKERRQ(ierr); 62456ba9f64SToby Isaac ierr = DMForestSetFineForest(dm,NULL);CHKERRQ(ierr); 62556ba9f64SToby Isaac } 62656ba9f64SToby Isaac if (flg2) { 627dd8e54a2SToby Isaac DM base; 628dd8e54a2SToby Isaac 629dd8e54a2SToby Isaac ierr = DMCreate(PetscObjectComm((PetscObject)dm),&base);CHKERRQ(ierr); 630dd8e54a2SToby Isaac ierr = PetscViewerPushFormat(viewer,format);CHKERRQ(ierr); 631dd8e54a2SToby Isaac ierr = DMLoad(base,viewer);CHKERRQ(ierr); 632dd8e54a2SToby Isaac ierr = PetscViewerDestroy(&viewer);CHKERRQ(ierr); 633dd8e54a2SToby Isaac ierr = DMForestSetBaseDM(dm,base);CHKERRQ(ierr); 634dd8e54a2SToby Isaac ierr = DMDestroy(&base);CHKERRQ(ierr); 63556ba9f64SToby Isaac ierr = DMForestSetTopology(dm,NULL);CHKERRQ(ierr); 63656ba9f64SToby Isaac ierr = DMForestSetCoarseForest(dm,NULL);CHKERRQ(ierr); 63756ba9f64SToby Isaac ierr = DMForestSetFineForest(dm,NULL);CHKERRQ(ierr); 638dd8e54a2SToby Isaac } 63956ba9f64SToby Isaac if (flg3) { 640dd8e54a2SToby Isaac DM coarse; 641dd8e54a2SToby Isaac 642dd8e54a2SToby Isaac ierr = DMCreate(PetscObjectComm((PetscObject)dm),&coarse);CHKERRQ(ierr); 643dd8e54a2SToby Isaac ierr = PetscViewerPushFormat(viewer,format);CHKERRQ(ierr); 644dd8e54a2SToby Isaac ierr = DMLoad(coarse,viewer);CHKERRQ(ierr); 645dd8e54a2SToby Isaac ierr = PetscViewerDestroy(&viewer);CHKERRQ(ierr); 646dd8e54a2SToby Isaac ierr = DMForestSetCoarseForest(dm,coarse);CHKERRQ(ierr); 647dd8e54a2SToby Isaac ierr = DMDestroy(&coarse);CHKERRQ(ierr); 64856ba9f64SToby Isaac ierr = DMForestSetTopology(dm,NULL);CHKERRQ(ierr); 64956ba9f64SToby Isaac ierr = DMForestSetBaseDM(dm,NULL);CHKERRQ(ierr); 65056ba9f64SToby Isaac ierr = DMForestSetFineForest(dm,NULL);CHKERRQ(ierr); 651dd8e54a2SToby Isaac } 65256ba9f64SToby Isaac if (flg4) { 653dd8e54a2SToby Isaac DM fine; 654dd8e54a2SToby Isaac 655dd8e54a2SToby Isaac ierr = DMCreate(PetscObjectComm((PetscObject)dm),&fine);CHKERRQ(ierr); 656dd8e54a2SToby Isaac ierr = PetscViewerPushFormat(viewer,format);CHKERRQ(ierr); 657dd8e54a2SToby Isaac ierr = DMLoad(fine,viewer);CHKERRQ(ierr); 658dd8e54a2SToby Isaac ierr = PetscViewerDestroy(&viewer);CHKERRQ(ierr); 659dd8e54a2SToby Isaac ierr = DMForestSetFineForest(dm,fine);CHKERRQ(ierr); 660dd8e54a2SToby Isaac ierr = DMDestroy(&fine);CHKERRQ(ierr); 66156ba9f64SToby Isaac ierr = DMForestSetTopology(dm,NULL);CHKERRQ(ierr); 66256ba9f64SToby Isaac ierr = DMForestSetBaseDM(dm,NULL);CHKERRQ(ierr); 66356ba9f64SToby Isaac ierr = DMForestSetCoarseForest(dm,NULL);CHKERRQ(ierr); 664dd8e54a2SToby Isaac } 665dd8e54a2SToby Isaac ierr = DMForestGetAdjacencyDimension(dm,&adjDim);CHKERRQ(ierr); 666dd8e54a2SToby Isaac ierr = PetscOptionsInt("-dm_forest_adjacency_dimension","set the dimension of points that define adjacency in the forest","DMForestSetAdjacencyDimension",adjDim,&adjDim,&flg);CHKERRQ(ierr); 667dd8e54a2SToby Isaac if (flg) { 668dd8e54a2SToby Isaac ierr = DMForestSetAdjacencyDimension(dm,adjDim);CHKERRQ(ierr); 669dd8e54a2SToby Isaac } 670dd8e54a2SToby Isaac else { 671dd8e54a2SToby Isaac ierr = DMForestGetAdjacencyCodimension(dm,&adjCodim);CHKERRQ(ierr); 672dd8e54a2SToby Isaac ierr = PetscOptionsInt("-dm_forest_adjacency_codimension","set the codimension of points that define adjacency in the forest","DMForestSetAdjacencyCodimension",adjCodim,&adjCodim,&flg);CHKERRQ(ierr); 673dd8e54a2SToby Isaac if (flg) { 674dd8e54a2SToby Isaac ierr = DMForestSetAdjacencyCodimension(dm,adjCodim);CHKERRQ(ierr); 675dd8e54a2SToby Isaac } 676dd8e54a2SToby Isaac } 677dd8e54a2SToby Isaac ierr = DMForestGetPartitionOverlap(dm,&overlap);CHKERRQ(ierr); 678dd8e54a2SToby Isaac ierr = PetscOptionsInt("-dm_forest_partition_overlap","set the degree of partition overlap","DMForestSetPartitionOverlap",overlap,&overlap,&flg);CHKERRQ(ierr); 679dd8e54a2SToby Isaac if (flg) { 680dd8e54a2SToby Isaac ierr = DMForestSetPartitionOverlap(dm,overlap);CHKERRQ(ierr); 681dd8e54a2SToby Isaac } 682dd8e54a2SToby Isaac ierr = DMForestGetMinimumRefinement(dm,&minRefinement);CHKERRQ(ierr); 683dd8e54a2SToby Isaac ierr = PetscOptionsInt("-dm_forest_minimum_refinement","set the minimum level of refinement in the forest","DMForestSetMinimumRefinement",minRefinement,&minRefinement,&flg);CHKERRQ(ierr); 684dd8e54a2SToby Isaac if (flg) { 685dd8e54a2SToby Isaac ierr = DMForestSetMinimumRefinement(dm,minRefinement);CHKERRQ(ierr); 686db4d5e8cSToby Isaac } 68756ba9f64SToby Isaac ierr = DMForestGetInitialRefinement(dm,&initRefinement);CHKERRQ(ierr); 68856ba9f64SToby Isaac ierr = PetscOptionsInt("-dm_forest_initial_refinement","set the initial level of refinement in the forest","DMForestSetInitialRefinement",initRefinement,&initRefinement,&flg);CHKERRQ(ierr); 68956ba9f64SToby Isaac if (flg) { 69056ba9f64SToby Isaac ierr = DMForestSetInitialRefinement(dm,initRefinement);CHKERRQ(ierr); 69156ba9f64SToby Isaac } 692c7eeac06SToby Isaac ierr = DMForestGetMaximumRefinement(dm,&maxRefinement);CHKERRQ(ierr); 693c7eeac06SToby Isaac ierr = PetscOptionsInt("-dm_forest_maximum_refinement","set the maximum level of refinement in the forest","DMForestSetMaximumRefinement",maxRefinement,&maxRefinement,&flg);CHKERRQ(ierr); 694c7eeac06SToby Isaac if (flg) { 695c7eeac06SToby Isaac ierr = DMForestSetMaximumRefinement(dm,maxRefinement);CHKERRQ(ierr); 696c7eeac06SToby Isaac } 697c7eeac06SToby Isaac ierr = DMForestGetAdaptivityStrategy(dm,&adaptStrategy);CHKERRQ(ierr); 698c7eeac06SToby Isaac ierr = PetscOptionsString("-dm_forest_adaptivity_strategy","the forest's adaptivity-flag resolution strategy","DMForestSetAdaptivityStrategy",adaptStrategy,stringBuffer,256,&flg);CHKERRQ(ierr); 699c7eeac06SToby Isaac if (flg) { 700c7eeac06SToby Isaac ierr = DMForestSetAdaptivityStrategy(dm,(DMForestAdaptivityStrategy)stringBuffer);CHKERRQ(ierr); 701c7eeac06SToby Isaac } 702c7eeac06SToby Isaac ierr = DMForestGetGradeFactor(dm,&grade);CHKERRQ(ierr); 703c7eeac06SToby Isaac ierr = PetscOptionsInt("-dm_forest_grade_factor","grade factor between neighboring cells","DMForestSetGradeFactor",grade,&grade,&flg);CHKERRQ(ierr); 704c7eeac06SToby Isaac if (flg) { 705c7eeac06SToby Isaac ierr = DMForestSetGradeFactor(dm,grade);CHKERRQ(ierr); 706c7eeac06SToby Isaac } 707c7eeac06SToby Isaac ierr = DMForestGetCellWeightFactor(dm,&weightsFactor);CHKERRQ(ierr); 708c7eeac06SToby Isaac ierr = PetscOptionsReal("-dm_forest_cell_weight_factor","multiplying weight factor for cell refinement","DMForestSetCellWeightFactor",weightsFactor,&weightsFactor,&flg);CHKERRQ(ierr); 709c7eeac06SToby Isaac if (flg) { 710c7eeac06SToby Isaac ierr = DMForestSetCellWeightFactor(dm,weightsFactor);CHKERRQ(ierr); 711c7eeac06SToby Isaac } 712db4d5e8cSToby Isaac ierr = PetscOptionsTail();CHKERRQ(ierr); 713db4d5e8cSToby Isaac PetscFunctionReturn(0); 714db4d5e8cSToby Isaac } 715db4d5e8cSToby Isaac 716db4d5e8cSToby Isaac #undef __FUNCT__ 717d222f98bSToby Isaac #define __FUNCT__ "DMInitialize_Forest" 718d222f98bSToby Isaac static PetscErrorCode DMInitialize_Forest(DM dm) 719d222f98bSToby Isaac { 720d222f98bSToby Isaac PetscErrorCode ierr; 721d222f98bSToby Isaac 722d222f98bSToby Isaac PetscFunctionBegin; 723d222f98bSToby Isaac ierr = PetscMemzero(dm->ops,sizeof(*(dm->ops)));CHKERRQ(ierr); 724d222f98bSToby Isaac 725d222f98bSToby Isaac dm->ops->clone = DMClone_Forest; 726d222f98bSToby Isaac dm->ops->setfromoptions = DMSetFromOptions_Forest; 727d222f98bSToby Isaac dm->ops->destroy = DMDestroy_Forest; 728d222f98bSToby Isaac PetscFunctionReturn(0); 729d222f98bSToby Isaac } 730d222f98bSToby Isaac 731d222f98bSToby Isaac #undef __FUNCT__ 732db4d5e8cSToby Isaac #define __FUNCT__ "DMCreate_Forest" 733db4d5e8cSToby Isaac PETSC_EXTERN PetscErrorCode DMCreate_Forest(DM dm) 734db4d5e8cSToby Isaac { 735db4d5e8cSToby Isaac DM_Forest *forest; 736db4d5e8cSToby Isaac PetscErrorCode ierr; 737db4d5e8cSToby Isaac 738db4d5e8cSToby Isaac PetscFunctionBegin; 739db4d5e8cSToby Isaac PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 740db4d5e8cSToby Isaac ierr = PetscNewLog(dm,&forest);CHKERRQ(ierr); 741db4d5e8cSToby Isaac dm->dim = 0; 742db4d5e8cSToby Isaac dm->data = forest; 743db4d5e8cSToby Isaac forest->refct = 1; 744db4d5e8cSToby Isaac forest->data = NULL; 745dd8e54a2SToby Isaac forest->setFromOptions = PETSC_FALSE; 746db4d5e8cSToby Isaac forest->topology = NULL; 747db4d5e8cSToby Isaac forest->base = NULL; 748db4d5e8cSToby Isaac forest->adjDim = PETSC_DEFAULT; 749db4d5e8cSToby Isaac forest->overlap = PETSC_DEFAULT; 750db4d5e8cSToby Isaac forest->minRefinement = PETSC_DEFAULT; 751db4d5e8cSToby Isaac forest->maxRefinement = PETSC_DEFAULT; 75256ba9f64SToby Isaac forest->initRefinement = PETSC_DEFAULT; 753c7eeac06SToby Isaac forest->cStart = PETSC_DETERMINE; 754c7eeac06SToby Isaac forest->cEnd = PETSC_DETERMINE; 755db4d5e8cSToby Isaac forest->cellSF = 0; 756db4d5e8cSToby Isaac forest->adaptMarkers = NULL; 757db4d5e8cSToby Isaac forest->adaptCopyMode = PETSC_USE_POINTER; 758db4d5e8cSToby Isaac forest->gradeFactor = 2; 759db4d5e8cSToby Isaac forest->cellWeights = NULL; 760db4d5e8cSToby Isaac forest->cellWeightsCopyMode = PETSC_USE_POINTER; 761db4d5e8cSToby Isaac forest->weightsFactor = 1.; 762db4d5e8cSToby Isaac forest->weightCapacity = 1.; 763*a73e2921SToby Isaac ierr = DMForestSetAdaptivityStrategy(dm,DMFORESTADAPTALL);CHKERRQ(ierr); 764d222f98bSToby Isaac ierr = DMInitialize_Forest(dm);CHKERRQ(ierr); 765db4d5e8cSToby Isaac PetscFunctionReturn(0); 766db4d5e8cSToby Isaac } 767db4d5e8cSToby Isaac 768