dune-localfunctions  2.7.0
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 <type_traits>
7 #include <utility>
8 #include <vector>
9 
10 #include <dune/common/std/type_traits.hh>
11 #include <dune/common/typeutilities.hh>
12 
15 
16 namespace Dune
17 {
18 
19  template< template <class,unsigned int> class LP,
20  unsigned int dim, class F >
22 
23  // LocalLagrangeInterpolation
24  // --------------------------
25 
26  template< template <class,unsigned int> class LP, unsigned int dim, class F >
28  {
30 
31  public:
32  typedef LP<F,dim> LagrangePointSet;
33  typedef typename LagrangePointSet::Field Field;
34 
35  static const unsigned int dimension = LagrangePointSet::dimension;
36 
37  private:
38  friend struct LagrangeInterpolationFactory<LP,dim,F>;
39  const LagrangePointSet &lagrangePoints_;
40 
42  : lagrangePoints_( lagrangePoints )
43  {}
44 
45  const LagrangePointSet *points () const { return &lagrangePoints_; }
46 
47  template< class Fn, class Vector >
48  auto interpolate ( const Fn &fn, Vector &coefficients, PriorityTag< 1 > ) const
49  -> std::enable_if_t< Std::is_invocable< const Fn &, decltype( this->lagrangePoints_.begin()->point() ) >::value >
50  {
51  unsigned int index = 0;
52  for( const auto &lp : lagrangePoints_ )
53  field_cast( fn( lp.point() ), coefficients[ index++ ] );
54  }
55  template< class Fn, class Vector >
56  auto interpolate ( const Fn &fn, Vector &coefficients, PriorityTag< 0 > ) const
57  -> std::enable_if_t< models<Impl::FunctionWithEvaluate< typename Fn::DomainType, typename Fn::RangeType >, Fn>(), void>
58  {
59  unsigned int index = 0;
60  for( const auto &lp : lagrangePoints_ )
61  {
62  typename Fn::RangeType val;
63  fn.evaluate( field_cast< typename Fn::DomainType::field_type >( lp.point() ), val );
64  field_cast( val, coefficients[ index++ ] );
65  }
66  }
67 
68  public:
69  template< class Fn, class Vector >
70  auto interpolate ( const Fn &fn, Vector &coefficients ) const
71  -> std::enable_if_t< std::is_same< decltype(std::declval<Vector>().resize(1) ),void >::value,void>
72  {
73  coefficients.resize( lagrangePoints_.size() );
74  interpolate( fn, coefficients, PriorityTag< 42 >() );
75  }
76 
77  template< class Basis, class Matrix >
78  auto interpolate ( const Basis &basis, Matrix &coefficients ) const
79  -> std::enable_if_t< std::is_same<
80  decltype(std::declval<Matrix>().rowPtr(0)), typename Matrix::Field* >::value,void>
81  {
82  coefficients.resize( lagrangePoints_.size(), basis.size( ) );
83 
84  unsigned int index = 0;
85  for( const auto &lp : lagrangePoints_ )
86  basis.template evaluate< 0 >( lp.point(), coefficients.rowPtr( index++ ) );
87  }
88 
89  const LagrangePointSet &lagrangePoints () const { return lagrangePoints_; }
90  };
91 
92 
93 
94  // LocalLagrangeInterpolationFactory
95  // ---------------------------------
96  template< template <class,unsigned int> class LP,
97  unsigned int dim, class F >
98  struct LagrangeInterpolationFactory
99  {
102 
105 
106  template< class Topology >
107  static Object *create ( const Key &key )
108  {
109  const LagrangePointSet *lagrangeCoeff
110  = 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 Key &key )
118  {
119  return true;
120  }
121  static void release( Object *object)
122  {
123  LagrangePointSetFactory::release( object->points() );
124  delete object;
125  }
126  };
127 
128 }
129 
130 #endif // #ifndef DUNE_LAGRANGEBASIS_INTERPOLATION_HH
Dune::LagrangeCoefficientsFactory::Object
const typedef LP< F, dim > Object
Definition: lagrangecoefficients.hh:23
Dune::LagrangeCoefficientsFactory::Key
std::size_t Key
Definition: lagrangecoefficients.hh:24
localinterpolation.hh
Dune::LagrangeInterpolationFactory::create
static Object * create(const Key &key)
Definition: lagrange/interpolation.hh:107
Dune::LagrangeInterpolationFactory::supports
static bool supports(const Key &key)
Definition: lagrange/interpolation.hh:117
Dune::LagrangeInterpolationFactory::release
static void release(Object *object)
Definition: lagrange/interpolation.hh:121
Dune
Definition: bdfmcube.hh:15
Dune::field_cast
void field_cast(const F1 &f1, F2 &f2)
a helper class to cast from one field to another
Definition: field.hh:157
Dune::LocalLagrangeInterpolation::LagrangePointSet
LP< F, dim > LagrangePointSet
Definition: lagrange/interpolation.hh:32
Dune::DerivativeLayoutNS::value
@ value
Definition: tensor.hh:166
Dune::LagrangeCoefficientsFactory::release
static void release(Object *object)
Definition: lagrangecoefficients.hh:40
Dune::LagrangeInterpolationFactory::LagrangePointSetFactory
LagrangeCoefficientsFactory< LP, dim, F > LagrangePointSetFactory
Definition: lagrange/interpolation.hh:100
Dune::LocalLagrangeInterpolation::interpolate
auto interpolate(const Basis &basis, Matrix &coefficients) const -> std::enable_if_t< std::is_same< decltype(std::declval< Matrix >().rowPtr(0)), typename Matrix::Field * >::value, void >
Definition: lagrange/interpolation.hh:78
lagrangecoefficients.hh
Dune::LagrangeInterpolationFactory
Definition: lagrange/interpolation.hh:21
Dune::LagrangeInterpolationFactory::Object
const typedef LocalLagrangeInterpolation< LP, dim, F > Object
Definition: lagrange/interpolation.hh:104
Dune::LocalLagrangeInterpolation::dimension
static const unsigned int dimension
Definition: lagrange/interpolation.hh:35
Dune::LocalLagrangeInterpolation::interpolate
auto interpolate(const Fn &fn, Vector &coefficients) const -> std::enable_if_t< std::is_same< decltype(std::declval< Vector >().resize(1)), void >::value, void >
Definition: lagrange/interpolation.hh:70
Dune::LocalLagrangeInterpolation::lagrangePoints
const LagrangePointSet & lagrangePoints() const
Definition: lagrange/interpolation.hh:89
Dune::LagrangeInterpolationFactory::LagrangePointSet
LagrangePointSetFactory::Object LagrangePointSet
Definition: lagrange/interpolation.hh:101
Dune::LagrangeInterpolationFactory::Key
LagrangePointSetFactory::Key Key
Definition: lagrange/interpolation.hh:103
Dune::LagrangeCoefficientsFactory
Definition: lagrangecoefficients.hh:20
Dune::LocalLagrangeInterpolation
Definition: lagrange/interpolation.hh:27
Dune::LocalLagrangeInterpolation::Field
LagrangePointSet::Field Field
Definition: lagrange/interpolation.hh:33