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