Dune Core Modules (2.9.1)

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