xref: /petsc/src/dm/tests/ex37.c (revision 66af8762ec03dbef0e079729eb2a1734a35ed7ff)
1 static char help[] = "VecView() with a DMDA1d vector and draw viewer.\n\n";
2 
3 #include <petscdm.h>
4 #include <petscdmda.h>
5 #include <petscao.h>
6 
7 PetscErrorCode apply(void *ctx, PetscInt n, const PetscScalar *x, PetscScalar *y)
8 {
9   PetscInt i;
10 
11   for (i = 0; i < n; i++) {
12     y[3 * i]     = x[i];
13     y[3 * i + 1] = x[i] * x[i];
14     y[3 * i + 2] = x[i] * x[i] * x[i];
15   }
16   return PETSC_SUCCESS;
17 }
18 
19 int main(int argc, char **argv)
20 {
21   DM  da;
22   Vec global;
23   PF  pf;
24 
25   PetscFunctionBeginUser;
26   PetscCall(PetscInitialize(&argc, &argv, (char *)0, help));
27   PetscCall(DMDACreate1d(PETSC_COMM_WORLD, DM_BOUNDARY_NONE, 10, 3, 1, NULL, &da));
28   PetscCall(DMSetFromOptions(da));
29   PetscCall(DMSetUp(da));
30   PetscCall(DMCreateGlobalVector(da, &global));
31   PetscCall(PFCreate(PETSC_COMM_WORLD, 1, 3, &pf));
32   PetscCall(PFSet(pf, apply, NULL, NULL, NULL, NULL));
33   PetscCall(PFApplyVec(pf, NULL, global));
34   PetscCall(PFDestroy(&pf));
35   PetscCall(VecView(global, PETSC_VIEWER_DRAW_WORLD));
36   PetscCall(VecDestroy(&global));
37   PetscCall(DMDestroy(&da));
38   PetscCall(PetscFinalize());
39   return 0;
40 }
41 
42 /*TEST
43 
44    test:
45       nsize: 2
46       requires: x
47 
48 TEST*/
49