:orphan:
# TSSetPreStage
Sets the general-purpose function called once at the beginning of each stage. 
## Synopsis
```
#include "petscts.h"  
PetscErrorCode TSSetPreStage(TS ts, PetscErrorCode (*func)(TS, PetscReal))
```
Logically Collective


## Input Parameters

- ***ts   -*** The `TS` context obtained from `TSCreate()`
- ***func -*** The function



## Calling sequence of `func`
```none
  PetscErrorCode func(TS ts, PetscReal stagetime)
```





## Note
There may be several stages per time step. If the solve for a given stage fails, the step may be rejected and retried.
The time step number being computed can be queried using `TSGetStepNumber()` and the total size of the step being
attempted can be obtained using `TSGetTimeStep()`. The time at the start of the step is available via `TSGetTime()`.


## See Also
 [](ch_ts), `TS`, `TSSetPostStage()`, `TSSetPreStep()`, `TSSetPostStep()`, `TSGetApplicationContext()`

## Level
intermediate

## Location
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/ts/interface/ts.c.html#TSSetPreStage">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](/manualpages/index.md)  
[Index of all manual pages](/manualpages/singleindex.md)  
