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