dune-pdelab  2.7-git
gridfunctionspace.hh
Go to the documentation of this file.
1 // -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 // vi: set et ts=4 sw=2 sts=2:
3 #ifndef DUNE_PDELAB_GRIDFUNCTIONSPACE_GRIDFUNCTIONSPACE_HH
4 #define DUNE_PDELAB_GRIDFUNCTIONSPACE_GRIDFUNCTIONSPACE_HH
5 
6 #include <cstddef>
7 #include <map>
8 #include <ostream>
9 #include <set>
10 #include <vector>
11 #include <memory>
12 
13 #include <dune/common/deprecated.hh>
14 #include <dune/common/exceptions.hh>
15 #include <dune/common/stdstreams.hh>
16 #include <dune/common/typetraits.hh>
17 #include <dune/common/shared_ptr.hh>
18 
19 #include <dune/geometry/referenceelements.hh>
20 #include <dune/geometry/type.hh>
21 
22 #include <dune/localfunctions/common/interfaceswitch.hh>
23 #include <dune/localfunctions/common/localkey.hh>
24 
25 #include <dune/common/version.hh>
26 #include <dune/typetree/typetree.hh>
27 
28 // This alias should be removed after a PDELab 2.7 release.
29 #if DUNE_VERSION_LT_REV(DUNE_TYPETREE,2,7,1)
30 namespace Dune {
31  namespace TypeTree {
32  template<std::size_t... i>
33  using StaticTreePath = TreePath<i...>;
34  }
35 }
36 #endif
37 
40 
41 // we just want the descriptors here, so we temporarily switch off the warning for
42 // directly including ISTL backend headers
43 #define _DUNE_PDELAB_SUPPRESS_ISTL_HH_WARNING
45 #undef _DUNE_PDELAB_SUPPRESS_ISTL_HH_WARNING
46 
56 
57 namespace Dune {
58  namespace PDELab {
59 
63 
64 #ifndef DOXYGEN
65 
66  namespace impl {
67 
68  // Helper structs to avoid compilation failures in the
69  // backwards compatibility mode where users stuff a
70  // GridView into a GridFunctionSpace.
71  // In that case, we cannot extract the GridView type from
72  // the GridView itself, so we use a std::conditional in the
73  // Traits class to pick either one of the following structs
74  // and then use the correct class to do the lookup.
75 
76  struct _lazy_identity
77  {
78  template<typename T>
79  struct evaluate
80  {
81  using type = T;
82  };
83  };
84 
85  struct _lazy_extract_gridview
86  {
87  template<typename T>
88  struct evaluate
89  {
90  using type = typename T::GridView;
91  };
92  };
93 
94  // Returns a GridView, regardless of whether GV_or_ES is a GridView or an EntitySet
95  template<typename GV_or_ES>
96  using GridView = typename std::conditional<
98  impl::_lazy_extract_gridview,
99  impl::_lazy_identity
100  >::type::template evaluate<GV_or_ES>::type;
101 
102 
103  // Returns an EntitySet, regardless of whether GV_or_ES is a GridView or an EntitySet
104  template<typename GV_or_ES>
105  using EntitySet = typename std::conditional<
107  GV_or_ES,
108  AllEntitySet<GV_or_ES>
109  >::type;
110 
111  }
112 
113 #endif // DOXYGEN
114 
115  //=======================================
116  // grid function space : single component case
117  //=======================================
118 
120 
123  template<typename G, typename L, typename C, typename B, typename O>
125  {
127  static const bool isComposite = false;
128 
130  using GridView = impl::GridView<G>;
131 
133  using EntitySet = impl::EntitySet<G>;
134 
136 
138  typedef B BackendType;
139 
140  typedef B Backend;
141 
143  typedef typename B::size_type SizeType;
144 
147 
149  typedef L FiniteElementMap;
150 
152  typedef typename L::Traits::FiniteElementType FiniteElementType;
153 
154  typedef typename L::Traits::FiniteElementType FiniteElement;
155 
157  typedef C ConstraintsType;
158 
160 
164  typedef O OrderingTag;
165 
166  };
167 
176  template<typename GV, typename FEM, typename CE=NoConstraints,
177  typename B=ISTL::VectorBackend<>, typename O=DefaultLeafOrderingTag>
179  : public TypeTree::LeafNode
180  , public GridFunctionSpaceBase<
181  GridFunctionSpace<GV,FEM,CE,B,O>,
182  GridFunctionSpaceTraits<GV,FEM,CE,B,O>
183  >
185  , public DataHandleProvider<GridFunctionSpace<GV,FEM,CE,B,O> >
186  {
187 
188  typedef TypeTree::TransformTree<GridFunctionSpace,gfs_to_ordering<GridFunctionSpace> > ordering_transformation;
189 
190  template<typename,typename>
191  friend class GridFunctionSpaceBase;
192 
193  public:
196 
197  private:
198 
200 
201  public:
202 
203  typedef typename GV::Traits::template Codim<0>::Entity Element;
204  typedef typename GV::Traits::template Codim<0>::Iterator ElementIterator;
205 
206  DUNE_DEPRECATED
207  typedef O SizeTag;
208 
209  typedef O OrderingTag;
210 
212 
213  typedef typename ordering_transformation::Type Ordering;
214 
216  template<typename E>
218  {
219 
221  typedef typename std::conditional<
222  std::is_same<
223  CE,
225  >::value,
228  >::type Type;
229 
230  private:
232  };
233 
234  // ****************************************************************************************************
235  // Construct from GridView
236  // ****************************************************************************************************
237 
239  GridFunctionSpace (const typename Traits::GridView& gridview, const FEM& fem, const CE& ce, const B& backend = B(), const OrderingTag& ordering_tag = OrderingTag())
240 #if DUNE_PDELAB_WARN_ON_GRIDVIEW_BASED_GFS
241  DUNE_DEPRECATED_MSG("GridFunctionSpaces now internally use an EntitySet instead of a GridView, please replace the template parameter and the first constructor parameter by an EntitySet").
242 #endif
243  : BaseT(backend,ordering_tag)
244  , _es(gridview)
245  , pfem(stackobject_to_shared_ptr(fem))
246  , _pce(stackobject_to_shared_ptr(ce))
247  {
248  }
249 
251  GridFunctionSpace (const typename Traits::GridView& gridview, const std::shared_ptr<const FEM>& fem, const std::shared_ptr<const CE>& ce, const B& backend = B(), const OrderingTag& ordering_tag = OrderingTag())
252 #if DUNE_PDELAB_WARN_ON_GRIDVIEW_BASED_GFS
253  DUNE_DEPRECATED_MSG("GridFunctionSpaces now internally use an EntitySet instead of a GridView, please replace the template parameter and the first constructor parameter by an EntitySet").
254 #endif
255  : BaseT(backend,ordering_tag)
256  , _es(gridview)
257  , pfem(fem)
258  , _pce(ce)
259  {}
260 
262  GridFunctionSpace (const typename Traits::GridView& gridview, const FEM& fem, const B& backend = B(), const OrderingTag& ordering_tag = OrderingTag())
263 #if DUNE_PDELAB_WARN_ON_GRIDVIEW_BASED_GFS
264  DUNE_DEPRECATED_MSG("GridFunctionSpaces now internally use an EntitySet instead of a GridView, please replace the template parameter and the first constructor parameter by an EntitySet").
265 #endif
266  : BaseT(backend,ordering_tag)
267  , _es(gridview)
268  , pfem(stackobject_to_shared_ptr(fem))
269  , _pce(std::make_shared<CE>())
270  {}
271 
273  GridFunctionSpace (const typename Traits::GridView& gridview, const std::shared_ptr<const FEM>& fem, const B& backend = B(), const OrderingTag& ordering_tag = OrderingTag())
274 #if DUNE_PDELAB_WARN_ON_GRIDVIEW_BASED_GFS
275  DUNE_DEPRECATED_MSG("GridFunctionSpaces now internally use an EntitySet instead of a GridView, please replace the template parameter and the first constructor parameter by an EntitySet").
276 #endif
277  : BaseT(backend,ordering_tag)
278  , _es(gridview)
279  , pfem(fem)
280  , _pce(std::make_shared<CE>())
281  {}
282 
283 
284  // ****************************************************************************************************
285  // Construct from EntitySet
286  // ****************************************************************************************************
287 
288 
290  GridFunctionSpace (const typename Traits::EntitySet& entitySet, const FEM& fem, const CE& ce, const B& backend = B(), const OrderingTag& ordering_tag = OrderingTag())
291  : BaseT(backend,ordering_tag)
292  , _es(entitySet)
293  , pfem(stackobject_to_shared_ptr(fem))
294  , _pce(stackobject_to_shared_ptr(ce))
295  {
296  }
297 
299  GridFunctionSpace (const typename Traits::EntitySet& entitySet, const std::shared_ptr<const FEM>& fem, const std::shared_ptr<const CE>& ce, const B& backend = B(), const OrderingTag& ordering_tag = OrderingTag())
300  : BaseT(backend,ordering_tag)
301  , _es(entitySet)
302  , pfem(fem)
303  , _pce(ce)
304  {}
305 
307  GridFunctionSpace (const typename Traits::EntitySet& entitySet, const FEM& fem, const B& backend = B(), const OrderingTag& ordering_tag = OrderingTag())
308  : BaseT(backend,ordering_tag)
309  , _es(entitySet)
310  , pfem(stackobject_to_shared_ptr(fem))
311  , _pce(std::make_shared<CE>())
312  {}
313 
315  GridFunctionSpace (const typename Traits::EntitySet& entitySet, const std::shared_ptr<const FEM>& fem, const B& backend = B(), const OrderingTag& ordering_tag = OrderingTag())
316  : BaseT(backend,ordering_tag)
317  , _es(entitySet)
318  , pfem(fem)
319  , _pce(std::make_shared<CE>())
320  {}
321 
322 
324  const typename Traits::GridView& gridView () const
325  {
326  return _es.gridView();
327  }
328 
330  const typename Traits::EntitySet& entitySet () const
331  {
332  return _es;
333  }
334 
336  const FEM& finiteElementMap () const
337  {
338  return *pfem;
339  }
340 
342  std::shared_ptr<const FEM> finiteElementMapStorage () const
343  {
344  return pfem;
345  }
346 
348  const typename Traits::ConstraintsType& constraints () const
349  {
350  return *_pce;
351  }
352 
354  std::shared_ptr<const CE> constraintsStorage () const
355  {
356  return _pce;
357  }
358 
359  //------------------------------
360 
362  const Ordering &ordering() const
363  {
364  if (!this->isRootSpace())
365  {
367  "Ordering can only be obtained for root space in GridFunctionSpace tree.");
368  }
369  if (!_ordering)
370  {
371  create_ordering();
372  this->update(*_ordering);
373  }
374  return *_ordering;
375  }
376 
379  {
380  if (!this->isRootSpace())
381  {
383  "Ordering can only be obtained for root space in GridFunctionSpace tree.");
384  }
385  if (!_ordering)
386  {
387  create_ordering();
388  this->update(*_ordering);
389  }
390  return *_ordering;
391  }
392 
394  std::shared_ptr<const Ordering> orderingStorage() const
395  {
396  if (!this->isRootSpace())
397  {
399  "Ordering can only be obtained for root space in GridFunctionSpace tree.");
400  }
401  if (!_ordering)
402  {
403  create_ordering();
404  this->update(*_ordering);
405  }
406  return _ordering;
407  }
408 
410  std::shared_ptr<Ordering> orderingStorage()
411  {
412  if (!this->isRootSpace())
413  {
415  "Ordering can only be obtained for root space in GridFunctionSpace tree.");
416  }
417  if (!_ordering)
418  {
419  create_ordering();
420  this->update(*_ordering);
421  }
422  return _ordering;
423  }
424 
425  private:
426 
427  // This method here is to avoid a double update of the Ordering when the user calls
428  // GFS::update() before GFS::ordering().
429  void create_ordering() const
430  {
431  _ordering = std::make_shared<Ordering>(ordering_transformation::transform(*this));
432  }
433 
434  typename Traits::EntitySet _es;
435  std::shared_ptr<FEM const> pfem;
436  std::shared_ptr<CE const> _pce;
437 
438  mutable std::shared_ptr<Ordering> _ordering;
439  };
440 
441 
442  } // namespace PDELab
443 } // namespace Dune
444 
445 #endif // DUNE_PDELAB_GRIDFUNCTIONSPACE_GRIDFUNCTIONSPACE_HH
gridviewordering.hh
Dune::PDELab::GridFunctionSpace::gridView
const Traits::GridView & gridView() const
get grid view
Definition: gridfunctionspace.hh:324
powergridfunctionspace.hh
Dune::PDELab::GridFunctionSpace::GridFunctionSpace
GridFunctionSpace(const typename Traits::GridView &gridview, const std::shared_ptr< const FEM > &fem, const std::shared_ptr< const CE > &ce, const B &backend=B(), const OrderingTag &ordering_tag=OrderingTag())
constructor
Definition: gridfunctionspace.hh:251
Dune::PDELab::GridFunctionSpace::entitySet
const Traits::EntitySet & entitySet() const
get EntitySet
Definition: gridfunctionspace.hh:330
Dune::PDELab::ISTL::VectorBackend
Definition: istl/descriptors.hh:47
partitionviewentityset.hh
Dune::PDELab::GridFunctionSpaceTraits
collect types exported by a leaf grid function space
Definition: gridfunctionspace.hh:124
Dune::PDELab::GridFunctionSpaceTraits::FiniteElementMap
L FiniteElementMap
finite element map
Definition: gridfunctionspace.hh:149
Dune::PDELab::GridFunctionSpace::ElementIterator
GV::Traits::template Codim< 0 >::Iterator ElementIterator
Definition: gridfunctionspace.hh:204
compositegridfunctionspace.hh
Dune::PDELab::GridFunctionSpaceTraits::GridViewType
GridView GridViewType
Definition: gridfunctionspace.hh:135
Dune::PDELab::GridFunctionSpaceTraits::GridView
impl::GridView< G > GridView
the grid view where grid function is defined upon
Definition: gridfunctionspace.hh:130
Dune::PDELab::GridFunctionSpaceBase< GridFunctionSpace< GV, FEM, NoConstraints, ISTL::VectorBackend<>, DefaultLeafOrderingTag >, GridFunctionSpaceTraits< GV, FEM, NoConstraints, ISTL::VectorBackend<>, DefaultLeafOrderingTag > >::update
void update(bool force=false)
Update the indexing information of the GridFunctionSpace.
Definition: gridfunctionspacebase.hh:205
gridfunctionspaceutilities.hh
Dune::PDELab::GridFunctionSpaceHierarchyError
Definition: exceptions.hh:34
datahandleprovider.hh
Dune::PDELab::LeafGridFunctionSpaceTag
Definition: gridfunctionspace/tags.hh:32
Dune::PDELab::GridFunctionSpace::OrderingTag
O OrderingTag
Definition: gridfunctionspace.hh:209
Dune::PDELab::GridFunctionSpace::Element
GV::Traits::template Codim< 0 >::Entity Element
Definition: gridfunctionspace.hh:203
Dune
For backward compatibility – Do not use this!
Definition: adaptivity.hh:28
Dune::PDELab::GridFunctionSpaceTraits::SizeType
B::size_type SizeType
short cut for size type exported by Backend
Definition: gridfunctionspace.hh:143
Dune::PDELab::GridFunctionSpace::GridFunctionSpace
GridFunctionSpace(const typename Traits::EntitySet &entitySet, const FEM &fem, const CE &ce, const B &backend=B(), const OrderingTag &ordering_tag=OrderingTag())
constructor
Definition: gridfunctionspace.hh:290
Dune::PDELab::LeafOrderingTag
Tag indicating a standard ordering for a leaf GridfunctionSpace.
Definition: gridfunctionspace/tags.hh:183
Dune::PDELab::GridFunctionSpaceBase< GridFunctionSpace< GV, FEM, NoConstraints, ISTL::VectorBackend<>, DefaultLeafOrderingTag >, GridFunctionSpaceTraits< GV, FEM, NoConstraints, ISTL::VectorBackend<>, DefaultLeafOrderingTag > >::backend
Traits::Backend & backend()
Definition: gridfunctionspacebase.hh:226
Dune::PDELab::GridFunctionSpace::GridFunctionSpace
GridFunctionSpace(const typename Traits::EntitySet &entitySet, const FEM &fem, const B &backend=B(), const OrderingTag &ordering_tag=OrderingTag())
constructor
Definition: gridfunctionspace.hh:307
Dune::PDELab::ConstraintsTransformation
a class holding transformation for constrained spaces
Definition: constraintstransformation.hh:18
Dune::PDELab::GridFunctionSpaceTraits::FiniteElementType
L::Traits::FiniteElementType FiniteElementType
finite element
Definition: gridfunctionspace.hh:152
Dune::PDELab::GridFunctionSpaceBase
Definition: gridfunctionspacebase.hh:134
Dune::PDELab::GridFunctionSpaceTraits::Backend
B Backend
Definition: gridfunctionspace.hh:140
Dune::PDELab::GridFunctionSpaceBase< GridFunctionSpace< GV, FEM, NoConstraints, ISTL::VectorBackend<>, DefaultLeafOrderingTag >, GridFunctionSpaceTraits< GV, FEM, NoConstraints, ISTL::VectorBackend<>, DefaultLeafOrderingTag > >::isRootSpace
bool isRootSpace() const
Definition: gridfunctionspacebase.hh:246
Dune::PDELab::NoConstraints
Definition: noconstraints.hh:18
tags.hh
Dune::PDELab::GridFunctionSpaceTraits::isComposite
static const bool isComposite
True if this grid function space is composed of others.
Definition: gridfunctionspace.hh:127
Dune::PDELab::GridFunctionSpace::orderingStorage
std::shared_ptr< Ordering > orderingStorage()
Direct access to the storage of the DOF ordering.
Definition: gridfunctionspace.hh:410
value
static const unsigned int value
Definition: gridfunctionspace/tags.hh:139
Dune::PDELab::GridFunctionSpace::ordering
Ordering & ordering()
Direct access to the DOF ordering.
Definition: gridfunctionspace.hh:378
Dune::PDELab::GridFunctionSpace::ConstraintsContainer::Type
std::conditional< std::is_same< CE, NoConstraints >::value, EmptyTransformation, ConstraintsTransformation< typename Ordering::Traits::DOFIndex, typename Ordering::Traits::ContainerIndex, E > >::type Type
define Type as the Type of a container of E's
Definition: gridfunctionspace.hh:228
Dune::PDELab::GridFunctionSpace::finiteElementMapStorage
std::shared_ptr< const FEM > finiteElementMapStorage() const
get finite element map
Definition: gridfunctionspace.hh:342
Dune::PDELab::GridFunctionSpace
A grid function space.
Definition: gridfunctionspace.hh:178
Dune::PDELab::GridFunctionSpaceTraits::EntitySet
impl::EntitySet< G > EntitySet
the entity set of this function space.
Definition: gridfunctionspace.hh:133
gridfunctionspacebase.hh
Dune::PDELab::GridFunctionSpaceTraits::ConstraintsType
C ConstraintsType
type representing constraints
Definition: gridfunctionspace.hh:157
noconstraints.hh
Dune::PDELab::GridFunctionSpaceTraits::FiniteElementMapType
L FiniteElementMapType
finite element map
Definition: gridfunctionspace.hh:146
Dune::PDELab::GridFunctionSpace::GridFunctionSpace
GridFunctionSpace(const typename Traits::EntitySet &entitySet, const std::shared_ptr< const FEM > &fem, const std::shared_ptr< const CE > &ce, const B &backend=B(), const OrderingTag &ordering_tag=OrderingTag())
constructor
Definition: gridfunctionspace.hh:299
Dune::PDELab::GridFunctionSpace::Traits
GridFunctionSpaceTraits< GV, FEM, CE, B, O > Traits
export Traits class
Definition: gridfunctionspace.hh:195
Dune::PDELab::GridFunctionSpace::Ordering
ordering_transformation::Type Ordering
Definition: gridfunctionspace.hh:213
Dune::PDELab::GridFunctionSpace::GridFunctionSpace
GridFunctionSpace(const typename Traits::EntitySet &entitySet, const std::shared_ptr< const FEM > &fem, const B &backend=B(), const OrderingTag &ordering_tag=OrderingTag())
constructor
Definition: gridfunctionspace.hh:315
Dune::PDELab::EmptyTransformation
Definition: constraintstransformation.hh:111
Dune::PDELab::GridFunctionSpace::finiteElementMap
const FEM & finiteElementMap() const
get finite element map
Definition: gridfunctionspace.hh:336
Dune::PDELab::DataHandleProvider
Definition: datahandleprovider.hh:188
interface.hh
Dune::PDELab::GridFunctionSpace::constraintsStorage
std::shared_ptr< const CE > constraintsStorage() const
return storage of constraints engine
Definition: gridfunctionspace.hh:354
Dune::PDELab::GridFunctionSpace::ordering
const Ordering & ordering() const
Direct access to the DOF ordering.
Definition: gridfunctionspace.hh:362
Dune::PDELab::GridFunctionSpace::orderingStorage
std::shared_ptr< const Ordering > orderingStorage() const
Direct access to the storage of the DOF ordering.
Definition: gridfunctionspace.hh:394
Dune::PDELab::GridFunctionSpace::GridFunctionSpace
GridFunctionSpace(const typename Traits::GridView &gridview, const std::shared_ptr< const FEM > &fem, const B &backend=B(), const OrderingTag &ordering_tag=OrderingTag())
constructor
Definition: gridfunctionspace.hh:273
Dune::PDELab::GridFunctionSpaceTraits::BackendType
B BackendType
vector backend
Definition: gridfunctionspace.hh:138
Dune::PDELab::GridFunctionSpace::ImplementationTag
LeafGridFunctionSpaceTag ImplementationTag
Definition: gridfunctionspace.hh:211
Dune::PDELab::GridFunctionSpace::GridFunctionSpace
GridFunctionSpace(const typename Traits::GridView &gridview, const FEM &fem, const CE &ce, const B &backend=B(), const OrderingTag &ordering_tag=OrderingTag())
constructor
Definition: gridfunctionspace.hh:239
lexicographicordering.hh
Dune::PDELab::GridFunctionSpaceTraits::OrderingTag
O OrderingTag
tag describing the ordering.
Definition: gridfunctionspace.hh:164
Dune::PDELab::GridFunctionSpaceTraits::FiniteElement
L::Traits::FiniteElementType FiniteElement
Definition: gridfunctionspace.hh:154
Dune::PDELab::GridFunctionOutputParameters
Mixin base class for specifying output hints to I/O routines like VTK.
Definition: function.hh:125
descriptors.hh
Dune::PDELab::GridFunctionSpace::SizeTag
O SizeTag
Definition: gridfunctionspace.hh:207
Dune::PDELab::GridFunctionSpace::ConstraintsContainer
extract type for storing constraints
Definition: gridfunctionspace.hh:217
Dune::PDELab::GridFunctionSpace::constraints
const Traits::ConstraintsType & constraints() const
return constraints engine
Definition: gridfunctionspace.hh:348
Dune::PDELab::GridFunctionSpace::GridFunctionSpace
GridFunctionSpace(const typename Traits::GridView &gridview, const FEM &fem, const B &backend=B(), const OrderingTag &ordering_tag=OrderingTag())
constructor
Definition: gridfunctionspace.hh:262