Actual source code: ex20.c
1: static char help[] = "Test DMStag transfer operators, on a faces-only grid.\n\n";
3: #include <petscdm.h>
4: #include <petscdmstag.h>
6: int main(int argc, char **argv)
7: {
8: DM dm;
9: PetscInt dim;
10: PetscBool flg, dump;
13: PetscInitialize(&argc, &argv, (char *)0, help);
14: PetscOptionsGetInt(NULL, NULL, "-dim", &dim, &flg);
16: if (dim == 1) DMStagCreate1d(PETSC_COMM_WORLD, DM_BOUNDARY_NONE, 4, 1, 0, DMSTAG_STENCIL_BOX, 1, NULL, &dm);
17: else if (dim == 2) DMStagCreate2d(PETSC_COMM_WORLD, DM_BOUNDARY_NONE, DM_BOUNDARY_NONE, 4, 4, PETSC_DECIDE, PETSC_DECIDE, 0, 1, 0, DMSTAG_STENCIL_BOX, 1, NULL, NULL, &dm);
18: else if (dim == 3) DMStagCreate3d(PETSC_COMM_WORLD, DM_BOUNDARY_NONE, DM_BOUNDARY_NONE, DM_BOUNDARY_NONE, 4, 4, 4, PETSC_DECIDE, PETSC_DECIDE, PETSC_DECIDE, 0, 0, 1, 0, DMSTAG_STENCIL_BOX, 1, NULL, NULL, NULL, &dm);
19: else SETERRQ(PETSC_COMM_WORLD, PETSC_ERR_SUP, "dim must be 1, 2, or 3");
20: DMSetFromOptions(dm);
21: DMSetUp(dm);
23: /* Flags to dump binary or ASCII output */
24: dump = PETSC_FALSE;
25: PetscOptionsGetBool(NULL, NULL, "-dump", &dump, NULL);
27: /* Directly create a coarsened DM and transfer operators */
28: {
29: DM dmCoarse;
30: DMCoarsen(dm, MPI_COMM_NULL, &dmCoarse);
31: {
32: Mat Ai;
33: DMCreateInterpolation(dmCoarse, dm, &Ai, NULL);
34: if (dump) {
35: PetscViewer viewer;
36: PetscViewerBinaryOpen(PetscObjectComm((PetscObject)dm), "matI.pbin", FILE_MODE_WRITE, &viewer);
37: MatView(Ai, viewer);
38: PetscViewerDestroy(&viewer);
39: }
40: MatDestroy(&Ai);
41: }
42: {
43: Mat Ar;
44: DMCreateRestriction(dmCoarse, dm, &Ar);
45: if (dump) {
46: PetscViewer viewer;
47: PetscViewerBinaryOpen(PetscObjectComm((PetscObject)dm), "matR.pbin", FILE_MODE_WRITE, &viewer);
48: MatView(Ar, viewer);
49: PetscViewerDestroy(&viewer);
50: }
51: MatDestroy(&Ar);
52: }
53: DMDestroy(&dmCoarse);
54: }
56: DMDestroy(&dm);
57: PetscFinalize();
58: return 0;
59: }
61: /*TEST
63: test:
64: suffix: 1
65: nsize: 1
66: args: -dim 1
68: test:
69: suffix: 2
70: nsize: 1
71: args: -dim 2
73: TEST*/