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;
19: PetscFunctionBeginUser;
20: PetscCall(PetscInitialize(&argc, &argv, (char *)0, help));
21: PetscCallMPI(MPI_Comm_size(PETSC_COMM_WORLD, &size));
23: PetscCall(DMCompositeCreate(PETSC_COMM_WORLD, &packer));
25: PetscCall(DMRedundantCreate(PETSC_COMM_WORLD, 0, 5, &dmred));
26: PetscCall(DMCompositeAddDM(packer, dmred));
27: PetscCall(DMGetLocalToGlobalMapping(dmred, <ogs));
28: PetscCall(PetscViewerASCIIPrintf(PETSC_VIEWER_STDOUT_WORLD, "Local to global mapping of dmred\n"));
29: PetscCall(ISLocalToGlobalMappingView(ltogs, PETSC_VIEWER_STDOUT_WORLD));
30: PetscCall(DMDestroy(&dmred));
32: PetscCall(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: PetscCall(DMSetFromOptions(da));
34: PetscCall(DMSetUp(da));
35: PetscCall(DMCompositeAddDM(packer, da));
36: PetscCall(DMGetLocalToGlobalMapping(da, <ogs));
37: PetscCall(PetscViewerASCIIPrintf(PETSC_VIEWER_STDOUT_WORLD, "Local to global mapping of da\n"));
38: PetscCall(ISLocalToGlobalMappingView(ltogs, PETSC_VIEWER_STDOUT_WORLD));
39: PetscCall(DMDestroy(&da));
41: PetscCall(DMSetMatType(packer, MATNEST));
42: PetscCall(DMSetFromOptions(packer));
43: PetscCall(DMCreateMatrix(packer, &M));
44: PetscCall(MatView(M, NULL));
45: PetscCall(MatDestroy(&M));
47: /* get the global numbering for each subvector element */
48: PetscCall(DMCompositeGetISLocalToGlobalMappings(packer, <og));
49: PetscCall(PetscViewerASCIIPrintf(PETSC_VIEWER_STDOUT_WORLD, "Local to global mapping of dmred vector\n"));
50: PetscCall(ISLocalToGlobalMappingView(ltog[0], PETSC_VIEWER_STDOUT_WORLD));
51: PetscCall(PetscViewerASCIIPrintf(PETSC_VIEWER_STDOUT_WORLD, "Local to global mapping of da vector\n"));
52: PetscCall(ISLocalToGlobalMappingView(ltog[1], PETSC_VIEWER_STDOUT_WORLD));
53: for (i = 0; i < 2; i++) PetscCall(ISLocalToGlobalMappingDestroy(<og[i]));
55: PetscCall(PetscFree(ltog));
56: PetscCall(DMDestroy(&packer));
57: PetscCall(PetscFinalize());
58: return 0;
59: }
61: /*TEST
63: test:
64: suffix: composite_nest_l2g
65: nsize: {{1 2}separate output}
67: TEST*/