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