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