Actual source code: ex1.c
petsc-3.7.3 2016-08-01
1: static char help[] = "Make a 2D grid of patches and view them\n\n";
3: /*
4: Serial Test
5: Parallel Test where all zooms are serials
6: Parallel Test where zooms are parallel
8: Return DMPatch from Zoom
9: Override refine from DMPatch to split cells
10: */
11: #include <petscdmpatch.h>
13: typedef struct {
14: PetscInt debug; /* The debugging level */
15: PetscInt dim; /* The spatial dimension */
16: MatStencil patchSize; /* Size of patches */
17: MatStencil gridSize; /* Size of patch grid */
18: MatStencil commSize; /* Size of patch comm */
19: } AppCtx;
23: PetscErrorCode ProcessOptions(MPI_Comm comm, AppCtx *options)
24: {
25: PetscInt patchSize, commSize, gridSize;
29: options->debug = 0;
30: options->dim = 2;
31: patchSize = 0;
32: commSize = 0;
33: gridSize = 0;
35: PetscOptionsBegin(comm, "", "Patch Test Options", "DMPATCH");
36: PetscOptionsInt("-debug", "The debugging level", "ex1.c", options->debug, &options->debug, NULL);
37: PetscOptionsInt("-dim", "The spatial dimension", "ex1.c", options->dim, &options->dim, NULL);
38: PetscOptionsInt("-patch_size", "The patch size in each dimension", "ex1.c", patchSize, &patchSize, NULL);
39: PetscOptionsInt("-comm_size", "The comm size in each dimension", "ex1.c", commSize, &commSize, NULL);
40: PetscOptionsInt("-grid_size", "The grid size in each dimension", "ex1.c", gridSize, &gridSize, NULL);
41: PetscOptionsEnd();
43: options->patchSize.i = options->patchSize.j = options->patchSize.k = 1;
44: options->commSize.i = options->commSize.j = options->commSize.k = 1;
45: options->gridSize.i = options->gridSize.j = options->gridSize.k = 1;
46: if (options->dim > 0) {options->patchSize.i = patchSize; options->commSize.i = commSize; options->gridSize.i = gridSize;}
47: if (options->dim > 1) {options->patchSize.j = patchSize; options->commSize.j = commSize; options->gridSize.j = gridSize;}
48: if (options->dim > 2) {options->patchSize.k = patchSize; options->commSize.k = commSize; options->gridSize.k = gridSize;}
49: return(0);
50: };
54: int main(int argc, char **argv)
55: {
56: DM dm;
57: AppCtx user; /* user-defined work context */
60: PetscInitialize(&argc, &argv, NULL, help);
61: ProcessOptions(PETSC_COMM_WORLD, &user);
62: DMPatchCreateGrid(PETSC_COMM_WORLD, user.dim, user.patchSize, user.commSize, user.gridSize, &dm);
63: PetscObjectSetName((PetscObject) dm, "Patch Mesh");
64: DMSetFromOptions(dm);
65: DMSetUp(dm);
66: DMView(dm, PETSC_VIEWER_STDOUT_WORLD);
67: DMPatchSolve(dm);
68: DMDestroy(&dm);
69: PetscFinalize();
70: return 0;
71: }