dune-pdelab  2.4.1
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 void map_index_dynamic(typename Traits::DOFIndexView di, typename Traits::ContainerIndex& ci) const
84  {
85  mapIndex(di,ci);
86  }
87 
88  typename Traits::ContainerIndex mapIndex(const typename Traits::DOFIndex& di) const
89  {
90  typename Traits::ContainerIndex ci;
91  mapIndex(di.view(),ci);
92  return ci;
93  }
94 
95  void mapIndex(typename Traits::DOFIndexView di, typename Traits::ContainerIndex& ci) const
96  {
97 
98  const typename Traits::SizeType geometry_type_index = Traits::DOFIndexAccessor::geometryType(di);
99  const typename Traits::SizeType entity_index = Traits::DOFIndexAccessor::entityIndex(di);
100  assert (di.treeIndex().size() == 1);
101  ci.push_back(di.treeIndex().back());
102 
103  if (localOrdering()._fixed_size)
104  {
105  if (_container_blocked)
106  {
107  // This check is needed to avoid a horrid stream of compiler warnings about
108  // exceeding array bounds in ReservedVector!
109  if (ci.size() < ci.capacity())
110  ci.push_back(_gt_dof_offsets[geometry_type_index] + entity_index);
111  else
112  {
113  DUNE_THROW(Dune::Exception,"Container blocking incompatible with backend structure");
114  }
115  }
116  else
117  {
118  ci.back() += _gt_dof_offsets[geometry_type_index] + entity_index * localOrdering()._gt_dof_sizes[geometry_type_index];
119  }
120  }
121  else
122  {
123  if (_container_blocked)
124  {
125  // This check is needed to avoid a horrid stream of compiler warnings about
126  // exceeding array bounds in ReservedVector!
127  if (ci.size() < ci.capacity())
128  ci.push_back(localOrdering()._gt_entity_offsets[geometry_type_index] + entity_index);
129  else
130  {
131  DUNE_THROW(Dune::Exception,"Container blocking incompatible with backend structure");
132  }
133  }
134  else
135  {
136  ci.back() += localOrdering()._entity_dof_offsets[localOrdering()._gt_entity_offsets[geometry_type_index] + entity_index];
137  }
138  }
139  }
140 
141 
142  template<typename ItIn, typename ItOut>
143  void map_lfs_indices(const ItIn begin, const ItIn end, ItOut out) const
144  {
145  typedef typename Traits::SizeType size_type;
146 
148  {
149  if (_container_blocked)
150  {
151  for (ItIn in = begin; in != end; ++in, ++out)
152  {
153  assert(in->treeIndex().size() == 1);
154  out->push_back(in->treeIndex().back());
155  const size_type geometry_type_index = Traits::DOFIndexAccessor::geometryType(*in);
156  const size_type entity_index = Traits::DOFIndexAccessor::entityIndex(*in);
157  assert(localOrdering()._gt_used[geometry_type_index]);
158  out->push_back(_gt_dof_offsets[geometry_type_index] + entity_index);
159  }
160  }
161  else
162  {
163  for (ItIn in = begin; in != end; ++in, ++out)
164  {
165  assert(in->treeIndex().size() == 1);
166  out->push_back(in->treeIndex().back());
167  const size_type geometry_type_index = Traits::DOFIndexAccessor::geometryType(*in);
168  const size_type entity_index = Traits::DOFIndexAccessor::entityIndex(*in);
169  assert(localOrdering()._gt_used[geometry_type_index]);
170  out->back() += _gt_dof_offsets[geometry_type_index] + entity_index * localOrdering()._gt_dof_sizes[geometry_type_index];
171  }
172  }
173  }
174  else
175  {
176  if (_container_blocked)
177  {
178  for (ItIn in = begin; in != end; ++in, ++out)
179  {
180  assert(in->treeIndex().size() == 1);
181  out->push_back(in->treeIndex().back());
182  const size_type geometry_type_index = Traits::DOFIndexAccessor::geometryType(*in);
183  const size_type entity_index = Traits::DOFIndexAccessor::entityIndex(*in);
184  assert(localOrdering()._gt_used[geometry_type_index]);
185  out->push_back(localOrdering()._gt_entity_offsets[geometry_type_index] + entity_index);
186  }
187  }
188  else
189  {
190  for (ItIn in = begin; in != end; ++in, ++out)
191  {
192  assert(in->treeIndex().size() == 1);
193  out->push_back(in->treeIndex().back());
194  const size_type geometry_type_index = Traits::DOFIndexAccessor::geometryType(*in);
195  const size_type entity_index = Traits::DOFIndexAccessor::entityIndex(*in);
196  assert(localOrdering()._gt_used[geometry_type_index]);
197  out->back() += localOrdering()._entity_dof_offsets[localOrdering()._gt_entity_offsets[geometry_type_index] + entity_index];
198  }
199  }
200  }
201  }
202 
203  template<typename CIOutIterator>
204  typename Traits::SizeType
205  extract_entity_indices(const typename Traits::DOFIndex::EntityIndex& ei,
206  typename Traits::SizeType child_index,
207  CIOutIterator ci_out, const CIOutIterator ci_end) const
208  {
209  typedef typename Traits::SizeType size_type;
210 
211  const size_type geometry_type_index = Traits::DOFIndexAccessor::GeometryIndex::geometryType(ei);
212  const size_type entity_index = Traits::DOFIndexAccessor::GeometryIndex::entityIndex(ei);
213 
214  if (!localOrdering()._gt_used[geometry_type_index])
215  return 0;
216 
218  {
219  size_type size = localOrdering()._gt_dof_sizes[geometry_type_index];
220  if (_container_blocked)
221  {
222  for (size_type i = 0; i < size; ++i, ++ci_out)
223  {
224  ci_out->push_back(i);
225  ci_out->push_back(_gt_dof_offsets[geometry_type_index] + entity_index);
226  }
227  }
228  else
229  {
230  for (size_type i = 0; i < size; ++i, ++ci_out)
231  {
232  ci_out->push_back(i);
233  ci_out->back() += _gt_dof_offsets[geometry_type_index] + entity_index * localOrdering()._gt_dof_sizes[geometry_type_index];
234  }
235  }
236  return 0;
237  }
238  else
239  {
240  size_type index = localOrdering()._gt_entity_offsets[geometry_type_index] + entity_index;
241  size_type size = localOrdering()._entity_dof_offsets[index+1] - localOrdering()._entity_dof_offsets[index];
242  if (_container_blocked)
243  {
244  for (size_type i = 0; i < size; ++i, ++ci_out)
245  {
246  ci_out->push_back(i);
247  ci_out->push_back(index);
248  }
249  }
250  else
251  {
252  for (size_type i = 0; i < size; ++i, ++ci_out)
253  {
254  ci_out->push_back(i);
255  ci_out->back() += localOrdering()._entity_dof_offsets[index];
256  }
257  }
258  return 0;
259  }
260  }
261 
265  virtual void update() = 0;
266 
267  using BaseT::fixedSize;
268 
269  protected:
270 
272  using BaseT::_size;
273  using BaseT::_block_count;
275  using BaseT::_fixed_size;
276  using BaseT::_codim_used;
278 
279  std::vector<typename Traits::SizeType> _gt_dof_offsets;
280 
281  };
282 
284  } // namespace PDELab
285 } // namespace Dune
286 
287 #endif // DUNE_PDELAB_ORDERING_LEAFORDERING_HH
Dune::PDELab::impl::GridFunctionSpaceOrderingData< typename Traits::SizeType > GFSData
Definition: orderingbase.hh:32
void setDelegate(const VirtualOrderingBase< LocalOrdering::Traits::DOFIndex, LocalOrdering::Traits::ContainerIndex > *delegate)
Set the delegate called in mapIndex().
Definition: orderingbase.hh:222
void mapIndex(typename Traits::DOFIndexView di, typename Traits::ContainerIndex &ci) const
Definition: leaforderingbase.hh:95
Traits::CodimFlag _codim_fixed_size
Definition: orderingbase.hh:280
std::size_t _max_local_size
Definition: orderingbase.hh:282
std::size_t _block_count
Definition: orderingbase.hh:284
Definition: adaptivity.hh:27
Generic infrastructure for orderings for leaf spaces.
Definition: leaforderingbase.hh:21
static const bool has_dynamic_ordering_children
Definition: leaforderingbase.hh:31
OrderingBase< typename LocalOrdering::Traits::DOFIndex, typename LocalOrdering::Traits::ContainerIndex > BaseT
Definition: leaforderingbase.hh:40
std::vector< typename Traits::SizeType > _gt_dof_offsets
Definition: leaforderingbase.hh:279
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:205
virtual void map_index_dynamic(typename Traits::DOFIndexView di, typename Traits::ContainerIndex &ci) const
Definition: leaforderingbase.hh:83
static const bool consume_tree_index
Definition: leaforderingbase.hh:33
Traits::ContainerIndex mapIndex(const typename Traits::DOFIndex &di) const
Definition: leaforderingbase.hh:88
TypeTree::CompositeNode< LocalOrdering > NodeT
Definition: leaforderingbase.hh:37
const LocalOrdering & localOrdering() const
Definition: leaforderingbase.hh:49
LeafOrderingBase(const typename NodeT::NodeStorage &local_ordering, bool container_blocked, typename BaseT::GFSData *gfs_data)
Definition: leaforderingbase.hh:55
bool fixedSize(typename Traits::SizeType codim) const
Definition: orderingbase.hh:209
Definition: ordering/utility.hh:231
Definition: orderingbase.hh:20
LocalOrdering & localOrdering()
Definition: leaforderingbase.hh:44
void map_lfs_indices(const ItIn begin, const ItIn end, ItOut out) const
Definition: leaforderingbase.hh:143
LocalOrdering::Traits Traits
Definition: leaforderingbase.hh:29
Traits::CodimFlag _codim_used
Definition: orderingbase.hh:279
std::size_t _size
Definition: orderingbase.hh:283