Actual source code: ex24.c
petsc-3.7.7 2017-09-25
2: static char help[] = "Tests DMDALocalToGlocal() for dof > 1\n\n";
4: #include <petscdm.h>
5: #include <petscdmda.h>
9: int main(int argc,char **argv)
10: {
11: PetscInt M = 6,N = 5,m = PETSC_DECIDE,n = PETSC_DECIDE,i,j,is,js,in,jen;
13: DM da;
14: Vec local,global;
15: PetscScalar ***l;
17: PetscInitialize(&argc,&argv,(char*)0,help);
19: /* Create distributed array and get vectors */
20: DMDACreate2d(PETSC_COMM_WORLD, DM_BOUNDARY_NONE, DM_BOUNDARY_NONE,DMDA_STENCIL_BOX,M,N,m,n,3,1,NULL,NULL,&da);
21: DMCreateGlobalVector(da,&global);
22: DMCreateLocalVector(da,&local);
24: DMDAGetCorners(da,&is,&js,0,&in,&jen,0);
25: DMDAVecGetArrayDOF(da,local,&l);
26: for (i=is; i<is+in; i++) {
27: for (j=js; j<js+jen; j++) {
28: l[j][i][0] = 3*(i + j*M);
29: l[j][i][1] = 3*(i + j*M) + 1;
30: l[j][i][2] = 3*(i + j*M) + 2;
31: }
32: }
33: DMDAVecRestoreArrayDOF(da,local,&l);
34: DMLocalToGlobalBegin(da,local,ADD_VALUES,global);
35: DMLocalToGlobalEnd(da,local,ADD_VALUES,global);
37: VecView(global,PETSC_VIEWER_STDOUT_WORLD);
39: /* Free memory */
40: VecDestroy(&local);
41: VecDestroy(&global);
42: DMDestroy(&da);
43: PetscFinalize();
44: return 0;
45: }