dune-localfunctions  2.3.1
lagrange/interpolation.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_LAGRANGEBASIS_INTERPOLATION_HH
4 #define DUNE_LAGRANGEBASIS_INTERPOLATION_HH
5 
6 #include <vector>
7 #include <dune/geometry/topologyfactory.hh>
9 
10 namespace Dune
11 {
12 
13  template< template <class,unsigned int> class LP,
14  unsigned int dim, class F >
15  struct LagrangeInterpolationFactory;
16 
17  // LocalLagrangeInterpolation
18  // --------------------------
19 
20  template< template <class,unsigned int> class LP,
21  unsigned int dim, class F >
23  {
25 
26  public:
27  typedef LP<F,dim> LagrangePointSet;
28  typedef typename LagrangePointSet::Field Field;
29 
30  static const unsigned int dimension = LagrangePointSet::dimension;
31 
32  private:
33  friend struct LagrangeInterpolationFactory<LP,dim,F>;
34  const LagrangePointSet &lagrangePoints_;
35 
37  : lagrangePoints_( lagrangePoints )
38  {}
39  const LagrangePointSet *points () const
40  {
41  return &lagrangePoints_;
42  }
43 
44  public:
45  template< class Function, class Fy >
46  void interpolate ( const Function &function, std::vector< Fy > &coefficients ) const
47  {
48  typedef typename LagrangePointSet::iterator Iterator;
49 
50  coefficients.resize( lagrangePoints_.size() );
51 
52  unsigned int index = 0;
53  const Iterator end = lagrangePoints_.end();
54  for( Iterator it = lagrangePoints_.begin(); it != end; ++it )
55  {
56  typename Function::RangeType val;
57  function.evaluate( field_cast<typename Function::DomainType::field_type>(it->point()), val );
58  field_cast( val, coefficients[ index++ ] );
59  }
60  }
61 
62  template< class Matrix, class Basis >
63  void interpolate ( const Basis &basis, Matrix &coefficients ) const
64  {
65  typedef typename LagrangePointSet::iterator Iterator;
66 
67  coefficients.resize( lagrangePoints_.size(), basis.size( ) );
68 
69  unsigned int index = 0;
70  const Iterator end = lagrangePoints_.end();
71  for( Iterator it = lagrangePoints_.begin(); it != end; ++it )
72  basis.template evaluate<0>( it->point(), coefficients.rowPtr( index++ ) );
73  }
74 
76  {
77  return lagrangePoints_;
78  }
79  };
80 
81 
82 
83  // LocalLagrangeInterpolationFactory
84  // ---------------------------------
85  template< template <class,unsigned int> class LP,
86  unsigned int dim, class F >
88  {
91 
95 
96  static const unsigned int dimension = dim;
97  };
98 
99  template< template <class,unsigned int> class LP,
100  unsigned int dim, class F >
102  public TopologyFactory< LagrangeInterpolationFactoryTraits< LP,dim,F > >
103  {
105  typedef typename Traits::Key Key;
106  typedef typename Traits::Object Object;
107 
108  template< class Topology >
109  static Object *createObject ( const Key &key )
110  {
111  const typename Traits::LagrangePointSet *lagrangeCoeff
112  = Traits::LagrangePointSetFactory::template create< Topology >( key );
113  if ( lagrangeCoeff == 0 )
114  return 0;
115  else
116  return new Object( *lagrangeCoeff );
117  }
118  template< class Topology >
119  static bool supports ( const typename Traits::Key &key )
120  {
121  return true;
122  }
123  static void release( Object *object)
124  {
125  Traits::LagrangePointSetFactory::release( object->points() );
126  delete object;
127  }
128  };
129 
130 }
131 
132 #endif // #ifndef DUNE_LAGRANGEBASIS_INTERPOLATION_HH