Actual source code: ex1.c
petsc-3.12.5 2020-03-29
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;
21: PetscErrorCode ProcessOptions(MPI_Comm comm, AppCtx *options)
22: {
23: PetscInt patchSize, commSize, gridSize;
27: options->debug = 0;
28: options->dim = 2;
29: patchSize = 0;
30: commSize = 0;
31: gridSize = 0;
33: PetscOptionsBegin(comm, "", "Patch Test Options", "DMPATCH");
34: PetscOptionsBoundedInt("-debug", "The debugging level", "ex1.c", options->debug, &options->debug, NULL,0);
35: PetscOptionsRangeInt("-dim", "The spatial dimension", "ex1.c", options->dim, &options->dim, NULL,1,3);
36: PetscOptionsBoundedInt("-patch_size", "The patch size in each dimension", "ex1.c", patchSize, &patchSize, NULL,0);
37: PetscOptionsBoundedInt("-comm_size", "The comm size in each dimension", "ex1.c", commSize, &commSize, NULL,0);
38: PetscOptionsBoundedInt("-grid_size", "The grid size in each dimension", "ex1.c", gridSize, &gridSize, NULL,1);
39: PetscOptionsEnd();
41: options->patchSize.i = options->patchSize.j = options->patchSize.k = 1;
42: options->commSize.i = options->commSize.j = options->commSize.k = 1;
43: options->gridSize.i = options->gridSize.j = options->gridSize.k = 1;
44: if (options->dim > 0) {options->patchSize.i = patchSize; options->commSize.i = commSize; options->gridSize.i = gridSize;}
45: if (options->dim > 1) {options->patchSize.j = patchSize; options->commSize.j = commSize; options->gridSize.j = gridSize;}
46: if (options->dim > 2) {options->patchSize.k = patchSize; options->commSize.k = commSize; options->gridSize.k = gridSize;}
47: return(0);
48: };
50: int main(int argc, char **argv)
51: {
52: DM dm;
53: AppCtx user; /* user-defined work context */
56: PetscInitialize(&argc, &argv, NULL, help);if (ierr) return ierr;
57: ProcessOptions(PETSC_COMM_WORLD, &user);
58: DMPatchCreateGrid(PETSC_COMM_WORLD, user.dim, user.patchSize, user.commSize, user.gridSize, &dm);
59: PetscObjectSetName((PetscObject) dm, "Patch Mesh");
60: DMSetFromOptions(dm);
61: DMSetUp(dm);
62: DMView(dm, PETSC_VIEWER_STDOUT_WORLD);
63: DMPatchSolve(dm);
64: DMDestroy(&dm);
65: PetscFinalize();
66: return ierr;
67: }