xref: /petsc/src/ts/utils/dmts.c (revision 5c87d4f4e8fa4f8d5c5b55af951006bee0e8748a)
1af0996ceSBarry Smith #include <petsc/private/tsimpl.h>     /*I "petscts.h" I*/
2af0996ceSBarry Smith #include <petsc/private/dmimpl.h>
324989b8cSPeter Brune 
4d74926cbSBarry Smith static PetscErrorCode DMTSDestroy(DMTS *kdm)
5d74926cbSBarry Smith {
6d74926cbSBarry Smith   PetscErrorCode ierr;
7d74926cbSBarry Smith 
8d74926cbSBarry Smith   PetscFunctionBegin;
9d74926cbSBarry Smith   if (!*kdm) PetscFunctionReturn(0);
10d74926cbSBarry Smith   PetscValidHeaderSpecific((*kdm),DMTS_CLASSID,1);
11d74926cbSBarry Smith   if (--((PetscObject)(*kdm))->refct > 0) {*kdm = 0; PetscFunctionReturn(0);}
12d74926cbSBarry Smith   if ((*kdm)->ops->destroy) {ierr = ((*kdm)->ops->destroy)(*kdm);CHKERRQ(ierr);}
13d74926cbSBarry Smith   ierr = PetscHeaderDestroy(kdm);CHKERRQ(ierr);
14d74926cbSBarry Smith   PetscFunctionReturn(0);
15d74926cbSBarry Smith }
16d74926cbSBarry Smith 
172d53ad75SBarry Smith PetscErrorCode DMTSLoad(DMTS kdm,PetscViewer viewer)
182d53ad75SBarry Smith {
192d53ad75SBarry Smith   PetscErrorCode ierr;
202d53ad75SBarry Smith 
212d53ad75SBarry Smith   PetscFunctionBegin;
22060da220SMatthew G. Knepley   ierr = PetscViewerBinaryRead(viewer,&kdm->ops->ifunction,1,NULL,PETSC_FUNCTION);CHKERRQ(ierr);
23060da220SMatthew G. Knepley   ierr = PetscViewerBinaryRead(viewer,&kdm->ops->ifunctionview,1,NULL,PETSC_FUNCTION);CHKERRQ(ierr);
24060da220SMatthew G. Knepley   ierr = PetscViewerBinaryRead(viewer,&kdm->ops->ifunctionload,1,NULL,PETSC_FUNCTION);CHKERRQ(ierr);
25ad6bc421SBarry Smith   if (kdm->ops->ifunctionload) {
26ad6bc421SBarry Smith     ierr = (*kdm->ops->ifunctionload)(&kdm->ifunctionctx,viewer);CHKERRQ(ierr);
27ad6bc421SBarry Smith   }
28060da220SMatthew G. Knepley   ierr = PetscViewerBinaryRead(viewer,&kdm->ops->ijacobian,1,NULL,PETSC_FUNCTION);CHKERRQ(ierr);
29060da220SMatthew G. Knepley   ierr = PetscViewerBinaryRead(viewer,&kdm->ops->ijacobianview,1,NULL,PETSC_FUNCTION);CHKERRQ(ierr);
30060da220SMatthew G. Knepley   ierr = PetscViewerBinaryRead(viewer,&kdm->ops->ijacobianload,1,NULL,PETSC_FUNCTION);CHKERRQ(ierr);
31ad6bc421SBarry Smith   if (kdm->ops->ijacobianload) {
32ad6bc421SBarry Smith     ierr = (*kdm->ops->ijacobianload)(&kdm->ijacobianctx,viewer);CHKERRQ(ierr);
33ad6bc421SBarry Smith   }
342d53ad75SBarry Smith   PetscFunctionReturn(0);
352d53ad75SBarry Smith }
362d53ad75SBarry Smith 
372d53ad75SBarry Smith PetscErrorCode DMTSView(DMTS kdm,PetscViewer viewer)
382d53ad75SBarry Smith {
392d53ad75SBarry Smith   PetscErrorCode ierr;
402d53ad75SBarry Smith   PetscBool      isascii,isbinary;
412d53ad75SBarry Smith 
422d53ad75SBarry Smith   PetscFunctionBegin;
432d53ad75SBarry Smith   ierr = PetscObjectTypeCompare((PetscObject)viewer,PETSCVIEWERASCII,&isascii);CHKERRQ(ierr);
442d53ad75SBarry Smith   ierr = PetscObjectTypeCompare((PetscObject)viewer,PETSCVIEWERBINARY,&isbinary);CHKERRQ(ierr);
452d53ad75SBarry Smith   if (isascii) {
46c7a10e08SBarry Smith #if defined(PETSC_SERIALIZE_FUNCTIONS)
472d53ad75SBarry Smith     const char *fname;
482d53ad75SBarry Smith 
492d53ad75SBarry Smith     ierr = PetscFPTFind(kdm->ops->ifunction,&fname);CHKERRQ(ierr);
502d53ad75SBarry Smith     if (fname) {
512d53ad75SBarry Smith       ierr = PetscViewerASCIIPrintf(viewer,"  IFunction used by TS: %s\n",fname);CHKERRQ(ierr);
522d53ad75SBarry Smith     }
532d53ad75SBarry Smith     ierr = PetscFPTFind(kdm->ops->ijacobian,&fname);CHKERRQ(ierr);
542d53ad75SBarry Smith     if (fname) {
552d53ad75SBarry Smith       ierr = PetscViewerASCIIPrintf(viewer,"  IJacobian function used by TS: %s\n",fname);CHKERRQ(ierr);
562d53ad75SBarry Smith     }
57c7a10e08SBarry Smith #endif
582d53ad75SBarry Smith   } else if (isbinary) {
593964eb88SJed Brown     struct {
603964eb88SJed Brown       TSIFunction ifunction;
619200755eSBarry Smith     } funcstruct;
629200755eSBarry Smith     struct {
633964eb88SJed Brown       PetscErrorCode (*ifunctionview)(void*,PetscViewer);
649200755eSBarry Smith     } funcviewstruct;
659200755eSBarry Smith     struct {
663964eb88SJed Brown       PetscErrorCode (*ifunctionload)(void**,PetscViewer);
679200755eSBarry Smith     } funcloadstruct;
683964eb88SJed Brown     struct {
693964eb88SJed Brown       TSIJacobian ijacobian;
709200755eSBarry Smith     } jacstruct;
719200755eSBarry Smith     struct {
723964eb88SJed Brown       PetscErrorCode (*ijacobianview)(void*,PetscViewer);
739200755eSBarry Smith     } jacviewstruct;
749200755eSBarry Smith     struct {
753964eb88SJed Brown       PetscErrorCode (*ijacobianload)(void**,PetscViewer);
769200755eSBarry Smith     } jacloadstruct;
773964eb88SJed Brown 
789200755eSBarry Smith     funcstruct.ifunction         = kdm->ops->ifunction;
799200755eSBarry Smith     funcviewstruct.ifunctionview = kdm->ops->ifunctionview;
809200755eSBarry Smith     funcloadstruct.ifunctionload = kdm->ops->ifunctionload;
819200755eSBarry Smith     ierr = PetscViewerBinaryWrite(viewer,&funcstruct,1,PETSC_FUNCTION,PETSC_FALSE);CHKERRQ(ierr);
829200755eSBarry Smith     ierr = PetscViewerBinaryWrite(viewer,&funcviewstruct,1,PETSC_FUNCTION,PETSC_FALSE);CHKERRQ(ierr);
839200755eSBarry Smith     ierr = PetscViewerBinaryWrite(viewer,&funcloadstruct,1,PETSC_FUNCTION,PETSC_FALSE);CHKERRQ(ierr);
84ad6bc421SBarry Smith     if (kdm->ops->ifunctionview) {
85ad6bc421SBarry Smith       ierr = (*kdm->ops->ifunctionview)(kdm->ifunctionctx,viewer);CHKERRQ(ierr);
86ad6bc421SBarry Smith     }
879200755eSBarry Smith     jacstruct.ijacobian = kdm->ops->ijacobian;
889200755eSBarry Smith     jacviewstruct.ijacobianview = kdm->ops->ijacobianview;
899200755eSBarry Smith     jacloadstruct.ijacobianload = kdm->ops->ijacobianload;
909200755eSBarry Smith     ierr = PetscViewerBinaryWrite(viewer,&jacstruct,1,PETSC_FUNCTION,PETSC_FALSE);CHKERRQ(ierr);
919200755eSBarry Smith     ierr = PetscViewerBinaryWrite(viewer,&jacviewstruct,1,PETSC_FUNCTION,PETSC_FALSE);CHKERRQ(ierr);
929200755eSBarry Smith     ierr = PetscViewerBinaryWrite(viewer,&jacloadstruct,1,PETSC_FUNCTION,PETSC_FALSE);CHKERRQ(ierr);
93ad6bc421SBarry Smith     if (kdm->ops->ijacobianview) {
94ad6bc421SBarry Smith       ierr = (*kdm->ops->ijacobianview)(kdm->ijacobianctx,viewer);CHKERRQ(ierr);
95ad6bc421SBarry Smith     }
962d53ad75SBarry Smith   }
972d53ad75SBarry Smith   PetscFunctionReturn(0);
982d53ad75SBarry Smith }
992d53ad75SBarry Smith 
100d74926cbSBarry Smith static PetscErrorCode DMTSCreate(MPI_Comm comm,DMTS *kdm)
101d74926cbSBarry Smith {
102d74926cbSBarry Smith   PetscErrorCode ierr;
103d74926cbSBarry Smith 
104d74926cbSBarry Smith   PetscFunctionBegin;
105607a6623SBarry Smith   ierr = TSInitializePackage();CHKERRQ(ierr);
10673107ff1SLisandro Dalcin   ierr = PetscHeaderCreate(*kdm, DMTS_CLASSID, "DMTS", "DMTS", "DMTS", comm, DMTSDestroy, DMTSView);CHKERRQ(ierr);
107d74926cbSBarry Smith   PetscFunctionReturn(0);
108d74926cbSBarry Smith }
10924989b8cSPeter Brune 
1102a34c10cSBarry Smith /* Attaches the DMTS to the coarse level.
11124989b8cSPeter Brune  * Under what conditions should we copy versus duplicate?
11224989b8cSPeter Brune  */
113942e3340SBarry Smith static PetscErrorCode DMCoarsenHook_DMTS(DM dm,DM dmc,void *ctx)
11424989b8cSPeter Brune {
11524989b8cSPeter Brune   PetscErrorCode ierr;
11624989b8cSPeter Brune 
11724989b8cSPeter Brune   PetscFunctionBegin;
118942e3340SBarry Smith   ierr = DMCopyDMTS(dm,dmc);CHKERRQ(ierr);
11924989b8cSPeter Brune   PetscFunctionReturn(0);
12024989b8cSPeter Brune }
12124989b8cSPeter Brune 
12224989b8cSPeter Brune /* This could restrict auxiliary information to the coarse level.
12324989b8cSPeter Brune  */
124942e3340SBarry Smith static PetscErrorCode DMRestrictHook_DMTS(DM dm,Mat Restrict,Vec rscale,Mat Inject,DM dmc,void *ctx)
12524989b8cSPeter Brune {
12624989b8cSPeter Brune 
12724989b8cSPeter Brune   PetscFunctionBegin;
12824989b8cSPeter Brune   PetscFunctionReturn(0);
12924989b8cSPeter Brune }
13024989b8cSPeter Brune 
131258e1594SPeter Brune static PetscErrorCode DMSubDomainHook_DMTS(DM dm,DM subdm,void *ctx)
132258e1594SPeter Brune {
133258e1594SPeter Brune   PetscErrorCode ierr;
134258e1594SPeter Brune 
135258e1594SPeter Brune   PetscFunctionBegin;
136258e1594SPeter Brune   ierr = DMCopyDMTS(dm,subdm);CHKERRQ(ierr);
137258e1594SPeter Brune   PetscFunctionReturn(0);
138258e1594SPeter Brune }
139258e1594SPeter Brune 
140258e1594SPeter Brune /* This could restrict auxiliary information to the coarse level.
141258e1594SPeter Brune  */
142258e1594SPeter Brune static PetscErrorCode DMSubDomainRestrictHook_DMTS(DM dm,VecScatter gscat,VecScatter lscat,DM subdm,void *ctx)
143258e1594SPeter Brune {
144258e1594SPeter Brune   PetscFunctionBegin;
145258e1594SPeter Brune   PetscFunctionReturn(0);
146258e1594SPeter Brune }
147258e1594SPeter Brune 
148d74926cbSBarry Smith /*@C
149d74926cbSBarry Smith    DMTSCopy - copies the information in a DMTS to another DMTS
150d74926cbSBarry Smith 
151d74926cbSBarry Smith    Not Collective
152d74926cbSBarry Smith 
153d74926cbSBarry Smith    Input Argument:
154d74926cbSBarry Smith +  kdm - Original DMTS
155d74926cbSBarry Smith -  nkdm - DMTS to receive the data, should have been created with DMTSCreate()
156d74926cbSBarry Smith 
157d74926cbSBarry Smith    Level: developer
158d74926cbSBarry Smith 
159d74926cbSBarry Smith .seealso: DMTSCreate(), DMTSDestroy()
160d74926cbSBarry Smith @*/
161d74926cbSBarry Smith PetscErrorCode DMTSCopy(DMTS kdm,DMTS nkdm)
16224989b8cSPeter Brune {
16324989b8cSPeter Brune   PetscErrorCode ierr;
16424989b8cSPeter Brune 
16524989b8cSPeter Brune   PetscFunctionBegin;
166d74926cbSBarry Smith   PetscValidHeaderSpecific(kdm,DMTS_CLASSID,1);
167d74926cbSBarry Smith   PetscValidHeaderSpecific(nkdm,DMTS_CLASSID,2);
168d74926cbSBarry Smith   nkdm->ops->rhsfunction = kdm->ops->rhsfunction;
169d74926cbSBarry Smith   nkdm->ops->rhsjacobian = kdm->ops->rhsjacobian;
170d74926cbSBarry Smith   nkdm->ops->ifunction   = kdm->ops->ifunction;
171d74926cbSBarry Smith   nkdm->ops->ijacobian   = kdm->ops->ijacobian;
172efe9872eSLisandro Dalcin   nkdm->ops->i2function  = kdm->ops->i2function;
173efe9872eSLisandro Dalcin   nkdm->ops->i2jacobian  = kdm->ops->i2jacobian;
174d74926cbSBarry Smith   nkdm->ops->solution    = kdm->ops->solution;
175d74926cbSBarry Smith   nkdm->ops->destroy     = kdm->ops->destroy;
176d74926cbSBarry Smith   nkdm->ops->duplicate   = kdm->ops->duplicate;
177d74926cbSBarry Smith 
178d74926cbSBarry Smith   nkdm->rhsfunctionctx = kdm->rhsfunctionctx;
179d74926cbSBarry Smith   nkdm->rhsjacobianctx = kdm->rhsjacobianctx;
180d74926cbSBarry Smith   nkdm->ifunctionctx   = kdm->ifunctionctx;
181d74926cbSBarry Smith   nkdm->ijacobianctx   = kdm->ijacobianctx;
182efe9872eSLisandro Dalcin   nkdm->i2functionctx  = kdm->i2functionctx;
183efe9872eSLisandro Dalcin   nkdm->i2jacobianctx  = kdm->i2jacobianctx;
184d74926cbSBarry Smith   nkdm->solutionctx    = kdm->solutionctx;
185d74926cbSBarry Smith 
186d74926cbSBarry Smith   nkdm->data = kdm->data;
187d74926cbSBarry Smith 
188d74926cbSBarry Smith   /*
189d74926cbSBarry Smith   nkdm->fortran_func_pointers[0] = kdm->fortran_func_pointers[0];
190d74926cbSBarry Smith   nkdm->fortran_func_pointers[1] = kdm->fortran_func_pointers[1];
191d74926cbSBarry Smith   nkdm->fortran_func_pointers[2] = kdm->fortran_func_pointers[2];
192d74926cbSBarry Smith   */
193d74926cbSBarry Smith 
194d74926cbSBarry Smith   /* implementation specific copy hooks */
195d74926cbSBarry Smith   if (kdm->ops->duplicate) {ierr = (*kdm->ops->duplicate)(kdm,nkdm);CHKERRQ(ierr);}
19624989b8cSPeter Brune   PetscFunctionReturn(0);
19724989b8cSPeter Brune }
19824989b8cSPeter Brune 
19924989b8cSPeter Brune /*@C
200942e3340SBarry Smith    DMGetDMTS - get read-only private DMTS context from a DM
20124989b8cSPeter Brune 
20224989b8cSPeter Brune    Not Collective
20324989b8cSPeter Brune 
20424989b8cSPeter Brune    Input Argument:
20524989b8cSPeter Brune .  dm - DM to be used with TS
20624989b8cSPeter Brune 
20724989b8cSPeter Brune    Output Argument:
208942e3340SBarry Smith .  tsdm - private DMTS context
20924989b8cSPeter Brune 
21024989b8cSPeter Brune    Level: developer
21124989b8cSPeter Brune 
21224989b8cSPeter Brune    Notes:
213942e3340SBarry Smith    Use DMGetDMTSWrite() if write access is needed. The DMTSSetXXX API should be used wherever possible.
21424989b8cSPeter Brune 
215942e3340SBarry Smith .seealso: DMGetDMTSWrite()
21624989b8cSPeter Brune @*/
217942e3340SBarry Smith PetscErrorCode DMGetDMTS(DM dm,DMTS *tsdm)
21824989b8cSPeter Brune {
21924989b8cSPeter Brune   PetscErrorCode ierr;
22024989b8cSPeter Brune 
22124989b8cSPeter Brune   PetscFunctionBegin;
22224989b8cSPeter Brune   PetscValidHeaderSpecific(dm,DM_CLASSID,1);
2232a34c10cSBarry Smith   *tsdm = (DMTS) dm->dmts;
224d74926cbSBarry Smith   if (!*tsdm) {
225942e3340SBarry Smith     ierr = PetscInfo(dm,"Creating new DMTS\n");CHKERRQ(ierr);
226ce94432eSBarry Smith     ierr = DMTSCreate(PetscObjectComm((PetscObject)dm),tsdm);CHKERRQ(ierr);
2272a34c10cSBarry Smith     dm->dmts = (PetscObject) *tsdm;
228*5c87d4f4SJunchao Zhang     (*tsdm)->originaldm = dm;
2290298fd71SBarry Smith     ierr = DMCoarsenHookAdd(dm,DMCoarsenHook_DMTS,DMRestrictHook_DMTS,NULL);CHKERRQ(ierr);
2300298fd71SBarry Smith     ierr = DMSubDomainHookAdd(dm,DMSubDomainHook_DMTS,DMSubDomainRestrictHook_DMTS,NULL);CHKERRQ(ierr);
23124989b8cSPeter Brune   }
23224989b8cSPeter Brune   PetscFunctionReturn(0);
23324989b8cSPeter Brune }
23424989b8cSPeter Brune 
23524989b8cSPeter Brune /*@C
236942e3340SBarry Smith    DMGetDMTSWrite - get write access to private DMTS context from a DM
23724989b8cSPeter Brune 
23824989b8cSPeter Brune    Not Collective
23924989b8cSPeter Brune 
24024989b8cSPeter Brune    Input Argument:
24124989b8cSPeter Brune .  dm - DM to be used with TS
24224989b8cSPeter Brune 
24324989b8cSPeter Brune    Output Argument:
244942e3340SBarry Smith .  tsdm - private DMTS context
24524989b8cSPeter Brune 
24624989b8cSPeter Brune    Level: developer
24724989b8cSPeter Brune 
248942e3340SBarry Smith .seealso: DMGetDMTS()
24924989b8cSPeter Brune @*/
250942e3340SBarry Smith PetscErrorCode DMGetDMTSWrite(DM dm,DMTS *tsdm)
25124989b8cSPeter Brune {
25224989b8cSPeter Brune   PetscErrorCode ierr;
253942e3340SBarry Smith   DMTS           sdm;
25424989b8cSPeter Brune 
25524989b8cSPeter Brune   PetscFunctionBegin;
25624989b8cSPeter Brune   PetscValidHeaderSpecific(dm,DM_CLASSID,1);
257942e3340SBarry Smith   ierr = DMGetDMTS(dm,&sdm);CHKERRQ(ierr);
258*5c87d4f4SJunchao Zhang   if (!sdm->originaldm) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_WRONGSTATE,"DMTS has a NULL originaldm");
25924989b8cSPeter Brune   if (sdm->originaldm != dm) {  /* Copy on write */
2602a34c10cSBarry Smith     DMTS oldsdm = sdm;
261942e3340SBarry Smith     ierr     = PetscInfo(dm,"Copying DMTS due to write\n");CHKERRQ(ierr);
262ce94432eSBarry Smith     ierr     = DMTSCreate(PetscObjectComm((PetscObject)dm),&sdm);CHKERRQ(ierr);
263d74926cbSBarry Smith     ierr     = DMTSCopy(oldsdm,sdm);CHKERRQ(ierr);
2642a34c10cSBarry Smith     ierr     = DMTSDestroy((DMTS*)&dm->dmts);CHKERRQ(ierr);
2652a34c10cSBarry Smith     dm->dmts = (PetscObject) sdm;
266*5c87d4f4SJunchao Zhang     sdm->originaldm = dm;
26724989b8cSPeter Brune   }
26824989b8cSPeter Brune   *tsdm = sdm;
26924989b8cSPeter Brune   PetscFunctionReturn(0);
27024989b8cSPeter Brune }
27124989b8cSPeter Brune 
27224989b8cSPeter Brune /*@C
273942e3340SBarry Smith    DMCopyDMTS - copies a DM context to a new DM
27424989b8cSPeter Brune 
27524989b8cSPeter Brune    Logically Collective
27624989b8cSPeter Brune 
27724989b8cSPeter Brune    Input Arguments:
27824989b8cSPeter Brune +  dmsrc - DM to obtain context from
27924989b8cSPeter Brune -  dmdest - DM to add context to
28024989b8cSPeter Brune 
28124989b8cSPeter Brune    Level: developer
28224989b8cSPeter Brune 
28324989b8cSPeter Brune    Note:
28424989b8cSPeter Brune    The context is copied by reference. This function does not ensure that a context exists.
28524989b8cSPeter Brune 
286942e3340SBarry Smith .seealso: DMGetDMTS(), TSSetDM()
28724989b8cSPeter Brune @*/
288942e3340SBarry Smith PetscErrorCode DMCopyDMTS(DM dmsrc,DM dmdest)
28924989b8cSPeter Brune {
29024989b8cSPeter Brune   PetscErrorCode ierr;
29124989b8cSPeter Brune 
29224989b8cSPeter Brune   PetscFunctionBegin;
29324989b8cSPeter Brune   PetscValidHeaderSpecific(dmsrc,DM_CLASSID,1);
29424989b8cSPeter Brune   PetscValidHeaderSpecific(dmdest,DM_CLASSID,2);
2952a34c10cSBarry Smith   ierr         = DMTSDestroy((DMTS*)&dmdest->dmts);CHKERRQ(ierr);
2962a34c10cSBarry Smith   dmdest->dmts = dmsrc->dmts;
2972a34c10cSBarry Smith   ierr         = PetscObjectReference(dmdest->dmts);CHKERRQ(ierr);
2980298fd71SBarry Smith   ierr         = DMCoarsenHookAdd(dmdest,DMCoarsenHook_DMTS,DMRestrictHook_DMTS,NULL);CHKERRQ(ierr);
2990298fd71SBarry Smith   ierr         = DMSubDomainHookAdd(dmdest,DMSubDomainHook_DMTS,DMSubDomainRestrictHook_DMTS,NULL);CHKERRQ(ierr);
30024989b8cSPeter Brune   PetscFunctionReturn(0);
30124989b8cSPeter Brune }
30224989b8cSPeter Brune 
30324989b8cSPeter Brune /*@C
30424989b8cSPeter Brune    DMTSSetIFunction - set TS implicit function evaluation function
30524989b8cSPeter Brune 
30624989b8cSPeter Brune    Not Collective
30724989b8cSPeter Brune 
30824989b8cSPeter Brune    Input Arguments:
30924989b8cSPeter Brune +  dm - DM to be used with TS
31024989b8cSPeter Brune .  func - function evaluation function, see TSSetIFunction() for calling sequence
31124989b8cSPeter Brune -  ctx - context for residual evaluation
31224989b8cSPeter Brune 
31324989b8cSPeter Brune    Level: advanced
31424989b8cSPeter Brune 
31524989b8cSPeter Brune    Note:
31624989b8cSPeter Brune    TSSetFunction() is normally used, but it calls this function internally because the user context is actually
31724989b8cSPeter Brune    associated with the DM.  This makes the interface consistent regardless of whether the user interacts with a DM or
31824989b8cSPeter Brune    not. If DM took a more central role at some later date, this could become the primary method of setting the residual.
31924989b8cSPeter Brune 
32024989b8cSPeter Brune .seealso: DMTSSetContext(), TSSetFunction(), DMTSSetJacobian()
32124989b8cSPeter Brune @*/
32224989b8cSPeter Brune PetscErrorCode DMTSSetIFunction(DM dm,TSIFunction func,void *ctx)
32324989b8cSPeter Brune {
32424989b8cSPeter Brune   PetscErrorCode ierr;
325942e3340SBarry Smith   DMTS           tsdm;
32624989b8cSPeter Brune 
32724989b8cSPeter Brune   PetscFunctionBegin;
32824989b8cSPeter Brune   PetscValidHeaderSpecific(dm,DM_CLASSID,1);
329942e3340SBarry Smith   ierr = DMGetDMTSWrite(dm,&tsdm);CHKERRQ(ierr);
330d74926cbSBarry Smith   if (func) tsdm->ops->ifunction = func;
33124989b8cSPeter Brune   if (ctx)  tsdm->ifunctionctx = ctx;
33224989b8cSPeter Brune   PetscFunctionReturn(0);
33324989b8cSPeter Brune }
33424989b8cSPeter Brune 
33524989b8cSPeter Brune /*@C
33624989b8cSPeter Brune    DMTSGetIFunction - get TS implicit residual evaluation function
33724989b8cSPeter Brune 
33824989b8cSPeter Brune    Not Collective
33924989b8cSPeter Brune 
34024989b8cSPeter Brune    Input Argument:
34124989b8cSPeter Brune .  dm - DM to be used with TS
34224989b8cSPeter Brune 
34324989b8cSPeter Brune    Output Arguments:
34424989b8cSPeter Brune +  func - function evaluation function, see TSSetIFunction() for calling sequence
34524989b8cSPeter Brune -  ctx - context for residual evaluation
34624989b8cSPeter Brune 
34724989b8cSPeter Brune    Level: advanced
34824989b8cSPeter Brune 
34924989b8cSPeter Brune    Note:
35024989b8cSPeter Brune    TSGetFunction() is normally used, but it calls this function internally because the user context is actually
35124989b8cSPeter Brune    associated with the DM.
35224989b8cSPeter Brune 
35324989b8cSPeter Brune .seealso: DMTSSetContext(), DMTSSetFunction(), TSSetFunction()
35424989b8cSPeter Brune @*/
35524989b8cSPeter Brune PetscErrorCode DMTSGetIFunction(DM dm,TSIFunction *func,void **ctx)
35624989b8cSPeter Brune {
35724989b8cSPeter Brune   PetscErrorCode ierr;
358942e3340SBarry Smith   DMTS           tsdm;
35924989b8cSPeter Brune 
36024989b8cSPeter Brune   PetscFunctionBegin;
36124989b8cSPeter Brune   PetscValidHeaderSpecific(dm,DM_CLASSID,1);
362942e3340SBarry Smith   ierr = DMGetDMTS(dm,&tsdm);CHKERRQ(ierr);
363d74926cbSBarry Smith   if (func) *func = tsdm->ops->ifunction;
36424989b8cSPeter Brune   if (ctx)  *ctx = tsdm->ifunctionctx;
36524989b8cSPeter Brune   PetscFunctionReturn(0);
36624989b8cSPeter Brune }
36724989b8cSPeter Brune 
368efe9872eSLisandro Dalcin /*@C
369efe9872eSLisandro Dalcin    DMTSSetI2Function - set TS implicit function evaluation function for 2nd order systems
370efe9872eSLisandro Dalcin 
371efe9872eSLisandro Dalcin    Not Collective
372efe9872eSLisandro Dalcin 
373efe9872eSLisandro Dalcin    Input Arguments:
374efe9872eSLisandro Dalcin +  dm - DM to be used with TS
375efe9872eSLisandro Dalcin .  fun - function evaluation function, see TSSetI2Function() for calling sequence
376efe9872eSLisandro Dalcin -  ctx - context for residual evaluation
377efe9872eSLisandro Dalcin 
378efe9872eSLisandro Dalcin    Level: advanced
379efe9872eSLisandro Dalcin 
380efe9872eSLisandro Dalcin    Note:
381efe9872eSLisandro Dalcin    TSSetI2Function() is normally used, but it calls this function internally because the user context is actually
382efe9872eSLisandro Dalcin    associated with the DM.
383efe9872eSLisandro Dalcin 
384efe9872eSLisandro Dalcin .seealso: TSSetI2Function()
385efe9872eSLisandro Dalcin @*/
386efe9872eSLisandro Dalcin PetscErrorCode DMTSSetI2Function(DM dm,TSI2Function fun,void *ctx)
387efe9872eSLisandro Dalcin {
388efe9872eSLisandro Dalcin   DMTS           tsdm;
389efe9872eSLisandro Dalcin   PetscErrorCode ierr;
390efe9872eSLisandro Dalcin 
391efe9872eSLisandro Dalcin   PetscFunctionBegin;
392efe9872eSLisandro Dalcin   PetscValidHeaderSpecific(dm,DM_CLASSID,1);
393efe9872eSLisandro Dalcin   ierr = DMGetDMTSWrite(dm,&tsdm);CHKERRQ(ierr);
394efe9872eSLisandro Dalcin   if (fun) tsdm->ops->i2function = fun;
395efe9872eSLisandro Dalcin   if (ctx) tsdm->i2functionctx   = ctx;
396efe9872eSLisandro Dalcin   PetscFunctionReturn(0);
397efe9872eSLisandro Dalcin }
398efe9872eSLisandro Dalcin 
399efe9872eSLisandro Dalcin /*@C
400efe9872eSLisandro Dalcin    DMTSGetI2Function - get TS implicit residual evaluation function for 2nd order systems
401efe9872eSLisandro Dalcin 
402efe9872eSLisandro Dalcin    Not Collective
403efe9872eSLisandro Dalcin 
404efe9872eSLisandro Dalcin    Input Argument:
405efe9872eSLisandro Dalcin .  dm - DM to be used with TS
406efe9872eSLisandro Dalcin 
407efe9872eSLisandro Dalcin    Output Arguments:
408efe9872eSLisandro Dalcin +  fun - function evaluation function, see TSSetI2Function() for calling sequence
409efe9872eSLisandro Dalcin -  ctx - context for residual evaluation
410efe9872eSLisandro Dalcin 
411efe9872eSLisandro Dalcin    Level: advanced
412efe9872eSLisandro Dalcin 
413efe9872eSLisandro Dalcin    Note:
414efe9872eSLisandro Dalcin    TSGetI2Function() is normally used, but it calls this function internally because the user context is actually
415efe9872eSLisandro Dalcin    associated with the DM.
416efe9872eSLisandro Dalcin 
417efe9872eSLisandro Dalcin .seealso: DMTSSetI2Function(),TSGetI2Function()
418efe9872eSLisandro Dalcin @*/
419efe9872eSLisandro Dalcin PetscErrorCode DMTSGetI2Function(DM dm,TSI2Function *fun,void **ctx)
420efe9872eSLisandro Dalcin {
421efe9872eSLisandro Dalcin   DMTS           tsdm;
422efe9872eSLisandro Dalcin   PetscErrorCode ierr;
423efe9872eSLisandro Dalcin 
424efe9872eSLisandro Dalcin   PetscFunctionBegin;
425efe9872eSLisandro Dalcin   PetscValidHeaderSpecific(dm,DM_CLASSID,1);
426efe9872eSLisandro Dalcin   ierr = DMGetDMTS(dm,&tsdm);CHKERRQ(ierr);
427efe9872eSLisandro Dalcin   if (fun) *fun = tsdm->ops->i2function;
428efe9872eSLisandro Dalcin   if (ctx) *ctx = tsdm->i2functionctx;
429efe9872eSLisandro Dalcin   PetscFunctionReturn(0);
430efe9872eSLisandro Dalcin }
431efe9872eSLisandro Dalcin 
432efe9872eSLisandro Dalcin /*@C
433efe9872eSLisandro Dalcin    DMTSSetI2Jacobian - set TS implicit Jacobian evaluation function for 2nd order systems
434efe9872eSLisandro Dalcin 
435efe9872eSLisandro Dalcin    Not Collective
436efe9872eSLisandro Dalcin 
437efe9872eSLisandro Dalcin    Input Arguments:
438efe9872eSLisandro Dalcin +  dm - DM to be used with TS
439efe9872eSLisandro Dalcin .  fun - Jacobian evaluation function, see TSSetI2Jacobian() for calling sequence
440efe9872eSLisandro Dalcin -  ctx - context for Jacobian evaluation
441efe9872eSLisandro Dalcin 
442efe9872eSLisandro Dalcin    Level: advanced
443efe9872eSLisandro Dalcin 
444efe9872eSLisandro Dalcin    Note:
445efe9872eSLisandro Dalcin    TSSetI2Jacobian() is normally used, but it calls this function internally because the user context is actually
446efe9872eSLisandro Dalcin    associated with the DM.
447efe9872eSLisandro Dalcin 
448efe9872eSLisandro Dalcin .seealso: TSSetI2Jacobian()
449efe9872eSLisandro Dalcin @*/
450efe9872eSLisandro Dalcin PetscErrorCode DMTSSetI2Jacobian(DM dm,TSI2Jacobian jac,void *ctx)
451efe9872eSLisandro Dalcin {
452efe9872eSLisandro Dalcin   DMTS           tsdm;
453efe9872eSLisandro Dalcin   PetscErrorCode ierr;
454efe9872eSLisandro Dalcin 
455efe9872eSLisandro Dalcin   PetscFunctionBegin;
456efe9872eSLisandro Dalcin   PetscValidHeaderSpecific(dm,DM_CLASSID,1);
457efe9872eSLisandro Dalcin   ierr = DMGetDMTSWrite(dm,&tsdm);CHKERRQ(ierr);
458efe9872eSLisandro Dalcin   if (jac) tsdm->ops->i2jacobian = jac;
459efe9872eSLisandro Dalcin   if (ctx) tsdm->i2jacobianctx   = ctx;
460efe9872eSLisandro Dalcin   PetscFunctionReturn(0);
461efe9872eSLisandro Dalcin }
462efe9872eSLisandro Dalcin 
463efe9872eSLisandro Dalcin /*@C
464efe9872eSLisandro Dalcin    DMTSGetI2Jacobian - get TS implicit Jacobian evaluation function for 2nd order systems
465efe9872eSLisandro Dalcin 
466efe9872eSLisandro Dalcin    Not Collective
467efe9872eSLisandro Dalcin 
468efe9872eSLisandro Dalcin    Input Argument:
469efe9872eSLisandro Dalcin .  dm - DM to be used with TS
470efe9872eSLisandro Dalcin 
471efe9872eSLisandro Dalcin    Output Arguments:
472efe9872eSLisandro Dalcin +  jac - Jacobian evaluation function, see TSSetI2Jacobian() for calling sequence
473efe9872eSLisandro Dalcin -  ctx - context for Jacobian evaluation
474efe9872eSLisandro Dalcin 
475efe9872eSLisandro Dalcin    Level: advanced
476efe9872eSLisandro Dalcin 
477efe9872eSLisandro Dalcin    Note:
478efe9872eSLisandro Dalcin    TSGetI2Jacobian() is normally used, but it calls this function internally because the user context is actually
479efe9872eSLisandro Dalcin    associated with the DM.
480efe9872eSLisandro Dalcin 
481efe9872eSLisandro Dalcin .seealso: DMTSSetI2Jacobian(),TSGetI2Jacobian()
482efe9872eSLisandro Dalcin @*/
483efe9872eSLisandro Dalcin PetscErrorCode DMTSGetI2Jacobian(DM dm,TSI2Jacobian *jac,void **ctx)
484efe9872eSLisandro Dalcin {
485efe9872eSLisandro Dalcin   DMTS           tsdm;
486efe9872eSLisandro Dalcin   PetscErrorCode ierr;
487efe9872eSLisandro Dalcin 
488efe9872eSLisandro Dalcin   PetscFunctionBegin;
489efe9872eSLisandro Dalcin   PetscValidHeaderSpecific(dm,DM_CLASSID,1);
490efe9872eSLisandro Dalcin   ierr = DMGetDMTS(dm,&tsdm);CHKERRQ(ierr);
491efe9872eSLisandro Dalcin   if (jac) *jac = tsdm->ops->i2jacobian;
492efe9872eSLisandro Dalcin   if (ctx) *ctx = tsdm->i2jacobianctx;
493efe9872eSLisandro Dalcin   PetscFunctionReturn(0);
494efe9872eSLisandro Dalcin }
49524989b8cSPeter Brune 
49624989b8cSPeter Brune /*@C
49724989b8cSPeter Brune    DMTSSetRHSFunction - set TS explicit residual evaluation function
49824989b8cSPeter Brune 
49924989b8cSPeter Brune    Not Collective
50024989b8cSPeter Brune 
50124989b8cSPeter Brune    Input Arguments:
50224989b8cSPeter Brune +  dm - DM to be used with TS
50324989b8cSPeter Brune .  func - RHS function evaluation function, see TSSetRHSFunction() for calling sequence
50424989b8cSPeter Brune -  ctx - context for residual evaluation
50524989b8cSPeter Brune 
50624989b8cSPeter Brune    Level: advanced
50724989b8cSPeter Brune 
50824989b8cSPeter Brune    Note:
509ef20d060SBarry Smith    TSSetRSHFunction() is normally used, but it calls this function internally because the user context is actually
51024989b8cSPeter Brune    associated with the DM.  This makes the interface consistent regardless of whether the user interacts with a DM or
51124989b8cSPeter Brune    not. If DM took a more central role at some later date, this could become the primary method of setting the residual.
51224989b8cSPeter Brune 
51324989b8cSPeter Brune .seealso: DMTSSetContext(), TSSetFunction(), DMTSSetJacobian()
51424989b8cSPeter Brune @*/
51524989b8cSPeter Brune PetscErrorCode DMTSSetRHSFunction(DM dm,TSRHSFunction func,void *ctx)
51624989b8cSPeter Brune {
51724989b8cSPeter Brune   PetscErrorCode ierr;
518942e3340SBarry Smith   DMTS           tsdm;
51924989b8cSPeter Brune 
52024989b8cSPeter Brune   PetscFunctionBegin;
52124989b8cSPeter Brune   PetscValidHeaderSpecific(dm,DM_CLASSID,1);
522942e3340SBarry Smith   ierr = DMGetDMTSWrite(dm,&tsdm);CHKERRQ(ierr);
523d74926cbSBarry Smith   if (func) tsdm->ops->rhsfunction = func;
52424989b8cSPeter Brune   if (ctx)  tsdm->rhsfunctionctx = ctx;
52524989b8cSPeter Brune   PetscFunctionReturn(0);
52624989b8cSPeter Brune }
52724989b8cSPeter Brune 
528ef20d060SBarry Smith /*@C
529ef20d060SBarry Smith    DMTSGetSolutionFunction - gets the TS solution evaluation function
530ef20d060SBarry Smith 
531ef20d060SBarry Smith    Not Collective
532ef20d060SBarry Smith 
533ef20d060SBarry Smith    Input Arguments:
534ef20d060SBarry Smith .  dm - DM to be used with TS
535ef20d060SBarry Smith 
536ef20d060SBarry Smith    Output Parameters:
537ef20d060SBarry Smith +  func - solution function evaluation function, see TSSetSolution() for calling sequence
538ef20d060SBarry Smith -  ctx - context for solution evaluation
539ef20d060SBarry Smith 
540ef20d060SBarry Smith    Level: advanced
541ef20d060SBarry Smith 
5420ed3bfb6SBarry Smith .seealso: DMTSSetContext(), TSSetFunction(), DMTSSetJacobian(), DMTSSetSolutionFunction()
543ef20d060SBarry Smith @*/
544ef20d060SBarry Smith PetscErrorCode DMTSGetSolutionFunction(DM dm,TSSolutionFunction *func,void **ctx)
545ef20d060SBarry Smith {
546ef20d060SBarry Smith   PetscErrorCode ierr;
547942e3340SBarry Smith   DMTS           tsdm;
548ef20d060SBarry Smith 
549ef20d060SBarry Smith   PetscFunctionBegin;
550ef20d060SBarry Smith   PetscValidHeaderSpecific(dm,DM_CLASSID,1);
551942e3340SBarry Smith   ierr = DMGetDMTS(dm,&tsdm);CHKERRQ(ierr);
552d74926cbSBarry Smith   if (func) *func = tsdm->ops->solution;
553ef20d060SBarry Smith   if (ctx)  *ctx  = tsdm->solutionctx;
554ef20d060SBarry Smith   PetscFunctionReturn(0);
555ef20d060SBarry Smith }
556ef20d060SBarry Smith 
557ef20d060SBarry Smith /*@C
558ef20d060SBarry Smith    DMTSSetSolutionFunction - set TS solution evaluation function
559ef20d060SBarry Smith 
560ef20d060SBarry Smith    Not Collective
561ef20d060SBarry Smith 
562ef20d060SBarry Smith    Input Arguments:
563ef20d060SBarry Smith +  dm - DM to be used with TS
564ef20d060SBarry Smith .  func - solution function evaluation function, see TSSetSolution() for calling sequence
565ef20d060SBarry Smith -  ctx - context for solution evaluation
566ef20d060SBarry Smith 
567ef20d060SBarry Smith    Level: advanced
568ef20d060SBarry Smith 
569ef20d060SBarry Smith    Note:
570ef20d060SBarry Smith    TSSetSolutionFunction() is normally used, but it calls this function internally because the user context is actually
571ef20d060SBarry Smith    associated with the DM.  This makes the interface consistent regardless of whether the user interacts with a DM or
572ef20d060SBarry Smith    not. If DM took a more central role at some later date, this could become the primary method of setting the residual.
573ef20d060SBarry Smith 
5740ed3bfb6SBarry Smith .seealso: DMTSSetContext(), TSSetFunction(), DMTSSetJacobian(), DMTSGetSolutionFunction()
575ef20d060SBarry Smith @*/
576ef20d060SBarry Smith PetscErrorCode DMTSSetSolutionFunction(DM dm,TSSolutionFunction func,void *ctx)
577ef20d060SBarry Smith {
578ef20d060SBarry Smith   PetscErrorCode ierr;
579942e3340SBarry Smith   DMTS           tsdm;
580ef20d060SBarry Smith 
581ef20d060SBarry Smith   PetscFunctionBegin;
582ef20d060SBarry Smith   PetscValidHeaderSpecific(dm,DM_CLASSID,1);
583942e3340SBarry Smith   ierr = DMGetDMTSWrite(dm,&tsdm);CHKERRQ(ierr);
584d74926cbSBarry Smith   if (func) tsdm->ops->solution = func;
585ef20d060SBarry Smith   if (ctx)  tsdm->solutionctx   = ctx;
586ef20d060SBarry Smith   PetscFunctionReturn(0);
587ef20d060SBarry Smith }
588ef20d060SBarry Smith 
5899b7cd975SBarry Smith /*@C
5909b7cd975SBarry Smith    DMTSSetForcingFunction - set TS forcing function evaluation function
5919b7cd975SBarry Smith 
5929b7cd975SBarry Smith    Not Collective
5939b7cd975SBarry Smith 
5949b7cd975SBarry Smith    Input Arguments:
5959b7cd975SBarry Smith +  dm - DM to be used with TS
596f8b49ee9SBarry Smith .  f - forcing function evaluation function; see TSForcingFunction
5979b7cd975SBarry Smith -  ctx - context for solution evaluation
5989b7cd975SBarry Smith 
5999b7cd975SBarry Smith    Level: advanced
6009b7cd975SBarry Smith 
6019b7cd975SBarry Smith    Note:
6029b7cd975SBarry Smith    TSSetForcingFunction() is normally used, but it calls this function internally because the user context is actually
6039b7cd975SBarry Smith    associated with the DM.  This makes the interface consistent regardless of whether the user interacts with a DM or
6049b7cd975SBarry Smith    not. If DM took a more central role at some later date, this could become the primary method of setting the residual.
6059b7cd975SBarry Smith 
6069b7cd975SBarry Smith .seealso: DMTSSetContext(), TSSetFunction(), DMTSSetJacobian(), TSSetForcingFunction(), DMTSGetForcingFunction()
6079b7cd975SBarry Smith @*/
608d56366bfSLisandro Dalcin PetscErrorCode DMTSSetForcingFunction(DM dm,TSForcingFunction f,void *ctx)
6099b7cd975SBarry Smith {
6109b7cd975SBarry Smith   PetscErrorCode ierr;
6119b7cd975SBarry Smith   DMTS           tsdm;
6129b7cd975SBarry Smith 
6139b7cd975SBarry Smith   PetscFunctionBegin;
6149b7cd975SBarry Smith   PetscValidHeaderSpecific(dm,DM_CLASSID,1);
6159b7cd975SBarry Smith   ierr = DMGetDMTSWrite(dm,&tsdm);CHKERRQ(ierr);
616f8b49ee9SBarry Smith   if (f)    tsdm->ops->forcing = f;
6179b7cd975SBarry Smith   if (ctx)  tsdm->forcingctx   = ctx;
6189b7cd975SBarry Smith   PetscFunctionReturn(0);
6199b7cd975SBarry Smith }
6209b7cd975SBarry Smith 
6219b7cd975SBarry Smith 
6229b7cd975SBarry Smith /*@C
6239b7cd975SBarry Smith    DMTSGetForcingFunction - get TS forcing function evaluation function
6249b7cd975SBarry Smith 
6259b7cd975SBarry Smith    Not Collective
6269b7cd975SBarry Smith 
6279b7cd975SBarry Smith    Input Argument:
6289b7cd975SBarry Smith .   dm - DM to be used with TS
6299b7cd975SBarry Smith 
6309b7cd975SBarry Smith    Output Arguments:
631f8b49ee9SBarry Smith +  f - forcing function evaluation function; see TSForcingFunction for details
6329b7cd975SBarry Smith -  ctx - context for solution evaluation
6339b7cd975SBarry Smith 
6349b7cd975SBarry Smith    Level: advanced
6359b7cd975SBarry Smith 
6369b7cd975SBarry Smith    Note:
6379b7cd975SBarry Smith    TSSetForcingFunction() is normally used, but it calls this function internally because the user context is actually
6389b7cd975SBarry Smith    associated with the DM.  This makes the interface consistent regardless of whether the user interacts with a DM or
6399b7cd975SBarry Smith    not. If DM took a more central role at some later date, this could become the primary method of setting the residual.
6409b7cd975SBarry Smith 
6419b7cd975SBarry Smith .seealso: DMTSSetContext(), TSSetFunction(), DMTSSetJacobian(), TSSetForcingFunction(), DMTSGetForcingFunction()
6429b7cd975SBarry Smith @*/
643d56366bfSLisandro Dalcin PetscErrorCode DMTSGetForcingFunction(DM dm,TSForcingFunction *f,void **ctx)
6449b7cd975SBarry Smith {
6459b7cd975SBarry Smith   PetscErrorCode ierr;
6469b7cd975SBarry Smith   DMTS           tsdm;
6479b7cd975SBarry Smith 
6489b7cd975SBarry Smith   PetscFunctionBegin;
6499b7cd975SBarry Smith   PetscValidHeaderSpecific(dm,DM_CLASSID,1);
6509b7cd975SBarry Smith   ierr = DMGetDMTSWrite(dm,&tsdm);CHKERRQ(ierr);
651f8b49ee9SBarry Smith   if (f)   *f   = tsdm->ops->forcing;
6529b7cd975SBarry Smith   if (ctx) *ctx = tsdm->forcingctx;
6539b7cd975SBarry Smith   PetscFunctionReturn(0);
6549b7cd975SBarry Smith }
6559b7cd975SBarry Smith 
65624989b8cSPeter Brune /*@C
65724989b8cSPeter Brune    DMTSGetRHSFunction - get TS explicit residual evaluation function
65824989b8cSPeter Brune 
65924989b8cSPeter Brune    Not Collective
66024989b8cSPeter Brune 
66124989b8cSPeter Brune    Input Argument:
66224989b8cSPeter Brune .  dm - DM to be used with TS
66324989b8cSPeter Brune 
66424989b8cSPeter Brune    Output Arguments:
66524989b8cSPeter Brune +  func - residual evaluation function, see TSSetRHSFunction() for calling sequence
66624989b8cSPeter Brune -  ctx - context for residual evaluation
66724989b8cSPeter Brune 
66824989b8cSPeter Brune    Level: advanced
66924989b8cSPeter Brune 
67024989b8cSPeter Brune    Note:
67124989b8cSPeter Brune    TSGetFunction() is normally used, but it calls this function internally because the user context is actually
67224989b8cSPeter Brune    associated with the DM.
67324989b8cSPeter Brune 
67424989b8cSPeter Brune .seealso: DMTSSetContext(), DMTSSetFunction(), TSSetFunction()
67524989b8cSPeter Brune @*/
67624989b8cSPeter Brune PetscErrorCode DMTSGetRHSFunction(DM dm,TSRHSFunction *func,void **ctx)
67724989b8cSPeter Brune {
67824989b8cSPeter Brune   PetscErrorCode ierr;
679942e3340SBarry Smith   DMTS           tsdm;
68024989b8cSPeter Brune 
68124989b8cSPeter Brune   PetscFunctionBegin;
68224989b8cSPeter Brune   PetscValidHeaderSpecific(dm,DM_CLASSID,1);
683942e3340SBarry Smith   ierr = DMGetDMTS(dm,&tsdm);CHKERRQ(ierr);
684d74926cbSBarry Smith   if (func) *func = tsdm->ops->rhsfunction;
68524989b8cSPeter Brune   if (ctx)  *ctx = tsdm->rhsfunctionctx;
68624989b8cSPeter Brune   PetscFunctionReturn(0);
68724989b8cSPeter Brune }
68824989b8cSPeter Brune 
68924989b8cSPeter Brune /*@C
69024989b8cSPeter Brune    DMTSSetIJacobian - set TS Jacobian evaluation function
69124989b8cSPeter Brune 
69224989b8cSPeter Brune    Not Collective
69324989b8cSPeter Brune 
69424989b8cSPeter Brune    Input Argument:
69524989b8cSPeter Brune +  dm - DM to be used with TS
69624989b8cSPeter Brune .  func - Jacobian evaluation function, see TSSetIJacobian() for calling sequence
69724989b8cSPeter Brune -  ctx - context for residual evaluation
69824989b8cSPeter Brune 
69924989b8cSPeter Brune    Level: advanced
70024989b8cSPeter Brune 
70124989b8cSPeter Brune    Note:
70224989b8cSPeter Brune    TSSetJacobian() is normally used, but it calls this function internally because the user context is actually
70324989b8cSPeter Brune    associated with the DM.  This makes the interface consistent regardless of whether the user interacts with a DM or
70424989b8cSPeter Brune    not. If DM took a more central role at some later date, this could become the primary method of setting the Jacobian.
70524989b8cSPeter Brune 
70624989b8cSPeter Brune .seealso: DMTSSetContext(), TSSetFunction(), DMTSGetJacobian(), TSSetJacobian()
70724989b8cSPeter Brune @*/
70824989b8cSPeter Brune PetscErrorCode DMTSSetIJacobian(DM dm,TSIJacobian func,void *ctx)
70924989b8cSPeter Brune {
71024989b8cSPeter Brune   PetscErrorCode ierr;
711942e3340SBarry Smith   DMTS           sdm;
71224989b8cSPeter Brune 
71324989b8cSPeter Brune   PetscFunctionBegin;
71424989b8cSPeter Brune   PetscValidHeaderSpecific(dm,DM_CLASSID,1);
715942e3340SBarry Smith   ierr = DMGetDMTSWrite(dm,&sdm);CHKERRQ(ierr);
716d74926cbSBarry Smith   if (func) sdm->ops->ijacobian = func;
71724989b8cSPeter Brune   if (ctx)  sdm->ijacobianctx   = ctx;
71824989b8cSPeter Brune   PetscFunctionReturn(0);
71924989b8cSPeter Brune }
72024989b8cSPeter Brune 
72124989b8cSPeter Brune /*@C
72224989b8cSPeter Brune    DMTSGetIJacobian - get TS Jacobian evaluation function
72324989b8cSPeter Brune 
72424989b8cSPeter Brune    Not Collective
72524989b8cSPeter Brune 
72624989b8cSPeter Brune    Input Argument:
72724989b8cSPeter Brune .  dm - DM to be used with TS
72824989b8cSPeter Brune 
72924989b8cSPeter Brune    Output Arguments:
73024989b8cSPeter Brune +  func - Jacobian evaluation function, see TSSetIJacobian() for calling sequence
73124989b8cSPeter Brune -  ctx - context for residual evaluation
73224989b8cSPeter Brune 
73324989b8cSPeter Brune    Level: advanced
73424989b8cSPeter Brune 
73524989b8cSPeter Brune    Note:
73624989b8cSPeter Brune    TSGetJacobian() is normally used, but it calls this function internally because the user context is actually
73724989b8cSPeter Brune    associated with the DM.  This makes the interface consistent regardless of whether the user interacts with a DM or
73824989b8cSPeter Brune    not. If DM took a more central role at some later date, this could become the primary method of setting the Jacobian.
73924989b8cSPeter Brune 
74024989b8cSPeter Brune .seealso: DMTSSetContext(), TSSetFunction(), DMTSSetJacobian()
74124989b8cSPeter Brune @*/
74224989b8cSPeter Brune PetscErrorCode DMTSGetIJacobian(DM dm,TSIJacobian *func,void **ctx)
74324989b8cSPeter Brune {
74424989b8cSPeter Brune   PetscErrorCode ierr;
745942e3340SBarry Smith   DMTS           tsdm;
74624989b8cSPeter Brune 
74724989b8cSPeter Brune   PetscFunctionBegin;
74824989b8cSPeter Brune   PetscValidHeaderSpecific(dm,DM_CLASSID,1);
749942e3340SBarry Smith   ierr = DMGetDMTS(dm,&tsdm);CHKERRQ(ierr);
750d74926cbSBarry Smith   if (func) *func = tsdm->ops->ijacobian;
75124989b8cSPeter Brune   if (ctx)  *ctx = tsdm->ijacobianctx;
75224989b8cSPeter Brune   PetscFunctionReturn(0);
75324989b8cSPeter Brune }
75424989b8cSPeter Brune 
75524989b8cSPeter Brune 
75624989b8cSPeter Brune /*@C
75724989b8cSPeter Brune    DMTSSetRHSJacobian - set TS Jacobian evaluation function
75824989b8cSPeter Brune 
75924989b8cSPeter Brune    Not Collective
76024989b8cSPeter Brune 
76124989b8cSPeter Brune    Input Argument:
76224989b8cSPeter Brune +  dm - DM to be used with TS
76324989b8cSPeter Brune .  func - Jacobian evaluation function, see TSSetRHSJacobian() for calling sequence
76424989b8cSPeter Brune -  ctx - context for residual evaluation
76524989b8cSPeter Brune 
76624989b8cSPeter Brune    Level: advanced
76724989b8cSPeter Brune 
76824989b8cSPeter Brune    Note:
76924989b8cSPeter Brune    TSSetJacobian() is normally used, but it calls this function internally because the user context is actually
77024989b8cSPeter Brune    associated with the DM.  This makes the interface consistent regardless of whether the user interacts with a DM or
77124989b8cSPeter Brune    not. If DM took a more central role at some later date, this could become the primary method of setting the Jacobian.
77224989b8cSPeter Brune 
77324989b8cSPeter Brune .seealso: DMTSSetContext(), TSSetFunction(), DMTSGetJacobian(), TSSetJacobian()
77424989b8cSPeter Brune @*/
77524989b8cSPeter Brune PetscErrorCode DMTSSetRHSJacobian(DM dm,TSRHSJacobian func,void *ctx)
77624989b8cSPeter Brune {
77724989b8cSPeter Brune   PetscErrorCode ierr;
778942e3340SBarry Smith   DMTS           tsdm;
77924989b8cSPeter Brune 
78024989b8cSPeter Brune   PetscFunctionBegin;
78124989b8cSPeter Brune   PetscValidHeaderSpecific(dm,DM_CLASSID,1);
782942e3340SBarry Smith   ierr = DMGetDMTSWrite(dm,&tsdm);CHKERRQ(ierr);
783d74926cbSBarry Smith   if (func) tsdm->ops->rhsjacobian = func;
78424989b8cSPeter Brune   if (ctx)  tsdm->rhsjacobianctx = ctx;
78524989b8cSPeter Brune   PetscFunctionReturn(0);
78624989b8cSPeter Brune }
78724989b8cSPeter Brune 
78824989b8cSPeter Brune /*@C
78924989b8cSPeter Brune    DMTSGetRHSJacobian - get TS Jacobian evaluation function
79024989b8cSPeter Brune 
79124989b8cSPeter Brune    Not Collective
79224989b8cSPeter Brune 
79324989b8cSPeter Brune    Input Argument:
79424989b8cSPeter Brune .  dm - DM to be used with TS
79524989b8cSPeter Brune 
79624989b8cSPeter Brune    Output Arguments:
79724989b8cSPeter Brune +  func - Jacobian evaluation function, see TSSetRHSJacobian() for calling sequence
79824989b8cSPeter Brune -  ctx - context for residual evaluation
79924989b8cSPeter Brune 
80024989b8cSPeter Brune    Level: advanced
80124989b8cSPeter Brune 
80224989b8cSPeter Brune    Note:
80324989b8cSPeter Brune    TSGetJacobian() is normally used, but it calls this function internally because the user context is actually
80424989b8cSPeter Brune    associated with the DM.  This makes the interface consistent regardless of whether the user interacts with a DM or
80524989b8cSPeter Brune    not. If DM took a more central role at some later date, this could become the primary method of setting the Jacobian.
80624989b8cSPeter Brune 
80724989b8cSPeter Brune .seealso: DMTSSetContext(), TSSetFunction(), DMTSSetJacobian()
80824989b8cSPeter Brune @*/
80924989b8cSPeter Brune PetscErrorCode DMTSGetRHSJacobian(DM dm,TSRHSJacobian *func,void **ctx)
81024989b8cSPeter Brune {
81124989b8cSPeter Brune   PetscErrorCode ierr;
812942e3340SBarry Smith   DMTS           tsdm;
81324989b8cSPeter Brune 
81424989b8cSPeter Brune   PetscFunctionBegin;
81524989b8cSPeter Brune   PetscValidHeaderSpecific(dm,DM_CLASSID,1);
816942e3340SBarry Smith   ierr = DMGetDMTS(dm,&tsdm);CHKERRQ(ierr);
817d74926cbSBarry Smith   if (func) *func = tsdm->ops->rhsjacobian;
81824989b8cSPeter Brune   if (ctx)  *ctx = tsdm->rhsjacobianctx;
81924989b8cSPeter Brune   PetscFunctionReturn(0);
82024989b8cSPeter Brune }
821ad6bc421SBarry Smith 
822ad6bc421SBarry Smith /*@C
823ad6bc421SBarry Smith    DMTSSetIFunctionSerialize - sets functions used to view and load a IFunction context
824ad6bc421SBarry Smith 
825ad6bc421SBarry Smith    Not Collective
826ad6bc421SBarry Smith 
827ad6bc421SBarry Smith    Input Arguments:
828ad6bc421SBarry Smith +  dm - DM to be used with TS
829ad6bc421SBarry Smith .  view - viewer function
830ad6bc421SBarry Smith -  load - loading function
831ad6bc421SBarry Smith 
832ad6bc421SBarry Smith    Level: advanced
833ad6bc421SBarry Smith 
834ad6bc421SBarry Smith .seealso: DMTSSetContext(), TSSetFunction(), DMTSSetJacobian()
835ad6bc421SBarry Smith @*/
836ad6bc421SBarry Smith PetscErrorCode DMTSSetIFunctionSerialize(DM dm,PetscErrorCode (*view)(void*,PetscViewer),PetscErrorCode (*load)(void**,PetscViewer))
837ad6bc421SBarry Smith {
838ad6bc421SBarry Smith   PetscErrorCode ierr;
839ad6bc421SBarry Smith   DMTS           tsdm;
840ad6bc421SBarry Smith 
841ad6bc421SBarry Smith   PetscFunctionBegin;
842ad6bc421SBarry Smith   PetscValidHeaderSpecific(dm,DM_CLASSID,1);
843ad6bc421SBarry Smith   ierr = DMGetDMTSWrite(dm,&tsdm);CHKERRQ(ierr);
844ad6bc421SBarry Smith   tsdm->ops->ifunctionview = view;
845ad6bc421SBarry Smith   tsdm->ops->ifunctionload = load;
846ad6bc421SBarry Smith   PetscFunctionReturn(0);
847ad6bc421SBarry Smith }
848ad6bc421SBarry Smith 
849ad6bc421SBarry Smith /*@C
850ad6bc421SBarry Smith    DMTSSetIJacobianSerialize - sets functions used to view and load a IJacobian context
851ad6bc421SBarry Smith 
852ad6bc421SBarry Smith    Not Collective
853ad6bc421SBarry Smith 
854ad6bc421SBarry Smith    Input Arguments:
855ad6bc421SBarry Smith +  dm - DM to be used with TS
856ad6bc421SBarry Smith .  view - viewer function
857ad6bc421SBarry Smith -  load - loading function
858ad6bc421SBarry Smith 
859ad6bc421SBarry Smith    Level: advanced
860ad6bc421SBarry Smith 
861ad6bc421SBarry Smith .seealso: DMTSSetContext(), TSSetFunction(), DMTSSetJacobian()
862ad6bc421SBarry Smith @*/
863ad6bc421SBarry Smith PetscErrorCode DMTSSetIJacobianSerialize(DM dm,PetscErrorCode (*view)(void*,PetscViewer),PetscErrorCode (*load)(void**,PetscViewer))
864ad6bc421SBarry Smith {
865ad6bc421SBarry Smith   PetscErrorCode ierr;
866ad6bc421SBarry Smith   DMTS           tsdm;
867ad6bc421SBarry Smith 
868ad6bc421SBarry Smith   PetscFunctionBegin;
869ad6bc421SBarry Smith   PetscValidHeaderSpecific(dm,DM_CLASSID,1);
870ad6bc421SBarry Smith   ierr = DMGetDMTSWrite(dm,&tsdm);CHKERRQ(ierr);
871ad6bc421SBarry Smith   tsdm->ops->ijacobianview = view;
872ad6bc421SBarry Smith   tsdm->ops->ijacobianload = load;
873ad6bc421SBarry Smith   PetscFunctionReturn(0);
874ad6bc421SBarry Smith }
875