dune-istl  2.7.1
About: dune-istl - DUNE (Distributed and Unified Numerics Environment) is a modular toolbox for solving partial differential equations (PDEs) with grid-based methods: DUNE Iterative Solver Template Library.
  Fossies Dox: dune-istl-2.7.1.tar.gz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

Provides methods for reading and writing matrices and vectors in various formats. More...

Collaboration diagram for IO for matrices and vectors.:

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.
 

Namespaces

 Dune::MatrixMarketImpl
 

Classes

class  Dune::MatrixMarketFormatError
 

Functions

template<class V >
void Dune::recursive_printvector (std::ostream &s, const V &v, std::string rowtext, int &counter, int columns, int width)
 Recursively print a vector. More...
 
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. More...
 
void Dune::fill_row (std::ostream &s, int m, int width, int precision)
 Print a row of zeros for a non-existing block. More...
 
template<class K >
void Dune::print_row (std::ostream &s, const K &value, 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, typename std::enable_if_t< Dune::IsNumber< K >::value > *sfinae=nullptr)
 Print one row of a matrix, specialization for number types. More...
 
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, typename std::enable_if_t<!Dune::IsNumber< M >::value > *sfinae=nullptr)
 Print one row of a matrix. More...
 
template<class M >
void Dune::printmatrix (std::ostream &s, const M &A, std::string title, std::string rowtext, int width=10, int precision=2)
 Print a generic block matrix. More...
 
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. More...
 
template<class FieldType >
void Dune::writeMatrixToMatlabHelper (const FieldType &value, int rowOffset, int colOffset, std::ostream &s, typename std::enable_if_t< Dune::IsNumber< FieldType >::value > *sfinae=nullptr)
 Helper method for the writeMatrixToMatlab routine. More...
 
template<class MatrixType >
void Dune::writeMatrixToMatlabHelper (const MatrixType &matrix, int externalRowOffset, int externalColOffset, std::ostream &s, typename std::enable_if_t<!Dune::IsNumber< MatrixType >::value > *sfinae=nullptr)
 Helper method for the writeMatrixToMatlab routine. More...
 
template<class MatrixType >
void Dune::writeMatrixToMatlab (const MatrixType &matrix, const std::string &filename, int outputPrecision=18)
 Writes sparse matrix in a Matlab-readable format. More...
 
template<class V >
void Dune::writeVectorToMatlabHelper (const V &v, std::ostream &stream)
 
template<class VectorType >
void Dune::writeVectorToMatlab (const VectorType &vector, const std::string &filename, int outputPrecision=18)
 Writes vectors in a Matlab-readable format. More...
 
void Dune::mm_read_header (std::size_t &rows, std::size_t &cols, MatrixMarketImpl::MMHeader &header, std::istream &istr, bool isVector)
 
template<typename T , typename A >
void Dune::mm_read_vector_entries (Dune::BlockVector< T, A > &vector, std::size_t size, std::istream &istr)
 
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 >
void Dune::readMatrixMarket (Dune::BlockVector< T, A > &vector, std::istream &istr)
 Reads a BlockVector from a matrix market file. More...
 
template<typename T , typename A >
void Dune::readMatrixMarket (Dune::BCRSMatrix< T, A > &matrix, std::istream &istr)
 Reads a sparse matrix from a matrix market file. More...
 
template<typename B >
void Dune::mm_print_entry (const B &entry, std::size_t rowidx, std::size_t colidx, std::ostream &ostr)
 
template<typename V >
void Dune::mm_print_vector_entry (const V &entry, std::ostream &ostr, const std::integral_constant< int, 1 > &)
 
template<typename V >
void Dune::mm_print_vector_entry (const V &vector, std::ostream &ostr, const std::integral_constant< int, 0 > &)
 
template<typename T , typename A >
std::size_t Dune::countEntries (const BlockVector< T, A > &vector)
 
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 std::integral_constant< int, 0 > &)
 
