Sparse Matrix and Vector classes
[ISTL]
Detailed Description
Matrix and Vector classes that support a block recursive structure capable of representing the natural structure from Finite Element discretisations.The interface of our matrices is designed according to what they represent from a mathematical point of view. The vector classes are representations of vector spaces:
- FieldVector represents a vector space
where the field
is represented by a numeric type (e.g. double, float, complex).
is known at compile time.
- BlockVector represents a vector space
where W is itself a vector space.
- VariableBlockVector represents a vector space having a two-level block structure of the form
, i.e. it is constructed from
vector spaces,
.
The matrix classes represent linear maps from vector space
to vector space
the recursive block structure of the matrix rows and columns immediately follows from the recursive block structure of the vectors representing the domain and range of the mapping, respectively:
- FieldMatrix represents a linear map
where
and
are vector spaces over the same field represented by a numerix type.
- BCRSMatrix represents a linear map
where
and
where W is itself a vector space.
- VariableBCRSMatrix is not yet implemented.
Files | |
file | io.hh |
Some generic functions for pretty printing vectors and matrices. | |
file | matrixutils.hh |
Some handy generic functions for ISTL matrices. | |
Modules | |
Block Recursive Iterative Kernels | |
Classes | |
class | Dune::BCRSMatrix< B, A > |
A sparse block matrix with compressed row storage. More... | |
class | Dune::BDMatrix< B, A > |
A block-diagonal matrix. More... | |
class | Dune::BlockVector< B, A > |
A vector of blocks with memory management. More... | |
class | Dune::Matrix< T, A > |
A generic dynamic matrix. More... | |
struct | Dune::CheckIfDiagonalPresent< blocklevel, l > |
Check whether the a matrix has diagonal values on blocklevel recursion levels. More... | |
class | Dune::VariableBlockVector< B, A > |
A Vector of blocks with different blocksizes. More... | |
Functions | |
void | Dune::fill_row (std::ostream &s, int m, int width, int precision) |
print a row of zeros for a non-existing block | |
template<class M> | |
void | Dune::print_row (std::ostream &s, const M &A, typename M::size_type I, typename M::size_type J, typename M::size_type therow, int width, int precision) |
print one row of a matrix | |
template<class K, int n, int m> | |
void | Dune::print_row (std::ostream &s, const FieldMatrix< K, n, m > &A, typename FieldMatrix< K, n, m >::size_type I, typename FieldMatrix< K, n, m >::size_type J, typename FieldMatrix< K, n, m >::size_type therow, int width, int precision) |
print one row of a matrix, specialization for FieldMatrix | |
template<class K> | |
void | Dune::print_row (std::ostream &s, const FieldMatrix< K, 1, 1 > &A, typename FieldMatrix< K, 1, 1 >::size_type I, typename FieldMatrix< K, 1, 1 >::size_type J, typename FieldMatrix< K, 1, 1 >::size_type therow, int width, int precision) |
print one row of a matrix, specialization for FieldMatrix<K,1,1> | |
template<class M> | |
void | Dune::printmatrix (std::ostream &s, const M &A, std::string title, std::string rowtext, int width=10, int precision=2) |
Prints a generic block matrix. | |
template<class B, int n, int m, class A> | |
void | Dune::printSparseMatrix (std::ostream &s, const BCRSMatrix< FieldMatrix< B, n, m >, A > &mat, std::string title, std::string rowtext, int width=3, int precision=2) |
Prints a BCRSMatrix with fixed sized blocks. | |
template<class FieldType, int rows, int cols> | |
void | Dune::writeMatrixToMatlabHelper (const FieldMatrix< FieldType, rows, cols > &matrix, int rowOffset, int colOffset, std::ostream &s) |
Helper method for the writeMatrixToMatlab routine. | |
template<class MatrixType> | |
void | Dune::writeMatrixToMatlab (const MatrixType &matrix, const std::string &filename) |
Writes sparse matrix in a Matlab-readable format. | |
template<class M> | |
int | Dune::countNonZeros (const M &matrix) |
Get the number of nonzero fields in the matrix. |
Function Documentation
int Dune::countNonZeros | ( | const M & | matrix | ) | [inline] |
Get the number of nonzero fields in the matrix.
This is not the number of nonzero blocks, but the number of non zero scalar entries (on blocklevel 1) if the matrix is viewed as a flat matrix.
For FieldMatrix this is simply the number of columns times the number of rows, for a BCRSMatrix<FieldMatrix<K,n,m>> this is the number of nonzero blocks time n*m.
void Dune::printmatrix | ( | std::ostream & | s, | |
const M & | A, | |||
std::string | title, | |||
std::string | rowtext, | |||
int | width = 10 , |
|||
int | precision = 2 | |||
) | [inline] |
Prints a generic block matrix.
- Bug:
- Empty rows and columns are omitted by this method. (FlySpray #7)
References Dune::print_row().
void Dune::printSparseMatrix | ( | std::ostream & | s, | |
const BCRSMatrix< FieldMatrix< B, n, m >, A > & | mat, | |||
std::string | title, | |||
std::string | rowtext, | |||
int | width = 3 , |
|||
int | precision = 2 | |||
) | [inline] |
Prints a BCRSMatrix with fixed sized blocks.
Only the nonzero entries will be printed as matrix blocks together with their corresponding column index and all others will be omitted.
This might be preferable over printmatrix in the case of big sparse matrices with nonscalar blocks.
- Parameters:
-
s The ostream to print to. mat The matrix to print. title The title for the matrix. rowtext The text to prepend to each print out of a matrix row. width The number of nonzero blocks to print in one line. precision The precision to use when printing the numbers.
void Dune::writeMatrixToMatlab | ( | const MatrixType & | matrix, | |
const std::string & | filename | |||
) | [inline] |
Writes sparse matrix in a Matlab-readable format.
This routine writes the argument BCRSMatrix to a file with the name given by the filename argument. The file format is ASCII, with no header, and three data columns. Each row describes a scalar matrix entry and consists of the matrix row and column numbers (both counted starting from 1), and the matrix entry. Such a file can be read from Matlab using the command
new_mat = spconvert(load('filename'));
References Dune::writeMatrixToMatlabHelper().
void Dune::writeMatrixToMatlabHelper | ( | const FieldMatrix< FieldType, rows, cols > & | matrix, | |
int | rowOffset, | |||
int | colOffset, | |||
std::ostream & | s | |||
) | [inline] |
Helper method for the writeMatrixToMatlab routine.
This specialization for FieldMatrices ends the recursion
References Dune::writeMatrixToMatlabHelper().
Referenced by Dune::writeMatrixToMatlab(), and Dune::writeMatrixToMatlabHelper().