# PetscObjectCompose
Associates another PETSc object with a given PETSc object. 
## Synopsis
```
#include "petscsys.h"    
PetscErrorCode PetscObjectCompose(PetscObject obj, const char name[], PetscObject ptr)
```
Not Collective


## Input Parameters

- ***obj -*** the PETSc object; this must be cast with (`PetscObject`), for example,
`PetscObjectCompose`((`PetscObject`)mat,...);
- ***name -*** name associated with the child object
- ***ptr -*** the other PETSc object to associate with the PETSc object; this must also be
cast with (`PetscObject`)





## Notes
The second objects reference count is automatically increased by one when it is
composed.

Replaces any previous object that had the same name.

If ptr is null and name has previously been composed using an object, then that
entry is removed from the obj.

`PetscObjectCompose()` can be used with any PETSc object (such as
`Mat`, `Vec`, `KSP`, `SNES`, etc.) or any user-provided object.

`PetscContainerCreate()` can be used to create an object from a
user-provided pointer that may then be composed with PETSc objects using `PetscObjectCompose()`


## See Also
 `PetscObjectQuery()`, `PetscContainerCreate()`, `PetscObjectComposeFunction()`, `PetscObjectQueryFunction()`, `PetscContainer`,
`PetscContainerSetPointer()`

## Level
advanced

## Location
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/sys/objects/inherit.c.html#PetscObjectCompose">src/sys/objects/inherit.c</A>

## Examples
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/ksp/ksp/tutorials/ex73.c.html">src/ksp/ksp/tutorials/ex73.c.html</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/snes/tutorials/ex48.c.html">src/snes/tutorials/ex48.c.html</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/snes/tutorials/ex56.c.html">src/snes/tutorials/ex56.c.html</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/snes/tutorials/ex62.c.html">src/snes/tutorials/ex62.c.html</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/snes/tutorials/ex63.c.html">src/snes/tutorials/ex63.c.html</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/snes/tutorials/ex69.c.html">src/snes/tutorials/ex69.c.html</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/snes/tutorials/ex77.c.html">src/snes/tutorials/ex77.c.html</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/ts/tutorials/ex29.c.html">src/ts/tutorials/ex29.c.html</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/ts/tutorials/ex46.c.html">src/ts/tutorials/ex46.c.html</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/ts/tutorials/ex76.c.html">src/ts/tutorials/ex76.c.html</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/ts/tutorials/ex77.c.html">src/ts/tutorials/ex77.c.html</A><BR>


---
[Edit on GitLab](https://gitlab.com/petsc/petsc/-/edit/release/src/sys/objects/inherit.c)


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