/*@C DMTSSetRHSJacobian - set TS Jacobian evaluation function Not Collective Input Argument: + dm - DM to be used with TS . func - Jacobian evaluation function, see TSSetRHSJacobian() for calling sequence - ctx - context for residual evaluation Level: advanced Note: TSSetJacobian() is normally used, but it calls this function internally because the user context is actually associated with the DM. This makes the interface consistent regardless of whether the user interacts with a DM or not. If DM took a more central role at some later date, this could become the primary method of setting the Jacobian. .seealso: DMTSSetContext(), TSSetFunction(), DMTSGetJacobian(), TSSetJacobian() @*/ PetscErrorCode DMTSSetRHSJacobian(DM dm,TSRHSJacobian func,void *ctx) { PetscErrorCode ierr; DMTS tsdm; PetscFunctionBegin; PetscValidHeaderSpecific(dm,DM_CLASSID,1); ierr = DMGetDMTSWrite(dm,&tsdm);CHKERRQ(ierr); if (func) tsdm->ops->rhsjacobian = func; if (ctx) tsdm->rhsjacobianctx = ctx; PetscFunctionReturn(0); }
/*@C DMTSSetIJacobianSerialize - sets functions used to view and load a IJacobian context Not Collective Input Arguments: + dm - DM to be used with TS . view - viewer function - load - loading function Level: advanced .seealso: DMTSSetContext(), TSSetFunction(), DMTSSetJacobian() @*/ PetscErrorCode DMTSSetIJacobianSerialize(DM dm,PetscErrorCode (*view)(void*,PetscViewer),PetscErrorCode (*load)(void**,PetscViewer)) { PetscErrorCode ierr; DMTS tsdm; PetscFunctionBegin; PetscValidHeaderSpecific(dm,DM_CLASSID,1); ierr = DMGetDMTSWrite(dm,&tsdm);CHKERRQ(ierr); tsdm->ops->ijacobianview = view; tsdm->ops->ijacobianload = load; PetscFunctionReturn(0); }
/*@C DMTSSetI2Jacobian - set TS implicit Jacobian evaluation function for 2nd order systems Not Collective Input Arguments: + dm - DM to be used with TS . fun - Jacobian evaluation function, see TSSetI2Jacobian() for calling sequence - ctx - context for Jacobian evaluation Level: advanced Note: TSSetI2Jacobian() is normally used, but it calls this function internally because the user context is actually associated with the DM. .seealso: TSSetI2Jacobian() @*/ PetscErrorCode DMTSSetI2Jacobian(DM dm,TSI2Jacobian jac,void *ctx) { DMTS tsdm; PetscErrorCode ierr; PetscFunctionBegin; PetscValidHeaderSpecific(dm,DM_CLASSID,1); ierr = DMGetDMTSWrite(dm,&tsdm);CHKERRQ(ierr); if (jac) tsdm->ops->i2jacobian = jac; if (ctx) tsdm->i2jacobianctx = ctx; PetscFunctionReturn(0); }
/*@C DMTSGetForcingFunction - get TS forcing function evaluation function Not Collective Input Argument: . dm - DM to be used with TS Output Arguments: + f - forcing function evaluation function; see TSForcingFunction for details - ctx - context for solution evaluation Level: advanced Note: TSSetForcingFunction() is normally used, but it calls this function internally because the user context is actually associated with the DM. This makes the interface consistent regardless of whether the user interacts with a DM or not. If DM took a more central role at some later date, this could become the primary method of setting the residual. .seealso: DMTSSetContext(), TSSetFunction(), DMTSSetJacobian(), TSSetForcingFunction(), DMTSGetForcingFunction() @*/ PetscErrorCode DMTSGetForcingFunction(DM dm,TSForcingFunction *f,void **ctx) { PetscErrorCode ierr; DMTS tsdm; PetscFunctionBegin; PetscValidHeaderSpecific(dm,DM_CLASSID,1); ierr = DMGetDMTSWrite(dm,&tsdm);CHKERRQ(ierr); if (f) *f = tsdm->ops->forcing; if (ctx) *ctx = tsdm->forcingctx; PetscFunctionReturn(0); }
/*@C DMTSSetI2Function - set TS implicit function evaluation function for 2nd order systems Not Collective Input Arguments: + dm - DM to be used with TS . fun - function evaluation function, see TSSetI2Function() for calling sequence - ctx - context for residual evaluation Level: advanced Note: TSSetI2Function() is normally used, but it calls this function internally because the user context is actually associated with the DM. .seealso: TSSetI2Function() @*/ PetscErrorCode DMTSSetI2Function(DM dm,TSI2Function fun,void *ctx) { DMTS tsdm; PetscErrorCode ierr; PetscFunctionBegin; PetscValidHeaderSpecific(dm,DM_CLASSID,1); ierr = DMGetDMTSWrite(dm,&tsdm);CHKERRQ(ierr); if (fun) tsdm->ops->i2function = fun; if (ctx) tsdm->i2functionctx = ctx; PetscFunctionReturn(0); }
/*@C DMTSSetForcingFunction - set TS forcing function evaluation function Not Collective Input Arguments: + dm - DM to be used with TS . TSForcingFunction - forcing function evaluation function - ctx - context for solution evaluation Level: advanced Note: TSSetForcingFunction() is normally used, but it calls this function internally because the user context is actually associated with the DM. This makes the interface consistent regardless of whether the user interacts with a DM or not. If DM took a more central role at some later date, this could become the primary method of setting the residual. .seealso: DMTSSetContext(), TSSetFunction(), DMTSSetJacobian(), TSSetForcingFunction(), DMTSGetForcingFunction() @*/ PetscErrorCode DMTSSetForcingFunction(DM dm,PetscErrorCode (*TSForcingFunction)(TS,PetscReal,Vec,void*),void *ctx) { PetscErrorCode ierr; DMTS tsdm; PetscFunctionBegin; PetscValidHeaderSpecific(dm,DM_CLASSID,1); ierr = DMGetDMTSWrite(dm,&tsdm);CHKERRQ(ierr); if (TSForcingFunction) tsdm->ops->forcing = TSForcingFunction; if (ctx) tsdm->forcingctx = ctx; PetscFunctionReturn(0); }
/*@C DMDATSSetIJacobianLocal - set a local residual evaluation function Logically Collective Input Arguments: + dm - DM to associate callback with . func - local residual evaluation - ctx - optional context for local residual evaluation Calling sequence for func: $ func(DMDALocalInfo* info,PetscReal t,void* x,void *xdot,Mat J,Mat B,MatStructure *flg,void *ctx); + info - DMDALocalInfo defining the subdomain to evaluate the residual on . t - time at which to evaluate the jacobian . x - array of local state information . xdot - time derivative at this state . J - Jacobian matrix . B - preconditioner matrix; often same as J . flg - flag indicating information about the preconditioner matrix structure (same as flag in KSPSetOperators()) - ctx - optional context passed above Level: beginner .seealso: DMTSSetJacobian(), DMDATSSetIFunctionLocal(), DMDASNESSetJacobianLocal() @*/ PetscErrorCode DMDATSSetIJacobianLocal(DM dm,DMDATSIJacobianLocal func,void *ctx) { PetscErrorCode ierr; DMTS sdm; DMTS_DA *dmdats; PetscFunctionBegin; PetscValidHeaderSpecific(dm,DM_CLASSID,1); ierr = DMGetDMTSWrite(dm,&sdm);CHKERRQ(ierr); ierr = DMDATSGetContext(dm,sdm,&dmdats);CHKERRQ(ierr); dmdats->ijacobianlocal = func; dmdats->ijacobianlocalctx = ctx; ierr = DMTSSetIJacobian(dm,TSComputeIJacobian_DMDA,dmdats);CHKERRQ(ierr); PetscFunctionReturn(0); }
/*@C DMDATSSetRHSFunctionLocal - set a local residual evaluation function Logically Collective Input Arguments: + dm - DM to associate callback with . imode - insert mode for the residual . func - local residual evaluation - ctx - optional context for local residual evaluation Calling sequence for func: $ func(DMDALocalInfo info,PetscReal t,void *x,void *f,void *ctx) + info - DMDALocalInfo defining the subdomain to evaluate the residual on . t - time at which to evaluate residual . x - array of local state information . f - output array of local residual information - ctx - optional user context Level: beginner .seealso: DMTSSetRHSFunction(), DMDATSSetRHSJacobianLocal(), DMDASNESSetFunctionLocal() @*/ PetscErrorCode DMDATSSetRHSFunctionLocal(DM dm,InsertMode imode,DMDATSRHSFunctionLocal func,void *ctx) { PetscErrorCode ierr; DMTS sdm; DMTS_DA *dmdats; PetscFunctionBegin; PetscValidHeaderSpecific(dm,DM_CLASSID,1); ierr = DMGetDMTSWrite(dm,&sdm);CHKERRQ(ierr); ierr = DMDATSGetContext(dm,sdm,&dmdats);CHKERRQ(ierr); dmdats->rhsfunctionlocalimode = imode; dmdats->rhsfunctionlocal = func; dmdats->rhsfunctionlocalctx = ctx; ierr = DMTSSetRHSFunction(dm,TSComputeRHSFunction_DMDA,dmdats);CHKERRQ(ierr); PetscFunctionReturn(0); }
/*@C DMPlexTSSetRHSFunctionLocal - set a local residual evaluation function Logically Collective Input Arguments: + dm - DM to associate callback with . riemann - Riemann solver - ctx - optional context for Riemann solve Calling sequence for riemann: $ riemann(const PetscReal x[], const PetscReal n[], const PetscScalar uL[], const PetscScalar uR[], PetscScalar flux[], void *ctx) + x - The coordinates at a point on the interface . n - The normal vector to the interface . uL - The state vector to the left of the interface . uR - The state vector to the right of the interface . flux - output array of flux through the interface - ctx - optional user context Level: beginner .seealso: DMTSSetRHSFunctionLocal() @*/ PetscErrorCode DMPlexTSSetRHSFunctionLocal(DM dm, void (*riemann)(const PetscReal x[], const PetscReal n[], const PetscScalar uL[], const PetscScalar uR[], PetscScalar flux[], void *ctx), void *ctx) { DMTS dmts; DMTS_Plex *dmplexts; PetscFV fvm; PetscInt Nf; PetscBool computeGradients; PetscErrorCode ierr; PetscFunctionBegin; PetscValidHeaderSpecific(dm, DM_CLASSID, 1); ierr = DMGetDMTSWrite(dm, &dmts);CHKERRQ(ierr); ierr = DMPlexTSGetContext(dm, dmts, &dmplexts);CHKERRQ(ierr); dmplexts->riemann = riemann; dmplexts->rhsfunctionlocalctx = ctx; ierr = DMGetNumFields(dm, &Nf);CHKERRQ(ierr); ierr = DMGetField(dm, 0, (PetscObject *) &fvm);CHKERRQ(ierr); ierr = DMPlexTSSetupGeometry(dm, fvm, dmplexts);CHKERRQ(ierr); ierr = PetscFVGetComputeGradients(fvm, &computeGradients);CHKERRQ(ierr); if (computeGradients) {ierr = DMPlexTSSetupGradient(dm, fvm, dmplexts);CHKERRQ(ierr);} ierr = DMTSSetRHSFunction(dm, TSComputeRHSFunction_DMPlex, dmplexts);CHKERRQ(ierr); PetscFunctionReturn(0); }