# TSSetSolutionFunction
Provide a function that computes the solution of the ODE or DAE 
## Synopsis
```
#include "petscts.h"  
PetscErrorCode TSSetSolutionFunction(TS ts, PetscErrorCode (*f)(TS, PetscReal, Vec, void *), void *ctx)
```
Logically Collective on ts


## Input Parameters

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



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


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



## Options Database Keys

- ***-ts_monitor_lg_error -*** create a graphical monitor of error history, requires user to have provided `TSSetSolutionFunction()`
- ***-ts_monitor_draw_error -*** Monitor error graphically, requires user to have provided `TSSetSolutionFunction()`





## Notes
This routine is used for testing accuracy of time integration schemes when you already know the solution.
If analytic solutions are not known for your system, consider using the Method of Manufactured Solutions to
create closed-form solutions with non-physical forcing terms.

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()`, `TSSetForcingFunction()`, `TSSetSolution()`, `TSGetSolution()`, `TSMonitorLGError()`, `TSMonitorDrawError()`

## Level
intermediate

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

## Examples
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/ts/tutorials/ex43.c.html">src/ts/tutorials/ex43.c.html</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/ts/tutorials/ex50.c.html">src/ts/tutorials/ex50.c.html</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/tao/unconstrained/tutorials/spectraladjointassimilation.c.html">src/tao/unconstrained/tutorials/spectraladjointassimilation.c.html</A><BR>


---
[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)  
