Actual source code: ex25.c


  2: static char help[] = "Tests DMLocalToGlobal() for dof > 1\n\n";

  4: #include <petscdm.h>
  5: #include <petscdmda.h>

  7: int main(int argc,char **argv)
  8: {
  9:   PetscInt       M = 6,N = 5,P = 4, m = PETSC_DECIDE,n = PETSC_DECIDE,p = PETSC_DECIDE,i,j,k,is,js,ks,in,jen,kn;
 11:   DM             da;
 12:   Vec            local,global;
 13:   PetscScalar    ****l;

 15:   PetscInitialize(&argc,&argv,(char*)0,help);if (ierr) return ierr;
 16:   /* Create distributed array and get vectors */
 17:   DMDACreate3d(PETSC_COMM_WORLD,DM_BOUNDARY_NONE,DM_BOUNDARY_NONE,DM_BOUNDARY_NONE,DMDA_STENCIL_BOX,M,N,P,m,n,p,2,1,NULL,NULL,NULL,&da);
 18:   DMSetFromOptions(da);
 19:   DMSetUp(da);
 20:   DMCreateGlobalVector(da,&global);
 21:   DMCreateLocalVector(da,&local);

 23:   DMDAGetCorners(da,&is,&js,&ks,&in,&jen,&kn);
 24:   DMDAVecGetArrayDOF(da,local,&l);
 25:   for (i=is; i<is+in; i++) {
 26:     for (j=js; j<js+jen; j++) {
 27:       for (k=ks; k<ks+kn; k++) {
 28:         l[k][j][i][0] = 2*(i + j*M + k*M*N);
 29:         l[k][j][i][1] = 2*(i + j*M + k*M*N) + 1;
 30:       }
 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 ierr;
 45: }

 47: /*TEST

 49:       test:
 50:          filter: grep -v -i Process
 51:          output_file: output/ex25_1.out

 53:       test:
 54:          suffix: 2
 55:          nsize: 2
 56:          filter: grep -v -i Process
 57:          output_file: output/ex25_2.out

 59:       test:
 60:          suffix: 3
 61:          nsize: 3
 62:          filter: grep -v -i Process
 63:          output_file: output/ex25_2.out

 65:       test:
 66:          suffix: 4
 67:          nsize: 4
 68:          filter: grep -v -i Process
 69:          output_file: output/ex25_2.out

 71:       test:
 72:          suffix: 5
 73:          nsize: 5
 74:          filter: grep -v -i Process
 75:          output_file: output/ex25_2.out

 77:       test:
 78:          suffix: 6
 79:          nsize: 6
 80:          filter: grep -v -i Process
 81:          output_file: output/ex25_2.out

 83: TEST*/