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 157a108d1dSBarry Smith /*@ 167a108d1dSBarry Smith DMGlobalToLocalBeginDefaultShell - Uses the GlobalToLocal VecScatter context set by the user to begin a global to local scatter 178d359177SBarry Smith Collective 188d359177SBarry Smith 198d359177SBarry Smith Input Arguments: 208d359177SBarry Smith + dm - shell DM 218d359177SBarry Smith . g - global vector 228d359177SBarry Smith . mode - InsertMode 238d359177SBarry Smith - l - local vector 248d359177SBarry Smith 257a108d1dSBarry Smith Level: advanced 268d359177SBarry Smith 277a108d1dSBarry 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. 287a108d1dSBarry Smith 297a108d1dSBarry Smith .seealso: DMGlobalToLocalEndDefaultShell() 308d359177SBarry Smith @*/ 317a108d1dSBarry Smith PetscErrorCode DMGlobalToLocalBeginDefaultShell(DM dm,Vec g,InsertMode mode,Vec l) 328d359177SBarry Smith { 338d359177SBarry Smith PetscErrorCode ierr; 348d359177SBarry Smith DM_Shell *shell = (DM_Shell*)dm->data; 358d359177SBarry Smith 368d359177SBarry Smith PetscFunctionBegin; 377a108d1dSBarry Smith if (!shell->gtol) SETERRQ(((PetscObject)dm)->comm,PETSC_ERR_ARG_WRONGSTATE, "Cannot be used without first setting the scatter context via DMShellSetGlobalToLocalVecScatter()"); 38a94b16f6SRichard Tran Mills ierr = VecScatterBegin(shell->gtol,g,l,mode,SCATTER_FORWARD);CHKERRQ(ierr); 398d359177SBarry Smith PetscFunctionReturn(0); 408d359177SBarry Smith } 418d359177SBarry Smith 427a108d1dSBarry Smith /*@ 437a108d1dSBarry Smith DMGlobalToLocalEndDefaultShell - Uses the GlobalToLocal VecScatter context set by the user to end a global to local scatter 448d359177SBarry Smith Collective 458d359177SBarry Smith 468d359177SBarry Smith Input Arguments: 478d359177SBarry Smith + dm - shell DM 488d359177SBarry Smith . g - global vector 498d359177SBarry Smith . mode - InsertMode 508d359177SBarry Smith - l - local vector 518d359177SBarry Smith 527a108d1dSBarry Smith Level: advanced 538d359177SBarry Smith 547a108d1dSBarry Smith .seealso: DMGlobalToLocalBeginDefaultShell() 558d359177SBarry Smith @*/ 567a108d1dSBarry Smith PetscErrorCode DMGlobalToLocalEndDefaultShell(DM dm,Vec g,InsertMode mode,Vec l) 578d359177SBarry Smith { 588d359177SBarry Smith PetscErrorCode ierr; 598d359177SBarry Smith DM_Shell *shell = (DM_Shell*)dm->data; 608d359177SBarry Smith 618d359177SBarry Smith PetscFunctionBegin; 627a108d1dSBarry Smith if (!shell->gtol) SETERRQ(((PetscObject)dm)->comm,PETSC_ERR_ARG_WRONGSTATE, "Cannot be used without first setting the scatter context via DMShellSetGlobalToLocalVecScatter()"); 63a94b16f6SRichard Tran Mills ierr = VecScatterEnd(shell->gtol,g,l,mode,SCATTER_FORWARD);CHKERRQ(ierr); 648d359177SBarry Smith PetscFunctionReturn(0); 658d359177SBarry Smith } 668d359177SBarry Smith 67c5076b69SRichard Tran Mills /*@ 68c5076b69SRichard Tran Mills DMLocalToGlobalBeginDefaultShell - Uses the LocalToGlobal VecScatter context set by the user to begin a local to global scatter 69c5076b69SRichard Tran Mills Collective 70c5076b69SRichard Tran Mills 71c5076b69SRichard Tran Mills Input Arguments: 72c5076b69SRichard Tran Mills + dm - shell DM 73c5076b69SRichard Tran Mills . l - local vector 74c5076b69SRichard Tran Mills . mode - InsertMode 75c5076b69SRichard Tran Mills - g - global vector 76c5076b69SRichard Tran Mills 77c5076b69SRichard Tran Mills Level: advanced 78c5076b69SRichard Tran Mills 79c5076b69SRichard 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. 80c5076b69SRichard Tran Mills 81c5076b69SRichard Tran Mills .seealso: DMLocalToGlobalEndDefaultShell() 82c5076b69SRichard Tran Mills @*/ 83c5076b69SRichard Tran Mills PetscErrorCode DMLocalToGlobalBeginDefaultShell(DM dm,Vec l,InsertMode mode,Vec g) 84c5076b69SRichard Tran Mills { 85c5076b69SRichard Tran Mills PetscErrorCode ierr; 86c5076b69SRichard Tran Mills DM_Shell *shell = (DM_Shell*)dm->data; 87c5076b69SRichard Tran Mills 88c5076b69SRichard Tran Mills PetscFunctionBegin; 89c5076b69SRichard Tran Mills if (!shell->ltog) SETERRQ(((PetscObject)dm)->comm,PETSC_ERR_ARG_WRONGSTATE, "Cannot be used without first setting the scatter context via DMShellSetLocalToGlobalVecScatter()"); 90a94b16f6SRichard Tran Mills ierr = VecScatterBegin(shell->ltog,l,g,mode,SCATTER_FORWARD);CHKERRQ(ierr); 91c5076b69SRichard Tran Mills PetscFunctionReturn(0); 92c5076b69SRichard Tran Mills } 93c5076b69SRichard Tran Mills 94c5076b69SRichard Tran Mills /*@ 95c5076b69SRichard Tran Mills DMLocalToGlobalEndDefaultShell - Uses the LocalToGlobal VecScatter context set by the user to end a local to global scatter 96c5076b69SRichard Tran Mills Collective 97c5076b69SRichard Tran Mills 98c5076b69SRichard Tran Mills Input Arguments: 99c5076b69SRichard Tran Mills + dm - shell DM 100c5076b69SRichard Tran Mills . l - local vector 101c5076b69SRichard Tran Mills . mode - InsertMode 102c5076b69SRichard Tran Mills - g - global vector 103c5076b69SRichard Tran Mills 104c5076b69SRichard Tran Mills Level: advanced 105c5076b69SRichard Tran Mills 106c5076b69SRichard Tran Mills .seealso: DMLocalToGlobalBeginDefaultShell() 107c5076b69SRichard Tran Mills @*/ 108c5076b69SRichard Tran Mills PetscErrorCode DMLocalToGlobalEndDefaultShell(DM dm,Vec l,InsertMode mode,Vec g) 109c5076b69SRichard Tran Mills { 110c5076b69SRichard Tran Mills PetscErrorCode ierr; 111c5076b69SRichard Tran Mills DM_Shell *shell = (DM_Shell*)dm->data; 112c5076b69SRichard Tran Mills 113c5076b69SRichard Tran Mills PetscFunctionBegin; 114c5076b69SRichard Tran Mills if (!shell->ltog) SETERRQ(((PetscObject)dm)->comm,PETSC_ERR_ARG_WRONGSTATE, "Cannot be used without first setting the scatter context via DMShellSetLocalToGlobalVecScatter()"); 115a94b16f6SRichard Tran Mills ierr = VecScatterEnd(shell->ltog,l,g,mode,SCATTER_FORWARD);CHKERRQ(ierr); 116c5076b69SRichard Tran Mills PetscFunctionReturn(0); 117c5076b69SRichard Tran Mills } 118c5076b69SRichard Tran Mills 119f3db62a7SRichard Tran Mills /*@ 120f3db62a7SRichard Tran Mills DMLocalToLocalBeginDefaultShell - Uses the LocalToLocal VecScatter context set by the user to begin a local to local scatter 121f3db62a7SRichard Tran Mills Collective 122f3db62a7SRichard Tran Mills 123f3db62a7SRichard Tran Mills Input Arguments: 124f3db62a7SRichard Tran Mills + dm - shell DM 125f3db62a7SRichard Tran Mills . g - the original local vector 126f3db62a7SRichard Tran Mills - mode - InsertMode 127f3db62a7SRichard Tran Mills 128f3db62a7SRichard Tran Mills Output Parameter: 129f3db62a7SRichard Tran Mills . l - the local vector with correct ghost values 130f3db62a7SRichard Tran Mills 131f3db62a7SRichard Tran Mills Level: advanced 132f3db62a7SRichard Tran Mills 133f3db62a7SRichard 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. 134f3db62a7SRichard Tran Mills 135f3db62a7SRichard Tran Mills .seealso: DMLocalToLocalEndDefaultShell() 136f3db62a7SRichard Tran Mills @*/ 137f3db62a7SRichard Tran Mills PetscErrorCode DMLocalToLocalBeginDefaultShell(DM dm,Vec g,InsertMode mode,Vec l) 138f3db62a7SRichard Tran Mills { 139f3db62a7SRichard Tran Mills PetscErrorCode ierr; 140f3db62a7SRichard Tran Mills DM_Shell *shell = (DM_Shell*)dm->data; 141f3db62a7SRichard Tran Mills 142f3db62a7SRichard Tran Mills PetscFunctionBegin; 143f3db62a7SRichard Tran Mills if (!shell->ltol) SETERRQ(((PetscObject)dm)->comm,PETSC_ERR_ARG_WRONGSTATE, "Cannot be used without first setting the scatter context via DMShellSetLocalToLocalVecScatter()"); 144f3db62a7SRichard Tran Mills ierr = VecScatterBegin(shell->ltol,g,l,mode,SCATTER_FORWARD);CHKERRQ(ierr); 145f3db62a7SRichard Tran Mills PetscFunctionReturn(0); 146f3db62a7SRichard Tran Mills } 147f3db62a7SRichard Tran Mills 148f3db62a7SRichard Tran Mills /*@ 149f3db62a7SRichard Tran Mills DMLocalToLocalEndDefaultShell - Uses the LocalToLocal VecScatter context set by the user to end a local to local scatter 150f3db62a7SRichard Tran Mills Collective 151f3db62a7SRichard Tran Mills 152f3db62a7SRichard Tran Mills Input Arguments: 153f3db62a7SRichard Tran Mills + dm - shell DM 154f3db62a7SRichard Tran Mills . g - the original local vector 155f3db62a7SRichard Tran Mills - mode - InsertMode 156f3db62a7SRichard Tran Mills 157f3db62a7SRichard Tran Mills Output Parameter: 158f3db62a7SRichard Tran Mills . l - the local vector with correct ghost values 159f3db62a7SRichard Tran Mills 160f3db62a7SRichard Tran Mills Level: advanced 161f3db62a7SRichard Tran Mills 162f3db62a7SRichard Tran Mills .seealso: DMLocalToLocalBeginDefaultShell() 163f3db62a7SRichard Tran Mills @*/ 164f3db62a7SRichard Tran Mills PetscErrorCode DMLocalToLocalEndDefaultShell(DM dm,Vec g,InsertMode mode,Vec l) 165f3db62a7SRichard Tran Mills { 166f3db62a7SRichard Tran Mills PetscErrorCode ierr; 167f3db62a7SRichard Tran Mills DM_Shell *shell = (DM_Shell*)dm->data; 168f3db62a7SRichard Tran Mills 169f3db62a7SRichard Tran Mills PetscFunctionBegin; 170f3db62a7SRichard Tran Mills if (!shell->ltol) SETERRQ(((PetscObject)dm)->comm,PETSC_ERR_ARG_WRONGSTATE, "Cannot be used without first setting the scatter context via DMShellSetGlobalToLocalVecScatter()"); 171f3db62a7SRichard Tran Mills ierr = VecScatterEnd(shell->ltol,g,l,mode,SCATTER_FORWARD);CHKERRQ(ierr); 172f3db62a7SRichard Tran Mills PetscFunctionReturn(0); 173f3db62a7SRichard Tran Mills } 174c5076b69SRichard Tran Mills 175b412c318SBarry Smith static PetscErrorCode DMCreateMatrix_Shell(DM dm,Mat *J) 176fe1899a2SJed Brown { 177fe1899a2SJed Brown PetscErrorCode ierr; 178fe1899a2SJed Brown DM_Shell *shell = (DM_Shell*)dm->data; 179fe1899a2SJed Brown Mat A; 180fe1899a2SJed Brown 181fe1899a2SJed Brown PetscFunctionBegin; 182fe1899a2SJed Brown PetscValidHeaderSpecific(dm,DM_CLASSID,1); 183fe1899a2SJed Brown PetscValidPointer(J,3); 1847bde9f88SJed Brown if (!shell->A) { 1857bde9f88SJed Brown if (shell->Xglobal) { 1867bde9f88SJed Brown PetscInt m,M; 187955c1f14SBarry Smith ierr = PetscInfo(dm,"Naively creating matrix using global vector distribution without preallocation\n");CHKERRQ(ierr); 1887bde9f88SJed Brown ierr = VecGetSize(shell->Xglobal,&M);CHKERRQ(ierr); 1897bde9f88SJed Brown ierr = VecGetLocalSize(shell->Xglobal,&m);CHKERRQ(ierr); 190ce94432eSBarry Smith ierr = MatCreate(PetscObjectComm((PetscObject)dm),&shell->A);CHKERRQ(ierr); 1917bde9f88SJed Brown ierr = MatSetSizes(shell->A,m,m,M,M);CHKERRQ(ierr); 192b412c318SBarry Smith ierr = MatSetType(shell->A,dm->mattype);CHKERRQ(ierr); 1937bde9f88SJed Brown ierr = MatSetUp(shell->A);CHKERRQ(ierr); 194ce94432eSBarry Smith } else SETERRQ(PetscObjectComm((PetscObject)dm),PETSC_ERR_USER,"Must call DMShellSetMatrix(), DMShellSetCreateMatrix(), or provide a vector"); 1957bde9f88SJed Brown } 196fe1899a2SJed Brown A = shell->A; 197ad6bc421SBarry Smith /* the check below is tacky and incomplete */ 198b412c318SBarry Smith if (dm->mattype) { 199ad6bc421SBarry Smith PetscBool flg,aij,seqaij,mpiaij; 200b412c318SBarry Smith ierr = PetscObjectTypeCompare((PetscObject)A,dm->mattype,&flg);CHKERRQ(ierr); 201ad6bc421SBarry Smith ierr = PetscObjectTypeCompare((PetscObject)A,MATSEQAIJ,&seqaij);CHKERRQ(ierr); 202ad6bc421SBarry Smith ierr = PetscObjectTypeCompare((PetscObject)A,MATMPIAIJ,&mpiaij);CHKERRQ(ierr); 203b412c318SBarry Smith ierr = PetscStrcmp(dm->mattype,MATAIJ,&aij);CHKERRQ(ierr); 204ad6bc421SBarry Smith if (!flg) { 205b412c318SBarry 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); 206ad6bc421SBarry Smith } 207fe1899a2SJed Brown } 208fe1899a2SJed Brown if (((PetscObject)A)->refct < 2) { /* We have an exclusive reference so we can give it out */ 209fe1899a2SJed Brown ierr = PetscObjectReference((PetscObject)A);CHKERRQ(ierr); 210fe1899a2SJed Brown ierr = MatZeroEntries(A);CHKERRQ(ierr); 211fe1899a2SJed Brown *J = A; 212fe1899a2SJed Brown } else { /* Need to create a copy, could use MAT_SHARE_NONZERO_PATTERN in most cases */ 213fe1899a2SJed Brown ierr = MatDuplicate(A,MAT_DO_NOT_COPY_VALUES,J);CHKERRQ(ierr); 214fe1899a2SJed Brown ierr = MatZeroEntries(*J);CHKERRQ(ierr); 215fe1899a2SJed Brown } 216fe1899a2SJed Brown PetscFunctionReturn(0); 217fe1899a2SJed Brown } 218fe1899a2SJed Brown 219fe1899a2SJed Brown PetscErrorCode DMCreateGlobalVector_Shell(DM dm,Vec *gvec) 220fe1899a2SJed Brown { 221fe1899a2SJed Brown PetscErrorCode ierr; 222fe1899a2SJed Brown DM_Shell *shell = (DM_Shell*)dm->data; 223fe1899a2SJed Brown Vec X; 224fe1899a2SJed Brown 225fe1899a2SJed Brown PetscFunctionBegin; 226fe1899a2SJed Brown PetscValidHeaderSpecific(dm,DM_CLASSID,1); 227fe1899a2SJed Brown PetscValidPointer(gvec,2); 228fe1899a2SJed Brown *gvec = 0; 229fe1899a2SJed Brown X = shell->Xglobal; 230ce94432eSBarry Smith if (!X) SETERRQ(PetscObjectComm((PetscObject)dm),PETSC_ERR_USER,"Must call DMShellSetGlobalVector() or DMShellSetCreateGlobalVector()"); 231fe1899a2SJed Brown if (((PetscObject)X)->refct < 2) { /* We have an exclusive reference so we can give it out */ 232fe1899a2SJed Brown ierr = PetscObjectReference((PetscObject)X);CHKERRQ(ierr); 233fe1899a2SJed Brown ierr = VecZeroEntries(X);CHKERRQ(ierr); 234fe1899a2SJed Brown *gvec = X; 235fe1899a2SJed Brown } else { /* Need to create a copy, could use MAT_SHARE_NONZERO_PATTERN in most cases */ 236fe1899a2SJed Brown ierr = VecDuplicate(X,gvec);CHKERRQ(ierr); 237fe1899a2SJed Brown ierr = VecZeroEntries(*gvec);CHKERRQ(ierr); 238fe1899a2SJed Brown } 239c688c046SMatthew G Knepley ierr = VecSetDM(*gvec,dm);CHKERRQ(ierr); 240fe1899a2SJed Brown PetscFunctionReturn(0); 241fe1899a2SJed Brown } 242fe1899a2SJed Brown 243dc43b69eSJed Brown PetscErrorCode DMCreateLocalVector_Shell(DM dm,Vec *gvec) 244dc43b69eSJed Brown { 245dc43b69eSJed Brown PetscErrorCode ierr; 246dc43b69eSJed Brown DM_Shell *shell = (DM_Shell*)dm->data; 247dc43b69eSJed Brown Vec X; 248dc43b69eSJed Brown 249dc43b69eSJed Brown PetscFunctionBegin; 250dc43b69eSJed Brown PetscValidHeaderSpecific(dm,DM_CLASSID,1); 251dc43b69eSJed Brown PetscValidPointer(gvec,2); 252dc43b69eSJed Brown *gvec = 0; 253dc43b69eSJed Brown X = shell->Xlocal; 254ce94432eSBarry Smith if (!X) SETERRQ(PetscObjectComm((PetscObject)dm),PETSC_ERR_USER,"Must call DMShellSetLocalVector() or DMShellSetCreateLocalVector()"); 255dc43b69eSJed Brown if (((PetscObject)X)->refct < 2) { /* We have an exclusive reference so we can give it out */ 256dc43b69eSJed Brown ierr = PetscObjectReference((PetscObject)X);CHKERRQ(ierr); 257dc43b69eSJed Brown ierr = VecZeroEntries(X);CHKERRQ(ierr); 258dc43b69eSJed Brown *gvec = X; 259dc43b69eSJed Brown } else { /* Need to create a copy, could use MAT_SHARE_NONZERO_PATTERN in most cases */ 260dc43b69eSJed Brown ierr = VecDuplicate(X,gvec);CHKERRQ(ierr); 261dc43b69eSJed Brown ierr = VecZeroEntries(*gvec);CHKERRQ(ierr); 262dc43b69eSJed Brown } 2636e4cbd8bSMark F. Adams ierr = VecSetDM(*gvec,dm);CHKERRQ(ierr); 264dc43b69eSJed Brown PetscFunctionReturn(0); 265dc43b69eSJed Brown } 266dc43b69eSJed Brown 267fef3a512SBarry Smith /*@ 268fef3a512SBarry Smith DMShellSetContext - set some data to be usable by this DM 269fef3a512SBarry Smith 270fef3a512SBarry Smith Collective 271fef3a512SBarry Smith 272fef3a512SBarry Smith Input Arguments: 273fef3a512SBarry Smith + dm - shell DM 274fef3a512SBarry Smith - ctx - the context 275fef3a512SBarry Smith 276fef3a512SBarry Smith Level: advanced 277fef3a512SBarry Smith 278fef3a512SBarry Smith .seealso: DMCreateMatrix(), DMShellGetContext() 279fef3a512SBarry Smith @*/ 280fef3a512SBarry Smith PetscErrorCode DMShellSetContext(DM dm,void *ctx) 281fef3a512SBarry Smith { 282fef3a512SBarry Smith DM_Shell *shell = (DM_Shell*)dm->data; 283fef3a512SBarry Smith PetscErrorCode ierr; 284fef3a512SBarry Smith PetscBool isshell; 285fef3a512SBarry Smith 286fef3a512SBarry Smith PetscFunctionBegin; 287fef3a512SBarry Smith PetscValidHeaderSpecific(dm,DM_CLASSID,1); 288fef3a512SBarry Smith ierr = PetscObjectTypeCompare((PetscObject)dm,DMSHELL,&isshell);CHKERRQ(ierr); 289fef3a512SBarry Smith if (!isshell) PetscFunctionReturn(0); 290fef3a512SBarry Smith shell->ctx = ctx; 291fef3a512SBarry Smith PetscFunctionReturn(0); 292fef3a512SBarry Smith } 293fef3a512SBarry Smith 294fef3a512SBarry Smith /*@ 295bf890c61SBoris Boutkov DMShellGetContext - Returns the user-provided context associated to the DM 296fef3a512SBarry Smith 297fef3a512SBarry Smith Collective 298fef3a512SBarry Smith 299fef3a512SBarry Smith Input Argument: 300fef3a512SBarry Smith . dm - shell DM 301fef3a512SBarry Smith 302fef3a512SBarry Smith Output Argument: 303fef3a512SBarry Smith . ctx - the context 304fef3a512SBarry Smith 305fef3a512SBarry Smith Level: advanced 306fef3a512SBarry Smith 307fef3a512SBarry Smith .seealso: DMCreateMatrix(), DMShellSetContext() 308fef3a512SBarry Smith @*/ 309fef3a512SBarry Smith PetscErrorCode DMShellGetContext(DM dm,void **ctx) 310fef3a512SBarry Smith { 311fef3a512SBarry Smith DM_Shell *shell = (DM_Shell*)dm->data; 312fef3a512SBarry Smith PetscErrorCode ierr; 313fef3a512SBarry Smith PetscBool isshell; 314fef3a512SBarry Smith 315fef3a512SBarry Smith PetscFunctionBegin; 316fef3a512SBarry Smith PetscValidHeaderSpecific(dm,DM_CLASSID,1); 317fef3a512SBarry Smith ierr = PetscObjectTypeCompare((PetscObject)dm,DMSHELL,&isshell);CHKERRQ(ierr); 3188dd90dd5SBoris Boutkov if (!isshell) SETERRQ(PetscObjectComm((PetscObject)dm),PETSC_ERR_SUP,"Can only use with DMSHELL type DMs"); 319fef3a512SBarry Smith *ctx = shell->ctx; 320fef3a512SBarry Smith PetscFunctionReturn(0); 321fef3a512SBarry Smith } 322fef3a512SBarry Smith 323fe1899a2SJed Brown /*@ 324fe1899a2SJed Brown DMShellSetMatrix - sets a template matrix associated with the DMShell 325fe1899a2SJed Brown 326fe1899a2SJed Brown Collective 327fe1899a2SJed Brown 328fe1899a2SJed Brown Input Arguments: 329fe1899a2SJed Brown + dm - shell DM 330fe1899a2SJed Brown - J - template matrix 331fe1899a2SJed Brown 332fe1899a2SJed Brown Level: advanced 333fe1899a2SJed Brown 334fef3a512SBarry Smith .seealso: DMCreateMatrix(), DMShellSetCreateMatrix(), DMShellSetContext(), DMShellGetContext() 335fe1899a2SJed Brown @*/ 336fe1899a2SJed Brown PetscErrorCode DMShellSetMatrix(DM dm,Mat J) 337fe1899a2SJed Brown { 338fe1899a2SJed Brown DM_Shell *shell = (DM_Shell*)dm->data; 339fe1899a2SJed Brown PetscErrorCode ierr; 3408c87107bSJed Brown PetscBool isshell; 341fe1899a2SJed Brown 342fe1899a2SJed Brown PetscFunctionBegin; 3438c87107bSJed Brown PetscValidHeaderSpecific(dm,DM_CLASSID,1); 3448c87107bSJed Brown PetscValidHeaderSpecific(J,MAT_CLASSID,2); 345251f4c67SDmitry Karpeev ierr = PetscObjectTypeCompare((PetscObject)dm,DMSHELL,&isshell);CHKERRQ(ierr); 3468c87107bSJed Brown if (!isshell) PetscFunctionReturn(0); 347fe1899a2SJed Brown ierr = PetscObjectReference((PetscObject)J);CHKERRQ(ierr); 348fe1899a2SJed Brown ierr = MatDestroy(&shell->A);CHKERRQ(ierr); 349fe1899a2SJed Brown shell->A = J; 350fe1899a2SJed Brown PetscFunctionReturn(0); 351fe1899a2SJed Brown } 352fe1899a2SJed Brown 353fe1899a2SJed Brown /*@C 354fe1899a2SJed Brown DMShellSetCreateMatrix - sets the routine to create a matrix associated with the shell DM 355fe1899a2SJed Brown 356d083f849SBarry Smith Logically Collective on dm 357fe1899a2SJed Brown 358fe1899a2SJed Brown Input Arguments: 359fe1899a2SJed Brown + dm - the shell DM 360fe1899a2SJed Brown - func - the function to create a matrix 361fe1899a2SJed Brown 362fe1899a2SJed Brown Level: advanced 363fe1899a2SJed Brown 364fef3a512SBarry Smith .seealso: DMCreateMatrix(), DMShellSetMatrix(), DMShellSetContext(), DMShellGetContext() 365fe1899a2SJed Brown @*/ 366b412c318SBarry Smith PetscErrorCode DMShellSetCreateMatrix(DM dm,PetscErrorCode (*func)(DM,Mat*)) 367fe1899a2SJed Brown { 368fe1899a2SJed Brown 369fe1899a2SJed Brown PetscFunctionBegin; 370fe1899a2SJed Brown PetscValidHeaderSpecific(dm,DM_CLASSID,1); 371fe1899a2SJed Brown dm->ops->creatematrix = func; 372fe1899a2SJed Brown PetscFunctionReturn(0); 373fe1899a2SJed Brown } 374fe1899a2SJed Brown 375fe1899a2SJed Brown /*@ 376fe1899a2SJed Brown DMShellSetGlobalVector - sets a template global vector associated with the DMShell 377fe1899a2SJed Brown 378d083f849SBarry Smith Logically Collective on dm 379fe1899a2SJed Brown 380fe1899a2SJed Brown Input Arguments: 381fe1899a2SJed Brown + dm - shell DM 382fe1899a2SJed Brown - X - template vector 383fe1899a2SJed Brown 384fe1899a2SJed Brown Level: advanced 385fe1899a2SJed Brown 386fe1899a2SJed Brown .seealso: DMCreateGlobalVector(), DMShellSetMatrix(), DMShellSetCreateGlobalVector() 387fe1899a2SJed Brown @*/ 388fe1899a2SJed Brown PetscErrorCode DMShellSetGlobalVector(DM dm,Vec X) 389fe1899a2SJed Brown { 390fe1899a2SJed Brown DM_Shell *shell = (DM_Shell*)dm->data; 391fe1899a2SJed Brown PetscErrorCode ierr; 3928c87107bSJed Brown PetscBool isshell; 393cca7ec1eSBarry Smith DM vdm; 394fe1899a2SJed Brown 395fe1899a2SJed Brown PetscFunctionBegin; 3968c87107bSJed Brown PetscValidHeaderSpecific(dm,DM_CLASSID,1); 3978c87107bSJed Brown PetscValidHeaderSpecific(X,VEC_CLASSID,2); 398251f4c67SDmitry Karpeev ierr = PetscObjectTypeCompare((PetscObject)dm,DMSHELL,&isshell);CHKERRQ(ierr); 3998c87107bSJed Brown if (!isshell) PetscFunctionReturn(0); 400cca7ec1eSBarry Smith ierr = VecGetDM(X,&vdm);CHKERRQ(ierr); 401cca7ec1eSBarry Smith /* 402cca7ec1eSBarry Smith if the vector proposed as the new base global vector for the DM is a DM vector associated 403cca7ec1eSBarry 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 404cca7ec1eSBarry Smith we get a circular dependency that prevents the DM from being destroy when it should be. 405cca7ec1eSBarry Smith This occurs when SNESSet/GetNPC() is used with a SNES that does not have a user provided 406cca7ec1eSBarry Smith DM attached to it since the inner SNES (which shares the DM with the outer SNES) tries 407cca7ec1eSBarry Smith to set its input vector (which is associated with the DM) as the base global vector. 408cca7ec1eSBarry Smith Thanks to Juan P. Mendez Granado Re: [petsc-maint] Nonlinear conjugate gradien 409cca7ec1eSBarry Smith for pointing out the problem. 410cca7ec1eSBarry Smith */ 411cca7ec1eSBarry Smith if (vdm == dm) PetscFunctionReturn(0); 412fe1899a2SJed Brown ierr = PetscObjectReference((PetscObject)X);CHKERRQ(ierr); 413fe1899a2SJed Brown ierr = VecDestroy(&shell->Xglobal);CHKERRQ(ierr); 414fe1899a2SJed Brown shell->Xglobal = X; 415fe1899a2SJed Brown PetscFunctionReturn(0); 416fe1899a2SJed Brown } 417fe1899a2SJed Brown 418fe1899a2SJed Brown /*@C 419fe1899a2SJed Brown DMShellSetCreateGlobalVector - sets the routine to create a global vector associated with the shell DM 420fe1899a2SJed Brown 421fe1899a2SJed Brown Logically Collective 422fe1899a2SJed Brown 423fe1899a2SJed Brown Input Arguments: 424fe1899a2SJed Brown + dm - the shell DM 425fe1899a2SJed Brown - func - the creation routine 426fe1899a2SJed Brown 427fe1899a2SJed Brown Level: advanced 428fe1899a2SJed Brown 429fef3a512SBarry Smith .seealso: DMShellSetGlobalVector(), DMShellSetCreateMatrix(), DMShellSetContext(), DMShellGetContext() 430fe1899a2SJed Brown @*/ 431fe1899a2SJed Brown PetscErrorCode DMShellSetCreateGlobalVector(DM dm,PetscErrorCode (*func)(DM,Vec*)) 432fe1899a2SJed Brown { 433fe1899a2SJed Brown 434fe1899a2SJed Brown PetscFunctionBegin; 435fe1899a2SJed Brown PetscValidHeaderSpecific(dm,DM_CLASSID,1); 436fe1899a2SJed Brown dm->ops->createglobalvector = func; 437fe1899a2SJed Brown PetscFunctionReturn(0); 438fe1899a2SJed Brown } 439fe1899a2SJed Brown 440dc43b69eSJed Brown /*@ 441dc43b69eSJed Brown DMShellSetLocalVector - sets a template local vector associated with the DMShell 442dc43b69eSJed Brown 443d083f849SBarry Smith Logically Collective on dm 444dc43b69eSJed Brown 445dc43b69eSJed Brown Input Arguments: 446dc43b69eSJed Brown + dm - shell DM 447dc43b69eSJed Brown - X - template vector 448dc43b69eSJed Brown 449dc43b69eSJed Brown Level: advanced 450dc43b69eSJed Brown 451dc43b69eSJed Brown .seealso: DMCreateLocalVector(), DMShellSetMatrix(), DMShellSetCreateLocalVector() 452dc43b69eSJed Brown @*/ 453dc43b69eSJed Brown PetscErrorCode DMShellSetLocalVector(DM dm,Vec X) 454dc43b69eSJed Brown { 455dc43b69eSJed Brown DM_Shell *shell = (DM_Shell*)dm->data; 456dc43b69eSJed Brown PetscErrorCode ierr; 457dc43b69eSJed Brown PetscBool isshell; 458cca7ec1eSBarry Smith DM vdm; 459dc43b69eSJed Brown 460dc43b69eSJed Brown PetscFunctionBegin; 461dc43b69eSJed Brown PetscValidHeaderSpecific(dm,DM_CLASSID,1); 462dc43b69eSJed Brown PetscValidHeaderSpecific(X,VEC_CLASSID,2); 463dc43b69eSJed Brown ierr = PetscObjectTypeCompare((PetscObject)dm,DMSHELL,&isshell);CHKERRQ(ierr); 464dc43b69eSJed Brown if (!isshell) PetscFunctionReturn(0); 465cca7ec1eSBarry Smith ierr = VecGetDM(X,&vdm);CHKERRQ(ierr); 466cca7ec1eSBarry Smith /* 467cca7ec1eSBarry Smith if the vector proposed as the new base global vector for the DM is a DM vector associated 468cca7ec1eSBarry 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 469cca7ec1eSBarry Smith we get a circular dependency that prevents the DM from being destroy when it should be. 470cca7ec1eSBarry Smith This occurs when SNESSet/GetNPC() is used with a SNES that does not have a user provided 471cca7ec1eSBarry Smith DM attached to it since the inner SNES (which shares the DM with the outer SNES) tries 472cca7ec1eSBarry Smith to set its input vector (which is associated with the DM) as the base global vector. 473cca7ec1eSBarry Smith Thanks to Juan P. Mendez Granado Re: [petsc-maint] Nonlinear conjugate gradien 474cca7ec1eSBarry Smith for pointing out the problem. 475cca7ec1eSBarry Smith */ 476cca7ec1eSBarry Smith if (vdm == dm) PetscFunctionReturn(0); 477dc43b69eSJed Brown ierr = PetscObjectReference((PetscObject)X);CHKERRQ(ierr); 478dc43b69eSJed Brown ierr = VecDestroy(&shell->Xlocal);CHKERRQ(ierr); 479dc43b69eSJed Brown shell->Xlocal = X; 480dc43b69eSJed Brown PetscFunctionReturn(0); 481dc43b69eSJed Brown } 482dc43b69eSJed Brown 483dc43b69eSJed Brown /*@C 484dc43b69eSJed Brown DMShellSetCreateLocalVector - sets the routine to create a local vector associated with the shell DM 485dc43b69eSJed Brown 486dc43b69eSJed Brown Logically Collective 487dc43b69eSJed Brown 488dc43b69eSJed Brown Input Arguments: 489dc43b69eSJed Brown + dm - the shell DM 490dc43b69eSJed Brown - func - the creation routine 491dc43b69eSJed Brown 492dc43b69eSJed Brown Level: advanced 493dc43b69eSJed Brown 494fef3a512SBarry Smith .seealso: DMShellSetLocalVector(), DMShellSetCreateMatrix(), DMShellSetContext(), DMShellGetContext() 495dc43b69eSJed Brown @*/ 496dc43b69eSJed Brown PetscErrorCode DMShellSetCreateLocalVector(DM dm,PetscErrorCode (*func)(DM,Vec*)) 497dc43b69eSJed Brown { 498dc43b69eSJed Brown PetscFunctionBegin; 499dc43b69eSJed Brown PetscValidHeaderSpecific(dm,DM_CLASSID,1); 500dc43b69eSJed Brown dm->ops->createlocalvector = func; 501dc43b69eSJed Brown PetscFunctionReturn(0); 502dc43b69eSJed Brown } 503dc43b69eSJed Brown 5048339e6d0SRichard Tran Mills /*@C 5058339e6d0SRichard Tran Mills DMShellSetGlobalToLocal - Sets the routines used to perform a global to local scatter 5068339e6d0SRichard Tran Mills 507d083f849SBarry Smith Logically Collective on dm 5088339e6d0SRichard Tran Mills 5098339e6d0SRichard Tran Mills Input Arguments 5108339e6d0SRichard Tran Mills + dm - the shell DM 5118339e6d0SRichard Tran Mills . begin - the routine that begins the global to local scatter 5128339e6d0SRichard Tran Mills - end - the routine that ends the global to local scatter 5138339e6d0SRichard Tran Mills 51495452b02SPatrick Sanan Notes: 51595452b02SPatrick Sanan If these functions are not provided but DMShellSetGlobalToLocalVecScatter() is called then 516f3db62a7SRichard Tran Mills DMGlobalToLocalBeginDefaultShell()/DMGlobalToLocalEndDefaultShell() are used to to perform the transfers 5177a108d1dSBarry Smith 5188339e6d0SRichard Tran Mills Level: advanced 5198339e6d0SRichard Tran Mills 5207a108d1dSBarry Smith .seealso: DMShellSetLocalToGlobal(), DMGlobalToLocalBeginDefaultShell(), DMGlobalToLocalEndDefaultShell() 5218339e6d0SRichard Tran Mills @*/ 5228339e6d0SRichard Tran Mills PetscErrorCode DMShellSetGlobalToLocal(DM dm,PetscErrorCode (*begin)(DM,Vec,InsertMode,Vec),PetscErrorCode (*end)(DM,Vec,InsertMode,Vec)) { 5238339e6d0SRichard Tran Mills PetscFunctionBegin; 524*2d1bcd87SStefano Zampini PetscValidHeaderSpecific(dm,DM_CLASSID,1); 5258339e6d0SRichard Tran Mills dm->ops->globaltolocalbegin = begin; 5268339e6d0SRichard Tran Mills dm->ops->globaltolocalend = end; 5278339e6d0SRichard Tran Mills PetscFunctionReturn(0); 5288339e6d0SRichard Tran Mills } 5298339e6d0SRichard Tran Mills 5308339e6d0SRichard Tran Mills /*@C 5318339e6d0SRichard Tran Mills DMShellSetLocalToGlobal - Sets the routines used to perform a local to global scatter 5328339e6d0SRichard Tran Mills 533d083f849SBarry Smith Logically Collective on dm 5348339e6d0SRichard Tran Mills 5358339e6d0SRichard Tran Mills Input Arguments 5368339e6d0SRichard Tran Mills + dm - the shell DM 5378339e6d0SRichard Tran Mills . begin - the routine that begins the local to global scatter 5388339e6d0SRichard Tran Mills - end - the routine that ends the local to global scatter 5398339e6d0SRichard Tran Mills 54095452b02SPatrick Sanan Notes: 54195452b02SPatrick Sanan If these functions are not provided but DMShellSetLocalToGlobalVecScatter() is called then 542f3db62a7SRichard Tran Mills DMLocalToGlobalBeginDefaultShell()/DMLocalToGlobalEndDefaultShell() are used to to perform the transfers 543f3db62a7SRichard Tran Mills 5448339e6d0SRichard Tran Mills Level: advanced 5458339e6d0SRichard Tran Mills 5468339e6d0SRichard Tran Mills .seealso: DMShellSetGlobalToLocal() 5478339e6d0SRichard Tran Mills @*/ 5488339e6d0SRichard Tran Mills PetscErrorCode DMShellSetLocalToGlobal(DM dm,PetscErrorCode (*begin)(DM,Vec,InsertMode,Vec),PetscErrorCode (*end)(DM,Vec,InsertMode,Vec)) { 5498339e6d0SRichard Tran Mills PetscFunctionBegin; 550*2d1bcd87SStefano Zampini PetscValidHeaderSpecific(dm,DM_CLASSID,1); 5518339e6d0SRichard Tran Mills dm->ops->localtoglobalbegin = begin; 5528339e6d0SRichard Tran Mills dm->ops->localtoglobalend = end; 5538339e6d0SRichard Tran Mills PetscFunctionReturn(0); 5548339e6d0SRichard Tran Mills } 5558339e6d0SRichard Tran Mills 556f3db62a7SRichard Tran Mills /*@C 557f3db62a7SRichard Tran Mills DMShellSetLocalToLocal - Sets the routines used to perform a local to local scatter 558f3db62a7SRichard Tran Mills 559d083f849SBarry Smith Logically Collective on dm 560f3db62a7SRichard Tran Mills 561f3db62a7SRichard Tran Mills Input Arguments 562f3db62a7SRichard Tran Mills + dm - the shell DM 563f3db62a7SRichard Tran Mills . begin - the routine that begins the local to local scatter 564f3db62a7SRichard Tran Mills - end - the routine that ends the local to local scatter 565f3db62a7SRichard Tran Mills 56695452b02SPatrick Sanan Notes: 56795452b02SPatrick Sanan If these functions are not provided but DMShellSetLocalToLocalVecScatter() is called then 568f3db62a7SRichard Tran Mills DMLocalToLocalBeginDefaultShell()/DMLocalToLocalEndDefaultShell() are used to to perform the transfers 569f3db62a7SRichard Tran Mills 570f3db62a7SRichard Tran Mills Level: advanced 571f3db62a7SRichard Tran Mills 572f3db62a7SRichard Tran Mills .seealso: DMShellSetGlobalToLocal(), DMLocalToLocalBeginDefaultShell(), DMLocalToLocalEndDefaultShell() 573f3db62a7SRichard Tran Mills @*/ 574f3db62a7SRichard Tran Mills PetscErrorCode DMShellSetLocalToLocal(DM dm,PetscErrorCode (*begin)(DM,Vec,InsertMode,Vec),PetscErrorCode (*end)(DM,Vec,InsertMode,Vec)) { 575f3db62a7SRichard Tran Mills PetscFunctionBegin; 576*2d1bcd87SStefano Zampini PetscValidHeaderSpecific(dm,DM_CLASSID,1); 577f3db62a7SRichard Tran Mills dm->ops->localtolocalbegin = begin; 578f3db62a7SRichard Tran Mills dm->ops->localtolocalend = end; 579f3db62a7SRichard Tran Mills PetscFunctionReturn(0); 580f3db62a7SRichard Tran Mills } 581f3db62a7SRichard Tran Mills 58281634712SRichard Tran Mills /*@ 58381634712SRichard Tran Mills DMShellSetGlobalToLocalVecScatter - Sets a VecScatter context for global to local communication 58481634712SRichard Tran Mills 585d083f849SBarry Smith Logically Collective on dm 58681634712SRichard Tran Mills 58781634712SRichard Tran Mills Input Arguments 58881634712SRichard Tran Mills + dm - the shell DM 58981634712SRichard Tran Mills - gtol - the global to local VecScatter context 59081634712SRichard Tran Mills 59181634712SRichard Tran Mills Level: advanced 59281634712SRichard Tran Mills 593f3db62a7SRichard Tran Mills .seealso: DMShellSetGlobalToLocal(), DMGlobalToLocalBeginDefaultShell(), DMGlobalToLocalEndDefaultShell() 59481634712SRichard Tran Mills @*/ 595a94b16f6SRichard Tran Mills PetscErrorCode DMShellSetGlobalToLocalVecScatter(DM dm, VecScatter gtol) 59681634712SRichard Tran Mills { 59781634712SRichard Tran Mills DM_Shell *shell = (DM_Shell*)dm->data; 598d885d199SRichard Tran Mills PetscErrorCode ierr; 59981634712SRichard Tran Mills 600b300e4a8SRichard Tran Mills PetscFunctionBegin; 601*2d1bcd87SStefano Zampini PetscValidHeaderSpecific(dm,DM_CLASSID,1); 602*2d1bcd87SStefano Zampini PetscValidHeaderSpecific(gtol,VEC_SCATTER_CLASSID,2); 603d885d199SRichard Tran Mills ierr = PetscObjectReference((PetscObject)gtol);CHKERRQ(ierr); 604d885d199SRichard Tran Mills ierr = VecScatterDestroy(&shell->gtol);CHKERRQ(ierr); 60581634712SRichard Tran Mills shell->gtol = gtol; 60681634712SRichard Tran Mills PetscFunctionReturn(0); 60781634712SRichard Tran Mills } 60881634712SRichard Tran Mills 609988ea7d6SRichard Tran Mills /*@ 610988ea7d6SRichard Tran Mills DMShellSetLocalToGlobalVecScatter - Sets a VecScatter context for local to global communication 611988ea7d6SRichard Tran Mills 612d083f849SBarry Smith Logically Collective on dm 613988ea7d6SRichard Tran Mills 614988ea7d6SRichard Tran Mills Input Arguments 615988ea7d6SRichard Tran Mills + dm - the shell DM 616988ea7d6SRichard Tran Mills - ltog - the local to global VecScatter context 617988ea7d6SRichard Tran Mills 618988ea7d6SRichard Tran Mills Level: advanced 619988ea7d6SRichard Tran Mills 620f3db62a7SRichard Tran Mills .seealso: DMShellSetLocalToGlobal(), DMLocalToGlobalBeginDefaultShell(), DMLocalToGlobalEndDefaultShell() 621988ea7d6SRichard Tran Mills @*/ 622a94b16f6SRichard Tran Mills PetscErrorCode DMShellSetLocalToGlobalVecScatter(DM dm, VecScatter ltog) 623988ea7d6SRichard Tran Mills { 624988ea7d6SRichard Tran Mills DM_Shell *shell = (DM_Shell*)dm->data; 625d885d199SRichard Tran Mills PetscErrorCode ierr; 626988ea7d6SRichard Tran Mills 627988ea7d6SRichard Tran Mills PetscFunctionBegin; 628*2d1bcd87SStefano Zampini PetscValidHeaderSpecific(dm,DM_CLASSID,1); 629*2d1bcd87SStefano Zampini PetscValidHeaderSpecific(ltog,VEC_SCATTER_CLASSID,2); 630d885d199SRichard Tran Mills ierr = PetscObjectReference((PetscObject)ltog);CHKERRQ(ierr); 631d885d199SRichard Tran Mills ierr = VecScatterDestroy(&shell->ltog);CHKERRQ(ierr); 632988ea7d6SRichard Tran Mills shell->ltog = ltog; 633988ea7d6SRichard Tran Mills PetscFunctionReturn(0); 634988ea7d6SRichard Tran Mills } 635988ea7d6SRichard Tran Mills 636f3db62a7SRichard Tran Mills /*@ 637f3db62a7SRichard Tran Mills DMShellSetLocalToLocalVecScatter - Sets a VecScatter context for local to local communication 638f3db62a7SRichard Tran Mills 639d083f849SBarry Smith Logically Collective on dm 640f3db62a7SRichard Tran Mills 641f3db62a7SRichard Tran Mills Input Arguments 642f3db62a7SRichard Tran Mills + dm - the shell DM 643f3db62a7SRichard Tran Mills - ltol - the local to local VecScatter context 644f3db62a7SRichard Tran Mills 645f3db62a7SRichard Tran Mills Level: advanced 646f3db62a7SRichard Tran Mills 647f3db62a7SRichard Tran Mills .seealso: DMShellSetLocalToLocal(), DMLocalToLocalBeginDefaultShell(), DMLocalToLocalEndDefaultShell() 648f3db62a7SRichard Tran Mills @*/ 649f3db62a7SRichard Tran Mills PetscErrorCode DMShellSetLocalToLocalVecScatter(DM dm, VecScatter ltol) 650f3db62a7SRichard Tran Mills { 651f3db62a7SRichard Tran Mills DM_Shell *shell = (DM_Shell*)dm->data; 652f3db62a7SRichard Tran Mills PetscErrorCode ierr; 653f3db62a7SRichard Tran Mills 654f3db62a7SRichard Tran Mills PetscFunctionBegin; 655*2d1bcd87SStefano Zampini PetscValidHeaderSpecific(dm,DM_CLASSID,1); 656*2d1bcd87SStefano Zampini PetscValidHeaderSpecific(ltol,VEC_SCATTER_CLASSID,2); 657f3db62a7SRichard Tran Mills ierr = PetscObjectReference((PetscObject)ltol);CHKERRQ(ierr); 658f3db62a7SRichard Tran Mills ierr = VecScatterDestroy(&shell->ltol);CHKERRQ(ierr); 659f3db62a7SRichard Tran Mills shell->ltol = ltol; 660f3db62a7SRichard Tran Mills PetscFunctionReturn(0); 661f3db62a7SRichard Tran Mills } 662f3db62a7SRichard Tran Mills 6639bf9660cSLawrence Mitchell /*@C 6649bf9660cSLawrence Mitchell DMShellSetCoarsen - Set the routine used to coarsen the shell DM 6659bf9660cSLawrence Mitchell 666d083f849SBarry Smith Logically Collective on dm 6679bf9660cSLawrence Mitchell 6689bf9660cSLawrence Mitchell Input Arguments 6699bf9660cSLawrence Mitchell + dm - the shell DM 6709bf9660cSLawrence Mitchell - coarsen - the routine that coarsens the DM 6719bf9660cSLawrence Mitchell 6729bf9660cSLawrence Mitchell Level: advanced 6739bf9660cSLawrence Mitchell 674bf890c61SBoris Boutkov .seealso: DMShellSetRefine(), DMCoarsen(), DMShellGetCoarsen(), DMShellSetContext(), DMShellGetContext() 6759bf9660cSLawrence Mitchell @*/ 676f572501eSLawrence Mitchell PetscErrorCode DMShellSetCoarsen(DM dm, PetscErrorCode (*coarsen)(DM,MPI_Comm,DM*)) 677f572501eSLawrence Mitchell { 678f572501eSLawrence Mitchell PetscErrorCode ierr; 679f572501eSLawrence Mitchell PetscBool isshell; 680f572501eSLawrence Mitchell 681f572501eSLawrence Mitchell PetscFunctionBegin; 682f572501eSLawrence Mitchell PetscValidHeaderSpecific(dm,DM_CLASSID,1); 683f572501eSLawrence Mitchell ierr = PetscObjectTypeCompare((PetscObject)dm,DMSHELL,&isshell);CHKERRQ(ierr); 684f572501eSLawrence Mitchell if (!isshell) PetscFunctionReturn(0); 685f572501eSLawrence Mitchell dm->ops->coarsen = coarsen; 686f572501eSLawrence Mitchell PetscFunctionReturn(0); 687f572501eSLawrence Mitchell } 688f572501eSLawrence Mitchell 6899bf9660cSLawrence Mitchell /*@C 6904363ddcaSBoris Boutkov DMShellGetCoarsen - Get the routine used to coarsen the shell DM 6914363ddcaSBoris Boutkov 692d083f849SBarry Smith Logically Collective on dm 6934363ddcaSBoris Boutkov 694a4a986ddSBoris Boutkov Input Argument: 6954363ddcaSBoris Boutkov . dm - the shell DM 6964363ddcaSBoris Boutkov 697a4a986ddSBoris Boutkov Output Argument: 6984363ddcaSBoris Boutkov . coarsen - the routine that coarsens the DM 6994363ddcaSBoris Boutkov 7004363ddcaSBoris Boutkov Level: advanced 7014363ddcaSBoris Boutkov 7024363ddcaSBoris Boutkov .seealso: DMShellSetCoarsen(), DMCoarsen(), DMShellSetRefine(), DMRefine() 7034363ddcaSBoris Boutkov @*/ 7044363ddcaSBoris Boutkov PetscErrorCode DMShellGetCoarsen(DM dm, PetscErrorCode (**coarsen)(DM,MPI_Comm,DM*)) 7054363ddcaSBoris Boutkov { 7064363ddcaSBoris Boutkov PetscErrorCode ierr; 7074363ddcaSBoris Boutkov PetscBool isshell; 7084363ddcaSBoris Boutkov 7094363ddcaSBoris Boutkov PetscFunctionBegin; 7104363ddcaSBoris Boutkov PetscValidHeaderSpecific(dm,DM_CLASSID,1); 7114363ddcaSBoris Boutkov ierr = PetscObjectTypeCompare((PetscObject)dm,DMSHELL,&isshell);CHKERRQ(ierr); 7128dd90dd5SBoris Boutkov if (!isshell) SETERRQ(PetscObjectComm((PetscObject)dm),PETSC_ERR_SUP,"Can only use with DMSHELL type DMs"); 7134363ddcaSBoris Boutkov *coarsen = dm->ops->coarsen; 7144363ddcaSBoris Boutkov PetscFunctionReturn(0); 7154363ddcaSBoris Boutkov } 7164363ddcaSBoris Boutkov 7174363ddcaSBoris Boutkov /*@C 7189bf9660cSLawrence Mitchell DMShellSetRefine - Set the routine used to refine the shell DM 7199bf9660cSLawrence Mitchell 720d083f849SBarry Smith Logically Collective on dm 7219bf9660cSLawrence Mitchell 7229bf9660cSLawrence Mitchell Input Arguments 7239bf9660cSLawrence Mitchell + dm - the shell DM 7249bf9660cSLawrence Mitchell - refine - the routine that refines the DM 7259bf9660cSLawrence Mitchell 7269bf9660cSLawrence Mitchell Level: advanced 7279bf9660cSLawrence Mitchell 728bf890c61SBoris Boutkov .seealso: DMShellSetCoarsen(), DMRefine(), DMShellGetRefine(), DMShellSetContext(), DMShellGetContext() 7299bf9660cSLawrence Mitchell @*/ 730f572501eSLawrence Mitchell PetscErrorCode DMShellSetRefine(DM dm, PetscErrorCode (*refine)(DM,MPI_Comm,DM*)) 731f572501eSLawrence Mitchell { 732f572501eSLawrence Mitchell PetscErrorCode ierr; 733f572501eSLawrence Mitchell PetscBool isshell; 734f572501eSLawrence Mitchell 735f572501eSLawrence Mitchell PetscFunctionBegin; 736f572501eSLawrence Mitchell PetscValidHeaderSpecific(dm,DM_CLASSID,1); 737f572501eSLawrence Mitchell ierr = PetscObjectTypeCompare((PetscObject)dm,DMSHELL,&isshell);CHKERRQ(ierr); 738f572501eSLawrence Mitchell if (!isshell) PetscFunctionReturn(0); 739f572501eSLawrence Mitchell dm->ops->refine = refine; 740f572501eSLawrence Mitchell PetscFunctionReturn(0); 741f572501eSLawrence Mitchell } 742f572501eSLawrence Mitchell 7439bf9660cSLawrence Mitchell /*@C 7444363ddcaSBoris Boutkov DMShellGetRefine - Get the routine used to refine the shell DM 7454363ddcaSBoris Boutkov 746d083f849SBarry Smith Logically Collective on dm 7474363ddcaSBoris Boutkov 748a4a986ddSBoris Boutkov Input Argument: 7494363ddcaSBoris Boutkov . dm - the shell DM 7504363ddcaSBoris Boutkov 751a4a986ddSBoris Boutkov Output Argument: 7524363ddcaSBoris Boutkov . refine - the routine that refines the DM 7534363ddcaSBoris Boutkov 7544363ddcaSBoris Boutkov Level: advanced 7554363ddcaSBoris Boutkov 7564363ddcaSBoris Boutkov .seealso: DMShellSetCoarsen(), DMCoarsen(), DMShellSetRefine(), DMRefine() 7574363ddcaSBoris Boutkov @*/ 7584363ddcaSBoris Boutkov PetscErrorCode DMShellGetRefine(DM dm, PetscErrorCode (**refine)(DM,MPI_Comm,DM*)) 7594363ddcaSBoris Boutkov { 7604363ddcaSBoris Boutkov PetscErrorCode ierr; 7614363ddcaSBoris Boutkov PetscBool isshell; 7624363ddcaSBoris Boutkov 7634363ddcaSBoris Boutkov PetscFunctionBegin; 7644363ddcaSBoris Boutkov PetscValidHeaderSpecific(dm,DM_CLASSID,1); 7654363ddcaSBoris Boutkov ierr = PetscObjectTypeCompare((PetscObject)dm,DMSHELL,&isshell);CHKERRQ(ierr); 7668dd90dd5SBoris Boutkov if (!isshell) SETERRQ(PetscObjectComm((PetscObject)dm),PETSC_ERR_SUP,"Can only use with DMSHELL type DMs"); 7674363ddcaSBoris Boutkov *refine = dm->ops->refine; 7684363ddcaSBoris Boutkov PetscFunctionReturn(0); 7694363ddcaSBoris Boutkov } 7704363ddcaSBoris Boutkov 7714363ddcaSBoris Boutkov /*@C 7729bf9660cSLawrence Mitchell DMShellSetCreateInterpolation - Set the routine used to create the interpolation operator 7739bf9660cSLawrence Mitchell 774d083f849SBarry Smith Logically Collective on dm 7759bf9660cSLawrence Mitchell 7769bf9660cSLawrence Mitchell Input Arguments 7779bf9660cSLawrence Mitchell + dm - the shell DM 7789bf9660cSLawrence Mitchell - interp - the routine to create the interpolation 7799bf9660cSLawrence Mitchell 7809bf9660cSLawrence Mitchell Level: advanced 7819bf9660cSLawrence Mitchell 782bf890c61SBoris Boutkov .seealso: DMShellSetCreateInjection(), DMCreateInterpolation(), DMShellGetCreateInterpolation(), DMShellSetCreateRestriction(), DMShellSetContext(), DMShellGetContext() 7839bf9660cSLawrence Mitchell @*/ 784f572501eSLawrence Mitchell PetscErrorCode DMShellSetCreateInterpolation(DM dm, PetscErrorCode (*interp)(DM,DM,Mat*,Vec*)) 785f572501eSLawrence Mitchell { 786f572501eSLawrence Mitchell PetscErrorCode ierr; 787f572501eSLawrence Mitchell PetscBool isshell; 788f572501eSLawrence Mitchell 789f572501eSLawrence Mitchell PetscFunctionBegin; 790f572501eSLawrence Mitchell PetscValidHeaderSpecific(dm,DM_CLASSID,1); 791f572501eSLawrence Mitchell ierr = PetscObjectTypeCompare((PetscObject)dm,DMSHELL,&isshell);CHKERRQ(ierr); 792f572501eSLawrence Mitchell if (!isshell) PetscFunctionReturn(0); 793f572501eSLawrence Mitchell dm->ops->createinterpolation = interp; 794f572501eSLawrence Mitchell PetscFunctionReturn(0); 795f572501eSLawrence Mitchell } 796f572501eSLawrence Mitchell 7973ad4599aSBarry Smith /*@C 7984363ddcaSBoris Boutkov DMShellGetCreateInterpolation - Get the routine used to create the interpolation operator 7994363ddcaSBoris Boutkov 800d083f849SBarry Smith Logically Collective on dm 8014363ddcaSBoris Boutkov 802a4a986ddSBoris Boutkov Input Argument: 8034363ddcaSBoris Boutkov + dm - the shell DM 804a4a986ddSBoris Boutkov 805a4a986ddSBoris Boutkov Output Argument: 8064363ddcaSBoris Boutkov - interp - the routine to create the interpolation 8074363ddcaSBoris Boutkov 8084363ddcaSBoris Boutkov Level: advanced 8094363ddcaSBoris Boutkov 8104363ddcaSBoris Boutkov .seealso: DMShellGetCreateInjection(), DMCreateInterpolation(), DMShellGetCreateRestriction(), DMShellSetContext(), DMShellGetContext() 8114363ddcaSBoris Boutkov @*/ 8124363ddcaSBoris Boutkov PetscErrorCode DMShellGetCreateInterpolation(DM dm, PetscErrorCode (**interp)(DM,DM,Mat*,Vec*)) 8134363ddcaSBoris Boutkov { 8144363ddcaSBoris Boutkov PetscErrorCode ierr; 8154363ddcaSBoris Boutkov PetscBool isshell; 8164363ddcaSBoris Boutkov 8174363ddcaSBoris Boutkov PetscFunctionBegin; 8184363ddcaSBoris Boutkov PetscValidHeaderSpecific(dm,DM_CLASSID,1); 8194363ddcaSBoris Boutkov ierr = PetscObjectTypeCompare((PetscObject)dm,DMSHELL,&isshell);CHKERRQ(ierr); 8208dd90dd5SBoris Boutkov if (!isshell) SETERRQ(PetscObjectComm((PetscObject)dm),PETSC_ERR_SUP,"Can only use with DMSHELL type DMs"); 8214363ddcaSBoris Boutkov *interp = dm->ops->createinterpolation; 8224363ddcaSBoris Boutkov PetscFunctionReturn(0); 8234363ddcaSBoris Boutkov } 8244363ddcaSBoris Boutkov 8254363ddcaSBoris Boutkov /*@C 8263ad4599aSBarry Smith DMShellSetCreateRestriction - Set the routine used to create the restriction operator 8273ad4599aSBarry Smith 828d083f849SBarry Smith Logically Collective on dm 8293ad4599aSBarry Smith 8303ad4599aSBarry Smith Input Arguments 8313ad4599aSBarry Smith + dm - the shell DM 8323ad4599aSBarry Smith - striction- the routine to create the restriction 8333ad4599aSBarry Smith 8343ad4599aSBarry Smith Level: advanced 8353ad4599aSBarry Smith 836bf890c61SBoris Boutkov .seealso: DMShellSetCreateInjection(), DMCreateInterpolation(), DMShellGetCreateRestriction(), DMShellSetContext(), DMShellGetContext() 8373ad4599aSBarry Smith @*/ 8383ad4599aSBarry Smith PetscErrorCode DMShellSetCreateRestriction(DM dm, PetscErrorCode (*restriction)(DM,DM,Mat*)) 8393ad4599aSBarry Smith { 8403ad4599aSBarry Smith PetscErrorCode ierr; 8413ad4599aSBarry Smith PetscBool isshell; 8423ad4599aSBarry Smith 8433ad4599aSBarry Smith PetscFunctionBegin; 8443ad4599aSBarry Smith PetscValidHeaderSpecific(dm,DM_CLASSID,1); 8453ad4599aSBarry Smith ierr = PetscObjectTypeCompare((PetscObject)dm,DMSHELL,&isshell);CHKERRQ(ierr); 8463ad4599aSBarry Smith if (!isshell) PetscFunctionReturn(0); 8473ad4599aSBarry Smith dm->ops->createrestriction = restriction; 8483ad4599aSBarry Smith PetscFunctionReturn(0); 8493ad4599aSBarry Smith } 8503ad4599aSBarry Smith 8519bf9660cSLawrence Mitchell /*@C 8524363ddcaSBoris Boutkov DMShellGetCreateRestriction - Get the routine used to create the restriction operator 8534363ddcaSBoris Boutkov 854d083f849SBarry Smith Logically Collective on dm 8554363ddcaSBoris Boutkov 856a4a986ddSBoris Boutkov Input Argument: 8574363ddcaSBoris Boutkov + dm - the shell DM 858a4a986ddSBoris Boutkov 859a4a986ddSBoris Boutkov Output Argument: 860a4a986ddSBoris Boutkov - restriction - the routine to create the restriction 8614363ddcaSBoris Boutkov 8624363ddcaSBoris Boutkov Level: advanced 8634363ddcaSBoris Boutkov 8644363ddcaSBoris Boutkov .seealso: DMShellSetCreateInjection(), DMCreateInterpolation(), DMShellSetContext(), DMShellGetContext() 8654363ddcaSBoris Boutkov @*/ 8664363ddcaSBoris Boutkov PetscErrorCode DMShellGetCreateRestriction(DM dm, PetscErrorCode (**restriction)(DM,DM,Mat*)) 8674363ddcaSBoris Boutkov { 8684363ddcaSBoris Boutkov PetscErrorCode ierr; 8694363ddcaSBoris Boutkov PetscBool isshell; 8704363ddcaSBoris Boutkov 8714363ddcaSBoris Boutkov PetscFunctionBegin; 8724363ddcaSBoris Boutkov PetscValidHeaderSpecific(dm,DM_CLASSID,1); 8734363ddcaSBoris Boutkov ierr = PetscObjectTypeCompare((PetscObject)dm,DMSHELL,&isshell);CHKERRQ(ierr); 8748dd90dd5SBoris Boutkov if (!isshell) SETERRQ(PetscObjectComm((PetscObject)dm),PETSC_ERR_SUP,"Can only use with DMSHELL type DMs"); 8754363ddcaSBoris Boutkov *restriction = dm->ops->createrestriction; 8764363ddcaSBoris Boutkov PetscFunctionReturn(0); 8774363ddcaSBoris Boutkov } 8784363ddcaSBoris Boutkov 8794363ddcaSBoris Boutkov /*@C 8809bf9660cSLawrence Mitchell DMShellSetCreateInjection - Set the routine used to create the injection operator 8819bf9660cSLawrence Mitchell 882d083f849SBarry Smith Logically Collective on dm 8839bf9660cSLawrence Mitchell 8849bf9660cSLawrence Mitchell Input Arguments 8859bf9660cSLawrence Mitchell + dm - the shell DM 8869bf9660cSLawrence Mitchell - inject - the routine to create the injection 8879bf9660cSLawrence Mitchell 8889bf9660cSLawrence Mitchell Level: advanced 8899bf9660cSLawrence Mitchell 890bf890c61SBoris Boutkov .seealso: DMShellSetCreateInterpolation(), DMCreateInjection(), DMShellGetCreateInjection(), DMShellSetContext(), DMShellGetContext() 8919bf9660cSLawrence Mitchell @*/ 892f572501eSLawrence Mitchell PetscErrorCode DMShellSetCreateInjection(DM dm, PetscErrorCode (*inject)(DM,DM,Mat*)) 893f572501eSLawrence Mitchell { 894f572501eSLawrence Mitchell PetscErrorCode ierr; 895f572501eSLawrence Mitchell PetscBool isshell; 896f572501eSLawrence Mitchell 897f572501eSLawrence Mitchell PetscFunctionBegin; 898f572501eSLawrence Mitchell PetscValidHeaderSpecific(dm,DM_CLASSID,1); 899f572501eSLawrence Mitchell ierr = PetscObjectTypeCompare((PetscObject)dm,DMSHELL,&isshell);CHKERRQ(ierr); 900f572501eSLawrence Mitchell if (!isshell) PetscFunctionReturn(0); 9015a84ad33SLisandro Dalcin dm->ops->createinjection = inject; 902f572501eSLawrence Mitchell PetscFunctionReturn(0); 903f572501eSLawrence Mitchell } 904f572501eSLawrence Mitchell 9054363ddcaSBoris Boutkov /*@C 9064363ddcaSBoris Boutkov DMShellGetCreateInjection - Get the routine used to create the injection operator 9074363ddcaSBoris Boutkov 908d083f849SBarry Smith Logically Collective on dm 9094363ddcaSBoris Boutkov 910a4a986ddSBoris Boutkov Input Argument: 9114363ddcaSBoris Boutkov + dm - the shell DM 912a4a986ddSBoris Boutkov 913a4a986ddSBoris Boutkov Output Argument: 9144363ddcaSBoris Boutkov - inject - the routine to create the injection 9154363ddcaSBoris Boutkov 9164363ddcaSBoris Boutkov Level: advanced 9174363ddcaSBoris Boutkov 9184363ddcaSBoris Boutkov .seealso: DMShellGetCreateInterpolation(), DMCreateInjection(), DMShellSetContext(), DMShellGetContext() 9194363ddcaSBoris Boutkov @*/ 9204363ddcaSBoris Boutkov PetscErrorCode DMShellGetCreateInjection(DM dm, PetscErrorCode (**inject)(DM,DM,Mat*)) 9214363ddcaSBoris Boutkov { 9224363ddcaSBoris Boutkov PetscErrorCode ierr; 9234363ddcaSBoris Boutkov PetscBool isshell; 9244363ddcaSBoris Boutkov 9254363ddcaSBoris Boutkov PetscFunctionBegin; 9264363ddcaSBoris Boutkov PetscValidHeaderSpecific(dm,DM_CLASSID,1); 9274363ddcaSBoris Boutkov ierr = PetscObjectTypeCompare((PetscObject)dm,DMSHELL,&isshell);CHKERRQ(ierr); 9288dd90dd5SBoris Boutkov if (!isshell) SETERRQ(PetscObjectComm((PetscObject)dm),PETSC_ERR_SUP,"Can only use with DMSHELL type DMs"); 9295a84ad33SLisandro Dalcin *inject = dm->ops->createinjection; 9304363ddcaSBoris Boutkov PetscFunctionReturn(0); 9314363ddcaSBoris Boutkov } 9324363ddcaSBoris Boutkov 9339bf9660cSLawrence Mitchell /*@C 9349bf9660cSLawrence Mitchell DMShellSetCreateFieldDecomposition - Set the routine used to create a decomposition of fields for the shell DM 9359bf9660cSLawrence Mitchell 936d083f849SBarry Smith Logically Collective on dm 9379bf9660cSLawrence Mitchell 9389bf9660cSLawrence Mitchell Input Arguments 9399bf9660cSLawrence Mitchell + dm - the shell DM 9409bf9660cSLawrence Mitchell - decomp - the routine to create the decomposition 9419bf9660cSLawrence Mitchell 9429bf9660cSLawrence Mitchell Level: advanced 9439bf9660cSLawrence Mitchell 944fef3a512SBarry Smith .seealso: DMCreateFieldDecomposition(), DMShellSetContext(), DMShellGetContext() 9459bf9660cSLawrence Mitchell @*/ 9465e2259d5SLawrence Mitchell PetscErrorCode DMShellSetCreateFieldDecomposition(DM dm, PetscErrorCode (*decomp)(DM,PetscInt*,char***, IS**,DM**)) 9475e2259d5SLawrence Mitchell { 9485e2259d5SLawrence Mitchell PetscErrorCode ierr; 9495e2259d5SLawrence Mitchell PetscBool isshell; 9505e2259d5SLawrence Mitchell 9515e2259d5SLawrence Mitchell PetscFunctionBegin; 9525e2259d5SLawrence Mitchell PetscValidHeaderSpecific(dm,DM_CLASSID,1); 9535e2259d5SLawrence Mitchell ierr = PetscObjectTypeCompare((PetscObject)dm,DMSHELL,&isshell);CHKERRQ(ierr); 9545e2259d5SLawrence Mitchell if (!isshell) PetscFunctionReturn(0); 9555e2259d5SLawrence Mitchell dm->ops->createfielddecomposition = decomp; 9565e2259d5SLawrence Mitchell PetscFunctionReturn(0); 9575e2259d5SLawrence Mitchell } 9585e2259d5SLawrence Mitchell 959c00061e5SLawrence Mitchell /*@C 960e734121bSPatrick Farrell DMShellSetCreateDomainDecomposition - Set the routine used to create a domain decomposition for the shell DM 961e734121bSPatrick Farrell 962d083f849SBarry Smith Logically Collective on dm 963e734121bSPatrick Farrell 964e734121bSPatrick Farrell Input Arguments 965e734121bSPatrick Farrell + dm - the shell DM 966e734121bSPatrick Farrell - decomp - the routine to create the decomposition 967e734121bSPatrick Farrell 968e734121bSPatrick Farrell Level: advanced 969e734121bSPatrick Farrell 970e734121bSPatrick Farrell .seealso: DMCreateDomainDecomposition(), DMShellSetContext(), DMShellGetContext() 971e734121bSPatrick Farrell @*/ 972e734121bSPatrick Farrell PetscErrorCode DMShellSetCreateDomainDecomposition(DM dm, PetscErrorCode (*decomp)(DM,PetscInt*,char***, IS**,IS**,DM**)) 973e734121bSPatrick Farrell { 974e734121bSPatrick Farrell PetscErrorCode ierr; 975e734121bSPatrick Farrell PetscBool isshell; 976e734121bSPatrick Farrell 977e734121bSPatrick Farrell PetscFunctionBegin; 978e734121bSPatrick Farrell PetscValidHeaderSpecific(dm,DM_CLASSID,1); 979e734121bSPatrick Farrell ierr = PetscObjectTypeCompare((PetscObject)dm,DMSHELL,&isshell);CHKERRQ(ierr); 980e734121bSPatrick Farrell if (!isshell) PetscFunctionReturn(0); 981e734121bSPatrick Farrell dm->ops->createdomaindecomposition = decomp; 982e734121bSPatrick Farrell PetscFunctionReturn(0); 983e734121bSPatrick Farrell } 984e734121bSPatrick Farrell 985e734121bSPatrick Farrell /*@C 986eef9d6cdSPatrick Farrell DMShellSetCreateDomainDecompositionScatters - Set the routine used to create the scatter contexts for domain decomposition with a shell DM 987eef9d6cdSPatrick Farrell 988d083f849SBarry Smith Logically Collective on dm 989eef9d6cdSPatrick Farrell 990eef9d6cdSPatrick Farrell Input Arguments 991eef9d6cdSPatrick Farrell + dm - the shell DM 992eef9d6cdSPatrick Farrell - scatter - the routine to create the scatters 993eef9d6cdSPatrick Farrell 994eef9d6cdSPatrick Farrell Level: advanced 995eef9d6cdSPatrick Farrell 996448b6425SPatrick Farrell .seealso: DMCreateDomainDecompositionScatters(), DMShellSetContext(), DMShellGetContext() 997eef9d6cdSPatrick Farrell @*/ 998eef9d6cdSPatrick Farrell PetscErrorCode DMShellSetCreateDomainDecompositionScatters(DM dm, PetscErrorCode (*scatter)(DM,PetscInt,DM*,VecScatter**,VecScatter**,VecScatter**)) 999eef9d6cdSPatrick Farrell { 1000eef9d6cdSPatrick Farrell PetscErrorCode ierr; 1001eef9d6cdSPatrick Farrell PetscBool isshell; 1002eef9d6cdSPatrick Farrell 1003eef9d6cdSPatrick Farrell PetscFunctionBegin; 1004eef9d6cdSPatrick Farrell PetscValidHeaderSpecific(dm,DM_CLASSID,1); 1005eef9d6cdSPatrick Farrell ierr = PetscObjectTypeCompare((PetscObject)dm,DMSHELL,&isshell);CHKERRQ(ierr); 1006eef9d6cdSPatrick Farrell if (!isshell) PetscFunctionReturn(0); 1007eef9d6cdSPatrick Farrell dm->ops->createddscatters = scatter; 1008eef9d6cdSPatrick Farrell PetscFunctionReturn(0); 1009eef9d6cdSPatrick Farrell } 1010eef9d6cdSPatrick Farrell 1011eef9d6cdSPatrick Farrell /*@C 1012c00061e5SLawrence Mitchell DMShellSetCreateSubDM - Set the routine used to create a sub DM from the shell DM 1013c00061e5SLawrence Mitchell 1014d083f849SBarry Smith Logically Collective on dm 1015c00061e5SLawrence Mitchell 1016c00061e5SLawrence Mitchell Input Arguments 1017c00061e5SLawrence Mitchell + dm - the shell DM 1018c00061e5SLawrence Mitchell - subdm - the routine to create the decomposition 1019c00061e5SLawrence Mitchell 1020c00061e5SLawrence Mitchell Level: advanced 1021c00061e5SLawrence Mitchell 1022bf890c61SBoris Boutkov .seealso: DMCreateSubDM(), DMShellGetCreateSubDM(), DMShellSetContext(), DMShellGetContext() 1023c00061e5SLawrence Mitchell @*/ 1024276c5506SMatthew G. Knepley PetscErrorCode DMShellSetCreateSubDM(DM dm, PetscErrorCode (*subdm)(DM,PetscInt,const PetscInt[],IS*,DM*)) 1025c00061e5SLawrence Mitchell { 1026c00061e5SLawrence Mitchell PetscErrorCode ierr; 1027c00061e5SLawrence Mitchell PetscBool isshell; 1028c00061e5SLawrence Mitchell 1029c00061e5SLawrence Mitchell PetscFunctionBegin; 1030c00061e5SLawrence Mitchell PetscValidHeaderSpecific(dm,DM_CLASSID,1); 1031c00061e5SLawrence Mitchell ierr = PetscObjectTypeCompare((PetscObject)dm,DMSHELL,&isshell);CHKERRQ(ierr); 1032c00061e5SLawrence Mitchell if (!isshell) PetscFunctionReturn(0); 1033c00061e5SLawrence Mitchell dm->ops->createsubdm = subdm; 1034c00061e5SLawrence Mitchell PetscFunctionReturn(0); 1035c00061e5SLawrence Mitchell } 1036c00061e5SLawrence Mitchell 10374363ddcaSBoris Boutkov /*@C 10384363ddcaSBoris Boutkov DMShellGetCreateSubDM - Get the routine used to create a sub DM from the shell DM 10394363ddcaSBoris Boutkov 1040d083f849SBarry Smith Logically Collective on dm 10414363ddcaSBoris Boutkov 1042a4a986ddSBoris Boutkov Input Argument: 10434363ddcaSBoris Boutkov + dm - the shell DM 1044a4a986ddSBoris Boutkov 1045a4a986ddSBoris Boutkov Output Argument: 10464363ddcaSBoris Boutkov - subdm - the routine to create the decomposition 10474363ddcaSBoris Boutkov 10484363ddcaSBoris Boutkov Level: advanced 10494363ddcaSBoris Boutkov 10504363ddcaSBoris Boutkov .seealso: DMCreateSubDM(), DMShellSetCreateSubDM(), DMShellSetContext(), DMShellGetContext() 10514363ddcaSBoris Boutkov @*/ 10524363ddcaSBoris Boutkov PetscErrorCode DMShellGetCreateSubDM(DM dm, PetscErrorCode (**subdm)(DM,PetscInt,const PetscInt[],IS*,DM*)) 10534363ddcaSBoris Boutkov { 10544363ddcaSBoris Boutkov PetscErrorCode ierr; 10554363ddcaSBoris Boutkov PetscBool isshell; 10564363ddcaSBoris Boutkov 10574363ddcaSBoris Boutkov PetscFunctionBegin; 10584363ddcaSBoris Boutkov PetscValidHeaderSpecific(dm,DM_CLASSID,1); 10594363ddcaSBoris Boutkov ierr = PetscObjectTypeCompare((PetscObject)dm,DMSHELL,&isshell);CHKERRQ(ierr); 10608dd90dd5SBoris Boutkov if (!isshell) SETERRQ(PetscObjectComm((PetscObject)dm),PETSC_ERR_SUP,"Can only use with DMSHELL type DMs"); 10614363ddcaSBoris Boutkov *subdm = dm->ops->createsubdm; 10624363ddcaSBoris Boutkov PetscFunctionReturn(0); 10634363ddcaSBoris Boutkov } 10644363ddcaSBoris Boutkov 1065fe1899a2SJed Brown static PetscErrorCode DMDestroy_Shell(DM dm) 1066fe1899a2SJed Brown { 1067fe1899a2SJed Brown PetscErrorCode ierr; 1068fe1899a2SJed Brown DM_Shell *shell = (DM_Shell*)dm->data; 1069fe1899a2SJed Brown 1070fe1899a2SJed Brown PetscFunctionBegin; 1071fe1899a2SJed Brown ierr = MatDestroy(&shell->A);CHKERRQ(ierr); 1072fe1899a2SJed Brown ierr = VecDestroy(&shell->Xglobal);CHKERRQ(ierr); 1073dc43b69eSJed Brown ierr = VecDestroy(&shell->Xlocal);CHKERRQ(ierr); 1074a94b16f6SRichard Tran Mills ierr = VecScatterDestroy(&shell->gtol);CHKERRQ(ierr); 1075a94b16f6SRichard Tran Mills ierr = VecScatterDestroy(&shell->ltog);CHKERRQ(ierr); 1076294a6417SLawrence Mitchell ierr = VecScatterDestroy(&shell->ltol);CHKERRQ(ierr); 10777b6ad80cSMatthew G Knepley /* This was originally freed in DMDestroy(), but that prevents reference counting of backend objects */ 10787b6ad80cSMatthew G Knepley ierr = PetscFree(shell);CHKERRQ(ierr); 1079fe1899a2SJed Brown PetscFunctionReturn(0); 1080fe1899a2SJed Brown } 1081fe1899a2SJed Brown 10822d53ad75SBarry Smith static PetscErrorCode DMView_Shell(DM dm,PetscViewer v) 10832d53ad75SBarry Smith { 10842d53ad75SBarry Smith PetscErrorCode ierr; 10852d53ad75SBarry Smith DM_Shell *shell = (DM_Shell*)dm->data; 10862d53ad75SBarry Smith 10872d53ad75SBarry Smith PetscFunctionBegin; 10882d53ad75SBarry Smith ierr = VecView(shell->Xglobal,v);CHKERRQ(ierr); 10892d53ad75SBarry Smith PetscFunctionReturn(0); 10902d53ad75SBarry Smith } 10912d53ad75SBarry Smith 10922d53ad75SBarry Smith static PetscErrorCode DMLoad_Shell(DM dm,PetscViewer v) 10932d53ad75SBarry Smith { 10942d53ad75SBarry Smith PetscErrorCode ierr; 10952d53ad75SBarry Smith DM_Shell *shell = (DM_Shell*)dm->data; 10962d53ad75SBarry Smith 10972d53ad75SBarry Smith PetscFunctionBegin; 1098ce94432eSBarry Smith ierr = VecCreate(PetscObjectComm((PetscObject)dm),&shell->Xglobal);CHKERRQ(ierr); 10992d53ad75SBarry Smith ierr = VecLoad(shell->Xglobal,v);CHKERRQ(ierr); 11002d53ad75SBarry Smith PetscFunctionReturn(0); 11012d53ad75SBarry Smith } 1102fe1899a2SJed Brown 1103276c5506SMatthew G. Knepley PetscErrorCode DMCreateSubDM_Shell(DM dm, PetscInt numFields, const PetscInt fields[], IS *is, DM *subdm) 11046e44b4cfSMatthew G. Knepley { 11056e44b4cfSMatthew G. Knepley PetscErrorCode ierr; 11066e44b4cfSMatthew G. Knepley 11076e44b4cfSMatthew G. Knepley PetscFunctionBegin; 11086e44b4cfSMatthew G. Knepley if (subdm) {ierr = DMShellCreate(PetscObjectComm((PetscObject) dm), subdm);CHKERRQ(ierr);} 1109792b654fSMatthew G. Knepley ierr = DMCreateSectionSubDM(dm, numFields, fields, is, subdm);CHKERRQ(ierr); 11106e44b4cfSMatthew G. Knepley PetscFunctionReturn(0); 11116e44b4cfSMatthew G. Knepley } 11126e44b4cfSMatthew G. Knepley 11138cc058d9SJed Brown PETSC_EXTERN PetscErrorCode DMCreate_Shell(DM dm) 1114fe1899a2SJed Brown { 1115fe1899a2SJed Brown PetscErrorCode ierr; 1116fe1899a2SJed Brown DM_Shell *shell; 1117fe1899a2SJed Brown 1118fe1899a2SJed Brown PetscFunctionBegin; 1119b00a9115SJed Brown ierr = PetscNewLog(dm,&shell);CHKERRQ(ierr); 11208c87107bSJed Brown dm->data = shell; 1121fe1899a2SJed Brown 11228c87107bSJed Brown dm->ops->destroy = DMDestroy_Shell; 11238c87107bSJed Brown dm->ops->createglobalvector = DMCreateGlobalVector_Shell; 1124dc43b69eSJed Brown dm->ops->createlocalvector = DMCreateLocalVector_Shell; 11258c87107bSJed Brown dm->ops->creatematrix = DMCreateMatrix_Shell; 11262d53ad75SBarry Smith dm->ops->view = DMView_Shell; 11272d53ad75SBarry Smith dm->ops->load = DMLoad_Shell; 11287a108d1dSBarry Smith dm->ops->globaltolocalbegin = DMGlobalToLocalBeginDefaultShell; 11297a108d1dSBarry Smith dm->ops->globaltolocalend = DMGlobalToLocalEndDefaultShell; 113055daaa54SRichard Tran Mills dm->ops->localtoglobalbegin = DMLocalToGlobalBeginDefaultShell; 113155daaa54SRichard Tran Mills dm->ops->localtoglobalend = DMLocalToGlobalEndDefaultShell; 113263731094SRichard Tran Mills dm->ops->localtolocalbegin = DMLocalToLocalBeginDefaultShell; 113363731094SRichard Tran Mills dm->ops->localtolocalend = DMLocalToLocalEndDefaultShell; 11346e44b4cfSMatthew G. Knepley dm->ops->createsubdm = DMCreateSubDM_Shell; 1135fe1899a2SJed Brown PetscFunctionReturn(0); 1136fe1899a2SJed Brown } 1137fe1899a2SJed Brown 1138fe1899a2SJed Brown /*@ 1139fe1899a2SJed Brown DMShellCreate - Creates a shell DM object, used to manage user-defined problem data 1140fe1899a2SJed Brown 1141d083f849SBarry Smith Collective 1142fe1899a2SJed Brown 1143fe1899a2SJed Brown Input Parameter: 1144fe1899a2SJed Brown . comm - the processors that will share the global vector 1145fe1899a2SJed Brown 1146fe1899a2SJed Brown Output Parameters: 1147fe1899a2SJed Brown . shell - the shell DM 1148fe1899a2SJed Brown 1149fe1899a2SJed Brown Level: advanced 1150fe1899a2SJed Brown 1151fef3a512SBarry Smith .seealso DMDestroy(), DMCreateGlobalVector(), DMCreateLocalVector(), DMShellSetContext(), DMShellGetContext() 1152fe1899a2SJed Brown @*/ 1153fe1899a2SJed Brown PetscErrorCode DMShellCreate(MPI_Comm comm,DM *dm) 1154fe1899a2SJed Brown { 1155fe1899a2SJed Brown PetscErrorCode ierr; 1156fe1899a2SJed Brown 1157fe1899a2SJed Brown PetscFunctionBegin; 1158fe1899a2SJed Brown PetscValidPointer(dm,2); 1159fe1899a2SJed Brown ierr = DMCreate(comm,dm);CHKERRQ(ierr); 1160fe1899a2SJed Brown ierr = DMSetType(*dm,DMSHELL);CHKERRQ(ierr); 116181a566bfSMatthew G. Knepley ierr = DMSetUp(*dm);CHKERRQ(ierr); 1162fe1899a2SJed Brown PetscFunctionReturn(0); 1163fe1899a2SJed Brown } 1164