Actual source code: patchcreate.c
petsc-3.12.5 2020-03-29
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, const 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->createinjection = 0;
40: dm->ops->refine = 0;
41: dm->ops->coarsen = 0;
42: dm->ops->refinehierarchy = 0;
43: dm->ops->coarsenhierarchy = 0;
44: dm->ops->globaltolocalbegin = NULL;
45: dm->ops->globaltolocalend = NULL;
46: dm->ops->localtoglobalbegin = NULL;
47: dm->ops->localtoglobalend = NULL;
48: dm->ops->destroy = DMDestroy_Patch;
49: dm->ops->createsubdm = DMCreateSubDM_Patch;
50: return(0);
51: }
53: PETSC_EXTERN PetscErrorCode DMCreate_Patch(DM dm)
54: {
55: DM_Patch *mesh;
60: PetscNewLog(dm,&mesh);
61: dm->data = mesh;
63: mesh->refct = 1;
64: mesh->dmCoarse = NULL;
65: mesh->patchSize.i = 0;
66: mesh->patchSize.j = 0;
67: mesh->patchSize.k = 0;
68: mesh->patchSize.c = 0;
70: DMInitialize_Patch(dm);
71: return(0);
72: }
74: /*@
75: DMPatchCreate - Creates a DMPatch object, which is a collections of DMs called patches.
77: Collective
79: Input Parameter:
80: . comm - The communicator for the DMPatch object
82: Output Parameter:
83: . mesh - The DMPatch object
85: Level: beginner
87: @*/
88: PetscErrorCode DMPatchCreate(MPI_Comm comm, DM *mesh)
89: {
94: DMCreate(comm, mesh);
95: DMSetType(*mesh, DMPATCH);
96: return(0);
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;
107: DMPatchCreate(comm, dm);
108: mesh = (DM_Patch*) (*dm)->data;
109: if (dim < 2) {
110: gridSize.j = 1;
111: patchSize.j = 1;
112: }
113: if (dim < 3) {
114: gridSize.k = 1;
115: patchSize.k = 1;
116: }
117: DMCreate(comm, &da);
118: DMSetType(da, DMDA);
119: DMSetDimension(da, dim);
120: DMDASetSizes(da, gridSize.i, gridSize.j, gridSize.k);
121: DMDASetBoundaryType(da, DM_BOUNDARY_NONE, DM_BOUNDARY_NONE, DM_BOUNDARY_NONE);
122: DMDASetDof(da, dof);
123: DMDASetStencilType(da, DMDA_STENCIL_BOX);
124: DMDASetStencilWidth(da, width);
126: mesh->dmCoarse = da;
128: DMPatchSetPatchSize(*dm, patchSize);
129: DMPatchSetCommSize(*dm, commSize);
130: return(0);
131: }