dune-pdelab  2.0.0
subordering.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_SUBORDERING_HH
5 #define DUNE_PDELAB_ORDERING_SUBORDERING_HH
6 
7 #include <algorithm>
8 #include <iterator>
9 
10 #include <dune/common/shared_ptr.hh>
11 #include <dune/common/array.hh>
12 
13 #include <dune/typetree/treepath.hh>
14 #include <dune/typetree/proxynode.hh>
15 #include <dune/typetree/childextraction.hh>
16 
19 
20 namespace Dune {
21  namespace PDELab {
22 
25 
27 
49  template<typename BaseOrdering_, typename TreePath>
51  : public TypeTree::ProxyNode<const typename TypeTree::extract_child_type<BaseOrdering_,TreePath>::type>
52  , public PartitionInfoProvider
53  {
54 
55  typedef typename TypeTree::ProxyNode<const typename TypeTree::extract_child_type<BaseOrdering_,TreePath>::type> NodeT;
56 
57  public:
58 
60  typedef BaseOrdering_ BaseOrdering;
61 
63  typedef typename TypeTree::extract_child_type<BaseOrdering,TreePath>::type TargetOrdering;
64 
66  typedef typename BaseOrdering::Traits Traits;
67 
69  typedef typename BaseOrdering::ContainerAllocationTag ContainerAllocationTag;
70 
72  typedef typename BaseOrdering::CacheTag CacheTag;
73 
75  static const bool has_dynamic_ordering_children = TargetOrdering::has_dynamic_ordering_children;
76 
78  static const bool consume_tree_index = TargetOrdering::consume_tree_index;
79 
80 
82 
95  explicit SubOrdering(shared_ptr<const BaseOrdering> base_ordering)
96  : NodeT(TypeTree::extract_child_storage(*base_ordering,TreePath()))
97  , _base_ordering(base_ordering)
98  {
99  update();
100  }
101 
103  void update()
104  {
105  setPartitionSet(*_base_ordering);
106  }
107 
108 
109  template<typename ItIn, typename ItOut>
110  void map_lfs_indices(ItIn begin, const ItIn end, ItOut out) const
111  {
112  // Only allocate storage for our local copy of the DOFIndices once
113  // we really need it.
114  // _dof_indices.resize(maxLocalSize()); TODO:Remove this thing!
115 
116  // Do the mapping up to the root ordering.
117  // Avoid spelling out the type of ItIn here (it has to be a DOFIndexViewIterator),
118  // so we don't need to include lfsindexcache.hh.
119  map_lfs_indices_to_root_space(TreePath(),
120  begin,
121  end,
122  out);
123  }
124 
125 
126  private:
127 
128 
130  template<typename TP, typename ItIn, typename ItOut>
131  void map_lfs_indices_in_ancestor(TP tp, ItIn& begin, ItIn& end, ItOut out) const
132  {
133  typedef typename TypeTree::extract_child_type<BaseOrdering,TP>::type Ordering;
134 
135  // This logic needs to be replicated from the IndexCache visitor, as we bypass
136  // the tree-visiting algorithm and work our way up the tree all by ourselves.
137  // Don't consume the first entry in the tree path to the parent before it has
138  // been used!
139  if (!is_same<TreePath,TP>::value && Ordering::consume_tree_index)
140  {
141  begin.restore_back();
142  end.restore_back();
143  }
144 
145  // Call the single-level mapping step of our ancestor ordering.
146  TypeTree::extract_child(baseOrdering(),tp).map_lfs_indices(begin,end,out);
147  }
148 
149  // Template recursion for walking up the TreePath to the BaseOrdering
150  template<typename TP, typename ItIn, typename ItOut>
151  typename enable_if<
153  >::type
154  map_lfs_indices_to_root_space(TP, ItIn begin, ItIn end, ItOut out) const
155  {
156  map_lfs_indices_in_ancestor(TP(),begin,end,out);
157  // recurse further up to the tree
158  map_lfs_indices_to_root_space(typename TypeTree::TreePathPopBack<TP>::type(),begin,end,out);
159  }
160 
161  // End of template recursion for walking up the TreePath to the BaseOrdering
162  template<typename TP, typename ItIn, typename ItOut>
163  typename enable_if<
165  >::type
166  map_lfs_indices_to_root_space(TP, ItIn begin, ItIn end, ItOut out) const
167  {
168  map_lfs_indices_in_ancestor(TP(),begin,end,out);
169  }
170 
171  public:
172 
174  typename Traits::ContainerIndex mapIndex(const typename Traits::DOFIndex& di) const
175  {
176  typename Traits::ContainerIndex ci;
177  mapIndex(di,ci);
178  return ci;
179  }
180 
182  void mapIndex(typename Traits::DOFIndexView di, typename Traits::ContainerIndex& ci) const
183  {
184  baseOrdering().mapIndex(di,ci);
185  }
186 
188  typename Traits::SizeType size() const
189  {
190  return baseOrdering().size();
191  }
192 
194  typename Traits::SizeType blockCount() const
195  {
196  return baseOrdering().blockCount();
197  }
198 
200  typename Traits::SizeType maxLocalSize() const
201  {
202  return targetOrdering().maxLocalSize();
203  }
204 
206  bool contains(typename Traits::SizeType codim) const
207  {
208  return targetOrdering().contains(codim);
209  }
210 
212  bool fixedSize(typename Traits::SizeType codim) const
213  {
214  return targetOrdering().fixedSize(codim);
215  }
216 
218  const BaseOrdering& baseOrdering() const
219  {
220  return *_base_ordering;
221  }
222 
225  {
226  return this->proxiedNode();
227  }
228 
229  private:
230 
231  shared_ptr<const BaseOrdering> _base_ordering;
232 
233  };
234 
236 
237  } // namespace PDELab
238 } // namespace Dune
239 
240 #endif // DUNE_PDELAB_ORDERING_SUBORDERING_HH
Mixin class for providing information about contained grid partitions.
Definition: partitioninfoprovider.hh:22
const TargetOrdering & targetOrdering() const
Returns the TargetOrdering.
Definition: subordering.hh:224
BaseOrdering::Traits Traits
Forwarded Ordering traits from BaseOrdering.
Definition: subordering.hh:66
TypeTree::extract_child_type< BaseOrdering, TreePath >::type TargetOrdering
The target ordering that makes up the root of this SubOrdering view.
Definition: subordering.hh:63
void setPartitionSet(const std::bitset< 6 > &partitions)
Sets the set of contained partitions to the passed-in value.
Definition: partitioninfoprovider.hh:58
bool fixedSize(typename Traits::SizeType codim) const
Returns whether the TargetOrdering is of fixed size for entities of codimension codim.
Definition: subordering.hh:212
A view on a subtree of a multi-component ordering.
Definition: subordering.hh:50
const BaseOrdering & baseOrdering() const
Returns the BaseOrdering.
Definition: subordering.hh:218
BaseOrdering::CacheTag CacheTag
Forwarded tag from BaseOrdering, required by PDELab internals.
Definition: subordering.hh:72
void map_lfs_indices(ItIn begin, const ItIn end, ItOut out) const
Definition: subordering.hh:110
void mapIndex(typename Traits::DOFIndexView di, typename Traits::ContainerIndex &ci) const
Maps di from the DOFIndex subtree to the ContainerIndex in the BaseOrdering - inplace version...
Definition: subordering.hh:182
Traits::ContainerIndex mapIndex(const typename Traits::DOFIndex &di) const
Maps di from the DOFIndex subtree to the ContainerIndex in the BaseOrdering.
Definition: subordering.hh:174
Traits::SizeType size() const
Returns the size of the BaseOrdering.
Definition: subordering.hh:188
static const unsigned int value
Definition: gridfunctionspace/tags.hh:175
bool contains(typename Traits::SizeType codim) const
Returns whether the TargetOrdering has DOFs attached to entities of codimension codim.
Definition: subordering.hh:206
BaseOrdering::ContainerAllocationTag ContainerAllocationTag
Forwarded tag from BaseOrdering, required by PDELab internals.
Definition: subordering.hh:69
void update()
Updates this SubOrdering.
Definition: subordering.hh:103
BaseOrdering_ BaseOrdering
The type of the BaseOrdering for which to represent a SubOrdering view.
Definition: subordering.hh:60
Traits::SizeType blockCount() const
Returns the block count of the BaseOrdering.
Definition: subordering.hh:194
static const bool has_dynamic_ordering_children
Forwarded ordering property from TargetOrdering, required by PDELab internals.
Definition: subordering.hh:75
static const bool consume_tree_index
Forwarded ordering property from TargetOrdering, required by PDELab internals.
Definition: subordering.hh:78
Traits::SizeType maxLocalSize() const
Returns the maximum per-entity size of the TargetOrdering.
Definition: subordering.hh:200
SubOrdering(shared_ptr< const BaseOrdering > base_ordering)
Constructs a SubOrdering for base_ordering.
Definition: subordering.hh:95