dune-pdelab  2.5-dev
dunefunctionsgridfunctionspace.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_DUNEFUNCTIONSGRIDFUNCTIONSPACE_HH
4 #define DUNE_PDELAB_GRIDFUNCTIONSPACE_DUNEFUNCTIONSGRIDFUNCTIONSPACE_HH
5 
6 #include <cstddef>
7 #include <map>
8 
9 #include <dune/common/exceptions.hh>
10 #include <dune/common/typetraits.hh>
11 
15 
18 
19 namespace Dune {
20  namespace PDELab {
21 
25 
26  namespace Experimental {
27 
28  // The following code recognizes whether the given VectorBackend (VBE) is an ISTL backend.
29  // If this is the case, then we need to replace it by ISTL::SimpleVectorBackend,
30  // because we cannot handle anything more complicated at the moment.
31  template<typename VBE>
33 
34  template<std::size_t block_size>
36 
37  template<typename VBE>
38  using DuneFunctionsCompatibleVBE = std::decay_t<decltype(*registerDuneFunctionsCompatibleVBE(std::declval<VBE*>()))>;
39 
52  template<typename DFBasis, typename VBE, typename CE>
54  : public TypeTree::LeafNode
56  // , public DataHandleProvider<DuneFunctionsGridFunctionSpace<DFBasis,CE,B,P> >
57  {
58  using GV = typename DFBasis::GridView;
59 
60  template<typename,typename>
61  friend class GridFunctionSpaceBase;
62 
63  public:
65 
66  struct Traits {
67 
68  using GridView = Dune::PDELab::impl::GridView<typename DFBasis::GridView>;
69  using EntitySet = Dune::PDELab::impl::EntitySet<typename DFBasis::GridView>;
70 
71  using size_type = std::size_t;
73  using ConstraintsType = CE;
74 
75  using Basis = DFBasis;
76 
77  // The following code recognizes whether the given VectorBackend (VBE) is an ISTL backend.
78  // If this is the case, then we replace it by ISTL::SimpleVectorBackend,
79  // because we cannot handle anything more complicated at the moment.
81 
83  struct FEM
84  {
85  struct Traits
86  {
87  using FiniteElement = typename DFBasis::LocalView::Tree::FiniteElement;
89  };
90 
101  const typename Traits::FiniteElementType& find (const typename GridView::template Codim<0>::Entity& element) const
102  {
103  auto type = element.type();
104  auto mapEntry = geometryTypeToLocalView_.find(type);
105  if (mapEntry == geometryTypeToLocalView_.end())
106  {
107  auto newLocalView = std::make_shared<typename DFBasis::LocalView>(_basis->localView());
108  newLocalView->bind(element);
109  auto insertedLocalView = geometryTypeToLocalView_.insert(std::make_pair(type, newLocalView));
110  return insertedLocalView.first->second->tree().finiteElement();
111  }
112  else
113  {
114  return mapEntry->second->tree().finiteElement();
115  }
116  }
117 
118  std::shared_ptr<DFBasis> _basis;
119 
120  mutable std::map<GeometryType, std::shared_ptr<typename DFBasis::LocalView> > geometryTypeToLocalView_;
121  };
122 
125 
126  };
127 
128  using Basis = DFBasis;
129 
130  struct Ordering {
131 
132  struct Traits {
133 
134  using DOFIndex = typename DFBasis::MultiIndex;
136  using size_type = std::size_t;
138 
139  };
140 
141  using DOFIndex = typename DFBasis::MultiIndex;
143  using size_type = std::size_t;
144 
147 
149  : _gfs(gfs)
150  {}
151 
152  size_type size() const
153  {
154  return _gfs.basis().size();
155  }
156 
160  {
161  return size();
162  }
163 
165  {
166  return _gfs.basis().maxLocalSize();
167  }
168 
170  {
171  return di;
172  }
173 
174  void mapIndex(const DOFIndex& di, ContainerIndex& ci) const
175  {
176  ci = di;
177  }
178 
179  void update()
180  {}
181 
182  private:
183 
184  const GridFunctionSpace& _gfs;
185 
186  };
187 
188 
190  template<typename E>
192  {
193 
195  using Type = std::conditional_t<
196  std::is_same<
197  CE,
199  >::value,
202  >;
203 
204  private:
206  };
207 
208  // ****************************************************************************************************
209  // Construct from a dune-functions basis
210  // ****************************************************************************************************
211 
213  GridFunctionSpace (std::shared_ptr<DFBasis> df_basis, std::shared_ptr<CE> ce)
214  : _es(df_basis->gridView(), Traits::EntitySet::allCodims())
215  , _df_basis(std::move(df_basis))
216  , _pce(std::move(ce))
217  , _ordering(*this)
218  {}
219 
220  GridFunctionSpace (std::shared_ptr<DFBasis> df_basis)
221  : _es(df_basis->gridView(), Traits::EntitySet::allCodims())
222  , _df_basis(std::move(df_basis))
223  , _pce(std::make_shared<CE>())
224  , _ordering(*this)
225  {}
226 
228  const typename Traits::GridView& gridView () const
229  {
230  return _es.gridView();
231  }
232 
234  const typename Traits::EntitySet& entitySet () const
235  {
236  return _es;
237  }
238 
240  const auto& finiteElementMap () const
241  {
242  return _finiteElementMap;
243  }
244 
246  const typename Traits::ConstraintsType& constraints () const
247  {
248  return *_pce;
249  }
250 
252  std::shared_ptr<const CE> constraintsStorage () const
253  {
254  return _pce;
255  }
256 
258  const Ordering& ordering() const
259  {
260  return _ordering;
261  }
262 
263  typename Traits::SizeType size() const
264  {
265  return _ordering.size();
266  }
267 
268  typename Traits::SizeType blockCount() const
269  {
270  return _ordering.blockCount();
271  }
272 
273  typename Traits::SizeType globalSize() const
274  {
275  return _ordering.size();
276  }
277 
278  typename Traits::SizeType maxLocalSize () const
279  {
280  return _ordering.maxLocalSize();
281  }
282 
288  void update(bool force = false)
289  {
290  _es.update(force);
291  _df_basis->update(_es.gridView());
292  }
293 
294  const std::string& name() const
295  {
296  return _name;
297  }
298 
299  void name(const std::string& name)
300  {
301  _name = name;
302  }
303 
304  bool isRootSpace() const
305  {
306  return true;
307  }
308 
309  const Basis& basis() const
310  {
311  return *_df_basis;
312  }
313 
314  private:
315 
316  typename Traits::EntitySet _es;
317  std::shared_ptr<DFBasis> _df_basis;
318  typename Traits::FiniteElementMap _finiteElementMap;
319  std::shared_ptr<CE const> _pce;
320  Ordering _ordering;
321  std::string _name;
322  };
323 
324  } // namespace Experimental
325 
331  template <typename DFBasis, typename V, typename CE, typename U>
332  class AddDataHandle<Experimental::GridFunctionSpace<DFBasis,V,CE>,U>
333  : public CommDataHandleIF<AddDataHandle<Experimental::GridFunctionSpace<DFBasis,V,CE>,U>, typename U::field_type>
334  {
335  using DataType = typename U::field_type;
336 
338  public:
340  const U& u)
341  {}
342 
344  bool contains (int dim, int codim) const
345  {
346  return false;
347  }
348 
350  bool fixedsize (int dim, int codim) const
351  {
352  return true;
353  }
354 
355  // How many objects of type DataType have to be sent for a given entity
356  template<class EntityType>
357  size_t size (const EntityType& e) const
358  {
359  return 0;
360  }
361 
362  // Pack data from user to message buffer
363  template<class MessageBuffer, class EntityType>
364  void gather(MessageBuffer& buffer, const EntityType& entity) const
365  {}
366 
367  // Unpack data from message buffer to user
368  template<class MessageBuffer, class EntityType>
369  void scatter(MessageBuffer& buffer, const EntityType& entity, size_t n)
370  {}
371  };
372  } // namespace PDELab
373 } // namespace Dune
374 
375 #endif // DUNE_PDELAB_GRIDFUNCTIONSPACE_DUNEFUNCTIONSGRIDFUNCTIONSPACE_HH
Dune::PDELab::Experimental::GridFunctionSpace::Ordering::Traits
Definition: dunefunctionsgridfunctionspace.hh:132
Dune::PDELab::Experimental::GridFunctionSpace::Ordering::ContainerIndex
DOFIndex ContainerIndex
Definition: dunefunctionsgridfunctionspace.hh:142
Dune::PDELab::AddDataHandle< Experimental::GridFunctionSpace< DFBasis, V, CE >, U >::gather
void gather(MessageBuffer &buffer, const EntityType &entity) const
Definition: dunefunctionsgridfunctionspace.hh:364
istl.hh
Dune::PDELab::Experimental::GridFunctionSpace::globalSize
Traits::SizeType globalSize() const
Definition: dunefunctionsgridfunctionspace.hh:273
Dune::PDELab::Experimental::GridFunctionSpace::Ordering::update
void update()
Definition: dunefunctionsgridfunctionspace.hh:179
Dune::PDELab::GridFunctionOutputParameters
Mixin base class for specifying output hints to I/O routines like VTK.
Definition: function.hh:124
Dune::PDELab::Experimental::GridFunctionSpace::Traits::FEM::Traits
Definition: dunefunctionsgridfunctionspace.hh:85
Dune::PDELab::Experimental::GridFunctionSpace::constraintsStorage
std::shared_ptr< const CE > constraintsStorage() const
return storage of constraints engine
Definition: dunefunctionsgridfunctionspace.hh:252
Dune::PDELab::Experimental::GridFunctionSpace::Ordering::Ordering
Ordering(const GridFunctionSpace &gfs)
Definition: dunefunctionsgridfunctionspace.hh:148
Dune::PDELab::Experimental::GridFunctionSpace::Traits::ConstraintsType
CE ConstraintsType
Definition: dunefunctionsgridfunctionspace.hh:73
Dune::PDELab::Experimental::DuneFunctionsCacheTag
Definition: gridfunctionspace/tags.hh:220
Dune::PDELab::Experimental::GridFunctionSpace
A pdelab grid function space implemented by a dune-functions function space basis.
Definition: dunefunctionsgridfunctionspace.hh:53
Dune::PDELab::Experimental::GridFunctionSpace::Traits::size_type
std::size_t size_type
Definition: dunefunctionsgridfunctionspace.hh:71
Dune::PDELab::Experimental::DuneFunctionsCompatibleVBE
std::decay_t< decltype(*registerDuneFunctionsCompatibleVBE(std::declval< VBE * >()))> DuneFunctionsCompatibleVBE
Definition: dunefunctionsgridfunctionspace.hh:38
Dune::PDELab::Experimental::GridFunctionSpace::blockCount
Traits::SizeType blockCount() const
Definition: dunefunctionsgridfunctionspace.hh:268
Dune::PDELab::Experimental::GridFunctionSpace::basis
const Basis & basis() const
Definition: dunefunctionsgridfunctionspace.hh:309
Dune::PDELab::Experimental::GridFunctionSpace::size
Traits::SizeType size() const
Definition: dunefunctionsgridfunctionspace.hh:263
dim
static const int dim
Definition: adaptivity.hh:84
Dune::PDELab::AddDataHandle< Experimental::GridFunctionSpace< DFBasis, V, CE >, U >::scatter
void scatter(MessageBuffer &buffer, const EntityType &entity, size_t n)
Definition: dunefunctionsgridfunctionspace.hh:369
gridfunctionspace.hh
Dune::PDELab::Experimental::GridFunctionSpace::Ordering::Traits::size_type
std::size_t size_type
Definition: dunefunctionsgridfunctionspace.hh:136
dunefunctionslfsindexcache.hh
Dune::PDELab::Experimental::GridFunctionSpace::Traits::FEM::find
const Traits::FiniteElementType & find(const typename GridView::template Codim< 0 >::Entity &element) const
Get local basis functions for entity.
Definition: dunefunctionsgridfunctionspace.hh:101
Dune::PDELab::NoConstraints
Definition: noconstraints.hh:16
Dune::PDELab::Experimental::GridFunctionSpace::Ordering::maxLocalSize
size_type maxLocalSize() const
Definition: dunefunctionsgridfunctionspace.hh:164
Dune::PDELab::Experimental::GridFunctionSpace::Traits::FEM
Rudimentary internal implementation of a FiniteElementMap.
Definition: dunefunctionsgridfunctionspace.hh:83
Dune
For backward compatibility – Do not use this!
Definition: adaptivity.hh:28
dunefunctions.hh
Dune::PDELab::Experimental::GridFunctionSpace::entitySet
const Traits::EntitySet & entitySet() const
get EntitySet
Definition: dunefunctionsgridfunctionspace.hh:234
Dune::PDELab::Experimental::GridFunctionSpace::name
const std::string & name() const
Definition: dunefunctionsgridfunctionspace.hh:294
Dune::PDELab::Experimental::GridFunctionSpace::Ordering::Traits::SizeType
size_type SizeType
Definition: dunefunctionsgridfunctionspace.hh:137
Dune::PDELab::Experimental::GridFunctionSpace::maxLocalSize
Traits::SizeType maxLocalSize() const
Definition: dunefunctionsgridfunctionspace.hh:278
Dune::PDELab::Experimental::GridFunctionSpace::Traits::Basis
DFBasis Basis
Definition: dunefunctionsgridfunctionspace.hh:75
Dune::PDELab::FlatContainerAllocationTag
Definition: gridfunctionspace/tags.hh:208
Dune::PDELab::Experimental::GridFunctionSpace::Ordering::mapIndex
ContainerIndex mapIndex(const DOFIndex &di) const
Definition: dunefunctionsgridfunctionspace.hh:169
Dune::PDELab::GridFunctionSpaceBase
Definition: gridfunctionspacebase.hh:134
Dune::PDELab::Experimental::GridFunctionSpace::ConstraintsContainer::Type
std::conditional_t< std::is_same< CE, NoConstraints >::value, EmptyTransformation, ConstraintsTransformation< typename Ordering::Traits::DOFIndex, typename Ordering::Traits::ContainerIndex, E > > Type
define Type as the Type of a container of E's
Definition: dunefunctionsgridfunctionspace.hh:202
Dune::PDELab::Experimental::GridFunctionSpace::ordering
const Ordering & ordering() const
Direct access to the DOF ordering.
Definition: dunefunctionsgridfunctionspace.hh:258
Dune::PDELab::Experimental::GridFunctionSpace::Ordering::DOFIndex
typename DFBasis::MultiIndex DOFIndex
Definition: dunefunctionsgridfunctionspace.hh:141
Dune::PDELab::ISTL::VectorBackend
Definition: istl/descriptors.hh:47
Dune::PDELab::Experimental::GridFunctionSpace::constraints
const Traits::ConstraintsType & constraints() const
return constraints engine
Definition: dunefunctionsgridfunctionspace.hh:246
Dune::PDELab::Experimental::GridFunctionSpace::Ordering::size
size_type size() const
Definition: dunefunctionsgridfunctionspace.hh:152
Dune::PDELab::GridFunctionSpace
A grid function space.
Definition: gridfunctionspace.hh:166
Dune::PDELab::Experimental::GridFunctionSpace::Ordering::Traits::ContainerIndex
DOFIndex ContainerIndex
Definition: dunefunctionsgridfunctionspace.hh:135
Dune::PDELab::Experimental::GridFunctionSpace::Traits::Backend
DuneFunctionsCompatibleVBE< VBE > Backend
Definition: dunefunctionsgridfunctionspace.hh:80
Dune::PDELab::EmptyTransformation
Definition: constraintstransformation.hh:111
Dune::PDELab::Experimental::GridFunctionSpace::Ordering::size_type
std::size_t size_type
Definition: dunefunctionsgridfunctionspace.hh:143
Dune::PDELab::Experimental::GridFunctionSpace::Ordering
Definition: dunefunctionsgridfunctionspace.hh:130
e
const Entity & e
Definition: localfunctionspace.hh:120
Dune::PDELab::Experimental::GridFunctionSpace::Ordering::mapIndex
void mapIndex(const DOFIndex &di, ContainerIndex &ci) const
Definition: dunefunctionsgridfunctionspace.hh:174
Dune::PDELab::ConstraintsTransformation
a class holding transformation for constrained spaces
Definition: constraintstransformation.hh:18
Dune::PDELab::Experimental::GridFunctionSpace::finiteElementMap
const auto & finiteElementMap() const
get finite element map
Definition: dunefunctionsgridfunctionspace.hh:240
Dune::PDELab::Experimental::GridFunctionSpace::Traits::EntitySet
Dune::PDELab::impl::EntitySet< typename DFBasis::GridView > EntitySet
Definition: dunefunctionsgridfunctionspace.hh:69
Dune::PDELab::Experimental::GridFunctionSpace::Ordering::blockCount
size_type blockCount() const
Same as size(), because block size is always 1.
Definition: dunefunctionsgridfunctionspace.hh:159
Dune::PDELab::Experimental::GridFunctionSpace::Traits::FiniteElementMap
FEM FiniteElementMap
Definition: dunefunctionsgridfunctionspace.hh:123
Dune::PDELab::Experimental::registerDuneFunctionsCompatibleVBE
VBE * registerDuneFunctionsCompatibleVBE(VBE *)
Dune::PDELab::Experimental::GridFunctionSpace::GridFunctionSpace
GridFunctionSpace(std::shared_ptr< DFBasis > df_basis, std::shared_ptr< CE > ce)
constructor
Definition: dunefunctionsgridfunctionspace.hh:213
Dune::PDELab::AddDataHandle< Experimental::GridFunctionSpace< DFBasis, V, CE >, U >::fixedsize
bool fixedsize(int dim, int codim) const
returns true if size per entity of given dim and codim is a constant
Definition: dunefunctionsgridfunctionspace.hh:350
Dune::PDELab::ISTL::SimpleVectorBackend
Definition: dunefunctions.hh:13
Dune::PDELab::Experimental::GridFunctionSpace::ConstraintsContainer
extract type for storing constraints
Definition: dunefunctionsgridfunctionspace.hh:191
Dune::PDELab::Experimental::GridFunctionSpace::Traits::SizeType
size_type SizeType
Definition: dunefunctionsgridfunctionspace.hh:72
Dune::PDELab::Experimental::GridFunctionSpace::isRootSpace
bool isRootSpace() const
Definition: dunefunctionsgridfunctionspace.hh:304
Dune::PDELab::AddDataHandle< Experimental::GridFunctionSpace< DFBasis, V, CE >, U >::contains
bool contains(int dim, int codim) const
returns true if data for this codim should be communicated
Definition: dunefunctionsgridfunctionspace.hh:344
Dune::PDELab::Experimental::GridFunctionSpace::Traits::FEM::_basis
std::shared_ptr< DFBasis > _basis
Definition: dunefunctionsgridfunctionspace.hh:118
Dune::PDELab::Experimental::GridFunctionSpace::Ordering::Traits::DOFIndex
typename DFBasis::MultiIndex DOFIndex
Definition: dunefunctionsgridfunctionspace.hh:134
Dune::PDELab::AddDataHandle
Definition: genericdatahandle.hh:665
Dune::PDELab::Experimental::GridFunctionSpace::Traits
export Traits class
Definition: dunefunctionsgridfunctionspace.hh:66
Dune::PDELab::Experimental::GridFunctionSpace::Traits::FEM::Traits::FiniteElement
typename DFBasis::LocalView::Tree::FiniteElement FiniteElement
Definition: dunefunctionsgridfunctionspace.hh:87
dunefunctionslocalfunctionspace.hh
Dune::PDELab::AddDataHandle< Experimental::GridFunctionSpace< DFBasis, V, CE >, U >::size
size_t size(const EntityType &e) const
Definition: dunefunctionsgridfunctionspace.hh:357
value
static const unsigned int value
Definition: gridfunctionspace/tags.hh:139
Dune::PDELab::AddDataHandle< Experimental::GridFunctionSpace< DFBasis, V, CE >, U >::AddDataHandle
AddDataHandle(const Experimental::GridFunctionSpace< DFBasis, V, CE > &gfs, const U &u)
constructor
Definition: dunefunctionsgridfunctionspace.hh:339
Dune::PDELab::Experimental::GridFunctionSpace::GridFunctionSpace
GridFunctionSpace(std::shared_ptr< DFBasis > df_basis)
Definition: dunefunctionsgridfunctionspace.hh:220
Dune::PDELab::Experimental::GridFunctionSpace< DFBasis, V, CE >::Basis
DFBasis Basis
Definition: dunefunctionsgridfunctionspace.hh:128
Dune::PDELab::Experimental::GridFunctionSpace::Traits::GridView
Dune::PDELab::impl::GridView< typename DFBasis::GridView > GridView
Definition: dunefunctionsgridfunctionspace.hh:68
Dune::PDELab::Experimental::GridFunctionSpace::name
void name(const std::string &name)
Definition: dunefunctionsgridfunctionspace.hh:299
Dune::PDELab::Experimental::GridFunctionSpace::Traits::FEM::geometryTypeToLocalView_
std::map< GeometryType, std::shared_ptr< typename DFBasis::LocalView > > geometryTypeToLocalView_
Definition: dunefunctionsgridfunctionspace.hh:120
Dune::PDELab::Experimental::GridFunctionSpace::gridView
const Traits::GridView & gridView() const
get grid view
Definition: dunefunctionsgridfunctionspace.hh:228
Dune::PDELab::Experimental::GridFunctionSpace::Traits::FEM::Traits::FiniteElementType
FiniteElement FiniteElementType
Definition: dunefunctionsgridfunctionspace.hh:88
Dune::PDELab::Experimental::GridFunctionSpace::update
void update(bool force=false)
Update the indexing information of the GridFunctionSpace.
Definition: dunefunctionsgridfunctionspace.hh:288