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