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;
57 static const size_type empty = ~static_cast<size_type>(0);
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());
168 :
public ForwardIteratorFacade<iterator, const size_type>
187 if (_oit->first == _row)
196 if (_it == _end || *_it == empty)
200 if (_oit == _oend || _oit->first > _row)
206 bool equals(
const iterator& other)
const
208 if (_row != other._row)
210 if (_at_end || other._at_end)
211 return _at_end && other._at_end;
213 return _oit == other._oit;
215 return _it == other._it;
220 , _in_overflow(
false)
222 , _it(
p._indices.begin() + row *
p._entries_per_row)
223 , _end(
p._indices.begin() + (row+1) *
p._entries_per_row)
224 , _oit(
p._overflow.lower_bound(std::make_pair(row,0)))
225 , _oend(
p._overflow.end())
228 if ((!_at_end) && (_it == _end || *_it == empty))
231 _at_end = _oit == _oend || _oit->first != _row;
238 typename std::vector<size_type>::const_iterator _it;
239 typename std::vector<size_type>::const_iterator _end;
240 typename std::set<std::pair<size_type,size_type> >::const_iterator _oit;
241 const typename std::set<std::pair<size_type,size_type> >::const_iterator _oend;
266 : _row_ordering(row_ordering)
267 , _col_ordering(col_ordering)
268 , _entries_per_row(entries_per_row)
269 , _indices(row_ordering.blockCount()*entries_per_row,
size_type(empty))
274 return _row_ordering;
279 return _row_ordering;
291 _indices = std::vector<size_type>();
292 _overflow = std::set<std::pair<size_type,size_type> >();
297 return _entries_per_row;
302 return _overflow.size();
307 const RowOrdering& _row_ordering;
308 const ColOrdering& _col_ordering;
311 std::vector<size_type> _indices;
312 std::set<std::pair<size_type,size_type> > _overflow;
323 template<
typename RowOrdering,
typename ColOrdering,
typename SubPattern_>
340 template<
typename RI,
typename CI>
343 recursive_add_entry(ri.view(),ci.view());
348 template<
typename RI,
typename CI>
349 void recursive_add_entry(
const RI& ri,
const CI& ci)
351 _sub_patterns[ri.back() * _col_ordering.blockCount() + ci.back()].recursive_add_entry(ri.back_popped(),ci.back_popped());
356 template<
typename EntriesPerRow>
357 NestedPattern(
const RowOrdering& row_ordering,
const ColOrdering& col_ordering,
const EntriesPerRow& entries_per_row)
358 : _row_ordering(row_ordering)
359 , _col_ordering(col_ordering)
361 size_type rows = row_ordering.blockCount();
362 size_type cols = col_ordering.blockCount();
365 _sub_patterns.push_back(
367 _row_ordering.childOrdering(i),
368 _col_ordering.childOrdering(j),
369 entries_per_row[i][j]
375 : _row_ordering(row_ordering)
376 , _col_ordering(col_ordering)
378 size_type rows = row_ordering.blockCount();
379 size_type cols = col_ordering.blockCount();
382 _sub_patterns.push_back(
384 _row_ordering.childOrdering(i),
385 _col_ordering.childOrdering(j),
394 return _sub_patterns[i * _col_ordering.blockCount() + j];
399 const RowOrdering& _row_ordering;
400 const ColOrdering& _col_ordering;
401 std::vector<SubPattern> _sub_patterns;
410 #endif // DUNE_PDELAB_BACKEND_ISTL_BCRSPATTERN_HH