Actual source code: ex32.c
petsc-3.4.2 2013-07-02

      1: static char help[] = "Tests DMDA ghost coordinates\n\n";

      3: #include <petscdmda.h>

      7: static PetscErrorCode CompareGhostedCoords(Vec gc1,Vec gc2)
      8: {
     10:   PetscReal      nrm,gnrm;
     11:   Vec            tmp;

     14:   VecDuplicate(gc1,&tmp);
     15:   VecWAXPY(tmp,-1.0,gc1,gc2);
     16:   VecNorm(tmp,NORM_INFINITY,&nrm);
     17:   MPI_Allreduce(&nrm,&gnrm,1,MPIU_REAL,MPIU_MAX,PETSC_COMM_WORLD);
     18:   PetscPrintf(PETSC_COMM_WORLD,"norm of difference of ghosted coordinates %8.2e\n",gnrm);
     19:   VecDestroy(&tmp);
     20:   return(0);
     21: }

     25: static PetscErrorCode TestQ2Q1DA(void)
     26: {
     27:   DM             Q2_da,Q1_da,cda;
     28:   PetscInt       mx,my,mz;
     29:   Vec            coords,gcoords,gcoords2;

     32:   mx   = 7;
     33:   my   = 11;
     34:   mz   = 13;
     35:   DMDACreate3d(PETSC_COMM_WORLD,DMDA_BOUNDARY_NONE,DMDA_BOUNDARY_NONE,DMDA_BOUNDARY_NONE,DMDA_STENCIL_BOX,mx,my,mz,PETSC_DECIDE,PETSC_DECIDE,PETSC_DECIDE,3,2,0,0,0,&Q2_da);
     36:   DMDASetUniformCoordinates(Q2_da,-1.0,1.0,-2.0,2.0,-3.0,3.0);
     37:   DMGetCoordinates(Q2_da,&coords);
     38:   DMDACreate3d(PETSC_COMM_WORLD,DMDA_BOUNDARY_NONE,DMDA_BOUNDARY_NONE,DMDA_BOUNDARY_NONE,DMDA_STENCIL_BOX,mx,my,mz,PETSC_DECIDE,PETSC_DECIDE,PETSC_DECIDE,3,1,0,0,0,&Q1_da);
     39:   DMSetCoordinates(Q1_da,coords);

     41:   /* Get ghost coordinates one way */
     42:   DMGetCoordinatesLocal(Q1_da,&gcoords);

     44:   /* And another */
     45:   DMGetCoordinates(Q1_da,&coords);
     46:   DMGetCoordinateDM(Q1_da,&cda);
     47:   DMGetLocalVector(cda,&gcoords2);
     48:   DMGlobalToLocalBegin(cda,coords,INSERT_VALUES,gcoords2);
     49:   DMGlobalToLocalEnd(cda,coords,INSERT_VALUES,gcoords2);

     51:   CompareGhostedCoords(gcoords,gcoords2);
     52:   DMRestoreLocalVector(cda,&gcoords2);

     54:   VecScale(coords,10.0);
     55:   VecScale(gcoords,10.0);
     56:   DMGetCoordinatesLocal(Q1_da,&gcoords2);
     57:   CompareGhostedCoords(gcoords,gcoords2);

     59:   DMDestroy(&Q2_da);
     60:   DMDestroy(&Q1_da);
     61:   return(0);
     62: }

     66: int main(int argc,char **argv)
     67: {

     70:   PetscInitialize(&argc,&argv,0,help);
     71:   TestQ2Q1DA();
     72:   PetscFinalize();
     73:   return 0;
     74: }