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