dune-fem  2.8-git
cacheprovider.hh
Go to the documentation of this file.
1 #ifndef DUNE_FEM_CACHEPROVIDER_HH
2 #define DUNE_FEM_CACHEPROVIDER_HH
3 
4 #include <vector>
5 #include <map>
6 #include <type_traits>
7 
8 #include <dune/common/math.hh>
9 
12 
13 #include "pointmapper.hh"
14 #include "twistprovider.hh"
15 #include "pointprovider.hh"
16 
17 namespace Dune
18 {
19 
20  namespace Fem
21  {
22 
24  template <class ct, int dim, bool hasTwists>
25  class CacheStorage;
26 
27 
28 
30  //---------------------------------------------------------------
31 
32  template <class ct, int dim>
33  class CacheStorage<ct, dim, true>
34  {
35  private:
37 
38  public:
39  typedef typename Traits::MapperType MapperType;
41 
42  public:
43  CacheStorage(int numFaces, int maxTwist) :
44  mappers_(numFaces)
45  {
46  for (MapperIteratorType it = mappers_.begin();
47  it != mappers_.end(); ++it)
48  {
49  it->resize(maxTwist + Traits::twistOffset_);
50  }
51  }
52 
53  CacheStorage(const CacheStorage& other) :
54  mappers_(other.mappers_)
55  {}
56 
57  void addMapper(const MapperType& faceMapper,
58  const MapperType& interpolMapper,
59  const MapperType& twistMapper,
60  int faceIndex, int faceTwist)
61  {
62  assert(twistMapper.size() == faceMapper.size());
63 
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)
69  {
70  mapper.first[i] = faceMapper[twistMapper[i]];
71  }
72 
73  if( !interpolMapper.empty() )
74  {
75  assert(twistMapper.size() == interpolMapper.size());
76  mapper.second.resize( twistMapper.size() );
77 
78  for (size_t i = 0; i < size; ++i) {
79  mapper.second[i] = interpolMapper[twistMapper[i]];
80  }
81  }
82  }
83 
84  const MapperPairType& getMapper(int faceIndex, int faceTwist) const
85  {
86  assert( faceTwist + Traits::twistOffset_ >= 0 );
87  return mappers_[faceIndex][faceTwist + Traits::twistOffset_];
88  }
89 
90  private:
91  typedef std::vector< std::vector< MapperPairType > > MapperContainerType;
92  typedef typename MapperContainerType::iterator MapperIteratorType;
93 
94  private:
95  MapperContainerType mappers_;
96  };
97 
98 
99 
101  //-------------------------------------------------------------------
102 
103  template <class ct, int dim>
104  class CacheStorage<ct, dim, false>
105  {
106  private:
108 
109  public:
110  typedef typename Traits::MapperType MapperType;
112 
113  public:
114  explicit CacheStorage ( int numFaces )
115  : mappers_( numFaces )
116  {}
117 
118  CacheStorage ( const CacheStorage &other )
119  : mappers_( other.mappers_ )
120  {}
121 
122  void addMapper ( const MapperType &mapper,
123  const MapperType &interpolMapper,
124  int faceIndex )
125  {
126  assert( (faceIndex >= 0) && (faceIndex < (int)mappers_.size()) );
127  mappers_[ faceIndex ].first = mapper;
128  if( !interpolMapper.empty() )
129  {
130  assert( interpolMapper.size() == mapper.size() );
131  mappers_[ faceIndex ].second = interpolMapper;
132  }
133  }
134 
135  const MapperPairType &getMapper ( int faceIndex, int faceTwist ) const
136  {
137 #ifndef NDEBUG
138  if( faceIndex >= (int)mappers_.size() )
139  std::cerr << "Error: faceIndex = " << faceIndex << " >= " << mappers_.size() << " = mappers_.size()" << std::endl;
140 #endif
141  assert( (faceIndex >= 0) && (faceIndex < (int)mappers_.size()) );
142  return mappers_[ faceIndex ];
143  }
144 
145  private:
146  typedef typename std::vector< MapperPairType > MapperContainerType;
147 
148  private:
149  MapperContainerType mappers_;
150  };
151 
152 
153  // CacheProvider
154  // -------------
155 
156  template< class GridPart, int codim >
158 
159  template <class GridPart>
160  class CacheProvider<GridPart, 0>
161  {
162  private:
163  static const int codim = 0;
164  static const int dim = GridPart::dimension;
165  typedef typename GridPart::ctype ct;
167 
168  public:
170 
171  public:
172  template <class QuadratureImpl>
173  static void registerQuadrature(const QuadratureImpl& quad) {
174  // get quadrature implementation
176  }
177  };
178 
179  template <class GridPart>
180  class CacheProvider<GridPart, 1>
181  {
182  static const int codim = 1;
183  static const int dim = GridPart::dimension;
184  typedef typename GridPart::ctype ct;
185  typedef CachingTraits<ct, dim-codim> Traits;
186 
187  // true if grid could have twists
188  static const bool hasTwists = ! Dune::Fem::GridPartCapabilities::isCartesian<GridPart>::v ;
189  public:
191  typedef typename Traits::MapperType MapperType;
193 
194  typedef std::pair< MapperType, MapperType > MapperPairType;
195 
196  public:
197  template <class QuadratureImpl>
198  static const MapperPairType& getMapper(const QuadratureImpl& quadImpl,
199  GeometryType elementGeometry,
200  int faceIndex,
201  int faceTwist)
202  {
203  // get quadrature implementation
204  const QuadratureType& quad = quadImpl.ipList();
205 
206  // create key
207  const QuadratureKeyType key (elementGeometry, quad.id() );
208 
209  MapperContainerType& mappers_ = mappers();
210  MapperIteratorType it = mappers_.find( key );
211 
212  if( it == mappers_.end() )
213  {
214  std::integral_constant< bool, hasTwists > i2t;
215  it = CacheProvider<GridPart, 1>::createMapper( quad, elementGeometry, i2t );
216  }
217 
218  return it->second.getMapper(faceIndex, faceTwist);
219  }
220 
221  private:
222  typedef CacheStorage< ct, dim-codim, hasTwists> CacheStorageType;
223 
224  typedef typename Traits::MapperVectorType MapperVectorType;
225  typedef std::map<const QuadratureKeyType, CacheStorageType> MapperContainerType;
226  typedef typename MapperContainerType::iterator MapperIteratorType;
227 
228  private:
229  static MapperIteratorType
230  createMapper ( const QuadratureType &quad, GeometryType elementGeometry, std::integral_constant< bool, true > );
231 
232  static MapperIteratorType
233  createMapper ( const QuadratureType &quad, GeometryType elementGeometry, std::integral_constant< bool, false > );
234 
235  private:
236  static MapperContainerType& mappers()
237  {
239  }
240  };
241 
242  } // namespace Fem
243 
244 } // namespace Dune
245 
246 #include "cacheprovider.cc"
247 
248 #endif // #ifndef DUNE_FEM_CACHEPROVIDER_HH
Definition: bindguard.hh:11
specialize with 'true' if the grid part is cartesian (default=false)
Definition: gridpart/common/capabilities.hh:40
Storage class for mappers.
Definition: cacheprovider.hh:25
CacheStorage(const CacheStorage &other)
Definition: cacheprovider.hh:53
Traits::MapperType MapperType
Definition: cacheprovider.hh:39
CacheStorage(int numFaces, int maxTwist)
Definition: cacheprovider.hh:43
Traits::MapperPairType MapperPairType
Definition: cacheprovider.hh:40
void addMapper(const MapperType &faceMapper, const MapperType &interpolMapper, const MapperType &twistMapper, int faceIndex, int faceTwist)
Definition: cacheprovider.hh:57
const MapperPairType & getMapper(int faceIndex, int faceTwist) const
Definition: cacheprovider.hh:84
Traits::MapperType MapperType
Definition: cacheprovider.hh:110
Traits::MapperPairType MapperPairType
Definition: cacheprovider.hh:111
CacheStorage(const CacheStorage &other)
Definition: cacheprovider.hh:118
const MapperPairType & getMapper(int faceIndex, int faceTwist) const
Definition: cacheprovider.hh:135
CacheStorage(int numFaces)
Definition: cacheprovider.hh:114
void addMapper(const MapperType &mapper, const MapperType &interpolMapper, int faceIndex)
Definition: cacheprovider.hh:122
Definition: cacheprovider.hh:157
static void registerQuadrature(const QuadratureImpl &quad)
Definition: cacheprovider.hh:173
Traits::QuadratureType QuadratureType
Definition: cacheprovider.hh:169
std::pair< MapperType, MapperType > MapperPairType
Definition: cacheprovider.hh:194
Traits::QuadratureType QuadratureType
Definition: cacheprovider.hh:190
Traits::QuadratureKeyType QuadratureKeyType
Definition: cacheprovider.hh:192
Traits::MapperType MapperType
Definition: cacheprovider.hh:191
static const MapperPairType & getMapper(const QuadratureImpl &quadImpl, GeometryType elementGeometry, int faceIndex, int faceTwist)
Definition: cacheprovider.hh:198
Definition: pointmapper.hh:18
Definition: pointmapper.hh:52
std::pair< MapperType, MapperType > MapperPairType
Definition: pointmapper.hh:59
std::vector< size_t > MapperType
Definition: pointmapper.hh:58
Definition: pointprovider.hh:24
Generic implementation of an IntegrationPointList.
Definition: quadratureimp.hh:33
size_t id() const
obtain the identifier of the integration point list
Definition: quadratureimp.hh:122
static Object & instance(Args &&... args)
return singleton instance of given Object type.
Definition: singleton.hh:101