Dune Core Modules (2.8.0)

defaultnodetorangemap.hh
1// -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2// vi: set et ts=4 sw=2 sts=2:
3#ifndef DUNE_FUNCTIONS_FUNCTIONSPACEBASES_DEFAULTNODETORANGEMAP_HH
4#define DUNE_FUNCTIONS_FUNCTIONSPACEBASES_DEFAULTNODETORANGEMAP_HH
5
6
8
9#include <dune/functions/functionspacebases/concepts.hh>
10
11#include <dune/typetree/traversal.hh>
12#include <dune/typetree/visitor.hh>
13
14
15namespace Dune {
16namespace Functions {
17
18
19
37template<class Tree>
39{
40
41 // A simple visitor for computing lexicographic
42 // subtree indices. To identify a leaf node
43 // we use its treeIndex() which is unique
44 // wrt the whole tree and store the computed
45 // index in a vector indexed by the tree indices.
46 struct Visitor
49 {
50 Visitor(std::vector<std::size_t>& indices) :
51 indices_(indices),
52 counter_(0)
53 {}
54
55 template<typename Node, typename TreePath>
56 void leaf(Node& node, TreePath treePath)
57 {
58 if (indices_.size() < node.treeIndex()+1)
59 indices_.resize(node.treeIndex()+1);
60 indices_[node.treeIndex()] = counter_;
61 ++counter_;
62 }
63
64 std::vector<std::size_t>& indices_;
65 std::size_t counter_;
66 };
67
78 DefaultNodeToRangeMap(const Tree& tree)
79 {
80 TypeTree::applyToTree(tree, Visitor(indices_));
81 }
82
83 template<class Node, class TreePath, class Range,
84 std::enable_if_t<models<Concept::HasIndexAccess, Range, decltype(std::declval<Node>().treeIndex())>() and not Tree::isLeaf, int> = 0>
85 decltype(auto) operator()(const Node& node, const TreePath& treePath, Range&& y) const
86 {
87 return y[indices_[node.treeIndex()]];
88 }
89
90 template<class Node, class TreePath, class Range,
91 std::enable_if_t< not models<Concept::HasIndexAccess, Range, decltype(std::declval<Node>().treeIndex())>() or Tree::isLeaf, int> = 0>
92 decltype(auto) operator()(const Node& node, const TreePath& treePath, Range&& y) const
93 {
94 return std::forward<Range>(y);
95 }
96
97 std::vector<std::size_t> indices_;
98};
99
100
101
102template<class Tree>
103DefaultNodeToRangeMap<Tree> makeDefaultNodeToRangeMap(const Tree& tree)
104{
105 return DefaultNodeToRangeMap<Tree>(tree);
106}
107
108
109
110template<class Basis, class TreePath>
111auto makeDefaultNodeToRangeMap(const Basis& basis, TreePath&& treePath)
112 -> decltype(makeDefaultNodeToRangeMap(TypeTree::child(basis.localView().tree(),treePath)))
113{
114 auto&& localView = basis.localView();
115 localView.bind(*basis.gridView().template begin<0>());
116 auto&& tree = TypeTree::child(localView.tree(),treePath);
117 return makeDefaultNodeToRangeMap(tree);
118}
119
120
121
122} // namespace Dune::Functions
123} // namespace Dune
124
125
126#endif // DUNE_FUNCTIONS_FUNCTIONSPACEBASES_DEFAULTNODETORANGEMAP_HH
Infrastructure for concepts.
constexpr HybridTreePath< T... > treePath(const T &... t)
Constructs a new HybridTreePath from the given indices.
Definition: treepath.hh:188
void applyToTree(Tree &&tree, Visitor &&visitor)
Apply visitor to TypeTree.
Definition: traversal.hh:237
ImplementationDefined child(Node &&node, Indices... indices)
Extracts the child of a node given by a sequence of compile-time and run-time indices.
Definition: childextraction.hh:126
Dune namespace.
Definition: alignedallocator.hh:11
A simple node to range map using lexicographic ordering.
Definition: defaultnodetorangemap.hh:39
DefaultNodeToRangeMap(const Tree &tree)
Construct DefaultNodeToRangeMap.
Definition: defaultnodetorangemap.hh:78
Mixin base class for visitors that only need a dynamic TreePath during traversal.
Definition: visitor.hh:424
Convenience base class for visiting the entire tree.
Definition: visitor.hh:433
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Dec 22, 23:30, 2024)