1#ifndef DUNE_FEM_CACHEPROVIDER_HH
2#define DUNE_FEM_CACHEPROVIDER_HH
10#include <dune/fem/gridpart/common/capabilities.hh>
11#include <dune/fem/storage/singleton.hh>
13#include "pointmapper.hh"
14#include "twistprovider.hh"
15#include "pointprovider.hh"
24 template <
class ct,
int dim,
bool hasTwists>
32 template <
class ct,
int dim>
36 typedef CachingTraits<ct, dim> Traits;
39 typedef typename Traits::MapperType MapperType;
40 typedef typename Traits::MapperPairType MapperPairType;
46 for (MapperIteratorType it = mappers_.begin();
47 it != mappers_.end(); ++it)
49 it->resize(maxTwist + Traits::twistOffset_);
54 mappers_(other.mappers_)
57 void addMapper(
const MapperType& faceMapper,
58 const MapperType& interpolMapper,
59 const MapperType& twistMapper,
60 int faceIndex,
int faceTwist)
62 assert(twistMapper.size() == faceMapper.size());
64 MapperPairType& mapper =
65 mappers_[faceIndex][faceTwist + Traits::twistOffset_];
66 const size_t size = twistMapper.size();
67 mapper.first.resize(
size );
68 for (
size_t i = 0; i <
size; ++i)
70 mapper.first[i] = faceMapper[twistMapper[i]];
73 if( !interpolMapper.empty() )
75 assert(twistMapper.size() == interpolMapper.size());
76 mapper.second.resize( twistMapper.size() );
78 for (
size_t i = 0; i <
size; ++i) {
79 mapper.second[i] = interpolMapper[twistMapper[i]];
84 const MapperPairType& getMapper(
int faceIndex,
int faceTwist)
const
86 assert( faceTwist + Traits::twistOffset_ >= 0 );
87 return mappers_[faceIndex][faceTwist + Traits::twistOffset_];
91 typedef std::vector< std::vector< MapperPairType > > MapperContainerType;
92 typedef typename MapperContainerType::iterator MapperIteratorType;
95 MapperContainerType mappers_;
103 template <
class ct,
int dim>
107 typedef CachingTraits<ct, dim> Traits;
110 typedef typename Traits::MapperType MapperType;
111 typedef typename Traits::MapperPairType MapperPairType;
115 : mappers_( numFaces )
119 : mappers_( other.mappers_ )
122 void addMapper (
const MapperType &mapper,
123 const MapperType &interpolMapper,
126 assert( (faceIndex >= 0) && (faceIndex < (
int)mappers_.size()) );
127 mappers_[ faceIndex ].first = mapper;
128 if( !interpolMapper.empty() )
130 assert( interpolMapper.size() == mapper.size() );
131 mappers_[ faceIndex ].second = interpolMapper;
135 const MapperPairType &getMapper (
int faceIndex,
int faceTwist )
const
138 if( faceIndex >= (
int)mappers_.size() )
139 std::cerr <<
"Error: faceIndex = " << faceIndex <<
" >= " << mappers_.size() <<
" = mappers_.size()" << std::endl;
141 assert( (faceIndex >= 0) && (faceIndex < (
int)mappers_.size()) );
142 return mappers_[ faceIndex ];
146 typedef typename std::vector< MapperPairType > MapperContainerType;
149 MapperContainerType mappers_;
156 template<
class Gr
idPart,
int codim >
159 template <
class Gr
idPart>
160 class CacheProvider<GridPart, 0>
163 static const int codim = 0;
164 static const int dim = GridPart::dimension;
165 typedef typename GridPart::ctype ct;
166 typedef CachingTraits<ct, dim> Traits;
169 typedef typename Traits::QuadratureType QuadratureType;
172 template <
class QuadratureImpl>
173 static void registerQuadrature(
const QuadratureImpl& quad) {
175 PointProvider<ct, dim, codim>::registerQuadrature(quad.ipList());
179 template <
class Gr
idPart>
180 class CacheProvider<GridPart, 1>
182 typedef CacheProvider<GridPart, 1> ThisType;
184 static const int codim = 1;
185 static const int dim = GridPart::dimension;
186 typedef typename GridPart::ctype ct;
187 typedef CachingTraits<ct, dim-codim> Traits;
192 typedef typename Traits::QuadratureType QuadratureType;
193 typedef typename Traits::MapperType MapperType;
194 typedef typename Traits::QuadratureKeyType QuadratureKeyType;
196 typedef std::pair< MapperType, MapperType > MapperPairType;
199 typedef CacheStorage< ct, dim-codim, hasTwists> CacheStorageType;
200 typedef typename Traits::MapperVectorType MapperVectorType;
202 typedef std::unordered_map<const QuadratureKeyType, CacheStorageType> MapperContainerType;
203 typedef typename MapperContainerType::iterator MapperIteratorType;
206 template <
class QuadratureImpl>
207 const MapperPairType& getMapperImpl(
const QuadratureImpl& quadImpl,
208 const GeometryType elementGeometry,
211 const bool registerQuadrature =
true )
214 const QuadratureType& quad = quadImpl.ipList();
217 const QuadratureKeyType key (elementGeometry, quad.id() );
219 MapperIteratorType it = mappers_.find( key );
221 assert( ! registerQuadrature ? it != mappers_.end() :
true );
222 if( registerQuadrature && (it == mappers_.end()) )
224 std::integral_constant< bool, hasTwists > i2t;
225 it = CacheProvider<GridPart, 1>::createMapper( quad, elementGeometry, i2t, mappers_ );
228 return it->second.getMapper(faceIndex, faceTwist);
231 template <
class QuadratureImpl>
232 static const MapperPairType& getMapper(
const QuadratureImpl& quadImpl,
233 const GeometryType elementGeometry,
237 return instance().getMapperImpl( quadImpl, elementGeometry, faceIndex, faceTwist );
241 static MapperIteratorType
242 createMapper (
const QuadratureType &quad, GeometryType elementGeometry, std::integral_constant< bool, true >, MapperContainerType& );
244 static MapperIteratorType
245 createMapper (
const QuadratureType &quad, GeometryType elementGeometry, std::integral_constant< bool, false >, MapperContainerType& );
248 MapperContainerType mappers_;
251 static ThisType& instance()
261#include "cacheprovider.cc"
Storage class for mappers.
Definition: cacheprovider.hh:25
static DUNE_EXPORT Object & instance(Args &&... args)
return singleton instance of given Object type.
Definition: singleton.hh:123
Some useful basic math stuff.
Dune namespace.
Definition: alignedallocator.hh:13
constexpr std::integral_constant< std::size_t, sizeof...(II)> size(std::integer_sequence< T, II... >)
Return the size of the sequence.
Definition: integersequence.hh:75
specialize with 'true' if the grid part is cartesian (default=false)
Definition: capabilities.hh:40