1*dba47a55SKris Buschelman #define PETSCKSP_DLL 2*dba47a55SKris Buschelman 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*/ 93c94ec11SBarry 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 */ 146849ba73SBarry Smith PetscErrorCode (*setup)(void*); 156849ba73SBarry Smith PetscErrorCode (*apply)(void*,Vec,Vec); 166849ba73SBarry Smith PetscErrorCode (*view)(void*,PetscViewer); 176849ba73SBarry Smith PetscErrorCode (*applytranspose)(void*,Vec,Vec); 1813f74950SBarry Smith PetscErrorCode (*applyrich)(void*,Vec,Vec,Vec,PetscReal,PetscReal,PetscReal,PetscInt); 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" 256849ba73SBarry Smith static PetscErrorCode PCSetUp_Shell(PC pc) 264b9ad928SBarry Smith { 274b9ad928SBarry Smith PC_Shell *shell; 28dfbe8321SBarry Smith PetscErrorCode 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" 406849ba73SBarry Smith static PetscErrorCode PCApply_Shell(PC pc,Vec x,Vec y) 414b9ad928SBarry Smith { 424b9ad928SBarry Smith PC_Shell *shell; 43dfbe8321SBarry Smith PetscErrorCode ierr; 444b9ad928SBarry Smith 454b9ad928SBarry Smith PetscFunctionBegin; 464b9ad928SBarry Smith shell = (PC_Shell*)pc->data; 471302d50aSBarry Smith if (!shell->apply) SETERRQ(PETSC_ERR_USER,"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" 546849ba73SBarry Smith static PetscErrorCode PCApplyTranspose_Shell(PC pc,Vec x,Vec y) 554b9ad928SBarry Smith { 564b9ad928SBarry Smith PC_Shell *shell; 57dfbe8321SBarry Smith PetscErrorCode ierr; 584b9ad928SBarry Smith 594b9ad928SBarry Smith PetscFunctionBegin; 604b9ad928SBarry Smith shell = (PC_Shell*)pc->data; 611302d50aSBarry Smith if (!shell->applytranspose) SETERRQ(PETSC_ERR_USER,"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" 6813f74950SBarry Smith static PetscErrorCode PCApplyRichardson_Shell(PC pc,Vec x,Vec y,Vec w,PetscReal rtol,PetscReal abstol, PetscReal dtol,PetscInt it) 694b9ad928SBarry Smith { 70dfbe8321SBarry Smith PetscErrorCode ierr; 714b9ad928SBarry Smith PC_Shell *shell; 724b9ad928SBarry Smith 734b9ad928SBarry Smith PetscFunctionBegin; 744b9ad928SBarry Smith shell = (PC_Shell*)pc->data; 7570441072SBarry Smith ierr = (*shell->applyrich)(shell->ctxrich,x,y,w,rtol,abstol,dtol,it);CHKERRQ(ierr); 764b9ad928SBarry Smith PetscFunctionReturn(0); 774b9ad928SBarry Smith } 784b9ad928SBarry Smith 794b9ad928SBarry Smith #undef __FUNCT__ 804b9ad928SBarry Smith #define __FUNCT__ "PCDestroy_Shell" 816849ba73SBarry Smith static PetscErrorCode PCDestroy_Shell(PC pc) 824b9ad928SBarry Smith { 834b9ad928SBarry Smith PC_Shell *shell = (PC_Shell*)pc->data; 84dfbe8321SBarry Smith PetscErrorCode 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" 946849ba73SBarry Smith static PetscErrorCode PCView_Shell(PC pc,PetscViewer viewer) 954b9ad928SBarry Smith { 964b9ad928SBarry Smith PC_Shell *shell = (PC_Shell*)pc->data; 97dfbe8321SBarry Smith PetscErrorCode ierr; 9832077d6dSBarry Smith PetscTruth iascii; 994b9ad928SBarry Smith 1004b9ad928SBarry Smith PetscFunctionBegin; 10132077d6dSBarry Smith ierr = PetscTypeCompare((PetscObject)viewer,PETSC_VIEWER_ASCII,&iascii);CHKERRQ(ierr); 10232077d6dSBarry Smith if (iascii) { 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" 118*dba47a55SKris Buschelman PetscErrorCode PETSCKSP_DLLEXPORT PCShellSetSetUp_Shell(PC pc, PetscErrorCode (*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" 132*dba47a55SKris Buschelman PetscErrorCode PETSCKSP_DLLEXPORT PCShellSetApply_Shell(PC pc,PetscErrorCode (*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" 147*dba47a55SKris Buschelman PetscErrorCode PETSCKSP_DLLEXPORT PCShellSetView_Shell(PC pc,PetscErrorCode (*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" 161*dba47a55SKris Buschelman PetscErrorCode PETSCKSP_DLLEXPORT PCShellSetApplyTranspose_Shell(PC pc,PetscErrorCode (*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" 175*dba47a55SKris Buschelman PetscErrorCode PETSCKSP_DLLEXPORT PCShellSetName_Shell(PC pc,const char name[]) 1764b9ad928SBarry Smith { 1774b9ad928SBarry Smith PC_Shell *shell; 178dfbe8321SBarry Smith PetscErrorCode 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" 190*dba47a55SKris Buschelman PetscErrorCode PETSCKSP_DLLEXPORT 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" 204*dba47a55SKris Buschelman PetscErrorCode PETSCKSP_DLLEXPORT PCShellSetApplyRichardson_Shell(PC pc,PetscErrorCode (*apply)(void*,Vec,Vec,Vec,PetscReal,PetscReal,PetscReal,PetscInt),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 23313f74950SBarry Smith PetscErrorCode 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 @*/ 244*dba47a55SKris Buschelman PetscErrorCode PETSCKSP_DLLEXPORT PCShellSetSetUp(PC pc,PetscErrorCode (*setup)(void*)) 2454b9ad928SBarry Smith { 2466849ba73SBarry Smith PetscErrorCode ierr,(*f)(PC,PetscErrorCode (*)(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 27113f74950SBarry Smith PetscErrorCode 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 @*/ 283*dba47a55SKris Buschelman PetscErrorCode PETSCKSP_DLLEXPORT PCShellSetView(PC pc,PetscErrorCode (*view)(void*,PetscViewer)) 2844b9ad928SBarry Smith { 2856849ba73SBarry Smith PetscErrorCode ierr,(*f)(PC,PetscErrorCode (*)(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 31013f74950SBarry Smith PetscErrorCode 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 @*/ 323*dba47a55SKris Buschelman PetscErrorCode PETSCKSP_DLLEXPORT PCShellSetApply(PC pc,PetscErrorCode (*apply)(void*,Vec,Vec),void *ptr) 3244b9ad928SBarry Smith { 3256849ba73SBarry Smith PetscErrorCode ierr,(*f)(PC,PetscErrorCode (*)(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 34913f74950SBarry Smith PetscErrorCode 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 @*/ 365*dba47a55SKris Buschelman PetscErrorCode PETSCKSP_DLLEXPORT PCShellSetApplyTranspose(PC pc,PetscErrorCode (*applytranspose)(void*,Vec,Vec)) 3664b9ad928SBarry Smith { 3676849ba73SBarry Smith PetscErrorCode ierr,(*f)(PC,PetscErrorCode (*)(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 @*/ 396*dba47a55SKris Buschelman PetscErrorCode PETSCKSP_DLLEXPORT PCShellSetName(PC pc,const char name[]) 3974b9ad928SBarry Smith { 398dfbe8321SBarry Smith PetscErrorCode 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 @*/ 429*dba47a55SKris Buschelman PetscErrorCode PETSCKSP_DLLEXPORT PCShellGetName(PC pc,char *name[]) 4304b9ad928SBarry Smith { 431dfbe8321SBarry Smith PetscErrorCode 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 { 4401302d50aSBarry Smith SETERRQ(PETSC_ERR_ARG_WRONG,"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 46013f74950SBarry Smith PetscErrorCode apply (void *ptr,Vec b,Vec x,Vec r,PetscReal rtol,PetscReal abstol,PetscReal dtol,PetscInt 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 46870441072SBarry Smith . abstol - 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 @*/ 478*dba47a55SKris Buschelman PetscErrorCode PETSCKSP_DLLEXPORT PCShellSetApplyRichardson(PC pc,PetscErrorCode (*apply)(void*,Vec,Vec,Vec,PetscReal,PetscReal,PetscReal,PetscInt),void *ptr) 4794b9ad928SBarry Smith { 48013f74950SBarry Smith PetscErrorCode ierr,(*f)(PC,PetscErrorCode (*)(void*,Vec,Vec,Vec,PetscReal,PetscReal,PetscReal,PetscInt),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: 5006849ba73SBarry Smith $ PetscErrorCode (*mult)(void*,Vec,Vec); 5016849ba73SBarry Smith $ PetscErrorCode (*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, 508d07a9264SSatish Balay 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" 516*dba47a55SKris Buschelman PetscErrorCode PETSCKSP_DLLEXPORT PCCreate_Shell(PC pc) 5174b9ad928SBarry Smith { 518dfbe8321SBarry Smith PetscErrorCode 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); 52452e6d16bSBarry Smith ierr = PetscLogObjectMemory(pc,sizeof(PC_Shell));CHKERRQ(ierr); 5254b9ad928SBarry Smith pc->data = (void*)shell; 5264b9ad928SBarry Smith pc->name = 0; 5274b9ad928SBarry Smith 5284b9ad928SBarry Smith pc->ops->apply = PCApply_Shell; 5294b9ad928SBarry Smith pc->ops->view = PCView_Shell; 5304b9ad928SBarry Smith pc->ops->applytranspose = PCApplyTranspose_Shell; 5314b9ad928SBarry Smith pc->ops->applyrichardson = 0; 5324b9ad928SBarry Smith pc->ops->setup = PCSetUp_Shell; 5334b9ad928SBarry Smith pc->ops->view = PCView_Shell; 5344b9ad928SBarry Smith 5354b9ad928SBarry Smith shell->apply = 0; 5364b9ad928SBarry Smith shell->applytranspose = 0; 5374b9ad928SBarry Smith shell->name = 0; 5384b9ad928SBarry Smith shell->applyrich = 0; 5394b9ad928SBarry Smith shell->ctxrich = 0; 5404b9ad928SBarry Smith shell->ctx = 0; 5414b9ad928SBarry Smith shell->setup = 0; 5424b9ad928SBarry Smith shell->view = 0; 5434b9ad928SBarry Smith 5444b9ad928SBarry Smith ierr = PetscObjectComposeFunctionDynamic((PetscObject)pc,"PCShellSetSetUp_C","PCShellSetSetUp_Shell", 5454b9ad928SBarry Smith PCShellSetSetUp_Shell);CHKERRQ(ierr); 5464b9ad928SBarry Smith ierr = PetscObjectComposeFunctionDynamic((PetscObject)pc,"PCShellSetApply_C","PCShellSetApply_Shell", 5474b9ad928SBarry Smith PCShellSetApply_Shell);CHKERRQ(ierr); 5484b9ad928SBarry Smith ierr = PetscObjectComposeFunctionDynamic((PetscObject)pc,"PCShellSetView_C","PCShellSetView_Shell", 5494b9ad928SBarry Smith PCShellSetView_Shell);CHKERRQ(ierr); 5504b9ad928SBarry Smith ierr = PetscObjectComposeFunctionDynamic((PetscObject)pc,"PCShellSetApplyTranspose_C", 5514b9ad928SBarry Smith "PCShellSetApplyTranspose_Shell", 5524b9ad928SBarry Smith PCShellSetApplyTranspose_Shell);CHKERRQ(ierr); 5534b9ad928SBarry Smith ierr = PetscObjectComposeFunctionDynamic((PetscObject)pc,"PCShellSetName_C","PCShellSetName_Shell", 5544b9ad928SBarry Smith PCShellSetName_Shell);CHKERRQ(ierr); 5554b9ad928SBarry Smith ierr = PetscObjectComposeFunctionDynamic((PetscObject)pc,"PCShellGetName_C","PCShellGetName_Shell", 5564b9ad928SBarry Smith PCShellGetName_Shell);CHKERRQ(ierr); 5574b9ad928SBarry Smith ierr = PetscObjectComposeFunctionDynamic((PetscObject)pc,"PCShellSetApplyRichardson_C", 5584b9ad928SBarry Smith "PCShellSetApplyRichardson_Shell", 5594b9ad928SBarry Smith PCShellSetApplyRichardson_Shell);CHKERRQ(ierr); 5604b9ad928SBarry Smith 5614b9ad928SBarry Smith PetscFunctionReturn(0); 5624b9ad928SBarry Smith } 5634b9ad928SBarry Smith EXTERN_C_END 5644b9ad928SBarry Smith 5654b9ad928SBarry Smith 5664b9ad928SBarry Smith 5674b9ad928SBarry Smith 5684b9ad928SBarry Smith 5694b9ad928SBarry Smith 570