AMDiS  0.3
The Adaptive Multi-Dimensional Simulation Toolbox
DiscreteFunction.inc.hpp
1 #pragma once
2 
3 #include <type_traits>
4 
5 #include <dune/grid/utility/hierarchicsearch.hh>
6 
7 #include <amdis/algorithm/Transform.hpp>
8 #include <amdis/functions/Interpolate.hpp>
9 #include <amdis/gridfunctions/GridFunction.hpp>
10 #include <amdis/linearalgebra/VectorFacade.hpp>
11 
12 namespace AMDiS {
13 
14 // Evaluate DiscreteFunction in global coordinates
15 template <class C, class GB, class TP, class R>
16 typename DiscreteFunction<C const,GB,TP,R>::Range DiscreteFunction<C const,GB,TP,R>::
17  operator()(Domain const& x) const
18 {
19  using Grid = typename GlobalBasis::GridView::Grid;
20  using IS = typename GlobalBasis::GridView::IndexSet;
21 
22  auto const& gv = this->basis().gridView();
23  Dune::HierarchicSearch<Grid,IS> hsearch{gv.grid(), gv.indexSet()};
24 
25  auto element = hsearch.findEntity(x);
26  auto geometry = element.geometry();
27  auto localFct = localFunction(*this);
28  localFct.bind(element);
29  return localFct(geometry.local(x));
30 }
31 
32 
33 // Interpolation of GridFunction to DOFVector
34 template <class C, class GB, class TP, class R>
35  template <class Expr, class Tag>
37  interpolate_noalias(Expr&& expr, Tag strategy)
38 {
39  auto const& basis = this->basis();
40  auto const& treePath = this->treePath();
41 
42  auto&& gf = makeGridFunction(FWD(expr), basis.gridView());
43 
44  if constexpr(std::is_same_v<Tag, tag::average>) {
45  VectorType_t<short,Coefficients> counter(basis);
46  AMDiS::interpolate(basis, coefficients(), gf, treePath, counter);
47 
48  Recursive::transform(coefficients(),
49  [](auto const& coeff, short c) { return coeff / std::max(double(c), 1.0); },
50  coefficients(), counter);
51 
52  } else {
53  AMDiS::interpolate(basis, coefficients(), gf, treePath);
54  }
55 }
56 
57 
58 // Interpolation of GridFunction to DOFVector
59 template <class C, class GB, class TP, class R>
60  template <class Expr, class Tag>
62  interpolate(Expr&& expr, Tag strategy)
63 {
64  // create temporary copy of data
65  Coefficients tmp(coefficients());
66 
67  Self tmpView{tmp, this->basis(), this->treePath()};
68  tmpView.interpolate_noalias(FWD(expr), strategy);
69 
70  // move data from temporary vector into stored DOFVector
71  coefficients() = std::move(tmp);
72 }
73 
74 } // end namespace AMDiS
void interpolate(Expr &&expr, Tag strategy={})
Interpolation of GridFunction to DOFVector.
Definition: DiscreteFunction.inc.hpp:62
decltype(auto) makeGridFunction(PreGridFct const &preGridFct, GridView const &gridView)
Generator for Gridfunctions from Expressions (PreGridfunctions)
Definition: GridFunction.hpp:168
Definition: AdaptBase.hpp:6
A mutable view on the subspace of a DOFVector,.
Definition: DiscreteFunction.hpp:36
void interpolate_noalias(Expr &&expr, Tag strategy={})
Interpolation of GridFunction to DOFVector, assuming that there is no reference to this DOFVector in ...
Definition: DiscreteFunction.inc.hpp:37