Date: 2013-07-02T14:46:05+00:00

Actual source code: patchcreate.c
petsc-3.4.2 2013-07-02

      1: #include <petsc-private/dmpatchimpl.h>   /*I      "petscdmpatch.h"   I*/
      2: #include <petscdmda.h>

      6: PetscErrorCode DMSetFromOptions_Patch(DM dm)
      7: {
      8:   /* DM_Patch      *mesh = (DM_Patch*) dm->data; */

     13:   PetscOptionsHead("DMPatch Options");
     14:   /* Handle associated vectors */
     15:   /* Handle viewing */
     16:   PetscOptionsTail();
     17:   return(0);
     18: }

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

     30: PetscErrorCode DMInitialize_Patch(DM dm)
     31: {

     35:   PetscStrallocpy(VECSTANDARD,(char**) &dm->vectype);

     37:   dm->ops->view                            = DMView_Patch;
     38:   dm->ops->setfromoptions                  = DMSetFromOptions_Patch;
     39:   dm->ops->setup                           = DMSetUp_Patch;
     40:   dm->ops->createglobalvector              = DMCreateGlobalVector_Patch;
     41:   dm->ops->createlocalvector               = DMCreateLocalVector_Patch;
     42:   dm->ops->getlocaltoglobalmapping         = NULL;
     43:   dm->ops->getlocaltoglobalmappingblock    = NULL;
     44:   dm->ops->createfieldis                   = NULL;
     45:   dm->ops->getcoloring                     = 0;
     46:   dm->ops->creatematrix                    = 0;
     47:   dm->ops->createinterpolation             = 0;
     48:   dm->ops->getaggregates                   = 0;
     49:   dm->ops->getinjection                    = 0;
     50:   dm->ops->refine                          = 0;
     51:   dm->ops->coarsen                         = 0;
     52:   dm->ops->refinehierarchy                 = 0;
     53:   dm->ops->coarsenhierarchy                = 0;
     54:   dm->ops->globaltolocalbegin              = NULL;
     55:   dm->ops->globaltolocalend                = NULL;
     56:   dm->ops->localtoglobalbegin              = NULL;
     57:   dm->ops->localtoglobalend                = NULL;
     58:   dm->ops->destroy                         = DMDestroy_Patch;
     59:   dm->ops->createsubdm                     = DMCreateSubDM_Patch;
     60:   return(0);
     61: }

     65: PETSC_EXTERN PetscErrorCode DMCreate_Patch(DM dm)
     66: {
     67:   DM_Patch       *mesh;

     72:   PetscNewLog(dm, DM_Patch, &mesh);
     73:   dm->data = mesh;

     75:   mesh->refct       = 1;
     76:   mesh->dmCoarse    = NULL;
     77:   mesh->patchSize.i = 0;
     78:   mesh->patchSize.j = 0;
     79:   mesh->patchSize.k = 0;
     80:   mesh->patchSize.c = 0;

     82:   DMInitialize_Patch(dm);
     83:   return(0);
     84: }

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

     91:   Collective on MPI_Comm

     93:   Input Parameter:
     94: . comm - The communicator for the DMPatch object

     96:   Output Parameter:
     97: . mesh  - The DMPatch object

     99:   Level: beginner

    101: .keywords: DMPatch, create
    102: @*/
    103: PetscErrorCode DMPatchCreate(MPI_Comm comm, DM *mesh)
    104: {

    109:   DMCreate(comm, mesh);
    110:   DMSetType(*mesh, DMPATCH);
    111:   return(0);
    112: }

    116: PetscErrorCode DMPatchCreateGrid(MPI_Comm comm, PetscInt dim, MatStencil patchSize, MatStencil commSize, MatStencil gridSize, DM *dm)
    117: {
    118:   DM_Patch       *mesh;
    119:   DM             da;
    120:   PetscInt       dof = 1, width = 1;

    124:   DMPatchCreate(comm, dm);
    125:   mesh = (DM_Patch*) (*dm)->data;
    126:   if (dim < 2) {
    127:     gridSize.j  = 1;
    128:     patchSize.j = 1;
    129:   }
    130:   if (dim < 3) {
    131:     gridSize.k  = 1;
    132:     patchSize.k = 1;
    133:   }
    134:   DMCreate(comm, &da);
    135:   DMSetType(da, DMDA);
    136:   DMDASetDim(da, dim);
    137:   DMDASetSizes(da, gridSize.i, gridSize.j, gridSize.k);
    138:   DMDASetBoundaryType(da, DMDA_BOUNDARY_NONE, DMDA_BOUNDARY_NONE, DMDA_BOUNDARY_NONE);
    139:   DMDASetDof(da, dof);
    140:   DMDASetStencilType(da, DMDA_STENCIL_BOX);
    141:   DMDASetStencilWidth(da, width);

    143:   mesh->dmCoarse = da;

    145:   DMPatchSetPatchSize(*dm, patchSize);
    146:   DMPatchSetCommSize(*dm, commSize);
    147:   return(0);
    148: }