Actual source code: ex37.c

petsc-3.6.4 2016-04-12
Report Typos and Errors
  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: }

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

 25:   PetscInitialize(&argc,&argv,(char*)0,help);

 27:   DMDACreate1d(PETSC_COMM_WORLD,DM_BOUNDARY_NONE,10,3,1,NULL,&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 0;
 38: }