2 #ifndef DUNE_PDELAB_BACKEND_ISTL_BCRSPATTERN_HH 3 #define DUNE_PDELAB_BACKEND_ISTL_BCRSPATTERN_HH 13 #include <dune/common/iteratorfacades.hh> 45 template<
typename RowOrdering,
typename ColOrdering>
52 typedef typename RowOrdering::Traits::size_type
size_type;
60 static const size_type empty = ~static_cast<size_type>(0);
72 struct PaddedColumnCriterion
75 bool operator()(size_type k)
const 77 return k == _j || k == empty;
80 PaddedColumnCriterion(size_type j)
89 typedef typename std::vector<size_type>::iterator IndicesIterator;
90 typedef typename std::set<std::pair<size_type,size_type> >
::iterator OverflowIterator;
92 typedef typename std::vector<size_type>::const_iterator ConstIndicesIterator;
93 typedef typename std::set<std::pair<size_type,size_type> >::const_iterator ConstOverflowIterator;
98 template<
typename RI,
typename CI>
102 size_type i = ri.back();
103 size_type j = ci.back();
105 IndicesIterator start = _indices.begin();
106 IndicesIterator
begin = start + _entries_per_row*i;
107 IndicesIterator
end = start + _entries_per_row*(i+1);
110 IndicesIterator it = std::find_if(begin,end,PaddedColumnCriterion(j));
120 _overflow.insert(std::make_pair(i,j));
127 template<
typename RI,
typename CI>
128 void recursive_add_entry(
const RI& ri,
const CI& ci)
139 ConstIndicesIterator it = _indices.begin();
140 ConstIndicesIterator
end = _indices.begin() + _entries_per_row;
141 ConstOverflowIterator oit = _overflow.begin();
142 ConstOverflowIterator oend = _overflow.end();
143 for (size_type i = 0; i < _row_ordering.blockCount(); ++i, ++rit, end+=_entries_per_row)
147 for (; it !=
end; ++it)
155 for (; oit != oend && oit->first == i; ++oit)
162 std::vector<size_type>
sizes()
const 164 std::vector<size_type> r(_row_ordering.blockCount());
171 :
public ForwardIteratorFacade<iterator, const size_type>
176 const size_type& dereference()
const 190 if (_oit->first == _row)
199 if (_it == _end || *_it == empty)
203 if (_oit == _oend || _oit->first > _row)
209 bool equals(
const iterator& other)
const 211 if (_row != other._row)
213 if (_at_end || other._at_end)
214 return _at_end && other._at_end;
216 return _oit == other._oit;
218 return _it == other._it;
223 , _in_overflow(
false)
225 , _it(p._indices.begin() + row * p._entries_per_row)
226 , _end(p._indices.begin() + (row+1) * p._entries_per_row)
227 , _oit(p._overflow.lower_bound(std::make_pair(row,0)))
228 , _oend(p._overflow.end())
231 if ((!_at_end) && (_it == _end || *_it == empty))
234 _at_end = _oit == _oend || _oit->first != _row;
241 typename std::vector<size_type>::const_iterator _it;
242 typename std::vector<size_type>::const_iterator _end;
243 typename std::set<std::pair<size_type,size_type> >::const_iterator _oit;
244 const typename std::set<std::pair<size_type,size_type> >::const_iterator _oend;
268 BCRSPattern(
const RowOrdering& row_ordering,
const ColOrdering& col_ordering, size_type entries_per_row)
269 : _row_ordering(row_ordering)
270 , _col_ordering(col_ordering)
271 , _entries_per_row(entries_per_row)
272 , _indices(row_ordering.blockCount()*entries_per_row,size_type(empty))
277 return _row_ordering;
282 return _row_ordering;
294 _indices = std::vector<size_type>();
295 _overflow = std::set<std::pair<size_type,size_type> >();
300 return _entries_per_row;
305 return _overflow.size();
310 const RowOrdering& _row_ordering;
311 const ColOrdering& _col_ordering;
312 const size_type _entries_per_row;
314 std::vector<size_type> _indices;
315 std::set<std::pair<size_type,size_type> > _overflow;
326 template<
typename RowOrdering,
typename ColOrdering,
typename SubPattern_>
343 template<
typename RI,
typename CI>
346 recursive_add_entry(ri.view(),ci.view());
351 template<
typename RI,
typename CI>
352 void recursive_add_entry(
const RI& ri,
const CI& ci)
354 _sub_patterns[ri.back() * _col_ordering.blockCount() + ci.back()].recursive_add_entry(ri.back_popped(),ci.back_popped());
359 template<
typename EntriesPerRow>
360 NestedPattern(
const RowOrdering& row_ordering,
const ColOrdering& col_ordering,
const EntriesPerRow& entries_per_row)
361 : _row_ordering(row_ordering)
362 , _col_ordering(col_ordering)
364 size_type rows = row_ordering.blockCount();
365 size_type cols = col_ordering.blockCount();
366 for (size_type i = 0; i < rows; ++i)
367 for (size_type j = 0; j < cols; ++j)
368 _sub_patterns.push_back(
370 _row_ordering.childOrdering(i),
371 _col_ordering.childOrdering(j),
372 entries_per_row[i][j]
377 NestedPattern(
const RowOrdering& row_ordering,
const ColOrdering& col_ordering, size_type entries_per_row)
378 : _row_ordering(row_ordering)
379 , _col_ordering(col_ordering)
381 size_type rows = row_ordering.blockCount();
382 size_type cols = col_ordering.blockCount();
383 for (size_type i = 0; i < rows; ++i)
384 for (size_type j = 0; j < cols; ++j)
385 _sub_patterns.push_back(
387 _row_ordering.childOrdering(i),
388 _col_ordering.childOrdering(j),
397 return _sub_patterns[i * _col_ordering.blockCount() + j];
402 const RowOrdering& _row_ordering;
403 const ColOrdering& _col_ordering;
404 std::vector<SubPattern> _sub_patterns;
413 #endif // DUNE_PDELAB_BACKEND_ISTL_BCRSPATTERN_HH void sizes(I rit) const
Stream the sizes of all rows into the output iterator rit.
Definition: bcrspattern.hh:137
Iterator over all column indices for a given row, unique but in arbitrary order.
Definition: bcrspattern.hh:170
Various tags for influencing backend behavior.
const std::string s
Definition: function.hh:1101
size_type overflowCount() const
Definition: bcrspattern.hh:303
const ColOrdering & colOrdering() const
Definition: bcrspattern.hh:280
RowOrdering::Traits::size_type size_type
size type used by BCRSPattern.
Definition: bcrspattern.hh:52
iterator begin(size_type i) const
Returns an iterator to the first column index of row i.
Definition: bcrspattern.hh:251
void add_link(const RI &ri, const CI &ci)
Add a link between the row indicated by ri and the column indicated by ci.
Definition: bcrspattern.hh:344
SubPattern::size_type size_type
size type used by NestedPattern.
Definition: bcrspattern.hh:336
NestedPattern(const RowOrdering &row_ordering, const ColOrdering &col_ordering, const EntriesPerRow &entries_per_row)
Definition: bcrspattern.hh:360
NestedPattern(const RowOrdering &row_ordering, const ColOrdering &col_ordering, size_type entries_per_row)
Definition: bcrspattern.hh:377
const P & p
Definition: constraints.hh:147
size_type entriesPerRow() const
Definition: bcrspattern.hh:298
const RowOrdering & rowOrdering() const
Definition: bcrspattern.hh:275
void SubPattern
BCRSPattern cannot contain nested subpatterns. This entry is only required for TMP purposes...
Definition: bcrspattern.hh:55
For backward compatibility – Do not use this!
Definition: adaptivity.hh:27
SubPattern_ SubPattern
The pattern type used for each block.
Definition: bcrspattern.hh:333
SubPattern & subPattern(size_type i, size_type j)
Returns the subpattern associated with block (i,j).
Definition: bcrspattern.hh:395
Pattern builder for nested hierarchies of generic BCRS-like sparse matrices.
Definition: bcrspattern.hh:327
void clear()
Discard all internal data.
Definition: bcrspattern.hh:292
std::vector< size_type > sizes() const
Returns a vector with the size of all rows in the pattern.
Definition: bcrspattern.hh:162
iterator end(size_type i) const
Returns an iterator past the last column index of row i.
Definition: bcrspattern.hh:257
void add_link(const RI &ri, const CI &ci)
Add a link between the row indicated by ri and the column indicated by ci.
Definition: bcrspattern.hh:99
Pattern builder for generic BCRS-like sparse matrices.
Definition: bcrspattern.hh:46
BCRSPattern(const RowOrdering &row_ordering, const ColOrdering &col_ordering, size_type entries_per_row)
Constructs a BCRSPattern for the given pair of orderings and reserves space for the provided average ...
Definition: bcrspattern.hh:268