dune-pdelab  2.5-dev
lexicographicordering.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_LEXICOGRAPHICORDERING_HH
5 #define DUNE_PDELAB_ORDERING_LEXICOGRAPHICORDERING_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 
23 
24 namespace Dune {
25  namespace PDELab {
26 
29 
30  namespace lexicographic_ordering {
31 
32  template<typename DI, typename CI, typename Node>
33  class Base
34  : public OrderingBase<DI,CI>
35  {
36 
37  typedef OrderingBase<DI,CI> BaseT;
38 
39  public:
40 
42 
44 
45  static const bool consume_tree_index = true;
46 
48 
53  Base(Node& node, bool container_blocked, typename BaseT::GFSData* gfs_data)
54  : BaseT(node,container_blocked,gfs_data,nullptr)
55  {
56  }
57 
58  template<typename ItIn, typename ItOut>
59  void map_lfs_indices(const ItIn begin, const ItIn end, ItOut out) const
60  {
61  if (this->_container_blocked)
62  {
63  for (ItIn in = begin; in != end; ++in, ++out)
64  out->push_back(in->treeIndex().back());
65  }
66  else
67  {
68  for (ItIn in = begin; in != end; ++in, ++out)
69  out->back() += (this->blockOffset(in->treeIndex().back()));
70  }
71  }
72 
73  template<typename CIOutIterator, typename DIOutIterator = DummyDOFIndexIterator>
74  typename Traits::SizeType
75  extract_entity_indices(const typename Traits::DOFIndex::EntityIndex& ei,
76  typename Traits::SizeType child_index,
77  CIOutIterator ci_out, const CIOutIterator ci_end) const
78  {
79  if (this->_container_blocked)
80  {
81  for (; ci_out != ci_end; ++ci_out)
82  {
83  ci_out->push_back(child_index);
84  }
85  }
86  else
87  {
88  for (; ci_out != ci_end; ++ci_out)
89  {
90  ci_out->back() += (this->blockOffset(child_index));
91  }
92  }
93 
94  // The return value is not used for non-leaf orderings.
95  return 0;
96  }
97 
98  };
99  }
100 
101 
102 
103  template<typename DI, typename CI, typename Child, std::size_t k>
105  : public TypeTree::PowerNode<Child, k>
106  , public lexicographic_ordering::Base<DI,
107  CI,
108  PowerLexicographicOrdering<DI,CI,Child,k>
109  >
110  {
111  typedef TypeTree::PowerNode<Child, k> Node;
112 
113  typedef lexicographic_ordering::Base<DI,
114  CI,
116  > Base;
117 
118  public:
119 
121 
129  PowerLexicographicOrdering(bool container_blocked, const typename Node::NodeStorage& children, typename Base::GFSData* gfs_data)
130  : Node(children)
131  , Base(*this,container_blocked,gfs_data)
132  { }
133 
134  void update()
135  {
136  for (std::size_t i = 0; i < k; ++i)
137  {
138  this->child(i).update();
139  }
140  Base::update();
141  }
142 
143  std::string name() const { return "PowerLexicographicOrdering"; }
144  };
145 
146 
147  template<typename GFS, typename Transformation>
149  {
150 
151  static const bool recursive = true;
152 
153  template<typename TC>
154  struct result
155  {
156 
158  typename Transformation::DOFIndex,
159  typename Transformation::ContainerIndex,
160  TC,
162  > type;
163 
164  typedef std::shared_ptr<type> storage_type;
165 
166  };
167 
168  template<typename TC>
169  static typename result<TC>::type transform(const GFS& gfs, const Transformation& t, const std::array<std::shared_ptr<TC>,TypeTree::StaticDegree<GFS>::value>& children)
170  {
171  return typename result<TC>::type(gfs.backend().blocked(gfs),children,const_cast<GFS*>(&gfs));
172  }
173 
174  template<typename TC>
175  static typename result<TC>::storage_type transform_storage(std::shared_ptr<const GFS> gfs, const Transformation& t, const std::array<std::shared_ptr<TC>,TypeTree::StaticDegree<GFS>::value>& children)
176  {
177  return std::make_shared<typename result<TC>::type>(gfs->backend().blocked(*gfs),children,const_cast<GFS*>(gfs.get()));
178  }
179 
180  };
181 
182  template<typename GFS, typename Transformation>
185 
186  // the generic registration for PowerGridFunctionSpace happens in transformations.hh
187 
188 
190  template<typename DI, typename CI, typename... Children>
192  public TypeTree::CompositeNode<Children...>,
194  CI,
195  CompositeLexicographicOrdering<
196  DI,
197  CI,
198  Children...
199  >
200  >
201  {
202  typedef TypeTree::CompositeNode<Children...> Node;
203 
205  DI,
206  CI,
208  DI,
209  CI,
210  Children...
211  >
212  > Base;
213 
214  public:
216 
224  CompositeLexicographicOrdering(bool backend_blocked, typename Base::GFSData* gfs_data, std::shared_ptr<Children>... children)
225  : Node(children...)
226  , Base(*this,backend_blocked,gfs_data)
227  { }
228 
229  std::string name() const { return "CompositeLexicographicOrdering"; }
230 
231  void update()
232  {
233  TypeTree::applyToTree(*this,ordering::update_direct_children());
234  Base::update();
235  }
236  };
237 
238  template<typename GFS, typename Transformation>
240  {
241 
242  static const bool recursive = true;
243 
244  template<typename... TC>
245  struct result
246  {
247 
249  typename Transformation::DOFIndex,
250  typename Transformation::ContainerIndex,
251  TC...
252  > type;
253 
254  typedef std::shared_ptr<type> storage_type;
255 
256  };
257 
258  template<typename... TC>
259  static typename result<TC...>::type transform(const GFS& gfs, const Transformation& t, std::shared_ptr<TC>... children)
260  {
261  return typename result<TC...>::type(gfs.backend().blocked(gfs),const_cast<GFS*>(&gfs),children...);
262  }
263 
264  template<typename... TC>
265  static typename result<TC...>::storage_type transform_storage(std::shared_ptr<const GFS> gfs, const Transformation& t, std::shared_ptr<TC>... children)
266  {
267  return std::make_shared<typename result<TC...>::type>(gfs->backend().blocked(*gfs),const_cast<GFS*>(gfs.get()),children...);
268  }
269 
270  };
271 
272 
273  template<typename GFS, typename Transformation>
276 
278  } // namespace PDELab
279 } // namespace Dune
280 
281 #endif // DUNE_PDELAB_ORDERING_LEXICOGRAPHICORDERING_HH
PowerLexicographicOrdering< typename Transformation::DOFIndex, typename Transformation::ContainerIndex, TC, TypeTree::StaticDegree< GFS >::value > type
Definition: lexicographicordering.hh:162
void update()
Definition: lexicographicordering.hh:231
static const unsigned int value
Definition: gridfunctionspace/tags.hh:139
Interface for merging index spaces.
Definition: lexicographicordering.hh:191
Definition: lexicographicordering.hh:104
std::shared_ptr< type > storage_type
Definition: lexicographicordering.hh:254
OrderingBase< DI, CI >::Traits Traits
Definition: lexicographicordering.hh:41
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
Definition: orderingbase.hh:20
std::string name() const
Definition: lexicographicordering.hh:229
CompositeLexicographicOrdering< typename Transformation::DOFIndex, typename Transformation::ContainerIndex, TC... > type
Definition: lexicographicordering.hh:252
void update()
Definition: orderingbase.hh:97
static result< TC... >::storage_type transform_storage(std::shared_ptr< const GFS > gfs, const Transformation &t, std::shared_ptr< TC >... children)
Definition: lexicographicordering.hh:265
std::shared_ptr< type > storage_type
Definition: lexicographicordering.hh:164
const bool _container_blocked
Definition: orderingbase.hh:270
power_gfs_to_entityblocked_ordering_descriptor< GFS, Transformation > register_power_gfs_to_ordering_descriptor(GFS *, Transformation *, EntityBlockedOrderingTag *)
CompositeLexicographicOrdering(bool backend_blocked, typename Base::GFSData *gfs_data, std::shared_ptr< Children >... children)
Construct ordering object.
Definition: lexicographicordering.hh:224
PowerLexicographicOrdering(bool container_blocked, const typename Node::NodeStorage &children, typename Base::GFSData *gfs_data)
Construct ordering object.
Definition: lexicographicordering.hh:129
Definition: ordering/utility.hh:186
DI::size_type SizeType
Definition: ordering/utility.hh:201
Traits::SizeType blockOffset(const typename Traits::SizeType child_index) const
Definition: orderingbase.hh:81
LexicographicOrderingTag OrderingTag
Definition: lexicographicordering.hh:43
Base(Node &node, bool container_blocked, typename BaseT::GFSData *gfs_data)
Construct ordering object.
Definition: lexicographicordering.hh:53
For backward compatibility – Do not use this!
Definition: adaptivity.hh:27
Definition: lexicographicordering.hh:33
composite_gfs_to_entityblocked_ordering_descriptor< GFS, Transformation > register_composite_gfs_to_ordering_descriptor(GFS *, Transformation *, EntityBlockedOrderingTag *)
void update()
Definition: lexicographicordering.hh:134
static result< TC >::storage_type transform_storage(std::shared_ptr< const GFS > gfs, const Transformation &t, const std::array< std::shared_ptr< TC >, TypeTree::StaticDegree< GFS >::value > &children)
Definition: lexicographicordering.hh:175
static const bool consume_tree_index
Definition: lexicographicordering.hh:45
static result< TC >::type transform(const GFS &gfs, const Transformation &t, const std::array< std::shared_ptr< TC >, TypeTree::StaticDegree< GFS >::value > &children)
Definition: lexicographicordering.hh:169
std::string name() const
Definition: lexicographicordering.hh:143
void map_lfs_indices(const ItIn begin, const ItIn end, ItOut out) const
Definition: lexicographicordering.hh:59
Dune::PDELab::impl::GridFunctionSpaceOrderingData< typename Traits::SizeType > GFSData
Definition: orderingbase.hh:32
static result< TC... >::type transform(const GFS &gfs, const Transformation &t, std::shared_ptr< TC >... children)
Definition: lexicographicordering.hh:259
Indicate lexicographic ordering of the unknowns of non-leaf grid function spaces. ...
Definition: gridfunctionspace/tags.hh:63
Definition: lexicographicordering.hh:148