dune-pdelab  2.5-dev
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 #include <memory>
10 
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 
18 
19 namespace Dune {
20  namespace PDELab {
21 
24 
26 
48  template<typename BaseOrdering_, typename TreePath>
50  : public TypeTree::ProxyNode<const TypeTree::ChildForTreePath<BaseOrdering_,TreePath>>
51  {
52 
53  using NodeT = TypeTree::ProxyNode<const TypeTree::ChildForTreePath<BaseOrdering_,TreePath>>;
54 
55  public:
56 
58  typedef BaseOrdering_ BaseOrdering;
59 
61  using TargetOrdering = TypeTree::ChildForTreePath<BaseOrdering,TreePath>;
62 
64  typedef typename BaseOrdering::Traits Traits;
65 
67  typedef typename BaseOrdering::ContainerAllocationTag ContainerAllocationTag;
68 
70  typedef typename BaseOrdering::CacheTag CacheTag;
71 
73  static const bool has_dynamic_ordering_children = TargetOrdering::has_dynamic_ordering_children;
74 
76  static const bool consume_tree_index = TargetOrdering::consume_tree_index;
77 
78 
80 
93  explicit SubOrdering(std::shared_ptr<const BaseOrdering> base_ordering)
94  : NodeT(base_ordering->child(TreePath()))
95  , _base_ordering(base_ordering)
96  {
97  update();
98  }
99 
101  void update()
102  {}
103 
104 
105  template<typename ItIn, typename ItOut>
106  void map_lfs_indices(ItIn begin, const ItIn end, ItOut out) const
107  {
108  // Only allocate storage for our local copy of the DOFIndices once
109  // we really need it.
110  // _dof_indices.resize(maxLocalSize()); TODO:Remove this thing!
111 
112  // Do the mapping up to the root ordering.
113  // Avoid spelling out the type of ItIn here (it has to be a DOFIndexViewIterator),
114  // so we don't need to include lfsindexcache.hh.
115  map_lfs_indices_to_root_space(TreePath(),
116  begin,
117  end,
118  out);
119  }
120 
121 
122  private:
123 
124 
126  template<typename TP, typename ItIn, typename ItOut>
127  void map_lfs_indices_in_ancestor(TP tp, ItIn& begin, ItIn& end, ItOut out) const
128  {
129  using Ordering = TypeTree::ChildForTreePath<BaseOrdering,TP>;
130 
131  // This logic needs to be replicated from the IndexCache visitor, as we bypass
132  // the tree-visiting algorithm and work our way up the tree all by ourselves.
133  // Don't consume the first entry in the tree path to the parent before it has
134  // been used!
135  if (!std::is_same<TreePath,TP>::value && Ordering::consume_tree_index)
136  {
137  begin.restore_back();
138  end.restore_back();
139  }
140 
141  // Call the single-level mapping step of our ancestor ordering.
142  TypeTree::child(baseOrdering(),tp).map_lfs_indices(begin,end,out);
143  }
144 
145  // Template recursion for walking up the TreePath to the BaseOrdering
146  template<typename TP, typename ItIn, typename ItOut>
147  typename std::enable_if<
149  >::type
150  map_lfs_indices_to_root_space(TP, ItIn begin, ItIn end, ItOut out) const
151  {
152  map_lfs_indices_in_ancestor(TP(),begin,end,out);
153  // recurse further up to the tree
154  map_lfs_indices_to_root_space(typename TypeTree::TreePathPopBack<TP>::type(),begin,end,out);
155  }
156 
157  // End of template recursion for walking up the TreePath to the BaseOrdering
158  template<typename TP, typename ItIn, typename ItOut>
159  typename std::enable_if<
161  >::type
162  map_lfs_indices_to_root_space(TP, ItIn begin, ItIn end, ItOut out) const
163  {
164  map_lfs_indices_in_ancestor(TP(),begin,end,out);
165  }
166 
167  public:
168 
170  typename Traits::ContainerIndex mapIndex(const typename Traits::DOFIndex& di) const
171  {
172  typename Traits::ContainerIndex ci;
173  mapIndex(di,ci);
174  return ci;
175  }
176 
178  void mapIndex(typename Traits::DOFIndexView di, typename Traits::ContainerIndex& ci) const
179  {
180  baseOrdering().mapIndex(di,ci);
181  }
182 
184  typename Traits::SizeType size() const
185  {
186  return baseOrdering().size();
187  }
188 
190  typename Traits::SizeType blockCount() const
191  {
192  return baseOrdering().blockCount();
193  }
194 
196  typename Traits::SizeType maxLocalSize() const
197  {
198  return targetOrdering().maxLocalSize();
199  }
200 
202  bool contains(typename Traits::SizeType codim) const
203  {
204  return targetOrdering().contains(codim);
205  }
206 
208  bool fixedSize(typename Traits::SizeType codim) const
209  {
210  return targetOrdering().fixedSize(codim);
211  }
212 
214  const BaseOrdering& baseOrdering() const
215  {
216  return *_base_ordering;
217  }
218 
221  {
222  return this->proxiedNode();
223  }
224 
225  private:
226 
227  std::shared_ptr<const BaseOrdering> _base_ordering;
228 
229  };
230 
232 
233  } // namespace PDELab
234 } // namespace Dune
235 
236 #endif // DUNE_PDELAB_ORDERING_SUBORDERING_HH
BaseOrdering_ BaseOrdering
The type of the BaseOrdering for which to represent a SubOrdering view.
Definition: subordering.hh:58
bool contains(typename Traits::SizeType codim) const
Returns whether the TargetOrdering has DOFs attached to entities of codimension codim.
Definition: subordering.hh:202
Traits::ContainerIndex mapIndex(const typename Traits::DOFIndex &di) const
Maps di from the DOFIndex subtree to the ContainerIndex in the BaseOrdering.
Definition: subordering.hh:170
static const unsigned int value
Definition: gridfunctionspace/tags.hh:139
static const bool has_dynamic_ordering_children
Forwarded ordering property from TargetOrdering, required by PDELab internals.
Definition: subordering.hh:73
bool fixedSize(typename Traits::SizeType codim) const
Returns whether the TargetOrdering is of fixed size for entities of codimension codim.
Definition: subordering.hh:208
Traits::SizeType maxLocalSize() const
Returns the maximum per-entity size of the TargetOrdering.
Definition: subordering.hh:196
BaseOrdering::ContainerAllocationTag ContainerAllocationTag
Forwarded tag from BaseOrdering, required by PDELab internals.
Definition: subordering.hh:67
BaseOrdering::CacheTag CacheTag
Forwarded tag from BaseOrdering, required by PDELab internals.
Definition: subordering.hh:70
void map_lfs_indices(ItIn begin, const ItIn end, ItOut out) const
Definition: subordering.hh:106
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:178
Traits::SizeType size() const
Returns the size of the BaseOrdering.
Definition: subordering.hh:184
void update()
Updates this SubOrdering.
Definition: subordering.hh:101
SubOrdering(std::shared_ptr< const BaseOrdering > base_ordering)
Constructs a SubOrdering for base_ordering.
Definition: subordering.hh:93
TypeTree::ChildForTreePath< BaseOrdering, typename find_ordering_treepath_for_sub_gfs< typename GFS::Ordering, GFS, TreePath >::type > TargetOrdering
The target ordering that makes up the root of this SubOrdering view.
Definition: subordering.hh:61
const TargetOrdering & targetOrdering() const
Returns the TargetOrdering.
Definition: subordering.hh:220
static const bool consume_tree_index
Forwarded ordering property from TargetOrdering, required by PDELab internals.
Definition: subordering.hh:76
For backward compatibility – Do not use this!
Definition: adaptivity.hh:27
const BaseOrdering & baseOrdering() const
Returns the BaseOrdering.
Definition: subordering.hh:214
BaseOrdering::Traits Traits
Forwarded Ordering traits from BaseOrdering.
Definition: subordering.hh:64
A view on a subtree of a multi-component ordering.
Definition: subordering.hh:49
Traits::SizeType blockCount() const
Returns the block count of the BaseOrdering.
Definition: subordering.hh:190