DUNE PDELab (2.8)

interpolation.hh
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
11
12#include <dune/localfunctions/common/localinterpolation.hh>
13#include <dune/localfunctions/lagrange/lagrangecoefficients.hh>
14
15namespace Dune
16{
17
18 template< template <class,unsigned int> class LP,
19 unsigned int dim, class F >
20 struct LagrangeInterpolationFactory;
21
22 // LocalLagrangeInterpolation
23 // --------------------------
24
25 template< template <class,unsigned int> class LP, unsigned int dim, class F >
26 class LocalLagrangeInterpolation
27 {
28 typedef LocalLagrangeInterpolation< LP,dim,F > This;
29
30 public:
31 typedef LP<F,dim> LagrangePointSet;
32 typedef typename LagrangePointSet::Field Field;
33
34 static const unsigned int dimension = LagrangePointSet::dimension;
35
36 private:
37 friend struct LagrangeInterpolationFactory<LP,dim,F>;
38 const LagrangePointSet &lagrangePoints_;
39
40 explicit LocalLagrangeInterpolation ( const LagrangePointSet &lagrangePoints )
41 : lagrangePoints_( lagrangePoints )
42 {}
43
44 const LagrangePointSet *points () const { return &lagrangePoints_; }
45
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() ) > >
49 {
50 unsigned int index = 0;
51 for( const auto &lp : lagrangePoints_ )
52 field_cast( fn( lp.point() ), coefficients[ index++ ] );
53 }
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>
57 {
58 unsigned int index = 0;
59 for( const auto &lp : lagrangePoints_ )
60 {
61 typename Fn::RangeType val;
62 fn.evaluate( field_cast< typename Fn::DomainType::field_type >( lp.point() ), val );
63 field_cast( val, coefficients[ index++ ] );
64 }
65 }
66
67 public:
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>
71 {
72 coefficients.resize( lagrangePoints_.size() );
73 interpolate( fn, coefficients, PriorityTag< 42 >() );
74 }
75
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>
80 {
81 coefficients.resize( lagrangePoints_.size(), basis.size( ) );
82
83 unsigned int index = 0;
84 for( const auto &lp : lagrangePoints_ )
85 basis.template evaluate< 0 >( lp.point(), coefficients.rowPtr( index++ ) );
86 }
87
88 const LagrangePointSet &lagrangePoints () const { return lagrangePoints_; }
89 };
90
91
92
93 // LocalLagrangeInterpolationFactory
94 // ---------------------------------
95 template< template <class,unsigned int> class LP,
96 unsigned int dim, class F >
97 struct LagrangeInterpolationFactory
98 {
99 typedef LagrangeCoefficientsFactory<LP,dim,F> LagrangePointSetFactory;
100 typedef typename LagrangePointSetFactory::Object LagrangePointSet;
101
102 typedef typename LagrangePointSetFactory::Key Key;
103 typedef const LocalLagrangeInterpolation< LP,dim,F > Object;
104
105 template< GeometryType::Id geometryId >
106 static Object *create ( const Key &key )
107 {
108 const LagrangePointSet *lagrangeCoeff
109 = LagrangePointSetFactory::template create< geometryId >( key );
110 if ( lagrangeCoeff == 0 )
111 return 0;
112 else
113 return new Object( *lagrangeCoeff );
114 }
115 template< GeometryType::Id geometryId >
116 static bool supports ( const Key &key )
117 {
118 return true;
119 }
120 static void release( Object *object)
121 {
122 LagrangePointSetFactory::release( object->points() );
123 delete object;
124 }
125 };
126
127}
128
129#endif // #ifndef DUNE_LAGRANGEBASIS_INTERPOLATION_HH
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, ...
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Jul 27, 22:29, 2024)