Date: 2022-03-31T04:47:47+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: {
     12:   DM             da;

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

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

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

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

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

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

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

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

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

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

    164: /*TEST

    166:    test:

    168: TEST*/