Actual source code: ex9.c
1: static char help[] = "Tests DMCreateMatrix for DMComposite.\n\n";
3: #include <petscdmredundant.h>
4: #include <petscdm.h>
5: #include <petscdmda.h>
6: #include <petscdmcomposite.h>
7: #include <petscpf.h>
9: int main(int argc, char **argv)
10: {
11: ISLocalToGlobalMapping *ltog, ltogs;
12: PetscMPIInt size;
13: DM packer;
14: DM da, dmred;
15: Mat M;
17: PetscFunctionBeginUser;
18: PetscCall(PetscInitialize(&argc, &argv, NULL, help));
19: PetscCallMPI(MPI_Comm_size(PETSC_COMM_WORLD, &size));
21: PetscCall(DMCompositeCreate(PETSC_COMM_WORLD, &packer));
23: PetscCall(DMRedundantCreate(PETSC_COMM_WORLD, 0, 5, &dmred));
24: PetscCall(DMCompositeAddDM(packer, dmred));
25: PetscCall(DMGetLocalToGlobalMapping(dmred, <ogs));
26: PetscCall(PetscViewerASCIIPrintf(PETSC_VIEWER_STDOUT_WORLD, "Local to global mapping of dmred\n"));
27: PetscCall(ISLocalToGlobalMappingView(ltogs, PETSC_VIEWER_STDOUT_WORLD));
28: PetscCall(DMDestroy(&dmred));
30: PetscCall(DMDACreate2d(PETSC_COMM_WORLD, DM_BOUNDARY_MIRROR, DM_BOUNDARY_MIRROR, DMDA_STENCIL_STAR, 4, 4, PETSC_DECIDE, PETSC_DECIDE, 2, 1, NULL, NULL, &da));
31: PetscCall(DMSetFromOptions(da));
32: PetscCall(DMSetUp(da));
33: PetscCall(DMCompositeAddDM(packer, da));
34: PetscCall(DMGetLocalToGlobalMapping(da, <ogs));
35: PetscCall(PetscViewerASCIIPrintf(PETSC_VIEWER_STDOUT_WORLD, "Local to global mapping of da\n"));
36: PetscCall(ISLocalToGlobalMappingView(ltogs, PETSC_VIEWER_STDOUT_WORLD));
37: PetscCall(DMDestroy(&da));
39: PetscCall(DMSetMatType(packer, MATNEST));
40: PetscCall(DMSetFromOptions(packer));
41: PetscCall(DMCreateMatrix(packer, &M));
42: PetscCall(MatView(M, NULL));
43: PetscCall(MatDestroy(&M));
45: /* get the global numbering for each subvector element */
46: PetscCall(DMCompositeGetISLocalToGlobalMappings(packer, <og));
47: PetscCall(PetscViewerASCIIPrintf(PETSC_VIEWER_STDOUT_WORLD, "Local to global mapping of dmred vector\n"));
48: PetscCall(ISLocalToGlobalMappingView(ltog[0], PETSC_VIEWER_STDOUT_WORLD));
49: PetscCall(PetscViewerASCIIPrintf(PETSC_VIEWER_STDOUT_WORLD, "Local to global mapping of da vector\n"));
50: PetscCall(ISLocalToGlobalMappingView(ltog[1], PETSC_VIEWER_STDOUT_WORLD));
51: for (PetscInt i = 0; i < 2; i++) PetscCall(ISLocalToGlobalMappingDestroy(<og[i]));
53: PetscCall(PetscFree(ltog));
54: PetscCall(DMDestroy(&packer));
55: PetscCall(PetscFinalize());
56: return 0;
57: }
59: /*TEST
61: test:
62: suffix: composite_nest_l2g
63: nsize: {{1 2}separate output}
65: TEST*/