1af0996ceSBarry Smith #include <petsc/private/snesimpl.h> /*I "petscsnes.h" I*/ 2af0996ceSBarry Smith #include <petsc/private/dmimpl.h> /*I "petscdm.h" I*/ 36cab3a1bSJed Brown 4800f99ffSJeremy L Thompson static PetscErrorCode DMSNESUnsetFunctionContext_DMSNES(DMSNES sdm) 5800f99ffSJeremy L Thompson { 6800f99ffSJeremy L Thompson PetscFunctionBegin; 7800f99ffSJeremy L Thompson PetscCall(PetscObjectCompose((PetscObject)sdm,"function ctx",NULL)); 8800f99ffSJeremy L Thompson sdm->functionctxcontainer = NULL; 9800f99ffSJeremy L Thompson PetscFunctionReturn(0); 10800f99ffSJeremy L Thompson } 11800f99ffSJeremy L Thompson 12800f99ffSJeremy L Thompson static PetscErrorCode DMSNESUnsetJacobianContext_DMSNES(DMSNES sdm) 13800f99ffSJeremy L Thompson { 14800f99ffSJeremy L Thompson PetscFunctionBegin; 15800f99ffSJeremy L Thompson PetscCall(PetscObjectCompose((PetscObject)sdm,"jacobian ctx",NULL)); 16800f99ffSJeremy L Thompson sdm->jacobianctxcontainer = NULL; 17800f99ffSJeremy L Thompson PetscFunctionReturn(0); 18800f99ffSJeremy L Thompson } 19800f99ffSJeremy L Thompson 2022c6f798SBarry Smith static PetscErrorCode DMSNESDestroy(DMSNES *kdm) 216cab3a1bSJed Brown { 226cab3a1bSJed Brown PetscFunctionBegin; 2322c6f798SBarry Smith if (!*kdm) PetscFunctionReturn(0); 2422c6f798SBarry Smith PetscValidHeaderSpecific((*kdm),DMSNES_CLASSID,1); 259e5d0892SLisandro Dalcin if (--((PetscObject)(*kdm))->refct > 0) {*kdm = NULL; PetscFunctionReturn(0);} 26800f99ffSJeremy L Thompson PetscCall(DMSNESUnsetFunctionContext_DMSNES(*kdm)); 27800f99ffSJeremy L Thompson PetscCall(DMSNESUnsetJacobianContext_DMSNES(*kdm)); 289566063dSJacob Faibussowitsch if ((*kdm)->ops->destroy) PetscCall(((*kdm)->ops->destroy)(*kdm)); 299566063dSJacob Faibussowitsch PetscCall(PetscHeaderDestroy(kdm)); 3022c6f798SBarry Smith PetscFunctionReturn(0); 3122c6f798SBarry Smith } 3222c6f798SBarry Smith 332d53ad75SBarry Smith PetscErrorCode DMSNESLoad(DMSNES kdm,PetscViewer viewer) 342d53ad75SBarry Smith { 352d53ad75SBarry Smith PetscFunctionBegin; 369566063dSJacob Faibussowitsch PetscCall(PetscViewerBinaryRead(viewer,&kdm->ops->computefunction,1,NULL,PETSC_FUNCTION)); 379566063dSJacob Faibussowitsch PetscCall(PetscViewerBinaryRead(viewer,&kdm->ops->computejacobian,1,NULL,PETSC_FUNCTION)); 382d53ad75SBarry Smith PetscFunctionReturn(0); 392d53ad75SBarry Smith } 402d53ad75SBarry Smith 412d53ad75SBarry Smith PetscErrorCode DMSNESView(DMSNES kdm,PetscViewer viewer) 422d53ad75SBarry Smith { 432d53ad75SBarry Smith PetscBool isascii,isbinary; 442d53ad75SBarry Smith 452d53ad75SBarry Smith PetscFunctionBegin; 469566063dSJacob Faibussowitsch PetscCall(PetscObjectTypeCompare((PetscObject)viewer,PETSCVIEWERASCII,&isascii)); 479566063dSJacob Faibussowitsch PetscCall(PetscObjectTypeCompare((PetscObject)viewer,PETSCVIEWERBINARY,&isbinary)); 482d53ad75SBarry Smith if (isascii) { 494b5d3663SBarry Smith #if defined(PETSC_SERIALIZE_FUNCTIONS) && defined(PETSC_SERIALIZE_FUNCTIONS_VIEW) 502d53ad75SBarry Smith const char *fname; 512d53ad75SBarry Smith 529566063dSJacob Faibussowitsch PetscCall(PetscFPTFind(kdm->ops->computefunction,&fname)); 532d53ad75SBarry Smith if (fname) { 549566063dSJacob Faibussowitsch PetscCall(PetscViewerASCIIPrintf(viewer,"Function used by SNES: %s\n",fname)); 552d53ad75SBarry Smith } 569566063dSJacob Faibussowitsch PetscCall(PetscFPTFind(kdm->ops->computejacobian,&fname)); 572d53ad75SBarry Smith if (fname) { 589566063dSJacob Faibussowitsch PetscCall(PetscViewerASCIIPrintf(viewer,"Jacobian function used by SNES: %s\n",fname)); 592d53ad75SBarry Smith } 60c7a10e08SBarry Smith #endif 612d53ad75SBarry Smith } else if (isbinary) { 623964eb88SJed Brown struct { 633964eb88SJed Brown PetscErrorCode (*func)(SNES,Vec,Vec,void*); 649200755eSBarry Smith } funcstruct; 659200755eSBarry Smith struct { 66d1e9a80fSBarry Smith PetscErrorCode (*jac)(SNES,Vec,Mat,Mat,void*); 679200755eSBarry Smith } jacstruct; 689200755eSBarry Smith funcstruct.func = kdm->ops->computefunction; 699200755eSBarry Smith jacstruct.jac = kdm->ops->computejacobian; 709566063dSJacob Faibussowitsch PetscCall(PetscViewerBinaryWrite(viewer,&funcstruct,1,PETSC_FUNCTION)); 719566063dSJacob Faibussowitsch PetscCall(PetscViewerBinaryWrite(viewer,&jacstruct,1,PETSC_FUNCTION)); 722d53ad75SBarry Smith } 732d53ad75SBarry Smith PetscFunctionReturn(0); 742d53ad75SBarry Smith } 752d53ad75SBarry Smith 7622c6f798SBarry Smith static PetscErrorCode DMSNESCreate(MPI_Comm comm,DMSNES *kdm) 7722c6f798SBarry Smith { 7822c6f798SBarry Smith PetscFunctionBegin; 799566063dSJacob Faibussowitsch PetscCall(SNESInitializePackage()); 809566063dSJacob Faibussowitsch PetscCall(PetscHeaderCreate(*kdm, DMSNES_CLASSID, "DMSNES", "DMSNES", "DMSNES", comm, DMSNESDestroy, DMSNESView)); 816cab3a1bSJed Brown PetscFunctionReturn(0); 826cab3a1bSJed Brown } 836cab3a1bSJed Brown 84942e3340SBarry Smith /* Attaches the DMSNES to the coarse level. 856cab3a1bSJed Brown * Under what conditions should we copy versus duplicate? 866cab3a1bSJed Brown */ 87942e3340SBarry Smith static PetscErrorCode DMCoarsenHook_DMSNES(DM dm,DM dmc,void *ctx) 886cab3a1bSJed Brown { 896cab3a1bSJed Brown PetscFunctionBegin; 909566063dSJacob Faibussowitsch PetscCall(DMCopyDMSNES(dm,dmc)); 916cab3a1bSJed Brown PetscFunctionReturn(0); 926cab3a1bSJed Brown } 936cab3a1bSJed Brown 94dfe15315SJed Brown /* This could restrict auxiliary information to the coarse level. 95caa4e7f2SJed Brown */ 96942e3340SBarry Smith static PetscErrorCode DMRestrictHook_DMSNES(DM dm,Mat Restrict,Vec rscale,Mat Inject,DM dmc,void *ctx) 97caa4e7f2SJed Brown { 98caa4e7f2SJed Brown PetscFunctionBegin; 99caa4e7f2SJed Brown PetscFunctionReturn(0); 100caa4e7f2SJed Brown } 101caa4e7f2SJed Brown 102be081cd6SPeter Brune /* Attaches the DMSNES to the subdomain. */ 103be081cd6SPeter Brune static PetscErrorCode DMSubDomainHook_DMSNES(DM dm,DM subdm,void *ctx) 104be081cd6SPeter Brune { 105be081cd6SPeter Brune PetscFunctionBegin; 1069566063dSJacob Faibussowitsch PetscCall(DMCopyDMSNES(dm,subdm)); 107be081cd6SPeter Brune PetscFunctionReturn(0); 108be081cd6SPeter Brune } 109be081cd6SPeter Brune 110be081cd6SPeter Brune /* This could restrict auxiliary information to the coarse level. 111be081cd6SPeter Brune */ 112be081cd6SPeter Brune static PetscErrorCode DMSubDomainRestrictHook_DMSNES(DM dm,VecScatter gscat,VecScatter lscat,DM subdm,void *ctx) 113be081cd6SPeter Brune { 114be081cd6SPeter Brune PetscFunctionBegin; 115be081cd6SPeter Brune PetscFunctionReturn(0); 116be081cd6SPeter Brune } 117be081cd6SPeter Brune 118942e3340SBarry Smith static PetscErrorCode DMRefineHook_DMSNES(DM dm,DM dmf,void *ctx) 11903a0fabfSPeter Brune { 12003a0fabfSPeter Brune PetscFunctionBegin; 1219566063dSJacob Faibussowitsch PetscCall(DMCopyDMSNES(dm,dmf)); 12203a0fabfSPeter Brune PetscFunctionReturn(0); 12303a0fabfSPeter Brune } 12403a0fabfSPeter Brune 12503a0fabfSPeter Brune /* This could restrict auxiliary information to the coarse level. 12603a0fabfSPeter Brune */ 127942e3340SBarry Smith static PetscErrorCode DMInterpolateHook_DMSNES(DM dm,Mat Interp,DM dmf,void *ctx) 12803a0fabfSPeter Brune { 12903a0fabfSPeter Brune PetscFunctionBegin; 13003a0fabfSPeter Brune PetscFunctionReturn(0); 13103a0fabfSPeter Brune } 13203a0fabfSPeter Brune 13322c6f798SBarry Smith /*@C 13422c6f798SBarry Smith DMSNESCopy - copies the information in a DMSNES to another DMSNES 13522c6f798SBarry Smith 13622c6f798SBarry Smith Not Collective 13722c6f798SBarry Smith 1384165533cSJose E. Roman Input Parameters: 13922c6f798SBarry Smith + kdm - Original DMSNES 14022c6f798SBarry Smith - nkdm - DMSNES to receive the data, should have been created with DMSNESCreate() 14122c6f798SBarry Smith 14222c6f798SBarry Smith Level: developer 14322c6f798SBarry Smith 144db781477SPatrick Sanan .seealso: `DMSNESCreate()`, `DMSNESDestroy()` 14522c6f798SBarry Smith @*/ 14622c6f798SBarry Smith PetscErrorCode DMSNESCopy(DMSNES kdm,DMSNES nkdm) 14722c6f798SBarry Smith { 14822c6f798SBarry Smith PetscFunctionBegin; 14922c6f798SBarry Smith PetscValidHeaderSpecific(kdm,DMSNES_CLASSID,1); 15022c6f798SBarry Smith PetscValidHeaderSpecific(nkdm,DMSNES_CLASSID,2); 15122c6f798SBarry Smith nkdm->ops->computefunction = kdm->ops->computefunction; 1522bc4d0c4SPeter Brune nkdm->ops->computejacobian = kdm->ops->computejacobian; 15322c6f798SBarry Smith nkdm->ops->computegs = kdm->ops->computegs; 15422c6f798SBarry Smith nkdm->ops->computeobjective = kdm->ops->computeobjective; 15522c6f798SBarry Smith nkdm->ops->computepjacobian = kdm->ops->computepjacobian; 15622c6f798SBarry Smith nkdm->ops->computepfunction = kdm->ops->computepfunction; 15722c6f798SBarry Smith nkdm->ops->destroy = kdm->ops->destroy; 15822c6f798SBarry Smith nkdm->ops->duplicate = kdm->ops->duplicate; 15922c6f798SBarry Smith 16022c6f798SBarry Smith nkdm->gsctx = kdm->gsctx; 16122c6f798SBarry Smith nkdm->pctx = kdm->pctx; 16222c6f798SBarry Smith nkdm->objectivectx = kdm->objectivectx; 163af903c1dSJunchao Zhang nkdm->originaldm = kdm->originaldm; 164800f99ffSJeremy L Thompson nkdm->functionctxcontainer = kdm->functionctxcontainer; 165800f99ffSJeremy L Thompson nkdm->jacobianctxcontainer = kdm->jacobianctxcontainer; 166800f99ffSJeremy L Thompson if (nkdm->functionctxcontainer) PetscCall(PetscObjectCompose((PetscObject)nkdm,"function ctx",(PetscObject)nkdm->functionctxcontainer)); 167800f99ffSJeremy L Thompson if (nkdm->jacobianctxcontainer) PetscCall(PetscObjectCompose((PetscObject)nkdm,"jacobian ctx",(PetscObject)nkdm->jacobianctxcontainer)); 16822c6f798SBarry Smith 16922c6f798SBarry Smith /* 17022c6f798SBarry Smith nkdm->fortran_func_pointers[0] = kdm->fortran_func_pointers[0]; 17122c6f798SBarry Smith nkdm->fortran_func_pointers[1] = kdm->fortran_func_pointers[1]; 17222c6f798SBarry Smith nkdm->fortran_func_pointers[2] = kdm->fortran_func_pointers[2]; 17322c6f798SBarry Smith */ 17422c6f798SBarry Smith 17522c6f798SBarry Smith /* implementation specific copy hooks */ 1769566063dSJacob Faibussowitsch if (kdm->ops->duplicate) PetscCall((*kdm->ops->duplicate)(kdm,nkdm)); 17722c6f798SBarry Smith PetscFunctionReturn(0); 17822c6f798SBarry Smith } 17922c6f798SBarry Smith 1806cab3a1bSJed Brown /*@C 181942e3340SBarry Smith DMGetDMSNES - get read-only private DMSNES context from a DM 1826cab3a1bSJed Brown 1836cab3a1bSJed Brown Not Collective 1846cab3a1bSJed Brown 1854165533cSJose E. Roman Input Parameter: 1866cab3a1bSJed Brown . dm - DM to be used with SNES 1876cab3a1bSJed Brown 1884165533cSJose E. Roman Output Parameter: 189942e3340SBarry Smith . snesdm - private DMSNES context 1906cab3a1bSJed Brown 1916cab3a1bSJed Brown Level: developer 1926cab3a1bSJed Brown 1936cab3a1bSJed Brown Notes: 194942e3340SBarry Smith Use DMGetDMSNESWrite() if write access is needed. The DMSNESSetXXX API should be used wherever possible. 1956cab3a1bSJed Brown 196db781477SPatrick Sanan .seealso: `DMGetDMSNESWrite()` 1976cab3a1bSJed Brown @*/ 198942e3340SBarry Smith PetscErrorCode DMGetDMSNES(DM dm,DMSNES *snesdm) 1996cab3a1bSJed Brown { 2006cab3a1bSJed Brown PetscFunctionBegin; 2016cab3a1bSJed Brown PetscValidHeaderSpecific(dm,DM_CLASSID,1); 202b4615a05SBarry Smith *snesdm = (DMSNES) dm->dmsnes; 20322c6f798SBarry Smith if (!*snesdm) { 2049566063dSJacob Faibussowitsch PetscCall(PetscInfo(dm,"Creating new DMSNES\n")); 2059566063dSJacob Faibussowitsch PetscCall(DMSNESCreate(PetscObjectComm((PetscObject)dm),snesdm)); 2061aa26658SKarl Rupp 207b4615a05SBarry Smith dm->dmsnes = (PetscObject) *snesdm; 208af903c1dSJunchao Zhang (*snesdm)->originaldm = dm; 2099566063dSJacob Faibussowitsch PetscCall(DMCoarsenHookAdd(dm,DMCoarsenHook_DMSNES,DMRestrictHook_DMSNES,NULL)); 2109566063dSJacob Faibussowitsch PetscCall(DMRefineHookAdd(dm,DMRefineHook_DMSNES,DMInterpolateHook_DMSNES,NULL)); 2119566063dSJacob Faibussowitsch PetscCall(DMSubDomainHookAdd(dm,DMSubDomainHook_DMSNES,DMSubDomainRestrictHook_DMSNES,NULL)); 2126cab3a1bSJed Brown } 2136cab3a1bSJed Brown PetscFunctionReturn(0); 2146cab3a1bSJed Brown } 2156cab3a1bSJed Brown 2166cab3a1bSJed Brown /*@C 217942e3340SBarry Smith DMGetDMSNESWrite - get write access to private DMSNES context from a DM 2186cab3a1bSJed Brown 2196cab3a1bSJed Brown Not Collective 2206cab3a1bSJed Brown 2214165533cSJose E. Roman Input Parameter: 2226cab3a1bSJed Brown . dm - DM to be used with SNES 2236cab3a1bSJed Brown 2244165533cSJose E. Roman Output Parameter: 225942e3340SBarry Smith . snesdm - private DMSNES context 2266cab3a1bSJed Brown 2276cab3a1bSJed Brown Level: developer 2286cab3a1bSJed Brown 229db781477SPatrick Sanan .seealso: `DMGetDMSNES()` 2306cab3a1bSJed Brown @*/ 231942e3340SBarry Smith PetscErrorCode DMGetDMSNESWrite(DM dm,DMSNES *snesdm) 2326cab3a1bSJed Brown { 233942e3340SBarry Smith DMSNES sdm; 2346cab3a1bSJed Brown 2356cab3a1bSJed Brown PetscFunctionBegin; 2366cab3a1bSJed Brown PetscValidHeaderSpecific(dm,DM_CLASSID,1); 2379566063dSJacob Faibussowitsch PetscCall(DMGetDMSNES(dm,&sdm)); 23828b400f6SJacob Faibussowitsch PetscCheck(sdm->originaldm,PETSC_COMM_SELF,PETSC_ERR_ARG_WRONGSTATE,"DMSNES has a NULL originaldm"); 2396cab3a1bSJed Brown if (sdm->originaldm != dm) { /* Copy on write */ 240b4615a05SBarry Smith DMSNES oldsdm = sdm; 2419566063dSJacob Faibussowitsch PetscCall(PetscInfo(dm,"Copying DMSNES due to write\n")); 2429566063dSJacob Faibussowitsch PetscCall(DMSNESCreate(PetscObjectComm((PetscObject)dm),&sdm)); 2439566063dSJacob Faibussowitsch PetscCall(DMSNESCopy(oldsdm,sdm)); 2449566063dSJacob Faibussowitsch PetscCall(DMSNESDestroy((DMSNES*)&dm->dmsnes)); 245b4615a05SBarry Smith dm->dmsnes = (PetscObject)sdm; 246af903c1dSJunchao Zhang sdm->originaldm = dm; 2476cab3a1bSJed Brown } 2486cab3a1bSJed Brown *snesdm = sdm; 2496cab3a1bSJed Brown PetscFunctionReturn(0); 2506cab3a1bSJed Brown } 2516cab3a1bSJed Brown 2526cab3a1bSJed Brown /*@C 253942e3340SBarry Smith DMCopyDMSNES - copies a DM context to a new DM 2546cab3a1bSJed Brown 2556cab3a1bSJed Brown Logically Collective 2566cab3a1bSJed Brown 2574165533cSJose E. Roman Input Parameters: 2586cab3a1bSJed Brown + dmsrc - DM to obtain context from 2596cab3a1bSJed Brown - dmdest - DM to add context to 2606cab3a1bSJed Brown 2616cab3a1bSJed Brown Level: developer 2626cab3a1bSJed Brown 2636cab3a1bSJed Brown Note: 2646cab3a1bSJed Brown The context is copied by reference. This function does not ensure that a context exists. 2656cab3a1bSJed Brown 266db781477SPatrick Sanan .seealso: `DMGetDMSNES()`, `SNESSetDM()` 2676cab3a1bSJed Brown @*/ 268942e3340SBarry Smith PetscErrorCode DMCopyDMSNES(DM dmsrc,DM dmdest) 2696cab3a1bSJed Brown { 2706cab3a1bSJed Brown PetscFunctionBegin; 2716cab3a1bSJed Brown PetscValidHeaderSpecific(dmsrc,DM_CLASSID,1); 2726cab3a1bSJed Brown PetscValidHeaderSpecific(dmdest,DM_CLASSID,2); 2739566063dSJacob Faibussowitsch if (!dmdest->dmsnes) PetscCall(DMSNESCreate(PetscObjectComm((PetscObject) dmdest), (DMSNES *) &dmdest->dmsnes)); 2749566063dSJacob Faibussowitsch PetscCall(DMSNESCopy((DMSNES) dmsrc->dmsnes, (DMSNES) dmdest->dmsnes)); 2759566063dSJacob Faibussowitsch PetscCall(DMCoarsenHookAdd(dmdest,DMCoarsenHook_DMSNES,NULL,NULL)); 2769566063dSJacob Faibussowitsch PetscCall(DMRefineHookAdd(dmdest,DMRefineHook_DMSNES,NULL,NULL)); 2779566063dSJacob Faibussowitsch PetscCall(DMSubDomainHookAdd(dmdest,DMSubDomainHook_DMSNES,DMSubDomainRestrictHook_DMSNES,NULL)); 2786cab3a1bSJed Brown PetscFunctionReturn(0); 2796cab3a1bSJed Brown } 2806cab3a1bSJed Brown 2816cab3a1bSJed Brown /*@C 2826cab3a1bSJed Brown DMSNESSetFunction - set SNES residual evaluation function 2836cab3a1bSJed Brown 2846cab3a1bSJed Brown Not Collective 2856cab3a1bSJed Brown 2864165533cSJose E. Roman Input Parameters: 2876cab3a1bSJed Brown + dm - DM to be used with SNES 288f8b49ee9SBarry Smith . f - residual evaluation function; see SNESFunction for details 2896cab3a1bSJed Brown - ctx - context for residual evaluation 2906cab3a1bSJed Brown 2916cab3a1bSJed Brown Level: advanced 2926cab3a1bSJed Brown 2936cab3a1bSJed Brown Note: 2946cab3a1bSJed Brown SNESSetFunction() is normally used, but it calls this function internally because the user context is actually 2956cab3a1bSJed Brown associated with the DM. This makes the interface consistent regardless of whether the user interacts with a DM or 2966cab3a1bSJed Brown not. If DM took a more central role at some later date, this could become the primary method of setting the residual. 2976cab3a1bSJed Brown 298db781477SPatrick Sanan .seealso: `DMSNESSetContext()`, `SNESSetFunction()`, `DMSNESSetJacobian()`, `SNESFunction` 2996cab3a1bSJed Brown @*/ 300f8b49ee9SBarry Smith PetscErrorCode DMSNESSetFunction(DM dm,PetscErrorCode (*f)(SNES,Vec,Vec,void*),void *ctx) 3016cab3a1bSJed Brown { 302942e3340SBarry Smith DMSNES sdm; 3036cab3a1bSJed Brown 3046cab3a1bSJed Brown PetscFunctionBegin; 3056cab3a1bSJed Brown PetscValidHeaderSpecific(dm,DM_CLASSID,1); 3069566063dSJacob Faibussowitsch PetscCall(DMGetDMSNESWrite(dm,&sdm)); 307f8b49ee9SBarry Smith if (f) sdm->ops->computefunction = f; 308800f99ffSJeremy L Thompson if (ctx) { 309800f99ffSJeremy L Thompson PetscContainer ctxcontainer; 310800f99ffSJeremy L Thompson PetscCall(PetscContainerCreate(PetscObjectComm((PetscObject)sdm),&ctxcontainer)); 311800f99ffSJeremy L Thompson PetscCall(PetscContainerSetPointer(ctxcontainer,ctx)); 312800f99ffSJeremy L Thompson PetscCall(PetscObjectCompose((PetscObject)sdm,"function ctx",(PetscObject)ctxcontainer)); 313800f99ffSJeremy L Thompson sdm->functionctxcontainer = ctxcontainer; 314800f99ffSJeremy L Thompson PetscCall(PetscContainerDestroy(&ctxcontainer)); 315800f99ffSJeremy L Thompson } 316800f99ffSJeremy L Thompson PetscFunctionReturn(0); 317800f99ffSJeremy L Thompson } 318800f99ffSJeremy L Thompson 319800f99ffSJeremy L Thompson /*@C 320*5cb80ecdSBarry Smith DMSNESSetFunctionContextDestroy - set `SNES` residual evaluation context destroy function 321800f99ffSJeremy L Thompson 322800f99ffSJeremy L Thompson Not Collective 323800f99ffSJeremy L Thompson 324800f99ffSJeremy L Thompson Input Parameters: 325*5cb80ecdSBarry Smith + dm - `DM` to be used with `SNES` 326*5cb80ecdSBarry Smith - f - residual evaluation context destroy function 327800f99ffSJeremy L Thompson 328800f99ffSJeremy L Thompson Level: advanced 329800f99ffSJeremy L Thompson 330800f99ffSJeremy L Thompson Note: 331*5cb80ecdSBarry Smith `SNESSetFunctionContextDestroy()` is normally used, but it calls this function internally because the user context is actually 332*5cb80ecdSBarry Smith associated with the `DM`. This makes the interface consistent regardless of whether the user interacts with a `DM` or 333*5cb80ecdSBarry Smith not. 334*5cb80ecdSBarry Smith 335*5cb80ecdSBarry Smith Developer Note: 336*5cb80ecdSBarry Smith If `DM` took a more central role at some later date, this could become the primary method of setting the residual. 337800f99ffSJeremy L Thompson 338800f99ffSJeremy L Thompson .seealso: `DMSNESSetFunction()`, `SNESSetFunction()` 339800f99ffSJeremy L Thompson @*/ 340800f99ffSJeremy L Thompson PetscErrorCode DMSNESSetFunctionContextDestroy(DM dm,PetscErrorCode (*f)(void*)) 341800f99ffSJeremy L Thompson { 342800f99ffSJeremy L Thompson DMSNES sdm; 343800f99ffSJeremy L Thompson 344800f99ffSJeremy L Thompson PetscFunctionBegin; 345800f99ffSJeremy L Thompson PetscValidHeaderSpecific(dm,DM_CLASSID,1); 346800f99ffSJeremy L Thompson PetscCall(DMGetDMSNESWrite(dm,&sdm)); 347800f99ffSJeremy L Thompson if (sdm->functionctxcontainer) PetscCall(PetscContainerSetUserDestroy(sdm->functionctxcontainer,f)); 348800f99ffSJeremy L Thompson PetscFunctionReturn(0); 349800f99ffSJeremy L Thompson } 350800f99ffSJeremy L Thompson 351800f99ffSJeremy L Thompson PetscErrorCode DMSNESUnsetFunctionContext_Internal(DM dm) 352800f99ffSJeremy L Thompson { 353800f99ffSJeremy L Thompson DMSNES sdm; 354800f99ffSJeremy L Thompson 355800f99ffSJeremy L Thompson PetscFunctionBegin; 356800f99ffSJeremy L Thompson PetscValidHeaderSpecific(dm,DM_CLASSID,1); 357800f99ffSJeremy L Thompson PetscCall(DMGetDMSNESWrite(dm,&sdm)); 358800f99ffSJeremy L Thompson PetscCall(DMSNESUnsetFunctionContext_DMSNES(sdm)); 3596cab3a1bSJed Brown PetscFunctionReturn(0); 3606cab3a1bSJed Brown } 3616cab3a1bSJed Brown 3626cab3a1bSJed Brown /*@C 363bbc1464cSBarry Smith DMSNESSetMFFunction - set SNES residual evaluation function used in applying the matrix-free Jacobian with -snes_mf_operator 364bbc1464cSBarry Smith 365bbc1464cSBarry Smith Logically Collective on dm 366bbc1464cSBarry Smith 3674165533cSJose E. Roman Input Parameters: 368bbc1464cSBarry Smith + dm - DM to be used with SNES 369bbc1464cSBarry Smith - f - residual evaluation function; see SNESFunction for details 370bbc1464cSBarry Smith 371bbc1464cSBarry Smith Level: advanced 372bbc1464cSBarry Smith 373db781477SPatrick Sanan .seealso: `DMSNESSetContext()`, `SNESSetFunction()`, `DMSNESSetJacobian()`, `SNESFunction`, `DMSNESSetFunction()` 374bbc1464cSBarry Smith @*/ 375bbc1464cSBarry Smith PetscErrorCode DMSNESSetMFFunction(DM dm,PetscErrorCode (*f)(SNES,Vec,Vec,void*),void *ctx) 376bbc1464cSBarry Smith { 377bbc1464cSBarry Smith DMSNES sdm; 378bbc1464cSBarry Smith 379bbc1464cSBarry Smith PetscFunctionBegin; 380bbc1464cSBarry Smith PetscValidHeaderSpecific(dm,DM_CLASSID,1); 381bbc1464cSBarry Smith if (f || ctx) { 3829566063dSJacob Faibussowitsch PetscCall(DMGetDMSNESWrite(dm,&sdm)); 383bbc1464cSBarry Smith } 384bbc1464cSBarry Smith if (f) sdm->ops->computemffunction = f; 385bbc1464cSBarry Smith if (ctx) sdm->mffunctionctx = ctx; 386bbc1464cSBarry Smith PetscFunctionReturn(0); 387bbc1464cSBarry Smith } 388bbc1464cSBarry Smith 389bbc1464cSBarry Smith /*@C 3906cab3a1bSJed Brown DMSNESGetFunction - get SNES residual evaluation function 3916cab3a1bSJed Brown 3926cab3a1bSJed Brown Not Collective 3936cab3a1bSJed Brown 3944165533cSJose E. Roman Input Parameter: 3956cab3a1bSJed Brown . dm - DM to be used with SNES 3966cab3a1bSJed Brown 3974165533cSJose E. Roman Output Parameters: 398f8b49ee9SBarry Smith + f - residual evaluation function; see SNESFunction for details 3996cab3a1bSJed Brown - ctx - context for residual evaluation 4006cab3a1bSJed Brown 4016cab3a1bSJed Brown Level: advanced 4026cab3a1bSJed Brown 4036cab3a1bSJed Brown Note: 4046cab3a1bSJed Brown SNESGetFunction() is normally used, but it calls this function internally because the user context is actually 4056cab3a1bSJed Brown associated with the DM. 4066cab3a1bSJed Brown 407db781477SPatrick Sanan .seealso: `DMSNESSetContext()`, `DMSNESSetFunction()`, `SNESSetFunction()`, `SNESFunction` 4086cab3a1bSJed Brown @*/ 409f8b49ee9SBarry Smith PetscErrorCode DMSNESGetFunction(DM dm,PetscErrorCode (**f)(SNES,Vec,Vec,void*),void **ctx) 4106cab3a1bSJed Brown { 411942e3340SBarry Smith DMSNES sdm; 4126cab3a1bSJed Brown 4136cab3a1bSJed Brown PetscFunctionBegin; 4146cab3a1bSJed Brown PetscValidHeaderSpecific(dm,DM_CLASSID,1); 4159566063dSJacob Faibussowitsch PetscCall(DMGetDMSNES(dm,&sdm)); 416f8b49ee9SBarry Smith if (f) *f = sdm->ops->computefunction; 417800f99ffSJeremy L Thompson if (ctx) { 418800f99ffSJeremy L Thompson if (sdm->functionctxcontainer) PetscCall(PetscContainerGetPointer(sdm->functionctxcontainer,ctx)); 419800f99ffSJeremy L Thompson else *ctx = NULL; 420800f99ffSJeremy L Thompson } 4216cab3a1bSJed Brown PetscFunctionReturn(0); 4226cab3a1bSJed Brown } 4236cab3a1bSJed Brown 4242a4ee8f2SPeter Brune /*@C 425081a7dcdSPeter Brune DMSNESSetObjective - set SNES objective evaluation function 4262a4ee8f2SPeter Brune 4272a4ee8f2SPeter Brune Not Collective 4282a4ee8f2SPeter Brune 4294165533cSJose E. Roman Input Parameters: 4302a4ee8f2SPeter Brune + dm - DM to be used with SNES 431f8b49ee9SBarry Smith . obj - objective evaluation function; see SNESObjectiveFunction for details 4322a4ee8f2SPeter Brune - ctx - context for residual evaluation 4332a4ee8f2SPeter Brune 4342a4ee8f2SPeter Brune Level: advanced 4352a4ee8f2SPeter Brune 436db781477SPatrick Sanan .seealso: `DMSNESSetContext()`, `SNESGetObjective()`, `DMSNESSetFunction()` 4372a4ee8f2SPeter Brune @*/ 438f8b49ee9SBarry Smith PetscErrorCode DMSNESSetObjective(DM dm,PetscErrorCode (*obj)(SNES,Vec,PetscReal*,void*),void *ctx) 4392a4ee8f2SPeter Brune { 440942e3340SBarry Smith DMSNES sdm; 4412a4ee8f2SPeter Brune 4422a4ee8f2SPeter Brune PetscFunctionBegin; 4432a4ee8f2SPeter Brune PetscValidHeaderSpecific(dm,DM_CLASSID,1); 444f8b49ee9SBarry Smith if (obj || ctx) { 4459566063dSJacob Faibussowitsch PetscCall(DMGetDMSNESWrite(dm,&sdm)); 446fdaff8d6SPeter Brune } 447f8b49ee9SBarry Smith if (obj) sdm->ops->computeobjective = obj; 4482a4ee8f2SPeter Brune if (ctx) sdm->objectivectx = ctx; 4492a4ee8f2SPeter Brune PetscFunctionReturn(0); 4502a4ee8f2SPeter Brune } 4512a4ee8f2SPeter Brune 4522a4ee8f2SPeter Brune /*@C 4532a4ee8f2SPeter Brune DMSNESGetObjective - get SNES objective evaluation function 4542a4ee8f2SPeter Brune 4552a4ee8f2SPeter Brune Not Collective 4562a4ee8f2SPeter Brune 4574165533cSJose E. Roman Input Parameter: 4582a4ee8f2SPeter Brune . dm - DM to be used with SNES 4592a4ee8f2SPeter Brune 4604165533cSJose E. Roman Output Parameters: 461f8b49ee9SBarry Smith + obj- residual evaluation function; see SNESObjectiveFunction for details 4622a4ee8f2SPeter Brune - ctx - context for residual evaluation 4632a4ee8f2SPeter Brune 4642a4ee8f2SPeter Brune Level: advanced 4652a4ee8f2SPeter Brune 4662a4ee8f2SPeter Brune Note: 4672a4ee8f2SPeter Brune SNESGetFunction() is normally used, but it calls this function internally because the user context is actually 4682a4ee8f2SPeter Brune associated with the DM. 4692a4ee8f2SPeter Brune 470db781477SPatrick Sanan .seealso: `DMSNESSetContext()`, `DMSNESSetObjective()`, `SNESSetFunction()` 4712a4ee8f2SPeter Brune @*/ 472f8b49ee9SBarry Smith PetscErrorCode DMSNESGetObjective(DM dm,PetscErrorCode (**obj)(SNES,Vec,PetscReal*,void*),void **ctx) 4732a4ee8f2SPeter Brune { 474942e3340SBarry Smith DMSNES sdm; 4752a4ee8f2SPeter Brune 4762a4ee8f2SPeter Brune PetscFunctionBegin; 4772a4ee8f2SPeter Brune PetscValidHeaderSpecific(dm,DM_CLASSID,1); 4789566063dSJacob Faibussowitsch PetscCall(DMGetDMSNES(dm,&sdm)); 479f8b49ee9SBarry Smith if (obj) *obj = sdm->ops->computeobjective; 4802a4ee8f2SPeter Brune if (ctx) *ctx = sdm->objectivectx; 4812a4ee8f2SPeter Brune PetscFunctionReturn(0); 4822a4ee8f2SPeter Brune } 4832a4ee8f2SPeter Brune 4846cab3a1bSJed Brown /*@C 485be95d8f1SBarry Smith DMSNESSetNGS - set SNES Gauss-Seidel relaxation function 4866cab3a1bSJed Brown 4876cab3a1bSJed Brown Not Collective 4886cab3a1bSJed Brown 4894165533cSJose E. Roman Input Parameters: 4906cab3a1bSJed Brown + dm - DM to be used with SNES 491be95d8f1SBarry Smith . f - relaxation function, see SNESGSFunction 4926cab3a1bSJed Brown - ctx - context for residual evaluation 4936cab3a1bSJed Brown 4946cab3a1bSJed Brown Level: advanced 4956cab3a1bSJed Brown 4966cab3a1bSJed Brown Note: 497be95d8f1SBarry Smith SNESSetNGS() is normally used, but it calls this function internally because the user context is actually 4986cab3a1bSJed Brown associated with the DM. This makes the interface consistent regardless of whether the user interacts with a DM or 4996cab3a1bSJed Brown not. If DM took a more central role at some later date, this could become the primary method of setting the residual. 5006cab3a1bSJed Brown 501db781477SPatrick Sanan .seealso: `DMSNESSetContext()`, `SNESSetFunction()`, `DMSNESSetJacobian()`, `DMSNESSetFunction()`, `SNESGSFunction` 5026cab3a1bSJed Brown @*/ 503be95d8f1SBarry Smith PetscErrorCode DMSNESSetNGS(DM dm,PetscErrorCode (*f)(SNES,Vec,Vec,void*),void *ctx) 5046cab3a1bSJed Brown { 505942e3340SBarry Smith DMSNES sdm; 5066cab3a1bSJed Brown 5076cab3a1bSJed Brown PetscFunctionBegin; 5086cab3a1bSJed Brown PetscValidHeaderSpecific(dm,DM_CLASSID,1); 509be95d8f1SBarry Smith if (f || ctx) { 5109566063dSJacob Faibussowitsch PetscCall(DMGetDMSNESWrite(dm,&sdm)); 511fdaff8d6SPeter Brune } 512be95d8f1SBarry Smith if (f) sdm->ops->computegs = f; 5136cab3a1bSJed Brown if (ctx) sdm->gsctx = ctx; 5146cab3a1bSJed Brown PetscFunctionReturn(0); 5156cab3a1bSJed Brown } 5166cab3a1bSJed Brown 5176cab3a1bSJed Brown /*@C 518be95d8f1SBarry Smith DMSNESGetNGS - get SNES Gauss-Seidel relaxation function 5196cab3a1bSJed Brown 5206cab3a1bSJed Brown Not Collective 5216cab3a1bSJed Brown 5224165533cSJose E. Roman Input Parameter: 5236cab3a1bSJed Brown . dm - DM to be used with SNES 5246cab3a1bSJed Brown 5254165533cSJose E. Roman Output Parameters: 526be95d8f1SBarry Smith + f - relaxation function which performs Gauss-Seidel sweeps, see SNESGSFunction 5276cab3a1bSJed Brown - ctx - context for residual evaluation 5286cab3a1bSJed Brown 5296cab3a1bSJed Brown Level: advanced 5306cab3a1bSJed Brown 5316cab3a1bSJed Brown Note: 532be95d8f1SBarry Smith SNESGetNGS() is normally used, but it calls this function internally because the user context is actually 5336cab3a1bSJed Brown associated with the DM. This makes the interface consistent regardless of whether the user interacts with a DM or 5346cab3a1bSJed Brown not. If DM took a more central role at some later date, this could become the primary method of setting the residual. 5356cab3a1bSJed Brown 536db781477SPatrick Sanan .seealso: `DMSNESSetContext()`, `SNESGetNGS()`, `DMSNESGetJacobian()`, `DMSNESGetFunction()`, `SNESNGSFunction` 5376cab3a1bSJed Brown @*/ 538be95d8f1SBarry Smith PetscErrorCode DMSNESGetNGS(DM dm,PetscErrorCode (**f)(SNES,Vec,Vec,void*),void **ctx) 5396cab3a1bSJed Brown { 540942e3340SBarry Smith DMSNES sdm; 5416cab3a1bSJed Brown 5426cab3a1bSJed Brown PetscFunctionBegin; 5436cab3a1bSJed Brown PetscValidHeaderSpecific(dm,DM_CLASSID,1); 5449566063dSJacob Faibussowitsch PetscCall(DMGetDMSNES(dm,&sdm)); 545be95d8f1SBarry Smith if (f) *f = sdm->ops->computegs; 5466cab3a1bSJed Brown if (ctx) *ctx = sdm->gsctx; 5476cab3a1bSJed Brown PetscFunctionReturn(0); 5486cab3a1bSJed Brown } 5496cab3a1bSJed Brown 5506cab3a1bSJed Brown /*@C 551ecfdb398SPeter Brune DMSNESSetJacobian - set SNES Jacobian evaluation function 5526cab3a1bSJed Brown 5536cab3a1bSJed Brown Not Collective 5546cab3a1bSJed Brown 5554165533cSJose E. Roman Input Parameters: 5566cab3a1bSJed Brown + dm - DM to be used with SNES 557f8b49ee9SBarry Smith . J - Jacobian evaluation function 5586cab3a1bSJed Brown - ctx - context for residual evaluation 5596cab3a1bSJed Brown 5606cab3a1bSJed Brown Level: advanced 5616cab3a1bSJed Brown 5626cab3a1bSJed Brown Note: 5636cab3a1bSJed Brown SNESSetJacobian() is normally used, but it calls this function internally because the user context is actually 5646cab3a1bSJed Brown associated with the DM. This makes the interface consistent regardless of whether the user interacts with a DM or 5656cab3a1bSJed Brown not. If DM took a more central role at some later date, this could become the primary method of setting the Jacobian. 5666cab3a1bSJed Brown 567db781477SPatrick Sanan .seealso: `DMSNESSetContext()`, `SNESSetFunction()`, `DMSNESGetJacobian()`, `SNESSetJacobian()`, `SNESJacobianFunction` 5686cab3a1bSJed Brown @*/ 569d1e9a80fSBarry Smith PetscErrorCode DMSNESSetJacobian(DM dm,PetscErrorCode (*J)(SNES,Vec,Mat,Mat,void*),void *ctx) 5706cab3a1bSJed Brown { 571942e3340SBarry Smith DMSNES sdm; 5726cab3a1bSJed Brown 5736cab3a1bSJed Brown PetscFunctionBegin; 5746cab3a1bSJed Brown PetscValidHeaderSpecific(dm,DM_CLASSID,1); 575800f99ffSJeremy L Thompson if (J || ctx) PetscCall(DMGetDMSNESWrite(dm,&sdm)); 576f8b49ee9SBarry Smith if (J) sdm->ops->computejacobian = J; 577800f99ffSJeremy L Thompson if (ctx) { 578800f99ffSJeremy L Thompson PetscContainer ctxcontainer; 579800f99ffSJeremy L Thompson PetscCall(PetscContainerCreate(PetscObjectComm((PetscObject)sdm),&ctxcontainer)); 580800f99ffSJeremy L Thompson PetscCall(PetscContainerSetPointer(ctxcontainer,ctx)); 581800f99ffSJeremy L Thompson PetscCall(PetscObjectCompose((PetscObject)sdm,"jacobian ctx",(PetscObject)ctxcontainer)); 582800f99ffSJeremy L Thompson sdm->jacobianctxcontainer = ctxcontainer; 583800f99ffSJeremy L Thompson PetscCall(PetscContainerDestroy(&ctxcontainer)); 584800f99ffSJeremy L Thompson } 585800f99ffSJeremy L Thompson PetscFunctionReturn(0); 586800f99ffSJeremy L Thompson } 587800f99ffSJeremy L Thompson 588800f99ffSJeremy L Thompson /*@C 589*5cb80ecdSBarry Smith DMSNESSetJacobianContextDestroy - set `SNES` Jacobian evaluation context destroy function 590800f99ffSJeremy L Thompson 591800f99ffSJeremy L Thompson Not Collective 592800f99ffSJeremy L Thompson 593800f99ffSJeremy L Thompson Input Parameters: 594*5cb80ecdSBarry Smith + dm - `DM` to be used with `SNES` 595*5cb80ecdSBarry Smith - f - Jacobian evaluation contex destroy function 596800f99ffSJeremy L Thompson 597800f99ffSJeremy L Thompson Level: advanced 598800f99ffSJeremy L Thompson 599800f99ffSJeremy L Thompson Note: 600*5cb80ecdSBarry Smith `SNESSetJacobianContextDestroy()` is normally used, but it calls this function internally because the user context is actually 601*5cb80ecdSBarry Smith associated with the `DM`. This makes the interface consistent regardless of whether the user interacts with a `DM` or 602*5cb80ecdSBarry Smith not. 603*5cb80ecdSBarry Smith 604*5cb80ecdSBarry Smith Developer Note: 605*5cb80ecdSBarry Smith If `DM` took a more central role at some later date, this could become the primary method of setting the Jacobian. 606800f99ffSJeremy L Thompson 607800f99ffSJeremy L Thompson .seealso: `DMSNESSetJacobian()`, `SNESSetJacobianContextDestroyFunction()` 608800f99ffSJeremy L Thompson @*/ 609800f99ffSJeremy L Thompson PetscErrorCode DMSNESSetJacobianContextDestroy(DM dm,PetscErrorCode (*f)(void*)) 610800f99ffSJeremy L Thompson { 611800f99ffSJeremy L Thompson DMSNES sdm; 612800f99ffSJeremy L Thompson 613800f99ffSJeremy L Thompson PetscFunctionBegin; 614800f99ffSJeremy L Thompson PetscValidHeaderSpecific(dm,DM_CLASSID,1); 615800f99ffSJeremy L Thompson PetscCall(DMGetDMSNESWrite(dm,&sdm)); 616800f99ffSJeremy L Thompson if (sdm->jacobianctxcontainer) PetscCall(PetscContainerSetUserDestroy(sdm->jacobianctxcontainer,f)); 617800f99ffSJeremy L Thompson PetscFunctionReturn(0); 618800f99ffSJeremy L Thompson } 619800f99ffSJeremy L Thompson 620800f99ffSJeremy L Thompson PetscErrorCode DMSNESUnsetJacobianContext_Internal(DM dm) 621800f99ffSJeremy L Thompson { 622800f99ffSJeremy L Thompson DMSNES sdm; 623800f99ffSJeremy L Thompson 624800f99ffSJeremy L Thompson PetscFunctionBegin; 625800f99ffSJeremy L Thompson PetscValidHeaderSpecific(dm,DM_CLASSID,1); 626800f99ffSJeremy L Thompson PetscCall(DMGetDMSNESWrite(dm,&sdm)); 627800f99ffSJeremy L Thompson PetscCall(DMSNESUnsetJacobianContext_DMSNES(sdm)); 6286cab3a1bSJed Brown PetscFunctionReturn(0); 6296cab3a1bSJed Brown } 6306cab3a1bSJed Brown 6316cab3a1bSJed Brown /*@C 632ecfdb398SPeter Brune DMSNESGetJacobian - get SNES Jacobian evaluation function 6336cab3a1bSJed Brown 6346cab3a1bSJed Brown Not Collective 6356cab3a1bSJed Brown 6364165533cSJose E. Roman Input Parameter: 6376cab3a1bSJed Brown . dm - DM to be used with SNES 6386cab3a1bSJed Brown 6394165533cSJose E. Roman Output Parameters: 640f8b49ee9SBarry Smith + J - Jacobian evaluation function; see SNESJacobianFunction for all calling sequence 6416cab3a1bSJed Brown - ctx - context for residual evaluation 6426cab3a1bSJed Brown 6436cab3a1bSJed Brown Level: advanced 6446cab3a1bSJed Brown 6456cab3a1bSJed Brown Note: 6466cab3a1bSJed Brown SNESGetJacobian() is normally used, but it calls this function internally because the user context is actually 6476cab3a1bSJed Brown associated with the DM. This makes the interface consistent regardless of whether the user interacts with a DM or 6486cab3a1bSJed Brown not. If DM took a more central role at some later date, this could become the primary method of setting the Jacobian. 6496cab3a1bSJed Brown 650db781477SPatrick Sanan .seealso: `DMSNESSetContext()`, `SNESSetFunction()`, `DMSNESSetJacobian()`, `SNESJacobianFunction` 6516cab3a1bSJed Brown @*/ 652d1e9a80fSBarry Smith PetscErrorCode DMSNESGetJacobian(DM dm,PetscErrorCode (**J)(SNES,Vec,Mat,Mat,void*),void **ctx) 6536cab3a1bSJed Brown { 654942e3340SBarry Smith DMSNES sdm; 6556cab3a1bSJed Brown 6566cab3a1bSJed Brown PetscFunctionBegin; 6576cab3a1bSJed Brown PetscValidHeaderSpecific(dm,DM_CLASSID,1); 6589566063dSJacob Faibussowitsch PetscCall(DMGetDMSNES(dm,&sdm)); 659f8b49ee9SBarry Smith if (J) *J = sdm->ops->computejacobian; 660800f99ffSJeremy L Thompson if (ctx) { 661800f99ffSJeremy L Thompson if (sdm->jacobianctxcontainer) PetscCall(PetscContainerGetPointer(sdm->jacobianctxcontainer,ctx)); 662800f99ffSJeremy L Thompson else *ctx = NULL; 663800f99ffSJeremy L Thompson } 6646cab3a1bSJed Brown PetscFunctionReturn(0); 6656cab3a1bSJed Brown } 6666cab3a1bSJed Brown 667e03ab78fSPeter Brune /*@C 668e03ab78fSPeter Brune DMSNESSetPicard - set SNES Picard iteration matrix and RHS evaluation functions. 669e03ab78fSPeter Brune 670e03ab78fSPeter Brune Not Collective 671e03ab78fSPeter Brune 6724165533cSJose E. Roman Input Parameters: 673e03ab78fSPeter Brune + dm - DM to be used with SNES 674f8b49ee9SBarry Smith . b - RHS evaluation function 675f8b49ee9SBarry Smith . J - Picard matrix evaluation function 676e03ab78fSPeter Brune - ctx - context for residual evaluation 677e03ab78fSPeter Brune 678e03ab78fSPeter Brune Level: advanced 679e03ab78fSPeter Brune 680db781477SPatrick Sanan .seealso: `SNESSetPicard()`, `DMSNESSetFunction()`, `DMSNESSetJacobian()` 681e03ab78fSPeter Brune @*/ 682d1e9a80fSBarry Smith PetscErrorCode DMSNESSetPicard(DM dm,PetscErrorCode (*b)(SNES,Vec,Vec,void*),PetscErrorCode (*J)(SNES,Vec,Mat,Mat,void*),void *ctx) 683e03ab78fSPeter Brune { 684942e3340SBarry Smith DMSNES sdm; 685e03ab78fSPeter Brune 686e03ab78fSPeter Brune PetscFunctionBegin; 687e03ab78fSPeter Brune PetscValidHeaderSpecific(dm,DM_CLASSID,1); 6889566063dSJacob Faibussowitsch PetscCall(DMGetDMSNES(dm,&sdm)); 689f8b49ee9SBarry Smith if (b) sdm->ops->computepfunction = b; 690f8b49ee9SBarry Smith if (J) sdm->ops->computepjacobian = J; 691e03ab78fSPeter Brune if (ctx) sdm->pctx = ctx; 692e03ab78fSPeter Brune PetscFunctionReturn(0); 693e03ab78fSPeter Brune } 694e03ab78fSPeter Brune 6957971a8bfSPeter Brune /*@C 6967971a8bfSPeter Brune DMSNESGetPicard - get SNES Picard iteration evaluation functions 6977971a8bfSPeter Brune 6987971a8bfSPeter Brune Not Collective 6997971a8bfSPeter Brune 7004165533cSJose E. Roman Input Parameter: 7017971a8bfSPeter Brune . dm - DM to be used with SNES 7027971a8bfSPeter Brune 7034165533cSJose E. Roman Output Parameters: 704f8b49ee9SBarry Smith + b - RHS evaluation function; see SNESFunction for details 705f8b49ee9SBarry Smith . J - RHS evaluation function; see SNESJacobianFunction for detailsa 7067971a8bfSPeter Brune - ctx - context for residual evaluation 7077971a8bfSPeter Brune 7087971a8bfSPeter Brune Level: advanced 7097971a8bfSPeter Brune 710db781477SPatrick Sanan .seealso: `DMSNESSetContext()`, `SNESSetFunction()`, `DMSNESSetJacobian()` 7117971a8bfSPeter Brune @*/ 712d1e9a80fSBarry Smith PetscErrorCode DMSNESGetPicard(DM dm,PetscErrorCode (**b)(SNES,Vec,Vec,void*),PetscErrorCode (**J)(SNES,Vec,Mat,Mat,void*),void **ctx) 7137971a8bfSPeter Brune { 714942e3340SBarry Smith DMSNES sdm; 7157971a8bfSPeter Brune 7167971a8bfSPeter Brune PetscFunctionBegin; 7177971a8bfSPeter Brune PetscValidHeaderSpecific(dm,DM_CLASSID,1); 7189566063dSJacob Faibussowitsch PetscCall(DMGetDMSNES(dm,&sdm)); 719f8b49ee9SBarry Smith if (b) *b = sdm->ops->computepfunction; 720f8b49ee9SBarry Smith if (J) *J = sdm->ops->computepjacobian; 7217971a8bfSPeter Brune if (ctx) *ctx = sdm->pctx; 7227971a8bfSPeter Brune PetscFunctionReturn(0); 7237971a8bfSPeter Brune } 724