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; 2280298fd71SBarry Smith ierr = DMCoarsenHookAdd(dm,DMCoarsenHook_DMTS,DMRestrictHook_DMTS,NULL);CHKERRQ(ierr); 2290298fd71SBarry Smith ierr = DMSubDomainHookAdd(dm,DMSubDomainHook_DMTS,DMSubDomainRestrictHook_DMTS,NULL);CHKERRQ(ierr); 23024989b8cSPeter Brune } 23124989b8cSPeter Brune PetscFunctionReturn(0); 23224989b8cSPeter Brune } 23324989b8cSPeter Brune 23424989b8cSPeter Brune /*@C 235942e3340SBarry Smith DMGetDMTSWrite - get write access to private DMTS context from a DM 23624989b8cSPeter Brune 23724989b8cSPeter Brune Not Collective 23824989b8cSPeter Brune 23924989b8cSPeter Brune Input Argument: 24024989b8cSPeter Brune . dm - DM to be used with TS 24124989b8cSPeter Brune 24224989b8cSPeter Brune Output Argument: 243942e3340SBarry Smith . tsdm - private DMTS context 24424989b8cSPeter Brune 24524989b8cSPeter Brune Level: developer 24624989b8cSPeter Brune 247942e3340SBarry Smith .seealso: DMGetDMTS() 24824989b8cSPeter Brune @*/ 249942e3340SBarry Smith PetscErrorCode DMGetDMTSWrite(DM dm,DMTS *tsdm) 25024989b8cSPeter Brune { 25124989b8cSPeter Brune PetscErrorCode ierr; 252942e3340SBarry Smith DMTS sdm; 25324989b8cSPeter Brune 25424989b8cSPeter Brune PetscFunctionBegin; 25524989b8cSPeter Brune PetscValidHeaderSpecific(dm,DM_CLASSID,1); 256942e3340SBarry Smith ierr = DMGetDMTS(dm,&sdm);CHKERRQ(ierr); 25724989b8cSPeter Brune if (!sdm->originaldm) sdm->originaldm = dm; 25824989b8cSPeter Brune if (sdm->originaldm != dm) { /* Copy on write */ 2592a34c10cSBarry Smith DMTS oldsdm = sdm; 260942e3340SBarry Smith ierr = PetscInfo(dm,"Copying DMTS due to write\n");CHKERRQ(ierr); 261ce94432eSBarry Smith ierr = DMTSCreate(PetscObjectComm((PetscObject)dm),&sdm);CHKERRQ(ierr); 262d74926cbSBarry Smith ierr = DMTSCopy(oldsdm,sdm);CHKERRQ(ierr); 2632a34c10cSBarry Smith ierr = DMTSDestroy((DMTS*)&dm->dmts);CHKERRQ(ierr); 2642a34c10cSBarry Smith dm->dmts = (PetscObject) sdm; 26524989b8cSPeter Brune } 26624989b8cSPeter Brune *tsdm = sdm; 26724989b8cSPeter Brune PetscFunctionReturn(0); 26824989b8cSPeter Brune } 26924989b8cSPeter Brune 27024989b8cSPeter Brune /*@C 271942e3340SBarry Smith DMCopyDMTS - copies a DM context to a new DM 27224989b8cSPeter Brune 27324989b8cSPeter Brune Logically Collective 27424989b8cSPeter Brune 27524989b8cSPeter Brune Input Arguments: 27624989b8cSPeter Brune + dmsrc - DM to obtain context from 27724989b8cSPeter Brune - dmdest - DM to add context to 27824989b8cSPeter Brune 27924989b8cSPeter Brune Level: developer 28024989b8cSPeter Brune 28124989b8cSPeter Brune Note: 28224989b8cSPeter Brune The context is copied by reference. This function does not ensure that a context exists. 28324989b8cSPeter Brune 284942e3340SBarry Smith .seealso: DMGetDMTS(), TSSetDM() 28524989b8cSPeter Brune @*/ 286942e3340SBarry Smith PetscErrorCode DMCopyDMTS(DM dmsrc,DM dmdest) 28724989b8cSPeter Brune { 28824989b8cSPeter Brune PetscErrorCode ierr; 28924989b8cSPeter Brune 29024989b8cSPeter Brune PetscFunctionBegin; 29124989b8cSPeter Brune PetscValidHeaderSpecific(dmsrc,DM_CLASSID,1); 29224989b8cSPeter Brune PetscValidHeaderSpecific(dmdest,DM_CLASSID,2); 2932a34c10cSBarry Smith ierr = DMTSDestroy((DMTS*)&dmdest->dmts);CHKERRQ(ierr); 2942a34c10cSBarry Smith dmdest->dmts = dmsrc->dmts; 2952a34c10cSBarry Smith ierr = PetscObjectReference(dmdest->dmts);CHKERRQ(ierr); 2960298fd71SBarry Smith ierr = DMCoarsenHookAdd(dmdest,DMCoarsenHook_DMTS,DMRestrictHook_DMTS,NULL);CHKERRQ(ierr); 2970298fd71SBarry Smith ierr = DMSubDomainHookAdd(dmdest,DMSubDomainHook_DMTS,DMSubDomainRestrictHook_DMTS,NULL);CHKERRQ(ierr); 29824989b8cSPeter Brune PetscFunctionReturn(0); 29924989b8cSPeter Brune } 30024989b8cSPeter Brune 30124989b8cSPeter Brune /*@C 30224989b8cSPeter Brune DMTSSetIFunction - set TS implicit function evaluation function 30324989b8cSPeter Brune 30424989b8cSPeter Brune Not Collective 30524989b8cSPeter Brune 30624989b8cSPeter Brune Input Arguments: 30724989b8cSPeter Brune + dm - DM to be used with TS 30824989b8cSPeter Brune . func - function evaluation function, see TSSetIFunction() for calling sequence 30924989b8cSPeter Brune - ctx - context for residual evaluation 31024989b8cSPeter Brune 31124989b8cSPeter Brune Level: advanced 31224989b8cSPeter Brune 31324989b8cSPeter Brune Note: 31424989b8cSPeter Brune TSSetFunction() is normally used, but it calls this function internally because the user context is actually 31524989b8cSPeter Brune associated with the DM. This makes the interface consistent regardless of whether the user interacts with a DM or 31624989b8cSPeter Brune not. If DM took a more central role at some later date, this could become the primary method of setting the residual. 31724989b8cSPeter Brune 31824989b8cSPeter Brune .seealso: DMTSSetContext(), TSSetFunction(), DMTSSetJacobian() 31924989b8cSPeter Brune @*/ 32024989b8cSPeter Brune PetscErrorCode DMTSSetIFunction(DM dm,TSIFunction func,void *ctx) 32124989b8cSPeter Brune { 32224989b8cSPeter Brune PetscErrorCode ierr; 323942e3340SBarry Smith DMTS tsdm; 32424989b8cSPeter Brune 32524989b8cSPeter Brune PetscFunctionBegin; 32624989b8cSPeter Brune PetscValidHeaderSpecific(dm,DM_CLASSID,1); 327942e3340SBarry Smith ierr = DMGetDMTSWrite(dm,&tsdm);CHKERRQ(ierr); 328d74926cbSBarry Smith if (func) tsdm->ops->ifunction = func; 32924989b8cSPeter Brune if (ctx) tsdm->ifunctionctx = ctx; 33024989b8cSPeter Brune PetscFunctionReturn(0); 33124989b8cSPeter Brune } 33224989b8cSPeter Brune 33324989b8cSPeter Brune /*@C 33424989b8cSPeter Brune DMTSGetIFunction - get TS implicit residual evaluation function 33524989b8cSPeter Brune 33624989b8cSPeter Brune Not Collective 33724989b8cSPeter Brune 33824989b8cSPeter Brune Input Argument: 33924989b8cSPeter Brune . dm - DM to be used with TS 34024989b8cSPeter Brune 34124989b8cSPeter Brune Output Arguments: 34224989b8cSPeter Brune + func - function evaluation function, see TSSetIFunction() for calling sequence 34324989b8cSPeter Brune - ctx - context for residual evaluation 34424989b8cSPeter Brune 34524989b8cSPeter Brune Level: advanced 34624989b8cSPeter Brune 34724989b8cSPeter Brune Note: 34824989b8cSPeter Brune TSGetFunction() is normally used, but it calls this function internally because the user context is actually 34924989b8cSPeter Brune associated with the DM. 35024989b8cSPeter Brune 35124989b8cSPeter Brune .seealso: DMTSSetContext(), DMTSSetFunction(), TSSetFunction() 35224989b8cSPeter Brune @*/ 35324989b8cSPeter Brune PetscErrorCode DMTSGetIFunction(DM dm,TSIFunction *func,void **ctx) 35424989b8cSPeter Brune { 35524989b8cSPeter Brune PetscErrorCode ierr; 356942e3340SBarry Smith DMTS tsdm; 35724989b8cSPeter Brune 35824989b8cSPeter Brune PetscFunctionBegin; 35924989b8cSPeter Brune PetscValidHeaderSpecific(dm,DM_CLASSID,1); 360942e3340SBarry Smith ierr = DMGetDMTS(dm,&tsdm);CHKERRQ(ierr); 361d74926cbSBarry Smith if (func) *func = tsdm->ops->ifunction; 36224989b8cSPeter Brune if (ctx) *ctx = tsdm->ifunctionctx; 36324989b8cSPeter Brune PetscFunctionReturn(0); 36424989b8cSPeter Brune } 36524989b8cSPeter Brune 366efe9872eSLisandro Dalcin /*@C 367efe9872eSLisandro Dalcin DMTSSetI2Function - set TS implicit function evaluation function for 2nd order systems 368efe9872eSLisandro Dalcin 369efe9872eSLisandro Dalcin Not Collective 370efe9872eSLisandro Dalcin 371efe9872eSLisandro Dalcin Input Arguments: 372efe9872eSLisandro Dalcin + dm - DM to be used with TS 373efe9872eSLisandro Dalcin . fun - function evaluation function, see TSSetI2Function() for calling sequence 374efe9872eSLisandro Dalcin - ctx - context for residual evaluation 375efe9872eSLisandro Dalcin 376efe9872eSLisandro Dalcin Level: advanced 377efe9872eSLisandro Dalcin 378efe9872eSLisandro Dalcin Note: 379efe9872eSLisandro Dalcin TSSetI2Function() is normally used, but it calls this function internally because the user context is actually 380efe9872eSLisandro Dalcin associated with the DM. 381efe9872eSLisandro Dalcin 382efe9872eSLisandro Dalcin .seealso: TSSetI2Function() 383efe9872eSLisandro Dalcin @*/ 384efe9872eSLisandro Dalcin PetscErrorCode DMTSSetI2Function(DM dm,TSI2Function fun,void *ctx) 385efe9872eSLisandro Dalcin { 386efe9872eSLisandro Dalcin DMTS tsdm; 387efe9872eSLisandro Dalcin PetscErrorCode ierr; 388efe9872eSLisandro Dalcin 389efe9872eSLisandro Dalcin PetscFunctionBegin; 390efe9872eSLisandro Dalcin PetscValidHeaderSpecific(dm,DM_CLASSID,1); 391efe9872eSLisandro Dalcin ierr = DMGetDMTSWrite(dm,&tsdm);CHKERRQ(ierr); 392efe9872eSLisandro Dalcin if (fun) tsdm->ops->i2function = fun; 393efe9872eSLisandro Dalcin if (ctx) tsdm->i2functionctx = ctx; 394efe9872eSLisandro Dalcin PetscFunctionReturn(0); 395efe9872eSLisandro Dalcin } 396efe9872eSLisandro Dalcin 397efe9872eSLisandro Dalcin /*@C 398efe9872eSLisandro Dalcin DMTSGetI2Function - get TS implicit residual evaluation function for 2nd order systems 399efe9872eSLisandro Dalcin 400efe9872eSLisandro Dalcin Not Collective 401efe9872eSLisandro Dalcin 402efe9872eSLisandro Dalcin Input Argument: 403efe9872eSLisandro Dalcin . dm - DM to be used with TS 404efe9872eSLisandro Dalcin 405efe9872eSLisandro Dalcin Output Arguments: 406efe9872eSLisandro Dalcin + fun - function evaluation function, see TSSetI2Function() for calling sequence 407efe9872eSLisandro Dalcin - ctx - context for residual evaluation 408efe9872eSLisandro Dalcin 409efe9872eSLisandro Dalcin Level: advanced 410efe9872eSLisandro Dalcin 411efe9872eSLisandro Dalcin Note: 412efe9872eSLisandro Dalcin TSGetI2Function() is normally used, but it calls this function internally because the user context is actually 413efe9872eSLisandro Dalcin associated with the DM. 414efe9872eSLisandro Dalcin 415efe9872eSLisandro Dalcin .seealso: DMTSSetI2Function(),TSGetI2Function() 416efe9872eSLisandro Dalcin @*/ 417efe9872eSLisandro Dalcin PetscErrorCode DMTSGetI2Function(DM dm,TSI2Function *fun,void **ctx) 418efe9872eSLisandro Dalcin { 419efe9872eSLisandro Dalcin DMTS tsdm; 420efe9872eSLisandro Dalcin PetscErrorCode ierr; 421efe9872eSLisandro Dalcin 422efe9872eSLisandro Dalcin PetscFunctionBegin; 423efe9872eSLisandro Dalcin PetscValidHeaderSpecific(dm,DM_CLASSID,1); 424efe9872eSLisandro Dalcin ierr = DMGetDMTS(dm,&tsdm);CHKERRQ(ierr); 425efe9872eSLisandro Dalcin if (fun) *fun = tsdm->ops->i2function; 426efe9872eSLisandro Dalcin if (ctx) *ctx = tsdm->i2functionctx; 427efe9872eSLisandro Dalcin PetscFunctionReturn(0); 428efe9872eSLisandro Dalcin } 429efe9872eSLisandro Dalcin 430efe9872eSLisandro Dalcin /*@C 431efe9872eSLisandro Dalcin DMTSSetI2Jacobian - set TS implicit Jacobian evaluation function for 2nd order systems 432efe9872eSLisandro Dalcin 433efe9872eSLisandro Dalcin Not Collective 434efe9872eSLisandro Dalcin 435efe9872eSLisandro Dalcin Input Arguments: 436efe9872eSLisandro Dalcin + dm - DM to be used with TS 437efe9872eSLisandro Dalcin . fun - Jacobian evaluation function, see TSSetI2Jacobian() for calling sequence 438efe9872eSLisandro Dalcin - ctx - context for Jacobian evaluation 439efe9872eSLisandro Dalcin 440efe9872eSLisandro Dalcin Level: advanced 441efe9872eSLisandro Dalcin 442efe9872eSLisandro Dalcin Note: 443efe9872eSLisandro Dalcin TSSetI2Jacobian() is normally used, but it calls this function internally because the user context is actually 444efe9872eSLisandro Dalcin associated with the DM. 445efe9872eSLisandro Dalcin 446efe9872eSLisandro Dalcin .seealso: TSSetI2Jacobian() 447efe9872eSLisandro Dalcin @*/ 448efe9872eSLisandro Dalcin PetscErrorCode DMTSSetI2Jacobian(DM dm,TSI2Jacobian jac,void *ctx) 449efe9872eSLisandro Dalcin { 450efe9872eSLisandro Dalcin DMTS tsdm; 451efe9872eSLisandro Dalcin PetscErrorCode ierr; 452efe9872eSLisandro Dalcin 453efe9872eSLisandro Dalcin PetscFunctionBegin; 454efe9872eSLisandro Dalcin PetscValidHeaderSpecific(dm,DM_CLASSID,1); 455efe9872eSLisandro Dalcin ierr = DMGetDMTSWrite(dm,&tsdm);CHKERRQ(ierr); 456efe9872eSLisandro Dalcin if (jac) tsdm->ops->i2jacobian = jac; 457efe9872eSLisandro Dalcin if (ctx) tsdm->i2jacobianctx = ctx; 458efe9872eSLisandro Dalcin PetscFunctionReturn(0); 459efe9872eSLisandro Dalcin } 460efe9872eSLisandro Dalcin 461efe9872eSLisandro Dalcin /*@C 462efe9872eSLisandro Dalcin DMTSGetI2Jacobian - get TS implicit Jacobian evaluation function for 2nd order systems 463efe9872eSLisandro Dalcin 464efe9872eSLisandro Dalcin Not Collective 465efe9872eSLisandro Dalcin 466efe9872eSLisandro Dalcin Input Argument: 467efe9872eSLisandro Dalcin . dm - DM to be used with TS 468efe9872eSLisandro Dalcin 469efe9872eSLisandro Dalcin Output Arguments: 470efe9872eSLisandro Dalcin + jac - Jacobian evaluation function, see TSSetI2Jacobian() for calling sequence 471efe9872eSLisandro Dalcin - ctx - context for Jacobian evaluation 472efe9872eSLisandro Dalcin 473efe9872eSLisandro Dalcin Level: advanced 474efe9872eSLisandro Dalcin 475efe9872eSLisandro Dalcin Note: 476efe9872eSLisandro Dalcin TSGetI2Jacobian() is normally used, but it calls this function internally because the user context is actually 477efe9872eSLisandro Dalcin associated with the DM. 478efe9872eSLisandro Dalcin 479efe9872eSLisandro Dalcin .seealso: DMTSSetI2Jacobian(),TSGetI2Jacobian() 480efe9872eSLisandro Dalcin @*/ 481efe9872eSLisandro Dalcin PetscErrorCode DMTSGetI2Jacobian(DM dm,TSI2Jacobian *jac,void **ctx) 482efe9872eSLisandro Dalcin { 483efe9872eSLisandro Dalcin DMTS tsdm; 484efe9872eSLisandro Dalcin PetscErrorCode ierr; 485efe9872eSLisandro Dalcin 486efe9872eSLisandro Dalcin PetscFunctionBegin; 487efe9872eSLisandro Dalcin PetscValidHeaderSpecific(dm,DM_CLASSID,1); 488efe9872eSLisandro Dalcin ierr = DMGetDMTS(dm,&tsdm);CHKERRQ(ierr); 489efe9872eSLisandro Dalcin if (jac) *jac = tsdm->ops->i2jacobian; 490efe9872eSLisandro Dalcin if (ctx) *ctx = tsdm->i2jacobianctx; 491efe9872eSLisandro Dalcin PetscFunctionReturn(0); 492efe9872eSLisandro Dalcin } 49324989b8cSPeter Brune 49424989b8cSPeter Brune /*@C 49524989b8cSPeter Brune DMTSSetRHSFunction - set TS explicit residual evaluation function 49624989b8cSPeter Brune 49724989b8cSPeter Brune Not Collective 49824989b8cSPeter Brune 49924989b8cSPeter Brune Input Arguments: 50024989b8cSPeter Brune + dm - DM to be used with TS 50124989b8cSPeter Brune . func - RHS function evaluation function, see TSSetRHSFunction() for calling sequence 50224989b8cSPeter Brune - ctx - context for residual evaluation 50324989b8cSPeter Brune 50424989b8cSPeter Brune Level: advanced 50524989b8cSPeter Brune 50624989b8cSPeter Brune Note: 507ef20d060SBarry Smith TSSetRSHFunction() is normally used, but it calls this function internally because the user context is actually 50824989b8cSPeter Brune associated with the DM. This makes the interface consistent regardless of whether the user interacts with a DM or 50924989b8cSPeter Brune not. If DM took a more central role at some later date, this could become the primary method of setting the residual. 51024989b8cSPeter Brune 51124989b8cSPeter Brune .seealso: DMTSSetContext(), TSSetFunction(), DMTSSetJacobian() 51224989b8cSPeter Brune @*/ 51324989b8cSPeter Brune PetscErrorCode DMTSSetRHSFunction(DM dm,TSRHSFunction func,void *ctx) 51424989b8cSPeter Brune { 51524989b8cSPeter Brune PetscErrorCode ierr; 516942e3340SBarry Smith DMTS tsdm; 51724989b8cSPeter Brune 51824989b8cSPeter Brune PetscFunctionBegin; 51924989b8cSPeter Brune PetscValidHeaderSpecific(dm,DM_CLASSID,1); 520942e3340SBarry Smith ierr = DMGetDMTSWrite(dm,&tsdm);CHKERRQ(ierr); 521d74926cbSBarry Smith if (func) tsdm->ops->rhsfunction = func; 52224989b8cSPeter Brune if (ctx) tsdm->rhsfunctionctx = ctx; 52324989b8cSPeter Brune PetscFunctionReturn(0); 52424989b8cSPeter Brune } 52524989b8cSPeter Brune 526ef20d060SBarry Smith /*@C 527ef20d060SBarry Smith DMTSGetSolutionFunction - gets the TS solution evaluation function 528ef20d060SBarry Smith 529ef20d060SBarry Smith Not Collective 530ef20d060SBarry Smith 531ef20d060SBarry Smith Input Arguments: 532ef20d060SBarry Smith . dm - DM to be used with TS 533ef20d060SBarry Smith 534ef20d060SBarry Smith Output Parameters: 535ef20d060SBarry Smith + func - solution function evaluation function, see TSSetSolution() for calling sequence 536ef20d060SBarry Smith - ctx - context for solution evaluation 537ef20d060SBarry Smith 538ef20d060SBarry Smith Level: advanced 539ef20d060SBarry Smith 540*0ed3bfb6SBarry Smith .seealso: DMTSSetContext(), TSSetFunction(), DMTSSetJacobian(), DMTSSetSolutionFunction() 541ef20d060SBarry Smith @*/ 542ef20d060SBarry Smith PetscErrorCode DMTSGetSolutionFunction(DM dm,TSSolutionFunction *func,void **ctx) 543ef20d060SBarry Smith { 544ef20d060SBarry Smith PetscErrorCode ierr; 545942e3340SBarry Smith DMTS tsdm; 546ef20d060SBarry Smith 547ef20d060SBarry Smith PetscFunctionBegin; 548ef20d060SBarry Smith PetscValidHeaderSpecific(dm,DM_CLASSID,1); 549942e3340SBarry Smith ierr = DMGetDMTS(dm,&tsdm);CHKERRQ(ierr); 550d74926cbSBarry Smith if (func) *func = tsdm->ops->solution; 551ef20d060SBarry Smith if (ctx) *ctx = tsdm->solutionctx; 552ef20d060SBarry Smith PetscFunctionReturn(0); 553ef20d060SBarry Smith } 554ef20d060SBarry Smith 555ef20d060SBarry Smith /*@C 556ef20d060SBarry Smith DMTSSetSolutionFunction - set TS solution evaluation function 557ef20d060SBarry Smith 558ef20d060SBarry Smith Not Collective 559ef20d060SBarry Smith 560ef20d060SBarry Smith Input Arguments: 561ef20d060SBarry Smith + dm - DM to be used with TS 562ef20d060SBarry Smith . func - solution function evaluation function, see TSSetSolution() for calling sequence 563ef20d060SBarry Smith - ctx - context for solution evaluation 564ef20d060SBarry Smith 565ef20d060SBarry Smith Level: advanced 566ef20d060SBarry Smith 567ef20d060SBarry Smith Note: 568ef20d060SBarry Smith TSSetSolutionFunction() is normally used, but it calls this function internally because the user context is actually 569ef20d060SBarry Smith associated with the DM. This makes the interface consistent regardless of whether the user interacts with a DM or 570ef20d060SBarry Smith not. If DM took a more central role at some later date, this could become the primary method of setting the residual. 571ef20d060SBarry Smith 572*0ed3bfb6SBarry Smith .seealso: DMTSSetContext(), TSSetFunction(), DMTSSetJacobian(), DMTSGetSolutionFunction() 573ef20d060SBarry Smith @*/ 574ef20d060SBarry Smith PetscErrorCode DMTSSetSolutionFunction(DM dm,TSSolutionFunction func,void *ctx) 575ef20d060SBarry Smith { 576ef20d060SBarry Smith PetscErrorCode ierr; 577942e3340SBarry Smith DMTS tsdm; 578ef20d060SBarry Smith 579ef20d060SBarry Smith PetscFunctionBegin; 580ef20d060SBarry Smith PetscValidHeaderSpecific(dm,DM_CLASSID,1); 581942e3340SBarry Smith ierr = DMGetDMTSWrite(dm,&tsdm);CHKERRQ(ierr); 582d74926cbSBarry Smith if (func) tsdm->ops->solution = func; 583ef20d060SBarry Smith if (ctx) tsdm->solutionctx = ctx; 584ef20d060SBarry Smith PetscFunctionReturn(0); 585ef20d060SBarry Smith } 586ef20d060SBarry Smith 5879b7cd975SBarry Smith /*@C 5889b7cd975SBarry Smith DMTSSetForcingFunction - set TS forcing function evaluation function 5899b7cd975SBarry Smith 5909b7cd975SBarry Smith Not Collective 5919b7cd975SBarry Smith 5929b7cd975SBarry Smith Input Arguments: 5939b7cd975SBarry Smith + dm - DM to be used with TS 594f8b49ee9SBarry Smith . f - forcing function evaluation function; see TSForcingFunction 5959b7cd975SBarry Smith - ctx - context for solution evaluation 5969b7cd975SBarry Smith 5979b7cd975SBarry Smith Level: advanced 5989b7cd975SBarry Smith 5999b7cd975SBarry Smith Note: 6009b7cd975SBarry Smith TSSetForcingFunction() is normally used, but it calls this function internally because the user context is actually 6019b7cd975SBarry Smith associated with the DM. This makes the interface consistent regardless of whether the user interacts with a DM or 6029b7cd975SBarry Smith not. If DM took a more central role at some later date, this could become the primary method of setting the residual. 6039b7cd975SBarry Smith 6049b7cd975SBarry Smith .seealso: DMTSSetContext(), TSSetFunction(), DMTSSetJacobian(), TSSetForcingFunction(), DMTSGetForcingFunction() 6059b7cd975SBarry Smith @*/ 606d56366bfSLisandro Dalcin PetscErrorCode DMTSSetForcingFunction(DM dm,TSForcingFunction f,void *ctx) 6079b7cd975SBarry Smith { 6089b7cd975SBarry Smith PetscErrorCode ierr; 6099b7cd975SBarry Smith DMTS tsdm; 6109b7cd975SBarry Smith 6119b7cd975SBarry Smith PetscFunctionBegin; 6129b7cd975SBarry Smith PetscValidHeaderSpecific(dm,DM_CLASSID,1); 6139b7cd975SBarry Smith ierr = DMGetDMTSWrite(dm,&tsdm);CHKERRQ(ierr); 614f8b49ee9SBarry Smith if (f) tsdm->ops->forcing = f; 6159b7cd975SBarry Smith if (ctx) tsdm->forcingctx = ctx; 6169b7cd975SBarry Smith PetscFunctionReturn(0); 6179b7cd975SBarry Smith } 6189b7cd975SBarry Smith 6199b7cd975SBarry Smith 6209b7cd975SBarry Smith /*@C 6219b7cd975SBarry Smith DMTSGetForcingFunction - get TS forcing function evaluation function 6229b7cd975SBarry Smith 6239b7cd975SBarry Smith Not Collective 6249b7cd975SBarry Smith 6259b7cd975SBarry Smith Input Argument: 6269b7cd975SBarry Smith . dm - DM to be used with TS 6279b7cd975SBarry Smith 6289b7cd975SBarry Smith Output Arguments: 629f8b49ee9SBarry Smith + f - forcing function evaluation function; see TSForcingFunction for details 6309b7cd975SBarry Smith - ctx - context for solution evaluation 6319b7cd975SBarry Smith 6329b7cd975SBarry Smith Level: advanced 6339b7cd975SBarry Smith 6349b7cd975SBarry Smith Note: 6359b7cd975SBarry Smith TSSetForcingFunction() is normally used, but it calls this function internally because the user context is actually 6369b7cd975SBarry Smith associated with the DM. This makes the interface consistent regardless of whether the user interacts with a DM or 6379b7cd975SBarry Smith not. If DM took a more central role at some later date, this could become the primary method of setting the residual. 6389b7cd975SBarry Smith 6399b7cd975SBarry Smith .seealso: DMTSSetContext(), TSSetFunction(), DMTSSetJacobian(), TSSetForcingFunction(), DMTSGetForcingFunction() 6409b7cd975SBarry Smith @*/ 641d56366bfSLisandro Dalcin PetscErrorCode DMTSGetForcingFunction(DM dm,TSForcingFunction *f,void **ctx) 6429b7cd975SBarry Smith { 6439b7cd975SBarry Smith PetscErrorCode ierr; 6449b7cd975SBarry Smith DMTS tsdm; 6459b7cd975SBarry Smith 6469b7cd975SBarry Smith PetscFunctionBegin; 6479b7cd975SBarry Smith PetscValidHeaderSpecific(dm,DM_CLASSID,1); 6489b7cd975SBarry Smith ierr = DMGetDMTSWrite(dm,&tsdm);CHKERRQ(ierr); 649f8b49ee9SBarry Smith if (f) *f = tsdm->ops->forcing; 6509b7cd975SBarry Smith if (ctx) *ctx = tsdm->forcingctx; 6519b7cd975SBarry Smith PetscFunctionReturn(0); 6529b7cd975SBarry Smith } 6539b7cd975SBarry Smith 65424989b8cSPeter Brune /*@C 65524989b8cSPeter Brune DMTSGetRHSFunction - get TS explicit residual evaluation function 65624989b8cSPeter Brune 65724989b8cSPeter Brune Not Collective 65824989b8cSPeter Brune 65924989b8cSPeter Brune Input Argument: 66024989b8cSPeter Brune . dm - DM to be used with TS 66124989b8cSPeter Brune 66224989b8cSPeter Brune Output Arguments: 66324989b8cSPeter Brune + func - residual evaluation function, see TSSetRHSFunction() for calling sequence 66424989b8cSPeter Brune - ctx - context for residual evaluation 66524989b8cSPeter Brune 66624989b8cSPeter Brune Level: advanced 66724989b8cSPeter Brune 66824989b8cSPeter Brune Note: 66924989b8cSPeter Brune TSGetFunction() is normally used, but it calls this function internally because the user context is actually 67024989b8cSPeter Brune associated with the DM. 67124989b8cSPeter Brune 67224989b8cSPeter Brune .seealso: DMTSSetContext(), DMTSSetFunction(), TSSetFunction() 67324989b8cSPeter Brune @*/ 67424989b8cSPeter Brune PetscErrorCode DMTSGetRHSFunction(DM dm,TSRHSFunction *func,void **ctx) 67524989b8cSPeter Brune { 67624989b8cSPeter Brune PetscErrorCode ierr; 677942e3340SBarry Smith DMTS tsdm; 67824989b8cSPeter Brune 67924989b8cSPeter Brune PetscFunctionBegin; 68024989b8cSPeter Brune PetscValidHeaderSpecific(dm,DM_CLASSID,1); 681942e3340SBarry Smith ierr = DMGetDMTS(dm,&tsdm);CHKERRQ(ierr); 682d74926cbSBarry Smith if (func) *func = tsdm->ops->rhsfunction; 68324989b8cSPeter Brune if (ctx) *ctx = tsdm->rhsfunctionctx; 68424989b8cSPeter Brune PetscFunctionReturn(0); 68524989b8cSPeter Brune } 68624989b8cSPeter Brune 68724989b8cSPeter Brune /*@C 68824989b8cSPeter Brune DMTSSetIJacobian - set TS Jacobian evaluation function 68924989b8cSPeter Brune 69024989b8cSPeter Brune Not Collective 69124989b8cSPeter Brune 69224989b8cSPeter Brune Input Argument: 69324989b8cSPeter Brune + dm - DM to be used with TS 69424989b8cSPeter Brune . func - Jacobian evaluation function, see TSSetIJacobian() for calling sequence 69524989b8cSPeter Brune - ctx - context for residual evaluation 69624989b8cSPeter Brune 69724989b8cSPeter Brune Level: advanced 69824989b8cSPeter Brune 69924989b8cSPeter Brune Note: 70024989b8cSPeter Brune TSSetJacobian() is normally used, but it calls this function internally because the user context is actually 70124989b8cSPeter Brune associated with the DM. This makes the interface consistent regardless of whether the user interacts with a DM or 70224989b8cSPeter Brune not. If DM took a more central role at some later date, this could become the primary method of setting the Jacobian. 70324989b8cSPeter Brune 70424989b8cSPeter Brune .seealso: DMTSSetContext(), TSSetFunction(), DMTSGetJacobian(), TSSetJacobian() 70524989b8cSPeter Brune @*/ 70624989b8cSPeter Brune PetscErrorCode DMTSSetIJacobian(DM dm,TSIJacobian func,void *ctx) 70724989b8cSPeter Brune { 70824989b8cSPeter Brune PetscErrorCode ierr; 709942e3340SBarry Smith DMTS sdm; 71024989b8cSPeter Brune 71124989b8cSPeter Brune PetscFunctionBegin; 71224989b8cSPeter Brune PetscValidHeaderSpecific(dm,DM_CLASSID,1); 713942e3340SBarry Smith ierr = DMGetDMTSWrite(dm,&sdm);CHKERRQ(ierr); 714d74926cbSBarry Smith if (func) sdm->ops->ijacobian = func; 71524989b8cSPeter Brune if (ctx) sdm->ijacobianctx = ctx; 71624989b8cSPeter Brune PetscFunctionReturn(0); 71724989b8cSPeter Brune } 71824989b8cSPeter Brune 71924989b8cSPeter Brune /*@C 72024989b8cSPeter Brune DMTSGetIJacobian - get TS Jacobian evaluation function 72124989b8cSPeter Brune 72224989b8cSPeter Brune Not Collective 72324989b8cSPeter Brune 72424989b8cSPeter Brune Input Argument: 72524989b8cSPeter Brune . dm - DM to be used with TS 72624989b8cSPeter Brune 72724989b8cSPeter Brune Output Arguments: 72824989b8cSPeter Brune + func - Jacobian evaluation function, see TSSetIJacobian() for calling sequence 72924989b8cSPeter Brune - ctx - context for residual evaluation 73024989b8cSPeter Brune 73124989b8cSPeter Brune Level: advanced 73224989b8cSPeter Brune 73324989b8cSPeter Brune Note: 73424989b8cSPeter Brune TSGetJacobian() is normally used, but it calls this function internally because the user context is actually 73524989b8cSPeter Brune associated with the DM. This makes the interface consistent regardless of whether the user interacts with a DM or 73624989b8cSPeter Brune not. If DM took a more central role at some later date, this could become the primary method of setting the Jacobian. 73724989b8cSPeter Brune 73824989b8cSPeter Brune .seealso: DMTSSetContext(), TSSetFunction(), DMTSSetJacobian() 73924989b8cSPeter Brune @*/ 74024989b8cSPeter Brune PetscErrorCode DMTSGetIJacobian(DM dm,TSIJacobian *func,void **ctx) 74124989b8cSPeter Brune { 74224989b8cSPeter Brune PetscErrorCode ierr; 743942e3340SBarry Smith DMTS tsdm; 74424989b8cSPeter Brune 74524989b8cSPeter Brune PetscFunctionBegin; 74624989b8cSPeter Brune PetscValidHeaderSpecific(dm,DM_CLASSID,1); 747942e3340SBarry Smith ierr = DMGetDMTS(dm,&tsdm);CHKERRQ(ierr); 748d74926cbSBarry Smith if (func) *func = tsdm->ops->ijacobian; 74924989b8cSPeter Brune if (ctx) *ctx = tsdm->ijacobianctx; 75024989b8cSPeter Brune PetscFunctionReturn(0); 75124989b8cSPeter Brune } 75224989b8cSPeter Brune 75324989b8cSPeter Brune 75424989b8cSPeter Brune /*@C 75524989b8cSPeter Brune DMTSSetRHSJacobian - set TS Jacobian evaluation function 75624989b8cSPeter Brune 75724989b8cSPeter Brune Not Collective 75824989b8cSPeter Brune 75924989b8cSPeter Brune Input Argument: 76024989b8cSPeter Brune + dm - DM to be used with TS 76124989b8cSPeter Brune . func - Jacobian evaluation function, see TSSetRHSJacobian() for calling sequence 76224989b8cSPeter Brune - ctx - context for residual evaluation 76324989b8cSPeter Brune 76424989b8cSPeter Brune Level: advanced 76524989b8cSPeter Brune 76624989b8cSPeter Brune Note: 76724989b8cSPeter Brune TSSetJacobian() is normally used, but it calls this function internally because the user context is actually 76824989b8cSPeter Brune associated with the DM. This makes the interface consistent regardless of whether the user interacts with a DM or 76924989b8cSPeter Brune not. If DM took a more central role at some later date, this could become the primary method of setting the Jacobian. 77024989b8cSPeter Brune 77124989b8cSPeter Brune .seealso: DMTSSetContext(), TSSetFunction(), DMTSGetJacobian(), TSSetJacobian() 77224989b8cSPeter Brune @*/ 77324989b8cSPeter Brune PetscErrorCode DMTSSetRHSJacobian(DM dm,TSRHSJacobian func,void *ctx) 77424989b8cSPeter Brune { 77524989b8cSPeter Brune PetscErrorCode ierr; 776942e3340SBarry Smith DMTS tsdm; 77724989b8cSPeter Brune 77824989b8cSPeter Brune PetscFunctionBegin; 77924989b8cSPeter Brune PetscValidHeaderSpecific(dm,DM_CLASSID,1); 780942e3340SBarry Smith ierr = DMGetDMTSWrite(dm,&tsdm);CHKERRQ(ierr); 781d74926cbSBarry Smith if (func) tsdm->ops->rhsjacobian = func; 78224989b8cSPeter Brune if (ctx) tsdm->rhsjacobianctx = ctx; 78324989b8cSPeter Brune PetscFunctionReturn(0); 78424989b8cSPeter Brune } 78524989b8cSPeter Brune 78624989b8cSPeter Brune /*@C 78724989b8cSPeter Brune DMTSGetRHSJacobian - get TS Jacobian evaluation function 78824989b8cSPeter Brune 78924989b8cSPeter Brune Not Collective 79024989b8cSPeter Brune 79124989b8cSPeter Brune Input Argument: 79224989b8cSPeter Brune . dm - DM to be used with TS 79324989b8cSPeter Brune 79424989b8cSPeter Brune Output Arguments: 79524989b8cSPeter Brune + func - Jacobian evaluation function, see TSSetRHSJacobian() for calling sequence 79624989b8cSPeter Brune - ctx - context for residual evaluation 79724989b8cSPeter Brune 79824989b8cSPeter Brune Level: advanced 79924989b8cSPeter Brune 80024989b8cSPeter Brune Note: 80124989b8cSPeter Brune TSGetJacobian() is normally used, but it calls this function internally because the user context is actually 80224989b8cSPeter Brune associated with the DM. This makes the interface consistent regardless of whether the user interacts with a DM or 80324989b8cSPeter Brune not. If DM took a more central role at some later date, this could become the primary method of setting the Jacobian. 80424989b8cSPeter Brune 80524989b8cSPeter Brune .seealso: DMTSSetContext(), TSSetFunction(), DMTSSetJacobian() 80624989b8cSPeter Brune @*/ 80724989b8cSPeter Brune PetscErrorCode DMTSGetRHSJacobian(DM dm,TSRHSJacobian *func,void **ctx) 80824989b8cSPeter Brune { 80924989b8cSPeter Brune PetscErrorCode ierr; 810942e3340SBarry Smith DMTS tsdm; 81124989b8cSPeter Brune 81224989b8cSPeter Brune PetscFunctionBegin; 81324989b8cSPeter Brune PetscValidHeaderSpecific(dm,DM_CLASSID,1); 814942e3340SBarry Smith ierr = DMGetDMTS(dm,&tsdm);CHKERRQ(ierr); 815d74926cbSBarry Smith if (func) *func = tsdm->ops->rhsjacobian; 81624989b8cSPeter Brune if (ctx) *ctx = tsdm->rhsjacobianctx; 81724989b8cSPeter Brune PetscFunctionReturn(0); 81824989b8cSPeter Brune } 819ad6bc421SBarry Smith 820ad6bc421SBarry Smith /*@C 821ad6bc421SBarry Smith DMTSSetIFunctionSerialize - sets functions used to view and load a IFunction context 822ad6bc421SBarry Smith 823ad6bc421SBarry Smith Not Collective 824ad6bc421SBarry Smith 825ad6bc421SBarry Smith Input Arguments: 826ad6bc421SBarry Smith + dm - DM to be used with TS 827ad6bc421SBarry Smith . view - viewer function 828ad6bc421SBarry Smith - load - loading function 829ad6bc421SBarry Smith 830ad6bc421SBarry Smith Level: advanced 831ad6bc421SBarry Smith 832ad6bc421SBarry Smith .seealso: DMTSSetContext(), TSSetFunction(), DMTSSetJacobian() 833ad6bc421SBarry Smith @*/ 834ad6bc421SBarry Smith PetscErrorCode DMTSSetIFunctionSerialize(DM dm,PetscErrorCode (*view)(void*,PetscViewer),PetscErrorCode (*load)(void**,PetscViewer)) 835ad6bc421SBarry Smith { 836ad6bc421SBarry Smith PetscErrorCode ierr; 837ad6bc421SBarry Smith DMTS tsdm; 838ad6bc421SBarry Smith 839ad6bc421SBarry Smith PetscFunctionBegin; 840ad6bc421SBarry Smith PetscValidHeaderSpecific(dm,DM_CLASSID,1); 841ad6bc421SBarry Smith ierr = DMGetDMTSWrite(dm,&tsdm);CHKERRQ(ierr); 842ad6bc421SBarry Smith tsdm->ops->ifunctionview = view; 843ad6bc421SBarry Smith tsdm->ops->ifunctionload = load; 844ad6bc421SBarry Smith PetscFunctionReturn(0); 845ad6bc421SBarry Smith } 846ad6bc421SBarry Smith 847ad6bc421SBarry Smith /*@C 848ad6bc421SBarry Smith DMTSSetIJacobianSerialize - sets functions used to view and load a IJacobian context 849ad6bc421SBarry Smith 850ad6bc421SBarry Smith Not Collective 851ad6bc421SBarry Smith 852ad6bc421SBarry Smith Input Arguments: 853ad6bc421SBarry Smith + dm - DM to be used with TS 854ad6bc421SBarry Smith . view - viewer function 855ad6bc421SBarry Smith - load - loading function 856ad6bc421SBarry Smith 857ad6bc421SBarry Smith Level: advanced 858ad6bc421SBarry Smith 859ad6bc421SBarry Smith .seealso: DMTSSetContext(), TSSetFunction(), DMTSSetJacobian() 860ad6bc421SBarry Smith @*/ 861ad6bc421SBarry Smith PetscErrorCode DMTSSetIJacobianSerialize(DM dm,PetscErrorCode (*view)(void*,PetscViewer),PetscErrorCode (*load)(void**,PetscViewer)) 862ad6bc421SBarry Smith { 863ad6bc421SBarry Smith PetscErrorCode ierr; 864ad6bc421SBarry Smith DMTS tsdm; 865ad6bc421SBarry Smith 866ad6bc421SBarry Smith PetscFunctionBegin; 867ad6bc421SBarry Smith PetscValidHeaderSpecific(dm,DM_CLASSID,1); 868ad6bc421SBarry Smith ierr = DMGetDMTSWrite(dm,&tsdm);CHKERRQ(ierr); 869ad6bc421SBarry Smith tsdm->ops->ijacobianview = view; 870ad6bc421SBarry Smith tsdm->ops->ijacobianload = load; 871ad6bc421SBarry Smith PetscFunctionReturn(0); 872ad6bc421SBarry Smith } 873