xref: /petsc/src/ts/utils/dmts.c (revision 060da220a69df799affd088f0100c1f4dac789cb)
124989b8cSPeter Brune #include <petsc-private/tsimpl.h>     /*I "petscts.h" I*/
207475bc1SBarry Smith #include <petsc-private/dmimpl.h>
324989b8cSPeter Brune 
4d74926cbSBarry Smith #undef __FUNCT__
5d74926cbSBarry Smith #define __FUNCT__ "DMTSDestroy"
6d74926cbSBarry Smith static PetscErrorCode DMTSDestroy(DMTS *kdm)
7d74926cbSBarry Smith {
8d74926cbSBarry Smith   PetscErrorCode ierr;
9d74926cbSBarry Smith 
10d74926cbSBarry Smith   PetscFunctionBegin;
11d74926cbSBarry Smith   if (!*kdm) PetscFunctionReturn(0);
12d74926cbSBarry Smith   PetscValidHeaderSpecific((*kdm),DMTS_CLASSID,1);
13d74926cbSBarry Smith   if (--((PetscObject)(*kdm))->refct > 0) {*kdm = 0; PetscFunctionReturn(0);}
14d74926cbSBarry Smith   if ((*kdm)->ops->destroy) {ierr = ((*kdm)->ops->destroy)(*kdm);CHKERRQ(ierr);}
15d74926cbSBarry Smith   ierr = PetscHeaderDestroy(kdm);CHKERRQ(ierr);
16d74926cbSBarry Smith   PetscFunctionReturn(0);
17d74926cbSBarry Smith }
18d74926cbSBarry Smith 
19d74926cbSBarry Smith #undef __FUNCT__
202d53ad75SBarry Smith #define __FUNCT__ "DMTSLoad"
212d53ad75SBarry Smith PetscErrorCode DMTSLoad(DMTS kdm,PetscViewer viewer)
222d53ad75SBarry Smith {
232d53ad75SBarry Smith   PetscErrorCode ierr;
242d53ad75SBarry Smith 
252d53ad75SBarry Smith   PetscFunctionBegin;
26*060da220SMatthew G. Knepley   ierr = PetscViewerBinaryRead(viewer,&kdm->ops->ifunction,1,NULL,PETSC_FUNCTION);CHKERRQ(ierr);
27*060da220SMatthew G. Knepley   ierr = PetscViewerBinaryRead(viewer,&kdm->ops->ifunctionview,1,NULL,PETSC_FUNCTION);CHKERRQ(ierr);
28*060da220SMatthew G. Knepley   ierr = PetscViewerBinaryRead(viewer,&kdm->ops->ifunctionload,1,NULL,PETSC_FUNCTION);CHKERRQ(ierr);
29ad6bc421SBarry Smith   if (kdm->ops->ifunctionload) {
30ad6bc421SBarry Smith     ierr = (*kdm->ops->ifunctionload)(&kdm->ifunctionctx,viewer);CHKERRQ(ierr);
31ad6bc421SBarry Smith   }
32*060da220SMatthew G. Knepley   ierr = PetscViewerBinaryRead(viewer,&kdm->ops->ijacobian,1,NULL,PETSC_FUNCTION);CHKERRQ(ierr);
33*060da220SMatthew G. Knepley   ierr = PetscViewerBinaryRead(viewer,&kdm->ops->ijacobianview,1,NULL,PETSC_FUNCTION);CHKERRQ(ierr);
34*060da220SMatthew G. Knepley   ierr = PetscViewerBinaryRead(viewer,&kdm->ops->ijacobianload,1,NULL,PETSC_FUNCTION);CHKERRQ(ierr);
35ad6bc421SBarry Smith   if (kdm->ops->ijacobianload) {
36ad6bc421SBarry Smith     ierr = (*kdm->ops->ijacobianload)(&kdm->ijacobianctx,viewer);CHKERRQ(ierr);
37ad6bc421SBarry Smith   }
382d53ad75SBarry Smith   PetscFunctionReturn(0);
392d53ad75SBarry Smith }
402d53ad75SBarry Smith 
412d53ad75SBarry Smith #undef __FUNCT__
422d53ad75SBarry Smith #define __FUNCT__ "DMTSView"
432d53ad75SBarry Smith PetscErrorCode DMTSView(DMTS kdm,PetscViewer viewer)
442d53ad75SBarry Smith {
452d53ad75SBarry Smith   PetscErrorCode ierr;
462d53ad75SBarry Smith   PetscBool      isascii,isbinary;
472d53ad75SBarry Smith 
482d53ad75SBarry Smith   PetscFunctionBegin;
492d53ad75SBarry Smith   ierr = PetscObjectTypeCompare((PetscObject)viewer,PETSCVIEWERASCII,&isascii);CHKERRQ(ierr);
502d53ad75SBarry Smith   ierr = PetscObjectTypeCompare((PetscObject)viewer,PETSCVIEWERBINARY,&isbinary);CHKERRQ(ierr);
512d53ad75SBarry Smith   if (isascii) {
52c7a10e08SBarry Smith #if defined(PETSC_SERIALIZE_FUNCTIONS)
532d53ad75SBarry Smith     const char *fname;
542d53ad75SBarry Smith 
552d53ad75SBarry Smith     ierr = PetscFPTFind(kdm->ops->ifunction,&fname);CHKERRQ(ierr);
562d53ad75SBarry Smith     if (fname) {
572d53ad75SBarry Smith       ierr = PetscViewerASCIIPrintf(viewer,"  IFunction used by TS: %s\n",fname);CHKERRQ(ierr);
582d53ad75SBarry Smith     }
592d53ad75SBarry Smith     ierr = PetscFPTFind(kdm->ops->ijacobian,&fname);CHKERRQ(ierr);
602d53ad75SBarry Smith     if (fname) {
612d53ad75SBarry Smith       ierr = PetscViewerASCIIPrintf(viewer,"  IJacobian function used by TS: %s\n",fname);CHKERRQ(ierr);
622d53ad75SBarry Smith     }
63c7a10e08SBarry Smith #endif
642d53ad75SBarry Smith   } else if (isbinary) {
653964eb88SJed Brown     struct {
663964eb88SJed Brown       TSIFunction ifunction;
679200755eSBarry Smith     } funcstruct;
689200755eSBarry Smith     struct {
693964eb88SJed Brown       PetscErrorCode (*ifunctionview)(void*,PetscViewer);
709200755eSBarry Smith     } funcviewstruct;
719200755eSBarry Smith     struct {
723964eb88SJed Brown       PetscErrorCode (*ifunctionload)(void**,PetscViewer);
739200755eSBarry Smith     } funcloadstruct;
743964eb88SJed Brown     struct {
753964eb88SJed Brown       TSIJacobian ijacobian;
769200755eSBarry Smith     } jacstruct;
779200755eSBarry Smith     struct {
783964eb88SJed Brown       PetscErrorCode (*ijacobianview)(void*,PetscViewer);
799200755eSBarry Smith     } jacviewstruct;
809200755eSBarry Smith     struct {
813964eb88SJed Brown       PetscErrorCode (*ijacobianload)(void**,PetscViewer);
829200755eSBarry Smith     } jacloadstruct;
833964eb88SJed Brown 
849200755eSBarry Smith     funcstruct.ifunction         = kdm->ops->ifunction;
859200755eSBarry Smith     funcviewstruct.ifunctionview = kdm->ops->ifunctionview;
869200755eSBarry Smith     funcloadstruct.ifunctionload = kdm->ops->ifunctionload;
879200755eSBarry Smith     ierr = PetscViewerBinaryWrite(viewer,&funcstruct,1,PETSC_FUNCTION,PETSC_FALSE);CHKERRQ(ierr);
889200755eSBarry Smith     ierr = PetscViewerBinaryWrite(viewer,&funcviewstruct,1,PETSC_FUNCTION,PETSC_FALSE);CHKERRQ(ierr);
899200755eSBarry Smith     ierr = PetscViewerBinaryWrite(viewer,&funcloadstruct,1,PETSC_FUNCTION,PETSC_FALSE);CHKERRQ(ierr);
90ad6bc421SBarry Smith     if (kdm->ops->ifunctionview) {
91ad6bc421SBarry Smith       ierr = (*kdm->ops->ifunctionview)(kdm->ifunctionctx,viewer);CHKERRQ(ierr);
92ad6bc421SBarry Smith     }
939200755eSBarry Smith     jacstruct.ijacobian = kdm->ops->ijacobian;
949200755eSBarry Smith     jacviewstruct.ijacobianview = kdm->ops->ijacobianview;
959200755eSBarry Smith     jacloadstruct.ijacobianload = kdm->ops->ijacobianload;
969200755eSBarry Smith     ierr = PetscViewerBinaryWrite(viewer,&jacstruct,1,PETSC_FUNCTION,PETSC_FALSE);CHKERRQ(ierr);
979200755eSBarry Smith     ierr = PetscViewerBinaryWrite(viewer,&jacviewstruct,1,PETSC_FUNCTION,PETSC_FALSE);CHKERRQ(ierr);
989200755eSBarry Smith     ierr = PetscViewerBinaryWrite(viewer,&jacloadstruct,1,PETSC_FUNCTION,PETSC_FALSE);CHKERRQ(ierr);
99ad6bc421SBarry Smith     if (kdm->ops->ijacobianview) {
100ad6bc421SBarry Smith       ierr = (*kdm->ops->ijacobianview)(kdm->ijacobianctx,viewer);CHKERRQ(ierr);
101ad6bc421SBarry Smith     }
1022d53ad75SBarry Smith   }
1032d53ad75SBarry Smith   PetscFunctionReturn(0);
1042d53ad75SBarry Smith }
1052d53ad75SBarry Smith 
1062d53ad75SBarry Smith #undef __FUNCT__
107d74926cbSBarry Smith #define __FUNCT__ "DMTSCreate"
108d74926cbSBarry Smith static PetscErrorCode DMTSCreate(MPI_Comm comm,DMTS *kdm)
109d74926cbSBarry Smith {
110d74926cbSBarry Smith   PetscErrorCode ierr;
111d74926cbSBarry Smith 
112d74926cbSBarry Smith   PetscFunctionBegin;
113607a6623SBarry Smith   ierr = TSInitializePackage();CHKERRQ(ierr);
11467c2884eSBarry Smith   ierr = PetscHeaderCreate(*kdm, _p_DMTS, struct _DMTSOps, DMTS_CLASSID, "DMTS", "DMTS", "DMTS", comm, DMTSDestroy, DMTSView);CHKERRQ(ierr);
115d74926cbSBarry Smith   ierr = PetscMemzero((*kdm)->ops, sizeof(struct _DMTSOps));CHKERRQ(ierr);
116d74926cbSBarry Smith   PetscFunctionReturn(0);
117d74926cbSBarry Smith }
11824989b8cSPeter Brune 
11924989b8cSPeter Brune #undef __FUNCT__
120942e3340SBarry Smith #define __FUNCT__ "DMCoarsenHook_DMTS"
1212a34c10cSBarry Smith /* Attaches the DMTS to the coarse level.
12224989b8cSPeter Brune  * Under what conditions should we copy versus duplicate?
12324989b8cSPeter Brune  */
124942e3340SBarry Smith static PetscErrorCode DMCoarsenHook_DMTS(DM dm,DM dmc,void *ctx)
12524989b8cSPeter Brune {
12624989b8cSPeter Brune   PetscErrorCode ierr;
12724989b8cSPeter Brune 
12824989b8cSPeter Brune   PetscFunctionBegin;
129942e3340SBarry Smith   ierr = DMCopyDMTS(dm,dmc);CHKERRQ(ierr);
13024989b8cSPeter Brune   PetscFunctionReturn(0);
13124989b8cSPeter Brune }
13224989b8cSPeter Brune 
13324989b8cSPeter Brune #undef __FUNCT__
134942e3340SBarry Smith #define __FUNCT__ "DMRestrictHook_DMTS"
13524989b8cSPeter Brune /* This could restrict auxiliary information to the coarse level.
13624989b8cSPeter Brune  */
137942e3340SBarry Smith static PetscErrorCode DMRestrictHook_DMTS(DM dm,Mat Restrict,Vec rscale,Mat Inject,DM dmc,void *ctx)
13824989b8cSPeter Brune {
13924989b8cSPeter Brune 
14024989b8cSPeter Brune   PetscFunctionBegin;
14124989b8cSPeter Brune   PetscFunctionReturn(0);
14224989b8cSPeter Brune }
14324989b8cSPeter Brune 
14424989b8cSPeter Brune #undef __FUNCT__
145258e1594SPeter Brune #define __FUNCT__ "DMSubDomainHook_DMTS"
146258e1594SPeter Brune static PetscErrorCode DMSubDomainHook_DMTS(DM dm,DM subdm,void *ctx)
147258e1594SPeter Brune {
148258e1594SPeter Brune   PetscErrorCode ierr;
149258e1594SPeter Brune 
150258e1594SPeter Brune   PetscFunctionBegin;
151258e1594SPeter Brune   ierr = DMCopyDMTS(dm,subdm);CHKERRQ(ierr);
152258e1594SPeter Brune   PetscFunctionReturn(0);
153258e1594SPeter Brune }
154258e1594SPeter Brune 
155258e1594SPeter Brune #undef __FUNCT__
156258e1594SPeter Brune #define __FUNCT__ "DMSubDomainRestrictHook_DMTS"
157258e1594SPeter Brune /* This could restrict auxiliary information to the coarse level.
158258e1594SPeter Brune  */
159258e1594SPeter Brune static PetscErrorCode DMSubDomainRestrictHook_DMTS(DM dm,VecScatter gscat,VecScatter lscat,DM subdm,void *ctx)
160258e1594SPeter Brune {
161258e1594SPeter Brune   PetscFunctionBegin;
162258e1594SPeter Brune   PetscFunctionReturn(0);
163258e1594SPeter Brune }
164258e1594SPeter Brune 
165258e1594SPeter Brune #undef __FUNCT__
166d74926cbSBarry Smith #define __FUNCT__ "DMTSCopy"
167d74926cbSBarry Smith /*@C
168d74926cbSBarry Smith    DMTSCopy - copies the information in a DMTS to another DMTS
169d74926cbSBarry Smith 
170d74926cbSBarry Smith    Not Collective
171d74926cbSBarry Smith 
172d74926cbSBarry Smith    Input Argument:
173d74926cbSBarry Smith +  kdm - Original DMTS
174d74926cbSBarry Smith -  nkdm - DMTS to receive the data, should have been created with DMTSCreate()
175d74926cbSBarry Smith 
176d74926cbSBarry Smith    Level: developer
177d74926cbSBarry Smith 
178d74926cbSBarry Smith .seealso: DMTSCreate(), DMTSDestroy()
179d74926cbSBarry Smith @*/
180d74926cbSBarry Smith PetscErrorCode DMTSCopy(DMTS kdm,DMTS nkdm)
18124989b8cSPeter Brune {
18224989b8cSPeter Brune   PetscErrorCode ierr;
18324989b8cSPeter Brune 
18424989b8cSPeter Brune   PetscFunctionBegin;
185d74926cbSBarry Smith   PetscValidHeaderSpecific(kdm,DMTS_CLASSID,1);
186d74926cbSBarry Smith   PetscValidHeaderSpecific(nkdm,DMTS_CLASSID,2);
187d74926cbSBarry Smith   nkdm->ops->rhsfunction = kdm->ops->rhsfunction;
188d74926cbSBarry Smith   nkdm->ops->rhsjacobian = kdm->ops->rhsjacobian;
189d74926cbSBarry Smith   nkdm->ops->ifunction   = kdm->ops->ifunction;
190d74926cbSBarry Smith   nkdm->ops->ijacobian   = kdm->ops->ijacobian;
191d74926cbSBarry Smith   nkdm->ops->solution    = kdm->ops->solution;
192d74926cbSBarry Smith   nkdm->ops->destroy     = kdm->ops->destroy;
193d74926cbSBarry Smith   nkdm->ops->duplicate   = kdm->ops->duplicate;
194d74926cbSBarry Smith 
195d74926cbSBarry Smith   nkdm->rhsfunctionctx = kdm->rhsfunctionctx;
196d74926cbSBarry Smith   nkdm->rhsjacobianctx = kdm->rhsjacobianctx;
197d74926cbSBarry Smith   nkdm->ifunctionctx   = kdm->ifunctionctx;
198d74926cbSBarry Smith   nkdm->ijacobianctx   = kdm->ijacobianctx;
199d74926cbSBarry Smith   nkdm->solutionctx    = kdm->solutionctx;
200d74926cbSBarry Smith 
201d74926cbSBarry Smith   nkdm->data = kdm->data;
202d74926cbSBarry Smith 
203d74926cbSBarry Smith   /*
204d74926cbSBarry Smith   nkdm->fortran_func_pointers[0] = kdm->fortran_func_pointers[0];
205d74926cbSBarry Smith   nkdm->fortran_func_pointers[1] = kdm->fortran_func_pointers[1];
206d74926cbSBarry Smith   nkdm->fortran_func_pointers[2] = kdm->fortran_func_pointers[2];
207d74926cbSBarry Smith   */
208d74926cbSBarry Smith 
209d74926cbSBarry Smith   /* implementation specific copy hooks */
210d74926cbSBarry Smith   if (kdm->ops->duplicate) {ierr = (*kdm->ops->duplicate)(kdm,nkdm);CHKERRQ(ierr);}
21124989b8cSPeter Brune   PetscFunctionReturn(0);
21224989b8cSPeter Brune }
21324989b8cSPeter Brune 
21424989b8cSPeter Brune #undef __FUNCT__
215942e3340SBarry Smith #define __FUNCT__ "DMGetDMTS"
21624989b8cSPeter Brune /*@C
217942e3340SBarry Smith    DMGetDMTS - get read-only private DMTS context from a DM
21824989b8cSPeter Brune 
21924989b8cSPeter Brune    Not Collective
22024989b8cSPeter Brune 
22124989b8cSPeter Brune    Input Argument:
22224989b8cSPeter Brune .  dm - DM to be used with TS
22324989b8cSPeter Brune 
22424989b8cSPeter Brune    Output Argument:
225942e3340SBarry Smith .  tsdm - private DMTS context
22624989b8cSPeter Brune 
22724989b8cSPeter Brune    Level: developer
22824989b8cSPeter Brune 
22924989b8cSPeter Brune    Notes:
230942e3340SBarry Smith    Use DMGetDMTSWrite() if write access is needed. The DMTSSetXXX API should be used wherever possible.
23124989b8cSPeter Brune 
232942e3340SBarry Smith .seealso: DMGetDMTSWrite()
23324989b8cSPeter Brune @*/
234942e3340SBarry Smith PetscErrorCode DMGetDMTS(DM dm,DMTS *tsdm)
23524989b8cSPeter Brune {
23624989b8cSPeter Brune   PetscErrorCode ierr;
23724989b8cSPeter Brune 
23824989b8cSPeter Brune   PetscFunctionBegin;
23924989b8cSPeter Brune   PetscValidHeaderSpecific(dm,DM_CLASSID,1);
2402a34c10cSBarry Smith   *tsdm = (DMTS) dm->dmts;
241d74926cbSBarry Smith   if (!*tsdm) {
242942e3340SBarry Smith     ierr = PetscInfo(dm,"Creating new DMTS\n");CHKERRQ(ierr);
243ce94432eSBarry Smith     ierr = DMTSCreate(PetscObjectComm((PetscObject)dm),tsdm);CHKERRQ(ierr);
2442a34c10cSBarry Smith     dm->dmts = (PetscObject) *tsdm;
2450298fd71SBarry Smith     ierr = DMCoarsenHookAdd(dm,DMCoarsenHook_DMTS,DMRestrictHook_DMTS,NULL);CHKERRQ(ierr);
2460298fd71SBarry Smith     ierr = DMSubDomainHookAdd(dm,DMSubDomainHook_DMTS,DMSubDomainRestrictHook_DMTS,NULL);CHKERRQ(ierr);
24724989b8cSPeter Brune   }
24824989b8cSPeter Brune   PetscFunctionReturn(0);
24924989b8cSPeter Brune }
25024989b8cSPeter Brune 
25124989b8cSPeter Brune #undef __FUNCT__
252942e3340SBarry Smith #define __FUNCT__ "DMGetDMTSWrite"
25324989b8cSPeter Brune /*@C
254942e3340SBarry Smith    DMGetDMTSWrite - get write access to private DMTS context from a DM
25524989b8cSPeter Brune 
25624989b8cSPeter Brune    Not Collective
25724989b8cSPeter Brune 
25824989b8cSPeter Brune    Input Argument:
25924989b8cSPeter Brune .  dm - DM to be used with TS
26024989b8cSPeter Brune 
26124989b8cSPeter Brune    Output Argument:
262942e3340SBarry Smith .  tsdm - private DMTS context
26324989b8cSPeter Brune 
26424989b8cSPeter Brune    Level: developer
26524989b8cSPeter Brune 
266942e3340SBarry Smith .seealso: DMGetDMTS()
26724989b8cSPeter Brune @*/
268942e3340SBarry Smith PetscErrorCode DMGetDMTSWrite(DM dm,DMTS *tsdm)
26924989b8cSPeter Brune {
27024989b8cSPeter Brune   PetscErrorCode ierr;
271942e3340SBarry Smith   DMTS           sdm;
27224989b8cSPeter Brune 
27324989b8cSPeter Brune   PetscFunctionBegin;
27424989b8cSPeter Brune   PetscValidHeaderSpecific(dm,DM_CLASSID,1);
275942e3340SBarry Smith   ierr = DMGetDMTS(dm,&sdm);CHKERRQ(ierr);
27624989b8cSPeter Brune   if (!sdm->originaldm) sdm->originaldm = dm;
27724989b8cSPeter Brune   if (sdm->originaldm != dm) {  /* Copy on write */
2782a34c10cSBarry Smith     DMTS oldsdm = sdm;
279942e3340SBarry Smith     ierr     = PetscInfo(dm,"Copying DMTS due to write\n");CHKERRQ(ierr);
280ce94432eSBarry Smith     ierr     = DMTSCreate(PetscObjectComm((PetscObject)dm),&sdm);CHKERRQ(ierr);
281d74926cbSBarry Smith     ierr     = DMTSCopy(oldsdm,sdm);CHKERRQ(ierr);
2822a34c10cSBarry Smith     ierr     = DMTSDestroy((DMTS*)&dm->dmts);CHKERRQ(ierr);
2832a34c10cSBarry Smith     dm->dmts = (PetscObject) sdm;
28424989b8cSPeter Brune   }
28524989b8cSPeter Brune   *tsdm = sdm;
28624989b8cSPeter Brune   PetscFunctionReturn(0);
28724989b8cSPeter Brune }
28824989b8cSPeter Brune 
28924989b8cSPeter Brune #undef __FUNCT__
290942e3340SBarry Smith #define __FUNCT__ "DMCopyDMTS"
29124989b8cSPeter Brune /*@C
292942e3340SBarry Smith    DMCopyDMTS - copies a DM context to a new DM
29324989b8cSPeter Brune 
29424989b8cSPeter Brune    Logically Collective
29524989b8cSPeter Brune 
29624989b8cSPeter Brune    Input Arguments:
29724989b8cSPeter Brune +  dmsrc - DM to obtain context from
29824989b8cSPeter Brune -  dmdest - DM to add context to
29924989b8cSPeter Brune 
30024989b8cSPeter Brune    Level: developer
30124989b8cSPeter Brune 
30224989b8cSPeter Brune    Note:
30324989b8cSPeter Brune    The context is copied by reference. This function does not ensure that a context exists.
30424989b8cSPeter Brune 
305942e3340SBarry Smith .seealso: DMGetDMTS(), TSSetDM()
30624989b8cSPeter Brune @*/
307942e3340SBarry Smith PetscErrorCode DMCopyDMTS(DM dmsrc,DM dmdest)
30824989b8cSPeter Brune {
30924989b8cSPeter Brune   PetscErrorCode ierr;
31024989b8cSPeter Brune 
31124989b8cSPeter Brune   PetscFunctionBegin;
31224989b8cSPeter Brune   PetscValidHeaderSpecific(dmsrc,DM_CLASSID,1);
31324989b8cSPeter Brune   PetscValidHeaderSpecific(dmdest,DM_CLASSID,2);
3142a34c10cSBarry Smith   ierr         = DMTSDestroy((DMTS*)&dmdest->dmts);CHKERRQ(ierr);
3152a34c10cSBarry Smith   dmdest->dmts = dmsrc->dmts;
3162a34c10cSBarry Smith   ierr         = PetscObjectReference(dmdest->dmts);CHKERRQ(ierr);
3170298fd71SBarry Smith   ierr         = DMCoarsenHookAdd(dmdest,DMCoarsenHook_DMTS,DMRestrictHook_DMTS,NULL);CHKERRQ(ierr);
3180298fd71SBarry Smith   ierr         = DMSubDomainHookAdd(dmdest,DMSubDomainHook_DMTS,DMSubDomainRestrictHook_DMTS,NULL);CHKERRQ(ierr);
31924989b8cSPeter Brune   PetscFunctionReturn(0);
32024989b8cSPeter Brune }
32124989b8cSPeter Brune 
32224989b8cSPeter Brune #undef __FUNCT__
32324989b8cSPeter Brune #define __FUNCT__ "DMTSSetIFunction"
32424989b8cSPeter Brune /*@C
32524989b8cSPeter Brune    DMTSSetIFunction - set TS implicit function evaluation function
32624989b8cSPeter Brune 
32724989b8cSPeter Brune    Not Collective
32824989b8cSPeter Brune 
32924989b8cSPeter Brune    Input Arguments:
33024989b8cSPeter Brune +  dm - DM to be used with TS
33124989b8cSPeter Brune .  func - function evaluation function, see TSSetIFunction() for calling sequence
33224989b8cSPeter Brune -  ctx - context for residual evaluation
33324989b8cSPeter Brune 
33424989b8cSPeter Brune    Level: advanced
33524989b8cSPeter Brune 
33624989b8cSPeter Brune    Note:
33724989b8cSPeter Brune    TSSetFunction() is normally used, but it calls this function internally because the user context is actually
33824989b8cSPeter Brune    associated with the DM.  This makes the interface consistent regardless of whether the user interacts with a DM or
33924989b8cSPeter Brune    not. If DM took a more central role at some later date, this could become the primary method of setting the residual.
34024989b8cSPeter Brune 
34124989b8cSPeter Brune .seealso: DMTSSetContext(), TSSetFunction(), DMTSSetJacobian()
34224989b8cSPeter Brune @*/
34324989b8cSPeter Brune PetscErrorCode DMTSSetIFunction(DM dm,TSIFunction func,void *ctx)
34424989b8cSPeter Brune {
34524989b8cSPeter Brune   PetscErrorCode ierr;
346942e3340SBarry Smith   DMTS           tsdm;
34724989b8cSPeter Brune 
34824989b8cSPeter Brune   PetscFunctionBegin;
34924989b8cSPeter Brune   PetscValidHeaderSpecific(dm,DM_CLASSID,1);
350942e3340SBarry Smith   ierr = DMGetDMTSWrite(dm,&tsdm);CHKERRQ(ierr);
351d74926cbSBarry Smith   if (func) tsdm->ops->ifunction = func;
35224989b8cSPeter Brune   if (ctx)  tsdm->ifunctionctx = ctx;
35324989b8cSPeter Brune   PetscFunctionReturn(0);
35424989b8cSPeter Brune }
35524989b8cSPeter Brune 
35624989b8cSPeter Brune #undef __FUNCT__
35724989b8cSPeter Brune #define __FUNCT__ "DMTSGetIFunction"
35824989b8cSPeter Brune /*@C
35924989b8cSPeter Brune    DMTSGetIFunction - get TS implicit residual evaluation function
36024989b8cSPeter Brune 
36124989b8cSPeter Brune    Not Collective
36224989b8cSPeter Brune 
36324989b8cSPeter Brune    Input Argument:
36424989b8cSPeter Brune .  dm - DM to be used with TS
36524989b8cSPeter Brune 
36624989b8cSPeter Brune    Output Arguments:
36724989b8cSPeter Brune +  func - function evaluation function, see TSSetIFunction() for calling sequence
36824989b8cSPeter Brune -  ctx - context for residual evaluation
36924989b8cSPeter Brune 
37024989b8cSPeter Brune    Level: advanced
37124989b8cSPeter Brune 
37224989b8cSPeter Brune    Note:
37324989b8cSPeter Brune    TSGetFunction() is normally used, but it calls this function internally because the user context is actually
37424989b8cSPeter Brune    associated with the DM.
37524989b8cSPeter Brune 
37624989b8cSPeter Brune .seealso: DMTSSetContext(), DMTSSetFunction(), TSSetFunction()
37724989b8cSPeter Brune @*/
37824989b8cSPeter Brune PetscErrorCode DMTSGetIFunction(DM dm,TSIFunction *func,void **ctx)
37924989b8cSPeter Brune {
38024989b8cSPeter Brune   PetscErrorCode ierr;
381942e3340SBarry Smith   DMTS           tsdm;
38224989b8cSPeter Brune 
38324989b8cSPeter Brune   PetscFunctionBegin;
38424989b8cSPeter Brune   PetscValidHeaderSpecific(dm,DM_CLASSID,1);
385942e3340SBarry Smith   ierr = DMGetDMTS(dm,&tsdm);CHKERRQ(ierr);
386d74926cbSBarry Smith   if (func) *func = tsdm->ops->ifunction;
38724989b8cSPeter Brune   if (ctx)  *ctx = tsdm->ifunctionctx;
38824989b8cSPeter Brune   PetscFunctionReturn(0);
38924989b8cSPeter Brune }
39024989b8cSPeter Brune 
39124989b8cSPeter Brune 
39224989b8cSPeter Brune #undef __FUNCT__
39324989b8cSPeter Brune #define __FUNCT__ "DMTSSetRHSFunction"
39424989b8cSPeter Brune /*@C
39524989b8cSPeter Brune    DMTSSetRHSFunction - set TS explicit residual evaluation function
39624989b8cSPeter Brune 
39724989b8cSPeter Brune    Not Collective
39824989b8cSPeter Brune 
39924989b8cSPeter Brune    Input Arguments:
40024989b8cSPeter Brune +  dm - DM to be used with TS
40124989b8cSPeter Brune .  func - RHS function evaluation function, see TSSetRHSFunction() for calling sequence
40224989b8cSPeter Brune -  ctx - context for residual evaluation
40324989b8cSPeter Brune 
40424989b8cSPeter Brune    Level: advanced
40524989b8cSPeter Brune 
40624989b8cSPeter Brune    Note:
407ef20d060SBarry Smith    TSSetRSHFunction() is normally used, but it calls this function internally because the user context is actually
40824989b8cSPeter Brune    associated with the DM.  This makes the interface consistent regardless of whether the user interacts with a DM or
40924989b8cSPeter Brune    not. If DM took a more central role at some later date, this could become the primary method of setting the residual.
41024989b8cSPeter Brune 
41124989b8cSPeter Brune .seealso: DMTSSetContext(), TSSetFunction(), DMTSSetJacobian()
41224989b8cSPeter Brune @*/
41324989b8cSPeter Brune PetscErrorCode DMTSSetRHSFunction(DM dm,TSRHSFunction func,void *ctx)
41424989b8cSPeter Brune {
41524989b8cSPeter Brune   PetscErrorCode ierr;
416942e3340SBarry Smith   DMTS           tsdm;
41724989b8cSPeter Brune 
41824989b8cSPeter Brune   PetscFunctionBegin;
41924989b8cSPeter Brune   PetscValidHeaderSpecific(dm,DM_CLASSID,1);
420942e3340SBarry Smith   ierr = DMGetDMTSWrite(dm,&tsdm);CHKERRQ(ierr);
421d74926cbSBarry Smith   if (func) tsdm->ops->rhsfunction = func;
42224989b8cSPeter Brune   if (ctx)  tsdm->rhsfunctionctx = ctx;
42324989b8cSPeter Brune   PetscFunctionReturn(0);
42424989b8cSPeter Brune }
42524989b8cSPeter Brune 
42624989b8cSPeter Brune #undef __FUNCT__
427ef20d060SBarry Smith #define __FUNCT__ "DMTSGetSolutionFunction"
428ef20d060SBarry Smith /*@C
429ef20d060SBarry Smith    DMTSGetSolutionFunction - gets the TS solution evaluation function
430ef20d060SBarry Smith 
431ef20d060SBarry Smith    Not Collective
432ef20d060SBarry Smith 
433ef20d060SBarry Smith    Input Arguments:
434ef20d060SBarry Smith .  dm - DM to be used with TS
435ef20d060SBarry Smith 
436ef20d060SBarry Smith    Output Parameters:
437ef20d060SBarry Smith +  func - solution function evaluation function, see TSSetSolution() for calling sequence
438ef20d060SBarry Smith -  ctx - context for solution evaluation
439ef20d060SBarry Smith 
440ef20d060SBarry Smith    Level: advanced
441ef20d060SBarry Smith 
442ef20d060SBarry Smith .seealso: DMTSSetContext(), TSSetFunction(), DMTSSetJacobian()
443ef20d060SBarry Smith @*/
444ef20d060SBarry Smith PetscErrorCode DMTSGetSolutionFunction(DM dm,TSSolutionFunction *func,void **ctx)
445ef20d060SBarry Smith {
446ef20d060SBarry Smith   PetscErrorCode ierr;
447942e3340SBarry Smith   DMTS           tsdm;
448ef20d060SBarry Smith 
449ef20d060SBarry Smith   PetscFunctionBegin;
450ef20d060SBarry Smith   PetscValidHeaderSpecific(dm,DM_CLASSID,1);
451942e3340SBarry Smith   ierr = DMGetDMTS(dm,&tsdm);CHKERRQ(ierr);
452d74926cbSBarry Smith   if (func) *func = tsdm->ops->solution;
453ef20d060SBarry Smith   if (ctx)  *ctx  = tsdm->solutionctx;
454ef20d060SBarry Smith   PetscFunctionReturn(0);
455ef20d060SBarry Smith }
456ef20d060SBarry Smith 
457ef20d060SBarry Smith #undef __FUNCT__
458ef20d060SBarry Smith #define __FUNCT__ "DMTSSetSolutionFunction"
459ef20d060SBarry Smith /*@C
460ef20d060SBarry Smith    DMTSSetSolutionFunction - set TS solution evaluation function
461ef20d060SBarry Smith 
462ef20d060SBarry Smith    Not Collective
463ef20d060SBarry Smith 
464ef20d060SBarry Smith    Input Arguments:
465ef20d060SBarry Smith +  dm - DM to be used with TS
466ef20d060SBarry Smith .  func - solution function evaluation function, see TSSetSolution() for calling sequence
467ef20d060SBarry Smith -  ctx - context for solution evaluation
468ef20d060SBarry Smith 
469ef20d060SBarry Smith    Level: advanced
470ef20d060SBarry Smith 
471ef20d060SBarry Smith    Note:
472ef20d060SBarry Smith    TSSetSolutionFunction() is normally used, but it calls this function internally because the user context is actually
473ef20d060SBarry Smith    associated with the DM.  This makes the interface consistent regardless of whether the user interacts with a DM or
474ef20d060SBarry Smith    not. If DM took a more central role at some later date, this could become the primary method of setting the residual.
475ef20d060SBarry Smith 
476ef20d060SBarry Smith .seealso: DMTSSetContext(), TSSetFunction(), DMTSSetJacobian()
477ef20d060SBarry Smith @*/
478ef20d060SBarry Smith PetscErrorCode DMTSSetSolutionFunction(DM dm,TSSolutionFunction func,void *ctx)
479ef20d060SBarry Smith {
480ef20d060SBarry Smith   PetscErrorCode ierr;
481942e3340SBarry Smith   DMTS           tsdm;
482ef20d060SBarry Smith 
483ef20d060SBarry Smith   PetscFunctionBegin;
484ef20d060SBarry Smith   PetscValidHeaderSpecific(dm,DM_CLASSID,1);
485942e3340SBarry Smith   ierr = DMGetDMTSWrite(dm,&tsdm);CHKERRQ(ierr);
486d74926cbSBarry Smith   if (func) tsdm->ops->solution = func;
487ef20d060SBarry Smith   if (ctx)  tsdm->solutionctx   = ctx;
488ef20d060SBarry Smith   PetscFunctionReturn(0);
489ef20d060SBarry Smith }
490ef20d060SBarry Smith 
491ef20d060SBarry Smith #undef __FUNCT__
4929b7cd975SBarry Smith #define __FUNCT__ "DMTSSetForcingFunction"
4939b7cd975SBarry Smith /*@C
4949b7cd975SBarry Smith    DMTSSetForcingFunction - set TS forcing function evaluation function
4959b7cd975SBarry Smith 
4969b7cd975SBarry Smith    Not Collective
4979b7cd975SBarry Smith 
4989b7cd975SBarry Smith    Input Arguments:
4999b7cd975SBarry Smith +  dm - DM to be used with TS
500f8b49ee9SBarry Smith .  f - forcing function evaluation function; see TSForcingFunction
5019b7cd975SBarry Smith -  ctx - context for solution evaluation
5029b7cd975SBarry Smith 
5039b7cd975SBarry Smith    Level: advanced
5049b7cd975SBarry Smith 
5059b7cd975SBarry Smith    Note:
5069b7cd975SBarry Smith    TSSetForcingFunction() is normally used, but it calls this function internally because the user context is actually
5079b7cd975SBarry Smith    associated with the DM.  This makes the interface consistent regardless of whether the user interacts with a DM or
5089b7cd975SBarry Smith    not. If DM took a more central role at some later date, this could become the primary method of setting the residual.
5099b7cd975SBarry Smith 
5109b7cd975SBarry Smith .seealso: DMTSSetContext(), TSSetFunction(), DMTSSetJacobian(), TSSetForcingFunction(), DMTSGetForcingFunction()
5119b7cd975SBarry Smith @*/
512f8b49ee9SBarry Smith PetscErrorCode DMTSSetForcingFunction(DM dm,PetscErrorCode (*f)(TS,PetscReal,Vec,void*),void *ctx)
5139b7cd975SBarry Smith {
5149b7cd975SBarry Smith   PetscErrorCode ierr;
5159b7cd975SBarry Smith   DMTS           tsdm;
5169b7cd975SBarry Smith 
5179b7cd975SBarry Smith   PetscFunctionBegin;
5189b7cd975SBarry Smith   PetscValidHeaderSpecific(dm,DM_CLASSID,1);
5199b7cd975SBarry Smith   ierr = DMGetDMTSWrite(dm,&tsdm);CHKERRQ(ierr);
520f8b49ee9SBarry Smith   if (f) tsdm->ops->forcing = f;
5219b7cd975SBarry Smith   if (ctx)  tsdm->forcingctx   = ctx;
5229b7cd975SBarry Smith   PetscFunctionReturn(0);
5239b7cd975SBarry Smith }
5249b7cd975SBarry Smith 
5259b7cd975SBarry Smith 
5269b7cd975SBarry Smith #undef __FUNCT__
5279b7cd975SBarry Smith #define __FUNCT__ "DMTSGetForcingFunction"
5289b7cd975SBarry Smith /*@C
5299b7cd975SBarry Smith    DMTSGetForcingFunction - get TS forcing function evaluation function
5309b7cd975SBarry Smith 
5319b7cd975SBarry Smith    Not Collective
5329b7cd975SBarry Smith 
5339b7cd975SBarry Smith    Input Argument:
5349b7cd975SBarry Smith .   dm - DM to be used with TS
5359b7cd975SBarry Smith 
5369b7cd975SBarry Smith    Output Arguments:
537f8b49ee9SBarry Smith +  f - forcing function evaluation function; see TSForcingFunction for details
5389b7cd975SBarry Smith -  ctx - context for solution evaluation
5399b7cd975SBarry Smith 
5409b7cd975SBarry Smith    Level: advanced
5419b7cd975SBarry Smith 
5429b7cd975SBarry Smith    Note:
5439b7cd975SBarry Smith    TSSetForcingFunction() is normally used, but it calls this function internally because the user context is actually
5449b7cd975SBarry Smith    associated with the DM.  This makes the interface consistent regardless of whether the user interacts with a DM or
5459b7cd975SBarry Smith    not. If DM took a more central role at some later date, this could become the primary method of setting the residual.
5469b7cd975SBarry Smith 
5479b7cd975SBarry Smith .seealso: DMTSSetContext(), TSSetFunction(), DMTSSetJacobian(), TSSetForcingFunction(), DMTSGetForcingFunction()
5489b7cd975SBarry Smith @*/
549f8b49ee9SBarry Smith PetscErrorCode DMTSGetForcingFunction(DM dm,PetscErrorCode (**f)(TS,PetscReal,Vec,void*),void **ctx)
5509b7cd975SBarry Smith {
5519b7cd975SBarry Smith   PetscErrorCode ierr;
5529b7cd975SBarry Smith   DMTS           tsdm;
5539b7cd975SBarry Smith 
5549b7cd975SBarry Smith   PetscFunctionBegin;
5559b7cd975SBarry Smith   PetscValidHeaderSpecific(dm,DM_CLASSID,1);
5569b7cd975SBarry Smith   ierr = DMGetDMTSWrite(dm,&tsdm);CHKERRQ(ierr);
557f8b49ee9SBarry Smith   if (f) *f = tsdm->ops->forcing;
5589b7cd975SBarry Smith   if (ctx) *ctx = tsdm->forcingctx;
5599b7cd975SBarry Smith   PetscFunctionReturn(0);
5609b7cd975SBarry Smith }
5619b7cd975SBarry Smith 
5629b7cd975SBarry Smith #undef __FUNCT__
56324989b8cSPeter Brune #define __FUNCT__ "DMTSGetRHSFunction"
56424989b8cSPeter Brune /*@C
56524989b8cSPeter Brune    DMTSGetRHSFunction - get TS explicit residual evaluation function
56624989b8cSPeter Brune 
56724989b8cSPeter Brune    Not Collective
56824989b8cSPeter Brune 
56924989b8cSPeter Brune    Input Argument:
57024989b8cSPeter Brune .  dm - DM to be used with TS
57124989b8cSPeter Brune 
57224989b8cSPeter Brune    Output Arguments:
57324989b8cSPeter Brune +  func - residual evaluation function, see TSSetRHSFunction() for calling sequence
57424989b8cSPeter Brune -  ctx - context for residual evaluation
57524989b8cSPeter Brune 
57624989b8cSPeter Brune    Level: advanced
57724989b8cSPeter Brune 
57824989b8cSPeter Brune    Note:
57924989b8cSPeter Brune    TSGetFunction() is normally used, but it calls this function internally because the user context is actually
58024989b8cSPeter Brune    associated with the DM.
58124989b8cSPeter Brune 
58224989b8cSPeter Brune .seealso: DMTSSetContext(), DMTSSetFunction(), TSSetFunction()
58324989b8cSPeter Brune @*/
58424989b8cSPeter Brune PetscErrorCode DMTSGetRHSFunction(DM dm,TSRHSFunction *func,void **ctx)
58524989b8cSPeter Brune {
58624989b8cSPeter Brune   PetscErrorCode ierr;
587942e3340SBarry Smith   DMTS           tsdm;
58824989b8cSPeter Brune 
58924989b8cSPeter Brune   PetscFunctionBegin;
59024989b8cSPeter Brune   PetscValidHeaderSpecific(dm,DM_CLASSID,1);
591942e3340SBarry Smith   ierr = DMGetDMTS(dm,&tsdm);CHKERRQ(ierr);
592d74926cbSBarry Smith   if (func) *func = tsdm->ops->rhsfunction;
59324989b8cSPeter Brune   if (ctx)  *ctx = tsdm->rhsfunctionctx;
59424989b8cSPeter Brune   PetscFunctionReturn(0);
59524989b8cSPeter Brune }
59624989b8cSPeter Brune 
59724989b8cSPeter Brune #undef __FUNCT__
59824989b8cSPeter Brune #define __FUNCT__ "DMTSSetIJacobian"
59924989b8cSPeter Brune /*@C
60024989b8cSPeter Brune    DMTSSetIJacobian - set TS Jacobian evaluation function
60124989b8cSPeter Brune 
60224989b8cSPeter Brune    Not Collective
60324989b8cSPeter Brune 
60424989b8cSPeter Brune    Input Argument:
60524989b8cSPeter Brune +  dm - DM to be used with TS
60624989b8cSPeter Brune .  func - Jacobian evaluation function, see TSSetIJacobian() for calling sequence
60724989b8cSPeter Brune -  ctx - context for residual evaluation
60824989b8cSPeter Brune 
60924989b8cSPeter Brune    Level: advanced
61024989b8cSPeter Brune 
61124989b8cSPeter Brune    Note:
61224989b8cSPeter Brune    TSSetJacobian() is normally used, but it calls this function internally because the user context is actually
61324989b8cSPeter Brune    associated with the DM.  This makes the interface consistent regardless of whether the user interacts with a DM or
61424989b8cSPeter Brune    not. If DM took a more central role at some later date, this could become the primary method of setting the Jacobian.
61524989b8cSPeter Brune 
61624989b8cSPeter Brune .seealso: DMTSSetContext(), TSSetFunction(), DMTSGetJacobian(), TSSetJacobian()
61724989b8cSPeter Brune @*/
61824989b8cSPeter Brune PetscErrorCode DMTSSetIJacobian(DM dm,TSIJacobian func,void *ctx)
61924989b8cSPeter Brune {
62024989b8cSPeter Brune   PetscErrorCode ierr;
621942e3340SBarry Smith   DMTS           sdm;
62224989b8cSPeter Brune 
62324989b8cSPeter Brune   PetscFunctionBegin;
62424989b8cSPeter Brune   PetscValidHeaderSpecific(dm,DM_CLASSID,1);
625942e3340SBarry Smith   ierr = DMGetDMTSWrite(dm,&sdm);CHKERRQ(ierr);
626d74926cbSBarry Smith   if (func) sdm->ops->ijacobian = func;
62724989b8cSPeter Brune   if (ctx)  sdm->ijacobianctx   = ctx;
62824989b8cSPeter Brune   PetscFunctionReturn(0);
62924989b8cSPeter Brune }
63024989b8cSPeter Brune 
63124989b8cSPeter Brune #undef __FUNCT__
63224989b8cSPeter Brune #define __FUNCT__ "DMTSGetIJacobian"
63324989b8cSPeter Brune /*@C
63424989b8cSPeter Brune    DMTSGetIJacobian - get TS Jacobian evaluation function
63524989b8cSPeter Brune 
63624989b8cSPeter Brune    Not Collective
63724989b8cSPeter Brune 
63824989b8cSPeter Brune    Input Argument:
63924989b8cSPeter Brune .  dm - DM to be used with TS
64024989b8cSPeter Brune 
64124989b8cSPeter Brune    Output Arguments:
64224989b8cSPeter Brune +  func - Jacobian evaluation function, see TSSetIJacobian() for calling sequence
64324989b8cSPeter Brune -  ctx - context for residual evaluation
64424989b8cSPeter Brune 
64524989b8cSPeter Brune    Level: advanced
64624989b8cSPeter Brune 
64724989b8cSPeter Brune    Note:
64824989b8cSPeter Brune    TSGetJacobian() is normally used, but it calls this function internally because the user context is actually
64924989b8cSPeter Brune    associated with the DM.  This makes the interface consistent regardless of whether the user interacts with a DM or
65024989b8cSPeter Brune    not. If DM took a more central role at some later date, this could become the primary method of setting the Jacobian.
65124989b8cSPeter Brune 
65224989b8cSPeter Brune .seealso: DMTSSetContext(), TSSetFunction(), DMTSSetJacobian()
65324989b8cSPeter Brune @*/
65424989b8cSPeter Brune PetscErrorCode DMTSGetIJacobian(DM dm,TSIJacobian *func,void **ctx)
65524989b8cSPeter Brune {
65624989b8cSPeter Brune   PetscErrorCode ierr;
657942e3340SBarry Smith   DMTS           tsdm;
65824989b8cSPeter Brune 
65924989b8cSPeter Brune   PetscFunctionBegin;
66024989b8cSPeter Brune   PetscValidHeaderSpecific(dm,DM_CLASSID,1);
661942e3340SBarry Smith   ierr = DMGetDMTS(dm,&tsdm);CHKERRQ(ierr);
662d74926cbSBarry Smith   if (func) *func = tsdm->ops->ijacobian;
66324989b8cSPeter Brune   if (ctx)  *ctx = tsdm->ijacobianctx;
66424989b8cSPeter Brune   PetscFunctionReturn(0);
66524989b8cSPeter Brune }
66624989b8cSPeter Brune 
66724989b8cSPeter Brune 
66824989b8cSPeter Brune #undef __FUNCT__
66924989b8cSPeter Brune #define __FUNCT__ "DMTSSetRHSJacobian"
67024989b8cSPeter Brune /*@C
67124989b8cSPeter Brune    DMTSSetRHSJacobian - set TS Jacobian evaluation function
67224989b8cSPeter Brune 
67324989b8cSPeter Brune    Not Collective
67424989b8cSPeter Brune 
67524989b8cSPeter Brune    Input Argument:
67624989b8cSPeter Brune +  dm - DM to be used with TS
67724989b8cSPeter Brune .  func - Jacobian evaluation function, see TSSetRHSJacobian() for calling sequence
67824989b8cSPeter Brune -  ctx - context for residual evaluation
67924989b8cSPeter Brune 
68024989b8cSPeter Brune    Level: advanced
68124989b8cSPeter Brune 
68224989b8cSPeter Brune    Note:
68324989b8cSPeter Brune    TSSetJacobian() is normally used, but it calls this function internally because the user context is actually
68424989b8cSPeter Brune    associated with the DM.  This makes the interface consistent regardless of whether the user interacts with a DM or
68524989b8cSPeter Brune    not. If DM took a more central role at some later date, this could become the primary method of setting the Jacobian.
68624989b8cSPeter Brune 
68724989b8cSPeter Brune .seealso: DMTSSetContext(), TSSetFunction(), DMTSGetJacobian(), TSSetJacobian()
68824989b8cSPeter Brune @*/
68924989b8cSPeter Brune PetscErrorCode DMTSSetRHSJacobian(DM dm,TSRHSJacobian func,void *ctx)
69024989b8cSPeter Brune {
69124989b8cSPeter Brune   PetscErrorCode ierr;
692942e3340SBarry Smith   DMTS           tsdm;
69324989b8cSPeter Brune 
69424989b8cSPeter Brune   PetscFunctionBegin;
69524989b8cSPeter Brune   PetscValidHeaderSpecific(dm,DM_CLASSID,1);
696942e3340SBarry Smith   ierr = DMGetDMTSWrite(dm,&tsdm);CHKERRQ(ierr);
697d74926cbSBarry Smith   if (func) tsdm->ops->rhsjacobian = func;
69824989b8cSPeter Brune   if (ctx)  tsdm->rhsjacobianctx = ctx;
69924989b8cSPeter Brune   PetscFunctionReturn(0);
70024989b8cSPeter Brune }
70124989b8cSPeter Brune 
70224989b8cSPeter Brune #undef __FUNCT__
70324989b8cSPeter Brune #define __FUNCT__ "DMTSGetRHSJacobian"
70424989b8cSPeter Brune /*@C
70524989b8cSPeter Brune    DMTSGetRHSJacobian - get TS Jacobian evaluation function
70624989b8cSPeter Brune 
70724989b8cSPeter Brune    Not Collective
70824989b8cSPeter Brune 
70924989b8cSPeter Brune    Input Argument:
71024989b8cSPeter Brune .  dm - DM to be used with TS
71124989b8cSPeter Brune 
71224989b8cSPeter Brune    Output Arguments:
71324989b8cSPeter Brune +  func - Jacobian evaluation function, see TSSetRHSJacobian() for calling sequence
71424989b8cSPeter Brune -  ctx - context for residual evaluation
71524989b8cSPeter Brune 
71624989b8cSPeter Brune    Level: advanced
71724989b8cSPeter Brune 
71824989b8cSPeter Brune    Note:
71924989b8cSPeter Brune    TSGetJacobian() is normally used, but it calls this function internally because the user context is actually
72024989b8cSPeter Brune    associated with the DM.  This makes the interface consistent regardless of whether the user interacts with a DM or
72124989b8cSPeter Brune    not. If DM took a more central role at some later date, this could become the primary method of setting the Jacobian.
72224989b8cSPeter Brune 
72324989b8cSPeter Brune .seealso: DMTSSetContext(), TSSetFunction(), DMTSSetJacobian()
72424989b8cSPeter Brune @*/
72524989b8cSPeter Brune PetscErrorCode DMTSGetRHSJacobian(DM dm,TSRHSJacobian *func,void **ctx)
72624989b8cSPeter Brune {
72724989b8cSPeter Brune   PetscErrorCode ierr;
728942e3340SBarry Smith   DMTS           tsdm;
72924989b8cSPeter Brune 
73024989b8cSPeter Brune   PetscFunctionBegin;
73124989b8cSPeter Brune   PetscValidHeaderSpecific(dm,DM_CLASSID,1);
732942e3340SBarry Smith   ierr = DMGetDMTS(dm,&tsdm);CHKERRQ(ierr);
733d74926cbSBarry Smith   if (func) *func = tsdm->ops->rhsjacobian;
73424989b8cSPeter Brune   if (ctx)  *ctx = tsdm->rhsjacobianctx;
73524989b8cSPeter Brune   PetscFunctionReturn(0);
73624989b8cSPeter Brune }
737ad6bc421SBarry Smith 
738ad6bc421SBarry Smith #undef __FUNCT__
739ad6bc421SBarry Smith #define __FUNCT__ "DMTSSetIFunctionSerialize"
740ad6bc421SBarry Smith /*@C
741ad6bc421SBarry Smith    DMTSSetIFunctionSerialize - sets functions used to view and load a IFunction context
742ad6bc421SBarry Smith 
743ad6bc421SBarry Smith    Not Collective
744ad6bc421SBarry Smith 
745ad6bc421SBarry Smith    Input Arguments:
746ad6bc421SBarry Smith +  dm - DM to be used with TS
747ad6bc421SBarry Smith .  view - viewer function
748ad6bc421SBarry Smith -  load - loading function
749ad6bc421SBarry Smith 
750ad6bc421SBarry Smith    Level: advanced
751ad6bc421SBarry Smith 
752ad6bc421SBarry Smith .seealso: DMTSSetContext(), TSSetFunction(), DMTSSetJacobian()
753ad6bc421SBarry Smith @*/
754ad6bc421SBarry Smith PetscErrorCode DMTSSetIFunctionSerialize(DM dm,PetscErrorCode (*view)(void*,PetscViewer),PetscErrorCode (*load)(void**,PetscViewer))
755ad6bc421SBarry Smith {
756ad6bc421SBarry Smith   PetscErrorCode ierr;
757ad6bc421SBarry Smith   DMTS           tsdm;
758ad6bc421SBarry Smith 
759ad6bc421SBarry Smith   PetscFunctionBegin;
760ad6bc421SBarry Smith   PetscValidHeaderSpecific(dm,DM_CLASSID,1);
761ad6bc421SBarry Smith   ierr = DMGetDMTSWrite(dm,&tsdm);CHKERRQ(ierr);
762ad6bc421SBarry Smith   tsdm->ops->ifunctionview = view;
763ad6bc421SBarry Smith   tsdm->ops->ifunctionload = load;
764ad6bc421SBarry Smith   PetscFunctionReturn(0);
765ad6bc421SBarry Smith }
766ad6bc421SBarry Smith 
767ad6bc421SBarry Smith #undef __FUNCT__
768ad6bc421SBarry Smith #define __FUNCT__ "DMTSSetIJacobianSerialize"
769ad6bc421SBarry Smith /*@C
770ad6bc421SBarry Smith    DMTSSetIJacobianSerialize - sets functions used to view and load a IJacobian context
771ad6bc421SBarry Smith 
772ad6bc421SBarry Smith    Not Collective
773ad6bc421SBarry Smith 
774ad6bc421SBarry Smith    Input Arguments:
775ad6bc421SBarry Smith +  dm - DM to be used with TS
776ad6bc421SBarry Smith .  view - viewer function
777ad6bc421SBarry Smith -  load - loading function
778ad6bc421SBarry Smith 
779ad6bc421SBarry Smith    Level: advanced
780ad6bc421SBarry Smith 
781ad6bc421SBarry Smith .seealso: DMTSSetContext(), TSSetFunction(), DMTSSetJacobian()
782ad6bc421SBarry Smith @*/
783ad6bc421SBarry Smith PetscErrorCode DMTSSetIJacobianSerialize(DM dm,PetscErrorCode (*view)(void*,PetscViewer),PetscErrorCode (*load)(void**,PetscViewer))
784ad6bc421SBarry Smith {
785ad6bc421SBarry Smith   PetscErrorCode ierr;
786ad6bc421SBarry Smith   DMTS           tsdm;
787ad6bc421SBarry Smith 
788ad6bc421SBarry Smith   PetscFunctionBegin;
789ad6bc421SBarry Smith   PetscValidHeaderSpecific(dm,DM_CLASSID,1);
790ad6bc421SBarry Smith   ierr = DMGetDMTSWrite(dm,&tsdm);CHKERRQ(ierr);
791ad6bc421SBarry Smith   tsdm->ops->ijacobianview = view;
792ad6bc421SBarry Smith   tsdm->ops->ijacobianload = load;
793ad6bc421SBarry Smith   PetscFunctionReturn(0);
794ad6bc421SBarry Smith }
795