2 #ifndef DUNE_PDELAB_BACKEND_ISTL_BCRSPATTERN_HH
3 #define DUNE_PDELAB_BACKEND_ISTL_BCRSPATTERN_HH
10 #include <dune/common/iteratorfacades.hh>
42 template<
typename RowOrdering,
typename ColOrdering>
49 typedef typename RowOrdering::Traits::size_type
size_type;
69 struct PaddedColumnCriterion
74 return k == _j || k == empty;
86 typedef typename std::vector<size_type>::iterator IndicesIterator;
87 typedef typename std::set<std::pair<size_type,size_type> >::iterator OverflowIterator;
89 typedef typename std::vector<size_type>::const_iterator ConstIndicesIterator;
90 typedef typename std::set<std::pair<size_type,size_type> >::const_iterator ConstOverflowIterator;
95 template<
typename RI,
typename CI>
102 IndicesIterator start = _indices.begin();
103 IndicesIterator
begin = start + _entries_per_row*i;
104 IndicesIterator
end = start + _entries_per_row*(i+1);
107 IndicesIterator it = std::find_if(begin,end,PaddedColumnCriterion(j));
117 _overflow.insert(std::make_pair(i,j));
124 template<
typename RI,
typename CI>
125 void recursive_add_entry(
const RI& ri,
const CI& ci)
136 ConstIndicesIterator it = _indices.begin();
137 ConstIndicesIterator
end = _indices.begin() + _entries_per_row;
138 ConstOverflowIterator oit = _overflow.begin();
139 ConstOverflowIterator oend = _overflow.end();
140 for (
size_type i = 0; i < _row_ordering.blockCount(); ++i, ++rit, end+=_entries_per_row)
144 for (; it !=
end; ++it)
152 for (; oit != oend && oit->first == i; ++oit)
159 std::vector<size_type>
sizes()
const
161 std::vector<size_type> r(_row_ordering.blockCount());
163 #if HAVE_RVALUE_REFERENCES
172 :
public ForwardIteratorFacade<iterator, const size_type>
191 if (
_oit->first == _row)
200 if (_it == _end || *_it == empty)
204 if (
_oit == _oend ||
_oit->first > _row)
210 bool equals(
const iterator& other)
const
212 if (_row != other._row)
214 if (_at_end || other._at_end)
215 return _at_end && other._at_end;
217 return _oit == other._oit;
219 return _it == other._it;
224 , _in_overflow(
false)
226 , _it(p._indices.begin() + row * p._entries_per_row)
227 , _end(p._indices.begin() + (row+1) * p._entries_per_row)
228 ,
_oit(p._overflow.lower_bound(std::make_pair(row,0)))
229 , _oend(p._overflow.end())
232 if ((!_at_end) && (_it == _end || *_it == empty))
235 _at_end =
_oit == _oend ||
_oit->first != _row;
242 typename std::vector<size_type>::const_iterator _it;
243 typename std::vector<size_type>::const_iterator _end;
244 typename std::set<std::pair<size_type,size_type> >::const_iterator
_oit;
245 const typename std::set<std::pair<size_type,size_type> >::const_iterator _oend;
270 : _row_ordering(row_ordering)
271 , _col_ordering(col_ordering)
272 , _entries_per_row(entries_per_row)
273 , _indices(row_ordering.blockCount()*entries_per_row,
size_type(empty))
278 return _row_ordering;
283 return _row_ordering;
295 _indices = std::vector<size_type>();
296 _overflow = std::set<std::pair<size_type,size_type> >();
301 return _entries_per_row;
306 return _overflow.size();
311 const RowOrdering& _row_ordering;
312 const ColOrdering& _col_ordering;
315 std::vector<size_type> _indices;
316 std::set<std::pair<size_type,size_type> > _overflow;
327 template<
typename RowOrdering,
typename ColOrdering,
typename SubPattern_>
344 template<
typename RI,
typename CI>
347 recursive_add_entry(ri.view(),ci.view());
352 template<
typename RI,
typename CI>
353 void recursive_add_entry(
const RI& ri,
const CI& ci)
355 _sub_patterns[ri.back() * _col_ordering.blockCount() + ci.back()].recursive_add_entry(ri.back_popped(),ci.back_popped());
360 template<
typename EntriesPerRow>
361 NestedPattern(
const RowOrdering& row_ordering,
const ColOrdering& col_ordering,
const EntriesPerRow& entries_per_row)
362 : _row_ordering(row_ordering)
363 , _col_ordering(col_ordering)
365 size_type rows = row_ordering.blockCount();
366 size_type cols = col_ordering.blockCount();
369 _sub_patterns.push_back(
371 _row_ordering.childOrdering(i),
372 _col_ordering.childOrdering(j),
373 entries_per_row[i][j]
379 : _row_ordering(row_ordering)
380 , _col_ordering(col_ordering)
382 size_type rows = row_ordering.blockCount();
383 size_type cols = col_ordering.blockCount();
386 _sub_patterns.push_back(
388 _row_ordering.childOrdering(i),
389 _col_ordering.childOrdering(j),
398 return _sub_patterns[i * _col_ordering.blockCount() + j];
403 const RowOrdering& _row_ordering;
404 const ColOrdering& _col_ordering;
405 std::vector<SubPattern> _sub_patterns;
414 #endif // DUNE_PDELAB_BACKEND_ISTL_BCRSPATTERN_HH
Pattern builder for generic BCRS-like sparse matrices.
Definition: bcrspattern.hh:43
Pattern builder for nested hierarchies of generic BCRS-like sparse matrices.
Definition: bcrspattern.hh:328
std::vector< size_type > sizes() const
Returns a vector with the size of all rows in the pattern.
Definition: bcrspattern.hh:159
void clear()
Discard all internal data.
Definition: bcrspattern.hh:293
SubPattern::size_type size_type
size type used by NestedPattern.
Definition: bcrspattern.hh:337
const ColOrdering & colOrdering() const
Definition: bcrspattern.hh:281
iterator begin(size_type i) const
Returns an iterator to the first column index of row i.
Definition: bcrspattern.hh:252
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:96
const RowOrdering & rowOrdering() const
Definition: bcrspattern.hh:276
void sizes(I rit) const
Stream the sizes of all rows into the output iterator rit.
Definition: bcrspattern.hh:134
iterator end(size_type i) const
Returns an iterator past the last column index of row i.
Definition: bcrspattern.hh:258
RowOrdering::Traits::size_type size_type
size type used by BCRSPattern.
Definition: bcrspattern.hh:49
size_type overflowCount() const
Definition: bcrspattern.hh:304
SubPattern & subPattern(size_type i, size_type j)
Returns the subpattern associated with block (i,j).
Definition: bcrspattern.hh:396
size_type entriesPerRow() const
Definition: bcrspattern.hh:299
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:345
SubPattern_ SubPattern
The pattern type used for each block.
Definition: bcrspattern.hh:334
void SubPattern
BCRSPattern cannot contain nested subpatterns. This entry is only required for TMP purposes...
Definition: bcrspattern.hh:52
NestedPattern(const RowOrdering &row_ordering, const ColOrdering &col_ordering, const EntriesPerRow &entries_per_row)
Definition: bcrspattern.hh:361
Iterator over all column indices for a given row, unique but in arbitrary order.
Definition: bcrspattern.hh:171
R p(int i, D x)
Definition: qkdg.hh:62
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:269
const std::string s
Definition: function.hh:1103
OffsetIterator _oit
Definition: datahandleprovider.hh:77
Various tags for influencing backend behavior.
NestedPattern(const RowOrdering &row_ordering, const ColOrdering &col_ordering, size_type entries_per_row)
Definition: bcrspattern.hh:378