xref: /petsc/src/ksp/pc/impls/shell/shellpc.c (revision b00a91154f763f12aa55f3d53a3f2776f15f49e3)
14d0a8057SBarry Smith 
24b9ad928SBarry Smith /*
34b9ad928SBarry Smith    This provides a simple shell for Fortran (and C programmers) to
44b9ad928SBarry Smith   create their own preconditioner without writing much interface code.
54b9ad928SBarry Smith */
64b9ad928SBarry Smith 
7b45d2f2cSJed Brown #include <petsc-private/pcimpl.h>        /*I "petscpc.h" I*/
8b45d2f2cSJed Brown #include <petsc-private/vecimpl.h>
94b9ad928SBarry Smith 
104b9ad928SBarry Smith typedef struct {
11be29d3c6SBarry Smith   void *ctx;                     /* user provided contexts for preconditioner */
122fa5cd67SKarl Rupp 
136891c3e4SJed Brown   PetscErrorCode (*destroy)(PC);
146891c3e4SJed Brown   PetscErrorCode (*setup)(PC);
156891c3e4SJed Brown   PetscErrorCode (*apply)(PC,Vec,Vec);
166891c3e4SJed Brown   PetscErrorCode (*applyBA)(PC,PCSide,Vec,Vec,Vec);
176891c3e4SJed Brown   PetscErrorCode (*presolve)(PC,KSP,Vec,Vec);
186891c3e4SJed Brown   PetscErrorCode (*postsolve)(PC,KSP,Vec,Vec);
196891c3e4SJed Brown   PetscErrorCode (*view)(PC,PetscViewer);
206891c3e4SJed Brown   PetscErrorCode (*applytranspose)(PC,Vec,Vec);
21ace3abfcSBarry Smith   PetscErrorCode (*applyrich)(PC,Vec,Vec,Vec,PetscReal,PetscReal,PetscReal,PetscInt,PetscBool,PetscInt*,PCRichardsonConvergedReason*);
222fa5cd67SKarl Rupp 
234b9ad928SBarry Smith   char *name;
244b9ad928SBarry Smith } PC_Shell;
254b9ad928SBarry Smith 
264b9ad928SBarry Smith #undef __FUNCT__
27be29d3c6SBarry Smith #define __FUNCT__ "PCShellGetContext"
28b29801fcSSatish Balay /*@C
29be29d3c6SBarry Smith     PCShellGetContext - Returns the user-provided context associated with a shell PC
30be29d3c6SBarry Smith 
31be29d3c6SBarry Smith     Not Collective
32be29d3c6SBarry Smith 
33be29d3c6SBarry Smith     Input Parameter:
34c5ae4b9aSBarry Smith .   pc - should have been created with PCSetType(pc,shell)
35be29d3c6SBarry Smith 
36be29d3c6SBarry Smith     Output Parameter:
37be29d3c6SBarry Smith .   ctx - the user provided context
38be29d3c6SBarry Smith 
39be29d3c6SBarry Smith     Level: advanced
40be29d3c6SBarry Smith 
41be29d3c6SBarry Smith     Notes:
42be29d3c6SBarry Smith     This routine is intended for use within various shell routines
43be29d3c6SBarry Smith 
44be29d3c6SBarry Smith .keywords: PC, shell, get, context
45be29d3c6SBarry Smith 
46c5ae4b9aSBarry Smith .seealso: PCShellSetContext()
47be29d3c6SBarry Smith @*/
487087cfbeSBarry Smith PetscErrorCode  PCShellGetContext(PC pc,void **ctx)
49be29d3c6SBarry Smith {
50be29d3c6SBarry Smith   PetscErrorCode ierr;
51ace3abfcSBarry Smith   PetscBool      flg;
52be29d3c6SBarry Smith 
53be29d3c6SBarry Smith   PetscFunctionBegin;
540700a824SBarry Smith   PetscValidHeaderSpecific(pc,PC_CLASSID,1);
55be29d3c6SBarry Smith   PetscValidPointer(ctx,2);
56251f4c67SDmitry Karpeev   ierr = PetscObjectTypeCompare((PetscObject)pc,PCSHELL,&flg);CHKERRQ(ierr);
57be29d3c6SBarry Smith   if (!flg) *ctx = 0;
58be29d3c6SBarry Smith   else      *ctx = ((PC_Shell*)(pc->data))->ctx;
59be29d3c6SBarry Smith   PetscFunctionReturn(0);
60be29d3c6SBarry Smith }
61be29d3c6SBarry Smith 
62be29d3c6SBarry Smith #undef __FUNCT__
63be29d3c6SBarry Smith #define __FUNCT__ "PCShellSetContext"
649dd1005fSJed Brown /*@
65be29d3c6SBarry Smith     PCShellSetContext - sets the context for a shell PC
66be29d3c6SBarry Smith 
673f9fe445SBarry Smith    Logically Collective on PC
68be29d3c6SBarry Smith 
69be29d3c6SBarry Smith     Input Parameters:
70be29d3c6SBarry Smith +   pc - the shell PC
71be29d3c6SBarry Smith -   ctx - the context
72be29d3c6SBarry Smith 
73be29d3c6SBarry Smith    Level: advanced
74be29d3c6SBarry Smith 
75be29d3c6SBarry Smith    Fortran Notes: The context can only be an integer or a PetscObject
76be29d3c6SBarry Smith       unfortunately it cannot be a Fortran array or derived type.
77be29d3c6SBarry Smith 
786895c445SBarry Smith 
79c5ae4b9aSBarry Smith .seealso: PCShellGetContext(), PCSHELL
80be29d3c6SBarry Smith @*/
817087cfbeSBarry Smith PetscErrorCode  PCShellSetContext(PC pc,void *ctx)
82be29d3c6SBarry Smith {
83c5ae4b9aSBarry Smith   PC_Shell       *shell = (PC_Shell*)pc->data;
84be29d3c6SBarry Smith   PetscErrorCode ierr;
85ace3abfcSBarry Smith   PetscBool      flg;
86be29d3c6SBarry Smith 
87be29d3c6SBarry Smith   PetscFunctionBegin;
880700a824SBarry Smith   PetscValidHeaderSpecific(pc,PC_CLASSID,1);
89251f4c67SDmitry Karpeev   ierr = PetscObjectTypeCompare((PetscObject)pc,PCSHELL,&flg);CHKERRQ(ierr);
902fa5cd67SKarl Rupp   if (flg) shell->ctx = ctx;
91be29d3c6SBarry Smith   PetscFunctionReturn(0);
92be29d3c6SBarry Smith }
93be29d3c6SBarry Smith 
94be29d3c6SBarry Smith #undef __FUNCT__
9518be62a5SSatish Balay #define __FUNCT__ "PCSetUp_Shell"
966849ba73SBarry Smith static PetscErrorCode PCSetUp_Shell(PC pc)
974b9ad928SBarry Smith {
98c5ae4b9aSBarry Smith   PC_Shell       *shell = (PC_Shell*)pc->data;
99dfbe8321SBarry Smith   PetscErrorCode ierr;
1004b9ad928SBarry Smith 
1014b9ad928SBarry Smith   PetscFunctionBegin;
102ce94432eSBarry Smith   if (!shell->setup) SETERRQ(PetscObjectComm((PetscObject)pc),PETSC_ERR_USER,"No setup() routine provided to Shell PC");
103eb6b5d47SBarry Smith   PetscStackCall("PCSHELL user function setup()",ierr = (*shell->setup)(pc);CHKERRQ(ierr));
1044b9ad928SBarry Smith   PetscFunctionReturn(0);
1054b9ad928SBarry Smith }
1064b9ad928SBarry Smith 
1074b9ad928SBarry Smith #undef __FUNCT__
1084b9ad928SBarry Smith #define __FUNCT__ "PCApply_Shell"
1096849ba73SBarry Smith static PetscErrorCode PCApply_Shell(PC pc,Vec x,Vec y)
1104b9ad928SBarry Smith {
111c5ae4b9aSBarry Smith   PC_Shell       *shell = (PC_Shell*)pc->data;
112dfbe8321SBarry Smith   PetscErrorCode ierr;
1134b9ad928SBarry Smith 
1144b9ad928SBarry Smith   PetscFunctionBegin;
115ce94432eSBarry Smith   if (!shell->apply) SETERRQ(PetscObjectComm((PetscObject)pc),PETSC_ERR_USER,"No apply() routine provided to Shell PC");
116eb6b5d47SBarry Smith   PetscStackCall("PCSHELL user function apply()",ierr = (*shell->apply)(pc,x,y);CHKERRQ(ierr));
1174b9ad928SBarry Smith   PetscFunctionReturn(0);
1184b9ad928SBarry Smith }
1194b9ad928SBarry Smith 
1204b9ad928SBarry Smith #undef __FUNCT__
1212bb17772SBarry Smith #define __FUNCT__ "PCApplyBA_Shell"
1222bb17772SBarry Smith static PetscErrorCode PCApplyBA_Shell(PC pc,PCSide side,Vec x,Vec y,Vec w)
1232bb17772SBarry Smith {
124c5ae4b9aSBarry Smith   PC_Shell       *shell = (PC_Shell*)pc->data;
1252bb17772SBarry Smith   PetscErrorCode ierr;
1262bb17772SBarry Smith 
1272bb17772SBarry Smith   PetscFunctionBegin;
128ce94432eSBarry Smith   if (!shell->applyBA) SETERRQ(PetscObjectComm((PetscObject)pc),PETSC_ERR_USER,"No applyBA() routine provided to Shell PC");
129eb6b5d47SBarry Smith   PetscStackCall("PCSHELL user function applyBA()",ierr = (*shell->applyBA)(pc,side,x,y,w);CHKERRQ(ierr));
1302bb17772SBarry Smith   PetscFunctionReturn(0);
1312bb17772SBarry Smith }
1322bb17772SBarry Smith 
1332bb17772SBarry Smith #undef __FUNCT__
1347cdd61b2SBarry Smith #define __FUNCT__ "PCPreSolve_Shell"
1357cdd61b2SBarry Smith static PetscErrorCode PCPreSolve_Shell(PC pc,KSP ksp,Vec b,Vec x)
1367cdd61b2SBarry Smith {
137c5ae4b9aSBarry Smith   PC_Shell       *shell = (PC_Shell*)pc->data;
1387cdd61b2SBarry Smith   PetscErrorCode ierr;
1397cdd61b2SBarry Smith 
1407cdd61b2SBarry Smith   PetscFunctionBegin;
141ce94432eSBarry Smith   if (!shell->presolve) SETERRQ(PetscObjectComm((PetscObject)pc),PETSC_ERR_USER,"No presolve() routine provided to Shell PC");
142eb6b5d47SBarry Smith   PetscStackCall("PCSHELL user function presolve()",ierr = (*shell->presolve)(pc,ksp,b,x);CHKERRQ(ierr));
1437cdd61b2SBarry Smith   PetscFunctionReturn(0);
1447cdd61b2SBarry Smith }
1457cdd61b2SBarry Smith 
1467cdd61b2SBarry Smith #undef __FUNCT__
1477cdd61b2SBarry Smith #define __FUNCT__ "PCPostSolve_Shell"
1487cdd61b2SBarry Smith static PetscErrorCode PCPostSolve_Shell(PC pc,KSP ksp,Vec b,Vec x)
1497cdd61b2SBarry Smith {
150c5ae4b9aSBarry Smith   PC_Shell       *shell = (PC_Shell*)pc->data;
1517cdd61b2SBarry Smith   PetscErrorCode ierr;
1527cdd61b2SBarry Smith 
1537cdd61b2SBarry Smith   PetscFunctionBegin;
154ce94432eSBarry Smith   if (!shell->postsolve) SETERRQ(PetscObjectComm((PetscObject)pc),PETSC_ERR_USER,"No postsolve() routine provided to Shell PC");
155eb6b5d47SBarry Smith   PetscStackCall("PCSHELL user function postsolve()",ierr = (*shell->postsolve)(pc,ksp,b,x);CHKERRQ(ierr));
1567cdd61b2SBarry Smith   PetscFunctionReturn(0);
1577cdd61b2SBarry Smith }
1587cdd61b2SBarry Smith 
1597cdd61b2SBarry Smith #undef __FUNCT__
1604b9ad928SBarry Smith #define __FUNCT__ "PCApplyTranspose_Shell"
1616849ba73SBarry Smith static PetscErrorCode PCApplyTranspose_Shell(PC pc,Vec x,Vec y)
1624b9ad928SBarry Smith {
163c5ae4b9aSBarry Smith   PC_Shell       *shell = (PC_Shell*)pc->data;
164dfbe8321SBarry Smith   PetscErrorCode ierr;
1654b9ad928SBarry Smith 
1664b9ad928SBarry Smith   PetscFunctionBegin;
167ce94432eSBarry Smith   if (!shell->applytranspose) SETERRQ(PetscObjectComm((PetscObject)pc),PETSC_ERR_USER,"No applytranspose() routine provided to Shell PC");
168eb6b5d47SBarry Smith   PetscStackCall("PCSHELL user function applytranspose()",ierr = (*shell->applytranspose)(pc,x,y);CHKERRQ(ierr));
1694b9ad928SBarry Smith   PetscFunctionReturn(0);
1704b9ad928SBarry Smith }
1714b9ad928SBarry Smith 
1724b9ad928SBarry Smith #undef __FUNCT__
1734b9ad928SBarry Smith #define __FUNCT__ "PCApplyRichardson_Shell"
174ace3abfcSBarry Smith static PetscErrorCode PCApplyRichardson_Shell(PC pc,Vec x,Vec y,Vec w,PetscReal rtol,PetscReal abstol, PetscReal dtol,PetscInt it,PetscBool guesszero,PetscInt *outits,PCRichardsonConvergedReason *reason)
1754b9ad928SBarry Smith {
176dfbe8321SBarry Smith   PetscErrorCode ierr;
177c5ae4b9aSBarry Smith   PC_Shell       *shell = (PC_Shell*)pc->data;
1784b9ad928SBarry Smith 
1794b9ad928SBarry Smith   PetscFunctionBegin;
180ce94432eSBarry Smith   if (!shell->applyrich) SETERRQ(PetscObjectComm((PetscObject)pc),PETSC_ERR_USER,"No applyrichardson() routine provided to Shell PC");
181eb6b5d47SBarry Smith   PetscStackCall("PCSHELL user function applyrichardson()",ierr = (*shell->applyrich)(pc,x,y,w,rtol,abstol,dtol,it,guesszero,outits,reason);CHKERRQ(ierr));
1824b9ad928SBarry Smith   PetscFunctionReturn(0);
1834b9ad928SBarry Smith }
1844b9ad928SBarry Smith 
1854b9ad928SBarry Smith #undef __FUNCT__
1864b9ad928SBarry Smith #define __FUNCT__ "PCDestroy_Shell"
1876849ba73SBarry Smith static PetscErrorCode PCDestroy_Shell(PC pc)
1884b9ad928SBarry Smith {
1894b9ad928SBarry Smith   PC_Shell       *shell = (PC_Shell*)pc->data;
190dfbe8321SBarry Smith   PetscErrorCode ierr;
1914b9ad928SBarry Smith 
1924b9ad928SBarry Smith   PetscFunctionBegin;
193503cfb0cSBarry Smith   ierr = PetscFree(shell->name);CHKERRQ(ierr);
1942fa5cd67SKarl Rupp   if (shell->destroy) PetscStackCall("PCSHELL user function destroy()",ierr = (*shell->destroy)(pc);CHKERRQ(ierr));
195c31cb41cSBarry Smith   ierr = PetscFree(pc->data);CHKERRQ(ierr);
1964b9ad928SBarry Smith   PetscFunctionReturn(0);
1974b9ad928SBarry Smith }
1984b9ad928SBarry Smith 
1994b9ad928SBarry Smith #undef __FUNCT__
2004b9ad928SBarry Smith #define __FUNCT__ "PCView_Shell"
2016849ba73SBarry Smith static PetscErrorCode PCView_Shell(PC pc,PetscViewer viewer)
2024b9ad928SBarry Smith {
2034b9ad928SBarry Smith   PC_Shell       *shell = (PC_Shell*)pc->data;
204dfbe8321SBarry Smith   PetscErrorCode ierr;
205ace3abfcSBarry Smith   PetscBool      iascii;
2064b9ad928SBarry Smith 
2074b9ad928SBarry Smith   PetscFunctionBegin;
208251f4c67SDmitry Karpeev   ierr = PetscObjectTypeCompare((PetscObject)viewer,PETSCVIEWERASCII,&iascii);CHKERRQ(ierr);
20932077d6dSBarry Smith   if (iascii) {
2102fa5cd67SKarl Rupp     if (shell->name) {
2112fa5cd67SKarl Rupp       ierr = PetscViewerASCIIPrintf(viewer,"  Shell: %s\n",shell->name);CHKERRQ(ierr);
2122fa5cd67SKarl Rupp     } else {
2132fa5cd67SKarl Rupp       ierr = PetscViewerASCIIPrintf(viewer,"  Shell: no name\n");CHKERRQ(ierr);
2142fa5cd67SKarl Rupp     }
2154b9ad928SBarry Smith   }
2164b9ad928SBarry Smith   if (shell->view) {
2174b9ad928SBarry Smith     ierr = PetscViewerASCIIPushTab(viewer);CHKERRQ(ierr);
2186891c3e4SJed Brown     ierr = (*shell->view)(pc,viewer);CHKERRQ(ierr);
2194b9ad928SBarry Smith     ierr = PetscViewerASCIIPopTab(viewer);CHKERRQ(ierr);
2204b9ad928SBarry Smith   }
2214b9ad928SBarry Smith   PetscFunctionReturn(0);
2224b9ad928SBarry Smith }
2234b9ad928SBarry Smith 
2244b9ad928SBarry Smith /* ------------------------------------------------------------------------------*/
2254b9ad928SBarry Smith #undef __FUNCT__
22618be62a5SSatish Balay #define __FUNCT__ "PCShellSetDestroy_Shell"
227f7a08781SBarry Smith static PetscErrorCode  PCShellSetDestroy_Shell(PC pc, PetscErrorCode (*destroy)(PC))
22818be62a5SSatish Balay {
229c5ae4b9aSBarry Smith   PC_Shell *shell= (PC_Shell*)pc->data;
23018be62a5SSatish Balay 
23118be62a5SSatish Balay   PetscFunctionBegin;
23218be62a5SSatish Balay   shell->destroy = destroy;
23318be62a5SSatish Balay   PetscFunctionReturn(0);
23418be62a5SSatish Balay }
23518be62a5SSatish Balay 
23618be62a5SSatish Balay #undef __FUNCT__
2374b9ad928SBarry Smith #define __FUNCT__ "PCShellSetSetUp_Shell"
238f7a08781SBarry Smith static PetscErrorCode  PCShellSetSetUp_Shell(PC pc, PetscErrorCode (*setup)(PC))
2394b9ad928SBarry Smith {
240c5ae4b9aSBarry Smith   PC_Shell *shell = (PC_Shell*)pc->data;;
2414b9ad928SBarry Smith 
2424b9ad928SBarry Smith   PetscFunctionBegin;
2434b9ad928SBarry Smith   shell->setup = setup;
244d01c8aa3SLisandro Dalcin   if (setup) pc->ops->setup = PCSetUp_Shell;
245d01c8aa3SLisandro Dalcin   else       pc->ops->setup = 0;
2464b9ad928SBarry Smith   PetscFunctionReturn(0);
2474b9ad928SBarry Smith }
2484b9ad928SBarry Smith 
2494b9ad928SBarry Smith #undef __FUNCT__
2504b9ad928SBarry Smith #define __FUNCT__ "PCShellSetApply_Shell"
251f7a08781SBarry Smith static PetscErrorCode  PCShellSetApply_Shell(PC pc,PetscErrorCode (*apply)(PC,Vec,Vec))
2524b9ad928SBarry Smith {
253c5ae4b9aSBarry Smith   PC_Shell *shell = (PC_Shell*)pc->data;
2544b9ad928SBarry Smith 
2554b9ad928SBarry Smith   PetscFunctionBegin;
2564b9ad928SBarry Smith   shell->apply = apply;
2574b9ad928SBarry Smith   PetscFunctionReturn(0);
2584b9ad928SBarry Smith }
2594b9ad928SBarry Smith 
2604b9ad928SBarry Smith #undef __FUNCT__
2612bb17772SBarry Smith #define __FUNCT__ "PCShellSetApplyBA_Shell"
262f7a08781SBarry Smith static PetscErrorCode  PCShellSetApplyBA_Shell(PC pc,PetscErrorCode (*applyBA)(PC,PCSide,Vec,Vec,Vec))
2632bb17772SBarry Smith {
264c5ae4b9aSBarry Smith   PC_Shell *shell = (PC_Shell*)pc->data;
2652bb17772SBarry Smith 
2662bb17772SBarry Smith   PetscFunctionBegin;
267d01c8aa3SLisandro Dalcin   shell->applyBA = applyBA;
268d01c8aa3SLisandro Dalcin   if (applyBA) pc->ops->applyBA  = PCApplyBA_Shell;
269aef0136fSBarry Smith   else         pc->ops->applyBA  = 0;
2702bb17772SBarry Smith   PetscFunctionReturn(0);
2712bb17772SBarry Smith }
2722bb17772SBarry Smith 
2732bb17772SBarry Smith #undef __FUNCT__
2747cdd61b2SBarry Smith #define __FUNCT__ "PCShellSetPreSolve_Shell"
275f7a08781SBarry Smith static PetscErrorCode  PCShellSetPreSolve_Shell(PC pc,PetscErrorCode (*presolve)(PC,KSP,Vec,Vec))
2767cdd61b2SBarry Smith {
277c5ae4b9aSBarry Smith   PC_Shell *shell = (PC_Shell*)pc->data;
2787cdd61b2SBarry Smith 
2797cdd61b2SBarry Smith   PetscFunctionBegin;
2807cdd61b2SBarry Smith   shell->presolve = presolve;
281d01c8aa3SLisandro Dalcin   if (presolve) pc->ops->presolve = PCPreSolve_Shell;
282d01c8aa3SLisandro Dalcin   else          pc->ops->presolve = 0;
2837cdd61b2SBarry Smith   PetscFunctionReturn(0);
2847cdd61b2SBarry Smith }
2857cdd61b2SBarry Smith 
2867cdd61b2SBarry Smith #undef __FUNCT__
2877cdd61b2SBarry Smith #define __FUNCT__ "PCShellSetPostSolve_Shell"
288f7a08781SBarry Smith static PetscErrorCode  PCShellSetPostSolve_Shell(PC pc,PetscErrorCode (*postsolve)(PC,KSP,Vec,Vec))
2897cdd61b2SBarry Smith {
290c5ae4b9aSBarry Smith   PC_Shell *shell = (PC_Shell*)pc->data;
2917cdd61b2SBarry Smith 
2927cdd61b2SBarry Smith   PetscFunctionBegin;
2937cdd61b2SBarry Smith   shell->postsolve = postsolve;
294d01c8aa3SLisandro Dalcin   if (postsolve) pc->ops->postsolve = PCPostSolve_Shell;
295d01c8aa3SLisandro Dalcin   else           pc->ops->postsolve = 0;
2967cdd61b2SBarry Smith   PetscFunctionReturn(0);
2977cdd61b2SBarry Smith }
2987cdd61b2SBarry Smith 
2997cdd61b2SBarry Smith #undef __FUNCT__
3004b9ad928SBarry Smith #define __FUNCT__ "PCShellSetView_Shell"
301f7a08781SBarry Smith static PetscErrorCode  PCShellSetView_Shell(PC pc,PetscErrorCode (*view)(PC,PetscViewer))
3024b9ad928SBarry Smith {
303c5ae4b9aSBarry Smith   PC_Shell *shell = (PC_Shell*)pc->data;
3044b9ad928SBarry Smith 
3054b9ad928SBarry Smith   PetscFunctionBegin;
3064b9ad928SBarry Smith   shell->view = view;
3074b9ad928SBarry Smith   PetscFunctionReturn(0);
3084b9ad928SBarry Smith }
3094b9ad928SBarry Smith 
3104b9ad928SBarry Smith #undef __FUNCT__
3114b9ad928SBarry Smith #define __FUNCT__ "PCShellSetApplyTranspose_Shell"
312f7a08781SBarry Smith static PetscErrorCode  PCShellSetApplyTranspose_Shell(PC pc,PetscErrorCode (*applytranspose)(PC,Vec,Vec))
3134b9ad928SBarry Smith {
314c5ae4b9aSBarry Smith   PC_Shell *shell = (PC_Shell*)pc->data;
3154b9ad928SBarry Smith 
3164b9ad928SBarry Smith   PetscFunctionBegin;
3174b9ad928SBarry Smith   shell->applytranspose = applytranspose;
318d01c8aa3SLisandro Dalcin   if (applytranspose) pc->ops->applytranspose = PCApplyTranspose_Shell;
319d01c8aa3SLisandro Dalcin   else                pc->ops->applytranspose = 0;
320d01c8aa3SLisandro Dalcin   PetscFunctionReturn(0);
321d01c8aa3SLisandro Dalcin }
322d01c8aa3SLisandro Dalcin 
323d01c8aa3SLisandro Dalcin #undef __FUNCT__
324d01c8aa3SLisandro Dalcin #define __FUNCT__ "PCShellSetApplyRichardson_Shell"
325f7a08781SBarry Smith static PetscErrorCode  PCShellSetApplyRichardson_Shell(PC pc,PetscErrorCode (*applyrich)(PC,Vec,Vec,Vec,PetscReal,PetscReal,PetscReal,PetscInt,PetscBool ,PetscInt*,PCRichardsonConvergedReason*))
326d01c8aa3SLisandro Dalcin {
327c5ae4b9aSBarry Smith   PC_Shell *shell = (PC_Shell*)pc->data;
328d01c8aa3SLisandro Dalcin 
329d01c8aa3SLisandro Dalcin   PetscFunctionBegin;
330d01c8aa3SLisandro Dalcin   shell->applyrich = applyrich;
331d01c8aa3SLisandro Dalcin   if (applyrich) pc->ops->applyrichardson = PCApplyRichardson_Shell;
332d01c8aa3SLisandro Dalcin   else           pc->ops->applyrichardson = 0;
3334b9ad928SBarry Smith   PetscFunctionReturn(0);
3344b9ad928SBarry Smith }
3354b9ad928SBarry Smith 
3364b9ad928SBarry Smith #undef __FUNCT__
3374b9ad928SBarry Smith #define __FUNCT__ "PCShellSetName_Shell"
338f7a08781SBarry Smith static PetscErrorCode  PCShellSetName_Shell(PC pc,const char name[])
3394b9ad928SBarry Smith {
340c5ae4b9aSBarry Smith   PC_Shell       *shell = (PC_Shell*)pc->data;
341dfbe8321SBarry Smith   PetscErrorCode ierr;
3424b9ad928SBarry Smith 
3434b9ad928SBarry Smith   PetscFunctionBegin;
344503cfb0cSBarry Smith   ierr = PetscFree(shell->name);CHKERRQ(ierr);
3454b9ad928SBarry Smith   ierr = PetscStrallocpy(name,&shell->name);CHKERRQ(ierr);
3464b9ad928SBarry Smith   PetscFunctionReturn(0);
3474b9ad928SBarry Smith }
3484b9ad928SBarry Smith 
3494b9ad928SBarry Smith #undef __FUNCT__
3504b9ad928SBarry Smith #define __FUNCT__ "PCShellGetName_Shell"
351f7a08781SBarry Smith static PetscErrorCode  PCShellGetName_Shell(PC pc,const char *name[])
3524b9ad928SBarry Smith {
353c5ae4b9aSBarry Smith   PC_Shell *shell = (PC_Shell*)pc->data;
3544b9ad928SBarry Smith 
3554b9ad928SBarry Smith   PetscFunctionBegin;
3564b9ad928SBarry Smith   *name = shell->name;
3574b9ad928SBarry Smith   PetscFunctionReturn(0);
3584b9ad928SBarry Smith }
3594b9ad928SBarry Smith 
3604b9ad928SBarry Smith /* -------------------------------------------------------------------------------*/
3614b9ad928SBarry Smith 
3624b9ad928SBarry Smith #undef __FUNCT__
36318be62a5SSatish Balay #define __FUNCT__ "PCShellSetDestroy"
36418be62a5SSatish Balay /*@C
36518be62a5SSatish Balay    PCShellSetDestroy - Sets routine to use to destroy the user-provided
36618be62a5SSatish Balay    application context.
36718be62a5SSatish Balay 
3683f9fe445SBarry Smith    Logically Collective on PC
36918be62a5SSatish Balay 
37018be62a5SSatish Balay    Input Parameters:
37118be62a5SSatish Balay +  pc - the preconditioner context
37218be62a5SSatish Balay .  destroy - the application-provided destroy routine
37318be62a5SSatish Balay 
37418be62a5SSatish Balay    Calling sequence of destroy:
37518be62a5SSatish Balay .vb
3766891c3e4SJed Brown    PetscErrorCode destroy (PC)
37718be62a5SSatish Balay .ve
37818be62a5SSatish Balay 
37918be62a5SSatish Balay .  ptr - the application context
38018be62a5SSatish Balay 
3814aa34b0aSBarry Smith    Notes: the function MUST return an error code of 0 on success and nonzero on failure.
3824aa34b0aSBarry Smith 
38318be62a5SSatish Balay    Level: developer
38418be62a5SSatish Balay 
38518be62a5SSatish Balay .keywords: PC, shell, set, destroy, user-provided
38618be62a5SSatish Balay 
38718be62a5SSatish Balay .seealso: PCShellSetApply(), PCShellSetContext()
38818be62a5SSatish Balay @*/
3897087cfbeSBarry Smith PetscErrorCode  PCShellSetDestroy(PC pc,PetscErrorCode (*destroy)(PC))
39018be62a5SSatish Balay {
3914ac538c5SBarry Smith   PetscErrorCode ierr;
39218be62a5SSatish Balay 
39318be62a5SSatish Balay   PetscFunctionBegin;
3940700a824SBarry Smith   PetscValidHeaderSpecific(pc,PC_CLASSID,1);
3954ac538c5SBarry Smith   ierr = PetscTryMethod(pc,"PCShellSetDestroy_C",(PC,PetscErrorCode (*)(PC)),(pc,destroy));CHKERRQ(ierr);
39618be62a5SSatish Balay   PetscFunctionReturn(0);
39718be62a5SSatish Balay }
39818be62a5SSatish Balay 
39918be62a5SSatish Balay 
40018be62a5SSatish Balay #undef __FUNCT__
4014b9ad928SBarry Smith #define __FUNCT__ "PCShellSetSetUp"
4024b9ad928SBarry Smith /*@C
4034b9ad928SBarry Smith    PCShellSetSetUp - Sets routine to use to "setup" the preconditioner whenever the
4044b9ad928SBarry Smith    matrix operator is changed.
4054b9ad928SBarry Smith 
4063f9fe445SBarry Smith    Logically Collective on PC
4074b9ad928SBarry Smith 
4084b9ad928SBarry Smith    Input Parameters:
4094b9ad928SBarry Smith +  pc - the preconditioner context
4104b9ad928SBarry Smith .  setup - the application-provided setup routine
4114b9ad928SBarry Smith 
4124b9ad928SBarry Smith    Calling sequence of setup:
4134b9ad928SBarry Smith .vb
4146891c3e4SJed Brown    PetscErrorCode setup (PC pc)
4154b9ad928SBarry Smith .ve
4164b9ad928SBarry Smith 
4176891c3e4SJed Brown .  pc - the preconditioner, get the application context with PCShellGetContext()
4184b9ad928SBarry Smith 
4194aa34b0aSBarry Smith    Notes: the function MUST return an error code of 0 on success and nonzero on failure.
4204aa34b0aSBarry Smith 
4214b9ad928SBarry Smith    Level: developer
4224b9ad928SBarry Smith 
4234b9ad928SBarry Smith .keywords: PC, shell, set, setup, user-provided
4244b9ad928SBarry Smith 
425be29d3c6SBarry Smith .seealso: PCShellSetApplyRichardson(), PCShellSetApply(), PCShellSetContext()
4264b9ad928SBarry Smith @*/
4277087cfbeSBarry Smith PetscErrorCode  PCShellSetSetUp(PC pc,PetscErrorCode (*setup)(PC))
4284b9ad928SBarry Smith {
4294ac538c5SBarry Smith   PetscErrorCode ierr;
4304b9ad928SBarry Smith 
4314b9ad928SBarry Smith   PetscFunctionBegin;
4320700a824SBarry Smith   PetscValidHeaderSpecific(pc,PC_CLASSID,1);
4334ac538c5SBarry Smith   ierr = PetscTryMethod(pc,"PCShellSetSetUp_C",(PC,PetscErrorCode (*)(PC)),(pc,setup));CHKERRQ(ierr);
4344b9ad928SBarry Smith   PetscFunctionReturn(0);
4354b9ad928SBarry Smith }
4364b9ad928SBarry Smith 
4374b9ad928SBarry Smith 
4384b9ad928SBarry Smith #undef __FUNCT__
4394b9ad928SBarry Smith #define __FUNCT__ "PCShellSetView"
4404b9ad928SBarry Smith /*@C
4414b9ad928SBarry Smith    PCShellSetView - Sets routine to use as viewer of shell preconditioner
4424b9ad928SBarry Smith 
4433f9fe445SBarry Smith    Logically Collective on PC
4444b9ad928SBarry Smith 
4454b9ad928SBarry Smith    Input Parameters:
4464b9ad928SBarry Smith +  pc - the preconditioner context
4474b9ad928SBarry Smith -  view - the application-provided view routine
4484b9ad928SBarry Smith 
4494b9ad928SBarry Smith    Calling sequence of apply:
4504b9ad928SBarry Smith .vb
4516891c3e4SJed Brown    PetscErrorCode view(PC pc,PetscViewer v)
4524b9ad928SBarry Smith .ve
4534b9ad928SBarry Smith 
4546891c3e4SJed Brown +  pc - the preconditioner, get the application context with PCShellGetContext()
4554b9ad928SBarry Smith -  v   - viewer
4564b9ad928SBarry Smith 
4574aa34b0aSBarry Smith    Notes: the function MUST return an error code of 0 on success and nonzero on failure.
4584aa34b0aSBarry Smith 
4594b9ad928SBarry Smith    Level: developer
4604b9ad928SBarry Smith 
4614b9ad928SBarry Smith .keywords: PC, shell, set, apply, user-provided
4624b9ad928SBarry Smith 
4634b9ad928SBarry Smith .seealso: PCShellSetApplyRichardson(), PCShellSetSetUp(), PCShellSetApplyTranspose()
4644b9ad928SBarry Smith @*/
4657087cfbeSBarry Smith PetscErrorCode  PCShellSetView(PC pc,PetscErrorCode (*view)(PC,PetscViewer))
4664b9ad928SBarry Smith {
4674ac538c5SBarry Smith   PetscErrorCode ierr;
4684b9ad928SBarry Smith 
4694b9ad928SBarry Smith   PetscFunctionBegin;
4700700a824SBarry Smith   PetscValidHeaderSpecific(pc,PC_CLASSID,1);
4714ac538c5SBarry Smith   ierr = PetscTryMethod(pc,"PCShellSetView_C",(PC,PetscErrorCode (*)(PC,PetscViewer)),(pc,view));CHKERRQ(ierr);
4724b9ad928SBarry Smith   PetscFunctionReturn(0);
4734b9ad928SBarry Smith }
4744b9ad928SBarry Smith 
4754b9ad928SBarry Smith #undef __FUNCT__
4764b9ad928SBarry Smith #define __FUNCT__ "PCShellSetApply"
4774b9ad928SBarry Smith /*@C
4784b9ad928SBarry Smith    PCShellSetApply - Sets routine to use as preconditioner.
4794b9ad928SBarry Smith 
4803f9fe445SBarry Smith    Logically Collective on PC
4814b9ad928SBarry Smith 
4824b9ad928SBarry Smith    Input Parameters:
4834b9ad928SBarry Smith +  pc - the preconditioner context
484be29d3c6SBarry Smith -  apply - the application-provided preconditioning routine
4854b9ad928SBarry Smith 
4864b9ad928SBarry Smith    Calling sequence of apply:
4874b9ad928SBarry Smith .vb
4886891c3e4SJed Brown    PetscErrorCode apply (PC pc,Vec xin,Vec xout)
4894b9ad928SBarry Smith .ve
4904b9ad928SBarry Smith 
4916891c3e4SJed Brown +  pc - the preconditioner, get the application context with PCShellGetContext()
4924b9ad928SBarry Smith .  xin - input vector
4934b9ad928SBarry Smith -  xout - output vector
4944b9ad928SBarry Smith 
4954aa34b0aSBarry Smith    Notes: the function MUST return an error code of 0 on success and nonzero on failure.
4964aa34b0aSBarry Smith 
497292fb18eSBarry Smith    Developer Notes: There should also be a PCShellSetApplySymmetricRight() and PCShellSetApplySymmetricLeft().
498292fb18eSBarry Smith 
4994b9ad928SBarry Smith    Level: developer
5004b9ad928SBarry Smith 
5014b9ad928SBarry Smith .keywords: PC, shell, set, apply, user-provided
5024b9ad928SBarry Smith 
5032bb17772SBarry Smith .seealso: PCShellSetApplyRichardson(), PCShellSetSetUp(), PCShellSetApplyTranspose(), PCShellSetContext(), PCShellSetApplyBA()
5044b9ad928SBarry Smith @*/
5057087cfbeSBarry Smith PetscErrorCode  PCShellSetApply(PC pc,PetscErrorCode (*apply)(PC,Vec,Vec))
5064b9ad928SBarry Smith {
5074ac538c5SBarry Smith   PetscErrorCode ierr;
5084b9ad928SBarry Smith 
5094b9ad928SBarry Smith   PetscFunctionBegin;
5100700a824SBarry Smith   PetscValidHeaderSpecific(pc,PC_CLASSID,1);
5114ac538c5SBarry Smith   ierr = PetscTryMethod(pc,"PCShellSetApply_C",(PC,PetscErrorCode (*)(PC,Vec,Vec)),(pc,apply));CHKERRQ(ierr);
5124b9ad928SBarry Smith   PetscFunctionReturn(0);
5134b9ad928SBarry Smith }
5144b9ad928SBarry Smith 
5154b9ad928SBarry Smith #undef __FUNCT__
5162bb17772SBarry Smith #define __FUNCT__ "PCShellSetApplyBA"
5172bb17772SBarry Smith /*@C
5182bb17772SBarry Smith    PCShellSetApplyBA - Sets routine to use as preconditioner times operator.
5192bb17772SBarry Smith 
5203f9fe445SBarry Smith    Logically Collective on PC
5212bb17772SBarry Smith 
5222bb17772SBarry Smith    Input Parameters:
5232bb17772SBarry Smith +  pc - the preconditioner context
5242bb17772SBarry Smith -  applyBA - the application-provided BA routine
5252bb17772SBarry Smith 
5262bb17772SBarry Smith    Calling sequence of apply:
5272bb17772SBarry Smith .vb
5286891c3e4SJed Brown    PetscErrorCode applyBA (PC pc,Vec xin,Vec xout)
5292bb17772SBarry Smith .ve
5302bb17772SBarry Smith 
5316891c3e4SJed Brown +  pc - the preconditioner, get the application context with PCShellGetContext()
5322bb17772SBarry Smith .  xin - input vector
5332bb17772SBarry Smith -  xout - output vector
5342bb17772SBarry Smith 
5354aa34b0aSBarry Smith    Notes: the function MUST return an error code of 0 on success and nonzero on failure.
5364aa34b0aSBarry Smith 
5372bb17772SBarry Smith    Level: developer
5382bb17772SBarry Smith 
5392bb17772SBarry Smith .keywords: PC, shell, set, apply, user-provided
5402bb17772SBarry Smith 
5412bb17772SBarry Smith .seealso: PCShellSetApplyRichardson(), PCShellSetSetUp(), PCShellSetApplyTranspose(), PCShellSetContext(), PCShellSetApply()
5422bb17772SBarry Smith @*/
5437087cfbeSBarry Smith PetscErrorCode  PCShellSetApplyBA(PC pc,PetscErrorCode (*applyBA)(PC,PCSide,Vec,Vec,Vec))
5442bb17772SBarry Smith {
5454ac538c5SBarry Smith   PetscErrorCode ierr;
5462bb17772SBarry Smith 
5472bb17772SBarry Smith   PetscFunctionBegin;
5480700a824SBarry Smith   PetscValidHeaderSpecific(pc,PC_CLASSID,1);
5494ac538c5SBarry Smith   ierr = PetscTryMethod(pc,"PCShellSetApplyBA_C",(PC,PetscErrorCode (*)(PC,PCSide,Vec,Vec,Vec)),(pc,applyBA));CHKERRQ(ierr);
5502bb17772SBarry Smith   PetscFunctionReturn(0);
5512bb17772SBarry Smith }
5522bb17772SBarry Smith 
5532bb17772SBarry Smith #undef __FUNCT__
5544b9ad928SBarry Smith #define __FUNCT__ "PCShellSetApplyTranspose"
5554b9ad928SBarry Smith /*@C
5564b9ad928SBarry Smith    PCShellSetApplyTranspose - Sets routine to use as preconditioner transpose.
5574b9ad928SBarry Smith 
5583f9fe445SBarry Smith    Logically Collective on PC
5594b9ad928SBarry Smith 
5604b9ad928SBarry Smith    Input Parameters:
5614b9ad928SBarry Smith +  pc - the preconditioner context
5624b9ad928SBarry Smith -  apply - the application-provided preconditioning transpose routine
5634b9ad928SBarry Smith 
5644b9ad928SBarry Smith    Calling sequence of apply:
5654b9ad928SBarry Smith .vb
5666891c3e4SJed Brown    PetscErrorCode applytranspose (PC pc,Vec xin,Vec xout)
5674b9ad928SBarry Smith .ve
5684b9ad928SBarry Smith 
5696891c3e4SJed Brown +  pc - the preconditioner, get the application context with PCShellGetContext()
5704b9ad928SBarry Smith .  xin - input vector
5714b9ad928SBarry Smith -  xout - output vector
5724b9ad928SBarry Smith 
5734aa34b0aSBarry Smith    Notes: the function MUST return an error code of 0 on success and nonzero on failure.
5744aa34b0aSBarry Smith 
5754b9ad928SBarry Smith    Level: developer
5764b9ad928SBarry Smith 
5774b9ad928SBarry Smith    Notes:
5784b9ad928SBarry Smith    Uses the same context variable as PCShellSetApply().
5794b9ad928SBarry Smith 
5804b9ad928SBarry Smith .keywords: PC, shell, set, apply, user-provided
5814b9ad928SBarry Smith 
5822bb17772SBarry Smith .seealso: PCShellSetApplyRichardson(), PCShellSetSetUp(), PCShellSetApply(), PCSetContext(), PCShellSetApplyBA()
5834b9ad928SBarry Smith @*/
5847087cfbeSBarry Smith PetscErrorCode  PCShellSetApplyTranspose(PC pc,PetscErrorCode (*applytranspose)(PC,Vec,Vec))
5854b9ad928SBarry Smith {
5864ac538c5SBarry Smith   PetscErrorCode ierr;
5874b9ad928SBarry Smith 
5884b9ad928SBarry Smith   PetscFunctionBegin;
5890700a824SBarry Smith   PetscValidHeaderSpecific(pc,PC_CLASSID,1);
5904ac538c5SBarry Smith   ierr = PetscTryMethod(pc,"PCShellSetApplyTranspose_C",(PC,PetscErrorCode (*)(PC,Vec,Vec)),(pc,applytranspose));CHKERRQ(ierr);
5914b9ad928SBarry Smith   PetscFunctionReturn(0);
5924b9ad928SBarry Smith }
5934b9ad928SBarry Smith 
5944b9ad928SBarry Smith #undef __FUNCT__
5957cdd61b2SBarry Smith #define __FUNCT__ "PCShellSetPreSolve"
5967cdd61b2SBarry Smith /*@C
5977cdd61b2SBarry Smith    PCShellSetPreSolve - Sets routine to apply to the operators/vectors before a KSPSolve() is
5987cdd61b2SBarry Smith       applied. This usually does something like scale the linear system in some application
5997cdd61b2SBarry Smith       specific way.
6007cdd61b2SBarry Smith 
6013f9fe445SBarry Smith    Logically Collective on PC
6027cdd61b2SBarry Smith 
6037cdd61b2SBarry Smith    Input Parameters:
6047cdd61b2SBarry Smith +  pc - the preconditioner context
6057cdd61b2SBarry Smith -  presolve - the application-provided presolve routine
6067cdd61b2SBarry Smith 
6077cdd61b2SBarry Smith    Calling sequence of presolve:
6087cdd61b2SBarry Smith .vb
6096891c3e4SJed Brown    PetscErrorCode presolve (PC,KSP ksp,Vec b,Vec x)
6107cdd61b2SBarry Smith .ve
6117cdd61b2SBarry Smith 
6126891c3e4SJed Brown +  pc - the preconditioner, get the application context with PCShellGetContext()
6137cdd61b2SBarry Smith .  xin - input vector
6147cdd61b2SBarry Smith -  xout - output vector
6157cdd61b2SBarry Smith 
6164aa34b0aSBarry Smith    Notes: the function MUST return an error code of 0 on success and nonzero on failure.
6174aa34b0aSBarry Smith 
6187cdd61b2SBarry Smith    Level: developer
6197cdd61b2SBarry Smith 
6207cdd61b2SBarry Smith .keywords: PC, shell, set, apply, user-provided
6217cdd61b2SBarry Smith 
622be29d3c6SBarry Smith .seealso: PCShellSetApplyRichardson(), PCShellSetSetUp(), PCShellSetApplyTranspose(), PCShellSetPostSolve(), PCShellSetContext()
6237cdd61b2SBarry Smith @*/
6247087cfbeSBarry Smith PetscErrorCode  PCShellSetPreSolve(PC pc,PetscErrorCode (*presolve)(PC,KSP,Vec,Vec))
6257cdd61b2SBarry Smith {
6264ac538c5SBarry Smith   PetscErrorCode ierr;
6277cdd61b2SBarry Smith 
6287cdd61b2SBarry Smith   PetscFunctionBegin;
6290700a824SBarry Smith   PetscValidHeaderSpecific(pc,PC_CLASSID,1);
6304ac538c5SBarry Smith   ierr = PetscTryMethod(pc,"PCShellSetPreSolve_C",(PC,PetscErrorCode (*)(PC,KSP,Vec,Vec)),(pc,presolve));CHKERRQ(ierr);
6317cdd61b2SBarry Smith   PetscFunctionReturn(0);
6327cdd61b2SBarry Smith }
6337cdd61b2SBarry Smith 
6347cdd61b2SBarry Smith #undef __FUNCT__
6357cdd61b2SBarry Smith #define __FUNCT__ "PCShellSetPostSolve"
6367cdd61b2SBarry Smith /*@C
6377cdd61b2SBarry Smith    PCShellSetPostSolve - Sets routine to apply to the operators/vectors before a KSPSolve() is
6387cdd61b2SBarry Smith       applied. This usually does something like scale the linear system in some application
6397cdd61b2SBarry Smith       specific way.
6407cdd61b2SBarry Smith 
6413f9fe445SBarry Smith    Logically Collective on PC
6427cdd61b2SBarry Smith 
6437cdd61b2SBarry Smith    Input Parameters:
6447cdd61b2SBarry Smith +  pc - the preconditioner context
6457cdd61b2SBarry Smith -  postsolve - the application-provided presolve routine
6467cdd61b2SBarry Smith 
6477cdd61b2SBarry Smith    Calling sequence of postsolve:
6487cdd61b2SBarry Smith .vb
6496891c3e4SJed Brown    PetscErrorCode postsolve(PC,KSP ksp,Vec b,Vec x)
6507cdd61b2SBarry Smith .ve
6517cdd61b2SBarry Smith 
6526891c3e4SJed Brown +  pc - the preconditioner, get the application context with PCShellGetContext()
6537cdd61b2SBarry Smith .  xin - input vector
6547cdd61b2SBarry Smith -  xout - output vector
6557cdd61b2SBarry Smith 
6564aa34b0aSBarry Smith    Notes: the function MUST return an error code of 0 on success and nonzero on failure.
6574aa34b0aSBarry Smith 
6587cdd61b2SBarry Smith    Level: developer
6597cdd61b2SBarry Smith 
6607cdd61b2SBarry Smith .keywords: PC, shell, set, apply, user-provided
6617cdd61b2SBarry Smith 
662be29d3c6SBarry Smith .seealso: PCShellSetApplyRichardson(), PCShellSetSetUp(), PCShellSetApplyTranspose(), PCShellSetPreSolve(), PCShellSetContext()
6637cdd61b2SBarry Smith @*/
6647087cfbeSBarry Smith PetscErrorCode  PCShellSetPostSolve(PC pc,PetscErrorCode (*postsolve)(PC,KSP,Vec,Vec))
6657cdd61b2SBarry Smith {
6664ac538c5SBarry Smith   PetscErrorCode ierr;
6677cdd61b2SBarry Smith 
6687cdd61b2SBarry Smith   PetscFunctionBegin;
6690700a824SBarry Smith   PetscValidHeaderSpecific(pc,PC_CLASSID,1);
6704ac538c5SBarry Smith   ierr = PetscTryMethod(pc,"PCShellSetPostSolve_C",(PC,PetscErrorCode (*)(PC,KSP,Vec,Vec)),(pc,postsolve));CHKERRQ(ierr);
6717cdd61b2SBarry Smith   PetscFunctionReturn(0);
6727cdd61b2SBarry Smith }
6737cdd61b2SBarry Smith 
6747cdd61b2SBarry Smith #undef __FUNCT__
6754b9ad928SBarry Smith #define __FUNCT__ "PCShellSetName"
6764b9ad928SBarry Smith /*@C
6774b9ad928SBarry Smith    PCShellSetName - Sets an optional name to associate with a shell
6784b9ad928SBarry Smith    preconditioner.
6794b9ad928SBarry Smith 
6804b9ad928SBarry Smith    Not Collective
6814b9ad928SBarry Smith 
6824b9ad928SBarry Smith    Input Parameters:
6834b9ad928SBarry Smith +  pc - the preconditioner context
6844b9ad928SBarry Smith -  name - character string describing shell preconditioner
6854b9ad928SBarry Smith 
6864b9ad928SBarry Smith    Level: developer
6874b9ad928SBarry Smith 
6884b9ad928SBarry Smith .keywords: PC, shell, set, name, user-provided
6894b9ad928SBarry Smith 
6904b9ad928SBarry Smith .seealso: PCShellGetName()
6914b9ad928SBarry Smith @*/
6927087cfbeSBarry Smith PetscErrorCode  PCShellSetName(PC pc,const char name[])
6934b9ad928SBarry Smith {
6944ac538c5SBarry Smith   PetscErrorCode ierr;
6954b9ad928SBarry Smith 
6964b9ad928SBarry Smith   PetscFunctionBegin;
6970700a824SBarry Smith   PetscValidHeaderSpecific(pc,PC_CLASSID,1);
6984ac538c5SBarry Smith   ierr = PetscTryMethod(pc,"PCShellSetName_C",(PC,const char []),(pc,name));CHKERRQ(ierr);
6994b9ad928SBarry Smith   PetscFunctionReturn(0);
7004b9ad928SBarry Smith }
7014b9ad928SBarry Smith 
7024b9ad928SBarry Smith #undef __FUNCT__
7034b9ad928SBarry Smith #define __FUNCT__ "PCShellGetName"
7044b9ad928SBarry Smith /*@C
7054b9ad928SBarry Smith    PCShellGetName - Gets an optional name that the user has set for a shell
7064b9ad928SBarry Smith    preconditioner.
7074b9ad928SBarry Smith 
7084b9ad928SBarry Smith    Not Collective
7094b9ad928SBarry Smith 
7104b9ad928SBarry Smith    Input Parameter:
7114b9ad928SBarry Smith .  pc - the preconditioner context
7124b9ad928SBarry Smith 
7134b9ad928SBarry Smith    Output Parameter:
7144b9ad928SBarry Smith .  name - character string describing shell preconditioner (you should not free this)
7154b9ad928SBarry Smith 
7164b9ad928SBarry Smith    Level: developer
7174b9ad928SBarry Smith 
7184b9ad928SBarry Smith .keywords: PC, shell, get, name, user-provided
7194b9ad928SBarry Smith 
7204b9ad928SBarry Smith .seealso: PCShellSetName()
7214b9ad928SBarry Smith @*/
722ccaf0856SBarry Smith PetscErrorCode  PCShellGetName(PC pc,const char *name[])
7234b9ad928SBarry Smith {
7244ac538c5SBarry Smith   PetscErrorCode ierr;
7254b9ad928SBarry Smith 
7264b9ad928SBarry Smith   PetscFunctionBegin;
7270700a824SBarry Smith   PetscValidHeaderSpecific(pc,PC_CLASSID,1);
7284482741eSBarry Smith   PetscValidPointer(name,2);
729ccaf0856SBarry Smith   ierr = PetscUseMethod(pc,"PCShellGetName_C",(PC,const char*[]),(pc,name));CHKERRQ(ierr);
7304b9ad928SBarry Smith   PetscFunctionReturn(0);
7314b9ad928SBarry Smith }
7324b9ad928SBarry Smith 
7334b9ad928SBarry Smith #undef __FUNCT__
7344b9ad928SBarry Smith #define __FUNCT__ "PCShellSetApplyRichardson"
7354b9ad928SBarry Smith /*@C
7364b9ad928SBarry Smith    PCShellSetApplyRichardson - Sets routine to use as preconditioner
7374b9ad928SBarry Smith    in Richardson iteration.
7384b9ad928SBarry Smith 
7393f9fe445SBarry Smith    Logically Collective on PC
7404b9ad928SBarry Smith 
7414b9ad928SBarry Smith    Input Parameters:
7424b9ad928SBarry Smith +  pc - the preconditioner context
743be29d3c6SBarry Smith -  apply - the application-provided preconditioning routine
7444b9ad928SBarry Smith 
7454b9ad928SBarry Smith    Calling sequence of apply:
7464b9ad928SBarry Smith .vb
7476891c3e4SJed Brown    PetscErrorCode apply (PC pc,Vec b,Vec x,Vec r,PetscReal rtol,PetscReal abstol,PetscReal dtol,PetscInt maxits)
7484b9ad928SBarry Smith .ve
7494b9ad928SBarry Smith 
7506891c3e4SJed Brown +  pc - the preconditioner, get the application context with PCShellGetContext()
7514b9ad928SBarry Smith .  b - right-hand-side
7524b9ad928SBarry Smith .  x - current iterate
7534b9ad928SBarry Smith .  r - work space
7544b9ad928SBarry Smith .  rtol - relative tolerance of residual norm to stop at
75570441072SBarry Smith .  abstol - absolute tolerance of residual norm to stop at
7564b9ad928SBarry Smith .  dtol - if residual norm increases by this factor than return
7574b9ad928SBarry Smith -  maxits - number of iterations to run
7584b9ad928SBarry Smith 
7594aa34b0aSBarry Smith    Notes: the function MUST return an error code of 0 on success and nonzero on failure.
7604aa34b0aSBarry Smith 
7614b9ad928SBarry Smith    Level: developer
7624b9ad928SBarry Smith 
7634b9ad928SBarry Smith .keywords: PC, shell, set, apply, Richardson, user-provided
7644b9ad928SBarry Smith 
765be29d3c6SBarry Smith .seealso: PCShellSetApply(), PCShellSetContext()
7664b9ad928SBarry Smith @*/
7677087cfbeSBarry Smith PetscErrorCode  PCShellSetApplyRichardson(PC pc,PetscErrorCode (*apply)(PC,Vec,Vec,Vec,PetscReal,PetscReal,PetscReal,PetscInt,PetscBool,PetscInt*,PCRichardsonConvergedReason*))
7684b9ad928SBarry Smith {
7694ac538c5SBarry Smith   PetscErrorCode ierr;
7704b9ad928SBarry Smith 
7714b9ad928SBarry Smith   PetscFunctionBegin;
7720700a824SBarry Smith   PetscValidHeaderSpecific(pc,PC_CLASSID,1);
7734ac538c5SBarry Smith   ierr = PetscTryMethod(pc,"PCShellSetApplyRichardson_C",(PC,PetscErrorCode (*)(PC,Vec,Vec,Vec,PetscReal,PetscReal,PetscReal,PetscInt,PetscBool,PetscInt*,PCRichardsonConvergedReason*)),(pc,apply));CHKERRQ(ierr);
7744b9ad928SBarry Smith   PetscFunctionReturn(0);
7754b9ad928SBarry Smith }
7764b9ad928SBarry Smith 
7774b9ad928SBarry Smith /*MC
7784b9ad928SBarry Smith    PCSHELL - Creates a new preconditioner class for use with your
7794b9ad928SBarry Smith               own private data storage format.
7804b9ad928SBarry Smith 
7814b9ad928SBarry Smith    Level: advanced
78290198e61SBarry Smith >
7834b9ad928SBarry Smith    Concepts: providing your own preconditioner
7844b9ad928SBarry Smith 
7854b9ad928SBarry Smith   Usage:
7866891c3e4SJed Brown $             extern PetscErrorCode apply(PC,Vec,Vec);
7876891c3e4SJed Brown $             extern PetscErrorCode applyba(PC,PCSide,Vec,Vec,Vec);
7886891c3e4SJed Brown $             extern PetscErrorCode applytranspose(PC,Vec,Vec);
7896891c3e4SJed Brown $             extern PetscErrorCode setup(PC);
7906891c3e4SJed Brown $             extern PetscErrorCode destroy(PC);
7916891c3e4SJed Brown $
7924b9ad928SBarry Smith $             PCCreate(comm,&pc);
7934b9ad928SBarry Smith $             PCSetType(pc,PCSHELL);
794be29d3c6SBarry Smith $             PCShellSetContext(pc,ctx)
7956891c3e4SJed Brown $             PCShellSetApply(pc,apply);
7966891c3e4SJed Brown $             PCShellSetApplyBA(pc,applyba);               (optional)
7976891c3e4SJed Brown $             PCShellSetApplyTranspose(pc,applytranspose); (optional)
7984b9ad928SBarry Smith $             PCShellSetSetUp(pc,setup);                   (optional)
799d01c8aa3SLisandro Dalcin $             PCShellSetDestroy(pc,destroy);               (optional)
8004b9ad928SBarry Smith 
8014b9ad928SBarry Smith .seealso:  PCCreate(), PCSetType(), PCType (for list of available types), PC,
802fd2d0fe1Svictor            MATSHELL, PCShellSetSetUp(), PCShellSetApply(), PCShellSetView(),
803fd2d0fe1Svictor            PCShellSetApplyTranspose(), PCShellSetName(), PCShellSetApplyRichardson(),
8042bb17772SBarry Smith            PCShellGetName(), PCShellSetContext(), PCShellGetContext(), PCShellSetApplyBA()
8054b9ad928SBarry Smith M*/
8064b9ad928SBarry Smith 
8074b9ad928SBarry Smith #undef __FUNCT__
8084b9ad928SBarry Smith #define __FUNCT__ "PCCreate_Shell"
8098cc058d9SJed Brown PETSC_EXTERN PetscErrorCode PCCreate_Shell(PC pc)
8104b9ad928SBarry Smith {
811dfbe8321SBarry Smith   PetscErrorCode ierr;
8124b9ad928SBarry Smith   PC_Shell       *shell;
8134b9ad928SBarry Smith 
8144b9ad928SBarry Smith   PetscFunctionBegin;
815*b00a9115SJed Brown   ierr     = PetscNewLog(pc,&shell);CHKERRQ(ierr);
8164b9ad928SBarry Smith   pc->data = (void*)shell;
8174b9ad928SBarry Smith 
818d01c8aa3SLisandro Dalcin   pc->ops->destroy         = PCDestroy_Shell;
8194b9ad928SBarry Smith   pc->ops->view            = PCView_Shell;
820d01c8aa3SLisandro Dalcin   pc->ops->apply           = PCApply_Shell;
821d01c8aa3SLisandro Dalcin   pc->ops->applytranspose  = 0;
8224b9ad928SBarry Smith   pc->ops->applyrichardson = 0;
823d01c8aa3SLisandro Dalcin   pc->ops->setup           = 0;
8249bbb2c88SBarry Smith   pc->ops->presolve        = 0;
8259bbb2c88SBarry Smith   pc->ops->postsolve       = 0;
8264b9ad928SBarry Smith 
8274b9ad928SBarry Smith   shell->apply          = 0;
8284b9ad928SBarry Smith   shell->applytranspose = 0;
8294b9ad928SBarry Smith   shell->name           = 0;
8304b9ad928SBarry Smith   shell->applyrich      = 0;
8317cdd61b2SBarry Smith   shell->presolve       = 0;
8327cdd61b2SBarry Smith   shell->postsolve      = 0;
8334b9ad928SBarry Smith   shell->ctx            = 0;
8344b9ad928SBarry Smith   shell->setup          = 0;
8354b9ad928SBarry Smith   shell->view           = 0;
83618be62a5SSatish Balay   shell->destroy        = 0;
8374b9ad928SBarry Smith 
838bdf89e91SBarry Smith   ierr = PetscObjectComposeFunction((PetscObject)pc,"PCShellSetDestroy_C",PCShellSetDestroy_Shell);CHKERRQ(ierr);
839bdf89e91SBarry Smith   ierr = PetscObjectComposeFunction((PetscObject)pc,"PCShellSetSetUp_C",PCShellSetSetUp_Shell);CHKERRQ(ierr);
840bdf89e91SBarry Smith   ierr = PetscObjectComposeFunction((PetscObject)pc,"PCShellSetApply_C",PCShellSetApply_Shell);CHKERRQ(ierr);
841bdf89e91SBarry Smith   ierr = PetscObjectComposeFunction((PetscObject)pc,"PCShellSetApplyBA_C",PCShellSetApplyBA_Shell);CHKERRQ(ierr);
842bdf89e91SBarry Smith   ierr = PetscObjectComposeFunction((PetscObject)pc,"PCShellSetPreSolve_C",PCShellSetPreSolve_Shell);CHKERRQ(ierr);
843bdf89e91SBarry Smith   ierr = PetscObjectComposeFunction((PetscObject)pc,"PCShellSetPostSolve_C",PCShellSetPostSolve_Shell);CHKERRQ(ierr);
844bdf89e91SBarry Smith   ierr = PetscObjectComposeFunction((PetscObject)pc,"PCShellSetView_C",PCShellSetView_Shell);CHKERRQ(ierr);
845bdf89e91SBarry Smith   ierr = PetscObjectComposeFunction((PetscObject)pc,"PCShellSetApplyTranspose_C",PCShellSetApplyTranspose_Shell);CHKERRQ(ierr);
846bdf89e91SBarry Smith   ierr = PetscObjectComposeFunction((PetscObject)pc,"PCShellSetName_C",PCShellSetName_Shell);CHKERRQ(ierr);
847bdf89e91SBarry Smith   ierr = PetscObjectComposeFunction((PetscObject)pc,"PCShellGetName_C",PCShellGetName_Shell);CHKERRQ(ierr);
848bdf89e91SBarry Smith   ierr = PetscObjectComposeFunction((PetscObject)pc,"PCShellSetApplyRichardson_C",PCShellSetApplyRichardson_Shell);CHKERRQ(ierr);
8494b9ad928SBarry Smith   PetscFunctionReturn(0);
8504b9ad928SBarry Smith }
8514b9ad928SBarry Smith 
8524b9ad928SBarry Smith 
8534b9ad928SBarry Smith 
8544b9ad928SBarry Smith 
8554b9ad928SBarry Smith 
8564b9ad928SBarry Smith 
857