AMDiS  0.3
The Adaptive Multi-Dimensional Simulation Toolbox
HierarchicNodeToRangeMap.hpp
1 #pragma once
2 
3 #include <utility>
4 #include <type_traits>
5 
6 #include <dune/common/concept.hh>
7 
8 #include <dune/functions/common/indexaccess.hh>
9 
10 #include <amdis/common/Concepts.hpp>
11 
12 namespace AMDiS
13 {
24  {
25  // Specialization for ranges with operator[] access
26  template <class Node, class TreePath, class Range,
27  REQUIRES(Concepts::HasIndexAccess<Range, Dune::index_constant<0>>)>
28  decltype(auto) operator()(const Node& node, const TreePath& treePath, Range&& y) const
29  {
30  return Dune::Functions::resolveStaticMultiIndex(y, transformTreePath(treePath));
31  }
32 
33  // Specialization for non-container ranges
34  template <class Node, class TreePath, class Range,
35  REQUIRES(not Concepts::HasIndexAccess<Range, Dune::index_constant<0>>)>
36  decltype(auto) operator()(const Node& node, const TreePath& treePath, Range&& y) const
37  {
38  return std::forward<Range>(y);
39  }
40 
41  private:
42  // NOTE: due to a bug in dune-functions <= 2.6, a hybrid-treepath can not be passed to a HierarchicNodeToRangeMap,
43  // i.e. the HybridTreePath missed a size() function
44  template <class TreePath>
45  static auto transformTreePath(TreePath const& treePath)
46  {
47  return Ranges::apply([](auto... i) { return Dune::makeTupleVector(i...); }, treePath._data);
48  }
49  };
50 
51 } // end namespace AMDiS
Definition: AdaptBase.hpp:6
constexpr bool HasIndexAccess
A Dune::Functions::HasIndexAccess type.
Definition: Concepts.hpp:158
A simple node to range map using the nested tree indices.
Definition: HierarchicNodeToRangeMap.hpp:23