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: PetscErrorCode DMPatchCreateGrid(MPI_Comm comm, PetscInt dim, MatStencil patchSize, MatStencil commSize, MatStencil gridSize, DM *dm)
    100: {
    101:   DM_Patch *mesh;
    102:   DM        da;
    103:   PetscInt  dof = 1, width = 1;

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

    125:   mesh->dmCoarse = da;

    127:   PetscCall(DMPatchSetPatchSize(*dm, patchSize));
    128:   PetscCall(DMPatchSetCommSize(*dm, commSize));
    129:   PetscFunctionReturn(PETSC_SUCCESS);
    130: }