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 PetscInt p; 94 PetscErrorCode ierr; 95 96 PetscFunctionBegin; 97 PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 98 ierr = DMCreateGlobalVector(mesh->activePatch, g);CHKERRQ(ierr); 99 PetscFunctionReturn(0); 100 } 101 102 #undef __FUNCT__ 103 #define __FUNCT__ "DMCreateLocalVector_Patch" 104 PetscErrorCode DMCreateLocalVector_Patch(DM dm, Vec *l) 105 { 106 DM_Patch *mesh = (DM_Patch *) dm->data; 107 PetscInt p; 108 PetscErrorCode ierr; 109 110 PetscFunctionBegin; 111 PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 112 ierr = DMCreateLocalVector(mesh->activePatch, l);CHKERRQ(ierr); 113 PetscFunctionReturn(0); 114 } 115 116 #undef __FUNCT__ 117 #define __FUNCT__ "DMPatchGetActivePatch" 118 PetscErrorCode DMPatchGetActivePatch(DM dm, PetscInt *patch) 119 { 120 DM_Patch *mesh; 121 122 PetscFunctionBegin; 123 PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 124 PetscValidPointer(patch, 2); 125 mesh = (DM_Patch *) dm->data; 126 *patch = mesh->activePatch; 127 PetscFunctionReturn(0); 128 } 129 130 #undef __FUNCT__ 131 #define __FUNCT__ "DMPatchSetActivePatch" 132 PetscErrorCode DMPatchSetActivePatch(DM dm, PetscInt patch) 133 { 134 DM_Patch *mesh; 135 136 PetscFunctionBegin; 137 PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 138 mesh = (DM_Patch *) dm->data; 139 mesh->activePatch = patch; 140 PetscFunctionReturn(0); 141 } 142 143 #undef __FUNCT__ 144 #define __FUNCT__ "DMCreateSubDM_Patch" 145 PetscErrorCode DMCreateSubDM_Patch(DM dm, PetscInt numFields, PetscInt fields[], IS *is, DM *subdm) 146 { 147 PetscFunctionBegin; 148 PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 149 SETERRQ(((PetscObject) dm)->comm, PETSC_ERR_SUP, "Tell me to code this"); 150 PetscFunctionReturn(0); 151 } 152