dune-pdelab  2.5-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_GRIDFUNCTIONSPACE_VECTORGRIDFUNCTIONSPACE_HH
5 #define DUNE_PDELAB_GRIDFUNCTIONSPACE_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  impl::EntitySet<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  impl::EntitySet<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  impl::EntitySet<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  impl::EntitySet<GV>,
106  Backend,
107  OrderingTag,
109 
111  VectorGridFunctionSpace,
112  impl::EntitySet<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 typename Traits::EntitySet& es,
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>(es,fem_ptr,leaf_backend,leaf_ordering_tag);
140  return r;
141  }
142 
143  public:
144 
145  VectorGridFunctionSpace(const typename Traits::GridView& 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(typename Traits::EntitySet(gv),stackobject_to_shared_ptr(fem),leaf_backend,leaf_ordering_tag))
149  , ImplementationBase(backend,ordering_tag)
150  {}
151 
152  VectorGridFunctionSpace(const typename Traits::EntitySet& es, const FEM& fem,
153  const Backend& backend = Backend(), const LeafBackend& leaf_backend = LeafBackend(),
154  const OrderingTag& ordering_tag = OrderingTag(), const LeafOrderingTag& leaf_ordering_tag = LeafOrderingTag())
155  : BaseT(create_components(es,stackobject_to_shared_ptr(fem),leaf_backend,leaf_ordering_tag))
156  , ImplementationBase(backend,ordering_tag)
157  {}
158 
159  std::string name() const
160  {
161  return ImplementationBase::name();
162  }
163 
164  void name(std::string name)
165  {
167  for (std::size_t i = 0; i < k; ++i)
168  {
169  std::stringstream ns;
170  ns << name << "_" << i;
171  this->child(i).name(ns.str());
172  }
173  }
174 
176  const Ordering &ordering() const
177  {
178  if (!this->isRootSpace())
179  {
181  "Ordering can only be obtained for root space in GridFunctionSpace tree.");
182  }
183  if (!_ordering)
184  {
185  create_ordering();
186  this->update(*_ordering);
187  }
188  return *_ordering;
189  }
190 
193  {
194  if (!this->isRootSpace())
195  {
197  "Ordering can only be obtained for root space in GridFunctionSpace tree.");
198  }
199  if (!_ordering)
200  {
201  create_ordering();
202  this->update(*_ordering);
203  }
204  return *_ordering;
205  }
206 
208  std::shared_ptr<const Ordering> orderingStorage() const
209  {
210  if (!this->isRootSpace())
211  {
213  "Ordering can only be obtained for root space in GridFunctionSpace tree.");
214  }
215  if (!_ordering)
216  {
217  create_ordering();
218  _ordering->update();
219  }
220  return _ordering;
221  }
222 
224  std::shared_ptr<Ordering> orderingStorage()
225  {
226  if (!this->isRootSpace())
227  {
229  "Ordering can only be obtained for root space in GridFunctionSpace tree.");
230  }
231  if (!_ordering)
232  {
233  create_ordering();
234  _ordering->update();
235  }
236  return _ordering;
237  }
238 
239  private:
240 
241  // This method here is to avoid a double update of the Ordering when the user calls
242  // GFS::update() before GFS::ordering().
243  void create_ordering() const
244  {
245  _ordering = std::make_shared<Ordering>(ordering_transformation::transform(*this));
246  }
247 
248  mutable std::shared_ptr<Ordering> _ordering;
249 
250  };
251 
252  } // namespace PDELab
253 } // namespace Dune
254 
255 #endif // DUNE_PDELAB_GRIDFUNCTIONSPACE_VECTORGRIDFUNCTIONSPACE_HH
VectorGridFunctionSpace(const typename Traits::GridView &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
typename EntitySet::GridView GridView
Definition: powercompositegridfunctionspacebase.hh:47
std::shared_ptr< Ordering > orderingStorage()
Direct access to the storage of the DOF ordering.
Definition: vectorgridfunctionspace.hh:224
Trait class for the multi component grid function spaces.
Definition: powercompositegridfunctionspacebase.hh:34
TypeTree::TransformTree< VectorGridFunctionSpace, gfs_to_ordering< VectorGridFunctionSpace > > ordering_transformation
Definition: vectorgridfunctionspace.hh:119
std::shared_ptr< const Ordering > orderingStorage() const
Direct access to the storage of the DOF ordering.
Definition: vectorgridfunctionspace.hh:208
For backward compatibility – Do not use this!
Definition: adaptivity.hh:27
std::string name() const
Definition: vectorgridfunctionspace.hh:159
ordering_transformation::Type Ordering
Definition: vectorgridfunctionspace.hh:123
Mixin class providing common functionality of PowerGridFunctionSpace and CompositeGridFunctionSpace.
Definition: powercompositegridfunctionspacebase.hh:68
VectorGridFunctionSpace(const typename Traits::EntitySet &es, 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:152
A grid function space.
Definition: gridfunctionspace.hh:169
Definition: datahandleprovider.hh:187
G EntitySet
Definition: powercompositegridfunctionspacebase.hh:45
VectorGridFunctionSpaceTag ImplementationTag
Definition: vectorgridfunctionspace.hh:99
Definition: gridfunctionspacebase.hh:134
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
Definition: gridfunctionspace/tags.hh:28
Ordering & ordering()
Direct access to the DOF ordering.
Definition: vectorgridfunctionspace.hh:192
const Ordering & ordering() const
Direct access to the DOF ordering.
Definition: vectorgridfunctionspace.hh:176
LeafOrderingTag< EmptyParams > DefaultLeafOrderingTag
Definition: gridfunctionspace/tags.hh:187
void name(std::string name)
Definition: vectorgridfunctionspace.hh:164
TypeTree::PowerNode< LeafGFS, k > BaseT
Definition: vectorgridfunctionspace.hh:101
PowerCompositeGridFunctionSpaceBase< VectorGridFunctionSpace, impl::EntitySet< GV >, Backend, OrderingTag, k > ImplementationBase
Definition: vectorgridfunctionspace.hh:108