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