# TSSetForcingFunction
Provide a function that computes a forcing term for a ODE or PDE 
## Synopsis
```
#include "petscts.h"  
PetscErrorCode TSSetForcingFunction(TS ts, TSForcingFunction func, void *ctx)
```
Logically Collective on ts


## Input Parameters

- ***ts -*** the `TS` context obtained from `TSCreate()`
- ***func -*** routine for evaluating the forcing function
- ***ctx -*** [optional] user-defined context for private data for the
function evaluation routine (may be NULL)



## Calling sequence of func
```none
PetscErrorCode func (TS ts,PetscReal t,Vec f,void *ctx);
```


- ***t -*** current timestep
- ***f -*** output vector
- ***ctx -*** [optional] user-defined function context





## Notes
This routine is useful for testing accuracy of time integration schemes when using the Method of Manufactured Solutions to
create closed-form solutions with a non-physical forcing term. It allows you to use the Method of Manufactored Solution without directly editing the
definition of the problem you are solving and hence possibly introducing bugs.

This replaces the ODE F(u,u_t,t) = 0 the TS is solving with F(u,u_t,t) - func(t) = 0

This forcing function does not depend on the solution to the equations, it can only depend on spatial location, time, and possibly parameters, the
parameters can be passed in the ctx variable.

For low-dimensional problems solved in serial, such as small discrete systems, `TSMonitorLGError()` can be used to monitor the error history.


## See Also
 [](chapter_ts), `TS`, `TSSetRHSJacobian()`, `TSSetIJacobian()`, `TSComputeSolutionFunction()`, `TSSetSolutionFunction()`

## Level
intermediate

## Location
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/ts/interface/ts.c.html#TSSetForcingFunction">src/ts/interface/ts.c</A>


---
[Edit on GitLab](https://gitlab.com/petsc/petsc/-/edit/release/src/ts/interface/ts.c)


[Index of all TS routines](index.md)  
[Table of Contents for all manual pages](/docs/manualpages/index.md)  
[Index of all manual pages](/docs/manualpages/singleindex.md)  
