Actual source code: ex40.c
petsc-3.4.2 2013-07-02
2: static char help[] = "Tests mirror boundary conditions in 2-d.\n\n";
4: #include <petscdmda.h>
8: int main(int argc,char **argv)
9: {
11: PetscInt M = -8, N = -8,stencil_width = 1, dof = 1,m,n,xstart,ystart,i,j,c;
12: DM da;
13: Vec global,local;
14: PetscScalar ***vglobal;
16: PetscInitialize(&argc,&argv,(char*)0,help);
19: PetscOptionsGetInt(0,"-stencil_width",&stencil_width,0);
20: PetscOptionsGetInt(0,"-dof",&dof,0);
22: DMDACreate2d(PETSC_COMM_WORLD,DMDA_BOUNDARY_MIRROR,DMDA_BOUNDARY_MIRROR,DMDA_STENCIL_STAR,M,N,PETSC_DECIDE,PETSC_DECIDE,dof,stencil_width,NULL,NULL,&da);
23: DMDAGetCorners(da,&xstart,&ystart,0,&m,&n,0);
25: DMCreateGlobalVector(da,&global);
26: DMDAVecGetArrayDOF(da,global,&vglobal);
27: for (j=ystart; j<ystart+n; j++) {
28: for (i=xstart; i<xstart+m; i++) {
29: for (c=0; c<dof; c++) {
30: vglobal[j][i][c] = 100*j + 10*(i+1) + c;
31: }
32: }
33: }
34: DMDAVecRestoreArrayDOF(da,global,&vglobal);
36: DMCreateLocalVector(da,&local);
37: DMGlobalToLocalBegin(da,global,INSERT_VALUES,local);
38: DMGlobalToLocalEnd(da,global,INSERT_VALUES,local);
40: PetscSequentialPhaseBegin(PETSC_COMM_WORLD,1);
41: VecView(local,PETSC_VIEWER_STDOUT_SELF);
42: PetscSequentialPhaseEnd(PETSC_COMM_WORLD,1);
43: VecView(global,PETSC_VIEWER_STDOUT_WORLD);
45: DMDestroy(&da);
46: VecDestroy(&local);
47: VecDestroy(&global);
49: PetscFinalize();
50: return 0;
51: }