Actual source code: patchcreate.c
1: #include <petsc/private/dmpatchimpl.h>
2: #include <petscdmda.h>
4: static PetscErrorCode DMSetFromOptions_Patch(DM dm, PetscOptionItems PetscOptionsObject)
5: {
6: /* DM_Patch *mesh = (DM_Patch*) dm->data; */
8: PetscFunctionBegin;
9: PetscOptionsHeadBegin(PetscOptionsObject, "DMPatch Options");
10: /* Handle associated vectors */
11: /* Handle viewing */
12: PetscOptionsHeadEnd();
13: PetscFunctionReturn(PETSC_SUCCESS);
14: }
16: /* External function declarations here */
17: extern PetscErrorCode DMSetUp_Patch(DM dm);
18: extern PetscErrorCode DMView_Patch(DM dm, PetscViewer viewer);
19: extern PetscErrorCode DMCreateGlobalVector_Patch(DM dm, Vec *g);
20: extern PetscErrorCode DMCreateLocalVector_Patch(DM dm, Vec *l);
21: extern PetscErrorCode DMDestroy_Patch(DM dm);
22: extern PetscErrorCode DMCreateSubDM_Patch(DM dm, PetscInt numFields, const PetscInt fields[], IS *is, DM *subdm);
24: static PetscErrorCode DMInitialize_Patch(DM dm)
25: {
26: PetscFunctionBegin;
27: dm->ops->view = DMView_Patch;
28: dm->ops->setfromoptions = DMSetFromOptions_Patch;
29: dm->ops->setup = DMSetUp_Patch;
30: dm->ops->createglobalvector = DMCreateGlobalVector_Patch;
31: dm->ops->createlocalvector = DMCreateLocalVector_Patch;
32: dm->ops->getlocaltoglobalmapping = NULL;
33: dm->ops->createfieldis = NULL;
34: dm->ops->getcoloring = NULL;
35: dm->ops->creatematrix = NULL;
36: dm->ops->createinterpolation = NULL;
37: dm->ops->createinjection = NULL;
38: dm->ops->refine = NULL;
39: dm->ops->coarsen = NULL;
40: dm->ops->refinehierarchy = NULL;
41: dm->ops->coarsenhierarchy = NULL;
42: dm->ops->globaltolocalbegin = NULL;
43: dm->ops->globaltolocalend = NULL;
44: dm->ops->localtoglobalbegin = NULL;
45: dm->ops->localtoglobalend = NULL;
46: dm->ops->destroy = DMDestroy_Patch;
47: dm->ops->createsubdm = DMCreateSubDM_Patch;
48: PetscFunctionReturn(PETSC_SUCCESS);
49: }
51: PETSC_EXTERN PetscErrorCode DMCreate_Patch(DM dm)
52: {
53: DM_Patch *mesh;
55: PetscFunctionBegin;
57: PetscCall(PetscNew(&mesh));
58: dm->data = mesh;
60: mesh->refct = 1;
61: mesh->dmCoarse = NULL;
62: mesh->patchSize.i = 0;
63: mesh->patchSize.j = 0;
64: mesh->patchSize.k = 0;
65: mesh->patchSize.c = 0;
67: PetscCall(DMInitialize_Patch(dm));
68: PetscFunctionReturn(PETSC_SUCCESS);
69: }
71: /*@
72: DMPatchCreate - Creates a DMPatch object, which is a collections of DMs called patches.
74: Collective
76: Input Parameter:
77: . comm - The communicator for the DMPatch object
79: Output Parameter:
80: . mesh - The DMPatch object
82: Notes:
84: This code is incomplete and not used by other parts of PETSc.
86: Level: beginner
88: .seealso: `DMPatchZoom()`
89: @*/
90: PetscErrorCode DMPatchCreate(MPI_Comm comm, DM *mesh)
91: {
92: PetscFunctionBegin;
93: PetscAssertPointer(mesh, 2);
94: PetscCall(DMCreate(comm, mesh));
95: PetscCall(DMSetType(*mesh, DMPATCH));
96: PetscFunctionReturn(PETSC_SUCCESS);
97: }
99: /*@
100: DMPatchCreateGrid - Create a `DMPATCH` whose coarse `DM` is a structured `DMDA` of the requested global size, with the given patch and process-grid sizes
102: Collective
104: Input Parameters:
105: + comm - the MPI communicator
106: . dim - the spatial dimension (1, 2, or 3); unused dimensions of `gridSize` and `patchSize` are forced to 1
107: . patchSize - `MatStencil` giving the size of each patch in cells
108: . commSize - `MatStencil` giving the process grid used per patch (see `DMPatchSetCommSize()`)
109: - gridSize - `MatStencil` giving the global cell count of the underlying `DMDA` in each dimension
111: Output Parameter:
112: . dm - the newly created `DMPATCH`
114: Level: developer
116: Note:
117: 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.
119: .seealso: `DMPATCH`, `DMPatchCreate()`, `DMPatchSetPatchSize()`, `DMPatchSetCommSize()`, `DMDA`, `MatStencil`
120: @*/
121: PetscErrorCode DMPatchCreateGrid(MPI_Comm comm, PetscInt dim, MatStencil patchSize, MatStencil commSize, MatStencil gridSize, DM *dm)
122: {
123: DM_Patch *mesh;
124: DM da;
125: PetscInt dof = 1, width = 1;
127: PetscFunctionBegin;
128: PetscCall(DMPatchCreate(comm, dm));
129: mesh = (DM_Patch *)(*dm)->data;
130: if (dim < 2) {
131: gridSize.j = 1;
132: patchSize.j = 1;
133: }
134: if (dim < 3) {
135: gridSize.k = 1;
136: patchSize.k = 1;
137: }
138: PetscCall(DMCreate(comm, &da));
139: PetscCall(DMSetType(da, DMDA));
140: PetscCall(DMSetDimension(da, dim));
141: PetscCall(DMDASetSizes(da, gridSize.i, gridSize.j, gridSize.k));
142: PetscCall(DMDASetBoundaryType(da, DM_BOUNDARY_NONE, DM_BOUNDARY_NONE, DM_BOUNDARY_NONE));
143: PetscCall(DMDASetDof(da, dof));
144: PetscCall(DMDASetStencilType(da, DMDA_STENCIL_BOX));
145: PetscCall(DMDASetStencilWidth(da, width));
147: mesh->dmCoarse = da;
149: PetscCall(DMPatchSetPatchSize(*dm, patchSize));
150: PetscCall(DMPatchSetCommSize(*dm, commSize));
151: PetscFunctionReturn(PETSC_SUCCESS);
152: }