3#ifndef DUNE_LAGRANGEBASIS_INTERPOLATION_HH
4#define DUNE_LAGRANGEBASIS_INTERPOLATION_HH
12#include <dune/localfunctions/common/localinterpolation.hh>
13#include <dune/localfunctions/lagrange/lagrangecoefficients.hh>
18 template<
template <
class,
unsigned int>
class LP,
19 unsigned int dim,
class F >
20 struct LagrangeInterpolationFactory;
25 template<
template <
class,
unsigned int>
class LP,
unsigned int dim,
class F >
26 class LocalLagrangeInterpolation
28 typedef LocalLagrangeInterpolation< LP,dim,F > This;
31 typedef LP<F,dim> LagrangePointSet;
32 typedef typename LagrangePointSet::Field Field;
34 static const unsigned int dimension = LagrangePointSet::dimension;
37 friend struct LagrangeInterpolationFactory<LP,dim,F>;
38 const LagrangePointSet &lagrangePoints_;
40 explicit LocalLagrangeInterpolation (
const LagrangePointSet &lagrangePoints )
41 : lagrangePoints_( lagrangePoints )
44 const LagrangePointSet *points ()
const {
return &lagrangePoints_; }
46 template<
class Fn,
class Vector >
47 auto interpolate (
const Fn &fn, Vector &coefficients, PriorityTag< 1 > )
const
48 -> std::enable_if_t< std::is_invocable_v<
const Fn &,
decltype( this->lagrangePoints_.begin()->point() ) > >
50 unsigned int index = 0;
51 for(
const auto &lp : lagrangePoints_ )
52 field_cast( fn( lp.point() ), coefficients[ index++ ] );
54 template<
class Fn,
class Vector >
55 auto interpolate (
const Fn &fn, Vector &coefficients, PriorityTag< 0 > )
const
56 -> std::enable_if_t< models<Impl::FunctionWithEvaluate< typename Fn::DomainType, typename Fn::RangeType >, Fn>(),
void>
58 unsigned int index = 0;
59 for(
const auto &lp : lagrangePoints_ )
61 typename Fn::RangeType val;
62 fn.evaluate( field_cast< typename Fn::DomainType::field_type >( lp.point() ), val );
68 template<
class Fn,
class Vector >
69 auto interpolate (
const Fn &fn, Vector &coefficients )
const
70 -> std::enable_if_t< std::is_same< decltype(std::declval<Vector>().resize(1) ),
void >::value,
void>
72 coefficients.resize( lagrangePoints_.size() );
76 template<
class Basis,
class Matrix >
77 auto interpolate (
const Basis &basis, Matrix &coefficients )
const
78 -> std::enable_if_t< std::is_same<
79 decltype(std::declval<Matrix>().rowPtr(0)),
typename Matrix::Field* >::value,
void>
81 coefficients.resize( lagrangePoints_.size(), basis.size( ) );
83 unsigned int index = 0;
84 for(
const auto &lp : lagrangePoints_ )
85 basis.template evaluate< 0 >( lp.point(), coefficients.rowPtr( index++ ) );
88 const LagrangePointSet &lagrangePoints ()
const {
return lagrangePoints_; }
95 template<
template <
class,
unsigned int>
class LP,
96 unsigned int dim,
class F >
97 struct LagrangeInterpolationFactory
99 typedef LagrangeCoefficientsFactory<LP,dim,F> LagrangePointSetFactory;
100 typedef typename LagrangePointSetFactory::Object LagrangePointSet;
102 typedef typename LagrangePointSetFactory::Key Key;
103 typedef const LocalLagrangeInterpolation< LP,dim,F > Object;
105 template< GeometryType::Id geometryId >
106 static Object *create (
const Key &key )
108 const LagrangePointSet *lagrangeCoeff
109 = LagrangePointSetFactory::template create< geometryId >( key );
110 if ( lagrangeCoeff == 0 )
113 return new Object( *lagrangeCoeff );
115 template< GeometryType::Id geometryId >
116 static bool supports (
const Key &key )
120 static void release( Object *
object)
122 LagrangePointSetFactory::release( object->points() );
void interpolate(const F &f, const GFS &gfs, XG &xg)
interpolation from a given grid function
Definition: interpolate.hh:177
Dune namespace.
Definition: alignedallocator.hh:11
void field_cast(const F1 &f1, F2 &f2)
a helper class to cast from one field to another
Definition: field.hh:157
Utilities for type computations, constraining overloads, ...