Dune Core Modules (2.6.0)

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.
 

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)
 Recursively print all the blocks. More...
 
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)
 Recursively print all the blocks – specialization for FieldVector. 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 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. More...
 
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. More...
 
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> 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 , int dim>
void Dune::writeMatrixToMatlabHelper (const ScaledIdentityMatrix< FieldType, dim > &matrix, int rowOffset, int colOffset, std::ostream &s)
 Helper method for the writeMatrixToMatlab routine. More...
 
template<class FieldType , int dim>
void Dune::writeMatrixToMatlabHelper (const DiagonalMatrix< FieldType, dim > &matrix, int rowOffset, int colOffset, std::ostream &s)
 Helper method for the writeMatrixToMatlab routine. More...
 
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. More...
 
template<class FieldType >
void Dune::writeMatrixToMatlabHelper (const DynamicMatrix< FieldType > &matrix, int rowOffset, int colOffset, std::ostream &s)
 Helper method for the writeMatrixToMatlab routine. More...
 
template<class MatrixType >
void Dune::writeMatrixToMatlabHelper (const MatrixType &matrix, int externalRowOffset, int externalColOffset, std::ostream &s)
 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 VectorType >
void Dune::writeVectorToMatlab (const VectorType &vector, const std::string &filename, int outputPrecision=18)
 Writes vectors in a Matlab-readable format. More...
 
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. More...
 
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. More...
 
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. More...
 
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. More...
 
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. 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

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

References DUNE_UNUSED_PARAMETER.

◆ loadMatrixMarket() [1/2]

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

References DUNE_THROW, and Dune::readMatrixMarket().

◆ loadMatrixMarket() [2/2]

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.

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
commThe information about the data distribution.
readIndicesWhether 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.

◆ print_row() [1/3]

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>

#include <dune/istl/io.hh>

◆ print_row() [2/3]

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.

#include <dune/istl/io.hh>

◆ print_row() [3/3]

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.

#include <dune/istl/io.hh>

◆ 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)

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

◆ 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 
)

Print an ISTL vector.

#include <dune/istl/io.hh>

References Dune::recursive_printvector().

◆ readMatrixMarket() [1/2]

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.

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

◆ readMatrixMarket() [2/2]

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.

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

Referenced by Dune::loadMatrixMarket().

◆ recursive_printvector() [1/2]

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 
)

Recursively print all the blocks – specialization for FieldVector.

#include <dune/istl/io.hh>

References DUNE_UNUSED_PARAMETER.

◆ recursive_printvector() [2/2]

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

Recursively print all the blocks.

#include <dune/istl/io.hh>

References Dune::recursive_printvector().

Referenced by Dune::printvector(), and Dune::recursive_printvector().

◆ storeMatrixMarket() [1/2]

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

◆ storeMatrixMarket() [2/2]

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.

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
commThe information about the data distribution.
storeIndicesWhether to store the parallel index information. If true rank i writes the index information to file filename_i.idx.

References Dune::ParallelIndexSet< TG, TL, N >::begin(), Dune::ParallelIndexSet< TG, TL, N >::end(), Dune::OwnerOverlapCopyCommunication< GlobalIdType, LocalIdType >::indexSet(), Dune::CollectiveCommunication< MPI_Comm >::rank(), and Dune::OwnerOverlapCopyCommunication< GlobalIdType, LocalIdType >::remoteIndices().

◆ 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

References Dune::writeMatrixToMatlabHelper().

◆ writeMatrixToMatlabHelper() [1/5]

template<class FieldType , int dim>
void Dune::writeMatrixToMatlabHelper ( const DiagonalMatrix< FieldType, dim > &  matrix,
int  rowOffset,
int  colOffset,
std::ostream &  s 
)

Helper method for the writeMatrixToMatlab routine.

#include <dune/istl/io.hh>

This specialization for DiagonalMatrices ends the recursion

References Dune::DiagonalMatrix< K, n >::diagonal().

◆ writeMatrixToMatlabHelper() [2/5]

template<class FieldType >
void Dune::writeMatrixToMatlabHelper ( const DynamicMatrix< FieldType > &  matrix,
int  rowOffset,
int  colOffset,
std::ostream &  s 
)

Helper method for the writeMatrixToMatlab routine.

#include <dune/istl/io.hh>

This specialization for DynamicMatrices ends the recursion

References Dune::DenseMatrix< MAT >::M(), and Dune::DenseMatrix< MAT >::N().

◆ writeMatrixToMatlabHelper() [3/5]

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.

#include <dune/istl/io.hh>

This specialization for FieldMatrices ends the recursion

◆ writeMatrixToMatlabHelper() [4/5]

template<class MatrixType >
void Dune::writeMatrixToMatlabHelper ( const MatrixType &  matrix,
int  externalRowOffset,
int  externalColOffset,
std::ostream &  s 
)

Helper method for the writeMatrixToMatlab routine.

#include <dune/istl/io.hh>

◆ writeMatrixToMatlabHelper() [5/5]

template<class FieldType , int dim>
void Dune::writeMatrixToMatlabHelper ( const ScaledIdentityMatrix< FieldType, dim > &  matrix,
int  rowOffset,
int  colOffset,
std::ostream &  s 
)

Helper method for the writeMatrixToMatlab routine.

#include <dune/istl/io.hh>

This specialization for DiagonalMatrices ends the recursion

References Dune::ScaledIdentityMatrix< K, n >::scalar().

Referenced by Dune::writeMatrixToMatlab().

◆ 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
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Nov 24, 23:30, 2024)