Skip to main content
`Ctrl`+`K`

# MatSetValuesBlockedStencil

Inserts or adds a block of values into a matrix. Using structured grid indexing

## Synopsis

    #include "petscmat.h"
    PetscErrorCode MatSetValuesBlockedStencil(Mat mat, PetscInt m, const MatStencil idxm[], PetscInt n, const MatStencil idxn[], const PetscScalar v[], InsertMode addv)

Not Collective

## Input Parameters

- mat - the matrix

- m - number of rows being entered

- idxm - grid coordinates for matrix rows being entered

- n - number of columns being entered

- idxn - grid coordinates for matrix columns being entered

- v - a one-dimensional array that contains the values implicitly stored as a two-dimensional array, by default in row-major order. See `MAT_ROW_ORIENTED` in `MatSetOption()` for how to use column-major order.

- addv - either `ADD_VALUES` to add to existing entries or `INSERT_VALUES` to replace existing entries with new values

## Notes

By default the values, `v`, are row-oriented and unsorted. See `MatSetOption()` for other options.

Calls to `MatSetValuesBlockedStencil()` with the `INSERT_VALUES` and `ADD_VALUES` options cannot be mixed without intervening calls to the assembly routines.

The grid coordinates are across the entire grid, not just the local portion

`MatSetValuesBlockedStencil()` uses 0-based row and column numbers in Fortran as well as in C.

For setting/accessing vector values via array coordinates you can use the `DMDAVecGetArray()` routine

In order to use this routine you must either obtain the matrix with `DMCreateMatrix()` or call `MatSetBlockSize()`, `MatSetLocalToGlobalMapping()` and `MatSetStencil()` first.

The columns and rows in the stencil passed in MUST be contained within the ghost region of the given process as set with DMDACreateXXX() or `MatSetStencil()`. For example, if you create a `DMDA` with an overlap of one grid level and on a particular process its first local nonghost x logical coordinate is 6 (so its first ghost x logical coordinate is 5) the first i index you can use in your column and row indices in `MatSetStencil()` is 5.

Negative indices may be passed in `idxm` and `idxn`, these rows and columns are simply ignored. This allows easily inserting element stiffness matrices with homogeneous Dirichlet boundary conditions that you don’t want represented in the matrix.

Inspired by the structured grid interface to the HYPRE package (https://computation.llnl.gov/projects/hypre-scalable-linear-solvers-multigrid-methods)

## Fortran Notes

`idxm` and `idxn` should be declared as

        MatStencil idxm(4,m),idxn(4,n)

and the values inserted using

        idxm(MatStencil_i,1) = i
        idxm(MatStencil_j,1) = j
        idxm(MatStencil_k,1) = k
       etc

If `v` is a two-dimensional array use `reshape()` to pass it as a one dimensional array

## See Also

Matrices, `Mat`, `DMDA`, `MatSetOption()`, `MatAssemblyBegin()`, `MatAssemblyEnd()`, `MatSetValuesBlocked()`, `MatSetValuesLocal()`, `MatSetValues()`, `MatSetValuesStencil()`, `MatSetStencil()`, `DMCreateMatrix()`, `DMDAVecGetArray()`, `MatStencil`, `MatSetBlockSize()`, `MatSetLocalToGlobalMapping()`

## Level

beginner

## Location

src/mat/interface/matrix.c

## Examples

src/snes/tutorials/ex48.c

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