xref: /petsc/src/ts/utils/dmts.c (revision 2d53ad75667bd9af5ca32c6f75ade56f24a4fbe1)
124989b8cSPeter Brune #include <petsc-private/tsimpl.h>     /*I "petscts.h" I*/
224989b8cSPeter Brune #include <petsc-private/dmimpl.h>     /*I "petscdm.h" I*/
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__
20*2d53ad75SBarry Smith #define __FUNCT__ "DMTSLoad"
21*2d53ad75SBarry Smith PetscErrorCode DMTSLoad(DMTS 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->ifunction,1,PETSC_FUNCTION);CHKERRQ(ierr);
27*2d53ad75SBarry Smith   ierr = PetscViewerBinaryRead(viewer,&kdm->ops->ijacobian,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__ "DMTSView"
33*2d53ad75SBarry Smith PetscErrorCode DMTSView(DMTS 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->ifunction,&fname);CHKERRQ(ierr);
45*2d53ad75SBarry Smith     if (fname) {
46*2d53ad75SBarry Smith       ierr = PetscViewerASCIIPrintf(viewer,"  IFunction used by TS: %s\n",fname);CHKERRQ(ierr);
47*2d53ad75SBarry Smith     }
48*2d53ad75SBarry Smith     ierr = PetscFPTFind(kdm->ops->ijacobian,&fname);CHKERRQ(ierr);
49*2d53ad75SBarry Smith     if (fname) {
50*2d53ad75SBarry Smith       ierr = PetscViewerASCIIPrintf(viewer,"  IJacobian function used by TS: %s\n",fname);CHKERRQ(ierr);
51*2d53ad75SBarry Smith     }
52*2d53ad75SBarry Smith   } else if (isbinary) {
53*2d53ad75SBarry Smith     ierr = PetscViewerBinaryWrite(viewer,kdm->ops->ifunction,1,PETSC_FUNCTION,PETSC_FALSE);CHKERRQ(ierr);
54*2d53ad75SBarry Smith     ierr = PetscViewerBinaryWrite(viewer,kdm->ops->ijacobian,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__
60d74926cbSBarry Smith #define __FUNCT__ "DMTSCreate"
61d74926cbSBarry Smith static PetscErrorCode DMTSCreate(MPI_Comm comm,DMTS *kdm)
62d74926cbSBarry Smith {
63d74926cbSBarry Smith   PetscErrorCode ierr;
64d74926cbSBarry Smith 
65d74926cbSBarry Smith   PetscFunctionBegin;
66d74926cbSBarry Smith #ifndef PETSC_USE_DYNAMIC_LIBRARIES
67d74926cbSBarry Smith   ierr = TSInitializePackage(PETSC_NULL);CHKERRQ(ierr);
68d74926cbSBarry Smith #endif
69*2d53ad75SBarry Smith   ierr = PetscHeaderCreate(*kdm, _p_DMTS, struct _DMTSOps, DMTS_CLASSID, -1, "DMTS", "DMTS", "DMTS", comm, DMTSDestroy, DMTSView);CHKERRQ(ierr);
70d74926cbSBarry Smith   ierr = PetscMemzero((*kdm)->ops, sizeof(struct _DMTSOps));CHKERRQ(ierr);
71d74926cbSBarry Smith   PetscFunctionReturn(0);
72d74926cbSBarry Smith }
7324989b8cSPeter Brune 
7424989b8cSPeter Brune #undef __FUNCT__
75942e3340SBarry Smith #define __FUNCT__ "DMCoarsenHook_DMTS"
762a34c10cSBarry Smith /* Attaches the DMTS to the coarse level.
7724989b8cSPeter Brune  * Under what conditions should we copy versus duplicate?
7824989b8cSPeter Brune  */
79942e3340SBarry Smith static PetscErrorCode DMCoarsenHook_DMTS(DM dm,DM dmc,void *ctx)
8024989b8cSPeter Brune {
8124989b8cSPeter Brune   PetscErrorCode ierr;
8224989b8cSPeter Brune 
8324989b8cSPeter Brune   PetscFunctionBegin;
84942e3340SBarry Smith   ierr = DMCopyDMTS(dm,dmc);CHKERRQ(ierr);
8524989b8cSPeter Brune   PetscFunctionReturn(0);
8624989b8cSPeter Brune }
8724989b8cSPeter Brune 
8824989b8cSPeter Brune #undef __FUNCT__
89942e3340SBarry Smith #define __FUNCT__ "DMRestrictHook_DMTS"
9024989b8cSPeter Brune /* This could restrict auxiliary information to the coarse level.
9124989b8cSPeter Brune  */
92942e3340SBarry Smith static PetscErrorCode DMRestrictHook_DMTS(DM dm,Mat Restrict,Vec rscale,Mat Inject,DM dmc,void *ctx)
9324989b8cSPeter Brune {
9424989b8cSPeter Brune 
9524989b8cSPeter Brune   PetscFunctionBegin;
9624989b8cSPeter Brune   PetscFunctionReturn(0);
9724989b8cSPeter Brune }
9824989b8cSPeter Brune 
9924989b8cSPeter Brune #undef __FUNCT__
100d74926cbSBarry Smith #define __FUNCT__ "DMTSCopy"
101d74926cbSBarry Smith /*@C
102d74926cbSBarry Smith    DMTSCopy - copies the information in a DMTS to another DMTS
103d74926cbSBarry Smith 
104d74926cbSBarry Smith    Not Collective
105d74926cbSBarry Smith 
106d74926cbSBarry Smith    Input Argument:
107d74926cbSBarry Smith +  kdm - Original DMTS
108d74926cbSBarry Smith -  nkdm - DMTS to receive the data, should have been created with DMTSCreate()
109d74926cbSBarry Smith 
110d74926cbSBarry Smith    Level: developer
111d74926cbSBarry Smith 
112d74926cbSBarry Smith .seealso: DMTSCreate(), DMTSDestroy()
113d74926cbSBarry Smith @*/
114d74926cbSBarry Smith PetscErrorCode DMTSCopy(DMTS kdm,DMTS nkdm)
11524989b8cSPeter Brune {
11624989b8cSPeter Brune   PetscErrorCode ierr;
11724989b8cSPeter Brune 
11824989b8cSPeter Brune   PetscFunctionBegin;
119d74926cbSBarry Smith   PetscValidHeaderSpecific(kdm,DMTS_CLASSID,1);
120d74926cbSBarry Smith   PetscValidHeaderSpecific(nkdm,DMTS_CLASSID,2);
121d74926cbSBarry Smith   nkdm->ops->rhsfunction    = kdm->ops->rhsfunction;
122d74926cbSBarry Smith   nkdm->ops->rhsjacobian    = kdm->ops->rhsjacobian;
123d74926cbSBarry Smith   nkdm->ops->ifunction      = kdm->ops->ifunction;
124d74926cbSBarry Smith   nkdm->ops->ijacobian      = kdm->ops->ijacobian;
125d74926cbSBarry Smith   nkdm->ops->solution       = kdm->ops->solution;
126d74926cbSBarry Smith   nkdm->ops->destroy        = kdm->ops->destroy;
127d74926cbSBarry Smith   nkdm->ops->duplicate      = kdm->ops->duplicate;
128d74926cbSBarry Smith 
129d74926cbSBarry Smith   nkdm->rhsfunctionctx      = kdm->rhsfunctionctx;
130d74926cbSBarry Smith   nkdm->rhsjacobianctx      = kdm->rhsjacobianctx;
131d74926cbSBarry Smith   nkdm->ifunctionctx        = kdm->ifunctionctx;
132d74926cbSBarry Smith   nkdm->ijacobianctx        = kdm->ijacobianctx;
133d74926cbSBarry Smith   nkdm->solutionctx         = kdm->solutionctx;
134d74926cbSBarry Smith 
135d74926cbSBarry Smith   nkdm->data             = kdm->data;
136d74926cbSBarry Smith 
137d74926cbSBarry Smith   /*
138d74926cbSBarry Smith   nkdm->fortran_func_pointers[0] = kdm->fortran_func_pointers[0];
139d74926cbSBarry Smith   nkdm->fortran_func_pointers[1] = kdm->fortran_func_pointers[1];
140d74926cbSBarry Smith   nkdm->fortran_func_pointers[2] = kdm->fortran_func_pointers[2];
141d74926cbSBarry Smith   */
142d74926cbSBarry Smith 
143d74926cbSBarry Smith   /* implementation specific copy hooks */
144d74926cbSBarry Smith   if (kdm->ops->duplicate) {ierr = (*kdm->ops->duplicate)(kdm,nkdm);CHKERRQ(ierr);}
14524989b8cSPeter Brune   PetscFunctionReturn(0);
14624989b8cSPeter Brune }
14724989b8cSPeter Brune 
14824989b8cSPeter Brune #undef __FUNCT__
149942e3340SBarry Smith #define __FUNCT__ "DMGetDMTS"
15024989b8cSPeter Brune /*@C
151942e3340SBarry Smith    DMGetDMTS - get read-only private DMTS context from a DM
15224989b8cSPeter Brune 
15324989b8cSPeter Brune    Not Collective
15424989b8cSPeter Brune 
15524989b8cSPeter Brune    Input Argument:
15624989b8cSPeter Brune .  dm - DM to be used with TS
15724989b8cSPeter Brune 
15824989b8cSPeter Brune    Output Argument:
159942e3340SBarry Smith .  tsdm - private DMTS context
16024989b8cSPeter Brune 
16124989b8cSPeter Brune    Level: developer
16224989b8cSPeter Brune 
16324989b8cSPeter Brune    Notes:
164942e3340SBarry Smith    Use DMGetDMTSWrite() if write access is needed. The DMTSSetXXX API should be used wherever possible.
16524989b8cSPeter Brune 
166942e3340SBarry Smith .seealso: DMGetDMTSWrite()
16724989b8cSPeter Brune @*/
168942e3340SBarry Smith PetscErrorCode DMGetDMTS(DM dm,DMTS *tsdm)
16924989b8cSPeter Brune {
17024989b8cSPeter Brune   PetscErrorCode ierr;
17124989b8cSPeter Brune 
17224989b8cSPeter Brune   PetscFunctionBegin;
17324989b8cSPeter Brune   PetscValidHeaderSpecific(dm,DM_CLASSID,1);
1742a34c10cSBarry Smith   *tsdm = (DMTS) dm->dmts;
175d74926cbSBarry Smith   if (!*tsdm) {
176942e3340SBarry Smith     ierr = PetscInfo(dm,"Creating new DMTS\n");CHKERRQ(ierr);
177d74926cbSBarry Smith     ierr = DMTSCreate(((PetscObject)dm)->comm,tsdm);CHKERRQ(ierr);
1782a34c10cSBarry Smith     dm->dmts = (PetscObject) *tsdm;
179942e3340SBarry Smith     ierr = DMCoarsenHookAdd(dm,DMCoarsenHook_DMTS,DMRestrictHook_DMTS,PETSC_NULL);CHKERRQ(ierr);
18024989b8cSPeter Brune   }
18124989b8cSPeter Brune   PetscFunctionReturn(0);
18224989b8cSPeter Brune }
18324989b8cSPeter Brune 
18424989b8cSPeter Brune #undef __FUNCT__
185942e3340SBarry Smith #define __FUNCT__ "DMGetDMTSWrite"
18624989b8cSPeter Brune /*@C
187942e3340SBarry Smith    DMGetDMTSWrite - get write access to private DMTS context from a DM
18824989b8cSPeter Brune 
18924989b8cSPeter Brune    Not Collective
19024989b8cSPeter Brune 
19124989b8cSPeter Brune    Input Argument:
19224989b8cSPeter Brune .  dm - DM to be used with TS
19324989b8cSPeter Brune 
19424989b8cSPeter Brune    Output Argument:
195942e3340SBarry Smith .  tsdm - private DMTS context
19624989b8cSPeter Brune 
19724989b8cSPeter Brune    Level: developer
19824989b8cSPeter Brune 
199942e3340SBarry Smith .seealso: DMGetDMTS()
20024989b8cSPeter Brune @*/
201942e3340SBarry Smith PetscErrorCode DMGetDMTSWrite(DM dm,DMTS *tsdm)
20224989b8cSPeter Brune {
20324989b8cSPeter Brune   PetscErrorCode ierr;
204942e3340SBarry Smith   DMTS           sdm;
20524989b8cSPeter Brune 
20624989b8cSPeter Brune   PetscFunctionBegin;
20724989b8cSPeter Brune   PetscValidHeaderSpecific(dm,DM_CLASSID,1);
208942e3340SBarry Smith   ierr = DMGetDMTS(dm,&sdm);CHKERRQ(ierr);
20924989b8cSPeter Brune   if (!sdm->originaldm) sdm->originaldm = dm;
21024989b8cSPeter Brune   if (sdm->originaldm != dm) {  /* Copy on write */
2112a34c10cSBarry Smith     DMTS          oldsdm = sdm;
212942e3340SBarry Smith     ierr = PetscInfo(dm,"Copying DMTS due to write\n");CHKERRQ(ierr);
213d74926cbSBarry Smith     ierr = DMTSCreate(((PetscObject)dm)->comm,&sdm);CHKERRQ(ierr);
214d74926cbSBarry Smith     ierr = DMTSCopy(oldsdm,sdm);CHKERRQ(ierr);
2152a34c10cSBarry Smith     ierr = DMTSDestroy((DMTS*)&dm->dmts);CHKERRQ(ierr);
2162a34c10cSBarry Smith     dm->dmts = (PetscObject) sdm;
21724989b8cSPeter Brune   }
21824989b8cSPeter Brune   *tsdm = sdm;
21924989b8cSPeter Brune   PetscFunctionReturn(0);
22024989b8cSPeter Brune }
22124989b8cSPeter Brune 
22224989b8cSPeter Brune #undef __FUNCT__
223942e3340SBarry Smith #define __FUNCT__ "DMCopyDMTS"
22424989b8cSPeter Brune /*@C
225942e3340SBarry Smith    DMCopyDMTS - copies a DM context to a new DM
22624989b8cSPeter Brune 
22724989b8cSPeter Brune    Logically Collective
22824989b8cSPeter Brune 
22924989b8cSPeter Brune    Input Arguments:
23024989b8cSPeter Brune +  dmsrc - DM to obtain context from
23124989b8cSPeter Brune -  dmdest - DM to add context to
23224989b8cSPeter Brune 
23324989b8cSPeter Brune    Level: developer
23424989b8cSPeter Brune 
23524989b8cSPeter Brune    Note:
23624989b8cSPeter Brune    The context is copied by reference. This function does not ensure that a context exists.
23724989b8cSPeter Brune 
238942e3340SBarry Smith .seealso: DMGetDMTS(), TSSetDM()
23924989b8cSPeter Brune @*/
240942e3340SBarry Smith PetscErrorCode DMCopyDMTS(DM dmsrc,DM dmdest)
24124989b8cSPeter Brune {
24224989b8cSPeter Brune   PetscErrorCode ierr;
24324989b8cSPeter Brune 
24424989b8cSPeter Brune   PetscFunctionBegin;
24524989b8cSPeter Brune   PetscValidHeaderSpecific(dmsrc,DM_CLASSID,1);
24624989b8cSPeter Brune   PetscValidHeaderSpecific(dmdest,DM_CLASSID,2);
2472a34c10cSBarry Smith   ierr = DMTSDestroy((DMTS*)&dmdest->dmts);CHKERRQ(ierr);
2482a34c10cSBarry Smith   dmdest->dmts = dmsrc->dmts;
2492a34c10cSBarry Smith   ierr = PetscObjectReference(dmdest->dmts);CHKERRQ(ierr);
250942e3340SBarry Smith   ierr = DMCoarsenHookAdd(dmdest,DMCoarsenHook_DMTS,DMRestrictHook_DMTS,PETSC_NULL);CHKERRQ(ierr);
25124989b8cSPeter Brune   PetscFunctionReturn(0);
25224989b8cSPeter Brune }
25324989b8cSPeter Brune 
25424989b8cSPeter Brune #undef __FUNCT__
25524989b8cSPeter Brune #define __FUNCT__ "DMTSSetIFunction"
25624989b8cSPeter Brune /*@C
25724989b8cSPeter Brune    DMTSSetIFunction - set TS implicit function evaluation function
25824989b8cSPeter Brune 
25924989b8cSPeter Brune    Not Collective
26024989b8cSPeter Brune 
26124989b8cSPeter Brune    Input Arguments:
26224989b8cSPeter Brune +  dm - DM to be used with TS
26324989b8cSPeter Brune .  func - function evaluation function, see TSSetIFunction() for calling sequence
26424989b8cSPeter Brune -  ctx - context for residual evaluation
26524989b8cSPeter Brune 
26624989b8cSPeter Brune    Level: advanced
26724989b8cSPeter Brune 
26824989b8cSPeter Brune    Note:
26924989b8cSPeter Brune    TSSetFunction() is normally used, but it calls this function internally because the user context is actually
27024989b8cSPeter Brune    associated with the DM.  This makes the interface consistent regardless of whether the user interacts with a DM or
27124989b8cSPeter Brune    not. If DM took a more central role at some later date, this could become the primary method of setting the residual.
27224989b8cSPeter Brune 
27324989b8cSPeter Brune .seealso: DMTSSetContext(), TSSetFunction(), DMTSSetJacobian()
27424989b8cSPeter Brune @*/
27524989b8cSPeter Brune PetscErrorCode DMTSSetIFunction(DM dm,TSIFunction func,void *ctx)
27624989b8cSPeter Brune {
27724989b8cSPeter Brune   PetscErrorCode ierr;
278942e3340SBarry Smith   DMTS           tsdm;
27924989b8cSPeter Brune 
28024989b8cSPeter Brune   PetscFunctionBegin;
28124989b8cSPeter Brune   PetscValidHeaderSpecific(dm,DM_CLASSID,1);
282942e3340SBarry Smith   ierr = DMGetDMTSWrite(dm,&tsdm);CHKERRQ(ierr);
283d74926cbSBarry Smith   if (func) tsdm->ops->ifunction = func;
28424989b8cSPeter Brune   if (ctx)  tsdm->ifunctionctx = ctx;
28524989b8cSPeter Brune   PetscFunctionReturn(0);
28624989b8cSPeter Brune }
28724989b8cSPeter Brune 
28824989b8cSPeter Brune #undef __FUNCT__
28924989b8cSPeter Brune #define __FUNCT__ "DMTSGetIFunction"
29024989b8cSPeter Brune /*@C
29124989b8cSPeter Brune    DMTSGetIFunction - get TS implicit residual evaluation function
29224989b8cSPeter Brune 
29324989b8cSPeter Brune    Not Collective
29424989b8cSPeter Brune 
29524989b8cSPeter Brune    Input Argument:
29624989b8cSPeter Brune .  dm - DM to be used with TS
29724989b8cSPeter Brune 
29824989b8cSPeter Brune    Output Arguments:
29924989b8cSPeter Brune +  func - function evaluation function, see TSSetIFunction() for calling sequence
30024989b8cSPeter Brune -  ctx - context for residual evaluation
30124989b8cSPeter Brune 
30224989b8cSPeter Brune    Level: advanced
30324989b8cSPeter Brune 
30424989b8cSPeter Brune    Note:
30524989b8cSPeter Brune    TSGetFunction() is normally used, but it calls this function internally because the user context is actually
30624989b8cSPeter Brune    associated with the DM.
30724989b8cSPeter Brune 
30824989b8cSPeter Brune .seealso: DMTSSetContext(), DMTSSetFunction(), TSSetFunction()
30924989b8cSPeter Brune @*/
31024989b8cSPeter Brune PetscErrorCode DMTSGetIFunction(DM dm,TSIFunction *func,void **ctx)
31124989b8cSPeter Brune {
31224989b8cSPeter Brune   PetscErrorCode ierr;
313942e3340SBarry Smith   DMTS           tsdm;
31424989b8cSPeter Brune 
31524989b8cSPeter Brune   PetscFunctionBegin;
31624989b8cSPeter Brune   PetscValidHeaderSpecific(dm,DM_CLASSID,1);
317942e3340SBarry Smith   ierr = DMGetDMTS(dm,&tsdm);CHKERRQ(ierr);
318d74926cbSBarry Smith   if (func) *func = tsdm->ops->ifunction;
31924989b8cSPeter Brune   if (ctx)  *ctx = tsdm->ifunctionctx;
32024989b8cSPeter Brune   PetscFunctionReturn(0);
32124989b8cSPeter Brune }
32224989b8cSPeter Brune 
32324989b8cSPeter Brune 
32424989b8cSPeter Brune #undef __FUNCT__
32524989b8cSPeter Brune #define __FUNCT__ "DMTSSetRHSFunction"
32624989b8cSPeter Brune /*@C
32724989b8cSPeter Brune    DMTSSetRHSFunction - set TS explicit residual evaluation function
32824989b8cSPeter Brune 
32924989b8cSPeter Brune    Not Collective
33024989b8cSPeter Brune 
33124989b8cSPeter Brune    Input Arguments:
33224989b8cSPeter Brune +  dm - DM to be used with TS
33324989b8cSPeter Brune .  func - RHS function evaluation function, see TSSetRHSFunction() for calling sequence
33424989b8cSPeter Brune -  ctx - context for residual evaluation
33524989b8cSPeter Brune 
33624989b8cSPeter Brune    Level: advanced
33724989b8cSPeter Brune 
33824989b8cSPeter Brune    Note:
339ef20d060SBarry Smith    TSSetRSHFunction() is normally used, but it calls this function internally because the user context is actually
34024989b8cSPeter Brune    associated with the DM.  This makes the interface consistent regardless of whether the user interacts with a DM or
34124989b8cSPeter Brune    not. If DM took a more central role at some later date, this could become the primary method of setting the residual.
34224989b8cSPeter Brune 
34324989b8cSPeter Brune .seealso: DMTSSetContext(), TSSetFunction(), DMTSSetJacobian()
34424989b8cSPeter Brune @*/
34524989b8cSPeter Brune PetscErrorCode DMTSSetRHSFunction(DM dm,TSRHSFunction func,void *ctx)
34624989b8cSPeter Brune {
34724989b8cSPeter Brune   PetscErrorCode ierr;
348942e3340SBarry Smith   DMTS           tsdm;
34924989b8cSPeter Brune 
35024989b8cSPeter Brune   PetscFunctionBegin;
35124989b8cSPeter Brune   PetscValidHeaderSpecific(dm,DM_CLASSID,1);
352942e3340SBarry Smith   ierr = DMGetDMTSWrite(dm,&tsdm);CHKERRQ(ierr);
353d74926cbSBarry Smith   if (func) tsdm->ops->rhsfunction = func;
35424989b8cSPeter Brune   if (ctx)  tsdm->rhsfunctionctx = ctx;
35524989b8cSPeter Brune   PetscFunctionReturn(0);
35624989b8cSPeter Brune }
35724989b8cSPeter Brune 
35824989b8cSPeter Brune #undef __FUNCT__
359ef20d060SBarry Smith #define __FUNCT__ "DMTSGetSolutionFunction"
360ef20d060SBarry Smith /*@C
361ef20d060SBarry Smith    DMTSGetSolutionFunction - gets the TS solution evaluation function
362ef20d060SBarry Smith 
363ef20d060SBarry Smith    Not Collective
364ef20d060SBarry Smith 
365ef20d060SBarry Smith    Input Arguments:
366ef20d060SBarry Smith .  dm - DM to be used with TS
367ef20d060SBarry Smith 
368ef20d060SBarry Smith    Output Parameters:
369ef20d060SBarry Smith +  func - solution function evaluation function, see TSSetSolution() for calling sequence
370ef20d060SBarry Smith -  ctx - context for solution evaluation
371ef20d060SBarry Smith 
372ef20d060SBarry Smith    Level: advanced
373ef20d060SBarry Smith 
374ef20d060SBarry Smith .seealso: DMTSSetContext(), TSSetFunction(), DMTSSetJacobian()
375ef20d060SBarry Smith @*/
376ef20d060SBarry Smith PetscErrorCode DMTSGetSolutionFunction(DM dm,TSSolutionFunction *func,void **ctx)
377ef20d060SBarry Smith {
378ef20d060SBarry Smith   PetscErrorCode ierr;
379942e3340SBarry Smith   DMTS           tsdm;
380ef20d060SBarry Smith 
381ef20d060SBarry Smith   PetscFunctionBegin;
382ef20d060SBarry Smith   PetscValidHeaderSpecific(dm,DM_CLASSID,1);
383942e3340SBarry Smith   ierr = DMGetDMTS(dm,&tsdm);CHKERRQ(ierr);
384d74926cbSBarry Smith   if (func) *func = tsdm->ops->solution;
385ef20d060SBarry Smith   if (ctx)  *ctx  = tsdm->solutionctx;
386ef20d060SBarry Smith   PetscFunctionReturn(0);
387ef20d060SBarry Smith }
388ef20d060SBarry Smith 
389ef20d060SBarry Smith #undef __FUNCT__
390ef20d060SBarry Smith #define __FUNCT__ "DMTSSetSolutionFunction"
391ef20d060SBarry Smith /*@C
392ef20d060SBarry Smith    DMTSSetSolutionFunction - set TS solution evaluation function
393ef20d060SBarry Smith 
394ef20d060SBarry Smith    Not Collective
395ef20d060SBarry Smith 
396ef20d060SBarry Smith    Input Arguments:
397ef20d060SBarry Smith +  dm - DM to be used with TS
398ef20d060SBarry Smith .  func - solution function evaluation function, see TSSetSolution() for calling sequence
399ef20d060SBarry Smith -  ctx - context for solution evaluation
400ef20d060SBarry Smith 
401ef20d060SBarry Smith    Level: advanced
402ef20d060SBarry Smith 
403ef20d060SBarry Smith    Note:
404ef20d060SBarry Smith    TSSetSolutionFunction() is normally used, but it calls this function internally because the user context is actually
405ef20d060SBarry Smith    associated with the DM.  This makes the interface consistent regardless of whether the user interacts with a DM or
406ef20d060SBarry Smith    not. If DM took a more central role at some later date, this could become the primary method of setting the residual.
407ef20d060SBarry Smith 
408ef20d060SBarry Smith .seealso: DMTSSetContext(), TSSetFunction(), DMTSSetJacobian()
409ef20d060SBarry Smith @*/
410ef20d060SBarry Smith PetscErrorCode DMTSSetSolutionFunction(DM dm,TSSolutionFunction func,void *ctx)
411ef20d060SBarry Smith {
412ef20d060SBarry Smith   PetscErrorCode ierr;
413942e3340SBarry Smith   DMTS           tsdm;
414ef20d060SBarry Smith 
415ef20d060SBarry Smith   PetscFunctionBegin;
416ef20d060SBarry Smith   PetscValidHeaderSpecific(dm,DM_CLASSID,1);
417942e3340SBarry Smith   ierr = DMGetDMTSWrite(dm,&tsdm);CHKERRQ(ierr);
418d74926cbSBarry Smith   if (func) tsdm->ops->solution = func;
419ef20d060SBarry Smith   if (ctx)  tsdm->solutionctx   = ctx;
420ef20d060SBarry Smith   PetscFunctionReturn(0);
421ef20d060SBarry Smith }
422ef20d060SBarry Smith 
423ef20d060SBarry Smith #undef __FUNCT__
42424989b8cSPeter Brune #define __FUNCT__ "DMTSGetRHSFunction"
42524989b8cSPeter Brune /*@C
42624989b8cSPeter Brune    DMTSGetRHSFunction - get TS explicit residual evaluation function
42724989b8cSPeter Brune 
42824989b8cSPeter Brune    Not Collective
42924989b8cSPeter Brune 
43024989b8cSPeter Brune    Input Argument:
43124989b8cSPeter Brune .  dm - DM to be used with TS
43224989b8cSPeter Brune 
43324989b8cSPeter Brune    Output Arguments:
43424989b8cSPeter Brune +  func - residual evaluation function, see TSSetRHSFunction() for calling sequence
43524989b8cSPeter Brune -  ctx - context for residual evaluation
43624989b8cSPeter Brune 
43724989b8cSPeter Brune    Level: advanced
43824989b8cSPeter Brune 
43924989b8cSPeter Brune    Note:
44024989b8cSPeter Brune    TSGetFunction() is normally used, but it calls this function internally because the user context is actually
44124989b8cSPeter Brune    associated with the DM.
44224989b8cSPeter Brune 
44324989b8cSPeter Brune .seealso: DMTSSetContext(), DMTSSetFunction(), TSSetFunction()
44424989b8cSPeter Brune @*/
44524989b8cSPeter Brune PetscErrorCode DMTSGetRHSFunction(DM dm,TSRHSFunction *func,void **ctx)
44624989b8cSPeter Brune {
44724989b8cSPeter Brune   PetscErrorCode ierr;
448942e3340SBarry Smith   DMTS           tsdm;
44924989b8cSPeter Brune 
45024989b8cSPeter Brune   PetscFunctionBegin;
45124989b8cSPeter Brune   PetscValidHeaderSpecific(dm,DM_CLASSID,1);
452942e3340SBarry Smith   ierr = DMGetDMTS(dm,&tsdm);CHKERRQ(ierr);
453d74926cbSBarry Smith   if (func) *func = tsdm->ops->rhsfunction;
45424989b8cSPeter Brune   if (ctx)  *ctx = tsdm->rhsfunctionctx;
45524989b8cSPeter Brune   PetscFunctionReturn(0);
45624989b8cSPeter Brune }
45724989b8cSPeter Brune 
45824989b8cSPeter Brune #undef __FUNCT__
45924989b8cSPeter Brune #define __FUNCT__ "DMTSSetIJacobian"
46024989b8cSPeter Brune /*@C
46124989b8cSPeter Brune    DMTSSetIJacobian - set TS Jacobian evaluation function
46224989b8cSPeter Brune 
46324989b8cSPeter Brune    Not Collective
46424989b8cSPeter Brune 
46524989b8cSPeter Brune    Input Argument:
46624989b8cSPeter Brune +  dm - DM to be used with TS
46724989b8cSPeter Brune .  func - Jacobian evaluation function, see TSSetIJacobian() for calling sequence
46824989b8cSPeter Brune -  ctx - context for residual evaluation
46924989b8cSPeter Brune 
47024989b8cSPeter Brune    Level: advanced
47124989b8cSPeter Brune 
47224989b8cSPeter Brune    Note:
47324989b8cSPeter Brune    TSSetJacobian() is normally used, but it calls this function internally because the user context is actually
47424989b8cSPeter Brune    associated with the DM.  This makes the interface consistent regardless of whether the user interacts with a DM or
47524989b8cSPeter Brune    not. If DM took a more central role at some later date, this could become the primary method of setting the Jacobian.
47624989b8cSPeter Brune 
47724989b8cSPeter Brune .seealso: DMTSSetContext(), TSSetFunction(), DMTSGetJacobian(), TSSetJacobian()
47824989b8cSPeter Brune @*/
47924989b8cSPeter Brune PetscErrorCode DMTSSetIJacobian(DM dm,TSIJacobian func,void *ctx)
48024989b8cSPeter Brune {
48124989b8cSPeter Brune   PetscErrorCode ierr;
482942e3340SBarry Smith   DMTS           sdm;
48324989b8cSPeter Brune 
48424989b8cSPeter Brune   PetscFunctionBegin;
48524989b8cSPeter Brune   PetscValidHeaderSpecific(dm,DM_CLASSID,1);
486942e3340SBarry Smith   ierr = DMGetDMTSWrite(dm,&sdm);CHKERRQ(ierr);
487d74926cbSBarry Smith   if (func) sdm->ops->ijacobian = func;
48824989b8cSPeter Brune   if (ctx)  sdm->ijacobianctx   = ctx;
48924989b8cSPeter Brune   PetscFunctionReturn(0);
49024989b8cSPeter Brune }
49124989b8cSPeter Brune 
49224989b8cSPeter Brune #undef __FUNCT__
49324989b8cSPeter Brune #define __FUNCT__ "DMTSGetIJacobian"
49424989b8cSPeter Brune /*@C
49524989b8cSPeter Brune    DMTSGetIJacobian - get TS Jacobian evaluation function
49624989b8cSPeter Brune 
49724989b8cSPeter Brune    Not Collective
49824989b8cSPeter Brune 
49924989b8cSPeter Brune    Input Argument:
50024989b8cSPeter Brune .  dm - DM to be used with TS
50124989b8cSPeter Brune 
50224989b8cSPeter Brune    Output Arguments:
50324989b8cSPeter Brune +  func - Jacobian evaluation function, see TSSetIJacobian() for calling sequence
50424989b8cSPeter Brune -  ctx - context for residual evaluation
50524989b8cSPeter Brune 
50624989b8cSPeter Brune    Level: advanced
50724989b8cSPeter Brune 
50824989b8cSPeter Brune    Note:
50924989b8cSPeter Brune    TSGetJacobian() 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 Jacobian.
51224989b8cSPeter Brune 
51324989b8cSPeter Brune .seealso: DMTSSetContext(), TSSetFunction(), DMTSSetJacobian()
51424989b8cSPeter Brune @*/
51524989b8cSPeter Brune PetscErrorCode DMTSGetIJacobian(DM dm,TSIJacobian *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 = DMGetDMTS(dm,&tsdm);CHKERRQ(ierr);
523d74926cbSBarry Smith   if (func) *func = tsdm->ops->ijacobian;
52424989b8cSPeter Brune   if (ctx)  *ctx = tsdm->ijacobianctx;
52524989b8cSPeter Brune   PetscFunctionReturn(0);
52624989b8cSPeter Brune }
52724989b8cSPeter Brune 
52824989b8cSPeter Brune 
52924989b8cSPeter Brune #undef __FUNCT__
53024989b8cSPeter Brune #define __FUNCT__ "DMTSSetRHSJacobian"
53124989b8cSPeter Brune /*@C
53224989b8cSPeter Brune    DMTSSetRHSJacobian - set TS Jacobian evaluation function
53324989b8cSPeter Brune 
53424989b8cSPeter Brune    Not Collective
53524989b8cSPeter Brune 
53624989b8cSPeter Brune    Input Argument:
53724989b8cSPeter Brune +  dm - DM to be used with TS
53824989b8cSPeter Brune .  func - Jacobian evaluation function, see TSSetRHSJacobian() for calling sequence
53924989b8cSPeter Brune -  ctx - context for residual evaluation
54024989b8cSPeter Brune 
54124989b8cSPeter Brune    Level: advanced
54224989b8cSPeter Brune 
54324989b8cSPeter Brune    Note:
54424989b8cSPeter Brune    TSSetJacobian() is normally used, but it calls this function internally because the user context is actually
54524989b8cSPeter Brune    associated with the DM.  This makes the interface consistent regardless of whether the user interacts with a DM or
54624989b8cSPeter Brune    not. If DM took a more central role at some later date, this could become the primary method of setting the Jacobian.
54724989b8cSPeter Brune 
54824989b8cSPeter Brune .seealso: DMTSSetContext(), TSSetFunction(), DMTSGetJacobian(), TSSetJacobian()
54924989b8cSPeter Brune @*/
55024989b8cSPeter Brune PetscErrorCode DMTSSetRHSJacobian(DM dm,TSRHSJacobian func,void *ctx)
55124989b8cSPeter Brune {
55224989b8cSPeter Brune   PetscErrorCode ierr;
553942e3340SBarry Smith   DMTS           tsdm;
55424989b8cSPeter Brune 
55524989b8cSPeter Brune   PetscFunctionBegin;
55624989b8cSPeter Brune   PetscValidHeaderSpecific(dm,DM_CLASSID,1);
557942e3340SBarry Smith   ierr = DMGetDMTSWrite(dm,&tsdm);CHKERRQ(ierr);
558d74926cbSBarry Smith   if (func) tsdm->ops->rhsjacobian = func;
55924989b8cSPeter Brune   if (ctx)  tsdm->rhsjacobianctx = ctx;
56024989b8cSPeter Brune   PetscFunctionReturn(0);
56124989b8cSPeter Brune }
56224989b8cSPeter Brune 
56324989b8cSPeter Brune #undef __FUNCT__
56424989b8cSPeter Brune #define __FUNCT__ "DMTSGetRHSJacobian"
56524989b8cSPeter Brune /*@C
56624989b8cSPeter Brune    DMTSGetRHSJacobian - get TS Jacobian evaluation function
56724989b8cSPeter Brune 
56824989b8cSPeter Brune    Not Collective
56924989b8cSPeter Brune 
57024989b8cSPeter Brune    Input Argument:
57124989b8cSPeter Brune .  dm - DM to be used with TS
57224989b8cSPeter Brune 
57324989b8cSPeter Brune    Output Arguments:
57424989b8cSPeter Brune +  func - Jacobian evaluation function, see TSSetRHSJacobian() for calling sequence
57524989b8cSPeter Brune -  ctx - context for residual evaluation
57624989b8cSPeter Brune 
57724989b8cSPeter Brune    Level: advanced
57824989b8cSPeter Brune 
57924989b8cSPeter Brune    Note:
58024989b8cSPeter Brune    TSGetJacobian() is normally used, but it calls this function internally because the user context is actually
58124989b8cSPeter Brune    associated with the DM.  This makes the interface consistent regardless of whether the user interacts with a DM or
58224989b8cSPeter Brune    not. If DM took a more central role at some later date, this could become the primary method of setting the Jacobian.
58324989b8cSPeter Brune 
58424989b8cSPeter Brune .seealso: DMTSSetContext(), TSSetFunction(), DMTSSetJacobian()
58524989b8cSPeter Brune @*/
58624989b8cSPeter Brune PetscErrorCode DMTSGetRHSJacobian(DM dm,TSRHSJacobian *func,void **ctx)
58724989b8cSPeter Brune {
58824989b8cSPeter Brune   PetscErrorCode ierr;
589942e3340SBarry Smith   DMTS           tsdm;
59024989b8cSPeter Brune 
59124989b8cSPeter Brune   PetscFunctionBegin;
59224989b8cSPeter Brune   PetscValidHeaderSpecific(dm,DM_CLASSID,1);
593942e3340SBarry Smith   ierr = DMGetDMTS(dm,&tsdm);CHKERRQ(ierr);
594d74926cbSBarry Smith   if (func) *func = tsdm->ops->rhsjacobian;
59524989b8cSPeter Brune   if (ctx)  *ctx = tsdm->rhsjacobianctx;
59624989b8cSPeter Brune   PetscFunctionReturn(0);
59724989b8cSPeter Brune }
598