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