dune-localfunctions  2.3beta2
dualq1localinterpolation.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_Q1_LOCALINTERPOLATION_HH
4 #define DUNE_DUAL_Q1_LOCALINTERPOLATION_HH
5 
6 #include <vector>
7 
8 #include <dune/common/fvector.hh>
9 #include <dune/common/fmatrix.hh>
10 
11 namespace Dune
12 {
13 
15  template<int dim, class LB>
17  {
18  public:
19 
20  void setCoefficients(const Dune::array<Dune::FieldVector<typename LB::Traits::RangeFieldType, (1<<dim)> ,(1<<dim)>& coefficients)
21  {
22  coefficients_ = coefficients;
23  }
24 
25 
27  template<typename F, typename C>
28  void interpolate (const F& f, std::vector<C>& out) const
29  {
30  typename LB::Traits::DomainType x;
31  typename LB::Traits::RangeType y;
32 
33  const int size = 1<<dim;
34 
35  // compute Q1 interpolation coefficients
36  Dune::FieldVector<C,size> q1Coefficients;
37 
38  for (int i=0; i< (1<<dim); i++) {
39 
40  // Generate coordinate of the i-th corner of the reference cube
41  // We could use the ReferenceElement for this as well, but it is
42  // still not clear how dune-localfunctions should have access to them.
43  for (int j=0; j<dim; j++)
44  x[j] = (i & (1<<j)) ? 1.0 : 0.0;
45 
46  f.evaluate(x,y); q1Coefficients[i] = y;
47 
48  }
49 
50  out.resize(size);
51 
52  // solve a linear system to compute the dual coefficients
53  Dune::FieldMatrix<C,size,size> mat;
54 
55  for (int i=0; i<size; i++)
56  for (int j=0; j<size; j++)
57  mat[i][j] = coefficients_[j][i];
58 
59  // now solve for the weights
60  Dune::FieldVector<C,size> sol(0);
61 
62  mat.solve(sol,q1Coefficients);
63 
64  // write result in out vector
65  for (int i=0; i<size; i++)
66  out[i] = sol[i];
67  }
68 
69  private:
70  Dune::array<Dune::FieldVector<typename LB::Traits::RangeFieldType, (1<<dim)> ,(1<<dim)> coefficients_;
71  };
72 
73 }
74 
75 #endif