xref: /petsc/src/snes/utils/dmsnes.c (revision 2d53ad75667bd9af5ca32c6f75ade56f24a4fbe1)
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__
20*2d53ad75SBarry Smith #define __FUNCT__ "DMSNESLoad"
21*2d53ad75SBarry Smith PetscErrorCode DMSNESLoad(DMSNES kdm,PetscViewer viewer)
22*2d53ad75SBarry Smith {
23*2d53ad75SBarry Smith   PetscErrorCode ierr;
24*2d53ad75SBarry Smith 
25*2d53ad75SBarry Smith   PetscFunctionBegin;
26*2d53ad75SBarry Smith   ierr = PetscViewerBinaryRead(viewer,&kdm->ops->computefunction,1,PETSC_FUNCTION);CHKERRQ(ierr);
27*2d53ad75SBarry Smith   ierr = PetscViewerBinaryRead(viewer,&kdm->ops->computejacobian,1,PETSC_FUNCTION);CHKERRQ(ierr);
28*2d53ad75SBarry Smith   PetscFunctionReturn(0);
29*2d53ad75SBarry Smith }
30*2d53ad75SBarry Smith 
31*2d53ad75SBarry Smith #undef __FUNCT__
32*2d53ad75SBarry Smith #define __FUNCT__ "DMSNESView"
33*2d53ad75SBarry Smith PetscErrorCode DMSNESView(DMSNES kdm,PetscViewer viewer)
34*2d53ad75SBarry Smith {
35*2d53ad75SBarry Smith   PetscErrorCode ierr;
36*2d53ad75SBarry Smith   PetscBool      isascii,isbinary;
37*2d53ad75SBarry Smith 
38*2d53ad75SBarry Smith   PetscFunctionBegin;
39*2d53ad75SBarry Smith   ierr = PetscObjectTypeCompare((PetscObject)viewer,PETSCVIEWERASCII,&isascii);CHKERRQ(ierr);
40*2d53ad75SBarry Smith   ierr = PetscObjectTypeCompare((PetscObject)viewer,PETSCVIEWERBINARY,&isbinary);CHKERRQ(ierr);
41*2d53ad75SBarry Smith   if (isascii) {
42*2d53ad75SBarry Smith     const char *fname;
43*2d53ad75SBarry Smith 
44*2d53ad75SBarry Smith     ierr = PetscFPTFind(kdm->ops->computefunction,&fname);CHKERRQ(ierr);
45*2d53ad75SBarry Smith     if (fname) {
46*2d53ad75SBarry Smith       ierr = PetscViewerASCIIPrintf(viewer,"Function used by SNES: %s\n",fname);CHKERRQ(ierr);
47*2d53ad75SBarry Smith     }
48*2d53ad75SBarry Smith     ierr = PetscFPTFind(kdm->ops->computejacobian,&fname);CHKERRQ(ierr);
49*2d53ad75SBarry Smith     if (fname) {
50*2d53ad75SBarry Smith       ierr = PetscViewerASCIIPrintf(viewer,"Jacobian function used by SNES: %s\n",fname);CHKERRQ(ierr);
51*2d53ad75SBarry Smith     }
52*2d53ad75SBarry Smith   } else if (isbinary) {
53*2d53ad75SBarry Smith     ierr = PetscViewerBinaryWrite(viewer,kdm->ops->computefunction,1,PETSC_FUNCTION,PETSC_FALSE);CHKERRQ(ierr);
54*2d53ad75SBarry Smith     ierr = PetscViewerBinaryWrite(viewer,kdm->ops->computejacobian,1,PETSC_FUNCTION,PETSC_FALSE);CHKERRQ(ierr);
55*2d53ad75SBarry Smith   }
56*2d53ad75SBarry Smith   PetscFunctionReturn(0);
57*2d53ad75SBarry Smith }
58*2d53ad75SBarry Smith 
59*2d53ad75SBarry Smith #undef __FUNCT__
6022c6f798SBarry Smith #define __FUNCT__ "DMSNESCreate"
6122c6f798SBarry Smith static PetscErrorCode DMSNESCreate(MPI_Comm comm,DMSNES *kdm)
6222c6f798SBarry Smith {
6322c6f798SBarry Smith   PetscErrorCode ierr;
6422c6f798SBarry Smith 
6522c6f798SBarry Smith   PetscFunctionBegin;
6622c6f798SBarry Smith #ifndef PETSC_USE_DYNAMIC_LIBRARIES
6722c6f798SBarry Smith   ierr = SNESInitializePackage(PETSC_NULL);CHKERRQ(ierr);
6822c6f798SBarry Smith #endif
69*2d53ad75SBarry Smith   ierr = PetscHeaderCreate(*kdm, _p_DMSNES, struct _DMSNESOps, DMSNES_CLASSID, -1, "DMSNES", "DMSNES", "DMSNES", comm, DMSNESDestroy, DMSNESView);CHKERRQ(ierr);
7022c6f798SBarry Smith   ierr = PetscMemzero((*kdm)->ops, sizeof(struct _DMSNESOps));CHKERRQ(ierr);
716cab3a1bSJed Brown   PetscFunctionReturn(0);
726cab3a1bSJed Brown }
736cab3a1bSJed Brown 
746cab3a1bSJed Brown #undef __FUNCT__
75942e3340SBarry Smith #define __FUNCT__ "DMCoarsenHook_DMSNES"
76942e3340SBarry Smith /* Attaches the DMSNES to the coarse level.
776cab3a1bSJed Brown  * Under what conditions should we copy versus duplicate?
786cab3a1bSJed Brown  */
79942e3340SBarry Smith static PetscErrorCode DMCoarsenHook_DMSNES(DM dm,DM dmc,void *ctx)
806cab3a1bSJed Brown {
816cab3a1bSJed Brown   PetscErrorCode ierr;
826cab3a1bSJed Brown 
836cab3a1bSJed Brown   PetscFunctionBegin;
84942e3340SBarry Smith   ierr = DMCopyDMSNES(dm,dmc);CHKERRQ(ierr);
856cab3a1bSJed Brown   PetscFunctionReturn(0);
866cab3a1bSJed Brown }
876cab3a1bSJed Brown 
886cab3a1bSJed Brown #undef __FUNCT__
89942e3340SBarry Smith #define __FUNCT__ "DMRestrictHook_DMSNES"
90dfe15315SJed Brown /* This could restrict auxiliary information to the coarse level.
91caa4e7f2SJed Brown  */
92942e3340SBarry Smith static PetscErrorCode DMRestrictHook_DMSNES(DM dm,Mat Restrict,Vec rscale,Mat Inject,DM dmc,void *ctx)
93caa4e7f2SJed Brown {
94caa4e7f2SJed Brown 
95caa4e7f2SJed Brown   PetscFunctionBegin;
96caa4e7f2SJed Brown   PetscFunctionReturn(0);
97caa4e7f2SJed Brown }
98caa4e7f2SJed Brown 
99caa4e7f2SJed Brown #undef __FUNCT__
100942e3340SBarry Smith #define __FUNCT__ "DMRefineHook_DMSNES"
101942e3340SBarry Smith static PetscErrorCode DMRefineHook_DMSNES(DM dm,DM dmf,void *ctx)
10203a0fabfSPeter Brune {
10303a0fabfSPeter Brune   PetscErrorCode ierr;
10403a0fabfSPeter Brune 
10503a0fabfSPeter Brune   PetscFunctionBegin;
106942e3340SBarry Smith   ierr = DMCopyDMSNES(dm,dmf);CHKERRQ(ierr);
10703a0fabfSPeter Brune   PetscFunctionReturn(0);
10803a0fabfSPeter Brune }
10903a0fabfSPeter Brune 
11003a0fabfSPeter Brune #undef __FUNCT__
111942e3340SBarry Smith #define __FUNCT__ "DMInterpolateHook_DMSNES"
11203a0fabfSPeter Brune /* This could restrict auxiliary information to the coarse level.
11303a0fabfSPeter Brune  */
114942e3340SBarry Smith static PetscErrorCode DMInterpolateHook_DMSNES(DM dm,Mat Interp,DM dmf,void *ctx)
11503a0fabfSPeter Brune {
11603a0fabfSPeter Brune 
11703a0fabfSPeter Brune   PetscFunctionBegin;
11803a0fabfSPeter Brune   PetscFunctionReturn(0);
11903a0fabfSPeter Brune }
12003a0fabfSPeter Brune 
12103a0fabfSPeter Brune #undef __FUNCT__
12222c6f798SBarry Smith #define __FUNCT__ "DMSNESCopy"
12322c6f798SBarry Smith /*@C
12422c6f798SBarry Smith    DMSNESCopy - copies the information in a DMSNES to another DMSNES
12522c6f798SBarry Smith 
12622c6f798SBarry Smith    Not Collective
12722c6f798SBarry Smith 
12822c6f798SBarry Smith    Input Argument:
12922c6f798SBarry Smith +  kdm - Original DMSNES
13022c6f798SBarry Smith -  nkdm - DMSNES to receive the data, should have been created with DMSNESCreate()
13122c6f798SBarry Smith 
13222c6f798SBarry Smith    Level: developer
13322c6f798SBarry Smith 
13422c6f798SBarry Smith .seealso: DMSNESCreate(), DMSNESDestroy()
13522c6f798SBarry Smith @*/
13622c6f798SBarry Smith PetscErrorCode DMSNESCopy(DMSNES kdm,DMSNES nkdm)
13722c6f798SBarry Smith {
13822c6f798SBarry Smith   PetscErrorCode ierr;
13922c6f798SBarry Smith 
14022c6f798SBarry Smith   PetscFunctionBegin;
14122c6f798SBarry Smith   PetscValidHeaderSpecific(kdm,DMSNES_CLASSID,1);
14222c6f798SBarry Smith   PetscValidHeaderSpecific(nkdm,DMSNES_CLASSID,2);
14322c6f798SBarry Smith   nkdm->ops->computefunction       = kdm->ops->computefunction;
14422c6f798SBarry Smith   nkdm->ops->computegs             = kdm->ops->computegs;
14522c6f798SBarry Smith   nkdm->ops->computeobjective      = kdm->ops->computeobjective;
14622c6f798SBarry Smith   nkdm->ops->computepjacobian      = kdm->ops->computepjacobian;
14722c6f798SBarry Smith   nkdm->ops->computepfunction      = kdm->ops->computepfunction;
14822c6f798SBarry Smith   nkdm->ops->computeblockfunction  = kdm->ops->computeblockfunction;
14922c6f798SBarry Smith   nkdm->ops->computeblockjacobian  = kdm->ops->computeblockjacobian;
15022c6f798SBarry Smith   nkdm->ops->destroy               = kdm->ops->destroy;
15122c6f798SBarry Smith   nkdm->ops->duplicate             = kdm->ops->duplicate;
15222c6f798SBarry Smith 
15322c6f798SBarry Smith   nkdm->functionctx      = kdm->functionctx;
15422c6f798SBarry Smith   nkdm->gsctx            = kdm->gsctx;
15522c6f798SBarry Smith   nkdm->pctx             = kdm->pctx;
15622c6f798SBarry Smith   nkdm->jacobianctx      = kdm->jacobianctx;
15722c6f798SBarry Smith   nkdm->objectivectx     = kdm->objectivectx;
15822c6f798SBarry Smith   nkdm->blockfunctionctx = kdm->blockfunctionctx;
15922c6f798SBarry Smith   nkdm->blockjacobianctx = kdm->blockjacobianctx;
16022c6f798SBarry Smith   nkdm->data             = kdm->data;
16122c6f798SBarry Smith 
16222c6f798SBarry Smith   /*
16322c6f798SBarry Smith   nkdm->fortran_func_pointers[0] = kdm->fortran_func_pointers[0];
16422c6f798SBarry Smith   nkdm->fortran_func_pointers[1] = kdm->fortran_func_pointers[1];
16522c6f798SBarry Smith   nkdm->fortran_func_pointers[2] = kdm->fortran_func_pointers[2];
16622c6f798SBarry Smith   */
16722c6f798SBarry Smith 
16822c6f798SBarry Smith   /* implementation specific copy hooks */
16922c6f798SBarry Smith   if (kdm->ops->duplicate) {ierr = (*kdm->ops->duplicate)(kdm,nkdm);CHKERRQ(ierr);}
17022c6f798SBarry Smith   PetscFunctionReturn(0);
17122c6f798SBarry Smith }
17222c6f798SBarry Smith 
17322c6f798SBarry Smith #undef __FUNCT__
174942e3340SBarry Smith #define __FUNCT__ "DMGetDMSNES"
1756cab3a1bSJed Brown /*@C
176942e3340SBarry Smith    DMGetDMSNES - get read-only private DMSNES context from a DM
1776cab3a1bSJed Brown 
1786cab3a1bSJed Brown    Not Collective
1796cab3a1bSJed Brown 
1806cab3a1bSJed Brown    Input Argument:
1816cab3a1bSJed Brown .  dm - DM to be used with SNES
1826cab3a1bSJed Brown 
1836cab3a1bSJed Brown    Output Argument:
184942e3340SBarry Smith .  snesdm - private DMSNES context
1856cab3a1bSJed Brown 
1866cab3a1bSJed Brown    Level: developer
1876cab3a1bSJed Brown 
1886cab3a1bSJed Brown    Notes:
189942e3340SBarry Smith    Use DMGetDMSNESWrite() if write access is needed. The DMSNESSetXXX API should be used wherever possible.
1906cab3a1bSJed Brown 
191942e3340SBarry Smith .seealso: DMGetDMSNESWrite()
1926cab3a1bSJed Brown @*/
193942e3340SBarry Smith PetscErrorCode DMGetDMSNES(DM dm,DMSNES *snesdm)
1946cab3a1bSJed Brown {
1956cab3a1bSJed Brown   PetscErrorCode ierr;
1966cab3a1bSJed Brown 
1976cab3a1bSJed Brown   PetscFunctionBegin;
1986cab3a1bSJed Brown   PetscValidHeaderSpecific(dm,DM_CLASSID,1);
199b4615a05SBarry Smith   *snesdm = (DMSNES) dm->dmsnes;
20022c6f798SBarry Smith   if (!*snesdm) {
201942e3340SBarry Smith     ierr = PetscInfo(dm,"Creating new DMSNES\n");CHKERRQ(ierr);
20222c6f798SBarry Smith     ierr = DMSNESCreate(((PetscObject)dm)->comm,snesdm);CHKERRQ(ierr);
203b4615a05SBarry Smith     dm->dmsnes = (PetscObject) *snesdm;
204942e3340SBarry Smith     ierr = DMCoarsenHookAdd(dm,DMCoarsenHook_DMSNES,DMRestrictHook_DMSNES,PETSC_NULL);CHKERRQ(ierr);
20522c6f798SBarry Smith     ierr = DMRefineHookAdd(dm,DMRefineHook_DMSNES,DMInterpolateHook_DMSNES,PETSC_NULL);CHKERRQ(ierr);
2066cab3a1bSJed Brown   }
2076cab3a1bSJed Brown   PetscFunctionReturn(0);
2086cab3a1bSJed Brown }
2096cab3a1bSJed Brown 
2106cab3a1bSJed Brown #undef __FUNCT__
211942e3340SBarry Smith #define __FUNCT__ "DMGetDMSNESWrite"
2126cab3a1bSJed Brown /*@C
213942e3340SBarry Smith    DMGetDMSNESWrite - get write access to private DMSNES context from a DM
2146cab3a1bSJed Brown 
2156cab3a1bSJed Brown    Not Collective
2166cab3a1bSJed Brown 
2176cab3a1bSJed Brown    Input Argument:
2186cab3a1bSJed Brown .  dm - DM to be used with SNES
2196cab3a1bSJed Brown 
2206cab3a1bSJed Brown    Output Argument:
221942e3340SBarry Smith .  snesdm - private DMSNES context
2226cab3a1bSJed Brown 
2236cab3a1bSJed Brown    Level: developer
2246cab3a1bSJed Brown 
225942e3340SBarry Smith .seealso: DMGetDMSNES()
2266cab3a1bSJed Brown @*/
227942e3340SBarry Smith PetscErrorCode DMGetDMSNESWrite(DM dm,DMSNES *snesdm)
2286cab3a1bSJed Brown {
2296cab3a1bSJed Brown   PetscErrorCode ierr;
230942e3340SBarry Smith   DMSNES         sdm;
2316cab3a1bSJed Brown 
2326cab3a1bSJed Brown   PetscFunctionBegin;
2336cab3a1bSJed Brown   PetscValidHeaderSpecific(dm,DM_CLASSID,1);
234942e3340SBarry Smith   ierr = DMGetDMSNES(dm,&sdm);CHKERRQ(ierr);
2356cab3a1bSJed Brown   if (!sdm->originaldm) sdm->originaldm = dm;
2366cab3a1bSJed Brown   if (sdm->originaldm != dm) {  /* Copy on write */
237b4615a05SBarry Smith     DMSNES          oldsdm = sdm;
238942e3340SBarry Smith     ierr = PetscInfo(dm,"Copying DMSNES due to write\n");CHKERRQ(ierr);
23922c6f798SBarry Smith     ierr = DMSNESCreate(((PetscObject)dm)->comm,&sdm);CHKERRQ(ierr);
24022c6f798SBarry Smith     ierr = DMSNESCopy(oldsdm,sdm);CHKERRQ(ierr);
241b4615a05SBarry Smith     ierr = DMSNESDestroy((DMSNES*)&dm->dmsnes);CHKERRQ(ierr);
242b4615a05SBarry Smith     dm->dmsnes = (PetscObject)sdm;
2436cab3a1bSJed Brown   }
2446cab3a1bSJed Brown   *snesdm = sdm;
2456cab3a1bSJed Brown   PetscFunctionReturn(0);
2466cab3a1bSJed Brown }
2476cab3a1bSJed Brown 
2486cab3a1bSJed Brown #undef __FUNCT__
249942e3340SBarry Smith #define __FUNCT__ "DMCopyDMSNES"
2506cab3a1bSJed Brown /*@C
251942e3340SBarry Smith    DMCopyDMSNES - copies a DM context to a new DM
2526cab3a1bSJed Brown 
2536cab3a1bSJed Brown    Logically Collective
2546cab3a1bSJed Brown 
2556cab3a1bSJed Brown    Input Arguments:
2566cab3a1bSJed Brown +  dmsrc - DM to obtain context from
2576cab3a1bSJed Brown -  dmdest - DM to add context to
2586cab3a1bSJed Brown 
2596cab3a1bSJed Brown    Level: developer
2606cab3a1bSJed Brown 
2616cab3a1bSJed Brown    Note:
2626cab3a1bSJed Brown    The context is copied by reference. This function does not ensure that a context exists.
2636cab3a1bSJed Brown 
264942e3340SBarry Smith .seealso: DMGetDMSNES(), SNESSetDM()
2656cab3a1bSJed Brown @*/
266942e3340SBarry Smith PetscErrorCode DMCopyDMSNES(DM dmsrc,DM dmdest)
2676cab3a1bSJed Brown {
2686cab3a1bSJed Brown   PetscErrorCode ierr;
2696cab3a1bSJed Brown 
2706cab3a1bSJed Brown   PetscFunctionBegin;
2716cab3a1bSJed Brown   PetscValidHeaderSpecific(dmsrc,DM_CLASSID,1);
2726cab3a1bSJed Brown   PetscValidHeaderSpecific(dmdest,DM_CLASSID,2);
273b4615a05SBarry Smith   ierr = DMSNESDestroy((DMSNES*)&dmdest->dmsnes);CHKERRQ(ierr);
274b4615a05SBarry Smith   dmdest->dmsnes = dmsrc->dmsnes;
275b4615a05SBarry Smith   ierr = PetscObjectReference(dmdest->dmsnes);CHKERRQ(ierr);
27622c6f798SBarry Smith   ierr = DMCoarsenHookAdd(dmdest,DMCoarsenHook_DMSNES,PETSC_NULL,PETSC_NULL);CHKERRQ(ierr);
27722c6f798SBarry Smith   ierr = DMRefineHookAdd(dmdest,DMRefineHook_DMSNES,PETSC_NULL,PETSC_NULL);CHKERRQ(ierr);
2786cab3a1bSJed Brown   PetscFunctionReturn(0);
2796cab3a1bSJed Brown }
2806cab3a1bSJed Brown 
2816cab3a1bSJed Brown #undef __FUNCT__
2826cab3a1bSJed Brown #define __FUNCT__ "DMSNESSetFunction"
2836cab3a1bSJed Brown /*@C
2846cab3a1bSJed Brown    DMSNESSetFunction - set SNES residual evaluation function
2856cab3a1bSJed Brown 
2866cab3a1bSJed Brown    Not Collective
2876cab3a1bSJed Brown 
2886cab3a1bSJed Brown    Input Arguments:
2896cab3a1bSJed Brown +  dm - DM to be used with SNES
2906cab3a1bSJed Brown .  func - residual evaluation function, see SNESSetFunction() for calling sequence
2916cab3a1bSJed Brown -  ctx - context for residual evaluation
2926cab3a1bSJed Brown 
2936cab3a1bSJed Brown    Level: advanced
2946cab3a1bSJed Brown 
2956cab3a1bSJed Brown    Note:
2966cab3a1bSJed Brown    SNESSetFunction() is normally used, but it calls this function internally because the user context is actually
2976cab3a1bSJed Brown    associated with the DM.  This makes the interface consistent regardless of whether the user interacts with a DM or
2986cab3a1bSJed Brown    not. If DM took a more central role at some later date, this could become the primary method of setting the residual.
2996cab3a1bSJed Brown 
3006cab3a1bSJed Brown .seealso: DMSNESSetContext(), SNESSetFunction(), DMSNESSetJacobian()
3016cab3a1bSJed Brown @*/
3026cab3a1bSJed Brown PetscErrorCode DMSNESSetFunction(DM dm,PetscErrorCode (*func)(SNES,Vec,Vec,void*),void *ctx)
3036cab3a1bSJed Brown {
3046cab3a1bSJed Brown   PetscErrorCode ierr;
305942e3340SBarry Smith   DMSNES         sdm;
3066cab3a1bSJed Brown 
3076cab3a1bSJed Brown   PetscFunctionBegin;
3086cab3a1bSJed Brown   PetscValidHeaderSpecific(dm,DM_CLASSID,1);
309fdaff8d6SPeter Brune   if (func || ctx) {
310942e3340SBarry Smith     ierr = DMGetDMSNESWrite(dm,&sdm);CHKERRQ(ierr);
311fdaff8d6SPeter Brune   }
31222c6f798SBarry Smith   if (func) sdm->ops->computefunction = func;
3136cab3a1bSJed Brown   if (ctx)  sdm->functionctx = ctx;
3146cab3a1bSJed Brown   PetscFunctionReturn(0);
3156cab3a1bSJed Brown }
3166cab3a1bSJed Brown 
3176cab3a1bSJed Brown #undef __FUNCT__
3186cab3a1bSJed Brown #define __FUNCT__ "DMSNESGetFunction"
3196cab3a1bSJed Brown /*@C
3206cab3a1bSJed Brown    DMSNESGetFunction - get SNES residual evaluation function
3216cab3a1bSJed Brown 
3226cab3a1bSJed Brown    Not Collective
3236cab3a1bSJed Brown 
3246cab3a1bSJed Brown    Input Argument:
3256cab3a1bSJed Brown .  dm - DM to be used with SNES
3266cab3a1bSJed Brown 
3276cab3a1bSJed Brown    Output Arguments:
3286cab3a1bSJed Brown +  func - residual evaluation function, see SNESSetFunction() for calling sequence
3296cab3a1bSJed Brown -  ctx - context for residual evaluation
3306cab3a1bSJed Brown 
3316cab3a1bSJed Brown    Level: advanced
3326cab3a1bSJed Brown 
3336cab3a1bSJed Brown    Note:
3346cab3a1bSJed Brown    SNESGetFunction() is normally used, but it calls this function internally because the user context is actually
3356cab3a1bSJed Brown    associated with the DM.
3366cab3a1bSJed Brown 
3376cab3a1bSJed Brown .seealso: DMSNESSetContext(), DMSNESSetFunction(), SNESSetFunction()
3386cab3a1bSJed Brown @*/
3396cab3a1bSJed Brown PetscErrorCode DMSNESGetFunction(DM dm,PetscErrorCode (**func)(SNES,Vec,Vec,void*),void **ctx)
3406cab3a1bSJed Brown {
3416cab3a1bSJed Brown   PetscErrorCode ierr;
342942e3340SBarry Smith   DMSNES         sdm;
3436cab3a1bSJed Brown 
3446cab3a1bSJed Brown   PetscFunctionBegin;
3456cab3a1bSJed Brown   PetscValidHeaderSpecific(dm,DM_CLASSID,1);
346942e3340SBarry Smith   ierr = DMGetDMSNES(dm,&sdm);CHKERRQ(ierr);
34722c6f798SBarry Smith   if (func) *func = sdm->ops->computefunction;
3486cab3a1bSJed Brown   if (ctx)  *ctx = sdm->functionctx;
3496cab3a1bSJed Brown   PetscFunctionReturn(0);
3506cab3a1bSJed Brown }
3516cab3a1bSJed Brown 
3526cab3a1bSJed Brown #undef __FUNCT__
3532a4ee8f2SPeter Brune #define __FUNCT__ "DMSNESSetObjective"
3542a4ee8f2SPeter Brune /*@C
355081a7dcdSPeter Brune    DMSNESSetObjective - set SNES objective evaluation function
3562a4ee8f2SPeter Brune 
3572a4ee8f2SPeter Brune    Not Collective
3582a4ee8f2SPeter Brune 
3592a4ee8f2SPeter Brune    Input Arguments:
3602a4ee8f2SPeter Brune +  dm - DM to be used with SNES
3612a4ee8f2SPeter Brune .  func - residual evaluation function, see SNESSetObjective() for calling sequence
3622a4ee8f2SPeter Brune -  ctx - context for residual evaluation
3632a4ee8f2SPeter Brune 
3642a4ee8f2SPeter Brune    Level: advanced
3652a4ee8f2SPeter Brune 
3662a4ee8f2SPeter Brune .seealso: DMSNESSetContext(), SNESGetObjective(), DMSNESSetFunction()
3672a4ee8f2SPeter Brune @*/
3682a4ee8f2SPeter Brune PetscErrorCode DMSNESSetObjective(DM dm,SNESObjective func,void *ctx)
3692a4ee8f2SPeter Brune {
3702a4ee8f2SPeter Brune   PetscErrorCode ierr;
371942e3340SBarry Smith   DMSNES         sdm;
3722a4ee8f2SPeter Brune 
3732a4ee8f2SPeter Brune   PetscFunctionBegin;
3742a4ee8f2SPeter Brune   PetscValidHeaderSpecific(dm,DM_CLASSID,1);
375fdaff8d6SPeter Brune   if (func || ctx) {
376942e3340SBarry Smith     ierr = DMGetDMSNESWrite(dm,&sdm);CHKERRQ(ierr);
377fdaff8d6SPeter Brune   }
37822c6f798SBarry Smith   if (func) sdm->ops->computeobjective = func;
3792a4ee8f2SPeter Brune   if (ctx)  sdm->objectivectx = ctx;
3802a4ee8f2SPeter Brune   PetscFunctionReturn(0);
3812a4ee8f2SPeter Brune }
3822a4ee8f2SPeter Brune 
3832a4ee8f2SPeter Brune #undef __FUNCT__
3842a4ee8f2SPeter Brune #define __FUNCT__ "DMSNESGetObjective"
3852a4ee8f2SPeter Brune /*@C
3862a4ee8f2SPeter Brune    DMSNESGetObjective - get SNES objective evaluation function
3872a4ee8f2SPeter Brune 
3882a4ee8f2SPeter Brune    Not Collective
3892a4ee8f2SPeter Brune 
3902a4ee8f2SPeter Brune    Input Argument:
3912a4ee8f2SPeter Brune .  dm - DM to be used with SNES
3922a4ee8f2SPeter Brune 
3932a4ee8f2SPeter Brune    Output Arguments:
3942a4ee8f2SPeter Brune +  func - residual evaluation function, see SNESSetObjective() for calling sequence
3952a4ee8f2SPeter Brune -  ctx - context for residual evaluation
3962a4ee8f2SPeter Brune 
3972a4ee8f2SPeter Brune    Level: advanced
3982a4ee8f2SPeter Brune 
3992a4ee8f2SPeter Brune    Note:
4002a4ee8f2SPeter Brune    SNESGetFunction() is normally used, but it calls this function internally because the user context is actually
4012a4ee8f2SPeter Brune    associated with the DM.
4022a4ee8f2SPeter Brune 
4032a4ee8f2SPeter Brune .seealso: DMSNESSetContext(), DMSNESSetObjective(), SNESSetFunction()
4042a4ee8f2SPeter Brune @*/
4052a4ee8f2SPeter Brune PetscErrorCode DMSNESGetObjective(DM dm,SNESObjective *func,void **ctx)
4062a4ee8f2SPeter Brune {
4072a4ee8f2SPeter Brune   PetscErrorCode ierr;
408942e3340SBarry Smith   DMSNES         sdm;
4092a4ee8f2SPeter Brune 
4102a4ee8f2SPeter Brune   PetscFunctionBegin;
4112a4ee8f2SPeter Brune   PetscValidHeaderSpecific(dm,DM_CLASSID,1);
412942e3340SBarry Smith   ierr = DMGetDMSNES(dm,&sdm);CHKERRQ(ierr);
41322c6f798SBarry Smith   if (func) *func = sdm->ops->computeobjective;
4142a4ee8f2SPeter Brune   if (ctx)  *ctx = sdm->objectivectx;
4152a4ee8f2SPeter Brune   PetscFunctionReturn(0);
4162a4ee8f2SPeter Brune }
4172a4ee8f2SPeter Brune 
4182a4ee8f2SPeter Brune #undef __FUNCT__
4196cab3a1bSJed Brown #define __FUNCT__ "DMSNESSetGS"
4206cab3a1bSJed Brown /*@C
4216cab3a1bSJed Brown    DMSNESSetGS - set SNES Gauss-Seidel relaxation function
4226cab3a1bSJed Brown 
4236cab3a1bSJed Brown    Not Collective
4246cab3a1bSJed Brown 
4256cab3a1bSJed Brown    Input Argument:
4266cab3a1bSJed Brown +  dm - DM to be used with SNES
4276cab3a1bSJed Brown .  func - relaxation function, see SNESSetGS() for calling sequence
4286cab3a1bSJed Brown -  ctx - context for residual evaluation
4296cab3a1bSJed Brown 
4306cab3a1bSJed Brown    Level: advanced
4316cab3a1bSJed Brown 
4326cab3a1bSJed Brown    Note:
4336cab3a1bSJed Brown    SNESSetGS() is normally used, but it calls this function internally because the user context is actually
4346cab3a1bSJed Brown    associated with the DM.  This makes the interface consistent regardless of whether the user interacts with a DM or
4356cab3a1bSJed Brown    not. If DM took a more central role at some later date, this could become the primary method of setting the residual.
4366cab3a1bSJed Brown 
4376cab3a1bSJed Brown .seealso: DMSNESSetContext(), SNESSetFunction(), DMSNESSetJacobian(), DMSNESSetFunction()
4386cab3a1bSJed Brown @*/
4396cab3a1bSJed Brown PetscErrorCode DMSNESSetGS(DM dm,PetscErrorCode (*func)(SNES,Vec,Vec,void*),void *ctx)
4406cab3a1bSJed Brown {
4416cab3a1bSJed Brown   PetscErrorCode ierr;
442942e3340SBarry Smith   DMSNES         sdm;
4436cab3a1bSJed Brown 
4446cab3a1bSJed Brown   PetscFunctionBegin;
4456cab3a1bSJed Brown   PetscValidHeaderSpecific(dm,DM_CLASSID,1);
446fdaff8d6SPeter Brune   if (func || ctx) {
447942e3340SBarry Smith     ierr = DMGetDMSNESWrite(dm,&sdm);CHKERRQ(ierr);
448fdaff8d6SPeter Brune   }
44922c6f798SBarry Smith   if (func) sdm->ops->computegs = func;
4506cab3a1bSJed Brown   if (ctx)  sdm->gsctx = ctx;
4516cab3a1bSJed Brown   PetscFunctionReturn(0);
4526cab3a1bSJed Brown }
4536cab3a1bSJed Brown 
4546cab3a1bSJed Brown #undef __FUNCT__
4556cab3a1bSJed Brown #define __FUNCT__ "DMSNESGetGS"
4566cab3a1bSJed Brown /*@C
4576cab3a1bSJed Brown    DMSNESGetGS - get SNES Gauss-Seidel relaxation function
4586cab3a1bSJed Brown 
4596cab3a1bSJed Brown    Not Collective
4606cab3a1bSJed Brown 
4616cab3a1bSJed Brown    Input Argument:
4626cab3a1bSJed Brown .  dm - DM to be used with SNES
4636cab3a1bSJed Brown 
4646cab3a1bSJed Brown    Output Arguments:
4656cab3a1bSJed Brown +  func - relaxation function, see SNESSetGS() for calling sequence
4666cab3a1bSJed Brown -  ctx - context for residual evaluation
4676cab3a1bSJed Brown 
4686cab3a1bSJed Brown    Level: advanced
4696cab3a1bSJed Brown 
4706cab3a1bSJed Brown    Note:
4716cab3a1bSJed Brown    SNESGetGS() is normally used, but it calls this function internally because the user context is actually
4726cab3a1bSJed Brown    associated with the DM.  This makes the interface consistent regardless of whether the user interacts with a DM or
4736cab3a1bSJed Brown    not. If DM took a more central role at some later date, this could become the primary method of setting the residual.
4746cab3a1bSJed Brown 
4756cab3a1bSJed Brown .seealso: DMSNESSetContext(), SNESGetGS(), DMSNESGetJacobian(), DMSNESGetFunction()
4766cab3a1bSJed Brown @*/
4776cab3a1bSJed Brown PetscErrorCode DMSNESGetGS(DM dm,PetscErrorCode (**func)(SNES,Vec,Vec,void*),void **ctx)
4786cab3a1bSJed Brown {
4796cab3a1bSJed Brown   PetscErrorCode ierr;
480942e3340SBarry Smith   DMSNES         sdm;
4816cab3a1bSJed Brown 
4826cab3a1bSJed Brown   PetscFunctionBegin;
4836cab3a1bSJed Brown   PetscValidHeaderSpecific(dm,DM_CLASSID,1);
484942e3340SBarry Smith   ierr = DMGetDMSNES(dm,&sdm);CHKERRQ(ierr);
48522c6f798SBarry Smith   if (func) *func = sdm->ops->computegs;
4866cab3a1bSJed Brown   if (ctx)  *ctx = sdm->gsctx;
4876cab3a1bSJed Brown   PetscFunctionReturn(0);
4886cab3a1bSJed Brown }
4896cab3a1bSJed Brown 
4906cab3a1bSJed Brown #undef __FUNCT__
4916cab3a1bSJed Brown #define __FUNCT__ "DMSNESSetJacobian"
4926cab3a1bSJed Brown /*@C
493ecfdb398SPeter Brune    DMSNESSetJacobian - set SNES Jacobian evaluation function
4946cab3a1bSJed Brown 
4956cab3a1bSJed Brown    Not Collective
4966cab3a1bSJed Brown 
4976cab3a1bSJed Brown    Input Argument:
4986cab3a1bSJed Brown +  dm - DM to be used with SNES
4996cab3a1bSJed Brown .  func - Jacobian evaluation function, see SNESSetJacobian() for calling sequence
5006cab3a1bSJed Brown -  ctx - context for residual evaluation
5016cab3a1bSJed Brown 
5026cab3a1bSJed Brown    Level: advanced
5036cab3a1bSJed Brown 
5046cab3a1bSJed Brown    Note:
5056cab3a1bSJed Brown    SNESSetJacobian() is normally used, but it calls this function internally because the user context is actually
5066cab3a1bSJed Brown    associated with the DM.  This makes the interface consistent regardless of whether the user interacts with a DM or
5076cab3a1bSJed Brown    not. If DM took a more central role at some later date, this could become the primary method of setting the Jacobian.
5086cab3a1bSJed Brown 
5096cab3a1bSJed Brown .seealso: DMSNESSetContext(), SNESSetFunction(), DMSNESGetJacobian(), SNESSetJacobian()
5106cab3a1bSJed Brown @*/
5116cab3a1bSJed Brown PetscErrorCode DMSNESSetJacobian(DM dm,PetscErrorCode (*func)(SNES,Vec,Mat*,Mat*,MatStructure*,void*),void *ctx)
5126cab3a1bSJed Brown {
5136cab3a1bSJed Brown   PetscErrorCode ierr;
514942e3340SBarry Smith   DMSNES         sdm;
5156cab3a1bSJed Brown 
5166cab3a1bSJed Brown   PetscFunctionBegin;
5176cab3a1bSJed Brown   PetscValidHeaderSpecific(dm,DM_CLASSID,1);
5181fdfe764SBarry Smith   if (func || ctx) {
519942e3340SBarry Smith     ierr = DMGetDMSNESWrite(dm,&sdm);CHKERRQ(ierr);
5201fdfe764SBarry Smith   }
52122c6f798SBarry Smith   if (func) sdm->ops->computejacobian = func;
5226cab3a1bSJed Brown   if (ctx)  sdm->jacobianctx = ctx;
5236cab3a1bSJed Brown   PetscFunctionReturn(0);
5246cab3a1bSJed Brown }
5256cab3a1bSJed Brown 
5266cab3a1bSJed Brown #undef __FUNCT__
5276cab3a1bSJed Brown #define __FUNCT__ "DMSNESGetJacobian"
5286cab3a1bSJed Brown /*@C
529ecfdb398SPeter Brune    DMSNESGetJacobian - get SNES Jacobian evaluation function
5306cab3a1bSJed Brown 
5316cab3a1bSJed Brown    Not Collective
5326cab3a1bSJed Brown 
5336cab3a1bSJed Brown    Input Argument:
5346cab3a1bSJed Brown .  dm - DM to be used with SNES
5356cab3a1bSJed Brown 
5366cab3a1bSJed Brown    Output Arguments:
5376cab3a1bSJed Brown +  func - Jacobian evaluation function, see SNESSetJacobian() for calling sequence
5386cab3a1bSJed Brown -  ctx - context for residual evaluation
5396cab3a1bSJed Brown 
5406cab3a1bSJed Brown    Level: advanced
5416cab3a1bSJed Brown 
5426cab3a1bSJed Brown    Note:
5436cab3a1bSJed Brown    SNESGetJacobian() is normally used, but it calls this function internally because the user context is actually
5446cab3a1bSJed Brown    associated with the DM.  This makes the interface consistent regardless of whether the user interacts with a DM or
5456cab3a1bSJed Brown    not. If DM took a more central role at some later date, this could become the primary method of setting the Jacobian.
5466cab3a1bSJed Brown 
5476cab3a1bSJed Brown .seealso: DMSNESSetContext(), SNESSetFunction(), DMSNESSetJacobian()
5486cab3a1bSJed Brown @*/
5496cab3a1bSJed Brown PetscErrorCode DMSNESGetJacobian(DM dm,PetscErrorCode (**func)(SNES,Vec,Mat*,Mat*,MatStructure*,void*),void **ctx)
5506cab3a1bSJed Brown {
5516cab3a1bSJed Brown   PetscErrorCode ierr;
552942e3340SBarry Smith   DMSNES         sdm;
5536cab3a1bSJed Brown 
5546cab3a1bSJed Brown   PetscFunctionBegin;
5556cab3a1bSJed Brown   PetscValidHeaderSpecific(dm,DM_CLASSID,1);
556942e3340SBarry Smith   ierr = DMGetDMSNES(dm,&sdm);CHKERRQ(ierr);
55722c6f798SBarry Smith   if (func) *func = sdm->ops->computejacobian;
5586cab3a1bSJed Brown   if (ctx)  *ctx = sdm->jacobianctx;
5596cab3a1bSJed Brown   PetscFunctionReturn(0);
5606cab3a1bSJed Brown }
5616cab3a1bSJed Brown 
5626cab3a1bSJed Brown #undef __FUNCT__
563e03ab78fSPeter Brune #define __FUNCT__ "DMSNESSetPicard"
564e03ab78fSPeter Brune /*@C
565e03ab78fSPeter Brune    DMSNESSetPicard - set SNES Picard iteration matrix and RHS evaluation functions.
566e03ab78fSPeter Brune 
567e03ab78fSPeter Brune    Not Collective
568e03ab78fSPeter Brune 
569e03ab78fSPeter Brune    Input Argument:
570e03ab78fSPeter Brune +  dm - DM to be used with SNES
571e03ab78fSPeter Brune .  func - RHS evaluation function, see SNESSetFunction() for calling sequence
572e03ab78fSPeter Brune .  pjac - Picard matrix evaluation function, see SNESSetJacobian() for calling sequence
573e03ab78fSPeter Brune -  ctx - context for residual evaluation
574e03ab78fSPeter Brune 
575e03ab78fSPeter Brune    Level: advanced
576e03ab78fSPeter Brune 
577e03ab78fSPeter Brune .seealso: SNESSetPicard(), DMSNESSetFunction(), DMSNESSetJacobian()
578e03ab78fSPeter Brune @*/
579e03ab78fSPeter Brune PetscErrorCode DMSNESSetPicard(DM dm,PetscErrorCode (*pfunc)(SNES,Vec,Vec,void*),PetscErrorCode (*pjac)(SNES,Vec,Mat*,Mat*,MatStructure*,void*),void *ctx)
580e03ab78fSPeter Brune {
581e03ab78fSPeter Brune   PetscErrorCode ierr;
582942e3340SBarry Smith   DMSNES         sdm;
583e03ab78fSPeter Brune 
584e03ab78fSPeter Brune   PetscFunctionBegin;
585e03ab78fSPeter Brune   PetscValidHeaderSpecific(dm,DM_CLASSID,1);
586942e3340SBarry Smith   ierr = DMGetDMSNES(dm,&sdm);CHKERRQ(ierr);
58722c6f798SBarry Smith   if (pfunc) sdm->ops->computepfunction = pfunc;
58822c6f798SBarry Smith   if (pjac)  sdm->ops->computepjacobian = pjac;
589e03ab78fSPeter Brune   if (ctx)   sdm->pctx             = ctx;
590e03ab78fSPeter Brune   PetscFunctionReturn(0);
591e03ab78fSPeter Brune }
592e03ab78fSPeter Brune 
5937971a8bfSPeter Brune 
5947971a8bfSPeter Brune #undef __FUNCT__
5957971a8bfSPeter Brune #define __FUNCT__ "DMSNESGetPicard"
5967971a8bfSPeter Brune /*@C
5977971a8bfSPeter Brune    DMSNESGetPicard - get SNES Picard iteration evaluation functions
5987971a8bfSPeter Brune 
5997971a8bfSPeter Brune    Not Collective
6007971a8bfSPeter Brune 
6017971a8bfSPeter Brune    Input Argument:
6027971a8bfSPeter Brune .  dm - DM to be used with SNES
6037971a8bfSPeter Brune 
6047971a8bfSPeter Brune    Output Arguments:
6057971a8bfSPeter Brune +  pfunc - Jacobian evaluation function, see SNESSetJacobian() for calling sequence
6067971a8bfSPeter Brune .  pjac  - RHS evaluation function, see SNESSetFunction() for calling sequence
6077971a8bfSPeter Brune -  ctx - context for residual evaluation
6087971a8bfSPeter Brune 
6097971a8bfSPeter Brune    Level: advanced
6107971a8bfSPeter Brune 
6117971a8bfSPeter Brune .seealso: DMSNESSetContext(), SNESSetFunction(), DMSNESSetJacobian()
6127971a8bfSPeter Brune @*/
6137971a8bfSPeter Brune PetscErrorCode DMSNESGetPicard(DM dm,PetscErrorCode (**pfunc)(SNES,Vec,Vec,void*),PetscErrorCode (**pjac)(SNES,Vec,Mat*,Mat*,MatStructure*,void*),void **ctx)
6147971a8bfSPeter Brune {
6157971a8bfSPeter Brune   PetscErrorCode ierr;
616942e3340SBarry Smith   DMSNES         sdm;
6177971a8bfSPeter Brune 
6187971a8bfSPeter Brune   PetscFunctionBegin;
6197971a8bfSPeter Brune   PetscValidHeaderSpecific(dm,DM_CLASSID,1);
620942e3340SBarry Smith   ierr = DMGetDMSNES(dm,&sdm);CHKERRQ(ierr);
62122c6f798SBarry Smith   if (pfunc) *pfunc = sdm->ops->computepfunction;
62222c6f798SBarry Smith   if (pjac) *pjac   = sdm->ops->computepjacobian;
6237971a8bfSPeter Brune   if (ctx)  *ctx    = sdm->pctx;
6247971a8bfSPeter Brune   PetscFunctionReturn(0);
6257971a8bfSPeter Brune }
6267971a8bfSPeter Brune 
6276427ad5bSPeter Brune /* block functions */
6286427ad5bSPeter Brune 
6296427ad5bSPeter Brune #undef __FUNCT__
6306427ad5bSPeter Brune #define __FUNCT__ "DMSNESSetBlockFunction"
6316427ad5bSPeter Brune /*@C
6326427ad5bSPeter Brune    DMSNESSetBlockFunction - set SNES residual evaluation function
6336427ad5bSPeter Brune 
6346427ad5bSPeter Brune    Not Collective
6356427ad5bSPeter Brune 
6366427ad5bSPeter Brune    Input Arguments:
6376427ad5bSPeter Brune +  dm - DM to be used with SNES
6386427ad5bSPeter Brune .  func - residual evaluation function, see SNESSetFunction() for calling sequence
6396427ad5bSPeter Brune -  ctx - context for residual evaluation
6406427ad5bSPeter Brune 
6416427ad5bSPeter Brune    Level: developer
6426427ad5bSPeter Brune 
6436427ad5bSPeter Brune    Note:
6446427ad5bSPeter Brune    Mostly for use in DM implementations and transferred to a block function rather than being called from here.
6456427ad5bSPeter Brune 
6466427ad5bSPeter Brune .seealso: DMSNESSetContext(), SNESSetFunction(), DMSNESSetJacobian()
6476427ad5bSPeter Brune @*/
6486427ad5bSPeter Brune PetscErrorCode DMSNESSetBlockFunction(DM dm,PetscErrorCode (*func)(SNES,Vec,Vec,void*),void *ctx)
6496427ad5bSPeter Brune {
6506427ad5bSPeter Brune   PetscErrorCode ierr;
651942e3340SBarry Smith   DMSNES         sdm;
6526427ad5bSPeter Brune 
6536427ad5bSPeter Brune   PetscFunctionBegin;
6546427ad5bSPeter Brune   PetscValidHeaderSpecific(dm,DM_CLASSID,1);
655fdaff8d6SPeter Brune   if (func || ctx) {
656942e3340SBarry Smith     ierr = DMGetDMSNESWrite(dm,&sdm);CHKERRQ(ierr);
657fdaff8d6SPeter Brune   }
65822c6f798SBarry Smith   if (func) sdm->ops->computeblockfunction = func;
6596427ad5bSPeter Brune   if (ctx)  sdm->blockfunctionctx = ctx;
6606427ad5bSPeter Brune   PetscFunctionReturn(0);
6616427ad5bSPeter Brune }
6626427ad5bSPeter Brune 
6636427ad5bSPeter Brune #undef __FUNCT__
6646427ad5bSPeter Brune #define __FUNCT__ "DMSNESGetBlockFunction"
6656427ad5bSPeter Brune /*@C
6666427ad5bSPeter Brune    DMSNESGetBlockFunction - get SNES residual evaluation function
6676427ad5bSPeter Brune 
6686427ad5bSPeter Brune    Not Collective
6696427ad5bSPeter Brune 
6706427ad5bSPeter Brune    Input Argument:
6716427ad5bSPeter Brune .  dm - DM to be used with SNES
6726427ad5bSPeter Brune 
6736427ad5bSPeter Brune    Output Arguments:
6746427ad5bSPeter Brune +  func - residual evaluation function, see SNESSetFunction() for calling sequence
6756427ad5bSPeter Brune -  ctx - context for residual evaluation
6766427ad5bSPeter Brune 
6776427ad5bSPeter Brune    Level: developer
6786427ad5bSPeter Brune 
6796427ad5bSPeter Brune .seealso: DMSNESSetContext(), DMSNESSetFunction(), SNESSetFunction()
6806427ad5bSPeter Brune @*/
6816427ad5bSPeter Brune PetscErrorCode DMSNESGetBlockFunction(DM dm,PetscErrorCode (**func)(SNES,Vec,Vec,void*),void **ctx)
6826427ad5bSPeter Brune {
6836427ad5bSPeter Brune   PetscErrorCode ierr;
684942e3340SBarry Smith   DMSNES         sdm;
6856427ad5bSPeter Brune 
6866427ad5bSPeter Brune   PetscFunctionBegin;
6876427ad5bSPeter Brune   PetscValidHeaderSpecific(dm,DM_CLASSID,1);
688942e3340SBarry Smith   ierr = DMGetDMSNES(dm,&sdm);CHKERRQ(ierr);
68922c6f798SBarry Smith   if (func) *func = sdm->ops->computeblockfunction;
6906427ad5bSPeter Brune   if (ctx)  *ctx = sdm->blockfunctionctx;
6916427ad5bSPeter Brune   PetscFunctionReturn(0);
6926427ad5bSPeter Brune }
6936427ad5bSPeter Brune 
6946427ad5bSPeter Brune 
6956427ad5bSPeter Brune #undef __FUNCT__
6966427ad5bSPeter Brune #define __FUNCT__ "DMSNESSetBlockJacobian"
6976427ad5bSPeter Brune /*@C
6986427ad5bSPeter Brune    DMSNESSetJacobian - set SNES Jacobian evaluation function
6996427ad5bSPeter Brune 
7006427ad5bSPeter Brune    Not Collective
7016427ad5bSPeter Brune 
7026427ad5bSPeter Brune    Input Argument:
7036427ad5bSPeter Brune +  dm - DM to be used with SNES
7046427ad5bSPeter Brune .  func - Jacobian evaluation function, see SNESSetJacobian() for calling sequence
7056427ad5bSPeter Brune -  ctx - context for residual evaluation
7066427ad5bSPeter Brune 
7076427ad5bSPeter Brune    Level: advanced
7086427ad5bSPeter Brune 
7096427ad5bSPeter Brune    Note:
7106427ad5bSPeter Brune    Mostly for use in DM implementations and transferred to a block function rather than being called from here.
7116427ad5bSPeter Brune 
7126427ad5bSPeter Brune .seealso: DMSNESSetContext(), SNESSetFunction(), DMSNESGetJacobian(), SNESSetJacobian()
7136427ad5bSPeter Brune @*/
7146427ad5bSPeter Brune PetscErrorCode DMSNESSetBlockJacobian(DM dm,PetscErrorCode (*func)(SNES,Vec,Mat*,Mat*,MatStructure*,void*),void *ctx)
7156427ad5bSPeter Brune {
7166427ad5bSPeter Brune   PetscErrorCode ierr;
717942e3340SBarry Smith   DMSNES         sdm;
7186427ad5bSPeter Brune 
7196427ad5bSPeter Brune   PetscFunctionBegin;
7206427ad5bSPeter Brune   PetscValidHeaderSpecific(dm,DM_CLASSID,1);
721fdaff8d6SPeter Brune   if (func || ctx) {
722942e3340SBarry Smith     ierr = DMGetDMSNESWrite(dm,&sdm);CHKERRQ(ierr);
723fdaff8d6SPeter Brune   }
72422c6f798SBarry Smith   if (func) sdm->ops->computeblockjacobian = func;
7256427ad5bSPeter Brune   if (ctx)  sdm->blockjacobianctx = ctx;
7266427ad5bSPeter Brune   PetscFunctionReturn(0);
7276427ad5bSPeter Brune }
7286427ad5bSPeter Brune 
7296427ad5bSPeter Brune #undef __FUNCT__
7306427ad5bSPeter Brune #define __FUNCT__ "DMSNESGetBlockJacobian"
7316427ad5bSPeter Brune /*@C
7326427ad5bSPeter Brune    DMSNESGetBlockJacobian - get SNES Jacobian evaluation function
7336427ad5bSPeter Brune 
7346427ad5bSPeter Brune    Not Collective
7356427ad5bSPeter Brune 
7366427ad5bSPeter Brune    Input Argument:
7376427ad5bSPeter Brune .  dm - DM to be used with SNES
7386427ad5bSPeter Brune 
7396427ad5bSPeter Brune    Output Arguments:
7406427ad5bSPeter Brune +  func - Jacobian evaluation function, see SNESSetJacobian() for calling sequence
7416427ad5bSPeter Brune -  ctx - context for residual evaluation
7426427ad5bSPeter Brune 
7436427ad5bSPeter Brune    Level: advanced
7446427ad5bSPeter Brune 
7456427ad5bSPeter Brune .seealso: DMSNESSetContext(), SNESSetFunction(), DMSNESSetJacobian()
7466427ad5bSPeter Brune @*/
7476427ad5bSPeter Brune PetscErrorCode DMSNESGetBlockJacobian(DM dm,PetscErrorCode (**func)(SNES,Vec,Mat*,Mat*,MatStructure*,void*),void **ctx)
7486427ad5bSPeter Brune {
7496427ad5bSPeter Brune   PetscErrorCode ierr;
750942e3340SBarry Smith   DMSNES         sdm;
7516427ad5bSPeter Brune 
7526427ad5bSPeter Brune   PetscFunctionBegin;
7536427ad5bSPeter Brune   PetscValidHeaderSpecific(dm,DM_CLASSID,1);
754942e3340SBarry Smith   ierr = DMGetDMSNES(dm,&sdm);CHKERRQ(ierr);
75522c6f798SBarry Smith   if (func) *func = sdm->ops->computeblockjacobian;
7566427ad5bSPeter Brune   if (ctx)  *ctx = sdm->blockjacobianctx;
7576427ad5bSPeter Brune   PetscFunctionReturn(0);
7586427ad5bSPeter Brune }
759