dune-pdelab  2.4-dev
localorderingbase.hh
Go to the documentation of this file.
1 // -*- tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 // vi: set et ts=8 sw=2 sts=2:
3 
4 #ifndef DUNE_PDELAB_ORDERING_LOCALORDERINGBASE_HH
5 #define DUNE_PDELAB_ORDERING_LOCALORDERINGBASE_HH
6 
10 
11 #include <vector>
12 
13 namespace Dune {
14  namespace PDELab {
15 
18 
19  template<typename GV, typename DI, typename CI>
21  : public PartitionInfoProvider
22  {
23 
25 
26  template<typename>
27  friend struct update_fixed_size;
28 
29  template<typename>
31 
32  template<typename>
34 
36 
37  template<typename>
39 
40  template<typename>
42 
43  template<typename>
44  friend class GridViewOrdering;
45 
46  template<typename size_type>
47  friend struct ::Dune::PDELab::impl::update_ordering_data;
48 
49  typedef std::vector<LocalOrderingBase*> ChildVector;
50  typedef typename ChildVector::iterator ChildIterator;
51  typedef typename ChildVector::const_iterator ConstChildIterator;
52 
53  public:
54 
55  static const bool has_dynamic_ordering_children = true;
56 
57  static const bool consume_tree_index = true;
58 
60 
61  protected:
62 
63  typedef impl::GridFunctionSpaceOrderingData<typename Traits::SizeType> GFSData;
64 
65  public:
66 
67  void map_local_index(const typename Traits::SizeType geometry_type_index,
68  const typename Traits::SizeType entity_index,
69  typename Traits::TreeIndexView mi,
70  typename Traits::ContainerIndex& ci) const
71  {
72  if (_child_count == 0)
73  {
74  assert(mi.size() == 1 && "MultiIndex length must match GridFunctionSpace tree depth");
75  ci.push_back(mi.back());
76  }
77  else
78  {
79  const typename Traits::SizeType child_index = mi.back();
80  if (!mi.empty())
81  _children[child_index]->map_local_index(geometry_type_index,entity_index,mi.back_popped(),ci);
83  {
84  ci.push_back(child_index);
85  }
86  else if (child_index > 0)
87  {
88  if (_fixed_size)
89  {
90  const typename Traits::SizeType index = geometry_type_index * _child_count + child_index - 1;
91  ci.back() += _gt_dof_offsets[index];
92  }
93  else
94  {
95  assert(_gt_used[geometry_type_index]);
96  const typename Traits::SizeType index = (_gt_entity_offsets[geometry_type_index] + entity_index) * _child_count + child_index - 1;
97  ci.back() += _entity_dof_offsets[index];
98  }
99  }
100  }
101  }
102 
103 
104  template<typename ItIn, typename ItOut>
105  void map_lfs_indices(const ItIn begin, const ItIn end, ItOut out) const
106  {
107  if (_child_count == 0)
108  {
109  for (ItIn in = begin; in != end; ++in, ++out)
110  {
111  assert(in->size() == 1 && "MultiIndex length must match GridFunctionSpace tree depth");
112  out->push_back(in->treeIndex().back());
113  }
114  }
115  else if (_container_blocked)
116  {
117  for (ItIn in = begin; in != end; ++in, ++out)
118  out->push_back(in->treeIndex().back());
119  }
120  else if (_fixed_size)
121  {
122  for (ItIn in = begin; in != end; ++in, ++out)
123  {
124  const typename Traits::SizeType child_index = in->treeIndex().back();
125  const typename Traits::SizeType gt_index = Traits::DOFIndexAccessor::geometryType(*in);
126  if (child_index > 0)
127  {
128  const typename Traits::SizeType index = gt_index * _child_count + child_index - 1;
129  out->back() += _gt_dof_offsets[index];
130  }
131  }
132  }
133  else
134  {
135  for (ItIn in = begin; in != end; ++in, ++out)
136  {
137  const typename Traits::SizeType child_index = in->treeIndex().back();
138  if (child_index > 0)
139  {
140  const typename Traits::SizeType gt_index = Traits::DOFIndexAccessor::geometryType(*in);
141  const typename Traits::SizeType entity_index = Traits::DOFIndexAccessor::entityIndex(*in);
142 
143  assert(_gt_used[gt_index]);
144 
145  const typename Traits::SizeType index = (_gt_entity_offsets[gt_index] + entity_index) * _child_count + child_index - 1;
146  out->back() += _entity_dof_offsets[index];
147  }
148  }
149  }
150  }
151 
152  template<typename CIOutIterator, typename DIOutIterator = DummyDOFIndexIterator>
153  typename Traits::SizeType
154  extract_entity_indices(const typename Traits::DOFIndex::EntityIndex& ei,
155  typename Traits::SizeType child_index,
156  CIOutIterator ci_out, const CIOutIterator ci_end,
157  DIOutIterator di_out = DIOutIterator()) const
158  {
159  typedef typename Traits::SizeType size_type;
160 
161  const size_type geometry_type_index = Traits::DOFIndexAccessor::GeometryIndex::geometryType(ei);
162  const size_type entity_index = Traits::DOFIndexAccessor::GeometryIndex::entityIndex(ei);
163 
164  if (!_gt_used[geometry_type_index])
165  return 0;
166 
167  if (_child_count == 0)
168  {
169  const size_type size = _fixed_size
170  ? _gt_dof_offsets[geometry_type_index]
171  : _entity_dof_offsets[(_gt_entity_offsets[geometry_type_index] + entity_index)];
172 
173  for (size_type i = 0; i < size; ++i, ++ci_out, ++di_out)
174  {
175  ci_out->push_back(i);
176  di_out->treeIndex().push_back(i);
177  }
178  return size;
179  }
180  else
181  {
182  if (_container_blocked)
183  {
184  for (; ci_out != ci_end; ++ci_out)
185  {
186  ci_out->push_back(child_index);
187  }
188  }
189  else if (child_index > 0)
190  {
191  if (_fixed_size)
192  for (; ci_out != ci_end; ++ci_out)
193  {
194  const typename Traits::SizeType index = geometry_type_index * _child_count + child_index - 1;
195  ci_out->back() += _gt_dof_offsets[index];
196  }
197  else
198  for (; ci_out != ci_end; ++ci_out)
199  {
200  const typename Traits::SizeType index = (_gt_entity_offsets[geometry_type_index] + entity_index) * _child_count + child_index - 1;
201  ci_out->back() += _entity_dof_offsets[index];
202  }
203  }
204 
205  // The return value is not used for non-leaf orderings.
206  return 0;
207  }
208  }
209 
210  typename Traits::SizeType size(const typename Traits::DOFIndex::EntityIndex& index) const
211  {
212  return size(
213  Traits::DOFIndexAccessor::GeometryIndex::geometryType(index),
214  Traits::DOFIndexAccessor::GeometryIndex::entityIndex(index)
215  );
216  }
217 
218  typename Traits::SizeType size(const typename Traits::SizeType geometry_type_index, const typename Traits::SizeType entity_index) const
219  {
220  if (_fixed_size)
221  return _child_count > 0
222  ? _gt_dof_offsets[geometry_type_index * _child_count + _child_count - 1]
223  : _gt_dof_offsets[geometry_type_index];
224 
225  if (!_gt_used[geometry_type_index])
226  return 0;
227 
228  return _child_count > 0
229  ? _entity_dof_offsets[(_gt_entity_offsets[geometry_type_index] + entity_index) * _child_count + _child_count - 1]
230  : _entity_dof_offsets[(_gt_entity_offsets[geometry_type_index] + entity_index)];
231  }
232 
233  typename Traits::SizeType size(const typename Traits::SizeType geometry_type_index, const typename Traits::SizeType entity_index, const typename Traits::SizeType child_index) const
234  {
235  assert(child_index < _child_count);
236  if (_fixed_size)
237  {
238  const typename Traits::SizeType index = geometry_type_index * _child_count + child_index;
239  return child_index > 0 ? _gt_dof_offsets[index] - _gt_dof_offsets[index-1] : _gt_dof_offsets[index];
240  }
241  else
242  {
243  if (_gt_used[geometry_type_index])
244  {
245  const typename Traits::SizeType index = (_gt_entity_offsets[geometry_type_index] + entity_index) * _child_count + child_index;
246  return child_index > 0 ? _entity_dof_offsets[index] - _entity_dof_offsets[index-1] : _entity_dof_offsets[index];
247  }
248  else
249  {
250  return 0;
251  }
252  }
253  }
254 
255  typename Traits::SizeType offset(const typename Traits::SizeType geometry_type_index, const typename Traits::SizeType entity_index, const typename Traits::SizeType child_index) const
256  {
257  assert(child_index < _child_count);
258  assert(_gt_used[geometry_type_index]);
259  if (_fixed_size)
260  return child_index > 0 ? _gt_dof_offsets[geometry_type_index * _child_count + child_index - 1] : 0;
261  else
262  return child_index > 0 ? _entity_dof_offsets[(_gt_entity_offsets[geometry_type_index] + entity_index) * _child_count + child_index - 1] : 0;
263  }
264 
265  template<typename Node>
266  LocalOrderingBase(Node& node, bool container_blocked, GFSData* gfs_data)
267  : _fixed_size(false)
268  , _fixed_size_possible(false)
269  , _container_blocked(container_blocked)
270  , _max_local_size(0)
271  , _child_count(Node::CHILDREN)
272  , _children(Node::CHILDREN,nullptr)
273  , _gfs_data(gfs_data)
274  {
275  TypeTree::applyToTree(node,extract_child_bases<LocalOrderingBase>(_children));
276 
277  // We contain all grid PartitionTypes that any of our children contain.
278  mergePartitionSets(_children.begin(),_children.end());
279  }
280 
281  bool fixedSize() const
282  {
283  return _fixed_size;
284  }
285 
286  bool contains(const GeometryType& gt) const
287  {
288  return _gt_used[GlobalGeometryTypeIndex::index(gt)];
289  }
290 
291  bool contains_geometry_type(typename Traits::SizeType gt_index) const
292  {
293  return _gt_used[gt_index];
294  }
295 
296  bool contains(typename Traits::SizeType codim) const
297  {
298  return _codim_used.test(codim);
299  }
300 
302  {
303  return _max_local_size;
304  }
305 
306  private:
307 
308  bool update_gfs_data_size(typename Traits::SizeType& size, typename Traits::SizeType& block_count) const
309  {
310  return false;
311  }
312 
313  protected:
314 
316  {
317  return *_children[i];
318  }
319 
321  {
322  return *_children[i];
323  }
324 
326  {
327  _container_blocked = false;
328  }
329 
331 
341  {
342  _fixed_size_possible = true;
343  for (ConstChildIterator it = _children.begin(),
344  end_it = _children.end();
345  it != end_it;
346  ++it)
347  _fixed_size_possible = _fixed_size_possible && (*it)->_fixed_size_possible;
348  }
349 
350 
351 
355  std::size_t _max_local_size;
356 
357  const std::size_t _child_count;
358  std::vector<LocalOrderingBase*> _children;
359 
361  std::vector<bool> _gt_used;
362 
363  std::vector<typename Traits::SizeType> _gt_entity_offsets;
364  std::vector<typename Traits::SizeType> _gt_dof_offsets;
365  std::vector<typename Traits::SizeType> _entity_dof_offsets;
366 
367  GFSData* _gfs_data;
368 
369  };
370 
372 
373  } // namespace PDELab
374 } // namespace Dune
375 
376 #endif // DUNE_PDELAB_ORDERING_LOCALORDERINGBASE_HH
Traits::SizeType size(const typename Traits::SizeType geometry_type_index, const typename Traits::SizeType entity_index) const
Definition: localorderingbase.hh:218
Traits::SizeType offset(const typename Traits::SizeType geometry_type_index, const typename Traits::SizeType entity_index, const typename Traits::SizeType child_index) const
Definition: localorderingbase.hh:255
LocalOrderingBase & childOrdering(typename Traits::SizeType i)
Definition: localorderingbase.hh:315
std::size_t _max_local_size
Definition: localorderingbase.hh:355
bool _container_blocked
Definition: localorderingbase.hh:354
std::size_t SizeType
Definition: ordering/utility.hh:162
LocalOrderingBase(Node &node, bool container_blocked, GFSData *gfs_data)
Definition: localorderingbase.hh:266
DI::size_type SizeType
Definition: ordering/utility.hh:201
Traits::SizeType maxLocalSize() const
Definition: localorderingbase.hh:301
static std::size_t geometryType(const DOFIndex &dof_index)
Definition: ordering/utility.hh:129
Definition: ordering/utility.hh:243
std::vector< typename Traits::SizeType > _gt_dof_offsets
Definition: localorderingbase.hh:364
bool _fixed_size
Definition: localorderingbase.hh:352
std::vector< bool > _gt_used
Definition: localorderingbase.hh:361
CI ContainerIndex
Definition: ordering/utility.hh:160
std::vector< typename Traits::SizeType > _entity_dof_offsets
Definition: localorderingbase.hh:365
impl::GridFunctionSpaceOrderingData< typename Traits::SizeType > GFSData
Definition: localorderingbase.hh:63
void mergePartitionSets(It begin, It end)
Adds the partitions from all PartitionInfoProviders in the range [begin,end).
Definition: partitioninfoprovider.hh:77
Traits::SizeType size(const typename Traits::DOFIndex::EntityIndex &index) const
Definition: localorderingbase.hh:210
Traits::CodimFlag _codim_used
Definition: localorderingbase.hh:360
void setup_fixed_size_possible()
Initial setup of the flag indicating whether a fixed size ordering is possible.
Definition: localorderingbase.hh:340
DI::View::TreeIndex TreeIndexView
Definition: ordering/utility.hh:199
Definition: gridviewordering.hh:59
const LocalOrderingBase & childOrdering(typename Traits::SizeType i) const
Definition: localorderingbase.hh:320
Traits::SizeType extract_entity_indices(const typename Traits::DOFIndex::EntityIndex &ei, typename Traits::SizeType child_index, CIOutIterator ci_out, const CIOutIterator ci_end, DIOutIterator di_out=DIOutIterator()) const
Definition: localorderingbase.hh:154
static const bool has_dynamic_ordering_children
Definition: localorderingbase.hh:55
std::bitset< max_dim > CodimFlag
Definition: ordering/utility.hh:194
void disable_container_blocking()
Definition: localorderingbase.hh:325
Definition: gridviewordering.hh:309
const std::size_t _child_count
Definition: localorderingbase.hh:357
Definition: gridviewordering.hh:22
bool contains(typename Traits::SizeType codim) const
Definition: localorderingbase.hh:296
Definition: ordering/utility.hh:208
Definition: adaptivity.hh:27
void map_lfs_indices(const ItIn begin, const ItIn end, ItOut out) const
Definition: localorderingbase.hh:105
GFSData * _gfs_data
Definition: localorderingbase.hh:367
friend struct collect_used_geometry_types_from_cell
Definition: localorderingbase.hh:38
Definition: gridviewordering.hh:420
Traits::SizeType size(const typename Traits::SizeType geometry_type_index, const typename Traits::SizeType entity_index, const typename Traits::SizeType child_index) const
Definition: localorderingbase.hh:233
Mixin class for providing information about contained grid partitions.
Definition: partitioninfoprovider.hh:22
std::vector< LocalOrderingBase * > _children
Definition: localorderingbase.hh:358
static const bool consume_tree_index
Definition: localorderingbase.hh:57
Definition: gridviewordering.hh:154
Definition: gridviewordering.hh:211
bool contains_geometry_type(typename Traits::SizeType gt_index) const
Definition: localorderingbase.hh:291
Definition: localorderingbase.hh:20
LocalOrderingTraits< GV, DI, CI > Traits
Definition: localorderingbase.hh:59
bool _fixed_size_possible
Definition: localorderingbase.hh:353
std::vector< typename Traits::SizeType > _gt_entity_offsets
Definition: localorderingbase.hh:363
void map_local_index(const typename Traits::SizeType geometry_type_index, const typename Traits::SizeType entity_index, typename Traits::TreeIndexView mi, typename Traits::ContainerIndex &ci) const
Definition: localorderingbase.hh:67
friend struct extract_per_entity_sizes_from_cell
Definition: localorderingbase.hh:41
bool fixedSize() const
Definition: localorderingbase.hh:281
bool contains(const GeometryType &gt) const
Definition: localorderingbase.hh:286
static std::size_t entityIndex(const DOFIndex &dof_index)
Definition: ordering/utility.hh:135