1 #include <petsc-private/patchimpl.h> /*I "petscdmpatch.h" I*/ 2 #include <petscdmda.h> 3 4 #undef __FUNCT__ 5 #define __FUNCT__ "DMPatchView_Ascii" 6 PetscErrorCode DMPatchView_Ascii(DM dm, PetscViewer viewer) 7 { 8 DM_Patch *mesh = (DM_Patch *) dm->data; 9 PetscViewerFormat format; 10 PetscInt p; 11 PetscErrorCode ierr; 12 13 PetscFunctionBegin; 14 ierr = PetscViewerGetFormat(viewer, &format);CHKERRQ(ierr); 15 /* if (format == PETSC_VIEWER_ASCII_INFO_DETAIL) */ 16 ierr = PetscViewerASCIIPrintf(viewer, "%D patches\n", mesh->numPatches);CHKERRQ(ierr); 17 for(p = 0; p < mesh->numPatches; ++p) { 18 ierr = PetscViewerASCIIPushTab(viewer);CHKERRQ(ierr); 19 ierr = PetscViewerASCIIPrintf(viewer, "Patch %D\n", p);CHKERRQ(ierr); 20 ierr = DMView(mesh->patches[p], viewer);CHKERRQ(ierr); 21 ierr = PetscViewerASCIIPopTab(viewer);CHKERRQ(ierr); 22 } 23 ierr = PetscViewerASCIIPushTab(viewer);CHKERRQ(ierr); 24 ierr = PetscViewerASCIIPrintf(viewer, "Coarse DM\n");CHKERRQ(ierr); 25 ierr = DMView(mesh->dmCoarse, viewer);CHKERRQ(ierr); 26 ierr = PetscViewerASCIIPopTab(viewer);CHKERRQ(ierr); 27 PetscFunctionReturn(0); 28 } 29 30 #undef __FUNCT__ 31 #define __FUNCT__ "DMView_Patch" 32 PetscErrorCode DMView_Patch(DM dm, PetscViewer viewer) 33 { 34 PetscBool iascii, isbinary; 35 PetscErrorCode ierr; 36 37 PetscFunctionBegin; 38 PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 39 PetscValidHeaderSpecific(viewer, PETSC_VIEWER_CLASSID, 2); 40 ierr = PetscObjectTypeCompare((PetscObject) viewer, PETSCVIEWERASCII, &iascii);CHKERRQ(ierr); 41 ierr = PetscObjectTypeCompare((PetscObject) viewer, PETSCVIEWERBINARY, &isbinary);CHKERRQ(ierr); 42 if (iascii) { 43 ierr = DMPatchView_Ascii(dm, viewer);CHKERRQ(ierr); 44 #if 0 45 } else if (isbinary) { 46 ierr = DMPatchView_Binary(dm, viewer);CHKERRQ(ierr); 47 #endif 48 } else SETERRQ1(((PetscObject)viewer)->comm,PETSC_ERR_SUP,"Viewer type %s not supported by this mesh object", ((PetscObject)viewer)->type_name); 49 PetscFunctionReturn(0); 50 } 51 52 #undef __FUNCT__ 53 #define __FUNCT__ "DMDestroy_Patch" 54 PetscErrorCode DMDestroy_Patch(DM dm) 55 { 56 DM_Patch *mesh = (DM_Patch *) dm->data; 57 PetscInt p; 58 PetscErrorCode ierr; 59 60 PetscFunctionBegin; 61 if (--mesh->refct > 0) {PetscFunctionReturn(0);} 62 for(p = 0; p < mesh->numPatches; ++p) { 63 ierr = DMDestroy(&mesh->patches[p]);CHKERRQ(ierr); 64 } 65 ierr = PetscFree(mesh->patches);CHKERRQ(ierr); 66 ierr = DMDestroy(&mesh->dmCoarse);CHKERRQ(ierr); 67 /* This was originally freed in DMDestroy(), but that prevents reference counting of backend objects */ 68 ierr = PetscFree(mesh);CHKERRQ(ierr); 69 PetscFunctionReturn(0); 70 } 71 72 #undef __FUNCT__ 73 #define __FUNCT__ "DMSetUp_Patch" 74 PetscErrorCode DMSetUp_Patch(DM dm) 75 { 76 DM_Patch *mesh = (DM_Patch *) dm->data; 77 PetscInt p; 78 PetscErrorCode ierr; 79 80 PetscFunctionBegin; 81 PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 82 for(p = 0; p < mesh->numPatches; ++p) { 83 ierr = DMSetUp(mesh->patches[p]);CHKERRQ(ierr); 84 } 85 PetscFunctionReturn(0); 86 } 87 88 #undef __FUNCT__ 89 #define __FUNCT__ "DMCreateGlobalVector_Patch" 90 PetscErrorCode DMCreateGlobalVector_Patch(DM dm, Vec *g) 91 { 92 DM_Patch *mesh = (DM_Patch *) dm->data; 93 PetscErrorCode ierr; 94 95 PetscFunctionBegin; 96 PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 97 ierr = DMCreateGlobalVector(mesh->patches[mesh->activePatch], g);CHKERRQ(ierr); 98 PetscFunctionReturn(0); 99 } 100 101 #undef __FUNCT__ 102 #define __FUNCT__ "DMCreateLocalVector_Patch" 103 PetscErrorCode DMCreateLocalVector_Patch(DM dm, Vec *l) 104 { 105 DM_Patch *mesh = (DM_Patch *) dm->data; 106 PetscErrorCode ierr; 107 108 PetscFunctionBegin; 109 PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 110 ierr = DMCreateLocalVector(mesh->patches[mesh->activePatch], l);CHKERRQ(ierr); 111 PetscFunctionReturn(0); 112 } 113 114 #undef __FUNCT__ 115 #define __FUNCT__ "DMPatchGetActivePatch" 116 PetscErrorCode DMPatchGetActivePatch(DM dm, PetscInt *patch) 117 { 118 DM_Patch *mesh; 119 120 PetscFunctionBegin; 121 PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 122 PetscValidPointer(patch, 2); 123 mesh = (DM_Patch *) dm->data; 124 *patch = mesh->activePatch; 125 PetscFunctionReturn(0); 126 } 127 128 #undef __FUNCT__ 129 #define __FUNCT__ "DMPatchSetActivePatch" 130 PetscErrorCode DMPatchSetActivePatch(DM dm, PetscInt patch) 131 { 132 DM_Patch *mesh; 133 134 PetscFunctionBegin; 135 PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 136 mesh = (DM_Patch *) dm->data; 137 mesh->activePatch = patch; 138 PetscFunctionReturn(0); 139 } 140 141 #undef __FUNCT__ 142 #define __FUNCT__ "DMCreateSubDM_Patch" 143 PetscErrorCode DMCreateSubDM_Patch(DM dm, PetscInt numFields, PetscInt fields[], IS *is, DM *subdm) 144 { 145 PetscFunctionBegin; 146 PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 147 SETERRQ(((PetscObject) dm)->comm, PETSC_ERR_SUP, "Tell me to code this"); 148 PetscFunctionReturn(0); 149 } 150