1fe1899a2SJed Brown #include <petscdmshell.h> /*I "petscdmshell.h" I*/ 207475bc1SBarry Smith #include <petscmat.h> 3af0996ceSBarry Smith #include <petsc/private/dmimpl.h> 4fe1899a2SJed Brown 5fe1899a2SJed Brown typedef struct { 6fe1899a2SJed Brown Vec Xglobal; 7dc43b69eSJed Brown Vec Xlocal; 8fe1899a2SJed Brown Mat A; 9a94b16f6SRichard Tran Mills VecScatter gtol; 10a94b16f6SRichard Tran Mills VecScatter ltog; 11f089877aSRichard Tran Mills VecScatter ltol; 12*fef3a512SBarry Smith void *ctx; 13fe1899a2SJed Brown } DM_Shell; 14fe1899a2SJed Brown 15fe1899a2SJed Brown #undef __FUNCT__ 167a108d1dSBarry Smith #define __FUNCT__ "DMGlobalToLocalBeginDefaultShell" 177a108d1dSBarry Smith /*@ 187a108d1dSBarry Smith DMGlobalToLocalBeginDefaultShell - Uses the GlobalToLocal VecScatter context set by the user to begin a global to local scatter 198d359177SBarry Smith Collective 208d359177SBarry Smith 218d359177SBarry Smith Input Arguments: 228d359177SBarry Smith + dm - shell DM 238d359177SBarry Smith . g - global vector 248d359177SBarry Smith . mode - InsertMode 258d359177SBarry Smith - l - local vector 268d359177SBarry Smith 277a108d1dSBarry Smith Level: advanced 288d359177SBarry Smith 297a108d1dSBarry Smith Note: This is not normally called directly by user code, generally user code calls DMGlobalToLocalBegin() and DMGlobalToLocalEnd(). If the user provides their own custom routines to DMShellSetLocalToGlobal() then those routines might have reason to call this function. 307a108d1dSBarry Smith 317a108d1dSBarry Smith .seealso: DMGlobalToLocalEndDefaultShell() 328d359177SBarry Smith @*/ 337a108d1dSBarry Smith PetscErrorCode DMGlobalToLocalBeginDefaultShell(DM dm,Vec g,InsertMode mode,Vec l) 348d359177SBarry Smith { 358d359177SBarry Smith PetscErrorCode ierr; 368d359177SBarry Smith DM_Shell *shell = (DM_Shell*)dm->data; 378d359177SBarry Smith 388d359177SBarry Smith PetscFunctionBegin; 397a108d1dSBarry Smith if (!shell->gtol) SETERRQ(((PetscObject)dm)->comm,PETSC_ERR_ARG_WRONGSTATE, "Cannot be used without first setting the scatter context via DMShellSetGlobalToLocalVecScatter()"); 40a94b16f6SRichard Tran Mills ierr = VecScatterBegin(shell->gtol,g,l,mode,SCATTER_FORWARD);CHKERRQ(ierr); 418d359177SBarry Smith PetscFunctionReturn(0); 428d359177SBarry Smith } 438d359177SBarry Smith 448d359177SBarry Smith #undef __FUNCT__ 457a108d1dSBarry Smith #define __FUNCT__ "DMGlobalToLocalEndDefaultShell" 467a108d1dSBarry Smith /*@ 477a108d1dSBarry Smith DMGlobalToLocalEndDefaultShell - Uses the GlobalToLocal VecScatter context set by the user to end a global to local scatter 488d359177SBarry Smith Collective 498d359177SBarry Smith 508d359177SBarry Smith Input Arguments: 518d359177SBarry Smith + dm - shell DM 528d359177SBarry Smith . g - global vector 538d359177SBarry Smith . mode - InsertMode 548d359177SBarry Smith - l - local vector 558d359177SBarry Smith 567a108d1dSBarry Smith Level: advanced 578d359177SBarry Smith 587a108d1dSBarry Smith .seealso: DMGlobalToLocalBeginDefaultShell() 598d359177SBarry Smith @*/ 607a108d1dSBarry Smith PetscErrorCode DMGlobalToLocalEndDefaultShell(DM dm,Vec g,InsertMode mode,Vec l) 618d359177SBarry Smith { 628d359177SBarry Smith PetscErrorCode ierr; 638d359177SBarry Smith DM_Shell *shell = (DM_Shell*)dm->data; 648d359177SBarry Smith 658d359177SBarry Smith PetscFunctionBegin; 667a108d1dSBarry Smith if (!shell->gtol) SETERRQ(((PetscObject)dm)->comm,PETSC_ERR_ARG_WRONGSTATE, "Cannot be used without first setting the scatter context via DMShellSetGlobalToLocalVecScatter()"); 67a94b16f6SRichard Tran Mills ierr = VecScatterEnd(shell->gtol,g,l,mode,SCATTER_FORWARD);CHKERRQ(ierr); 688d359177SBarry Smith PetscFunctionReturn(0); 698d359177SBarry Smith } 708d359177SBarry Smith 718d359177SBarry Smith #undef __FUNCT__ 72c5076b69SRichard Tran Mills #define __FUNCT__ "DMLocalToGlobalBeginDefaultShell" 73c5076b69SRichard Tran Mills /*@ 74c5076b69SRichard Tran Mills DMLocalToGlobalBeginDefaultShell - Uses the LocalToGlobal VecScatter context set by the user to begin a local to global scatter 75c5076b69SRichard Tran Mills Collective 76c5076b69SRichard Tran Mills 77c5076b69SRichard Tran Mills Input Arguments: 78c5076b69SRichard Tran Mills + dm - shell DM 79c5076b69SRichard Tran Mills . l - local vector 80c5076b69SRichard Tran Mills . mode - InsertMode 81c5076b69SRichard Tran Mills - g - global vector 82c5076b69SRichard Tran Mills 83c5076b69SRichard Tran Mills Level: advanced 84c5076b69SRichard Tran Mills 85c5076b69SRichard Tran Mills Note: This is not normally called directly by user code, generally user code calls DMLocalToGlobalBegin() and DMLocalToGlobalEnd(). If the user provides their own custom routines to DMShellSetLocalToGlobal() then those routines might have reason to call this function. 86c5076b69SRichard Tran Mills 87c5076b69SRichard Tran Mills .seealso: DMLocalToGlobalEndDefaultShell() 88c5076b69SRichard Tran Mills @*/ 89c5076b69SRichard Tran Mills PetscErrorCode DMLocalToGlobalBeginDefaultShell(DM dm,Vec l,InsertMode mode,Vec g) 90c5076b69SRichard Tran Mills { 91c5076b69SRichard Tran Mills PetscErrorCode ierr; 92c5076b69SRichard Tran Mills DM_Shell *shell = (DM_Shell*)dm->data; 93c5076b69SRichard Tran Mills 94c5076b69SRichard Tran Mills PetscFunctionBegin; 95c5076b69SRichard Tran Mills if (!shell->ltog) SETERRQ(((PetscObject)dm)->comm,PETSC_ERR_ARG_WRONGSTATE, "Cannot be used without first setting the scatter context via DMShellSetLocalToGlobalVecScatter()"); 96a94b16f6SRichard Tran Mills ierr = VecScatterBegin(shell->ltog,l,g,mode,SCATTER_FORWARD);CHKERRQ(ierr); 97c5076b69SRichard Tran Mills PetscFunctionReturn(0); 98c5076b69SRichard Tran Mills } 99c5076b69SRichard Tran Mills 100c5076b69SRichard Tran Mills #undef __FUNCT__ 101c5076b69SRichard Tran Mills #define __FUNCT__ "DMLocalToGlobalEndDefaultShell" 102c5076b69SRichard Tran Mills /*@ 103c5076b69SRichard Tran Mills DMLocalToGlobalEndDefaultShell - Uses the LocalToGlobal VecScatter context set by the user to end a local to global scatter 104c5076b69SRichard Tran Mills Collective 105c5076b69SRichard Tran Mills 106c5076b69SRichard Tran Mills Input Arguments: 107c5076b69SRichard Tran Mills + dm - shell DM 108c5076b69SRichard Tran Mills . l - local vector 109c5076b69SRichard Tran Mills . mode - InsertMode 110c5076b69SRichard Tran Mills - g - global vector 111c5076b69SRichard Tran Mills 112c5076b69SRichard Tran Mills Level: advanced 113c5076b69SRichard Tran Mills 114c5076b69SRichard Tran Mills .seealso: DMLocalToGlobalBeginDefaultShell() 115c5076b69SRichard Tran Mills @*/ 116c5076b69SRichard Tran Mills PetscErrorCode DMLocalToGlobalEndDefaultShell(DM dm,Vec l,InsertMode mode,Vec g) 117c5076b69SRichard Tran Mills { 118c5076b69SRichard Tran Mills PetscErrorCode ierr; 119c5076b69SRichard Tran Mills DM_Shell *shell = (DM_Shell*)dm->data; 120c5076b69SRichard Tran Mills 121c5076b69SRichard Tran Mills PetscFunctionBegin; 122c5076b69SRichard Tran Mills if (!shell->ltog) SETERRQ(((PetscObject)dm)->comm,PETSC_ERR_ARG_WRONGSTATE, "Cannot be used without first setting the scatter context via DMShellSetLocalToGlobalVecScatter()"); 123a94b16f6SRichard Tran Mills ierr = VecScatterEnd(shell->ltog,l,g,mode,SCATTER_FORWARD);CHKERRQ(ierr); 124c5076b69SRichard Tran Mills PetscFunctionReturn(0); 125c5076b69SRichard Tran Mills } 126c5076b69SRichard Tran Mills 127f3db62a7SRichard Tran Mills #undef __FUNCT__ 128f3db62a7SRichard Tran Mills #define __FUNCT__ "DMLocalToLocalBeginDefaultShell" 129f3db62a7SRichard Tran Mills /*@ 130f3db62a7SRichard Tran Mills DMLocalToLocalBeginDefaultShell - Uses the LocalToLocal VecScatter context set by the user to begin a local to local scatter 131f3db62a7SRichard Tran Mills Collective 132f3db62a7SRichard Tran Mills 133f3db62a7SRichard Tran Mills Input Arguments: 134f3db62a7SRichard Tran Mills + dm - shell DM 135f3db62a7SRichard Tran Mills . g - the original local vector 136f3db62a7SRichard Tran Mills - mode - InsertMode 137f3db62a7SRichard Tran Mills 138f3db62a7SRichard Tran Mills Output Parameter: 139f3db62a7SRichard Tran Mills . l - the local vector with correct ghost values 140f3db62a7SRichard Tran Mills 141f3db62a7SRichard Tran Mills Level: advanced 142f3db62a7SRichard Tran Mills 143f3db62a7SRichard Tran Mills Note: This is not normally called directly by user code, generally user code calls DMLocalToLocalBegin() and DMLocalToLocalEnd(). If the user provides their own custom routines to DMShellSetLocalToLocal() then those routines might have reason to call this function. 144f3db62a7SRichard Tran Mills 145f3db62a7SRichard Tran Mills .seealso: DMLocalToLocalEndDefaultShell() 146f3db62a7SRichard Tran Mills @*/ 147f3db62a7SRichard Tran Mills PetscErrorCode DMLocalToLocalBeginDefaultShell(DM dm,Vec g,InsertMode mode,Vec l) 148f3db62a7SRichard Tran Mills { 149f3db62a7SRichard Tran Mills PetscErrorCode ierr; 150f3db62a7SRichard Tran Mills DM_Shell *shell = (DM_Shell*)dm->data; 151f3db62a7SRichard Tran Mills 152f3db62a7SRichard Tran Mills PetscFunctionBegin; 153f3db62a7SRichard Tran Mills if (!shell->ltol) SETERRQ(((PetscObject)dm)->comm,PETSC_ERR_ARG_WRONGSTATE, "Cannot be used without first setting the scatter context via DMShellSetLocalToLocalVecScatter()"); 154f3db62a7SRichard Tran Mills ierr = VecScatterBegin(shell->ltol,g,l,mode,SCATTER_FORWARD);CHKERRQ(ierr); 155f3db62a7SRichard Tran Mills PetscFunctionReturn(0); 156f3db62a7SRichard Tran Mills } 157f3db62a7SRichard Tran Mills 158f3db62a7SRichard Tran Mills #undef __FUNCT__ 159f3db62a7SRichard Tran Mills #define __FUNCT__ "DMLocalToLocalEndDefaultShell" 160f3db62a7SRichard Tran Mills /*@ 161f3db62a7SRichard Tran Mills DMLocalToLocalEndDefaultShell - Uses the LocalToLocal VecScatter context set by the user to end a local to local scatter 162f3db62a7SRichard Tran Mills Collective 163f3db62a7SRichard Tran Mills 164f3db62a7SRichard Tran Mills Input Arguments: 165f3db62a7SRichard Tran Mills + dm - shell DM 166f3db62a7SRichard Tran Mills . g - the original local vector 167f3db62a7SRichard Tran Mills - mode - InsertMode 168f3db62a7SRichard Tran Mills 169f3db62a7SRichard Tran Mills Output Parameter: 170f3db62a7SRichard Tran Mills . l - the local vector with correct ghost values 171f3db62a7SRichard Tran Mills 172f3db62a7SRichard Tran Mills Level: advanced 173f3db62a7SRichard Tran Mills 174f3db62a7SRichard Tran Mills .seealso: DMLocalToLocalBeginDefaultShell() 175f3db62a7SRichard Tran Mills @*/ 176f3db62a7SRichard Tran Mills PetscErrorCode DMLocalToLocalEndDefaultShell(DM dm,Vec g,InsertMode mode,Vec l) 177f3db62a7SRichard Tran Mills { 178f3db62a7SRichard Tran Mills PetscErrorCode ierr; 179f3db62a7SRichard Tran Mills DM_Shell *shell = (DM_Shell*)dm->data; 180f3db62a7SRichard Tran Mills 181f3db62a7SRichard Tran Mills PetscFunctionBegin; 182f3db62a7SRichard Tran Mills if (!shell->ltol) SETERRQ(((PetscObject)dm)->comm,PETSC_ERR_ARG_WRONGSTATE, "Cannot be used without first setting the scatter context via DMShellSetGlobalToLocalVecScatter()"); 183f3db62a7SRichard Tran Mills ierr = VecScatterEnd(shell->ltol,g,l,mode,SCATTER_FORWARD);CHKERRQ(ierr); 184f3db62a7SRichard Tran Mills PetscFunctionReturn(0); 185f3db62a7SRichard Tran Mills } 186c5076b69SRichard Tran Mills 187c5076b69SRichard Tran Mills #undef __FUNCT__ 188fe1899a2SJed Brown #define __FUNCT__ "DMCreateMatrix_Shell" 189b412c318SBarry Smith static PetscErrorCode DMCreateMatrix_Shell(DM dm,Mat *J) 190fe1899a2SJed Brown { 191fe1899a2SJed Brown PetscErrorCode ierr; 192fe1899a2SJed Brown DM_Shell *shell = (DM_Shell*)dm->data; 193fe1899a2SJed Brown Mat A; 194fe1899a2SJed Brown 195fe1899a2SJed Brown PetscFunctionBegin; 196fe1899a2SJed Brown PetscValidHeaderSpecific(dm,DM_CLASSID,1); 197fe1899a2SJed Brown PetscValidPointer(J,3); 1987bde9f88SJed Brown if (!shell->A) { 1997bde9f88SJed Brown if (shell->Xglobal) { 2007bde9f88SJed Brown PetscInt m,M; 201955c1f14SBarry Smith ierr = PetscInfo(dm,"Naively creating matrix using global vector distribution without preallocation\n");CHKERRQ(ierr); 2027bde9f88SJed Brown ierr = VecGetSize(shell->Xglobal,&M);CHKERRQ(ierr); 2037bde9f88SJed Brown ierr = VecGetLocalSize(shell->Xglobal,&m);CHKERRQ(ierr); 204ce94432eSBarry Smith ierr = MatCreate(PetscObjectComm((PetscObject)dm),&shell->A);CHKERRQ(ierr); 2057bde9f88SJed Brown ierr = MatSetSizes(shell->A,m,m,M,M);CHKERRQ(ierr); 206b412c318SBarry Smith ierr = MatSetType(shell->A,dm->mattype);CHKERRQ(ierr); 2077bde9f88SJed Brown ierr = MatSetUp(shell->A);CHKERRQ(ierr); 208ce94432eSBarry Smith } else SETERRQ(PetscObjectComm((PetscObject)dm),PETSC_ERR_USER,"Must call DMShellSetMatrix(), DMShellSetCreateMatrix(), or provide a vector"); 2097bde9f88SJed Brown } 210fe1899a2SJed Brown A = shell->A; 211ad6bc421SBarry Smith /* the check below is tacky and incomplete */ 212b412c318SBarry Smith if (dm->mattype) { 213ad6bc421SBarry Smith PetscBool flg,aij,seqaij,mpiaij; 214b412c318SBarry Smith ierr = PetscObjectTypeCompare((PetscObject)A,dm->mattype,&flg);CHKERRQ(ierr); 215ad6bc421SBarry Smith ierr = PetscObjectTypeCompare((PetscObject)A,MATSEQAIJ,&seqaij);CHKERRQ(ierr); 216ad6bc421SBarry Smith ierr = PetscObjectTypeCompare((PetscObject)A,MATMPIAIJ,&mpiaij);CHKERRQ(ierr); 217b412c318SBarry Smith ierr = PetscStrcmp(dm->mattype,MATAIJ,&aij);CHKERRQ(ierr); 218ad6bc421SBarry Smith if (!flg) { 219b412c318SBarry Smith if (!(aij && (seqaij || mpiaij))) SETERRQ2(PetscObjectComm((PetscObject)dm),PETSC_ERR_ARG_NOTSAMETYPE,"Requested matrix of type %s, but only %s available",dm->mattype,((PetscObject)A)->type_name); 220ad6bc421SBarry Smith } 221fe1899a2SJed Brown } 222fe1899a2SJed Brown if (((PetscObject)A)->refct < 2) { /* We have an exclusive reference so we can give it out */ 223fe1899a2SJed Brown ierr = PetscObjectReference((PetscObject)A);CHKERRQ(ierr); 224fe1899a2SJed Brown ierr = MatZeroEntries(A);CHKERRQ(ierr); 225fe1899a2SJed Brown *J = A; 226fe1899a2SJed Brown } else { /* Need to create a copy, could use MAT_SHARE_NONZERO_PATTERN in most cases */ 227fe1899a2SJed Brown ierr = MatDuplicate(A,MAT_DO_NOT_COPY_VALUES,J);CHKERRQ(ierr); 228fe1899a2SJed Brown ierr = MatZeroEntries(*J);CHKERRQ(ierr); 229fe1899a2SJed Brown } 230fe1899a2SJed Brown PetscFunctionReturn(0); 231fe1899a2SJed Brown } 232fe1899a2SJed Brown 233fe1899a2SJed Brown #undef __FUNCT__ 234fe1899a2SJed Brown #define __FUNCT__ "DMCreateGlobalVector_Shell" 235fe1899a2SJed Brown PetscErrorCode DMCreateGlobalVector_Shell(DM dm,Vec *gvec) 236fe1899a2SJed Brown { 237fe1899a2SJed Brown PetscErrorCode ierr; 238fe1899a2SJed Brown DM_Shell *shell = (DM_Shell*)dm->data; 239fe1899a2SJed Brown Vec X; 240fe1899a2SJed Brown 241fe1899a2SJed Brown PetscFunctionBegin; 242fe1899a2SJed Brown PetscValidHeaderSpecific(dm,DM_CLASSID,1); 243fe1899a2SJed Brown PetscValidPointer(gvec,2); 244fe1899a2SJed Brown *gvec = 0; 245fe1899a2SJed Brown X = shell->Xglobal; 246ce94432eSBarry Smith if (!X) SETERRQ(PetscObjectComm((PetscObject)dm),PETSC_ERR_USER,"Must call DMShellSetGlobalVector() or DMShellSetCreateGlobalVector()"); 247fe1899a2SJed Brown if (((PetscObject)X)->refct < 2) { /* We have an exclusive reference so we can give it out */ 248fe1899a2SJed Brown ierr = PetscObjectReference((PetscObject)X);CHKERRQ(ierr); 249fe1899a2SJed Brown ierr = VecZeroEntries(X);CHKERRQ(ierr); 250fe1899a2SJed Brown *gvec = X; 251fe1899a2SJed Brown } else { /* Need to create a copy, could use MAT_SHARE_NONZERO_PATTERN in most cases */ 252fe1899a2SJed Brown ierr = VecDuplicate(X,gvec);CHKERRQ(ierr); 253fe1899a2SJed Brown ierr = VecZeroEntries(*gvec);CHKERRQ(ierr); 254fe1899a2SJed Brown } 255c688c046SMatthew G Knepley ierr = VecSetDM(*gvec,dm);CHKERRQ(ierr); 256fe1899a2SJed Brown PetscFunctionReturn(0); 257fe1899a2SJed Brown } 258fe1899a2SJed Brown 259fe1899a2SJed Brown #undef __FUNCT__ 260dc43b69eSJed Brown #define __FUNCT__ "DMCreateLocalVector_Shell" 261dc43b69eSJed Brown PetscErrorCode DMCreateLocalVector_Shell(DM dm,Vec *gvec) 262dc43b69eSJed Brown { 263dc43b69eSJed Brown PetscErrorCode ierr; 264dc43b69eSJed Brown DM_Shell *shell = (DM_Shell*)dm->data; 265dc43b69eSJed Brown Vec X; 266dc43b69eSJed Brown 267dc43b69eSJed Brown PetscFunctionBegin; 268dc43b69eSJed Brown PetscValidHeaderSpecific(dm,DM_CLASSID,1); 269dc43b69eSJed Brown PetscValidPointer(gvec,2); 270dc43b69eSJed Brown *gvec = 0; 271dc43b69eSJed Brown X = shell->Xlocal; 272ce94432eSBarry Smith if (!X) SETERRQ(PetscObjectComm((PetscObject)dm),PETSC_ERR_USER,"Must call DMShellSetLocalVector() or DMShellSetCreateLocalVector()"); 273dc43b69eSJed Brown if (((PetscObject)X)->refct < 2) { /* We have an exclusive reference so we can give it out */ 274dc43b69eSJed Brown ierr = PetscObjectReference((PetscObject)X);CHKERRQ(ierr); 275dc43b69eSJed Brown ierr = VecZeroEntries(X);CHKERRQ(ierr); 276dc43b69eSJed Brown *gvec = X; 277dc43b69eSJed Brown } else { /* Need to create a copy, could use MAT_SHARE_NONZERO_PATTERN in most cases */ 278dc43b69eSJed Brown ierr = VecDuplicate(X,gvec);CHKERRQ(ierr); 279dc43b69eSJed Brown ierr = VecZeroEntries(*gvec);CHKERRQ(ierr); 280dc43b69eSJed Brown } 2816e4cbd8bSMark F. Adams ierr = VecSetDM(*gvec,dm);CHKERRQ(ierr); 282dc43b69eSJed Brown PetscFunctionReturn(0); 283dc43b69eSJed Brown } 284dc43b69eSJed Brown 285dc43b69eSJed Brown #undef __FUNCT__ 286*fef3a512SBarry Smith #define __FUNCT__ "DMShellSetContext" 287*fef3a512SBarry Smith /*@ 288*fef3a512SBarry Smith DMShellSetContext - set some data to be usable by this DM 289*fef3a512SBarry Smith 290*fef3a512SBarry Smith Collective 291*fef3a512SBarry Smith 292*fef3a512SBarry Smith Input Arguments: 293*fef3a512SBarry Smith + dm - shell DM 294*fef3a512SBarry Smith - ctx - the context 295*fef3a512SBarry Smith 296*fef3a512SBarry Smith Level: advanced 297*fef3a512SBarry Smith 298*fef3a512SBarry Smith .seealso: DMCreateMatrix(), DMShellGetContext() 299*fef3a512SBarry Smith @*/ 300*fef3a512SBarry Smith PetscErrorCode DMShellSetContext(DM dm,void *ctx) 301*fef3a512SBarry Smith { 302*fef3a512SBarry Smith DM_Shell *shell = (DM_Shell*)dm->data; 303*fef3a512SBarry Smith PetscErrorCode ierr; 304*fef3a512SBarry Smith PetscBool isshell; 305*fef3a512SBarry Smith 306*fef3a512SBarry Smith PetscFunctionBegin; 307*fef3a512SBarry Smith PetscValidHeaderSpecific(dm,DM_CLASSID,1); 308*fef3a512SBarry Smith ierr = PetscObjectTypeCompare((PetscObject)dm,DMSHELL,&isshell);CHKERRQ(ierr); 309*fef3a512SBarry Smith if (!isshell) PetscFunctionReturn(0); 310*fef3a512SBarry Smith shell->ctx = ctx; 311*fef3a512SBarry Smith PetscFunctionReturn(0); 312*fef3a512SBarry Smith } 313*fef3a512SBarry Smith 314*fef3a512SBarry Smith #undef __FUNCT__ 315*fef3a512SBarry Smith #define __FUNCT__ "DMShellGetContext" 316*fef3a512SBarry Smith /*@ 317*fef3a512SBarry Smith DMShellGetContext - set some data to be usable by this DM 318*fef3a512SBarry Smith 319*fef3a512SBarry Smith Collective 320*fef3a512SBarry Smith 321*fef3a512SBarry Smith Input Argument: 322*fef3a512SBarry Smith . dm - shell DM 323*fef3a512SBarry Smith 324*fef3a512SBarry Smith Output Argument: 325*fef3a512SBarry Smith . ctx - the context 326*fef3a512SBarry Smith 327*fef3a512SBarry Smith Level: advanced 328*fef3a512SBarry Smith 329*fef3a512SBarry Smith .seealso: DMCreateMatrix(), DMShellSetContext() 330*fef3a512SBarry Smith @*/ 331*fef3a512SBarry Smith PetscErrorCode DMShellGetContext(DM dm,void **ctx) 332*fef3a512SBarry Smith { 333*fef3a512SBarry Smith DM_Shell *shell = (DM_Shell*)dm->data; 334*fef3a512SBarry Smith PetscErrorCode ierr; 335*fef3a512SBarry Smith PetscBool isshell; 336*fef3a512SBarry Smith 337*fef3a512SBarry Smith PetscFunctionBegin; 338*fef3a512SBarry Smith PetscValidHeaderSpecific(dm,DM_CLASSID,1); 339*fef3a512SBarry Smith ierr = PetscObjectTypeCompare((PetscObject)dm,DMSHELL,&isshell);CHKERRQ(ierr); 340*fef3a512SBarry Smith if (!isshell) PetscFunctionReturn(0); 341*fef3a512SBarry Smith *ctx = shell->ctx; 342*fef3a512SBarry Smith PetscFunctionReturn(0); 343*fef3a512SBarry Smith } 344*fef3a512SBarry Smith 345*fef3a512SBarry Smith #undef __FUNCT__ 346fe1899a2SJed Brown #define __FUNCT__ "DMShellSetMatrix" 347fe1899a2SJed Brown /*@ 348fe1899a2SJed Brown DMShellSetMatrix - sets a template matrix associated with the DMShell 349fe1899a2SJed Brown 350fe1899a2SJed Brown Collective 351fe1899a2SJed Brown 352fe1899a2SJed Brown Input Arguments: 353fe1899a2SJed Brown + dm - shell DM 354fe1899a2SJed Brown - J - template matrix 355fe1899a2SJed Brown 356fe1899a2SJed Brown Level: advanced 357fe1899a2SJed Brown 358*fef3a512SBarry Smith .seealso: DMCreateMatrix(), DMShellSetCreateMatrix(), DMShellSetContext(), DMShellGetContext() 359fe1899a2SJed Brown @*/ 360fe1899a2SJed Brown PetscErrorCode DMShellSetMatrix(DM dm,Mat J) 361fe1899a2SJed Brown { 362fe1899a2SJed Brown DM_Shell *shell = (DM_Shell*)dm->data; 363fe1899a2SJed Brown PetscErrorCode ierr; 3648c87107bSJed Brown PetscBool isshell; 365fe1899a2SJed Brown 366fe1899a2SJed Brown PetscFunctionBegin; 3678c87107bSJed Brown PetscValidHeaderSpecific(dm,DM_CLASSID,1); 3688c87107bSJed Brown PetscValidHeaderSpecific(J,MAT_CLASSID,2); 369251f4c67SDmitry Karpeev ierr = PetscObjectTypeCompare((PetscObject)dm,DMSHELL,&isshell);CHKERRQ(ierr); 3708c87107bSJed Brown if (!isshell) PetscFunctionReturn(0); 371fe1899a2SJed Brown ierr = PetscObjectReference((PetscObject)J);CHKERRQ(ierr); 372fe1899a2SJed Brown ierr = MatDestroy(&shell->A);CHKERRQ(ierr); 373fe1899a2SJed Brown shell->A = J; 374fe1899a2SJed Brown PetscFunctionReturn(0); 375fe1899a2SJed Brown } 376fe1899a2SJed Brown 377fe1899a2SJed Brown #undef __FUNCT__ 378fe1899a2SJed Brown #define __FUNCT__ "DMShellSetCreateMatrix" 379fe1899a2SJed Brown /*@C 380fe1899a2SJed Brown DMShellSetCreateMatrix - sets the routine to create a matrix associated with the shell DM 381fe1899a2SJed Brown 382fe1899a2SJed Brown Logically Collective on DM 383fe1899a2SJed Brown 384fe1899a2SJed Brown Input Arguments: 385fe1899a2SJed Brown + dm - the shell DM 386fe1899a2SJed Brown - func - the function to create a matrix 387fe1899a2SJed Brown 388fe1899a2SJed Brown Level: advanced 389fe1899a2SJed Brown 390*fef3a512SBarry Smith .seealso: DMCreateMatrix(), DMShellSetMatrix(), DMShellSetContext(), DMShellGetContext() 391fe1899a2SJed Brown @*/ 392b412c318SBarry Smith PetscErrorCode DMShellSetCreateMatrix(DM dm,PetscErrorCode (*func)(DM,Mat*)) 393fe1899a2SJed Brown { 394fe1899a2SJed Brown 395fe1899a2SJed Brown PetscFunctionBegin; 396fe1899a2SJed Brown PetscValidHeaderSpecific(dm,DM_CLASSID,1); 397fe1899a2SJed Brown dm->ops->creatematrix = func; 398fe1899a2SJed Brown PetscFunctionReturn(0); 399fe1899a2SJed Brown } 400fe1899a2SJed Brown 401fe1899a2SJed Brown #undef __FUNCT__ 402fe1899a2SJed Brown #define __FUNCT__ "DMShellSetGlobalVector" 403fe1899a2SJed Brown /*@ 404fe1899a2SJed Brown DMShellSetGlobalVector - sets a template global vector associated with the DMShell 405fe1899a2SJed Brown 406fe1899a2SJed Brown Logically Collective on DM 407fe1899a2SJed Brown 408fe1899a2SJed Brown Input Arguments: 409fe1899a2SJed Brown + dm - shell DM 410fe1899a2SJed Brown - X - template vector 411fe1899a2SJed Brown 412fe1899a2SJed Brown Level: advanced 413fe1899a2SJed Brown 414fe1899a2SJed Brown .seealso: DMCreateGlobalVector(), DMShellSetMatrix(), DMShellSetCreateGlobalVector() 415fe1899a2SJed Brown @*/ 416fe1899a2SJed Brown PetscErrorCode DMShellSetGlobalVector(DM dm,Vec X) 417fe1899a2SJed Brown { 418fe1899a2SJed Brown DM_Shell *shell = (DM_Shell*)dm->data; 419fe1899a2SJed Brown PetscErrorCode ierr; 4208c87107bSJed Brown PetscBool isshell; 421fe1899a2SJed Brown 422fe1899a2SJed Brown PetscFunctionBegin; 4238c87107bSJed Brown PetscValidHeaderSpecific(dm,DM_CLASSID,1); 4248c87107bSJed Brown PetscValidHeaderSpecific(X,VEC_CLASSID,2); 425251f4c67SDmitry Karpeev ierr = PetscObjectTypeCompare((PetscObject)dm,DMSHELL,&isshell);CHKERRQ(ierr); 4268c87107bSJed Brown if (!isshell) PetscFunctionReturn(0); 427fe1899a2SJed Brown ierr = PetscObjectReference((PetscObject)X);CHKERRQ(ierr); 428fe1899a2SJed Brown ierr = VecDestroy(&shell->Xglobal);CHKERRQ(ierr); 429fe1899a2SJed Brown shell->Xglobal = X; 430fe1899a2SJed Brown PetscFunctionReturn(0); 431fe1899a2SJed Brown } 432fe1899a2SJed Brown 433fe1899a2SJed Brown #undef __FUNCT__ 434fe1899a2SJed Brown #define __FUNCT__ "DMShellSetCreateGlobalVector" 435fe1899a2SJed Brown /*@C 436fe1899a2SJed Brown DMShellSetCreateGlobalVector - sets the routine to create a global vector associated with the shell DM 437fe1899a2SJed Brown 438fe1899a2SJed Brown Logically Collective 439fe1899a2SJed Brown 440fe1899a2SJed Brown Input Arguments: 441fe1899a2SJed Brown + dm - the shell DM 442fe1899a2SJed Brown - func - the creation routine 443fe1899a2SJed Brown 444fe1899a2SJed Brown Level: advanced 445fe1899a2SJed Brown 446*fef3a512SBarry Smith .seealso: DMShellSetGlobalVector(), DMShellSetCreateMatrix(), DMShellSetContext(), DMShellGetContext() 447fe1899a2SJed Brown @*/ 448fe1899a2SJed Brown PetscErrorCode DMShellSetCreateGlobalVector(DM dm,PetscErrorCode (*func)(DM,Vec*)) 449fe1899a2SJed Brown { 450fe1899a2SJed Brown 451fe1899a2SJed Brown PetscFunctionBegin; 452fe1899a2SJed Brown PetscValidHeaderSpecific(dm,DM_CLASSID,1); 453fe1899a2SJed Brown dm->ops->createglobalvector = func; 454fe1899a2SJed Brown PetscFunctionReturn(0); 455fe1899a2SJed Brown } 456fe1899a2SJed Brown 457fe1899a2SJed Brown #undef __FUNCT__ 458dc43b69eSJed Brown #define __FUNCT__ "DMShellSetLocalVector" 459dc43b69eSJed Brown /*@ 460dc43b69eSJed Brown DMShellSetLocalVector - sets a template local vector associated with the DMShell 461dc43b69eSJed Brown 462dc43b69eSJed Brown Logically Collective on DM 463dc43b69eSJed Brown 464dc43b69eSJed Brown Input Arguments: 465dc43b69eSJed Brown + dm - shell DM 466dc43b69eSJed Brown - X - template vector 467dc43b69eSJed Brown 468dc43b69eSJed Brown Level: advanced 469dc43b69eSJed Brown 470dc43b69eSJed Brown .seealso: DMCreateLocalVector(), DMShellSetMatrix(), DMShellSetCreateLocalVector() 471dc43b69eSJed Brown @*/ 472dc43b69eSJed Brown PetscErrorCode DMShellSetLocalVector(DM dm,Vec X) 473dc43b69eSJed Brown { 474dc43b69eSJed Brown DM_Shell *shell = (DM_Shell*)dm->data; 475dc43b69eSJed Brown PetscErrorCode ierr; 476dc43b69eSJed Brown PetscBool isshell; 477dc43b69eSJed Brown 478dc43b69eSJed Brown PetscFunctionBegin; 479dc43b69eSJed Brown PetscValidHeaderSpecific(dm,DM_CLASSID,1); 480dc43b69eSJed Brown PetscValidHeaderSpecific(X,VEC_CLASSID,2); 481dc43b69eSJed Brown ierr = PetscObjectTypeCompare((PetscObject)dm,DMSHELL,&isshell);CHKERRQ(ierr); 482dc43b69eSJed Brown if (!isshell) PetscFunctionReturn(0); 483dc43b69eSJed Brown ierr = PetscObjectReference((PetscObject)X);CHKERRQ(ierr); 484dc43b69eSJed Brown ierr = VecDestroy(&shell->Xlocal);CHKERRQ(ierr); 485dc43b69eSJed Brown shell->Xlocal = X; 486dc43b69eSJed Brown PetscFunctionReturn(0); 487dc43b69eSJed Brown } 488dc43b69eSJed Brown 489dc43b69eSJed Brown #undef __FUNCT__ 490dc43b69eSJed Brown #define __FUNCT__ "DMShellSetCreateLocalVector" 491dc43b69eSJed Brown /*@C 492dc43b69eSJed Brown DMShellSetCreateLocalVector - sets the routine to create a local vector associated with the shell DM 493dc43b69eSJed Brown 494dc43b69eSJed Brown Logically Collective 495dc43b69eSJed Brown 496dc43b69eSJed Brown Input Arguments: 497dc43b69eSJed Brown + dm - the shell DM 498dc43b69eSJed Brown - func - the creation routine 499dc43b69eSJed Brown 500dc43b69eSJed Brown Level: advanced 501dc43b69eSJed Brown 502*fef3a512SBarry Smith .seealso: DMShellSetLocalVector(), DMShellSetCreateMatrix(), DMShellSetContext(), DMShellGetContext() 503dc43b69eSJed Brown @*/ 504dc43b69eSJed Brown PetscErrorCode DMShellSetCreateLocalVector(DM dm,PetscErrorCode (*func)(DM,Vec*)) 505dc43b69eSJed Brown { 506dc43b69eSJed Brown 507dc43b69eSJed Brown PetscFunctionBegin; 508dc43b69eSJed Brown PetscValidHeaderSpecific(dm,DM_CLASSID,1); 509dc43b69eSJed Brown dm->ops->createlocalvector = func; 510dc43b69eSJed Brown PetscFunctionReturn(0); 511dc43b69eSJed Brown } 512dc43b69eSJed Brown 513dc43b69eSJed Brown #undef __FUNCT__ 5148339e6d0SRichard Tran Mills #define __FUNCT__ "DMShellSetGlobalToLocal" 5158339e6d0SRichard Tran Mills /*@C 5168339e6d0SRichard Tran Mills DMShellSetGlobalToLocal - Sets the routines used to perform a global to local scatter 5178339e6d0SRichard Tran Mills 5188339e6d0SRichard Tran Mills Logically Collective on DM 5198339e6d0SRichard Tran Mills 5208339e6d0SRichard Tran Mills Input Arguments 5218339e6d0SRichard Tran Mills + dm - the shell DM 5228339e6d0SRichard Tran Mills . begin - the routine that begins the global to local scatter 5238339e6d0SRichard Tran Mills - end - the routine that ends the global to local scatter 5248339e6d0SRichard Tran Mills 5257a108d1dSBarry Smith Notes: If these functions are not provided but DMShellSetGlobalToLocalVecScatter() is called then 526f3db62a7SRichard Tran Mills DMGlobalToLocalBeginDefaultShell()/DMGlobalToLocalEndDefaultShell() are used to to perform the transfers 5277a108d1dSBarry Smith 5288339e6d0SRichard Tran Mills Level: advanced 5298339e6d0SRichard Tran Mills 5307a108d1dSBarry Smith .seealso: DMShellSetLocalToGlobal(), DMGlobalToLocalBeginDefaultShell(), DMGlobalToLocalEndDefaultShell() 5318339e6d0SRichard Tran Mills @*/ 5328339e6d0SRichard Tran Mills PetscErrorCode DMShellSetGlobalToLocal(DM dm,PetscErrorCode (*begin)(DM,Vec,InsertMode,Vec),PetscErrorCode (*end)(DM,Vec,InsertMode,Vec)) { 5338339e6d0SRichard Tran Mills PetscFunctionBegin; 5348339e6d0SRichard Tran Mills dm->ops->globaltolocalbegin = begin; 5358339e6d0SRichard Tran Mills dm->ops->globaltolocalend = end; 5368339e6d0SRichard Tran Mills PetscFunctionReturn(0); 5378339e6d0SRichard Tran Mills } 5388339e6d0SRichard Tran Mills 5398339e6d0SRichard Tran Mills #undef __FUNCT__ 5408339e6d0SRichard Tran Mills #define __FUNCT__ "DMShellSetLocalToGlobal" 5418339e6d0SRichard Tran Mills /*@C 5428339e6d0SRichard Tran Mills DMShellSetLocalToGlobal - Sets the routines used to perform a local to global scatter 5438339e6d0SRichard Tran Mills 5448339e6d0SRichard Tran Mills Logically Collective on DM 5458339e6d0SRichard Tran Mills 5468339e6d0SRichard Tran Mills Input Arguments 5478339e6d0SRichard Tran Mills + dm - the shell DM 5488339e6d0SRichard Tran Mills . begin - the routine that begins the local to global scatter 5498339e6d0SRichard Tran Mills - end - the routine that ends the local to global scatter 5508339e6d0SRichard Tran Mills 551f3db62a7SRichard Tran Mills Notes: If these functions are not provided but DMShellSetLocalToGlobalVecScatter() is called then 552f3db62a7SRichard Tran Mills DMLocalToGlobalBeginDefaultShell()/DMLocalToGlobalEndDefaultShell() are used to to perform the transfers 553f3db62a7SRichard Tran Mills 5548339e6d0SRichard Tran Mills Level: advanced 5558339e6d0SRichard Tran Mills 5568339e6d0SRichard Tran Mills .seealso: DMShellSetGlobalToLocal() 5578339e6d0SRichard Tran Mills @*/ 5588339e6d0SRichard Tran Mills PetscErrorCode DMShellSetLocalToGlobal(DM dm,PetscErrorCode (*begin)(DM,Vec,InsertMode,Vec),PetscErrorCode (*end)(DM,Vec,InsertMode,Vec)) { 5598339e6d0SRichard Tran Mills PetscFunctionBegin; 5608339e6d0SRichard Tran Mills dm->ops->localtoglobalbegin = begin; 5618339e6d0SRichard Tran Mills dm->ops->localtoglobalend = end; 5628339e6d0SRichard Tran Mills PetscFunctionReturn(0); 5638339e6d0SRichard Tran Mills } 5648339e6d0SRichard Tran Mills 5658339e6d0SRichard Tran Mills #undef __FUNCT__ 566f3db62a7SRichard Tran Mills #define __FUNCT__ "DMShellSetLocalToLocal" 567f3db62a7SRichard Tran Mills /*@C 568f3db62a7SRichard Tran Mills DMShellSetLocalToLocal - Sets the routines used to perform a local to local scatter 569f3db62a7SRichard Tran Mills 570f3db62a7SRichard Tran Mills Logically Collective on DM 571f3db62a7SRichard Tran Mills 572f3db62a7SRichard Tran Mills Input Arguments 573f3db62a7SRichard Tran Mills + dm - the shell DM 574f3db62a7SRichard Tran Mills . begin - the routine that begins the local to local scatter 575f3db62a7SRichard Tran Mills - end - the routine that ends the local to local scatter 576f3db62a7SRichard Tran Mills 577f3db62a7SRichard Tran Mills Notes: If these functions are not provided but DMShellSetLocalToLocalVecScatter() is called then 578f3db62a7SRichard Tran Mills DMLocalToLocalBeginDefaultShell()/DMLocalToLocalEndDefaultShell() are used to to perform the transfers 579f3db62a7SRichard Tran Mills 580f3db62a7SRichard Tran Mills Level: advanced 581f3db62a7SRichard Tran Mills 582f3db62a7SRichard Tran Mills .seealso: DMShellSetGlobalToLocal(), DMLocalToLocalBeginDefaultShell(), DMLocalToLocalEndDefaultShell() 583f3db62a7SRichard Tran Mills @*/ 584f3db62a7SRichard Tran Mills PetscErrorCode DMShellSetLocalToLocal(DM dm,PetscErrorCode (*begin)(DM,Vec,InsertMode,Vec),PetscErrorCode (*end)(DM,Vec,InsertMode,Vec)) { 585f3db62a7SRichard Tran Mills PetscFunctionBegin; 586f3db62a7SRichard Tran Mills dm->ops->localtolocalbegin = begin; 587f3db62a7SRichard Tran Mills dm->ops->localtolocalend = end; 588f3db62a7SRichard Tran Mills PetscFunctionReturn(0); 589f3db62a7SRichard Tran Mills } 590f3db62a7SRichard Tran Mills 591f3db62a7SRichard Tran Mills #undef __FUNCT__ 59281634712SRichard Tran Mills #define __FUNCT__ "DMShellSetGlobalToLocalVecScatter" 59381634712SRichard Tran Mills /*@ 59481634712SRichard Tran Mills DMShellSetGlobalToLocalVecScatter - Sets a VecScatter context for global to local communication 59581634712SRichard Tran Mills 59681634712SRichard Tran Mills Logically Collective on DM 59781634712SRichard Tran Mills 59881634712SRichard Tran Mills Input Arguments 59981634712SRichard Tran Mills + dm - the shell DM 60081634712SRichard Tran Mills - gtol - the global to local VecScatter context 60181634712SRichard Tran Mills 60281634712SRichard Tran Mills Level: advanced 60381634712SRichard Tran Mills 604f3db62a7SRichard Tran Mills .seealso: DMShellSetGlobalToLocal(), DMGlobalToLocalBeginDefaultShell(), DMGlobalToLocalEndDefaultShell() 60581634712SRichard Tran Mills @*/ 606a94b16f6SRichard Tran Mills PetscErrorCode DMShellSetGlobalToLocalVecScatter(DM dm, VecScatter gtol) 60781634712SRichard Tran Mills { 60881634712SRichard Tran Mills DM_Shell *shell = (DM_Shell*)dm->data; 609d885d199SRichard Tran Mills PetscErrorCode ierr; 61081634712SRichard Tran Mills 611b300e4a8SRichard Tran Mills PetscFunctionBegin; 612d885d199SRichard Tran Mills ierr = PetscObjectReference((PetscObject)gtol);CHKERRQ(ierr); 613d885d199SRichard Tran Mills /* Call VecScatterDestroy() to avoid a memory leak in case of re-setting. */ 614d885d199SRichard Tran Mills ierr = VecScatterDestroy(&shell->gtol);CHKERRQ(ierr); 61581634712SRichard Tran Mills shell->gtol = gtol; 61681634712SRichard Tran Mills PetscFunctionReturn(0); 61781634712SRichard Tran Mills } 61881634712SRichard Tran Mills 61981634712SRichard Tran Mills #undef __FUNCT__ 620988ea7d6SRichard Tran Mills #define __FUNCT__ "DMShellSetLocalToGlobalVecScatter" 621988ea7d6SRichard Tran Mills /*@ 622988ea7d6SRichard Tran Mills DMShellSetLocalToGlobalVecScatter - Sets a VecScatter context for local to global communication 623988ea7d6SRichard Tran Mills 624988ea7d6SRichard Tran Mills Logically Collective on DM 625988ea7d6SRichard Tran Mills 626988ea7d6SRichard Tran Mills Input Arguments 627988ea7d6SRichard Tran Mills + dm - the shell DM 628988ea7d6SRichard Tran Mills - ltog - the local to global VecScatter context 629988ea7d6SRichard Tran Mills 630988ea7d6SRichard Tran Mills Level: advanced 631988ea7d6SRichard Tran Mills 632f3db62a7SRichard Tran Mills .seealso: DMShellSetLocalToGlobal(), DMLocalToGlobalBeginDefaultShell(), DMLocalToGlobalEndDefaultShell() 633988ea7d6SRichard Tran Mills @*/ 634a94b16f6SRichard Tran Mills PetscErrorCode DMShellSetLocalToGlobalVecScatter(DM dm, VecScatter ltog) 635988ea7d6SRichard Tran Mills { 636988ea7d6SRichard Tran Mills DM_Shell *shell = (DM_Shell*)dm->data; 637d885d199SRichard Tran Mills PetscErrorCode ierr; 638988ea7d6SRichard Tran Mills 639988ea7d6SRichard Tran Mills PetscFunctionBegin; 640d885d199SRichard Tran Mills ierr = PetscObjectReference((PetscObject)ltog);CHKERRQ(ierr); 641d885d199SRichard Tran Mills /* Call VecScatterDestroy() to avoid a memory leak in case of re-setting. */ 642d885d199SRichard Tran Mills ierr = VecScatterDestroy(&shell->ltog);CHKERRQ(ierr); 643988ea7d6SRichard Tran Mills shell->ltog = ltog; 644988ea7d6SRichard Tran Mills PetscFunctionReturn(0); 645988ea7d6SRichard Tran Mills } 646988ea7d6SRichard Tran Mills 647988ea7d6SRichard Tran Mills #undef __FUNCT__ 648f3db62a7SRichard Tran Mills #define __FUNCT__ "DMShellSetLocalToLocalVecScatter" 649f3db62a7SRichard Tran Mills /*@ 650f3db62a7SRichard Tran Mills DMShellSetLocalToLocalVecScatter - Sets a VecScatter context for local to local communication 651f3db62a7SRichard Tran Mills 652f3db62a7SRichard Tran Mills Logically Collective on DM 653f3db62a7SRichard Tran Mills 654f3db62a7SRichard Tran Mills Input Arguments 655f3db62a7SRichard Tran Mills + dm - the shell DM 656f3db62a7SRichard Tran Mills - ltol - the local to local VecScatter context 657f3db62a7SRichard Tran Mills 658f3db62a7SRichard Tran Mills Level: advanced 659f3db62a7SRichard Tran Mills 660f3db62a7SRichard Tran Mills .seealso: DMShellSetLocalToLocal(), DMLocalToLocalBeginDefaultShell(), DMLocalToLocalEndDefaultShell() 661f3db62a7SRichard Tran Mills @*/ 662f3db62a7SRichard Tran Mills PetscErrorCode DMShellSetLocalToLocalVecScatter(DM dm, VecScatter ltol) 663f3db62a7SRichard Tran Mills { 664f3db62a7SRichard Tran Mills DM_Shell *shell = (DM_Shell*)dm->data; 665f3db62a7SRichard Tran Mills PetscErrorCode ierr; 666f3db62a7SRichard Tran Mills 667f3db62a7SRichard Tran Mills PetscFunctionBegin; 668f3db62a7SRichard Tran Mills ierr = PetscObjectReference((PetscObject)ltol);CHKERRQ(ierr); 669f3db62a7SRichard Tran Mills /* Call VecScatterDestroy() to avoid a memory leak in case of re-setting. */ 670f3db62a7SRichard Tran Mills ierr = VecScatterDestroy(&shell->ltol);CHKERRQ(ierr); 671f3db62a7SRichard Tran Mills shell->ltol = ltol; 672f3db62a7SRichard Tran Mills PetscFunctionReturn(0); 673f3db62a7SRichard Tran Mills } 674f3db62a7SRichard Tran Mills 675f3db62a7SRichard Tran Mills #undef __FUNCT__ 676f572501eSLawrence Mitchell #define __FUNCT__ "DMShellSetCoarsen" 6779bf9660cSLawrence Mitchell /*@C 6789bf9660cSLawrence Mitchell DMShellSetCoarsen - Set the routine used to coarsen the shell DM 6799bf9660cSLawrence Mitchell 6809bf9660cSLawrence Mitchell Logically Collective on DM 6819bf9660cSLawrence Mitchell 6829bf9660cSLawrence Mitchell Input Arguments 6839bf9660cSLawrence Mitchell + dm - the shell DM 6849bf9660cSLawrence Mitchell - coarsen - the routine that coarsens the DM 6859bf9660cSLawrence Mitchell 6869bf9660cSLawrence Mitchell Level: advanced 6879bf9660cSLawrence Mitchell 688*fef3a512SBarry Smith .seealso: DMShellSetRefine(), DMCoarsen(), DMShellSetContext(), DMShellGetContext() 6899bf9660cSLawrence Mitchell @*/ 690f572501eSLawrence Mitchell PetscErrorCode DMShellSetCoarsen(DM dm, PetscErrorCode (*coarsen)(DM,MPI_Comm,DM*)) 691f572501eSLawrence Mitchell { 692f572501eSLawrence Mitchell PetscErrorCode ierr; 693f572501eSLawrence Mitchell PetscBool isshell; 694f572501eSLawrence Mitchell 695f572501eSLawrence Mitchell PetscFunctionBegin; 696f572501eSLawrence Mitchell PetscValidHeaderSpecific(dm,DM_CLASSID,1); 697f572501eSLawrence Mitchell ierr = PetscObjectTypeCompare((PetscObject)dm,DMSHELL,&isshell);CHKERRQ(ierr); 698f572501eSLawrence Mitchell if (!isshell) PetscFunctionReturn(0); 699f572501eSLawrence Mitchell dm->ops->coarsen = coarsen; 700f572501eSLawrence Mitchell PetscFunctionReturn(0); 701f572501eSLawrence Mitchell } 702f572501eSLawrence Mitchell 703f572501eSLawrence Mitchell #undef __FUNCT__ 704f572501eSLawrence Mitchell #define __FUNCT__ "DMShellSetRefine" 7059bf9660cSLawrence Mitchell /*@C 7069bf9660cSLawrence Mitchell DMShellSetRefine - Set the routine used to refine the shell DM 7079bf9660cSLawrence Mitchell 7089bf9660cSLawrence Mitchell Logically Collective on DM 7099bf9660cSLawrence Mitchell 7109bf9660cSLawrence Mitchell Input Arguments 7119bf9660cSLawrence Mitchell + dm - the shell DM 7129bf9660cSLawrence Mitchell - refine - the routine that refines the DM 7139bf9660cSLawrence Mitchell 7149bf9660cSLawrence Mitchell Level: advanced 7159bf9660cSLawrence Mitchell 716*fef3a512SBarry Smith .seealso: DMShellSetCoarsen(), DMRefine(), DMShellSetContext(), DMShellGetContext() 7179bf9660cSLawrence Mitchell @*/ 718f572501eSLawrence Mitchell PetscErrorCode DMShellSetRefine(DM dm, PetscErrorCode (*refine)(DM,MPI_Comm,DM*)) 719f572501eSLawrence Mitchell { 720f572501eSLawrence Mitchell PetscErrorCode ierr; 721f572501eSLawrence Mitchell PetscBool isshell; 722f572501eSLawrence Mitchell 723f572501eSLawrence Mitchell PetscFunctionBegin; 724f572501eSLawrence Mitchell PetscValidHeaderSpecific(dm,DM_CLASSID,1); 725f572501eSLawrence Mitchell ierr = PetscObjectTypeCompare((PetscObject)dm,DMSHELL,&isshell);CHKERRQ(ierr); 726f572501eSLawrence Mitchell if (!isshell) PetscFunctionReturn(0); 727f572501eSLawrence Mitchell dm->ops->refine = refine; 728f572501eSLawrence Mitchell PetscFunctionReturn(0); 729f572501eSLawrence Mitchell } 730f572501eSLawrence Mitchell 731f572501eSLawrence Mitchell #undef __FUNCT__ 732f572501eSLawrence Mitchell #define __FUNCT__ "DMShellSetCreateInterpolation" 7339bf9660cSLawrence Mitchell /*@C 7349bf9660cSLawrence Mitchell DMShellSetCreateInterpolation - Set the routine used to create the interpolation operator 7359bf9660cSLawrence Mitchell 7369bf9660cSLawrence Mitchell Logically Collective on DM 7379bf9660cSLawrence Mitchell 7389bf9660cSLawrence Mitchell Input Arguments 7399bf9660cSLawrence Mitchell + dm - the shell DM 7409bf9660cSLawrence Mitchell - interp - the routine to create the interpolation 7419bf9660cSLawrence Mitchell 7429bf9660cSLawrence Mitchell Level: advanced 7439bf9660cSLawrence Mitchell 744*fef3a512SBarry Smith .seealso: DMShellSetCreateInjection(), DMCreateInterpolation(), DMShellSetCreateRestriction(), DMShellSetContext(), DMShellGetContext() 7459bf9660cSLawrence Mitchell @*/ 746f572501eSLawrence Mitchell PetscErrorCode DMShellSetCreateInterpolation(DM dm, PetscErrorCode (*interp)(DM,DM,Mat*,Vec*)) 747f572501eSLawrence Mitchell { 748f572501eSLawrence Mitchell PetscErrorCode ierr; 749f572501eSLawrence Mitchell PetscBool isshell; 750f572501eSLawrence Mitchell 751f572501eSLawrence Mitchell PetscFunctionBegin; 752f572501eSLawrence Mitchell PetscValidHeaderSpecific(dm,DM_CLASSID,1); 753f572501eSLawrence Mitchell ierr = PetscObjectTypeCompare((PetscObject)dm,DMSHELL,&isshell);CHKERRQ(ierr); 754f572501eSLawrence Mitchell if (!isshell) PetscFunctionReturn(0); 755f572501eSLawrence Mitchell dm->ops->createinterpolation = interp; 756f572501eSLawrence Mitchell PetscFunctionReturn(0); 757f572501eSLawrence Mitchell } 758f572501eSLawrence Mitchell 759f572501eSLawrence Mitchell #undef __FUNCT__ 7603ad4599aSBarry Smith #define __FUNCT__ "DMShellSetCreateRestriction" 7613ad4599aSBarry Smith /*@C 7623ad4599aSBarry Smith DMShellSetCreateRestriction - Set the routine used to create the restriction operator 7633ad4599aSBarry Smith 7643ad4599aSBarry Smith Logically Collective on DM 7653ad4599aSBarry Smith 7663ad4599aSBarry Smith Input Arguments 7673ad4599aSBarry Smith + dm - the shell DM 7683ad4599aSBarry Smith - striction- the routine to create the restriction 7693ad4599aSBarry Smith 7703ad4599aSBarry Smith Level: advanced 7713ad4599aSBarry Smith 772*fef3a512SBarry Smith .seealso: DMShellSetCreateInjection(), DMCreateInterpolation(), DMShellSetContext(), DMShellGetContext() 7733ad4599aSBarry Smith @*/ 7743ad4599aSBarry Smith PetscErrorCode DMShellSetCreateRestriction(DM dm, PetscErrorCode (*restriction)(DM,DM,Mat*)) 7753ad4599aSBarry Smith { 7763ad4599aSBarry Smith PetscErrorCode ierr; 7773ad4599aSBarry Smith PetscBool isshell; 7783ad4599aSBarry Smith 7793ad4599aSBarry Smith PetscFunctionBegin; 7803ad4599aSBarry Smith PetscValidHeaderSpecific(dm,DM_CLASSID,1); 7813ad4599aSBarry Smith ierr = PetscObjectTypeCompare((PetscObject)dm,DMSHELL,&isshell);CHKERRQ(ierr); 7823ad4599aSBarry Smith if (!isshell) PetscFunctionReturn(0); 7833ad4599aSBarry Smith dm->ops->createrestriction = restriction; 7843ad4599aSBarry Smith PetscFunctionReturn(0); 7853ad4599aSBarry Smith } 7863ad4599aSBarry Smith 7873ad4599aSBarry Smith #undef __FUNCT__ 788f572501eSLawrence Mitchell #define __FUNCT__ "DMShellSetCreateInjection" 7899bf9660cSLawrence Mitchell /*@C 7909bf9660cSLawrence Mitchell DMShellSetCreateInjection - Set the routine used to create the injection operator 7919bf9660cSLawrence Mitchell 7929bf9660cSLawrence Mitchell Logically Collective on DM 7939bf9660cSLawrence Mitchell 7949bf9660cSLawrence Mitchell Input Arguments 7959bf9660cSLawrence Mitchell + dm - the shell DM 7969bf9660cSLawrence Mitchell - inject - the routine to create the injection 7979bf9660cSLawrence Mitchell 7989bf9660cSLawrence Mitchell Level: advanced 7999bf9660cSLawrence Mitchell 800*fef3a512SBarry Smith .seealso: DMShellSetCreateInterpolation(), DMCreateInjection(), DMShellSetContext(), DMShellGetContext() 8019bf9660cSLawrence Mitchell @*/ 802f572501eSLawrence Mitchell PetscErrorCode DMShellSetCreateInjection(DM dm, PetscErrorCode (*inject)(DM,DM,Mat*)) 803f572501eSLawrence Mitchell { 804f572501eSLawrence Mitchell PetscErrorCode ierr; 805f572501eSLawrence Mitchell PetscBool isshell; 806f572501eSLawrence Mitchell 807f572501eSLawrence Mitchell PetscFunctionBegin; 808f572501eSLawrence Mitchell PetscValidHeaderSpecific(dm,DM_CLASSID,1); 809f572501eSLawrence Mitchell ierr = PetscObjectTypeCompare((PetscObject)dm,DMSHELL,&isshell);CHKERRQ(ierr); 810f572501eSLawrence Mitchell if (!isshell) PetscFunctionReturn(0); 811f572501eSLawrence Mitchell dm->ops->getinjection = inject; 812f572501eSLawrence Mitchell PetscFunctionReturn(0); 813f572501eSLawrence Mitchell } 814f572501eSLawrence Mitchell 815f572501eSLawrence Mitchell #undef __FUNCT__ 8165e2259d5SLawrence Mitchell #define __FUNCT__ "DMShellSetCreateFieldDecomposition" 8179bf9660cSLawrence Mitchell /*@C 8189bf9660cSLawrence Mitchell DMShellSetCreateFieldDecomposition - Set the routine used to create a decomposition of fields for the shell DM 8199bf9660cSLawrence Mitchell 8209bf9660cSLawrence Mitchell Logically Collective on DM 8219bf9660cSLawrence Mitchell 8229bf9660cSLawrence Mitchell Input Arguments 8239bf9660cSLawrence Mitchell + dm - the shell DM 8249bf9660cSLawrence Mitchell - decomp - the routine to create the decomposition 8259bf9660cSLawrence Mitchell 8269bf9660cSLawrence Mitchell Level: advanced 8279bf9660cSLawrence Mitchell 828*fef3a512SBarry Smith .seealso: DMCreateFieldDecomposition(), DMShellSetContext(), DMShellGetContext() 8299bf9660cSLawrence Mitchell @*/ 8305e2259d5SLawrence Mitchell PetscErrorCode DMShellSetCreateFieldDecomposition(DM dm, PetscErrorCode (*decomp)(DM,PetscInt*,char***, IS**,DM**)) 8315e2259d5SLawrence Mitchell { 8325e2259d5SLawrence Mitchell PetscErrorCode ierr; 8335e2259d5SLawrence Mitchell PetscBool isshell; 8345e2259d5SLawrence Mitchell 8355e2259d5SLawrence Mitchell PetscFunctionBegin; 8365e2259d5SLawrence Mitchell PetscValidHeaderSpecific(dm,DM_CLASSID,1); 8375e2259d5SLawrence Mitchell ierr = PetscObjectTypeCompare((PetscObject)dm,DMSHELL,&isshell);CHKERRQ(ierr); 8385e2259d5SLawrence Mitchell if (!isshell) PetscFunctionReturn(0); 8395e2259d5SLawrence Mitchell dm->ops->createfielddecomposition = decomp; 8405e2259d5SLawrence Mitchell PetscFunctionReturn(0); 8415e2259d5SLawrence Mitchell } 8425e2259d5SLawrence Mitchell 843c00061e5SLawrence Mitchell /*@C 844c00061e5SLawrence Mitchell DMShellSetCreateSubDM - Set the routine used to create a sub DM from the shell DM 845c00061e5SLawrence Mitchell 846c00061e5SLawrence Mitchell Logically Collective on DM 847c00061e5SLawrence Mitchell 848c00061e5SLawrence Mitchell Input Arguments 849c00061e5SLawrence Mitchell + dm - the shell DM 850c00061e5SLawrence Mitchell - subdm - the routine to create the decomposition 851c00061e5SLawrence Mitchell 852c00061e5SLawrence Mitchell Level: advanced 853c00061e5SLawrence Mitchell 854*fef3a512SBarry Smith .seealso: DMCreateSubDM(), DMShellSetContext(), DMShellGetContext() 855c00061e5SLawrence Mitchell @*/ 856c00061e5SLawrence Mitchell #undef __FUNCT__ 857c00061e5SLawrence Mitchell #define __FUNCT__ "DMShellSetCreateSubDM" 858c00061e5SLawrence Mitchell PetscErrorCode DMShellSetCreateSubDM(DM dm, PetscErrorCode (*subdm)(DM,PetscInt,PetscInt[],IS*,DM*)) 859c00061e5SLawrence Mitchell { 860c00061e5SLawrence Mitchell PetscErrorCode ierr; 861c00061e5SLawrence Mitchell PetscBool isshell; 862c00061e5SLawrence Mitchell 863c00061e5SLawrence Mitchell PetscFunctionBegin; 864c00061e5SLawrence Mitchell PetscValidHeaderSpecific(dm,DM_CLASSID,1); 865c00061e5SLawrence Mitchell ierr = PetscObjectTypeCompare((PetscObject)dm,DMSHELL,&isshell);CHKERRQ(ierr); 866c00061e5SLawrence Mitchell if (!isshell) PetscFunctionReturn(0); 867c00061e5SLawrence Mitchell dm->ops->createsubdm = subdm; 868c00061e5SLawrence Mitchell PetscFunctionReturn(0); 869c00061e5SLawrence Mitchell } 870c00061e5SLawrence Mitchell 8715e2259d5SLawrence Mitchell #undef __FUNCT__ 872fe1899a2SJed Brown #define __FUNCT__ "DMDestroy_Shell" 873fe1899a2SJed Brown static PetscErrorCode DMDestroy_Shell(DM dm) 874fe1899a2SJed Brown { 875fe1899a2SJed Brown PetscErrorCode ierr; 876fe1899a2SJed Brown DM_Shell *shell = (DM_Shell*)dm->data; 877fe1899a2SJed Brown 878fe1899a2SJed Brown PetscFunctionBegin; 879fe1899a2SJed Brown ierr = MatDestroy(&shell->A);CHKERRQ(ierr); 880fe1899a2SJed Brown ierr = VecDestroy(&shell->Xglobal);CHKERRQ(ierr); 881dc43b69eSJed Brown ierr = VecDestroy(&shell->Xlocal);CHKERRQ(ierr); 882a94b16f6SRichard Tran Mills ierr = VecScatterDestroy(&shell->gtol);CHKERRQ(ierr); 883a94b16f6SRichard Tran Mills ierr = VecScatterDestroy(&shell->ltog);CHKERRQ(ierr); 884294a6417SLawrence Mitchell ierr = VecScatterDestroy(&shell->ltol);CHKERRQ(ierr); 8857b6ad80cSMatthew G Knepley /* This was originally freed in DMDestroy(), but that prevents reference counting of backend objects */ 8867b6ad80cSMatthew G Knepley ierr = PetscFree(shell);CHKERRQ(ierr); 887fe1899a2SJed Brown PetscFunctionReturn(0); 888fe1899a2SJed Brown } 889fe1899a2SJed Brown 8902d53ad75SBarry Smith #undef __FUNCT__ 8912d53ad75SBarry Smith #define __FUNCT__ "DMView_Shell" 8922d53ad75SBarry Smith static PetscErrorCode DMView_Shell(DM dm,PetscViewer v) 8932d53ad75SBarry Smith { 8942d53ad75SBarry Smith PetscErrorCode ierr; 8952d53ad75SBarry Smith DM_Shell *shell = (DM_Shell*)dm->data; 8962d53ad75SBarry Smith 8972d53ad75SBarry Smith PetscFunctionBegin; 8982d53ad75SBarry Smith ierr = VecView(shell->Xglobal,v);CHKERRQ(ierr); 8992d53ad75SBarry Smith PetscFunctionReturn(0); 9002d53ad75SBarry Smith } 9012d53ad75SBarry Smith 9022d53ad75SBarry Smith #undef __FUNCT__ 9032d53ad75SBarry Smith #define __FUNCT__ "DMLoad_Shell" 9042d53ad75SBarry Smith static PetscErrorCode DMLoad_Shell(DM dm,PetscViewer v) 9052d53ad75SBarry Smith { 9062d53ad75SBarry Smith PetscErrorCode ierr; 9072d53ad75SBarry Smith DM_Shell *shell = (DM_Shell*)dm->data; 9082d53ad75SBarry Smith 9092d53ad75SBarry Smith PetscFunctionBegin; 910ce94432eSBarry Smith ierr = VecCreate(PetscObjectComm((PetscObject)dm),&shell->Xglobal);CHKERRQ(ierr); 9112d53ad75SBarry Smith ierr = VecLoad(shell->Xglobal,v);CHKERRQ(ierr); 9122d53ad75SBarry Smith PetscFunctionReturn(0); 9132d53ad75SBarry Smith } 914fe1899a2SJed Brown 915fe1899a2SJed Brown #undef __FUNCT__ 9166e44b4cfSMatthew G. Knepley #define __FUNCT__ "DMCreateSubDM_Shell" 9176e44b4cfSMatthew G. Knepley PetscErrorCode DMCreateSubDM_Shell(DM dm, PetscInt numFields, PetscInt fields[], IS *is, DM *subdm) 9186e44b4cfSMatthew G. Knepley { 9196e44b4cfSMatthew G. Knepley PetscErrorCode ierr; 9206e44b4cfSMatthew G. Knepley 9216e44b4cfSMatthew G. Knepley PetscFunctionBegin; 9226e44b4cfSMatthew G. Knepley if (subdm) {ierr = DMShellCreate(PetscObjectComm((PetscObject) dm), subdm);CHKERRQ(ierr);} 9236e44b4cfSMatthew G. Knepley ierr = DMCreateSubDM_Section_Private(dm, numFields, fields, is, subdm);CHKERRQ(ierr); 9246e44b4cfSMatthew G. Knepley PetscFunctionReturn(0); 9256e44b4cfSMatthew G. Knepley } 9266e44b4cfSMatthew G. Knepley 9276e44b4cfSMatthew G. Knepley #undef __FUNCT__ 928fe1899a2SJed Brown #define __FUNCT__ "DMCreate_Shell" 9298cc058d9SJed Brown PETSC_EXTERN PetscErrorCode DMCreate_Shell(DM dm) 930fe1899a2SJed Brown { 931fe1899a2SJed Brown PetscErrorCode ierr; 932fe1899a2SJed Brown DM_Shell *shell; 933fe1899a2SJed Brown 934fe1899a2SJed Brown PetscFunctionBegin; 935b00a9115SJed Brown ierr = PetscNewLog(dm,&shell);CHKERRQ(ierr); 9368c87107bSJed Brown dm->data = shell; 937fe1899a2SJed Brown 9388c87107bSJed Brown ierr = PetscObjectChangeTypeName((PetscObject)dm,DMSHELL);CHKERRQ(ierr); 9398865f1eaSKarl Rupp 9408c87107bSJed Brown dm->ops->destroy = DMDestroy_Shell; 9418c87107bSJed Brown dm->ops->createglobalvector = DMCreateGlobalVector_Shell; 942dc43b69eSJed Brown dm->ops->createlocalvector = DMCreateLocalVector_Shell; 9438c87107bSJed Brown dm->ops->creatematrix = DMCreateMatrix_Shell; 9442d53ad75SBarry Smith dm->ops->view = DMView_Shell; 9452d53ad75SBarry Smith dm->ops->load = DMLoad_Shell; 9467a108d1dSBarry Smith dm->ops->globaltolocalbegin = DMGlobalToLocalBeginDefaultShell; 9477a108d1dSBarry Smith dm->ops->globaltolocalend = DMGlobalToLocalEndDefaultShell; 94855daaa54SRichard Tran Mills dm->ops->localtoglobalbegin = DMLocalToGlobalBeginDefaultShell; 94955daaa54SRichard Tran Mills dm->ops->localtoglobalend = DMLocalToGlobalEndDefaultShell; 95063731094SRichard Tran Mills dm->ops->localtolocalbegin = DMLocalToLocalBeginDefaultShell; 95163731094SRichard Tran Mills dm->ops->localtolocalend = DMLocalToLocalEndDefaultShell; 9526e44b4cfSMatthew G. Knepley dm->ops->createsubdm = DMCreateSubDM_Shell; 953fe1899a2SJed Brown PetscFunctionReturn(0); 954fe1899a2SJed Brown } 955fe1899a2SJed Brown 956fe1899a2SJed Brown #undef __FUNCT__ 957fe1899a2SJed Brown #define __FUNCT__ "DMShellCreate" 958fe1899a2SJed Brown /*@ 959fe1899a2SJed Brown DMShellCreate - Creates a shell DM object, used to manage user-defined problem data 960fe1899a2SJed Brown 961fe1899a2SJed Brown Collective on MPI_Comm 962fe1899a2SJed Brown 963fe1899a2SJed Brown Input Parameter: 964fe1899a2SJed Brown . comm - the processors that will share the global vector 965fe1899a2SJed Brown 966fe1899a2SJed Brown Output Parameters: 967fe1899a2SJed Brown . shell - the shell DM 968fe1899a2SJed Brown 969fe1899a2SJed Brown Level: advanced 970fe1899a2SJed Brown 971*fef3a512SBarry Smith .seealso DMDestroy(), DMCreateGlobalVector(), DMCreateLocalVector(), DMShellSetContext(), DMShellGetContext() 972fe1899a2SJed Brown @*/ 973fe1899a2SJed Brown PetscErrorCode DMShellCreate(MPI_Comm comm,DM *dm) 974fe1899a2SJed Brown { 975fe1899a2SJed Brown PetscErrorCode ierr; 976fe1899a2SJed Brown 977fe1899a2SJed Brown PetscFunctionBegin; 978fe1899a2SJed Brown PetscValidPointer(dm,2); 979fe1899a2SJed Brown ierr = DMCreate(comm,dm);CHKERRQ(ierr); 980fe1899a2SJed Brown ierr = DMSetType(*dm,DMSHELL);CHKERRQ(ierr); 98181a566bfSMatthew G. Knepley ierr = DMSetUp(*dm);CHKERRQ(ierr); 982fe1899a2SJed Brown PetscFunctionReturn(0); 983fe1899a2SJed Brown } 98481634712SRichard Tran Mills 985