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; 19706f803f6SStefano Zampini ierr = MatDuplicate(A,MAT_SHARE_NONZERO_PATTERN,J);CHKERRQ(ierr); 19806f803f6SStefano Zampini ierr = MatSetDM(*J,dm);CHKERRQ(ierr); 199fe1899a2SJed Brown PetscFunctionReturn(0); 200fe1899a2SJed Brown } 201fe1899a2SJed Brown 202fe1899a2SJed Brown PetscErrorCode DMCreateGlobalVector_Shell(DM dm,Vec *gvec) 203fe1899a2SJed Brown { 204fe1899a2SJed Brown PetscErrorCode ierr; 205fe1899a2SJed Brown DM_Shell *shell = (DM_Shell*)dm->data; 206fe1899a2SJed Brown Vec X; 207fe1899a2SJed Brown 208fe1899a2SJed Brown PetscFunctionBegin; 209fe1899a2SJed Brown PetscValidHeaderSpecific(dm,DM_CLASSID,1); 210fe1899a2SJed Brown PetscValidPointer(gvec,2); 211ea78f98cSLisandro Dalcin *gvec = NULL; 212fe1899a2SJed Brown X = shell->Xglobal; 213ce94432eSBarry Smith if (!X) SETERRQ(PetscObjectComm((PetscObject)dm),PETSC_ERR_USER,"Must call DMShellSetGlobalVector() or DMShellSetCreateGlobalVector()"); 21406f803f6SStefano Zampini /* Need to create a copy in order to attach the DM to the vector */ 215fe1899a2SJed Brown ierr = VecDuplicate(X,gvec);CHKERRQ(ierr); 216fe1899a2SJed Brown ierr = VecZeroEntries(*gvec);CHKERRQ(ierr); 217c688c046SMatthew G Knepley ierr = VecSetDM(*gvec,dm);CHKERRQ(ierr); 218fe1899a2SJed Brown PetscFunctionReturn(0); 219fe1899a2SJed Brown } 220fe1899a2SJed Brown 221dc43b69eSJed Brown PetscErrorCode DMCreateLocalVector_Shell(DM dm,Vec *gvec) 222dc43b69eSJed Brown { 223dc43b69eSJed Brown PetscErrorCode ierr; 224dc43b69eSJed Brown DM_Shell *shell = (DM_Shell*)dm->data; 225dc43b69eSJed Brown Vec X; 226dc43b69eSJed Brown 227dc43b69eSJed Brown PetscFunctionBegin; 228dc43b69eSJed Brown PetscValidHeaderSpecific(dm,DM_CLASSID,1); 229dc43b69eSJed Brown PetscValidPointer(gvec,2); 230ea78f98cSLisandro Dalcin *gvec = NULL; 231dc43b69eSJed Brown X = shell->Xlocal; 232ce94432eSBarry Smith if (!X) SETERRQ(PetscObjectComm((PetscObject)dm),PETSC_ERR_USER,"Must call DMShellSetLocalVector() or DMShellSetCreateLocalVector()"); 23306f803f6SStefano Zampini /* Need to create a copy in order to attach the DM to the vector */ 234dc43b69eSJed Brown ierr = VecDuplicate(X,gvec);CHKERRQ(ierr); 235dc43b69eSJed Brown ierr = VecZeroEntries(*gvec);CHKERRQ(ierr); 2366e4cbd8bSMark F. Adams ierr = VecSetDM(*gvec,dm);CHKERRQ(ierr); 237dc43b69eSJed Brown PetscFunctionReturn(0); 238dc43b69eSJed Brown } 239dc43b69eSJed Brown 240fef3a512SBarry Smith /*@ 241fef3a512SBarry Smith DMShellSetContext - set some data to be usable by this DM 242fef3a512SBarry Smith 243fef3a512SBarry Smith Collective 244fef3a512SBarry Smith 245fef3a512SBarry Smith Input Arguments: 246fef3a512SBarry Smith + dm - shell DM 247fef3a512SBarry Smith - ctx - the context 248fef3a512SBarry Smith 249fef3a512SBarry Smith Level: advanced 250fef3a512SBarry Smith 251fef3a512SBarry Smith .seealso: DMCreateMatrix(), DMShellGetContext() 252fef3a512SBarry Smith @*/ 253fef3a512SBarry Smith PetscErrorCode DMShellSetContext(DM dm,void *ctx) 254fef3a512SBarry Smith { 255fef3a512SBarry Smith DM_Shell *shell = (DM_Shell*)dm->data; 256fef3a512SBarry Smith PetscErrorCode ierr; 257fef3a512SBarry Smith PetscBool isshell; 258fef3a512SBarry Smith 259fef3a512SBarry Smith PetscFunctionBegin; 260fef3a512SBarry Smith PetscValidHeaderSpecific(dm,DM_CLASSID,1); 261fef3a512SBarry Smith ierr = PetscObjectTypeCompare((PetscObject)dm,DMSHELL,&isshell);CHKERRQ(ierr); 262fef3a512SBarry Smith if (!isshell) PetscFunctionReturn(0); 263fef3a512SBarry Smith shell->ctx = ctx; 264fef3a512SBarry Smith PetscFunctionReturn(0); 265fef3a512SBarry Smith } 266fef3a512SBarry Smith 267fef3a512SBarry Smith /*@ 268bf890c61SBoris Boutkov DMShellGetContext - Returns the user-provided context associated to the DM 269fef3a512SBarry Smith 270fef3a512SBarry Smith Collective 271fef3a512SBarry Smith 272fef3a512SBarry Smith Input Argument: 273fef3a512SBarry Smith . dm - shell DM 274fef3a512SBarry Smith 275fef3a512SBarry Smith Output Argument: 276fef3a512SBarry Smith . ctx - the context 277fef3a512SBarry Smith 278fef3a512SBarry Smith Level: advanced 279fef3a512SBarry Smith 280fef3a512SBarry Smith .seealso: DMCreateMatrix(), DMShellSetContext() 281fef3a512SBarry Smith @*/ 282fef3a512SBarry Smith PetscErrorCode DMShellGetContext(DM dm,void **ctx) 283fef3a512SBarry Smith { 284fef3a512SBarry Smith DM_Shell *shell = (DM_Shell*)dm->data; 285fef3a512SBarry Smith PetscErrorCode ierr; 286fef3a512SBarry Smith PetscBool isshell; 287fef3a512SBarry Smith 288fef3a512SBarry Smith PetscFunctionBegin; 289fef3a512SBarry Smith PetscValidHeaderSpecific(dm,DM_CLASSID,1); 290fef3a512SBarry Smith ierr = PetscObjectTypeCompare((PetscObject)dm,DMSHELL,&isshell);CHKERRQ(ierr); 2918dd90dd5SBoris Boutkov if (!isshell) SETERRQ(PetscObjectComm((PetscObject)dm),PETSC_ERR_SUP,"Can only use with DMSHELL type DMs"); 292fef3a512SBarry Smith *ctx = shell->ctx; 293fef3a512SBarry Smith PetscFunctionReturn(0); 294fef3a512SBarry Smith } 295fef3a512SBarry Smith 296fe1899a2SJed Brown /*@ 297fe1899a2SJed Brown DMShellSetMatrix - sets a template matrix associated with the DMShell 298fe1899a2SJed Brown 299fe1899a2SJed Brown Collective 300fe1899a2SJed Brown 301fe1899a2SJed Brown Input Arguments: 302fe1899a2SJed Brown + dm - shell DM 303fe1899a2SJed Brown - J - template matrix 304fe1899a2SJed Brown 305fe1899a2SJed Brown Level: advanced 306fe1899a2SJed Brown 30706f803f6SStefano Zampini Developer Notes: 30806f803f6SStefano Zampini To avoid circular references, if J is already associated to the same DM, then MatDuplicate(SHARE_NONZERO_PATTERN) is called, followed by removing the DM reference from the private template. 30906f803f6SStefano Zampini 310fef3a512SBarry Smith .seealso: DMCreateMatrix(), DMShellSetCreateMatrix(), DMShellSetContext(), DMShellGetContext() 311fe1899a2SJed Brown @*/ 312fe1899a2SJed Brown PetscErrorCode DMShellSetMatrix(DM dm,Mat J) 313fe1899a2SJed Brown { 314fe1899a2SJed Brown DM_Shell *shell = (DM_Shell*)dm->data; 315fe1899a2SJed Brown PetscErrorCode ierr; 3168c87107bSJed Brown PetscBool isshell; 31706f803f6SStefano Zampini DM mdm; 318fe1899a2SJed Brown 319fe1899a2SJed Brown PetscFunctionBegin; 3208c87107bSJed Brown PetscValidHeaderSpecific(dm,DM_CLASSID,1); 3218c87107bSJed Brown PetscValidHeaderSpecific(J,MAT_CLASSID,2); 322251f4c67SDmitry Karpeev ierr = PetscObjectTypeCompare((PetscObject)dm,DMSHELL,&isshell);CHKERRQ(ierr); 3238c87107bSJed Brown if (!isshell) PetscFunctionReturn(0); 32406f803f6SStefano Zampini if (J == shell->A) PetscFunctionReturn(0); 32506f803f6SStefano Zampini ierr = MatGetDM(J,&mdm);CHKERRQ(ierr); 326fe1899a2SJed Brown ierr = PetscObjectReference((PetscObject)J);CHKERRQ(ierr); 327fe1899a2SJed Brown ierr = MatDestroy(&shell->A);CHKERRQ(ierr); 32806f803f6SStefano Zampini if (mdm == dm) { 32906f803f6SStefano Zampini ierr = MatDuplicate(J,MAT_SHARE_NONZERO_PATTERN,&shell->A);CHKERRQ(ierr); 33006f803f6SStefano Zampini ierr = MatSetDM(shell->A,NULL);CHKERRQ(ierr); 33106f803f6SStefano Zampini } else shell->A = J; 332fe1899a2SJed Brown PetscFunctionReturn(0); 333fe1899a2SJed Brown } 334fe1899a2SJed Brown 335fe1899a2SJed Brown /*@C 336fe1899a2SJed Brown DMShellSetCreateMatrix - sets the routine to create a matrix associated with the shell DM 337fe1899a2SJed Brown 338d083f849SBarry Smith Logically Collective on dm 339fe1899a2SJed Brown 340fe1899a2SJed Brown Input Arguments: 341fe1899a2SJed Brown + dm - the shell DM 342fe1899a2SJed Brown - func - the function to create a matrix 343fe1899a2SJed Brown 344fe1899a2SJed Brown Level: advanced 345fe1899a2SJed Brown 346fef3a512SBarry Smith .seealso: DMCreateMatrix(), DMShellSetMatrix(), DMShellSetContext(), DMShellGetContext() 347fe1899a2SJed Brown @*/ 348b412c318SBarry Smith PetscErrorCode DMShellSetCreateMatrix(DM dm,PetscErrorCode (*func)(DM,Mat*)) 349fe1899a2SJed Brown { 350fe1899a2SJed Brown PetscFunctionBegin; 351fe1899a2SJed Brown PetscValidHeaderSpecific(dm,DM_CLASSID,1); 352fe1899a2SJed Brown dm->ops->creatematrix = func; 353fe1899a2SJed Brown PetscFunctionReturn(0); 354fe1899a2SJed Brown } 355fe1899a2SJed Brown 356fe1899a2SJed Brown /*@ 357fe1899a2SJed Brown DMShellSetGlobalVector - sets a template global vector associated with the DMShell 358fe1899a2SJed Brown 359d083f849SBarry Smith Logically Collective on dm 360fe1899a2SJed Brown 361fe1899a2SJed Brown Input Arguments: 362fe1899a2SJed Brown + dm - shell DM 363fe1899a2SJed Brown - X - template vector 364fe1899a2SJed Brown 365fe1899a2SJed Brown Level: advanced 366fe1899a2SJed Brown 367fe1899a2SJed Brown .seealso: DMCreateGlobalVector(), DMShellSetMatrix(), DMShellSetCreateGlobalVector() 368fe1899a2SJed Brown @*/ 369fe1899a2SJed Brown PetscErrorCode DMShellSetGlobalVector(DM dm,Vec X) 370fe1899a2SJed Brown { 371fe1899a2SJed Brown DM_Shell *shell = (DM_Shell*)dm->data; 372fe1899a2SJed Brown PetscErrorCode ierr; 3738c87107bSJed Brown PetscBool isshell; 374cca7ec1eSBarry Smith DM vdm; 375fe1899a2SJed Brown 376fe1899a2SJed Brown PetscFunctionBegin; 3778c87107bSJed Brown PetscValidHeaderSpecific(dm,DM_CLASSID,1); 3788c87107bSJed Brown PetscValidHeaderSpecific(X,VEC_CLASSID,2); 379251f4c67SDmitry Karpeev ierr = PetscObjectTypeCompare((PetscObject)dm,DMSHELL,&isshell);CHKERRQ(ierr); 3808c87107bSJed Brown if (!isshell) PetscFunctionReturn(0); 381cca7ec1eSBarry Smith ierr = VecGetDM(X,&vdm);CHKERRQ(ierr); 382cca7ec1eSBarry Smith /* 383cca7ec1eSBarry Smith if the vector proposed as the new base global vector for the DM is a DM vector associated 384cca7ec1eSBarry 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 385cca7ec1eSBarry Smith we get a circular dependency that prevents the DM from being destroy when it should be. 386cca7ec1eSBarry Smith This occurs when SNESSet/GetNPC() is used with a SNES that does not have a user provided 387cca7ec1eSBarry Smith DM attached to it since the inner SNES (which shares the DM with the outer SNES) tries 388cca7ec1eSBarry Smith to set its input vector (which is associated with the DM) as the base global vector. 389cca7ec1eSBarry Smith Thanks to Juan P. Mendez Granado Re: [petsc-maint] Nonlinear conjugate gradien 390cca7ec1eSBarry Smith for pointing out the problem. 391cca7ec1eSBarry Smith */ 392cca7ec1eSBarry Smith if (vdm == dm) PetscFunctionReturn(0); 393fe1899a2SJed Brown ierr = PetscObjectReference((PetscObject)X);CHKERRQ(ierr); 394fe1899a2SJed Brown ierr = VecDestroy(&shell->Xglobal);CHKERRQ(ierr); 395fe1899a2SJed Brown shell->Xglobal = X; 396fe1899a2SJed Brown PetscFunctionReturn(0); 397fe1899a2SJed Brown } 398fe1899a2SJed Brown 399fe1899a2SJed Brown /*@C 400fe1899a2SJed Brown DMShellSetCreateGlobalVector - sets the routine to create a global vector associated with the shell DM 401fe1899a2SJed Brown 402fe1899a2SJed Brown Logically Collective 403fe1899a2SJed Brown 404fe1899a2SJed Brown Input Arguments: 405fe1899a2SJed Brown + dm - the shell DM 406fe1899a2SJed Brown - func - the creation routine 407fe1899a2SJed Brown 408fe1899a2SJed Brown Level: advanced 409fe1899a2SJed Brown 410fef3a512SBarry Smith .seealso: DMShellSetGlobalVector(), DMShellSetCreateMatrix(), DMShellSetContext(), DMShellGetContext() 411fe1899a2SJed Brown @*/ 412fe1899a2SJed Brown PetscErrorCode DMShellSetCreateGlobalVector(DM dm,PetscErrorCode (*func)(DM,Vec*)) 413fe1899a2SJed Brown { 414fe1899a2SJed Brown PetscFunctionBegin; 415fe1899a2SJed Brown PetscValidHeaderSpecific(dm,DM_CLASSID,1); 416fe1899a2SJed Brown dm->ops->createglobalvector = func; 417fe1899a2SJed Brown PetscFunctionReturn(0); 418fe1899a2SJed Brown } 419fe1899a2SJed Brown 420dc43b69eSJed Brown /*@ 421dc43b69eSJed Brown DMShellSetLocalVector - sets a template local vector associated with the DMShell 422dc43b69eSJed Brown 423d083f849SBarry Smith Logically Collective on dm 424dc43b69eSJed Brown 425dc43b69eSJed Brown Input Arguments: 426dc43b69eSJed Brown + dm - shell DM 427dc43b69eSJed Brown - X - template vector 428dc43b69eSJed Brown 429dc43b69eSJed Brown Level: advanced 430dc43b69eSJed Brown 431dc43b69eSJed Brown .seealso: DMCreateLocalVector(), DMShellSetMatrix(), DMShellSetCreateLocalVector() 432dc43b69eSJed Brown @*/ 433dc43b69eSJed Brown PetscErrorCode DMShellSetLocalVector(DM dm,Vec X) 434dc43b69eSJed Brown { 435dc43b69eSJed Brown DM_Shell *shell = (DM_Shell*)dm->data; 436dc43b69eSJed Brown PetscErrorCode ierr; 437dc43b69eSJed Brown PetscBool isshell; 438cca7ec1eSBarry Smith DM vdm; 439dc43b69eSJed Brown 440dc43b69eSJed Brown PetscFunctionBegin; 441dc43b69eSJed Brown PetscValidHeaderSpecific(dm,DM_CLASSID,1); 442dc43b69eSJed Brown PetscValidHeaderSpecific(X,VEC_CLASSID,2); 443dc43b69eSJed Brown ierr = PetscObjectTypeCompare((PetscObject)dm,DMSHELL,&isshell);CHKERRQ(ierr); 444dc43b69eSJed Brown if (!isshell) PetscFunctionReturn(0); 445cca7ec1eSBarry Smith ierr = VecGetDM(X,&vdm);CHKERRQ(ierr); 446cca7ec1eSBarry Smith /* 447cca7ec1eSBarry Smith if the vector proposed as the new base global vector for the DM is a DM vector associated 448cca7ec1eSBarry 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 449cca7ec1eSBarry Smith we get a circular dependency that prevents the DM from being destroy when it should be. 450cca7ec1eSBarry Smith This occurs when SNESSet/GetNPC() is used with a SNES that does not have a user provided 451cca7ec1eSBarry Smith DM attached to it since the inner SNES (which shares the DM with the outer SNES) tries 452cca7ec1eSBarry Smith to set its input vector (which is associated with the DM) as the base global vector. 453cca7ec1eSBarry Smith Thanks to Juan P. Mendez Granado Re: [petsc-maint] Nonlinear conjugate gradien 454cca7ec1eSBarry Smith for pointing out the problem. 455cca7ec1eSBarry Smith */ 456cca7ec1eSBarry Smith if (vdm == dm) PetscFunctionReturn(0); 457dc43b69eSJed Brown ierr = PetscObjectReference((PetscObject)X);CHKERRQ(ierr); 458dc43b69eSJed Brown ierr = VecDestroy(&shell->Xlocal);CHKERRQ(ierr); 459dc43b69eSJed Brown shell->Xlocal = X; 460dc43b69eSJed Brown PetscFunctionReturn(0); 461dc43b69eSJed Brown } 462dc43b69eSJed Brown 463dc43b69eSJed Brown /*@C 464dc43b69eSJed Brown DMShellSetCreateLocalVector - sets the routine to create a local vector associated with the shell DM 465dc43b69eSJed Brown 466dc43b69eSJed Brown Logically Collective 467dc43b69eSJed Brown 468dc43b69eSJed Brown Input Arguments: 469dc43b69eSJed Brown + dm - the shell DM 470dc43b69eSJed Brown - func - the creation routine 471dc43b69eSJed Brown 472dc43b69eSJed Brown Level: advanced 473dc43b69eSJed Brown 474fef3a512SBarry Smith .seealso: DMShellSetLocalVector(), DMShellSetCreateMatrix(), DMShellSetContext(), DMShellGetContext() 475dc43b69eSJed Brown @*/ 476dc43b69eSJed Brown PetscErrorCode DMShellSetCreateLocalVector(DM dm,PetscErrorCode (*func)(DM,Vec*)) 477dc43b69eSJed Brown { 478dc43b69eSJed Brown PetscFunctionBegin; 479dc43b69eSJed Brown PetscValidHeaderSpecific(dm,DM_CLASSID,1); 480dc43b69eSJed Brown dm->ops->createlocalvector = func; 481dc43b69eSJed Brown PetscFunctionReturn(0); 482dc43b69eSJed Brown } 483dc43b69eSJed Brown 4848339e6d0SRichard Tran Mills /*@C 4858339e6d0SRichard Tran Mills DMShellSetGlobalToLocal - Sets the routines used to perform a global to local scatter 4868339e6d0SRichard Tran Mills 487d083f849SBarry Smith Logically Collective on dm 4888339e6d0SRichard Tran Mills 4898339e6d0SRichard Tran Mills Input Arguments 4908339e6d0SRichard Tran Mills + dm - the shell DM 4918339e6d0SRichard Tran Mills . begin - the routine that begins the global to local scatter 4928339e6d0SRichard Tran Mills - end - the routine that ends the global to local scatter 4938339e6d0SRichard Tran Mills 49495452b02SPatrick Sanan Notes: 49595452b02SPatrick Sanan If these functions are not provided but DMShellSetGlobalToLocalVecScatter() is called then 496f3db62a7SRichard Tran Mills DMGlobalToLocalBeginDefaultShell()/DMGlobalToLocalEndDefaultShell() are used to to perform the transfers 4977a108d1dSBarry Smith 4988339e6d0SRichard Tran Mills Level: advanced 4998339e6d0SRichard Tran Mills 5007a108d1dSBarry Smith .seealso: DMShellSetLocalToGlobal(), DMGlobalToLocalBeginDefaultShell(), DMGlobalToLocalEndDefaultShell() 5018339e6d0SRichard Tran Mills @*/ 5028339e6d0SRichard Tran Mills PetscErrorCode DMShellSetGlobalToLocal(DM dm,PetscErrorCode (*begin)(DM,Vec,InsertMode,Vec),PetscErrorCode (*end)(DM,Vec,InsertMode,Vec)) { 5038339e6d0SRichard Tran Mills PetscFunctionBegin; 5042d1bcd87SStefano Zampini PetscValidHeaderSpecific(dm,DM_CLASSID,1); 5058339e6d0SRichard Tran Mills dm->ops->globaltolocalbegin = begin; 5068339e6d0SRichard Tran Mills dm->ops->globaltolocalend = end; 5078339e6d0SRichard Tran Mills PetscFunctionReturn(0); 5088339e6d0SRichard Tran Mills } 5098339e6d0SRichard Tran Mills 5108339e6d0SRichard Tran Mills /*@C 5118339e6d0SRichard Tran Mills DMShellSetLocalToGlobal - Sets the routines used to perform a local to global scatter 5128339e6d0SRichard Tran Mills 513d083f849SBarry Smith Logically Collective on dm 5148339e6d0SRichard Tran Mills 5158339e6d0SRichard Tran Mills Input Arguments 5168339e6d0SRichard Tran Mills + dm - the shell DM 5178339e6d0SRichard Tran Mills . begin - the routine that begins the local to global scatter 5188339e6d0SRichard Tran Mills - end - the routine that ends the local to global scatter 5198339e6d0SRichard Tran Mills 52095452b02SPatrick Sanan Notes: 52195452b02SPatrick Sanan If these functions are not provided but DMShellSetLocalToGlobalVecScatter() is called then 522f3db62a7SRichard Tran Mills DMLocalToGlobalBeginDefaultShell()/DMLocalToGlobalEndDefaultShell() are used to to perform the transfers 523f3db62a7SRichard Tran Mills 5248339e6d0SRichard Tran Mills Level: advanced 5258339e6d0SRichard Tran Mills 5268339e6d0SRichard Tran Mills .seealso: DMShellSetGlobalToLocal() 5278339e6d0SRichard Tran Mills @*/ 5288339e6d0SRichard Tran Mills PetscErrorCode DMShellSetLocalToGlobal(DM dm,PetscErrorCode (*begin)(DM,Vec,InsertMode,Vec),PetscErrorCode (*end)(DM,Vec,InsertMode,Vec)) { 5298339e6d0SRichard Tran Mills PetscFunctionBegin; 5302d1bcd87SStefano Zampini PetscValidHeaderSpecific(dm,DM_CLASSID,1); 5318339e6d0SRichard Tran Mills dm->ops->localtoglobalbegin = begin; 5328339e6d0SRichard Tran Mills dm->ops->localtoglobalend = end; 5338339e6d0SRichard Tran Mills PetscFunctionReturn(0); 5348339e6d0SRichard Tran Mills } 5358339e6d0SRichard Tran Mills 536f3db62a7SRichard Tran Mills /*@C 537f3db62a7SRichard Tran Mills DMShellSetLocalToLocal - Sets the routines used to perform a local to local scatter 538f3db62a7SRichard Tran Mills 539d083f849SBarry Smith Logically Collective on dm 540f3db62a7SRichard Tran Mills 541f3db62a7SRichard Tran Mills Input Arguments 542f3db62a7SRichard Tran Mills + dm - the shell DM 543f3db62a7SRichard Tran Mills . begin - the routine that begins the local to local scatter 544f3db62a7SRichard Tran Mills - end - the routine that ends the local to local scatter 545f3db62a7SRichard Tran Mills 54695452b02SPatrick Sanan Notes: 54795452b02SPatrick Sanan If these functions are not provided but DMShellSetLocalToLocalVecScatter() is called then 548f3db62a7SRichard Tran Mills DMLocalToLocalBeginDefaultShell()/DMLocalToLocalEndDefaultShell() are used to to perform the transfers 549f3db62a7SRichard Tran Mills 550f3db62a7SRichard Tran Mills Level: advanced 551f3db62a7SRichard Tran Mills 552f3db62a7SRichard Tran Mills .seealso: DMShellSetGlobalToLocal(), DMLocalToLocalBeginDefaultShell(), DMLocalToLocalEndDefaultShell() 553f3db62a7SRichard Tran Mills @*/ 554f3db62a7SRichard Tran Mills PetscErrorCode DMShellSetLocalToLocal(DM dm,PetscErrorCode (*begin)(DM,Vec,InsertMode,Vec),PetscErrorCode (*end)(DM,Vec,InsertMode,Vec)) { 555f3db62a7SRichard Tran Mills PetscFunctionBegin; 5562d1bcd87SStefano Zampini PetscValidHeaderSpecific(dm,DM_CLASSID,1); 557f3db62a7SRichard Tran Mills dm->ops->localtolocalbegin = begin; 558f3db62a7SRichard Tran Mills dm->ops->localtolocalend = end; 559f3db62a7SRichard Tran Mills PetscFunctionReturn(0); 560f3db62a7SRichard Tran Mills } 561f3db62a7SRichard Tran Mills 56281634712SRichard Tran Mills /*@ 56381634712SRichard Tran Mills DMShellSetGlobalToLocalVecScatter - Sets a VecScatter context for global to local communication 56481634712SRichard Tran Mills 565d083f849SBarry Smith Logically Collective on dm 56681634712SRichard Tran Mills 56781634712SRichard Tran Mills Input Arguments 56881634712SRichard Tran Mills + dm - the shell DM 56981634712SRichard Tran Mills - gtol - the global to local VecScatter context 57081634712SRichard Tran Mills 57181634712SRichard Tran Mills Level: advanced 57281634712SRichard Tran Mills 573f3db62a7SRichard Tran Mills .seealso: DMShellSetGlobalToLocal(), DMGlobalToLocalBeginDefaultShell(), DMGlobalToLocalEndDefaultShell() 57481634712SRichard Tran Mills @*/ 575a94b16f6SRichard Tran Mills PetscErrorCode DMShellSetGlobalToLocalVecScatter(DM dm, VecScatter gtol) 57681634712SRichard Tran Mills { 57781634712SRichard Tran Mills DM_Shell *shell = (DM_Shell*)dm->data; 578d885d199SRichard Tran Mills PetscErrorCode ierr; 57981634712SRichard Tran Mills 580b300e4a8SRichard Tran Mills PetscFunctionBegin; 5812d1bcd87SStefano Zampini PetscValidHeaderSpecific(dm,DM_CLASSID,1); 582*97929ea7SJunchao Zhang PetscValidHeaderSpecific(gtol,PETSCSF_CLASSID,2); 583d885d199SRichard Tran Mills ierr = PetscObjectReference((PetscObject)gtol);CHKERRQ(ierr); 584d885d199SRichard Tran Mills ierr = VecScatterDestroy(&shell->gtol);CHKERRQ(ierr); 58581634712SRichard Tran Mills shell->gtol = gtol; 58681634712SRichard Tran Mills PetscFunctionReturn(0); 58781634712SRichard Tran Mills } 58881634712SRichard Tran Mills 589988ea7d6SRichard Tran Mills /*@ 590988ea7d6SRichard Tran Mills DMShellSetLocalToGlobalVecScatter - Sets a VecScatter context for local to global communication 591988ea7d6SRichard Tran Mills 592d083f849SBarry Smith Logically Collective on dm 593988ea7d6SRichard Tran Mills 594988ea7d6SRichard Tran Mills Input Arguments 595988ea7d6SRichard Tran Mills + dm - the shell DM 596988ea7d6SRichard Tran Mills - ltog - the local to global VecScatter context 597988ea7d6SRichard Tran Mills 598988ea7d6SRichard Tran Mills Level: advanced 599988ea7d6SRichard Tran Mills 600f3db62a7SRichard Tran Mills .seealso: DMShellSetLocalToGlobal(), DMLocalToGlobalBeginDefaultShell(), DMLocalToGlobalEndDefaultShell() 601988ea7d6SRichard Tran Mills @*/ 602a94b16f6SRichard Tran Mills PetscErrorCode DMShellSetLocalToGlobalVecScatter(DM dm, VecScatter ltog) 603988ea7d6SRichard Tran Mills { 604988ea7d6SRichard Tran Mills DM_Shell *shell = (DM_Shell*)dm->data; 605d885d199SRichard Tran Mills PetscErrorCode ierr; 606988ea7d6SRichard Tran Mills 607988ea7d6SRichard Tran Mills PetscFunctionBegin; 6082d1bcd87SStefano Zampini PetscValidHeaderSpecific(dm,DM_CLASSID,1); 609*97929ea7SJunchao Zhang PetscValidHeaderSpecific(ltog,PETSCSF_CLASSID,2); 610d885d199SRichard Tran Mills ierr = PetscObjectReference((PetscObject)ltog);CHKERRQ(ierr); 611d885d199SRichard Tran Mills ierr = VecScatterDestroy(&shell->ltog);CHKERRQ(ierr); 612988ea7d6SRichard Tran Mills shell->ltog = ltog; 613988ea7d6SRichard Tran Mills PetscFunctionReturn(0); 614988ea7d6SRichard Tran Mills } 615988ea7d6SRichard Tran Mills 616f3db62a7SRichard Tran Mills /*@ 617f3db62a7SRichard Tran Mills DMShellSetLocalToLocalVecScatter - Sets a VecScatter context for local to local communication 618f3db62a7SRichard Tran Mills 619d083f849SBarry Smith Logically Collective on dm 620f3db62a7SRichard Tran Mills 621f3db62a7SRichard Tran Mills Input Arguments 622f3db62a7SRichard Tran Mills + dm - the shell DM 623f3db62a7SRichard Tran Mills - ltol - the local to local VecScatter context 624f3db62a7SRichard Tran Mills 625f3db62a7SRichard Tran Mills Level: advanced 626f3db62a7SRichard Tran Mills 627f3db62a7SRichard Tran Mills .seealso: DMShellSetLocalToLocal(), DMLocalToLocalBeginDefaultShell(), DMLocalToLocalEndDefaultShell() 628f3db62a7SRichard Tran Mills @*/ 629f3db62a7SRichard Tran Mills PetscErrorCode DMShellSetLocalToLocalVecScatter(DM dm, VecScatter ltol) 630f3db62a7SRichard Tran Mills { 631f3db62a7SRichard Tran Mills DM_Shell *shell = (DM_Shell*)dm->data; 632f3db62a7SRichard Tran Mills PetscErrorCode ierr; 633f3db62a7SRichard Tran Mills 634f3db62a7SRichard Tran Mills PetscFunctionBegin; 6352d1bcd87SStefano Zampini PetscValidHeaderSpecific(dm,DM_CLASSID,1); 636*97929ea7SJunchao Zhang PetscValidHeaderSpecific(ltol,PETSCSF_CLASSID,2); 637f3db62a7SRichard Tran Mills ierr = PetscObjectReference((PetscObject)ltol);CHKERRQ(ierr); 638f3db62a7SRichard Tran Mills ierr = VecScatterDestroy(&shell->ltol);CHKERRQ(ierr); 639f3db62a7SRichard Tran Mills shell->ltol = ltol; 640f3db62a7SRichard Tran Mills PetscFunctionReturn(0); 641f3db62a7SRichard Tran Mills } 642f3db62a7SRichard Tran Mills 6439bf9660cSLawrence Mitchell /*@C 6449bf9660cSLawrence Mitchell DMShellSetCoarsen - Set the routine used to coarsen the shell DM 6459bf9660cSLawrence Mitchell 646d083f849SBarry Smith Logically Collective on dm 6479bf9660cSLawrence Mitchell 6489bf9660cSLawrence Mitchell Input Arguments 6499bf9660cSLawrence Mitchell + dm - the shell DM 6509bf9660cSLawrence Mitchell - coarsen - the routine that coarsens the DM 6519bf9660cSLawrence Mitchell 6529bf9660cSLawrence Mitchell Level: advanced 6539bf9660cSLawrence Mitchell 654bf890c61SBoris Boutkov .seealso: DMShellSetRefine(), DMCoarsen(), DMShellGetCoarsen(), DMShellSetContext(), DMShellGetContext() 6559bf9660cSLawrence Mitchell @*/ 656f572501eSLawrence Mitchell PetscErrorCode DMShellSetCoarsen(DM dm, PetscErrorCode (*coarsen)(DM,MPI_Comm,DM*)) 657f572501eSLawrence Mitchell { 658f572501eSLawrence Mitchell PetscErrorCode ierr; 659f572501eSLawrence Mitchell PetscBool isshell; 660f572501eSLawrence Mitchell 661f572501eSLawrence Mitchell PetscFunctionBegin; 662f572501eSLawrence Mitchell PetscValidHeaderSpecific(dm,DM_CLASSID,1); 663f572501eSLawrence Mitchell ierr = PetscObjectTypeCompare((PetscObject)dm,DMSHELL,&isshell);CHKERRQ(ierr); 664f572501eSLawrence Mitchell if (!isshell) PetscFunctionReturn(0); 665f572501eSLawrence Mitchell dm->ops->coarsen = coarsen; 666f572501eSLawrence Mitchell PetscFunctionReturn(0); 667f572501eSLawrence Mitchell } 668f572501eSLawrence Mitchell 6699bf9660cSLawrence Mitchell /*@C 6704363ddcaSBoris Boutkov DMShellGetCoarsen - Get the routine used to coarsen the shell DM 6714363ddcaSBoris Boutkov 672d083f849SBarry Smith Logically Collective on dm 6734363ddcaSBoris Boutkov 674a4a986ddSBoris Boutkov Input Argument: 6754363ddcaSBoris Boutkov . dm - the shell DM 6764363ddcaSBoris Boutkov 677a4a986ddSBoris Boutkov Output Argument: 6784363ddcaSBoris Boutkov . coarsen - the routine that coarsens the DM 6794363ddcaSBoris Boutkov 6804363ddcaSBoris Boutkov Level: advanced 6814363ddcaSBoris Boutkov 6824363ddcaSBoris Boutkov .seealso: DMShellSetCoarsen(), DMCoarsen(), DMShellSetRefine(), DMRefine() 6834363ddcaSBoris Boutkov @*/ 6844363ddcaSBoris Boutkov PetscErrorCode DMShellGetCoarsen(DM dm, PetscErrorCode (**coarsen)(DM,MPI_Comm,DM*)) 6854363ddcaSBoris Boutkov { 6864363ddcaSBoris Boutkov PetscErrorCode ierr; 6874363ddcaSBoris Boutkov PetscBool isshell; 6884363ddcaSBoris Boutkov 6894363ddcaSBoris Boutkov PetscFunctionBegin; 6904363ddcaSBoris Boutkov PetscValidHeaderSpecific(dm,DM_CLASSID,1); 6914363ddcaSBoris Boutkov ierr = PetscObjectTypeCompare((PetscObject)dm,DMSHELL,&isshell);CHKERRQ(ierr); 6928dd90dd5SBoris Boutkov if (!isshell) SETERRQ(PetscObjectComm((PetscObject)dm),PETSC_ERR_SUP,"Can only use with DMSHELL type DMs"); 6934363ddcaSBoris Boutkov *coarsen = dm->ops->coarsen; 6944363ddcaSBoris Boutkov PetscFunctionReturn(0); 6954363ddcaSBoris Boutkov } 6964363ddcaSBoris Boutkov 6974363ddcaSBoris Boutkov /*@C 6989bf9660cSLawrence Mitchell DMShellSetRefine - Set the routine used to refine the shell DM 6999bf9660cSLawrence Mitchell 700d083f849SBarry Smith Logically Collective on dm 7019bf9660cSLawrence Mitchell 7029bf9660cSLawrence Mitchell Input Arguments 7039bf9660cSLawrence Mitchell + dm - the shell DM 7049bf9660cSLawrence Mitchell - refine - the routine that refines the DM 7059bf9660cSLawrence Mitchell 7069bf9660cSLawrence Mitchell Level: advanced 7079bf9660cSLawrence Mitchell 708bf890c61SBoris Boutkov .seealso: DMShellSetCoarsen(), DMRefine(), DMShellGetRefine(), DMShellSetContext(), DMShellGetContext() 7099bf9660cSLawrence Mitchell @*/ 710f572501eSLawrence Mitchell PetscErrorCode DMShellSetRefine(DM dm, PetscErrorCode (*refine)(DM,MPI_Comm,DM*)) 711f572501eSLawrence Mitchell { 712f572501eSLawrence Mitchell PetscErrorCode ierr; 713f572501eSLawrence Mitchell PetscBool isshell; 714f572501eSLawrence Mitchell 715f572501eSLawrence Mitchell PetscFunctionBegin; 716f572501eSLawrence Mitchell PetscValidHeaderSpecific(dm,DM_CLASSID,1); 717f572501eSLawrence Mitchell ierr = PetscObjectTypeCompare((PetscObject)dm,DMSHELL,&isshell);CHKERRQ(ierr); 718f572501eSLawrence Mitchell if (!isshell) PetscFunctionReturn(0); 719f572501eSLawrence Mitchell dm->ops->refine = refine; 720f572501eSLawrence Mitchell PetscFunctionReturn(0); 721f572501eSLawrence Mitchell } 722f572501eSLawrence Mitchell 7239bf9660cSLawrence Mitchell /*@C 7244363ddcaSBoris Boutkov DMShellGetRefine - Get the routine used to refine the shell DM 7254363ddcaSBoris Boutkov 726d083f849SBarry Smith Logically Collective on dm 7274363ddcaSBoris Boutkov 728a4a986ddSBoris Boutkov Input Argument: 7294363ddcaSBoris Boutkov . dm - the shell DM 7304363ddcaSBoris Boutkov 731a4a986ddSBoris Boutkov Output Argument: 7324363ddcaSBoris Boutkov . refine - the routine that refines the DM 7334363ddcaSBoris Boutkov 7344363ddcaSBoris Boutkov Level: advanced 7354363ddcaSBoris Boutkov 7364363ddcaSBoris Boutkov .seealso: DMShellSetCoarsen(), DMCoarsen(), DMShellSetRefine(), DMRefine() 7374363ddcaSBoris Boutkov @*/ 7384363ddcaSBoris Boutkov PetscErrorCode DMShellGetRefine(DM dm, PetscErrorCode (**refine)(DM,MPI_Comm,DM*)) 7394363ddcaSBoris Boutkov { 7404363ddcaSBoris Boutkov PetscErrorCode ierr; 7414363ddcaSBoris Boutkov PetscBool isshell; 7424363ddcaSBoris Boutkov 7434363ddcaSBoris Boutkov PetscFunctionBegin; 7444363ddcaSBoris Boutkov PetscValidHeaderSpecific(dm,DM_CLASSID,1); 7454363ddcaSBoris Boutkov ierr = PetscObjectTypeCompare((PetscObject)dm,DMSHELL,&isshell);CHKERRQ(ierr); 7468dd90dd5SBoris Boutkov if (!isshell) SETERRQ(PetscObjectComm((PetscObject)dm),PETSC_ERR_SUP,"Can only use with DMSHELL type DMs"); 7474363ddcaSBoris Boutkov *refine = dm->ops->refine; 7484363ddcaSBoris Boutkov PetscFunctionReturn(0); 7494363ddcaSBoris Boutkov } 7504363ddcaSBoris Boutkov 7514363ddcaSBoris Boutkov /*@C 7529bf9660cSLawrence Mitchell DMShellSetCreateInterpolation - Set the routine used to create the interpolation operator 7539bf9660cSLawrence Mitchell 754d083f849SBarry Smith Logically Collective on dm 7559bf9660cSLawrence Mitchell 7569bf9660cSLawrence Mitchell Input Arguments 7579bf9660cSLawrence Mitchell + dm - the shell DM 7589bf9660cSLawrence Mitchell - interp - the routine to create the interpolation 7599bf9660cSLawrence Mitchell 7609bf9660cSLawrence Mitchell Level: advanced 7619bf9660cSLawrence Mitchell 762bf890c61SBoris Boutkov .seealso: DMShellSetCreateInjection(), DMCreateInterpolation(), DMShellGetCreateInterpolation(), DMShellSetCreateRestriction(), DMShellSetContext(), DMShellGetContext() 7639bf9660cSLawrence Mitchell @*/ 764f572501eSLawrence Mitchell PetscErrorCode DMShellSetCreateInterpolation(DM dm, PetscErrorCode (*interp)(DM,DM,Mat*,Vec*)) 765f572501eSLawrence Mitchell { 766f572501eSLawrence Mitchell PetscErrorCode ierr; 767f572501eSLawrence Mitchell PetscBool isshell; 768f572501eSLawrence Mitchell 769f572501eSLawrence Mitchell PetscFunctionBegin; 770f572501eSLawrence Mitchell PetscValidHeaderSpecific(dm,DM_CLASSID,1); 771f572501eSLawrence Mitchell ierr = PetscObjectTypeCompare((PetscObject)dm,DMSHELL,&isshell);CHKERRQ(ierr); 772f572501eSLawrence Mitchell if (!isshell) PetscFunctionReturn(0); 773f572501eSLawrence Mitchell dm->ops->createinterpolation = interp; 774f572501eSLawrence Mitchell PetscFunctionReturn(0); 775f572501eSLawrence Mitchell } 776f572501eSLawrence Mitchell 7773ad4599aSBarry Smith /*@C 7784363ddcaSBoris Boutkov DMShellGetCreateInterpolation - Get the routine used to create the interpolation operator 7794363ddcaSBoris Boutkov 780d083f849SBarry Smith Logically Collective on dm 7814363ddcaSBoris Boutkov 782a4a986ddSBoris Boutkov Input Argument: 7834363ddcaSBoris Boutkov + dm - the shell DM 784a4a986ddSBoris Boutkov 785a4a986ddSBoris Boutkov Output Argument: 7864363ddcaSBoris Boutkov - interp - the routine to create the interpolation 7874363ddcaSBoris Boutkov 7884363ddcaSBoris Boutkov Level: advanced 7894363ddcaSBoris Boutkov 7904363ddcaSBoris Boutkov .seealso: DMShellGetCreateInjection(), DMCreateInterpolation(), DMShellGetCreateRestriction(), DMShellSetContext(), DMShellGetContext() 7914363ddcaSBoris Boutkov @*/ 7924363ddcaSBoris Boutkov PetscErrorCode DMShellGetCreateInterpolation(DM dm, PetscErrorCode (**interp)(DM,DM,Mat*,Vec*)) 7934363ddcaSBoris Boutkov { 7944363ddcaSBoris Boutkov PetscErrorCode ierr; 7954363ddcaSBoris Boutkov PetscBool isshell; 7964363ddcaSBoris Boutkov 7974363ddcaSBoris Boutkov PetscFunctionBegin; 7984363ddcaSBoris Boutkov PetscValidHeaderSpecific(dm,DM_CLASSID,1); 7994363ddcaSBoris Boutkov ierr = PetscObjectTypeCompare((PetscObject)dm,DMSHELL,&isshell);CHKERRQ(ierr); 8008dd90dd5SBoris Boutkov if (!isshell) SETERRQ(PetscObjectComm((PetscObject)dm),PETSC_ERR_SUP,"Can only use with DMSHELL type DMs"); 8014363ddcaSBoris Boutkov *interp = dm->ops->createinterpolation; 8024363ddcaSBoris Boutkov PetscFunctionReturn(0); 8034363ddcaSBoris Boutkov } 8044363ddcaSBoris Boutkov 8054363ddcaSBoris Boutkov /*@C 8063ad4599aSBarry Smith DMShellSetCreateRestriction - Set the routine used to create the restriction operator 8073ad4599aSBarry Smith 808d083f849SBarry Smith Logically Collective on dm 8093ad4599aSBarry Smith 8103ad4599aSBarry Smith Input Arguments 8113ad4599aSBarry Smith + dm - the shell DM 8123ad4599aSBarry Smith - striction- the routine to create the restriction 8133ad4599aSBarry Smith 8143ad4599aSBarry Smith Level: advanced 8153ad4599aSBarry Smith 816bf890c61SBoris Boutkov .seealso: DMShellSetCreateInjection(), DMCreateInterpolation(), DMShellGetCreateRestriction(), DMShellSetContext(), DMShellGetContext() 8173ad4599aSBarry Smith @*/ 8183ad4599aSBarry Smith PetscErrorCode DMShellSetCreateRestriction(DM dm, PetscErrorCode (*restriction)(DM,DM,Mat*)) 8193ad4599aSBarry Smith { 8203ad4599aSBarry Smith PetscErrorCode ierr; 8213ad4599aSBarry Smith PetscBool isshell; 8223ad4599aSBarry Smith 8233ad4599aSBarry Smith PetscFunctionBegin; 8243ad4599aSBarry Smith PetscValidHeaderSpecific(dm,DM_CLASSID,1); 8253ad4599aSBarry Smith ierr = PetscObjectTypeCompare((PetscObject)dm,DMSHELL,&isshell);CHKERRQ(ierr); 8263ad4599aSBarry Smith if (!isshell) PetscFunctionReturn(0); 8273ad4599aSBarry Smith dm->ops->createrestriction = restriction; 8283ad4599aSBarry Smith PetscFunctionReturn(0); 8293ad4599aSBarry Smith } 8303ad4599aSBarry Smith 8319bf9660cSLawrence Mitchell /*@C 8324363ddcaSBoris Boutkov DMShellGetCreateRestriction - Get the routine used to create the restriction operator 8334363ddcaSBoris Boutkov 834d083f849SBarry Smith Logically Collective on dm 8354363ddcaSBoris Boutkov 836a4a986ddSBoris Boutkov Input Argument: 8374363ddcaSBoris Boutkov + dm - the shell DM 838a4a986ddSBoris Boutkov 839a4a986ddSBoris Boutkov Output Argument: 840a4a986ddSBoris Boutkov - restriction - the routine to create the restriction 8414363ddcaSBoris Boutkov 8424363ddcaSBoris Boutkov Level: advanced 8434363ddcaSBoris Boutkov 8444363ddcaSBoris Boutkov .seealso: DMShellSetCreateInjection(), DMCreateInterpolation(), DMShellSetContext(), DMShellGetContext() 8454363ddcaSBoris Boutkov @*/ 8464363ddcaSBoris Boutkov PetscErrorCode DMShellGetCreateRestriction(DM dm, PetscErrorCode (**restriction)(DM,DM,Mat*)) 8474363ddcaSBoris Boutkov { 8484363ddcaSBoris Boutkov PetscErrorCode ierr; 8494363ddcaSBoris Boutkov PetscBool isshell; 8504363ddcaSBoris Boutkov 8514363ddcaSBoris Boutkov PetscFunctionBegin; 8524363ddcaSBoris Boutkov PetscValidHeaderSpecific(dm,DM_CLASSID,1); 8534363ddcaSBoris Boutkov ierr = PetscObjectTypeCompare((PetscObject)dm,DMSHELL,&isshell);CHKERRQ(ierr); 8548dd90dd5SBoris Boutkov if (!isshell) SETERRQ(PetscObjectComm((PetscObject)dm),PETSC_ERR_SUP,"Can only use with DMSHELL type DMs"); 8554363ddcaSBoris Boutkov *restriction = dm->ops->createrestriction; 8564363ddcaSBoris Boutkov PetscFunctionReturn(0); 8574363ddcaSBoris Boutkov } 8584363ddcaSBoris Boutkov 8594363ddcaSBoris Boutkov /*@C 8609bf9660cSLawrence Mitchell DMShellSetCreateInjection - Set the routine used to create the injection operator 8619bf9660cSLawrence Mitchell 862d083f849SBarry Smith Logically Collective on dm 8639bf9660cSLawrence Mitchell 8649bf9660cSLawrence Mitchell Input Arguments 8659bf9660cSLawrence Mitchell + dm - the shell DM 8669bf9660cSLawrence Mitchell - inject - the routine to create the injection 8679bf9660cSLawrence Mitchell 8689bf9660cSLawrence Mitchell Level: advanced 8699bf9660cSLawrence Mitchell 870bf890c61SBoris Boutkov .seealso: DMShellSetCreateInterpolation(), DMCreateInjection(), DMShellGetCreateInjection(), DMShellSetContext(), DMShellGetContext() 8719bf9660cSLawrence Mitchell @*/ 872f572501eSLawrence Mitchell PetscErrorCode DMShellSetCreateInjection(DM dm, PetscErrorCode (*inject)(DM,DM,Mat*)) 873f572501eSLawrence Mitchell { 874f572501eSLawrence Mitchell PetscErrorCode ierr; 875f572501eSLawrence Mitchell PetscBool isshell; 876f572501eSLawrence Mitchell 877f572501eSLawrence Mitchell PetscFunctionBegin; 878f572501eSLawrence Mitchell PetscValidHeaderSpecific(dm,DM_CLASSID,1); 879f572501eSLawrence Mitchell ierr = PetscObjectTypeCompare((PetscObject)dm,DMSHELL,&isshell);CHKERRQ(ierr); 880f572501eSLawrence Mitchell if (!isshell) PetscFunctionReturn(0); 8815a84ad33SLisandro Dalcin dm->ops->createinjection = inject; 882f572501eSLawrence Mitchell PetscFunctionReturn(0); 883f572501eSLawrence Mitchell } 884f572501eSLawrence Mitchell 8854363ddcaSBoris Boutkov /*@C 8864363ddcaSBoris Boutkov DMShellGetCreateInjection - Get the routine used to create the injection operator 8874363ddcaSBoris Boutkov 888d083f849SBarry Smith Logically Collective on dm 8894363ddcaSBoris Boutkov 890a4a986ddSBoris Boutkov Input Argument: 8914363ddcaSBoris Boutkov + dm - the shell DM 892a4a986ddSBoris Boutkov 893a4a986ddSBoris Boutkov Output Argument: 8944363ddcaSBoris Boutkov - inject - the routine to create the injection 8954363ddcaSBoris Boutkov 8964363ddcaSBoris Boutkov Level: advanced 8974363ddcaSBoris Boutkov 8984363ddcaSBoris Boutkov .seealso: DMShellGetCreateInterpolation(), DMCreateInjection(), DMShellSetContext(), DMShellGetContext() 8994363ddcaSBoris Boutkov @*/ 9004363ddcaSBoris Boutkov PetscErrorCode DMShellGetCreateInjection(DM dm, PetscErrorCode (**inject)(DM,DM,Mat*)) 9014363ddcaSBoris Boutkov { 9024363ddcaSBoris Boutkov PetscErrorCode ierr; 9034363ddcaSBoris Boutkov PetscBool isshell; 9044363ddcaSBoris Boutkov 9054363ddcaSBoris Boutkov PetscFunctionBegin; 9064363ddcaSBoris Boutkov PetscValidHeaderSpecific(dm,DM_CLASSID,1); 9074363ddcaSBoris Boutkov ierr = PetscObjectTypeCompare((PetscObject)dm,DMSHELL,&isshell);CHKERRQ(ierr); 9088dd90dd5SBoris Boutkov if (!isshell) SETERRQ(PetscObjectComm((PetscObject)dm),PETSC_ERR_SUP,"Can only use with DMSHELL type DMs"); 9095a84ad33SLisandro Dalcin *inject = dm->ops->createinjection; 9104363ddcaSBoris Boutkov PetscFunctionReturn(0); 9114363ddcaSBoris Boutkov } 9124363ddcaSBoris Boutkov 9139bf9660cSLawrence Mitchell /*@C 9149bf9660cSLawrence Mitchell DMShellSetCreateFieldDecomposition - Set the routine used to create a decomposition of fields for the shell DM 9159bf9660cSLawrence Mitchell 916d083f849SBarry Smith Logically Collective on dm 9179bf9660cSLawrence Mitchell 9189bf9660cSLawrence Mitchell Input Arguments 9199bf9660cSLawrence Mitchell + dm - the shell DM 9209bf9660cSLawrence Mitchell - decomp - the routine to create the decomposition 9219bf9660cSLawrence Mitchell 9229bf9660cSLawrence Mitchell Level: advanced 9239bf9660cSLawrence Mitchell 924fef3a512SBarry Smith .seealso: DMCreateFieldDecomposition(), DMShellSetContext(), DMShellGetContext() 9259bf9660cSLawrence Mitchell @*/ 9265e2259d5SLawrence Mitchell PetscErrorCode DMShellSetCreateFieldDecomposition(DM dm, PetscErrorCode (*decomp)(DM,PetscInt*,char***, IS**,DM**)) 9275e2259d5SLawrence Mitchell { 9285e2259d5SLawrence Mitchell PetscErrorCode ierr; 9295e2259d5SLawrence Mitchell PetscBool isshell; 9305e2259d5SLawrence Mitchell 9315e2259d5SLawrence Mitchell PetscFunctionBegin; 9325e2259d5SLawrence Mitchell PetscValidHeaderSpecific(dm,DM_CLASSID,1); 9335e2259d5SLawrence Mitchell ierr = PetscObjectTypeCompare((PetscObject)dm,DMSHELL,&isshell);CHKERRQ(ierr); 9345e2259d5SLawrence Mitchell if (!isshell) PetscFunctionReturn(0); 9355e2259d5SLawrence Mitchell dm->ops->createfielddecomposition = decomp; 9365e2259d5SLawrence Mitchell PetscFunctionReturn(0); 9375e2259d5SLawrence Mitchell } 9385e2259d5SLawrence Mitchell 939c00061e5SLawrence Mitchell /*@C 940e734121bSPatrick Farrell DMShellSetCreateDomainDecomposition - Set the routine used to create a domain decomposition for the shell DM 941e734121bSPatrick Farrell 942d083f849SBarry Smith Logically Collective on dm 943e734121bSPatrick Farrell 944e734121bSPatrick Farrell Input Arguments 945e734121bSPatrick Farrell + dm - the shell DM 946e734121bSPatrick Farrell - decomp - the routine to create the decomposition 947e734121bSPatrick Farrell 948e734121bSPatrick Farrell Level: advanced 949e734121bSPatrick Farrell 950e734121bSPatrick Farrell .seealso: DMCreateDomainDecomposition(), DMShellSetContext(), DMShellGetContext() 951e734121bSPatrick Farrell @*/ 952e734121bSPatrick Farrell PetscErrorCode DMShellSetCreateDomainDecomposition(DM dm, PetscErrorCode (*decomp)(DM,PetscInt*,char***, IS**,IS**,DM**)) 953e734121bSPatrick Farrell { 954e734121bSPatrick Farrell PetscErrorCode ierr; 955e734121bSPatrick Farrell PetscBool isshell; 956e734121bSPatrick Farrell 957e734121bSPatrick Farrell PetscFunctionBegin; 958e734121bSPatrick Farrell PetscValidHeaderSpecific(dm,DM_CLASSID,1); 959e734121bSPatrick Farrell ierr = PetscObjectTypeCompare((PetscObject)dm,DMSHELL,&isshell);CHKERRQ(ierr); 960e734121bSPatrick Farrell if (!isshell) PetscFunctionReturn(0); 961e734121bSPatrick Farrell dm->ops->createdomaindecomposition = decomp; 962e734121bSPatrick Farrell PetscFunctionReturn(0); 963e734121bSPatrick Farrell } 964e734121bSPatrick Farrell 965e734121bSPatrick Farrell /*@C 966eef9d6cdSPatrick Farrell DMShellSetCreateDomainDecompositionScatters - Set the routine used to create the scatter contexts for domain decomposition with a shell DM 967eef9d6cdSPatrick Farrell 968d083f849SBarry Smith Logically Collective on dm 969eef9d6cdSPatrick Farrell 970eef9d6cdSPatrick Farrell Input Arguments 971eef9d6cdSPatrick Farrell + dm - the shell DM 972eef9d6cdSPatrick Farrell - scatter - the routine to create the scatters 973eef9d6cdSPatrick Farrell 974eef9d6cdSPatrick Farrell Level: advanced 975eef9d6cdSPatrick Farrell 976448b6425SPatrick Farrell .seealso: DMCreateDomainDecompositionScatters(), DMShellSetContext(), DMShellGetContext() 977eef9d6cdSPatrick Farrell @*/ 978eef9d6cdSPatrick Farrell PetscErrorCode DMShellSetCreateDomainDecompositionScatters(DM dm, PetscErrorCode (*scatter)(DM,PetscInt,DM*,VecScatter**,VecScatter**,VecScatter**)) 979eef9d6cdSPatrick Farrell { 980eef9d6cdSPatrick Farrell PetscErrorCode ierr; 981eef9d6cdSPatrick Farrell PetscBool isshell; 982eef9d6cdSPatrick Farrell 983eef9d6cdSPatrick Farrell PetscFunctionBegin; 984eef9d6cdSPatrick Farrell PetscValidHeaderSpecific(dm,DM_CLASSID,1); 985eef9d6cdSPatrick Farrell ierr = PetscObjectTypeCompare((PetscObject)dm,DMSHELL,&isshell);CHKERRQ(ierr); 986eef9d6cdSPatrick Farrell if (!isshell) PetscFunctionReturn(0); 987eef9d6cdSPatrick Farrell dm->ops->createddscatters = scatter; 988eef9d6cdSPatrick Farrell PetscFunctionReturn(0); 989eef9d6cdSPatrick Farrell } 990eef9d6cdSPatrick Farrell 991eef9d6cdSPatrick Farrell /*@C 992c00061e5SLawrence Mitchell DMShellSetCreateSubDM - Set the routine used to create a sub DM from the shell DM 993c00061e5SLawrence Mitchell 994d083f849SBarry Smith Logically Collective on dm 995c00061e5SLawrence Mitchell 996c00061e5SLawrence Mitchell Input Arguments 997c00061e5SLawrence Mitchell + dm - the shell DM 998c00061e5SLawrence Mitchell - subdm - the routine to create the decomposition 999c00061e5SLawrence Mitchell 1000c00061e5SLawrence Mitchell Level: advanced 1001c00061e5SLawrence Mitchell 1002bf890c61SBoris Boutkov .seealso: DMCreateSubDM(), DMShellGetCreateSubDM(), DMShellSetContext(), DMShellGetContext() 1003c00061e5SLawrence Mitchell @*/ 1004276c5506SMatthew G. Knepley PetscErrorCode DMShellSetCreateSubDM(DM dm, PetscErrorCode (*subdm)(DM,PetscInt,const PetscInt[],IS*,DM*)) 1005c00061e5SLawrence Mitchell { 1006c00061e5SLawrence Mitchell PetscErrorCode ierr; 1007c00061e5SLawrence Mitchell PetscBool isshell; 1008c00061e5SLawrence Mitchell 1009c00061e5SLawrence Mitchell PetscFunctionBegin; 1010c00061e5SLawrence Mitchell PetscValidHeaderSpecific(dm,DM_CLASSID,1); 1011c00061e5SLawrence Mitchell ierr = PetscObjectTypeCompare((PetscObject)dm,DMSHELL,&isshell);CHKERRQ(ierr); 1012c00061e5SLawrence Mitchell if (!isshell) PetscFunctionReturn(0); 1013c00061e5SLawrence Mitchell dm->ops->createsubdm = subdm; 1014c00061e5SLawrence Mitchell PetscFunctionReturn(0); 1015c00061e5SLawrence Mitchell } 1016c00061e5SLawrence Mitchell 10174363ddcaSBoris Boutkov /*@C 10184363ddcaSBoris Boutkov DMShellGetCreateSubDM - Get the routine used to create a sub DM from the shell DM 10194363ddcaSBoris Boutkov 1020d083f849SBarry Smith Logically Collective on dm 10214363ddcaSBoris Boutkov 1022a4a986ddSBoris Boutkov Input Argument: 10234363ddcaSBoris Boutkov + dm - the shell DM 1024a4a986ddSBoris Boutkov 1025a4a986ddSBoris Boutkov Output Argument: 10264363ddcaSBoris Boutkov - subdm - the routine to create the decomposition 10274363ddcaSBoris Boutkov 10284363ddcaSBoris Boutkov Level: advanced 10294363ddcaSBoris Boutkov 10304363ddcaSBoris Boutkov .seealso: DMCreateSubDM(), DMShellSetCreateSubDM(), DMShellSetContext(), DMShellGetContext() 10314363ddcaSBoris Boutkov @*/ 10324363ddcaSBoris Boutkov PetscErrorCode DMShellGetCreateSubDM(DM dm, PetscErrorCode (**subdm)(DM,PetscInt,const PetscInt[],IS*,DM*)) 10334363ddcaSBoris Boutkov { 10344363ddcaSBoris Boutkov PetscErrorCode ierr; 10354363ddcaSBoris Boutkov PetscBool isshell; 10364363ddcaSBoris Boutkov 10374363ddcaSBoris Boutkov PetscFunctionBegin; 10384363ddcaSBoris Boutkov PetscValidHeaderSpecific(dm,DM_CLASSID,1); 10394363ddcaSBoris Boutkov ierr = PetscObjectTypeCompare((PetscObject)dm,DMSHELL,&isshell);CHKERRQ(ierr); 10408dd90dd5SBoris Boutkov if (!isshell) SETERRQ(PetscObjectComm((PetscObject)dm),PETSC_ERR_SUP,"Can only use with DMSHELL type DMs"); 10414363ddcaSBoris Boutkov *subdm = dm->ops->createsubdm; 10424363ddcaSBoris Boutkov PetscFunctionReturn(0); 10434363ddcaSBoris Boutkov } 10444363ddcaSBoris Boutkov 1045fe1899a2SJed Brown static PetscErrorCode DMDestroy_Shell(DM dm) 1046fe1899a2SJed Brown { 1047fe1899a2SJed Brown PetscErrorCode ierr; 1048fe1899a2SJed Brown DM_Shell *shell = (DM_Shell*)dm->data; 1049fe1899a2SJed Brown 1050fe1899a2SJed Brown PetscFunctionBegin; 1051fe1899a2SJed Brown ierr = MatDestroy(&shell->A);CHKERRQ(ierr); 1052fe1899a2SJed Brown ierr = VecDestroy(&shell->Xglobal);CHKERRQ(ierr); 1053dc43b69eSJed Brown ierr = VecDestroy(&shell->Xlocal);CHKERRQ(ierr); 1054a94b16f6SRichard Tran Mills ierr = VecScatterDestroy(&shell->gtol);CHKERRQ(ierr); 1055a94b16f6SRichard Tran Mills ierr = VecScatterDestroy(&shell->ltog);CHKERRQ(ierr); 1056294a6417SLawrence Mitchell ierr = VecScatterDestroy(&shell->ltol);CHKERRQ(ierr); 10577b6ad80cSMatthew G Knepley /* This was originally freed in DMDestroy(), but that prevents reference counting of backend objects */ 10587b6ad80cSMatthew G Knepley ierr = PetscFree(shell);CHKERRQ(ierr); 1059fe1899a2SJed Brown PetscFunctionReturn(0); 1060fe1899a2SJed Brown } 1061fe1899a2SJed Brown 10622d53ad75SBarry Smith static PetscErrorCode DMView_Shell(DM dm,PetscViewer v) 10632d53ad75SBarry Smith { 10642d53ad75SBarry Smith PetscErrorCode ierr; 10652d53ad75SBarry Smith DM_Shell *shell = (DM_Shell*)dm->data; 10662d53ad75SBarry Smith 10672d53ad75SBarry Smith PetscFunctionBegin; 10682d53ad75SBarry Smith ierr = VecView(shell->Xglobal,v);CHKERRQ(ierr); 10692d53ad75SBarry Smith PetscFunctionReturn(0); 10702d53ad75SBarry Smith } 10712d53ad75SBarry Smith 10722d53ad75SBarry Smith static PetscErrorCode DMLoad_Shell(DM dm,PetscViewer v) 10732d53ad75SBarry Smith { 10742d53ad75SBarry Smith PetscErrorCode ierr; 10752d53ad75SBarry Smith DM_Shell *shell = (DM_Shell*)dm->data; 10762d53ad75SBarry Smith 10772d53ad75SBarry Smith PetscFunctionBegin; 1078ce94432eSBarry Smith ierr = VecCreate(PetscObjectComm((PetscObject)dm),&shell->Xglobal);CHKERRQ(ierr); 10792d53ad75SBarry Smith ierr = VecLoad(shell->Xglobal,v);CHKERRQ(ierr); 10802d53ad75SBarry Smith PetscFunctionReturn(0); 10812d53ad75SBarry Smith } 1082fe1899a2SJed Brown 1083276c5506SMatthew G. Knepley PetscErrorCode DMCreateSubDM_Shell(DM dm, PetscInt numFields, const PetscInt fields[], IS *is, DM *subdm) 10846e44b4cfSMatthew G. Knepley { 10856e44b4cfSMatthew G. Knepley PetscErrorCode ierr; 10866e44b4cfSMatthew G. Knepley 10876e44b4cfSMatthew G. Knepley PetscFunctionBegin; 10886e44b4cfSMatthew G. Knepley if (subdm) {ierr = DMShellCreate(PetscObjectComm((PetscObject) dm), subdm);CHKERRQ(ierr);} 1089792b654fSMatthew G. Knepley ierr = DMCreateSectionSubDM(dm, numFields, fields, is, subdm);CHKERRQ(ierr); 10906e44b4cfSMatthew G. Knepley PetscFunctionReturn(0); 10916e44b4cfSMatthew G. Knepley } 10926e44b4cfSMatthew G. Knepley 10938cc058d9SJed Brown PETSC_EXTERN PetscErrorCode DMCreate_Shell(DM dm) 1094fe1899a2SJed Brown { 1095fe1899a2SJed Brown PetscErrorCode ierr; 1096fe1899a2SJed Brown DM_Shell *shell; 1097fe1899a2SJed Brown 1098fe1899a2SJed Brown PetscFunctionBegin; 1099b00a9115SJed Brown ierr = PetscNewLog(dm,&shell);CHKERRQ(ierr); 11008c87107bSJed Brown dm->data = shell; 1101fe1899a2SJed Brown 11028c87107bSJed Brown dm->ops->destroy = DMDestroy_Shell; 11038c87107bSJed Brown dm->ops->createglobalvector = DMCreateGlobalVector_Shell; 1104dc43b69eSJed Brown dm->ops->createlocalvector = DMCreateLocalVector_Shell; 11058c87107bSJed Brown dm->ops->creatematrix = DMCreateMatrix_Shell; 11062d53ad75SBarry Smith dm->ops->view = DMView_Shell; 11072d53ad75SBarry Smith dm->ops->load = DMLoad_Shell; 11087a108d1dSBarry Smith dm->ops->globaltolocalbegin = DMGlobalToLocalBeginDefaultShell; 11097a108d1dSBarry Smith dm->ops->globaltolocalend = DMGlobalToLocalEndDefaultShell; 111055daaa54SRichard Tran Mills dm->ops->localtoglobalbegin = DMLocalToGlobalBeginDefaultShell; 111155daaa54SRichard Tran Mills dm->ops->localtoglobalend = DMLocalToGlobalEndDefaultShell; 111263731094SRichard Tran Mills dm->ops->localtolocalbegin = DMLocalToLocalBeginDefaultShell; 111363731094SRichard Tran Mills dm->ops->localtolocalend = DMLocalToLocalEndDefaultShell; 11146e44b4cfSMatthew G. Knepley dm->ops->createsubdm = DMCreateSubDM_Shell; 11152a350339SBarry Smith ierr = DMSetMatType(dm,MATDENSE);CHKERRQ(ierr); 1116fe1899a2SJed Brown PetscFunctionReturn(0); 1117fe1899a2SJed Brown } 1118fe1899a2SJed Brown 1119fe1899a2SJed Brown /*@ 1120fe1899a2SJed Brown DMShellCreate - Creates a shell DM object, used to manage user-defined problem data 1121fe1899a2SJed Brown 1122d083f849SBarry Smith Collective 1123fe1899a2SJed Brown 1124fe1899a2SJed Brown Input Parameter: 1125fe1899a2SJed Brown . comm - the processors that will share the global vector 1126fe1899a2SJed Brown 1127fe1899a2SJed Brown Output Parameters: 1128fe1899a2SJed Brown . shell - the shell DM 1129fe1899a2SJed Brown 1130fe1899a2SJed Brown Level: advanced 1131fe1899a2SJed Brown 1132fef3a512SBarry Smith .seealso DMDestroy(), DMCreateGlobalVector(), DMCreateLocalVector(), DMShellSetContext(), DMShellGetContext() 1133fe1899a2SJed Brown @*/ 1134fe1899a2SJed Brown PetscErrorCode DMShellCreate(MPI_Comm comm,DM *dm) 1135fe1899a2SJed Brown { 1136fe1899a2SJed Brown PetscErrorCode ierr; 1137fe1899a2SJed Brown 1138fe1899a2SJed Brown PetscFunctionBegin; 1139fe1899a2SJed Brown PetscValidPointer(dm,2); 1140fe1899a2SJed Brown ierr = DMCreate(comm,dm);CHKERRQ(ierr); 1141fe1899a2SJed Brown ierr = DMSetType(*dm,DMSHELL);CHKERRQ(ierr); 114281a566bfSMatthew G. Knepley ierr = DMSetUp(*dm);CHKERRQ(ierr); 1143fe1899a2SJed Brown PetscFunctionReturn(0); 1144fe1899a2SJed Brown } 1145