DiscreteFunction.inc.hpp 2.07 KB
Newer Older
1
2
#pragma once

3
#include <type_traits>
4

5
6
#include <dune/grid/utility/hierarchicsearch.hh>

7
8
#include <amdis/functions/Interpolate.hpp>
#include <amdis/gridfunctions/GridFunction.hpp>
Praetorius, Simon's avatar
Praetorius, Simon committed
9
#include <amdis/linearalgebra/VectorFacade.hpp>
10

11
namespace AMDiS {
12

13
// Evaluate DiscreteFunction in global coordinates
14
15
template <class C, class GB, class TP, class R>
typename DiscreteFunction<C const,GB,TP,R>::Range DiscreteFunction<C const,GB,TP,R>::
16
  operator()(Domain const& x) const
17
{
18
19
  using Grid = typename GlobalBasis::GridView::Grid;
  using IS = typename GlobalBasis::GridView::IndexSet;
20

Praetorius, Simon's avatar
Praetorius, Simon committed
21
  auto const& gv = this->basis().gridView();
22
  Dune::HierarchicSearch<Grid,IS> hsearch{gv.grid(), gv.indexSet()};
23

24
25
26
27
28
  auto element = hsearch.findEntity(x);
  auto geometry = element.geometry();
  auto localFct = localFunction(*this);
  localFct.bind(element);
  return localFct(geometry.local(x));
29
30
31
}


32
// Interpolation of GridFunction to DOFVector
33
template <class C, class GB, class TP, class R>
34
  template <class Expr, class Tag>
35
void DiscreteFunction<C,GB,TP,R>::
36
  interpolate_noalias(Expr&& expr, Tag strategy)
37
{
Praetorius, Simon's avatar
Praetorius, Simon committed
38
  auto const& basis = this->basis();
39
  auto const& treePath = this->treePath();
40

41
  auto&& gf = makeGridFunction(FWD(expr), basis.gridView());
42

43
  if (std::is_same_v<Tag, tag::average>) {
44
    VectorType_t<short,Coefficients> counter(basis);
45
    AMDiS::interpolate(basis, coefficients(), gf, treePath, counter);
46

Praetorius, Simon's avatar
Praetorius, Simon committed
47
    coefficients().forEach([&counter](auto dof, auto& coeff)
48
    {
49
      coeff /= std::max(double(counter.at(dof)), 1.0);
50
    });
51
52
  } else {
    AMDiS::interpolate(basis, coefficients(), gf, treePath);
53
  }
54
}
55

56

57
// Interpolation of GridFunction to DOFVector
58
template <class C, class GB, class TP, class R>
59
  template <class Expr, class Tag>
60
void DiscreteFunction<C,GB,TP,R>::
61
  interpolate(Expr&& expr, Tag strategy)
62
{
63
  // create temporary copy of data
64
  Coefficients tmp(coefficients());
65

Praetorius, Simon's avatar
Praetorius, Simon committed
66
  Self tmpView{tmp, this->basis(), this->treePath()};
67
  tmpView.interpolate_noalias(FWD(expr), strategy);
68

69
  // move data from temporary vector into stored DOFVector
Praetorius, Simon's avatar
Praetorius, Simon committed
70
  coefficients() = std::move(tmp);
71
72
}

73
} // end namespace AMDiS