xref: /petsc/src/ksp/pc/impls/wb/wb.c (revision bedee52e9ed8e757d168f199e69a2cb4f6f93fb3)
1174b6946SBarry Smith #define PETSCKSP_DLL
2174b6946SBarry Smith 
3174b6946SBarry Smith 
4174b6946SBarry Smith #include "petscpc.h"   /*I "petscpc.h" I*/
5174b6946SBarry Smith #include "petscmg.h"   /*I "petscpc.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;
53*bedee52eSLisandro 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;
89*bedee52eSLisandro 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;
144*bedee52eSLisandro 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;
160*bedee52eSLisandro 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;
179*bedee52eSLisandro 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
1967233f9f0SBarry Smith    grid spaces. These coarse grid spaces originate in the work of Bramble, Pasiak (Sp) and Schatz, they
1977233f9f0SBarry Smith    were generalized slightly in "Domain Decomposition Method for Linear Elasticity", Ph. D. thesis, Barry Smith,
1987233f9f0SBarry Smith    New York University, 1990. These were developed in the context of iterative substructuring preconditioners.
1997233f9f0SBarry Smith    They were then ingeniously applied as coarse grid spaces for overlapping Schwarz methods by XXXX and Widlund.
2007233f9f0SBarry Smith    They refer to them as GDSW (generalized Dryja, Smith, Widlund preconditioners).
2017233f9f0SBarry Smith 
2027233f9f0SBarry Smith    Options Database: The usual PCMG options are supported, such as -mg_levels_pc_type <type> -mg_coarse_pc_type <type>
2037233f9f0SBarry Smith       -pc_mg_type <type>
2047233f9f0SBarry Smith 
2057233f9f0SBarry Smith .seealso:  PCMG, PCExoticSetDA(), PCExoticType, PCExoticSetType()
206174b6946SBarry Smith 
207174b6946SBarry Smith M*/
208174b6946SBarry Smith 
209174b6946SBarry Smith EXTERN_C_BEGIN
210174b6946SBarry Smith #undef __FUNCT__
2117233f9f0SBarry Smith #define __FUNCT__ "PCCreate_Exotic"
2127233f9f0SBarry Smith PetscErrorCode PETSCKSP_DLLEXPORT PCCreate_Exotic(PC pc)
213174b6946SBarry Smith {
214174b6946SBarry Smith   PetscErrorCode ierr;
2157233f9f0SBarry Smith   PC_Exotic      *ex;
2167233f9f0SBarry Smith   PC_MG          **mg;
217174b6946SBarry Smith 
218174b6946SBarry Smith   PetscFunctionBegin;
219174b6946SBarry Smith   ierr = PCSetType(pc,PCMG);CHKERRQ(ierr);
220174b6946SBarry Smith   ierr = PCMGSetLevels(pc,2,PETSC_NULL);CHKERRQ(ierr);
221174b6946SBarry Smith   ierr = PCMGSetGalerkin(pc);CHKERRQ(ierr);
2227233f9f0SBarry Smith   ierr = PetscNew(PC_Exotic,&ex);CHKERRQ(ierr);
2237233f9f0SBarry Smith   ex->type = PC_EXOTIC_FACE;
2247233f9f0SBarry Smith   mg = (void*)(PC_MG**)pc->data;
2257233f9f0SBarry Smith   mg[0]->innerctx = ex;
2267233f9f0SBarry Smith 
2277233f9f0SBarry Smith 
2287233f9f0SBarry Smith   pc->ops->setfromoptions = PCSetFromOptions_Exotic;
2297233f9f0SBarry Smith   pc->ops->view           = PCView_Exotic;
2307233f9f0SBarry Smith   pc->ops->destroy        = PCDestroy_Exotic;
2317233f9f0SBarry Smith   pc->ops->setup          = PCSetUp_Exotic_Error;
2327233f9f0SBarry Smith   ierr = PetscObjectComposeFunctionDynamic((PetscObject)pc,"PCExoticSetType_C","PCExoticSetType_Exotic",PCExoticSetType_Exotic);CHKERRQ(ierr);
2337233f9f0SBarry Smith   ierr = PetscObjectComposeFunctionDynamic((PetscObject)pc,"PCExoticSetDA_C","PCExoticSetDA_Exotic",PCExoticSetDA_Exotic);CHKERRQ(ierr);
234174b6946SBarry Smith   PetscFunctionReturn(0);
235174b6946SBarry Smith }
236174b6946SBarry Smith EXTERN_C_END
237