DiscreteFunction.inc.hpp 2.01 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>
9

10
namespace AMDiS {
11

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

20
21
  auto const& gv = this->basis()->gridView();
  Dune::HierarchicSearch<Grid,IS> hsearch{gv.grid(), gv.indexSet()};
22

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


31
// Interpolation of GridFunction to DOFVector
32
template <class GB, class VT, class TP>
33
34
35
  template <class Expr, class Tag>
void DiscreteFunction<GB,VT,TP,false>::
  interpolate_noalias(Expr&& expr, Tag strategy)
36
{
37
38
  auto const& basis = *this->basis();
  auto const& treePath = this->treePath();
39

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

42
43
44
  if (std::is_same<Tag, tag::average>::value) {
    auto counter = coefficients();
    AMDiS::interpolate(basis, coefficients(), gf, treePath, counter);
45

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

55

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

65
66
  Self tmpView{tmp, this->treePath()};
  tmpView.interpolate_noalias(FWD(expr), strategy);
67

68
69
  // move data from temporary vector into stored DOFVector
  coefficients().backend() = std::move(tmp.backend());
70
71
}

72
} // end namespace AMDiS