1 const char help[] = "Test Berend's example"; 2 3 #include <petscdmplex.h> 4 #include <petscdmforest.h> 5 6 int main(int argc, char **argv) 7 { 8 PetscCall(PetscInitialize(&argc, &argv, NULL, help)); 9 MPI_Comm comm = PETSC_COMM_WORLD; 10 PetscInt dim = 3; 11 PetscInt cells_per_dir[] = {3, 3, 3}; 12 PetscReal dir_min[] = {0.0, 0.0, 0.0}; 13 PetscReal dir_max[] = {1.0, 1.0, 1.0}; 14 PetscInt overlap = 1; 15 DMBoundaryType bcs[] = {DM_BOUNDARY_NONE, DM_BOUNDARY_NONE, DM_BOUNDARY_NONE}; 16 DM forest, plex; 17 Vec CoordVec; 18 19 PetscCall(DMCreate(comm, &forest)); 20 PetscCall(DMSetType(forest, DMP8EST)); 21 PetscCall(DMSetBasicAdjacency(forest, PETSC_TRUE, PETSC_TRUE)); 22 { 23 DM dm_base, pdm, idm; 24 PetscCall(DMPlexCreateBoxMesh(comm, dim, PETSC_FALSE /* simplex */ 25 , 26 cells_per_dir, dir_min, dir_max, bcs, PETSC_TRUE /* interpolate */ 27 , 28 &dm_base)); 29 PetscCall(DMSetBasicAdjacency(dm_base, PETSC_TRUE, PETSC_TRUE)); 30 PetscCall(DMPlexDistribute(dm_base, overlap, NULL, &pdm)); 31 if (pdm) { 32 PetscCall(DMDestroy(&dm_base)); 33 dm_base = pdm; 34 } 35 PetscCall(DMPlexInterpolate(dm_base, &idm)); 36 PetscCall(DMDestroy(&dm_base)); 37 dm_base = idm; 38 PetscCall(DMLocalizeCoordinates(dm_base)); 39 PetscCall(DMPlexDistributeSetDefault(dm_base, PETSC_FALSE)); 40 PetscCall(DMSetFromOptions(dm_base)); 41 PetscCall(DMViewFromOptions(dm_base, NULL, "-dm_base_view")); 42 PetscCall(DMCopyFields(dm_base, forest)); 43 PetscCall(DMForestSetBaseDM(forest, dm_base)); 44 PetscCall(DMDestroy(&dm_base)); 45 } 46 PetscCall(DMForestSetPartitionOverlap(forest, 1)); 47 PetscCall(DMSetFromOptions(forest)); 48 PetscCall(DMSetUp(forest)); 49 PetscCall(DMViewFromOptions(forest, NULL, "-dm_forest_view")); 50 51 PetscCall(DMConvert(forest, DMPLEX, &plex)); 52 PetscCall(DMGetCoordinates(plex, &CoordVec)); 53 PetscCall(DMViewFromOptions(forest, NULL, "-dm_plex_view")); 54 55 PetscCall(DMDestroy(&plex)); 56 PetscCall(DMDestroy(&forest)); 57 PetscCall(PetscFinalize()); 58 return 0; 59 } 60 61 /*TEST 62 63 test: 64 requires: p4est 65 suffix: 0 66 67 TEST*/ 68