Actual source code: ex37.c

petsc-3.3-p6 2013-02-11
  1: 
  2: static char help[] = "VecView() with a DA1d vector and draw viewer.\n\n";

  4: #include <petscdmda.h>
  5: #include <petscao.h>

  7: PetscErrorCode apply(void *ctx,PetscInt n,const PetscScalar *x,PetscScalar *y)
  8: {
  9:   PetscInt i;

 11:   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];}
 12:   return 0;
 13: }

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

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

 26:   DMDACreate1d(PETSC_COMM_WORLD,DMDA_BOUNDARY_NONE,10,3,1,PETSC_NULL,&da);
 27:   DMCreateGlobalVector(da,&global);
 28:   PFCreate(PETSC_COMM_WORLD,1,3,&pf);
 29:   PFSet(pf,apply,PETSC_NULL,PETSC_NULL,PETSC_NULL,PETSC_NULL);
 30:   PFApplyVec(pf,PETSC_NULL,global);
 31:   PFDestroy(&pf);
 32:   VecView(global,PETSC_VIEWER_DRAW_WORLD);
 33:   VecDestroy(&global);
 34:   DMDestroy(&da);
 35:   PetscFinalize();
 36:   return 0;
 37: }