dune-localfunctions  2.2.1
q2localinterpolation.hh
Go to the documentation of this file.
1 // -*- tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 // vi: set et ts=2 sw=2 sts=2:
3 #ifndef DUNE_Q2_LOCALINTERPOLATION_HH
4 #define DUNE_Q2_LOCALINTERPOLATION_HH
5 
6 #include <cstddef>
7 #include <vector>
8 
9 namespace Dune
10 {
11 template<class LB>
13 {
14 public:
15 
17  template<typename F, typename C>
18  void interpolate (const F& f, std::vector<C>& out) const
19  {
20  typename LB::Traits::DomainType x;
21  typename LB::Traits::RangeType y;
22  static const int dim = LB::Traits::dimDomain;
23 
24  // Compute number of Lagrange points
25  size_t size = 1;
26  for (int i=0; i<dim; i++)
27  size *= 3;
28 
29  out.resize(size);
30 
31  for (size_t i=0; i<size; i++) {
32 
33  // Construct the i-th Lagrange point
34  size_t ternary = i;
35  for (int j=0; j<dim; j++) {
36 
37  int digit = ternary%3;
38  ternary /= 3;
39 
40  x[j] = digit*0.5;
41 
42  }
43 
44  // Evaluate the function at this point
45  f.evaluate(x,y);
46  out[i] = y;
47 
48  }
49 
50  }
51 };
52 }
53 
54 #endif