3#ifndef DUNE_ISTL_MATRIXMARKET_HH
4#define DUNE_ISTL_MATRIXMARKET_HH
15#include <dune/common/fmatrix.hh>
16#include <dune/common/tuples.hh>
17#include <dune/common/unused.hh>
47 namespace MatrixMarketImpl
78 static std::string
str()
94 static std::string
str()
159 template<
typename T,
typename A,
int i,
int j>
164 os<<
"%%MatrixMarket matrix coordinate ";
169 template<
typename B,
typename A>
174 os<<
"%%MatrixMarket matrix array ";
179 template<
typename T,
int j>
184 os<<
"%%MatrixMarket matrix array ";
189 template<
typename T,
int i,
int j>
194 os<<
"%%MatrixMarket matrix array ";
210 template<
typename T,
typename A,
int i>
217 os<<
"% ISTL_STRUCT blocked ";
218 os<<i<<
" "<<1<<std::endl;
222 template<
typename T,
typename A,
int i,
int j>
229 os<<
"% ISTL_STRUCT blocked ";
230 os<<i<<
" "<<j<<std::endl;
235 template<
typename T,
int i,
int j>
244 template<
typename T,
int i>
304 file.ignore(std::numeric_limits<std::streamsize>::max(),
'\n');
319 std::cout<<
buffer<<std::endl;
321 if(
buffer!=
"%%MatrixMarket") {
323 file.ignore(std::numeric_limits<std::streamsize>::max(),
'\n');
337 file.ignore(std::numeric_limits<std::streamsize>::max(),
'\n');
360 file.ignore(std::numeric_limits<std::streamsize>::max(),
'\n');
367 if(
buffer !=
"coordinate")
369 file.ignore(std::numeric_limits<std::streamsize>::max(),
'\n');
375 file.ignore(std::numeric_limits<std::streamsize>::max(),
'\n');
397 file.ignore(std::numeric_limits<std::streamsize>::max(),
'\n');
406 file.ignore(std::numeric_limits<std::streamsize>::max(),
'\n');
415 file.ignore(std::numeric_limits<std::streamsize>::max(),
'\n');
424 file.ignore(std::numeric_limits<std::streamsize>::max(),
'\n');
430 file.ignore(std::numeric_limits<std::streamsize>::max(),
'\n');
447 file.ignore(std::numeric_limits<std::streamsize>::max(),
'\n');
456 file.ignore(std::numeric_limits<std::streamsize>::max(),
'\n');
463 file.ignore(std::numeric_limits<std::streamsize>::max(),
'\n');
473 file.ignore(std::numeric_limits<std::streamsize>::max(),
'\n');
480 if(
buffer !=
"skew-symmetric")
482 file.ignore(std::numeric_limits<std::streamsize>::max(),
'\n');
488 file.ignore(std::numeric_limits<std::streamsize>::max(),
'\n');
492 file.ignore(std::numeric_limits<std::streamsize>::max(),
'\n');
495 file.ignore(std::numeric_limits<std::streamsize>::max(),
'\n');
501 template<std::
size_t brows, std::
size_t bcols>
572 return is>>
num.number;
589 return i1.index<
i2.index;
612 template<
typename D,
int brows,
int bcols>
624 for(
typename M::RowIterator
iter=matrix.begin();
631 typedef typename std::set<IndexData<D> >::const_iterator
Siter;
640 template<
int brows,
int bcols>
649 template<
typename T,
typename A,
int brows,
int bcols,
typename D>
651 std::istream&
file, std::size_t entries,
658 std::vector<std::set<IndexData<D> > > rows(matrix.N()*
brows);
660 for(; entries>0; --entries) {
669 rows[row].insert(
data);
678 for(
typename Matrix::CreateIterator
iter=matrix.createbegin();
684 typedef typename std::set<IndexData<D> >::const_iterator
Siter;
708 using namespace MatrixMarketImpl;
711 std::cerr <<
"First line was not a correct Matrix Market banner. Using default:\n"
712 <<
"%%MatrixMarket matrix coordinate real general"<<std::endl;
715 istr.seekg(0, std::ios::beg);
732 template<
typename T,
typename A,
int entries>
737 for(
int i=0; size>0; ++i, --size) {
740 vector[i/entries][i%entries]=
val;
751 template<
typename T,
typename A,
int entries>
755 using namespace MatrixMarketImpl;
758 std::size_t rows, cols;
763 if(
header.type!=array_type)
766 std::size_t size=rows/entries;
767 if(size*entries!=rows)
772 istr.ignore(std::numeric_limits<std::streamsize>::max(),
'\n');
784 template<
typename T,
typename A,
int brows,
int bcols>
788 using namespace MatrixMarketImpl;
792 std::cerr <<
"First line was not a correct Matrix Market banner. Using default:\n"
793 <<
"%%MatrixMarket matrix coordinate real general"<<std::endl;
796 istr.seekg(0, std::ios::beg);
800 std::size_t rows, cols, entries;
820 istr.ignore(std::numeric_limits<std::streamsize>::max(),
'\n');
826 if(
header.type==array_type)
836 template<
typename B,
int i,
int j,
typename A>
845 template<
typename B,
int i,
int j>
853 for(
riterator row=entry.begin(); row != entry.end(); ++row, ++
rowidx) {
863 const std::integral_constant<int,1>&)
865 ostr<<entry<<std::endl;
871 const std::integral_constant<int,0>&)
873 using namespace MatrixMarketImpl;
876 const int isnumeric = mm_numeric_type<typename V::block_type>::is_numeric;
877 typedef typename V::const_iterator
VIter;
879 for(
VIter i=vector.begin(); i != vector.end(); ++i)
882 std::integral_constant<int,isnumeric>());
885 template<
typename T,
typename A,
int i>
888 return vector.size()*i;
894 const std::integral_constant<int,0>&)
896 using namespace MatrixMarketImpl;
899 const int isnumeric = mm_numeric_type<typename V::block_type>::is_numeric;
907 const std::integral_constant<int,1>&)
913 typedef typename M::const_iterator
riterator;
914 typedef typename M::ConstColIterator
citerator;
915 for(
riterator row=matrix.begin(); row != matrix.end(); ++row)
930 using namespace MatrixMarketImpl;
933 mm_header_printer<M>::print(
ostr);
934 mm_block_structure_header<M>::print(
ostr,matrix);
955 file.setf(std::ios::scientific,std::ios::floatfield);
974 template<
typename M,
typename G,
typename L>
981 int rank = comm.communicator().rank();
987 file.setf(std::ios::scientific,std::ios::floatfield);
998 file.setf(std::ios::scientific,std::ios::floatfield);
1000 typedef typename IndexSet::const_iterator Iterator;
1001 for(Iterator
iter = comm.indexSet().begin();
1002 iter != comm.indexSet().end(); ++
iter) {
1003 file <<
iter->global()<<
" "<<(std::size_t)
iter->local()<<
" "
1004 <<(
int)
iter->local().attribute()<<
" "<<(
int)
iter->local().isPublic()<<std::endl;
1007 file<<
"neighbours:";
1008 const std::set<int>& neighbours=comm.remoteIndices().getNeighbours();
1009 typedef std::set<int>::const_iterator
SIter;
1030 template<
typename M,
typename G,
typename L>
1036 using namespace MatrixMarketImpl;
1039 typedef typename LocalIndex::Attribute Attribute;
1041 int rank = comm.communicator().rank();
1059 IndexSet& pis=comm.pis;
1067 while(!
file.eof() &&
file.peek()!=
'n') {
1076 pis.add(
g,LocalIndex(
l,Attribute(c),b));
1084 if(
s!=
"neighbours:")
1087 while(!
file.eof()) {
1093 comm.ri.setNeighbours(
nb);
1110 template<
typename M>
Classes providing communication interfaces for overlapping Schwarz methods.
Some handy generic functions for ISTL matrices.
Implementation of the BCRSMatrix class.
Col col
Definition matrixmatrix.hh:347
int countNonZeros(const M &matrix)
Get the number of nonzero fields in the matrix.
Definition matrixutils.hh:153
void readMatrixMarket(Dune::BlockVector< Dune::FieldVector< T, entries >, A > &vector, std::istream &istr)
Reads a BlockVector from a matrix market file.
Definition matrixmarket.hh:752
void loadMatrixMarket(M &matrix, const std::string &filename, OwnerOverlapCopyCommunication< G, L > &comm, bool readIndices=true)
Load a parallel matrix/vector stored in matrix market format.
Definition matrixmarket.hh:1031
void writeMatrixMarket(const V &vector, std::ostream &ostr, const std::integral_constant< int, 0 > &)
Definition matrixmarket.hh:893
std::size_t countEntries(const BlockVector< FieldVector< T, i >, A > &vector)
Definition matrixmarket.hh:886
void mm_read_vector_entries(Dune::BlockVector< Dune::FieldVector< T, entries >, A > &vector, std::size_t size, std::istream &istr)
Definition matrixmarket.hh:733
void mm_print_vector_entry(const V &entry, std::ostream &ostr, const std::integral_constant< int, 1 > &)
Definition matrixmarket.hh:862
void 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)
Definition matrixmarket.hh:846
void storeMatrixMarket(const M &matrix, std::string filename)
Stores a parallel matrix/vector in matrix market format in a file.
Definition matrixmarket.hh:951
void mm_read_header(std::size_t &rows, std::size_t &cols, MatrixMarketImpl::MMHeader &header, std::istream &istr, bool isVector)
Definition matrixmarket.hh:704
Definition basearray.hh:19
bool operator<(const IndexData< T > &i1, const IndexData< T > &i2)
LessThan operator.
Definition matrixmarket.hh:587
LineType
Definition matrixmarket.hh:253
@ DATA
Definition matrixmarket.hh:253
@ MM_HEADER
Definition matrixmarket.hh:253
@ MM_ISTLSTRUCT
Definition matrixmarket.hh:253
bool readMatrixMarketBanner(std::istream &file, MMHeader &mmHeader)
Definition matrixmarket.hh:310
void readSparseEntries(Dune::BCRSMatrix< Dune::FieldMatrix< T, brows, bcols >, A > &matrix, std::istream &file, std::size_t entries, const MMHeader &mmHeader, const D &)
Definition matrixmarket.hh:650
MM_TYPE
Definition matrixmarket.hh:256
@ array_type
Definition matrixmarket.hh:256
@ coordinate_type
Definition matrixmarket.hh:256
@ unknown_type
Definition matrixmarket.hh:256
std::istream & operator>>(std::istream &is, NumericWrapper< T > &num)
Definition matrixmarket.hh:570
void skipComments(std::istream &file)
Definition matrixmarket.hh:296
bool lineFeed(std::istream &file)
Definition matrixmarket.hh:272
MM_STRUCTURE
Definition matrixmarket.hh:260
@ skew_symmetric
Definition matrixmarket.hh:260
@ general
Definition matrixmarket.hh:260
@ hermitian
Definition matrixmarket.hh:260
@ unknown_structure
Definition matrixmarket.hh:260
@ symmetric
Definition matrixmarket.hh:260
MM_CTYPE
Definition matrixmarket.hh:258
@ unknown_ctype
Definition matrixmarket.hh:258
@ pattern
Definition matrixmarket.hh:258
@ complex_type
Definition matrixmarket.hh:258
@ double_type
Definition matrixmarket.hh:258
@ integer_type
Definition matrixmarket.hh:258
@ MM_MAX_LINE_LENGTH
Definition matrixmarket.hh:254
Dune::tuple< std::size_t, std::size_t, std::size_t > calculateNNZ(std::size_t rows, std::size_t cols, std::size_t entries, const MMHeader &header)
Definition matrixmarket.hh:503
Statistics about compression achieved in implicit mode.
Definition bcrsmatrix.hh:81
A sparse block matrix with compressed row storage.
Definition bcrsmatrix.hh:412
A vector of blocks with memory management.
Definition bvector.hh:309
A generic dynamic dense matrix.
Definition matrix.hh:555
Helper metaprogram to get the matrix market string representation of the numeric type.
Definition matrixmarket.hh:59
@ is_numeric
Whether T is a supported numeric type.
Definition matrixmarket.hh:64
static std::string str()
Definition matrixmarket.hh:78
static std::string str()
Definition matrixmarket.hh:94
static std::string str()
Definition matrixmarket.hh:110
static std::string str()
Definition matrixmarket.hh:126
static std::string str()
Definition matrixmarket.hh:142
Meta program to write the correct Matrix Market header.
Definition matrixmarket.hh:157
static void print(std::ostream &os)
Definition matrixmarket.hh:162
static void print(std::ostream &os)
Definition matrixmarket.hh:172
static void print(std::ostream &os)
Definition matrixmarket.hh:182
static void print(std::ostream &os)
Definition matrixmarket.hh:192
Metaprogram for writing the ISTL block structure header.
Definition matrixmarket.hh:208
BlockVector< FieldVector< T, i >, A > M
Definition matrixmarket.hh:213
static void print(std::ostream &os, const M &)
Definition matrixmarket.hh:215
BCRSMatrix< FieldMatrix< T, i, j >, A > M
Definition matrixmarket.hh:225
static void print(std::ostream &os, const M &)
Definition matrixmarket.hh:227
static void print(std::ostream &os, const M &m)
Definition matrixmarket.hh:240
FieldMatrix< T, i, j > M
Definition matrixmarket.hh:238
static void print(std::ostream &os, const M &m)
Definition matrixmarket.hh:249
FieldVector< T, i > M
Definition matrixmarket.hh:247
Definition matrixmarket.hh:263
MM_STRUCTURE structure
Definition matrixmarket.hh:269
MM_TYPE type
Definition matrixmarket.hh:267
MMHeader()
Definition matrixmarket.hh:264
MM_CTYPE ctype
Definition matrixmarket.hh:268
Definition matrixmarket.hh:534
std::size_t index
Definition matrixmarket.hh:535
a wrapper class of numeric values.
Definition matrixmarket.hh:551
T number
Definition matrixmarket.hh:552
Utility class for marking the pattern type of the MatrixMarket matrices.
Definition matrixmarket.hh:563
Functor to the data values of the matrix.
Definition matrixmarket.hh:614
void operator()(const std::vector< std::set< IndexData< D > > > &rows, M &matrix)
Sets the matrixvalues.
Definition matrixmarket.hh:621
void operator()(const std::vector< std::set< IndexData< PatternDummy > > > &rows, M &matrix)
Definition matrixmarket.hh:644
Definition matrixmarket.hh:701
Definition matrixmarket.hh:834
Definition matrixutils.hh:25
Test whether a type is an ISTL Matrix.
Definition matrixutils.hh:478
A class setting up standard communication for a two-valued attribute set with owner/overlap/copy sema...
Definition owneroverlapcopy.hh:173