:orphan:
# MatStoreValues
Stashes a copy of the matrix values; this allows reusing of the linear part of a Jacobian, while recomputing only the nonlinear portion.
## Synopsis
```
#include "petscmat.h"
PetscErrorCode MatStoreValues(Mat mat)
```
Logically Collect
## Input Parameter
- ***mat -*** the matrix (currently only `MATAIJ` matrices support this option)
## Usage
```none
Using SNES
Create Jacobian matrix
Set linear terms into matrix
Apply boundary conditions to matrix, at this time matrix must have
final nonzero structure (i.e. setting the nonlinear terms and applying
boundary conditions again will not change the nonzero structure
MatSetOption(mat,MAT_NEW_NONZERO_LOCATIONS,PETSC_FALSE);
MatStoreValues(mat);
Call SNESSetJacobian() with matrix
In your Jacobian routine
MatRetrieveValues(mat);
Set nonlinear terms in matrix
Without `SNESSolve()`, i.e. when you handle nonlinear solve yourself:
// build linear portion of Jacobian
MatSetOption(mat,MAT_NEW_NONZERO_LOCATIONS,PETSC_FALSE);
MatStoreValues(mat);
loop over nonlinear iterations
MatRetrieveValues(mat);
// call MatSetValues(mat,...) to set nonliner portion of Jacobian
// call MatAssemblyBegin/End() on matrix
Solve linear system with Jacobian
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
[](ch_matrices), `Mat`, `Mat`, `MatRetrieveValues()`
## Level
advanced
## Location
src/mat/impls/aij/seq/aij.c
## Implementations
MatStoreValues_MPIAIJ in src/mat/impls/aij/mpi/mpiaij.c
MatStoreValues_SeqAIJ in src/mat/impls/aij/seq/aij.c
MatStoreValues_MPIBAIJ in src/mat/impls/baij/mpi/mpibaij.c
MatStoreValues_SeqBAIJ in src/mat/impls/baij/seq/baij.c
MatStoreValues_MPISBAIJ in src/mat/impls/sbaij/mpi/mpisbaij.c
MatStoreValues_SeqSBAIJ in src/mat/impls/sbaij/seq/sbaij.c
MatStoreValues_MPISELL in src/mat/impls/sell/mpi/mpisell.c
MatStoreValues_SeqSELL in src/mat/impls/sell/seq/sell.c
---
[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](/manualpages/index.md)
[Index of all manual pages](/manualpages/singleindex.md)