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