dune-localfunctions  2.3.1
defaultbasisfactory.hh
Go to the documentation of this file.
1 // -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 // vi: set et ts=4 sw=2 sts=2:
3 #ifndef DUNE_DEFAULTBASISFACTORY_HH
4 #define DUNE_DEFAULTBASISFACTORY_HH
5 
6 #include <fstream>
7 #include <dune/common/exceptions.hh>
8 #include <dune/geometry/topologyfactory.hh>
9 
11 
12 namespace Dune
13 {
14  struct Identity
15  {
16  template <class T>
17  static T apply( const T &t )
18  {
19  return t;
20  }
21  };
22  /************************************************
23  * Class for providing a factory for basis
24  * functions over the set of reference elements.
25  * Is based on the TopologyFactory but additionaly
26  * provides rebindes of the field type.
27  * The user provides factories for the pre basis and the
28  * interpolations. The default construction process of
29  * the basis is performed in this class.
30  ************************************************/
31  template< class PreBFactory,
32  class InterpolFactory,
33  unsigned int dim, unsigned int dimR,
34  class SF, class CF,
35  class PreBasisKeyExtractor = Identity >
36  struct DefaultBasisFactory;
37 
38  template< class PreBFactory,
39  class InterpolFactory,
40  unsigned int dim, unsigned int dimR,
41  class SF, class CF,
42  class PreBasisKeyExtractor >
44  {
45  static const unsigned int dimension = dim;
46  static const unsigned int dimRange = dimR;
47 
48  typedef PreBFactory PreBasisFactory;
49  typedef typename PreBasisFactory::Object PreBasis;
50  typedef InterpolFactory InterpolationFactory;
51  typedef typename InterpolationFactory::Object Interpolation;
52 
53  typedef typename PreBasisFactory::template EvaluationBasisFactory<dim,SF>::Type MonomialBasisFactory;
57 
58  typedef const Basis Object;
59  typedef typename InterpolationFactory::Key Key;
61  };
62 
63  template< class PreBFactory,
64  class InterpolFactory,
65  unsigned int dim, unsigned int dimR,
66  class SF, class CF,
67  class PreBasisKeyExtractor >
69  : public TopologyFactory<
70  DefaultBasisFactoryTraits< PreBFactory,InterpolFactory,dim,dimR,SF,CF,PreBasisKeyExtractor >
71  >
72  {
74  static const unsigned int dimension = Traits::dimension;
75  static const unsigned int dimRange = Traits::dimRange;
76  typedef SF StorageField;
77  typedef CF ComputeField;
78  typedef typename Traits::Basis Basis;
80 
81  typedef typename Traits::Object Object;
82  typedef typename Traits::Key Key;
83  template <unsigned int dd, class FF>
85  {
86  typedef typename Traits::PreBasisFactory::template EvaluationBasisFactory<dd,FF>::Type
88  };
89 
90  template< class Topology >
91  static Object *createObject ( const Key &key )
92  {
93  const typename PreBasisFactory::Key preBasisKey = PreBasisKeyExtractor::apply(key);
94  const typename Traits::PreBasis *preBasis = Traits::PreBasisFactory::template create<Topology>( preBasisKey );
95  const typename Traits::Interpolation *interpol = Traits::InterpolationFactory::template create<Topology>( key );
96  BasisMatrix< typename Traits::PreBasis,
97  typename Traits::Interpolation,
98  ComputeField > matrix( *preBasis, *interpol );
99 
100  const typename Traits::MonomialBasis *monomialBasis = Traits::MonomialBasisFactory::template create< Topology >( preBasis->order() );
101 
102  Basis *basis = new Basis( *monomialBasis );
103 
104  basis->fill( matrix );
105 
108 
109  return basis;
110  }
112  static void release( Object *object)
113  {
114  const typename Traits::MonomialBasis *monomialBasis = &(object->basis());
115  delete object;
116  Traits::MonomialBasisFactory::release( monomialBasis );
117  }
118  };
119 }
120 
121 #endif // #ifndef DUNE_DEFAULTBASISFACTORY_HH