dune-pdelab  2.4-dev
vectorgridfunctionspace.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_VECTORGRIDFUNCTIONSPACE_HH
5 #define DUNE_PDELAB_VECTORGRIDFUNCTIONSPACE_HH
6 
7 #include <algorithm>
8 #include <cstddef>
9 
10 #include <dune/common/shared_ptr.hh>
11 
12 #include <dune/typetree/powernode.hh>
13 
18 
19 namespace Dune {
20  namespace PDELab {
21 
22  //=======================================
23  // power grid function space
24  //=======================================
25 
40  template<typename GV,
41  typename FEM,
42  std::size_t k,
43  typename Backend,
44  typename LeafBackend,
45  typename Constraints = NoConstraints,
46  typename OrderingTag = LexicographicOrderingTag,
47  typename LeafOrderingTag = DefaultLeafOrderingTag>
49  : public TypeTree::PowerNode<GridFunctionSpace<
50  GV,
51  FEM,
52  Constraints,
53  LeafBackend,
54  LeafOrderingTag
55  >,
56  k>
57  , public PowerCompositeGridFunctionSpaceBase<VectorGridFunctionSpace<
58  GV,
59  FEM,
60  k,
61  Backend,
62  LeafBackend,
63  Constraints,
64  OrderingTag,
65  LeafOrderingTag
66  >,
67  GV,
68  Backend,
69  OrderingTag,
70  k>
71 
72  , public DataHandleProvider<VectorGridFunctionSpace<
73  GV,
74  FEM,
75  k,
76  Backend,
77  LeafBackend,
78  Constraints,
79  OrderingTag,
80  LeafOrderingTag
81  > >
82 
84  {
85 
86  typedef GridFunctionSpace<
87  GV,
88  FEM,
89  Constraints,
90  LeafBackend,
91  LeafOrderingTag
92  > LeafGFS;
93 
94  template<typename,typename>
95  friend class GridFunctionSpaceBase;
96 
97  public:
98 
100 
101  typedef TypeTree::PowerNode<LeafGFS,k> BaseT;
102 
105  GV,
106  Backend,
107  OrderingTag,
109 
111  VectorGridFunctionSpace,
112  GV,
113  Backend,
114  OrderingTag,
115  k>;
116 
117  typedef TypeTree::TransformTree<VectorGridFunctionSpace,
118  gfs_to_ordering<VectorGridFunctionSpace>
120 
121  public:
122 
123  typedef typename ordering_transformation::Type Ordering;
124 
127 
128  private:
129 
130  // Preconstruct children - it is important that the children are set before entering the constructor
131  // of ImplementationBase!
132  static typename BaseT::NodeStorage create_components(const GV& gv,
133  std::shared_ptr<const FEM> fem_ptr,
134  const LeafBackend& leaf_backend,
135  const LeafOrderingTag& leaf_ordering_tag)
136  {
137  typename BaseT::NodeStorage r;
138  for (std::size_t i = 0; i < k; ++i)
139  r[i] = std::make_shared<LeafGFS>(gv,fem_ptr,leaf_backend,leaf_ordering_tag);
140  return r;
141  }
142 
143  public:
144 
145  VectorGridFunctionSpace(const GV& gv, const FEM& fem,
146  const Backend& backend = Backend(), const LeafBackend& leaf_backend = LeafBackend(),
147  const OrderingTag& ordering_tag = OrderingTag(), const LeafOrderingTag& leaf_ordering_tag = LeafOrderingTag())
148  : BaseT(create_components(gv,stackobject_to_shared_ptr(fem),leaf_backend,leaf_ordering_tag))
149  , ImplementationBase(backend,ordering_tag)
150  {}
151 
152  std::string name() const
153  {
154  return ImplementationBase::name();
155  }
156 
157  void name(std::string name)
158  {
160  for (std::size_t i = 0; i < k; ++i)
161  {
162  std::stringstream ns;
163  ns << name << "_" << i;
164  this->child(i).name(ns.str());
165  }
166  }
167 
169  const Ordering &ordering() const
170  {
171  if (!this->isRootSpace())
172  {
174  "Ordering can only be obtained for root space in GridFunctionSpace tree.");
175  }
176  if (!_ordering)
177  {
178  create_ordering();
179  this->update(*_ordering);
180  }
181  return *_ordering;
182  }
183 
185  Ordering &ordering()
186  {
187  if (!this->isRootSpace())
188  {
190  "Ordering can only be obtained for root space in GridFunctionSpace tree.");
191  }
192  if (!_ordering)
193  {
194  create_ordering();
195  this->update(*_ordering);
196  }
197  return *_ordering;
198  }
199 
201  std::shared_ptr<const Ordering> orderingStorage() const
202  {
203  if (!this->isRootSpace())
204  {
206  "Ordering can only be obtained for root space in GridFunctionSpace tree.");
207  }
208  if (!_ordering)
209  {
210  create_ordering();
211  _ordering->update();
212  }
213  return _ordering;
214  }
215 
217  std::shared_ptr<Ordering> orderingStorage()
218  {
219  if (!this->isRootSpace())
220  {
222  "Ordering can only be obtained for root space in GridFunctionSpace tree.");
223  }
224  if (!_ordering)
225  {
226  create_ordering();
227  _ordering->update();
228  }
229  return _ordering;
230  }
231 
232  private:
233 
234  // This method here is to avoid a double update of the Ordering when the user calls
235  // GFS::update() before GFS::ordering().
236  void create_ordering() const
237  {
238  _ordering = std::make_shared<Ordering>(ordering_transformation::transform(*this));
239  }
240 
241  mutable std::shared_ptr<Ordering> _ordering;
242 
243  };
244 
245  } // namespace PDELab
246 } // namespace Dune
247 
248 #endif // DUNE_PDELAB_VECTORGRIDFUNCTIONSPACE_HH
Definition: gridfunctionspacebase.hh:137
Definition: gridfunctionspace/tags.hh:28
Mixin class providing common functionality of PowerGridFunctionSpace and CompositeGridFunctionSpace.
Definition: powercompositegridfunctionspacebase.hh:66
Ordering & ordering()
Direct access to the DOF ordering.
Definition: vectorgridfunctionspace.hh:185
VectorGridFunctionSpace(const GV &gv, const FEM &fem, const Backend &backend=Backend(), const LeafBackend &leaf_backend=LeafBackend(), const OrderingTag &ordering_tag=OrderingTag(), const LeafOrderingTag &leaf_ordering_tag=LeafOrderingTag())
Definition: vectorgridfunctionspace.hh:145
Trait class for the multi component grid function spaces.
Definition: powercompositegridfunctionspacebase.hh:34
ImplementationBase::Traits Traits
export traits class
Definition: vectorgridfunctionspace.hh:126
std::shared_ptr< const Ordering > orderingStorage() const
Direct access to the storage of the DOF ordering.
Definition: vectorgridfunctionspace.hh:201
Mixin base class for specifying output hints to I/O routines like VTK.
Definition: function.hh:123
base class for tuples of grid function spaces product of identical grid function spaces base class th...
Definition: vectorgridfunctionspace.hh:48
LeafOrderingTag< DefaultLeafOrderingParams > DefaultLeafOrderingTag
Default ordering tag for a MultiIndex-based ordering with standard behavior.
Definition: gridfunctionspace/tags.hh:252
ordering_transformation::Type Ordering
Definition: vectorgridfunctionspace.hh:123
PowerCompositeGridFunctionSpaceBase< VectorGridFunctionSpace, GV, Backend, OrderingTag, k > ImplementationBase
Definition: vectorgridfunctionspace.hh:108
Definition: adaptivity.hh:27
const Ordering & ordering() const
Direct access to the DOF ordering.
Definition: vectorgridfunctionspace.hh:169
Definition: datahandleprovider.hh:188
TypeTree::TransformTree< VectorGridFunctionSpace, gfs_to_ordering< VectorGridFunctionSpace > > ordering_transformation
Definition: vectorgridfunctionspace.hh:119
VectorGridFunctionSpaceTag ImplementationTag
Definition: vectorgridfunctionspace.hh:99
void name(std::string name)
Definition: vectorgridfunctionspace.hh:157
A grid function space.
Definition: gridfunctionspace.hh:108
std::shared_ptr< Ordering > orderingStorage()
Direct access to the storage of the DOF ordering.
Definition: vectorgridfunctionspace.hh:217
TypeTree::PowerNode< LeafGFS, k > BaseT
Definition: vectorgridfunctionspace.hh:101
std::string name() const
Definition: vectorgridfunctionspace.hh:152