dune-pdelab  2.5-dev
entityindexcache.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_ENTITYINDEXCACHE_HH
4 #define DUNE_PDELAB_GRIDFUNCTIONSPACE_ENTITYINDEXCACHE_HH
5 
6 #include <dune/common/array.hh>
7 #include <dune/typetree/utility.hh>
8 
10 
11 namespace Dune {
12  namespace PDELab {
13 
14 
15  template<typename GFS, bool map_dof_indices = false>
17  {
18 
19  public:
20 
21  typedef GFS GridFunctionSpace;
22  typedef typename GFS::Ordering Ordering;
23  typedef typename Ordering::Traits::ContainerIndex ContainerIndex;
24  typedef ContainerIndex CI;
25  typedef typename Ordering::Traits::DOFIndex DOFIndex;
26  typedef DOFIndex DI;
27  typedef std::size_t size_type;
28 
29  typedef std::vector<CI> CIVector;
30  typedef std::vector<DI> DIVector;
31 
32  private:
33 
34  static const size_type leaf_count = TypeTree::TreeInfo<Ordering>::leafCount;
35 
36  public:
37 
38  typedef std::array<size_type,leaf_count + 1> Offsets;
39 
40  EntityIndexCache(const GFS& gfs)
41  : _gfs(gfs)
42  , _container_indices(gfs.maxLocalSize())
43  , _dof_indices(map_dof_indices ? gfs.maxLocalSize() : 0)
44  {
45  std::fill(_offsets.begin(),_offsets.end(),0);
46  }
47 
48  template<typename Entity>
49  void update(const Entity& e)
50  {
51  std::fill(_offsets.begin(),_offsets.end(),0);
52  if (!_gfs.dataHandleContains(Entity::codimension))
53  return;
54 
55  _gfs.dataHandleIndices(e,_container_indices,_dof_indices,_offsets.begin(),std::integral_constant<bool,map_dof_indices>());
56  }
57 
58  const DI& dofIndex(size_type i) const
59  {
60  assert(map_dof_indices);
61  return _dof_indices[i];
62  }
63 
64  const CI& containerIndex(size_type i) const
65  {
66  return _container_indices[i];
67  }
68 
69  const GridFunctionSpace& gridFunctionSpace() const
70  {
71  return _gfs;
72  }
73 
74  size_type size() const
75  {
76  return _offsets[leaf_count];
77  }
78 
79  const Offsets& offsets() const
80  {
81  return _offsets;
82  }
83 
84  private:
85 
86  const GFS& _gfs;
87  CIVector _container_indices;
88  DIVector _dof_indices;
89  Offsets _offsets;
90 
91  };
92 
93  } // namespace PDELab
94 } // namespace Dune
95 
96 #endif // DUNE_PDELAB_GRIDFUNCTIONSPACE_ENTITYINDEXCACHE_HH
Definition: entityindexcache.hh:16
std::size_t size_type
Definition: entityindexcache.hh:27
std::vector< CI > CIVector
Definition: entityindexcache.hh:29
const GridFunctionSpace & gridFunctionSpace() const
Definition: entityindexcache.hh:69
DOFIndex DI
Definition: entityindexcache.hh:26
EntityIndexCache(const GFS &gfs)
Definition: entityindexcache.hh:40
const Offsets & offsets() const
Definition: entityindexcache.hh:79
void update(const Entity &e)
Definition: entityindexcache.hh:49
GFS GridFunctionSpace
Definition: entityindexcache.hh:21
GFS::Ordering Ordering
Definition: entityindexcache.hh:22
ContainerIndex CI
Definition: entityindexcache.hh:24
const DI & dofIndex(size_type i) const
Definition: entityindexcache.hh:58
For backward compatibility – Do not use this!
Definition: adaptivity.hh:27
Ordering::Traits::DOFIndex DOFIndex
Definition: entityindexcache.hh:25
const Entity & e
Definition: localfunctionspace.hh:111
Ordering::Traits::ContainerIndex ContainerIndex
Definition: entityindexcache.hh:23
std::array< size_type, leaf_count+1 > Offsets
Definition: entityindexcache.hh:38
std::vector< DI > DIVector
Definition: entityindexcache.hh:30
const CI & containerIndex(size_type i) const
Definition: entityindexcache.hh:64
size_type size() const
Definition: entityindexcache.hh:74