5#ifndef DUNE_LAGRANGEBASIS_INTERPOLATION_HH
6#define DUNE_LAGRANGEBASIS_INTERPOLATION_HH
14#include <dune/localfunctions/common/localinterpolation.hh>
15#include <dune/localfunctions/lagrange/lagrangecoefficients.hh>
20 template<
template <
class,
unsigned int>
class LP,
21 unsigned int dim,
class F >
22 struct LagrangeInterpolationFactory;
27 template<
template <
class,
unsigned int>
class LP,
unsigned int dim,
class F >
28 class LocalLagrangeInterpolation
30 typedef LocalLagrangeInterpolation< LP,dim,F > This;
33 typedef LP<F,dim> LagrangePointSet;
34 typedef typename LagrangePointSet::Field Field;
36 static const unsigned int dimension = LagrangePointSet::dimension;
39 friend struct LagrangeInterpolationFactory<LP,dim,F>;
40 const LagrangePointSet &lagrangePoints_;
42 explicit LocalLagrangeInterpolation (
const LagrangePointSet &lagrangePoints )
43 : lagrangePoints_( lagrangePoints )
46 const LagrangePointSet *points ()
const {
return &lagrangePoints_; }
48 template<
class Fn,
class Vector >
49 auto interpolate (
const Fn &fn, Vector &coefficients, PriorityTag< 1 > )
const
50 -> std::enable_if_t< std::is_invocable_v<
const Fn &,
decltype( this->lagrangePoints_.begin()->point() ) > >
52 unsigned int index = 0;
53 for(
const auto &lp : lagrangePoints_ )
54 field_cast( fn( lp.point() ), coefficients[ index++ ] );
56 template<
class Fn,
class Vector >
57 auto interpolate (
const Fn &fn, Vector &coefficients, PriorityTag< 0 > )
const
58 -> std::enable_if_t< models<Impl::FunctionWithEvaluate< typename Fn::DomainType, typename Fn::RangeType >, Fn>(),
void>
60 unsigned int index = 0;
61 for(
const auto &lp : lagrangePoints_ )
63 typename Fn::RangeType val;
64 fn.evaluate( field_cast< typename Fn::DomainType::field_type >( lp.point() ), val );
70 template<
class Fn,
class Vector >
71 auto interpolate (
const Fn &fn, Vector &coefficients )
const
72 -> std::enable_if_t< std::is_same< decltype(std::declval<Vector>().resize(1) ),
void >::value,
void>
74 coefficients.resize( lagrangePoints_.size() );
75 interpolate( fn, coefficients, PriorityTag< 42 >() );
78 template<
class Basis,
class Matrix >
79 auto interpolate (
const Basis &basis, Matrix &coefficients )
const
80 -> std::enable_if_t< std::is_same<
81 decltype(std::declval<Matrix>().rowPtr(0)),
typename Matrix::Field* >::value,
void>
83 coefficients.resize( lagrangePoints_.size(), basis.size( ) );
85 unsigned int index = 0;
86 for(
const auto &lp : lagrangePoints_ )
87 basis.template evaluate< 0 >( lp.point(), coefficients.rowPtr( index++ ) );
90 const LagrangePointSet &lagrangePoints ()
const {
return lagrangePoints_; }
97 template<
template <
class,
unsigned int>
class LP,
98 unsigned int dim,
class F >
99 struct LagrangeInterpolationFactory
101 typedef LagrangeCoefficientsFactory<LP,dim,F> LagrangePointSetFactory;
102 typedef typename LagrangePointSetFactory::Object LagrangePointSet;
104 typedef typename LagrangePointSetFactory::Key Key;
105 typedef const LocalLagrangeInterpolation< LP,dim,F > Object;
107 template< GeometryType::Id geometryId >
108 static Object *create (
const Key &key )
110 const LagrangePointSet *lagrangeCoeff
111 = LagrangePointSetFactory::template create< geometryId >( key );
112 if ( lagrangeCoeff == 0 )
115 return new Object( *lagrangeCoeff );
117 template< GeometryType::Id geometryId >
118 static bool supports (
const Key &key )
122 static void release( Object *
object)
124 LagrangePointSetFactory::release( object->points() );
Dune namespace.
Definition: alignedallocator.hh:13
void field_cast(const F1 &f1, F2 &f2)
a helper class to cast from one field to another
Definition: field.hh:159
Utilities for type computations, constraining overloads, ...