xref: /petsc/src/dm/tests/ex9.c (revision 8fb5bd83c3955fefcf33a54e3bb66920a9fa884b)
1 
2 static char help[] = "Tests DMCreateMatrix for DMComposite.\n\n";
3 
4 #include <petscdmredundant.h>
5 #include <petscdm.h>
6 #include <petscdmda.h>
7 #include <petscdmcomposite.h>
8 #include <petscpf.h>
9 
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;
18 
19   PetscCall(PetscInitialize(&argc,&argv,(char*)0,help));
20   PetscCallMPI(MPI_Comm_size(PETSC_COMM_WORLD,&size));
21 
22   PetscCall(DMCompositeCreate(PETSC_COMM_WORLD,&packer));
23 
24   PetscCall(DMRedundantCreate(PETSC_COMM_WORLD,0,5,&dmred));
25   PetscCall(DMCompositeAddDM(packer,dmred));
26   PetscCall(DMGetLocalToGlobalMapping(dmred,&ltogs));
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));
30 
31   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));
32   PetscCall(DMSetFromOptions(da));
33   PetscCall(DMSetUp(da));
34   PetscCall(DMCompositeAddDM(packer,da));
35   PetscCall(DMGetLocalToGlobalMapping(da,&ltogs));
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));
39 
40   PetscCall(DMSetMatType(packer,MATNEST));
41   PetscCall(DMSetFromOptions(packer));
42   PetscCall(DMCreateMatrix(packer,&M));
43   PetscCall(MatView(M,NULL));
44   PetscCall(MatDestroy(&M));
45 
46   /* get the global numbering for each subvector element */
47   PetscCall(DMCompositeGetISLocalToGlobalMappings(packer,&ltog));
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(&ltog[i]));
53 
54   PetscCall(PetscFree(ltog));
55   PetscCall(DMDestroy(&packer));
56   PetscCall(PetscFinalize());
57   return 0;
58 }
59 
60 /*TEST
61 
62    test:
63      suffix: composite_nest_l2g
64      nsize: {{1 2}separate output}
65 
66 TEST*/
67