Actual source code: ex19.c

petsc-3.14.6 2021-03-30
Report Typos and Errors
  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);


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

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

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


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

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

167: /*TEST

169:    test:

171: TEST*/