2#ifndef DUNE_PDELAB_BACKEND_SIMPLE_SPARSE_HH
3#define DUNE_PDELAB_BACKEND_SIMPLE_SPARSE_HH
10#include <unordered_set>
12#include <dune/common/typetraits.hh>
23 :
public std::vector< std::unordered_set<std::size_t> >
28 typedef std::unordered_set<std::size_t>
col_type;
30 template<
typename RI,
typename CI>
33 (*this)[ri.back()].insert(ci.back());
37 :
std::vector<
std::unordered_set<
std::size_t> >(rows)
42 template<
template<
typename>
class C,
typename ET,
typename I>
76 template<
typename GFSV,
typename GFSU,
template<
typename>
class C,
typename ET,
typename I>
78 :
public Backend::impl::Wrapper<SparseMatrixData<C,ET,I> >
87 friend Backend::impl::Wrapper<Container>;
100 typedef typename GFSV::Ordering::Traits::ContainerIndex
RowIndex;
101 typedef typename GFSU::Ordering::Traits::ContainerIndex
ColIndex;
103 template<
typename RowCache,
typename ColCache>
106 template<
typename RowCache,
typename ColCache>
111 template<
typename GO>
118 template<
typename GO>
158 void attach(std::shared_ptr<Container> container)
168 const std::shared_ptr<Container>&
storage()
const
191 using namespace std::placeholders;
197 void mv(
const V& x, V& y)
const
199 assert(y.N() ==
N());
200 assert(x.N() ==
M());
201 for (std::size_t r = 0; r <
N(); ++r)
210 assert(y.N() ==
N());
211 assert(x.N() ==
M());
212 for (std::size_t r = 0; r <
N(); ++r)
223 auto it = std::lower_bound(begin,end,ci[0]);
233 auto it = std::lower_bound(begin,end,ci[0]);
273 (*this)(ri,ri) = diagonal_entry;
281 (*this)(ri,ri) = diagonal_entry;
285 template<
typename GO>
289 Pattern pattern(go.testGridFunctionSpace().ordering().blockCount());
290 go.fill_pattern(pattern);
292 c->_rows = go.testGridFunctionSpace().size();
293 c->_cols = go.trialGridFunctionSpace().size();
295 c->_rowoffset.resize(c->_rows+1);
297 auto calc_offset = [=](
const col_type & entry)
mutable ->
size_t {
offset += entry.size();
return offset; };
298 std::transform(pattern.begin(), pattern.end(),
299 c->_rowoffset.begin()+1,
302 c->_non_zeros = c->_rowoffset.back();
304 c->_data.resize(c->_non_zeros, e);
305 c->_colindex.resize(c->_non_zeros);
307 auto colit = c->_colindex.begin();
308 c->_rowoffset[0] = 0;
309 for (
auto & row : pattern)
311 auto last = std::copy(row.begin(),row.end(),colit);
312 std::sort(colit, last);
319 std::size_t begin =
_container->_rowoffset[row];
320 std::size_t end =
_container->_rowoffset[row+1];
323 return std::inner_product(
const std::size_t offset
Definition: localfunctionspace.hh:75
For backward compatibility – Do not use this!
Definition: adaptivity.hh:28
Tag for requesting a vector or matrix container without a pre-attached underlying object.
Definition: backend/common/tags.hh:24
Tag for requesting a vector or matrix container with a pre-attached underlying object.
Definition: backend/common/tags.hh:28
Definition: uncachedmatrixview.hh:13
Definition: uncachedmatrixview.hh:167
std::unordered_set< std::size_t > col_type
Definition: sparse.hh:28
SparseMatrixPattern(std::size_t rows)
Definition: sparse.hh:36
void add_link(const RI &ri, const CI &ci)
Definition: sparse.hh:31
ET ElementType
Definition: sparse.hh:45
C< index_type > _rowoffset
Definition: sparse.hh:53
C< ElementType > _data
Definition: sparse.hh:51
std::size_t _rows
Definition: sparse.hh:48
I index_type
Definition: sparse.hh:46
std::size_t size_type
Definition: sparse.hh:47
C< index_type > _colindex
Definition: sparse.hh:52
std::size_t _non_zeros
Definition: sparse.hh:50
std::size_t _cols
Definition: sparse.hh:49
size_type N() const
Definition: sparse.hh:173
Container::size_type size_type
Definition: sparse.hh:94
Container & base()
Definition: sparse.hh:243
void clear_row_block(const RowIndex &ri, const ElementType &diagonal_entry)
Definition: sparse.hh:276
void flush()
Definition: sparse.hh:262
SparseMatrixContainer(Backend::attached_container)
Creates an SparseMatrixContainer with an empty underlying ISTL matrix.
Definition: sparse.hh:130
void mv(const V &x, V &y) const
Definition: sparse.hh:197
ElementType field_type
Definition: sparse.hh:93
ET ElementType
Definition: sparse.hh:91
SparseMatrixContainer & operator=(const SparseMatrixContainer &rhs)
Definition: sparse.hh:138
void clear_row(const RowIndex &ri, const ElementType &diagonal_entry)
Definition: sparse.hh:268
void attach(std::shared_ptr< Container > container)
Definition: sparse.hh:158
SparseMatrixPattern Pattern
Definition: sparse.hh:109
std::shared_ptr< Container > _container
Definition: sparse.hh:332
SparseMatrixContainer(Backend::unattached_container=Backend::unattached_container())
Creates an SparseMatrixContainer without allocating an underlying ISTL matrix.
Definition: sparse.hh:126
void detach()
Definition: sparse.hh:153
const Container & base() const
Definition: sparse.hh:238
const ElementType & operator()(const RowIndex &ri, const ColIndex &ci) const
Definition: sparse.hh:228
ElementType & operator()(const RowIndex &ri, const ColIndex &ci)
Definition: sparse.hh:218
const std::shared_ptr< Container > & storage() const
Definition: sparse.hh:168
GFSV::Ordering::Traits::ContainerIndex RowIndex
Definition: sparse.hh:100
ElementType sparse_inner_product(std::size_t row, const V &x) const
Definition: sparse.hh:318
bool attached() const
Definition: sparse.hh:163
GFSU::Ordering::Traits::ContainerIndex ColIndex
Definition: sparse.hh:101
SparseMatrixContainer(const SparseMatrixContainer &rhs)
Definition: sparse.hh:134
GFSU TrialGridFunctionSpace
Definition: sparse.hh:97
SparseMatrixData< C, ET, I > Container
Definition: sparse.hh:83
SparseMatrixContainer & operator=(const ElementType &e)
Definition: sparse.hh:183
void finalize()
Definition: sparse.hh:265
static void allocate_matrix(std::shared_ptr< Container > &c, const GO &go, const ElementType &e)
Definition: sparse.hh:286
I index_type
Definition: sparse.hh:95
SparseMatrixContainer(const GO &go, const ElementType &e)
Definition: sparse.hh:119
void usmv(const ElementType alpha, const V &x, V &y) const
Definition: sparse.hh:208
GFSV TestGridFunctionSpace
Definition: sparse.hh:98
SparseMatrixContainer(const GO &go)
Definition: sparse.hh:112
size_type M() const
Definition: sparse.hh:178
SparseMatrixContainer & operator*=(const ElementType &e)
Definition: sparse.hh:189
Various tags for influencing backend behavior.