dune-pdelab  2.4.1
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_HH
4 #define DUNE_PDELAB_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 
37 
38 namespace Dune {
39  namespace PDELab {
40 
44 
45 #ifndef DOXYGEN
46 
47  namespace impl {
48 
49  // Helper structs to avoid compilation failures in the
50  // backwards compatibility mode where users stuff a
51  // GridView into a GridFunctionSpace.
52  // In that case, we cannot extract the GridView type from
53  // the GridView itself, so we use a std::conditional in the
54  // Traits class to pick either one of the following structs
55  // and then use the correct class to do the lookup.
56 
57  struct _lazy_identity
58  {
59  template<typename T>
60  struct evaluate
61  {
62  using type = T;
63  };
64  };
65 
66  struct _lazy_extract_gridview
67  {
68  template<typename T>
69  struct evaluate
70  {
71  using type = typename T::GridView;
72  };
73  };
74 
75  // Returns a GridView, regardless of whether GV_or_ES is a GridView or an EntitySet
76  template<typename GV_or_ES>
77  using GridView = typename std::conditional<
79  impl::_lazy_extract_gridview,
80  impl::_lazy_identity
81  >::type::template evaluate<GV_or_ES>::type;
82 
83 
84  // Returns an EntitySet, regardless of whether GV_or_ES is a GridView or an EntitySet
85  template<typename GV_or_ES>
86  using EntitySet = typename std::conditional<
87  isEntitySet<GV_or_ES>::value,
88  GV_or_ES,
89  AllEntitySet<GV_or_ES>
90  >::type;
91 
92  }
93 
94 #endif // DOXYGEN
95 
96  //=======================================
97  // grid function space : single component case
98  //=======================================
99 
101 
104  template<typename G, typename L, typename C, typename B, typename O>
106  {
108  static const bool isComposite = false;
109 
111  using GridView = impl::GridView<G>;
112 
114  using EntitySet = impl::EntitySet<G>;
115 
117 
119  typedef B BackendType;
120 
121  typedef B Backend;
122 
124  typedef typename B::size_type SizeType;
125 
128 
130  typedef L FiniteElementMap;
131 
133  typedef typename L::Traits::FiniteElementType FiniteElementType;
134 
135  typedef typename L::Traits::FiniteElementType FiniteElement;
136 
138  typedef C ConstraintsType;
139 
141 
145  typedef O OrderingTag;
146 
147  };
148 
161  template<typename GV, typename FEM, typename CE=NoConstraints,
162  typename B=istl::VectorBackend<>, typename P=DefaultLeafOrderingTag>
164  : public TypeTree::LeafNode
165  , public GridFunctionSpaceBase<
166  GridFunctionSpace<GV,FEM,CE,B,P>,
167  GridFunctionSpaceTraits<GV,FEM,CE,B,P>
168  >
170  , public DataHandleProvider<GridFunctionSpace<GV,FEM,CE,B,P> >
171  {
172 
173  typedef TypeTree::TransformTree<GridFunctionSpace,gfs_to_ordering<GridFunctionSpace> > ordering_transformation;
174 
175  template<typename,typename>
176  friend class GridFunctionSpaceBase;
177 
178  public:
181 
182  private:
183 
185 
186  public:
187 
188  typedef typename GV::Traits::template Codim<0>::Entity Element;
189  typedef typename GV::Traits::template Codim<0>::Iterator ElementIterator;
190 
191  typedef P SizeTag;
192 
193  typedef P OrderingTag;
194 
196 
197  typedef typename ordering_transformation::Type Ordering;
198 
200  template<typename E>
202  {
203 
205  typedef typename conditional<
206  is_same<
207  CE,
209  >::value,
212  >::type Type;
213 
214  private:
216  };
217 
218  // ****************************************************************************************************
219  // Construct from GridView
220  // ****************************************************************************************************
221 
223  GridFunctionSpace (const typename Traits::GridView& gridview, const FEM& fem, const CE& ce, const B& backend = B(), const OrderingTag& ordering_tag = OrderingTag())
224  : BaseT(backend,ordering_tag)
225  , _es(gridview)
226  , pfem(stackobject_to_shared_ptr(fem))
227  , _pce(stackobject_to_shared_ptr(ce))
228  {
229  }
230 
232  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())
233  : BaseT(backend,ordering_tag)
234  , _es(gridview)
235  , pfem(fem)
236  , _pce(ce)
237  {}
238 
240  GridFunctionSpace (const typename Traits::GridView& gridview, const FEM& fem, const B& backend = B(), const OrderingTag& ordering_tag = OrderingTag())
241  : BaseT(backend,ordering_tag)
242  , _es(gridview)
243  , pfem(stackobject_to_shared_ptr(fem))
244  , _pce(std::make_shared<CE>())
245  {}
246 
248  GridFunctionSpace (const typename Traits::GridView& gridview, const std::shared_ptr<const FEM>& fem, const B& backend = B(), const OrderingTag& ordering_tag = OrderingTag())
249  : BaseT(backend,ordering_tag)
250  , _es(gridview)
251  , pfem(fem)
252  , _pce(std::make_shared<CE>())
253  {}
254 
255 
256  // ****************************************************************************************************
257  // Construct from EntitySet
258  // ****************************************************************************************************
259 
260 
262  GridFunctionSpace (const typename Traits::EntitySet& entitySet, const FEM& fem, const CE& ce, const B& backend = B(), const OrderingTag& ordering_tag = OrderingTag())
263  : BaseT(backend,ordering_tag)
264  , _es(entitySet)
265  , pfem(stackobject_to_shared_ptr(fem))
266  , _pce(stackobject_to_shared_ptr(ce))
267  {
268  }
269 
271  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())
272  : BaseT(backend,ordering_tag)
273  , _es(entitySet)
274  , pfem(fem)
275  , _pce(ce)
276  {}
277 
279  GridFunctionSpace (const typename Traits::EntitySet& entitySet, const FEM& fem, const B& backend = B(), const OrderingTag& ordering_tag = OrderingTag())
280  : BaseT(backend,ordering_tag)
281  , _es(entitySet)
282  , pfem(stackobject_to_shared_ptr(fem))
283  , _pce(std::make_shared<CE>())
284  {}
285 
287  GridFunctionSpace (const typename Traits::EntitySet& entitySet, const std::shared_ptr<const FEM>& fem, const B& backend = B(), const OrderingTag& ordering_tag = OrderingTag())
288  : BaseT(backend,ordering_tag)
289  , _es(entitySet)
290  , pfem(fem)
291  , _pce(std::make_shared<CE>())
292  {}
293 
294 
296  const typename Traits::GridView& gridView () const
297  {
298  return _es.gridView();
299  }
300 
302  const typename Traits::EntitySet& entitySet () const
303  {
304  return _es;
305  }
306 
308  const FEM& finiteElementMap () const
309  {
310  return *pfem;
311  }
312 
314  std::shared_ptr<const FEM> finiteElementMapStorage () const
315  {
316  return pfem;
317  }
318 
320  const typename Traits::ConstraintsType& constraints () const
321  {
322  return *_pce;
323  }
324 
326  std::shared_ptr<const CE> constraintsStorage () const
327  {
328  return _pce;
329  }
330 
331  //------------------------------
332 
334  const Ordering &ordering() const
335  {
336  if (!this->isRootSpace())
337  {
339  "Ordering can only be obtained for root space in GridFunctionSpace tree.");
340  }
341  if (!_ordering)
342  {
343  create_ordering();
344  this->update(*_ordering);
345  }
346  return *_ordering;
347  }
348 
350  Ordering &ordering()
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 
366  std::shared_ptr<const Ordering> orderingStorage() const
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<Ordering> orderingStorage()
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 
397  private:
398 
399  // This method here is to avoid a double update of the Ordering when the user calls
400  // GFS::update() before GFS::ordering().
401  void create_ordering() const
402  {
403  _ordering = std::make_shared<Ordering>(ordering_transformation::transform(*this));
404  }
405 
406  typename Traits::EntitySet _es;
407  std::shared_ptr<FEM const> pfem;
408  std::shared_ptr<CE const> _pce;
409 
410  mutable std::shared_ptr<Ordering> _ordering;
411  };
412 
413 
414  } // namespace PDELab
415 } // namespace Dune
416 
417 #endif
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:262
STL namespace.
std::shared_ptr< const Ordering > orderingStorage() const
Direct access to the storage of the DOF ordering.
Definition: gridfunctionspace.hh:366
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:232
L FiniteElementMap
finite element map
Definition: gridfunctionspace.hh:130
Tag indicating a standard ordering for a leaf GridfunctionSpace.
Definition: gridfunctionspace/tags.hh:221
L FiniteElementMapType
finite element map
Definition: gridfunctionspace.hh:127
static const unsigned int value
Definition: gridfunctionspace/tags.hh:177
impl::GridView< G > GridView
the grid view where grid function is defined upon
Definition: gridfunctionspace.hh:111
Definition: noconstraints.hh:16
std::shared_ptr< Ordering > orderingStorage()
Direct access to the storage of the DOF ordering.
Definition: gridfunctionspace.hh:382
a class holding transformation for constrained spaces
Definition: constraintstransformation.hh:18
std::shared_ptr< const FEM > finiteElementMapStorage() const
get finite element map
Definition: gridfunctionspace.hh:314
Definition: adaptivity.hh:27
impl::EntitySet< G > EntitySet
the entity set of this function space.
Definition: gridfunctionspace.hh:114
P SizeTag
Definition: gridfunctionspace.hh:191
const Traits::GridView & gridView() const
get grid view
Definition: gridfunctionspace.hh:296
B BackendType
vector backend
Definition: gridfunctionspace.hh:119
Ordering & ordering()
Direct access to the DOF ordering.
Definition: gridfunctionspace.hh:350
B::size_type SizeType
short cut for size type exported by Backend
Definition: gridfunctionspace.hh:124
P OrderingTag
Definition: gridfunctionspace.hh:193
LeafGridFunctionSpaceTag ImplementationTag
Definition: gridfunctionspace.hh:195
Definition: datahandleprovider.hh:188
ordering_transformation::Type Ordering
Definition: gridfunctionspace.hh:197
collect types exported by a leaf grid function space
Definition: gridfunctionspace.hh:105
GridView GridViewType
Definition: gridfunctionspace.hh:116
const Traits::ConstraintsType & constraints() const
return constraints engine
Definition: gridfunctionspace.hh:320
GridFunctionSpace(const typename Traits::EntitySet &entitySet, const FEM &fem, const B &backend=B(), const OrderingTag &ordering_tag=OrderingTag())
constructor
Definition: gridfunctionspace.hh:279
GridFunctionSpace(const typename Traits::GridView &gridview, const FEM &fem, const B &backend=B(), const OrderingTag &ordering_tag=OrderingTag())
constructor
Definition: gridfunctionspace.hh:240
extract type for storing constraints
Definition: gridfunctionspace.hh:201
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:271
Definition: gridfunctionspace/tags.hh:32
Mixin base class for specifying output hints to I/O routines like VTK.
Definition: function.hh:123
const Ordering & ordering() const
Direct access to the DOF ordering.
Definition: gridfunctionspace.hh:334
GV::Traits::template Codim< 0 >::Iterator ElementIterator
Definition: gridfunctionspace.hh:189
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:287
L::Traits::FiniteElementType FiniteElement
Definition: gridfunctionspace.hh:135
Definition: constraintstransformation.hh:111
Definition: istl/descriptors.hh:47
GridFunctionSpaceTraits< GV, FEM, CE, B, P > Traits
export Traits class
Definition: gridfunctionspace.hh:180
GV::Traits::template Codim< 0 >::Entity Element
Definition: gridfunctionspace.hh:188
C ConstraintsType
type representing constraints
Definition: gridfunctionspace.hh:138
conditional< 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:212
Definition: gridfunctionspacebase.hh:134
std::shared_ptr< const CE > constraintsStorage() const
return storage of constraints engine
Definition: gridfunctionspace.hh:326
const Traits::EntitySet & entitySet() const
get EntitySet
Definition: gridfunctionspace.hh:302
L::Traits::FiniteElementType FiniteElementType
finite element
Definition: gridfunctionspace.hh:133
B Backend
Definition: gridfunctionspace.hh:121
const FEM & finiteElementMap() const
get finite element map
Definition: gridfunctionspace.hh:308
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:248
O OrderingTag
tag describing the ordering.
Definition: gridfunctionspace.hh:145
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:223
A grid function space.
Definition: gridfunctionspace.hh:163