Actual source code: ex24.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,m = PETSC_DECIDE,n = PETSC_DECIDE,i,j,is,js,in,jen;
 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:   DMDACreate2d(PETSC_COMM_WORLD, DM_BOUNDARY_NONE, DM_BOUNDARY_NONE,DMDA_STENCIL_BOX,M,N,m,n,3,1,NULL,NULL,&da);
 18:   DMSetFromOptions(da);
 19:   DMSetUp(da);
 20:   DMCreateGlobalVector(da,&global);
 21:   DMCreateLocalVector(da,&local);

 23:   DMDAGetCorners(da,&is,&js,0,&in,&jen,0);
 24:   DMDAVecGetArrayDOF(da,local,&l);
 25:   for (i=is; i<is+in; i++) {
 26:     for (j=js; j<js+jen; j++) {
 27:       l[j][i][0] = 3*(i + j*M);
 28:       l[j][i][1] = 3*(i + j*M) + 1;
 29:       l[j][i][2] = 3*(i + j*M) + 2;
 30:     }
 31:   }
 32:   DMDAVecRestoreArrayDOF(da,local,&l);
 33:   DMLocalToGlobalBegin(da,local,ADD_VALUES,global);
 34:   DMLocalToGlobalEnd(da,local,ADD_VALUES,global);

 36:   VecView(global,PETSC_VIEWER_STDOUT_WORLD);

 38:   /* Free memory */
 39:   VecDestroy(&local);
 40:   VecDestroy(&global);
 41:   DMDestroy(&da);
 42:   PetscFinalize();
 43:   return ierr;
 44: }



 48: /*TEST

 50:       test:
 51:          filter: grep -v -i Process
 52:          output_file: output/ex24_1.out

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

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

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

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

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

 84: TEST*/