3#ifndef DUNE_LAGRANGEBASIS_INTERPOLATION_HH
4#define DUNE_LAGRANGEBASIS_INTERPOLATION_HH
10#include <dune/common/std/type_traits.hh>
13#include <dune/localfunctions/common/localinterpolation.hh>
14#include <dune/localfunctions/lagrange/lagrangecoefficients.hh>
19 template<
template <
class,
unsigned int>
class LP,
20 unsigned int dim,
class F >
21 struct LagrangeInterpolationFactory;
26 template<
template <
class,
unsigned int>
class LP,
unsigned int dim,
class F >
27 class LocalLagrangeInterpolation
29 typedef LocalLagrangeInterpolation< LP,dim,F > This;
32 typedef LP<F,dim> LagrangePointSet;
33 typedef typename LagrangePointSet::Field Field;
35 static const unsigned int dimension = LagrangePointSet::dimension;
38 friend struct LagrangeInterpolationFactory<LP,dim,F>;
39 const LagrangePointSet &lagrangePoints_;
41 explicit LocalLagrangeInterpolation (
const LagrangePointSet &lagrangePoints )
42 : lagrangePoints_( lagrangePoints )
45 const LagrangePointSet *points ()
const {
return &lagrangePoints_; }
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 >
51 unsigned int index = 0;
52 for(
const auto &lp : lagrangePoints_ )
53 field_cast( fn( lp.point() ), coefficients[ index++ ] );
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>
59 unsigned int index = 0;
60 for(
const auto &lp : lagrangePoints_ )
62 typename Fn::RangeType val;
63 fn.evaluate( field_cast< typename Fn::DomainType::field_type >( lp.point() ), val );
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>
73 coefficients.resize( lagrangePoints_.size() );
74 interpolate( fn, coefficients, PriorityTag< 42 >() );
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>
82 coefficients.resize( lagrangePoints_.size(), basis.size( ) );
84 unsigned int index = 0;
85 for(
const auto &lp : lagrangePoints_ )
86 basis.template evaluate< 0 >( lp.point(), coefficients.rowPtr( index++ ) );
89 const LagrangePointSet &lagrangePoints ()
const {
return lagrangePoints_; }
96 template<
template <
class,
unsigned int>
class LP,
97 unsigned int dim,
class F >
98 struct LagrangeInterpolationFactory
100 typedef LagrangeCoefficientsFactory<LP,dim,F> LagrangePointSetFactory;
101 typedef typename LagrangePointSetFactory::Object LagrangePointSet;
103 typedef typename LagrangePointSetFactory::Key Key;
104 typedef const LocalLagrangeInterpolation< LP,dim,F > Object;
106 template<
class Topology >
107 static Object *create (
const Key &key )
109 const LagrangePointSet *lagrangeCoeff
110 = LagrangePointSetFactory::template create< Topology >( key );
111 if ( lagrangeCoeff == 0 )
114 return new Object( *lagrangeCoeff );
116 template<
class Topology >
117 static bool supports (
const Key &key )
121 static void release( Object *
object)
123 LagrangePointSetFactory::release( object->points() );
Dune namespace.
Definition: alignedallocator.hh:14
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, ...