Actual source code: ex37.c
petsc-3.8.4 2018-03-24
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++) {y[3*i] = x[i]; y[3*i+1] = x[i]*x[i]; y[3*i+2] = x[i]*x[i]*x[i];}
13: return 0;
14: }
16: int main(int argc,char **argv)
17: {
19: DM da;
20: Vec global;
21: PF pf;
23: PetscInitialize(&argc,&argv,(char*)0,help);if (ierr) return ierr;
24: DMDACreate1d(PETSC_COMM_WORLD,DM_BOUNDARY_NONE,10,3,1,NULL,&da);
25: DMSetFromOptions(da);
26: DMSetUp(da);
27: DMCreateGlobalVector(da,&global);
28: PFCreate(PETSC_COMM_WORLD,1,3,&pf);
29: PFSet(pf,apply,NULL,NULL,NULL,NULL);
30: PFApplyVec(pf,NULL,global);
31: PFDestroy(&pf);
32: VecView(global,PETSC_VIEWER_DRAW_WORLD);
33: VecDestroy(&global);
34: DMDestroy(&da);
35: PetscFinalize();
36: return ierr;
37: }