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 29b4615a05SBarry 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" 36*2a34c10cSBarry Smith /* Attaches the DMTS 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); 134*2a34c10cSBarry Smith *tsdm = (DMTS) dm->dmts; 135d74926cbSBarry Smith if (!*tsdm) { 136942e3340SBarry Smith ierr = PetscInfo(dm,"Creating new DMTS\n");CHKERRQ(ierr); 137d74926cbSBarry Smith ierr = DMTSCreate(((PetscObject)dm)->comm,tsdm);CHKERRQ(ierr); 138*2a34c10cSBarry Smith dm->dmts = (PetscObject) *tsdm; 139942e3340SBarry Smith ierr = DMCoarsenHookAdd(dm,DMCoarsenHook_DMTS,DMRestrictHook_DMTS,PETSC_NULL);CHKERRQ(ierr); 14024989b8cSPeter Brune } 14124989b8cSPeter Brune PetscFunctionReturn(0); 14224989b8cSPeter Brune } 14324989b8cSPeter Brune 14424989b8cSPeter Brune #undef __FUNCT__ 145942e3340SBarry Smith #define __FUNCT__ "DMGetDMTSWrite" 14624989b8cSPeter Brune /*@C 147942e3340SBarry Smith DMGetDMTSWrite - get write access to private DMTS context from a DM 14824989b8cSPeter Brune 14924989b8cSPeter Brune Not Collective 15024989b8cSPeter Brune 15124989b8cSPeter Brune Input Argument: 15224989b8cSPeter Brune . dm - DM to be used with TS 15324989b8cSPeter Brune 15424989b8cSPeter Brune Output Argument: 155942e3340SBarry Smith . tsdm - private DMTS context 15624989b8cSPeter Brune 15724989b8cSPeter Brune Level: developer 15824989b8cSPeter Brune 159942e3340SBarry Smith .seealso: DMGetDMTS() 16024989b8cSPeter Brune @*/ 161942e3340SBarry Smith PetscErrorCode DMGetDMTSWrite(DM dm,DMTS *tsdm) 16224989b8cSPeter Brune { 16324989b8cSPeter Brune PetscErrorCode ierr; 164942e3340SBarry Smith DMTS sdm; 16524989b8cSPeter Brune 16624989b8cSPeter Brune PetscFunctionBegin; 16724989b8cSPeter Brune PetscValidHeaderSpecific(dm,DM_CLASSID,1); 168942e3340SBarry Smith ierr = DMGetDMTS(dm,&sdm);CHKERRQ(ierr); 16924989b8cSPeter Brune if (!sdm->originaldm) sdm->originaldm = dm; 17024989b8cSPeter Brune if (sdm->originaldm != dm) { /* Copy on write */ 171*2a34c10cSBarry Smith DMTS oldsdm = sdm; 172942e3340SBarry Smith ierr = PetscInfo(dm,"Copying DMTS due to write\n");CHKERRQ(ierr); 173d74926cbSBarry Smith ierr = DMTSCreate(((PetscObject)dm)->comm,&sdm);CHKERRQ(ierr); 174d74926cbSBarry Smith ierr = DMTSCopy(oldsdm,sdm);CHKERRQ(ierr); 175*2a34c10cSBarry Smith ierr = DMTSDestroy((DMTS*)&dm->dmts);CHKERRQ(ierr); 176*2a34c10cSBarry Smith dm->dmts = (PetscObject) sdm; 17724989b8cSPeter Brune } 17824989b8cSPeter Brune *tsdm = sdm; 17924989b8cSPeter Brune PetscFunctionReturn(0); 18024989b8cSPeter Brune } 18124989b8cSPeter Brune 18224989b8cSPeter Brune #undef __FUNCT__ 183942e3340SBarry Smith #define __FUNCT__ "DMCopyDMTS" 18424989b8cSPeter Brune /*@C 185942e3340SBarry Smith DMCopyDMTS - copies a DM context to a new DM 18624989b8cSPeter Brune 18724989b8cSPeter Brune Logically Collective 18824989b8cSPeter Brune 18924989b8cSPeter Brune Input Arguments: 19024989b8cSPeter Brune + dmsrc - DM to obtain context from 19124989b8cSPeter Brune - dmdest - DM to add context to 19224989b8cSPeter Brune 19324989b8cSPeter Brune Level: developer 19424989b8cSPeter Brune 19524989b8cSPeter Brune Note: 19624989b8cSPeter Brune The context is copied by reference. This function does not ensure that a context exists. 19724989b8cSPeter Brune 198942e3340SBarry Smith .seealso: DMGetDMTS(), TSSetDM() 19924989b8cSPeter Brune @*/ 200942e3340SBarry Smith PetscErrorCode DMCopyDMTS(DM dmsrc,DM dmdest) 20124989b8cSPeter Brune { 20224989b8cSPeter Brune PetscErrorCode ierr; 20324989b8cSPeter Brune 20424989b8cSPeter Brune PetscFunctionBegin; 20524989b8cSPeter Brune PetscValidHeaderSpecific(dmsrc,DM_CLASSID,1); 20624989b8cSPeter Brune PetscValidHeaderSpecific(dmdest,DM_CLASSID,2); 207*2a34c10cSBarry Smith ierr = DMTSDestroy((DMTS*)&dmdest->dmts);CHKERRQ(ierr); 208*2a34c10cSBarry Smith dmdest->dmts = dmsrc->dmts; 209*2a34c10cSBarry Smith ierr = PetscObjectReference(dmdest->dmts);CHKERRQ(ierr); 210942e3340SBarry Smith ierr = DMCoarsenHookAdd(dmdest,DMCoarsenHook_DMTS,DMRestrictHook_DMTS,PETSC_NULL);CHKERRQ(ierr); 21124989b8cSPeter Brune PetscFunctionReturn(0); 21224989b8cSPeter Brune } 21324989b8cSPeter Brune 21424989b8cSPeter Brune #undef __FUNCT__ 21524989b8cSPeter Brune #define __FUNCT__ "DMTSSetIFunction" 21624989b8cSPeter Brune /*@C 21724989b8cSPeter Brune DMTSSetIFunction - set TS implicit function evaluation function 21824989b8cSPeter Brune 21924989b8cSPeter Brune Not Collective 22024989b8cSPeter Brune 22124989b8cSPeter Brune Input Arguments: 22224989b8cSPeter Brune + dm - DM to be used with TS 22324989b8cSPeter Brune . func - function evaluation function, see TSSetIFunction() for calling sequence 22424989b8cSPeter Brune - ctx - context for residual evaluation 22524989b8cSPeter Brune 22624989b8cSPeter Brune Level: advanced 22724989b8cSPeter Brune 22824989b8cSPeter Brune Note: 22924989b8cSPeter Brune TSSetFunction() is normally used, but it calls this function internally because the user context is actually 23024989b8cSPeter Brune associated with the DM. This makes the interface consistent regardless of whether the user interacts with a DM or 23124989b8cSPeter Brune not. If DM took a more central role at some later date, this could become the primary method of setting the residual. 23224989b8cSPeter Brune 23324989b8cSPeter Brune .seealso: DMTSSetContext(), TSSetFunction(), DMTSSetJacobian() 23424989b8cSPeter Brune @*/ 23524989b8cSPeter Brune PetscErrorCode DMTSSetIFunction(DM dm,TSIFunction func,void *ctx) 23624989b8cSPeter Brune { 23724989b8cSPeter Brune PetscErrorCode ierr; 238942e3340SBarry Smith DMTS tsdm; 23924989b8cSPeter Brune 24024989b8cSPeter Brune PetscFunctionBegin; 24124989b8cSPeter Brune PetscValidHeaderSpecific(dm,DM_CLASSID,1); 242942e3340SBarry Smith ierr = DMGetDMTSWrite(dm,&tsdm);CHKERRQ(ierr); 243d74926cbSBarry Smith if (func) tsdm->ops->ifunction = func; 24424989b8cSPeter Brune if (ctx) tsdm->ifunctionctx = ctx; 24524989b8cSPeter Brune PetscFunctionReturn(0); 24624989b8cSPeter Brune } 24724989b8cSPeter Brune 24824989b8cSPeter Brune #undef __FUNCT__ 24924989b8cSPeter Brune #define __FUNCT__ "DMTSGetIFunction" 25024989b8cSPeter Brune /*@C 25124989b8cSPeter Brune DMTSGetIFunction - get TS implicit residual evaluation function 25224989b8cSPeter Brune 25324989b8cSPeter Brune Not Collective 25424989b8cSPeter Brune 25524989b8cSPeter Brune Input Argument: 25624989b8cSPeter Brune . dm - DM to be used with TS 25724989b8cSPeter Brune 25824989b8cSPeter Brune Output Arguments: 25924989b8cSPeter Brune + func - function evaluation function, see TSSetIFunction() for calling sequence 26024989b8cSPeter Brune - ctx - context for residual evaluation 26124989b8cSPeter Brune 26224989b8cSPeter Brune Level: advanced 26324989b8cSPeter Brune 26424989b8cSPeter Brune Note: 26524989b8cSPeter Brune TSGetFunction() is normally used, but it calls this function internally because the user context is actually 26624989b8cSPeter Brune associated with the DM. 26724989b8cSPeter Brune 26824989b8cSPeter Brune .seealso: DMTSSetContext(), DMTSSetFunction(), TSSetFunction() 26924989b8cSPeter Brune @*/ 27024989b8cSPeter Brune PetscErrorCode DMTSGetIFunction(DM dm,TSIFunction *func,void **ctx) 27124989b8cSPeter Brune { 27224989b8cSPeter Brune PetscErrorCode ierr; 273942e3340SBarry Smith DMTS tsdm; 27424989b8cSPeter Brune 27524989b8cSPeter Brune PetscFunctionBegin; 27624989b8cSPeter Brune PetscValidHeaderSpecific(dm,DM_CLASSID,1); 277942e3340SBarry Smith ierr = DMGetDMTS(dm,&tsdm);CHKERRQ(ierr); 278d74926cbSBarry Smith if (func) *func = tsdm->ops->ifunction; 27924989b8cSPeter Brune if (ctx) *ctx = tsdm->ifunctionctx; 28024989b8cSPeter Brune PetscFunctionReturn(0); 28124989b8cSPeter Brune } 28224989b8cSPeter Brune 28324989b8cSPeter Brune 28424989b8cSPeter Brune #undef __FUNCT__ 28524989b8cSPeter Brune #define __FUNCT__ "DMTSSetRHSFunction" 28624989b8cSPeter Brune /*@C 28724989b8cSPeter Brune DMTSSetRHSFunction - set TS explicit residual evaluation function 28824989b8cSPeter Brune 28924989b8cSPeter Brune Not Collective 29024989b8cSPeter Brune 29124989b8cSPeter Brune Input Arguments: 29224989b8cSPeter Brune + dm - DM to be used with TS 29324989b8cSPeter Brune . func - RHS function evaluation function, see TSSetRHSFunction() for calling sequence 29424989b8cSPeter Brune - ctx - context for residual evaluation 29524989b8cSPeter Brune 29624989b8cSPeter Brune Level: advanced 29724989b8cSPeter Brune 29824989b8cSPeter Brune Note: 299ef20d060SBarry Smith TSSetRSHFunction() is normally used, but it calls this function internally because the user context is actually 30024989b8cSPeter Brune associated with the DM. This makes the interface consistent regardless of whether the user interacts with a DM or 30124989b8cSPeter Brune not. If DM took a more central role at some later date, this could become the primary method of setting the residual. 30224989b8cSPeter Brune 30324989b8cSPeter Brune .seealso: DMTSSetContext(), TSSetFunction(), DMTSSetJacobian() 30424989b8cSPeter Brune @*/ 30524989b8cSPeter Brune PetscErrorCode DMTSSetRHSFunction(DM dm,TSRHSFunction func,void *ctx) 30624989b8cSPeter Brune { 30724989b8cSPeter Brune PetscErrorCode ierr; 308942e3340SBarry Smith DMTS tsdm; 30924989b8cSPeter Brune 31024989b8cSPeter Brune PetscFunctionBegin; 31124989b8cSPeter Brune PetscValidHeaderSpecific(dm,DM_CLASSID,1); 312942e3340SBarry Smith ierr = DMGetDMTSWrite(dm,&tsdm);CHKERRQ(ierr); 313d74926cbSBarry Smith if (func) tsdm->ops->rhsfunction = func; 31424989b8cSPeter Brune if (ctx) tsdm->rhsfunctionctx = ctx; 31524989b8cSPeter Brune PetscFunctionReturn(0); 31624989b8cSPeter Brune } 31724989b8cSPeter Brune 31824989b8cSPeter Brune #undef __FUNCT__ 319ef20d060SBarry Smith #define __FUNCT__ "DMTSGetSolutionFunction" 320ef20d060SBarry Smith /*@C 321ef20d060SBarry Smith DMTSGetSolutionFunction - gets the TS solution evaluation function 322ef20d060SBarry Smith 323ef20d060SBarry Smith Not Collective 324ef20d060SBarry Smith 325ef20d060SBarry Smith Input Arguments: 326ef20d060SBarry Smith . dm - DM to be used with TS 327ef20d060SBarry Smith 328ef20d060SBarry Smith Output Parameters: 329ef20d060SBarry Smith + func - solution function evaluation function, see TSSetSolution() for calling sequence 330ef20d060SBarry Smith - ctx - context for solution evaluation 331ef20d060SBarry Smith 332ef20d060SBarry Smith Level: advanced 333ef20d060SBarry Smith 334ef20d060SBarry Smith .seealso: DMTSSetContext(), TSSetFunction(), DMTSSetJacobian() 335ef20d060SBarry Smith @*/ 336ef20d060SBarry Smith PetscErrorCode DMTSGetSolutionFunction(DM dm,TSSolutionFunction *func,void **ctx) 337ef20d060SBarry Smith { 338ef20d060SBarry Smith PetscErrorCode ierr; 339942e3340SBarry Smith DMTS tsdm; 340ef20d060SBarry Smith 341ef20d060SBarry Smith PetscFunctionBegin; 342ef20d060SBarry Smith PetscValidHeaderSpecific(dm,DM_CLASSID,1); 343942e3340SBarry Smith ierr = DMGetDMTS(dm,&tsdm);CHKERRQ(ierr); 344d74926cbSBarry Smith if (func) *func = tsdm->ops->solution; 345ef20d060SBarry Smith if (ctx) *ctx = tsdm->solutionctx; 346ef20d060SBarry Smith PetscFunctionReturn(0); 347ef20d060SBarry Smith } 348ef20d060SBarry Smith 349ef20d060SBarry Smith #undef __FUNCT__ 350ef20d060SBarry Smith #define __FUNCT__ "DMTSSetSolutionFunction" 351ef20d060SBarry Smith /*@C 352ef20d060SBarry Smith DMTSSetSolutionFunction - set TS solution evaluation function 353ef20d060SBarry Smith 354ef20d060SBarry Smith Not Collective 355ef20d060SBarry Smith 356ef20d060SBarry Smith Input Arguments: 357ef20d060SBarry Smith + dm - DM to be used with TS 358ef20d060SBarry Smith . func - solution function evaluation function, see TSSetSolution() for calling sequence 359ef20d060SBarry Smith - ctx - context for solution evaluation 360ef20d060SBarry Smith 361ef20d060SBarry Smith Level: advanced 362ef20d060SBarry Smith 363ef20d060SBarry Smith Note: 364ef20d060SBarry Smith TSSetSolutionFunction() is normally used, but it calls this function internally because the user context is actually 365ef20d060SBarry Smith associated with the DM. This makes the interface consistent regardless of whether the user interacts with a DM or 366ef20d060SBarry Smith not. If DM took a more central role at some later date, this could become the primary method of setting the residual. 367ef20d060SBarry Smith 368ef20d060SBarry Smith .seealso: DMTSSetContext(), TSSetFunction(), DMTSSetJacobian() 369ef20d060SBarry Smith @*/ 370ef20d060SBarry Smith PetscErrorCode DMTSSetSolutionFunction(DM dm,TSSolutionFunction func,void *ctx) 371ef20d060SBarry Smith { 372ef20d060SBarry Smith PetscErrorCode ierr; 373942e3340SBarry Smith DMTS tsdm; 374ef20d060SBarry Smith 375ef20d060SBarry Smith PetscFunctionBegin; 376ef20d060SBarry Smith PetscValidHeaderSpecific(dm,DM_CLASSID,1); 377942e3340SBarry Smith ierr = DMGetDMTSWrite(dm,&tsdm);CHKERRQ(ierr); 378d74926cbSBarry Smith if (func) tsdm->ops->solution = func; 379ef20d060SBarry Smith if (ctx) tsdm->solutionctx = ctx; 380ef20d060SBarry Smith PetscFunctionReturn(0); 381ef20d060SBarry Smith } 382ef20d060SBarry Smith 383ef20d060SBarry Smith #undef __FUNCT__ 38424989b8cSPeter Brune #define __FUNCT__ "DMTSGetRHSFunction" 38524989b8cSPeter Brune /*@C 38624989b8cSPeter Brune DMTSGetRHSFunction - get TS explicit residual evaluation function 38724989b8cSPeter Brune 38824989b8cSPeter Brune Not Collective 38924989b8cSPeter Brune 39024989b8cSPeter Brune Input Argument: 39124989b8cSPeter Brune . dm - DM to be used with TS 39224989b8cSPeter Brune 39324989b8cSPeter Brune Output Arguments: 39424989b8cSPeter Brune + func - residual evaluation function, see TSSetRHSFunction() for calling sequence 39524989b8cSPeter Brune - ctx - context for residual evaluation 39624989b8cSPeter Brune 39724989b8cSPeter Brune Level: advanced 39824989b8cSPeter Brune 39924989b8cSPeter Brune Note: 40024989b8cSPeter Brune TSGetFunction() is normally used, but it calls this function internally because the user context is actually 40124989b8cSPeter Brune associated with the DM. 40224989b8cSPeter Brune 40324989b8cSPeter Brune .seealso: DMTSSetContext(), DMTSSetFunction(), TSSetFunction() 40424989b8cSPeter Brune @*/ 40524989b8cSPeter Brune PetscErrorCode DMTSGetRHSFunction(DM dm,TSRHSFunction *func,void **ctx) 40624989b8cSPeter Brune { 40724989b8cSPeter Brune PetscErrorCode ierr; 408942e3340SBarry Smith DMTS tsdm; 40924989b8cSPeter Brune 41024989b8cSPeter Brune PetscFunctionBegin; 41124989b8cSPeter Brune PetscValidHeaderSpecific(dm,DM_CLASSID,1); 412942e3340SBarry Smith ierr = DMGetDMTS(dm,&tsdm);CHKERRQ(ierr); 413d74926cbSBarry Smith if (func) *func = tsdm->ops->rhsfunction; 41424989b8cSPeter Brune if (ctx) *ctx = tsdm->rhsfunctionctx; 41524989b8cSPeter Brune PetscFunctionReturn(0); 41624989b8cSPeter Brune } 41724989b8cSPeter Brune 41824989b8cSPeter Brune #undef __FUNCT__ 41924989b8cSPeter Brune #define __FUNCT__ "DMTSSetIJacobian" 42024989b8cSPeter Brune /*@C 42124989b8cSPeter Brune DMTSSetIJacobian - set TS Jacobian evaluation function 42224989b8cSPeter Brune 42324989b8cSPeter Brune Not Collective 42424989b8cSPeter Brune 42524989b8cSPeter Brune Input Argument: 42624989b8cSPeter Brune + dm - DM to be used with TS 42724989b8cSPeter Brune . func - Jacobian evaluation function, see TSSetIJacobian() for calling sequence 42824989b8cSPeter Brune - ctx - context for residual evaluation 42924989b8cSPeter Brune 43024989b8cSPeter Brune Level: advanced 43124989b8cSPeter Brune 43224989b8cSPeter Brune Note: 43324989b8cSPeter Brune TSSetJacobian() is normally used, but it calls this function internally because the user context is actually 43424989b8cSPeter Brune associated with the DM. This makes the interface consistent regardless of whether the user interacts with a DM or 43524989b8cSPeter Brune not. If DM took a more central role at some later date, this could become the primary method of setting the Jacobian. 43624989b8cSPeter Brune 43724989b8cSPeter Brune .seealso: DMTSSetContext(), TSSetFunction(), DMTSGetJacobian(), TSSetJacobian() 43824989b8cSPeter Brune @*/ 43924989b8cSPeter Brune PetscErrorCode DMTSSetIJacobian(DM dm,TSIJacobian func,void *ctx) 44024989b8cSPeter Brune { 44124989b8cSPeter Brune PetscErrorCode ierr; 442942e3340SBarry Smith DMTS sdm; 44324989b8cSPeter Brune 44424989b8cSPeter Brune PetscFunctionBegin; 44524989b8cSPeter Brune PetscValidHeaderSpecific(dm,DM_CLASSID,1); 446942e3340SBarry Smith ierr = DMGetDMTSWrite(dm,&sdm);CHKERRQ(ierr); 447d74926cbSBarry Smith if (func) sdm->ops->ijacobian = func; 44824989b8cSPeter Brune if (ctx) sdm->ijacobianctx = ctx; 44924989b8cSPeter Brune PetscFunctionReturn(0); 45024989b8cSPeter Brune } 45124989b8cSPeter Brune 45224989b8cSPeter Brune #undef __FUNCT__ 45324989b8cSPeter Brune #define __FUNCT__ "DMTSGetIJacobian" 45424989b8cSPeter Brune /*@C 45524989b8cSPeter Brune DMTSGetIJacobian - get TS Jacobian evaluation function 45624989b8cSPeter Brune 45724989b8cSPeter Brune Not Collective 45824989b8cSPeter Brune 45924989b8cSPeter Brune Input Argument: 46024989b8cSPeter Brune . dm - DM to be used with TS 46124989b8cSPeter Brune 46224989b8cSPeter Brune Output Arguments: 46324989b8cSPeter Brune + func - Jacobian evaluation function, see TSSetIJacobian() for calling sequence 46424989b8cSPeter Brune - ctx - context for residual evaluation 46524989b8cSPeter Brune 46624989b8cSPeter Brune Level: advanced 46724989b8cSPeter Brune 46824989b8cSPeter Brune Note: 46924989b8cSPeter Brune TSGetJacobian() is normally used, but it calls this function internally because the user context is actually 47024989b8cSPeter Brune associated with the DM. This makes the interface consistent regardless of whether the user interacts with a DM or 47124989b8cSPeter Brune not. If DM took a more central role at some later date, this could become the primary method of setting the Jacobian. 47224989b8cSPeter Brune 47324989b8cSPeter Brune .seealso: DMTSSetContext(), TSSetFunction(), DMTSSetJacobian() 47424989b8cSPeter Brune @*/ 47524989b8cSPeter Brune PetscErrorCode DMTSGetIJacobian(DM dm,TSIJacobian *func,void **ctx) 47624989b8cSPeter Brune { 47724989b8cSPeter Brune PetscErrorCode ierr; 478942e3340SBarry Smith DMTS tsdm; 47924989b8cSPeter Brune 48024989b8cSPeter Brune PetscFunctionBegin; 48124989b8cSPeter Brune PetscValidHeaderSpecific(dm,DM_CLASSID,1); 482942e3340SBarry Smith ierr = DMGetDMTS(dm,&tsdm);CHKERRQ(ierr); 483d74926cbSBarry Smith if (func) *func = tsdm->ops->ijacobian; 48424989b8cSPeter Brune if (ctx) *ctx = tsdm->ijacobianctx; 48524989b8cSPeter Brune PetscFunctionReturn(0); 48624989b8cSPeter Brune } 48724989b8cSPeter Brune 48824989b8cSPeter Brune 48924989b8cSPeter Brune #undef __FUNCT__ 49024989b8cSPeter Brune #define __FUNCT__ "DMTSSetRHSJacobian" 49124989b8cSPeter Brune /*@C 49224989b8cSPeter Brune DMTSSetRHSJacobian - set TS Jacobian evaluation function 49324989b8cSPeter Brune 49424989b8cSPeter Brune Not Collective 49524989b8cSPeter Brune 49624989b8cSPeter Brune Input Argument: 49724989b8cSPeter Brune + dm - DM to be used with TS 49824989b8cSPeter Brune . func - Jacobian evaluation function, see TSSetRHSJacobian() for calling sequence 49924989b8cSPeter Brune - ctx - context for residual evaluation 50024989b8cSPeter Brune 50124989b8cSPeter Brune Level: advanced 50224989b8cSPeter Brune 50324989b8cSPeter Brune Note: 50424989b8cSPeter Brune TSSetJacobian() is normally used, but it calls this function internally because the user context is actually 50524989b8cSPeter Brune associated with the DM. This makes the interface consistent regardless of whether the user interacts with a DM or 50624989b8cSPeter Brune not. If DM took a more central role at some later date, this could become the primary method of setting the Jacobian. 50724989b8cSPeter Brune 50824989b8cSPeter Brune .seealso: DMTSSetContext(), TSSetFunction(), DMTSGetJacobian(), TSSetJacobian() 50924989b8cSPeter Brune @*/ 51024989b8cSPeter Brune PetscErrorCode DMTSSetRHSJacobian(DM dm,TSRHSJacobian func,void *ctx) 51124989b8cSPeter Brune { 51224989b8cSPeter Brune PetscErrorCode ierr; 513942e3340SBarry Smith DMTS tsdm; 51424989b8cSPeter Brune 51524989b8cSPeter Brune PetscFunctionBegin; 51624989b8cSPeter Brune PetscValidHeaderSpecific(dm,DM_CLASSID,1); 517942e3340SBarry Smith ierr = DMGetDMTSWrite(dm,&tsdm);CHKERRQ(ierr); 518d74926cbSBarry Smith if (func) tsdm->ops->rhsjacobian = func; 51924989b8cSPeter Brune if (ctx) tsdm->rhsjacobianctx = ctx; 52024989b8cSPeter Brune PetscFunctionReturn(0); 52124989b8cSPeter Brune } 52224989b8cSPeter Brune 52324989b8cSPeter Brune #undef __FUNCT__ 52424989b8cSPeter Brune #define __FUNCT__ "DMTSGetRHSJacobian" 52524989b8cSPeter Brune /*@C 52624989b8cSPeter Brune DMTSGetRHSJacobian - get TS Jacobian evaluation function 52724989b8cSPeter Brune 52824989b8cSPeter Brune Not Collective 52924989b8cSPeter Brune 53024989b8cSPeter Brune Input Argument: 53124989b8cSPeter Brune . dm - DM to be used with TS 53224989b8cSPeter Brune 53324989b8cSPeter Brune Output Arguments: 53424989b8cSPeter Brune + func - Jacobian evaluation function, see TSSetRHSJacobian() for calling sequence 53524989b8cSPeter Brune - ctx - context for residual evaluation 53624989b8cSPeter Brune 53724989b8cSPeter Brune Level: advanced 53824989b8cSPeter Brune 53924989b8cSPeter Brune Note: 54024989b8cSPeter Brune TSGetJacobian() is normally used, but it calls this function internally because the user context is actually 54124989b8cSPeter Brune associated with the DM. This makes the interface consistent regardless of whether the user interacts with a DM or 54224989b8cSPeter Brune not. If DM took a more central role at some later date, this could become the primary method of setting the Jacobian. 54324989b8cSPeter Brune 54424989b8cSPeter Brune .seealso: DMTSSetContext(), TSSetFunction(), DMTSSetJacobian() 54524989b8cSPeter Brune @*/ 54624989b8cSPeter Brune PetscErrorCode DMTSGetRHSJacobian(DM dm,TSRHSJacobian *func,void **ctx) 54724989b8cSPeter Brune { 54824989b8cSPeter Brune PetscErrorCode ierr; 549942e3340SBarry Smith DMTS tsdm; 55024989b8cSPeter Brune 55124989b8cSPeter Brune PetscFunctionBegin; 55224989b8cSPeter Brune PetscValidHeaderSpecific(dm,DM_CLASSID,1); 553942e3340SBarry Smith ierr = DMGetDMTS(dm,&tsdm);CHKERRQ(ierr); 554d74926cbSBarry Smith if (func) *func = tsdm->ops->rhsjacobian; 55524989b8cSPeter Brune if (ctx) *ctx = tsdm->rhsjacobianctx; 55624989b8cSPeter Brune PetscFunctionReturn(0); 55724989b8cSPeter Brune } 558