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 
31 #ifndef DOXYGEN
32 
33  namespace ordering {
34 
35  // This is an implementation detail of the composite orderings, no need to confuse our users!
36  struct update_direct_children
37  : public TypeTree::DirectChildrenVisitor
38  , public TypeTree::DynamicTraversal
39  {
40 
41  template<typename GFS, typename Child, typename TreePath, typename ChildIndex>
42  void afterChild(const GFS& gfs, Child& child, TreePath tp, ChildIndex childIndex) const
43  {
44  child.update();
45  }
46 
47  };
48 
49  } // end namespace ordering
50 
51 #endif // DOXYGEN
52 
53 
55  {
56 
57  template<typename DOFIndex, typename SizeType, typename IndexType>
58  static typename std::enable_if<
60  >::type
61  store(DOFIndex& dof_index, const GeometryType& gt, SizeType entity_index, IndexType tree_index)
62  {
63  dof_index.clear();
64  dof_index.entityIndex()[0] = GlobalGeometryTypeIndex::index(gt);
65  dof_index.entityIndex()[1] = entity_index;
66  dof_index.treeIndex().push_back(tree_index);
67  }
68 
69  template<typename DOFIndex, typename SizeType, typename IndexType>
70  static typename std::enable_if<
72  >::type
73  store(DOFIndex& dof_index, const GeometryType& gt, SizeType entity_index, IndexType tree_index)
74  {
75  dof_index.entityIndex()[0] = GlobalGeometryTypeIndex::index(gt);
76  dof_index.entityIndex()[1] = entity_index;
77  dof_index.treeIndex() = tree_index;
78  }
79 
80  template<typename DOFIndex, typename SizeType, typename IndexType>
81  static typename std::enable_if<
83  >::type
84  store(DOFIndex& dof_index, SizeType gt_index, SizeType entity_index, IndexType tree_index)
85  {
86  dof_index.clear();
87  dof_index.entityIndex()[0] = gt_index;
88  dof_index.entityIndex()[1] = entity_index;
89  dof_index.treeIndex().push_back(tree_index);
90  }
91 
92  template<typename DOFIndex, typename SizeType, typename IndexType>
93  static typename std::enable_if<
95  >::type
96  store(DOFIndex& dof_index, SizeType gt_index, SizeType entity_index, IndexType tree_index)
97  {
98  dof_index.entityIndex()[0] = gt_index;
99  dof_index.entityIndex()[1] = entity_index;
100  dof_index.treeIndex() = tree_index;
101  }
102 
103 
105  {
106 
107  template<typename Index>
108  static std::size_t geometryType(const Index& geometry_index)
109  {
110  return geometry_index[0];
111  }
112 
113  template<typename Index>
114  static std::size_t entityIndex(const Index& geometry_index)
115  {
116  return geometry_index[1];
117  }
118 
119  template<typename Index, typename SizeType>
120  static void store(Index& index, const GeometryType& gt, SizeType entity_index)
121  {
123  index[1] = entity_index;
124  }
125 
126  };
127 
128  template<typename DOFIndex>
129  static std::size_t geometryType(const DOFIndex& dof_index)
130  {
131  return GeometryIndex::geometryType(dof_index.entityIndex());
132  }
133 
134  template<typename DOFIndex>
135  static std::size_t entityIndex(const DOFIndex& dof_index)
136  {
137  return GeometryIndex::entityIndex(dof_index.entityIndex());
138  }
139 
140  };
141 
143  {
144 
145  template<typename DOFIndex, typename SizeType>
146  static void store(DOFIndex& dof_index, const GeometryType& gt, SizeType entity_index, SizeType tree_index)
147  {
148  dof_index = entity_index;
149  }
150 
151  };
152 
153 
154  template<typename DI, typename CI>
156  {
157 
158  typedef DI DOFIndex;
159 
160  typedef CI ContainerIndex;
161 
162  typedef std::size_t SizeType;
163 
165 
166  };
167 
168 
169  template<typename SizeType_, typename CI>
170  struct SimpleOrderingTraits<SimpleDOFIndex<SizeType_>,CI>
171  {
172 
174 
175  typedef CI ContainerIndex;
176 
177  typedef SizeType_ SizeType;
178 
180 
181  };
182 
183 
184 
185  template<typename DI, typename CI>
187  : public SimpleOrderingTraits<DI,CI>
188  {
189 
190  // The maximum dimension supported (length of bitsets)
191  // 32 dimensions should probably be fine for now... ;-)
192  static const std::size_t max_dim = 32;
193 
194  typedef std::bitset<max_dim> CodimFlag;
195 
196  typedef typename DI::TreeIndex TreeIndex;
197 
198  typedef typename DI::View DOFIndexView;
199  typedef typename DI::View::TreeIndex TreeIndexView;
200 
201  typedef typename DI::size_type SizeType;
202  typedef typename DI::size_type size_type;
203 
204  };
205 
206 
207  template<typename ES, typename DI, typename CI>
209  : public OrderingTraits<DI,
210  CI
211  >
212  {
213 
214  using EntitySet = ES;
215  using GridView = typename ES::GridView;
216 
217  };
218 
219  template<typename ES, typename DI, typename CI>
221  : public LocalOrderingTraits<ES,DI,CI>
222  {
223 
224  typedef typename DI::EntityIndex EntityIndex;
225  typedef typename DI::View::EntityIndex EntityIndexView;
226 
227  };
228 
229 
230  template<typename DI, typename CI>
232  {
233  public:
234 
236 
238  virtual ~VirtualOrderingBase() = default;
239 
240  virtual void map_index_dynamic(typename Traits::DOFIndexView di, typename Traits::ContainerIndex& ci) const = 0;
241  };
242 
243 
244  template<typename child_type>
246  : public TypeTree::DirectChildrenVisitor
247  , public TypeTree::DynamicTraversal
248  {
249 
250  template<typename Node, typename Child, typename TreePath, typename ChildIndex>
251  void afterChild(const Node& node, Child& child, TreePath tp, ChildIndex child_index)
252  {
253  extract_child(node,child,child_index);
254  }
255 
256  template<typename Node, typename Child, typename ChildIndex>
257  typename std::enable_if<Node::has_dynamic_ordering_children>::type
258  extract_child(const Node& node, Child& child, ChildIndex child_index)
259  {
260  _children[child_index] = &child;
261  }
262 
263  template<typename Node, typename Child, typename ChildIndex>
264  typename std::enable_if<!Node::has_dynamic_ordering_children>::type
265  extract_child(const Node& node, Child& child, ChildIndex child_index)
266  {
267  }
268 
269  extract_child_bases(std::vector<child_type*>& children)
270  : _children(children)
271  {}
272 
273  private:
274  std::vector<child_type*>& _children;
275 
276  };
277 
278 
280 
290  {
291 
292  typedef std::size_t size_type;
293 
295  {
296  return *this;
297  }
298 
300  {
301  return *this;
302  }
303 
305  {
306  return *this;
307  }
308 
310  {
311  return this;
312  }
313 
315  {
316  return *this;
317  }
318 
319  bool operator==(const DummyDOFIndexIterator& r) const
320  {
321  return true;
322  }
323 
324  bool operator!=(const DummyDOFIndexIterator& r) const
325  {
326  return !operator==(r);
327  }
328 
330  {}
331 
332  };
333 
335  } // namespace PDELab
336 } // namespace Dune
337 
338 #endif // DUNE_PDELAB_ORDERING_UTILITY_HH
Dune::PDELab::SimpleDOFIndexAccessor::store
static void store(DOFIndex &dof_index, const GeometryType &gt, SizeType entity_index, SizeType tree_index)
Definition: ordering/utility.hh:146
index
std::size_t index
Definition: interpolate.hh:97
Dune::PDELab::SimpleDOFIndexAccessor
Definition: ordering/utility.hh:142
Dune::PDELab::extract_child_bases::extract_child_bases
extract_child_bases(std::vector< child_type * > &children)
Definition: ordering/utility.hh:269
Dune::PDELab::LocalOrderingTraits::EntitySet
ES EntitySet
Definition: ordering/utility.hh:214
Dune::PDELab::VirtualOrderingBase
Definition: ordering/utility.hh:231
Dune::PDELab::DefaultDOFIndexAccessor::GeometryIndex::geometryType
static std::size_t geometryType(const Index &geometry_index)
Definition: ordering/utility.hh:108
Dune::PDELab::DummyDOFIndexIterator::operator++
DummyDOFIndexIterator & operator++()
Definition: ordering/utility.hh:294
Dune::PDELab::VirtualOrderingBase::~VirtualOrderingBase
virtual ~VirtualOrderingBase()=default
Dune::PDELab::OrderingTraits::CodimFlag
std::bitset< max_dim > CodimFlag
Definition: ordering/utility.hh:194
Dune::PDELab::GridViewOrderingTraits::EntityIndexView
DI::View::EntityIndex EntityIndexView
Definition: ordering/utility.hh:225
Dune::PDELab::extract_child_bases::extract_child
std::enable_if< Node::has_dynamic_ordering_children >::type extract_child(const Node &node, Child &child, ChildIndex child_index)
Definition: ordering/utility.hh:258
Dune::PDELab::extract_child_bases::extract_child
std::enable_if<!Node::has_dynamic_ordering_children >::type extract_child(const Node &node, Child &child, ChildIndex child_index)
Definition: ordering/utility.hh:265
Dune::PDELab::SimpleOrderingTraits::SizeType
std::size_t SizeType
Definition: ordering/utility.hh:162
Dune::PDELab::LocalOrderingTraits
Definition: ordering/utility.hh:208
Dune
For backward compatibility – Do not use this!
Definition: adaptivity.hh:28
Dune::PDELab::DOFIndex::clear
void clear()
Definition: dofindex.hh:251
Dune::PDELab::OrderingTraits::TreeIndexView
DI::View::TreeIndex TreeIndexView
Definition: ordering/utility.hh:199
Dune::PDELab::MergeMode::interleaved
@ interleaved
Indices are interleaved according to a user-supplied pattern ([i1,i2],[j1,j2] -> [i1,...
Definition: ordering/utility.hh:26
Dune::PDELab::DefaultDOFIndexAccessor::GeometryIndex::store
static void store(Index &index, const GeometryType &gt, SizeType entity_index)
Definition: ordering/utility.hh:120
Dune::PDELab::MergeMode::type
type
Definition: ordering/utility.hh:24
Dune::PDELab::DefaultDOFIndexAccessor::GeometryIndex
Definition: ordering/utility.hh:104
Dune::PDELab::VirtualOrderingBase::VirtualOrderingBase
VirtualOrderingBase()
Definition: ordering/utility.hh:237
Dune::PDELab::OrderingTraits::DOFIndexView
DI::View DOFIndexView
Definition: ordering/utility.hh:198
Dune::PDELab::DummyDOFIndexIterator::operator+=
DummyDOFIndexIterator & operator+=(size_type i)
Definition: ordering/utility.hh:299
Dune::PDELab::DOFIndex
A multi-index representing a degree of freedom in a GridFunctionSpace.
Definition: dofindex.hh:147
Dune::PDELab::MergeMode
Index merging algorithm for global orderings.
Definition: ordering/utility.hh:21
value
static const unsigned int value
Definition: gridfunctionspace/tags.hh:139
Dune::PDELab::DummyDOFIndexIterator
Dummy iterator type over DOF indices.
Definition: ordering/utility.hh:289
Dune::PDELab::SimpleOrderingTraits
Definition: ordering/utility.hh:155
Dune::PDELab::GridViewOrderingTraits::EntityIndex
DI::EntityIndex EntityIndex
Definition: ordering/utility.hh:224
Dune::PDELab::DefaultDOFIndexAccessor::store
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:61
Dune::PDELab::DefaultDOFIndexAccessor::store
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:73
Dune::PDELab::SimpleOrderingTraits::DOFIndexAccessor
DefaultDOFIndexAccessor DOFIndexAccessor
Definition: ordering/utility.hh:164
transformations.hh
Define and register ordering related transformations. This header defines the two transformations gfs...
Dune::PDELab::OrderingTraits::size_type
DI::size_type size_type
Definition: ordering/utility.hh:202
Dune::PDELab::OrderingTraits::max_dim
static const std::size_t max_dim
Definition: ordering/utility.hh:192
Dune::PDELab::DOFIndex::treeIndex
TreeIndex & treeIndex()
Returns the tuple of entity-local indices associated with the DOF.
Definition: dofindex.hh:270
Dune::PDELab::DummyDOFIndexIterator::size_type
std::size_t size_type
Definition: ordering/utility.hh:292
Dune::PDELab::DummyDOFIndexIterator::push_back
void push_back(size_type i)
Definition: ordering/utility.hh:329
Dune::PDELab::SimpleOrderingTraits< SimpleDOFIndex< SizeType_ >, CI >::DOFIndex
SimpleDOFIndex< SizeType_ > DOFIndex
Definition: ordering/utility.hh:173
Dune::PDELab::DummyDOFIndexIterator::operator!=
bool operator!=(const DummyDOFIndexIterator &r) const
Definition: ordering/utility.hh:324
Dune::PDELab::OrderingTraits::SizeType
DI::size_type SizeType
Definition: ordering/utility.hh:201
Dune::PDELab::GridViewOrderingTraits
Definition: ordering/utility.hh:220
Dune::PDELab::MergeMode::lexicographic
@ lexicographic
Lexicographically ordered ([i1,i2],[j1,j2] -> [i1,i2,j1,j2]).
Definition: ordering/utility.hh:25
Dune::PDELab::SimpleOrderingTraits::DOFIndex
DI DOFIndex
Definition: ordering/utility.hh:158
Dune::PDELab::DOFIndex::entityIndex
EntityIndex & entityIndex()
Returns the index of the grid entity associated with the DOF.
Definition: dofindex.hh:258
Dune::PDELab::DummyDOFIndexIterator::operator*
DummyDOFIndexIterator & operator*()
Definition: ordering/utility.hh:304
Dune::PDELab::DefaultDOFIndexAccessor::store
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:84
Dune::PDELab::DummyDOFIndexIterator::treeIndex
DummyDOFIndexIterator & treeIndex()
Definition: ordering/utility.hh:314
Dune::PDELab::SimpleDOFIndex
Definition: simpledofindex.hh:14
globaldofindex.hh
Dune::PDELab::OrderingTraits
Definition: ordering/utility.hh:186
Dune::PDELab::DefaultDOFIndexAccessor::store
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:96
Dune::PDELab::SimpleOrderingTraits::ContainerIndex
CI ContainerIndex
Definition: ordering/utility.hh:160
Dune::PDELab::SimpleOrderingTraits< SimpleDOFIndex< SizeType_ >, CI >::ContainerIndex
CI ContainerIndex
Definition: ordering/utility.hh:175
Dune::PDELab::LocalOrderingTraits::GridView
typename ES::GridView GridView
Definition: ordering/utility.hh:215
Dune::PDELab::VirtualOrderingBase::map_index_dynamic
virtual void map_index_dynamic(typename Traits::DOFIndexView di, typename Traits::ContainerIndex &ci) const =0
Dune::PDELab::DefaultDOFIndexAccessor::geometryType
static std::size_t geometryType(const DOFIndex &dof_index)
Definition: ordering/utility.hh:129
Dune::PDELab::DummyDOFIndexIterator::operator==
bool operator==(const DummyDOFIndexIterator &r) const
Definition: ordering/utility.hh:319
Dune::PDELab::SimpleOrderingTraits< SimpleDOFIndex< SizeType_ >, CI >::SizeType
SizeType_ SizeType
Definition: ordering/utility.hh:177
Dune::PDELab::DefaultDOFIndexAccessor
Definition: ordering/utility.hh:54
Dune::PDELab::extract_child_bases
Definition: ordering/utility.hh:245
Dune::PDELab::DummyDOFIndexIterator::operator->
DummyDOFIndexIterator * operator->()
Definition: ordering/utility.hh:309
Dune::PDELab::VirtualOrderingBase::Traits
OrderingTraits< DI, CI > Traits
Definition: ordering/utility.hh:235
Dune::PDELab::extract_child_bases::afterChild
void afterChild(const Node &node, Child &child, TreePath tp, ChildIndex child_index)
Definition: ordering/utility.hh:251
Dune::PDELab::SimpleOrderingTraits< SimpleDOFIndex< SizeType_ >, CI >::DOFIndexAccessor
SimpleDOFIndexAccessor DOFIndexAccessor
Definition: ordering/utility.hh:179
dofindex.hh
Dune::PDELab::DefaultDOFIndexAccessor::entityIndex
static std::size_t entityIndex(const DOFIndex &dof_index)
Definition: ordering/utility.hh:135
Dune::PDELab::OrderingTraits::TreeIndex
DI::TreeIndex TreeIndex
Definition: ordering/utility.hh:196
Dune::PDELab::DefaultDOFIndexAccessor::GeometryIndex::entityIndex
static std::size_t entityIndex(const Index &geometry_index)
Definition: ordering/utility.hh:114