1af0996ceSBarry Smith #include <petsc/private/tsimpl.h> /*I "petscts.h" I*/ 2af0996ceSBarry Smith #include <petsc/private/dmimpl.h> 324989b8cSPeter Brune 4*800f99ffSJeremy L Thompson static PetscErrorCode DMTSUnsetRHSFunctionContext_DMTS(DMTS tsdm) 5*800f99ffSJeremy L Thompson { 6*800f99ffSJeremy L Thompson PetscFunctionBegin; 7*800f99ffSJeremy L Thompson PetscCall(PetscObjectCompose((PetscObject)tsdm,"rhs function ctx",NULL)); 8*800f99ffSJeremy L Thompson tsdm->rhsfunctionctxcontainer = NULL; 9*800f99ffSJeremy L Thompson PetscFunctionReturn(0); 10*800f99ffSJeremy L Thompson } 11*800f99ffSJeremy L Thompson 12*800f99ffSJeremy L Thompson static PetscErrorCode DMTSUnsetRHSJacobianContext_DMTS(DMTS tsdm) 13*800f99ffSJeremy L Thompson { 14*800f99ffSJeremy L Thompson PetscFunctionBegin; 15*800f99ffSJeremy L Thompson PetscCall(PetscObjectCompose((PetscObject)tsdm,"rhs jacobian ctx",NULL)); 16*800f99ffSJeremy L Thompson tsdm->rhsjacobianctxcontainer = NULL; 17*800f99ffSJeremy L Thompson PetscFunctionReturn(0); 18*800f99ffSJeremy L Thompson } 19*800f99ffSJeremy L Thompson 20*800f99ffSJeremy L Thompson static PetscErrorCode DMTSUnsetIFunctionContext_DMTS(DMTS tsdm) 21*800f99ffSJeremy L Thompson { 22*800f99ffSJeremy L Thompson PetscFunctionBegin; 23*800f99ffSJeremy L Thompson PetscCall(PetscObjectCompose((PetscObject)tsdm,"ifunction ctx",NULL)); 24*800f99ffSJeremy L Thompson tsdm->ifunctionctxcontainer = NULL; 25*800f99ffSJeremy L Thompson PetscFunctionReturn(0); 26*800f99ffSJeremy L Thompson } 27*800f99ffSJeremy L Thompson 28*800f99ffSJeremy L Thompson static PetscErrorCode DMTSUnsetIJacobianContext_DMTS(DMTS tsdm) 29*800f99ffSJeremy L Thompson { 30*800f99ffSJeremy L Thompson PetscFunctionBegin; 31*800f99ffSJeremy L Thompson PetscCall(PetscObjectCompose((PetscObject)tsdm,"ijacobian ctx",NULL)); 32*800f99ffSJeremy L Thompson tsdm->ijacobianctxcontainer = NULL; 33*800f99ffSJeremy L Thompson PetscFunctionReturn(0); 34*800f99ffSJeremy L Thompson } 35*800f99ffSJeremy L Thompson 36*800f99ffSJeremy L Thompson static PetscErrorCode DMTSUnsetI2FunctionContext_DMTS(DMTS tsdm) 37*800f99ffSJeremy L Thompson { 38*800f99ffSJeremy L Thompson PetscFunctionBegin; 39*800f99ffSJeremy L Thompson PetscCall(PetscObjectCompose((PetscObject)tsdm,"i2function ctx",NULL)); 40*800f99ffSJeremy L Thompson tsdm->i2functionctxcontainer = NULL; 41*800f99ffSJeremy L Thompson PetscFunctionReturn(0); 42*800f99ffSJeremy L Thompson } 43*800f99ffSJeremy L Thompson 44*800f99ffSJeremy L Thompson static PetscErrorCode DMTSUnsetI2JacobianContext_DMTS(DMTS tsdm) 45*800f99ffSJeremy L Thompson { 46*800f99ffSJeremy L Thompson PetscFunctionBegin; 47*800f99ffSJeremy L Thompson PetscCall(PetscObjectCompose((PetscObject)tsdm,"i2jacobian ctx",NULL)); 48*800f99ffSJeremy L Thompson tsdm->i2jacobianctxcontainer = NULL; 49*800f99ffSJeremy L Thompson PetscFunctionReturn(0); 50*800f99ffSJeremy L Thompson } 51*800f99ffSJeremy L Thompson 52d74926cbSBarry Smith static PetscErrorCode DMTSDestroy(DMTS *kdm) 53d74926cbSBarry Smith { 54d74926cbSBarry Smith PetscFunctionBegin; 55d74926cbSBarry Smith if (!*kdm) PetscFunctionReturn(0); 56d74926cbSBarry Smith PetscValidHeaderSpecific((*kdm),DMTS_CLASSID,1); 57c793f718SLisandro Dalcin if (--((PetscObject)(*kdm))->refct > 0) {*kdm = NULL; PetscFunctionReturn(0);} 58*800f99ffSJeremy L Thompson PetscCall(DMTSUnsetRHSFunctionContext_DMTS(*kdm)); 59*800f99ffSJeremy L Thompson PetscCall(DMTSUnsetRHSJacobianContext_DMTS(*kdm)); 60*800f99ffSJeremy L Thompson PetscCall(DMTSUnsetIFunctionContext_DMTS(*kdm)); 61*800f99ffSJeremy L Thompson PetscCall(DMTSUnsetIJacobianContext_DMTS(*kdm)); 62*800f99ffSJeremy L Thompson PetscCall(DMTSUnsetI2FunctionContext_DMTS(*kdm)); 63*800f99ffSJeremy L Thompson PetscCall(DMTSUnsetI2JacobianContext_DMTS(*kdm)); 649566063dSJacob Faibussowitsch if ((*kdm)->ops->destroy) PetscCall(((*kdm)->ops->destroy)(*kdm)); 659566063dSJacob Faibussowitsch PetscCall(PetscHeaderDestroy(kdm)); 66d74926cbSBarry Smith PetscFunctionReturn(0); 67d74926cbSBarry Smith } 68d74926cbSBarry Smith 692d53ad75SBarry Smith PetscErrorCode DMTSLoad(DMTS kdm,PetscViewer viewer) 702d53ad75SBarry Smith { 712d53ad75SBarry Smith PetscFunctionBegin; 729566063dSJacob Faibussowitsch PetscCall(PetscViewerBinaryRead(viewer,&kdm->ops->ifunction,1,NULL,PETSC_FUNCTION)); 739566063dSJacob Faibussowitsch PetscCall(PetscViewerBinaryRead(viewer,&kdm->ops->ifunctionview,1,NULL,PETSC_FUNCTION)); 749566063dSJacob Faibussowitsch PetscCall(PetscViewerBinaryRead(viewer,&kdm->ops->ifunctionload,1,NULL,PETSC_FUNCTION)); 75ad6bc421SBarry Smith if (kdm->ops->ifunctionload) { 76*800f99ffSJeremy L Thompson void *ctx; 77*800f99ffSJeremy L Thompson 78*800f99ffSJeremy L Thompson PetscCall(PetscContainerGetPointer(kdm->ifunctionctxcontainer,&ctx)); 79*800f99ffSJeremy L Thompson PetscCall((*kdm->ops->ifunctionload)(&ctx,viewer)); 80ad6bc421SBarry Smith } 819566063dSJacob Faibussowitsch PetscCall(PetscViewerBinaryRead(viewer,&kdm->ops->ijacobian,1,NULL,PETSC_FUNCTION)); 829566063dSJacob Faibussowitsch PetscCall(PetscViewerBinaryRead(viewer,&kdm->ops->ijacobianview,1,NULL,PETSC_FUNCTION)); 839566063dSJacob Faibussowitsch PetscCall(PetscViewerBinaryRead(viewer,&kdm->ops->ijacobianload,1,NULL,PETSC_FUNCTION)); 84ad6bc421SBarry Smith if (kdm->ops->ijacobianload) { 85*800f99ffSJeremy L Thompson void *ctx; 86*800f99ffSJeremy L Thompson 87*800f99ffSJeremy L Thompson PetscCall(PetscContainerGetPointer(kdm->ijacobianctxcontainer,&ctx)); 88*800f99ffSJeremy L Thompson PetscCall((*kdm->ops->ijacobianload)(&ctx,viewer)); 89ad6bc421SBarry Smith } 902d53ad75SBarry Smith PetscFunctionReturn(0); 912d53ad75SBarry Smith } 922d53ad75SBarry Smith 932d53ad75SBarry Smith PetscErrorCode DMTSView(DMTS kdm,PetscViewer viewer) 942d53ad75SBarry Smith { 952d53ad75SBarry Smith PetscBool isascii,isbinary; 962d53ad75SBarry Smith 972d53ad75SBarry Smith PetscFunctionBegin; 989566063dSJacob Faibussowitsch PetscCall(PetscObjectTypeCompare((PetscObject)viewer,PETSCVIEWERASCII,&isascii)); 999566063dSJacob Faibussowitsch PetscCall(PetscObjectTypeCompare((PetscObject)viewer,PETSCVIEWERBINARY,&isbinary)); 1002d53ad75SBarry Smith if (isascii) { 101c7a10e08SBarry Smith #if defined(PETSC_SERIALIZE_FUNCTIONS) 1022d53ad75SBarry Smith const char *fname; 1032d53ad75SBarry Smith 1049566063dSJacob Faibussowitsch PetscCall(PetscFPTFind(kdm->ops->ifunction,&fname)); 1052d53ad75SBarry Smith if (fname) { 1069566063dSJacob Faibussowitsch PetscCall(PetscViewerASCIIPrintf(viewer," IFunction used by TS: %s\n",fname)); 1072d53ad75SBarry Smith } 1089566063dSJacob Faibussowitsch PetscCall(PetscFPTFind(kdm->ops->ijacobian,&fname)); 1092d53ad75SBarry Smith if (fname) { 1109566063dSJacob Faibussowitsch PetscCall(PetscViewerASCIIPrintf(viewer," IJacobian function used by TS: %s\n",fname)); 1112d53ad75SBarry Smith } 112c7a10e08SBarry Smith #endif 1132d53ad75SBarry Smith } else if (isbinary) { 1143964eb88SJed Brown struct { 1153964eb88SJed Brown TSIFunction ifunction; 1169200755eSBarry Smith } funcstruct; 1179200755eSBarry Smith struct { 1183964eb88SJed Brown PetscErrorCode (*ifunctionview)(void*,PetscViewer); 1199200755eSBarry Smith } funcviewstruct; 1209200755eSBarry Smith struct { 1213964eb88SJed Brown PetscErrorCode (*ifunctionload)(void**,PetscViewer); 1229200755eSBarry Smith } funcloadstruct; 1233964eb88SJed Brown struct { 1243964eb88SJed Brown TSIJacobian ijacobian; 1259200755eSBarry Smith } jacstruct; 1269200755eSBarry Smith struct { 1273964eb88SJed Brown PetscErrorCode (*ijacobianview)(void*,PetscViewer); 1289200755eSBarry Smith } jacviewstruct; 1299200755eSBarry Smith struct { 1303964eb88SJed Brown PetscErrorCode (*ijacobianload)(void**,PetscViewer); 1319200755eSBarry Smith } jacloadstruct; 1323964eb88SJed Brown 1339200755eSBarry Smith funcstruct.ifunction = kdm->ops->ifunction; 1349200755eSBarry Smith funcviewstruct.ifunctionview = kdm->ops->ifunctionview; 1359200755eSBarry Smith funcloadstruct.ifunctionload = kdm->ops->ifunctionload; 1369566063dSJacob Faibussowitsch PetscCall(PetscViewerBinaryWrite(viewer,&funcstruct,1,PETSC_FUNCTION)); 1379566063dSJacob Faibussowitsch PetscCall(PetscViewerBinaryWrite(viewer,&funcviewstruct,1,PETSC_FUNCTION)); 1389566063dSJacob Faibussowitsch PetscCall(PetscViewerBinaryWrite(viewer,&funcloadstruct,1,PETSC_FUNCTION)); 139*800f99ffSJeremy L Thompson if (kdm->ops->ifunctionview) { 140*800f99ffSJeremy L Thompson void *ctx; 141*800f99ffSJeremy L Thompson 142*800f99ffSJeremy L Thompson PetscCall(PetscContainerGetPointer(kdm->ifunctionctxcontainer,&ctx)); 143*800f99ffSJeremy L Thompson PetscCall((*kdm->ops->ifunctionview)(ctx,viewer)); 144*800f99ffSJeremy L Thompson } 1459200755eSBarry Smith jacstruct.ijacobian = kdm->ops->ijacobian; 1469200755eSBarry Smith jacviewstruct.ijacobianview = kdm->ops->ijacobianview; 1479200755eSBarry Smith jacloadstruct.ijacobianload = kdm->ops->ijacobianload; 1489566063dSJacob Faibussowitsch PetscCall(PetscViewerBinaryWrite(viewer,&jacstruct,1,PETSC_FUNCTION)); 1499566063dSJacob Faibussowitsch PetscCall(PetscViewerBinaryWrite(viewer,&jacviewstruct,1,PETSC_FUNCTION)); 1509566063dSJacob Faibussowitsch PetscCall(PetscViewerBinaryWrite(viewer,&jacloadstruct,1,PETSC_FUNCTION)); 151*800f99ffSJeremy L Thompson if (kdm->ops->ijacobianview) { 152*800f99ffSJeremy L Thompson void *ctx; 153*800f99ffSJeremy L Thompson 154*800f99ffSJeremy L Thompson PetscCall(PetscContainerGetPointer(kdm->ijacobianctxcontainer,&ctx)); 155*800f99ffSJeremy L Thompson PetscCall((*kdm->ops->ijacobianview)(ctx,viewer)); 156*800f99ffSJeremy L Thompson } 1572d53ad75SBarry Smith } 1582d53ad75SBarry Smith PetscFunctionReturn(0); 1592d53ad75SBarry Smith } 1602d53ad75SBarry Smith 161d74926cbSBarry Smith static PetscErrorCode DMTSCreate(MPI_Comm comm,DMTS *kdm) 162d74926cbSBarry Smith { 163d74926cbSBarry Smith PetscFunctionBegin; 1649566063dSJacob Faibussowitsch PetscCall(TSInitializePackage()); 1659566063dSJacob Faibussowitsch PetscCall(PetscHeaderCreate(*kdm, DMTS_CLASSID, "DMTS", "DMTS", "DMTS", comm, DMTSDestroy, DMTSView)); 166d74926cbSBarry Smith PetscFunctionReturn(0); 167d74926cbSBarry Smith } 16824989b8cSPeter Brune 1692a34c10cSBarry Smith /* Attaches the DMTS to the coarse level. 17024989b8cSPeter Brune * Under what conditions should we copy versus duplicate? 17124989b8cSPeter Brune */ 172942e3340SBarry Smith static PetscErrorCode DMCoarsenHook_DMTS(DM dm,DM dmc,void *ctx) 17324989b8cSPeter Brune { 17424989b8cSPeter Brune PetscFunctionBegin; 1759566063dSJacob Faibussowitsch PetscCall(DMCopyDMTS(dm,dmc)); 17624989b8cSPeter Brune PetscFunctionReturn(0); 17724989b8cSPeter Brune } 17824989b8cSPeter Brune 17924989b8cSPeter Brune /* This could restrict auxiliary information to the coarse level. 18024989b8cSPeter Brune */ 181942e3340SBarry Smith static PetscErrorCode DMRestrictHook_DMTS(DM dm,Mat Restrict,Vec rscale,Mat Inject,DM dmc,void *ctx) 18224989b8cSPeter Brune { 18324989b8cSPeter Brune PetscFunctionBegin; 18424989b8cSPeter Brune PetscFunctionReturn(0); 18524989b8cSPeter Brune } 18624989b8cSPeter Brune 187258e1594SPeter Brune static PetscErrorCode DMSubDomainHook_DMTS(DM dm,DM subdm,void *ctx) 188258e1594SPeter Brune { 189258e1594SPeter Brune PetscFunctionBegin; 1909566063dSJacob Faibussowitsch PetscCall(DMCopyDMTS(dm,subdm)); 191258e1594SPeter Brune PetscFunctionReturn(0); 192258e1594SPeter Brune } 193258e1594SPeter Brune 194258e1594SPeter Brune /* This could restrict auxiliary information to the coarse level. 195258e1594SPeter Brune */ 196258e1594SPeter Brune static PetscErrorCode DMSubDomainRestrictHook_DMTS(DM dm,VecScatter gscat,VecScatter lscat,DM subdm,void *ctx) 197258e1594SPeter Brune { 198258e1594SPeter Brune PetscFunctionBegin; 199258e1594SPeter Brune PetscFunctionReturn(0); 200258e1594SPeter Brune } 201258e1594SPeter Brune 202d74926cbSBarry Smith /*@C 203d74926cbSBarry Smith DMTSCopy - copies the information in a DMTS to another DMTS 204d74926cbSBarry Smith 205d74926cbSBarry Smith Not Collective 206d74926cbSBarry Smith 2074165533cSJose E. Roman Input Parameters: 208d74926cbSBarry Smith + kdm - Original DMTS 209d74926cbSBarry Smith - nkdm - DMTS to receive the data, should have been created with DMTSCreate() 210d74926cbSBarry Smith 211d74926cbSBarry Smith Level: developer 212d74926cbSBarry Smith 213db781477SPatrick Sanan .seealso: `DMTSCreate()`, `DMTSDestroy()` 214d74926cbSBarry Smith @*/ 215d74926cbSBarry Smith PetscErrorCode DMTSCopy(DMTS kdm,DMTS nkdm) 21624989b8cSPeter Brune { 21724989b8cSPeter Brune PetscFunctionBegin; 218d74926cbSBarry Smith PetscValidHeaderSpecific(kdm,DMTS_CLASSID,1); 219d74926cbSBarry Smith PetscValidHeaderSpecific(nkdm,DMTS_CLASSID,2); 220d74926cbSBarry Smith nkdm->ops->rhsfunction = kdm->ops->rhsfunction; 221d74926cbSBarry Smith nkdm->ops->rhsjacobian = kdm->ops->rhsjacobian; 222d74926cbSBarry Smith nkdm->ops->ifunction = kdm->ops->ifunction; 223d74926cbSBarry Smith nkdm->ops->ijacobian = kdm->ops->ijacobian; 224efe9872eSLisandro Dalcin nkdm->ops->i2function = kdm->ops->i2function; 225efe9872eSLisandro Dalcin nkdm->ops->i2jacobian = kdm->ops->i2jacobian; 226d74926cbSBarry Smith nkdm->ops->solution = kdm->ops->solution; 227d74926cbSBarry Smith nkdm->ops->destroy = kdm->ops->destroy; 228d74926cbSBarry Smith nkdm->ops->duplicate = kdm->ops->duplicate; 229d74926cbSBarry Smith 230d74926cbSBarry Smith nkdm->solutionctx = kdm->solutionctx; 231*800f99ffSJeremy L Thompson nkdm->rhsfunctionctxcontainer = kdm->rhsfunctionctxcontainer; 232*800f99ffSJeremy L Thompson nkdm->rhsjacobianctxcontainer = kdm->rhsjacobianctxcontainer; 233*800f99ffSJeremy L Thompson nkdm->ifunctionctxcontainer = kdm->ifunctionctxcontainer; 234*800f99ffSJeremy L Thompson nkdm->ijacobianctxcontainer = kdm->ijacobianctxcontainer; 235*800f99ffSJeremy L Thompson nkdm->i2functionctxcontainer = kdm->i2functionctxcontainer; 236*800f99ffSJeremy L Thompson nkdm->i2jacobianctxcontainer = kdm->i2jacobianctxcontainer; 237*800f99ffSJeremy L Thompson if (nkdm->rhsfunctionctxcontainer) PetscCall(PetscObjectCompose((PetscObject)nkdm,"rhs function ctx",(PetscObject)nkdm->rhsfunctionctxcontainer)); 238*800f99ffSJeremy L Thompson if (nkdm->rhsjacobianctxcontainer) PetscCall(PetscObjectCompose((PetscObject)nkdm,"rhs jacobian ctx",(PetscObject)nkdm->rhsjacobianctxcontainer)); 239*800f99ffSJeremy L Thompson if (nkdm->ifunctionctxcontainer) PetscCall(PetscObjectCompose((PetscObject)nkdm,"ifunction ctx",(PetscObject)nkdm->ifunctionctxcontainer)); 240*800f99ffSJeremy L Thompson if (nkdm->ijacobianctxcontainer) PetscCall(PetscObjectCompose((PetscObject)nkdm,"ijacobian ctx",(PetscObject)nkdm->ijacobianctxcontainer)); 241*800f99ffSJeremy L Thompson if (nkdm->i2functionctxcontainer) PetscCall(PetscObjectCompose((PetscObject)nkdm,"i2function ctx",(PetscObject)nkdm->i2functionctxcontainer)); 242*800f99ffSJeremy L Thompson if (nkdm->i2jacobianctxcontainer) PetscCall(PetscObjectCompose((PetscObject)nkdm,"i2jacobian ctx",(PetscObject)nkdm->i2jacobianctxcontainer)); 243d74926cbSBarry Smith 244d74926cbSBarry Smith nkdm->data = kdm->data; 245d74926cbSBarry Smith 246d74926cbSBarry Smith /* 247d74926cbSBarry Smith nkdm->fortran_func_pointers[0] = kdm->fortran_func_pointers[0]; 248d74926cbSBarry Smith nkdm->fortran_func_pointers[1] = kdm->fortran_func_pointers[1]; 249d74926cbSBarry Smith nkdm->fortran_func_pointers[2] = kdm->fortran_func_pointers[2]; 250d74926cbSBarry Smith */ 251d74926cbSBarry Smith 252d74926cbSBarry Smith /* implementation specific copy hooks */ 2539566063dSJacob Faibussowitsch if (kdm->ops->duplicate) PetscCall((*kdm->ops->duplicate)(kdm,nkdm)); 25424989b8cSPeter Brune PetscFunctionReturn(0); 25524989b8cSPeter Brune } 25624989b8cSPeter Brune 25724989b8cSPeter Brune /*@C 258942e3340SBarry Smith DMGetDMTS - get read-only private DMTS context from a DM 25924989b8cSPeter Brune 26024989b8cSPeter Brune Not Collective 26124989b8cSPeter Brune 2624165533cSJose E. Roman Input Parameter: 26324989b8cSPeter Brune . dm - DM to be used with TS 26424989b8cSPeter Brune 2654165533cSJose E. Roman Output Parameter: 266942e3340SBarry Smith . tsdm - private DMTS context 26724989b8cSPeter Brune 26824989b8cSPeter Brune Level: developer 26924989b8cSPeter Brune 27024989b8cSPeter Brune Notes: 271942e3340SBarry Smith Use DMGetDMTSWrite() if write access is needed. The DMTSSetXXX API should be used wherever possible. 27224989b8cSPeter Brune 273db781477SPatrick Sanan .seealso: `DMGetDMTSWrite()` 27424989b8cSPeter Brune @*/ 275942e3340SBarry Smith PetscErrorCode DMGetDMTS(DM dm,DMTS *tsdm) 27624989b8cSPeter Brune { 27724989b8cSPeter Brune PetscFunctionBegin; 27824989b8cSPeter Brune PetscValidHeaderSpecific(dm,DM_CLASSID,1); 2792a34c10cSBarry Smith *tsdm = (DMTS) dm->dmts; 280d74926cbSBarry Smith if (!*tsdm) { 2819566063dSJacob Faibussowitsch PetscCall(PetscInfo(dm,"Creating new DMTS\n")); 2829566063dSJacob Faibussowitsch PetscCall(DMTSCreate(PetscObjectComm((PetscObject)dm),tsdm)); 2832a34c10cSBarry Smith dm->dmts = (PetscObject) *tsdm; 2845c87d4f4SJunchao Zhang (*tsdm)->originaldm = dm; 2859566063dSJacob Faibussowitsch PetscCall(DMCoarsenHookAdd(dm,DMCoarsenHook_DMTS,DMRestrictHook_DMTS,NULL)); 2869566063dSJacob Faibussowitsch PetscCall(DMSubDomainHookAdd(dm,DMSubDomainHook_DMTS,DMSubDomainRestrictHook_DMTS,NULL)); 28724989b8cSPeter Brune } 28824989b8cSPeter Brune PetscFunctionReturn(0); 28924989b8cSPeter Brune } 29024989b8cSPeter Brune 29124989b8cSPeter Brune /*@C 292942e3340SBarry Smith DMGetDMTSWrite - get write access to private DMTS context from a DM 29324989b8cSPeter Brune 29424989b8cSPeter Brune Not Collective 29524989b8cSPeter Brune 2964165533cSJose E. Roman Input Parameter: 29724989b8cSPeter Brune . dm - DM to be used with TS 29824989b8cSPeter Brune 2994165533cSJose E. Roman Output Parameter: 300942e3340SBarry Smith . tsdm - private DMTS context 30124989b8cSPeter Brune 30224989b8cSPeter Brune Level: developer 30324989b8cSPeter Brune 304db781477SPatrick Sanan .seealso: `DMGetDMTS()` 30524989b8cSPeter Brune @*/ 306942e3340SBarry Smith PetscErrorCode DMGetDMTSWrite(DM dm,DMTS *tsdm) 30724989b8cSPeter Brune { 308942e3340SBarry Smith DMTS sdm; 30924989b8cSPeter Brune 31024989b8cSPeter Brune PetscFunctionBegin; 31124989b8cSPeter Brune PetscValidHeaderSpecific(dm,DM_CLASSID,1); 3129566063dSJacob Faibussowitsch PetscCall(DMGetDMTS(dm,&sdm)); 3133c633725SBarry Smith PetscCheck(sdm->originaldm,PETSC_COMM_SELF,PETSC_ERR_ARG_WRONGSTATE,"DMTS has a NULL originaldm"); 31424989b8cSPeter Brune if (sdm->originaldm != dm) { /* Copy on write */ 3152a34c10cSBarry Smith DMTS oldsdm = sdm; 3169566063dSJacob Faibussowitsch PetscCall(PetscInfo(dm,"Copying DMTS due to write\n")); 3179566063dSJacob Faibussowitsch PetscCall(DMTSCreate(PetscObjectComm((PetscObject)dm),&sdm)); 3189566063dSJacob Faibussowitsch PetscCall(DMTSCopy(oldsdm,sdm)); 3199566063dSJacob Faibussowitsch PetscCall(DMTSDestroy((DMTS*)&dm->dmts)); 3202a34c10cSBarry Smith dm->dmts = (PetscObject) sdm; 3215c87d4f4SJunchao Zhang sdm->originaldm = dm; 32224989b8cSPeter Brune } 32324989b8cSPeter Brune *tsdm = sdm; 32424989b8cSPeter Brune PetscFunctionReturn(0); 32524989b8cSPeter Brune } 32624989b8cSPeter Brune 32724989b8cSPeter Brune /*@C 328942e3340SBarry Smith DMCopyDMTS - copies a DM context to a new DM 32924989b8cSPeter Brune 33024989b8cSPeter Brune Logically Collective 33124989b8cSPeter Brune 3324165533cSJose E. Roman Input Parameters: 33324989b8cSPeter Brune + dmsrc - DM to obtain context from 33424989b8cSPeter Brune - dmdest - DM to add context to 33524989b8cSPeter Brune 33624989b8cSPeter Brune Level: developer 33724989b8cSPeter Brune 33824989b8cSPeter Brune Note: 33924989b8cSPeter Brune The context is copied by reference. This function does not ensure that a context exists. 34024989b8cSPeter Brune 341db781477SPatrick Sanan .seealso: `DMGetDMTS()`, `TSSetDM()` 34224989b8cSPeter Brune @*/ 343942e3340SBarry Smith PetscErrorCode DMCopyDMTS(DM dmsrc,DM dmdest) 34424989b8cSPeter Brune { 34524989b8cSPeter Brune PetscFunctionBegin; 34624989b8cSPeter Brune PetscValidHeaderSpecific(dmsrc,DM_CLASSID,1); 34724989b8cSPeter Brune PetscValidHeaderSpecific(dmdest,DM_CLASSID,2); 3489566063dSJacob Faibussowitsch PetscCall(DMTSDestroy((DMTS*)&dmdest->dmts)); 3492a34c10cSBarry Smith dmdest->dmts = dmsrc->dmts; 3509566063dSJacob Faibussowitsch PetscCall(PetscObjectReference(dmdest->dmts)); 3519566063dSJacob Faibussowitsch PetscCall(DMCoarsenHookAdd(dmdest,DMCoarsenHook_DMTS,DMRestrictHook_DMTS,NULL)); 3529566063dSJacob Faibussowitsch PetscCall(DMSubDomainHookAdd(dmdest,DMSubDomainHook_DMTS,DMSubDomainRestrictHook_DMTS,NULL)); 35324989b8cSPeter Brune PetscFunctionReturn(0); 35424989b8cSPeter Brune } 35524989b8cSPeter Brune 35624989b8cSPeter Brune /*@C 35724989b8cSPeter Brune DMTSSetIFunction - set TS implicit function evaluation function 35824989b8cSPeter Brune 35924989b8cSPeter Brune Not Collective 36024989b8cSPeter Brune 3614165533cSJose E. Roman Input Parameters: 36224989b8cSPeter Brune + dm - DM to be used with TS 363a96d6ef6SBarry Smith . func - function evaluating f(t,u,u_t) 36424989b8cSPeter Brune - ctx - context for residual evaluation 36524989b8cSPeter Brune 366a96d6ef6SBarry Smith Calling sequence of func: 367a96d6ef6SBarry Smith $ PetscErrorCode func(TS ts,PetscReal t,Vec u,Vec u_t,Vec F,ctx); 368a96d6ef6SBarry Smith 369a96d6ef6SBarry Smith + t - time at step/stage being solved 370a96d6ef6SBarry Smith . u - state vector 371a96d6ef6SBarry Smith . u_t - time derivative of state vector 372a96d6ef6SBarry Smith . F - function vector 373a96d6ef6SBarry Smith - ctx - [optional] user-defined context for matrix evaluation routine 374a96d6ef6SBarry Smith 37524989b8cSPeter Brune Level: advanced 37624989b8cSPeter Brune 37724989b8cSPeter Brune Note: 37824989b8cSPeter Brune TSSetFunction() is normally used, but it calls this function internally because the user context is actually 37924989b8cSPeter Brune associated with the DM. This makes the interface consistent regardless of whether the user interacts with a DM or 38024989b8cSPeter Brune not. If DM took a more central role at some later date, this could become the primary method of setting the residual. 38124989b8cSPeter Brune 382db781477SPatrick Sanan .seealso: `DMTSSetContext()`, `TSSetIFunction()`, `DMTSSetJacobian()` 38324989b8cSPeter Brune @*/ 38424989b8cSPeter Brune PetscErrorCode DMTSSetIFunction(DM dm,TSIFunction func,void *ctx) 38524989b8cSPeter Brune { 386942e3340SBarry Smith DMTS tsdm; 38724989b8cSPeter Brune 38824989b8cSPeter Brune PetscFunctionBegin; 38924989b8cSPeter Brune PetscValidHeaderSpecific(dm,DM_CLASSID,1); 3909566063dSJacob Faibussowitsch PetscCall(DMGetDMTSWrite(dm,&tsdm)); 391d74926cbSBarry Smith if (func) tsdm->ops->ifunction = func; 392*800f99ffSJeremy L Thompson if (ctx) { 393*800f99ffSJeremy L Thompson PetscContainer ctxcontainer; 394*800f99ffSJeremy L Thompson PetscCall(PetscContainerCreate(PetscObjectComm((PetscObject)tsdm),&ctxcontainer)); 395*800f99ffSJeremy L Thompson PetscCall(PetscContainerSetPointer(ctxcontainer,ctx)); 396*800f99ffSJeremy L Thompson PetscCall(PetscObjectCompose((PetscObject)tsdm,"ifunction ctx",(PetscObject)ctxcontainer)); 397*800f99ffSJeremy L Thompson tsdm->ifunctionctxcontainer = ctxcontainer; 398*800f99ffSJeremy L Thompson PetscCall(PetscContainerDestroy(&ctxcontainer)); 399*800f99ffSJeremy L Thompson } 400*800f99ffSJeremy L Thompson PetscFunctionReturn(0); 401*800f99ffSJeremy L Thompson } 402*800f99ffSJeremy L Thompson 403*800f99ffSJeremy L Thompson /*@C 404*800f99ffSJeremy L Thompson DMTSSetIFunctionContextDestroy - set TS implicit evaluation context destroy function 405*800f99ffSJeremy L Thompson 406*800f99ffSJeremy L Thompson Not Collective 407*800f99ffSJeremy L Thompson 408*800f99ffSJeremy L Thompson Input Parameters: 409*800f99ffSJeremy L Thompson + dm - DM to be used with TS 410*800f99ffSJeremy L Thompson . f - implicit evaluation context destroy function 411*800f99ffSJeremy L Thompson 412*800f99ffSJeremy L Thompson Level: advanced 413*800f99ffSJeremy L Thompson 414*800f99ffSJeremy L Thompson Note: 415*800f99ffSJeremy L Thompson TSSetFunctionContextDestroy() is normally used, but it calls this function internally because the user context is actually 416*800f99ffSJeremy L Thompson associated with the DM. This makes the interface consistent regardless of whether the user interacts with a DM or 417*800f99ffSJeremy L Thompson not. If DM took a more central role at some later date, this could become the primary method of setting the residual. 418*800f99ffSJeremy L Thompson 419*800f99ffSJeremy L Thompson .seealso: `TSSetFunctionContextDestroy()`, `DMTSSetIFunction()`, `TSSetIFunction()` 420*800f99ffSJeremy L Thompson @*/ 421*800f99ffSJeremy L Thompson PetscErrorCode DMTSSetIFunctionContextDestroy(DM dm,PetscErrorCode (*f)(void*)) 422*800f99ffSJeremy L Thompson { 423*800f99ffSJeremy L Thompson DMTS tsdm; 424*800f99ffSJeremy L Thompson 425*800f99ffSJeremy L Thompson PetscFunctionBegin; 426*800f99ffSJeremy L Thompson PetscValidHeaderSpecific(dm,DM_CLASSID,1); 427*800f99ffSJeremy L Thompson PetscCall(DMGetDMTSWrite(dm,&tsdm)); 428*800f99ffSJeremy L Thompson if (tsdm->ifunctionctxcontainer)PetscCall(PetscContainerSetUserDestroy(tsdm->ifunctionctxcontainer,f)); 429*800f99ffSJeremy L Thompson PetscFunctionReturn(0); 430*800f99ffSJeremy L Thompson } 431*800f99ffSJeremy L Thompson 432*800f99ffSJeremy L Thompson PetscErrorCode DMTSUnsetIFunctionContext_Internal(DM dm) 433*800f99ffSJeremy L Thompson { 434*800f99ffSJeremy L Thompson DMTS tsdm; 435*800f99ffSJeremy L Thompson 436*800f99ffSJeremy L Thompson PetscFunctionBegin; 437*800f99ffSJeremy L Thompson PetscValidHeaderSpecific(dm,DM_CLASSID,1); 438*800f99ffSJeremy L Thompson PetscCall(DMGetDMTSWrite(dm,&tsdm)); 439*800f99ffSJeremy L Thompson PetscCall(DMTSUnsetIFunctionContext_DMTS(tsdm)); 44024989b8cSPeter Brune PetscFunctionReturn(0); 44124989b8cSPeter Brune } 44224989b8cSPeter Brune 44324989b8cSPeter Brune /*@C 44424989b8cSPeter Brune DMTSGetIFunction - get TS implicit residual evaluation function 44524989b8cSPeter Brune 44624989b8cSPeter Brune Not Collective 44724989b8cSPeter Brune 4484165533cSJose E. Roman Input Parameter: 44924989b8cSPeter Brune . dm - DM to be used with TS 45024989b8cSPeter Brune 4514165533cSJose E. Roman Output Parameters: 45224989b8cSPeter Brune + func - function evaluation function, see TSSetIFunction() for calling sequence 45324989b8cSPeter Brune - ctx - context for residual evaluation 45424989b8cSPeter Brune 45524989b8cSPeter Brune Level: advanced 45624989b8cSPeter Brune 45724989b8cSPeter Brune Note: 45824989b8cSPeter Brune TSGetFunction() is normally used, but it calls this function internally because the user context is actually 45924989b8cSPeter Brune associated with the DM. 46024989b8cSPeter Brune 461db781477SPatrick Sanan .seealso: `DMTSSetContext()`, `DMTSSetFunction()`, `TSSetFunction()` 46224989b8cSPeter Brune @*/ 46324989b8cSPeter Brune PetscErrorCode DMTSGetIFunction(DM dm,TSIFunction *func,void **ctx) 46424989b8cSPeter Brune { 465942e3340SBarry Smith DMTS tsdm; 46624989b8cSPeter Brune 46724989b8cSPeter Brune PetscFunctionBegin; 46824989b8cSPeter Brune PetscValidHeaderSpecific(dm,DM_CLASSID,1); 4699566063dSJacob Faibussowitsch PetscCall(DMGetDMTS(dm,&tsdm)); 470d74926cbSBarry Smith if (func) *func = tsdm->ops->ifunction; 471*800f99ffSJeremy L Thompson if (ctx) { 472*800f99ffSJeremy L Thompson if (tsdm->ifunctionctxcontainer) PetscCall(PetscContainerGetPointer(tsdm->ifunctionctxcontainer,ctx)); 473*800f99ffSJeremy L Thompson else *ctx = NULL; 474*800f99ffSJeremy L Thompson } 47524989b8cSPeter Brune PetscFunctionReturn(0); 47624989b8cSPeter Brune } 47724989b8cSPeter Brune 478efe9872eSLisandro Dalcin /*@C 479efe9872eSLisandro Dalcin DMTSSetI2Function - set TS implicit function evaluation function for 2nd order systems 480efe9872eSLisandro Dalcin 481efe9872eSLisandro Dalcin Not Collective 482efe9872eSLisandro Dalcin 4834165533cSJose E. Roman Input Parameters: 484efe9872eSLisandro Dalcin + dm - DM to be used with TS 485a96d6ef6SBarry Smith . fun - function evaluation routine 486efe9872eSLisandro Dalcin - ctx - context for residual evaluation 487efe9872eSLisandro Dalcin 488a96d6ef6SBarry Smith Calling sequence of fun: 489a96d6ef6SBarry Smith $ PetscErrorCode fun(TS ts,PetscReal t,Vec U,Vec U_t,Vec U_tt,Vec F,ctx); 490a96d6ef6SBarry Smith 491a96d6ef6SBarry Smith + t - time at step/stage being solved 492a96d6ef6SBarry Smith . U - state vector 493a96d6ef6SBarry Smith . U_t - time derivative of state vector 494a96d6ef6SBarry Smith . U_tt - second time derivative of state vector 495a96d6ef6SBarry Smith . F - function vector 496a96d6ef6SBarry Smith - ctx - [optional] user-defined context for matrix evaluation routine (may be NULL) 497a96d6ef6SBarry Smith 498efe9872eSLisandro Dalcin Level: advanced 499efe9872eSLisandro Dalcin 500efe9872eSLisandro Dalcin Note: 501efe9872eSLisandro Dalcin TSSetI2Function() is normally used, but it calls this function internally because the user context is actually 502efe9872eSLisandro Dalcin associated with the DM. 503efe9872eSLisandro Dalcin 504db781477SPatrick Sanan .seealso: `TSSetI2Function()` 505efe9872eSLisandro Dalcin @*/ 506efe9872eSLisandro Dalcin PetscErrorCode DMTSSetI2Function(DM dm,TSI2Function fun,void *ctx) 507efe9872eSLisandro Dalcin { 508efe9872eSLisandro Dalcin DMTS tsdm; 509efe9872eSLisandro Dalcin 510efe9872eSLisandro Dalcin PetscFunctionBegin; 511efe9872eSLisandro Dalcin PetscValidHeaderSpecific(dm,DM_CLASSID,1); 5129566063dSJacob Faibussowitsch PetscCall(DMGetDMTSWrite(dm,&tsdm)); 513efe9872eSLisandro Dalcin if (fun) tsdm->ops->i2function = fun; 514*800f99ffSJeremy L Thompson if (ctx) { 515*800f99ffSJeremy L Thompson PetscContainer ctxcontainer; 516*800f99ffSJeremy L Thompson PetscCall(PetscContainerCreate(PetscObjectComm((PetscObject)tsdm),&ctxcontainer)); 517*800f99ffSJeremy L Thompson PetscCall(PetscContainerSetPointer(ctxcontainer,ctx)); 518*800f99ffSJeremy L Thompson PetscCall(PetscObjectCompose((PetscObject)tsdm,"i2function ctx",(PetscObject)ctxcontainer)); 519*800f99ffSJeremy L Thompson tsdm->i2functionctxcontainer = ctxcontainer; 520*800f99ffSJeremy L Thompson PetscCall(PetscContainerDestroy(&ctxcontainer)); 521*800f99ffSJeremy L Thompson } 522*800f99ffSJeremy L Thompson PetscFunctionReturn(0); 523*800f99ffSJeremy L Thompson } 524*800f99ffSJeremy L Thompson 525*800f99ffSJeremy L Thompson /*@C 526*800f99ffSJeremy L Thompson DMTSSetI2FunctionContextDestroy - set TS implicit evaluation for 2nd order systems context destroy 527*800f99ffSJeremy L Thompson 528*800f99ffSJeremy L Thompson Not Collective 529*800f99ffSJeremy L Thompson 530*800f99ffSJeremy L Thompson Input Parameters: 531*800f99ffSJeremy L Thompson + dm - DM to be used with TS 532*800f99ffSJeremy L Thompson . f - implicit evaluation context destroy function 533*800f99ffSJeremy L Thompson 534*800f99ffSJeremy L Thompson Level: advanced 535*800f99ffSJeremy L Thompson 536*800f99ffSJeremy L Thompson Note: 537*800f99ffSJeremy L Thompson TSSetI2FunctionContextDestroy() is normally used, but it calls this function internally because the user context is actually 538*800f99ffSJeremy L Thompson associated with the DM. 539*800f99ffSJeremy L Thompson 540*800f99ffSJeremy L Thompson .seealso: `TSSetI2FunctionContextDestroy()`, `DMTSSetI2Function()`, `TSSetI2Function()` 541*800f99ffSJeremy L Thompson @*/ 542*800f99ffSJeremy L Thompson PetscErrorCode DMTSSetI2FunctionContextDestroy(DM dm,PetscErrorCode (*f)(void*)) 543*800f99ffSJeremy L Thompson { 544*800f99ffSJeremy L Thompson DMTS tsdm; 545*800f99ffSJeremy L Thompson 546*800f99ffSJeremy L Thompson PetscFunctionBegin; 547*800f99ffSJeremy L Thompson PetscValidHeaderSpecific(dm,DM_CLASSID,1); 548*800f99ffSJeremy L Thompson PetscCall(DMGetDMTSWrite(dm,&tsdm)); 549*800f99ffSJeremy L Thompson if (tsdm->i2functionctxcontainer) PetscCall(PetscContainerSetUserDestroy(tsdm->i2functionctxcontainer,f)); 550*800f99ffSJeremy L Thompson PetscFunctionReturn(0); 551*800f99ffSJeremy L Thompson } 552*800f99ffSJeremy L Thompson 553*800f99ffSJeremy L Thompson PetscErrorCode DMTSUnsetI2FunctionContext_Internal(DM dm) 554*800f99ffSJeremy L Thompson { 555*800f99ffSJeremy L Thompson DMTS tsdm; 556*800f99ffSJeremy L Thompson 557*800f99ffSJeremy L Thompson PetscFunctionBegin; 558*800f99ffSJeremy L Thompson PetscValidHeaderSpecific(dm,DM_CLASSID,1); 559*800f99ffSJeremy L Thompson PetscCall(DMGetDMTSWrite(dm,&tsdm)); 560*800f99ffSJeremy L Thompson PetscCall(DMTSUnsetI2FunctionContext_DMTS(tsdm)); 561efe9872eSLisandro Dalcin PetscFunctionReturn(0); 562efe9872eSLisandro Dalcin } 563efe9872eSLisandro Dalcin 564efe9872eSLisandro Dalcin /*@C 565efe9872eSLisandro Dalcin DMTSGetI2Function - get TS implicit residual evaluation function for 2nd order systems 566efe9872eSLisandro Dalcin 567efe9872eSLisandro Dalcin Not Collective 568efe9872eSLisandro Dalcin 5694165533cSJose E. Roman Input Parameter: 570efe9872eSLisandro Dalcin . dm - DM to be used with TS 571efe9872eSLisandro Dalcin 5724165533cSJose E. Roman Output Parameters: 573efe9872eSLisandro Dalcin + fun - function evaluation function, see TSSetI2Function() for calling sequence 574efe9872eSLisandro Dalcin - ctx - context for residual evaluation 575efe9872eSLisandro Dalcin 576efe9872eSLisandro Dalcin Level: advanced 577efe9872eSLisandro Dalcin 578efe9872eSLisandro Dalcin Note: 579efe9872eSLisandro Dalcin TSGetI2Function() is normally used, but it calls this function internally because the user context is actually 580efe9872eSLisandro Dalcin associated with the DM. 581efe9872eSLisandro Dalcin 582c2e3fba1SPatrick Sanan .seealso: `DMTSSetI2Function()`, `TSGetI2Function()` 583efe9872eSLisandro Dalcin @*/ 584efe9872eSLisandro Dalcin PetscErrorCode DMTSGetI2Function(DM dm,TSI2Function *fun,void **ctx) 585efe9872eSLisandro Dalcin { 586efe9872eSLisandro Dalcin DMTS tsdm; 587efe9872eSLisandro Dalcin 588efe9872eSLisandro Dalcin PetscFunctionBegin; 589efe9872eSLisandro Dalcin PetscValidHeaderSpecific(dm,DM_CLASSID,1); 5909566063dSJacob Faibussowitsch PetscCall(DMGetDMTS(dm,&tsdm)); 591efe9872eSLisandro Dalcin if (fun) *fun = tsdm->ops->i2function; 592*800f99ffSJeremy L Thompson if (ctx) { 593*800f99ffSJeremy L Thompson if (tsdm->i2functionctxcontainer) PetscCall(PetscContainerGetPointer(tsdm->i2functionctxcontainer,ctx)); 594*800f99ffSJeremy L Thompson else *ctx = NULL; 595*800f99ffSJeremy L Thompson } 596efe9872eSLisandro Dalcin PetscFunctionReturn(0); 597efe9872eSLisandro Dalcin } 598efe9872eSLisandro Dalcin 599efe9872eSLisandro Dalcin /*@C 600efe9872eSLisandro Dalcin DMTSSetI2Jacobian - set TS implicit Jacobian evaluation function for 2nd order systems 601efe9872eSLisandro Dalcin 602efe9872eSLisandro Dalcin Not Collective 603efe9872eSLisandro Dalcin 6044165533cSJose E. Roman Input Parameters: 605efe9872eSLisandro Dalcin + dm - DM to be used with TS 606a96d6ef6SBarry Smith . fun - Jacobian evaluation routine 607efe9872eSLisandro Dalcin - ctx - context for Jacobian evaluation 608efe9872eSLisandro Dalcin 609a96d6ef6SBarry Smith Calling sequence of jac: 610a96d6ef6SBarry Smith $ PetscErrorCode jac(TS ts,PetscReal t,Vec U,Vec U_t,Vec U_tt,PetscReal v,PetscReal a,Mat J,Mat P,void *ctx); 611a96d6ef6SBarry Smith 612a96d6ef6SBarry Smith + t - time at step/stage being solved 613a96d6ef6SBarry Smith . U - state vector 614a96d6ef6SBarry Smith . U_t - time derivative of state vector 615a96d6ef6SBarry Smith . U_tt - second time derivative of state vector 616a96d6ef6SBarry Smith . v - shift for U_t 617a96d6ef6SBarry Smith . a - shift for U_tt 618a96d6ef6SBarry Smith . J - Jacobian of G(U) = F(t,U,W+v*U,W'+a*U), equivalent to dF/dU + v*dF/dU_t + a*dF/dU_tt 619a96d6ef6SBarry Smith . P - preconditioning matrix for J, may be same as J 620a96d6ef6SBarry Smith - ctx - [optional] user-defined context for matrix evaluation routine 621a96d6ef6SBarry Smith 622efe9872eSLisandro Dalcin Level: advanced 623efe9872eSLisandro Dalcin 624efe9872eSLisandro Dalcin Note: 625efe9872eSLisandro Dalcin TSSetI2Jacobian() is normally used, but it calls this function internally because the user context is actually 626efe9872eSLisandro Dalcin associated with the DM. 627efe9872eSLisandro Dalcin 628db781477SPatrick Sanan .seealso: `TSSetI2Jacobian()` 629efe9872eSLisandro Dalcin @*/ 630efe9872eSLisandro Dalcin PetscErrorCode DMTSSetI2Jacobian(DM dm,TSI2Jacobian jac,void *ctx) 631efe9872eSLisandro Dalcin { 632efe9872eSLisandro Dalcin DMTS tsdm; 633efe9872eSLisandro Dalcin 634efe9872eSLisandro Dalcin PetscFunctionBegin; 635efe9872eSLisandro Dalcin PetscValidHeaderSpecific(dm,DM_CLASSID,1); 6369566063dSJacob Faibussowitsch PetscCall(DMGetDMTSWrite(dm,&tsdm)); 637efe9872eSLisandro Dalcin if (jac) tsdm->ops->i2jacobian = jac; 638*800f99ffSJeremy L Thompson if (ctx) { 639*800f99ffSJeremy L Thompson PetscContainer ctxcontainer; 640*800f99ffSJeremy L Thompson PetscCall(PetscContainerCreate(PetscObjectComm((PetscObject)tsdm),&ctxcontainer)); 641*800f99ffSJeremy L Thompson PetscCall(PetscContainerSetPointer(ctxcontainer,ctx)); 642*800f99ffSJeremy L Thompson PetscCall(PetscObjectCompose((PetscObject)tsdm,"i2jacobian ctx",(PetscObject)ctxcontainer)); 643*800f99ffSJeremy L Thompson tsdm->i2jacobianctxcontainer = ctxcontainer; 644*800f99ffSJeremy L Thompson PetscCall(PetscContainerDestroy(&ctxcontainer)); 645*800f99ffSJeremy L Thompson } 646*800f99ffSJeremy L Thompson PetscFunctionReturn(0); 647*800f99ffSJeremy L Thompson } 648*800f99ffSJeremy L Thompson 649*800f99ffSJeremy L Thompson /*@C 650*800f99ffSJeremy L Thompson DMTSSetI2JacobianContextDestroy - set TS implicit Jacobian evaluation for 2nd order systems context destroy function 651*800f99ffSJeremy L Thompson 652*800f99ffSJeremy L Thompson Not Collective 653*800f99ffSJeremy L Thompson 654*800f99ffSJeremy L Thompson Input Parameters: 655*800f99ffSJeremy L Thompson + dm - DM to be used with TS 656*800f99ffSJeremy L Thompson . f - implicit Jacobian evaluation context destroy function 657*800f99ffSJeremy L Thompson 658*800f99ffSJeremy L Thompson .seealso: `TSSetI2JacobianContextDestroy()`, `DMTSSetI2Jacobian()`, `TSSetI2Jacobian()` 659*800f99ffSJeremy L Thompson @*/ 660*800f99ffSJeremy L Thompson PetscErrorCode DMTSSetI2JacobianContextDestroy(DM dm,PetscErrorCode (*f)(void*)) 661*800f99ffSJeremy L Thompson { 662*800f99ffSJeremy L Thompson DMTS tsdm; 663*800f99ffSJeremy L Thompson 664*800f99ffSJeremy L Thompson PetscFunctionBegin; 665*800f99ffSJeremy L Thompson PetscValidHeaderSpecific(dm,DM_CLASSID,1); 666*800f99ffSJeremy L Thompson PetscCall(DMGetDMTSWrite(dm,&tsdm)); 667*800f99ffSJeremy L Thompson if (tsdm->i2jacobianctxcontainer) PetscCall(PetscContainerSetUserDestroy(tsdm->i2jacobianctxcontainer,f)); 668*800f99ffSJeremy L Thompson PetscFunctionReturn(0); 669*800f99ffSJeremy L Thompson } 670*800f99ffSJeremy L Thompson 671*800f99ffSJeremy L Thompson PetscErrorCode DMTSUnsetI2JacobianContext_Internal(DM dm) 672*800f99ffSJeremy L Thompson { 673*800f99ffSJeremy L Thompson DMTS tsdm; 674*800f99ffSJeremy L Thompson 675*800f99ffSJeremy L Thompson PetscFunctionBegin; 676*800f99ffSJeremy L Thompson PetscValidHeaderSpecific(dm,DM_CLASSID,1); 677*800f99ffSJeremy L Thompson PetscCall(DMGetDMTSWrite(dm,&tsdm)); 678*800f99ffSJeremy L Thompson PetscCall(DMTSUnsetI2JacobianContext_DMTS(tsdm)); 679efe9872eSLisandro Dalcin PetscFunctionReturn(0); 680efe9872eSLisandro Dalcin } 681efe9872eSLisandro Dalcin 682efe9872eSLisandro Dalcin /*@C 683efe9872eSLisandro Dalcin DMTSGetI2Jacobian - get TS implicit Jacobian evaluation function for 2nd order systems 684efe9872eSLisandro Dalcin 685efe9872eSLisandro Dalcin Not Collective 686efe9872eSLisandro Dalcin 6874165533cSJose E. Roman Input Parameter: 688efe9872eSLisandro Dalcin . dm - DM to be used with TS 689efe9872eSLisandro Dalcin 6904165533cSJose E. Roman Output Parameters: 691efe9872eSLisandro Dalcin + jac - Jacobian evaluation function, see TSSetI2Jacobian() for calling sequence 692efe9872eSLisandro Dalcin - ctx - context for Jacobian evaluation 693efe9872eSLisandro Dalcin 694efe9872eSLisandro Dalcin Level: advanced 695efe9872eSLisandro Dalcin 696efe9872eSLisandro Dalcin Note: 697efe9872eSLisandro Dalcin TSGetI2Jacobian() is normally used, but it calls this function internally because the user context is actually 698efe9872eSLisandro Dalcin associated with the DM. 699efe9872eSLisandro Dalcin 700c2e3fba1SPatrick Sanan .seealso: `DMTSSetI2Jacobian()`, `TSGetI2Jacobian()` 701efe9872eSLisandro Dalcin @*/ 702efe9872eSLisandro Dalcin PetscErrorCode DMTSGetI2Jacobian(DM dm,TSI2Jacobian *jac,void **ctx) 703efe9872eSLisandro Dalcin { 704efe9872eSLisandro Dalcin DMTS tsdm; 705efe9872eSLisandro Dalcin 706efe9872eSLisandro Dalcin PetscFunctionBegin; 707efe9872eSLisandro Dalcin PetscValidHeaderSpecific(dm,DM_CLASSID,1); 7089566063dSJacob Faibussowitsch PetscCall(DMGetDMTS(dm,&tsdm)); 709efe9872eSLisandro Dalcin if (jac) *jac = tsdm->ops->i2jacobian; 710*800f99ffSJeremy L Thompson if (ctx) { 711*800f99ffSJeremy L Thompson if (tsdm->i2jacobianctxcontainer) PetscCall(PetscContainerGetPointer(tsdm->i2jacobianctxcontainer,ctx)); 712*800f99ffSJeremy L Thompson else *ctx = NULL; 713*800f99ffSJeremy L Thompson } 714efe9872eSLisandro Dalcin PetscFunctionReturn(0); 715efe9872eSLisandro Dalcin } 71624989b8cSPeter Brune 71724989b8cSPeter Brune /*@C 71824989b8cSPeter Brune DMTSSetRHSFunction - set TS explicit residual evaluation function 71924989b8cSPeter Brune 72024989b8cSPeter Brune Not Collective 72124989b8cSPeter Brune 7224165533cSJose E. Roman Input Parameters: 72324989b8cSPeter Brune + dm - DM to be used with TS 724a96d6ef6SBarry Smith . func - RHS function evaluation routine 72524989b8cSPeter Brune - ctx - context for residual evaluation 72624989b8cSPeter Brune 727a96d6ef6SBarry Smith Calling sequence of func: 728a96d6ef6SBarry Smith $ PetscErrorCode func(TS ts,PetscReal t,Vec u,Vec F,void *ctx); 729a96d6ef6SBarry Smith 730a96d6ef6SBarry Smith + ts - timestep context 731a96d6ef6SBarry Smith . t - current timestep 732a96d6ef6SBarry Smith . u - input vector 733a96d6ef6SBarry Smith . F - function vector 734a96d6ef6SBarry Smith - ctx - [optional] user-defined function context 735a96d6ef6SBarry Smith 73624989b8cSPeter Brune Level: advanced 73724989b8cSPeter Brune 73824989b8cSPeter Brune Note: 739*800f99ffSJeremy L Thompson TSSetRHSFunction() is normally used, but it calls this function internally because the user context is actually 74024989b8cSPeter Brune associated with the DM. This makes the interface consistent regardless of whether the user interacts with a DM or 74124989b8cSPeter Brune not. If DM took a more central role at some later date, this could become the primary method of setting the residual. 74224989b8cSPeter Brune 743db781477SPatrick Sanan .seealso: `DMTSSetContext()`, `TSSetRHSFunction()`, `DMTSSetJacobian()` 74424989b8cSPeter Brune @*/ 74524989b8cSPeter Brune PetscErrorCode DMTSSetRHSFunction(DM dm,TSRHSFunction func,void *ctx) 74624989b8cSPeter Brune { 747942e3340SBarry Smith DMTS tsdm; 74824989b8cSPeter Brune 74924989b8cSPeter Brune PetscFunctionBegin; 75024989b8cSPeter Brune PetscValidHeaderSpecific(dm,DM_CLASSID,1); 7519566063dSJacob Faibussowitsch PetscCall(DMGetDMTSWrite(dm,&tsdm)); 752d74926cbSBarry Smith if (func) tsdm->ops->rhsfunction = func; 753*800f99ffSJeremy L Thompson if (ctx) { 754*800f99ffSJeremy L Thompson PetscContainer ctxcontainer; 755*800f99ffSJeremy L Thompson PetscCall(PetscContainerCreate(PetscObjectComm((PetscObject)tsdm),&ctxcontainer)); 756*800f99ffSJeremy L Thompson PetscCall(PetscContainerSetPointer(ctxcontainer,ctx)); 757*800f99ffSJeremy L Thompson PetscCall(PetscObjectCompose((PetscObject)tsdm,"rhs function ctx",(PetscObject)ctxcontainer)); 758*800f99ffSJeremy L Thompson tsdm->rhsfunctionctxcontainer = ctxcontainer; 759*800f99ffSJeremy L Thompson PetscCall(PetscContainerDestroy(&ctxcontainer)); 760*800f99ffSJeremy L Thompson } 761*800f99ffSJeremy L Thompson PetscFunctionReturn(0); 762*800f99ffSJeremy L Thompson } 763*800f99ffSJeremy L Thompson 764*800f99ffSJeremy L Thompson /*@C 765*800f99ffSJeremy L Thompson DMTSSetRHSFunctionContextDestroy - set TS explicit residual evaluation context destroy function 766*800f99ffSJeremy L Thompson 767*800f99ffSJeremy L Thompson Not Collective 768*800f99ffSJeremy L Thompson 769*800f99ffSJeremy L Thompson Input Parameters: 770*800f99ffSJeremy L Thompson + dm - DM to be used with TS 771*800f99ffSJeremy L Thompson . f - explicit evaluation context destroy function 772*800f99ffSJeremy L Thompson 773*800f99ffSJeremy L Thompson Level: advanced 774*800f99ffSJeremy L Thompson 775*800f99ffSJeremy L Thompson Note: 776*800f99ffSJeremy L Thompson TSSetRHSFunctionContextDestroy() is normally used, but it calls this function internally because the user context is actually 777*800f99ffSJeremy L Thompson associated with the DM. This makes the interface consistent regardless of whether the user interacts with a DM or 778*800f99ffSJeremy L Thompson not. If DM took a more central role at some later date, this could become the primary method of setting the residual. 779*800f99ffSJeremy L Thompson 780*800f99ffSJeremy L Thompson .seealso: `TSSetRHSFunctionContextDestroy()`, `DMTSSetRHSFunction()`, `TSSetRHSFunction()` 781*800f99ffSJeremy L Thompson @*/ 782*800f99ffSJeremy L Thompson PetscErrorCode DMTSSetRHSFunctionContextDestroy(DM dm,PetscErrorCode (*f)(void*)) 783*800f99ffSJeremy L Thompson { 784*800f99ffSJeremy L Thompson DMTS tsdm; 785*800f99ffSJeremy L Thompson 786*800f99ffSJeremy L Thompson PetscFunctionBegin; 787*800f99ffSJeremy L Thompson PetscValidHeaderSpecific(dm,DM_CLASSID,1); 788*800f99ffSJeremy L Thompson PetscCall(DMGetDMTSWrite(dm,&tsdm)); 789*800f99ffSJeremy L Thompson if (tsdm->rhsfunctionctxcontainer) PetscCall(PetscContainerSetUserDestroy(tsdm->rhsfunctionctxcontainer,f)); 790*800f99ffSJeremy L Thompson PetscFunctionReturn(0); 791*800f99ffSJeremy L Thompson } 792*800f99ffSJeremy L Thompson 793*800f99ffSJeremy L Thompson PetscErrorCode DMTSUnsetRHSFunctionContext_Internal(DM dm) 794*800f99ffSJeremy L Thompson { 795*800f99ffSJeremy L Thompson DMTS tsdm; 796*800f99ffSJeremy L Thompson 797*800f99ffSJeremy L Thompson PetscFunctionBegin; 798*800f99ffSJeremy L Thompson PetscValidHeaderSpecific(dm,DM_CLASSID,1); 799*800f99ffSJeremy L Thompson PetscCall(DMGetDMTSWrite(dm,&tsdm)); 800*800f99ffSJeremy L Thompson PetscCall(DMTSUnsetRHSFunctionContext_DMTS(tsdm)); 801*800f99ffSJeremy L Thompson tsdm->rhsfunctionctxcontainer = NULL; 80224989b8cSPeter Brune PetscFunctionReturn(0); 80324989b8cSPeter Brune } 80424989b8cSPeter Brune 805ef20d060SBarry Smith /*@C 806e3c11fc1SJed Brown DMTSSetTransientVariable - sets function to transform from state to transient variables 807e3c11fc1SJed Brown 808e3c11fc1SJed Brown Logically Collective 809e3c11fc1SJed Brown 8104165533cSJose E. Roman Input Parameters: 811e3c11fc1SJed Brown + dm - DM to be used with TS 812a96d6ef6SBarry Smith . tvar - a function that transforms to transient variables 813e3c11fc1SJed Brown - ctx - a context for tvar 814e3c11fc1SJed Brown 815a96d6ef6SBarry Smith Calling sequence of tvar: 816a96d6ef6SBarry Smith $ PetscErrorCode tvar(TS ts,Vec p,Vec c,void *ctx); 817a96d6ef6SBarry Smith 818a96d6ef6SBarry Smith + ts - timestep context 8196aad120cSJose E. Roman . p - input vector (primitive form) 820a96d6ef6SBarry Smith . c - output vector, transient variables (conservative form) 821a96d6ef6SBarry Smith - ctx - [optional] user-defined function context 822a96d6ef6SBarry Smith 823e3c11fc1SJed Brown Level: advanced 824e3c11fc1SJed Brown 825e3c11fc1SJed Brown Notes: 826e3c11fc1SJed Brown This is typically used to transform from primitive to conservative variables so that a time integrator (e.g., TSBDF) 827e3c11fc1SJed Brown can be conservative. In this context, primitive variables P are used to model the state (e.g., because they lead to 828e3c11fc1SJed Brown well-conditioned formulations even in limiting cases such as low-Mach or zero porosity). The transient variable is 829e3c11fc1SJed Brown C(P), specified by calling this function. An IFunction thus receives arguments (P, Cdot) and the IJacobian must be 830e3c11fc1SJed Brown evaluated via the chain rule, as in 831e3c11fc1SJed Brown 832e3c11fc1SJed Brown dF/dP + shift * dF/dCdot dC/dP. 833e3c11fc1SJed Brown 834db781477SPatrick Sanan .seealso: `TSSetTransientVariable()`, `DMTSGetTransientVariable()`, `DMTSSetIFunction()`, `DMTSSetIJacobian()` 835e3c11fc1SJed Brown @*/ 836e3c11fc1SJed Brown PetscErrorCode DMTSSetTransientVariable(DM dm,TSTransientVariable tvar,void *ctx) 837e3c11fc1SJed Brown { 838e3c11fc1SJed Brown DMTS dmts; 839e3c11fc1SJed Brown 840e3c11fc1SJed Brown PetscFunctionBegin; 841e3c11fc1SJed Brown PetscValidHeaderSpecific(dm,DM_CLASSID,1); 8429566063dSJacob Faibussowitsch PetscCall(DMGetDMTSWrite(dm,&dmts)); 843e3c11fc1SJed Brown dmts->ops->transientvar = tvar; 844e3c11fc1SJed Brown dmts->transientvarctx = ctx; 845e3c11fc1SJed Brown PetscFunctionReturn(0); 846e3c11fc1SJed Brown } 847e3c11fc1SJed Brown 848e3c11fc1SJed Brown /*@C 849e3c11fc1SJed Brown DMTSGetTransientVariable - gets function to transform from state to transient variables 850e3c11fc1SJed Brown 851e3c11fc1SJed Brown Logically Collective 852e3c11fc1SJed Brown 8534165533cSJose E. Roman Input Parameter: 854e3c11fc1SJed Brown . dm - DM to be used with TS 855e3c11fc1SJed Brown 8564165533cSJose E. Roman Output Parameters: 857a96d6ef6SBarry Smith + tvar - a function that transforms to transient variables 858e3c11fc1SJed Brown - ctx - a context for tvar 859e3c11fc1SJed Brown 860e3c11fc1SJed Brown Level: advanced 861e3c11fc1SJed Brown 862db781477SPatrick Sanan .seealso: `DMTSSetTransientVariable()`, `DMTSGetIFunction()`, `DMTSGetIJacobian()` 863e3c11fc1SJed Brown @*/ 864e3c11fc1SJed Brown PetscErrorCode DMTSGetTransientVariable(DM dm,TSTransientVariable *tvar,void *ctx) 865e3c11fc1SJed Brown { 866e3c11fc1SJed Brown DMTS dmts; 867e3c11fc1SJed Brown 868e3c11fc1SJed Brown PetscFunctionBegin; 869e3c11fc1SJed Brown PetscValidHeaderSpecific(dm,DM_CLASSID,1); 8709566063dSJacob Faibussowitsch PetscCall(DMGetDMTS(dm,&dmts)); 871e3c11fc1SJed Brown if (tvar) *tvar = dmts->ops->transientvar; 872e3c11fc1SJed Brown if (ctx) *(void**)ctx = dmts->transientvarctx; 873e3c11fc1SJed Brown PetscFunctionReturn(0); 874e3c11fc1SJed Brown } 875e3c11fc1SJed Brown 876e3c11fc1SJed Brown /*@C 877ef20d060SBarry Smith DMTSGetSolutionFunction - gets the TS solution evaluation function 878ef20d060SBarry Smith 879ef20d060SBarry Smith Not Collective 880ef20d060SBarry Smith 8814165533cSJose E. Roman Input Parameter: 882ef20d060SBarry Smith . dm - DM to be used with TS 883ef20d060SBarry Smith 884ef20d060SBarry Smith Output Parameters: 885ef20d060SBarry Smith + func - solution function evaluation function, see TSSetSolution() for calling sequence 886ef20d060SBarry Smith - ctx - context for solution evaluation 887ef20d060SBarry Smith 888ef20d060SBarry Smith Level: advanced 889ef20d060SBarry Smith 890db781477SPatrick Sanan .seealso: `DMTSSetContext()`, `TSSetFunction()`, `DMTSSetJacobian()`, `DMTSSetSolutionFunction()` 891ef20d060SBarry Smith @*/ 892ef20d060SBarry Smith PetscErrorCode DMTSGetSolutionFunction(DM dm,TSSolutionFunction *func,void **ctx) 893ef20d060SBarry Smith { 894942e3340SBarry Smith DMTS tsdm; 895ef20d060SBarry Smith 896ef20d060SBarry Smith PetscFunctionBegin; 897ef20d060SBarry Smith PetscValidHeaderSpecific(dm,DM_CLASSID,1); 8989566063dSJacob Faibussowitsch PetscCall(DMGetDMTS(dm,&tsdm)); 899d74926cbSBarry Smith if (func) *func = tsdm->ops->solution; 900ef20d060SBarry Smith if (ctx) *ctx = tsdm->solutionctx; 901ef20d060SBarry Smith PetscFunctionReturn(0); 902ef20d060SBarry Smith } 903ef20d060SBarry Smith 904ef20d060SBarry Smith /*@C 905ef20d060SBarry Smith DMTSSetSolutionFunction - set TS solution evaluation function 906ef20d060SBarry Smith 907ef20d060SBarry Smith Not Collective 908ef20d060SBarry Smith 9094165533cSJose E. Roman Input Parameters: 910ef20d060SBarry Smith + dm - DM to be used with TS 911a96d6ef6SBarry Smith . func - solution function evaluation routine 912ef20d060SBarry Smith - ctx - context for solution evaluation 913ef20d060SBarry Smith 914a96d6ef6SBarry Smith Calling sequence of f: 915a96d6ef6SBarry Smith $ PetscErrorCode f(TS ts,PetscReal t,Vec u,void *ctx); 916a96d6ef6SBarry Smith 917a96d6ef6SBarry Smith + ts - timestep context 918a96d6ef6SBarry Smith . t - current timestep 919a96d6ef6SBarry Smith . u - output vector 920a96d6ef6SBarry Smith - ctx - [optional] user-defined function context 921a96d6ef6SBarry Smith 922ef20d060SBarry Smith Level: advanced 923ef20d060SBarry Smith 924ef20d060SBarry Smith Note: 925ef20d060SBarry Smith TSSetSolutionFunction() is normally used, but it calls this function internally because the user context is actually 926ef20d060SBarry Smith associated with the DM. This makes the interface consistent regardless of whether the user interacts with a DM or 927ef20d060SBarry Smith not. If DM took a more central role at some later date, this could become the primary method of setting the residual. 928ef20d060SBarry Smith 929db781477SPatrick Sanan .seealso: `DMTSSetContext()`, `TSSetFunction()`, `DMTSSetJacobian()`, `DMTSGetSolutionFunction()` 930ef20d060SBarry Smith @*/ 931ef20d060SBarry Smith PetscErrorCode DMTSSetSolutionFunction(DM dm,TSSolutionFunction func,void *ctx) 932ef20d060SBarry Smith { 933942e3340SBarry Smith DMTS tsdm; 934ef20d060SBarry Smith 935ef20d060SBarry Smith PetscFunctionBegin; 936ef20d060SBarry Smith PetscValidHeaderSpecific(dm,DM_CLASSID,1); 9379566063dSJacob Faibussowitsch PetscCall(DMGetDMTSWrite(dm,&tsdm)); 938d74926cbSBarry Smith if (func) tsdm->ops->solution = func; 939ef20d060SBarry Smith if (ctx) tsdm->solutionctx = ctx; 940ef20d060SBarry Smith PetscFunctionReturn(0); 941ef20d060SBarry Smith } 942ef20d060SBarry Smith 9439b7cd975SBarry Smith /*@C 9449b7cd975SBarry Smith DMTSSetForcingFunction - set TS forcing function evaluation function 9459b7cd975SBarry Smith 9469b7cd975SBarry Smith Not Collective 9479b7cd975SBarry Smith 9484165533cSJose E. Roman Input Parameters: 9499b7cd975SBarry Smith + dm - DM to be used with TS 950a96d6ef6SBarry Smith . f - forcing function evaluation routine 9519b7cd975SBarry Smith - ctx - context for solution evaluation 9529b7cd975SBarry Smith 953a96d6ef6SBarry Smith Calling sequence of func: 954a96d6ef6SBarry Smith $ PetscErrorCode func (TS ts,PetscReal t,Vec f,void *ctx); 955a96d6ef6SBarry Smith 956a96d6ef6SBarry Smith + ts - timestep context 957a96d6ef6SBarry Smith . t - current timestep 958a96d6ef6SBarry Smith . f - output vector 959a96d6ef6SBarry Smith - ctx - [optional] user-defined function context 960a96d6ef6SBarry Smith 9619b7cd975SBarry Smith Level: advanced 9629b7cd975SBarry Smith 9639b7cd975SBarry Smith Note: 9649b7cd975SBarry Smith TSSetForcingFunction() is normally used, but it calls this function internally because the user context is actually 9659b7cd975SBarry Smith associated with the DM. This makes the interface consistent regardless of whether the user interacts with a DM or 9669b7cd975SBarry Smith not. If DM took a more central role at some later date, this could become the primary method of setting the residual. 9679b7cd975SBarry Smith 968db781477SPatrick Sanan .seealso: `DMTSSetContext()`, `TSSetFunction()`, `DMTSSetJacobian()`, `TSSetForcingFunction()`, `DMTSGetForcingFunction()` 9699b7cd975SBarry Smith @*/ 970d56366bfSLisandro Dalcin PetscErrorCode DMTSSetForcingFunction(DM dm,TSForcingFunction f,void *ctx) 9719b7cd975SBarry Smith { 9729b7cd975SBarry Smith DMTS tsdm; 9739b7cd975SBarry Smith 9749b7cd975SBarry Smith PetscFunctionBegin; 9759b7cd975SBarry Smith PetscValidHeaderSpecific(dm,DM_CLASSID,1); 9769566063dSJacob Faibussowitsch PetscCall(DMGetDMTSWrite(dm,&tsdm)); 977f8b49ee9SBarry Smith if (f) tsdm->ops->forcing = f; 9789b7cd975SBarry Smith if (ctx) tsdm->forcingctx = ctx; 9799b7cd975SBarry Smith PetscFunctionReturn(0); 9809b7cd975SBarry Smith } 9819b7cd975SBarry Smith 9829b7cd975SBarry Smith /*@C 9839b7cd975SBarry Smith DMTSGetForcingFunction - get TS forcing function evaluation function 9849b7cd975SBarry Smith 9859b7cd975SBarry Smith Not Collective 9869b7cd975SBarry Smith 9874165533cSJose E. Roman Input Parameter: 9889b7cd975SBarry Smith . dm - DM to be used with TS 9899b7cd975SBarry Smith 9904165533cSJose E. Roman Output Parameters: 991f8b49ee9SBarry Smith + f - forcing function evaluation function; see TSForcingFunction for details 9929b7cd975SBarry Smith - ctx - context for solution evaluation 9939b7cd975SBarry Smith 9949b7cd975SBarry Smith Level: advanced 9959b7cd975SBarry Smith 9969b7cd975SBarry Smith Note: 9979b7cd975SBarry Smith TSSetForcingFunction() is normally used, but it calls this function internally because the user context is actually 9989b7cd975SBarry Smith associated with the DM. This makes the interface consistent regardless of whether the user interacts with a DM or 9999b7cd975SBarry Smith not. If DM took a more central role at some later date, this could become the primary method of setting the residual. 10009b7cd975SBarry Smith 1001db781477SPatrick Sanan .seealso: `DMTSSetContext()`, `TSSetFunction()`, `DMTSSetJacobian()`, `TSSetForcingFunction()`, `DMTSGetForcingFunction()` 10029b7cd975SBarry Smith @*/ 1003d56366bfSLisandro Dalcin PetscErrorCode DMTSGetForcingFunction(DM dm,TSForcingFunction *f,void **ctx) 10049b7cd975SBarry Smith { 10059b7cd975SBarry Smith DMTS tsdm; 10069b7cd975SBarry Smith 10079b7cd975SBarry Smith PetscFunctionBegin; 10089b7cd975SBarry Smith PetscValidHeaderSpecific(dm,DM_CLASSID,1); 10099566063dSJacob Faibussowitsch PetscCall(DMGetDMTSWrite(dm,&tsdm)); 1010f8b49ee9SBarry Smith if (f) *f = tsdm->ops->forcing; 10119b7cd975SBarry Smith if (ctx) *ctx = tsdm->forcingctx; 10129b7cd975SBarry Smith PetscFunctionReturn(0); 10139b7cd975SBarry Smith } 10149b7cd975SBarry Smith 101524989b8cSPeter Brune /*@C 101624989b8cSPeter Brune DMTSGetRHSFunction - get TS explicit residual evaluation function 101724989b8cSPeter Brune 101824989b8cSPeter Brune Not Collective 101924989b8cSPeter Brune 10204165533cSJose E. Roman Input Parameter: 102124989b8cSPeter Brune . dm - DM to be used with TS 102224989b8cSPeter Brune 10234165533cSJose E. Roman Output Parameters: 102424989b8cSPeter Brune + func - residual evaluation function, see TSSetRHSFunction() for calling sequence 102524989b8cSPeter Brune - ctx - context for residual evaluation 102624989b8cSPeter Brune 102724989b8cSPeter Brune Level: advanced 102824989b8cSPeter Brune 102924989b8cSPeter Brune Note: 103024989b8cSPeter Brune TSGetFunction() is normally used, but it calls this function internally because the user context is actually 103124989b8cSPeter Brune associated with the DM. 103224989b8cSPeter Brune 1033db781477SPatrick Sanan .seealso: `DMTSSetContext()`, `DMTSSetRHSFunction()`, `TSSetRHSFunction()` 103424989b8cSPeter Brune @*/ 103524989b8cSPeter Brune PetscErrorCode DMTSGetRHSFunction(DM dm,TSRHSFunction *func,void **ctx) 103624989b8cSPeter Brune { 1037942e3340SBarry Smith DMTS tsdm; 103824989b8cSPeter Brune 103924989b8cSPeter Brune PetscFunctionBegin; 104024989b8cSPeter Brune PetscValidHeaderSpecific(dm,DM_CLASSID,1); 10419566063dSJacob Faibussowitsch PetscCall(DMGetDMTS(dm,&tsdm)); 1042d74926cbSBarry Smith if (func) *func = tsdm->ops->rhsfunction; 1043*800f99ffSJeremy L Thompson if (ctx) { 1044*800f99ffSJeremy L Thompson if (tsdm->rhsfunctionctxcontainer) PetscCall(PetscContainerGetPointer(tsdm->rhsfunctionctxcontainer,ctx)); 1045*800f99ffSJeremy L Thompson else *ctx = NULL; 1046*800f99ffSJeremy L Thompson } 104724989b8cSPeter Brune PetscFunctionReturn(0); 104824989b8cSPeter Brune } 104924989b8cSPeter Brune 105024989b8cSPeter Brune /*@C 105124989b8cSPeter Brune DMTSSetIJacobian - set TS Jacobian evaluation function 105224989b8cSPeter Brune 105324989b8cSPeter Brune Not Collective 105424989b8cSPeter Brune 10554165533cSJose E. Roman Input Parameters: 105624989b8cSPeter Brune + dm - DM to be used with TS 1057a96d6ef6SBarry Smith . func - Jacobian evaluation routine 105824989b8cSPeter Brune - ctx - context for residual evaluation 105924989b8cSPeter Brune 1060a96d6ef6SBarry Smith Calling sequence of f: 1061a96d6ef6SBarry Smith $ PetscErrorCode f(TS ts,PetscReal t,Vec U,Vec U_t,PetscReal a,Mat Amat,Mat Pmat,void *ctx); 1062a96d6ef6SBarry Smith 1063a96d6ef6SBarry Smith + t - time at step/stage being solved 1064a96d6ef6SBarry Smith . U - state vector 1065a96d6ef6SBarry Smith . U_t - time derivative of state vector 1066a96d6ef6SBarry Smith . a - shift 1067a96d6ef6SBarry Smith . Amat - (approximate) Jacobian of F(t,U,W+a*U), equivalent to dF/dU + a*dF/dU_t 1068a96d6ef6SBarry Smith . Pmat - matrix used for constructing preconditioner, usually the same as Amat 1069a96d6ef6SBarry Smith - ctx - [optional] user-defined context for matrix evaluation routine 1070a96d6ef6SBarry Smith 107124989b8cSPeter Brune Level: advanced 107224989b8cSPeter Brune 107324989b8cSPeter Brune Note: 107424989b8cSPeter Brune TSSetJacobian() is normally used, but it calls this function internally because the user context is actually 107524989b8cSPeter Brune associated with the DM. This makes the interface consistent regardless of whether the user interacts with a DM or 107624989b8cSPeter Brune not. If DM took a more central role at some later date, this could become the primary method of setting the Jacobian. 107724989b8cSPeter Brune 1078db781477SPatrick Sanan .seealso: `DMTSSetContext()`, `TSSetRHSFunction()`, `DMTSGetJacobian()`, `TSSetIJacobian()`, `TSSetIFunction()` 107924989b8cSPeter Brune @*/ 108024989b8cSPeter Brune PetscErrorCode DMTSSetIJacobian(DM dm,TSIJacobian func,void *ctx) 108124989b8cSPeter Brune { 1082*800f99ffSJeremy L Thompson DMTS tsdm; 108324989b8cSPeter Brune 108424989b8cSPeter Brune PetscFunctionBegin; 108524989b8cSPeter Brune PetscValidHeaderSpecific(dm,DM_CLASSID,1); 1086*800f99ffSJeremy L Thompson PetscCall(DMGetDMTSWrite(dm,&tsdm)); 1087*800f99ffSJeremy L Thompson if (func) tsdm->ops->ijacobian = func; 1088*800f99ffSJeremy L Thompson if (ctx) { 1089*800f99ffSJeremy L Thompson PetscContainer ctxcontainer; 1090*800f99ffSJeremy L Thompson PetscCall(PetscContainerCreate(PetscObjectComm((PetscObject)tsdm),&ctxcontainer)); 1091*800f99ffSJeremy L Thompson PetscCall(PetscContainerSetPointer(ctxcontainer,ctx)); 1092*800f99ffSJeremy L Thompson PetscCall(PetscObjectCompose((PetscObject)tsdm,"ijacobian ctx",(PetscObject)ctxcontainer)); 1093*800f99ffSJeremy L Thompson tsdm->ijacobianctxcontainer = ctxcontainer; 1094*800f99ffSJeremy L Thompson PetscCall(PetscContainerDestroy(&ctxcontainer)); 1095*800f99ffSJeremy L Thompson } 1096*800f99ffSJeremy L Thompson PetscFunctionReturn(0); 1097*800f99ffSJeremy L Thompson } 1098*800f99ffSJeremy L Thompson 1099*800f99ffSJeremy L Thompson /*@C 1100*800f99ffSJeremy L Thompson DMTSSetIJacobianContextDestroy - set TS Jacobian evaluation context destroy function 1101*800f99ffSJeremy L Thompson 1102*800f99ffSJeremy L Thompson Not Collective 1103*800f99ffSJeremy L Thompson 1104*800f99ffSJeremy L Thompson Input Parameters: 1105*800f99ffSJeremy L Thompson + dm - DM to be used with TS 1106*800f99ffSJeremy L Thompson . f - Jacobian evaluation context destroy function 1107*800f99ffSJeremy L Thompson 1108*800f99ffSJeremy L Thompson Level: advanced 1109*800f99ffSJeremy L Thompson 1110*800f99ffSJeremy L Thompson Note: 1111*800f99ffSJeremy L Thompson TSSetIJacobianContextDestroy() is normally used, but it calls this function internally because the user context is actually 1112*800f99ffSJeremy L Thompson associated with the DM. This makes the interface consistent regardless of whether the user interacts with a DM or 1113*800f99ffSJeremy L Thompson not. If DM took a more central role at some later date, this could become the primary method of setting the Jacobian. 1114*800f99ffSJeremy L Thompson 1115*800f99ffSJeremy L Thompson .seealso: `TSSetIJacobianContextDestroy()`, `DMTSSetIJacobian()`, `TSSetIJacobian()` 1116*800f99ffSJeremy L Thompson @*/ 1117*800f99ffSJeremy L Thompson PetscErrorCode DMTSSetIJacobianContextDestroy(DM dm,PetscErrorCode (*f)(void*)) 1118*800f99ffSJeremy L Thompson { 1119*800f99ffSJeremy L Thompson DMTS tsdm; 1120*800f99ffSJeremy L Thompson 1121*800f99ffSJeremy L Thompson PetscFunctionBegin; 1122*800f99ffSJeremy L Thompson PetscValidHeaderSpecific(dm,DM_CLASSID,1); 1123*800f99ffSJeremy L Thompson PetscCall(DMGetDMTSWrite(dm,&tsdm)); 1124*800f99ffSJeremy L Thompson if (tsdm->ijacobianctxcontainer) PetscCall(PetscContainerSetUserDestroy(tsdm->ijacobianctxcontainer,f)); 1125*800f99ffSJeremy L Thompson PetscFunctionReturn(0); 1126*800f99ffSJeremy L Thompson } 1127*800f99ffSJeremy L Thompson 1128*800f99ffSJeremy L Thompson PetscErrorCode DMTSUnsetIJacobianContext_Internal(DM dm) 1129*800f99ffSJeremy L Thompson { 1130*800f99ffSJeremy L Thompson DMTS tsdm; 1131*800f99ffSJeremy L Thompson 1132*800f99ffSJeremy L Thompson PetscFunctionBegin; 1133*800f99ffSJeremy L Thompson PetscValidHeaderSpecific(dm,DM_CLASSID,1); 1134*800f99ffSJeremy L Thompson PetscCall(DMGetDMTSWrite(dm,&tsdm)); 1135*800f99ffSJeremy L Thompson PetscCall(DMTSUnsetIJacobianContext_DMTS(tsdm)); 113624989b8cSPeter Brune PetscFunctionReturn(0); 113724989b8cSPeter Brune } 113824989b8cSPeter Brune 113924989b8cSPeter Brune /*@C 114024989b8cSPeter Brune DMTSGetIJacobian - get TS Jacobian evaluation function 114124989b8cSPeter Brune 114224989b8cSPeter Brune Not Collective 114324989b8cSPeter Brune 11444165533cSJose E. Roman Input Parameter: 114524989b8cSPeter Brune . dm - DM to be used with TS 114624989b8cSPeter Brune 11474165533cSJose E. Roman Output Parameters: 114824989b8cSPeter Brune + func - Jacobian evaluation function, see TSSetIJacobian() for calling sequence 114924989b8cSPeter Brune - ctx - context for residual evaluation 115024989b8cSPeter Brune 115124989b8cSPeter Brune Level: advanced 115224989b8cSPeter Brune 115324989b8cSPeter Brune Note: 115424989b8cSPeter Brune TSGetJacobian() is normally used, but it calls this function internally because the user context is actually 115524989b8cSPeter Brune associated with the DM. This makes the interface consistent regardless of whether the user interacts with a DM or 115624989b8cSPeter Brune not. If DM took a more central role at some later date, this could become the primary method of setting the Jacobian. 115724989b8cSPeter Brune 1158db781477SPatrick Sanan .seealso: `DMTSSetContext()`, `TSSetFunction()`, `DMTSSetJacobian()` 115924989b8cSPeter Brune @*/ 116024989b8cSPeter Brune PetscErrorCode DMTSGetIJacobian(DM dm,TSIJacobian *func,void **ctx) 116124989b8cSPeter Brune { 1162942e3340SBarry Smith DMTS tsdm; 116324989b8cSPeter Brune 116424989b8cSPeter Brune PetscFunctionBegin; 116524989b8cSPeter Brune PetscValidHeaderSpecific(dm,DM_CLASSID,1); 11669566063dSJacob Faibussowitsch PetscCall(DMGetDMTS(dm,&tsdm)); 1167d74926cbSBarry Smith if (func) *func = tsdm->ops->ijacobian; 1168*800f99ffSJeremy L Thompson if (ctx) { 1169*800f99ffSJeremy L Thompson if (tsdm->ijacobianctxcontainer) PetscCall(PetscContainerGetPointer(tsdm->ijacobianctxcontainer,ctx)); 1170*800f99ffSJeremy L Thompson else *ctx = NULL; 1171*800f99ffSJeremy L Thompson } 117224989b8cSPeter Brune PetscFunctionReturn(0); 117324989b8cSPeter Brune } 117424989b8cSPeter Brune 117524989b8cSPeter Brune /*@C 117624989b8cSPeter Brune DMTSSetRHSJacobian - set TS Jacobian evaluation function 117724989b8cSPeter Brune 117824989b8cSPeter Brune Not Collective 117924989b8cSPeter Brune 11804165533cSJose E. Roman Input Parameters: 118124989b8cSPeter Brune + dm - DM to be used with TS 1182a96d6ef6SBarry Smith . func - Jacobian evaluation routine 118324989b8cSPeter Brune - ctx - context for residual evaluation 118424989b8cSPeter Brune 1185a96d6ef6SBarry Smith Calling sequence of func: 1186a96d6ef6SBarry Smith $ PetscErrorCode func(TS ts,PetscReal t,Vec u,Mat A,Mat B,void *ctx); 1187a96d6ef6SBarry Smith 1188a96d6ef6SBarry Smith + t - current timestep 1189a96d6ef6SBarry Smith . u - input vector 1190a96d6ef6SBarry Smith . Amat - (approximate) Jacobian matrix 1191a96d6ef6SBarry Smith . Pmat - matrix from which preconditioner is to be constructed (usually the same as Amat) 1192a96d6ef6SBarry Smith - ctx - [optional] user-defined context for matrix evaluation routine 1193a96d6ef6SBarry Smith 119424989b8cSPeter Brune Level: advanced 119524989b8cSPeter Brune 119624989b8cSPeter Brune Note: 119724989b8cSPeter Brune TSSetJacobian() is normally used, but it calls this function internally because the user context is actually 119824989b8cSPeter Brune associated with the DM. This makes the interface consistent regardless of whether the user interacts with a DM or 119924989b8cSPeter Brune not. If DM took a more central role at some later date, this could become the primary method of setting the Jacobian. 120024989b8cSPeter Brune 1201db781477SPatrick Sanan .seealso: `DMTSSetContext()`, `TSSetFunction()`, `DMTSGetJacobian()`, `TSSetRHSJacobian()` 120224989b8cSPeter Brune @*/ 120324989b8cSPeter Brune PetscErrorCode DMTSSetRHSJacobian(DM dm,TSRHSJacobian func,void *ctx) 120424989b8cSPeter Brune { 1205942e3340SBarry Smith DMTS tsdm; 120624989b8cSPeter Brune 120724989b8cSPeter Brune PetscFunctionBegin; 120824989b8cSPeter Brune PetscValidHeaderSpecific(dm,DM_CLASSID,1); 12099566063dSJacob Faibussowitsch PetscCall(DMGetDMTSWrite(dm,&tsdm)); 1210d74926cbSBarry Smith if (func) tsdm->ops->rhsjacobian = func; 1211*800f99ffSJeremy L Thompson if (ctx) { 1212*800f99ffSJeremy L Thompson PetscContainer ctxcontainer; 1213*800f99ffSJeremy L Thompson PetscCall(PetscContainerCreate(PetscObjectComm((PetscObject)tsdm),&ctxcontainer)); 1214*800f99ffSJeremy L Thompson PetscCall(PetscContainerSetPointer(ctxcontainer,ctx)); 1215*800f99ffSJeremy L Thompson PetscCall(PetscObjectCompose((PetscObject)tsdm,"rhs jacobian ctx",(PetscObject)ctxcontainer)); 1216*800f99ffSJeremy L Thompson tsdm->rhsjacobianctxcontainer = ctxcontainer; 1217*800f99ffSJeremy L Thompson PetscCall(PetscContainerDestroy(&ctxcontainer)); 1218*800f99ffSJeremy L Thompson } 1219*800f99ffSJeremy L Thompson PetscFunctionReturn(0); 1220*800f99ffSJeremy L Thompson } 1221*800f99ffSJeremy L Thompson 1222*800f99ffSJeremy L Thompson /*@C 1223*800f99ffSJeremy L Thompson DMTSSetRHSJacobianContextDestroy - set TS Jacobian evaluation context destroy function 1224*800f99ffSJeremy L Thompson 1225*800f99ffSJeremy L Thompson Not Collective 1226*800f99ffSJeremy L Thompson 1227*800f99ffSJeremy L Thompson Input Parameters: 1228*800f99ffSJeremy L Thompson + dm - DM to be used with TS 1229*800f99ffSJeremy L Thompson . f - Jacobian evaluation context destroy function 1230*800f99ffSJeremy L Thompson 1231*800f99ffSJeremy L Thompson .seealso: `TSSetRHSJacobianContextDestroy()`, `DMTSSetRHSJacobian()`, `TSSetRHSJacobian()` 1232*800f99ffSJeremy L Thompson @*/ 1233*800f99ffSJeremy L Thompson PetscErrorCode DMTSSetRHSJacobianContextDestroy(DM dm,PetscErrorCode (*f)(void*)) 1234*800f99ffSJeremy L Thompson { 1235*800f99ffSJeremy L Thompson DMTS tsdm; 1236*800f99ffSJeremy L Thompson 1237*800f99ffSJeremy L Thompson PetscFunctionBegin; 1238*800f99ffSJeremy L Thompson PetscValidHeaderSpecific(dm,DM_CLASSID,1); 1239*800f99ffSJeremy L Thompson PetscCall(DMGetDMTSWrite(dm,&tsdm)); 1240*800f99ffSJeremy L Thompson if (tsdm->rhsjacobianctxcontainer) PetscCall(PetscContainerSetUserDestroy(tsdm->rhsjacobianctxcontainer,f)); 1241*800f99ffSJeremy L Thompson PetscFunctionReturn(0); 1242*800f99ffSJeremy L Thompson } 1243*800f99ffSJeremy L Thompson 1244*800f99ffSJeremy L Thompson PetscErrorCode DMTSUnsetRHSJacobianContext_Internal(DM dm) 1245*800f99ffSJeremy L Thompson { 1246*800f99ffSJeremy L Thompson DMTS tsdm; 1247*800f99ffSJeremy L Thompson 1248*800f99ffSJeremy L Thompson PetscFunctionBegin; 1249*800f99ffSJeremy L Thompson PetscValidHeaderSpecific(dm,DM_CLASSID,1); 1250*800f99ffSJeremy L Thompson PetscCall(DMGetDMTSWrite(dm,&tsdm)); 1251*800f99ffSJeremy L Thompson PetscCall(DMTSUnsetRHSJacobianContext_DMTS(tsdm)); 125224989b8cSPeter Brune PetscFunctionReturn(0); 125324989b8cSPeter Brune } 125424989b8cSPeter Brune 125524989b8cSPeter Brune /*@C 125624989b8cSPeter Brune DMTSGetRHSJacobian - get TS Jacobian evaluation function 125724989b8cSPeter Brune 125824989b8cSPeter Brune Not Collective 125924989b8cSPeter Brune 12604165533cSJose E. Roman Input Parameter: 126124989b8cSPeter Brune . dm - DM to be used with TS 126224989b8cSPeter Brune 12634165533cSJose E. Roman Output Parameters: 126424989b8cSPeter Brune + func - Jacobian evaluation function, see TSSetRHSJacobian() for calling sequence 126524989b8cSPeter Brune - ctx - context for residual evaluation 126624989b8cSPeter Brune 126724989b8cSPeter Brune Level: advanced 126824989b8cSPeter Brune 126924989b8cSPeter Brune Note: 127024989b8cSPeter Brune TSGetJacobian() is normally used, but it calls this function internally because the user context is actually 127124989b8cSPeter Brune associated with the DM. This makes the interface consistent regardless of whether the user interacts with a DM or 127224989b8cSPeter Brune not. If DM took a more central role at some later date, this could become the primary method of setting the Jacobian. 127324989b8cSPeter Brune 1274db781477SPatrick Sanan .seealso: `DMTSSetContext()`, `TSSetRHSFunction()`, `DMTSSetRHSJacobian()`, `TSSetRHSJacobian()` 127524989b8cSPeter Brune @*/ 127624989b8cSPeter Brune PetscErrorCode DMTSGetRHSJacobian(DM dm,TSRHSJacobian *func,void **ctx) 127724989b8cSPeter Brune { 1278942e3340SBarry Smith DMTS tsdm; 127924989b8cSPeter Brune 128024989b8cSPeter Brune PetscFunctionBegin; 128124989b8cSPeter Brune PetscValidHeaderSpecific(dm,DM_CLASSID,1); 12829566063dSJacob Faibussowitsch PetscCall(DMGetDMTS(dm,&tsdm)); 1283d74926cbSBarry Smith if (func) *func = tsdm->ops->rhsjacobian; 1284*800f99ffSJeremy L Thompson if (ctx) { 1285*800f99ffSJeremy L Thompson if (tsdm->rhsjacobianctxcontainer) PetscCall(PetscContainerGetPointer(tsdm->rhsjacobianctxcontainer,ctx)); 1286*800f99ffSJeremy L Thompson else *ctx = NULL; 1287*800f99ffSJeremy L Thompson } 128824989b8cSPeter Brune PetscFunctionReturn(0); 128924989b8cSPeter Brune } 1290ad6bc421SBarry Smith 1291ad6bc421SBarry Smith /*@C 1292ad6bc421SBarry Smith DMTSSetIFunctionSerialize - sets functions used to view and load a IFunction context 1293ad6bc421SBarry Smith 1294ad6bc421SBarry Smith Not Collective 1295ad6bc421SBarry Smith 12964165533cSJose E. Roman Input Parameters: 1297ad6bc421SBarry Smith + dm - DM to be used with TS 1298ad6bc421SBarry Smith . view - viewer function 1299ad6bc421SBarry Smith - load - loading function 1300ad6bc421SBarry Smith 1301ad6bc421SBarry Smith Level: advanced 1302ad6bc421SBarry Smith 1303db781477SPatrick Sanan .seealso: `DMTSSetContext()`, `TSSetFunction()`, `DMTSSetJacobian()` 1304ad6bc421SBarry Smith @*/ 1305ad6bc421SBarry Smith PetscErrorCode DMTSSetIFunctionSerialize(DM dm,PetscErrorCode (*view)(void*,PetscViewer),PetscErrorCode (*load)(void**,PetscViewer)) 1306ad6bc421SBarry Smith { 1307ad6bc421SBarry Smith DMTS tsdm; 1308ad6bc421SBarry Smith 1309ad6bc421SBarry Smith PetscFunctionBegin; 1310ad6bc421SBarry Smith PetscValidHeaderSpecific(dm,DM_CLASSID,1); 13119566063dSJacob Faibussowitsch PetscCall(DMGetDMTSWrite(dm,&tsdm)); 1312ad6bc421SBarry Smith tsdm->ops->ifunctionview = view; 1313ad6bc421SBarry Smith tsdm->ops->ifunctionload = load; 1314ad6bc421SBarry Smith PetscFunctionReturn(0); 1315ad6bc421SBarry Smith } 1316ad6bc421SBarry Smith 1317ad6bc421SBarry Smith /*@C 1318ad6bc421SBarry Smith DMTSSetIJacobianSerialize - sets functions used to view and load a IJacobian context 1319ad6bc421SBarry Smith 1320ad6bc421SBarry Smith Not Collective 1321ad6bc421SBarry Smith 13224165533cSJose E. Roman Input Parameters: 1323ad6bc421SBarry Smith + dm - DM to be used with TS 1324ad6bc421SBarry Smith . view - viewer function 1325ad6bc421SBarry Smith - load - loading function 1326ad6bc421SBarry Smith 1327ad6bc421SBarry Smith Level: advanced 1328ad6bc421SBarry Smith 1329db781477SPatrick Sanan .seealso: `DMTSSetContext()`, `TSSetFunction()`, `DMTSSetJacobian()` 1330ad6bc421SBarry Smith @*/ 1331ad6bc421SBarry Smith PetscErrorCode DMTSSetIJacobianSerialize(DM dm,PetscErrorCode (*view)(void*,PetscViewer),PetscErrorCode (*load)(void**,PetscViewer)) 1332ad6bc421SBarry Smith { 1333ad6bc421SBarry Smith DMTS tsdm; 1334ad6bc421SBarry Smith 1335ad6bc421SBarry Smith PetscFunctionBegin; 1336ad6bc421SBarry Smith PetscValidHeaderSpecific(dm,DM_CLASSID,1); 13379566063dSJacob Faibussowitsch PetscCall(DMGetDMTSWrite(dm,&tsdm)); 1338ad6bc421SBarry Smith tsdm->ops->ijacobianview = view; 1339ad6bc421SBarry Smith tsdm->ops->ijacobianload = load; 1340ad6bc421SBarry Smith PetscFunctionReturn(0); 1341ad6bc421SBarry Smith } 1342