Actual source code: ex37.c
petsc-3.12.5 2020-03-29
2: static char help[] = "VecView() with a DMDA1d vector and draw viewer.\n\n";
5: #include <petscdm.h>
6: #include <petscdmda.h>
7: #include <petscao.h>
9: PetscErrorCode apply(void *ctx,PetscInt n,const PetscScalar *x,PetscScalar *y)
10: {
11: PetscInt i;
13: for (i=0; i<n; i++) {y[3*i] = x[i]; y[3*i+1] = x[i]*x[i]; y[3*i+2] = x[i]*x[i]*x[i];}
14: return 0;
15: }
17: int main(int argc,char **argv)
18: {
20: DM da;
21: Vec global;
22: PF pf;
24: PetscInitialize(&argc,&argv,(char*)0,help);if (ierr) return ierr;
25: DMDACreate1d(PETSC_COMM_WORLD,DM_BOUNDARY_NONE,10,3,1,NULL,&da);
26: DMSetFromOptions(da);
27: DMSetUp(da);
28: DMCreateGlobalVector(da,&global);
29: PFCreate(PETSC_COMM_WORLD,1,3,&pf);
30: PFSet(pf,apply,NULL,NULL,NULL,NULL);
31: PFApplyVec(pf,NULL,global);
32: PFDestroy(&pf);
33: VecView(global,PETSC_VIEWER_DRAW_WORLD);
34: VecDestroy(&global);
35: DMDestroy(&da);
36: PetscFinalize();
37: return ierr;
38: }
41: /*TEST
43: test:
44: nsize: 2
45: requires: x
47: TEST*/