Actual source code: ex51.c

  1: static char help[] = "DMStag slot test (to excerpt for manual)\n\n";

  3: #include <petscdmstag.h>

  5: int main(int argc, char **argv)
  6: {
  7:   DM              dm;
  8:   Vec             x;
  9:   PetscInt        start_x, start_y, start_z, n_x, n_y, n_z, n_extra_x, n_extra_y, n_extra_z, slot_vertex_2;
 10:   PetscScalar ****x_array;

 12:   const DMStagStencilLocation location_vertex = DMSTAG_BACK_DOWN_LEFT;
 13:   const PetscInt              dof0 = 2, dof1 = 2, dof2 = 2, dof3 = 2, N_x = 3, N_y = 3, N_z = 3;

 16:   PetscInitialize(&argc, &argv, (char *)0, help);

 18:   DMStagCreate3d(PETSC_COMM_WORLD, DM_BOUNDARY_NONE, DM_BOUNDARY_NONE, DM_BOUNDARY_NONE, N_x, N_y, N_z, PETSC_DECIDE, PETSC_DECIDE, PETSC_DECIDE, dof0, dof1, dof2, dof3, DMSTAG_STENCIL_BOX, 1, NULL, NULL, NULL, &dm);
 19:   DMSetFromOptions(dm);
 20:   DMSetUp(dm);

 22:   DMCreateLocalVector(dm, &x);
 23:   VecZeroEntries(x);

 25:   /* Set the second component of all vertex dof to 2.0 */
 26:   DMStagGetCorners(dm, &start_x, &start_y, &start_z, &n_x, &n_y, &n_z, &n_extra_x, &n_extra_y, &n_extra_z);
 27:   DMStagGetLocationSlot(dm, location_vertex, 1, &slot_vertex_2);
 28:   DMStagVecGetArray(dm, x, &x_array);
 29:   for (PetscInt k = start_z; k < start_z + n_z + n_extra_z; ++k) {
 30:     for (PetscInt j = start_y; j < start_y + n_y + n_extra_y; ++j) {
 31:       for (PetscInt i = start_x; i < start_x + n_x + n_extra_x; ++i) x_array[k][j][i][slot_vertex_2] = 2.0;
 32:     }
 33:   }
 34:   DMStagVecRestoreArray(dm, x, &x_array);
 35:   VecDestroy(&x);
 36:   DMDestroy(&dm);
 37:   PetscFinalize();
 38:   return 0;
 39: }

 41: /*TEST

 43:    test:

 45: TEST*/