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 11174b6946SBarry Smith extern PetscErrorCode DAGetWireBasketInterpolation(DA,Mat,Mat*); 123639cd1fSBarry Smith extern PetscErrorCode DAGetFaceInterpolation(DA,Mat,Mat*); 13174b6946SBarry Smith 147233f9f0SBarry Smith typedef struct { 157233f9f0SBarry Smith DA da; 167233f9f0SBarry Smith PCExoticType type; 177233f9f0SBarry Smith } PC_Exotic; 187233f9f0SBarry Smith 19174b6946SBarry Smith #undef __FUNCT__ 207233f9f0SBarry Smith #define __FUNCT__ "PCExoticSetType" 217233f9f0SBarry Smith /*@ 227233f9f0SBarry Smith PCExoticSetType - Sets the type of coarse grid interpolation to use 237233f9f0SBarry Smith 247233f9f0SBarry Smith Collective on PC 257233f9f0SBarry Smith 267233f9f0SBarry Smith Input Parameters: 277233f9f0SBarry Smith + pc - the preconditioner context 287233f9f0SBarry Smith - type - either PC_EXOTIC_FACE or PC_EXOTIC_WIREBASKET (defaults to face) 297233f9f0SBarry Smith 307233f9f0SBarry Smith Level: intermediate 317233f9f0SBarry Smith 327233f9f0SBarry Smith 337233f9f0SBarry Smith .seealso: PCEXOTIC, PCExoticType() 347233f9f0SBarry Smith @*/ 357233f9f0SBarry Smith PetscErrorCode PETSCKSP_DLLEXPORT PCExoticSetType(PC pc,PCExoticType type) 367233f9f0SBarry Smith { 377233f9f0SBarry Smith PetscErrorCode ierr,(*f)(PC,PCExoticType); 387233f9f0SBarry Smith 397233f9f0SBarry Smith PetscFunctionBegin; 407233f9f0SBarry Smith PetscValidHeaderSpecific(pc,PC_COOKIE,1); 417233f9f0SBarry Smith ierr = PetscObjectQueryFunction((PetscObject)pc,"PCExoticSetType_C",(void (**)(void))&f);CHKERRQ(ierr); 427233f9f0SBarry Smith if (f) { 437233f9f0SBarry Smith ierr = (*f)(pc,type);CHKERRQ(ierr); 447233f9f0SBarry Smith } 457233f9f0SBarry Smith PetscFunctionReturn(0); 467233f9f0SBarry Smith } 477233f9f0SBarry Smith 487233f9f0SBarry Smith #undef __FUNCT__ 497233f9f0SBarry Smith #define __FUNCT__ "PCExoticSetType_Exotic" 507233f9f0SBarry Smith PetscErrorCode PETSCKSP_DLLEXPORT PCExoticSetType_Exotic(PC pc,PCExoticType type) 517233f9f0SBarry Smith { 527233f9f0SBarry Smith PC_MG **mg = (PC_MG**)pc->data; 53bedee52eSLisandro Dalcin PC_Exotic *ctx = (PC_Exotic*) mg[0]->innerctx; 547233f9f0SBarry Smith 557233f9f0SBarry Smith PetscFunctionBegin; 567233f9f0SBarry Smith ctx->type = type; 577233f9f0SBarry Smith PetscFunctionReturn(0); 587233f9f0SBarry Smith } 597233f9f0SBarry Smith 607233f9f0SBarry Smith #undef __FUNCT__ 617233f9f0SBarry Smith #define __FUNCT__ "PCSetUp_Exotic" 627233f9f0SBarry Smith PetscErrorCode PCSetUp_Exotic(PC pc) 63174b6946SBarry Smith { 64174b6946SBarry Smith PetscErrorCode ierr; 65174b6946SBarry Smith Mat A,P; 667233f9f0SBarry Smith PC_MG **mg = (PC_MG**)pc->data; 677233f9f0SBarry Smith PC_Exotic *ex = (PC_Exotic*) mg[0]->innerctx; 687233f9f0SBarry Smith DA da = ex->da; 69174b6946SBarry Smith 70174b6946SBarry Smith PetscFunctionBegin; 71174b6946SBarry Smith ierr = PCGetOperators(pc,PETSC_NULL,&A,PETSC_NULL);CHKERRQ(ierr); 727233f9f0SBarry Smith if (ex->type == PC_EXOTIC_FACE) { 733639cd1fSBarry Smith ierr = DAGetFaceInterpolation(da,A,&P);CHKERRQ(ierr); 747233f9f0SBarry Smith } else if (ex->type == PC_EXOTIC_WIREBASKET) { 757233f9f0SBarry Smith ierr = DAGetWireBasketInterpolation(da,A,&P);CHKERRQ(ierr); 767233f9f0SBarry Smith } else SETERRQ1(PETSC_ERR_PLIB,"Unknown exotic coarse space %d",ex->type); 77174b6946SBarry Smith ierr = PCMGSetInterpolation(pc,1,P);CHKERRQ(ierr); 78174b6946SBarry Smith ierr = MatDestroy(P);CHKERRQ(ierr); 797233f9f0SBarry Smith ierr = PCSetUp_MG(pc);CHKERRQ(ierr); 80174b6946SBarry Smith PetscFunctionReturn(0); 81174b6946SBarry Smith } 82174b6946SBarry Smith 83174b6946SBarry Smith #undef __FUNCT__ 847233f9f0SBarry Smith #define __FUNCT__ "PCDestroy_Exotic" 857233f9f0SBarry Smith PetscErrorCode PCDestroy_Exotic(PC pc) 86174b6946SBarry Smith { 87174b6946SBarry Smith PetscErrorCode ierr; 887233f9f0SBarry Smith PC_MG **mg = (PC_MG**)pc->data; 89bedee52eSLisandro Dalcin PC_Exotic *ctx = (PC_Exotic*) mg[0]->innerctx; 90174b6946SBarry Smith 91174b6946SBarry Smith PetscFunctionBegin; 927233f9f0SBarry Smith ierr = DADestroy(ctx->da);CHKERRQ(ierr); 937233f9f0SBarry Smith ierr = PetscFree(ctx);CHKERRQ(ierr); 947233f9f0SBarry Smith ierr = PCDestroy_MG(pc);CHKERRQ(ierr); 95174b6946SBarry Smith PetscFunctionReturn(0); 96174b6946SBarry Smith } 97174b6946SBarry Smith 98174b6946SBarry Smith #undef __FUNCT__ 997233f9f0SBarry Smith #define __FUNCT__ "PCSetUp_Exotic_Error" 1007233f9f0SBarry Smith PetscErrorCode PCSetUp_Exotic_Error(PC pc) 101174b6946SBarry Smith { 102174b6946SBarry Smith PetscFunctionBegin; 1037233f9f0SBarry Smith SETERRQ(PETSC_ERR_ARG_WRONGSTATE,"You are using the Exotic preconditioner but never called PCExoticSetDA()"); 104174b6946SBarry Smith PetscFunctionReturn(0); 105174b6946SBarry Smith } 106174b6946SBarry Smith 107174b6946SBarry Smith #undef __FUNCT__ 1087233f9f0SBarry Smith #define __FUNCT__ "PCExoticSetDA" 1097233f9f0SBarry Smith /*@ 1107233f9f0SBarry Smith PCExoticSetDA - Sets the DA that is to be used by the PCEXOTIC preconditioner 1117233f9f0SBarry Smith 1127233f9f0SBarry Smith Collective on PC 1137233f9f0SBarry Smith 1147233f9f0SBarry Smith Input Parameters: 1157233f9f0SBarry Smith + pc - the preconditioner context 1167233f9f0SBarry Smith - da - the da 1177233f9f0SBarry Smith 1187233f9f0SBarry Smith Level: intermediate 1197233f9f0SBarry Smith 1207233f9f0SBarry Smith 1217233f9f0SBarry Smith .seealso: PCEXOTIC, PCExoticType() 1227233f9f0SBarry Smith @*/ 1237233f9f0SBarry Smith PetscErrorCode PETSCKSP_DLLEXPORT PCExoticSetDA(PC pc,DA da) 124174b6946SBarry Smith { 1257233f9f0SBarry Smith PetscErrorCode ierr,(*f)(PC,DA); 126174b6946SBarry Smith 127174b6946SBarry Smith PetscFunctionBegin; 128174b6946SBarry Smith PetscValidHeaderSpecific(pc,PC_COOKIE,1); 129174b6946SBarry Smith PetscValidHeaderSpecific(da,DM_COOKIE,1); 1307233f9f0SBarry Smith ierr = PetscObjectQueryFunction((PetscObject)pc,"PCExoticSetDA_C",(void (**)(void))&f);CHKERRQ(ierr); 1317233f9f0SBarry Smith if (f) { 1327233f9f0SBarry Smith ierr = (*f)(pc,da);CHKERRQ(ierr); 1337233f9f0SBarry Smith } 1347233f9f0SBarry Smith PetscFunctionReturn(0); 1357233f9f0SBarry Smith } 136174b6946SBarry Smith 1377233f9f0SBarry Smith 1387233f9f0SBarry Smith #undef __FUNCT__ 1397233f9f0SBarry Smith #define __FUNCT__ "PCExoticSetDA_Exotic" 1407233f9f0SBarry Smith PetscErrorCode PETSCKSP_DLLEXPORT PCExoticSetDA_Exotic(PC pc,DA da) 1417233f9f0SBarry Smith { 1427233f9f0SBarry Smith PetscErrorCode ierr; 1437233f9f0SBarry Smith PC_MG **mg = (PC_MG**)pc->data; 144bedee52eSLisandro Dalcin PC_Exotic *ctx = (PC_Exotic*) mg[0]->innerctx; 1457233f9f0SBarry Smith 1467233f9f0SBarry Smith PetscFunctionBegin; 1477233f9f0SBarry Smith ctx->da = da; 1487233f9f0SBarry Smith pc->ops->setup = PCSetUp_Exotic; 149174b6946SBarry Smith ierr = PetscObjectReference((PetscObject)da);CHKERRQ(ierr); 150174b6946SBarry Smith PetscFunctionReturn(0); 151174b6946SBarry Smith } 152174b6946SBarry Smith 1537233f9f0SBarry Smith #undef __FUNCT__ 1547233f9f0SBarry Smith #define __FUNCT__ "PCView_Exotic" 1557233f9f0SBarry Smith PetscErrorCode PCView_Exotic(PC pc,PetscViewer viewer) 1567233f9f0SBarry Smith { 1577233f9f0SBarry Smith PC_MG **mg = (PC_MG**)pc->data; 1587233f9f0SBarry Smith PetscErrorCode ierr; 1597233f9f0SBarry Smith PetscTruth iascii; 160bedee52eSLisandro Dalcin PC_Exotic *ctx = (PC_Exotic*) mg[0]->innerctx; 1617233f9f0SBarry Smith 1627233f9f0SBarry Smith PetscFunctionBegin; 1637233f9f0SBarry Smith ierr = PetscTypeCompare((PetscObject)viewer,PETSC_VIEWER_ASCII,&iascii);CHKERRQ(ierr); 1647233f9f0SBarry Smith if (iascii) { 1657233f9f0SBarry Smith ierr = PetscViewerASCIIPrintf(viewer," Exotic type = %s\n",PCExoticTypes[ctx->type]);CHKERRQ(ierr); 1667233f9f0SBarry Smith } 1677233f9f0SBarry Smith ierr = PCView_MG(pc,viewer);CHKERRQ(ierr); 1687233f9f0SBarry Smith PetscFunctionReturn(0); 1697233f9f0SBarry Smith } 1707233f9f0SBarry Smith 1717233f9f0SBarry Smith #undef __FUNCT__ 1727233f9f0SBarry Smith #define __FUNCT__ "PCSetFromOptions_Exotic" 1737233f9f0SBarry Smith PetscErrorCode PCSetFromOptions_Exotic(PC pc) 1747233f9f0SBarry Smith { 1757233f9f0SBarry Smith PetscErrorCode ierr; 1767233f9f0SBarry Smith PetscTruth flg; 1777233f9f0SBarry Smith PC_MG **mg = (PC_MG**)pc->data; 1787233f9f0SBarry Smith PCExoticType mgctype; 179bedee52eSLisandro Dalcin PC_Exotic *ctx = (PC_Exotic*) mg[0]->innerctx; 1807233f9f0SBarry Smith 1817233f9f0SBarry Smith PetscFunctionBegin; 1827233f9f0SBarry Smith ierr = PetscOptionsHead("Exotic coarse space options");CHKERRQ(ierr); 1837233f9f0SBarry Smith ierr = PetscOptionsEnum("-pc_exotic_type","face or wirebasket","PCExoticSetType",PCExoticTypes,(PetscEnum)ctx->type,(PetscEnum*)&mgctype,&flg);CHKERRQ(ierr); 1847233f9f0SBarry Smith if (flg) { 1857233f9f0SBarry Smith ierr = PCExoticSetType(pc,mgctype);CHKERRQ(ierr); 1867233f9f0SBarry Smith } 1877233f9f0SBarry Smith ierr = PetscOptionsTail();CHKERRQ(ierr); 1887233f9f0SBarry Smith PetscFunctionReturn(0); 1897233f9f0SBarry Smith } 1907233f9f0SBarry Smith 191174b6946SBarry Smith 192174b6946SBarry Smith /*MC 1937233f9f0SBarry Smith PCEXOTIC - Two level overlapping Schwarz preconditioner with exotic (non-standard) coarse grid spaces 194174b6946SBarry Smith 1957233f9f0SBarry Smith This uses the PCMG infrastructure restricted to two levels and the face and wirebasket based coarse 1963b65e785SBarry Smith grid spaces. These coarse grid spaces originate in the work of Bramble, Pasciak and Schatz, "The Construction 1973b65e785SBarry Smith of Preconditioners for Elliptic Problems by Substructing IV", Mathematics of Computation, volume 53 pages 1--24, 1989. 1983b65e785SBarry Smith They were generalized slightly in "Domain Decomposition Method for Linear Elasticity", Ph. D. thesis, Barry Smith, 1993b65e785SBarry Smith New York University, 1990. They were then explored in great detail in Dryja, Smith, Widlund, "Schwarz Analysis 2003b65e785SBarry Smith of Iterative Substructuring Methods for Elliptic Problems in Three Dimensions, SIAM Journal on Numerical 2013b65e785SBarry Smith Analysis, volume 31. pages 1662-1694, 1994. These were developed in the context of iterative substructuring preconditioners. 2023b65e785SBarry Smith They were then ingeniously applied as coarse grid spaces for overlapping Schwarz methods by Dohrmann and Widlund. 2033b65e785SBarry Smith They refer to them as GDSW (generalized Dryja, Smith, Widlund preconditioners). See, for example, 2043b65e785SBarry Smith Clark R. Dohrmann, Axel Klawonn, and Olof B. Widlund. Extending theory for domain decomposition algorithms to irregular subdomains. In Ulrich Langer, Marco 2053b65e785SBarry Smith Discacciati, David Keyes, Olof Widlund, and Walter Zulehner, editors, Proceedings 2063b65e785SBarry Smith of the 17th International Conference on Domain Decomposition Methods in 2073b65e785SBarry Smith Science and Engineering, held in Strobl, Austria, July 3-7, 2006, number 60 in 2083b65e785SBarry Smith Springer-Verlag, Lecture Notes in Computational Science and Engineering, pages 255-261, 2007. 2093b65e785SBarry Smith Clark R. Dohrmann, Axel Klawonn, and Olof B. Widlund. A family of energy min- 2103b65e785SBarry Smith imizing coarse spaces for overlapping Schwarz preconditioners. In Ulrich Langer, 2113b65e785SBarry Smith Marco Discacciati, David Keyes, OlofWidlund, andWalter Zulehner, editors, Proceedings 2123b65e785SBarry Smith of the 17th International Conference on Domain Decomposition Methods 2133b65e785SBarry Smith in Science and Engineering, held in Strobl, Austria, July 3-7, 2006, number 60 in 2143b65e785SBarry Smith Springer-Verlag, Lecture Notes in Computational Science and Engineering, pages 247-254, 2007 2153b65e785SBarry Smith Clark R. Dohrmann, Axel Klawonn, and Olof B. Widlund. Domain decomposition 2163b65e785SBarry Smith for less regular subdomains: Overlapping Schwarz in two dimensions. SIAM J. 2173b65e785SBarry Smith Numer. Anal., 46(4):2153-2168, 2008. 2183b65e785SBarry Smith Clark R. Dohrmann and Olof B. Widlund. An overlapping Schwarz 2193b65e785SBarry Smith algorithm for almost incompressible elasticity. Technical Report 2203b65e785SBarry Smith TR2008-912, Department of Computer Science, Courant Institute 2213b65e785SBarry Smith of Mathematical Sciences, New York University, May 2008. URL: 2223b65e785SBarry Smith http://cs.nyu.edu/csweb/Research/TechReports/TR2008-912/TR2008-912.pdf 2237233f9f0SBarry Smith 2247233f9f0SBarry Smith Options Database: The usual PCMG options are supported, such as -mg_levels_pc_type <type> -mg_coarse_pc_type <type> 2257233f9f0SBarry Smith -pc_mg_type <type> 2267233f9f0SBarry Smith 2277233f9f0SBarry Smith .seealso: PCMG, PCExoticSetDA(), PCExoticType, PCExoticSetType() 228174b6946SBarry Smith 229174b6946SBarry Smith M*/ 230174b6946SBarry Smith 231174b6946SBarry Smith EXTERN_C_BEGIN 232174b6946SBarry Smith #undef __FUNCT__ 2337233f9f0SBarry Smith #define __FUNCT__ "PCCreate_Exotic" 2347233f9f0SBarry Smith PetscErrorCode PETSCKSP_DLLEXPORT PCCreate_Exotic(PC pc) 235174b6946SBarry Smith { 236174b6946SBarry Smith PetscErrorCode ierr; 2377233f9f0SBarry Smith PC_Exotic *ex; 2387233f9f0SBarry Smith PC_MG **mg; 239174b6946SBarry Smith 240174b6946SBarry Smith PetscFunctionBegin; 241174b6946SBarry Smith ierr = PCSetType(pc,PCMG);CHKERRQ(ierr); 242174b6946SBarry Smith ierr = PCMGSetLevels(pc,2,PETSC_NULL);CHKERRQ(ierr); 243174b6946SBarry Smith ierr = PCMGSetGalerkin(pc);CHKERRQ(ierr); 2447233f9f0SBarry Smith ierr = PetscNew(PC_Exotic,&ex);CHKERRQ(ierr); 2457233f9f0SBarry Smith ex->type = PC_EXOTIC_FACE; 246*a36ce94aSMatthew Knepley mg = (PC_MG**) pc->data; 2477233f9f0SBarry Smith mg[0]->innerctx = ex; 2487233f9f0SBarry Smith 2497233f9f0SBarry Smith 2507233f9f0SBarry Smith pc->ops->setfromoptions = PCSetFromOptions_Exotic; 2517233f9f0SBarry Smith pc->ops->view = PCView_Exotic; 2527233f9f0SBarry Smith pc->ops->destroy = PCDestroy_Exotic; 2537233f9f0SBarry Smith pc->ops->setup = PCSetUp_Exotic_Error; 2547233f9f0SBarry Smith ierr = PetscObjectComposeFunctionDynamic((PetscObject)pc,"PCExoticSetType_C","PCExoticSetType_Exotic",PCExoticSetType_Exotic);CHKERRQ(ierr); 2557233f9f0SBarry Smith ierr = PetscObjectComposeFunctionDynamic((PetscObject)pc,"PCExoticSetDA_C","PCExoticSetDA_Exotic",PCExoticSetDA_Exotic);CHKERRQ(ierr); 256174b6946SBarry Smith PetscFunctionReturn(0); 257174b6946SBarry Smith } 258174b6946SBarry Smith EXTERN_C_END 259