dune-pdelab  2.5-dev
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 
12 #include <dune/common/deprecated.hh>
13 #include <dune/common/exceptions.hh>
14 #include <dune/common/shared_ptr.hh>
15 #include <dune/common/stdstreams.hh>
16 #include <dune/common/typetraits.hh>
17 
18 #include <dune/geometry/referenceelements.hh>
19 #include <dune/geometry/type.hh>
20 
21 #include <dune/localfunctions/common/interfaceswitch.hh>
22 #include <dune/localfunctions/common/localkey.hh>
23 
24 #include <dune/typetree/typetree.hh>
25 
28 
29 // we just want the descriptors here, so we temporarily switch off the warning for
30 // directly including ISTL backend headers
31 #define _DUNE_PDELAB_SUPPRESS_ISTL_HH_WARNING
33 #undef _DUNE_PDELAB_SUPPRESS_ISTL_HH_WARNING
34 
44 
45 namespace Dune {
46  namespace PDELab {
47 
51 
52 #ifndef DOXYGEN
53 
54  namespace impl {
55 
56  // Helper structs to avoid compilation failures in the
57  // backwards compatibility mode where users stuff a
58  // GridView into a GridFunctionSpace.
59  // In that case, we cannot extract the GridView type from
60  // the GridView itself, so we use a std::conditional in the
61  // Traits class to pick either one of the following structs
62  // and then use the correct class to do the lookup.
63 
64  struct _lazy_identity
65  {
66  template<typename T>
67  struct evaluate
68  {
69  using type = T;
70  };
71  };
72 
73  struct _lazy_extract_gridview
74  {
75  template<typename T>
76  struct evaluate
77  {
78  using type = typename T::GridView;
79  };
80  };
81 
82  // Returns a GridView, regardless of whether GV_or_ES is a GridView or an EntitySet
83  template<typename GV_or_ES>
84  using GridView = typename std::conditional<
86  impl::_lazy_extract_gridview,
87  impl::_lazy_identity
88  >::type::template evaluate<GV_or_ES>::type;
89 
90 
91  // Returns an EntitySet, regardless of whether GV_or_ES is a GridView or an EntitySet
92  template<typename GV_or_ES>
93  using EntitySet = typename std::conditional<
95  GV_or_ES,
96  AllEntitySet<GV_or_ES>
97  >::type;
98 
99  }
100 
101 #endif // DOXYGEN
102 
103  //=======================================
104  // grid function space : single component case
105  //=======================================
106 
108 
111  template<typename G, typename L, typename C, typename B, typename O>
113  {
115  static const bool isComposite = false;
116 
118  using GridView = impl::GridView<G>;
119 
121  using EntitySet = impl::EntitySet<G>;
122 
124 
126  typedef B BackendType;
127 
128  typedef B Backend;
129 
131  typedef typename B::size_type SizeType;
132 
135 
137  typedef L FiniteElementMap;
138 
140  typedef typename L::Traits::FiniteElementType FiniteElementType;
141 
142  typedef typename L::Traits::FiniteElementType FiniteElement;
143 
145  typedef C ConstraintsType;
146 
148 
152  typedef O OrderingTag;
153 
154  };
155 
164  template<typename GV, typename FEM, typename CE=NoConstraints,
165  typename B=ISTL::VectorBackend<>, typename O=DefaultLeafOrderingTag>
167  : public TypeTree::LeafNode
168  , public GridFunctionSpaceBase<
169  GridFunctionSpace<GV,FEM,CE,B,O>,
170  GridFunctionSpaceTraits<GV,FEM,CE,B,O>
171  >
173  , public DataHandleProvider<GridFunctionSpace<GV,FEM,CE,B,O> >
174  {
175 
176  typedef TypeTree::TransformTree<GridFunctionSpace,gfs_to_ordering<GridFunctionSpace> > ordering_transformation;
177 
178  template<typename,typename>
179  friend class GridFunctionSpaceBase;
180 
181  public:
184 
185  private:
186 
188 
189  public:
190 
191  typedef typename GV::Traits::template Codim<0>::Entity Element;
192  typedef typename GV::Traits::template Codim<0>::Iterator ElementIterator;
193 
194  DUNE_DEPRECATED
195  typedef O SizeTag;
196 
197  typedef O OrderingTag;
198 
200 
201  typedef typename ordering_transformation::Type Ordering;
202 
204  template<typename E>
206  {
207 
209  typedef typename std::conditional<
210  std::is_same<
211  CE,
213  >::value,
216  >::type Type;
217 
218  private:
220  };
221 
222  // ****************************************************************************************************
223  // Construct from GridView
224  // ****************************************************************************************************
225 
227  GridFunctionSpace (const typename Traits::GridView& gridview, const FEM& fem, const CE& ce, const B& backend = B(), const OrderingTag& ordering_tag = OrderingTag())
228 #if DUNE_PDELAB_WARN_ON_GRIDVIEW_BASED_GFS
229  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").
230 #endif
231  : BaseT(backend,ordering_tag)
232  , _es(gridview)
233  , pfem(stackobject_to_shared_ptr(fem))
234  , _pce(stackobject_to_shared_ptr(ce))
235  {
236  }
237 
239  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())
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(fem)
246  , _pce(ce)
247  {}
248 
250  GridFunctionSpace (const typename Traits::GridView& gridview, const FEM& fem, const B& backend = B(), const OrderingTag& ordering_tag = OrderingTag())
251 #if DUNE_PDELAB_WARN_ON_GRIDVIEW_BASED_GFS
252  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").
253 #endif
254  : BaseT(backend,ordering_tag)
255  , _es(gridview)
256  , pfem(stackobject_to_shared_ptr(fem))
257  , _pce(std::make_shared<CE>())
258  {}
259 
261  GridFunctionSpace (const typename Traits::GridView& gridview, const std::shared_ptr<const FEM>& fem, const B& backend = B(), const OrderingTag& ordering_tag = OrderingTag())
262 #if DUNE_PDELAB_WARN_ON_GRIDVIEW_BASED_GFS
263  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").
264 #endif
265  : BaseT(backend,ordering_tag)
266  , _es(gridview)
267  , pfem(fem)
268  , _pce(std::make_shared<CE>())
269  {}
270 
271 
272  // ****************************************************************************************************
273  // Construct from EntitySet
274  // ****************************************************************************************************
275 
276 
278  GridFunctionSpace (const typename Traits::EntitySet& entitySet, const FEM& fem, const CE& ce, const B& backend = B(), const OrderingTag& ordering_tag = OrderingTag())
279  : BaseT(backend,ordering_tag)
280  , _es(entitySet)
281  , pfem(stackobject_to_shared_ptr(fem))
282  , _pce(stackobject_to_shared_ptr(ce))
283  {
284  }
285 
287  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())
288  : BaseT(backend,ordering_tag)
289  , _es(entitySet)
290  , pfem(fem)
291  , _pce(ce)
292  {}
293 
295  GridFunctionSpace (const typename Traits::EntitySet& entitySet, const FEM& fem, const B& backend = B(), const OrderingTag& ordering_tag = OrderingTag())
296  : BaseT(backend,ordering_tag)
297  , _es(entitySet)
298  , pfem(stackobject_to_shared_ptr(fem))
299  , _pce(std::make_shared<CE>())
300  {}
301 
303  GridFunctionSpace (const typename Traits::EntitySet& entitySet, const std::shared_ptr<const FEM>& fem, const B& backend = B(), const OrderingTag& ordering_tag = OrderingTag())
304  : BaseT(backend,ordering_tag)
305  , _es(entitySet)
306  , pfem(fem)
307  , _pce(std::make_shared<CE>())
308  {}
309 
310 
312  const typename Traits::GridView& gridView () const
313  {
314  return _es.gridView();
315  }
316 
318  const typename Traits::EntitySet& entitySet () const
319  {
320  return _es;
321  }
322 
324  const FEM& finiteElementMap () const
325  {
326  return *pfem;
327  }
328 
330  std::shared_ptr<const FEM> finiteElementMapStorage () const
331  {
332  return pfem;
333  }
334 
336  const typename Traits::ConstraintsType& constraints () const
337  {
338  return *_pce;
339  }
340 
342  std::shared_ptr<const CE> constraintsStorage () const
343  {
344  return _pce;
345  }
346 
347  //------------------------------
348 
350  const Ordering &ordering() const
351  {
352  if (!this->isRootSpace())
353  {
355  "Ordering can only be obtained for root space in GridFunctionSpace tree.");
356  }
357  if (!_ordering)
358  {
359  create_ordering();
360  this->update(*_ordering);
361  }
362  return *_ordering;
363  }
364 
367  {
368  if (!this->isRootSpace())
369  {
371  "Ordering can only be obtained for root space in GridFunctionSpace tree.");
372  }
373  if (!_ordering)
374  {
375  create_ordering();
376  this->update(*_ordering);
377  }
378  return *_ordering;
379  }
380 
382  std::shared_ptr<const Ordering> orderingStorage() const
383  {
384  if (!this->isRootSpace())
385  {
387  "Ordering can only be obtained for root space in GridFunctionSpace tree.");
388  }
389  if (!_ordering)
390  {
391  create_ordering();
392  this->update(*_ordering);
393  }
394  return _ordering;
395  }
396 
398  std::shared_ptr<Ordering> orderingStorage()
399  {
400  if (!this->isRootSpace())
401  {
403  "Ordering can only be obtained for root space in GridFunctionSpace tree.");
404  }
405  if (!_ordering)
406  {
407  create_ordering();
408  this->update(*_ordering);
409  }
410  return _ordering;
411  }
412 
413  private:
414 
415  // This method here is to avoid a double update of the Ordering when the user calls
416  // GFS::update() before GFS::ordering().
417  void create_ordering() const
418  {
419  _ordering = std::make_shared<Ordering>(ordering_transformation::transform(*this));
420  }
421 
422  typename Traits::EntitySet _es;
423  std::shared_ptr<FEM const> pfem;
424  std::shared_ptr<CE const> _pce;
425 
426  mutable std::shared_ptr<Ordering> _ordering;
427  };
428 
429 
430  } // namespace PDELab
431 } // namespace Dune
432 
433 #endif // DUNE_PDELAB_GRIDFUNCTIONSPACE_GRIDFUNCTIONSPACE_HH
Dune::PDELab::GridFunctionSpace::constraintsStorage
std::shared_ptr< const CE > constraintsStorage() const
return storage of constraints engine
Definition: gridfunctionspace.hh:342
gridfunctionspaceutilities.hh
Dune::PDELab::GridFunctionSpace::Ordering
ordering_transformation::Type Ordering
Definition: gridfunctionspace.hh:201
compositegridfunctionspace.hh
Dune::PDELab::GridFunctionOutputParameters
Mixin base class for specifying output hints to I/O routines like VTK.
Definition: function.hh:124
Dune::PDELab::GridFunctionSpaceTraits
collect types exported by a leaf grid function space
Definition: gridfunctionspace.hh:112
Dune::PDELab::GridFunctionSpaceTraits::FiniteElement
L::Traits::FiniteElementType FiniteElement
Definition: gridfunctionspace.hh:142
Dune::PDELab::GridFunctionSpaceTraits::FiniteElementType
L::Traits::FiniteElementType FiniteElementType
finite element
Definition: gridfunctionspace.hh:140
partitionviewentityset.hh
Dune::PDELab::GridFunctionSpace::constraints
const Traits::ConstraintsType & constraints() const
return constraints engine
Definition: gridfunctionspace.hh:336
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:16
lexicographicordering.hh
Dune
For backward compatibility – Do not use this!
Definition: adaptivity.hh:28
Dune::PDELab::GridFunctionSpace::ordering
Ordering & ordering()
Direct access to the DOF ordering.
Definition: gridfunctionspace.hh:366
Dune::PDELab::GridFunctionSpace::finiteElementMap
const FEM & finiteElementMap() const
get finite element map
Definition: gridfunctionspace.hh:324
Dune::PDELab::GridFunctionSpace::OrderingTag
O OrderingTag
Definition: gridfunctionspace.hh:197
Dune::PDELab::GridFunctionSpaceBase
Definition: gridfunctionspacebase.hh:134
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
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:303
Dune::PDELab::GridFunctionSpaceTraits::GridView
impl::GridView< G > GridView
the grid view where grid function is defined upon
Definition: gridfunctionspace.hh:118
gridfunctionspacebase.hh
Dune::PDELab::ISTL::VectorBackend
Definition: istl/descriptors.hh:47
Dune::PDELab::GridFunctionSpace::entitySet
const Traits::EntitySet & entitySet() const
get EntitySet
Definition: gridfunctionspace.hh:318
Dune::PDELab::GridFunctionSpaceTraits::EntitySet
impl::EntitySet< G > EntitySet
the entity set of this function space.
Definition: gridfunctionspace.hh:121
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:278
Dune::PDELab::GridFunctionSpace
A grid function space.
Definition: gridfunctionspace.hh:166
Dune::PDELab::GridFunctionSpaceTraits::OrderingTag
O OrderingTag
tag describing the ordering.
Definition: gridfunctionspace.hh:152
Dune::PDELab::GridFunctionSpaceTraits::SizeType
B::size_type SizeType
short cut for size type exported by Backend
Definition: gridfunctionspace.hh:131
tags.hh
Dune::PDELab::GridFunctionSpace::finiteElementMapStorage
std::shared_ptr< const FEM > finiteElementMapStorage() const
get finite element map
Definition: gridfunctionspace.hh:330
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:261
Dune::PDELab::EmptyTransformation
Definition: constraintstransformation.hh:111
Dune::PDELab::GridFunctionSpaceTraits::isComposite
static const bool isComposite
True if this grid function space is composed of others.
Definition: gridfunctionspace.hh:115
Dune::PDELab::GridFunctionSpaceTraits::ConstraintsType
C ConstraintsType
type representing constraints
Definition: gridfunctionspace.hh:145
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:227
Dune::PDELab::GridFunctionSpaceTraits::FiniteElementMapType
L FiniteElementMapType
finite element map
Definition: gridfunctionspace.hh:134
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:250
powergridfunctionspace.hh
Dune::PDELab::ConstraintsTransformation
a class holding transformation for constrained spaces
Definition: constraintstransformation.hh:18
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:216
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::DataHandleProvider
Definition: datahandleprovider.hh:187
datahandleprovider.hh
Dune::PDELab::LeafOrderingTag
Tag indicating a standard ordering for a leaf GridfunctionSpace.
Definition: gridfunctionspace/tags.hh:183
Dune::PDELab::LeafGridFunctionSpaceTag
Definition: gridfunctionspace/tags.hh:32
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:239
Dune::PDELab::GridFunctionSpace::orderingStorage
std::shared_ptr< Ordering > orderingStorage()
Direct access to the storage of the DOF ordering.
Definition: gridfunctionspace.hh:398
Dune::PDELab::GridFunctionSpace::ImplementationTag
LeafGridFunctionSpaceTag ImplementationTag
Definition: gridfunctionspace.hh:199
Dune::PDELab::GridFunctionSpace::Element
GV::Traits::template Codim< 0 >::Entity Element
Definition: gridfunctionspace.hh:191
Dune::PDELab::GridFunctionSpaceHierarchyError
Definition: exceptions.hh:34
Dune::PDELab::GridFunctionSpace::ElementIterator
GV::Traits::template Codim< 0 >::Iterator ElementIterator
Definition: gridfunctionspace.hh:192
noconstraints.hh
Dune::PDELab::GridFunctionSpace::ordering
const Ordering & ordering() const
Direct access to the DOF ordering.
Definition: gridfunctionspace.hh:350
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:287
Dune::PDELab::GridFunctionSpaceTraits::BackendType
B BackendType
vector backend
Definition: gridfunctionspace.hh:126
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:295
value
static const unsigned int value
Definition: gridfunctionspace/tags.hh:139
Dune::PDELab::GridFunctionSpace::gridView
const Traits::GridView & gridView() const
get grid view
Definition: gridfunctionspace.hh:312
Dune::PDELab::GridFunctionSpace::Traits
GridFunctionSpaceTraits< GV, FEM, CE, B, O > Traits
export Traits class
Definition: gridfunctionspace.hh:183
Dune::PDELab::GridFunctionSpaceTraits::GridViewType
GridView GridViewType
Definition: gridfunctionspace.hh:123
interface.hh
Dune::PDELab::GridFunctionSpace::ConstraintsContainer
extract type for storing constraints
Definition: gridfunctionspace.hh:205
Dune::PDELab::GridFunctionSpaceTraits::FiniteElementMap
L FiniteElementMap
finite element map
Definition: gridfunctionspace.hh:137
Dune::PDELab::GridFunctionSpace::SizeTag
O SizeTag
Definition: gridfunctionspace.hh:195
gridviewordering.hh
descriptors.hh
Dune::PDELab::GridFunctionSpace::orderingStorage
std::shared_ptr< const Ordering > orderingStorage() const
Direct access to the storage of the DOF ordering.
Definition: gridfunctionspace.hh:382
Dune::PDELab::GridFunctionSpaceTraits::Backend
B Backend
Definition: gridfunctionspace.hh:128