5#ifndef DUNE_ISTL_MATRIXMARKET_HH
6#define DUNE_ISTL_MATRIXMARKET_HH
24#include <dune/common/exceptions.hh>
25#include <dune/common/fmatrix.hh>
26#include <dune/common/fvector.hh>
27#include <dune/common/hybridutilities.hh>
28#include <dune/common/stdstreams.hh>
29#include <dune/common/simd/simd.hh>
64 namespace MatrixMarketImpl
86 struct mm_numeric_type<int>
95 static std::string str()
102 struct mm_numeric_type<double>
111 static std::string str()
118 struct mm_numeric_type<float>
127 static std::string str()
134 struct mm_numeric_type<
std::complex<double> >
143 static std::string str()
150 struct mm_numeric_type<
std::complex<float> >
159 static std::string str()
176 template<
typename T,
typename A>
179 static void print(std::ostream& os)
181 os<<
"%%MatrixMarket matrix coordinate ";
182 os<<mm_numeric_type<Simd::Scalar<typename Imp::BlockTraits<T>::field_type>>::str()<<
" general"<<std::endl;
186 template<
typename B,
typename A>
189 static void print(std::ostream& os)
191 os<<
"%%MatrixMarket matrix array ";
192 os<<mm_numeric_type<Simd::Scalar<typename Imp::BlockTraits<B>::field_type>>::str()<<
" general"<<std::endl;
196 template<
typename T,
int j>
197 struct mm_header_printer<FieldVector<T,j> >
199 static void print(std::ostream& os)
201 os<<
"%%MatrixMarket matrix array ";
202 os<<mm_numeric_type<T>::str()<<
" general"<<std::endl;
206 template<
typename T,
int i,
int j>
207 struct mm_header_printer<FieldMatrix<T,i,j> >
209 static void print(std::ostream& os)
211 os<<
"%%MatrixMarket matrix array ";
212 os<<mm_numeric_type<T>::str()<<
" general"<<std::endl;
227 template<
typename T,
typename A>
231 static_assert(IsNumber<T>::value,
"Only scalar entries are expected here!");
233 static void print(std::ostream& os,
const M&)
235 os<<
"% ISTL_STRUCT blocked ";
236 os<<
"1 1"<<std::endl;
240 template<
typename T,
typename A,
int i>
241 struct mm_block_structure_header<
BlockVector<FieldVector<T,i>,A> >
245 static void print(std::ostream& os,
const M&)
247 os<<
"% ISTL_STRUCT blocked ";
248 os<<i<<
" "<<1<<std::endl;
252 template<
typename T,
typename A>
253 struct mm_block_structure_header<BCRSMatrix<T,A> >
255 typedef BCRSMatrix<T,A> M;
256 static_assert(IsNumber<T>::value,
"Only scalar entries are expected here!");
258 static void print(std::ostream& os,
const M&)
260 os<<
"% ISTL_STRUCT blocked ";
261 os<<
"1 1"<<std::endl;
265 template<
typename T,
typename A,
int i,
int j>
266 struct mm_block_structure_header<BCRSMatrix<FieldMatrix<T,i,j>,A> >
268 typedef BCRSMatrix<FieldMatrix<T,i,j>,A> M;
270 static void print(std::ostream& os,
const M&)
272 os<<
"% ISTL_STRUCT blocked ";
273 os<<i<<
" "<<j<<std::endl;
278 template<
typename T,
int i,
int j>
279 struct mm_block_structure_header<FieldMatrix<T,i,j> >
281 typedef FieldMatrix<T,i,j> M;
283 static void print(std::ostream& os,
const M& m)
287 template<
typename T,
int i>
288 struct mm_block_structure_header<FieldVector<T,i> >
290 typedef FieldVector<T,i> M;
292 static void print(std::ostream& os,
const M& m)
296 enum LineType { MM_HEADER, MM_ISTLSTRUCT, DATA };
297 enum { MM_MAX_LINE_LENGTH=1025 };
299 enum MM_TYPE { coordinate_type, array_type, unknown_type };
301 enum MM_CTYPE { integer_type, double_type, complex_type, pattern, unknown_ctype };
303 enum MM_STRUCTURE { general, symmetric, skew_symmetric, hermitian, unknown_structure };
308 : type(coordinate_type), ctype(double_type), structure(general)
312 MM_STRUCTURE structure;
315 inline bool lineFeed(std::istream& file)
339 inline void skipComments(std::istream& file)
347 file.ignore(std::numeric_limits<std::streamsize>::max(),
'\n');
353 inline bool readMatrixMarketBanner(std::istream& file, MMHeader& mmHeader)
362 dverb<<buffer<<std::endl;
364 if(buffer!=
"%%MatrixMarket") {
366 file.ignore(std::numeric_limits<std::streamsize>::max(),
'\n');
377 if(buffer !=
"matrix")
380 file.ignore(std::numeric_limits<std::streamsize>::max(),
'\n');
394 std::transform(buffer.begin(), buffer.end(), buffer.begin(),
401 if(buffer !=
"array")
403 file.ignore(std::numeric_limits<std::streamsize>::max(),
'\n');
406 mmHeader.type=array_type;
410 if(buffer !=
"coordinate")
412 file.ignore(std::numeric_limits<std::streamsize>::max(),
'\n');
415 mmHeader.type=coordinate_type;
418 file.ignore(std::numeric_limits<std::streamsize>::max(),
'\n');
432 std::transform(buffer.begin(), buffer.end(), buffer.begin(),
438 if(buffer !=
"integer")
440 file.ignore(std::numeric_limits<std::streamsize>::max(),
'\n');
443 mmHeader.ctype=integer_type;
449 file.ignore(std::numeric_limits<std::streamsize>::max(),
'\n');
452 mmHeader.ctype=double_type;
456 if(buffer !=
"complex")
458 file.ignore(std::numeric_limits<std::streamsize>::max(),
'\n');
461 mmHeader.ctype=complex_type;
465 if(buffer !=
"pattern")
467 file.ignore(std::numeric_limits<std::streamsize>::max(),
'\n');
470 mmHeader.ctype=pattern;
473 file.ignore(std::numeric_limits<std::streamsize>::max(),
'\n');
482 std::transform(buffer.begin(), buffer.end(), buffer.begin(),
488 if(buffer !=
"general")
490 file.ignore(std::numeric_limits<std::streamsize>::max(),
'\n');
493 mmHeader.structure=general;
497 if(buffer !=
"hermitian")
499 file.ignore(std::numeric_limits<std::streamsize>::max(),
'\n');
502 mmHeader.structure=hermitian;
505 if(buffer.size()==1) {
506 file.ignore(std::numeric_limits<std::streamsize>::max(),
'\n');
514 if(buffer !=
"symmetric")
516 file.ignore(std::numeric_limits<std::streamsize>::max(),
'\n');
519 mmHeader.structure=symmetric;
523 if(buffer !=
"skew-symmetric")
525 file.ignore(std::numeric_limits<std::streamsize>::max(),
'\n');
528 mmHeader.structure=skew_symmetric;
531 file.ignore(std::numeric_limits<std::streamsize>::max(),
'\n');
536 file.ignore(std::numeric_limits<std::streamsize>::max(),
'\n');
539 file.ignore(std::numeric_limits<std::streamsize>::max(),
'\n');
545 template<std::
size_t brows, std::
size_t bcols>
546 std::tuple<std::size_t, std::size_t, std::size_t>
547 calculateNNZ(std::size_t rows, std::size_t cols, std::size_t entries,
const MMHeader& header)
549 std::size_t blockrows=rows/brows;
550 std::size_t blockcols=cols/bcols;
551 std::size_t blocksize=brows*bcols;
552 std::size_t blockentries=0;
554 switch(header.structure)
557 blockentries = entries/blocksize;
break;
558 case skew_symmetric :
559 blockentries = 2*entries/blocksize;
break;
561 blockentries = (2*entries-rows)/blocksize;
break;
563 blockentries = (2*entries-rows)/blocksize;
break;
565 throw Dune::NotImplemented();
567 return std::make_tuple(blockrows, blockcols, blockentries);
577 struct IndexData :
public T
579 std::size_t index = {};
614 std::istream& operator>>(std::istream& is, NumericWrapper<T>& num)
616 return is>>num.number;
619 inline std::istream& operator>>(std::istream& is, [[maybe_unused]] NumericWrapper<PatternDummy>& num)
630 bool operator<(
const IndexData<T>& i1,
const IndexData<T>& i2)
632 return i1.index<i2.index;
641 std::istream& operator>>(std::istream& is, IndexData<T>& data)
646 return is>>data.number;
655 std::istream& operator>>(std::istream& is, IndexData<
NumericWrapper<std::complex<T>>>& data)
665 data.number = {real.number, imag.number};
675 template<
typename D,
int brows,
int bcols>
684 void operator()(
const std::vector<std::set<IndexData<D> > >& rows,
687 static_assert(IsNumber<T>::value && brows==1 && bcols==1,
"Only scalar entries are expected here!");
688 for (
auto iter=matrix.
begin(); iter!= matrix.
end(); ++iter)
690 auto brow=iter.index();
691 for (
auto siter=rows[brow].begin(); siter != rows[brow].end(); ++siter)
692 (*iter)[siter->index] = siter->number;
702 void operator()(
const std::vector<std::set<IndexData<D> > >& rows,
703 BCRSMatrix<FieldMatrix<T,brows,bcols> >& matrix)
705 for (
auto iter=matrix.begin(); iter!= matrix.end(); ++iter)
707 for (
auto brow=iter.index()*brows,
708 browend=iter.index()*brows+brows;
709 brow<browend; ++brow)
711 for (
auto siter=rows[brow].begin(), send=rows[brow].end();
712 siter != send; ++siter)
713 (*iter)[siter->index/bcols][brow%brows][siter->index%bcols]=siter->number;
719 template<
int brows,
int bcols>
720 struct MatrixValuesSetter<PatternDummy,brows,bcols>
723 void operator()(
const std::vector<std::set<IndexData<PatternDummy> > >& rows,
728 template<
class T>
struct is_complex : std::false_type {};
729 template<
class T>
struct is_complex<
std::complex<T>> : std::true_type {};
733 std::enable_if_t<!is_complex<T>::value, T> conj(
const T& r){
738 std::enable_if_t<is_complex<T>::value, T> conj(
const T& r){
743 struct mm_multipliers
746 template<
typename B,
typename A>
747 struct mm_multipliers<BCRSMatrix<B,A> >
755 template<
typename B,
int i,
int j,
typename A>
756 struct mm_multipliers<BCRSMatrix<FieldMatrix<B,i,j>,A> >
764 template<
typename T,
typename A,
typename D>
766 std::istream& file, std::size_t entries,
767 const MMHeader& mmHeader,
const D&)
772 constexpr int brows = mm_multipliers<Matrix>::rows;
773 constexpr int bcols = mm_multipliers<Matrix>::cols;
778 std::vector<std::set<IndexData<D> > > rows(matrix.
N()*brows);
780 auto readloop = [&] (
auto symmetryFixup) {
781 for(std::size_t i = 0; i < entries; ++i) {
787 assert(row/bcols<matrix.
N());
789 assert(data.index/bcols<matrix.
M());
790 rows[row].insert(data);
792 symmetryFixup(row, data);
796 switch(mmHeader.structure)
799 readloop([](
auto...){});
802 readloop([&](
auto row,
auto data) {
803 IndexData<D> data_sym(data);
804 data_sym.index = row;
805 rows[data.index].insert(data_sym);
808 case skew_symmetric :
809 readloop([&](
auto row,
auto data) {
810 IndexData<D> data_sym;
811 data_sym.number = -data.number;
812 data_sym.index = row;
813 rows[data.index].insert(data_sym);
817 readloop([&](
auto row,
auto data) {
818 IndexData<D> data_sym;
819 data_sym.number = conj(data.number);
820 data_sym.index = row;
821 rows[data.index].insert(data_sym);
825 DUNE_THROW(Dune::NotImplemented,
826 "Only general, symmetric, skew-symmetric and hermitian is supported right now!");
831 for(
typename Matrix::CreateIterator iter=matrix.
createbegin();
834 for(std::size_t brow=iter.index()*brows, browend=iter.index()*brows+brows;
835 brow<browend; ++brow)
837 typedef typename std::set<IndexData<D> >::const_iterator Siter;
838 for(Siter siter=rows[brow].begin(), send=rows[brow].end();
839 siter != send; ++siter, ++nnz)
840 iter.insert(siter->index/bcols);
847 MatrixValuesSetter<D,brows,bcols> Setter;
849 Setter(rows, matrix);
852 inline std::tuple<std::string, std::string> splitFilename(
const std::string& filename) {
853 std::size_t lastdot = filename.find_last_of(
".");
854 if(lastdot == std::string::npos)
855 return std::make_tuple(filename,
"");
857 std::string potentialFileExtension = filename.substr(lastdot);
858 if (potentialFileExtension ==
".mm" || potentialFileExtension ==
".mtx")
859 return std::make_tuple(filename.substr(0, lastdot), potentialFileExtension);
861 return std::make_tuple(filename,
"");
867 class MatrixMarketFormatError :
public Dune::Exception
871 inline void mm_read_header(std::size_t& rows, std::size_t& cols,
872 MatrixMarketImpl::MMHeader& header, std::istream& istr,
875 using namespace MatrixMarketImpl;
877 if(!readMatrixMarketBanner(istr, header)) {
878 std::cerr <<
"First line was not a correct Matrix Market banner. Using default:\n"
879 <<
"%%MatrixMarket matrix coordinate real general"<<std::endl;
882 istr.seekg(0, std::ios::beg);
884 header.type=array_type;
890 throw MatrixMarketFormatError();
895 throw MatrixMarketFormatError();
899 template<
typename T,
typename A>
905 for (
int i=0; size>0; ++i, --size)
906 istr>>Simd::lane(lane,vector[i]);
909 template<
typename T,
typename A,
int entries>
910 void mm_read_vector_entries(
Dune::BlockVector<Dune::FieldVector<T,entries>,A>& vector,
915 for(
int i=0; size>0; ++i, --size) {
918 Simd::lane(lane, vector[i/entries][i%entries])=val;
929 template<
typename T,
typename A>
934 using namespace MatrixMarketImpl;
937 std::size_t rows, cols;
938 mm_read_header(rows,cols,header,istr,
true);
939 if(cols!=Simd::lanes<field_type>()) {
940 if(Simd::lanes<field_type>() == 1)
941 DUNE_THROW(MatrixMarketFormatError,
"cols!=1, therefore this is no vector!");
943 DUNE_THROW(MatrixMarketFormatError,
"cols does not match the number of lanes in the field_type!");
946 if(header.type!=array_type)
947 DUNE_THROW(MatrixMarketFormatError,
"Vectors have to be stored in array format!");
950 if constexpr (Dune::IsNumber<T>())
955 auto blocksize = dummy.size();
956 std::size_t size=rows/blocksize;
957 if(size*blocksize!=rows)
958 DUNE_THROW(MatrixMarketFormatError,
"Block size of vector is not correct!");
963 istr.ignore(std::numeric_limits<std::streamsize>::max(),
'\n');
964 for(
size_t l=0;l<Simd::lanes<field_type>();++l){
965 mm_read_vector_entries(vector, rows, istr, l);
975 template<
typename T,
typename A>
979 using namespace MatrixMarketImpl;
983 if(!readMatrixMarketBanner(istr, header)) {
984 std::cerr <<
"First line was not a correct Matrix Market banner. Using default:\n"
985 <<
"%%MatrixMarket matrix coordinate real general"<<std::endl;
988 istr.seekg(0, std::ios::beg);
992 std::size_t rows, cols, entries;
995 throw MatrixMarketFormatError();
1000 throw MatrixMarketFormatError();
1004 throw MatrixMarketFormatError();
1008 std::size_t nnz, blockrows, blockcols;
1011 constexpr int brows = mm_multipliers<Matrix>::rows;
1012 constexpr int bcols = mm_multipliers<Matrix>::cols;
1014 std::tie(blockrows, blockcols, nnz) = calculateNNZ<brows, bcols>(rows, cols, entries, header);
1016 istr.ignore(std::numeric_limits<std::streamsize>::max(),
'\n');
1019 matrix.
setSize(blockrows, blockcols, nnz);
1022 if(header.type==array_type)
1023 DUNE_THROW(Dune::NotImplemented,
"Array format currently not supported for matrices!");
1025 readSparseEntries(matrix, istr, entries, header, NumericWrapper<typename Matrix::field_type>());
1029 template<
typename B>
1030 void mm_print_entry(
const B& entry,
1035 if constexpr (IsNumber<B>())
1036 ostr << rowidx <<
" " << colidx <<
" " << entry << std::endl;
1039 for (
auto row=entry.begin(); row != entry.end(); ++row, ++rowidx) {
1041 for (
auto col = row->begin(); col != row->end(); ++col, ++coli)
1042 ostr<< rowidx<<
" "<<coli<<
" "<<*col<<std::endl;
1048 template<
typename V>
1049 void mm_print_vector_entry(
const V& entry, std::ostream& ostr,
1050 const std::integral_constant<int,1>&,
1053 ostr<<Simd::lane(lane,entry)<<std::endl;
1057 template<
typename V>
1058 void mm_print_vector_entry(
const V& vector, std::ostream& ostr,
1059 const std::integral_constant<int,0>&,
1062 using namespace MatrixMarketImpl;
1065 const int isnumeric = mm_numeric_type<Simd::Scalar<typename V::block_type>>::is_numeric;
1066 typedef typename V::const_iterator VIter;
1068 for(VIter i=vector.begin(); i != vector.end(); ++i)
1070 mm_print_vector_entry(*i, ostr,
1071 std::integral_constant<int,isnumeric>(),
1075 template<
typename T,
typename A>
1076 std::size_t countEntries(
const BlockVector<T,A>& vector)
1078 return vector.size();
1081 template<
typename T,
typename A,
int i>
1082 std::size_t countEntries(
const BlockVector<FieldVector<T,i>,A>& vector)
1084 return vector.size()*i;
1088 template<
typename V>
1090 const std::integral_constant<int,0>&)
1092 using namespace MatrixMarketImpl;
1093 typedef typename V::field_type field_type;
1095 ostr<<countEntries(vector)<<
" "<<Simd::lanes<field_type>()<<std::endl;
1096 const int isnumeric = mm_numeric_type<Simd::Scalar<V>>::is_numeric;
1097 for(
size_t l=0;l<Simd::lanes<field_type>(); ++l){
1098 mm_print_vector_entry(vector,ostr, std::integral_constant<int,isnumeric>(), l);
1103 template<
typename M>
1106 const std::integral_constant<int,1>&)
1108 ostr<<matrix.N()*MatrixMarketImpl::mm_multipliers<M>::rows<<
" "
1109 <<matrix.M()*MatrixMarketImpl::mm_multipliers<M>::cols<<
" "
1112 typedef typename M::const_iterator riterator;
1113 typedef typename M::ConstColIterator citerator;
1114 for(riterator row=matrix.begin(); row != matrix.end(); ++row)
1115 for(citerator col = row->begin(); col != row->end(); ++col)
1117 mm_print_entry(*col, row.index()*MatrixMarketImpl::mm_multipliers<M>::rows+1,
1118 col.index()*MatrixMarketImpl::mm_multipliers<M>::cols+1, ostr);
1125 template<
typename M>
1129 using namespace MatrixMarketImpl;
1132 mm_header_printer<M>::print(ostr);
1133 mm_block_structure_header<M>::print(ostr,matrix);
1138 static const int default_precision = -1;
1150 template<
typename M>
1152 std::string filename,
1153 int prec=default_precision)
1155 auto [pureFilename, extension] = MatrixMarketImpl::splitFilename(filename);
1156 std::string rfilename;
1158 if (extension !=
"") {
1159 rfilename = pureFilename + extension;
1160 file.open(rfilename.c_str());
1162 DUNE_THROW(IOError,
"Could not open file for storage: " << rfilename.c_str());
1166 rfilename = pureFilename +
".mm";
1167 file.open(rfilename.c_str());
1169 DUNE_THROW(IOError,
"Could not open file for storage: " << rfilename.c_str());
1172 file.setf(std::ios::scientific,std::ios::floatfield);
1174 file.precision(prec);
1194 template<
typename M,
typename G,
typename L>
1196 std::string filename,
1198 bool storeIndices=
true,
1199 int prec=default_precision)
1202 int rank = comm.communicator().rank();
1204 auto [pureFilename, extension] = MatrixMarketImpl::splitFilename(filename);
1205 std::string rfilename;
1207 if (extension !=
"") {
1208 rfilename = pureFilename +
"_" + std::to_string(rank) + extension;
1209 file.open(rfilename.c_str());
1210 dverb<< rfilename <<std::endl;
1212 DUNE_THROW(IOError,
"Could not open file for storage: " << rfilename.c_str());
1216 rfilename = pureFilename +
"_" + std::to_string(rank) +
".mm";
1217 file.open(rfilename.c_str());
1218 dverb<< rfilename <<std::endl;
1220 DUNE_THROW(IOError,
"Could not open file for storage: " << rfilename.c_str());
1222 file.setf(std::ios::scientific,std::ios::floatfield);
1224 file.precision(prec);
1232 rfilename = pureFilename +
"_" + std::to_string(rank) +
".idx";
1233 file.open(rfilename.c_str());
1235 DUNE_THROW(IOError,
"Could not open file for storage: " << rfilename.c_str());
1236 file.setf(std::ios::scientific,std::ios::floatfield);
1238 typedef typename IndexSet::const_iterator Iterator;
1239 for(Iterator iter = comm.
indexSet().begin();
1240 iter != comm.
indexSet().end(); ++iter) {
1241 file << iter->global()<<
" "<<(std::size_t)iter->local()<<
" "
1242 <<(int)iter->local().attribute()<<
" "<<(int)iter->local().isPublic()<<std::endl;
1245 file<<
"neighbours:";
1246 const std::set<int>& neighbours=comm.
remoteIndices().getNeighbours();
1247 typedef std::set<int>::const_iterator SIter;
1248 for(SIter neighbour=neighbours.begin(); neighbour != neighbours.end(); ++neighbour) {
1249 file<<
" "<< *neighbour;
1268 template<
typename M,
typename G,
typename L>
1270 const std::string& filename,
1272 bool readIndices=
true)
1274 using namespace MatrixMarketImpl;
1277 typedef typename LocalIndexT::Attribute Attribute;
1279 int rank = comm.communicator().rank();
1281 auto [pureFilename, extension] = MatrixMarketImpl::splitFilename(filename);
1282 std::string rfilename;
1284 if (extension !=
"") {
1285 rfilename = pureFilename +
"_" + std::to_string(rank) + extension;
1286 file.open(rfilename.c_str(), std::ios::in);
1287 dverb<< rfilename <<std::endl;
1289 DUNE_THROW(IOError,
"Could not open file: " << rfilename.c_str());
1293 rfilename = pureFilename +
"_" + std::to_string(rank) +
".mm";
1294 file.open(rfilename.c_str(), std::ios::in);
1296 rfilename = pureFilename +
"_" + std::to_string(rank) +
".mtx";
1297 file.open(rfilename.c_str(), std::ios::in);
1298 dverb<< rfilename <<std::endl;
1300 DUNE_THROW(IOError,
"Could not open file: " << rfilename.c_str());
1311 IndexSet& pis=comm.pis;
1312 rfilename = pureFilename +
"_" + std::to_string(rank) +
".idx";
1313 file.open(rfilename.c_str());
1315 DUNE_THROW(IOError,
"Could not open file: " << rfilename.c_str());
1317 DUNE_THROW(InvalidIndexSetState,
"Index set is not empty!");
1320 while(!file.eof() && file.peek()!=
'n') {
1329 pis.add(g,LocalIndexT(l,Attribute(c),b));
1337 if(s!=
"neighbours:")
1338 DUNE_THROW(MatrixMarketFormatError,
"was expecting the string: \"neighbours:\"");
1340 while(!file.eof()) {
1346 comm.ri.setNeighbours(nb);
1348 comm.ri.template rebuild<false>();
1363 template<
typename M>
1365 const std::string& filename)
1367 auto [pureFilename, extension] = MatrixMarketImpl::splitFilename(filename);
1368 std::string rfilename;
1370 if (extension !=
"") {
1371 rfilename = pureFilename + extension;
1372 file.open(rfilename.c_str());
1374 DUNE_THROW(IOError,
"Could not open file: " << rfilename.c_str());
1378 rfilename = pureFilename +
".mm";
1379 file.open(rfilename.c_str(), std::ios::in);
1381 rfilename = pureFilename +
".mtx";
1382 file.open(rfilename.c_str(), std::ios::in);
1384 DUNE_THROW(IOError,
"Could not open file: " << rfilename.c_str());
Implementation of the BCRSMatrix class.
This file implements a vector space as a tensor product of a given vector space. The number of compon...
A sparse block matrix with compressed row storage.
Definition: bcrsmatrix.hh:466
Iterator begin()
Get iterator to first row.
Definition: bcrsmatrix.hh:675
Iterator end()
Get iterator to one beyond last row.
Definition: bcrsmatrix.hh:681
CreateIterator createend()
get create iterator pointing to one after the last block
Definition: bcrsmatrix.hh:1103
size_type M() const
number of columns (counted in blocks)
Definition: bcrsmatrix.hh:1978
CreateIterator createbegin()
get initial create iterator
Definition: bcrsmatrix.hh:1097
size_type N() const
number of rows (counted in blocks)
Definition: bcrsmatrix.hh:1972
void setBuildMode(BuildMode bm)
Sets the build mode of the matrix.
Definition: bcrsmatrix.hh:833
void setSize(size_type rows, size_type columns, size_type nnz=0)
Set the size of the matrix.
Definition: bcrsmatrix.hh:861
A vector of blocks with memory management.
Definition: bvector.hh:395
void resize(size_type size)
Resize the vector.
Definition: bvector.hh:503
typename Imp::BlockTraits< B >::field_type field_type
export the type representing the field
Definition: bvector.hh:401
A generic dynamic dense matrix.
Definition: matrix.hh:561
A class setting up standard communication for a two-valued attribute set with owner/overlap/copy sema...
Definition: owneroverlapcopy.hh:174
const ParallelIndexSet & indexSet() const
Get the underlying parallel index set.
Definition: owneroverlapcopy.hh:462
const RemoteIndices & remoteIndices() const
Get the underlying remote indices.
Definition: owneroverlapcopy.hh:471
Dune::ParallelIndexSet< GlobalIdType, LI, 512 > ParallelIndexSet
The type of the parallel index set.
Definition: owneroverlapcopy.hh:449
void readMatrixMarket(Dune::BCRSMatrix< T, A > &matrix, std::istream &istr)
Reads a sparse matrix from a matrix market file.
Definition: matrixmarket.hh:976
void writeMatrixMarket(const M &matrix, std::ostream &ostr)
writes a ISTL matrix or vector to a stream in matrix market format.
Definition: matrixmarket.hh:1126
void storeMatrixMarket(const M &matrix, std::string filename, const OwnerOverlapCopyCommunication< G, L > &comm, bool storeIndices=true, int prec=default_precision)
Stores a parallel matrix/vector in matrix market format in a file.
Definition: matrixmarket.hh:1195
void loadMatrixMarket(M &matrix, const std::string &filename)
Load a matrix/vector stored in matrix market format.
Definition: matrixmarket.hh:1364
auto countNonZeros(const M &, typename std::enable_if_t< Dune::IsNumber< M >::value > *sfinae=nullptr)
Get the number of nonzero fields in the matrix.
Definition: matrixutils.hh:119
bool operator<(const IndexData< T > &i1, const IndexData< T > &i2)
LessThan operator.
Definition: matrixmarket.hh:630
Some handy generic functions for ISTL matrices.
Classes providing communication interfaces for overlapping Schwarz methods.
Test whether a type is an ISTL Matrix.
Definition: matrixutils.hh:504
Functor to the data values of the matrix.
Definition: matrixmarket.hh:677
void operator()(const std::vector< std::set< IndexData< D > > > &rows, BCRSMatrix< T > &matrix)
Sets the matrix values.
Definition: matrixmarket.hh:684
void operator()(const std::vector< std::set< IndexData< D > > > &rows, BCRSMatrix< FieldMatrix< T, brows, bcols > > &matrix)
Sets the matrix values.
Definition: matrixmarket.hh:702
a wrapper class of numeric values.
Definition: matrixmarket.hh:595
Utility class for marking the pattern type of the MatrixMarket matrices.
Definition: matrixmarket.hh:607
Helper metaprogram to get the matrix market string representation of the numeric type.
Definition: matrixmarket.hh:76
@ is_numeric
Whether T is a supported numeric type.
Definition: matrixmarket.hh:81