dune-pdelab  2.7-git
leaforderingbase.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_LEAFORDERINGBASE_HH
5 #define DUNE_PDELAB_ORDERING_LEAFORDERINGBASE_HH
6 
7 #include <dune/typetree/typetree.hh>
8 
12 
13 namespace Dune {
14  namespace PDELab {
15 
18 
20  template<typename LocalOrdering>
22  : public TypeTree::CompositeNode<LocalOrdering>
23  , public VirtualOrderingBase<typename LocalOrdering::Traits::DOFIndex,
24  typename LocalOrdering::Traits::ContainerIndex>
25  , public OrderingBase<typename LocalOrdering::Traits::DOFIndex,
26  typename LocalOrdering::Traits::ContainerIndex>
27  {
28  public:
29  typedef typename LocalOrdering::Traits Traits;
30 
31  static const bool has_dynamic_ordering_children = false;
32 
33  static const bool consume_tree_index = false;
34 
35  protected:
36 
37  typedef TypeTree::CompositeNode<LocalOrdering> NodeT;
38 
39  typedef OrderingBase<typename LocalOrdering::Traits::DOFIndex,
40  typename LocalOrdering::Traits::ContainerIndex> BaseT;
41 
42  public:
43 
44  LocalOrdering& localOrdering()
45  {
46  return this->template child<0>();
47  }
48 
49  const LocalOrdering& localOrdering() const
50  {
51  return this->template child<0>();
52  }
53 
54 
55  LeafOrderingBase(const typename NodeT::NodeStorage& local_ordering, bool container_blocked, typename BaseT::GFSData* gfs_data)
56  : NodeT(local_ordering)
57  , BaseT(*this,container_blocked,gfs_data,this)
58  {}
59 
60 #ifndef DOXYGEN
61 
62 // we need to override the default copy / move ctor to fix the delegate pointer, but that is
63 // hardly interesting to our users...
64 
66  : NodeT(r.nodeStorage())
67  , BaseT(r)
69  {
70  this->setDelegate(this);
71  }
72 
74  : NodeT(r.nodeStorage())
75  , BaseT(std::move(r))
76  , _gt_dof_offsets(std::move(r._gt_dof_offsets))
77  {
78  this->setDelegate(this);
79  }
80 
81 #endif // DOXYGEN
82 
83  virtual ~LeafOrderingBase() override = default;
84 
85  virtual void map_index_dynamic(typename Traits::DOFIndexView di, typename Traits::ContainerIndex& ci) const override
86  {
87  mapIndex(di,ci);
88  }
89 
90  typename Traits::ContainerIndex mapIndex(const typename Traits::DOFIndex& di) const
91  {
92  typename Traits::ContainerIndex ci;
93  mapIndex(di.view(),ci);
94  return ci;
95  }
96 
97  void mapIndex(typename Traits::DOFIndexView di, typename Traits::ContainerIndex& ci) const
98  {
99 
100  const typename Traits::SizeType geometry_type_index = Traits::DOFIndexAccessor::geometryType(di);
101  const typename Traits::SizeType entity_index = Traits::DOFIndexAccessor::entityIndex(di);
102  assert (di.treeIndex().size() == 1);
103  ci.push_back(di.treeIndex().back());
104 
106  {
107  if (_container_blocked)
108  {
109  // This check is needed to avoid a horrid stream of compiler warnings about
110  // exceeding array bounds in ReservedVector!
111  if (ci.size() < ci.capacity())
112  ci.push_back(_gt_dof_offsets[geometry_type_index] + entity_index);
113  else
114  {
115  DUNE_THROW(Dune::Exception,"Container blocking incompatible with backend structure");
116  }
117  }
118  else
119  {
120  ci.back() += _gt_dof_offsets[geometry_type_index] + entity_index * localOrdering()._gt_dof_sizes[geometry_type_index];
121  }
122  }
123  else
124  {
125  if (_container_blocked)
126  {
127  // This check is needed to avoid a horrid stream of compiler warnings about
128  // exceeding array bounds in ReservedVector!
129  if (ci.size() < ci.capacity())
130  ci.push_back(localOrdering()._gt_entity_offsets[geometry_type_index] + entity_index);
131  else
132  {
133  DUNE_THROW(Dune::Exception,"Container blocking incompatible with backend structure");
134  }
135  }
136  else
137  {
138  ci.back() += localOrdering()._entity_dof_offsets[localOrdering()._gt_entity_offsets[geometry_type_index] + entity_index];
139  }
140  }
141  }
142 
143 
144  template<typename ItIn, typename ItOut>
145  void map_lfs_indices(const ItIn begin, const ItIn end, ItOut out) const
146  {
147  typedef typename Traits::SizeType size_type;
148 
150  {
151  if (_container_blocked)
152  {
153  for (ItIn in = begin; in != end; ++in, ++out)
154  {
155  assert(in->treeIndex().size() == 1);
156  out->push_back(in->treeIndex().back());
157  const size_type geometry_type_index = Traits::DOFIndexAccessor::geometryType(*in);
158  const size_type entity_index = Traits::DOFIndexAccessor::entityIndex(*in);
159  assert(localOrdering()._gt_used[geometry_type_index]);
160  out->push_back(_gt_dof_offsets[geometry_type_index] + entity_index);
161  }
162  }
163  else
164  {
165  for (ItIn in = begin; in != end; ++in, ++out)
166  {
167  assert(in->treeIndex().size() == 1);
168  out->push_back(in->treeIndex().back());
169  const size_type geometry_type_index = Traits::DOFIndexAccessor::geometryType(*in);
170  const size_type entity_index = Traits::DOFIndexAccessor::entityIndex(*in);
171  assert(localOrdering()._gt_used[geometry_type_index]);
172  out->back() += _gt_dof_offsets[geometry_type_index] + entity_index * localOrdering()._gt_dof_sizes[geometry_type_index];
173  }
174  }
175  }
176  else
177  {
178  if (_container_blocked)
179  {
180  for (ItIn in = begin; in != end; ++in, ++out)
181  {
182  assert(in->treeIndex().size() == 1);
183  out->push_back(in->treeIndex().back());
184  const size_type geometry_type_index = Traits::DOFIndexAccessor::geometryType(*in);
185  const size_type entity_index = Traits::DOFIndexAccessor::entityIndex(*in);
186  assert(localOrdering()._gt_used[geometry_type_index]);
187  out->push_back(localOrdering()._gt_entity_offsets[geometry_type_index] + entity_index);
188  }
189  }
190  else
191  {
192  for (ItIn in = begin; in != end; ++in, ++out)
193  {
194  assert(in->treeIndex().size() == 1);
195  out->push_back(in->treeIndex().back());
196  const size_type geometry_type_index = Traits::DOFIndexAccessor::geometryType(*in);
197  const size_type entity_index = Traits::DOFIndexAccessor::entityIndex(*in);
198  assert(localOrdering()._gt_used[geometry_type_index]);
199  out->back() += localOrdering()._entity_dof_offsets[localOrdering()._gt_entity_offsets[geometry_type_index] + entity_index];
200  }
201  }
202  }
203  }
204 
205  template<typename CIOutIterator>
206  typename Traits::SizeType
207  extract_entity_indices(const typename Traits::DOFIndex::EntityIndex& ei,
208  typename Traits::SizeType child_index,
209  CIOutIterator ci_out, const CIOutIterator ci_end) const
210  {
211  typedef typename Traits::SizeType size_type;
212 
213  const size_type geometry_type_index = Traits::DOFIndexAccessor::GeometryIndex::geometryType(ei);
214  const size_type entity_index = Traits::DOFIndexAccessor::GeometryIndex::entityIndex(ei);
215 
216  if (!localOrdering()._gt_used[geometry_type_index])
217  return 0;
218 
220  {
221  size_type size = localOrdering()._gt_dof_sizes[geometry_type_index];
222  if (_container_blocked)
223  {
224  for (size_type i = 0; i < size; ++i, ++ci_out)
225  {
226  ci_out->push_back(i);
227  ci_out->push_back(_gt_dof_offsets[geometry_type_index] + entity_index);
228  }
229  }
230  else
231  {
232  for (size_type i = 0; i < size; ++i, ++ci_out)
233  {
234  ci_out->push_back(i);
235  ci_out->back() += _gt_dof_offsets[geometry_type_index] + entity_index * localOrdering()._gt_dof_sizes[geometry_type_index];
236  }
237  }
238  return 0;
239  }
240  else
241  {
242  size_type index = localOrdering()._gt_entity_offsets[geometry_type_index] + entity_index;
243  size_type size = localOrdering()._entity_dof_offsets[index+1] - localOrdering()._entity_dof_offsets[index];
244  if (_container_blocked)
245  {
246  for (size_type i = 0; i < size; ++i, ++ci_out)
247  {
248  ci_out->push_back(i);
249  ci_out->push_back(index);
250  }
251  }
252  else
253  {
254  for (size_type i = 0; i < size; ++i, ++ci_out)
255  {
256  ci_out->push_back(i);
257  ci_out->back() += localOrdering()._entity_dof_offsets[index];
258  }
259  }
260  return 0;
261  }
262  }
263 
267  virtual void update() = 0;
268 
269  using BaseT::fixedSize;
270 
271  protected:
272 
274  using BaseT::_size;
275  using BaseT::_block_count;
277  using BaseT::_fixed_size;
278  using BaseT::_codim_used;
280 
281  std::vector<typename Traits::SizeType> _gt_dof_offsets;
282 
283  };
284 
286  } // namespace PDELab
287 } // namespace Dune
288 
289 #endif // DUNE_PDELAB_ORDERING_LEAFORDERINGBASE_HH
std::size_t index
Definition: interpolate.hh:97
For backward compatibility – Do not use this!
Definition: adaptivity.hh:28
Generic infrastructure for orderings for leaf spaces.
Definition: leaforderingbase.hh:27
OrderingBase< typename LocalOrdering::Traits::DOFIndex, typename LocalOrdering::Traits::ContainerIndex > BaseT
Definition: leaforderingbase.hh:40
LeafOrderingBase(const typename NodeT::NodeStorage &local_ordering, bool container_blocked, typename BaseT::GFSData *gfs_data)
Definition: leaforderingbase.hh:55
LocalOrdering::Traits Traits
Definition: leaforderingbase.hh:29
const LocalOrdering & localOrdering() const
Definition: leaforderingbase.hh:49
Traits::SizeType extract_entity_indices(const typename Traits::DOFIndex::EntityIndex &ei, typename Traits::SizeType child_index, CIOutIterator ci_out, const CIOutIterator ci_end) const
Definition: leaforderingbase.hh:207
virtual ~LeafOrderingBase() override=default
virtual void map_index_dynamic(typename Traits::DOFIndexView di, typename Traits::ContainerIndex &ci) const override
Definition: leaforderingbase.hh:85
static const bool has_dynamic_ordering_children
Definition: leaforderingbase.hh:31
void mapIndex(typename Traits::DOFIndexView di, typename Traits::ContainerIndex &ci) const
Definition: leaforderingbase.hh:97
std::vector< typename Traits::SizeType > _gt_dof_offsets
Definition: leaforderingbase.hh:281
Traits::ContainerIndex mapIndex(const typename Traits::DOFIndex &di) const
Definition: leaforderingbase.hh:90
void map_lfs_indices(const ItIn begin, const ItIn end, ItOut out) const
Definition: leaforderingbase.hh:145
static const bool consume_tree_index
Definition: leaforderingbase.hh:33
TypeTree::CompositeNode< LocalOrdering > NodeT
Definition: leaforderingbase.hh:37
LocalOrdering & localOrdering()
Definition: leaforderingbase.hh:44
bool _fixed_size
Definition: orderingbase.hh:274
const bool _container_blocked
Definition: orderingbase.hh:275
Definition: orderingbase.hh:21
Dune::PDELab::impl::GridFunctionSpaceOrderingData< typename Traits::SizeType > GFSData
Definition: orderingbase.hh:32
Traits::CodimFlag _codim_fixed_size
Definition: orderingbase.hh:285
bool fixedSize() const
Definition: orderingbase.hh:209
Traits::CodimFlag _codim_used
Definition: orderingbase.hh:284
std::size_t _size
Definition: orderingbase.hh:288
void setDelegate(const VirtualOrderingBase< LocalOrdering::Traits::DOFIndex, LocalOrdering::Traits::ContainerIndex > *delegate)
Set the delegate called in mapIndex().
Definition: orderingbase.hh:227
std::size_t _max_local_size
Definition: orderingbase.hh:287
std::size_t _block_count
Definition: orderingbase.hh:289
bool _fixed_size
Definition: orderingbase.hh:274
const bool _container_blocked
Definition: orderingbase.hh:275
Definition: ordering/utility.hh:243