Actual source code: patchcreate.c

  1: #include <petsc/private/dmpatchimpl.h>
  2: #include <petscdmda.h>

  4: PetscErrorCode DMSetFromOptions_Patch(DM dm, PetscOptionItems *PetscOptionsObject)
  5: {
  6:   /* DM_Patch      *mesh = (DM_Patch*) dm->data; */

  8:   PetscOptionsHeadBegin(PetscOptionsObject, "DMPatch Options");
  9:   /* Handle associated vectors */
 10:   /* Handle viewing */
 11:   PetscOptionsHeadEnd();
 12:   return 0;
 13: }

 15: /* External function declarations here */
 16: extern PetscErrorCode DMSetUp_Patch(DM dm);
 17: extern PetscErrorCode DMView_Patch(DM dm, PetscViewer viewer);
 18: extern PetscErrorCode DMCreateGlobalVector_Patch(DM dm, Vec *g);
 19: extern PetscErrorCode DMCreateLocalVector_Patch(DM dm, Vec *l);
 20: extern PetscErrorCode DMDestroy_Patch(DM dm);
 21: extern PetscErrorCode DMCreateSubDM_Patch(DM dm, PetscInt numFields, const PetscInt fields[], IS *is, DM *subdm);

 23: PetscErrorCode DMInitialize_Patch(DM dm)
 24: {
 25:   dm->ops->view                    = DMView_Patch;
 26:   dm->ops->setfromoptions          = DMSetFromOptions_Patch;
 27:   dm->ops->setup                   = DMSetUp_Patch;
 28:   dm->ops->createglobalvector      = DMCreateGlobalVector_Patch;
 29:   dm->ops->createlocalvector       = DMCreateLocalVector_Patch;
 30:   dm->ops->getlocaltoglobalmapping = NULL;
 31:   dm->ops->createfieldis           = NULL;
 32:   dm->ops->getcoloring             = NULL;
 33:   dm->ops->creatematrix            = NULL;
 34:   dm->ops->createinterpolation     = NULL;
 35:   dm->ops->createinjection         = NULL;
 36:   dm->ops->refine                  = NULL;
 37:   dm->ops->coarsen                 = NULL;
 38:   dm->ops->refinehierarchy         = NULL;
 39:   dm->ops->coarsenhierarchy        = NULL;
 40:   dm->ops->globaltolocalbegin      = NULL;
 41:   dm->ops->globaltolocalend        = NULL;
 42:   dm->ops->localtoglobalbegin      = NULL;
 43:   dm->ops->localtoglobalend        = NULL;
 44:   dm->ops->destroy                 = DMDestroy_Patch;
 45:   dm->ops->createsubdm             = DMCreateSubDM_Patch;
 46:   return 0;
 47: }

 49: PETSC_EXTERN PetscErrorCode DMCreate_Patch(DM dm)
 50: {
 51:   DM_Patch *mesh;

 54:   PetscNew(&mesh);
 55:   dm->data = mesh;

 57:   mesh->refct       = 1;
 58:   mesh->dmCoarse    = NULL;
 59:   mesh->patchSize.i = 0;
 60:   mesh->patchSize.j = 0;
 61:   mesh->patchSize.k = 0;
 62:   mesh->patchSize.c = 0;

 64:   DMInitialize_Patch(dm);
 65:   return 0;
 66: }

 68: /*@
 69:   DMPatchCreate - Creates a DMPatch object, which is a collections of DMs called patches.

 71:   Collective

 73:   Input Parameter:
 74: . comm - The communicator for the DMPatch object

 76:   Output Parameter:
 77: . mesh  - The DMPatch object

 79:   Notes:

 81:   This code is incomplete and not used by other parts of PETSc.

 83:   Level: beginner

 85: .seealso: `DMPatchZoom()`

 87: @*/
 88: PetscErrorCode DMPatchCreate(MPI_Comm comm, DM *mesh)
 89: {
 91:   DMCreate(comm, mesh);
 92:   DMSetType(*mesh, DMPATCH);
 93:   return 0;
 94: }

 96: PetscErrorCode DMPatchCreateGrid(MPI_Comm comm, PetscInt dim, MatStencil patchSize, MatStencil commSize, MatStencil gridSize, DM *dm)
 97: {
 98:   DM_Patch *mesh;
 99:   DM        da;
100:   PetscInt  dof = 1, width = 1;

102:   DMPatchCreate(comm, dm);
103:   mesh = (DM_Patch *)(*dm)->data;
104:   if (dim < 2) {
105:     gridSize.j  = 1;
106:     patchSize.j = 1;
107:   }
108:   if (dim < 3) {
109:     gridSize.k  = 1;
110:     patchSize.k = 1;
111:   }
112:   DMCreate(comm, &da);
113:   DMSetType(da, DMDA);
114:   DMSetDimension(da, dim);
115:   DMDASetSizes(da, gridSize.i, gridSize.j, gridSize.k);
116:   DMDASetBoundaryType(da, DM_BOUNDARY_NONE, DM_BOUNDARY_NONE, DM_BOUNDARY_NONE);
117:   DMDASetDof(da, dof);
118:   DMDASetStencilType(da, DMDA_STENCIL_BOX);
119:   DMDASetStencilWidth(da, width);

121:   mesh->dmCoarse = da;

123:   DMPatchSetPatchSize(*dm, patchSize);
124:   DMPatchSetCommSize(*dm, commSize);
125:   return 0;
126: }