Actual source code: patchcreate.c
1: #include <petsc/private/dmpatchimpl.h>
2: #include <petscdmda.h>
4: /* External function declarations here */
5: extern PetscErrorCode DMSetUp_Patch(DM dm);
6: extern PetscErrorCode DMView_Patch(DM dm, PetscViewer viewer);
7: extern PetscErrorCode DMCreateGlobalVector_Patch(DM dm, Vec *g);
8: extern PetscErrorCode DMCreateLocalVector_Patch(DM dm, Vec *l);
9: extern PetscErrorCode DMDestroy_Patch(DM dm);
10: extern PetscErrorCode DMCreateSubDM_Patch(DM dm, PetscInt numFields, const PetscInt fields[], IS *is, DM *subdm);
12: static PetscErrorCode DMInitialize_Patch(DM dm)
13: {
14: PetscFunctionBegin;
15: dm->ops->view = DMView_Patch;
16: dm->ops->setup = DMSetUp_Patch;
17: dm->ops->createglobalvector = DMCreateGlobalVector_Patch;
18: dm->ops->createlocalvector = DMCreateLocalVector_Patch;
19: dm->ops->destroy = DMDestroy_Patch;
20: dm->ops->createsubdm = DMCreateSubDM_Patch;
21: PetscFunctionReturn(PETSC_SUCCESS);
22: }
24: PETSC_EXTERN PetscErrorCode DMCreate_Patch(DM dm)
25: {
26: DM_Patch *mesh;
28: PetscFunctionBegin;
30: PetscCall(PetscNew(&mesh));
31: dm->data = mesh;
33: mesh->refct = 1;
34: mesh->dmCoarse = NULL;
35: mesh->patchSize.i = 0;
36: mesh->patchSize.j = 0;
37: mesh->patchSize.k = 0;
38: mesh->patchSize.c = 0;
40: PetscCall(DMInitialize_Patch(dm));
41: PetscFunctionReturn(PETSC_SUCCESS);
42: }
44: /*@
45: DMPatchCreate - Creates a `DMPATCH` object, which is a collection of `DM`s called patches.
47: Collective
49: Input Parameter:
50: . comm - The communicator for the `DMPATCH` object
52: Output Parameter:
53: . mesh - The `DMPATCH` object
55: Level: beginner
57: Notes:
58: This code is incomplete and not used by other parts of PETSc.
60: .seealso: `DMPATCH`, `DMPatchZoom()`, `DMPatchCreateGrid()`
61: @*/
62: PetscErrorCode DMPatchCreate(MPI_Comm comm, DM *mesh)
63: {
64: PetscFunctionBegin;
65: PetscAssertPointer(mesh, 2);
66: PetscCall(DMCreate(comm, mesh));
67: PetscCall(DMSetType(*mesh, DMPATCH));
68: PetscFunctionReturn(PETSC_SUCCESS);
69: }
71: /*@
72: DMPatchCreateGrid - Create a `DMPATCH` whose coarse `DM` is a structured `DMDA` of the requested global size, with the given patch and process-grid sizes
74: Collective
76: Input Parameters:
77: + comm - the MPI communicator
78: . dim - the spatial dimension (1, 2, or 3); unused dimensions of `gridSize` and `patchSize` are set to 1
79: . patchSize - `MatStencil` giving the size of each patch in cells
80: . commSize - `MatStencil` giving the process grid used per patch (see `DMPatchSetCommSize()`)
81: - gridSize - `MatStencil` giving the global cell count of the underlying `DMDA` in each dimension
83: Output Parameter:
84: . dm - the newly created `DMPATCH`
86: Level: developer
88: Note:
89: The coarse `DM` is created as a `DMDA` with a single degree of freedom per node, stencil width 1, and `DM_BOUNDARY_NONE` on every side.
91: .seealso: `DMPATCH`, `DMPatchCreate()`, `DMPatchSetPatchSize()`, `DMPatchSetCommSize()`, `DMDA`, `MatStencil`
92: @*/
93: PetscErrorCode DMPatchCreateGrid(MPI_Comm comm, PetscInt dim, MatStencil patchSize, MatStencil commSize, MatStencil gridSize, DM *dm)
94: {
95: DM_Patch *mesh;
96: DM da;
97: PetscInt dof = 1, width = 1;
99: PetscFunctionBegin;
100: PetscCall(DMPatchCreate(comm, dm));
101: mesh = (DM_Patch *)(*dm)->data;
102: if (dim < 2) {
103: gridSize.j = 1;
104: patchSize.j = 1;
105: }
106: if (dim < 3) {
107: gridSize.k = 1;
108: patchSize.k = 1;
109: }
110: PetscCall(DMCreate(comm, &da));
111: PetscCall(DMSetType(da, DMDA));
112: PetscCall(DMSetDimension(da, dim));
113: PetscCall(DMDASetSizes(da, gridSize.i, gridSize.j, gridSize.k));
114: PetscCall(DMDASetBoundaryType(da, DM_BOUNDARY_NONE, DM_BOUNDARY_NONE, DM_BOUNDARY_NONE));
115: PetscCall(DMDASetDof(da, dof));
116: PetscCall(DMDASetStencilType(da, DMDA_STENCIL_BOX));
117: PetscCall(DMDASetStencilWidth(da, width));
119: mesh->dmCoarse = da;
121: PetscCall(DMPatchSetPatchSize(*dm, patchSize));
122: PetscCall(DMPatchSetCommSize(*dm, commSize));
123: PetscFunctionReturn(PETSC_SUCCESS);
124: }
126: /*MC
127: DMPATCH = "patch" - A `DM` object that is a collection of other `DM`s patched together
129: Level: intermediate
131: Note:
132: Not currently enabled, see `DMPatchCreateGrid()` and `DMPatchCreate()`.
134: .seealso: `DMType`, `DMPatchCreateGrid()`, `DMPatchCreate()`, `DMCOMPOSITE`, `DMSTAG`, `DMPLEX`, `DMDA`, `DMDACreate()`, `DMCreate()`, `DMSetType()`
135: M*/