xref: /petsc/src/ksp/pc/impls/wb/wb.c (revision 3639cd1f213126b2c4fa06aeb7c69920728414f5)
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*/
7174b6946SBarry Smith 
8174b6946SBarry Smith extern PetscErrorCode DAGetWireBasketInterpolation(DA,Mat,Mat*);
9*3639cd1fSBarry Smith extern PetscErrorCode DAGetFaceInterpolation(DA,Mat,Mat*);
10174b6946SBarry Smith 
11174b6946SBarry Smith #undef __FUNCT__
12174b6946SBarry Smith #define __FUNCT__ "PCSetUp_WB"
13174b6946SBarry Smith PetscErrorCode PCSetUp_WB(PC pc,void *ida)
14174b6946SBarry Smith {
15174b6946SBarry Smith   PetscErrorCode ierr;
16174b6946SBarry Smith   DA             da = (DA)ida;
17174b6946SBarry Smith   Mat            A,P;
18174b6946SBarry Smith 
19174b6946SBarry Smith   PetscFunctionBegin;
20174b6946SBarry Smith   ierr = PCGetOperators(pc,PETSC_NULL,&A,PETSC_NULL);CHKERRQ(ierr);
21*3639cd1fSBarry Smith   ierr = DAGetFaceInterpolation(da,A,&P);CHKERRQ(ierr);
22174b6946SBarry Smith   ierr = PCMGSetInterpolation(pc,1,P);CHKERRQ(ierr);
23174b6946SBarry Smith   ierr = MatDestroy(P);CHKERRQ(ierr);
24174b6946SBarry Smith   PetscFunctionReturn(0);
25174b6946SBarry Smith }
26174b6946SBarry Smith 
27174b6946SBarry Smith #undef __FUNCT__
28174b6946SBarry Smith #define __FUNCT__ "PCDestroy_WB"
29174b6946SBarry Smith PetscErrorCode PCDestroy_WB(PC pc,void *ida)
30174b6946SBarry Smith {
31174b6946SBarry Smith   PetscErrorCode ierr;
32174b6946SBarry Smith   DA             da = (DA)ida;
33174b6946SBarry Smith 
34174b6946SBarry Smith   PetscFunctionBegin;
35174b6946SBarry Smith   ierr = DADestroy(da);CHKERRQ(ierr);
36174b6946SBarry Smith   PetscFunctionReturn(0);
37174b6946SBarry Smith }
38174b6946SBarry Smith 
39174b6946SBarry Smith #undef __FUNCT__
40174b6946SBarry Smith #define __FUNCT__ "PCSetUp_WB_Error"
41174b6946SBarry Smith PetscErrorCode PCSetUp_WB_Error(PC pc,void *ida)
42174b6946SBarry Smith {
43174b6946SBarry Smith   PetscFunctionBegin;
44174b6946SBarry Smith   SETERRQ(PETSC_ERR_ARG_WRONGSTATE,"You are using the WB preconditioner but never called PDWBSetDA()");
45174b6946SBarry Smith   PetscFunctionReturn(0);
46174b6946SBarry Smith }
47174b6946SBarry Smith 
48174b6946SBarry Smith #undef __FUNCT__
49174b6946SBarry Smith #define __FUNCT__ "PCWBSetDA"
50174b6946SBarry Smith PetscErrorCode PETSCKSP_DLLEXPORT PCWBSetDA(PC pc,DA da)
51174b6946SBarry Smith {
52174b6946SBarry Smith   PetscErrorCode ierr;
53174b6946SBarry Smith 
54174b6946SBarry Smith   PetscFunctionBegin;
55174b6946SBarry Smith   PetscValidHeaderSpecific(pc,PC_COOKIE,1);
56174b6946SBarry Smith   PetscValidHeaderSpecific(da,DM_COOKIE,1);
57174b6946SBarry Smith 
58174b6946SBarry Smith   ierr = PCMGSetSetup(pc,PCSetUp_WB,PCDestroy_WB,da);CHKERRQ(ierr);
59174b6946SBarry Smith   ierr = PetscObjectReference((PetscObject)da);CHKERRQ(ierr);
60174b6946SBarry Smith   PetscFunctionReturn(0);
61174b6946SBarry Smith }
62174b6946SBarry Smith 
63174b6946SBarry Smith 
64174b6946SBarry Smith /*MC
65174b6946SBarry Smith      PCWB - Wirebasket based coarse problem two level multigrid preconditioner
66174b6946SBarry Smith 
67174b6946SBarry Smith .seealso:  PCMG, PCWBSetDA()
68174b6946SBarry Smith 
69174b6946SBarry Smith M*/
70174b6946SBarry Smith 
71174b6946SBarry Smith EXTERN_C_BEGIN
72174b6946SBarry Smith #undef __FUNCT__
73174b6946SBarry Smith #define __FUNCT__ "PCCreate_WB"
74174b6946SBarry Smith PetscErrorCode PETSCKSP_DLLEXPORT PCCreate_WB(PC pc)
75174b6946SBarry Smith {
76174b6946SBarry Smith   PetscErrorCode ierr;
77174b6946SBarry Smith 
78174b6946SBarry Smith   PetscFunctionBegin;
79174b6946SBarry Smith   ierr = PCSetType(pc,PCMG);CHKERRQ(ierr);
80174b6946SBarry Smith   ierr = PCMGSetLevels(pc,2,PETSC_NULL);CHKERRQ(ierr);
81174b6946SBarry Smith   ierr = PCMGSetGalerkin(pc);CHKERRQ(ierr);
82174b6946SBarry Smith   ierr = PCMGSetSetup(pc,PCSetUp_WB_Error,0,0);CHKERRQ(ierr);
83174b6946SBarry Smith   PetscFunctionReturn(0);
84174b6946SBarry Smith }
85174b6946SBarry Smith EXTERN_C_END
86