xref: /petsc/src/ksp/pc/impls/shell/shellpc.c (revision 3c94ec114b93ba0cfbf7331735f0e93b9db506db)
14b9ad928SBarry Smith /*$Id: shellpc.c,v 1.77 2001/08/21 21:03:18 bsmith Exp $*/
24b9ad928SBarry Smith 
34b9ad928SBarry Smith /*
44b9ad928SBarry Smith    This provides a simple shell for Fortran (and C programmers) to
54b9ad928SBarry Smith   create their own preconditioner without writing much interface code.
64b9ad928SBarry Smith */
74b9ad928SBarry Smith 
84b9ad928SBarry Smith #include "src/ksp/pc/pcimpl.h"        /*I "petscpc.h" I*/
9*3c94ec11SBarry Smith #include "vecimpl.h"
104b9ad928SBarry Smith 
11ac226902SBarry Smith EXTERN_C_BEGIN
124b9ad928SBarry Smith typedef struct {
134b9ad928SBarry Smith   void *ctx,*ctxrich;    /* user provided contexts for preconditioner */
144b9ad928SBarry Smith   int  (*setup)(void *);
154b9ad928SBarry Smith   int  (*apply)(void *,Vec,Vec);
164b9ad928SBarry Smith   int  (*view)(void *,PetscViewer);
174b9ad928SBarry Smith   int  (*applytranspose)(void *,Vec,Vec);
184b9ad928SBarry Smith   int  (*applyrich)(void *,Vec,Vec,Vec,PetscReal,PetscReal,PetscReal,int);
194b9ad928SBarry Smith   char *name;
204b9ad928SBarry Smith } PC_Shell;
21ac226902SBarry Smith EXTERN_C_END
224b9ad928SBarry Smith 
234b9ad928SBarry Smith #undef __FUNCT__
244b9ad928SBarry Smith #define __FUNCT__ "PCApply_SetUp"
254b9ad928SBarry Smith static int PCSetUp_Shell(PC pc)
264b9ad928SBarry Smith {
274b9ad928SBarry Smith   PC_Shell *shell;
284b9ad928SBarry Smith   int      ierr;
294b9ad928SBarry Smith 
304b9ad928SBarry Smith   PetscFunctionBegin;
314b9ad928SBarry Smith   shell = (PC_Shell*)pc->data;
324b9ad928SBarry Smith   if (shell->setup) {
334b9ad928SBarry Smith     ierr  = (*shell->setup)(shell->ctx);CHKERRQ(ierr);
344b9ad928SBarry Smith   }
354b9ad928SBarry Smith   PetscFunctionReturn(0);
364b9ad928SBarry Smith }
374b9ad928SBarry Smith 
384b9ad928SBarry Smith #undef __FUNCT__
394b9ad928SBarry Smith #define __FUNCT__ "PCApply_Shell"
404b9ad928SBarry Smith static int PCApply_Shell(PC pc,Vec x,Vec y)
414b9ad928SBarry Smith {
424b9ad928SBarry Smith   PC_Shell *shell;
434b9ad928SBarry Smith   int      ierr;
444b9ad928SBarry Smith 
454b9ad928SBarry Smith   PetscFunctionBegin;
464b9ad928SBarry Smith   shell = (PC_Shell*)pc->data;
474b9ad928SBarry Smith   if (!shell->apply) SETERRQ(1,"No apply() routine provided to Shell PC");
484b9ad928SBarry Smith   ierr  = (*shell->apply)(shell->ctx,x,y);CHKERRQ(ierr);
494b9ad928SBarry Smith   PetscFunctionReturn(0);
504b9ad928SBarry Smith }
514b9ad928SBarry Smith 
524b9ad928SBarry Smith #undef __FUNCT__
534b9ad928SBarry Smith #define __FUNCT__ "PCApplyTranspose_Shell"
544b9ad928SBarry Smith static int PCApplyTranspose_Shell(PC pc,Vec x,Vec y)
554b9ad928SBarry Smith {
564b9ad928SBarry Smith   PC_Shell *shell;
574b9ad928SBarry Smith   int      ierr;
584b9ad928SBarry Smith 
594b9ad928SBarry Smith   PetscFunctionBegin;
604b9ad928SBarry Smith   shell = (PC_Shell*)pc->data;
614b9ad928SBarry Smith   if (!shell->applytranspose) SETERRQ(1,"No applytranspose() routine provided to Shell PC");
624b9ad928SBarry Smith   ierr  = (*shell->applytranspose)(shell->ctx,x,y);CHKERRQ(ierr);
634b9ad928SBarry Smith   PetscFunctionReturn(0);
644b9ad928SBarry Smith }
654b9ad928SBarry Smith 
664b9ad928SBarry Smith #undef __FUNCT__
674b9ad928SBarry Smith #define __FUNCT__ "PCApplyRichardson_Shell"
684b9ad928SBarry Smith static int PCApplyRichardson_Shell(PC pc,Vec x,Vec y,Vec w,PetscReal rtol,PetscReal atol, PetscReal dtol,int it)
694b9ad928SBarry Smith {
704b9ad928SBarry Smith   int      ierr;
714b9ad928SBarry Smith   PC_Shell *shell;
724b9ad928SBarry Smith 
734b9ad928SBarry Smith   PetscFunctionBegin;
744b9ad928SBarry Smith   shell = (PC_Shell*)pc->data;
754b9ad928SBarry Smith   ierr  = (*shell->applyrich)(shell->ctxrich,x,y,w,rtol,atol,dtol,it);CHKERRQ(ierr);
764b9ad928SBarry Smith   PetscFunctionReturn(0);
774b9ad928SBarry Smith }
784b9ad928SBarry Smith 
794b9ad928SBarry Smith #undef __FUNCT__
804b9ad928SBarry Smith #define __FUNCT__ "PCDestroy_Shell"
814b9ad928SBarry Smith static int PCDestroy_Shell(PC pc)
824b9ad928SBarry Smith {
834b9ad928SBarry Smith   PC_Shell *shell = (PC_Shell*)pc->data;
844b9ad928SBarry Smith   int      ierr;
854b9ad928SBarry Smith 
864b9ad928SBarry Smith   PetscFunctionBegin;
874b9ad928SBarry Smith   if (shell->name) {ierr = PetscFree(shell->name);}
884b9ad928SBarry Smith   ierr = PetscFree(shell);CHKERRQ(ierr);
894b9ad928SBarry Smith   PetscFunctionReturn(0);
904b9ad928SBarry Smith }
914b9ad928SBarry Smith 
924b9ad928SBarry Smith #undef __FUNCT__
934b9ad928SBarry Smith #define __FUNCT__ "PCView_Shell"
944b9ad928SBarry Smith static int PCView_Shell(PC pc,PetscViewer viewer)
954b9ad928SBarry Smith {
964b9ad928SBarry Smith   PC_Shell   *shell = (PC_Shell*)pc->data;
974b9ad928SBarry Smith   int        ierr;
984b9ad928SBarry Smith   PetscTruth isascii;
994b9ad928SBarry Smith 
1004b9ad928SBarry Smith   PetscFunctionBegin;
1014b9ad928SBarry Smith   ierr = PetscTypeCompare((PetscObject)viewer,PETSC_VIEWER_ASCII,&isascii);CHKERRQ(ierr);
1024b9ad928SBarry Smith   if (isascii) {
1034b9ad928SBarry Smith     if (shell->name) {ierr = PetscViewerASCIIPrintf(viewer,"  Shell: %s\n",shell->name);CHKERRQ(ierr);}
1044b9ad928SBarry Smith     else             {ierr = PetscViewerASCIIPrintf(viewer,"  Shell: no name\n");CHKERRQ(ierr);}
1054b9ad928SBarry Smith   }
1064b9ad928SBarry Smith   if (shell->view) {
1074b9ad928SBarry Smith     ierr = PetscViewerASCIIPushTab(viewer);CHKERRQ(ierr);
1084b9ad928SBarry Smith     ierr  = (*shell->view)(shell->ctx,viewer);CHKERRQ(ierr);
1094b9ad928SBarry Smith     ierr = PetscViewerASCIIPopTab(viewer);CHKERRQ(ierr);
1104b9ad928SBarry Smith   }
1114b9ad928SBarry Smith   PetscFunctionReturn(0);
1124b9ad928SBarry Smith }
1134b9ad928SBarry Smith 
1144b9ad928SBarry Smith /* ------------------------------------------------------------------------------*/
1154b9ad928SBarry Smith EXTERN_C_BEGIN
1164b9ad928SBarry Smith #undef __FUNCT__
1174b9ad928SBarry Smith #define __FUNCT__ "PCShellSetSetUp_Shell"
1184b9ad928SBarry Smith int PCShellSetSetUp_Shell(PC pc, int (*setup)(void*))
1194b9ad928SBarry Smith {
1204b9ad928SBarry Smith   PC_Shell *shell;
1214b9ad928SBarry Smith 
1224b9ad928SBarry Smith   PetscFunctionBegin;
1234b9ad928SBarry Smith   shell        = (PC_Shell*)pc->data;
1244b9ad928SBarry Smith   shell->setup = setup;
1254b9ad928SBarry Smith   PetscFunctionReturn(0);
1264b9ad928SBarry Smith }
1274b9ad928SBarry Smith EXTERN_C_END
1284b9ad928SBarry Smith 
1294b9ad928SBarry Smith EXTERN_C_BEGIN
1304b9ad928SBarry Smith #undef __FUNCT__
1314b9ad928SBarry Smith #define __FUNCT__ "PCShellSetApply_Shell"
1324b9ad928SBarry Smith int PCShellSetApply_Shell(PC pc,int (*apply)(void*,Vec,Vec),void *ptr)
1334b9ad928SBarry Smith {
1344b9ad928SBarry Smith   PC_Shell *shell;
1354b9ad928SBarry Smith 
1364b9ad928SBarry Smith   PetscFunctionBegin;
1374b9ad928SBarry Smith   shell        = (PC_Shell*)pc->data;
1384b9ad928SBarry Smith   shell->apply = apply;
1394b9ad928SBarry Smith   shell->ctx   = ptr;
1404b9ad928SBarry Smith   PetscFunctionReturn(0);
1414b9ad928SBarry Smith }
1424b9ad928SBarry Smith EXTERN_C_END
1434b9ad928SBarry Smith 
1444b9ad928SBarry Smith EXTERN_C_BEGIN
1454b9ad928SBarry Smith #undef __FUNCT__
1464b9ad928SBarry Smith #define __FUNCT__ "PCShellSetView_Shell"
1474b9ad928SBarry Smith int PCShellSetView_Shell(PC pc,int (*view)(void*,PetscViewer))
1484b9ad928SBarry Smith {
1494b9ad928SBarry Smith   PC_Shell *shell;
1504b9ad928SBarry Smith 
1514b9ad928SBarry Smith   PetscFunctionBegin;
1524b9ad928SBarry Smith   shell        = (PC_Shell*)pc->data;
1534b9ad928SBarry Smith   shell->view = view;
1544b9ad928SBarry Smith   PetscFunctionReturn(0);
1554b9ad928SBarry Smith }
1564b9ad928SBarry Smith EXTERN_C_END
1574b9ad928SBarry Smith 
1584b9ad928SBarry Smith EXTERN_C_BEGIN
1594b9ad928SBarry Smith #undef __FUNCT__
1604b9ad928SBarry Smith #define __FUNCT__ "PCShellSetApplyTranspose_Shell"
1614b9ad928SBarry Smith int PCShellSetApplyTranspose_Shell(PC pc,int (*applytranspose)(void*,Vec,Vec))
1624b9ad928SBarry Smith {
1634b9ad928SBarry Smith   PC_Shell *shell;
1644b9ad928SBarry Smith 
1654b9ad928SBarry Smith   PetscFunctionBegin;
1664b9ad928SBarry Smith   shell                 = (PC_Shell*)pc->data;
1674b9ad928SBarry Smith   shell->applytranspose = applytranspose;
1684b9ad928SBarry Smith   PetscFunctionReturn(0);
1694b9ad928SBarry Smith }
1704b9ad928SBarry Smith EXTERN_C_END
1714b9ad928SBarry Smith 
1724b9ad928SBarry Smith EXTERN_C_BEGIN
1734b9ad928SBarry Smith #undef __FUNCT__
1744b9ad928SBarry Smith #define __FUNCT__ "PCShellSetName_Shell"
1754b9ad928SBarry Smith int PCShellSetName_Shell(PC pc,const char name[])
1764b9ad928SBarry Smith {
1774b9ad928SBarry Smith   PC_Shell *shell;
1784b9ad928SBarry Smith   int      ierr;
1794b9ad928SBarry Smith 
1804b9ad928SBarry Smith   PetscFunctionBegin;
1814b9ad928SBarry Smith   shell = (PC_Shell*)pc->data;
1824b9ad928SBarry Smith   ierr  = PetscStrallocpy(name,&shell->name);CHKERRQ(ierr);
1834b9ad928SBarry Smith   PetscFunctionReturn(0);
1844b9ad928SBarry Smith }
1854b9ad928SBarry Smith EXTERN_C_END
1864b9ad928SBarry Smith 
1874b9ad928SBarry Smith EXTERN_C_BEGIN
1884b9ad928SBarry Smith #undef __FUNCT__
1894b9ad928SBarry Smith #define __FUNCT__ "PCShellGetName_Shell"
1904b9ad928SBarry Smith int PCShellGetName_Shell(PC pc,char *name[])
1914b9ad928SBarry Smith {
1924b9ad928SBarry Smith   PC_Shell *shell;
1934b9ad928SBarry Smith 
1944b9ad928SBarry Smith   PetscFunctionBegin;
1954b9ad928SBarry Smith   shell  = (PC_Shell*)pc->data;
1964b9ad928SBarry Smith   *name  = shell->name;
1974b9ad928SBarry Smith   PetscFunctionReturn(0);
1984b9ad928SBarry Smith }
1994b9ad928SBarry Smith EXTERN_C_END
2004b9ad928SBarry Smith 
2014b9ad928SBarry Smith EXTERN_C_BEGIN
2024b9ad928SBarry Smith #undef __FUNCT__
2034b9ad928SBarry Smith #define __FUNCT__ "PCShellSetApplyRichardson_Shell"
2044b9ad928SBarry Smith int PCShellSetApplyRichardson_Shell(PC pc,int (*apply)(void*,Vec,Vec,Vec,PetscReal,PetscReal,PetscReal,int),void *ptr)
2054b9ad928SBarry Smith {
2064b9ad928SBarry Smith   PC_Shell *shell;
2074b9ad928SBarry Smith 
2084b9ad928SBarry Smith   PetscFunctionBegin;
2094b9ad928SBarry Smith   shell                     = (PC_Shell*)pc->data;
2104b9ad928SBarry Smith   pc->ops->applyrichardson  = PCApplyRichardson_Shell;
2114b9ad928SBarry Smith   shell->applyrich          = apply;
2124b9ad928SBarry Smith   shell->ctxrich            = ptr;
2134b9ad928SBarry Smith   PetscFunctionReturn(0);
2144b9ad928SBarry Smith }
2154b9ad928SBarry Smith EXTERN_C_END
2164b9ad928SBarry Smith 
2174b9ad928SBarry Smith /* -------------------------------------------------------------------------------*/
2184b9ad928SBarry Smith 
2194b9ad928SBarry Smith #undef __FUNCT__
2204b9ad928SBarry Smith #define __FUNCT__ "PCShellSetSetUp"
2214b9ad928SBarry Smith /*@C
2224b9ad928SBarry Smith    PCShellSetSetUp - Sets routine to use to "setup" the preconditioner whenever the
2234b9ad928SBarry Smith    matrix operator is changed.
2244b9ad928SBarry Smith 
2254b9ad928SBarry Smith    Collective on PC
2264b9ad928SBarry Smith 
2274b9ad928SBarry Smith    Input Parameters:
2284b9ad928SBarry Smith +  pc - the preconditioner context
2294b9ad928SBarry Smith .  setup - the application-provided setup routine
2304b9ad928SBarry Smith 
2314b9ad928SBarry Smith    Calling sequence of setup:
2324b9ad928SBarry Smith .vb
2334b9ad928SBarry Smith    int setup (void *ptr)
2344b9ad928SBarry Smith .ve
2354b9ad928SBarry Smith 
2364b9ad928SBarry Smith .  ptr - the application context
2374b9ad928SBarry Smith 
2384b9ad928SBarry Smith    Level: developer
2394b9ad928SBarry Smith 
2404b9ad928SBarry Smith .keywords: PC, shell, set, setup, user-provided
2414b9ad928SBarry Smith 
2424b9ad928SBarry Smith .seealso: PCShellSetApplyRichardson(), PCShellSetApply()
2434b9ad928SBarry Smith @*/
2444b9ad928SBarry Smith int PCShellSetSetUp(PC pc,int (*setup)(void*))
2454b9ad928SBarry Smith {
2464b9ad928SBarry Smith   int ierr,(*f)(PC,int (*)(void*));
2474b9ad928SBarry Smith 
2484b9ad928SBarry Smith   PetscFunctionBegin;
2494482741eSBarry Smith   PetscValidHeaderSpecific(pc,PC_COOKIE,1);
2504b9ad928SBarry Smith   ierr = PetscObjectQueryFunction((PetscObject)pc,"PCShellSetSetUp_C",(void (**)(void))&f);CHKERRQ(ierr);
2514b9ad928SBarry Smith   if (f) {
2524b9ad928SBarry Smith     ierr = (*f)(pc,setup);CHKERRQ(ierr);
2534b9ad928SBarry Smith   }
2544b9ad928SBarry Smith   PetscFunctionReturn(0);
2554b9ad928SBarry Smith }
2564b9ad928SBarry Smith 
2574b9ad928SBarry Smith 
2584b9ad928SBarry Smith #undef __FUNCT__
2594b9ad928SBarry Smith #define __FUNCT__ "PCShellSetView"
2604b9ad928SBarry Smith /*@C
2614b9ad928SBarry Smith    PCShellSetView - Sets routine to use as viewer of shell preconditioner
2624b9ad928SBarry Smith 
2634b9ad928SBarry Smith    Collective on PC
2644b9ad928SBarry Smith 
2654b9ad928SBarry Smith    Input Parameters:
2664b9ad928SBarry Smith +  pc - the preconditioner context
2674b9ad928SBarry Smith -  view - the application-provided view routine
2684b9ad928SBarry Smith 
2694b9ad928SBarry Smith    Calling sequence of apply:
2704b9ad928SBarry Smith .vb
2714b9ad928SBarry Smith    int view(void *ptr,PetscViewer v)
2724b9ad928SBarry Smith .ve
2734b9ad928SBarry Smith 
2744b9ad928SBarry Smith +  ptr - the application context
2754b9ad928SBarry Smith -  v   - viewer
2764b9ad928SBarry Smith 
2774b9ad928SBarry Smith    Level: developer
2784b9ad928SBarry Smith 
2794b9ad928SBarry Smith .keywords: PC, shell, set, apply, user-provided
2804b9ad928SBarry Smith 
2814b9ad928SBarry Smith .seealso: PCShellSetApplyRichardson(), PCShellSetSetUp(), PCShellSetApplyTranspose()
2824b9ad928SBarry Smith @*/
2834b9ad928SBarry Smith int PCShellSetView(PC pc,int (*view)(void*,PetscViewer))
2844b9ad928SBarry Smith {
2854b9ad928SBarry Smith   int ierr,(*f)(PC,int (*)(void*,PetscViewer));
2864b9ad928SBarry Smith 
2874b9ad928SBarry Smith   PetscFunctionBegin;
2884482741eSBarry Smith   PetscValidHeaderSpecific(pc,PC_COOKIE,1);
2894b9ad928SBarry Smith   ierr = PetscObjectQueryFunction((PetscObject)pc,"PCShellSetView_C",(void (**)(void))&f);CHKERRQ(ierr);
2904b9ad928SBarry Smith   if (f) {
2914b9ad928SBarry Smith     ierr = (*f)(pc,view);CHKERRQ(ierr);
2924b9ad928SBarry Smith   }
2934b9ad928SBarry Smith   PetscFunctionReturn(0);
2944b9ad928SBarry Smith }
2954b9ad928SBarry Smith 
2964b9ad928SBarry Smith #undef __FUNCT__
2974b9ad928SBarry Smith #define __FUNCT__ "PCShellSetApply"
2984b9ad928SBarry Smith /*@C
2994b9ad928SBarry Smith    PCShellSetApply - Sets routine to use as preconditioner.
3004b9ad928SBarry Smith 
3014b9ad928SBarry Smith    Collective on PC
3024b9ad928SBarry Smith 
3034b9ad928SBarry Smith    Input Parameters:
3044b9ad928SBarry Smith +  pc - the preconditioner context
3054b9ad928SBarry Smith .  apply - the application-provided preconditioning routine
3064b9ad928SBarry Smith -  ptr - pointer to data needed by this routine
3074b9ad928SBarry Smith 
3084b9ad928SBarry Smith    Calling sequence of apply:
3094b9ad928SBarry Smith .vb
3104b9ad928SBarry Smith    int apply (void *ptr,Vec xin,Vec xout)
3114b9ad928SBarry Smith .ve
3124b9ad928SBarry Smith 
3134b9ad928SBarry Smith +  ptr - the application context
3144b9ad928SBarry Smith .  xin - input vector
3154b9ad928SBarry Smith -  xout - output vector
3164b9ad928SBarry Smith 
3174b9ad928SBarry Smith    Level: developer
3184b9ad928SBarry Smith 
3194b9ad928SBarry Smith .keywords: PC, shell, set, apply, user-provided
3204b9ad928SBarry Smith 
3214b9ad928SBarry Smith .seealso: PCShellSetApplyRichardson(), PCShellSetSetUp(), PCShellSetApplyTranspose()
3224b9ad928SBarry Smith @*/
3234b9ad928SBarry Smith int PCShellSetApply(PC pc,int (*apply)(void*,Vec,Vec),void *ptr)
3244b9ad928SBarry Smith {
3254b9ad928SBarry Smith   int ierr,(*f)(PC,int (*)(void*,Vec,Vec),void *);
3264b9ad928SBarry Smith 
3274b9ad928SBarry Smith   PetscFunctionBegin;
3284482741eSBarry Smith   PetscValidHeaderSpecific(pc,PC_COOKIE,1);
3294b9ad928SBarry Smith   ierr = PetscObjectQueryFunction((PetscObject)pc,"PCShellSetApply_C",(void (**)(void))&f);CHKERRQ(ierr);
3304b9ad928SBarry Smith   if (f) {
3314b9ad928SBarry Smith     ierr = (*f)(pc,apply,ptr);CHKERRQ(ierr);
3324b9ad928SBarry Smith   }
3334b9ad928SBarry Smith   PetscFunctionReturn(0);
3344b9ad928SBarry Smith }
3354b9ad928SBarry Smith 
3364b9ad928SBarry Smith #undef __FUNCT__
3374b9ad928SBarry Smith #define __FUNCT__ "PCShellSetApplyTranspose"
3384b9ad928SBarry Smith /*@C
3394b9ad928SBarry Smith    PCShellSetApplyTranspose - Sets routine to use as preconditioner transpose.
3404b9ad928SBarry Smith 
3414b9ad928SBarry Smith    Collective on PC
3424b9ad928SBarry Smith 
3434b9ad928SBarry Smith    Input Parameters:
3444b9ad928SBarry Smith +  pc - the preconditioner context
3454b9ad928SBarry Smith -  apply - the application-provided preconditioning transpose routine
3464b9ad928SBarry Smith 
3474b9ad928SBarry Smith    Calling sequence of apply:
3484b9ad928SBarry Smith .vb
3494b9ad928SBarry Smith    int applytranspose (void *ptr,Vec xin,Vec xout)
3504b9ad928SBarry Smith .ve
3514b9ad928SBarry Smith 
3524b9ad928SBarry Smith +  ptr - the application context
3534b9ad928SBarry Smith .  xin - input vector
3544b9ad928SBarry Smith -  xout - output vector
3554b9ad928SBarry Smith 
3564b9ad928SBarry Smith    Level: developer
3574b9ad928SBarry Smith 
3584b9ad928SBarry Smith    Notes:
3594b9ad928SBarry Smith    Uses the same context variable as PCShellSetApply().
3604b9ad928SBarry Smith 
3614b9ad928SBarry Smith .keywords: PC, shell, set, apply, user-provided
3624b9ad928SBarry Smith 
3634b9ad928SBarry Smith .seealso: PCShellSetApplyRichardson(), PCShellSetSetUp(), PCShellSetApply()
3644b9ad928SBarry Smith @*/
3654b9ad928SBarry Smith int PCShellSetApplyTranspose(PC pc,int (*applytranspose)(void*,Vec,Vec))
3664b9ad928SBarry Smith {
3674b9ad928SBarry Smith   int ierr,(*f)(PC,int (*)(void*,Vec,Vec));
3684b9ad928SBarry Smith 
3694b9ad928SBarry Smith   PetscFunctionBegin;
3704482741eSBarry Smith   PetscValidHeaderSpecific(pc,PC_COOKIE,1);
3714b9ad928SBarry Smith   ierr = PetscObjectQueryFunction((PetscObject)pc,"PCShellSetApplyTranspose_C",(void (**)(void))&f);CHKERRQ(ierr);
3724b9ad928SBarry Smith   if (f) {
3734b9ad928SBarry Smith     ierr = (*f)(pc,applytranspose);CHKERRQ(ierr);
3744b9ad928SBarry Smith   }
3754b9ad928SBarry Smith   PetscFunctionReturn(0);
3764b9ad928SBarry Smith }
3774b9ad928SBarry Smith 
3784b9ad928SBarry Smith #undef __FUNCT__
3794b9ad928SBarry Smith #define __FUNCT__ "PCShellSetName"
3804b9ad928SBarry Smith /*@C
3814b9ad928SBarry Smith    PCShellSetName - Sets an optional name to associate with a shell
3824b9ad928SBarry Smith    preconditioner.
3834b9ad928SBarry Smith 
3844b9ad928SBarry Smith    Not Collective
3854b9ad928SBarry Smith 
3864b9ad928SBarry Smith    Input Parameters:
3874b9ad928SBarry Smith +  pc - the preconditioner context
3884b9ad928SBarry Smith -  name - character string describing shell preconditioner
3894b9ad928SBarry Smith 
3904b9ad928SBarry Smith    Level: developer
3914b9ad928SBarry Smith 
3924b9ad928SBarry Smith .keywords: PC, shell, set, name, user-provided
3934b9ad928SBarry Smith 
3944b9ad928SBarry Smith .seealso: PCShellGetName()
3954b9ad928SBarry Smith @*/
3964b9ad928SBarry Smith int PCShellSetName(PC pc,const char name[])
3974b9ad928SBarry Smith {
3984b9ad928SBarry Smith   int ierr,(*f)(PC,const char []);
3994b9ad928SBarry Smith 
4004b9ad928SBarry Smith   PetscFunctionBegin;
4014482741eSBarry Smith   PetscValidHeaderSpecific(pc,PC_COOKIE,1);
4024b9ad928SBarry Smith   ierr = PetscObjectQueryFunction((PetscObject)pc,"PCShellSetName_C",(void (**)(void))&f);CHKERRQ(ierr);
4034b9ad928SBarry Smith   if (f) {
4044b9ad928SBarry Smith     ierr = (*f)(pc,name);CHKERRQ(ierr);
4054b9ad928SBarry Smith   }
4064b9ad928SBarry Smith   PetscFunctionReturn(0);
4074b9ad928SBarry Smith }
4084b9ad928SBarry Smith 
4094b9ad928SBarry Smith #undef __FUNCT__
4104b9ad928SBarry Smith #define __FUNCT__ "PCShellGetName"
4114b9ad928SBarry Smith /*@C
4124b9ad928SBarry Smith    PCShellGetName - Gets an optional name that the user has set for a shell
4134b9ad928SBarry Smith    preconditioner.
4144b9ad928SBarry Smith 
4154b9ad928SBarry Smith    Not Collective
4164b9ad928SBarry Smith 
4174b9ad928SBarry Smith    Input Parameter:
4184b9ad928SBarry Smith .  pc - the preconditioner context
4194b9ad928SBarry Smith 
4204b9ad928SBarry Smith    Output Parameter:
4214b9ad928SBarry Smith .  name - character string describing shell preconditioner (you should not free this)
4224b9ad928SBarry Smith 
4234b9ad928SBarry Smith    Level: developer
4244b9ad928SBarry Smith 
4254b9ad928SBarry Smith .keywords: PC, shell, get, name, user-provided
4264b9ad928SBarry Smith 
4274b9ad928SBarry Smith .seealso: PCShellSetName()
4284b9ad928SBarry Smith @*/
4294b9ad928SBarry Smith int PCShellGetName(PC pc,char *name[])
4304b9ad928SBarry Smith {
4314b9ad928SBarry Smith   int ierr,(*f)(PC,char *[]);
4324b9ad928SBarry Smith 
4334b9ad928SBarry Smith   PetscFunctionBegin;
4344482741eSBarry Smith   PetscValidHeaderSpecific(pc,PC_COOKIE,1);
4354482741eSBarry Smith   PetscValidPointer(name,2);
4364b9ad928SBarry Smith   ierr = PetscObjectQueryFunction((PetscObject)pc,"PCShellGetName_C",(void (**)(void))&f);CHKERRQ(ierr);
4374b9ad928SBarry Smith   if (f) {
4384b9ad928SBarry Smith     ierr = (*f)(pc,name);CHKERRQ(ierr);
4394b9ad928SBarry Smith   } else {
4404b9ad928SBarry Smith     SETERRQ(1,"Not shell preconditioner, cannot get name");
4414b9ad928SBarry Smith   }
4424b9ad928SBarry Smith   PetscFunctionReturn(0);
4434b9ad928SBarry Smith }
4444b9ad928SBarry Smith 
4454b9ad928SBarry Smith #undef __FUNCT__
4464b9ad928SBarry Smith #define __FUNCT__ "PCShellSetApplyRichardson"
4474b9ad928SBarry Smith /*@C
4484b9ad928SBarry Smith    PCShellSetApplyRichardson - Sets routine to use as preconditioner
4494b9ad928SBarry Smith    in Richardson iteration.
4504b9ad928SBarry Smith 
4514b9ad928SBarry Smith    Collective on PC
4524b9ad928SBarry Smith 
4534b9ad928SBarry Smith    Input Parameters:
4544b9ad928SBarry Smith +  pc - the preconditioner context
4554b9ad928SBarry Smith .  apply - the application-provided preconditioning routine
4564b9ad928SBarry Smith -  ptr - pointer to data needed by this routine
4574b9ad928SBarry Smith 
4584b9ad928SBarry Smith    Calling sequence of apply:
4594b9ad928SBarry Smith .vb
4604b9ad928SBarry Smith    int apply (void *ptr,Vec b,Vec x,Vec r,PetscReal rtol,PetscReal atol,PetscReal dtol,int maxits)
4614b9ad928SBarry Smith .ve
4624b9ad928SBarry Smith 
4634b9ad928SBarry Smith +  ptr - the application context
4644b9ad928SBarry Smith .  b - right-hand-side
4654b9ad928SBarry Smith .  x - current iterate
4664b9ad928SBarry Smith .  r - work space
4674b9ad928SBarry Smith .  rtol - relative tolerance of residual norm to stop at
4684b9ad928SBarry Smith .  atol - absolute tolerance of residual norm to stop at
4694b9ad928SBarry Smith .  dtol - if residual norm increases by this factor than return
4704b9ad928SBarry Smith -  maxits - number of iterations to run
4714b9ad928SBarry Smith 
4724b9ad928SBarry Smith    Level: developer
4734b9ad928SBarry Smith 
4744b9ad928SBarry Smith .keywords: PC, shell, set, apply, Richardson, user-provided
4754b9ad928SBarry Smith 
4764b9ad928SBarry Smith .seealso: PCShellSetApply()
4774b9ad928SBarry Smith @*/
4784b9ad928SBarry Smith int PCShellSetApplyRichardson(PC pc,int (*apply)(void*,Vec,Vec,Vec,PetscReal,PetscReal,PetscReal,int),void *ptr)
4794b9ad928SBarry Smith {
4804b9ad928SBarry Smith   int ierr,(*f)(PC,int (*)(void*,Vec,Vec,Vec,PetscReal,PetscReal,PetscReal,int),void *);
4814b9ad928SBarry Smith 
4824b9ad928SBarry Smith   PetscFunctionBegin;
4834482741eSBarry Smith   PetscValidHeaderSpecific(pc,PC_COOKIE,1);
4844b9ad928SBarry Smith   ierr = PetscObjectQueryFunction((PetscObject)pc,"PCShellSetApplyRichardson_C",(void (**)(void))&f);CHKERRQ(ierr);
4854b9ad928SBarry Smith   if (f) {
4864b9ad928SBarry Smith     ierr = (*f)(pc,apply,ptr);CHKERRQ(ierr);
4874b9ad928SBarry Smith   }
4884b9ad928SBarry Smith   PetscFunctionReturn(0);
4894b9ad928SBarry Smith }
4904b9ad928SBarry Smith 
4914b9ad928SBarry Smith /*MC
4924b9ad928SBarry Smith    PCSHELL - Creates a new preconditioner class for use with your
4934b9ad928SBarry Smith               own private data storage format.
4944b9ad928SBarry Smith 
4954b9ad928SBarry Smith    Level: advanced
4964b9ad928SBarry Smith 
4974b9ad928SBarry Smith    Concepts: providing your own preconditioner
4984b9ad928SBarry Smith 
4994b9ad928SBarry Smith   Usage:
5004b9ad928SBarry Smith $             int (*mult)(void *,Vec,Vec);
5014b9ad928SBarry Smith $             int (*setup)(void *);
5024b9ad928SBarry Smith $             PCCreate(comm,&pc);
5034b9ad928SBarry Smith $             PCSetType(pc,PCSHELL);
5044b9ad928SBarry Smith $             PCShellSetApply(pc,mult,ctx);
5054b9ad928SBarry Smith $             PCShellSetSetUp(pc,setup);       (optional)
5064b9ad928SBarry Smith 
5074b9ad928SBarry Smith .seealso:  PCCreate(), PCSetType(), PCType (for list of available types), PC,
5084b9ad928SBarry Smith            KSPSHELL(), MATSHELL(), PCShellSetUp(), PCShellSetApply(), PCShellSetView(),
5094b9ad928SBarry Smith            PCShellSetApplyTranpose(), PCShellSetName(), PCShellSetApplyRichardson(),
5104b9ad928SBarry Smith            PCShellGetName()
5114b9ad928SBarry Smith M*/
5124b9ad928SBarry Smith 
5134b9ad928SBarry Smith EXTERN_C_BEGIN
5144b9ad928SBarry Smith #undef __FUNCT__
5154b9ad928SBarry Smith #define __FUNCT__ "PCCreate_Shell"
5164b9ad928SBarry Smith int PCCreate_Shell(PC pc)
5174b9ad928SBarry Smith {
5184b9ad928SBarry Smith   int      ierr;
5194b9ad928SBarry Smith   PC_Shell *shell;
5204b9ad928SBarry Smith 
5214b9ad928SBarry Smith   PetscFunctionBegin;
5224b9ad928SBarry Smith   pc->ops->destroy    = PCDestroy_Shell;
5234b9ad928SBarry Smith   ierr                = PetscNew(PC_Shell,&shell);CHKERRQ(ierr);
5244b9ad928SBarry Smith   PetscLogObjectMemory(pc,sizeof(PC_Shell));
5254b9ad928SBarry Smith 
5264b9ad928SBarry Smith   pc->data         = (void*)shell;
5274b9ad928SBarry Smith   pc->name         = 0;
5284b9ad928SBarry Smith 
5294b9ad928SBarry Smith   pc->ops->apply           = PCApply_Shell;
5304b9ad928SBarry Smith   pc->ops->view            = PCView_Shell;
5314b9ad928SBarry Smith   pc->ops->applytranspose  = PCApplyTranspose_Shell;
5324b9ad928SBarry Smith   pc->ops->applyrichardson = 0;
5334b9ad928SBarry Smith   pc->ops->setup           = PCSetUp_Shell;
5344b9ad928SBarry Smith   pc->ops->view            = PCView_Shell;
5354b9ad928SBarry Smith 
5364b9ad928SBarry Smith   shell->apply          = 0;
5374b9ad928SBarry Smith   shell->applytranspose = 0;
5384b9ad928SBarry Smith   shell->name           = 0;
5394b9ad928SBarry Smith   shell->applyrich      = 0;
5404b9ad928SBarry Smith   shell->ctxrich        = 0;
5414b9ad928SBarry Smith   shell->ctx            = 0;
5424b9ad928SBarry Smith   shell->setup          = 0;
5434b9ad928SBarry Smith   shell->view           = 0;
5444b9ad928SBarry Smith 
5454b9ad928SBarry Smith   ierr = PetscObjectComposeFunctionDynamic((PetscObject)pc,"PCShellSetSetUp_C","PCShellSetSetUp_Shell",
5464b9ad928SBarry Smith                     PCShellSetSetUp_Shell);CHKERRQ(ierr);
5474b9ad928SBarry Smith   ierr = PetscObjectComposeFunctionDynamic((PetscObject)pc,"PCShellSetApply_C","PCShellSetApply_Shell",
5484b9ad928SBarry Smith                     PCShellSetApply_Shell);CHKERRQ(ierr);
5494b9ad928SBarry Smith   ierr = PetscObjectComposeFunctionDynamic((PetscObject)pc,"PCShellSetView_C","PCShellSetView_Shell",
5504b9ad928SBarry Smith                     PCShellSetView_Shell);CHKERRQ(ierr);
5514b9ad928SBarry Smith   ierr = PetscObjectComposeFunctionDynamic((PetscObject)pc,"PCShellSetApplyTranspose_C",
5524b9ad928SBarry Smith                     "PCShellSetApplyTranspose_Shell",
5534b9ad928SBarry Smith                     PCShellSetApplyTranspose_Shell);CHKERRQ(ierr);
5544b9ad928SBarry Smith   ierr = PetscObjectComposeFunctionDynamic((PetscObject)pc,"PCShellSetName_C","PCShellSetName_Shell",
5554b9ad928SBarry Smith                     PCShellSetName_Shell);CHKERRQ(ierr);
5564b9ad928SBarry Smith   ierr = PetscObjectComposeFunctionDynamic((PetscObject)pc,"PCShellGetName_C","PCShellGetName_Shell",
5574b9ad928SBarry Smith                     PCShellGetName_Shell);CHKERRQ(ierr);
5584b9ad928SBarry Smith   ierr = PetscObjectComposeFunctionDynamic((PetscObject)pc,"PCShellSetApplyRichardson_C",
5594b9ad928SBarry Smith                     "PCShellSetApplyRichardson_Shell",
5604b9ad928SBarry Smith                     PCShellSetApplyRichardson_Shell);CHKERRQ(ierr);
5614b9ad928SBarry Smith 
5624b9ad928SBarry Smith   PetscFunctionReturn(0);
5634b9ad928SBarry Smith }
5644b9ad928SBarry Smith EXTERN_C_END
5654b9ad928SBarry Smith 
5664b9ad928SBarry Smith 
5674b9ad928SBarry Smith 
5684b9ad928SBarry Smith 
5694b9ad928SBarry Smith 
5704b9ad928SBarry Smith 
571