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; 103a19ef87SMatthew G Knepley PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 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; 36*ea78f98cSLisandro Dalcin dm->ops->getcoloring = NULL; 37*ea78f98cSLisandro Dalcin dm->ops->creatematrix = NULL; 38*ea78f98cSLisandro Dalcin dm->ops->createinterpolation = NULL; 39*ea78f98cSLisandro Dalcin dm->ops->createinjection = NULL; 40*ea78f98cSLisandro Dalcin dm->ops->refine = NULL; 41*ea78f98cSLisandro Dalcin dm->ops->coarsen = NULL; 42*ea78f98cSLisandro Dalcin dm->ops->refinehierarchy = NULL; 43*ea78f98cSLisandro 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 853a19ef87SMatthew G Knepley Level: beginner 863a19ef87SMatthew G Knepley 873a19ef87SMatthew G Knepley @*/ 883a19ef87SMatthew G Knepley PetscErrorCode DMPatchCreate(MPI_Comm comm, DM *mesh) 893a19ef87SMatthew G Knepley { 903a19ef87SMatthew G Knepley PetscErrorCode ierr; 913a19ef87SMatthew G Knepley 923a19ef87SMatthew G Knepley PetscFunctionBegin; 933a19ef87SMatthew G Knepley PetscValidPointer(mesh,2); 943a19ef87SMatthew G Knepley ierr = DMCreate(comm, mesh);CHKERRQ(ierr); 953a19ef87SMatthew G Knepley ierr = DMSetType(*mesh, DMPATCH);CHKERRQ(ierr); 963a19ef87SMatthew G Knepley PetscFunctionReturn(0); 973a19ef87SMatthew G Knepley } 983a19ef87SMatthew G Knepley 99bb71ef15SMatthew G Knepley PetscErrorCode DMPatchCreateGrid(MPI_Comm comm, PetscInt dim, MatStencil patchSize, MatStencil commSize, MatStencil gridSize, DM *dm) 1003a19ef87SMatthew G Knepley { 1013a19ef87SMatthew G Knepley DM_Patch *mesh; 102392fa6c6SMatthew G Knepley DM da; 103392fa6c6SMatthew G Knepley PetscInt dof = 1, width = 1; 1043a19ef87SMatthew G Knepley PetscErrorCode ierr; 1053a19ef87SMatthew G Knepley 1063a19ef87SMatthew G Knepley PetscFunctionBegin; 1073a19ef87SMatthew G Knepley ierr = DMPatchCreate(comm, dm);CHKERRQ(ierr); 1083a19ef87SMatthew G Knepley mesh = (DM_Patch*) (*dm)->data; 1093a19ef87SMatthew G Knepley if (dim < 2) { 1103a19ef87SMatthew G Knepley gridSize.j = 1; 1113a19ef87SMatthew G Knepley patchSize.j = 1; 1123a19ef87SMatthew G Knepley } 1133a19ef87SMatthew G Knepley if (dim < 3) { 1143a19ef87SMatthew G Knepley gridSize.k = 1; 1153a19ef87SMatthew G Knepley patchSize.k = 1; 1163a19ef87SMatthew G Knepley } 117302440fdSBarry Smith ierr = DMCreate(comm, &da);CHKERRQ(ierr); 118302440fdSBarry Smith ierr = DMSetType(da, DMDA);CHKERRQ(ierr); 119c73cfb54SMatthew G. Knepley ierr = DMSetDimension(da, dim);CHKERRQ(ierr); 1203a19ef87SMatthew G Knepley ierr = DMDASetSizes(da, gridSize.i, gridSize.j, gridSize.k);CHKERRQ(ierr); 121bff4a2f0SMatthew G. Knepley ierr = DMDASetBoundaryType(da, DM_BOUNDARY_NONE, DM_BOUNDARY_NONE, DM_BOUNDARY_NONE);CHKERRQ(ierr); 1223a19ef87SMatthew G Knepley ierr = DMDASetDof(da, dof);CHKERRQ(ierr); 1233a19ef87SMatthew G Knepley ierr = DMDASetStencilType(da, DMDA_STENCIL_BOX);CHKERRQ(ierr); 1243a19ef87SMatthew G Knepley ierr = DMDASetStencilWidth(da, width);CHKERRQ(ierr); 1258865f1eaSKarl Rupp 1263a19ef87SMatthew G Knepley mesh->dmCoarse = da; 1278865f1eaSKarl Rupp 128392fa6c6SMatthew G Knepley ierr = DMPatchSetPatchSize(*dm, patchSize);CHKERRQ(ierr); 129bb71ef15SMatthew G Knepley ierr = DMPatchSetCommSize(*dm, commSize);CHKERRQ(ierr); 1303a19ef87SMatthew G Knepley PetscFunctionReturn(0); 1313a19ef87SMatthew G Knepley } 132