# MatStoreValues
Stashes a copy of the matrix values; this allows, for example, reuse of the linear part of a Jacobian, while recomputing the nonlinear portion. 
## Synopsis
```
#include "petscmat.h" 
PetscErrorCode MatStoreValues(Mat mat)
```
Logically Collect


## Input Parameters

- ***mat -*** the matrix (currently only `MATAIJ` matrices support this option)





## Common Usage, with `SNESSolve()`
```none
Create Jacobian matrix
```
```none
Set linear terms into matrix
```
```none
Apply boundary conditions to matrix, at this time matrix must have
```
```none
final nonzero structure (i.e. setting the nonlinear terms and applying
```
```none
boundary conditions again will not change the nonzero structure
```
```none
ierr = MatSetOption(mat,MAT_NEW_NONZERO_LOCATIONS,PETSC_FALSE);
```
```none
ierr = MatStoreValues(mat);
```
```none
Call SNESSetJacobian() with matrix
```
```none
In your Jacobian routine
```
```none
ierr = MatRetrieveValues(mat);
```
```none
Set nonlinear terms in matrix
```


## Common Usage without SNESSolve(), i.e. when you handle nonlinear solve yourself
```none
// build linear portion of Jacobian
```
```none
ierr = MatSetOption(mat,MAT_NEW_NONZERO_LOCATIONS,PETSC_FALSE);
```
```none
ierr = MatStoreValues(mat);
```
```none
loop over nonlinear iterations
```
```none
ierr = MatRetrieveValues(mat);
```
```none
// call MatSetValues(mat,...) to set nonliner portion of Jacobian
```
```none
// call MatAssemblyBegin/End() on matrix
```
```none
Solve linear system with Jacobian
```
```none
endloop
```


## Notes
Matrix must already be assembled before calling this routine
Must set the matrix option `MatSetOption`(mat,`MAT_NEW_NONZERO_LOCATIONS`,`PETSC_FALSE`); before
calling this routine.

When this is called multiple times it overwrites the previous set of stored values
and does not allocated additional space.


## See Also
 `MatRetrieveValues()`

## Level
advanced

## Location
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/mat/impls/aij/seq/aij.c.html#MatStoreValues">src/mat/impls/aij/seq/aij.c</A>

## Implementations

<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/mat/impls/aij/mpi/mpiaij.c.html#MatStoreValues_MPIAIJ">MatStoreValues_MPIAIJ in src/mat/impls/aij/mpi/mpiaij.c</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/mat/impls/aij/seq/aij.c.html#MatStoreValues_SeqAIJ">MatStoreValues_SeqAIJ in src/mat/impls/aij/seq/aij.c</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/mat/impls/baij/mpi/mpibaij.c.html#MatStoreValues_MPIBAIJ">MatStoreValues_MPIBAIJ in src/mat/impls/baij/mpi/mpibaij.c</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/mat/impls/baij/seq/baij.c.html#MatStoreValues_SeqBAIJ">MatStoreValues_SeqBAIJ in src/mat/impls/baij/seq/baij.c</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/mat/impls/sbaij/mpi/mpisbaij.c.html#MatStoreValues_MPISBAIJ">MatStoreValues_MPISBAIJ in src/mat/impls/sbaij/mpi/mpisbaij.c</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/mat/impls/sbaij/seq/sbaij.c.html#MatStoreValues_SeqSBAIJ">MatStoreValues_SeqSBAIJ in src/mat/impls/sbaij/seq/sbaij.c</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/mat/impls/sell/mpi/mpisell.c.html#MatStoreValues_MPISELL">MatStoreValues_MPISELL in src/mat/impls/sell/mpi/mpisell.c</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/mat/impls/sell/seq/sell.c.html#MatStoreValues_SeqSELL">MatStoreValues_SeqSELL in src/mat/impls/sell/seq/sell.c</A><BR>


---
[Edit on GitLab](https://gitlab.com/petsc/petsc/-/edit/release/src/mat/impls/aij/seq/aij.c)


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