template<typename M >
void Dune::writeMatrixMarket (const M &matrix, std::ostream &ostr, const std::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. More...
 
template<typename M >
void Dune::storeMatrixMarket (const M &matrix, std::string filename)
 Stores a parallel matrix/vector in matrix market format in a file. More...
 
template<typename M >
void Dune::loadMatrixMarket (M &matrix, const std::string &filename)
 Load a matrix/vector stored in matrix market format. More...
 

Detailed Description

Provides methods for reading and writing matrices and vectors in various formats.

Routine printmatrix 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.

Function Documentation

◆ countEntries() [1/2]

template<typename T , typename A , int i>
std::size_t Dune::countEntries ( const BlockVector< FieldVector< T, i >, A > &  vector)

Definition at line 1057 of file matrixmarket.hh.

◆ countEntries() [2/2]

template<typename T , typename A >
std::size_t Dune::countEntries ( const BlockVector< T, A > &  vector)

◆ fill_row()

void Dune::fill_row ( std::ostream &  s,
int  m,
int  width,
int  precision 
)
inline

Print a row of zeros for a non-existing block.

#include <dune/istl/io.hh>
Some generic functions for pretty printing vectors and matrices.

Definition at line 130 of file io.hh.

Referenced by Dune::print_row().

◆ loadMatrixMarket()

template<typename M >
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.

Parameters
matrixWhere to store the matrix/vector.
filenamethe name of the filename (without suffix and rank!) rank i will read the file filename_i.mm

Definition at line 1282 of file matrixmarket.hh.

References Dune::readMatrixMarket().

◆ mm_print_entry()

template<typename B >
void Dune::mm_print_entry ( const B &  entry,
std::size_t  rowidx,
std::size_t  colidx,
std::ostream &  ostr 
)

Definition at line 1007 of file matrixmarket.hh.

References col, and row.

Referenced by Dune::writeMatrixMarket().

◆ mm_print_vector_entry() [1/2]

template<typename V >
void Dune::mm_print_vector_entry ( const V &  entry,
std::ostream &  ostr,
const std::integral_constant< int, 1 > &   
)

Definition at line 1027 of file matrixmarket.hh.

Referenced by Dune::mm_print_vector_entry(), and Dune::writeMatrixMarket().

◆ mm_print_vector_entry() [2/2]

template<typename V >
void Dune::mm_print_vector_entry ( const V &  vector,
std::ostream &  ostr,
const std::integral_constant< int, 0 > &   
)

◆ mm_read_header()

void Dune::mm_read_header ( std::size_t &  rows,
std::size_t &  cols,
MatrixMarketImpl::MMHeader header,
std::istream &  istr,
bool  isVector 
)
inline

◆ mm_read_vector_entries() [1/2]

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 
)

Definition at line 894 of file matrixmarket.hh.

◆ mm_read_vector_entries() [2/2]

template<typename T , typename A >
void Dune::mm_read_vector_entries ( Dune::BlockVector< T, A > &  vector,
std::size_t  size,
std::istream &  istr 
)

Definition at line 885 of file matrixmarket.hh.

Referenced by Dune::readMatrixMarket().

◆ print_row() [1/2]

template<class K >
void Dune::print_row ( std::ostream &  s,
const K &  value,
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,
typename std::enable_if_t< Dune::IsNumber< K >::value > *  sfinae = nullptr 
)

Print one row of a matrix, specialization for number types.

#include <dune/istl/io.hh>

Definition at line 149 of file io.hh.

Referenced by Dune::print_row(), and Dune::printmatrix().

◆ print_row() [2/2]

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,
typename std::enable_if_t<!Dune::IsNumber< M >::value > *  sfinae = nullptr 
)

◆ printmatrix()

template<class M >
void Dune::printmatrix ( std::ostream &  s,
const M &  A,
std::string  title,
std::string  rowtext,
int  width = 10,
int  precision = 2 
)

Print a generic block matrix.

#include <dune/istl/io.hh>
Bug:
Empty rows and columns are omitted by this method. (FlySpray #7)

Definition at line 215 of file io.hh.

References A, Dune::MatrixDimension< M >::coldim(), Dune::Matrix< T, A >::M(), Dune::Matrix< T, A >::N(), Dune::print_row(), and Dune::MatrixDimension< M >::rowdim().

◆ printSparseMatrix()

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.

#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.

Parameters
sThe ostream to print to.
matThe matrix to print.
titleThe title for the matrix.
rowtextThe text to prepend to each print out of a matrix row.
widthThe number of nonzero blocks to print in one line.
precisionThe precision to use when printing the numbers.

Definition at line 273 of file io.hh.

References A, Dune::Matrix< T, A >::begin(), col, Dune::MatrixDimension< M >::coldim(), count, Dune::Matrix< T, A >::end(), Dune::Matrix< T, A >::M(), mat, Dune::Matrix< T, A >::N(), row, and Dune::MatrixDimension< M >::rowdim().

◆ printvector()

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 
)

◆ readMatrixMarket() [1/2]

template<typename T , typename A >
void Dune::readMatrixMarket ( Dune::BCRSMatrix< T, A > &  matrix,
std::istream &  istr 
)

Reads a sparse matrix from a matrix market file.

Parameters
matrixThe matrix to store the data in.
istrThe input stream to read the data from.
Warning
Not all formats are supported!

Definition at line 953 of file matrixmarket.hh.

References Dune::MatrixMarketImpl::array_type, Dune::MatrixMarketImpl::lineFeed(), Dune::MatrixMarketImpl::readMatrixMarketBanner(), Dune::MatrixMarketImpl::readSparseEntries(), Dune::BCRSMatrix< B, A >::setBuildMode(), Dune::BCRSMatrix< B, A >::setSize(), and Dune::MatrixMarketImpl::skipComments().

