Actual source code: ex5.c

petsc-3.7.5 2017-01-01
Report Typos and Errors
  2: static char help[] = "Demonstrates using ISLocalToGlobalMappings with block size.\n\n";

  4: /*T
  5:     Concepts: local to global mappings
  6:     Concepts: global to local mappings

  8:     Description:  Creates an index set based on blocks of integers. Views that index set
  9:     and then destroys it.
 10: T*/

 12: #include <petscis.h>
 13: #include <petscviewer.h>

 17: int main(int argc,char **argv)
 18: {
 19:   PetscErrorCode         ierr;
 20:   PetscInt               i,n = 4,indices[] = {0,3,9,12},m = 2,input[] = {0,2};
 21:   PetscInt               output[2],inglobals[13],outlocals[13];
 22:   ISLocalToGlobalMapping mapping;

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

 26:   /*
 27:       Create a local to global mapping. Each processor independently
 28:      creates a mapping
 29:   */
 30:   PetscIntView(n,indices,PETSC_VIEWER_STDOUT_WORLD);
 31:   ISLocalToGlobalMappingCreate(PETSC_COMM_WORLD,2,n,indices,PETSC_COPY_VALUES,&mapping);

 33:   /*
 34:      Map a set of local indices to their global values
 35:   */
 36:   PetscIntView(m,input,PETSC_VIEWER_STDOUT_WORLD);
 37:   ISLocalToGlobalMappingApply(mapping,m,input,output);
 38:   PetscIntView(m,output,PETSC_VIEWER_STDOUT_WORLD);

 40:   /*
 41:      Map some global indices to local, retaining the ones without a local index by -1
 42:   */
 43:   for (i=0; i<13; i++) inglobals[i] = i;
 44:   PetscIntView(13,inglobals,PETSC_VIEWER_STDOUT_WORLD);
 45:   ISGlobalToLocalMappingApply(mapping,IS_GTOLM_MASK,13,inglobals,NULL,outlocals);
 46:   PetscIntView(13,outlocals,PETSC_VIEWER_STDOUT_WORLD);

 48:   /*
 49:      Map some block global indices to local, dropping the ones without a local index.
 50:   */
 51:   PetscIntView(13,inglobals,PETSC_VIEWER_STDOUT_WORLD);
 52:   ISGlobalToLocalMappingApplyBlock(mapping,IS_GTOLM_DROP,13,inglobals,&m,outlocals);
 53:   PetscIntView(m,outlocals,PETSC_VIEWER_STDOUT_WORLD);

 55:   /*
 56:      Free the space used by the local to global mapping
 57:   */
 58:   ISLocalToGlobalMappingDestroy(&mapping);


 61:   PetscFinalize();
 62:   return 0;
 63: }