18#include <dune/common/fvector.hh>
19#include <dune/common/fmatrix.hh>
20#include <dune/istl/bvector.hh>
21#include <dune/istl/bcrsmatrix.hh>
29 template <
class OutIter>
36 template <
class OutIter>
44 template <
class K,
int size,
class OutIter>
47 for (
size_t i=0; i<size; ++i)
52 std::cerr << __FILE__ <<
':' << __LINE__ <<
":VectorToSequence::call v[" << i <<
"] = inf\n" << std::flush;
57 std::cerr << __FILE__ <<
':' << __LINE__ <<
":VectorToSequence::call v[" << i <<
"] = nan\n" << std::flush;
75 template <
class B,
class A,
class OutIter>
78 for (
int i=0; i<v.N(); ++i)
83 template <
class K,
class OutIter>
86 for (
auto const& x: v)
96 template <
class InIter>
103 template <
class InIter>
110 template <
class K,
int size,
class InIter>
113 for (
size_t i=0; i<v.N(); ++i)
126 template <
class B,
class A,
class InIter>
129 for (
int i=0; i<v.N(); ++i)
134 template <
class K,
class InIter>
153 template <
class Entry>
159 template <
class Entry,
int n>
176 template <
class Matrix>
179 template <
class K,
int N,
int M,
class Allocator>
184 typedef typename Matrix::ConstRowIterator RI;
185 typedef typename Matrix::ConstColIterator CI;
212 template <
class OutIteratorI,
class OutIteratorD>
213 static void call(Matrix
const& a,
214 OutIteratorI& i, OutIteratorI& j,
216 int startrow,
int const startcol,
217 bool onlyLowerTriangle =
false,
218 bool symmetric =
false)
220 for (RI row=a.begin(); row!=a.end(); ++row)
221 for (CI col=row->begin() ; col!=row->end(); ++col)
223 if (!onlyLowerTriangle || (row.index()>=col.index()))
225 (row.index()==col.index()) && onlyLowerTriangle);
226 if (symmetric && !onlyLowerTriangle && row.index()>col.index())
244 static size_t nnz(Matrix
const& a,
245 bool onlyLowerTriangle =
false,
246 bool symmetric =
false)
250 for (RI row=a.begin(); row!=rend; ++row)
252 CI cend = row->end();
253 for (CI col=row->begin(); col!=cend; ++col)
255 if (!onlyLowerTriangle || (row.index()>=col.index()))
258 if (symmetric && !onlyLowerTriangle && row.index()>col.index())
266 template <
class Entry,
class Index>
267 class NumaBCRSMatrix;
269 template <
class K,
int N,
int M,
class Index>
300 template <
class OutIteratorI,
class OutIteratorD>
301 static void call(Matrix
const& a,
302 OutIteratorI& i, OutIteratorI& j,
304 int startrow,
int const startcol,
305 bool onlyLowerTriangle =
false,
306 bool symmetric =
false)
309 for (
auto row=a.
begin(); row!=rend; ++row)
311 auto cend = row->end();
312 for (
auto col=row->begin() ; col!=cend; ++col)
314 if (!onlyLowerTriangle || (row.index()>=col.index()))
316 (row.index()==col.index()) && onlyLowerTriangle);
317 if (symmetric && !onlyLowerTriangle && row.index()>col.index())
336 static size_t nnz(Matrix
const& a,
337 bool onlyLowerTriangle =
false,
338 bool symmetric =
false)
342 for (
auto row=a.
begin(); row!=rend; ++row)
344 auto cend = row->end();
345 for (
auto col=row->begin(); col!=cend; ++col)
347 if (!onlyLowerTriangle || (row.index()>=col.index()))
350 if (symmetric && !onlyLowerTriangle && row.index()>col.index())
358 template <
class K,
int n,
int m>
361 template <
class OutIteratorI,
class OutIteratorD>
363 OutIteratorI& i, OutIteratorI& j,
365 int startrow,
int const startcol,
366 bool onlyLowerTriangle =
false)
368 if (onlyLowerTriangle)
371 for (
int row=0; row<n; ++row)
372 for (
int col=0; col<=row; ++col) {
373 *i++ = row + startrow;
374 *j++ = col + startcol;
379 for (
int row=0; row<n; ++row)
380 for (
int col=0; col<m; ++col) {
381 *i++ = row + startrow;
382 *j++ = col + startcol;
387 template <
class OutIteratorI,
class OutIteratorD>
389 OutIteratorI& i, OutIteratorI& j,
391 int startrow,
int const startcol)
393 for (
int row=0; row<n; ++row)
394 for (
int col=0; col<m; ++col) {
395 *i++ = col + startrow;
396 *j++ = row + startcol;
402 bool onlyLowerTriangle =
false)
404 if (onlyLowerTriangle) {
417 template <
class Matrix,
class OutIteratorI,
class OutIteratorD>
419 OutIteratorI i, OutIteratorI j,
439 template <
class Index>
441 std::vector<Index>
const& ridx,
442 std::vector<Index>
const& cidx,
445 std::vector<std::vector<Index>> rowColumnIndices(nrows);
446 for(Index i=0; i<ridx.size(); ++i)
447 rowColumnIndices[ridx[i]/nr].push_back(cidx[i]/nc);
454 for (
auto& r: rowColumnIndices)
456 std::sort(begin(r),end(r));
457 r.erase(std::unique(begin(r),end(r)),end(r));
459 return rowColumnIndices;
465 template <
class B,
class A>
472 int const width = prec + 3;
475 for (RI row=a.begin(); row!=a.end(); ++row) {
477 for (CI col=row->begin() ; col!=row->end(); ++col) {
478 out.width((col.index()-oldidx-1)*(width+1)); out <<
"";
479 out.setf(std::ios_base::fixed,std::ios_base::floatfield);
480 out.width(width); out.precision(prec); out << *col <<
' ';
481 oldidx = col.index();
A NUMA-aware compressed row storage matrix adhering mostly to the Dune ISTL interface (to complete....
iterator end()
returns an iterator to the first row
iterator begin()
returns an iterator to the first row
This file contains various utility functions that augment the basic functionality of Dune.
std::vector< std::vector< Index > > getBCRSIndicesFromTriplet(Index nrows, std::vector< Index > const &ridx, std::vector< Index > const &cidx, int nr=1, int nc=1)
Sorts the sparse matrix nonzero positions into row buckets.
void matrix_to_triplet(Matrix const &a, OutIteratorI i, OutIteratorI j, OutIteratorD z)
converts a matrix to the coordinate (triplet) format.
OutIter vectorToSequence(double x, OutIter iter)
constexpr bool contiguousStorage
InIter vectorFromSequence(FunctionSpaceElement< Space, m > &v, InIter in)
std::ostream & operator<<(std::ostream &stream, VTKReader::FunctionInfo const &info)
static const bool contiguous
static const bool contiguous
static const bool contiguous
static size_t nnz(Matrix const &a, bool onlyLowerTriangle=false, bool symmetric=false)
returns the number of structurally nonzero scalars in the matrix
static void call(Matrix const &a, OutIteratorI &i, OutIteratorI &j, OutIteratorD &z, int startrow, int const startcol, bool onlyLowerTriangle=false, bool symmetric=false)
converts a Dune matrix into triplet format
static size_t nnz(Dune::FieldMatrix< K, n, m > const &a, bool onlyLowerTriangle=false)
static void callTransposed(Dune::FieldMatrix< K, n, m > const &a, OutIteratorI &i, OutIteratorI &j, OutIteratorD &z, int startrow, int const startcol)
static void call(Dune::FieldMatrix< K, n, m > const &a, OutIteratorI &i, OutIteratorI &j, OutIteratorD &z, int startrow, int const startcol, bool onlyLowerTriangle=false)
static void call(Matrix const &a, OutIteratorI &i, OutIteratorI &j, OutIteratorD &z, int startrow, int const startcol, bool onlyLowerTriangle=false, bool symmetric=false)
converts a Dune matrix into triplet format
static size_t nnz(Matrix const &a, bool onlyLowerTriangle=false, bool symmetric=false)
returns the number of structurally nonzero scalars in the matrix
A class template that supports converting certain Dune matrices into the coordinate (triplet) format.