1 static char help[] = "Tests mirror boundary conditions in 1-d.\n\n"; 2 3 #include <petscdm.h> 4 #include <petscdmda.h> 5 6 int main(int argc, char **argv) 7 { 8 PetscInt M = 6, stencil_width = 1, dof = 1, m, xstart, i, j; 9 DM da; 10 Vec global, local; 11 PetscScalar **vglobal; 12 PetscViewer sviewer; 13 14 PetscFunctionBeginUser; 15 PetscCall(PetscInitialize(&argc, &argv, (char *)0, help)); 16 PetscCall(PetscOptionsGetInt(NULL, 0, "-stencil_width", &stencil_width, 0)); 17 PetscCall(PetscOptionsGetInt(NULL, 0, "-dof", &dof, 0)); 18 19 PetscCall(DMDACreate1d(PETSC_COMM_WORLD, DM_BOUNDARY_MIRROR, M, dof, stencil_width, NULL, &da)); 20 PetscCall(DMSetFromOptions(da)); 21 PetscCall(DMSetUp(da)); 22 PetscCall(DMDAGetCorners(da, &xstart, 0, 0, &m, 0, 0)); 23 24 PetscCall(DMCreateGlobalVector(da, &global)); 25 PetscCall(DMDAVecGetArrayDOF(da, global, &vglobal)); 26 for (i = xstart; i < xstart + m; i++) { 27 for (j = 0; j < dof; j++) vglobal[i][j] = 100 * (i + 1) + j; 28 } 29 PetscCall(DMDAVecRestoreArrayDOF(da, global, &vglobal)); 30 31 PetscCall(DMCreateLocalVector(da, &local)); 32 PetscCall(DMGlobalToLocalBegin(da, global, INSERT_VALUES, local)); 33 PetscCall(DMGlobalToLocalEnd(da, global, INSERT_VALUES, local)); 34 35 PetscCall(PetscViewerGetSubViewer(PETSC_VIEWER_STDOUT_WORLD, PETSC_COMM_SELF, &sviewer)); 36 PetscCall(VecView(local, sviewer)); 37 PetscCall(PetscViewerRestoreSubViewer(PETSC_VIEWER_STDOUT_WORLD, PETSC_COMM_SELF, &sviewer)); 38 PetscCall(VecView(global, PETSC_VIEWER_STDOUT_WORLD)); 39 40 PetscCall(DMDestroy(&da)); 41 PetscCall(VecDestroy(&local)); 42 PetscCall(VecDestroy(&global)); 43 44 PetscCall(PetscFinalize()); 45 return 0; 46 } 47 48 /*TEST 49 50 test: 51 52 test: 53 suffix: 2 54 nsize: 2 55 filter: grep -v "Vec Object" 56 57 TEST*/ 58