Actual source code: patchcreate.c

petsc-3.8.4 2018-03-24
Report Typos and Errors
  1:  #include <petsc/private/dmpatchimpl.h>
  2:  #include <petscdmda.h>

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

 11:   PetscOptionsHead(PetscOptionsObject,"DMPatch Options");
 12:   /* Handle associated vectors */
 13:   /* Handle viewing */
 14:   PetscOptionsTail();
 15:   return(0);
 16: }

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

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

 54: PETSC_EXTERN PetscErrorCode DMCreate_Patch(DM dm)
 55: {
 56:   DM_Patch       *mesh;

 61:   PetscNewLog(dm,&mesh);
 62:   dm->data = mesh;

 64:   mesh->refct       = 1;
 65:   mesh->dmCoarse    = NULL;
 66:   mesh->patchSize.i = 0;
 67:   mesh->patchSize.j = 0;
 68:   mesh->patchSize.k = 0;
 69:   mesh->patchSize.c = 0;

 71:   DMInitialize_Patch(dm);
 72:   return(0);
 73: }

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

 78:   Collective on MPI_Comm

 80:   Input Parameter:
 81: . comm - The communicator for the DMPatch object

 83:   Output Parameter:
 84: . mesh  - The DMPatch object

 86:   Level: beginner

 88: .keywords: DMPatch, create
 89: @*/
 90: PetscErrorCode DMPatchCreate(MPI_Comm comm, DM *mesh)
 91: {

 96:   DMCreate(comm, mesh);
 97:   DMSetType(*mesh, DMPATCH);
 98:   return(0);
 99: }

101: PetscErrorCode DMPatchCreateGrid(MPI_Comm comm, PetscInt dim, MatStencil patchSize, MatStencil commSize, MatStencil gridSize, DM *dm)
102: {
103:   DM_Patch       *mesh;
104:   DM             da;
105:   PetscInt       dof = 1, width = 1;

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

128:   mesh->dmCoarse = da;

130:   DMPatchSetPatchSize(*dm, patchSize);
131:   DMPatchSetCommSize(*dm, commSize);
132:   return(0);
133: }