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; 12fef3a512SBarry 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__ 286fef3a512SBarry Smith #define __FUNCT__ "DMShellSetContext" 287fef3a512SBarry Smith /*@ 288fef3a512SBarry Smith DMShellSetContext - set some data to be usable by this DM 289fef3a512SBarry Smith 290fef3a512SBarry Smith Collective 291fef3a512SBarry Smith 292fef3a512SBarry Smith Input Arguments: 293fef3a512SBarry Smith + dm - shell DM 294fef3a512SBarry Smith - ctx - the context 295fef3a512SBarry Smith 296fef3a512SBarry Smith Level: advanced 297fef3a512SBarry Smith 298fef3a512SBarry Smith .seealso: DMCreateMatrix(), DMShellGetContext() 299fef3a512SBarry Smith @*/ 300fef3a512SBarry Smith PetscErrorCode DMShellSetContext(DM dm,void *ctx) 301fef3a512SBarry Smith { 302fef3a512SBarry Smith DM_Shell *shell = (DM_Shell*)dm->data; 303fef3a512SBarry Smith PetscErrorCode ierr; 304fef3a512SBarry Smith PetscBool isshell; 305fef3a512SBarry Smith 306fef3a512SBarry Smith PetscFunctionBegin; 307fef3a512SBarry Smith PetscValidHeaderSpecific(dm,DM_CLASSID,1); 308fef3a512SBarry Smith ierr = PetscObjectTypeCompare((PetscObject)dm,DMSHELL,&isshell);CHKERRQ(ierr); 309fef3a512SBarry Smith if (!isshell) PetscFunctionReturn(0); 310fef3a512SBarry Smith shell->ctx = ctx; 311fef3a512SBarry Smith PetscFunctionReturn(0); 312fef3a512SBarry Smith } 313fef3a512SBarry Smith 314fef3a512SBarry Smith #undef __FUNCT__ 315fef3a512SBarry Smith #define __FUNCT__ "DMShellGetContext" 316fef3a512SBarry Smith /*@ 317fef3a512SBarry Smith DMShellGetContext - set some data to be usable by this DM 318fef3a512SBarry Smith 319fef3a512SBarry Smith Collective 320fef3a512SBarry Smith 321fef3a512SBarry Smith Input Argument: 322fef3a512SBarry Smith . dm - shell DM 323fef3a512SBarry Smith 324fef3a512SBarry Smith Output Argument: 325fef3a512SBarry Smith . ctx - the context 326fef3a512SBarry Smith 327fef3a512SBarry Smith Level: advanced 328fef3a512SBarry Smith 329fef3a512SBarry Smith .seealso: DMCreateMatrix(), DMShellSetContext() 330fef3a512SBarry Smith @*/ 331fef3a512SBarry Smith PetscErrorCode DMShellGetContext(DM dm,void **ctx) 332fef3a512SBarry Smith { 333fef3a512SBarry Smith DM_Shell *shell = (DM_Shell*)dm->data; 334fef3a512SBarry Smith PetscErrorCode ierr; 335fef3a512SBarry Smith PetscBool isshell; 336fef3a512SBarry Smith 337fef3a512SBarry Smith PetscFunctionBegin; 338fef3a512SBarry Smith PetscValidHeaderSpecific(dm,DM_CLASSID,1); 339fef3a512SBarry Smith ierr = PetscObjectTypeCompare((PetscObject)dm,DMSHELL,&isshell);CHKERRQ(ierr); 340fef3a512SBarry Smith if (!isshell) PetscFunctionReturn(0); 341fef3a512SBarry Smith *ctx = shell->ctx; 342fef3a512SBarry Smith PetscFunctionReturn(0); 343fef3a512SBarry Smith } 344fef3a512SBarry Smith 345fef3a512SBarry 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 358fef3a512SBarry 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 390fef3a512SBarry 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; 421*cca7ec1eSBarry Smith DM vdm; 422fe1899a2SJed Brown 423fe1899a2SJed Brown PetscFunctionBegin; 4248c87107bSJed Brown PetscValidHeaderSpecific(dm,DM_CLASSID,1); 4258c87107bSJed Brown PetscValidHeaderSpecific(X,VEC_CLASSID,2); 426251f4c67SDmitry Karpeev ierr = PetscObjectTypeCompare((PetscObject)dm,DMSHELL,&isshell);CHKERRQ(ierr); 4278c87107bSJed Brown if (!isshell) PetscFunctionReturn(0); 428*cca7ec1eSBarry Smith ierr = VecGetDM(X,&vdm);CHKERRQ(ierr); 429*cca7ec1eSBarry Smith /* 430*cca7ec1eSBarry Smith if the vector proposed as the new base global vector for the DM is a DM vector associated 431*cca7ec1eSBarry Smith with the same DM then the current base global vector for the DM is ok and if we replace it with the new one 432*cca7ec1eSBarry Smith we get a circular dependency that prevents the DM from being destroy when it should be. 433*cca7ec1eSBarry Smith This occurs when SNESSet/GetNPC() is used with a SNES that does not have a user provided 434*cca7ec1eSBarry Smith DM attached to it since the inner SNES (which shares the DM with the outer SNES) tries 435*cca7ec1eSBarry Smith to set its input vector (which is associated with the DM) as the base global vector. 436*cca7ec1eSBarry Smith Thanks to Juan P. Mendez Granado Re: [petsc-maint] Nonlinear conjugate gradien 437*cca7ec1eSBarry Smith for pointing out the problem. 438*cca7ec1eSBarry Smith */ 439*cca7ec1eSBarry Smith if (vdm == dm) PetscFunctionReturn(0); 440fe1899a2SJed Brown ierr = PetscObjectReference((PetscObject)X);CHKERRQ(ierr); 441fe1899a2SJed Brown ierr = VecDestroy(&shell->Xglobal);CHKERRQ(ierr); 442fe1899a2SJed Brown shell->Xglobal = X; 443fe1899a2SJed Brown PetscFunctionReturn(0); 444fe1899a2SJed Brown } 445fe1899a2SJed Brown 446fe1899a2SJed Brown #undef __FUNCT__ 447fe1899a2SJed Brown #define __FUNCT__ "DMShellSetCreateGlobalVector" 448fe1899a2SJed Brown /*@C 449fe1899a2SJed Brown DMShellSetCreateGlobalVector - sets the routine to create a global vector associated with the shell DM 450fe1899a2SJed Brown 451fe1899a2SJed Brown Logically Collective 452fe1899a2SJed Brown 453fe1899a2SJed Brown Input Arguments: 454fe1899a2SJed Brown + dm - the shell DM 455fe1899a2SJed Brown - func - the creation routine 456fe1899a2SJed Brown 457fe1899a2SJed Brown Level: advanced 458fe1899a2SJed Brown 459fef3a512SBarry Smith .seealso: DMShellSetGlobalVector(), DMShellSetCreateMatrix(), DMShellSetContext(), DMShellGetContext() 460fe1899a2SJed Brown @*/ 461fe1899a2SJed Brown PetscErrorCode DMShellSetCreateGlobalVector(DM dm,PetscErrorCode (*func)(DM,Vec*)) 462fe1899a2SJed Brown { 463fe1899a2SJed Brown 464fe1899a2SJed Brown PetscFunctionBegin; 465fe1899a2SJed Brown PetscValidHeaderSpecific(dm,DM_CLASSID,1); 466fe1899a2SJed Brown dm->ops->createglobalvector = func; 467fe1899a2SJed Brown PetscFunctionReturn(0); 468fe1899a2SJed Brown } 469fe1899a2SJed Brown 470fe1899a2SJed Brown #undef __FUNCT__ 471dc43b69eSJed Brown #define __FUNCT__ "DMShellSetLocalVector" 472dc43b69eSJed Brown /*@ 473dc43b69eSJed Brown DMShellSetLocalVector - sets a template local vector associated with the DMShell 474dc43b69eSJed Brown 475dc43b69eSJed Brown Logically Collective on DM 476dc43b69eSJed Brown 477dc43b69eSJed Brown Input Arguments: 478dc43b69eSJed Brown + dm - shell DM 479dc43b69eSJed Brown - X - template vector 480dc43b69eSJed Brown 481dc43b69eSJed Brown Level: advanced 482dc43b69eSJed Brown 483dc43b69eSJed Brown .seealso: DMCreateLocalVector(), DMShellSetMatrix(), DMShellSetCreateLocalVector() 484dc43b69eSJed Brown @*/ 485dc43b69eSJed Brown PetscErrorCode DMShellSetLocalVector(DM dm,Vec X) 486dc43b69eSJed Brown { 487dc43b69eSJed Brown DM_Shell *shell = (DM_Shell*)dm->data; 488dc43b69eSJed Brown PetscErrorCode ierr; 489dc43b69eSJed Brown PetscBool isshell; 490*cca7ec1eSBarry Smith DM vdm; 491dc43b69eSJed Brown 492dc43b69eSJed Brown PetscFunctionBegin; 493dc43b69eSJed Brown PetscValidHeaderSpecific(dm,DM_CLASSID,1); 494dc43b69eSJed Brown PetscValidHeaderSpecific(X,VEC_CLASSID,2); 495dc43b69eSJed Brown ierr = PetscObjectTypeCompare((PetscObject)dm,DMSHELL,&isshell);CHKERRQ(ierr); 496dc43b69eSJed Brown if (!isshell) PetscFunctionReturn(0); 497*cca7ec1eSBarry Smith ierr = VecGetDM(X,&vdm);CHKERRQ(ierr); 498*cca7ec1eSBarry Smith /* 499*cca7ec1eSBarry Smith if the vector proposed as the new base global vector for the DM is a DM vector associated 500*cca7ec1eSBarry Smith with the same DM then the current base global vector for the DM is ok and if we replace it with the new one 501*cca7ec1eSBarry Smith we get a circular dependency that prevents the DM from being destroy when it should be. 502*cca7ec1eSBarry Smith This occurs when SNESSet/GetNPC() is used with a SNES that does not have a user provided 503*cca7ec1eSBarry Smith DM attached to it since the inner SNES (which shares the DM with the outer SNES) tries 504*cca7ec1eSBarry Smith to set its input vector (which is associated with the DM) as the base global vector. 505*cca7ec1eSBarry Smith Thanks to Juan P. Mendez Granado Re: [petsc-maint] Nonlinear conjugate gradien 506*cca7ec1eSBarry Smith for pointing out the problem. 507*cca7ec1eSBarry Smith */ 508*cca7ec1eSBarry Smith if (vdm == dm) PetscFunctionReturn(0); 509dc43b69eSJed Brown ierr = PetscObjectReference((PetscObject)X);CHKERRQ(ierr); 510dc43b69eSJed Brown ierr = VecDestroy(&shell->Xlocal);CHKERRQ(ierr); 511dc43b69eSJed Brown shell->Xlocal = X; 512dc43b69eSJed Brown PetscFunctionReturn(0); 513dc43b69eSJed Brown } 514dc43b69eSJed Brown 515dc43b69eSJed Brown #undef __FUNCT__ 516dc43b69eSJed Brown #define __FUNCT__ "DMShellSetCreateLocalVector" 517dc43b69eSJed Brown /*@C 518dc43b69eSJed Brown DMShellSetCreateLocalVector - sets the routine to create a local vector associated with the shell DM 519dc43b69eSJed Brown 520dc43b69eSJed Brown Logically Collective 521dc43b69eSJed Brown 522dc43b69eSJed Brown Input Arguments: 523dc43b69eSJed Brown + dm - the shell DM 524dc43b69eSJed Brown - func - the creation routine 525dc43b69eSJed Brown 526dc43b69eSJed Brown Level: advanced 527dc43b69eSJed Brown 528fef3a512SBarry Smith .seealso: DMShellSetLocalVector(), DMShellSetCreateMatrix(), DMShellSetContext(), DMShellGetContext() 529dc43b69eSJed Brown @*/ 530dc43b69eSJed Brown PetscErrorCode DMShellSetCreateLocalVector(DM dm,PetscErrorCode (*func)(DM,Vec*)) 531dc43b69eSJed Brown { 532dc43b69eSJed Brown 533dc43b69eSJed Brown PetscFunctionBegin; 534dc43b69eSJed Brown PetscValidHeaderSpecific(dm,DM_CLASSID,1); 535dc43b69eSJed Brown dm->ops->createlocalvector = func; 536dc43b69eSJed Brown PetscFunctionReturn(0); 537dc43b69eSJed Brown } 538dc43b69eSJed Brown 539dc43b69eSJed Brown #undef __FUNCT__ 5408339e6d0SRichard Tran Mills #define __FUNCT__ "DMShellSetGlobalToLocal" 5418339e6d0SRichard Tran Mills /*@C 5428339e6d0SRichard Tran Mills DMShellSetGlobalToLocal - Sets the routines used to perform a global to local 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 global to local scatter 5498339e6d0SRichard Tran Mills - end - the routine that ends the global to local scatter 5508339e6d0SRichard Tran Mills 5517a108d1dSBarry Smith Notes: If these functions are not provided but DMShellSetGlobalToLocalVecScatter() is called then 552f3db62a7SRichard Tran Mills DMGlobalToLocalBeginDefaultShell()/DMGlobalToLocalEndDefaultShell() are used to to perform the transfers 5537a108d1dSBarry Smith 5548339e6d0SRichard Tran Mills Level: advanced 5558339e6d0SRichard Tran Mills 5567a108d1dSBarry Smith .seealso: DMShellSetLocalToGlobal(), DMGlobalToLocalBeginDefaultShell(), DMGlobalToLocalEndDefaultShell() 5578339e6d0SRichard Tran Mills @*/ 5588339e6d0SRichard Tran Mills PetscErrorCode DMShellSetGlobalToLocal(DM dm,PetscErrorCode (*begin)(DM,Vec,InsertMode,Vec),PetscErrorCode (*end)(DM,Vec,InsertMode,Vec)) { 5598339e6d0SRichard Tran Mills PetscFunctionBegin; 5608339e6d0SRichard Tran Mills dm->ops->globaltolocalbegin = begin; 5618339e6d0SRichard Tran Mills dm->ops->globaltolocalend = end; 5628339e6d0SRichard Tran Mills PetscFunctionReturn(0); 5638339e6d0SRichard Tran Mills } 5648339e6d0SRichard Tran Mills 5658339e6d0SRichard Tran Mills #undef __FUNCT__ 5668339e6d0SRichard Tran Mills #define __FUNCT__ "DMShellSetLocalToGlobal" 5678339e6d0SRichard Tran Mills /*@C 5688339e6d0SRichard Tran Mills DMShellSetLocalToGlobal - Sets the routines used to perform a local to global scatter 5698339e6d0SRichard Tran Mills 5708339e6d0SRichard Tran Mills Logically Collective on DM 5718339e6d0SRichard Tran Mills 5728339e6d0SRichard Tran Mills Input Arguments 5738339e6d0SRichard Tran Mills + dm - the shell DM 5748339e6d0SRichard Tran Mills . begin - the routine that begins the local to global scatter 5758339e6d0SRichard Tran Mills - end - the routine that ends the local to global scatter 5768339e6d0SRichard Tran Mills 577f3db62a7SRichard Tran Mills Notes: If these functions are not provided but DMShellSetLocalToGlobalVecScatter() is called then 578f3db62a7SRichard Tran Mills DMLocalToGlobalBeginDefaultShell()/DMLocalToGlobalEndDefaultShell() are used to to perform the transfers 579f3db62a7SRichard Tran Mills 5808339e6d0SRichard Tran Mills Level: advanced 5818339e6d0SRichard Tran Mills 5828339e6d0SRichard Tran Mills .seealso: DMShellSetGlobalToLocal() 5838339e6d0SRichard Tran Mills @*/ 5848339e6d0SRichard Tran Mills PetscErrorCode DMShellSetLocalToGlobal(DM dm,PetscErrorCode (*begin)(DM,Vec,InsertMode,Vec),PetscErrorCode (*end)(DM,Vec,InsertMode,Vec)) { 5858339e6d0SRichard Tran Mills PetscFunctionBegin; 5868339e6d0SRichard Tran Mills dm->ops->localtoglobalbegin = begin; 5878339e6d0SRichard Tran Mills dm->ops->localtoglobalend = end; 5888339e6d0SRichard Tran Mills PetscFunctionReturn(0); 5898339e6d0SRichard Tran Mills } 5908339e6d0SRichard Tran Mills 5918339e6d0SRichard Tran Mills #undef __FUNCT__ 592f3db62a7SRichard Tran Mills #define __FUNCT__ "DMShellSetLocalToLocal" 593f3db62a7SRichard Tran Mills /*@C 594f3db62a7SRichard Tran Mills DMShellSetLocalToLocal - Sets the routines used to perform a local to local scatter 595f3db62a7SRichard Tran Mills 596f3db62a7SRichard Tran Mills Logically Collective on DM 597f3db62a7SRichard Tran Mills 598f3db62a7SRichard Tran Mills Input Arguments 599f3db62a7SRichard Tran Mills + dm - the shell DM 600f3db62a7SRichard Tran Mills . begin - the routine that begins the local to local scatter 601f3db62a7SRichard Tran Mills - end - the routine that ends the local to local scatter 602f3db62a7SRichard Tran Mills 603f3db62a7SRichard Tran Mills Notes: If these functions are not provided but DMShellSetLocalToLocalVecScatter() is called then 604f3db62a7SRichard Tran Mills DMLocalToLocalBeginDefaultShell()/DMLocalToLocalEndDefaultShell() are used to to perform the transfers 605f3db62a7SRichard Tran Mills 606f3db62a7SRichard Tran Mills Level: advanced 607f3db62a7SRichard Tran Mills 608f3db62a7SRichard Tran Mills .seealso: DMShellSetGlobalToLocal(), DMLocalToLocalBeginDefaultShell(), DMLocalToLocalEndDefaultShell() 609f3db62a7SRichard Tran Mills @*/ 610f3db62a7SRichard Tran Mills PetscErrorCode DMShellSetLocalToLocal(DM dm,PetscErrorCode (*begin)(DM,Vec,InsertMode,Vec),PetscErrorCode (*end)(DM,Vec,InsertMode,Vec)) { 611f3db62a7SRichard Tran Mills PetscFunctionBegin; 612f3db62a7SRichard Tran Mills dm->ops->localtolocalbegin = begin; 613f3db62a7SRichard Tran Mills dm->ops->localtolocalend = end; 614f3db62a7SRichard Tran Mills PetscFunctionReturn(0); 615f3db62a7SRichard Tran Mills } 616f3db62a7SRichard Tran Mills 617f3db62a7SRichard Tran Mills #undef __FUNCT__ 61881634712SRichard Tran Mills #define __FUNCT__ "DMShellSetGlobalToLocalVecScatter" 61981634712SRichard Tran Mills /*@ 62081634712SRichard Tran Mills DMShellSetGlobalToLocalVecScatter - Sets a VecScatter context for global to local communication 62181634712SRichard Tran Mills 62281634712SRichard Tran Mills Logically Collective on DM 62381634712SRichard Tran Mills 62481634712SRichard Tran Mills Input Arguments 62581634712SRichard Tran Mills + dm - the shell DM 62681634712SRichard Tran Mills - gtol - the global to local VecScatter context 62781634712SRichard Tran Mills 62881634712SRichard Tran Mills Level: advanced 62981634712SRichard Tran Mills 630f3db62a7SRichard Tran Mills .seealso: DMShellSetGlobalToLocal(), DMGlobalToLocalBeginDefaultShell(), DMGlobalToLocalEndDefaultShell() 63181634712SRichard Tran Mills @*/ 632a94b16f6SRichard Tran Mills PetscErrorCode DMShellSetGlobalToLocalVecScatter(DM dm, VecScatter gtol) 63381634712SRichard Tran Mills { 63481634712SRichard Tran Mills DM_Shell *shell = (DM_Shell*)dm->data; 635d885d199SRichard Tran Mills PetscErrorCode ierr; 63681634712SRichard Tran Mills 637b300e4a8SRichard Tran Mills PetscFunctionBegin; 638d885d199SRichard Tran Mills ierr = PetscObjectReference((PetscObject)gtol);CHKERRQ(ierr); 639d885d199SRichard Tran Mills /* Call VecScatterDestroy() to avoid a memory leak in case of re-setting. */ 640d885d199SRichard Tran Mills ierr = VecScatterDestroy(&shell->gtol);CHKERRQ(ierr); 64181634712SRichard Tran Mills shell->gtol = gtol; 64281634712SRichard Tran Mills PetscFunctionReturn(0); 64381634712SRichard Tran Mills } 64481634712SRichard Tran Mills 64581634712SRichard Tran Mills #undef __FUNCT__ 646988ea7d6SRichard Tran Mills #define __FUNCT__ "DMShellSetLocalToGlobalVecScatter" 647988ea7d6SRichard Tran Mills /*@ 648988ea7d6SRichard Tran Mills DMShellSetLocalToGlobalVecScatter - Sets a VecScatter context for local to global communication 649988ea7d6SRichard Tran Mills 650988ea7d6SRichard Tran Mills Logically Collective on DM 651988ea7d6SRichard Tran Mills 652988ea7d6SRichard Tran Mills Input Arguments 653988ea7d6SRichard Tran Mills + dm - the shell DM 654988ea7d6SRichard Tran Mills - ltog - the local to global VecScatter context 655988ea7d6SRichard Tran Mills 656988ea7d6SRichard Tran Mills Level: advanced 657988ea7d6SRichard Tran Mills 658f3db62a7SRichard Tran Mills .seealso: DMShellSetLocalToGlobal(), DMLocalToGlobalBeginDefaultShell(), DMLocalToGlobalEndDefaultShell() 659988ea7d6SRichard Tran Mills @*/ 660a94b16f6SRichard Tran Mills PetscErrorCode DMShellSetLocalToGlobalVecScatter(DM dm, VecScatter ltog) 661988ea7d6SRichard Tran Mills { 662988ea7d6SRichard Tran Mills DM_Shell *shell = (DM_Shell*)dm->data; 663d885d199SRichard Tran Mills PetscErrorCode ierr; 664988ea7d6SRichard Tran Mills 665988ea7d6SRichard Tran Mills PetscFunctionBegin; 666d885d199SRichard Tran Mills ierr = PetscObjectReference((PetscObject)ltog);CHKERRQ(ierr); 667d885d199SRichard Tran Mills /* Call VecScatterDestroy() to avoid a memory leak in case of re-setting. */ 668d885d199SRichard Tran Mills ierr = VecScatterDestroy(&shell->ltog);CHKERRQ(ierr); 669988ea7d6SRichard Tran Mills shell->ltog = ltog; 670988ea7d6SRichard Tran Mills PetscFunctionReturn(0); 671988ea7d6SRichard Tran Mills } 672988ea7d6SRichard Tran Mills 673988ea7d6SRichard Tran Mills #undef __FUNCT__ 674f3db62a7SRichard Tran Mills #define __FUNCT__ "DMShellSetLocalToLocalVecScatter" 675f3db62a7SRichard Tran Mills /*@ 676f3db62a7SRichard Tran Mills DMShellSetLocalToLocalVecScatter - Sets a VecScatter context for local to local communication 677f3db62a7SRichard Tran Mills 678f3db62a7SRichard Tran Mills Logically Collective on DM 679f3db62a7SRichard Tran Mills 680f3db62a7SRichard Tran Mills Input Arguments 681f3db62a7SRichard Tran Mills + dm - the shell DM 682f3db62a7SRichard Tran Mills - ltol - the local to local VecScatter context 683f3db62a7SRichard Tran Mills 684f3db62a7SRichard Tran Mills Level: advanced 685f3db62a7SRichard Tran Mills 686f3db62a7SRichard Tran Mills .seealso: DMShellSetLocalToLocal(), DMLocalToLocalBeginDefaultShell(), DMLocalToLocalEndDefaultShell() 687f3db62a7SRichard Tran Mills @*/ 688f3db62a7SRichard Tran Mills PetscErrorCode DMShellSetLocalToLocalVecScatter(DM dm, VecScatter ltol) 689f3db62a7SRichard Tran Mills { 690f3db62a7SRichard Tran Mills DM_Shell *shell = (DM_Shell*)dm->data; 691f3db62a7SRichard Tran Mills PetscErrorCode ierr; 692f3db62a7SRichard Tran Mills 693f3db62a7SRichard Tran Mills PetscFunctionBegin; 694f3db62a7SRichard Tran Mills ierr = PetscObjectReference((PetscObject)ltol);CHKERRQ(ierr); 695f3db62a7SRichard Tran Mills /* Call VecScatterDestroy() to avoid a memory leak in case of re-setting. */ 696f3db62a7SRichard Tran Mills ierr = VecScatterDestroy(&shell->ltol);CHKERRQ(ierr); 697f3db62a7SRichard Tran Mills shell->ltol = ltol; 698f3db62a7SRichard Tran Mills PetscFunctionReturn(0); 699f3db62a7SRichard Tran Mills } 700f3db62a7SRichard Tran Mills 701f3db62a7SRichard Tran Mills #undef __FUNCT__ 702f572501eSLawrence Mitchell #define __FUNCT__ "DMShellSetCoarsen" 7039bf9660cSLawrence Mitchell /*@C 7049bf9660cSLawrence Mitchell DMShellSetCoarsen - Set the routine used to coarsen the shell DM 7059bf9660cSLawrence Mitchell 7069bf9660cSLawrence Mitchell Logically Collective on DM 7079bf9660cSLawrence Mitchell 7089bf9660cSLawrence Mitchell Input Arguments 7099bf9660cSLawrence Mitchell + dm - the shell DM 7109bf9660cSLawrence Mitchell - coarsen - the routine that coarsens the DM 7119bf9660cSLawrence Mitchell 7129bf9660cSLawrence Mitchell Level: advanced 7139bf9660cSLawrence Mitchell 714fef3a512SBarry Smith .seealso: DMShellSetRefine(), DMCoarsen(), DMShellSetContext(), DMShellGetContext() 7159bf9660cSLawrence Mitchell @*/ 716f572501eSLawrence Mitchell PetscErrorCode DMShellSetCoarsen(DM dm, PetscErrorCode (*coarsen)(DM,MPI_Comm,DM*)) 717f572501eSLawrence Mitchell { 718f572501eSLawrence Mitchell PetscErrorCode ierr; 719f572501eSLawrence Mitchell PetscBool isshell; 720f572501eSLawrence Mitchell 721f572501eSLawrence Mitchell PetscFunctionBegin; 722f572501eSLawrence Mitchell PetscValidHeaderSpecific(dm,DM_CLASSID,1); 723f572501eSLawrence Mitchell ierr = PetscObjectTypeCompare((PetscObject)dm,DMSHELL,&isshell);CHKERRQ(ierr); 724f572501eSLawrence Mitchell if (!isshell) PetscFunctionReturn(0); 725f572501eSLawrence Mitchell dm->ops->coarsen = coarsen; 726f572501eSLawrence Mitchell PetscFunctionReturn(0); 727f572501eSLawrence Mitchell } 728f572501eSLawrence Mitchell 729f572501eSLawrence Mitchell #undef __FUNCT__ 730f572501eSLawrence Mitchell #define __FUNCT__ "DMShellSetRefine" 7319bf9660cSLawrence Mitchell /*@C 7329bf9660cSLawrence Mitchell DMShellSetRefine - Set the routine used to refine the shell DM 7339bf9660cSLawrence Mitchell 7349bf9660cSLawrence Mitchell Logically Collective on DM 7359bf9660cSLawrence Mitchell 7369bf9660cSLawrence Mitchell Input Arguments 7379bf9660cSLawrence Mitchell + dm - the shell DM 7389bf9660cSLawrence Mitchell - refine - the routine that refines the DM 7399bf9660cSLawrence Mitchell 7409bf9660cSLawrence Mitchell Level: advanced 7419bf9660cSLawrence Mitchell 742fef3a512SBarry Smith .seealso: DMShellSetCoarsen(), DMRefine(), DMShellSetContext(), DMShellGetContext() 7439bf9660cSLawrence Mitchell @*/ 744f572501eSLawrence Mitchell PetscErrorCode DMShellSetRefine(DM dm, PetscErrorCode (*refine)(DM,MPI_Comm,DM*)) 745f572501eSLawrence Mitchell { 746f572501eSLawrence Mitchell PetscErrorCode ierr; 747f572501eSLawrence Mitchell PetscBool isshell; 748f572501eSLawrence Mitchell 749f572501eSLawrence Mitchell PetscFunctionBegin; 750f572501eSLawrence Mitchell PetscValidHeaderSpecific(dm,DM_CLASSID,1); 751f572501eSLawrence Mitchell ierr = PetscObjectTypeCompare((PetscObject)dm,DMSHELL,&isshell);CHKERRQ(ierr); 752f572501eSLawrence Mitchell if (!isshell) PetscFunctionReturn(0); 753f572501eSLawrence Mitchell dm->ops->refine = refine; 754f572501eSLawrence Mitchell PetscFunctionReturn(0); 755f572501eSLawrence Mitchell } 756f572501eSLawrence Mitchell 757f572501eSLawrence Mitchell #undef __FUNCT__ 758f572501eSLawrence Mitchell #define __FUNCT__ "DMShellSetCreateInterpolation" 7599bf9660cSLawrence Mitchell /*@C 7609bf9660cSLawrence Mitchell DMShellSetCreateInterpolation - Set the routine used to create the interpolation operator 7619bf9660cSLawrence Mitchell 7629bf9660cSLawrence Mitchell Logically Collective on DM 7639bf9660cSLawrence Mitchell 7649bf9660cSLawrence Mitchell Input Arguments 7659bf9660cSLawrence Mitchell + dm - the shell DM 7669bf9660cSLawrence Mitchell - interp - the routine to create the interpolation 7679bf9660cSLawrence Mitchell 7689bf9660cSLawrence Mitchell Level: advanced 7699bf9660cSLawrence Mitchell 770fef3a512SBarry Smith .seealso: DMShellSetCreateInjection(), DMCreateInterpolation(), DMShellSetCreateRestriction(), DMShellSetContext(), DMShellGetContext() 7719bf9660cSLawrence Mitchell @*/ 772f572501eSLawrence Mitchell PetscErrorCode DMShellSetCreateInterpolation(DM dm, PetscErrorCode (*interp)(DM,DM,Mat*,Vec*)) 773f572501eSLawrence Mitchell { 774f572501eSLawrence Mitchell PetscErrorCode ierr; 775f572501eSLawrence Mitchell PetscBool isshell; 776f572501eSLawrence Mitchell 777f572501eSLawrence Mitchell PetscFunctionBegin; 778f572501eSLawrence Mitchell PetscValidHeaderSpecific(dm,DM_CLASSID,1); 779f572501eSLawrence Mitchell ierr = PetscObjectTypeCompare((PetscObject)dm,DMSHELL,&isshell);CHKERRQ(ierr); 780f572501eSLawrence Mitchell if (!isshell) PetscFunctionReturn(0); 781f572501eSLawrence Mitchell dm->ops->createinterpolation = interp; 782f572501eSLawrence Mitchell PetscFunctionReturn(0); 783f572501eSLawrence Mitchell } 784f572501eSLawrence Mitchell 785f572501eSLawrence Mitchell #undef __FUNCT__ 7863ad4599aSBarry Smith #define __FUNCT__ "DMShellSetCreateRestriction" 7873ad4599aSBarry Smith /*@C 7883ad4599aSBarry Smith DMShellSetCreateRestriction - Set the routine used to create the restriction operator 7893ad4599aSBarry Smith 7903ad4599aSBarry Smith Logically Collective on DM 7913ad4599aSBarry Smith 7923ad4599aSBarry Smith Input Arguments 7933ad4599aSBarry Smith + dm - the shell DM 7943ad4599aSBarry Smith - striction- the routine to create the restriction 7953ad4599aSBarry Smith 7963ad4599aSBarry Smith Level: advanced 7973ad4599aSBarry Smith 798fef3a512SBarry Smith .seealso: DMShellSetCreateInjection(), DMCreateInterpolation(), DMShellSetContext(), DMShellGetContext() 7993ad4599aSBarry Smith @*/ 8003ad4599aSBarry Smith PetscErrorCode DMShellSetCreateRestriction(DM dm, PetscErrorCode (*restriction)(DM,DM,Mat*)) 8013ad4599aSBarry Smith { 8023ad4599aSBarry Smith PetscErrorCode ierr; 8033ad4599aSBarry Smith PetscBool isshell; 8043ad4599aSBarry Smith 8053ad4599aSBarry Smith PetscFunctionBegin; 8063ad4599aSBarry Smith PetscValidHeaderSpecific(dm,DM_CLASSID,1); 8073ad4599aSBarry Smith ierr = PetscObjectTypeCompare((PetscObject)dm,DMSHELL,&isshell);CHKERRQ(ierr); 8083ad4599aSBarry Smith if (!isshell) PetscFunctionReturn(0); 8093ad4599aSBarry Smith dm->ops->createrestriction = restriction; 8103ad4599aSBarry Smith PetscFunctionReturn(0); 8113ad4599aSBarry Smith } 8123ad4599aSBarry Smith 8133ad4599aSBarry Smith #undef __FUNCT__ 814f572501eSLawrence Mitchell #define __FUNCT__ "DMShellSetCreateInjection" 8159bf9660cSLawrence Mitchell /*@C 8169bf9660cSLawrence Mitchell DMShellSetCreateInjection - Set the routine used to create the injection operator 8179bf9660cSLawrence Mitchell 8189bf9660cSLawrence Mitchell Logically Collective on DM 8199bf9660cSLawrence Mitchell 8209bf9660cSLawrence Mitchell Input Arguments 8219bf9660cSLawrence Mitchell + dm - the shell DM 8229bf9660cSLawrence Mitchell - inject - the routine to create the injection 8239bf9660cSLawrence Mitchell 8249bf9660cSLawrence Mitchell Level: advanced 8259bf9660cSLawrence Mitchell 826fef3a512SBarry Smith .seealso: DMShellSetCreateInterpolation(), DMCreateInjection(), DMShellSetContext(), DMShellGetContext() 8279bf9660cSLawrence Mitchell @*/ 828f572501eSLawrence Mitchell PetscErrorCode DMShellSetCreateInjection(DM dm, PetscErrorCode (*inject)(DM,DM,Mat*)) 829f572501eSLawrence Mitchell { 830f572501eSLawrence Mitchell PetscErrorCode ierr; 831f572501eSLawrence Mitchell PetscBool isshell; 832f572501eSLawrence Mitchell 833f572501eSLawrence Mitchell PetscFunctionBegin; 834f572501eSLawrence Mitchell PetscValidHeaderSpecific(dm,DM_CLASSID,1); 835f572501eSLawrence Mitchell ierr = PetscObjectTypeCompare((PetscObject)dm,DMSHELL,&isshell);CHKERRQ(ierr); 836f572501eSLawrence Mitchell if (!isshell) PetscFunctionReturn(0); 837f572501eSLawrence Mitchell dm->ops->getinjection = inject; 838f572501eSLawrence Mitchell PetscFunctionReturn(0); 839f572501eSLawrence Mitchell } 840f572501eSLawrence Mitchell 841f572501eSLawrence Mitchell #undef __FUNCT__ 8425e2259d5SLawrence Mitchell #define __FUNCT__ "DMShellSetCreateFieldDecomposition" 8439bf9660cSLawrence Mitchell /*@C 8449bf9660cSLawrence Mitchell DMShellSetCreateFieldDecomposition - Set the routine used to create a decomposition of fields for the shell DM 8459bf9660cSLawrence Mitchell 8469bf9660cSLawrence Mitchell Logically Collective on DM 8479bf9660cSLawrence Mitchell 8489bf9660cSLawrence Mitchell Input Arguments 8499bf9660cSLawrence Mitchell + dm - the shell DM 8509bf9660cSLawrence Mitchell - decomp - the routine to create the decomposition 8519bf9660cSLawrence Mitchell 8529bf9660cSLawrence Mitchell Level: advanced 8539bf9660cSLawrence Mitchell 854fef3a512SBarry Smith .seealso: DMCreateFieldDecomposition(), DMShellSetContext(), DMShellGetContext() 8559bf9660cSLawrence Mitchell @*/ 8565e2259d5SLawrence Mitchell PetscErrorCode DMShellSetCreateFieldDecomposition(DM dm, PetscErrorCode (*decomp)(DM,PetscInt*,char***, IS**,DM**)) 8575e2259d5SLawrence Mitchell { 8585e2259d5SLawrence Mitchell PetscErrorCode ierr; 8595e2259d5SLawrence Mitchell PetscBool isshell; 8605e2259d5SLawrence Mitchell 8615e2259d5SLawrence Mitchell PetscFunctionBegin; 8625e2259d5SLawrence Mitchell PetscValidHeaderSpecific(dm,DM_CLASSID,1); 8635e2259d5SLawrence Mitchell ierr = PetscObjectTypeCompare((PetscObject)dm,DMSHELL,&isshell);CHKERRQ(ierr); 8645e2259d5SLawrence Mitchell if (!isshell) PetscFunctionReturn(0); 8655e2259d5SLawrence Mitchell dm->ops->createfielddecomposition = decomp; 8665e2259d5SLawrence Mitchell PetscFunctionReturn(0); 8675e2259d5SLawrence Mitchell } 8685e2259d5SLawrence Mitchell 869c00061e5SLawrence Mitchell /*@C 870c00061e5SLawrence Mitchell DMShellSetCreateSubDM - Set the routine used to create a sub DM from the shell DM 871c00061e5SLawrence Mitchell 872c00061e5SLawrence Mitchell Logically Collective on DM 873c00061e5SLawrence Mitchell 874c00061e5SLawrence Mitchell Input Arguments 875c00061e5SLawrence Mitchell + dm - the shell DM 876c00061e5SLawrence Mitchell - subdm - the routine to create the decomposition 877c00061e5SLawrence Mitchell 878c00061e5SLawrence Mitchell Level: advanced 879c00061e5SLawrence Mitchell 880fef3a512SBarry Smith .seealso: DMCreateSubDM(), DMShellSetContext(), DMShellGetContext() 881c00061e5SLawrence Mitchell @*/ 882c00061e5SLawrence Mitchell #undef __FUNCT__ 883c00061e5SLawrence Mitchell #define __FUNCT__ "DMShellSetCreateSubDM" 884c00061e5SLawrence Mitchell PetscErrorCode DMShellSetCreateSubDM(DM dm, PetscErrorCode (*subdm)(DM,PetscInt,PetscInt[],IS*,DM*)) 885c00061e5SLawrence Mitchell { 886c00061e5SLawrence Mitchell PetscErrorCode ierr; 887c00061e5SLawrence Mitchell PetscBool isshell; 888c00061e5SLawrence Mitchell 889c00061e5SLawrence Mitchell PetscFunctionBegin; 890c00061e5SLawrence Mitchell PetscValidHeaderSpecific(dm,DM_CLASSID,1); 891c00061e5SLawrence Mitchell ierr = PetscObjectTypeCompare((PetscObject)dm,DMSHELL,&isshell);CHKERRQ(ierr); 892c00061e5SLawrence Mitchell if (!isshell) PetscFunctionReturn(0); 893c00061e5SLawrence Mitchell dm->ops->createsubdm = subdm; 894c00061e5SLawrence Mitchell PetscFunctionReturn(0); 895c00061e5SLawrence Mitchell } 896c00061e5SLawrence Mitchell 8975e2259d5SLawrence Mitchell #undef __FUNCT__ 898fe1899a2SJed Brown #define __FUNCT__ "DMDestroy_Shell" 899fe1899a2SJed Brown static PetscErrorCode DMDestroy_Shell(DM dm) 900fe1899a2SJed Brown { 901fe1899a2SJed Brown PetscErrorCode ierr; 902fe1899a2SJed Brown DM_Shell *shell = (DM_Shell*)dm->data; 903fe1899a2SJed Brown 904fe1899a2SJed Brown PetscFunctionBegin; 905fe1899a2SJed Brown ierr = MatDestroy(&shell->A);CHKERRQ(ierr); 906fe1899a2SJed Brown ierr = VecDestroy(&shell->Xglobal);CHKERRQ(ierr); 907dc43b69eSJed Brown ierr = VecDestroy(&shell->Xlocal);CHKERRQ(ierr); 908a94b16f6SRichard Tran Mills ierr = VecScatterDestroy(&shell->gtol);CHKERRQ(ierr); 909a94b16f6SRichard Tran Mills ierr = VecScatterDestroy(&shell->ltog);CHKERRQ(ierr); 910294a6417SLawrence Mitchell ierr = VecScatterDestroy(&shell->ltol);CHKERRQ(ierr); 9117b6ad80cSMatthew G Knepley /* This was originally freed in DMDestroy(), but that prevents reference counting of backend objects */ 9127b6ad80cSMatthew G Knepley ierr = PetscFree(shell);CHKERRQ(ierr); 913fe1899a2SJed Brown PetscFunctionReturn(0); 914fe1899a2SJed Brown } 915fe1899a2SJed Brown 9162d53ad75SBarry Smith #undef __FUNCT__ 9172d53ad75SBarry Smith #define __FUNCT__ "DMView_Shell" 9182d53ad75SBarry Smith static PetscErrorCode DMView_Shell(DM dm,PetscViewer v) 9192d53ad75SBarry Smith { 9202d53ad75SBarry Smith PetscErrorCode ierr; 9212d53ad75SBarry Smith DM_Shell *shell = (DM_Shell*)dm->data; 9222d53ad75SBarry Smith 9232d53ad75SBarry Smith PetscFunctionBegin; 9242d53ad75SBarry Smith ierr = VecView(shell->Xglobal,v);CHKERRQ(ierr); 9252d53ad75SBarry Smith PetscFunctionReturn(0); 9262d53ad75SBarry Smith } 9272d53ad75SBarry Smith 9282d53ad75SBarry Smith #undef __FUNCT__ 9292d53ad75SBarry Smith #define __FUNCT__ "DMLoad_Shell" 9302d53ad75SBarry Smith static PetscErrorCode DMLoad_Shell(DM dm,PetscViewer v) 9312d53ad75SBarry Smith { 9322d53ad75SBarry Smith PetscErrorCode ierr; 9332d53ad75SBarry Smith DM_Shell *shell = (DM_Shell*)dm->data; 9342d53ad75SBarry Smith 9352d53ad75SBarry Smith PetscFunctionBegin; 936ce94432eSBarry Smith ierr = VecCreate(PetscObjectComm((PetscObject)dm),&shell->Xglobal);CHKERRQ(ierr); 9372d53ad75SBarry Smith ierr = VecLoad(shell->Xglobal,v);CHKERRQ(ierr); 9382d53ad75SBarry Smith PetscFunctionReturn(0); 9392d53ad75SBarry Smith } 940fe1899a2SJed Brown 941fe1899a2SJed Brown #undef __FUNCT__ 9426e44b4cfSMatthew G. Knepley #define __FUNCT__ "DMCreateSubDM_Shell" 9436e44b4cfSMatthew G. Knepley PetscErrorCode DMCreateSubDM_Shell(DM dm, PetscInt numFields, PetscInt fields[], IS *is, DM *subdm) 9446e44b4cfSMatthew G. Knepley { 9456e44b4cfSMatthew G. Knepley PetscErrorCode ierr; 9466e44b4cfSMatthew G. Knepley 9476e44b4cfSMatthew G. Knepley PetscFunctionBegin; 9486e44b4cfSMatthew G. Knepley if (subdm) {ierr = DMShellCreate(PetscObjectComm((PetscObject) dm), subdm);CHKERRQ(ierr);} 9496e44b4cfSMatthew G. Knepley ierr = DMCreateSubDM_Section_Private(dm, numFields, fields, is, subdm);CHKERRQ(ierr); 9506e44b4cfSMatthew G. Knepley PetscFunctionReturn(0); 9516e44b4cfSMatthew G. Knepley } 9526e44b4cfSMatthew G. Knepley 9536e44b4cfSMatthew G. Knepley #undef __FUNCT__ 954fe1899a2SJed Brown #define __FUNCT__ "DMCreate_Shell" 9558cc058d9SJed Brown PETSC_EXTERN PetscErrorCode DMCreate_Shell(DM dm) 956fe1899a2SJed Brown { 957fe1899a2SJed Brown PetscErrorCode ierr; 958fe1899a2SJed Brown DM_Shell *shell; 959fe1899a2SJed Brown 960fe1899a2SJed Brown PetscFunctionBegin; 961b00a9115SJed Brown ierr = PetscNewLog(dm,&shell);CHKERRQ(ierr); 9628c87107bSJed Brown dm->data = shell; 963fe1899a2SJed Brown 9648c87107bSJed Brown ierr = PetscObjectChangeTypeName((PetscObject)dm,DMSHELL);CHKERRQ(ierr); 9658865f1eaSKarl Rupp 9668c87107bSJed Brown dm->ops->destroy = DMDestroy_Shell; 9678c87107bSJed Brown dm->ops->createglobalvector = DMCreateGlobalVector_Shell; 968dc43b69eSJed Brown dm->ops->createlocalvector = DMCreateLocalVector_Shell; 9698c87107bSJed Brown dm->ops->creatematrix = DMCreateMatrix_Shell; 9702d53ad75SBarry Smith dm->ops->view = DMView_Shell; 9712d53ad75SBarry Smith dm->ops->load = DMLoad_Shell; 9727a108d1dSBarry Smith dm->ops->globaltolocalbegin = DMGlobalToLocalBeginDefaultShell; 9737a108d1dSBarry Smith dm->ops->globaltolocalend = DMGlobalToLocalEndDefaultShell; 97455daaa54SRichard Tran Mills dm->ops->localtoglobalbegin = DMLocalToGlobalBeginDefaultShell; 97555daaa54SRichard Tran Mills dm->ops->localtoglobalend = DMLocalToGlobalEndDefaultShell; 97663731094SRichard Tran Mills dm->ops->localtolocalbegin = DMLocalToLocalBeginDefaultShell; 97763731094SRichard Tran Mills dm->ops->localtolocalend = DMLocalToLocalEndDefaultShell; 9786e44b4cfSMatthew G. Knepley dm->ops->createsubdm = DMCreateSubDM_Shell; 979fe1899a2SJed Brown PetscFunctionReturn(0); 980fe1899a2SJed Brown } 981fe1899a2SJed Brown 982fe1899a2SJed Brown #undef __FUNCT__ 983fe1899a2SJed Brown #define __FUNCT__ "DMShellCreate" 984fe1899a2SJed Brown /*@ 985fe1899a2SJed Brown DMShellCreate - Creates a shell DM object, used to manage user-defined problem data 986fe1899a2SJed Brown 987fe1899a2SJed Brown Collective on MPI_Comm 988fe1899a2SJed Brown 989fe1899a2SJed Brown Input Parameter: 990fe1899a2SJed Brown . comm - the processors that will share the global vector 991fe1899a2SJed Brown 992fe1899a2SJed Brown Output Parameters: 993fe1899a2SJed Brown . shell - the shell DM 994fe1899a2SJed Brown 995fe1899a2SJed Brown Level: advanced 996fe1899a2SJed Brown 997fef3a512SBarry Smith .seealso DMDestroy(), DMCreateGlobalVector(), DMCreateLocalVector(), DMShellSetContext(), DMShellGetContext() 998fe1899a2SJed Brown @*/ 999fe1899a2SJed Brown PetscErrorCode DMShellCreate(MPI_Comm comm,DM *dm) 1000fe1899a2SJed Brown { 1001fe1899a2SJed Brown PetscErrorCode ierr; 1002fe1899a2SJed Brown 1003fe1899a2SJed Brown PetscFunctionBegin; 1004fe1899a2SJed Brown PetscValidPointer(dm,2); 1005fe1899a2SJed Brown ierr = DMCreate(comm,dm);CHKERRQ(ierr); 1006fe1899a2SJed Brown ierr = DMSetType(*dm,DMSHELL);CHKERRQ(ierr); 100781a566bfSMatthew G. Knepley ierr = DMSetUp(*dm);CHKERRQ(ierr); 1008fe1899a2SJed Brown PetscFunctionReturn(0); 1009fe1899a2SJed Brown } 101081634712SRichard Tran Mills 1011