dune-istl
2.2.1
|
Provides methods for reading and writing matrices and vectors in various formats. More...
![]() |
Files | |
file | io.hh |
Some generic functions for pretty printing vectors and matrices. | |
file | matrixmarket.hh |
Provides classes for reading and writing MatrixMarket Files with an extension for parallel matrices. |
Classes | |
class | Dune::MatrixMarketFormatError |
struct | Dune::mm_multipliers< M > |
struct | Dune::mm_multipliers< BCRSMatrix< FieldMatrix< B, i, j >, A > > |
Functions | |
template<class V > | |
void | Dune::recursive_printvector (std::ostream &s, const V &v, std::string rowtext, int &counter, int columns, int width, int precision) |
template<class K , int n> | |
void | Dune::recursive_printvector (std::ostream &s, const FieldVector< K, n > &v, std::string rowtext, int &counter, int columns, int width, int precision) |
template<class V > | |
void | Dune::printvector (std::ostream &s, const V &v, std::string title, std::string rowtext, int columns=1, int width=10, int precision=2) |
print an ISTL vector | |
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::writeMatrixToMatlabHelper (const MatrixType &matrix, int externalRowOffset, int externalColOffset, std::ostream &s) |
Helper method for the writeMatrixToMatlab routine. | |
template<class MatrixType > | |
void | Dune::writeMatrixToMatlab (const MatrixType &matrix, const std::string &filename, int outputPrecision=18) |
Writes sparse matrix in a Matlab-readable format. | |
void | Dune::mm_read_header (std::size_t &rows, std::size_t &cols, MMHeader &header, std::istream &istr, bool isVector) |
template<typename T , typename A , int entries> | |
void | Dune::mm_read_vector_entries (Dune::BlockVector< Dune::FieldVector< T, entries >, A > &vector, std::size_t size, std::istream &istr) |
template<typename T , typename A , int entries> | |
void | Dune::readMatrixMarket (Dune::BlockVector< Dune::FieldVector< T, entries >, A > &vector, std::istream &istr) |
Reads a BlockVector from a matrix market file. | |
template<typename T , typename A , int brows, int bcols> | |
void | Dune::readMatrixMarket (Dune::BCRSMatrix< Dune::FieldMatrix< T, brows, bcols >, A > &matrix, std::istream &istr) |
Reads a sparse matrix from a matrix market file. | |
template<typename B , int i, int j> | |
void | Dune::mm_print_entry (const FieldMatrix< B, i, j > &entry, typename FieldMatrix< B, i, j >::size_type rowidx, typename FieldMatrix< B, i, j >::size_type colidx, std::ostream &ostr) |
template<typename V > | |
void | Dune::mm_print_vector_entry (const V &entry, std::ostream &ostr, const integral_constant< int, 1 > &) |
template<typename V > | |
void | Dune::mm_print_vector_entry (const V &vector, std::ostream &ostr, const integral_constant< int, 0 > &) |
template<typename T , typename A , int i> | |
std::size_t | Dune::countEntries (const BlockVector< FieldVector< T, i >, A > &vector) |
template<typename V > | |
void | Dune::writeMatrixMarket (const V &vector, std::ostream &ostr, const integral_constant< int, 0 > &) |
template<typename M > | |
void | Dune::writeMatrixMarket (const M &matrix, std::ostream &ostr, const integral_constant< int, 1 > &) |
template<typename M > | |
void | Dune::writeMatrixMarket (const M &matrix, std::ostream &ostr) |
writes a ISTL matrix or vector to a stream in matrix market format. | |
template<typename M > | |
void | Dune::storeMatrixMarket (const M &matrix, std::string filename) |
Stores a parallel matrix/vector in matrix market format in a file. | |
template<typename M , typename G , typename L > | |
void | Dune::storeMatrixMarket (const M &matrix, std::string filename, const OwnerOverlapCopyCommunication< G, L > &comm, bool storeIndices=true) |
Stores a parallel matrix/vector in matrix market format in a file. | |
template<typename M , typename G , typename L > | |
void | Dune::loadMatrixMarket (M &matrix, const std::string &filename, OwnerOverlapCopyCommunication< G, L > &comm, bool readIndices=true) |
Load a parallel matrix/vector stored in matrix market format. | |
template<typename M > | |
void | Dune::loadMatrixMarket (M &matrix, const std::string &filename) |
Load a matrix/vector stored in matrix market format. |
Provides methods for reading and writing matrices and vectors in various formats.
Routine printmatix prints a (sparse matrix with all entries (even zeroes). Function printvector prints a vector to a stream. PrintSparseMatrix prints a sparse matrix omitting all nonzeroes. With writeMatrixToMatlab one can write a matrix in a Matlab readable format. Using storeMartrixMarket and loadMatrixMarket one can store and load a parallel ISTL matrix in MatrixMarket format. The latter can even read a matrix written with writeMatrixToMatlab.
std::size_t Dune::countEntries | ( | const BlockVector< FieldVector< T, i >, A > & | vector | ) |
|
inline |
print a row of zeros for a non-existing block
@code
#include <dune/istl/io.hh>
Referenced by Dune::print_row().
void Dune::loadMatrixMarket | ( | M & | matrix, |
const std::string & | filename, | ||
OwnerOverlapCopyCommunication< G, L > & | comm, | ||
bool | readIndices = true |
||
) |
Load a parallel matrix/vector stored in matrix market format.
More about the matrix market exchange format can be found here.
matrix | Where to store the matrix/vector. |
filename | the name of the filename (without suffix and rank!) rank i will read the file filename_i.mm |
comm | The information about the data distribution. |
readIndices | Whether to read the parallel index information. If true rank i reads the index information form file filename_i.idx And builds the remote indices information. |
References Dune::OwnerOverlapCopyCommunication< GlobalIdType, LocalIdType >::communicator(), and Dune::readMatrixMarket().
void Dune::loadMatrixMarket | ( | M & | matrix, |
const std::string & | filename | ||
) |
Load a matrix/vector stored in matrix market format.
More about the matrix market exchange format can be found here.
matrix | Where to store the matrix/vector. |
filename | the name of the filename (without suffix and rank!) rank i will read the file filename_i.mm |
References Dune::readMatrixMarket().
void Dune::mm_print_entry | ( | const FieldMatrix< B, i, j > & | entry, |
typename FieldMatrix< B, i, j >::size_type | rowidx, | ||
typename FieldMatrix< B, i, j >::size_type | colidx, | ||
std::ostream & | ostr | ||
) |
Referenced by Dune::writeMatrixMarket().
void Dune::mm_print_vector_entry | ( | const V & | entry, |
std::ostream & | ostr, | ||
const integral_constant< int, 1 > & | |||
) |
Referenced by Dune::mm_print_vector_entry(), and Dune::writeMatrixMarket().
void Dune::mm_print_vector_entry | ( | const V & | vector, |
std::ostream & | ostr, | ||
const integral_constant< int, 0 > & | |||
) |
References Dune::mm_print_vector_entry().
void Dune::mm_read_header | ( | std::size_t & | rows, |
std::size_t & | cols, | ||
MMHeader & | header, | ||
std::istream & | istr, | ||
bool | isVector | ||
) |
Referenced by Dune::readMatrixMarket().
void Dune::mm_read_vector_entries | ( | Dune::BlockVector< Dune::FieldVector< T, entries >, A > & | vector, |
std::size_t | size, | ||
std::istream & | istr | ||
) |
Referenced by Dune::readMatrixMarket().
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
@code
#include <dune/istl/io.hh>
References Dune::fill_row().
Referenced by Dune::printmatrix().
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 | ||
) |
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>
@code
#include <dune/istl/io.hh>
References A.
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.
@code
#include <dune/istl/io.hh>
References Dune::print_row().
Referenced by Dune::redistributeMatrixEntries(), and test_IO().
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.
@code
#include <dune/istl/io.hh>
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.
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. |
References A, Dune::Matrix< T, A >::begin(), col, count, Dune::Matrix< T, A >::end(), Dune::Matrix< T, A >::M(), mat, Dune::Matrix< T, A >::N(), and row.
void Dune::printvector | ( | std::ostream & | s, |
const V & | v, | ||
std::string | title, | ||
std::string | rowtext, | ||
int | columns = 1 , |
||
int | width = 10 , |
||
int | precision = 2 |
||
) |
print an ISTL vector
@code
#include <dune/istl/io.hh>
References Dune::recursive_printvector().
Referenced by test_IO().
void Dune::readMatrixMarket | ( | Dune::BlockVector< Dune::FieldVector< T, entries >, A > & | vector, |
std::istream & | istr | ||
) |
Reads a BlockVector from a matrix market file.
vector | The vector to store the data in. |
istr | The input stream to read the data from. |
References Dune::mm_read_header(), and Dune::mm_read_vector_entries().
Referenced by Dune::loadMatrixMarket().
void Dune::readMatrixMarket | ( | Dune::BCRSMatrix< Dune::FieldMatrix< T, brows, bcols >, A > & | matrix, |
std::istream & | istr | ||
) |
Reads a sparse matrix from a matrix market file.
matrix | The matrix to store the data in. |
istr | The input stream to read the data from. |
References A.
void Dune::recursive_printvector | ( | std::ostream & | s, |
const V & | v, | ||
std::string | rowtext, | ||
int & | counter, | ||
int | columns, | ||
int | width, | ||
int | precision | ||
) |
void Dune::recursive_printvector | ( | std::ostream & | s, |
const FieldVector< K, n > & | v, | ||
std::string | rowtext, | ||
int & | counter, | ||
int | columns, | ||
int | width, | ||
int | precision | ||
) |
@code
#include <dune/istl/io.hh>
void Dune::storeMatrixMarket | ( | const M & | matrix, |
std::string | filename | ||
) |
Stores a parallel matrix/vector in matrix market format in a file.
More about the matrix market exchange format can be found here.
matrix | The matrix/vector to store. |
filename | the name of the filename (without suffix and rank!) rank i will write the file filename_i.mm |
References Dune::writeMatrixMarket().
void Dune::storeMatrixMarket | ( | const M & | matrix, |
std::string | filename, | ||
const OwnerOverlapCopyCommunication< G, L > & | comm, | ||
bool | storeIndices = true |
||
) |
Stores a parallel matrix/vector in matrix market format in a file.
More about the matrix market exchange format can be found here.
matrix | The matrix/vector to store. |
filename | the name of the filename (without suffix and rank!) rank i will write the file filename_i.mm |
comm | The information about the data distribution. |
storeIndices | Whether to store the parallel index information. If true rank i writes the index information to file filename_i.idx. |
References Dune::OwnerOverlapCopyCommunication< GlobalIdType, LocalIdType >::communicator(), Dune::OwnerOverlapCopyCommunication< GlobalIdType, LocalIdType >::indexSet(), Dune::OwnerOverlapCopyCommunication< GlobalIdType, LocalIdType >::remoteIndices(), and Dune::writeMatrixMarket().
void Dune::writeMatrixMarket | ( | const V & | vector, |
std::ostream & | ostr, | ||
const integral_constant< int, 0 > & | |||
) |
References Dune::countEntries(), and Dune::mm_print_vector_entry().
Referenced by Dune::storeMatrixMarket(), and Dune::writeMatrixMarket().
void Dune::writeMatrixMarket | ( | const M & | matrix, |
std::ostream & | ostr, | ||
const integral_constant< int, 1 > & | |||
) |
References col, Dune::countNonZeros(), Dune::mm_print_entry(), and row.
void Dune::writeMatrixMarket | ( | const M & | matrix, |
std::ostream & | ostr | ||
) |
writes a ISTL matrix or vector to a stream in matrix market format.
References Dune::writeMatrixMarket().
void Dune::writeMatrixToMatlab | ( | const MatrixType & | matrix, |
const std::string & | filename, | ||
int | outputPrecision = 18 |
||
) |
Writes sparse matrix in a Matlab-readable format.
@code
#include <dune/istl/io.hh> 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
matrix | reference to matrix |
filename | |
outputPrecision | (number of digits) which is used to write the output file |
References Dune::writeMatrixToMatlabHelper().
void Dune::writeMatrixToMatlabHelper | ( | const FieldMatrix< FieldType, rows, cols > & | matrix, |
int | rowOffset, | ||
int | colOffset, | ||
std::ostream & | s | ||
) |
Helper method for the writeMatrixToMatlab routine.
@code
#include <dune/istl/io.hh>
This specialization for FieldMatrices ends the recursion
Referenced by Dune::writeMatrixToMatlab(), and Dune::writeMatrixToMatlabHelper().
void Dune::writeMatrixToMatlabHelper | ( | const MatrixType & | matrix, |
int | externalRowOffset, | ||
int | externalColOffset, | ||
std::ostream & | s | ||
) |
Helper method for the writeMatrixToMatlab routine.
@code
#include <dune/istl/io.hh>
References row, and Dune::writeMatrixToMatlabHelper().