124989b8cSPeter Brune #include <petsc-private/tsimpl.h> /*I "petscts.h" I*/ 224989b8cSPeter Brune #include <petsc-private/dmimpl.h> /*I "petscdm.h" I*/ 324989b8cSPeter Brune 4d74926cbSBarry Smith #undef __FUNCT__ 5d74926cbSBarry Smith #define __FUNCT__ "DMTSDestroy" 6d74926cbSBarry Smith static PetscErrorCode DMTSDestroy(DMTS *kdm) 7d74926cbSBarry Smith { 8d74926cbSBarry Smith PetscErrorCode ierr; 9d74926cbSBarry Smith 10d74926cbSBarry Smith PetscFunctionBegin; 11d74926cbSBarry Smith if (!*kdm) PetscFunctionReturn(0); 12d74926cbSBarry Smith PetscValidHeaderSpecific((*kdm),DMTS_CLASSID,1); 13d74926cbSBarry Smith if (--((PetscObject)(*kdm))->refct > 0) {*kdm = 0; PetscFunctionReturn(0);} 14d74926cbSBarry Smith if ((*kdm)->ops->destroy) {ierr = ((*kdm)->ops->destroy)(*kdm);CHKERRQ(ierr);} 15d74926cbSBarry Smith ierr = PetscHeaderDestroy(kdm);CHKERRQ(ierr); 16d74926cbSBarry Smith PetscFunctionReturn(0); 17d74926cbSBarry Smith } 18d74926cbSBarry Smith 19d74926cbSBarry Smith #undef __FUNCT__ 20d74926cbSBarry Smith #define __FUNCT__ "DMTSCreate" 21d74926cbSBarry Smith static PetscErrorCode DMTSCreate(MPI_Comm comm,DMTS *kdm) 22d74926cbSBarry Smith { 23d74926cbSBarry Smith PetscErrorCode ierr; 24d74926cbSBarry Smith 25d74926cbSBarry Smith PetscFunctionBegin; 26d74926cbSBarry Smith #ifndef PETSC_USE_DYNAMIC_LIBRARIES 27d74926cbSBarry Smith ierr = TSInitializePackage(PETSC_NULL);CHKERRQ(ierr); 28d74926cbSBarry Smith #endif 29*b4615a05SBarry Smith ierr = PetscHeaderCreate(*kdm, _p_DMTS, struct _DMTSOps, DMTS_CLASSID, -1, "DMTS", "DMTS", "DMTS", comm, DMTSDestroy, PETSC_NULL);CHKERRQ(ierr); 30d74926cbSBarry Smith ierr = PetscMemzero((*kdm)->ops, sizeof(struct _DMTSOps));CHKERRQ(ierr); 31d74926cbSBarry Smith PetscFunctionReturn(0); 32d74926cbSBarry Smith } 3324989b8cSPeter Brune 3424989b8cSPeter Brune #undef __FUNCT__ 35942e3340SBarry Smith #define __FUNCT__ "DMCoarsenHook_DMTS" 36942e3340SBarry Smith /* Attaches the DMSNES to the coarse level. 3724989b8cSPeter Brune * Under what conditions should we copy versus duplicate? 3824989b8cSPeter Brune */ 39942e3340SBarry Smith static PetscErrorCode DMCoarsenHook_DMTS(DM dm,DM dmc,void *ctx) 4024989b8cSPeter Brune { 4124989b8cSPeter Brune PetscErrorCode ierr; 4224989b8cSPeter Brune 4324989b8cSPeter Brune PetscFunctionBegin; 44942e3340SBarry Smith ierr = DMCopyDMTS(dm,dmc);CHKERRQ(ierr); 4524989b8cSPeter Brune PetscFunctionReturn(0); 4624989b8cSPeter Brune } 4724989b8cSPeter Brune 4824989b8cSPeter Brune #undef __FUNCT__ 49942e3340SBarry Smith #define __FUNCT__ "DMRestrictHook_DMTS" 5024989b8cSPeter Brune /* This could restrict auxiliary information to the coarse level. 5124989b8cSPeter Brune */ 52942e3340SBarry Smith static PetscErrorCode DMRestrictHook_DMTS(DM dm,Mat Restrict,Vec rscale,Mat Inject,DM dmc,void *ctx) 5324989b8cSPeter Brune { 5424989b8cSPeter Brune 5524989b8cSPeter Brune PetscFunctionBegin; 5624989b8cSPeter Brune PetscFunctionReturn(0); 5724989b8cSPeter Brune } 5824989b8cSPeter Brune 5924989b8cSPeter Brune #undef __FUNCT__ 60d74926cbSBarry Smith #define __FUNCT__ "DMTSCopy" 61d74926cbSBarry Smith /*@C 62d74926cbSBarry Smith DMTSCopy - copies the information in a DMTS to another DMTS 63d74926cbSBarry Smith 64d74926cbSBarry Smith Not Collective 65d74926cbSBarry Smith 66d74926cbSBarry Smith Input Argument: 67d74926cbSBarry Smith + kdm - Original DMTS 68d74926cbSBarry Smith - nkdm - DMTS to receive the data, should have been created with DMTSCreate() 69d74926cbSBarry Smith 70d74926cbSBarry Smith Level: developer 71d74926cbSBarry Smith 72d74926cbSBarry Smith .seealso: DMTSCreate(), DMTSDestroy() 73d74926cbSBarry Smith @*/ 74d74926cbSBarry Smith PetscErrorCode DMTSCopy(DMTS kdm,DMTS nkdm) 7524989b8cSPeter Brune { 7624989b8cSPeter Brune PetscErrorCode ierr; 7724989b8cSPeter Brune 7824989b8cSPeter Brune PetscFunctionBegin; 79d74926cbSBarry Smith PetscValidHeaderSpecific(kdm,DMTS_CLASSID,1); 80d74926cbSBarry Smith PetscValidHeaderSpecific(nkdm,DMTS_CLASSID,2); 81d74926cbSBarry Smith nkdm->ops->rhsfunction = kdm->ops->rhsfunction; 82d74926cbSBarry Smith nkdm->ops->rhsjacobian = kdm->ops->rhsjacobian; 83d74926cbSBarry Smith nkdm->ops->ifunction = kdm->ops->ifunction; 84d74926cbSBarry Smith nkdm->ops->ijacobian = kdm->ops->ijacobian; 85d74926cbSBarry Smith nkdm->ops->solution = kdm->ops->solution; 86d74926cbSBarry Smith nkdm->ops->destroy = kdm->ops->destroy; 87d74926cbSBarry Smith nkdm->ops->duplicate = kdm->ops->duplicate; 88d74926cbSBarry Smith 89d74926cbSBarry Smith nkdm->rhsfunctionctx = kdm->rhsfunctionctx; 90d74926cbSBarry Smith nkdm->rhsjacobianctx = kdm->rhsjacobianctx; 91d74926cbSBarry Smith nkdm->ifunctionctx = kdm->ifunctionctx; 92d74926cbSBarry Smith nkdm->ijacobianctx = kdm->ijacobianctx; 93d74926cbSBarry Smith nkdm->solutionctx = kdm->solutionctx; 94d74926cbSBarry Smith 95d74926cbSBarry Smith nkdm->data = kdm->data; 96d74926cbSBarry Smith 97d74926cbSBarry Smith /* 98d74926cbSBarry Smith nkdm->fortran_func_pointers[0] = kdm->fortran_func_pointers[0]; 99d74926cbSBarry Smith nkdm->fortran_func_pointers[1] = kdm->fortran_func_pointers[1]; 100d74926cbSBarry Smith nkdm->fortran_func_pointers[2] = kdm->fortran_func_pointers[2]; 101d74926cbSBarry Smith */ 102d74926cbSBarry Smith 103d74926cbSBarry Smith /* implementation specific copy hooks */ 104d74926cbSBarry Smith if (kdm->ops->duplicate) {ierr = (*kdm->ops->duplicate)(kdm,nkdm);CHKERRQ(ierr);} 10524989b8cSPeter Brune PetscFunctionReturn(0); 10624989b8cSPeter Brune } 10724989b8cSPeter Brune 10824989b8cSPeter Brune #undef __FUNCT__ 109942e3340SBarry Smith #define __FUNCT__ "DMGetDMTS" 11024989b8cSPeter Brune /*@C 111942e3340SBarry Smith DMGetDMTS - get read-only private DMTS context from a DM 11224989b8cSPeter Brune 11324989b8cSPeter Brune Not Collective 11424989b8cSPeter Brune 11524989b8cSPeter Brune Input Argument: 11624989b8cSPeter Brune . dm - DM to be used with TS 11724989b8cSPeter Brune 11824989b8cSPeter Brune Output Argument: 119942e3340SBarry Smith . tsdm - private DMTS context 12024989b8cSPeter Brune 12124989b8cSPeter Brune Level: developer 12224989b8cSPeter Brune 12324989b8cSPeter Brune Notes: 124942e3340SBarry Smith Use DMGetDMTSWrite() if write access is needed. The DMTSSetXXX API should be used wherever possible. 12524989b8cSPeter Brune 126942e3340SBarry Smith .seealso: DMGetDMTSWrite() 12724989b8cSPeter Brune @*/ 128942e3340SBarry Smith PetscErrorCode DMGetDMTS(DM dm,DMTS *tsdm) 12924989b8cSPeter Brune { 13024989b8cSPeter Brune PetscErrorCode ierr; 13124989b8cSPeter Brune 13224989b8cSPeter Brune PetscFunctionBegin; 13324989b8cSPeter Brune PetscValidHeaderSpecific(dm,DM_CLASSID,1); 134d74926cbSBarry Smith ierr = PetscObjectQuery((PetscObject)dm,"DMTS",(PetscObject*)tsdm);CHKERRQ(ierr); 135d74926cbSBarry Smith if (!*tsdm) { 136d74926cbSBarry Smith DMTS tmptsdm; 137942e3340SBarry Smith ierr = PetscInfo(dm,"Creating new DMTS\n");CHKERRQ(ierr); 138d74926cbSBarry Smith ierr = DMTSCreate(((PetscObject)dm)->comm,tsdm);CHKERRQ(ierr); 139d74926cbSBarry Smith ierr = PetscObjectCompose((PetscObject)dm,"DMTS",(PetscObject)*tsdm);CHKERRQ(ierr); 140942e3340SBarry Smith ierr = DMCoarsenHookAdd(dm,DMCoarsenHook_DMTS,DMRestrictHook_DMTS,PETSC_NULL);CHKERRQ(ierr); 141d74926cbSBarry Smith tmptsdm = *tsdm; 142d74926cbSBarry Smith ierr = DMTSDestroy(&tmptsdm);CHKERRQ(ierr); 14324989b8cSPeter Brune } 14424989b8cSPeter Brune PetscFunctionReturn(0); 14524989b8cSPeter Brune } 14624989b8cSPeter Brune 14724989b8cSPeter Brune #undef __FUNCT__ 148942e3340SBarry Smith #define __FUNCT__ "DMGetDMTSWrite" 14924989b8cSPeter Brune /*@C 150942e3340SBarry Smith DMGetDMTSWrite - get write access to private DMTS context from a DM 15124989b8cSPeter Brune 15224989b8cSPeter Brune Not Collective 15324989b8cSPeter Brune 15424989b8cSPeter Brune Input Argument: 15524989b8cSPeter Brune . dm - DM to be used with TS 15624989b8cSPeter Brune 15724989b8cSPeter Brune Output Argument: 158942e3340SBarry Smith . tsdm - private DMTS context 15924989b8cSPeter Brune 16024989b8cSPeter Brune Level: developer 16124989b8cSPeter Brune 162942e3340SBarry Smith .seealso: DMGetDMTS() 16324989b8cSPeter Brune @*/ 164942e3340SBarry Smith PetscErrorCode DMGetDMTSWrite(DM dm,DMTS *tsdm) 16524989b8cSPeter Brune { 16624989b8cSPeter Brune PetscErrorCode ierr; 167942e3340SBarry Smith DMTS sdm; 16824989b8cSPeter Brune 16924989b8cSPeter Brune PetscFunctionBegin; 17024989b8cSPeter Brune PetscValidHeaderSpecific(dm,DM_CLASSID,1); 171942e3340SBarry Smith ierr = DMGetDMTS(dm,&sdm);CHKERRQ(ierr); 17224989b8cSPeter Brune if (!sdm->originaldm) sdm->originaldm = dm; 17324989b8cSPeter Brune if (sdm->originaldm != dm) { /* Copy on write */ 174d74926cbSBarry Smith DMTS oldsdm = sdm,tsdm; 175942e3340SBarry Smith ierr = PetscInfo(dm,"Copying DMTS due to write\n");CHKERRQ(ierr); 176d74926cbSBarry Smith ierr = DMTSCreate(((PetscObject)dm)->comm,&sdm);CHKERRQ(ierr); 177d74926cbSBarry Smith ierr = DMTSCopy(oldsdm,sdm);CHKERRQ(ierr); 178d74926cbSBarry Smith 179d74926cbSBarry Smith ierr = PetscObjectCompose((PetscObject)dm,"DMTS",(PetscObject)sdm);CHKERRQ(ierr); 180d74926cbSBarry Smith tsdm = sdm; 181d74926cbSBarry Smith ierr = DMTSDestroy(&tsdm );CHKERRQ(ierr); 18224989b8cSPeter Brune } 18324989b8cSPeter Brune *tsdm = sdm; 18424989b8cSPeter Brune PetscFunctionReturn(0); 18524989b8cSPeter Brune } 18624989b8cSPeter Brune 18724989b8cSPeter Brune #undef __FUNCT__ 188942e3340SBarry Smith #define __FUNCT__ "DMCopyDMTS" 18924989b8cSPeter Brune /*@C 190942e3340SBarry Smith DMCopyDMTS - copies a DM context to a new DM 19124989b8cSPeter Brune 19224989b8cSPeter Brune Logically Collective 19324989b8cSPeter Brune 19424989b8cSPeter Brune Input Arguments: 19524989b8cSPeter Brune + dmsrc - DM to obtain context from 19624989b8cSPeter Brune - dmdest - DM to add context to 19724989b8cSPeter Brune 19824989b8cSPeter Brune Level: developer 19924989b8cSPeter Brune 20024989b8cSPeter Brune Note: 20124989b8cSPeter Brune The context is copied by reference. This function does not ensure that a context exists. 20224989b8cSPeter Brune 203942e3340SBarry Smith .seealso: DMGetDMTS(), TSSetDM() 20424989b8cSPeter Brune @*/ 205942e3340SBarry Smith PetscErrorCode DMCopyDMTS(DM dmsrc,DM dmdest) 20624989b8cSPeter Brune { 20724989b8cSPeter Brune PetscErrorCode ierr; 208d74926cbSBarry Smith DMTS sdm; 20924989b8cSPeter Brune 21024989b8cSPeter Brune PetscFunctionBegin; 21124989b8cSPeter Brune PetscValidHeaderSpecific(dmsrc,DM_CLASSID,1); 21224989b8cSPeter Brune PetscValidHeaderSpecific(dmdest,DM_CLASSID,2); 213d74926cbSBarry Smith ierr = PetscObjectQuery((PetscObject)dmsrc,"DMTS",(PetscObject*)&sdm);CHKERRQ(ierr); 214d74926cbSBarry Smith if (sdm) { 215d74926cbSBarry Smith ierr = PetscObjectCompose((PetscObject)dmdest,"DMTS",(PetscObject)sdm);CHKERRQ(ierr); 216942e3340SBarry Smith ierr = DMCoarsenHookAdd(dmdest,DMCoarsenHook_DMTS,DMRestrictHook_DMTS,PETSC_NULL);CHKERRQ(ierr); 21724989b8cSPeter Brune } 21824989b8cSPeter Brune PetscFunctionReturn(0); 21924989b8cSPeter Brune } 22024989b8cSPeter Brune 22124989b8cSPeter Brune #undef __FUNCT__ 22224989b8cSPeter Brune #define __FUNCT__ "DMTSSetIFunction" 22324989b8cSPeter Brune /*@C 22424989b8cSPeter Brune DMTSSetIFunction - set TS implicit function evaluation function 22524989b8cSPeter Brune 22624989b8cSPeter Brune Not Collective 22724989b8cSPeter Brune 22824989b8cSPeter Brune Input Arguments: 22924989b8cSPeter Brune + dm - DM to be used with TS 23024989b8cSPeter Brune . func - function evaluation function, see TSSetIFunction() for calling sequence 23124989b8cSPeter Brune - ctx - context for residual evaluation 23224989b8cSPeter Brune 23324989b8cSPeter Brune Level: advanced 23424989b8cSPeter Brune 23524989b8cSPeter Brune Note: 23624989b8cSPeter Brune TSSetFunction() is normally used, but it calls this function internally because the user context is actually 23724989b8cSPeter Brune associated with the DM. This makes the interface consistent regardless of whether the user interacts with a DM or 23824989b8cSPeter Brune not. If DM took a more central role at some later date, this could become the primary method of setting the residual. 23924989b8cSPeter Brune 24024989b8cSPeter Brune .seealso: DMTSSetContext(), TSSetFunction(), DMTSSetJacobian() 24124989b8cSPeter Brune @*/ 24224989b8cSPeter Brune PetscErrorCode DMTSSetIFunction(DM dm,TSIFunction func,void *ctx) 24324989b8cSPeter Brune { 24424989b8cSPeter Brune PetscErrorCode ierr; 245942e3340SBarry Smith DMTS tsdm; 24624989b8cSPeter Brune 24724989b8cSPeter Brune PetscFunctionBegin; 24824989b8cSPeter Brune PetscValidHeaderSpecific(dm,DM_CLASSID,1); 249942e3340SBarry Smith ierr = DMGetDMTSWrite(dm,&tsdm);CHKERRQ(ierr); 250d74926cbSBarry Smith if (func) tsdm->ops->ifunction = func; 25124989b8cSPeter Brune if (ctx) tsdm->ifunctionctx = ctx; 25224989b8cSPeter Brune PetscFunctionReturn(0); 25324989b8cSPeter Brune } 25424989b8cSPeter Brune 25524989b8cSPeter Brune #undef __FUNCT__ 25624989b8cSPeter Brune #define __FUNCT__ "DMTSGetIFunction" 25724989b8cSPeter Brune /*@C 25824989b8cSPeter Brune DMTSGetIFunction - get TS implicit residual evaluation function 25924989b8cSPeter Brune 26024989b8cSPeter Brune Not Collective 26124989b8cSPeter Brune 26224989b8cSPeter Brune Input Argument: 26324989b8cSPeter Brune . dm - DM to be used with TS 26424989b8cSPeter Brune 26524989b8cSPeter Brune Output Arguments: 26624989b8cSPeter Brune + func - function evaluation function, see TSSetIFunction() for calling sequence 26724989b8cSPeter Brune - ctx - context for residual evaluation 26824989b8cSPeter Brune 26924989b8cSPeter Brune Level: advanced 27024989b8cSPeter Brune 27124989b8cSPeter Brune Note: 27224989b8cSPeter Brune TSGetFunction() is normally used, but it calls this function internally because the user context is actually 27324989b8cSPeter Brune associated with the DM. 27424989b8cSPeter Brune 27524989b8cSPeter Brune .seealso: DMTSSetContext(), DMTSSetFunction(), TSSetFunction() 27624989b8cSPeter Brune @*/ 27724989b8cSPeter Brune PetscErrorCode DMTSGetIFunction(DM dm,TSIFunction *func,void **ctx) 27824989b8cSPeter Brune { 27924989b8cSPeter Brune PetscErrorCode ierr; 280942e3340SBarry Smith DMTS tsdm; 28124989b8cSPeter Brune 28224989b8cSPeter Brune PetscFunctionBegin; 28324989b8cSPeter Brune PetscValidHeaderSpecific(dm,DM_CLASSID,1); 284942e3340SBarry Smith ierr = DMGetDMTS(dm,&tsdm);CHKERRQ(ierr); 285d74926cbSBarry Smith if (func) *func = tsdm->ops->ifunction; 28624989b8cSPeter Brune if (ctx) *ctx = tsdm->ifunctionctx; 28724989b8cSPeter Brune PetscFunctionReturn(0); 28824989b8cSPeter Brune } 28924989b8cSPeter Brune 29024989b8cSPeter Brune 29124989b8cSPeter Brune #undef __FUNCT__ 29224989b8cSPeter Brune #define __FUNCT__ "DMTSSetRHSFunction" 29324989b8cSPeter Brune /*@C 29424989b8cSPeter Brune DMTSSetRHSFunction - set TS explicit residual evaluation function 29524989b8cSPeter Brune 29624989b8cSPeter Brune Not Collective 29724989b8cSPeter Brune 29824989b8cSPeter Brune Input Arguments: 29924989b8cSPeter Brune + dm - DM to be used with TS 30024989b8cSPeter Brune . func - RHS function evaluation function, see TSSetRHSFunction() for calling sequence 30124989b8cSPeter Brune - ctx - context for residual evaluation 30224989b8cSPeter Brune 30324989b8cSPeter Brune Level: advanced 30424989b8cSPeter Brune 30524989b8cSPeter Brune Note: 306ef20d060SBarry Smith TSSetRSHFunction() is normally used, but it calls this function internally because the user context is actually 30724989b8cSPeter Brune associated with the DM. This makes the interface consistent regardless of whether the user interacts with a DM or 30824989b8cSPeter Brune not. If DM took a more central role at some later date, this could become the primary method of setting the residual. 30924989b8cSPeter Brune 31024989b8cSPeter Brune .seealso: DMTSSetContext(), TSSetFunction(), DMTSSetJacobian() 31124989b8cSPeter Brune @*/ 31224989b8cSPeter Brune PetscErrorCode DMTSSetRHSFunction(DM dm,TSRHSFunction func,void *ctx) 31324989b8cSPeter Brune { 31424989b8cSPeter Brune PetscErrorCode ierr; 315942e3340SBarry Smith DMTS tsdm; 31624989b8cSPeter Brune 31724989b8cSPeter Brune PetscFunctionBegin; 31824989b8cSPeter Brune PetscValidHeaderSpecific(dm,DM_CLASSID,1); 319942e3340SBarry Smith ierr = DMGetDMTSWrite(dm,&tsdm);CHKERRQ(ierr); 320d74926cbSBarry Smith if (func) tsdm->ops->rhsfunction = func; 32124989b8cSPeter Brune if (ctx) tsdm->rhsfunctionctx = ctx; 32224989b8cSPeter Brune PetscFunctionReturn(0); 32324989b8cSPeter Brune } 32424989b8cSPeter Brune 32524989b8cSPeter Brune #undef __FUNCT__ 326ef20d060SBarry Smith #define __FUNCT__ "DMTSGetSolutionFunction" 327ef20d060SBarry Smith /*@C 328ef20d060SBarry Smith DMTSGetSolutionFunction - gets the TS solution evaluation function 329ef20d060SBarry Smith 330ef20d060SBarry Smith Not Collective 331ef20d060SBarry Smith 332ef20d060SBarry Smith Input Arguments: 333ef20d060SBarry Smith . dm - DM to be used with TS 334ef20d060SBarry Smith 335ef20d060SBarry Smith Output Parameters: 336ef20d060SBarry Smith + func - solution function evaluation function, see TSSetSolution() for calling sequence 337ef20d060SBarry Smith - ctx - context for solution evaluation 338ef20d060SBarry Smith 339ef20d060SBarry Smith Level: advanced 340ef20d060SBarry Smith 341ef20d060SBarry Smith .seealso: DMTSSetContext(), TSSetFunction(), DMTSSetJacobian() 342ef20d060SBarry Smith @*/ 343ef20d060SBarry Smith PetscErrorCode DMTSGetSolutionFunction(DM dm,TSSolutionFunction *func,void **ctx) 344ef20d060SBarry Smith { 345ef20d060SBarry Smith PetscErrorCode ierr; 346942e3340SBarry Smith DMTS tsdm; 347ef20d060SBarry Smith 348ef20d060SBarry Smith PetscFunctionBegin; 349ef20d060SBarry Smith PetscValidHeaderSpecific(dm,DM_CLASSID,1); 350942e3340SBarry Smith ierr = DMGetDMTS(dm,&tsdm);CHKERRQ(ierr); 351d74926cbSBarry Smith if (func) *func = tsdm->ops->solution; 352ef20d060SBarry Smith if (ctx) *ctx = tsdm->solutionctx; 353ef20d060SBarry Smith PetscFunctionReturn(0); 354ef20d060SBarry Smith } 355ef20d060SBarry Smith 356ef20d060SBarry Smith #undef __FUNCT__ 357ef20d060SBarry Smith #define __FUNCT__ "DMTSSetSolutionFunction" 358ef20d060SBarry Smith /*@C 359ef20d060SBarry Smith DMTSSetSolutionFunction - set TS solution evaluation function 360ef20d060SBarry Smith 361ef20d060SBarry Smith Not Collective 362ef20d060SBarry Smith 363ef20d060SBarry Smith Input Arguments: 364ef20d060SBarry Smith + dm - DM to be used with TS 365ef20d060SBarry Smith . func - solution function evaluation function, see TSSetSolution() for calling sequence 366ef20d060SBarry Smith - ctx - context for solution evaluation 367ef20d060SBarry Smith 368ef20d060SBarry Smith Level: advanced 369ef20d060SBarry Smith 370ef20d060SBarry Smith Note: 371ef20d060SBarry Smith TSSetSolutionFunction() is normally used, but it calls this function internally because the user context is actually 372ef20d060SBarry Smith associated with the DM. This makes the interface consistent regardless of whether the user interacts with a DM or 373ef20d060SBarry Smith not. If DM took a more central role at some later date, this could become the primary method of setting the residual. 374ef20d060SBarry Smith 375ef20d060SBarry Smith .seealso: DMTSSetContext(), TSSetFunction(), DMTSSetJacobian() 376ef20d060SBarry Smith @*/ 377ef20d060SBarry Smith PetscErrorCode DMTSSetSolutionFunction(DM dm,TSSolutionFunction func,void *ctx) 378ef20d060SBarry Smith { 379ef20d060SBarry Smith PetscErrorCode ierr; 380942e3340SBarry Smith DMTS tsdm; 381ef20d060SBarry Smith 382ef20d060SBarry Smith PetscFunctionBegin; 383ef20d060SBarry Smith PetscValidHeaderSpecific(dm,DM_CLASSID,1); 384942e3340SBarry Smith ierr = DMGetDMTSWrite(dm,&tsdm);CHKERRQ(ierr); 385d74926cbSBarry Smith if (func) tsdm->ops->solution = func; 386ef20d060SBarry Smith if (ctx) tsdm->solutionctx = ctx; 387ef20d060SBarry Smith PetscFunctionReturn(0); 388ef20d060SBarry Smith } 389ef20d060SBarry Smith 390ef20d060SBarry Smith #undef __FUNCT__ 39124989b8cSPeter Brune #define __FUNCT__ "DMTSGetRHSFunction" 39224989b8cSPeter Brune /*@C 39324989b8cSPeter Brune DMTSGetRHSFunction - get TS explicit residual evaluation function 39424989b8cSPeter Brune 39524989b8cSPeter Brune Not Collective 39624989b8cSPeter Brune 39724989b8cSPeter Brune Input Argument: 39824989b8cSPeter Brune . dm - DM to be used with TS 39924989b8cSPeter Brune 40024989b8cSPeter Brune Output Arguments: 40124989b8cSPeter Brune + func - residual evaluation function, see TSSetRHSFunction() for calling sequence 40224989b8cSPeter Brune - ctx - context for residual evaluation 40324989b8cSPeter Brune 40424989b8cSPeter Brune Level: advanced 40524989b8cSPeter Brune 40624989b8cSPeter Brune Note: 40724989b8cSPeter Brune TSGetFunction() is normally used, but it calls this function internally because the user context is actually 40824989b8cSPeter Brune associated with the DM. 40924989b8cSPeter Brune 41024989b8cSPeter Brune .seealso: DMTSSetContext(), DMTSSetFunction(), TSSetFunction() 41124989b8cSPeter Brune @*/ 41224989b8cSPeter Brune PetscErrorCode DMTSGetRHSFunction(DM dm,TSRHSFunction *func,void **ctx) 41324989b8cSPeter Brune { 41424989b8cSPeter Brune PetscErrorCode ierr; 415942e3340SBarry Smith DMTS tsdm; 41624989b8cSPeter Brune 41724989b8cSPeter Brune PetscFunctionBegin; 41824989b8cSPeter Brune PetscValidHeaderSpecific(dm,DM_CLASSID,1); 419942e3340SBarry Smith ierr = DMGetDMTS(dm,&tsdm);CHKERRQ(ierr); 420d74926cbSBarry Smith if (func) *func = tsdm->ops->rhsfunction; 42124989b8cSPeter Brune if (ctx) *ctx = tsdm->rhsfunctionctx; 42224989b8cSPeter Brune PetscFunctionReturn(0); 42324989b8cSPeter Brune } 42424989b8cSPeter Brune 42524989b8cSPeter Brune #undef __FUNCT__ 42624989b8cSPeter Brune #define __FUNCT__ "DMTSSetIJacobian" 42724989b8cSPeter Brune /*@C 42824989b8cSPeter Brune DMTSSetIJacobian - set TS Jacobian evaluation function 42924989b8cSPeter Brune 43024989b8cSPeter Brune Not Collective 43124989b8cSPeter Brune 43224989b8cSPeter Brune Input Argument: 43324989b8cSPeter Brune + dm - DM to be used with TS 43424989b8cSPeter Brune . func - Jacobian evaluation function, see TSSetIJacobian() for calling sequence 43524989b8cSPeter Brune - ctx - context for residual evaluation 43624989b8cSPeter Brune 43724989b8cSPeter Brune Level: advanced 43824989b8cSPeter Brune 43924989b8cSPeter Brune Note: 44024989b8cSPeter Brune TSSetJacobian() is normally used, but it calls this function internally because the user context is actually 44124989b8cSPeter Brune associated with the DM. This makes the interface consistent regardless of whether the user interacts with a DM or 44224989b8cSPeter Brune not. If DM took a more central role at some later date, this could become the primary method of setting the Jacobian. 44324989b8cSPeter Brune 44424989b8cSPeter Brune .seealso: DMTSSetContext(), TSSetFunction(), DMTSGetJacobian(), TSSetJacobian() 44524989b8cSPeter Brune @*/ 44624989b8cSPeter Brune PetscErrorCode DMTSSetIJacobian(DM dm,TSIJacobian func,void *ctx) 44724989b8cSPeter Brune { 44824989b8cSPeter Brune PetscErrorCode ierr; 449942e3340SBarry Smith DMTS sdm; 45024989b8cSPeter Brune 45124989b8cSPeter Brune PetscFunctionBegin; 45224989b8cSPeter Brune PetscValidHeaderSpecific(dm,DM_CLASSID,1); 453942e3340SBarry Smith ierr = DMGetDMTSWrite(dm,&sdm);CHKERRQ(ierr); 454d74926cbSBarry Smith if (func) sdm->ops->ijacobian = func; 45524989b8cSPeter Brune if (ctx) sdm->ijacobianctx = ctx; 45624989b8cSPeter Brune PetscFunctionReturn(0); 45724989b8cSPeter Brune } 45824989b8cSPeter Brune 45924989b8cSPeter Brune #undef __FUNCT__ 46024989b8cSPeter Brune #define __FUNCT__ "DMTSGetIJacobian" 46124989b8cSPeter Brune /*@C 46224989b8cSPeter Brune DMTSGetIJacobian - get TS Jacobian evaluation function 46324989b8cSPeter Brune 46424989b8cSPeter Brune Not Collective 46524989b8cSPeter Brune 46624989b8cSPeter Brune Input Argument: 46724989b8cSPeter Brune . dm - DM to be used with TS 46824989b8cSPeter Brune 46924989b8cSPeter Brune Output Arguments: 47024989b8cSPeter Brune + func - Jacobian evaluation function, see TSSetIJacobian() for calling sequence 47124989b8cSPeter Brune - ctx - context for residual evaluation 47224989b8cSPeter Brune 47324989b8cSPeter Brune Level: advanced 47424989b8cSPeter Brune 47524989b8cSPeter Brune Note: 47624989b8cSPeter Brune TSGetJacobian() is normally used, but it calls this function internally because the user context is actually 47724989b8cSPeter Brune associated with the DM. This makes the interface consistent regardless of whether the user interacts with a DM or 47824989b8cSPeter Brune not. If DM took a more central role at some later date, this could become the primary method of setting the Jacobian. 47924989b8cSPeter Brune 48024989b8cSPeter Brune .seealso: DMTSSetContext(), TSSetFunction(), DMTSSetJacobian() 48124989b8cSPeter Brune @*/ 48224989b8cSPeter Brune PetscErrorCode DMTSGetIJacobian(DM dm,TSIJacobian *func,void **ctx) 48324989b8cSPeter Brune { 48424989b8cSPeter Brune PetscErrorCode ierr; 485942e3340SBarry Smith DMTS tsdm; 48624989b8cSPeter Brune 48724989b8cSPeter Brune PetscFunctionBegin; 48824989b8cSPeter Brune PetscValidHeaderSpecific(dm,DM_CLASSID,1); 489942e3340SBarry Smith ierr = DMGetDMTS(dm,&tsdm);CHKERRQ(ierr); 490d74926cbSBarry Smith if (func) *func = tsdm->ops->ijacobian; 49124989b8cSPeter Brune if (ctx) *ctx = tsdm->ijacobianctx; 49224989b8cSPeter Brune PetscFunctionReturn(0); 49324989b8cSPeter Brune } 49424989b8cSPeter Brune 49524989b8cSPeter Brune 49624989b8cSPeter Brune #undef __FUNCT__ 49724989b8cSPeter Brune #define __FUNCT__ "DMTSSetRHSJacobian" 49824989b8cSPeter Brune /*@C 49924989b8cSPeter Brune DMTSSetRHSJacobian - set TS Jacobian evaluation function 50024989b8cSPeter Brune 50124989b8cSPeter Brune Not Collective 50224989b8cSPeter Brune 50324989b8cSPeter Brune Input Argument: 50424989b8cSPeter Brune + dm - DM to be used with TS 50524989b8cSPeter Brune . func - Jacobian evaluation function, see TSSetRHSJacobian() for calling sequence 50624989b8cSPeter Brune - ctx - context for residual evaluation 50724989b8cSPeter Brune 50824989b8cSPeter Brune Level: advanced 50924989b8cSPeter Brune 51024989b8cSPeter Brune Note: 51124989b8cSPeter Brune TSSetJacobian() is normally used, but it calls this function internally because the user context is actually 51224989b8cSPeter Brune associated with the DM. This makes the interface consistent regardless of whether the user interacts with a DM or 51324989b8cSPeter Brune not. If DM took a more central role at some later date, this could become the primary method of setting the Jacobian. 51424989b8cSPeter Brune 51524989b8cSPeter Brune .seealso: DMTSSetContext(), TSSetFunction(), DMTSGetJacobian(), TSSetJacobian() 51624989b8cSPeter Brune @*/ 51724989b8cSPeter Brune PetscErrorCode DMTSSetRHSJacobian(DM dm,TSRHSJacobian func,void *ctx) 51824989b8cSPeter Brune { 51924989b8cSPeter Brune PetscErrorCode ierr; 520942e3340SBarry Smith DMTS tsdm; 52124989b8cSPeter Brune 52224989b8cSPeter Brune PetscFunctionBegin; 52324989b8cSPeter Brune PetscValidHeaderSpecific(dm,DM_CLASSID,1); 524942e3340SBarry Smith ierr = DMGetDMTSWrite(dm,&tsdm);CHKERRQ(ierr); 525d74926cbSBarry Smith if (func) tsdm->ops->rhsjacobian = func; 52624989b8cSPeter Brune if (ctx) tsdm->rhsjacobianctx = ctx; 52724989b8cSPeter Brune PetscFunctionReturn(0); 52824989b8cSPeter Brune } 52924989b8cSPeter Brune 53024989b8cSPeter Brune #undef __FUNCT__ 53124989b8cSPeter Brune #define __FUNCT__ "DMTSGetRHSJacobian" 53224989b8cSPeter Brune /*@C 53324989b8cSPeter Brune DMTSGetRHSJacobian - get TS Jacobian evaluation function 53424989b8cSPeter Brune 53524989b8cSPeter Brune Not Collective 53624989b8cSPeter Brune 53724989b8cSPeter Brune Input Argument: 53824989b8cSPeter Brune . dm - DM to be used with TS 53924989b8cSPeter Brune 54024989b8cSPeter Brune Output Arguments: 54124989b8cSPeter Brune + func - Jacobian evaluation function, see TSSetRHSJacobian() for calling sequence 54224989b8cSPeter Brune - ctx - context for residual evaluation 54324989b8cSPeter Brune 54424989b8cSPeter Brune Level: advanced 54524989b8cSPeter Brune 54624989b8cSPeter Brune Note: 54724989b8cSPeter Brune TSGetJacobian() is normally used, but it calls this function internally because the user context is actually 54824989b8cSPeter Brune associated with the DM. This makes the interface consistent regardless of whether the user interacts with a DM or 54924989b8cSPeter Brune not. If DM took a more central role at some later date, this could become the primary method of setting the Jacobian. 55024989b8cSPeter Brune 55124989b8cSPeter Brune .seealso: DMTSSetContext(), TSSetFunction(), DMTSSetJacobian() 55224989b8cSPeter Brune @*/ 55324989b8cSPeter Brune PetscErrorCode DMTSGetRHSJacobian(DM dm,TSRHSJacobian *func,void **ctx) 55424989b8cSPeter Brune { 55524989b8cSPeter Brune PetscErrorCode ierr; 556942e3340SBarry Smith DMTS tsdm; 55724989b8cSPeter Brune 55824989b8cSPeter Brune PetscFunctionBegin; 55924989b8cSPeter Brune PetscValidHeaderSpecific(dm,DM_CLASSID,1); 560942e3340SBarry Smith ierr = DMGetDMTS(dm,&tsdm);CHKERRQ(ierr); 561d74926cbSBarry Smith if (func) *func = tsdm->ops->rhsjacobian; 56224989b8cSPeter Brune if (ctx) *ctx = tsdm->rhsjacobianctx; 56324989b8cSPeter Brune PetscFunctionReturn(0); 56424989b8cSPeter Brune } 565