dune-fem  2.6-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 #include <dune/common/visibility.hh>
10 
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;
40 
41  public:
42  CacheStorage(int numFaces, int maxTwist) :
43  mappers_(numFaces)
44  {
45  for (MapperIteratorType it = mappers_.begin();
46  it != mappers_.end(); ++it) {
47  it->resize(maxTwist + Traits::twistOffset_);
48  }
49  }
50 
51  CacheStorage(const CacheStorage& other) :
52  mappers_(other.mappers_)
53  {}
54 
55  void addMapper(const MapperType& faceMapper,
56  const MapperType& twistMapper,
57  int faceIndex, int faceTwist)
58  {
59  assert(twistMapper.size() == faceMapper.size());
60 
61  MapperType& mapper =
62  mappers_[faceIndex][faceTwist + Traits::twistOffset_];
63  mapper.resize(twistMapper.size());
64 
65  for (size_t i = 0; i < mapper.size(); ++i) {
66  mapper[i] = faceMapper[twistMapper[i]];
67  }
68 
69  }
70 
71  const MapperType& getMapper(int faceIndex, int faceTwist) const
72  {
73  assert( faceTwist + Traits::twistOffset_ >= 0 );
74  return mappers_[faceIndex][faceTwist + Traits::twistOffset_];
75  }
76 
77  private:
78  typedef std::vector<std::vector<MapperType> > MapperContainerType;
79  typedef typename MapperContainerType::iterator MapperIteratorType;
80 
81  private:
82  MapperContainerType mappers_;
83  };
84 
85 
86 
88  //-------------------------------------------------------------------
89 
90  template <class ct, int dim>
91  class CacheStorage<ct, dim, false>
92  {
93  private:
95 
96  public:
97  typedef typename Traits::MapperType MapperType;
98 
99  public:
100  explicit CacheStorage ( int numFaces )
101  : mappers_( numFaces )
102  {}
103 
104  CacheStorage ( const CacheStorage &other )
105  : mappers_( other.mappers_ )
106  {}
107 
108  void addMapper ( const MapperType &mapper, int faceIndex )
109  {
110  assert( (faceIndex >= 0) && (faceIndex < (int)mappers_.size()) );
111  mappers_[ faceIndex ] = mapper;
112  }
113 
114  const MapperType &getMapper ( int faceIndex, int faceTwist ) const
115  {
116 #ifndef NDEBUG
117  if( faceIndex >= (int)mappers_.size() )
118  std::cerr << "Error: faceIndex = " << faceIndex << " >= " << mappers_.size() << " = mappers_.size()" << std::endl;
119 #endif
120  assert( (faceIndex >= 0) && (faceIndex < (int)mappers_.size()) );
121  return mappers_[ faceIndex ];
122  }
123 
124  private:
125  typedef typename std::vector<MapperType> MapperContainerType;
126 
127  private:
128  MapperContainerType mappers_;
129  };
130 
131 
132  // CacheProvider
133  // -------------
134 
135  template< class GridPart, int codim >
137 
138  template <class GridPart>
139  class CacheProvider<GridPart, 0>
140  {
141  private:
142  enum { codim = 0 };
143  enum { dim = GridPart::dimension };
144  typedef typename GridPart::ctype ct;
146 
147  public:
149 
150  public:
151  template <class QuadratureImpl>
152  static void registerQuadrature(const QuadratureImpl& quad) {
153  // get quadrature implementation
155  }
156  };
157 
158  template <class GridPart>
159  class CacheProvider<GridPart, 1>
160  {
161  enum { codim = 1 };
162  enum { dim = GridPart::dimension };
163  typedef typename GridPart::ctype ct;
164  typedef CachingTraits<ct, dim-codim> Traits;
165 
166  // true if grid could have twists
167  static const bool hasTwists = ! Dune::Fem::GridPartCapabilities::isCartesian<GridPart>::v ;
168  public:
170  typedef typename Traits::MapperType MapperType;
172 
173  public:
174  template <class QuadratureImpl>
175  static const MapperType& getMapper(const QuadratureImpl& quadImpl,
176  GeometryType elementGeometry,
177  int faceIndex,
178  int faceTwist)
179  {
180  // get quadrature implementation
181  const QuadratureType& quad = quadImpl.ipList();
182 
183  // create key
184  const QuadratureKeyType key (elementGeometry, quad.id() );
185 
186  MapperIteratorType it = mappers_.find( key );
187 
188  if( it == mappers_.end() )
189  {
190  std::integral_constant< bool, hasTwists > i2t;
191  it = CacheProvider<GridPart, 1>::createMapper( quad, elementGeometry, i2t );
192  }
193 
194  return it->second.getMapper(faceIndex, faceTwist);
195  }
196 
197  private:
198  typedef CacheStorage< ct, dim-codim, hasTwists> CacheStorageType;
199 
200  typedef typename Traits::MapperVectorType MapperVectorType;
201  typedef std::map<const QuadratureKeyType, CacheStorageType> MapperContainerType;
202  typedef typename MapperContainerType::iterator MapperIteratorType;
203 
204  private:
205  static MapperIteratorType
206  createMapper ( const QuadratureType &quad, GeometryType elementGeometry, std::integral_constant< bool, true > );
207 
208  static MapperIteratorType
209  createMapper ( const QuadratureType &quad, GeometryType elementGeometry, std::integral_constant< bool, false > );
210 
211  private:
212  DUNE_EXPORT static MapperContainerType mappers_;
213  };
214 
215  } // namespace Fem
216 
217 } // namespace Dune
218 
219 #include "cacheprovider.cc"
220 
221 #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
void addMapper(const MapperType &faceMapper, const MapperType &twistMapper, int faceIndex, int faceTwist)
Definition: cacheprovider.hh:55
CacheStorage(const CacheStorage &other)
Definition: cacheprovider.hh:51
Traits::MapperType MapperType
Definition: cacheprovider.hh:39
CacheStorage(int numFaces, int maxTwist)
Definition: cacheprovider.hh:42
const MapperType & getMapper(int faceIndex, int faceTwist) const
Definition: cacheprovider.hh:71
const MapperType & getMapper(int faceIndex, int faceTwist) const
Definition: cacheprovider.hh:114
void addMapper(const MapperType &mapper, int faceIndex)
Definition: cacheprovider.hh:108
Traits::MapperType MapperType
Definition: cacheprovider.hh:97
CacheStorage(const CacheStorage &other)
Definition: cacheprovider.hh:104
CacheStorage(int numFaces)
Definition: cacheprovider.hh:100
Definition: cacheprovider.hh:136
static void registerQuadrature(const QuadratureImpl &quad)
Definition: cacheprovider.hh:152
Traits::QuadratureType QuadratureType
Definition: cacheprovider.hh:148
Traits::QuadratureType QuadratureType
Definition: cacheprovider.hh:169
Traits::QuadratureKeyType QuadratureKeyType
Definition: cacheprovider.hh:171
static const MapperType & getMapper(const QuadratureImpl &quadImpl, GeometryType elementGeometry, int faceIndex, int faceTwist)
Definition: cacheprovider.hh:175
Traits::MapperType MapperType
Definition: cacheprovider.hh:170
Definition: pointmapper.hh:18
Definition: pointmapper.hh:52
std::vector< size_t > MapperType
Definition: pointmapper.hh:58
Definition: pointprovider.hh:23
size_t id() const
obtain the identifier of the integration point list
Definition: quadratureimp.hh:117