Actual source code: ex25.c

petsc-3.13.6 2020-09-29
Report Typos and Errors

  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: }



 49: /*TEST

 51:       test:
 52:          filter: grep -v -i Process
 53:          output_file: output/ex25_1.out

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

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

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

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

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

 85: TEST*/