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