2 #ifndef DUNE_PDELAB_BACKEND_SIMPLE_SPARSE_HH
3 #define DUNE_PDELAB_BACKEND_SIMPLE_SPARSE_HH
9 #include <unordered_set>
11 #include <dune/common/typetraits.hh>
12 #include <dune/common/shared_ptr.hh>
22 template<
typename _RowOrdering,
typename _ColOrdering>
24 :
public std::vector< std::unordered_set<std::size_t> >
32 typedef std::unordered_set<std::size_t>
col_type;
34 template<
typename RI,
typename CI>
37 this->resize(_row_ordering.blockCount());
38 (*this)[ri.back()].insert(ci.back());
42 : _row_ordering(row_ordering)
43 , _col_ordering(col_ordering)
53 template<
template<
typename>
class C,
typename ET,
typename I>
87 template<
typename GFSV,
typename GFSU,
template<
typename>
class C,
typename ET,
typename I>
103 typedef typename GFSV::Ordering::Traits::ContainerIndex
RowIndex;
104 typedef typename GFSU::Ordering::Traits::ContainerIndex
ColIndex;
106 template<
typename RowCache,
typename ColCache>
109 template<
typename RowCache,
typename ColCache>
113 typename GFSV::Ordering::Traits::DOFIndex,
114 typename GFSV::Ordering::Traits::ContainerIndex
118 typename GFSU::Ordering::Traits::DOFIndex,
119 typename GFSU::Ordering::Traits::ContainerIndex
124 template<
typename GO>
131 template<
typename GO>
171 void attach(shared_ptr<Container> container)
204 using namespace std::placeholders;
210 void mv(
const V& x, V& y)
const
212 assert(y.N() ==
N());
213 assert(x.N() ==
M());
214 for (std::size_t r = 0; r <
N(); ++r)
223 assert(y.N() ==
N());
224 assert(x.N() ==
M());
225 for (std::size_t r = 0; r <
N(); ++r)
236 auto it = std::lower_bound(begin,end,ci[0]);
246 auto it = std::lower_bound(begin,end,ci[0]);
272 (*this)(ri,ri) = diagonal_entry;
276 template<
typename GO>
280 Pattern pattern(go.testGridFunctionSpace().ordering(),go.trialGridFunctionSpace().ordering());
281 go.fill_pattern(pattern);
283 c->_rows = go.testGridFunctionSpace().size();
284 c->_cols = go.trialGridFunctionSpace().size();
286 c->_rowoffset.resize(c->_rows+1);
288 auto calc_offset = [=](
const col_type & entry)
mutable ->
size_t { offset += entry.size();
return offset; };
289 std::transform(pattern.begin(), pattern.end(),
290 c->_rowoffset.begin()+1,
293 c->_non_zeros = c->_rowoffset.back();
295 c->_data.resize(c->_non_zeros, e);
296 c->_colindex.resize(c->_non_zeros);
298 auto colit = c->_colindex.begin();
299 c->_rowoffset[0] = 0;
300 for (
auto & row : pattern)
302 auto last = std::copy(row.begin(),row.end(),colit);
303 std::sort(colit, last);
310 std::size_t begin =
_container->_rowoffset[row];
311 std::size_t end =
_container->_rowoffset[row+1];
314 return std::inner_product(
330 #endif // DUNE_PDELAB_BACKEND_SIMPLE_SPARSE_HH
_RowOrdering RowOrdering
Definition: sparse.hh:29
I index_type
Definition: sparse.hh:98
Definition: uncachedmatrixview.hh:14
Definition: uncachedmatrixview.hh:159
C< index_type > _colindex
Definition: sparse.hh:63
OrderingBase< typename GFSU::Ordering::Traits::DOFIndex, typename GFSU::Ordering::Traits::ContainerIndex > ColOrdering
Definition: sparse.hh:120
GFSU::Ordering::Traits::ContainerIndex ColIndex
Definition: sparse.hh:104
Tag for requesting a vector or matrix container with a pre-attached underlying object.
Definition: backend/tags.hh:27
GFSU TrialGridFunctionSpace
Definition: sparse.hh:100
SparseMatrixContainer & operator=(const ElementType &e)
Definition: sparse.hh:196
size_type M() const
Definition: sparse.hh:191
shared_ptr< Container > _container
Definition: sparse.hh:323
GFSV::Ordering::Traits::ContainerIndex RowIndex
Definition: sparse.hh:103
OrderingBase< typename GFSV::Ordering::Traits::DOFIndex, typename GFSV::Ordering::Traits::ContainerIndex > RowOrdering
Definition: sparse.hh:115
const ElementType & operator()(const RowIndex &ri, const ColIndex &ci) const
Definition: sparse.hh:241
void attach(shared_ptr< Container > container)
Definition: sparse.hh:171
SparseMatrixPattern(const RowOrdering &row_ordering, const ColOrdering &col_ordering)
Definition: sparse.hh:41
Definition: orderingbase.hh:22
ET ElementType
Definition: sparse.hh:94
SparseMatrixContainer(const GO &go, const ElementType &e)
Definition: sparse.hh:132
Container & base()
Definition: sparse.hh:256
C< ElementType > _data
Definition: sparse.hh:62
const std::size_t offset
Definition: localfunctionspace.hh:74
SparseMatrixContainer & operator=(const SparseMatrixContainer &rhs)
Definition: sparse.hh:151
std::size_t _cols
Definition: sparse.hh:60
Tag for requesting a vector or matrix container without a pre-attached underlying object...
Definition: backend/tags.hh:23
std::size_t size_type
Definition: sparse.hh:58
void add_link(const RI &ri, const CI &ci)
Definition: sparse.hh:35
std::unordered_set< std::size_t > col_type
Definition: sparse.hh:32
SparseMatrixContainer(const SparseMatrixContainer &rhs)
Definition: sparse.hh:147
void flush()
Definition: sparse.hh:261
SparseMatrixContainer(const GO &go)
Definition: sparse.hh:125
void clear_row(const RowIndex &ri, const ElementType &diagonal_entry)
Definition: sparse.hh:267
SparseMatrixPattern< RowOrdering, ColOrdering > Pattern
Definition: sparse.hh:122
GFSV TestGridFunctionSpace
Definition: sparse.hh:101
void mv(const V &x, V &y) const
Definition: sparse.hh:210
SparseMatrixContainer(tags::attached_container)
Creates an SparseMatrixContainer with an empty underlying ISTL matrix.
Definition: sparse.hh:143
ElementType sparse_inner_product(std::size_t row, const V &x) const
Definition: sparse.hh:309
SparseMatrixData< C, ET, I > Container
Definition: sparse.hh:93
C< index_type > _rowoffset
Definition: sparse.hh:64
std::size_t _non_zeros
Definition: sparse.hh:61
const Container & base() const
Definition: sparse.hh:251
I index_type
Definition: sparse.hh:57
size_type N() const
Definition: sparse.hh:186
bool attached() const
Definition: sparse.hh:176
const shared_ptr< Container > & storage() const
Definition: sparse.hh:181
void finalize()
Definition: sparse.hh:264
std::size_t _rows
Definition: sparse.hh:59
void detach()
Definition: sparse.hh:166
static void allocate_matrix(shared_ptr< Container > &c, const GO &go, const ElementType &e)
Definition: sparse.hh:277
ET ElementType
Definition: sparse.hh:56
ElementType & operator()(const RowIndex &ri, const ColIndex &ci)
Definition: sparse.hh:231
const E & e
Definition: interpolate.hh:172
void usmv(const ElementType alpha, const V &x, V &y) const
Definition: sparse.hh:221
Container::size_type size_type
Definition: sparse.hh:97
SparseMatrixContainer(tags::unattached_container=tags::unattached_container())
Creates an SparseMatrixContainer without allocating an underlying ISTL matrix.
Definition: sparse.hh:139
SparseMatrixContainer & operator*=(const ElementType &e)
Definition: sparse.hh:202
ElementType field_type
Definition: sparse.hh:96
_ColOrdering ColOrdering
Definition: sparse.hh:30
Various tags for influencing backend behavior.