dune-fem  2.4.1-rc
evaluatecaller.hh
Go to the documentation of this file.
1 #ifndef DUNE_FEM_EVALUATECALLER_HH
2 #define DUNE_FEM_EVALUATECALLER_HH
3 
4 #include <cstdlib>
5 #include <vector>
6 
7 #include <dune/common/exceptions.hh>
9 
10 #ifdef USE_BASEFUNCTIONSET_CODEGEN
11 #define CODEGEN_INCLUDEMAXNUMS
12 // include max number definitions
13 #include <autogeneratedcode.hh>
14 #undef CODEGEN_INCLUDEMAXNUMS
15 #endif
16 
18 //
19 // pre-define these values for faster compilation
20 //
22 #ifndef MAX_NUMBER_OF_QUAD_POINTS
23 #define MAX_NUMBER_OF_QUAD_POINTS 20
24 #endif
25 
26 #ifndef MAX_NUMBER_OF_BASE_FCT
27 #define MAX_NUMBER_OF_BASE_FCT 20
28 #endif
29 
30 #ifndef MIN_NUMBER_OF_QUAD_POINTS
31 #define MIN_NUMBER_OF_QUAD_POINTS 1
32 #endif
33 
34 #ifndef MIN_NUMBER_OF_BASE_FCT
35 #define MIN_NUMBER_OF_BASE_FCT 1
36 #endif
37 
38 namespace Dune
39 {
40 
41  namespace Fem
42  {
43 
44  // empty class for specialization of evaluation classes in basefunctionsets.hh
45  class EmptyGeometry {};
46 
47  // forward declaration
48  template <class Traits,
49  int quadNop,
50  int numBaseFct >
52 
53  template< class QuadratureImp,
54  class FactorImp,
55  class LocalDofVectorImp,
56  class GeometryImp = EmptyGeometry >
58  {
60  typedef FactorImp FactorType;
61  typedef LocalDofVectorImp LocalDofVectorType;
62  typedef GeometryImp Geometry;
63  };
64 
65  template <class Traits,
66  class BaseFunctionSet,
67  class RangeVectorImp>
69  {
70  typedef Traits BaseTraits;
71  typedef typename Traits :: QuadratureType QuadratureType ;
72  typedef typename Traits :: FactorType FactorType ;
73  typedef typename Traits :: LocalDofVectorType LocalDofVectorType ;
74  typedef typename Traits :: Geometry Geometry ;
75 
76  typedef BaseFunctionSet BaseFunctionSetType;
77  typedef RangeVectorImp RangeVectorType;
78  };
79 
80  //- base function evaluation interface
81  template <class Traits>
83  {
85  protected:
86  enum { maxNumBaseFunctions = MAX_NUMBER_OF_BASE_FCT };
87  enum { maxQuadratures = 50 };
88  enum { maxQuadNop = MAX_NUMBER_OF_QUAD_POINTS };
89 
91  {
92  protected:
93  typedef ThisType* ValueType ;
94  std::vector< ValueType > storage_;
95  public:
97  storage_( maxQuadratures, (ThisType* ) 0 )
98  {}
99 
101  {
102  for( size_t i = 0; i<storage_.size(); ++i )
103  delete storage_[ i ];
104  }
105 
106  ValueType& operator [] ( const int i ) { return storage_[ i ]; }
107  const ValueType& operator [] ( const int i ) const { return storage_[ i ]; }
108  };
109 
110 
112 
113  public:
114  typedef typename Traits :: QuadratureType QuadratureType ;
115  typedef typename Traits :: FactorType FactorType ;
116  typedef typename Traits :: LocalDofVectorType LocalDofVectorType ;
117  typedef typename Traits :: Geometry Geometry ;
118 
120 
121  virtual void* storageAddress () const = 0;
122 
123  virtual void axpyRanges( const QuadratureType&,
124  const FactorType& ,
125  LocalDofVectorType & ) const = 0;
126 
127  virtual void evaluateRanges( const QuadratureType& quad,
128  const LocalDofVectorType & dofs,
129  FactorType& factors) const = 0;
130 
131  virtual void axpyJacobians( const QuadratureType&,
132  const Geometry&,
133  const FactorType& ,
134  LocalDofVectorType & ) const = 0;
135 
136  virtual void evaluateJacobians( const QuadratureType&,
137  const Geometry&,
138  const LocalDofVectorType&,
139  FactorType&) const = 0;
140 
141  template < class BaseFunctionSet, class Storage >
142  static const ThisType& storage(const BaseFunctionSet& baseSet,
143  const Storage& dataCache,
144  const QuadratureType& quad)
145  {
146  // assert that max numbers are big enough
147  assert( baseSet.numDifferentBaseFunctions() <= maxNumBaseFunctions );
148  assert( quad.nop() <= maxQuadNop );
149  assert( quad.id() < maxQuadratures );
150 
151  // static vector holding all evaluator instances
152  static ThreadSafeValue< EvaluatorStorage > evaluatorStorage;
153  EvaluatorStorage& evaluators = *evaluatorStorage;
154 
155  // check if object already created
156  const size_t quadId = quad.id();
157  if( evaluators[ quadId ] == 0 )
158  {
160  // create appropriate evaluator
161  evaluators[ quadId ] =
163  :: create( dataCache , quad.nop(), baseSet.numDifferentBaseFunctions() );
164  }
165 
166  // make sure the storage is the same
167  assert( ((void *) &dataCache) == evaluators[ quadId ]->storageAddress() );
168 
169  // return reference to evaluator
170  return *(evaluators[ quadId ]);
171  }
172  };
173 
174  template <class Traits,
175  int quadNop,
176  int numBaseFct >
178  : public EvaluateCallerInterface< typename Traits :: BaseTraits >
179  {
180  protected:
181  typedef typename Traits :: BaseFunctionSetType BaseFunctionSetType;
182  typedef typename Traits :: QuadratureType QuadratureType ;
183  typedef typename Traits :: FactorType FactorType ;
184  typedef typename Traits :: LocalDofVectorType LocalDofVectorType ;
185  typedef typename Traits :: Geometry Geometry ;
186  typedef typename Traits :: RangeVectorType RangeVectorType ;
187 
188  enum { dimRange = BaseFunctionSetType :: dimRange };
191 
192  const RangeVectorType& rangeStorage_;
193 
194  public:
195  // type of interface class
196  typedef BaseType InterfaceType;
197 
198  EvaluateRealImplementation( const RangeVectorType& rangeStorage )
199  : rangeStorage_( rangeStorage )
200  {}
201 
202  virtual void* storageAddress() const { return (void *) &rangeStorage_ ; }
203 
204  virtual void axpyRanges( const QuadratureType& quad,
205  const FactorType& rangeFactors,
206  LocalDofVectorType & dofs ) const
207  {
208  BaseFunctionSetType :: template AxpyRanges
209  < BaseFunctionSetType, Geometry, dimRange, quadNop, numBaseFct > :: axpy
210  ( quad, rangeStorage_, rangeFactors, dofs );
211  }
212 
213  virtual void axpyJacobians( const QuadratureType& quad,
214  const Geometry& geometry,
215  const FactorType& jacFactors,
216  LocalDofVectorType& dofs) const
217  {
218  BaseFunctionSetType :: template AxpyJacobians
219  < BaseFunctionSetType, Geometry, dimRange, quadNop, numBaseFct > :: axpy
220  ( quad, geometry, rangeStorage_, jacFactors, dofs );
221  }
222 
223  virtual void evaluateRanges( const QuadratureType& quad,
224  const LocalDofVectorType & dofs,
225  FactorType& rangeFactors) const
226  {
227  BaseFunctionSetType :: template EvaluateRanges
228  < BaseFunctionSetType, Geometry, dimRange, quadNop, numBaseFct >
229  :: eval ( quad, rangeStorage_, dofs, rangeFactors );
230  }
231 
232  virtual void evaluateJacobians( const QuadratureType& quad,
233  const Geometry& geometry,
234  const LocalDofVectorType& dofs,
235  FactorType& jacFactors) const
236  {
237  BaseFunctionSetType :: template EvaluateJacobians
238  < BaseFunctionSetType, Geometry, dimRange, quadNop, numBaseFct > :: eval
239  ( quad, geometry, rangeStorage_, dofs, jacFactors );
240  }
241 
242  static InterfaceType* create( const RangeVectorType& rangeStorage )
243  {
244  return new ThisType( rangeStorage );
245  }
246  };
247 
248  // The default EvaluateImplementation is empty
249  // to create this has to be specified and derived from EvaluateCallerDefault
250  template <class Traits,
251  int quadNop,
252  int numBaseFct >
254  : public EvaluateCallerInterface< typename Traits :: BaseTraits >
255  {
256  protected:
257  typedef typename Traits :: BaseFunctionSetType BaseFunctionSetType;
258  typedef typename Traits :: QuadratureType QuadratureType ;
259  typedef typename Traits :: FactorType FactorType ;
260  typedef typename Traits :: LocalDofVectorType LocalDofVectorType ;
261  typedef typename Traits :: Geometry Geometry ;
262  typedef typename Traits :: RangeVectorType RangeVectorType ;
263 
265 
267  public:
268  // type of interface class
269  typedef BaseType InterfaceType;
270 
271  EvaluateImplementation( const RangeVectorType& rangeStorage )
272  {}
273 
274  virtual void axpyRanges( const QuadratureType& quad,
275  const FactorType& rangeFactors,
276  LocalDofVectorType & dofs ) const
277  {
278  abort();
279  }
280 
281  virtual void axpyJacobians( const QuadratureType& quad,
282  const Geometry& geometry,
283  const FactorType& jacFactors,
284  LocalDofVectorType& dofs) const
285  {
286  abort();
287  }
288 
289  virtual void evaluateRanges( const QuadratureType& quad,
290  const LocalDofVectorType & dofs,
291  FactorType& rangeFactors) const
292  {
293  abort();
294  }
295 
296  virtual void evaluateJacobians( const QuadratureType& quad,
297  const Geometry& geometry,
298  const LocalDofVectorType& dofs,
299  FactorType& jacFactors) const
300  {
301  abort();
302  }
303 
304  static InterfaceType* create( const RangeVectorType& )
305  {
306  DUNE_THROW(NotImplemented,"EvaluateImplementation for < " << quadNop << " , " << numBaseFct << " > not created!");
307  return (InterfaceType*) 0;
308  }
309  };
310 
311  template <class Traits,
312  int quadNop,
313  int numBaseFct >
314  class EvaluateCaller
315  {
316  protected:
317  typedef typename Traits :: RangeVectorType RangeVectorType ;
319  public:
320  static InterfaceType* createObj( const RangeVectorType& rangeStorage,
321  const size_t numbase )
322  {
323  if( numBaseFct == numbase )
325  else
327  }
328 
329  static InterfaceType* create( const RangeVectorType& rangeStorage,
330  const size_t quadnop, const size_t numbase )
331  {
332  if( quadNop == quadnop )
333  return EvaluateCaller< Traits, quadNop, numBaseFct > :: createObj( rangeStorage, numbase );
334  else
335  return EvaluateCaller< Traits, quadNop - 1, numBaseFct > :: create( rangeStorage, quadnop, numbase );
336  }
337  };
338 
339  template <class Traits,
340  int numBaseFct >
341  class EvaluateCaller< Traits, MIN_NUMBER_OF_QUAD_POINTS, numBaseFct >
342  {
343  protected:
344  enum { quadNop = MIN_NUMBER_OF_QUAD_POINTS };
345  typedef typename Traits :: RangeVectorType RangeVectorType ;
347  public:
348  static InterfaceType* createObj( const RangeVectorType& rangeStorage,
349  const size_t numbase )
350  {
351  if( numBaseFct == numbase )
353  else
355  }
356 
357  static InterfaceType* create( const RangeVectorType& rangeStorage,
358  const size_t quadnop, const size_t numbase )
359  {
360  if( quadNop == quadnop )
361  return EvaluateCaller< Traits, quadNop, numBaseFct > :: createObj( rangeStorage, numbase );
362  else
363  {
364  abort();
365  }
366  }
367  };
368 
369  template <class Traits,
370  int quadNop>
371  class EvaluateCaller< Traits, quadNop, MIN_NUMBER_OF_BASE_FCT >
372  {
373  protected:
374  enum { numBaseFct = MIN_NUMBER_OF_BASE_FCT };
375  typedef typename Traits :: RangeVectorType RangeVectorType ;
377  public:
378  static InterfaceType* createObj( const RangeVectorType& rangeStorage,
379  const size_t numbase )
380  {
381  if( numBaseFct == numbase )
383  else
384  abort();
385  }
386 
387  static InterfaceType* create( const RangeVectorType& rangeStorage,
388  const size_t quadnop, const size_t numbase )
389  {
390  if( quadNop == quadnop )
391  return EvaluateCaller< Traits, quadNop, numBaseFct > :: createObj( rangeStorage, numbase );
392  else
393  {
394  return EvaluateCaller< Traits, quadNop - 1, numBaseFct > :: create( rangeStorage, quadnop, numbase );
395  }
396  }
397  };
398 
399  template <class Traits>
401  {
402  protected:
403  enum { quadNop = MIN_NUMBER_OF_QUAD_POINTS };
404  enum { numBaseFct = MIN_NUMBER_OF_BASE_FCT };
405  typedef typename Traits :: RangeVectorType RangeVectorType ;
407  public:
408  static InterfaceType* createObj( const RangeVectorType& rangeStorage,
409  const size_t numbase )
410  {
411  if( numBaseFct == numbase )
413  else
414  abort();
415  }
416 
417  static InterfaceType* create( const RangeVectorType& rangeStorage,
418  const size_t quadnop, const size_t numbase )
419  {
420  if( quadNop == quadnop )
421  return EvaluateCaller< Traits, quadNop, numBaseFct > :: createObj( rangeStorage, numbase );
422  else
423  {
424  abort();
425  }
426  }
427  };
428 
429 #ifdef USE_BASEFUNCTIONSET_CODEGEN
430 #define CODEGEN_INCLUDEEVALCALLERS
431  // include specializations of EvaluateImplementation
432 #include <autogeneratedcode.hh>
433 #undef CODEGEN_INCLUDEEVALCALLERS
434 #endif
435 
436  } // namespace Fem
437 
438 } // namespace Dune
439 
440 #endif // #ifndef DUNE_FEM_EVALUATECALLER_HH
Traits::BaseFunctionSetType BaseFunctionSetType
Definition: evaluatecaller.hh:257
Traits::Geometry Geometry
Definition: evaluatecaller.hh:74
QuadratureImp QuadratureType
Definition: evaluatecaller.hh:59
Definition: evaluatecaller.hh:68
Traits::FactorType FactorType
Definition: evaluatecaller.hh:115
static InterfaceType * create(const RangeVectorType &)
Definition: evaluatecaller.hh:304
Definition: evaluatecaller.hh:177
virtual void axpyRanges(const QuadratureType &quad, const FactorType &rangeFactors, LocalDofVectorType &dofs) const
Definition: evaluatecaller.hh:204
static InterfaceType * createObj(const RangeVectorType &rangeStorage, const size_t numbase)
Definition: evaluatecaller.hh:348
EvaluateCallerInterface< typename Traits::BaseTraits > InterfaceType
Definition: evaluatecaller.hh:318
Traits::FactorType FactorType
Definition: evaluatecaller.hh:259
Traits::LocalDofVectorType LocalDofVectorType
Definition: evaluatecaller.hh:116
Traits::Geometry Geometry
Definition: evaluatecaller.hh:117
#define MIN_NUMBER_OF_QUAD_POINTS
Definition: evaluatecaller.hh:31
EvaluateRealImplementation< Traits, quadNop, numBaseFct > ThisType
Definition: evaluatecaller.hh:189
Definition: evaluatecaller.hh:51
BaseType InterfaceType
Definition: evaluatecaller.hh:269
EvaluateCallerInterface< typename Traits::BaseTraits > InterfaceType
Definition: evaluatecaller.hh:406
virtual void axpyJacobians(const QuadratureType &quad, const Geometry &geometry, const FactorType &jacFactors, LocalDofVectorType &dofs) const
Definition: evaluatecaller.hh:281
virtual void evaluateJacobians(const QuadratureType &quad, const Geometry &geometry, const LocalDofVectorType &dofs, FactorType &jacFactors) const
Definition: evaluatecaller.hh:296
Traits::LocalDofVectorType LocalDofVectorType
Definition: evaluatecaller.hh:260
Traits::RangeVectorType RangeVectorType
Definition: evaluatecaller.hh:375
virtual void * storageAddress() const
Definition: evaluatecaller.hh:202
Definition: evaluatecaller.hh:57
#define MIN_NUMBER_OF_BASE_FCT
Definition: evaluatecaller.hh:35
Traits::QuadratureType QuadratureType
Definition: evaluatecaller.hh:182
const RangeVectorType & rangeStorage_
Definition: evaluatecaller.hh:192
#define MAX_NUMBER_OF_QUAD_POINTS
Definition: evaluatecaller.hh:23
EvaluateImplementation< Traits, quadNop, numBaseFct > ThisType
Definition: evaluatecaller.hh:264
Traits::BaseFunctionSetType BaseFunctionSetType
Definition: evaluatecaller.hh:181
void axpy(const T &a, const T &x, T &y)
Definition: space/basisfunctionset/functor.hh:37
Traits::QuadratureType QuadratureType
Definition: evaluatecaller.hh:71
Traits::QuadratureType QuadratureType
Definition: evaluatecaller.hh:258
static InterfaceType * create(const RangeVectorType &rangeStorage)
Definition: evaluatecaller.hh:242
Traits::FactorType FactorType
Definition: evaluatecaller.hh:72
virtual void evaluateJacobians(const QuadratureType &quad, const Geometry &geometry, const LocalDofVectorType &dofs, FactorType &jacFactors) const
Definition: evaluatecaller.hh:232
virtual void axpyJacobians(const QuadratureType &quad, const Geometry &geometry, const FactorType &jacFactors, LocalDofVectorType &dofs) const
Definition: evaluatecaller.hh:213
#define MAX_NUMBER_OF_BASE_FCT
Definition: evaluatecaller.hh:27
static const ThisType & storage(const BaseFunctionSet &baseSet, const Storage &dataCache, const QuadratureType &quad)
Definition: evaluatecaller.hh:142
Traits::QuadratureType QuadratureType
Definition: evaluatecaller.hh:114
static InterfaceType * create(const RangeVectorType &rangeStorage, const size_t quadnop, const size_t numbase)
Definition: evaluatecaller.hh:329
Definition: evaluatecaller.hh:253
EvaluateCallerInterface()
Definition: evaluatecaller.hh:111
Definition: coordinate.hh:4
LocalDofVectorImp LocalDofVectorType
Definition: evaluatecaller.hh:61
Traits::LocalDofVectorType LocalDofVectorType
Definition: evaluatecaller.hh:73
~EvaluatorStorage()
Definition: evaluatecaller.hh:100
Definition: evaluatecaller.hh:45
Traits::Geometry Geometry
Definition: evaluatecaller.hh:261
Traits::Geometry Geometry
Definition: evaluatecaller.hh:185
RangeVectorImp RangeVectorType
Definition: evaluatecaller.hh:77
Definition: evaluatecaller.hh:82
static InterfaceType * createObj(const RangeVectorType &rangeStorage, const size_t numbase)
Definition: evaluatecaller.hh:320
static InterfaceType * create(const RangeVectorType &rangeStorage, const size_t quadnop, const size_t numbase)
Definition: evaluatecaller.hh:357
Traits::RangeVectorType RangeVectorType
Definition: evaluatecaller.hh:317
static InterfaceType * create(const RangeVectorType &rangeStorage, const size_t quadnop, const size_t numbase)
Definition: evaluatecaller.hh:387
std::vector< ValueType > storage_
Definition: evaluatecaller.hh:94
GeometryImp Geometry
Definition: evaluatecaller.hh:62
Traits BaseTraits
Definition: evaluatecaller.hh:70
Traits::RangeVectorType RangeVectorType
Definition: evaluatecaller.hh:405
EvaluateImplementation(const RangeVectorType &rangeStorage)
Definition: evaluatecaller.hh:271
BaseFunctionSet BaseFunctionSetType
Definition: evaluatecaller.hh:76
Traits::FactorType FactorType
Definition: evaluatecaller.hh:183
virtual void axpyRanges(const QuadratureType &quad, const FactorType &rangeFactors, LocalDofVectorType &dofs) const
Definition: evaluatecaller.hh:274
EvaluateRealImplementation(const RangeVectorType &rangeStorage)
Definition: evaluatecaller.hh:198
ThisType * ValueType
Definition: evaluatecaller.hh:93
Generic implementation of a Dune quadrature.
Definition: quadratureimp.hh:178
static InterfaceType * create(const RangeVectorType &rangeStorage, const size_t quadnop, const size_t numbase)
Definition: evaluatecaller.hh:417
BaseType InterfaceType
Definition: evaluatecaller.hh:196
ThreadSafeValue realizes thread safety for a given variable by creating an instance of this variable ...
Definition: threadsafevalue.hh:16
static InterfaceType * createObj(const RangeVectorType &rangeStorage, const size_t numbase)
Definition: evaluatecaller.hh:408
EvaluateCallerInterface< typename Traits::BaseTraits > InterfaceType
Definition: evaluatecaller.hh:346
Traits::RangeVectorType RangeVectorType
Definition: evaluatecaller.hh:262
EvaluateCallerInterface< typename Traits::BaseTraits > InterfaceType
Definition: evaluatecaller.hh:376
EvaluatorStorage()
Definition: evaluatecaller.hh:96
FactorImp FactorType
Definition: evaluatecaller.hh:60
virtual void evaluateRanges(const QuadratureType &quad, const LocalDofVectorType &dofs, FactorType &rangeFactors) const
Definition: evaluatecaller.hh:289
EvaluateCallerInterface< typename Traits::BaseTraits > BaseType
Definition: evaluatecaller.hh:190
virtual ~EvaluateCallerInterface()
Definition: evaluatecaller.hh:119
static InterfaceType * createObj(const RangeVectorType &rangeStorage, const size_t numbase)
Definition: evaluatecaller.hh:378
virtual void evaluateRanges(const QuadratureType &quad, const LocalDofVectorType &dofs, FactorType &rangeFactors) const
Definition: evaluatecaller.hh:223
EvaluateCallerInterface< typename Traits::BaseTraits > BaseType
Definition: evaluatecaller.hh:266
Traits::LocalDofVectorType LocalDofVectorType
Definition: evaluatecaller.hh:184
Traits::RangeVectorType RangeVectorType
Definition: evaluatecaller.hh:186
Traits::RangeVectorType RangeVectorType
Definition: evaluatecaller.hh:345