Dune Core Modules (2.7.0)

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