xref: /petsc/src/ts/utils/dmts.c (revision ad6bc4219076b084d4a49a29c04a77944f238f10)
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__
202d53ad75SBarry Smith #define __FUNCT__ "DMTSLoad"
212d53ad75SBarry Smith PetscErrorCode DMTSLoad(DMTS kdm,PetscViewer viewer)
222d53ad75SBarry Smith {
232d53ad75SBarry Smith   PetscErrorCode ierr;
242d53ad75SBarry Smith 
252d53ad75SBarry Smith   PetscFunctionBegin;
262d53ad75SBarry Smith   ierr = PetscViewerBinaryRead(viewer,&kdm->ops->ifunction,1,PETSC_FUNCTION);CHKERRQ(ierr);
27*ad6bc421SBarry Smith   ierr = PetscViewerBinaryRead(viewer,&kdm->ops->ifunctionview,1,PETSC_FUNCTION);CHKERRQ(ierr);
28*ad6bc421SBarry Smith   ierr = PetscViewerBinaryRead(viewer,&kdm->ops->ifunctionload,1,PETSC_FUNCTION);CHKERRQ(ierr);
29*ad6bc421SBarry Smith   if (kdm->ops->ifunctionload) {
30*ad6bc421SBarry Smith     ierr = (*kdm->ops->ifunctionload)(&kdm->ifunctionctx,viewer);CHKERRQ(ierr);
31*ad6bc421SBarry Smith   }
322d53ad75SBarry Smith   ierr = PetscViewerBinaryRead(viewer,&kdm->ops->ijacobian,1,PETSC_FUNCTION);CHKERRQ(ierr);
33*ad6bc421SBarry Smith   ierr = PetscViewerBinaryRead(viewer,&kdm->ops->ijacobianview,1,PETSC_FUNCTION);CHKERRQ(ierr);
34*ad6bc421SBarry Smith   ierr = PetscViewerBinaryRead(viewer,&kdm->ops->ijacobianload,1,PETSC_FUNCTION);CHKERRQ(ierr);
35*ad6bc421SBarry Smith   if (kdm->ops->ijacobianload) {
36*ad6bc421SBarry Smith     ierr = (*kdm->ops->ijacobianload)(&kdm->ijacobianctx,viewer);CHKERRQ(ierr);
37*ad6bc421SBarry 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) {
522d53ad75SBarry Smith     const char *fname;
532d53ad75SBarry Smith 
542d53ad75SBarry Smith     ierr = PetscFPTFind(kdm->ops->ifunction,&fname);CHKERRQ(ierr);
552d53ad75SBarry Smith     if (fname) {
562d53ad75SBarry Smith       ierr = PetscViewerASCIIPrintf(viewer,"  IFunction used by TS: %s\n",fname);CHKERRQ(ierr);
572d53ad75SBarry Smith     }
582d53ad75SBarry Smith     ierr = PetscFPTFind(kdm->ops->ijacobian,&fname);CHKERRQ(ierr);
592d53ad75SBarry Smith     if (fname) {
602d53ad75SBarry Smith       ierr = PetscViewerASCIIPrintf(viewer,"  IJacobian function used by TS: %s\n",fname);CHKERRQ(ierr);
612d53ad75SBarry Smith     }
622d53ad75SBarry Smith   } else if (isbinary) {
632d53ad75SBarry Smith     ierr = PetscViewerBinaryWrite(viewer,kdm->ops->ifunction,1,PETSC_FUNCTION,PETSC_FALSE);CHKERRQ(ierr);
64*ad6bc421SBarry Smith     ierr = PetscViewerBinaryWrite(viewer,kdm->ops->ifunctionview,1,PETSC_FUNCTION,PETSC_FALSE);CHKERRQ(ierr);
65*ad6bc421SBarry Smith     ierr = PetscViewerBinaryWrite(viewer,kdm->ops->ifunctionload,1,PETSC_FUNCTION,PETSC_FALSE);CHKERRQ(ierr);
66*ad6bc421SBarry Smith     if (kdm->ops->ifunctionview) {
67*ad6bc421SBarry Smith       ierr = (*kdm->ops->ifunctionview)(kdm->ifunctionctx,viewer);CHKERRQ(ierr);
68*ad6bc421SBarry Smith     }
692d53ad75SBarry Smith     ierr = PetscViewerBinaryWrite(viewer,kdm->ops->ijacobian,1,PETSC_FUNCTION,PETSC_FALSE);CHKERRQ(ierr);
70*ad6bc421SBarry Smith     ierr = PetscViewerBinaryWrite(viewer,kdm->ops->ijacobianview,1,PETSC_FUNCTION,PETSC_FALSE);CHKERRQ(ierr);
71*ad6bc421SBarry Smith     ierr = PetscViewerBinaryWrite(viewer,kdm->ops->ijacobianload,1,PETSC_FUNCTION,PETSC_FALSE);CHKERRQ(ierr);
72*ad6bc421SBarry Smith     if (kdm->ops->ijacobianview) {
73*ad6bc421SBarry Smith       ierr = (*kdm->ops->ijacobianview)(kdm->ijacobianctx,viewer);CHKERRQ(ierr);
74*ad6bc421SBarry Smith     }
752d53ad75SBarry Smith   }
762d53ad75SBarry Smith   PetscFunctionReturn(0);
772d53ad75SBarry Smith }
782d53ad75SBarry Smith 
792d53ad75SBarry Smith #undef __FUNCT__
80d74926cbSBarry Smith #define __FUNCT__ "DMTSCreate"
81d74926cbSBarry Smith static PetscErrorCode DMTSCreate(MPI_Comm comm,DMTS *kdm)
82d74926cbSBarry Smith {
83d74926cbSBarry Smith   PetscErrorCode ierr;
84d74926cbSBarry Smith 
85d74926cbSBarry Smith   PetscFunctionBegin;
86d74926cbSBarry Smith #ifndef PETSC_USE_DYNAMIC_LIBRARIES
87d74926cbSBarry Smith   ierr = TSInitializePackage(PETSC_NULL);CHKERRQ(ierr);
88d74926cbSBarry Smith #endif
892d53ad75SBarry Smith   ierr = PetscHeaderCreate(*kdm, _p_DMTS, struct _DMTSOps, DMTS_CLASSID, -1, "DMTS", "DMTS", "DMTS", comm, DMTSDestroy, DMTSView);CHKERRQ(ierr);
90d74926cbSBarry Smith   ierr = PetscMemzero((*kdm)->ops, sizeof(struct _DMTSOps));CHKERRQ(ierr);
91d74926cbSBarry Smith   PetscFunctionReturn(0);
92d74926cbSBarry Smith }
9324989b8cSPeter Brune 
9424989b8cSPeter Brune #undef __FUNCT__
95942e3340SBarry Smith #define __FUNCT__ "DMCoarsenHook_DMTS"
962a34c10cSBarry Smith /* Attaches the DMTS to the coarse level.
9724989b8cSPeter Brune  * Under what conditions should we copy versus duplicate?
9824989b8cSPeter Brune  */
99942e3340SBarry Smith static PetscErrorCode DMCoarsenHook_DMTS(DM dm,DM dmc,void *ctx)
10024989b8cSPeter Brune {
10124989b8cSPeter Brune   PetscErrorCode ierr;
10224989b8cSPeter Brune 
10324989b8cSPeter Brune   PetscFunctionBegin;
104942e3340SBarry Smith   ierr = DMCopyDMTS(dm,dmc);CHKERRQ(ierr);
10524989b8cSPeter Brune   PetscFunctionReturn(0);
10624989b8cSPeter Brune }
10724989b8cSPeter Brune 
10824989b8cSPeter Brune #undef __FUNCT__
109942e3340SBarry Smith #define __FUNCT__ "DMRestrictHook_DMTS"
11024989b8cSPeter Brune /* This could restrict auxiliary information to the coarse level.
11124989b8cSPeter Brune  */
112942e3340SBarry Smith static PetscErrorCode DMRestrictHook_DMTS(DM dm,Mat Restrict,Vec rscale,Mat Inject,DM dmc,void *ctx)
11324989b8cSPeter Brune {
11424989b8cSPeter Brune 
11524989b8cSPeter Brune   PetscFunctionBegin;
11624989b8cSPeter Brune   PetscFunctionReturn(0);
11724989b8cSPeter Brune }
11824989b8cSPeter Brune 
11924989b8cSPeter Brune #undef __FUNCT__
120d74926cbSBarry Smith #define __FUNCT__ "DMTSCopy"
121d74926cbSBarry Smith /*@C
122d74926cbSBarry Smith    DMTSCopy - copies the information in a DMTS to another DMTS
123d74926cbSBarry Smith 
124d74926cbSBarry Smith    Not Collective
125d74926cbSBarry Smith 
126d74926cbSBarry Smith    Input Argument:
127d74926cbSBarry Smith +  kdm - Original DMTS
128d74926cbSBarry Smith -  nkdm - DMTS to receive the data, should have been created with DMTSCreate()
129d74926cbSBarry Smith 
130d74926cbSBarry Smith    Level: developer
131d74926cbSBarry Smith 
132d74926cbSBarry Smith .seealso: DMTSCreate(), DMTSDestroy()
133d74926cbSBarry Smith @*/
134d74926cbSBarry Smith PetscErrorCode DMTSCopy(DMTS kdm,DMTS nkdm)
13524989b8cSPeter Brune {
13624989b8cSPeter Brune   PetscErrorCode ierr;
13724989b8cSPeter Brune 
13824989b8cSPeter Brune   PetscFunctionBegin;
139d74926cbSBarry Smith   PetscValidHeaderSpecific(kdm,DMTS_CLASSID,1);
140d74926cbSBarry Smith   PetscValidHeaderSpecific(nkdm,DMTS_CLASSID,2);
141d74926cbSBarry Smith   nkdm->ops->rhsfunction    = kdm->ops->rhsfunction;
142d74926cbSBarry Smith   nkdm->ops->rhsjacobian    = kdm->ops->rhsjacobian;
143d74926cbSBarry Smith   nkdm->ops->ifunction      = kdm->ops->ifunction;
144d74926cbSBarry Smith   nkdm->ops->ijacobian      = kdm->ops->ijacobian;
145d74926cbSBarry Smith   nkdm->ops->solution       = kdm->ops->solution;
146d74926cbSBarry Smith   nkdm->ops->destroy        = kdm->ops->destroy;
147d74926cbSBarry Smith   nkdm->ops->duplicate      = kdm->ops->duplicate;
148d74926cbSBarry Smith 
149d74926cbSBarry Smith   nkdm->rhsfunctionctx      = kdm->rhsfunctionctx;
150d74926cbSBarry Smith   nkdm->rhsjacobianctx      = kdm->rhsjacobianctx;
151d74926cbSBarry Smith   nkdm->ifunctionctx        = kdm->ifunctionctx;
152d74926cbSBarry Smith   nkdm->ijacobianctx        = kdm->ijacobianctx;
153d74926cbSBarry Smith   nkdm->solutionctx         = kdm->solutionctx;
154d74926cbSBarry Smith 
155d74926cbSBarry Smith   nkdm->data             = kdm->data;
156d74926cbSBarry Smith 
157d74926cbSBarry Smith   /*
158d74926cbSBarry Smith   nkdm->fortran_func_pointers[0] = kdm->fortran_func_pointers[0];
159d74926cbSBarry Smith   nkdm->fortran_func_pointers[1] = kdm->fortran_func_pointers[1];
160d74926cbSBarry Smith   nkdm->fortran_func_pointers[2] = kdm->fortran_func_pointers[2];
161d74926cbSBarry Smith   */
162d74926cbSBarry Smith 
163d74926cbSBarry Smith   /* implementation specific copy hooks */
164d74926cbSBarry Smith   if (kdm->ops->duplicate) {ierr = (*kdm->ops->duplicate)(kdm,nkdm);CHKERRQ(ierr);}
16524989b8cSPeter Brune   PetscFunctionReturn(0);
16624989b8cSPeter Brune }
16724989b8cSPeter Brune 
16824989b8cSPeter Brune #undef __FUNCT__
169942e3340SBarry Smith #define __FUNCT__ "DMGetDMTS"
17024989b8cSPeter Brune /*@C
171942e3340SBarry Smith    DMGetDMTS - get read-only private DMTS context from a DM
17224989b8cSPeter Brune 
17324989b8cSPeter Brune    Not Collective
17424989b8cSPeter Brune 
17524989b8cSPeter Brune    Input Argument:
17624989b8cSPeter Brune .  dm - DM to be used with TS
17724989b8cSPeter Brune 
17824989b8cSPeter Brune    Output Argument:
179942e3340SBarry Smith .  tsdm - private DMTS context
18024989b8cSPeter Brune 
18124989b8cSPeter Brune    Level: developer
18224989b8cSPeter Brune 
18324989b8cSPeter Brune    Notes:
184942e3340SBarry Smith    Use DMGetDMTSWrite() if write access is needed. The DMTSSetXXX API should be used wherever possible.
18524989b8cSPeter Brune 
186942e3340SBarry Smith .seealso: DMGetDMTSWrite()
18724989b8cSPeter Brune @*/
188942e3340SBarry Smith PetscErrorCode DMGetDMTS(DM dm,DMTS *tsdm)
18924989b8cSPeter Brune {
19024989b8cSPeter Brune   PetscErrorCode ierr;
19124989b8cSPeter Brune 
19224989b8cSPeter Brune   PetscFunctionBegin;
19324989b8cSPeter Brune   PetscValidHeaderSpecific(dm,DM_CLASSID,1);
1942a34c10cSBarry Smith   *tsdm = (DMTS) dm->dmts;
195d74926cbSBarry Smith   if (!*tsdm) {
196942e3340SBarry Smith     ierr = PetscInfo(dm,"Creating new DMTS\n");CHKERRQ(ierr);
197d74926cbSBarry Smith     ierr = DMTSCreate(((PetscObject)dm)->comm,tsdm);CHKERRQ(ierr);
1982a34c10cSBarry Smith     dm->dmts = (PetscObject) *tsdm;
199942e3340SBarry Smith     ierr = DMCoarsenHookAdd(dm,DMCoarsenHook_DMTS,DMRestrictHook_DMTS,PETSC_NULL);CHKERRQ(ierr);
20024989b8cSPeter Brune   }
20124989b8cSPeter Brune   PetscFunctionReturn(0);
20224989b8cSPeter Brune }
20324989b8cSPeter Brune 
20424989b8cSPeter Brune #undef __FUNCT__
205942e3340SBarry Smith #define __FUNCT__ "DMGetDMTSWrite"
20624989b8cSPeter Brune /*@C
207942e3340SBarry Smith    DMGetDMTSWrite - get write access to private DMTS context from a DM
20824989b8cSPeter Brune 
20924989b8cSPeter Brune    Not Collective
21024989b8cSPeter Brune 
21124989b8cSPeter Brune    Input Argument:
21224989b8cSPeter Brune .  dm - DM to be used with TS
21324989b8cSPeter Brune 
21424989b8cSPeter Brune    Output Argument:
215942e3340SBarry Smith .  tsdm - private DMTS context
21624989b8cSPeter Brune 
21724989b8cSPeter Brune    Level: developer
21824989b8cSPeter Brune 
219942e3340SBarry Smith .seealso: DMGetDMTS()
22024989b8cSPeter Brune @*/
221942e3340SBarry Smith PetscErrorCode DMGetDMTSWrite(DM dm,DMTS *tsdm)
22224989b8cSPeter Brune {
22324989b8cSPeter Brune   PetscErrorCode ierr;
224942e3340SBarry Smith   DMTS           sdm;
22524989b8cSPeter Brune 
22624989b8cSPeter Brune   PetscFunctionBegin;
22724989b8cSPeter Brune   PetscValidHeaderSpecific(dm,DM_CLASSID,1);
228942e3340SBarry Smith   ierr = DMGetDMTS(dm,&sdm);CHKERRQ(ierr);
22924989b8cSPeter Brune   if (!sdm->originaldm) sdm->originaldm = dm;
23024989b8cSPeter Brune   if (sdm->originaldm != dm) {  /* Copy on write */
2312a34c10cSBarry Smith     DMTS          oldsdm = sdm;
232942e3340SBarry Smith     ierr = PetscInfo(dm,"Copying DMTS due to write\n");CHKERRQ(ierr);
233d74926cbSBarry Smith     ierr = DMTSCreate(((PetscObject)dm)->comm,&sdm);CHKERRQ(ierr);
234d74926cbSBarry Smith     ierr = DMTSCopy(oldsdm,sdm);CHKERRQ(ierr);
2352a34c10cSBarry Smith     ierr = DMTSDestroy((DMTS*)&dm->dmts);CHKERRQ(ierr);
2362a34c10cSBarry Smith     dm->dmts = (PetscObject) sdm;
23724989b8cSPeter Brune   }
23824989b8cSPeter Brune   *tsdm = sdm;
23924989b8cSPeter Brune   PetscFunctionReturn(0);
24024989b8cSPeter Brune }
24124989b8cSPeter Brune 
24224989b8cSPeter Brune #undef __FUNCT__
243942e3340SBarry Smith #define __FUNCT__ "DMCopyDMTS"
24424989b8cSPeter Brune /*@C
245942e3340SBarry Smith    DMCopyDMTS - copies a DM context to a new DM
24624989b8cSPeter Brune 
24724989b8cSPeter Brune    Logically Collective
24824989b8cSPeter Brune 
24924989b8cSPeter Brune    Input Arguments:
25024989b8cSPeter Brune +  dmsrc - DM to obtain context from
25124989b8cSPeter Brune -  dmdest - DM to add context to
25224989b8cSPeter Brune 
25324989b8cSPeter Brune    Level: developer
25424989b8cSPeter Brune 
25524989b8cSPeter Brune    Note:
25624989b8cSPeter Brune    The context is copied by reference. This function does not ensure that a context exists.
25724989b8cSPeter Brune 
258942e3340SBarry Smith .seealso: DMGetDMTS(), TSSetDM()
25924989b8cSPeter Brune @*/
260942e3340SBarry Smith PetscErrorCode DMCopyDMTS(DM dmsrc,DM dmdest)
26124989b8cSPeter Brune {
26224989b8cSPeter Brune   PetscErrorCode ierr;
26324989b8cSPeter Brune 
26424989b8cSPeter Brune   PetscFunctionBegin;
26524989b8cSPeter Brune   PetscValidHeaderSpecific(dmsrc,DM_CLASSID,1);
26624989b8cSPeter Brune   PetscValidHeaderSpecific(dmdest,DM_CLASSID,2);
2672a34c10cSBarry Smith   ierr = DMTSDestroy((DMTS*)&dmdest->dmts);CHKERRQ(ierr);
2682a34c10cSBarry Smith   dmdest->dmts = dmsrc->dmts;
2692a34c10cSBarry Smith   ierr = PetscObjectReference(dmdest->dmts);CHKERRQ(ierr);
270942e3340SBarry Smith   ierr = DMCoarsenHookAdd(dmdest,DMCoarsenHook_DMTS,DMRestrictHook_DMTS,PETSC_NULL);CHKERRQ(ierr);
27124989b8cSPeter Brune   PetscFunctionReturn(0);
27224989b8cSPeter Brune }
27324989b8cSPeter Brune 
27424989b8cSPeter Brune #undef __FUNCT__
27524989b8cSPeter Brune #define __FUNCT__ "DMTSSetIFunction"
27624989b8cSPeter Brune /*@C
27724989b8cSPeter Brune    DMTSSetIFunction - set TS implicit function evaluation function
27824989b8cSPeter Brune 
27924989b8cSPeter Brune    Not Collective
28024989b8cSPeter Brune 
28124989b8cSPeter Brune    Input Arguments:
28224989b8cSPeter Brune +  dm - DM to be used with TS
28324989b8cSPeter Brune .  func - function evaluation function, see TSSetIFunction() for calling sequence
28424989b8cSPeter Brune -  ctx - context for residual evaluation
28524989b8cSPeter Brune 
28624989b8cSPeter Brune    Level: advanced
28724989b8cSPeter Brune 
28824989b8cSPeter Brune    Note:
28924989b8cSPeter Brune    TSSetFunction() is normally used, but it calls this function internally because the user context is actually
29024989b8cSPeter Brune    associated with the DM.  This makes the interface consistent regardless of whether the user interacts with a DM or
29124989b8cSPeter Brune    not. If DM took a more central role at some later date, this could become the primary method of setting the residual.
29224989b8cSPeter Brune 
29324989b8cSPeter Brune .seealso: DMTSSetContext(), TSSetFunction(), DMTSSetJacobian()
29424989b8cSPeter Brune @*/
29524989b8cSPeter Brune PetscErrorCode DMTSSetIFunction(DM dm,TSIFunction func,void *ctx)
29624989b8cSPeter Brune {
29724989b8cSPeter Brune   PetscErrorCode ierr;
298942e3340SBarry Smith   DMTS           tsdm;
29924989b8cSPeter Brune 
30024989b8cSPeter Brune   PetscFunctionBegin;
30124989b8cSPeter Brune   PetscValidHeaderSpecific(dm,DM_CLASSID,1);
302942e3340SBarry Smith   ierr = DMGetDMTSWrite(dm,&tsdm);CHKERRQ(ierr);
303d74926cbSBarry Smith   if (func) tsdm->ops->ifunction = func;
30424989b8cSPeter Brune   if (ctx)  tsdm->ifunctionctx = ctx;
30524989b8cSPeter Brune   PetscFunctionReturn(0);
30624989b8cSPeter Brune }
30724989b8cSPeter Brune 
30824989b8cSPeter Brune #undef __FUNCT__
30924989b8cSPeter Brune #define __FUNCT__ "DMTSGetIFunction"
31024989b8cSPeter Brune /*@C
31124989b8cSPeter Brune    DMTSGetIFunction - get TS implicit residual evaluation function
31224989b8cSPeter Brune 
31324989b8cSPeter Brune    Not Collective
31424989b8cSPeter Brune 
31524989b8cSPeter Brune    Input Argument:
31624989b8cSPeter Brune .  dm - DM to be used with TS
31724989b8cSPeter Brune 
31824989b8cSPeter Brune    Output Arguments:
31924989b8cSPeter Brune +  func - function evaluation function, see TSSetIFunction() for calling sequence
32024989b8cSPeter Brune -  ctx - context for residual evaluation
32124989b8cSPeter Brune 
32224989b8cSPeter Brune    Level: advanced
32324989b8cSPeter Brune 
32424989b8cSPeter Brune    Note:
32524989b8cSPeter Brune    TSGetFunction() is normally used, but it calls this function internally because the user context is actually
32624989b8cSPeter Brune    associated with the DM.
32724989b8cSPeter Brune 
32824989b8cSPeter Brune .seealso: DMTSSetContext(), DMTSSetFunction(), TSSetFunction()
32924989b8cSPeter Brune @*/
33024989b8cSPeter Brune PetscErrorCode DMTSGetIFunction(DM dm,TSIFunction *func,void **ctx)
33124989b8cSPeter Brune {
33224989b8cSPeter Brune   PetscErrorCode ierr;
333942e3340SBarry Smith   DMTS           tsdm;
33424989b8cSPeter Brune 
33524989b8cSPeter Brune   PetscFunctionBegin;
33624989b8cSPeter Brune   PetscValidHeaderSpecific(dm,DM_CLASSID,1);
337942e3340SBarry Smith   ierr = DMGetDMTS(dm,&tsdm);CHKERRQ(ierr);
338d74926cbSBarry Smith   if (func) *func = tsdm->ops->ifunction;
33924989b8cSPeter Brune   if (ctx)  *ctx = tsdm->ifunctionctx;
34024989b8cSPeter Brune   PetscFunctionReturn(0);
34124989b8cSPeter Brune }
34224989b8cSPeter Brune 
34324989b8cSPeter Brune 
34424989b8cSPeter Brune #undef __FUNCT__
34524989b8cSPeter Brune #define __FUNCT__ "DMTSSetRHSFunction"
34624989b8cSPeter Brune /*@C
34724989b8cSPeter Brune    DMTSSetRHSFunction - set TS explicit residual evaluation function
34824989b8cSPeter Brune 
34924989b8cSPeter Brune    Not Collective
35024989b8cSPeter Brune 
35124989b8cSPeter Brune    Input Arguments:
35224989b8cSPeter Brune +  dm - DM to be used with TS
35324989b8cSPeter Brune .  func - RHS function evaluation function, see TSSetRHSFunction() for calling sequence
35424989b8cSPeter Brune -  ctx - context for residual evaluation
35524989b8cSPeter Brune 
35624989b8cSPeter Brune    Level: advanced
35724989b8cSPeter Brune 
35824989b8cSPeter Brune    Note:
359ef20d060SBarry Smith    TSSetRSHFunction() is normally used, but it calls this function internally because the user context is actually
36024989b8cSPeter Brune    associated with the DM.  This makes the interface consistent regardless of whether the user interacts with a DM or
36124989b8cSPeter Brune    not. If DM took a more central role at some later date, this could become the primary method of setting the residual.
36224989b8cSPeter Brune 
36324989b8cSPeter Brune .seealso: DMTSSetContext(), TSSetFunction(), DMTSSetJacobian()
36424989b8cSPeter Brune @*/
36524989b8cSPeter Brune PetscErrorCode DMTSSetRHSFunction(DM dm,TSRHSFunction func,void *ctx)
36624989b8cSPeter Brune {
36724989b8cSPeter Brune   PetscErrorCode ierr;
368942e3340SBarry Smith   DMTS           tsdm;
36924989b8cSPeter Brune 
37024989b8cSPeter Brune   PetscFunctionBegin;
37124989b8cSPeter Brune   PetscValidHeaderSpecific(dm,DM_CLASSID,1);
372942e3340SBarry Smith   ierr = DMGetDMTSWrite(dm,&tsdm);CHKERRQ(ierr);
373d74926cbSBarry Smith   if (func) tsdm->ops->rhsfunction = func;
37424989b8cSPeter Brune   if (ctx)  tsdm->rhsfunctionctx = ctx;
37524989b8cSPeter Brune   PetscFunctionReturn(0);
37624989b8cSPeter Brune }
37724989b8cSPeter Brune 
37824989b8cSPeter Brune #undef __FUNCT__
379ef20d060SBarry Smith #define __FUNCT__ "DMTSGetSolutionFunction"
380ef20d060SBarry Smith /*@C
381ef20d060SBarry Smith    DMTSGetSolutionFunction - gets the TS solution evaluation function
382ef20d060SBarry Smith 
383ef20d060SBarry Smith    Not Collective
384ef20d060SBarry Smith 
385ef20d060SBarry Smith    Input Arguments:
386ef20d060SBarry Smith .  dm - DM to be used with TS
387ef20d060SBarry Smith 
388ef20d060SBarry Smith    Output Parameters:
389ef20d060SBarry Smith +  func - solution function evaluation function, see TSSetSolution() for calling sequence
390ef20d060SBarry Smith -  ctx - context for solution evaluation
391ef20d060SBarry Smith 
392ef20d060SBarry Smith    Level: advanced
393ef20d060SBarry Smith 
394ef20d060SBarry Smith .seealso: DMTSSetContext(), TSSetFunction(), DMTSSetJacobian()
395ef20d060SBarry Smith @*/
396ef20d060SBarry Smith PetscErrorCode DMTSGetSolutionFunction(DM dm,TSSolutionFunction *func,void **ctx)
397ef20d060SBarry Smith {
398ef20d060SBarry Smith   PetscErrorCode ierr;
399942e3340SBarry Smith   DMTS           tsdm;
400ef20d060SBarry Smith 
401ef20d060SBarry Smith   PetscFunctionBegin;
402ef20d060SBarry Smith   PetscValidHeaderSpecific(dm,DM_CLASSID,1);
403942e3340SBarry Smith   ierr = DMGetDMTS(dm,&tsdm);CHKERRQ(ierr);
404d74926cbSBarry Smith   if (func) *func = tsdm->ops->solution;
405ef20d060SBarry Smith   if (ctx)  *ctx  = tsdm->solutionctx;
406ef20d060SBarry Smith   PetscFunctionReturn(0);
407ef20d060SBarry Smith }
408ef20d060SBarry Smith 
409ef20d060SBarry Smith #undef __FUNCT__
410ef20d060SBarry Smith #define __FUNCT__ "DMTSSetSolutionFunction"
411ef20d060SBarry Smith /*@C
412ef20d060SBarry Smith    DMTSSetSolutionFunction - set TS solution evaluation function
413ef20d060SBarry Smith 
414ef20d060SBarry Smith    Not Collective
415ef20d060SBarry Smith 
416ef20d060SBarry Smith    Input Arguments:
417ef20d060SBarry Smith +  dm - DM to be used with TS
418ef20d060SBarry Smith .  func - solution function evaluation function, see TSSetSolution() for calling sequence
419ef20d060SBarry Smith -  ctx - context for solution evaluation
420ef20d060SBarry Smith 
421ef20d060SBarry Smith    Level: advanced
422ef20d060SBarry Smith 
423ef20d060SBarry Smith    Note:
424ef20d060SBarry Smith    TSSetSolutionFunction() is normally used, but it calls this function internally because the user context is actually
425ef20d060SBarry Smith    associated with the DM.  This makes the interface consistent regardless of whether the user interacts with a DM or
426ef20d060SBarry Smith    not. If DM took a more central role at some later date, this could become the primary method of setting the residual.
427ef20d060SBarry Smith 
428ef20d060SBarry Smith .seealso: DMTSSetContext(), TSSetFunction(), DMTSSetJacobian()
429ef20d060SBarry Smith @*/
430ef20d060SBarry Smith PetscErrorCode DMTSSetSolutionFunction(DM dm,TSSolutionFunction func,void *ctx)
431ef20d060SBarry Smith {
432ef20d060SBarry Smith   PetscErrorCode ierr;
433942e3340SBarry Smith   DMTS           tsdm;
434ef20d060SBarry Smith 
435ef20d060SBarry Smith   PetscFunctionBegin;
436ef20d060SBarry Smith   PetscValidHeaderSpecific(dm,DM_CLASSID,1);
437942e3340SBarry Smith   ierr = DMGetDMTSWrite(dm,&tsdm);CHKERRQ(ierr);
438d74926cbSBarry Smith   if (func) tsdm->ops->solution = func;
439ef20d060SBarry Smith   if (ctx)  tsdm->solutionctx   = ctx;
440ef20d060SBarry Smith   PetscFunctionReturn(0);
441ef20d060SBarry Smith }
442ef20d060SBarry Smith 
443ef20d060SBarry Smith #undef __FUNCT__
44424989b8cSPeter Brune #define __FUNCT__ "DMTSGetRHSFunction"
44524989b8cSPeter Brune /*@C
44624989b8cSPeter Brune    DMTSGetRHSFunction - get TS explicit residual evaluation function
44724989b8cSPeter Brune 
44824989b8cSPeter Brune    Not Collective
44924989b8cSPeter Brune 
45024989b8cSPeter Brune    Input Argument:
45124989b8cSPeter Brune .  dm - DM to be used with TS
45224989b8cSPeter Brune 
45324989b8cSPeter Brune    Output Arguments:
45424989b8cSPeter Brune +  func - residual evaluation function, see TSSetRHSFunction() for calling sequence
45524989b8cSPeter Brune -  ctx - context for residual evaluation
45624989b8cSPeter Brune 
45724989b8cSPeter Brune    Level: advanced
45824989b8cSPeter Brune 
45924989b8cSPeter Brune    Note:
46024989b8cSPeter Brune    TSGetFunction() is normally used, but it calls this function internally because the user context is actually
46124989b8cSPeter Brune    associated with the DM.
46224989b8cSPeter Brune 
46324989b8cSPeter Brune .seealso: DMTSSetContext(), DMTSSetFunction(), TSSetFunction()
46424989b8cSPeter Brune @*/
46524989b8cSPeter Brune PetscErrorCode DMTSGetRHSFunction(DM dm,TSRHSFunction *func,void **ctx)
46624989b8cSPeter Brune {
46724989b8cSPeter Brune   PetscErrorCode ierr;
468942e3340SBarry Smith   DMTS           tsdm;
46924989b8cSPeter Brune 
47024989b8cSPeter Brune   PetscFunctionBegin;
47124989b8cSPeter Brune   PetscValidHeaderSpecific(dm,DM_CLASSID,1);
472942e3340SBarry Smith   ierr = DMGetDMTS(dm,&tsdm);CHKERRQ(ierr);
473d74926cbSBarry Smith   if (func) *func = tsdm->ops->rhsfunction;
47424989b8cSPeter Brune   if (ctx)  *ctx = tsdm->rhsfunctionctx;
47524989b8cSPeter Brune   PetscFunctionReturn(0);
47624989b8cSPeter Brune }
47724989b8cSPeter Brune 
47824989b8cSPeter Brune #undef __FUNCT__
47924989b8cSPeter Brune #define __FUNCT__ "DMTSSetIJacobian"
48024989b8cSPeter Brune /*@C
48124989b8cSPeter Brune    DMTSSetIJacobian - set TS Jacobian evaluation function
48224989b8cSPeter Brune 
48324989b8cSPeter Brune    Not Collective
48424989b8cSPeter Brune 
48524989b8cSPeter Brune    Input Argument:
48624989b8cSPeter Brune +  dm - DM to be used with TS
48724989b8cSPeter Brune .  func - Jacobian evaluation function, see TSSetIJacobian() for calling sequence
48824989b8cSPeter Brune -  ctx - context for residual evaluation
48924989b8cSPeter Brune 
49024989b8cSPeter Brune    Level: advanced
49124989b8cSPeter Brune 
49224989b8cSPeter Brune    Note:
49324989b8cSPeter Brune    TSSetJacobian() is normally used, but it calls this function internally because the user context is actually
49424989b8cSPeter Brune    associated with the DM.  This makes the interface consistent regardless of whether the user interacts with a DM or
49524989b8cSPeter Brune    not. If DM took a more central role at some later date, this could become the primary method of setting the Jacobian.
49624989b8cSPeter Brune 
49724989b8cSPeter Brune .seealso: DMTSSetContext(), TSSetFunction(), DMTSGetJacobian(), TSSetJacobian()
49824989b8cSPeter Brune @*/
49924989b8cSPeter Brune PetscErrorCode DMTSSetIJacobian(DM dm,TSIJacobian func,void *ctx)
50024989b8cSPeter Brune {
50124989b8cSPeter Brune   PetscErrorCode ierr;
502942e3340SBarry Smith   DMTS           sdm;
50324989b8cSPeter Brune 
50424989b8cSPeter Brune   PetscFunctionBegin;
50524989b8cSPeter Brune   PetscValidHeaderSpecific(dm,DM_CLASSID,1);
506942e3340SBarry Smith   ierr = DMGetDMTSWrite(dm,&sdm);CHKERRQ(ierr);
507d74926cbSBarry Smith   if (func) sdm->ops->ijacobian = func;
50824989b8cSPeter Brune   if (ctx)  sdm->ijacobianctx   = ctx;
50924989b8cSPeter Brune   PetscFunctionReturn(0);
51024989b8cSPeter Brune }
51124989b8cSPeter Brune 
51224989b8cSPeter Brune #undef __FUNCT__
51324989b8cSPeter Brune #define __FUNCT__ "DMTSGetIJacobian"
51424989b8cSPeter Brune /*@C
51524989b8cSPeter Brune    DMTSGetIJacobian - get TS Jacobian evaluation function
51624989b8cSPeter Brune 
51724989b8cSPeter Brune    Not Collective
51824989b8cSPeter Brune 
51924989b8cSPeter Brune    Input Argument:
52024989b8cSPeter Brune .  dm - DM to be used with TS
52124989b8cSPeter Brune 
52224989b8cSPeter Brune    Output Arguments:
52324989b8cSPeter Brune +  func - Jacobian evaluation function, see TSSetIJacobian() for calling sequence
52424989b8cSPeter Brune -  ctx - context for residual evaluation
52524989b8cSPeter Brune 
52624989b8cSPeter Brune    Level: advanced
52724989b8cSPeter Brune 
52824989b8cSPeter Brune    Note:
52924989b8cSPeter Brune    TSGetJacobian() is normally used, but it calls this function internally because the user context is actually
53024989b8cSPeter Brune    associated with the DM.  This makes the interface consistent regardless of whether the user interacts with a DM or
53124989b8cSPeter Brune    not. If DM took a more central role at some later date, this could become the primary method of setting the Jacobian.
53224989b8cSPeter Brune 
53324989b8cSPeter Brune .seealso: DMTSSetContext(), TSSetFunction(), DMTSSetJacobian()
53424989b8cSPeter Brune @*/
53524989b8cSPeter Brune PetscErrorCode DMTSGetIJacobian(DM dm,TSIJacobian *func,void **ctx)
53624989b8cSPeter Brune {
53724989b8cSPeter Brune   PetscErrorCode ierr;
538942e3340SBarry Smith   DMTS           tsdm;
53924989b8cSPeter Brune 
54024989b8cSPeter Brune   PetscFunctionBegin;
54124989b8cSPeter Brune   PetscValidHeaderSpecific(dm,DM_CLASSID,1);
542942e3340SBarry Smith   ierr = DMGetDMTS(dm,&tsdm);CHKERRQ(ierr);
543d74926cbSBarry Smith   if (func) *func = tsdm->ops->ijacobian;
54424989b8cSPeter Brune   if (ctx)  *ctx = tsdm->ijacobianctx;
54524989b8cSPeter Brune   PetscFunctionReturn(0);
54624989b8cSPeter Brune }
54724989b8cSPeter Brune 
54824989b8cSPeter Brune 
54924989b8cSPeter Brune #undef __FUNCT__
55024989b8cSPeter Brune #define __FUNCT__ "DMTSSetRHSJacobian"
55124989b8cSPeter Brune /*@C
55224989b8cSPeter Brune    DMTSSetRHSJacobian - set TS Jacobian evaluation function
55324989b8cSPeter Brune 
55424989b8cSPeter Brune    Not Collective
55524989b8cSPeter Brune 
55624989b8cSPeter Brune    Input Argument:
55724989b8cSPeter Brune +  dm - DM to be used with TS
55824989b8cSPeter Brune .  func - Jacobian evaluation function, see TSSetRHSJacobian() for calling sequence
55924989b8cSPeter Brune -  ctx - context for residual evaluation
56024989b8cSPeter Brune 
56124989b8cSPeter Brune    Level: advanced
56224989b8cSPeter Brune 
56324989b8cSPeter Brune    Note:
56424989b8cSPeter Brune    TSSetJacobian() is normally used, but it calls this function internally because the user context is actually
56524989b8cSPeter Brune    associated with the DM.  This makes the interface consistent regardless of whether the user interacts with a DM or
56624989b8cSPeter Brune    not. If DM took a more central role at some later date, this could become the primary method of setting the Jacobian.
56724989b8cSPeter Brune 
56824989b8cSPeter Brune .seealso: DMTSSetContext(), TSSetFunction(), DMTSGetJacobian(), TSSetJacobian()
56924989b8cSPeter Brune @*/
57024989b8cSPeter Brune PetscErrorCode DMTSSetRHSJacobian(DM dm,TSRHSJacobian func,void *ctx)
57124989b8cSPeter Brune {
57224989b8cSPeter Brune   PetscErrorCode ierr;
573942e3340SBarry Smith   DMTS           tsdm;
57424989b8cSPeter Brune 
57524989b8cSPeter Brune   PetscFunctionBegin;
57624989b8cSPeter Brune   PetscValidHeaderSpecific(dm,DM_CLASSID,1);
577942e3340SBarry Smith   ierr = DMGetDMTSWrite(dm,&tsdm);CHKERRQ(ierr);
578d74926cbSBarry Smith   if (func) tsdm->ops->rhsjacobian = func;
57924989b8cSPeter Brune   if (ctx)  tsdm->rhsjacobianctx = ctx;
58024989b8cSPeter Brune   PetscFunctionReturn(0);
58124989b8cSPeter Brune }
58224989b8cSPeter Brune 
58324989b8cSPeter Brune #undef __FUNCT__
58424989b8cSPeter Brune #define __FUNCT__ "DMTSGetRHSJacobian"
58524989b8cSPeter Brune /*@C
58624989b8cSPeter Brune    DMTSGetRHSJacobian - get TS Jacobian evaluation function
58724989b8cSPeter Brune 
58824989b8cSPeter Brune    Not Collective
58924989b8cSPeter Brune 
59024989b8cSPeter Brune    Input Argument:
59124989b8cSPeter Brune .  dm - DM to be used with TS
59224989b8cSPeter Brune 
59324989b8cSPeter Brune    Output Arguments:
59424989b8cSPeter Brune +  func - Jacobian evaluation function, see TSSetRHSJacobian() for calling sequence
59524989b8cSPeter Brune -  ctx - context for residual evaluation
59624989b8cSPeter Brune 
59724989b8cSPeter Brune    Level: advanced
59824989b8cSPeter Brune 
59924989b8cSPeter Brune    Note:
60024989b8cSPeter Brune    TSGetJacobian() is normally used, but it calls this function internally because the user context is actually
60124989b8cSPeter Brune    associated with the DM.  This makes the interface consistent regardless of whether the user interacts with a DM or
60224989b8cSPeter Brune    not. If DM took a more central role at some later date, this could become the primary method of setting the Jacobian.
60324989b8cSPeter Brune 
60424989b8cSPeter Brune .seealso: DMTSSetContext(), TSSetFunction(), DMTSSetJacobian()
60524989b8cSPeter Brune @*/
60624989b8cSPeter Brune PetscErrorCode DMTSGetRHSJacobian(DM dm,TSRHSJacobian *func,void **ctx)
60724989b8cSPeter Brune {
60824989b8cSPeter Brune   PetscErrorCode ierr;
609942e3340SBarry Smith   DMTS           tsdm;
61024989b8cSPeter Brune 
61124989b8cSPeter Brune   PetscFunctionBegin;
61224989b8cSPeter Brune   PetscValidHeaderSpecific(dm,DM_CLASSID,1);
613942e3340SBarry Smith   ierr = DMGetDMTS(dm,&tsdm);CHKERRQ(ierr);
614d74926cbSBarry Smith   if (func) *func = tsdm->ops->rhsjacobian;
61524989b8cSPeter Brune   if (ctx)  *ctx = tsdm->rhsjacobianctx;
61624989b8cSPeter Brune   PetscFunctionReturn(0);
61724989b8cSPeter Brune }
618*ad6bc421SBarry Smith 
619*ad6bc421SBarry Smith #undef __FUNCT__
620*ad6bc421SBarry Smith #define __FUNCT__ "DMTSSetIFunctionSerialize"
621*ad6bc421SBarry Smith /*@C
622*ad6bc421SBarry Smith    DMTSSetIFunctionSerialize - sets functions used to view and load a IFunction context
623*ad6bc421SBarry Smith 
624*ad6bc421SBarry Smith    Not Collective
625*ad6bc421SBarry Smith 
626*ad6bc421SBarry Smith    Input Arguments:
627*ad6bc421SBarry Smith +  dm - DM to be used with TS
628*ad6bc421SBarry Smith .  view - viewer function
629*ad6bc421SBarry Smith -  load - loading function
630*ad6bc421SBarry Smith 
631*ad6bc421SBarry Smith    Level: advanced
632*ad6bc421SBarry Smith 
633*ad6bc421SBarry Smith .seealso: DMTSSetContext(), TSSetFunction(), DMTSSetJacobian()
634*ad6bc421SBarry Smith @*/
635*ad6bc421SBarry Smith PetscErrorCode DMTSSetIFunctionSerialize(DM dm,PetscErrorCode (*view)(void*,PetscViewer),PetscErrorCode (*load)(void**,PetscViewer))
636*ad6bc421SBarry Smith {
637*ad6bc421SBarry Smith   PetscErrorCode ierr;
638*ad6bc421SBarry Smith   DMTS           tsdm;
639*ad6bc421SBarry Smith 
640*ad6bc421SBarry Smith   PetscFunctionBegin;
641*ad6bc421SBarry Smith   PetscValidHeaderSpecific(dm,DM_CLASSID,1);
642*ad6bc421SBarry Smith   ierr = DMGetDMTSWrite(dm,&tsdm);CHKERRQ(ierr);
643*ad6bc421SBarry Smith   tsdm->ops->ifunctionview = view;
644*ad6bc421SBarry Smith   tsdm->ops->ifunctionload = load;
645*ad6bc421SBarry Smith   PetscFunctionReturn(0);
646*ad6bc421SBarry Smith }
647*ad6bc421SBarry Smith 
648*ad6bc421SBarry Smith #undef __FUNCT__
649*ad6bc421SBarry Smith #define __FUNCT__ "DMTSSetIJacobianSerialize"
650*ad6bc421SBarry Smith /*@C
651*ad6bc421SBarry Smith    DMTSSetIJacobianSerialize - sets functions used to view and load a IJacobian context
652*ad6bc421SBarry Smith 
653*ad6bc421SBarry Smith    Not Collective
654*ad6bc421SBarry Smith 
655*ad6bc421SBarry Smith    Input Arguments:
656*ad6bc421SBarry Smith +  dm - DM to be used with TS
657*ad6bc421SBarry Smith .  view - viewer function
658*ad6bc421SBarry Smith -  load - loading function
659*ad6bc421SBarry Smith 
660*ad6bc421SBarry Smith    Level: advanced
661*ad6bc421SBarry Smith 
662*ad6bc421SBarry Smith .seealso: DMTSSetContext(), TSSetFunction(), DMTSSetJacobian()
663*ad6bc421SBarry Smith @*/
664*ad6bc421SBarry Smith PetscErrorCode DMTSSetIJacobianSerialize(DM dm,PetscErrorCode (*view)(void*,PetscViewer),PetscErrorCode (*load)(void**,PetscViewer))
665*ad6bc421SBarry Smith {
666*ad6bc421SBarry Smith   PetscErrorCode ierr;
667*ad6bc421SBarry Smith   DMTS           tsdm;
668*ad6bc421SBarry Smith 
669*ad6bc421SBarry Smith   PetscFunctionBegin;
670*ad6bc421SBarry Smith   PetscValidHeaderSpecific(dm,DM_CLASSID,1);
671*ad6bc421SBarry Smith   ierr = DMGetDMTSWrite(dm,&tsdm);CHKERRQ(ierr);
672*ad6bc421SBarry Smith   tsdm->ops->ijacobianview = view;
673*ad6bc421SBarry Smith   tsdm->ops->ijacobianload = load;
674*ad6bc421SBarry Smith   PetscFunctionReturn(0);
675*ad6bc421SBarry Smith }
676