1174b6946SBarry Smith #define PETSCKSP_DLL 2174b6946SBarry Smith 3174b6946SBarry Smith 4174b6946SBarry Smith #include "petscpc.h" /*I "petscpc.h" I*/ 5a9f2baa8SLisandro Dalcin #include "petscmg.h" /*I "petscmg.h" I*/ 6174b6946SBarry Smith #include "petscda.h" /*I "petscda.h" I*/ 77233f9f0SBarry Smith #include "../src/ksp/pc/impls/mg/mgimpl.h" 87233f9f0SBarry Smith 97233f9f0SBarry Smith const char *PCExoticTypes[] = {"face","wirebasket","PCExoticType","PC_Exotic",0}; 10174b6946SBarry Smith 1196bdf778SBarry Smith extern PetscErrorCode DAGetWireBasketInterpolation(DA,Mat,MatReuse,Mat*); 1296bdf778SBarry Smith extern PetscErrorCode DAGetFaceInterpolation(DA,Mat,MatReuse,Mat*); 13174b6946SBarry Smith 147233f9f0SBarry Smith typedef struct { 157233f9f0SBarry Smith DA da; 167233f9f0SBarry Smith PCExoticType type; 1796bdf778SBarry Smith Mat P; /* the interpolation matrix */ 187233f9f0SBarry Smith } PC_Exotic; 197233f9f0SBarry Smith 20174b6946SBarry Smith #undef __FUNCT__ 217233f9f0SBarry Smith #define __FUNCT__ "PCExoticSetType" 227233f9f0SBarry Smith /*@ 237233f9f0SBarry Smith PCExoticSetType - Sets the type of coarse grid interpolation to use 247233f9f0SBarry Smith 257233f9f0SBarry Smith Collective on PC 267233f9f0SBarry Smith 277233f9f0SBarry Smith Input Parameters: 287233f9f0SBarry Smith + pc - the preconditioner context 297233f9f0SBarry Smith - type - either PC_EXOTIC_FACE or PC_EXOTIC_WIREBASKET (defaults to face) 307233f9f0SBarry Smith 31*563e08c6SBarry Smith Notes: The face based interpolation has 1 degree of freedom per face and ignores the 32*563e08c6SBarry Smith edge and vertex values completely in the coarse problem. For any seven point 33*563e08c6SBarry Smith stencil the interpolation of a constant on all faces into the interior is that constant. 34*563e08c6SBarry Smith 35*563e08c6SBarry Smith The wirebasket interpolation has 1 degree of freedom per vertex, per edge and 36*563e08c6SBarry Smith per face. A constant on the subdomain boundary is interpolated as that constant 37*563e08c6SBarry Smith in the interior of the domain. 38*563e08c6SBarry Smith 39*563e08c6SBarry Smith The coarse grid matrix is obtained via the Galerkin computation A_c = R A R^T, hence 40*563e08c6SBarry Smith if A is nonsingular A_c is also nonsingular. 41*563e08c6SBarry Smith 42*563e08c6SBarry Smith Both interpolations are suitable for only scalar problems. 43*563e08c6SBarry Smith 447233f9f0SBarry Smith Level: intermediate 457233f9f0SBarry Smith 467233f9f0SBarry Smith 477233f9f0SBarry Smith .seealso: PCEXOTIC, PCExoticType() 487233f9f0SBarry Smith @*/ 497233f9f0SBarry Smith PetscErrorCode PETSCKSP_DLLEXPORT PCExoticSetType(PC pc,PCExoticType type) 507233f9f0SBarry Smith { 517233f9f0SBarry Smith PetscErrorCode ierr,(*f)(PC,PCExoticType); 527233f9f0SBarry Smith 537233f9f0SBarry Smith PetscFunctionBegin; 547233f9f0SBarry Smith PetscValidHeaderSpecific(pc,PC_COOKIE,1); 557233f9f0SBarry Smith ierr = PetscObjectQueryFunction((PetscObject)pc,"PCExoticSetType_C",(void (**)(void))&f);CHKERRQ(ierr); 567233f9f0SBarry Smith if (f) { 577233f9f0SBarry Smith ierr = (*f)(pc,type);CHKERRQ(ierr); 587233f9f0SBarry Smith } 597233f9f0SBarry Smith PetscFunctionReturn(0); 607233f9f0SBarry Smith } 617233f9f0SBarry Smith 627233f9f0SBarry Smith #undef __FUNCT__ 637233f9f0SBarry Smith #define __FUNCT__ "PCExoticSetType_Exotic" 647233f9f0SBarry Smith PetscErrorCode PETSCKSP_DLLEXPORT PCExoticSetType_Exotic(PC pc,PCExoticType type) 657233f9f0SBarry Smith { 667233f9f0SBarry Smith PC_MG **mg = (PC_MG**)pc->data; 67bedee52eSLisandro Dalcin PC_Exotic *ctx = (PC_Exotic*) mg[0]->innerctx; 687233f9f0SBarry Smith 697233f9f0SBarry Smith PetscFunctionBegin; 707233f9f0SBarry Smith ctx->type = type; 717233f9f0SBarry Smith PetscFunctionReturn(0); 727233f9f0SBarry Smith } 737233f9f0SBarry Smith 747233f9f0SBarry Smith #undef __FUNCT__ 757233f9f0SBarry Smith #define __FUNCT__ "PCSetUp_Exotic" 767233f9f0SBarry Smith PetscErrorCode PCSetUp_Exotic(PC pc) 77174b6946SBarry Smith { 78174b6946SBarry Smith PetscErrorCode ierr; 7996bdf778SBarry Smith Mat A; 807233f9f0SBarry Smith PC_MG **mg = (PC_MG**)pc->data; 817233f9f0SBarry Smith PC_Exotic *ex = (PC_Exotic*) mg[0]->innerctx; 827233f9f0SBarry Smith DA da = ex->da; 8396bdf778SBarry Smith MatReuse reuse = (ex->P) ? MAT_REUSE_MATRIX : MAT_INITIAL_MATRIX; 84174b6946SBarry Smith 85174b6946SBarry Smith PetscFunctionBegin; 86174b6946SBarry Smith ierr = PCGetOperators(pc,PETSC_NULL,&A,PETSC_NULL);CHKERRQ(ierr); 877233f9f0SBarry Smith if (ex->type == PC_EXOTIC_FACE) { 8896bdf778SBarry Smith ierr = DAGetFaceInterpolation(da,A,reuse,&ex->P);CHKERRQ(ierr); 897233f9f0SBarry Smith } else if (ex->type == PC_EXOTIC_WIREBASKET) { 9096bdf778SBarry Smith ierr = DAGetWireBasketInterpolation(da,A,reuse,&ex->P);CHKERRQ(ierr); 917233f9f0SBarry Smith } else SETERRQ1(PETSC_ERR_PLIB,"Unknown exotic coarse space %d",ex->type); 9296bdf778SBarry Smith ierr = PCMGSetInterpolation(pc,1,ex->P);CHKERRQ(ierr); 937233f9f0SBarry Smith ierr = PCSetUp_MG(pc);CHKERRQ(ierr); 94174b6946SBarry Smith PetscFunctionReturn(0); 95174b6946SBarry Smith } 96174b6946SBarry Smith 97174b6946SBarry Smith #undef __FUNCT__ 987233f9f0SBarry Smith #define __FUNCT__ "PCDestroy_Exotic" 997233f9f0SBarry Smith PetscErrorCode PCDestroy_Exotic(PC pc) 100174b6946SBarry Smith { 101174b6946SBarry Smith PetscErrorCode ierr; 1027233f9f0SBarry Smith PC_MG **mg = (PC_MG**)pc->data; 103bedee52eSLisandro Dalcin PC_Exotic *ctx = (PC_Exotic*) mg[0]->innerctx; 104174b6946SBarry Smith 105174b6946SBarry Smith PetscFunctionBegin; 10696bdf778SBarry Smith if (ctx->da) {ierr = DADestroy(ctx->da);CHKERRQ(ierr);} 10796bdf778SBarry Smith if (ctx->P) {ierr = MatDestroy(ctx->P);CHKERRQ(ierr);} 1087233f9f0SBarry Smith ierr = PetscFree(ctx);CHKERRQ(ierr); 1097233f9f0SBarry Smith ierr = PCDestroy_MG(pc);CHKERRQ(ierr); 110174b6946SBarry Smith PetscFunctionReturn(0); 111174b6946SBarry Smith } 112174b6946SBarry Smith 113174b6946SBarry Smith #undef __FUNCT__ 1147233f9f0SBarry Smith #define __FUNCT__ "PCSetUp_Exotic_Error" 1157233f9f0SBarry Smith PetscErrorCode PCSetUp_Exotic_Error(PC pc) 116174b6946SBarry Smith { 117174b6946SBarry Smith PetscFunctionBegin; 1187233f9f0SBarry Smith SETERRQ(PETSC_ERR_ARG_WRONGSTATE,"You are using the Exotic preconditioner but never called PCExoticSetDA()"); 119174b6946SBarry Smith PetscFunctionReturn(0); 120174b6946SBarry Smith } 121174b6946SBarry Smith 122174b6946SBarry Smith #undef __FUNCT__ 1237233f9f0SBarry Smith #define __FUNCT__ "PCExoticSetDA" 1247233f9f0SBarry Smith /*@ 1257233f9f0SBarry Smith PCExoticSetDA - Sets the DA that is to be used by the PCEXOTIC preconditioner 1267233f9f0SBarry Smith 1277233f9f0SBarry Smith Collective on PC 1287233f9f0SBarry Smith 1297233f9f0SBarry Smith Input Parameters: 1307233f9f0SBarry Smith + pc - the preconditioner context 1317233f9f0SBarry Smith - da - the da 1327233f9f0SBarry Smith 1337233f9f0SBarry Smith Level: intermediate 1347233f9f0SBarry Smith 1357233f9f0SBarry Smith 1367233f9f0SBarry Smith .seealso: PCEXOTIC, PCExoticType() 1377233f9f0SBarry Smith @*/ 1387233f9f0SBarry Smith PetscErrorCode PETSCKSP_DLLEXPORT PCExoticSetDA(PC pc,DA da) 139174b6946SBarry Smith { 1407233f9f0SBarry Smith PetscErrorCode ierr,(*f)(PC,DA); 141174b6946SBarry Smith 142174b6946SBarry Smith PetscFunctionBegin; 143174b6946SBarry Smith PetscValidHeaderSpecific(pc,PC_COOKIE,1); 144174b6946SBarry Smith PetscValidHeaderSpecific(da,DM_COOKIE,1); 1457233f9f0SBarry Smith ierr = PetscObjectQueryFunction((PetscObject)pc,"PCExoticSetDA_C",(void (**)(void))&f);CHKERRQ(ierr); 1467233f9f0SBarry Smith if (f) { 1477233f9f0SBarry Smith ierr = (*f)(pc,da);CHKERRQ(ierr); 1487233f9f0SBarry Smith } 1497233f9f0SBarry Smith PetscFunctionReturn(0); 1507233f9f0SBarry Smith } 151174b6946SBarry Smith 1527233f9f0SBarry Smith 1537233f9f0SBarry Smith #undef __FUNCT__ 1547233f9f0SBarry Smith #define __FUNCT__ "PCExoticSetDA_Exotic" 1557233f9f0SBarry Smith PetscErrorCode PETSCKSP_DLLEXPORT PCExoticSetDA_Exotic(PC pc,DA da) 1567233f9f0SBarry Smith { 1577233f9f0SBarry Smith PetscErrorCode ierr; 1587233f9f0SBarry Smith PC_MG **mg = (PC_MG**)pc->data; 159bedee52eSLisandro Dalcin PC_Exotic *ctx = (PC_Exotic*) mg[0]->innerctx; 1607233f9f0SBarry Smith 1617233f9f0SBarry Smith PetscFunctionBegin; 1627233f9f0SBarry Smith ctx->da = da; 1637233f9f0SBarry Smith pc->ops->setup = PCSetUp_Exotic; 164174b6946SBarry Smith ierr = PetscObjectReference((PetscObject)da);CHKERRQ(ierr); 165174b6946SBarry Smith PetscFunctionReturn(0); 166174b6946SBarry Smith } 167174b6946SBarry Smith 1687233f9f0SBarry Smith #undef __FUNCT__ 1697233f9f0SBarry Smith #define __FUNCT__ "PCView_Exotic" 1707233f9f0SBarry Smith PetscErrorCode PCView_Exotic(PC pc,PetscViewer viewer) 1717233f9f0SBarry Smith { 1727233f9f0SBarry Smith PC_MG **mg = (PC_MG**)pc->data; 1737233f9f0SBarry Smith PetscErrorCode ierr; 1747233f9f0SBarry Smith PetscTruth iascii; 175bedee52eSLisandro Dalcin PC_Exotic *ctx = (PC_Exotic*) mg[0]->innerctx; 1767233f9f0SBarry Smith 1777233f9f0SBarry Smith PetscFunctionBegin; 1787233f9f0SBarry Smith ierr = PetscTypeCompare((PetscObject)viewer,PETSC_VIEWER_ASCII,&iascii);CHKERRQ(ierr); 1797233f9f0SBarry Smith if (iascii) { 1807233f9f0SBarry Smith ierr = PetscViewerASCIIPrintf(viewer," Exotic type = %s\n",PCExoticTypes[ctx->type]);CHKERRQ(ierr); 1817233f9f0SBarry Smith } 1827233f9f0SBarry Smith ierr = PCView_MG(pc,viewer);CHKERRQ(ierr); 1837233f9f0SBarry Smith PetscFunctionReturn(0); 1847233f9f0SBarry Smith } 1857233f9f0SBarry Smith 1867233f9f0SBarry Smith #undef __FUNCT__ 1877233f9f0SBarry Smith #define __FUNCT__ "PCSetFromOptions_Exotic" 1887233f9f0SBarry Smith PetscErrorCode PCSetFromOptions_Exotic(PC pc) 1897233f9f0SBarry Smith { 1907233f9f0SBarry Smith PetscErrorCode ierr; 1917233f9f0SBarry Smith PetscTruth flg; 1927233f9f0SBarry Smith PC_MG **mg = (PC_MG**)pc->data; 1937233f9f0SBarry Smith PCExoticType mgctype; 194bedee52eSLisandro Dalcin PC_Exotic *ctx = (PC_Exotic*) mg[0]->innerctx; 1957233f9f0SBarry Smith 1967233f9f0SBarry Smith PetscFunctionBegin; 1977233f9f0SBarry Smith ierr = PetscOptionsHead("Exotic coarse space options");CHKERRQ(ierr); 1987233f9f0SBarry Smith ierr = PetscOptionsEnum("-pc_exotic_type","face or wirebasket","PCExoticSetType",PCExoticTypes,(PetscEnum)ctx->type,(PetscEnum*)&mgctype,&flg);CHKERRQ(ierr); 1997233f9f0SBarry Smith if (flg) { 2007233f9f0SBarry Smith ierr = PCExoticSetType(pc,mgctype);CHKERRQ(ierr); 2017233f9f0SBarry Smith } 2027233f9f0SBarry Smith ierr = PetscOptionsTail();CHKERRQ(ierr); 2037233f9f0SBarry Smith PetscFunctionReturn(0); 2047233f9f0SBarry Smith } 2057233f9f0SBarry Smith 206174b6946SBarry Smith 207174b6946SBarry Smith /*MC 2087233f9f0SBarry Smith PCEXOTIC - Two level overlapping Schwarz preconditioner with exotic (non-standard) coarse grid spaces 209174b6946SBarry Smith 2107233f9f0SBarry Smith This uses the PCMG infrastructure restricted to two levels and the face and wirebasket based coarse 2113b65e785SBarry Smith grid spaces. These coarse grid spaces originate in the work of Bramble, Pasciak and Schatz, "The Construction 2123b65e785SBarry Smith of Preconditioners for Elliptic Problems by Substructing IV", Mathematics of Computation, volume 53 pages 1--24, 1989. 2133b65e785SBarry Smith They were generalized slightly in "Domain Decomposition Method for Linear Elasticity", Ph. D. thesis, Barry Smith, 2143b65e785SBarry Smith New York University, 1990. They were then explored in great detail in Dryja, Smith, Widlund, "Schwarz Analysis 2153b65e785SBarry Smith of Iterative Substructuring Methods for Elliptic Problems in Three Dimensions, SIAM Journal on Numerical 2163b65e785SBarry Smith Analysis, volume 31. pages 1662-1694, 1994. These were developed in the context of iterative substructuring preconditioners. 2173b65e785SBarry Smith They were then ingeniously applied as coarse grid spaces for overlapping Schwarz methods by Dohrmann and Widlund. 2183b65e785SBarry Smith They refer to them as GDSW (generalized Dryja, Smith, Widlund preconditioners). See, for example, 2193b65e785SBarry Smith Clark R. Dohrmann, Axel Klawonn, and Olof B. Widlund. Extending theory for domain decomposition algorithms to irregular subdomains. In Ulrich Langer, Marco 2203b65e785SBarry Smith Discacciati, David Keyes, Olof Widlund, and Walter Zulehner, editors, Proceedings 2213b65e785SBarry Smith of the 17th International Conference on Domain Decomposition Methods in 2223b65e785SBarry Smith Science and Engineering, held in Strobl, Austria, July 3-7, 2006, number 60 in 2233b65e785SBarry Smith Springer-Verlag, Lecture Notes in Computational Science and Engineering, pages 255-261, 2007. 2243b65e785SBarry Smith Clark R. Dohrmann, Axel Klawonn, and Olof B. Widlund. A family of energy min- 2253b65e785SBarry Smith imizing coarse spaces for overlapping Schwarz preconditioners. In Ulrich Langer, 2263b65e785SBarry Smith Marco Discacciati, David Keyes, OlofWidlund, andWalter Zulehner, editors, Proceedings 2273b65e785SBarry Smith of the 17th International Conference on Domain Decomposition Methods 2283b65e785SBarry Smith in Science and Engineering, held in Strobl, Austria, July 3-7, 2006, number 60 in 2293b65e785SBarry Smith Springer-Verlag, Lecture Notes in Computational Science and Engineering, pages 247-254, 2007 2303b65e785SBarry Smith Clark R. Dohrmann, Axel Klawonn, and Olof B. Widlund. Domain decomposition 2313b65e785SBarry Smith for less regular subdomains: Overlapping Schwarz in two dimensions. SIAM J. 2323b65e785SBarry Smith Numer. Anal., 46(4):2153-2168, 2008. 2333b65e785SBarry Smith Clark R. Dohrmann and Olof B. Widlund. An overlapping Schwarz 2343b65e785SBarry Smith algorithm for almost incompressible elasticity. Technical Report 2353b65e785SBarry Smith TR2008-912, Department of Computer Science, Courant Institute 2363b65e785SBarry Smith of Mathematical Sciences, New York University, May 2008. URL: 2373b65e785SBarry Smith http://cs.nyu.edu/csweb/Research/TechReports/TR2008-912/TR2008-912.pdf 2387233f9f0SBarry Smith 2397233f9f0SBarry Smith Options Database: The usual PCMG options are supported, such as -mg_levels_pc_type <type> -mg_coarse_pc_type <type> 2407233f9f0SBarry Smith -pc_mg_type <type> 2417233f9f0SBarry Smith 24225a35f6fSSatish Balay Level: advanced 243174b6946SBarry Smith 24425a35f6fSSatish Balay .seealso: PCMG, PCExoticSetDA(), PCExoticType, PCExoticSetType() 245174b6946SBarry Smith M*/ 246174b6946SBarry Smith 247174b6946SBarry Smith EXTERN_C_BEGIN 248174b6946SBarry Smith #undef __FUNCT__ 2497233f9f0SBarry Smith #define __FUNCT__ "PCCreate_Exotic" 2507233f9f0SBarry Smith PetscErrorCode PETSCKSP_DLLEXPORT PCCreate_Exotic(PC pc) 251174b6946SBarry Smith { 252174b6946SBarry Smith PetscErrorCode ierr; 2537233f9f0SBarry Smith PC_Exotic *ex; 2547233f9f0SBarry Smith PC_MG **mg; 255174b6946SBarry Smith 256174b6946SBarry Smith PetscFunctionBegin; 257174b6946SBarry Smith ierr = PCSetType(pc,PCMG);CHKERRQ(ierr); 258174b6946SBarry Smith ierr = PCMGSetLevels(pc,2,PETSC_NULL);CHKERRQ(ierr); 259174b6946SBarry Smith ierr = PCMGSetGalerkin(pc);CHKERRQ(ierr); 26096bdf778SBarry Smith ierr = PetscNew(PC_Exotic,&ex);CHKERRQ(ierr);\ 2617233f9f0SBarry Smith ex->type = PC_EXOTIC_FACE; 262a36ce94aSMatthew Knepley mg = (PC_MG**) pc->data; 2637233f9f0SBarry Smith mg[0]->innerctx = ex; 2647233f9f0SBarry Smith 2657233f9f0SBarry Smith 2667233f9f0SBarry Smith pc->ops->setfromoptions = PCSetFromOptions_Exotic; 2677233f9f0SBarry Smith pc->ops->view = PCView_Exotic; 2687233f9f0SBarry Smith pc->ops->destroy = PCDestroy_Exotic; 2697233f9f0SBarry Smith pc->ops->setup = PCSetUp_Exotic_Error; 2707233f9f0SBarry Smith ierr = PetscObjectComposeFunctionDynamic((PetscObject)pc,"PCExoticSetType_C","PCExoticSetType_Exotic",PCExoticSetType_Exotic);CHKERRQ(ierr); 2717233f9f0SBarry Smith ierr = PetscObjectComposeFunctionDynamic((PetscObject)pc,"PCExoticSetDA_C","PCExoticSetDA_Exotic",PCExoticSetDA_Exotic);CHKERRQ(ierr); 272174b6946SBarry Smith PetscFunctionReturn(0); 273174b6946SBarry Smith } 274174b6946SBarry Smith EXTERN_C_END 275