xref: /petsc/src/dm/impls/patch/patchcreate.c (revision 064a246e8b5c1f87897a54b4a9ec05181ea08258)
1af0996ceSBarry Smith #include <petsc/private/dmpatchimpl.h>   /*I      "petscdmpatch.h"   I*/
23a19ef87SMatthew G Knepley #include <petscdmda.h>
33a19ef87SMatthew G Knepley 
44416b707SBarry Smith PetscErrorCode DMSetFromOptions_Patch(PetscOptionItems *PetscOptionsObject,DM dm)
53a19ef87SMatthew G Knepley {
66fbb21edSJed Brown   /* DM_Patch      *mesh = (DM_Patch*) dm->data; */
73a19ef87SMatthew G Knepley   PetscErrorCode ierr;
83a19ef87SMatthew G Knepley 
93a19ef87SMatthew G Knepley   PetscFunctionBegin;
10*064a246eSJacob Faibussowitsch   PetscValidHeaderSpecific(dm, DM_CLASSID, 2);
11e55864a3SBarry Smith   ierr = PetscOptionsHead(PetscOptionsObject,"DMPatch Options");CHKERRQ(ierr);
123a19ef87SMatthew G Knepley   /* Handle associated vectors */
133a19ef87SMatthew G Knepley   /* Handle viewing */
143a19ef87SMatthew G Knepley   ierr = PetscOptionsTail();CHKERRQ(ierr);
153a19ef87SMatthew G Knepley   PetscFunctionReturn(0);
163a19ef87SMatthew G Knepley }
173a19ef87SMatthew G Knepley 
183a19ef87SMatthew G Knepley /* External function declarations here */
193a19ef87SMatthew G Knepley extern PetscErrorCode DMSetUp_Patch(DM dm);
203a19ef87SMatthew G Knepley extern PetscErrorCode DMView_Patch(DM dm, PetscViewer viewer);
213a19ef87SMatthew G Knepley extern PetscErrorCode DMCreateGlobalVector_Patch(DM dm, Vec *g);
223a19ef87SMatthew G Knepley extern PetscErrorCode DMCreateLocalVector_Patch(DM dm, Vec *l);
233a19ef87SMatthew G Knepley extern PetscErrorCode DMDestroy_Patch(DM dm);
24276c5506SMatthew G. Knepley extern PetscErrorCode DMCreateSubDM_Patch(DM dm, PetscInt numFields, const PetscInt fields[], IS *is, DM *subdm);
253a19ef87SMatthew G Knepley 
263a19ef87SMatthew G Knepley PetscErrorCode DMInitialize_Patch(DM dm)
273a19ef87SMatthew G Knepley {
283a19ef87SMatthew G Knepley   PetscFunctionBegin;
293a19ef87SMatthew G Knepley   dm->ops->view                            = DMView_Patch;
303a19ef87SMatthew G Knepley   dm->ops->setfromoptions                  = DMSetFromOptions_Patch;
313a19ef87SMatthew G Knepley   dm->ops->setup                           = DMSetUp_Patch;
323a19ef87SMatthew G Knepley   dm->ops->createglobalvector              = DMCreateGlobalVector_Patch;
333a19ef87SMatthew G Knepley   dm->ops->createlocalvector               = DMCreateLocalVector_Patch;
34184d77edSJed Brown   dm->ops->getlocaltoglobalmapping         = NULL;
350298fd71SBarry Smith   dm->ops->createfieldis                   = NULL;
36ea78f98cSLisandro Dalcin   dm->ops->getcoloring                     = NULL;
37ea78f98cSLisandro Dalcin   dm->ops->creatematrix                    = NULL;
38ea78f98cSLisandro Dalcin   dm->ops->createinterpolation             = NULL;
39ea78f98cSLisandro Dalcin   dm->ops->createinjection                 = NULL;
40ea78f98cSLisandro Dalcin   dm->ops->refine                          = NULL;
41ea78f98cSLisandro Dalcin   dm->ops->coarsen                         = NULL;
42ea78f98cSLisandro Dalcin   dm->ops->refinehierarchy                 = NULL;
43ea78f98cSLisandro Dalcin   dm->ops->coarsenhierarchy                = NULL;
440298fd71SBarry Smith   dm->ops->globaltolocalbegin              = NULL;
450298fd71SBarry Smith   dm->ops->globaltolocalend                = NULL;
460298fd71SBarry Smith   dm->ops->localtoglobalbegin              = NULL;
470298fd71SBarry Smith   dm->ops->localtoglobalend                = NULL;
483a19ef87SMatthew G Knepley   dm->ops->destroy                         = DMDestroy_Patch;
493a19ef87SMatthew G Knepley   dm->ops->createsubdm                     = DMCreateSubDM_Patch;
503a19ef87SMatthew G Knepley   PetscFunctionReturn(0);
513a19ef87SMatthew G Knepley }
523a19ef87SMatthew G Knepley 
538cc058d9SJed Brown PETSC_EXTERN PetscErrorCode DMCreate_Patch(DM dm)
543a19ef87SMatthew G Knepley {
553a19ef87SMatthew G Knepley   DM_Patch       *mesh;
563a19ef87SMatthew G Knepley   PetscErrorCode ierr;
573a19ef87SMatthew G Knepley 
583a19ef87SMatthew G Knepley   PetscFunctionBegin;
593a19ef87SMatthew G Knepley   PetscValidHeaderSpecific(dm, DM_CLASSID, 1);
60b00a9115SJed Brown   ierr     = PetscNewLog(dm,&mesh);CHKERRQ(ierr);
613a19ef87SMatthew G Knepley   dm->data = mesh;
623a19ef87SMatthew G Knepley 
633a19ef87SMatthew G Knepley   mesh->refct       = 1;
640298fd71SBarry Smith   mesh->dmCoarse    = NULL;
65392fa6c6SMatthew G Knepley   mesh->patchSize.i = 0;
66392fa6c6SMatthew G Knepley   mesh->patchSize.j = 0;
67392fa6c6SMatthew G Knepley   mesh->patchSize.k = 0;
68392fa6c6SMatthew G Knepley   mesh->patchSize.c = 0;
693a19ef87SMatthew G Knepley 
703a19ef87SMatthew G Knepley   ierr = DMInitialize_Patch(dm);CHKERRQ(ierr);
713a19ef87SMatthew G Knepley   PetscFunctionReturn(0);
723a19ef87SMatthew G Knepley }
733a19ef87SMatthew G Knepley 
743a19ef87SMatthew G Knepley /*@
753a19ef87SMatthew G Knepley   DMPatchCreate - Creates a DMPatch object, which is a collections of DMs called patches.
763a19ef87SMatthew G Knepley 
77d083f849SBarry Smith   Collective
783a19ef87SMatthew G Knepley 
793a19ef87SMatthew G Knepley   Input Parameter:
803a19ef87SMatthew G Knepley . comm - The communicator for the DMPatch object
813a19ef87SMatthew G Knepley 
823a19ef87SMatthew G Knepley   Output Parameter:
833a19ef87SMatthew G Knepley . mesh  - The DMPatch object
843a19ef87SMatthew G Knepley 
8560c22052SBarry Smith   Notes:
8660c22052SBarry Smith 
8760c22052SBarry Smith   This code is incomplete and not used by other parts of PETSc.
8860c22052SBarry Smith 
893a19ef87SMatthew G Knepley   Level: beginner
903a19ef87SMatthew G Knepley 
9160c22052SBarry Smith .seealso: DMPatchZoom()
9260c22052SBarry Smith 
933a19ef87SMatthew G Knepley @*/
943a19ef87SMatthew G Knepley PetscErrorCode DMPatchCreate(MPI_Comm comm, DM *mesh)
953a19ef87SMatthew G Knepley {
963a19ef87SMatthew G Knepley   PetscErrorCode ierr;
973a19ef87SMatthew G Knepley 
983a19ef87SMatthew G Knepley   PetscFunctionBegin;
993a19ef87SMatthew G Knepley   PetscValidPointer(mesh,2);
1003a19ef87SMatthew G Knepley   ierr = DMCreate(comm, mesh);CHKERRQ(ierr);
1013a19ef87SMatthew G Knepley   ierr = DMSetType(*mesh, DMPATCH);CHKERRQ(ierr);
1023a19ef87SMatthew G Knepley   PetscFunctionReturn(0);
1033a19ef87SMatthew G Knepley }
1043a19ef87SMatthew G Knepley 
105bb71ef15SMatthew G Knepley PetscErrorCode DMPatchCreateGrid(MPI_Comm comm, PetscInt dim, MatStencil patchSize, MatStencil commSize, MatStencil gridSize, DM *dm)
1063a19ef87SMatthew G Knepley {
1073a19ef87SMatthew G Knepley   DM_Patch       *mesh;
108392fa6c6SMatthew G Knepley   DM             da;
109392fa6c6SMatthew G Knepley   PetscInt       dof = 1, width = 1;
1103a19ef87SMatthew G Knepley   PetscErrorCode ierr;
1113a19ef87SMatthew G Knepley 
1123a19ef87SMatthew G Knepley   PetscFunctionBegin;
1133a19ef87SMatthew G Knepley   ierr = DMPatchCreate(comm, dm);CHKERRQ(ierr);
1143a19ef87SMatthew G Knepley   mesh = (DM_Patch*) (*dm)->data;
1153a19ef87SMatthew G Knepley   if (dim < 2) {
1163a19ef87SMatthew G Knepley     gridSize.j  = 1;
1173a19ef87SMatthew G Knepley     patchSize.j = 1;
1183a19ef87SMatthew G Knepley   }
1193a19ef87SMatthew G Knepley   if (dim < 3) {
1203a19ef87SMatthew G Knepley     gridSize.k  = 1;
1213a19ef87SMatthew G Knepley     patchSize.k = 1;
1223a19ef87SMatthew G Knepley   }
123302440fdSBarry Smith   ierr = DMCreate(comm, &da);CHKERRQ(ierr);
124302440fdSBarry Smith   ierr = DMSetType(da, DMDA);CHKERRQ(ierr);
125c73cfb54SMatthew G. Knepley   ierr = DMSetDimension(da, dim);CHKERRQ(ierr);
1263a19ef87SMatthew G Knepley   ierr = DMDASetSizes(da, gridSize.i, gridSize.j, gridSize.k);CHKERRQ(ierr);
127bff4a2f0SMatthew G. Knepley   ierr = DMDASetBoundaryType(da, DM_BOUNDARY_NONE, DM_BOUNDARY_NONE, DM_BOUNDARY_NONE);CHKERRQ(ierr);
1283a19ef87SMatthew G Knepley   ierr = DMDASetDof(da, dof);CHKERRQ(ierr);
1293a19ef87SMatthew G Knepley   ierr = DMDASetStencilType(da, DMDA_STENCIL_BOX);CHKERRQ(ierr);
1303a19ef87SMatthew G Knepley   ierr = DMDASetStencilWidth(da, width);CHKERRQ(ierr);
1318865f1eaSKarl Rupp 
1323a19ef87SMatthew G Knepley   mesh->dmCoarse = da;
1338865f1eaSKarl Rupp 
134392fa6c6SMatthew G Knepley   ierr = DMPatchSetPatchSize(*dm, patchSize);CHKERRQ(ierr);
135bb71ef15SMatthew G Knepley   ierr = DMPatchSetCommSize(*dm, commSize);CHKERRQ(ierr);
1363a19ef87SMatthew G Knepley   PetscFunctionReturn(0);
1373a19ef87SMatthew G Knepley }
138