dune-fem  2.8-git
twistprovider.hh
Go to the documentation of this file.
1 #ifndef DUNE_FEM_TWISTPROVIDER_HH
2 #define DUNE_FEM_TWISTPROVIDER_HH
3 
4 //- System includes
5 #include <cassert>
6 
7 #include <map>
8 #include <memory>
9 #include <vector>
10 
11 //- Dune includes
12 #include <dune/geometry/referenceelements.hh>
13 
15 
17 
18 //- Local includes
19 #include "pointmapper.hh"
20 #include "topology.hh"
21 
22 namespace Dune
23 {
24 
25  namespace Fem
26  {
27 
28  // Forward declaration
29  template <class ct, int dim>
30  class TwistProvider;
31  template <class ct, int dim>
32  class TwistMapperCreator;
33  template <class ct, int dim>
34  class TwistStorage;
35 
36 
48 
49 
52  template <class ct, int dim>
54  {
56  public:
57  typedef typename Traits::PointType PointType;
59  typedef typename Traits::MapperType MapperType;
60 
61  public:
65  explicit TwistStorage(int minTwist, int maxTwist);
66 
68  void addMapper(const MapperType& mapper, int twist);
69 
71  size_t addPoint(const PointType& points);
72 
74  const MapperType& getMapper(int twist) const;
75 
78  const PointVectorType& getPoints() const;
79 
81  int minTwist() const { return minTwist_; }
82 
84  int maxTwist() const { return maxTwist_; }
85 
86  private:
87  typedef typename Traits::MapperVectorType MapperVectorType;
88 
89  private:
90  MapperVectorType mappers_;
91  PointVectorType points_;
92 
93  int minTwist_;
94  int maxTwist_;
95  };
96 
97 
98 
99  // TiwstProvider
100  // -------------
101 
107  template <class ct, int dim>
109  {
111  public:
118 
119  public:
121  static const TwistStorageType& getTwistStorage(const QuadratureType& quad);
122 
123  private:
124  typedef std::vector< const TwistStorageType* > MapperContainerType;
125  typedef typename MapperContainerType::iterator IteratorType;
126 
127  private:
128  // singleton class holding map with storages
129  class MapperContainer
130  {
131  // instance of map
132  MapperContainerType mappers_;
133 
134  public:
136  MapperContainer() : mappers_(100, (TwistStorageType*) 0)
137  {}
138 
140  ~MapperContainer()
141  {
142  IteratorType endit = mappers_.end();
143  for(IteratorType it = mappers_.begin(); it != endit; ++it)
144  {
145  delete (*it);
146  }
147  }
148 
149  friend class Dune::Fem::Singleton< MapperContainerType >;
151  static MapperContainerType& instance()
152  {
154  }
155  };
156  };
157 
158 
159 
160  // TwistMapperStrategy
161  // -------------------
162 
164  template <class ct, int dim>
166  {
167  typedef FieldMatrix<ct, dim+1, dim> MatrixType;
168 
169  public:
171  minTwist_(minTwist),
172  maxTwist_(maxTwist)
173  {}
174 
176  virtual ~TwistMapperStrategy () = default;
177 
178  virtual MatrixType buildTransformationMatrix ( int twist ) const = 0;
179 
180  int minTwist() const { return minTwist_; }
181  int maxTwist() const { return maxTwist_; }
182 
183  private:
184  int minTwist_;
185  int maxTwist_;
186  };
187 
188 
189 
190  // TwistMapperCreator
191  // ------------------
192 
194  template <class ct, int dim>
196  {
198  public:
200  typedef typename Traits::PointType PointType;
201  typedef typename Traits::MapperType MapperType;
202  typedef FieldVector<ct, dim+1> CoordinateType;
204 
205  public:
207  TwistMapperCreator(const QuadratureType& quad);
208 
211 
213  const TwistStorageType* createStorage() const;
214 
216  int minTwist() const {
217  return helper_->minTwist();
218  }
219 
221  int maxTwist() const {
222  return helper_->maxTwist();
223  }
224 
225  private:
226  typedef typename TwistMapperStrategy<ct, dim>::MatrixType MatrixType;
227 
228  private:
230  TwistMapperCreator& operator=(const TwistMapperCreator&);
231 
232  private:
233  const QuadratureType& quad_;
235 
236  static const ct eps_;
237  };
238 
239 
240 
241  // PointTwistMapperStrategy
242  // ------------------------
243 
246  template <class ct, int dim>
248  : public TwistMapperStrategy<ct, dim>
249  {
251  typedef typename BaseType::MatrixType MatrixType;
252 
253  public:
254  PointTwistMapperStrategy(GeometryType geo)
255  : BaseType( 0, 1 )
256  {
257  assert(dim == 0);
258  }
259 
260  virtual MatrixType buildTransformationMatrix ( int twist ) const
261  {
262  const auto &refElement = Dune::ReferenceElements< ct, dim >::cube();
263 
264  assert( twist == 0 );
265  MatrixType mat;
266  mat[ 0 ] = refElement.position( 0, dim );
267  return mat;
268  }
269  };
270 
271 
272 
273  // LineTwistMapperStrategy
274  // -----------------------
275 
278  template <class ct, int dim>
280  : public TwistMapperStrategy<ct, dim>
281  {
283  typedef typename BaseType::MatrixType MatrixType;
284 
285  public:
286  LineTwistMapperStrategy(GeometryType geo)
287  : BaseType( 0, 2 )
288  {
289  assert(dim == 1);
290  }
291 
292  MatrixType buildTransformationMatrix ( int twist ) const override
293  {
294  const auto &refElement = Dune::ReferenceElements< ct, dim >::cube();
295 
296  assert( (twist == 0) || (twist == 1) );
297  MatrixType mat;
298  mat[ twist ] = refElement.position( 0, dim );
299  mat[ 1-twist ] = refElement.position( 1, dim );
300  return mat;
301  }
302  };
303 
304 
305 
306  // TriangleTwistMapperStrategy
307  // ---------------------------
308 
311  template <class ct, int dim>
313  : public TwistMapperStrategy<ct, dim>
314  {
316  typedef typename BaseType::MatrixType MatrixType;
317 
318  public:
319  TriangleTwistMapperStrategy(GeometryType geo)
320  : BaseType( -3, 3 )
321  {
322  assert(dim == 2);
323  }
324 
325  virtual MatrixType buildTransformationMatrix ( int twist ) const override
326  {
327  typedef Dune::Fem::FaceTopologyMapping<tetra> FaceTopo;
328 
329  const auto &refElement = Dune::ReferenceElements< ct, dim >::simplex();
330 
331  MatrixType mat( ct( 0 ) );
332  for (int idx = 0; idx < dim+1; ++idx)
333  mat[idx] = refElement.position( FaceTopo::twistedDuneIndex(idx, twist), dim); // dim == codim here
334  return mat;
335  }
336  };
337 
338 
339 
340  // QuadrilateralTwistMapperStrategy
341  // --------------------------------
342 
345  template <class ct, int dim>
347  : public TwistMapperStrategy<ct, dim>
348  {
350  typedef typename BaseType::MatrixType MatrixType;
351 
352  public:
354  : BaseType( -4, 4 )
355  {
356  assert(dim == 2);
357  }
358 
359  MatrixType buildTransformationMatrix ( int twist ) const override
360  {
361  typedef Dune::Fem::FaceTopologyMapping<hexa> FaceTopo;
362 
363  const auto &refElement = Dune::ReferenceElements< ct, dim >::cube();
364 
365  MatrixType mat( ct( 0 ) );
366  for (int idx = 0; idx < dim+1; ++idx)
367  mat[idx] = refElement.position( FaceTopo::twistedDuneIndex(idx, twist), dim); // dim == codim here
368  return mat;
369  }
370  };
371 
372  } // namespace Fem
373 
374 } // namespace Dune
375 
376 #include "twistprovider.cc"
377 #endif // #ifndef DUNE_FEM_TWISTPROVIDER_HH
Definition: bindguard.hh:11
Definition: pointmapper.hh:52
std::vector< MapperType > MapperVectorType
Definition: pointmapper.hh:60
QuadratureType::CoordinateType PointType
extracted types from integration point list
Definition: pointmapper.hh:56
std::vector< size_t > MapperType
Definition: pointmapper.hh:58
std::vector< PointType > PointVectorType
Definition: pointmapper.hh:57
Access point for PointMapper objects with twist information PointMapper objects get created once and ...
Definition: twistprovider.hh:109
TwistMapperCreator< ct, dim >::TwistStorageType TwistStorageType
Definition: twistprovider.hh:117
Traits::QuadratureType QuadratureType
Generic quadrature type.
Definition: twistprovider.hh:113
static const TwistStorageType & getTwistStorage(const QuadratureType &quad)
Delivers the PointMapper object for quadrature quad and twist twist.
Definition: twistprovider.cc:47
Helper class for TwistProvider which takes care of the creation process.
Definition: twistprovider.hh:196
TwistMapperCreator(const QuadratureType &quad)
Constructor.
Definition: twistprovider.cc:67
~TwistMapperCreator()
Destructor.
Definition: twistprovider.cc:98
int maxTwist() const
Largest possible twist + 1 for the quadrature's geometry.
Definition: twistprovider.hh:221
const TwistStorageType * createStorage() const
Create the actual mapper for a given twist.
Definition: twistprovider.cc:105
FieldVector< ct, dim+1 > CoordinateType
Definition: twistprovider.hh:202
Traits::MapperType MapperType
Definition: twistprovider.hh:201
int minTwist() const
Lowest possible twist for the quadrature's geometry.
Definition: twistprovider.hh:216
Traits::QuadratureType QuadratureType
Definition: twistprovider.hh:199
TwistStorage< ct, dim > TwistStorageType
Definition: twistprovider.hh:203
Traits::PointType PointType
Definition: twistprovider.hh:200
Identifies quadrature points on faces with twists For a given quadrature type and a face with a given...
Definition: twistprovider.hh:54
TwistStorage(int minTwist, int maxTwist)
Definition: twistprovider.cc:8
Traits::PointVectorType PointVectorType
Definition: twistprovider.hh:58
Traits::MapperType MapperType
Definition: twistprovider.hh:59
void addMapper(const MapperType &mapper, int twist)
Add a new mapper for a given twist.
Definition: twistprovider.cc:16
int maxTwist() const
Maximal twist + 1.
Definition: twistprovider.hh:84
const MapperType & getMapper(int twist) const
Access to a mapper.
Definition: twistprovider.cc:33
size_t addPoint(const PointType &points)
Add a point (in the case of asymmetric quadratures)
Definition: twistprovider.cc:23
const PointVectorType & getPoints() const
Definition: twistprovider.cc:40
int minTwist() const
Minimal twist.
Definition: twistprovider.hh:81
Traits::PointType PointType
Definition: twistprovider.hh:57
This class factors out all geometry dependent stuff in a strategy class.
Definition: twistprovider.hh:166
int maxTwist() const
Definition: twistprovider.hh:181
TwistMapperStrategy(int minTwist, int maxTwist)
Definition: twistprovider.hh:170
virtual ~TwistMapperStrategy()=default
virtual desctructor because of virtual functions
virtual MatrixType buildTransformationMatrix(int twist) const =0
int minTwist() const
Definition: twistprovider.hh:180
FieldMatrix< ct, dim+1, dim > MatrixType
Definition: twistprovider.hh:167
Definition: twistprovider.hh:249
PointTwistMapperStrategy(GeometryType geo)
Definition: twistprovider.hh:254
virtual MatrixType buildTransformationMatrix(int twist) const
Definition: twistprovider.hh:260
Definition: twistprovider.hh:281
MatrixType buildTransformationMatrix(int twist) const override
Definition: twistprovider.hh:292
LineTwistMapperStrategy(GeometryType geo)
Definition: twistprovider.hh:286
Definition: twistprovider.hh:314
virtual MatrixType buildTransformationMatrix(int twist) const override
Definition: twistprovider.hh:325
TriangleTwistMapperStrategy(GeometryType geo)
Definition: twistprovider.hh:319
Definition: twistprovider.hh:348
QuadrilateralTwistMapperStrategy(GeometryType geo)
Definition: twistprovider.hh:353
MatrixType buildTransformationMatrix(int twist) const override
Definition: twistprovider.hh:359
Generic implementation of an IntegrationPointList.
Definition: quadratureimp.hh:33
return singleton instance of given Object type.
Definition: singleton.hh:71
static Object & instance(Args &&... args)
return singleton instance of given Object type.
Definition: singleton.hh:101