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