19be51f97SToby Isaac #include <petsc/private/dmforestimpl.h> /*I "petscdmforest.h" I*/ 29be51f97SToby Isaac #include <petsc/private/dmimpl.h> /*I "petscdm.h" I*/ 3ef19d27cSToby Isaac #include <petscsf.h> 4db4d5e8cSToby Isaac 527d4645fSToby Isaac PetscBool DMForestPackageInitialized = PETSC_FALSE; 627d4645fSToby Isaac 727d4645fSToby Isaac typedef struct _DMForestTypeLink*DMForestTypeLink; 827d4645fSToby Isaac 927d4645fSToby Isaac struct _DMForestTypeLink 1027d4645fSToby Isaac { 1127d4645fSToby Isaac char *name; 1227d4645fSToby Isaac DMForestTypeLink next; 1327d4645fSToby Isaac }; 1427d4645fSToby Isaac 1527d4645fSToby Isaac DMForestTypeLink DMForestTypeList; 1627d4645fSToby Isaac 1727d4645fSToby Isaac #undef __FUNCT__ 1827d4645fSToby Isaac #define __FUNCT__ "DMForestPackageFinalize" 1927d4645fSToby Isaac static PetscErrorCode DMForestPackageFinalize(void) 2027d4645fSToby Isaac { 2127d4645fSToby Isaac DMForestTypeLink oldLink, link = DMForestTypeList; 2227d4645fSToby Isaac PetscErrorCode ierr; 2327d4645fSToby Isaac 2427d4645fSToby Isaac PetscFunctionBegin; 2527d4645fSToby Isaac while (link) { 2627d4645fSToby Isaac oldLink = link; 27f416af30SBarry Smith ierr = PetscFree(oldLink->name);CHKERRQ(ierr); 2827d4645fSToby Isaac link = oldLink->next; 2927d4645fSToby Isaac ierr = PetscFree(oldLink);CHKERRQ(ierr); 3027d4645fSToby Isaac } 3127d4645fSToby Isaac PetscFunctionReturn(0); 3227d4645fSToby Isaac } 3327d4645fSToby Isaac 3427d4645fSToby Isaac #undef __FUNCT__ 3527d4645fSToby Isaac #define __FUNCT__ "DMForestPackageInitialize" 3627d4645fSToby Isaac static PetscErrorCode DMForestPackageInitialize(void) 3727d4645fSToby Isaac { 3827d4645fSToby Isaac PetscErrorCode ierr; 3927d4645fSToby Isaac 4027d4645fSToby Isaac PetscFunctionBegin; 4127d4645fSToby Isaac if (DMForestPackageInitialized) PetscFunctionReturn(0); 4227d4645fSToby Isaac DMForestPackageInitialized = PETSC_TRUE; 43f885a11aSToby Isaac 4427d4645fSToby Isaac ierr = DMForestRegisterType(DMFOREST);CHKERRQ(ierr); 4527d4645fSToby Isaac ierr = PetscRegisterFinalize(DMForestPackageFinalize);CHKERRQ(ierr); 4627d4645fSToby Isaac PetscFunctionReturn(0); 4727d4645fSToby Isaac } 4827d4645fSToby Isaac 4927d4645fSToby Isaac #undef __FUNCT__ 5027d4645fSToby Isaac #define __FUNCT__ "DMForestRegisterType" 519be51f97SToby Isaac /*@C 529be51f97SToby Isaac DMForestRegisterType - Registers a DMType as a subtype of DMFOREST (so that DMIsForest() will be correct) 539be51f97SToby Isaac 549be51f97SToby Isaac Not Collective 559be51f97SToby Isaac 569be51f97SToby Isaac Input parameter: 579be51f97SToby Isaac . name - the name of the type 589be51f97SToby Isaac 599be51f97SToby Isaac Level: advanced 609be51f97SToby Isaac 619be51f97SToby Isaac .seealso: DMFOREST, DMIsForest() 629be51f97SToby Isaac @*/ 6327d4645fSToby Isaac PetscErrorCode DMForestRegisterType(DMType name) 6427d4645fSToby Isaac { 6527d4645fSToby Isaac DMForestTypeLink link; 6627d4645fSToby Isaac PetscErrorCode ierr; 6727d4645fSToby Isaac 6827d4645fSToby Isaac PetscFunctionBegin; 6927d4645fSToby Isaac ierr = DMForestPackageInitialize();CHKERRQ(ierr); 7027d4645fSToby Isaac ierr = PetscNew(&link);CHKERRQ(ierr); 7127d4645fSToby Isaac ierr = PetscStrallocpy(name,&link->name);CHKERRQ(ierr); 7227d4645fSToby Isaac link->next = DMForestTypeList; 7327d4645fSToby Isaac DMForestTypeList = link; 7427d4645fSToby Isaac PetscFunctionReturn(0); 7527d4645fSToby Isaac } 7627d4645fSToby Isaac 7727d4645fSToby Isaac #undef __FUNCT__ 7827d4645fSToby Isaac #define __FUNCT__ "DMIsForest" 799be51f97SToby Isaac /*@ 809be51f97SToby Isaac DMIsForest - Check whether a DM uses the DMFOREST interface for hierarchically-refined meshes 819be51f97SToby Isaac 829be51f97SToby Isaac Not Collective 839be51f97SToby Isaac 849be51f97SToby Isaac Input parameter: 859be51f97SToby Isaac . dm - the DM object 869be51f97SToby Isaac 879be51f97SToby Isaac Output parameter: 889be51f97SToby Isaac . isForest - whether dm is a subtype of DMFOREST 899be51f97SToby Isaac 909be51f97SToby Isaac Level: intermediate 919be51f97SToby Isaac 929be51f97SToby Isaac .seealso: DMFOREST, DMForestRegisterType() 939be51f97SToby Isaac @*/ 9427d4645fSToby Isaac PetscErrorCode DMIsForest(DM dm, PetscBool *isForest) 9527d4645fSToby Isaac { 9627d4645fSToby Isaac DMForestTypeLink link = DMForestTypeList; 9727d4645fSToby Isaac PetscErrorCode ierr; 9827d4645fSToby Isaac 9927d4645fSToby Isaac PetscFunctionBegin; 10027d4645fSToby Isaac while (link) { 10127d4645fSToby Isaac PetscBool sameType; 10227d4645fSToby Isaac ierr = PetscObjectTypeCompare((PetscObject)dm,link->name,&sameType);CHKERRQ(ierr); 10327d4645fSToby Isaac if (sameType) { 10427d4645fSToby Isaac *isForest = PETSC_TRUE; 10527d4645fSToby Isaac PetscFunctionReturn(0); 10627d4645fSToby Isaac } 10727d4645fSToby Isaac link = link->next; 10827d4645fSToby Isaac } 10927d4645fSToby Isaac *isForest = PETSC_FALSE; 11027d4645fSToby Isaac PetscFunctionReturn(0); 11127d4645fSToby Isaac } 11227d4645fSToby Isaac 113db4d5e8cSToby Isaac #undef __FUNCT__ 114a0452a8eSToby Isaac #define __FUNCT__ "DMForestTemplate" 1159be51f97SToby Isaac /*@ 1169be51f97SToby Isaac DMForestTemplate - Create a new DM that will be adapted from a source DM. The new DM reproduces the configuration 1179be51f97SToby Isaac of the source, but is not yet setup, so that the user can then define only the ways that the new DM should differ 1189be51f97SToby Isaac (by, e.g., refinement or repartitioning). The source DM is also set as the adaptivity source DM of the new DM (see 1199be51f97SToby Isaac DMForestSetAdaptivityForest()). 1209be51f97SToby Isaac 1219be51f97SToby Isaac Collective on dm 1229be51f97SToby Isaac 1239be51f97SToby Isaac Input Parameters: 1249be51f97SToby Isaac + dm - the source DM object 1259be51f97SToby Isaac - comm - the communicator for the new DM (this communicator is currently ignored, but is present so that DMForestTemplate() can be used within DMCoarsen()) 1269be51f97SToby Isaac 1279be51f97SToby Isaac Output Parameter: 1289be51f97SToby Isaac . tdm - the new DM object 1299be51f97SToby Isaac 1309be51f97SToby Isaac Level: intermediate 1319be51f97SToby Isaac 1329be51f97SToby Isaac .seealso: DMForestSetAdaptivityForest() 1339be51f97SToby Isaac @*/ 1349be51f97SToby Isaac PetscErrorCode DMForestTemplate(DM dm, MPI_Comm comm, DM *tdm) 135a0452a8eSToby Isaac { 136a0452a8eSToby Isaac DM_Forest *forest = (DM_Forest*) dm->data; 13720e8089bSToby Isaac DMType type; 138a0452a8eSToby Isaac DM base; 139a0452a8eSToby Isaac DMForestTopology topology; 140a0452a8eSToby Isaac PetscInt dim, overlap, ref, factor; 141a0452a8eSToby Isaac DMForestAdaptivityStrategy strat; 142795844e7SToby Isaac PetscDS ds; 143795844e7SToby Isaac void *ctx; 14449fc9a2fSToby Isaac PetscErrorCode (*map)(DM, PetscInt, PetscInt, const PetscReal[], PetscReal[], void*); 1453e58adeeSToby Isaac void *mapCtx; 146a0452a8eSToby Isaac PetscErrorCode ierr; 147a0452a8eSToby Isaac 148a0452a8eSToby Isaac PetscFunctionBegin; 149a0452a8eSToby Isaac PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 15020e8089bSToby Isaac ierr = DMCreate(PetscObjectComm((PetscObject)dm),tdm);CHKERRQ(ierr); 15120e8089bSToby Isaac ierr = DMGetType(dm,&type);CHKERRQ(ierr); 15220e8089bSToby Isaac ierr = DMSetType(*tdm,type);CHKERRQ(ierr); 153a0452a8eSToby Isaac ierr = DMForestGetBaseDM(dm,&base);CHKERRQ(ierr); 15420e8089bSToby Isaac ierr = DMForestSetBaseDM(*tdm,base);CHKERRQ(ierr); 155a0452a8eSToby Isaac ierr = DMForestGetTopology(dm,&topology);CHKERRQ(ierr); 15620e8089bSToby Isaac ierr = DMForestSetTopology(*tdm,topology);CHKERRQ(ierr); 157a0452a8eSToby Isaac ierr = DMForestGetAdjacencyDimension(dm,&dim);CHKERRQ(ierr); 15820e8089bSToby Isaac ierr = DMForestSetAdjacencyDimension(*tdm,dim);CHKERRQ(ierr); 159a0452a8eSToby Isaac ierr = DMForestGetPartitionOverlap(dm,&overlap);CHKERRQ(ierr); 16020e8089bSToby Isaac ierr = DMForestSetPartitionOverlap(*tdm,overlap);CHKERRQ(ierr); 161a0452a8eSToby Isaac ierr = DMForestGetMinimumRefinement(dm,&ref);CHKERRQ(ierr); 16220e8089bSToby Isaac ierr = DMForestSetMinimumRefinement(*tdm,ref);CHKERRQ(ierr); 163a0452a8eSToby Isaac ierr = DMForestGetMaximumRefinement(dm,&ref);CHKERRQ(ierr); 16420e8089bSToby Isaac ierr = DMForestSetMaximumRefinement(*tdm,ref);CHKERRQ(ierr); 165a0452a8eSToby Isaac ierr = DMForestGetAdaptivityStrategy(dm,&strat);CHKERRQ(ierr); 16620e8089bSToby Isaac ierr = DMForestSetAdaptivityStrategy(*tdm,strat);CHKERRQ(ierr); 167a0452a8eSToby Isaac ierr = DMForestGetGradeFactor(dm,&factor);CHKERRQ(ierr); 16820e8089bSToby Isaac ierr = DMForestSetGradeFactor(*tdm,factor);CHKERRQ(ierr); 1693e58adeeSToby Isaac ierr = DMForestGetBaseCoordinateMapping(dm,&map,&mapCtx);CHKERRQ(ierr); 1705e8c540aSToby Isaac ierr = DMForestSetBaseCoordinateMapping(*tdm,map,mapCtx);CHKERRQ(ierr); 171a0452a8eSToby Isaac if (forest->ftemplate) { 17220e8089bSToby Isaac ierr = (forest->ftemplate)(dm, *tdm);CHKERRQ(ierr); 173a0452a8eSToby Isaac } 17420e8089bSToby Isaac ierr = DMForestSetAdaptivityForest(*tdm,dm);CHKERRQ(ierr); 175795844e7SToby Isaac ierr = DMGetDS(dm,&ds);CHKERRQ(ierr); 176795844e7SToby Isaac ierr = DMSetDS(*tdm,ds);CHKERRQ(ierr); 177795844e7SToby Isaac ierr = DMGetApplicationContext(dm,&ctx);CHKERRQ(ierr); 178795844e7SToby Isaac ierr = DMSetApplicationContext(*tdm,&ctx);CHKERRQ(ierr); 179795844e7SToby Isaac if (dm->maxCell) { 180795844e7SToby Isaac const PetscReal *maxCell, *L; 181795844e7SToby Isaac const DMBoundaryType *bd; 182795844e7SToby Isaac 183795844e7SToby Isaac ierr = DMGetPeriodicity(dm,&maxCell,&L,&bd);CHKERRQ(ierr); 184795844e7SToby Isaac ierr = DMSetPeriodicity(*tdm,maxCell,L,bd);CHKERRQ(ierr); 185795844e7SToby Isaac } 186*bff67a9bSToby Isaac ierr = DMCopyBoundary(dm,*tdm);CHKERRQ(ierr); 187a0452a8eSToby Isaac PetscFunctionReturn(0); 188a0452a8eSToby Isaac } 189a0452a8eSToby Isaac 19001d9d024SToby Isaac static PetscErrorCode DMInitialize_Forest(DM dm); 19101d9d024SToby Isaac 192a0452a8eSToby Isaac #undef __FUNCT__ 193db4d5e8cSToby Isaac #define __FUNCT__ "DMClone_Forest" 194db4d5e8cSToby Isaac PETSC_EXTERN PetscErrorCode DMClone_Forest(DM dm, DM *newdm) 195db4d5e8cSToby Isaac { 196db4d5e8cSToby Isaac DM_Forest *forest = (DM_Forest*) dm->data; 197db4d5e8cSToby Isaac const char *type; 198db4d5e8cSToby Isaac PetscErrorCode ierr; 199db4d5e8cSToby Isaac 200db4d5e8cSToby Isaac PetscFunctionBegin; 201db4d5e8cSToby Isaac forest->refct++; 202db4d5e8cSToby Isaac (*newdm)->data = forest; 203db4d5e8cSToby Isaac ierr = PetscObjectGetType((PetscObject) dm, &type);CHKERRQ(ierr); 204db4d5e8cSToby Isaac ierr = PetscObjectChangeTypeName((PetscObject) *newdm, type);CHKERRQ(ierr); 20501d9d024SToby Isaac ierr = DMInitialize_Forest(*newdm);CHKERRQ(ierr); 206db4d5e8cSToby Isaac PetscFunctionReturn(0); 207db4d5e8cSToby Isaac } 208db4d5e8cSToby Isaac 209db4d5e8cSToby Isaac #undef __FUNCT__ 210db4d5e8cSToby Isaac #define __FUNCT__ "DMDestroy_Forest" 211d222f98bSToby Isaac static PetscErrorCode DMDestroy_Forest(DM dm) 212db4d5e8cSToby Isaac { 213db4d5e8cSToby Isaac DM_Forest *forest = (DM_Forest*) dm->data; 214db4d5e8cSToby Isaac PetscErrorCode ierr; 215db4d5e8cSToby Isaac 216db4d5e8cSToby Isaac PetscFunctionBegin; 217db4d5e8cSToby Isaac if (--forest->refct > 0) PetscFunctionReturn(0); 218d222f98bSToby Isaac if (forest->destroy) {ierr = forest->destroy(dm);CHKERRQ(ierr);} 219db4d5e8cSToby Isaac ierr = PetscSFDestroy(&forest->cellSF);CHKERRQ(ierr); 2200f17b9e3SToby Isaac ierr = PetscSFDestroy(&forest->preCoarseToFine);CHKERRQ(ierr); 2210f17b9e3SToby Isaac ierr = PetscSFDestroy(&forest->coarseToPreFine);CHKERRQ(ierr); 222ebdf65a2SToby Isaac ierr = PetscFree(forest->adaptLabel);CHKERRQ(ierr); 2239a81d013SToby Isaac ierr = PetscFree(forest->adaptStrategy);CHKERRQ(ierr); 22456ba9f64SToby Isaac ierr = DMDestroy(&forest->base);CHKERRQ(ierr); 225ba936b91SToby Isaac ierr = DMDestroy(&forest->adapt);CHKERRQ(ierr); 22630f902e7SToby Isaac ierr = PetscFree(forest->topology);CHKERRQ(ierr); 22730f902e7SToby Isaac ierr = PetscFree(forest);CHKERRQ(ierr); 228db4d5e8cSToby Isaac PetscFunctionReturn(0); 229db4d5e8cSToby Isaac } 230db4d5e8cSToby Isaac 231db4d5e8cSToby Isaac #undef __FUNCT__ 232dd8e54a2SToby Isaac #define __FUNCT__ "DMForestSetTopology" 2339be51f97SToby Isaac /*@C 2349be51f97SToby Isaac DMForestSetTopology - Set the topology of a DMForest during the pre-setup phase. The topology is a string (e.g. 2359be51f97SToby Isaac "cube", "shell") and can be interpreted by subtypes of DMFOREST) to construct the base DM of a forest durint 2369be51f97SToby Isaac DMSetUp(). 2379be51f97SToby Isaac 2389be51f97SToby Isaac Logically collective on dm 2399be51f97SToby Isaac 2409be51f97SToby Isaac Input parameters: 2419be51f97SToby Isaac + dm - the forest 2429be51f97SToby Isaac - topology - the topology of the forest 2439be51f97SToby Isaac 2449be51f97SToby Isaac Level: intermediate 2459be51f97SToby Isaac 2469be51f97SToby Isaac .seealso(): DMForestGetTopology(), DMForestSetBaseDM() 2479be51f97SToby Isaac @*/ 248dd8e54a2SToby Isaac PetscErrorCode DMForestSetTopology(DM dm, DMForestTopology topology) 249db4d5e8cSToby Isaac { 250db4d5e8cSToby Isaac DM_Forest *forest = (DM_Forest*) dm->data; 251db4d5e8cSToby Isaac PetscErrorCode ierr; 252db4d5e8cSToby Isaac 253db4d5e8cSToby Isaac PetscFunctionBegin; 254db4d5e8cSToby Isaac PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 255ef51cf95SToby Isaac if (dm->setupcalled) SETERRQ(PetscObjectComm((PetscObject)dm),PETSC_ERR_ARG_WRONGSTATE,"Cannot change the topology after setup"); 256dd8e54a2SToby Isaac ierr = PetscFree(forest->topology);CHKERRQ(ierr); 257dd8e54a2SToby Isaac ierr = PetscStrallocpy((const char*)topology,(char**) &forest->topology);CHKERRQ(ierr); 258db4d5e8cSToby Isaac PetscFunctionReturn(0); 259db4d5e8cSToby Isaac } 260db4d5e8cSToby Isaac 261db4d5e8cSToby Isaac #undef __FUNCT__ 262dd8e54a2SToby Isaac #define __FUNCT__ "DMForestGetTopology" 2639be51f97SToby Isaac /*@C 2649be51f97SToby Isaac DMForestGetTopology - Get a string describing the topology of a DMForest. 2659be51f97SToby Isaac 2669be51f97SToby Isaac Not collective 2679be51f97SToby Isaac 2689be51f97SToby Isaac Input parameter: 2699be51f97SToby Isaac . dm - the forest 2709be51f97SToby Isaac 2719be51f97SToby Isaac Output parameter: 2729be51f97SToby Isaac . topology - the topology of the forest (e.g., 'cube', 'shell') 2739be51f97SToby Isaac 2749be51f97SToby Isaac Level: intermediate 2759be51f97SToby Isaac 2769be51f97SToby Isaac .seealso: DMForestSetTopology() 2779be51f97SToby Isaac @*/ 278dd8e54a2SToby Isaac PetscErrorCode DMForestGetTopology(DM dm, DMForestTopology *topology) 279dd8e54a2SToby Isaac { 280dd8e54a2SToby Isaac DM_Forest *forest = (DM_Forest*) dm->data; 281dd8e54a2SToby Isaac 282dd8e54a2SToby Isaac PetscFunctionBegin; 283dd8e54a2SToby Isaac PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 284dd8e54a2SToby Isaac PetscValidPointer(topology,2); 285dd8e54a2SToby Isaac *topology = forest->topology; 286dd8e54a2SToby Isaac PetscFunctionReturn(0); 287dd8e54a2SToby Isaac } 288dd8e54a2SToby Isaac 289dd8e54a2SToby Isaac #undef __FUNCT__ 290dd8e54a2SToby Isaac #define __FUNCT__ "DMForestSetBaseDM" 2919be51f97SToby Isaac /*@ 2929be51f97SToby Isaac DMForestSetBaseDM - During the pre-setup phase, set the DM that defines the base mesh of a DMForest forest. The 2939be51f97SToby Isaac forest will be hierarchically refined from the base, and all refinements/coarsenings of the forest will share its 2949be51f97SToby Isaac base. In general, two forest must share a bse to be comparable, to do things like construct interpolators. 2959be51f97SToby Isaac 2969be51f97SToby Isaac Logically collective on dm 2979be51f97SToby Isaac 2989be51f97SToby Isaac Input Parameters: 2999be51f97SToby Isaac + dm - the forest 3009be51f97SToby Isaac - base - the base DM of the forest 3019be51f97SToby Isaac 3029be51f97SToby Isaac Level: intermediate 3039be51f97SToby Isaac 3049be51f97SToby Isaac .seealso(): DMForestGetBaseDM() 3059be51f97SToby Isaac @*/ 306dd8e54a2SToby Isaac PetscErrorCode DMForestSetBaseDM(DM dm, DM base) 307dd8e54a2SToby Isaac { 308dd8e54a2SToby Isaac DM_Forest *forest = (DM_Forest*) dm->data; 309dd8e54a2SToby Isaac PetscInt dim, dimEmbed; 310dd8e54a2SToby Isaac PetscErrorCode ierr; 311dd8e54a2SToby Isaac 312dd8e54a2SToby Isaac PetscFunctionBegin; 313dd8e54a2SToby Isaac PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 314ef51cf95SToby Isaac if (dm->setupcalled) SETERRQ(PetscObjectComm((PetscObject)dm),PETSC_ERR_ARG_WRONGSTATE,"Cannot change the base after setup"); 315dd8e54a2SToby Isaac ierr = PetscObjectReference((PetscObject)base);CHKERRQ(ierr); 316dd8e54a2SToby Isaac ierr = DMDestroy(&forest->base);CHKERRQ(ierr); 317dd8e54a2SToby Isaac forest->base = base; 318a0452a8eSToby Isaac if (base) { 319a0452a8eSToby Isaac PetscValidHeaderSpecific(base, DM_CLASSID, 2); 320dd8e54a2SToby Isaac ierr = DMGetDimension(base,&dim);CHKERRQ(ierr); 321dd8e54a2SToby Isaac ierr = DMSetDimension(dm,dim);CHKERRQ(ierr); 322dd8e54a2SToby Isaac ierr = DMGetCoordinateDim(base,&dimEmbed);CHKERRQ(ierr); 323dd8e54a2SToby Isaac ierr = DMSetCoordinateDim(dm,dimEmbed);CHKERRQ(ierr); 324a0452a8eSToby Isaac } 325dd8e54a2SToby Isaac PetscFunctionReturn(0); 326dd8e54a2SToby Isaac } 327dd8e54a2SToby Isaac 328dd8e54a2SToby Isaac #undef __FUNCT__ 329dd8e54a2SToby Isaac #define __FUNCT__ "DMForestGetBaseDM" 3309be51f97SToby Isaac /*@ 3319be51f97SToby Isaac DMForestGetBaseDM - Get the base DM of a DMForest forest. The forest will be hierarchically refined from the base, 3329be51f97SToby Isaac and all refinements/coarsenings of the forest will share its base. In general, two forest must share a bse to be 3339be51f97SToby Isaac comparable, to do things like construct interpolators. 3349be51f97SToby Isaac 3359be51f97SToby Isaac Not collective 3369be51f97SToby Isaac 3379be51f97SToby Isaac Input Parameter: 3389be51f97SToby Isaac . dm - the forest 3399be51f97SToby Isaac 3409be51f97SToby Isaac Output Parameter: 3419be51f97SToby Isaac . base - the base DM of the forest 3429be51f97SToby Isaac 3439be51f97SToby Isaac Level: intermediate 3449be51f97SToby Isaac 3459be51f97SToby Isaac .seealso(); DMForestSetBaseDM() 3469be51f97SToby Isaac @*/ 347dd8e54a2SToby Isaac PetscErrorCode DMForestGetBaseDM(DM dm, DM *base) 348dd8e54a2SToby Isaac { 349dd8e54a2SToby Isaac DM_Forest *forest = (DM_Forest*) dm->data; 350dd8e54a2SToby Isaac 351dd8e54a2SToby Isaac PetscFunctionBegin; 352dd8e54a2SToby Isaac PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 353dd8e54a2SToby Isaac PetscValidPointer(base, 2); 354dd8e54a2SToby Isaac *base = forest->base; 355dd8e54a2SToby Isaac PetscFunctionReturn(0); 356dd8e54a2SToby Isaac } 357dd8e54a2SToby Isaac 358dd8e54a2SToby Isaac #undef __FUNCT__ 359cf38a08cSToby Isaac #define __FUNCT__ "DMForestSetBaseCoordinateMapping" 36099478f86SToby Isaac PetscErrorCode DMForestSetBaseCoordinateMapping(DM dm, PetscErrorCode (*func)(DM,PetscInt,PetscInt,const PetscReal [],PetscReal [],void*),void *ctx) 361cf38a08cSToby Isaac { 362cf38a08cSToby Isaac DM_Forest *forest = (DM_Forest*) dm->data; 363cf38a08cSToby Isaac 364cf38a08cSToby Isaac PetscFunctionBegin; 365cf38a08cSToby Isaac PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 366cf38a08cSToby Isaac forest->mapcoordinates = func; 367cf38a08cSToby Isaac forest->mapcoordinatesctx = ctx; 368cf38a08cSToby Isaac PetscFunctionReturn(0); 369cf38a08cSToby Isaac } 370cf38a08cSToby Isaac 371cf38a08cSToby Isaac #undef __FUNCT__ 372cf38a08cSToby Isaac #define __FUNCT__ "DMForestGetBaseCoordinateMapping" 37399478f86SToby Isaac PetscErrorCode DMForestGetBaseCoordinateMapping(DM dm, PetscErrorCode (**func) (DM,PetscInt,PetscInt,const PetscReal [],PetscReal [],void*),void *ctx) 374cf38a08cSToby Isaac { 375cf38a08cSToby Isaac DM_Forest *forest = (DM_Forest*) dm->data; 376cf38a08cSToby Isaac 377cf38a08cSToby Isaac PetscFunctionBegin; 378cf38a08cSToby Isaac PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 379cf38a08cSToby Isaac if (func) *func = forest->mapcoordinates; 380cf38a08cSToby Isaac if (ctx) *((void**) ctx) = forest->mapcoordinatesctx; 381cf38a08cSToby Isaac PetscFunctionReturn(0); 382cf38a08cSToby Isaac } 383cf38a08cSToby Isaac 384cf38a08cSToby Isaac #undef __FUNCT__ 385ba936b91SToby Isaac #define __FUNCT__ "DMForestSetAdaptivityForest" 3869be51f97SToby Isaac /*@ 3879be51f97SToby Isaac DMForestSetAdaptivityForest - During the pre-setup phase, set the forest from which the current forest will be 3889be51f97SToby Isaac adapted (e.g., the current forest will be refined/coarsened/repartitioned from it) im DMSetUp(). Usually not needed 3899be51f97SToby Isaac by users directly: DMForestTemplate() constructs a new forest to be adapted from an old forest and calls this 3909be51f97SToby Isaac routine. 3919be51f97SToby Isaac 392dffe73a3SToby Isaac Note that this can be called after setup with adapt = NULL, which will clear all internal data related to the 393dffe73a3SToby Isaac adaptivity forest from dm. This way, repeatedly adapting does not leave stale DM objects in memory. 394dffe73a3SToby Isaac 3959be51f97SToby Isaac Logically collective on dm 3969be51f97SToby Isaac 3979be51f97SToby Isaac Input Parameter: 3989be51f97SToby Isaac + dm - the new forest, which will be constructed from adapt 3999be51f97SToby Isaac - adapt - the old forest 4009be51f97SToby Isaac 4019be51f97SToby Isaac Level: intermediate 4029be51f97SToby Isaac 4039be51f97SToby Isaac .seealso: DMForestGetAdaptivityForest(), DMForestSetAdaptivityPurpose() 4049be51f97SToby Isaac @*/ 405ba936b91SToby Isaac PetscErrorCode DMForestSetAdaptivityForest(DM dm,DM adapt) 406dd8e54a2SToby Isaac { 407dffe73a3SToby Isaac DM_Forest *forest, *adaptForest, *oldAdaptForest; 408dffe73a3SToby Isaac DM oldAdapt; 409dd8e54a2SToby Isaac PetscErrorCode ierr; 410dd8e54a2SToby Isaac 411dd8e54a2SToby Isaac PetscFunctionBegin; 412dd8e54a2SToby Isaac PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 413ba936b91SToby Isaac PetscValidHeaderSpecific(dm, DM_CLASSID, 2); 414ba936b91SToby Isaac forest = (DM_Forest*) dm->data; 415dffe73a3SToby Isaac ierr = DMForestGetAdaptivityForest(dm,&oldAdapt);CHKERRQ(ierr); 416dffe73a3SToby Isaac if (adapt != NULL && dm->setupcalled) SETERRQ(PetscObjectComm((PetscObject)dm),PETSC_ERR_ARG_WRONGSTATE,"Cannot change the adaptation forest after setup"); 417dffe73a3SToby Isaac adaptForest = (DM_Forest*) adapt ? adapt->data : NULL; 418dffe73a3SToby Isaac oldAdaptForest = (DM_Forest*) oldAdapt ? oldAdapt->data : NULL; 419dffe73a3SToby Isaac if (adaptForest != oldAdaptForest) { 420dffe73a3SToby Isaac ierr = PetscSFDestroy(&forest->preCoarseToFine);CHKERRQ(ierr); 421dffe73a3SToby Isaac ierr = PetscSFDestroy(&forest->coarseToPreFine);CHKERRQ(ierr); 422dffe73a3SToby Isaac if (forest->clearadaptivityforest) {ierr = (forest->clearadaptivityforest)(dm);CHKERRQ(ierr);} 423dffe73a3SToby Isaac } 42426d9498aSToby Isaac switch (forest->adaptPurpose) { 42526d9498aSToby Isaac case DM_FOREST_KEEP: 426ba936b91SToby Isaac ierr = PetscObjectReference((PetscObject)adapt);CHKERRQ(ierr); 427ba936b91SToby Isaac ierr = DMDestroy(&(forest->adapt));CHKERRQ(ierr); 428ba936b91SToby Isaac forest->adapt = adapt; 42926d9498aSToby Isaac break; 43026d9498aSToby Isaac case DM_FOREST_REFINE: 43126d9498aSToby Isaac ierr = DMSetCoarseDM(dm,adapt);CHKERRQ(ierr); 43226d9498aSToby Isaac break; 43326d9498aSToby Isaac case DM_FOREST_COARSEN: 43426d9498aSToby Isaac ierr = DMSetFineDM(dm,adapt);CHKERRQ(ierr); 43526d9498aSToby Isaac break; 43626d9498aSToby Isaac default: 43726d9498aSToby Isaac SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_OUTOFRANGE,"invalid adaptivity purpose"); 43826d9498aSToby Isaac } 439dd8e54a2SToby Isaac PetscFunctionReturn(0); 440dd8e54a2SToby Isaac } 441dd8e54a2SToby Isaac 442dd8e54a2SToby Isaac #undef __FUNCT__ 443ba936b91SToby Isaac #define __FUNCT__ "DMForestGetAdaptivityForest" 4449be51f97SToby Isaac /*@ 4459be51f97SToby Isaac DMForestGetAdaptivityForest - Get the forest from which the current forest is adapted. 4469be51f97SToby Isaac 4479be51f97SToby Isaac Not collective 4489be51f97SToby Isaac 4499be51f97SToby Isaac Input Parameter: 4509be51f97SToby Isaac . dm - the forest 4519be51f97SToby Isaac 4529be51f97SToby Isaac Output Parameter: 4539be51f97SToby Isaac . adapt - the forest from which dm is/was adapted 4549be51f97SToby Isaac 4559be51f97SToby Isaac Level: intermediate 4569be51f97SToby Isaac 4579be51f97SToby Isaac .seealso: DMForestSetAdaptivityForest(), DMForestSetAdaptivityPurpose() 4589be51f97SToby Isaac @*/ 459ba936b91SToby Isaac PetscErrorCode DMForestGetAdaptivityForest(DM dm, DM *adapt) 460dd8e54a2SToby Isaac { 461ba936b91SToby Isaac DM_Forest *forest; 46226d9498aSToby Isaac PetscErrorCode ierr; 463dd8e54a2SToby Isaac 464dd8e54a2SToby Isaac PetscFunctionBegin; 465dd8e54a2SToby Isaac PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 466ba936b91SToby Isaac forest = (DM_Forest*) dm->data; 46726d9498aSToby Isaac switch (forest->adaptPurpose) { 46826d9498aSToby Isaac case DM_FOREST_KEEP: 469ba936b91SToby Isaac *adapt = forest->adapt; 47026d9498aSToby Isaac break; 47126d9498aSToby Isaac case DM_FOREST_REFINE: 47226d9498aSToby Isaac ierr = DMGetCoarseDM(dm,adapt);CHKERRQ(ierr); 47326d9498aSToby Isaac break; 47426d9498aSToby Isaac case DM_FOREST_COARSEN: 47526d9498aSToby Isaac ierr = DMGetFineDM(dm,adapt);CHKERRQ(ierr); 47626d9498aSToby Isaac break; 47726d9498aSToby Isaac default: 47826d9498aSToby Isaac SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_OUTOFRANGE,"invalid adaptivity purpose"); 47926d9498aSToby Isaac } 48026d9498aSToby Isaac PetscFunctionReturn(0); 48126d9498aSToby Isaac } 48226d9498aSToby Isaac 48326d9498aSToby Isaac #undef __FUNCT__ 48426d9498aSToby Isaac #define __FUNCT__ "DMForestSetAdaptivityPurpose" 4859be51f97SToby Isaac /*@ 4869be51f97SToby Isaac DMForestSetAdaptivityPurpose - During the pre-setup phase, set whether the current DM is being adapted from its 4879be51f97SToby Isaac source (set with DMForestSetAdaptivityForest()) for the purpose of refinement (DM_FOREST_REFINE), coarsening 4889be51f97SToby Isaac (DM_FOREST_COARSEN), or undefined (DM_FOREST_NONE). This only matters for the purposes of reference counting: 4899be51f97SToby Isaac during DMDestroy(), cyclic references can be found between DMs only if the cyclic reference is due to a fine/coarse 4909be51f97SToby Isaac relationship (see DMSetFineDM()/DMSetCoarseDM()). If the purpose is not refinement or coarsening, and the user does 4919be51f97SToby Isaac not maintain a reference to the post-adaptation forest (i.e., the one created by DMForestTemplate()), then this can 4929be51f97SToby Isaac cause a memory leak. This method is used by subtypes of DMForest when automatically constructing mesh hierarchies. 4939be51f97SToby Isaac 4949be51f97SToby Isaac Logically collective on dm 4959be51f97SToby Isaac 4969be51f97SToby Isaac Input Parameters: 4979be51f97SToby Isaac + dm - the forest 4989be51f97SToby Isaac - purpose - the adaptivity purpose (DM_FOREST_NONE/DM_FOREST_REFINE/DM_FOREST_COARSEN) 4999be51f97SToby Isaac 5009be51f97SToby Isaac Level: advanced 5019be51f97SToby Isaac 5029be51f97SToby Isaac .seealso: DMForestTemplate(), DMForestSetAdaptivityForest(), DMForestGetAdaptivityForest() 5039be51f97SToby Isaac @*/ 50426d9498aSToby Isaac PetscErrorCode DMForestSetAdaptivityPurpose(DM dm, DMForestAdaptivityPurpose purpose) 50526d9498aSToby Isaac { 50626d9498aSToby Isaac DM_Forest *forest; 50726d9498aSToby Isaac PetscErrorCode ierr; 50826d9498aSToby Isaac 50926d9498aSToby Isaac PetscFunctionBegin; 51026d9498aSToby Isaac forest = (DM_Forest*) dm->data; 5119be51f97SToby Isaac if (dm->setupcalled) SETERRQ(PetscObjectComm((PetscObject)dm),PETSC_ERR_ARG_WRONGSTATE,"Cannot change the adaptation forest after setup"); 51226d9498aSToby Isaac if (purpose != forest->adaptPurpose) { 51326d9498aSToby Isaac DM adapt; 51426d9498aSToby Isaac 51526d9498aSToby Isaac ierr = DMForestGetAdaptivityForest(dm,&adapt);CHKERRQ(ierr); 51626d9498aSToby Isaac ierr = PetscObjectReference((PetscObject)adapt);CHKERRQ(ierr); 51726d9498aSToby Isaac ierr = DMForestSetAdaptivityForest(dm,NULL);CHKERRQ(ierr); 518f885a11aSToby Isaac 51926d9498aSToby Isaac forest->adaptPurpose = purpose; 520f885a11aSToby Isaac 52126d9498aSToby Isaac ierr = DMForestSetAdaptivityForest(dm,adapt);CHKERRQ(ierr); 52226d9498aSToby Isaac ierr = DMDestroy(&adapt);CHKERRQ(ierr); 52326d9498aSToby Isaac } 524dd8e54a2SToby Isaac PetscFunctionReturn(0); 525dd8e54a2SToby Isaac } 526dd8e54a2SToby Isaac 527dd8e54a2SToby Isaac #undef __FUNCT__ 52856c0450aSToby Isaac #define __FUNCT__ "DMForestGetAdaptivityPurpose" 52956c0450aSToby Isaac /*@ 53056c0450aSToby Isaac DMForestGetAdaptivityPurpose - Get whether the current DM is being adapted from its source (set with 53156c0450aSToby Isaac DMForestSetAdaptivityForest()) for the purpose of refinement (DM_FOREST_REFINE), coarsening (DM_FOREST_COARSEN), or 53256c0450aSToby Isaac undefined (DM_FOREST_NONE). This only matters for the purposes of reference counting: during DMDestroy(), cyclic 53356c0450aSToby Isaac references can be found between DMs only if the cyclic reference is due to a fine/coarse relationship (see 53456c0450aSToby Isaac DMSetFineDM()/DMSetCoarseDM()). If the purpose is not refinement or coarsening, and the user does not maintain a 53556c0450aSToby Isaac reference to the post-adaptation forest (i.e., the one created by DMForestTemplate()), then this can cause a memory 53656c0450aSToby Isaac leak. This method is used by subtypes of DMForest when automatically constructing mesh hierarchies. 53756c0450aSToby Isaac 53856c0450aSToby Isaac Not collective 53956c0450aSToby Isaac 54056c0450aSToby Isaac Input Parameter: 54156c0450aSToby Isaac . dm - the forest 54256c0450aSToby Isaac 54356c0450aSToby Isaac Output Parameter: 54456c0450aSToby Isaac . purpose - the adaptivity purpose (DM_FOREST_NONE/DM_FOREST_REFINE/DM_FOREST_COARSEN) 54556c0450aSToby Isaac 54656c0450aSToby Isaac Level: advanced 54756c0450aSToby Isaac 54856c0450aSToby Isaac .seealso: DMForestTemplate(), DMForestSetAdaptivityForest(), DMForestGetAdaptivityForest() 54956c0450aSToby Isaac @*/ 55056c0450aSToby Isaac PetscErrorCode DMForestGetAdaptivityPurpose(DM dm, DMForestAdaptivityPurpose *purpose) 55156c0450aSToby Isaac { 55256c0450aSToby Isaac DM_Forest *forest; 55356c0450aSToby Isaac 55456c0450aSToby Isaac PetscFunctionBegin; 55556c0450aSToby Isaac forest = (DM_Forest*) dm->data; 55656c0450aSToby Isaac *purpose = forest->adaptPurpose; 55756c0450aSToby Isaac PetscFunctionReturn(0); 55856c0450aSToby Isaac } 55956c0450aSToby Isaac 56056c0450aSToby Isaac #undef __FUNCT__ 561dd8e54a2SToby Isaac #define __FUNCT__ "DMForestSetAdjacencyDimension" 5629be51f97SToby Isaac /*@ 5639be51f97SToby Isaac DMForestSetAdjacencyDimension - During the pre-setup phase, set the dimension of interface points that determine 5649be51f97SToby Isaac cell adjacency (for the purposes of partitioning and overlap). 5659be51f97SToby Isaac 5669be51f97SToby Isaac Logically collective on dm 5679be51f97SToby Isaac 5689be51f97SToby Isaac Input Parameters: 5699be51f97SToby Isaac + dm - the forest 5709be51f97SToby Isaac - adjDim - default 0 (i.e., vertices determine adjacency) 5719be51f97SToby Isaac 5729be51f97SToby Isaac Level: intermediate 5739be51f97SToby Isaac 5749be51f97SToby Isaac .seealso: DMForestGetAdjacencyDimension(), DMForestSetAdjacencyCodimension(), DMForestSetPartitionOverlap() 5759be51f97SToby Isaac @*/ 576dd8e54a2SToby Isaac PetscErrorCode DMForestSetAdjacencyDimension(DM dm, PetscInt adjDim) 577dd8e54a2SToby Isaac { 578dd8e54a2SToby Isaac PetscInt dim; 579dd8e54a2SToby Isaac DM_Forest *forest = (DM_Forest*) dm->data; 580dd8e54a2SToby Isaac PetscErrorCode ierr; 581dd8e54a2SToby Isaac 582dd8e54a2SToby Isaac PetscFunctionBegin; 583dd8e54a2SToby Isaac PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 584ef51cf95SToby Isaac if (dm->setupcalled) SETERRQ(PetscObjectComm((PetscObject)dm),PETSC_ERR_ARG_WRONGSTATE,"Cannot change the adjacency dimension after setup"); 585dd8e54a2SToby Isaac if (adjDim < 0) SETERRQ1(PetscObjectComm((PetscObject)dm),PETSC_ERR_ARG_OUTOFRANGE,"adjacency dim cannot be < 0: %d", adjDim); 586dd8e54a2SToby Isaac ierr = DMGetDimension(dm,&dim);CHKERRQ(ierr); 587dd8e54a2SToby Isaac if (adjDim > dim) SETERRQ2(PetscObjectComm((PetscObject)dm),PETSC_ERR_ARG_OUTOFRANGE,"adjacency dim cannot be > %d: %d", dim, adjDim); 588dd8e54a2SToby Isaac forest->adjDim = adjDim; 589dd8e54a2SToby Isaac PetscFunctionReturn(0); 590dd8e54a2SToby Isaac } 591dd8e54a2SToby Isaac 592dd8e54a2SToby Isaac #undef __FUNCT__ 593dd8e54a2SToby Isaac #define __FUNCT__ "DMForestSetAdjacencyCodimension" 5949be51f97SToby Isaac /*@ 5959be51f97SToby Isaac DMForestSetAdjacencyCodimension - Like DMForestSetAdjacencyDimension(), but specified as a co-dimension (so that, 5969be51f97SToby Isaac e.g., adjacency based on facets can be specified by codimension 1 in all cases) 5979be51f97SToby Isaac 5989be51f97SToby Isaac Logically collective on dm 5999be51f97SToby Isaac 6009be51f97SToby Isaac Input Parameters: 6019be51f97SToby Isaac + dm - the forest 6029be51f97SToby Isaac - adjCodim - default isthe dimension of the forest (see DMGetDimension()), since this is the codimension of vertices 6039be51f97SToby Isaac 6049be51f97SToby Isaac Level: intermediate 6059be51f97SToby Isaac 6069be51f97SToby Isaac .seealso: DMForestGetAdjacencyCodimension(), DMForestSetAdjacencyDimension() 6079be51f97SToby Isaac @*/ 608dd8e54a2SToby Isaac PetscErrorCode DMForestSetAdjacencyCodimension(DM dm, PetscInt adjCodim) 609dd8e54a2SToby Isaac { 610dd8e54a2SToby Isaac PetscInt dim; 611dd8e54a2SToby Isaac PetscErrorCode ierr; 612dd8e54a2SToby Isaac 613dd8e54a2SToby Isaac PetscFunctionBegin; 614dd8e54a2SToby Isaac PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 615dd8e54a2SToby Isaac ierr = DMGetDimension(dm,&dim);CHKERRQ(ierr); 616dd8e54a2SToby Isaac ierr = DMForestSetAdjacencyDimension(dm,dim-adjCodim);CHKERRQ(ierr); 617dd8e54a2SToby Isaac PetscFunctionReturn(0); 618dd8e54a2SToby Isaac } 619dd8e54a2SToby Isaac 620dd8e54a2SToby Isaac #undef __FUNCT__ 621dd8e54a2SToby Isaac #define __FUNCT__ "DMForestGetAdjacencyDimension" 6229be51f97SToby Isaac /*@ 6239be51f97SToby Isaac DMForestGetAdjacencyDimension - Get the dimension of interface points that determine cell adjacency (for the 6249be51f97SToby Isaac purposes of partitioning and overlap). 6259be51f97SToby Isaac 6269be51f97SToby Isaac Not collective 6279be51f97SToby Isaac 6289be51f97SToby Isaac Input Parameter: 6299be51f97SToby Isaac . dm - the forest 6309be51f97SToby Isaac 6319be51f97SToby Isaac Output Parameter: 6329be51f97SToby Isaac . adjDim - default 0 (i.e., vertices determine adjacency) 6339be51f97SToby Isaac 6349be51f97SToby Isaac Level: intermediate 6359be51f97SToby Isaac 6369be51f97SToby Isaac .seealso: DMForestSetAdjacencyDimension(), DMForestGetAdjacencyCodimension(), DMForestSetPartitionOverlap() 6379be51f97SToby Isaac @*/ 638dd8e54a2SToby Isaac PetscErrorCode DMForestGetAdjacencyDimension(DM dm, PetscInt *adjDim) 639dd8e54a2SToby Isaac { 640dd8e54a2SToby Isaac DM_Forest *forest = (DM_Forest*) dm->data; 641dd8e54a2SToby Isaac 642dd8e54a2SToby Isaac PetscFunctionBegin; 643dd8e54a2SToby Isaac PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 644dd8e54a2SToby Isaac PetscValidIntPointer(adjDim,2); 645dd8e54a2SToby Isaac *adjDim = forest->adjDim; 646dd8e54a2SToby Isaac PetscFunctionReturn(0); 647dd8e54a2SToby Isaac } 648dd8e54a2SToby Isaac 649dd8e54a2SToby Isaac #undef __FUNCT__ 650dd8e54a2SToby Isaac #define __FUNCT__ "DMForestGetAdjacencyCodimension" 6519be51f97SToby Isaac /*@ 6529be51f97SToby Isaac DMForestGetAdjacencyCodimension - Like DMForestGetAdjacencyDimension(), but specified as a co-dimension (so that, 6539be51f97SToby Isaac e.g., adjacency based on facets can be specified by codimension 1 in all cases) 6549be51f97SToby Isaac 6559be51f97SToby Isaac Not collective 6569be51f97SToby Isaac 6579be51f97SToby Isaac Input Parameter: 6589be51f97SToby Isaac . dm - the forest 6599be51f97SToby Isaac 6609be51f97SToby Isaac Output Parameter: 6619be51f97SToby Isaac . adjCodim - default isthe dimension of the forest (see DMGetDimension()), since this is the codimension of vertices 6629be51f97SToby Isaac 6639be51f97SToby Isaac Level: intermediate 6649be51f97SToby Isaac 6659be51f97SToby Isaac .seealso: DMForestSetAdjacencyCodimension(), DMForestGetAdjacencyDimension() 6669be51f97SToby Isaac @*/ 667dd8e54a2SToby Isaac PetscErrorCode DMForestGetAdjacencyCodimension(DM dm, PetscInt *adjCodim) 668dd8e54a2SToby Isaac { 669dd8e54a2SToby Isaac DM_Forest *forest = (DM_Forest*) dm->data; 670dd8e54a2SToby Isaac PetscInt dim; 671dd8e54a2SToby Isaac PetscErrorCode ierr; 672dd8e54a2SToby Isaac 673dd8e54a2SToby Isaac PetscFunctionBegin; 674dd8e54a2SToby Isaac PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 675dd8e54a2SToby Isaac PetscValidIntPointer(adjCodim,2); 676dd8e54a2SToby Isaac ierr = DMGetDimension(dm,&dim);CHKERRQ(ierr); 677dd8e54a2SToby Isaac *adjCodim = dim - forest->adjDim; 678dd8e54a2SToby Isaac PetscFunctionReturn(0); 679dd8e54a2SToby Isaac } 680dd8e54a2SToby Isaac 681dd8e54a2SToby Isaac #undef __FUNCT__ 682ef51cf95SToby Isaac #define __FUNCT__ "DMForestSetPartitionOverlap" 6839be51f97SToby Isaac /*@ 6849be51f97SToby Isaac DMForestSetPartitionOverlap - During the pre-setup phase, set the amount of cell-overlap present in parallel 6859be51f97SToby Isaac partitions of a forest, with values > 0 indicating subdomains that are expanded by that many iterations of adding 6869be51f97SToby Isaac adjacent cells 6879be51f97SToby Isaac 6889be51f97SToby Isaac Logically collective on dm 6899be51f97SToby Isaac 6909be51f97SToby Isaac Input Parameters: 6919be51f97SToby Isaac + dm - the forest 6929be51f97SToby Isaac - overlap - default 0 6939be51f97SToby Isaac 6949be51f97SToby Isaac Level: intermediate 6959be51f97SToby Isaac 6969be51f97SToby Isaac .seealso: DMForestGetPartitionOverlap(), DMForestSetAdjacencyDimension(), DMForestSetAdjacencyCodimension() 6979be51f97SToby Isaac @*/ 698dd8e54a2SToby Isaac PetscErrorCode DMForestSetPartitionOverlap(DM dm, PetscInt overlap) 699dd8e54a2SToby Isaac { 700dd8e54a2SToby Isaac DM_Forest *forest = (DM_Forest*) dm->data; 701dd8e54a2SToby Isaac 702dd8e54a2SToby Isaac PetscFunctionBegin; 703dd8e54a2SToby Isaac PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 704ef51cf95SToby Isaac if (dm->setupcalled) SETERRQ(PetscObjectComm((PetscObject)dm),PETSC_ERR_ARG_WRONGSTATE,"Cannot change the overlap after setup"); 705dd8e54a2SToby Isaac if (overlap < 0) SETERRQ1(PetscObjectComm((PetscObject)dm),PETSC_ERR_ARG_OUTOFRANGE,"overlap cannot be < 0: %d", overlap); 706dd8e54a2SToby Isaac forest->overlap = overlap; 707dd8e54a2SToby Isaac PetscFunctionReturn(0); 708dd8e54a2SToby Isaac } 709dd8e54a2SToby Isaac 710dd8e54a2SToby Isaac #undef __FUNCT__ 711dd8e54a2SToby Isaac #define __FUNCT__ "DMForestGetPartitionOverlap" 7129be51f97SToby Isaac /*@ 7139be51f97SToby Isaac DMForestGetPartitionOverlap - Get the amount of cell-overlap present in parallel partitions of a forest, with values 7149be51f97SToby Isaac > 0 indicating subdomains that are expanded by that many iterations of adding adjacent cells 7159be51f97SToby Isaac 7169be51f97SToby Isaac Not collective 7179be51f97SToby Isaac 7189be51f97SToby Isaac Input Parameter: 7199be51f97SToby Isaac . dm - the forest 7209be51f97SToby Isaac 7219be51f97SToby Isaac Output Parameter: 7229be51f97SToby Isaac . overlap - default 0 7239be51f97SToby Isaac 7249be51f97SToby Isaac Level: intermediate 7259be51f97SToby Isaac 7269be51f97SToby Isaac .seealso: DMForestGetPartitionOverlap(), DMForestSetAdjacencyDimension(), DMForestSetAdjacencyCodimension() 7279be51f97SToby Isaac @*/ 728dd8e54a2SToby Isaac PetscErrorCode DMForestGetPartitionOverlap(DM dm, PetscInt *overlap) 729dd8e54a2SToby Isaac { 730dd8e54a2SToby Isaac DM_Forest *forest = (DM_Forest*) dm->data; 731dd8e54a2SToby Isaac 732dd8e54a2SToby Isaac PetscFunctionBegin; 733dd8e54a2SToby Isaac PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 734dd8e54a2SToby Isaac PetscValidIntPointer(overlap,2); 735dd8e54a2SToby Isaac *overlap = forest->overlap; 736dd8e54a2SToby Isaac PetscFunctionReturn(0); 737dd8e54a2SToby Isaac } 738dd8e54a2SToby Isaac 739dd8e54a2SToby Isaac #undef __FUNCT__ 740dd8e54a2SToby Isaac #define __FUNCT__ "DMForestSetMinimumRefinement" 7419be51f97SToby Isaac /*@ 7429be51f97SToby Isaac DMForestSetMinimumRefinement - During the pre-setup phase, set the minimum level of refinement (relative to the base 7439be51f97SToby Isaac DM, see DMForestGetBaseDM()) allowed in the forest. If the forest is being created by coarsening a previous forest 7449be51f97SToby Isaac (see DMForestGetAdaptivityForest()) this limits the amount of coarsening. 7459be51f97SToby Isaac 7469be51f97SToby Isaac Logically collective on dm 7479be51f97SToby Isaac 7489be51f97SToby Isaac Input Parameters: 7499be51f97SToby Isaac + dm - the forest 7509be51f97SToby Isaac - minRefinement - default PETSC_DEFAULT (interpreted by the subtype of DMForest) 7519be51f97SToby Isaac 7529be51f97SToby Isaac Level: intermediate 7539be51f97SToby Isaac 7549be51f97SToby Isaac .seealso: DMForestGetMinimumRefinement(), DMForestSetMaximumRefinement(), DMForestSetInitialRefinement(), DMForestGetBaseDM(), DMForestGetAdaptivityForest() 7559be51f97SToby Isaac @*/ 756dd8e54a2SToby Isaac PetscErrorCode DMForestSetMinimumRefinement(DM dm, PetscInt minRefinement) 757dd8e54a2SToby Isaac { 758dd8e54a2SToby Isaac DM_Forest *forest = (DM_Forest*) dm->data; 759dd8e54a2SToby Isaac 760dd8e54a2SToby Isaac PetscFunctionBegin; 761dd8e54a2SToby Isaac PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 762ef51cf95SToby Isaac if (dm->setupcalled) SETERRQ(PetscObjectComm((PetscObject)dm),PETSC_ERR_ARG_WRONGSTATE,"Cannot change the minimum refinement after setup"); 763dd8e54a2SToby Isaac forest->minRefinement = minRefinement; 764dd8e54a2SToby Isaac PetscFunctionReturn(0); 765dd8e54a2SToby Isaac } 766dd8e54a2SToby Isaac 767dd8e54a2SToby Isaac #undef __FUNCT__ 768dd8e54a2SToby Isaac #define __FUNCT__ "DMForestGetMinimumRefinement" 7699be51f97SToby Isaac /*@ 7709be51f97SToby Isaac DMForestGetMinimumRefinement - Get the minimum level of refinement (relative to the base DM, see 7719be51f97SToby Isaac DMForestGetBaseDM()) allowed in the forest. If the forest is being created by coarsening a previous forest (see 7729be51f97SToby Isaac DMForestGetAdaptivityForest()), this limits the amount of coarsening. 7739be51f97SToby Isaac 7749be51f97SToby Isaac Not collective 7759be51f97SToby Isaac 7769be51f97SToby Isaac Input Parameter: 7779be51f97SToby Isaac . dm - the forest 7789be51f97SToby Isaac 7799be51f97SToby Isaac Output Parameter: 7809be51f97SToby Isaac . minRefinement - default PETSC_DEFAULT (interpreted by the subtype of DMForest) 7819be51f97SToby Isaac 7829be51f97SToby Isaac Level: intermediate 7839be51f97SToby Isaac 7849be51f97SToby Isaac .seealso: DMForestSetMinimumRefinement(), DMForestGetMaximumRefinement(), DMForestGetInitialRefinement(), DMForestGetBaseDM(), DMForestGetAdaptivityForest() 7859be51f97SToby Isaac @*/ 786dd8e54a2SToby Isaac PetscErrorCode DMForestGetMinimumRefinement(DM dm, PetscInt *minRefinement) 787dd8e54a2SToby Isaac { 788dd8e54a2SToby Isaac DM_Forest *forest = (DM_Forest*) dm->data; 789dd8e54a2SToby Isaac 790dd8e54a2SToby Isaac PetscFunctionBegin; 791dd8e54a2SToby Isaac PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 792dd8e54a2SToby Isaac PetscValidIntPointer(minRefinement,2); 793dd8e54a2SToby Isaac *minRefinement = forest->minRefinement; 794dd8e54a2SToby Isaac PetscFunctionReturn(0); 795dd8e54a2SToby Isaac } 796dd8e54a2SToby Isaac 797dd8e54a2SToby Isaac #undef __FUNCT__ 79856ba9f64SToby Isaac #define __FUNCT__ "DMForestSetInitialRefinement" 7999be51f97SToby Isaac /*@ 8009be51f97SToby Isaac DMForestSetInitialRefinement - During the pre-setup phase, set the initial level of refinement (relative to the base 8019be51f97SToby Isaac DM, see DMForestGetBaseDM()) allowed in the forest. 8029be51f97SToby Isaac 8039be51f97SToby Isaac Logically collective on dm 8049be51f97SToby Isaac 8059be51f97SToby Isaac Input Parameters: 8069be51f97SToby Isaac + dm - the forest 8079be51f97SToby Isaac - initefinement - default PETSC_DEFAULT (interpreted by the subtype of DMForest) 8089be51f97SToby Isaac 8099be51f97SToby Isaac Level: intermediate 8109be51f97SToby Isaac 8119be51f97SToby Isaac .seealso: DMForestSetMinimumRefinement(), DMForestSetMaximumRefinement(), DMForestGetBaseDM() 8129be51f97SToby Isaac @*/ 81356ba9f64SToby Isaac PetscErrorCode DMForestSetInitialRefinement(DM dm, PetscInt initRefinement) 81456ba9f64SToby Isaac { 81556ba9f64SToby Isaac DM_Forest *forest = (DM_Forest*) dm->data; 81656ba9f64SToby Isaac 81756ba9f64SToby Isaac PetscFunctionBegin; 81856ba9f64SToby Isaac PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 81956ba9f64SToby Isaac if (dm->setupcalled) SETERRQ(PetscObjectComm((PetscObject)dm),PETSC_ERR_ARG_WRONGSTATE,"Cannot change the initial refinement after setup"); 82056ba9f64SToby Isaac forest->initRefinement = initRefinement; 82156ba9f64SToby Isaac PetscFunctionReturn(0); 82256ba9f64SToby Isaac } 82356ba9f64SToby Isaac 82456ba9f64SToby Isaac #undef __FUNCT__ 82556ba9f64SToby Isaac #define __FUNCT__ "DMForestGetInitialRefinement" 8269be51f97SToby Isaac /*@ 8279be51f97SToby Isaac DMForestGetInitialRefinement - Get the initial level of refinement (relative to the base DM, see 8289be51f97SToby Isaac DMForestGetBaseDM()) allowed in the forest. 8299be51f97SToby Isaac 8309be51f97SToby Isaac Not collective 8319be51f97SToby Isaac 8329be51f97SToby Isaac Input Parameter: 8339be51f97SToby Isaac . dm - the forest 8349be51f97SToby Isaac 8359be51f97SToby Isaac Output Paramater: 8369be51f97SToby Isaac . initefinement - default PETSC_DEFAULT (interpreted by the subtype of DMForest) 8379be51f97SToby Isaac 8389be51f97SToby Isaac Level: intermediate 8399be51f97SToby Isaac 8409be51f97SToby Isaac .seealso: DMForestSetMinimumRefinement(), DMForestSetMaximumRefinement(), DMForestGetBaseDM() 8419be51f97SToby Isaac @*/ 84256ba9f64SToby Isaac PetscErrorCode DMForestGetInitialRefinement(DM dm, PetscInt *initRefinement) 84356ba9f64SToby Isaac { 84456ba9f64SToby Isaac DM_Forest *forest = (DM_Forest*) dm->data; 84556ba9f64SToby Isaac 84656ba9f64SToby Isaac PetscFunctionBegin; 84756ba9f64SToby Isaac PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 84856ba9f64SToby Isaac PetscValidIntPointer(initRefinement,2); 84956ba9f64SToby Isaac *initRefinement = forest->initRefinement; 85056ba9f64SToby Isaac PetscFunctionReturn(0); 85156ba9f64SToby Isaac } 85256ba9f64SToby Isaac 85356ba9f64SToby Isaac #undef __FUNCT__ 854c7eeac06SToby Isaac #define __FUNCT__ "DMForestSetMaximumRefinement" 8559be51f97SToby Isaac /*@ 8569be51f97SToby Isaac DMForestSetMaximumRefinement - During the pre-setup phase, set the maximum level of refinement (relative to the base 8579be51f97SToby Isaac DM, see DMForestGetBaseDM()) allowed in the forest. If the forest is being created by refining a previous forest 8589be51f97SToby Isaac (see DMForestGetAdaptivityForest()), this limits the amount of refinement. 8599be51f97SToby Isaac 8609be51f97SToby Isaac Logically collective on dm 8619be51f97SToby Isaac 8629be51f97SToby Isaac Input Parameters: 8639be51f97SToby Isaac + dm - the forest 8649be51f97SToby Isaac - maxRefinement - default PETSC_DEFAULT (interpreted by the subtype of DMForest) 8659be51f97SToby Isaac 8669be51f97SToby Isaac Level: intermediate 8679be51f97SToby Isaac 8689be51f97SToby Isaac .seealso: DMForestGetMinimumRefinement(), DMForestSetMaximumRefinement(), DMForestSetInitialRefinement(), DMForestGetBaseDM(), DMForestGetAdaptivityDM() 8699be51f97SToby Isaac @*/ 870c7eeac06SToby Isaac PetscErrorCode DMForestSetMaximumRefinement(DM dm, PetscInt maxRefinement) 871dd8e54a2SToby Isaac { 872dd8e54a2SToby Isaac DM_Forest *forest = (DM_Forest*) dm->data; 873dd8e54a2SToby Isaac 874dd8e54a2SToby Isaac PetscFunctionBegin; 875dd8e54a2SToby Isaac PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 876ef51cf95SToby Isaac if (dm->setupcalled) SETERRQ(PetscObjectComm((PetscObject)dm),PETSC_ERR_ARG_WRONGSTATE,"Cannot change the maximum refinement after setup"); 877c7eeac06SToby Isaac forest->maxRefinement = maxRefinement; 878dd8e54a2SToby Isaac PetscFunctionReturn(0); 879dd8e54a2SToby Isaac } 880dd8e54a2SToby Isaac 881dd8e54a2SToby Isaac #undef __FUNCT__ 882c7eeac06SToby Isaac #define __FUNCT__ "DMForestGetMaximumRefinement" 8839be51f97SToby Isaac /*@ 8849be51f97SToby Isaac DMForestGetMaximumRefinement - Get the maximum level of refinement (relative to the base DM, see 8859be51f97SToby Isaac DMForestGetBaseDM()) allowed in the forest. If the forest is being created by refining a previous forest (see 8869be51f97SToby Isaac DMForestGetAdaptivityForest()), this limits the amount of refinement. 8879be51f97SToby Isaac 8889be51f97SToby Isaac Not collective 8899be51f97SToby Isaac 8909be51f97SToby Isaac Input Parameter: 8919be51f97SToby Isaac . dm - the forest 8929be51f97SToby Isaac 8939be51f97SToby Isaac Output Parameter: 8949be51f97SToby Isaac . maxRefinement - default PETSC_DEFAULT (interpreted by the subtype of DMForest) 8959be51f97SToby Isaac 8969be51f97SToby Isaac Level: intermediate 8979be51f97SToby Isaac 8989be51f97SToby Isaac .seealso: DMForestSetMaximumRefinement(), DMForestGetMinimumRefinement(), DMForestGetInitialRefinement(), DMForestGetBaseDM(), DMForestGetAdaptivityForest() 8999be51f97SToby Isaac @*/ 900c7eeac06SToby Isaac PetscErrorCode DMForestGetMaximumRefinement(DM dm, PetscInt *maxRefinement) 901dd8e54a2SToby Isaac { 902dd8e54a2SToby Isaac DM_Forest *forest = (DM_Forest*) dm->data; 903dd8e54a2SToby Isaac 904dd8e54a2SToby Isaac PetscFunctionBegin; 905dd8e54a2SToby Isaac PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 906c7eeac06SToby Isaac PetscValidIntPointer(maxRefinement,2); 907c7eeac06SToby Isaac *maxRefinement = forest->maxRefinement; 908dd8e54a2SToby Isaac PetscFunctionReturn(0); 909dd8e54a2SToby Isaac } 910c7eeac06SToby Isaac 911c7eeac06SToby Isaac #undef __FUNCT__ 912c7eeac06SToby Isaac #define __FUNCT__ "DMForestSetAdaptivityStrategy" 9139be51f97SToby Isaac /*@C 9149be51f97SToby Isaac DMForestSetAdaptivityStrategy - During the pre-setup phase, set the strategy for combining adaptivity labels from multiple processes. 9159be51f97SToby Isaac Subtypes of DMForest may define their own strategies. Two default strategies are DMFORESTADAPTALL, which indicates that all processes must agree 9169be51f97SToby Isaac for a refinement/coarsening flag to be valid, and DMFORESTADAPTANY, which indicates that only one process needs to 9179be51f97SToby Isaac specify refinement/coarsening. 9189be51f97SToby Isaac 9199be51f97SToby Isaac Logically collective on dm 9209be51f97SToby Isaac 9219be51f97SToby Isaac Input Parameters: 9229be51f97SToby Isaac + dm - the forest 9239be51f97SToby Isaac - adaptStrategy - default DMFORESTADAPTALL 9249be51f97SToby Isaac 9259be51f97SToby Isaac Level: advanced 9269be51f97SToby Isaac 9279be51f97SToby Isaac .seealso: DMForestGetAdaptivityStrategy() 9289be51f97SToby Isaac @*/ 929c7eeac06SToby Isaac PetscErrorCode DMForestSetAdaptivityStrategy(DM dm, DMForestAdaptivityStrategy adaptStrategy) 930c7eeac06SToby Isaac { 931c7eeac06SToby Isaac DM_Forest *forest = (DM_Forest*) dm->data; 932c7eeac06SToby Isaac PetscErrorCode ierr; 933c7eeac06SToby Isaac 934c7eeac06SToby Isaac PetscFunctionBegin; 935c7eeac06SToby Isaac PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 936c7eeac06SToby Isaac ierr = PetscFree(forest->adaptStrategy);CHKERRQ(ierr); 937a73e2921SToby Isaac ierr = PetscStrallocpy((const char*) adaptStrategy,(char**)&forest->adaptStrategy);CHKERRQ(ierr); 938c7eeac06SToby Isaac PetscFunctionReturn(0); 939c7eeac06SToby Isaac } 940c7eeac06SToby Isaac 941c7eeac06SToby Isaac #undef __FUNCT__ 942c7eeac06SToby Isaac #define __FUNCT__ "DMForestGetAdaptivityStrategy" 9439be51f97SToby Isaac /*@C 9449be51f97SToby Isaac DMForestSetAdaptivityStrategy - Get the strategy for combining adaptivity labels from multiple processes. Subtypes 9459be51f97SToby Isaac of DMForest may define their own strategies. Two default strategies are DMFORESTADAPTALL, which indicates that all 9469be51f97SToby Isaac processes must agree for a refinement/coarsening flag to be valid, and DMFORESTADAPTANY, which indicates that only 9479be51f97SToby Isaac one process needs to specify refinement/coarsening. 9489be51f97SToby Isaac 9499be51f97SToby Isaac Not collective 9509be51f97SToby Isaac 9519be51f97SToby Isaac Input Parameter: 9529be51f97SToby Isaac . dm - the forest 9539be51f97SToby Isaac 9549be51f97SToby Isaac Output Parameter: 9559be51f97SToby Isaac . adaptStrategy - the adaptivity strategy (default DMFORESTADAPTALL) 9569be51f97SToby Isaac 9579be51f97SToby Isaac Level: advanced 9589be51f97SToby Isaac 9599be51f97SToby Isaac .seealso: DMForestSetAdaptivityStrategy() 9609be51f97SToby Isaac @*/ 961c7eeac06SToby Isaac PetscErrorCode DMForestGetAdaptivityStrategy(DM dm, DMForestAdaptivityStrategy *adaptStrategy) 962c7eeac06SToby Isaac { 963c7eeac06SToby Isaac DM_Forest *forest = (DM_Forest*) dm->data; 964c7eeac06SToby Isaac 965c7eeac06SToby Isaac PetscFunctionBegin; 966c7eeac06SToby Isaac PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 967c7eeac06SToby Isaac PetscValidPointer(adaptStrategy,2); 968c7eeac06SToby Isaac *adaptStrategy = forest->adaptStrategy; 969c7eeac06SToby Isaac PetscFunctionReturn(0); 970c7eeac06SToby Isaac } 971c7eeac06SToby Isaac 972c7eeac06SToby Isaac #undef __FUNCT__ 973bf9b5d84SToby Isaac #define __FUNCT__ "DMForestSetComputeAdaptivitySF" 974bf9b5d84SToby Isaac /*@ 975bf9b5d84SToby Isaac DMForestSetComputeAdaptivitySF - During the pre-setup phase, set whether transfer PetscSFs should be computed 976bf9b5d84SToby Isaac relating the cells of the pre-adaptation forest to the post-adaptiation forest. After DMSetUp() is called, these transfer PetscSFs can be accessed with DMForestGetAdaptivitySF(). 977bf9b5d84SToby Isaac 978bf9b5d84SToby Isaac Logically collective on dm 979bf9b5d84SToby Isaac 980bf9b5d84SToby Isaac Input Parameters: 981bf9b5d84SToby Isaac + dm - the post-adaptation forest 982bf9b5d84SToby Isaac - computeSF - default PETSC_TRUE 983bf9b5d84SToby Isaac 984bf9b5d84SToby Isaac Level: advanced 985bf9b5d84SToby Isaac 986bf9b5d84SToby Isaac .seealso: DMForestGetComputeAdaptivitySF(), DMForestGetAdaptivitySF() 987bf9b5d84SToby Isaac @*/ 988bf9b5d84SToby Isaac PetscErrorCode DMForestSetComputeAdaptivitySF(DM dm, PetscBool computeSF) 989bf9b5d84SToby Isaac { 990bf9b5d84SToby Isaac DM_Forest *forest; 991bf9b5d84SToby Isaac 992bf9b5d84SToby Isaac PetscFunctionBegin; 993bf9b5d84SToby Isaac PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 994bf9b5d84SToby Isaac if (dm->setupcalled) SETERRQ(PetscObjectComm((PetscObject)dm),PETSC_ERR_ARG_WRONGSTATE,"Cannot compute adaptivity PetscSFs after setup is called"); 995bf9b5d84SToby Isaac forest = (DM_Forest*) dm->data; 996bf9b5d84SToby Isaac forest->computeAdaptSF = computeSF; 997bf9b5d84SToby Isaac PetscFunctionReturn(0); 998bf9b5d84SToby Isaac } 999bf9b5d84SToby Isaac 1000bf9b5d84SToby Isaac #undef __FUNCT__ 100180b27e07SToby Isaac #define __FUNCT__ "DMForestTransferVec" 10020eb7e1eaSToby Isaac PetscErrorCode DMForestTransferVec(DM dmIn, Vec vecIn, DM dmOut, Vec vecOut, PetscBool useBCs, PetscReal time) 100380b27e07SToby Isaac { 100480b27e07SToby Isaac DM_Forest *forest; 100580b27e07SToby Isaac PetscErrorCode ierr; 100680b27e07SToby Isaac 100780b27e07SToby Isaac PetscFunctionBegin; 100880b27e07SToby Isaac PetscValidHeaderSpecific(dmIn ,DM_CLASSID ,1); 100980b27e07SToby Isaac PetscValidHeaderSpecific(vecIn ,VEC_CLASSID ,2); 101080b27e07SToby Isaac PetscValidHeaderSpecific(dmOut ,DM_CLASSID ,3); 101180b27e07SToby Isaac PetscValidHeaderSpecific(vecOut ,VEC_CLASSID ,4); 101280b27e07SToby Isaac forest = (DM_Forest *) dmIn->data; 101380b27e07SToby Isaac if (!forest->transfervec) SETERRQ(PetscObjectComm((PetscObject)dmIn),PETSC_ERR_SUP,"DMForestTransferVec() not implemented"); 10140eb7e1eaSToby Isaac ierr = (forest->transfervec)(dmIn,vecIn,dmOut,vecOut,useBCs,time);CHKERRQ(ierr); 101580b27e07SToby Isaac PetscFunctionReturn(0); 101680b27e07SToby Isaac } 101780b27e07SToby Isaac 101880b27e07SToby Isaac #undef __FUNCT__ 1019bf9b5d84SToby Isaac #define __FUNCT__ "DMForestGetComputeAdaptivitySF" 1020bf9b5d84SToby Isaac /*@ 1021bf9b5d84SToby Isaac DMForestGetComputeAdaptivitySF - Get whether transfer PetscSFs should be computed relating the cells of the 1022bf9b5d84SToby Isaac pre-adaptation forest to the post-adaptiation forest. After DMSetUp() is called, these transfer PetscSFs can be 1023bf9b5d84SToby Isaac accessed with DMForestGetAdaptivitySF(). 1024bf9b5d84SToby Isaac 1025bf9b5d84SToby Isaac Not collective 1026bf9b5d84SToby Isaac 1027bf9b5d84SToby Isaac Input Parameter: 1028bf9b5d84SToby Isaac . dm - the post-adaptation forest 1029bf9b5d84SToby Isaac 1030bf9b5d84SToby Isaac Output Parameter: 1031bf9b5d84SToby Isaac . computeSF - default PETSC_TRUE 1032bf9b5d84SToby Isaac 1033bf9b5d84SToby Isaac Level: advanced 1034bf9b5d84SToby Isaac 1035bf9b5d84SToby Isaac .seealso: DMForestSetComputeAdaptivitySF(), DMForestGetAdaptivitySF() 1036bf9b5d84SToby Isaac @*/ 1037bf9b5d84SToby Isaac PetscErrorCode DMForestGetComputeAdaptivitySF(DM dm, PetscBool *computeSF) 1038bf9b5d84SToby Isaac { 1039bf9b5d84SToby Isaac DM_Forest *forest; 1040bf9b5d84SToby Isaac 1041bf9b5d84SToby Isaac PetscFunctionBegin; 1042bf9b5d84SToby Isaac PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 1043bf9b5d84SToby Isaac forest = (DM_Forest*) dm->data; 1044bf9b5d84SToby Isaac *computeSF = forest->computeAdaptSF; 1045bf9b5d84SToby Isaac PetscFunctionReturn(0); 1046bf9b5d84SToby Isaac } 1047bf9b5d84SToby Isaac 1048bf9b5d84SToby Isaac #undef __FUNCT__ 1049bf9b5d84SToby Isaac #define __FUNCT__ "DMForestGetAdaptivitySF" 1050bf9b5d84SToby Isaac /*@ 1051bf9b5d84SToby Isaac DMForestGetAdaptivitySF - Get PetscSFs that relate the pre-adaptation forest to the post-adaptation forest. 1052bf9b5d84SToby Isaac Adaptation can be any combination of refinement, coarsening, repartition, and change of overlap, so there may be 1053bf9b5d84SToby Isaac some cells of the pre-adaptation that are parents of post-adaptation cells, and vice versa. Therefore there are two 1054bf9b5d84SToby Isaac PetscSFs: one that relates pre-adaptation coarse cells to post-adaptation fine cells, and one that relates 1055bf9b5d84SToby Isaac pre-adaptation fine cells to post-adaptation coarse cells. 1056bf9b5d84SToby Isaac 1057bf9b5d84SToby Isaac Not collective 1058bf9b5d84SToby Isaac 1059bf9b5d84SToby Isaac Input Parameter: 1060bf9b5d84SToby Isaac dm - the post-adaptation forest 1061bf9b5d84SToby Isaac 1062bf9b5d84SToby Isaac Output Parameter: 10630f17b9e3SToby Isaac preCoarseToFine - pre-adaptation coarse cells to post-adaptation fine cells: BCast goes from pre- to post- 10640f17b9e3SToby Isaac coarseToPreFine - post-adaptation coarse cells to pre-adaptation fine cells: BCast goes from post- to pre- 1065bf9b5d84SToby Isaac 1066bf9b5d84SToby Isaac Level: advanced 1067bf9b5d84SToby Isaac 1068bf9b5d84SToby Isaac .seealso: DMForestGetComputeAdaptivitySF(), DMForestSetComputeAdaptivitySF() 1069bf9b5d84SToby Isaac @*/ 10700f17b9e3SToby Isaac PetscErrorCode DMForestGetAdaptivitySF(DM dm, PetscSF *preCoarseToFine, PetscSF *coarseToPreFine) 1071bf9b5d84SToby Isaac { 1072bf9b5d84SToby Isaac DM_Forest *forest; 1073bf9b5d84SToby Isaac PetscErrorCode ierr; 1074bf9b5d84SToby Isaac 1075bf9b5d84SToby Isaac PetscFunctionBegin; 1076bf9b5d84SToby Isaac PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 1077bf9b5d84SToby Isaac ierr = DMSetUp(dm);CHKERRQ(ierr); 1078bf9b5d84SToby Isaac forest = (DM_Forest*) dm->data; 1079f885a11aSToby Isaac if (preCoarseToFine) *preCoarseToFine = forest->preCoarseToFine; 1080f885a11aSToby Isaac if (coarseToPreFine) *coarseToPreFine = forest->coarseToPreFine; 1081bf9b5d84SToby Isaac PetscFunctionReturn(0); 1082bf9b5d84SToby Isaac } 1083bf9b5d84SToby Isaac 1084bf9b5d84SToby Isaac #undef __FUNCT__ 1085c7eeac06SToby Isaac #define __FUNCT__ "DMForestSetGradeFactor" 10869be51f97SToby Isaac /*@ 10879be51f97SToby Isaac DMForestSetGradeFactor - During the pre-setup phase, set the desired amount of grading in the mesh, e.g. give 2 to 10889be51f97SToby Isaac indicate that the diameter of neighboring cells should differ by at most a factor of 2. Subtypes of DMForest may 10899be51f97SToby Isaac only support one particular choice of grading factor. 10909be51f97SToby Isaac 10919be51f97SToby Isaac Logically collective on dm 10929be51f97SToby Isaac 10939be51f97SToby Isaac Input Parameters: 10949be51f97SToby Isaac + dm - the forest 10959be51f97SToby Isaac - grade - the grading factor 10969be51f97SToby Isaac 10979be51f97SToby Isaac Level: advanced 10989be51f97SToby Isaac 10999be51f97SToby Isaac .seealso: DMForestGetGradeFactor() 11009be51f97SToby Isaac @*/ 1101c7eeac06SToby Isaac PetscErrorCode DMForestSetGradeFactor(DM dm, PetscInt grade) 1102c7eeac06SToby Isaac { 1103c7eeac06SToby Isaac DM_Forest *forest = (DM_Forest*) dm->data; 1104c7eeac06SToby Isaac 1105c7eeac06SToby Isaac PetscFunctionBegin; 1106c7eeac06SToby Isaac PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 1107ef51cf95SToby Isaac if (dm->setupcalled) SETERRQ(PetscObjectComm((PetscObject)dm),PETSC_ERR_ARG_WRONGSTATE,"Cannot change the grade factor after setup"); 1108c7eeac06SToby Isaac forest->gradeFactor = grade; 1109c7eeac06SToby Isaac PetscFunctionReturn(0); 1110c7eeac06SToby Isaac } 1111c7eeac06SToby Isaac 1112c7eeac06SToby Isaac #undef __FUNCT__ 1113c7eeac06SToby Isaac #define __FUNCT__ "DMForestGetGradeFactor" 11149be51f97SToby Isaac /*@ 11159be51f97SToby Isaac DMForestGetGradeFactor - Get the desired amount of grading in the mesh, e.g. give 2 to indicate that the diameter of 11169be51f97SToby Isaac neighboring cells should differ by at most a factor of 2. Subtypes of DMForest may only support one particular 11179be51f97SToby Isaac choice of grading factor. 11189be51f97SToby Isaac 11199be51f97SToby Isaac Not collective 11209be51f97SToby Isaac 11219be51f97SToby Isaac Input Parameter: 11229be51f97SToby Isaac . dm - the forest 11239be51f97SToby Isaac 11249be51f97SToby Isaac Output Parameter: 11259be51f97SToby Isaac . grade - the grading factor 11269be51f97SToby Isaac 11279be51f97SToby Isaac Level: advanced 11289be51f97SToby Isaac 11299be51f97SToby Isaac .seealso: DMForestSetGradeFactor() 11309be51f97SToby Isaac @*/ 1131c7eeac06SToby Isaac PetscErrorCode DMForestGetGradeFactor(DM dm, PetscInt *grade) 1132c7eeac06SToby Isaac { 1133c7eeac06SToby Isaac DM_Forest *forest = (DM_Forest*) dm->data; 1134c7eeac06SToby Isaac 1135c7eeac06SToby Isaac PetscFunctionBegin; 1136c7eeac06SToby Isaac PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 1137c7eeac06SToby Isaac PetscValidIntPointer(grade,2); 1138c7eeac06SToby Isaac *grade = forest->gradeFactor; 1139c7eeac06SToby Isaac PetscFunctionReturn(0); 1140c7eeac06SToby Isaac } 1141c7eeac06SToby Isaac 1142c7eeac06SToby Isaac #undef __FUNCT__ 1143ef51cf95SToby Isaac #define __FUNCT__ "DMForestSetCellWeightFactor" 11449be51f97SToby Isaac /*@ 11459be51f97SToby Isaac DMForestSetCellWeightFactor - During the pre-setup phase, set the factor by which the level of refinement changes 11469be51f97SToby Isaac the cell weight (see DMForestSetCellWeights()) when calculating partitions. The final weight of a cell will be 11479be51f97SToby Isaac (cellWeight) * (weightFactor^refinementLevel). A factor of 1 indicates that the weight of a cell does not depend on 11489be51f97SToby Isaac its level; a factor of 2, for example, might be appropriate for sub-cycling time-stepping methods, when the 11499be51f97SToby Isaac computation associated with a cell is multiplied by a factor of 2 for each additional level of refinement. 11509be51f97SToby Isaac 11519be51f97SToby Isaac Logically collective on dm 11529be51f97SToby Isaac 11539be51f97SToby Isaac Input Parameters: 11549be51f97SToby Isaac + dm - the forest 11559be51f97SToby Isaac - weightsFactors - default 1. 11569be51f97SToby Isaac 11579be51f97SToby Isaac Level: advanced 11589be51f97SToby Isaac 11599be51f97SToby Isaac .seealso: DMForestGetCellWeightFactor(), DMForestSetCellWeights() 11609be51f97SToby Isaac @*/ 1161ef51cf95SToby Isaac PetscErrorCode DMForestSetCellWeightFactor(DM dm, PetscReal weightsFactor) 1162c7eeac06SToby Isaac { 1163c7eeac06SToby Isaac DM_Forest *forest = (DM_Forest*) dm->data; 1164c7eeac06SToby Isaac 1165c7eeac06SToby Isaac PetscFunctionBegin; 1166c7eeac06SToby Isaac PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 1167ef51cf95SToby Isaac if (dm->setupcalled) SETERRQ(PetscObjectComm((PetscObject)dm),PETSC_ERR_ARG_WRONGSTATE,"Cannot change the weights factor after setup"); 1168c7eeac06SToby Isaac forest->weightsFactor = weightsFactor; 1169c7eeac06SToby Isaac PetscFunctionReturn(0); 1170c7eeac06SToby Isaac } 1171c7eeac06SToby Isaac 1172c7eeac06SToby Isaac #undef __FUNCT__ 1173ef51cf95SToby Isaac #define __FUNCT__ "DMForestGetCellWeightFactor" 11749be51f97SToby Isaac /*@ 11759be51f97SToby Isaac DMForestGetCellWeightFactor - Get the factor by which the level of refinement changes the cell weight (see 11769be51f97SToby Isaac DMForestSetCellWeights()) when calculating partitions. The final weight of a cell will be (cellWeight) * 11779be51f97SToby Isaac (weightFactor^refinementLevel). A factor of 1 indicates that the weight of a cell does not depend on its level; a 11789be51f97SToby Isaac factor of 2, for example, might be appropriate for sub-cycling time-stepping methods, when the computation 11799be51f97SToby Isaac associated with a cell is multiplied by a factor of 2 for each additional level of refinement. 11809be51f97SToby Isaac 11819be51f97SToby Isaac Not collective 11829be51f97SToby Isaac 11839be51f97SToby Isaac Input Parameter: 11849be51f97SToby Isaac . dm - the forest 11859be51f97SToby Isaac 11869be51f97SToby Isaac Output Parameter: 11879be51f97SToby Isaac . weightsFactors - default 1. 11889be51f97SToby Isaac 11899be51f97SToby Isaac Level: advanced 11909be51f97SToby Isaac 11919be51f97SToby Isaac .seealso: DMForestSetCellWeightFactor(), DMForestSetCellWeights() 11929be51f97SToby Isaac @*/ 1193ef51cf95SToby Isaac PetscErrorCode DMForestGetCellWeightFactor(DM dm, PetscReal *weightsFactor) 1194c7eeac06SToby Isaac { 1195c7eeac06SToby Isaac DM_Forest *forest = (DM_Forest*) dm->data; 1196c7eeac06SToby Isaac 1197c7eeac06SToby Isaac PetscFunctionBegin; 1198c7eeac06SToby Isaac PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 1199c7eeac06SToby Isaac PetscValidRealPointer(weightsFactor,2); 1200c7eeac06SToby Isaac *weightsFactor = forest->weightsFactor; 1201c7eeac06SToby Isaac PetscFunctionReturn(0); 1202c7eeac06SToby Isaac } 1203c7eeac06SToby Isaac 1204c7eeac06SToby Isaac #undef __FUNCT__ 1205c7eeac06SToby Isaac #define __FUNCT__ "DMForestGetCellChart" 12069be51f97SToby Isaac /*@ 12079be51f97SToby Isaac DMForestGetCellChart - After the setup phase, get the local half-open interval of the chart of cells on this process 12089be51f97SToby Isaac 12099be51f97SToby Isaac Not collective 12109be51f97SToby Isaac 12119be51f97SToby Isaac Input Parameter: 12129be51f97SToby Isaac . dm - the forest 12139be51f97SToby Isaac 12149be51f97SToby Isaac Output Parameters: 12159be51f97SToby Isaac + cStart - the first cell on this process 12169be51f97SToby Isaac - cEnd - one after the final cell on this process 12179be51f97SToby Isaac 12181a244344SSatish Balay Level: intermediate 12199be51f97SToby Isaac 12209be51f97SToby Isaac .seealso: DMForestGetCellSF() 12219be51f97SToby Isaac @*/ 1222c7eeac06SToby Isaac PetscErrorCode DMForestGetCellChart(DM dm, PetscInt *cStart, PetscInt *cEnd) 1223c7eeac06SToby Isaac { 1224c7eeac06SToby Isaac DM_Forest *forest = (DM_Forest*) dm->data; 1225c7eeac06SToby Isaac PetscErrorCode ierr; 1226c7eeac06SToby Isaac 1227c7eeac06SToby Isaac PetscFunctionBegin; 1228c7eeac06SToby Isaac PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 1229c7eeac06SToby Isaac PetscValidIntPointer(cStart,2); 1230c7eeac06SToby Isaac PetscValidIntPointer(cEnd,2); 1231c7eeac06SToby Isaac if (((forest->cStart == PETSC_DETERMINE) || (forest->cEnd == PETSC_DETERMINE)) && forest->createcellchart) { 1232c7eeac06SToby Isaac ierr = forest->createcellchart(dm,&forest->cStart,&forest->cEnd);CHKERRQ(ierr); 1233c7eeac06SToby Isaac } 1234c7eeac06SToby Isaac *cStart = forest->cStart; 1235c7eeac06SToby Isaac *cEnd = forest->cEnd; 1236c7eeac06SToby Isaac PetscFunctionReturn(0); 1237c7eeac06SToby Isaac } 1238c7eeac06SToby Isaac 1239c7eeac06SToby Isaac #undef __FUNCT__ 1240c7eeac06SToby Isaac #define __FUNCT__ "DMForestGetCellSF" 12419be51f97SToby Isaac /*@ 12429be51f97SToby Isaac DMForestGetCellSF - After the setup phase, get the PetscSF for overlapping cells between processes 12439be51f97SToby Isaac 12449be51f97SToby Isaac Not collective 12459be51f97SToby Isaac 12469be51f97SToby Isaac Input Parameter: 12479be51f97SToby Isaac . dm - the forest 12489be51f97SToby Isaac 12499be51f97SToby Isaac Output Parameter: 12509be51f97SToby Isaac . cellSF - the PetscSF 12519be51f97SToby Isaac 12521a244344SSatish Balay Level: intermediate 12539be51f97SToby Isaac 12549be51f97SToby Isaac .seealso: DMForestGetCellChart() 12559be51f97SToby Isaac @*/ 1256c7eeac06SToby Isaac PetscErrorCode DMForestGetCellSF(DM dm, PetscSF *cellSF) 1257c7eeac06SToby Isaac { 1258c7eeac06SToby Isaac DM_Forest *forest = (DM_Forest*) dm->data; 1259c7eeac06SToby Isaac PetscErrorCode ierr; 1260c7eeac06SToby Isaac 1261c7eeac06SToby Isaac PetscFunctionBegin; 1262c7eeac06SToby Isaac PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 1263c7eeac06SToby Isaac PetscValidPointer(cellSF,2); 1264c7eeac06SToby Isaac if ((!forest->cellSF) && forest->createcellsf) { 1265c7eeac06SToby Isaac ierr = forest->createcellsf(dm,&forest->cellSF);CHKERRQ(ierr); 1266c7eeac06SToby Isaac } 1267c7eeac06SToby Isaac *cellSF = forest->cellSF; 1268c7eeac06SToby Isaac PetscFunctionReturn(0); 1269c7eeac06SToby Isaac } 1270c7eeac06SToby Isaac 1271c7eeac06SToby Isaac #undef __FUNCT__ 1272ebdf65a2SToby Isaac #define __FUNCT__ "DMForestSetAdaptivityLabel" 12739be51f97SToby Isaac /*@C 12749be51f97SToby Isaac DMForestSetAdaptivityLabel - During the pre-setup phase, set the label of the pre-adaptation forest (see 12759be51f97SToby Isaac DMForestGetAdaptivityForest()) that holds the adaptation flags (refinement, coarsening, or some combination). The 12769be51f97SToby Isaac interpretation of the label values is up to the subtype of DMForest, but DM_FOREST_KEEP, DM_FOREST_REFINE, and 12779be51f97SToby Isaac DM_FOREST_COARSEN have been reserved as choices that should be accepted by all subtypes. 12789be51f97SToby Isaac 12799be51f97SToby Isaac Logically collective on dm 12809be51f97SToby Isaac 12819be51f97SToby Isaac Input Parameters: 12829be51f97SToby Isaac - dm - the forest 12839be51f97SToby Isaac + adaptLabel - the name of the label in the pre-adaptation forest 12849be51f97SToby Isaac 12859be51f97SToby Isaac Level: intermediate 12869be51f97SToby Isaac 12879be51f97SToby Isaac .seealso DMForestGetAdaptivityLabel() 12889be51f97SToby Isaac @*/ 1289ebdf65a2SToby Isaac PetscErrorCode DMForestSetAdaptivityLabel(DM dm, const char * adaptLabel) 1290c7eeac06SToby Isaac { 1291c7eeac06SToby Isaac DM_Forest *forest = (DM_Forest*) dm->data; 1292c7eeac06SToby Isaac PetscErrorCode ierr; 1293c7eeac06SToby Isaac 1294c7eeac06SToby Isaac PetscFunctionBegin; 1295c7eeac06SToby Isaac PetscValidHeaderSpecific(dm,DM_CLASSID,1); 1296ebdf65a2SToby Isaac ierr = PetscFree(forest->adaptLabel);CHKERRQ(ierr); 1297ebdf65a2SToby Isaac ierr = PetscStrallocpy(adaptLabel,&forest->adaptLabel);CHKERRQ(ierr); 1298c7eeac06SToby Isaac PetscFunctionReturn(0); 1299c7eeac06SToby Isaac } 1300c7eeac06SToby Isaac 1301c7eeac06SToby Isaac #undef __FUNCT__ 1302ebdf65a2SToby Isaac #define __FUNCT__ "DMForestGetAdaptivityLabel" 13039be51f97SToby Isaac /*@C 13049be51f97SToby Isaac DMForestGetAdaptivityLabel - Get the label of the pre-adaptation forest (see DMForestGetAdaptivityForest()) that 13059be51f97SToby Isaac holds the adaptation flags (refinement, coarsening, or some combination). The interpretation of the label values is 13069be51f97SToby Isaac up to the subtype of DMForest, but DM_FOREST_KEEP, DM_FOREST_REFINE, and DM_FOREST_COARSEN have been reserved as 13079be51f97SToby Isaac choices that should be accepted by all subtypes. 13089be51f97SToby Isaac 13099be51f97SToby Isaac Not collective 13109be51f97SToby Isaac 13119be51f97SToby Isaac Input Parameter: 13129be51f97SToby Isaac . dm - the forest 13139be51f97SToby Isaac 13149be51f97SToby Isaac Output Parameter: 13159be51f97SToby Isaac . adaptLabel - the name of the label in the pre-adaptation forest 13169be51f97SToby Isaac 13179be51f97SToby Isaac Level: intermediate 13189be51f97SToby Isaac 13199be51f97SToby Isaac .seealso DMForestSetAdaptivityLabel() 13209be51f97SToby Isaac @*/ 1321ba936b91SToby Isaac PetscErrorCode DMForestGetAdaptivityLabel(DM dm, const char ** adaptLabel) 1322c7eeac06SToby Isaac { 1323c7eeac06SToby Isaac DM_Forest *forest = (DM_Forest*) dm->data; 1324c7eeac06SToby Isaac 1325c7eeac06SToby Isaac PetscFunctionBegin; 1326c7eeac06SToby Isaac PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 1327ba936b91SToby Isaac *adaptLabel = forest->adaptLabel; 1328c7eeac06SToby Isaac PetscFunctionReturn(0); 1329c7eeac06SToby Isaac } 1330c7eeac06SToby Isaac 1331c7eeac06SToby Isaac #undef __FUNCT__ 1332c7eeac06SToby Isaac #define __FUNCT__ "DMForestSetCellWeights" 13339be51f97SToby Isaac /*@ 13349be51f97SToby Isaac DMForestSetCellWeights - Set the weights assigned to each of the cells (see DMForestGetCellChart()) of the current 13359be51f97SToby Isaac process: weights are used to determine parallel partitioning. Partitions will be created so that each process's 13369be51f97SToby Isaac ratio of weight to capacity (see DMForestSetWeightCapacity()) is roughly equal. If NULL, each cell receives a weight 13379be51f97SToby Isaac of 1. 13389be51f97SToby Isaac 13399be51f97SToby Isaac Logically collective on dm 13409be51f97SToby Isaac 13419be51f97SToby Isaac Input Parameters: 13429be51f97SToby Isaac + dm - the forest 13439be51f97SToby Isaac . weights - the array of weights for all cells, or NULL to indicate each cell has weight 1. 13449be51f97SToby Isaac - copyMode - how weights should reference weights 13459be51f97SToby Isaac 13469be51f97SToby Isaac Level: advanced 13479be51f97SToby Isaac 13489be51f97SToby Isaac .seealso: DMForestGetCellWeights(), DMForestSetWeightCapacity() 13499be51f97SToby Isaac @*/ 1350c7eeac06SToby Isaac PetscErrorCode DMForestSetCellWeights(DM dm, PetscReal weights[], PetscCopyMode copyMode) 1351c7eeac06SToby Isaac { 1352c7eeac06SToby Isaac DM_Forest *forest = (DM_Forest*) dm->data; 1353c7eeac06SToby Isaac PetscInt cStart, cEnd; 1354c7eeac06SToby Isaac PetscErrorCode ierr; 1355c7eeac06SToby Isaac 1356c7eeac06SToby Isaac PetscFunctionBegin; 1357c7eeac06SToby Isaac PetscValidHeaderSpecific(dm,DM_CLASSID,1); 1358c7eeac06SToby Isaac ierr = DMForestGetCellChart(dm,&cStart,&cEnd);CHKERRQ(ierr); 1359c7eeac06SToby Isaac if (cEnd < cStart) SETERRQ2(PETSC_COMM_SELF,PETSC_ERR_ARG_WRONGSTATE,"cell chart [%d,%d) is not valid",cStart,cEnd); 1360c7eeac06SToby Isaac if (copyMode == PETSC_COPY_VALUES) { 1361c7eeac06SToby Isaac if (forest->cellWeightsCopyMode != PETSC_OWN_POINTER || forest->cellWeights == weights) { 1362c7eeac06SToby Isaac ierr = PetscMalloc1(cEnd-cStart,&forest->cellWeights);CHKERRQ(ierr); 1363c7eeac06SToby Isaac } 1364c7eeac06SToby Isaac ierr = PetscMemcpy(forest->cellWeights,weights,(cEnd-cStart)*sizeof(*weights));CHKERRQ(ierr); 1365c7eeac06SToby Isaac forest->cellWeightsCopyMode = PETSC_OWN_POINTER; 1366c7eeac06SToby Isaac PetscFunctionReturn(0); 1367c7eeac06SToby Isaac } 1368c7eeac06SToby Isaac if (forest->cellWeightsCopyMode == PETSC_OWN_POINTER) { 1369c7eeac06SToby Isaac ierr = PetscFree(forest->cellWeights);CHKERRQ(ierr); 1370c7eeac06SToby Isaac } 1371c7eeac06SToby Isaac forest->cellWeights = weights; 1372c7eeac06SToby Isaac forest->cellWeightsCopyMode = copyMode; 1373c7eeac06SToby Isaac PetscFunctionReturn(0); 1374c7eeac06SToby Isaac } 1375c7eeac06SToby Isaac 1376c7eeac06SToby Isaac #undef __FUNCT__ 1377c7eeac06SToby Isaac #define __FUNCT__ "DMForestGetCellWeights" 13789be51f97SToby Isaac /*@ 13799be51f97SToby Isaac DMForestGetCellWeights - Get the weights assigned to each of the cells (see DMForestGetCellChart()) of the current 13809be51f97SToby Isaac process: weights are used to determine parallel partitioning. Partitions will be created so that each process's 13819be51f97SToby Isaac ratio of weight to capacity (see DMForestSetWeightCapacity()) is roughly equal. If NULL, each cell receives a weight 13829be51f97SToby Isaac of 1. 13839be51f97SToby Isaac 13849be51f97SToby Isaac Not collective 13859be51f97SToby Isaac 13869be51f97SToby Isaac Input Parameter: 13879be51f97SToby Isaac . dm - the forest 13889be51f97SToby Isaac 13899be51f97SToby Isaac Output Parameter: 13909be51f97SToby Isaac . weights - the array of weights for all cells, or NULL to indicate each cell has weight 1. 13919be51f97SToby Isaac 13929be51f97SToby Isaac Level: advanced 13939be51f97SToby Isaac 13949be51f97SToby Isaac .seealso: DMForestSetCellWeights(), DMForestSetWeightCapacity() 13959be51f97SToby Isaac @*/ 1396c7eeac06SToby Isaac PetscErrorCode DMForestGetCellWeights(DM dm, PetscReal **weights) 1397c7eeac06SToby Isaac { 1398c7eeac06SToby Isaac DM_Forest *forest = (DM_Forest*) dm->data; 1399c7eeac06SToby Isaac 1400c7eeac06SToby Isaac PetscFunctionBegin; 1401c7eeac06SToby Isaac PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 1402c7eeac06SToby Isaac PetscValidPointer(weights,2); 1403c7eeac06SToby Isaac *weights = forest->cellWeights; 1404c7eeac06SToby Isaac PetscFunctionReturn(0); 1405c7eeac06SToby Isaac } 1406c7eeac06SToby Isaac 1407c7eeac06SToby Isaac #undef __FUNCT__ 1408c7eeac06SToby Isaac #define __FUNCT__ "DMForestSetWeightCapacity" 14099be51f97SToby Isaac /*@ 14109be51f97SToby Isaac DMForestSetWeightCapacity - During the pre-setup phase, set the capacity of the current process when repartitioning 14119be51f97SToby Isaac a pre-adaptation forest (see DMForestGetAdaptivityForest()). After partitioning, the ratio of the weight of each 14129be51f97SToby Isaac process's cells to the process's capacity will be roughly equal for all processes. A capacity of 0 indicates that 14139be51f97SToby Isaac the current process should not have any cells after repartitioning. 14149be51f97SToby Isaac 14159be51f97SToby Isaac Logically Collective on dm 14169be51f97SToby Isaac 14179be51f97SToby Isaac Input parameters: 14189be51f97SToby Isaac + dm - the forest 14199be51f97SToby Isaac - capacity - this process's capacity 14209be51f97SToby Isaac 14219be51f97SToby Isaac Level: advanced 14229be51f97SToby Isaac 14239be51f97SToby Isaac .seealso DMForestGetWeightCapacity(), DMForestSetCellWeights(), DMForestSetCellWeightFactor() 14249be51f97SToby Isaac @*/ 1425c7eeac06SToby Isaac PetscErrorCode DMForestSetWeightCapacity(DM dm, PetscReal capacity) 1426c7eeac06SToby Isaac { 1427c7eeac06SToby Isaac DM_Forest *forest = (DM_Forest*) dm->data; 1428c7eeac06SToby Isaac 1429c7eeac06SToby Isaac PetscFunctionBegin; 1430c7eeac06SToby Isaac PetscValidHeaderSpecific(dm,DM_CLASSID,1); 1431ef51cf95SToby Isaac if (dm->setupcalled) SETERRQ(PetscObjectComm((PetscObject)dm),PETSC_ERR_ARG_WRONGSTATE,"Cannot change the weight capacity after setup"); 1432c7eeac06SToby Isaac if (capacity < 0.) SETERRQ1(PetscObjectComm((PetscObject)dm),PETSC_ERR_ARG_OUTOFRANGE,"Cannot have negative weight capacity; %f",capacity); 1433c7eeac06SToby Isaac forest->weightCapacity = capacity; 1434c7eeac06SToby Isaac PetscFunctionReturn(0); 1435c7eeac06SToby Isaac } 1436c7eeac06SToby Isaac 1437c7eeac06SToby Isaac #undef __FUNCT__ 1438c7eeac06SToby Isaac #define __FUNCT__ "DMForestGetWeightCapacity" 14399be51f97SToby Isaac /*@ 14409be51f97SToby Isaac DMForestGetWeightCapacity - Set the capacity of the current process when repartitioning a pre-adaptation forest (see 14419be51f97SToby Isaac DMForestGetAdaptivityForest()). After partitioning, the ratio of the weight of each process's cells to the 14429be51f97SToby Isaac process's capacity will be roughly equal for all processes. A capacity of 0 indicates that the current process 14439be51f97SToby Isaac should not have any cells after repartitioning. 14449be51f97SToby Isaac 14459be51f97SToby Isaac Not collective 14469be51f97SToby Isaac 14479be51f97SToby Isaac Input parameter: 14489be51f97SToby Isaac . dm - the forest 14499be51f97SToby Isaac 14509be51f97SToby Isaac Output parameter: 14519be51f97SToby Isaac . capacity - this process's capacity 14529be51f97SToby Isaac 14539be51f97SToby Isaac Level: advanced 14549be51f97SToby Isaac 14559be51f97SToby Isaac .seealso DMForestSetWeightCapacity(), DMForestSetCellWeights(), DMForestSetCellWeightFactor() 14569be51f97SToby Isaac @*/ 1457c7eeac06SToby Isaac PetscErrorCode DMForestGetWeightCapacity(DM dm, PetscReal *capacity) 1458c7eeac06SToby Isaac { 1459c7eeac06SToby Isaac DM_Forest *forest = (DM_Forest*) dm->data; 1460c7eeac06SToby Isaac 1461c7eeac06SToby Isaac PetscFunctionBegin; 1462c7eeac06SToby Isaac PetscValidHeaderSpecific(dm,DM_CLASSID,1); 1463c7eeac06SToby Isaac PetscValidRealPointer(capacity,2); 1464c7eeac06SToby Isaac *capacity = forest->weightCapacity; 1465c7eeac06SToby Isaac PetscFunctionReturn(0); 1466c7eeac06SToby Isaac } 1467c7eeac06SToby Isaac 1468dd8e54a2SToby Isaac #undef __FUNCT__ 1469db4d5e8cSToby Isaac #define __FUNCT__ "DMSetFromOptions_Forest" 14700709b2feSToby Isaac PETSC_EXTERN PetscErrorCode DMSetFromOptions_Forest(PetscOptionItems *PetscOptionsObject,DM dm) 1471db4d5e8cSToby Isaac { 1472db4d5e8cSToby Isaac DM_Forest *forest = (DM_Forest*) dm->data; 147356ba9f64SToby Isaac PetscBool flg, flg1, flg2, flg3, flg4; 1474dd8e54a2SToby Isaac DMForestTopology oldTopo; 1475c7eeac06SToby Isaac char stringBuffer[256]; 1476dd8e54a2SToby Isaac PetscViewer viewer; 1477dd8e54a2SToby Isaac PetscViewerFormat format; 147856ba9f64SToby Isaac PetscInt adjDim, adjCodim, overlap, minRefinement, initRefinement, maxRefinement, grade; 1479c7eeac06SToby Isaac PetscReal weightsFactor; 1480c7eeac06SToby Isaac DMForestAdaptivityStrategy adaptStrategy; 1481db4d5e8cSToby Isaac PetscErrorCode ierr; 1482db4d5e8cSToby Isaac 1483db4d5e8cSToby Isaac PetscFunctionBegin; 1484db4d5e8cSToby Isaac PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 148558762b62SToby Isaac forest->setfromoptionscalled = PETSC_TRUE; 1486dd8e54a2SToby Isaac ierr = DMForestGetTopology(dm, &oldTopo);CHKERRQ(ierr); 1487a3eda1eaSToby Isaac ierr = PetscOptionsHead(PetscOptionsObject,"DMForest Options");CHKERRQ(ierr); 148856ba9f64SToby Isaac ierr = PetscOptionsString("-dm_forest_topology","the topology of the forest's base mesh","DMForestSetTopology",oldTopo,stringBuffer,256,&flg1);CHKERRQ(ierr); 148956ba9f64SToby Isaac ierr = PetscOptionsViewer("-dm_forest_base_dm","load the base DM from a viewer specification","DMForestSetBaseDM",&viewer,&format,&flg2);CHKERRQ(ierr); 149056ba9f64SToby Isaac ierr = PetscOptionsViewer("-dm_forest_coarse_forest","load the coarse forest from a viewer specification","DMForestSetCoarseForest",&viewer,&format,&flg3);CHKERRQ(ierr); 149156ba9f64SToby Isaac ierr = PetscOptionsViewer("-dm_forest_fine_forest","load the fine forest from a viewer specification","DMForestSetFineForest",&viewer,&format,&flg4);CHKERRQ(ierr); 1492f885a11aSToby Isaac if ((PetscInt) flg1 + (PetscInt) flg2 + (PetscInt) flg3 + (PetscInt) flg4 > 1) SETERRQ(PetscObjectComm((PetscObject)dm),PETSC_ERR_ARG_INCOMP,"Specify only one of -dm_forest_{topology,base_dm,coarse_forest,fine_forest}"); 149356ba9f64SToby Isaac if (flg1) { 149456ba9f64SToby Isaac ierr = DMForestSetTopology(dm,(DMForestTopology)stringBuffer);CHKERRQ(ierr); 149556ba9f64SToby Isaac ierr = DMForestSetBaseDM(dm,NULL);CHKERRQ(ierr); 149620e8089bSToby Isaac ierr = DMForestSetAdaptivityForest(dm,NULL);CHKERRQ(ierr); 149756ba9f64SToby Isaac } 149856ba9f64SToby Isaac if (flg2) { 1499dd8e54a2SToby Isaac DM base; 1500dd8e54a2SToby Isaac 1501dd8e54a2SToby Isaac ierr = DMCreate(PetscObjectComm((PetscObject)dm),&base);CHKERRQ(ierr); 1502dd8e54a2SToby Isaac ierr = PetscViewerPushFormat(viewer,format);CHKERRQ(ierr); 1503dd8e54a2SToby Isaac ierr = DMLoad(base,viewer);CHKERRQ(ierr); 1504dd8e54a2SToby Isaac ierr = PetscViewerDestroy(&viewer);CHKERRQ(ierr); 1505dd8e54a2SToby Isaac ierr = DMForestSetBaseDM(dm,base);CHKERRQ(ierr); 1506dd8e54a2SToby Isaac ierr = DMDestroy(&base);CHKERRQ(ierr); 150756ba9f64SToby Isaac ierr = DMForestSetTopology(dm,NULL);CHKERRQ(ierr); 150820e8089bSToby Isaac ierr = DMForestSetAdaptivityForest(dm,NULL);CHKERRQ(ierr); 1509dd8e54a2SToby Isaac } 151056ba9f64SToby Isaac if (flg3) { 1511dd8e54a2SToby Isaac DM coarse; 1512dd8e54a2SToby Isaac 1513dd8e54a2SToby Isaac ierr = DMCreate(PetscObjectComm((PetscObject)dm),&coarse);CHKERRQ(ierr); 1514dd8e54a2SToby Isaac ierr = PetscViewerPushFormat(viewer,format);CHKERRQ(ierr); 1515dd8e54a2SToby Isaac ierr = DMLoad(coarse,viewer);CHKERRQ(ierr); 1516dd8e54a2SToby Isaac ierr = PetscViewerDestroy(&viewer);CHKERRQ(ierr); 151720e8089bSToby Isaac ierr = DMForestSetAdaptivityForest(dm,coarse);CHKERRQ(ierr); 1518dd8e54a2SToby Isaac ierr = DMDestroy(&coarse);CHKERRQ(ierr); 151956ba9f64SToby Isaac ierr = DMForestSetTopology(dm,NULL);CHKERRQ(ierr); 152056ba9f64SToby Isaac ierr = DMForestSetBaseDM(dm,NULL);CHKERRQ(ierr); 1521dd8e54a2SToby Isaac } 152256ba9f64SToby Isaac if (flg4) { 1523dd8e54a2SToby Isaac DM fine; 1524dd8e54a2SToby Isaac 1525dd8e54a2SToby Isaac ierr = DMCreate(PetscObjectComm((PetscObject)dm),&fine);CHKERRQ(ierr); 1526dd8e54a2SToby Isaac ierr = PetscViewerPushFormat(viewer,format);CHKERRQ(ierr); 1527dd8e54a2SToby Isaac ierr = DMLoad(fine,viewer);CHKERRQ(ierr); 1528dd8e54a2SToby Isaac ierr = PetscViewerDestroy(&viewer);CHKERRQ(ierr); 152920e8089bSToby Isaac ierr = DMForestSetAdaptivityForest(dm,fine);CHKERRQ(ierr); 1530dd8e54a2SToby Isaac ierr = DMDestroy(&fine);CHKERRQ(ierr); 153156ba9f64SToby Isaac ierr = DMForestSetTopology(dm,NULL);CHKERRQ(ierr); 153256ba9f64SToby Isaac ierr = DMForestSetBaseDM(dm,NULL);CHKERRQ(ierr); 1533dd8e54a2SToby Isaac } 1534dd8e54a2SToby Isaac ierr = DMForestGetAdjacencyDimension(dm,&adjDim);CHKERRQ(ierr); 1535dd8e54a2SToby Isaac ierr = PetscOptionsInt("-dm_forest_adjacency_dimension","set the dimension of points that define adjacency in the forest","DMForestSetAdjacencyDimension",adjDim,&adjDim,&flg);CHKERRQ(ierr); 1536dd8e54a2SToby Isaac if (flg) { 1537dd8e54a2SToby Isaac ierr = DMForestSetAdjacencyDimension(dm,adjDim);CHKERRQ(ierr); 1538f885a11aSToby Isaac } else { 1539dd8e54a2SToby Isaac ierr = DMForestGetAdjacencyCodimension(dm,&adjCodim);CHKERRQ(ierr); 1540dd8e54a2SToby Isaac ierr = PetscOptionsInt("-dm_forest_adjacency_codimension","set the codimension of points that define adjacency in the forest","DMForestSetAdjacencyCodimension",adjCodim,&adjCodim,&flg);CHKERRQ(ierr); 1541dd8e54a2SToby Isaac if (flg) { 1542dd8e54a2SToby Isaac ierr = DMForestSetAdjacencyCodimension(dm,adjCodim);CHKERRQ(ierr); 1543dd8e54a2SToby Isaac } 1544dd8e54a2SToby Isaac } 1545dd8e54a2SToby Isaac ierr = DMForestGetPartitionOverlap(dm,&overlap);CHKERRQ(ierr); 1546dd8e54a2SToby Isaac ierr = PetscOptionsInt("-dm_forest_partition_overlap","set the degree of partition overlap","DMForestSetPartitionOverlap",overlap,&overlap,&flg);CHKERRQ(ierr); 1547dd8e54a2SToby Isaac if (flg) { 1548dd8e54a2SToby Isaac ierr = DMForestSetPartitionOverlap(dm,overlap);CHKERRQ(ierr); 1549dd8e54a2SToby Isaac } 1550a6121fbdSMatthew G. Knepley #if 0 1551a6121fbdSMatthew G. Knepley ierr = PetscOptionsInt("-dm_refine","equivalent to -dm_forest_set_minimum_refinement and -dm_forest_set_initial_refinement with the same value",NULL,minRefinement,&minRefinement,&flg);CHKERRQ(ierr); 1552a6121fbdSMatthew G. Knepley if (flg) { 1553a6121fbdSMatthew G. Knepley ierr = DMForestSetMinimumRefinement(dm,minRefinement);CHKERRQ(ierr); 1554a6121fbdSMatthew G. Knepley ierr = DMForestSetInitialRefinement(dm,minRefinement);CHKERRQ(ierr); 1555a6121fbdSMatthew G. Knepley } 1556a6121fbdSMatthew G. Knepley ierr = PetscOptionsInt("-dm_refine_hierarchy","equivalent to -dm_forest_set_minimum_refinement 0 and -dm_forest_set_initial_refinement",NULL,initRefinement,&initRefinement,&flg);CHKERRQ(ierr); 1557a6121fbdSMatthew G. Knepley if (flg) { 1558a6121fbdSMatthew G. Knepley ierr = DMForestSetMinimumRefinement(dm,0);CHKERRQ(ierr); 1559a6121fbdSMatthew G. Knepley ierr = DMForestSetInitialRefinement(dm,initRefinement);CHKERRQ(ierr); 1560a6121fbdSMatthew G. Knepley } 1561a6121fbdSMatthew G. Knepley #endif 1562dd8e54a2SToby Isaac ierr = DMForestGetMinimumRefinement(dm,&minRefinement);CHKERRQ(ierr); 1563dd8e54a2SToby Isaac ierr = PetscOptionsInt("-dm_forest_minimum_refinement","set the minimum level of refinement in the forest","DMForestSetMinimumRefinement",minRefinement,&minRefinement,&flg);CHKERRQ(ierr); 1564dd8e54a2SToby Isaac if (flg) { 1565dd8e54a2SToby Isaac ierr = DMForestSetMinimumRefinement(dm,minRefinement);CHKERRQ(ierr); 1566db4d5e8cSToby Isaac } 156756ba9f64SToby Isaac ierr = DMForestGetInitialRefinement(dm,&initRefinement);CHKERRQ(ierr); 156856ba9f64SToby Isaac ierr = PetscOptionsInt("-dm_forest_initial_refinement","set the initial level of refinement in the forest","DMForestSetInitialRefinement",initRefinement,&initRefinement,&flg);CHKERRQ(ierr); 156956ba9f64SToby Isaac if (flg) { 157056ba9f64SToby Isaac ierr = DMForestSetInitialRefinement(dm,initRefinement);CHKERRQ(ierr); 157156ba9f64SToby Isaac } 1572c7eeac06SToby Isaac ierr = DMForestGetMaximumRefinement(dm,&maxRefinement);CHKERRQ(ierr); 1573c7eeac06SToby Isaac ierr = PetscOptionsInt("-dm_forest_maximum_refinement","set the maximum level of refinement in the forest","DMForestSetMaximumRefinement",maxRefinement,&maxRefinement,&flg);CHKERRQ(ierr); 1574c7eeac06SToby Isaac if (flg) { 1575c7eeac06SToby Isaac ierr = DMForestSetMaximumRefinement(dm,maxRefinement);CHKERRQ(ierr); 1576c7eeac06SToby Isaac } 1577c7eeac06SToby Isaac ierr = DMForestGetAdaptivityStrategy(dm,&adaptStrategy);CHKERRQ(ierr); 1578c7eeac06SToby Isaac ierr = PetscOptionsString("-dm_forest_adaptivity_strategy","the forest's adaptivity-flag resolution strategy","DMForestSetAdaptivityStrategy",adaptStrategy,stringBuffer,256,&flg);CHKERRQ(ierr); 1579c7eeac06SToby Isaac if (flg) { 1580c7eeac06SToby Isaac ierr = DMForestSetAdaptivityStrategy(dm,(DMForestAdaptivityStrategy)stringBuffer);CHKERRQ(ierr); 1581c7eeac06SToby Isaac } 1582c7eeac06SToby Isaac ierr = DMForestGetGradeFactor(dm,&grade);CHKERRQ(ierr); 1583c7eeac06SToby Isaac ierr = PetscOptionsInt("-dm_forest_grade_factor","grade factor between neighboring cells","DMForestSetGradeFactor",grade,&grade,&flg);CHKERRQ(ierr); 1584c7eeac06SToby Isaac if (flg) { 1585c7eeac06SToby Isaac ierr = DMForestSetGradeFactor(dm,grade);CHKERRQ(ierr); 1586c7eeac06SToby Isaac } 1587c7eeac06SToby Isaac ierr = DMForestGetCellWeightFactor(dm,&weightsFactor);CHKERRQ(ierr); 1588c7eeac06SToby Isaac ierr = PetscOptionsReal("-dm_forest_cell_weight_factor","multiplying weight factor for cell refinement","DMForestSetCellWeightFactor",weightsFactor,&weightsFactor,&flg);CHKERRQ(ierr); 1589c7eeac06SToby Isaac if (flg) { 1590c7eeac06SToby Isaac ierr = DMForestSetCellWeightFactor(dm,weightsFactor);CHKERRQ(ierr); 1591c7eeac06SToby Isaac } 1592db4d5e8cSToby Isaac ierr = PetscOptionsTail();CHKERRQ(ierr); 1593db4d5e8cSToby Isaac PetscFunctionReturn(0); 1594db4d5e8cSToby Isaac } 1595db4d5e8cSToby Isaac 1596db4d5e8cSToby Isaac #undef __FUNCT__ 1597d8984e3bSMatthew G. Knepley #define __FUNCT__ "DMCreateSubDM_Forest" 1598d8984e3bSMatthew G. Knepley PetscErrorCode DMCreateSubDM_Forest(DM dm, PetscInt numFields, PetscInt fields[], IS *is, DM *subdm) 1599d8984e3bSMatthew G. Knepley { 1600d8984e3bSMatthew G. Knepley PetscErrorCode ierr; 1601d8984e3bSMatthew G. Knepley 1602d8984e3bSMatthew G. Knepley PetscFunctionBegin; 1603d8984e3bSMatthew G. Knepley if (subdm) {ierr = DMClone(dm, subdm);CHKERRQ(ierr);} 1604d8984e3bSMatthew G. Knepley ierr = DMCreateSubDM_Section_Private(dm, numFields, fields, is, subdm);CHKERRQ(ierr); 1605d8984e3bSMatthew G. Knepley PetscFunctionReturn(0); 1606d8984e3bSMatthew G. Knepley } 1607d8984e3bSMatthew G. Knepley 1608d8984e3bSMatthew G. Knepley #undef __FUNCT__ 16095421bac9SToby Isaac #define __FUNCT__ "DMRefine_Forest" 16105421bac9SToby Isaac PetscErrorCode DMRefine_Forest(DM dm, MPI_Comm comm, DM *dmRefined) 16115421bac9SToby Isaac { 16125421bac9SToby Isaac DMLabel refine; 16135421bac9SToby Isaac DM fineDM; 16145421bac9SToby Isaac PetscErrorCode ierr; 16155421bac9SToby Isaac 16165421bac9SToby Isaac PetscFunctionBegin; 16175421bac9SToby Isaac ierr = DMGetFineDM(dm,&fineDM);CHKERRQ(ierr); 16185421bac9SToby Isaac if (fineDM) { 16195421bac9SToby Isaac ierr = PetscObjectReference((PetscObject)fineDM);CHKERRQ(ierr); 16205421bac9SToby Isaac *dmRefined = fineDM; 16215421bac9SToby Isaac PetscFunctionReturn(0); 16225421bac9SToby Isaac } 16235421bac9SToby Isaac ierr = DMForestTemplate(dm,comm,dmRefined);CHKERRQ(ierr); 16245421bac9SToby Isaac ierr = DMGetLabel(dm,"refine",&refine);CHKERRQ(ierr); 16255421bac9SToby Isaac if (!refine) { 16265421bac9SToby Isaac ierr = DMCreateLabel(dm,"refine");CHKERRQ(ierr); 16275421bac9SToby Isaac ierr = DMGetLabel(dm,"refine",&refine);CHKERRQ(ierr); 16285421bac9SToby Isaac ierr = DMLabelSetDefaultValue(refine,DM_FOREST_REFINE);CHKERRQ(ierr); 16295421bac9SToby Isaac } 16305421bac9SToby Isaac ierr = DMForestSetAdaptivityLabel(*dmRefined,"refine");CHKERRQ(ierr); 16315421bac9SToby Isaac PetscFunctionReturn(0); 16325421bac9SToby Isaac } 16335421bac9SToby Isaac 16345421bac9SToby Isaac #undef __FUNCT__ 16355421bac9SToby Isaac #define __FUNCT__ "DMCoarsen_Forest" 16365421bac9SToby Isaac PetscErrorCode DMCoarsen_Forest(DM dm, MPI_Comm comm, DM *dmCoarsened) 16375421bac9SToby Isaac { 16385421bac9SToby Isaac DMLabel coarsen; 16395421bac9SToby Isaac DM coarseDM; 16405421bac9SToby Isaac PetscErrorCode ierr; 16415421bac9SToby Isaac 16425421bac9SToby Isaac PetscFunctionBegin; 16434098eed7SToby Isaac { 16444098eed7SToby Isaac PetscMPIInt mpiComparison; 16454098eed7SToby Isaac MPI_Comm dmcomm = PetscObjectComm((PetscObject)dm); 16464098eed7SToby Isaac 16474098eed7SToby Isaac ierr = MPI_Comm_compare(comm, dmcomm, &mpiComparison);CHKERRQ(ierr); 1648f885a11aSToby Isaac if (mpiComparison != MPI_IDENT && mpiComparison != MPI_CONGRUENT) SETERRQ(dmcomm,PETSC_ERR_SUP,"No support for different communicators yet"); 16494098eed7SToby Isaac } 16505421bac9SToby Isaac ierr = DMGetCoarseDM(dm,&coarseDM);CHKERRQ(ierr); 16515421bac9SToby Isaac if (coarseDM) { 16525421bac9SToby Isaac ierr = PetscObjectReference((PetscObject)coarseDM);CHKERRQ(ierr); 16535421bac9SToby Isaac *dmCoarsened = coarseDM; 16545421bac9SToby Isaac PetscFunctionReturn(0); 16555421bac9SToby Isaac } 16565421bac9SToby Isaac ierr = DMForestTemplate(dm,comm,dmCoarsened);CHKERRQ(ierr); 16574098eed7SToby Isaac ierr = DMForestSetAdaptivityPurpose(coarseDM,DM_FOREST_COARSEN);CHKERRQ(ierr); 16585421bac9SToby Isaac ierr = DMGetLabel(dm,"coarsen",&coarsen);CHKERRQ(ierr); 16595421bac9SToby Isaac if (!coarsen) { 16605421bac9SToby Isaac ierr = DMCreateLabel(dm,"coarsen");CHKERRQ(ierr); 16615421bac9SToby Isaac ierr = DMGetLabel(dm,"coarsen",&coarsen);CHKERRQ(ierr); 16625421bac9SToby Isaac ierr = DMLabelSetDefaultValue(coarsen,DM_FOREST_COARSEN);CHKERRQ(ierr); 16635421bac9SToby Isaac } 16645421bac9SToby Isaac ierr = DMForestSetAdaptivityLabel(*dmCoarsened,"coarsen");CHKERRQ(ierr); 16655421bac9SToby Isaac PetscFunctionReturn(0); 16665421bac9SToby Isaac } 16675421bac9SToby Isaac 16685421bac9SToby Isaac #undef __FUNCT__ 1669d222f98bSToby Isaac #define __FUNCT__ "DMInitialize_Forest" 1670d222f98bSToby Isaac static PetscErrorCode DMInitialize_Forest(DM dm) 1671d222f98bSToby Isaac { 1672d222f98bSToby Isaac PetscErrorCode ierr; 1673d222f98bSToby Isaac 1674d222f98bSToby Isaac PetscFunctionBegin; 1675d222f98bSToby Isaac ierr = PetscMemzero(dm->ops,sizeof(*(dm->ops)));CHKERRQ(ierr); 1676d222f98bSToby Isaac 1677d222f98bSToby Isaac dm->ops->clone = DMClone_Forest; 1678d222f98bSToby Isaac dm->ops->setfromoptions = DMSetFromOptions_Forest; 1679d222f98bSToby Isaac dm->ops->destroy = DMDestroy_Forest; 1680d8984e3bSMatthew G. Knepley dm->ops->createsubdm = DMCreateSubDM_Forest; 16815421bac9SToby Isaac dm->ops->refine = DMRefine_Forest; 16825421bac9SToby Isaac dm->ops->coarsen = DMCoarsen_Forest; 1683d222f98bSToby Isaac PetscFunctionReturn(0); 1684d222f98bSToby Isaac } 1685d222f98bSToby Isaac 16869be51f97SToby Isaac /*MC 16879be51f97SToby Isaac DMFOREST = "forest" - A DM object that encapsulates a hierarchically refined mesh. Forests usually have a base DM (see DMForestGetBaseDM()), from which it is refined. The refinement and partitioning of forests is considered immutable after DMSetUp() is called. To adapt a mesh, one should call DMForestTemplate() to create a new mesh that will default to being identical to it, specify how that mesh should differ, and then calling DMSetUp() on the new mesh. 16889be51f97SToby Isaac 16899be51f97SToby Isaac To specify that a mesh should be refined or coarsened from the previous mesh, a label should be defined on the previous mesh whose values indicate which cells should be refined (DM_FOREST_REFINE) or coarsened (DM_FOREST_COARSEN) and how (subtypes are free to allow additional values for things like anisotropic refinement). The name of the label should be given to the *new* mesh with DMForestSetAdaptivityLabel(). 16909be51f97SToby Isaac 16919be51f97SToby Isaac Level: advanced 16929be51f97SToby Isaac 16939be51f97SToby Isaac .seealso: DMType, DMCreate(), DMSetType(), DMForestGetBaseDM(), DMForestSetBaseDM(), DMForestTemplate(), DMForestSetAdaptivityLabel() 16949be51f97SToby Isaac M*/ 16959be51f97SToby Isaac 1696d222f98bSToby Isaac #undef __FUNCT__ 1697db4d5e8cSToby Isaac #define __FUNCT__ "DMCreate_Forest" 1698db4d5e8cSToby Isaac PETSC_EXTERN PetscErrorCode DMCreate_Forest(DM dm) 1699db4d5e8cSToby Isaac { 1700db4d5e8cSToby Isaac DM_Forest *forest; 1701db4d5e8cSToby Isaac PetscErrorCode ierr; 1702db4d5e8cSToby Isaac 1703db4d5e8cSToby Isaac PetscFunctionBegin; 1704db4d5e8cSToby Isaac PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 1705db4d5e8cSToby Isaac ierr = PetscNewLog(dm,&forest);CHKERRQ(ierr); 1706db4d5e8cSToby Isaac dm->dim = 0; 1707db4d5e8cSToby Isaac dm->data = forest; 1708db4d5e8cSToby Isaac forest->refct = 1; 1709db4d5e8cSToby Isaac forest->data = NULL; 171058762b62SToby Isaac forest->setfromoptionscalled = PETSC_FALSE; 1711db4d5e8cSToby Isaac forest->topology = NULL; 1712db4d5e8cSToby Isaac forest->base = NULL; 1713db4d5e8cSToby Isaac forest->adjDim = PETSC_DEFAULT; 1714db4d5e8cSToby Isaac forest->overlap = PETSC_DEFAULT; 1715db4d5e8cSToby Isaac forest->minRefinement = PETSC_DEFAULT; 1716db4d5e8cSToby Isaac forest->maxRefinement = PETSC_DEFAULT; 171756ba9f64SToby Isaac forest->initRefinement = PETSC_DEFAULT; 1718c7eeac06SToby Isaac forest->cStart = PETSC_DETERMINE; 1719c7eeac06SToby Isaac forest->cEnd = PETSC_DETERMINE; 1720db4d5e8cSToby Isaac forest->cellSF = 0; 1721ebdf65a2SToby Isaac forest->adaptLabel = NULL; 1722db4d5e8cSToby Isaac forest->gradeFactor = 2; 1723db4d5e8cSToby Isaac forest->cellWeights = NULL; 1724db4d5e8cSToby Isaac forest->cellWeightsCopyMode = PETSC_USE_POINTER; 1725db4d5e8cSToby Isaac forest->weightsFactor = 1.; 1726db4d5e8cSToby Isaac forest->weightCapacity = 1.; 1727a73e2921SToby Isaac ierr = DMForestSetAdaptivityStrategy(dm,DMFORESTADAPTALL);CHKERRQ(ierr); 1728d222f98bSToby Isaac ierr = DMInitialize_Forest(dm);CHKERRQ(ierr); 1729db4d5e8cSToby Isaac PetscFunctionReturn(0); 1730db4d5e8cSToby Isaac } 1731db4d5e8cSToby Isaac 1732