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->getlocaltoglobalmapping = NULL;
 20:   dm->ops->createfieldis           = NULL;
 21:   dm->ops->getcoloring             = NULL;
 22:   dm->ops->creatematrix            = NULL;
 23:   dm->ops->createinterpolation     = NULL;
 24:   dm->ops->createinjection         = NULL;
 25:   dm->ops->refine                  = NULL;
 26:   dm->ops->coarsen                 = NULL;
 27:   dm->ops->refinehierarchy         = NULL;
 28:   dm->ops->coarsenhierarchy        = NULL;
 29:   dm->ops->globaltolocalbegin      = NULL;
 30:   dm->ops->globaltolocalend        = NULL;
 31:   dm->ops->localtoglobalbegin      = NULL;
 32:   dm->ops->localtoglobalend        = NULL;
 33:   dm->ops->destroy                 = DMDestroy_Patch;
 34:   dm->ops->createsubdm             = DMCreateSubDM_Patch;
 35:   PetscFunctionReturn(PETSC_SUCCESS);
 36: }

 38: PETSC_EXTERN PetscErrorCode DMCreate_Patch(DM dm)
 39: {
 40:   DM_Patch *mesh;

 42:   PetscFunctionBegin;
 44:   PetscCall(PetscNew(&mesh));
 45:   dm->data = mesh;

 47:   mesh->refct       = 1;
 48:   mesh->dmCoarse    = NULL;
 49:   mesh->patchSize.i = 0;
 50:   mesh->patchSize.j = 0;
 51:   mesh->patchSize.k = 0;
 52:   mesh->patchSize.c = 0;

 54:   PetscCall(DMInitialize_Patch(dm));
 55:   PetscFunctionReturn(PETSC_SUCCESS);
 56: }

 58: /*@
 59:   DMPatchCreate - Creates a `DMPATCH` object, which is a collection of `DM`s called patches.

 61:   Collective

 63:   Input Parameter:
 64: . comm - The communicator for the `DMPATCH` object

 66:   Output Parameter:
 67: . mesh - The `DMPATCH` object

 69:   Level: beginner

 71:   Notes:
 72:   This code is incomplete and not used by other parts of PETSc.

 74: .seealso: `DMPATCH`, `DMPatchZoom()`, `DMPatchCreateGrid()`
 75: @*/
 76: PetscErrorCode DMPatchCreate(MPI_Comm comm, DM *mesh)
 77: {
 78:   PetscFunctionBegin;
 79:   PetscAssertPointer(mesh, 2);
 80:   PetscCall(DMCreate(comm, mesh));
 81:   PetscCall(DMSetType(*mesh, DMPATCH));
 82:   PetscFunctionReturn(PETSC_SUCCESS);
 83: }

 85: /*@
 86:   DMPatchCreateGrid - Create a `DMPATCH` whose coarse `DM` is a structured `DMDA` of the requested global size, with the given patch and process-grid sizes

 88:   Collective

 90:   Input Parameters:
 91: + comm      - the MPI communicator
 92: . dim       - the spatial dimension (1, 2, or 3); unused dimensions of `gridSize` and `patchSize` are set to 1
 93: . patchSize - `MatStencil` giving the size of each patch in cells
 94: . commSize  - `MatStencil` giving the process grid used per patch (see `DMPatchSetCommSize()`)
 95: - gridSize  - `MatStencil` giving the global cell count of the underlying `DMDA` in each dimension

 97:   Output Parameter:
 98: . dm - the newly created `DMPATCH`

100:   Level: developer

102:   Note:
103:   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.

105: .seealso: `DMPATCH`, `DMPatchCreate()`, `DMPatchSetPatchSize()`, `DMPatchSetCommSize()`, `DMDA`, `MatStencil`
106: @*/
107: PetscErrorCode DMPatchCreateGrid(MPI_Comm comm, PetscInt dim, MatStencil patchSize, MatStencil commSize, MatStencil gridSize, DM *dm)
108: {
109:   DM_Patch *mesh;
110:   DM        da;
111:   PetscInt  dof = 1, width = 1;

113:   PetscFunctionBegin;
114:   PetscCall(DMPatchCreate(comm, dm));
115:   mesh = (DM_Patch *)(*dm)->data;
116:   if (dim < 2) {
117:     gridSize.j  = 1;
118:     patchSize.j = 1;
119:   }
120:   if (dim < 3) {
121:     gridSize.k  = 1;
122:     patchSize.k = 1;
123:   }
124:   PetscCall(DMCreate(comm, &da));
125:   PetscCall(DMSetType(da, DMDA));
126:   PetscCall(DMSetDimension(da, dim));
127:   PetscCall(DMDASetSizes(da, gridSize.i, gridSize.j, gridSize.k));
128:   PetscCall(DMDASetBoundaryType(da, DM_BOUNDARY_NONE, DM_BOUNDARY_NONE, DM_BOUNDARY_NONE));
129:   PetscCall(DMDASetDof(da, dof));
130:   PetscCall(DMDASetStencilType(da, DMDA_STENCIL_BOX));
131:   PetscCall(DMDASetStencilWidth(da, width));

133:   mesh->dmCoarse = da;

135:   PetscCall(DMPatchSetPatchSize(*dm, patchSize));
136:   PetscCall(DMPatchSetCommSize(*dm, commSize));
137:   PetscFunctionReturn(PETSC_SUCCESS);
138: }

140: /*MC
141:   DMPATCH = "patch" - A `DM` object that is a collection of other `DM`s patched together

143:   Level: intermediate

145:   Note:
146:   Not currently enabled, see `DMPatchCreateGrid()` and `DMPatchCreate()`.

148: .seealso: `DMType`, `DMPatchCreateGrid()`, `DMPatchCreate()`, `DMCOMPOSITE`, `DMSTAG`, `DMPLEX`, `DMDA`, `DMDACreate()`, `DMCreate()`, `DMSetType()`
149: M*/