dune-localfunctions  2.11
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 // SPDX-FileCopyrightInfo: Copyright © DUNE Project contributors, see file LICENSE.md in module root
4 // SPDX-License-Identifier: LicenseRef-GPL-2.0-only-with-DUNE-exception
5 #ifndef DUNE_LAGRANGEBASIS_INTERPOLATION_HH
6 #define DUNE_LAGRANGEBASIS_INTERPOLATION_HH
7 
8 #include <type_traits>
9 #include <utility>
10 #include <vector>
11 
12 #include <dune/common/typeutilities.hh>
13 
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_v< const Fn &, decltype( this->lagrangePoints_.begin()->point() ) > >
50  {
51  unsigned int index = 0;
52  for( const auto &lp : lagrangePoints_ )
53  field_cast( fn( lp.point() ), coefficients[ index++ ] );
54  }
55 
56  public:
57  template< class Fn, class Vector,
58  decltype(std::declval<Vector>().size(),bool{}) = true,
59  decltype(std::declval<Vector>().resize(0u),bool{}) = true>
60  void interpolate ( const Fn &fn, Vector &coefficients ) const
61  {
62  coefficients.resize( lagrangePoints_.size() );
63  interpolate( fn, coefficients, PriorityTag< 42 >() );
64  }
65 
66  template< class Basis, class Matrix,
67  decltype(std::declval<Matrix>().rows(),bool{}) = true,
68  decltype(std::declval<Matrix>().cols(),bool{}) = true,
69  decltype(std::declval<Matrix>().resize(0u,0u),bool{}) = true>
70  void interpolate ( const Basis &basis, Matrix &coefficients ) const
71  {
72  coefficients.resize( lagrangePoints_.size(), basis.size( ) );
73 
74  unsigned int index = 0;
75  for( const auto &lp : lagrangePoints_ )
76  basis.template evaluate< 0 >( lp.point(), coefficients[index++] );
77  }
78 
79  const LagrangePointSet &lagrangePoints () const { return lagrangePoints_; }
80  };
81 
82 
83 
84  // LocalLagrangeInterpolationFactory
85  // ---------------------------------
86  template< template <class,unsigned int> class LP,
87  unsigned int dim, class F >
88  struct LagrangeInterpolationFactory
89  {
92 
95 
96  template< GeometryType::Id geometryId >
97  static Object *create ( const Key &key )
98  {
99  const LagrangePointSet *lagrangeCoeff
100  = LagrangePointSetFactory::template create< geometryId >( key );
101  if ( lagrangeCoeff == 0 )
102  return 0;
103  else
104  return new Object( *lagrangeCoeff );
105  }
106  template< GeometryType::Id geometryId >
107  static bool supports ( const Key &key )
108  {
109  return true;
110  }
111  static void release( Object *object)
112  {
113  LagrangePointSetFactory::release( object->points() );
114  delete object;
115  }
116  };
117 
118 }
119 
120 #endif // #ifndef DUNE_LAGRANGEBASIS_INTERPOLATION_HH
static void release(Object *object)
Definition: lagrange/interpolation.hh:111
static bool supports(const Key &key)
Definition: lagrange/interpolation.hh:107
static void release(Object *object)
Definition: lagrangecoefficients.hh:42
LagrangePointSetFactory::Object LagrangePointSet
Definition: lagrange/interpolation.hh:91
Definition: bdfmcube.hh:17
const LocalLagrangeInterpolation< LP, dim, F > Object
Definition: lagrange/interpolation.hh:94
Definition: lagrange/interpolation.hh:21
LP< F, dim > LagrangePointSet
Definition: lagrange/interpolation.hh:32
LagrangeCoefficientsFactory< LP, dim, F > LagrangePointSetFactory
Definition: lagrange/interpolation.hh:90
static const unsigned int dimension
Definition: lagrange/interpolation.hh:35
Definition: lagrange/interpolation.hh:27
const LagrangePointSet & lagrangePoints() const
Definition: lagrange/interpolation.hh:79
std::size_t Key
Definition: lagrangecoefficients.hh:26
static Object * create(const Key &key)
Definition: lagrange/interpolation.hh:97
const typedef LP< F, dim > Object
Definition: lagrangecoefficients.hh:25
LagrangePointSetFactory::Key Key
Definition: lagrange/interpolation.hh:93
Definition: lagrangecoefficients.hh:22
void field_cast(const F1 &f1, F2 &f2)
a helper class to cast from one field to another
Definition: field.hh:160
LagrangePointSet::Field Field
Definition: lagrange/interpolation.hh:33