Actual source code: ex9.c


  2: static char help[] = "Tests DMCreateMatrix for DMComposite.\n\n";

  4: #include <petscdmredundant.h>
  5: #include <petscdm.h>
  6: #include <petscdmda.h>
  7: #include <petscdmcomposite.h>
  8: #include <petscpf.h>

 10: int main(int argc, char **argv)
 11: {
 12:   ISLocalToGlobalMapping *ltog, ltogs;
 13:   PetscMPIInt             size;
 14:   DM                      packer;
 15:   DM                      da, dmred;
 16:   Mat                     M;
 17:   PetscInt                i;

 20:   PetscInitialize(&argc, &argv, (char *)0, help);
 21:   MPI_Comm_size(PETSC_COMM_WORLD, &size);

 23:   DMCompositeCreate(PETSC_COMM_WORLD, &packer);

 25:   DMRedundantCreate(PETSC_COMM_WORLD, 0, 5, &dmred);
 26:   DMCompositeAddDM(packer, dmred);
 27:   DMGetLocalToGlobalMapping(dmred, &ltogs);
 28:   PetscViewerASCIIPrintf(PETSC_VIEWER_STDOUT_WORLD, "Local to global mapping of dmred\n");
 29:   ISLocalToGlobalMappingView(ltogs, PETSC_VIEWER_STDOUT_WORLD);
 30:   DMDestroy(&dmred);

 32:   DMDACreate2d(PETSC_COMM_WORLD, DM_BOUNDARY_MIRROR, DM_BOUNDARY_MIRROR, DMDA_STENCIL_STAR, 3, 3, PETSC_DECIDE, PETSC_DECIDE, 2, 1, NULL, NULL, &da);
 33:   DMSetFromOptions(da);
 34:   DMSetUp(da);
 35:   DMCompositeAddDM(packer, da);
 36:   DMGetLocalToGlobalMapping(da, &ltogs);
 37:   PetscViewerASCIIPrintf(PETSC_VIEWER_STDOUT_WORLD, "Local to global mapping of da\n");
 38:   ISLocalToGlobalMappingView(ltogs, PETSC_VIEWER_STDOUT_WORLD);
 39:   DMDestroy(&da);

 41:   DMSetMatType(packer, MATNEST);
 42:   DMSetFromOptions(packer);
 43:   DMCreateMatrix(packer, &M);
 44:   MatView(M, NULL);
 45:   MatDestroy(&M);

 47:   /* get the global numbering for each subvector element */
 48:   DMCompositeGetISLocalToGlobalMappings(packer, &ltog);
 49:   PetscViewerASCIIPrintf(PETSC_VIEWER_STDOUT_WORLD, "Local to global mapping of dmred vector\n");
 50:   ISLocalToGlobalMappingView(ltog[0], PETSC_VIEWER_STDOUT_WORLD);
 51:   PetscViewerASCIIPrintf(PETSC_VIEWER_STDOUT_WORLD, "Local to global mapping of da vector\n");
 52:   ISLocalToGlobalMappingView(ltog[1], PETSC_VIEWER_STDOUT_WORLD);
 53:   for (i = 0; i < 2; i++) ISLocalToGlobalMappingDestroy(&ltog[i]);

 55:   PetscFree(ltog);
 56:   DMDestroy(&packer);
 57:   PetscFinalize();
 58:   return 0;
 59: }

 61: /*TEST

 63:    test:
 64:      suffix: composite_nest_l2g
 65:      nsize: {{1 2}separate output}

 67: TEST*/