dune-pdelab  2.7-git
ordering/utility.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_UTILITY_HH
5 #define DUNE_PDELAB_ORDERING_UTILITY_HH
6 
7 #include <vector>
8 #include <bitset>
9 
13 
14 namespace Dune {
15  namespace PDELab {
16 
19 
21  struct MergeMode
22  {
23 
24  enum type {
27  };
28 
29  };
30 
32  enum class MultiIndexOrder {
37  };
38 
39 
40 #ifndef DOXYGEN
41 
42  namespace ordering {
43 
44  // This is an implementation detail of the composite orderings, no need to confuse our users!
45  struct update_direct_children
46  : public TypeTree::DirectChildrenVisitor
47  , public TypeTree::DynamicTraversal
48  {
49 
50  template<typename GFS, typename Child, typename TreePath, typename ChildIndex>
51  void afterChild(const GFS& gfs, Child& child, TreePath tp, ChildIndex childIndex) const
52  {
53  child.update();
54  }
55 
56  };
57 
58  } // end namespace ordering
59 
60 #endif // DOXYGEN
61 
62 
64  {
65 
66  template<typename DOFIndex, typename SizeType, typename IndexType>
67  static typename std::enable_if<
69  >::type
70  store(DOFIndex& dof_index, const GeometryType& gt, SizeType entity_index, IndexType tree_index)
71  {
72  dof_index.clear();
73  dof_index.entityIndex()[0] = GlobalGeometryTypeIndex::index(gt);
74  dof_index.entityIndex()[1] = entity_index;
75  dof_index.treeIndex().push_back(tree_index);
76  }
77 
78  template<typename DOFIndex, typename SizeType, typename IndexType>
79  static typename std::enable_if<
81  >::type
82  store(DOFIndex& dof_index, const GeometryType& gt, SizeType entity_index, IndexType tree_index)
83  {
84  dof_index.entityIndex()[0] = GlobalGeometryTypeIndex::index(gt);
85  dof_index.entityIndex()[1] = entity_index;
86  dof_index.treeIndex() = tree_index;
87  }
88 
89  template<typename DOFIndex, typename SizeType, typename IndexType>
90  static typename std::enable_if<
92  >::type
93  store(DOFIndex& dof_index, SizeType gt_index, SizeType entity_index, IndexType tree_index)
94  {
95  dof_index.clear();
96  dof_index.entityIndex()[0] = gt_index;
97  dof_index.entityIndex()[1] = entity_index;
98  dof_index.treeIndex().push_back(tree_index);
99  }
100 
101  template<typename DOFIndex, typename SizeType, typename IndexType>
102  static typename std::enable_if<
104  >::type
105  store(DOFIndex& dof_index, SizeType gt_index, SizeType entity_index, IndexType tree_index)
106  {
107  dof_index.entityIndex()[0] = gt_index;
108  dof_index.entityIndex()[1] = entity_index;
109  dof_index.treeIndex() = tree_index;
110  }
111 
112 
114  {
115 
116  template<typename Index>
117  static std::size_t geometryType(const Index& geometry_index)
118  {
119  return geometry_index[0];
120  }
121 
122  template<typename Index>
123  static std::size_t entityIndex(const Index& geometry_index)
124  {
125  return geometry_index[1];
126  }
127 
128  template<typename Index, typename SizeType>
129  static void store(Index& index, const GeometryType& gt, SizeType entity_index)
130  {
132  index[1] = entity_index;
133  }
134 
135  template<typename Index, typename SizeType>
136  static void store(Index& index, SizeType geometry_index, SizeType entity_index)
137  {
138  index[0] = geometry_index;
139  index[1] = entity_index;
140  }
141 
142  };
143 
144  template<typename DOFIndex>
145  static std::size_t geometryType(const DOFIndex& dof_index)
146  {
147  return GeometryIndex::geometryType(dof_index.entityIndex());
148  }
149 
150  template<typename DOFIndex>
151  static std::size_t entityIndex(const DOFIndex& dof_index)
152  {
153  return GeometryIndex::entityIndex(dof_index.entityIndex());
154  }
155 
156  };
157 
159  {
160 
161  template<typename DOFIndex, typename SizeType>
162  static void store(DOFIndex& dof_index, const GeometryType& gt, SizeType entity_index, SizeType tree_index)
163  {
164  dof_index = entity_index;
165  }
166 
167  };
168 
169 
170  template<typename DI, typename CI, MultiIndexOrder CIOrder = MultiIndexOrder::Inner2Outer>
172  {
173 
174  typedef DI DOFIndex;
175 
176  typedef CI ContainerIndex;
177 
178  typedef std::size_t SizeType;
179 
181 
183  static constexpr MultiIndexOrder ContainerIndexOrder = CIOrder;
184  };
185 
186 
187  template<typename SizeType_, typename CI, MultiIndexOrder CIOrder>
188  struct SimpleOrderingTraits<SimpleDOFIndex<SizeType_>,CI,CIOrder>
189  {
190 
192 
193  typedef CI ContainerIndex;
194 
195  typedef SizeType_ SizeType;
196 
198 
200  static constexpr MultiIndexOrder ContainerIndexOrder = CIOrder;
201  };
202 
203  template <typename DI, typename CI,
205  struct OrderingTraits : public SimpleOrderingTraits<DI, CI, CIOrder> {
206 
207  // The maximum dimension supported (length of bitsets)
208  // 32 dimensions should probably be fine for now... ;-)
209  static const std::size_t max_dim = 32;
210 
211  typedef std::bitset<max_dim> CodimFlag;
212 
213  typedef typename DI::TreeIndex TreeIndex;
214 
215  typedef typename DI::View DOFIndexView;
216  typedef typename DI::View::TreeIndex TreeIndexView;
217 
218  typedef typename DI::size_type SizeType;
219  typedef typename DI::size_type size_type;
220  };
221 
222  template <typename ES, typename DI, typename CI,
224  struct LocalOrderingTraits : public OrderingTraits<DI, CI, CIOrder> {
225 
226  using EntitySet = ES;
227  using GridView = typename ES::GridView;
228  };
229 
230  template<typename ES, typename DI, typename CI>
232  : public LocalOrderingTraits<ES,DI,CI>
233  {
234 
235  typedef typename DI::EntityIndex EntityIndex;
236  typedef typename DI::View::EntityIndex EntityIndexView;
237 
238  };
239 
240 
241  template<typename DI, typename CI>
243  {
244  public:
245 
247 
249  virtual ~VirtualOrderingBase() = default;
250 
251  virtual void map_index_dynamic(typename Traits::DOFIndexView di, typename Traits::ContainerIndex& ci) const = 0;
252  };
253 
254 
255  template<typename child_type>
257  : public TypeTree::DirectChildrenVisitor
258  , public TypeTree::DynamicTraversal
259  {
260 
261  template<typename Node, typename Child, typename TreePath, typename ChildIndex>
262  void afterChild(const Node& node, Child& child, TreePath tp, ChildIndex child_index)
263  {
264  extract_child(node,child,child_index);
265  }
266 
267  template<typename Node, typename Child, typename ChildIndex>
268  typename std::enable_if<Node::has_dynamic_ordering_children>::type
269  extract_child(const Node& node, Child& child, ChildIndex child_index)
270  {
271  _children[child_index] = &child;
272  }
273 
274  template<typename Node, typename Child, typename ChildIndex>
275  typename std::enable_if<!Node::has_dynamic_ordering_children>::type
276  extract_child(const Node& node, Child& child, ChildIndex child_index)
277  {
278  }
279 
280  extract_child_bases(std::vector<child_type*>& children)
281  : _children(children)
282  {}
283 
284  private:
285  std::vector<child_type*>& _children;
286 
287  };
288 
289 
291 
301  {
302 
303  typedef std::size_t size_type;
304 
306  {
307  return *this;
308  }
309 
311  {
312  return *this;
313  }
314 
316  {
317  return *this;
318  }
319 
321  {
322  return this;
323  }
324 
326  {
327  return *this;
328  }
329 
330  bool operator==(const DummyDOFIndexIterator& r) const
331  {
332  return true;
333  }
334 
335  bool operator!=(const DummyDOFIndexIterator& r) const
336  {
337  return !operator==(r);
338  }
339 
341  {}
342 
343  };
344 
362  template <class Size, class ContainerIndex_, MultiIndexOrder OriginOrder>
364 
371  template <class Ordering>
372  SizeProviderAdapter(const std::shared_ptr<const Ordering> &ordering)
373  : _size_provider([=](const ContainerIndex_ &partial_multiindex) {
374  return ordering->size(partial_multiindex);
375  }) {
376  static_assert(Ordering::Traits::ContainerIndexOrder == OriginOrder);
377  }
378 
380  using ContainerIndex = ContainerIndex_;
381 
384 
386  using SizeType = Size;
387 
390 
396  SizeType size(const SizePrefix &prefix) const {
397  if constexpr (OriginOrder == MultiIndexOrder::Inner2Outer) {
398  // reversing Outer2Inner prefix into a Inner2Outer suffix
399  ContainerIndex suffix;
400  suffix.resize(prefix.size());
401  std::reverse_copy(prefix.begin(), prefix.end(),suffix.begin());
402  // forward size request to ordering with new Inner2Outer suffix
403  return _size_provider(suffix);
404  } else {
405  // prefix is already Outer2Inner, forward to size provider
406  return _size_provider(prefix);
407  }
408  }
409 
410  private:
411 
412  const std::function<SizeType(const ContainerIndex &)> _size_provider;
413  };
414 
416  template<class Ordering>
417  SizeProviderAdapter(const std::shared_ptr<const Ordering>& ordering)
418  -> SizeProviderAdapter<typename Ordering::Traits::SizeType,
419  typename Ordering::Traits::ContainerIndex,
420  Ordering::Traits::ContainerIndexOrder>;
421 
422 
424  } // namespace PDELab
425 } // namespace Dune
426 
427 #endif // DUNE_PDELAB_ORDERING_UTILITY_HH
std::size_t index
Definition: interpolate.hh:97
Define and register ordering related transformations. This header defines the two transformations gfs...
MultiIndexOrder
Information about order semantics on multi-indices.
Definition: ordering/utility.hh:32
SizeProviderAdapter(const std::shared_ptr< const Ordering > &ordering) -> SizeProviderAdapter< typename Ordering::Traits::SizeType, typename Ordering::Traits::ContainerIndex, Ordering::Traits::ContainerIndexOrder >
template deduction guide for orderings
@ Inner2Outer
indices are ordered from inner to outer container: {inner,...,outer}
@ Outer2Inner
indices are ordered from outer to inner container: {outer,...,inner}
For backward compatibility – Do not use this!
Definition: adaptivity.hh:28
A multi-index representing a degree of freedom in a GridFunctionSpace.
Definition: dofindex.hh:148
EntityIndex & entityIndex()
Returns the index of the grid entity associated with the DOF.
Definition: dofindex.hh:258
TreeIndex & treeIndex()
Returns the tuple of entity-local indices associated with the DOF.
Definition: dofindex.hh:270
void clear()
Definition: dofindex.hh:251
Definition: simpledofindex.hh:16
Index merging algorithm for global orderings.
Definition: ordering/utility.hh:22
type
Definition: ordering/utility.hh:24
@ interleaved
Indices are interleaved according to a user-supplied pattern ([i1,i2],[j1,j2] -> [i1,...
Definition: ordering/utility.hh:26
@ lexicographic
Lexicographically ordered ([i1,i2],[j1,j2] -> [i1,i2,j1,j2]).
Definition: ordering/utility.hh:25
Definition: ordering/utility.hh:64
static std::enable_if< !std::is_integral< IndexType >::value >::type store(DOFIndex &dof_index, const GeometryType &gt, SizeType entity_index, IndexType tree_index)
Definition: ordering/utility.hh:82
static std::enable_if< !std::is_integral< IndexType >::value >::type store(DOFIndex &dof_index, SizeType gt_index, SizeType entity_index, IndexType tree_index)
Definition: ordering/utility.hh:105
static std::size_t entityIndex(const DOFIndex &dof_index)
Definition: ordering/utility.hh:151
static std::enable_if< std::is_integral< IndexType >::value >::type store(DOFIndex &dof_index, SizeType gt_index, SizeType entity_index, IndexType tree_index)
Definition: ordering/utility.hh:93
static std::enable_if< std::is_integral< IndexType >::value >::type store(DOFIndex &dof_index, const GeometryType &gt, SizeType entity_index, IndexType tree_index)
Definition: ordering/utility.hh:70
static std::size_t geometryType(const DOFIndex &dof_index)
Definition: ordering/utility.hh:145
Definition: ordering/utility.hh:114
static std::size_t entityIndex(const Index &geometry_index)
Definition: ordering/utility.hh:123
static void store(Index &index, const GeometryType &gt, SizeType entity_index)
Definition: ordering/utility.hh:129
static std::size_t geometryType(const Index &geometry_index)
Definition: ordering/utility.hh:117
static void store(Index &index, SizeType geometry_index, SizeType entity_index)
Definition: ordering/utility.hh:136
Definition: ordering/utility.hh:159
static void store(DOFIndex &dof_index, const GeometryType &gt, SizeType entity_index, SizeType tree_index)
Definition: ordering/utility.hh:162
Definition: ordering/utility.hh:172
DI DOFIndex
Definition: ordering/utility.hh:174
std::size_t SizeType
Definition: ordering/utility.hh:178
CI ContainerIndex
Definition: ordering/utility.hh:176
DefaultDOFIndexAccessor DOFIndexAccessor
Definition: ordering/utility.hh:180
static constexpr MultiIndexOrder ContainerIndexOrder
Inform about ContainerIndex multi-index order semantics.
Definition: ordering/utility.hh:183
SimpleDOFIndex< SizeType_ > DOFIndex
Definition: ordering/utility.hh:191
SimpleDOFIndexAccessor DOFIndexAccessor
Definition: ordering/utility.hh:197
Definition: ordering/utility.hh:205
std::bitset< max_dim > CodimFlag
Definition: ordering/utility.hh:211
DI::size_type SizeType
Definition: ordering/utility.hh:218
DI::TreeIndex TreeIndex
Definition: ordering/utility.hh:213
static const std::size_t max_dim
Definition: ordering/utility.hh:209
DI::View::TreeIndex TreeIndexView
Definition: ordering/utility.hh:216
DI::size_type size_type
Definition: ordering/utility.hh:219
DI::View DOFIndexView
Definition: ordering/utility.hh:215
Definition: ordering/utility.hh:224
typename ES::GridView GridView
Definition: ordering/utility.hh:227
ES EntitySet
Definition: ordering/utility.hh:226
Definition: ordering/utility.hh:233
DI::EntityIndex EntityIndex
Definition: ordering/utility.hh:235
DI::View::EntityIndex EntityIndexView
Definition: ordering/utility.hh:236
Definition: ordering/utility.hh:243
virtual void map_index_dynamic(typename Traits::DOFIndexView di, typename Traits::ContainerIndex &ci) const =0
virtual ~VirtualOrderingBase()=default
OrderingTraits< DI, CI > Traits
Definition: ordering/utility.hh:246
VirtualOrderingBase()
Definition: ordering/utility.hh:248
Definition: ordering/utility.hh:259
extract_child_bases(std::vector< child_type * > &children)
Definition: ordering/utility.hh:280
std::enable_if<!Node::has_dynamic_ordering_children >::type extract_child(const Node &node, Child &child, ChildIndex child_index)
Definition: ordering/utility.hh:276
void afterChild(const Node &node, Child &child, TreePath tp, ChildIndex child_index)
Definition: ordering/utility.hh:262
std::enable_if< Node::has_dynamic_ordering_children >::type extract_child(const Node &node, Child &child, ChildIndex child_index)
Definition: ordering/utility.hh:269
Dummy iterator type over DOF indices.
Definition: ordering/utility.hh:301
DummyDOFIndexIterator & operator+=(size_type i)
Definition: ordering/utility.hh:310
DummyDOFIndexIterator & treeIndex()
Definition: ordering/utility.hh:325
void push_back(size_type i)
Definition: ordering/utility.hh:340
DummyDOFIndexIterator & operator++()
Definition: ordering/utility.hh:305
DummyDOFIndexIterator & operator*()
Definition: ordering/utility.hh:315
bool operator==(const DummyDOFIndexIterator &r) const
Definition: ordering/utility.hh:330
std::size_t size_type
Definition: ordering/utility.hh:303
bool operator!=(const DummyDOFIndexIterator &r) const
Definition: ordering/utility.hh:335
DummyDOFIndexIterator * operator->()
Definition: ordering/utility.hh:320
Adapter to create a size provider from an ordering.
Definition: ordering/utility.hh:363
ContainerIndex SizePrefix
Partial MultiIndex of a ContainerIndex.
Definition: ordering/utility.hh:383
SizeType size(const SizePrefix &prefix) const
Gives the size for a given prefix.
Definition: ordering/utility.hh:396
SizeProviderAdapter(const std::shared_ptr< const Ordering > &ordering)
Construct a new Size Provider Adapter object.
Definition: ordering/utility.hh:372
Size SizeType
Type that refers to the size of containers.
Definition: ordering/utility.hh:386
ContainerIndex_ ContainerIndex
Partial MultiIndex of a ContainerIndex.
Definition: ordering/utility.hh:380
static constexpr MultiIndexOrder ContainerIndexOrder
Inform about ContainerIndex multi-index order semantics.
Definition: ordering/utility.hh:389
static const unsigned int value
Definition: gridfunctionspace/tags.hh:139