xref: /petsc/src/snes/utils/dmsnes.c (revision c7a10e08591f5a3773572f14db2d1653e42f2f38)
1b45d2f2cSJed Brown #include <petsc-private/snesimpl.h>   /*I "petscsnes.h" I*/
2679f678eSPeter Brune #include <petsc-private/dmimpl.h>     /*I "petscdm.h" I*/
36cab3a1bSJed Brown 
46cab3a1bSJed Brown #undef __FUNCT__
522c6f798SBarry Smith #define __FUNCT__ "DMSNESDestroy"
622c6f798SBarry Smith static PetscErrorCode DMSNESDestroy(DMSNES *kdm)
76cab3a1bSJed Brown {
86cab3a1bSJed Brown   PetscErrorCode ierr;
96cab3a1bSJed Brown 
106cab3a1bSJed Brown   PetscFunctionBegin;
1122c6f798SBarry Smith  if (!*kdm) PetscFunctionReturn(0);
1222c6f798SBarry Smith   PetscValidHeaderSpecific((*kdm),DMSNES_CLASSID,1);
1322c6f798SBarry Smith   if (--((PetscObject)(*kdm))->refct > 0) {*kdm = 0; PetscFunctionReturn(0);}
1422c6f798SBarry Smith   if ((*kdm)->ops->destroy) {ierr = ((*kdm)->ops->destroy)(*kdm);CHKERRQ(ierr);}
1522c6f798SBarry Smith   ierr = PetscHeaderDestroy(kdm);CHKERRQ(ierr);
1622c6f798SBarry Smith   PetscFunctionReturn(0);
1722c6f798SBarry Smith }
1822c6f798SBarry Smith 
1922c6f798SBarry Smith #undef __FUNCT__
202d53ad75SBarry Smith #define __FUNCT__ "DMSNESLoad"
212d53ad75SBarry Smith PetscErrorCode DMSNESLoad(DMSNES kdm,PetscViewer viewer)
222d53ad75SBarry Smith {
232d53ad75SBarry Smith   PetscErrorCode ierr;
242d53ad75SBarry Smith 
252d53ad75SBarry Smith   PetscFunctionBegin;
262d53ad75SBarry Smith   ierr = PetscViewerBinaryRead(viewer,&kdm->ops->computefunction,1,PETSC_FUNCTION);CHKERRQ(ierr);
272d53ad75SBarry Smith   ierr = PetscViewerBinaryRead(viewer,&kdm->ops->computejacobian,1,PETSC_FUNCTION);CHKERRQ(ierr);
282d53ad75SBarry Smith   PetscFunctionReturn(0);
292d53ad75SBarry Smith }
302d53ad75SBarry Smith 
312d53ad75SBarry Smith #undef __FUNCT__
322d53ad75SBarry Smith #define __FUNCT__ "DMSNESView"
332d53ad75SBarry Smith PetscErrorCode DMSNESView(DMSNES kdm,PetscViewer viewer)
342d53ad75SBarry Smith {
352d53ad75SBarry Smith   PetscErrorCode ierr;
362d53ad75SBarry Smith   PetscBool      isascii,isbinary;
372d53ad75SBarry Smith 
382d53ad75SBarry Smith   PetscFunctionBegin;
392d53ad75SBarry Smith   ierr = PetscObjectTypeCompare((PetscObject)viewer,PETSCVIEWERASCII,&isascii);CHKERRQ(ierr);
402d53ad75SBarry Smith   ierr = PetscObjectTypeCompare((PetscObject)viewer,PETSCVIEWERBINARY,&isbinary);CHKERRQ(ierr);
412d53ad75SBarry Smith   if (isascii) {
42*c7a10e08SBarry Smith #if defined(PETSC_SERIALIZE_FUNCTIONS)
432d53ad75SBarry Smith     const char *fname;
442d53ad75SBarry Smith 
452d53ad75SBarry Smith     ierr = PetscFPTFind(kdm->ops->computefunction,&fname);CHKERRQ(ierr);
462d53ad75SBarry Smith     if (fname) {
472d53ad75SBarry Smith       ierr = PetscViewerASCIIPrintf(viewer,"Function used by SNES: %s\n",fname);CHKERRQ(ierr);
482d53ad75SBarry Smith     }
492d53ad75SBarry Smith     ierr = PetscFPTFind(kdm->ops->computejacobian,&fname);CHKERRQ(ierr);
502d53ad75SBarry Smith     if (fname) {
512d53ad75SBarry Smith       ierr = PetscViewerASCIIPrintf(viewer,"Jacobian function used by SNES: %s\n",fname);CHKERRQ(ierr);
522d53ad75SBarry Smith     }
53*c7a10e08SBarry Smith #endif
542d53ad75SBarry Smith   } else if (isbinary) {
552d53ad75SBarry Smith     ierr = PetscViewerBinaryWrite(viewer,kdm->ops->computefunction,1,PETSC_FUNCTION,PETSC_FALSE);CHKERRQ(ierr);
562d53ad75SBarry Smith     ierr = PetscViewerBinaryWrite(viewer,kdm->ops->computejacobian,1,PETSC_FUNCTION,PETSC_FALSE);CHKERRQ(ierr);
572d53ad75SBarry Smith   }
582d53ad75SBarry Smith   PetscFunctionReturn(0);
592d53ad75SBarry Smith }
602d53ad75SBarry Smith 
612d53ad75SBarry Smith #undef __FUNCT__
6222c6f798SBarry Smith #define __FUNCT__ "DMSNESCreate"
6322c6f798SBarry Smith static PetscErrorCode DMSNESCreate(MPI_Comm comm,DMSNES *kdm)
6422c6f798SBarry Smith {
6522c6f798SBarry Smith   PetscErrorCode ierr;
6622c6f798SBarry Smith 
6722c6f798SBarry Smith   PetscFunctionBegin;
6822c6f798SBarry Smith #ifndef PETSC_USE_DYNAMIC_LIBRARIES
6922c6f798SBarry Smith   ierr = SNESInitializePackage(PETSC_NULL);CHKERRQ(ierr);
7022c6f798SBarry Smith #endif
712d53ad75SBarry Smith   ierr = PetscHeaderCreate(*kdm, _p_DMSNES, struct _DMSNESOps, DMSNES_CLASSID, -1, "DMSNES", "DMSNES", "DMSNES", comm, DMSNESDestroy, DMSNESView);CHKERRQ(ierr);
7222c6f798SBarry Smith   ierr = PetscMemzero((*kdm)->ops, sizeof(struct _DMSNESOps));CHKERRQ(ierr);
736cab3a1bSJed Brown   PetscFunctionReturn(0);
746cab3a1bSJed Brown }
756cab3a1bSJed Brown 
766cab3a1bSJed Brown #undef __FUNCT__
77942e3340SBarry Smith #define __FUNCT__ "DMCoarsenHook_DMSNES"
78942e3340SBarry Smith /* Attaches the DMSNES to the coarse level.
796cab3a1bSJed Brown  * Under what conditions should we copy versus duplicate?
806cab3a1bSJed Brown  */
81942e3340SBarry Smith static PetscErrorCode DMCoarsenHook_DMSNES(DM dm,DM dmc,void *ctx)
826cab3a1bSJed Brown {
836cab3a1bSJed Brown   PetscErrorCode ierr;
846cab3a1bSJed Brown 
856cab3a1bSJed Brown   PetscFunctionBegin;
86942e3340SBarry Smith   ierr = DMCopyDMSNES(dm,dmc);CHKERRQ(ierr);
876cab3a1bSJed Brown   PetscFunctionReturn(0);
886cab3a1bSJed Brown }
896cab3a1bSJed Brown 
906cab3a1bSJed Brown #undef __FUNCT__
91942e3340SBarry Smith #define __FUNCT__ "DMRestrictHook_DMSNES"
92dfe15315SJed Brown /* This could restrict auxiliary information to the coarse level.
93caa4e7f2SJed Brown  */
94942e3340SBarry Smith static PetscErrorCode DMRestrictHook_DMSNES(DM dm,Mat Restrict,Vec rscale,Mat Inject,DM dmc,void *ctx)
95caa4e7f2SJed Brown {
96caa4e7f2SJed Brown 
97caa4e7f2SJed Brown   PetscFunctionBegin;
98caa4e7f2SJed Brown   PetscFunctionReturn(0);
99caa4e7f2SJed Brown }
100caa4e7f2SJed Brown 
101caa4e7f2SJed Brown #undef __FUNCT__
102942e3340SBarry Smith #define __FUNCT__ "DMRefineHook_DMSNES"
103942e3340SBarry Smith static PetscErrorCode DMRefineHook_DMSNES(DM dm,DM dmf,void *ctx)
10403a0fabfSPeter Brune {
10503a0fabfSPeter Brune   PetscErrorCode ierr;
10603a0fabfSPeter Brune 
10703a0fabfSPeter Brune   PetscFunctionBegin;
108942e3340SBarry Smith   ierr = DMCopyDMSNES(dm,dmf);CHKERRQ(ierr);
10903a0fabfSPeter Brune   PetscFunctionReturn(0);
11003a0fabfSPeter Brune }
11103a0fabfSPeter Brune 
11203a0fabfSPeter Brune #undef __FUNCT__
113942e3340SBarry Smith #define __FUNCT__ "DMInterpolateHook_DMSNES"
11403a0fabfSPeter Brune /* This could restrict auxiliary information to the coarse level.
11503a0fabfSPeter Brune  */
116942e3340SBarry Smith static PetscErrorCode DMInterpolateHook_DMSNES(DM dm,Mat Interp,DM dmf,void *ctx)
11703a0fabfSPeter Brune {
11803a0fabfSPeter Brune 
11903a0fabfSPeter Brune   PetscFunctionBegin;
12003a0fabfSPeter Brune   PetscFunctionReturn(0);
12103a0fabfSPeter Brune }
12203a0fabfSPeter Brune 
12303a0fabfSPeter Brune #undef __FUNCT__
12422c6f798SBarry Smith #define __FUNCT__ "DMSNESCopy"
12522c6f798SBarry Smith /*@C
12622c6f798SBarry Smith    DMSNESCopy - copies the information in a DMSNES to another DMSNES
12722c6f798SBarry Smith 
12822c6f798SBarry Smith    Not Collective
12922c6f798SBarry Smith 
13022c6f798SBarry Smith    Input Argument:
13122c6f798SBarry Smith +  kdm - Original DMSNES
13222c6f798SBarry Smith -  nkdm - DMSNES to receive the data, should have been created with DMSNESCreate()
13322c6f798SBarry Smith 
13422c6f798SBarry Smith    Level: developer
13522c6f798SBarry Smith 
13622c6f798SBarry Smith .seealso: DMSNESCreate(), DMSNESDestroy()
13722c6f798SBarry Smith @*/
13822c6f798SBarry Smith PetscErrorCode DMSNESCopy(DMSNES kdm,DMSNES nkdm)
13922c6f798SBarry Smith {
14022c6f798SBarry Smith   PetscErrorCode ierr;
14122c6f798SBarry Smith 
14222c6f798SBarry Smith   PetscFunctionBegin;
14322c6f798SBarry Smith   PetscValidHeaderSpecific(kdm,DMSNES_CLASSID,1);
14422c6f798SBarry Smith   PetscValidHeaderSpecific(nkdm,DMSNES_CLASSID,2);
14522c6f798SBarry Smith   nkdm->ops->computefunction       = kdm->ops->computefunction;
14622c6f798SBarry Smith   nkdm->ops->computegs             = kdm->ops->computegs;
14722c6f798SBarry Smith   nkdm->ops->computeobjective      = kdm->ops->computeobjective;
14822c6f798SBarry Smith   nkdm->ops->computepjacobian      = kdm->ops->computepjacobian;
14922c6f798SBarry Smith   nkdm->ops->computepfunction      = kdm->ops->computepfunction;
15022c6f798SBarry Smith   nkdm->ops->computeblockfunction  = kdm->ops->computeblockfunction;
15122c6f798SBarry Smith   nkdm->ops->computeblockjacobian  = kdm->ops->computeblockjacobian;
15222c6f798SBarry Smith   nkdm->ops->destroy               = kdm->ops->destroy;
15322c6f798SBarry Smith   nkdm->ops->duplicate             = kdm->ops->duplicate;
15422c6f798SBarry Smith 
15522c6f798SBarry Smith   nkdm->functionctx      = kdm->functionctx;
15622c6f798SBarry Smith   nkdm->gsctx            = kdm->gsctx;
15722c6f798SBarry Smith   nkdm->pctx             = kdm->pctx;
15822c6f798SBarry Smith   nkdm->jacobianctx      = kdm->jacobianctx;
15922c6f798SBarry Smith   nkdm->objectivectx     = kdm->objectivectx;
16022c6f798SBarry Smith   nkdm->blockfunctionctx = kdm->blockfunctionctx;
16122c6f798SBarry Smith   nkdm->blockjacobianctx = kdm->blockjacobianctx;
16222c6f798SBarry Smith   nkdm->data             = kdm->data;
16322c6f798SBarry Smith 
16422c6f798SBarry Smith   /*
16522c6f798SBarry Smith   nkdm->fortran_func_pointers[0] = kdm->fortran_func_pointers[0];
16622c6f798SBarry Smith   nkdm->fortran_func_pointers[1] = kdm->fortran_func_pointers[1];
16722c6f798SBarry Smith   nkdm->fortran_func_pointers[2] = kdm->fortran_func_pointers[2];
16822c6f798SBarry Smith   */
16922c6f798SBarry Smith 
17022c6f798SBarry Smith   /* implementation specific copy hooks */
17122c6f798SBarry Smith   if (kdm->ops->duplicate) {ierr = (*kdm->ops->duplicate)(kdm,nkdm);CHKERRQ(ierr);}
17222c6f798SBarry Smith   PetscFunctionReturn(0);
17322c6f798SBarry Smith }
17422c6f798SBarry Smith 
17522c6f798SBarry Smith #undef __FUNCT__
176942e3340SBarry Smith #define __FUNCT__ "DMGetDMSNES"
1776cab3a1bSJed Brown /*@C
178942e3340SBarry Smith    DMGetDMSNES - get read-only private DMSNES context from a DM
1796cab3a1bSJed Brown 
1806cab3a1bSJed Brown    Not Collective
1816cab3a1bSJed Brown 
1826cab3a1bSJed Brown    Input Argument:
1836cab3a1bSJed Brown .  dm - DM to be used with SNES
1846cab3a1bSJed Brown 
1856cab3a1bSJed Brown    Output Argument:
186942e3340SBarry Smith .  snesdm - private DMSNES context
1876cab3a1bSJed Brown 
1886cab3a1bSJed Brown    Level: developer
1896cab3a1bSJed Brown 
1906cab3a1bSJed Brown    Notes:
191942e3340SBarry Smith    Use DMGetDMSNESWrite() if write access is needed. The DMSNESSetXXX API should be used wherever possible.
1926cab3a1bSJed Brown 
193942e3340SBarry Smith .seealso: DMGetDMSNESWrite()
1946cab3a1bSJed Brown @*/
195942e3340SBarry Smith PetscErrorCode DMGetDMSNES(DM dm,DMSNES *snesdm)
1966cab3a1bSJed Brown {
1976cab3a1bSJed Brown   PetscErrorCode ierr;
1986cab3a1bSJed Brown 
1996cab3a1bSJed Brown   PetscFunctionBegin;
2006cab3a1bSJed Brown   PetscValidHeaderSpecific(dm,DM_CLASSID,1);
201b4615a05SBarry Smith   *snesdm = (DMSNES) dm->dmsnes;
20222c6f798SBarry Smith   if (!*snesdm) {
203942e3340SBarry Smith     ierr = PetscInfo(dm,"Creating new DMSNES\n");CHKERRQ(ierr);
20422c6f798SBarry Smith     ierr = DMSNESCreate(((PetscObject)dm)->comm,snesdm);CHKERRQ(ierr);
205b4615a05SBarry Smith     dm->dmsnes = (PetscObject) *snesdm;
206942e3340SBarry Smith     ierr = DMCoarsenHookAdd(dm,DMCoarsenHook_DMSNES,DMRestrictHook_DMSNES,PETSC_NULL);CHKERRQ(ierr);
20722c6f798SBarry Smith     ierr = DMRefineHookAdd(dm,DMRefineHook_DMSNES,DMInterpolateHook_DMSNES,PETSC_NULL);CHKERRQ(ierr);
2086cab3a1bSJed Brown   }
2096cab3a1bSJed Brown   PetscFunctionReturn(0);
2106cab3a1bSJed Brown }
2116cab3a1bSJed Brown 
2126cab3a1bSJed Brown #undef __FUNCT__
213942e3340SBarry Smith #define __FUNCT__ "DMGetDMSNESWrite"
2146cab3a1bSJed Brown /*@C
215942e3340SBarry Smith    DMGetDMSNESWrite - get write access to private DMSNES context from a DM
2166cab3a1bSJed Brown 
2176cab3a1bSJed Brown    Not Collective
2186cab3a1bSJed Brown 
2196cab3a1bSJed Brown    Input Argument:
2206cab3a1bSJed Brown .  dm - DM to be used with SNES
2216cab3a1bSJed Brown 
2226cab3a1bSJed Brown    Output Argument:
223942e3340SBarry Smith .  snesdm - private DMSNES context
2246cab3a1bSJed Brown 
2256cab3a1bSJed Brown    Level: developer
2266cab3a1bSJed Brown 
227942e3340SBarry Smith .seealso: DMGetDMSNES()
2286cab3a1bSJed Brown @*/
229942e3340SBarry Smith PetscErrorCode DMGetDMSNESWrite(DM dm,DMSNES *snesdm)
2306cab3a1bSJed Brown {
2316cab3a1bSJed Brown   PetscErrorCode ierr;
232942e3340SBarry Smith   DMSNES         sdm;
2336cab3a1bSJed Brown 
2346cab3a1bSJed Brown   PetscFunctionBegin;
2356cab3a1bSJed Brown   PetscValidHeaderSpecific(dm,DM_CLASSID,1);
236942e3340SBarry Smith   ierr = DMGetDMSNES(dm,&sdm);CHKERRQ(ierr);
2376cab3a1bSJed Brown   if (!sdm->originaldm) sdm->originaldm = dm;
2386cab3a1bSJed Brown   if (sdm->originaldm != dm) {  /* Copy on write */
239b4615a05SBarry Smith     DMSNES          oldsdm = sdm;
240942e3340SBarry Smith     ierr = PetscInfo(dm,"Copying DMSNES due to write\n");CHKERRQ(ierr);
24122c6f798SBarry Smith     ierr = DMSNESCreate(((PetscObject)dm)->comm,&sdm);CHKERRQ(ierr);
24222c6f798SBarry Smith     ierr = DMSNESCopy(oldsdm,sdm);CHKERRQ(ierr);
243b4615a05SBarry Smith     ierr = DMSNESDestroy((DMSNES*)&dm->dmsnes);CHKERRQ(ierr);
244b4615a05SBarry Smith     dm->dmsnes = (PetscObject)sdm;
2456cab3a1bSJed Brown   }
2466cab3a1bSJed Brown   *snesdm = sdm;
2476cab3a1bSJed Brown   PetscFunctionReturn(0);
2486cab3a1bSJed Brown }
2496cab3a1bSJed Brown 
2506cab3a1bSJed Brown #undef __FUNCT__
251942e3340SBarry Smith #define __FUNCT__ "DMCopyDMSNES"
2526cab3a1bSJed Brown /*@C
253942e3340SBarry Smith    DMCopyDMSNES - copies a DM context to a new DM
2546cab3a1bSJed Brown 
2556cab3a1bSJed Brown    Logically Collective
2566cab3a1bSJed Brown 
2576cab3a1bSJed Brown    Input Arguments:
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 
266942e3340SBarry Smith .seealso: DMGetDMSNES(), SNESSetDM()
2676cab3a1bSJed Brown @*/
268942e3340SBarry Smith PetscErrorCode DMCopyDMSNES(DM dmsrc,DM dmdest)
2696cab3a1bSJed Brown {
2706cab3a1bSJed Brown   PetscErrorCode ierr;
2716cab3a1bSJed Brown 
2726cab3a1bSJed Brown   PetscFunctionBegin;
2736cab3a1bSJed Brown   PetscValidHeaderSpecific(dmsrc,DM_CLASSID,1);
2746cab3a1bSJed Brown   PetscValidHeaderSpecific(dmdest,DM_CLASSID,2);
275b4615a05SBarry Smith   ierr = DMSNESDestroy((DMSNES*)&dmdest->dmsnes);CHKERRQ(ierr);
276b4615a05SBarry Smith   dmdest->dmsnes = dmsrc->dmsnes;
277b4615a05SBarry Smith   ierr = PetscObjectReference(dmdest->dmsnes);CHKERRQ(ierr);
27822c6f798SBarry Smith   ierr = DMCoarsenHookAdd(dmdest,DMCoarsenHook_DMSNES,PETSC_NULL,PETSC_NULL);CHKERRQ(ierr);
27922c6f798SBarry Smith   ierr = DMRefineHookAdd(dmdest,DMRefineHook_DMSNES,PETSC_NULL,PETSC_NULL);CHKERRQ(ierr);
2806cab3a1bSJed Brown   PetscFunctionReturn(0);
2816cab3a1bSJed Brown }
2826cab3a1bSJed Brown 
2836cab3a1bSJed Brown #undef __FUNCT__
2846cab3a1bSJed Brown #define __FUNCT__ "DMSNESSetFunction"
2856cab3a1bSJed Brown /*@C
2866cab3a1bSJed Brown    DMSNESSetFunction - set SNES residual evaluation function
2876cab3a1bSJed Brown 
2886cab3a1bSJed Brown    Not Collective
2896cab3a1bSJed Brown 
2906cab3a1bSJed Brown    Input Arguments:
2916cab3a1bSJed Brown +  dm - DM to be used with SNES
2926cab3a1bSJed Brown .  func - residual evaluation function, see SNESSetFunction() for calling sequence
2936cab3a1bSJed Brown -  ctx - context for residual evaluation
2946cab3a1bSJed Brown 
2956cab3a1bSJed Brown    Level: advanced
2966cab3a1bSJed Brown 
2976cab3a1bSJed Brown    Note:
2986cab3a1bSJed Brown    SNESSetFunction() is normally used, but it calls this function internally because the user context is actually
2996cab3a1bSJed Brown    associated with the DM.  This makes the interface consistent regardless of whether the user interacts with a DM or
3006cab3a1bSJed Brown    not. If DM took a more central role at some later date, this could become the primary method of setting the residual.
3016cab3a1bSJed Brown 
3026cab3a1bSJed Brown .seealso: DMSNESSetContext(), SNESSetFunction(), DMSNESSetJacobian()
3036cab3a1bSJed Brown @*/
3046cab3a1bSJed Brown PetscErrorCode DMSNESSetFunction(DM dm,PetscErrorCode (*func)(SNES,Vec,Vec,void*),void *ctx)
3056cab3a1bSJed Brown {
3066cab3a1bSJed Brown   PetscErrorCode ierr;
307942e3340SBarry Smith   DMSNES         sdm;
3086cab3a1bSJed Brown 
3096cab3a1bSJed Brown   PetscFunctionBegin;
3106cab3a1bSJed Brown   PetscValidHeaderSpecific(dm,DM_CLASSID,1);
311fdaff8d6SPeter Brune   if (func || ctx) {
312942e3340SBarry Smith     ierr = DMGetDMSNESWrite(dm,&sdm);CHKERRQ(ierr);
313fdaff8d6SPeter Brune   }
31422c6f798SBarry Smith   if (func) sdm->ops->computefunction = func;
3156cab3a1bSJed Brown   if (ctx)  sdm->functionctx = ctx;
3166cab3a1bSJed Brown   PetscFunctionReturn(0);
3176cab3a1bSJed Brown }
3186cab3a1bSJed Brown 
3196cab3a1bSJed Brown #undef __FUNCT__
3206cab3a1bSJed Brown #define __FUNCT__ "DMSNESGetFunction"
3216cab3a1bSJed Brown /*@C
3226cab3a1bSJed Brown    DMSNESGetFunction - get SNES residual evaluation function
3236cab3a1bSJed Brown 
3246cab3a1bSJed Brown    Not Collective
3256cab3a1bSJed Brown 
3266cab3a1bSJed Brown    Input Argument:
3276cab3a1bSJed Brown .  dm - DM to be used with SNES
3286cab3a1bSJed Brown 
3296cab3a1bSJed Brown    Output Arguments:
3306cab3a1bSJed Brown +  func - residual evaluation function, see SNESSetFunction() for calling sequence
3316cab3a1bSJed Brown -  ctx - context for residual evaluation
3326cab3a1bSJed Brown 
3336cab3a1bSJed Brown    Level: advanced
3346cab3a1bSJed Brown 
3356cab3a1bSJed Brown    Note:
3366cab3a1bSJed Brown    SNESGetFunction() is normally used, but it calls this function internally because the user context is actually
3376cab3a1bSJed Brown    associated with the DM.
3386cab3a1bSJed Brown 
3396cab3a1bSJed Brown .seealso: DMSNESSetContext(), DMSNESSetFunction(), SNESSetFunction()
3406cab3a1bSJed Brown @*/
3416cab3a1bSJed Brown PetscErrorCode DMSNESGetFunction(DM dm,PetscErrorCode (**func)(SNES,Vec,Vec,void*),void **ctx)
3426cab3a1bSJed Brown {
3436cab3a1bSJed Brown   PetscErrorCode ierr;
344942e3340SBarry Smith   DMSNES         sdm;
3456cab3a1bSJed Brown 
3466cab3a1bSJed Brown   PetscFunctionBegin;
3476cab3a1bSJed Brown   PetscValidHeaderSpecific(dm,DM_CLASSID,1);
348942e3340SBarry Smith   ierr = DMGetDMSNES(dm,&sdm);CHKERRQ(ierr);
34922c6f798SBarry Smith   if (func) *func = sdm->ops->computefunction;
3506cab3a1bSJed Brown   if (ctx)  *ctx = sdm->functionctx;
3516cab3a1bSJed Brown   PetscFunctionReturn(0);
3526cab3a1bSJed Brown }
3536cab3a1bSJed Brown 
3546cab3a1bSJed Brown #undef __FUNCT__
3552a4ee8f2SPeter Brune #define __FUNCT__ "DMSNESSetObjective"
3562a4ee8f2SPeter Brune /*@C
357081a7dcdSPeter Brune    DMSNESSetObjective - set SNES objective evaluation function
3582a4ee8f2SPeter Brune 
3592a4ee8f2SPeter Brune    Not Collective
3602a4ee8f2SPeter Brune 
3612a4ee8f2SPeter Brune    Input Arguments:
3622a4ee8f2SPeter Brune +  dm - DM to be used with SNES
3632a4ee8f2SPeter Brune .  func - residual evaluation function, see SNESSetObjective() for calling sequence
3642a4ee8f2SPeter Brune -  ctx - context for residual evaluation
3652a4ee8f2SPeter Brune 
3662a4ee8f2SPeter Brune    Level: advanced
3672a4ee8f2SPeter Brune 
3682a4ee8f2SPeter Brune .seealso: DMSNESSetContext(), SNESGetObjective(), DMSNESSetFunction()
3692a4ee8f2SPeter Brune @*/
3702a4ee8f2SPeter Brune PetscErrorCode DMSNESSetObjective(DM dm,SNESObjective func,void *ctx)
3712a4ee8f2SPeter Brune {
3722a4ee8f2SPeter Brune   PetscErrorCode ierr;
373942e3340SBarry Smith   DMSNES         sdm;
3742a4ee8f2SPeter Brune 
3752a4ee8f2SPeter Brune   PetscFunctionBegin;
3762a4ee8f2SPeter Brune   PetscValidHeaderSpecific(dm,DM_CLASSID,1);
377fdaff8d6SPeter Brune   if (func || ctx) {
378942e3340SBarry Smith     ierr = DMGetDMSNESWrite(dm,&sdm);CHKERRQ(ierr);
379fdaff8d6SPeter Brune   }
38022c6f798SBarry Smith   if (func) sdm->ops->computeobjective = func;
3812a4ee8f2SPeter Brune   if (ctx)  sdm->objectivectx = ctx;
3822a4ee8f2SPeter Brune   PetscFunctionReturn(0);
3832a4ee8f2SPeter Brune }
3842a4ee8f2SPeter Brune 
3852a4ee8f2SPeter Brune #undef __FUNCT__
3862a4ee8f2SPeter Brune #define __FUNCT__ "DMSNESGetObjective"
3872a4ee8f2SPeter Brune /*@C
3882a4ee8f2SPeter Brune    DMSNESGetObjective - get SNES objective evaluation function
3892a4ee8f2SPeter Brune 
3902a4ee8f2SPeter Brune    Not Collective
3912a4ee8f2SPeter Brune 
3922a4ee8f2SPeter Brune    Input Argument:
3932a4ee8f2SPeter Brune .  dm - DM to be used with SNES
3942a4ee8f2SPeter Brune 
3952a4ee8f2SPeter Brune    Output Arguments:
3962a4ee8f2SPeter Brune +  func - residual evaluation function, see SNESSetObjective() for calling sequence
3972a4ee8f2SPeter Brune -  ctx - context for residual evaluation
3982a4ee8f2SPeter Brune 
3992a4ee8f2SPeter Brune    Level: advanced
4002a4ee8f2SPeter Brune 
4012a4ee8f2SPeter Brune    Note:
4022a4ee8f2SPeter Brune    SNESGetFunction() is normally used, but it calls this function internally because the user context is actually
4032a4ee8f2SPeter Brune    associated with the DM.
4042a4ee8f2SPeter Brune 
4052a4ee8f2SPeter Brune .seealso: DMSNESSetContext(), DMSNESSetObjective(), SNESSetFunction()
4062a4ee8f2SPeter Brune @*/
4072a4ee8f2SPeter Brune PetscErrorCode DMSNESGetObjective(DM dm,SNESObjective *func,void **ctx)
4082a4ee8f2SPeter Brune {
4092a4ee8f2SPeter Brune   PetscErrorCode ierr;
410942e3340SBarry Smith   DMSNES         sdm;
4112a4ee8f2SPeter Brune 
4122a4ee8f2SPeter Brune   PetscFunctionBegin;
4132a4ee8f2SPeter Brune   PetscValidHeaderSpecific(dm,DM_CLASSID,1);
414942e3340SBarry Smith   ierr = DMGetDMSNES(dm,&sdm);CHKERRQ(ierr);
41522c6f798SBarry Smith   if (func) *func = sdm->ops->computeobjective;
4162a4ee8f2SPeter Brune   if (ctx)  *ctx = sdm->objectivectx;
4172a4ee8f2SPeter Brune   PetscFunctionReturn(0);
4182a4ee8f2SPeter Brune }
4192a4ee8f2SPeter Brune 
4202a4ee8f2SPeter Brune #undef __FUNCT__
4216cab3a1bSJed Brown #define __FUNCT__ "DMSNESSetGS"
4226cab3a1bSJed Brown /*@C
4236cab3a1bSJed Brown    DMSNESSetGS - set SNES Gauss-Seidel relaxation function
4246cab3a1bSJed Brown 
4256cab3a1bSJed Brown    Not Collective
4266cab3a1bSJed Brown 
4276cab3a1bSJed Brown    Input Argument:
4286cab3a1bSJed Brown +  dm - DM to be used with SNES
4296cab3a1bSJed Brown .  func - relaxation function, see SNESSetGS() for calling sequence
4306cab3a1bSJed Brown -  ctx - context for residual evaluation
4316cab3a1bSJed Brown 
4326cab3a1bSJed Brown    Level: advanced
4336cab3a1bSJed Brown 
4346cab3a1bSJed Brown    Note:
4356cab3a1bSJed Brown    SNESSetGS() is normally used, but it calls this function internally because the user context is actually
4366cab3a1bSJed Brown    associated with the DM.  This makes the interface consistent regardless of whether the user interacts with a DM or
4376cab3a1bSJed Brown    not. If DM took a more central role at some later date, this could become the primary method of setting the residual.
4386cab3a1bSJed Brown 
4396cab3a1bSJed Brown .seealso: DMSNESSetContext(), SNESSetFunction(), DMSNESSetJacobian(), DMSNESSetFunction()
4406cab3a1bSJed Brown @*/
4416cab3a1bSJed Brown PetscErrorCode DMSNESSetGS(DM dm,PetscErrorCode (*func)(SNES,Vec,Vec,void*),void *ctx)
4426cab3a1bSJed Brown {
4436cab3a1bSJed Brown   PetscErrorCode ierr;
444942e3340SBarry Smith   DMSNES         sdm;
4456cab3a1bSJed Brown 
4466cab3a1bSJed Brown   PetscFunctionBegin;
4476cab3a1bSJed Brown   PetscValidHeaderSpecific(dm,DM_CLASSID,1);
448fdaff8d6SPeter Brune   if (func || ctx) {
449942e3340SBarry Smith     ierr = DMGetDMSNESWrite(dm,&sdm);CHKERRQ(ierr);
450fdaff8d6SPeter Brune   }
45122c6f798SBarry Smith   if (func) sdm->ops->computegs = func;
4526cab3a1bSJed Brown   if (ctx)  sdm->gsctx = ctx;
4536cab3a1bSJed Brown   PetscFunctionReturn(0);
4546cab3a1bSJed Brown }
4556cab3a1bSJed Brown 
4566cab3a1bSJed Brown #undef __FUNCT__
4576cab3a1bSJed Brown #define __FUNCT__ "DMSNESGetGS"
4586cab3a1bSJed Brown /*@C
4596cab3a1bSJed Brown    DMSNESGetGS - get SNES Gauss-Seidel relaxation function
4606cab3a1bSJed Brown 
4616cab3a1bSJed Brown    Not Collective
4626cab3a1bSJed Brown 
4636cab3a1bSJed Brown    Input Argument:
4646cab3a1bSJed Brown .  dm - DM to be used with SNES
4656cab3a1bSJed Brown 
4666cab3a1bSJed Brown    Output Arguments:
4676cab3a1bSJed Brown +  func - relaxation function, see SNESSetGS() for calling sequence
4686cab3a1bSJed Brown -  ctx - context for residual evaluation
4696cab3a1bSJed Brown 
4706cab3a1bSJed Brown    Level: advanced
4716cab3a1bSJed Brown 
4726cab3a1bSJed Brown    Note:
4736cab3a1bSJed Brown    SNESGetGS() is normally used, but it calls this function internally because the user context is actually
4746cab3a1bSJed Brown    associated with the DM.  This makes the interface consistent regardless of whether the user interacts with a DM or
4756cab3a1bSJed Brown    not. If DM took a more central role at some later date, this could become the primary method of setting the residual.
4766cab3a1bSJed Brown 
4776cab3a1bSJed Brown .seealso: DMSNESSetContext(), SNESGetGS(), DMSNESGetJacobian(), DMSNESGetFunction()
4786cab3a1bSJed Brown @*/
4796cab3a1bSJed Brown PetscErrorCode DMSNESGetGS(DM dm,PetscErrorCode (**func)(SNES,Vec,Vec,void*),void **ctx)
4806cab3a1bSJed Brown {
4816cab3a1bSJed Brown   PetscErrorCode ierr;
482942e3340SBarry Smith   DMSNES         sdm;
4836cab3a1bSJed Brown 
4846cab3a1bSJed Brown   PetscFunctionBegin;
4856cab3a1bSJed Brown   PetscValidHeaderSpecific(dm,DM_CLASSID,1);
486942e3340SBarry Smith   ierr = DMGetDMSNES(dm,&sdm);CHKERRQ(ierr);
48722c6f798SBarry Smith   if (func) *func = sdm->ops->computegs;
4886cab3a1bSJed Brown   if (ctx)  *ctx = sdm->gsctx;
4896cab3a1bSJed Brown   PetscFunctionReturn(0);
4906cab3a1bSJed Brown }
4916cab3a1bSJed Brown 
4926cab3a1bSJed Brown #undef __FUNCT__
4936cab3a1bSJed Brown #define __FUNCT__ "DMSNESSetJacobian"
4946cab3a1bSJed Brown /*@C
495ecfdb398SPeter Brune    DMSNESSetJacobian - set SNES Jacobian evaluation function
4966cab3a1bSJed Brown 
4976cab3a1bSJed Brown    Not Collective
4986cab3a1bSJed Brown 
4996cab3a1bSJed Brown    Input Argument:
5006cab3a1bSJed Brown +  dm - DM to be used with SNES
5016cab3a1bSJed Brown .  func - Jacobian evaluation function, see SNESSetJacobian() for calling sequence
5026cab3a1bSJed Brown -  ctx - context for residual evaluation
5036cab3a1bSJed Brown 
5046cab3a1bSJed Brown    Level: advanced
5056cab3a1bSJed Brown 
5066cab3a1bSJed Brown    Note:
5076cab3a1bSJed Brown    SNESSetJacobian() is normally used, but it calls this function internally because the user context is actually
5086cab3a1bSJed Brown    associated with the DM.  This makes the interface consistent regardless of whether the user interacts with a DM or
5096cab3a1bSJed Brown    not. If DM took a more central role at some later date, this could become the primary method of setting the Jacobian.
5106cab3a1bSJed Brown 
5116cab3a1bSJed Brown .seealso: DMSNESSetContext(), SNESSetFunction(), DMSNESGetJacobian(), SNESSetJacobian()
5126cab3a1bSJed Brown @*/
5136cab3a1bSJed Brown PetscErrorCode DMSNESSetJacobian(DM dm,PetscErrorCode (*func)(SNES,Vec,Mat*,Mat*,MatStructure*,void*),void *ctx)
5146cab3a1bSJed Brown {
5156cab3a1bSJed Brown   PetscErrorCode ierr;
516942e3340SBarry Smith   DMSNES         sdm;
5176cab3a1bSJed Brown 
5186cab3a1bSJed Brown   PetscFunctionBegin;
5196cab3a1bSJed Brown   PetscValidHeaderSpecific(dm,DM_CLASSID,1);
5201fdfe764SBarry Smith   if (func || ctx) {
521942e3340SBarry Smith     ierr = DMGetDMSNESWrite(dm,&sdm);CHKERRQ(ierr);
5221fdfe764SBarry Smith   }
52322c6f798SBarry Smith   if (func) sdm->ops->computejacobian = func;
5246cab3a1bSJed Brown   if (ctx)  sdm->jacobianctx = ctx;
5256cab3a1bSJed Brown   PetscFunctionReturn(0);
5266cab3a1bSJed Brown }
5276cab3a1bSJed Brown 
5286cab3a1bSJed Brown #undef __FUNCT__
5296cab3a1bSJed Brown #define __FUNCT__ "DMSNESGetJacobian"
5306cab3a1bSJed Brown /*@C
531ecfdb398SPeter Brune    DMSNESGetJacobian - get SNES Jacobian evaluation function
5326cab3a1bSJed Brown 
5336cab3a1bSJed Brown    Not Collective
5346cab3a1bSJed Brown 
5356cab3a1bSJed Brown    Input Argument:
5366cab3a1bSJed Brown .  dm - DM to be used with SNES
5376cab3a1bSJed Brown 
5386cab3a1bSJed Brown    Output Arguments:
5396cab3a1bSJed Brown +  func - Jacobian evaluation function, see SNESSetJacobian() for calling sequence
5406cab3a1bSJed Brown -  ctx - context for residual evaluation
5416cab3a1bSJed Brown 
5426cab3a1bSJed Brown    Level: advanced
5436cab3a1bSJed Brown 
5446cab3a1bSJed Brown    Note:
5456cab3a1bSJed Brown    SNESGetJacobian() is normally used, but it calls this function internally because the user context is actually
5466cab3a1bSJed Brown    associated with the DM.  This makes the interface consistent regardless of whether the user interacts with a DM or
5476cab3a1bSJed Brown    not. If DM took a more central role at some later date, this could become the primary method of setting the Jacobian.
5486cab3a1bSJed Brown 
5496cab3a1bSJed Brown .seealso: DMSNESSetContext(), SNESSetFunction(), DMSNESSetJacobian()
5506cab3a1bSJed Brown @*/
5516cab3a1bSJed Brown PetscErrorCode DMSNESGetJacobian(DM dm,PetscErrorCode (**func)(SNES,Vec,Mat*,Mat*,MatStructure*,void*),void **ctx)
5526cab3a1bSJed Brown {
5536cab3a1bSJed Brown   PetscErrorCode ierr;
554942e3340SBarry Smith   DMSNES         sdm;
5556cab3a1bSJed Brown 
5566cab3a1bSJed Brown   PetscFunctionBegin;
5576cab3a1bSJed Brown   PetscValidHeaderSpecific(dm,DM_CLASSID,1);
558942e3340SBarry Smith   ierr = DMGetDMSNES(dm,&sdm);CHKERRQ(ierr);
55922c6f798SBarry Smith   if (func) *func = sdm->ops->computejacobian;
5606cab3a1bSJed Brown   if (ctx)  *ctx = sdm->jacobianctx;
5616cab3a1bSJed Brown   PetscFunctionReturn(0);
5626cab3a1bSJed Brown }
5636cab3a1bSJed Brown 
5646cab3a1bSJed Brown #undef __FUNCT__
565e03ab78fSPeter Brune #define __FUNCT__ "DMSNESSetPicard"
566e03ab78fSPeter Brune /*@C
567e03ab78fSPeter Brune    DMSNESSetPicard - set SNES Picard iteration matrix and RHS evaluation functions.
568e03ab78fSPeter Brune 
569e03ab78fSPeter Brune    Not Collective
570e03ab78fSPeter Brune 
571e03ab78fSPeter Brune    Input Argument:
572e03ab78fSPeter Brune +  dm - DM to be used with SNES
573e03ab78fSPeter Brune .  func - RHS evaluation function, see SNESSetFunction() for calling sequence
574e03ab78fSPeter Brune .  pjac - Picard matrix evaluation function, see SNESSetJacobian() for calling sequence
575e03ab78fSPeter Brune -  ctx - context for residual evaluation
576e03ab78fSPeter Brune 
577e03ab78fSPeter Brune    Level: advanced
578e03ab78fSPeter Brune 
579e03ab78fSPeter Brune .seealso: SNESSetPicard(), DMSNESSetFunction(), DMSNESSetJacobian()
580e03ab78fSPeter Brune @*/
581e03ab78fSPeter Brune PetscErrorCode DMSNESSetPicard(DM dm,PetscErrorCode (*pfunc)(SNES,Vec,Vec,void*),PetscErrorCode (*pjac)(SNES,Vec,Mat*,Mat*,MatStructure*,void*),void *ctx)
582e03ab78fSPeter Brune {
583e03ab78fSPeter Brune   PetscErrorCode ierr;
584942e3340SBarry Smith   DMSNES         sdm;
585e03ab78fSPeter Brune 
586e03ab78fSPeter Brune   PetscFunctionBegin;
587e03ab78fSPeter Brune   PetscValidHeaderSpecific(dm,DM_CLASSID,1);
588942e3340SBarry Smith   ierr = DMGetDMSNES(dm,&sdm);CHKERRQ(ierr);
58922c6f798SBarry Smith   if (pfunc) sdm->ops->computepfunction = pfunc;
59022c6f798SBarry Smith   if (pjac)  sdm->ops->computepjacobian = pjac;
591e03ab78fSPeter Brune   if (ctx)   sdm->pctx             = ctx;
592e03ab78fSPeter Brune   PetscFunctionReturn(0);
593e03ab78fSPeter Brune }
594e03ab78fSPeter Brune 
5957971a8bfSPeter Brune 
5967971a8bfSPeter Brune #undef __FUNCT__
5977971a8bfSPeter Brune #define __FUNCT__ "DMSNESGetPicard"
5987971a8bfSPeter Brune /*@C
5997971a8bfSPeter Brune    DMSNESGetPicard - get SNES Picard iteration evaluation functions
6007971a8bfSPeter Brune 
6017971a8bfSPeter Brune    Not Collective
6027971a8bfSPeter Brune 
6037971a8bfSPeter Brune    Input Argument:
6047971a8bfSPeter Brune .  dm - DM to be used with SNES
6057971a8bfSPeter Brune 
6067971a8bfSPeter Brune    Output Arguments:
6077971a8bfSPeter Brune +  pfunc - Jacobian evaluation function, see SNESSetJacobian() for calling sequence
6087971a8bfSPeter Brune .  pjac  - RHS evaluation function, see SNESSetFunction() for calling sequence
6097971a8bfSPeter Brune -  ctx - context for residual evaluation
6107971a8bfSPeter Brune 
6117971a8bfSPeter Brune    Level: advanced
6127971a8bfSPeter Brune 
6137971a8bfSPeter Brune .seealso: DMSNESSetContext(), SNESSetFunction(), DMSNESSetJacobian()
6147971a8bfSPeter Brune @*/
6157971a8bfSPeter Brune PetscErrorCode DMSNESGetPicard(DM dm,PetscErrorCode (**pfunc)(SNES,Vec,Vec,void*),PetscErrorCode (**pjac)(SNES,Vec,Mat*,Mat*,MatStructure*,void*),void **ctx)
6167971a8bfSPeter Brune {
6177971a8bfSPeter Brune   PetscErrorCode ierr;
618942e3340SBarry Smith   DMSNES         sdm;
6197971a8bfSPeter Brune 
6207971a8bfSPeter Brune   PetscFunctionBegin;
6217971a8bfSPeter Brune   PetscValidHeaderSpecific(dm,DM_CLASSID,1);
622942e3340SBarry Smith   ierr = DMGetDMSNES(dm,&sdm);CHKERRQ(ierr);
62322c6f798SBarry Smith   if (pfunc) *pfunc = sdm->ops->computepfunction;
62422c6f798SBarry Smith   if (pjac) *pjac   = sdm->ops->computepjacobian;
6257971a8bfSPeter Brune   if (ctx)  *ctx    = sdm->pctx;
6267971a8bfSPeter Brune   PetscFunctionReturn(0);
6277971a8bfSPeter Brune }
6287971a8bfSPeter Brune 
6296427ad5bSPeter Brune /* block functions */
6306427ad5bSPeter Brune 
6316427ad5bSPeter Brune #undef __FUNCT__
6326427ad5bSPeter Brune #define __FUNCT__ "DMSNESSetBlockFunction"
6336427ad5bSPeter Brune /*@C
6346427ad5bSPeter Brune    DMSNESSetBlockFunction - set SNES residual evaluation function
6356427ad5bSPeter Brune 
6366427ad5bSPeter Brune    Not Collective
6376427ad5bSPeter Brune 
6386427ad5bSPeter Brune    Input Arguments:
6396427ad5bSPeter Brune +  dm - DM to be used with SNES
6406427ad5bSPeter Brune .  func - residual evaluation function, see SNESSetFunction() for calling sequence
6416427ad5bSPeter Brune -  ctx - context for residual evaluation
6426427ad5bSPeter Brune 
6436427ad5bSPeter Brune    Level: developer
6446427ad5bSPeter Brune 
6456427ad5bSPeter Brune    Note:
6466427ad5bSPeter Brune    Mostly for use in DM implementations and transferred to a block function rather than being called from here.
6476427ad5bSPeter Brune 
6486427ad5bSPeter Brune .seealso: DMSNESSetContext(), SNESSetFunction(), DMSNESSetJacobian()
6496427ad5bSPeter Brune @*/
6506427ad5bSPeter Brune PetscErrorCode DMSNESSetBlockFunction(DM dm,PetscErrorCode (*func)(SNES,Vec,Vec,void*),void *ctx)
6516427ad5bSPeter Brune {
6526427ad5bSPeter Brune   PetscErrorCode ierr;
653942e3340SBarry Smith   DMSNES         sdm;
6546427ad5bSPeter Brune 
6556427ad5bSPeter Brune   PetscFunctionBegin;
6566427ad5bSPeter Brune   PetscValidHeaderSpecific(dm,DM_CLASSID,1);
657fdaff8d6SPeter Brune   if (func || ctx) {
658942e3340SBarry Smith     ierr = DMGetDMSNESWrite(dm,&sdm);CHKERRQ(ierr);
659fdaff8d6SPeter Brune   }
66022c6f798SBarry Smith   if (func) sdm->ops->computeblockfunction = func;
6616427ad5bSPeter Brune   if (ctx)  sdm->blockfunctionctx = ctx;
6626427ad5bSPeter Brune   PetscFunctionReturn(0);
6636427ad5bSPeter Brune }
6646427ad5bSPeter Brune 
6656427ad5bSPeter Brune #undef __FUNCT__
6666427ad5bSPeter Brune #define __FUNCT__ "DMSNESGetBlockFunction"
6676427ad5bSPeter Brune /*@C
6686427ad5bSPeter Brune    DMSNESGetBlockFunction - get SNES residual evaluation function
6696427ad5bSPeter Brune 
6706427ad5bSPeter Brune    Not Collective
6716427ad5bSPeter Brune 
6726427ad5bSPeter Brune    Input Argument:
6736427ad5bSPeter Brune .  dm - DM to be used with SNES
6746427ad5bSPeter Brune 
6756427ad5bSPeter Brune    Output Arguments:
6766427ad5bSPeter Brune +  func - residual evaluation function, see SNESSetFunction() for calling sequence
6776427ad5bSPeter Brune -  ctx - context for residual evaluation
6786427ad5bSPeter Brune 
6796427ad5bSPeter Brune    Level: developer
6806427ad5bSPeter Brune 
6816427ad5bSPeter Brune .seealso: DMSNESSetContext(), DMSNESSetFunction(), SNESSetFunction()
6826427ad5bSPeter Brune @*/
6836427ad5bSPeter Brune PetscErrorCode DMSNESGetBlockFunction(DM dm,PetscErrorCode (**func)(SNES,Vec,Vec,void*),void **ctx)
6846427ad5bSPeter Brune {
6856427ad5bSPeter Brune   PetscErrorCode ierr;
686942e3340SBarry Smith   DMSNES         sdm;
6876427ad5bSPeter Brune 
6886427ad5bSPeter Brune   PetscFunctionBegin;
6896427ad5bSPeter Brune   PetscValidHeaderSpecific(dm,DM_CLASSID,1);
690942e3340SBarry Smith   ierr = DMGetDMSNES(dm,&sdm);CHKERRQ(ierr);
69122c6f798SBarry Smith   if (func) *func = sdm->ops->computeblockfunction;
6926427ad5bSPeter Brune   if (ctx)  *ctx = sdm->blockfunctionctx;
6936427ad5bSPeter Brune   PetscFunctionReturn(0);
6946427ad5bSPeter Brune }
6956427ad5bSPeter Brune 
6966427ad5bSPeter Brune 
6976427ad5bSPeter Brune #undef __FUNCT__
6986427ad5bSPeter Brune #define __FUNCT__ "DMSNESSetBlockJacobian"
6996427ad5bSPeter Brune /*@C
7006427ad5bSPeter Brune    DMSNESSetJacobian - set SNES Jacobian evaluation function
7016427ad5bSPeter Brune 
7026427ad5bSPeter Brune    Not Collective
7036427ad5bSPeter Brune 
7046427ad5bSPeter Brune    Input Argument:
7056427ad5bSPeter Brune +  dm - DM to be used with SNES
7066427ad5bSPeter Brune .  func - Jacobian evaluation function, see SNESSetJacobian() for calling sequence
7076427ad5bSPeter Brune -  ctx - context for residual evaluation
7086427ad5bSPeter Brune 
7096427ad5bSPeter Brune    Level: advanced
7106427ad5bSPeter Brune 
7116427ad5bSPeter Brune    Note:
7126427ad5bSPeter Brune    Mostly for use in DM implementations and transferred to a block function rather than being called from here.
7136427ad5bSPeter Brune 
7146427ad5bSPeter Brune .seealso: DMSNESSetContext(), SNESSetFunction(), DMSNESGetJacobian(), SNESSetJacobian()
7156427ad5bSPeter Brune @*/
7166427ad5bSPeter Brune PetscErrorCode DMSNESSetBlockJacobian(DM dm,PetscErrorCode (*func)(SNES,Vec,Mat*,Mat*,MatStructure*,void*),void *ctx)
7176427ad5bSPeter Brune {
7186427ad5bSPeter Brune   PetscErrorCode ierr;
719942e3340SBarry Smith   DMSNES         sdm;
7206427ad5bSPeter Brune 
7216427ad5bSPeter Brune   PetscFunctionBegin;
7226427ad5bSPeter Brune   PetscValidHeaderSpecific(dm,DM_CLASSID,1);
723fdaff8d6SPeter Brune   if (func || ctx) {
724942e3340SBarry Smith     ierr = DMGetDMSNESWrite(dm,&sdm);CHKERRQ(ierr);
725fdaff8d6SPeter Brune   }
72622c6f798SBarry Smith   if (func) sdm->ops->computeblockjacobian = func;
7276427ad5bSPeter Brune   if (ctx)  sdm->blockjacobianctx = ctx;
7286427ad5bSPeter Brune   PetscFunctionReturn(0);
7296427ad5bSPeter Brune }
7306427ad5bSPeter Brune 
7316427ad5bSPeter Brune #undef __FUNCT__
7326427ad5bSPeter Brune #define __FUNCT__ "DMSNESGetBlockJacobian"
7336427ad5bSPeter Brune /*@C
7346427ad5bSPeter Brune    DMSNESGetBlockJacobian - get SNES Jacobian evaluation function
7356427ad5bSPeter Brune 
7366427ad5bSPeter Brune    Not Collective
7376427ad5bSPeter Brune 
7386427ad5bSPeter Brune    Input Argument:
7396427ad5bSPeter Brune .  dm - DM to be used with SNES
7406427ad5bSPeter Brune 
7416427ad5bSPeter Brune    Output Arguments:
7426427ad5bSPeter Brune +  func - Jacobian evaluation function, see SNESSetJacobian() for calling sequence
7436427ad5bSPeter Brune -  ctx - context for residual evaluation
7446427ad5bSPeter Brune 
7456427ad5bSPeter Brune    Level: advanced
7466427ad5bSPeter Brune 
7476427ad5bSPeter Brune .seealso: DMSNESSetContext(), SNESSetFunction(), DMSNESSetJacobian()
7486427ad5bSPeter Brune @*/
7496427ad5bSPeter Brune PetscErrorCode DMSNESGetBlockJacobian(DM dm,PetscErrorCode (**func)(SNES,Vec,Mat*,Mat*,MatStructure*,void*),void **ctx)
7506427ad5bSPeter Brune {
7516427ad5bSPeter Brune   PetscErrorCode ierr;
752942e3340SBarry Smith   DMSNES         sdm;
7536427ad5bSPeter Brune 
7546427ad5bSPeter Brune   PetscFunctionBegin;
7556427ad5bSPeter Brune   PetscValidHeaderSpecific(dm,DM_CLASSID,1);
756942e3340SBarry Smith   ierr = DMGetDMSNES(dm,&sdm);CHKERRQ(ierr);
75722c6f798SBarry Smith   if (func) *func = sdm->ops->computeblockjacobian;
7586427ad5bSPeter Brune   if (ctx)  *ctx = sdm->blockjacobianctx;
7596427ad5bSPeter Brune   PetscFunctionReturn(0);
7606427ad5bSPeter Brune }
761