dune-pdelab  2.0.0
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/compositenodemacros.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 < Node::CHILDREN; ++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,
161  GFS::CHILDREN
162  > type;
163 
164  typedef 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 array<shared_ptr<TC>,GFS::CHILDREN>& 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(shared_ptr<const GFS> gfs, const Transformation& t, const array<shared_ptr<TC>,GFS::CHILDREN>& children)
176  {
177  return 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>
183  power_gfs_to_lexicographic_ordering_descriptor<GFS,Transformation>
184  register_power_gfs_to_ordering_descriptor(GFS*,Transformation*,LexicographicOrderingTag*);
185 
186  // the generic registration for PowerGridFunctionSpace happens in transformations.hh
187 
188 
190  template<typename DI, typename CI, DUNE_TYPETREE_COMPOSITENODE_TEMPLATE_CHILDREN>
192  public DUNE_TYPETREE_COMPOSITENODE_BASETYPE,
194  CI,
195  CompositeLexicographicOrdering<
196  DI,
197  CI,
198  DUNE_TYPETREE_COMPOSITENODE_CHILDTYPES
199  >
200  >
201  {
202  typedef DUNE_TYPETREE_COMPOSITENODE_BASETYPE Node;
203 
205  DI,
206  CI,
208  DI,
209  CI,
210  DUNE_TYPETREE_COMPOSITENODE_CHILDTYPES
211  >
212  > Base;
213 
214  public:
216 
224  CompositeLexicographicOrdering(bool backend_blocked, typename Base::GFSData* gfs_data, DUNE_TYPETREE_COMPOSITENODE_STORAGE_CONSTRUCTOR_SIGNATURE)
225  : Node(DUNE_TYPETREE_COMPOSITENODE_CHILDVARIABLES)
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 #if HAVE_VARIADIC_TEMPLATES
239 
240  template<typename GFS, typename Transformation>
241  struct composite_gfs_to_lexicographic_ordering_descriptor
242  {
243 
244  static const bool recursive = true;
245 
246  template<typename... TC>
247  struct result
248  {
249 
250  typedef CompositeLexicographicOrdering<
251  typename Transformation::DOFIndex,
252  typename Transformation::ContainerIndex,
253  TC...
254  > type;
255 
256  typedef shared_ptr<type> storage_type;
257 
258  };
259 
260  template<typename... TC>
261  static typename result<TC...>::type transform(const GFS& gfs, const Transformation& t, shared_ptr<TC>... children)
262  {
263  return typename result<TC...>::type(gfs.backend().blocked(gfs),const_cast<GFS*>(&gfs),children...);
264  }
265 
266  template<typename... TC>
267  static typename result<TC...>::storage_type transform_storage(shared_ptr<const GFS> gfs, const Transformation& t, shared_ptr<TC>... children)
268  {
269  return make_shared<typename result<TC...>::type>(gfs->backend().blocked(*gfs),const_cast<GFS*>(gfs.get()),children...);
270  }
271 
272  };
273 
274 #else // HAVE_VARIADIC_TEMPLATES
275 
277  template<typename GFS, typename Transformation>
279  {
280 
281  static const bool recursive = true;
282 
283  template<typename TC0,
284  typename TC1,
285  typename TC2,
286  typename TC3,
287  typename TC4,
288  typename TC5,
289  typename TC6,
290  typename TC7,
291  typename TC8,
292  typename TC9>
293  struct result
294  {
295  // TODO: FIXME - this has not been changed to new interface yet!
296  typedef CompositeLexicographicOrdering<typename Transformation::GridFunctionSpace::Traits::SizeType,
297  TC0,TC1,TC2,TC3,TC4,TC5,TC6,TC7,TC8,TC9> type;
298  typedef shared_ptr<type> storage_type;
299  };
300 
301  template<typename TC0,
302  typename TC1,
303  typename TC2,
304  typename TC3,
305  typename TC4,
306  typename TC5,
307  typename TC6,
308  typename TC7,
309  typename TC8,
310  typename TC9>
312  transform(const GFSNode& s,
313  const Transformation& t,
314  shared_ptr<TC0> c0,
315  shared_ptr<TC1> c1,
316  shared_ptr<TC2> c2,
317  shared_ptr<TC3> c3,
318  shared_ptr<TC4> c4,
319  shared_ptr<TC5> c5,
320  shared_ptr<TC6> c6,
321  shared_ptr<TC7> c7,
322  shared_ptr<TC8> c8,
323  shared_ptr<TC9> c9)
324  {
325  return typename result<TC0,TC1,TC2,TC3,TC4,TC5,TC6,TC7,TC8,TC9>::type(t.asGridFunctionSpace(s),c0,c1,c2,c3,c4,c5,c6,c7,c8,c9);
326  }
327 
328  template<typename TC0,
329  typename TC1,
330  typename TC2,
331  typename TC3,
332  typename TC4,
333  typename TC5,
334  typename TC6,
335  typename TC7,
336  typename TC8,
337  typename TC9>
338  static typename result<TC0,TC1,TC2,TC3,TC4,TC5,TC6,TC7,TC8,TC9>::storage_type
339  transform_storage(shared_ptr<const GFSNode> s,
340  const Transformation& t,
341  shared_ptr<TC0> c0,
342  shared_ptr<TC1> c1,
343  shared_ptr<TC2> c2,
344  shared_ptr<TC3> c3,
345  shared_ptr<TC4> c4,
346  shared_ptr<TC5> c5,
347  shared_ptr<TC6> c6,
348  shared_ptr<TC7> c7,
349  shared_ptr<TC8> c8,
350  shared_ptr<TC9> c9)
351  {
352  return make_shared<typename result<TC0,TC1,TC2,TC3,TC4,TC5,TC6,TC7,TC8,TC9>::type>(t.asGridFunctionSpace(s),c0,c1,c2,c3,c4,c5,c6,c7,c8,c9);
353  }
354 
355  };
356 
357 #endif // HAVE_VARIADIC_TEMPLATES
358 
359  template<typename GFS, typename Transformation>
360  composite_gfs_to_lexicographic_ordering_descriptor<GFS,Transformation>
361  register_composite_gfs_to_ordering_descriptor(GFS*,Transformation*,LexicographicOrderingTag*);
362 
364  } // namespace PDELab
365 } // namespace Dune
366 
367 #endif // DUNE_PDELAB_ORDERING_LEXICOGRAPHICORDERING_HH
LexicographicOrderingTag OrderingTag
Definition: lexicographicordering.hh:43
std::string name() const
Definition: lexicographicordering.hh:143
Node transformation descriptor for CompositeGridFunctionSpace -> LexicographicOrdering (without varia...
Definition: lexicographicordering.hh:278
DI::size_type SizeType
Definition: ordering/utility.hh:201
Definition: lexicographicordering.hh:148
void update()
Definition: lexicographicordering.hh:134
Indicate lexicographic ordering of the unknowns of non-leaf grid function spaces. ...
Definition: gridfunctionspace/tags.hh:59
composite_gfs_to_entityblocked_ordering_descriptor< GFS, Transformation > register_composite_gfs_to_ordering_descriptor(GFS *, Transformation *, EntityBlockedOrderingTag *)
void map_lfs_indices(const ItIn begin, const ItIn end, ItOut out) const
Definition: lexicographicordering.hh:59
power_gfs_to_entityblocked_ordering_descriptor< GFS, Transformation > register_power_gfs_to_ordering_descriptor(GFS *, Transformation *, EntityBlockedOrderingTag *)
Definition: orderingbase.hh:22
Traits::SizeType blockOffset(const typename Traits::SizeType child_index) const
Definition: orderingbase.hh:84
static const bool recursive
Definition: lexicographicordering.hh:281
Base(Node &node, bool container_blocked, typename BaseT::GFSData *gfs_data)
Construct ordering object.
Definition: lexicographicordering.hh:53
Definition: ordering/utility.hh:186
CompositeLexicographicOrdering(bool backend_blocked, typename Base::GFSData *gfs_data, DUNE_TYPETREE_COMPOSITENODE_STORAGE_CONSTRUCTOR_SIGNATURE)
Construct ordering object.
Definition: lexicographicordering.hh:224
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
CompositeLexicographicOrdering< typename Transformation::GridFunctionSpace::Traits::SizeType, TC0, TC1, TC2, TC3, TC4, TC5, TC6, TC7, TC8, TC9 > type
Definition: lexicographicordering.hh:297
PowerLexicographicOrdering< typename Transformation::DOFIndex, typename Transformation::ContainerIndex, TC, GFS::CHILDREN > type
Definition: lexicographicordering.hh:162
std::string name() const
Definition: lexicographicordering.hh:229
static const bool consume_tree_index
Definition: lexicographicordering.hh:45
void update()
Definition: lexicographicordering.hh:231
Definition: lexicographicordering.hh:104
static result< TC0, TC1, TC2, TC3, TC4, TC5, TC6, TC7, TC8, TC9 >::type transform(const GFSNode &s, const Transformation &t, shared_ptr< TC0 > c0, shared_ptr< TC1 > c1, shared_ptr< TC2 > c2, shared_ptr< TC3 > c3, shared_ptr< TC4 > c4, shared_ptr< TC5 > c5, shared_ptr< TC6 > c6, shared_ptr< TC7 > c7, shared_ptr< TC8 > c8, shared_ptr< TC9 > c9)
Definition: lexicographicordering.hh:312
static const bool recursive
Definition: lexicographicordering.hh:151
static result< TC >::storage_type transform_storage(shared_ptr< const GFS > gfs, const Transformation &t, const array< shared_ptr< TC >, GFS::CHILDREN > &children)
Definition: lexicographicordering.hh:175
void update()
Definition: orderingbase.hh:100
static result< TC >::type transform(const GFS &gfs, const Transformation &t, const array< shared_ptr< TC >, GFS::CHILDREN > &children)
Definition: lexicographicordering.hh:169
static result< TC0, TC1, TC2, TC3, TC4, TC5, TC6, TC7, TC8, TC9 >::storage_type transform_storage(shared_ptr< const GFSNode > s, const Transformation &t, shared_ptr< TC0 > c0, shared_ptr< TC1 > c1, shared_ptr< TC2 > c2, shared_ptr< TC3 > c3, shared_ptr< TC4 > c4, shared_ptr< TC5 > c5, shared_ptr< TC6 > c6, shared_ptr< TC7 > c7, shared_ptr< TC8 > c8, shared_ptr< TC9 > c9)
Definition: lexicographicordering.hh:339
shared_ptr< type > storage_type
Definition: lexicographicordering.hh:164
PowerLexicographicOrdering(bool container_blocked, const typename Node::NodeStorage &children, typename Base::GFSData *gfs_data)
Construct ordering object.
Definition: lexicographicordering.hh:129
OrderingBase< DI, CI >::Traits Traits
Definition: lexicographicordering.hh:41
const bool _container_blocked
Definition: orderingbase.hh:275
Dune::PDELab::impl::GridFunctionSpaceOrderingData< typename Traits::SizeType > GFSData
Definition: orderingbase.hh:35
Interface for merging index spaces.
Definition: lexicographicordering.hh:191
shared_ptr< type > storage_type
Definition: lexicographicordering.hh:298
const std::string s
Definition: function.hh:1103
Definition: lexicographicordering.hh:33