# 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 PETSCMAT_DLLEXPORT MatStoreValues(Mat mat)

Collect on Mat

### Input Parameters

mat -the matrix (currently only AIJ matrices support this option)

### Common Usage, with SNESSolve()

       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

       ierr = MatSetOption(mat,MAT_NO_NEW_NONZERO_LOCATIONS);

       ierr = MatStoreValues(mat);

       Call SNESSetJacobian() with matrix

       In your Jacobian routine

         ierr = MatRetrieveValues(mat);

         Set nonlinear terms in matrix

### Common Usage without SNESSolve(), i.e. when you handle nonlinear solve yourself

       // build linear portion of Jacobian

       ierr = MatSetOption(mat,MAT_NO_NEW_NONZERO_LOCATIONS);

       ierr = MatStoreValues(mat);

       loop over nonlinear iterations

          ierr = 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 assemblied before calling this routine Must set the matrix option MatSetOption(mat,MAT_NO_NEW_NONZERO_LOCATIONS); 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:src/mat/impls/aij/seq/aij.c
Index of all Mat routines
Table of Contents for all manual pages
Index of all manual pages