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 7af0996ceSBarry Smith #include <petsc/private/pcimpl.h> /*I "petscpc.h" I*/ 8af0996ceSBarry Smith #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 44*daf670e6SBarry Smith Fortran Notes: To use this from Fortran you must write a Fortran interface definition for this 45*daf670e6SBarry Smith function that tells Fortran the Fortran derived data type that you are passing in as the ctx argument. 46*daf670e6SBarry Smith 47be29d3c6SBarry Smith .keywords: PC, shell, get, context 48be29d3c6SBarry Smith 49c5ae4b9aSBarry Smith .seealso: PCShellSetContext() 50be29d3c6SBarry Smith @*/ 517087cfbeSBarry Smith PetscErrorCode PCShellGetContext(PC pc,void **ctx) 52be29d3c6SBarry Smith { 53be29d3c6SBarry Smith PetscErrorCode ierr; 54ace3abfcSBarry Smith PetscBool flg; 55be29d3c6SBarry Smith 56be29d3c6SBarry Smith PetscFunctionBegin; 570700a824SBarry Smith PetscValidHeaderSpecific(pc,PC_CLASSID,1); 58be29d3c6SBarry Smith PetscValidPointer(ctx,2); 59251f4c67SDmitry Karpeev ierr = PetscObjectTypeCompare((PetscObject)pc,PCSHELL,&flg);CHKERRQ(ierr); 60be29d3c6SBarry Smith if (!flg) *ctx = 0; 61be29d3c6SBarry Smith else *ctx = ((PC_Shell*)(pc->data))->ctx; 62be29d3c6SBarry Smith PetscFunctionReturn(0); 63be29d3c6SBarry Smith } 64be29d3c6SBarry Smith 65be29d3c6SBarry Smith #undef __FUNCT__ 66be29d3c6SBarry Smith #define __FUNCT__ "PCShellSetContext" 679dd1005fSJed Brown /*@ 68be29d3c6SBarry Smith PCShellSetContext - sets the context for a shell PC 69be29d3c6SBarry Smith 703f9fe445SBarry Smith Logically Collective on PC 71be29d3c6SBarry Smith 72be29d3c6SBarry Smith Input Parameters: 73be29d3c6SBarry Smith + pc - the shell PC 74be29d3c6SBarry Smith - ctx - the context 75be29d3c6SBarry Smith 76be29d3c6SBarry Smith Level: advanced 77be29d3c6SBarry Smith 78*daf670e6SBarry Smith Fortran Notes: To use this from Fortran you must write a Fortran interface definition for this 79*daf670e6SBarry Smith function that tells Fortran the Fortran derived data type that you are passing in as the ctx argument. 80*daf670e6SBarry Smith 81be29d3c6SBarry Smith 826895c445SBarry Smith 83c5ae4b9aSBarry Smith .seealso: PCShellGetContext(), PCSHELL 84be29d3c6SBarry Smith @*/ 857087cfbeSBarry Smith PetscErrorCode PCShellSetContext(PC pc,void *ctx) 86be29d3c6SBarry Smith { 87c5ae4b9aSBarry Smith PC_Shell *shell = (PC_Shell*)pc->data; 88be29d3c6SBarry Smith PetscErrorCode ierr; 89ace3abfcSBarry Smith PetscBool flg; 90be29d3c6SBarry Smith 91be29d3c6SBarry Smith PetscFunctionBegin; 920700a824SBarry Smith PetscValidHeaderSpecific(pc,PC_CLASSID,1); 93251f4c67SDmitry Karpeev ierr = PetscObjectTypeCompare((PetscObject)pc,PCSHELL,&flg);CHKERRQ(ierr); 942fa5cd67SKarl Rupp if (flg) shell->ctx = ctx; 95be29d3c6SBarry Smith PetscFunctionReturn(0); 96be29d3c6SBarry Smith } 97be29d3c6SBarry Smith 98be29d3c6SBarry Smith #undef __FUNCT__ 9918be62a5SSatish Balay #define __FUNCT__ "PCSetUp_Shell" 1006849ba73SBarry Smith static PetscErrorCode PCSetUp_Shell(PC pc) 1014b9ad928SBarry Smith { 102c5ae4b9aSBarry Smith PC_Shell *shell = (PC_Shell*)pc->data; 103dfbe8321SBarry Smith PetscErrorCode ierr; 1044b9ad928SBarry Smith 1054b9ad928SBarry Smith PetscFunctionBegin; 106ce94432eSBarry Smith if (!shell->setup) SETERRQ(PetscObjectComm((PetscObject)pc),PETSC_ERR_USER,"No setup() routine provided to Shell PC"); 107eb6b5d47SBarry Smith PetscStackCall("PCSHELL user function setup()",ierr = (*shell->setup)(pc);CHKERRQ(ierr)); 1084b9ad928SBarry Smith PetscFunctionReturn(0); 1094b9ad928SBarry Smith } 1104b9ad928SBarry Smith 1114b9ad928SBarry Smith #undef __FUNCT__ 1124b9ad928SBarry Smith #define __FUNCT__ "PCApply_Shell" 1136849ba73SBarry Smith static PetscErrorCode PCApply_Shell(PC pc,Vec x,Vec y) 1144b9ad928SBarry Smith { 115c5ae4b9aSBarry Smith PC_Shell *shell = (PC_Shell*)pc->data; 116dfbe8321SBarry Smith PetscErrorCode ierr; 1174b9ad928SBarry Smith 1184b9ad928SBarry Smith PetscFunctionBegin; 119ce94432eSBarry Smith if (!shell->apply) SETERRQ(PetscObjectComm((PetscObject)pc),PETSC_ERR_USER,"No apply() routine provided to Shell PC"); 120eb6b5d47SBarry Smith PetscStackCall("PCSHELL user function apply()",ierr = (*shell->apply)(pc,x,y);CHKERRQ(ierr)); 1214b9ad928SBarry Smith PetscFunctionReturn(0); 1224b9ad928SBarry Smith } 1234b9ad928SBarry Smith 1244b9ad928SBarry Smith #undef __FUNCT__ 1252bb17772SBarry Smith #define __FUNCT__ "PCApplyBA_Shell" 1262bb17772SBarry Smith static PetscErrorCode PCApplyBA_Shell(PC pc,PCSide side,Vec x,Vec y,Vec w) 1272bb17772SBarry Smith { 128c5ae4b9aSBarry Smith PC_Shell *shell = (PC_Shell*)pc->data; 1292bb17772SBarry Smith PetscErrorCode ierr; 1302bb17772SBarry Smith 1312bb17772SBarry Smith PetscFunctionBegin; 132ce94432eSBarry Smith if (!shell->applyBA) SETERRQ(PetscObjectComm((PetscObject)pc),PETSC_ERR_USER,"No applyBA() routine provided to Shell PC"); 133eb6b5d47SBarry Smith PetscStackCall("PCSHELL user function applyBA()",ierr = (*shell->applyBA)(pc,side,x,y,w);CHKERRQ(ierr)); 1342bb17772SBarry Smith PetscFunctionReturn(0); 1352bb17772SBarry Smith } 1362bb17772SBarry Smith 1372bb17772SBarry Smith #undef __FUNCT__ 1387cdd61b2SBarry Smith #define __FUNCT__ "PCPreSolve_Shell" 1397cdd61b2SBarry Smith static PetscErrorCode PCPreSolve_Shell(PC pc,KSP ksp,Vec b,Vec x) 1407cdd61b2SBarry Smith { 141c5ae4b9aSBarry Smith PC_Shell *shell = (PC_Shell*)pc->data; 1427cdd61b2SBarry Smith PetscErrorCode ierr; 1437cdd61b2SBarry Smith 1447cdd61b2SBarry Smith PetscFunctionBegin; 145ce94432eSBarry Smith if (!shell->presolve) SETERRQ(PetscObjectComm((PetscObject)pc),PETSC_ERR_USER,"No presolve() routine provided to Shell PC"); 146eb6b5d47SBarry Smith PetscStackCall("PCSHELL user function presolve()",ierr = (*shell->presolve)(pc,ksp,b,x);CHKERRQ(ierr)); 1477cdd61b2SBarry Smith PetscFunctionReturn(0); 1487cdd61b2SBarry Smith } 1497cdd61b2SBarry Smith 1507cdd61b2SBarry Smith #undef __FUNCT__ 1517cdd61b2SBarry Smith #define __FUNCT__ "PCPostSolve_Shell" 1527cdd61b2SBarry Smith static PetscErrorCode PCPostSolve_Shell(PC pc,KSP ksp,Vec b,Vec x) 1537cdd61b2SBarry Smith { 154c5ae4b9aSBarry Smith PC_Shell *shell = (PC_Shell*)pc->data; 1557cdd61b2SBarry Smith PetscErrorCode ierr; 1567cdd61b2SBarry Smith 1577cdd61b2SBarry Smith PetscFunctionBegin; 158ce94432eSBarry Smith if (!shell->postsolve) SETERRQ(PetscObjectComm((PetscObject)pc),PETSC_ERR_USER,"No postsolve() routine provided to Shell PC"); 159eb6b5d47SBarry Smith PetscStackCall("PCSHELL user function postsolve()",ierr = (*shell->postsolve)(pc,ksp,b,x);CHKERRQ(ierr)); 1607cdd61b2SBarry Smith PetscFunctionReturn(0); 1617cdd61b2SBarry Smith } 1627cdd61b2SBarry Smith 1637cdd61b2SBarry Smith #undef __FUNCT__ 1644b9ad928SBarry Smith #define __FUNCT__ "PCApplyTranspose_Shell" 1656849ba73SBarry Smith static PetscErrorCode PCApplyTranspose_Shell(PC pc,Vec x,Vec y) 1664b9ad928SBarry Smith { 167c5ae4b9aSBarry Smith PC_Shell *shell = (PC_Shell*)pc->data; 168dfbe8321SBarry Smith PetscErrorCode ierr; 1694b9ad928SBarry Smith 1704b9ad928SBarry Smith PetscFunctionBegin; 171ce94432eSBarry Smith if (!shell->applytranspose) SETERRQ(PetscObjectComm((PetscObject)pc),PETSC_ERR_USER,"No applytranspose() routine provided to Shell PC"); 172eb6b5d47SBarry Smith PetscStackCall("PCSHELL user function applytranspose()",ierr = (*shell->applytranspose)(pc,x,y);CHKERRQ(ierr)); 1734b9ad928SBarry Smith PetscFunctionReturn(0); 1744b9ad928SBarry Smith } 1754b9ad928SBarry Smith 1764b9ad928SBarry Smith #undef __FUNCT__ 1774b9ad928SBarry Smith #define __FUNCT__ "PCApplyRichardson_Shell" 178ace3abfcSBarry 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) 1794b9ad928SBarry Smith { 180dfbe8321SBarry Smith PetscErrorCode ierr; 181c5ae4b9aSBarry Smith PC_Shell *shell = (PC_Shell*)pc->data; 1824b9ad928SBarry Smith 1834b9ad928SBarry Smith PetscFunctionBegin; 184ce94432eSBarry Smith if (!shell->applyrich) SETERRQ(PetscObjectComm((PetscObject)pc),PETSC_ERR_USER,"No applyrichardson() routine provided to Shell PC"); 185eb6b5d47SBarry Smith PetscStackCall("PCSHELL user function applyrichardson()",ierr = (*shell->applyrich)(pc,x,y,w,rtol,abstol,dtol,it,guesszero,outits,reason);CHKERRQ(ierr)); 1864b9ad928SBarry Smith PetscFunctionReturn(0); 1874b9ad928SBarry Smith } 1884b9ad928SBarry Smith 1894b9ad928SBarry Smith #undef __FUNCT__ 1904b9ad928SBarry Smith #define __FUNCT__ "PCDestroy_Shell" 1916849ba73SBarry Smith static PetscErrorCode PCDestroy_Shell(PC pc) 1924b9ad928SBarry Smith { 1934b9ad928SBarry Smith PC_Shell *shell = (PC_Shell*)pc->data; 194dfbe8321SBarry Smith PetscErrorCode ierr; 1954b9ad928SBarry Smith 1964b9ad928SBarry Smith PetscFunctionBegin; 197503cfb0cSBarry Smith ierr = PetscFree(shell->name);CHKERRQ(ierr); 1982fa5cd67SKarl Rupp if (shell->destroy) PetscStackCall("PCSHELL user function destroy()",ierr = (*shell->destroy)(pc);CHKERRQ(ierr)); 199c31cb41cSBarry Smith ierr = PetscFree(pc->data);CHKERRQ(ierr); 2004b9ad928SBarry Smith PetscFunctionReturn(0); 2014b9ad928SBarry Smith } 2024b9ad928SBarry Smith 2034b9ad928SBarry Smith #undef __FUNCT__ 2044b9ad928SBarry Smith #define __FUNCT__ "PCView_Shell" 2056849ba73SBarry Smith static PetscErrorCode PCView_Shell(PC pc,PetscViewer viewer) 2064b9ad928SBarry Smith { 2074b9ad928SBarry Smith PC_Shell *shell = (PC_Shell*)pc->data; 208dfbe8321SBarry Smith PetscErrorCode ierr; 209ace3abfcSBarry Smith PetscBool iascii; 2104b9ad928SBarry Smith 2114b9ad928SBarry Smith PetscFunctionBegin; 212251f4c67SDmitry Karpeev ierr = PetscObjectTypeCompare((PetscObject)viewer,PETSCVIEWERASCII,&iascii);CHKERRQ(ierr); 21332077d6dSBarry Smith if (iascii) { 2142fa5cd67SKarl Rupp if (shell->name) { 2152fa5cd67SKarl Rupp ierr = PetscViewerASCIIPrintf(viewer," Shell: %s\n",shell->name);CHKERRQ(ierr); 2162fa5cd67SKarl Rupp } else { 2172fa5cd67SKarl Rupp ierr = PetscViewerASCIIPrintf(viewer," Shell: no name\n");CHKERRQ(ierr); 2182fa5cd67SKarl Rupp } 2194b9ad928SBarry Smith } 2204b9ad928SBarry Smith if (shell->view) { 2214b9ad928SBarry Smith ierr = PetscViewerASCIIPushTab(viewer);CHKERRQ(ierr); 2226891c3e4SJed Brown ierr = (*shell->view)(pc,viewer);CHKERRQ(ierr); 2234b9ad928SBarry Smith ierr = PetscViewerASCIIPopTab(viewer);CHKERRQ(ierr); 2244b9ad928SBarry Smith } 2254b9ad928SBarry Smith PetscFunctionReturn(0); 2264b9ad928SBarry Smith } 2274b9ad928SBarry Smith 2284b9ad928SBarry Smith /* ------------------------------------------------------------------------------*/ 2294b9ad928SBarry Smith #undef __FUNCT__ 23018be62a5SSatish Balay #define __FUNCT__ "PCShellSetDestroy_Shell" 231f7a08781SBarry Smith static PetscErrorCode PCShellSetDestroy_Shell(PC pc, PetscErrorCode (*destroy)(PC)) 23218be62a5SSatish Balay { 233c5ae4b9aSBarry Smith PC_Shell *shell= (PC_Shell*)pc->data; 23418be62a5SSatish Balay 23518be62a5SSatish Balay PetscFunctionBegin; 23618be62a5SSatish Balay shell->destroy = destroy; 23718be62a5SSatish Balay PetscFunctionReturn(0); 23818be62a5SSatish Balay } 23918be62a5SSatish Balay 24018be62a5SSatish Balay #undef __FUNCT__ 2414b9ad928SBarry Smith #define __FUNCT__ "PCShellSetSetUp_Shell" 242f7a08781SBarry Smith static PetscErrorCode PCShellSetSetUp_Shell(PC pc, PetscErrorCode (*setup)(PC)) 2434b9ad928SBarry Smith { 244c5ae4b9aSBarry Smith PC_Shell *shell = (PC_Shell*)pc->data;; 2454b9ad928SBarry Smith 2464b9ad928SBarry Smith PetscFunctionBegin; 2474b9ad928SBarry Smith shell->setup = setup; 248d01c8aa3SLisandro Dalcin if (setup) pc->ops->setup = PCSetUp_Shell; 249d01c8aa3SLisandro Dalcin else pc->ops->setup = 0; 2504b9ad928SBarry Smith PetscFunctionReturn(0); 2514b9ad928SBarry Smith } 2524b9ad928SBarry Smith 2534b9ad928SBarry Smith #undef __FUNCT__ 2544b9ad928SBarry Smith #define __FUNCT__ "PCShellSetApply_Shell" 255f7a08781SBarry Smith static PetscErrorCode PCShellSetApply_Shell(PC pc,PetscErrorCode (*apply)(PC,Vec,Vec)) 2564b9ad928SBarry Smith { 257c5ae4b9aSBarry Smith PC_Shell *shell = (PC_Shell*)pc->data; 2584b9ad928SBarry Smith 2594b9ad928SBarry Smith PetscFunctionBegin; 2604b9ad928SBarry Smith shell->apply = apply; 2614b9ad928SBarry Smith PetscFunctionReturn(0); 2624b9ad928SBarry Smith } 2634b9ad928SBarry Smith 2644b9ad928SBarry Smith #undef __FUNCT__ 2652bb17772SBarry Smith #define __FUNCT__ "PCShellSetApplyBA_Shell" 266f7a08781SBarry Smith static PetscErrorCode PCShellSetApplyBA_Shell(PC pc,PetscErrorCode (*applyBA)(PC,PCSide,Vec,Vec,Vec)) 2672bb17772SBarry Smith { 268c5ae4b9aSBarry Smith PC_Shell *shell = (PC_Shell*)pc->data; 2692bb17772SBarry Smith 2702bb17772SBarry Smith PetscFunctionBegin; 271d01c8aa3SLisandro Dalcin shell->applyBA = applyBA; 272d01c8aa3SLisandro Dalcin if (applyBA) pc->ops->applyBA = PCApplyBA_Shell; 273aef0136fSBarry Smith else pc->ops->applyBA = 0; 2742bb17772SBarry Smith PetscFunctionReturn(0); 2752bb17772SBarry Smith } 2762bb17772SBarry Smith 2772bb17772SBarry Smith #undef __FUNCT__ 2787cdd61b2SBarry Smith #define __FUNCT__ "PCShellSetPreSolve_Shell" 279f7a08781SBarry Smith static PetscErrorCode PCShellSetPreSolve_Shell(PC pc,PetscErrorCode (*presolve)(PC,KSP,Vec,Vec)) 2807cdd61b2SBarry Smith { 281c5ae4b9aSBarry Smith PC_Shell *shell = (PC_Shell*)pc->data; 2827cdd61b2SBarry Smith 2837cdd61b2SBarry Smith PetscFunctionBegin; 2847cdd61b2SBarry Smith shell->presolve = presolve; 285d01c8aa3SLisandro Dalcin if (presolve) pc->ops->presolve = PCPreSolve_Shell; 286d01c8aa3SLisandro Dalcin else pc->ops->presolve = 0; 2877cdd61b2SBarry Smith PetscFunctionReturn(0); 2887cdd61b2SBarry Smith } 2897cdd61b2SBarry Smith 2907cdd61b2SBarry Smith #undef __FUNCT__ 2917cdd61b2SBarry Smith #define __FUNCT__ "PCShellSetPostSolve_Shell" 292f7a08781SBarry Smith static PetscErrorCode PCShellSetPostSolve_Shell(PC pc,PetscErrorCode (*postsolve)(PC,KSP,Vec,Vec)) 2937cdd61b2SBarry Smith { 294c5ae4b9aSBarry Smith PC_Shell *shell = (PC_Shell*)pc->data; 2957cdd61b2SBarry Smith 2967cdd61b2SBarry Smith PetscFunctionBegin; 2977cdd61b2SBarry Smith shell->postsolve = postsolve; 298d01c8aa3SLisandro Dalcin if (postsolve) pc->ops->postsolve = PCPostSolve_Shell; 299d01c8aa3SLisandro Dalcin else pc->ops->postsolve = 0; 3007cdd61b2SBarry Smith PetscFunctionReturn(0); 3017cdd61b2SBarry Smith } 3027cdd61b2SBarry Smith 3037cdd61b2SBarry Smith #undef __FUNCT__ 3044b9ad928SBarry Smith #define __FUNCT__ "PCShellSetView_Shell" 305f7a08781SBarry Smith static PetscErrorCode PCShellSetView_Shell(PC pc,PetscErrorCode (*view)(PC,PetscViewer)) 3064b9ad928SBarry Smith { 307c5ae4b9aSBarry Smith PC_Shell *shell = (PC_Shell*)pc->data; 3084b9ad928SBarry Smith 3094b9ad928SBarry Smith PetscFunctionBegin; 3104b9ad928SBarry Smith shell->view = view; 3114b9ad928SBarry Smith PetscFunctionReturn(0); 3124b9ad928SBarry Smith } 3134b9ad928SBarry Smith 3144b9ad928SBarry Smith #undef __FUNCT__ 3154b9ad928SBarry Smith #define __FUNCT__ "PCShellSetApplyTranspose_Shell" 316f7a08781SBarry Smith static PetscErrorCode PCShellSetApplyTranspose_Shell(PC pc,PetscErrorCode (*applytranspose)(PC,Vec,Vec)) 3174b9ad928SBarry Smith { 318c5ae4b9aSBarry Smith PC_Shell *shell = (PC_Shell*)pc->data; 3194b9ad928SBarry Smith 3204b9ad928SBarry Smith PetscFunctionBegin; 3214b9ad928SBarry Smith shell->applytranspose = applytranspose; 322d01c8aa3SLisandro Dalcin if (applytranspose) pc->ops->applytranspose = PCApplyTranspose_Shell; 323d01c8aa3SLisandro Dalcin else pc->ops->applytranspose = 0; 324d01c8aa3SLisandro Dalcin PetscFunctionReturn(0); 325d01c8aa3SLisandro Dalcin } 326d01c8aa3SLisandro Dalcin 327d01c8aa3SLisandro Dalcin #undef __FUNCT__ 328d01c8aa3SLisandro Dalcin #define __FUNCT__ "PCShellSetApplyRichardson_Shell" 329f7a08781SBarry Smith static PetscErrorCode PCShellSetApplyRichardson_Shell(PC pc,PetscErrorCode (*applyrich)(PC,Vec,Vec,Vec,PetscReal,PetscReal,PetscReal,PetscInt,PetscBool ,PetscInt*,PCRichardsonConvergedReason*)) 330d01c8aa3SLisandro Dalcin { 331c5ae4b9aSBarry Smith PC_Shell *shell = (PC_Shell*)pc->data; 332d01c8aa3SLisandro Dalcin 333d01c8aa3SLisandro Dalcin PetscFunctionBegin; 334d01c8aa3SLisandro Dalcin shell->applyrich = applyrich; 335d01c8aa3SLisandro Dalcin if (applyrich) pc->ops->applyrichardson = PCApplyRichardson_Shell; 336d01c8aa3SLisandro Dalcin else pc->ops->applyrichardson = 0; 3374b9ad928SBarry Smith PetscFunctionReturn(0); 3384b9ad928SBarry Smith } 3394b9ad928SBarry Smith 3404b9ad928SBarry Smith #undef __FUNCT__ 3414b9ad928SBarry Smith #define __FUNCT__ "PCShellSetName_Shell" 342f7a08781SBarry Smith static PetscErrorCode PCShellSetName_Shell(PC pc,const char name[]) 3434b9ad928SBarry Smith { 344c5ae4b9aSBarry Smith PC_Shell *shell = (PC_Shell*)pc->data; 345dfbe8321SBarry Smith PetscErrorCode ierr; 3464b9ad928SBarry Smith 3474b9ad928SBarry Smith PetscFunctionBegin; 348503cfb0cSBarry Smith ierr = PetscFree(shell->name);CHKERRQ(ierr); 3494b9ad928SBarry Smith ierr = PetscStrallocpy(name,&shell->name);CHKERRQ(ierr); 3504b9ad928SBarry Smith PetscFunctionReturn(0); 3514b9ad928SBarry Smith } 3524b9ad928SBarry Smith 3534b9ad928SBarry Smith #undef __FUNCT__ 3544b9ad928SBarry Smith #define __FUNCT__ "PCShellGetName_Shell" 355f7a08781SBarry Smith static PetscErrorCode PCShellGetName_Shell(PC pc,const char *name[]) 3564b9ad928SBarry Smith { 357c5ae4b9aSBarry Smith PC_Shell *shell = (PC_Shell*)pc->data; 3584b9ad928SBarry Smith 3594b9ad928SBarry Smith PetscFunctionBegin; 3604b9ad928SBarry Smith *name = shell->name; 3614b9ad928SBarry Smith PetscFunctionReturn(0); 3624b9ad928SBarry Smith } 3634b9ad928SBarry Smith 3644b9ad928SBarry Smith /* -------------------------------------------------------------------------------*/ 3654b9ad928SBarry Smith 3664b9ad928SBarry Smith #undef __FUNCT__ 36718be62a5SSatish Balay #define __FUNCT__ "PCShellSetDestroy" 36818be62a5SSatish Balay /*@C 36918be62a5SSatish Balay PCShellSetDestroy - Sets routine to use to destroy the user-provided 37018be62a5SSatish Balay application context. 37118be62a5SSatish Balay 3723f9fe445SBarry Smith Logically Collective on PC 37318be62a5SSatish Balay 37418be62a5SSatish Balay Input Parameters: 37518be62a5SSatish Balay + pc - the preconditioner context 37618be62a5SSatish Balay . destroy - the application-provided destroy routine 37718be62a5SSatish Balay 37818be62a5SSatish Balay Calling sequence of destroy: 37918be62a5SSatish Balay .vb 3806891c3e4SJed Brown PetscErrorCode destroy (PC) 38118be62a5SSatish Balay .ve 38218be62a5SSatish Balay 38318be62a5SSatish Balay . ptr - the application context 38418be62a5SSatish Balay 3854aa34b0aSBarry Smith Notes: the function MUST return an error code of 0 on success and nonzero on failure. 3864aa34b0aSBarry Smith 38718be62a5SSatish Balay Level: developer 38818be62a5SSatish Balay 38918be62a5SSatish Balay .keywords: PC, shell, set, destroy, user-provided 39018be62a5SSatish Balay 39118be62a5SSatish Balay .seealso: PCShellSetApply(), PCShellSetContext() 39218be62a5SSatish Balay @*/ 3937087cfbeSBarry Smith PetscErrorCode PCShellSetDestroy(PC pc,PetscErrorCode (*destroy)(PC)) 39418be62a5SSatish Balay { 3954ac538c5SBarry Smith PetscErrorCode ierr; 39618be62a5SSatish Balay 39718be62a5SSatish Balay PetscFunctionBegin; 3980700a824SBarry Smith PetscValidHeaderSpecific(pc,PC_CLASSID,1); 3994ac538c5SBarry Smith ierr = PetscTryMethod(pc,"PCShellSetDestroy_C",(PC,PetscErrorCode (*)(PC)),(pc,destroy));CHKERRQ(ierr); 40018be62a5SSatish Balay PetscFunctionReturn(0); 40118be62a5SSatish Balay } 40218be62a5SSatish Balay 40318be62a5SSatish Balay 40418be62a5SSatish Balay #undef __FUNCT__ 4054b9ad928SBarry Smith #define __FUNCT__ "PCShellSetSetUp" 4064b9ad928SBarry Smith /*@C 4074b9ad928SBarry Smith PCShellSetSetUp - Sets routine to use to "setup" the preconditioner whenever the 4084b9ad928SBarry Smith matrix operator is changed. 4094b9ad928SBarry Smith 4103f9fe445SBarry Smith Logically Collective on PC 4114b9ad928SBarry Smith 4124b9ad928SBarry Smith Input Parameters: 4134b9ad928SBarry Smith + pc - the preconditioner context 4144b9ad928SBarry Smith . setup - the application-provided setup routine 4154b9ad928SBarry Smith 4164b9ad928SBarry Smith Calling sequence of setup: 4174b9ad928SBarry Smith .vb 4186891c3e4SJed Brown PetscErrorCode setup (PC pc) 4194b9ad928SBarry Smith .ve 4204b9ad928SBarry Smith 4216891c3e4SJed Brown . pc - the preconditioner, get the application context with PCShellGetContext() 4224b9ad928SBarry Smith 4234aa34b0aSBarry Smith Notes: the function MUST return an error code of 0 on success and nonzero on failure. 4244aa34b0aSBarry Smith 4254b9ad928SBarry Smith Level: developer 4264b9ad928SBarry Smith 4274b9ad928SBarry Smith .keywords: PC, shell, set, setup, user-provided 4284b9ad928SBarry Smith 429be29d3c6SBarry Smith .seealso: PCShellSetApplyRichardson(), PCShellSetApply(), PCShellSetContext() 4304b9ad928SBarry Smith @*/ 4317087cfbeSBarry Smith PetscErrorCode PCShellSetSetUp(PC pc,PetscErrorCode (*setup)(PC)) 4324b9ad928SBarry Smith { 4334ac538c5SBarry Smith PetscErrorCode ierr; 4344b9ad928SBarry Smith 4354b9ad928SBarry Smith PetscFunctionBegin; 4360700a824SBarry Smith PetscValidHeaderSpecific(pc,PC_CLASSID,1); 4374ac538c5SBarry Smith ierr = PetscTryMethod(pc,"PCShellSetSetUp_C",(PC,PetscErrorCode (*)(PC)),(pc,setup));CHKERRQ(ierr); 4384b9ad928SBarry Smith PetscFunctionReturn(0); 4394b9ad928SBarry Smith } 4404b9ad928SBarry Smith 4414b9ad928SBarry Smith 4424b9ad928SBarry Smith #undef __FUNCT__ 4434b9ad928SBarry Smith #define __FUNCT__ "PCShellSetView" 4444b9ad928SBarry Smith /*@C 4454b9ad928SBarry Smith PCShellSetView - Sets routine to use as viewer of shell preconditioner 4464b9ad928SBarry Smith 4473f9fe445SBarry Smith Logically Collective on PC 4484b9ad928SBarry Smith 4494b9ad928SBarry Smith Input Parameters: 4504b9ad928SBarry Smith + pc - the preconditioner context 4514b9ad928SBarry Smith - view - the application-provided view routine 4524b9ad928SBarry Smith 4534b9ad928SBarry Smith Calling sequence of apply: 4544b9ad928SBarry Smith .vb 4556891c3e4SJed Brown PetscErrorCode view(PC pc,PetscViewer v) 4564b9ad928SBarry Smith .ve 4574b9ad928SBarry Smith 4586891c3e4SJed Brown + pc - the preconditioner, get the application context with PCShellGetContext() 4594b9ad928SBarry Smith - v - viewer 4604b9ad928SBarry Smith 4614aa34b0aSBarry Smith Notes: the function MUST return an error code of 0 on success and nonzero on failure. 4624aa34b0aSBarry Smith 4634b9ad928SBarry Smith Level: developer 4644b9ad928SBarry Smith 4654b9ad928SBarry Smith .keywords: PC, shell, set, apply, user-provided 4664b9ad928SBarry Smith 4674b9ad928SBarry Smith .seealso: PCShellSetApplyRichardson(), PCShellSetSetUp(), PCShellSetApplyTranspose() 4684b9ad928SBarry Smith @*/ 4697087cfbeSBarry Smith PetscErrorCode PCShellSetView(PC pc,PetscErrorCode (*view)(PC,PetscViewer)) 4704b9ad928SBarry Smith { 4714ac538c5SBarry Smith PetscErrorCode ierr; 4724b9ad928SBarry Smith 4734b9ad928SBarry Smith PetscFunctionBegin; 4740700a824SBarry Smith PetscValidHeaderSpecific(pc,PC_CLASSID,1); 4754ac538c5SBarry Smith ierr = PetscTryMethod(pc,"PCShellSetView_C",(PC,PetscErrorCode (*)(PC,PetscViewer)),(pc,view));CHKERRQ(ierr); 4764b9ad928SBarry Smith PetscFunctionReturn(0); 4774b9ad928SBarry Smith } 4784b9ad928SBarry Smith 4794b9ad928SBarry Smith #undef __FUNCT__ 4804b9ad928SBarry Smith #define __FUNCT__ "PCShellSetApply" 4814b9ad928SBarry Smith /*@C 4824b9ad928SBarry Smith PCShellSetApply - Sets routine to use as preconditioner. 4834b9ad928SBarry Smith 4843f9fe445SBarry Smith Logically Collective on PC 4854b9ad928SBarry Smith 4864b9ad928SBarry Smith Input Parameters: 4874b9ad928SBarry Smith + pc - the preconditioner context 488be29d3c6SBarry Smith - apply - the application-provided preconditioning routine 4894b9ad928SBarry Smith 4904b9ad928SBarry Smith Calling sequence of apply: 4914b9ad928SBarry Smith .vb 4926891c3e4SJed Brown PetscErrorCode apply (PC pc,Vec xin,Vec xout) 4934b9ad928SBarry Smith .ve 4944b9ad928SBarry Smith 4956891c3e4SJed Brown + pc - the preconditioner, get the application context with PCShellGetContext() 4964b9ad928SBarry Smith . xin - input vector 4974b9ad928SBarry Smith - xout - output vector 4984b9ad928SBarry Smith 4994aa34b0aSBarry Smith Notes: the function MUST return an error code of 0 on success and nonzero on failure. 5004aa34b0aSBarry Smith 501292fb18eSBarry Smith Developer Notes: There should also be a PCShellSetApplySymmetricRight() and PCShellSetApplySymmetricLeft(). 502292fb18eSBarry Smith 5034b9ad928SBarry Smith Level: developer 5044b9ad928SBarry Smith 5054b9ad928SBarry Smith .keywords: PC, shell, set, apply, user-provided 5064b9ad928SBarry Smith 5072bb17772SBarry Smith .seealso: PCShellSetApplyRichardson(), PCShellSetSetUp(), PCShellSetApplyTranspose(), PCShellSetContext(), PCShellSetApplyBA() 5084b9ad928SBarry Smith @*/ 5097087cfbeSBarry Smith PetscErrorCode PCShellSetApply(PC pc,PetscErrorCode (*apply)(PC,Vec,Vec)) 5104b9ad928SBarry Smith { 5114ac538c5SBarry Smith PetscErrorCode ierr; 5124b9ad928SBarry Smith 5134b9ad928SBarry Smith PetscFunctionBegin; 5140700a824SBarry Smith PetscValidHeaderSpecific(pc,PC_CLASSID,1); 5154ac538c5SBarry Smith ierr = PetscTryMethod(pc,"PCShellSetApply_C",(PC,PetscErrorCode (*)(PC,Vec,Vec)),(pc,apply));CHKERRQ(ierr); 5164b9ad928SBarry Smith PetscFunctionReturn(0); 5174b9ad928SBarry Smith } 5184b9ad928SBarry Smith 5194b9ad928SBarry Smith #undef __FUNCT__ 5202bb17772SBarry Smith #define __FUNCT__ "PCShellSetApplyBA" 5212bb17772SBarry Smith /*@C 5222bb17772SBarry Smith PCShellSetApplyBA - Sets routine to use as preconditioner times operator. 5232bb17772SBarry Smith 5243f9fe445SBarry Smith Logically Collective on PC 5252bb17772SBarry Smith 5262bb17772SBarry Smith Input Parameters: 5272bb17772SBarry Smith + pc - the preconditioner context 5282bb17772SBarry Smith - applyBA - the application-provided BA routine 5292bb17772SBarry Smith 5302bb17772SBarry Smith Calling sequence of apply: 5312bb17772SBarry Smith .vb 5326891c3e4SJed Brown PetscErrorCode applyBA (PC pc,Vec xin,Vec xout) 5332bb17772SBarry Smith .ve 5342bb17772SBarry Smith 5356891c3e4SJed Brown + pc - the preconditioner, get the application context with PCShellGetContext() 5362bb17772SBarry Smith . xin - input vector 5372bb17772SBarry Smith - xout - output vector 5382bb17772SBarry Smith 5394aa34b0aSBarry Smith Notes: the function MUST return an error code of 0 on success and nonzero on failure. 5404aa34b0aSBarry Smith 5412bb17772SBarry Smith Level: developer 5422bb17772SBarry Smith 5432bb17772SBarry Smith .keywords: PC, shell, set, apply, user-provided 5442bb17772SBarry Smith 5452bb17772SBarry Smith .seealso: PCShellSetApplyRichardson(), PCShellSetSetUp(), PCShellSetApplyTranspose(), PCShellSetContext(), PCShellSetApply() 5462bb17772SBarry Smith @*/ 5477087cfbeSBarry Smith PetscErrorCode PCShellSetApplyBA(PC pc,PetscErrorCode (*applyBA)(PC,PCSide,Vec,Vec,Vec)) 5482bb17772SBarry Smith { 5494ac538c5SBarry Smith PetscErrorCode ierr; 5502bb17772SBarry Smith 5512bb17772SBarry Smith PetscFunctionBegin; 5520700a824SBarry Smith PetscValidHeaderSpecific(pc,PC_CLASSID,1); 5534ac538c5SBarry Smith ierr = PetscTryMethod(pc,"PCShellSetApplyBA_C",(PC,PetscErrorCode (*)(PC,PCSide,Vec,Vec,Vec)),(pc,applyBA));CHKERRQ(ierr); 5542bb17772SBarry Smith PetscFunctionReturn(0); 5552bb17772SBarry Smith } 5562bb17772SBarry Smith 5572bb17772SBarry Smith #undef __FUNCT__ 5584b9ad928SBarry Smith #define __FUNCT__ "PCShellSetApplyTranspose" 5594b9ad928SBarry Smith /*@C 5604b9ad928SBarry Smith PCShellSetApplyTranspose - Sets routine to use as preconditioner transpose. 5614b9ad928SBarry Smith 5623f9fe445SBarry Smith Logically Collective on PC 5634b9ad928SBarry Smith 5644b9ad928SBarry Smith Input Parameters: 5654b9ad928SBarry Smith + pc - the preconditioner context 5664b9ad928SBarry Smith - apply - the application-provided preconditioning transpose routine 5674b9ad928SBarry Smith 5684b9ad928SBarry Smith Calling sequence of apply: 5694b9ad928SBarry Smith .vb 5706891c3e4SJed Brown PetscErrorCode applytranspose (PC pc,Vec xin,Vec xout) 5714b9ad928SBarry Smith .ve 5724b9ad928SBarry Smith 5736891c3e4SJed Brown + pc - the preconditioner, get the application context with PCShellGetContext() 5744b9ad928SBarry Smith . xin - input vector 5754b9ad928SBarry Smith - xout - output vector 5764b9ad928SBarry Smith 5774aa34b0aSBarry Smith Notes: the function MUST return an error code of 0 on success and nonzero on failure. 5784aa34b0aSBarry Smith 5794b9ad928SBarry Smith Level: developer 5804b9ad928SBarry Smith 5814b9ad928SBarry Smith Notes: 5824b9ad928SBarry Smith Uses the same context variable as PCShellSetApply(). 5834b9ad928SBarry Smith 5844b9ad928SBarry Smith .keywords: PC, shell, set, apply, user-provided 5854b9ad928SBarry Smith 5862bb17772SBarry Smith .seealso: PCShellSetApplyRichardson(), PCShellSetSetUp(), PCShellSetApply(), PCSetContext(), PCShellSetApplyBA() 5874b9ad928SBarry Smith @*/ 5887087cfbeSBarry Smith PetscErrorCode PCShellSetApplyTranspose(PC pc,PetscErrorCode (*applytranspose)(PC,Vec,Vec)) 5894b9ad928SBarry Smith { 5904ac538c5SBarry Smith PetscErrorCode ierr; 5914b9ad928SBarry Smith 5924b9ad928SBarry Smith PetscFunctionBegin; 5930700a824SBarry Smith PetscValidHeaderSpecific(pc,PC_CLASSID,1); 5944ac538c5SBarry Smith ierr = PetscTryMethod(pc,"PCShellSetApplyTranspose_C",(PC,PetscErrorCode (*)(PC,Vec,Vec)),(pc,applytranspose));CHKERRQ(ierr); 5954b9ad928SBarry Smith PetscFunctionReturn(0); 5964b9ad928SBarry Smith } 5974b9ad928SBarry Smith 5984b9ad928SBarry Smith #undef __FUNCT__ 5997cdd61b2SBarry Smith #define __FUNCT__ "PCShellSetPreSolve" 6007cdd61b2SBarry Smith /*@C 6017cdd61b2SBarry Smith PCShellSetPreSolve - Sets routine to apply to the operators/vectors before a KSPSolve() is 6027cdd61b2SBarry Smith applied. This usually does something like scale the linear system in some application 6037cdd61b2SBarry Smith specific way. 6047cdd61b2SBarry Smith 6053f9fe445SBarry Smith Logically Collective on PC 6067cdd61b2SBarry Smith 6077cdd61b2SBarry Smith Input Parameters: 6087cdd61b2SBarry Smith + pc - the preconditioner context 6097cdd61b2SBarry Smith - presolve - the application-provided presolve routine 6107cdd61b2SBarry Smith 6117cdd61b2SBarry Smith Calling sequence of presolve: 6127cdd61b2SBarry Smith .vb 6136891c3e4SJed Brown PetscErrorCode presolve (PC,KSP ksp,Vec b,Vec x) 6147cdd61b2SBarry Smith .ve 6157cdd61b2SBarry Smith 6166891c3e4SJed Brown + pc - the preconditioner, get the application context with PCShellGetContext() 6177cdd61b2SBarry Smith . xin - input vector 6187cdd61b2SBarry Smith - xout - output vector 6197cdd61b2SBarry Smith 6204aa34b0aSBarry Smith Notes: the function MUST return an error code of 0 on success and nonzero on failure. 6214aa34b0aSBarry Smith 6227cdd61b2SBarry Smith Level: developer 6237cdd61b2SBarry Smith 6247cdd61b2SBarry Smith .keywords: PC, shell, set, apply, user-provided 6257cdd61b2SBarry Smith 626be29d3c6SBarry Smith .seealso: PCShellSetApplyRichardson(), PCShellSetSetUp(), PCShellSetApplyTranspose(), PCShellSetPostSolve(), PCShellSetContext() 6277cdd61b2SBarry Smith @*/ 6287087cfbeSBarry Smith PetscErrorCode PCShellSetPreSolve(PC pc,PetscErrorCode (*presolve)(PC,KSP,Vec,Vec)) 6297cdd61b2SBarry Smith { 6304ac538c5SBarry Smith PetscErrorCode ierr; 6317cdd61b2SBarry Smith 6327cdd61b2SBarry Smith PetscFunctionBegin; 6330700a824SBarry Smith PetscValidHeaderSpecific(pc,PC_CLASSID,1); 6344ac538c5SBarry Smith ierr = PetscTryMethod(pc,"PCShellSetPreSolve_C",(PC,PetscErrorCode (*)(PC,KSP,Vec,Vec)),(pc,presolve));CHKERRQ(ierr); 6357cdd61b2SBarry Smith PetscFunctionReturn(0); 6367cdd61b2SBarry Smith } 6377cdd61b2SBarry Smith 6387cdd61b2SBarry Smith #undef __FUNCT__ 6397cdd61b2SBarry Smith #define __FUNCT__ "PCShellSetPostSolve" 6407cdd61b2SBarry Smith /*@C 6417cdd61b2SBarry Smith PCShellSetPostSolve - Sets routine to apply to the operators/vectors before a KSPSolve() is 6427cdd61b2SBarry Smith applied. This usually does something like scale the linear system in some application 6437cdd61b2SBarry Smith specific way. 6447cdd61b2SBarry Smith 6453f9fe445SBarry Smith Logically Collective on PC 6467cdd61b2SBarry Smith 6477cdd61b2SBarry Smith Input Parameters: 6487cdd61b2SBarry Smith + pc - the preconditioner context 6497cdd61b2SBarry Smith - postsolve - the application-provided presolve routine 6507cdd61b2SBarry Smith 6517cdd61b2SBarry Smith Calling sequence of postsolve: 6527cdd61b2SBarry Smith .vb 6536891c3e4SJed Brown PetscErrorCode postsolve(PC,KSP ksp,Vec b,Vec x) 6547cdd61b2SBarry Smith .ve 6557cdd61b2SBarry Smith 6566891c3e4SJed Brown + pc - the preconditioner, get the application context with PCShellGetContext() 6577cdd61b2SBarry Smith . xin - input vector 6587cdd61b2SBarry Smith - xout - output vector 6597cdd61b2SBarry Smith 6604aa34b0aSBarry Smith Notes: the function MUST return an error code of 0 on success and nonzero on failure. 6614aa34b0aSBarry Smith 6627cdd61b2SBarry Smith Level: developer 6637cdd61b2SBarry Smith 6647cdd61b2SBarry Smith .keywords: PC, shell, set, apply, user-provided 6657cdd61b2SBarry Smith 666be29d3c6SBarry Smith .seealso: PCShellSetApplyRichardson(), PCShellSetSetUp(), PCShellSetApplyTranspose(), PCShellSetPreSolve(), PCShellSetContext() 6677cdd61b2SBarry Smith @*/ 6687087cfbeSBarry Smith PetscErrorCode PCShellSetPostSolve(PC pc,PetscErrorCode (*postsolve)(PC,KSP,Vec,Vec)) 6697cdd61b2SBarry Smith { 6704ac538c5SBarry Smith PetscErrorCode ierr; 6717cdd61b2SBarry Smith 6727cdd61b2SBarry Smith PetscFunctionBegin; 6730700a824SBarry Smith PetscValidHeaderSpecific(pc,PC_CLASSID,1); 6744ac538c5SBarry Smith ierr = PetscTryMethod(pc,"PCShellSetPostSolve_C",(PC,PetscErrorCode (*)(PC,KSP,Vec,Vec)),(pc,postsolve));CHKERRQ(ierr); 6757cdd61b2SBarry Smith PetscFunctionReturn(0); 6767cdd61b2SBarry Smith } 6777cdd61b2SBarry Smith 6787cdd61b2SBarry Smith #undef __FUNCT__ 6794b9ad928SBarry Smith #define __FUNCT__ "PCShellSetName" 6804b9ad928SBarry Smith /*@C 6814b9ad928SBarry Smith PCShellSetName - Sets an optional name to associate with a shell 6824b9ad928SBarry Smith preconditioner. 6834b9ad928SBarry Smith 6844b9ad928SBarry Smith Not Collective 6854b9ad928SBarry Smith 6864b9ad928SBarry Smith Input Parameters: 6874b9ad928SBarry Smith + pc - the preconditioner context 6884b9ad928SBarry Smith - name - character string describing shell preconditioner 6894b9ad928SBarry Smith 6904b9ad928SBarry Smith Level: developer 6914b9ad928SBarry Smith 6924b9ad928SBarry Smith .keywords: PC, shell, set, name, user-provided 6934b9ad928SBarry Smith 6944b9ad928SBarry Smith .seealso: PCShellGetName() 6954b9ad928SBarry Smith @*/ 6967087cfbeSBarry Smith PetscErrorCode PCShellSetName(PC pc,const char name[]) 6974b9ad928SBarry Smith { 6984ac538c5SBarry Smith PetscErrorCode ierr; 6994b9ad928SBarry Smith 7004b9ad928SBarry Smith PetscFunctionBegin; 7010700a824SBarry Smith PetscValidHeaderSpecific(pc,PC_CLASSID,1); 7024ac538c5SBarry Smith ierr = PetscTryMethod(pc,"PCShellSetName_C",(PC,const char []),(pc,name));CHKERRQ(ierr); 7034b9ad928SBarry Smith PetscFunctionReturn(0); 7044b9ad928SBarry Smith } 7054b9ad928SBarry Smith 7064b9ad928SBarry Smith #undef __FUNCT__ 7074b9ad928SBarry Smith #define __FUNCT__ "PCShellGetName" 7084b9ad928SBarry Smith /*@C 7094b9ad928SBarry Smith PCShellGetName - Gets an optional name that the user has set for a shell 7104b9ad928SBarry Smith preconditioner. 7114b9ad928SBarry Smith 7124b9ad928SBarry Smith Not Collective 7134b9ad928SBarry Smith 7144b9ad928SBarry Smith Input Parameter: 7154b9ad928SBarry Smith . pc - the preconditioner context 7164b9ad928SBarry Smith 7174b9ad928SBarry Smith Output Parameter: 7184b9ad928SBarry Smith . name - character string describing shell preconditioner (you should not free this) 7194b9ad928SBarry Smith 7204b9ad928SBarry Smith Level: developer 7214b9ad928SBarry Smith 7224b9ad928SBarry Smith .keywords: PC, shell, get, name, user-provided 7234b9ad928SBarry Smith 7244b9ad928SBarry Smith .seealso: PCShellSetName() 7254b9ad928SBarry Smith @*/ 726ccaf0856SBarry Smith PetscErrorCode PCShellGetName(PC pc,const char *name[]) 7274b9ad928SBarry Smith { 7284ac538c5SBarry Smith PetscErrorCode ierr; 7294b9ad928SBarry Smith 7304b9ad928SBarry Smith PetscFunctionBegin; 7310700a824SBarry Smith PetscValidHeaderSpecific(pc,PC_CLASSID,1); 7324482741eSBarry Smith PetscValidPointer(name,2); 733ccaf0856SBarry Smith ierr = PetscUseMethod(pc,"PCShellGetName_C",(PC,const char*[]),(pc,name));CHKERRQ(ierr); 7344b9ad928SBarry Smith PetscFunctionReturn(0); 7354b9ad928SBarry Smith } 7364b9ad928SBarry Smith 7374b9ad928SBarry Smith #undef __FUNCT__ 7384b9ad928SBarry Smith #define __FUNCT__ "PCShellSetApplyRichardson" 7394b9ad928SBarry Smith /*@C 7404b9ad928SBarry Smith PCShellSetApplyRichardson - Sets routine to use as preconditioner 7414b9ad928SBarry Smith in Richardson iteration. 7424b9ad928SBarry Smith 7433f9fe445SBarry Smith Logically Collective on PC 7444b9ad928SBarry Smith 7454b9ad928SBarry Smith Input Parameters: 7464b9ad928SBarry Smith + pc - the preconditioner context 747be29d3c6SBarry Smith - apply - the application-provided preconditioning routine 7484b9ad928SBarry Smith 7494b9ad928SBarry Smith Calling sequence of apply: 7504b9ad928SBarry Smith .vb 7516891c3e4SJed Brown PetscErrorCode apply (PC pc,Vec b,Vec x,Vec r,PetscReal rtol,PetscReal abstol,PetscReal dtol,PetscInt maxits) 7524b9ad928SBarry Smith .ve 7534b9ad928SBarry Smith 7546891c3e4SJed Brown + pc - the preconditioner, get the application context with PCShellGetContext() 7554b9ad928SBarry Smith . b - right-hand-side 7564b9ad928SBarry Smith . x - current iterate 7574b9ad928SBarry Smith . r - work space 7584b9ad928SBarry Smith . rtol - relative tolerance of residual norm to stop at 75970441072SBarry Smith . abstol - absolute tolerance of residual norm to stop at 7604b9ad928SBarry Smith . dtol - if residual norm increases by this factor than return 7614b9ad928SBarry Smith - maxits - number of iterations to run 7624b9ad928SBarry Smith 7634aa34b0aSBarry Smith Notes: the function MUST return an error code of 0 on success and nonzero on failure. 7644aa34b0aSBarry Smith 7654b9ad928SBarry Smith Level: developer 7664b9ad928SBarry Smith 7674b9ad928SBarry Smith .keywords: PC, shell, set, apply, Richardson, user-provided 7684b9ad928SBarry Smith 769be29d3c6SBarry Smith .seealso: PCShellSetApply(), PCShellSetContext() 7704b9ad928SBarry Smith @*/ 7717087cfbeSBarry Smith PetscErrorCode PCShellSetApplyRichardson(PC pc,PetscErrorCode (*apply)(PC,Vec,Vec,Vec,PetscReal,PetscReal,PetscReal,PetscInt,PetscBool,PetscInt*,PCRichardsonConvergedReason*)) 7724b9ad928SBarry Smith { 7734ac538c5SBarry Smith PetscErrorCode ierr; 7744b9ad928SBarry Smith 7754b9ad928SBarry Smith PetscFunctionBegin; 7760700a824SBarry Smith PetscValidHeaderSpecific(pc,PC_CLASSID,1); 7774ac538c5SBarry Smith ierr = PetscTryMethod(pc,"PCShellSetApplyRichardson_C",(PC,PetscErrorCode (*)(PC,Vec,Vec,Vec,PetscReal,PetscReal,PetscReal,PetscInt,PetscBool,PetscInt*,PCRichardsonConvergedReason*)),(pc,apply));CHKERRQ(ierr); 7784b9ad928SBarry Smith PetscFunctionReturn(0); 7794b9ad928SBarry Smith } 7804b9ad928SBarry Smith 7814b9ad928SBarry Smith /*MC 7824b9ad928SBarry Smith PCSHELL - Creates a new preconditioner class for use with your 7834b9ad928SBarry Smith own private data storage format. 7844b9ad928SBarry Smith 7854b9ad928SBarry Smith Level: advanced 78690198e61SBarry Smith > 7874b9ad928SBarry Smith Concepts: providing your own preconditioner 7884b9ad928SBarry Smith 7894b9ad928SBarry Smith Usage: 7906891c3e4SJed Brown $ extern PetscErrorCode apply(PC,Vec,Vec); 7916891c3e4SJed Brown $ extern PetscErrorCode applyba(PC,PCSide,Vec,Vec,Vec); 7926891c3e4SJed Brown $ extern PetscErrorCode applytranspose(PC,Vec,Vec); 7936891c3e4SJed Brown $ extern PetscErrorCode setup(PC); 7946891c3e4SJed Brown $ extern PetscErrorCode destroy(PC); 7956891c3e4SJed Brown $ 7964b9ad928SBarry Smith $ PCCreate(comm,&pc); 7974b9ad928SBarry Smith $ PCSetType(pc,PCSHELL); 798be29d3c6SBarry Smith $ PCShellSetContext(pc,ctx) 7996891c3e4SJed Brown $ PCShellSetApply(pc,apply); 8006891c3e4SJed Brown $ PCShellSetApplyBA(pc,applyba); (optional) 8016891c3e4SJed Brown $ PCShellSetApplyTranspose(pc,applytranspose); (optional) 8024b9ad928SBarry Smith $ PCShellSetSetUp(pc,setup); (optional) 803d01c8aa3SLisandro Dalcin $ PCShellSetDestroy(pc,destroy); (optional) 8044b9ad928SBarry Smith 8054b9ad928SBarry Smith .seealso: PCCreate(), PCSetType(), PCType (for list of available types), PC, 806fd2d0fe1Svictor MATSHELL, PCShellSetSetUp(), PCShellSetApply(), PCShellSetView(), 807fd2d0fe1Svictor PCShellSetApplyTranspose(), PCShellSetName(), PCShellSetApplyRichardson(), 8082bb17772SBarry Smith PCShellGetName(), PCShellSetContext(), PCShellGetContext(), PCShellSetApplyBA() 8094b9ad928SBarry Smith M*/ 8104b9ad928SBarry Smith 8114b9ad928SBarry Smith #undef __FUNCT__ 8124b9ad928SBarry Smith #define __FUNCT__ "PCCreate_Shell" 8138cc058d9SJed Brown PETSC_EXTERN PetscErrorCode PCCreate_Shell(PC pc) 8144b9ad928SBarry Smith { 815dfbe8321SBarry Smith PetscErrorCode ierr; 8164b9ad928SBarry Smith PC_Shell *shell; 8174b9ad928SBarry Smith 8184b9ad928SBarry Smith PetscFunctionBegin; 819b00a9115SJed Brown ierr = PetscNewLog(pc,&shell);CHKERRQ(ierr); 8204b9ad928SBarry Smith pc->data = (void*)shell; 8214b9ad928SBarry Smith 822d01c8aa3SLisandro Dalcin pc->ops->destroy = PCDestroy_Shell; 8234b9ad928SBarry Smith pc->ops->view = PCView_Shell; 824d01c8aa3SLisandro Dalcin pc->ops->apply = PCApply_Shell; 825d01c8aa3SLisandro Dalcin pc->ops->applytranspose = 0; 8264b9ad928SBarry Smith pc->ops->applyrichardson = 0; 827d01c8aa3SLisandro Dalcin pc->ops->setup = 0; 8289bbb2c88SBarry Smith pc->ops->presolve = 0; 8299bbb2c88SBarry Smith pc->ops->postsolve = 0; 8304b9ad928SBarry Smith 8314b9ad928SBarry Smith shell->apply = 0; 8324b9ad928SBarry Smith shell->applytranspose = 0; 8334b9ad928SBarry Smith shell->name = 0; 8344b9ad928SBarry Smith shell->applyrich = 0; 8357cdd61b2SBarry Smith shell->presolve = 0; 8367cdd61b2SBarry Smith shell->postsolve = 0; 8374b9ad928SBarry Smith shell->ctx = 0; 8384b9ad928SBarry Smith shell->setup = 0; 8394b9ad928SBarry Smith shell->view = 0; 84018be62a5SSatish Balay shell->destroy = 0; 8414b9ad928SBarry Smith 842bdf89e91SBarry Smith ierr = PetscObjectComposeFunction((PetscObject)pc,"PCShellSetDestroy_C",PCShellSetDestroy_Shell);CHKERRQ(ierr); 843bdf89e91SBarry Smith ierr = PetscObjectComposeFunction((PetscObject)pc,"PCShellSetSetUp_C",PCShellSetSetUp_Shell);CHKERRQ(ierr); 844bdf89e91SBarry Smith ierr = PetscObjectComposeFunction((PetscObject)pc,"PCShellSetApply_C",PCShellSetApply_Shell);CHKERRQ(ierr); 845bdf89e91SBarry Smith ierr = PetscObjectComposeFunction((PetscObject)pc,"PCShellSetApplyBA_C",PCShellSetApplyBA_Shell);CHKERRQ(ierr); 846bdf89e91SBarry Smith ierr = PetscObjectComposeFunction((PetscObject)pc,"PCShellSetPreSolve_C",PCShellSetPreSolve_Shell);CHKERRQ(ierr); 847bdf89e91SBarry Smith ierr = PetscObjectComposeFunction((PetscObject)pc,"PCShellSetPostSolve_C",PCShellSetPostSolve_Shell);CHKERRQ(ierr); 848bdf89e91SBarry Smith ierr = PetscObjectComposeFunction((PetscObject)pc,"PCShellSetView_C",PCShellSetView_Shell);CHKERRQ(ierr); 849bdf89e91SBarry Smith ierr = PetscObjectComposeFunction((PetscObject)pc,"PCShellSetApplyTranspose_C",PCShellSetApplyTranspose_Shell);CHKERRQ(ierr); 850bdf89e91SBarry Smith ierr = PetscObjectComposeFunction((PetscObject)pc,"PCShellSetName_C",PCShellSetName_Shell);CHKERRQ(ierr); 851bdf89e91SBarry Smith ierr = PetscObjectComposeFunction((PetscObject)pc,"PCShellGetName_C",PCShellGetName_Shell);CHKERRQ(ierr); 852bdf89e91SBarry Smith ierr = PetscObjectComposeFunction((PetscObject)pc,"PCShellSetApplyRichardson_C",PCShellSetApplyRichardson_Shell);CHKERRQ(ierr); 8534b9ad928SBarry Smith PetscFunctionReturn(0); 8544b9ad928SBarry Smith } 8554b9ad928SBarry Smith 8564b9ad928SBarry Smith 8574b9ad928SBarry Smith 8584b9ad928SBarry Smith 8594b9ad928SBarry Smith 8604b9ad928SBarry Smith 861