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 11*96bdf778SBarry Smith extern PetscErrorCode DAGetWireBasketInterpolation(DA,Mat,MatReuse,Mat*); 12*96bdf778SBarry Smith extern PetscErrorCode DAGetFaceInterpolation(DA,Mat,MatReuse,Mat*); 13174b6946SBarry Smith 147233f9f0SBarry Smith typedef struct { 157233f9f0SBarry Smith DA da; 167233f9f0SBarry Smith PCExoticType type; 17*96bdf778SBarry 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 317233f9f0SBarry Smith Level: intermediate 327233f9f0SBarry Smith 337233f9f0SBarry Smith 347233f9f0SBarry Smith .seealso: PCEXOTIC, PCExoticType() 357233f9f0SBarry Smith @*/ 367233f9f0SBarry Smith PetscErrorCode PETSCKSP_DLLEXPORT PCExoticSetType(PC pc,PCExoticType type) 377233f9f0SBarry Smith { 387233f9f0SBarry Smith PetscErrorCode ierr,(*f)(PC,PCExoticType); 397233f9f0SBarry Smith 407233f9f0SBarry Smith PetscFunctionBegin; 417233f9f0SBarry Smith PetscValidHeaderSpecific(pc,PC_COOKIE,1); 427233f9f0SBarry Smith ierr = PetscObjectQueryFunction((PetscObject)pc,"PCExoticSetType_C",(void (**)(void))&f);CHKERRQ(ierr); 437233f9f0SBarry Smith if (f) { 447233f9f0SBarry Smith ierr = (*f)(pc,type);CHKERRQ(ierr); 457233f9f0SBarry Smith } 467233f9f0SBarry Smith PetscFunctionReturn(0); 477233f9f0SBarry Smith } 487233f9f0SBarry Smith 497233f9f0SBarry Smith #undef __FUNCT__ 507233f9f0SBarry Smith #define __FUNCT__ "PCExoticSetType_Exotic" 517233f9f0SBarry Smith PetscErrorCode PETSCKSP_DLLEXPORT PCExoticSetType_Exotic(PC pc,PCExoticType type) 527233f9f0SBarry Smith { 537233f9f0SBarry Smith PC_MG **mg = (PC_MG**)pc->data; 54bedee52eSLisandro Dalcin PC_Exotic *ctx = (PC_Exotic*) mg[0]->innerctx; 557233f9f0SBarry Smith 567233f9f0SBarry Smith PetscFunctionBegin; 577233f9f0SBarry Smith ctx->type = type; 587233f9f0SBarry Smith PetscFunctionReturn(0); 597233f9f0SBarry Smith } 607233f9f0SBarry Smith 617233f9f0SBarry Smith #undef __FUNCT__ 627233f9f0SBarry Smith #define __FUNCT__ "PCSetUp_Exotic" 637233f9f0SBarry Smith PetscErrorCode PCSetUp_Exotic(PC pc) 64174b6946SBarry Smith { 65174b6946SBarry Smith PetscErrorCode ierr; 66*96bdf778SBarry Smith Mat A; 677233f9f0SBarry Smith PC_MG **mg = (PC_MG**)pc->data; 687233f9f0SBarry Smith PC_Exotic *ex = (PC_Exotic*) mg[0]->innerctx; 697233f9f0SBarry Smith DA da = ex->da; 70*96bdf778SBarry Smith MatReuse reuse = (ex->P) ? MAT_REUSE_MATRIX : MAT_INITIAL_MATRIX; 71174b6946SBarry Smith 72174b6946SBarry Smith PetscFunctionBegin; 73174b6946SBarry Smith ierr = PCGetOperators(pc,PETSC_NULL,&A,PETSC_NULL);CHKERRQ(ierr); 747233f9f0SBarry Smith if (ex->type == PC_EXOTIC_FACE) { 75*96bdf778SBarry Smith ierr = DAGetFaceInterpolation(da,A,reuse,&ex->P);CHKERRQ(ierr); 767233f9f0SBarry Smith } else if (ex->type == PC_EXOTIC_WIREBASKET) { 77*96bdf778SBarry Smith ierr = DAGetWireBasketInterpolation(da,A,reuse,&ex->P);CHKERRQ(ierr); 787233f9f0SBarry Smith } else SETERRQ1(PETSC_ERR_PLIB,"Unknown exotic coarse space %d",ex->type); 79*96bdf778SBarry Smith ierr = PCMGSetInterpolation(pc,1,ex->P);CHKERRQ(ierr); 807233f9f0SBarry Smith ierr = PCSetUp_MG(pc);CHKERRQ(ierr); 81174b6946SBarry Smith PetscFunctionReturn(0); 82174b6946SBarry Smith } 83174b6946SBarry Smith 84174b6946SBarry Smith #undef __FUNCT__ 857233f9f0SBarry Smith #define __FUNCT__ "PCDestroy_Exotic" 867233f9f0SBarry Smith PetscErrorCode PCDestroy_Exotic(PC pc) 87174b6946SBarry Smith { 88174b6946SBarry Smith PetscErrorCode ierr; 897233f9f0SBarry Smith PC_MG **mg = (PC_MG**)pc->data; 90bedee52eSLisandro Dalcin PC_Exotic *ctx = (PC_Exotic*) mg[0]->innerctx; 91174b6946SBarry Smith 92174b6946SBarry Smith PetscFunctionBegin; 93*96bdf778SBarry Smith if (ctx->da) {ierr = DADestroy(ctx->da);CHKERRQ(ierr);} 94*96bdf778SBarry Smith if (ctx->P) {ierr = MatDestroy(ctx->P);CHKERRQ(ierr);} 957233f9f0SBarry Smith ierr = PetscFree(ctx);CHKERRQ(ierr); 967233f9f0SBarry Smith ierr = PCDestroy_MG(pc);CHKERRQ(ierr); 97174b6946SBarry Smith PetscFunctionReturn(0); 98174b6946SBarry Smith } 99174b6946SBarry Smith 100174b6946SBarry Smith #undef __FUNCT__ 1017233f9f0SBarry Smith #define __FUNCT__ "PCSetUp_Exotic_Error" 1027233f9f0SBarry Smith PetscErrorCode PCSetUp_Exotic_Error(PC pc) 103174b6946SBarry Smith { 104174b6946SBarry Smith PetscFunctionBegin; 1057233f9f0SBarry Smith SETERRQ(PETSC_ERR_ARG_WRONGSTATE,"You are using the Exotic preconditioner but never called PCExoticSetDA()"); 106174b6946SBarry Smith PetscFunctionReturn(0); 107174b6946SBarry Smith } 108174b6946SBarry Smith 109174b6946SBarry Smith #undef __FUNCT__ 1107233f9f0SBarry Smith #define __FUNCT__ "PCExoticSetDA" 1117233f9f0SBarry Smith /*@ 1127233f9f0SBarry Smith PCExoticSetDA - Sets the DA that is to be used by the PCEXOTIC preconditioner 1137233f9f0SBarry Smith 1147233f9f0SBarry Smith Collective on PC 1157233f9f0SBarry Smith 1167233f9f0SBarry Smith Input Parameters: 1177233f9f0SBarry Smith + pc - the preconditioner context 1187233f9f0SBarry Smith - da - the da 1197233f9f0SBarry Smith 1207233f9f0SBarry Smith Level: intermediate 1217233f9f0SBarry Smith 1227233f9f0SBarry Smith 1237233f9f0SBarry Smith .seealso: PCEXOTIC, PCExoticType() 1247233f9f0SBarry Smith @*/ 1257233f9f0SBarry Smith PetscErrorCode PETSCKSP_DLLEXPORT PCExoticSetDA(PC pc,DA da) 126174b6946SBarry Smith { 1277233f9f0SBarry Smith PetscErrorCode ierr,(*f)(PC,DA); 128174b6946SBarry Smith 129174b6946SBarry Smith PetscFunctionBegin; 130174b6946SBarry Smith PetscValidHeaderSpecific(pc,PC_COOKIE,1); 131174b6946SBarry Smith PetscValidHeaderSpecific(da,DM_COOKIE,1); 1327233f9f0SBarry Smith ierr = PetscObjectQueryFunction((PetscObject)pc,"PCExoticSetDA_C",(void (**)(void))&f);CHKERRQ(ierr); 1337233f9f0SBarry Smith if (f) { 1347233f9f0SBarry Smith ierr = (*f)(pc,da);CHKERRQ(ierr); 1357233f9f0SBarry Smith } 1367233f9f0SBarry Smith PetscFunctionReturn(0); 1377233f9f0SBarry Smith } 138174b6946SBarry Smith 1397233f9f0SBarry Smith 1407233f9f0SBarry Smith #undef __FUNCT__ 1417233f9f0SBarry Smith #define __FUNCT__ "PCExoticSetDA_Exotic" 1427233f9f0SBarry Smith PetscErrorCode PETSCKSP_DLLEXPORT PCExoticSetDA_Exotic(PC pc,DA da) 1437233f9f0SBarry Smith { 1447233f9f0SBarry Smith PetscErrorCode ierr; 1457233f9f0SBarry Smith PC_MG **mg = (PC_MG**)pc->data; 146bedee52eSLisandro Dalcin PC_Exotic *ctx = (PC_Exotic*) mg[0]->innerctx; 1477233f9f0SBarry Smith 1487233f9f0SBarry Smith PetscFunctionBegin; 1497233f9f0SBarry Smith ctx->da = da; 1507233f9f0SBarry Smith pc->ops->setup = PCSetUp_Exotic; 151174b6946SBarry Smith ierr = PetscObjectReference((PetscObject)da);CHKERRQ(ierr); 152174b6946SBarry Smith PetscFunctionReturn(0); 153174b6946SBarry Smith } 154174b6946SBarry Smith 1557233f9f0SBarry Smith #undef __FUNCT__ 1567233f9f0SBarry Smith #define __FUNCT__ "PCView_Exotic" 1577233f9f0SBarry Smith PetscErrorCode PCView_Exotic(PC pc,PetscViewer viewer) 1587233f9f0SBarry Smith { 1597233f9f0SBarry Smith PC_MG **mg = (PC_MG**)pc->data; 1607233f9f0SBarry Smith PetscErrorCode ierr; 1617233f9f0SBarry Smith PetscTruth iascii; 162bedee52eSLisandro Dalcin PC_Exotic *ctx = (PC_Exotic*) mg[0]->innerctx; 1637233f9f0SBarry Smith 1647233f9f0SBarry Smith PetscFunctionBegin; 1657233f9f0SBarry Smith ierr = PetscTypeCompare((PetscObject)viewer,PETSC_VIEWER_ASCII,&iascii);CHKERRQ(ierr); 1667233f9f0SBarry Smith if (iascii) { 1677233f9f0SBarry Smith ierr = PetscViewerASCIIPrintf(viewer," Exotic type = %s\n",PCExoticTypes[ctx->type]);CHKERRQ(ierr); 1687233f9f0SBarry Smith } 1697233f9f0SBarry Smith ierr = PCView_MG(pc,viewer);CHKERRQ(ierr); 1707233f9f0SBarry Smith PetscFunctionReturn(0); 1717233f9f0SBarry Smith } 1727233f9f0SBarry Smith 1737233f9f0SBarry Smith #undef __FUNCT__ 1747233f9f0SBarry Smith #define __FUNCT__ "PCSetFromOptions_Exotic" 1757233f9f0SBarry Smith PetscErrorCode PCSetFromOptions_Exotic(PC pc) 1767233f9f0SBarry Smith { 1777233f9f0SBarry Smith PetscErrorCode ierr; 1787233f9f0SBarry Smith PetscTruth flg; 1797233f9f0SBarry Smith PC_MG **mg = (PC_MG**)pc->data; 1807233f9f0SBarry Smith PCExoticType mgctype; 181bedee52eSLisandro Dalcin PC_Exotic *ctx = (PC_Exotic*) mg[0]->innerctx; 1827233f9f0SBarry Smith 1837233f9f0SBarry Smith PetscFunctionBegin; 1847233f9f0SBarry Smith ierr = PetscOptionsHead("Exotic coarse space options");CHKERRQ(ierr); 1857233f9f0SBarry Smith ierr = PetscOptionsEnum("-pc_exotic_type","face or wirebasket","PCExoticSetType",PCExoticTypes,(PetscEnum)ctx->type,(PetscEnum*)&mgctype,&flg);CHKERRQ(ierr); 1867233f9f0SBarry Smith if (flg) { 1877233f9f0SBarry Smith ierr = PCExoticSetType(pc,mgctype);CHKERRQ(ierr); 1887233f9f0SBarry Smith } 1897233f9f0SBarry Smith ierr = PetscOptionsTail();CHKERRQ(ierr); 1907233f9f0SBarry Smith PetscFunctionReturn(0); 1917233f9f0SBarry Smith } 1927233f9f0SBarry Smith 193174b6946SBarry Smith 194174b6946SBarry Smith /*MC 1957233f9f0SBarry Smith PCEXOTIC - Two level overlapping Schwarz preconditioner with exotic (non-standard) coarse grid spaces 196174b6946SBarry Smith 1977233f9f0SBarry Smith This uses the PCMG infrastructure restricted to two levels and the face and wirebasket based coarse 1983b65e785SBarry Smith grid spaces. These coarse grid spaces originate in the work of Bramble, Pasciak and Schatz, "The Construction 1993b65e785SBarry Smith of Preconditioners for Elliptic Problems by Substructing IV", Mathematics of Computation, volume 53 pages 1--24, 1989. 2003b65e785SBarry Smith They were generalized slightly in "Domain Decomposition Method for Linear Elasticity", Ph. D. thesis, Barry Smith, 2013b65e785SBarry Smith New York University, 1990. They were then explored in great detail in Dryja, Smith, Widlund, "Schwarz Analysis 2023b65e785SBarry Smith of Iterative Substructuring Methods for Elliptic Problems in Three Dimensions, SIAM Journal on Numerical 2033b65e785SBarry Smith Analysis, volume 31. pages 1662-1694, 1994. These were developed in the context of iterative substructuring preconditioners. 2043b65e785SBarry Smith They were then ingeniously applied as coarse grid spaces for overlapping Schwarz methods by Dohrmann and Widlund. 2053b65e785SBarry Smith They refer to them as GDSW (generalized Dryja, Smith, Widlund preconditioners). See, for example, 2063b65e785SBarry Smith Clark R. Dohrmann, Axel Klawonn, and Olof B. Widlund. Extending theory for domain decomposition algorithms to irregular subdomains. In Ulrich Langer, Marco 2073b65e785SBarry Smith Discacciati, David Keyes, Olof Widlund, and Walter Zulehner, editors, Proceedings 2083b65e785SBarry Smith of the 17th International Conference on Domain Decomposition Methods in 2093b65e785SBarry Smith Science and Engineering, held in Strobl, Austria, July 3-7, 2006, number 60 in 2103b65e785SBarry Smith Springer-Verlag, Lecture Notes in Computational Science and Engineering, pages 255-261, 2007. 2113b65e785SBarry Smith Clark R. Dohrmann, Axel Klawonn, and Olof B. Widlund. A family of energy min- 2123b65e785SBarry Smith imizing coarse spaces for overlapping Schwarz preconditioners. In Ulrich Langer, 2133b65e785SBarry Smith Marco Discacciati, David Keyes, OlofWidlund, andWalter Zulehner, editors, Proceedings 2143b65e785SBarry Smith of the 17th International Conference on Domain Decomposition Methods 2153b65e785SBarry Smith in Science and Engineering, held in Strobl, Austria, July 3-7, 2006, number 60 in 2163b65e785SBarry Smith Springer-Verlag, Lecture Notes in Computational Science and Engineering, pages 247-254, 2007 2173b65e785SBarry Smith Clark R. Dohrmann, Axel Klawonn, and Olof B. Widlund. Domain decomposition 2183b65e785SBarry Smith for less regular subdomains: Overlapping Schwarz in two dimensions. SIAM J. 2193b65e785SBarry Smith Numer. Anal., 46(4):2153-2168, 2008. 2203b65e785SBarry Smith Clark R. Dohrmann and Olof B. Widlund. An overlapping Schwarz 2213b65e785SBarry Smith algorithm for almost incompressible elasticity. Technical Report 2223b65e785SBarry Smith TR2008-912, Department of Computer Science, Courant Institute 2233b65e785SBarry Smith of Mathematical Sciences, New York University, May 2008. URL: 2243b65e785SBarry Smith http://cs.nyu.edu/csweb/Research/TechReports/TR2008-912/TR2008-912.pdf 2257233f9f0SBarry Smith 2267233f9f0SBarry Smith Options Database: The usual PCMG options are supported, such as -mg_levels_pc_type <type> -mg_coarse_pc_type <type> 2277233f9f0SBarry Smith -pc_mg_type <type> 2287233f9f0SBarry Smith 2297233f9f0SBarry Smith .seealso: PCMG, PCExoticSetDA(), PCExoticType, PCExoticSetType() 230174b6946SBarry Smith 231174b6946SBarry Smith M*/ 232174b6946SBarry Smith 233174b6946SBarry Smith EXTERN_C_BEGIN 234174b6946SBarry Smith #undef __FUNCT__ 2357233f9f0SBarry Smith #define __FUNCT__ "PCCreate_Exotic" 2367233f9f0SBarry Smith PetscErrorCode PETSCKSP_DLLEXPORT PCCreate_Exotic(PC pc) 237174b6946SBarry Smith { 238174b6946SBarry Smith PetscErrorCode ierr; 2397233f9f0SBarry Smith PC_Exotic *ex; 2407233f9f0SBarry Smith PC_MG **mg; 241174b6946SBarry Smith 242174b6946SBarry Smith PetscFunctionBegin; 243174b6946SBarry Smith ierr = PCSetType(pc,PCMG);CHKERRQ(ierr); 244174b6946SBarry Smith ierr = PCMGSetLevels(pc,2,PETSC_NULL);CHKERRQ(ierr); 245174b6946SBarry Smith ierr = PCMGSetGalerkin(pc);CHKERRQ(ierr); 246*96bdf778SBarry Smith ierr = PetscNew(PC_Exotic,&ex);CHKERRQ(ierr);\ 2477233f9f0SBarry Smith ex->type = PC_EXOTIC_FACE; 248a36ce94aSMatthew Knepley mg = (PC_MG**) pc->data; 2497233f9f0SBarry Smith mg[0]->innerctx = ex; 2507233f9f0SBarry Smith 2517233f9f0SBarry Smith 2527233f9f0SBarry Smith pc->ops->setfromoptions = PCSetFromOptions_Exotic; 2537233f9f0SBarry Smith pc->ops->view = PCView_Exotic; 2547233f9f0SBarry Smith pc->ops->destroy = PCDestroy_Exotic; 2557233f9f0SBarry Smith pc->ops->setup = PCSetUp_Exotic_Error; 2567233f9f0SBarry Smith ierr = PetscObjectComposeFunctionDynamic((PetscObject)pc,"PCExoticSetType_C","PCExoticSetType_Exotic",PCExoticSetType_Exotic);CHKERRQ(ierr); 2577233f9f0SBarry Smith ierr = PetscObjectComposeFunctionDynamic((PetscObject)pc,"PCExoticSetDA_C","PCExoticSetDA_Exotic",PCExoticSetDA_Exotic);CHKERRQ(ierr); 258174b6946SBarry Smith PetscFunctionReturn(0); 259174b6946SBarry Smith } 260174b6946SBarry Smith EXTERN_C_END 261