3#ifndef DUNE_PDELAB_GRIDFUNCTIONSPACE_DUNEFUNCTIONSLFSINDEXCACHE_HH
4#define DUNE_PDELAB_GRIDFUNCTIONSPACE_DUNEFUNCTIONSLFSINDEXCACHE_HH
6#include <dune/pdelab/gridfunctionspace/lfsindexcache.hh>
7#include <dune/pdelab/gridfunctionspace/dunefunctionsgridfunctionspace.hh>
12 template<
typename LFS,
typename C>
13 class LFSIndexCacheBase<LFS,C,Experimental::DuneFunctionsCacheTag, false>
18 DOF_NONCONSTRAINED = 0,
19 DOF_CONSTRAINED = 1<<0,
25 using LocalFunctionSpace = LFS;
26 using GFS =
typename LFS::Traits::GridFunctionSpace;
27 using Ordering =
typename GFS::Ordering;
28 using DOFIndex =
typename Ordering::Traits::DOFIndex;
30 using ContainerIndex =
typename Ordering::Traits::ContainerIndex;
31 using CI = ContainerIndex;
32 using size_type = std::size_t;
34 typedef std::vector<CI> CIVector;
35 typedef std::unordered_map<DI,CI> CIMap;
37 typedef std::unordered_map<const CI*,std::pair<size_type,bool> > InverseMap;
39 struct ConstraintsEntry
40 :
public std::pair<const CI*,typename C::mapped_type::mapped_type>
42 typedef CI ContainerIndex;
43 typedef typename C::mapped_type::mapped_type Weight;
45 const ContainerIndex& containerIndex()
const
47 return *(this->first);
50 const Weight& weight()
const
58 typedef std::vector<ConstraintsEntry> ConstraintsVector;
59 typedef typename ConstraintsVector::const_iterator ConstraintsIterator;
61 LFSIndexCacheBase(
const LFS& lfs,
const C&
constraints,
bool enable_constraints_caching)
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)
75 DI dofIndex(size_type i)
const
77 return _lfs.dofIndex(i);
80 CI containerIndex(size_type i)
const
82 return _lfs.containerIndex(i);
85 CI containerIndex(
const DI& i)
const
90 bool isConstrained(size_type i)
const
92 return _dof_flags[i] & DOF_CONSTRAINED;
95 bool isDirichletConstraint(size_type i)
const
97 return _dof_flags[i] & DOF_DIRICHLET;
100 ConstraintsIterator constraintsBegin(size_type i)
const
102 assert(isConstrained(i));
103 return _constraints_iterators[i].first;
106 ConstraintsIterator constraintsEnd(size_type i)
const
108 assert(isConstrained(i));
109 return _constraints_iterators[i].second;
112 const LocalFunctionSpace& localFunctionSpace()
const
117 size_type size()
const
122 bool constraintsCachingEnabled()
const
124 return _enable_constraints_caching;
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;
139 const C& _gfs_constraints;
144 template<
typename LFS>
145 class LFSIndexCacheBase<LFS,EmptyTransformation,Experimental::DuneFunctionsCacheTag, false>
150 using LocalFunctionSpace = LFS;
151 using GFS =
typename LFS::Traits::GridFunctionSpace;
152 using Ordering =
typename GFS::Ordering;
153 using DOFIndex =
typename Ordering::Traits::DOFIndex;
155 using ContainerIndex =
typename Ordering::Traits::ContainerIndex;
156 using CI = ContainerIndex;
157 using size_type = std::size_t;
159 struct ConstraintsEntry
160 :
public std::pair<const CI*,double>
162 typedef CI ContainerIndex;
163 typedef double Weight;
165 const ContainerIndex& containerIndex()
const
167 return *(this->first);
170 const Weight& weight()
const
176 typedef std::vector<ConstraintsEntry> ConstraintsVector;
177 typedef typename ConstraintsVector::const_iterator ConstraintsIterator;
179 typedef std::vector<CI> CIVector;
180 typedef std::unordered_map<DI,CI> CIMap;
182 explicit LFSIndexCacheBase(
const LFS& lfs)
187 LFSIndexCacheBase(
const LFS& lfs,
const C& c,
bool enable_constraints_caching)
191 DI dofIndex(size_type i)
const
193 return _lfs.dofIndex(i);
196 CI containerIndex(size_type i)
const
198 return _lfs.containerIndex(i);
201 CI containerIndex(
const DI& i)
const
203 return _lfs.containerIndex(i);
206 bool isConstrained(size_type i)
const
211 bool isDirichletConstraint(size_type i)
const
216 ConstraintsIterator constraintsBegin(size_type i)
const
218 return _constraints.begin();
221 ConstraintsIterator constraintsEnd(size_type i)
const
223 return _constraints.end();
226 const LocalFunctionSpace& localFunctionSpace()
const
231 size_type size()
const
236 bool constraintsCachingEnabled()
const
247 CIVector _container_indices;
248 mutable CIMap _container_index_map;
249 const ConstraintsVector _constraints;
void constraints(const GFS &gfs, CG &cg, const bool verbose=false)
construct constraints
Definition: constraints.hh:749
Dune namespace.
Definition: alignedallocator.hh:11