Skip to main content
`Ctrl`+`K`

# MatHeaderReplace

Replaces the internal data of matrix `A` by the internal data of matrix `C` while deleting the outer wrapper of `C`

## Synopsis

    #include "petscmat.h"
    PetscErrorCode MatHeaderReplace(Mat A, Mat *C)

## Input Parameters

- A - a `Mat` whose internal data is to be replaced

- C - the `Mat` providing new internal data for `A`

Example Usage:

      Mat C;
      MatCreateSeqAIJWithArrays(..., &C);
      MatHeaderReplace(A, &C);
      // C has been destroyed and A contains the matrix entries of C

## Note

This can be used inside a function provided to `SNESSetJacobian()`, `TSSetRHSJacobian()`, or `TSSetIJacobian()` in cases where the user code computes an entirely new sparse matrix (generally with a different matrix nonzero structure/pattern) for each Newton update. It is usually better to reuse the matrix nonzero structure of `A` instead of constructing an entirely new one.

## Developer Note

This is somewhat different from `MatHeaderMerge()` it would be nice to merge the code

## See Also

`Mat`, `MatHeaderMerge()`

## Level

advanced

## Location

src/mat/utils/gcreate.c

## Examples

src/ksp/ksp/tutorials/ex77.c

Index of all Mat routines
Table of Contents for all manual pages
Index of all manual pages