1 #include <petsc-private/patchimpl.h> /*I "petscdmpatch.h" I*/ 2 #include <petscdmda.h> 3 4 /* 5 Solver loop to update \tau: 6 7 DMZoom(dmc, &dmz) 8 DMRefine(dmz, &dmf), 9 Scatter Xcoarse -> Xzoom, 10 Interpolate Xzoom -> Xfine (note that this may be on subcomms), 11 Smooth Xfine using two-step smoother 12 normal smoother plus Kaczmarz---moves back and forth from dmzoom to dmfine 13 Compute residual Rfine 14 Restrict Rfine to Rzoom_restricted 15 Scatter Rzoom_restricted -> Rcoarse_restricted 16 Compute global residual Rcoarse 17 TauCoarse = Rcoarse - Rcoarse_restricted 18 */ 19 20 #undef __FUNCT__ 21 #define __FUNCT__ "DMPatchView_Ascii" 22 PetscErrorCode DMPatchView_Ascii(DM dm, PetscViewer viewer) 23 { 24 DM_Patch *mesh = (DM_Patch *) dm->data; 25 PetscViewerFormat format; 26 PetscInt p; 27 PetscErrorCode ierr; 28 29 PetscFunctionBegin; 30 ierr = PetscViewerGetFormat(viewer, &format);CHKERRQ(ierr); 31 /* if (format == PETSC_VIEWER_ASCII_INFO_DETAIL) */ 32 ierr = PetscViewerASCIIPrintf(viewer, "%D patches\n", mesh->numPatches);CHKERRQ(ierr); 33 for(p = 0; p < mesh->numPatches; ++p) { 34 ierr = PetscViewerASCIIPushTab(viewer);CHKERRQ(ierr); 35 ierr = PetscViewerASCIIPrintf(viewer, "Patch %D\n", p);CHKERRQ(ierr); 36 ierr = DMView(mesh->patches[p], viewer);CHKERRQ(ierr); 37 ierr = PetscViewerASCIIPopTab(viewer);CHKERRQ(ierr); 38 } 39 ierr = PetscViewerASCIIPushTab(viewer);CHKERRQ(ierr); 40 ierr = PetscViewerASCIIPrintf(viewer, "Coarse DM\n");CHKERRQ(ierr); 41 ierr = DMView(mesh->dmCoarse, viewer);CHKERRQ(ierr); 42 ierr = PetscViewerASCIIPopTab(viewer);CHKERRQ(ierr); 43 PetscFunctionReturn(0); 44 } 45 46 #undef __FUNCT__ 47 #define __FUNCT__ "DMView_Patch" 48 PetscErrorCode DMView_Patch(DM dm, PetscViewer viewer) 49 { 50 PetscBool iascii, isbinary; 51 PetscErrorCode ierr; 52 53 PetscFunctionBegin; 54 PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 55 PetscValidHeaderSpecific(viewer, PETSC_VIEWER_CLASSID, 2); 56 ierr = PetscObjectTypeCompare((PetscObject) viewer, PETSCVIEWERASCII, &iascii);CHKERRQ(ierr); 57 ierr = PetscObjectTypeCompare((PetscObject) viewer, PETSCVIEWERBINARY, &isbinary);CHKERRQ(ierr); 58 if (iascii) { 59 ierr = DMPatchView_Ascii(dm, viewer);CHKERRQ(ierr); 60 #if 0 61 } else if (isbinary) { 62 ierr = DMPatchView_Binary(dm, viewer);CHKERRQ(ierr); 63 #endif 64 } else SETERRQ1(((PetscObject)viewer)->comm,PETSC_ERR_SUP,"Viewer type %s not supported by this mesh object", ((PetscObject)viewer)->type_name); 65 PetscFunctionReturn(0); 66 } 67 68 #undef __FUNCT__ 69 #define __FUNCT__ "DMDestroy_Patch" 70 PetscErrorCode DMDestroy_Patch(DM dm) 71 { 72 DM_Patch *mesh = (DM_Patch *) dm->data; 73 PetscInt p; 74 PetscErrorCode ierr; 75 76 PetscFunctionBegin; 77 if (--mesh->refct > 0) {PetscFunctionReturn(0);} 78 for(p = 0; p < mesh->numPatches; ++p) { 79 ierr = DMDestroy(&mesh->patches[p]);CHKERRQ(ierr); 80 } 81 ierr = PetscFree(mesh->patches);CHKERRQ(ierr); 82 ierr = DMDestroy(&mesh->dmCoarse);CHKERRQ(ierr); 83 /* This was originally freed in DMDestroy(), but that prevents reference counting of backend objects */ 84 ierr = PetscFree(mesh);CHKERRQ(ierr); 85 PetscFunctionReturn(0); 86 } 87 88 #undef __FUNCT__ 89 #define __FUNCT__ "DMSetUp_Patch" 90 PetscErrorCode DMSetUp_Patch(DM dm) 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 for(p = 0; p < mesh->numPatches; ++p) { 99 ierr = DMSetUp(mesh->patches[p]);CHKERRQ(ierr); 100 } 101 PetscFunctionReturn(0); 102 } 103 104 #undef __FUNCT__ 105 #define __FUNCT__ "DMCreateGlobalVector_Patch" 106 PetscErrorCode DMCreateGlobalVector_Patch(DM dm, Vec *g) 107 { 108 DM_Patch *mesh = (DM_Patch *) dm->data; 109 PetscErrorCode ierr; 110 111 PetscFunctionBegin; 112 PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 113 ierr = DMCreateGlobalVector(mesh->patches[mesh->activePatch], g);CHKERRQ(ierr); 114 PetscFunctionReturn(0); 115 } 116 117 #undef __FUNCT__ 118 #define __FUNCT__ "DMCreateLocalVector_Patch" 119 PetscErrorCode DMCreateLocalVector_Patch(DM dm, Vec *l) 120 { 121 DM_Patch *mesh = (DM_Patch *) dm->data; 122 PetscErrorCode ierr; 123 124 PetscFunctionBegin; 125 PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 126 ierr = DMCreateLocalVector(mesh->patches[mesh->activePatch], l);CHKERRQ(ierr); 127 PetscFunctionReturn(0); 128 } 129 130 #undef __FUNCT__ 131 #define __FUNCT__ "DMPatchGetActivePatch" 132 PetscErrorCode DMPatchGetActivePatch(DM dm, PetscInt *patch) 133 { 134 DM_Patch *mesh; 135 136 PetscFunctionBegin; 137 PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 138 PetscValidPointer(patch, 2); 139 mesh = (DM_Patch *) dm->data; 140 *patch = mesh->activePatch; 141 PetscFunctionReturn(0); 142 } 143 144 #undef __FUNCT__ 145 #define __FUNCT__ "DMPatchSetActivePatch" 146 PetscErrorCode DMPatchSetActivePatch(DM dm, PetscInt patch) 147 { 148 DM_Patch *mesh; 149 150 PetscFunctionBegin; 151 PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 152 mesh = (DM_Patch *) dm->data; 153 mesh->activePatch = patch; 154 PetscFunctionReturn(0); 155 } 156 157 #undef __FUNCT__ 158 #define __FUNCT__ "DMCreateSubDM_Patch" 159 PetscErrorCode DMCreateSubDM_Patch(DM dm, PetscInt numFields, PetscInt fields[], IS *is, DM *subdm) 160 { 161 PetscFunctionBegin; 162 PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 163 SETERRQ(((PetscObject) dm)->comm, PETSC_ERR_SUP, "Tell me to code this"); 164 PetscFunctionReturn(0); 165 } 166