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; 2285c87d4f4SJunchao Zhang (*tsdm)->originaldm = dm; 2290298fd71SBarry Smith ierr = DMCoarsenHookAdd(dm,DMCoarsenHook_DMTS,DMRestrictHook_DMTS,NULL);CHKERRQ(ierr); 2300298fd71SBarry Smith ierr = DMSubDomainHookAdd(dm,DMSubDomainHook_DMTS,DMSubDomainRestrictHook_DMTS,NULL);CHKERRQ(ierr); 23124989b8cSPeter Brune } 23224989b8cSPeter Brune PetscFunctionReturn(0); 23324989b8cSPeter Brune } 23424989b8cSPeter Brune 23524989b8cSPeter Brune /*@C 236942e3340SBarry Smith DMGetDMTSWrite - get write access to private DMTS context from a DM 23724989b8cSPeter Brune 23824989b8cSPeter Brune Not Collective 23924989b8cSPeter Brune 24024989b8cSPeter Brune Input Argument: 24124989b8cSPeter Brune . dm - DM to be used with TS 24224989b8cSPeter Brune 24324989b8cSPeter Brune Output Argument: 244942e3340SBarry Smith . tsdm - private DMTS context 24524989b8cSPeter Brune 24624989b8cSPeter Brune Level: developer 24724989b8cSPeter Brune 248942e3340SBarry Smith .seealso: DMGetDMTS() 24924989b8cSPeter Brune @*/ 250942e3340SBarry Smith PetscErrorCode DMGetDMTSWrite(DM dm,DMTS *tsdm) 25124989b8cSPeter Brune { 25224989b8cSPeter Brune PetscErrorCode ierr; 253942e3340SBarry Smith DMTS sdm; 25424989b8cSPeter Brune 25524989b8cSPeter Brune PetscFunctionBegin; 25624989b8cSPeter Brune PetscValidHeaderSpecific(dm,DM_CLASSID,1); 257942e3340SBarry Smith ierr = DMGetDMTS(dm,&sdm);CHKERRQ(ierr); 2585c87d4f4SJunchao Zhang if (!sdm->originaldm) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_WRONGSTATE,"DMTS has a NULL originaldm"); 25924989b8cSPeter Brune if (sdm->originaldm != dm) { /* Copy on write */ 2602a34c10cSBarry Smith DMTS oldsdm = sdm; 261942e3340SBarry Smith ierr = PetscInfo(dm,"Copying DMTS due to write\n");CHKERRQ(ierr); 262ce94432eSBarry Smith ierr = DMTSCreate(PetscObjectComm((PetscObject)dm),&sdm);CHKERRQ(ierr); 263d74926cbSBarry Smith ierr = DMTSCopy(oldsdm,sdm);CHKERRQ(ierr); 2642a34c10cSBarry Smith ierr = DMTSDestroy((DMTS*)&dm->dmts);CHKERRQ(ierr); 2652a34c10cSBarry Smith dm->dmts = (PetscObject) sdm; 2665c87d4f4SJunchao Zhang sdm->originaldm = dm; 26724989b8cSPeter Brune } 26824989b8cSPeter Brune *tsdm = sdm; 26924989b8cSPeter Brune PetscFunctionReturn(0); 27024989b8cSPeter Brune } 27124989b8cSPeter Brune 27224989b8cSPeter Brune /*@C 273942e3340SBarry Smith DMCopyDMTS - copies a DM context to a new DM 27424989b8cSPeter Brune 27524989b8cSPeter Brune Logically Collective 27624989b8cSPeter Brune 27724989b8cSPeter Brune Input Arguments: 27824989b8cSPeter Brune + dmsrc - DM to obtain context from 27924989b8cSPeter Brune - dmdest - DM to add context to 28024989b8cSPeter Brune 28124989b8cSPeter Brune Level: developer 28224989b8cSPeter Brune 28324989b8cSPeter Brune Note: 28424989b8cSPeter Brune The context is copied by reference. This function does not ensure that a context exists. 28524989b8cSPeter Brune 286942e3340SBarry Smith .seealso: DMGetDMTS(), TSSetDM() 28724989b8cSPeter Brune @*/ 288942e3340SBarry Smith PetscErrorCode DMCopyDMTS(DM dmsrc,DM dmdest) 28924989b8cSPeter Brune { 29024989b8cSPeter Brune PetscErrorCode ierr; 29124989b8cSPeter Brune 29224989b8cSPeter Brune PetscFunctionBegin; 29324989b8cSPeter Brune PetscValidHeaderSpecific(dmsrc,DM_CLASSID,1); 29424989b8cSPeter Brune PetscValidHeaderSpecific(dmdest,DM_CLASSID,2); 2952a34c10cSBarry Smith ierr = DMTSDestroy((DMTS*)&dmdest->dmts);CHKERRQ(ierr); 2962a34c10cSBarry Smith dmdest->dmts = dmsrc->dmts; 2972a34c10cSBarry Smith ierr = PetscObjectReference(dmdest->dmts);CHKERRQ(ierr); 2980298fd71SBarry Smith ierr = DMCoarsenHookAdd(dmdest,DMCoarsenHook_DMTS,DMRestrictHook_DMTS,NULL);CHKERRQ(ierr); 2990298fd71SBarry Smith ierr = DMSubDomainHookAdd(dmdest,DMSubDomainHook_DMTS,DMSubDomainRestrictHook_DMTS,NULL);CHKERRQ(ierr); 30024989b8cSPeter Brune PetscFunctionReturn(0); 30124989b8cSPeter Brune } 30224989b8cSPeter Brune 30324989b8cSPeter Brune /*@C 30424989b8cSPeter Brune DMTSSetIFunction - set TS implicit function evaluation function 30524989b8cSPeter Brune 30624989b8cSPeter Brune Not Collective 30724989b8cSPeter Brune 30824989b8cSPeter Brune Input Arguments: 30924989b8cSPeter Brune + dm - DM to be used with TS 31024989b8cSPeter Brune . func - function evaluation function, see TSSetIFunction() for calling sequence 31124989b8cSPeter Brune - ctx - context for residual evaluation 31224989b8cSPeter Brune 31324989b8cSPeter Brune Level: advanced 31424989b8cSPeter Brune 31524989b8cSPeter Brune Note: 31624989b8cSPeter Brune TSSetFunction() is normally used, but it calls this function internally because the user context is actually 31724989b8cSPeter Brune associated with the DM. This makes the interface consistent regardless of whether the user interacts with a DM or 31824989b8cSPeter Brune not. If DM took a more central role at some later date, this could become the primary method of setting the residual. 31924989b8cSPeter Brune 32024989b8cSPeter Brune .seealso: DMTSSetContext(), TSSetFunction(), DMTSSetJacobian() 32124989b8cSPeter Brune @*/ 32224989b8cSPeter Brune PetscErrorCode DMTSSetIFunction(DM dm,TSIFunction func,void *ctx) 32324989b8cSPeter Brune { 32424989b8cSPeter Brune PetscErrorCode ierr; 325942e3340SBarry Smith DMTS tsdm; 32624989b8cSPeter Brune 32724989b8cSPeter Brune PetscFunctionBegin; 32824989b8cSPeter Brune PetscValidHeaderSpecific(dm,DM_CLASSID,1); 329942e3340SBarry Smith ierr = DMGetDMTSWrite(dm,&tsdm);CHKERRQ(ierr); 330d74926cbSBarry Smith if (func) tsdm->ops->ifunction = func; 33124989b8cSPeter Brune if (ctx) tsdm->ifunctionctx = ctx; 33224989b8cSPeter Brune PetscFunctionReturn(0); 33324989b8cSPeter Brune } 33424989b8cSPeter Brune 33524989b8cSPeter Brune /*@C 33624989b8cSPeter Brune DMTSGetIFunction - get TS implicit residual evaluation function 33724989b8cSPeter Brune 33824989b8cSPeter Brune Not Collective 33924989b8cSPeter Brune 34024989b8cSPeter Brune Input Argument: 34124989b8cSPeter Brune . dm - DM to be used with TS 34224989b8cSPeter Brune 34324989b8cSPeter Brune Output Arguments: 34424989b8cSPeter Brune + func - function evaluation function, see TSSetIFunction() for calling sequence 34524989b8cSPeter Brune - ctx - context for residual evaluation 34624989b8cSPeter Brune 34724989b8cSPeter Brune Level: advanced 34824989b8cSPeter Brune 34924989b8cSPeter Brune Note: 35024989b8cSPeter Brune TSGetFunction() is normally used, but it calls this function internally because the user context is actually 35124989b8cSPeter Brune associated with the DM. 35224989b8cSPeter Brune 35324989b8cSPeter Brune .seealso: DMTSSetContext(), DMTSSetFunction(), TSSetFunction() 35424989b8cSPeter Brune @*/ 35524989b8cSPeter Brune PetscErrorCode DMTSGetIFunction(DM dm,TSIFunction *func,void **ctx) 35624989b8cSPeter Brune { 35724989b8cSPeter Brune PetscErrorCode ierr; 358942e3340SBarry Smith DMTS tsdm; 35924989b8cSPeter Brune 36024989b8cSPeter Brune PetscFunctionBegin; 36124989b8cSPeter Brune PetscValidHeaderSpecific(dm,DM_CLASSID,1); 362942e3340SBarry Smith ierr = DMGetDMTS(dm,&tsdm);CHKERRQ(ierr); 363d74926cbSBarry Smith if (func) *func = tsdm->ops->ifunction; 36424989b8cSPeter Brune if (ctx) *ctx = tsdm->ifunctionctx; 36524989b8cSPeter Brune PetscFunctionReturn(0); 36624989b8cSPeter Brune } 36724989b8cSPeter Brune 368efe9872eSLisandro Dalcin /*@C 369efe9872eSLisandro Dalcin DMTSSetI2Function - set TS implicit function evaluation function for 2nd order systems 370efe9872eSLisandro Dalcin 371efe9872eSLisandro Dalcin Not Collective 372efe9872eSLisandro Dalcin 373efe9872eSLisandro Dalcin Input Arguments: 374efe9872eSLisandro Dalcin + dm - DM to be used with TS 375efe9872eSLisandro Dalcin . fun - function evaluation function, see TSSetI2Function() for calling sequence 376efe9872eSLisandro Dalcin - ctx - context for residual evaluation 377efe9872eSLisandro Dalcin 378efe9872eSLisandro Dalcin Level: advanced 379efe9872eSLisandro Dalcin 380efe9872eSLisandro Dalcin Note: 381efe9872eSLisandro Dalcin TSSetI2Function() is normally used, but it calls this function internally because the user context is actually 382efe9872eSLisandro Dalcin associated with the DM. 383efe9872eSLisandro Dalcin 384efe9872eSLisandro Dalcin .seealso: TSSetI2Function() 385efe9872eSLisandro Dalcin @*/ 386efe9872eSLisandro Dalcin PetscErrorCode DMTSSetI2Function(DM dm,TSI2Function fun,void *ctx) 387efe9872eSLisandro Dalcin { 388efe9872eSLisandro Dalcin DMTS tsdm; 389efe9872eSLisandro Dalcin PetscErrorCode ierr; 390efe9872eSLisandro Dalcin 391efe9872eSLisandro Dalcin PetscFunctionBegin; 392efe9872eSLisandro Dalcin PetscValidHeaderSpecific(dm,DM_CLASSID,1); 393efe9872eSLisandro Dalcin ierr = DMGetDMTSWrite(dm,&tsdm);CHKERRQ(ierr); 394efe9872eSLisandro Dalcin if (fun) tsdm->ops->i2function = fun; 395efe9872eSLisandro Dalcin if (ctx) tsdm->i2functionctx = ctx; 396efe9872eSLisandro Dalcin PetscFunctionReturn(0); 397efe9872eSLisandro Dalcin } 398efe9872eSLisandro Dalcin 399efe9872eSLisandro Dalcin /*@C 400efe9872eSLisandro Dalcin DMTSGetI2Function - get TS implicit residual evaluation function for 2nd order systems 401efe9872eSLisandro Dalcin 402efe9872eSLisandro Dalcin Not Collective 403efe9872eSLisandro Dalcin 404efe9872eSLisandro Dalcin Input Argument: 405efe9872eSLisandro Dalcin . dm - DM to be used with TS 406efe9872eSLisandro Dalcin 407efe9872eSLisandro Dalcin Output Arguments: 408efe9872eSLisandro Dalcin + fun - function evaluation function, see TSSetI2Function() for calling sequence 409efe9872eSLisandro Dalcin - ctx - context for residual evaluation 410efe9872eSLisandro Dalcin 411efe9872eSLisandro Dalcin Level: advanced 412efe9872eSLisandro Dalcin 413efe9872eSLisandro Dalcin Note: 414efe9872eSLisandro Dalcin TSGetI2Function() is normally used, but it calls this function internally because the user context is actually 415efe9872eSLisandro Dalcin associated with the DM. 416efe9872eSLisandro Dalcin 417efe9872eSLisandro Dalcin .seealso: DMTSSetI2Function(),TSGetI2Function() 418efe9872eSLisandro Dalcin @*/ 419efe9872eSLisandro Dalcin PetscErrorCode DMTSGetI2Function(DM dm,TSI2Function *fun,void **ctx) 420efe9872eSLisandro Dalcin { 421efe9872eSLisandro Dalcin DMTS tsdm; 422efe9872eSLisandro Dalcin PetscErrorCode ierr; 423efe9872eSLisandro Dalcin 424efe9872eSLisandro Dalcin PetscFunctionBegin; 425efe9872eSLisandro Dalcin PetscValidHeaderSpecific(dm,DM_CLASSID,1); 426efe9872eSLisandro Dalcin ierr = DMGetDMTS(dm,&tsdm);CHKERRQ(ierr); 427efe9872eSLisandro Dalcin if (fun) *fun = tsdm->ops->i2function; 428efe9872eSLisandro Dalcin if (ctx) *ctx = tsdm->i2functionctx; 429efe9872eSLisandro Dalcin PetscFunctionReturn(0); 430efe9872eSLisandro Dalcin } 431efe9872eSLisandro Dalcin 432efe9872eSLisandro Dalcin /*@C 433efe9872eSLisandro Dalcin DMTSSetI2Jacobian - set TS implicit Jacobian evaluation function for 2nd order systems 434efe9872eSLisandro Dalcin 435efe9872eSLisandro Dalcin Not Collective 436efe9872eSLisandro Dalcin 437efe9872eSLisandro Dalcin Input Arguments: 438efe9872eSLisandro Dalcin + dm - DM to be used with TS 439efe9872eSLisandro Dalcin . fun - Jacobian evaluation function, see TSSetI2Jacobian() for calling sequence 440efe9872eSLisandro Dalcin - ctx - context for Jacobian evaluation 441efe9872eSLisandro Dalcin 442efe9872eSLisandro Dalcin Level: advanced 443efe9872eSLisandro Dalcin 444efe9872eSLisandro Dalcin Note: 445efe9872eSLisandro Dalcin TSSetI2Jacobian() is normally used, but it calls this function internally because the user context is actually 446efe9872eSLisandro Dalcin associated with the DM. 447efe9872eSLisandro Dalcin 448efe9872eSLisandro Dalcin .seealso: TSSetI2Jacobian() 449efe9872eSLisandro Dalcin @*/ 450efe9872eSLisandro Dalcin PetscErrorCode DMTSSetI2Jacobian(DM dm,TSI2Jacobian jac,void *ctx) 451efe9872eSLisandro Dalcin { 452efe9872eSLisandro Dalcin DMTS tsdm; 453efe9872eSLisandro Dalcin PetscErrorCode ierr; 454efe9872eSLisandro Dalcin 455efe9872eSLisandro Dalcin PetscFunctionBegin; 456efe9872eSLisandro Dalcin PetscValidHeaderSpecific(dm,DM_CLASSID,1); 457efe9872eSLisandro Dalcin ierr = DMGetDMTSWrite(dm,&tsdm);CHKERRQ(ierr); 458efe9872eSLisandro Dalcin if (jac) tsdm->ops->i2jacobian = jac; 459efe9872eSLisandro Dalcin if (ctx) tsdm->i2jacobianctx = ctx; 460efe9872eSLisandro Dalcin PetscFunctionReturn(0); 461efe9872eSLisandro Dalcin } 462efe9872eSLisandro Dalcin 463efe9872eSLisandro Dalcin /*@C 464efe9872eSLisandro Dalcin DMTSGetI2Jacobian - get TS implicit Jacobian evaluation function for 2nd order systems 465efe9872eSLisandro Dalcin 466efe9872eSLisandro Dalcin Not Collective 467efe9872eSLisandro Dalcin 468efe9872eSLisandro Dalcin Input Argument: 469efe9872eSLisandro Dalcin . dm - DM to be used with TS 470efe9872eSLisandro Dalcin 471efe9872eSLisandro Dalcin Output Arguments: 472efe9872eSLisandro Dalcin + jac - Jacobian evaluation function, see TSSetI2Jacobian() for calling sequence 473efe9872eSLisandro Dalcin - ctx - context for Jacobian evaluation 474efe9872eSLisandro Dalcin 475efe9872eSLisandro Dalcin Level: advanced 476efe9872eSLisandro Dalcin 477efe9872eSLisandro Dalcin Note: 478efe9872eSLisandro Dalcin TSGetI2Jacobian() is normally used, but it calls this function internally because the user context is actually 479efe9872eSLisandro Dalcin associated with the DM. 480efe9872eSLisandro Dalcin 481efe9872eSLisandro Dalcin .seealso: DMTSSetI2Jacobian(),TSGetI2Jacobian() 482efe9872eSLisandro Dalcin @*/ 483efe9872eSLisandro Dalcin PetscErrorCode DMTSGetI2Jacobian(DM dm,TSI2Jacobian *jac,void **ctx) 484efe9872eSLisandro Dalcin { 485efe9872eSLisandro Dalcin DMTS tsdm; 486efe9872eSLisandro Dalcin PetscErrorCode ierr; 487efe9872eSLisandro Dalcin 488efe9872eSLisandro Dalcin PetscFunctionBegin; 489efe9872eSLisandro Dalcin PetscValidHeaderSpecific(dm,DM_CLASSID,1); 490efe9872eSLisandro Dalcin ierr = DMGetDMTS(dm,&tsdm);CHKERRQ(ierr); 491efe9872eSLisandro Dalcin if (jac) *jac = tsdm->ops->i2jacobian; 492efe9872eSLisandro Dalcin if (ctx) *ctx = tsdm->i2jacobianctx; 493efe9872eSLisandro Dalcin PetscFunctionReturn(0); 494efe9872eSLisandro Dalcin } 49524989b8cSPeter Brune 49624989b8cSPeter Brune /*@C 49724989b8cSPeter Brune DMTSSetRHSFunction - set TS explicit residual evaluation function 49824989b8cSPeter Brune 49924989b8cSPeter Brune Not Collective 50024989b8cSPeter Brune 50124989b8cSPeter Brune Input Arguments: 50224989b8cSPeter Brune + dm - DM to be used with TS 50324989b8cSPeter Brune . func - RHS function evaluation function, see TSSetRHSFunction() for calling sequence 50424989b8cSPeter Brune - ctx - context for residual evaluation 50524989b8cSPeter Brune 50624989b8cSPeter Brune Level: advanced 50724989b8cSPeter Brune 50824989b8cSPeter Brune Note: 509ef20d060SBarry Smith TSSetRSHFunction() is normally used, but it calls this function internally because the user context is actually 51024989b8cSPeter Brune associated with the DM. This makes the interface consistent regardless of whether the user interacts with a DM or 51124989b8cSPeter Brune not. If DM took a more central role at some later date, this could become the primary method of setting the residual. 51224989b8cSPeter Brune 51324989b8cSPeter Brune .seealso: DMTSSetContext(), TSSetFunction(), DMTSSetJacobian() 51424989b8cSPeter Brune @*/ 51524989b8cSPeter Brune PetscErrorCode DMTSSetRHSFunction(DM dm,TSRHSFunction func,void *ctx) 51624989b8cSPeter Brune { 51724989b8cSPeter Brune PetscErrorCode ierr; 518942e3340SBarry Smith DMTS tsdm; 51924989b8cSPeter Brune 52024989b8cSPeter Brune PetscFunctionBegin; 52124989b8cSPeter Brune PetscValidHeaderSpecific(dm,DM_CLASSID,1); 522942e3340SBarry Smith ierr = DMGetDMTSWrite(dm,&tsdm);CHKERRQ(ierr); 523d74926cbSBarry Smith if (func) tsdm->ops->rhsfunction = func; 52424989b8cSPeter Brune if (ctx) tsdm->rhsfunctionctx = ctx; 52524989b8cSPeter Brune PetscFunctionReturn(0); 52624989b8cSPeter Brune } 52724989b8cSPeter Brune 528ef20d060SBarry Smith /*@C 529e3c11fc1SJed Brown DMTSSetTransientVariable - sets function to transform from state to transient variables 530e3c11fc1SJed Brown 531e3c11fc1SJed Brown Logically Collective 532e3c11fc1SJed Brown 533e3c11fc1SJed Brown Input Arguments: 534e3c11fc1SJed Brown + dm - DM to be used with TS 535e3c11fc1SJed Brown . tvar - a function that transforms in-place to transient variables 536e3c11fc1SJed Brown - ctx - a context for tvar 537e3c11fc1SJed Brown 538e3c11fc1SJed Brown Level: advanced 539e3c11fc1SJed Brown 540e3c11fc1SJed Brown Notes: 541e3c11fc1SJed Brown This is typically used to transform from primitive to conservative variables so that a time integrator (e.g., TSBDF) 542e3c11fc1SJed Brown can be conservative. In this context, primitive variables P are used to model the state (e.g., because they lead to 543e3c11fc1SJed Brown well-conditioned formulations even in limiting cases such as low-Mach or zero porosity). The transient variable is 544e3c11fc1SJed Brown C(P), specified by calling this function. An IFunction thus receives arguments (P, Cdot) and the IJacobian must be 545e3c11fc1SJed Brown evaluated via the chain rule, as in 546e3c11fc1SJed Brown 547e3c11fc1SJed Brown dF/dP + shift * dF/dCdot dC/dP. 548e3c11fc1SJed Brown 549*438f35afSJed Brown .seealso: TSSetTransientVariable(), DMTSGetTransientVariable(), DMTSSetIFunction(), DMTSSetIJacobian() 550e3c11fc1SJed Brown @*/ 551e3c11fc1SJed Brown PetscErrorCode DMTSSetTransientVariable(DM dm,TSTransientVariable tvar,void *ctx) 552e3c11fc1SJed Brown { 553e3c11fc1SJed Brown PetscErrorCode ierr; 554e3c11fc1SJed Brown DMTS dmts; 555e3c11fc1SJed Brown 556e3c11fc1SJed Brown PetscFunctionBegin; 557e3c11fc1SJed Brown PetscValidHeaderSpecific(dm,DM_CLASSID,1); 558e3c11fc1SJed Brown ierr = DMGetDMTSWrite(dm,&dmts);CHKERRQ(ierr); 559e3c11fc1SJed Brown dmts->ops->transientvar = tvar; 560e3c11fc1SJed Brown dmts->transientvarctx = ctx; 561e3c11fc1SJed Brown PetscFunctionReturn(0); 562e3c11fc1SJed Brown } 563e3c11fc1SJed Brown 564e3c11fc1SJed Brown /*@C 565e3c11fc1SJed Brown DMTSGetTransientVariable - gets function to transform from state to transient variables 566e3c11fc1SJed Brown 567e3c11fc1SJed Brown Logically Collective 568e3c11fc1SJed Brown 569e3c11fc1SJed Brown Input Arguments: 570e3c11fc1SJed Brown . dm - DM to be used with TS 571e3c11fc1SJed Brown 572e3c11fc1SJed Brown Output Arguments: 573e3c11fc1SJed Brown + tvar - a function that transforms in-place to transient variables 574e3c11fc1SJed Brown - ctx - a context for tvar 575e3c11fc1SJed Brown 576e3c11fc1SJed Brown Level: advanced 577e3c11fc1SJed Brown 578e3c11fc1SJed Brown .seealso: DMTSSetTransientVariable(), DMTSGetIFunction(), DMTSGetIJacobian() 579e3c11fc1SJed Brown @*/ 580e3c11fc1SJed Brown PetscErrorCode DMTSGetTransientVariable(DM dm,TSTransientVariable *tvar,void *ctx) 581e3c11fc1SJed Brown { 582e3c11fc1SJed Brown PetscErrorCode ierr; 583e3c11fc1SJed Brown DMTS dmts; 584e3c11fc1SJed Brown 585e3c11fc1SJed Brown PetscFunctionBegin; 586e3c11fc1SJed Brown PetscValidHeaderSpecific(dm,DM_CLASSID,1); 587e3c11fc1SJed Brown ierr = DMGetDMTS(dm,&dmts);CHKERRQ(ierr); 588e3c11fc1SJed Brown if (tvar) *tvar = dmts->ops->transientvar; 589e3c11fc1SJed Brown if (ctx) *(void**)ctx = dmts->transientvarctx; 590e3c11fc1SJed Brown PetscFunctionReturn(0); 591e3c11fc1SJed Brown } 592e3c11fc1SJed Brown 593e3c11fc1SJed Brown /*@C 594ef20d060SBarry Smith DMTSGetSolutionFunction - gets the TS solution evaluation function 595ef20d060SBarry Smith 596ef20d060SBarry Smith Not Collective 597ef20d060SBarry Smith 598ef20d060SBarry Smith Input Arguments: 599ef20d060SBarry Smith . dm - DM to be used with TS 600ef20d060SBarry Smith 601ef20d060SBarry Smith Output Parameters: 602ef20d060SBarry Smith + func - solution function evaluation function, see TSSetSolution() for calling sequence 603ef20d060SBarry Smith - ctx - context for solution evaluation 604ef20d060SBarry Smith 605ef20d060SBarry Smith Level: advanced 606ef20d060SBarry Smith 6070ed3bfb6SBarry Smith .seealso: DMTSSetContext(), TSSetFunction(), DMTSSetJacobian(), DMTSSetSolutionFunction() 608ef20d060SBarry Smith @*/ 609ef20d060SBarry Smith PetscErrorCode DMTSGetSolutionFunction(DM dm,TSSolutionFunction *func,void **ctx) 610ef20d060SBarry Smith { 611ef20d060SBarry Smith PetscErrorCode ierr; 612942e3340SBarry Smith DMTS tsdm; 613ef20d060SBarry Smith 614ef20d060SBarry Smith PetscFunctionBegin; 615ef20d060SBarry Smith PetscValidHeaderSpecific(dm,DM_CLASSID,1); 616942e3340SBarry Smith ierr = DMGetDMTS(dm,&tsdm);CHKERRQ(ierr); 617d74926cbSBarry Smith if (func) *func = tsdm->ops->solution; 618ef20d060SBarry Smith if (ctx) *ctx = tsdm->solutionctx; 619ef20d060SBarry Smith PetscFunctionReturn(0); 620ef20d060SBarry Smith } 621ef20d060SBarry Smith 622ef20d060SBarry Smith /*@C 623ef20d060SBarry Smith DMTSSetSolutionFunction - set TS solution evaluation function 624ef20d060SBarry Smith 625ef20d060SBarry Smith Not Collective 626ef20d060SBarry Smith 627ef20d060SBarry Smith Input Arguments: 628ef20d060SBarry Smith + dm - DM to be used with TS 629ef20d060SBarry Smith . func - solution function evaluation function, see TSSetSolution() for calling sequence 630ef20d060SBarry Smith - ctx - context for solution evaluation 631ef20d060SBarry Smith 632ef20d060SBarry Smith Level: advanced 633ef20d060SBarry Smith 634ef20d060SBarry Smith Note: 635ef20d060SBarry Smith TSSetSolutionFunction() is normally used, but it calls this function internally because the user context is actually 636ef20d060SBarry Smith associated with the DM. This makes the interface consistent regardless of whether the user interacts with a DM or 637ef20d060SBarry Smith not. If DM took a more central role at some later date, this could become the primary method of setting the residual. 638ef20d060SBarry Smith 6390ed3bfb6SBarry Smith .seealso: DMTSSetContext(), TSSetFunction(), DMTSSetJacobian(), DMTSGetSolutionFunction() 640ef20d060SBarry Smith @*/ 641ef20d060SBarry Smith PetscErrorCode DMTSSetSolutionFunction(DM dm,TSSolutionFunction func,void *ctx) 642ef20d060SBarry Smith { 643ef20d060SBarry Smith PetscErrorCode ierr; 644942e3340SBarry Smith DMTS tsdm; 645ef20d060SBarry Smith 646ef20d060SBarry Smith PetscFunctionBegin; 647ef20d060SBarry Smith PetscValidHeaderSpecific(dm,DM_CLASSID,1); 648942e3340SBarry Smith ierr = DMGetDMTSWrite(dm,&tsdm);CHKERRQ(ierr); 649d74926cbSBarry Smith if (func) tsdm->ops->solution = func; 650ef20d060SBarry Smith if (ctx) tsdm->solutionctx = ctx; 651ef20d060SBarry Smith PetscFunctionReturn(0); 652ef20d060SBarry Smith } 653ef20d060SBarry Smith 6549b7cd975SBarry Smith /*@C 6559b7cd975SBarry Smith DMTSSetForcingFunction - set TS forcing function evaluation function 6569b7cd975SBarry Smith 6579b7cd975SBarry Smith Not Collective 6589b7cd975SBarry Smith 6599b7cd975SBarry Smith Input Arguments: 6609b7cd975SBarry Smith + dm - DM to be used with TS 661f8b49ee9SBarry Smith . f - forcing function evaluation function; see TSForcingFunction 6629b7cd975SBarry Smith - ctx - context for solution evaluation 6639b7cd975SBarry Smith 6649b7cd975SBarry Smith Level: advanced 6659b7cd975SBarry Smith 6669b7cd975SBarry Smith Note: 6679b7cd975SBarry Smith TSSetForcingFunction() is normally used, but it calls this function internally because the user context is actually 6689b7cd975SBarry Smith associated with the DM. This makes the interface consistent regardless of whether the user interacts with a DM or 6699b7cd975SBarry Smith not. If DM took a more central role at some later date, this could become the primary method of setting the residual. 6709b7cd975SBarry Smith 6719b7cd975SBarry Smith .seealso: DMTSSetContext(), TSSetFunction(), DMTSSetJacobian(), TSSetForcingFunction(), DMTSGetForcingFunction() 6729b7cd975SBarry Smith @*/ 673d56366bfSLisandro Dalcin PetscErrorCode DMTSSetForcingFunction(DM dm,TSForcingFunction f,void *ctx) 6749b7cd975SBarry Smith { 6759b7cd975SBarry Smith PetscErrorCode ierr; 6769b7cd975SBarry Smith DMTS tsdm; 6779b7cd975SBarry Smith 6789b7cd975SBarry Smith PetscFunctionBegin; 6799b7cd975SBarry Smith PetscValidHeaderSpecific(dm,DM_CLASSID,1); 6809b7cd975SBarry Smith ierr = DMGetDMTSWrite(dm,&tsdm);CHKERRQ(ierr); 681f8b49ee9SBarry Smith if (f) tsdm->ops->forcing = f; 6829b7cd975SBarry Smith if (ctx) tsdm->forcingctx = ctx; 6839b7cd975SBarry Smith PetscFunctionReturn(0); 6849b7cd975SBarry Smith } 6859b7cd975SBarry Smith 6869b7cd975SBarry Smith 6879b7cd975SBarry Smith /*@C 6889b7cd975SBarry Smith DMTSGetForcingFunction - get TS forcing function evaluation function 6899b7cd975SBarry Smith 6909b7cd975SBarry Smith Not Collective 6919b7cd975SBarry Smith 6929b7cd975SBarry Smith Input Argument: 6939b7cd975SBarry Smith . dm - DM to be used with TS 6949b7cd975SBarry Smith 6959b7cd975SBarry Smith Output Arguments: 696f8b49ee9SBarry Smith + f - forcing function evaluation function; see TSForcingFunction for details 6979b7cd975SBarry Smith - ctx - context for solution evaluation 6989b7cd975SBarry Smith 6999b7cd975SBarry Smith Level: advanced 7009b7cd975SBarry Smith 7019b7cd975SBarry Smith Note: 7029b7cd975SBarry Smith TSSetForcingFunction() is normally used, but it calls this function internally because the user context is actually 7039b7cd975SBarry Smith associated with the DM. This makes the interface consistent regardless of whether the user interacts with a DM or 7049b7cd975SBarry Smith not. If DM took a more central role at some later date, this could become the primary method of setting the residual. 7059b7cd975SBarry Smith 7069b7cd975SBarry Smith .seealso: DMTSSetContext(), TSSetFunction(), DMTSSetJacobian(), TSSetForcingFunction(), DMTSGetForcingFunction() 7079b7cd975SBarry Smith @*/ 708d56366bfSLisandro Dalcin PetscErrorCode DMTSGetForcingFunction(DM dm,TSForcingFunction *f,void **ctx) 7099b7cd975SBarry Smith { 7109b7cd975SBarry Smith PetscErrorCode ierr; 7119b7cd975SBarry Smith DMTS tsdm; 7129b7cd975SBarry Smith 7139b7cd975SBarry Smith PetscFunctionBegin; 7149b7cd975SBarry Smith PetscValidHeaderSpecific(dm,DM_CLASSID,1); 7159b7cd975SBarry Smith ierr = DMGetDMTSWrite(dm,&tsdm);CHKERRQ(ierr); 716f8b49ee9SBarry Smith if (f) *f = tsdm->ops->forcing; 7179b7cd975SBarry Smith if (ctx) *ctx = tsdm->forcingctx; 7189b7cd975SBarry Smith PetscFunctionReturn(0); 7199b7cd975SBarry Smith } 7209b7cd975SBarry Smith 72124989b8cSPeter Brune /*@C 72224989b8cSPeter Brune DMTSGetRHSFunction - get TS explicit residual evaluation function 72324989b8cSPeter Brune 72424989b8cSPeter Brune Not Collective 72524989b8cSPeter Brune 72624989b8cSPeter Brune Input Argument: 72724989b8cSPeter Brune . dm - DM to be used with TS 72824989b8cSPeter Brune 72924989b8cSPeter Brune Output Arguments: 73024989b8cSPeter Brune + func - residual evaluation function, see TSSetRHSFunction() for calling sequence 73124989b8cSPeter Brune - ctx - context for residual evaluation 73224989b8cSPeter Brune 73324989b8cSPeter Brune Level: advanced 73424989b8cSPeter Brune 73524989b8cSPeter Brune Note: 73624989b8cSPeter Brune TSGetFunction() is normally used, but it calls this function internally because the user context is actually 73724989b8cSPeter Brune associated with the DM. 73824989b8cSPeter Brune 73924989b8cSPeter Brune .seealso: DMTSSetContext(), DMTSSetFunction(), TSSetFunction() 74024989b8cSPeter Brune @*/ 74124989b8cSPeter Brune PetscErrorCode DMTSGetRHSFunction(DM dm,TSRHSFunction *func,void **ctx) 74224989b8cSPeter Brune { 74324989b8cSPeter Brune PetscErrorCode ierr; 744942e3340SBarry Smith DMTS tsdm; 74524989b8cSPeter Brune 74624989b8cSPeter Brune PetscFunctionBegin; 74724989b8cSPeter Brune PetscValidHeaderSpecific(dm,DM_CLASSID,1); 748942e3340SBarry Smith ierr = DMGetDMTS(dm,&tsdm);CHKERRQ(ierr); 749d74926cbSBarry Smith if (func) *func = tsdm->ops->rhsfunction; 75024989b8cSPeter Brune if (ctx) *ctx = tsdm->rhsfunctionctx; 75124989b8cSPeter Brune PetscFunctionReturn(0); 75224989b8cSPeter Brune } 75324989b8cSPeter Brune 75424989b8cSPeter Brune /*@C 75524989b8cSPeter Brune DMTSSetIJacobian - 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 TSSetIJacobian() 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 DMTSSetIJacobian(DM dm,TSIJacobian func,void *ctx) 77424989b8cSPeter Brune { 77524989b8cSPeter Brune PetscErrorCode ierr; 776942e3340SBarry Smith DMTS sdm; 77724989b8cSPeter Brune 77824989b8cSPeter Brune PetscFunctionBegin; 77924989b8cSPeter Brune PetscValidHeaderSpecific(dm,DM_CLASSID,1); 780942e3340SBarry Smith ierr = DMGetDMTSWrite(dm,&sdm);CHKERRQ(ierr); 781d74926cbSBarry Smith if (func) sdm->ops->ijacobian = func; 78224989b8cSPeter Brune if (ctx) sdm->ijacobianctx = ctx; 78324989b8cSPeter Brune PetscFunctionReturn(0); 78424989b8cSPeter Brune } 78524989b8cSPeter Brune 78624989b8cSPeter Brune /*@C 78724989b8cSPeter Brune DMTSGetIJacobian - 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 TSSetIJacobian() 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 DMTSGetIJacobian(DM dm,TSIJacobian *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->ijacobian; 81624989b8cSPeter Brune if (ctx) *ctx = tsdm->ijacobianctx; 81724989b8cSPeter Brune PetscFunctionReturn(0); 81824989b8cSPeter Brune } 81924989b8cSPeter Brune 82024989b8cSPeter Brune 82124989b8cSPeter Brune /*@C 82224989b8cSPeter Brune DMTSSetRHSJacobian - set TS Jacobian evaluation function 82324989b8cSPeter Brune 82424989b8cSPeter Brune Not Collective 82524989b8cSPeter Brune 82624989b8cSPeter Brune Input Argument: 82724989b8cSPeter Brune + dm - DM to be used with TS 82824989b8cSPeter Brune . func - Jacobian evaluation function, see TSSetRHSJacobian() for calling sequence 82924989b8cSPeter Brune - ctx - context for residual evaluation 83024989b8cSPeter Brune 83124989b8cSPeter Brune Level: advanced 83224989b8cSPeter Brune 83324989b8cSPeter Brune Note: 83424989b8cSPeter Brune TSSetJacobian() is normally used, but it calls this function internally because the user context is actually 83524989b8cSPeter Brune associated with the DM. This makes the interface consistent regardless of whether the user interacts with a DM or 83624989b8cSPeter Brune not. If DM took a more central role at some later date, this could become the primary method of setting the Jacobian. 83724989b8cSPeter Brune 83824989b8cSPeter Brune .seealso: DMTSSetContext(), TSSetFunction(), DMTSGetJacobian(), TSSetJacobian() 83924989b8cSPeter Brune @*/ 84024989b8cSPeter Brune PetscErrorCode DMTSSetRHSJacobian(DM dm,TSRHSJacobian func,void *ctx) 84124989b8cSPeter Brune { 84224989b8cSPeter Brune PetscErrorCode ierr; 843942e3340SBarry Smith DMTS tsdm; 84424989b8cSPeter Brune 84524989b8cSPeter Brune PetscFunctionBegin; 84624989b8cSPeter Brune PetscValidHeaderSpecific(dm,DM_CLASSID,1); 847942e3340SBarry Smith ierr = DMGetDMTSWrite(dm,&tsdm);CHKERRQ(ierr); 848d74926cbSBarry Smith if (func) tsdm->ops->rhsjacobian = func; 84924989b8cSPeter Brune if (ctx) tsdm->rhsjacobianctx = ctx; 85024989b8cSPeter Brune PetscFunctionReturn(0); 85124989b8cSPeter Brune } 85224989b8cSPeter Brune 85324989b8cSPeter Brune /*@C 85424989b8cSPeter Brune DMTSGetRHSJacobian - get TS Jacobian evaluation function 85524989b8cSPeter Brune 85624989b8cSPeter Brune Not Collective 85724989b8cSPeter Brune 85824989b8cSPeter Brune Input Argument: 85924989b8cSPeter Brune . dm - DM to be used with TS 86024989b8cSPeter Brune 86124989b8cSPeter Brune Output Arguments: 86224989b8cSPeter Brune + func - Jacobian evaluation function, see TSSetRHSJacobian() for calling sequence 86324989b8cSPeter Brune - ctx - context for residual evaluation 86424989b8cSPeter Brune 86524989b8cSPeter Brune Level: advanced 86624989b8cSPeter Brune 86724989b8cSPeter Brune Note: 86824989b8cSPeter Brune TSGetJacobian() is normally used, but it calls this function internally because the user context is actually 86924989b8cSPeter Brune associated with the DM. This makes the interface consistent regardless of whether the user interacts with a DM or 87024989b8cSPeter Brune not. If DM took a more central role at some later date, this could become the primary method of setting the Jacobian. 87124989b8cSPeter Brune 87224989b8cSPeter Brune .seealso: DMTSSetContext(), TSSetFunction(), DMTSSetJacobian() 87324989b8cSPeter Brune @*/ 87424989b8cSPeter Brune PetscErrorCode DMTSGetRHSJacobian(DM dm,TSRHSJacobian *func,void **ctx) 87524989b8cSPeter Brune { 87624989b8cSPeter Brune PetscErrorCode ierr; 877942e3340SBarry Smith DMTS tsdm; 87824989b8cSPeter Brune 87924989b8cSPeter Brune PetscFunctionBegin; 88024989b8cSPeter Brune PetscValidHeaderSpecific(dm,DM_CLASSID,1); 881942e3340SBarry Smith ierr = DMGetDMTS(dm,&tsdm);CHKERRQ(ierr); 882d74926cbSBarry Smith if (func) *func = tsdm->ops->rhsjacobian; 88324989b8cSPeter Brune if (ctx) *ctx = tsdm->rhsjacobianctx; 88424989b8cSPeter Brune PetscFunctionReturn(0); 88524989b8cSPeter Brune } 886ad6bc421SBarry Smith 887ad6bc421SBarry Smith /*@C 888ad6bc421SBarry Smith DMTSSetIFunctionSerialize - sets functions used to view and load a IFunction context 889ad6bc421SBarry Smith 890ad6bc421SBarry Smith Not Collective 891ad6bc421SBarry Smith 892ad6bc421SBarry Smith Input Arguments: 893ad6bc421SBarry Smith + dm - DM to be used with TS 894ad6bc421SBarry Smith . view - viewer function 895ad6bc421SBarry Smith - load - loading function 896ad6bc421SBarry Smith 897ad6bc421SBarry Smith Level: advanced 898ad6bc421SBarry Smith 899ad6bc421SBarry Smith .seealso: DMTSSetContext(), TSSetFunction(), DMTSSetJacobian() 900ad6bc421SBarry Smith @*/ 901ad6bc421SBarry Smith PetscErrorCode DMTSSetIFunctionSerialize(DM dm,PetscErrorCode (*view)(void*,PetscViewer),PetscErrorCode (*load)(void**,PetscViewer)) 902ad6bc421SBarry Smith { 903ad6bc421SBarry Smith PetscErrorCode ierr; 904ad6bc421SBarry Smith DMTS tsdm; 905ad6bc421SBarry Smith 906ad6bc421SBarry Smith PetscFunctionBegin; 907ad6bc421SBarry Smith PetscValidHeaderSpecific(dm,DM_CLASSID,1); 908ad6bc421SBarry Smith ierr = DMGetDMTSWrite(dm,&tsdm);CHKERRQ(ierr); 909ad6bc421SBarry Smith tsdm->ops->ifunctionview = view; 910ad6bc421SBarry Smith tsdm->ops->ifunctionload = load; 911ad6bc421SBarry Smith PetscFunctionReturn(0); 912ad6bc421SBarry Smith } 913ad6bc421SBarry Smith 914ad6bc421SBarry Smith /*@C 915ad6bc421SBarry Smith DMTSSetIJacobianSerialize - sets functions used to view and load a IJacobian context 916ad6bc421SBarry Smith 917ad6bc421SBarry Smith Not Collective 918ad6bc421SBarry Smith 919ad6bc421SBarry Smith Input Arguments: 920ad6bc421SBarry Smith + dm - DM to be used with TS 921ad6bc421SBarry Smith . view - viewer function 922ad6bc421SBarry Smith - load - loading function 923ad6bc421SBarry Smith 924ad6bc421SBarry Smith Level: advanced 925ad6bc421SBarry Smith 926ad6bc421SBarry Smith .seealso: DMTSSetContext(), TSSetFunction(), DMTSSetJacobian() 927ad6bc421SBarry Smith @*/ 928ad6bc421SBarry Smith PetscErrorCode DMTSSetIJacobianSerialize(DM dm,PetscErrorCode (*view)(void*,PetscViewer),PetscErrorCode (*load)(void**,PetscViewer)) 929ad6bc421SBarry Smith { 930ad6bc421SBarry Smith PetscErrorCode ierr; 931ad6bc421SBarry Smith DMTS tsdm; 932ad6bc421SBarry Smith 933ad6bc421SBarry Smith PetscFunctionBegin; 934ad6bc421SBarry Smith PetscValidHeaderSpecific(dm,DM_CLASSID,1); 935ad6bc421SBarry Smith ierr = DMGetDMTSWrite(dm,&tsdm);CHKERRQ(ierr); 936ad6bc421SBarry Smith tsdm->ops->ijacobianview = view; 937ad6bc421SBarry Smith tsdm->ops->ijacobianload = load; 938ad6bc421SBarry Smith PetscFunctionReturn(0); 939ad6bc421SBarry Smith } 940