dune-localfunctions  2.8.0
raviartthomas02dlocalinterpolation.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_RT02DLOCALINTERPOLATION_HH
4 #define DUNE_RT02DLOCALINTERPOLATION_HH
5 
6 #include <cmath>
7 #include <array>
8 #include <bitset>
9 #include <vector>
11 
12 namespace Dune
13 {
14  template<class LB>
16  {
17  public:
18 
20  RT02DLocalInterpolation (std::bitset<3> s = 0)
21  {
22  using std::sqrt;
23  for (std::size_t i=0; i<sign_.size(); i++)
24  sign_[i] = (s[i]) ? -1.0 : 1.0;
25 
26  m_[0] = {0.5, 0.0};
27  m_[1] = {0.0, 0.5};
28  m_[2] = {0.5, 0.5};
29  n_[0] = {0.0, -1.0};
30  n_[1] = {-1.0, 0.0};
31  n_[2] = {1.0/sqrt(2.0), 1.0/sqrt(2.0)};
32  c_[0] = ( 0.5*n_[0][0] - 1.0*n_[0][1]);
33  c_[1] = (-1.0*n_[1][0] + 0.5*n_[1][1]);
34  c_[2] = ( 0.5*n_[2][0] + 0.5*n_[2][1]);
35  }
36 
37  template<typename F, typename C>
38  void interpolate (const F& ff, std::vector<C>& out) const
39  {
40  // f gives v*outer normal at a point on the edge!
41  auto&& f = Impl::makeFunctionWithCallOperator<typename LB::Traits::DomainType>(ff);
42 
43  out.resize(3);
44 
45  for (int i=0; i<3; i++)
46  {
47  auto y = f(m_[i]);
48  out[i] = (y[0]*n_[i][0]+y[1]*n_[i][1])*sign_[i]/c_[i];
49  }
50  }
51 
52  private:
53  // Edge orientations
54  std::array<typename LB::Traits::RangeFieldType,3> sign_;
55  // Edge midpoints of the reference triangle
56  std::array<typename LB::Traits::DomainType,3> m_;
57  // Unit outer normals of the reference triangle
58  std::array<typename LB::Traits::DomainType,3> n_;
59  // Inverse triangle edge length
60  std::array<typename LB::Traits::RangeFieldType,3> c_;
61  };
62 }
63 
64 #endif
Definition: bdfmcube.hh:16
Definition: raviartthomas02dlocalinterpolation.hh:16
void interpolate(const F &ff, std::vector< C > &out) const
Definition: raviartthomas02dlocalinterpolation.hh:38
RT02DLocalInterpolation(std::bitset< 3 > s=0)
Constructor with given set of edge orientations.
Definition: raviartthomas02dlocalinterpolation.hh:20