:orphan:
# DMRefineHookAdd
adds a callback to be run when interpolating a nonlinear problem to a finer grid 
## Synopsis
```
#include "petscdm.h"          
#include "petscdmlabel.h"     
#include "petscds.h"     
PetscErrorCode DMRefineHookAdd(DM coarse, PetscErrorCode (*refinehook)(DM, DM, void *), PetscErrorCode (*interphook)(DM, Mat, DM, void *), void *ctx)
```
Logically Collective; No Fortran Support


## Input Parameters

- ***coarse -*** `DM` on which to run a hook when interpolating to a finer level
- ***refinehook -*** function to run when setting up the finer level
- ***interphook -*** function to run to update data on finer levels (once per `SNESSolve()`)
- ***ctx -*** [optional] user-defined context for provide data for the hooks (may be `NULL`)



## Calling sequence of `refinehook`
```none
PetscErrorCode refinehook(DM coarse, DM fine, void *ctx);
```

- ***coarse -*** coarse level `DM`
- ***fine -*** fine level `DM` to interpolate problem to
- ***ctx -*** optional user-defined function context



## Calling sequence of `interphook`
```none
PetscErrorCode interphook(DM coarse, Mat interp, DM fine, void *ctx)
```

- ***coarse -*** coarse level `DM`
- ***interp -*** matrix interpolating a coarse-level solution to the finer grid
- ***fine -*** fine level `DM` to update
- ***ctx -*** optional user-defined function context





## Notes
This function is only needed if auxiliary data that is attached to the `DM`s via, for example, `PetscObjectCompose()`, needs to be
passed to fine grids while grid sequencing.

The actual interpolation is done when `DMInterpolate()` is called.

If this function is called multiple times, the hooks will be run in the order they are added.


## See Also
 [](ch_dmbase), `DM`, `DMCoarsenHookAdd()`, `DMInterpolate()`, `SNESFASGetInterpolation()`, `SNESFASGetInjection()`, `PetscObjectCompose()`, `PetscContainerCreate()`

## Level
advanced

## Location
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/dm/interface/dm.c.html#DMRefineHookAdd">src/dm/interface/dm.c</A>

## Examples
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/snes/tutorials/ex48.c.html">src/snes/tutorials/ex48.c</A><BR>


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


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