1dba47a55SKris Buschelman #define PETSCKSP_DLL 2dba47a55SKris Buschelman 34b9ad928SBarry Smith /* 44b9ad928SBarry Smith This provides a simple shell for Fortran (and C programmers) to 54b9ad928SBarry Smith create their own preconditioner without writing much interface code. 64b9ad928SBarry Smith */ 74b9ad928SBarry Smith 86356e834SBarry Smith #include "private/pcimpl.h" /*I "petscpc.h" I*/ 91d8d5f9aSSatish Balay #include "private/vecimpl.h" 104b9ad928SBarry Smith 11ac226902SBarry Smith EXTERN_C_BEGIN 124b9ad928SBarry Smith typedef struct { 13be29d3c6SBarry Smith void *ctx; /* user provided contexts for preconditioner */ 1418be62a5SSatish Balay PetscErrorCode (*destroy)(void*); 156849ba73SBarry Smith PetscErrorCode (*setup)(void*); 166849ba73SBarry Smith PetscErrorCode (*apply)(void*,Vec,Vec); 172bb17772SBarry Smith PetscErrorCode (*applyBA)(void*,PCSide,Vec,Vec,Vec); 187cdd61b2SBarry Smith PetscErrorCode (*presolve)(void*,KSP,Vec,Vec); 197cdd61b2SBarry Smith PetscErrorCode (*postsolve)(void*,KSP,Vec,Vec); 206849ba73SBarry Smith PetscErrorCode (*view)(void*,PetscViewer); 216849ba73SBarry Smith PetscErrorCode (*applytranspose)(void*,Vec,Vec); 2213f74950SBarry Smith PetscErrorCode (*applyrich)(void*,Vec,Vec,Vec,PetscReal,PetscReal,PetscReal,PetscInt); 234b9ad928SBarry Smith char *name; 244b9ad928SBarry Smith } PC_Shell; 25ac226902SBarry Smith EXTERN_C_END 264b9ad928SBarry Smith 274b9ad928SBarry Smith #undef __FUNCT__ 28be29d3c6SBarry Smith #define __FUNCT__ "PCShellGetContext" 29b29801fcSSatish Balay /*@C 30be29d3c6SBarry Smith PCShellGetContext - Returns the user-provided context associated with a shell PC 31be29d3c6SBarry Smith 32be29d3c6SBarry Smith Not Collective 33be29d3c6SBarry Smith 34be29d3c6SBarry Smith Input Parameter: 35be29d3c6SBarry Smith . pc - should have been created with PCCreateShell() 36be29d3c6SBarry Smith 37be29d3c6SBarry Smith Output Parameter: 38be29d3c6SBarry Smith . ctx - the user provided context 39be29d3c6SBarry Smith 40be29d3c6SBarry Smith Level: advanced 41be29d3c6SBarry Smith 42be29d3c6SBarry Smith Notes: 43be29d3c6SBarry Smith This routine is intended for use within various shell routines 44be29d3c6SBarry Smith 45be29d3c6SBarry Smith .keywords: PC, shell, get, context 46be29d3c6SBarry Smith 47be29d3c6SBarry Smith .seealso: PCCreateShell(), PCShellSetContext() 48be29d3c6SBarry Smith @*/ 49be29d3c6SBarry Smith PetscErrorCode PETSCKSP_DLLEXPORT PCShellGetContext(PC pc,void **ctx) 50be29d3c6SBarry Smith { 51be29d3c6SBarry Smith PetscErrorCode ierr; 52be29d3c6SBarry Smith PetscTruth flg; 53be29d3c6SBarry Smith 54be29d3c6SBarry Smith PetscFunctionBegin; 55be29d3c6SBarry Smith PetscValidHeaderSpecific(pc,PC_COOKIE,1); 56be29d3c6SBarry Smith PetscValidPointer(ctx,2); 57be29d3c6SBarry Smith ierr = PetscTypeCompare((PetscObject)pc,PCSHELL,&flg);CHKERRQ(ierr); 58be29d3c6SBarry Smith if (!flg) *ctx = 0; 59be29d3c6SBarry Smith else *ctx = ((PC_Shell*)(pc->data))->ctx; 60be29d3c6SBarry Smith PetscFunctionReturn(0); 61be29d3c6SBarry Smith } 62be29d3c6SBarry Smith 63be29d3c6SBarry Smith #undef __FUNCT__ 64be29d3c6SBarry Smith #define __FUNCT__ "PCShellSetContext" 656895c445SBarry Smith /*@C 66be29d3c6SBarry Smith PCShellSetContext - sets the context for a shell PC 67be29d3c6SBarry Smith 68be29d3c6SBarry Smith Collective on PC 69be29d3c6SBarry Smith 70be29d3c6SBarry Smith Input Parameters: 71be29d3c6SBarry Smith + pc - the shell PC 72be29d3c6SBarry Smith - ctx - the context 73be29d3c6SBarry Smith 74be29d3c6SBarry Smith Level: advanced 75be29d3c6SBarry Smith 76be29d3c6SBarry Smith Fortran Notes: The context can only be an integer or a PetscObject 77be29d3c6SBarry Smith unfortunately it cannot be a Fortran array or derived type. 78be29d3c6SBarry Smith 796895c445SBarry Smith 80be29d3c6SBarry Smith .seealso: PCCreateShell(), PCShellGetContext() 81be29d3c6SBarry Smith @*/ 82be29d3c6SBarry Smith PetscErrorCode PETSCKSP_DLLEXPORT PCShellSetContext(PC pc,void *ctx) 83be29d3c6SBarry Smith { 84d01c8aa3SLisandro Dalcin PC_Shell *shell; 85be29d3c6SBarry Smith PetscErrorCode ierr; 86be29d3c6SBarry Smith PetscTruth flg; 87be29d3c6SBarry Smith 88be29d3c6SBarry Smith PetscFunctionBegin; 89be29d3c6SBarry Smith PetscValidHeaderSpecific(pc,PC_COOKIE,1); 90d01c8aa3SLisandro Dalcin shell = (PC_Shell*)pc->data; 91be29d3c6SBarry Smith ierr = PetscTypeCompare((PetscObject)pc,PCSHELL,&flg);CHKERRQ(ierr); 92be29d3c6SBarry Smith if (flg) { 93be29d3c6SBarry Smith shell->ctx = ctx; 94be29d3c6SBarry Smith } 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 { 1024b9ad928SBarry Smith PC_Shell *shell; 103dfbe8321SBarry Smith PetscErrorCode ierr; 1044b9ad928SBarry Smith 1054b9ad928SBarry Smith PetscFunctionBegin; 1064b9ad928SBarry Smith shell = (PC_Shell*)pc->data; 107d01c8aa3SLisandro Dalcin if (!shell->setup) SETERRQ(PETSC_ERR_USER,"No setup() routine provided to Shell PC"); 108d01c8aa3SLisandro Dalcin PetscStackPush("PCSHELL user function setup()"); 109e9a2bbcdSBarry Smith CHKMEMQ; 1104b9ad928SBarry Smith ierr = (*shell->setup)(shell->ctx);CHKERRQ(ierr); 111e9a2bbcdSBarry Smith CHKMEMQ; 112d01c8aa3SLisandro Dalcin PetscStackPop; 1134b9ad928SBarry Smith PetscFunctionReturn(0); 1144b9ad928SBarry Smith } 1154b9ad928SBarry Smith 1164b9ad928SBarry Smith #undef __FUNCT__ 1174b9ad928SBarry Smith #define __FUNCT__ "PCApply_Shell" 1186849ba73SBarry Smith static PetscErrorCode PCApply_Shell(PC pc,Vec x,Vec y) 1194b9ad928SBarry Smith { 1204b9ad928SBarry Smith PC_Shell *shell; 121dfbe8321SBarry Smith PetscErrorCode ierr; 1224b9ad928SBarry Smith 1234b9ad928SBarry Smith PetscFunctionBegin; 1244b9ad928SBarry Smith shell = (PC_Shell*)pc->data; 1251302d50aSBarry Smith if (!shell->apply) SETERRQ(PETSC_ERR_USER,"No apply() routine provided to Shell PC"); 126d01c8aa3SLisandro Dalcin PetscStackPush("PCSHELL user function apply()"); 127e9a2bbcdSBarry Smith CHKMEMQ; 1284b9ad928SBarry Smith ierr = (*shell->apply)(shell->ctx,x,y);CHKERRQ(ierr); 129e9a2bbcdSBarry Smith CHKMEMQ; 130e9a2bbcdSBarry Smith PetscStackPop; 1314b9ad928SBarry Smith PetscFunctionReturn(0); 1324b9ad928SBarry Smith } 1334b9ad928SBarry Smith 1344b9ad928SBarry Smith #undef __FUNCT__ 1352bb17772SBarry Smith #define __FUNCT__ "PCApplyBA_Shell" 1362bb17772SBarry Smith static PetscErrorCode PCApplyBA_Shell(PC pc,PCSide side,Vec x,Vec y,Vec w) 1372bb17772SBarry Smith { 1382bb17772SBarry Smith PC_Shell *shell; 1392bb17772SBarry Smith PetscErrorCode ierr; 1402bb17772SBarry Smith 1412bb17772SBarry Smith PetscFunctionBegin; 1422bb17772SBarry Smith shell = (PC_Shell*)pc->data; 1432bb17772SBarry Smith if (!shell->applyBA) SETERRQ(PETSC_ERR_USER,"No applyBA() routine provided to Shell PC"); 144d01c8aa3SLisandro Dalcin PetscStackPush("PCSHELL user function applyBA()"); 1452bb17772SBarry Smith CHKMEMQ; 1462bb17772SBarry Smith ierr = (*shell->applyBA)(shell->ctx,side,x,y,w);CHKERRQ(ierr); 1472bb17772SBarry Smith CHKMEMQ; 1482bb17772SBarry Smith PetscStackPop; 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 { 1567cdd61b2SBarry Smith PC_Shell *shell; 1577cdd61b2SBarry Smith PetscErrorCode ierr; 1587cdd61b2SBarry Smith 1597cdd61b2SBarry Smith PetscFunctionBegin; 1607cdd61b2SBarry Smith shell = (PC_Shell*)pc->data; 16191ad8336SSatish Balay if (!shell->presolve) SETERRQ(PETSC_ERR_USER,"No presolve() routine provided to Shell PC"); 162d01c8aa3SLisandro Dalcin PetscStackPush("PCSHELL user function presolve()"); 163d01c8aa3SLisandro Dalcin CHKMEMQ; 1647cdd61b2SBarry Smith ierr = (*shell->presolve)(shell->ctx,ksp,b,x);CHKERRQ(ierr); 165d01c8aa3SLisandro Dalcin CHKMEMQ; 166d01c8aa3SLisandro Dalcin PetscStackPop; 1677cdd61b2SBarry Smith PetscFunctionReturn(0); 1687cdd61b2SBarry Smith } 1697cdd61b2SBarry Smith 1707cdd61b2SBarry Smith #undef __FUNCT__ 1717cdd61b2SBarry Smith #define __FUNCT__ "PCPostSolve_Shell" 1727cdd61b2SBarry Smith static PetscErrorCode PCPostSolve_Shell(PC pc,KSP ksp,Vec b,Vec x) 1737cdd61b2SBarry Smith { 1747cdd61b2SBarry Smith PC_Shell *shell; 1757cdd61b2SBarry Smith PetscErrorCode ierr; 1767cdd61b2SBarry Smith 1777cdd61b2SBarry Smith PetscFunctionBegin; 1787cdd61b2SBarry Smith shell = (PC_Shell*)pc->data; 17991ad8336SSatish Balay if (!shell->postsolve) SETERRQ(PETSC_ERR_USER,"No postsolve() routine provided to Shell PC"); 180d01c8aa3SLisandro Dalcin PetscStackPush("PCSHELL user function postsolve()"); 181d01c8aa3SLisandro Dalcin CHKMEMQ; 18291ad8336SSatish Balay ierr = (*shell->postsolve)(shell->ctx,ksp,b,x);CHKERRQ(ierr); 183d01c8aa3SLisandro Dalcin CHKMEMQ; 184d01c8aa3SLisandro Dalcin PetscStackPop; 1857cdd61b2SBarry Smith PetscFunctionReturn(0); 1867cdd61b2SBarry Smith } 1877cdd61b2SBarry Smith 1887cdd61b2SBarry Smith #undef __FUNCT__ 1894b9ad928SBarry Smith #define __FUNCT__ "PCApplyTranspose_Shell" 1906849ba73SBarry Smith static PetscErrorCode PCApplyTranspose_Shell(PC pc,Vec x,Vec y) 1914b9ad928SBarry Smith { 1924b9ad928SBarry Smith PC_Shell *shell; 193dfbe8321SBarry Smith PetscErrorCode ierr; 1944b9ad928SBarry Smith 1954b9ad928SBarry Smith PetscFunctionBegin; 1964b9ad928SBarry Smith shell = (PC_Shell*)pc->data; 1971302d50aSBarry Smith if (!shell->applytranspose) SETERRQ(PETSC_ERR_USER,"No applytranspose() routine provided to Shell PC"); 198d01c8aa3SLisandro Dalcin PetscStackPush("PCSHELL user function applytranspose()"); 199d01c8aa3SLisandro Dalcin CHKMEMQ; 2004b9ad928SBarry Smith ierr = (*shell->applytranspose)(shell->ctx,x,y);CHKERRQ(ierr); 201d01c8aa3SLisandro Dalcin CHKMEMQ; 202d01c8aa3SLisandro Dalcin PetscStackPop; 2034b9ad928SBarry Smith PetscFunctionReturn(0); 2044b9ad928SBarry Smith } 2054b9ad928SBarry Smith 2064b9ad928SBarry Smith #undef __FUNCT__ 2074b9ad928SBarry Smith #define __FUNCT__ "PCApplyRichardson_Shell" 20813f74950SBarry Smith static PetscErrorCode PCApplyRichardson_Shell(PC pc,Vec x,Vec y,Vec w,PetscReal rtol,PetscReal abstol, PetscReal dtol,PetscInt it) 2094b9ad928SBarry Smith { 210dfbe8321SBarry Smith PetscErrorCode ierr; 2114b9ad928SBarry Smith PC_Shell *shell; 2124b9ad928SBarry Smith 2134b9ad928SBarry Smith PetscFunctionBegin; 2144b9ad928SBarry Smith shell = (PC_Shell*)pc->data; 215d01c8aa3SLisandro Dalcin if (!shell->applyrich) SETERRQ(PETSC_ERR_USER,"No applyrichardson() routine provided to Shell PC"); 216d01c8aa3SLisandro Dalcin PetscStackPush("PCSHELL user function applyrichardson()"); 217d01c8aa3SLisandro Dalcin CHKMEMQ; 218be29d3c6SBarry Smith ierr = (*shell->applyrich)(shell->ctx,x,y,w,rtol,abstol,dtol,it);CHKERRQ(ierr); 219d01c8aa3SLisandro Dalcin CHKMEMQ; 220d01c8aa3SLisandro Dalcin PetscStackPop; 2214b9ad928SBarry Smith PetscFunctionReturn(0); 2224b9ad928SBarry Smith } 2234b9ad928SBarry Smith 2244b9ad928SBarry Smith #undef __FUNCT__ 2254b9ad928SBarry Smith #define __FUNCT__ "PCDestroy_Shell" 2266849ba73SBarry Smith static PetscErrorCode PCDestroy_Shell(PC pc) 2274b9ad928SBarry Smith { 2284b9ad928SBarry Smith PC_Shell *shell = (PC_Shell*)pc->data; 229dfbe8321SBarry Smith PetscErrorCode ierr; 2304b9ad928SBarry Smith 2314b9ad928SBarry Smith PetscFunctionBegin; 23205b42c5fSBarry Smith ierr = PetscStrfree(shell->name);CHKERRQ(ierr); 23318be62a5SSatish Balay if (shell->destroy) { 23418be62a5SSatish Balay ierr = (*shell->destroy)(shell->ctx);CHKERRQ(ierr); 23518be62a5SSatish Balay } 2364b9ad928SBarry Smith ierr = PetscFree(shell);CHKERRQ(ierr); 2374b9ad928SBarry Smith PetscFunctionReturn(0); 2384b9ad928SBarry Smith } 2394b9ad928SBarry Smith 2404b9ad928SBarry Smith #undef __FUNCT__ 2414b9ad928SBarry Smith #define __FUNCT__ "PCView_Shell" 2426849ba73SBarry Smith static PetscErrorCode PCView_Shell(PC pc,PetscViewer viewer) 2434b9ad928SBarry Smith { 2444b9ad928SBarry Smith PC_Shell *shell = (PC_Shell*)pc->data; 245dfbe8321SBarry Smith PetscErrorCode ierr; 24632077d6dSBarry Smith PetscTruth iascii; 2474b9ad928SBarry Smith 2484b9ad928SBarry Smith PetscFunctionBegin; 24932077d6dSBarry Smith ierr = PetscTypeCompare((PetscObject)viewer,PETSC_VIEWER_ASCII,&iascii);CHKERRQ(ierr); 25032077d6dSBarry Smith if (iascii) { 2514b9ad928SBarry Smith if (shell->name) {ierr = PetscViewerASCIIPrintf(viewer," Shell: %s\n",shell->name);CHKERRQ(ierr);} 2524b9ad928SBarry Smith else {ierr = PetscViewerASCIIPrintf(viewer," Shell: no name\n");CHKERRQ(ierr);} 2534b9ad928SBarry Smith } 2544b9ad928SBarry Smith if (shell->view) { 2554b9ad928SBarry Smith ierr = PetscViewerASCIIPushTab(viewer);CHKERRQ(ierr); 2564b9ad928SBarry Smith ierr = (*shell->view)(shell->ctx,viewer);CHKERRQ(ierr); 2574b9ad928SBarry Smith ierr = PetscViewerASCIIPopTab(viewer);CHKERRQ(ierr); 2584b9ad928SBarry Smith } 2594b9ad928SBarry Smith PetscFunctionReturn(0); 2604b9ad928SBarry Smith } 2614b9ad928SBarry Smith 2624b9ad928SBarry Smith /* ------------------------------------------------------------------------------*/ 2634b9ad928SBarry Smith EXTERN_C_BEGIN 2644b9ad928SBarry Smith #undef __FUNCT__ 26518be62a5SSatish Balay #define __FUNCT__ "PCShellSetDestroy_Shell" 26618be62a5SSatish Balay PetscErrorCode PETSCKSP_DLLEXPORT PCShellSetDestroy_Shell(PC pc, PetscErrorCode (*destroy)(void*)) 26718be62a5SSatish Balay { 26818be62a5SSatish Balay PC_Shell *shell; 26918be62a5SSatish Balay 27018be62a5SSatish Balay PetscFunctionBegin; 27118be62a5SSatish Balay shell = (PC_Shell*)pc->data; 27218be62a5SSatish Balay shell->destroy = destroy; 27318be62a5SSatish Balay PetscFunctionReturn(0); 27418be62a5SSatish Balay } 27518be62a5SSatish Balay EXTERN_C_END 27618be62a5SSatish Balay 27718be62a5SSatish Balay EXTERN_C_BEGIN 27818be62a5SSatish Balay #undef __FUNCT__ 2794b9ad928SBarry Smith #define __FUNCT__ "PCShellSetSetUp_Shell" 280dba47a55SKris Buschelman PetscErrorCode PETSCKSP_DLLEXPORT PCShellSetSetUp_Shell(PC pc, PetscErrorCode (*setup)(void*)) 2814b9ad928SBarry Smith { 2824b9ad928SBarry Smith PC_Shell *shell; 2834b9ad928SBarry Smith 2844b9ad928SBarry Smith PetscFunctionBegin; 2854b9ad928SBarry Smith shell = (PC_Shell*)pc->data; 2864b9ad928SBarry Smith shell->setup = setup; 287d01c8aa3SLisandro Dalcin if (setup) pc->ops->setup = PCSetUp_Shell; 288d01c8aa3SLisandro Dalcin else pc->ops->setup = 0; 2894b9ad928SBarry Smith PetscFunctionReturn(0); 2904b9ad928SBarry Smith } 2914b9ad928SBarry Smith EXTERN_C_END 2924b9ad928SBarry Smith 2934b9ad928SBarry Smith EXTERN_C_BEGIN 2944b9ad928SBarry Smith #undef __FUNCT__ 2954b9ad928SBarry Smith #define __FUNCT__ "PCShellSetApply_Shell" 296be29d3c6SBarry Smith PetscErrorCode PETSCKSP_DLLEXPORT PCShellSetApply_Shell(PC pc,PetscErrorCode (*apply)(void*,Vec,Vec)) 2974b9ad928SBarry Smith { 2984b9ad928SBarry Smith PC_Shell *shell; 2994b9ad928SBarry Smith 3004b9ad928SBarry Smith PetscFunctionBegin; 3014b9ad928SBarry Smith shell = (PC_Shell*)pc->data; 3024b9ad928SBarry Smith shell->apply = apply; 3034b9ad928SBarry Smith PetscFunctionReturn(0); 3044b9ad928SBarry Smith } 3054b9ad928SBarry Smith EXTERN_C_END 3064b9ad928SBarry Smith 3074b9ad928SBarry Smith EXTERN_C_BEGIN 3084b9ad928SBarry Smith #undef __FUNCT__ 3092bb17772SBarry Smith #define __FUNCT__ "PCShellSetApplyBA_Shell" 310d01c8aa3SLisandro Dalcin PetscErrorCode PETSCKSP_DLLEXPORT PCShellSetApplyBA_Shell(PC pc,PetscErrorCode (*applyBA)(void*,PCSide,Vec,Vec,Vec)) 3112bb17772SBarry Smith { 3122bb17772SBarry Smith PC_Shell *shell; 3132bb17772SBarry Smith 3142bb17772SBarry Smith PetscFunctionBegin; 3152bb17772SBarry Smith shell = (PC_Shell*)pc->data; 316d01c8aa3SLisandro Dalcin shell->applyBA = applyBA; 317d01c8aa3SLisandro Dalcin if (applyBA) pc->ops->applyBA = PCApplyBA_Shell; 318aef0136fSBarry Smith else pc->ops->applyBA = 0; 3192bb17772SBarry Smith PetscFunctionReturn(0); 3202bb17772SBarry Smith } 3212bb17772SBarry Smith EXTERN_C_END 3222bb17772SBarry Smith 3232bb17772SBarry Smith EXTERN_C_BEGIN 3242bb17772SBarry Smith #undef __FUNCT__ 3257cdd61b2SBarry Smith #define __FUNCT__ "PCShellSetPreSolve_Shell" 326be29d3c6SBarry Smith PetscErrorCode PETSCKSP_DLLEXPORT PCShellSetPreSolve_Shell(PC pc,PetscErrorCode (*presolve)(void*,KSP,Vec,Vec)) 3277cdd61b2SBarry Smith { 3287cdd61b2SBarry Smith PC_Shell *shell; 3297cdd61b2SBarry Smith 3307cdd61b2SBarry Smith PetscFunctionBegin; 3317cdd61b2SBarry Smith shell = (PC_Shell*)pc->data; 3327cdd61b2SBarry Smith shell->presolve = presolve; 333d01c8aa3SLisandro Dalcin if (presolve) pc->ops->presolve = PCPreSolve_Shell; 334d01c8aa3SLisandro Dalcin else pc->ops->presolve = 0; 3357cdd61b2SBarry Smith PetscFunctionReturn(0); 3367cdd61b2SBarry Smith } 3377cdd61b2SBarry Smith EXTERN_C_END 3387cdd61b2SBarry Smith 3397cdd61b2SBarry Smith EXTERN_C_BEGIN 3407cdd61b2SBarry Smith #undef __FUNCT__ 3417cdd61b2SBarry Smith #define __FUNCT__ "PCShellSetPostSolve_Shell" 342be29d3c6SBarry Smith PetscErrorCode PETSCKSP_DLLEXPORT PCShellSetPostSolve_Shell(PC pc,PetscErrorCode (*postsolve)(void*,KSP,Vec,Vec)) 3437cdd61b2SBarry Smith { 3447cdd61b2SBarry Smith PC_Shell *shell; 3457cdd61b2SBarry Smith 3467cdd61b2SBarry Smith PetscFunctionBegin; 3477cdd61b2SBarry Smith shell = (PC_Shell*)pc->data; 3487cdd61b2SBarry Smith shell->postsolve = postsolve; 349d01c8aa3SLisandro Dalcin if (postsolve) pc->ops->postsolve = PCPostSolve_Shell; 350d01c8aa3SLisandro Dalcin else pc->ops->postsolve = 0; 3517cdd61b2SBarry Smith PetscFunctionReturn(0); 3527cdd61b2SBarry Smith } 3537cdd61b2SBarry Smith EXTERN_C_END 3547cdd61b2SBarry Smith 3557cdd61b2SBarry Smith EXTERN_C_BEGIN 3567cdd61b2SBarry Smith #undef __FUNCT__ 3574b9ad928SBarry Smith #define __FUNCT__ "PCShellSetView_Shell" 358dba47a55SKris Buschelman PetscErrorCode PETSCKSP_DLLEXPORT PCShellSetView_Shell(PC pc,PetscErrorCode (*view)(void*,PetscViewer)) 3594b9ad928SBarry Smith { 3604b9ad928SBarry Smith PC_Shell *shell; 3614b9ad928SBarry Smith 3624b9ad928SBarry Smith PetscFunctionBegin; 3634b9ad928SBarry Smith shell = (PC_Shell*)pc->data; 3644b9ad928SBarry Smith shell->view = view; 3654b9ad928SBarry Smith PetscFunctionReturn(0); 3664b9ad928SBarry Smith } 3674b9ad928SBarry Smith EXTERN_C_END 3684b9ad928SBarry Smith 3694b9ad928SBarry Smith EXTERN_C_BEGIN 3704b9ad928SBarry Smith #undef __FUNCT__ 3714b9ad928SBarry Smith #define __FUNCT__ "PCShellSetApplyTranspose_Shell" 372dba47a55SKris Buschelman PetscErrorCode PETSCKSP_DLLEXPORT PCShellSetApplyTranspose_Shell(PC pc,PetscErrorCode (*applytranspose)(void*,Vec,Vec)) 3734b9ad928SBarry Smith { 3744b9ad928SBarry Smith PC_Shell *shell; 3754b9ad928SBarry Smith 3764b9ad928SBarry Smith PetscFunctionBegin; 3774b9ad928SBarry Smith shell = (PC_Shell*)pc->data; 3784b9ad928SBarry Smith shell->applytranspose = applytranspose; 379d01c8aa3SLisandro Dalcin if (applytranspose) pc->ops->applytranspose = PCApplyTranspose_Shell; 380d01c8aa3SLisandro Dalcin else pc->ops->applytranspose = 0; 381d01c8aa3SLisandro Dalcin PetscFunctionReturn(0); 382d01c8aa3SLisandro Dalcin } 383d01c8aa3SLisandro Dalcin EXTERN_C_END 384d01c8aa3SLisandro Dalcin 385d01c8aa3SLisandro Dalcin EXTERN_C_BEGIN 386d01c8aa3SLisandro Dalcin #undef __FUNCT__ 387d01c8aa3SLisandro Dalcin #define __FUNCT__ "PCShellSetApplyRichardson_Shell" 388d01c8aa3SLisandro Dalcin PetscErrorCode PETSCKSP_DLLEXPORT PCShellSetApplyRichardson_Shell(PC pc,PetscErrorCode (*applyrich)(void*,Vec,Vec,Vec,PetscReal,PetscReal,PetscReal,PetscInt)) 389d01c8aa3SLisandro Dalcin { 390d01c8aa3SLisandro Dalcin PC_Shell *shell; 391d01c8aa3SLisandro Dalcin 392d01c8aa3SLisandro Dalcin PetscFunctionBegin; 393d01c8aa3SLisandro Dalcin shell = (PC_Shell*)pc->data; 394d01c8aa3SLisandro Dalcin shell->applyrich = applyrich; 395d01c8aa3SLisandro Dalcin if (applyrich) pc->ops->applyrichardson = PCApplyRichardson_Shell; 396d01c8aa3SLisandro Dalcin else pc->ops->applyrichardson = 0; 3974b9ad928SBarry Smith PetscFunctionReturn(0); 3984b9ad928SBarry Smith } 3994b9ad928SBarry Smith EXTERN_C_END 4004b9ad928SBarry Smith 4014b9ad928SBarry Smith EXTERN_C_BEGIN 4024b9ad928SBarry Smith #undef __FUNCT__ 4034b9ad928SBarry Smith #define __FUNCT__ "PCShellSetName_Shell" 404dba47a55SKris Buschelman PetscErrorCode PETSCKSP_DLLEXPORT PCShellSetName_Shell(PC pc,const char name[]) 4054b9ad928SBarry Smith { 4064b9ad928SBarry Smith PC_Shell *shell; 407dfbe8321SBarry Smith PetscErrorCode ierr; 4084b9ad928SBarry Smith 4094b9ad928SBarry Smith PetscFunctionBegin; 4104b9ad928SBarry Smith shell = (PC_Shell*)pc->data; 411f259bd47SBarry Smith ierr = PetscStrfree(shell->name);CHKERRQ(ierr); 4124b9ad928SBarry Smith ierr = PetscStrallocpy(name,&shell->name);CHKERRQ(ierr); 4134b9ad928SBarry Smith PetscFunctionReturn(0); 4144b9ad928SBarry Smith } 4154b9ad928SBarry Smith EXTERN_C_END 4164b9ad928SBarry Smith 4174b9ad928SBarry Smith EXTERN_C_BEGIN 4184b9ad928SBarry Smith #undef __FUNCT__ 4194b9ad928SBarry Smith #define __FUNCT__ "PCShellGetName_Shell" 420dba47a55SKris Buschelman PetscErrorCode PETSCKSP_DLLEXPORT PCShellGetName_Shell(PC pc,char *name[]) 4214b9ad928SBarry Smith { 4224b9ad928SBarry Smith PC_Shell *shell; 4234b9ad928SBarry Smith 4244b9ad928SBarry Smith PetscFunctionBegin; 4254b9ad928SBarry Smith shell = (PC_Shell*)pc->data; 4264b9ad928SBarry Smith *name = shell->name; 4274b9ad928SBarry Smith PetscFunctionReturn(0); 4284b9ad928SBarry Smith } 4294b9ad928SBarry Smith EXTERN_C_END 4304b9ad928SBarry Smith 4314b9ad928SBarry Smith /* -------------------------------------------------------------------------------*/ 4324b9ad928SBarry Smith 4334b9ad928SBarry Smith #undef __FUNCT__ 43418be62a5SSatish Balay #define __FUNCT__ "PCShellSetDestroy" 43518be62a5SSatish Balay /*@C 43618be62a5SSatish Balay PCShellSetDestroy - Sets routine to use to destroy the user-provided 43718be62a5SSatish Balay application context. 43818be62a5SSatish Balay 43918be62a5SSatish Balay Collective on PC 44018be62a5SSatish Balay 44118be62a5SSatish Balay Input Parameters: 44218be62a5SSatish Balay + pc - the preconditioner context 44318be62a5SSatish Balay . destroy - the application-provided destroy routine 44418be62a5SSatish Balay 44518be62a5SSatish Balay Calling sequence of destroy: 44618be62a5SSatish Balay .vb 44718be62a5SSatish Balay PetscErrorCode destroy (void *ptr) 44818be62a5SSatish Balay .ve 44918be62a5SSatish Balay 45018be62a5SSatish Balay . ptr - the application context 45118be62a5SSatish Balay 452*4aa34b0aSBarry Smith Notes: the function MUST return an error code of 0 on success and nonzero on failure. 453*4aa34b0aSBarry Smith 45418be62a5SSatish Balay Level: developer 45518be62a5SSatish Balay 45618be62a5SSatish Balay .keywords: PC, shell, set, destroy, user-provided 45718be62a5SSatish Balay 45818be62a5SSatish Balay .seealso: PCShellSetApply(), PCShellSetContext() 45918be62a5SSatish Balay @*/ 46018be62a5SSatish Balay PetscErrorCode PETSCKSP_DLLEXPORT PCShellSetDestroy(PC pc,PetscErrorCode (*destroy)(void*)) 46118be62a5SSatish Balay { 46218be62a5SSatish Balay PetscErrorCode ierr,(*f)(PC,PetscErrorCode (*)(void*)); 46318be62a5SSatish Balay 46418be62a5SSatish Balay PetscFunctionBegin; 46518be62a5SSatish Balay PetscValidHeaderSpecific(pc,PC_COOKIE,1); 46618be62a5SSatish Balay ierr = PetscObjectQueryFunction((PetscObject)pc,"PCShellSetDestroy_C",(void (**)(void))&f);CHKERRQ(ierr); 46718be62a5SSatish Balay if (f) { 46818be62a5SSatish Balay ierr = (*f)(pc,destroy);CHKERRQ(ierr); 46918be62a5SSatish Balay } 47018be62a5SSatish Balay PetscFunctionReturn(0); 47118be62a5SSatish Balay } 47218be62a5SSatish Balay 47318be62a5SSatish Balay 47418be62a5SSatish Balay #undef __FUNCT__ 4754b9ad928SBarry Smith #define __FUNCT__ "PCShellSetSetUp" 4764b9ad928SBarry Smith /*@C 4774b9ad928SBarry Smith PCShellSetSetUp - Sets routine to use to "setup" the preconditioner whenever the 4784b9ad928SBarry Smith matrix operator is changed. 4794b9ad928SBarry Smith 4804b9ad928SBarry Smith Collective on PC 4814b9ad928SBarry Smith 4824b9ad928SBarry Smith Input Parameters: 4834b9ad928SBarry Smith + pc - the preconditioner context 4844b9ad928SBarry Smith . setup - the application-provided setup routine 4854b9ad928SBarry Smith 4864b9ad928SBarry Smith Calling sequence of setup: 4874b9ad928SBarry Smith .vb 48813f74950SBarry Smith PetscErrorCode setup (void *ptr) 4894b9ad928SBarry Smith .ve 4904b9ad928SBarry Smith 4914b9ad928SBarry Smith . ptr - the application context 4924b9ad928SBarry Smith 493*4aa34b0aSBarry Smith Notes: the function MUST return an error code of 0 on success and nonzero on failure. 494*4aa34b0aSBarry Smith 4954b9ad928SBarry Smith Level: developer 4964b9ad928SBarry Smith 4974b9ad928SBarry Smith .keywords: PC, shell, set, setup, user-provided 4984b9ad928SBarry Smith 499be29d3c6SBarry Smith .seealso: PCShellSetApplyRichardson(), PCShellSetApply(), PCShellSetContext() 5004b9ad928SBarry Smith @*/ 501dba47a55SKris Buschelman PetscErrorCode PETSCKSP_DLLEXPORT PCShellSetSetUp(PC pc,PetscErrorCode (*setup)(void*)) 5024b9ad928SBarry Smith { 5036849ba73SBarry Smith PetscErrorCode ierr,(*f)(PC,PetscErrorCode (*)(void*)); 5044b9ad928SBarry Smith 5054b9ad928SBarry Smith PetscFunctionBegin; 5064482741eSBarry Smith PetscValidHeaderSpecific(pc,PC_COOKIE,1); 5074b9ad928SBarry Smith ierr = PetscObjectQueryFunction((PetscObject)pc,"PCShellSetSetUp_C",(void (**)(void))&f);CHKERRQ(ierr); 5084b9ad928SBarry Smith if (f) { 5094b9ad928SBarry Smith ierr = (*f)(pc,setup);CHKERRQ(ierr); 5104b9ad928SBarry Smith } 5114b9ad928SBarry Smith PetscFunctionReturn(0); 5124b9ad928SBarry Smith } 5134b9ad928SBarry Smith 5144b9ad928SBarry Smith 5154b9ad928SBarry Smith #undef __FUNCT__ 5164b9ad928SBarry Smith #define __FUNCT__ "PCShellSetView" 5174b9ad928SBarry Smith /*@C 5184b9ad928SBarry Smith PCShellSetView - Sets routine to use as viewer of shell preconditioner 5194b9ad928SBarry Smith 5204b9ad928SBarry Smith Collective on PC 5214b9ad928SBarry Smith 5224b9ad928SBarry Smith Input Parameters: 5234b9ad928SBarry Smith + pc - the preconditioner context 5244b9ad928SBarry Smith - view - the application-provided view routine 5254b9ad928SBarry Smith 5264b9ad928SBarry Smith Calling sequence of apply: 5274b9ad928SBarry Smith .vb 52813f74950SBarry Smith PetscErrorCode view(void *ptr,PetscViewer v) 5294b9ad928SBarry Smith .ve 5304b9ad928SBarry Smith 5314b9ad928SBarry Smith + ptr - the application context 5324b9ad928SBarry Smith - v - viewer 5334b9ad928SBarry Smith 534*4aa34b0aSBarry Smith Notes: the function MUST return an error code of 0 on success and nonzero on failure. 535*4aa34b0aSBarry Smith 5364b9ad928SBarry Smith Level: developer 5374b9ad928SBarry Smith 5384b9ad928SBarry Smith .keywords: PC, shell, set, apply, user-provided 5394b9ad928SBarry Smith 5404b9ad928SBarry Smith .seealso: PCShellSetApplyRichardson(), PCShellSetSetUp(), PCShellSetApplyTranspose() 5414b9ad928SBarry Smith @*/ 542dba47a55SKris Buschelman PetscErrorCode PETSCKSP_DLLEXPORT PCShellSetView(PC pc,PetscErrorCode (*view)(void*,PetscViewer)) 5434b9ad928SBarry Smith { 5446849ba73SBarry Smith PetscErrorCode ierr,(*f)(PC,PetscErrorCode (*)(void*,PetscViewer)); 5454b9ad928SBarry Smith 5464b9ad928SBarry Smith PetscFunctionBegin; 5474482741eSBarry Smith PetscValidHeaderSpecific(pc,PC_COOKIE,1); 5484b9ad928SBarry Smith ierr = PetscObjectQueryFunction((PetscObject)pc,"PCShellSetView_C",(void (**)(void))&f);CHKERRQ(ierr); 5494b9ad928SBarry Smith if (f) { 5504b9ad928SBarry Smith ierr = (*f)(pc,view);CHKERRQ(ierr); 5514b9ad928SBarry Smith } 5524b9ad928SBarry Smith PetscFunctionReturn(0); 5534b9ad928SBarry Smith } 5544b9ad928SBarry Smith 5554b9ad928SBarry Smith #undef __FUNCT__ 5564b9ad928SBarry Smith #define __FUNCT__ "PCShellSetApply" 5574b9ad928SBarry Smith /*@C 5584b9ad928SBarry Smith PCShellSetApply - Sets routine to use as preconditioner. 5594b9ad928SBarry Smith 5604b9ad928SBarry Smith Collective on PC 5614b9ad928SBarry Smith 5624b9ad928SBarry Smith Input Parameters: 5634b9ad928SBarry Smith + pc - the preconditioner context 564be29d3c6SBarry Smith - apply - the application-provided preconditioning routine 5654b9ad928SBarry Smith 5664b9ad928SBarry Smith Calling sequence of apply: 5674b9ad928SBarry Smith .vb 56813f74950SBarry Smith PetscErrorCode apply (void *ptr,Vec xin,Vec xout) 5694b9ad928SBarry Smith .ve 5704b9ad928SBarry Smith 5714b9ad928SBarry Smith + ptr - the application context 5724b9ad928SBarry Smith . xin - input vector 5734b9ad928SBarry Smith - xout - output vector 5744b9ad928SBarry Smith 575*4aa34b0aSBarry Smith Notes: the function MUST return an error code of 0 on success and nonzero on failure. 576*4aa34b0aSBarry Smith 5774b9ad928SBarry Smith Level: developer 5784b9ad928SBarry Smith 5794b9ad928SBarry Smith .keywords: PC, shell, set, apply, user-provided 5804b9ad928SBarry Smith 5812bb17772SBarry Smith .seealso: PCShellSetApplyRichardson(), PCShellSetSetUp(), PCShellSetApplyTranspose(), PCShellSetContext(), PCShellSetApplyBA() 5824b9ad928SBarry Smith @*/ 583be29d3c6SBarry Smith PetscErrorCode PETSCKSP_DLLEXPORT PCShellSetApply(PC pc,PetscErrorCode (*apply)(void*,Vec,Vec)) 5844b9ad928SBarry Smith { 585be29d3c6SBarry Smith PetscErrorCode ierr,(*f)(PC,PetscErrorCode (*)(void*,Vec,Vec)); 5864b9ad928SBarry Smith 5874b9ad928SBarry Smith PetscFunctionBegin; 5884482741eSBarry Smith PetscValidHeaderSpecific(pc,PC_COOKIE,1); 5894b9ad928SBarry Smith ierr = PetscObjectQueryFunction((PetscObject)pc,"PCShellSetApply_C",(void (**)(void))&f);CHKERRQ(ierr); 5904b9ad928SBarry Smith if (f) { 591be29d3c6SBarry Smith ierr = (*f)(pc,apply);CHKERRQ(ierr); 5924b9ad928SBarry Smith } 5934b9ad928SBarry Smith PetscFunctionReturn(0); 5944b9ad928SBarry Smith } 5954b9ad928SBarry Smith 5964b9ad928SBarry Smith #undef __FUNCT__ 5972bb17772SBarry Smith #define __FUNCT__ "PCShellSetApplyBA" 5982bb17772SBarry Smith /*@C 5992bb17772SBarry Smith PCShellSetApplyBA - Sets routine to use as preconditioner times operator. 6002bb17772SBarry Smith 6012bb17772SBarry Smith Collective on PC 6022bb17772SBarry Smith 6032bb17772SBarry Smith Input Parameters: 6042bb17772SBarry Smith + pc - the preconditioner context 6052bb17772SBarry Smith - applyBA - the application-provided BA routine 6062bb17772SBarry Smith 6072bb17772SBarry Smith Calling sequence of apply: 6082bb17772SBarry Smith .vb 6092bb17772SBarry Smith PetscErrorCode applyBA (void *ptr,Vec xin,Vec xout) 6102bb17772SBarry Smith .ve 6112bb17772SBarry Smith 6122bb17772SBarry Smith + ptr - the application context 6132bb17772SBarry Smith . xin - input vector 6142bb17772SBarry Smith - xout - output vector 6152bb17772SBarry Smith 616*4aa34b0aSBarry Smith Notes: the function MUST return an error code of 0 on success and nonzero on failure. 617*4aa34b0aSBarry Smith 6182bb17772SBarry Smith Level: developer 6192bb17772SBarry Smith 6202bb17772SBarry Smith .keywords: PC, shell, set, apply, user-provided 6212bb17772SBarry Smith 6222bb17772SBarry Smith .seealso: PCShellSetApplyRichardson(), PCShellSetSetUp(), PCShellSetApplyTranspose(), PCShellSetContext(), PCShellSetApply() 6232bb17772SBarry Smith @*/ 6242bb17772SBarry Smith PetscErrorCode PETSCKSP_DLLEXPORT PCShellSetApplyBA(PC pc,PetscErrorCode (*applyBA)(void*,PCSide,Vec,Vec,Vec)) 6252bb17772SBarry Smith { 6262bb17772SBarry Smith PetscErrorCode ierr,(*f)(PC,PetscErrorCode (*)(void*,PCSide,Vec,Vec,Vec)); 6272bb17772SBarry Smith 6282bb17772SBarry Smith PetscFunctionBegin; 6292bb17772SBarry Smith PetscValidHeaderSpecific(pc,PC_COOKIE,1); 6302bb17772SBarry Smith ierr = PetscObjectQueryFunction((PetscObject)pc,"PCShellSetApplyBA_C",(void (**)(void))&f);CHKERRQ(ierr); 6312bb17772SBarry Smith if (f) { 6322bb17772SBarry Smith ierr = (*f)(pc,applyBA);CHKERRQ(ierr); 6332bb17772SBarry Smith } 6342bb17772SBarry Smith PetscFunctionReturn(0); 6352bb17772SBarry Smith } 6362bb17772SBarry Smith 6372bb17772SBarry Smith #undef __FUNCT__ 6384b9ad928SBarry Smith #define __FUNCT__ "PCShellSetApplyTranspose" 6394b9ad928SBarry Smith /*@C 6404b9ad928SBarry Smith PCShellSetApplyTranspose - Sets routine to use as preconditioner transpose. 6414b9ad928SBarry Smith 6424b9ad928SBarry Smith Collective on PC 6434b9ad928SBarry Smith 6444b9ad928SBarry Smith Input Parameters: 6454b9ad928SBarry Smith + pc - the preconditioner context 6464b9ad928SBarry Smith - apply - the application-provided preconditioning transpose routine 6474b9ad928SBarry Smith 6484b9ad928SBarry Smith Calling sequence of apply: 6494b9ad928SBarry Smith .vb 65013f74950SBarry Smith PetscErrorCode applytranspose (void *ptr,Vec xin,Vec xout) 6514b9ad928SBarry Smith .ve 6524b9ad928SBarry Smith 6534b9ad928SBarry Smith + ptr - the application context 6544b9ad928SBarry Smith . xin - input vector 6554b9ad928SBarry Smith - xout - output vector 6564b9ad928SBarry Smith 657*4aa34b0aSBarry Smith Notes: the function MUST return an error code of 0 on success and nonzero on failure. 658*4aa34b0aSBarry Smith 6594b9ad928SBarry Smith Level: developer 6604b9ad928SBarry Smith 6614b9ad928SBarry Smith Notes: 6624b9ad928SBarry Smith Uses the same context variable as PCShellSetApply(). 6634b9ad928SBarry Smith 6644b9ad928SBarry Smith .keywords: PC, shell, set, apply, user-provided 6654b9ad928SBarry Smith 6662bb17772SBarry Smith .seealso: PCShellSetApplyRichardson(), PCShellSetSetUp(), PCShellSetApply(), PCSetContext(), PCShellSetApplyBA() 6674b9ad928SBarry Smith @*/ 668dba47a55SKris Buschelman PetscErrorCode PETSCKSP_DLLEXPORT PCShellSetApplyTranspose(PC pc,PetscErrorCode (*applytranspose)(void*,Vec,Vec)) 6694b9ad928SBarry Smith { 6706849ba73SBarry Smith PetscErrorCode ierr,(*f)(PC,PetscErrorCode (*)(void*,Vec,Vec)); 6714b9ad928SBarry Smith 6724b9ad928SBarry Smith PetscFunctionBegin; 6734482741eSBarry Smith PetscValidHeaderSpecific(pc,PC_COOKIE,1); 6744b9ad928SBarry Smith ierr = PetscObjectQueryFunction((PetscObject)pc,"PCShellSetApplyTranspose_C",(void (**)(void))&f);CHKERRQ(ierr); 6754b9ad928SBarry Smith if (f) { 6764b9ad928SBarry Smith ierr = (*f)(pc,applytranspose);CHKERRQ(ierr); 6774b9ad928SBarry Smith } 6784b9ad928SBarry Smith PetscFunctionReturn(0); 6794b9ad928SBarry Smith } 6804b9ad928SBarry Smith 6814b9ad928SBarry Smith #undef __FUNCT__ 6827cdd61b2SBarry Smith #define __FUNCT__ "PCShellSetPreSolve" 6837cdd61b2SBarry Smith /*@C 6847cdd61b2SBarry Smith PCShellSetPreSolve - Sets routine to apply to the operators/vectors before a KSPSolve() is 6857cdd61b2SBarry Smith applied. This usually does something like scale the linear system in some application 6867cdd61b2SBarry Smith specific way. 6877cdd61b2SBarry Smith 6887cdd61b2SBarry Smith Collective on PC 6897cdd61b2SBarry Smith 6907cdd61b2SBarry Smith Input Parameters: 6917cdd61b2SBarry Smith + pc - the preconditioner context 6927cdd61b2SBarry Smith - presolve - the application-provided presolve routine 6937cdd61b2SBarry Smith 6947cdd61b2SBarry Smith Calling sequence of presolve: 6957cdd61b2SBarry Smith .vb 6967cdd61b2SBarry Smith PetscErrorCode presolve (void *ptr,KSP ksp,Vec b,Vec x) 6977cdd61b2SBarry Smith .ve 6987cdd61b2SBarry Smith 6997cdd61b2SBarry Smith + ptr - the application context 7007cdd61b2SBarry Smith . xin - input vector 7017cdd61b2SBarry Smith - xout - output vector 7027cdd61b2SBarry Smith 703*4aa34b0aSBarry Smith Notes: the function MUST return an error code of 0 on success and nonzero on failure. 704*4aa34b0aSBarry Smith 7057cdd61b2SBarry Smith Level: developer 7067cdd61b2SBarry Smith 7077cdd61b2SBarry Smith .keywords: PC, shell, set, apply, user-provided 7087cdd61b2SBarry Smith 709be29d3c6SBarry Smith .seealso: PCShellSetApplyRichardson(), PCShellSetSetUp(), PCShellSetApplyTranspose(), PCShellSetPostSolve(), PCShellSetContext() 7107cdd61b2SBarry Smith @*/ 7117cdd61b2SBarry Smith PetscErrorCode PETSCKSP_DLLEXPORT PCShellSetPreSolve(PC pc,PetscErrorCode (*presolve)(void*,KSP,Vec,Vec)) 7127cdd61b2SBarry Smith { 7137cdd61b2SBarry Smith PetscErrorCode ierr,(*f)(PC,PetscErrorCode (*)(void*,KSP,Vec,Vec)); 7147cdd61b2SBarry Smith 7157cdd61b2SBarry Smith PetscFunctionBegin; 7167cdd61b2SBarry Smith PetscValidHeaderSpecific(pc,PC_COOKIE,1); 7177cdd61b2SBarry Smith ierr = PetscObjectQueryFunction((PetscObject)pc,"PCShellSetPreSolve_C",(void (**)(void))&f);CHKERRQ(ierr); 7187cdd61b2SBarry Smith if (f) { 7197cdd61b2SBarry Smith ierr = (*f)(pc,presolve);CHKERRQ(ierr); 7207cdd61b2SBarry Smith } 7217cdd61b2SBarry Smith PetscFunctionReturn(0); 7227cdd61b2SBarry Smith } 7237cdd61b2SBarry Smith 7247cdd61b2SBarry Smith #undef __FUNCT__ 7257cdd61b2SBarry Smith #define __FUNCT__ "PCShellSetPostSolve" 7267cdd61b2SBarry Smith /*@C 7277cdd61b2SBarry Smith PCShellSetPostSolve - Sets routine to apply to the operators/vectors before a KSPSolve() is 7287cdd61b2SBarry Smith applied. This usually does something like scale the linear system in some application 7297cdd61b2SBarry Smith specific way. 7307cdd61b2SBarry Smith 7317cdd61b2SBarry Smith Collective on PC 7327cdd61b2SBarry Smith 7337cdd61b2SBarry Smith Input Parameters: 7347cdd61b2SBarry Smith + pc - the preconditioner context 7357cdd61b2SBarry Smith - postsolve - the application-provided presolve routine 7367cdd61b2SBarry Smith 7377cdd61b2SBarry Smith Calling sequence of postsolve: 7387cdd61b2SBarry Smith .vb 7397cdd61b2SBarry Smith PetscErrorCode postsolve(void *ptr,KSP ksp,Vec b,Vec x) 7407cdd61b2SBarry Smith .ve 7417cdd61b2SBarry Smith 7427cdd61b2SBarry Smith + ptr - the application context 7437cdd61b2SBarry Smith . xin - input vector 7447cdd61b2SBarry Smith - xout - output vector 7457cdd61b2SBarry Smith 746*4aa34b0aSBarry Smith Notes: the function MUST return an error code of 0 on success and nonzero on failure. 747*4aa34b0aSBarry Smith 7487cdd61b2SBarry Smith Level: developer 7497cdd61b2SBarry Smith 7507cdd61b2SBarry Smith .keywords: PC, shell, set, apply, user-provided 7517cdd61b2SBarry Smith 752be29d3c6SBarry Smith .seealso: PCShellSetApplyRichardson(), PCShellSetSetUp(), PCShellSetApplyTranspose(), PCShellSetPreSolve(), PCShellSetContext() 7537cdd61b2SBarry Smith @*/ 7547cdd61b2SBarry Smith PetscErrorCode PETSCKSP_DLLEXPORT PCShellSetPostSolve(PC pc,PetscErrorCode (*postsolve)(void*,KSP,Vec,Vec)) 7557cdd61b2SBarry Smith { 7567cdd61b2SBarry Smith PetscErrorCode ierr,(*f)(PC,PetscErrorCode (*)(void*,KSP,Vec,Vec)); 7577cdd61b2SBarry Smith 7587cdd61b2SBarry Smith PetscFunctionBegin; 7597cdd61b2SBarry Smith PetscValidHeaderSpecific(pc,PC_COOKIE,1); 7607cdd61b2SBarry Smith ierr = PetscObjectQueryFunction((PetscObject)pc,"PCShellSetPostSolve_C",(void (**)(void))&f);CHKERRQ(ierr); 7617cdd61b2SBarry Smith if (f) { 7627cdd61b2SBarry Smith ierr = (*f)(pc,postsolve);CHKERRQ(ierr); 7637cdd61b2SBarry Smith } 7647cdd61b2SBarry Smith PetscFunctionReturn(0); 7657cdd61b2SBarry Smith } 7667cdd61b2SBarry Smith 7677cdd61b2SBarry Smith #undef __FUNCT__ 7684b9ad928SBarry Smith #define __FUNCT__ "PCShellSetName" 7694b9ad928SBarry Smith /*@C 7704b9ad928SBarry Smith PCShellSetName - Sets an optional name to associate with a shell 7714b9ad928SBarry Smith preconditioner. 7724b9ad928SBarry Smith 7734b9ad928SBarry Smith Not Collective 7744b9ad928SBarry Smith 7754b9ad928SBarry Smith Input Parameters: 7764b9ad928SBarry Smith + pc - the preconditioner context 7774b9ad928SBarry Smith - name - character string describing shell preconditioner 7784b9ad928SBarry Smith 7794b9ad928SBarry Smith Level: developer 7804b9ad928SBarry Smith 7814b9ad928SBarry Smith .keywords: PC, shell, set, name, user-provided 7824b9ad928SBarry Smith 7834b9ad928SBarry Smith .seealso: PCShellGetName() 7844b9ad928SBarry Smith @*/ 785dba47a55SKris Buschelman PetscErrorCode PETSCKSP_DLLEXPORT PCShellSetName(PC pc,const char name[]) 7864b9ad928SBarry Smith { 787dfbe8321SBarry Smith PetscErrorCode ierr,(*f)(PC,const char []); 7884b9ad928SBarry Smith 7894b9ad928SBarry Smith PetscFunctionBegin; 7904482741eSBarry Smith PetscValidHeaderSpecific(pc,PC_COOKIE,1); 7914b9ad928SBarry Smith ierr = PetscObjectQueryFunction((PetscObject)pc,"PCShellSetName_C",(void (**)(void))&f);CHKERRQ(ierr); 7924b9ad928SBarry Smith if (f) { 7934b9ad928SBarry Smith ierr = (*f)(pc,name);CHKERRQ(ierr); 7944b9ad928SBarry Smith } 7954b9ad928SBarry Smith PetscFunctionReturn(0); 7964b9ad928SBarry Smith } 7974b9ad928SBarry Smith 7984b9ad928SBarry Smith #undef __FUNCT__ 7994b9ad928SBarry Smith #define __FUNCT__ "PCShellGetName" 8004b9ad928SBarry Smith /*@C 8014b9ad928SBarry Smith PCShellGetName - Gets an optional name that the user has set for a shell 8024b9ad928SBarry Smith preconditioner. 8034b9ad928SBarry Smith 8044b9ad928SBarry Smith Not Collective 8054b9ad928SBarry Smith 8064b9ad928SBarry Smith Input Parameter: 8074b9ad928SBarry Smith . pc - the preconditioner context 8084b9ad928SBarry Smith 8094b9ad928SBarry Smith Output Parameter: 8104b9ad928SBarry Smith . name - character string describing shell preconditioner (you should not free this) 8114b9ad928SBarry Smith 8124b9ad928SBarry Smith Level: developer 8134b9ad928SBarry Smith 8144b9ad928SBarry Smith .keywords: PC, shell, get, name, user-provided 8154b9ad928SBarry Smith 8164b9ad928SBarry Smith .seealso: PCShellSetName() 8174b9ad928SBarry Smith @*/ 818dba47a55SKris Buschelman PetscErrorCode PETSCKSP_DLLEXPORT PCShellGetName(PC pc,char *name[]) 8194b9ad928SBarry Smith { 820dfbe8321SBarry Smith PetscErrorCode ierr,(*f)(PC,char *[]); 8214b9ad928SBarry Smith 8224b9ad928SBarry Smith PetscFunctionBegin; 8234482741eSBarry Smith PetscValidHeaderSpecific(pc,PC_COOKIE,1); 8244482741eSBarry Smith PetscValidPointer(name,2); 8254b9ad928SBarry Smith ierr = PetscObjectQueryFunction((PetscObject)pc,"PCShellGetName_C",(void (**)(void))&f);CHKERRQ(ierr); 8264b9ad928SBarry Smith if (f) { 8274b9ad928SBarry Smith ierr = (*f)(pc,name);CHKERRQ(ierr); 8284b9ad928SBarry Smith } else { 8291302d50aSBarry Smith SETERRQ(PETSC_ERR_ARG_WRONG,"Not shell preconditioner, cannot get name"); 8304b9ad928SBarry Smith } 8314b9ad928SBarry Smith PetscFunctionReturn(0); 8324b9ad928SBarry Smith } 8334b9ad928SBarry Smith 8344b9ad928SBarry Smith #undef __FUNCT__ 8354b9ad928SBarry Smith #define __FUNCT__ "PCShellSetApplyRichardson" 8364b9ad928SBarry Smith /*@C 8374b9ad928SBarry Smith PCShellSetApplyRichardson - Sets routine to use as preconditioner 8384b9ad928SBarry Smith in Richardson iteration. 8394b9ad928SBarry Smith 8404b9ad928SBarry Smith Collective on PC 8414b9ad928SBarry Smith 8424b9ad928SBarry Smith Input Parameters: 8434b9ad928SBarry Smith + pc - the preconditioner context 844be29d3c6SBarry Smith - apply - the application-provided preconditioning routine 8454b9ad928SBarry Smith 8464b9ad928SBarry Smith Calling sequence of apply: 8474b9ad928SBarry Smith .vb 84813f74950SBarry Smith PetscErrorCode apply (void *ptr,Vec b,Vec x,Vec r,PetscReal rtol,PetscReal abstol,PetscReal dtol,PetscInt maxits) 8494b9ad928SBarry Smith .ve 8504b9ad928SBarry Smith 8514b9ad928SBarry Smith + ptr - the application context 8524b9ad928SBarry Smith . b - right-hand-side 8534b9ad928SBarry Smith . x - current iterate 8544b9ad928SBarry Smith . r - work space 8554b9ad928SBarry Smith . rtol - relative tolerance of residual norm to stop at 85670441072SBarry Smith . abstol - absolute tolerance of residual norm to stop at 8574b9ad928SBarry Smith . dtol - if residual norm increases by this factor than return 8584b9ad928SBarry Smith - maxits - number of iterations to run 8594b9ad928SBarry Smith 860*4aa34b0aSBarry Smith Notes: the function MUST return an error code of 0 on success and nonzero on failure. 861*4aa34b0aSBarry Smith 8624b9ad928SBarry Smith Level: developer 8634b9ad928SBarry Smith 8644b9ad928SBarry Smith .keywords: PC, shell, set, apply, Richardson, user-provided 8654b9ad928SBarry Smith 866be29d3c6SBarry Smith .seealso: PCShellSetApply(), PCShellSetContext() 8674b9ad928SBarry Smith @*/ 868be29d3c6SBarry Smith PetscErrorCode PETSCKSP_DLLEXPORT PCShellSetApplyRichardson(PC pc,PetscErrorCode (*apply)(void*,Vec,Vec,Vec,PetscReal,PetscReal,PetscReal,PetscInt)) 8694b9ad928SBarry Smith { 870be29d3c6SBarry Smith PetscErrorCode ierr,(*f)(PC,PetscErrorCode (*)(void*,Vec,Vec,Vec,PetscReal,PetscReal,PetscReal,PetscInt)); 8714b9ad928SBarry Smith 8724b9ad928SBarry Smith PetscFunctionBegin; 8734482741eSBarry Smith PetscValidHeaderSpecific(pc,PC_COOKIE,1); 8744b9ad928SBarry Smith ierr = PetscObjectQueryFunction((PetscObject)pc,"PCShellSetApplyRichardson_C",(void (**)(void))&f);CHKERRQ(ierr); 8754b9ad928SBarry Smith if (f) { 876be29d3c6SBarry Smith ierr = (*f)(pc,apply);CHKERRQ(ierr); 8774b9ad928SBarry Smith } 8784b9ad928SBarry Smith PetscFunctionReturn(0); 8794b9ad928SBarry Smith } 8804b9ad928SBarry Smith 8814b9ad928SBarry Smith /*MC 8824b9ad928SBarry Smith PCSHELL - Creates a new preconditioner class for use with your 8834b9ad928SBarry Smith own private data storage format. 8844b9ad928SBarry Smith 8854b9ad928SBarry Smith Level: advanced 88690198e61SBarry Smith > 8874b9ad928SBarry Smith Concepts: providing your own preconditioner 8884b9ad928SBarry Smith 8894b9ad928SBarry Smith Usage: 8906849ba73SBarry Smith $ PetscErrorCode (*mult)(void*,Vec,Vec); 8916849ba73SBarry Smith $ PetscErrorCode (*setup)(void*); 8924b9ad928SBarry Smith $ PCCreate(comm,&pc); 8934b9ad928SBarry Smith $ PCSetType(pc,PCSHELL); 894d01c8aa3SLisandro Dalcin $ PCShellSetApply(pc,apply); 895d01c8aa3SLisandro Dalcin $ PCShellSetApplyBA(pc,apply); (optional) 896d01c8aa3SLisandro Dalcin $ PCShellSetApplyTranspose(pc,apply); (optional) 897be29d3c6SBarry Smith $ PCShellSetContext(pc,ctx) 8984b9ad928SBarry Smith $ PCShellSetSetUp(pc,setup); (optional) 899d01c8aa3SLisandro Dalcin $ PCShellSetDestroy(pc,destroy); (optional) 9004b9ad928SBarry Smith 9014b9ad928SBarry Smith .seealso: PCCreate(), PCSetType(), PCType (for list of available types), PC, 902fd2d0fe1Svictor MATSHELL, PCShellSetSetUp(), PCShellSetApply(), PCShellSetView(), 903fd2d0fe1Svictor PCShellSetApplyTranspose(), PCShellSetName(), PCShellSetApplyRichardson(), 9042bb17772SBarry Smith PCShellGetName(), PCShellSetContext(), PCShellGetContext(), PCShellSetApplyBA() 9054b9ad928SBarry Smith M*/ 9064b9ad928SBarry Smith 9074b9ad928SBarry Smith EXTERN_C_BEGIN 9084b9ad928SBarry Smith #undef __FUNCT__ 9094b9ad928SBarry Smith #define __FUNCT__ "PCCreate_Shell" 910dba47a55SKris Buschelman PetscErrorCode PETSCKSP_DLLEXPORT PCCreate_Shell(PC pc) 9114b9ad928SBarry Smith { 912dfbe8321SBarry Smith PetscErrorCode ierr; 9134b9ad928SBarry Smith PC_Shell *shell; 9144b9ad928SBarry Smith 9154b9ad928SBarry Smith PetscFunctionBegin; 91638f2d2fdSLisandro Dalcin ierr = PetscNewLog(pc,PC_Shell,&shell);CHKERRQ(ierr); 9174b9ad928SBarry Smith pc->data = (void*)shell; 9184b9ad928SBarry Smith 919d01c8aa3SLisandro Dalcin pc->ops->destroy = PCDestroy_Shell; 9204b9ad928SBarry Smith pc->ops->view = PCView_Shell; 921d01c8aa3SLisandro Dalcin pc->ops->apply = PCApply_Shell; 922d01c8aa3SLisandro Dalcin pc->ops->applytranspose = 0; 9234b9ad928SBarry Smith pc->ops->applyrichardson = 0; 924d01c8aa3SLisandro Dalcin pc->ops->setup = 0; 9259bbb2c88SBarry Smith pc->ops->presolve = 0; 9269bbb2c88SBarry Smith pc->ops->postsolve = 0; 9274b9ad928SBarry Smith 9284b9ad928SBarry Smith shell->apply = 0; 9294b9ad928SBarry Smith shell->applytranspose = 0; 9304b9ad928SBarry Smith shell->name = 0; 9314b9ad928SBarry Smith shell->applyrich = 0; 9327cdd61b2SBarry Smith shell->presolve = 0; 9337cdd61b2SBarry Smith shell->postsolve = 0; 9344b9ad928SBarry Smith shell->ctx = 0; 9354b9ad928SBarry Smith shell->setup = 0; 9364b9ad928SBarry Smith shell->view = 0; 93718be62a5SSatish Balay shell->destroy = 0; 9384b9ad928SBarry Smith 93918be62a5SSatish Balay ierr = PetscObjectComposeFunctionDynamic((PetscObject)pc,"PCShellSetDestroy_C","PCShellSetDestroy_Shell", 94018be62a5SSatish Balay PCShellSetDestroy_Shell);CHKERRQ(ierr); 9414b9ad928SBarry Smith ierr = PetscObjectComposeFunctionDynamic((PetscObject)pc,"PCShellSetSetUp_C","PCShellSetSetUp_Shell", 9424b9ad928SBarry Smith PCShellSetSetUp_Shell);CHKERRQ(ierr); 9434b9ad928SBarry Smith ierr = PetscObjectComposeFunctionDynamic((PetscObject)pc,"PCShellSetApply_C","PCShellSetApply_Shell", 9444b9ad928SBarry Smith PCShellSetApply_Shell);CHKERRQ(ierr); 9452bb17772SBarry Smith ierr = PetscObjectComposeFunctionDynamic((PetscObject)pc,"PCShellSetApplyBA_C","PCShellSetApplyBA_Shell", 9462bb17772SBarry Smith PCShellSetApplyBA_Shell);CHKERRQ(ierr); 9477cdd61b2SBarry Smith ierr = PetscObjectComposeFunctionDynamic((PetscObject)pc,"PCShellSetPreSolve_C","PCShellSetPreSolve_Shell", 9487cdd61b2SBarry Smith PCShellSetPreSolve_Shell);CHKERRQ(ierr); 9497cdd61b2SBarry Smith ierr = PetscObjectComposeFunctionDynamic((PetscObject)pc,"PCShellSetPostSolve_C","PCShellSetPostSolve_Shell", 9507cdd61b2SBarry Smith PCShellSetPostSolve_Shell);CHKERRQ(ierr); 9514b9ad928SBarry Smith ierr = PetscObjectComposeFunctionDynamic((PetscObject)pc,"PCShellSetView_C","PCShellSetView_Shell", 9524b9ad928SBarry Smith PCShellSetView_Shell);CHKERRQ(ierr); 953be29d3c6SBarry Smith ierr = PetscObjectComposeFunctionDynamic((PetscObject)pc,"PCShellSetApplyTranspose_C","PCShellSetApplyTranspose_Shell", 9544b9ad928SBarry Smith PCShellSetApplyTranspose_Shell);CHKERRQ(ierr); 9554b9ad928SBarry Smith ierr = PetscObjectComposeFunctionDynamic((PetscObject)pc,"PCShellSetName_C","PCShellSetName_Shell", 9564b9ad928SBarry Smith PCShellSetName_Shell);CHKERRQ(ierr); 9574b9ad928SBarry Smith ierr = PetscObjectComposeFunctionDynamic((PetscObject)pc,"PCShellGetName_C","PCShellGetName_Shell", 9584b9ad928SBarry Smith PCShellGetName_Shell);CHKERRQ(ierr); 959be29d3c6SBarry Smith ierr = PetscObjectComposeFunctionDynamic((PetscObject)pc,"PCShellSetApplyRichardson_C","PCShellSetApplyRichardson_Shell", 9604b9ad928SBarry Smith PCShellSetApplyRichardson_Shell);CHKERRQ(ierr); 9614b9ad928SBarry Smith PetscFunctionReturn(0); 9624b9ad928SBarry Smith } 9634b9ad928SBarry Smith EXTERN_C_END 9644b9ad928SBarry Smith 9654b9ad928SBarry Smith 9664b9ad928SBarry Smith 9674b9ad928SBarry Smith 9684b9ad928SBarry Smith 9694b9ad928SBarry Smith 970