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++) {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 } 15 16 int main(int argc,char **argv) 17 { 18 DM da; 19 Vec global; 20 PF pf; 21 22 PetscFunctionBeginUser; 23 PetscCall(PetscInitialize(&argc,&argv,(char*)0,help)); 24 PetscCall(DMDACreate1d(PETSC_COMM_WORLD,DM_BOUNDARY_NONE,10,3,1,NULL,&da)); 25 PetscCall(DMSetFromOptions(da)); 26 PetscCall(DMSetUp(da)); 27 PetscCall(DMCreateGlobalVector(da,&global)); 28 PetscCall(PFCreate(PETSC_COMM_WORLD,1,3,&pf)); 29 PetscCall(PFSet(pf,apply,NULL,NULL,NULL,NULL)); 30 PetscCall(PFApplyVec(pf,NULL,global)); 31 PetscCall(PFDestroy(&pf)); 32 PetscCall(VecView(global,PETSC_VIEWER_DRAW_WORLD)); 33 PetscCall(VecDestroy(&global)); 34 PetscCall(DMDestroy(&da)); 35 PetscCall(PetscFinalize()); 36 return 0; 37 } 38 39 /*TEST 40 41 test: 42 nsize: 2 43 requires: x 44 45 TEST*/ 46