Actual source code: ex1.c

      2: static char help[] = "Tests VecView() contour plotting for 2d DAs.\n\n";

     4:  #include petscda.h
     5:  #include petscsys.h

      9: int main(int argc,char **argv)
     10: {
     11:   PetscMPIInt    rank;
     12:   PetscInt       M = 10,N = 8,m = PETSC_DECIDE,n = PETSC_DECIDE;
     14:   PetscTruth     flg;
     15:   DA             da;
     16:   PetscViewer    viewer;
     17:   Vec            local,global;
     18:   PetscScalar    value;
     19:   DAPeriodicType ptype = DA_NONPERIODIC;
     20:   DAStencilType  stype = DA_STENCIL_BOX;
     21: #if defined(PETSC_HAVE_MATLAB)
     22:   PetscViewer    mviewer;
     23: #endif

     25:   PetscInitialize(&argc,&argv,(char*)0,help);
     26:   PetscViewerDrawOpen(PETSC_COMM_WORLD,0,"",300,0,300,300,&viewer);
     27: #if defined(PETSC_HAVE_MATLAB)
     28:   PetscViewerMatlabOpen(PETSC_COMM_WORLD,"tmp.mat",PETSC_FILE_CREATE,&mviewer);
     29: #endif

     31:   /* Read options */
     32:   PetscOptionsGetInt(PETSC_NULL,"-M",&M,PETSC_NULL);
     33:   PetscOptionsGetInt(PETSC_NULL,"-N",&N,PETSC_NULL);
     34:   PetscOptionsGetInt(PETSC_NULL,"-m",&m,PETSC_NULL);
     35:   PetscOptionsGetInt(PETSC_NULL,"-n",&n,PETSC_NULL);
     36:   PetscOptionsHasName(PETSC_NULL,"-star_stencil",&flg);
     37:   if (flg) stype = DA_STENCIL_STAR;

     39:   /* Create distributed array and get vectors */
     40:   DACreate2d(PETSC_COMM_WORLD,ptype,stype,M,N,m,n,1,1,PETSC_NULL,PETSC_NULL,&da);
     41:   DACreateGlobalVector(da,&global);
     42:   DACreateLocalVector(da,&local);

     44:   value = -3.0;
     45:   VecSet(global,value);
     46:   DAGlobalToLocalBegin(da,global,INSERT_VALUES,local);
     47:   DAGlobalToLocalEnd(da,global,INSERT_VALUES,local);

     49:   MPI_Comm_rank(PETSC_COMM_WORLD,&rank);
     50:   value = rank+1;
     51:   VecScale(local,value);
     52:   DALocalToGlobal(da,local,ADD_VALUES,global);

     54:   DAView(da,viewer);
     55:   VecView(global,viewer);
     56: #if defined(PETSC_HAVE_MATLAB)
     57:   DAView(da,mviewer);
     58:   VecView(global,mviewer);
     59: #endif

     61:   /* Free memory */
     62: #if defined(PETSC_HAVE_MATLAB)
     63:   PetscViewerDestroy(mviewer);
     64: #endif
     65:   PetscViewerDestroy(viewer);
     66:   VecDestroy(local);
     67:   VecDestroy(global);
     68:   DADestroy(da);
     69:   PetscFinalize();
     70:   return 0;
     71: }
     72: