dune-pdelab  2.5-dev
dunefunctionslfsindexcache.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_DUNEFUNCTIONSLFSINDEXCACHE_HH
4 #define DUNE_PDELAB_GRIDFUNCTIONSPACE_DUNEFUNCTIONSLFSINDEXCACHE_HH
5 
8 
9 namespace Dune {
10  namespace PDELab {
11 
12  template<typename LFS, typename C>
13  class LFSIndexCacheBase<LFS,C,Experimental::DuneFunctionsCacheTag, false>
14  {
15 
16  enum DOFFlags
17  {
18  DOF_NONCONSTRAINED = 0,
19  DOF_CONSTRAINED = 1<<0,
20  DOF_DIRICHLET = 1<<1
21  };
22 
23  public:
24 
25  using LocalFunctionSpace = LFS;
26  using GFS = typename LFS::Traits::GridFunctionSpace;
27  using Ordering = typename GFS::Ordering;
28  using DOFIndex = typename Ordering::Traits::DOFIndex;
29  using DI = DOFIndex;
30  using ContainerIndex = typename Ordering::Traits::ContainerIndex;
31  using CI = ContainerIndex;
32  using size_type = std::size_t;
33 
34  typedef std::vector<CI> CIVector;
35  typedef std::unordered_map<DI,CI> CIMap;
36 
37  typedef std::unordered_map<const CI*,std::pair<size_type,bool> > InverseMap;
38 
39  struct ConstraintsEntry
40  : public std::pair<const CI*,typename C::mapped_type::mapped_type>
41  {
42  typedef CI ContainerIndex;
43  typedef typename C::mapped_type::mapped_type Weight;
44 
46  {
47  return *(this->first);
48  }
49 
50  const Weight& weight() const
51  {
52  return this->second;
53  }
54  };
55 
56  //typedef std::pair<CI,typename C::mapped_type::mapped_type> ConstraintsEntry;
57 
58  typedef std::vector<ConstraintsEntry> ConstraintsVector;
59  typedef typename ConstraintsVector::const_iterator ConstraintsIterator;
60 
61  LFSIndexCacheBase(const LFS& lfs, const C& constraints, bool enable_constraints_caching)
62  : _lfs(lfs)
63  , _enable_constraints_caching(enable_constraints_caching)
64  , _container_indices(lfs.maxSize())
65  , _dof_flags(lfs.maxSize(),0)
66  , _constraints_iterators(lfs.maxSize())
67  , _inverse_cache_built(false)
68  , _gfs_constraints(constraints)
69  {
70  }
71 
72  void update()
73  {}
74 
76  {
77  return _lfs.dofIndex(i);
78  }
79 
81  {
82  return _lfs.dofIndex(i);
83  }
84 
85  CI containerIndex(const DI& i) const
86  {
87  return i;
88  }
89 
90  bool isConstrained(size_type i) const
91  {
92  return _dof_flags[i] & DOF_CONSTRAINED;
93  }
94 
96  {
97  return _dof_flags[i] & DOF_DIRICHLET;
98  }
99 
101  {
102  assert(isConstrained(i));
103  return _constraints_iterators[i].first;
104  }
105 
107  {
108  assert(isConstrained(i));
109  return _constraints_iterators[i].second;
110  }
111 
113  {
114  return _lfs;
115  }
116 
117  size_type size() const
118  {
119  return _lfs.size();
120  }
121 
123  {
124  return _enable_constraints_caching;
125  }
126 
127  private:
128 
129  const LFS& _lfs;
130  const bool _enable_constraints_caching;
131  CIVector _container_indices;
132  std::vector<unsigned char> _dof_flags;
133  std::vector<std::pair<ConstraintsIterator,ConstraintsIterator> > _constraints_iterators;
134  mutable CIMap _container_index_map;
135  ConstraintsVector _constraints;
136  mutable bool _inverse_cache_built;
137  mutable InverseMap _inverse_map;
138 
139  const C& _gfs_constraints;
140 
141  };
142 
143 
144  template<typename LFS>
145  class LFSIndexCacheBase<LFS,EmptyTransformation,Experimental::DuneFunctionsCacheTag, false>
146  {
147 
148  public:
149 
150  using LocalFunctionSpace = LFS;
151  using GFS = typename LFS::Traits::GridFunctionSpace;
152  using Ordering = typename GFS::Ordering;
153  using DOFIndex = typename Ordering::Traits::DOFIndex;
154  using DI = DOFIndex;
155  using ContainerIndex = typename Ordering::Traits::ContainerIndex;
157  using size_type = std::size_t;
158 
159  struct ConstraintsEntry
160  : public std::pair<const CI*,double>
161  {
163  typedef double Weight;
164 
166  {
167  return *(this->first);
168  }
169 
170  const Weight& weight() const
171  {
172  return this->second;
173  }
174  };
175 
176  typedef std::vector<ConstraintsEntry> ConstraintsVector;
177  typedef typename ConstraintsVector::const_iterator ConstraintsIterator;
178 
179  typedef std::vector<CI> CIVector;
180  typedef std::unordered_map<DI,CI> CIMap;
181 
182  explicit LFSIndexCacheBase(const LFS& lfs)
183  : _lfs(lfs)
184  {}
185 
186  template<typename C>
187  LFSIndexCacheBase(const LFS& lfs, const C& c, bool enable_constraints_caching)
188  : _lfs(lfs)
189  {}
190 
192  {
193  return _lfs.dofIndex(i);
194  }
195 
197  {
198  return _lfs.dofIndex(i);
199  }
200 
201  CI containerIndex(const DI& i) const
202  {
203  return i;
204  }
205 
206  bool isConstrained(size_type i) const
207  {
208  return false;
209  }
210 
212  {
213  return false;
214  }
215 
217  {
218  return _constraints.begin();
219  }
220 
222  {
223  return _constraints.end();
224  }
225 
227  {
228  return _lfs;
229  }
230 
231  size_type size() const
232  {
233  return _lfs.size();
234  }
235 
237  {
238  return false;
239  }
240 
241  void update()
242  {}
243 
244  private:
245 
246  const LFS& _lfs;
247  CIVector _container_indices;
248  mutable CIMap _container_index_map;
249  const ConstraintsVector _constraints;
250 
251  };
252 
253  } // namespace PDELab
254 } // namespace Dune
255 
256 #endif // DUNE_PDELAB_GRIDFUNCTIONSPACE_DUNEFUNCTIONSLFSINDEXCACHE_HH
Dune::PDELab::LFSIndexCacheBase< LFS, C, Experimental::DuneFunctionsCacheTag, false >::GFS
typename LFS::Traits::GridFunctionSpace GFS
Definition: dunefunctionslfsindexcache.hh:26
Dune::PDELab::LFSIndexCacheBase< LFS, C, Experimental::DuneFunctionsCacheTag, false >::DI
DOFIndex DI
Definition: dunefunctionslfsindexcache.hh:29
Dune::PDELab::LFSIndexCacheBase< LFS, EmptyTransformation, Experimental::DuneFunctionsCacheTag, false >::ConstraintsEntry::containerIndex
const ContainerIndex & containerIndex() const
Definition: dunefunctionslfsindexcache.hh:165
Dune::PDELab::LFSIndexCacheBase::CIVector
std::vector< CI > CIVector
Definition: lfsindexcache.hh:266
Dune::PDELab::LFSIndexCacheBase< LFS, EmptyTransformation, Experimental::DuneFunctionsCacheTag, false >::GFS
typename LFS::Traits::GridFunctionSpace GFS
Definition: dunefunctionslfsindexcache.hh:151
Dune::PDELab::LFSIndexCacheBase< LFS, EmptyTransformation, Experimental::DuneFunctionsCacheTag, false >::isDirichletConstraint
bool isDirichletConstraint(size_type i) const
Definition: dunefunctionslfsindexcache.hh:211
Dune::PDELab::LFSIndexCacheBase< LFS, C, Experimental::DuneFunctionsCacheTag, false >::ConstraintsVector
std::vector< ConstraintsEntry > ConstraintsVector
Definition: dunefunctionslfsindexcache.hh:58
Dune::PDELab::LFSIndexCacheBase< LFS, C, Experimental::DuneFunctionsCacheTag, false >::ConstraintsEntry::Weight
C::mapped_type::mapped_type Weight
Definition: dunefunctionslfsindexcache.hh:43
Dune::PDELab::LFSIndexCacheBase< LFS, EmptyTransformation, Experimental::DuneFunctionsCacheTag, false >::ConstraintsEntry::Weight
double Weight
Definition: dunefunctionslfsindexcache.hh:163
lfsindexcache.hh
Dune::PDELab::LFSIndexCacheBase< LFS, C, Experimental::DuneFunctionsCacheTag, false >::CIVector
std::vector< CI > CIVector
Definition: dunefunctionslfsindexcache.hh:34
Dune::PDELab::LFSIndexCacheBase< LFS, C, Experimental::DuneFunctionsCacheTag, false >::CI
ContainerIndex CI
Definition: dunefunctionslfsindexcache.hh:31
Dune::PDELab::LFSIndexCacheBase< LFS, EmptyTransformation, Experimental::DuneFunctionsCacheTag, false >::containerIndex
CI containerIndex(size_type i) const
Definition: dunefunctionslfsindexcache.hh:196
Dune::PDELab::LFSIndexCacheBase< LFS, EmptyTransformation, Experimental::DuneFunctionsCacheTag, false >::constraintsEnd
ConstraintsIterator constraintsEnd(size_type i) const
Definition: dunefunctionslfsindexcache.hh:221
Dune::PDELab::LFSIndexCacheBase< LFS, C, Experimental::DuneFunctionsCacheTag, false >::constraintsEnd
ConstraintsIterator constraintsEnd(size_type i) const
Definition: dunefunctionslfsindexcache.hh:106
Dune::PDELab::LFSIndexCacheBase< LFS, C, Experimental::DuneFunctionsCacheTag, false >::isDirichletConstraint
bool isDirichletConstraint(size_type i) const
Definition: dunefunctionslfsindexcache.hh:95
Dune
For backward compatibility – Do not use this!
Definition: adaptivity.hh:28
Dune::PDELab::LFSIndexCacheBase< LFS, EmptyTransformation, Experimental::DuneFunctionsCacheTag, false >::LocalFunctionSpace
LFS LocalFunctionSpace
Definition: dunefunctionslfsindexcache.hh:150
Dune::PDELab::LFSIndexCacheBase< LFS, EmptyTransformation, Experimental::DuneFunctionsCacheTag, false >::DOFIndex
typename Ordering::Traits::DOFIndex DOFIndex
Definition: dunefunctionslfsindexcache.hh:153
Dune::PDELab::LFSIndexCacheBase< LFS, EmptyTransformation, Experimental::DuneFunctionsCacheTag, false >::ContainerIndex
typename Ordering::Traits::ContainerIndex ContainerIndex
Definition: dunefunctionslfsindexcache.hh:155
Dune::PDELab::LFSIndexCacheBase< LFS, EmptyTransformation, Experimental::DuneFunctionsCacheTag, false >::ConstraintsVector
std::vector< ConstraintsEntry > ConstraintsVector
Definition: dunefunctionslfsindexcache.hh:176
Dune::PDELab::LFSIndexCacheBase< LFS, C, Experimental::DuneFunctionsCacheTag, false >::containerIndex
CI containerIndex(const DI &i) const
Definition: dunefunctionslfsindexcache.hh:85
Dune::PDELab::LFSIndexCacheBase< LFS, C, Experimental::DuneFunctionsCacheTag, false >::ConstraintsIterator
ConstraintsVector::const_iterator ConstraintsIterator
Definition: dunefunctionslfsindexcache.hh:59
Dune::PDELab::LFSIndexCacheBase< LFS, EmptyTransformation, Experimental::DuneFunctionsCacheTag, false >::DI
DOFIndex DI
Definition: dunefunctionslfsindexcache.hh:154
Dune::PDELab::LFSIndexCacheBase< LFS, EmptyTransformation, Experimental::DuneFunctionsCacheTag, false >::CIVector
std::vector< CI > CIVector
Definition: dunefunctionslfsindexcache.hh:179
Dune::PDELab::LFSIndexCacheBase::CIMap
std::unordered_map< DI, CI > CIMap
Definition: lfsindexcache.hh:267
Dune::PDELab::LFSIndexCacheBase< LFS, C, Experimental::DuneFunctionsCacheTag, false >::LocalFunctionSpace
LFS LocalFunctionSpace
Definition: dunefunctionslfsindexcache.hh:25
Dune::PDELab::LFSIndexCacheBase::DOFIndex
Ordering::Traits::DOFIndex DOFIndex
Definition: lfsindexcache.hh:262
Dune::PDELab::LFSIndexCacheBase< LFS, C, Experimental::DuneFunctionsCacheTag, false >::isConstrained
bool isConstrained(size_type i) const
Definition: dunefunctionslfsindexcache.hh:90
Dune::PDELab::LFSIndexCacheBase::ConstraintsVector
std::vector< ConstraintsEntry > ConstraintsVector
Definition: lfsindexcache.hh:290
Dune::PDELab::LFSIndexCacheBase< LFS, C, Experimental::DuneFunctionsCacheTag, false >::size_type
std::size_t size_type
Definition: dunefunctionslfsindexcache.hh:32
Dune::PDELab::LFSIndexCacheBase< LFS, C, Experimental::DuneFunctionsCacheTag, false >::constraintsCachingEnabled
bool constraintsCachingEnabled() const
Definition: dunefunctionslfsindexcache.hh:122
Dune::PDELab::LFSIndexCacheBase< LFS, EmptyTransformation, Experimental::DuneFunctionsCacheTag, false >::localFunctionSpace
const LocalFunctionSpace & localFunctionSpace() const
Definition: dunefunctionslfsindexcache.hh:226
Dune::PDELab::LFSIndexCacheBase< LFS, EmptyTransformation, Experimental::DuneFunctionsCacheTag, false >::ConstraintsIterator
ConstraintsVector::const_iterator ConstraintsIterator
Definition: dunefunctionslfsindexcache.hh:177
Dune::PDELab::LFSIndexCacheBase< LFS, C, Experimental::DuneFunctionsCacheTag, false >::localFunctionSpace
const LocalFunctionSpace & localFunctionSpace() const
Definition: dunefunctionslfsindexcache.hh:112
Dune::PDELab::LFSIndexCacheBase< LFS, EmptyTransformation, Experimental::DuneFunctionsCacheTag, false >::Ordering
typename GFS::Ordering Ordering
Definition: dunefunctionslfsindexcache.hh:152
Dune::PDELab::LFSIndexCacheBase::InverseMap
std::unordered_map< const CI *, std::pair< size_type, bool > > InverseMap
Definition: lfsindexcache.hh:269
Dune::PDELab::LFSIndexCacheBase< LFS, EmptyTransformation, Experimental::DuneFunctionsCacheTag, false >::LFSIndexCacheBase
LFSIndexCacheBase(const LFS &lfs, const C &c, bool enable_constraints_caching)
Definition: dunefunctionslfsindexcache.hh:187
Dune::PDELab::LFSIndexCacheBase< LFS, C, Experimental::DuneFunctionsCacheTag, false >::ConstraintsEntry::ContainerIndex
CI ContainerIndex
Definition: dunefunctionslfsindexcache.hh:42
Dune::PDELab::LFSIndexCacheBase< LFS, EmptyTransformation, Experimental::DuneFunctionsCacheTag, false >::containerIndex
CI containerIndex(const DI &i) const
Definition: dunefunctionslfsindexcache.hh:201
Dune::PDELab::constraints
void constraints(const GFS &gfs, CG &cg, const bool verbose=false)
construct constraints
Definition: constraints.hh:751
Dune::PDELab::LFSIndexCacheBase< LFS, EmptyTransformation, Experimental::DuneFunctionsCacheTag, false >::constraintsBegin
ConstraintsIterator constraintsBegin(size_type i) const
Definition: dunefunctionslfsindexcache.hh:216
Dune::PDELab::LFSIndexCacheBase< LFS, EmptyTransformation, Experimental::DuneFunctionsCacheTag, false >::size_type
std::size_t size_type
Definition: dunefunctionslfsindexcache.hh:157
Dune::PDELab::LFSIndexCacheBase< LFS, EmptyTransformation, Experimental::DuneFunctionsCacheTag, false >::dofIndex
DI dofIndex(size_type i) const
Definition: dunefunctionslfsindexcache.hh:191
Dune::PDELab::LFSIndexCacheBase< LFS, EmptyTransformation, Experimental::DuneFunctionsCacheTag, false >::constraintsCachingEnabled
bool constraintsCachingEnabled() const
Definition: dunefunctionslfsindexcache.hh:236
Dune::PDELab::LFSIndexCacheBase< LFS, C, Experimental::DuneFunctionsCacheTag, false >::ConstraintsEntry::weight
const Weight & weight() const
Definition: dunefunctionslfsindexcache.hh:50
Dune::PDELab::LFSIndexCacheBase< LFS, C, Experimental::DuneFunctionsCacheTag, false >::ContainerIndex
typename Ordering::Traits::ContainerIndex ContainerIndex
Definition: dunefunctionslfsindexcache.hh:30
Dune::PDELab::LFSIndexCacheBase< LFS, EmptyTransformation, Experimental::DuneFunctionsCacheTag, false >::ConstraintsEntry::weight
const Weight & weight() const
Definition: dunefunctionslfsindexcache.hh:170
Dune::PDELab::LFSIndexCacheBase< LFS, C, Experimental::DuneFunctionsCacheTag, false >::InverseMap
std::unordered_map< const CI *, std::pair< size_type, bool > > InverseMap
Definition: dunefunctionslfsindexcache.hh:37
Dune::PDELab::LFSIndexCacheBase< LFS, C, Experimental::DuneFunctionsCacheTag, false >::constraintsBegin
ConstraintsIterator constraintsBegin(size_type i) const
Definition: dunefunctionslfsindexcache.hh:100
Dune::PDELab::EmptyTransformation
Definition: constraintstransformation.hh:111
Dune::PDELab::LFSIndexCacheBase< LFS, EmptyTransformation, Experimental::DuneFunctionsCacheTag, false >::ConstraintsEntry::ContainerIndex
CI ContainerIndex
Definition: dunefunctionslfsindexcache.hh:162
Dune::PDELab::LFSIndexCacheBase< LFS, C, Experimental::DuneFunctionsCacheTag, false >::DOFIndex
typename Ordering::Traits::DOFIndex DOFIndex
Definition: dunefunctionslfsindexcache.hh:28
Dune::PDELab::LFSIndexCacheBase< LFS, EmptyTransformation, Experimental::DuneFunctionsCacheTag, false >::LFSIndexCacheBase
LFSIndexCacheBase(const LFS &lfs)
Definition: dunefunctionslfsindexcache.hh:182
Dune::PDELab::LFSIndexCacheBase< LFS, EmptyTransformation, Experimental::DuneFunctionsCacheTag, false >::CI
ContainerIndex CI
Definition: dunefunctionslfsindexcache.hh:156
Dune::PDELab::LFSIndexCacheBase< LFS, EmptyTransformation, Experimental::DuneFunctionsCacheTag, false >::CIMap
std::unordered_map< DI, CI > CIMap
Definition: dunefunctionslfsindexcache.hh:180
Dune::PDELab::LFSIndexCacheBase
Definition: lfsindexcache.hh:244
Dune::PDELab::LFSIndexCacheBase< LFS, C, Experimental::DuneFunctionsCacheTag, false >::ConstraintsEntry::containerIndex
const ContainerIndex & containerIndex() const
Definition: dunefunctionslfsindexcache.hh:45
Dune::PDELab::LFSIndexCacheBase< LFS, EmptyTransformation, Experimental::DuneFunctionsCacheTag, false >::size
size_type size() const
Definition: dunefunctionslfsindexcache.hh:231
Dune::PDELab::LFSIndexCacheBase< LFS, C, Experimental::DuneFunctionsCacheTag, false >::size
size_type size() const
Definition: dunefunctionslfsindexcache.hh:117
Dune::PDELab::LFSIndexCacheBase< LFS, EmptyTransformation, Experimental::DuneFunctionsCacheTag, false >::update
void update()
Definition: dunefunctionslfsindexcache.hh:241
Dune::PDELab::LFSIndexCacheBase< LFS, C, Experimental::DuneFunctionsCacheTag, false >::CIMap
std::unordered_map< DI, CI > CIMap
Definition: dunefunctionslfsindexcache.hh:35
Dune::PDELab::LFSIndexCacheBase< LFS, C, Experimental::DuneFunctionsCacheTag, false >::dofIndex
DI dofIndex(size_type i) const
Definition: dunefunctionslfsindexcache.hh:75
Dune::PDELab::LFSIndexCacheBase< LFS, EmptyTransformation, Experimental::DuneFunctionsCacheTag, false >::isConstrained
bool isConstrained(size_type i) const
Definition: dunefunctionslfsindexcache.hh:206
Dune::PDELab::LFSIndexCacheBase< LFS, C, Experimental::DuneFunctionsCacheTag, false >::Ordering
typename GFS::Ordering Ordering
Definition: dunefunctionslfsindexcache.hh:27
Dune::PDELab::LFSIndexCacheBase< LFS, C, Experimental::DuneFunctionsCacheTag, false >::LFSIndexCacheBase
LFSIndexCacheBase(const LFS &lfs, const C &constraints, bool enable_constraints_caching)
Definition: dunefunctionslfsindexcache.hh:61
Dune::PDELab::LFSIndexCacheBase::ContainerIndex
Ordering::Traits::ContainerIndex ContainerIndex
Definition: lfsindexcache.hh:260
Dune::PDELab::LFSIndexCacheBase< LFS, C, Experimental::DuneFunctionsCacheTag, false >::update
void update()
Definition: dunefunctionslfsindexcache.hh:72
Dune::PDELab::LFSIndexCacheBase::isConstrained
bool isConstrained(size_type i) const
Definition: lfsindexcache.hh:410
dunefunctionsgridfunctionspace.hh
Dune::PDELab::LFSIndexCacheBase< LFS, C, Experimental::DuneFunctionsCacheTag, false >::containerIndex
CI containerIndex(size_type i) const
Definition: dunefunctionslfsindexcache.hh:80