Creating an Epetra_CrsMatrix

This file first gives an example of how to create an Epetra_CrsMatrix object, then it details the supported matrices and gives a list of required parameters.

Given an already created Epetra_Map, Galeri can construct an Epetra_CrsMatrix object that has this Map as RowMatrixRowMap(). A simple example is as follows. Let Map be an already created Epetra_Map* object; then, a diagonal matrix with $a = 2.0$ on the diagonal can be created using the instructions

#include "Galeri_CrsMatrices.h"
using namespace Galeri;
...
string MatrixType = "Diag";
List.set("a", 2.0);
Epetra_CrsMatrix* Matrix = CreateCrsMatrix(MatrixType, Map, List);

More interesting matrices can be easily created. For example, a 2D biharmonic operator can be created like this:

List.set("nx", 10);
List.set("ny", 10);
Epetra_CrsMatrix* Matrix = Galeri.Create("Biharmonic2D", Map, List);

For matrices arising from 2D discretizations on Cartesian grids, it is possible to visualize the computational stencil at a given grid point by using function PrintStencil2D, defined in the Galeri namespace:

#include "Galeri_Utils.h"
using namespace Galeri;
...
// Matrix is an already created Epetra_CrsMatrix* object
// and nx and ny the number of nodes along the X-axis and Y-axis, 
// respectively.
PrintStencil2D(Matrix, nx, ny);

The output is:

2D computational stencil at GID 12 (grid is 5 x 5)

        0          0          1          0          0
        0          2         -8          2          0
        1         -8         20         -8          1
        0          2         -8          2          0
        0          0          1          0          0

To present the list of supported matrices we adopt the following symbols:

The list of supported matrices is now reported in alphabetical order.

For example, to approximate the 2D Helmhotlz equation

\[ - \nabla u - \sigma u = f \quad \quad (\sigma \geq 0) \]

with the standard 5-pt discretization stencil

\[ \frac{1}{h^2} \; \left[ \begin{tabular}{ccc} & -1 & \\ -1 & $4 -\sigma h^2$ & -1 \\ & -1 & \\ \end{tabular} \right] \]

and $\sigma = 0.1, h = 1/nx$, one can set

  List.set("a", 4 - 0.1 * h * h);
  List.set("b", -1.0);
  List.set("c", -1.0);
  List.set("d", -1.0);
  List.set("e", -1.0);
  

The factor $\frac{1}{h^2}$ can be considered by scaling the input parameters.

 All Classes Files Functions Variables
Generated on Wed Apr 13 10:08:44 2011 for Galeri by  doxygen 1.6.3