MatSetValuesStencil

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

Synopsis

#include "petscmat.h" 
int MatSetValuesStencil(Mat mat,int m,MatStencil *idxm,int n,MatStencil *idxn,PetscScalar *v,InsertMode addv)
Not Collective

Input Parameters

mat - the matrix
v - a logically two-dimensional array of values
m - number of rows being entered
idxm - grid coordinates (and component number when dof > 1) for matrix rows being entered
n - number of columns being entered
idxn - grid coordinates (and component number when dof > 1) for matrix columns being entered
addv - either ADD_VALUES or INSERT_VALUES, where ADD_VALUES adds values to any existing entries, and INSERT_VALUES replaces existing entries with new values

Notes

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

Calls to MatSetValuesStencil() 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

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

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

In Fortran 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
   idxm(MatStencil_c,1) = c
etc

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 Dirchlet boundary conditions that you don't want represented in the matrix.

Inspired by the structured grid interface to the HYPRE package (http://www.llnl.gov/CASC/hypre)

Efficiency Alert

The routine MatSetValuesBlockedStencil() may offer much better efficiency for users of block sparse formats (MATSEQBAIJ and MATMPIBAIJ).

See Also

MatSetOption(), MatAssemblyBegin(), MatAssemblyEnd(), MatSetValuesBlocked(), MatSetValuesLocal()
MatSetValues(), MatSetValuesBlockedStencil(), MatSetStencil(), DAGetMatrix()

Level:beginner
Location:
src/mat/interface/matrix.c
Index of all Mat routines
Table of Contents for all manual pages
Index of all manual pages

Examples

src/sles/examples/tutorials/ex22.c.html
src/sles/examples/tutorials/ex25.c.html
src/snes/examples/tutorials/ex5.c.html
src/snes/examples/tutorials/ex14.c.html
src/snes/examples/tutorials/ex18.c.html
src/snes/examples/tutorials/ex20.c.html