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