dune-fem  2.4.1-rc
quadprovider.hh
Go to the documentation of this file.
1 #ifndef DUNE_FEM_QUADPROVIDER_HH
2 #define DUNE_FEM_QUADPROVIDER_HH
3 
8 
9 namespace Dune
10 {
11 
12  namespace Fem
13  {
14 
24  template< unsigned int dummy >
26  {
27  private:
29  template< class QuadImp >
30  class QuadratureStorage
31  {
32  public:
33  typedef QuadImp QuadType;
34 
35  typedef QuadType *QuadPtr;
36 
37  protected:
38  DynamicArray< QuadPtr > storage_;
39  //std :: vector< QuadPtr > storage_;
40 
41  public:
42  inline QuadratureStorage ()
43  : storage_( QuadType :: maxOrder() + 1, (QuadPtr)0 )
44  {
45  }
46 
47  inline ~QuadratureStorage ()
48  {
49  for( unsigned int i = 0; i < storage_.size(); ++i )
50  delete storage_[ i ];
51  }
52 
53  inline QuadImp &getQuadrature( const GeometryType &geometry,
54  unsigned int order )
55  {
56  assert( order < storage_.size() );
57 
58  QuadPtr& quadPtr = storage_[ order ];
59  if( quadPtr == 0 )
60  {
61  // make sure we work in single thread mode when quadrature is created
63  quadPtr = new QuadImp( geometry, order, IdProvider :: instance().newId() );
64  }
65  assert( quadPtr != 0 );
66  return *quadPtr;
67  }
68  }; // end class QuadratureStorage
69 
70  public:
76  template< class QuadImp >
77  static const QuadImp &provideQuad( const GeometryType &geometry,
78  unsigned int order )
79  {
80  static QuadratureStorage< QuadImp > storage;
81  return storage.getQuadrature( geometry, order );
82  }
83  };
84 
85 
86 
102  template< typename FieldImp, int dim, template< class, int > class QuadratureTraits >
104  {
105  public:
106  typedef FieldImp FieldType;
107 
108  enum { dimension = dim };
109 
110  private:
112 
113  typedef QuadratureTraits< FieldType, dimension > QuadratureTraitsType;
114 
115  public:
117  typedef typename QuadratureTraitsType :: CubeQuadratureType CubeQuadratureType;
118 
120  typedef typename QuadratureTraitsType :: IntegrationPointListType
122 
124  static const IntegrationPointListType &getQuadrature( const GeometryType &geometry,
125  int order )
126  {
127  assert( geometry.isCube() );
128  return QuadCreator< 0 > :: template provideQuad< CubeQuadratureType > ( geometry, order );
129  }
131  static const IntegrationPointListType &getQuadrature( const GeometryType &geometry,
132  const GeometryType &elementGeometry,
133  int order )
134  {
135  return getQuadrature( geometry, order );
136  }
137 
138  private:
139  // forbid creation
141 
142  // forbid copying
143  QuadratureProvider( const ThisType& );
144 
145  // forbid assignment
146  QuadratureProvider &operator=( const ThisType& );
147  };
148 
149 
150 
152  template< typename FieldImp, template< class, int > class QuadratureTraits >
153  class QuadratureProvider< FieldImp, 0, QuadratureTraits >
154  {
155  public:
156  typedef FieldImp FieldType;
157 
158  enum { dimension = 0 };
159 
160  private:
162 
163  typedef QuadratureTraits< FieldType, dimension > QuadratureTraitsType;
164 
165  public:
167  typedef typename QuadratureTraitsType :: PointQuadratureType PointQuadratureType;
168 
170  typedef typename QuadratureTraitsType :: IntegrationPointListType IntegrationPointListType;
171 
172  public:
174  static const IntegrationPointListType &getQuadrature( const GeometryType &geometry,
175  int order )
176  {
177  assert( geometry.isCube() || geometry.isSimplex() );
178  assert( order >= 0 );
179  //return QuadCreator< 0 > :: template provideQuad< PointQuadratureType > ( geometry, order );
180  static PointQuadratureType quad( geometry,
181  order,
182  IdProvider ::instance().newId());
183  return quad;
184  }
185 
187  static const IntegrationPointListType &getQuadrature( const GeometryType &geometry,
188  const GeometryType &elementGeometry,
189  int order )
190  {
191  return getQuadrature(geometry, order);
192  }
193 
194  private:
195  // forbid creation
197 
198  // forbid copying
199  QuadratureProvider( const ThisType& );
200 
201  // forbid assignment
202  QuadratureProvider &operator=( const ThisType& );
203  };
204 
205 
206 
208  template< class FieldImp, template< class, int > class QuadratureTraits >
209  class QuadratureProvider< FieldImp, 1, QuadratureTraits >
210  {
211  public:
212  typedef FieldImp FieldType;
213 
214  enum { dimension = 1 };
215 
216  private:
218 
219  typedef QuadratureTraits< FieldType, dimension > QuadratureTraitsType;
220 
221  public:
223  typedef typename QuadratureTraitsType :: LineQuadratureType LineQuadratureType;
224 
226  typedef typename QuadratureTraitsType :: IntegrationPointListType IntegrationPointListType;
227 
228  public:
230  static const IntegrationPointListType &getQuadrature( const GeometryType &geometry,
231  int order )
232  {
233  assert( geometry.isCube() || geometry.isSimplex() );
234  assert( order >= 0 );
235  return QuadCreator< 0 > :: template provideQuad< LineQuadratureType > ( geometry, order );
236  }
237 
239  static const IntegrationPointListType &getQuadrature( const GeometryType &geometry,
240  const GeometryType &elementGeometry,
241  int order )
242  {
243  assert( geometry.isCube() || geometry.isSimplex() );
244  assert( order >= 0 );
245  // we need here to distinguish between the basic types
246  // otherwise the this won't work for UGGrid
247  return ( elementGeometry.isSimplex() ) ?
248  QuadCreator< 0 > :: template provideQuad< LineQuadratureType > ( geometry, order ) :
249  QuadCreator< 1 > :: template provideQuad< LineQuadratureType > ( geometry, order ) ;
250  }
251 
252  private:
253  // forbid creation
255 
256  // forbid copying
257  QuadratureProvider( const ThisType& );
258 
259  // forbid assignment
260  QuadratureProvider &operator=( const ThisType& );
261  };
262 
263 
264 
266  template< class FieldImp, template< class, int > class QuadratureTraits >
267  class QuadratureProvider< FieldImp, 2, QuadratureTraits >
268  {
269  public:
270  typedef FieldImp FieldType;
271 
272  enum { dimension = 2 };
273 
274  private:
276 
277  typedef QuadratureTraits< FieldType, dimension > QuadratureTraitsType;
278 
279  public:
281  typedef typename QuadratureTraitsType :: SimplexQuadratureType SimplexQuadratureType;
283  typedef typename QuadratureTraitsType :: CubeQuadratureType CubeQuadratureType;
284 
286  typedef typename QuadratureTraitsType :: IntegrationPointListType IntegrationPointListType;
287 
288  public:
290  static const IntegrationPointListType &getQuadrature( const GeometryType &geometry,
291  int order )
292  {
293  assert( geometry.isCube() || geometry.isSimplex() );
294  assert( order >= 0 );
295 
296  if( geometry.isSimplex() )
297  {
298  return QuadCreator< 0 > ::
299  template provideQuad< SimplexQuadratureType > ( geometry, order );
300  }
301  else
302  {
303  return QuadCreator< 1 > ::
304  template provideQuad< CubeQuadratureType > ( geometry, order ) ;
305  }
306  }
307 
309  static const IntegrationPointListType &getQuadrature( const GeometryType &geometry,
310  const GeometryType &elementGeometry,
311  int order )
312  {
313  assert( geometry.isCube() || geometry.isSimplex() );
314  assert( order >= 0 );
315 
316  // if geometry is simplex return simplex quadrature
317  if ( geometry.isSimplex() )
318  {
319  // check element geometry to provide quadratures with different ids
320  if( elementGeometry.isSimplex() )
321  return QuadCreator< 0 > :: template provideQuad< SimplexQuadratureType > ( geometry, order ) ;
322  else if( elementGeometry.isCube() )
323  return QuadCreator< 1 > :: template provideQuad< SimplexQuadratureType > ( geometry, order ) ;
324  else if( elementGeometry.isPrism() )
325  return QuadCreator< 2 > :: template provideQuad< SimplexQuadratureType > ( geometry, order ) ;
326  else if( elementGeometry.isPyramid() )
327  return QuadCreator< 3 > :: template provideQuad< SimplexQuadratureType > ( geometry, order ) ;
328  else
329  DUNE_THROW( RangeError, "Element type not available for dimension 3" );
330  }
331  else
332  {
333  // return cube quadrature
334  // check element geometry to provide quadratures with different ids
335  if( elementGeometry.isSimplex() )
336  return QuadCreator< 4 > :: template provideQuad< CubeQuadratureType > ( geometry, order ) ;
337  else if( elementGeometry.isCube() )
338  return QuadCreator< 5 > :: template provideQuad< CubeQuadratureType > ( geometry, order ) ;
339  else if( elementGeometry.isPrism() )
340  return QuadCreator< 6 > :: template provideQuad< CubeQuadratureType > ( geometry, order ) ;
341  else if( elementGeometry.isPyramid() )
342  return QuadCreator< 7 > :: template provideQuad< CubeQuadratureType > ( geometry, order ) ;
343  else
344  DUNE_THROW( RangeError, "Element type not available for dimension 3" );
345  }
346 
347  DUNE_THROW( RangeError, "Element type not available for dimension 2" );
348  // dummy return
349  return QuadCreator< 0 > ::
350  template provideQuad< SimplexQuadratureType >( geometry, 0 );
351  }
352 
353  private:
354  // forbid creation
356 
357  // forbid copying
358  QuadratureProvider( const ThisType& );
359 
360  // forbid assignment
361  QuadratureProvider &operator=( const ThisType& );
362  };
363 
364 
365 
367  template< class FieldImp, template< class, int > class QuadratureTraits >
368  class QuadratureProvider< FieldImp, 3, QuadratureTraits >
369  {
370  public:
371  typedef FieldImp FieldType;
372 
373  enum { dimension = 3 };
374 
375  private:
377 
378  typedef QuadratureTraits< FieldType, dimension > QuadratureTraitsType;
379 
380  public:
382  typedef typename QuadratureTraitsType :: SimplexQuadratureType SimplexQuadratureType;
384  typedef typename QuadratureTraitsType :: CubeQuadratureType CubeQuadratureType;
386  typedef typename QuadratureTraitsType :: PrismQuadratureType PrismQuadratureType;
388  typedef typename QuadratureTraitsType :: PyramidQuadratureType PyramidQuadratureType;
389 
391  typedef typename QuadratureTraitsType :: IntegrationPointListType IntegrationPointListType;
392 
393  public:
395  static const IntegrationPointListType &getQuadrature( const GeometryType &geometry,
396  int order )
397  {
398  assert( geometry.isCube() || geometry.isSimplex()
399  || geometry.isPrism() || geometry.isPyramid() );
400  assert( order >= 0 );
401 
402  if( geometry.isSimplex() )
403  return QuadCreator< 0 > :: template provideQuad< SimplexQuadratureType >
404  ( geometry, order );
405  if( geometry.isCube() )
406  return QuadCreator< 1 > :: template provideQuad< CubeQuadratureType >
407  ( geometry, order );
408 
409  if( geometry.isPrism() )
410  return QuadCreator< 2 > :: template provideQuad< PrismQuadratureType >
411  ( geometry, order );
412  if( geometry.isPyramid() )
413  return QuadCreator< 3 > :: template provideQuad< PyramidQuadratureType >
414  ( geometry, order );
415 
416  DUNE_THROW( RangeError, "Element type not available for dimension 3" );
417  // dummy return
418  return QuadCreator< 0 > :: template provideQuad< SimplexQuadratureType >
419  ( geometry, 0 );
420  }
421 
422  static const IntegrationPointListType &getQuadrature( const GeometryType &geometry,
423  const GeometryType &elementGeometry,
424  int order )
425  {
426  DUNE_THROW( RangeError, "QuadProvider::getQuadrature not implemented for 3d face quadratures!" );
427  // dummy return
428  return QuadCreator< 0 > :: template provideQuad< SimplexQuadratureType >
429  ( geometry, 0 );
430  }
431  private:
432  // forbid creation
434 
435  // forbid copying
436  QuadratureProvider( const ThisType& );
437 
438  // forbid assignment
439  QuadratureProvider &operator=( const ThisType& );
440  };
441 
442  } // namespace Fem
443 
444 } // namespace Dune
445 
446 #endif // #ifndef DUNE_FEM_QUADPROVIDER_HH
static IdProvider & instance()
Access to the singleton object.
Definition: idprovider.hh:17
static const IntegrationPointListType & getQuadrature(const GeometryType &geometry, int order)
Access to the quadrature implementations.
Definition: quadprovider.hh:395
unsigned int size() const
Definition: array.hh:617
static const IntegrationPointListType & getQuadrature(const GeometryType &geometry, int order)
Access to the quadrature implementations.
Definition: quadprovider.hh:230
QuadratureTraitsType::IntegrationPointListType IntegrationPointListType
type of integration point list implementation
Definition: quadprovider.hh:226
FieldImp FieldType
Definition: quadprovider.hh:371
static const IntegrationPointListType & getQuadrature(const GeometryType &geometry, const GeometryType &elementGeometry, int order)
Access to the quadrature implementations.
Definition: quadprovider.hh:131
QuadratureTraitsType::PyramidQuadratureType PyramidQuadratureType
type of pyramid quadrature
Definition: quadprovider.hh:388
QuadratureTraitsType::SimplexQuadratureType SimplexQuadratureType
type of simplex quadrature
Definition: quadprovider.hh:281
QuadratureTraitsType::LineQuadratureType LineQuadratureType
type of line quadrature
Definition: quadprovider.hh:223
QuadratureTraitsType::PointQuadratureType PointQuadratureType
type of point quadrature
Definition: quadprovider.hh:167
static const IntegrationPointListType & getQuadrature(const GeometryType &geometry, int order)
Access to the quadrature implementations.
Definition: quadprovider.hh:290
QuadratureTraitsType::CubeQuadratureType CubeQuadratureType
type of cube quadrature
Definition: quadprovider.hh:283
static const IntegrationPointListType & getQuadrature(const GeometryType &geometry, const GeometryType &elementGeometry, int order)
Access to the quadrature implementations.
Definition: quadprovider.hh:239
FieldImp FieldType
Definition: quadprovider.hh:270
QuadratureTraitsType::CubeQuadratureType CubeQuadratureType
type of cube quadrature
Definition: quadprovider.hh:384
QuadratureTraitsType::IntegrationPointListType IntegrationPointListType
type of integration point list implementation
Definition: quadprovider.hh:391
QuadratureTraitsType::IntegrationPointListType IntegrationPointListType
type of integration point list implementation
Definition: quadprovider.hh:121
static const IntegrationPointListType & getQuadrature(const GeometryType &geometry, int order)
Access to the quadrature implementations.
Definition: quadprovider.hh:124
QuadratureTraitsType::IntegrationPointListType IntegrationPointListType
type of integration point list implementation
Definition: quadprovider.hh:170
Definition: coordinate.hh:4
QuadratureTraitsType::SimplexQuadratureType SimplexQuadratureType
type of simplex quadrature
Definition: quadprovider.hh:382
the actual quadrature storage
Definition: quadprovider.hh:25
static const IntegrationPointListType & getQuadrature(const GeometryType &geometry, const GeometryType &elementGeometry, int order)
Access to the quadrature implementations.
Definition: quadprovider.hh:309
FieldImp FieldType
Definition: quadprovider.hh:212
QuadratureTraitsType::PrismQuadratureType PrismQuadratureType
type of prims quadrature
Definition: quadprovider.hh:386
QuadratureTraitsType::IntegrationPointListType IntegrationPointListType
type of integration point list implementation
Definition: quadprovider.hh:286
static const QuadImp & provideQuad(const GeometryType &geometry, unsigned int order)
provide quadrature
Definition: quadprovider.hh:77
FieldImp FieldType
Definition: quadprovider.hh:156
static const IntegrationPointListType & getQuadrature(const GeometryType &geometry, const GeometryType &elementGeometry, int order)
Definition: quadprovider.hh:422
static const IntegrationPointListType & getQuadrature(const GeometryType &geometry, const GeometryType &elementGeometry, int order)
Access to the quadrature implementations.
Definition: quadprovider.hh:187
provide a single instance pool of quadratures
Definition: quadprovider.hh:103
FieldImp FieldType
Definition: quadprovider.hh:106
static bool singleThreadMode()
returns true if program is operating on one thread currently
Definition: threadmanager.hh:217
static const IntegrationPointListType & getQuadrature(const GeometryType &geometry, int order)
Access to the quadrature implementations.
Definition: quadprovider.hh:174
QuadratureTraitsType::CubeQuadratureType CubeQuadratureType
type for cube quadrature
Definition: quadprovider.hh:117