◆ readMatrixMarket() [2/2]

template<typename T , typename A >
void Dune::readMatrixMarket ( Dune::BlockVector< T, A > &  vector,
std::istream &  istr 
)

Reads a BlockVector from a matrix market file.

Parameters
vectorThe vector to store the data in.
istrThe input stream to read the data from.
Warning
Not all formats are supported!

Definition at line 913 of file matrixmarket.hh.

References Dune::MatrixMarketImpl::array_type, Dune::mm_read_header(), Dune::mm_read_vector_entries(), and Dune::BlockVector< B, A >::resize().

Referenced by Dune::loadMatrixMarket().

◆ recursive_printvector()

template<class V >
void Dune::recursive_printvector ( std::ostream &  s,
const V &  v,
std::string  rowtext,
int &  counter,
int  columns,
int  width 
)

Recursively print a vector.

#include <dune/istl/io.hh>

Definition at line 50 of file io.hh.

Referenced by Dune::printvector().

◆ storeMatrixMarket()

template<typename M >
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.

Parameters
matrixThe matrix/vector to store.
filenamethe name of the filename (without suffix and rank!) rank i will write the file filename_i.mm

Definition at line 1122 of file matrixmarket.hh.

References Dune::writeMatrixMarket().

◆ writeMatrixMarket() [1/3]

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.

Definition at line 1098 of file matrixmarket.hh.

References Dune::writeMatrixMarket().

◆ writeMatrixMarket() [2/3]

template<typename M >
void Dune::writeMatrixMarket ( const M &  matrix,
std::ostream &  ostr,
const std::integral_constant< int, 1 > &   
)

Definition at line 1076 of file matrixmarket.hh.

References col, Dune::countNonZeros(), Dune::mm_print_entry(), and row.

◆ writeMatrixMarket() [3/3]

template<typename V >
void Dune::writeMatrixMarket ( const V &  vector,
std::ostream &  ostr,
const std::integral_constant< int, 0 > &   
)

◆ writeMatrixToMatlab()

template<class MatrixType >
void Dune::writeMatrixToMatlab ( const MatrixType &  matrix,
const std::string &  filename,
int  outputPrecision = 18 
)

Writes sparse matrix in a Matlab-readable format.

#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

new_mat = spconvert(load('filename'));
Parameters
matrixreference to matrix
filename
outputPrecision(number of digits) which is used to write the output file

Definition at line 453 of file io.hh.

References Dune::writeMatrixToMatlabHelper().

◆ writeMatrixToMatlabHelper() [1/2]

template<class FieldType >
void Dune::writeMatrixToMatlabHelper ( const FieldType &  value,
int  rowOffset,
int  colOffset,
std::ostream &  s,
typename std::enable_if_t< Dune::IsNumber< FieldType >::value > *  sfinae = nullptr 
)

Helper method for the writeMatrixToMatlab routine.

#include <dune/istl/io.hh>

This specialization for numbers ends the recursion

Definition at line 381 of file io.hh.

Referenced by Dune::writeMatrixToMatlab(), and Dune::writeMatrixToMatlabHelper().

◆ writeMatrixToMatlabHelper() [2/2]

template<class MatrixType >
void Dune::writeMatrixToMatlabHelper ( const MatrixType &  matrix,
int  externalRowOffset,
int  externalColOffset,
std::ostream &  s,
typename std::enable_if_t<!Dune::IsNumber< MatrixType >::value > *  sfinae = nullptr 
)

Helper method for the writeMatrixToMatlab routine.

#include <dune/istl/io.hh>

Definition at line 399 of file io.hh.

References Dune::MatrixDimension< M >::rowdim(), and Dune::writeMatrixToMatlabHelper().

◆ writeVectorToMatlab()

template<class VectorType >
void Dune::writeVectorToMatlab ( const VectorType &  vector,
const std::string &  filename,
int  outputPrecision = 18 
)

Writes vectors in a Matlab-readable format.

#include <dune/istl/io.hh>

This routine writes the argument block vector to a file with the name given by the filename argument. The file format is ASCII, with no header, and a single data column. Such a file can be read from Matlab using the command

new_vec = load('filename');
Parameters
vectorreference to vector to be printed to output file
filenamefilename of output file
outputPrecision(number of digits) which is used to write the output file

Definition at line 496 of file io.hh.

References Dune::writeVectorToMatlabHelper().

◆ writeVectorToMatlabHelper()

template<class V >
void Dune::writeVectorToMatlabHelper ( const V &  v,
std::ostream &  stream 
)

Definition at line 466 of file io.hh.

Referenced by Dune::writeVectorToMatlab().