dune-pdelab  2.5-dev
compositegridfunctionspace.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_GRIDFUNCTIONSPACE_COMPOSITEGRIDFUNCTIONSPACE_HH
5 #define DUNE_PDELAB_GRIDFUNCTIONSPACE_COMPOSITEGRIDFUNCTIONSPACE_HH
6 
7 #include <memory>
8 
9 #include <dune/typetree/compositenode.hh>
10 #include <dune/typetree/utility.hh>
11 
16 
17 namespace Dune {
18  namespace PDELab {
19 
20  //=======================================
21  // composite grid function space
22  //=======================================
23 
27 
38  template<typename Backend,
39  typename OrderingTag,
40  typename... Children>
42  : public TypeTree::CompositeNode<Children...>
44  CompositeGridFunctionSpace<
45  Backend,
46  OrderingTag,
47  Children...>,
48  typename TypeTree::Child<TypeTree::CompositeNode<Children...>,0>::Traits::EntitySet,
49  Backend,
50  OrderingTag,
51  sizeof...(Children)
52  >
53  , public DataHandleProvider<CompositeGridFunctionSpace<Backend,OrderingTag,Children...> >
54  {
55  typedef TypeTree::CompositeNode<Children...> NodeT;
56 
59  typename TypeTree::Child<NodeT,0>::Traits::EntitySet,
60  Backend,
62  sizeof...(Children)> ImplementationBase;
63 
65  CompositeGridFunctionSpace,
66  typename TypeTree::Child<NodeT,0>::Traits::EntitySet,
67  Backend,
68  OrderingTag,
69  sizeof...(Children)>;
70 
71  typedef TypeTree::TransformTree<CompositeGridFunctionSpace,
72  gfs_to_ordering<CompositeGridFunctionSpace>
73  > ordering_transformation;
74 
75  template<typename,typename>
76  friend class GridFunctionSpaceBase;
77 
78  public:
80 
81  typedef typename ordering_transformation::Type Ordering;
82 
84 
85  // ********************************************************************************
86  // constructors for stack-constructed children passed in by reference
87  // ********************************************************************************
88 
89  CompositeGridFunctionSpace(const Backend& backend, Children&... children)
90  : NodeT(TypeTree::assertGridViewType<typename NodeT::template Child<0>::Type>(children)...)
91  , ImplementationBase(backend,OrderingTag())
92  { }
93 
94  CompositeGridFunctionSpace(const OrderingTag& ordering_tag, Children&... children)
95  : NodeT(TypeTree::assertGridViewType<typename NodeT::template Child<0>::Type>(children)...)
96  , ImplementationBase(Backend(),ordering_tag)
97  { }
98 
99  CompositeGridFunctionSpace(const Backend& backend, const OrderingTag& ordering_tag, Children&... children)
100  : NodeT(TypeTree::assertGridViewType<typename NodeT::template Child<0>::Type>(children)...)
101  , ImplementationBase(backend,ordering_tag)
102  { }
103 
104  CompositeGridFunctionSpace(Children&... children)
105  : NodeT(TypeTree::assertGridViewType<typename NodeT::template Child<0>::Type>(children)...)
106  , ImplementationBase(Backend(),OrderingTag())
107  { }
108 
109  // ********************************************************************************
110  // constructors for heap-constructed children passed in as shared_ptrs
111  // ********************************************************************************
112 
113  CompositeGridFunctionSpace(const Backend& backend, std::shared_ptr<Children>... children)
114  : NodeT(children...)
115  , ImplementationBase(backend,OrderingTag())
116  { }
117 
118  CompositeGridFunctionSpace(const OrderingTag& ordering_tag, std::shared_ptr<Children>... children)
119  : NodeT(children...)
120  , ImplementationBase(Backend(),ordering_tag)
121  { }
122 
123  CompositeGridFunctionSpace(const Backend& backend, const OrderingTag& ordering_tag, std::shared_ptr<Children>... children)
124  : NodeT(children...)
125  , ImplementationBase(backend,ordering_tag)
126  { }
127 
128  CompositeGridFunctionSpace(std::shared_ptr<Children>... children)
129  : NodeT(children...)
130  , ImplementationBase(Backend(),OrderingTag())
131  { }
132 
133 
135  const Ordering &ordering() const
136  {
137  if (!this->isRootSpace())
138  {
140  "Ordering can only be obtained for root space in GridFunctionSpace tree.");
141  }
142  if (!_ordering)
143  {
144  create_ordering();
145  this->update(*_ordering);
146  }
147  return *_ordering;
148  }
149 
152  {
153  if (!this->isRootSpace())
154  {
156  "Ordering can only be obtained for root space in GridFunctionSpace tree.");
157  }
158  if (!_ordering)
159  {
160  create_ordering();
161  this->update(*_ordering);
162  }
163  return *_ordering;
164  }
165 
167  std::shared_ptr<const Ordering> orderingStorage() const
168  {
169  if (!this->isRootSpace())
170  {
172  "Ordering can only be obtained for root space in GridFunctionSpace tree.");
173  }
174  if (!_ordering)
175  {
176  create_ordering();
177  this->update(*_ordering);
178  }
179  return _ordering;
180  }
181 
183  std::shared_ptr<Ordering> orderingStorage()
184  {
185  if (!this->isRootSpace())
186  {
188  "Ordering can only be obtained for root space in GridFunctionSpace tree.");
189  }
190  if (!_ordering)
191  {
192  create_ordering();
193  this->update(*_ordering);
194  }
195  return _ordering;
196  }
197 
198 
199  private:
200 
201  // This method here is to avoid a double update of the Ordering when the user calls
202  // GFS::update() before GFS::ordering().
203  void create_ordering() const
204  {
206  TypeTree::applyToTree(*this,visitor);
207  _ordering = std::make_shared<Ordering>(ordering_transformation::transform(*this));
208  }
209 
210  mutable std::shared_ptr<Ordering> _ordering;
211 
212  };
213 
215 
216  } // namespace PDELab
217 } // namespace Dune
218 
219 #endif // DUNE_PDELAB_GRIDFUNCTIONSPACE_COMPOSITEGRIDFUNCTIONSPACE_HH
Mixin class providing common functionality of PowerGridFunctionSpace and CompositeGridFunctionSpace.
Definition: powercompositegridfunctionspacebase.hh:68
base class for tuples of grid function spaces base class that holds implementation of the methods thi...
Definition: compositegridfunctionspace.hh:41
G EntitySet
Definition: powercompositegridfunctionspacebase.hh:45
CompositeGridFunctionSpace(const Backend &backend, const OrderingTag &ordering_tag, std::shared_ptr< Children >... children)
Definition: compositegridfunctionspace.hh:123
std::shared_ptr< const Ordering > orderingStorage() const
Direct access to the storage of the DOF ordering.
Definition: compositegridfunctionspace.hh:167
std::shared_ptr< Ordering > orderingStorage()
Direct access to the storage of the DOF ordering.
Definition: compositegridfunctionspace.hh:183
Definition: gridfunctionspaceutilities.hh:23
CompositeGridFunctionSpace(const OrderingTag &ordering_tag, Children &... children)
Definition: compositegridfunctionspace.hh:94
Definition: datahandleprovider.hh:187
const Ordering & ordering() const
Direct access to the DOF ordering.
Definition: compositegridfunctionspace.hh:135
CompositeGridFunctionSpace(const Backend &backend, const OrderingTag &ordering_tag, Children &... children)
Definition: compositegridfunctionspace.hh:99
CompositeGridFunctionSpace(const OrderingTag &ordering_tag, std::shared_ptr< Children >... children)
Definition: compositegridfunctionspace.hh:118
CompositeGridFunctionSpace(const Backend &backend, std::shared_ptr< Children >... children)
Definition: compositegridfunctionspace.hh:113
Trait class for the multi component grid function spaces.
Definition: powercompositegridfunctionspacebase.hh:34
CompositeGridFunctionSpace(Children &... children)
Definition: compositegridfunctionspace.hh:104
For backward compatibility – Do not use this!
Definition: adaptivity.hh:27
Definition: gridfunctionspacebase.hh:134
ordering_transformation::Type Ordering
Definition: compositegridfunctionspace.hh:81
Definition: gridfunctionspace/tags.hh:30
CompositeGridFunctionSpace(const Backend &backend, Children &... children)
Definition: compositegridfunctionspace.hh:89
Ordering & ordering()
Direct access to the DOF ordering.
Definition: compositegridfunctionspace.hh:151
CompositeGridFunctionSpace(std::shared_ptr< Children >... children)
Definition: compositegridfunctionspace.hh:128