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 44daf670e6SBarry Smith Fortran Notes: To use this from Fortran you must write a Fortran interface definition for this 45daf670e6SBarry Smith function that tells Fortran the Fortran derived data type that you are passing in as the ctx argument. 46daf670e6SBarry 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 78daf670e6SBarry Smith Fortran Notes: To use this from Fortran you must write a Fortran interface definition for this 79daf670e6SBarry Smith function that tells Fortran the Fortran derived data type that you are passing in as the ctx argument. 80daf670e6SBarry 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; 117*e3f487b0SBarry Smith PetscObjectState instate,outstate; 1184b9ad928SBarry Smith 1194b9ad928SBarry Smith PetscFunctionBegin; 120ce94432eSBarry Smith if (!shell->apply) SETERRQ(PetscObjectComm((PetscObject)pc),PETSC_ERR_USER,"No apply() routine provided to Shell PC"); 121*e3f487b0SBarry Smith ierr = PetscObjectStateGet((PetscObject)y, &instate);CHKERRQ(ierr); 122eb6b5d47SBarry Smith PetscStackCall("PCSHELL user function apply()",ierr = (*shell->apply)(pc,x,y);CHKERRQ(ierr)); 123*e3f487b0SBarry Smith ierr = PetscObjectStateGet((PetscObject)y, &outstate);CHKERRQ(ierr); 124*e3f487b0SBarry Smith if (instate == outstate) { 125*e3f487b0SBarry Smith /* increase the state of the output vector since the user did not update its state themselve as should have been done */ 126*e3f487b0SBarry Smith ierr = PetscObjectStateIncrease((PetscObject)y);CHKERRQ(ierr); 127*e3f487b0SBarry Smith } 128*e3f487b0SBarry Smith ierr = PetscObjectStateIncrease((PetscObject)y);CHKERRQ(ierr); 1294b9ad928SBarry Smith PetscFunctionReturn(0); 1304b9ad928SBarry Smith } 1314b9ad928SBarry Smith 1324b9ad928SBarry Smith #undef __FUNCT__ 1332bb17772SBarry Smith #define __FUNCT__ "PCApplyBA_Shell" 1342bb17772SBarry Smith static PetscErrorCode PCApplyBA_Shell(PC pc,PCSide side,Vec x,Vec y,Vec w) 1352bb17772SBarry Smith { 136c5ae4b9aSBarry Smith PC_Shell *shell = (PC_Shell*)pc->data; 1372bb17772SBarry Smith PetscErrorCode ierr; 138*e3f487b0SBarry Smith PetscObjectState instate,outstate; 1392bb17772SBarry Smith 1402bb17772SBarry Smith PetscFunctionBegin; 141ce94432eSBarry Smith if (!shell->applyBA) SETERRQ(PetscObjectComm((PetscObject)pc),PETSC_ERR_USER,"No applyBA() routine provided to Shell PC"); 142*e3f487b0SBarry Smith ierr = PetscObjectStateGet((PetscObject)w, &instate);CHKERRQ(ierr); 143eb6b5d47SBarry Smith PetscStackCall("PCSHELL user function applyBA()",ierr = (*shell->applyBA)(pc,side,x,y,w);CHKERRQ(ierr)); 144*e3f487b0SBarry Smith ierr = PetscObjectStateGet((PetscObject)w, &outstate);CHKERRQ(ierr); 145*e3f487b0SBarry Smith if (instate == outstate) { 146*e3f487b0SBarry Smith /* increase the state of the output vector since the user did not update its state themselve as should have been done */ 147*e3f487b0SBarry Smith ierr = PetscObjectStateIncrease((PetscObject)w);CHKERRQ(ierr); 148*e3f487b0SBarry Smith } 1492bb17772SBarry Smith PetscFunctionReturn(0); 1502bb17772SBarry Smith } 1512bb17772SBarry Smith 1522bb17772SBarry Smith #undef __FUNCT__ 1537cdd61b2SBarry Smith #define __FUNCT__ "PCPreSolve_Shell" 1547cdd61b2SBarry Smith static PetscErrorCode PCPreSolve_Shell(PC pc,KSP ksp,Vec b,Vec x) 1557cdd61b2SBarry Smith { 156c5ae4b9aSBarry Smith PC_Shell *shell = (PC_Shell*)pc->data; 1577cdd61b2SBarry Smith PetscErrorCode ierr; 1587cdd61b2SBarry Smith 1597cdd61b2SBarry Smith PetscFunctionBegin; 160ce94432eSBarry Smith if (!shell->presolve) SETERRQ(PetscObjectComm((PetscObject)pc),PETSC_ERR_USER,"No presolve() routine provided to Shell PC"); 161eb6b5d47SBarry Smith PetscStackCall("PCSHELL user function presolve()",ierr = (*shell->presolve)(pc,ksp,b,x);CHKERRQ(ierr)); 1627cdd61b2SBarry Smith PetscFunctionReturn(0); 1637cdd61b2SBarry Smith } 1647cdd61b2SBarry Smith 1657cdd61b2SBarry Smith #undef __FUNCT__ 1667cdd61b2SBarry Smith #define __FUNCT__ "PCPostSolve_Shell" 1677cdd61b2SBarry Smith static PetscErrorCode PCPostSolve_Shell(PC pc,KSP ksp,Vec b,Vec x) 1687cdd61b2SBarry Smith { 169c5ae4b9aSBarry Smith PC_Shell *shell = (PC_Shell*)pc->data; 1707cdd61b2SBarry Smith PetscErrorCode ierr; 1717cdd61b2SBarry Smith 1727cdd61b2SBarry Smith PetscFunctionBegin; 173ce94432eSBarry Smith if (!shell->postsolve) SETERRQ(PetscObjectComm((PetscObject)pc),PETSC_ERR_USER,"No postsolve() routine provided to Shell PC"); 174eb6b5d47SBarry Smith PetscStackCall("PCSHELL user function postsolve()",ierr = (*shell->postsolve)(pc,ksp,b,x);CHKERRQ(ierr)); 1757cdd61b2SBarry Smith PetscFunctionReturn(0); 1767cdd61b2SBarry Smith } 1777cdd61b2SBarry Smith 1787cdd61b2SBarry Smith #undef __FUNCT__ 1794b9ad928SBarry Smith #define __FUNCT__ "PCApplyTranspose_Shell" 1806849ba73SBarry Smith static PetscErrorCode PCApplyTranspose_Shell(PC pc,Vec x,Vec y) 1814b9ad928SBarry Smith { 182c5ae4b9aSBarry Smith PC_Shell *shell = (PC_Shell*)pc->data; 183dfbe8321SBarry Smith PetscErrorCode ierr; 184*e3f487b0SBarry Smith PetscObjectState instate,outstate; 1854b9ad928SBarry Smith 1864b9ad928SBarry Smith PetscFunctionBegin; 187ce94432eSBarry Smith if (!shell->applytranspose) SETERRQ(PetscObjectComm((PetscObject)pc),PETSC_ERR_USER,"No applytranspose() routine provided to Shell PC"); 188*e3f487b0SBarry Smith ierr = PetscObjectStateGet((PetscObject)y, &instate);CHKERRQ(ierr); 189eb6b5d47SBarry Smith PetscStackCall("PCSHELL user function applytranspose()",ierr = (*shell->applytranspose)(pc,x,y);CHKERRQ(ierr)); 190*e3f487b0SBarry Smith ierr = PetscObjectStateGet((PetscObject)y, &outstate);CHKERRQ(ierr); 191*e3f487b0SBarry Smith if (instate == outstate) { 192*e3f487b0SBarry Smith /* increase the state of the output vector since the user did not update its state themself as should have been done */ 193*e3f487b0SBarry Smith ierr = PetscObjectStateIncrease((PetscObject)y);CHKERRQ(ierr); 194*e3f487b0SBarry Smith } 1954b9ad928SBarry Smith PetscFunctionReturn(0); 1964b9ad928SBarry Smith } 1974b9ad928SBarry Smith 1984b9ad928SBarry Smith #undef __FUNCT__ 1994b9ad928SBarry Smith #define __FUNCT__ "PCApplyRichardson_Shell" 200ace3abfcSBarry 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) 2014b9ad928SBarry Smith { 202dfbe8321SBarry Smith PetscErrorCode ierr; 203c5ae4b9aSBarry Smith PC_Shell *shell = (PC_Shell*)pc->data; 204*e3f487b0SBarry Smith PetscObjectState instate,outstate; 2054b9ad928SBarry Smith 2064b9ad928SBarry Smith PetscFunctionBegin; 207ce94432eSBarry Smith if (!shell->applyrich) SETERRQ(PetscObjectComm((PetscObject)pc),PETSC_ERR_USER,"No applyrichardson() routine provided to Shell PC"); 208*e3f487b0SBarry Smith ierr = PetscObjectStateGet((PetscObject)y, &instate);CHKERRQ(ierr); 209eb6b5d47SBarry Smith PetscStackCall("PCSHELL user function applyrichardson()",ierr = (*shell->applyrich)(pc,x,y,w,rtol,abstol,dtol,it,guesszero,outits,reason);CHKERRQ(ierr)); 210*e3f487b0SBarry Smith ierr = PetscObjectStateGet((PetscObject)y, &outstate);CHKERRQ(ierr); 211*e3f487b0SBarry Smith if (instate == outstate) { 212*e3f487b0SBarry Smith /* increase the state of the output vector since the user did not update its state themself as should have been done */ 213*e3f487b0SBarry Smith ierr = PetscObjectStateIncrease((PetscObject)y);CHKERRQ(ierr); 214*e3f487b0SBarry Smith } 2154b9ad928SBarry Smith PetscFunctionReturn(0); 2164b9ad928SBarry Smith } 2174b9ad928SBarry Smith 2184b9ad928SBarry Smith #undef __FUNCT__ 2194b9ad928SBarry Smith #define __FUNCT__ "PCDestroy_Shell" 2206849ba73SBarry Smith static PetscErrorCode PCDestroy_Shell(PC pc) 2214b9ad928SBarry Smith { 2224b9ad928SBarry Smith PC_Shell *shell = (PC_Shell*)pc->data; 223dfbe8321SBarry Smith PetscErrorCode ierr; 2244b9ad928SBarry Smith 2254b9ad928SBarry Smith PetscFunctionBegin; 226503cfb0cSBarry Smith ierr = PetscFree(shell->name);CHKERRQ(ierr); 2272fa5cd67SKarl Rupp if (shell->destroy) PetscStackCall("PCSHELL user function destroy()",ierr = (*shell->destroy)(pc);CHKERRQ(ierr)); 228c31cb41cSBarry Smith ierr = PetscFree(pc->data);CHKERRQ(ierr); 2294b9ad928SBarry Smith PetscFunctionReturn(0); 2304b9ad928SBarry Smith } 2314b9ad928SBarry Smith 2324b9ad928SBarry Smith #undef __FUNCT__ 2334b9ad928SBarry Smith #define __FUNCT__ "PCView_Shell" 2346849ba73SBarry Smith static PetscErrorCode PCView_Shell(PC pc,PetscViewer viewer) 2354b9ad928SBarry Smith { 2364b9ad928SBarry Smith PC_Shell *shell = (PC_Shell*)pc->data; 237dfbe8321SBarry Smith PetscErrorCode ierr; 238ace3abfcSBarry Smith PetscBool iascii; 2394b9ad928SBarry Smith 2404b9ad928SBarry Smith PetscFunctionBegin; 241251f4c67SDmitry Karpeev ierr = PetscObjectTypeCompare((PetscObject)viewer,PETSCVIEWERASCII,&iascii);CHKERRQ(ierr); 24232077d6dSBarry Smith if (iascii) { 2432fa5cd67SKarl Rupp if (shell->name) { 2442fa5cd67SKarl Rupp ierr = PetscViewerASCIIPrintf(viewer," Shell: %s\n",shell->name);CHKERRQ(ierr); 2452fa5cd67SKarl Rupp } else { 2462fa5cd67SKarl Rupp ierr = PetscViewerASCIIPrintf(viewer," Shell: no name\n");CHKERRQ(ierr); 2472fa5cd67SKarl Rupp } 2484b9ad928SBarry Smith } 2494b9ad928SBarry Smith if (shell->view) { 2504b9ad928SBarry Smith ierr = PetscViewerASCIIPushTab(viewer);CHKERRQ(ierr); 2516891c3e4SJed Brown ierr = (*shell->view)(pc,viewer);CHKERRQ(ierr); 2524b9ad928SBarry Smith ierr = PetscViewerASCIIPopTab(viewer);CHKERRQ(ierr); 2534b9ad928SBarry Smith } 2544b9ad928SBarry Smith PetscFunctionReturn(0); 2554b9ad928SBarry Smith } 2564b9ad928SBarry Smith 2574b9ad928SBarry Smith /* ------------------------------------------------------------------------------*/ 2584b9ad928SBarry Smith #undef __FUNCT__ 25918be62a5SSatish Balay #define __FUNCT__ "PCShellSetDestroy_Shell" 260f7a08781SBarry Smith static PetscErrorCode PCShellSetDestroy_Shell(PC pc, PetscErrorCode (*destroy)(PC)) 26118be62a5SSatish Balay { 262c5ae4b9aSBarry Smith PC_Shell *shell= (PC_Shell*)pc->data; 26318be62a5SSatish Balay 26418be62a5SSatish Balay PetscFunctionBegin; 26518be62a5SSatish Balay shell->destroy = destroy; 26618be62a5SSatish Balay PetscFunctionReturn(0); 26718be62a5SSatish Balay } 26818be62a5SSatish Balay 26918be62a5SSatish Balay #undef __FUNCT__ 2704b9ad928SBarry Smith #define __FUNCT__ "PCShellSetSetUp_Shell" 271f7a08781SBarry Smith static PetscErrorCode PCShellSetSetUp_Shell(PC pc, PetscErrorCode (*setup)(PC)) 2724b9ad928SBarry Smith { 273c5ae4b9aSBarry Smith PC_Shell *shell = (PC_Shell*)pc->data;; 2744b9ad928SBarry Smith 2754b9ad928SBarry Smith PetscFunctionBegin; 2764b9ad928SBarry Smith shell->setup = setup; 277d01c8aa3SLisandro Dalcin if (setup) pc->ops->setup = PCSetUp_Shell; 278d01c8aa3SLisandro Dalcin else pc->ops->setup = 0; 2794b9ad928SBarry Smith PetscFunctionReturn(0); 2804b9ad928SBarry Smith } 2814b9ad928SBarry Smith 2824b9ad928SBarry Smith #undef __FUNCT__ 2834b9ad928SBarry Smith #define __FUNCT__ "PCShellSetApply_Shell" 284f7a08781SBarry Smith static PetscErrorCode PCShellSetApply_Shell(PC pc,PetscErrorCode (*apply)(PC,Vec,Vec)) 2854b9ad928SBarry Smith { 286c5ae4b9aSBarry Smith PC_Shell *shell = (PC_Shell*)pc->data; 2874b9ad928SBarry Smith 2884b9ad928SBarry Smith PetscFunctionBegin; 2894b9ad928SBarry Smith shell->apply = apply; 2904b9ad928SBarry Smith PetscFunctionReturn(0); 2914b9ad928SBarry Smith } 2924b9ad928SBarry Smith 2934b9ad928SBarry Smith #undef __FUNCT__ 2942bb17772SBarry Smith #define __FUNCT__ "PCShellSetApplyBA_Shell" 295f7a08781SBarry Smith static PetscErrorCode PCShellSetApplyBA_Shell(PC pc,PetscErrorCode (*applyBA)(PC,PCSide,Vec,Vec,Vec)) 2962bb17772SBarry Smith { 297c5ae4b9aSBarry Smith PC_Shell *shell = (PC_Shell*)pc->data; 2982bb17772SBarry Smith 2992bb17772SBarry Smith PetscFunctionBegin; 300d01c8aa3SLisandro Dalcin shell->applyBA = applyBA; 301d01c8aa3SLisandro Dalcin if (applyBA) pc->ops->applyBA = PCApplyBA_Shell; 302aef0136fSBarry Smith else pc->ops->applyBA = 0; 3032bb17772SBarry Smith PetscFunctionReturn(0); 3042bb17772SBarry Smith } 3052bb17772SBarry Smith 3062bb17772SBarry Smith #undef __FUNCT__ 3077cdd61b2SBarry Smith #define __FUNCT__ "PCShellSetPreSolve_Shell" 308f7a08781SBarry Smith static PetscErrorCode PCShellSetPreSolve_Shell(PC pc,PetscErrorCode (*presolve)(PC,KSP,Vec,Vec)) 3097cdd61b2SBarry Smith { 310c5ae4b9aSBarry Smith PC_Shell *shell = (PC_Shell*)pc->data; 3117cdd61b2SBarry Smith 3127cdd61b2SBarry Smith PetscFunctionBegin; 3137cdd61b2SBarry Smith shell->presolve = presolve; 314d01c8aa3SLisandro Dalcin if (presolve) pc->ops->presolve = PCPreSolve_Shell; 315d01c8aa3SLisandro Dalcin else pc->ops->presolve = 0; 3167cdd61b2SBarry Smith PetscFunctionReturn(0); 3177cdd61b2SBarry Smith } 3187cdd61b2SBarry Smith 3197cdd61b2SBarry Smith #undef __FUNCT__ 3207cdd61b2SBarry Smith #define __FUNCT__ "PCShellSetPostSolve_Shell" 321f7a08781SBarry Smith static PetscErrorCode PCShellSetPostSolve_Shell(PC pc,PetscErrorCode (*postsolve)(PC,KSP,Vec,Vec)) 3227cdd61b2SBarry Smith { 323c5ae4b9aSBarry Smith PC_Shell *shell = (PC_Shell*)pc->data; 3247cdd61b2SBarry Smith 3257cdd61b2SBarry Smith PetscFunctionBegin; 3267cdd61b2SBarry Smith shell->postsolve = postsolve; 327d01c8aa3SLisandro Dalcin if (postsolve) pc->ops->postsolve = PCPostSolve_Shell; 328d01c8aa3SLisandro Dalcin else pc->ops->postsolve = 0; 3297cdd61b2SBarry Smith PetscFunctionReturn(0); 3307cdd61b2SBarry Smith } 3317cdd61b2SBarry Smith 3327cdd61b2SBarry Smith #undef __FUNCT__ 3334b9ad928SBarry Smith #define __FUNCT__ "PCShellSetView_Shell" 334f7a08781SBarry Smith static PetscErrorCode PCShellSetView_Shell(PC pc,PetscErrorCode (*view)(PC,PetscViewer)) 3354b9ad928SBarry Smith { 336c5ae4b9aSBarry Smith PC_Shell *shell = (PC_Shell*)pc->data; 3374b9ad928SBarry Smith 3384b9ad928SBarry Smith PetscFunctionBegin; 3394b9ad928SBarry Smith shell->view = view; 3404b9ad928SBarry Smith PetscFunctionReturn(0); 3414b9ad928SBarry Smith } 3424b9ad928SBarry Smith 3434b9ad928SBarry Smith #undef __FUNCT__ 3444b9ad928SBarry Smith #define __FUNCT__ "PCShellSetApplyTranspose_Shell" 345f7a08781SBarry Smith static PetscErrorCode PCShellSetApplyTranspose_Shell(PC pc,PetscErrorCode (*applytranspose)(PC,Vec,Vec)) 3464b9ad928SBarry Smith { 347c5ae4b9aSBarry Smith PC_Shell *shell = (PC_Shell*)pc->data; 3484b9ad928SBarry Smith 3494b9ad928SBarry Smith PetscFunctionBegin; 3504b9ad928SBarry Smith shell->applytranspose = applytranspose; 351d01c8aa3SLisandro Dalcin if (applytranspose) pc->ops->applytranspose = PCApplyTranspose_Shell; 352d01c8aa3SLisandro Dalcin else pc->ops->applytranspose = 0; 353d01c8aa3SLisandro Dalcin PetscFunctionReturn(0); 354d01c8aa3SLisandro Dalcin } 355d01c8aa3SLisandro Dalcin 356d01c8aa3SLisandro Dalcin #undef __FUNCT__ 357d01c8aa3SLisandro Dalcin #define __FUNCT__ "PCShellSetApplyRichardson_Shell" 358f7a08781SBarry Smith static PetscErrorCode PCShellSetApplyRichardson_Shell(PC pc,PetscErrorCode (*applyrich)(PC,Vec,Vec,Vec,PetscReal,PetscReal,PetscReal,PetscInt,PetscBool ,PetscInt*,PCRichardsonConvergedReason*)) 359d01c8aa3SLisandro Dalcin { 360c5ae4b9aSBarry Smith PC_Shell *shell = (PC_Shell*)pc->data; 361d01c8aa3SLisandro Dalcin 362d01c8aa3SLisandro Dalcin PetscFunctionBegin; 363d01c8aa3SLisandro Dalcin shell->applyrich = applyrich; 364d01c8aa3SLisandro Dalcin if (applyrich) pc->ops->applyrichardson = PCApplyRichardson_Shell; 365d01c8aa3SLisandro Dalcin else pc->ops->applyrichardson = 0; 3664b9ad928SBarry Smith PetscFunctionReturn(0); 3674b9ad928SBarry Smith } 3684b9ad928SBarry Smith 3694b9ad928SBarry Smith #undef __FUNCT__ 3704b9ad928SBarry Smith #define __FUNCT__ "PCShellSetName_Shell" 371f7a08781SBarry Smith static PetscErrorCode PCShellSetName_Shell(PC pc,const char name[]) 3724b9ad928SBarry Smith { 373c5ae4b9aSBarry Smith PC_Shell *shell = (PC_Shell*)pc->data; 374dfbe8321SBarry Smith PetscErrorCode ierr; 3754b9ad928SBarry Smith 3764b9ad928SBarry Smith PetscFunctionBegin; 377503cfb0cSBarry Smith ierr = PetscFree(shell->name);CHKERRQ(ierr); 3784b9ad928SBarry Smith ierr = PetscStrallocpy(name,&shell->name);CHKERRQ(ierr); 3794b9ad928SBarry Smith PetscFunctionReturn(0); 3804b9ad928SBarry Smith } 3814b9ad928SBarry Smith 3824b9ad928SBarry Smith #undef __FUNCT__ 3834b9ad928SBarry Smith #define __FUNCT__ "PCShellGetName_Shell" 384f7a08781SBarry Smith static PetscErrorCode PCShellGetName_Shell(PC pc,const char *name[]) 3854b9ad928SBarry Smith { 386c5ae4b9aSBarry Smith PC_Shell *shell = (PC_Shell*)pc->data; 3874b9ad928SBarry Smith 3884b9ad928SBarry Smith PetscFunctionBegin; 3894b9ad928SBarry Smith *name = shell->name; 3904b9ad928SBarry Smith PetscFunctionReturn(0); 3914b9ad928SBarry Smith } 3924b9ad928SBarry Smith 3934b9ad928SBarry Smith /* -------------------------------------------------------------------------------*/ 3944b9ad928SBarry Smith 3954b9ad928SBarry Smith #undef __FUNCT__ 39618be62a5SSatish Balay #define __FUNCT__ "PCShellSetDestroy" 39718be62a5SSatish Balay /*@C 39818be62a5SSatish Balay PCShellSetDestroy - Sets routine to use to destroy the user-provided 39918be62a5SSatish Balay application context. 40018be62a5SSatish Balay 4013f9fe445SBarry Smith Logically Collective on PC 40218be62a5SSatish Balay 40318be62a5SSatish Balay Input Parameters: 40418be62a5SSatish Balay + pc - the preconditioner context 40518be62a5SSatish Balay . destroy - the application-provided destroy routine 40618be62a5SSatish Balay 40718be62a5SSatish Balay Calling sequence of destroy: 40818be62a5SSatish Balay .vb 4096891c3e4SJed Brown PetscErrorCode destroy (PC) 41018be62a5SSatish Balay .ve 41118be62a5SSatish Balay 41218be62a5SSatish Balay . ptr - the application context 41318be62a5SSatish Balay 4144aa34b0aSBarry Smith Notes: the function MUST return an error code of 0 on success and nonzero on failure. 4154aa34b0aSBarry Smith 41618be62a5SSatish Balay Level: developer 41718be62a5SSatish Balay 41818be62a5SSatish Balay .keywords: PC, shell, set, destroy, user-provided 41918be62a5SSatish Balay 42018be62a5SSatish Balay .seealso: PCShellSetApply(), PCShellSetContext() 42118be62a5SSatish Balay @*/ 4227087cfbeSBarry Smith PetscErrorCode PCShellSetDestroy(PC pc,PetscErrorCode (*destroy)(PC)) 42318be62a5SSatish Balay { 4244ac538c5SBarry Smith PetscErrorCode ierr; 42518be62a5SSatish Balay 42618be62a5SSatish Balay PetscFunctionBegin; 4270700a824SBarry Smith PetscValidHeaderSpecific(pc,PC_CLASSID,1); 4284ac538c5SBarry Smith ierr = PetscTryMethod(pc,"PCShellSetDestroy_C",(PC,PetscErrorCode (*)(PC)),(pc,destroy));CHKERRQ(ierr); 42918be62a5SSatish Balay PetscFunctionReturn(0); 43018be62a5SSatish Balay } 43118be62a5SSatish Balay 43218be62a5SSatish Balay 43318be62a5SSatish Balay #undef __FUNCT__ 4344b9ad928SBarry Smith #define __FUNCT__ "PCShellSetSetUp" 4354b9ad928SBarry Smith /*@C 4364b9ad928SBarry Smith PCShellSetSetUp - Sets routine to use to "setup" the preconditioner whenever the 4374b9ad928SBarry Smith matrix operator is changed. 4384b9ad928SBarry Smith 4393f9fe445SBarry Smith Logically Collective on PC 4404b9ad928SBarry Smith 4414b9ad928SBarry Smith Input Parameters: 4424b9ad928SBarry Smith + pc - the preconditioner context 4434b9ad928SBarry Smith . setup - the application-provided setup routine 4444b9ad928SBarry Smith 4454b9ad928SBarry Smith Calling sequence of setup: 4464b9ad928SBarry Smith .vb 4476891c3e4SJed Brown PetscErrorCode setup (PC pc) 4484b9ad928SBarry Smith .ve 4494b9ad928SBarry Smith 4506891c3e4SJed Brown . pc - the preconditioner, get the application context with PCShellGetContext() 4514b9ad928SBarry Smith 4524aa34b0aSBarry Smith Notes: the function MUST return an error code of 0 on success and nonzero on failure. 4534aa34b0aSBarry Smith 4544b9ad928SBarry Smith Level: developer 4554b9ad928SBarry Smith 4564b9ad928SBarry Smith .keywords: PC, shell, set, setup, user-provided 4574b9ad928SBarry Smith 458be29d3c6SBarry Smith .seealso: PCShellSetApplyRichardson(), PCShellSetApply(), PCShellSetContext() 4594b9ad928SBarry Smith @*/ 4607087cfbeSBarry Smith PetscErrorCode PCShellSetSetUp(PC pc,PetscErrorCode (*setup)(PC)) 4614b9ad928SBarry Smith { 4624ac538c5SBarry Smith PetscErrorCode ierr; 4634b9ad928SBarry Smith 4644b9ad928SBarry Smith PetscFunctionBegin; 4650700a824SBarry Smith PetscValidHeaderSpecific(pc,PC_CLASSID,1); 4664ac538c5SBarry Smith ierr = PetscTryMethod(pc,"PCShellSetSetUp_C",(PC,PetscErrorCode (*)(PC)),(pc,setup));CHKERRQ(ierr); 4674b9ad928SBarry Smith PetscFunctionReturn(0); 4684b9ad928SBarry Smith } 4694b9ad928SBarry Smith 4704b9ad928SBarry Smith 4714b9ad928SBarry Smith #undef __FUNCT__ 4724b9ad928SBarry Smith #define __FUNCT__ "PCShellSetView" 4734b9ad928SBarry Smith /*@C 4744b9ad928SBarry Smith PCShellSetView - Sets routine to use as viewer of shell preconditioner 4754b9ad928SBarry Smith 4763f9fe445SBarry Smith Logically Collective on PC 4774b9ad928SBarry Smith 4784b9ad928SBarry Smith Input Parameters: 4794b9ad928SBarry Smith + pc - the preconditioner context 4804b9ad928SBarry Smith - view - the application-provided view routine 4814b9ad928SBarry Smith 4824b9ad928SBarry Smith Calling sequence of apply: 4834b9ad928SBarry Smith .vb 4846891c3e4SJed Brown PetscErrorCode view(PC pc,PetscViewer v) 4854b9ad928SBarry Smith .ve 4864b9ad928SBarry Smith 4876891c3e4SJed Brown + pc - the preconditioner, get the application context with PCShellGetContext() 4884b9ad928SBarry Smith - v - viewer 4894b9ad928SBarry Smith 4904aa34b0aSBarry Smith Notes: the function MUST return an error code of 0 on success and nonzero on failure. 4914aa34b0aSBarry Smith 4924b9ad928SBarry Smith Level: developer 4934b9ad928SBarry Smith 4944b9ad928SBarry Smith .keywords: PC, shell, set, apply, user-provided 4954b9ad928SBarry Smith 4964b9ad928SBarry Smith .seealso: PCShellSetApplyRichardson(), PCShellSetSetUp(), PCShellSetApplyTranspose() 4974b9ad928SBarry Smith @*/ 4987087cfbeSBarry Smith PetscErrorCode PCShellSetView(PC pc,PetscErrorCode (*view)(PC,PetscViewer)) 4994b9ad928SBarry Smith { 5004ac538c5SBarry Smith PetscErrorCode ierr; 5014b9ad928SBarry Smith 5024b9ad928SBarry Smith PetscFunctionBegin; 5030700a824SBarry Smith PetscValidHeaderSpecific(pc,PC_CLASSID,1); 5044ac538c5SBarry Smith ierr = PetscTryMethod(pc,"PCShellSetView_C",(PC,PetscErrorCode (*)(PC,PetscViewer)),(pc,view));CHKERRQ(ierr); 5054b9ad928SBarry Smith PetscFunctionReturn(0); 5064b9ad928SBarry Smith } 5074b9ad928SBarry Smith 5084b9ad928SBarry Smith #undef __FUNCT__ 5094b9ad928SBarry Smith #define __FUNCT__ "PCShellSetApply" 5104b9ad928SBarry Smith /*@C 5114b9ad928SBarry Smith PCShellSetApply - Sets routine to use as preconditioner. 5124b9ad928SBarry Smith 5133f9fe445SBarry Smith Logically Collective on PC 5144b9ad928SBarry Smith 5154b9ad928SBarry Smith Input Parameters: 5164b9ad928SBarry Smith + pc - the preconditioner context 517be29d3c6SBarry Smith - apply - the application-provided preconditioning routine 5184b9ad928SBarry Smith 5194b9ad928SBarry Smith Calling sequence of apply: 5204b9ad928SBarry Smith .vb 5216891c3e4SJed Brown PetscErrorCode apply (PC pc,Vec xin,Vec xout) 5224b9ad928SBarry Smith .ve 5234b9ad928SBarry Smith 5246891c3e4SJed Brown + pc - the preconditioner, get the application context with PCShellGetContext() 5254b9ad928SBarry Smith . xin - input vector 5264b9ad928SBarry Smith - xout - output vector 5274b9ad928SBarry Smith 5284aa34b0aSBarry Smith Notes: the function MUST return an error code of 0 on success and nonzero on failure. 5294aa34b0aSBarry Smith 530292fb18eSBarry Smith Developer Notes: There should also be a PCShellSetApplySymmetricRight() and PCShellSetApplySymmetricLeft(). 531292fb18eSBarry Smith 5324b9ad928SBarry Smith Level: developer 5334b9ad928SBarry Smith 5344b9ad928SBarry Smith .keywords: PC, shell, set, apply, user-provided 5354b9ad928SBarry Smith 5362bb17772SBarry Smith .seealso: PCShellSetApplyRichardson(), PCShellSetSetUp(), PCShellSetApplyTranspose(), PCShellSetContext(), PCShellSetApplyBA() 5374b9ad928SBarry Smith @*/ 5387087cfbeSBarry Smith PetscErrorCode PCShellSetApply(PC pc,PetscErrorCode (*apply)(PC,Vec,Vec)) 5394b9ad928SBarry Smith { 5404ac538c5SBarry Smith PetscErrorCode ierr; 5414b9ad928SBarry Smith 5424b9ad928SBarry Smith PetscFunctionBegin; 5430700a824SBarry Smith PetscValidHeaderSpecific(pc,PC_CLASSID,1); 5444ac538c5SBarry Smith ierr = PetscTryMethod(pc,"PCShellSetApply_C",(PC,PetscErrorCode (*)(PC,Vec,Vec)),(pc,apply));CHKERRQ(ierr); 5454b9ad928SBarry Smith PetscFunctionReturn(0); 5464b9ad928SBarry Smith } 5474b9ad928SBarry Smith 5484b9ad928SBarry Smith #undef __FUNCT__ 5492bb17772SBarry Smith #define __FUNCT__ "PCShellSetApplyBA" 5502bb17772SBarry Smith /*@C 5512bb17772SBarry Smith PCShellSetApplyBA - Sets routine to use as preconditioner times operator. 5522bb17772SBarry Smith 5533f9fe445SBarry Smith Logically Collective on PC 5542bb17772SBarry Smith 5552bb17772SBarry Smith Input Parameters: 5562bb17772SBarry Smith + pc - the preconditioner context 5572bb17772SBarry Smith - applyBA - the application-provided BA routine 5582bb17772SBarry Smith 5592bb17772SBarry Smith Calling sequence of apply: 5602bb17772SBarry Smith .vb 5616891c3e4SJed Brown PetscErrorCode applyBA (PC pc,Vec xin,Vec xout) 5622bb17772SBarry Smith .ve 5632bb17772SBarry Smith 5646891c3e4SJed Brown + pc - the preconditioner, get the application context with PCShellGetContext() 5652bb17772SBarry Smith . xin - input vector 5662bb17772SBarry Smith - xout - output vector 5672bb17772SBarry Smith 5684aa34b0aSBarry Smith Notes: the function MUST return an error code of 0 on success and nonzero on failure. 5694aa34b0aSBarry Smith 5702bb17772SBarry Smith Level: developer 5712bb17772SBarry Smith 5722bb17772SBarry Smith .keywords: PC, shell, set, apply, user-provided 5732bb17772SBarry Smith 5742bb17772SBarry Smith .seealso: PCShellSetApplyRichardson(), PCShellSetSetUp(), PCShellSetApplyTranspose(), PCShellSetContext(), PCShellSetApply() 5752bb17772SBarry Smith @*/ 5767087cfbeSBarry Smith PetscErrorCode PCShellSetApplyBA(PC pc,PetscErrorCode (*applyBA)(PC,PCSide,Vec,Vec,Vec)) 5772bb17772SBarry Smith { 5784ac538c5SBarry Smith PetscErrorCode ierr; 5792bb17772SBarry Smith 5802bb17772SBarry Smith PetscFunctionBegin; 5810700a824SBarry Smith PetscValidHeaderSpecific(pc,PC_CLASSID,1); 5824ac538c5SBarry Smith ierr = PetscTryMethod(pc,"PCShellSetApplyBA_C",(PC,PetscErrorCode (*)(PC,PCSide,Vec,Vec,Vec)),(pc,applyBA));CHKERRQ(ierr); 5832bb17772SBarry Smith PetscFunctionReturn(0); 5842bb17772SBarry Smith } 5852bb17772SBarry Smith 5862bb17772SBarry Smith #undef __FUNCT__ 5874b9ad928SBarry Smith #define __FUNCT__ "PCShellSetApplyTranspose" 5884b9ad928SBarry Smith /*@C 5894b9ad928SBarry Smith PCShellSetApplyTranspose - Sets routine to use as preconditioner transpose. 5904b9ad928SBarry Smith 5913f9fe445SBarry Smith Logically Collective on PC 5924b9ad928SBarry Smith 5934b9ad928SBarry Smith Input Parameters: 5944b9ad928SBarry Smith + pc - the preconditioner context 5954b9ad928SBarry Smith - apply - the application-provided preconditioning transpose routine 5964b9ad928SBarry Smith 5974b9ad928SBarry Smith Calling sequence of apply: 5984b9ad928SBarry Smith .vb 5996891c3e4SJed Brown PetscErrorCode applytranspose (PC pc,Vec xin,Vec xout) 6004b9ad928SBarry Smith .ve 6014b9ad928SBarry Smith 6026891c3e4SJed Brown + pc - the preconditioner, get the application context with PCShellGetContext() 6034b9ad928SBarry Smith . xin - input vector 6044b9ad928SBarry Smith - xout - output vector 6054b9ad928SBarry Smith 6064aa34b0aSBarry Smith Notes: the function MUST return an error code of 0 on success and nonzero on failure. 6074aa34b0aSBarry Smith 6084b9ad928SBarry Smith Level: developer 6094b9ad928SBarry Smith 6104b9ad928SBarry Smith Notes: 6114b9ad928SBarry Smith Uses the same context variable as PCShellSetApply(). 6124b9ad928SBarry Smith 6134b9ad928SBarry Smith .keywords: PC, shell, set, apply, user-provided 6144b9ad928SBarry Smith 6152bb17772SBarry Smith .seealso: PCShellSetApplyRichardson(), PCShellSetSetUp(), PCShellSetApply(), PCSetContext(), PCShellSetApplyBA() 6164b9ad928SBarry Smith @*/ 6177087cfbeSBarry Smith PetscErrorCode PCShellSetApplyTranspose(PC pc,PetscErrorCode (*applytranspose)(PC,Vec,Vec)) 6184b9ad928SBarry Smith { 6194ac538c5SBarry Smith PetscErrorCode ierr; 6204b9ad928SBarry Smith 6214b9ad928SBarry Smith PetscFunctionBegin; 6220700a824SBarry Smith PetscValidHeaderSpecific(pc,PC_CLASSID,1); 6234ac538c5SBarry Smith ierr = PetscTryMethod(pc,"PCShellSetApplyTranspose_C",(PC,PetscErrorCode (*)(PC,Vec,Vec)),(pc,applytranspose));CHKERRQ(ierr); 6244b9ad928SBarry Smith PetscFunctionReturn(0); 6254b9ad928SBarry Smith } 6264b9ad928SBarry Smith 6274b9ad928SBarry Smith #undef __FUNCT__ 6287cdd61b2SBarry Smith #define __FUNCT__ "PCShellSetPreSolve" 6297cdd61b2SBarry Smith /*@C 6307cdd61b2SBarry Smith PCShellSetPreSolve - Sets routine to apply to the operators/vectors before a KSPSolve() is 6317cdd61b2SBarry Smith applied. This usually does something like scale the linear system in some application 6327cdd61b2SBarry Smith specific way. 6337cdd61b2SBarry Smith 6343f9fe445SBarry Smith Logically Collective on PC 6357cdd61b2SBarry Smith 6367cdd61b2SBarry Smith Input Parameters: 6377cdd61b2SBarry Smith + pc - the preconditioner context 6387cdd61b2SBarry Smith - presolve - the application-provided presolve routine 6397cdd61b2SBarry Smith 6407cdd61b2SBarry Smith Calling sequence of presolve: 6417cdd61b2SBarry Smith .vb 6426891c3e4SJed Brown PetscErrorCode presolve (PC,KSP ksp,Vec b,Vec x) 6437cdd61b2SBarry Smith .ve 6447cdd61b2SBarry Smith 6456891c3e4SJed Brown + pc - the preconditioner, get the application context with PCShellGetContext() 6467cdd61b2SBarry Smith . xin - input vector 6477cdd61b2SBarry Smith - xout - output vector 6487cdd61b2SBarry Smith 6494aa34b0aSBarry Smith Notes: the function MUST return an error code of 0 on success and nonzero on failure. 6504aa34b0aSBarry Smith 6517cdd61b2SBarry Smith Level: developer 6527cdd61b2SBarry Smith 6537cdd61b2SBarry Smith .keywords: PC, shell, set, apply, user-provided 6547cdd61b2SBarry Smith 655be29d3c6SBarry Smith .seealso: PCShellSetApplyRichardson(), PCShellSetSetUp(), PCShellSetApplyTranspose(), PCShellSetPostSolve(), PCShellSetContext() 6567cdd61b2SBarry Smith @*/ 6577087cfbeSBarry Smith PetscErrorCode PCShellSetPreSolve(PC pc,PetscErrorCode (*presolve)(PC,KSP,Vec,Vec)) 6587cdd61b2SBarry Smith { 6594ac538c5SBarry Smith PetscErrorCode ierr; 6607cdd61b2SBarry Smith 6617cdd61b2SBarry Smith PetscFunctionBegin; 6620700a824SBarry Smith PetscValidHeaderSpecific(pc,PC_CLASSID,1); 6634ac538c5SBarry Smith ierr = PetscTryMethod(pc,"PCShellSetPreSolve_C",(PC,PetscErrorCode (*)(PC,KSP,Vec,Vec)),(pc,presolve));CHKERRQ(ierr); 6647cdd61b2SBarry Smith PetscFunctionReturn(0); 6657cdd61b2SBarry Smith } 6667cdd61b2SBarry Smith 6677cdd61b2SBarry Smith #undef __FUNCT__ 6687cdd61b2SBarry Smith #define __FUNCT__ "PCShellSetPostSolve" 6697cdd61b2SBarry Smith /*@C 6707cdd61b2SBarry Smith PCShellSetPostSolve - Sets routine to apply to the operators/vectors before a KSPSolve() is 6717cdd61b2SBarry Smith applied. This usually does something like scale the linear system in some application 6727cdd61b2SBarry Smith specific way. 6737cdd61b2SBarry Smith 6743f9fe445SBarry Smith Logically Collective on PC 6757cdd61b2SBarry Smith 6767cdd61b2SBarry Smith Input Parameters: 6777cdd61b2SBarry Smith + pc - the preconditioner context 6787cdd61b2SBarry Smith - postsolve - the application-provided presolve routine 6797cdd61b2SBarry Smith 6807cdd61b2SBarry Smith Calling sequence of postsolve: 6817cdd61b2SBarry Smith .vb 6826891c3e4SJed Brown PetscErrorCode postsolve(PC,KSP ksp,Vec b,Vec x) 6837cdd61b2SBarry Smith .ve 6847cdd61b2SBarry Smith 6856891c3e4SJed Brown + pc - the preconditioner, get the application context with PCShellGetContext() 6867cdd61b2SBarry Smith . xin - input vector 6877cdd61b2SBarry Smith - xout - output vector 6887cdd61b2SBarry Smith 6894aa34b0aSBarry Smith Notes: the function MUST return an error code of 0 on success and nonzero on failure. 6904aa34b0aSBarry Smith 6917cdd61b2SBarry Smith Level: developer 6927cdd61b2SBarry Smith 6937cdd61b2SBarry Smith .keywords: PC, shell, set, apply, user-provided 6947cdd61b2SBarry Smith 695be29d3c6SBarry Smith .seealso: PCShellSetApplyRichardson(), PCShellSetSetUp(), PCShellSetApplyTranspose(), PCShellSetPreSolve(), PCShellSetContext() 6967cdd61b2SBarry Smith @*/ 6977087cfbeSBarry Smith PetscErrorCode PCShellSetPostSolve(PC pc,PetscErrorCode (*postsolve)(PC,KSP,Vec,Vec)) 6987cdd61b2SBarry Smith { 6994ac538c5SBarry Smith PetscErrorCode ierr; 7007cdd61b2SBarry Smith 7017cdd61b2SBarry Smith PetscFunctionBegin; 7020700a824SBarry Smith PetscValidHeaderSpecific(pc,PC_CLASSID,1); 7034ac538c5SBarry Smith ierr = PetscTryMethod(pc,"PCShellSetPostSolve_C",(PC,PetscErrorCode (*)(PC,KSP,Vec,Vec)),(pc,postsolve));CHKERRQ(ierr); 7047cdd61b2SBarry Smith PetscFunctionReturn(0); 7057cdd61b2SBarry Smith } 7067cdd61b2SBarry Smith 7077cdd61b2SBarry Smith #undef __FUNCT__ 7084b9ad928SBarry Smith #define __FUNCT__ "PCShellSetName" 7094b9ad928SBarry Smith /*@C 7104b9ad928SBarry Smith PCShellSetName - Sets an optional name to associate with a shell 7114b9ad928SBarry Smith preconditioner. 7124b9ad928SBarry Smith 7134b9ad928SBarry Smith Not Collective 7144b9ad928SBarry Smith 7154b9ad928SBarry Smith Input Parameters: 7164b9ad928SBarry Smith + pc - the preconditioner context 7174b9ad928SBarry Smith - name - character string describing shell preconditioner 7184b9ad928SBarry Smith 7194b9ad928SBarry Smith Level: developer 7204b9ad928SBarry Smith 7214b9ad928SBarry Smith .keywords: PC, shell, set, name, user-provided 7224b9ad928SBarry Smith 7234b9ad928SBarry Smith .seealso: PCShellGetName() 7244b9ad928SBarry Smith @*/ 7257087cfbeSBarry Smith PetscErrorCode PCShellSetName(PC pc,const char name[]) 7264b9ad928SBarry Smith { 7274ac538c5SBarry Smith PetscErrorCode ierr; 7284b9ad928SBarry Smith 7294b9ad928SBarry Smith PetscFunctionBegin; 7300700a824SBarry Smith PetscValidHeaderSpecific(pc,PC_CLASSID,1); 7314ac538c5SBarry Smith ierr = PetscTryMethod(pc,"PCShellSetName_C",(PC,const char []),(pc,name));CHKERRQ(ierr); 7324b9ad928SBarry Smith PetscFunctionReturn(0); 7334b9ad928SBarry Smith } 7344b9ad928SBarry Smith 7354b9ad928SBarry Smith #undef __FUNCT__ 7364b9ad928SBarry Smith #define __FUNCT__ "PCShellGetName" 7374b9ad928SBarry Smith /*@C 7384b9ad928SBarry Smith PCShellGetName - Gets an optional name that the user has set for a shell 7394b9ad928SBarry Smith preconditioner. 7404b9ad928SBarry Smith 7414b9ad928SBarry Smith Not Collective 7424b9ad928SBarry Smith 7434b9ad928SBarry Smith Input Parameter: 7444b9ad928SBarry Smith . pc - the preconditioner context 7454b9ad928SBarry Smith 7464b9ad928SBarry Smith Output Parameter: 7474b9ad928SBarry Smith . name - character string describing shell preconditioner (you should not free this) 7484b9ad928SBarry Smith 7494b9ad928SBarry Smith Level: developer 7504b9ad928SBarry Smith 7514b9ad928SBarry Smith .keywords: PC, shell, get, name, user-provided 7524b9ad928SBarry Smith 7534b9ad928SBarry Smith .seealso: PCShellSetName() 7544b9ad928SBarry Smith @*/ 755ccaf0856SBarry Smith PetscErrorCode PCShellGetName(PC pc,const char *name[]) 7564b9ad928SBarry Smith { 7574ac538c5SBarry Smith PetscErrorCode ierr; 7584b9ad928SBarry Smith 7594b9ad928SBarry Smith PetscFunctionBegin; 7600700a824SBarry Smith PetscValidHeaderSpecific(pc,PC_CLASSID,1); 7614482741eSBarry Smith PetscValidPointer(name,2); 762ccaf0856SBarry Smith ierr = PetscUseMethod(pc,"PCShellGetName_C",(PC,const char*[]),(pc,name));CHKERRQ(ierr); 7634b9ad928SBarry Smith PetscFunctionReturn(0); 7644b9ad928SBarry Smith } 7654b9ad928SBarry Smith 7664b9ad928SBarry Smith #undef __FUNCT__ 7674b9ad928SBarry Smith #define __FUNCT__ "PCShellSetApplyRichardson" 7684b9ad928SBarry Smith /*@C 7694b9ad928SBarry Smith PCShellSetApplyRichardson - Sets routine to use as preconditioner 7704b9ad928SBarry Smith in Richardson iteration. 7714b9ad928SBarry Smith 7723f9fe445SBarry Smith Logically Collective on PC 7734b9ad928SBarry Smith 7744b9ad928SBarry Smith Input Parameters: 7754b9ad928SBarry Smith + pc - the preconditioner context 776be29d3c6SBarry Smith - apply - the application-provided preconditioning routine 7774b9ad928SBarry Smith 7784b9ad928SBarry Smith Calling sequence of apply: 7794b9ad928SBarry Smith .vb 7806891c3e4SJed Brown PetscErrorCode apply (PC pc,Vec b,Vec x,Vec r,PetscReal rtol,PetscReal abstol,PetscReal dtol,PetscInt maxits) 7814b9ad928SBarry Smith .ve 7824b9ad928SBarry Smith 7836891c3e4SJed Brown + pc - the preconditioner, get the application context with PCShellGetContext() 7844b9ad928SBarry Smith . b - right-hand-side 7854b9ad928SBarry Smith . x - current iterate 7864b9ad928SBarry Smith . r - work space 7874b9ad928SBarry Smith . rtol - relative tolerance of residual norm to stop at 78870441072SBarry Smith . abstol - absolute tolerance of residual norm to stop at 7894b9ad928SBarry Smith . dtol - if residual norm increases by this factor than return 7904b9ad928SBarry Smith - maxits - number of iterations to run 7914b9ad928SBarry Smith 7924aa34b0aSBarry Smith Notes: the function MUST return an error code of 0 on success and nonzero on failure. 7934aa34b0aSBarry Smith 7944b9ad928SBarry Smith Level: developer 7954b9ad928SBarry Smith 7964b9ad928SBarry Smith .keywords: PC, shell, set, apply, Richardson, user-provided 7974b9ad928SBarry Smith 798be29d3c6SBarry Smith .seealso: PCShellSetApply(), PCShellSetContext() 7994b9ad928SBarry Smith @*/ 8007087cfbeSBarry Smith PetscErrorCode PCShellSetApplyRichardson(PC pc,PetscErrorCode (*apply)(PC,Vec,Vec,Vec,PetscReal,PetscReal,PetscReal,PetscInt,PetscBool,PetscInt*,PCRichardsonConvergedReason*)) 8014b9ad928SBarry Smith { 8024ac538c5SBarry Smith PetscErrorCode ierr; 8034b9ad928SBarry Smith 8044b9ad928SBarry Smith PetscFunctionBegin; 8050700a824SBarry Smith PetscValidHeaderSpecific(pc,PC_CLASSID,1); 8064ac538c5SBarry Smith ierr = PetscTryMethod(pc,"PCShellSetApplyRichardson_C",(PC,PetscErrorCode (*)(PC,Vec,Vec,Vec,PetscReal,PetscReal,PetscReal,PetscInt,PetscBool,PetscInt*,PCRichardsonConvergedReason*)),(pc,apply));CHKERRQ(ierr); 8074b9ad928SBarry Smith PetscFunctionReturn(0); 8084b9ad928SBarry Smith } 8094b9ad928SBarry Smith 8104b9ad928SBarry Smith /*MC 8114b9ad928SBarry Smith PCSHELL - Creates a new preconditioner class for use with your 8124b9ad928SBarry Smith own private data storage format. 8134b9ad928SBarry Smith 8144b9ad928SBarry Smith Level: advanced 81590198e61SBarry Smith > 8164b9ad928SBarry Smith Concepts: providing your own preconditioner 8174b9ad928SBarry Smith 8184b9ad928SBarry Smith Usage: 8196891c3e4SJed Brown $ extern PetscErrorCode apply(PC,Vec,Vec); 8206891c3e4SJed Brown $ extern PetscErrorCode applyba(PC,PCSide,Vec,Vec,Vec); 8216891c3e4SJed Brown $ extern PetscErrorCode applytranspose(PC,Vec,Vec); 8226891c3e4SJed Brown $ extern PetscErrorCode setup(PC); 8236891c3e4SJed Brown $ extern PetscErrorCode destroy(PC); 8246891c3e4SJed Brown $ 8254b9ad928SBarry Smith $ PCCreate(comm,&pc); 8264b9ad928SBarry Smith $ PCSetType(pc,PCSHELL); 827be29d3c6SBarry Smith $ PCShellSetContext(pc,ctx) 8286891c3e4SJed Brown $ PCShellSetApply(pc,apply); 8296891c3e4SJed Brown $ PCShellSetApplyBA(pc,applyba); (optional) 8306891c3e4SJed Brown $ PCShellSetApplyTranspose(pc,applytranspose); (optional) 8314b9ad928SBarry Smith $ PCShellSetSetUp(pc,setup); (optional) 832d01c8aa3SLisandro Dalcin $ PCShellSetDestroy(pc,destroy); (optional) 8334b9ad928SBarry Smith 8344b9ad928SBarry Smith .seealso: PCCreate(), PCSetType(), PCType (for list of available types), PC, 835fd2d0fe1Svictor MATSHELL, PCShellSetSetUp(), PCShellSetApply(), PCShellSetView(), 836fd2d0fe1Svictor PCShellSetApplyTranspose(), PCShellSetName(), PCShellSetApplyRichardson(), 8372bb17772SBarry Smith PCShellGetName(), PCShellSetContext(), PCShellGetContext(), PCShellSetApplyBA() 8384b9ad928SBarry Smith M*/ 8394b9ad928SBarry Smith 8404b9ad928SBarry Smith #undef __FUNCT__ 8414b9ad928SBarry Smith #define __FUNCT__ "PCCreate_Shell" 8428cc058d9SJed Brown PETSC_EXTERN PetscErrorCode PCCreate_Shell(PC pc) 8434b9ad928SBarry Smith { 844dfbe8321SBarry Smith PetscErrorCode ierr; 8454b9ad928SBarry Smith PC_Shell *shell; 8464b9ad928SBarry Smith 8474b9ad928SBarry Smith PetscFunctionBegin; 848b00a9115SJed Brown ierr = PetscNewLog(pc,&shell);CHKERRQ(ierr); 8494b9ad928SBarry Smith pc->data = (void*)shell; 8504b9ad928SBarry Smith 851d01c8aa3SLisandro Dalcin pc->ops->destroy = PCDestroy_Shell; 8524b9ad928SBarry Smith pc->ops->view = PCView_Shell; 853d01c8aa3SLisandro Dalcin pc->ops->apply = PCApply_Shell; 854d01c8aa3SLisandro Dalcin pc->ops->applytranspose = 0; 8554b9ad928SBarry Smith pc->ops->applyrichardson = 0; 856d01c8aa3SLisandro Dalcin pc->ops->setup = 0; 8579bbb2c88SBarry Smith pc->ops->presolve = 0; 8589bbb2c88SBarry Smith pc->ops->postsolve = 0; 8594b9ad928SBarry Smith 8604b9ad928SBarry Smith shell->apply = 0; 8614b9ad928SBarry Smith shell->applytranspose = 0; 8624b9ad928SBarry Smith shell->name = 0; 8634b9ad928SBarry Smith shell->applyrich = 0; 8647cdd61b2SBarry Smith shell->presolve = 0; 8657cdd61b2SBarry Smith shell->postsolve = 0; 8664b9ad928SBarry Smith shell->ctx = 0; 8674b9ad928SBarry Smith shell->setup = 0; 8684b9ad928SBarry Smith shell->view = 0; 86918be62a5SSatish Balay shell->destroy = 0; 8704b9ad928SBarry Smith 871bdf89e91SBarry Smith ierr = PetscObjectComposeFunction((PetscObject)pc,"PCShellSetDestroy_C",PCShellSetDestroy_Shell);CHKERRQ(ierr); 872bdf89e91SBarry Smith ierr = PetscObjectComposeFunction((PetscObject)pc,"PCShellSetSetUp_C",PCShellSetSetUp_Shell);CHKERRQ(ierr); 873bdf89e91SBarry Smith ierr = PetscObjectComposeFunction((PetscObject)pc,"PCShellSetApply_C",PCShellSetApply_Shell);CHKERRQ(ierr); 874bdf89e91SBarry Smith ierr = PetscObjectComposeFunction((PetscObject)pc,"PCShellSetApplyBA_C",PCShellSetApplyBA_Shell);CHKERRQ(ierr); 875bdf89e91SBarry Smith ierr = PetscObjectComposeFunction((PetscObject)pc,"PCShellSetPreSolve_C",PCShellSetPreSolve_Shell);CHKERRQ(ierr); 876bdf89e91SBarry Smith ierr = PetscObjectComposeFunction((PetscObject)pc,"PCShellSetPostSolve_C",PCShellSetPostSolve_Shell);CHKERRQ(ierr); 877bdf89e91SBarry Smith ierr = PetscObjectComposeFunction((PetscObject)pc,"PCShellSetView_C",PCShellSetView_Shell);CHKERRQ(ierr); 878bdf89e91SBarry Smith ierr = PetscObjectComposeFunction((PetscObject)pc,"PCShellSetApplyTranspose_C",PCShellSetApplyTranspose_Shell);CHKERRQ(ierr); 879bdf89e91SBarry Smith ierr = PetscObjectComposeFunction((PetscObject)pc,"PCShellSetName_C",PCShellSetName_Shell);CHKERRQ(ierr); 880bdf89e91SBarry Smith ierr = PetscObjectComposeFunction((PetscObject)pc,"PCShellGetName_C",PCShellGetName_Shell);CHKERRQ(ierr); 881bdf89e91SBarry Smith ierr = PetscObjectComposeFunction((PetscObject)pc,"PCShellSetApplyRichardson_C",PCShellSetApplyRichardson_Shell);CHKERRQ(ierr); 8824b9ad928SBarry Smith PetscFunctionReturn(0); 8834b9ad928SBarry Smith } 8844b9ad928SBarry Smith 8854b9ad928SBarry Smith 8864b9ad928SBarry Smith 8874b9ad928SBarry Smith 8884b9ad928SBarry Smith 8894b9ad928SBarry Smith 890