Date: 2022-03-04T17:38:42+00:00

Actual source code: ex19.c

      1: /*
      2:      Demonstrates creating domain decomposition DAs and how to shuffle around data between the two
      3:  */

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

      8: static char help[] = "Test for DMDA with overlap.\n\n";

     10: int main(int argc,char **argv)
     11: {
     13:   DM             da;

     15:   PetscInitialize(&argc,&argv,(char*)0,help);if (ierr) return ierr;
     16:   /* Build of the DMDA -- 1D -- boundary_none */
     17:   PetscPrintf(PETSC_COMM_WORLD,"1D -- DM_BOUNDARY_NONE\n");
     18:   DMDACreate(PETSC_COMM_WORLD, &da);
     19:   DMSetDimension(da, 1);
     20:   DMDASetSizes(da, 8, 1, 1);
     21:   DMDASetBoundaryType(da, DM_BOUNDARY_NONE, DM_BOUNDARY_NONE, DM_BOUNDARY_NONE);
     22:   DMDASetDof(da, 1);
     23:   DMDASetStencilWidth(da, 1);
     24:   DMDASetOverlap(da,1,1,1);
     25:   DMSetFromOptions(da);
     26:   DMSetOptionsPrefix(da,"n1d_");
     27:   DMSetFromOptions(da);
     28:   DMSetUp(da);
     29:   DMView(da,PETSC_VIEWER_STDOUT_WORLD);
     30:   DMDestroy(&da);

     32:   /* Build of the DMDA -- 1D -- boundary_ghosted */
     33:   PetscPrintf(PETSC_COMM_WORLD,"1D -- DM_BOUNDARY_GHOSTED\n");
     34:   DMDACreate(PETSC_COMM_WORLD, &da);
     35:   DMSetDimension(da, 1);
     36:   DMDASetSizes(da, 8, 1, 1);
     37:   DMDASetBoundaryType(da, DM_BOUNDARY_GHOSTED, DM_BOUNDARY_GHOSTED, DM_BOUNDARY_GHOSTED);
     38:   DMDASetDof(da, 2);
     39:   DMDASetStencilWidth(da, 1);
     40:   DMDASetOverlap(da,1,1,1);
     41:   DMSetFromOptions(da);
     42:   DMSetOptionsPrefix(da,"g1d_");
     43:   DMSetFromOptions(da);
     44:   DMSetUp(da);
     45:   DMView(da,PETSC_VIEWER_STDOUT_WORLD);
     46:   DMDestroy(&da);

     48:   /* Build of the DMDA -- 1D -- boundary_periodic */
     49:   PetscPrintf(PETSC_COMM_WORLD,"1D -- DM_BOUNDARY_PERIODIC\n");
     50:   DMDACreate(PETSC_COMM_WORLD, &da);
     51:   DMSetDimension(da, 1);
     52:   DMDASetSizes(da, 8, 1, 1);
     53:   DMDASetBoundaryType(da, DM_BOUNDARY_PERIODIC, DM_BOUNDARY_PERIODIC, DM_BOUNDARY_PERIODIC);
     54:   DMDASetDof(da, 2);
     55:   DMDASetStencilWidth(da, 1);
     56:   DMDASetOverlap(da,1,1,1);
     57:   DMSetFromOptions(da);
     58:   DMSetOptionsPrefix(da,"p1d_");
     59:   DMSetFromOptions(da);
     60:   DMSetUp(da);
     61:   DMView(da,PETSC_VIEWER_STDOUT_WORLD);
     62:   DMDestroy(&da);

     64:   /* Build of the DMDA -- 2D -- boundary_none */
     65:   PetscPrintf(PETSC_COMM_WORLD,"2D -- DM_BOUNDARY_NONE\n");
     66:   DMDACreate(PETSC_COMM_WORLD, &da);
     67:   DMSetDimension(da, 2);
     68:   DMDASetSizes(da, 8, 8, 1);
     69:   DMDASetBoundaryType(da, DM_BOUNDARY_NONE, DM_BOUNDARY_NONE, DM_BOUNDARY_NONE);
     70:   DMDASetDof(da, 2);
     71:   DMDASetStencilWidth(da, 1);
     72:   DMDASetOverlap(da,1,1,1);
     73:   DMSetFromOptions(da);
     74:   DMSetOptionsPrefix(da,"n2d_");
     75:   DMSetFromOptions(da);
     76:   DMSetUp(da);
     77:   DMView(da,PETSC_VIEWER_STDOUT_WORLD);
     78:   DMDestroy(&da);

     80:   /* Build of the DMDA -- 2D -- boundary_ghosted */
     81:   PetscPrintf(PETSC_COMM_WORLD,"2D -- DM_BOUNDARY_GHOSTED\n");
     82:   DMDACreate(PETSC_COMM_WORLD, &da);
     83:   DMSetDimension(da, 2);
     84:   DMDASetSizes(da, 8, 8, 1);
     85:   DMDASetBoundaryType(da, DM_BOUNDARY_GHOSTED, DM_BOUNDARY_GHOSTED, DM_BOUNDARY_GHOSTED);
     86:   DMDASetDof(da, 2);
     87:   DMDASetStencilWidth(da, 1);
     88:   DMDASetOverlap(da,1,1,1);
     89:   DMSetFromOptions(da);
     90:   DMSetOptionsPrefix(da,"g2d_");
     91:   DMSetFromOptions(da);
     92:   DMSetUp(da);
     93:   DMView(da,PETSC_VIEWER_STDOUT_WORLD);
     94:   DMDestroy(&da);

     96:   /* Build of the DMDA -- 2D -- boundary_periodic */
     97:   PetscPrintf(PETSC_COMM_WORLD,"2D -- DM_BOUNDARY_PERIODIC\n");
     98:   DMDACreate(PETSC_COMM_WORLD, &da);
     99:   DMSetDimension(da, 2);
    100:   DMDASetSizes(da, 8, 8, 1);
    101:   DMDASetBoundaryType(da, DM_BOUNDARY_PERIODIC, DM_BOUNDARY_PERIODIC, DM_BOUNDARY_PERIODIC);
    102:   DMDASetDof(da, 2);
    103:   DMDASetStencilWidth(da, 1);
    104:   DMDASetOverlap(da,1,1,1);
    105:   DMSetFromOptions(da);
    106:   DMSetOptionsPrefix(da,"p2d_");
    107:   DMSetFromOptions(da);
    108:   DMSetUp(da);
    109:   DMView(da,PETSC_VIEWER_STDOUT_WORLD);
    110:   DMDestroy(&da);

    112:   /* Build of the DMDA -- 3D -- boundary_none */
    113:   PetscPrintf(PETSC_COMM_WORLD,"3D -- DM_BOUNDARY_NONE\n");
    114:   DMDACreate(PETSC_COMM_WORLD, &da);
    115:   DMSetDimension(da, 3);
    116:   DMDASetSizes(da, 8, 8, 8);
    117:   DMDASetBoundaryType(da, DM_BOUNDARY_NONE, DM_BOUNDARY_NONE, DM_BOUNDARY_NONE);
    118:   DMDASetDof(da, 2);
    119:   DMDASetStencilWidth(da, 1);
    120:   DMDASetOverlap(da,1,1,1);
    121:   DMSetFromOptions(da);
    122:   DMSetOptionsPrefix(da,"n3d_");
    123:   DMSetFromOptions(da);
    124:   DMSetUp(da);
    125:   DMView(da,PETSC_VIEWER_STDOUT_WORLD);
    126:   DMDestroy(&da);

    128:   /* Build of the DMDA -- 3D -- boundary_ghosted */
    129:   PetscPrintf(PETSC_COMM_WORLD,"3D -- DM_BOUNDARY_GHOSTED\n");
    130:   DMDACreate(PETSC_COMM_WORLD, &da);
    131:   DMSetDimension(da, 3);
    132:   DMDASetSizes(da, 8, 8, 8);
    133:   DMDASetBoundaryType(da, DM_BOUNDARY_GHOSTED, DM_BOUNDARY_GHOSTED, DM_BOUNDARY_GHOSTED);
    134:   DMDASetDof(da, 2);
    135:   DMDASetStencilWidth(da, 1);
    136:   DMDASetOverlap(da,1,1,1);
    137:   DMSetFromOptions(da);
    138:   DMSetOptionsPrefix(da,"g3d_");
    139:   DMSetFromOptions(da);
    140:   DMSetUp(da);
    141:   DMView(da,PETSC_VIEWER_STDOUT_WORLD);
    142:   DMDestroy(&da);

    144:   /* Build of the DMDA -- 3D -- boundary_periodic */
    145:   PetscPrintf(PETSC_COMM_WORLD,"3D -- DM_BOUNDARY_PERIODIC\n");
    146:   DMDACreate(PETSC_COMM_WORLD, &da);
    147:   DMSetDimension(da, 3);
    148:   DMDASetSizes(da, 8, 8, 8);
    149:   DMDASetBoundaryType(da, DM_BOUNDARY_PERIODIC, DM_BOUNDARY_PERIODIC, DM_BOUNDARY_PERIODIC);
    150:   DMDASetDof(da, 2);
    151:   DMDASetStencilWidth(da, 1);
    152:   DMDASetOverlap(da,1,1,1);
    153:   DMSetFromOptions(da);
    154:   DMSetOptionsPrefix(da,"p3d_");
    155:   DMSetFromOptions(da);
    156:   DMSetUp(da);
    157:   DMView(da,PETSC_VIEWER_STDOUT_WORLD);
    158:   DMDestroy(&da);

    160:   /* test moving data in and out */
    161:   PetscFinalize();
    162:   return ierr;
    163: }

    165: /*TEST

    167:    test:

    169: TEST*/