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

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

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

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

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

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

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

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

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

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

165: /*TEST

167:    test:

169: TEST*/