dune-pdelab  2.4-dev
permutationordering.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_PERMUTATIONORDERING_HH
5 #define DUNE_PDELAB_ORDERING_PERMUTATIONORDERING_HH
6 
7 #include <cstddef>
8 #include <ostream>
9 #include <string>
10 
11 #include <dune/common/classname.hh>
12 #include <dune/common/exceptions.hh>
13 #include <dune/common/stdstreams.hh>
14 
15 #include <dune/typetree/compositenode.hh>
16 #include <dune/typetree/powernode.hh>
17 #include <dune/typetree/traversal.hh>
18 #include <dune/typetree/visitor.hh>
19 
24 
25 namespace Dune {
26  namespace PDELab {
27 
30 
31  namespace permutation_ordering {
32 
34  template<typename DI, typename CI, typename Node>
35  class Base
36  : public lexicographic_ordering::Base<DI,CI,Node>,
37  public VirtualOrderingBase<DI,CI>
38  {
39 
40  public:
41 
44  typedef typename BaseT::Traits Traits;
45 
47 
48  static const bool consume_tree_index = true;
49 
51 
56  Base(Node& node, bool container_blocked, const OrderingTag& ordering_tag)
57  : BaseT(node,container_blocked),
58  _perm(ordering_tag.permutation())
59  {
60  // Make sure to use 'this' as a delegate in OrderingBase, so the virtual function call
61  // to 'map_index_dynamic' is found!
62  this->setDelegate(this);
63  }
64 
66  Base(const This& other)
67  : BaseT(other),
68  _perm(other._perm)
69  {
70  // Make sure to use 'this' as a delegate in OrderingBase, so the virtual function call
71  // to 'map_index_dynamic' is found!
72  this->setDelegate(this);
73  }
74 
75  Base(This&& other)
76  : BaseT(std::move(other)),
77  _perm(std::move(other._perm))
78  {
79  // Make sure to use 'this' as a delegate in OrderingBase, so the virtual function call
80  // to 'map_index_dynamic' is found!
81  this->setDelegate(this);
82  }
83 
84  template<typename ItIn, typename ItOut>
85  void map_lfs_indices(const ItIn begin, const ItIn end, ItOut out) const
86  {
87  BaseT::map_lfs_indices(begin,end,out);
88 
89  // Permute indices
90  for (ItIn in = begin; in != end; ++in, ++out)
91  out->back() = _perm[out->back()];
92  }
93 
94  template<typename CIOutIterator, typename DIOutIterator = DummyDOFIndexIterator>
95  typename Traits::SizeType
96  extract_entity_indices(const typename Traits::DOFIndex::EntityIndex& ei,
97  typename Traits::SizeType child_index,
98  CIOutIterator ci_out, const CIOutIterator ci_end) const
99  {
100  BaseT::extract_entity_indices(ei,child_index,ci_out,ci_end);
101 
102  // Permute indices
103  for (; ci_out != ci_end; ++ci_out)
104  {
105  ci_out->back() = _perm[ci_out->back()];
106  }
107 
108  // The return value is not used for non-leaf orderings.
109  return 0;
110  }
111 
112  virtual void map_index_dynamic(typename Traits::DOFIndexView di, typename Traits::ContainerIndex& ci) const
113  {
114  this->_mapIndex(di,ci);
115 
116  // Permute index
117  ci.back() = _perm[ci.back()];
118  }
119 
120  private:
121  const std::vector<std::size_t>& _perm;
122 
123  };
124  }
125 
127  template<typename DI, typename CI, typename Child, std::size_t k>
129  : public TypeTree::PowerNode<Child, k>
130  , public permutation_ordering::Base<DI,
131  CI,
132  PowerLexicographicOrdering<DI,CI,Child,k>
133  >
134  {
135  typedef TypeTree::PowerNode<Child, k> Node;
136 
137  typedef permutation_ordering::Base<DI,
138  CI,
140  > Base;
141 
142  public:
143 
145 
153  PowerPermutationOrdering(bool container_blocked, const PermutationOrderingTag& ordering_tag, const typename Node::NodeStorage& children)
154  : Node(children)
155  , Base(*this,container_blocked,ordering_tag)
156  { }
157 
158  void update()
159  {
160  for (std::size_t i = 0; i < Node::CHILDREN; ++i)
161  {
162  this->child(i).update();
163  }
164  Base::update();
165  }
166 
167  std::string name() const { return "PowerPermutationOrdering"; }
168  };
169 
170 
171  template<typename GFS, typename Transformation>
172  struct power_gfs_to_ordering_descriptor<GFS,Transformation,PermutationOrderingTag>
173  {
174 
175  static const bool recursive = true;
176 
177  template<typename TC>
178  struct result
179  {
180 
181  typedef PowerPermutationOrdering<
182  typename Transformation::DOFIndex,
183  typename Transformation::ContainerIndex,
184  TC,
185  GFS::CHILDREN
186  > type;
187 
188  typedef std::shared_ptr<type> storage_type;
189 
190  };
191 
192  template<typename TC>
193  static typename result<TC>::type transform(const GFS& gfs, const Transformation& t, const array<std::shared_ptr<TC>,GFS::CHILDREN>& children)
194  {
195  return typename result<TC>::type(gfs.backend().blocked(gfs),gfs->orderingTag(),children);
196  }
197 
198  template<typename TC>
199  static typename result<TC>::storage_type transform_storage(std::shared_ptr<const GFS> gfs, const Transformation& t, const array<std::shared_ptr<TC>,GFS::CHILDREN>& children)
200  {
201  return std::make_shared<typename result<TC>::type>(gfs->backend().blocked(*gfs),gfs->orderingTag(),children);
202  }
203 
204  };
205 
206  // the generic registration for PowerGridFunctionSpace happens in transformations.hh
207 
208 
210  template<typename DI, typename CI, typename... Children>
212  public TypeTree::CompositeNode<Children...>,
213  public permutation_ordering::Base<DI,
214  CI,
215  CompositePermutationOrdering<
216  DI,
217  CI,
218  Children...
219  >
220  >
221  {
222  typedef TypeTree::CompositeNode<Children...> Node;
223 
225  DI,
226  CI,
228  DI,
229  CI,
230  Children...
231  >
232  > Base;
233 
234  public:
236 
244  CompositePermutationOrdering(bool backend_blocked, const PermutationOrderingTag& ordering_tag,
245  std::shared_ptr<Children>... children)
246  : Node(children...)
247  , Base(*this,backend_blocked,ordering_tag)
248  { }
249 
250  std::string name() const { return "CompositePermutationOrdering"; }
251 
252  void update()
253  {
254  TypeTree::applyToTree(*this,ordering::update_direct_children());
255  Base::update();
256  }
257  };
258 
259  template<typename GFS, typename Transformation>
260  struct composite_gfs_to_ordering_descriptor<GFS,Transformation,PermutationOrderingTag>
261  {
262 
263  static const bool recursive = true;
264 
265  template<typename... TC>
266  struct result
267  {
268 
270  typename Transformation::DOFIndex,
271  typename Transformation::ContainerIndex,
272  TC...
273  > type;
274 
275  typedef std::shared_ptr<type> storage_type;
276 
277  };
278 
279  template<typename... TC>
280  static typename result<TC...>::type transform(const GFS& gfs, const Transformation& t, std::shared_ptr<TC>... children)
281  {
282  return typename result<TC...>::type(gfs.backend().blocked(gfs),gfs.orderingTag(),children...);
283  }
284 
285  template<typename... TC>
286  static typename result<TC...>::storage_type transform_storage(std::shared_ptr<const GFS> gfs, const Transformation& t, std::shared_ptr<TC>... children)
287  {
288  return std::make_shared<typename result<TC...>::type>(gfs->backend().blocked(*gfs),gfs.orderingTag(),children...);
289  }
290 
291  };
292 
293  // the generic registration for PowerGridFunctionSpace happens in transformations.hh
294 
296  } // namespace PDELab
297 } // namespace Dune
298 
299 #endif // DUNE_PDELAB_ORDERING_PERMUTATIONORDERING_HH
void _mapIndex(typename Traits::DOFIndexView di, typename Traits::ContainerIndex &ci) const
Definition: orderingbase.hh:233
Definition: lexicographicordering.hh:104
PowerPermutationOrdering(bool container_blocked, const PermutationOrderingTag &ordering_tag, const typename Node::NodeStorage &children)
Construct ordering object.
Definition: permutationordering.hh:153
virtual void map_index_dynamic(typename Traits::DOFIndexView di, typename Traits::ContainerIndex &ci) const
Definition: permutationordering.hh:112
DI::size_type SizeType
Definition: ordering/utility.hh:201
PowerPermutationOrdering< typename Transformation::DOFIndex, typename Transformation::ContainerIndex, TC, GFS::CHILDREN > type
Definition: permutationordering.hh:186
Interface for merging index spaces.
Definition: permutationordering.hh:128
PermutationOrderingTag OrderingTag
Definition: permutationordering.hh:46
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: lexicographicordering.hh:75
STL namespace.
Base(const This &other)
Copy constructor.
Definition: permutationordering.hh:66
CI ContainerIndex
Definition: ordering/utility.hh:160
CompositePermutationOrdering< typename Transformation::DOFIndex, typename Transformation::ContainerIndex, TC... > type
Definition: permutationordering.hh:273
std::string name() const
Definition: permutationordering.hh:167
void map_lfs_indices(const ItIn begin, const ItIn end, ItOut out) const
Definition: lexicographicordering.hh:59
static result< TC...>::storage_type transform_storage(std::shared_ptr< const GFS > gfs, const Transformation &t, std::shared_ptr< TC >...children)
Definition: permutationordering.hh:286
BaseT::Traits Traits
Definition: permutationordering.hh:44
void map_lfs_indices(const ItIn begin, const ItIn end, ItOut out) const
Definition: permutationordering.hh:85
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: permutationordering.hh:96
DI::View DOFIndexView
Definition: ordering/utility.hh:198
Definition: lexicographicordering.hh:33
static const bool consume_tree_index
Definition: permutationordering.hh:48
Definition: adaptivity.hh:27
void update()
Definition: permutationordering.hh:252
Base(Node &node, bool container_blocked, const OrderingTag &ordering_tag)
Construct ordering object.
Definition: permutationordering.hh:56
std::string name() const
Definition: permutationordering.hh:250
CompositePermutationOrdering(bool backend_blocked, const PermutationOrderingTag &ordering_tag, std::shared_ptr< Children >...children)
Construct ordering object.
Definition: permutationordering.hh:244
void setDelegate(const VirtualOrderingBase< DI, CI > *delegate)
Set the delegate called in mapIndex().
Definition: orderingbase.hh:228
lexicographic_ordering::Base< DI, CI, Node > BaseT
Definition: permutationordering.hh:43
Interface for merging index spaces.
Definition: permutationordering.hh:35
void update()
Definition: permutationordering.hh:158
Definition: ordering/utility.hh:230
Base(This &&other)
Definition: permutationordering.hh:75
Definition: ordering/utility.hh:186
Interface for merging index spaces.
Definition: permutationordering.hh:211
Indicate permuted ordering of the unknowns of non-leaf grid function spaces according to a given perm...
Definition: gridfunctionspace/tags.hh:134
void update()
Definition: orderingbase.hh:99
static result< TC >::type transform(const GFS &gfs, const Transformation &t, const array< std::shared_ptr< TC >, GFS::CHILDREN > &children)
Definition: permutationordering.hh:193
Base< DI, CI, Node > This
Definition: permutationordering.hh:42
static result< TC...>::type transform(const GFS &gfs, const Transformation &t, std::shared_ptr< TC >...children)
Definition: permutationordering.hh:280
static result< TC >::storage_type transform_storage(std::shared_ptr< const GFS > gfs, const Transformation &t, const array< std::shared_ptr< TC >, GFS::CHILDREN > &children)
Definition: permutationordering.hh:199