dune-localfunctions  2.4.1-rc2
dualp1localinterpolation.hh
Go to the documentation of this file.
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_DUAL_P1_LOCALINTERPOLATION_HH
4 #define DUNE_DUAL_P1_LOCALINTERPOLATION_HH
5 
6 #include <vector>
7 
8 namespace Dune
9 {
10  template<int dim, class LB>
12  {
13  public:
15  template<typename F, typename C>
16  void interpolate (const F& f, std::vector<C>& out) const
17  {
18  typename LB::Traits::RangeType y;
19  typename LB::Traits::DomainType x;
20 
21  // compute P1 interpolation coefficients
22  std::vector<C> p1Interpolation(dim+1);
23 
24  // vertex 0
25  for (int i=0; i<dim; i++)
26  x[i] = 0;
27  f.evaluate(x,y); p1Interpolation[0] = y;
28 
29  // remaining vertices
30  for (int i=0; i<dim; i++) {
31  for (int j=0; j<dim; j++)
32  x[j] = (i==j);
33 
34  f.evaluate(x,y); p1Interpolation[i+1] = y;
35 
36  }
37 
38  // compute dual coefficients from the Lagrange ones
39  out.resize(dim+1);
40  for (int i=0; i<dim+1; i++) {
41  out[i] = 2*p1Interpolation[i]/(dim+2) ;
42 
43  for (int j=0; j<i; j++)
44  out[i] += p1Interpolation[j]/(dim+2);
45 
46  for (int j=i+1; j<=dim; j++)
47  out[i] += p1Interpolation[j]/(dim+2);
48  }
49  }
50 
51  };
52 }
53 
54 #endif
void interpolate(const F &f, std::vector< C > &out) const
Local interpolation of a function.
Definition: dualp1localinterpolation.hh:16
Definition: brezzidouglasmarini1cube2dlocalbasis.hh:14
Definition: dualp1localinterpolation.hh:11