dune-composites (2.5.1)

serendipitylocalinterpolation.hh
1// -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2// vi: set et ts=4 sw=2 sts=2:
3
4#ifndef DUNE_LOCALFUNCTIONS_SERENDIPITYLOCALINTERPOLATION_HH
5#define DUNE_LOCALFUNCTIONS_SERENDIPITYLOCALINTERPOLATION_HH
6
7#include <dune/common/fvector.hh>
8#include <dune/common/power.hh>
9
10#include <dune/geometry/type.hh>
11
12#include <dune/localfunctions/common/localbasis.hh>
13#include <dune/localfunctions/common/localfiniteelementtraits.hh>
14
15
16namespace Dune
17{
19 template<int k, int d, class LB>
21 {
22
23 typedef typename Dune::FieldVector<int,d> DuneVector;
24 static void multiindex (DuneVector& alpha)
25 {
26 int i = 0;
27 for (int j=0; j<d; j++){
28 i+=alpha[j]*pow(k+1,j);
29 }
30 i++;
31 for (int j=0; j<d; j++)
32 {
33 alpha[j] = i % (k+1);
34 i = i/(k+1);
35 }
36 unsigned int sum = 0;
37 for (unsigned int j=0; j<d; j++){
38 if(alpha[j] > 0 && alpha[j] < k){ sum++; }
39 }
40 if(sum > 1){
41 multiindex(alpha);
42 }
43 }
44
46 unsigned int size () const
47 {
48 if(d == 1){
49 return k+1;
50 }
51 if(d == 2){
52 return 2*(k+1)+2*(k-1);
53 }
54 if(d == 3){
55 return 4*(k+1)+8*(k-1);
56 }
57 }
58
59 public:
60
62 template<typename F, typename C>
63 void interpolate (const F& f, std::vector<C>& out) const
64 {
65 typename LB::Traits::DomainType x;
66 typename LB::Traits::RangeType y;
67
68 out.resize(size());
69 DuneVector alpha(0);
70 for (unsigned int i=0; i<size(); i++)
71 {
72 // convert index i to multiindex
73 if(i>0){ multiindex(alpha); }
74
75 // Generate coordinate of the i-th Lagrange point
76 for (int j=0; j<d; j++)
77 x[j] = (1.0*alpha[j])/k;
78
79 f.evaluate(x,y);
80 out[i] = y;
81 }
82 }
83 };
84
86 template<int d, class LB>
88 {
89 public:
91 template<typename F, typename C>
92 void interpolate (const F& f, std::vector<C>& out) const
93 {
94 typename LB::Traits::DomainType x(0);
95 typename LB::Traits::RangeType y;
96 f.evaluate(x,y);
97 out.resize(1);
98 out[0] = y;
99 }
100 };
101
102}
103
104
105#endif
void interpolate(const F &f, std::vector< C > &out) const
Local interpolation of a function.
Definition: serendipitylocalinterpolation.hh:92
Definition: serendipitylocalinterpolation.hh:21
void interpolate(const F &f, std::vector< C > &out) const
Local interpolation of a function.
Definition: serendipitylocalinterpolation.hh:63
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden & Uni Heidelberg  |  generated with Hugo v0.111.3 (Sep 4, 22:38, 2025)