Actual source code: ex37.c


  2: static char help[] = "VecView() with a DMDA1d vector and draw viewer.\n\n";

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

  8: PetscErrorCode apply(void *ctx, PetscInt n, const PetscScalar *x, PetscScalar *y)
  9: {
 10:   PetscInt i;

 12:   for (i = 0; i < n; i++) {
 13:     y[3 * i]     = x[i];
 14:     y[3 * i + 1] = x[i] * x[i];
 15:     y[3 * i + 2] = x[i] * x[i] * x[i];
 16:   }
 17:   return 0;
 18: }

 20: int main(int argc, char **argv)
 21: {
 22:   DM  da;
 23:   Vec global;
 24:   PF  pf;

 27:   PetscInitialize(&argc, &argv, (char *)0, help);
 28:   DMDACreate1d(PETSC_COMM_WORLD, DM_BOUNDARY_NONE, 10, 3, 1, NULL, &da);
 29:   DMSetFromOptions(da);
 30:   DMSetUp(da);
 31:   DMCreateGlobalVector(da, &global);
 32:   PFCreate(PETSC_COMM_WORLD, 1, 3, &pf);
 33:   PFSet(pf, apply, NULL, NULL, NULL, NULL);
 34:   PFApplyVec(pf, NULL, global);
 35:   PFDestroy(&pf);
 36:   VecView(global, PETSC_VIEWER_DRAW_WORLD);
 37:   VecDestroy(&global);
 38:   DMDestroy(&da);
 39:   PetscFinalize();
 40:   return 0;
 41: }

 43: /*TEST

 45:    test:
 46:       nsize: 2
 47:       requires: x

 49: TEST*/